Frontend SDK version 2.0.0
Version 2.0.0 of the Frontend SDK brings several updates, including breaking changes, new features, and bug fixes. Following are the most important changes.
Breaking changes
The latest SDK update contains several breaking changes, bringing adjustments and improvements to streamline usage and maintain consistency:
-
Commerce-related events are now in the Composable Commerce integration, making them easier to manage. The Page API underwent significant changes; among these, the
getPagemethod now returns a union type ofPageResponseandRedirectResponseinstead of justPageResponse.getPage: (options: { path: string; query?: AcceptedQueryTypes; customHeaderValue?: string; serverOptions?: ServerOptions; }) => Promise<SDKResponse<PageResponse | RedirectResponse>>; -
We restructured the
sectionsproperty in thePagetype. Previously, it was an array ofSectionobjects, while now it's an object with optionalfooter,head, andmainproperties of typeSection. Additionally, thestateproperty in thePagetype now accepts specific values:default,published,draft, orscheduled. To ensure consistency, all Page API and event-related types are now defined as interfaces.import { Section } from "@frontastic/extension-types"; export interface Page { pageId: string; sections: { footer?: Section; head?: Section; main?: Section; }; state: "default" | "published" | "draft" | "scheduled"; } -
The SDK methods underwent some changes too:
- In
SDK.configure, theextensionVersionargument is now required.
type SDKConfig = { locale: string; currency: Currency; endpoint: string; extensionVersion: string; useCurrencyInLocale?: boolean; sessionLifetime?: number; cookieHandlingOverride?: CookieManager; redactionHandlingOverride?: RedactionManager | RedactionManagerConfig; customHeaderValue?: string; };- For
SDK.callAction, we replaced theskipQueueparameter with an optionalparallelargument, which defaults totrue.
* @param {boolean} [options.parallel] - An optional boolean, default true indicating whether the action should executed asynchronously or be added to a queue and executed in sequence. Useful to supply false on actions you may think have race conditions. async callAction<ReturnData>(options: { actionName: string; payload?: AcceptedPayloadTypes; query?: AcceptedQueryTypes; parallel?: boolean; customHeaderValue?: string; serverOptions?: ServerOptions; }): Promise<SDKResponse<ReturnData>> - In
-
Cookie handling is now fully asynchronous and we removed the previous synchronous cookie handling. The
rememberMeCookieAsyncobject was renamed torememberMeCookieand now serves as the default. -
Several classes and properties were deprecated or removed:
- The
Integrationclass replaced theExtensionone. - Properties like
posixLocaleand methods such asendpoint,locale,currency, andcustomHeaderValueare now deprecated. - Event class properties, including
isDefaultPrevented,isCancelled, andisPropagationStoppedare also deprecated.
- The
-
For event handling, the
Eventclass no longer includes properties likeisDefaultPrevented,isCancelled, andisPropagationStopped. Thepayloadargument inSDK.callActionmust now be of typeAcceptedPayloadTypes.async callAction<ReturnData>(options: { actionName: string; payload?: AcceptedPayloadTypes; query?: AcceptedQueryTypes; parallel?: boolean; customHeaderValue?: string; serverOptions?: ServerOptions; }): Promise<SDKResponse<ReturnData>> -
Error handling was also updated:
- The
FetchErrorclass now accepts anoptionsargument with anerrorproperty of typestring | Error. - The
ActionErrorclass no longer includes theactionNameproperty and now requires a singleoptionsargument. - Similarly, the
PageErrorclass no longer contains thepathproperty and only accepts anoptionsargument with anerrorproperty of typestring | Error.
- The
New features
We introduced some exciting features to the SDK, bringing more flexibility and functionality:
-
The
BaseEventsfile now replacesStandardEventsand contains several new events. For example,actionCalledtriggers when an action is called, whilepageApiMethodCalledtriggers when a Page API method is called. Also,fetchCalledactivates when you call an action or a Page API method. On top of that, you’ll find events likeactionFetchSuccessful,fetchSuccessful, andpageApiFetchSuccessfulto indicate successful responses. Errors are handled too, withactionErrorCaughtandpageApiErrorCaughtcapturing issues during operations. -
Redaction handling is enhanced too. Sensitive JSON and URL data is now automatically redacted in internal events. If you need a different behavior, you can override this default with
redactionHandlingOverrideinSDK.configure. -
Another big update is asynchronous execution. Actions now run asynchronously by default, but you can switch to synchronous behavior by setting
parallel: falseinSDK.callAction. Cookie handling is now fully asynchronous and works seamlessly withcookieHandlingOverride.type SDKConfig = { locale: string; currency: Currency; endpoint: string; extensionVersion: string; useCurrencyInLocale?: boolean; sessionLifetime?: number; cookieHandlingOverride?: CookieManager; redactionHandlingOverride?: RedactionManager | RedactionManagerConfig; customHeaderValue?: string; };
Enhancements and bug fixes
We released enhancements and bug fixes to improve the SDK’s reliability and functionality:
-
The Page API is enhanced with updates to the
sectionsproperty and thegetPagemethod, ensuring they align with the latest response types. In theSDK.configuremethod, theextensionVersionargument is now properly marked as required, addressing a previous inconsistency. -
We also improved Error handling by removing repetitive text from error messages, making them clearer and easier to understand. Additionally, the internal fetcher now catches and reports errors for responses that can’t be serialized, making troubleshooting more straightforward.
Developer experience improvements
We optimized the Frontend SDK for ease of use and extensibility:
-
Multi-tenancy projects are now easier to manage. The new
extensionVersionconfiguration option in theSDK.configuremethod lets you specify the version of the extension bundle that you want to connect to in multi-tenant setups, thus streamlining the process. For session management, a newsessionLifetimeoption is now available. This gives developers more control by allowing them to adjust the default session duration based on their needs.type SDKConfig = { locale: string; currency: Currency; endpoint: string; extensionVersion: string; useCurrencyInLocale?: boolean; sessionLifetime?: number; cookieHandlingOverride?: CookieManager; redactionHandlingOverride?: RedactionManager | RedactionManagerConfig; customHeaderValue?: string; }; -
In terms of types and composability, we aimed at simplifying things. We encourage you to abandon the older
@commercetools/frontend-domain-typesand@commercetools/frontend-composable-commercepackages. Instead, you can now reference types and SDK integrations directly within your project’s folder structure for a cleaner setup. -
Cookie handling got more customizable. You can now use the
cookieHandlingOverrideoption to extend or override the default cookie behavior. This gives you better control to manage cookies across various environments.
CLI updates (version 2.4.2)
We updated the CLI, fixing some issues and improving the overall behavior:
-
Installation issues have been addressed. If Yarn isn’t detected, the CLI now gives you clear installation instructions instead of letting you know it’s missing. Log view readability has also improved as long messages no longer spill over the right border, making it much easier to read.
-
We also have good news about uploads. The CLI now properly handles uploading backend extensions in newly cloned repositories without needing a restart. Validation is tighter because the GUID validation pattern in the code generator is now more precise. Additionally, if you run into errors while copying log messages, errors will now appear in a dialog to make troubleshooting more straightforward.
-
We made a handy change for project initialization. You no longer need to include the
--multitenantparameter when running thefrontastic initcommand. That’s one less thing to worry about.