@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.
- package/lib/Application.d.ts +3 -2
- package/lib/Application.js +7 -4
- package/package.json +1 -1
package/lib/Application.d.ts
CHANGED
|
@@ -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
|
}
|
package/lib/Application.js
CHANGED
|
@@ -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
|
-
|
|
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;
|