kontent-ai / delivery-sdk-js

Kontent Delivery SDK for Javascript
https://kontent.ai
MIT License
50 stars 34 forks source link

Apply a global filter to deliveryClient #362

Closed kevinmcgillicuddy closed 1 year ago

kevinmcgillicuddy commented 1 year ago

Motivation

I am looking to globally filter on system.workflow_step where the step is archive

Somewhat motivated by this previous issue. We are using the delivery client in 2 pretty large Angular applications and what we do is initialize the delivery client once in a middleware library and then expose functions that get the various kontent items

example:

this.client = new DeliveryClient({
      projectId: config.projectId ?? '',
      previewApiKey: config.previewApiKey,
      secureApiKey: config.secureApiKey,
       ...

and then in a class that extends the above class

getContactInfo(): Observable<WFE.IContactInfo> {
return from(
      this.client
        .items<WWW.KontentContactInfoItem>()
        .type('contact_info')
        .toPromise()
    ).pipe(
      map((contactInfo) =>
        WWW.convertKontentContactInfoItem(contactInfo.data.items[0])
      )
    );
  }

so I can get it to work within every method (like getContactInfo above) adding in .notEqualsFilter('system.workflow_step', 'archived');

Proposed solution

adding this to all the methods is less then ideal, what I would love is to be able to apply it on the delivery client initialization

Additional context

"@kontent-ai/delivery-sdk" SDK version: "12.4.3"

Nickm615 commented 1 year ago

can you assign this to me?

Nickm615 commented 1 year ago

Hi @kevinmcgillicuddy, are there any other filters you feel would be useful on a global client level? Right now I'm considering adding the option to exclude archived items as well as the option to set a default collection. Would this solve the issue for you is there more functionality you're hoping for?

kevinmcgillicuddy commented 1 year ago

Hi @kevinmcgillicuddy, are there any other filters you feel would be useful on a global client level? Right now I'm considering adding the option to exclude archived items as well as the option to set a default collection. Would this solve the issue for you is there more functionality you're hoping for?

hey @Nickm615 the only use case I can think of right now was to exclude archived items. Thanks for taking this on! Anything I can do to help let me know

Nickm615 commented 1 year ago

Hi @kevinmcgillicuddy. We've added the requested functionality, you should find a new client configuration option excludeArchivedItems

Thanks again for your feedback, let us know if you have any other ideas you think we should consider incorporating.