@fyul/embed-sdk 2.7.0 → 2.7.2

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.
@@ -0,0 +1,7 @@
1
+ export declare function parseJwt<T>(token: string): {
2
+ data: T;
3
+ error: null;
4
+ } | {
5
+ data: null;
6
+ error: Error;
7
+ };
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseJwt = parseJwt;
4
+ function parseJwt(token) {
5
+ try {
6
+ const base64Url = token.split('.')[1];
7
+ const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
8
+ const jsonPayload = decodeURIComponent(window
9
+ .atob(base64)
10
+ .split('')
11
+ .map(function (c) {
12
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
13
+ })
14
+ .join(''));
15
+ return { data: JSON.parse(jsonPayload), error: null };
16
+ }
17
+ catch (e) {
18
+ return { data: null, error: e };
19
+ }
20
+ }
@@ -11,7 +11,7 @@ export type WhiteLabelParams = ({
11
11
  element?: null;
12
12
  } & WhiteLabelCommonParams);
13
13
  export interface WhiteLabelCommonParams {
14
- nonce: string;
14
+ jwt: string;
15
15
  iframeClassName?: string;
16
16
  debug?: boolean;
17
17
  }
@@ -11,7 +11,8 @@ const edmBroadcastModule_1 = require("../modules/edm/edmBroadcastModule");
11
11
  class EDM {
12
12
  params;
13
13
  config;
14
- static BASE_URL = 'https://www.printful.com/embedded-designer';
14
+ static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.edmUrl ??
15
+ 'https://www.printful.com/embedded-designer';
15
16
  static broadCastEventHandler;
16
17
  nonce;
17
18
  iFrameManager = null;
@@ -16,4 +16,5 @@ export declare class Embed {
16
16
  constructor(nonce: string, config?: SdkConfig | undefined);
17
17
  init(): Promise<void>;
18
18
  destroy(): void;
19
+ getNonce(): string;
19
20
  }
@@ -12,7 +12,8 @@ const modules_1 = require("../modules/modules");
12
12
  const version_1 = require("../version");
13
13
  class Embed {
14
14
  config;
15
- static BASE_URL = 'https://www.printful.com/embed-sdk';
15
+ static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.sdkUrl ??
16
+ 'https://www.printful.com/embed-sdk';
16
17
  nonce;
17
18
  iFrameManager = null;
18
19
  communicator = embedCommunicator_1.EmbedCommunicator.getInstance();
@@ -79,5 +80,8 @@ class Embed {
79
80
  this.moduleLoader.clearCache();
80
81
  this.initialized = false;
81
82
  }
83
+ getNonce() {
84
+ return this.nonce;
85
+ }
82
86
  }
83
87
  exports.Embed = Embed;
@@ -11,7 +11,7 @@ const messageLogger_1 = require("../helpers/messageLogger");
11
11
  class EmbedStudio {
12
12
  params;
13
13
  config;
14
- static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.iframeUrl ??
14
+ static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.embedStudioUrl ??
15
15
  'https://embed-studio.fyul.com';
16
16
  static broadCastEventHandler = null;
17
17
  iFrameManager = null;
@@ -20,7 +20,10 @@ class iFrameManager {
20
20
  iFrame.setAttribute('class', this.config.class);
21
21
  }
22
22
  const convertedUrlParams = Object.entries(this.config.urlParams).map(([k, v]) => [k, String(v)]);
23
- iFrame.src = `${this.config.baseUrl}?${new URLSearchParams(convertedUrlParams).toString()}`;
23
+ const query = convertedUrlParams.length
24
+ ? `?${new URLSearchParams(convertedUrlParams).toString()}`
25
+ : '';
26
+ iFrame.src = `${this.config.baseUrl}${query}`;
24
27
  let settled = false;
25
28
  const cleanup = () => {
26
29
  settled = true;
@@ -7,13 +7,15 @@ export declare class WhiteLabel {
7
7
  private config?;
8
8
  static BASE_URL: string;
9
9
  static broadCastEventHandler: WhiteLabelBroadcastModule | null;
10
- private nonce;
10
+ private jwt;
11
11
  private iFrameManager;
12
12
  private communicator;
13
13
  private moduleLoader;
14
14
  private initialized;
15
15
  constructor(params: WhiteLabelParams, config?: WhiteLabelConfig | undefined, callbacks?: Partial<BroadcastListeners>);
16
- init(): Promise<void>;
16
+ init(): Promise<{
17
+ error: null | string;
18
+ }>;
17
19
  destroy(): void;
18
20
  goToView(payload: GoToViewPayload): Promise<import("..").HandledResponse<import("../modules/white-label/types").GoToViewResultPayload, Error>>;
19
21
  static getBroadCastEventHandler(): WhiteLabelBroadcastModule;
@@ -8,12 +8,14 @@ const messageLogger_1 = require("../helpers/messageLogger");
8
8
  const moduleNames_1 = require("../modules/moduleNames");
9
9
  const version_1 = require("../version");
10
10
  const whiteLabelBroadcastModule_1 = require("../modules/white-label/whiteLabelBroadcastModule");
11
+ const jwtDecoder_1 = require("../helpers/jwtDecoder");
11
12
  class WhiteLabel {
12
13
  params;
13
14
  config;
14
- static BASE_URL = 'https://embed-white-label-fe.nonprod.printify.com/iframe';
15
+ static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.ewlUrl ??
16
+ 'https://embed-white-label-fe.nonprod.printify.com/iframe';
15
17
  static broadCastEventHandler;
16
- nonce;
18
+ jwt;
17
19
  iFrameManager = null;
18
20
  communicator = embedCommunicator_1.EmbedCommunicator.getInstance();
19
21
  moduleLoader = moduleLoaderService_1.ModuleLoaderService.getInstance();
@@ -21,35 +23,54 @@ class WhiteLabel {
21
23
  constructor(params, config, callbacks) {
22
24
  this.params = params;
23
25
  this.config = config;
24
- this.nonce = params.nonce;
26
+ this.jwt = params.jwt;
25
27
  WhiteLabel.broadCastEventHandler = new whiteLabelBroadcastModule_1.WhiteLabelBroadcastModule(callbacks);
26
28
  (0, messageLogger_1.setLoggerState)(params?.debug ?? false, messageLogger_1.SOURCES.WHITE_LABEL);
27
29
  }
28
30
  async init() {
29
31
  if (this.initialized) {
32
+ const message = 'WhiteLabel already initialized';
30
33
  (0, messageLogger_1.logEmbedMessage)({
31
- message: 'WhiteLabel already initialized',
34
+ message,
32
35
  logType: messageLogger_1.LOG_TYPES.WARN,
33
36
  });
34
- return;
37
+ return { error: message };
35
38
  }
36
39
  const elementToBindTo = this.params.element ?? document.getElementById(this.params.elementId);
37
40
  if (!elementToBindTo) {
41
+ const message = 'Cant find element for WhiteLabel';
38
42
  (0, messageLogger_1.logEmbedMessage)({
39
- message: 'Cant find element for WhiteLabel',
43
+ message,
40
44
  logType: messageLogger_1.LOG_TYPES.ERROR,
41
45
  });
42
- return;
46
+ return { error: message };
47
+ }
48
+ const { data, error } = (0, jwtDecoder_1.parseJwt)(this.jwt);
49
+ if (error) {
50
+ const message = 'Failed to parse JWT';
51
+ (0, messageLogger_1.logEmbedMessage)({
52
+ message,
53
+ logType: messageLogger_1.LOG_TYPES.ERROR,
54
+ });
55
+ return { error: message };
43
56
  }
44
57
  this.iFrameManager = new iFrameManager_1.iFrameManager({
45
- baseUrl: WhiteLabel.BASE_URL,
46
- urlParams: {
47
- nonce: this.nonce,
48
- },
58
+ baseUrl: WhiteLabel.BASE_URL + `/${data.tenant_id}`,
59
+ urlParams: {},
49
60
  class: this.params.iframeClassName,
50
61
  elementToAppendTo: elementToBindTo,
51
62
  });
52
- await this.iFrameManager.create();
63
+ try {
64
+ await this.iFrameManager.create();
65
+ }
66
+ catch {
67
+ const message = 'Failed to to load Iframe';
68
+ (0, messageLogger_1.logEmbedMessage)({
69
+ message,
70
+ logType: messageLogger_1.LOG_TYPES.ERROR,
71
+ });
72
+ return { error: message };
73
+ }
53
74
  this.communicator.setIFrameManager(moduleNames_1.MODULE_NAMES.WHITE_LABEL, this.iFrameManager);
54
75
  this.communicator.setupListener();
55
76
  const whiteLabelModule = this.moduleLoader.getModule(moduleNames_1.MODULE_NAMES.WHITE_LABEL);
@@ -63,6 +84,7 @@ class WhiteLabel {
63
84
  logType: messageLogger_1.LOG_TYPES.LOG,
64
85
  });
65
86
  this.initialized = true;
87
+ return { error: null };
66
88
  }
67
89
  destroy() {
68
90
  if (this.iFrameManager) {
@@ -0,0 +1,8 @@
1
+ export interface JWTData {
2
+ tenant_id: string;
3
+ nonce: string;
4
+ scopes: string[];
5
+ iat: number;
6
+ exp: number;
7
+ external_customer_id: string;
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1 @@
1
- export declare const VERSION: "2.7.0";
1
+ export declare const VERSION: "2.7.2";
@@ -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.0';
5
+ exports.VERSION = '2.7.2';
@@ -0,0 +1,7 @@
1
+ export declare function parseJwt<T>(token: string): {
2
+ data: T;
3
+ error: null;
4
+ } | {
5
+ data: null;
6
+ error: Error;
7
+ };
@@ -0,0 +1,17 @@
1
+ export function parseJwt(token) {
2
+ try {
3
+ const base64Url = token.split('.')[1];
4
+ const base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
5
+ const jsonPayload = decodeURIComponent(window
6
+ .atob(base64)
7
+ .split('')
8
+ .map(function (c) {
9
+ return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
10
+ })
11
+ .join(''));
12
+ return { data: JSON.parse(jsonPayload), error: null };
13
+ }
14
+ catch (e) {
15
+ return { data: null, error: e };
16
+ }
17
+ }
@@ -11,7 +11,7 @@ export type WhiteLabelParams = ({
11
11
  element?: null;
12
12
  } & WhiteLabelCommonParams);
13
13
  export interface WhiteLabelCommonParams {
14
- nonce: string;
14
+ jwt: string;
15
15
  iframeClassName?: string;
16
16
  debug?: boolean;
17
17
  }
@@ -8,7 +8,8 @@ import { EdmBroadcastModule } from '../modules/edm/edmBroadcastModule';
8
8
  export class EDM {
9
9
  params;
10
10
  config;
11
- static BASE_URL = 'https://www.printful.com/embedded-designer';
11
+ static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.edmUrl ??
12
+ 'https://www.printful.com/embedded-designer';
12
13
  static broadCastEventHandler;
13
14
  nonce;
14
15
  iFrameManager = null;
@@ -16,4 +16,5 @@ export declare class Embed {
16
16
  constructor(nonce: string, config?: SdkConfig | undefined);
17
17
  init(): Promise<void>;
18
18
  destroy(): void;
19
+ getNonce(): string;
19
20
  }
@@ -9,7 +9,8 @@ import { MODULE_NAMES } from '../modules/modules';
9
9
  import { VERSION } from '../version';
10
10
  export class Embed {
11
11
  config;
12
- static BASE_URL = 'https://www.printful.com/embed-sdk';
12
+ static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.sdkUrl ??
13
+ 'https://www.printful.com/embed-sdk';
13
14
  nonce;
14
15
  iFrameManager = null;
15
16
  communicator = EmbedCommunicator.getInstance();
@@ -76,4 +77,7 @@ export class Embed {
76
77
  this.moduleLoader.clearCache();
77
78
  this.initialized = false;
78
79
  }
80
+ getNonce() {
81
+ return this.nonce;
82
+ }
79
83
  }
@@ -8,7 +8,7 @@ import { LOG_TYPES, logEmbedMessage, setLoggerState, SOURCES, } from '../helpers
8
8
  export class EmbedStudio {
9
9
  params;
10
10
  config;
11
- static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.iframeUrl ??
11
+ static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.embedStudioUrl ??
12
12
  'https://embed-studio.fyul.com';
13
13
  static broadCastEventHandler = null;
14
14
  iFrameManager = null;
@@ -17,7 +17,10 @@ export class iFrameManager {
17
17
  iFrame.setAttribute('class', this.config.class);
18
18
  }
19
19
  const convertedUrlParams = Object.entries(this.config.urlParams).map(([k, v]) => [k, String(v)]);
20
- iFrame.src = `${this.config.baseUrl}?${new URLSearchParams(convertedUrlParams).toString()}`;
20
+ const query = convertedUrlParams.length
21
+ ? `?${new URLSearchParams(convertedUrlParams).toString()}`
22
+ : '';
23
+ iFrame.src = `${this.config.baseUrl}${query}`;
21
24
  let settled = false;
22
25
  const cleanup = () => {
23
26
  settled = true;
@@ -7,13 +7,15 @@ export declare class WhiteLabel {
7
7
  private config?;
8
8
  static BASE_URL: string;
9
9
  static broadCastEventHandler: WhiteLabelBroadcastModule | null;
10
- private nonce;
10
+ private jwt;
11
11
  private iFrameManager;
12
12
  private communicator;
13
13
  private moduleLoader;
14
14
  private initialized;
15
15
  constructor(params: WhiteLabelParams, config?: WhiteLabelConfig | undefined, callbacks?: Partial<BroadcastListeners>);
16
- init(): Promise<void>;
16
+ init(): Promise<{
17
+ error: null | string;
18
+ }>;
17
19
  destroy(): void;
18
20
  goToView(payload: GoToViewPayload): Promise<import("..").HandledResponse<import("../modules/white-label/types").GoToViewResultPayload, Error>>;
19
21
  static getBroadCastEventHandler(): WhiteLabelBroadcastModule;
@@ -5,12 +5,14 @@ import { LOG_TYPES, logEmbedMessage, setLoggerState, SOURCES, } from '../helpers
5
5
  import { MODULE_NAMES } from '../modules/moduleNames';
6
6
  import { VERSION } from '../version';
7
7
  import { WhiteLabelBroadcastModule } from '../modules/white-label/whiteLabelBroadcastModule';
8
+ import { parseJwt } from '../helpers/jwtDecoder';
8
9
  export class WhiteLabel {
9
10
  params;
10
11
  config;
11
- static BASE_URL = 'https://embed-white-label-fe.nonprod.printify.com/iframe';
12
+ static BASE_URL = globalThis.__FYUL_TESTING_VARS__?.ewlUrl ??
13
+ 'https://embed-white-label-fe.nonprod.printify.com/iframe';
12
14
  static broadCastEventHandler;
13
- nonce;
15
+ jwt;
14
16
  iFrameManager = null;
15
17
  communicator = EmbedCommunicator.getInstance();
16
18
  moduleLoader = ModuleLoaderService.getInstance();
@@ -18,35 +20,54 @@ export class WhiteLabel {
18
20
  constructor(params, config, callbacks) {
19
21
  this.params = params;
20
22
  this.config = config;
21
- this.nonce = params.nonce;
23
+ this.jwt = params.jwt;
22
24
  WhiteLabel.broadCastEventHandler = new WhiteLabelBroadcastModule(callbacks);
23
25
  setLoggerState(params?.debug ?? false, SOURCES.WHITE_LABEL);
24
26
  }
25
27
  async init() {
26
28
  if (this.initialized) {
29
+ const message = 'WhiteLabel already initialized';
27
30
  logEmbedMessage({
28
- message: 'WhiteLabel already initialized',
31
+ message,
29
32
  logType: LOG_TYPES.WARN,
30
33
  });
31
- return;
34
+ return { error: message };
32
35
  }
33
36
  const elementToBindTo = this.params.element ?? document.getElementById(this.params.elementId);
34
37
  if (!elementToBindTo) {
38
+ const message = 'Cant find element for WhiteLabel';
35
39
  logEmbedMessage({
36
- message: 'Cant find element for WhiteLabel',
40
+ message,
37
41
  logType: LOG_TYPES.ERROR,
38
42
  });
39
- return;
43
+ return { error: message };
44
+ }
45
+ const { data, error } = parseJwt(this.jwt);
46
+ if (error) {
47
+ const message = 'Failed to parse JWT';
48
+ logEmbedMessage({
49
+ message,
50
+ logType: LOG_TYPES.ERROR,
51
+ });
52
+ return { error: message };
40
53
  }
41
54
  this.iFrameManager = new iFrameManager({
42
- baseUrl: WhiteLabel.BASE_URL,
43
- urlParams: {
44
- nonce: this.nonce,
45
- },
55
+ baseUrl: WhiteLabel.BASE_URL + `/${data.tenant_id}`,
56
+ urlParams: {},
46
57
  class: this.params.iframeClassName,
47
58
  elementToAppendTo: elementToBindTo,
48
59
  });
49
- await this.iFrameManager.create();
60
+ try {
61
+ await this.iFrameManager.create();
62
+ }
63
+ catch {
64
+ const message = 'Failed to to load Iframe';
65
+ logEmbedMessage({
66
+ message,
67
+ logType: LOG_TYPES.ERROR,
68
+ });
69
+ return { error: message };
70
+ }
50
71
  this.communicator.setIFrameManager(MODULE_NAMES.WHITE_LABEL, this.iFrameManager);
51
72
  this.communicator.setupListener();
52
73
  const whiteLabelModule = this.moduleLoader.getModule(MODULE_NAMES.WHITE_LABEL);
@@ -60,6 +81,7 @@ export class WhiteLabel {
60
81
  logType: LOG_TYPES.LOG,
61
82
  });
62
83
  this.initialized = true;
84
+ return { error: null };
63
85
  }
64
86
  destroy() {
65
87
  if (this.iFrameManager) {
@@ -0,0 +1,8 @@
1
+ export interface JWTData {
2
+ tenant_id: string;
3
+ nonce: string;
4
+ scopes: string[];
5
+ iat: number;
6
+ exp: number;
7
+ external_customer_id: string;
8
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -1 +1 @@
1
- export declare const VERSION: "2.7.0";
1
+ export declare const VERSION: "2.7.2";
@@ -1,2 +1,2 @@
1
1
  // AUTO-GENERATED
2
- export const VERSION = '2.7.0';
2
+ export const VERSION = '2.7.2';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fyul/embed-sdk",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",