Skip to content

Commit

Permalink
fix(superset-embedded-sdk): Buffer is not defined (#21641)
Browse files Browse the repository at this point in the history
  • Loading branch information
doornot authored Oct 17, 2022
1 parent 6f2e76b commit 7ec136f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
13 changes: 12 additions & 1 deletion superset-embedded-sdk/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion superset-embedded-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion superset-embedded-sdk/src/guestTokenRefresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@
* 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
export const DEFAULT_TOKEN_EXP_MS = 300000 // (5 min) used only when parsing guest token exp fails

// 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<Record<string, any>>(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';
Expand Down

0 comments on commit 7ec136f

Please sign in to comment.