wcz-test 7.1.3 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/DialogsContext-CGAKEKKW.js +546 -0
  2. package/dist/DialogsContext-CGAKEKKW.js.map +1 -0
  3. package/dist/{DialogsHooks-BXfwbYWP.js → DialogsHooks-BZUdpDVJ.js} +14 -14
  4. package/dist/DialogsHooks-BZUdpDVJ.js.map +1 -0
  5. package/dist/RouterListItemButton-C_jUvB6C.js +18 -0
  6. package/dist/{RouterListItemButton-DrW6M53Y.js.map → RouterListItemButton-C_jUvB6C.js.map} +1 -1
  7. package/dist/compiler-runtime-BNHg76kC.js +37 -0
  8. package/dist/compiler-runtime-BNHg76kC.js.map +1 -0
  9. package/dist/components/core/Layout.d.ts +1 -1
  10. package/dist/components.js +686 -682
  11. package/dist/components.js.map +1 -1
  12. package/dist/exports/hooks.d.ts +1 -1
  13. package/dist/exports/middleware.d.ts +1 -0
  14. package/dist/exports/utils.d.ts +3 -2
  15. package/dist/hooks/UseScanDetection.d.ts +28 -0
  16. package/dist/hooks.js +603 -610
  17. package/dist/hooks.js.map +1 -1
  18. package/dist/{i18next-Bx3TmZAT.js → i18next-8reizFda.js} +71 -63
  19. package/dist/i18next-8reizFda.js.map +1 -0
  20. package/dist/{index-DchOf6FV.js → index-wOcJpekI.js} +6 -4
  21. package/dist/index-wOcJpekI.js.map +1 -0
  22. package/dist/index.js +661 -821
  23. package/dist/index.js.map +1 -1
  24. package/dist/lib/auth/msalClient.d.ts +20 -0
  25. package/dist/lib/auth/msalServer.d.ts +11 -0
  26. package/dist/lib/auth/scopes.d.ts +2 -0
  27. package/dist/lib/auth/utils.d.ts +0 -0
  28. package/dist/lib/theme.d.ts +1 -0
  29. package/dist/lib/utils.d.ts +2 -10
  30. package/dist/middleware/authMiddleware.d.ts +6 -0
  31. package/dist/middleware.js +1101 -0
  32. package/dist/middleware.js.map +1 -0
  33. package/dist/models/TokenPayload.d.ts +8 -0
  34. package/dist/models/User.d.ts +10 -13
  35. package/dist/msalClient-Cem8ZXIU.js +75 -0
  36. package/dist/msalClient-Cem8ZXIU.js.map +1 -0
  37. package/dist/providers/AuthProvider.d.ts +0 -2
  38. package/dist/queries/FileHooks.d.ts +1 -1
  39. package/dist/queries/GraphQueries.d.ts +0 -20
  40. package/dist/query.js +1 -1
  41. package/dist/utils-BXxJ2sNo.js +151 -0
  42. package/dist/utils-BXxJ2sNo.js.map +1 -0
  43. package/dist/utils.js +72 -37
  44. package/dist/utils.js.map +1 -1
  45. package/package.json +16 -11
  46. package/dist/DialogsContext-8xfQ3X-k.js +0 -285
  47. package/dist/DialogsContext-8xfQ3X-k.js.map +0 -1
  48. package/dist/DialogsHooks-BXfwbYWP.js.map +0 -1
  49. package/dist/RouterListItemButton-DrW6M53Y.js +0 -17
  50. package/dist/hooks/User.d.ts +0 -8
  51. package/dist/i18next-Bx3TmZAT.js.map +0 -1
  52. package/dist/index-DchOf6FV.js.map +0 -1
  53. package/dist/utils-Dttzp8un.js +0 -10879
  54. package/dist/utils-Dttzp8un.js.map +0 -1
@@ -0,0 +1,1101 @@
1
+ import { createMiddleware as k } from "@tanstack/react-start";
2
+ import { permissions as re } from "virtual:wcz-layout";
3
+ import { c as H } from "./utils-BXxJ2sNo.js";
4
+ import { g as ne } from "./msalClient-Cem8ZXIU.js";
5
+ const N = new TextEncoder(), v = new TextDecoder();
6
+ function ae(...e) {
7
+ const t = e.reduce((a, { length: i }) => a + i, 0), r = new Uint8Array(t);
8
+ let n = 0;
9
+ for (const a of e)
10
+ r.set(a, n), n += a.length;
11
+ return r;
12
+ }
13
+ function C(e) {
14
+ const t = new Uint8Array(e.length);
15
+ for (let r = 0; r < e.length; r++) {
16
+ const n = e.charCodeAt(r);
17
+ if (n > 127)
18
+ throw new TypeError("non-ASCII string encountered in encode()");
19
+ t[r] = n;
20
+ }
21
+ return t;
22
+ }
23
+ function ie(e) {
24
+ if (Uint8Array.fromBase64)
25
+ return Uint8Array.fromBase64(e);
26
+ const t = atob(e), r = new Uint8Array(t.length);
27
+ for (let n = 0; n < t.length; n++)
28
+ r[n] = t.charCodeAt(n);
29
+ return r;
30
+ }
31
+ function K(e) {
32
+ if (Uint8Array.fromBase64)
33
+ return Uint8Array.fromBase64(typeof e == "string" ? e : v.decode(e), {
34
+ alphabet: "base64url"
35
+ });
36
+ let t = e;
37
+ t instanceof Uint8Array && (t = v.decode(t)), t = t.replace(/-/g, "+").replace(/_/g, "/");
38
+ try {
39
+ return ie(t);
40
+ } catch {
41
+ throw new TypeError("The input to be decoded is not correctly encoded.");
42
+ }
43
+ }
44
+ class h extends Error {
45
+ static code = "ERR_JOSE_GENERIC";
46
+ code = "ERR_JOSE_GENERIC";
47
+ constructor(t, r) {
48
+ super(t, r), this.name = this.constructor.name, Error.captureStackTrace?.(this, this.constructor);
49
+ }
50
+ }
51
+ class y extends h {
52
+ static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
53
+ code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
54
+ claim;
55
+ reason;
56
+ payload;
57
+ constructor(t, r, n = "unspecified", a = "unspecified") {
58
+ super(t, { cause: { claim: n, reason: a, payload: r } }), this.claim = n, this.reason = a, this.payload = r;
59
+ }
60
+ }
61
+ class M extends h {
62
+ static code = "ERR_JWT_EXPIRED";
63
+ code = "ERR_JWT_EXPIRED";
64
+ claim;
65
+ reason;
66
+ payload;
67
+ constructor(t, r, n = "unspecified", a = "unspecified") {
68
+ super(t, { cause: { claim: n, reason: a, payload: r } }), this.claim = n, this.reason = a, this.payload = r;
69
+ }
70
+ }
71
+ class se extends h {
72
+ static code = "ERR_JOSE_ALG_NOT_ALLOWED";
73
+ code = "ERR_JOSE_ALG_NOT_ALLOWED";
74
+ }
75
+ class S extends h {
76
+ static code = "ERR_JOSE_NOT_SUPPORTED";
77
+ code = "ERR_JOSE_NOT_SUPPORTED";
78
+ }
79
+ class d extends h {
80
+ static code = "ERR_JWS_INVALID";
81
+ code = "ERR_JWS_INVALID";
82
+ }
83
+ class B extends h {
84
+ static code = "ERR_JWT_INVALID";
85
+ code = "ERR_JWT_INVALID";
86
+ }
87
+ class G extends h {
88
+ static code = "ERR_JWKS_INVALID";
89
+ code = "ERR_JWKS_INVALID";
90
+ }
91
+ class z extends h {
92
+ static code = "ERR_JWKS_NO_MATCHING_KEY";
93
+ code = "ERR_JWKS_NO_MATCHING_KEY";
94
+ constructor(t = "no applicable key found in the JSON Web Key Set", r) {
95
+ super(t, r);
96
+ }
97
+ }
98
+ class oe extends h {
99
+ [Symbol.asyncIterator];
100
+ static code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
101
+ code = "ERR_JWKS_MULTIPLE_MATCHING_KEYS";
102
+ constructor(t = "multiple matching keys found in the JSON Web Key Set", r) {
103
+ super(t, r);
104
+ }
105
+ }
106
+ class ce extends h {
107
+ static code = "ERR_JWKS_TIMEOUT";
108
+ code = "ERR_JWKS_TIMEOUT";
109
+ constructor(t = "request timed out", r) {
110
+ super(t, r);
111
+ }
112
+ }
113
+ class fe extends h {
114
+ static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
115
+ code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
116
+ constructor(t = "signature verification failed", r) {
117
+ super(t, r);
118
+ }
119
+ }
120
+ const m = (e, t = "algorithm.name") => new TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`), b = (e, t) => e.name === t;
121
+ function P(e) {
122
+ return parseInt(e.name.slice(4), 10);
123
+ }
124
+ function de(e) {
125
+ switch (e) {
126
+ case "ES256":
127
+ return "P-256";
128
+ case "ES384":
129
+ return "P-384";
130
+ case "ES512":
131
+ return "P-521";
132
+ default:
133
+ throw new Error("unreachable");
134
+ }
135
+ }
136
+ function ue(e, t) {
137
+ if (!e.usages.includes(t))
138
+ throw new TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`);
139
+ }
140
+ function he(e, t, r) {
141
+ switch (t) {
142
+ case "HS256":
143
+ case "HS384":
144
+ case "HS512": {
145
+ if (!b(e.algorithm, "HMAC"))
146
+ throw m("HMAC");
147
+ const n = parseInt(t.slice(2), 10);
148
+ if (P(e.algorithm.hash) !== n)
149
+ throw m(`SHA-${n}`, "algorithm.hash");
150
+ break;
151
+ }
152
+ case "RS256":
153
+ case "RS384":
154
+ case "RS512": {
155
+ if (!b(e.algorithm, "RSASSA-PKCS1-v1_5"))
156
+ throw m("RSASSA-PKCS1-v1_5");
157
+ const n = parseInt(t.slice(2), 10);
158
+ if (P(e.algorithm.hash) !== n)
159
+ throw m(`SHA-${n}`, "algorithm.hash");
160
+ break;
161
+ }
162
+ case "PS256":
163
+ case "PS384":
164
+ case "PS512": {
165
+ if (!b(e.algorithm, "RSA-PSS"))
166
+ throw m("RSA-PSS");
167
+ const n = parseInt(t.slice(2), 10);
168
+ if (P(e.algorithm.hash) !== n)
169
+ throw m(`SHA-${n}`, "algorithm.hash");
170
+ break;
171
+ }
172
+ case "Ed25519":
173
+ case "EdDSA": {
174
+ if (!b(e.algorithm, "Ed25519"))
175
+ throw m("Ed25519");
176
+ break;
177
+ }
178
+ case "ML-DSA-44":
179
+ case "ML-DSA-65":
180
+ case "ML-DSA-87": {
181
+ if (!b(e.algorithm, t))
182
+ throw m(t);
183
+ break;
184
+ }
185
+ case "ES256":
186
+ case "ES384":
187
+ case "ES512": {
188
+ if (!b(e.algorithm, "ECDSA"))
189
+ throw m("ECDSA");
190
+ const n = de(t);
191
+ if (e.algorithm.namedCurve !== n)
192
+ throw m(n, "algorithm.namedCurve");
193
+ break;
194
+ }
195
+ default:
196
+ throw new TypeError("CryptoKey does not support this operation");
197
+ }
198
+ ue(e, r);
199
+ }
200
+ function q(e, t, ...r) {
201
+ if (r = r.filter(Boolean), r.length > 2) {
202
+ const n = r.pop();
203
+ e += `one of type ${r.join(", ")}, or ${n}.`;
204
+ } else r.length === 2 ? e += `one of type ${r[0]} or ${r[1]}.` : e += `of type ${r[0]}.`;
205
+ return t == null ? e += ` Received ${t}` : typeof t == "function" && t.name ? e += ` Received function ${t.name}` : typeof t == "object" && t != null && t.constructor?.name && (e += ` Received an instance of ${t.constructor.name}`), e;
206
+ }
207
+ const le = (e, ...t) => q("Key must be ", e, ...t), Y = (e, t, ...r) => q(`Key for the ${e} algorithm must be `, t, ...r), X = (e) => {
208
+ if (e?.[Symbol.toStringTag] === "CryptoKey")
209
+ return !0;
210
+ try {
211
+ return e instanceof CryptoKey;
212
+ } catch {
213
+ return !1;
214
+ }
215
+ }, Q = (e) => e?.[Symbol.toStringTag] === "KeyObject", Z = (e) => X(e) || Q(e);
216
+ function pe(...e) {
217
+ const t = e.filter(Boolean);
218
+ if (t.length === 0 || t.length === 1)
219
+ return !0;
220
+ let r;
221
+ for (const n of t) {
222
+ const a = Object.keys(n);
223
+ if (!r || r.size === 0) {
224
+ r = new Set(a);
225
+ continue;
226
+ }
227
+ for (const i of a) {
228
+ if (r.has(i))
229
+ return !1;
230
+ r.add(i);
231
+ }
232
+ }
233
+ return !0;
234
+ }
235
+ const ye = (e) => typeof e == "object" && e !== null;
236
+ function w(e) {
237
+ if (!ye(e) || Object.prototype.toString.call(e) !== "[object Object]")
238
+ return !1;
239
+ if (Object.getPrototypeOf(e) === null)
240
+ return !0;
241
+ let t = e;
242
+ for (; Object.getPrototypeOf(t) !== null; )
243
+ t = Object.getPrototypeOf(t);
244
+ return Object.getPrototypeOf(e) === t;
245
+ }
246
+ function me(e, t) {
247
+ if (e.startsWith("RS") || e.startsWith("PS")) {
248
+ const { modulusLength: r } = t.algorithm;
249
+ if (typeof r != "number" || r < 2048)
250
+ throw new TypeError(`${e} requires key modulusLength to be 2048 bits or larger`);
251
+ }
252
+ }
253
+ function Se(e) {
254
+ let t, r;
255
+ switch (e.kty) {
256
+ case "AKP": {
257
+ switch (e.alg) {
258
+ case "ML-DSA-44":
259
+ case "ML-DSA-65":
260
+ case "ML-DSA-87":
261
+ t = { name: e.alg }, r = e.priv ? ["sign"] : ["verify"];
262
+ break;
263
+ default:
264
+ throw new S('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
265
+ }
266
+ break;
267
+ }
268
+ case "RSA": {
269
+ switch (e.alg) {
270
+ case "PS256":
271
+ case "PS384":
272
+ case "PS512":
273
+ t = { name: "RSA-PSS", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
274
+ break;
275
+ case "RS256":
276
+ case "RS384":
277
+ case "RS512":
278
+ t = { name: "RSASSA-PKCS1-v1_5", hash: `SHA-${e.alg.slice(-3)}` }, r = e.d ? ["sign"] : ["verify"];
279
+ break;
280
+ case "RSA-OAEP":
281
+ case "RSA-OAEP-256":
282
+ case "RSA-OAEP-384":
283
+ case "RSA-OAEP-512":
284
+ t = {
285
+ name: "RSA-OAEP",
286
+ hash: `SHA-${parseInt(e.alg.slice(-3), 10) || 1}`
287
+ }, r = e.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
288
+ break;
289
+ default:
290
+ throw new S('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
291
+ }
292
+ break;
293
+ }
294
+ case "EC": {
295
+ switch (e.alg) {
296
+ case "ES256":
297
+ t = { name: "ECDSA", namedCurve: "P-256" }, r = e.d ? ["sign"] : ["verify"];
298
+ break;
299
+ case "ES384":
300
+ t = { name: "ECDSA", namedCurve: "P-384" }, r = e.d ? ["sign"] : ["verify"];
301
+ break;
302
+ case "ES512":
303
+ t = { name: "ECDSA", namedCurve: "P-521" }, r = e.d ? ["sign"] : ["verify"];
304
+ break;
305
+ case "ECDH-ES":
306
+ case "ECDH-ES+A128KW":
307
+ case "ECDH-ES+A192KW":
308
+ case "ECDH-ES+A256KW":
309
+ t = { name: "ECDH", namedCurve: e.crv }, r = e.d ? ["deriveBits"] : [];
310
+ break;
311
+ default:
312
+ throw new S('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
313
+ }
314
+ break;
315
+ }
316
+ case "OKP": {
317
+ switch (e.alg) {
318
+ case "Ed25519":
319
+ case "EdDSA":
320
+ t = { name: "Ed25519" }, r = e.d ? ["sign"] : ["verify"];
321
+ break;
322
+ case "ECDH-ES":
323
+ case "ECDH-ES+A128KW":
324
+ case "ECDH-ES+A192KW":
325
+ case "ECDH-ES+A256KW":
326
+ t = { name: e.crv }, r = e.d ? ["deriveBits"] : [];
327
+ break;
328
+ default:
329
+ throw new S('Invalid or unsupported JWK "alg" (Algorithm) Parameter value');
330
+ }
331
+ break;
332
+ }
333
+ default:
334
+ throw new S('Invalid or unsupported JWK "kty" (Key Type) Parameter value');
335
+ }
336
+ return { algorithm: t, keyUsages: r };
337
+ }
338
+ async function W(e) {
339
+ if (!e.alg)
340
+ throw new TypeError('"alg" argument is required when "jwk.alg" is not present');
341
+ const { algorithm: t, keyUsages: r } = Se(e), n = { ...e };
342
+ return n.kty !== "AKP" && delete n.alg, delete n.use, crypto.subtle.importKey("jwk", n, t, e.ext ?? !(e.d || e.priv), e.key_ops ?? r);
343
+ }
344
+ async function we(e, t, r) {
345
+ if (!w(e))
346
+ throw new TypeError("JWK must be an object");
347
+ let n;
348
+ switch (t ??= e.alg, n ??= e.ext, e.kty) {
349
+ case "oct":
350
+ if (typeof e.k != "string" || !e.k)
351
+ throw new TypeError('missing "k" (Key Value) Parameter value');
352
+ return K(e.k);
353
+ case "RSA":
354
+ if ("oth" in e && e.oth !== void 0)
355
+ throw new S('RSA JWK "oth" (Other Primes Info) Parameter value is not supported');
356
+ return W({ ...e, alg: t, ext: n });
357
+ case "AKP": {
358
+ if (typeof e.alg != "string" || !e.alg)
359
+ throw new TypeError('missing "alg" (Algorithm) Parameter value');
360
+ if (t !== void 0 && t !== e.alg)
361
+ throw new TypeError("JWK alg and alg option value mismatch");
362
+ return W({ ...e, ext: n });
363
+ }
364
+ case "EC":
365
+ case "OKP":
366
+ return W({ ...e, alg: t, ext: n });
367
+ default:
368
+ throw new S('Unsupported "kty" (Key Type) Parameter value');
369
+ }
370
+ }
371
+ function Ee(e, t, r, n, a) {
372
+ if (a.crit !== void 0 && n?.crit === void 0)
373
+ throw new e('"crit" (Critical) Header Parameter MUST be integrity protected');
374
+ if (!n || n.crit === void 0)
375
+ return /* @__PURE__ */ new Set();
376
+ if (!Array.isArray(n.crit) || n.crit.length === 0 || n.crit.some((s) => typeof s != "string" || s.length === 0))
377
+ throw new e('"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present');
378
+ let i;
379
+ r !== void 0 ? i = new Map([...Object.entries(r), ...t.entries()]) : i = t;
380
+ for (const s of n.crit) {
381
+ if (!i.has(s))
382
+ throw new S(`Extension Header Parameter "${s}" is not recognized`);
383
+ if (a[s] === void 0)
384
+ throw new e(`Extension Header Parameter "${s}" is missing`);
385
+ if (i.get(s) && n[s] === void 0)
386
+ throw new e(`Extension Header Parameter "${s}" MUST be integrity protected`);
387
+ }
388
+ return new Set(n.crit);
389
+ }
390
+ function be(e, t) {
391
+ if (t !== void 0 && (!Array.isArray(t) || t.some((r) => typeof r != "string")))
392
+ throw new TypeError(`"${e}" option must be an array of strings`);
393
+ if (t)
394
+ return new Set(t);
395
+ }
396
+ const I = (e) => w(e) && typeof e.kty == "string", Ae = (e) => e.kty !== "oct" && (e.kty === "AKP" && typeof e.priv == "string" || typeof e.d == "string"), ge = (e) => e.kty !== "oct" && e.d === void 0 && e.priv === void 0, Ke = (e) => e.kty === "oct" && typeof e.k == "string";
397
+ let g;
398
+ const L = async (e, t, r, n = !1) => {
399
+ g ||= /* @__PURE__ */ new WeakMap();
400
+ let a = g.get(e);
401
+ if (a?.[r])
402
+ return a[r];
403
+ const i = await W({ ...t, alg: r });
404
+ return n && Object.freeze(e), a ? a[r] = i : g.set(e, { [r]: i }), i;
405
+ }, ve = (e, t) => {
406
+ g ||= /* @__PURE__ */ new WeakMap();
407
+ let r = g.get(e);
408
+ if (r?.[t])
409
+ return r[t];
410
+ const n = e.type === "public", a = !!n;
411
+ let i;
412
+ if (e.asymmetricKeyType === "x25519") {
413
+ switch (t) {
414
+ case "ECDH-ES":
415
+ case "ECDH-ES+A128KW":
416
+ case "ECDH-ES+A192KW":
417
+ case "ECDH-ES+A256KW":
418
+ break;
419
+ default:
420
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
421
+ }
422
+ i = e.toCryptoKey(e.asymmetricKeyType, a, n ? [] : ["deriveBits"]);
423
+ }
424
+ if (e.asymmetricKeyType === "ed25519") {
425
+ if (t !== "EdDSA" && t !== "Ed25519")
426
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
427
+ i = e.toCryptoKey(e.asymmetricKeyType, a, [
428
+ n ? "verify" : "sign"
429
+ ]);
430
+ }
431
+ switch (e.asymmetricKeyType) {
432
+ case "ml-dsa-44":
433
+ case "ml-dsa-65":
434
+ case "ml-dsa-87": {
435
+ if (t !== e.asymmetricKeyType.toUpperCase())
436
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
437
+ i = e.toCryptoKey(e.asymmetricKeyType, a, [
438
+ n ? "verify" : "sign"
439
+ ]);
440
+ }
441
+ }
442
+ if (e.asymmetricKeyType === "rsa") {
443
+ let s;
444
+ switch (t) {
445
+ case "RSA-OAEP":
446
+ s = "SHA-1";
447
+ break;
448
+ case "RS256":
449
+ case "PS256":
450
+ case "RSA-OAEP-256":
451
+ s = "SHA-256";
452
+ break;
453
+ case "RS384":
454
+ case "PS384":
455
+ case "RSA-OAEP-384":
456
+ s = "SHA-384";
457
+ break;
458
+ case "RS512":
459
+ case "PS512":
460
+ case "RSA-OAEP-512":
461
+ s = "SHA-512";
462
+ break;
463
+ default:
464
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
465
+ }
466
+ if (t.startsWith("RSA-OAEP"))
467
+ return e.toCryptoKey({
468
+ name: "RSA-OAEP",
469
+ hash: s
470
+ }, a, n ? ["encrypt"] : ["decrypt"]);
471
+ i = e.toCryptoKey({
472
+ name: t.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
473
+ hash: s
474
+ }, a, [n ? "verify" : "sign"]);
475
+ }
476
+ if (e.asymmetricKeyType === "ec") {
477
+ const o = (/* @__PURE__ */ new Map([
478
+ ["prime256v1", "P-256"],
479
+ ["secp384r1", "P-384"],
480
+ ["secp521r1", "P-521"]
481
+ ])).get(e.asymmetricKeyDetails?.namedCurve);
482
+ if (!o)
483
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
484
+ t === "ES256" && o === "P-256" && (i = e.toCryptoKey({
485
+ name: "ECDSA",
486
+ namedCurve: o
487
+ }, a, [n ? "verify" : "sign"])), t === "ES384" && o === "P-384" && (i = e.toCryptoKey({
488
+ name: "ECDSA",
489
+ namedCurve: o
490
+ }, a, [n ? "verify" : "sign"])), t === "ES512" && o === "P-521" && (i = e.toCryptoKey({
491
+ name: "ECDSA",
492
+ namedCurve: o
493
+ }, a, [n ? "verify" : "sign"])), t.startsWith("ECDH-ES") && (i = e.toCryptoKey({
494
+ name: "ECDH",
495
+ namedCurve: o
496
+ }, a, n ? [] : ["deriveBits"]));
497
+ }
498
+ if (!i)
499
+ throw new TypeError("given KeyObject instance cannot be used for this algorithm");
500
+ return r ? r[t] = i : g.set(e, { [t]: i }), i;
501
+ };
502
+ async function Te(e, t) {
503
+ if (e instanceof Uint8Array || X(e))
504
+ return e;
505
+ if (Q(e)) {
506
+ if (e.type === "secret")
507
+ return e.export();
508
+ if ("toCryptoKey" in e && typeof e.toCryptoKey == "function")
509
+ try {
510
+ return ve(e, t);
511
+ } catch (n) {
512
+ if (n instanceof TypeError)
513
+ throw n;
514
+ }
515
+ let r = e.export({ format: "jwk" });
516
+ return L(e, r, t);
517
+ }
518
+ if (I(e))
519
+ return e.k ? K(e.k) : L(e, e, t, !0);
520
+ throw new Error("unreachable");
521
+ }
522
+ const A = (e) => e?.[Symbol.toStringTag], J = (e, t, r) => {
523
+ if (t.use !== void 0) {
524
+ let n;
525
+ switch (r) {
526
+ case "sign":
527
+ case "verify":
528
+ n = "sig";
529
+ break;
530
+ case "encrypt":
531
+ case "decrypt":
532
+ n = "enc";
533
+ break;
534
+ }
535
+ if (t.use !== n)
536
+ throw new TypeError(`Invalid key for this operation, its "use" must be "${n}" when present`);
537
+ }
538
+ if (t.alg !== void 0 && t.alg !== e)
539
+ throw new TypeError(`Invalid key for this operation, its "alg" must be "${e}" when present`);
540
+ if (Array.isArray(t.key_ops)) {
541
+ let n;
542
+ switch (!0) {
543
+ case r === "verify":
544
+ case e === "dir":
545
+ case e.includes("CBC-HS"):
546
+ n = r;
547
+ break;
548
+ case e.startsWith("PBES2"):
549
+ n = "deriveBits";
550
+ break;
551
+ case /^A\d{3}(?:GCM)?(?:KW)?$/.test(e):
552
+ !e.includes("GCM") && e.endsWith("KW") ? n = "unwrapKey" : n = r;
553
+ break;
554
+ case r === "encrypt":
555
+ n = "wrapKey";
556
+ break;
557
+ case r === "decrypt":
558
+ n = e.startsWith("RSA") ? "unwrapKey" : "deriveBits";
559
+ break;
560
+ }
561
+ if (n && t.key_ops?.includes?.(n) === !1)
562
+ throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${n}" when present`);
563
+ }
564
+ return !0;
565
+ }, Re = (e, t, r) => {
566
+ if (!(t instanceof Uint8Array)) {
567
+ if (I(t)) {
568
+ if (Ke(t) && J(e, t, r))
569
+ return;
570
+ throw new TypeError('JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present');
571
+ }
572
+ if (!Z(t))
573
+ throw new TypeError(Y(e, t, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
574
+ if (t.type !== "secret")
575
+ throw new TypeError(`${A(t)} instances for symmetric algorithms must be of type "secret"`);
576
+ }
577
+ }, We = (e, t, r) => {
578
+ if (I(t))
579
+ switch (r) {
580
+ case "decrypt":
581
+ case "sign":
582
+ if (Ae(t) && J(e, t, r))
583
+ return;
584
+ throw new TypeError("JSON Web Key for this operation must be a private JWK");
585
+ case "encrypt":
586
+ case "verify":
587
+ if (ge(t) && J(e, t, r))
588
+ return;
589
+ throw new TypeError("JSON Web Key for this operation must be a public JWK");
590
+ }
591
+ if (!Z(t))
592
+ throw new TypeError(Y(e, t, "CryptoKey", "KeyObject", "JSON Web Key"));
593
+ if (t.type === "secret")
594
+ throw new TypeError(`${A(t)} instances for asymmetric algorithms must not be of type "secret"`);
595
+ if (t.type === "public")
596
+ switch (r) {
597
+ case "sign":
598
+ throw new TypeError(`${A(t)} instances for asymmetric algorithm signing must be of type "private"`);
599
+ case "decrypt":
600
+ throw new TypeError(`${A(t)} instances for asymmetric algorithm decryption must be of type "private"`);
601
+ }
602
+ if (t.type === "private")
603
+ switch (r) {
604
+ case "verify":
605
+ throw new TypeError(`${A(t)} instances for asymmetric algorithm verifying must be of type "public"`);
606
+ case "encrypt":
607
+ throw new TypeError(`${A(t)} instances for asymmetric algorithm encryption must be of type "public"`);
608
+ }
609
+ };
610
+ function Ce(e, t, r) {
611
+ switch (e.substring(0, 2)) {
612
+ case "A1":
613
+ case "A2":
614
+ case "di":
615
+ case "HS":
616
+ case "PB":
617
+ Re(e, t, r);
618
+ break;
619
+ default:
620
+ We(e, t, r);
621
+ }
622
+ }
623
+ function Pe(e, t) {
624
+ const r = `SHA-${e.slice(-3)}`;
625
+ switch (e) {
626
+ case "HS256":
627
+ case "HS384":
628
+ case "HS512":
629
+ return { hash: r, name: "HMAC" };
630
+ case "PS256":
631
+ case "PS384":
632
+ case "PS512":
633
+ return { hash: r, name: "RSA-PSS", saltLength: parseInt(e.slice(-3), 10) >> 3 };
634
+ case "RS256":
635
+ case "RS384":
636
+ case "RS512":
637
+ return { hash: r, name: "RSASSA-PKCS1-v1_5" };
638
+ case "ES256":
639
+ case "ES384":
640
+ case "ES512":
641
+ return { hash: r, name: "ECDSA", namedCurve: t.namedCurve };
642
+ case "Ed25519":
643
+ case "EdDSA":
644
+ return { name: "Ed25519" };
645
+ case "ML-DSA-44":
646
+ case "ML-DSA-65":
647
+ case "ML-DSA-87":
648
+ return { name: e };
649
+ default:
650
+ throw new S(`alg ${e} is not supported either by JOSE or your javascript runtime`);
651
+ }
652
+ }
653
+ async function _e(e, t, r) {
654
+ if (t instanceof Uint8Array) {
655
+ if (!e.startsWith("HS"))
656
+ throw new TypeError(le(t, "CryptoKey", "KeyObject", "JSON Web Key"));
657
+ return crypto.subtle.importKey("raw", t, { hash: `SHA-${e.slice(-3)}`, name: "HMAC" }, !1, [r]);
658
+ }
659
+ return he(t, e, r), t;
660
+ }
661
+ async function Je(e, t, r, n) {
662
+ const a = await _e(e, t, "verify");
663
+ me(e, a);
664
+ const i = Pe(e, a.algorithm);
665
+ try {
666
+ return await crypto.subtle.verify(i, a, r, n);
667
+ } catch {
668
+ return !1;
669
+ }
670
+ }
671
+ async function De(e, t, r) {
672
+ if (!w(e))
673
+ throw new d("Flattened JWS must be an object");
674
+ if (e.protected === void 0 && e.header === void 0)
675
+ throw new d('Flattened JWS must have either of the "protected" or "header" members');
676
+ if (e.protected !== void 0 && typeof e.protected != "string")
677
+ throw new d("JWS Protected Header incorrect type");
678
+ if (e.payload === void 0)
679
+ throw new d("JWS Payload missing");
680
+ if (typeof e.signature != "string")
681
+ throw new d("JWS Signature missing or incorrect type");
682
+ if (e.header !== void 0 && !w(e.header))
683
+ throw new d("JWS Unprotected Header incorrect type");
684
+ let n = {};
685
+ if (e.protected)
686
+ try {
687
+ const te = K(e.protected);
688
+ n = JSON.parse(v.decode(te));
689
+ } catch {
690
+ throw new d("JWS Protected Header is invalid");
691
+ }
692
+ if (!pe(n, e.header))
693
+ throw new d("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
694
+ const a = {
695
+ ...n,
696
+ ...e.header
697
+ }, i = Ee(d, /* @__PURE__ */ new Map([["b64", !0]]), r?.crit, n, a);
698
+ let s = !0;
699
+ if (i.has("b64") && (s = n.b64, typeof s != "boolean"))
700
+ throw new d('The "b64" (base64url-encode payload) Header Parameter must be a boolean');
701
+ const { alg: o } = a;
702
+ if (typeof o != "string" || !o)
703
+ throw new d('JWS "alg" (Algorithm) Header Parameter missing or invalid');
704
+ const u = r && be("algorithms", r.algorithms);
705
+ if (u && !u.has(o))
706
+ throw new se('"alg" (Algorithm) Header Parameter value not allowed');
707
+ if (s) {
708
+ if (typeof e.payload != "string")
709
+ throw new d("JWS Payload must be a string");
710
+ } else if (typeof e.payload != "string" && !(e.payload instanceof Uint8Array))
711
+ throw new d("JWS Payload must be a string or an Uint8Array instance");
712
+ let c = !1;
713
+ typeof t == "function" && (t = await t(n, e), c = !0), Ce(o, t, "verify");
714
+ const f = ae(e.protected !== void 0 ? C(e.protected) : new Uint8Array(), C("."), typeof e.payload == "string" ? s ? C(e.payload) : N.encode(e.payload) : e.payload);
715
+ let l;
716
+ try {
717
+ l = K(e.signature);
718
+ } catch {
719
+ throw new d("Failed to base64url decode the signature");
720
+ }
721
+ const T = await Te(t, o);
722
+ if (!await Je(o, T, l, f))
723
+ throw new fe();
724
+ let p;
725
+ if (s)
726
+ try {
727
+ p = K(e.payload);
728
+ } catch {
729
+ throw new d("Failed to base64url decode the payload");
730
+ }
731
+ else typeof e.payload == "string" ? p = N.encode(e.payload) : p = e.payload;
732
+ const E = { payload: p };
733
+ return e.protected !== void 0 && (E.protectedHeader = n), e.header !== void 0 && (E.unprotectedHeader = e.header), c ? { ...E, key: T } : E;
734
+ }
735
+ async function Ie(e, t, r) {
736
+ if (e instanceof Uint8Array && (e = v.decode(e)), typeof e != "string")
737
+ throw new d("Compact JWS must be a string or Uint8Array");
738
+ const { 0: n, 1: a, 2: i, length: s } = e.split(".");
739
+ if (s !== 3)
740
+ throw new d("Invalid Compact JWS");
741
+ const o = await De({ payload: a, protected: n, signature: i }, t, r), u = { payload: o.payload, protectedHeader: o.protectedHeader };
742
+ return typeof t == "function" ? { ...u, key: o.key } : u;
743
+ }
744
+ const Oe = (e) => Math.floor(e.getTime() / 1e3), j = 60, ee = j * 60, O = ee * 24, He = O * 7, Ne = O * 365.25, Me = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
745
+ function x(e) {
746
+ const t = Me.exec(e);
747
+ if (!t || t[4] && t[1])
748
+ throw new TypeError("Invalid time period format");
749
+ const r = parseFloat(t[2]), n = t[3].toLowerCase();
750
+ let a;
751
+ switch (n) {
752
+ case "sec":
753
+ case "secs":
754
+ case "second":
755
+ case "seconds":
756
+ case "s":
757
+ a = Math.round(r);
758
+ break;
759
+ case "minute":
760
+ case "minutes":
761
+ case "min":
762
+ case "mins":
763
+ case "m":
764
+ a = Math.round(r * j);
765
+ break;
766
+ case "hour":
767
+ case "hours":
768
+ case "hr":
769
+ case "hrs":
770
+ case "h":
771
+ a = Math.round(r * ee);
772
+ break;
773
+ case "day":
774
+ case "days":
775
+ case "d":
776
+ a = Math.round(r * O);
777
+ break;
778
+ case "week":
779
+ case "weeks":
780
+ case "w":
781
+ a = Math.round(r * He);
782
+ break;
783
+ default:
784
+ a = Math.round(r * Ne);
785
+ break;
786
+ }
787
+ return t[1] === "-" || t[4] === "ago" ? -a : a;
788
+ }
789
+ const U = (e) => e.includes("/") ? e.toLowerCase() : `application/${e.toLowerCase()}`, Le = (e, t) => typeof e == "string" ? t.includes(e) : Array.isArray(e) ? t.some(Set.prototype.has.bind(new Set(e))) : !1;
790
+ function xe(e, t, r = {}) {
791
+ let n;
792
+ try {
793
+ n = JSON.parse(v.decode(t));
794
+ } catch {
795
+ }
796
+ if (!w(n))
797
+ throw new B("JWT Claims Set must be a top-level JSON object");
798
+ const { typ: a } = r;
799
+ if (a && (typeof e.typ != "string" || U(e.typ) !== U(a)))
800
+ throw new y('unexpected "typ" JWT header value', n, "typ", "check_failed");
801
+ const { requiredClaims: i = [], issuer: s, subject: o, audience: u, maxTokenAge: c } = r, f = [...i];
802
+ c !== void 0 && f.push("iat"), u !== void 0 && f.push("aud"), o !== void 0 && f.push("sub"), s !== void 0 && f.push("iss");
803
+ for (const p of new Set(f.reverse()))
804
+ if (!(p in n))
805
+ throw new y(`missing required "${p}" claim`, n, p, "missing");
806
+ if (s && !(Array.isArray(s) ? s : [s]).includes(n.iss))
807
+ throw new y('unexpected "iss" claim value', n, "iss", "check_failed");
808
+ if (o && n.sub !== o)
809
+ throw new y('unexpected "sub" claim value', n, "sub", "check_failed");
810
+ if (u && !Le(n.aud, typeof u == "string" ? [u] : u))
811
+ throw new y('unexpected "aud" claim value', n, "aud", "check_failed");
812
+ let l;
813
+ switch (typeof r.clockTolerance) {
814
+ case "string":
815
+ l = x(r.clockTolerance);
816
+ break;
817
+ case "number":
818
+ l = r.clockTolerance;
819
+ break;
820
+ case "undefined":
821
+ l = 0;
822
+ break;
823
+ default:
824
+ throw new TypeError("Invalid clockTolerance option type");
825
+ }
826
+ const { currentDate: T } = r, R = Oe(T || /* @__PURE__ */ new Date());
827
+ if ((n.iat !== void 0 || c) && typeof n.iat != "number")
828
+ throw new y('"iat" claim must be a number', n, "iat", "invalid");
829
+ if (n.nbf !== void 0) {
830
+ if (typeof n.nbf != "number")
831
+ throw new y('"nbf" claim must be a number', n, "nbf", "invalid");
832
+ if (n.nbf > R + l)
833
+ throw new y('"nbf" claim timestamp check failed', n, "nbf", "check_failed");
834
+ }
835
+ if (n.exp !== void 0) {
836
+ if (typeof n.exp != "number")
837
+ throw new y('"exp" claim must be a number', n, "exp", "invalid");
838
+ if (n.exp <= R - l)
839
+ throw new M('"exp" claim timestamp check failed', n, "exp", "check_failed");
840
+ }
841
+ if (c) {
842
+ const p = R - n.iat, E = typeof c == "number" ? c : x(c);
843
+ if (p - l > E)
844
+ throw new M('"iat" claim timestamp check failed (too far in the past)', n, "iat", "check_failed");
845
+ if (p < 0 - l)
846
+ throw new y('"iat" claim timestamp check failed (it should be in the past)', n, "iat", "check_failed");
847
+ }
848
+ return n;
849
+ }
850
+ async function Ue(e, t, r) {
851
+ const n = await Ie(e, t, r);
852
+ if (n.protectedHeader.crit?.includes("b64") && n.protectedHeader.b64 === !1)
853
+ throw new B("JWTs MUST NOT use unencoded payload");
854
+ const i = { payload: xe(n.protectedHeader, n.payload, r), protectedHeader: n.protectedHeader };
855
+ return typeof t == "function" ? { ...i, key: n.key } : i;
856
+ }
857
+ function $e(e) {
858
+ switch (typeof e == "string" && e.slice(0, 2)) {
859
+ case "RS":
860
+ case "PS":
861
+ return "RSA";
862
+ case "ES":
863
+ return "EC";
864
+ case "Ed":
865
+ return "OKP";
866
+ case "ML":
867
+ return "AKP";
868
+ default:
869
+ throw new S('Unsupported "alg" value for a JSON Web Key Set');
870
+ }
871
+ }
872
+ function Fe(e) {
873
+ return e && typeof e == "object" && Array.isArray(e.keys) && e.keys.every(Ve);
874
+ }
875
+ function Ve(e) {
876
+ return w(e);
877
+ }
878
+ class ke {
879
+ #r;
880
+ #s = /* @__PURE__ */ new WeakMap();
881
+ constructor(t) {
882
+ if (!Fe(t))
883
+ throw new G("JSON Web Key Set malformed");
884
+ this.#r = structuredClone(t);
885
+ }
886
+ jwks() {
887
+ return this.#r;
888
+ }
889
+ async getKey(t, r) {
890
+ const { alg: n, kid: a } = { ...t, ...r?.header }, i = $e(n), s = this.#r.keys.filter((c) => {
891
+ let f = i === c.kty;
892
+ if (f && typeof a == "string" && (f = a === c.kid), f && (typeof c.alg == "string" || i === "AKP") && (f = n === c.alg), f && typeof c.use == "string" && (f = c.use === "sig"), f && Array.isArray(c.key_ops) && (f = c.key_ops.includes("verify")), f)
893
+ switch (n) {
894
+ case "ES256":
895
+ f = c.crv === "P-256";
896
+ break;
897
+ case "ES384":
898
+ f = c.crv === "P-384";
899
+ break;
900
+ case "ES512":
901
+ f = c.crv === "P-521";
902
+ break;
903
+ case "Ed25519":
904
+ case "EdDSA":
905
+ f = c.crv === "Ed25519";
906
+ break;
907
+ }
908
+ return f;
909
+ }), { 0: o, length: u } = s;
910
+ if (u === 0)
911
+ throw new z();
912
+ if (u !== 1) {
913
+ const c = new oe(), f = this.#s;
914
+ throw c[Symbol.asyncIterator] = async function* () {
915
+ for (const l of s)
916
+ try {
917
+ yield await $(f, l, n);
918
+ } catch {
919
+ }
920
+ }, c;
921
+ }
922
+ return $(this.#s, o, n);
923
+ }
924
+ }
925
+ async function $(e, t, r) {
926
+ const n = e.get(t) || e.set(t, {}).get(t);
927
+ if (n[r] === void 0) {
928
+ const a = await we({ ...t, ext: !0 }, r);
929
+ if (a instanceof Uint8Array || a.type !== "public")
930
+ throw new G("JSON Web Key Set members must be public keys");
931
+ n[r] = a;
932
+ }
933
+ return n[r];
934
+ }
935
+ function F(e) {
936
+ const t = new ke(e), r = async (n, a) => t.getKey(n, a);
937
+ return Object.defineProperties(r, {
938
+ jwks: {
939
+ value: () => structuredClone(t.jwks()),
940
+ enumerable: !1,
941
+ configurable: !1,
942
+ writable: !1
943
+ }
944
+ }), r;
945
+ }
946
+ function Be() {
947
+ return typeof WebSocketPair < "u" || typeof navigator < "u" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime < "u" && EdgeRuntime === "vercel";
948
+ }
949
+ let D;
950
+ (typeof navigator > "u" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) && (D = "jose/v6.1.3");
951
+ const Ge = /* @__PURE__ */ Symbol();
952
+ async function ze(e, t, r, n = fetch) {
953
+ const a = await n(e, {
954
+ method: "GET",
955
+ signal: r,
956
+ redirect: "manual",
957
+ headers: t
958
+ }).catch((i) => {
959
+ throw i.name === "TimeoutError" ? new ce() : i;
960
+ });
961
+ if (a.status !== 200)
962
+ throw new h("Expected 200 OK from the JSON Web Key Set HTTP response");
963
+ try {
964
+ return await a.json();
965
+ } catch {
966
+ throw new h("Failed to parse the JSON Web Key Set HTTP response as JSON");
967
+ }
968
+ }
969
+ const _ = /* @__PURE__ */ Symbol();
970
+ function qe(e, t) {
971
+ return !(typeof e != "object" || e === null || !("uat" in e) || typeof e.uat != "number" || Date.now() - e.uat >= t || !("jwks" in e) || !w(e.jwks) || !Array.isArray(e.jwks.keys) || !Array.prototype.every.call(e.jwks.keys, w));
972
+ }
973
+ class Ye {
974
+ #r;
975
+ #s;
976
+ #c;
977
+ #o;
978
+ #n;
979
+ #e;
980
+ #t;
981
+ #f;
982
+ #a;
983
+ #i;
984
+ constructor(t, r) {
985
+ if (!(t instanceof URL))
986
+ throw new TypeError("url must be an instance of URL");
987
+ this.#r = new URL(t.href), this.#s = typeof r?.timeoutDuration == "number" ? r?.timeoutDuration : 5e3, this.#c = typeof r?.cooldownDuration == "number" ? r?.cooldownDuration : 3e4, this.#o = typeof r?.cacheMaxAge == "number" ? r?.cacheMaxAge : 6e5, this.#t = new Headers(r?.headers), D && !this.#t.has("User-Agent") && this.#t.set("User-Agent", D), this.#t.has("accept") || (this.#t.set("accept", "application/json"), this.#t.append("accept", "application/jwk-set+json")), this.#f = r?.[Ge], r?.[_] !== void 0 && (this.#i = r?.[_], qe(r?.[_], this.#o) && (this.#n = this.#i.uat, this.#a = F(this.#i.jwks)));
988
+ }
989
+ pendingFetch() {
990
+ return !!this.#e;
991
+ }
992
+ coolingDown() {
993
+ return typeof this.#n == "number" ? Date.now() < this.#n + this.#c : !1;
994
+ }
995
+ fresh() {
996
+ return typeof this.#n == "number" ? Date.now() < this.#n + this.#o : !1;
997
+ }
998
+ jwks() {
999
+ return this.#a?.jwks();
1000
+ }
1001
+ async getKey(t, r) {
1002
+ (!this.#a || !this.fresh()) && await this.reload();
1003
+ try {
1004
+ return await this.#a(t, r);
1005
+ } catch (n) {
1006
+ if (n instanceof z && this.coolingDown() === !1)
1007
+ return await this.reload(), this.#a(t, r);
1008
+ throw n;
1009
+ }
1010
+ }
1011
+ async reload() {
1012
+ this.#e && Be() && (this.#e = void 0), this.#e ||= ze(this.#r.href, this.#t, AbortSignal.timeout(this.#s), this.#f).then((t) => {
1013
+ this.#a = F(t), this.#i && (this.#i.uat = Date.now(), this.#i.jwks = t), this.#n = Date.now(), this.#e = void 0;
1014
+ }).catch((t) => {
1015
+ throw this.#e = void 0, t;
1016
+ }), await this.#e;
1017
+ }
1018
+ }
1019
+ function Xe(e, t) {
1020
+ const r = new Ye(e, t), n = async (a, i) => r.getKey(a, i);
1021
+ return Object.defineProperties(n, {
1022
+ coolingDown: {
1023
+ get: () => r.coolingDown(),
1024
+ enumerable: !0,
1025
+ configurable: !1
1026
+ },
1027
+ fresh: {
1028
+ get: () => r.fresh(),
1029
+ enumerable: !0,
1030
+ configurable: !1
1031
+ },
1032
+ reload: {
1033
+ value: () => r.reload(),
1034
+ enumerable: !0,
1035
+ configurable: !1,
1036
+ writable: !1
1037
+ },
1038
+ reloading: {
1039
+ get: () => r.pendingFetch(),
1040
+ enumerable: !0,
1041
+ configurable: !1
1042
+ },
1043
+ jwks: {
1044
+ value: () => r.jwks(),
1045
+ enumerable: !0,
1046
+ configurable: !1,
1047
+ writable: !1
1048
+ }
1049
+ }), n;
1050
+ }
1051
+ const nt = (e) => k().server(async ({
1052
+ next: t,
1053
+ request: r
1054
+ }) => {
1055
+ const n = r.headers.get("Authorization");
1056
+ if (!n?.startsWith("Bearer ")) throw new Error("Unauthorized: Missing access token or invalid Authorization header");
1057
+ const a = await Qe(n.substring(7)), i = {
1058
+ id: a.sub,
1059
+ name: a.name.split("/")[0],
1060
+ email: a.preferred_username.toLowerCase(),
1061
+ groups: a.groups ?? [],
1062
+ department: a.department || "",
1063
+ employeeId: a.employeeId || "",
1064
+ hasPermission: (s) => re[s].some((u) => (a.groups ?? []).includes(u))
1065
+ };
1066
+ if (!i.hasPermission(e)) throw new Error(`Forbidden: User ${i.name} is not authorized to access this resource`);
1067
+ return t({
1068
+ context: {
1069
+ user: i
1070
+ }
1071
+ });
1072
+ }), at = k({
1073
+ type: "function"
1074
+ }).client(async ({
1075
+ next: e
1076
+ }) => {
1077
+ const t = await ne("appstore");
1078
+ return e({
1079
+ headers: {
1080
+ Authorization: `Bearer ${t}`
1081
+ }
1082
+ });
1083
+ });
1084
+ async function Qe(e) {
1085
+ const {
1086
+ payload: t
1087
+ } = await Ue(e, Ze(), {
1088
+ issuer: `https://login.microsoftonline.com/${H.VITE_ENTRA_TENANT_ID}/v2.0`,
1089
+ audience: H.VITE_ENTRA_CLIENT_ID
1090
+ });
1091
+ return t;
1092
+ }
1093
+ let V = null;
1094
+ function Ze() {
1095
+ return V ??= Xe(new URL(`https://login.microsoftonline.com/${process.env.ENTRA_TENANT_ID}/discovery/v2.0/keys`)), V;
1096
+ }
1097
+ export {
1098
+ nt as authMiddleware,
1099
+ at as serverFnAccessTokenMiddleware
1100
+ };
1101
+ //# sourceMappingURL=middleware.js.map