@shopfront/bridge 1.18.2 → 1.18.3

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.
@@ -18,8 +18,14 @@ export interface ShopfrontEmbeddedVerificationToken {
18
18
  loaded: string;
19
19
  };
20
20
  }
21
+ export interface ShopfrontEmbeddedTokenError {
22
+ error: boolean;
23
+ type: string;
24
+ }
21
25
  export declare class ShopfrontTokenDecodingError extends Error {
22
26
  }
27
+ export declare class ShopfrontTokenRequestError extends Error {
28
+ }
23
29
  export declare class Application {
24
30
  protected bridge: Bridge;
25
31
  protected isReady: boolean;
@@ -139,6 +145,7 @@ export declare class Application {
139
145
  };
140
146
  protected generateSigningKey(): Promise<void>;
141
147
  protected decodeToken(signature: BufferSource, data: BufferSource, returnTokenObject?: boolean): Promise<ShopfrontEmbeddedVerificationToken | string>;
148
+ protected tokenDataContainsErrors(data: unknown): data is ShopfrontEmbeddedTokenError;
142
149
  getToken(returnTokenObject: true): Promise<ShopfrontEmbeddedVerificationToken>;
143
150
  getToken(returnTokenObject?: false): Promise<string>;
144
151
  }
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.Application = exports.ShopfrontTokenDecodingError = void 0;
6
+ exports.Application = exports.ShopfrontTokenRequestError = exports.ShopfrontTokenDecodingError = void 0;
7
7
  const ApplicationEvents_1 = require("./ApplicationEvents");
8
8
  const Ready_1 = require("./Events/Ready");
9
9
  const Button_1 = require("./Actions/Button");
@@ -34,6 +34,9 @@ const SaleCreate_1 = require("./Utilities/SaleCreate");
34
34
  class ShopfrontTokenDecodingError extends Error {
35
35
  }
36
36
  exports.ShopfrontTokenDecodingError = ShopfrontTokenDecodingError;
37
+ class ShopfrontTokenRequestError extends Error {
38
+ }
39
+ exports.ShopfrontTokenRequestError = ShopfrontTokenRequestError;
37
40
  // noinspection JSUnusedGlobalSymbols
38
41
  class Application {
39
42
  constructor(bridge) {
@@ -595,6 +598,12 @@ class Application {
595
598
  }
596
599
  return decoded.auth;
597
600
  }
601
+ tokenDataContainsErrors(data) {
602
+ if (!data || typeof data !== "object") {
603
+ return false;
604
+ }
605
+ return "error" in data && "type" in data;
606
+ }
598
607
  async getToken(returnTokenObject) {
599
608
  await this.generateSigningKey();
600
609
  const request = `TokenRequest-${Date.now().toString()}`;
@@ -617,7 +626,12 @@ class Application {
617
626
  this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.REQUEST_SECURE_KEY, {
618
627
  requestId: request,
619
628
  });
620
- return this.decodeToken(...(await promise), returnTokenObject);
629
+ const [signature, data] = await promise;
630
+ // Throw the error if there is one
631
+ if (this.tokenDataContainsErrors(data)) {
632
+ throw new ShopfrontTokenRequestError(data.type);
633
+ }
634
+ return this.decodeToken(signature, data, returnTokenObject);
621
635
  }
622
636
  }
623
637
  exports.Application = Application;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopfront/bridge",
3
- "version": "1.18.2",
3
+ "version": "1.18.3",
4
4
  "main": "./lib/index.js",
5
5
  "license": "ISC",
6
6
  "description": "The bridge used to embed your application within Shopfront",