@okta/okta-auth-js 7.8.0 → 7.9.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/CHANGELOG.md +6 -0
- package/cjs/authn/util/poll.js +53 -2
- package/cjs/authn/util/poll.js.map +1 -1
- package/cjs/base/types.js.map +1 -1
- package/cjs/features.js +7 -0
- package/cjs/features.js.map +1 -1
- package/cjs/http/OktaUserAgent.js +2 -2
- package/cjs/idx/idxState/v1/idxResponseParser.js +1 -1
- package/cjs/idx/idxState/v1/idxResponseParser.js.map +1 -1
- package/cjs/util/jsonpath.js +32 -8
- package/cjs/util/jsonpath.js.map +1 -1
- package/dist/okta-auth-js.authn.min.analyzer.html +2 -2
- package/dist/okta-auth-js.authn.min.js +1 -1
- package/dist/okta-auth-js.authn.min.js.map +1 -1
- package/dist/okta-auth-js.core.min.analyzer.html +2 -2
- package/dist/okta-auth-js.core.min.js +1 -1
- package/dist/okta-auth-js.core.min.js.map +1 -1
- package/dist/okta-auth-js.idx.min.analyzer.html +2 -2
- package/dist/okta-auth-js.idx.min.js +1 -1
- package/dist/okta-auth-js.idx.min.js.map +1 -1
- package/dist/okta-auth-js.min.analyzer.html +2 -2
- package/dist/okta-auth-js.min.js +1 -1
- package/dist/okta-auth-js.min.js.map +1 -1
- package/dist/okta-auth-js.myaccount.min.analyzer.html +2 -2
- package/dist/okta-auth-js.myaccount.min.js +1 -1
- package/dist/okta-auth-js.myaccount.min.js.map +1 -1
- package/esm/browser/authn/util/poll.js +55 -6
- package/esm/browser/authn/util/poll.js.map +1 -1
- package/esm/browser/features.js +5 -1
- package/esm/browser/features.js.map +1 -1
- package/esm/browser/http/OktaUserAgent.js +2 -2
- package/esm/browser/idx/idxState/v1/idxResponseParser.js +1 -1
- package/esm/browser/idx/idxState/v1/idxResponseParser.js.map +1 -1
- package/esm/browser/package.json +1 -1
- package/esm/browser/util/jsonpath.js +25 -5
- package/esm/browser/util/jsonpath.js.map +1 -1
- package/esm/node/authn/util/poll.js +55 -7
- package/esm/node/authn/util/poll.js.map +1 -1
- package/esm/node/features.js +5 -1
- package/esm/node/features.js.map +1 -1
- package/esm/node/http/OktaUserAgent.js +2 -2
- package/esm/node/idx/idxState/v1/idxResponseParser.js +1 -1
- package/esm/node/idx/idxState/v1/idxResponseParser.js.map +1 -1
- package/esm/node/package.json +1 -1
- package/esm/node/util/jsonpath.js +25 -5
- package/esm/node/util/jsonpath.js.map +1 -1
- package/package.json +3 -4
- package/types/lib/base/types.d.ts +1 -0
- package/types/lib/features.d.ts +1 -0
- package/types/lib/util/jsonpath.d.ts +4 -2
- package/umd/authn.js +1 -1
- package/umd/authn.js.map +1 -1
- package/umd/core.js +1 -1
- package/umd/core.js.map +1 -1
- package/umd/default.js +1 -1
- package/umd/default.js.map +1 -1
- package/umd/idx.js +1 -1
- package/umd/idx.js.map +1 -1
- package/umd/myaccount.js +1 -1
- package/umd/myaccount.js.map +1 -1
package/CHANGELOG.md
CHANGED
package/cjs/authn/util/poll.js
CHANGED
|
@@ -9,6 +9,7 @@ var _AuthSdkError = _interopRequireDefault(require("../../errors/AuthSdkError"))
|
|
|
9
9
|
var _AuthPollStopError = _interopRequireDefault(require("../../errors/AuthPollStopError"));
|
|
10
10
|
var _types = require("../types");
|
|
11
11
|
var _stateToken = require("./stateToken");
|
|
12
|
+
var _features = require("../../features");
|
|
12
13
|
/*!
|
|
13
14
|
* Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.
|
|
14
15
|
* The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.")
|
|
@@ -70,6 +71,40 @@ function getPollFn(sdk, res, ref) {
|
|
|
70
71
|
withCredentials: true
|
|
71
72
|
});
|
|
72
73
|
}
|
|
74
|
+
const delayNextPoll = ms => {
|
|
75
|
+
// no need for extra logic in non-iOS environments, just continue polling
|
|
76
|
+
if (!(0, _features.isIOS)()) {
|
|
77
|
+
return (0, _util.delay)(ms);
|
|
78
|
+
}
|
|
79
|
+
let timeoutId;
|
|
80
|
+
const cancelableDelay = () => {
|
|
81
|
+
return new Promise(resolve => {
|
|
82
|
+
timeoutId = setTimeout(resolve, ms);
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
const delayForFocus = () => {
|
|
86
|
+
let pageVisibilityHandler;
|
|
87
|
+
return new Promise(resolve => {
|
|
88
|
+
let pageDidHide = false;
|
|
89
|
+
pageVisibilityHandler = () => {
|
|
90
|
+
if (document.hidden) {
|
|
91
|
+
clearTimeout(timeoutId);
|
|
92
|
+
pageDidHide = true;
|
|
93
|
+
} else if (pageDidHide) {
|
|
94
|
+
resolve();
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
document.addEventListener('visibilitychange', pageVisibilityHandler);
|
|
98
|
+
}).then(() => {
|
|
99
|
+
document.removeEventListener('visibilitychange', pageVisibilityHandler);
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
return Promise.race([
|
|
103
|
+
// this function will never resolve if the page changes to hidden because the timeout gets cleared
|
|
104
|
+
cancelableDelay(),
|
|
105
|
+
// this function won't resolve until the page becomes visible after being hidden
|
|
106
|
+
delayForFocus()]);
|
|
107
|
+
};
|
|
73
108
|
ref.isPolling = true;
|
|
74
109
|
var retryCount = 0;
|
|
75
110
|
var recursivePoll = function () {
|
|
@@ -77,6 +112,22 @@ function getPollFn(sdk, res, ref) {
|
|
|
77
112
|
if (!ref.isPolling) {
|
|
78
113
|
return Promise.reject(new _AuthPollStopError.default());
|
|
79
114
|
}
|
|
115
|
+
|
|
116
|
+
// don't trigger polling request if page is hidden wait until window is visible again
|
|
117
|
+
if ((0, _features.isIOS)() && document.hidden) {
|
|
118
|
+
let handler;
|
|
119
|
+
return new Promise(resolve => {
|
|
120
|
+
handler = () => {
|
|
121
|
+
if (!document.hidden) {
|
|
122
|
+
resolve();
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
document.addEventListener('visibilitychange', handler);
|
|
126
|
+
}).then(() => {
|
|
127
|
+
document.removeEventListener('visibilitychange', handler);
|
|
128
|
+
return recursivePoll();
|
|
129
|
+
});
|
|
130
|
+
}
|
|
80
131
|
return pollFn().then(function (pollRes) {
|
|
81
132
|
// Reset our retry counter on success
|
|
82
133
|
retryCount = 0;
|
|
@@ -92,7 +143,7 @@ function getPollFn(sdk, res, ref) {
|
|
|
92
143
|
}
|
|
93
144
|
|
|
94
145
|
// Continue poll
|
|
95
|
-
return (
|
|
146
|
+
return delayNextPoll(delay).then(recursivePoll);
|
|
96
147
|
} else {
|
|
97
148
|
// Any non-waiting result, even if polling was stopped
|
|
98
149
|
// during a request, will return
|
|
@@ -104,7 +155,7 @@ function getPollFn(sdk, res, ref) {
|
|
|
104
155
|
if (err.xhr && (err.xhr.status === 0 || err.xhr.status === 429) && retryCount <= 4) {
|
|
105
156
|
var delayLength = Math.pow(2, retryCount) * 1000;
|
|
106
157
|
retryCount++;
|
|
107
|
-
return (
|
|
158
|
+
return delayNextPoll(delayLength).then(recursivePoll);
|
|
108
159
|
}
|
|
109
160
|
throw err;
|
|
110
161
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"poll.js","names":["getPollFn","sdk","res","ref","options","delay","rememberDevice","autoPush","transactionCallBack","isNumber","isObject","DEFAULT_POLLING_DELAY","pollLink","getLink","pollFn","opts","e","Promise","reject","AuthSdkError","undefined","href","toQueryString","post","getStateToken","saveAuthnState","withCredentials","isPolling","retryCount","recursivePoll","AuthPollStopError","then","pollRes","factorResult","delayFn","tx","createTransaction","catch","err","xhr","status","delayLength","Math","pow"],"sources":["../../../../lib/authn/util/poll.ts"],"sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n *\n */\n\nimport { post } from '../../http';\nimport { isNumber, isObject, getLink, toQueryString, delay as delayFn } from '../../util';\nimport { DEFAULT_POLLING_DELAY } from '../../constants';\nimport AuthSdkError from '../../errors/AuthSdkError';\nimport AuthPollStopError from '../../errors/AuthPollStopError';\nimport { AuthnTransactionState } from '../types';\nimport { getStateToken } from './stateToken';\n\ninterface PollOptions {\n delay?: number;\n rememberDevice?: boolean;\n autoPush?: boolean;\n transactionCallBack?: (AuthnTransactionState) => void;\n}\n\nexport function getPollFn(sdk, res: AuthnTransactionState, ref) {\n return function (options: PollOptions | number) {\n var delay;\n var rememberDevice;\n var autoPush;\n var transactionCallBack;\n\n if (isNumber(options)) {\n delay = options;\n } else if (isObject(options)) {\n options = options as PollOptions;\n delay = options.delay;\n rememberDevice = options.rememberDevice;\n autoPush = options.autoPush;\n transactionCallBack = options.transactionCallBack;\n }\n\n if (!delay && delay !== 0) {\n delay = DEFAULT_POLLING_DELAY;\n }\n\n // Get the poll function\n var pollLink = getLink(res, 'next', 'poll');\n // eslint-disable-next-line complexity\n function pollFn() {\n var opts = {} as PollOptions;\n if (typeof autoPush === 'function') {\n try {\n opts.autoPush = !!autoPush();\n }\n catch (e) {\n return Promise.reject(new AuthSdkError('AutoPush resulted in an error.'));\n }\n }\n else if (autoPush !== undefined && autoPush !== null) {\n opts.autoPush = !!autoPush;\n }\n if (typeof rememberDevice === 'function') {\n try {\n opts.rememberDevice = !!rememberDevice();\n }\n catch (e) {\n return Promise.reject(new AuthSdkError('RememberDevice resulted in an error.'));\n }\n }\n else if (rememberDevice !== undefined && rememberDevice !== null) {\n opts.rememberDevice = !!rememberDevice;\n }\n\n var href = pollLink.href + toQueryString(opts);\n return post(sdk, href, getStateToken(res), {\n saveAuthnState: false,\n withCredentials: true\n });\n }\n\n ref.isPolling = true;\n\n var retryCount = 0;\n var recursivePoll = function () {\n // If the poll was manually stopped during the delay\n if (!ref.isPolling) {\n return Promise.reject(new AuthPollStopError());\n }\n return pollFn()\n .then(function (pollRes) {\n // Reset our retry counter on success\n retryCount = 0;\n\n // If we're still waiting\n if (pollRes.factorResult && pollRes.factorResult === 'WAITING') {\n\n // If the poll was manually stopped while the pollFn was called\n if (!ref.isPolling) {\n throw new AuthPollStopError();\n }\n\n if (typeof transactionCallBack === 'function') {\n transactionCallBack(pollRes);\n }\n\n // Continue poll\n return delayFn(delay).then(recursivePoll);\n\n } else {\n // Any non-waiting result, even if polling was stopped\n // during a request, will return\n ref.isPolling = false;\n return sdk.tx.createTransaction(pollRes);\n }\n })\n .catch(function(err) {\n // Exponential backoff, up to 16 seconds\n if (err.xhr &&\n (err.xhr.status === 0 || err.xhr.status === 429) &&\n retryCount <= 4) {\n var delayLength = Math.pow(2, retryCount) * 1000;\n retryCount++;\n return delayFn(delayLength)\n .then(recursivePoll);\n }\n throw err;\n });\n };\n return recursivePoll()\n .catch(function(err) {\n ref.isPolling = false;\n throw err;\n });\n };\n}\n"],"mappings":";;;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAiBO,SAASA,SAAS,CAACC,GAAG,EAAEC,GAA0B,EAAEC,GAAG,EAAE;EAC9D,OAAO,UAAUC,OAA6B,EAAE;IAC9C,IAAIC,KAAK;IACT,IAAIC,cAAc;IAClB,IAAIC,QAAQ;IACZ,IAAIC,mBAAmB;IAEvB,IAAI,IAAAC,cAAQ,EAACL,OAAO,CAAC,EAAE;MACrBC,KAAK,GAAGD,OAAO;IACjB,CAAC,MAAM,IAAI,IAAAM,cAAQ,EAACN,OAAO,CAAC,EAAE;MAC5BA,OAAO,GAAGA,OAAsB;MAChCC,KAAK,GAAGD,OAAO,CAACC,KAAK;MACrBC,cAAc,GAAGF,OAAO,CAACE,cAAc;MACvCC,QAAQ,GAAGH,OAAO,CAACG,QAAQ;M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,CACxBV,IAAI,CAACF,aAAa,CAAC;QACxB;QACA,MAAMS,GAAG;MACX,CAAC,CAAC;IACN,CAAC;IACD,OAAOT,aAAa,EAAE,CACnBQ,KAAK,CAAC,UAASC,GAAG,EAAE;MACnBnC,GAAG,CAACwB,SAAS,GAAG,KAAK;MACrB,MAAMW,GAAG;IACX,CAAC,CAAC;EACN,CAAC;AACH"}
|
|
1
|
+
{"version":3,"file":"poll.js","names":["getPollFn","sdk","res","ref","options","delay","rememberDevice","autoPush","transactionCallBack","isNumber","isObject","DEFAULT_POLLING_DELAY","pollLink","getLink","pollFn","opts","e","Promise","reject","AuthSdkError","undefined","href","toQueryString","post","getStateToken","saveAuthnState","withCredentials","delayNextPoll","ms","isIOS","delayFn","timeoutId","cancelableDelay","resolve","setTimeout","delayForFocus","pageVisibilityHandler","pageDidHide","document","hidden","clearTimeout","addEventListener","then","removeEventListener","race","isPolling","retryCount","recursivePoll","AuthPollStopError","handler","pollRes","factorResult","tx","createTransaction","catch","err","xhr","status","delayLength","Math","pow"],"sources":["../../../../lib/authn/util/poll.ts"],"sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n *\n */\n\nimport { post } from '../../http';\nimport { isNumber, isObject, getLink, toQueryString, delay as delayFn } from '../../util';\nimport { DEFAULT_POLLING_DELAY } from '../../constants';\nimport AuthSdkError from '../../errors/AuthSdkError';\nimport AuthPollStopError from '../../errors/AuthPollStopError';\nimport { AuthnTransactionState } from '../types';\nimport { getStateToken } from './stateToken';\nimport { isIOS } from '../../features';\n\ninterface PollOptions {\n delay?: number;\n rememberDevice?: boolean;\n autoPush?: boolean;\n transactionCallBack?: (AuthnTransactionState) => void;\n}\n\nexport function getPollFn(sdk, res: AuthnTransactionState, ref) {\n return function (options: PollOptions | number) {\n var delay;\n var rememberDevice;\n var autoPush;\n var transactionCallBack;\n\n if (isNumber(options)) {\n delay = options;\n } else if (isObject(options)) {\n options = options as PollOptions;\n delay = options.delay;\n rememberDevice = options.rememberDevice;\n autoPush = options.autoPush;\n transactionCallBack = options.transactionCallBack;\n }\n\n if (!delay && delay !== 0) {\n delay = DEFAULT_POLLING_DELAY;\n }\n\n // Get the poll function\n var pollLink = getLink(res, 'next', 'poll');\n // eslint-disable-next-line complexity\n function pollFn() {\n var opts = {} as PollOptions;\n if (typeof autoPush === 'function') {\n try {\n opts.autoPush = !!autoPush();\n }\n catch (e) {\n return Promise.reject(new AuthSdkError('AutoPush resulted in an error.'));\n }\n }\n else if (autoPush !== undefined && autoPush !== null) {\n opts.autoPush = !!autoPush;\n }\n if (typeof rememberDevice === 'function') {\n try {\n opts.rememberDevice = !!rememberDevice();\n }\n catch (e) {\n return Promise.reject(new AuthSdkError('RememberDevice resulted in an error.'));\n }\n }\n else if (rememberDevice !== undefined && rememberDevice !== null) {\n opts.rememberDevice = !!rememberDevice;\n }\n\n var href = pollLink.href + toQueryString(opts);\n return post(sdk, href, getStateToken(res), {\n saveAuthnState: false,\n withCredentials: true\n });\n }\n\n const delayNextPoll = (ms) => {\n // no need for extra logic in non-iOS environments, just continue polling\n if (!isIOS()) {\n return delayFn(ms);\n }\n\n let timeoutId: ReturnType<typeof setTimeout>;\n const cancelableDelay = () => {\n return new Promise((resolve) => {\n timeoutId = setTimeout(resolve, ms);\n });\n };\n\n const delayForFocus = () => {\n let pageVisibilityHandler;\n return new Promise<void>((resolve) => {\n let pageDidHide = false;\n pageVisibilityHandler = () => {\n if (document.hidden) {\n clearTimeout(timeoutId);\n pageDidHide = true;\n }\n else if (pageDidHide) {\n resolve();\n }\n };\n\n document.addEventListener('visibilitychange', pageVisibilityHandler);\n })\n .then(() => {\n document.removeEventListener('visibilitychange', pageVisibilityHandler);\n });\n };\n\n return Promise.race([\n // this function will never resolve if the page changes to hidden because the timeout gets cleared\n cancelableDelay(),\n // this function won't resolve until the page becomes visible after being hidden\n delayForFocus(),\n ]);\n };\n\n ref.isPolling = true;\n\n var retryCount = 0;\n var recursivePoll = function () {\n // If the poll was manually stopped during the delay\n if (!ref.isPolling) {\n return Promise.reject(new AuthPollStopError());\n }\n\n // don't trigger polling request if page is hidden wait until window is visible again\n if (isIOS() && document.hidden) {\n let handler;\n return new Promise<void>((resolve) => {\n handler = () => {\n if (!document.hidden) {\n resolve();\n }\n };\n document.addEventListener('visibilitychange', handler);\n })\n .then(() => {\n document.removeEventListener('visibilitychange', handler);\n return recursivePoll();\n });\n }\n\n return pollFn()\n .then(function (pollRes) {\n // Reset our retry counter on success\n retryCount = 0;\n\n // If we're still waiting\n if (pollRes.factorResult && pollRes.factorResult === 'WAITING') {\n\n // If the poll was manually stopped while the pollFn was called\n if (!ref.isPolling) {\n throw new AuthPollStopError();\n }\n\n if (typeof transactionCallBack === 'function') {\n transactionCallBack(pollRes);\n }\n\n // Continue poll\n return delayNextPoll(delay).then(recursivePoll);\n\n } else {\n // Any non-waiting result, even if polling was stopped\n // during a request, will return\n ref.isPolling = false;\n return sdk.tx.createTransaction(pollRes);\n }\n })\n .catch(function(err) {\n // Exponential backoff, up to 16 seconds\n if (err.xhr &&\n (err.xhr.status === 0 || err.xhr.status === 429) &&\n retryCount <= 4) {\n var delayLength = Math.pow(2, retryCount) * 1000;\n retryCount++;\n return delayNextPoll(delayLength)\n .then(recursivePoll);\n }\n throw err;\n });\n };\n return recursivePoll()\n .catch(function(err) {\n ref.isPolling = false;\n throw err;\n });\n };\n}\n"],"mappings":";;;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AApBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAkBO,SAASA,SA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AU,EAAE;YAC7CA,mBAAmB,CAAC0C,OAAO,CAAC;UAC9B;;UAEA;UACA,OAAOvB,aAAa,CAACtB,KAAK,CAAC,CAACqC,IAAI,CAACK,aAAa,CAAC;QAEjD,CAAC,MAAM;UACL;UACA;UACA5C,GAAG,CAAC0C,SAAS,GAAG,KAAK;UACrB,OAAO5C,GAAG,CAACmD,EAAE,CAACC,iBAAiB,CAACH,OAAO,CAAC;QAC1C;MACF,CAAC,CAAC,CACDI,KAAK,CAAC,UAASC,GAAG,EAAE;QACnB;QACA,IAAIA,GAAG,CAACC,GAAG,KACND,GAAG,CAACC,GAAG,CAACC,MAAM,KAAK,CAAC,IAAIF,GAAG,CAACC,GAAG,CAACC,MAAM,KAAK,GAAG,CAAC,IAChDX,UAAU,IAAI,CAAC,EAAE;UACnB,IAAIY,WAAW,GAAGC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEd,UAAU,CAAC,GAAG,IAAI;UAChDA,UAAU,EAAE;UACZ,OAAOnB,aAAa,CAAC+B,WAAW,CAAC,CAC9BhB,IAAI,CAACK,aAAa,CAAC;QACxB;QACA,MAAMQ,GAAG;MACX,CAAC,CAAC;IACN,CAAC;IACD,OAAOR,aAAa,EAAE,CACnBO,KAAK,CAAC,UAASC,GAAG,EAAE;MACnBpD,GAAG,CAAC0C,SAAS,GAAG,KAAK;MACrB,MAAMU,GAAG;IACX,CAAC,CAAC;EACN,CAAC;AACH"}
|
package/cjs/base/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../lib/base/types.ts"],"sourcesContent":["/*!\n * Copyright (c) 2021-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport * as constants from '../constants';\n\nexport declare class EventEmitter {\n on (event: string, callback: (...args: any[]) => any, ctx?: any): EventEmitter;\n once (event: string, callback: (...args: any[]) => any, ctx?: any): EventEmitter;\n emit (event: string, ...args: any[]): EventEmitter;\n off (event: string, callback?: (...args: any[]) => any): EventEmitter;\n}\n\nexport interface FeaturesAPI {\n isLocalhost(): boolean;\n isHTTPS(): boolean;\n isPopupPostMessageSupported(): boolean;\n hasTextEncoder(): boolean;\n isTokenVerifySupported(): boolean;\n isPKCESupported(): boolean;\n isIE11OrLess(): boolean;\n isDPoPSupported(): boolean;\n}\n\n\nexport interface FingerprintOptions {\n timeout?: number;\n container?: Element | null;\n}\nexport type FingerprintAPI = (options?: FingerprintOptions) => Promise<string>;\n\n// options that can be passed to AuthJS\nexport interface OktaAuthBaseOptions {\n devMode?: boolean;\n}\n\n// a class that constructs options\nexport interface OktaAuthOptionsConstructor<O extends OktaAuthBaseOptions = OktaAuthBaseOptions> {\n new(args: any): O;\n}\n\n// a \"base\" instance of AuthJS\nexport interface OktaAuthBaseInterface<O extends OktaAuthBaseOptions = OktaAuthBaseOptions> {\n options: O;\n emitter: EventEmitter;\n features: FeaturesAPI;\n}\n\n// a constructor that returns an instance of AuthJS\nexport interface OktaAuthConstructor\n<\n I extends OktaAuthBaseInterface = OktaAuthBaseInterface\n> \n{\n new(...args: any[]): I;\n features: FeaturesAPI; // static class member\n constants: typeof constants;\n}\n"],"mappings":""}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../lib/base/types.ts"],"sourcesContent":["/*!\n * Copyright (c) 2021-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\nimport * as constants from '../constants';\n\nexport declare class EventEmitter {\n on (event: string, callback: (...args: any[]) => any, ctx?: any): EventEmitter;\n once (event: string, callback: (...args: any[]) => any, ctx?: any): EventEmitter;\n emit (event: string, ...args: any[]): EventEmitter;\n off (event: string, callback?: (...args: any[]) => any): EventEmitter;\n}\n\nexport interface FeaturesAPI {\n isLocalhost(): boolean;\n isHTTPS(): boolean;\n isPopupPostMessageSupported(): boolean;\n hasTextEncoder(): boolean;\n isTokenVerifySupported(): boolean;\n isPKCESupported(): boolean;\n isIE11OrLess(): boolean;\n isDPoPSupported(): boolean;\n isIOS(): boolean;\n}\n\n\nexport interface FingerprintOptions {\n timeout?: number;\n container?: Element | null;\n}\nexport type FingerprintAPI = (options?: FingerprintOptions) => Promise<string>;\n\n// options that can be passed to AuthJS\nexport interface OktaAuthBaseOptions {\n devMode?: boolean;\n}\n\n// a class that constructs options\nexport interface OktaAuthOptionsConstructor<O extends OktaAuthBaseOptions = OktaAuthBaseOptions> {\n new(args: any): O;\n}\n\n// a \"base\" instance of AuthJS\nexport interface OktaAuthBaseInterface<O extends OktaAuthBaseOptions = OktaAuthBaseOptions> {\n options: O;\n emitter: EventEmitter;\n features: FeaturesAPI;\n}\n\n// a constructor that returns an instance of AuthJS\nexport interface OktaAuthConstructor\n<\n I extends OktaAuthBaseInterface = OktaAuthBaseInterface\n> \n{\n new(...args: any[]): I;\n features: FeaturesAPI; // static class member\n constants: typeof constants;\n}\n"],"mappings":""}
|
package/cjs/features.js
CHANGED
|
@@ -7,6 +7,7 @@ exports.isDPoPSupported = isDPoPSupported;
|
|
|
7
7
|
exports.isFingerprintSupported = isFingerprintSupported;
|
|
8
8
|
exports.isHTTPS = isHTTPS;
|
|
9
9
|
exports.isIE11OrLess = isIE11OrLess;
|
|
10
|
+
exports.isIOS = isIOS;
|
|
10
11
|
exports.isLocalhost = isLocalhost;
|
|
11
12
|
exports.isPKCESupported = isPKCESupported;
|
|
12
13
|
exports.isPopupPostMessageSupported = isPopupPostMessageSupported;
|
|
@@ -83,4 +84,10 @@ function isLocalhost() {
|
|
|
83
84
|
function isDPoPSupported() {
|
|
84
85
|
return !isIE11OrLess() && typeof window.indexedDB !== 'undefined' && hasTextEncoder() && isWebCryptoSubtleSupported();
|
|
85
86
|
}
|
|
87
|
+
function isIOS() {
|
|
88
|
+
// iOS detection from: http://stackoverflow.com/a/9039885/177710
|
|
89
|
+
return isBrowser() && typeof navigator !== 'undefined' && typeof navigator.userAgent !== 'undefined' &&
|
|
90
|
+
// @ts-expect-error - MSStream is not in `window` type, unsurprisingly
|
|
91
|
+
/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
|
|
92
|
+
}
|
|
86
93
|
//# sourceMappingURL=features.js.map
|
package/cjs/features.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.js","names":["isWindowsPhone","isBrowser","document","window","isIE11OrLess","documentMode","getUserAgent","navigator","userAgent","isFingerprintSupported","agent","test","isPopupPostMessageSupported","isIE8or9","postMessage","isWebCryptoSubtleSupported","webcrypto","subtle","Uint8Array","isTokenVerifySupported","hasTextEncoder","TextEncoder","isPKCESupported","isHTTPS","location","protocol","isLocalhost","hostname","isDPoPSupported","indexedDB"],"sources":["../../lib/features.ts"],"sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n/* eslint-disable node/no-unsupported-features/node-builtins */\n/* global document, window, TextEncoder, navigator */\n\nimport { webcrypto } from './crypto';\n\nconst isWindowsPhone = /windows phone|iemobile|wpdesktop/i;\t\n\nexport function isBrowser() {\n return typeof document !== 'undefined' && typeof window !== 'undefined';\n}\n\nexport function isIE11OrLess() {\n if (!isBrowser()) {\n return false;\n }\n const documentMode = (document as any).documentMode;\n return !!documentMode && documentMode <= 11;\n}\n\nexport function getUserAgent() {\n return navigator.userAgent;\n}\n\nexport function isFingerprintSupported() {\n const agent = getUserAgent();\n return agent && !isWindowsPhone.test(agent);\t\n}\n\nexport function isPopupPostMessageSupported() {\n if (!isBrowser()) {\n return false;\n }\n const documentMode = (document as any).documentMode;\n var isIE8or9 = documentMode && documentMode < 10;\n if (typeof window.postMessage !== 'undefined' && !isIE8or9) {\n return true;\n }\n return false;\n}\n\nfunction isWebCryptoSubtleSupported () {\n return typeof webcrypto !== 'undefined'\n && webcrypto !== null\n && typeof webcrypto.subtle !== 'undefined'\n && typeof Uint8Array !== 'undefined';\n}\n\nexport function isTokenVerifySupported() {\n return isWebCryptoSubtleSupported();\n}\n\nexport function hasTextEncoder() {\n return typeof TextEncoder !== 'undefined';\n}\n\nexport function isPKCESupported() {\n return isTokenVerifySupported() && hasTextEncoder();\n}\n\nexport function isHTTPS() {\n if (!isBrowser()) {\n return false;\n }\n return window.location.protocol === 'https:';\n}\n\nexport function isLocalhost() {\n // eslint-disable-next-line compat/compat\n return isBrowser() && window.location.hostname === 'localhost';\n}\n\n// For now, DPoP is only supported on browsers\nexport function isDPoPSupported () {\n return !isIE11OrLess() &&\n typeof window.indexedDB !== 'undefined' &&\n hasTextEncoder() &&\n isWebCryptoSubtleSupported();\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"features.js","names":["isWindowsPhone","isBrowser","document","window","isIE11OrLess","documentMode","getUserAgent","navigator","userAgent","isFingerprintSupported","agent","test","isPopupPostMessageSupported","isIE8or9","postMessage","isWebCryptoSubtleSupported","webcrypto","subtle","Uint8Array","isTokenVerifySupported","hasTextEncoder","TextEncoder","isPKCESupported","isHTTPS","location","protocol","isLocalhost","hostname","isDPoPSupported","indexedDB","isIOS","MSStream"],"sources":["../../lib/features.ts"],"sourcesContent":["/*!\n * Copyright (c) 2015-present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n/* eslint-disable node/no-unsupported-features/node-builtins */\n/* global document, window, TextEncoder, navigator */\n\nimport { webcrypto } from './crypto';\n\nconst isWindowsPhone = /windows phone|iemobile|wpdesktop/i;\t\n\nexport function isBrowser() {\n return typeof document !== 'undefined' && typeof window !== 'undefined';\n}\n\nexport function isIE11OrLess() {\n if (!isBrowser()) {\n return false;\n }\n const documentMode = (document as any).documentMode;\n return !!documentMode && documentMode <= 11;\n}\n\nexport function getUserAgent() {\n return navigator.userAgent;\n}\n\nexport function isFingerprintSupported() {\n const agent = getUserAgent();\n return agent && !isWindowsPhone.test(agent);\t\n}\n\nexport function isPopupPostMessageSupported() {\n if (!isBrowser()) {\n return false;\n }\n const documentMode = (document as any).documentMode;\n var isIE8or9 = documentMode && documentMode < 10;\n if (typeof window.postMessage !== 'undefined' && !isIE8or9) {\n return true;\n }\n return false;\n}\n\nfunction isWebCryptoSubtleSupported () {\n return typeof webcrypto !== 'undefined'\n && webcrypto !== null\n && typeof webcrypto.subtle !== 'undefined'\n && typeof Uint8Array !== 'undefined';\n}\n\nexport function isTokenVerifySupported() {\n return isWebCryptoSubtleSupported();\n}\n\nexport function hasTextEncoder() {\n return typeof TextEncoder !== 'undefined';\n}\n\nexport function isPKCESupported() {\n return isTokenVerifySupported() && hasTextEncoder();\n}\n\nexport function isHTTPS() {\n if (!isBrowser()) {\n return false;\n }\n return window.location.protocol === 'https:';\n}\n\nexport function isLocalhost() {\n // eslint-disable-next-line compat/compat\n return isBrowser() && window.location.hostname === 'localhost';\n}\n\n// For now, DPoP is only supported on browsers\nexport function isDPoPSupported () {\n return !isIE11OrLess() &&\n typeof window.indexedDB !== 'undefined' &&\n hasTextEncoder() &&\n isWebCryptoSubtleSupported();\n}\n\nexport function isIOS () {\n // iOS detection from: http://stackoverflow.com/a/9039885/177710\n return isBrowser() && typeof navigator !== 'undefined' && typeof navigator.userAgent !== 'undefined' &&\n // @ts-expect-error - MSStream is not in `window` type, unsurprisingly\n (/iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream);\n}\n"],"mappings":";;;;;;;;;;;;;;AAeA;AAfA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAIA,MAAMA,cAAc,GAAG,mCAAmC;AAEnD,SAASC,SAAS,GAAG;EAC1B,OAAO,OAAOC,QAAQ,KAAK,WAAW,IAAI,OAAOC,MAAM,KAAK,WAAW;AACzE;AAEO,SAASC,YAAY,GAAG;EAC7B,IAAI,CAACH,SAAS,EAAE,EAAE;IAChB,OAAO,KAAK;EACd;EACA,MAAMI,YAAY,GAAIH,QAAQ,CAASG,YAAY;EACnD,OAAO,CAAC,CAACA,YAAY,IAAIA,YAAY,IAAI,EAAE;AAC7C;AAEO,SAASC,YAAY,GAAG;EAC7B,OAAOC,SAAS,CAACC,SAAS;AAC5B;AAEO,SAASC,sBAAsB,GAAG;EACvC,MAAMC,KAAK,GAAGJ,YAAY,EAAE;EAC5B,OAAOI,KAAK,IAAI,CAACV,cAAc,CAACW,IAAI,CAACD,KAAK,CAAC;AAC7C;AAEO,SAASE,2BAA2B,GAAG;EAC5C,IAAI,CAACX,SAAS,EAAE,EAAE;IAChB,OAAO,KAAK;EACd;EACA,MAAMI,YAAY,GAAIH,QAAQ,CAASG,YAAY;EACnD,IAAI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= require("../features");
|
|
|
20
20
|
class OktaUserAgent {
|
|
21
21
|
constructor() {
|
|
22
22
|
// add base sdk env
|
|
23
|
-
this.environments = [`okta-auth-js/${"7.
|
|
23
|
+
this.environments = [`okta-auth-js/${"7.9.0"}`];
|
|
24
24
|
this.maybeAddNodeEnvironment();
|
|
25
25
|
}
|
|
26
26
|
addEnvironment(env) {
|
|
@@ -32,7 +32,7 @@ class OktaUserAgent {
|
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
34
|
getVersion() {
|
|
35
|
-
return "7.
|
|
35
|
+
return "7.9.0";
|
|
36
36
|
}
|
|
37
37
|
maybeAddNodeEnvironment() {
|
|
38
38
|
if ((0, _features.isBrowser)() || !process || !process.versions) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"idxResponseParser.js","names":["SKIP_FIELDS","parseNonRemediations","authClient","idxResponse","toPersist","actions","context","Object","keys","filter","field","forEach","fieldIsObject","rel","name","generateIdxAction","value","fieldValue","type","info","entries","subField","expandRelatesTo","k","query","Array","isArray","result","jsonpath","path","json","AuthSdkError","innerValue","convertRemediationAction","remediation","remediationActions","generateRemediationFunctions","actionFn","action","parseIdxResponse","remediationData","relatesTo","authenticatorChallenge","remediations","map"],"sources":["../../../../../lib/idx/idxState/v1/idxResponseParser.ts"],"sourcesContent":["/*!\n * Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n/* eslint-disable max-len */\n\nimport { OktaAuthIdxInterface, IdxResponse, IdxRemediation, IdxContext } from '../../types'; // auth-js/types\nimport { IdxActions } from '../../types/idx-js';\nimport { generateRemediationFunctions } from './remediationParser';\nimport generateIdxAction from './generateIdxAction';\nimport { jsonpath } from '../../../util/jsonpath';\nimport { AuthSdkError } from '../../../errors';\n\nconst SKIP_FIELDS = {\n 'remediation': true, // remediations are put into proceed/neededToProceed\n 'context': true, // the API response of 'context' isn't externally useful. We ignore it and put all non-action (contextual) info into idxState.context\n};\n\nexport const parseNonRemediations = function parseNonRemediations( authClient: OktaAuthIdxInterface, idxResponse: IdxResponse, toPersist = {} ) {\n const actions = {};\n const context = {} as IdxContext;\n\n Object.keys(idxResponse)\n .filter( field => !SKIP_FIELDS[field])\n .forEach( field => {\n const fieldIsObject = typeof idxResponse[field] === 'object' && !!idxResponse[field];\n\n if ( !fieldIsObject ) {\n // simple fields are contextual info\n context[field] = idxResponse[field];\n return;\n }\n\n if ( idxResponse[field].rel ) {\n // top level actions\n actions[idxResponse[field].name] = generateIdxAction(authClient, idxResponse[field], toPersist);\n return;\n }\n\n const { value: fieldValue, type, ...info} = idxResponse[field];\n context[field] = { type, ...info}; // add the non-action parts as context\n\n if ( type !== 'object' ) {\n // only object values hold actions\n context[field].value = fieldValue;\n return;\n }\n\n // We are an object field containing an object value\n context[field].value = {};\n Object.entries<IdxRemediation>(fieldValue)\n .forEach( ([subField, value]) => {\n if (value.rel) { // is [field].value[subField] an action?\n // add any \"action\" value subfields to actions\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n actions[`${field}-${subField.name || subField}`] = generateIdxAction(authClient, value, toPersist);\n } else {\n // add non-action value subfields to context\n context[field].value[subField] = value;\n }\n });\n });\n\n return { context, actions };\n};\n\nconst expandRelatesTo = (idxResponse, value) => {\n Object.keys(value).forEach(k => {\n if (k === 'relatesTo') {\n const query = Array.isArray(value[k]) ? value[k][0] : value[k];\n if (typeof query === 'string') {\n const result = jsonpath({ path: query, json: idxResponse })
|
|
1
|
+
{"version":3,"file":"idxResponseParser.js","names":["SKIP_FIELDS","parseNonRemediations","authClient","idxResponse","toPersist","actions","context","Object","keys","filter","field","forEach","fieldIsObject","rel","name","generateIdxAction","value","fieldValue","type","info","entries","subField","expandRelatesTo","k","query","Array","isArray","result","jsonpath","path","json","AuthSdkError","innerValue","convertRemediationAction","remediation","remediationActions","generateRemediationFunctions","actionFn","action","parseIdxResponse","remediationData","relatesTo","authenticatorChallenge","remediations","map"],"sources":["../../../../../lib/idx/idxState/v1/idxResponseParser.ts"],"sourcesContent":["/*!\n * Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved.\n * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the \"License.\")\n *\n * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n *\n * See the License for the specific language governing permissions and limitations under the License.\n */\n\n/* eslint-disable max-len */\n\nimport { OktaAuthIdxInterface, IdxResponse, IdxRemediation, IdxContext } from '../../types'; // auth-js/types\nimport { IdxActions } from '../../types/idx-js';\nimport { generateRemediationFunctions } from './remediationParser';\nimport generateIdxAction from './generateIdxAction';\nimport { jsonpath } from '../../../util/jsonpath';\nimport { AuthSdkError } from '../../../errors';\n\nconst SKIP_FIELDS = {\n 'remediation': true, // remediations are put into proceed/neededToProceed\n 'context': true, // the API response of 'context' isn't externally useful. We ignore it and put all non-action (contextual) info into idxState.context\n};\n\nexport const parseNonRemediations = function parseNonRemediations( authClient: OktaAuthIdxInterface, idxResponse: IdxResponse, toPersist = {} ) {\n const actions = {};\n const context = {} as IdxContext;\n\n Object.keys(idxResponse)\n .filter( field => !SKIP_FIELDS[field])\n .forEach( field => {\n const fieldIsObject = typeof idxResponse[field] === 'object' && !!idxResponse[field];\n\n if ( !fieldIsObject ) {\n // simple fields are contextual info\n context[field] = idxResponse[field];\n return;\n }\n\n if ( idxResponse[field].rel ) {\n // top level actions\n actions[idxResponse[field].name] = generateIdxAction(authClient, idxResponse[field], toPersist);\n return;\n }\n\n const { value: fieldValue, type, ...info} = idxResponse[field];\n context[field] = { type, ...info}; // add the non-action parts as context\n\n if ( type !== 'object' ) {\n // only object values hold actions\n context[field].value = fieldValue;\n return;\n }\n\n // We are an object field containing an object value\n context[field].value = {};\n Object.entries<IdxRemediation>(fieldValue)\n .forEach( ([subField, value]) => {\n if (value.rel) { // is [field].value[subField] an action?\n // add any \"action\" value subfields to actions\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n actions[`${field}-${subField.name || subField}`] = generateIdxAction(authClient, value, toPersist);\n } else {\n // add non-action value subfields to context\n context[field].value[subField] = value;\n }\n });\n });\n\n return { context, actions };\n};\n\nconst expandRelatesTo = (idxResponse, value) => {\n Object.keys(value).forEach(k => {\n if (k === 'relatesTo') {\n const query = Array.isArray(value[k]) ? value[k][0] : value[k];\n if (typeof query === 'string') {\n const result = jsonpath({ path: query, json: idxResponse });\n if (result) {\n value[k] = result;\n return;\n } else {\n throw new AuthSdkError(`Cannot resolve relatesTo: ${query}`);\n }\n }\n }\n if (Array.isArray(value[k])) {\n value[k].forEach(innerValue => expandRelatesTo(idxResponse, innerValue));\n }\n });\n};\n\nconst convertRemediationAction = (authClient: OktaAuthIdxInterface, remediation, toPersist) => {\n // Only remediation that has `rel` field (indicator for form submission) can have http action\n if (remediation.rel) {\n const remediationActions = generateRemediationFunctions( authClient, [remediation], toPersist );\n const actionFn = remediationActions[remediation.name];\n return {\n ...remediation,\n action: actionFn,\n };\n }\n\n return remediation;\n};\n\nexport const parseIdxResponse = function parseIdxResponse( authClient: OktaAuthIdxInterface, idxResponse, toPersist = {} ): {\n remediations: IdxRemediation[];\n context: IdxContext;\n actions: IdxActions;\n} {\n const remediationData = idxResponse.remediation?.value || [];\n\n remediationData.forEach(\n remediation => {\n // TODO: remove once IDX is fixed - OKTA-659181\n if (remediation.name === 'launch-authenticator' &&\n remediation?.relatesTo?.[0] === 'authenticatorChallenge' &&\n !idxResponse?.authenticatorChallenge\n ) {\n delete remediation.relatesTo;\n return;\n }\n\n return expandRelatesTo(idxResponse, remediation);\n }\n );\n\n const remediations = remediationData.map(remediation => convertRemediationAction( authClient, remediation, toPersist ));\n\n const { context, actions } = parseNonRemediations( authClient, idxResponse, toPersist );\n\n return {\n remediations,\n context,\n actions,\n };\n};\n"],"mappings":";;;;AAgBA;AACA;AACA;AACA;AAnBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;;AAEgG;;AAOhG,MAAMA,WAAW,GAAG;EAClB,aAAa,EAAE,IAAI;EAAE;EACrB,SAAS,EAAE,IAAI,CAAE;AACnB,CAAC;;AAEM,MAAMC,oBAAoB,GAAG,SAASA,oBAAoB,CAAEC,UAAgC,EAAEC,WAAwB,EAAEC,SAAS,GAAG,CAAC,CAAC,EAAG;EAC9I,MAAMC,OAAO,GAAG,CAAC,CAAC;EAClB,MAAMC,OAAO,GAAG,CAAC,CAAe;EAEhCC,MAAM,CAACC,IAAI,CAACL,WAAW,CAAC,CACrBM,MAAM,CAAEC,KAAK,IAAI,CAACV,WAAW,CAACU,KAAK,CAAC,CAAC,CACrCC,OAAO,CAAED,KAAK,IAAI;IACjB,MAAME,aAAa,GAAG,OAAOT,WAAW,CAACO,KAAK,CAAC,KAAK,QAAQ,IAAI,CAAC,CAACP,WAAW,CAACO,KAAK,CAAC;IAEpF,IAAK,CAACE,aAAa,EAAG;MACpB;MACAN,OAAO,CAACI,KAAK,CAAC,GAAGP,WAAW,CAACO,KAAK,CAAC;MACnC;IACF;IAEA,IAAKP,WAAW,CAACO,KAAK,CAAC,CAACG,GAAG,EAAG;MAC5B;MACAR,OAAO,CAACF,WAAW,CAACO,KAAK,CAAC,CAACI,IAAI,CAAC,GAAG,IAAAC,0BAAiB,EAACb,UAAU,EAAEC,WAAW,CAACO,KAAK,CAAC,EAAEN,SAAS,CAAC;MAC/F;IACF;IAEA,MAAM;MAAEY,KAAK,EAAEC,UAA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,CAAC,KAAK,wBAAwB,IACxD,CAACtC,WAAW,EAAEuC,sBAAsB,EACpC;MACA,OAAOR,WAAW,CAACO,SAAS;MAC5B;IACF;IAEA,OAAOnB,eAAe,CAACnB,WAAW,EAAE+B,WAAW,CAAC;EAClD,CAAC,CACF;EAED,MAAMS,YAAY,GAAGH,eAAe,CAACI,GAAG,CAACV,WAAW,IAAID,wBAAwB,CAAE/B,UAAU,EAAEgC,WAAW,EAAE9B,SAAS,CAAE,CAAC;EAEvH,MAAM;IAAEE,OAAO;IAAED;EAAQ,CAAC,GAAGJ,oBAAoB,CAAEC,UAAU,EAAEC,WAAW,EAAEC,SAAS,CAAE;EAEvF,OAAO;IACLuC,YAAY;IACZrC,OAAO;IACPD;EACF,CAAC;AACH,CAAC;AAAC"}
|
package/cjs/util/jsonpath.js
CHANGED
|
@@ -1,13 +1,37 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
exports.jsonpath = jsonpath;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
const jsonpathRegex = /\$?(?<step>\w+)|(?:\[(?<index>\d+)\])/g;
|
|
5
|
+
|
|
6
|
+
/* eslint complexity:[0,8] */
|
|
7
|
+
function jsonpath({
|
|
8
|
+
path,
|
|
9
|
+
json
|
|
10
|
+
}) {
|
|
11
|
+
const steps = [];
|
|
12
|
+
let match;
|
|
13
|
+
while ((match = jsonpathRegex.exec(path)) !== null) {
|
|
14
|
+
const step = match?.groups?.step ?? match?.groups?.index;
|
|
15
|
+
if (step) {
|
|
16
|
+
steps.push(step);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (steps.length < 1) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
// array length check above guarantees .pop() will return a value
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
25
|
+
const lastStep = steps.pop();
|
|
26
|
+
let curr = json;
|
|
27
|
+
for (const step of steps) {
|
|
28
|
+
if (Object.prototype.hasOwnProperty.call(curr, step)) {
|
|
29
|
+
if (typeof curr[step] !== 'object') {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
curr = curr[step];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return curr[lastStep];
|
|
12
36
|
}
|
|
13
37
|
//# sourceMappingURL=jsonpath.js.map
|
package/cjs/util/jsonpath.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonpath.js","names":["jsonpath","
|
|
1
|
+
{"version":3,"file":"jsonpath.js","names":["jsonpathRegex","jsonpath","path","json","steps","match","exec","step","groups","index","push","length","undefined","lastStep","pop","curr","Object","prototype","hasOwnProperty","call"],"sources":["../../../lib/util/jsonpath.ts"],"sourcesContent":["const jsonpathRegex = /\\$?(?<step>\\w+)|(?:\\[(?<index>\\d+)\\])/g;\n\n/* eslint complexity:[0,8] */\nexport function jsonpath({ path, json }) {\n const steps: string[] = [];\n let match: RegExpExecArray | null;\n while ((match = jsonpathRegex.exec(path)) !== null) {\n const step = match?.groups?.step ?? match?.groups?.index;\n if (step) {\n steps.push(step);\n }\n }\n\n if (steps.length < 1) {\n return undefined;\n }\n\n // array length check above guarantees .pop() will return a value\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const lastStep = steps.pop()!;\n let curr = json;\n for (const step of steps) {\n if (Object.prototype.hasOwnProperty.call(curr, step)) {\n if (typeof curr[step] !== 'object') {\n return undefined;\n }\n\n curr = curr[step];\n }\n }\n\n return curr[lastStep];\n}\n"],"mappings":";;;AAAA,MAAMA,aAAa,GAAG,wCAAwC;;AAE9D;AACO,SAASC,QAAQ,CAAC;EAAEC,IAAI;EAAEC;AAAK,CAAC,EAAE;EACvC,MAAMC,KAAe,GAAG,EAAE;EAC1B,IAAIC,KAA6B;EACjC,OAAO,CAACA,KAAK,GAAGL,aAAa,CAACM,IAAI,CAACJ,IAAI,CAAC,MAAM,IAAI,EAAE;IAClD,MAAMK,IAAI,GAAGF,KAAK,EAAEG,MAAM,EAAED,IAAI,IAAIF,KAAK,EAAEG,MAAM,EAAEC,KAAK;IACxD,IAAIF,IAAI,EAAE;MACRH,KAAK,CAACM,IAAI,CAACH,IAAI,CAAC;IAClB;EACF;EAEA,IAAIH,KAAK,CAACO,MAAM,GAAG,CAAC,EAAE;IACpB,OAAOC,SAAS;EAClB;;EAEA;EACA;EACA,MAAMC,QAAQ,GAAGT,KAAK,CAACU,GAAG,EAAG;EAC7B,IAAIC,IAAI,GAAGZ,IAAI;EACf,KAAK,MAAMI,IAAI,IAAIH,KAAK,EAAE;IACxB,IAAIY,MAAM,CAACC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,IAAI,EAAER,IAAI,CAAC,EAAE;MACpD,IAAI,OAAOQ,IAAI,CAACR,IAAI,CAAC,KAAK,QAAQ,EAAE;QAClC,OAAOK,SAAS;MAClB;MAEAG,IAAI,GAAGA,IAAI,CAACR,IAAI,CAAC;IACnB;EACF;EAEA,OAAOQ,IAAI,CAACF,QAAQ,CAAC;AACvB"}
|