@fyul/embed-sdk 2.7.62 → 2.7.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/dist/cjs/modules/baseFetchModule.d.ts +11 -0
  2. package/dist/cjs/modules/baseFetchModule.js +46 -0
  3. package/dist/cjs/modules/baseModule.d.ts +5 -4
  4. package/dist/cjs/modules/baseModule.js +4 -2
  5. package/dist/cjs/modules/catalog/catalogModule.d.ts +1 -1
  6. package/dist/cjs/modules/catalog/catalogModule.js +11 -2
  7. package/dist/cjs/modules/edm/types/data.types.d.ts +21 -2
  8. package/dist/cjs/modules/eventTypes.d.ts +2 -2
  9. package/dist/cjs/modules/events.d.ts +6 -0
  10. package/dist/cjs/modules/product-publish/events.d.ts +6 -0
  11. package/dist/cjs/modules/product-publish/events.js +3 -0
  12. package/dist/cjs/modules/product-publish/productPublishModule.d.ts +2 -1
  13. package/dist/cjs/modules/product-publish/productPublishModule.js +4 -0
  14. package/dist/cjs/modules/product-publish/productPublishService.d.ts +2 -1
  15. package/dist/cjs/modules/product-publish/productPublishService.js +4 -0
  16. package/dist/cjs/modules/product-publish/types/event/actionEvent.types.d.ts +3 -2
  17. package/dist/cjs/modules/product-publish/types/event/actionEventPayload.types.d.ts +7 -1
  18. package/dist/cjs/modules/product-publish/types/event/resultEvent.types.d.ts +3 -2
  19. package/dist/cjs/modules/product-publish/types/event/resultEventPayload.types.d.ts +2 -1
  20. package/dist/cjs/modules/white-label/types/data.types.d.ts +5 -1
  21. package/dist/cjs/services/authStore.d.ts +10 -0
  22. package/dist/cjs/services/authStore.js +23 -0
  23. package/dist/cjs/services/edm.d.ts +4 -2
  24. package/dist/cjs/services/edm.js +16 -1
  25. package/dist/cjs/services/embed.d.ts +1 -1
  26. package/dist/cjs/services/embed.js +13 -2
  27. package/dist/cjs/services/moduleLoaderService.d.ts +1 -0
  28. package/dist/cjs/services/moduleLoaderService.js +3 -1
  29. package/dist/cjs/services/whiteLabel.js +3 -0
  30. package/dist/cjs/types/event/network/networkEvent.types.d.ts +9 -0
  31. package/dist/cjs/types/event/network/networkEvent.types.js +2 -0
  32. package/dist/cjs/types/module/module.types.d.ts +2 -1
  33. package/dist/cjs/version.d.ts +1 -1
  34. package/dist/cjs/version.js +1 -1
  35. package/dist/esm/modules/baseFetchModule.d.ts +11 -0
  36. package/dist/esm/modules/baseFetchModule.js +42 -0
  37. package/dist/esm/modules/baseModule.d.ts +5 -4
  38. package/dist/esm/modules/baseModule.js +4 -2
  39. package/dist/esm/modules/catalog/catalogModule.d.ts +1 -1
  40. package/dist/esm/modules/catalog/catalogModule.js +11 -2
  41. package/dist/esm/modules/edm/types/data.types.d.ts +21 -2
  42. package/dist/esm/modules/eventTypes.d.ts +2 -2
  43. package/dist/esm/modules/events.d.ts +6 -0
  44. package/dist/esm/modules/product-publish/events.d.ts +6 -0
  45. package/dist/esm/modules/product-publish/events.js +3 -0
  46. package/dist/esm/modules/product-publish/productPublishModule.d.ts +2 -1
  47. package/dist/esm/modules/product-publish/productPublishModule.js +4 -0
  48. package/dist/esm/modules/product-publish/productPublishService.d.ts +2 -1
  49. package/dist/esm/modules/product-publish/productPublishService.js +4 -0
  50. package/dist/esm/modules/product-publish/types/event/actionEvent.types.d.ts +3 -2
  51. package/dist/esm/modules/product-publish/types/event/actionEventPayload.types.d.ts +7 -1
  52. package/dist/esm/modules/product-publish/types/event/resultEvent.types.d.ts +3 -2
  53. package/dist/esm/modules/product-publish/types/event/resultEventPayload.types.d.ts +2 -1
  54. package/dist/esm/modules/white-label/types/data.types.d.ts +5 -1
  55. package/dist/esm/services/authStore.d.ts +10 -0
  56. package/dist/esm/services/authStore.js +19 -0
  57. package/dist/esm/services/edm.d.ts +4 -2
  58. package/dist/esm/services/edm.js +16 -1
  59. package/dist/esm/services/embed.d.ts +1 -1
  60. package/dist/esm/services/embed.js +13 -2
  61. package/dist/esm/services/moduleLoaderService.d.ts +1 -0
  62. package/dist/esm/services/moduleLoaderService.js +3 -1
  63. package/dist/esm/services/whiteLabel.js +3 -0
  64. package/dist/esm/types/event/network/networkEvent.types.d.ts +9 -0
  65. package/dist/esm/types/event/network/networkEvent.types.js +1 -0
  66. package/dist/esm/types/module/module.types.d.ts +2 -1
  67. package/dist/esm/version.d.ts +1 -1
  68. package/dist/esm/version.js +1 -1
  69. package/package.json +1 -1
@@ -0,0 +1,9 @@
1
+ import type { ActionEventPayload } from '../action/actionEventPayload.types';
2
+ import type { ResultEventPayload } from '../result/resultEventPayload.types';
3
+ export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'PATCH' | 'DELETE';
4
+ export interface BaseNetworkRequest<TParams extends ActionEventPayload = undefined, TResponse extends ResultEventPayload = ResultEventPayload> {
5
+ method: HttpMethod;
6
+ path: string;
7
+ params?: TParams;
8
+ _response?: TResponse;
9
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -3,7 +3,7 @@ import { AdjustMockupPayload, AdjustMockupResultPayload, GetMockupsPayload, GetM
3
3
  import { SdkModuleConfigData } from '../../modules/sdk/types';
4
4
  import { GetCatalogCategoriesResultPayload, GetCatalogProductsByIdsPayload, GetCatalogProductsPayload, GetCatalogProductsResultPayload, GetSingleCatalogProductPayload, GetSingleCatalogProductResultPayload } from '../../modules/catalog/types';
5
5
  import { NotificationEventPayload } from '../../types/event/notification/notificationEventPayload.types';
6
- import { DeleteProductsPayload, DeleteProductResultPayload, GetProductPublishPayload, GetSavedProductsPayload, GetSavedProductsResultPayload, ProductPublishData } from '../../modules/product-publish/types';
6
+ import { DeleteProductsPayload, DeleteProductResultPayload, GetProductPublishPayload, GetSavedProductPayload, GetSavedProductResultPayload, GetSavedProductsPayload, GetSavedProductsResultPayload, ProductPublishData } from '../../modules/product-publish/types';
7
7
  import { OnDesignStatusEventPayload, OnErrorEventPayload, OnFilePickerRequestedEventPayload, OnPricingStatusUpdateEventPayload, OnStepStatusUpdateEventPayload } from '../../modules/edm/types/event/broadcastEventPayload.types';
8
8
  import { OnDesignStatusEventPayload as EmbedStudioOnDesignStatusEventPayload, OnErrorEventPayload as EmbedStudioOnErrorEventPayload } from '../../modules/embed-studio/types/event/broadcastEventPayload.types';
9
9
  import { AddImagePayload, AddImageResultPayload, InitializeEdmPayload, NavigateStepPayload, NavigateStepResultPayload, SaveDesignResultPayload, SetStylePayload, SetStyleResultPayload } from '../../modules/edm/types';
@@ -27,6 +27,7 @@ export interface IMockupGenerationModule {
27
27
  }
28
28
  export interface IProductPublishModule {
29
29
  productPublish(data: GetProductPublishPayload): ProductPublishData;
30
+ getSavedProduct(data: GetSavedProductPayload): GetSavedProductResultPayload;
30
31
  getSavedProducts(data: GetSavedProductsPayload): GetSavedProductsResultPayload;
31
32
  deleteProducts(data: DeleteProductsPayload): DeleteProductResultPayload;
32
33
  }
@@ -1 +1 @@
1
- export declare const VERSION: "2.7.62";
1
+ export declare const VERSION: "2.7.64";
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // AUTO-GENERATED
5
- exports.VERSION = '2.7.62';
5
+ exports.VERSION = '2.7.64';
@@ -0,0 +1,11 @@
1
+ import { NotificationEventPayload } from '../types/event/notification/notificationEventPayload.types';
2
+ import { BaseNetworkRequest } from '../types/event/network/networkEvent.types';
3
+ import { ActionEventPayload } from '../types/event/action/actionEventPayload.types';
4
+ import { ResultEventPayload } from '../types/event/result/resultEventPayload.types';
5
+ import { MainModuleKey } from '../services/authStore';
6
+ export declare abstract class BaseFetchModule {
7
+ protected readonly rootUrl: string;
8
+ private readonly authKey;
9
+ protected constructor(rootUrl: string, authKey: MainModuleKey);
10
+ protected sendFetch<TParams extends ActionEventPayload, TResponse extends ResultEventPayload>(request: BaseNetworkRequest<TParams, TResponse>): Promise<TResponse | NotificationEventPayload>;
11
+ }
@@ -0,0 +1,42 @@
1
+ import { AuthStore } from '../services/authStore';
2
+ export class BaseFetchModule {
3
+ rootUrl;
4
+ authKey;
5
+ constructor(rootUrl, authKey) {
6
+ this.rootUrl = rootUrl;
7
+ this.authKey = authKey;
8
+ }
9
+ async sendFetch(request) {
10
+ const { method, path, params } = request;
11
+ const init = { method };
12
+ const headers = {};
13
+ const jwt = AuthStore.getInstance().get(this.authKey);
14
+ if (jwt) {
15
+ headers['Authorization'] = `Bearer ${jwt}`;
16
+ }
17
+ if (params !== undefined) {
18
+ headers['Content-Type'] = 'application/json';
19
+ init.body = JSON.stringify(params);
20
+ }
21
+ if (Object.keys(headers).length) {
22
+ init.headers = headers;
23
+ }
24
+ try {
25
+ const response = await fetch(`${this.rootUrl}${path}`, init);
26
+ if (!response.ok) {
27
+ return {
28
+ status: 'error',
29
+ message: `Fetch failed [${method} ${path}]: ${response.status} ${response.statusText}`,
30
+ };
31
+ }
32
+ return (await response.json());
33
+ }
34
+ catch (e) {
35
+ return {
36
+ status: 'error',
37
+ message: e instanceof Error ? e.message : `Fetch failed [${method} ${path}]`,
38
+ error: e instanceof Error ? e : undefined,
39
+ };
40
+ }
41
+ }
42
+ }
@@ -2,9 +2,10 @@ import { ActionEventName } from '../types/event/action/actionEvent.types';
2
2
  import { ActionEventPayload } from '../types/event/action/actionEventPayload.types';
3
3
  import { ResultEventPayload } from '../types/event/result/resultEventPayload.types';
4
4
  import { NotificationEventPayload } from '../types/event/notification/notificationEventPayload.types';
5
- import type { MODULE_NAMES } from '../modules/moduleNames';
6
- export declare abstract class BaseModule {
7
- protected moduleType: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL;
8
- constructor(moduleType: typeof MODULE_NAMES.SDK | typeof MODULE_NAMES.EDM | typeof MODULE_NAMES.EMBED_STUDIO | typeof MODULE_NAMES.WHITE_LABEL);
5
+ import { BaseFetchModule } from '../modules/baseFetchModule';
6
+ import { MainModuleKey } from '../services/authStore';
7
+ export declare abstract class BaseModule extends BaseFetchModule {
8
+ protected moduleType: MainModuleKey;
9
+ constructor(moduleType: MainModuleKey, apiRoot?: string);
9
10
  protected sendRequest<T extends ResultEventPayload | NotificationEventPayload>(eventName: ActionEventName, eventPayload?: ActionEventPayload): Promise<T>;
10
11
  }
@@ -1,7 +1,9 @@
1
1
  import { EmbedCommunicator } from '../services/embedCommunicator';
2
- export class BaseModule {
2
+ import { BaseFetchModule } from '../modules/baseFetchModule';
3
+ export class BaseModule extends BaseFetchModule {
3
4
  moduleType;
4
- constructor(moduleType) {
5
+ constructor(moduleType, apiRoot) {
6
+ super(apiRoot ?? '', moduleType);
5
7
  this.moduleType = moduleType;
6
8
  }
7
9
  async sendRequest(eventName, eventPayload) {
@@ -3,7 +3,7 @@ import { BaseModule } from '../../modules/baseModule';
3
3
  import { GetCatalogCategoriesResultPayload, GetCatalogProductsByIdsPayload, GetCatalogProductsPayload, GetCatalogProductsResultPayload, GetSingleCatalogProductPayload, GetSingleCatalogProductResultPayload } from './types';
4
4
  import { WithHandledResponses } from '../../helpers/typeHelper.types';
5
5
  export declare class CatalogModule extends BaseModule implements WithHandledResponses<ICatalogModule> {
6
- constructor();
6
+ constructor(baseApiUrl?: string);
7
7
  getProducts(data: GetCatalogProductsPayload): Promise<import("../..").HandledResponse<GetCatalogProductsResultPayload, Error>>;
8
8
  getProductsByIds(data: GetCatalogProductsByIdsPayload): Promise<import("../..").HandledResponse<GetCatalogProductsResultPayload, Error>>;
9
9
  getProduct(data: GetSingleCatalogProductPayload): Promise<import("../..").HandledResponse<GetSingleCatalogProductResultPayload, Error>>;
@@ -2,9 +2,10 @@ import { BaseModule } from '../../modules/baseModule';
2
2
  import { EVENTS_ACTION, } from './types';
3
3
  import { handleResponse } from '../../helpers/responseHandler';
4
4
  import { MODULE_NAMES } from '../../modules/modules';
5
+ import { AuthStore } from '../../services/authStore';
5
6
  export class CatalogModule extends BaseModule {
6
- constructor() {
7
- super(MODULE_NAMES.SDK);
7
+ constructor(baseApiUrl) {
8
+ super(MODULE_NAMES.SDK, baseApiUrl);
8
9
  }
9
10
  async getProducts(data) {
10
11
  const response = await this.sendRequest(EVENTS_ACTION.GET_CATALOG_PRODUCTS, data).catch((e) => e);
@@ -19,6 +20,14 @@ export class CatalogModule extends BaseModule {
19
20
  return handleResponse(response, 'Failed to get catalog products');
20
21
  }
21
22
  async getCategories() {
23
+ const hasJwt = !!AuthStore.getInstance().get(this.moduleType);
24
+ if (hasJwt) {
25
+ const response = await this.sendFetch({
26
+ method: 'POST',
27
+ path: '/v1/sdk/get-catalog-categories',
28
+ });
29
+ return handleResponse(response, 'Failed to get catalog categories');
30
+ }
22
31
  const response = await this.sendRequest(EVENTS_ACTION.GET_CATALOG_CATEGORIES).catch((e) => e);
23
32
  return handleResponse(response, 'Failed to get catalog categories');
24
33
  }
@@ -124,8 +124,7 @@ export type EDMParams = ({
124
124
  elementId: string;
125
125
  element?: null;
126
126
  } & EDMCommonParams);
127
- export interface EDMCommonParams {
128
- nonce: string;
127
+ interface EDMCommonParamsBase {
129
128
  externalProductId: string;
130
129
  iframeClassName?: string;
131
130
  origin?: string;
@@ -136,6 +135,25 @@ export interface EDMCommonParams {
136
135
  };
137
136
  debug?: boolean;
138
137
  }
138
+ interface EDMJwtParams extends EDMCommonParamsBase {
139
+ jwt: string;
140
+ nonce?: never;
141
+ }
142
+ interface EDMNonceParams extends EDMCommonParamsBase {
143
+ /** @deprecated Use jwt instead */
144
+ nonce: string;
145
+ jwt?: never;
146
+ }
147
+ export type EDMCommonParams = EDMJwtParams | EDMNonceParams;
148
+ type EDMElementVariants = {
149
+ element: HTMLElement;
150
+ elementId?: null;
151
+ } | {
152
+ elementId: string;
153
+ element?: null;
154
+ };
155
+ export type EDMParamsWithJwt = EDMElementVariants & EDMJwtParams;
156
+ export type EDMParamsWithNonce = EDMElementVariants & EDMNonceParams;
139
157
  export interface Message {
140
158
  type: string;
141
159
  message: string;
@@ -214,3 +232,4 @@ export interface TOSStepResponse extends OnStepStatusUpdateEvent {
214
232
  stepData: TOSStepData;
215
233
  }
216
234
  export type StepResponse = MockupStepResponse | PricingEditStepResponse | DetailsEditStepResponse | TOSStepResponse;
235
+ export {};
@@ -5,7 +5,7 @@ export declare const EVENT_TYPES: {
5
5
  readonly RESULT: "result";
6
6
  readonly BROADCAST: "broadcast";
7
7
  };
8
- export declare function isAction(event: AnyEvent): event is import("./sdk/types").InitializeSdkAction | import("./sdk/types").LoadModuleAction | import("./mockup-generation/types").GetMockupsAction | import("./mockup-generation/types").GetMoreMockupsAction | import("./mockup-generation/types").AdjustMockupAction | import("./edm/types").InitializeEdmAction | import("./edm/types").SaveDesignAction | import("./edm/types").AddImageAction | import("./edm/types").NavigateStepAction | import("./white-label/types").InitializeWhiteLabelAction | import("./catalog/types").GetCatalogCategoriesAction | import("./catalog/types").GetCatalogProductsByIdsAction | import("./catalog/types").GetCatalogProductsAction | import("./catalog/types").GetSingleCatalogProductAction | import("./product-publish/types").DeleteProductsAction | import("./product-publish/types").GetSavedProductsAction | import("./product-publish/types").GetProductPublishAction | import("./embed-studio/types").InitializeEmbedStudioAction | import("./embed-studio/types").SaveDesignAction;
8
+ export declare function isAction(event: AnyEvent): event is import("./sdk/types").InitializeSdkAction | import("./sdk/types").LoadModuleAction | import("./mockup-generation/types").GetMockupsAction | import("./mockup-generation/types").GetMoreMockupsAction | import("./mockup-generation/types").AdjustMockupAction | import("./edm/types").InitializeEdmAction | import("./edm/types").SaveDesignAction | import("./edm/types").AddImageAction | import("./edm/types").NavigateStepAction | import("./white-label/types").InitializeWhiteLabelAction | import("./catalog/types").GetCatalogCategoriesAction | import("./catalog/types").GetCatalogProductsByIdsAction | import("./catalog/types").GetCatalogProductsAction | import("./catalog/types").GetSingleCatalogProductAction | import("./product-publish/types").DeleteProductsAction | import("./product-publish/types").GetSavedProductAction | import("./product-publish/types").GetSavedProductsAction | import("./product-publish/types").GetProductPublishAction | import("./embed-studio/types").InitializeEmbedStudioAction | import("./embed-studio/types").SaveDesignAction;
9
9
  export declare function isNotification(event: AnyEvent): event is import("..").NotificationEvent;
10
- export declare function isResult(event: AnyEvent): event is import("./catalog/types").GetCatalogProductsResult | import("./catalog/types").GetSingleCatalogProductResult | import("./catalog/types").GetCatalogCategoriesResult | import("./product-publish/types").GetProductPublishResult | import("./product-publish/types").GetSavedProductsResult | import("./product-publish/types").GetSavedProductMockupsResult | import("./product-publish/types").DeleteProductsResult | import("./edm/types").SaveDesignResultEvent | import("./edm/types").AddImageResultEvent | import("./edm/types").SetStyleResultEvent | import("./edm/types").NavigateStepResultEvent | import("./embed-studio/types").SaveDesignResultEvent | import("./mockup-generation/types").GetMockupsResultEvent | import("./mockup-generation/types").GetMoreMockupsResultEvent | import("./mockup-generation/types").AdjustMockupResultEvent | import("./white-label/types").GoToViewResultEvent | import("./white-label/types").GetAvailableRoutesResultEvent;
10
+ export declare function isResult(event: AnyEvent): event is import("./catalog/types").GetCatalogProductsResult | import("./catalog/types").GetSingleCatalogProductResult | import("./catalog/types").GetCatalogCategoriesResult | import("./product-publish/types").GetProductPublishResult | import("./product-publish/types").GetSavedProductsResult | import("./product-publish/types").GetSavedProductMockupsResult | import("./product-publish/types").GetSavedProductResult | import("./product-publish/types").DeleteProductsResult | import("./edm/types").SaveDesignResultEvent | import("./edm/types").AddImageResultEvent | import("./edm/types").SetStyleResultEvent | import("./edm/types").NavigateStepResultEvent | import("./embed-studio/types").SaveDesignResultEvent | import("./mockup-generation/types").GetMockupsResultEvent | import("./mockup-generation/types").GetMoreMockupsResultEvent | import("./mockup-generation/types").AdjustMockupResultEvent | import("./white-label/types").GoToViewResultEvent | import("./white-label/types").GetAvailableRoutesResultEvent;
11
11
  export declare function isBroadcast(event: AnyEvent): event is import("./edm/types/event/broadcastEvent.types").OnDesignStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnPricingStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnFilePickerRequestBroadcast | import("./edm/types/event/broadcastEvent.types").OnStepStatusUpdateBroadcast | import("./edm/types/event/broadcastEvent.types").OnErrorUpdateBroadcast | import("./white-label/types").OnShoppingCartUpdateBroadcast | import("./white-label/types").OnContentSizeChangeBroadcast;
@@ -12,6 +12,7 @@ export declare const ALL_ACTION_EVENTS: {
12
12
  readonly GET_SAVED_PRODUCTS: "actionGetSavedProducts";
13
13
  readonly DELETE_PRODUCTS: "actionDeleteProducts";
14
14
  readonly GET_SAVED_PRODUCT_MOCKUPS: "actionGetSavedProductMockups";
15
+ readonly GET_SAVED_PRODUCT: "actionGetSavedProduct";
15
16
  readonly GET_MOCKUPS: "actionGetMockups";
16
17
  readonly GET_MORE_MOCKUPS: "actionGetMoreMockups";
17
18
  readonly ADJUST_MOCKUP: "actionAdjustMockup";
@@ -36,6 +37,7 @@ export declare const ALL_NOTIFICATION_EVENTS: {
36
37
  readonly GET_SAVED_PRODUCTS_FAILURE: "actionGetSavedProductsFailure";
37
38
  readonly DELETE_PRODUCTS_FAILURE: "actionDeleteProductsFailure";
38
39
  readonly GET_SAVED_PRODUCT_MOCKUPS_FAILURE: "actionGetSavedProductMockupsFailure";
40
+ readonly GET_SAVED_PRODUCT_FAILURE: "actionGetSavedProductFailure";
39
41
  readonly GET_MOCKUPS_FAILURE: "notificationGetMockupsFailure";
40
42
  readonly GET_MORE_MOCKUPS_FAILURE: "notificationGetMoreMockupsFailure";
41
43
  readonly ADJUST_MOCKUP_FAILURE: "actionAdjustMockupFailure";
@@ -55,6 +57,7 @@ export declare const ALL_RESULT_EVENTS: {
55
57
  readonly GET_SAVED_PRODUCTS_RESULT: "resultGetSavedProducts";
56
58
  readonly DELETE_PRODUCTS_RESULT: "resultDeleteProducts";
57
59
  readonly GET_SAVED_PRODUCT_MOCKUPS_RESULT: "resultGetSavedProductMockups";
60
+ readonly GET_SAVED_PRODUCT_RESULT: "resultGetSavedProduct";
58
61
  readonly GET_MOCKUPS_RESULT: "resultGetMockups";
59
62
  readonly GET_MORE_MOCKUPS_RESULT: "resultGetMoreMockups";
60
63
  readonly ADJUST_MOCKUP_RESULT: "resultActionAdjustMockup";
@@ -89,6 +92,7 @@ export declare const ALL_EVENTS: {
89
92
  readonly GET_SAVED_PRODUCTS_RESULT: "resultGetSavedProducts";
90
93
  readonly DELETE_PRODUCTS_RESULT: "resultDeleteProducts";
91
94
  readonly GET_SAVED_PRODUCT_MOCKUPS_RESULT: "resultGetSavedProductMockups";
95
+ readonly GET_SAVED_PRODUCT_RESULT: "resultGetSavedProduct";
92
96
  readonly GET_MOCKUPS_RESULT: "resultGetMockups";
93
97
  readonly GET_MORE_MOCKUPS_RESULT: "resultGetMoreMockups";
94
98
  readonly ADJUST_MOCKUP_RESULT: "resultActionAdjustMockup";
@@ -108,6 +112,7 @@ export declare const ALL_EVENTS: {
108
112
  readonly GET_SAVED_PRODUCTS_FAILURE: "actionGetSavedProductsFailure";
109
113
  readonly DELETE_PRODUCTS_FAILURE: "actionDeleteProductsFailure";
110
114
  readonly GET_SAVED_PRODUCT_MOCKUPS_FAILURE: "actionGetSavedProductMockupsFailure";
115
+ readonly GET_SAVED_PRODUCT_FAILURE: "actionGetSavedProductFailure";
111
116
  readonly GET_MOCKUPS_FAILURE: "notificationGetMockupsFailure";
112
117
  readonly GET_MORE_MOCKUPS_FAILURE: "notificationGetMoreMockupsFailure";
113
118
  readonly ADJUST_MOCKUP_FAILURE: "actionAdjustMockupFailure";
@@ -128,6 +133,7 @@ export declare const ALL_EVENTS: {
128
133
  readonly GET_SAVED_PRODUCTS: "actionGetSavedProducts";
129
134
  readonly DELETE_PRODUCTS: "actionDeleteProducts";
130
135
  readonly GET_SAVED_PRODUCT_MOCKUPS: "actionGetSavedProductMockups";
136
+ readonly GET_SAVED_PRODUCT: "actionGetSavedProduct";
131
137
  readonly GET_MOCKUPS: "actionGetMockups";
132
138
  readonly GET_MORE_MOCKUPS: "actionGetMoreMockups";
133
139
  readonly ADJUST_MOCKUP: "actionAdjustMockup";
@@ -3,30 +3,36 @@ export declare const EVENTS_ACTION: {
3
3
  readonly GET_SAVED_PRODUCTS: "actionGetSavedProducts";
4
4
  readonly DELETE_PRODUCTS: "actionDeleteProducts";
5
5
  readonly GET_SAVED_PRODUCT_MOCKUPS: "actionGetSavedProductMockups";
6
+ readonly GET_SAVED_PRODUCT: "actionGetSavedProduct";
6
7
  };
7
8
  export declare const EVENTS_NOTIFICATION: {
8
9
  readonly GET_PRODUCT_PUBLISH_FAILURE: "actionGetProductPublishFailure";
9
10
  readonly GET_SAVED_PRODUCTS_FAILURE: "actionGetSavedProductsFailure";
10
11
  readonly DELETE_PRODUCTS_FAILURE: "actionDeleteProductsFailure";
11
12
  readonly GET_SAVED_PRODUCT_MOCKUPS_FAILURE: "actionGetSavedProductMockupsFailure";
13
+ readonly GET_SAVED_PRODUCT_FAILURE: "actionGetSavedProductFailure";
12
14
  };
13
15
  export declare const EVENTS_RESULT: {
14
16
  readonly GET_PRODUCT_PUBLISH_RESULT: "resultGetProductPublish";
15
17
  readonly GET_SAVED_PRODUCTS_RESULT: "resultGetSavedProducts";
16
18
  readonly DELETE_PRODUCTS_RESULT: "resultDeleteProducts";
17
19
  readonly GET_SAVED_PRODUCT_MOCKUPS_RESULT: "resultGetSavedProductMockups";
20
+ readonly GET_SAVED_PRODUCT_RESULT: "resultGetSavedProduct";
18
21
  };
19
22
  export declare const EVENTS: {
20
23
  readonly GET_PRODUCT_PUBLISH_RESULT: "resultGetProductPublish";
21
24
  readonly GET_SAVED_PRODUCTS_RESULT: "resultGetSavedProducts";
22
25
  readonly DELETE_PRODUCTS_RESULT: "resultDeleteProducts";
23
26
  readonly GET_SAVED_PRODUCT_MOCKUPS_RESULT: "resultGetSavedProductMockups";
27
+ readonly GET_SAVED_PRODUCT_RESULT: "resultGetSavedProduct";
24
28
  readonly GET_PRODUCT_PUBLISH_FAILURE: "actionGetProductPublishFailure";
25
29
  readonly GET_SAVED_PRODUCTS_FAILURE: "actionGetSavedProductsFailure";
26
30
  readonly DELETE_PRODUCTS_FAILURE: "actionDeleteProductsFailure";
27
31
  readonly GET_SAVED_PRODUCT_MOCKUPS_FAILURE: "actionGetSavedProductMockupsFailure";
32
+ readonly GET_SAVED_PRODUCT_FAILURE: "actionGetSavedProductFailure";
28
33
  readonly PRODUCT_PUBLISH: "actionProductPublish";
29
34
  readonly GET_SAVED_PRODUCTS: "actionGetSavedProducts";
30
35
  readonly DELETE_PRODUCTS: "actionDeleteProducts";
31
36
  readonly GET_SAVED_PRODUCT_MOCKUPS: "actionGetSavedProductMockups";
37
+ readonly GET_SAVED_PRODUCT: "actionGetSavedProduct";
32
38
  };
@@ -3,18 +3,21 @@ export const EVENTS_ACTION = {
3
3
  GET_SAVED_PRODUCTS: 'actionGetSavedProducts',
4
4
  DELETE_PRODUCTS: 'actionDeleteProducts',
5
5
  GET_SAVED_PRODUCT_MOCKUPS: 'actionGetSavedProductMockups',
6
+ GET_SAVED_PRODUCT: 'actionGetSavedProduct',
6
7
  };
7
8
  export const EVENTS_NOTIFICATION = {
8
9
  GET_PRODUCT_PUBLISH_FAILURE: 'actionGetProductPublishFailure',
9
10
  GET_SAVED_PRODUCTS_FAILURE: 'actionGetSavedProductsFailure',
10
11
  DELETE_PRODUCTS_FAILURE: 'actionDeleteProductsFailure',
11
12
  GET_SAVED_PRODUCT_MOCKUPS_FAILURE: 'actionGetSavedProductMockupsFailure',
13
+ GET_SAVED_PRODUCT_FAILURE: 'actionGetSavedProductFailure',
12
14
  };
13
15
  export const EVENTS_RESULT = {
14
16
  GET_PRODUCT_PUBLISH_RESULT: 'resultGetProductPublish',
15
17
  GET_SAVED_PRODUCTS_RESULT: 'resultGetSavedProducts',
16
18
  DELETE_PRODUCTS_RESULT: 'resultDeleteProducts',
17
19
  GET_SAVED_PRODUCT_MOCKUPS_RESULT: 'resultGetSavedProductMockups',
20
+ GET_SAVED_PRODUCT_RESULT: 'resultGetSavedProduct',
18
21
  };
19
22
  export const EVENTS = {
20
23
  ...EVENTS_ACTION,
@@ -1,10 +1,11 @@
1
1
  import { IProductPublishModule } from '../../types/module/module.types';
2
2
  import { BaseModule } from '../../modules/baseModule';
3
- import { DeleteProductsPayload, DeleteProductResultPayload, GetProductPublishPayload, GetSavedProductsPayload, GetSavedProductsResultPayload, GetSavedProductMockupsPayload, GetSavedProductMockupsResultPayload, ProductPublishData } from '../../modules/product-publish/types';
3
+ import { DeleteProductsPayload, DeleteProductResultPayload, GetProductPublishPayload, GetSavedProductPayload, GetSavedProductsPayload, GetSavedProductsResultPayload, GetSavedProductMockupsPayload, GetSavedProductMockupsResultPayload, ProductPublishData } from '../../modules/product-publish/types';
4
4
  import { WithHandledResponses } from '../../helpers/typeHelper.types';
5
5
  export declare class ProductPublishModule extends BaseModule implements WithHandledResponses<IProductPublishModule> {
6
6
  constructor();
7
7
  productPublish(data: GetProductPublishPayload): Promise<import("../..").HandledResponse<ProductPublishData, Error>>;
8
+ getSavedProduct(data?: GetSavedProductPayload): Promise<import("../..").HandledResponse<import("../../modules/product-publish/types").SavedProductListItem, Error>>;
8
9
  getSavedProducts(data?: GetSavedProductsPayload): Promise<import("../..").HandledResponse<GetSavedProductsResultPayload, Error>>;
9
10
  deleteProducts(data: DeleteProductsPayload): Promise<import("../..").HandledResponse<DeleteProductResultPayload, Error>>;
10
11
  getSavedProductMockups(data: GetSavedProductMockupsPayload): Promise<import("../..").HandledResponse<GetSavedProductMockupsResultPayload, Error>>;
@@ -10,6 +10,10 @@ export class ProductPublishModule extends BaseModule {
10
10
  const response = await this.sendRequest(EVENTS_ACTION.PRODUCT_PUBLISH, data).catch((e) => e);
11
11
  return handleResponse(response, 'Failed to publish products');
12
12
  }
13
+ async getSavedProduct(data) {
14
+ const response = await this.sendRequest(EVENTS_ACTION.GET_SAVED_PRODUCT, data).catch((e) => e);
15
+ return handleResponse(response, 'getSavedProduct');
16
+ }
13
17
  async getSavedProducts(data) {
14
18
  const response = await this.sendRequest(EVENTS_ACTION.GET_SAVED_PRODUCTS, data).catch((e) => e);
15
19
  return handleResponse(response, 'getSavedProducts');
@@ -1,8 +1,9 @@
1
1
  import { BaseModuleService } from '../../modules/baseModuleService';
2
- import { DeleteProductsPayload, GetProductPublishPayload, GetSavedProductsPayload, GetSavedProductMockupsPayload } from '../../modules/product-publish/types';
2
+ import { DeleteProductsPayload, GetProductPublishPayload, GetSavedProductPayload, GetSavedProductsPayload, GetSavedProductMockupsPayload } from '../../modules/product-publish/types';
3
3
  export declare class ProductPublishService extends BaseModuleService {
4
4
  private getProductPublishModule;
5
5
  productPublish(data: GetProductPublishPayload): Promise<import("../..").HandledResponse<import("../../modules/product-publish/types").ProductPublishData, Error>>;
6
+ getSavedProduct(data?: GetSavedProductPayload): Promise<import("../..").HandledResponse<import("../../modules/product-publish/types").SavedProductListItem, Error>>;
6
7
  getSavedProducts(data?: GetSavedProductsPayload): Promise<import("../..").HandledResponse<import("../../modules/product-publish/types").GetSavedProductsResultPayload, Error>>;
7
8
  deleteProducts(data: DeleteProductsPayload): Promise<import("../..").HandledResponse<import("../../modules/product-publish/types").DeleteProductResultPayload, Error>>;
8
9
  getSavedProductMockups(data: GetSavedProductMockupsPayload): Promise<import("../..").HandledResponse<import("../../modules/product-publish/types").GetSavedProductMockupsResultPayload, Error>>;
@@ -8,6 +8,10 @@ export class ProductPublishService extends BaseModuleService {
8
8
  const module = await this.getProductPublishModule();
9
9
  return await module.productPublish(data);
10
10
  }
11
+ async getSavedProduct(data) {
12
+ const module = await this.getProductPublishModule();
13
+ return await module.getSavedProduct(data);
14
+ }
11
15
  async getSavedProducts(data) {
12
16
  const module = await this.getProductPublishModule();
13
17
  return await module.getSavedProducts(data);
@@ -1,7 +1,8 @@
1
1
  import { EVENTS_ACTION } from '../../../../modules/product-publish/events';
2
- import type { DeleteProductsPayload, GetProductPublishPayload, GetSavedProductsPayload } from '../../../../modules/product-publish/types/event/actionEventPayload.types';
2
+ import type { DeleteProductsPayload, GetProductPublishPayload, GetSavedProductPayload, GetSavedProductsPayload } from '../../../../modules/product-publish/types/event/actionEventPayload.types';
3
3
  import { BaseActionEvent } from '../../../../types/event/action/actionEvent.types';
4
4
  export type GetProductPublishAction = BaseActionEvent<typeof EVENTS_ACTION.PRODUCT_PUBLISH, GetProductPublishPayload>;
5
5
  export type GetSavedProductsAction = BaseActionEvent<typeof EVENTS_ACTION.GET_SAVED_PRODUCTS, GetSavedProductsPayload>;
6
+ export type GetSavedProductAction = BaseActionEvent<typeof EVENTS_ACTION.GET_SAVED_PRODUCT, GetSavedProductPayload>;
6
7
  export type DeleteProductsAction = BaseActionEvent<typeof EVENTS_ACTION.DELETE_PRODUCTS, DeleteProductsPayload>;
7
- export type ActionEvent = DeleteProductsAction | GetSavedProductsAction | GetProductPublishAction;
8
+ export type ActionEvent = DeleteProductsAction | GetSavedProductAction | GetSavedProductsAction | GetProductPublishAction;
@@ -14,6 +14,7 @@ export interface GetProductPublishPayload {
14
14
  designOptions?: DesignOption[];
15
15
  }
16
16
  export interface GetSavedProductsPayload {
17
+ /** @deprecated use GetSavedProductPayload */
17
18
  externalProductId?: string;
18
19
  limit?: number;
19
20
  offset?: number;
@@ -21,11 +22,16 @@ export interface GetSavedProductsPayload {
21
22
  * if updated data is needed (on the same page, after editing, for example) */
22
23
  forceRefresh?: boolean;
23
24
  }
25
+ export interface GetSavedProductPayload {
26
+ externalProductId: string;
27
+ forceRefresh?: boolean;
28
+ }
24
29
  export interface DeleteProductsPayload {
25
30
  productTemplateIds: number[];
26
31
  }
27
32
  export interface GetSavedProductMockupsPayload {
28
33
  externalProductId: string;
29
34
  variantId?: number;
35
+ forceRefresh?: boolean;
30
36
  }
31
- export type ActionEventPayload = DeleteProductsPayload | GetSavedProductsPayload | GetProductPublishPayload | GetSavedProductMockupsPayload;
37
+ export type ActionEventPayload = DeleteProductsPayload | GetSavedProductPayload | GetSavedProductsPayload | GetProductPublishPayload | GetSavedProductMockupsPayload;
@@ -1,8 +1,9 @@
1
1
  import type { EVENTS_RESULT } from '../../../../modules/product-publish/events';
2
- import type { DeleteProductResultPayload, GetSavedProductsResultPayload, GetSavedProductMockupsResultPayload, ProductPublishData } from '../../../../modules/product-publish/types/event/resultEventPayload.types';
2
+ import type { DeleteProductResultPayload, GetSavedProductResultPayload, GetSavedProductsResultPayload, GetSavedProductMockupsResultPayload, ProductPublishData } from '../../../../modules/product-publish/types/event/resultEventPayload.types';
3
3
  import { BaseResultEvent } from '../../../../types/event/result/resultEvent.types';
4
4
  export type GetProductPublishResult = BaseResultEvent<typeof EVENTS_RESULT.GET_PRODUCT_PUBLISH_RESULT, ProductPublishData>;
5
5
  export type GetSavedProductsResult = BaseResultEvent<typeof EVENTS_RESULT.GET_SAVED_PRODUCTS_RESULT, GetSavedProductsResultPayload>;
6
6
  export type GetSavedProductMockupsResult = BaseResultEvent<typeof EVENTS_RESULT.GET_SAVED_PRODUCT_MOCKUPS_RESULT, GetSavedProductMockupsResultPayload>;
7
+ export type GetSavedProductResult = BaseResultEvent<typeof EVENTS_RESULT.GET_SAVED_PRODUCT_RESULT, GetSavedProductResultPayload>;
7
8
  export type DeleteProductsResult = BaseResultEvent<typeof EVENTS_RESULT.DELETE_PRODUCTS_RESULT, DeleteProductResultPayload>;
8
- export type ResultEvent = DeleteProductsResult | GetSavedProductsResult | GetSavedProductMockupsResult | GetProductPublishResult;
9
+ export type ResultEvent = DeleteProductsResult | GetSavedProductResult | GetSavedProductsResult | GetSavedProductMockupsResult | GetProductPublishResult;
@@ -15,7 +15,8 @@ export interface GetSavedProductsResultPayload {
15
15
  export interface DeleteProductResultPayload {
16
16
  success: boolean;
17
17
  }
18
+ export type GetSavedProductResultPayload = SavedProductListItem;
18
19
  export interface GetSavedProductMockupsResultPayload {
19
20
  mockups: MockupItem[];
20
21
  }
21
- export type ProductPublishResultPayload = DeleteProductResultPayload | GetSavedProductsResultPayload | ProductPublishData | GetSavedProductMockupsResultPayload;
22
+ export type ProductPublishResultPayload = DeleteProductResultPayload | GetSavedProductResultPayload | GetSavedProductsResultPayload | ProductPublishData | GetSavedProductMockupsResultPayload;
@@ -45,5 +45,9 @@ export interface JWTData {
45
45
  scp: string[];
46
46
  iat: number;
47
47
  exp: number;
48
- cid: string;
48
+ cid?: string;
49
+ mka?: number;
50
+ mkt?: string;
51
+ pid?: string;
52
+ cur?: string;
49
53
  }
@@ -0,0 +1,10 @@
1
+ import { MODULE_DEPENDENCY_MAP } from '../modules/modules';
2
+ export type MainModuleKey = (typeof MODULE_DEPENDENCY_MAP)[keyof typeof MODULE_DEPENDENCY_MAP];
3
+ export declare class AuthStore {
4
+ private static instance;
5
+ private tokens;
6
+ static getInstance(): AuthStore;
7
+ set(key: MainModuleKey, jwt: string): void;
8
+ get(key: MainModuleKey): string | undefined;
9
+ delete(key: MainModuleKey): void;
10
+ }
@@ -0,0 +1,19 @@
1
+ export class AuthStore {
2
+ static instance;
3
+ tokens = new Map();
4
+ static getInstance() {
5
+ if (!AuthStore.instance) {
6
+ AuthStore.instance = new AuthStore();
7
+ }
8
+ return AuthStore.instance;
9
+ }
10
+ set(key, jwt) {
11
+ this.tokens.set(key, jwt);
12
+ }
13
+ get(key) {
14
+ return this.tokens.get(key);
15
+ }
16
+ delete(key) {
17
+ this.tokens.delete(key);
18
+ }
19
+ }
@@ -1,4 +1,4 @@
1
- import { EDMConfig, EDMParams } from '../modules/edm/types/data.types';
1
+ import { EDMConfig, EDMParamsWithJwt, EDMParamsWithNonce } from '../modules/edm/types/data.types';
2
2
  import { EdmBroadcastModule } from '../modules/edm/edmBroadcastModule';
3
3
  import { BroadcastListeners } from '../modules/edm/types/event/broadcastEvent.types';
4
4
  import type { AddImagePayload, NavigateStepPayload, SetStylePayload } from '../modules/edm/types';
@@ -12,7 +12,9 @@ export declare class EDM {
12
12
  private communicator;
13
13
  private moduleLoader;
14
14
  private initialized;
15
- constructor(params: EDMParams, config?: EDMConfig | undefined, callbacks?: Partial<BroadcastListeners>);
15
+ constructor(params: EDMParamsWithJwt, config?: EDMConfig, callbacks?: Partial<BroadcastListeners>);
16
+ /** @deprecated Use jwt instead of nonce */
17
+ constructor(params: EDMParamsWithNonce, config?: EDMConfig, callbacks?: Partial<BroadcastListeners>);
16
18
  init(): Promise<void>;
17
19
  saveDesign(): Promise<import("..").HandledResponse<import("../modules/edm/types").SaveDesignResultPayload, Error>>;
18
20
  setStyle(payload: SetStylePayload): Promise<import("..").HandledResponse<import("../modules/edm/types").SetStyleResultPayload, Error>>;
@@ -6,6 +6,8 @@ import { MODULE_NAMES } from '../modules/moduleNames';
6
6
  import { VERSION } from '../version';
7
7
  import { EdmBroadcastModule } from '../modules/edm/edmBroadcastModule';
8
8
  import { EDM_BROADCAST_EVENT_MAP } from '../types/event/broadcast/broadcastEventMap';
9
+ import { parseJwt } from '../helpers/jwtDecoder';
10
+ import { AuthStore } from '../services/authStore';
9
11
  export class EDM {
10
12
  params;
11
13
  config;
@@ -20,7 +22,19 @@ export class EDM {
20
22
  constructor(params, config, callbacks) {
21
23
  this.params = params;
22
24
  this.config = config;
23
- this.nonce = params.nonce;
25
+ if (params.jwt !== undefined) {
26
+ const { data, error } = parseJwt(params.jwt);
27
+ if (error) {
28
+ throw new Error('Failed to decode JWT');
29
+ }
30
+ this.nonce = data.nce;
31
+ }
32
+ else {
33
+ this.nonce = params.nonce;
34
+ }
35
+ if (params.jwt !== undefined) {
36
+ AuthStore.getInstance().set(MODULE_NAMES.EDM, params.jwt);
37
+ }
24
38
  EDM.broadCastEventHandler = new EdmBroadcastModule(callbacks);
25
39
  this.communicator.registerBroadcastDispatcher(MODULE_NAMES.EDM, EDM_BROADCAST_EVENT_MAP);
26
40
  setLoggerState(params?.debug ?? false, SOURCES.EDM);
@@ -89,6 +103,7 @@ export class EDM {
89
103
  }
90
104
  this.communicator.cleanup();
91
105
  this.moduleLoader.clearCache();
106
+ AuthStore.getInstance().delete(MODULE_NAMES.EDM);
92
107
  this.initialized = false;
93
108
  EDM.broadCastEventHandler = null;
94
109
  }
@@ -13,7 +13,7 @@ export declare class Embed {
13
13
  readonly catalog: CatalogService;
14
14
  readonly mockup: MockupService;
15
15
  readonly publish: ProductPublishService;
16
- constructor(nonce: string, config?: SdkConfig | undefined);
16
+ constructor(jwt: string, config?: SdkConfig | undefined);
17
17
  init(): Promise<void>;
18
18
  destroy(): void;
19
19
  getNonce(): string;
@@ -7,6 +7,8 @@ import { ProductPublishService } from '../modules/product-publish/productPublish
7
7
  import { LOG_TYPES, logEmbedMessage, setLoggerState, SOURCES, } from '../helpers/messageLogger';
8
8
  import { MODULE_NAMES } from '../modules/modules';
9
9
  import { VERSION } from '../version';
10
+ import { parseJwt } from '../helpers/jwtDecoder';
11
+ import { AuthStore } from '../services/authStore';
10
12
  export class Embed {
11
13
  config;
12
14
  static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.sdkUrl ??
@@ -20,9 +22,17 @@ export class Embed {
20
22
  catalog;
21
23
  mockup;
22
24
  publish;
23
- constructor(nonce, config) {
25
+ constructor(jwt, config) {
24
26
  this.config = config;
25
- this.nonce = nonce;
27
+ const { data, error } = parseJwt(jwt);
28
+ if (error) {
29
+ // If decoding fails, it means that regular nonce was passed, for now leave as is till deprecation for nonce is finished
30
+ this.nonce = jwt;
31
+ }
32
+ else {
33
+ this.nonce = data.nce;
34
+ AuthStore.getInstance().set(MODULE_NAMES.SDK, jwt);
35
+ }
26
36
  setLoggerState(config?.debug ?? false, SOURCES.SDK);
27
37
  // Initialize services
28
38
  this.catalog = new CatalogService();
@@ -75,6 +85,7 @@ export class Embed {
75
85
  }
76
86
  this.communicator.cleanup();
77
87
  this.moduleLoader.clearCache();
88
+ AuthStore.getInstance().delete(MODULE_NAMES.SDK);
78
89
  this.initialized = false;
79
90
  }
80
91
  getNonce() {
@@ -4,6 +4,7 @@ import { ModuleConfig, ModuleConfigData } from '../types/module/moduleConfig.typ
4
4
  export type ModuleInstance = InstanceType<(typeof MODULES)[keyof typeof MODULES]>;
5
5
  export declare class ModuleLoaderService {
6
6
  private static instance;
7
+ static BASE_API_URL: string;
7
8
  private communicator;
8
9
  private moduleCache;
9
10
  static getInstance(): ModuleLoaderService;