@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.
- package/dist/cjs/modules/baseFetchModule.d.ts +11 -0
- package/dist/cjs/modules/baseFetchModule.js +46 -0
- package/dist/cjs/modules/baseModule.d.ts +5 -4
- package/dist/cjs/modules/baseModule.js +4 -2
- package/dist/cjs/modules/catalog/catalogModule.d.ts +1 -1
- package/dist/cjs/modules/catalog/catalogModule.js +11 -2
- package/dist/cjs/modules/edm/types/data.types.d.ts +21 -2
- package/dist/cjs/modules/eventTypes.d.ts +2 -2
- package/dist/cjs/modules/events.d.ts +6 -0
- package/dist/cjs/modules/product-publish/events.d.ts +6 -0
- package/dist/cjs/modules/product-publish/events.js +3 -0
- package/dist/cjs/modules/product-publish/productPublishModule.d.ts +2 -1
- package/dist/cjs/modules/product-publish/productPublishModule.js +4 -0
- package/dist/cjs/modules/product-publish/productPublishService.d.ts +2 -1
- package/dist/cjs/modules/product-publish/productPublishService.js +4 -0
- package/dist/cjs/modules/product-publish/types/event/actionEvent.types.d.ts +3 -2
- package/dist/cjs/modules/product-publish/types/event/actionEventPayload.types.d.ts +7 -1
- package/dist/cjs/modules/product-publish/types/event/resultEvent.types.d.ts +3 -2
- package/dist/cjs/modules/product-publish/types/event/resultEventPayload.types.d.ts +2 -1
- package/dist/cjs/modules/white-label/types/data.types.d.ts +5 -1
- package/dist/cjs/services/authStore.d.ts +10 -0
- package/dist/cjs/services/authStore.js +23 -0
- package/dist/cjs/services/edm.d.ts +4 -2
- package/dist/cjs/services/edm.js +16 -1
- package/dist/cjs/services/embed.d.ts +1 -1
- package/dist/cjs/services/embed.js +13 -2
- package/dist/cjs/services/moduleLoaderService.d.ts +1 -0
- package/dist/cjs/services/moduleLoaderService.js +3 -1
- package/dist/cjs/services/whiteLabel.js +3 -0
- package/dist/cjs/types/event/network/networkEvent.types.d.ts +9 -0
- package/dist/cjs/types/event/network/networkEvent.types.js +2 -0
- package/dist/cjs/types/module/module.types.d.ts +2 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/modules/baseFetchModule.d.ts +11 -0
- package/dist/esm/modules/baseFetchModule.js +42 -0
- package/dist/esm/modules/baseModule.d.ts +5 -4
- package/dist/esm/modules/baseModule.js +4 -2
- package/dist/esm/modules/catalog/catalogModule.d.ts +1 -1
- package/dist/esm/modules/catalog/catalogModule.js +11 -2
- package/dist/esm/modules/edm/types/data.types.d.ts +21 -2
- package/dist/esm/modules/eventTypes.d.ts +2 -2
- package/dist/esm/modules/events.d.ts +6 -0
- package/dist/esm/modules/product-publish/events.d.ts +6 -0
- package/dist/esm/modules/product-publish/events.js +3 -0
- package/dist/esm/modules/product-publish/productPublishModule.d.ts +2 -1
- package/dist/esm/modules/product-publish/productPublishModule.js +4 -0
- package/dist/esm/modules/product-publish/productPublishService.d.ts +2 -1
- package/dist/esm/modules/product-publish/productPublishService.js +4 -0
- package/dist/esm/modules/product-publish/types/event/actionEvent.types.d.ts +3 -2
- package/dist/esm/modules/product-publish/types/event/actionEventPayload.types.d.ts +7 -1
- package/dist/esm/modules/product-publish/types/event/resultEvent.types.d.ts +3 -2
- package/dist/esm/modules/product-publish/types/event/resultEventPayload.types.d.ts +2 -1
- package/dist/esm/modules/white-label/types/data.types.d.ts +5 -1
- package/dist/esm/services/authStore.d.ts +10 -0
- package/dist/esm/services/authStore.js +19 -0
- package/dist/esm/services/edm.d.ts +4 -2
- package/dist/esm/services/edm.js +16 -1
- package/dist/esm/services/embed.d.ts +1 -1
- package/dist/esm/services/embed.js +13 -2
- package/dist/esm/services/moduleLoaderService.d.ts +1 -0
- package/dist/esm/services/moduleLoaderService.js +3 -1
- package/dist/esm/services/whiteLabel.js +3 -0
- package/dist/esm/types/event/network/networkEvent.types.d.ts +9 -0
- package/dist/esm/types/event/network/networkEvent.types.js +1 -0
- package/dist/esm/types/module/module.types.d.ts +2 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/package.json +1 -1
|
@@ -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,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseFetchModule = void 0;
|
|
4
|
+
const authStore_1 = require("../services/authStore");
|
|
5
|
+
class BaseFetchModule {
|
|
6
|
+
rootUrl;
|
|
7
|
+
authKey;
|
|
8
|
+
constructor(rootUrl, authKey) {
|
|
9
|
+
this.rootUrl = rootUrl;
|
|
10
|
+
this.authKey = authKey;
|
|
11
|
+
}
|
|
12
|
+
async sendFetch(request) {
|
|
13
|
+
const { method, path, params } = request;
|
|
14
|
+
const init = { method };
|
|
15
|
+
const headers = {};
|
|
16
|
+
const jwt = authStore_1.AuthStore.getInstance().get(this.authKey);
|
|
17
|
+
if (jwt) {
|
|
18
|
+
headers['Authorization'] = `Bearer ${jwt}`;
|
|
19
|
+
}
|
|
20
|
+
if (params !== undefined) {
|
|
21
|
+
headers['Content-Type'] = 'application/json';
|
|
22
|
+
init.body = JSON.stringify(params);
|
|
23
|
+
}
|
|
24
|
+
if (Object.keys(headers).length) {
|
|
25
|
+
init.headers = headers;
|
|
26
|
+
}
|
|
27
|
+
try {
|
|
28
|
+
const response = await fetch(`${this.rootUrl}${path}`, init);
|
|
29
|
+
if (!response.ok) {
|
|
30
|
+
return {
|
|
31
|
+
status: 'error',
|
|
32
|
+
message: `Fetch failed [${method} ${path}]: ${response.status} ${response.statusText}`,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return (await response.json());
|
|
36
|
+
}
|
|
37
|
+
catch (e) {
|
|
38
|
+
return {
|
|
39
|
+
status: 'error',
|
|
40
|
+
message: e instanceof Error ? e.message : `Fetch failed [${method} ${path}]`,
|
|
41
|
+
error: e instanceof Error ? e : undefined,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.BaseFetchModule = BaseFetchModule;
|
|
@@ -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
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
}
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseModule = void 0;
|
|
4
4
|
const embedCommunicator_1 = require("../services/embedCommunicator");
|
|
5
|
-
|
|
5
|
+
const baseFetchModule_1 = require("../modules/baseFetchModule");
|
|
6
|
+
class BaseModule extends baseFetchModule_1.BaseFetchModule {
|
|
6
7
|
moduleType;
|
|
7
|
-
constructor(moduleType) {
|
|
8
|
+
constructor(moduleType, apiRoot) {
|
|
9
|
+
super(apiRoot ?? '', moduleType);
|
|
8
10
|
this.moduleType = moduleType;
|
|
9
11
|
}
|
|
10
12
|
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>>;
|
|
@@ -5,9 +5,10 @@ const baseModule_1 = require("../../modules/baseModule");
|
|
|
5
5
|
const types_1 = require("./types");
|
|
6
6
|
const responseHandler_1 = require("../../helpers/responseHandler");
|
|
7
7
|
const modules_1 = require("../../modules/modules");
|
|
8
|
+
const authStore_1 = require("../../services/authStore");
|
|
8
9
|
class CatalogModule extends baseModule_1.BaseModule {
|
|
9
|
-
constructor() {
|
|
10
|
-
super(modules_1.MODULE_NAMES.SDK);
|
|
10
|
+
constructor(baseApiUrl) {
|
|
11
|
+
super(modules_1.MODULE_NAMES.SDK, baseApiUrl);
|
|
11
12
|
}
|
|
12
13
|
async getProducts(data) {
|
|
13
14
|
const response = await this.sendRequest(types_1.EVENTS_ACTION.GET_CATALOG_PRODUCTS, data).catch((e) => e);
|
|
@@ -22,6 +23,14 @@ class CatalogModule extends baseModule_1.BaseModule {
|
|
|
22
23
|
return (0, responseHandler_1.handleResponse)(response, 'Failed to get catalog products');
|
|
23
24
|
}
|
|
24
25
|
async getCategories() {
|
|
26
|
+
const hasJwt = !!authStore_1.AuthStore.getInstance().get(this.moduleType);
|
|
27
|
+
if (hasJwt) {
|
|
28
|
+
const response = await this.sendFetch({
|
|
29
|
+
method: 'POST',
|
|
30
|
+
path: '/v1/sdk/get-catalog-categories',
|
|
31
|
+
});
|
|
32
|
+
return (0, responseHandler_1.handleResponse)(response, 'Failed to get catalog categories');
|
|
33
|
+
}
|
|
25
34
|
const response = await this.sendRequest(types_1.EVENTS_ACTION.GET_CATALOG_CATEGORIES).catch((e) => e);
|
|
26
35
|
return (0, responseHandler_1.handleResponse)(response, 'Failed to get catalog categories');
|
|
27
36
|
}
|
|
@@ -124,8 +124,7 @@ export type EDMParams = ({
|
|
|
124
124
|
elementId: string;
|
|
125
125
|
element?: null;
|
|
126
126
|
} & EDMCommonParams);
|
|
127
|
-
|
|
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
|
};
|
|
@@ -6,18 +6,21 @@ exports.EVENTS_ACTION = {
|
|
|
6
6
|
GET_SAVED_PRODUCTS: 'actionGetSavedProducts',
|
|
7
7
|
DELETE_PRODUCTS: 'actionDeleteProducts',
|
|
8
8
|
GET_SAVED_PRODUCT_MOCKUPS: 'actionGetSavedProductMockups',
|
|
9
|
+
GET_SAVED_PRODUCT: 'actionGetSavedProduct',
|
|
9
10
|
};
|
|
10
11
|
exports.EVENTS_NOTIFICATION = {
|
|
11
12
|
GET_PRODUCT_PUBLISH_FAILURE: 'actionGetProductPublishFailure',
|
|
12
13
|
GET_SAVED_PRODUCTS_FAILURE: 'actionGetSavedProductsFailure',
|
|
13
14
|
DELETE_PRODUCTS_FAILURE: 'actionDeleteProductsFailure',
|
|
14
15
|
GET_SAVED_PRODUCT_MOCKUPS_FAILURE: 'actionGetSavedProductMockupsFailure',
|
|
16
|
+
GET_SAVED_PRODUCT_FAILURE: 'actionGetSavedProductFailure',
|
|
15
17
|
};
|
|
16
18
|
exports.EVENTS_RESULT = {
|
|
17
19
|
GET_PRODUCT_PUBLISH_RESULT: 'resultGetProductPublish',
|
|
18
20
|
GET_SAVED_PRODUCTS_RESULT: 'resultGetSavedProducts',
|
|
19
21
|
DELETE_PRODUCTS_RESULT: 'resultDeleteProducts',
|
|
20
22
|
GET_SAVED_PRODUCT_MOCKUPS_RESULT: 'resultGetSavedProductMockups',
|
|
23
|
+
GET_SAVED_PRODUCT_RESULT: 'resultGetSavedProduct',
|
|
21
24
|
};
|
|
22
25
|
exports.EVENTS = {
|
|
23
26
|
...exports.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>>;
|
|
@@ -13,6 +13,10 @@ class ProductPublishModule extends baseModule_1.BaseModule {
|
|
|
13
13
|
const response = await this.sendRequest(types_1.EVENTS_ACTION.PRODUCT_PUBLISH, data).catch((e) => e);
|
|
14
14
|
return (0, responseHandler_1.handleResponse)(response, 'Failed to publish products');
|
|
15
15
|
}
|
|
16
|
+
async getSavedProduct(data) {
|
|
17
|
+
const response = await this.sendRequest(types_1.EVENTS_ACTION.GET_SAVED_PRODUCT, data).catch((e) => e);
|
|
18
|
+
return (0, responseHandler_1.handleResponse)(response, 'getSavedProduct');
|
|
19
|
+
}
|
|
16
20
|
async getSavedProducts(data) {
|
|
17
21
|
const response = await this.sendRequest(types_1.EVENTS_ACTION.GET_SAVED_PRODUCTS, data).catch((e) => e);
|
|
18
22
|
return (0, responseHandler_1.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>>;
|
|
@@ -11,6 +11,10 @@ class ProductPublishService extends baseModuleService_1.BaseModuleService {
|
|
|
11
11
|
const module = await this.getProductPublishModule();
|
|
12
12
|
return await module.productPublish(data);
|
|
13
13
|
}
|
|
14
|
+
async getSavedProduct(data) {
|
|
15
|
+
const module = await this.getProductPublishModule();
|
|
16
|
+
return await module.getSavedProduct(data);
|
|
17
|
+
}
|
|
14
18
|
async getSavedProducts(data) {
|
|
15
19
|
const module = await this.getProductPublishModule();
|
|
16
20
|
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;
|
|
@@ -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,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthStore = void 0;
|
|
4
|
+
class AuthStore {
|
|
5
|
+
static instance;
|
|
6
|
+
tokens = new Map();
|
|
7
|
+
static getInstance() {
|
|
8
|
+
if (!AuthStore.instance) {
|
|
9
|
+
AuthStore.instance = new AuthStore();
|
|
10
|
+
}
|
|
11
|
+
return AuthStore.instance;
|
|
12
|
+
}
|
|
13
|
+
set(key, jwt) {
|
|
14
|
+
this.tokens.set(key, jwt);
|
|
15
|
+
}
|
|
16
|
+
get(key) {
|
|
17
|
+
return this.tokens.get(key);
|
|
18
|
+
}
|
|
19
|
+
delete(key) {
|
|
20
|
+
this.tokens.delete(key);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.AuthStore = AuthStore;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EDMConfig,
|
|
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:
|
|
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>>;
|
package/dist/cjs/services/edm.js
CHANGED
|
@@ -9,6 +9,8 @@ const moduleNames_1 = require("../modules/moduleNames");
|
|
|
9
9
|
const version_1 = require("../version");
|
|
10
10
|
const edmBroadcastModule_1 = require("../modules/edm/edmBroadcastModule");
|
|
11
11
|
const broadcastEventMap_1 = require("../types/event/broadcast/broadcastEventMap");
|
|
12
|
+
const jwtDecoder_1 = require("../helpers/jwtDecoder");
|
|
13
|
+
const authStore_1 = require("../services/authStore");
|
|
12
14
|
class EDM {
|
|
13
15
|
params;
|
|
14
16
|
config;
|
|
@@ -23,7 +25,19 @@ class EDM {
|
|
|
23
25
|
constructor(params, config, callbacks) {
|
|
24
26
|
this.params = params;
|
|
25
27
|
this.config = config;
|
|
26
|
-
|
|
28
|
+
if (params.jwt !== undefined) {
|
|
29
|
+
const { data, error } = (0, jwtDecoder_1.parseJwt)(params.jwt);
|
|
30
|
+
if (error) {
|
|
31
|
+
throw new Error('Failed to decode JWT');
|
|
32
|
+
}
|
|
33
|
+
this.nonce = data.nce;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.nonce = params.nonce;
|
|
37
|
+
}
|
|
38
|
+
if (params.jwt !== undefined) {
|
|
39
|
+
authStore_1.AuthStore.getInstance().set(moduleNames_1.MODULE_NAMES.EDM, params.jwt);
|
|
40
|
+
}
|
|
27
41
|
EDM.broadCastEventHandler = new edmBroadcastModule_1.EdmBroadcastModule(callbacks);
|
|
28
42
|
this.communicator.registerBroadcastDispatcher(moduleNames_1.MODULE_NAMES.EDM, broadcastEventMap_1.EDM_BROADCAST_EVENT_MAP);
|
|
29
43
|
(0, messageLogger_1.setLoggerState)(params?.debug ?? false, messageLogger_1.SOURCES.EDM);
|
|
@@ -92,6 +106,7 @@ class EDM {
|
|
|
92
106
|
}
|
|
93
107
|
this.communicator.cleanup();
|
|
94
108
|
this.moduleLoader.clearCache();
|
|
109
|
+
authStore_1.AuthStore.getInstance().delete(moduleNames_1.MODULE_NAMES.EDM);
|
|
95
110
|
this.initialized = false;
|
|
96
111
|
EDM.broadCastEventHandler = null;
|
|
97
112
|
}
|
|
@@ -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(
|
|
16
|
+
constructor(jwt: string, config?: SdkConfig | undefined);
|
|
17
17
|
init(): Promise<void>;
|
|
18
18
|
destroy(): void;
|
|
19
19
|
getNonce(): string;
|
|
@@ -10,6 +10,8 @@ const productPublishService_1 = require("../modules/product-publish/productPubli
|
|
|
10
10
|
const messageLogger_1 = require("../helpers/messageLogger");
|
|
11
11
|
const modules_1 = require("../modules/modules");
|
|
12
12
|
const version_1 = require("../version");
|
|
13
|
+
const jwtDecoder_1 = require("../helpers/jwtDecoder");
|
|
14
|
+
const authStore_1 = require("../services/authStore");
|
|
13
15
|
class Embed {
|
|
14
16
|
config;
|
|
15
17
|
static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.sdkUrl ??
|
|
@@ -23,9 +25,17 @@ class Embed {
|
|
|
23
25
|
catalog;
|
|
24
26
|
mockup;
|
|
25
27
|
publish;
|
|
26
|
-
constructor(
|
|
28
|
+
constructor(jwt, config) {
|
|
27
29
|
this.config = config;
|
|
28
|
-
|
|
30
|
+
const { data, error } = (0, jwtDecoder_1.parseJwt)(jwt);
|
|
31
|
+
if (error) {
|
|
32
|
+
// If decoding fails, it means that regular nonce was passed, for now leave as is till deprecation for nonce is finished
|
|
33
|
+
this.nonce = jwt;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.nonce = data.nce;
|
|
37
|
+
authStore_1.AuthStore.getInstance().set(modules_1.MODULE_NAMES.SDK, jwt);
|
|
38
|
+
}
|
|
29
39
|
(0, messageLogger_1.setLoggerState)(config?.debug ?? false, messageLogger_1.SOURCES.SDK);
|
|
30
40
|
// Initialize services
|
|
31
41
|
this.catalog = new catalogService_1.CatalogService();
|
|
@@ -78,6 +88,7 @@ class Embed {
|
|
|
78
88
|
}
|
|
79
89
|
this.communicator.cleanup();
|
|
80
90
|
this.moduleLoader.clearCache();
|
|
91
|
+
authStore_1.AuthStore.getInstance().delete(modules_1.MODULE_NAMES.SDK);
|
|
81
92
|
this.initialized = false;
|
|
82
93
|
}
|
|
83
94
|
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;
|
|
@@ -7,6 +7,8 @@ const types_1 = require("../modules/sdk/types");
|
|
|
7
7
|
const messageLogger_1 = require("../helpers/messageLogger");
|
|
8
8
|
class ModuleLoaderService {
|
|
9
9
|
static instance;
|
|
10
|
+
static BASE_API_URL = globalThis.__FYUL_TESTING_VARS__?.sdkApiUrl ??
|
|
11
|
+
'https://ewl.printify.com/api';
|
|
10
12
|
communicator = embedCommunicator_1.EmbedCommunicator.getInstance();
|
|
11
13
|
moduleCache = new Map();
|
|
12
14
|
static getInstance() {
|
|
@@ -17,7 +19,7 @@ class ModuleLoaderService {
|
|
|
17
19
|
}
|
|
18
20
|
getModule(moduleName) {
|
|
19
21
|
if (!this.isModuleLoaded(moduleName)) {
|
|
20
|
-
const module = new modules_1.MODULES[moduleName]();
|
|
22
|
+
const module = new modules_1.MODULES[moduleName](ModuleLoaderService.BASE_API_URL);
|
|
21
23
|
this.moduleCache.set(moduleName, module);
|
|
22
24
|
}
|
|
23
25
|
return this.moduleCache.get(moduleName);
|
|
@@ -10,6 +10,7 @@ const version_1 = require("../version");
|
|
|
10
10
|
const whiteLabelBroadcastModule_1 = require("../modules/white-label/whiteLabelBroadcastModule");
|
|
11
11
|
const jwtDecoder_1 = require("../helpers/jwtDecoder");
|
|
12
12
|
const broadcastEventMap_1 = require("../types/event/broadcast/broadcastEventMap");
|
|
13
|
+
const authStore_1 = require("../services/authStore");
|
|
13
14
|
class WhiteLabel {
|
|
14
15
|
params;
|
|
15
16
|
config;
|
|
@@ -25,6 +26,7 @@ class WhiteLabel {
|
|
|
25
26
|
this.params = params;
|
|
26
27
|
this.config = config;
|
|
27
28
|
this.jwt = params.jwt;
|
|
29
|
+
authStore_1.AuthStore.getInstance().set(moduleNames_1.MODULE_NAMES.WHITE_LABEL, params.jwt);
|
|
28
30
|
WhiteLabel.broadCastEventHandler = new whiteLabelBroadcastModule_1.WhiteLabelBroadcastModule(callbacks);
|
|
29
31
|
this.communicator.registerBroadcastDispatcher(moduleNames_1.MODULE_NAMES.WHITE_LABEL, broadcastEventMap_1.WHITE_LABEL_BROADCAST_EVENT_MAP);
|
|
30
32
|
(0, messageLogger_1.setLoggerState)(params?.debug ?? false, messageLogger_1.SOURCES.WHITE_LABEL);
|
|
@@ -95,6 +97,7 @@ class WhiteLabel {
|
|
|
95
97
|
}
|
|
96
98
|
this.communicator.cleanup();
|
|
97
99
|
this.moduleLoader.clearCache();
|
|
100
|
+
authStore_1.AuthStore.getInstance().delete(moduleNames_1.MODULE_NAMES.WHITE_LABEL);
|
|
98
101
|
this.initialized = false;
|
|
99
102
|
WhiteLabel.broadCastEventHandler = null;
|
|
100
103
|
}
|