oidc-jwt-client
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -29,2 +29,520 @@ import { createContext, useMemo, useEffect, createElement, useState, useContext } from 'react'; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var strictUriEncode = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); | ||
var token = '%[a-f0-9]{2}'; | ||
var singleMatcher = new RegExp(token, 'gi'); | ||
var multiMatcher = new RegExp('(' + token + ')+', 'gi'); | ||
function decodeComponents(components, split) { | ||
try { | ||
// Try to decode the entire string first | ||
return decodeURIComponent(components.join('')); | ||
} catch (err) { | ||
// Do nothing | ||
} | ||
if (components.length === 1) { | ||
return components; | ||
} | ||
split = split || 1; | ||
// Split the array in 2 parts | ||
var left = components.slice(0, split); | ||
var right = components.slice(split); | ||
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right)); | ||
} | ||
function decode(input) { | ||
try { | ||
return decodeURIComponent(input); | ||
} catch (err) { | ||
var tokens = input.match(singleMatcher); | ||
for (var i = 1; i < tokens.length; i++) { | ||
input = decodeComponents(tokens, i).join(''); | ||
tokens = input.match(singleMatcher); | ||
} | ||
return input; | ||
} | ||
} | ||
function customDecodeURIComponent(input) { | ||
// Keep track of all the replacements and prefill the map with the `BOM` | ||
var replaceMap = { | ||
'%FE%FF': '\uFFFD\uFFFD', | ||
'%FF%FE': '\uFFFD\uFFFD' | ||
}; | ||
var match = multiMatcher.exec(input); | ||
while (match) { | ||
try { | ||
// Decode as big chunks as possible | ||
replaceMap[match[0]] = decodeURIComponent(match[0]); | ||
} catch (err) { | ||
var result = decode(match[0]); | ||
if (result !== match[0]) { | ||
replaceMap[match[0]] = result; | ||
} | ||
} | ||
match = multiMatcher.exec(input); | ||
} | ||
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else | ||
replaceMap['%C2'] = '\uFFFD'; | ||
var entries = Object.keys(replaceMap); | ||
for (var i = 0; i < entries.length; i++) { | ||
// Replace all decoded components | ||
var key = entries[i]; | ||
input = input.replace(new RegExp(key, 'g'), replaceMap[key]); | ||
} | ||
return input; | ||
} | ||
var decodeUriComponent = function (encodedURI) { | ||
if (typeof encodedURI !== 'string') { | ||
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`'); | ||
} | ||
try { | ||
encodedURI = encodedURI.replace(/\+/g, ' '); | ||
// Try the built in decoder first | ||
return decodeURIComponent(encodedURI); | ||
} catch (err) { | ||
// Fallback to a more advanced decoder | ||
return customDecodeURIComponent(encodedURI); | ||
} | ||
}; | ||
var splitOnFirst = (string, separator) => { | ||
if (!(typeof string === 'string' && typeof separator === 'string')) { | ||
throw new TypeError('Expected the arguments to be of type `string`'); | ||
} | ||
if (separator === '') { | ||
return [string]; | ||
} | ||
const separatorIndex = string.indexOf(separator); | ||
if (separatorIndex === -1) { | ||
return [string]; | ||
} | ||
return [ | ||
string.slice(0, separatorIndex), | ||
string.slice(separatorIndex + separator.length) | ||
]; | ||
}; | ||
var queryString = createCommonjsModule(function (module, exports) { | ||
const isNullOrUndefined = value => value === null || value === undefined; | ||
function encoderForArrayFormat(options) { | ||
switch (options.arrayFormat) { | ||
case 'index': | ||
return key => (result, value) => { | ||
const index = result.length; | ||
if ( | ||
value === undefined || | ||
(options.skipNull && value === null) || | ||
(options.skipEmptyString && value === '') | ||
) { | ||
return result; | ||
} | ||
if (value === null) { | ||
return [...result, [encode(key, options), '[', index, ']'].join('')]; | ||
} | ||
return [ | ||
...result, | ||
[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('') | ||
]; | ||
}; | ||
case 'bracket': | ||
return key => (result, value) => { | ||
if ( | ||
value === undefined || | ||
(options.skipNull && value === null) || | ||
(options.skipEmptyString && value === '') | ||
) { | ||
return result; | ||
} | ||
if (value === null) { | ||
return [...result, [encode(key, options), '[]'].join('')]; | ||
} | ||
return [...result, [encode(key, options), '[]=', encode(value, options)].join('')]; | ||
}; | ||
case 'comma': | ||
case 'separator': | ||
return key => (result, value) => { | ||
if (value === null || value === undefined || value.length === 0) { | ||
return result; | ||
} | ||
if (result.length === 0) { | ||
return [[encode(key, options), '=', encode(value, options)].join('')]; | ||
} | ||
return [[result, encode(value, options)].join(options.arrayFormatSeparator)]; | ||
}; | ||
default: | ||
return key => (result, value) => { | ||
if ( | ||
value === undefined || | ||
(options.skipNull && value === null) || | ||
(options.skipEmptyString && value === '') | ||
) { | ||
return result; | ||
} | ||
if (value === null) { | ||
return [...result, encode(key, options)]; | ||
} | ||
return [...result, [encode(key, options), '=', encode(value, options)].join('')]; | ||
}; | ||
} | ||
} | ||
function parserForArrayFormat(options) { | ||
let result; | ||
switch (options.arrayFormat) { | ||
case 'index': | ||
return (key, value, accumulator) => { | ||
result = /\[(\d*)\]$/.exec(key); | ||
key = key.replace(/\[\d*\]$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = {}; | ||
} | ||
accumulator[key][result[1]] = value; | ||
}; | ||
case 'bracket': | ||
return (key, value, accumulator) => { | ||
result = /(\[\])$/.exec(key); | ||
key = key.replace(/\[\]$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = [value]; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
case 'comma': | ||
case 'separator': | ||
return (key, value, accumulator) => { | ||
const isArray = typeof value === 'string' && value.split('').indexOf(options.arrayFormatSeparator) > -1; | ||
const newValue = isArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options); | ||
accumulator[key] = newValue; | ||
}; | ||
default: | ||
return (key, value, accumulator) => { | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
} | ||
} | ||
function validateArrayFormatSeparator(value) { | ||
if (typeof value !== 'string' || value.length !== 1) { | ||
throw new TypeError('arrayFormatSeparator must be single character string'); | ||
} | ||
} | ||
function encode(value, options) { | ||
if (options.encode) { | ||
return options.strict ? strictUriEncode(value) : encodeURIComponent(value); | ||
} | ||
return value; | ||
} | ||
function decode(value, options) { | ||
if (options.decode) { | ||
return decodeUriComponent(value); | ||
} | ||
return value; | ||
} | ||
function keysSorter(input) { | ||
if (Array.isArray(input)) { | ||
return input.sort(); | ||
} | ||
if (typeof input === 'object') { | ||
return keysSorter(Object.keys(input)) | ||
.sort((a, b) => Number(a) - Number(b)) | ||
.map(key => input[key]); | ||
} | ||
return input; | ||
} | ||
function removeHash(input) { | ||
const hashStart = input.indexOf('#'); | ||
if (hashStart !== -1) { | ||
input = input.slice(0, hashStart); | ||
} | ||
return input; | ||
} | ||
function getHash(url) { | ||
let hash = ''; | ||
const hashStart = url.indexOf('#'); | ||
if (hashStart !== -1) { | ||
hash = url.slice(hashStart); | ||
} | ||
return hash; | ||
} | ||
function extract(input) { | ||
input = removeHash(input); | ||
const queryStart = input.indexOf('?'); | ||
if (queryStart === -1) { | ||
return ''; | ||
} | ||
return input.slice(queryStart + 1); | ||
} | ||
function parseValue(value, options) { | ||
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) { | ||
value = Number(value); | ||
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) { | ||
value = value.toLowerCase() === 'true'; | ||
} | ||
return value; | ||
} | ||
function parse(input, options) { | ||
options = Object.assign({ | ||
decode: true, | ||
sort: true, | ||
arrayFormat: 'none', | ||
arrayFormatSeparator: ',', | ||
parseNumbers: false, | ||
parseBooleans: false | ||
}, options); | ||
validateArrayFormatSeparator(options.arrayFormatSeparator); | ||
const formatter = parserForArrayFormat(options); | ||
// Create an object with no prototype | ||
const ret = Object.create(null); | ||
if (typeof input !== 'string') { | ||
return ret; | ||
} | ||
input = input.trim().replace(/^[?#&]/, ''); | ||
if (!input) { | ||
return ret; | ||
} | ||
for (const param of input.split('&')) { | ||
let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '='); | ||
// Missing `=` should be `null`: | ||
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters | ||
value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options); | ||
formatter(decode(key, options), value, ret); | ||
} | ||
for (const key of Object.keys(ret)) { | ||
const value = ret[key]; | ||
if (typeof value === 'object' && value !== null) { | ||
for (const k of Object.keys(value)) { | ||
value[k] = parseValue(value[k], options); | ||
} | ||
} else { | ||
ret[key] = parseValue(value, options); | ||
} | ||
} | ||
if (options.sort === false) { | ||
return ret; | ||
} | ||
return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => { | ||
const value = ret[key]; | ||
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) { | ||
// Sort object keys, not values | ||
result[key] = keysSorter(value); | ||
} else { | ||
result[key] = value; | ||
} | ||
return result; | ||
}, Object.create(null)); | ||
} | ||
exports.extract = extract; | ||
exports.parse = parse; | ||
exports.stringify = (object, options) => { | ||
if (!object) { | ||
return ''; | ||
} | ||
options = Object.assign({ | ||
encode: true, | ||
strict: true, | ||
arrayFormat: 'none', | ||
arrayFormatSeparator: ',' | ||
}, options); | ||
validateArrayFormatSeparator(options.arrayFormatSeparator); | ||
const shouldFilter = key => ( | ||
(options.skipNull && isNullOrUndefined(object[key])) || | ||
(options.skipEmptyString && object[key] === '') | ||
); | ||
const formatter = encoderForArrayFormat(options); | ||
const objectCopy = {}; | ||
for (const key of Object.keys(object)) { | ||
if (!shouldFilter(key)) { | ||
objectCopy[key] = object[key]; | ||
} | ||
} | ||
const keys = Object.keys(objectCopy); | ||
if (options.sort !== false) { | ||
keys.sort(options.sort); | ||
} | ||
return keys.map(key => { | ||
const value = object[key]; | ||
if (value === undefined) { | ||
return ''; | ||
} | ||
if (value === null) { | ||
return encode(key, options); | ||
} | ||
if (Array.isArray(value)) { | ||
return value | ||
.reduce(formatter(key), []) | ||
.join('&'); | ||
} | ||
return encode(key, options) + '=' + encode(value, options); | ||
}).filter(x => x.length > 0).join('&'); | ||
}; | ||
exports.parseUrl = (input, options) => { | ||
options = Object.assign({ | ||
decode: true | ||
}, options); | ||
const [url, hash] = splitOnFirst(input, '#'); | ||
return Object.assign( | ||
{ | ||
url: url.split('?')[0] || '', | ||
query: parse(extract(input), options) | ||
}, | ||
options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {} | ||
); | ||
}; | ||
exports.stringifyUrl = (input, options) => { | ||
options = Object.assign({ | ||
encode: true, | ||
strict: true | ||
}, options); | ||
const url = removeHash(input.url).split('?')[0] || ''; | ||
const queryFromUrl = exports.extract(input.url); | ||
const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false}); | ||
const query = Object.assign(parsedQueryFromUrl, input.query); | ||
let queryString = exports.stringify(query, options); | ||
if (queryString) { | ||
queryString = `?${queryString}`; | ||
} | ||
let hash = getHash(input.url); | ||
if (input.fragmentIdentifier) { | ||
hash = `#${encode(input.fragmentIdentifier, options)}`; | ||
} | ||
return `${url}${queryString}${hash}`; | ||
}; | ||
}); | ||
var queryString_1 = queryString.extract; | ||
var queryString_2 = queryString.parse; | ||
var queryString_3 = queryString.stringify; | ||
var queryString_4 = queryString.parseUrl; | ||
var queryString_5 = queryString.stringifyUrl; | ||
function buildQuerystring(params) { | ||
@@ -35,4 +553,8 @@ return Object.keys(params) | ||
} | ||
function stripTokenFromUrl(url) { | ||
return url.replace(/([?&])token=([^&#]+)/, '$1'); | ||
function stripTokenFromUrl(href) { | ||
//= > {url: 'https://foo.bar', query: {foo: 'bar'}} | ||
var parsedUrl = queryString.parseUrl(href, { parseFragmentIdentifier: true }); | ||
var url = parsedUrl.url, query = parsedUrl.query, fragmentIdentifier = parsedUrl.fragmentIdentifier; | ||
var token = query.token, params = __rest(query, ["token"]); | ||
return queryString.stringifyUrl({ url: url, query: params, fragmentIdentifier: fragmentIdentifier }); | ||
} | ||
@@ -39,0 +561,0 @@ var OidcJwtClientImpl = /** @class */ (function () { |
@@ -33,2 +33,520 @@ 'use strict'; | ||
function __rest(s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
} | ||
function createCommonjsModule(fn, module) { | ||
return module = { exports: {} }, fn(module, module.exports), module.exports; | ||
} | ||
var strictUriEncode = str => encodeURIComponent(str).replace(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`); | ||
var token = '%[a-f0-9]{2}'; | ||
var singleMatcher = new RegExp(token, 'gi'); | ||
var multiMatcher = new RegExp('(' + token + ')+', 'gi'); | ||
function decodeComponents(components, split) { | ||
try { | ||
// Try to decode the entire string first | ||
return decodeURIComponent(components.join('')); | ||
} catch (err) { | ||
// Do nothing | ||
} | ||
if (components.length === 1) { | ||
return components; | ||
} | ||
split = split || 1; | ||
// Split the array in 2 parts | ||
var left = components.slice(0, split); | ||
var right = components.slice(split); | ||
return Array.prototype.concat.call([], decodeComponents(left), decodeComponents(right)); | ||
} | ||
function decode(input) { | ||
try { | ||
return decodeURIComponent(input); | ||
} catch (err) { | ||
var tokens = input.match(singleMatcher); | ||
for (var i = 1; i < tokens.length; i++) { | ||
input = decodeComponents(tokens, i).join(''); | ||
tokens = input.match(singleMatcher); | ||
} | ||
return input; | ||
} | ||
} | ||
function customDecodeURIComponent(input) { | ||
// Keep track of all the replacements and prefill the map with the `BOM` | ||
var replaceMap = { | ||
'%FE%FF': '\uFFFD\uFFFD', | ||
'%FF%FE': '\uFFFD\uFFFD' | ||
}; | ||
var match = multiMatcher.exec(input); | ||
while (match) { | ||
try { | ||
// Decode as big chunks as possible | ||
replaceMap[match[0]] = decodeURIComponent(match[0]); | ||
} catch (err) { | ||
var result = decode(match[0]); | ||
if (result !== match[0]) { | ||
replaceMap[match[0]] = result; | ||
} | ||
} | ||
match = multiMatcher.exec(input); | ||
} | ||
// Add `%C2` at the end of the map to make sure it does not replace the combinator before everything else | ||
replaceMap['%C2'] = '\uFFFD'; | ||
var entries = Object.keys(replaceMap); | ||
for (var i = 0; i < entries.length; i++) { | ||
// Replace all decoded components | ||
var key = entries[i]; | ||
input = input.replace(new RegExp(key, 'g'), replaceMap[key]); | ||
} | ||
return input; | ||
} | ||
var decodeUriComponent = function (encodedURI) { | ||
if (typeof encodedURI !== 'string') { | ||
throw new TypeError('Expected `encodedURI` to be of type `string`, got `' + typeof encodedURI + '`'); | ||
} | ||
try { | ||
encodedURI = encodedURI.replace(/\+/g, ' '); | ||
// Try the built in decoder first | ||
return decodeURIComponent(encodedURI); | ||
} catch (err) { | ||
// Fallback to a more advanced decoder | ||
return customDecodeURIComponent(encodedURI); | ||
} | ||
}; | ||
var splitOnFirst = (string, separator) => { | ||
if (!(typeof string === 'string' && typeof separator === 'string')) { | ||
throw new TypeError('Expected the arguments to be of type `string`'); | ||
} | ||
if (separator === '') { | ||
return [string]; | ||
} | ||
const separatorIndex = string.indexOf(separator); | ||
if (separatorIndex === -1) { | ||
return [string]; | ||
} | ||
return [ | ||
string.slice(0, separatorIndex), | ||
string.slice(separatorIndex + separator.length) | ||
]; | ||
}; | ||
var queryString = createCommonjsModule(function (module, exports) { | ||
const isNullOrUndefined = value => value === null || value === undefined; | ||
function encoderForArrayFormat(options) { | ||
switch (options.arrayFormat) { | ||
case 'index': | ||
return key => (result, value) => { | ||
const index = result.length; | ||
if ( | ||
value === undefined || | ||
(options.skipNull && value === null) || | ||
(options.skipEmptyString && value === '') | ||
) { | ||
return result; | ||
} | ||
if (value === null) { | ||
return [...result, [encode(key, options), '[', index, ']'].join('')]; | ||
} | ||
return [ | ||
...result, | ||
[encode(key, options), '[', encode(index, options), ']=', encode(value, options)].join('') | ||
]; | ||
}; | ||
case 'bracket': | ||
return key => (result, value) => { | ||
if ( | ||
value === undefined || | ||
(options.skipNull && value === null) || | ||
(options.skipEmptyString && value === '') | ||
) { | ||
return result; | ||
} | ||
if (value === null) { | ||
return [...result, [encode(key, options), '[]'].join('')]; | ||
} | ||
return [...result, [encode(key, options), '[]=', encode(value, options)].join('')]; | ||
}; | ||
case 'comma': | ||
case 'separator': | ||
return key => (result, value) => { | ||
if (value === null || value === undefined || value.length === 0) { | ||
return result; | ||
} | ||
if (result.length === 0) { | ||
return [[encode(key, options), '=', encode(value, options)].join('')]; | ||
} | ||
return [[result, encode(value, options)].join(options.arrayFormatSeparator)]; | ||
}; | ||
default: | ||
return key => (result, value) => { | ||
if ( | ||
value === undefined || | ||
(options.skipNull && value === null) || | ||
(options.skipEmptyString && value === '') | ||
) { | ||
return result; | ||
} | ||
if (value === null) { | ||
return [...result, encode(key, options)]; | ||
} | ||
return [...result, [encode(key, options), '=', encode(value, options)].join('')]; | ||
}; | ||
} | ||
} | ||
function parserForArrayFormat(options) { | ||
let result; | ||
switch (options.arrayFormat) { | ||
case 'index': | ||
return (key, value, accumulator) => { | ||
result = /\[(\d*)\]$/.exec(key); | ||
key = key.replace(/\[\d*\]$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = {}; | ||
} | ||
accumulator[key][result[1]] = value; | ||
}; | ||
case 'bracket': | ||
return (key, value, accumulator) => { | ||
result = /(\[\])$/.exec(key); | ||
key = key.replace(/\[\]$/, ''); | ||
if (!result) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = [value]; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
case 'comma': | ||
case 'separator': | ||
return (key, value, accumulator) => { | ||
const isArray = typeof value === 'string' && value.split('').indexOf(options.arrayFormatSeparator) > -1; | ||
const newValue = isArray ? value.split(options.arrayFormatSeparator).map(item => decode(item, options)) : value === null ? value : decode(value, options); | ||
accumulator[key] = newValue; | ||
}; | ||
default: | ||
return (key, value, accumulator) => { | ||
if (accumulator[key] === undefined) { | ||
accumulator[key] = value; | ||
return; | ||
} | ||
accumulator[key] = [].concat(accumulator[key], value); | ||
}; | ||
} | ||
} | ||
function validateArrayFormatSeparator(value) { | ||
if (typeof value !== 'string' || value.length !== 1) { | ||
throw new TypeError('arrayFormatSeparator must be single character string'); | ||
} | ||
} | ||
function encode(value, options) { | ||
if (options.encode) { | ||
return options.strict ? strictUriEncode(value) : encodeURIComponent(value); | ||
} | ||
return value; | ||
} | ||
function decode(value, options) { | ||
if (options.decode) { | ||
return decodeUriComponent(value); | ||
} | ||
return value; | ||
} | ||
function keysSorter(input) { | ||
if (Array.isArray(input)) { | ||
return input.sort(); | ||
} | ||
if (typeof input === 'object') { | ||
return keysSorter(Object.keys(input)) | ||
.sort((a, b) => Number(a) - Number(b)) | ||
.map(key => input[key]); | ||
} | ||
return input; | ||
} | ||
function removeHash(input) { | ||
const hashStart = input.indexOf('#'); | ||
if (hashStart !== -1) { | ||
input = input.slice(0, hashStart); | ||
} | ||
return input; | ||
} | ||
function getHash(url) { | ||
let hash = ''; | ||
const hashStart = url.indexOf('#'); | ||
if (hashStart !== -1) { | ||
hash = url.slice(hashStart); | ||
} | ||
return hash; | ||
} | ||
function extract(input) { | ||
input = removeHash(input); | ||
const queryStart = input.indexOf('?'); | ||
if (queryStart === -1) { | ||
return ''; | ||
} | ||
return input.slice(queryStart + 1); | ||
} | ||
function parseValue(value, options) { | ||
if (options.parseNumbers && !Number.isNaN(Number(value)) && (typeof value === 'string' && value.trim() !== '')) { | ||
value = Number(value); | ||
} else if (options.parseBooleans && value !== null && (value.toLowerCase() === 'true' || value.toLowerCase() === 'false')) { | ||
value = value.toLowerCase() === 'true'; | ||
} | ||
return value; | ||
} | ||
function parse(input, options) { | ||
options = Object.assign({ | ||
decode: true, | ||
sort: true, | ||
arrayFormat: 'none', | ||
arrayFormatSeparator: ',', | ||
parseNumbers: false, | ||
parseBooleans: false | ||
}, options); | ||
validateArrayFormatSeparator(options.arrayFormatSeparator); | ||
const formatter = parserForArrayFormat(options); | ||
// Create an object with no prototype | ||
const ret = Object.create(null); | ||
if (typeof input !== 'string') { | ||
return ret; | ||
} | ||
input = input.trim().replace(/^[?#&]/, ''); | ||
if (!input) { | ||
return ret; | ||
} | ||
for (const param of input.split('&')) { | ||
let [key, value] = splitOnFirst(options.decode ? param.replace(/\+/g, ' ') : param, '='); | ||
// Missing `=` should be `null`: | ||
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters | ||
value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options); | ||
formatter(decode(key, options), value, ret); | ||
} | ||
for (const key of Object.keys(ret)) { | ||
const value = ret[key]; | ||
if (typeof value === 'object' && value !== null) { | ||
for (const k of Object.keys(value)) { | ||
value[k] = parseValue(value[k], options); | ||
} | ||
} else { | ||
ret[key] = parseValue(value, options); | ||
} | ||
} | ||
if (options.sort === false) { | ||
return ret; | ||
} | ||
return (options.sort === true ? Object.keys(ret).sort() : Object.keys(ret).sort(options.sort)).reduce((result, key) => { | ||
const value = ret[key]; | ||
if (Boolean(value) && typeof value === 'object' && !Array.isArray(value)) { | ||
// Sort object keys, not values | ||
result[key] = keysSorter(value); | ||
} else { | ||
result[key] = value; | ||
} | ||
return result; | ||
}, Object.create(null)); | ||
} | ||
exports.extract = extract; | ||
exports.parse = parse; | ||
exports.stringify = (object, options) => { | ||
if (!object) { | ||
return ''; | ||
} | ||
options = Object.assign({ | ||
encode: true, | ||
strict: true, | ||
arrayFormat: 'none', | ||
arrayFormatSeparator: ',' | ||
}, options); | ||
validateArrayFormatSeparator(options.arrayFormatSeparator); | ||
const shouldFilter = key => ( | ||
(options.skipNull && isNullOrUndefined(object[key])) || | ||
(options.skipEmptyString && object[key] === '') | ||
); | ||
const formatter = encoderForArrayFormat(options); | ||
const objectCopy = {}; | ||
for (const key of Object.keys(object)) { | ||
if (!shouldFilter(key)) { | ||
objectCopy[key] = object[key]; | ||
} | ||
} | ||
const keys = Object.keys(objectCopy); | ||
if (options.sort !== false) { | ||
keys.sort(options.sort); | ||
} | ||
return keys.map(key => { | ||
const value = object[key]; | ||
if (value === undefined) { | ||
return ''; | ||
} | ||
if (value === null) { | ||
return encode(key, options); | ||
} | ||
if (Array.isArray(value)) { | ||
return value | ||
.reduce(formatter(key), []) | ||
.join('&'); | ||
} | ||
return encode(key, options) + '=' + encode(value, options); | ||
}).filter(x => x.length > 0).join('&'); | ||
}; | ||
exports.parseUrl = (input, options) => { | ||
options = Object.assign({ | ||
decode: true | ||
}, options); | ||
const [url, hash] = splitOnFirst(input, '#'); | ||
return Object.assign( | ||
{ | ||
url: url.split('?')[0] || '', | ||
query: parse(extract(input), options) | ||
}, | ||
options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {} | ||
); | ||
}; | ||
exports.stringifyUrl = (input, options) => { | ||
options = Object.assign({ | ||
encode: true, | ||
strict: true | ||
}, options); | ||
const url = removeHash(input.url).split('?')[0] || ''; | ||
const queryFromUrl = exports.extract(input.url); | ||
const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false}); | ||
const query = Object.assign(parsedQueryFromUrl, input.query); | ||
let queryString = exports.stringify(query, options); | ||
if (queryString) { | ||
queryString = `?${queryString}`; | ||
} | ||
let hash = getHash(input.url); | ||
if (input.fragmentIdentifier) { | ||
hash = `#${encode(input.fragmentIdentifier, options)}`; | ||
} | ||
return `${url}${queryString}${hash}`; | ||
}; | ||
}); | ||
var queryString_1 = queryString.extract; | ||
var queryString_2 = queryString.parse; | ||
var queryString_3 = queryString.stringify; | ||
var queryString_4 = queryString.parseUrl; | ||
var queryString_5 = queryString.stringifyUrl; | ||
function buildQuerystring(params) { | ||
@@ -39,4 +557,8 @@ return Object.keys(params) | ||
} | ||
function stripTokenFromUrl(url) { | ||
return url.replace(/([?&])token=([^&#]+)/, '$1'); | ||
function stripTokenFromUrl(href) { | ||
//= > {url: 'https://foo.bar', query: {foo: 'bar'}} | ||
var parsedUrl = queryString.parseUrl(href, { parseFragmentIdentifier: true }); | ||
var url = parsedUrl.url, query = parsedUrl.query, fragmentIdentifier = parsedUrl.fragmentIdentifier; | ||
var token = query.token, params = __rest(query, ["token"]); | ||
return queryString.stringifyUrl({ url: url, query: params, fragmentIdentifier: fragmentIdentifier }); | ||
} | ||
@@ -43,0 +565,0 @@ var OidcJwtClientImpl = /** @class */ (function () { |
{ | ||
"name": "oidc-jwt-client", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Fetch JWTs for API access from oidc-jwt-provider", | ||
@@ -52,2 +52,3 @@ "main": "dist/index.js", | ||
"prettier": "^2.1.1", | ||
"query-string": "^6.13.5", | ||
"react": "^16.13.1", | ||
@@ -54,0 +55,0 @@ "react-dom": "^16.13.1", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
140175
1478
37