bloomreach / spa-sdk

Apache License 2.0
15 stars 16 forks source link

Delivery API upgrade 0.9 to 1.0: Wrong PageModel used? #34

Closed linkhat29 closed 2 months ago

linkhat29 commented 4 months ago

Hello,

I’m trying to upgrade the delivery API from 0.9 to 1.0. I’m using react on the frontend and BloomreachXM 14.7.

I am currently using “bloomreach/react-sdk”: “22.0.3” and “@bloomreach/spa-sdk”: “22.0.3”.

After updating the default pagemodelapi version to 1.0 in hst-config.properties I’m able to see the new API response format when I call for /resourceapi/ , but I’m also seeing errors in the devtools console:

Uncaught Error: Unsupported component type: ‘undefined’. at ComponentFactory.buildComponent (component-factory09.ts:68:1) at ComponentFactory.create (component-factory09.ts:55:1) at new PageImpl (page09.ts:84:1)

These errors are happening in files coming from @bloomreach/spa-sdk package.

After looking through the code from the package the issue seems to be related to the component types being changed in the API response between the two API versions from uppercase format ‘CONTAINER_ITEM_COMPONENT’ to lowercase ‘container-item’.

I can see the difference when I compare the delivery api response for the same url before and after the upgrade: 0.9: “type”: “CONTAINER_COMPONENT”, 1.0: “type”: “container”,

I think somehow the wrong files are being used as I see component09.ts, component-factory09.ts being hit when it should be component.ts, component-factory.ts as those have the correct type casing.

I think the issue may also be related to page-factory.ts where I see this line: export type PageFactory = Builder<[PageModel | PageModel09], Page>;

Is there a configuration I’m not setting up properly?

Thank you!

joerideg commented 3 months ago

Hi @linkhat29 , Since v21 of the SPA SDK the apiVersion is no longer set by default. See the explanation in the migration guide here. So you need to set the apiVersion (typedoc reference) in the configuration object you are passing to the initialize call or BrPage component configuration prop.

I hope that resolves your issue.

linkhat29 commented 3 months ago

Hello @joerideg ,

Thanks for the response! I have implemented the configuration for the BrPage component by adding a new line to the config like so:

apiVersion: "PDA 1.0",

Is this correct? I no longer see the console error related to undefined component type which is great!

However I now see http 400 console error when my app is hitting the /resourceapi/ url "Message UnsupportedApiVersion: Header 'Accept-Version: PDA 1.0' points to a non-supported version"

If I call the same resourceapi url without the header separately I get 200 response. I've already configured hst-config.properties to point to the right api version and I do see a json response in 1.0 format if I call the resource api without adding this accept-version header.

Is there something else I'm missing such that I see http 400?

joerideg commented 3 months ago

Hi @linkhat29 , So the string provided to apiVersion should be "1.0" (not "PDA 1.0"). Also there is some checking done on your configuration object if you are using configuration options for the older versions. For example you should not be using the options property to configure live and preview options, nor the cmsBaseUrl property, as that will automatically assume you are using an older setup.

I hope this helps!

linkhat29 commented 3 months ago

Hello @joerideg,

Thanks for the details. That's helpful, I'll look at our config more and see what might be outdated. Thanks!