From 1b7fed7d601be3138404168b7eb888a8cb648e93 Mon Sep 17 00:00:00 2001 From: wangbiao Date: Thu, 29 Sep 2022 16:15:03 +0800 Subject: [PATCH 1/2] fix(superset-embedded-sdk): Buffer is not defined --- superset-embedded-sdk/package-lock.json | 17 ++++++++++++++--- superset-embedded-sdk/package.json | 5 +++-- superset-embedded-sdk/src/guestTokenRefresh.ts | 3 ++- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/superset-embedded-sdk/package-lock.json b/superset-embedded-sdk/package-lock.json index 35836b79bc175..568b4c40c90ab 100644 --- a/superset-embedded-sdk/package-lock.json +++ b/superset-embedded-sdk/package-lock.json @@ -1,15 +1,16 @@ { "name": "@superset-ui/embedded-sdk", - "version": "0.1.0-alpha.7", + "version": "0.1.0-alpha.8", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@superset-ui/embedded-sdk", - "version": "0.1.0-alpha.7", + "version": "0.1.0-alpha.8", "license": "Apache-2.0", "dependencies": { - "@superset-ui/switchboard": "^0.18.26-0" + "@superset-ui/switchboard": "^0.18.26-0", + "jwt-decode": "^3.1.2" }, "devDependencies": { "@babel/cli": "^7.16.8", @@ -6495,6 +6496,11 @@ "node": ">=6" } }, + "node_modules/jwt-decode": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", + "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" + }, "node_modules/kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -13042,6 +13048,11 @@ "minimist": "^1.2.5" } }, + "jwt-decode": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/jwt-decode/-/jwt-decode-3.1.2.tgz", + "integrity": "sha512-UfpWE/VZn0iP50d8cz9NrZLM9lSWhcJ+0Gt/nm4by88UL+J1SiKN8/5dkjMmbEzwL2CAe+67GsegCbIKtbp75A==" + }, "kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", diff --git a/superset-embedded-sdk/package.json b/superset-embedded-sdk/package.json index 49debb4ad321f..055f44191a7e8 100644 --- a/superset-embedded-sdk/package.json +++ b/superset-embedded-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@superset-ui/embedded-sdk", - "version": "0.1.0-alpha.7", + "version": "0.1.0-alpha.8", "description": "SDK for embedding resources from Superset into your own application", "access": "public", "keywords": [ @@ -33,7 +33,8 @@ "last 3 edge versions" ], "dependencies": { - "@superset-ui/switchboard": "^0.18.26-0" + "@superset-ui/switchboard": "^0.18.26-0", + "jwt-decode": "^3.1.2" }, "devDependencies": { "@babel/cli": "^7.16.8", diff --git a/superset-embedded-sdk/src/guestTokenRefresh.ts b/superset-embedded-sdk/src/guestTokenRefresh.ts index 214e91a1c33e4..101c4d9e93930 100644 --- a/superset-embedded-sdk/src/guestTokenRefresh.ts +++ b/superset-embedded-sdk/src/guestTokenRefresh.ts @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ +import jwt_decode from "jwt-decode"; export const REFRESH_TIMING_BUFFER_MS = 5000 // refresh guest token early to avoid failed superset requests export const MIN_REFRESH_WAIT_MS = 10000 // avoid blasting requests as fast as the cpu can handle @@ -23,7 +24,7 @@ export const DEFAULT_TOKEN_EXP_MS = 300000 // (5 min) used only when parsing gue // when do we refresh the guest token? export function getGuestTokenRefreshTiming(currentGuestToken: string) { - const parsedJwt = JSON.parse(Buffer.from(currentGuestToken.split('.')[1], 'base64').toString()); + const parsedJwt = jwt_decode>(currentGuestToken); // if exp is int, it is in seconds, but Date() takes milliseconds const exp = new Date(/[^0-9\.]/g.test(parsedJwt.exp) ? parsedJwt.exp : parseFloat(parsedJwt.exp) * 1000); const isValidDate = exp.toString() !== 'Invalid Date'; From 248582ff97700b02c884fb174ca905fcbe5b2f84 Mon Sep 17 00:00:00 2001 From: wangbiao Date: Thu, 13 Oct 2022 10:28:26 +0800 Subject: [PATCH 2/2] feat: revert sdk version --- superset-embedded-sdk/package-lock.json | 4 ++-- superset-embedded-sdk/package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/superset-embedded-sdk/package-lock.json b/superset-embedded-sdk/package-lock.json index 568b4c40c90ab..f956ee27ac0b9 100644 --- a/superset-embedded-sdk/package-lock.json +++ b/superset-embedded-sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@superset-ui/embedded-sdk", - "version": "0.1.0-alpha.8", + "version": "0.1.0-alpha.7", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@superset-ui/embedded-sdk", - "version": "0.1.0-alpha.8", + "version": "0.1.0-alpha.7", "license": "Apache-2.0", "dependencies": { "@superset-ui/switchboard": "^0.18.26-0", diff --git a/superset-embedded-sdk/package.json b/superset-embedded-sdk/package.json index 055f44191a7e8..fea75d7af58c9 100644 --- a/superset-embedded-sdk/package.json +++ b/superset-embedded-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@superset-ui/embedded-sdk", - "version": "0.1.0-alpha.8", + "version": "0.1.0-alpha.7", "description": "SDK for embedding resources from Superset into your own application", "access": "public", "keywords": [