e-Spirit/javascript-content-api-library

Media references not resolved when adding additionalParams

Opened this issue · 6 comments

Hello everyone,
Currently I'm facing the problem that when I add the additionalParams parameter to my fetchByFilter request that the response is not resolved correctly. For example I want to resolve for alt and resolutions from an image.

In the CaaS docs I found an entry to resolveRefs under https://docs.e-spirit.com/module/caas-platform/CaaS_Platform_Documentation_EN.html#ref-resolving. But how can I use this feature in this type of request?

My current request looks like this:

const res = await remoteApi.fetchByFilter({
  filters: [
    {
      field: 'fsType',
      operator: ComparisonQueryOperatorEnum.EQUALS,
      value: 'PageRef',
    },
    ...
  ],
  locale,
  page: 1,
  pagesize: 100,
  additionalParams: {
    keys: {
      ...
      'page.formData.image': 1,
      ...
    },
  },
});

My response from res.items[0]['page'].formData['image']:

{
  fsType: 'FS_REFERENCE',
  name: 'image',
  value: {
    fsType: 'Media',
    name: '...',
    identifier: '...',
    uid: '...',
    uidType: 'MEDIASTORE_LEAF',
    mediaType: 'PICTURE',
    url: '...'
  }
}

In the request without additionalParams the response of the image contains meta.alt and resolutions.

 image: {
    type: 'Image',
    id: '...',
    previewId: '...',
    meta: {
      alt: '...',
    },
    description: '...',
    resolutions: {
      ORIGINAL: [Object],
      large: [Object],
      retina: [Object],
      medium: [Object],
      retina: [Object],
      ...
    },
    ...
  },

We need to use the additionalParams because the response would be too big from CaaS if we don't filter the keys. This would lead into strong performance issues.

Thank you for your help!

I'm not sure how your questions relates to the query parameter resolveRef - I don't see this in your fetchByFiltercall.

What I can say is that if you filter attributes out from the response (what is done by your addition of keys) then it is expected that attributes in the response are missing. See here for an explanation for what keys is doing: Projection

Regarding your comment for the response size: You are requesting the first 100 documents of type PageRef without additional filter (with an unspecified definition of first). That looks strange.

What's causing the different data formats is the keys attribute in your additional Parameters.

For a normal request, the fsxa API resolves Media References by requesting them from CaaS. Also, it maps the data format from CaaS to a custom fsxa-api Format

If you use the keys param, that reference resolving and data mapping is explicitly skipped, and the unresolved raw data is returned

Regarding your comment for the response size: You are requesting the first 100 documents of type PageRef without additional filter (with an unspecified definition of first). That looks strange.

This was intentionally hidden in my example request here. We have additional filters in our original request for type PageRef.

What's causing the different data formats is the keys attribute in your additional Parameters.

For a normal request, the fsxa API resolves Media References by requesting them from CaaS. Also, it maps the data format from CaaS to a custom fsxa-api Format

If you use the keys param, that reference resolving and data mapping is explicitly skipped, and the unresolved raw data is returned

Thank you for explaining!

But how is it possible to make the response smaller filtering by keys and at the same time resolving the image information without making another request to CaaS?
Making another request for each image wouldn't speed up the performance of my service.

Doing that with the initial request to CaaS won't be possible when relying on the fsxa resolving process.
What you could do, is manipulate your elements on the server in the remote api after they have been resolved, by hooking into the caasItemFilter and then send the trimmed data back to the client.

You find the documentation about that in the (deprecated) fsxa-nuxt-module, though it's actually a feature offered by the (not-deprecated) javascript-content-api. Hence i would deem it safe for usage.
https://github.com/e-Spirit/fsxa-nuxt-module/blob/master/docs/HOW_TO_ACCESS_CONTROL.md

While the idea of this feature is to filter out items that should not be sent to the client, you could manipulate the contents of images as well and trim the content down to your needs.

If you want to trim the actual responses from the CaaS, you would need to implement your own reference resolving and not use the content api for that.