@wandelbots/wandelbots-js-react-components 4.7.2 → 5.0.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.
Files changed (95) hide show
  1. package/README.md +11 -32
  2. package/dist/3d.cjs.js +1 -1
  3. package/dist/3d.es.js +1 -1
  4. package/dist/MotionGroupVisualizer-C6MgXjCN.cjs +2 -0
  5. package/dist/MotionGroupVisualizer-C6MgXjCN.cjs.map +1 -0
  6. package/dist/MotionGroupVisualizer-Cm-XYEZe.js +1328 -0
  7. package/dist/{MotionGroupVisualizer-DP4K1dVw.cjs.map → MotionGroupVisualizer-Cm-XYEZe.js.map} +1 -1
  8. package/dist/auth0-spa-js.production.esm-CVEdrQ4-.cjs +5 -0
  9. package/dist/auth0-spa-js.production.esm-CVEdrQ4-.cjs.map +1 -0
  10. package/dist/auth0-spa-js.production.esm-Cr9w0sUa.js +4217 -0
  11. package/dist/auth0-spa-js.production.esm-Cr9w0sUa.js.map +1 -0
  12. package/dist/components/3d-viewport/CoordinateSystemTransform.d.ts +1 -1
  13. package/dist/components/3d-viewport/CoordinateSystemTransform.d.ts.map +1 -1
  14. package/dist/components/3d-viewport/SafetyZonesRenderer.d.ts +1 -2
  15. package/dist/components/3d-viewport/SafetyZonesRenderer.d.ts.map +1 -1
  16. package/dist/components/3d-viewport/TrajectoryRenderer.d.ts +2 -2
  17. package/dist/components/3d-viewport/TrajectoryRenderer.d.ts.map +1 -1
  18. package/dist/components/3d-viewport/collider/ColliderCollection.d.ts +1 -1
  19. package/dist/components/3d-viewport/collider/ColliderElement.d.ts +1 -1
  20. package/dist/components/3d-viewport/collider/CollisionSceneRenderer.d.ts +2 -2
  21. package/dist/components/3d-viewport/collider/colliderShapeToBufferGeometry.d.ts +1 -1
  22. package/dist/core.cjs.js +1 -1
  23. package/dist/core.es.js +37 -39
  24. package/dist/core.es.js.map +1 -1
  25. package/dist/index.cjs.js +1 -1
  26. package/dist/index.d.ts +0 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.es.js +51 -55
  29. package/dist/index.es.js.map +1 -1
  30. package/dist/interpolation-GwZidExa.cjs +42 -0
  31. package/dist/interpolation-GwZidExa.cjs.map +1 -0
  32. package/dist/{interpolation-B8AcxfdD.js → interpolation-JdOMWH6y.js} +3635 -3115
  33. package/dist/interpolation-JdOMWH6y.js.map +1 -0
  34. package/dist/lib/ConnectedMotionGroup.d.ts +2 -3
  35. package/dist/lib/ConnectedMotionGroup.d.ts.map +1 -1
  36. package/dist/lib/MotionStreamConnection.d.ts +0 -1
  37. package/dist/lib/MotionStreamConnection.d.ts.map +1 -1
  38. package/dist/themes/createDarkTheme.d.ts.map +1 -1
  39. package/dist/themes/themeTypes.d.ts +0 -4
  40. package/dist/themes/themeTypes.d.ts.map +1 -1
  41. package/dist/{theming-BKpqgTRM.js → theming-B1iO9Lkl.js} +3104 -3062
  42. package/dist/theming-B1iO9Lkl.js.map +1 -0
  43. package/dist/theming-BKsKrdpU.cjs +115 -0
  44. package/dist/theming-BKsKrdpU.cjs.map +1 -0
  45. package/package.json +15 -29
  46. package/src/components/3d-viewport/CoordinateSystemTransform.tsx +29 -18
  47. package/src/components/3d-viewport/SafetyZonesRenderer.tsx +24 -151
  48. package/src/components/3d-viewport/TrajectoryRenderer.tsx +9 -10
  49. package/src/components/3d-viewport/collider/ColliderCollection.tsx +1 -1
  50. package/src/components/3d-viewport/collider/ColliderElement.tsx +1 -1
  51. package/src/components/3d-viewport/collider/CollisionSceneRenderer.tsx +2 -2
  52. package/src/components/3d-viewport/collider/colliderShapeToBufferGeometry.ts +1 -1
  53. package/src/index.ts +0 -1
  54. package/src/lib/ConnectedMotionGroup.ts +0 -5
  55. package/src/lib/MotionStreamConnection.ts +0 -5
  56. package/src/themes/createDarkTheme.ts +1 -22
  57. package/src/themes/themeTypes.ts +0 -5
  58. package/dist/LoadingCover-B3UN1lnU.js +0 -81
  59. package/dist/LoadingCover-B3UN1lnU.js.map +0 -1
  60. package/dist/LoadingCover-DXcsXWDy.cjs +0 -2
  61. package/dist/LoadingCover-DXcsXWDy.cjs.map +0 -1
  62. package/dist/MotionGroupVisualizer-CPEIGXUC.js +0 -1407
  63. package/dist/MotionGroupVisualizer-CPEIGXUC.js.map +0 -1
  64. package/dist/MotionGroupVisualizer-DP4K1dVw.cjs +0 -2
  65. package/dist/WandelscriptEditor-6sAoniLC.cjs +0 -2
  66. package/dist/WandelscriptEditor-6sAoniLC.cjs.map +0 -1
  67. package/dist/WandelscriptEditor-kWC2VyG_.js +0 -140
  68. package/dist/WandelscriptEditor-kWC2VyG_.js.map +0 -1
  69. package/dist/auth0-spa-js.production.esm-DNao6_S5.js +0 -4064
  70. package/dist/auth0-spa-js.production.esm-DNao6_S5.js.map +0 -1
  71. package/dist/auth0-spa-js.production.esm-DaBMfOV8.cjs +0 -5
  72. package/dist/auth0-spa-js.production.esm-DaBMfOV8.cjs.map +0 -1
  73. package/dist/components/wandelscript-editor/WandelscriptEditor.d.ts +0 -16
  74. package/dist/components/wandelscript-editor/WandelscriptEditor.d.ts.map +0 -1
  75. package/dist/components/wandelscript-editor/wandelscript.tmLanguage.d.ts +0 -45
  76. package/dist/components/wandelscript-editor/wandelscript.tmLanguage.d.ts.map +0 -1
  77. package/dist/externalizeComponent-B98tgTPP.cjs +0 -24
  78. package/dist/externalizeComponent-B98tgTPP.cjs.map +0 -1
  79. package/dist/externalizeComponent-BOqKMZMc.js +0 -526
  80. package/dist/externalizeComponent-BOqKMZMc.js.map +0 -1
  81. package/dist/interpolation-B8AcxfdD.js.map +0 -1
  82. package/dist/interpolation-SWzo5zr4.cjs +0 -20
  83. package/dist/interpolation-SWzo5zr4.cjs.map +0 -1
  84. package/dist/theming-BKpqgTRM.js.map +0 -1
  85. package/dist/theming-CatQaIl_.cjs +0 -115
  86. package/dist/theming-CatQaIl_.cjs.map +0 -1
  87. package/dist/wandelscript.cjs.js +0 -2
  88. package/dist/wandelscript.cjs.js.map +0 -1
  89. package/dist/wandelscript.d.ts +0 -2
  90. package/dist/wandelscript.d.ts.map +0 -1
  91. package/dist/wandelscript.es.js +0 -5
  92. package/dist/wandelscript.es.js.map +0 -1
  93. package/src/components/wandelscript-editor/WandelscriptEditor.tsx +0 -142
  94. package/src/components/wandelscript-editor/wandelscript.tmLanguage.ts +0 -62
  95. package/src/wandelscript.ts +0 -2
@@ -0,0 +1,4217 @@
1
+ function te(n, e) {
2
+ var t = {};
3
+ for (var o in n) Object.prototype.hasOwnProperty.call(n, o) && e.indexOf(o) < 0 && (t[o] = n[o]);
4
+ if (n != null && typeof Object.getOwnPropertySymbols == "function") {
5
+ var r = 0;
6
+ for (o = Object.getOwnPropertySymbols(n); r < o.length; r++) e.indexOf(o[r]) < 0 && Object.prototype.propertyIsEnumerable.call(n, o[r]) && (t[o[r]] = n[o[r]]);
7
+ }
8
+ return t;
9
+ }
10
+ const oi = { timeoutInSeconds: 60 }, Un = 1e4, _o = "memory", Kn = { name: "auth0-spa-js", version: "2.19.0" }, ar = () => Date.now(), H = "default";
11
+ class j extends Error {
12
+ constructor(e, t) {
13
+ super(t), this.error = e, this.error_description = t, Object.setPrototypeOf(this, j.prototype);
14
+ }
15
+ static fromPayload(e) {
16
+ let { error: t, error_description: o } = e;
17
+ return new j(t, o);
18
+ }
19
+ }
20
+ class $n extends j {
21
+ constructor(e, t, o) {
22
+ let r = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : null;
23
+ super(e, t), this.state = o, this.appState = r, Object.setPrototypeOf(this, $n.prototype);
24
+ }
25
+ }
26
+ class eo extends j {
27
+ constructor(e, t, o, r) {
28
+ let i = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : null;
29
+ super(e, t), this.connection = o, this.state = r, this.appState = i, Object.setPrototypeOf(this, eo.prototype);
30
+ }
31
+ }
32
+ class nt extends j {
33
+ constructor() {
34
+ super("timeout", "Timeout"), Object.setPrototypeOf(this, nt.prototype);
35
+ }
36
+ }
37
+ class to extends nt {
38
+ constructor(e) {
39
+ super(), this.popup = e, Object.setPrototypeOf(this, to.prototype);
40
+ }
41
+ }
42
+ class no extends j {
43
+ constructor(e) {
44
+ super("cancelled", "Popup closed"), this.popup = e, Object.setPrototypeOf(this, no.prototype);
45
+ }
46
+ }
47
+ class oo extends j {
48
+ constructor() {
49
+ super("popup_open", "Unable to open a popup for loginWithPopup - window.open returned `null`"), Object.setPrototypeOf(this, oo.prototype);
50
+ }
51
+ }
52
+ class $e extends j {
53
+ constructor(e, t, o, r) {
54
+ super(e, t), this.mfa_token = o, this.mfa_requirements = r, Object.setPrototypeOf(this, $e.prototype);
55
+ }
56
+ }
57
+ class tn extends j {
58
+ constructor(e, t) {
59
+ super("missing_refresh_token", "Missing Refresh Token (audience: '".concat(Zt(e, ["default"]), "', scope: '").concat(Zt(t), "')")), this.audience = e, this.scope = t, Object.setPrototypeOf(this, tn.prototype);
60
+ }
61
+ }
62
+ class ro extends j {
63
+ constructor(e, t) {
64
+ super("missing_scopes", "Missing requested scopes after refresh (audience: '".concat(Zt(e, ["default"]), "', missing scope: '").concat(Zt(t), "')")), this.audience = e, this.scope = t, Object.setPrototypeOf(this, ro.prototype);
65
+ }
66
+ }
67
+ class nn extends j {
68
+ constructor(e) {
69
+ super("use_dpop_nonce", "Server rejected DPoP proof: wrong nonce"), this.newDpopNonce = e, Object.setPrototypeOf(this, nn.prototype);
70
+ }
71
+ }
72
+ function Zt(n) {
73
+ return n && !(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : []).includes(n) ? n : "";
74
+ }
75
+ const Vt = () => window.crypto, rt = () => {
76
+ const n = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_~.";
77
+ let e = "";
78
+ for (; e.length < 43; ) {
79
+ const t = Vt().getRandomValues(new Uint8Array(43 - e.length));
80
+ for (const o of t) e.length < 43 && o < 198 && (e += n[o % 66]);
81
+ }
82
+ return e;
83
+ }, un = (n) => btoa(n), ri = [{ key: "name", type: ["string"] }, { key: "version", type: ["string", "number"] }, { key: "env", type: ["object"] }], Dn = function(n) {
84
+ let e = arguments.length > 1 && arguments[1] !== void 0 && arguments[1];
85
+ return Object.keys(n).reduce((t, o) => {
86
+ if (e && o === "env") return t;
87
+ const r = ri.find((i) => i.key === o);
88
+ return r && r.type.includes(typeof n[o]) && (t[o] = n[o]), t;
89
+ }, {});
90
+ }, ut = (n) => {
91
+ var { clientId: e } = n, t = te(n, ["clientId"]);
92
+ return new URLSearchParams(((o) => Object.keys(o).filter((r) => o[r] !== void 0).reduce((r, i) => Object.assign(Object.assign({}, r), { [i]: o[i] }), {}))(Object.assign({ client_id: e }, t))).toString();
93
+ }, So = async (n) => await Vt().subtle.digest({ name: "SHA-256" }, new TextEncoder().encode(n)), To = (n) => ((e) => decodeURIComponent(atob(e).split("").map((t) => "%" + ("00" + t.charCodeAt(0).toString(16)).slice(-2)).join("")))(n.replace(/_/g, "/").replace(/-/g, "+")), Eo = (n) => {
94
+ const e = new Uint8Array(n);
95
+ return ((t) => {
96
+ const o = { "+": "-", "/": "_", "=": "" };
97
+ return t.replace(/[+/=]/g, (r) => o[r]);
98
+ })(window.btoa(String.fromCharCode(...Array.from(e))));
99
+ };
100
+ var Le = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, sr = {}, io = {};
101
+ Object.defineProperty(io, "__esModule", { value: !0 });
102
+ var ii = (function() {
103
+ function n() {
104
+ var e = this;
105
+ this.locked = /* @__PURE__ */ new Map(), this.addToLocked = function(t, o) {
106
+ var r = e.locked.get(t);
107
+ r === void 0 ? o === void 0 ? e.locked.set(t, []) : e.locked.set(t, [o]) : o !== void 0 && (r.unshift(o), e.locked.set(t, r));
108
+ }, this.isLocked = function(t) {
109
+ return e.locked.has(t);
110
+ }, this.lock = function(t) {
111
+ return new Promise(function(o, r) {
112
+ e.isLocked(t) ? e.addToLocked(t, o) : (e.addToLocked(t), o());
113
+ });
114
+ }, this.unlock = function(t) {
115
+ var o = e.locked.get(t);
116
+ if (o !== void 0 && o.length !== 0) {
117
+ var r = o.pop();
118
+ e.locked.set(t, o), r !== void 0 && setTimeout(r, 0);
119
+ } else e.locked.delete(t);
120
+ };
121
+ }
122
+ return n.getInstance = function() {
123
+ return n.instance === void 0 && (n.instance = new n()), n.instance;
124
+ }, n;
125
+ })();
126
+ io.default = function() {
127
+ return ii.getInstance();
128
+ };
129
+ var ne = Le && Le.__awaiter || function(n, e, t, o) {
130
+ return new (t || (t = Promise))(function(r, i) {
131
+ function a(l) {
132
+ try {
133
+ c(o.next(l));
134
+ } catch (u) {
135
+ i(u);
136
+ }
137
+ }
138
+ function s(l) {
139
+ try {
140
+ c(o.throw(l));
141
+ } catch (u) {
142
+ i(u);
143
+ }
144
+ }
145
+ function c(l) {
146
+ l.done ? r(l.value) : new t(function(u) {
147
+ u(l.value);
148
+ }).then(a, s);
149
+ }
150
+ c((o = o.apply(n, e || [])).next());
151
+ });
152
+ }, oe = Le && Le.__generator || function(n, e) {
153
+ var t, o, r, i, a = { label: 0, sent: function() {
154
+ if (1 & r[0]) throw r[1];
155
+ return r[1];
156
+ }, trys: [], ops: [] };
157
+ return i = { next: s(0), throw: s(1), return: s(2) }, typeof Symbol == "function" && (i[Symbol.iterator] = function() {
158
+ return this;
159
+ }), i;
160
+ function s(c) {
161
+ return function(l) {
162
+ return (function(u) {
163
+ if (t) throw new TypeError("Generator is already executing.");
164
+ for (; a; ) try {
165
+ if (t = 1, o && (r = 2 & u[0] ? o.return : u[0] ? o.throw || ((r = o.return) && r.call(o), 0) : o.next) && !(r = r.call(o, u[1])).done) return r;
166
+ switch (o = 0, r && (u = [2 & u[0], r.value]), u[0]) {
167
+ case 0:
168
+ case 1:
169
+ r = u;
170
+ break;
171
+ case 4:
172
+ return a.label++, { value: u[1], done: !1 };
173
+ case 5:
174
+ a.label++, o = u[1], u = [0];
175
+ continue;
176
+ case 7:
177
+ u = a.ops.pop(), a.trys.pop();
178
+ continue;
179
+ default:
180
+ if (r = a.trys, !((r = r.length > 0 && r[r.length - 1]) || u[0] !== 6 && u[0] !== 2)) {
181
+ a = 0;
182
+ continue;
183
+ }
184
+ if (u[0] === 3 && (!r || u[1] > r[0] && u[1] < r[3])) {
185
+ a.label = u[1];
186
+ break;
187
+ }
188
+ if (u[0] === 6 && a.label < r[1]) {
189
+ a.label = r[1], r = u;
190
+ break;
191
+ }
192
+ if (r && a.label < r[2]) {
193
+ a.label = r[2], a.ops.push(u);
194
+ break;
195
+ }
196
+ r[2] && a.ops.pop(), a.trys.pop();
197
+ continue;
198
+ }
199
+ u = e.call(n, a);
200
+ } catch (p) {
201
+ u = [6, p], o = 0;
202
+ } finally {
203
+ t = r = 0;
204
+ }
205
+ if (5 & u[0]) throw u[1];
206
+ return { value: u[0] ? u[1] : void 0, done: !0 };
207
+ })([c, l]);
208
+ };
209
+ }
210
+ }, it = Le;
211
+ Object.defineProperty(sr, "__esModule", { value: !0 });
212
+ var Me = io, ln = "browser-tabs-lock-key", At = { key: function(n) {
213
+ return ne(it, void 0, void 0, function() {
214
+ return oe(this, function(e) {
215
+ throw new Error("Unsupported");
216
+ });
217
+ });
218
+ }, getItem: function(n) {
219
+ return ne(it, void 0, void 0, function() {
220
+ return oe(this, function(e) {
221
+ throw new Error("Unsupported");
222
+ });
223
+ });
224
+ }, clear: function() {
225
+ return ne(it, void 0, void 0, function() {
226
+ return oe(this, function(n) {
227
+ return [2, window.localStorage.clear()];
228
+ });
229
+ });
230
+ }, removeItem: function(n) {
231
+ return ne(it, void 0, void 0, function() {
232
+ return oe(this, function(e) {
233
+ throw new Error("Unsupported");
234
+ });
235
+ });
236
+ }, setItem: function(n, e) {
237
+ return ne(it, void 0, void 0, function() {
238
+ return oe(this, function(t) {
239
+ throw new Error("Unsupported");
240
+ });
241
+ });
242
+ }, keySync: function(n) {
243
+ return window.localStorage.key(n);
244
+ }, getItemSync: function(n) {
245
+ return window.localStorage.getItem(n);
246
+ }, clearSync: function() {
247
+ return window.localStorage.clear();
248
+ }, removeItemSync: function(n) {
249
+ return window.localStorage.removeItem(n);
250
+ }, setItemSync: function(n, e) {
251
+ return window.localStorage.setItem(n, e);
252
+ } };
253
+ function hn(n) {
254
+ return new Promise(function(e) {
255
+ return setTimeout(e, n);
256
+ });
257
+ }
258
+ function dn(n) {
259
+ for (var e = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz", t = "", o = 0; o < n; o++)
260
+ t += e[Math.floor(61 * Math.random())];
261
+ return t;
262
+ }
263
+ var ai = (function() {
264
+ function n(e) {
265
+ this.acquiredIatSet = /* @__PURE__ */ new Set(), this.storageHandler = void 0, this.id = Date.now().toString() + dn(15), this.acquireLock = this.acquireLock.bind(this), this.releaseLock = this.releaseLock.bind(this), this.releaseLock__private__ = this.releaseLock__private__.bind(this), this.waitForSomethingToChange = this.waitForSomethingToChange.bind(this), this.refreshLockWhileAcquired = this.refreshLockWhileAcquired.bind(this), this.storageHandler = e, n.waiters === void 0 && (n.waiters = []);
266
+ }
267
+ return n.prototype.acquireLock = function(e, t) {
268
+ return t === void 0 && (t = 5e3), ne(this, void 0, void 0, function() {
269
+ var o, r, i, a, s, c, l;
270
+ return oe(this, function(u) {
271
+ switch (u.label) {
272
+ case 0:
273
+ o = Date.now() + dn(4), r = Date.now() + t, i = ln + "-" + e, a = this.storageHandler === void 0 ? At : this.storageHandler, u.label = 1;
274
+ case 1:
275
+ return Date.now() < r ? [4, hn(30)] : [3, 8];
276
+ case 2:
277
+ return u.sent(), a.getItemSync(i) !== null ? [3, 5] : (s = this.id + "-" + e + "-" + o, [4, hn(Math.floor(25 * Math.random()))]);
278
+ case 3:
279
+ return u.sent(), a.setItemSync(i, JSON.stringify({ id: this.id, iat: o, timeoutKey: s, timeAcquired: Date.now(), timeRefreshed: Date.now() })), [4, hn(30)];
280
+ case 4:
281
+ return u.sent(), (c = a.getItemSync(i)) !== null && (l = JSON.parse(c)).id === this.id && l.iat === o ? (this.acquiredIatSet.add(o), this.refreshLockWhileAcquired(i, o), [2, !0]) : [3, 7];
282
+ case 5:
283
+ return n.lockCorrector(this.storageHandler === void 0 ? At : this.storageHandler), [4, this.waitForSomethingToChange(r)];
284
+ case 6:
285
+ u.sent(), u.label = 7;
286
+ case 7:
287
+ return o = Date.now() + dn(4), [3, 1];
288
+ case 8:
289
+ return [2, !1];
290
+ }
291
+ });
292
+ });
293
+ }, n.prototype.refreshLockWhileAcquired = function(e, t) {
294
+ return ne(this, void 0, void 0, function() {
295
+ var o = this;
296
+ return oe(this, function(r) {
297
+ return setTimeout(function() {
298
+ return ne(o, void 0, void 0, function() {
299
+ var i, a, s;
300
+ return oe(this, function(c) {
301
+ switch (c.label) {
302
+ case 0:
303
+ return [4, Me.default().lock(t)];
304
+ case 1:
305
+ return c.sent(), this.acquiredIatSet.has(t) ? (i = this.storageHandler === void 0 ? At : this.storageHandler, (a = i.getItemSync(e)) === null ? (Me.default().unlock(t), [2]) : ((s = JSON.parse(a)).timeRefreshed = Date.now(), i.setItemSync(e, JSON.stringify(s)), Me.default().unlock(t), this.refreshLockWhileAcquired(e, t), [2])) : (Me.default().unlock(t), [2]);
306
+ }
307
+ });
308
+ });
309
+ }, 1e3), [2];
310
+ });
311
+ });
312
+ }, n.prototype.waitForSomethingToChange = function(e) {
313
+ return ne(this, void 0, void 0, function() {
314
+ return oe(this, function(t) {
315
+ switch (t.label) {
316
+ case 0:
317
+ return [4, new Promise(function(o) {
318
+ var r = !1, i = Date.now(), a = !1;
319
+ function s() {
320
+ if (a || (window.removeEventListener("storage", s), n.removeFromWaiting(s), clearTimeout(c), a = !0), !r) {
321
+ r = !0;
322
+ var l = 50 - (Date.now() - i);
323
+ l > 0 ? setTimeout(o, l) : o(null);
324
+ }
325
+ }
326
+ window.addEventListener("storage", s), n.addToWaiting(s);
327
+ var c = setTimeout(s, Math.max(0, e - Date.now()));
328
+ })];
329
+ case 1:
330
+ return t.sent(), [2];
331
+ }
332
+ });
333
+ });
334
+ }, n.addToWaiting = function(e) {
335
+ this.removeFromWaiting(e), n.waiters !== void 0 && n.waiters.push(e);
336
+ }, n.removeFromWaiting = function(e) {
337
+ n.waiters !== void 0 && (n.waiters = n.waiters.filter(function(t) {
338
+ return t !== e;
339
+ }));
340
+ }, n.notifyWaiters = function() {
341
+ n.waiters !== void 0 && n.waiters.slice().forEach(function(e) {
342
+ return e();
343
+ });
344
+ }, n.prototype.releaseLock = function(e) {
345
+ return ne(this, void 0, void 0, function() {
346
+ return oe(this, function(t) {
347
+ switch (t.label) {
348
+ case 0:
349
+ return [4, this.releaseLock__private__(e)];
350
+ case 1:
351
+ return [2, t.sent()];
352
+ }
353
+ });
354
+ });
355
+ }, n.prototype.releaseLock__private__ = function(e) {
356
+ return ne(this, void 0, void 0, function() {
357
+ var t, o, r, i;
358
+ return oe(this, function(a) {
359
+ switch (a.label) {
360
+ case 0:
361
+ return t = this.storageHandler === void 0 ? At : this.storageHandler, o = ln + "-" + e, (r = t.getItemSync(o)) === null ? [2] : (i = JSON.parse(r)).id !== this.id ? [3, 2] : [4, Me.default().lock(i.iat)];
362
+ case 1:
363
+ a.sent(), this.acquiredIatSet.delete(i.iat), t.removeItemSync(o), Me.default().unlock(i.iat), n.notifyWaiters(), a.label = 2;
364
+ case 2:
365
+ return [2];
366
+ }
367
+ });
368
+ });
369
+ }, n.lockCorrector = function(e) {
370
+ for (var t = Date.now() - 5e3, o = e, r = [], i = 0; ; ) {
371
+ var a = o.keySync(i);
372
+ if (a === null) break;
373
+ r.push(a), i++;
374
+ }
375
+ for (var s = !1, c = 0; c < r.length; c++) {
376
+ var l = r[c];
377
+ if (l.includes(ln)) {
378
+ var u = o.getItemSync(l);
379
+ if (u !== null) {
380
+ var p = JSON.parse(u);
381
+ (p.timeRefreshed === void 0 && p.timeAcquired < t || p.timeRefreshed !== void 0 && p.timeRefreshed < t) && (o.removeItemSync(l), s = !0);
382
+ }
383
+ }
384
+ }
385
+ s && n.notifyWaiters();
386
+ }, n.waiters = void 0, n;
387
+ })(), si = sr.default = ai;
388
+ class ci {
389
+ async runWithLock(e, t, o) {
390
+ const r = new AbortController(), i = setTimeout(() => r.abort(), t);
391
+ try {
392
+ return await navigator.locks.request(e, { mode: "exclusive", signal: r.signal }, async (a) => {
393
+ if (clearTimeout(i), !a) throw new Error("Lock not available");
394
+ return await o();
395
+ });
396
+ } catch (a) {
397
+ throw clearTimeout(i), (a == null ? void 0 : a.name) === "AbortError" ? new nt() : a;
398
+ }
399
+ }
400
+ }
401
+ class ui {
402
+ constructor() {
403
+ this.activeLocks = /* @__PURE__ */ new Set(), this.lock = new si(), this.pagehideHandler = () => {
404
+ this.activeLocks.forEach((e) => this.lock.releaseLock(e)), this.activeLocks.clear();
405
+ };
406
+ }
407
+ async runWithLock(e, t, o) {
408
+ let r = !1;
409
+ for (let i = 0; i < 10 && !r; i++) r = await this.lock.acquireLock(e, t);
410
+ if (!r) throw new nt();
411
+ this.activeLocks.add(e), this.activeLocks.size === 1 && typeof window < "u" && window.addEventListener("pagehide", this.pagehideHandler);
412
+ try {
413
+ return await o();
414
+ } finally {
415
+ this.activeLocks.delete(e), await this.lock.releaseLock(e), this.activeLocks.size === 0 && typeof window < "u" && window.removeEventListener("pagehide", this.pagehideHandler);
416
+ }
417
+ }
418
+ }
419
+ function li() {
420
+ return typeof navigator < "u" && typeof ((n = navigator.locks) === null || n === void 0 ? void 0 : n.request) == "function" ? new ci() : new ui();
421
+ var n;
422
+ }
423
+ let pn = null;
424
+ const hi = new TextEncoder(), di = new TextDecoder();
425
+ function ht(n) {
426
+ return typeof n == "string" ? hi.encode(n) : di.decode(n);
427
+ }
428
+ function Po(n) {
429
+ if (typeof n.modulusLength != "number" || n.modulusLength < 2048) throw new mi(`${n.name} modulusLength must be at least 2048 bits`);
430
+ }
431
+ async function pi(n, e, t) {
432
+ if (t.usages.includes("sign") === !1) throw new TypeError('private CryptoKey instances used for signing assertions must include "sign" in their "usages"');
433
+ const o = `${dt(ht(JSON.stringify(n)))}.${dt(ht(JSON.stringify(e)))}`;
434
+ return `${o}.${dt(await crypto.subtle.sign((function(r) {
435
+ switch (r.algorithm.name) {
436
+ case "ECDSA":
437
+ return { name: r.algorithm.name, hash: "SHA-256" };
438
+ case "RSA-PSS":
439
+ return Po(r.algorithm), { name: r.algorithm.name, saltLength: 32 };
440
+ case "RSASSA-PKCS1-v1_5":
441
+ return Po(r.algorithm), { name: r.algorithm.name };
442
+ case "Ed25519":
443
+ return { name: r.algorithm.name };
444
+ }
445
+ throw new Ke();
446
+ })(t), t, ht(o)))}`;
447
+ }
448
+ let Nn;
449
+ Uint8Array.prototype.toBase64 ? Nn = (n) => (n instanceof ArrayBuffer && (n = new Uint8Array(n)), n.toBase64({ alphabet: "base64url", omitPadding: !0 })) : Nn = (e) => {
450
+ e instanceof ArrayBuffer && (e = new Uint8Array(e));
451
+ const t = [];
452
+ for (let o = 0; o < e.byteLength; o += 32768) t.push(String.fromCharCode.apply(null, e.subarray(o, o + 32768)));
453
+ return btoa(t.join("")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
454
+ };
455
+ function dt(n) {
456
+ return Nn(n);
457
+ }
458
+ class Ke extends Error {
459
+ constructor(e) {
460
+ var t;
461
+ super(e ?? "operation not supported"), this.name = this.constructor.name, (t = Error.captureStackTrace) === null || t === void 0 || t.call(Error, this, this.constructor);
462
+ }
463
+ }
464
+ class mi extends Error {
465
+ constructor(e) {
466
+ var t;
467
+ super(e), this.name = this.constructor.name, (t = Error.captureStackTrace) === null || t === void 0 || t.call(Error, this, this.constructor);
468
+ }
469
+ }
470
+ function fi(n) {
471
+ switch (n.algorithm.name) {
472
+ case "RSA-PSS":
473
+ return (function(e) {
474
+ if (e.algorithm.hash.name === "SHA-256") return "PS256";
475
+ throw new Ke("unsupported RsaHashedKeyAlgorithm hash name");
476
+ })(n);
477
+ case "RSASSA-PKCS1-v1_5":
478
+ return (function(e) {
479
+ if (e.algorithm.hash.name === "SHA-256") return "RS256";
480
+ throw new Ke("unsupported RsaHashedKeyAlgorithm hash name");
481
+ })(n);
482
+ case "ECDSA":
483
+ return (function(e) {
484
+ if (e.algorithm.namedCurve === "P-256") return "ES256";
485
+ throw new Ke("unsupported EcKeyAlgorithm namedCurve");
486
+ })(n);
487
+ case "Ed25519":
488
+ return "Ed25519";
489
+ default:
490
+ throw new Ke("unsupported CryptoKey algorithm name");
491
+ }
492
+ }
493
+ function cr(n) {
494
+ return n instanceof CryptoKey;
495
+ }
496
+ function ur(n) {
497
+ return cr(n) && n.type === "public";
498
+ }
499
+ async function yi(n, e, t, o, r, i) {
500
+ const a = n == null ? void 0 : n.privateKey, s = n == null ? void 0 : n.publicKey;
501
+ if (!cr(c = a) || c.type !== "private") throw new TypeError('"keypair.privateKey" must be a private CryptoKey');
502
+ var c;
503
+ if (!ur(s)) throw new TypeError('"keypair.publicKey" must be a public CryptoKey');
504
+ if (s.extractable !== !0) throw new TypeError('"keypair.publicKey.extractable" must be true');
505
+ if (typeof e != "string") throw new TypeError('"htu" must be a string');
506
+ if (typeof t != "string") throw new TypeError('"htm" must be a string');
507
+ if (o !== void 0 && typeof o != "string") throw new TypeError('"nonce" must be a string or undefined');
508
+ if (r !== void 0 && typeof r != "string") throw new TypeError('"accessToken" must be a string or undefined');
509
+ return pi({ alg: fi(a), typ: "dpop+jwt", jwk: await lr(s) }, Object.assign(Object.assign({}, i), { iat: Math.floor(Date.now() / 1e3), jti: crypto.randomUUID(), htm: t, nonce: o, htu: e, ath: r ? dt(await crypto.subtle.digest("SHA-256", ht(r))) : void 0 }), a);
510
+ }
511
+ async function lr(n) {
512
+ const { kty: e, e: t, n: o, x: r, y: i, crv: a } = await crypto.subtle.exportKey("jwk", n);
513
+ return { kty: e, crv: a, e: t, n: o, x: r, y: i };
514
+ }
515
+ const hr = "dpop-nonce", gi = ["authorization_code", "refresh_token", "urn:ietf:params:oauth:grant-type:token-exchange", "http://auth0.com/oauth/grant-type/mfa-oob", "http://auth0.com/oauth/grant-type/mfa-otp", "http://auth0.com/oauth/grant-type/mfa-recovery-code"];
516
+ function wi() {
517
+ return (async function(n, e) {
518
+ var t;
519
+ let o;
520
+ if (n.length === 0) throw new TypeError('"alg" must be a non-empty string');
521
+ switch (n) {
522
+ case "PS256":
523
+ o = { name: "RSA-PSS", hash: "SHA-256", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]) };
524
+ break;
525
+ case "RS256":
526
+ o = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-256", modulusLength: 2048, publicExponent: new Uint8Array([1, 0, 1]) };
527
+ break;
528
+ case "ES256":
529
+ o = { name: "ECDSA", namedCurve: "P-256" };
530
+ break;
531
+ case "Ed25519":
532
+ o = { name: "Ed25519" };
533
+ break;
534
+ default:
535
+ throw new Ke();
536
+ }
537
+ return crypto.subtle.generateKey(o, (t = e == null ? void 0 : e.extractable) !== null && t !== void 0 && t, ["sign", "verify"]);
538
+ })("ES256", { extractable: !1 });
539
+ }
540
+ function vi(n) {
541
+ return (async function(e) {
542
+ if (!ur(e)) throw new TypeError('"publicKey" must be a public CryptoKey');
543
+ if (e.extractable !== !0) throw new TypeError('"publicKey.extractable" must be true');
544
+ const t = await lr(e);
545
+ let o;
546
+ switch (t.kty) {
547
+ case "EC":
548
+ o = { crv: t.crv, kty: t.kty, x: t.x, y: t.y };
549
+ break;
550
+ case "OKP":
551
+ o = { crv: t.crv, kty: t.kty, x: t.x };
552
+ break;
553
+ case "RSA":
554
+ o = { e: t.e, kty: t.kty, n: t.n };
555
+ break;
556
+ default:
557
+ throw new Ke("unsupported JWK kty");
558
+ }
559
+ return dt(await crypto.subtle.digest({ name: "SHA-256" }, ht(JSON.stringify(o))));
560
+ })(n.publicKey);
561
+ }
562
+ function bi(n) {
563
+ let { keyPair: e, url: t, method: o, nonce: r, accessToken: i } = n;
564
+ const a = (function(s) {
565
+ const c = new URL(s);
566
+ return c.search = "", c.hash = "", c.href;
567
+ })(t);
568
+ return yi(e, a, o, r, i);
569
+ }
570
+ const dr = (n, e) => new Promise(function(t, o) {
571
+ const r = new MessageChannel();
572
+ r.port1.onmessage = function(i) {
573
+ i.data.error ? o(new Error(i.data.error)) : t(i.data), r.port1.close();
574
+ }, e.postMessage(n, [r.port2]);
575
+ }), pr = (n, e, t) => {
576
+ const o = new AbortController();
577
+ let r;
578
+ return e.signal = o.signal, Promise.race([fetch(n, e), new Promise((i, a) => {
579
+ r = setTimeout(() => {
580
+ o.abort(), a(new Error("Timeout when executing 'fetch'"));
581
+ }, t);
582
+ })]).finally(() => {
583
+ clearTimeout(r);
584
+ });
585
+ }, ki = async function(n, e, t, o, r, i) {
586
+ let a = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : Un;
587
+ return r ? (async (s, c, l, u, p, h, d, g) => dr({ type: "refresh", auth: { audience: c, scope: l }, timeout: p, fetchUrl: s, fetchOptions: u, useFormData: d, useMrrt: g }, h))(n, e, t, o, a, r, i, arguments.length > 7 ? arguments[7] : void 0) : (async (s, c, l) => {
588
+ const u = await pr(s, c, l);
589
+ return { ok: u.ok, json: await u.json(), headers: (p = u.headers, [...p].reduce((h, d) => {
590
+ let [g, f] = d;
591
+ return h[g] = f, h;
592
+ }, {})) };
593
+ var p;
594
+ })(n, o, a);
595
+ };
596
+ async function mr(n, e, t, o, r, i, a, s, c, l) {
597
+ if (c) {
598
+ const S = await c.generateProof({ url: n, method: r.method || "GET", nonce: await c.getNonce() });
599
+ r.headers = Object.assign(Object.assign({}, r.headers), { dpop: S });
600
+ }
601
+ let u, p = null;
602
+ for (let S = 0; S < 3; S++) try {
603
+ u = await ki(n, t, o, r, i, a, e, s), p = null;
604
+ break;
605
+ } catch (T) {
606
+ p = T;
607
+ }
608
+ if (p) throw p;
609
+ const h = u.json, { error: d, error_description: g } = h, f = te(h, ["error", "error_description"]), { headers: m, ok: w } = u;
610
+ let k;
611
+ if (c && (k = m[hr], k && await c.setNonce(k)), !w) {
612
+ const S = g || "HTTP error. Unable to fetch ".concat(n);
613
+ if (d === "mfa_required") throw new $e(d, S, f.mfa_token, f.mfa_requirements);
614
+ if (d === "missing_refresh_token") throw new tn(t, o);
615
+ if (d === "use_dpop_nonce") {
616
+ if (!c || !k || l) throw new nn(k);
617
+ return mr(n, e, t, o, r, i, a, s, c, !0);
618
+ }
619
+ throw new j(d || "request_error", S);
620
+ }
621
+ return f;
622
+ }
623
+ async function _i(n, e) {
624
+ var { baseUrl: t, timeout: o, audience: r, scope: i, auth0Client: a, useFormData: s, useMrrt: c, dpop: l } = n, u = te(n, ["baseUrl", "timeout", "audience", "scope", "auth0Client", "useFormData", "useMrrt", "dpop"]);
625
+ const p = u.grant_type === "urn:ietf:params:oauth:grant-type:token-exchange", h = u.grant_type === "refresh_token" && c, d = Object.assign(Object.assign(Object.assign(Object.assign({}, u), p && r && { audience: r }), p && i && { scope: i }), h && { audience: r, scope: i }), g = s ? ut(d) : JSON.stringify(d), f = (m = u.grant_type, gi.includes(m));
626
+ var m;
627
+ return await mr("".concat(t, "/oauth/token"), o, r || H, i, { method: "POST", body: g, headers: { "Content-Type": s ? "application/x-www-form-urlencoded" : "application/json", "Auth0-Client": btoa(JSON.stringify(Dn(a || Kn))) } }, e, s, c, f ? l : void 0);
628
+ }
629
+ const zt = function() {
630
+ for (var n = arguments.length, e = new Array(n), t = 0; t < n; t++) e[t] = arguments[t];
631
+ return (o = e.filter(Boolean).join(" ").trim().split(/\s+/), Array.from(new Set(o))).join(" ");
632
+ var o;
633
+ }, Rt = (n, e, t) => {
634
+ let o;
635
+ return t && (o = n[t]), o || (o = n[H]), zt(o, e);
636
+ }, De = "@@auth0spajs@@", Fe = "@@user@@";
637
+ class G {
638
+ constructor(e) {
639
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : De, o = arguments.length > 2 ? arguments[2] : void 0;
640
+ this.prefix = t, this.suffix = o, this.clientId = e.clientId, this.scope = e.scope, this.audience = e.audience;
641
+ }
642
+ toKey() {
643
+ return [this.prefix, this.clientId, this.audience, this.scope, this.suffix].filter(Boolean).join("::");
644
+ }
645
+ static fromKey(e) {
646
+ const [t, o, r, i] = e.split("::");
647
+ return new G({ clientId: o, scope: i, audience: r }, t);
648
+ }
649
+ static fromCacheEntry(e) {
650
+ const { scope: t, audience: o, client_id: r } = e;
651
+ return new G({ scope: t, audience: o, clientId: r });
652
+ }
653
+ }
654
+ class Si {
655
+ set(e, t) {
656
+ localStorage.setItem(e, JSON.stringify(t));
657
+ }
658
+ get(e) {
659
+ const t = window.localStorage.getItem(e);
660
+ if (t) try {
661
+ return JSON.parse(t);
662
+ } catch {
663
+ return;
664
+ }
665
+ }
666
+ remove(e) {
667
+ localStorage.removeItem(e);
668
+ }
669
+ allKeys() {
670
+ return Object.keys(window.localStorage).filter((e) => e.startsWith(De));
671
+ }
672
+ }
673
+ class fr {
674
+ constructor() {
675
+ this.enclosedCache = /* @__PURE__ */ (function() {
676
+ let e = {};
677
+ return { set(t, o) {
678
+ e[t] = o;
679
+ }, get(t) {
680
+ const o = e[t];
681
+ if (o) return o;
682
+ }, remove(t) {
683
+ delete e[t];
684
+ }, allKeys: () => Object.keys(e) };
685
+ })();
686
+ }
687
+ }
688
+ class Ti {
689
+ constructor(e, t, o) {
690
+ this.cache = e, this.keyManifest = t, this.nowProvider = o || ar;
691
+ }
692
+ async setIdToken(e, t, o) {
693
+ var r;
694
+ const i = this.getIdTokenCacheKey(e);
695
+ await this.cache.set(i, { id_token: t, decodedToken: o }), await ((r = this.keyManifest) === null || r === void 0 ? void 0 : r.add(i));
696
+ }
697
+ async getIdToken(e) {
698
+ const t = await this.cache.get(this.getIdTokenCacheKey(e.clientId));
699
+ if (!t && e.scope && e.audience) {
700
+ const o = await this.get(e);
701
+ return !o || !o.id_token || !o.decodedToken ? void 0 : { id_token: o.id_token, decodedToken: o.decodedToken };
702
+ }
703
+ if (t) return { id_token: t.id_token, decodedToken: t.decodedToken };
704
+ }
705
+ async get(e) {
706
+ let t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, o = arguments.length > 2 && arguments[2] !== void 0 && arguments[2], r = arguments.length > 3 ? arguments[3] : void 0;
707
+ var i;
708
+ let a = await this.cache.get(e.toKey());
709
+ if (!a) {
710
+ const l = await this.getCacheKeys();
711
+ if (!l) return;
712
+ const u = this.matchExistingCacheKey(e, l);
713
+ if (u && (a = await this.cache.get(u)), !a && o && r !== "cache-only") return this.getEntryWithRefreshToken(e, l);
714
+ }
715
+ if (!a) return;
716
+ const s = await this.nowProvider(), c = Math.floor(s / 1e3);
717
+ return a.expiresAt - t < c ? a.body.refresh_token ? this.modifiedCachedEntry(a, e) : (await this.cache.remove(e.toKey()), void await ((i = this.keyManifest) === null || i === void 0 ? void 0 : i.remove(e.toKey()))) : a.body;
718
+ }
719
+ async modifiedCachedEntry(e, t) {
720
+ return e.body = { refresh_token: e.body.refresh_token, audience: e.body.audience, scope: e.body.scope }, await this.cache.set(t.toKey(), e), { refresh_token: e.body.refresh_token, audience: e.body.audience, scope: e.body.scope };
721
+ }
722
+ async set(e) {
723
+ var t;
724
+ const o = new G({ clientId: e.client_id, scope: e.scope, audience: e.audience }), r = await this.wrapCacheEntry(e);
725
+ await this.cache.set(o.toKey(), r), await ((t = this.keyManifest) === null || t === void 0 ? void 0 : t.add(o.toKey()));
726
+ }
727
+ async remove(e, t, o) {
728
+ const r = new G({ clientId: e, scope: o, audience: t });
729
+ await this.cache.remove(r.toKey());
730
+ }
731
+ async stripRefreshToken(e) {
732
+ var t;
733
+ const o = await this.getCacheKeys();
734
+ if (o) for (const r of o) {
735
+ const i = await this.cache.get(r);
736
+ ((t = i == null ? void 0 : i.body) === null || t === void 0 ? void 0 : t.refresh_token) === e && (delete i.body.refresh_token, await this.cache.set(r, i));
737
+ }
738
+ }
739
+ async clear(e) {
740
+ var t;
741
+ const o = await this.getCacheKeys();
742
+ o && (await o.filter((r) => !e || r.includes(e)).reduce(async (r, i) => {
743
+ await r, await this.cache.remove(i);
744
+ }, Promise.resolve()), await ((t = this.keyManifest) === null || t === void 0 ? void 0 : t.clear()));
745
+ }
746
+ async wrapCacheEntry(e) {
747
+ const t = await this.nowProvider();
748
+ return { body: e, expiresAt: Math.floor(t / 1e3) + e.expires_in };
749
+ }
750
+ async getCacheKeys() {
751
+ var e;
752
+ return this.keyManifest ? (e = await this.keyManifest.get()) === null || e === void 0 ? void 0 : e.keys : this.cache.allKeys ? this.cache.allKeys() : void 0;
753
+ }
754
+ getIdTokenCacheKey(e) {
755
+ return new G({ clientId: e }, De, Fe).toKey();
756
+ }
757
+ matchExistingCacheKey(e, t) {
758
+ return t.filter((o) => {
759
+ var r;
760
+ const i = G.fromKey(o), a = new Set(i.scope && i.scope.split(" ")), s = ((r = e.scope) === null || r === void 0 ? void 0 : r.split(" ")) || [], c = i.scope && s.reduce((l, u) => l && a.has(u), !0);
761
+ return i.prefix === De && i.clientId === e.clientId && i.audience === e.audience && c;
762
+ })[0];
763
+ }
764
+ async getEntryWithRefreshToken(e, t) {
765
+ var o;
766
+ for (const r of t) {
767
+ const i = G.fromKey(r);
768
+ if (i.prefix === De && i.clientId === e.clientId) {
769
+ const a = await this.cache.get(r);
770
+ if (!((o = a == null ? void 0 : a.body) === null || o === void 0) && o.refresh_token) return this.modifiedCachedEntry(a, e);
771
+ }
772
+ }
773
+ }
774
+ async getRefreshTokensByAudience(e, t) {
775
+ var o;
776
+ const r = await this.getCacheKeys();
777
+ if (!r) return [];
778
+ const i = /* @__PURE__ */ new Set();
779
+ for (const a of r) {
780
+ const s = G.fromKey(a);
781
+ if (s.prefix === De && s.clientId === t && s.audience === e) {
782
+ const c = await this.cache.get(a);
783
+ !((o = c == null ? void 0 : c.body) === null || o === void 0) && o.refresh_token && i.add(c.body.refresh_token);
784
+ }
785
+ }
786
+ return Array.from(i);
787
+ }
788
+ async updateEntry(e, t) {
789
+ var o;
790
+ const r = await this.getCacheKeys();
791
+ if (r) for (const i of r) {
792
+ const a = await this.cache.get(i);
793
+ ((o = a == null ? void 0 : a.body) === null || o === void 0 ? void 0 : o.refresh_token) === e && (a.body.refresh_token = t, await this.cache.set(i, a));
794
+ }
795
+ }
796
+ }
797
+ class Ei {
798
+ constructor(e, t, o) {
799
+ this.storage = e, this.clientId = t, this.cookieDomain = o, this.storageKey = "".concat("a0.spajs.txs", ".").concat(this.clientId);
800
+ }
801
+ create(e) {
802
+ this.storage.save(this.storageKey, e, { daysUntilExpire: 1, cookieDomain: this.cookieDomain });
803
+ }
804
+ get() {
805
+ return this.storage.get(this.storageKey);
806
+ }
807
+ remove() {
808
+ this.storage.remove(this.storageKey, { cookieDomain: this.cookieDomain });
809
+ }
810
+ }
811
+ const at = (n) => typeof n == "number", Pi = ["iss", "aud", "exp", "nbf", "iat", "jti", "azp", "nonce", "auth_time", "at_hash", "c_hash", "acr", "amr", "sub_jwk", "cnf", "sip_from_tag", "sip_date", "sip_callid", "sip_cseq_num", "sip_via_branch", "orig", "dest", "mky", "events", "toe", "txn", "rph", "sid", "vot", "vtm"], Ai = (n) => {
812
+ if (!n.id_token) throw new Error("ID token is required but missing");
813
+ const e = ((i) => {
814
+ const a = i.split("."), [s, c, l] = a;
815
+ if (a.length !== 3 || !s || !c || !l) throw new Error("ID token could not be decoded");
816
+ const u = JSON.parse(To(c)), p = { __raw: i }, h = {};
817
+ return Object.keys(u).forEach((d) => {
818
+ p[d] = u[d], Pi.includes(d) || (h[d] = u[d]);
819
+ }), { encoded: { header: s, payload: c, signature: l }, header: JSON.parse(To(s)), claims: p, user: h };
820
+ })(n.id_token);
821
+ if (!e.claims.iss) throw new Error("Issuer (iss) claim must be a string present in the ID token");
822
+ if (e.claims.iss !== n.iss) throw new Error('Issuer (iss) claim mismatch in the ID token; expected "'.concat(n.iss, '", found "').concat(e.claims.iss, '"'));
823
+ if (!e.user.sub) throw new Error("Subject (sub) claim must be a string present in the ID token");
824
+ if (e.header.alg !== "RS256") throw new Error('Signature algorithm of "'.concat(e.header.alg, '" is not supported. Expected the ID token to be signed with "RS256".'));
825
+ if (!e.claims.aud || typeof e.claims.aud != "string" && !Array.isArray(e.claims.aud)) throw new Error("Audience (aud) claim must be a string or array of strings present in the ID token");
826
+ if (Array.isArray(e.claims.aud)) {
827
+ if (!e.claims.aud.includes(n.aud)) throw new Error('Audience (aud) claim mismatch in the ID token; expected "'.concat(n.aud, '" but was not one of "').concat(e.claims.aud.join(", "), '"'));
828
+ if (e.claims.aud.length > 1) {
829
+ if (!e.claims.azp) throw new Error("Authorized Party (azp) claim must be a string present in the ID token when Audience (aud) claim has multiple values");
830
+ if (e.claims.azp !== n.aud) throw new Error('Authorized Party (azp) claim mismatch in the ID token; expected "'.concat(n.aud, '", found "').concat(e.claims.azp, '"'));
831
+ }
832
+ } else if (e.claims.aud !== n.aud) throw new Error('Audience (aud) claim mismatch in the ID token; expected "'.concat(n.aud, '" but found "').concat(e.claims.aud, '"'));
833
+ if (n.nonce) {
834
+ if (!e.claims.nonce) throw new Error("Nonce (nonce) claim must be a string present in the ID token");
835
+ if (e.claims.nonce !== n.nonce) throw new Error('Nonce (nonce) claim mismatch in the ID token; expected "'.concat(n.nonce, '", found "').concat(e.claims.nonce, '"'));
836
+ }
837
+ if (n.max_age && !at(e.claims.auth_time)) throw new Error("Authentication Time (auth_time) claim must be a number present in the ID token when Max Age (max_age) is specified");
838
+ if (e.claims.exp == null || !at(e.claims.exp)) throw new Error("Expiration Time (exp) claim must be a number present in the ID token");
839
+ if (!at(e.claims.iat)) throw new Error("Issued At (iat) claim must be a number present in the ID token");
840
+ const t = n.leeway || 60, o = new Date(n.now || Date.now()), r = /* @__PURE__ */ new Date(0);
841
+ if (r.setUTCSeconds(e.claims.exp + t), o > r) throw new Error("Expiration Time (exp) claim error in the ID token; current time (".concat(o, ") is after expiration time (").concat(r, ")"));
842
+ if (e.claims.nbf != null && at(e.claims.nbf)) {
843
+ const i = /* @__PURE__ */ new Date(0);
844
+ if (i.setUTCSeconds(e.claims.nbf - t), o < i) throw new Error("Not Before time (nbf) claim in the ID token indicates that this token can't be used just yet. Current time (".concat(o, ") is before ").concat(i));
845
+ }
846
+ if (e.claims.auth_time != null && at(e.claims.auth_time)) {
847
+ const i = /* @__PURE__ */ new Date(0);
848
+ if (i.setUTCSeconds(parseInt(e.claims.auth_time) + n.max_age + t), o > i) throw new Error("Authentication Time (auth_time) claim in the ID token indicates that too much time has passed since the last end-user authentication. Current time (".concat(o, ") is after last auth at ").concat(i));
849
+ }
850
+ if (n.organization) {
851
+ const i = n.organization.trim();
852
+ if (i.startsWith("org_")) {
853
+ const a = i;
854
+ if (!e.claims.org_id) throw new Error("Organization ID (org_id) claim must be a string present in the ID token");
855
+ if (a !== e.claims.org_id) throw new Error('Organization ID (org_id) claim mismatch in the ID token; expected "'.concat(a, '", found "').concat(e.claims.org_id, '"'));
856
+ } else {
857
+ const a = i.toLowerCase();
858
+ if (!e.claims.org_name) throw new Error("Organization Name (org_name) claim must be a string present in the ID token");
859
+ if (a !== e.claims.org_name) throw new Error('Organization Name (org_name) claim mismatch in the ID token; expected "'.concat(a, '", found "').concat(e.claims.org_name, '"'));
860
+ }
861
+ }
862
+ return e;
863
+ };
864
+ var yt = Le && Le.__assign || function() {
865
+ return yt = Object.assign || function(n) {
866
+ for (var e, t = 1, o = arguments.length; t < o; t++) for (var r in e = arguments[t]) Object.prototype.hasOwnProperty.call(e, r) && (n[r] = e[r]);
867
+ return n;
868
+ }, yt.apply(this, arguments);
869
+ };
870
+ function st(n, e) {
871
+ if (!e) return "";
872
+ var t = "; " + n;
873
+ return e === !0 ? t : t + "=" + e;
874
+ }
875
+ function Ri(n, e, t) {
876
+ return encodeURIComponent(n).replace(/%(23|24|26|2B|5E|60|7C)/g, decodeURIComponent).replace(/\(/g, "%28").replace(/\)/g, "%29") + "=" + encodeURIComponent(e).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g, decodeURIComponent) + (function(o) {
877
+ if (typeof o.expires == "number") {
878
+ var r = /* @__PURE__ */ new Date();
879
+ r.setMilliseconds(r.getMilliseconds() + 864e5 * o.expires), o.expires = r;
880
+ }
881
+ return st("Expires", o.expires ? o.expires.toUTCString() : "") + st("Domain", o.domain) + st("Path", o.path) + st("Secure", o.secure) + st("SameSite", o.sameSite);
882
+ })(t);
883
+ }
884
+ function Ii() {
885
+ return (function(n) {
886
+ for (var e = {}, t = n ? n.split("; ") : [], o = /(%[\dA-F]{2})+/gi, r = 0; r < t.length; r++) {
887
+ var i = t[r].split("="), a = i.slice(1).join("=");
888
+ a.charAt(0) === '"' && (a = a.slice(1, -1));
889
+ try {
890
+ e[i[0].replace(o, decodeURIComponent)] = a.replace(o, decodeURIComponent);
891
+ } catch {
892
+ }
893
+ }
894
+ return e;
895
+ })(document.cookie);
896
+ }
897
+ var xi = function(n) {
898
+ return Ii()[n];
899
+ };
900
+ function yr(n, e, t) {
901
+ document.cookie = Ri(n, e, yt({ path: "/" }, t));
902
+ }
903
+ var gr = yr, wr = function(n, e) {
904
+ yr(n, "", yt(yt({}, e), { expires: -1 }));
905
+ };
906
+ const Xe = { get(n) {
907
+ const e = xi(n);
908
+ if (e !== void 0) return JSON.parse(e);
909
+ }, save(n, e, t) {
910
+ let o = {};
911
+ window.location.protocol === "https:" && (o = { secure: !0, sameSite: "none" }), t != null && t.daysUntilExpire && (o.expires = t.daysUntilExpire), t != null && t.cookieDomain && (o.domain = t.cookieDomain), gr(n, JSON.stringify(e), o);
912
+ }, remove(n, e) {
913
+ let t = {};
914
+ e != null && e.cookieDomain && (t.domain = e.cookieDomain), wr(n, t);
915
+ } }, mn = "_legacy_", Oi = { get(n) {
916
+ return Xe.get(n) || Xe.get("".concat(mn).concat(n));
917
+ }, save(n, e, t) {
918
+ let o = {};
919
+ window.location.protocol === "https:" && (o = { secure: !0 }), t != null && t.daysUntilExpire && (o.expires = t.daysUntilExpire), t != null && t.cookieDomain && (o.domain = t.cookieDomain), gr("".concat(mn).concat(n), JSON.stringify(e), o), Xe.save(n, e, t);
920
+ }, remove(n, e) {
921
+ let t = {};
922
+ e != null && e.cookieDomain && (t.domain = e.cookieDomain), wr(n, t), Xe.remove(n, e), Xe.remove("".concat(mn).concat(n), e);
923
+ } }, Ci = { get(n) {
924
+ if (typeof sessionStorage > "u") return;
925
+ const e = sessionStorage.getItem(n);
926
+ return e != null ? JSON.parse(e) : void 0;
927
+ }, save(n, e) {
928
+ sessionStorage.setItem(n, JSON.stringify(e));
929
+ }, remove(n) {
930
+ sessionStorage.removeItem(n);
931
+ } };
932
+ var Ue;
933
+ (function(n) {
934
+ n.Code = "code", n.ConnectCode = "connect_code";
935
+ })(Ue || (Ue = {}));
936
+ function ji(n, e, t) {
937
+ var o = e === void 0 ? null : e, r = (function(c, l) {
938
+ var u = atob(c);
939
+ if (l) {
940
+ for (var p = new Uint8Array(u.length), h = 0, d = u.length; h < d; ++h) p[h] = u.charCodeAt(h);
941
+ return String.fromCharCode.apply(null, new Uint16Array(p.buffer));
942
+ }
943
+ return u;
944
+ })(n, t !== void 0 && t), i = r.indexOf(`
945
+ `, 10) + 1, a = r.substring(i) + (o ? "//# sourceMappingURL=" + o : ""), s = new Blob([a], { type: "application/javascript" });
946
+ return URL.createObjectURL(s);
947
+ }
948
+ var Ao, Ro, Io, fn, Wi = (Ao = "Lyogcm9sbHVwLXBsdWdpbi13ZWItd29ya2VyLWxvYWRlciAqLwohZnVuY3Rpb24oKXsidXNlIHN0cmljdCI7Y2xhc3MgZSBleHRlbmRzIEVycm9ye2NvbnN0cnVjdG9yKHQscil7c3VwZXIociksdGhpcy5lcnJvcj10LHRoaXMuZXJyb3JfZGVzY3JpcHRpb249cixPYmplY3Quc2V0UHJvdG90eXBlT2YodGhpcyxlLnByb3RvdHlwZSl9c3RhdGljIGZyb21QYXlsb2FkKHQpe2xldHtlcnJvcjpyLGVycm9yX2Rlc2NyaXB0aW9uOm99PXQ7cmV0dXJuIG5ldyBlKHIsbyl9fWNsYXNzIHQgZXh0ZW5kcyBle2NvbnN0cnVjdG9yKGUsbyl7c3VwZXIoIm1pc3NpbmdfcmVmcmVzaF90b2tlbiIsIk1pc3NpbmcgUmVmcmVzaCBUb2tlbiAoYXVkaWVuY2U6ICciLmNvbmNhdChyKGUsWyJkZWZhdWx0Il0pLCInLCBzY29wZTogJyIpLmNvbmNhdChyKG8pLCInKSIpKSx0aGlzLmF1ZGllbmNlPWUsdGhpcy5zY29wZT1vLE9iamVjdC5zZXRQcm90b3R5cGVPZih0aGlzLHQucHJvdG90eXBlKX19ZnVuY3Rpb24gcihlKXtyZXR1cm4gZSYmIShhcmd1bWVudHMubGVuZ3RoPjEmJnZvaWQgMCE9PWFyZ3VtZW50c1sxXT9hcmd1bWVudHNbMV06W10pLmluY2x1ZGVzKGUpP2U6IiJ9ImZ1bmN0aW9uIj09dHlwZW9mIFN1cHByZXNzZWRFcnJvciYmU3VwcHJlc3NlZEVycm9yO2NvbnN0IG89ZT0+e3ZhcntjbGllbnRJZDp0fT1lLHI9ZnVuY3Rpb24oZSx0KXt2YXIgcj17fTtmb3IodmFyIG8gaW4gZSlPYmplY3QucHJvdG90eXBlLmhhc093blByb3BlcnR5LmNhbGwoZSxvKSYmdC5pbmRleE9mKG8pPDAmJihyW29dPWVbb10pO2lmKG51bGwhPWUmJiJmdW5jdGlvbiI9PXR5cGVvZiBPYmplY3QuZ2V0T3duUHJvcGVydHlTeW1ib2xzKXt2YXIgcz0wO2ZvcihvPU9iamVjdC5nZXRPd25Qcm9wZXJ0eVN5bWJvbHMoZSk7czxvLmxlbmd0aDtzKyspdC5pbmRleE9mKG9bc10pPDAmJk9iamVjdC5wcm90b3R5cGUucHJvcGVydHlJc0VudW1lcmFibGUuY2FsbChlLG9bc10pJiYocltvW3NdXT1lW29bc11dKX1yZXR1cm4gcn0oZSxbImNsaWVudElkIl0pO3JldHVybiBuZXcgVVJMU2VhcmNoUGFyYW1zKChlPT5PYmplY3Qua2V5cyhlKS5maWx0ZXIodD0+dm9pZCAwIT09ZVt0XSkucmVkdWNlKCh0LHIpPT5PYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30sdCkse1tyXTplW3JdfSkse30pKShPYmplY3QuYXNzaWduKHtjbGllbnRfaWQ6dH0scikpKS50b1N0cmluZygpfTtsZXQgcz17fSxuPW51bGw7Y29uc3QgaT0oZSx0KT0+IiIuY29uY2F0KGUsInwiKS5jb25jYXQodCksYT0oZSx0KT0+dC5zdGFydHNXaXRoKCIiLmNvbmNhdChlLCJ8IikpLGM9ZT0+e09iamVjdC5lbnRyaWVzKHMpLmZvckVhY2godD0+e2xldFtyLG9dPXQ7bz09PWUmJmRlbGV0ZSBzW3JdfSl9LGw9ZT0+e2NvbnN0IHQ9bmV3IFVSTFNlYXJjaFBhcmFtcyhlKSxyPXt9O3JldHVybiB0LmZvckVhY2goKGUsdCk9PntyW3RdPWV9KSxyfSxmPWFzeW5jIGU9PntsZXQgcixuLHtkYXRhOnt0aW1lb3V0OmMsYXV0aDpmLGZldGNoVXJsOnUsZmV0Y2hPcHRpb25zOmgsdXNlRm9ybURhdGE6ZCx1c2VNcnJ0OnB9LHBvcnRzOltnXX09ZSx5PXt9O2NvbnN0e2F1ZGllbmNlOmIsc2NvcGU6T309Znx8e307dHJ5e2NvbnN0IGU9ZD9sKGguYm9keSk6SlNPTi5wYXJzZShoLmJvZHkpO2lmKCFlLnJlZnJlc2hfdG9rZW4mJiJyZWZyZXNoX3Rva2VuIj09PWUuZ3JhbnRfdHlwZSl7aWYobj0oKGUsdCk9PnNbaShlLHQpXSkoYixPKSwhbiYmcCl7Y29uc3QgZT1zLmxhdGVzdF9yZWZyZXNoX3Rva2VuLHQ9KChlLHQpPT4hIU9iamVjdC5rZXlzKHMpLmZpbmQocj0+e2lmKCJsYXRlc3RfcmVmcmVzaF90b2tlbiIhPT1yKXtjb25zdCBvPWEodCxyKSxzPXIuc3BsaXQoInwiKVsxXS5zcGxpdCgiICIpLG49ZS5zcGxpdCgiICIpLmV2ZXJ5KGU9PnMuaW5jbHVkZXMoZSkpO3JldHVybiBvJiZufX0pKShPLGIpO2UmJiF0JiYobj1lKX1pZighbil0aHJvdyBuZXcgdChiLE8pO2guYm9keT1kP28oT2JqZWN0LmFzc2lnbihPYmplY3QuYXNzaWduKHt9LGUpLHtyZWZyZXNoX3Rva2VuOm59KSk6SlNPTi5zdHJpbmdpZnkoT2JqZWN0LmFzc2lnbihPYmplY3QuYXNzaWduKHt9LGUpLHtyZWZyZXNoX3Rva2VuOm59KSl9bGV0IGYsdzsiZnVuY3Rpb24iPT10eXBlb2YgQWJvcnRDb250cm9sbGVyJiYoZj1uZXcgQWJvcnRDb250cm9sbGVyLGguc2lnbmFsPWYuc2lnbmFsKTt0cnl7dz1hd2FpdCBQcm9taXNlLnJhY2UoWyhtPWMsbmV3IFByb21pc2UoZT0+c2V0VGltZW91dChlLG0pKSksZmV0Y2godSxPYmplY3QuYXNzaWduKHt9LGgpKV0pfWNhdGNoKGUpe3JldHVybiB2b2lkIGcucG9zdE1lc3NhZ2Uoe2Vycm9yOmUubWVzc2FnZX0pfWlmKCF3KXJldHVybiBmJiZmLmFib3J0KCksdm9pZCBnLnBvc3RNZXNzYWdlKHtlcnJvcjoiVGltZW91dCB3aGVuIGV4ZWN1dGluZyAnZmV0Y2gnIn0pO189dy5oZWFkZXJzLHk9Wy4uLl9dLnJlZHVjZSgoZSx0KT0+e2xldFtyLG9dPXQ7cmV0dXJuIGVbcl09byxlfSx7fSkscj1hd2FpdCB3Lmpzb24oKSxyLnJlZnJlc2hfdG9rZW4/KHAmJihzLmxhdGVzdF9yZWZyZXNoX3Rva2VuPXIucmVmcmVzaF90b2tlbixrPW4saj1yLnJlZnJlc2hfdG9rZW4sT2JqZWN0LmVudHJpZXMocykuZm9yRWFjaChlPT57bGV0W3Qscl09ZTtyPT09ayYmKHNbdF09ail9KSksKChlLHQscik9PntzW2kodCxyKV09ZX0pKHIucmVmcmVzaF90b2tlbixiLE8pLGRlbGV0ZSByLnJlZnJlc2hfdG9rZW4pOigoZSx0KT0+e2RlbGV0ZSBzW2koZSx0KV19KShiLE8pLGcucG9zdE1lc3NhZ2Uoe29rOncub2ssanNvbjpyLGhlYWRlcnM6eX0pfWNhdGNoKGUpe2cucG9zdE1lc3NhZ2Uoe29rOiExLGpzb246e2Vycm9yOmUuZXJyb3IsZXJyb3JfZGVzY3JpcHRpb246ZS5tZXNzYWdlfSxoZWFkZXJzOnl9KX12YXIgayxqLF8sbX0sdT1hc3luYyBlPT57bGV0e2RhdGE6e3RpbWVvdXQ6dCxhdXRoOnIsZmV0Y2hVcmw6bixmZXRjaE9wdGlvbnM6aSx1c2VGb3JtRGF0YTpmfSxwb3J0czpbdV19PWU7Y29uc3R7YXVkaWVuY2U6aH09cnx8e307dHJ5e2NvbnN0IGU9KGU9Pntjb25zdCB0PW5ldyBTZXQ7cmV0dXJuIE9iamVjdC5lbnRyaWVzKHMpLmZvckVhY2gocj0+e2xldFtvLHNdPXI7YShlLG8pJiZ0LmFkZChzKX0pLEFycmF5LmZyb20odCl9KShoKTtpZigwPT09ZS5sZW5ndGgpcmV0dXJuIHZvaWQgdS5wb3N0TWVzc2FnZSh7b2s6ITB9KTtjb25zdCByPWY/bChpLmJvZHkpOkpTT04ucGFyc2UoaS5ib2R5KTtmb3IoY29uc3QgcyBvZiBlKXtjb25zdCBlPWY/byhPYmplY3QuYXNzaWduKE9iamVjdC5hc3NpZ24oe30scikse3Rva2VuOnN9KSk6SlNPTi5zdHJpbmdpZnkoT2JqZWN0LmFzc2lnbihPYmplY3QuYXNzaWduKHt9LHIpLHt0b2tlbjpzfSkpO2xldCBhLGwsaCxkOyJmdW5jdGlvbiI9PXR5cGVvZiBBYm9ydENvbnRyb2xsZXImJihhPW5ldyBBYm9ydENvbnRyb2xsZXIsbD1hLnNpZ25hbCk7dHJ5e2Q9YXdhaXQgUHJvbWlzZS5yYWNlKFtuZXcgUHJvbWlzZShlPT57aD1zZXRUaW1lb3V0KGUsdCl9KSxmZXRjaChuLE9iamVjdC5hc3NpZ24oT2JqZWN0LmFzc2lnbih7fSxpKSx7Ym9keTplLHNpZ25hbDpsfSkpXSkuZmluYWxseSgoKT0+Y2xlYXJUaW1lb3V0KGgpKX1jYXRjaChlKXtyZXR1cm4gdm9pZCB1LnBvc3RNZXNzYWdlKHtlcnJvcjplLm1lc3NhZ2V9KX1pZighZClyZXR1cm4gYSYmYS5hYm9ydCgpLHZvaWQgdS5wb3N0TWVzc2FnZSh7ZXJyb3I6IlRpbWVvdXQgd2hlbiBleGVjdXRpbmcgJ2ZldGNoJyJ9KTtpZighZC5vayl7bGV0IGU7dHJ5e2NvbnN0e2Vycm9yX2Rlc2NyaXB0aW9uOnR9PUpTT04ucGFyc2UoYXdhaXQgZC50ZXh0KCkpO2U9dH1jYXRjaChlKXt9cmV0dXJuIHZvaWQgdS5wb3N0TWVzc2FnZSh7ZXJyb3I6ZXx8IkhUVFAgZXJyb3IgIi5jb25jYXQoZC5zdGF0dXMpfSl9YyhzKX11LnBvc3RNZXNzYWdlKHtvazohMH0pfWNhdGNoKGUpe3UucG9zdE1lc3NhZ2Uoe2Vycm9yOmUubWVzc2FnZXx8IlVua25vd24gZXJyb3IgZHVyaW5nIHRva2VuIHJldm9jYXRpb24ifSl9fSxoPShlLHQpPT57aWYoIW4pcmV0dXJuITE7dHJ5e2NvbnN0IHI9bmV3IFVSTChuKS5vcmlnaW4sbz1uZXcgVVJMKGUuZmV0Y2hVcmwpO3JldHVybiBvLm9yaWdpbj09PXImJm8ucGF0aG5hbWU9PT10fWNhdGNoKGUpe3JldHVybiExfX07YWRkRXZlbnRMaXN0ZW5lcigibWVzc2FnZSIsZT0+e2NvbnN0e2RhdGE6dCxwb3J0czpyfT1lLFtvXT1yO2lmKCJ0eXBlImluIHQmJiJpbml0Ij09PXQudHlwZSl7aWYobnVsbD09PW4pdHJ5e25ldyBVUkwodC5hbGxvd2VkQmFzZVVybCksbj10LmFsbG93ZWRCYXNlVXJsfWNhdGNoKGUpe3JldHVybn19ZWxzZXtpZigidHlwZSJpbiB0JiYicmV2b2tlIj09PXQudHlwZSlyZXR1cm4gaCh0LCIvb2F1dGgvcmV2b2tlIik/dm9pZCB1KGUpOnZvaWQobnVsbD09b3x8by5wb3N0TWVzc2FnZSh7b2s6ITEsanNvbjp7ZXJyb3I6ImludmFsaWRfZmV0Y2hfdXJsIixlcnJvcl9kZXNjcmlwdGlvbjoiVW5hdXRob3JpemVkIGZldGNoIFVSTCJ9LGhlYWRlcnM6e319KSk7ImZldGNoVXJsImluIHQmJmgodCwiL29hdXRoL3Rva2VuIik/ZihlKTpudWxsPT1vfHxvLnBvc3RNZXNzYWdlKHtvazohMSxqc29uOntlcnJvcjoiaW52YWxpZF9mZXRjaF91cmwiLGVycm9yX2Rlc2NyaXB0aW9uOiJVbmF1dGhvcml6ZWQgZmV0Y2ggVVJMIn0saGVhZGVyczp7fX0pfX0pfSgpOwoK", Ro = null, Io = !1, function(n) {
949
+ return fn = fn || ji(Ao, Ro, Io), new Worker(fn, n);
950
+ });
951
+ const yn = {};
952
+ class Ui {
953
+ constructor(e, t) {
954
+ this.cache = e, this.clientId = t, this.manifestKey = this.createManifestKeyFrom(this.clientId);
955
+ }
956
+ async add(e) {
957
+ var t;
958
+ const o = new Set(((t = await this.cache.get(this.manifestKey)) === null || t === void 0 ? void 0 : t.keys) || []);
959
+ o.add(e), await this.cache.set(this.manifestKey, { keys: [...o] });
960
+ }
961
+ async remove(e) {
962
+ const t = await this.cache.get(this.manifestKey);
963
+ if (t) {
964
+ const o = new Set(t.keys);
965
+ return o.delete(e), o.size > 0 ? await this.cache.set(this.manifestKey, { keys: [...o] }) : await this.cache.remove(this.manifestKey);
966
+ }
967
+ }
968
+ get() {
969
+ return this.cache.get(this.manifestKey);
970
+ }
971
+ clear() {
972
+ return this.cache.remove(this.manifestKey);
973
+ }
974
+ createManifestKeyFrom(e) {
975
+ return "".concat(De, "::").concat(e);
976
+ }
977
+ }
978
+ const xo = "auth0.is.authenticated", Ki = { memory: () => new fr().enclosedCache, localstorage: () => new Si() }, Oo = (n) => Ki[n], Co = (n) => {
979
+ const { openUrl: e, onRedirect: t } = n, o = te(n, ["openUrl", "onRedirect"]);
980
+ return Object.assign(Object.assign({}, o), { openUrl: e === !1 || e ? e : t });
981
+ }, jo = (n, e) => {
982
+ const t = (e == null ? void 0 : e.split(" ")) || [];
983
+ return ((n == null ? void 0 : n.split(" ")) || []).every((o) => t.includes(o));
984
+ }, Re = { NONCE: "nonce", KEYPAIR: "keypair" };
985
+ class Di {
986
+ constructor(e) {
987
+ this.clientId = e;
988
+ }
989
+ getVersion() {
990
+ return 1;
991
+ }
992
+ createDbHandle() {
993
+ const e = window.indexedDB.open("auth0-spa-js", this.getVersion());
994
+ return new Promise((t, o) => {
995
+ e.onupgradeneeded = () => Object.values(Re).forEach((r) => e.result.createObjectStore(r)), e.onerror = () => o(e.error), e.onsuccess = () => t(e.result);
996
+ });
997
+ }
998
+ async getDbHandle() {
999
+ return this.dbHandle || (this.dbHandle = await this.createDbHandle()), this.dbHandle;
1000
+ }
1001
+ async executeDbRequest(e, t, o) {
1002
+ const r = o((await this.getDbHandle()).transaction(e, t).objectStore(e));
1003
+ return new Promise((i, a) => {
1004
+ r.onsuccess = () => i(r.result), r.onerror = () => a(r.error);
1005
+ });
1006
+ }
1007
+ buildKey(e) {
1008
+ const t = e ? "_".concat(e) : "auth0";
1009
+ return "".concat(this.clientId, "::").concat(t);
1010
+ }
1011
+ setNonce(e, t) {
1012
+ return this.save(Re.NONCE, this.buildKey(t), e);
1013
+ }
1014
+ setKeyPair(e) {
1015
+ return this.save(Re.KEYPAIR, this.buildKey(), e);
1016
+ }
1017
+ async save(e, t, o) {
1018
+ await this.executeDbRequest(e, "readwrite", (r) => r.put(o, t));
1019
+ }
1020
+ findNonce(e) {
1021
+ return this.find(Re.NONCE, this.buildKey(e));
1022
+ }
1023
+ findKeyPair() {
1024
+ return this.find(Re.KEYPAIR, this.buildKey());
1025
+ }
1026
+ find(e, t) {
1027
+ return this.executeDbRequest(e, "readonly", (o) => o.get(t));
1028
+ }
1029
+ async deleteBy(e, t) {
1030
+ const o = await this.executeDbRequest(e, "readonly", (r) => r.getAllKeys());
1031
+ o == null || o.filter(t).map((r) => this.executeDbRequest(e, "readwrite", (i) => i.delete(r)));
1032
+ }
1033
+ deleteByClientId(e, t) {
1034
+ return this.deleteBy(e, (o) => typeof o == "string" && o.startsWith("".concat(t, "::")));
1035
+ }
1036
+ clearNonces() {
1037
+ return this.deleteByClientId(Re.NONCE, this.clientId);
1038
+ }
1039
+ clearKeyPairs() {
1040
+ return this.deleteByClientId(Re.KEYPAIR, this.clientId);
1041
+ }
1042
+ }
1043
+ class Ni {
1044
+ constructor(e) {
1045
+ this.storage = new Di(e);
1046
+ }
1047
+ getNonce(e) {
1048
+ return this.storage.findNonce(e);
1049
+ }
1050
+ setNonce(e, t) {
1051
+ return this.storage.setNonce(e, t);
1052
+ }
1053
+ async getOrGenerateKeyPair() {
1054
+ let e = await this.storage.findKeyPair();
1055
+ return e || (e = await wi(), await this.storage.setKeyPair(e)), e;
1056
+ }
1057
+ async generateProof(e) {
1058
+ const t = await this.getOrGenerateKeyPair();
1059
+ return bi(Object.assign({ keyPair: t }, e));
1060
+ }
1061
+ async calculateThumbprint() {
1062
+ return vi(await this.getOrGenerateKeyPair());
1063
+ }
1064
+ async clear() {
1065
+ await Promise.all([this.storage.clearNonces(), this.storage.clearKeyPairs()]);
1066
+ }
1067
+ }
1068
+ var Ge;
1069
+ (function(n) {
1070
+ n.Bearer = "Bearer", n.DPoP = "DPoP";
1071
+ })(Ge || (Ge = {}));
1072
+ class Li {
1073
+ constructor(e, t) {
1074
+ this.hooks = t, this.config = Object.assign(Object.assign({}, e), { fetch: e.fetch || (typeof window > "u" ? fetch : window.fetch.bind(window)) });
1075
+ }
1076
+ isAbsoluteUrl(e) {
1077
+ return /^(https?:)?\/\//i.test(e);
1078
+ }
1079
+ buildUrl(e, t) {
1080
+ if (t) {
1081
+ if (this.isAbsoluteUrl(t)) return t;
1082
+ if (e) return "".concat(e.replace(/\/?\/$/, ""), "/").concat(t.replace(/^\/+/, ""));
1083
+ }
1084
+ throw new TypeError("`url` must be absolute or `baseUrl` non-empty.");
1085
+ }
1086
+ getAccessToken(e) {
1087
+ return this.config.getAccessToken ? this.config.getAccessToken(e) : this.hooks.getAccessToken(e);
1088
+ }
1089
+ extractUrl(e) {
1090
+ return typeof e == "string" ? e : e instanceof URL ? e.href : e.url;
1091
+ }
1092
+ buildBaseRequest(e, t) {
1093
+ if (!this.config.baseUrl) return new Request(e, t);
1094
+ const o = this.buildUrl(this.config.baseUrl, this.extractUrl(e)), r = e instanceof Request ? new Request(o, e) : o;
1095
+ return new Request(r, t);
1096
+ }
1097
+ setAuthorizationHeader(e, t) {
1098
+ let o = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : Ge.Bearer;
1099
+ e.headers.set("authorization", "".concat(o, " ").concat(t));
1100
+ }
1101
+ async setDpopProofHeader(e, t) {
1102
+ if (!this.config.dpopNonceId) return;
1103
+ const o = await this.hooks.getDpopNonce(), r = await this.hooks.generateDpopProof({ accessToken: t, method: e.method, nonce: o, url: e.url });
1104
+ e.headers.set("dpop", r);
1105
+ }
1106
+ async prepareRequest(e, t) {
1107
+ const o = await this.getAccessToken(t);
1108
+ let r, i;
1109
+ typeof o == "string" ? (r = this.config.dpopNonceId ? Ge.DPoP : Ge.Bearer, i = o) : (r = o.token_type, i = o.access_token), this.setAuthorizationHeader(e, i, r), r === Ge.DPoP && await this.setDpopProofHeader(e, i);
1110
+ }
1111
+ getHeader(e, t) {
1112
+ return Array.isArray(e) ? new Headers(e).get(t) || "" : typeof e.get == "function" ? e.get(t) || "" : e[t] || "";
1113
+ }
1114
+ hasUseDpopNonceError(e) {
1115
+ if (e.status !== 401) return !1;
1116
+ const t = this.getHeader(e.headers, "www-authenticate");
1117
+ return t.includes("invalid_dpop_nonce") || t.includes("use_dpop_nonce");
1118
+ }
1119
+ async handleResponse(e, t) {
1120
+ const o = this.getHeader(e.headers, hr);
1121
+ if (o && await this.hooks.setDpopNonce(o), !this.hasUseDpopNonceError(e)) return e;
1122
+ if (!o || !t.onUseDpopNonceError) throw new nn(o);
1123
+ return t.onUseDpopNonceError();
1124
+ }
1125
+ async internalFetchWithAuth(e, t, o, r) {
1126
+ const i = this.buildBaseRequest(e, t);
1127
+ await this.prepareRequest(i, r);
1128
+ const a = await this.config.fetch(i);
1129
+ return this.handleResponse(a, o);
1130
+ }
1131
+ fetchWithAuth(e, t, o) {
1132
+ const r = { onUseDpopNonceError: () => this.internalFetchWithAuth(e, t, Object.assign(Object.assign({}, r), { onUseDpopNonceError: void 0 }), o) };
1133
+ return this.internalFetchWithAuth(e, t, r, o);
1134
+ }
1135
+ }
1136
+ class zi {
1137
+ constructor(e, t) {
1138
+ this.myAccountFetcher = e, this.apiBase = t;
1139
+ }
1140
+ async connectAccount(e) {
1141
+ const t = await this.myAccountFetcher.fetchWithAuth("".concat(this.apiBase, "v1/connected-accounts/connect"), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(e) });
1142
+ return this._handleResponse(t);
1143
+ }
1144
+ async completeAccount(e) {
1145
+ const t = await this.myAccountFetcher.fetchWithAuth("".concat(this.apiBase, "v1/connected-accounts/complete"), { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(e) });
1146
+ return this._handleResponse(t);
1147
+ }
1148
+ async _handleResponse(e) {
1149
+ let t;
1150
+ try {
1151
+ t = await e.text(), t = JSON.parse(t);
1152
+ } catch (o) {
1153
+ throw new Ft({ type: "invalid_json", status: e.status, title: "Invalid JSON response", detail: t || String(o) });
1154
+ }
1155
+ if (e.ok) return t;
1156
+ throw new Ft(t);
1157
+ }
1158
+ }
1159
+ class Ft extends Error {
1160
+ constructor(e) {
1161
+ let { type: t, status: o, title: r, detail: i, validation_errors: a } = e;
1162
+ super(i), this.name = "MyAccountApiError", this.type = t, this.status = o, this.title = r, this.detail = i, this.validation_errors = a, Object.setPrototypeOf(this, Ft.prototype);
1163
+ }
1164
+ }
1165
+ const Hi = { otp: { authenticatorTypes: ["otp"] }, sms: { authenticatorTypes: ["oob"], oobChannels: ["sms"] }, email: { authenticatorTypes: ["oob"], oobChannels: ["email"] }, push: { authenticatorTypes: ["oob"], oobChannels: ["auth0"] }, voice: { authenticatorTypes: ["oob"], oobChannels: ["voice"] } }, Mi = "http://auth0.com/oauth/grant-type/mfa-otp", Ji = "http://auth0.com/oauth/grant-type/mfa-oob", Zi = "http://auth0.com/oauth/grant-type/mfa-recovery-code";
1166
+ function vr(n, e) {
1167
+ this.v = n, this.k = e;
1168
+ }
1169
+ function C(n, e, t) {
1170
+ if (typeof n == "function" ? n === e : n.has(e)) return arguments.length < 3 ? e : t;
1171
+ throw new TypeError("Private element is not present on this object");
1172
+ }
1173
+ function Vi(n) {
1174
+ return new vr(n, 0);
1175
+ }
1176
+ function br(n, e) {
1177
+ if (e.has(n)) throw new TypeError("Cannot initialize the same private elements twice on an object");
1178
+ }
1179
+ function y(n, e) {
1180
+ return n.get(C(n, e));
1181
+ }
1182
+ function W(n, e, t) {
1183
+ br(n, e), e.set(n, t);
1184
+ }
1185
+ function P(n, e, t) {
1186
+ return n.set(C(n, e), t), t;
1187
+ }
1188
+ function b(n, e, t) {
1189
+ return (e = (function(o) {
1190
+ var r = (function(i, a) {
1191
+ if (typeof i != "object" || !i) return i;
1192
+ var s = i[Symbol.toPrimitive];
1193
+ if (s !== void 0) {
1194
+ var c = s.call(i, a);
1195
+ if (typeof c != "object") return c;
1196
+ throw new TypeError("@@toPrimitive must return a primitive value.");
1197
+ }
1198
+ return (a === "string" ? String : Number)(i);
1199
+ })(o, "string");
1200
+ return typeof r == "symbol" ? r : r + "";
1201
+ })(e)) in n ? Object.defineProperty(n, e, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : n[e] = t, n;
1202
+ }
1203
+ function Wo(n, e) {
1204
+ var t = Object.keys(n);
1205
+ if (Object.getOwnPropertySymbols) {
1206
+ var o = Object.getOwnPropertySymbols(n);
1207
+ e && (o = o.filter(function(r) {
1208
+ return Object.getOwnPropertyDescriptor(n, r).enumerable;
1209
+ })), t.push.apply(t, o);
1210
+ }
1211
+ return t;
1212
+ }
1213
+ function _(n) {
1214
+ for (var e = 1; e < arguments.length; e++) {
1215
+ var t = arguments[e] != null ? arguments[e] : {};
1216
+ e % 2 ? Wo(Object(t), !0).forEach(function(o) {
1217
+ b(n, o, t[o]);
1218
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(n, Object.getOwnPropertyDescriptors(t)) : Wo(Object(t)).forEach(function(o) {
1219
+ Object.defineProperty(n, o, Object.getOwnPropertyDescriptor(t, o));
1220
+ });
1221
+ }
1222
+ return n;
1223
+ }
1224
+ function Uo(n, e) {
1225
+ if (n == null) return {};
1226
+ var t, o, r = (function(a, s) {
1227
+ if (a == null) return {};
1228
+ var c = {};
1229
+ for (var l in a) if ({}.hasOwnProperty.call(a, l)) {
1230
+ if (s.indexOf(l) !== -1) continue;
1231
+ c[l] = a[l];
1232
+ }
1233
+ return c;
1234
+ })(n, e);
1235
+ if (Object.getOwnPropertySymbols) {
1236
+ var i = Object.getOwnPropertySymbols(n);
1237
+ for (o = 0; o < i.length; o++) t = i[o], e.indexOf(t) === -1 && {}.propertyIsEnumerable.call(n, t) && (r[t] = n[t]);
1238
+ }
1239
+ return r;
1240
+ }
1241
+ function Fi(n) {
1242
+ return function() {
1243
+ return new lt(n.apply(this, arguments));
1244
+ };
1245
+ }
1246
+ function lt(n) {
1247
+ var e, t;
1248
+ function o(i, a) {
1249
+ try {
1250
+ var s = n[i](a), c = s.value, l = c instanceof vr;
1251
+ Promise.resolve(l ? c.v : c).then(function(u) {
1252
+ if (l) {
1253
+ var p = i === "return" && c.k ? i : "next";
1254
+ if (!c.k || u.done) return o(p, u);
1255
+ u = n[p](u).value;
1256
+ }
1257
+ r(!!s.done, u);
1258
+ }, function(u) {
1259
+ o("throw", u);
1260
+ });
1261
+ } catch (u) {
1262
+ r(2, u);
1263
+ }
1264
+ }
1265
+ function r(i, a) {
1266
+ i === 2 ? e.reject(a) : e.resolve({ value: a, done: i }), (e = e.next) ? o(e.key, e.arg) : t = null;
1267
+ }
1268
+ this._invoke = function(i, a) {
1269
+ return new Promise(function(s, c) {
1270
+ var l = { key: i, arg: a, resolve: s, reject: c, next: null };
1271
+ t ? t = t.next = l : (e = t = l, o(i, a));
1272
+ });
1273
+ }, typeof n.return != "function" && (this.return = void 0);
1274
+ }
1275
+ var It, gn;
1276
+ let Ln;
1277
+ lt.prototype[typeof Symbol == "function" && Symbol.asyncIterator || "@@asyncIterator"] = function() {
1278
+ return this;
1279
+ }, lt.prototype.next = function(n) {
1280
+ return this._invoke("next", n);
1281
+ }, lt.prototype.throw = function(n) {
1282
+ return this._invoke("throw", n);
1283
+ }, lt.prototype.return = function(n) {
1284
+ return this._invoke("return", n);
1285
+ }, (typeof navigator > "u" || (It = navigator.userAgent) === null || It === void 0 || (gn = It.startsWith) === null || gn === void 0 || !gn.call(It, "Mozilla/5.0 ")) && (Ln = "".concat("oauth4webapi", "/").concat("v3.8.5"));
1286
+ function ot(n, e) {
1287
+ if (n == null) return !1;
1288
+ try {
1289
+ return n instanceof e || Object.getPrototypeOf(n)[Symbol.toStringTag] === e.prototype[Symbol.toStringTag];
1290
+ } catch {
1291
+ return !1;
1292
+ }
1293
+ }
1294
+ const M = "ERR_INVALID_ARG_VALUE", X = "ERR_INVALID_ARG_TYPE";
1295
+ function x(n, e, t) {
1296
+ const o = new TypeError(n, { cause: t });
1297
+ return Object.assign(o, { code: e }), o;
1298
+ }
1299
+ const Q = Symbol(), zn = Symbol(), Hn = Symbol(), ae = Symbol(), ye = Symbol(), Xi = new TextEncoder(), Gi = new TextDecoder();
1300
+ function Be(n) {
1301
+ return typeof n == "string" ? Xi.encode(n) : Gi.decode(n);
1302
+ }
1303
+ let Mn, kr;
1304
+ Uint8Array.prototype.toBase64 ? Mn = (n) => (n instanceof ArrayBuffer && (n = new Uint8Array(n)), n.toBase64({ alphabet: "base64url", omitPadding: !0 })) : Mn = (e) => {
1305
+ e instanceof ArrayBuffer && (e = new Uint8Array(e));
1306
+ const t = [];
1307
+ for (let o = 0; o < e.byteLength; o += 32768) t.push(String.fromCharCode.apply(null, e.subarray(o, o + 32768)));
1308
+ return btoa(t.join("")).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
1309
+ };
1310
+ function Ne(n) {
1311
+ return typeof n == "string" ? kr(n) : Mn(n);
1312
+ }
1313
+ kr = Uint8Array.fromBase64 ? (n) => {
1314
+ try {
1315
+ return Uint8Array.fromBase64(n, { alphabet: "base64url" });
1316
+ } catch (e) {
1317
+ throw x("The input to be decoded is not correctly encoded.", M, e);
1318
+ }
1319
+ } : (n) => {
1320
+ try {
1321
+ const e = atob(n.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "")), t = new Uint8Array(e.length);
1322
+ for (let o = 0; o < e.length; o++) t[o] = e.charCodeAt(o);
1323
+ return t;
1324
+ } catch (e) {
1325
+ throw x("The input to be decoded is not correctly encoded.", M, e);
1326
+ }
1327
+ };
1328
+ class q extends Error {
1329
+ constructor(e, t) {
1330
+ var o;
1331
+ super(e, t), b(this, "code", void 0), this.name = this.constructor.name, this.code = Vn, (o = Error.captureStackTrace) === null || o === void 0 || o.call(Error, this, this.constructor);
1332
+ }
1333
+ }
1334
+ class ao extends Error {
1335
+ constructor(e, t) {
1336
+ var o;
1337
+ super(e, t), b(this, "code", void 0), this.name = this.constructor.name, t != null && t.code && (this.code = t == null ? void 0 : t.code), (o = Error.captureStackTrace) === null || o === void 0 || o.call(Error, this, this.constructor);
1338
+ }
1339
+ }
1340
+ function E(n, e, t) {
1341
+ return new ao(n, { code: e, cause: t });
1342
+ }
1343
+ function Yi(n, e) {
1344
+ if ((function(t, o) {
1345
+ if (!(t instanceof CryptoKey)) throw x("".concat(o, " must be a CryptoKey"), X);
1346
+ })(n, e), n.type !== "private") throw x("".concat(e, " must be a private CryptoKey"), M);
1347
+ }
1348
+ function Xt(n) {
1349
+ return n !== null && typeof n == "object" && !Array.isArray(n);
1350
+ }
1351
+ function on(n) {
1352
+ ot(n, Headers) && (n = Object.fromEntries(n.entries()));
1353
+ const e = new Headers(n ?? {});
1354
+ if (Ln && !e.has("user-agent") && e.set("user-agent", Ln), e.has("authorization")) throw x('"options.headers" must not include the "authorization" header name', M);
1355
+ return e;
1356
+ }
1357
+ function _r(n, e) {
1358
+ if (e !== void 0) {
1359
+ if (typeof e == "function" && (e = e(n.href)), !(e instanceof AbortSignal)) throw x('"options.signal" must return or be an instance of AbortSignal', X);
1360
+ return e;
1361
+ }
1362
+ }
1363
+ function Ko(n) {
1364
+ return n.includes("//") ? n.replace("//", "/") : n;
1365
+ }
1366
+ async function qi(n, e) {
1367
+ return (async function(t, o, r, i) {
1368
+ if (!(t instanceof URL)) throw x('"'.concat(o, '" must be an instance of URL'), X);
1369
+ so(t, (i == null ? void 0 : i[Q]) !== !0);
1370
+ const a = r(new URL(t.href)), s = on(i == null ? void 0 : i.headers);
1371
+ return s.set("accept", "application/json"), ((i == null ? void 0 : i[ae]) || fetch)(a.href, { body: void 0, headers: Object.fromEntries(s.entries()), method: "GET", redirect: "manual", signal: _r(a, i == null ? void 0 : i.signal) });
1372
+ })(n, "issuerIdentifier", (t) => {
1373
+ switch (e == null ? void 0 : e.algorithm) {
1374
+ case void 0:
1375
+ case "oidc":
1376
+ (function(o, r) {
1377
+ o.pathname = Ko("".concat(o.pathname, "/").concat(r));
1378
+ })(t, ".well-known/openid-configuration");
1379
+ break;
1380
+ case "oauth2":
1381
+ (function(o, r) {
1382
+ let i = arguments.length > 2 && arguments[2] !== void 0 && arguments[2];
1383
+ o.pathname === "/" ? o.pathname = r : o.pathname = Ko("".concat(r, "/").concat(i ? o.pathname : o.pathname.replace(/(\/)$/, "")));
1384
+ })(t, ".well-known/oauth-authorization-server");
1385
+ break;
1386
+ default:
1387
+ throw x('"options.algorithm" must be "oidc" (default), or "oauth2"', M);
1388
+ }
1389
+ return t;
1390
+ }, e);
1391
+ }
1392
+ function Te(n, e, t, o, r) {
1393
+ try {
1394
+ if (typeof n != "number" || !Number.isFinite(n)) throw x("".concat(t, " must be a number"), X, r);
1395
+ if (n > 0) return;
1396
+ if (e) {
1397
+ if (n !== 0) throw x("".concat(t, " must be a non-negative number"), M, r);
1398
+ return;
1399
+ }
1400
+ throw x("".concat(t, " must be a positive number"), M, r);
1401
+ } catch (i) {
1402
+ throw o ? E(i.message, o, r) : i;
1403
+ }
1404
+ }
1405
+ function U(n, e, t, o) {
1406
+ try {
1407
+ if (typeof n != "string") throw x("".concat(e, " must be a string"), X, o);
1408
+ if (n.length === 0) throw x("".concat(e, " must not be empty"), M, o);
1409
+ } catch (r) {
1410
+ throw t ? E(r.message, t, o) : r;
1411
+ }
1412
+ }
1413
+ function Sr(n) {
1414
+ (function(e, t) {
1415
+ if (Ar(e) !== t) throw (function(o) {
1416
+ let r = '"response" content-type must be ';
1417
+ for (var i = arguments.length, a = new Array(i > 1 ? i - 1 : 0), s = 1; s < i; s++) a[s - 1] = arguments[s];
1418
+ if (a.length > 2) {
1419
+ const c = a.pop();
1420
+ r += "".concat(a.join(", "), ", or ").concat(c);
1421
+ } else a.length === 2 ? r += "".concat(a[0], " or ").concat(a[1]) : r += a[0];
1422
+ return E(r, Ir, o);
1423
+ })(e, t);
1424
+ })(n, "application/json");
1425
+ }
1426
+ function Tr() {
1427
+ return Ne(crypto.getRandomValues(new Uint8Array(32)));
1428
+ }
1429
+ function Bi(n) {
1430
+ switch (n.algorithm.name) {
1431
+ case "RSA-PSS":
1432
+ return (function(e) {
1433
+ switch (e.algorithm.hash.name) {
1434
+ case "SHA-256":
1435
+ return "PS256";
1436
+ case "SHA-384":
1437
+ return "PS384";
1438
+ case "SHA-512":
1439
+ return "PS512";
1440
+ default:
1441
+ throw new q("unsupported RsaHashedKeyAlgorithm hash name", { cause: e });
1442
+ }
1443
+ })(n);
1444
+ case "RSASSA-PKCS1-v1_5":
1445
+ return (function(e) {
1446
+ switch (e.algorithm.hash.name) {
1447
+ case "SHA-256":
1448
+ return "RS256";
1449
+ case "SHA-384":
1450
+ return "RS384";
1451
+ case "SHA-512":
1452
+ return "RS512";
1453
+ default:
1454
+ throw new q("unsupported RsaHashedKeyAlgorithm hash name", { cause: e });
1455
+ }
1456
+ })(n);
1457
+ case "ECDSA":
1458
+ return (function(e) {
1459
+ switch (e.algorithm.namedCurve) {
1460
+ case "P-256":
1461
+ return "ES256";
1462
+ case "P-384":
1463
+ return "ES384";
1464
+ case "P-521":
1465
+ return "ES512";
1466
+ default:
1467
+ throw new q("unsupported EcKeyAlgorithm namedCurve", { cause: e });
1468
+ }
1469
+ })(n);
1470
+ case "Ed25519":
1471
+ case "ML-DSA-44":
1472
+ case "ML-DSA-65":
1473
+ case "ML-DSA-87":
1474
+ return n.algorithm.name;
1475
+ case "EdDSA":
1476
+ return "Ed25519";
1477
+ default:
1478
+ throw new q("unsupported CryptoKey algorithm name", { cause: n });
1479
+ }
1480
+ }
1481
+ function Gt(n) {
1482
+ const e = n == null ? void 0 : n[zn];
1483
+ return typeof e == "number" && Number.isFinite(e) ? e : 0;
1484
+ }
1485
+ function Jn(n) {
1486
+ const e = n == null ? void 0 : n[Hn];
1487
+ return typeof e == "number" && Number.isFinite(e) && Math.sign(e) !== -1 ? e : 30;
1488
+ }
1489
+ function Yt() {
1490
+ return Math.floor(Date.now() / 1e3);
1491
+ }
1492
+ function re(n) {
1493
+ if (typeof n != "object" || n === null) throw x('"as" must be an object', X);
1494
+ U(n.issuer, '"as.issuer"');
1495
+ }
1496
+ function ie(n) {
1497
+ if (typeof n != "object" || n === null) throw x('"client" must be an object', X);
1498
+ U(n.client_id, '"client.client_id"');
1499
+ }
1500
+ function Do(n) {
1501
+ return U(n, '"clientSecret"'), (e, t, o, r) => {
1502
+ o.set("client_id", t.client_id), o.set("client_secret", n);
1503
+ };
1504
+ }
1505
+ function Qi(n, e) {
1506
+ const { key: t, kid: o } = (r = n) instanceof CryptoKey ? { key: r } : (r == null ? void 0 : r.key) instanceof CryptoKey ? (r.kid !== void 0 && U(r.kid, '"kid"'), { key: r.key, kid: r.kid }) : {};
1507
+ var r;
1508
+ return Yi(t, '"clientPrivateKey.key"'), async (i, a, s, c) => {
1509
+ const l = { alg: Bi(t), kid: o }, u = (function(p, h) {
1510
+ const d = Yt() + Gt(h);
1511
+ return { jti: Tr(), aud: p.issuer, exp: d + 60, iat: d, nbf: d, iss: h.client_id, sub: h.client_id };
1512
+ })(i, a);
1513
+ s.set("client_id", a.client_id), s.set("client_assertion_type", "urn:ietf:params:oauth:client-assertion-type:jwt-bearer"), s.set("client_assertion", await (async function(p, h, d) {
1514
+ if (!d.usages.includes("sign")) throw x('CryptoKey instances used for signing assertions must include "sign" in their "usages"', M);
1515
+ const g = "".concat(Ne(Be(JSON.stringify(p))), ".").concat(Ne(Be(JSON.stringify(h)))), f = Ne(await crypto.subtle.sign((function(m) {
1516
+ switch (m.algorithm.name) {
1517
+ case "ECDSA":
1518
+ return { name: m.algorithm.name, hash: ga(m) };
1519
+ case "RSA-PSS":
1520
+ switch (zo(m), m.algorithm.hash.name) {
1521
+ case "SHA-256":
1522
+ case "SHA-384":
1523
+ case "SHA-512":
1524
+ return { name: m.algorithm.name, saltLength: parseInt(m.algorithm.hash.name.slice(-3), 10) >> 3 };
1525
+ default:
1526
+ throw new q("unsupported RSA-PSS hash name", { cause: m });
1527
+ }
1528
+ case "RSASSA-PKCS1-v1_5":
1529
+ return zo(m), m.algorithm.name;
1530
+ case "ML-DSA-44":
1531
+ case "ML-DSA-65":
1532
+ case "ML-DSA-87":
1533
+ case "Ed25519":
1534
+ return m.algorithm.name;
1535
+ }
1536
+ throw new q("unsupported CryptoKey algorithm name", { cause: m });
1537
+ })(d), d, Be(g)));
1538
+ return "".concat(g, ".").concat(f);
1539
+ })(l, u, t));
1540
+ };
1541
+ }
1542
+ const $i = URL.parse ? (n, e) => URL.parse(n, e) : (n, e) => {
1543
+ try {
1544
+ return new URL(n, e);
1545
+ } catch {
1546
+ return null;
1547
+ }
1548
+ };
1549
+ function so(n, e) {
1550
+ if (e && n.protocol !== "https:") throw E("only requests to HTTPS are allowed", xr, n);
1551
+ if (n.protocol !== "https:" && n.protocol !== "http:") throw E("only HTTP and HTTPS requests are allowed", Or, n);
1552
+ }
1553
+ function No(n, e, t, o) {
1554
+ let r;
1555
+ if (typeof n != "string" || !(r = $i(n))) throw E("authorization server metadata does not contain a valid ".concat(t ? '"as.mtls_endpoint_aliases.'.concat(e, '"') : '"as.'.concat(e, '"')), n === void 0 ? fa : ya, { attribute: t ? "mtls_endpoint_aliases.".concat(e) : e });
1556
+ return so(r, o), r;
1557
+ }
1558
+ function vt(n, e, t, o) {
1559
+ return t && n.mtls_endpoint_aliases && e in n.mtls_endpoint_aliases ? No(n.mtls_endpoint_aliases[e], e, t, o) : No(n[e], e, t, o);
1560
+ }
1561
+ class rn extends Error {
1562
+ constructor(e, t) {
1563
+ var o;
1564
+ super(e, t), b(this, "cause", void 0), b(this, "code", void 0), b(this, "error", void 0), b(this, "status", void 0), b(this, "error_description", void 0), b(this, "response", void 0), this.name = this.constructor.name, this.code = pa, this.cause = t.cause, this.error = t.cause.error, this.status = t.response.status, this.error_description = t.cause.error_description, Object.defineProperty(this, "response", { enumerable: !1, value: t.response }), (o = Error.captureStackTrace) === null || o === void 0 || o.call(Error, this, this.constructor);
1565
+ }
1566
+ }
1567
+ class Er extends Error {
1568
+ constructor(e, t) {
1569
+ var o, r;
1570
+ super(e, t), b(this, "cause", void 0), b(this, "code", void 0), b(this, "error", void 0), b(this, "error_description", void 0), this.name = this.constructor.name, this.code = ma, this.cause = t.cause, this.error = t.cause.get("error"), this.error_description = (o = t.cause.get("error_description")) !== null && o !== void 0 ? o : void 0, (r = Error.captureStackTrace) === null || r === void 0 || r.call(Error, this, this.constructor);
1571
+ }
1572
+ }
1573
+ class co extends Error {
1574
+ constructor(e, t) {
1575
+ var o;
1576
+ super(e, t), b(this, "cause", void 0), b(this, "code", void 0), b(this, "response", void 0), b(this, "status", void 0), this.name = this.constructor.name, this.code = da, this.cause = t.cause, this.status = t.response.status, this.response = t.response, Object.defineProperty(this, "response", { enumerable: !1 }), (o = Error.captureStackTrace) === null || o === void 0 || o.call(Error, this, this.constructor);
1577
+ }
1578
+ }
1579
+ const qt = "[a-zA-Z0-9!#$%&\\'\\*\\+\\-\\.\\^_`\\|~]+", ea = "(" + qt + ')\\s*=\\s*"((?:[^"\\\\]|\\\\[\\s\\S])*)"', ta = "(" + qt + ")\\s*=\\s*(" + qt + ")", na = new RegExp("^[,\\s]*(" + qt + ")"), oa = new RegExp("^[,\\s]*" + ea + "[,\\s]*(.*)"), ra = new RegExp("^[,\\s]*" + ta + "[,\\s]*(.*)"), ia = new RegExp("^([a-zA-Z0-9\\-\\._\\~\\+\\/]+={0,2})(?:$|[,\\s])(.*)");
1580
+ async function uo(n, e, t) {
1581
+ if (n.status !== e) {
1582
+ let r;
1583
+ var o;
1584
+ throw (function(i) {
1585
+ let a;
1586
+ if (a = (function(s) {
1587
+ if (!ot(s, Response)) throw x('"response" must be an instance of Response', X);
1588
+ const c = s.headers.get("www-authenticate");
1589
+ if (c === null) return;
1590
+ const l = [];
1591
+ let u = c;
1592
+ for (; u; ) {
1593
+ var p;
1594
+ let h = u.match(na);
1595
+ const d = (p = h) === null || p === void 0 ? void 0 : p[1].toLowerCase();
1596
+ if (!d) return;
1597
+ const g = u.substring(h[0].length);
1598
+ if (g && !g.match(/^[\s,]/)) return;
1599
+ const f = g.match(/^\s+(.*)$/), m = !!f;
1600
+ u = f ? f[1] : void 0;
1601
+ const w = {};
1602
+ let k;
1603
+ if (m) for (; u; ) {
1604
+ let T, v;
1605
+ if (h = u.match(oa)) {
1606
+ if ([, T, v, u] = h, v.includes("\\")) try {
1607
+ v = JSON.parse('"'.concat(v, '"'));
1608
+ } catch {
1609
+ }
1610
+ w[T.toLowerCase()] = v;
1611
+ } else {
1612
+ if (!(h = u.match(ra))) {
1613
+ if (h = u.match(ia)) {
1614
+ if (Object.keys(w).length) break;
1615
+ [, k, u] = h;
1616
+ break;
1617
+ }
1618
+ return;
1619
+ }
1620
+ [, T, v, u] = h, w[T.toLowerCase()] = v;
1621
+ }
1622
+ }
1623
+ else u = g || void 0;
1624
+ const S = { scheme: d, parameters: w };
1625
+ k && (S.token68 = k), l.push(S);
1626
+ }
1627
+ return l.length ? l : void 0;
1628
+ })(i)) throw new co("server responded with a challenge in the WWW-Authenticate HTTP Header", { cause: a, response: i });
1629
+ })(n), (r = await (async function(i) {
1630
+ if (i.status > 399 && i.status < 500) {
1631
+ kt(i), Sr(i);
1632
+ try {
1633
+ const a = await i.clone().json();
1634
+ if (Xt(a) && typeof a.error == "string" && a.error.length) return a;
1635
+ } catch {
1636
+ }
1637
+ }
1638
+ })(n)) ? (await ((o = n.body) === null || o === void 0 ? void 0 : o.cancel()), new rn("server responded with an error in the response body", { cause: r, response: n })) : E('"response" is not a conform '.concat(t, " response (unexpected HTTP status code)"), po, n);
1639
+ }
1640
+ }
1641
+ function Pr(n) {
1642
+ if (!ho.has(n)) throw x('"options.DPoP" is not a valid DPoPHandle', M);
1643
+ }
1644
+ function Ar(n) {
1645
+ var e;
1646
+ return (e = n.headers.get("content-type")) === null || e === void 0 ? void 0 : e.split(";")[0];
1647
+ }
1648
+ async function lo(n, e, t, o, r, i, a) {
1649
+ return await t(n, e, r, i), i.set("content-type", "application/x-www-form-urlencoded;charset=UTF-8"), ((a == null ? void 0 : a[ae]) || fetch)(o.href, { body: r, headers: Object.fromEntries(i.entries()), method: "POST", redirect: "manual", signal: _r(o, a == null ? void 0 : a.signal) });
1650
+ }
1651
+ async function bt(n, e, t, o, r, i) {
1652
+ var a;
1653
+ const s = vt(n, "token_endpoint", e.use_mtls_endpoint_aliases, (i == null ? void 0 : i[Q]) !== !0);
1654
+ r.set("grant_type", o);
1655
+ const c = on(i == null ? void 0 : i.headers);
1656
+ c.set("accept", "application/json"), (i == null ? void 0 : i.DPoP) !== void 0 && (Pr(i.DPoP), await i.DPoP.addProof(s, c, "POST"));
1657
+ const l = await lo(n, e, t, s, r, c, i);
1658
+ return i == null || (a = i.DPoP) === null || a === void 0 || a.cacheNonce(l, s), l;
1659
+ }
1660
+ const Rr = /* @__PURE__ */ new WeakMap(), aa = /* @__PURE__ */ new WeakMap();
1661
+ function Zn(n) {
1662
+ if (!n.id_token) return;
1663
+ const e = Rr.get(n);
1664
+ if (!e) throw x('"ref" was already garbage collected or did not resolve from the proper sources', M);
1665
+ return e;
1666
+ }
1667
+ async function et(n, e, t, o, r, i) {
1668
+ if (re(n), ie(e), !ot(t, Response)) throw x('"response" must be an instance of Response', X);
1669
+ await uo(t, 200, "Token Endpoint"), kt(t);
1670
+ const a = await an(t);
1671
+ if (U(a.access_token, '"response" body "access_token" property', A, { body: a }), U(a.token_type, '"response" body "token_type" property', A, { body: a }), a.token_type = a.token_type.toLowerCase(), a.expires_in !== void 0) {
1672
+ let s = typeof a.expires_in != "number" ? parseFloat(a.expires_in) : a.expires_in;
1673
+ Te(s, !0, '"response" body "expires_in" property', A, { body: a }), a.expires_in = s;
1674
+ }
1675
+ if (a.refresh_token !== void 0 && U(a.refresh_token, '"response" body "refresh_token" property', A, { body: a }), a.scope !== void 0 && typeof a.scope != "string") throw E('"response" body "scope" property must be a string', A, { body: a });
1676
+ if (a.id_token !== void 0) {
1677
+ U(a.id_token, '"response" body "id_token" property', A, { body: a });
1678
+ const s = ["aud", "exp", "iat", "iss", "sub"];
1679
+ e.require_auth_time === !0 && s.push("auth_time"), e.default_max_age !== void 0 && (Te(e.default_max_age, !0, '"client.default_max_age"'), s.push("auth_time")), o != null && o.length && s.push(...o);
1680
+ const { claims: c, jwt: l } = await (async function(u, p, h, d, g) {
1681
+ let f, m, { 0: w, 1: k, length: S } = u.split(".");
1682
+ if (S === 5) {
1683
+ if (g === void 0) throw new q("JWE decryption is not configured", { cause: u });
1684
+ u = await g(u), { 0: w, 1: k, length: S } = u.split(".");
1685
+ }
1686
+ if (S !== 3) throw E("Invalid JWT", A, u);
1687
+ try {
1688
+ f = JSON.parse(Be(Ne(w)));
1689
+ } catch (v) {
1690
+ throw E("failed to parse JWT Header body as base64url encoded JSON", Bt, v);
1691
+ }
1692
+ if (!Xt(f)) throw E("JWT Header must be a top level object", A, u);
1693
+ if (p(f), f.crit !== void 0) throw new q('no JWT "crit" header parameter extensions are supported', { cause: { header: f } });
1694
+ try {
1695
+ m = JSON.parse(Be(Ne(k)));
1696
+ } catch (v) {
1697
+ throw E("failed to parse JWT Payload body as base64url encoded JSON", Bt, v);
1698
+ }
1699
+ if (!Xt(m)) throw E("JWT Payload must be a top level object", A, u);
1700
+ const T = Yt() + h;
1701
+ if (m.exp !== void 0) {
1702
+ if (typeof m.exp != "number") throw E('unexpected JWT "exp" (expiration time) claim type', A, { claims: m });
1703
+ if (m.exp <= T - d) throw E('unexpected JWT "exp" (expiration time) claim value, expiration is past current timestamp', gt, { claims: m, now: T, tolerance: d, claim: "exp" });
1704
+ }
1705
+ if (m.iat !== void 0 && typeof m.iat != "number") throw E('unexpected JWT "iat" (issued at) claim type', A, { claims: m });
1706
+ if (m.iss !== void 0 && typeof m.iss != "string") throw E('unexpected JWT "iss" (issuer) claim type', A, { claims: m });
1707
+ if (m.nbf !== void 0) {
1708
+ if (typeof m.nbf != "number") throw E('unexpected JWT "nbf" (not before) claim type', A, { claims: m });
1709
+ if (m.nbf > T + d) throw E('unexpected JWT "nbf" (not before) claim value', gt, { claims: m, now: T, tolerance: d, claim: "nbf" });
1710
+ }
1711
+ if (m.aud !== void 0 && typeof m.aud != "string" && !Array.isArray(m.aud)) throw E('unexpected JWT "aud" (audience) claim type', A, { claims: m });
1712
+ return { header: f, claims: m, jwt: u };
1713
+ })(a.id_token, va.bind(void 0, e.id_token_signed_response_alg, n.id_token_signing_alg_values_supported, "RS256"), Gt(e), Jn(e), r).then(la.bind(void 0, s)).then(ca.bind(void 0, n)).then(sa.bind(void 0, e.client_id));
1714
+ if (Array.isArray(c.aud) && c.aud.length !== 1) {
1715
+ if (c.azp === void 0) throw E('ID Token "aud" (audience) claim includes additional untrusted audiences', fe, { claims: c, claim: "aud" });
1716
+ if (c.azp !== e.client_id) throw E('unexpected ID Token "azp" (authorized party) claim value', fe, { expected: e.client_id, claims: c, claim: "azp" });
1717
+ }
1718
+ c.auth_time !== void 0 && Te(c.auth_time, !0, 'ID Token "auth_time" (authentication time)', A, { claims: c }), aa.set(t, l), Rr.set(a, c);
1719
+ }
1720
+ if ((i == null ? void 0 : i[a.token_type]) !== void 0) i[a.token_type](t, a);
1721
+ else if (a.token_type !== "dpop" && a.token_type !== "bearer") throw new q("unsupported `token_type` value", { cause: { body: a } });
1722
+ return a;
1723
+ }
1724
+ function sa(n, e) {
1725
+ if (Array.isArray(e.claims.aud)) {
1726
+ if (!e.claims.aud.includes(n)) throw E('unexpected JWT "aud" (audience) claim value', fe, { expected: n, claims: e.claims, claim: "aud" });
1727
+ } else if (e.claims.aud !== n) throw E('unexpected JWT "aud" (audience) claim value', fe, { expected: n, claims: e.claims, claim: "aud" });
1728
+ return e;
1729
+ }
1730
+ function ca(n, e) {
1731
+ var t, o;
1732
+ const r = (t = (o = n[Cr]) === null || o === void 0 ? void 0 : o.call(n, e)) !== null && t !== void 0 ? t : n.issuer;
1733
+ if (e.claims.iss !== r) throw E('unexpected JWT "iss" (issuer) claim value', fe, { expected: r, claims: e.claims, claim: "iss" });
1734
+ return e;
1735
+ }
1736
+ const ho = /* @__PURE__ */ new WeakSet(), Lo = Symbol(), ua = { aud: "audience", c_hash: "code hash", client_id: "client id", exp: "expiration time", iat: "issued at", iss: "issuer", jti: "jwt id", nonce: "nonce", s_hash: "state hash", sub: "subject", ath: "access token hash", htm: "http method", htu: "http uri", cnf: "confirmation", auth_time: "authentication time" };
1737
+ function la(n, e) {
1738
+ for (const t of n) if (e.claims[t] === void 0) throw E('JWT "'.concat(t, '" (').concat(ua[t], ") claim missing"), A, { claims: e.claims });
1739
+ return e;
1740
+ }
1741
+ const wn = Symbol(), vn = Symbol();
1742
+ async function ha(n, e, t, o) {
1743
+ return typeof (o == null ? void 0 : o.expectedNonce) == "string" || typeof (o == null ? void 0 : o.maxAge) == "number" || o != null && o.requireIdToken ? (async function(r, i, a, s, c, l, u) {
1744
+ const p = [];
1745
+ switch (s) {
1746
+ case void 0:
1747
+ s = wn;
1748
+ break;
1749
+ case wn:
1750
+ break;
1751
+ default:
1752
+ U(s, '"expectedNonce" argument'), p.push("nonce");
1753
+ }
1754
+ switch (c != null || (c = i.default_max_age), c) {
1755
+ case void 0:
1756
+ c = vn;
1757
+ break;
1758
+ case vn:
1759
+ break;
1760
+ default:
1761
+ Te(c, !0, '"maxAge" argument'), p.push("auth_time");
1762
+ }
1763
+ const h = await et(r, i, a, p, l, u);
1764
+ U(h.id_token, '"response" body "id_token" property', A, { body: h });
1765
+ const d = Zn(h);
1766
+ if (c !== vn) {
1767
+ const g = Yt() + Gt(i), f = Jn(i);
1768
+ if (d.auth_time + c < g - f) throw E("too much time has elapsed since the last End-User authentication", gt, { claims: d, now: g, tolerance: f, claim: "auth_time" });
1769
+ }
1770
+ if (s === wn) {
1771
+ if (d.nonce !== void 0) throw E('unexpected ID Token "nonce" claim value', fe, { expected: void 0, claims: d, claim: "nonce" });
1772
+ } else if (d.nonce !== s) throw E('unexpected ID Token "nonce" claim value', fe, { expected: s, claims: d, claim: "nonce" });
1773
+ return h;
1774
+ })(n, e, t, o.expectedNonce, o.maxAge, o[ye], o.recognizedTokenTypes) : (async function(r, i, a, s, c) {
1775
+ const l = await et(r, i, a, void 0, s, c), u = Zn(l);
1776
+ if (u) {
1777
+ if (i.default_max_age !== void 0) {
1778
+ Te(i.default_max_age, !0, '"client.default_max_age"');
1779
+ const p = Yt() + Gt(i), h = Jn(i);
1780
+ if (u.auth_time + i.default_max_age < p - h) throw E("too much time has elapsed since the last End-User authentication", gt, { claims: u, now: p, tolerance: h, claim: "auth_time" });
1781
+ }
1782
+ if (u.nonce !== void 0) throw E('unexpected ID Token "nonce" claim value', fe, { expected: void 0, claims: u, claim: "nonce" });
1783
+ }
1784
+ return l;
1785
+ })(n, e, t, o == null ? void 0 : o[ye], o == null ? void 0 : o.recognizedTokenTypes);
1786
+ }
1787
+ const da = "OAUTH_WWW_AUTHENTICATE_CHALLENGE", pa = "OAUTH_RESPONSE_BODY_ERROR", Vn = "OAUTH_UNSUPPORTED_OPERATION", ma = "OAUTH_AUTHORIZATION_RESPONSE_ERROR", Bt = "OAUTH_PARSE_ERROR", A = "OAUTH_INVALID_RESPONSE", Ir = "OAUTH_RESPONSE_IS_NOT_JSON", po = "OAUTH_RESPONSE_IS_NOT_CONFORM", xr = "OAUTH_HTTP_REQUEST_FORBIDDEN", Or = "OAUTH_REQUEST_PROTOCOL_FORBIDDEN", gt = "OAUTH_JWT_TIMESTAMP_CHECK_FAILED", fe = "OAUTH_JWT_CLAIM_COMPARISON_FAILED", Fn = "OAUTH_JSON_ATTRIBUTE_COMPARISON_FAILED", fa = "OAUTH_MISSING_SERVER_METADATA", ya = "OAUTH_INVALID_SERVER_METADATA";
1788
+ function kt(n) {
1789
+ if (n.bodyUsed) throw x('"response" body has been used already', M);
1790
+ }
1791
+ function zo(n) {
1792
+ const { algorithm: e } = n;
1793
+ if (typeof e.modulusLength != "number" || e.modulusLength < 2048) throw new q("unsupported ".concat(e.name, " modulusLength"), { cause: n });
1794
+ }
1795
+ function ga(n) {
1796
+ const { algorithm: e } = n;
1797
+ switch (e.namedCurve) {
1798
+ case "P-256":
1799
+ return "SHA-256";
1800
+ case "P-384":
1801
+ return "SHA-384";
1802
+ case "P-521":
1803
+ return "SHA-512";
1804
+ default:
1805
+ throw new q("unsupported ECDSA namedCurve", { cause: n });
1806
+ }
1807
+ }
1808
+ async function wa(n) {
1809
+ if (n.method !== "POST") throw x("form_post responses are expected to use the POST method", M, { cause: n });
1810
+ if (Ar(n) !== "application/x-www-form-urlencoded") throw x("form_post responses are expected to use the application/x-www-form-urlencoded content-type", M, { cause: n });
1811
+ return (async function(e) {
1812
+ if (e.bodyUsed) throw x("form_post Request instances must contain a readable body", M, { cause: e });
1813
+ return e.text();
1814
+ })(n);
1815
+ }
1816
+ function va(n, e, t, o) {
1817
+ if (n === void 0) if (Array.isArray(e)) {
1818
+ if (!e.includes(o.alg)) throw E('unexpected JWT "alg" header parameter', A, { header: o, expected: e, reason: "authorization server metadata" });
1819
+ } else {
1820
+ if (t === void 0) throw E('missing client or server configuration to verify used JWT "alg" header parameter', void 0, { client: n, issuer: e, fallback: t });
1821
+ if (typeof t == "string" ? o.alg !== t : typeof t == "function" ? !t(o.alg) : !t.includes(o.alg)) throw E('unexpected JWT "alg" header parameter', A, { header: o, expected: t, reason: "default value" });
1822
+ }
1823
+ else if (typeof n == "string" ? o.alg !== n : !n.includes(o.alg)) throw E('unexpected JWT "alg" header parameter', A, { header: o, expected: n, reason: "client configuration" });
1824
+ }
1825
+ function We(n, e) {
1826
+ const { 0: t, length: o } = n.getAll(e);
1827
+ if (o > 1) throw E('"'.concat(e, '" parameter must be provided only once'), A);
1828
+ return t;
1829
+ }
1830
+ const ba = Symbol(), ka = Symbol();
1831
+ function _a(n, e, t, o) {
1832
+ if (re(n), ie(e), t instanceof URL && (t = t.searchParams), !(t instanceof URLSearchParams)) throw x('"parameters" must be an instance of URLSearchParams, or URL', X);
1833
+ if (We(t, "response")) throw E('"parameters" contains a JARM response, use validateJwtAuthResponse() instead of validateAuthResponse()', A, { parameters: t });
1834
+ const r = We(t, "iss"), i = We(t, "state");
1835
+ if (!r && n.authorization_response_iss_parameter_supported) throw E('response parameter "iss" (issuer) missing', A, { parameters: t });
1836
+ if (r && r !== n.issuer) throw E('unexpected "iss" (issuer) response parameter value', A, { expected: n.issuer, parameters: t });
1837
+ switch (o) {
1838
+ case void 0:
1839
+ case ka:
1840
+ if (i !== void 0) throw E('unexpected "state" response parameter encountered', A, { expected: void 0, parameters: t });
1841
+ break;
1842
+ case ba:
1843
+ break;
1844
+ default:
1845
+ if (U(o, '"expectedState" argument'), i !== o) throw E(i === void 0 ? 'response parameter "state" missing' : 'unexpected "state" response parameter value', A, { expected: o, parameters: t });
1846
+ }
1847
+ if (We(t, "error")) throw new Er("authorization response from the server is an error", { cause: t });
1848
+ const a = We(t, "id_token"), s = We(t, "token");
1849
+ if (a !== void 0 || s !== void 0) throw new q("implicit and hybrid flows are not supported");
1850
+ return c = new URLSearchParams(t), ho.add(c), c;
1851
+ var c;
1852
+ }
1853
+ async function an(n) {
1854
+ let e, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Sr;
1855
+ try {
1856
+ e = await n.json();
1857
+ } catch (o) {
1858
+ throw t(n), E('failed to parse "response" body as JSON', Bt, o);
1859
+ }
1860
+ if (!Xt(e)) throw E('"response" body must be a top level object', A, { body: e });
1861
+ return e;
1862
+ }
1863
+ const bn = Symbol(), Cr = Symbol(), Ho = new TextEncoder(), wt = new TextDecoder();
1864
+ function kn(n) {
1865
+ const e = new Uint8Array(n.length);
1866
+ for (let t = 0; t < n.length; t++) {
1867
+ const o = n.charCodeAt(t);
1868
+ if (o > 127) throw new TypeError("non-ASCII string encountered in encode()");
1869
+ e[t] = o;
1870
+ }
1871
+ return e;
1872
+ }
1873
+ function jr(n) {
1874
+ if (Uint8Array.fromBase64) return Uint8Array.fromBase64(n);
1875
+ const e = atob(n), t = new Uint8Array(e.length);
1876
+ for (let o = 0; o < e.length; o++) t[o] = e.charCodeAt(o);
1877
+ return t;
1878
+ }
1879
+ function sn(n) {
1880
+ if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof n == "string" ? n : wt.decode(n), { alphabet: "base64url" });
1881
+ let e = n;
1882
+ e instanceof Uint8Array && (e = wt.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/");
1883
+ try {
1884
+ return jr(e);
1885
+ } catch {
1886
+ throw new TypeError("The input to be decoded is not correctly encoded.");
1887
+ }
1888
+ }
1889
+ const ke = function(n) {
1890
+ return new TypeError("CryptoKey does not support this operation, its ".concat(arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "algorithm.name", " must be ").concat(n));
1891
+ }, Je = (n, e) => n.name === e;
1892
+ function _n(n, e) {
1893
+ var t;
1894
+ if (t = n.hash, parseInt(t.name.slice(4), 10) !== e) throw ke("SHA-".concat(e), "algorithm.hash");
1895
+ }
1896
+ function Sa(n, e, t) {
1897
+ switch (e) {
1898
+ case "HS256":
1899
+ case "HS384":
1900
+ case "HS512":
1901
+ if (!Je(n.algorithm, "HMAC")) throw ke("HMAC");
1902
+ _n(n.algorithm, parseInt(e.slice(2), 10));
1903
+ break;
1904
+ case "RS256":
1905
+ case "RS384":
1906
+ case "RS512":
1907
+ if (!Je(n.algorithm, "RSASSA-PKCS1-v1_5")) throw ke("RSASSA-PKCS1-v1_5");
1908
+ _n(n.algorithm, parseInt(e.slice(2), 10));
1909
+ break;
1910
+ case "PS256":
1911
+ case "PS384":
1912
+ case "PS512":
1913
+ if (!Je(n.algorithm, "RSA-PSS")) throw ke("RSA-PSS");
1914
+ _n(n.algorithm, parseInt(e.slice(2), 10));
1915
+ break;
1916
+ case "Ed25519":
1917
+ case "EdDSA":
1918
+ if (!Je(n.algorithm, "Ed25519")) throw ke("Ed25519");
1919
+ break;
1920
+ case "ML-DSA-44":
1921
+ case "ML-DSA-65":
1922
+ case "ML-DSA-87":
1923
+ if (!Je(n.algorithm, e)) throw ke(e);
1924
+ break;
1925
+ case "ES256":
1926
+ case "ES384":
1927
+ case "ES512": {
1928
+ if (!Je(n.algorithm, "ECDSA")) throw ke("ECDSA");
1929
+ const o = (function(r) {
1930
+ switch (r) {
1931
+ case "ES256":
1932
+ return "P-256";
1933
+ case "ES384":
1934
+ return "P-384";
1935
+ case "ES512":
1936
+ return "P-521";
1937
+ default:
1938
+ throw new Error("unreachable");
1939
+ }
1940
+ })(e);
1941
+ if (n.algorithm.namedCurve !== o) throw ke(o, "algorithm.namedCurve");
1942
+ break;
1943
+ }
1944
+ default:
1945
+ throw new TypeError("CryptoKey does not support this operation");
1946
+ }
1947
+ (function(o, r) {
1948
+ if (!o.usages.includes(r)) throw new TypeError("CryptoKey does not support this operation, its usages must include ".concat(r, "."));
1949
+ })(n, t);
1950
+ }
1951
+ function Wr(n, e) {
1952
+ for (var t = arguments.length, o = new Array(t > 2 ? t - 2 : 0), r = 2; r < t; r++) o[r - 2] = arguments[r];
1953
+ if ((o = o.filter(Boolean)).length > 2) {
1954
+ const a = o.pop();
1955
+ n += "one of type ".concat(o.join(", "), ", or ").concat(a, ".");
1956
+ } else o.length === 2 ? n += "one of type ".concat(o[0], " or ").concat(o[1], ".") : n += "of type ".concat(o[0], ".");
1957
+ if (e == null) n += " Received ".concat(e);
1958
+ else if (typeof e == "function" && e.name) n += " Received function ".concat(e.name);
1959
+ else if (typeof e == "object" && e != null) {
1960
+ var i;
1961
+ (i = e.constructor) !== null && i !== void 0 && i.name && (n += " Received an instance of ".concat(e.constructor.name));
1962
+ }
1963
+ return n;
1964
+ }
1965
+ const Mo = function(n, e) {
1966
+ for (var t = arguments.length, o = new Array(t > 2 ? t - 2 : 0), r = 2; r < t; r++) o[r - 2] = arguments[r];
1967
+ return Wr("Key for the ".concat(n, " algorithm must be "), e, ...o);
1968
+ };
1969
+ class L extends Error {
1970
+ constructor(e, t) {
1971
+ var o;
1972
+ super(e, t), b(this, "code", "ERR_JOSE_GENERIC"), this.name = this.constructor.name, (o = Error.captureStackTrace) === null || o === void 0 || o.call(Error, this, this.constructor);
1973
+ }
1974
+ }
1975
+ b(L, "code", "ERR_JOSE_GENERIC");
1976
+ class $ extends L {
1977
+ constructor(e, t) {
1978
+ let o = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "unspecified", r = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "unspecified";
1979
+ super(e, { cause: { claim: o, reason: r, payload: t } }), b(this, "code", "ERR_JWT_CLAIM_VALIDATION_FAILED"), b(this, "claim", void 0), b(this, "reason", void 0), b(this, "payload", void 0), this.claim = o, this.reason = r, this.payload = t;
1980
+ }
1981
+ }
1982
+ b($, "code", "ERR_JWT_CLAIM_VALIDATION_FAILED");
1983
+ class Xn extends L {
1984
+ constructor(e, t) {
1985
+ let o = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : "unspecified", r = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : "unspecified";
1986
+ super(e, { cause: { claim: o, reason: r, payload: t } }), b(this, "code", "ERR_JWT_EXPIRED"), b(this, "claim", void 0), b(this, "reason", void 0), b(this, "payload", void 0), this.claim = o, this.reason = r, this.payload = t;
1987
+ }
1988
+ }
1989
+ b(Xn, "code", "ERR_JWT_EXPIRED");
1990
+ class Ur extends L {
1991
+ constructor() {
1992
+ super(...arguments), b(this, "code", "ERR_JOSE_ALG_NOT_ALLOWED");
1993
+ }
1994
+ }
1995
+ b(Ur, "code", "ERR_JOSE_ALG_NOT_ALLOWED");
1996
+ class Y extends L {
1997
+ constructor() {
1998
+ super(...arguments), b(this, "code", "ERR_JOSE_NOT_SUPPORTED");
1999
+ }
2000
+ }
2001
+ b(Y, "code", "ERR_JOSE_NOT_SUPPORTED");
2002
+ b(class extends L {
2003
+ constructor() {
2004
+ super(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "decryption operation failed", arguments.length > 1 ? arguments[1] : void 0), b(this, "code", "ERR_JWE_DECRYPTION_FAILED");
2005
+ }
2006
+ }, "code", "ERR_JWE_DECRYPTION_FAILED");
2007
+ b(class extends L {
2008
+ constructor() {
2009
+ super(...arguments), b(this, "code", "ERR_JWE_INVALID");
2010
+ }
2011
+ }, "code", "ERR_JWE_INVALID");
2012
+ class D extends L {
2013
+ constructor() {
2014
+ super(...arguments), b(this, "code", "ERR_JWS_INVALID");
2015
+ }
2016
+ }
2017
+ b(D, "code", "ERR_JWS_INVALID");
2018
+ class mo extends L {
2019
+ constructor() {
2020
+ super(...arguments), b(this, "code", "ERR_JWT_INVALID");
2021
+ }
2022
+ }
2023
+ b(mo, "code", "ERR_JWT_INVALID");
2024
+ b(class extends L {
2025
+ constructor() {
2026
+ super(...arguments), b(this, "code", "ERR_JWK_INVALID");
2027
+ }
2028
+ }, "code", "ERR_JWK_INVALID");
2029
+ class fo extends L {
2030
+ constructor() {
2031
+ super(...arguments), b(this, "code", "ERR_JWKS_INVALID");
2032
+ }
2033
+ }
2034
+ b(fo, "code", "ERR_JWKS_INVALID");
2035
+ class yo extends L {
2036
+ constructor() {
2037
+ super(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "no applicable key found in the JSON Web Key Set", arguments.length > 1 ? arguments[1] : void 0), b(this, "code", "ERR_JWKS_NO_MATCHING_KEY");
2038
+ }
2039
+ }
2040
+ b(yo, "code", "ERR_JWKS_NO_MATCHING_KEY");
2041
+ class Kr extends L {
2042
+ constructor() {
2043
+ super(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "multiple matching keys found in the JSON Web Key Set", arguments.length > 1 ? arguments[1] : void 0), b(this, Symbol.asyncIterator, void 0), b(this, "code", "ERR_JWKS_MULTIPLE_MATCHING_KEYS");
2044
+ }
2045
+ }
2046
+ b(Kr, "code", "ERR_JWKS_MULTIPLE_MATCHING_KEYS");
2047
+ class Dr extends L {
2048
+ constructor() {
2049
+ super(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "request timed out", arguments.length > 1 ? arguments[1] : void 0), b(this, "code", "ERR_JWKS_TIMEOUT");
2050
+ }
2051
+ }
2052
+ b(Dr, "code", "ERR_JWKS_TIMEOUT");
2053
+ class Nr extends L {
2054
+ constructor() {
2055
+ super(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "signature verification failed", arguments.length > 1 ? arguments[1] : void 0), b(this, "code", "ERR_JWS_SIGNATURE_VERIFICATION_FAILED");
2056
+ }
2057
+ }
2058
+ b(Nr, "code", "ERR_JWS_SIGNATURE_VERIFICATION_FAILED");
2059
+ const Lr = (n) => {
2060
+ if ((n == null ? void 0 : n[Symbol.toStringTag]) === "CryptoKey") return !0;
2061
+ try {
2062
+ return n instanceof CryptoKey;
2063
+ } catch {
2064
+ return !1;
2065
+ }
2066
+ }, zr = (n) => (n == null ? void 0 : n[Symbol.toStringTag]) === "KeyObject", Jo = (n) => Lr(n) || zr(n);
2067
+ function Zo(n, e, t) {
2068
+ try {
2069
+ return sn(n);
2070
+ } catch {
2071
+ throw new t("Failed to base64url decode the ".concat(e));
2072
+ }
2073
+ }
2074
+ function Pe(n) {
2075
+ if (typeof (e = n) != "object" || e === null || Object.prototype.toString.call(n) !== "[object Object]") return !1;
2076
+ var e;
2077
+ if (Object.getPrototypeOf(n) === null) return !0;
2078
+ let t = n;
2079
+ for (; Object.getPrototypeOf(t) !== null; ) t = Object.getPrototypeOf(t);
2080
+ return Object.getPrototypeOf(n) === t;
2081
+ }
2082
+ const Gn = (n) => Pe(n) && typeof n.kty == "string";
2083
+ async function Ta(n, e, t) {
2084
+ if (e instanceof Uint8Array) {
2085
+ if (!n.startsWith("HS")) throw new TypeError((function(o) {
2086
+ for (var r = arguments.length, i = new Array(r > 1 ? r - 1 : 0), a = 1; a < r; a++) i[a - 1] = arguments[a];
2087
+ return Wr("Key must be ", o, ...i);
2088
+ })(e, "CryptoKey", "KeyObject", "JSON Web Key"));
2089
+ return crypto.subtle.importKey("raw", e, { hash: "SHA-".concat(n.slice(-3)), name: "HMAC" }, !1, [t]);
2090
+ }
2091
+ return Sa(e, n, t), e;
2092
+ }
2093
+ async function Ea(n, e, t, o) {
2094
+ const r = await Ta(n, e, "verify");
2095
+ (function(a, s) {
2096
+ if (a.startsWith("RS") || a.startsWith("PS")) {
2097
+ const { modulusLength: c } = s.algorithm;
2098
+ if (typeof c != "number" || c < 2048) throw new TypeError("".concat(a, " requires key modulusLength to be 2048 bits or larger"));
2099
+ }
2100
+ })(n, r);
2101
+ const i = (function(a, s) {
2102
+ const c = "SHA-".concat(a.slice(-3));
2103
+ switch (a) {
2104
+ case "HS256":
2105
+ case "HS384":
2106
+ case "HS512":
2107
+ return { hash: c, name: "HMAC" };
2108
+ case "PS256":
2109
+ case "PS384":
2110
+ case "PS512":
2111
+ return { hash: c, name: "RSA-PSS", saltLength: parseInt(a.slice(-3), 10) >> 3 };
2112
+ case "RS256":
2113
+ case "RS384":
2114
+ case "RS512":
2115
+ return { hash: c, name: "RSASSA-PKCS1-v1_5" };
2116
+ case "ES256":
2117
+ case "ES384":
2118
+ case "ES512":
2119
+ return { hash: c, name: "ECDSA", namedCurve: s.namedCurve };
2120
+ case "Ed25519":
2121
+ case "EdDSA":
2122
+ return { name: "Ed25519" };
2123
+ case "ML-DSA-44":
2124
+ case "ML-DSA-65":
2125
+ case "ML-DSA-87":
2126
+ return { name: a };
2127
+ default:
2128
+ throw new Y("alg ".concat(a, " is not supported either by JOSE or your javascript runtime"));
2129
+ }
2130
+ })(n, r.algorithm);
2131
+ try {
2132
+ return await crypto.subtle.verify(i, r, t, o);
2133
+ } catch {
2134
+ return !1;
2135
+ }
2136
+ }
2137
+ const xt = 'Invalid or unsupported JWK "alg" (Algorithm) Parameter value';
2138
+ async function Ht(n) {
2139
+ var e, t;
2140
+ if (!n.alg) throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
2141
+ const { algorithm: o, keyUsages: r } = (function(a) {
2142
+ let s, c;
2143
+ switch (a.kty) {
2144
+ case "AKP":
2145
+ switch (a.alg) {
2146
+ case "ML-DSA-44":
2147
+ case "ML-DSA-65":
2148
+ case "ML-DSA-87":
2149
+ s = { name: a.alg }, c = a.priv ? ["sign"] : ["verify"];
2150
+ break;
2151
+ default:
2152
+ throw new Y(xt);
2153
+ }
2154
+ break;
2155
+ case "RSA":
2156
+ switch (a.alg) {
2157
+ case "PS256":
2158
+ case "PS384":
2159
+ case "PS512":
2160
+ s = { name: "RSA-PSS", hash: "SHA-".concat(a.alg.slice(-3)) }, c = a.d ? ["sign"] : ["verify"];
2161
+ break;
2162
+ case "RS256":
2163
+ case "RS384":
2164
+ case "RS512":
2165
+ s = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-".concat(a.alg.slice(-3)) }, c = a.d ? ["sign"] : ["verify"];
2166
+ break;
2167
+ case "RSA-OAEP":
2168
+ case "RSA-OAEP-256":
2169
+ case "RSA-OAEP-384":
2170
+ case "RSA-OAEP-512":
2171
+ s = { name: "RSA-OAEP", hash: "SHA-".concat(parseInt(a.alg.slice(-3), 10) || 1) }, c = a.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
2172
+ break;
2173
+ default:
2174
+ throw new Y(xt);
2175
+ }
2176
+ break;
2177
+ case "EC":
2178
+ switch (a.alg) {
2179
+ case "ES256":
2180
+ case "ES384":
2181
+ case "ES512":
2182
+ s = { name: "ECDSA", namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[a.alg] }, c = a.d ? ["sign"] : ["verify"];
2183
+ break;
2184
+ case "ECDH-ES":
2185
+ case "ECDH-ES+A128KW":
2186
+ case "ECDH-ES+A192KW":
2187
+ case "ECDH-ES+A256KW":
2188
+ s = { name: "ECDH", namedCurve: a.crv }, c = a.d ? ["deriveBits"] : [];
2189
+ break;
2190
+ default:
2191
+ throw new Y(xt);
2192
+ }
2193
+ break;
2194
+ case "OKP":
2195
+ switch (a.alg) {
2196
+ case "Ed25519":
2197
+ case "EdDSA":
2198
+ s = { name: "Ed25519" }, c = a.d ? ["sign"] : ["verify"];
2199
+ break;
2200
+ case "ECDH-ES":
2201
+ case "ECDH-ES+A128KW":
2202
+ case "ECDH-ES+A192KW":
2203
+ case "ECDH-ES+A256KW":
2204
+ s = { name: a.crv }, c = a.d ? ["deriveBits"] : [];
2205
+ break;
2206
+ default:
2207
+ throw new Y(xt);
2208
+ }
2209
+ break;
2210
+ default:
2211
+ throw new Y('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
2212
+ }
2213
+ return { algorithm: s, keyUsages: c };
2214
+ })(n), i = _({}, n);
2215
+ return i.kty !== "AKP" && delete i.alg, delete i.use, crypto.subtle.importKey("jwk", i, o, (e = n.ext) !== null && e !== void 0 ? e : !n.d && !n.priv, (t = n.key_ops) !== null && t !== void 0 ? t : r);
2216
+ }
2217
+ const Ze = "given KeyObject instance cannot be used for this algorithm";
2218
+ let Se;
2219
+ const Vo = async function(n, e, t) {
2220
+ let o = arguments.length > 3 && arguments[3] !== void 0 && arguments[3];
2221
+ Se || (Se = /* @__PURE__ */ new WeakMap());
2222
+ let r = Se.get(n);
2223
+ if (r != null && r[t]) return r[t];
2224
+ const i = await Ht(_(_({}, e), {}, { alg: t }));
2225
+ return o && Object.freeze(n), r ? r[t] = i : Se.set(n, { [t]: i }), i;
2226
+ };
2227
+ async function Pa(n, e) {
2228
+ if (n instanceof Uint8Array || Lr(n)) return n;
2229
+ if (zr(n)) {
2230
+ if (n.type === "secret") return n.export();
2231
+ if ("toCryptoKey" in n && typeof n.toCryptoKey == "function") try {
2232
+ return ((o, r) => {
2233
+ Se || (Se = /* @__PURE__ */ new WeakMap());
2234
+ let i = Se.get(o);
2235
+ if (i != null && i[r]) return i[r];
2236
+ const a = o.type === "public", s = !!a;
2237
+ let c;
2238
+ if (o.asymmetricKeyType === "x25519") {
2239
+ switch (r) {
2240
+ case "ECDH-ES":
2241
+ case "ECDH-ES+A128KW":
2242
+ case "ECDH-ES+A192KW":
2243
+ case "ECDH-ES+A256KW":
2244
+ break;
2245
+ default:
2246
+ throw new TypeError(Ze);
2247
+ }
2248
+ c = o.toCryptoKey(o.asymmetricKeyType, s, a ? [] : ["deriveBits"]);
2249
+ }
2250
+ if (o.asymmetricKeyType === "ed25519") {
2251
+ if (r !== "EdDSA" && r !== "Ed25519") throw new TypeError(Ze);
2252
+ c = o.toCryptoKey(o.asymmetricKeyType, s, [a ? "verify" : "sign"]);
2253
+ }
2254
+ switch (o.asymmetricKeyType) {
2255
+ case "ml-dsa-44":
2256
+ case "ml-dsa-65":
2257
+ case "ml-dsa-87":
2258
+ if (r !== o.asymmetricKeyType.toUpperCase()) throw new TypeError(Ze);
2259
+ c = o.toCryptoKey(o.asymmetricKeyType, s, [a ? "verify" : "sign"]);
2260
+ }
2261
+ if (o.asymmetricKeyType === "rsa") {
2262
+ let u;
2263
+ switch (r) {
2264
+ case "RSA-OAEP":
2265
+ u = "SHA-1";
2266
+ break;
2267
+ case "RS256":
2268
+ case "PS256":
2269
+ case "RSA-OAEP-256":
2270
+ u = "SHA-256";
2271
+ break;
2272
+ case "RS384":
2273
+ case "PS384":
2274
+ case "RSA-OAEP-384":
2275
+ u = "SHA-384";
2276
+ break;
2277
+ case "RS512":
2278
+ case "PS512":
2279
+ case "RSA-OAEP-512":
2280
+ u = "SHA-512";
2281
+ break;
2282
+ default:
2283
+ throw new TypeError(Ze);
2284
+ }
2285
+ if (r.startsWith("RSA-OAEP")) return o.toCryptoKey({ name: "RSA-OAEP", hash: u }, s, a ? ["encrypt"] : ["decrypt"]);
2286
+ c = o.toCryptoKey({ name: r.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5", hash: u }, s, [a ? "verify" : "sign"]);
2287
+ }
2288
+ if (o.asymmetricKeyType === "ec") {
2289
+ var l;
2290
+ const u = (/* @__PURE__ */ new Map([["prime256v1", "P-256"], ["secp384r1", "P-384"], ["secp521r1", "P-521"]])).get((l = o.asymmetricKeyDetails) === null || l === void 0 ? void 0 : l.namedCurve);
2291
+ if (!u) throw new TypeError(Ze);
2292
+ const p = { ES256: "P-256", ES384: "P-384", ES512: "P-521" };
2293
+ p[r] && u === p[r] && (c = o.toCryptoKey({ name: "ECDSA", namedCurve: u }, s, [a ? "verify" : "sign"])), r.startsWith("ECDH-ES") && (c = o.toCryptoKey({ name: "ECDH", namedCurve: u }, s, a ? [] : ["deriveBits"]));
2294
+ }
2295
+ if (!c) throw new TypeError(Ze);
2296
+ return i ? i[r] = c : Se.set(o, { [r]: c }), c;
2297
+ })(n, e);
2298
+ } catch (o) {
2299
+ if (o instanceof TypeError) throw o;
2300
+ }
2301
+ let t = n.export({ format: "jwk" });
2302
+ return Vo(n, t, e);
2303
+ }
2304
+ if (Gn(n)) return n.k ? sn(n.k) : Vo(n, n, e, !0);
2305
+ throw new Error("unreachable");
2306
+ }
2307
+ const Sn = (n, e) => {
2308
+ if (n.byteLength !== e.length) return !1;
2309
+ for (let t = 0; t < n.byteLength; t++) if (n[t] !== e[t]) return !1;
2310
+ return !0;
2311
+ }, pt = (n) => {
2312
+ const e = n.data[n.pos++];
2313
+ if (128 & e) {
2314
+ const t = 127 & e;
2315
+ let o = 0;
2316
+ for (let r = 0; r < t; r++) o = o << 8 | n.data[n.pos++];
2317
+ return o;
2318
+ }
2319
+ return e;
2320
+ }, mt = (n, e, t) => {
2321
+ if (n.data[n.pos++] !== e) throw new Error(t);
2322
+ }, Fo = (n, e) => {
2323
+ const t = n.data.subarray(n.pos, n.pos + e);
2324
+ return n.pos += e, t;
2325
+ }, Aa = (n) => {
2326
+ const e = ((r) => {
2327
+ mt(r, 6, "Expected algorithm OID");
2328
+ const i = pt(r);
2329
+ return Fo(r, i);
2330
+ })(n);
2331
+ if (Sn(e, [43, 101, 110])) return "X25519";
2332
+ if (!Sn(e, [42, 134, 72, 206, 61, 2, 1])) throw new Error("Unsupported key algorithm");
2333
+ mt(n, 6, "Expected curve OID");
2334
+ const t = pt(n), o = Fo(n, t);
2335
+ for (const { name: r, oid: i } of [{ name: "P-256", oid: [42, 134, 72, 206, 61, 3, 1, 7] }, { name: "P-384", oid: [43, 129, 4, 0, 34] }, { name: "P-521", oid: [43, 129, 4, 0, 35] }]) if (Sn(o, i)) return r;
2336
+ throw new Error("Unsupported named curve");
2337
+ }, Ra = async (n, e, t, o) => {
2338
+ var r;
2339
+ let i, a;
2340
+ const s = () => ["sign"];
2341
+ switch (t) {
2342
+ case "PS256":
2343
+ case "PS384":
2344
+ case "PS512":
2345
+ i = { name: "RSA-PSS", hash: "SHA-".concat(t.slice(-3)) }, a = s();
2346
+ break;
2347
+ case "RS256":
2348
+ case "RS384":
2349
+ case "RS512":
2350
+ i = { name: "RSASSA-PKCS1-v1_5", hash: "SHA-".concat(t.slice(-3)) }, a = s();
2351
+ break;
2352
+ case "RSA-OAEP":
2353
+ case "RSA-OAEP-256":
2354
+ case "RSA-OAEP-384":
2355
+ case "RSA-OAEP-512":
2356
+ i = { name: "RSA-OAEP", hash: "SHA-".concat(parseInt(t.slice(-3), 10) || 1) }, a = ["decrypt", "unwrapKey"];
2357
+ break;
2358
+ case "ES256":
2359
+ case "ES384":
2360
+ case "ES512":
2361
+ i = { name: "ECDSA", namedCurve: { ES256: "P-256", ES384: "P-384", ES512: "P-521" }[t] }, a = s();
2362
+ break;
2363
+ case "ECDH-ES":
2364
+ case "ECDH-ES+A128KW":
2365
+ case "ECDH-ES+A192KW":
2366
+ case "ECDH-ES+A256KW":
2367
+ try {
2368
+ const c = o.getNamedCurve(e);
2369
+ i = c === "X25519" ? { name: "X25519" } : { name: "ECDH", namedCurve: c };
2370
+ } catch {
2371
+ throw new Y("Invalid or unsupported key format");
2372
+ }
2373
+ a = ["deriveBits"];
2374
+ break;
2375
+ case "Ed25519":
2376
+ case "EdDSA":
2377
+ i = { name: "Ed25519" }, a = s();
2378
+ break;
2379
+ case "ML-DSA-44":
2380
+ case "ML-DSA-65":
2381
+ case "ML-DSA-87":
2382
+ i = { name: t }, a = s();
2383
+ break;
2384
+ default:
2385
+ throw new Y('Invalid or unsupported "alg" (Algorithm) value');
2386
+ }
2387
+ return crypto.subtle.importKey(n, e, i, (r = o == null ? void 0 : o.extractable) !== null && r !== void 0 ? r : !1, a);
2388
+ }, Ia = (n, e, t) => {
2389
+ var o;
2390
+ const r = ((a, s) => jr(a.replace(s, "")))(n, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
2391
+ let i = t;
2392
+ return e != null && (o = e.startsWith) !== null && o !== void 0 && o.call(e, "ECDH-ES") && (i || (i = {}), i.getNamedCurve = (a) => {
2393
+ const s = { data: a, pos: 0 };
2394
+ return (function(c) {
2395
+ mt(c, 48, "Invalid PKCS#8 structure"), pt(c), mt(c, 2, "Expected version field");
2396
+ const l = pt(c);
2397
+ c.pos += l, mt(c, 48, "Expected algorithm identifier"), pt(c);
2398
+ })(s), Aa(s);
2399
+ }), Ra("pkcs8", r, e, i);
2400
+ }, Ve = (n) => n == null ? void 0 : n[Symbol.toStringTag], Tn = (n, e, t) => {
2401
+ if (e.use !== void 0) {
2402
+ let i;
2403
+ switch (t) {
2404
+ case "sign":
2405
+ case "verify":
2406
+ i = "sig";
2407
+ break;
2408
+ case "encrypt":
2409
+ case "decrypt":
2410
+ i = "enc";
2411
+ }
2412
+ if (e.use !== i) throw new TypeError('Invalid key for this operation, its "use" must be "'.concat(i, '" when present'));
2413
+ }
2414
+ if (e.alg !== void 0 && e.alg !== n) throw new TypeError('Invalid key for this operation, its "alg" must be "'.concat(n, '" when present'));
2415
+ if (Array.isArray(e.key_ops)) {
2416
+ var o, r;
2417
+ let i;
2418
+ switch (!0) {
2419
+ case t === "verify":
2420
+ case n === "dir":
2421
+ case n.includes("CBC-HS"):
2422
+ i = t;
2423
+ break;
2424
+ case n.startsWith("PBES2"):
2425
+ i = "deriveBits";
2426
+ break;
2427
+ case /^A\d{3}(?:GCM)?(?:KW)?$/.test(n):
2428
+ i = !n.includes("GCM") && n.endsWith("KW") ? "unwrapKey" : t;
2429
+ break;
2430
+ case t === "encrypt":
2431
+ i = "wrapKey";
2432
+ break;
2433
+ case t === "decrypt":
2434
+ i = n.startsWith("RSA") ? "unwrapKey" : "deriveBits";
2435
+ }
2436
+ if (i && ((o = e.key_ops) === null || o === void 0 || (r = o.includes) === null || r === void 0 ? void 0 : r.call(o, i)) === !1) throw new TypeError('Invalid key for this operation, its "key_ops" must include "'.concat(i, '" when present'));
2437
+ }
2438
+ return !0;
2439
+ };
2440
+ function xa(n, e, t) {
2441
+ switch (n.substring(0, 2)) {
2442
+ case "A1":
2443
+ case "A2":
2444
+ case "di":
2445
+ case "HS":
2446
+ case "PB":
2447
+ ((o, r, i) => {
2448
+ if (!(r instanceof Uint8Array)) {
2449
+ if (Gn(r)) {
2450
+ if (((a) => a.kty === "oct" && typeof a.k == "string")(r) && Tn(o, r, i)) return;
2451
+ throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
2452
+ }
2453
+ if (!Jo(r)) throw new TypeError(Mo(o, r, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
2454
+ if (r.type !== "secret") throw new TypeError("".concat(Ve(r), ' instances for symmetric algorithms must be of type "secret"'));
2455
+ }
2456
+ })(n, e, t);
2457
+ break;
2458
+ default:
2459
+ ((o, r, i) => {
2460
+ if (Gn(r)) switch (i) {
2461
+ case "decrypt":
2462
+ case "sign":
2463
+ if (((a) => a.kty !== "oct" && (a.kty === "AKP" && typeof a.priv == "string" || typeof a.d == "string"))(r) && Tn(o, r, i)) return;
2464
+ throw new TypeError("JSON Web Key for this operation must be a private JWK");
2465
+ case "encrypt":
2466
+ case "verify":
2467
+ if (((a) => a.kty !== "oct" && a.d === void 0 && a.priv === void 0)(r) && Tn(o, r, i)) return;
2468
+ throw new TypeError("JSON Web Key for this operation must be a public JWK");
2469
+ }
2470
+ if (!Jo(r)) throw new TypeError(Mo(o, r, "CryptoKey", "KeyObject", "JSON Web Key"));
2471
+ if (r.type === "secret") throw new TypeError("".concat(Ve(r), ' instances for asymmetric algorithms must not be of type "secret"'));
2472
+ if (r.type === "public") switch (i) {
2473
+ case "sign":
2474
+ throw new TypeError("".concat(Ve(r), ' instances for asymmetric algorithm signing must be of type "private"'));
2475
+ case "decrypt":
2476
+ throw new TypeError("".concat(Ve(r), ' instances for asymmetric algorithm decryption must be of type "private"'));
2477
+ }
2478
+ if (r.type === "private") switch (i) {
2479
+ case "verify":
2480
+ throw new TypeError("".concat(Ve(r), ' instances for asymmetric algorithm verifying must be of type "public"'));
2481
+ case "encrypt":
2482
+ throw new TypeError("".concat(Ve(r), ' instances for asymmetric algorithm encryption must be of type "public"'));
2483
+ }
2484
+ })(n, e, t);
2485
+ }
2486
+ }
2487
+ var Ot, En;
2488
+ let le, Xo;
2489
+ (typeof navigator > "u" || (Ot = navigator.userAgent) === null || Ot === void 0 || (En = Ot.startsWith) === null || En === void 0 || !En.call(Ot, "Mozilla/5.0 ")) && (Xo = "".concat("openid-client", "/").concat("v6.8.2"), le = { "user-agent": Xo });
2490
+ const N = (n) => Mt.get(n);
2491
+ let Mt, Ct;
2492
+ function Hr(n) {
2493
+ return n !== void 0 ? Do(n) : (Ct || (Ct = /* @__PURE__ */ new WeakMap()), (e, t, o, r) => {
2494
+ let i;
2495
+ return (i = Ct.get(t)) || ((function(a, s) {
2496
+ if (typeof a != "string") throw he("".concat(s, " must be a string"), St);
2497
+ if (a.length === 0) throw he("".concat(s, " must not be empty"), _t);
2498
+ })(t.client_secret, '"metadata.client_secret"'), i = Do(t.client_secret), Ct.set(t, i)), i(e, t, o, r);
2499
+ });
2500
+ }
2501
+ const ue = ae, _t = "ERR_INVALID_ARG_VALUE", St = "ERR_INVALID_ARG_TYPE";
2502
+ function he(n, e, t) {
2503
+ const o = new TypeError(n, { cause: t });
2504
+ return Object.assign(o, { code: e }), o;
2505
+ }
2506
+ function Oa(n) {
2507
+ return (async function(e) {
2508
+ return U(e, "codeVerifier"), Ne(await crypto.subtle.digest("SHA-256", Be(e)));
2509
+ })(n);
2510
+ }
2511
+ function Ca() {
2512
+ return Tr();
2513
+ }
2514
+ class Qt extends Error {
2515
+ constructor(e, t) {
2516
+ var o;
2517
+ super(e, t), b(this, "code", void 0), this.name = this.constructor.name, this.code = t == null ? void 0 : t.code, (o = Error.captureStackTrace) === null || o === void 0 || o.call(Error, this, this.constructor);
2518
+ }
2519
+ }
2520
+ function J(n, e, t) {
2521
+ return new Qt(n, { cause: e, code: t });
2522
+ }
2523
+ function Z(n) {
2524
+ if (n instanceof TypeError || n instanceof Qt || n instanceof rn || n instanceof Er || n instanceof co) throw n;
2525
+ if (n instanceof ao) switch (n.code) {
2526
+ case xr:
2527
+ throw J("only requests to HTTPS are allowed", n, n.code);
2528
+ case Or:
2529
+ throw J("only requests to HTTP or HTTPS are allowed", n, n.code);
2530
+ case po:
2531
+ throw J("unexpected HTTP response status code", n.cause, n.code);
2532
+ case Ir:
2533
+ throw J("unexpected response content-type", n.cause, n.code);
2534
+ case Bt:
2535
+ throw J("parsing error occured", n, n.code);
2536
+ case A:
2537
+ throw J("invalid response encountered", n, n.code);
2538
+ case fe:
2539
+ throw J("unexpected JWT claim value encountered", n, n.code);
2540
+ case Fn:
2541
+ throw J("unexpected JSON attribute value encountered", n, n.code);
2542
+ case gt:
2543
+ throw J("JWT timestamp claim value failed validation", n, n.code);
2544
+ default:
2545
+ throw J(n.message, n, n.code);
2546
+ }
2547
+ if (n instanceof q) throw J("unsupported operation", n, n.code);
2548
+ if (n instanceof DOMException) switch (n.name) {
2549
+ case "OperationError":
2550
+ throw J("runtime operation error", n, Vn);
2551
+ case "NotSupportedError":
2552
+ throw J("runtime unsupported operation", n, Vn);
2553
+ case "TimeoutError":
2554
+ throw J("operation timed out", n, "OAUTH_TIMEOUT");
2555
+ case "AbortError":
2556
+ throw J("operation aborted", n, "OAUTH_ABORT");
2557
+ }
2558
+ throw new Qt("something went wrong", { cause: n });
2559
+ }
2560
+ async function ja(n, e, t, o, r) {
2561
+ const i = await (async function(c, l) {
2562
+ var u, p;
2563
+ if (!(c instanceof URL)) throw he('"server" must be an instance of URL', St);
2564
+ const h = !c.href.includes("/.well-known/"), d = (u = l == null ? void 0 : l.timeout) !== null && u !== void 0 ? u : 30, g = AbortSignal.timeout(1e3 * d), f = await (h ? qi(c, { algorithm: l == null ? void 0 : l.algorithm, [ae]: l == null ? void 0 : l[ue], [Q]: l == null || (p = l.execute) === null || p === void 0 ? void 0 : p.includes(qo), signal: g, headers: new Headers(le) }) : ((l == null ? void 0 : l[ue]) || fetch)((so(c, l == null || (m = l.execute) === null || m === void 0 || !m.includes(qo)), c.href), { headers: Object.fromEntries(new Headers(_({ accept: "application/json" }, le)).entries()), body: void 0, method: "GET", redirect: "manual", signal: g })).then((w) => (async function(k, S) {
2565
+ const T = k;
2566
+ if (!(T instanceof URL) && T !== bn) throw x('"expectedIssuerIdentifier" must be an instance of URL', X);
2567
+ if (!ot(S, Response)) throw x('"response" must be an instance of Response', X);
2568
+ if (S.status !== 200) throw E('"response" is not a conform Authorization Server Metadata response (unexpected HTTP status code)', po, S);
2569
+ kt(S);
2570
+ const v = await an(S);
2571
+ if (U(v.issuer, '"response" body "issuer" property', A, { body: v }), T !== bn && new URL(v.issuer).href !== T.href) throw E('"response" body "issuer" property does not match the expected value', Fn, { expected: T.href, body: v, attribute: "issuer" });
2572
+ return v;
2573
+ })(bn, w)).catch(Z);
2574
+ var m;
2575
+ return h && new URL(f.issuer).href !== c.href && ((function(w, k, S) {
2576
+ return !(w.origin !== "https://login.microsoftonline.com" || S != null && S.algorithm && S.algorithm !== "oidc" || (k[Mr] = !0, 0));
2577
+ })(c, f, l) || (function(w, k) {
2578
+ return !(!w.hostname.endsWith(".b2clogin.com") || k != null && k.algorithm && k.algorithm !== "oidc");
2579
+ })(c, l) || (() => {
2580
+ throw new Qt("discovered metadata issuer does not match the expected issuer", { code: Fn, cause: { expected: c.href, body: f, attribute: "issuer" } });
2581
+ })()), f;
2582
+ })(n, r), a = new tt(i, e, t, o);
2583
+ let s = N(a);
2584
+ if (r != null && r[ue] && (s.fetch = r[ue]), r != null && r.timeout && (s.timeout = r.timeout), r != null && r.execute) for (const c of r.execute) c(a);
2585
+ return a;
2586
+ }
2587
+ new TextDecoder();
2588
+ const Mr = Symbol();
2589
+ class tt {
2590
+ constructor(e, t, o, r) {
2591
+ var i, a, s, c, l;
2592
+ if (typeof t != "string" || !t.length) throw he('"clientId" must be a non-empty string', St);
2593
+ if (typeof o == "string" && (o = { client_secret: o }), ((i = o) === null || i === void 0 ? void 0 : i.client_id) !== void 0 && t !== o.client_id) throw he('"clientId" and "metadata.client_id" must be the same', _t);
2594
+ const u = _(_({}, structuredClone(o)), {}, { client_id: t });
2595
+ let p;
2596
+ u[zn] = (a = (s = o) === null || s === void 0 ? void 0 : s[zn]) !== null && a !== void 0 ? a : 0, u[Hn] = (c = (l = o) === null || l === void 0 ? void 0 : l[Hn]) !== null && c !== void 0 ? c : 30, p = r || (typeof u.client_secret == "string" && u.client_secret.length ? Hr(u.client_secret) : (f, m, w, k) => {
2597
+ w.set("client_id", m.client_id);
2598
+ });
2599
+ let h = Object.freeze(u);
2600
+ const d = structuredClone(e);
2601
+ Mr in e && (d[Cr] = (f) => {
2602
+ let { claims: { tid: m } } = f;
2603
+ return e.issuer.replace("{tenantid}", m);
2604
+ });
2605
+ let g = Object.freeze(d);
2606
+ Mt || (Mt = /* @__PURE__ */ new WeakMap()), Mt.set(this, { __proto__: null, as: g, c: h, auth: p, tlsOnly: !0, jwksCache: {} });
2607
+ }
2608
+ serverMetadata() {
2609
+ const e = structuredClone(N(this).as);
2610
+ return (function(t) {
2611
+ Object.defineProperties(t, /* @__PURE__ */ (function(o) {
2612
+ return { supportsPKCE: { __proto__: null, value() {
2613
+ var r;
2614
+ let i = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "S256";
2615
+ return ((r = o.code_challenge_methods_supported) === null || r === void 0 ? void 0 : r.includes(i)) === !0;
2616
+ } } };
2617
+ })(t));
2618
+ })(e), e;
2619
+ }
2620
+ clientMetadata() {
2621
+ return structuredClone(N(this).c);
2622
+ }
2623
+ get timeout() {
2624
+ return N(this).timeout;
2625
+ }
2626
+ set timeout(e) {
2627
+ N(this).timeout = e;
2628
+ }
2629
+ get [ue]() {
2630
+ return N(this).fetch;
2631
+ }
2632
+ set [ue](e) {
2633
+ N(this).fetch = e;
2634
+ }
2635
+ }
2636
+ function Tt(n) {
2637
+ Object.defineProperties(n, (function(e) {
2638
+ let t;
2639
+ if (e.expires_in !== void 0) {
2640
+ const o = /* @__PURE__ */ new Date();
2641
+ o.setSeconds(o.getSeconds() + e.expires_in), t = o.getTime();
2642
+ }
2643
+ return { expiresIn: { __proto__: null, value() {
2644
+ if (t) {
2645
+ const o = Date.now();
2646
+ return t > o ? Math.floor((t - o) / 1e3) : 0;
2647
+ }
2648
+ } }, claims: { __proto__: null, value() {
2649
+ try {
2650
+ return Zn(this);
2651
+ } catch {
2652
+ return;
2653
+ }
2654
+ } } };
2655
+ })(n));
2656
+ }
2657
+ async function Go(n, e, t) {
2658
+ var o;
2659
+ let r = arguments.length > 3 && arguments[3] !== void 0 && arguments[3];
2660
+ const i = (o = n.headers.get("retry-after")) === null || o === void 0 ? void 0 : o.trim();
2661
+ if (i === void 0) return;
2662
+ let a;
2663
+ if (/^\d+$/.test(i)) a = parseInt(i, 10);
2664
+ else {
2665
+ const s = new Date(i);
2666
+ if (Number.isFinite(s.getTime())) {
2667
+ const c = /* @__PURE__ */ new Date(), l = s.getTime() - c.getTime();
2668
+ l > 0 && (a = Math.ceil(l / 1e3));
2669
+ }
2670
+ }
2671
+ if (r && !Number.isFinite(a)) throw new ao("invalid Retry-After header value", { cause: n });
2672
+ a > e && await Jr(a - e, t);
2673
+ }
2674
+ function Jr(n, e) {
2675
+ return new Promise((t, o) => {
2676
+ const r = (i) => {
2677
+ try {
2678
+ e.throwIfAborted();
2679
+ } catch (s) {
2680
+ return void o(s);
2681
+ }
2682
+ if (i <= 0) return void t();
2683
+ const a = Math.min(i, 5);
2684
+ setTimeout(() => r(i - a), 1e3 * a);
2685
+ };
2686
+ r(n);
2687
+ });
2688
+ }
2689
+ async function Yo(n, e) {
2690
+ ge(n);
2691
+ const { as: t, c: o, auth: r, fetch: i, tlsOnly: a, timeout: s } = N(n);
2692
+ return (async function(c, l, u, p, h) {
2693
+ re(c), ie(l);
2694
+ const d = vt(c, "backchannel_authentication_endpoint", l.use_mtls_endpoint_aliases, (h == null ? void 0 : h[Q]) !== !0), g = new URLSearchParams(p);
2695
+ g.set("client_id", l.client_id);
2696
+ const f = on(h == null ? void 0 : h.headers);
2697
+ return f.set("accept", "application/json"), lo(c, l, u, d, g, f, h);
2698
+ })(t, o, r, e, { [ae]: i, [Q]: !a, headers: new Headers(le), signal: ze(s) }).then((c) => (async function(l, u, p) {
2699
+ if (re(l), ie(u), !ot(p, Response)) throw x('"response" must be an instance of Response', X);
2700
+ await uo(p, 200, "Backchannel Authentication Endpoint"), kt(p);
2701
+ const h = await an(p);
2702
+ U(h.auth_req_id, '"response" body "auth_req_id" property', A, { body: h });
2703
+ let d = typeof h.expires_in != "number" ? parseFloat(h.expires_in) : h.expires_in;
2704
+ return Te(d, !0, '"response" body "expires_in" property', A, { body: h }), h.expires_in = d, h.interval !== void 0 && Te(h.interval, !1, '"response" body "interval" property', A, { body: h }), h;
2705
+ })(t, o, c)).catch(Z);
2706
+ }
2707
+ async function Zr(n, e, t, o) {
2708
+ var r, i;
2709
+ ge(n), t = new URLSearchParams(t);
2710
+ let a = (r = e.interval) !== null && r !== void 0 ? r : 5;
2711
+ const s = (i = o == null ? void 0 : o.signal) !== null && i !== void 0 ? i : AbortSignal.timeout(1e3 * e.expires_in);
2712
+ try {
2713
+ await Jr(a, s);
2714
+ } catch (v) {
2715
+ Z(v);
2716
+ }
2717
+ const { as: c, c: l, auth: u, fetch: p, tlsOnly: h, nonRepudiation: d, timeout: g, decrypt: f } = N(n), m = (v, R) => Zr(n, _(_({}, e), {}, { interval: v }), t, _(_({}, o), {}, { signal: s, flag: R })), w = await (async function(v, R, z, K, we) {
2718
+ re(v), ie(R), U(K, '"authReqId"');
2719
+ const V = new URLSearchParams(we == null ? void 0 : we.additionalParameters);
2720
+ return V.set("auth_req_id", K), bt(v, R, z, "urn:openid:params:grant-type:ciba", V, we);
2721
+ })(c, l, u, e.auth_req_id, { [ae]: p, [Q]: !h, additionalParameters: t, DPoP: o == null ? void 0 : o.DPoP, headers: new Headers(le), signal: s.aborted ? s : ze(g) }).catch(Z);
2722
+ var k;
2723
+ if (w.status === 503 && w.headers.has("retry-after")) return await Go(w, a, s, !0), await ((k = w.body) === null || k === void 0 ? void 0 : k.cancel()), m(a);
2724
+ const S = (async function(v, R, z, K) {
2725
+ return et(v, R, z, void 0, K == null ? void 0 : K[ye], K == null ? void 0 : K.recognizedTokenTypes);
2726
+ })(c, l, w, { [ye]: f });
2727
+ let T;
2728
+ try {
2729
+ T = await S;
2730
+ } catch (v) {
2731
+ if (Et(v, o)) return m(a, Ee);
2732
+ if (v instanceof rn) switch (v.error) {
2733
+ case "slow_down":
2734
+ a += 5;
2735
+ case "authorization_pending":
2736
+ return await Go(v.response, a, s), m(a);
2737
+ }
2738
+ Z(v);
2739
+ }
2740
+ return T.id_token && await (d == null ? void 0 : d(w)), Tt(T), T;
2741
+ }
2742
+ function qo(n) {
2743
+ N(n).tlsOnly = !1;
2744
+ }
2745
+ async function Vr(n, e, t, o, r) {
2746
+ if (ge(n), !((r == null ? void 0 : r.flag) === Ee || e instanceof URL || (function(v, R) {
2747
+ try {
2748
+ return Object.getPrototypeOf(v)[Symbol.toStringTag] === R;
2749
+ } catch {
2750
+ return !1;
2751
+ }
2752
+ })(e, "Request"))) throw he('"currentUrl" must be an instance of URL, or Request', St);
2753
+ let i, a;
2754
+ const { as: s, c, auth: l, fetch: u, tlsOnly: p, jarm: h, hybrid: d, nonRepudiation: g, timeout: f, decrypt: m, implicit: w } = N(n);
2755
+ if ((r == null ? void 0 : r.flag) === Ee) i = r.authResponse, a = r.redirectUri;
2756
+ else {
2757
+ if (!(e instanceof URL)) {
2758
+ const v = e;
2759
+ switch (e = new URL(e.url), v.method) {
2760
+ case "GET":
2761
+ break;
2762
+ case "POST":
2763
+ const R = new URLSearchParams(await wa(v));
2764
+ if (d) e.hash = R.toString();
2765
+ else for (const [z, K] of R.entries()) e.searchParams.append(z, K);
2766
+ break;
2767
+ default:
2768
+ throw he("unexpected Request HTTP method", _t);
2769
+ }
2770
+ }
2771
+ switch (a = (function(v) {
2772
+ return (v = new URL(v)).search = "", v.hash = "", v.href;
2773
+ })(e), !0) {
2774
+ case !!h:
2775
+ i = await h(e, t == null ? void 0 : t.expectedState);
2776
+ break;
2777
+ case !!d:
2778
+ i = await d(e, t == null ? void 0 : t.expectedNonce, t == null ? void 0 : t.expectedState, t == null ? void 0 : t.maxAge);
2779
+ break;
2780
+ case !!w:
2781
+ throw new TypeError("authorizationCodeGrant() cannot be used by response_type=id_token clients");
2782
+ default:
2783
+ try {
2784
+ i = _a(s, c, e.searchParams, t == null ? void 0 : t.expectedState);
2785
+ } catch (v) {
2786
+ Z(v);
2787
+ }
2788
+ }
2789
+ }
2790
+ const k = await (async function(v, R, z, K, we, V, He) {
2791
+ if (re(v), ie(R), !ho.has(K)) throw x('"callbackParameters" must be an instance of URLSearchParams obtained from "validateAuthResponse()", or "validateJwtAuthResponse()', M);
2792
+ U(we, '"redirectUri"');
2793
+ const ko = We(K, "code");
2794
+ if (!ko) throw E('no authorization code in "callbackParameters"', A);
2795
+ const Pt = new URLSearchParams(He == null ? void 0 : He.additionalParameters);
2796
+ return Pt.set("redirect_uri", we), Pt.set("code", ko), V !== Lo && (U(V, '"codeVerifier"'), Pt.set("code_verifier", V)), bt(v, R, z, "authorization_code", Pt, He);
2797
+ })(s, c, l, i, a, (t == null ? void 0 : t.pkceCodeVerifier) || Lo, { additionalParameters: o, [ae]: u, [Q]: !p, DPoP: r == null ? void 0 : r.DPoP, headers: new Headers(le), signal: ze(f) }).catch(Z);
2798
+ typeof (t == null ? void 0 : t.expectedNonce) != "string" && typeof (t == null ? void 0 : t.maxAge) != "number" || (t.idTokenExpected = !0);
2799
+ const S = ha(s, c, k, { expectedNonce: t == null ? void 0 : t.expectedNonce, maxAge: t == null ? void 0 : t.maxAge, requireIdToken: t == null ? void 0 : t.idTokenExpected, [ye]: m });
2800
+ let T;
2801
+ try {
2802
+ T = await S;
2803
+ } catch (v) {
2804
+ if (Et(v, r)) return Vr(n, void 0, t, o, _(_({}, r), {}, { flag: Ee, authResponse: i, redirectUri: a }));
2805
+ Z(v);
2806
+ }
2807
+ return T.id_token && await (g == null ? void 0 : g(k)), Tt(T), T;
2808
+ }
2809
+ async function Fr(n, e, t, o) {
2810
+ ge(n), t = new URLSearchParams(t);
2811
+ const { as: r, c: i, auth: a, fetch: s, tlsOnly: c, nonRepudiation: l, timeout: u, decrypt: p } = N(n), h = await (async function(f, m, w, k, S) {
2812
+ re(f), ie(m), U(k, '"refreshToken"');
2813
+ const T = new URLSearchParams(S == null ? void 0 : S.additionalParameters);
2814
+ return T.set("refresh_token", k), bt(f, m, w, "refresh_token", T, S);
2815
+ })(r, i, a, e, { [ae]: s, [Q]: !c, additionalParameters: t, DPoP: o == null ? void 0 : o.DPoP, headers: new Headers(le), signal: ze(u) }).catch(Z), d = (async function(f, m, w, k) {
2816
+ return et(f, m, w, void 0, k == null ? void 0 : k[ye], k == null ? void 0 : k.recognizedTokenTypes);
2817
+ })(r, i, h, { [ye]: p });
2818
+ let g;
2819
+ try {
2820
+ g = await d;
2821
+ } catch (f) {
2822
+ if (Et(f, o)) return Fr(n, e, t, _(_({}, o), {}, { flag: Ee }));
2823
+ Z(f);
2824
+ }
2825
+ return g.id_token && await (l == null ? void 0 : l(h)), Tt(g), g;
2826
+ }
2827
+ async function Xr(n, e, t) {
2828
+ ge(n), e = new URLSearchParams(e);
2829
+ const { as: o, c: r, auth: i, fetch: a, tlsOnly: s, timeout: c } = N(n), l = await (async function(h, d, g, f, m) {
2830
+ return re(h), ie(d), bt(h, d, g, "client_credentials", new URLSearchParams(f), m);
2831
+ })(o, r, i, e, { [ae]: a, [Q]: !s, DPoP: t == null ? void 0 : t.DPoP, headers: new Headers(le), signal: ze(c) }).catch(Z), u = (async function(h, d, g, f) {
2832
+ return et(h, d, g, void 0, void 0, void 0);
2833
+ })(o, r, l);
2834
+ let p;
2835
+ try {
2836
+ p = await u;
2837
+ } catch (h) {
2838
+ if (Et(h, t)) return Xr(n, e, _(_({}, t), {}, { flag: Ee }));
2839
+ Z(h);
2840
+ }
2841
+ return Tt(p), p;
2842
+ }
2843
+ function Yn(n, e) {
2844
+ ge(n);
2845
+ const { as: t, c: o, tlsOnly: r, hybrid: i, jarm: a, implicit: s } = N(n), c = vt(t, "authorization_endpoint", !1, r);
2846
+ if ((e = new URLSearchParams(e)).has("client_id") || e.set("client_id", o.client_id), !e.has("request_uri") && !e.has("request")) {
2847
+ if (e.has("response_type") || e.set("response_type", i ? "code id_token" : s ? "id_token" : "code"), s && !e.has("nonce")) throw he("response_type=id_token clients must provide a nonce parameter in their authorization request parameters", _t);
2848
+ a && e.set("response_mode", "jwt");
2849
+ }
2850
+ for (const [l, u] of e.entries()) c.searchParams.append(l, u);
2851
+ return c;
2852
+ }
2853
+ async function Gr(n, e, t) {
2854
+ ge(n);
2855
+ const o = Yn(n, e), { as: r, c: i, auth: a, fetch: s, tlsOnly: c, timeout: l } = N(n), u = await (async function(d, g, f, m, w) {
2856
+ var k;
2857
+ re(d), ie(g);
2858
+ const S = vt(d, "pushed_authorization_request_endpoint", g.use_mtls_endpoint_aliases, (w == null ? void 0 : w[Q]) !== !0), T = new URLSearchParams(m);
2859
+ T.set("client_id", g.client_id);
2860
+ const v = on(w == null ? void 0 : w.headers);
2861
+ v.set("accept", "application/json"), (w == null ? void 0 : w.DPoP) !== void 0 && (Pr(w.DPoP), await w.DPoP.addProof(S, v, "POST"));
2862
+ const R = await lo(d, g, f, S, T, v, w);
2863
+ return w == null || (k = w.DPoP) === null || k === void 0 || k.cacheNonce(R, S), R;
2864
+ })(r, i, a, o.searchParams, { [ae]: s, [Q]: !c, DPoP: t == null ? void 0 : t.DPoP, headers: new Headers(le), signal: ze(l) }).catch(Z), p = (async function(d, g, f) {
2865
+ if (re(d), ie(g), !ot(f, Response)) throw x('"response" must be an instance of Response', X);
2866
+ await uo(f, 201, "Pushed Authorization Request Endpoint"), kt(f);
2867
+ const m = await an(f);
2868
+ U(m.request_uri, '"response" body "request_uri" property', A, { body: m });
2869
+ let w = typeof m.expires_in != "number" ? parseFloat(m.expires_in) : m.expires_in;
2870
+ return Te(w, !0, '"response" body "expires_in" property', A, { body: m }), m.expires_in = w, m;
2871
+ })(r, i, u);
2872
+ let h;
2873
+ try {
2874
+ h = await p;
2875
+ } catch (d) {
2876
+ if (Et(d, t)) return Gr(n, e, _(_({}, t), {}, { flag: Ee }));
2877
+ Z(d);
2878
+ }
2879
+ return Yn(n, { request_uri: h.request_uri });
2880
+ }
2881
+ function ge(n) {
2882
+ if (!(n instanceof tt)) throw he('"config" must be an instance of Configuration', St);
2883
+ if (Object.getPrototypeOf(n) !== tt.prototype) throw he("subclassing Configuration is not allowed", _t);
2884
+ }
2885
+ function ze(n) {
2886
+ return n ? AbortSignal.timeout(1e3 * n) : void 0;
2887
+ }
2888
+ function Et(n, e) {
2889
+ return !(e == null || !e.DPoP || e.flag === Ee) && (function(t) {
2890
+ if (t instanceof co) {
2891
+ const { 0: o, length: r } = t.cause;
2892
+ return r === 1 && o.scheme === "dpop" && o.parameters.error === "use_dpop_nonce";
2893
+ }
2894
+ return t instanceof rn && t.error === "use_dpop_nonce";
2895
+ })(n);
2896
+ }
2897
+ Object.freeze(tt.prototype);
2898
+ const Ee = Symbol();
2899
+ async function $t(n, e, t, o) {
2900
+ ge(n);
2901
+ const { as: r, c: i, auth: a, fetch: s, tlsOnly: c, timeout: l, decrypt: u } = N(n), p = await (async function(h, d, g, f, m, w) {
2902
+ return re(h), ie(d), U(f, '"grantType"'), bt(h, d, g, f, new URLSearchParams(m), w);
2903
+ })(r, i, a, e, new URLSearchParams(t), { [ae]: s, [Q]: !c, DPoP: void 0, headers: new Headers(le), signal: ze(l) }).then((h) => {
2904
+ let d;
2905
+ return e === "urn:ietf:params:oauth:grant-type:token-exchange" && (d = { n_a: () => {
2906
+ } }), (async function(g, f, m, w) {
2907
+ return et(g, f, m, void 0, w == null ? void 0 : w[ye], w == null ? void 0 : w.recognizedTokenTypes);
2908
+ })(r, i, h, { [ye]: u, recognizedTokenTypes: d });
2909
+ }).catch(Z);
2910
+ return Tt(p), p;
2911
+ }
2912
+ async function Wa(n, e, t) {
2913
+ if (!Pe(n)) throw new D("Flattened JWS must be an object");
2914
+ if (n.protected === void 0 && n.header === void 0) throw new D('Flattened JWS must have either of the "protected" or "header" members');
2915
+ if (n.protected !== void 0 && typeof n.protected != "string") throw new D("JWS Protected Header incorrect type");
2916
+ if (n.payload === void 0) throw new D("JWS Payload missing");
2917
+ if (typeof n.signature != "string") throw new D("JWS Signature missing or incorrect type");
2918
+ if (n.header !== void 0 && !Pe(n.header)) throw new D("JWS Unprotected Header incorrect type");
2919
+ let o = {};
2920
+ if (n.protected) try {
2921
+ const f = sn(n.protected);
2922
+ o = JSON.parse(wt.decode(f));
2923
+ } catch {
2924
+ throw new D("JWS Protected Header is invalid");
2925
+ }
2926
+ if (!(function() {
2927
+ for (var f = arguments.length, m = new Array(f), w = 0; w < f; w++) m[w] = arguments[w];
2928
+ const k = m.filter(Boolean);
2929
+ if (k.length === 0 || k.length === 1) return !0;
2930
+ let S;
2931
+ for (const T of k) {
2932
+ const v = Object.keys(T);
2933
+ if (S && S.size !== 0) for (const R of v) {
2934
+ if (S.has(R)) return !1;
2935
+ S.add(R);
2936
+ }
2937
+ else S = new Set(v);
2938
+ }
2939
+ return !0;
2940
+ })(o, n.header)) throw new D("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
2941
+ const r = _(_({}, o), n.header), i = (function(f, m, w, k, S) {
2942
+ if (S.crit !== void 0 && (k == null ? void 0 : k.crit) === void 0) throw new f('"crit" (Critical) Header Parameter MUST be integrity protected');
2943
+ if (!k || k.crit === void 0) return /* @__PURE__ */ new Set();
2944
+ if (!Array.isArray(k.crit) || k.crit.length === 0 || k.crit.some((v) => typeof v != "string" || v.length === 0)) throw new f('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
2945
+ let T;
2946
+ T = w !== void 0 ? new Map([...Object.entries(w), ...m.entries()]) : m;
2947
+ for (const v of k.crit) {
2948
+ if (!T.has(v)) throw new Y('Extension Header Parameter "'.concat(v, '" is not recognized'));
2949
+ if (S[v] === void 0) throw new f('Extension Header Parameter "'.concat(v, '" is missing'));
2950
+ if (T.get(v) && k[v] === void 0) throw new f('Extension Header Parameter "'.concat(v, '" MUST be integrity protected'));
2951
+ }
2952
+ return new Set(k.crit);
2953
+ })(D, /* @__PURE__ */ new Map([["b64", !0]]), t == null ? void 0 : t.crit, o, r);
2954
+ let a = !0;
2955
+ if (i.has("b64") && (a = o.b64, typeof a != "boolean")) throw new D('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
2956
+ const { alg: s } = r;
2957
+ if (typeof s != "string" || !s) throw new D('JWS "alg" (Algorithm) Header Parameter missing or invalid');
2958
+ const c = t && (function(f, m) {
2959
+ if (m !== void 0 && (!Array.isArray(m) || m.some((w) => typeof w != "string"))) throw new TypeError('"'.concat(f, '" option must be an array of strings'));
2960
+ if (m) return new Set(m);
2961
+ })("algorithms", t.algorithms);
2962
+ if (c && !c.has(s)) throw new Ur('"alg" (Algorithm) Header Parameter value not allowed');
2963
+ if (a) {
2964
+ if (typeof n.payload != "string") throw new D("JWS Payload must be a string");
2965
+ } else if (typeof n.payload != "string" && !(n.payload instanceof Uint8Array)) throw new D("JWS Payload must be a string or an Uint8Array instance");
2966
+ let l = !1;
2967
+ typeof e == "function" && (e = await e(o, n), l = !0), xa(s, e, "verify");
2968
+ const u = (function() {
2969
+ for (var f = arguments.length, m = new Array(f), w = 0; w < f; w++) m[w] = arguments[w];
2970
+ const k = m.reduce((v, R) => {
2971
+ let { length: z } = R;
2972
+ return v + z;
2973
+ }, 0), S = new Uint8Array(k);
2974
+ let T = 0;
2975
+ for (const v of m) S.set(v, T), T += v.length;
2976
+ return S;
2977
+ })(n.protected !== void 0 ? kn(n.protected) : new Uint8Array(), kn("."), typeof n.payload == "string" ? a ? kn(n.payload) : Ho.encode(n.payload) : n.payload), p = Zo(n.signature, "signature", D), h = await Pa(e, s);
2978
+ if (!await Ea(s, h, p, u)) throw new Nr();
2979
+ let d;
2980
+ d = a ? Zo(n.payload, "payload", D) : typeof n.payload == "string" ? Ho.encode(n.payload) : n.payload;
2981
+ const g = { payload: d };
2982
+ return n.protected !== void 0 && (g.protectedHeader = o), n.header !== void 0 && (g.unprotectedHeader = n.header), l ? _(_({}, g), {}, { key: h }) : g;
2983
+ }
2984
+ const Ua = 86400, Ka = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
2985
+ function Bo(n) {
2986
+ const e = Ka.exec(n);
2987
+ if (!e || e[4] && e[1]) throw new TypeError("Invalid time period format");
2988
+ const t = parseFloat(e[2]);
2989
+ let o;
2990
+ switch (e[3].toLowerCase()) {
2991
+ case "sec":
2992
+ case "secs":
2993
+ case "second":
2994
+ case "seconds":
2995
+ case "s":
2996
+ o = Math.round(t);
2997
+ break;
2998
+ case "minute":
2999
+ case "minutes":
3000
+ case "min":
3001
+ case "mins":
3002
+ case "m":
3003
+ o = Math.round(60 * t);
3004
+ break;
3005
+ case "hour":
3006
+ case "hours":
3007
+ case "hr":
3008
+ case "hrs":
3009
+ case "h":
3010
+ o = Math.round(3600 * t);
3011
+ break;
3012
+ case "day":
3013
+ case "days":
3014
+ case "d":
3015
+ o = Math.round(t * Ua);
3016
+ break;
3017
+ case "week":
3018
+ case "weeks":
3019
+ case "w":
3020
+ o = Math.round(604800 * t);
3021
+ break;
3022
+ default:
3023
+ o = Math.round(31557600 * t);
3024
+ }
3025
+ return e[1] === "-" || e[4] === "ago" ? -o : o;
3026
+ }
3027
+ const Qo = (n) => n.includes("/") ? n.toLowerCase() : "application/".concat(n.toLowerCase());
3028
+ function Da(n, e) {
3029
+ let t, o = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
3030
+ try {
3031
+ t = JSON.parse(wt.decode(e));
3032
+ } catch {
3033
+ }
3034
+ if (!Pe(t)) throw new mo("JWT Claims Set must be a top-level JSON object");
3035
+ const { typ: r } = o;
3036
+ if (r && (typeof n.typ != "string" || Qo(n.typ) !== Qo(r))) throw new $('unexpected "typ" JWT header value', t, "typ", "check_failed");
3037
+ const { requiredClaims: i = [], issuer: a, subject: s, audience: c, maxTokenAge: l } = o, u = [...i];
3038
+ l !== void 0 && u.push("iat"), c !== void 0 && u.push("aud"), s !== void 0 && u.push("sub"), a !== void 0 && u.push("iss");
3039
+ for (const w of new Set(u.reverse())) if (!(w in t)) throw new $('missing required "'.concat(w, '" claim'), t, w, "missing");
3040
+ if (a && !(Array.isArray(a) ? a : [a]).includes(t.iss)) throw new $('unexpected "iss" claim value', t, "iss", "check_failed");
3041
+ if (s && t.sub !== s) throw new $('unexpected "sub" claim value', t, "sub", "check_failed");
3042
+ if (c && (p = t.aud, h = typeof c == "string" ? [c] : c, !(typeof p == "string" ? h.includes(p) : Array.isArray(p) && h.some(Set.prototype.has.bind(new Set(p)))))) throw new $('unexpected "aud" claim value', t, "aud", "check_failed");
3043
+ var p, h;
3044
+ let d;
3045
+ switch (typeof o.clockTolerance) {
3046
+ case "string":
3047
+ d = Bo(o.clockTolerance);
3048
+ break;
3049
+ case "number":
3050
+ d = o.clockTolerance;
3051
+ break;
3052
+ case "undefined":
3053
+ d = 0;
3054
+ break;
3055
+ default:
3056
+ throw new TypeError("Invalid clockTolerance option type");
3057
+ }
3058
+ const { currentDate: g } = o, f = (m = g || /* @__PURE__ */ new Date(), Math.floor(m.getTime() / 1e3));
3059
+ var m;
3060
+ if ((t.iat !== void 0 || l) && typeof t.iat != "number") throw new $('"iat" claim must be a number', t, "iat", "invalid");
3061
+ if (t.nbf !== void 0) {
3062
+ if (typeof t.nbf != "number") throw new $('"nbf" claim must be a number', t, "nbf", "invalid");
3063
+ if (t.nbf > f + d) throw new $('"nbf" claim timestamp check failed', t, "nbf", "check_failed");
3064
+ }
3065
+ if (t.exp !== void 0) {
3066
+ if (typeof t.exp != "number") throw new $('"exp" claim must be a number', t, "exp", "invalid");
3067
+ if (t.exp <= f - d) throw new Xn('"exp" claim timestamp check failed', t, "exp", "check_failed");
3068
+ }
3069
+ if (l) {
3070
+ const w = f - t.iat;
3071
+ if (w - d > (typeof l == "number" ? l : Bo(l))) throw new Xn('"iat" claim timestamp check failed (too far in the past)', t, "iat", "check_failed");
3072
+ if (w < 0 - d) throw new $('"iat" claim timestamp check failed (it should be in the past)', t, "iat", "check_failed");
3073
+ }
3074
+ return t;
3075
+ }
3076
+ async function Na(n, e, t) {
3077
+ var o;
3078
+ const r = await (async function(a, s, c) {
3079
+ if (a instanceof Uint8Array && (a = wt.decode(a)), typeof a != "string") throw new D("Compact JWS must be a string or Uint8Array");
3080
+ const { 0: l, 1: u, 2: p, length: h } = a.split(".");
3081
+ if (h !== 3) throw new D("Invalid Compact JWS");
3082
+ const d = await Wa({ payload: u, protected: l, signature: p }, s, c), g = { payload: d.payload, protectedHeader: d.protectedHeader };
3083
+ return typeof s == "function" ? _(_({}, g), {}, { key: d.key }) : g;
3084
+ })(n, e, t);
3085
+ if ((o = r.protectedHeader.crit) !== null && o !== void 0 && o.includes("b64") && r.protectedHeader.b64 === !1) throw new mo("JWTs MUST NOT use unencoded payload");
3086
+ const i = { payload: Da(r.protectedHeader, r.payload, t), protectedHeader: r.protectedHeader };
3087
+ return typeof e == "function" ? _(_({}, i), {}, { key: r.key }) : i;
3088
+ }
3089
+ function La(n) {
3090
+ return Pe(n);
3091
+ }
3092
+ var jt, Pn, Wt = /* @__PURE__ */ new WeakMap(), An = /* @__PURE__ */ new WeakMap();
3093
+ class za {
3094
+ constructor(e) {
3095
+ if (W(this, Wt, void 0), W(this, An, /* @__PURE__ */ new WeakMap()), !(function(t) {
3096
+ return t && typeof t == "object" && Array.isArray(t.keys) && t.keys.every(La);
3097
+ })(e)) throw new fo("JSON Web Key Set malformed");
3098
+ P(Wt, this, structuredClone(e));
3099
+ }
3100
+ jwks() {
3101
+ return y(Wt, this);
3102
+ }
3103
+ async getKey(e, t) {
3104
+ const { alg: o, kid: r } = _(_({}, e), t == null ? void 0 : t.header), i = (function(l) {
3105
+ switch (typeof l == "string" && l.slice(0, 2)) {
3106
+ case "RS":
3107
+ case "PS":
3108
+ return "RSA";
3109
+ case "ES":
3110
+ return "EC";
3111
+ case "Ed":
3112
+ return "OKP";
3113
+ case "ML":
3114
+ return "AKP";
3115
+ default:
3116
+ throw new Y('Unsupported "alg" value for a JSON Web Key Set');
3117
+ }
3118
+ })(o), a = y(Wt, this).keys.filter((l) => {
3119
+ let u = i === l.kty;
3120
+ if (u && typeof r == "string" && (u = r === l.kid), !u || typeof l.alg != "string" && i !== "AKP" || (u = o === l.alg), u && typeof l.use == "string" && (u = l.use === "sig"), u && Array.isArray(l.key_ops) && (u = l.key_ops.includes("verify")), u) switch (o) {
3121
+ case "ES256":
3122
+ u = l.crv === "P-256";
3123
+ break;
3124
+ case "ES384":
3125
+ u = l.crv === "P-384";
3126
+ break;
3127
+ case "ES512":
3128
+ u = l.crv === "P-521";
3129
+ break;
3130
+ case "Ed25519":
3131
+ case "EdDSA":
3132
+ u = l.crv === "Ed25519";
3133
+ }
3134
+ return u;
3135
+ }), { 0: s, length: c } = a;
3136
+ if (c === 0) throw new yo();
3137
+ if (c !== 1) {
3138
+ const l = new Kr(), u = y(An, this);
3139
+ throw l[Symbol.asyncIterator] = Fi(function* () {
3140
+ for (const p of a) try {
3141
+ yield yield Vi($o(u, p, o));
3142
+ } catch {
3143
+ }
3144
+ }), l;
3145
+ }
3146
+ return $o(y(An, this), s, o);
3147
+ }
3148
+ }
3149
+ async function $o(n, e, t) {
3150
+ const o = n.get(e) || n.set(e, {}).get(e);
3151
+ if (o[t] === void 0) {
3152
+ const r = await (async function(i, a, s) {
3153
+ var c;
3154
+ if (!Pe(i)) throw new TypeError("JWK must be an object");
3155
+ let l;
3156
+ switch (a != null || (a = i.alg), l != null || (l = (c = void 0) !== null && c !== void 0 ? c : i.ext), i.kty) {
3157
+ case "oct":
3158
+ if (typeof i.k != "string" || !i.k) throw new TypeError('missing "k" (Key Value) Parameter value');
3159
+ return sn(i.k);
3160
+ case "RSA":
3161
+ if ("oth" in i && i.oth !== void 0) throw new Y('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
3162
+ return Ht(_(_({}, i), {}, { alg: a, ext: l }));
3163
+ case "AKP":
3164
+ if (typeof i.alg != "string" || !i.alg) throw new TypeError('missing "alg" (Algorithm) Parameter value');
3165
+ if (a !== void 0 && a !== i.alg) throw new TypeError("JWK alg and alg option value mismatch");
3166
+ return Ht(_(_({}, i), {}, { ext: l }));
3167
+ case "EC":
3168
+ case "OKP":
3169
+ return Ht(_(_({}, i), {}, { alg: a, ext: l }));
3170
+ default:
3171
+ throw new Y('Unsupported "kty" (Key Type) Parameter value');
3172
+ }
3173
+ })(_(_({}, e), {}, { ext: !0 }), t);
3174
+ if (r instanceof Uint8Array || r.type !== "public") throw new fo("JSON Web Key Set members must be public keys");
3175
+ o[t] = r;
3176
+ }
3177
+ return o[t];
3178
+ }
3179
+ function er(n) {
3180
+ const e = new za(n), t = async (o, r) => e.getKey(o, r);
3181
+ return Object.defineProperties(t, { jwks: { value: () => structuredClone(e.jwks()), enumerable: !1, configurable: !1, writable: !1 } }), t;
3182
+ }
3183
+ let qn;
3184
+ (typeof navigator > "u" || (jt = navigator.userAgent) === null || jt === void 0 || (Pn = jt.startsWith) === null || Pn === void 0 || !Pn.call(jt, "Mozilla/5.0 ")) && (qn = "".concat("jose", "/").concat("v6.2.2"));
3185
+ const Yr = Symbol(), Jt = Symbol();
3186
+ var Rn = /* @__PURE__ */ new WeakMap(), In = /* @__PURE__ */ new WeakMap(), xn = /* @__PURE__ */ new WeakMap(), Ut = /* @__PURE__ */ new WeakMap(), Ie = /* @__PURE__ */ new WeakMap(), pe = /* @__PURE__ */ new WeakMap(), ve = /* @__PURE__ */ new WeakMap(), On = /* @__PURE__ */ new WeakMap(), xe = /* @__PURE__ */ new WeakMap(), Oe = /* @__PURE__ */ new WeakMap();
3187
+ class Ha {
3188
+ constructor(e, t) {
3189
+ if (W(this, Rn, void 0), W(this, In, void 0), W(this, xn, void 0), W(this, Ut, void 0), W(this, Ie, void 0), W(this, pe, void 0), W(this, ve, void 0), W(this, On, void 0), W(this, xe, void 0), W(this, Oe, void 0), !(e instanceof URL)) throw new TypeError("url must be an instance of URL");
3190
+ var o, r;
3191
+ P(Rn, this, new URL(e.href)), P(In, this, typeof (t == null ? void 0 : t.timeoutDuration) == "number" ? t == null ? void 0 : t.timeoutDuration : 5e3), P(xn, this, typeof (t == null ? void 0 : t.cooldownDuration) == "number" ? t == null ? void 0 : t.cooldownDuration : 3e4), P(Ut, this, typeof (t == null ? void 0 : t.cacheMaxAge) == "number" ? t == null ? void 0 : t.cacheMaxAge : 6e5), P(ve, this, new Headers(t == null ? void 0 : t.headers)), qn && !y(ve, this).has("User-Agent") && y(ve, this).set("User-Agent", qn), y(ve, this).has("accept") || (y(ve, this).set("accept", "application/json"), y(ve, this).append("accept", "application/jwk-set+json")), P(On, this, t == null ? void 0 : t[Yr]), (t == null ? void 0 : t[Jt]) !== void 0 && (P(Oe, this, t == null ? void 0 : t[Jt]), o = t == null ? void 0 : t[Jt], r = y(Ut, this), typeof o == "object" && o !== null && "uat" in o && typeof o.uat == "number" && !(Date.now() - o.uat >= r) && "jwks" in o && Pe(o.jwks) && Array.isArray(o.jwks.keys) && Array.prototype.every.call(o.jwks.keys, Pe) && (P(Ie, this, y(Oe, this).uat), P(xe, this, er(y(Oe, this).jwks))));
3192
+ }
3193
+ pendingFetch() {
3194
+ return !!y(pe, this);
3195
+ }
3196
+ coolingDown() {
3197
+ return typeof y(Ie, this) == "number" && Date.now() < y(Ie, this) + y(xn, this);
3198
+ }
3199
+ fresh() {
3200
+ return typeof y(Ie, this) == "number" && Date.now() < y(Ie, this) + y(Ut, this);
3201
+ }
3202
+ jwks() {
3203
+ var e;
3204
+ return (e = y(xe, this)) === null || e === void 0 ? void 0 : e.jwks();
3205
+ }
3206
+ async getKey(e, t) {
3207
+ y(xe, this) && this.fresh() || await this.reload();
3208
+ try {
3209
+ return await y(xe, this).call(this, e, t);
3210
+ } catch (o) {
3211
+ if (o instanceof yo && this.coolingDown() === !1) return await this.reload(), y(xe, this).call(this, e, t);
3212
+ throw o;
3213
+ }
3214
+ }
3215
+ async reload() {
3216
+ y(pe, this) && (typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel") && P(pe, this, void 0), y(pe, this) || P(pe, this, (async function(e, t, o) {
3217
+ const i = await (arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : fetch)(e, { method: "GET", signal: o, redirect: "manual", headers: t }).catch((a) => {
3218
+ throw a.name === "TimeoutError" ? new Dr() : a;
3219
+ });
3220
+ if (i.status !== 200) throw new L("Expected 200 OK from the JSON Web Key Set HTTP response");
3221
+ try {
3222
+ return await i.json();
3223
+ } catch {
3224
+ throw new L("Failed to parse the JSON Web Key Set HTTP response as JSON");
3225
+ }
3226
+ })(y(Rn, this).href, y(ve, this), AbortSignal.timeout(y(In, this)), y(On, this)).then((e) => {
3227
+ P(xe, this, er(e)), y(Oe, this) && (y(Oe, this).uat = Date.now(), y(Oe, this).jwks = e), P(Ie, this, Date.now()), P(pe, this, void 0);
3228
+ }).catch((e) => {
3229
+ throw P(pe, this, void 0), e;
3230
+ })), await y(pe, this);
3231
+ }
3232
+ }
3233
+ const Ma = ["mfaToken"], Ja = ["mfaToken"];
3234
+ var Ce, Kt, je, B, Dt, Nt, ee, se, Ye, I, me, ct, ft, Qe, Lt, O, tr = class extends Error {
3235
+ constructor(n, e) {
3236
+ super(e), b(this, "code", void 0), this.name = "NotSupportedError", this.code = n;
3237
+ }
3238
+ }, de = class extends Error {
3239
+ constructor(n, e, t) {
3240
+ super(e), b(this, "cause", void 0), b(this, "code", void 0), this.code = n, this.cause = t && { error: t.error, error_description: t.error_description, message: t.message };
3241
+ }
3242
+ }, Za = class extends de {
3243
+ constructor(n, e) {
3244
+ super("token_by_code_error", n, e), this.name = "TokenByCodeError";
3245
+ }
3246
+ }, Va = class extends de {
3247
+ constructor(n, e) {
3248
+ super("token_by_client_credentials_error", n, e), this.name = "TokenByClientCredentialsError";
3249
+ }
3250
+ }, Fa = class extends de {
3251
+ constructor(n, e) {
3252
+ super("token_by_refresh_token_error", n, e), this.name = "TokenByRefreshTokenError";
3253
+ }
3254
+ }, Xa = class extends de {
3255
+ constructor(n, e) {
3256
+ super("token_by_password_error", n, e), this.name = "TokenByPasswordError";
3257
+ }
3258
+ }, Cn = class extends de {
3259
+ constructor(n, e) {
3260
+ super("token_for_connection_error", n, e), this.name = "TokenForConnectionErrorCode";
3261
+ }
3262
+ }, ce = class extends de {
3263
+ constructor(n, e) {
3264
+ super("token_exchange_error", n, e), this.name = "TokenExchangeError";
3265
+ }
3266
+ }, be = class extends Error {
3267
+ constructor(n) {
3268
+ super(n), b(this, "code", "verify_logout_token_error"), this.name = "VerifyLogoutTokenError";
3269
+ }
3270
+ }, jn = class extends de {
3271
+ constructor(n) {
3272
+ super("backchannel_authentication_error", "There was an error when trying to use Client-Initiated Backchannel Authentication.", n), b(this, "code", "backchannel_authentication_error"), this.name = "BackchannelAuthenticationError";
3273
+ }
3274
+ }, Ga = class extends de {
3275
+ constructor(n) {
3276
+ super("build_authorization_url_error", "There was an error when trying to build the authorization URL.", n), this.name = "BuildAuthorizationUrlError";
3277
+ }
3278
+ }, Ya = class extends de {
3279
+ constructor(n) {
3280
+ super("build_link_user_url_error", "There was an error when trying to build the Link User URL.", n), this.name = "BuildLinkUserUrlError";
3281
+ }
3282
+ }, qa = class extends de {
3283
+ constructor(n) {
3284
+ super("build_unlink_user_url_error", "There was an error when trying to build the Unlink User URL.", n), this.name = "BuildUnlinkUserUrlError";
3285
+ }
3286
+ }, Ba = class extends Error {
3287
+ constructor() {
3288
+ super("The client secret or client assertion signing key must be provided."), b(this, "code", "missing_client_auth_error"), this.name = "MissingClientAuthError";
3289
+ }
3290
+ };
3291
+ function Bn(n) {
3292
+ return Object.entries(n).filter((e) => {
3293
+ let [, t] = e;
3294
+ return t !== void 0;
3295
+ }).reduce((e, t) => _(_({}, e), {}, { [t[0]]: t[1] }), {});
3296
+ }
3297
+ var cn = class extends Error {
3298
+ constructor(n, e, t) {
3299
+ super(e), b(this, "cause", void 0), b(this, "code", void 0), this.code = n, this.cause = t && { error: t.error, error_description: t.error_description, message: t.message };
3300
+ }
3301
+ }, qr = class extends cn {
3302
+ constructor(n, e) {
3303
+ super("mfa_list_authenticators_error", n, e), this.name = "MfaListAuthenticatorsError";
3304
+ }
3305
+ }, Br = class extends cn {
3306
+ constructor(n, e) {
3307
+ super("mfa_enrollment_error", n, e), this.name = "MfaEnrollmentError";
3308
+ }
3309
+ }, Qa = class extends cn {
3310
+ constructor(n, e) {
3311
+ super("mfa_delete_authenticator_error", n, e), this.name = "MfaDeleteAuthenticatorError";
3312
+ }
3313
+ }, Qr = class extends cn {
3314
+ constructor(n, e) {
3315
+ super("mfa_challenge_error", n, e), this.name = "MfaChallengeError";
3316
+ }
3317
+ };
3318
+ function $a(n) {
3319
+ return { id: n.id, authenticatorType: n.authenticator_type, active: n.active, name: n.name, oobChannels: n.oob_channels, type: n.type };
3320
+ }
3321
+ var es = (Ce = /* @__PURE__ */ new WeakMap(), Kt = /* @__PURE__ */ new WeakMap(), je = /* @__PURE__ */ new WeakMap(), class {
3322
+ constructor(n) {
3323
+ var e;
3324
+ W(this, Ce, void 0), W(this, Kt, void 0), W(this, je, void 0), P(Ce, this, "https://".concat(n.domain)), P(Kt, this, n.clientId), P(je, this, (e = n.customFetch) !== null && e !== void 0 ? e : function() {
3325
+ return fetch(...arguments);
3326
+ });
3327
+ }
3328
+ async listAuthenticators(n) {
3329
+ const e = "".concat(y(Ce, this), "/mfa/authenticators"), { mfaToken: t } = n, o = await y(je, this).call(this, e, { method: "GET", headers: { Authorization: "Bearer ".concat(t), "Content-Type": "application/json" } });
3330
+ if (!o.ok) {
3331
+ const r = await o.json();
3332
+ throw new qr(r.error_description || "Failed to list authenticators", r);
3333
+ }
3334
+ return (await o.json()).map($a);
3335
+ }
3336
+ async enrollAuthenticator(n) {
3337
+ const e = "".concat(y(Ce, this), "/mfa/associate"), { mfaToken: t } = n, o = Uo(n, Ma), r = { authenticator_types: o.authenticatorTypes };
3338
+ "oobChannels" in o && (r.oob_channels = o.oobChannels), "phoneNumber" in o && o.phoneNumber && (r.phone_number = o.phoneNumber), "email" in o && o.email && (r.email = o.email);
3339
+ const i = await y(je, this).call(this, e, { method: "POST", headers: { Authorization: "Bearer ".concat(t), "Content-Type": "application/json" }, body: JSON.stringify(r) });
3340
+ if (!i.ok) {
3341
+ const a = await i.json();
3342
+ throw new Br(a.error_description || "Failed to enroll authenticator", a);
3343
+ }
3344
+ return (function(a) {
3345
+ if (a.authenticator_type === "otp") return { authenticatorType: "otp", secret: a.secret, barcodeUri: a.barcode_uri, recoveryCodes: a.recovery_codes, id: a.id };
3346
+ if (a.authenticator_type === "oob") return { authenticatorType: "oob", oobChannel: a.oob_channel, oobCode: a.oob_code, bindingMethod: a.binding_method, id: a.id, barcodeUri: a.barcode_uri, recoveryCodes: a.recovery_codes };
3347
+ throw new Error("Unexpected authenticator type: ".concat(a.authenticator_type));
3348
+ })(await i.json());
3349
+ }
3350
+ async deleteAuthenticator(n) {
3351
+ const { authenticatorId: e, mfaToken: t } = n, o = "".concat(y(Ce, this), "/mfa/authenticators/").concat(encodeURIComponent(e)), r = await y(je, this).call(this, o, { method: "DELETE", headers: { Authorization: "Bearer ".concat(t), "Content-Type": "application/json" } });
3352
+ if (!r.ok) {
3353
+ const i = await r.json();
3354
+ throw new Qa(i.error_description || "Failed to delete authenticator", i);
3355
+ }
3356
+ }
3357
+ async challengeAuthenticator(n) {
3358
+ const e = "".concat(y(Ce, this), "/mfa/challenge"), { mfaToken: t } = n, o = Uo(n, Ja), r = { mfa_token: t, client_id: y(Kt, this), challenge_type: o.challengeType };
3359
+ o.authenticatorId && (r.authenticator_id = o.authenticatorId);
3360
+ const i = await y(je, this).call(this, e, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(r) });
3361
+ if (!i.ok) {
3362
+ const a = await i.json();
3363
+ throw new Qr(a.error_description || "Failed to challenge authenticator", a);
3364
+ }
3365
+ return (function(a) {
3366
+ const s = { challengeType: a.challenge_type };
3367
+ return a.oob_code !== void 0 && (s.oobCode = a.oob_code), a.binding_method !== void 0 && (s.bindingMethod = a.binding_method), s;
3368
+ })(await i.json());
3369
+ }
3370
+ }), _e = class $r {
3371
+ constructor(e, t, o, r, i, a, s) {
3372
+ b(this, "accessToken", void 0), b(this, "idToken", void 0), b(this, "refreshToken", void 0), b(this, "expiresAt", void 0), b(this, "scope", void 0), b(this, "claims", void 0), b(this, "authorizationDetails", void 0), b(this, "tokenType", void 0), b(this, "issuedTokenType", void 0), this.accessToken = e, this.idToken = o, this.refreshToken = r, this.expiresAt = t, this.scope = i, this.claims = a, this.authorizationDetails = s;
3373
+ }
3374
+ static fromTokenEndpointResponse(e) {
3375
+ const t = e.id_token ? e.claims() : void 0, o = new $r(e.access_token, Math.floor(Date.now() / 1e3) + Number(e.expires_in), e.id_token, e.refresh_token, e.scope, t, e.authorization_details);
3376
+ return o.tokenType = e.token_type, o.issuedTokenType = e.issued_token_type, o;
3377
+ }
3378
+ }, ts = (B = /* @__PURE__ */ new WeakMap(), Dt = /* @__PURE__ */ new WeakMap(), Nt = /* @__PURE__ */ new WeakMap(), class {
3379
+ constructor(n, e) {
3380
+ W(this, B, /* @__PURE__ */ new Map()), W(this, Dt, void 0), W(this, Nt, void 0), P(Nt, this, Math.max(1, Math.floor(n))), P(Dt, this, Math.max(0, Math.floor(e)));
3381
+ }
3382
+ get(n) {
3383
+ const e = y(B, this).get(n);
3384
+ if (e) {
3385
+ if (!(Date.now() >= e.expiresAt)) return y(B, this).delete(n), y(B, this).set(n, e), e.value;
3386
+ y(B, this).delete(n);
3387
+ }
3388
+ }
3389
+ set(n, e) {
3390
+ for (y(B, this).has(n) && y(B, this).delete(n), y(B, this).set(n, { value: e, expiresAt: Date.now() + y(Dt, this) }); y(B, this).size > y(Nt, this); ) {
3391
+ const t = y(B, this).keys().next().value;
3392
+ if (t === void 0) break;
3393
+ y(B, this).delete(t);
3394
+ }
3395
+ }
3396
+ }), nr = /* @__PURE__ */ new Map();
3397
+ function or(n) {
3398
+ return { ttlMs: 1e3 * (typeof (n == null ? void 0 : n.ttl) == "number" ? n.ttl : 600), maxEntries: typeof (n == null ? void 0 : n.maxEntries) == "number" && n.maxEntries > 0 ? n.maxEntries : 100 };
3399
+ }
3400
+ var rr = class {
3401
+ static createDiscoveryCache(n) {
3402
+ const e = (t = n.maxEntries, o = n.ttlMs, "".concat(t, ":").concat(o));
3403
+ var t, o;
3404
+ let r = (i = e, nr.get(i));
3405
+ var i;
3406
+ return r || (r = new ts(n.maxEntries, n.ttlMs), nr.set(e, r)), r;
3407
+ }
3408
+ static createJwksCache() {
3409
+ return {};
3410
+ }
3411
+ }, Qn = "openid profile email offline_access", ns = Object.freeze(/* @__PURE__ */ new Set(["grant_type", "client_id", "client_secret", "client_assertion", "client_assertion_type", "subject_token", "subject_token_type", "requested_token_type", "actor_token", "actor_token_type", "audience", "aud", "resource", "resources", "resource_indicator", "scope", "connection", "login_hint", "organization", "assertion"]));
3412
+ function ei(n) {
3413
+ if (n == null) throw new ce("subject_token is required");
3414
+ if (typeof n != "string") throw new ce("subject_token must be a string");
3415
+ if (n.trim().length === 0) throw new ce("subject_token cannot be blank or whitespace");
3416
+ if (n !== n.trim()) throw new ce("subject_token must not include leading or trailing whitespace");
3417
+ if (/^bearer\s+/i.test(n)) throw new ce("subject_token must not include the 'Bearer ' prefix");
3418
+ }
3419
+ function ti(n, e) {
3420
+ if (e) {
3421
+ for (const [t, o] of Object.entries(e)) if (!ns.has(t)) if (Array.isArray(o)) {
3422
+ if (o.length > 20) throw new ce("Parameter '".concat(t, "' exceeds maximum array size of ").concat(20));
3423
+ o.forEach((r) => {
3424
+ n.append(t, r);
3425
+ });
3426
+ } else n.append(t, o);
3427
+ }
3428
+ }
3429
+ var ni = "urn:ietf:params:oauth:token-type:access_token", os = (ee = /* @__PURE__ */ new WeakMap(), se = /* @__PURE__ */ new WeakMap(), Ye = /* @__PURE__ */ new WeakMap(), I = /* @__PURE__ */ new WeakMap(), me = /* @__PURE__ */ new WeakMap(), ct = /* @__PURE__ */ new WeakMap(), ft = /* @__PURE__ */ new WeakMap(), Qe = /* @__PURE__ */ new WeakMap(), Lt = /* @__PURE__ */ new WeakMap(), O = /* @__PURE__ */ new WeakSet(), class {
3430
+ constructor(n) {
3431
+ var e, t, o, r;
3432
+ if ((function(a, s) {
3433
+ br(a, s), s.add(a);
3434
+ })(this, O), W(this, ee, void 0), W(this, se, void 0), W(this, Ye, void 0), W(this, I, void 0), W(this, me, void 0), W(this, ct, void 0), W(this, ft, void 0), W(this, Qe, void 0), W(this, Lt, void 0), b(this, "mfa", void 0), P(I, this, n), n.useMtls && !n.customFetch) throw new tr("mtls_without_custom_fetch_not_supported", "Using mTLS without a custom fetch implementation is not supported");
3435
+ P(me, this, (function(a, s) {
3436
+ if (s.enabled === !1) return a;
3437
+ const c = { name: s.name, version: s.version }, l = btoa(JSON.stringify(c));
3438
+ return async (u, p) => {
3439
+ const h = u instanceof Request ? new Headers(u.headers) : new Headers();
3440
+ return p != null && p.headers && new Headers(p.headers).forEach((d, g) => {
3441
+ h.set(g, d);
3442
+ }), h.set("Auth0-Client", l), a(u, _(_({}, p), {}, { headers: h }));
3443
+ };
3444
+ })((e = n.customFetch) !== null && e !== void 0 ? e : function() {
3445
+ return fetch(...arguments);
3446
+ }, ((t = n.telemetry) == null ? void 0 : t.enabled) === !1 ? t : { enabled: !0, name: (o = t == null ? void 0 : t.name) !== null && o !== void 0 ? o : "@auth0/auth0-auth-js", version: (r = t == null ? void 0 : t.version) !== null && r !== void 0 ? r : "1.6.0" }));
3447
+ const i = or(n.discoveryCache);
3448
+ P(ft, this, rr.createDiscoveryCache(i)), P(Qe, this, /* @__PURE__ */ new Map()), P(Lt, this, rr.createJwksCache()), this.mfa = new es({ domain: y(I, this).domain, clientId: y(I, this).clientId, customFetch: y(me, this) });
3449
+ }
3450
+ async getServerMetadata() {
3451
+ const { serverMetadata: n } = await C(O, this, F).call(this);
3452
+ return n;
3453
+ }
3454
+ async buildAuthorizationUrl(n) {
3455
+ const { serverMetadata: e } = await C(O, this, F).call(this);
3456
+ if (n != null && n.pushedAuthorizationRequests && !e.pushed_authorization_request_endpoint) throw new tr("par_not_supported_error", "The Auth0 tenant does not have pushed authorization requests enabled. Learn how to enable it here: https://auth0.com/docs/get-started/applications/configure-par");
3457
+ try {
3458
+ return await C(O, this, Wn).call(this, n);
3459
+ } catch (t) {
3460
+ throw new Ga(t);
3461
+ }
3462
+ }
3463
+ async buildLinkUserUrl(n) {
3464
+ try {
3465
+ const e = await C(O, this, Wn).call(this, { authorizationParams: _(_({}, n.authorizationParams), {}, { requested_connection: n.connection, requested_connection_scope: n.connectionScope, scope: "openid link_account offline_access", id_token_hint: n.idToken }) });
3466
+ return { linkUserUrl: e.authorizationUrl, codeVerifier: e.codeVerifier };
3467
+ } catch (e) {
3468
+ throw new Ya(e);
3469
+ }
3470
+ }
3471
+ async buildUnlinkUserUrl(n) {
3472
+ try {
3473
+ const e = await C(O, this, Wn).call(this, { authorizationParams: _(_({}, n.authorizationParams), {}, { requested_connection: n.connection, scope: "openid unlink_account", id_token_hint: n.idToken }) });
3474
+ return { unlinkUserUrl: e.authorizationUrl, codeVerifier: e.codeVerifier };
3475
+ } catch (e) {
3476
+ throw new qa(e);
3477
+ }
3478
+ }
3479
+ async backchannelAuthentication(n) {
3480
+ const { configuration: e, serverMetadata: t } = await C(O, this, F).call(this), o = Bn(_(_({}, y(I, this).authorizationParams), n == null ? void 0 : n.authorizationParams)), r = new URLSearchParams(_(_({ scope: Qn }, o), {}, { client_id: y(I, this).clientId, binding_message: n.bindingMessage, login_hint: JSON.stringify({ format: "iss_sub", iss: t.issuer, sub: n.loginHint.sub }) }));
3481
+ n.requestedExpiry && r.append("requested_expiry", n.requestedExpiry.toString()), n.authorizationDetails && r.append("authorization_details", JSON.stringify(n.authorizationDetails));
3482
+ try {
3483
+ const i = await Yo(e, r), a = await Zr(e, i);
3484
+ return _e.fromTokenEndpointResponse(a);
3485
+ } catch (i) {
3486
+ throw new jn(i);
3487
+ }
3488
+ }
3489
+ async initiateBackchannelAuthentication(n) {
3490
+ const { configuration: e, serverMetadata: t } = await C(O, this, F).call(this), o = Bn(_(_({}, y(I, this).authorizationParams), n == null ? void 0 : n.authorizationParams)), r = new URLSearchParams(_(_({ scope: Qn }, o), {}, { client_id: y(I, this).clientId, binding_message: n.bindingMessage, login_hint: JSON.stringify({ format: "iss_sub", iss: t.issuer, sub: n.loginHint.sub }) }));
3491
+ n.requestedExpiry && r.append("requested_expiry", n.requestedExpiry.toString()), n.authorizationDetails && r.append("authorization_details", JSON.stringify(n.authorizationDetails));
3492
+ try {
3493
+ const i = await Yo(e, r);
3494
+ return { authReqId: i.auth_req_id, expiresIn: i.expires_in, interval: i.interval };
3495
+ } catch (i) {
3496
+ throw new jn(i);
3497
+ }
3498
+ }
3499
+ async backchannelAuthenticationGrant(n) {
3500
+ let { authReqId: e } = n;
3501
+ const { configuration: t } = await C(O, this, F).call(this), o = new URLSearchParams({ auth_req_id: e });
3502
+ try {
3503
+ const r = await $t(t, "urn:openid:params:grant-type:ciba", o);
3504
+ return _e.fromTokenEndpointResponse(r);
3505
+ } catch (r) {
3506
+ throw new jn(r);
3507
+ }
3508
+ }
3509
+ async getTokenForConnection(n) {
3510
+ var e;
3511
+ if (n.refreshToken && n.accessToken) throw new Cn("Either a refresh or access token should be specified, but not both.");
3512
+ const t = (e = n.accessToken) !== null && e !== void 0 ? e : n.refreshToken;
3513
+ if (!t) throw new Cn("Either a refresh or access token must be specified.");
3514
+ try {
3515
+ return await this.exchangeToken({ connection: n.connection, subjectToken: t, subjectTokenType: n.accessToken ? ni : "urn:ietf:params:oauth:token-type:refresh_token", loginHint: n.loginHint });
3516
+ } catch (o) {
3517
+ throw o instanceof ce ? new Cn(o.message, o.cause) : o;
3518
+ }
3519
+ }
3520
+ async exchangeToken(n) {
3521
+ return "connection" in n ? C(O, this, is).call(this, n) : C(O, this, as).call(this, n);
3522
+ }
3523
+ async getTokenByCode(n, e) {
3524
+ const { configuration: t } = await C(O, this, F).call(this);
3525
+ try {
3526
+ const o = await Vr(t, n, { pkceCodeVerifier: e.codeVerifier });
3527
+ return _e.fromTokenEndpointResponse(o);
3528
+ } catch (o) {
3529
+ throw new Za("There was an error while trying to request a token.", o);
3530
+ }
3531
+ }
3532
+ async getTokenByRefreshToken(n) {
3533
+ const { configuration: e } = await C(O, this, F).call(this), t = new URLSearchParams();
3534
+ n.audience && t.append("audience", n.audience), n.scope && t.append("scope", n.scope);
3535
+ try {
3536
+ const o = await Fr(e, n.refreshToken, t);
3537
+ return _e.fromTokenEndpointResponse(o);
3538
+ } catch (o) {
3539
+ throw new Fa("The access token has expired and there was an error while trying to refresh it.", o);
3540
+ }
3541
+ }
3542
+ async getTokenByPassword(n) {
3543
+ const { configuration: e } = await C(O, this, F).call(this), t = new URLSearchParams({ username: n.username, password: n.password });
3544
+ n.audience && t.append("audience", n.audience), n.scope && t.append("scope", n.scope), n.realm && t.append("realm", n.realm);
3545
+ let o = e;
3546
+ if (n.auth0ForwardedFor) {
3547
+ const r = await C(O, this, go).call(this);
3548
+ o = new tt(e.serverMetadata(), y(I, this).clientId, y(I, this).clientSecret, r), o[ue] = (i, a) => y(me, this).call(this, i, _(_({}, a), {}, { headers: _(_({}, a.headers), {}, { "auth0-forwarded-for": n.auth0ForwardedFor }) }));
3549
+ }
3550
+ try {
3551
+ const r = await $t(o, "password", t);
3552
+ return _e.fromTokenEndpointResponse(r);
3553
+ } catch (r) {
3554
+ throw new Xa("There was an error while trying to request a token.", r);
3555
+ }
3556
+ }
3557
+ async getTokenByClientCredentials(n) {
3558
+ const { configuration: e } = await C(O, this, F).call(this);
3559
+ try {
3560
+ const t = new URLSearchParams({ audience: n.audience });
3561
+ n.organization && t.append("organization", n.organization);
3562
+ const o = await Xr(e, t);
3563
+ return _e.fromTokenEndpointResponse(o);
3564
+ } catch (t) {
3565
+ throw new Va("There was an error while trying to request a token.", t);
3566
+ }
3567
+ }
3568
+ async buildLogoutUrl(n) {
3569
+ const { configuration: e, serverMetadata: t } = await C(O, this, F).call(this);
3570
+ if (!t.end_session_endpoint) {
3571
+ const o = new URL("https://".concat(y(I, this).domain, "/v2/logout"));
3572
+ return o.searchParams.set("returnTo", n.returnTo), o.searchParams.set("client_id", y(I, this).clientId), o;
3573
+ }
3574
+ return (function(o, r) {
3575
+ ge(o);
3576
+ const { as: i, c: a, tlsOnly: s } = N(o), c = vt(i, "end_session_endpoint", !1, s);
3577
+ (r = new URLSearchParams(r)).has("client_id") || r.set("client_id", a.client_id);
3578
+ for (const [l, u] of r.entries()) c.searchParams.append(l, u);
3579
+ return c;
3580
+ })(e, { post_logout_redirect_uri: n.returnTo });
3581
+ }
3582
+ async verifyLogoutToken(n) {
3583
+ const { serverMetadata: e } = await C(O, this, F).call(this), t = or(y(I, this).discoveryCache), o = e.jwks_uri;
3584
+ y(ct, this) || P(ct, this, (function(i, a) {
3585
+ const s = new Ha(i, a), c = async (l, u) => s.getKey(l, u);
3586
+ return Object.defineProperties(c, { coolingDown: { get: () => s.coolingDown(), enumerable: !0, configurable: !1 }, fresh: { get: () => s.fresh(), enumerable: !0, configurable: !1 }, reload: { value: () => s.reload(), enumerable: !0, configurable: !1, writable: !1 }, reloading: { get: () => s.pendingFetch(), enumerable: !0, configurable: !1 }, jwks: { value: () => s.jwks(), enumerable: !0, configurable: !1, writable: !1 } }), c;
3587
+ })(new URL(o), { cacheMaxAge: t.ttlMs, [Yr]: y(me, this), [Jt]: y(Lt, this) }));
3588
+ const { payload: r } = await Na(n.logoutToken, y(ct, this), { issuer: e.issuer, audience: y(I, this).clientId, algorithms: ["RS256"], requiredClaims: ["iat"] });
3589
+ if (!("sid" in r) && !("sub" in r)) throw new be('either "sid" or "sub" (or both) claims must be present');
3590
+ if ("sid" in r && typeof r.sid != "string") throw new be('"sid" claim must be a string');
3591
+ if ("sub" in r && typeof r.sub != "string") throw new be('"sub" claim must be a string');
3592
+ if ("nonce" in r) throw new be('"nonce" claim is prohibited');
3593
+ if (!("events" in r)) throw new be('"events" claim is missing');
3594
+ if (typeof r.events != "object" || r.events === null) throw new be('"events" claim must be an object');
3595
+ if (!("http://schemas.openid.net/event/backchannel-logout" in r.events)) throw new be('"http://schemas.openid.net/event/backchannel-logout" member is missing in the "events" claim');
3596
+ if (typeof r.events["http://schemas.openid.net/event/backchannel-logout"] != "object") throw new be('"http://schemas.openid.net/event/backchannel-logout" member in the "events" claim must be an object');
3597
+ return { sid: r.sid, sub: r.sub };
3598
+ }
3599
+ });
3600
+ function rs() {
3601
+ const n = y(I, this).domain.toLowerCase();
3602
+ return "".concat(n, "|mtls:").concat(y(I, this).useMtls ? "1" : "0");
3603
+ }
3604
+ async function ir(n) {
3605
+ const e = await C(O, this, go).call(this), t = new tt(n, y(I, this).clientId, y(I, this).clientSecret, e);
3606
+ return t[ue] = y(me, this), t;
3607
+ }
3608
+ async function F() {
3609
+ if (y(ee, this) && y(se, this)) return { configuration: y(ee, this), serverMetadata: y(se, this) };
3610
+ const n = C(O, this, rs).call(this), e = y(ft, this).get(n);
3611
+ if (e) return P(se, this, e.serverMetadata), P(ee, this, await C(O, this, ir).call(this, e.serverMetadata)), { configuration: y(ee, this), serverMetadata: y(se, this) };
3612
+ const t = y(Qe, this).get(n);
3613
+ if (t) {
3614
+ const i = await t;
3615
+ return P(se, this, i.serverMetadata), P(ee, this, await C(O, this, ir).call(this, i.serverMetadata)), { configuration: y(ee, this), serverMetadata: y(se, this) };
3616
+ }
3617
+ const o = (async () => {
3618
+ const i = await C(O, this, go).call(this), a = await ja(new URL("https://".concat(y(I, this).domain)), y(I, this).clientId, { use_mtls_endpoint_aliases: y(I, this).useMtls }, i, { [ue]: y(me, this) }), s = a.serverMetadata();
3619
+ return y(ft, this).set(n, { serverMetadata: s }), { configuration: a, serverMetadata: s };
3620
+ })(), r = o.then((i) => {
3621
+ let { serverMetadata: a } = i;
3622
+ return { serverMetadata: a };
3623
+ });
3624
+ r.catch(() => {
3625
+ }), y(Qe, this).set(n, r);
3626
+ try {
3627
+ const { configuration: i, serverMetadata: a } = await o;
3628
+ P(ee, this, i), P(se, this, a), y(ee, this)[ue] = y(me, this);
3629
+ } finally {
3630
+ y(Qe, this).delete(n);
3631
+ }
3632
+ return { configuration: y(ee, this), serverMetadata: y(se, this) };
3633
+ }
3634
+ async function is(n) {
3635
+ var e, t;
3636
+ const { configuration: o } = await C(O, this, F).call(this);
3637
+ if ("audience" in n || "resource" in n) throw new ce("audience and resource parameters are not supported for Token Vault exchanges");
3638
+ ei(n.subjectToken);
3639
+ const r = new URLSearchParams({ connection: n.connection, subject_token: n.subjectToken, subject_token_type: (e = n.subjectTokenType) !== null && e !== void 0 ? e : ni, requested_token_type: (t = n.requestedTokenType) !== null && t !== void 0 ? t : "http://auth0.com/oauth/token-type/federated-connection-access-token" });
3640
+ n.loginHint && r.append("login_hint", n.loginHint), n.scope && r.append("scope", n.scope), ti(r, n.extra);
3641
+ try {
3642
+ const i = await $t(o, "urn:auth0:params:oauth:grant-type:token-exchange:federated-connection-access-token", r);
3643
+ return _e.fromTokenEndpointResponse(i);
3644
+ } catch (i) {
3645
+ throw new ce("Failed to exchange token for connection '".concat(n.connection, "'."), i);
3646
+ }
3647
+ }
3648
+ async function as(n) {
3649
+ const { configuration: e } = await C(O, this, F).call(this);
3650
+ ei(n.subjectToken);
3651
+ const t = new URLSearchParams({ subject_token_type: n.subjectTokenType, subject_token: n.subjectToken });
3652
+ n.audience && t.append("audience", n.audience), n.scope && t.append("scope", n.scope), n.requestedTokenType && t.append("requested_token_type", n.requestedTokenType), n.organization && t.append("organization", n.organization), ti(t, n.extra);
3653
+ try {
3654
+ const o = await $t(e, "urn:ietf:params:oauth:grant-type:token-exchange", t);
3655
+ return _e.fromTokenEndpointResponse(o);
3656
+ } catch (o) {
3657
+ throw new ce("Failed to exchange token of type '".concat(n.subjectTokenType, "'").concat(n.audience ? " for audience '".concat(n.audience, "'") : "", "."), o);
3658
+ }
3659
+ }
3660
+ async function go() {
3661
+ return y(Ye, this) || P(Ye, this, (async () => {
3662
+ if (!y(I, this).clientSecret && !y(I, this).clientAssertionSigningKey && !y(I, this).useMtls) throw new Ba();
3663
+ if (y(I, this).useMtls) return (e, t, o, r) => {
3664
+ o.set("client_id", t.client_id);
3665
+ };
3666
+ let n = y(I, this).clientAssertionSigningKey;
3667
+ return !n || n instanceof CryptoKey || (n = await (async function(e, t, o) {
3668
+ if (typeof e != "string" || e.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
3669
+ return Ia(e, t, o);
3670
+ })(n, y(I, this).clientAssertionSigningAlg || "RS256")), n ? (function(e, t) {
3671
+ return Qi(e);
3672
+ })(n) : Hr(y(I, this).clientSecret);
3673
+ })().catch((n) => {
3674
+ throw P(Ye, this, void 0), n;
3675
+ })), y(Ye, this);
3676
+ }
3677
+ async function Wn(n) {
3678
+ const { configuration: e } = await C(O, this, F).call(this), t = Ca(), o = await Oa(t), r = Bn(_(_({}, y(I, this).authorizationParams), n == null ? void 0 : n.authorizationParams)), i = new URLSearchParams(_(_({ scope: Qn }, r), {}, { client_id: y(I, this).clientId, code_challenge: o, code_challenge_method: "S256" }));
3679
+ return { authorizationUrl: n != null && n.pushedAuthorizationRequests ? await Gr(e, i) : await Yn(e, i), codeVerifier: t };
3680
+ }
3681
+ class Ae extends j {
3682
+ constructor(e, t) {
3683
+ super(e, t), Object.setPrototypeOf(this, Ae.prototype);
3684
+ }
3685
+ static fromPayload(e) {
3686
+ let { error: t, error_description: o } = e;
3687
+ return new Ae(t, o);
3688
+ }
3689
+ }
3690
+ class en extends Ae {
3691
+ constructor(e, t) {
3692
+ super(e, t), Object.setPrototypeOf(this, en.prototype);
3693
+ }
3694
+ }
3695
+ class wo extends Ae {
3696
+ constructor(e, t) {
3697
+ super(e, t), Object.setPrototypeOf(this, wo.prototype);
3698
+ }
3699
+ }
3700
+ class vo extends Ae {
3701
+ constructor(e, t) {
3702
+ super(e, t), Object.setPrototypeOf(this, vo.prototype);
3703
+ }
3704
+ }
3705
+ class qe extends Ae {
3706
+ constructor(e, t) {
3707
+ super(e, t), Object.setPrototypeOf(this, qe.prototype);
3708
+ }
3709
+ }
3710
+ class bo extends Ae {
3711
+ constructor(e, t) {
3712
+ super(e, t), Object.setPrototypeOf(this, bo.prototype);
3713
+ }
3714
+ }
3715
+ class ss {
3716
+ constructor() {
3717
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : 6e5;
3718
+ this.contexts = /* @__PURE__ */ new Map(), this.ttlMs = e;
3719
+ }
3720
+ set(e, t) {
3721
+ this.cleanup(), this.contexts.set(e, Object.assign(Object.assign({}, t), { createdAt: Date.now() }));
3722
+ }
3723
+ get(e) {
3724
+ const t = this.contexts.get(e);
3725
+ if (t) {
3726
+ if (!(Date.now() - t.createdAt > this.ttlMs)) return t;
3727
+ this.contexts.delete(e);
3728
+ }
3729
+ }
3730
+ remove(e) {
3731
+ this.contexts.delete(e);
3732
+ }
3733
+ cleanup() {
3734
+ const e = Date.now();
3735
+ for (const [t, o] of this.contexts) e - o.createdAt > this.ttlMs && this.contexts.delete(t);
3736
+ }
3737
+ get size() {
3738
+ return this.contexts.size;
3739
+ }
3740
+ }
3741
+ class cs {
3742
+ constructor(e, t) {
3743
+ this.authJsMfaClient = e, this.auth0Client = t, this.contextManager = new ss();
3744
+ }
3745
+ setMFAAuthDetails(e, t, o, r) {
3746
+ this.contextManager.set(e, { scope: t, audience: o, mfaRequirements: r });
3747
+ }
3748
+ async getAuthenticators(e) {
3749
+ var t, o;
3750
+ const r = this.contextManager.get(e);
3751
+ if (!(!((t = r == null ? void 0 : r.mfaRequirements) === null || t === void 0) && t.challenge) || r.mfaRequirements.challenge.length === 0) throw new en("invalid_request", "challengeType is required and must contain at least one challenge type, please check mfa_required error payload");
3752
+ const i = r.mfaRequirements.challenge.map((a) => a.type);
3753
+ try {
3754
+ return (await this.authJsMfaClient.listAuthenticators({ mfaToken: e })).filter((a) => !!a.type && i.includes(a.type));
3755
+ } catch (a) {
3756
+ throw a instanceof qr ? new en((o = a.cause) === null || o === void 0 ? void 0 : o.error, a.message) : a;
3757
+ }
3758
+ }
3759
+ async enroll(e) {
3760
+ var t;
3761
+ const o = (function(r) {
3762
+ const i = Hi[r.factorType];
3763
+ return Object.assign(Object.assign(Object.assign({ mfaToken: r.mfaToken, authenticatorTypes: i.authenticatorTypes }, i.oobChannels && { oobChannels: i.oobChannels }), "phoneNumber" in r && { phoneNumber: r.phoneNumber }), "email" in r && { email: r.email });
3764
+ })(e);
3765
+ try {
3766
+ return await this.authJsMfaClient.enrollAuthenticator(o);
3767
+ } catch (r) {
3768
+ throw r instanceof Br ? new wo((t = r.cause) === null || t === void 0 ? void 0 : t.error, r.message) : r;
3769
+ }
3770
+ }
3771
+ async challenge(e) {
3772
+ var t;
3773
+ try {
3774
+ const o = { challengeType: e.challengeType, mfaToken: e.mfaToken };
3775
+ return e.authenticatorId && (o.authenticatorId = e.authenticatorId), await this.authJsMfaClient.challengeAuthenticator(o);
3776
+ } catch (o) {
3777
+ throw o instanceof Qr ? new vo((t = o.cause) === null || t === void 0 ? void 0 : t.error, o.message) : o;
3778
+ }
3779
+ }
3780
+ async getEnrollmentFactors(e) {
3781
+ const t = this.contextManager.get(e);
3782
+ if (!t || !t.mfaRequirements) throw new bo("mfa_context_not_found", "MFA context not found for this MFA token. Please retry the original request to get a new MFA token.");
3783
+ return t.mfaRequirements.enroll && t.mfaRequirements.enroll.length !== 0 ? t.mfaRequirements.enroll : [];
3784
+ }
3785
+ async verify(e) {
3786
+ const t = this.contextManager.get(e.mfaToken);
3787
+ if (!t) throw new qe("mfa_context_not_found", "MFA context not found for this MFA token. Please retry the original request to get a new MFA token.");
3788
+ const o = (function(a) {
3789
+ return "otp" in a && a.otp ? Mi : "oobCode" in a && a.oobCode ? Ji : "recoveryCode" in a && a.recoveryCode ? Zi : void 0;
3790
+ })(e);
3791
+ if (!o) throw new qe("invalid_request", "Unable to determine grant type. Provide one of: otp, oobCode, or recoveryCode.");
3792
+ const r = t.scope, i = t.audience;
3793
+ try {
3794
+ const a = await this.auth0Client._requestTokenForMfa({ grant_type: o, mfaToken: e.mfaToken, scope: r, audience: i, otp: e.otp, oob_code: e.oobCode, binding_code: e.bindingCode, recovery_code: e.recoveryCode });
3795
+ return this.contextManager.remove(e.mfaToken), a;
3796
+ } catch (a) {
3797
+ if (a instanceof $e) this.setMFAAuthDetails(a.mfa_token, r, i, a.mfa_requirements);
3798
+ else if (a instanceof qe) throw new qe(a.error, a.error_description);
3799
+ throw a;
3800
+ }
3801
+ }
3802
+ }
3803
+ class us {
3804
+ constructor(e) {
3805
+ let t, o;
3806
+ if (this.userCache = new fr().enclosedCache, this.defaultOptions = { authorizationParams: { scope: "openid profile email" }, useRefreshTokensFallback: !1, useFormData: !0 }, this.options = Object.assign(Object.assign(Object.assign({}, this.defaultOptions), e), { authorizationParams: Object.assign(Object.assign({}, this.defaultOptions.authorizationParams), e.authorizationParams) }), typeof window < "u" && (() => {
3807
+ if (!Vt()) throw new Error("For security reasons, `window.crypto` is required to run `auth0-spa-js`.");
3808
+ if (Vt().subtle === void 0) throw new Error(`
3809
+ auth0-spa-js must run on a secure origin. See https://github.com/auth0/auth0-spa-js/blob/main/FAQ.md#why-do-i-get-auth0-spa-js-must-run-on-a-secure-origin for more information.
3810
+ `);
3811
+ })(), this.lockManager = (pn || (pn = li()), pn), e.cache && e.cacheLocation && console.warn("Both `cache` and `cacheLocation` options have been specified in the Auth0Client configuration; ignoring `cacheLocation` and using `cache`."), e.cache) o = e.cache;
3812
+ else {
3813
+ if (t = e.cacheLocation || _o, !Oo(t)) throw new Error('Invalid cache location "'.concat(t, '"'));
3814
+ o = Oo(t)();
3815
+ }
3816
+ var r;
3817
+ this.httpTimeoutMs = e.httpTimeoutInSeconds ? 1e3 * e.httpTimeoutInSeconds : Un, this.cookieStorage = e.legacySameSiteCookie === !1 ? Xe : Oi, this.orgHintCookieName = (r = this.options.clientId, "auth0.".concat(r, ".organization_hint")), this.isAuthenticatedCookieName = ((l) => "auth0.".concat(l, ".is.authenticated"))(this.options.clientId), this.sessionCheckExpiryDays = e.sessionCheckExpiryDays || 1;
3818
+ const i = e.useCookiesForTransactions ? this.cookieStorage : Ci;
3819
+ var a;
3820
+ this.scope = (function(l, u) {
3821
+ for (var p = arguments.length, h = new Array(p > 2 ? p - 2 : 0), d = 2; d < p; d++) h[d - 2] = arguments[d];
3822
+ if (typeof l != "object") return { [H]: zt(u, l, ...h) };
3823
+ let g = { [H]: zt(u, ...h) };
3824
+ return Object.keys(l).forEach((f) => {
3825
+ const m = l[f];
3826
+ g[f] = zt(u, m, ...h);
3827
+ }), g;
3828
+ })(this.options.authorizationParams.scope, "openid", this.options.useRefreshTokens ? "offline_access" : ""), this.transactionManager = new Ei(i, this.options.clientId, this.options.cookieDomain), this.nowProvider = this.options.nowProvider || ar, this.cacheManager = new Ti(o, o.allKeys ? void 0 : new Ui(o, this.options.clientId), this.nowProvider), this.dpop = this.options.useDpop ? new Ni(this.options.clientId) : void 0, this.domainUrl = (a = this.options.domain, /^https?:\/\//.test(a) ? a : "https://".concat(a)), this.tokenIssuer = ((l, u) => l ? l.startsWith("https://") ? l : "https://".concat(l, "/") : "".concat(u, "/"))(this.options.issuer, this.domainUrl);
3829
+ const s = "".concat(this.domainUrl, "/me/"), c = this.createFetcher(Object.assign(Object.assign({}, this.options.useDpop && { dpopNonceId: "__auth0_my_account_api__" }), { getAccessToken: () => this.getTokenSilently({ authorizationParams: { scope: "create:me:connected_accounts", audience: s }, detailedResponse: !0 }) }));
3830
+ this.myAccountApi = new zi(c, s), this.authJsClient = new os({ domain: this.options.domain, clientId: this.options.clientId }), this.mfa = new cs(this.authJsClient.mfa, this), typeof window < "u" && window.Worker && this.options.useRefreshTokens && t === _o && (this.options.workerUrl ? this.worker = new Worker(this.options.workerUrl) : this.worker = new Wi(), this.worker.postMessage({ type: "init", allowedBaseUrl: this.domainUrl }));
3831
+ }
3832
+ getConfiguration() {
3833
+ return Object.freeze({ domain: this.options.domain, clientId: this.options.clientId });
3834
+ }
3835
+ _url(e) {
3836
+ const t = this.options.auth0Client || Kn, o = Dn(t, !0), r = encodeURIComponent(btoa(JSON.stringify(o)));
3837
+ return "".concat(this.domainUrl).concat(e, "&auth0Client=").concat(r);
3838
+ }
3839
+ _authorizeUrl(e) {
3840
+ return this._url("/authorize?".concat(ut(e)));
3841
+ }
3842
+ async _verifyIdToken(e, t, o) {
3843
+ const r = await this.nowProvider();
3844
+ return Ai({ iss: this.tokenIssuer, aud: this.options.clientId, id_token: e, nonce: t, organization: o, leeway: this.options.leeway, max_age: (i = this.options.authorizationParams.max_age, typeof i != "string" ? i : parseInt(i, 10) || void 0), now: r });
3845
+ var i;
3846
+ }
3847
+ _processOrgHint(e) {
3848
+ e ? this.cookieStorage.save(this.orgHintCookieName, e, { daysUntilExpire: this.sessionCheckExpiryDays, cookieDomain: this.options.cookieDomain }) : this.cookieStorage.remove(this.orgHintCookieName, { cookieDomain: this.options.cookieDomain });
3849
+ }
3850
+ _extractSessionTransferToken(e) {
3851
+ return new URLSearchParams(window.location.search).get(e) || void 0;
3852
+ }
3853
+ _clearSessionTransferTokenFromUrl(e) {
3854
+ try {
3855
+ const t = new URL(window.location.href);
3856
+ t.searchParams.has(e) && (t.searchParams.delete(e), window.history.replaceState({}, "", t.toString()));
3857
+ } catch {
3858
+ }
3859
+ }
3860
+ _applySessionTransferToken(e) {
3861
+ const t = this.options.sessionTransferTokenQueryParamName;
3862
+ if (!t || e.session_transfer_token) return e;
3863
+ const o = this._extractSessionTransferToken(t);
3864
+ return o ? (this._clearSessionTransferTokenFromUrl(t), Object.assign(Object.assign({}, e), { session_transfer_token: o })) : e;
3865
+ }
3866
+ async _prepareAuthorizeUrl(e, t, o) {
3867
+ var r;
3868
+ const i = un(rt()), a = un(rt()), s = rt(), c = await So(s), l = Eo(c), u = await ((r = this.dpop) === null || r === void 0 ? void 0 : r.calculateThumbprint()), p = ((d, g, f, m, w, k, S, T, v) => Object.assign(Object.assign(Object.assign({ client_id: d.clientId }, d.authorizationParams), f), { scope: Rt(g, f.scope, f.audience), response_type: "code", response_mode: T || "query", state: m, nonce: w, redirect_uri: S || d.authorizationParams.redirect_uri, code_challenge: k, code_challenge_method: "S256", dpop_jkt: v }))(this.options, this.scope, e, i, a, l, e.redirect_uri || this.options.authorizationParams.redirect_uri || o, t == null ? void 0 : t.response_mode, u), h = this._authorizeUrl(p);
3869
+ return { nonce: a, code_verifier: s, scope: p.scope, audience: p.audience || H, redirect_uri: p.redirect_uri, state: i, url: h };
3870
+ }
3871
+ async loginWithPopup(e, t) {
3872
+ var o;
3873
+ if (e = e || {}, !(t = t || {}).popup && (t.popup = ((c) => {
3874
+ const l = window.screenX + (window.innerWidth - 400) / 2, u = window.screenY + (window.innerHeight - 600) / 2;
3875
+ return window.open(c, "auth0:authorize:popup", "left=".concat(l, ",top=").concat(u, ",width=").concat(400, ",height=").concat(600, ",resizable,scrollbars=yes,status=1"));
3876
+ })(""), !t.popup)) throw new oo();
3877
+ const r = this._applySessionTransferToken(e.authorizationParams || {}), i = await this._prepareAuthorizeUrl(r, { response_mode: "web_message" }, window.location.origin);
3878
+ t.popup.location.href = i.url;
3879
+ const a = await ((c, l) => new Promise((u, p) => {
3880
+ let h;
3881
+ const d = setInterval(() => {
3882
+ c.popup && c.popup.closed && (clearInterval(d), clearTimeout(g), window.removeEventListener("message", h, !1), p(new no(c.popup)));
3883
+ }, 1e3), g = setTimeout(() => {
3884
+ clearInterval(d), p(new to(c.popup)), window.removeEventListener("message", h, !1);
3885
+ }, 1e3 * (c.timeoutInSeconds || 60));
3886
+ h = function(f) {
3887
+ if (f.origin === l && f.data && f.data.type === "authorization_response") {
3888
+ if (clearTimeout(g), clearInterval(d), window.removeEventListener("message", h, !1), c.closePopup !== !1 && c.popup.close(), f.data.response.error) return p(j.fromPayload(f.data.response));
3889
+ u(f.data.response);
3890
+ }
3891
+ }, window.addEventListener("message", h);
3892
+ }))(Object.assign(Object.assign({}, t), { timeoutInSeconds: t.timeoutInSeconds || this.options.authorizeTimeoutInSeconds || 60 }), new URL(i.url).origin);
3893
+ if (i.state !== a.state) throw new j("state_mismatch", "Invalid state");
3894
+ const s = ((o = e.authorizationParams) === null || o === void 0 ? void 0 : o.organization) || this.options.authorizationParams.organization;
3895
+ await this._requestToken({ audience: i.audience, scope: i.scope, code_verifier: i.code_verifier, grant_type: "authorization_code", code: a.code, redirect_uri: i.redirect_uri }, { nonceIn: i.nonce, organization: s });
3896
+ }
3897
+ async getUser() {
3898
+ var e;
3899
+ const t = await this._getIdTokenFromCache();
3900
+ return (e = t == null ? void 0 : t.decodedToken) === null || e === void 0 ? void 0 : e.user;
3901
+ }
3902
+ async getIdTokenClaims() {
3903
+ var e;
3904
+ const t = await this._getIdTokenFromCache();
3905
+ return (e = t == null ? void 0 : t.decodedToken) === null || e === void 0 ? void 0 : e.claims;
3906
+ }
3907
+ async loginWithRedirect() {
3908
+ var e;
3909
+ const t = Co(arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}), { openUrl: o, fragment: r, appState: i } = t, a = te(t, ["openUrl", "fragment", "appState"]), s = ((e = a.authorizationParams) === null || e === void 0 ? void 0 : e.organization) || this.options.authorizationParams.organization, c = this._applySessionTransferToken(a.authorizationParams || {}), l = await this._prepareAuthorizeUrl(c), { url: u } = l, p = te(l, ["url"]);
3910
+ this.transactionManager.create(Object.assign(Object.assign(Object.assign({}, p), { appState: i, response_type: Ue.Code }), s && { organization: s }));
3911
+ const h = r ? "".concat(u, "#").concat(r) : u;
3912
+ o ? await o(h) : window.location.assign(h);
3913
+ }
3914
+ async handleRedirectCallback() {
3915
+ const e = (arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : window.location.href).split("?").slice(1);
3916
+ if (e.length === 0) throw new Error("There are no query params available for parsing.");
3917
+ const t = this.transactionManager.get();
3918
+ if (!t) throw new j("missing_transaction", "Invalid state");
3919
+ this.transactionManager.remove();
3920
+ const o = ((r) => {
3921
+ r.indexOf("#") > -1 && (r = r.substring(0, r.indexOf("#")));
3922
+ const i = new URLSearchParams(r);
3923
+ return { state: i.get("state"), code: i.get("code") || void 0, connect_code: i.get("connect_code") || void 0, error: i.get("error") || void 0, error_description: i.get("error_description") || void 0 };
3924
+ })(e.join(""));
3925
+ return t.response_type === Ue.ConnectCode ? this._handleConnectAccountRedirectCallback(o, t) : this._handleLoginRedirectCallback(o, t);
3926
+ }
3927
+ async _handleLoginRedirectCallback(e, t) {
3928
+ const { code: o, state: r, error: i, error_description: a } = e;
3929
+ if (i) throw new $n(i, a || i, r, t.appState);
3930
+ if (!t.code_verifier || t.state && t.state !== r) throw new j("state_mismatch", "Invalid state");
3931
+ const s = t.organization, c = t.nonce, l = t.redirect_uri;
3932
+ return await this._requestToken(Object.assign({ audience: t.audience, scope: t.scope, code_verifier: t.code_verifier, grant_type: "authorization_code", code: o }, l ? { redirect_uri: l } : {}), { nonceIn: c, organization: s }), { appState: t.appState, response_type: Ue.Code };
3933
+ }
3934
+ async _handleConnectAccountRedirectCallback(e, t) {
3935
+ const { connect_code: o, state: r, error: i, error_description: a } = e;
3936
+ if (i) throw new eo(i, a || i, t.connection, r, t.appState);
3937
+ if (!o) throw new j("missing_connect_code", "Missing connect code");
3938
+ if (!(t.code_verifier && t.state && t.auth_session && t.redirect_uri && t.state === r)) throw new j("state_mismatch", "Invalid state");
3939
+ const s = await this.myAccountApi.completeAccount({ auth_session: t.auth_session, connect_code: o, redirect_uri: t.redirect_uri, code_verifier: t.code_verifier });
3940
+ return Object.assign(Object.assign({}, s), { appState: t.appState, response_type: Ue.ConnectCode });
3941
+ }
3942
+ async checkSession(e) {
3943
+ if (!this.cookieStorage.get(this.isAuthenticatedCookieName)) {
3944
+ if (!this.cookieStorage.get(xo)) return;
3945
+ this.cookieStorage.save(this.isAuthenticatedCookieName, !0, { daysUntilExpire: this.sessionCheckExpiryDays, cookieDomain: this.options.cookieDomain }), this.cookieStorage.remove(xo);
3946
+ }
3947
+ try {
3948
+ await this.getTokenSilently(e);
3949
+ } catch {
3950
+ }
3951
+ }
3952
+ async getTokenSilently() {
3953
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
3954
+ var t, o;
3955
+ const r = Object.assign(Object.assign({ cacheMode: "on" }, e), { authorizationParams: Object.assign(Object.assign(Object.assign({}, this.options.authorizationParams), e.authorizationParams), { scope: Rt(this.scope, (t = e.authorizationParams) === null || t === void 0 ? void 0 : t.scope, ((o = e.authorizationParams) === null || o === void 0 ? void 0 : o.audience) || this.options.authorizationParams.audience) }) }), i = await ((a, s) => {
3956
+ let c = yn[s];
3957
+ return c || (c = a().finally(() => {
3958
+ delete yn[s], c = null;
3959
+ }), yn[s] = c), c;
3960
+ })(() => this._getTokenSilently(r), "".concat(this.options.clientId, "::").concat(r.authorizationParams.audience, "::").concat(r.authorizationParams.scope));
3961
+ return e.detailedResponse ? i : i == null ? void 0 : i.access_token;
3962
+ }
3963
+ async _getTokenSilently(e) {
3964
+ const { cacheMode: t } = e, o = te(e, ["cacheMode"]);
3965
+ if (t !== "off") {
3966
+ const s = await this._getEntryFromCache({ scope: o.authorizationParams.scope, audience: o.authorizationParams.audience || H, clientId: this.options.clientId, cacheMode: t });
3967
+ if (s) return s;
3968
+ }
3969
+ if (t === "cache-only") return;
3970
+ const r = (i = this.options.clientId, a = o.authorizationParams.audience || "default", "".concat("auth0.lock.getTokenSilently", ".").concat(i, ".").concat(a));
3971
+ var i, a;
3972
+ try {
3973
+ return await this.lockManager.runWithLock(r, 5e3, async () => {
3974
+ if (t !== "off") {
3975
+ const d = await this._getEntryFromCache({ scope: o.authorizationParams.scope, audience: o.authorizationParams.audience || H, clientId: this.options.clientId });
3976
+ if (d) return d;
3977
+ }
3978
+ const s = this.options.useRefreshTokens ? await this._getTokenUsingRefreshToken(o) : await this._getTokenFromIFrame(o), { id_token: c, token_type: l, access_token: u, oauthTokenScope: p, expires_in: h } = s;
3979
+ return Object.assign(Object.assign({ id_token: c, token_type: l, access_token: u }, p ? { scope: p } : null), { expires_in: h });
3980
+ });
3981
+ } catch (s) {
3982
+ if (this._isInteractiveError(s) && this.options.interactiveErrorHandler === "popup") return await this._handleInteractiveErrorWithPopup(o);
3983
+ throw s;
3984
+ }
3985
+ }
3986
+ _isInteractiveError(e) {
3987
+ return e instanceof $e || e instanceof j && this._isIframeMfaError(e);
3988
+ }
3989
+ _isIframeMfaError(e) {
3990
+ return e.error === "login_required" && e.error_description === "Multifactor authentication required";
3991
+ }
3992
+ async _handleInteractiveErrorWithPopup(e) {
3993
+ try {
3994
+ await this.loginWithPopup({ authorizationParams: e.authorizationParams });
3995
+ const t = await this._getEntryFromCache({ scope: e.authorizationParams.scope, audience: e.authorizationParams.audience || H, clientId: this.options.clientId });
3996
+ if (!t) throw new j("interactive_handler_cache_miss", "Token not found in cache after interactive authentication");
3997
+ return t;
3998
+ } catch (t) {
3999
+ throw t;
4000
+ }
4001
+ }
4002
+ async getTokenWithPopup() {
4003
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, t = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
4004
+ var o, r;
4005
+ const i = Object.assign(Object.assign({}, e), { authorizationParams: Object.assign(Object.assign(Object.assign({}, this.options.authorizationParams), e.authorizationParams), { scope: Rt(this.scope, (o = e.authorizationParams) === null || o === void 0 ? void 0 : o.scope, ((r = e.authorizationParams) === null || r === void 0 ? void 0 : r.audience) || this.options.authorizationParams.audience) }) });
4006
+ return t = Object.assign(Object.assign({}, oi), t), await this.loginWithPopup(i, t), (await this.cacheManager.get(new G({ scope: i.authorizationParams.scope, audience: i.authorizationParams.audience || H, clientId: this.options.clientId }), void 0, this.options.useMrrt)).access_token;
4007
+ }
4008
+ async isAuthenticated() {
4009
+ return !!await this.getUser();
4010
+ }
4011
+ _buildLogoutUrl(e) {
4012
+ e.clientId !== null ? e.clientId = e.clientId || this.options.clientId : delete e.clientId;
4013
+ const t = e.logoutParams || {}, { federated: o } = t, r = te(t, ["federated"]), i = o ? "&federated" : "";
4014
+ return this._url("/v2/logout?".concat(ut(Object.assign({ clientId: e.clientId }, r)))) + i;
4015
+ }
4016
+ async revokeRefreshToken() {
4017
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
4018
+ if (!this.options.useRefreshTokens) return;
4019
+ const t = e.audience || this.options.authorizationParams.audience || H, o = await this.cacheManager.getRefreshTokensByAudience(t, this.options.clientId);
4020
+ await (async function(r, i) {
4021
+ let { baseUrl: a, timeout: s, auth0Client: c, useFormData: l, refreshTokens: u, audience: p, client_id: h, onRefreshTokenRevoked: d } = r;
4022
+ const g = s || Un, f = "refresh_token", m = "".concat(a, "/oauth/revoke"), w = { "Content-Type": l ? "application/x-www-form-urlencoded" : "application/json", "Auth0-Client": btoa(JSON.stringify(Dn(c || Kn))) };
4023
+ if (i) {
4024
+ const k = { client_id: h, token_type_hint: f }, S = l ? ut(k) : JSON.stringify(k);
4025
+ return dr({ type: "revoke", timeout: g, fetchUrl: m, fetchOptions: { method: "POST", body: S, headers: w }, useFormData: l, auth: { audience: p ?? H } }, i);
4026
+ }
4027
+ for (const k of u) {
4028
+ const S = { client_id: h, token_type_hint: f, token: k }, T = l ? ut(S) : JSON.stringify(S), v = await pr(m, { method: "POST", body: T, headers: w }, g);
4029
+ if (!v.ok) {
4030
+ let R, z;
4031
+ try {
4032
+ ({ error: R, error_description: z } = JSON.parse(await v.text()));
4033
+ } catch {
4034
+ }
4035
+ throw new j(R || "revoke_error", z || "HTTP error ".concat(v.status));
4036
+ }
4037
+ await (d == null ? void 0 : d(k));
4038
+ }
4039
+ })({ baseUrl: this.domainUrl, timeout: this.httpTimeoutMs, auth0Client: this.options.auth0Client, useFormData: this.options.useFormData, client_id: this.options.clientId, refreshTokens: o, audience: t, onRefreshTokenRevoked: (r) => this.cacheManager.stripRefreshToken(r) }, this.worker);
4040
+ }
4041
+ async logout() {
4042
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
4043
+ var t;
4044
+ const o = Co(e), { openUrl: r } = o, i = te(o, ["openUrl"]);
4045
+ e.clientId === null ? await this.cacheManager.clear() : await this.cacheManager.clear(e.clientId || this.options.clientId), this.cookieStorage.remove(this.orgHintCookieName, { cookieDomain: this.options.cookieDomain }), this.cookieStorage.remove(this.isAuthenticatedCookieName, { cookieDomain: this.options.cookieDomain }), this.userCache.remove(Fe), await ((t = this.dpop) === null || t === void 0 ? void 0 : t.clear());
4046
+ const a = this._buildLogoutUrl(i);
4047
+ r ? await r(a) : r !== !1 && window.location.assign(a);
4048
+ }
4049
+ async _getTokenFromIFrame(e) {
4050
+ const t = (o = this.options.clientId, "".concat("auth0.lock.getTokenFromIFrame", ".").concat(o));
4051
+ var o;
4052
+ try {
4053
+ return await this.lockManager.runWithLock(t, 5e3, async () => {
4054
+ const r = Object.assign(Object.assign({}, e.authorizationParams), { prompt: "none" }), i = this.cookieStorage.get(this.orgHintCookieName);
4055
+ i && !r.organization && (r.organization = i);
4056
+ const { url: a, state: s, nonce: c, code_verifier: l, redirect_uri: u, scope: p, audience: h } = await this._prepareAuthorizeUrl(r, { response_mode: "web_message" }, window.location.origin);
4057
+ if (window.crossOriginIsolated) throw new j("login_required", "The application is running in a Cross-Origin Isolated context, silently retrieving a token without refresh token is not possible.");
4058
+ const d = e.timeoutInSeconds || this.options.authorizeTimeoutInSeconds;
4059
+ let g;
4060
+ try {
4061
+ g = new URL(this.domainUrl).origin;
4062
+ } catch {
4063
+ g = this.domainUrl;
4064
+ }
4065
+ const f = await (function(w, k) {
4066
+ let S = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 60;
4067
+ return new Promise((T, v) => {
4068
+ const R = window.document.createElement("iframe");
4069
+ R.setAttribute("width", "0"), R.setAttribute("height", "0"), R.style.display = "none";
4070
+ const z = () => {
4071
+ window.document.body.contains(R) && (window.document.body.removeChild(R), window.removeEventListener("message", K, !1));
4072
+ };
4073
+ let K;
4074
+ const we = setTimeout(() => {
4075
+ v(new nt()), z();
4076
+ }, 1e3 * S);
4077
+ K = function(V) {
4078
+ if (V.origin != k || !V.data || V.data.type !== "authorization_response") return;
4079
+ const He = V.source;
4080
+ He && He.close(), V.data.response.error ? v(j.fromPayload(V.data.response)) : T(V.data.response), clearTimeout(we), window.removeEventListener("message", K, !1), setTimeout(z, 2e3);
4081
+ }, window.addEventListener("message", K, !1), window.document.body.appendChild(R), R.setAttribute("src", w);
4082
+ });
4083
+ })(a, g, d);
4084
+ if (s !== f.state) throw new j("state_mismatch", "Invalid state");
4085
+ const m = await this._requestToken(Object.assign(Object.assign({}, e.authorizationParams), { code_verifier: l, code: f.code, grant_type: "authorization_code", redirect_uri: u, timeout: e.authorizationParams.timeout || this.httpTimeoutMs }), { nonceIn: c, organization: r.organization });
4086
+ return Object.assign(Object.assign({}, m), { scope: p, oauthTokenScope: m.scope, audience: h });
4087
+ });
4088
+ } catch (r) {
4089
+ throw r.error === "login_required" && (r instanceof j && this._isIframeMfaError(r) && this.options.interactiveErrorHandler === "popup" || this.logout({ openUrl: !1 })), r;
4090
+ }
4091
+ }
4092
+ async _getTokenUsingRefreshToken(e) {
4093
+ var t, o;
4094
+ const r = await this.cacheManager.get(new G({ scope: e.authorizationParams.scope, audience: e.authorizationParams.audience || H, clientId: this.options.clientId }), void 0, this.options.useMrrt);
4095
+ if (!(r && r.refresh_token || this.worker)) {
4096
+ if (this.options.useRefreshTokensFallback) return await this._getTokenFromIFrame(e);
4097
+ throw new tn(e.authorizationParams.audience || H, e.authorizationParams.scope);
4098
+ }
4099
+ const i = e.authorizationParams.redirect_uri || this.options.authorizationParams.redirect_uri || window.location.origin, a = typeof e.timeoutInSeconds == "number" ? 1e3 * e.timeoutInSeconds : null, s = ((h, d, g, f) => {
4100
+ var m;
4101
+ if (h && g && f) {
4102
+ if (d.audience !== g) return d.scope;
4103
+ const w = f.split(" "), k = ((m = d.scope) === null || m === void 0 ? void 0 : m.split(" ")) || [], S = k.every((T) => w.includes(T));
4104
+ return w.length >= k.length && S ? f : d.scope;
4105
+ }
4106
+ return d.scope;
4107
+ })(this.options.useMrrt, e.authorizationParams, r == null ? void 0 : r.audience, r == null ? void 0 : r.scope);
4108
+ try {
4109
+ const h = await this._requestToken(Object.assign(Object.assign(Object.assign({}, e.authorizationParams), { grant_type: "refresh_token", refresh_token: r && r.refresh_token, redirect_uri: i }), a && { timeout: a }), { scopesToRequest: s });
4110
+ if (h.refresh_token && (r != null && r.refresh_token) && await this.cacheManager.updateEntry(r.refresh_token, h.refresh_token), this.options.useMrrt && (c = r == null ? void 0 : r.audience, l = r == null ? void 0 : r.scope, u = e.authorizationParams.audience, p = e.authorizationParams.scope, (c !== u || !jo(p, l)) && !jo(s, h.scope))) {
4111
+ if (this.options.useRefreshTokensFallback) return await this._getTokenFromIFrame(e);
4112
+ await this.cacheManager.remove(this.options.clientId, e.authorizationParams.audience, e.authorizationParams.scope);
4113
+ const d = ((g, f) => {
4114
+ const m = (g == null ? void 0 : g.split(" ")) || [], w = (f == null ? void 0 : f.split(" ")) || [];
4115
+ return m.filter((k) => w.indexOf(k) == -1).join(",");
4116
+ })(s, h.scope);
4117
+ throw new ro(e.authorizationParams.audience || "default", d);
4118
+ }
4119
+ return Object.assign(Object.assign({}, h), { scope: e.authorizationParams.scope, oauthTokenScope: h.scope, audience: e.authorizationParams.audience || H });
4120
+ } catch (h) {
4121
+ if (h.message) {
4122
+ if (h.message.includes("user is blocked")) throw await this.logout({ openUrl: !1 }), h;
4123
+ if ((h.message.includes("Missing Refresh Token") || h.message.includes("invalid refresh token")) && this.options.useRefreshTokensFallback) return await this._getTokenFromIFrame(e);
4124
+ }
4125
+ throw h instanceof $e && this.mfa.setMFAAuthDetails(h.mfa_token, (t = e.authorizationParams) === null || t === void 0 ? void 0 : t.scope, (o = e.authorizationParams) === null || o === void 0 ? void 0 : o.audience, h.mfa_requirements), h;
4126
+ }
4127
+ var c, l, u, p;
4128
+ }
4129
+ async _saveEntryInCache(e) {
4130
+ const { id_token: t, decodedToken: o } = e, r = te(e, ["id_token", "decodedToken"]);
4131
+ this.userCache.set(Fe, { id_token: t, decodedToken: o }), await this.cacheManager.setIdToken(this.options.clientId, e.id_token, e.decodedToken), await this.cacheManager.set(r);
4132
+ }
4133
+ async _getIdTokenFromCache() {
4134
+ const e = this.options.authorizationParams.audience || H, t = this.scope[e], o = await this.cacheManager.getIdToken(new G({ clientId: this.options.clientId, audience: e, scope: t })), r = this.userCache.get(Fe);
4135
+ return o && o.id_token === (r == null ? void 0 : r.id_token) ? r : (this.userCache.set(Fe, o), o);
4136
+ }
4137
+ async _getEntryFromCache(e) {
4138
+ let { scope: t, audience: o, clientId: r, cacheMode: i } = e;
4139
+ const a = await this.cacheManager.get(new G({ scope: t, audience: o, clientId: r }), 60, this.options.useMrrt, i);
4140
+ if (a && a.access_token) {
4141
+ const { token_type: s, access_token: c, oauthTokenScope: l, expires_in: u } = a, p = await this._getIdTokenFromCache();
4142
+ return p && Object.assign(Object.assign({ id_token: p.id_token, token_type: s || "Bearer", access_token: c }, l ? { scope: l } : null), { expires_in: u });
4143
+ }
4144
+ }
4145
+ async _requestToken(e, t) {
4146
+ var o, r;
4147
+ const { nonceIn: i, organization: a, scopesToRequest: s } = t || {}, c = await _i(Object.assign(Object.assign({ baseUrl: this.domainUrl, client_id: this.options.clientId, auth0Client: this.options.auth0Client, useFormData: this.options.useFormData, timeout: this.httpTimeoutMs, useMrrt: this.options.useMrrt, dpop: this.dpop }, e), { scope: s || e.scope }), this.worker), l = await this._verifyIdToken(c.id_token, i, a);
4148
+ if (e.grant_type === "authorization_code") {
4149
+ const u = await this._getIdTokenFromCache();
4150
+ !((r = (o = u == null ? void 0 : u.decodedToken) === null || o === void 0 ? void 0 : o.claims) === null || r === void 0) && r.sub && u.decodedToken.claims.sub !== l.claims.sub && (await this.cacheManager.clear(this.options.clientId), this.userCache.remove(Fe));
4151
+ }
4152
+ return await this._saveEntryInCache(Object.assign(Object.assign(Object.assign(Object.assign({}, c), { decodedToken: l, scope: e.scope, audience: e.audience || H }), c.scope ? { oauthTokenScope: c.scope } : null), { client_id: this.options.clientId })), this.cookieStorage.save(this.isAuthenticatedCookieName, !0, { daysUntilExpire: this.sessionCheckExpiryDays, cookieDomain: this.options.cookieDomain }), this._processOrgHint(a || l.claims.org_id), Object.assign(Object.assign({}, c), { decodedToken: l });
4153
+ }
4154
+ async loginWithCustomTokenExchange(e) {
4155
+ return this._requestToken(Object.assign(Object.assign({}, e), { grant_type: "urn:ietf:params:oauth:grant-type:token-exchange", subject_token: e.subject_token, subject_token_type: e.subject_token_type, scope: Rt(this.scope, e.scope, e.audience || this.options.authorizationParams.audience), audience: e.audience || this.options.authorizationParams.audience, organization: e.organization || this.options.authorizationParams.organization }));
4156
+ }
4157
+ async exchangeToken(e) {
4158
+ return this.loginWithCustomTokenExchange(e);
4159
+ }
4160
+ _assertDpop(e) {
4161
+ if (!e) throw new Error("`useDpop` option must be enabled before using DPoP.");
4162
+ }
4163
+ getDpopNonce(e) {
4164
+ return this._assertDpop(this.dpop), this.dpop.getNonce(e);
4165
+ }
4166
+ setDpopNonce(e, t) {
4167
+ return this._assertDpop(this.dpop), this.dpop.setNonce(e, t);
4168
+ }
4169
+ generateDpopProof(e) {
4170
+ return this._assertDpop(this.dpop), this.dpop.generateProof(e);
4171
+ }
4172
+ createFetcher() {
4173
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
4174
+ return new Li(e, { isDpopEnabled: () => !!this.options.useDpop, getAccessToken: (t) => {
4175
+ var o;
4176
+ return this.getTokenSilently({ authorizationParams: { scope: (o = t == null ? void 0 : t.scope) === null || o === void 0 ? void 0 : o.join(" "), audience: t == null ? void 0 : t.audience }, detailedResponse: !0 });
4177
+ }, getDpopNonce: () => this.getDpopNonce(e.dpopNonceId), setDpopNonce: (t) => this.setDpopNonce(t, e.dpopNonceId), generateDpopProof: (t) => this.generateDpopProof(t) });
4178
+ }
4179
+ async connectAccountWithRedirect(e) {
4180
+ const { openUrl: t, appState: o, connection: r, scopes: i, authorization_params: a, redirectUri: s = this.options.authorizationParams.redirect_uri || window.location.origin } = e;
4181
+ if (!r) throw new Error("connection is required");
4182
+ const c = un(rt()), l = rt(), u = await So(l), p = Eo(u), { connect_uri: h, connect_params: d, auth_session: g } = await this.myAccountApi.connectAccount({ connection: r, scopes: i, redirect_uri: s, state: c, code_challenge: p, code_challenge_method: "S256", authorization_params: a });
4183
+ this.transactionManager.create({ state: c, code_verifier: l, auth_session: g, redirect_uri: s, appState: o, connection: r, response_type: Ue.ConnectCode });
4184
+ const f = new URL(h);
4185
+ f.searchParams.set("ticket", d.ticket), t ? await t(f.toString()) : window.location.assign(f);
4186
+ }
4187
+ async _requestTokenForMfa(e, t) {
4188
+ const { mfaToken: o } = e, r = te(e, ["mfaToken"]);
4189
+ return this._requestToken(Object.assign(Object.assign({}, r), { mfa_token: o }), t);
4190
+ }
4191
+ }
4192
+ export {
4193
+ us as Auth0Client,
4194
+ $n as AuthenticationError,
4195
+ G as CacheKey,
4196
+ eo as ConnectError,
4197
+ j as GenericError,
4198
+ fr as InMemoryCache,
4199
+ Si as LocalStorageCache,
4200
+ cs as MfaApiClient,
4201
+ vo as MfaChallengeError,
4202
+ wo as MfaEnrollmentError,
4203
+ bo as MfaEnrollmentFactorsError,
4204
+ Ae as MfaError,
4205
+ en as MfaListAuthenticatorsError,
4206
+ $e as MfaRequiredError,
4207
+ qe as MfaVerifyError,
4208
+ tn as MissingRefreshTokenError,
4209
+ Ft as MyAccountApiError,
4210
+ no as PopupCancelledError,
4211
+ oo as PopupOpenError,
4212
+ to as PopupTimeoutError,
4213
+ Ue as ResponseType,
4214
+ nt as TimeoutError,
4215
+ nn as UseDpopNonceError
4216
+ };
4217
+ //# sourceMappingURL=auth0-spa-js.production.esm-Cr9w0sUa.js.map