mp-front-cli 0.0.28 → 0.0.30

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.
@@ -0,0 +1,4696 @@
1
+ var Xr = Object.defineProperty;
2
+ var Yr = (t, e, r) => e in t ? Xr(t, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : t[e] = r;
3
+ var Kt = (t, e, r) => (Yr(t, typeof e != "symbol" ? e + "" : e, r), r);
4
+ import { g as ft, C as Zr } from "./custom-encoder-b2078b5c.js";
5
+ import { CustomLogger as jt } from "./mp-front-cli-logger.es.js";
6
+ import { t as Qr } from "./index-6f6eb615.js";
7
+ const jr = {
8
+ type: "logger",
9
+ log(t) {
10
+ this.output("log", t);
11
+ },
12
+ warn(t) {
13
+ this.output("warn", t);
14
+ },
15
+ error(t) {
16
+ this.output("error", t);
17
+ },
18
+ output(t, e) {
19
+ console && console[t] && console[t].apply(console, e);
20
+ }
21
+ };
22
+ class xe {
23
+ constructor(e) {
24
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
25
+ this.init(e, r);
26
+ }
27
+ init(e) {
28
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
29
+ this.prefix = r.prefix || "i18next:", this.logger = e || jr, this.options = r, this.debug = r.debug;
30
+ }
31
+ log() {
32
+ for (var e = arguments.length, r = new Array(e), n = 0; n < e; n++)
33
+ r[n] = arguments[n];
34
+ return this.forward(r, "log", "", !0);
35
+ }
36
+ warn() {
37
+ for (var e = arguments.length, r = new Array(e), n = 0; n < e; n++)
38
+ r[n] = arguments[n];
39
+ return this.forward(r, "warn", "", !0);
40
+ }
41
+ error() {
42
+ for (var e = arguments.length, r = new Array(e), n = 0; n < e; n++)
43
+ r[n] = arguments[n];
44
+ return this.forward(r, "error", "");
45
+ }
46
+ deprecate() {
47
+ for (var e = arguments.length, r = new Array(e), n = 0; n < e; n++)
48
+ r[n] = arguments[n];
49
+ return this.forward(r, "warn", "WARNING DEPRECATED: ", !0);
50
+ }
51
+ forward(e, r, n, a) {
52
+ return a && !this.debug ? null : (typeof e[0] == "string" && (e[0] = `${n}${this.prefix} ${e[0]}`), this.logger[r](e));
53
+ }
54
+ create(e) {
55
+ return new xe(this.logger, {
56
+ prefix: `${this.prefix}:${e}:`,
57
+ ...this.options
58
+ });
59
+ }
60
+ clone(e) {
61
+ return e = e || this.options, e.prefix = e.prefix || this.prefix, new xe(this.logger, e);
62
+ }
63
+ }
64
+ var Z = new xe();
65
+ class Ue {
66
+ constructor() {
67
+ this.observers = {};
68
+ }
69
+ on(e, r) {
70
+ return e.split(" ").forEach((n) => {
71
+ this.observers[n] = this.observers[n] || [], this.observers[n].push(r);
72
+ }), this;
73
+ }
74
+ off(e, r) {
75
+ if (this.observers[e]) {
76
+ if (!r) {
77
+ delete this.observers[e];
78
+ return;
79
+ }
80
+ this.observers[e] = this.observers[e].filter((n) => n !== r);
81
+ }
82
+ }
83
+ emit(e) {
84
+ for (var r = arguments.length, n = new Array(r > 1 ? r - 1 : 0), a = 1; a < r; a++)
85
+ n[a - 1] = arguments[a];
86
+ this.observers[e] && [].concat(this.observers[e]).forEach((i) => {
87
+ i(...n);
88
+ }), this.observers["*"] && [].concat(this.observers["*"]).forEach((i) => {
89
+ i.apply(i, [e, ...n]);
90
+ });
91
+ }
92
+ }
93
+ function he() {
94
+ let t, e;
95
+ const r = new Promise((n, a) => {
96
+ t = n, e = a;
97
+ });
98
+ return r.resolve = t, r.reject = e, r;
99
+ }
100
+ function Rt(t) {
101
+ return t == null ? "" : "" + t;
102
+ }
103
+ function en(t, e, r) {
104
+ t.forEach((n) => {
105
+ e[n] && (r[n] = e[n]);
106
+ });
107
+ }
108
+ function ht(t, e, r) {
109
+ function n(i) {
110
+ return i && i.indexOf("###") > -1 ? i.replace(/###/g, ".") : i;
111
+ }
112
+ function a() {
113
+ return !t || typeof t == "string";
114
+ }
115
+ const s = typeof e != "string" ? [].concat(e) : e.split(".");
116
+ for (; s.length > 1; ) {
117
+ if (a())
118
+ return {};
119
+ const i = n(s.shift());
120
+ !t[i] && r && (t[i] = new r()), Object.prototype.hasOwnProperty.call(t, i) ? t = t[i] : t = {};
121
+ }
122
+ return a() ? {} : {
123
+ obj: t,
124
+ k: n(s.shift())
125
+ };
126
+ }
127
+ function Ot(t, e, r) {
128
+ const {
129
+ obj: n,
130
+ k: a
131
+ } = ht(t, e, Object);
132
+ n[a] = r;
133
+ }
134
+ function tn(t, e, r, n) {
135
+ const {
136
+ obj: a,
137
+ k: s
138
+ } = ht(t, e, Object);
139
+ a[s] = a[s] || [], n && (a[s] = a[s].concat(r)), n || a[s].push(r);
140
+ }
141
+ function Ce(t, e) {
142
+ const {
143
+ obj: r,
144
+ k: n
145
+ } = ht(t, e);
146
+ if (r)
147
+ return r[n];
148
+ }
149
+ function rn(t, e, r) {
150
+ const n = Ce(t, r);
151
+ return n !== void 0 ? n : Ce(e, r);
152
+ }
153
+ function er(t, e, r) {
154
+ for (const n in e)
155
+ n !== "__proto__" && n !== "constructor" && (n in t ? typeof t[n] == "string" || t[n] instanceof String || typeof e[n] == "string" || e[n] instanceof String ? r && (t[n] = e[n]) : er(t[n], e[n], r) : t[n] = e[n]);
156
+ return t;
157
+ }
158
+ function oe(t) {
159
+ return t.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
160
+ }
161
+ var nn = {
162
+ "&": "&amp;",
163
+ "<": "&lt;",
164
+ ">": "&gt;",
165
+ '"': "&quot;",
166
+ "'": "&#39;",
167
+ "/": "&#x2F;"
168
+ };
169
+ function an(t) {
170
+ return typeof t == "string" ? t.replace(/[&<>"'\/]/g, (e) => nn[e]) : t;
171
+ }
172
+ const sn = [" ", ",", "?", "!", ";"];
173
+ function on(t, e, r) {
174
+ e = e || "", r = r || "";
175
+ const n = sn.filter((i) => e.indexOf(i) < 0 && r.indexOf(i) < 0);
176
+ if (n.length === 0)
177
+ return !0;
178
+ const a = new RegExp(`(${n.map((i) => i === "?" ? "\\?" : i).join("|")})`);
179
+ let s = !a.test(t);
180
+ if (!s) {
181
+ const i = t.indexOf(r);
182
+ i > 0 && !a.test(t.substring(0, i)) && (s = !0);
183
+ }
184
+ return s;
185
+ }
186
+ function _e(t, e) {
187
+ let r = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : ".";
188
+ if (!t)
189
+ return;
190
+ if (t[e])
191
+ return t[e];
192
+ const n = e.split(r);
193
+ let a = t;
194
+ for (let s = 0; s < n.length; ++s) {
195
+ if (!a || typeof a[n[s]] == "string" && s + 1 < n.length)
196
+ return;
197
+ if (a[n[s]] === void 0) {
198
+ let i = 2, o = n.slice(s, s + i).join(r), c = a[o];
199
+ for (; c === void 0 && n.length > s + i; )
200
+ i++, o = n.slice(s, s + i).join(r), c = a[o];
201
+ if (c === void 0)
202
+ return;
203
+ if (c === null)
204
+ return null;
205
+ if (e.endsWith(o)) {
206
+ if (typeof c == "string")
207
+ return c;
208
+ if (o && typeof c[o] == "string")
209
+ return c[o];
210
+ }
211
+ const u = n.slice(s + i).join(r);
212
+ return u ? _e(c, u, r) : void 0;
213
+ }
214
+ a = a[n[s]];
215
+ }
216
+ return a;
217
+ }
218
+ function Pe(t) {
219
+ return t && t.indexOf("_") > 0 ? t.replace("_", "-") : t;
220
+ }
221
+ class Tt extends Ue {
222
+ constructor(e) {
223
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
224
+ ns: ["translation"],
225
+ defaultNS: "translation"
226
+ };
227
+ super(), this.data = e || {}, this.options = r, this.options.keySeparator === void 0 && (this.options.keySeparator = "."), this.options.ignoreJSONStructure === void 0 && (this.options.ignoreJSONStructure = !0);
228
+ }
229
+ addNamespaces(e) {
230
+ this.options.ns.indexOf(e) < 0 && this.options.ns.push(e);
231
+ }
232
+ removeNamespaces(e) {
233
+ const r = this.options.ns.indexOf(e);
234
+ r > -1 && this.options.ns.splice(r, 1);
235
+ }
236
+ getResource(e, r, n) {
237
+ let a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
238
+ const s = a.keySeparator !== void 0 ? a.keySeparator : this.options.keySeparator, i = a.ignoreJSONStructure !== void 0 ? a.ignoreJSONStructure : this.options.ignoreJSONStructure;
239
+ let o = [e, r];
240
+ n && typeof n != "string" && (o = o.concat(n)), n && typeof n == "string" && (o = o.concat(s ? n.split(s) : n)), e.indexOf(".") > -1 && (o = e.split("."));
241
+ const c = Ce(this.data, o);
242
+ return c || !i || typeof n != "string" ? c : _e(this.data && this.data[e] && this.data[e][r], n, s);
243
+ }
244
+ addResource(e, r, n, a) {
245
+ let s = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : {
246
+ silent: !1
247
+ };
248
+ const i = s.keySeparator !== void 0 ? s.keySeparator : this.options.keySeparator;
249
+ let o = [e, r];
250
+ n && (o = o.concat(i ? n.split(i) : n)), e.indexOf(".") > -1 && (o = e.split("."), a = r, r = o[1]), this.addNamespaces(r), Ot(this.data, o, a), s.silent || this.emit("added", e, r, n, a);
251
+ }
252
+ addResources(e, r, n) {
253
+ let a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {
254
+ silent: !1
255
+ };
256
+ for (const s in n)
257
+ (typeof n[s] == "string" || Object.prototype.toString.apply(n[s]) === "[object Array]") && this.addResource(e, r, s, n[s], {
258
+ silent: !0
259
+ });
260
+ a.silent || this.emit("added", e, r, n);
261
+ }
262
+ addResourceBundle(e, r, n, a, s) {
263
+ let i = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {
264
+ silent: !1
265
+ }, o = [e, r];
266
+ e.indexOf(".") > -1 && (o = e.split("."), a = n, n = r, r = o[1]), this.addNamespaces(r);
267
+ let c = Ce(this.data, o) || {};
268
+ a ? er(c, n, s) : c = {
269
+ ...c,
270
+ ...n
271
+ }, Ot(this.data, o, c), i.silent || this.emit("added", e, r, n);
272
+ }
273
+ removeResourceBundle(e, r) {
274
+ this.hasResourceBundle(e, r) && delete this.data[e][r], this.removeNamespaces(r), this.emit("removed", e, r);
275
+ }
276
+ hasResourceBundle(e, r) {
277
+ return this.getResource(e, r) !== void 0;
278
+ }
279
+ getResourceBundle(e, r) {
280
+ return r || (r = this.options.defaultNS), this.options.compatibilityAPI === "v1" ? {
281
+ ...this.getResource(e, r)
282
+ } : this.getResource(e, r);
283
+ }
284
+ getDataByLanguage(e) {
285
+ return this.data[e];
286
+ }
287
+ hasLanguageSomeTranslations(e) {
288
+ const r = this.getDataByLanguage(e);
289
+ return !!(r && Object.keys(r) || []).find((a) => r[a] && Object.keys(r[a]).length > 0);
290
+ }
291
+ toJSON() {
292
+ return this.data;
293
+ }
294
+ }
295
+ var tr = {
296
+ processors: {},
297
+ addPostProcessor(t) {
298
+ this.processors[t.name] = t;
299
+ },
300
+ handle(t, e, r, n, a) {
301
+ return t.forEach((s) => {
302
+ this.processors[s] && (e = this.processors[s].process(e, r, n, a));
303
+ }), e;
304
+ }
305
+ };
306
+ const It = {};
307
+ class He extends Ue {
308
+ constructor(e) {
309
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
310
+ super(), en(["resourceStore", "languageUtils", "pluralResolver", "interpolator", "backendConnector", "i18nFormat", "utils"], e, this), this.options = r, this.options.keySeparator === void 0 && (this.options.keySeparator = "."), this.logger = Z.create("translator");
311
+ }
312
+ changeLanguage(e) {
313
+ e && (this.language = e);
314
+ }
315
+ exists(e) {
316
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
317
+ interpolation: {}
318
+ };
319
+ if (e == null)
320
+ return !1;
321
+ const n = this.resolve(e, r);
322
+ return n && n.res !== void 0;
323
+ }
324
+ extractFromKey(e, r) {
325
+ let n = r.nsSeparator !== void 0 ? r.nsSeparator : this.options.nsSeparator;
326
+ n === void 0 && (n = ":");
327
+ const a = r.keySeparator !== void 0 ? r.keySeparator : this.options.keySeparator;
328
+ let s = r.ns || this.options.defaultNS || [];
329
+ const i = n && e.indexOf(n) > -1, o = !this.options.userDefinedKeySeparator && !r.keySeparator && !this.options.userDefinedNsSeparator && !r.nsSeparator && !on(e, n, a);
330
+ if (i && !o) {
331
+ const c = e.match(this.interpolator.nestingRegexp);
332
+ if (c && c.length > 0)
333
+ return {
334
+ key: e,
335
+ namespaces: s
336
+ };
337
+ const u = e.split(n);
338
+ (n !== a || n === a && this.options.ns.indexOf(u[0]) > -1) && (s = u.shift()), e = u.join(a);
339
+ }
340
+ return typeof s == "string" && (s = [s]), {
341
+ key: e,
342
+ namespaces: s
343
+ };
344
+ }
345
+ translate(e, r, n) {
346
+ if (typeof r != "object" && this.options.overloadTranslationOptionHandler && (r = this.options.overloadTranslationOptionHandler(arguments)), typeof r == "object" && (r = {
347
+ ...r
348
+ }), r || (r = {}), e == null)
349
+ return "";
350
+ Array.isArray(e) || (e = [String(e)]);
351
+ const a = r.returnDetails !== void 0 ? r.returnDetails : this.options.returnDetails, s = r.keySeparator !== void 0 ? r.keySeparator : this.options.keySeparator, {
352
+ key: i,
353
+ namespaces: o
354
+ } = this.extractFromKey(e[e.length - 1], r), c = o[o.length - 1], u = r.lng || this.language, l = r.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
355
+ if (u && u.toLowerCase() === "cimode") {
356
+ if (l) {
357
+ const m = r.nsSeparator || this.options.nsSeparator;
358
+ return a ? {
359
+ res: `${c}${m}${i}`,
360
+ usedKey: i,
361
+ exactUsedKey: i,
362
+ usedLng: u,
363
+ usedNS: c,
364
+ usedParams: this.getUsedParamsDetails(r)
365
+ } : `${c}${m}${i}`;
366
+ }
367
+ return a ? {
368
+ res: i,
369
+ usedKey: i,
370
+ exactUsedKey: i,
371
+ usedLng: u,
372
+ usedNS: c,
373
+ usedParams: this.getUsedParamsDetails(r)
374
+ } : i;
375
+ }
376
+ const f = this.resolve(e, r);
377
+ let d = f && f.res;
378
+ const p = f && f.usedKey || i, h = f && f.exactUsedKey || i, g = Object.prototype.toString.apply(d), S = ["[object Number]", "[object Function]", "[object RegExp]"], C = r.joinArrays !== void 0 ? r.joinArrays : this.options.joinArrays, v = !this.i18nFormat || this.i18nFormat.handleAsObject;
379
+ if (v && d && (typeof d != "string" && typeof d != "boolean" && typeof d != "number") && S.indexOf(g) < 0 && !(typeof C == "string" && g === "[object Array]")) {
380
+ if (!r.returnObjects && !this.options.returnObjects) {
381
+ this.options.returnedObjectHandler || this.logger.warn("accessing an object - but returnObjects options is not enabled!");
382
+ const m = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(p, d, {
383
+ ...r,
384
+ ns: o
385
+ }) : `key '${i} (${this.language})' returned an object instead of string.`;
386
+ return a ? (f.res = m, f.usedParams = this.getUsedParamsDetails(r), f) : m;
387
+ }
388
+ if (s) {
389
+ const m = g === "[object Array]", E = m ? [] : {}, _ = m ? h : p;
390
+ for (const A in d)
391
+ if (Object.prototype.hasOwnProperty.call(d, A)) {
392
+ const R = `${_}${s}${A}`;
393
+ E[A] = this.translate(R, {
394
+ ...r,
395
+ joinArrays: !1,
396
+ ns: o
397
+ }), E[A] === R && (E[A] = d[A]);
398
+ }
399
+ d = E;
400
+ }
401
+ } else if (v && typeof C == "string" && g === "[object Array]")
402
+ d = d.join(C), d && (d = this.extendTranslation(d, e, r, n));
403
+ else {
404
+ let m = !1, E = !1;
405
+ const _ = r.count !== void 0 && typeof r.count != "string", A = He.hasDefaultValue(r), R = _ ? this.pluralResolver.getSuffix(u, r.count, r) : "", F = r.ordinal && _ ? this.pluralResolver.getSuffix(u, r.count, {
406
+ ordinal: !1
407
+ }) : "", q = _ && !r.ordinal && r.count === 0 && this.pluralResolver.shouldUseIntlApi(), Y = q && r[`defaultValue${this.options.pluralSeparator}zero`] || r[`defaultValue${R}`] || r[`defaultValue${F}`] || r.defaultValue;
408
+ !this.isValidLookup(d) && A && (m = !0, d = Y), this.isValidLookup(d) || (E = !0, d = i);
409
+ const qr = (r.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey) && E ? void 0 : d, le = A && Y !== d && this.options.updateMissing;
410
+ if (E || m || le) {
411
+ if (this.logger.log(le ? "updateKey" : "missingKey", u, c, i, le ? Y : d), s) {
412
+ const z = this.resolve(i, {
413
+ ...r,
414
+ keySeparator: !1
415
+ });
416
+ z && z.res && this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
417
+ }
418
+ let de = [];
419
+ const we = this.languageUtils.getFallbackCodes(this.options.fallbackLng, r.lng || this.language);
420
+ if (this.options.saveMissingTo === "fallback" && we && we[0])
421
+ for (let z = 0; z < we.length; z++)
422
+ de.push(we[z]);
423
+ else
424
+ this.options.saveMissingTo === "all" ? de = this.languageUtils.toResolveHierarchy(r.lng || this.language) : de.push(r.lng || this.language);
425
+ const Pt = (z, se, fe) => {
426
+ const Ht = A && fe !== d ? fe : qr;
427
+ this.options.missingKeyHandler ? this.options.missingKeyHandler(z, c, se, Ht, le, r) : this.backendConnector && this.backendConnector.saveMissing && this.backendConnector.saveMissing(z, c, se, Ht, le, r), this.emit("missingKey", z, c, se, d);
428
+ };
429
+ this.options.saveMissing && (this.options.saveMissingPlurals && _ ? de.forEach((z) => {
430
+ const se = this.pluralResolver.getSuffixes(z, r);
431
+ q && r[`defaultValue${this.options.pluralSeparator}zero`] && se.indexOf(`${this.options.pluralSeparator}zero`) < 0 && se.push(`${this.options.pluralSeparator}zero`), se.forEach((fe) => {
432
+ Pt([z], i + fe, r[`defaultValue${fe}`] || Y);
433
+ });
434
+ }) : Pt(de, i, Y));
435
+ }
436
+ d = this.extendTranslation(d, e, r, f, n), E && d === i && this.options.appendNamespaceToMissingKey && (d = `${c}:${i}`), (E || m) && this.options.parseMissingKeyHandler && (this.options.compatibilityAPI !== "v1" ? d = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${c}:${i}` : i, m ? d : void 0) : d = this.options.parseMissingKeyHandler(d));
437
+ }
438
+ return a ? (f.res = d, f.usedParams = this.getUsedParamsDetails(r), f) : d;
439
+ }
440
+ extendTranslation(e, r, n, a, s) {
441
+ var i = this;
442
+ if (this.i18nFormat && this.i18nFormat.parse)
443
+ e = this.i18nFormat.parse(e, {
444
+ ...this.options.interpolation.defaultVariables,
445
+ ...n
446
+ }, n.lng || this.language || a.usedLng, a.usedNS, a.usedKey, {
447
+ resolved: a
448
+ });
449
+ else if (!n.skipInterpolation) {
450
+ n.interpolation && this.interpolator.init({
451
+ ...n,
452
+ interpolation: {
453
+ ...this.options.interpolation,
454
+ ...n.interpolation
455
+ }
456
+ });
457
+ const u = typeof e == "string" && (n && n.interpolation && n.interpolation.skipOnVariables !== void 0 ? n.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
458
+ let l;
459
+ if (u) {
460
+ const d = e.match(this.interpolator.nestingRegexp);
461
+ l = d && d.length;
462
+ }
463
+ let f = n.replace && typeof n.replace != "string" ? n.replace : n;
464
+ if (this.options.interpolation.defaultVariables && (f = {
465
+ ...this.options.interpolation.defaultVariables,
466
+ ...f
467
+ }), e = this.interpolator.interpolate(e, f, n.lng || this.language, n), u) {
468
+ const d = e.match(this.interpolator.nestingRegexp), p = d && d.length;
469
+ l < p && (n.nest = !1);
470
+ }
471
+ !n.lng && this.options.compatibilityAPI !== "v1" && a && a.res && (n.lng = a.usedLng), n.nest !== !1 && (e = this.interpolator.nest(e, function() {
472
+ for (var d = arguments.length, p = new Array(d), h = 0; h < d; h++)
473
+ p[h] = arguments[h];
474
+ return s && s[0] === p[0] && !n.context ? (i.logger.warn(`It seems you are nesting recursively key: ${p[0]} in key: ${r[0]}`), null) : i.translate(...p, r);
475
+ }, n)), n.interpolation && this.interpolator.reset();
476
+ }
477
+ const o = n.postProcess || this.options.postProcess, c = typeof o == "string" ? [o] : o;
478
+ return e != null && c && c.length && n.applyPostProcessor !== !1 && (e = tr.handle(c, e, r, this.options && this.options.postProcessPassResolved ? {
479
+ i18nResolved: {
480
+ ...a,
481
+ usedParams: this.getUsedParamsDetails(n)
482
+ },
483
+ ...n
484
+ } : n, this)), e;
485
+ }
486
+ resolve(e) {
487
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, n, a, s, i, o;
488
+ return typeof e == "string" && (e = [e]), e.forEach((c) => {
489
+ if (this.isValidLookup(n))
490
+ return;
491
+ const u = this.extractFromKey(c, r), l = u.key;
492
+ a = l;
493
+ let f = u.namespaces;
494
+ this.options.fallbackNS && (f = f.concat(this.options.fallbackNS));
495
+ const d = r.count !== void 0 && typeof r.count != "string", p = d && !r.ordinal && r.count === 0 && this.pluralResolver.shouldUseIntlApi(), h = r.context !== void 0 && (typeof r.context == "string" || typeof r.context == "number") && r.context !== "", g = r.lngs ? r.lngs : this.languageUtils.toResolveHierarchy(r.lng || this.language, r.fallbackLng);
496
+ f.forEach((S) => {
497
+ this.isValidLookup(n) || (o = S, !It[`${g[0]}-${S}`] && this.utils && this.utils.hasLoadedNamespace && !this.utils.hasLoadedNamespace(o) && (It[`${g[0]}-${S}`] = !0, this.logger.warn(`key "${a}" for languages "${g.join(", ")}" won't get resolved as namespace "${o}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!")), g.forEach((C) => {
498
+ if (this.isValidLookup(n))
499
+ return;
500
+ i = C;
501
+ const v = [l];
502
+ if (this.i18nFormat && this.i18nFormat.addLookupKeys)
503
+ this.i18nFormat.addLookupKeys(v, l, C, S, r);
504
+ else {
505
+ let m;
506
+ d && (m = this.pluralResolver.getSuffix(C, r.count, r));
507
+ const E = `${this.options.pluralSeparator}zero`, _ = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
508
+ if (d && (v.push(l + m), r.ordinal && m.indexOf(_) === 0 && v.push(l + m.replace(_, this.options.pluralSeparator)), p && v.push(l + E)), h) {
509
+ const A = `${l}${this.options.contextSeparator}${r.context}`;
510
+ v.push(A), d && (v.push(A + m), r.ordinal && m.indexOf(_) === 0 && v.push(A + m.replace(_, this.options.pluralSeparator)), p && v.push(A + E));
511
+ }
512
+ }
513
+ let w;
514
+ for (; w = v.pop(); )
515
+ this.isValidLookup(n) || (s = w, n = this.getResource(C, S, w, r));
516
+ }));
517
+ });
518
+ }), {
519
+ res: n,
520
+ usedKey: a,
521
+ exactUsedKey: s,
522
+ usedLng: i,
523
+ usedNS: o
524
+ };
525
+ }
526
+ isValidLookup(e) {
527
+ return e !== void 0 && !(!this.options.returnNull && e === null) && !(!this.options.returnEmptyString && e === "");
528
+ }
529
+ getResource(e, r, n) {
530
+ let a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
531
+ return this.i18nFormat && this.i18nFormat.getResource ? this.i18nFormat.getResource(e, r, n, a) : this.resourceStore.getResource(e, r, n, a);
532
+ }
533
+ getUsedParamsDetails() {
534
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
535
+ const r = ["defaultValue", "ordinal", "context", "replace", "lng", "lngs", "fallbackLng", "ns", "keySeparator", "nsSeparator", "returnObjects", "returnDetails", "joinArrays", "postProcess", "interpolation"], n = e.replace && typeof e.replace != "string";
536
+ let a = n ? e.replace : e;
537
+ if (n && typeof e.count < "u" && (a.count = e.count), this.options.interpolation.defaultVariables && (a = {
538
+ ...this.options.interpolation.defaultVariables,
539
+ ...a
540
+ }), !n) {
541
+ a = {
542
+ ...a
543
+ };
544
+ for (const s of r)
545
+ delete a[s];
546
+ }
547
+ return a;
548
+ }
549
+ static hasDefaultValue(e) {
550
+ const r = "defaultValue";
551
+ for (const n in e)
552
+ if (Object.prototype.hasOwnProperty.call(e, n) && r === n.substring(0, r.length) && e[n] !== void 0)
553
+ return !0;
554
+ return !1;
555
+ }
556
+ }
557
+ function Ge(t) {
558
+ return t.charAt(0).toUpperCase() + t.slice(1);
559
+ }
560
+ class Wt {
561
+ constructor(e) {
562
+ this.options = e, this.supportedLngs = this.options.supportedLngs || !1, this.logger = Z.create("languageUtils");
563
+ }
564
+ getScriptPartFromCode(e) {
565
+ if (e = Pe(e), !e || e.indexOf("-") < 0)
566
+ return null;
567
+ const r = e.split("-");
568
+ return r.length === 2 || (r.pop(), r[r.length - 1].toLowerCase() === "x") ? null : this.formatLanguageCode(r.join("-"));
569
+ }
570
+ getLanguagePartFromCode(e) {
571
+ if (e = Pe(e), !e || e.indexOf("-") < 0)
572
+ return e;
573
+ const r = e.split("-");
574
+ return this.formatLanguageCode(r[0]);
575
+ }
576
+ formatLanguageCode(e) {
577
+ if (typeof e == "string" && e.indexOf("-") > -1) {
578
+ const r = ["hans", "hant", "latn", "cyrl", "cans", "mong", "arab"];
579
+ let n = e.split("-");
580
+ return this.options.lowerCaseLng ? n = n.map((a) => a.toLowerCase()) : n.length === 2 ? (n[0] = n[0].toLowerCase(), n[1] = n[1].toUpperCase(), r.indexOf(n[1].toLowerCase()) > -1 && (n[1] = Ge(n[1].toLowerCase()))) : n.length === 3 && (n[0] = n[0].toLowerCase(), n[1].length === 2 && (n[1] = n[1].toUpperCase()), n[0] !== "sgn" && n[2].length === 2 && (n[2] = n[2].toUpperCase()), r.indexOf(n[1].toLowerCase()) > -1 && (n[1] = Ge(n[1].toLowerCase())), r.indexOf(n[2].toLowerCase()) > -1 && (n[2] = Ge(n[2].toLowerCase()))), n.join("-");
581
+ }
582
+ return this.options.cleanCode || this.options.lowerCaseLng ? e.toLowerCase() : e;
583
+ }
584
+ isSupportedCode(e) {
585
+ return (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) && (e = this.getLanguagePartFromCode(e)), !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.indexOf(e) > -1;
586
+ }
587
+ getBestMatchFromCodes(e) {
588
+ if (!e)
589
+ return null;
590
+ let r;
591
+ return e.forEach((n) => {
592
+ if (r)
593
+ return;
594
+ const a = this.formatLanguageCode(n);
595
+ (!this.options.supportedLngs || this.isSupportedCode(a)) && (r = a);
596
+ }), !r && this.options.supportedLngs && e.forEach((n) => {
597
+ if (r)
598
+ return;
599
+ const a = this.getLanguagePartFromCode(n);
600
+ if (this.isSupportedCode(a))
601
+ return r = a;
602
+ r = this.options.supportedLngs.find((s) => {
603
+ if (s === a)
604
+ return s;
605
+ if (!(s.indexOf("-") < 0 && a.indexOf("-") < 0) && s.indexOf(a) === 0)
606
+ return s;
607
+ });
608
+ }), r || (r = this.getFallbackCodes(this.options.fallbackLng)[0]), r;
609
+ }
610
+ getFallbackCodes(e, r) {
611
+ if (!e)
612
+ return [];
613
+ if (typeof e == "function" && (e = e(r)), typeof e == "string" && (e = [e]), Object.prototype.toString.apply(e) === "[object Array]")
614
+ return e;
615
+ if (!r)
616
+ return e.default || [];
617
+ let n = e[r];
618
+ return n || (n = e[this.getScriptPartFromCode(r)]), n || (n = e[this.formatLanguageCode(r)]), n || (n = e[this.getLanguagePartFromCode(r)]), n || (n = e.default), n || [];
619
+ }
620
+ toResolveHierarchy(e, r) {
621
+ const n = this.getFallbackCodes(r || this.options.fallbackLng || [], e), a = [], s = (i) => {
622
+ i && (this.isSupportedCode(i) ? a.push(i) : this.logger.warn(`rejecting language code not found in supportedLngs: ${i}`));
623
+ };
624
+ return typeof e == "string" && (e.indexOf("-") > -1 || e.indexOf("_") > -1) ? (this.options.load !== "languageOnly" && s(this.formatLanguageCode(e)), this.options.load !== "languageOnly" && this.options.load !== "currentOnly" && s(this.getScriptPartFromCode(e)), this.options.load !== "currentOnly" && s(this.getLanguagePartFromCode(e))) : typeof e == "string" && s(this.formatLanguageCode(e)), n.forEach((i) => {
625
+ a.indexOf(i) < 0 && s(this.formatLanguageCode(i));
626
+ }), a;
627
+ }
628
+ }
629
+ let cn = [{
630
+ lngs: ["ach", "ak", "am", "arn", "br", "fil", "gun", "ln", "mfe", "mg", "mi", "oc", "pt", "pt-BR", "tg", "tl", "ti", "tr", "uz", "wa"],
631
+ nr: [1, 2],
632
+ fc: 1
633
+ }, {
634
+ lngs: ["af", "an", "ast", "az", "bg", "bn", "ca", "da", "de", "dev", "el", "en", "eo", "es", "et", "eu", "fi", "fo", "fur", "fy", "gl", "gu", "ha", "hi", "hu", "hy", "ia", "it", "kk", "kn", "ku", "lb", "mai", "ml", "mn", "mr", "nah", "nap", "nb", "ne", "nl", "nn", "no", "nso", "pa", "pap", "pms", "ps", "pt-PT", "rm", "sco", "se", "si", "so", "son", "sq", "sv", "sw", "ta", "te", "tk", "ur", "yo"],
635
+ nr: [1, 2],
636
+ fc: 2
637
+ }, {
638
+ lngs: ["ay", "bo", "cgg", "fa", "ht", "id", "ja", "jbo", "ka", "km", "ko", "ky", "lo", "ms", "sah", "su", "th", "tt", "ug", "vi", "wo", "zh"],
639
+ nr: [1],
640
+ fc: 3
641
+ }, {
642
+ lngs: ["be", "bs", "cnr", "dz", "hr", "ru", "sr", "uk"],
643
+ nr: [1, 2, 5],
644
+ fc: 4
645
+ }, {
646
+ lngs: ["ar"],
647
+ nr: [0, 1, 2, 3, 11, 100],
648
+ fc: 5
649
+ }, {
650
+ lngs: ["cs", "sk"],
651
+ nr: [1, 2, 5],
652
+ fc: 6
653
+ }, {
654
+ lngs: ["csb", "pl"],
655
+ nr: [1, 2, 5],
656
+ fc: 7
657
+ }, {
658
+ lngs: ["cy"],
659
+ nr: [1, 2, 3, 8],
660
+ fc: 8
661
+ }, {
662
+ lngs: ["fr"],
663
+ nr: [1, 2],
664
+ fc: 9
665
+ }, {
666
+ lngs: ["ga"],
667
+ nr: [1, 2, 3, 7, 11],
668
+ fc: 10
669
+ }, {
670
+ lngs: ["gd"],
671
+ nr: [1, 2, 3, 20],
672
+ fc: 11
673
+ }, {
674
+ lngs: ["is"],
675
+ nr: [1, 2],
676
+ fc: 12
677
+ }, {
678
+ lngs: ["jv"],
679
+ nr: [0, 1],
680
+ fc: 13
681
+ }, {
682
+ lngs: ["kw"],
683
+ nr: [1, 2, 3, 4],
684
+ fc: 14
685
+ }, {
686
+ lngs: ["lt"],
687
+ nr: [1, 2, 10],
688
+ fc: 15
689
+ }, {
690
+ lngs: ["lv"],
691
+ nr: [1, 2, 0],
692
+ fc: 16
693
+ }, {
694
+ lngs: ["mk"],
695
+ nr: [1, 2],
696
+ fc: 17
697
+ }, {
698
+ lngs: ["mnk"],
699
+ nr: [0, 1, 2],
700
+ fc: 18
701
+ }, {
702
+ lngs: ["mt"],
703
+ nr: [1, 2, 11, 20],
704
+ fc: 19
705
+ }, {
706
+ lngs: ["or"],
707
+ nr: [2, 1],
708
+ fc: 2
709
+ }, {
710
+ lngs: ["ro"],
711
+ nr: [1, 2, 20],
712
+ fc: 20
713
+ }, {
714
+ lngs: ["sl"],
715
+ nr: [5, 1, 2, 3],
716
+ fc: 21
717
+ }, {
718
+ lngs: ["he", "iw"],
719
+ nr: [1, 2, 20, 21],
720
+ fc: 22
721
+ }], un = {
722
+ 1: function(t) {
723
+ return +(t > 1);
724
+ },
725
+ 2: function(t) {
726
+ return +(t != 1);
727
+ },
728
+ 3: function(t) {
729
+ return 0;
730
+ },
731
+ 4: function(t) {
732
+ return t % 10 == 1 && t % 100 != 11 ? 0 : t % 10 >= 2 && t % 10 <= 4 && (t % 100 < 10 || t % 100 >= 20) ? 1 : 2;
733
+ },
734
+ 5: function(t) {
735
+ return t == 0 ? 0 : t == 1 ? 1 : t == 2 ? 2 : t % 100 >= 3 && t % 100 <= 10 ? 3 : t % 100 >= 11 ? 4 : 5;
736
+ },
737
+ 6: function(t) {
738
+ return t == 1 ? 0 : t >= 2 && t <= 4 ? 1 : 2;
739
+ },
740
+ 7: function(t) {
741
+ return t == 1 ? 0 : t % 10 >= 2 && t % 10 <= 4 && (t % 100 < 10 || t % 100 >= 20) ? 1 : 2;
742
+ },
743
+ 8: function(t) {
744
+ return t == 1 ? 0 : t == 2 ? 1 : t != 8 && t != 11 ? 2 : 3;
745
+ },
746
+ 9: function(t) {
747
+ return +(t >= 2);
748
+ },
749
+ 10: function(t) {
750
+ return t == 1 ? 0 : t == 2 ? 1 : t < 7 ? 2 : t < 11 ? 3 : 4;
751
+ },
752
+ 11: function(t) {
753
+ return t == 1 || t == 11 ? 0 : t == 2 || t == 12 ? 1 : t > 2 && t < 20 ? 2 : 3;
754
+ },
755
+ 12: function(t) {
756
+ return +(t % 10 != 1 || t % 100 == 11);
757
+ },
758
+ 13: function(t) {
759
+ return +(t !== 0);
760
+ },
761
+ 14: function(t) {
762
+ return t == 1 ? 0 : t == 2 ? 1 : t == 3 ? 2 : 3;
763
+ },
764
+ 15: function(t) {
765
+ return t % 10 == 1 && t % 100 != 11 ? 0 : t % 10 >= 2 && (t % 100 < 10 || t % 100 >= 20) ? 1 : 2;
766
+ },
767
+ 16: function(t) {
768
+ return t % 10 == 1 && t % 100 != 11 ? 0 : t !== 0 ? 1 : 2;
769
+ },
770
+ 17: function(t) {
771
+ return t == 1 || t % 10 == 1 && t % 100 != 11 ? 0 : 1;
772
+ },
773
+ 18: function(t) {
774
+ return t == 0 ? 0 : t == 1 ? 1 : 2;
775
+ },
776
+ 19: function(t) {
777
+ return t == 1 ? 0 : t == 0 || t % 100 > 1 && t % 100 < 11 ? 1 : t % 100 > 10 && t % 100 < 20 ? 2 : 3;
778
+ },
779
+ 20: function(t) {
780
+ return t == 1 ? 0 : t == 0 || t % 100 > 0 && t % 100 < 20 ? 1 : 2;
781
+ },
782
+ 21: function(t) {
783
+ return t % 100 == 1 ? 1 : t % 100 == 2 ? 2 : t % 100 == 3 || t % 100 == 4 ? 3 : 0;
784
+ },
785
+ 22: function(t) {
786
+ return t == 1 ? 0 : t == 2 ? 1 : (t < 0 || t > 10) && t % 10 == 0 ? 2 : 3;
787
+ }
788
+ };
789
+ const ln = ["v1", "v2", "v3"], dn = ["v4"], Ut = {
790
+ zero: 0,
791
+ one: 1,
792
+ two: 2,
793
+ few: 3,
794
+ many: 4,
795
+ other: 5
796
+ };
797
+ function fn() {
798
+ const t = {};
799
+ return cn.forEach((e) => {
800
+ e.lngs.forEach((r) => {
801
+ t[r] = {
802
+ numbers: e.nr,
803
+ plurals: un[e.fc]
804
+ };
805
+ });
806
+ }), t;
807
+ }
808
+ class hn {
809
+ constructor(e) {
810
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
811
+ this.languageUtils = e, this.options = r, this.logger = Z.create("pluralResolver"), (!this.options.compatibilityJSON || dn.includes(this.options.compatibilityJSON)) && (typeof Intl > "u" || !Intl.PluralRules) && (this.options.compatibilityJSON = "v3", this.logger.error("Your environment seems not to be Intl API compatible, use an Intl.PluralRules polyfill. Will fallback to the compatibilityJSON v3 format handling.")), this.rules = fn();
812
+ }
813
+ addRule(e, r) {
814
+ this.rules[e] = r;
815
+ }
816
+ getRule(e) {
817
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
818
+ if (this.shouldUseIntlApi())
819
+ try {
820
+ return new Intl.PluralRules(Pe(e === "dev" ? "en" : e), {
821
+ type: r.ordinal ? "ordinal" : "cardinal"
822
+ });
823
+ } catch {
824
+ return;
825
+ }
826
+ return this.rules[e] || this.rules[this.languageUtils.getLanguagePartFromCode(e)];
827
+ }
828
+ needsPlural(e) {
829
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
830
+ const n = this.getRule(e, r);
831
+ return this.shouldUseIntlApi() ? n && n.resolvedOptions().pluralCategories.length > 1 : n && n.numbers.length > 1;
832
+ }
833
+ getPluralFormsOfKey(e, r) {
834
+ let n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
835
+ return this.getSuffixes(e, n).map((a) => `${r}${a}`);
836
+ }
837
+ getSuffixes(e) {
838
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
839
+ const n = this.getRule(e, r);
840
+ return n ? this.shouldUseIntlApi() ? n.resolvedOptions().pluralCategories.sort((a, s) => Ut[a] - Ut[s]).map((a) => `${this.options.prepend}${r.ordinal ? `ordinal${this.options.prepend}` : ""}${a}`) : n.numbers.map((a) => this.getSuffix(e, a, r)) : [];
841
+ }
842
+ getSuffix(e, r) {
843
+ let n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
844
+ const a = this.getRule(e, n);
845
+ return a ? this.shouldUseIntlApi() ? `${this.options.prepend}${n.ordinal ? `ordinal${this.options.prepend}` : ""}${a.select(r)}` : this.getSuffixRetroCompatible(a, r) : (this.logger.warn(`no plural rule found for: ${e}`), "");
846
+ }
847
+ getSuffixRetroCompatible(e, r) {
848
+ const n = e.noAbs ? e.plurals(r) : e.plurals(Math.abs(r));
849
+ let a = e.numbers[n];
850
+ this.options.simplifyPluralSuffix && e.numbers.length === 2 && e.numbers[0] === 1 && (a === 2 ? a = "plural" : a === 1 && (a = ""));
851
+ const s = () => this.options.prepend && a.toString() ? this.options.prepend + a.toString() : a.toString();
852
+ return this.options.compatibilityJSON === "v1" ? a === 1 ? "" : typeof a == "number" ? `_plural_${a.toString()}` : s() : this.options.compatibilityJSON === "v2" || this.options.simplifyPluralSuffix && e.numbers.length === 2 && e.numbers[0] === 1 ? s() : this.options.prepend && n.toString() ? this.options.prepend + n.toString() : n.toString();
853
+ }
854
+ shouldUseIntlApi() {
855
+ return !ln.includes(this.options.compatibilityJSON);
856
+ }
857
+ }
858
+ function Lt(t, e, r) {
859
+ let n = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : ".", a = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : !0, s = rn(t, e, r);
860
+ return !s && a && typeof r == "string" && (s = _e(t, r, n), s === void 0 && (s = _e(e, r, n))), s;
861
+ }
862
+ class pn {
863
+ constructor() {
864
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
865
+ this.logger = Z.create("interpolator"), this.options = e, this.format = e.interpolation && e.interpolation.format || ((r) => r), this.init(e);
866
+ }
867
+ init() {
868
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
869
+ e.interpolation || (e.interpolation = {
870
+ escapeValue: !0
871
+ });
872
+ const r = e.interpolation;
873
+ this.escape = r.escape !== void 0 ? r.escape : an, this.escapeValue = r.escapeValue !== void 0 ? r.escapeValue : !0, this.useRawValueToEscape = r.useRawValueToEscape !== void 0 ? r.useRawValueToEscape : !1, this.prefix = r.prefix ? oe(r.prefix) : r.prefixEscaped || "{{", this.suffix = r.suffix ? oe(r.suffix) : r.suffixEscaped || "}}", this.formatSeparator = r.formatSeparator ? r.formatSeparator : r.formatSeparator || ",", this.unescapePrefix = r.unescapeSuffix ? "" : r.unescapePrefix || "-", this.unescapeSuffix = this.unescapePrefix ? "" : r.unescapeSuffix || "", this.nestingPrefix = r.nestingPrefix ? oe(r.nestingPrefix) : r.nestingPrefixEscaped || oe("$t("), this.nestingSuffix = r.nestingSuffix ? oe(r.nestingSuffix) : r.nestingSuffixEscaped || oe(")"), this.nestingOptionsSeparator = r.nestingOptionsSeparator ? r.nestingOptionsSeparator : r.nestingOptionsSeparator || ",", this.maxReplaces = r.maxReplaces ? r.maxReplaces : 1e3, this.alwaysFormat = r.alwaysFormat !== void 0 ? r.alwaysFormat : !1, this.resetRegExp();
874
+ }
875
+ reset() {
876
+ this.options && this.init(this.options);
877
+ }
878
+ resetRegExp() {
879
+ const e = `${this.prefix}(.+?)${this.suffix}`;
880
+ this.regexp = new RegExp(e, "g");
881
+ const r = `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`;
882
+ this.regexpUnescape = new RegExp(r, "g");
883
+ const n = `${this.nestingPrefix}(.+?)${this.nestingSuffix}`;
884
+ this.nestingRegexp = new RegExp(n, "g");
885
+ }
886
+ interpolate(e, r, n, a) {
887
+ let s, i, o;
888
+ const c = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
889
+ function u(h) {
890
+ return h.replace(/\$/g, "$$$$");
891
+ }
892
+ const l = (h) => {
893
+ if (h.indexOf(this.formatSeparator) < 0) {
894
+ const v = Lt(r, c, h, this.options.keySeparator, this.options.ignoreJSONStructure);
895
+ return this.alwaysFormat ? this.format(v, void 0, n, {
896
+ ...a,
897
+ ...r,
898
+ interpolationkey: h
899
+ }) : v;
900
+ }
901
+ const g = h.split(this.formatSeparator), S = g.shift().trim(), C = g.join(this.formatSeparator).trim();
902
+ return this.format(Lt(r, c, S, this.options.keySeparator, this.options.ignoreJSONStructure), C, n, {
903
+ ...a,
904
+ ...r,
905
+ interpolationkey: S
906
+ });
907
+ };
908
+ this.resetRegExp();
909
+ const f = a && a.missingInterpolationHandler || this.options.missingInterpolationHandler, d = a && a.interpolation && a.interpolation.skipOnVariables !== void 0 ? a.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
910
+ return [{
911
+ regex: this.regexpUnescape,
912
+ safeValue: (h) => u(h)
913
+ }, {
914
+ regex: this.regexp,
915
+ safeValue: (h) => this.escapeValue ? u(this.escape(h)) : u(h)
916
+ }].forEach((h) => {
917
+ for (o = 0; s = h.regex.exec(e); ) {
918
+ const g = s[1].trim();
919
+ if (i = l(g), i === void 0)
920
+ if (typeof f == "function") {
921
+ const C = f(e, s, a);
922
+ i = typeof C == "string" ? C : "";
923
+ } else if (a && Object.prototype.hasOwnProperty.call(a, g))
924
+ i = "";
925
+ else if (d) {
926
+ i = s[0];
927
+ continue;
928
+ } else
929
+ this.logger.warn(`missed to pass in variable ${g} for interpolating ${e}`), i = "";
930
+ else
931
+ typeof i != "string" && !this.useRawValueToEscape && (i = Rt(i));
932
+ const S = h.safeValue(i);
933
+ if (e = e.replace(s[0], S), d ? (h.regex.lastIndex += i.length, h.regex.lastIndex -= s[0].length) : h.regex.lastIndex = 0, o++, o >= this.maxReplaces)
934
+ break;
935
+ }
936
+ }), e;
937
+ }
938
+ nest(e, r) {
939
+ let n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, a, s, i;
940
+ function o(c, u) {
941
+ const l = this.nestingOptionsSeparator;
942
+ if (c.indexOf(l) < 0)
943
+ return c;
944
+ const f = c.split(new RegExp(`${l}[ ]*{`));
945
+ let d = `{${f[1]}`;
946
+ c = f[0], d = this.interpolate(d, i);
947
+ const p = d.match(/'/g), h = d.match(/"/g);
948
+ (p && p.length % 2 === 0 && !h || h.length % 2 !== 0) && (d = d.replace(/'/g, '"'));
949
+ try {
950
+ i = JSON.parse(d), u && (i = {
951
+ ...u,
952
+ ...i
953
+ });
954
+ } catch (g) {
955
+ return this.logger.warn(`failed parsing options string in nesting for key ${c}`, g), `${c}${l}${d}`;
956
+ }
957
+ return delete i.defaultValue, c;
958
+ }
959
+ for (; a = this.nestingRegexp.exec(e); ) {
960
+ let c = [];
961
+ i = {
962
+ ...n
963
+ }, i = i.replace && typeof i.replace != "string" ? i.replace : i, i.applyPostProcessor = !1, delete i.defaultValue;
964
+ let u = !1;
965
+ if (a[0].indexOf(this.formatSeparator) !== -1 && !/{.*}/.test(a[1])) {
966
+ const l = a[1].split(this.formatSeparator).map((f) => f.trim());
967
+ a[1] = l.shift(), c = l, u = !0;
968
+ }
969
+ if (s = r(o.call(this, a[1].trim(), i), i), s && a[0] === e && typeof s != "string")
970
+ return s;
971
+ typeof s != "string" && (s = Rt(s)), s || (this.logger.warn(`missed to resolve ${a[1]} for nesting ${e}`), s = ""), u && (s = c.reduce((l, f) => this.format(l, f, n.lng, {
972
+ ...n,
973
+ interpolationkey: a[1].trim()
974
+ }), s.trim())), e = e.replace(a[0], s), this.regexp.lastIndex = 0;
975
+ }
976
+ return e;
977
+ }
978
+ }
979
+ function gn(t) {
980
+ let e = t.toLowerCase().trim();
981
+ const r = {};
982
+ if (t.indexOf("(") > -1) {
983
+ const n = t.split("(");
984
+ e = n[0].toLowerCase().trim();
985
+ const a = n[1].substring(0, n[1].length - 1);
986
+ e === "currency" && a.indexOf(":") < 0 ? r.currency || (r.currency = a.trim()) : e === "relativetime" && a.indexOf(":") < 0 ? r.range || (r.range = a.trim()) : a.split(";").forEach((i) => {
987
+ if (!i)
988
+ return;
989
+ const [o, ...c] = i.split(":"), u = c.join(":").trim().replace(/^'+|'+$/g, "");
990
+ r[o.trim()] || (r[o.trim()] = u), u === "false" && (r[o.trim()] = !1), u === "true" && (r[o.trim()] = !0), isNaN(u) || (r[o.trim()] = parseInt(u, 10));
991
+ });
992
+ }
993
+ return {
994
+ formatName: e,
995
+ formatOptions: r
996
+ };
997
+ }
998
+ function ce(t) {
999
+ const e = {};
1000
+ return function(n, a, s) {
1001
+ const i = a + JSON.stringify(s);
1002
+ let o = e[i];
1003
+ return o || (o = t(Pe(a), s), e[i] = o), o(n);
1004
+ };
1005
+ }
1006
+ class mn {
1007
+ constructor() {
1008
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {};
1009
+ this.logger = Z.create("formatter"), this.options = e, this.formats = {
1010
+ number: ce((r, n) => {
1011
+ const a = new Intl.NumberFormat(r, {
1012
+ ...n
1013
+ });
1014
+ return (s) => a.format(s);
1015
+ }),
1016
+ currency: ce((r, n) => {
1017
+ const a = new Intl.NumberFormat(r, {
1018
+ ...n,
1019
+ style: "currency"
1020
+ });
1021
+ return (s) => a.format(s);
1022
+ }),
1023
+ datetime: ce((r, n) => {
1024
+ const a = new Intl.DateTimeFormat(r, {
1025
+ ...n
1026
+ });
1027
+ return (s) => a.format(s);
1028
+ }),
1029
+ relativetime: ce((r, n) => {
1030
+ const a = new Intl.RelativeTimeFormat(r, {
1031
+ ...n
1032
+ });
1033
+ return (s) => a.format(s, n.range || "day");
1034
+ }),
1035
+ list: ce((r, n) => {
1036
+ const a = new Intl.ListFormat(r, {
1037
+ ...n
1038
+ });
1039
+ return (s) => a.format(s);
1040
+ })
1041
+ }, this.init(e);
1042
+ }
1043
+ init(e) {
1044
+ const n = (arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {
1045
+ interpolation: {}
1046
+ }).interpolation;
1047
+ this.formatSeparator = n.formatSeparator ? n.formatSeparator : n.formatSeparator || ",";
1048
+ }
1049
+ add(e, r) {
1050
+ this.formats[e.toLowerCase().trim()] = r;
1051
+ }
1052
+ addCached(e, r) {
1053
+ this.formats[e.toLowerCase().trim()] = ce(r);
1054
+ }
1055
+ format(e, r, n) {
1056
+ let a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
1057
+ return r.split(this.formatSeparator).reduce((o, c) => {
1058
+ const {
1059
+ formatName: u,
1060
+ formatOptions: l
1061
+ } = gn(c);
1062
+ if (this.formats[u]) {
1063
+ let f = o;
1064
+ try {
1065
+ const d = a && a.formatParams && a.formatParams[a.interpolationkey] || {}, p = d.locale || d.lng || a.locale || a.lng || n;
1066
+ f = this.formats[u](o, p, {
1067
+ ...l,
1068
+ ...a,
1069
+ ...d
1070
+ });
1071
+ } catch (d) {
1072
+ this.logger.warn(d);
1073
+ }
1074
+ return f;
1075
+ } else
1076
+ this.logger.warn(`there was no format function for ${u}`);
1077
+ return o;
1078
+ }, e);
1079
+ }
1080
+ }
1081
+ function yn(t, e) {
1082
+ t.pending[e] !== void 0 && (delete t.pending[e], t.pendingCount--);
1083
+ }
1084
+ class wn extends Ue {
1085
+ constructor(e, r, n) {
1086
+ let a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : {};
1087
+ super(), this.backend = e, this.store = r, this.services = n, this.languageUtils = n.languageUtils, this.options = a, this.logger = Z.create("backendConnector"), this.waitingReads = [], this.maxParallelReads = a.maxParallelReads || 10, this.readingCalls = 0, this.maxRetries = a.maxRetries >= 0 ? a.maxRetries : 5, this.retryTimeout = a.retryTimeout >= 1 ? a.retryTimeout : 350, this.state = {}, this.queue = [], this.backend && this.backend.init && this.backend.init(n, a.backend, a);
1088
+ }
1089
+ queueLoad(e, r, n, a) {
1090
+ const s = {}, i = {}, o = {}, c = {};
1091
+ return e.forEach((u) => {
1092
+ let l = !0;
1093
+ r.forEach((f) => {
1094
+ const d = `${u}|${f}`;
1095
+ !n.reload && this.store.hasResourceBundle(u, f) ? this.state[d] = 2 : this.state[d] < 0 || (this.state[d] === 1 ? i[d] === void 0 && (i[d] = !0) : (this.state[d] = 1, l = !1, i[d] === void 0 && (i[d] = !0), s[d] === void 0 && (s[d] = !0), c[f] === void 0 && (c[f] = !0)));
1096
+ }), l || (o[u] = !0);
1097
+ }), (Object.keys(s).length || Object.keys(i).length) && this.queue.push({
1098
+ pending: i,
1099
+ pendingCount: Object.keys(i).length,
1100
+ loaded: {},
1101
+ errors: [],
1102
+ callback: a
1103
+ }), {
1104
+ toLoad: Object.keys(s),
1105
+ pending: Object.keys(i),
1106
+ toLoadLanguages: Object.keys(o),
1107
+ toLoadNamespaces: Object.keys(c)
1108
+ };
1109
+ }
1110
+ loaded(e, r, n) {
1111
+ const a = e.split("|"), s = a[0], i = a[1];
1112
+ r && this.emit("failedLoading", s, i, r), n && this.store.addResourceBundle(s, i, n), this.state[e] = r ? -1 : 2;
1113
+ const o = {};
1114
+ this.queue.forEach((c) => {
1115
+ tn(c.loaded, [s], i), yn(c, e), r && c.errors.push(r), c.pendingCount === 0 && !c.done && (Object.keys(c.loaded).forEach((u) => {
1116
+ o[u] || (o[u] = {});
1117
+ const l = c.loaded[u];
1118
+ l.length && l.forEach((f) => {
1119
+ o[u][f] === void 0 && (o[u][f] = !0);
1120
+ });
1121
+ }), c.done = !0, c.errors.length ? c.callback(c.errors) : c.callback());
1122
+ }), this.emit("loaded", o), this.queue = this.queue.filter((c) => !c.done);
1123
+ }
1124
+ read(e, r, n) {
1125
+ let a = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : 0, s = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : this.retryTimeout, i = arguments.length > 5 ? arguments[5] : void 0;
1126
+ if (!e.length)
1127
+ return i(null, {});
1128
+ if (this.readingCalls >= this.maxParallelReads) {
1129
+ this.waitingReads.push({
1130
+ lng: e,
1131
+ ns: r,
1132
+ fcName: n,
1133
+ tried: a,
1134
+ wait: s,
1135
+ callback: i
1136
+ });
1137
+ return;
1138
+ }
1139
+ this.readingCalls++;
1140
+ const o = (u, l) => {
1141
+ if (this.readingCalls--, this.waitingReads.length > 0) {
1142
+ const f = this.waitingReads.shift();
1143
+ this.read(f.lng, f.ns, f.fcName, f.tried, f.wait, f.callback);
1144
+ }
1145
+ if (u && l && a < this.maxRetries) {
1146
+ setTimeout(() => {
1147
+ this.read.call(this, e, r, n, a + 1, s * 2, i);
1148
+ }, s);
1149
+ return;
1150
+ }
1151
+ i(u, l);
1152
+ }, c = this.backend[n].bind(this.backend);
1153
+ if (c.length === 2) {
1154
+ try {
1155
+ const u = c(e, r);
1156
+ u && typeof u.then == "function" ? u.then((l) => o(null, l)).catch(o) : o(null, u);
1157
+ } catch (u) {
1158
+ o(u);
1159
+ }
1160
+ return;
1161
+ }
1162
+ return c(e, r, o);
1163
+ }
1164
+ prepareLoading(e, r) {
1165
+ let n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, a = arguments.length > 3 ? arguments[3] : void 0;
1166
+ if (!this.backend)
1167
+ return this.logger.warn("No backend was added via i18next.use. Will not load resources."), a && a();
1168
+ typeof e == "string" && (e = this.languageUtils.toResolveHierarchy(e)), typeof r == "string" && (r = [r]);
1169
+ const s = this.queueLoad(e, r, n, a);
1170
+ if (!s.toLoad.length)
1171
+ return s.pending.length || a(), null;
1172
+ s.toLoad.forEach((i) => {
1173
+ this.loadOne(i);
1174
+ });
1175
+ }
1176
+ load(e, r, n) {
1177
+ this.prepareLoading(e, r, {}, n);
1178
+ }
1179
+ reload(e, r, n) {
1180
+ this.prepareLoading(e, r, {
1181
+ reload: !0
1182
+ }, n);
1183
+ }
1184
+ loadOne(e) {
1185
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "";
1186
+ const n = e.split("|"), a = n[0], s = n[1];
1187
+ this.read(a, s, "read", void 0, void 0, (i, o) => {
1188
+ i && this.logger.warn(`${r}loading namespace ${s} for language ${a} failed`, i), !i && o && this.logger.log(`${r}loaded namespace ${s} for language ${a}`, o), this.loaded(e, i, o);
1189
+ });
1190
+ }
1191
+ saveMissing(e, r, n, a, s) {
1192
+ let i = arguments.length > 5 && arguments[5] !== void 0 ? arguments[5] : {}, o = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : () => {
1193
+ };
1194
+ if (this.services.utils && this.services.utils.hasLoadedNamespace && !this.services.utils.hasLoadedNamespace(r)) {
1195
+ this.logger.warn(`did not save key "${n}" as the namespace "${r}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
1196
+ return;
1197
+ }
1198
+ if (!(n == null || n === "")) {
1199
+ if (this.backend && this.backend.create) {
1200
+ const c = {
1201
+ ...i,
1202
+ isUpdate: s
1203
+ }, u = this.backend.create.bind(this.backend);
1204
+ if (u.length < 6)
1205
+ try {
1206
+ let l;
1207
+ u.length === 5 ? l = u(e, r, n, a, c) : l = u(e, r, n, a), l && typeof l.then == "function" ? l.then((f) => o(null, f)).catch(o) : o(null, l);
1208
+ } catch (l) {
1209
+ o(l);
1210
+ }
1211
+ else
1212
+ u(e, r, n, a, o, c);
1213
+ }
1214
+ !e || !e[0] || this.store.addResource(e[0], r, n, a);
1215
+ }
1216
+ }
1217
+ }
1218
+ function Dt() {
1219
+ return {
1220
+ debug: !1,
1221
+ initImmediate: !0,
1222
+ ns: ["translation"],
1223
+ defaultNS: ["translation"],
1224
+ fallbackLng: ["dev"],
1225
+ fallbackNS: !1,
1226
+ supportedLngs: !1,
1227
+ nonExplicitSupportedLngs: !1,
1228
+ load: "all",
1229
+ preload: !1,
1230
+ simplifyPluralSuffix: !0,
1231
+ keySeparator: ".",
1232
+ nsSeparator: ":",
1233
+ pluralSeparator: "_",
1234
+ contextSeparator: "_",
1235
+ partialBundledLanguages: !1,
1236
+ saveMissing: !1,
1237
+ updateMissing: !1,
1238
+ saveMissingTo: "fallback",
1239
+ saveMissingPlurals: !0,
1240
+ missingKeyHandler: !1,
1241
+ missingInterpolationHandler: !1,
1242
+ postProcess: !1,
1243
+ postProcessPassResolved: !1,
1244
+ returnNull: !1,
1245
+ returnEmptyString: !0,
1246
+ returnObjects: !1,
1247
+ joinArrays: !1,
1248
+ returnedObjectHandler: !1,
1249
+ parseMissingKeyHandler: !1,
1250
+ appendNamespaceToMissingKey: !1,
1251
+ appendNamespaceToCIMode: !1,
1252
+ overloadTranslationOptionHandler: function(e) {
1253
+ let r = {};
1254
+ if (typeof e[1] == "object" && (r = e[1]), typeof e[1] == "string" && (r.defaultValue = e[1]), typeof e[2] == "string" && (r.tDescription = e[2]), typeof e[2] == "object" || typeof e[3] == "object") {
1255
+ const n = e[3] || e[2];
1256
+ Object.keys(n).forEach((a) => {
1257
+ r[a] = n[a];
1258
+ });
1259
+ }
1260
+ return r;
1261
+ },
1262
+ interpolation: {
1263
+ escapeValue: !0,
1264
+ format: (t) => t,
1265
+ prefix: "{{",
1266
+ suffix: "}}",
1267
+ formatSeparator: ",",
1268
+ unescapePrefix: "-",
1269
+ nestingPrefix: "$t(",
1270
+ nestingSuffix: ")",
1271
+ nestingOptionsSeparator: ",",
1272
+ maxReplaces: 1e3,
1273
+ skipOnVariables: !0
1274
+ }
1275
+ };
1276
+ }
1277
+ function Jt(t) {
1278
+ return typeof t.ns == "string" && (t.ns = [t.ns]), typeof t.fallbackLng == "string" && (t.fallbackLng = [t.fallbackLng]), typeof t.fallbackNS == "string" && (t.fallbackNS = [t.fallbackNS]), t.supportedLngs && t.supportedLngs.indexOf("cimode") < 0 && (t.supportedLngs = t.supportedLngs.concat(["cimode"])), t;
1279
+ }
1280
+ function Se() {
1281
+ }
1282
+ function Sn(t) {
1283
+ Object.getOwnPropertyNames(Object.getPrototypeOf(t)).forEach((r) => {
1284
+ typeof t[r] == "function" && (t[r] = t[r].bind(t));
1285
+ });
1286
+ }
1287
+ class pe extends Ue {
1288
+ constructor() {
1289
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, r = arguments.length > 1 ? arguments[1] : void 0;
1290
+ if (super(), this.options = Jt(e), this.services = {}, this.logger = Z, this.modules = {
1291
+ external: []
1292
+ }, Sn(this), r && !this.isInitialized && !e.isClone) {
1293
+ if (!this.options.initImmediate)
1294
+ return this.init(e, r), this;
1295
+ setTimeout(() => {
1296
+ this.init(e, r);
1297
+ }, 0);
1298
+ }
1299
+ }
1300
+ init() {
1301
+ var e = this;
1302
+ let r = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, n = arguments.length > 1 ? arguments[1] : void 0;
1303
+ typeof r == "function" && (n = r, r = {}), !r.defaultNS && r.defaultNS !== !1 && r.ns && (typeof r.ns == "string" ? r.defaultNS = r.ns : r.ns.indexOf("translation") < 0 && (r.defaultNS = r.ns[0]));
1304
+ const a = Dt();
1305
+ this.options = {
1306
+ ...a,
1307
+ ...this.options,
1308
+ ...Jt(r)
1309
+ }, this.options.compatibilityAPI !== "v1" && (this.options.interpolation = {
1310
+ ...a.interpolation,
1311
+ ...this.options.interpolation
1312
+ }), r.keySeparator !== void 0 && (this.options.userDefinedKeySeparator = r.keySeparator), r.nsSeparator !== void 0 && (this.options.userDefinedNsSeparator = r.nsSeparator);
1313
+ function s(l) {
1314
+ return l ? typeof l == "function" ? new l() : l : null;
1315
+ }
1316
+ if (!this.options.isClone) {
1317
+ this.modules.logger ? Z.init(s(this.modules.logger), this.options) : Z.init(null, this.options);
1318
+ let l;
1319
+ this.modules.formatter ? l = this.modules.formatter : typeof Intl < "u" && (l = mn);
1320
+ const f = new Wt(this.options);
1321
+ this.store = new Tt(this.options.resources, this.options);
1322
+ const d = this.services;
1323
+ d.logger = Z, d.resourceStore = this.store, d.languageUtils = f, d.pluralResolver = new hn(f, {
1324
+ prepend: this.options.pluralSeparator,
1325
+ compatibilityJSON: this.options.compatibilityJSON,
1326
+ simplifyPluralSuffix: this.options.simplifyPluralSuffix
1327
+ }), l && (!this.options.interpolation.format || this.options.interpolation.format === a.interpolation.format) && (d.formatter = s(l), d.formatter.init(d, this.options), this.options.interpolation.format = d.formatter.format.bind(d.formatter)), d.interpolator = new pn(this.options), d.utils = {
1328
+ hasLoadedNamespace: this.hasLoadedNamespace.bind(this)
1329
+ }, d.backendConnector = new wn(s(this.modules.backend), d.resourceStore, d, this.options), d.backendConnector.on("*", function(p) {
1330
+ for (var h = arguments.length, g = new Array(h > 1 ? h - 1 : 0), S = 1; S < h; S++)
1331
+ g[S - 1] = arguments[S];
1332
+ e.emit(p, ...g);
1333
+ }), this.modules.languageDetector && (d.languageDetector = s(this.modules.languageDetector), d.languageDetector.init && d.languageDetector.init(d, this.options.detection, this.options)), this.modules.i18nFormat && (d.i18nFormat = s(this.modules.i18nFormat), d.i18nFormat.init && d.i18nFormat.init(this)), this.translator = new He(this.services, this.options), this.translator.on("*", function(p) {
1334
+ for (var h = arguments.length, g = new Array(h > 1 ? h - 1 : 0), S = 1; S < h; S++)
1335
+ g[S - 1] = arguments[S];
1336
+ e.emit(p, ...g);
1337
+ }), this.modules.external.forEach((p) => {
1338
+ p.init && p.init(this);
1339
+ });
1340
+ }
1341
+ if (this.format = this.options.interpolation.format, n || (n = Se), this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
1342
+ const l = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1343
+ l.length > 0 && l[0] !== "dev" && (this.options.lng = l[0]);
1344
+ }
1345
+ !this.services.languageDetector && !this.options.lng && this.logger.warn("init: no languageDetector is used and no lng is defined"), ["getResource", "hasResourceBundle", "getResourceBundle", "getDataByLanguage"].forEach((l) => {
1346
+ this[l] = function() {
1347
+ return e.store[l](...arguments);
1348
+ };
1349
+ }), ["addResource", "addResources", "addResourceBundle", "removeResourceBundle"].forEach((l) => {
1350
+ this[l] = function() {
1351
+ return e.store[l](...arguments), e;
1352
+ };
1353
+ });
1354
+ const c = he(), u = () => {
1355
+ const l = (f, d) => {
1356
+ this.isInitialized && !this.initializedStoreOnce && this.logger.warn("init: i18next is already initialized. You should call init just once!"), this.isInitialized = !0, this.options.isClone || this.logger.log("initialized", this.options), this.emit("initialized", this.options), c.resolve(d), n(f, d);
1357
+ };
1358
+ if (this.languages && this.options.compatibilityAPI !== "v1" && !this.isInitialized)
1359
+ return l(null, this.t.bind(this));
1360
+ this.changeLanguage(this.options.lng, l);
1361
+ };
1362
+ return this.options.resources || !this.options.initImmediate ? u() : setTimeout(u, 0), c;
1363
+ }
1364
+ loadResources(e) {
1365
+ let n = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Se;
1366
+ const a = typeof e == "string" ? e : this.language;
1367
+ if (typeof e == "function" && (n = e), !this.options.resources || this.options.partialBundledLanguages) {
1368
+ if (a && a.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0))
1369
+ return n();
1370
+ const s = [], i = (o) => {
1371
+ if (!o || o === "cimode")
1372
+ return;
1373
+ this.services.languageUtils.toResolveHierarchy(o).forEach((u) => {
1374
+ u !== "cimode" && s.indexOf(u) < 0 && s.push(u);
1375
+ });
1376
+ };
1377
+ a ? i(a) : this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach((c) => i(c)), this.options.preload && this.options.preload.forEach((o) => i(o)), this.services.backendConnector.load(s, this.options.ns, (o) => {
1378
+ !o && !this.resolvedLanguage && this.language && this.setResolvedLanguage(this.language), n(o);
1379
+ });
1380
+ } else
1381
+ n(null);
1382
+ }
1383
+ reloadResources(e, r, n) {
1384
+ const a = he();
1385
+ return e || (e = this.languages), r || (r = this.options.ns), n || (n = Se), this.services.backendConnector.reload(e, r, (s) => {
1386
+ a.resolve(), n(s);
1387
+ }), a;
1388
+ }
1389
+ use(e) {
1390
+ if (!e)
1391
+ throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
1392
+ if (!e.type)
1393
+ throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
1394
+ return e.type === "backend" && (this.modules.backend = e), (e.type === "logger" || e.log && e.warn && e.error) && (this.modules.logger = e), e.type === "languageDetector" && (this.modules.languageDetector = e), e.type === "i18nFormat" && (this.modules.i18nFormat = e), e.type === "postProcessor" && tr.addPostProcessor(e), e.type === "formatter" && (this.modules.formatter = e), e.type === "3rdParty" && this.modules.external.push(e), this;
1395
+ }
1396
+ setResolvedLanguage(e) {
1397
+ if (!(!e || !this.languages) && !(["cimode", "dev"].indexOf(e) > -1))
1398
+ for (let r = 0; r < this.languages.length; r++) {
1399
+ const n = this.languages[r];
1400
+ if (!(["cimode", "dev"].indexOf(n) > -1) && this.store.hasLanguageSomeTranslations(n)) {
1401
+ this.resolvedLanguage = n;
1402
+ break;
1403
+ }
1404
+ }
1405
+ }
1406
+ changeLanguage(e, r) {
1407
+ var n = this;
1408
+ this.isLanguageChangingTo = e;
1409
+ const a = he();
1410
+ this.emit("languageChanging", e);
1411
+ const s = (c) => {
1412
+ this.language = c, this.languages = this.services.languageUtils.toResolveHierarchy(c), this.resolvedLanguage = void 0, this.setResolvedLanguage(c);
1413
+ }, i = (c, u) => {
1414
+ u ? (s(u), this.translator.changeLanguage(u), this.isLanguageChangingTo = void 0, this.emit("languageChanged", u), this.logger.log("languageChanged", u)) : this.isLanguageChangingTo = void 0, a.resolve(function() {
1415
+ return n.t(...arguments);
1416
+ }), r && r(c, function() {
1417
+ return n.t(...arguments);
1418
+ });
1419
+ }, o = (c) => {
1420
+ !e && !c && this.services.languageDetector && (c = []);
1421
+ const u = typeof c == "string" ? c : this.services.languageUtils.getBestMatchFromCodes(c);
1422
+ u && (this.language || s(u), this.translator.language || this.translator.changeLanguage(u), this.services.languageDetector && this.services.languageDetector.cacheUserLanguage && this.services.languageDetector.cacheUserLanguage(u)), this.loadResources(u, (l) => {
1423
+ i(l, u);
1424
+ });
1425
+ };
1426
+ return !e && this.services.languageDetector && !this.services.languageDetector.async ? o(this.services.languageDetector.detect()) : !e && this.services.languageDetector && this.services.languageDetector.async ? this.services.languageDetector.detect.length === 0 ? this.services.languageDetector.detect().then(o) : this.services.languageDetector.detect(o) : o(e), a;
1427
+ }
1428
+ getFixedT(e, r, n) {
1429
+ var a = this;
1430
+ const s = function(i, o) {
1431
+ let c;
1432
+ if (typeof o != "object") {
1433
+ for (var u = arguments.length, l = new Array(u > 2 ? u - 2 : 0), f = 2; f < u; f++)
1434
+ l[f - 2] = arguments[f];
1435
+ c = a.options.overloadTranslationOptionHandler([i, o].concat(l));
1436
+ } else
1437
+ c = {
1438
+ ...o
1439
+ };
1440
+ c.lng = c.lng || s.lng, c.lngs = c.lngs || s.lngs, c.ns = c.ns || s.ns, c.keyPrefix = c.keyPrefix || n || s.keyPrefix;
1441
+ const d = a.options.keySeparator || ".";
1442
+ let p;
1443
+ return c.keyPrefix && Array.isArray(i) ? p = i.map((h) => `${c.keyPrefix}${d}${h}`) : p = c.keyPrefix ? `${c.keyPrefix}${d}${i}` : i, a.t(p, c);
1444
+ };
1445
+ return typeof e == "string" ? s.lng = e : s.lngs = e, s.ns = r, s.keyPrefix = n, s;
1446
+ }
1447
+ t() {
1448
+ return this.translator && this.translator.translate(...arguments);
1449
+ }
1450
+ exists() {
1451
+ return this.translator && this.translator.exists(...arguments);
1452
+ }
1453
+ setDefaultNamespace(e) {
1454
+ this.options.defaultNS = e;
1455
+ }
1456
+ hasLoadedNamespace(e) {
1457
+ let r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
1458
+ if (!this.isInitialized)
1459
+ return this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages), !1;
1460
+ if (!this.languages || !this.languages.length)
1461
+ return this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages), !1;
1462
+ const n = r.lng || this.resolvedLanguage || this.languages[0], a = this.options ? this.options.fallbackLng : !1, s = this.languages[this.languages.length - 1];
1463
+ if (n.toLowerCase() === "cimode")
1464
+ return !0;
1465
+ const i = (o, c) => {
1466
+ const u = this.services.backendConnector.state[`${o}|${c}`];
1467
+ return u === -1 || u === 2;
1468
+ };
1469
+ if (r.precheck) {
1470
+ const o = r.precheck(this, i);
1471
+ if (o !== void 0)
1472
+ return o;
1473
+ }
1474
+ return !!(this.hasResourceBundle(n, e) || !this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages || i(n, e) && (!a || i(s, e)));
1475
+ }
1476
+ loadNamespaces(e, r) {
1477
+ const n = he();
1478
+ return this.options.ns ? (typeof e == "string" && (e = [e]), e.forEach((a) => {
1479
+ this.options.ns.indexOf(a) < 0 && this.options.ns.push(a);
1480
+ }), this.loadResources((a) => {
1481
+ n.resolve(), r && r(a);
1482
+ }), n) : (r && r(), Promise.resolve());
1483
+ }
1484
+ loadLanguages(e, r) {
1485
+ const n = he();
1486
+ typeof e == "string" && (e = [e]);
1487
+ const a = this.options.preload || [], s = e.filter((i) => a.indexOf(i) < 0);
1488
+ return s.length ? (this.options.preload = a.concat(s), this.loadResources((i) => {
1489
+ n.resolve(), r && r(i);
1490
+ }), n) : (r && r(), Promise.resolve());
1491
+ }
1492
+ dir(e) {
1493
+ if (e || (e = this.resolvedLanguage || (this.languages && this.languages.length > 0 ? this.languages[0] : this.language)), !e)
1494
+ return "rtl";
1495
+ const r = ["ar", "shu", "sqr", "ssh", "xaa", "yhd", "yud", "aao", "abh", "abv", "acm", "acq", "acw", "acx", "acy", "adf", "ads", "aeb", "aec", "afb", "ajp", "apc", "apd", "arb", "arq", "ars", "ary", "arz", "auz", "avl", "ayh", "ayl", "ayn", "ayp", "bbz", "pga", "he", "iw", "ps", "pbt", "pbu", "pst", "prp", "prd", "ug", "ur", "ydd", "yds", "yih", "ji", "yi", "hbo", "men", "xmn", "fa", "jpr", "peo", "pes", "prs", "dv", "sam", "ckb"], n = this.services && this.services.languageUtils || new Wt(Dt());
1496
+ return r.indexOf(n.getLanguagePartFromCode(e)) > -1 || e.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
1497
+ }
1498
+ static createInstance() {
1499
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, r = arguments.length > 1 ? arguments[1] : void 0;
1500
+ return new pe(e, r);
1501
+ }
1502
+ cloneInstance() {
1503
+ let e = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {}, r = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : Se;
1504
+ const n = e.forkResourceStore;
1505
+ n && delete e.forkResourceStore;
1506
+ const a = {
1507
+ ...this.options,
1508
+ ...e,
1509
+ isClone: !0
1510
+ }, s = new pe(a);
1511
+ return (e.debug !== void 0 || e.prefix !== void 0) && (s.logger = s.logger.clone(e)), ["store", "services", "language"].forEach((o) => {
1512
+ s[o] = this[o];
1513
+ }), s.services = {
1514
+ ...this.services
1515
+ }, s.services.utils = {
1516
+ hasLoadedNamespace: s.hasLoadedNamespace.bind(s)
1517
+ }, n && (s.store = new Tt(this.store.data, a), s.services.resourceStore = s.store), s.translator = new He(s.services, a), s.translator.on("*", function(o) {
1518
+ for (var c = arguments.length, u = new Array(c > 1 ? c - 1 : 0), l = 1; l < c; l++)
1519
+ u[l - 1] = arguments[l];
1520
+ s.emit(o, ...u);
1521
+ }), s.init(a, r), s.translator.options = a, s.translator.backendConnector.services.utils = {
1522
+ hasLoadedNamespace: s.hasLoadedNamespace.bind(s)
1523
+ }, s;
1524
+ }
1525
+ toJSON() {
1526
+ return {
1527
+ options: this.options,
1528
+ store: this.store,
1529
+ language: this.language,
1530
+ languages: this.languages,
1531
+ resolvedLanguage: this.resolvedLanguage
1532
+ };
1533
+ }
1534
+ }
1535
+ const k = pe.createInstance();
1536
+ k.createInstance = pe.createInstance;
1537
+ k.createInstance;
1538
+ k.dir;
1539
+ k.init;
1540
+ k.loadResources;
1541
+ k.reloadResources;
1542
+ k.use;
1543
+ k.changeLanguage;
1544
+ k.getFixedT;
1545
+ const be = k.t;
1546
+ k.exists;
1547
+ k.setDefaultNamespace;
1548
+ k.hasLoadedNamespace;
1549
+ k.loadNamespaces;
1550
+ k.loadLanguages;
1551
+ const bn = {
1552
+ es: {
1553
+ translation: {
1554
+ ...Qr
1555
+ }
1556
+ }
1557
+ };
1558
+ k.init({
1559
+ resources: bn,
1560
+ lng: "es",
1561
+ // language to use, more information here: https://www.i18next.com/overview/configuration-options#languages-namespaces-resources
1562
+ // you can use the i18n.changeLanguage function to change the language manually: https://www.i18next.com/overview/api#changelanguage
1563
+ // if you're using a language detector, do not define the lng option
1564
+ supportedLngs: ["es", "en"],
1565
+ interpolation: {
1566
+ escapeValue: !1
1567
+ // react already safes from xss
1568
+ },
1569
+ debug: !1
1570
+ });
1571
+ const j = {
1572
+ // EXAMPLE ERROR
1573
+ "MP-001": {
1574
+ code: 400,
1575
+ type: "modal",
1576
+ message: "errors.MP-001.message",
1577
+ title: "errors.MP-001.title",
1578
+ level: "info"
1579
+ },
1580
+ UNAUTHORIZED: {
1581
+ level: "error",
1582
+ type: "modal",
1583
+ message: "errors.UnAuthorized.message",
1584
+ title: "errors.UnAuthorized.title",
1585
+ code: 310
1586
+ },
1587
+ "ERR-GENERAL-01": {
1588
+ level: "error",
1589
+ type: "modal",
1590
+ message: "errors.ERR-GENERAL-01.message",
1591
+ title: "errors.ERR-GENERAL-01.title",
1592
+ code: 400
1593
+ },
1594
+ internalError: {
1595
+ level: "error",
1596
+ type: "modal",
1597
+ message: "errors.internalError.message",
1598
+ title: "errors.internalError.title",
1599
+ code: 500
1600
+ },
1601
+ default: {
1602
+ code: 520,
1603
+ type: "modal",
1604
+ message: "errors.default.message",
1605
+ title: "errors.default.title",
1606
+ level: "warning"
1607
+ }
1608
+ };
1609
+ class vn extends jt {
1610
+ get(e = "default") {
1611
+ var a, s;
1612
+ if (e instanceof Error)
1613
+ return this.logError(e.message), {
1614
+ ...j.internalError,
1615
+ title: be(j.internalError.title),
1616
+ message: be(j.internalError.message)
1617
+ };
1618
+ const r = typeof e == "string" ? e : e.code ?? e.errorType, n = typeof e == "string" ? {} : { ...e };
1619
+ return {
1620
+ ...j[r] ?? j.default,
1621
+ title: be(
1622
+ ((a = j[r]) == null ? void 0 : a.title) ?? j.default.title,
1623
+ n
1624
+ ),
1625
+ message: be(
1626
+ ((s = j[r]) == null ? void 0 : s.message) ?? j.default.message,
1627
+ n
1628
+ )
1629
+ };
1630
+ }
1631
+ }
1632
+ class En extends jt {
1633
+ constructor(r) {
1634
+ super();
1635
+ Kt(this, "messageError");
1636
+ const n = new vn();
1637
+ this.messageError = n.get(r), this.logError("MessageErrorBFF", JSON.stringify(this.messageError));
1638
+ }
1639
+ get() {
1640
+ return this.messageError;
1641
+ }
1642
+ }
1643
+ var rr = {}, nr = { exports: {} };
1644
+ (function(t) {
1645
+ function e(r) {
1646
+ return r && r.__esModule ? r : {
1647
+ default: r
1648
+ };
1649
+ }
1650
+ t.exports = e, t.exports.__esModule = !0, t.exports.default = t.exports;
1651
+ })(nr);
1652
+ var ar = nr.exports;
1653
+ const b = crypto, G = (t) => t instanceof CryptoKey, sr = async (t, e) => {
1654
+ const r = `SHA-${t.slice(-3)}`;
1655
+ return new Uint8Array(await b.subtle.digest(r, e));
1656
+ }, K = new TextEncoder(), X = new TextDecoder(), Ke = 2 ** 32;
1657
+ function Q(...t) {
1658
+ const e = t.reduce((a, { length: s }) => a + s, 0), r = new Uint8Array(e);
1659
+ let n = 0;
1660
+ return t.forEach((a) => {
1661
+ r.set(a, n), n += a.length;
1662
+ }), r;
1663
+ }
1664
+ function An(t, e) {
1665
+ return Q(K.encode(t), new Uint8Array([0]), e);
1666
+ }
1667
+ function it(t, e, r) {
1668
+ if (e < 0 || e >= Ke)
1669
+ throw new RangeError(`value must be >= 0 and <= ${Ke - 1}. Received ${e}`);
1670
+ t.set([e >>> 24, e >>> 16, e >>> 8, e & 255], r);
1671
+ }
1672
+ function ir(t) {
1673
+ const e = Math.floor(t / Ke), r = t % Ke, n = new Uint8Array(8);
1674
+ return it(n, e, 0), it(n, r, 4), n;
1675
+ }
1676
+ function pt(t) {
1677
+ const e = new Uint8Array(4);
1678
+ return it(e, t), e;
1679
+ }
1680
+ function ze(t) {
1681
+ return Q(pt(t.length), t);
1682
+ }
1683
+ async function xn(t, e, r) {
1684
+ const n = Math.ceil((e >> 3) / 32), a = new Uint8Array(n * 32);
1685
+ for (let s = 0; s < n; s++) {
1686
+ const i = new Uint8Array(4 + t.length + r.length);
1687
+ i.set(pt(s + 1)), i.set(t, 4), i.set(r, 4 + t.length), a.set(await sr("sha256", i), s * 32);
1688
+ }
1689
+ return a.slice(0, e >> 3);
1690
+ }
1691
+ const gt = (t) => {
1692
+ let e = t;
1693
+ typeof e == "string" && (e = K.encode(e));
1694
+ const r = 32768, n = [];
1695
+ for (let a = 0; a < e.length; a += r)
1696
+ n.push(String.fromCharCode.apply(null, e.subarray(a, a + r)));
1697
+ return btoa(n.join(""));
1698
+ }, O = (t) => gt(t).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_"), or = (t) => {
1699
+ const e = atob(t), r = new Uint8Array(e.length);
1700
+ for (let n = 0; n < e.length; n++)
1701
+ r[n] = e.charCodeAt(n);
1702
+ return r;
1703
+ }, T = (t) => {
1704
+ let e = t;
1705
+ e instanceof Uint8Array && (e = X.decode(e)), e = e.replace(/-/g, "+").replace(/_/g, "/").replace(/\s/g, "");
1706
+ try {
1707
+ return or(e);
1708
+ } catch {
1709
+ throw new TypeError("The input to be decoded is not correctly encoded.");
1710
+ }
1711
+ };
1712
+ class L extends Error {
1713
+ static get code() {
1714
+ return "ERR_JOSE_GENERIC";
1715
+ }
1716
+ constructor(e) {
1717
+ var r;
1718
+ super(e), this.code = "ERR_JOSE_GENERIC", this.name = this.constructor.name, (r = Error.captureStackTrace) === null || r === void 0 || r.call(Error, this, this.constructor);
1719
+ }
1720
+ }
1721
+ class V extends L {
1722
+ static get code() {
1723
+ return "ERR_JWT_CLAIM_VALIDATION_FAILED";
1724
+ }
1725
+ constructor(e, r = "unspecified", n = "unspecified") {
1726
+ super(e), this.code = "ERR_JWT_CLAIM_VALIDATION_FAILED", this.claim = r, this.reason = n;
1727
+ }
1728
+ }
1729
+ class ot extends L {
1730
+ static get code() {
1731
+ return "ERR_JWT_EXPIRED";
1732
+ }
1733
+ constructor(e, r = "unspecified", n = "unspecified") {
1734
+ super(e), this.code = "ERR_JWT_EXPIRED", this.claim = r, this.reason = n;
1735
+ }
1736
+ }
1737
+ class Re extends L {
1738
+ constructor() {
1739
+ super(...arguments), this.code = "ERR_JOSE_ALG_NOT_ALLOWED";
1740
+ }
1741
+ static get code() {
1742
+ return "ERR_JOSE_ALG_NOT_ALLOWED";
1743
+ }
1744
+ }
1745
+ class x extends L {
1746
+ constructor() {
1747
+ super(...arguments), this.code = "ERR_JOSE_NOT_SUPPORTED";
1748
+ }
1749
+ static get code() {
1750
+ return "ERR_JOSE_NOT_SUPPORTED";
1751
+ }
1752
+ }
1753
+ class ge extends L {
1754
+ constructor() {
1755
+ super(...arguments), this.code = "ERR_JWE_DECRYPTION_FAILED", this.message = "decryption operation failed";
1756
+ }
1757
+ static get code() {
1758
+ return "ERR_JWE_DECRYPTION_FAILED";
1759
+ }
1760
+ }
1761
+ class y extends L {
1762
+ constructor() {
1763
+ super(...arguments), this.code = "ERR_JWE_INVALID";
1764
+ }
1765
+ static get code() {
1766
+ return "ERR_JWE_INVALID";
1767
+ }
1768
+ }
1769
+ class P extends L {
1770
+ constructor() {
1771
+ super(...arguments), this.code = "ERR_JWS_INVALID";
1772
+ }
1773
+ static get code() {
1774
+ return "ERR_JWS_INVALID";
1775
+ }
1776
+ }
1777
+ class B extends L {
1778
+ constructor() {
1779
+ super(...arguments), this.code = "ERR_JWT_INVALID";
1780
+ }
1781
+ static get code() {
1782
+ return "ERR_JWT_INVALID";
1783
+ }
1784
+ }
1785
+ class cr extends L {
1786
+ constructor() {
1787
+ super(...arguments), this.code = "ERR_JWK_INVALID";
1788
+ }
1789
+ static get code() {
1790
+ return "ERR_JWK_INVALID";
1791
+ }
1792
+ }
1793
+ class Le extends L {
1794
+ constructor() {
1795
+ super(...arguments), this.code = "ERR_JWKS_INVALID";
1796
+ }
1797
+ static get code() {
1798
+ return "ERR_JWKS_INVALID";
1799
+ }
1800
+ }
1801
+ class mt extends L {
1802
+ constructor() {
1803
+ super(...arguments), this.code = "ERR_JWKS_NO_MATCHING_KEY", this.message = "no applicable key found in the JSON Web Key Set";
1804
+ }
1805
+ static get code() {
1806
+ return "ERR_JWKS_NO_MATCHING_KEY";
1807
+ }
1808
+ }
1809
+ class ur extends L {
1810
+ constructor() {
1811
+ super(...arguments), this.code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS", this.message = "multiple matching keys found in the JSON Web Key Set";
1812
+ }
1813
+ static get code() {
1814
+ return "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
1815
+ }
1816
+ }
1817
+ class lr extends L {
1818
+ constructor() {
1819
+ super(...arguments), this.code = "ERR_JWKS_TIMEOUT", this.message = "request timed out";
1820
+ }
1821
+ static get code() {
1822
+ return "ERR_JWKS_TIMEOUT";
1823
+ }
1824
+ }
1825
+ class yt extends L {
1826
+ constructor() {
1827
+ super(...arguments), this.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED", this.message = "signature verification failed";
1828
+ }
1829
+ static get code() {
1830
+ return "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
1831
+ }
1832
+ }
1833
+ const Cn = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1834
+ __proto__: null,
1835
+ JOSEAlgNotAllowed: Re,
1836
+ JOSEError: L,
1837
+ JOSENotSupported: x,
1838
+ JWEDecryptionFailed: ge,
1839
+ JWEInvalid: y,
1840
+ JWKInvalid: cr,
1841
+ JWKSInvalid: Le,
1842
+ JWKSMultipleMatchingKeys: ur,
1843
+ JWKSNoMatchingKey: mt,
1844
+ JWKSTimeout: lr,
1845
+ JWSInvalid: P,
1846
+ JWSSignatureVerificationFailed: yt,
1847
+ JWTClaimValidationFailed: V,
1848
+ JWTExpired: ot,
1849
+ JWTInvalid: B
1850
+ }, Symbol.toStringTag, { value: "Module" })), De = b.getRandomValues.bind(b);
1851
+ function dr(t) {
1852
+ switch (t) {
1853
+ case "A128GCM":
1854
+ case "A128GCMKW":
1855
+ case "A192GCM":
1856
+ case "A192GCMKW":
1857
+ case "A256GCM":
1858
+ case "A256GCMKW":
1859
+ return 96;
1860
+ case "A128CBC-HS256":
1861
+ case "A192CBC-HS384":
1862
+ case "A256CBC-HS512":
1863
+ return 128;
1864
+ default:
1865
+ throw new x(`Unsupported JWE Algorithm: ${t}`);
1866
+ }
1867
+ }
1868
+ const fr = (t) => De(new Uint8Array(dr(t) >> 3)), hr = (t, e) => {
1869
+ if (e.length << 3 !== dr(t))
1870
+ throw new y("Invalid Initialization Vector length");
1871
+ }, Oe = (t, e) => {
1872
+ const r = t.byteLength << 3;
1873
+ if (r !== e)
1874
+ throw new y(`Invalid Content Encryption Key length. Expected ${e} bits, got ${r} bits`);
1875
+ }, _n = (t, e) => {
1876
+ if (!(t instanceof Uint8Array))
1877
+ throw new TypeError("First argument must be a buffer");
1878
+ if (!(e instanceof Uint8Array))
1879
+ throw new TypeError("Second argument must be a buffer");
1880
+ if (t.length !== e.length)
1881
+ throw new TypeError("Input buffers must have the same length");
1882
+ const r = t.length;
1883
+ let n = 0, a = -1;
1884
+ for (; ++a < r; )
1885
+ n |= t[a] ^ e[a];
1886
+ return n === 0;
1887
+ };
1888
+ function U(t, e = "algorithm.name") {
1889
+ return new TypeError(`CryptoKey does not support this operation, its ${e} must be ${t}`);
1890
+ }
1891
+ function re(t, e) {
1892
+ return t.name === e;
1893
+ }
1894
+ function Ee(t) {
1895
+ return parseInt(t.name.slice(4), 10);
1896
+ }
1897
+ function Pn(t) {
1898
+ switch (t) {
1899
+ case "ES256":
1900
+ return "P-256";
1901
+ case "ES384":
1902
+ return "P-384";
1903
+ case "ES512":
1904
+ return "P-521";
1905
+ default:
1906
+ throw new Error("unreachable");
1907
+ }
1908
+ }
1909
+ function pr(t, e) {
1910
+ if (e.length && !e.some((r) => t.usages.includes(r))) {
1911
+ let r = "CryptoKey does not support this operation, its usages must include ";
1912
+ if (e.length > 2) {
1913
+ const n = e.pop();
1914
+ r += `one of ${e.join(", ")}, or ${n}.`;
1915
+ } else
1916
+ e.length === 2 ? r += `one of ${e[0]} or ${e[1]}.` : r += `${e[0]}.`;
1917
+ throw new TypeError(r);
1918
+ }
1919
+ }
1920
+ function Hn(t, e, ...r) {
1921
+ switch (e) {
1922
+ case "HS256":
1923
+ case "HS384":
1924
+ case "HS512": {
1925
+ if (!re(t.algorithm, "HMAC"))
1926
+ throw U("HMAC");
1927
+ const n = parseInt(e.slice(2), 10);
1928
+ if (Ee(t.algorithm.hash) !== n)
1929
+ throw U(`SHA-${n}`, "algorithm.hash");
1930
+ break;
1931
+ }
1932
+ case "RS256":
1933
+ case "RS384":
1934
+ case "RS512": {
1935
+ if (!re(t.algorithm, "RSASSA-PKCS1-v1_5"))
1936
+ throw U("RSASSA-PKCS1-v1_5");
1937
+ const n = parseInt(e.slice(2), 10);
1938
+ if (Ee(t.algorithm.hash) !== n)
1939
+ throw U(`SHA-${n}`, "algorithm.hash");
1940
+ break;
1941
+ }
1942
+ case "PS256":
1943
+ case "PS384":
1944
+ case "PS512": {
1945
+ if (!re(t.algorithm, "RSA-PSS"))
1946
+ throw U("RSA-PSS");
1947
+ const n = parseInt(e.slice(2), 10);
1948
+ if (Ee(t.algorithm.hash) !== n)
1949
+ throw U(`SHA-${n}`, "algorithm.hash");
1950
+ break;
1951
+ }
1952
+ case "EdDSA": {
1953
+ if (t.algorithm.name !== "Ed25519" && t.algorithm.name !== "Ed448")
1954
+ throw U("Ed25519 or Ed448");
1955
+ break;
1956
+ }
1957
+ case "ES256":
1958
+ case "ES384":
1959
+ case "ES512": {
1960
+ if (!re(t.algorithm, "ECDSA"))
1961
+ throw U("ECDSA");
1962
+ const n = Pn(e);
1963
+ if (t.algorithm.namedCurve !== n)
1964
+ throw U(n, "algorithm.namedCurve");
1965
+ break;
1966
+ }
1967
+ default:
1968
+ throw new TypeError("CryptoKey does not support this operation");
1969
+ }
1970
+ pr(t, r);
1971
+ }
1972
+ function ae(t, e, ...r) {
1973
+ switch (e) {
1974
+ case "A128GCM":
1975
+ case "A192GCM":
1976
+ case "A256GCM": {
1977
+ if (!re(t.algorithm, "AES-GCM"))
1978
+ throw U("AES-GCM");
1979
+ const n = parseInt(e.slice(1, 4), 10);
1980
+ if (t.algorithm.length !== n)
1981
+ throw U(n, "algorithm.length");
1982
+ break;
1983
+ }
1984
+ case "A128KW":
1985
+ case "A192KW":
1986
+ case "A256KW": {
1987
+ if (!re(t.algorithm, "AES-KW"))
1988
+ throw U("AES-KW");
1989
+ const n = parseInt(e.slice(1, 4), 10);
1990
+ if (t.algorithm.length !== n)
1991
+ throw U(n, "algorithm.length");
1992
+ break;
1993
+ }
1994
+ case "ECDH": {
1995
+ switch (t.algorithm.name) {
1996
+ case "ECDH":
1997
+ case "X25519":
1998
+ case "X448":
1999
+ break;
2000
+ default:
2001
+ throw U("ECDH, X25519, or X448");
2002
+ }
2003
+ break;
2004
+ }
2005
+ case "PBES2-HS256+A128KW":
2006
+ case "PBES2-HS384+A192KW":
2007
+ case "PBES2-HS512+A256KW":
2008
+ if (!re(t.algorithm, "PBKDF2"))
2009
+ throw U("PBKDF2");
2010
+ break;
2011
+ case "RSA-OAEP":
2012
+ case "RSA-OAEP-256":
2013
+ case "RSA-OAEP-384":
2014
+ case "RSA-OAEP-512": {
2015
+ if (!re(t.algorithm, "RSA-OAEP"))
2016
+ throw U("RSA-OAEP");
2017
+ const n = parseInt(e.slice(9), 10) || 1;
2018
+ if (Ee(t.algorithm.hash) !== n)
2019
+ throw U(`SHA-${n}`, "algorithm.hash");
2020
+ break;
2021
+ }
2022
+ default:
2023
+ throw new TypeError("CryptoKey does not support this operation");
2024
+ }
2025
+ pr(t, r);
2026
+ }
2027
+ function gr(t, e, ...r) {
2028
+ if (r.length > 2) {
2029
+ const n = r.pop();
2030
+ t += `one of type ${r.join(", ")}, or ${n}.`;
2031
+ } else
2032
+ r.length === 2 ? t += `one of type ${r[0]} or ${r[1]}.` : t += `of type ${r[0]}.`;
2033
+ return e == null ? t += ` Received ${e}` : typeof e == "function" && e.name ? t += ` Received function ${e.name}` : typeof e == "object" && e != null && e.constructor && e.constructor.name && (t += ` Received an instance of ${e.constructor.name}`), t;
2034
+ }
2035
+ const M = (t, ...e) => gr("Key must be ", t, ...e);
2036
+ function mr(t, e, ...r) {
2037
+ return gr(`Key for the ${t} algorithm must be `, e, ...r);
2038
+ }
2039
+ const yr = (t) => G(t), H = ["CryptoKey"];
2040
+ async function Kn(t, e, r, n, a, s) {
2041
+ if (!(e instanceof Uint8Array))
2042
+ throw new TypeError(M(e, "Uint8Array"));
2043
+ const i = parseInt(t.slice(1, 4), 10), o = await b.subtle.importKey("raw", e.subarray(i >> 3), "AES-CBC", !1, ["decrypt"]), c = await b.subtle.importKey("raw", e.subarray(0, i >> 3), {
2044
+ hash: `SHA-${i << 1}`,
2045
+ name: "HMAC"
2046
+ }, !1, ["sign"]), u = Q(s, n, r, ir(s.length << 3)), l = new Uint8Array((await b.subtle.sign("HMAC", c, u)).slice(0, i >> 3));
2047
+ let f;
2048
+ try {
2049
+ f = _n(a, l);
2050
+ } catch {
2051
+ }
2052
+ if (!f)
2053
+ throw new ge();
2054
+ let d;
2055
+ try {
2056
+ d = new Uint8Array(await b.subtle.decrypt({ iv: n, name: "AES-CBC" }, o, r));
2057
+ } catch {
2058
+ }
2059
+ if (!d)
2060
+ throw new ge();
2061
+ return d;
2062
+ }
2063
+ async function Rn(t, e, r, n, a, s) {
2064
+ let i;
2065
+ e instanceof Uint8Array ? i = await b.subtle.importKey("raw", e, "AES-GCM", !1, ["decrypt"]) : (ae(e, t, "decrypt"), i = e);
2066
+ try {
2067
+ return new Uint8Array(await b.subtle.decrypt({
2068
+ additionalData: s,
2069
+ iv: n,
2070
+ name: "AES-GCM",
2071
+ tagLength: 128
2072
+ }, i, Q(r, a)));
2073
+ } catch {
2074
+ throw new ge();
2075
+ }
2076
+ }
2077
+ const wr = async (t, e, r, n, a, s) => {
2078
+ if (!G(e) && !(e instanceof Uint8Array))
2079
+ throw new TypeError(M(e, ...H, "Uint8Array"));
2080
+ switch (hr(t, n), t) {
2081
+ case "A128CBC-HS256":
2082
+ case "A192CBC-HS384":
2083
+ case "A256CBC-HS512":
2084
+ return e instanceof Uint8Array && Oe(e, parseInt(t.slice(-3), 10)), Kn(t, e, r, n, a, s);
2085
+ case "A128GCM":
2086
+ case "A192GCM":
2087
+ case "A256GCM":
2088
+ return e instanceof Uint8Array && Oe(e, parseInt(t.slice(1, 4), 10)), Rn(t, e, r, n, a, s);
2089
+ default:
2090
+ throw new x("Unsupported JWE Content Encryption Algorithm");
2091
+ }
2092
+ }, On = async () => {
2093
+ throw new x('JWE "zip" (Compression Algorithm) Header Parameter is not supported by your javascript runtime. You need to use the `inflateRaw` decrypt option to provide Inflate Raw implementation.');
2094
+ }, Tn = async () => {
2095
+ throw new x('JWE "zip" (Compression Algorithm) Header Parameter is not supported by your javascript runtime. You need to use the `deflateRaw` encrypt option to provide Deflate Raw implementation.');
2096
+ }, me = (...t) => {
2097
+ const e = t.filter(Boolean);
2098
+ if (e.length === 0 || e.length === 1)
2099
+ return !0;
2100
+ let r;
2101
+ for (const n of e) {
2102
+ const a = Object.keys(n);
2103
+ if (!r || r.size === 0) {
2104
+ r = new Set(a);
2105
+ continue;
2106
+ }
2107
+ for (const s of a) {
2108
+ if (r.has(s))
2109
+ return !1;
2110
+ r.add(s);
2111
+ }
2112
+ }
2113
+ return !0;
2114
+ };
2115
+ function In(t) {
2116
+ return typeof t == "object" && t !== null;
2117
+ }
2118
+ function I(t) {
2119
+ if (!In(t) || Object.prototype.toString.call(t) !== "[object Object]")
2120
+ return !1;
2121
+ if (Object.getPrototypeOf(t) === null)
2122
+ return !0;
2123
+ let e = t;
2124
+ for (; Object.getPrototypeOf(e) !== null; )
2125
+ e = Object.getPrototypeOf(e);
2126
+ return Object.getPrototypeOf(t) === e;
2127
+ }
2128
+ const Je = [
2129
+ { hash: "SHA-256", name: "HMAC" },
2130
+ !0,
2131
+ ["sign"]
2132
+ ];
2133
+ function Sr(t, e) {
2134
+ if (t.algorithm.length !== parseInt(e.slice(1, 4), 10))
2135
+ throw new TypeError(`Invalid key size for alg: ${e}`);
2136
+ }
2137
+ function br(t, e, r) {
2138
+ if (G(t))
2139
+ return ae(t, e, r), t;
2140
+ if (t instanceof Uint8Array)
2141
+ return b.subtle.importKey("raw", t, "AES-KW", !0, [r]);
2142
+ throw new TypeError(M(t, ...H, "Uint8Array"));
2143
+ }
2144
+ const ct = async (t, e, r) => {
2145
+ const n = await br(e, t, "wrapKey");
2146
+ Sr(n, t);
2147
+ const a = await b.subtle.importKey("raw", r, ...Je);
2148
+ return new Uint8Array(await b.subtle.wrapKey("raw", a, n, "AES-KW"));
2149
+ }, ut = async (t, e, r) => {
2150
+ const n = await br(e, t, "unwrapKey");
2151
+ Sr(n, t);
2152
+ const a = await b.subtle.unwrapKey("raw", r, n, "AES-KW", ...Je);
2153
+ return new Uint8Array(await b.subtle.exportKey("raw", a));
2154
+ };
2155
+ async function vr(t, e, r, n, a = new Uint8Array(0), s = new Uint8Array(0)) {
2156
+ if (!G(t))
2157
+ throw new TypeError(M(t, ...H));
2158
+ if (ae(t, "ECDH"), !G(e))
2159
+ throw new TypeError(M(e, ...H));
2160
+ ae(e, "ECDH", "deriveBits");
2161
+ const i = Q(ze(K.encode(r)), ze(a), ze(s), pt(n));
2162
+ let o;
2163
+ t.algorithm.name === "X25519" ? o = 256 : t.algorithm.name === "X448" ? o = 448 : o = Math.ceil(parseInt(t.algorithm.namedCurve.substr(-3), 10) / 8) << 3;
2164
+ const c = new Uint8Array(await b.subtle.deriveBits({
2165
+ name: t.algorithm.name,
2166
+ public: t
2167
+ }, e, o));
2168
+ return xn(c, n, i);
2169
+ }
2170
+ async function Wn(t) {
2171
+ if (!G(t))
2172
+ throw new TypeError(M(t, ...H));
2173
+ return b.subtle.generateKey(t.algorithm, !0, ["deriveBits"]);
2174
+ }
2175
+ function Er(t) {
2176
+ if (!G(t))
2177
+ throw new TypeError(M(t, ...H));
2178
+ return ["P-256", "P-384", "P-521"].includes(t.algorithm.namedCurve) || t.algorithm.name === "X25519" || t.algorithm.name === "X448";
2179
+ }
2180
+ function Un(t) {
2181
+ if (!(t instanceof Uint8Array) || t.length < 8)
2182
+ throw new y("PBES2 Salt Input must be 8 or more octets");
2183
+ }
2184
+ function Ln(t, e) {
2185
+ if (t instanceof Uint8Array)
2186
+ return b.subtle.importKey("raw", t, "PBKDF2", !1, ["deriveBits"]);
2187
+ if (G(t))
2188
+ return ae(t, e, "deriveBits", "deriveKey"), t;
2189
+ throw new TypeError(M(t, ...H, "Uint8Array"));
2190
+ }
2191
+ async function Ar(t, e, r, n) {
2192
+ Un(t);
2193
+ const a = An(e, t), s = parseInt(e.slice(13, 16), 10), i = {
2194
+ hash: `SHA-${e.slice(8, 11)}`,
2195
+ iterations: r,
2196
+ name: "PBKDF2",
2197
+ salt: a
2198
+ }, o = {
2199
+ length: s,
2200
+ name: "AES-KW"
2201
+ }, c = await Ln(n, e);
2202
+ if (c.usages.includes("deriveBits"))
2203
+ return new Uint8Array(await b.subtle.deriveBits(i, c, s));
2204
+ if (c.usages.includes("deriveKey"))
2205
+ return b.subtle.deriveKey(i, c, o, !1, ["wrapKey", "unwrapKey"]);
2206
+ throw new TypeError('PBKDF2 key "usages" must include "deriveBits" or "deriveKey"');
2207
+ }
2208
+ const Dn = async (t, e, r, n = 2048, a = De(new Uint8Array(16))) => {
2209
+ const s = await Ar(a, t, n, e);
2210
+ return { encryptedKey: await ct(t.slice(-6), s, r), p2c: n, p2s: O(a) };
2211
+ }, Jn = async (t, e, r, n, a) => {
2212
+ const s = await Ar(a, t, n, e);
2213
+ return ut(t.slice(-6), s, r);
2214
+ };
2215
+ function Te(t) {
2216
+ switch (t) {
2217
+ case "RSA-OAEP":
2218
+ case "RSA-OAEP-256":
2219
+ case "RSA-OAEP-384":
2220
+ case "RSA-OAEP-512":
2221
+ return "RSA-OAEP";
2222
+ default:
2223
+ throw new x(`alg ${t} is not supported either by JOSE or your javascript runtime`);
2224
+ }
2225
+ }
2226
+ const Ne = (t, e) => {
2227
+ if (t.startsWith("RS") || t.startsWith("PS")) {
2228
+ const { modulusLength: r } = e.algorithm;
2229
+ if (typeof r != "number" || r < 2048)
2230
+ throw new TypeError(`${t} requires key modulusLength to be 2048 bits or larger`);
2231
+ }
2232
+ }, Nn = async (t, e, r) => {
2233
+ if (!G(e))
2234
+ throw new TypeError(M(e, ...H));
2235
+ if (ae(e, t, "encrypt", "wrapKey"), Ne(t, e), e.usages.includes("encrypt"))
2236
+ return new Uint8Array(await b.subtle.encrypt(Te(t), e, r));
2237
+ if (e.usages.includes("wrapKey")) {
2238
+ const n = await b.subtle.importKey("raw", r, ...Je);
2239
+ return new Uint8Array(await b.subtle.wrapKey("raw", n, e, Te(t)));
2240
+ }
2241
+ throw new TypeError('RSA-OAEP key "usages" must include "encrypt" or "wrapKey" for this operation');
2242
+ }, $n = async (t, e, r) => {
2243
+ if (!G(e))
2244
+ throw new TypeError(M(e, ...H));
2245
+ if (ae(e, t, "decrypt", "unwrapKey"), Ne(t, e), e.usages.includes("decrypt"))
2246
+ return new Uint8Array(await b.subtle.decrypt(Te(t), e, r));
2247
+ if (e.usages.includes("unwrapKey")) {
2248
+ const n = await b.subtle.unwrapKey("raw", r, e, Te(t), ...Je);
2249
+ return new Uint8Array(await b.subtle.exportKey("raw", n));
2250
+ }
2251
+ throw new TypeError('RSA-OAEP key "usages" must include "decrypt" or "unwrapKey" for this operation');
2252
+ };
2253
+ function wt(t) {
2254
+ switch (t) {
2255
+ case "A128GCM":
2256
+ return 128;
2257
+ case "A192GCM":
2258
+ return 192;
2259
+ case "A256GCM":
2260
+ case "A128CBC-HS256":
2261
+ return 256;
2262
+ case "A192CBC-HS384":
2263
+ return 384;
2264
+ case "A256CBC-HS512":
2265
+ return 512;
2266
+ default:
2267
+ throw new x(`Unsupported JWE Algorithm: ${t}`);
2268
+ }
2269
+ }
2270
+ const ie = (t) => De(new Uint8Array(wt(t) >> 3)), xr = (t, e) => {
2271
+ const r = (t.match(/.{1,64}/g) || []).join(`
2272
+ `);
2273
+ return `-----BEGIN ${e}-----
2274
+ ${r}
2275
+ -----END ${e}-----`;
2276
+ }, Cr = async (t, e, r) => {
2277
+ if (!G(r))
2278
+ throw new TypeError(M(r, ...H));
2279
+ if (!r.extractable)
2280
+ throw new TypeError("CryptoKey is not extractable");
2281
+ if (r.type !== t)
2282
+ throw new TypeError(`key is not a ${t} key`);
2283
+ return xr(gt(new Uint8Array(await b.subtle.exportKey(e, r))), `${t.toUpperCase()} KEY`);
2284
+ }, Mn = (t) => Cr("public", "spki", t), kn = (t) => Cr("private", "pkcs8", t), te = (t, e, r = 0) => {
2285
+ r === 0 && (e.unshift(e.length), e.unshift(6));
2286
+ let n = t.indexOf(e[0], r);
2287
+ if (n === -1)
2288
+ return !1;
2289
+ const a = t.subarray(n, n + e.length);
2290
+ return a.length !== e.length ? !1 : a.every((s, i) => s === e[i]) || te(t, e, n + 1);
2291
+ }, Nt = (t) => {
2292
+ switch (!0) {
2293
+ case te(t, [42, 134, 72, 206, 61, 3, 1, 7]):
2294
+ return "P-256";
2295
+ case te(t, [43, 129, 4, 0, 34]):
2296
+ return "P-384";
2297
+ case te(t, [43, 129, 4, 0, 35]):
2298
+ return "P-521";
2299
+ case te(t, [43, 101, 110]):
2300
+ return "X25519";
2301
+ case te(t, [43, 101, 111]):
2302
+ return "X448";
2303
+ case te(t, [43, 101, 112]):
2304
+ return "Ed25519";
2305
+ case te(t, [43, 101, 113]):
2306
+ return "Ed448";
2307
+ default:
2308
+ throw new x("Invalid or unsupported EC Key Curve or OKP Key Sub Type");
2309
+ }
2310
+ }, _r = async (t, e, r, n, a) => {
2311
+ var s;
2312
+ let i, o;
2313
+ const c = new Uint8Array(atob(r.replace(t, "")).split("").map((l) => l.charCodeAt(0))), u = e === "spki";
2314
+ switch (n) {
2315
+ case "PS256":
2316
+ case "PS384":
2317
+ case "PS512":
2318
+ i = { name: "RSA-PSS", hash: `SHA-${n.slice(-3)}` }, o = u ? ["verify"] : ["sign"];
2319
+ break;
2320
+ case "RS256":
2321
+ case "RS384":
2322
+ case "RS512":
2323
+ i = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${n.slice(-3)}` }, o = u ? ["verify"] : ["sign"];
2324
+ break;
2325
+ case "RSA-OAEP":
2326
+ case "RSA-OAEP-256":
2327
+ case "RSA-OAEP-384":
2328
+ case "RSA-OAEP-512":
2329
+ i = {
2330
+ name: "RSA-OAEP",
2331
+ hash: `SHA-${parseInt(n.slice(-3), 10) || 1}`
2332
+ }, o = u ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
2333
+ break;
2334
+ case "ES256":
2335
+ i = { name: "ECDSA", namedCurve: "P-256" }, o = u ? ["verify"] : ["sign"];
2336
+ break;
2337
+ case "ES384":
2338
+ i = { name: "ECDSA", namedCurve: "P-384" }, o = u ? ["verify"] : ["sign"];
2339
+ break;
2340
+ case "ES512":
2341
+ i = { name: "ECDSA", namedCurve: "P-521" }, o = u ? ["verify"] : ["sign"];
2342
+ break;
2343
+ case "ECDH-ES":
2344
+ case "ECDH-ES+A128KW":
2345
+ case "ECDH-ES+A192KW":
2346
+ case "ECDH-ES+A256KW": {
2347
+ const l = Nt(c);
2348
+ i = l.startsWith("P-") ? { name: "ECDH", namedCurve: l } : { name: l }, o = u ? [] : ["deriveBits"];
2349
+ break;
2350
+ }
2351
+ case "EdDSA":
2352
+ i = { name: Nt(c) }, o = u ? ["verify"] : ["sign"];
2353
+ break;
2354
+ default:
2355
+ throw new x('Invalid or unsupported "alg" (Algorithm) value');
2356
+ }
2357
+ return b.subtle.importKey(e, c, i, (s = a == null ? void 0 : a.extractable) !== null && s !== void 0 ? s : !1, o);
2358
+ }, Fn = (t, e, r) => _r(/(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g, "pkcs8", t, e, r), Pr = (t, e, r) => _r(/(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g, "spki", t, e, r);
2359
+ function $t(t) {
2360
+ let e = [], r = 0;
2361
+ for (; r < t.length; ) {
2362
+ let n = Hr(t.subarray(r));
2363
+ e.push(n), r += n.byteLength;
2364
+ }
2365
+ return e;
2366
+ }
2367
+ function Hr(t) {
2368
+ let e = 0, r = t[0] & 31;
2369
+ if (e++, r === 31) {
2370
+ for (r = 0; t[e] >= 128; )
2371
+ r = r * 128 + t[e] - 128, e++;
2372
+ r = r * 128 + t[e] - 128, e++;
2373
+ }
2374
+ let n = 0;
2375
+ if (t[e] < 128)
2376
+ n = t[e], e++;
2377
+ else if (n === 128) {
2378
+ for (n = 0; t[e + n] !== 0 || t[e + n + 1] !== 0; ) {
2379
+ if (n > t.byteLength)
2380
+ throw new TypeError("invalid indefinite form length");
2381
+ n++;
2382
+ }
2383
+ const s = e + n + 2;
2384
+ return {
2385
+ byteLength: s,
2386
+ contents: t.subarray(e, e + n),
2387
+ raw: t.subarray(0, s)
2388
+ };
2389
+ } else {
2390
+ let s = t[e] & 127;
2391
+ e++, n = 0;
2392
+ for (let i = 0; i < s; i++)
2393
+ n = n * 256 + t[e], e++;
2394
+ }
2395
+ const a = e + n;
2396
+ return {
2397
+ byteLength: a,
2398
+ contents: t.subarray(e, a),
2399
+ raw: t.subarray(0, a)
2400
+ };
2401
+ }
2402
+ function Vn(t) {
2403
+ const e = $t($t(Hr(t).contents)[0].contents);
2404
+ return gt(e[e[0].raw[0] === 160 ? 6 : 5].raw);
2405
+ }
2406
+ function Bn(t) {
2407
+ const e = t.replace(/(?:-----(?:BEGIN|END) CERTIFICATE-----|\s)/g, ""), r = or(e);
2408
+ return xr(Vn(r), "PUBLIC KEY");
2409
+ }
2410
+ const Gn = (t, e, r) => {
2411
+ let n;
2412
+ try {
2413
+ n = Bn(t);
2414
+ } catch (a) {
2415
+ throw new TypeError("Failed to parse the X.509 certificate", { cause: a });
2416
+ }
2417
+ return Pr(n, e, r);
2418
+ };
2419
+ function zn(t) {
2420
+ let e, r;
2421
+ switch (t.kty) {
2422
+ case "oct": {
2423
+ switch (t.alg) {
2424
+ case "HS256":
2425
+ case "HS384":
2426
+ case "HS512":
2427
+ e = { name: "HMAC", hash: `SHA-${t.alg.slice(-3)}` }, r = ["sign", "verify"];
2428
+ break;
2429
+ case "A128CBC-HS256":
2430
+ case "A192CBC-HS384":
2431
+ case "A256CBC-HS512":
2432
+ throw new x(`${t.alg} keys cannot be imported as CryptoKey instances`);
2433
+ case "A128GCM":
2434
+ case "A192GCM":
2435
+ case "A256GCM":
2436
+ case "A128GCMKW":
2437
+ case "A192GCMKW":
2438
+ case "A256GCMKW":
2439
+ e = { name: "AES-GCM" }, r = ["encrypt", "decrypt"];
2440
+ break;
2441
+ case "A128KW":
2442
+ case "A192KW":
2443
+ case "A256KW":
2444
+ e = { name: "AES-KW" }, r = ["wrapKey", "unwrapKey"];
2445
+ break;
2446
+ case "PBES2-HS256+A128KW":
2447
+ case "PBES2-HS384+A192KW":
2448
+ case "PBES2-HS512+A256KW":
2449
+ e = { name: "PBKDF2" }, r = ["deriveBits"];
2450
+ break;
2451
+ default:
2452
+ throw new x('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
2453
+ }
2454
+ break;
2455
+ }
2456
+ case "RSA": {
2457
+ switch (t.alg) {
2458
+ case "PS256":
2459
+ case "PS384":
2460
+ case "PS512":
2461
+ e = { name: "RSA-PSS", hash: `SHA-${t.alg.slice(-3)}` }, r = t.d ? ["sign"] : ["verify"];
2462
+ break;
2463
+ case "RS256":
2464
+ case "RS384":
2465
+ case "RS512":
2466
+ e = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${t.alg.slice(-3)}` }, r = t.d ? ["sign"] : ["verify"];
2467
+ break;
2468
+ case "RSA-OAEP":
2469
+ case "RSA-OAEP-256":
2470
+ case "RSA-OAEP-384":
2471
+ case "RSA-OAEP-512":
2472
+ e = {
2473
+ name: "RSA-OAEP",
2474
+ hash: `SHA-${parseInt(t.alg.slice(-3), 10) || 1}`
2475
+ }, r = t.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
2476
+ break;
2477
+ default:
2478
+ throw new x('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
2479
+ }
2480
+ break;
2481
+ }
2482
+ case "EC": {
2483
+ switch (t.alg) {
2484
+ case "ES256":
2485
+ e = { name: "ECDSA", namedCurve: "P-256" }, r = t.d ? ["sign"] : ["verify"];
2486
+ break;
2487
+ case "ES384":
2488
+ e = { name: "ECDSA", namedCurve: "P-384" }, r = t.d ? ["sign"] : ["verify"];
2489
+ break;
2490
+ case "ES512":
2491
+ e = { name: "ECDSA", namedCurve: "P-521" }, r = t.d ? ["sign"] : ["verify"];
2492
+ break;
2493
+ case "ECDH-ES":
2494
+ case "ECDH-ES+A128KW":
2495
+ case "ECDH-ES+A192KW":
2496
+ case "ECDH-ES+A256KW":
2497
+ e = { name: "ECDH", namedCurve: t.crv }, r = t.d ? ["deriveBits"] : [];
2498
+ break;
2499
+ default:
2500
+ throw new x('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
2501
+ }
2502
+ break;
2503
+ }
2504
+ case "OKP": {
2505
+ switch (t.alg) {
2506
+ case "EdDSA":
2507
+ e = { name: t.crv }, r = t.d ? ["sign"] : ["verify"];
2508
+ break;
2509
+ case "ECDH-ES":
2510
+ case "ECDH-ES+A128KW":
2511
+ case "ECDH-ES+A192KW":
2512
+ case "ECDH-ES+A256KW":
2513
+ e = { name: t.crv }, r = t.d ? ["deriveBits"] : [];
2514
+ break;
2515
+ default:
2516
+ throw new x('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
2517
+ }
2518
+ break;
2519
+ }
2520
+ default:
2521
+ throw new x('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
2522
+ }
2523
+ return { algorithm: e, keyUsages: r };
2524
+ }
2525
+ const qn = async (t) => {
2526
+ var e, r;
2527
+ if (!t.alg)
2528
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
2529
+ const { algorithm: n, keyUsages: a } = zn(t), s = [
2530
+ n,
2531
+ (e = t.ext) !== null && e !== void 0 ? e : !1,
2532
+ (r = t.key_ops) !== null && r !== void 0 ? r : a
2533
+ ];
2534
+ if (n.name === "PBKDF2")
2535
+ return b.subtle.importKey("raw", T(t.k), ...s);
2536
+ const i = { ...t };
2537
+ return delete i.alg, delete i.use, b.subtle.importKey("jwk", i, ...s);
2538
+ }, Mt = qn;
2539
+ async function Xn(t, e, r) {
2540
+ if (typeof t != "string" || t.indexOf("-----BEGIN PUBLIC KEY-----") !== 0)
2541
+ throw new TypeError('"spki" must be SPKI formatted string');
2542
+ return Pr(t, e, r);
2543
+ }
2544
+ async function Yn(t, e, r) {
2545
+ if (typeof t != "string" || t.indexOf("-----BEGIN CERTIFICATE-----") !== 0)
2546
+ throw new TypeError('"x509" must be X.509 formatted string');
2547
+ return Gn(t, e, r);
2548
+ }
2549
+ async function Zn(t, e, r) {
2550
+ if (typeof t != "string" || t.indexOf("-----BEGIN PRIVATE KEY-----") !== 0)
2551
+ throw new TypeError('"pkcs8" must be PKCS#8 formatted string');
2552
+ return Fn(t, e, r);
2553
+ }
2554
+ async function $e(t, e, r) {
2555
+ var n;
2556
+ if (!I(t))
2557
+ throw new TypeError("JWK must be an object");
2558
+ switch (e || (e = t.alg), t.kty) {
2559
+ case "oct":
2560
+ if (typeof t.k != "string" || !t.k)
2561
+ throw new TypeError('missing "k" (Key Value) Parameter value');
2562
+ return r ?? (r = t.ext !== !0), r ? Mt({ ...t, alg: e, ext: (n = t.ext) !== null && n !== void 0 ? n : !1 }) : T(t.k);
2563
+ case "RSA":
2564
+ if (t.oth !== void 0)
2565
+ throw new x('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
2566
+ case "EC":
2567
+ case "OKP":
2568
+ return Mt({ ...t, alg: e });
2569
+ default:
2570
+ throw new x('Unsupported "kty" (Key Type) Parameter value');
2571
+ }
2572
+ }
2573
+ const Qn = (t, e) => {
2574
+ if (!(e instanceof Uint8Array)) {
2575
+ if (!yr(e))
2576
+ throw new TypeError(mr(t, e, ...H, "Uint8Array"));
2577
+ if (e.type !== "secret")
2578
+ throw new TypeError(`${H.join(" or ")} instances for symmetric algorithms must be of type "secret"`);
2579
+ }
2580
+ }, jn = (t, e, r) => {
2581
+ if (!yr(e))
2582
+ throw new TypeError(mr(t, e, ...H));
2583
+ if (e.type === "secret")
2584
+ throw new TypeError(`${H.join(" or ")} instances for asymmetric algorithms must not be of type "secret"`);
2585
+ if (r === "sign" && e.type === "public")
2586
+ throw new TypeError(`${H.join(" or ")} instances for asymmetric algorithm signing must be of type "private"`);
2587
+ if (r === "decrypt" && e.type === "public")
2588
+ throw new TypeError(`${H.join(" or ")} instances for asymmetric algorithm decryption must be of type "private"`);
2589
+ if (e.algorithm && r === "verify" && e.type === "private")
2590
+ throw new TypeError(`${H.join(" or ")} instances for asymmetric algorithm verifying must be of type "public"`);
2591
+ if (e.algorithm && r === "encrypt" && e.type === "private")
2592
+ throw new TypeError(`${H.join(" or ")} instances for asymmetric algorithm encryption must be of type "public"`);
2593
+ }, Me = (t, e, r) => {
2594
+ t.startsWith("HS") || t === "dir" || t.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(t) ? Qn(t, e) : jn(t, e, r);
2595
+ };
2596
+ async function ea(t, e, r, n, a) {
2597
+ if (!(r instanceof Uint8Array))
2598
+ throw new TypeError(M(r, "Uint8Array"));
2599
+ const s = parseInt(t.slice(1, 4), 10), i = await b.subtle.importKey("raw", r.subarray(s >> 3), "AES-CBC", !1, ["encrypt"]), o = await b.subtle.importKey("raw", r.subarray(0, s >> 3), {
2600
+ hash: `SHA-${s << 1}`,
2601
+ name: "HMAC"
2602
+ }, !1, ["sign"]), c = new Uint8Array(await b.subtle.encrypt({
2603
+ iv: n,
2604
+ name: "AES-CBC"
2605
+ }, i, e)), u = Q(a, n, c, ir(a.length << 3)), l = new Uint8Array((await b.subtle.sign("HMAC", o, u)).slice(0, s >> 3));
2606
+ return { ciphertext: c, tag: l };
2607
+ }
2608
+ async function ta(t, e, r, n, a) {
2609
+ let s;
2610
+ r instanceof Uint8Array ? s = await b.subtle.importKey("raw", r, "AES-GCM", !1, ["encrypt"]) : (ae(r, t, "encrypt"), s = r);
2611
+ const i = new Uint8Array(await b.subtle.encrypt({
2612
+ additionalData: a,
2613
+ iv: n,
2614
+ name: "AES-GCM",
2615
+ tagLength: 128
2616
+ }, s, e)), o = i.slice(-16);
2617
+ return { ciphertext: i.slice(0, -16), tag: o };
2618
+ }
2619
+ const lt = async (t, e, r, n, a) => {
2620
+ if (!G(r) && !(r instanceof Uint8Array))
2621
+ throw new TypeError(M(r, ...H, "Uint8Array"));
2622
+ switch (hr(t, n), t) {
2623
+ case "A128CBC-HS256":
2624
+ case "A192CBC-HS384":
2625
+ case "A256CBC-HS512":
2626
+ return r instanceof Uint8Array && Oe(r, parseInt(t.slice(-3), 10)), ea(t, e, r, n, a);
2627
+ case "A128GCM":
2628
+ case "A192GCM":
2629
+ case "A256GCM":
2630
+ return r instanceof Uint8Array && Oe(r, parseInt(t.slice(1, 4), 10)), ta(t, e, r, n, a);
2631
+ default:
2632
+ throw new x("Unsupported JWE Content Encryption Algorithm");
2633
+ }
2634
+ };
2635
+ async function ra(t, e, r, n) {
2636
+ const a = t.slice(0, 7);
2637
+ n || (n = fr(a));
2638
+ const { ciphertext: s, tag: i } = await lt(a, r, e, n, new Uint8Array(0));
2639
+ return { encryptedKey: s, iv: O(n), tag: O(i) };
2640
+ }
2641
+ async function na(t, e, r, n, a) {
2642
+ const s = t.slice(0, 7);
2643
+ return wr(s, e, r, n, a, new Uint8Array(0));
2644
+ }
2645
+ async function aa(t, e, r, n, a) {
2646
+ switch (Me(t, e, "decrypt"), t) {
2647
+ case "dir": {
2648
+ if (r !== void 0)
2649
+ throw new y("Encountered unexpected JWE Encrypted Key");
2650
+ return e;
2651
+ }
2652
+ case "ECDH-ES":
2653
+ if (r !== void 0)
2654
+ throw new y("Encountered unexpected JWE Encrypted Key");
2655
+ case "ECDH-ES+A128KW":
2656
+ case "ECDH-ES+A192KW":
2657
+ case "ECDH-ES+A256KW": {
2658
+ if (!I(n.epk))
2659
+ throw new y('JOSE Header "epk" (Ephemeral Public Key) missing or invalid');
2660
+ if (!Er(e))
2661
+ throw new x("ECDH with the provided key is not allowed or not supported by your javascript runtime");
2662
+ const s = await $e(n.epk, t);
2663
+ let i, o;
2664
+ if (n.apu !== void 0) {
2665
+ if (typeof n.apu != "string")
2666
+ throw new y('JOSE Header "apu" (Agreement PartyUInfo) invalid');
2667
+ try {
2668
+ i = T(n.apu);
2669
+ } catch {
2670
+ throw new y("Failed to base64url decode the apu");
2671
+ }
2672
+ }
2673
+ if (n.apv !== void 0) {
2674
+ if (typeof n.apv != "string")
2675
+ throw new y('JOSE Header "apv" (Agreement PartyVInfo) invalid');
2676
+ try {
2677
+ o = T(n.apv);
2678
+ } catch {
2679
+ throw new y("Failed to base64url decode the apv");
2680
+ }
2681
+ }
2682
+ const c = await vr(s, e, t === "ECDH-ES" ? n.enc : t, t === "ECDH-ES" ? wt(n.enc) : parseInt(t.slice(-5, -2), 10), i, o);
2683
+ if (t === "ECDH-ES")
2684
+ return c;
2685
+ if (r === void 0)
2686
+ throw new y("JWE Encrypted Key missing");
2687
+ return ut(t.slice(-6), c, r);
2688
+ }
2689
+ case "RSA1_5":
2690
+ case "RSA-OAEP":
2691
+ case "RSA-OAEP-256":
2692
+ case "RSA-OAEP-384":
2693
+ case "RSA-OAEP-512": {
2694
+ if (r === void 0)
2695
+ throw new y("JWE Encrypted Key missing");
2696
+ return $n(t, e, r);
2697
+ }
2698
+ case "PBES2-HS256+A128KW":
2699
+ case "PBES2-HS384+A192KW":
2700
+ case "PBES2-HS512+A256KW": {
2701
+ if (r === void 0)
2702
+ throw new y("JWE Encrypted Key missing");
2703
+ if (typeof n.p2c != "number")
2704
+ throw new y('JOSE Header "p2c" (PBES2 Count) missing or invalid');
2705
+ const s = (a == null ? void 0 : a.maxPBES2Count) || 1e4;
2706
+ if (n.p2c > s)
2707
+ throw new y('JOSE Header "p2c" (PBES2 Count) out is of acceptable bounds');
2708
+ if (typeof n.p2s != "string")
2709
+ throw new y('JOSE Header "p2s" (PBES2 Salt) missing or invalid');
2710
+ let i;
2711
+ try {
2712
+ i = T(n.p2s);
2713
+ } catch {
2714
+ throw new y("Failed to base64url decode the p2s");
2715
+ }
2716
+ return Jn(t, e, r, n.p2c, i);
2717
+ }
2718
+ case "A128KW":
2719
+ case "A192KW":
2720
+ case "A256KW": {
2721
+ if (r === void 0)
2722
+ throw new y("JWE Encrypted Key missing");
2723
+ return ut(t, e, r);
2724
+ }
2725
+ case "A128GCMKW":
2726
+ case "A192GCMKW":
2727
+ case "A256GCMKW": {
2728
+ if (r === void 0)
2729
+ throw new y("JWE Encrypted Key missing");
2730
+ if (typeof n.iv != "string")
2731
+ throw new y('JOSE Header "iv" (Initialization Vector) missing or invalid');
2732
+ if (typeof n.tag != "string")
2733
+ throw new y('JOSE Header "tag" (Authentication Tag) missing or invalid');
2734
+ let s;
2735
+ try {
2736
+ s = T(n.iv);
2737
+ } catch {
2738
+ throw new y("Failed to base64url decode the iv");
2739
+ }
2740
+ let i;
2741
+ try {
2742
+ i = T(n.tag);
2743
+ } catch {
2744
+ throw new y("Failed to base64url decode the tag");
2745
+ }
2746
+ return na(t, e, r, s, i);
2747
+ }
2748
+ default:
2749
+ throw new x('Invalid or unsupported "alg" (JWE Algorithm) header value');
2750
+ }
2751
+ }
2752
+ function ye(t, e, r, n, a) {
2753
+ if (a.crit !== void 0 && n.crit === void 0)
2754
+ throw new t('"crit" (Critical) Header Parameter MUST be integrity protected');
2755
+ if (!n || n.crit === void 0)
2756
+ return /* @__PURE__ */ new Set();
2757
+ if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((i) => typeof i != "string" || i.length === 0))
2758
+ throw new t('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
2759
+ let s;
2760
+ r !== void 0 ? s = new Map([...Object.entries(r), ...e.entries()]) : s = e;
2761
+ for (const i of n.crit) {
2762
+ if (!s.has(i))
2763
+ throw new x(`Extension Header Parameter "${i}" is not recognized`);
2764
+ if (a[i] === void 0)
2765
+ throw new t(`Extension Header Parameter "${i}" is missing`);
2766
+ if (s.get(i) && n[i] === void 0)
2767
+ throw new t(`Extension Header Parameter "${i}" MUST be integrity protected`);
2768
+ }
2769
+ return new Set(n.crit);
2770
+ }
2771
+ const dt = (t, e) => {
2772
+ if (e !== void 0 && (!Array.isArray(e) || e.some((r) => typeof r != "string")))
2773
+ throw new TypeError(`"${t}" option must be an array of strings`);
2774
+ if (e)
2775
+ return new Set(e);
2776
+ };
2777
+ async function St(t, e, r) {
2778
+ var n;
2779
+ if (!I(t))
2780
+ throw new y("Flattened JWE must be an object");
2781
+ if (t.protected === void 0 && t.header === void 0 && t.unprotected === void 0)
2782
+ throw new y("JOSE Header missing");
2783
+ if (typeof t.iv != "string")
2784
+ throw new y("JWE Initialization Vector missing or incorrect type");
2785
+ if (typeof t.ciphertext != "string")
2786
+ throw new y("JWE Ciphertext missing or incorrect type");
2787
+ if (typeof t.tag != "string")
2788
+ throw new y("JWE Authentication Tag missing or incorrect type");
2789
+ if (t.protected !== void 0 && typeof t.protected != "string")
2790
+ throw new y("JWE Protected Header incorrect type");
2791
+ if (t.encrypted_key !== void 0 && typeof t.encrypted_key != "string")
2792
+ throw new y("JWE Encrypted Key incorrect type");
2793
+ if (t.aad !== void 0 && typeof t.aad != "string")
2794
+ throw new y("JWE AAD incorrect type");
2795
+ if (t.header !== void 0 && !I(t.header))
2796
+ throw new y("JWE Shared Unprotected Header incorrect type");
2797
+ if (t.unprotected !== void 0 && !I(t.unprotected))
2798
+ throw new y("JWE Per-Recipient Unprotected Header incorrect type");
2799
+ let a;
2800
+ if (t.protected)
2801
+ try {
2802
+ const m = T(t.protected);
2803
+ a = JSON.parse(X.decode(m));
2804
+ } catch {
2805
+ throw new y("JWE Protected Header is invalid");
2806
+ }
2807
+ if (!me(a, t.header, t.unprotected))
2808
+ throw new y("JWE Protected, JWE Unprotected Header, and JWE Per-Recipient Unprotected Header Parameter names must be disjoint");
2809
+ const s = {
2810
+ ...a,
2811
+ ...t.header,
2812
+ ...t.unprotected
2813
+ };
2814
+ if (ye(y, /* @__PURE__ */ new Map(), r == null ? void 0 : r.crit, a, s), s.zip !== void 0) {
2815
+ if (!a || !a.zip)
2816
+ throw new y('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
2817
+ if (s.zip !== "DEF")
2818
+ throw new x('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value');
2819
+ }
2820
+ const { alg: i, enc: o } = s;
2821
+ if (typeof i != "string" || !i)
2822
+ throw new y("missing JWE Algorithm (alg) in JWE Header");
2823
+ if (typeof o != "string" || !o)
2824
+ throw new y("missing JWE Encryption Algorithm (enc) in JWE Header");
2825
+ const c = r && dt("keyManagementAlgorithms", r.keyManagementAlgorithms), u = r && dt("contentEncryptionAlgorithms", r.contentEncryptionAlgorithms);
2826
+ if (c && !c.has(i))
2827
+ throw new Re('"alg" (Algorithm) Header Parameter not allowed');
2828
+ if (u && !u.has(o))
2829
+ throw new Re('"enc" (Encryption Algorithm) Header Parameter not allowed');
2830
+ let l;
2831
+ if (t.encrypted_key !== void 0)
2832
+ try {
2833
+ l = T(t.encrypted_key);
2834
+ } catch {
2835
+ throw new y("Failed to base64url decode the encrypted_key");
2836
+ }
2837
+ let f = !1;
2838
+ typeof e == "function" && (e = await e(a, t), f = !0);
2839
+ let d;
2840
+ try {
2841
+ d = await aa(i, e, l, s, r);
2842
+ } catch (m) {
2843
+ if (m instanceof TypeError || m instanceof y || m instanceof x)
2844
+ throw m;
2845
+ d = ie(o);
2846
+ }
2847
+ let p, h;
2848
+ try {
2849
+ p = T(t.iv);
2850
+ } catch {
2851
+ throw new y("Failed to base64url decode the iv");
2852
+ }
2853
+ try {
2854
+ h = T(t.tag);
2855
+ } catch {
2856
+ throw new y("Failed to base64url decode the tag");
2857
+ }
2858
+ const g = K.encode((n = t.protected) !== null && n !== void 0 ? n : "");
2859
+ let S;
2860
+ t.aad !== void 0 ? S = Q(g, K.encode("."), K.encode(t.aad)) : S = g;
2861
+ let C;
2862
+ try {
2863
+ C = T(t.ciphertext);
2864
+ } catch {
2865
+ throw new y("Failed to base64url decode the ciphertext");
2866
+ }
2867
+ let v = await wr(o, d, C, p, h, S);
2868
+ s.zip === "DEF" && (v = await ((r == null ? void 0 : r.inflateRaw) || On)(v));
2869
+ const w = { plaintext: v };
2870
+ if (t.protected !== void 0 && (w.protectedHeader = a), t.aad !== void 0)
2871
+ try {
2872
+ w.additionalAuthenticatedData = T(t.aad);
2873
+ } catch {
2874
+ throw new y("Failed to base64url decode the aad");
2875
+ }
2876
+ return t.unprotected !== void 0 && (w.sharedUnprotectedHeader = t.unprotected), t.header !== void 0 && (w.unprotectedHeader = t.header), f ? { ...w, key: e } : w;
2877
+ }
2878
+ async function Kr(t, e, r) {
2879
+ if (t instanceof Uint8Array && (t = X.decode(t)), typeof t != "string")
2880
+ throw new y("Compact JWE must be a string or Uint8Array");
2881
+ const { 0: n, 1: a, 2: s, 3: i, 4: o, length: c } = t.split(".");
2882
+ if (c !== 5)
2883
+ throw new y("Invalid Compact JWE");
2884
+ const u = await St({
2885
+ ciphertext: i,
2886
+ iv: s || void 0,
2887
+ protected: n || void 0,
2888
+ tag: o || void 0,
2889
+ encrypted_key: a || void 0
2890
+ }, e, r), l = { plaintext: u.plaintext, protectedHeader: u.protectedHeader };
2891
+ return typeof e == "function" ? { ...l, key: u.key } : l;
2892
+ }
2893
+ async function sa(t, e, r) {
2894
+ if (!I(t))
2895
+ throw new y("General JWE must be an object");
2896
+ if (!Array.isArray(t.recipients) || !t.recipients.every(I))
2897
+ throw new y("JWE Recipients missing or incorrect type");
2898
+ if (!t.recipients.length)
2899
+ throw new y("JWE Recipients has no members");
2900
+ for (const n of t.recipients)
2901
+ try {
2902
+ return await St({
2903
+ aad: t.aad,
2904
+ ciphertext: t.ciphertext,
2905
+ encrypted_key: n.encrypted_key,
2906
+ header: n.header,
2907
+ iv: t.iv,
2908
+ protected: t.protected,
2909
+ tag: t.tag,
2910
+ unprotected: t.unprotected
2911
+ }, e, r);
2912
+ } catch {
2913
+ }
2914
+ throw new ge();
2915
+ }
2916
+ const ia = async (t) => {
2917
+ if (t instanceof Uint8Array)
2918
+ return {
2919
+ kty: "oct",
2920
+ k: O(t)
2921
+ };
2922
+ if (!G(t))
2923
+ throw new TypeError(M(t, ...H, "Uint8Array"));
2924
+ if (!t.extractable)
2925
+ throw new TypeError("non-extractable CryptoKey cannot be exported as a JWK");
2926
+ const { ext: e, key_ops: r, alg: n, use: a, ...s } = await b.subtle.exportKey("jwk", t);
2927
+ return s;
2928
+ }, oa = ia;
2929
+ async function ca(t) {
2930
+ return Mn(t);
2931
+ }
2932
+ async function ua(t) {
2933
+ return kn(t);
2934
+ }
2935
+ async function Rr(t) {
2936
+ return oa(t);
2937
+ }
2938
+ async function Or(t, e, r, n, a = {}) {
2939
+ let s, i, o;
2940
+ switch (Me(t, r, "encrypt"), t) {
2941
+ case "dir": {
2942
+ o = r;
2943
+ break;
2944
+ }
2945
+ case "ECDH-ES":
2946
+ case "ECDH-ES+A128KW":
2947
+ case "ECDH-ES+A192KW":
2948
+ case "ECDH-ES+A256KW": {
2949
+ if (!Er(r))
2950
+ throw new x("ECDH with the provided key is not allowed or not supported by your javascript runtime");
2951
+ const { apu: c, apv: u } = a;
2952
+ let { epk: l } = a;
2953
+ l || (l = (await Wn(r)).privateKey);
2954
+ const { x: f, y: d, crv: p, kty: h } = await Rr(l), g = await vr(r, l, t === "ECDH-ES" ? e : t, t === "ECDH-ES" ? wt(e) : parseInt(t.slice(-5, -2), 10), c, u);
2955
+ if (i = { epk: { x: f, crv: p, kty: h } }, h === "EC" && (i.epk.y = d), c && (i.apu = O(c)), u && (i.apv = O(u)), t === "ECDH-ES") {
2956
+ o = g;
2957
+ break;
2958
+ }
2959
+ o = n || ie(e);
2960
+ const S = t.slice(-6);
2961
+ s = await ct(S, g, o);
2962
+ break;
2963
+ }
2964
+ case "RSA1_5":
2965
+ case "RSA-OAEP":
2966
+ case "RSA-OAEP-256":
2967
+ case "RSA-OAEP-384":
2968
+ case "RSA-OAEP-512": {
2969
+ o = n || ie(e), s = await Nn(t, r, o);
2970
+ break;
2971
+ }
2972
+ case "PBES2-HS256+A128KW":
2973
+ case "PBES2-HS384+A192KW":
2974
+ case "PBES2-HS512+A256KW": {
2975
+ o = n || ie(e);
2976
+ const { p2c: c, p2s: u } = a;
2977
+ ({ encryptedKey: s, ...i } = await Dn(t, r, o, c, u));
2978
+ break;
2979
+ }
2980
+ case "A128KW":
2981
+ case "A192KW":
2982
+ case "A256KW": {
2983
+ o = n || ie(e), s = await ct(t, r, o);
2984
+ break;
2985
+ }
2986
+ case "A128GCMKW":
2987
+ case "A192GCMKW":
2988
+ case "A256GCMKW": {
2989
+ o = n || ie(e);
2990
+ const { iv: c } = a;
2991
+ ({ encryptedKey: s, ...i } = await ra(t, r, o, c));
2992
+ break;
2993
+ }
2994
+ default:
2995
+ throw new x('Invalid or unsupported "alg" (JWE Algorithm) header value');
2996
+ }
2997
+ return { cek: o, encryptedKey: s, parameters: i };
2998
+ }
2999
+ const Tr = Symbol();
3000
+ class Ie {
3001
+ constructor(e) {
3002
+ if (!(e instanceof Uint8Array))
3003
+ throw new TypeError("plaintext must be an instance of Uint8Array");
3004
+ this._plaintext = e;
3005
+ }
3006
+ setKeyManagementParameters(e) {
3007
+ if (this._keyManagementParameters)
3008
+ throw new TypeError("setKeyManagementParameters can only be called once");
3009
+ return this._keyManagementParameters = e, this;
3010
+ }
3011
+ setProtectedHeader(e) {
3012
+ if (this._protectedHeader)
3013
+ throw new TypeError("setProtectedHeader can only be called once");
3014
+ return this._protectedHeader = e, this;
3015
+ }
3016
+ setSharedUnprotectedHeader(e) {
3017
+ if (this._sharedUnprotectedHeader)
3018
+ throw new TypeError("setSharedUnprotectedHeader can only be called once");
3019
+ return this._sharedUnprotectedHeader = e, this;
3020
+ }
3021
+ setUnprotectedHeader(e) {
3022
+ if (this._unprotectedHeader)
3023
+ throw new TypeError("setUnprotectedHeader can only be called once");
3024
+ return this._unprotectedHeader = e, this;
3025
+ }
3026
+ setAdditionalAuthenticatedData(e) {
3027
+ return this._aad = e, this;
3028
+ }
3029
+ setContentEncryptionKey(e) {
3030
+ if (this._cek)
3031
+ throw new TypeError("setContentEncryptionKey can only be called once");
3032
+ return this._cek = e, this;
3033
+ }
3034
+ setInitializationVector(e) {
3035
+ if (this._iv)
3036
+ throw new TypeError("setInitializationVector can only be called once");
3037
+ return this._iv = e, this;
3038
+ }
3039
+ async encrypt(e, r) {
3040
+ if (!this._protectedHeader && !this._unprotectedHeader && !this._sharedUnprotectedHeader)
3041
+ throw new y("either setProtectedHeader, setUnprotectedHeader, or sharedUnprotectedHeader must be called before #encrypt()");
3042
+ if (!me(this._protectedHeader, this._unprotectedHeader, this._sharedUnprotectedHeader))
3043
+ throw new y("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
3044
+ const n = {
3045
+ ...this._protectedHeader,
3046
+ ...this._unprotectedHeader,
3047
+ ...this._sharedUnprotectedHeader
3048
+ };
3049
+ if (ye(y, /* @__PURE__ */ new Map(), r == null ? void 0 : r.crit, this._protectedHeader, n), n.zip !== void 0) {
3050
+ if (!this._protectedHeader || !this._protectedHeader.zip)
3051
+ throw new y('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
3052
+ if (n.zip !== "DEF")
3053
+ throw new x('Unsupported JWE "zip" (Compression Algorithm) Header Parameter value');
3054
+ }
3055
+ const { alg: a, enc: s } = n;
3056
+ if (typeof a != "string" || !a)
3057
+ throw new y('JWE "alg" (Algorithm) Header Parameter missing or invalid');
3058
+ if (typeof s != "string" || !s)
3059
+ throw new y('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
3060
+ let i;
3061
+ if (a === "dir") {
3062
+ if (this._cek)
3063
+ throw new TypeError("setContentEncryptionKey cannot be called when using Direct Encryption");
3064
+ } else if (a === "ECDH-ES" && this._cek)
3065
+ throw new TypeError("setContentEncryptionKey cannot be called when using Direct Key Agreement");
3066
+ let o;
3067
+ {
3068
+ let h;
3069
+ ({ cek: o, encryptedKey: i, parameters: h } = await Or(a, s, e, this._cek, this._keyManagementParameters)), h && (r && Tr in r ? this._unprotectedHeader ? this._unprotectedHeader = { ...this._unprotectedHeader, ...h } : this.setUnprotectedHeader(h) : this._protectedHeader ? this._protectedHeader = { ...this._protectedHeader, ...h } : this.setProtectedHeader(h));
3070
+ }
3071
+ this._iv || (this._iv = fr(s));
3072
+ let c, u, l;
3073
+ this._protectedHeader ? u = K.encode(O(JSON.stringify(this._protectedHeader))) : u = K.encode(""), this._aad ? (l = O(this._aad), c = Q(u, K.encode("."), K.encode(l))) : c = u;
3074
+ let f, d;
3075
+ if (n.zip === "DEF") {
3076
+ const h = await ((r == null ? void 0 : r.deflateRaw) || Tn)(this._plaintext);
3077
+ ({ ciphertext: f, tag: d } = await lt(s, h, o, this._iv, c));
3078
+ } else
3079
+ ({ ciphertext: f, tag: d } = await lt(s, this._plaintext, o, this._iv, c));
3080
+ const p = {
3081
+ ciphertext: O(f),
3082
+ iv: O(this._iv),
3083
+ tag: O(d)
3084
+ };
3085
+ return i && (p.encrypted_key = O(i)), l && (p.aad = l), this._protectedHeader && (p.protected = X.decode(u)), this._sharedUnprotectedHeader && (p.unprotected = this._sharedUnprotectedHeader), this._unprotectedHeader && (p.header = this._unprotectedHeader), p;
3086
+ }
3087
+ }
3088
+ class la {
3089
+ constructor(e, r, n) {
3090
+ this.parent = e, this.key = r, this.options = n;
3091
+ }
3092
+ setUnprotectedHeader(e) {
3093
+ if (this.unprotectedHeader)
3094
+ throw new TypeError("setUnprotectedHeader can only be called once");
3095
+ return this.unprotectedHeader = e, this;
3096
+ }
3097
+ addRecipient(...e) {
3098
+ return this.parent.addRecipient(...e);
3099
+ }
3100
+ encrypt(...e) {
3101
+ return this.parent.encrypt(...e);
3102
+ }
3103
+ done() {
3104
+ return this.parent;
3105
+ }
3106
+ }
3107
+ class da {
3108
+ constructor(e) {
3109
+ this._recipients = [], this._plaintext = e;
3110
+ }
3111
+ addRecipient(e, r) {
3112
+ const n = new la(this, e, { crit: r == null ? void 0 : r.crit });
3113
+ return this._recipients.push(n), n;
3114
+ }
3115
+ setProtectedHeader(e) {
3116
+ if (this._protectedHeader)
3117
+ throw new TypeError("setProtectedHeader can only be called once");
3118
+ return this._protectedHeader = e, this;
3119
+ }
3120
+ setSharedUnprotectedHeader(e) {
3121
+ if (this._unprotectedHeader)
3122
+ throw new TypeError("setSharedUnprotectedHeader can only be called once");
3123
+ return this._unprotectedHeader = e, this;
3124
+ }
3125
+ setAdditionalAuthenticatedData(e) {
3126
+ return this._aad = e, this;
3127
+ }
3128
+ async encrypt(e) {
3129
+ var r, n, a;
3130
+ if (!this._recipients.length)
3131
+ throw new y("at least one recipient must be added");
3132
+ if (e = { deflateRaw: e == null ? void 0 : e.deflateRaw }, this._recipients.length === 1) {
3133
+ const [c] = this._recipients, u = await new Ie(this._plaintext).setAdditionalAuthenticatedData(this._aad).setProtectedHeader(this._protectedHeader).setSharedUnprotectedHeader(this._unprotectedHeader).setUnprotectedHeader(c.unprotectedHeader).encrypt(c.key, { ...c.options, ...e });
3134
+ let l = {
3135
+ ciphertext: u.ciphertext,
3136
+ iv: u.iv,
3137
+ recipients: [{}],
3138
+ tag: u.tag
3139
+ };
3140
+ return u.aad && (l.aad = u.aad), u.protected && (l.protected = u.protected), u.unprotected && (l.unprotected = u.unprotected), u.encrypted_key && (l.recipients[0].encrypted_key = u.encrypted_key), u.header && (l.recipients[0].header = u.header), l;
3141
+ }
3142
+ let s;
3143
+ for (let c = 0; c < this._recipients.length; c++) {
3144
+ const u = this._recipients[c];
3145
+ if (!me(this._protectedHeader, this._unprotectedHeader, u.unprotectedHeader))
3146
+ throw new y("JWE Protected, JWE Shared Unprotected and JWE Per-Recipient Header Parameter names must be disjoint");
3147
+ const l = {
3148
+ ...this._protectedHeader,
3149
+ ...this._unprotectedHeader,
3150
+ ...u.unprotectedHeader
3151
+ }, { alg: f } = l;
3152
+ if (typeof f != "string" || !f)
3153
+ throw new y('JWE "alg" (Algorithm) Header Parameter missing or invalid');
3154
+ if (f === "dir" || f === "ECDH-ES")
3155
+ throw new y('"dir" and "ECDH-ES" alg may only be used with a single recipient');
3156
+ if (typeof l.enc != "string" || !l.enc)
3157
+ throw new y('JWE "enc" (Encryption Algorithm) Header Parameter missing or invalid');
3158
+ if (!s)
3159
+ s = l.enc;
3160
+ else if (s !== l.enc)
3161
+ throw new y('JWE "enc" (Encryption Algorithm) Header Parameter must be the same for all recipients');
3162
+ if (ye(y, /* @__PURE__ */ new Map(), u.options.crit, this._protectedHeader, l), l.zip !== void 0 && (!this._protectedHeader || !this._protectedHeader.zip))
3163
+ throw new y('JWE "zip" (Compression Algorithm) Header MUST be integrity protected');
3164
+ }
3165
+ const i = ie(s);
3166
+ let o = {
3167
+ ciphertext: "",
3168
+ iv: "",
3169
+ recipients: [],
3170
+ tag: ""
3171
+ };
3172
+ for (let c = 0; c < this._recipients.length; c++) {
3173
+ const u = this._recipients[c], l = {};
3174
+ o.recipients.push(l);
3175
+ const d = {
3176
+ ...this._protectedHeader,
3177
+ ...this._unprotectedHeader,
3178
+ ...u.unprotectedHeader
3179
+ }.alg.startsWith("PBES2") ? 2048 + c : void 0;
3180
+ if (c === 0) {
3181
+ const g = await new Ie(this._plaintext).setAdditionalAuthenticatedData(this._aad).setContentEncryptionKey(i).setProtectedHeader(this._protectedHeader).setSharedUnprotectedHeader(this._unprotectedHeader).setUnprotectedHeader(u.unprotectedHeader).setKeyManagementParameters({ p2c: d }).encrypt(u.key, {
3182
+ ...u.options,
3183
+ ...e,
3184
+ [Tr]: !0
3185
+ });
3186
+ o.ciphertext = g.ciphertext, o.iv = g.iv, o.tag = g.tag, g.aad && (o.aad = g.aad), g.protected && (o.protected = g.protected), g.unprotected && (o.unprotected = g.unprotected), l.encrypted_key = g.encrypted_key, g.header && (l.header = g.header);
3187
+ continue;
3188
+ }
3189
+ const { encryptedKey: p, parameters: h } = await Or(((r = u.unprotectedHeader) === null || r === void 0 ? void 0 : r.alg) || ((n = this._protectedHeader) === null || n === void 0 ? void 0 : n.alg) || ((a = this._unprotectedHeader) === null || a === void 0 ? void 0 : a.alg), s, u.key, i, { p2c: d });
3190
+ l.encrypted_key = O(p), (u.unprotectedHeader || h) && (l.header = { ...u.unprotectedHeader, ...h });
3191
+ }
3192
+ return o;
3193
+ }
3194
+ }
3195
+ function Ir(t, e) {
3196
+ const r = `SHA-${t.slice(-3)}`;
3197
+ switch (t) {
3198
+ case "HS256":
3199
+ case "HS384":
3200
+ case "HS512":
3201
+ return { hash: r, name: "HMAC" };
3202
+ case "PS256":
3203
+ case "PS384":
3204
+ case "PS512":
3205
+ return { hash: r, name: "RSA-PSS", saltLength: t.slice(-3) >> 3 };
3206
+ case "RS256":
3207
+ case "RS384":
3208
+ case "RS512":
3209
+ return { hash: r, name: "RSASSA-PKCS1-v1_5" };
3210
+ case "ES256":
3211
+ case "ES384":
3212
+ case "ES512":
3213
+ return { hash: r, name: "ECDSA", namedCurve: e.namedCurve };
3214
+ case "EdDSA":
3215
+ return { name: e.name };
3216
+ default:
3217
+ throw new x(`alg ${t} is not supported either by JOSE or your javascript runtime`);
3218
+ }
3219
+ }
3220
+ function Wr(t, e, r) {
3221
+ if (G(e))
3222
+ return Hn(e, t, r), e;
3223
+ if (e instanceof Uint8Array) {
3224
+ if (!t.startsWith("HS"))
3225
+ throw new TypeError(M(e, ...H));
3226
+ return b.subtle.importKey("raw", e, { hash: `SHA-${t.slice(-3)}`, name: "HMAC" }, !1, [r]);
3227
+ }
3228
+ throw new TypeError(M(e, ...H, "Uint8Array"));
3229
+ }
3230
+ const fa = async (t, e, r, n) => {
3231
+ const a = await Wr(t, e, "verify");
3232
+ Ne(t, a);
3233
+ const s = Ir(t, a.algorithm);
3234
+ try {
3235
+ return await b.subtle.verify(s, a, r, n);
3236
+ } catch {
3237
+ return !1;
3238
+ }
3239
+ };
3240
+ async function bt(t, e, r) {
3241
+ var n;
3242
+ if (!I(t))
3243
+ throw new P("Flattened JWS must be an object");
3244
+ if (t.protected === void 0 && t.header === void 0)
3245
+ throw new P('Flattened JWS must have either of the "protected" or "header" members');
3246
+ if (t.protected !== void 0 && typeof t.protected != "string")
3247
+ throw new P("JWS Protected Header incorrect type");
3248
+ if (t.payload === void 0)
3249
+ throw new P("JWS Payload missing");
3250
+ if (typeof t.signature != "string")
3251
+ throw new P("JWS Signature missing or incorrect type");
3252
+ if (t.header !== void 0 && !I(t.header))
3253
+ throw new P("JWS Unprotected Header incorrect type");
3254
+ let a = {};
3255
+ if (t.protected)
3256
+ try {
3257
+ const S = T(t.protected);
3258
+ a = JSON.parse(X.decode(S));
3259
+ } catch {
3260
+ throw new P("JWS Protected Header is invalid");
3261
+ }
3262
+ if (!me(a, t.header))
3263
+ throw new P("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
3264
+ const s = {
3265
+ ...a,
3266
+ ...t.header
3267
+ }, i = ye(P, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, a, s);
3268
+ let o = !0;
3269
+ if (i.has("b64") && (o = a.b64, typeof o != "boolean"))
3270
+ throw new P('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
3271
+ const { alg: c } = s;
3272
+ if (typeof c != "string" || !c)
3273
+ throw new P('JWS "alg" (Algorithm) Header Parameter missing or invalid');
3274
+ const u = r && dt("algorithms", r.algorithms);
3275
+ if (u && !u.has(c))
3276
+ throw new Re('"alg" (Algorithm) Header Parameter not allowed');
3277
+ if (o) {
3278
+ if (typeof t.payload != "string")
3279
+ throw new P("JWS Payload must be a string");
3280
+ } else if (typeof t.payload != "string" && !(t.payload instanceof Uint8Array))
3281
+ throw new P("JWS Payload must be a string or an Uint8Array instance");
3282
+ let l = !1;
3283
+ typeof e == "function" && (e = await e(a, t), l = !0), Me(c, e, "verify");
3284
+ const f = Q(K.encode((n = t.protected) !== null && n !== void 0 ? n : ""), K.encode("."), typeof t.payload == "string" ? K.encode(t.payload) : t.payload);
3285
+ let d;
3286
+ try {
3287
+ d = T(t.signature);
3288
+ } catch {
3289
+ throw new P("Failed to base64url decode the signature");
3290
+ }
3291
+ if (!await fa(c, e, d, f))
3292
+ throw new yt();
3293
+ let h;
3294
+ if (o)
3295
+ try {
3296
+ h = T(t.payload);
3297
+ } catch {
3298
+ throw new P("Failed to base64url decode the payload");
3299
+ }
3300
+ else
3301
+ typeof t.payload == "string" ? h = K.encode(t.payload) : h = t.payload;
3302
+ const g = { payload: h };
3303
+ return t.protected !== void 0 && (g.protectedHeader = a), t.header !== void 0 && (g.unprotectedHeader = t.header), l ? { ...g, key: e } : g;
3304
+ }
3305
+ async function Ur(t, e, r) {
3306
+ if (t instanceof Uint8Array && (t = X.decode(t)), typeof t != "string")
3307
+ throw new P("Compact JWS must be a string or Uint8Array");
3308
+ const { 0: n, 1: a, 2: s, length: i } = t.split(".");
3309
+ if (i !== 3)
3310
+ throw new P("Invalid Compact JWS");
3311
+ const o = await bt({ payload: a, protected: n, signature: s }, e, r), c = { payload: o.payload, protectedHeader: o.protectedHeader };
3312
+ return typeof e == "function" ? { ...c, key: o.key } : c;
3313
+ }
3314
+ async function ha(t, e, r) {
3315
+ if (!I(t))
3316
+ throw new P("General JWS must be an object");
3317
+ if (!Array.isArray(t.signatures) || !t.signatures.every(I))
3318
+ throw new P("JWS Signatures missing or incorrect type");
3319
+ for (const n of t.signatures)
3320
+ try {
3321
+ return await bt({
3322
+ header: n.header,
3323
+ payload: t.payload,
3324
+ protected: n.protected,
3325
+ signature: n.signature
3326
+ }, e, r);
3327
+ } catch {
3328
+ }
3329
+ throw new yt();
3330
+ }
3331
+ const Ae = (t) => Math.floor(t.getTime() / 1e3), Lr = 60, Dr = Lr * 60, vt = Dr * 24, pa = vt * 7, ga = vt * 365.25, ma = /^(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)$/i, We = (t) => {
3332
+ const e = ma.exec(t);
3333
+ if (!e)
3334
+ throw new TypeError("Invalid time period format");
3335
+ const r = parseFloat(e[1]);
3336
+ switch (e[2].toLowerCase()) {
3337
+ case "sec":
3338
+ case "secs":
3339
+ case "second":
3340
+ case "seconds":
3341
+ case "s":
3342
+ return Math.round(r);
3343
+ case "minute":
3344
+ case "minutes":
3345
+ case "min":
3346
+ case "mins":
3347
+ case "m":
3348
+ return Math.round(r * Lr);
3349
+ case "hour":
3350
+ case "hours":
3351
+ case "hr":
3352
+ case "hrs":
3353
+ case "h":
3354
+ return Math.round(r * Dr);
3355
+ case "day":
3356
+ case "days":
3357
+ case "d":
3358
+ return Math.round(r * vt);
3359
+ case "week":
3360
+ case "weeks":
3361
+ case "w":
3362
+ return Math.round(r * pa);
3363
+ default:
3364
+ return Math.round(r * ga);
3365
+ }
3366
+ }, kt = (t) => t.toLowerCase().replace(/^application\//, ""), ya = (t, e) => typeof t == "string" ? e.includes(t) : Array.isArray(t) ? e.some(Set.prototype.has.bind(new Set(t))) : !1, Et = (t, e, r = {}) => {
3367
+ const { typ: n } = r;
3368
+ if (n && (typeof t.typ != "string" || kt(t.typ) !== kt(n)))
3369
+ throw new V('unexpected "typ" JWT header value', "typ", "check_failed");
3370
+ let a;
3371
+ try {
3372
+ a = JSON.parse(X.decode(e));
3373
+ } catch {
3374
+ }
3375
+ if (!I(a))
3376
+ throw new B("JWT Claims Set must be a top-level JSON object");
3377
+ const { requiredClaims: s = [], issuer: i, subject: o, audience: c, maxTokenAge: u } = r;
3378
+ u !== void 0 && s.push("iat"), c !== void 0 && s.push("aud"), o !== void 0 && s.push("sub"), i !== void 0 && s.push("iss");
3379
+ for (const p of new Set(s.reverse()))
3380
+ if (!(p in a))
3381
+ throw new V(`missing required "${p}" claim`, p, "missing");
3382
+ if (i && !(Array.isArray(i) ? i : [i]).includes(a.iss))
3383
+ throw new V('unexpected "iss" claim value', "iss", "check_failed");
3384
+ if (o && a.sub !== o)
3385
+ throw new V('unexpected "sub" claim value', "sub", "check_failed");
3386
+ if (c && !ya(a.aud, typeof c == "string" ? [c] : c))
3387
+ throw new V('unexpected "aud" claim value', "aud", "check_failed");
3388
+ let l;
3389
+ switch (typeof r.clockTolerance) {
3390
+ case "string":
3391
+ l = We(r.clockTolerance);
3392
+ break;
3393
+ case "number":
3394
+ l = r.clockTolerance;
3395
+ break;
3396
+ case "undefined":
3397
+ l = 0;
3398
+ break;
3399
+ default:
3400
+ throw new TypeError("Invalid clockTolerance option type");
3401
+ }
3402
+ const { currentDate: f } = r, d = Ae(f || /* @__PURE__ */ new Date());
3403
+ if ((a.iat !== void 0 || u) && typeof a.iat != "number")
3404
+ throw new V('"iat" claim must be a number', "iat", "invalid");
3405
+ if (a.nbf !== void 0) {
3406
+ if (typeof a.nbf != "number")
3407
+ throw new V('"nbf" claim must be a number', "nbf", "invalid");
3408
+ if (a.nbf > d + l)
3409
+ throw new V('"nbf" claim timestamp check failed', "nbf", "check_failed");
3410
+ }
3411
+ if (a.exp !== void 0) {
3412
+ if (typeof a.exp != "number")
3413
+ throw new V('"exp" claim must be a number', "exp", "invalid");
3414
+ if (a.exp <= d - l)
3415
+ throw new ot('"exp" claim timestamp check failed', "exp", "check_failed");
3416
+ }
3417
+ if (u) {
3418
+ const p = d - a.iat, h = typeof u == "number" ? u : We(u);
3419
+ if (p - l > h)
3420
+ throw new ot('"iat" claim timestamp check failed (too far in the past)', "iat", "check_failed");
3421
+ if (p < 0 - l)
3422
+ throw new V('"iat" claim timestamp check failed (it should be in the past)', "iat", "check_failed");
3423
+ }
3424
+ return a;
3425
+ };
3426
+ async function wa(t, e, r) {
3427
+ var n;
3428
+ const a = await Ur(t, e, r);
3429
+ if (!((n = a.protectedHeader.crit) === null || n === void 0) && n.includes("b64") && a.protectedHeader.b64 === !1)
3430
+ throw new B("JWTs MUST NOT use unencoded payload");
3431
+ const i = { payload: Et(a.protectedHeader, a.payload, r), protectedHeader: a.protectedHeader };
3432
+ return typeof e == "function" ? { ...i, key: a.key } : i;
3433
+ }
3434
+ async function Sa(t, e, r) {
3435
+ const n = await Kr(t, e, r), a = Et(n.protectedHeader, n.plaintext, r), { protectedHeader: s } = n;
3436
+ if (s.iss !== void 0 && s.iss !== a.iss)
3437
+ throw new V('replicated "iss" claim header parameter mismatch', "iss", "mismatch");
3438
+ if (s.sub !== void 0 && s.sub !== a.sub)
3439
+ throw new V('replicated "sub" claim header parameter mismatch', "sub", "mismatch");
3440
+ if (s.aud !== void 0 && JSON.stringify(s.aud) !== JSON.stringify(a.aud))
3441
+ throw new V('replicated "aud" claim header parameter mismatch', "aud", "mismatch");
3442
+ const i = { payload: a, protectedHeader: s };
3443
+ return typeof e == "function" ? { ...i, key: n.key } : i;
3444
+ }
3445
+ class Jr {
3446
+ constructor(e) {
3447
+ this._flattened = new Ie(e);
3448
+ }
3449
+ setContentEncryptionKey(e) {
3450
+ return this._flattened.setContentEncryptionKey(e), this;
3451
+ }
3452
+ setInitializationVector(e) {
3453
+ return this._flattened.setInitializationVector(e), this;
3454
+ }
3455
+ setProtectedHeader(e) {
3456
+ return this._flattened.setProtectedHeader(e), this;
3457
+ }
3458
+ setKeyManagementParameters(e) {
3459
+ return this._flattened.setKeyManagementParameters(e), this;
3460
+ }
3461
+ async encrypt(e, r) {
3462
+ const n = await this._flattened.encrypt(e, r);
3463
+ return [n.protected, n.encrypted_key, n.iv, n.ciphertext, n.tag].join(".");
3464
+ }
3465
+ }
3466
+ const ba = async (t, e, r) => {
3467
+ const n = await Wr(t, e, "sign");
3468
+ Ne(t, n);
3469
+ const a = await b.subtle.sign(Ir(t, n.algorithm), n, r);
3470
+ return new Uint8Array(a);
3471
+ };
3472
+ class At {
3473
+ constructor(e) {
3474
+ if (!(e instanceof Uint8Array))
3475
+ throw new TypeError("payload must be an instance of Uint8Array");
3476
+ this._payload = e;
3477
+ }
3478
+ setProtectedHeader(e) {
3479
+ if (this._protectedHeader)
3480
+ throw new TypeError("setProtectedHeader can only be called once");
3481
+ return this._protectedHeader = e, this;
3482
+ }
3483
+ setUnprotectedHeader(e) {
3484
+ if (this._unprotectedHeader)
3485
+ throw new TypeError("setUnprotectedHeader can only be called once");
3486
+ return this._unprotectedHeader = e, this;
3487
+ }
3488
+ async sign(e, r) {
3489
+ if (!this._protectedHeader && !this._unprotectedHeader)
3490
+ throw new P("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
3491
+ if (!me(this._protectedHeader, this._unprotectedHeader))
3492
+ throw new P("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
3493
+ const n = {
3494
+ ...this._protectedHeader,
3495
+ ...this._unprotectedHeader
3496
+ }, a = ye(P, /* @__PURE__ */ new Map([["b64", !0]]), r == null ? void 0 : r.crit, this._protectedHeader, n);
3497
+ let s = !0;
3498
+ if (a.has("b64") && (s = this._protectedHeader.b64, typeof s != "boolean"))
3499
+ throw new P('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
3500
+ const { alg: i } = n;
3501
+ if (typeof i != "string" || !i)
3502
+ throw new P('JWS "alg" (Algorithm) Header Parameter missing or invalid');
3503
+ Me(i, e, "sign");
3504
+ let o = this._payload;
3505
+ s && (o = K.encode(O(o)));
3506
+ let c;
3507
+ this._protectedHeader ? c = K.encode(O(JSON.stringify(this._protectedHeader))) : c = K.encode("");
3508
+ const u = Q(c, K.encode("."), o), l = await ba(i, e, u), f = {
3509
+ signature: O(l),
3510
+ payload: ""
3511
+ };
3512
+ return s && (f.payload = X.decode(o)), this._unprotectedHeader && (f.header = this._unprotectedHeader), this._protectedHeader && (f.protected = X.decode(c)), f;
3513
+ }
3514
+ }
3515
+ class Nr {
3516
+ constructor(e) {
3517
+ this._flattened = new At(e);
3518
+ }
3519
+ setProtectedHeader(e) {
3520
+ return this._flattened.setProtectedHeader(e), this;
3521
+ }
3522
+ async sign(e, r) {
3523
+ const n = await this._flattened.sign(e, r);
3524
+ if (n.payload === void 0)
3525
+ throw new TypeError("use the flattened module for creating JWS with b64: false");
3526
+ return `${n.protected}.${n.payload}.${n.signature}`;
3527
+ }
3528
+ }
3529
+ class va {
3530
+ constructor(e, r, n) {
3531
+ this.parent = e, this.key = r, this.options = n;
3532
+ }
3533
+ setProtectedHeader(e) {
3534
+ if (this.protectedHeader)
3535
+ throw new TypeError("setProtectedHeader can only be called once");
3536
+ return this.protectedHeader = e, this;
3537
+ }
3538
+ setUnprotectedHeader(e) {
3539
+ if (this.unprotectedHeader)
3540
+ throw new TypeError("setUnprotectedHeader can only be called once");
3541
+ return this.unprotectedHeader = e, this;
3542
+ }
3543
+ addSignature(...e) {
3544
+ return this.parent.addSignature(...e);
3545
+ }
3546
+ sign(...e) {
3547
+ return this.parent.sign(...e);
3548
+ }
3549
+ done() {
3550
+ return this.parent;
3551
+ }
3552
+ }
3553
+ class Ea {
3554
+ constructor(e) {
3555
+ this._signatures = [], this._payload = e;
3556
+ }
3557
+ addSignature(e, r) {
3558
+ const n = new va(this, e, r);
3559
+ return this._signatures.push(n), n;
3560
+ }
3561
+ async sign() {
3562
+ if (!this._signatures.length)
3563
+ throw new P("at least one signature must be added");
3564
+ const e = {
3565
+ signatures: [],
3566
+ payload: ""
3567
+ };
3568
+ for (let r = 0; r < this._signatures.length; r++) {
3569
+ const n = this._signatures[r], a = new At(this._payload);
3570
+ a.setProtectedHeader(n.protectedHeader), a.setUnprotectedHeader(n.unprotectedHeader);
3571
+ const { payload: s, ...i } = await a.sign(n.key, n.options);
3572
+ if (r === 0)
3573
+ e.payload = s;
3574
+ else if (e.payload !== s)
3575
+ throw new P("inconsistent use of JWS Unencoded Payload (RFC7797)");
3576
+ e.signatures.push(i);
3577
+ }
3578
+ return e;
3579
+ }
3580
+ }
3581
+ class xt {
3582
+ constructor(e) {
3583
+ if (!I(e))
3584
+ throw new TypeError("JWT Claims Set MUST be an object");
3585
+ this._payload = e;
3586
+ }
3587
+ setIssuer(e) {
3588
+ return this._payload = { ...this._payload, iss: e }, this;
3589
+ }
3590
+ setSubject(e) {
3591
+ return this._payload = { ...this._payload, sub: e }, this;
3592
+ }
3593
+ setAudience(e) {
3594
+ return this._payload = { ...this._payload, aud: e }, this;
3595
+ }
3596
+ setJti(e) {
3597
+ return this._payload = { ...this._payload, jti: e }, this;
3598
+ }
3599
+ setNotBefore(e) {
3600
+ return typeof e == "number" ? this._payload = { ...this._payload, nbf: e } : this._payload = { ...this._payload, nbf: Ae(/* @__PURE__ */ new Date()) + We(e) }, this;
3601
+ }
3602
+ setExpirationTime(e) {
3603
+ return typeof e == "number" ? this._payload = { ...this._payload, exp: e } : this._payload = { ...this._payload, exp: Ae(/* @__PURE__ */ new Date()) + We(e) }, this;
3604
+ }
3605
+ setIssuedAt(e) {
3606
+ return typeof e > "u" ? this._payload = { ...this._payload, iat: Ae(/* @__PURE__ */ new Date()) } : this._payload = { ...this._payload, iat: e }, this;
3607
+ }
3608
+ }
3609
+ class Aa extends xt {
3610
+ setProtectedHeader(e) {
3611
+ return this._protectedHeader = e, this;
3612
+ }
3613
+ async sign(e, r) {
3614
+ var n;
3615
+ const a = new Nr(K.encode(JSON.stringify(this._payload)));
3616
+ if (a.setProtectedHeader(this._protectedHeader), Array.isArray((n = this._protectedHeader) === null || n === void 0 ? void 0 : n.crit) && this._protectedHeader.crit.includes("b64") && this._protectedHeader.b64 === !1)
3617
+ throw new B("JWTs MUST NOT use unencoded payload");
3618
+ return a.sign(e, r);
3619
+ }
3620
+ }
3621
+ class xa extends xt {
3622
+ setProtectedHeader(e) {
3623
+ if (this._protectedHeader)
3624
+ throw new TypeError("setProtectedHeader can only be called once");
3625
+ return this._protectedHeader = e, this;
3626
+ }
3627
+ setKeyManagementParameters(e) {
3628
+ if (this._keyManagementParameters)
3629
+ throw new TypeError("setKeyManagementParameters can only be called once");
3630
+ return this._keyManagementParameters = e, this;
3631
+ }
3632
+ setContentEncryptionKey(e) {
3633
+ if (this._cek)
3634
+ throw new TypeError("setContentEncryptionKey can only be called once");
3635
+ return this._cek = e, this;
3636
+ }
3637
+ setInitializationVector(e) {
3638
+ if (this._iv)
3639
+ throw new TypeError("setInitializationVector can only be called once");
3640
+ return this._iv = e, this;
3641
+ }
3642
+ replicateIssuerAsHeader() {
3643
+ return this._replicateIssuerAsHeader = !0, this;
3644
+ }
3645
+ replicateSubjectAsHeader() {
3646
+ return this._replicateSubjectAsHeader = !0, this;
3647
+ }
3648
+ replicateAudienceAsHeader() {
3649
+ return this._replicateAudienceAsHeader = !0, this;
3650
+ }
3651
+ async encrypt(e, r) {
3652
+ const n = new Jr(K.encode(JSON.stringify(this._payload)));
3653
+ return this._replicateIssuerAsHeader && (this._protectedHeader = { ...this._protectedHeader, iss: this._payload.iss }), this._replicateSubjectAsHeader && (this._protectedHeader = { ...this._protectedHeader, sub: this._payload.sub }), this._replicateAudienceAsHeader && (this._protectedHeader = { ...this._protectedHeader, aud: this._payload.aud }), n.setProtectedHeader(this._protectedHeader), this._iv && n.setInitializationVector(this._iv), this._cek && n.setContentEncryptionKey(this._cek), this._keyManagementParameters && n.setKeyManagementParameters(this._keyManagementParameters), n.encrypt(e, r);
3654
+ }
3655
+ }
3656
+ const ee = (t, e) => {
3657
+ if (typeof t != "string" || !t)
3658
+ throw new cr(`${e} missing or invalid`);
3659
+ };
3660
+ async function $r(t, e) {
3661
+ if (!I(t))
3662
+ throw new TypeError("JWK must be an object");
3663
+ if (e ?? (e = "sha256"), e !== "sha256" && e !== "sha384" && e !== "sha512")
3664
+ throw new TypeError('digestAlgorithm must one of "sha256", "sha384", or "sha512"');
3665
+ let r;
3666
+ switch (t.kty) {
3667
+ case "EC":
3668
+ ee(t.crv, '"crv" (Curve) Parameter'), ee(t.x, '"x" (X Coordinate) Parameter'), ee(t.y, '"y" (Y Coordinate) Parameter'), r = { crv: t.crv, kty: t.kty, x: t.x, y: t.y };
3669
+ break;
3670
+ case "OKP":
3671
+ ee(t.crv, '"crv" (Subtype of Key Pair) Parameter'), ee(t.x, '"x" (Public Key) Parameter'), r = { crv: t.crv, kty: t.kty, x: t.x };
3672
+ break;
3673
+ case "RSA":
3674
+ ee(t.e, '"e" (Exponent) Parameter'), ee(t.n, '"n" (Modulus) Parameter'), r = { e: t.e, kty: t.kty, n: t.n };
3675
+ break;
3676
+ case "oct":
3677
+ ee(t.k, '"k" (Key Value) Parameter'), r = { k: t.k, kty: t.kty };
3678
+ break;
3679
+ default:
3680
+ throw new x('"kty" (Key Type) Parameter missing or unsupported');
3681
+ }
3682
+ const n = K.encode(JSON.stringify(r));
3683
+ return O(await sr(e, n));
3684
+ }
3685
+ async function Ca(t, e) {
3686
+ e ?? (e = "sha256");
3687
+ const r = await $r(t, e);
3688
+ return `urn:ietf:params:oauth:jwk-thumbprint:sha-${e.slice(-3)}:${r}`;
3689
+ }
3690
+ async function _a(t, e) {
3691
+ const r = {
3692
+ ...t,
3693
+ ...e == null ? void 0 : e.header
3694
+ };
3695
+ if (!I(r.jwk))
3696
+ throw new P('"jwk" (JSON Web Key) Header Parameter must be a JSON object');
3697
+ const n = await $e({ ...r.jwk, ext: !0 }, r.alg, !0);
3698
+ if (n instanceof Uint8Array || n.type !== "public")
3699
+ throw new P('"jwk" (JSON Web Key) Header Parameter must be a public key');
3700
+ return n;
3701
+ }
3702
+ function Pa(t) {
3703
+ switch (typeof t == "string" && t.slice(0, 2)) {
3704
+ case "RS":
3705
+ case "PS":
3706
+ return "RSA";
3707
+ case "ES":
3708
+ return "EC";
3709
+ case "Ed":
3710
+ return "OKP";
3711
+ default:
3712
+ throw new x('Unsupported "alg" value for a JSON Web Key Set');
3713
+ }
3714
+ }
3715
+ function Mr(t) {
3716
+ return t && typeof t == "object" && Array.isArray(t.keys) && t.keys.every(Ha);
3717
+ }
3718
+ function Ha(t) {
3719
+ return I(t);
3720
+ }
3721
+ function Ka(t) {
3722
+ return typeof structuredClone == "function" ? structuredClone(t) : JSON.parse(JSON.stringify(t));
3723
+ }
3724
+ class kr {
3725
+ constructor(e) {
3726
+ if (this._cached = /* @__PURE__ */ new WeakMap(), !Mr(e))
3727
+ throw new Le("JSON Web Key Set malformed");
3728
+ this._jwks = Ka(e);
3729
+ }
3730
+ async getKey(e, r) {
3731
+ const { alg: n, kid: a } = { ...e, ...r == null ? void 0 : r.header }, s = Pa(n), i = this._jwks.keys.filter((u) => {
3732
+ let l = s === u.kty;
3733
+ if (l && typeof a == "string" && (l = a === u.kid), l && typeof u.alg == "string" && (l = n === u.alg), l && typeof u.use == "string" && (l = u.use === "sig"), l && Array.isArray(u.key_ops) && (l = u.key_ops.includes("verify")), l && n === "EdDSA" && (l = u.crv === "Ed25519" || u.crv === "Ed448"), l)
3734
+ switch (n) {
3735
+ case "ES256":
3736
+ l = u.crv === "P-256";
3737
+ break;
3738
+ case "ES256K":
3739
+ l = u.crv === "secp256k1";
3740
+ break;
3741
+ case "ES384":
3742
+ l = u.crv === "P-384";
3743
+ break;
3744
+ case "ES512":
3745
+ l = u.crv === "P-521";
3746
+ break;
3747
+ }
3748
+ return l;
3749
+ }), { 0: o, length: c } = i;
3750
+ if (c === 0)
3751
+ throw new mt();
3752
+ if (c !== 1) {
3753
+ const u = new ur(), { _cached: l } = this;
3754
+ throw u[Symbol.asyncIterator] = async function* () {
3755
+ for (const f of i)
3756
+ try {
3757
+ yield await Ft(l, f, n);
3758
+ } catch {
3759
+ continue;
3760
+ }
3761
+ }, u;
3762
+ }
3763
+ return Ft(this._cached, o, n);
3764
+ }
3765
+ }
3766
+ async function Ft(t, e, r) {
3767
+ const n = t.get(e) || t.set(e, {}).get(e);
3768
+ if (n[r] === void 0) {
3769
+ const a = await $e({ ...e, ext: !0 }, r);
3770
+ if (a instanceof Uint8Array || a.type !== "public")
3771
+ throw new Le("JSON Web Key Set members must be public keys");
3772
+ n[r] = a;
3773
+ }
3774
+ return n[r];
3775
+ }
3776
+ function Ra(t) {
3777
+ const e = new kr(t);
3778
+ return async function(r, n) {
3779
+ return e.getKey(r, n);
3780
+ };
3781
+ }
3782
+ const Oa = async (t, e, r) => {
3783
+ let n, a, s = !1;
3784
+ typeof AbortController == "function" && (n = new AbortController(), a = setTimeout(() => {
3785
+ s = !0, n.abort();
3786
+ }, e));
3787
+ const i = await fetch(t.href, {
3788
+ signal: n ? n.signal : void 0,
3789
+ redirect: "manual",
3790
+ headers: r.headers
3791
+ }).catch((o) => {
3792
+ throw s ? new lr() : o;
3793
+ });
3794
+ if (a !== void 0 && clearTimeout(a), i.status !== 200)
3795
+ throw new L("Expected 200 OK from the JSON Web Key Set HTTP response");
3796
+ try {
3797
+ return await i.json();
3798
+ } catch {
3799
+ throw new L("Failed to parse the JSON Web Key Set HTTP response as JSON");
3800
+ }
3801
+ };
3802
+ function Ta() {
3803
+ return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
3804
+ }
3805
+ class Ia extends kr {
3806
+ constructor(e, r) {
3807
+ if (super({ keys: [] }), this._jwks = void 0, !(e instanceof URL))
3808
+ throw new TypeError("url must be an instance of URL");
3809
+ this._url = new URL(e.href), this._options = { agent: r == null ? void 0 : r.agent, headers: r == null ? void 0 : r.headers }, this._timeoutDuration = typeof (r == null ? void 0 : r.timeoutDuration) == "number" ? r == null ? void 0 : r.timeoutDuration : 5e3, this._cooldownDuration = typeof (r == null ? void 0 : r.cooldownDuration) == "number" ? r == null ? void 0 : r.cooldownDuration : 3e4, this._cacheMaxAge = typeof (r == null ? void 0 : r.cacheMaxAge) == "number" ? r == null ? void 0 : r.cacheMaxAge : 6e5;
3810
+ }
3811
+ coolingDown() {
3812
+ return typeof this._jwksTimestamp == "number" ? Date.now() < this._jwksTimestamp + this._cooldownDuration : !1;
3813
+ }
3814
+ fresh() {
3815
+ return typeof this._jwksTimestamp == "number" ? Date.now() < this._jwksTimestamp + this._cacheMaxAge : !1;
3816
+ }
3817
+ async getKey(e, r) {
3818
+ (!this._jwks || !this.fresh()) && await this.reload();
3819
+ try {
3820
+ return await super.getKey(e, r);
3821
+ } catch (n) {
3822
+ if (n instanceof mt && this.coolingDown() === !1)
3823
+ return await this.reload(), super.getKey(e, r);
3824
+ throw n;
3825
+ }
3826
+ }
3827
+ async reload() {
3828
+ this._pendingFetch && Ta() && (this._pendingFetch = void 0), this._pendingFetch || (this._pendingFetch = Oa(this._url, this._timeoutDuration, this._options).then((e) => {
3829
+ if (!Mr(e))
3830
+ throw new Le("JSON Web Key Set malformed");
3831
+ this._jwks = { keys: e.keys }, this._jwksTimestamp = Date.now(), this._pendingFetch = void 0;
3832
+ }).catch((e) => {
3833
+ throw this._pendingFetch = void 0, e;
3834
+ })), await this._pendingFetch;
3835
+ }
3836
+ }
3837
+ function Wa(t, e) {
3838
+ const r = new Ia(t, e);
3839
+ return async function(n, a) {
3840
+ return r.getKey(n, a);
3841
+ };
3842
+ }
3843
+ class Ua extends xt {
3844
+ encode() {
3845
+ const e = O(JSON.stringify({ alg: "none" })), r = O(JSON.stringify(this._payload));
3846
+ return `${e}.${r}.`;
3847
+ }
3848
+ static decode(e, r) {
3849
+ if (typeof e != "string")
3850
+ throw new B("Unsecured JWT must be a string");
3851
+ const { 0: n, 1: a, 2: s, length: i } = e.split(".");
3852
+ if (i !== 3 || s !== "")
3853
+ throw new B("Invalid Unsecured JWT");
3854
+ let o;
3855
+ try {
3856
+ if (o = JSON.parse(X.decode(T(n))), o.alg !== "none")
3857
+ throw new Error();
3858
+ } catch {
3859
+ throw new B("Invalid Unsecured JWT");
3860
+ }
3861
+ return { payload: Et(o, T(a), r), header: o };
3862
+ }
3863
+ }
3864
+ const La = O, Ct = T, Da = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
3865
+ __proto__: null,
3866
+ decode: Ct,
3867
+ encode: La
3868
+ }, Symbol.toStringTag, { value: "Module" }));
3869
+ function Ja(t) {
3870
+ let e;
3871
+ if (typeof t == "string") {
3872
+ const r = t.split(".");
3873
+ (r.length === 3 || r.length === 5) && ([e] = r);
3874
+ } else if (typeof t == "object" && t)
3875
+ if ("protected" in t)
3876
+ e = t.protected;
3877
+ else
3878
+ throw new TypeError("Token does not contain a Protected Header");
3879
+ try {
3880
+ if (typeof e != "string" || !e)
3881
+ throw new Error();
3882
+ const r = JSON.parse(X.decode(Ct(e)));
3883
+ if (!I(r))
3884
+ throw new Error();
3885
+ return r;
3886
+ } catch {
3887
+ throw new TypeError("Invalid Token or Protected Header formatting");
3888
+ }
3889
+ }
3890
+ function Na(t) {
3891
+ if (typeof t != "string")
3892
+ throw new B("JWTs must use Compact JWS serialization, JWT must be a string");
3893
+ const { 1: e, length: r } = t.split(".");
3894
+ if (r === 5)
3895
+ throw new B("Only JWTs using Compact JWS serialization can be decoded");
3896
+ if (r !== 3)
3897
+ throw new B("Invalid JWT");
3898
+ if (!e)
3899
+ throw new B("JWTs must contain a payload");
3900
+ let n;
3901
+ try {
3902
+ n = Ct(e);
3903
+ } catch {
3904
+ throw new B("Failed to base64url decode the payload");
3905
+ }
3906
+ let a;
3907
+ try {
3908
+ a = JSON.parse(X.decode(n));
3909
+ } catch {
3910
+ throw new B("Failed to parse the decoded payload as JSON");
3911
+ }
3912
+ if (!I(a))
3913
+ throw new B("Invalid JWT Claims Set");
3914
+ return a;
3915
+ }
3916
+ async function $a(t, e) {
3917
+ var r;
3918
+ let n, a, s;
3919
+ switch (t) {
3920
+ case "HS256":
3921
+ case "HS384":
3922
+ case "HS512":
3923
+ n = parseInt(t.slice(-3), 10), a = { name: "HMAC", hash: `SHA-${n}`, length: n }, s = ["sign", "verify"];
3924
+ break;
3925
+ case "A128CBC-HS256":
3926
+ case "A192CBC-HS384":
3927
+ case "A256CBC-HS512":
3928
+ return n = parseInt(t.slice(-3), 10), De(new Uint8Array(n >> 3));
3929
+ case "A128KW":
3930
+ case "A192KW":
3931
+ case "A256KW":
3932
+ n = parseInt(t.slice(1, 4), 10), a = { name: "AES-KW", length: n }, s = ["wrapKey", "unwrapKey"];
3933
+ break;
3934
+ case "A128GCMKW":
3935
+ case "A192GCMKW":
3936
+ case "A256GCMKW":
3937
+ case "A128GCM":
3938
+ case "A192GCM":
3939
+ case "A256GCM":
3940
+ n = parseInt(t.slice(1, 4), 10), a = { name: "AES-GCM", length: n }, s = ["encrypt", "decrypt"];
3941
+ break;
3942
+ default:
3943
+ throw new x('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
3944
+ }
3945
+ return b.subtle.generateKey(a, (r = e == null ? void 0 : e.extractable) !== null && r !== void 0 ? r : !1, s);
3946
+ }
3947
+ function qe(t) {
3948
+ var e;
3949
+ const r = (e = t == null ? void 0 : t.modulusLength) !== null && e !== void 0 ? e : 2048;
3950
+ if (typeof r != "number" || r < 2048)
3951
+ throw new x("Invalid or unsupported modulusLength option provided, 2048 bits or larger keys must be used");
3952
+ return r;
3953
+ }
3954
+ async function Ma(t, e) {
3955
+ var r, n, a;
3956
+ let s, i;
3957
+ switch (t) {
3958
+ case "PS256":
3959
+ case "PS384":
3960
+ case "PS512":
3961
+ s = {
3962
+ name: "RSA-PSS",
3963
+ hash: `SHA-${t.slice(-3)}`,
3964
+ publicExponent: new Uint8Array([1, 0, 1]),
3965
+ modulusLength: qe(e)
3966
+ }, i = ["sign", "verify"];
3967
+ break;
3968
+ case "RS256":
3969
+ case "RS384":
3970
+ case "RS512":
3971
+ s = {
3972
+ name: "RSASSA-PKCS1-v1_5",
3973
+ hash: `SHA-${t.slice(-3)}`,
3974
+ publicExponent: new Uint8Array([1, 0, 1]),
3975
+ modulusLength: qe(e)
3976
+ }, i = ["sign", "verify"];
3977
+ break;
3978
+ case "RSA-OAEP":
3979
+ case "RSA-OAEP-256":
3980
+ case "RSA-OAEP-384":
3981
+ case "RSA-OAEP-512":
3982
+ s = {
3983
+ name: "RSA-OAEP",
3984
+ hash: `SHA-${parseInt(t.slice(-3), 10) || 1}`,
3985
+ publicExponent: new Uint8Array([1, 0, 1]),
3986
+ modulusLength: qe(e)
3987
+ }, i = ["decrypt", "unwrapKey", "encrypt", "wrapKey"];
3988
+ break;
3989
+ case "ES256":
3990
+ s = { name: "ECDSA", namedCurve: "P-256" }, i = ["sign", "verify"];
3991
+ break;
3992
+ case "ES384":
3993
+ s = { name: "ECDSA", namedCurve: "P-384" }, i = ["sign", "verify"];
3994
+ break;
3995
+ case "ES512":
3996
+ s = { name: "ECDSA", namedCurve: "P-521" }, i = ["sign", "verify"];
3997
+ break;
3998
+ case "EdDSA":
3999
+ i = ["sign", "verify"];
4000
+ const o = (r = e == null ? void 0 : e.crv) !== null && r !== void 0 ? r : "Ed25519";
4001
+ switch (o) {
4002
+ case "Ed25519":
4003
+ case "Ed448":
4004
+ s = { name: o };
4005
+ break;
4006
+ default:
4007
+ throw new x("Invalid or unsupported crv option provided");
4008
+ }
4009
+ break;
4010
+ case "ECDH-ES":
4011
+ case "ECDH-ES+A128KW":
4012
+ case "ECDH-ES+A192KW":
4013
+ case "ECDH-ES+A256KW": {
4014
+ i = ["deriveKey", "deriveBits"];
4015
+ const c = (n = e == null ? void 0 : e.crv) !== null && n !== void 0 ? n : "P-256";
4016
+ switch (c) {
4017
+ case "P-256":
4018
+ case "P-384":
4019
+ case "P-521": {
4020
+ s = { name: "ECDH", namedCurve: c };
4021
+ break;
4022
+ }
4023
+ case "X25519":
4024
+ case "X448":
4025
+ s = { name: c };
4026
+ break;
4027
+ default:
4028
+ throw new x("Invalid or unsupported crv option provided, supported values are P-256, P-384, P-521, X25519, and X448");
4029
+ }
4030
+ break;
4031
+ }
4032
+ default:
4033
+ throw new x('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
4034
+ }
4035
+ return b.subtle.generateKey(s, (a = e == null ? void 0 : e.extractable) !== null && a !== void 0 ? a : !1, i);
4036
+ }
4037
+ async function ka(t, e) {
4038
+ return Ma(t, e);
4039
+ }
4040
+ async function Fa(t, e) {
4041
+ return $a(t, e);
4042
+ }
4043
+ const Va = "WebCryptoAPI", Ba = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4044
+ __proto__: null,
4045
+ CompactEncrypt: Jr,
4046
+ CompactSign: Nr,
4047
+ EmbeddedJWK: _a,
4048
+ EncryptJWT: xa,
4049
+ FlattenedEncrypt: Ie,
4050
+ FlattenedSign: At,
4051
+ GeneralEncrypt: da,
4052
+ GeneralSign: Ea,
4053
+ SignJWT: Aa,
4054
+ UnsecuredJWT: Ua,
4055
+ base64url: Da,
4056
+ calculateJwkThumbprint: $r,
4057
+ calculateJwkThumbprintUri: Ca,
4058
+ compactDecrypt: Kr,
4059
+ compactVerify: Ur,
4060
+ createLocalJWKSet: Ra,
4061
+ createRemoteJWKSet: Wa,
4062
+ cryptoRuntime: Va,
4063
+ decodeJwt: Na,
4064
+ decodeProtectedHeader: Ja,
4065
+ errors: Cn,
4066
+ exportJWK: Rr,
4067
+ exportPKCS8: ua,
4068
+ exportSPKI: ca,
4069
+ flattenedDecrypt: St,
4070
+ flattenedVerify: bt,
4071
+ generalDecrypt: sa,
4072
+ generalVerify: ha,
4073
+ generateKeyPair: ka,
4074
+ generateSecret: Fa,
4075
+ importJWK: $e,
4076
+ importPKCS8: Zn,
4077
+ importSPKI: Xn,
4078
+ importX509: Yn,
4079
+ jwtDecrypt: Sa,
4080
+ jwtVerify: wa
4081
+ }, Symbol.toStringTag, { value: "Module" })), Ga = /* @__PURE__ */ ft(Ba), za = () => {
4082
+ if (typeof globalThis < "u")
4083
+ return globalThis;
4084
+ if (typeof self < "u")
4085
+ return self;
4086
+ if (typeof window < "u")
4087
+ return window;
4088
+ throw new Error("unable to locate global object");
4089
+ }, qa = async (t, e, r, n, a) => {
4090
+ const { crypto: { subtle: s } } = za();
4091
+ return new Uint8Array(await s.deriveBits({
4092
+ name: "HKDF",
4093
+ hash: `SHA-${t.substr(3)}`,
4094
+ salt: r,
4095
+ info: n
4096
+ }, await s.importKey("raw", e, "HKDF", !1, ["deriveBits"]), a << 3));
4097
+ };
4098
+ function Xa(t) {
4099
+ switch (t) {
4100
+ case "sha256":
4101
+ case "sha384":
4102
+ case "sha512":
4103
+ case "sha1":
4104
+ return t;
4105
+ default:
4106
+ throw new TypeError('unsupported "digest" value');
4107
+ }
4108
+ }
4109
+ function _t(t, e) {
4110
+ if (typeof t == "string")
4111
+ return new TextEncoder().encode(t);
4112
+ if (!(t instanceof Uint8Array))
4113
+ throw new TypeError(`"${e}"" must be an instance of Uint8Array or a string`);
4114
+ return t;
4115
+ }
4116
+ function Ya(t) {
4117
+ const e = _t(t, "ikm");
4118
+ if (!e.byteLength)
4119
+ throw new TypeError('"ikm" must be at least one byte in length');
4120
+ return e;
4121
+ }
4122
+ function Za(t) {
4123
+ const e = _t(t, "info");
4124
+ if (e.byteLength > 1024)
4125
+ throw TypeError('"info" must not contain more than 1024 bytes');
4126
+ return e;
4127
+ }
4128
+ function Qa(t, e) {
4129
+ if (typeof t != "number" || !Number.isInteger(t) || t < 1)
4130
+ throw new TypeError('"keylen" must be a positive integer');
4131
+ const r = parseInt(e.substr(3), 10) >> 3 || 20;
4132
+ if (t > 255 * r)
4133
+ throw new TypeError('"keylen" too large');
4134
+ return t;
4135
+ }
4136
+ async function Vt(t, e, r, n, a) {
4137
+ return qa(Xa(t), Ya(e), _t(r, "salt"), Za(n), Qa(a, t));
4138
+ }
4139
+ const ja = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4140
+ __proto__: null,
4141
+ default: Vt,
4142
+ hkdf: Vt
4143
+ }, Symbol.toStringTag, { value: "Module" })), es = /* @__PURE__ */ ft(ja);
4144
+ var ve, ts = new Uint8Array(16);
4145
+ function Fr() {
4146
+ if (!ve && (ve = typeof crypto < "u" && crypto.getRandomValues && crypto.getRandomValues.bind(crypto) || typeof msCrypto < "u" && typeof msCrypto.getRandomValues == "function" && msCrypto.getRandomValues.bind(msCrypto), !ve))
4147
+ throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
4148
+ return ve(ts);
4149
+ }
4150
+ const rs = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
4151
+ function ke(t) {
4152
+ return typeof t == "string" && rs.test(t);
4153
+ }
4154
+ var W = [];
4155
+ for (var Xe = 0; Xe < 256; ++Xe)
4156
+ W.push((Xe + 256).toString(16).substr(1));
4157
+ function Fe(t) {
4158
+ var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : 0, r = (W[t[e + 0]] + W[t[e + 1]] + W[t[e + 2]] + W[t[e + 3]] + "-" + W[t[e + 4]] + W[t[e + 5]] + "-" + W[t[e + 6]] + W[t[e + 7]] + "-" + W[t[e + 8]] + W[t[e + 9]] + "-" + W[t[e + 10]] + W[t[e + 11]] + W[t[e + 12]] + W[t[e + 13]] + W[t[e + 14]] + W[t[e + 15]]).toLowerCase();
4159
+ if (!ke(r))
4160
+ throw TypeError("Stringified UUID is invalid");
4161
+ return r;
4162
+ }
4163
+ var Bt, Ye, Ze = 0, Qe = 0;
4164
+ function ns(t, e, r) {
4165
+ var n = e && r || 0, a = e || new Array(16);
4166
+ t = t || {};
4167
+ var s = t.node || Bt, i = t.clockseq !== void 0 ? t.clockseq : Ye;
4168
+ if (s == null || i == null) {
4169
+ var o = t.random || (t.rng || Fr)();
4170
+ s == null && (s = Bt = [o[0] | 1, o[1], o[2], o[3], o[4], o[5]]), i == null && (i = Ye = (o[6] << 8 | o[7]) & 16383);
4171
+ }
4172
+ var c = t.msecs !== void 0 ? t.msecs : Date.now(), u = t.nsecs !== void 0 ? t.nsecs : Qe + 1, l = c - Ze + (u - Qe) / 1e4;
4173
+ if (l < 0 && t.clockseq === void 0 && (i = i + 1 & 16383), (l < 0 || c > Ze) && t.nsecs === void 0 && (u = 0), u >= 1e4)
4174
+ throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");
4175
+ Ze = c, Qe = u, Ye = i, c += 122192928e5;
4176
+ var f = ((c & 268435455) * 1e4 + u) % 4294967296;
4177
+ a[n++] = f >>> 24 & 255, a[n++] = f >>> 16 & 255, a[n++] = f >>> 8 & 255, a[n++] = f & 255;
4178
+ var d = c / 4294967296 * 1e4 & 268435455;
4179
+ a[n++] = d >>> 8 & 255, a[n++] = d & 255, a[n++] = d >>> 24 & 15 | 16, a[n++] = d >>> 16 & 255, a[n++] = i >>> 8 | 128, a[n++] = i & 255;
4180
+ for (var p = 0; p < 6; ++p)
4181
+ a[n + p] = s[p];
4182
+ return e || Fe(a);
4183
+ }
4184
+ function Vr(t) {
4185
+ if (!ke(t))
4186
+ throw TypeError("Invalid UUID");
4187
+ var e, r = new Uint8Array(16);
4188
+ return r[0] = (e = parseInt(t.slice(0, 8), 16)) >>> 24, r[1] = e >>> 16 & 255, r[2] = e >>> 8 & 255, r[3] = e & 255, r[4] = (e = parseInt(t.slice(9, 13), 16)) >>> 8, r[5] = e & 255, r[6] = (e = parseInt(t.slice(14, 18), 16)) >>> 8, r[7] = e & 255, r[8] = (e = parseInt(t.slice(19, 23), 16)) >>> 8, r[9] = e & 255, r[10] = (e = parseInt(t.slice(24, 36), 16)) / 1099511627776 & 255, r[11] = e / 4294967296 & 255, r[12] = e >>> 24 & 255, r[13] = e >>> 16 & 255, r[14] = e >>> 8 & 255, r[15] = e & 255, r;
4189
+ }
4190
+ function as(t) {
4191
+ t = unescape(encodeURIComponent(t));
4192
+ for (var e = [], r = 0; r < t.length; ++r)
4193
+ e.push(t.charCodeAt(r));
4194
+ return e;
4195
+ }
4196
+ var ss = "6ba7b810-9dad-11d1-80b4-00c04fd430c8", is = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
4197
+ function Br(t, e, r) {
4198
+ function n(a, s, i, o) {
4199
+ if (typeof a == "string" && (a = as(a)), typeof s == "string" && (s = Vr(s)), s.length !== 16)
4200
+ throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
4201
+ var c = new Uint8Array(16 + a.length);
4202
+ if (c.set(s), c.set(a, s.length), c = r(c), c[6] = c[6] & 15 | e, c[8] = c[8] & 63 | 128, i) {
4203
+ o = o || 0;
4204
+ for (var u = 0; u < 16; ++u)
4205
+ i[o + u] = c[u];
4206
+ return i;
4207
+ }
4208
+ return Fe(c);
4209
+ }
4210
+ try {
4211
+ n.name = t;
4212
+ } catch {
4213
+ }
4214
+ return n.DNS = ss, n.URL = is, n;
4215
+ }
4216
+ function os(t) {
4217
+ if (typeof t == "string") {
4218
+ var e = unescape(encodeURIComponent(t));
4219
+ t = new Uint8Array(e.length);
4220
+ for (var r = 0; r < e.length; ++r)
4221
+ t[r] = e.charCodeAt(r);
4222
+ }
4223
+ return cs(us(ls(t), t.length * 8));
4224
+ }
4225
+ function cs(t) {
4226
+ for (var e = [], r = t.length * 32, n = "0123456789abcdef", a = 0; a < r; a += 8) {
4227
+ var s = t[a >> 5] >>> a % 32 & 255, i = parseInt(n.charAt(s >>> 4 & 15) + n.charAt(s & 15), 16);
4228
+ e.push(i);
4229
+ }
4230
+ return e;
4231
+ }
4232
+ function Gr(t) {
4233
+ return (t + 64 >>> 9 << 4) + 14 + 1;
4234
+ }
4235
+ function us(t, e) {
4236
+ t[e >> 5] |= 128 << e % 32, t[Gr(e) - 1] = e;
4237
+ for (var r = 1732584193, n = -271733879, a = -1732584194, s = 271733878, i = 0; i < t.length; i += 16) {
4238
+ var o = r, c = n, u = a, l = s;
4239
+ r = D(r, n, a, s, t[i], 7, -680876936), s = D(s, r, n, a, t[i + 1], 12, -389564586), a = D(a, s, r, n, t[i + 2], 17, 606105819), n = D(n, a, s, r, t[i + 3], 22, -1044525330), r = D(r, n, a, s, t[i + 4], 7, -176418897), s = D(s, r, n, a, t[i + 5], 12, 1200080426), a = D(a, s, r, n, t[i + 6], 17, -1473231341), n = D(n, a, s, r, t[i + 7], 22, -45705983), r = D(r, n, a, s, t[i + 8], 7, 1770035416), s = D(s, r, n, a, t[i + 9], 12, -1958414417), a = D(a, s, r, n, t[i + 10], 17, -42063), n = D(n, a, s, r, t[i + 11], 22, -1990404162), r = D(r, n, a, s, t[i + 12], 7, 1804603682), s = D(s, r, n, a, t[i + 13], 12, -40341101), a = D(a, s, r, n, t[i + 14], 17, -1502002290), n = D(n, a, s, r, t[i + 15], 22, 1236535329), r = J(r, n, a, s, t[i + 1], 5, -165796510), s = J(s, r, n, a, t[i + 6], 9, -1069501632), a = J(a, s, r, n, t[i + 11], 14, 643717713), n = J(n, a, s, r, t[i], 20, -373897302), r = J(r, n, a, s, t[i + 5], 5, -701558691), s = J(s, r, n, a, t[i + 10], 9, 38016083), a = J(a, s, r, n, t[i + 15], 14, -660478335), n = J(n, a, s, r, t[i + 4], 20, -405537848), r = J(r, n, a, s, t[i + 9], 5, 568446438), s = J(s, r, n, a, t[i + 14], 9, -1019803690), a = J(a, s, r, n, t[i + 3], 14, -187363961), n = J(n, a, s, r, t[i + 8], 20, 1163531501), r = J(r, n, a, s, t[i + 13], 5, -1444681467), s = J(s, r, n, a, t[i + 2], 9, -51403784), a = J(a, s, r, n, t[i + 7], 14, 1735328473), n = J(n, a, s, r, t[i + 12], 20, -1926607734), r = N(r, n, a, s, t[i + 5], 4, -378558), s = N(s, r, n, a, t[i + 8], 11, -2022574463), a = N(a, s, r, n, t[i + 11], 16, 1839030562), n = N(n, a, s, r, t[i + 14], 23, -35309556), r = N(r, n, a, s, t[i + 1], 4, -1530992060), s = N(s, r, n, a, t[i + 4], 11, 1272893353), a = N(a, s, r, n, t[i + 7], 16, -155497632), n = N(n, a, s, r, t[i + 10], 23, -1094730640), r = N(r, n, a, s, t[i + 13], 4, 681279174), s = N(s, r, n, a, t[i], 11, -358537222), a = N(a, s, r, n, t[i + 3], 16, -722521979), n = N(n, a, s, r, t[i + 6], 23, 76029189), r = N(r, n, a, s, t[i + 9], 4, -640364487), s = N(s, r, n, a, t[i + 12], 11, -421815835), a = N(a, s, r, n, t[i + 15], 16, 530742520), n = N(n, a, s, r, t[i + 2], 23, -995338651), r = $(r, n, a, s, t[i], 6, -198630844), s = $(s, r, n, a, t[i + 7], 10, 1126891415), a = $(a, s, r, n, t[i + 14], 15, -1416354905), n = $(n, a, s, r, t[i + 5], 21, -57434055), r = $(r, n, a, s, t[i + 12], 6, 1700485571), s = $(s, r, n, a, t[i + 3], 10, -1894986606), a = $(a, s, r, n, t[i + 10], 15, -1051523), n = $(n, a, s, r, t[i + 1], 21, -2054922799), r = $(r, n, a, s, t[i + 8], 6, 1873313359), s = $(s, r, n, a, t[i + 15], 10, -30611744), a = $(a, s, r, n, t[i + 6], 15, -1560198380), n = $(n, a, s, r, t[i + 13], 21, 1309151649), r = $(r, n, a, s, t[i + 4], 6, -145523070), s = $(s, r, n, a, t[i + 11], 10, -1120210379), a = $(a, s, r, n, t[i + 2], 15, 718787259), n = $(n, a, s, r, t[i + 9], 21, -343485551), r = ne(r, o), n = ne(n, c), a = ne(a, u), s = ne(s, l);
4240
+ }
4241
+ return [r, n, a, s];
4242
+ }
4243
+ function ls(t) {
4244
+ if (t.length === 0)
4245
+ return [];
4246
+ for (var e = t.length * 8, r = new Uint32Array(Gr(e)), n = 0; n < e; n += 8)
4247
+ r[n >> 5] |= (t[n / 8] & 255) << n % 32;
4248
+ return r;
4249
+ }
4250
+ function ne(t, e) {
4251
+ var r = (t & 65535) + (e & 65535), n = (t >> 16) + (e >> 16) + (r >> 16);
4252
+ return n << 16 | r & 65535;
4253
+ }
4254
+ function ds(t, e) {
4255
+ return t << e | t >>> 32 - e;
4256
+ }
4257
+ function Ve(t, e, r, n, a, s) {
4258
+ return ne(ds(ne(ne(e, t), ne(n, s)), a), r);
4259
+ }
4260
+ function D(t, e, r, n, a, s, i) {
4261
+ return Ve(e & r | ~e & n, t, e, a, s, i);
4262
+ }
4263
+ function J(t, e, r, n, a, s, i) {
4264
+ return Ve(e & n | r & ~n, t, e, a, s, i);
4265
+ }
4266
+ function N(t, e, r, n, a, s, i) {
4267
+ return Ve(e ^ r ^ n, t, e, a, s, i);
4268
+ }
4269
+ function $(t, e, r, n, a, s, i) {
4270
+ return Ve(r ^ (e | ~n), t, e, a, s, i);
4271
+ }
4272
+ var fs = Br("v3", 48, os);
4273
+ const hs = fs;
4274
+ function ps(t, e, r) {
4275
+ t = t || {};
4276
+ var n = t.random || (t.rng || Fr)();
4277
+ if (n[6] = n[6] & 15 | 64, n[8] = n[8] & 63 | 128, e) {
4278
+ r = r || 0;
4279
+ for (var a = 0; a < 16; ++a)
4280
+ e[r + a] = n[a];
4281
+ return e;
4282
+ }
4283
+ return Fe(n);
4284
+ }
4285
+ function gs(t, e, r, n) {
4286
+ switch (t) {
4287
+ case 0:
4288
+ return e & r ^ ~e & n;
4289
+ case 1:
4290
+ return e ^ r ^ n;
4291
+ case 2:
4292
+ return e & r ^ e & n ^ r & n;
4293
+ case 3:
4294
+ return e ^ r ^ n;
4295
+ }
4296
+ }
4297
+ function je(t, e) {
4298
+ return t << e | t >>> 32 - e;
4299
+ }
4300
+ function ms(t) {
4301
+ var e = [1518500249, 1859775393, 2400959708, 3395469782], r = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
4302
+ if (typeof t == "string") {
4303
+ var n = unescape(encodeURIComponent(t));
4304
+ t = [];
4305
+ for (var a = 0; a < n.length; ++a)
4306
+ t.push(n.charCodeAt(a));
4307
+ } else
4308
+ Array.isArray(t) || (t = Array.prototype.slice.call(t));
4309
+ t.push(128);
4310
+ for (var s = t.length / 4 + 2, i = Math.ceil(s / 16), o = new Array(i), c = 0; c < i; ++c) {
4311
+ for (var u = new Uint32Array(16), l = 0; l < 16; ++l)
4312
+ u[l] = t[c * 64 + l * 4] << 24 | t[c * 64 + l * 4 + 1] << 16 | t[c * 64 + l * 4 + 2] << 8 | t[c * 64 + l * 4 + 3];
4313
+ o[c] = u;
4314
+ }
4315
+ o[i - 1][14] = (t.length - 1) * 8 / Math.pow(2, 32), o[i - 1][14] = Math.floor(o[i - 1][14]), o[i - 1][15] = (t.length - 1) * 8 & 4294967295;
4316
+ for (var f = 0; f < i; ++f) {
4317
+ for (var d = new Uint32Array(80), p = 0; p < 16; ++p)
4318
+ d[p] = o[f][p];
4319
+ for (var h = 16; h < 80; ++h)
4320
+ d[h] = je(d[h - 3] ^ d[h - 8] ^ d[h - 14] ^ d[h - 16], 1);
4321
+ for (var g = r[0], S = r[1], C = r[2], v = r[3], w = r[4], m = 0; m < 80; ++m) {
4322
+ var E = Math.floor(m / 20), _ = je(g, 5) + gs(E, S, C, v) + w + e[E] + d[m] >>> 0;
4323
+ w = v, v = C, C = je(S, 30) >>> 0, S = g, g = _;
4324
+ }
4325
+ r[0] = r[0] + g >>> 0, r[1] = r[1] + S >>> 0, r[2] = r[2] + C >>> 0, r[3] = r[3] + v >>> 0, r[4] = r[4] + w >>> 0;
4326
+ }
4327
+ return [r[0] >> 24 & 255, r[0] >> 16 & 255, r[0] >> 8 & 255, r[0] & 255, r[1] >> 24 & 255, r[1] >> 16 & 255, r[1] >> 8 & 255, r[1] & 255, r[2] >> 24 & 255, r[2] >> 16 & 255, r[2] >> 8 & 255, r[2] & 255, r[3] >> 24 & 255, r[3] >> 16 & 255, r[3] >> 8 & 255, r[3] & 255, r[4] >> 24 & 255, r[4] >> 16 & 255, r[4] >> 8 & 255, r[4] & 255];
4328
+ }
4329
+ var ys = Br("v5", 80, ms);
4330
+ const ws = ys, Ss = "00000000-0000-0000-0000-000000000000";
4331
+ function bs(t) {
4332
+ if (!ke(t))
4333
+ throw TypeError("Invalid UUID");
4334
+ return parseInt(t.substr(14, 1), 16);
4335
+ }
4336
+ const vs = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4337
+ __proto__: null,
4338
+ NIL: Ss,
4339
+ parse: Vr,
4340
+ stringify: Fe,
4341
+ v1: ns,
4342
+ v3: hs,
4343
+ v4: ps,
4344
+ v5: ws,
4345
+ validate: ke,
4346
+ version: bs
4347
+ }, Symbol.toStringTag, { value: "Module" })), Es = /* @__PURE__ */ ft(vs);
4348
+ var ue = {}, et = { exports: {} }, tt = { exports: {} }, Gt;
4349
+ function As() {
4350
+ return Gt || (Gt = 1, function(t) {
4351
+ function e(r, n) {
4352
+ return n.get ? n.get.call(r) : n.value;
4353
+ }
4354
+ t.exports = e, t.exports.__esModule = !0, t.exports.default = t.exports;
4355
+ }(tt)), tt.exports;
4356
+ }
4357
+ var rt = { exports: {} }, zt;
4358
+ function zr() {
4359
+ return zt || (zt = 1, function(t) {
4360
+ function e(r, n, a) {
4361
+ if (!n.has(r))
4362
+ throw new TypeError("attempted to " + a + " private field on non-instance");
4363
+ return n.get(r);
4364
+ }
4365
+ t.exports = e, t.exports.__esModule = !0, t.exports.default = t.exports;
4366
+ }(rt)), rt.exports;
4367
+ }
4368
+ var qt;
4369
+ function xs() {
4370
+ return qt || (qt = 1, function(t) {
4371
+ var e = As(), r = zr();
4372
+ function n(a, s) {
4373
+ var i = r(a, s, "get");
4374
+ return e(a, i);
4375
+ }
4376
+ t.exports = n, t.exports.__esModule = !0, t.exports.default = t.exports;
4377
+ }(et)), et.exports;
4378
+ }
4379
+ var nt = { exports: {} }, at = { exports: {} }, Xt;
4380
+ function Cs() {
4381
+ return Xt || (Xt = 1, function(t) {
4382
+ function e(r, n, a) {
4383
+ if (n.set)
4384
+ n.set.call(r, a);
4385
+ else {
4386
+ if (!n.writable)
4387
+ throw new TypeError("attempted to set read only private field");
4388
+ n.value = a;
4389
+ }
4390
+ }
4391
+ t.exports = e, t.exports.__esModule = !0, t.exports.default = t.exports;
4392
+ }(at)), at.exports;
4393
+ }
4394
+ var Yt;
4395
+ function _s() {
4396
+ return Yt || (Yt = 1, function(t) {
4397
+ var e = Cs(), r = zr();
4398
+ function n(a, s, i) {
4399
+ var o = r(a, s, "set");
4400
+ return e(a, o, i), i;
4401
+ }
4402
+ t.exports = n, t.exports.__esModule = !0, t.exports.default = t.exports;
4403
+ }(nt)), nt.exports;
4404
+ }
4405
+ var Zt;
4406
+ function Ps() {
4407
+ if (Zt)
4408
+ return ue;
4409
+ Zt = 1;
4410
+ var t = ar;
4411
+ Object.defineProperty(ue, "__esModule", {
4412
+ value: !0
4413
+ }), ue.SessionStore = void 0, ue.defaultCookies = l;
4414
+ var e = t(xs()), r = t(_s());
4415
+ function n(w, m) {
4416
+ s(w, m), m.add(w);
4417
+ }
4418
+ function a(w, m, E) {
4419
+ s(w, m), m.set(w, E);
4420
+ }
4421
+ function s(w, m) {
4422
+ if (m.has(w))
4423
+ throw new TypeError("Cannot initialize the same private elements twice on an object");
4424
+ }
4425
+ function i(w, m, E) {
4426
+ if (!m.has(w))
4427
+ throw new TypeError("attempted to get private field on non-instance");
4428
+ return E;
4429
+ }
4430
+ const o = 4096, c = 163, u = o - c;
4431
+ function l(w) {
4432
+ const m = w ? "__Secure-" : "";
4433
+ return {
4434
+ sessionToken: {
4435
+ name: `${m}next-auth.session-token`,
4436
+ options: {
4437
+ httpOnly: !0,
4438
+ sameSite: "lax",
4439
+ path: "/",
4440
+ secure: w
4441
+ }
4442
+ },
4443
+ callbackUrl: {
4444
+ name: `${m}next-auth.callback-url`,
4445
+ options: {
4446
+ httpOnly: !0,
4447
+ sameSite: "lax",
4448
+ path: "/",
4449
+ secure: w
4450
+ }
4451
+ },
4452
+ csrfToken: {
4453
+ name: `${w ? "__Host-" : ""}next-auth.csrf-token`,
4454
+ options: {
4455
+ httpOnly: !0,
4456
+ sameSite: "lax",
4457
+ path: "/",
4458
+ secure: w
4459
+ }
4460
+ },
4461
+ pkceCodeVerifier: {
4462
+ name: `${m}next-auth.pkce.code_verifier`,
4463
+ options: {
4464
+ httpOnly: !0,
4465
+ sameSite: "lax",
4466
+ path: "/",
4467
+ secure: w,
4468
+ maxAge: 60 * 15
4469
+ }
4470
+ },
4471
+ state: {
4472
+ name: `${m}next-auth.state`,
4473
+ options: {
4474
+ httpOnly: !0,
4475
+ sameSite: "lax",
4476
+ path: "/",
4477
+ secure: w,
4478
+ maxAge: 60 * 15
4479
+ }
4480
+ },
4481
+ nonce: {
4482
+ name: `${m}next-auth.nonce`,
4483
+ options: {
4484
+ httpOnly: !0,
4485
+ sameSite: "lax",
4486
+ path: "/",
4487
+ secure: w
4488
+ }
4489
+ }
4490
+ };
4491
+ }
4492
+ var f = /* @__PURE__ */ new WeakMap(), d = /* @__PURE__ */ new WeakMap(), p = /* @__PURE__ */ new WeakMap(), h = /* @__PURE__ */ new WeakSet(), g = /* @__PURE__ */ new WeakSet();
4493
+ class S {
4494
+ constructor(m, E, _) {
4495
+ n(this, g), n(this, h), a(this, f, {
4496
+ writable: !0,
4497
+ value: {}
4498
+ }), a(this, d, {
4499
+ writable: !0,
4500
+ value: void 0
4501
+ }), a(this, p, {
4502
+ writable: !0,
4503
+ value: void 0
4504
+ }), (0, r.default)(this, p, _), (0, r.default)(this, d, m);
4505
+ const {
4506
+ cookies: A
4507
+ } = E, {
4508
+ name: R
4509
+ } = m;
4510
+ if (typeof (A == null ? void 0 : A.getAll) == "function")
4511
+ for (const {
4512
+ name: F,
4513
+ value: q
4514
+ } of A.getAll())
4515
+ F.startsWith(R) && ((0, e.default)(this, f)[F] = q);
4516
+ else if (A instanceof Map)
4517
+ for (const F of A.keys())
4518
+ F.startsWith(R) && ((0, e.default)(this, f)[F] = A.get(F));
4519
+ else
4520
+ for (const F in A)
4521
+ F.startsWith(R) && ((0, e.default)(this, f)[F] = A[F]);
4522
+ }
4523
+ get value() {
4524
+ return Object.keys((0, e.default)(this, f)).sort((E, _) => {
4525
+ var A, R;
4526
+ const F = parseInt((A = E.split(".").pop()) !== null && A !== void 0 ? A : "0"), q = parseInt((R = _.split(".").pop()) !== null && R !== void 0 ? R : "0");
4527
+ return F - q;
4528
+ }).map((E) => (0, e.default)(this, f)[E]).join("");
4529
+ }
4530
+ chunk(m, E) {
4531
+ const _ = i(this, g, v).call(this), A = i(this, h, C).call(this, {
4532
+ name: (0, e.default)(this, d).name,
4533
+ value: m,
4534
+ options: {
4535
+ ...(0, e.default)(this, d).options,
4536
+ ...E
4537
+ }
4538
+ });
4539
+ for (const R of A)
4540
+ _[R.name] = R;
4541
+ return Object.values(_);
4542
+ }
4543
+ clean() {
4544
+ return Object.values(i(this, g, v).call(this));
4545
+ }
4546
+ }
4547
+ ue.SessionStore = S;
4548
+ function C(w) {
4549
+ const m = Math.ceil(w.value.length / u);
4550
+ if (m === 1)
4551
+ return (0, e.default)(this, f)[w.name] = w.value, [w];
4552
+ const E = [];
4553
+ for (let _ = 0; _ < m; _++) {
4554
+ const A = `${w.name}.${_}`, R = w.value.substr(_ * u, u);
4555
+ E.push({
4556
+ ...w,
4557
+ name: A,
4558
+ value: R
4559
+ }), (0, e.default)(this, f)[A] = R;
4560
+ }
4561
+ return (0, e.default)(this, p).debug("CHUNKING_SESSION_COOKIE", {
4562
+ message: `Session cookie exceeds allowed ${o} bytes.`,
4563
+ emptyCookieSize: c,
4564
+ valueSize: w.value.length,
4565
+ chunks: E.map((_) => _.value.length + c)
4566
+ }), E;
4567
+ }
4568
+ function v() {
4569
+ const w = {};
4570
+ for (const E in (0, e.default)(this, f)) {
4571
+ var m;
4572
+ (m = (0, e.default)(this, f)) === null || m === void 0 || delete m[E], w[E] = {
4573
+ name: E,
4574
+ value: "",
4575
+ options: {
4576
+ ...(0, e.default)(this, d).options,
4577
+ maxAge: 0
4578
+ }
4579
+ };
4580
+ }
4581
+ return w;
4582
+ }
4583
+ return ue;
4584
+ }
4585
+ var st = {}, Qt;
4586
+ function Hs() {
4587
+ return Qt || (Qt = 1, Object.defineProperty(st, "__esModule", {
4588
+ value: !0
4589
+ })), st;
4590
+ }
4591
+ (function(t) {
4592
+ var e = ar;
4593
+ Object.defineProperty(t, "__esModule", {
4594
+ value: !0
4595
+ });
4596
+ var r = {
4597
+ encode: !0,
4598
+ decode: !0,
4599
+ getToken: !0
4600
+ };
4601
+ t.decode = f, t.encode = l, t.getToken = d;
4602
+ var n = Ga, a = e(es), s = Es, i = Ps(), o = Hs();
4603
+ Object.keys(o).forEach(function(h) {
4604
+ h === "default" || h === "__esModule" || Object.prototype.hasOwnProperty.call(r, h) || h in t && t[h] === o[h] || Object.defineProperty(t, h, {
4605
+ enumerable: !0,
4606
+ get: function() {
4607
+ return o[h];
4608
+ }
4609
+ });
4610
+ });
4611
+ const c = 30 * 24 * 60 * 60, u = () => Date.now() / 1e3 | 0;
4612
+ async function l(h) {
4613
+ const {
4614
+ token: g = {},
4615
+ secret: S,
4616
+ maxAge: C = c,
4617
+ salt: v = ""
4618
+ } = h, w = await p(S, v);
4619
+ return await new n.EncryptJWT(g).setProtectedHeader({
4620
+ alg: "dir",
4621
+ enc: "A256GCM"
4622
+ }).setIssuedAt().setExpirationTime(u() + C).setJti((0, s.v4)()).encrypt(w);
4623
+ }
4624
+ async function f(h) {
4625
+ const {
4626
+ token: g,
4627
+ secret: S,
4628
+ salt: C = ""
4629
+ } = h;
4630
+ if (!g)
4631
+ return null;
4632
+ const v = await p(S, C), {
4633
+ payload: w
4634
+ } = await (0, n.jwtDecrypt)(g, v, {
4635
+ clockTolerance: 15
4636
+ });
4637
+ return w;
4638
+ }
4639
+ async function d(h) {
4640
+ var g, S, C;
4641
+ const {
4642
+ req: v,
4643
+ secureCookie: w = (g = (S = process.env.NEXTAUTH_URL) === null || S === void 0 ? void 0 : S.startsWith("https://")) !== null && g !== void 0 ? g : !!process.env.VERCEL,
4644
+ cookieName: m = w ? "__Secure-next-auth.session-token" : "next-auth.session-token",
4645
+ raw: E,
4646
+ decode: _ = f,
4647
+ logger: A = console,
4648
+ secret: R = process.env.NEXTAUTH_SECRET
4649
+ } = h;
4650
+ if (!v)
4651
+ throw new Error("Must pass `req` to JWT getToken()");
4652
+ let q = new i.SessionStore({
4653
+ name: m,
4654
+ options: {
4655
+ secure: w
4656
+ }
4657
+ }, {
4658
+ cookies: v.cookies,
4659
+ headers: v.headers
4660
+ }, A).value;
4661
+ const Y = v.headers instanceof Headers ? v.headers.get("authorization") : (C = v.headers) === null || C === void 0 ? void 0 : C.authorization;
4662
+ if (!q && (Y == null ? void 0 : Y.split(" ")[0]) === "Bearer") {
4663
+ const Be = Y.split(" ")[1];
4664
+ q = decodeURIComponent(Be);
4665
+ }
4666
+ if (!q)
4667
+ return null;
4668
+ if (E)
4669
+ return q;
4670
+ try {
4671
+ return await _({
4672
+ token: q,
4673
+ secret: R
4674
+ });
4675
+ } catch {
4676
+ return null;
4677
+ }
4678
+ }
4679
+ async function p(h, g) {
4680
+ return await (0, a.default)("sha256", h, g, `NextAuth.js Generated Encryption Key${g ? ` (${g})` : ""}`, 32);
4681
+ }
4682
+ })(rr);
4683
+ class Is extends Zr {
4684
+ async validateTokenFront(e) {
4685
+ this.logDebug("entra validate Token Front");
4686
+ const r = await rr.getToken({ req: e });
4687
+ if (this.logDebug("Token Front", JSON.stringify(r)), !r)
4688
+ throw new En("UNAUTHORIZED").get();
4689
+ return e;
4690
+ }
4691
+ }
4692
+ export {
4693
+ Is as C,
4694
+ vn as E,
4695
+ En as M
4696
+ };