@shopfront/bridge 1.15.0 → 1.16.0

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.
@@ -122,6 +122,7 @@ export declare class Application {
122
122
  signature: BufferSource;
123
123
  };
124
124
  protected generateSigningKey(): Promise<void>;
125
- protected decodeToken(signature: BufferSource, data: BufferSource): Promise<ShopfrontEmbeddedVerificationToken>;
126
- getToken(): Promise<ShopfrontEmbeddedVerificationToken>;
125
+ protected decodeToken(signature: BufferSource, data: BufferSource, returnTokenObject?: boolean): Promise<ShopfrontEmbeddedVerificationToken | string>;
126
+ getToken(returnTokenObject: true): Promise<ShopfrontEmbeddedVerificationToken>;
127
+ getToken(returnTokenObject?: false): Promise<string>;
127
128
  }
@@ -486,7 +486,7 @@ class Application {
486
486
  }, true, ["sign", "verify"]);
487
487
  this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.ROTATE_SIGNING_KEY, await crypto.subtle.exportKey("jwk", this.signingKey.privateKey));
488
488
  }
489
- async decodeToken(signature, data) {
489
+ async decodeToken(signature, data, returnTokenObject) {
490
490
  if (typeof this.signingKey === "undefined") {
491
491
  // Not possible to decode
492
492
  throw new Error("Unable to decode token due to a missing signing key");
@@ -506,9 +506,12 @@ class Application {
506
506
  if (decoded.url.loaded !== location.href) {
507
507
  throw new ShopfrontTokenDecodingError();
508
508
  }
509
- return decoded;
509
+ if (returnTokenObject) {
510
+ return decoded;
511
+ }
512
+ return decoded.auth;
510
513
  }
511
- async getToken() {
514
+ async getToken(returnTokenObject) {
512
515
  await this.generateSigningKey();
513
516
  const request = `TokenRequest-${Date.now().toString()}`;
514
517
  const promise = new Promise(res => {
@@ -530,7 +533,7 @@ class Application {
530
533
  this.bridge.sendMessage(ApplicationEvents_1.ToShopfront.REQUEST_SECURE_KEY, {
531
534
  requestId: request,
532
535
  });
533
- return this.decodeToken(...(await promise));
536
+ return this.decodeToken(...(await promise), returnTokenObject);
534
537
  }
535
538
  }
536
539
  exports.Application = Application;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shopfront/bridge",
3
- "version": "1.15.0",
3
+ "version": "1.16.0",
4
4
  "main": "./lib/index.js",
5
5
  "license": "ISC",
6
6
  "description": "The bridge used to embed your application within Shopfront",