@frontegg/rest-api
Advanced tools
Comparing version 1.23.20 to 1.23.21
@@ -1,3 +0,2 @@ | ||
import { __awaiter, __generator, __assign, __rest } from 'tslib'; | ||
import jwtDecode from 'jwt-decode'; | ||
import { __awaiter, __generator, __assign, __extends, __rest } from 'tslib'; | ||
@@ -410,2 +409,90 @@ var ContextHolder = /** @class */ (function () { | ||
/** | ||
* The code was extracted from: | ||
* https://github.com/davidchambers/Base64.js | ||
*/ | ||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
var InvalidCharacterError = /** @class */ (function (_super) { | ||
__extends(InvalidCharacterError, _super); | ||
function InvalidCharacterError(message) { | ||
return _super.call(this, message) || this; | ||
} | ||
return InvalidCharacterError; | ||
}(Error)); | ||
function polyfill(input) { | ||
var str = String(input).replace(/=+$/, ''); | ||
if (str.length % 4 === 1) { | ||
throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded."); | ||
} | ||
var output = ''; | ||
// noinspection JSAssignmentUsedAsCondition,JSUnusedAssignment,CommaExpressionJS | ||
for ( | ||
// initialize result and counters | ||
var bc = 0, bs = void 0, buffer = void 0, idx = 0; | ||
// get next character | ||
// tslint:disable-next-line:no-conditional-assignment | ||
(buffer = str.charAt(idx++)); | ||
// character found in table? initialize bit storage and add its ascii value; | ||
// tslint:disable-next-line:no-conditional-assignment | ||
~buffer && | ||
((bs = bc % 4 ? bs * 64 + buffer : buffer), | ||
// and if not first of each 4 characters, | ||
// convert the first 8 bits to one ascii character | ||
bc++ % 4) | ||
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) | ||
: 0) { | ||
// try to find character in table (0-63, not found => -1) | ||
buffer = chars.indexOf(buffer); | ||
} | ||
return output; | ||
} | ||
var atob = (typeof window !== 'undefined' && window.atob && window.atob.bind(window)) || polyfill; | ||
function b64DecodeUnicode(str) { | ||
return decodeURIComponent(atob(str).replace(/(.)/g, function (m, p) { | ||
var code = p.charCodeAt(0).toString(16).toUpperCase(); | ||
if (code.length < 2) { | ||
code = '0' + code; | ||
} | ||
return '%' + code; | ||
})); | ||
} | ||
var base64UrlDecode = function (str) { | ||
var output = str.replace(/-/g, '+').replace(/_/g, '/'); | ||
switch (output.length % 4) { | ||
case 0: | ||
break; | ||
case 2: | ||
output += '=='; | ||
break; | ||
case 3: | ||
output += '='; | ||
break; | ||
default: | ||
throw new Error('Illegal base64url string!'); | ||
} | ||
try { | ||
return b64DecodeUnicode(output); | ||
} | ||
catch (err) { | ||
return atob(output); | ||
} | ||
}; | ||
var InvalidTokenError = /** @class */ (function (_super) { | ||
__extends(InvalidTokenError, _super); | ||
function InvalidTokenError(message) { | ||
return _super.call(this, message) || this; | ||
} | ||
return InvalidTokenError; | ||
}(Error)); | ||
var jwtDecode = function (token, options) { | ||
if (options === void 0) { options = {}; } | ||
var pos = !!options.header ? 0 : 1; | ||
try { | ||
return JSON.parse(base64UrlDecode(token.split('.')[pos])); | ||
} | ||
catch (e) { | ||
throw new InvalidTokenError('Invalid token specified: ' + e.message); | ||
} | ||
}; | ||
/***************************************** | ||
@@ -412,0 +499,0 @@ * Authentication |
import { __awaiter, __rest } from 'tslib'; | ||
import jwtDecode from 'jwt-decode'; | ||
@@ -309,2 +308,85 @@ class ContextHolder { | ||
/** | ||
* The code was extracted from: | ||
* https://github.com/davidchambers/Base64.js | ||
*/ | ||
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
class InvalidCharacterError extends Error { | ||
constructor(message) { | ||
super(message); | ||
} | ||
} | ||
function polyfill(input) { | ||
const str = String(input).replace(/=+$/, ''); | ||
if (str.length % 4 === 1) { | ||
throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded."); | ||
} | ||
let output = ''; | ||
// noinspection JSAssignmentUsedAsCondition,JSUnusedAssignment,CommaExpressionJS | ||
for ( | ||
// initialize result and counters | ||
let bc = 0, bs, buffer, idx = 0; | ||
// get next character | ||
// tslint:disable-next-line:no-conditional-assignment | ||
(buffer = str.charAt(idx++)); | ||
// character found in table? initialize bit storage and add its ascii value; | ||
// tslint:disable-next-line:no-conditional-assignment | ||
~buffer && | ||
((bs = bc % 4 ? bs * 64 + buffer : buffer), | ||
// and if not first of each 4 characters, | ||
// convert the first 8 bits to one ascii character | ||
bc++ % 4) | ||
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) | ||
: 0) { | ||
// try to find character in table (0-63, not found => -1) | ||
buffer = chars.indexOf(buffer); | ||
} | ||
return output; | ||
} | ||
const atob = (typeof window !== 'undefined' && window.atob && window.atob.bind(window)) || polyfill; | ||
function b64DecodeUnicode(str) { | ||
return decodeURIComponent(atob(str).replace(/(.)/g, (m, p) => { | ||
let code = p.charCodeAt(0).toString(16).toUpperCase(); | ||
if (code.length < 2) { | ||
code = '0' + code; | ||
} | ||
return '%' + code; | ||
})); | ||
} | ||
const base64UrlDecode = (str) => { | ||
let output = str.replace(/-/g, '+').replace(/_/g, '/'); | ||
switch (output.length % 4) { | ||
case 0: | ||
break; | ||
case 2: | ||
output += '=='; | ||
break; | ||
case 3: | ||
output += '='; | ||
break; | ||
default: | ||
throw new Error('Illegal base64url string!'); | ||
} | ||
try { | ||
return b64DecodeUnicode(output); | ||
} | ||
catch (err) { | ||
return atob(output); | ||
} | ||
}; | ||
class InvalidTokenError extends Error { | ||
constructor(message) { | ||
super(message); | ||
} | ||
} | ||
const jwtDecode = (token, options = {}) => { | ||
const pos = !!options.header ? 0 : 1; | ||
try { | ||
return JSON.parse(base64UrlDecode(token.split('.')[pos])); | ||
} | ||
catch (e) { | ||
throw new InvalidTokenError('Invalid token specified: ' + e.message); | ||
} | ||
}; | ||
/***************************************** | ||
@@ -311,0 +393,0 @@ * Authentication |
91
index.js
@@ -5,6 +5,3 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var tslib = require('tslib'); | ||
var jwtDecode = _interopDefault(require('jwt-decode')); | ||
@@ -417,2 +414,90 @@ var ContextHolder = /** @class */ (function () { | ||
/** | ||
* The code was extracted from: | ||
* https://github.com/davidchambers/Base64.js | ||
*/ | ||
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; | ||
var InvalidCharacterError = /** @class */ (function (_super) { | ||
tslib.__extends(InvalidCharacterError, _super); | ||
function InvalidCharacterError(message) { | ||
return _super.call(this, message) || this; | ||
} | ||
return InvalidCharacterError; | ||
}(Error)); | ||
function polyfill(input) { | ||
var str = String(input).replace(/=+$/, ''); | ||
if (str.length % 4 === 1) { | ||
throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded."); | ||
} | ||
var output = ''; | ||
// noinspection JSAssignmentUsedAsCondition,JSUnusedAssignment,CommaExpressionJS | ||
for ( | ||
// initialize result and counters | ||
var bc = 0, bs = void 0, buffer = void 0, idx = 0; | ||
// get next character | ||
// tslint:disable-next-line:no-conditional-assignment | ||
(buffer = str.charAt(idx++)); | ||
// character found in table? initialize bit storage and add its ascii value; | ||
// tslint:disable-next-line:no-conditional-assignment | ||
~buffer && | ||
((bs = bc % 4 ? bs * 64 + buffer : buffer), | ||
// and if not first of each 4 characters, | ||
// convert the first 8 bits to one ascii character | ||
bc++ % 4) | ||
? (output += String.fromCharCode(255 & (bs >> ((-2 * bc) & 6)))) | ||
: 0) { | ||
// try to find character in table (0-63, not found => -1) | ||
buffer = chars.indexOf(buffer); | ||
} | ||
return output; | ||
} | ||
var atob = (typeof window !== 'undefined' && window.atob && window.atob.bind(window)) || polyfill; | ||
function b64DecodeUnicode(str) { | ||
return decodeURIComponent(atob(str).replace(/(.)/g, function (m, p) { | ||
var code = p.charCodeAt(0).toString(16).toUpperCase(); | ||
if (code.length < 2) { | ||
code = '0' + code; | ||
} | ||
return '%' + code; | ||
})); | ||
} | ||
var base64UrlDecode = function (str) { | ||
var output = str.replace(/-/g, '+').replace(/_/g, '/'); | ||
switch (output.length % 4) { | ||
case 0: | ||
break; | ||
case 2: | ||
output += '=='; | ||
break; | ||
case 3: | ||
output += '='; | ||
break; | ||
default: | ||
throw new Error('Illegal base64url string!'); | ||
} | ||
try { | ||
return b64DecodeUnicode(output); | ||
} | ||
catch (err) { | ||
return atob(output); | ||
} | ||
}; | ||
var InvalidTokenError = /** @class */ (function (_super) { | ||
tslib.__extends(InvalidTokenError, _super); | ||
function InvalidTokenError(message) { | ||
return _super.call(this, message) || this; | ||
} | ||
return InvalidTokenError; | ||
}(Error)); | ||
var jwtDecode = function (token, options) { | ||
if (options === void 0) { options = {}; } | ||
var pos = !!options.header ? 0 : 1; | ||
try { | ||
return JSON.parse(base64UrlDecode(token.split('.')[pos])); | ||
} | ||
catch (e) { | ||
throw new InvalidTokenError('Invalid token specified: ' + e.message); | ||
} | ||
}; | ||
/***************************************** | ||
@@ -419,0 +504,0 @@ * Authentication |
{ | ||
"name": "@frontegg/rest-api", | ||
"libName": "FronteggRestApi", | ||
"version": "1.23.20", | ||
"version": "1.23.21", | ||
"author": "Frontegg LTD", | ||
@@ -14,6 +14,3 @@ "main": "index.js", | ||
"test": "jest --runInBand --passWithNoTests -c ../../scripts/jest.config.json --rootDir . && echo DONE" | ||
}, | ||
"dependencies": { | ||
"jwt-decode": "2.2.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
442473
0
33
5746
- Removedjwt-decode@2.2.0
- Removedjwt-decode@2.2.0(transitive)