Vue Storefront is now Alokai! Learn More
@vsf-enterprise/unified-sdk

@vsf-enterprise/unified-sdk

1.6.1

Patch Changes

This package has been deprecated. Please migrate to the middlewareModule instead.

Migration Guide

Starting with a version ^1.4.0 of @vue-storefront/sdk a new middlewareModule has been added which allows you to add a Proxy-based module not only to the Unified Extension, but any of the integration extension.

To update the SDK, follow these steps:

Next.js

  1. Update the SDK to the latest version. Go to apps/storefront-unified-nextjs/package.json and update the @vue-storefront/sdk package and @vue-storefront/next versions. Then run yarn install to regenerate the yarn.lock file.
- "@vue-storefront/sdk": "1.3.3",
- "@vue-storefront/next": "1.0.2",
+ "@vue-storefront/sdk": "^1.4.0",
+ "@vue-storefront/next": "^1.1.0",
  1. Go to the apps/storefront-middleware/middleware.config.ts and export the UnifiedEndpoints
+ export type UnifiedEndpoints = WithoutContext<UnifiedApiExtension["extendApiMethods"]>;
  1. Adjust the SDK Config to use the new middlewareModule.
    1. middlewareModule is available as a parameter in the createSdk function.
    2. Replace the unifiedModule with the middlewareModule and pass the UnifiedEndpoints type.
- import { unifiedModule } from '@vsf-enterprise/unified-sdk';
import { CreateSdkOptions, createSdk } from '@vue-storefront/next';
- import { UnifiedApiExtension } from 'storefront-middleware/middleware.config';
+ import { UnifiedEndpoints } from 'storefront-middleware/middleware.config';

-export const { getSdk } = createSdk(options, ({ buildModule, middlewareUrl, getRequestHeaders }) => ({
+export const { getSdk } = createSdk(options, ({ buildModule, middlewareUrl, getRequestHeaders, middlewareModule }) => ({
- unified: buildModule(unifiedModule<UnifiedApiExtension>, {
+ unified: buildModule(middlewareModule<UnifiedEndpoints>, {
    apiUrl: `${middlewareUrl}/commerce`,
-   requestOptions: {
-     headers: () => getRequestHeaders() as Record<string, string>,
+   defaultRequestConfig: {
+     headers: getRequestHeaders(),
    },
  }),
  1. Remove the @vsf-enterprise/unified-sdk references from the code. You can find all imports of @vsf-enterprise/unified-sdk in the apps/storefront-unified-nextjs, and replace them with the imports coming from the @vue-storefront/sdk package.

Example:

- import { isSdkUnauthorizedError } from '@vsf-enterprise/unified-sdk';
+ import { isSdkUnauthorizedError } from '@vue-storefront/sdk';

Important notes on the breaking changes in naming:

  • RENAMED SDKError to SdkHttpError
  • RENAMED isSpecificSdkError to isSpecificSdkHttpError
  1. Infer the types based on the UnifiedEndpoints in apps/storefront-unified-nextjs/sdk/types.ts file
- import { InferSdkMethodArgs, InferSdkMethodReturn } from '@vsf-enterprise/unified-sdk';
- import { UnifiedApiExtension } from 'storefront-middleware/middleware.config';
-
- export type InferSdk<TName extends keyof UnifiedApiExtension['extendApiMethods']> = InferSdkMethodReturn<
-   UnifiedApiExtension,
-   TName
- >;
-
- export type InferSdkArgs<TName extends keyof UnifiedApiExtension['extendApiMethods']> = InferSdkMethodArgs<
-   UnifiedApiExtension,
-   TName
- >;

+ import { UnifiedEndpoints } from 'storefront-middleware/middleware.config';
+
+ export type InferSdk<TName extends keyof UnifiedEndpoints> = Awaited<ReturnType<UnifiedEndpoints[TName]>>;
+
+ export type InferSdkArgs<TName extends keyof UnifiedEndpoints> = Parameters<UnifiedEndpoints[TName]>[0];
  1. Remove @vsf-enterprise/unified-sdk from apps/storefront-unified-nextjs/package.json and run yarn install to regenerate the yarn.lock file.
- "@vsf-enterprise/unified-sdk": "1.6.0",
  1. Run yarn build to confirm that the changes are correct.

Nuxt

  1. Update the SDK to the latest version. Go to apps/storefront-unified-nuxt/package.json and update the @vue-storefront/sdk package and @vue-storefront/nuxt versions. Then run yarn install to regenerate the yarn.lock file.
- "@vue-storefront/nuxt": "3.0.3",
- "@vue-storefront/sdk": "1.3.3",
+ "@vue-storefront/nuxt": "3.1.0",
+ "@vue-storefront/sdk": "^1.4.0",
  1. Go to the apps/storefront-middleware/middleware.config.ts and export the UnifiedEndpoints
+ export type UnifiedEndpoints = WithoutContext<UnifiedApiExtension["extendApiMethods"]>;
  1. Adjust the SDK Config to use the new middlewareModule.
    1. middlewareModule is available as a parameter in the createSdk function.
    2. Replace the unifiedModule with the middlewareModule and pass the UnifiedEndpoints type.
    3. Pass as headers getRequestHeaders function to the defaultRequestConfig object.
- import { unifiedModule } from '@vsf-enterprise/unified-sdk';
- import { UnifiedApiExtension } from '../../storefront-middleware/middleware.config';
+ import { UnifiedEndpoints } from '../../storefront-middleware/middleware.config';

-export default defineSdkConfig(({ buildModule, middlewareUrl, getCookieHeader }) => ({
+export default defineSdkConfig(({ buildModule, middlewareUrl, getRequestHeaders, middlewareModule }) => ({
- unified: buildModule(unifiedModule<UnifiedApiExtension>, {
+ unified: buildModule(middlewareModule<UnifiedEndpoints>, {
    apiUrl: `${middlewareUrl}/commerce`,
-   requestOptions: {
-     headers: () => getCookieHeader(),
+   defaultRequestConfig: {
+     headers: getRequestHeaders(),
    },
  }),
  1. Remove the @vsf-enterprise/unified-sdk references from the code. You can find all imports of @vsf-enterprise/unified-sdk in the apps/storefront-unified-nuxt, and replace them with the imports coming from the @vue-storefront/sdk package.

Example:

- import { isSdkUnauthorizedError } from '@vsf-enterprise/unified-sdk';
+ import { isSdkUnauthorizedError } from '@vue-storefront/sdk';

Important notes on the breaking changes in naming:

  • RENAMED SDKError to SdkHttpError
  • RENAMED isSpecificSdkError to isSpecificSdkHttpError
  1. Infer the types based on the UnifiedEndpoints in apps/storefront-unified-nuxt/types/sdk.ts file
- import { InferSdkMethodArgs, InferSdkMethodReturn } from '@vsf-enterprise/unified-sdk';
- import { UnifiedApiExtension } from 'storefront-middleware/middleware.config';
-
- export type InferSdk<TName extends keyof UnifiedApiExtension['extendApiMethods']> = InferSdkMethodReturn<
-   UnifiedApiExtension,
-   TName
- >;
-
- export type InferSdkArgs<TName extends keyof UnifiedApiExtension['extendApiMethods']> = InferSdkMethodArgs<
-   UnifiedApiExtension,
-   TName
- >;

+ import { UnifiedEndpoints } from 'storefront-middleware/middleware.config';
+
+ export type InferSdk<TName extends keyof UnifiedEndpoints> = Awaited<ReturnType<UnifiedEndpoints[TName]>>;
+
+ export type InferSdkArgs<TName extends keyof UnifiedEndpoints> = Parameters<UnifiedEndpoints[TName]>[0];
  1. Remove @vsf-enterprise/unified-sdk from apps/storefront-unified-nextjs/package.json and run yarn install to regenerate the yarn.lock file.
- "@vsf-enterprise/unified-sdk": "1.6.0",
  1. Run yarn build to confirm that the changes are correct.

1.6.0

Minor Changes

  • adc5bf9: Added new option - errorHandler - that allows to define custom error handling for all reqests. This option also allows to use createRefreshTokenAndRetryHandler() from @vsf-enterprise/sapcc-sdk to refreshing expired user token.

1.5.1

Patch Changes

  • 1f52ffa: Update dependencies

1.5.0

Minor Changes

  • 5aa28292: Infer sdk method type helpers

1.4.0

Minor Changes

  • Added utils types for error handling:
    • isCausedBySdkError
    • isSpecificSdkError
    • isSdkRequestError
    • isSdkUnauthorizedError

1.3.0

Minor Changes

  • Added extra configration option - headers - that takes function which is resolved on every request and that result is spread to the request's headers

1.2.1

Patch Changes

  • Publish src directory

1.2.0

Minor Changes

  • sdk now tries to parse all responses as JSON and fallbacks to text in case of unsuccessful attempt

1.1.1

Patch Changes

  • Export SDKError, fix response statusCode

1.1.0

Minor Changes

  • Improved error messages - now Unifed SDK module, uses the SDKError class that contains a message, statusCode & cause of the error

Patch Changes

  • Fix problem with handling empty responses from Middleware in Unifed SDK module

1.0.0

Major Changes

  • The package has been rewritten into an SDK module, compatible with other integrations.

0.3.0

Minor Changes

  • Update packages for SI demo preparation

0.2.0

Minor Changes

  • Update packages for SI demo preparation

0.1.1

Patch Changes

  • Update release pipeline

0.1.0

Minor Changes

  • Update packages in order to prepare unified storefront demo
  • Update packages for demo purposes