Skip to content

Commit

Permalink
fix: module type depreciacion (#1516)
Browse files Browse the repository at this point in the history
* fix: type inference for the module build

* chore: add changeset

* Apply suggestions from code review

Co-authored-by: Wojciech Sikora <[email protected]>

---------

Co-authored-by: Wojciech Sikora <[email protected]>
  • Loading branch information
bartoszherba and WojtekTheWebDev authored Apr 11, 2024
1 parent 938440e commit ae8a741
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
26 changes: 26 additions & 0 deletions .changeset/eight-islands-scream.md
Original file line number Diff line number Diff line change
@@ -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.
13 changes: 8 additions & 5 deletions packages/sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ 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<typeof connector>;
}

/**
* Magento module.
*
* @example
*
* @example
* Initialization of the Magento module.
*
* ```js
Expand All @@ -19,7 +22,7 @@ export interface MagentoModuleType extends Module {
*
* const sdkConfig = {
* magento:
* buildModule<MagentoModuleType>(
* buildModule(
* magentoModule,
* {
* apiUrl: 'http://localhost:8181/magento',
Expand All @@ -30,10 +33,10 @@ export interface MagentoModuleType extends Module {
* export const sdk = initSDK<typeof sdkConfig>(sdkConfig);
* ```
*/
export const magentoModule = (options: ModuleOptions): MagentoModuleType => {
export const magentoModule = (options: ModuleOptions) => {
return {
connector: connector(options),
};
} satisfies Module;
};

export { client } from './client';
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/src/types/ModuleOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ export interface ModuleOptions {
/**
* The SSR API URL of the Magento instance
*/
ssrApiUrl: string;
ssrApiUrl?: string;
}

0 comments on commit ae8a741

Please sign in to comment.