From f721636268b7cda6556eec97e3379c62f6e5352a Mon Sep 17 00:00:00 2001 From: Bartosz Herba Date: Thu, 11 Apr 2024 10:15:24 +0200 Subject: [PATCH 1/3] fix: type inference for the module build --- packages/sdk/src/index.ts | 12 +++++++----- packages/sdk/src/types/ModuleOptions.ts | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/sdk/src/index.ts b/packages/sdk/src/index.ts index 210eb7808..b1267680f 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,9 +13,7 @@ export interface MagentoModuleType extends Module { /** * Magento module. * - * @example - * - * Initialization of the Magento module. + * @example Initialization of the Magento module. * * ```js * import { initSDK, buildModule } from '@vue-storefront/sdk'; @@ -19,7 +21,7 @@ export interface MagentoModuleType extends Module { * * const sdkConfig = { * magento: - * buildModule( + * buildModule( * magentoModule, * { * apiUrl: 'http://localhost:8181/magento', @@ -30,7 +32,7 @@ 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), }; 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; } From 5065b31f28b710213ca8904408baff862066bf4f Mon Sep 17 00:00:00 2001 From: Bartosz Herba Date: Thu, 11 Apr 2024 10:20:51 +0200 Subject: [PATCH 2/3] chore: add changeset --- .changeset/eight-islands-scream.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) 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..307401073 --- /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. From 6026f4047a266033f3407378f9437b96ae5a7331 Mon Sep 17 00:00:00 2001 From: Bartosz Herba Date: Thu, 11 Apr 2024 13:24:27 +0200 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Wojciech Sikora <35867383+WojtekTheWebDev@users.noreply.github.com> --- .changeset/eight-islands-scream.md | 2 +- packages/sdk/src/index.ts | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.changeset/eight-islands-scream.md b/.changeset/eight-islands-scream.md index 307401073..556ea8ad2 100644 --- a/.changeset/eight-islands-scream.md +++ b/.changeset/eight-islands-scream.md @@ -20,7 +20,7 @@ const sdkConfig = { ) }; -export const sdk = initSDK(sdkConfig); +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 b1267680f..65bc159df 100644 --- a/packages/sdk/src/index.ts +++ b/packages/sdk/src/index.ts @@ -13,7 +13,8 @@ export interface MagentoModuleType extends Module { /** * Magento module. * - * @example Initialization of the Magento module. + * @example + * Initialization of the Magento module. * * ```js * import { initSDK, buildModule } from '@vue-storefront/sdk'; @@ -35,7 +36,7 @@ export interface MagentoModuleType extends Module { export const magentoModule = (options: ModuleOptions) => { return { connector: connector(options), - }; + } satisfies Module; }; export { client } from './client';