@wandelbots/wandelbots-js-react-components 3.5.1 → 3.6.0-pr.feat-model-retrieval-from-rdp.463.014e7d3

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