From ae8a741d9843a0e7fd95fce0bc440a320a44fe27 Mon Sep 17 00:00:00 2001 From: Bartosz Herba Date: Thu, 11 Apr 2024 13:25:00 +0200 Subject: [PATCH] fix: module type depreciacion (#1516) * fix: type inference for the module build * chore: add changeset * Apply suggestions from code review Co-authored-by: Wojciech Sikora <35867383+WojtekTheWebDev@users.noreply.github.com> --------- Co-authored-by: Wojciech Sikora <35867383+WojtekTheWebDev@users.noreply.github.com> --- .changeset/eight-islands-scream.md | 26 +++++++++++++++++++++++++ packages/sdk/src/index.ts | 13 ++++++++----- packages/sdk/src/types/ModuleOptions.ts | 2 +- 3 files changed, 35 insertions(+), 6 deletions(-) create mode 100644 .changeset/eight-islands-scream.md diff --git a/.changeset/eight-islands-scream.md b/.changeset/eight-islands-scream.md new file mode 100644 index 000000000..556ea8ad2 --- /dev/null +++ b/.changeset/eight-islands-scream.md @@ -0,0 +1,26 @@ +--- +"@vue-storefront/magento-sdk": patch +--- + +### Change Log + +- [CHANGED] Deprecated the `MagentoModuleType` interface in `index.ts`. It is no longer necessary to use this type. Please, check documentation of `magentoModule` for alternatives. Below you can find a snippet of the new way of using `magentoModule`. Pay attention to the `buildModule` function that is used to create a module instance, it no longer requires the `MagentoModuleType` type as a generic parameter. + +```ts +import { initSDK, buildModule } from '@vue-storefront/sdk'; +import { magentoModule, MagentoModuleType } from '@vue-storefront/magento2-sdk' + +const sdkConfig = { + magento: + buildModule( + magentoModule, + { + apiUrl: 'http://localhost:8181/magento', + } + ) +}; + +export const sdk = initSDK(sdkConfig); +``` + +- [CHANGED] Made the `ssrApiUrl` property in `ModuleOptions.ts` optional. diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 210eb7808..65bc159df 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -2,6 +2,10 @@ import type { Module } from '@vue-storefront/sdk'; import { connector } from './connector'; import { ModuleOptions } from './types'; +/** + * @deprecated This type is deprecated and will be removed in the next major version. + * It is no longer necessary to use this type. Please, check documentation of `magentoModule`. + */ export interface MagentoModuleType extends Module { connector: ReturnType; } @@ -9,8 +13,7 @@ export interface MagentoModuleType extends Module { /** * Magento module. * - * @example - * + * @example * Initialization of the Magento module. * * ```js @@ -19,7 +22,7 @@ export interface MagentoModuleType extends Module { * * const sdkConfig = { * magento: - * buildModule( + * buildModule( * magentoModule, * { * apiUrl: 'http://localhost:8181/magento', @@ -30,10 +33,10 @@ export interface MagentoModuleType extends Module { * export const sdk = initSDK(sdkConfig); * ``` */ -export const magentoModule = (options: ModuleOptions): MagentoModuleType => { +export const magentoModule = (options: ModuleOptions) => { return { connector: connector(options), - }; + } satisfies Module; }; export { client } from './client'; diff --git a/packages/sdk/src/types/ModuleOptions.ts b/packages/sdk/src/types/ModuleOptions.ts index 50e98294d..4d9c877b3 100644 --- a/packages/sdk/src/types/ModuleOptions.ts +++ b/packages/sdk/src/types/ModuleOptions.ts @@ -10,5 +10,5 @@ export interface ModuleOptions { /** * The SSR API URL of the Magento instance */ - ssrApiUrl: string; + ssrApiUrl?: string; }