@fluid-app/portal-sdk 0.1.101 → 0.1.103

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 (92) hide show
  1. package/dist/{AppDownloadScreen-rO--O0pk.mjs → AppDownloadScreen-BBpvNeFO.mjs} +2 -2
  2. package/dist/{AppDownloadScreen-rO--O0pk.mjs.map → AppDownloadScreen-BBpvNeFO.mjs.map} +1 -1
  3. package/dist/{AppDownloadScreen-BcK2snUL.cjs → AppDownloadScreen-Da79ffTK.cjs} +2 -2
  4. package/dist/{AppDownloadScreen-BcK2snUL.cjs.map → AppDownloadScreen-Da79ffTK.cjs.map} +1 -1
  5. package/dist/{AppDownloadScreen-CwLZzr-7.cjs → AppDownloadScreen-R3rcFWzL.cjs} +2 -2
  6. package/dist/{ContactsScreen-CkSeaPyz.cjs → ContactsScreen-CFC32ATZ.cjs} +2 -2
  7. package/dist/{ContactsScreen-CkSeaPyz.cjs.map → ContactsScreen-CFC32ATZ.cjs.map} +1 -1
  8. package/dist/{ContactsScreen-BGwqGlpV.mjs → ContactsScreen-CGyCNeZy.mjs} +2 -2
  9. package/dist/{ContactsScreen-BGwqGlpV.mjs.map → ContactsScreen-CGyCNeZy.mjs.map} +1 -1
  10. package/dist/{ContactsScreen-D4WQ59ib.cjs → ContactsScreen-D81raD2s.cjs} +2 -2
  11. package/dist/{FluidProvider-CWYquEIF.mjs → FluidProvider-B59bzF__.mjs} +118 -1131
  12. package/dist/FluidProvider-B59bzF__.mjs.map +1 -0
  13. package/dist/{FluidProvider-CyzA2g75.cjs → FluidProvider-DbYLBGGg.cjs} +119 -1210
  14. package/dist/FluidProvider-DbYLBGGg.cjs.map +1 -0
  15. package/dist/{MessagingScreen-CBuI3fu6.mjs → MessagingScreen-6SfuZqDC.mjs} +4 -9
  16. package/dist/MessagingScreen-6SfuZqDC.mjs.map +1 -0
  17. package/dist/{MessagingScreen-DKigg2jz.mjs → MessagingScreen-Bg-7zNye.mjs} +2 -2
  18. package/dist/{MessagingScreen-Cgx3jwpr.cjs → MessagingScreen-DsH-L7vB.cjs} +4 -9
  19. package/dist/MessagingScreen-DsH-L7vB.cjs.map +1 -0
  20. package/dist/{MessagingScreen-CGS7aG1A.cjs → MessagingScreen-TCOhXTPN.cjs} +2 -2
  21. package/dist/{MySiteScreen-BSFb-n7n.cjs → MySiteScreen-BHiMCIZ_.cjs} +2 -2
  22. package/dist/{MySiteScreen-BSFb-n7n.cjs.map → MySiteScreen-BHiMCIZ_.cjs.map} +1 -1
  23. package/dist/{MySiteScreen-Bvyx63pT.mjs → MySiteScreen-BI089vJc.mjs} +2 -2
  24. package/dist/{MySiteScreen-Bvyx63pT.mjs.map → MySiteScreen-BI089vJc.mjs.map} +1 -1
  25. package/dist/{MySiteScreen-2IzxVfpO.cjs → MySiteScreen-DDX4xcMv.cjs} +2 -2
  26. package/dist/{OrdersScreen-Bf4o3Kty.cjs → OrdersScreen-Cc6iUf0a.cjs} +3 -3
  27. package/dist/{OrdersScreen-Bf4o3Kty.cjs.map → OrdersScreen-Cc6iUf0a.cjs.map} +1 -1
  28. package/dist/{OrdersScreen-Djdeji9g.mjs → OrdersScreen-CdwVcUrG.mjs} +3 -3
  29. package/dist/{OrdersScreen-Djdeji9g.mjs.map → OrdersScreen-CdwVcUrG.mjs.map} +1 -1
  30. package/dist/{OrdersScreen-DCzYEgsP.cjs → OrdersScreen-CtG8_C45.cjs} +2 -2
  31. package/dist/{ProductsScreen-DZiugPVb.mjs → ProductsScreen-BZbpjY2G.mjs} +3 -3
  32. package/dist/{ProductsScreen-6J79mnIB.mjs → ProductsScreen-BcIiBPCz.mjs} +4 -4
  33. package/dist/{ProductsScreen-6J79mnIB.mjs.map → ProductsScreen-BcIiBPCz.mjs.map} +1 -1
  34. package/dist/{ProductsScreen-PJ95OcSX.cjs → ProductsScreen-W0uLKrfx.cjs} +4 -4
  35. package/dist/{ProductsScreen-PJ95OcSX.cjs.map → ProductsScreen-W0uLKrfx.cjs.map} +1 -1
  36. package/dist/{ProductsScreen-DZnKtPBp.cjs → ProductsScreen-eiMXiu0K.cjs} +3 -3
  37. package/dist/{ProfileScreen-CUsGRCB7.mjs → ProfileScreen-BEHwzWv1.mjs} +3 -3
  38. package/dist/{ProfileScreen-CUsGRCB7.mjs.map → ProfileScreen-BEHwzWv1.mjs.map} +1 -1
  39. package/dist/{ProfileScreen-DtmReqa8.cjs → ProfileScreen-CKuu4YAP.cjs} +3 -3
  40. package/dist/{ProfileScreen-DtmReqa8.cjs.map → ProfileScreen-CKuu4YAP.cjs.map} +1 -1
  41. package/dist/{ProfileScreen-B46jd4Ic.cjs → ProfileScreen-xD7FL-W6.cjs} +2 -2
  42. package/dist/{ShareablesScreen-Dk5EQGMa.cjs → ShareablesScreen-B_N1aWKn.cjs} +3 -3
  43. package/dist/{ShareablesScreen-DFAVIeqB.mjs → ShareablesScreen-Bvkd-M9u.mjs} +3 -3
  44. package/dist/{ShareablesScreen-CVT7u2hN.cjs → ShareablesScreen-M_f9a05D.cjs} +5 -5
  45. package/dist/{ShareablesScreen-CVT7u2hN.cjs.map → ShareablesScreen-M_f9a05D.cjs.map} +1 -1
  46. package/dist/{ShareablesScreen-Cy7w85IH.mjs → ShareablesScreen-Xf6w_Cri.mjs} +5 -5
  47. package/dist/{ShareablesScreen-Cy7w85IH.mjs.map → ShareablesScreen-Xf6w_Cri.mjs.map} +1 -1
  48. package/dist/{ShopScreen-AGvcqUii.mjs → ShopScreen-C9OVBv3h.mjs} +4 -4
  49. package/dist/{ShopScreen-AGvcqUii.mjs.map → ShopScreen-C9OVBv3h.mjs.map} +1 -1
  50. package/dist/{ShopScreen-DgBjP_8D.cjs → ShopScreen-CcNHTbVr.cjs} +4 -4
  51. package/dist/{ShopScreen-DgBjP_8D.cjs.map → ShopScreen-CcNHTbVr.cjs.map} +1 -1
  52. package/dist/{ShopScreen-wYtLEGXo.cjs → ShopScreen-Czot9O3w.cjs} +2 -2
  53. package/dist/{SubscriptionsScreen-C5YWtYfE.mjs → SubscriptionsScreen-BAwlzqnk.mjs} +3 -3
  54. package/dist/{SubscriptionsScreen-C5YWtYfE.mjs.map → SubscriptionsScreen-BAwlzqnk.mjs.map} +1 -1
  55. package/dist/{SubscriptionsScreen-BrLlvFJn.cjs → SubscriptionsScreen-BDtmlP7D.cjs} +3 -3
  56. package/dist/{SubscriptionsScreen-BrLlvFJn.cjs.map → SubscriptionsScreen-BDtmlP7D.cjs.map} +1 -1
  57. package/dist/{SubscriptionsScreen-BqOb2kYR.cjs → SubscriptionsScreen-De15MoiH.cjs} +2 -2
  58. package/dist/index.cjs +53 -54
  59. package/dist/index.cjs.map +1 -1
  60. package/dist/index.d.cts +52 -41
  61. package/dist/index.d.cts.map +1 -1
  62. package/dist/index.d.mts +52 -41
  63. package/dist/index.d.mts.map +1 -1
  64. package/dist/index.mjs +53 -54
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/{src-BrwLqPPh.mjs → src-DjlwUaws.mjs} +40 -12
  67. package/dist/src-DjlwUaws.mjs.map +1 -0
  68. package/dist/{src-Dlsw83js.cjs → src-xEfkv04t.cjs} +40 -12
  69. package/dist/src-xEfkv04t.cjs.map +1 -0
  70. package/dist/{use-account-clients-Dsqx0mKw.mjs → use-account-clients-BbT2Gfi8.mjs} +2 -2
  71. package/dist/{use-account-clients-Dsqx0mKw.mjs.map → use-account-clients-BbT2Gfi8.mjs.map} +1 -1
  72. package/dist/{use-account-clients-CkDfPpCR.cjs → use-account-clients-FORfQTn6.cjs} +2 -2
  73. package/dist/{use-account-clients-CkDfPpCR.cjs.map → use-account-clients-FORfQTn6.cjs.map} +1 -1
  74. package/dist/{use-current-user-LLJ1GtNB.cjs → use-current-user-CrHH290V.cjs} +3 -3
  75. package/dist/{use-current-user-LLJ1GtNB.cjs.map → use-current-user-CrHH290V.cjs.map} +1 -1
  76. package/dist/{use-current-user-BMI-LR9t.mjs → use-current-user-SmbdS--3.mjs} +3 -3
  77. package/dist/{use-current-user-BMI-LR9t.mjs.map → use-current-user-SmbdS--3.mjs.map} +1 -1
  78. package/dist/{use-customer-account-DzOD3vLz.mjs → use-customer-account-CXOgxyNX.mjs} +3 -3
  79. package/dist/{use-customer-account-DzOD3vLz.mjs.map → use-customer-account-CXOgxyNX.mjs.map} +1 -1
  80. package/dist/{use-customer-account-DZW_YY9d.cjs → use-customer-account-DJiCXIoH.cjs} +3 -3
  81. package/dist/{use-customer-account-DZW_YY9d.cjs.map → use-customer-account-DJiCXIoH.cjs.map} +1 -1
  82. package/dist/{use-fluid-api-Kw0AKvCs.cjs → use-fluid-api-C2evcv_D.cjs} +2 -2
  83. package/dist/{use-fluid-api-Kw0AKvCs.cjs.map → use-fluid-api-C2evcv_D.cjs.map} +1 -1
  84. package/dist/{use-fluid-api-CaSYWFuj.mjs → use-fluid-api-f1PKU6dS.mjs} +2 -2
  85. package/dist/{use-fluid-api-CaSYWFuj.mjs.map → use-fluid-api-f1PKU6dS.mjs.map} +1 -1
  86. package/package.json +8 -8
  87. package/dist/FluidProvider-CWYquEIF.mjs.map +0 -1
  88. package/dist/FluidProvider-CyzA2g75.cjs.map +0 -1
  89. package/dist/MessagingScreen-CBuI3fu6.mjs.map +0 -1
  90. package/dist/MessagingScreen-Cgx3jwpr.cjs.map +0 -1
  91. package/dist/src-BrwLqPPh.mjs.map +0 -1
  92. package/dist/src-Dlsw83js.cjs.map +0 -1
@@ -55,7 +55,7 @@ var ApiError$1 = class ApiError$1 extends Error {
55
55
  * Creates a configured fetch client instance
56
56
  */
57
57
  function createFetchClient(config) {
58
- const { baseUrl, getAuthToken, onAuthError, defaultHeaders = {} } = config;
58
+ const { baseUrl, getAuthToken, onAuthError, defaultHeaders = {}, credentials } = config;
59
59
  /**
60
60
  * Build headers for a request
61
61
  */
@@ -144,6 +144,7 @@ function createFetchClient(config) {
144
144
  method,
145
145
  headers
146
146
  };
147
+ if (credentials) fetchOptions.credentials = credentials;
147
148
  const serializedBody = body && method !== "GET" ? JSON.stringify(body) : null;
148
149
  if (serializedBody) fetchOptions.body = serializedBody;
149
150
  if (signal) fetchOptions.signal = signal;
@@ -168,6 +169,7 @@ function createFetchClient(config) {
168
169
  headers,
169
170
  body: formData
170
171
  };
172
+ if (credentials) fetchOptions.credentials = credentials;
171
173
  if (signal) fetchOptions.signal = signal;
172
174
  response = await fetch(url, fetchOptions);
173
175
  } catch (networkError) {
@@ -1140,24 +1142,8 @@ const URL_PARAMS = {
1140
1142
  function isBrowser() {
1141
1143
  return typeof window !== "undefined" && typeof document !== "undefined";
1142
1144
  }
1143
- //#endregion
1144
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/webcrypto.js
1145
- var webcrypto_default = crypto;
1146
- const isCryptoKey = (key) => key instanceof CryptoKey;
1147
- //#endregion
1148
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/buffer_utils.js
1149
- const encoder = new TextEncoder();
1145
+ new TextEncoder();
1150
1146
  const decoder = new TextDecoder();
1151
- function concat(...buffers) {
1152
- const size = buffers.reduce((acc, { length }) => acc + length, 0);
1153
- const buf = new Uint8Array(size);
1154
- let i = 0;
1155
- for (const buffer of buffers) {
1156
- buf.set(buffer, i);
1157
- i += buffer.length;
1158
- }
1159
- return buf;
1160
- }
1161
1147
  const decodeBase64 = (encoded) => {
1162
1148
  const binary = atob(encoded);
1163
1149
  const bytes = new Uint8Array(binary.length);
@@ -1298,128 +1284,6 @@ var JWSSignatureVerificationFailed = class extends JOSEError {
1298
1284
  };
1299
1285
  JWSSignatureVerificationFailed.code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
1300
1286
  //#endregion
1301
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/crypto_key.js
1302
- function unusable(name, prop = "algorithm.name") {
1303
- return /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
1304
- }
1305
- function isAlgorithm(algorithm, name) {
1306
- return algorithm.name === name;
1307
- }
1308
- function getHashLength(hash) {
1309
- return parseInt(hash.name.slice(4), 10);
1310
- }
1311
- function getNamedCurve(alg) {
1312
- switch (alg) {
1313
- case "ES256": return "P-256";
1314
- case "ES384": return "P-384";
1315
- case "ES512": return "P-521";
1316
- default: throw new Error("unreachable");
1317
- }
1318
- }
1319
- function checkUsage(key, usages) {
1320
- if (usages.length && !usages.some((expected) => key.usages.includes(expected))) {
1321
- let msg = "CryptoKey does not support this operation, its usages must include ";
1322
- if (usages.length > 2) {
1323
- const last = usages.pop();
1324
- msg += `one of ${usages.join(", ")}, or ${last}.`;
1325
- } else if (usages.length === 2) msg += `one of ${usages[0]} or ${usages[1]}.`;
1326
- else msg += `${usages[0]}.`;
1327
- throw new TypeError(msg);
1328
- }
1329
- }
1330
- function checkSigCryptoKey(key, alg, ...usages) {
1331
- switch (alg) {
1332
- case "HS256":
1333
- case "HS384":
1334
- case "HS512": {
1335
- if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
1336
- const expected = parseInt(alg.slice(2), 10);
1337
- if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
1338
- break;
1339
- }
1340
- case "RS256":
1341
- case "RS384":
1342
- case "RS512": {
1343
- if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
1344
- const expected = parseInt(alg.slice(2), 10);
1345
- if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
1346
- break;
1347
- }
1348
- case "PS256":
1349
- case "PS384":
1350
- case "PS512": {
1351
- if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
1352
- const expected = parseInt(alg.slice(2), 10);
1353
- if (getHashLength(key.algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
1354
- break;
1355
- }
1356
- case "EdDSA":
1357
- if (key.algorithm.name !== "Ed25519" && key.algorithm.name !== "Ed448") throw unusable("Ed25519 or Ed448");
1358
- break;
1359
- case "Ed25519":
1360
- if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
1361
- break;
1362
- case "ES256":
1363
- case "ES384":
1364
- case "ES512": {
1365
- if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
1366
- const expected = getNamedCurve(alg);
1367
- if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
1368
- break;
1369
- }
1370
- default: throw new TypeError("CryptoKey does not support this operation");
1371
- }
1372
- checkUsage(key, usages);
1373
- }
1374
- //#endregion
1375
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/invalid_key_input.js
1376
- function message(msg, actual, ...types) {
1377
- types = types.filter(Boolean);
1378
- if (types.length > 2) {
1379
- const last = types.pop();
1380
- msg += `one of type ${types.join(", ")}, or ${last}.`;
1381
- } else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
1382
- else msg += `of type ${types[0]}.`;
1383
- if (actual == null) msg += ` Received ${actual}`;
1384
- else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
1385
- else if (typeof actual === "object" && actual != null) {
1386
- if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
1387
- }
1388
- return msg;
1389
- }
1390
- var invalid_key_input_default = (actual, ...types) => {
1391
- return message("Key must be ", actual, ...types);
1392
- };
1393
- function withAlg(alg, actual, ...types) {
1394
- return message(`Key for the ${alg} algorithm must be `, actual, ...types);
1395
- }
1396
- //#endregion
1397
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/is_key_like.js
1398
- var is_key_like_default = (key) => {
1399
- if (isCryptoKey(key)) return true;
1400
- return key?.[Symbol.toStringTag] === "KeyObject";
1401
- };
1402
- const types = ["CryptoKey"];
1403
- //#endregion
1404
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/is_disjoint.js
1405
- const isDisjoint = (...headers) => {
1406
- const sources = headers.filter(Boolean);
1407
- if (sources.length === 0 || sources.length === 1) return true;
1408
- let acc;
1409
- for (const header of sources) {
1410
- const parameters = Object.keys(header);
1411
- if (!acc || acc.size === 0) {
1412
- acc = new Set(parameters);
1413
- continue;
1414
- }
1415
- for (const parameter of parameters) {
1416
- if (acc.has(parameter)) return false;
1417
- acc.add(parameter);
1418
- }
1419
- }
1420
- return true;
1421
- };
1422
- //#endregion
1423
1287
  //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/is_object.js
1424
1288
  function isObjectLike(value) {
1425
1289
  return typeof value === "object" && value !== null;
@@ -1431,802 +1295,6 @@ function isObject(input) {
1431
1295
  while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
1432
1296
  return Object.getPrototypeOf(input) === proto;
1433
1297
  }
1434
- //#endregion
1435
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/check_key_length.js
1436
- var check_key_length_default = (alg, key) => {
1437
- if (alg.startsWith("RS") || alg.startsWith("PS")) {
1438
- const { modulusLength } = key.algorithm;
1439
- if (typeof modulusLength !== "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
1440
- }
1441
- };
1442
- //#endregion
1443
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/is_jwk.js
1444
- function isJWK(key) {
1445
- return isObject(key) && typeof key.kty === "string";
1446
- }
1447
- function isPrivateJWK(key) {
1448
- return key.kty !== "oct" && typeof key.d === "string";
1449
- }
1450
- function isPublicJWK(key) {
1451
- return key.kty !== "oct" && typeof key.d === "undefined";
1452
- }
1453
- function isSecretJWK(key) {
1454
- return isJWK(key) && key.kty === "oct" && typeof key.k === "string";
1455
- }
1456
- //#endregion
1457
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/jwk_to_key.js
1458
- function subtleMapping(jwk) {
1459
- let algorithm;
1460
- let keyUsages;
1461
- switch (jwk.kty) {
1462
- case "RSA":
1463
- switch (jwk.alg) {
1464
- case "PS256":
1465
- case "PS384":
1466
- case "PS512":
1467
- algorithm = {
1468
- name: "RSA-PSS",
1469
- hash: `SHA-${jwk.alg.slice(-3)}`
1470
- };
1471
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1472
- break;
1473
- case "RS256":
1474
- case "RS384":
1475
- case "RS512":
1476
- algorithm = {
1477
- name: "RSASSA-PKCS1-v1_5",
1478
- hash: `SHA-${jwk.alg.slice(-3)}`
1479
- };
1480
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1481
- break;
1482
- case "RSA-OAEP":
1483
- case "RSA-OAEP-256":
1484
- case "RSA-OAEP-384":
1485
- case "RSA-OAEP-512":
1486
- algorithm = {
1487
- name: "RSA-OAEP",
1488
- hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
1489
- };
1490
- keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
1491
- break;
1492
- default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
1493
- }
1494
- break;
1495
- case "EC":
1496
- switch (jwk.alg) {
1497
- case "ES256":
1498
- algorithm = {
1499
- name: "ECDSA",
1500
- namedCurve: "P-256"
1501
- };
1502
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1503
- break;
1504
- case "ES384":
1505
- algorithm = {
1506
- name: "ECDSA",
1507
- namedCurve: "P-384"
1508
- };
1509
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1510
- break;
1511
- case "ES512":
1512
- algorithm = {
1513
- name: "ECDSA",
1514
- namedCurve: "P-521"
1515
- };
1516
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1517
- break;
1518
- case "ECDH-ES":
1519
- case "ECDH-ES+A128KW":
1520
- case "ECDH-ES+A192KW":
1521
- case "ECDH-ES+A256KW":
1522
- algorithm = {
1523
- name: "ECDH",
1524
- namedCurve: jwk.crv
1525
- };
1526
- keyUsages = jwk.d ? ["deriveBits"] : [];
1527
- break;
1528
- default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
1529
- }
1530
- break;
1531
- case "OKP":
1532
- switch (jwk.alg) {
1533
- case "Ed25519":
1534
- algorithm = { name: "Ed25519" };
1535
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1536
- break;
1537
- case "EdDSA":
1538
- algorithm = { name: jwk.crv };
1539
- keyUsages = jwk.d ? ["sign"] : ["verify"];
1540
- break;
1541
- case "ECDH-ES":
1542
- case "ECDH-ES+A128KW":
1543
- case "ECDH-ES+A192KW":
1544
- case "ECDH-ES+A256KW":
1545
- algorithm = { name: jwk.crv };
1546
- keyUsages = jwk.d ? ["deriveBits"] : [];
1547
- break;
1548
- default: throw new JOSENotSupported("Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value");
1549
- }
1550
- break;
1551
- default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
1552
- }
1553
- return {
1554
- algorithm,
1555
- keyUsages
1556
- };
1557
- }
1558
- const parse = async (jwk) => {
1559
- if (!jwk.alg) throw new TypeError("\"alg\" argument is required when \"jwk.alg\" is not present");
1560
- const { algorithm, keyUsages } = subtleMapping(jwk);
1561
- const rest = [
1562
- algorithm,
1563
- jwk.ext ?? false,
1564
- jwk.key_ops ?? keyUsages
1565
- ];
1566
- const keyData = { ...jwk };
1567
- delete keyData.alg;
1568
- delete keyData.use;
1569
- return webcrypto_default.subtle.importKey("jwk", keyData, ...rest);
1570
- };
1571
- //#endregion
1572
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/normalize_key.js
1573
- const exportKeyValue = (k) => decode$1(k);
1574
- let privCache;
1575
- let pubCache;
1576
- const isKeyObject = (key) => {
1577
- return key?.[Symbol.toStringTag] === "KeyObject";
1578
- };
1579
- const importAndCache = async (cache, key, jwk, alg, freeze = false) => {
1580
- let cached = cache.get(key);
1581
- if (cached?.[alg]) return cached[alg];
1582
- const cryptoKey = await parse({
1583
- ...jwk,
1584
- alg
1585
- });
1586
- if (freeze) Object.freeze(key);
1587
- if (!cached) cache.set(key, { [alg]: cryptoKey });
1588
- else cached[alg] = cryptoKey;
1589
- return cryptoKey;
1590
- };
1591
- const normalizePublicKey = (key, alg) => {
1592
- if (isKeyObject(key)) {
1593
- let jwk = key.export({ format: "jwk" });
1594
- delete jwk.d;
1595
- delete jwk.dp;
1596
- delete jwk.dq;
1597
- delete jwk.p;
1598
- delete jwk.q;
1599
- delete jwk.qi;
1600
- if (jwk.k) return exportKeyValue(jwk.k);
1601
- pubCache || (pubCache = /* @__PURE__ */ new WeakMap());
1602
- return importAndCache(pubCache, key, jwk, alg);
1603
- }
1604
- if (isJWK(key)) {
1605
- if (key.k) return decode$1(key.k);
1606
- pubCache || (pubCache = /* @__PURE__ */ new WeakMap());
1607
- return importAndCache(pubCache, key, key, alg, true);
1608
- }
1609
- return key;
1610
- };
1611
- const normalizePrivateKey = (key, alg) => {
1612
- if (isKeyObject(key)) {
1613
- let jwk = key.export({ format: "jwk" });
1614
- if (jwk.k) return exportKeyValue(jwk.k);
1615
- privCache || (privCache = /* @__PURE__ */ new WeakMap());
1616
- return importAndCache(privCache, key, jwk, alg);
1617
- }
1618
- if (isJWK(key)) {
1619
- if (key.k) return decode$1(key.k);
1620
- privCache || (privCache = /* @__PURE__ */ new WeakMap());
1621
- return importAndCache(privCache, key, key, alg, true);
1622
- }
1623
- return key;
1624
- };
1625
- var normalize_key_default = {
1626
- normalizePublicKey,
1627
- normalizePrivateKey
1628
- };
1629
- //#endregion
1630
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/key/import.js
1631
- async function importJWK(jwk, alg) {
1632
- if (!isObject(jwk)) throw new TypeError("JWK must be an object");
1633
- alg || (alg = jwk.alg);
1634
- switch (jwk.kty) {
1635
- case "oct":
1636
- if (typeof jwk.k !== "string" || !jwk.k) throw new TypeError("missing \"k\" (Key Value) Parameter value");
1637
- return decode$1(jwk.k);
1638
- case "RSA": if ("oth" in jwk && jwk.oth !== void 0) throw new JOSENotSupported("RSA JWK \"oth\" (Other Primes Info) Parameter value is not supported");
1639
- case "EC":
1640
- case "OKP": return parse({
1641
- ...jwk,
1642
- alg
1643
- });
1644
- default: throw new JOSENotSupported("Unsupported \"kty\" (Key Type) Parameter value");
1645
- }
1646
- }
1647
- //#endregion
1648
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/check_key_type.js
1649
- const tag = (key) => key?.[Symbol.toStringTag];
1650
- const jwkMatchesOp = (alg, key, usage) => {
1651
- if (key.use !== void 0 && key.use !== "sig") throw new TypeError("Invalid key for this operation, when present its use must be sig");
1652
- if (key.key_ops !== void 0 && key.key_ops.includes?.(usage) !== true) throw new TypeError(`Invalid key for this operation, when present its key_ops must include ${usage}`);
1653
- if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, when present its alg must be ${alg}`);
1654
- return true;
1655
- };
1656
- const symmetricTypeCheck = (alg, key, usage, allowJwk) => {
1657
- if (key instanceof Uint8Array) return;
1658
- if (allowJwk && isJWK(key)) {
1659
- if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage)) return;
1660
- 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`);
1661
- }
1662
- if (!is_key_like_default(key)) throw new TypeError(withAlg(alg, key, ...types, "Uint8Array", allowJwk ? "JSON Web Key" : null));
1663
- if (key.type !== "secret") throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
1664
- };
1665
- const asymmetricTypeCheck = (alg, key, usage, allowJwk) => {
1666
- if (allowJwk && isJWK(key)) switch (usage) {
1667
- case "sign":
1668
- if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage)) return;
1669
- throw new TypeError(`JSON Web Key for this operation be a private JWK`);
1670
- case "verify":
1671
- if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage)) return;
1672
- throw new TypeError(`JSON Web Key for this operation be a public JWK`);
1673
- }
1674
- if (!is_key_like_default(key)) throw new TypeError(withAlg(alg, key, ...types, allowJwk ? "JSON Web Key" : null));
1675
- if (key.type === "secret") throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
1676
- if (usage === "sign" && key.type === "public") throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
1677
- if (usage === "decrypt" && key.type === "public") throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
1678
- if (key.algorithm && usage === "verify" && key.type === "private") throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
1679
- if (key.algorithm && usage === "encrypt" && key.type === "private") throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
1680
- };
1681
- function checkKeyType(allowJwk, alg, key, usage) {
1682
- if (alg.startsWith("HS") || alg === "dir" || alg.startsWith("PBES2") || /^A\d{3}(?:GCM)?KW$/.test(alg)) symmetricTypeCheck(alg, key, usage, allowJwk);
1683
- else asymmetricTypeCheck(alg, key, usage, allowJwk);
1684
- }
1685
- checkKeyType.bind(void 0, false);
1686
- const checkKeyTypeWithJwk = checkKeyType.bind(void 0, true);
1687
- //#endregion
1688
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/validate_crit.js
1689
- function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
1690
- if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
1691
- if (!protectedHeader || protectedHeader.crit === void 0) return /* @__PURE__ */ new Set();
1692
- if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
1693
- let recognized;
1694
- if (recognizedOption !== void 0) recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
1695
- else recognized = recognizedDefault;
1696
- for (const parameter of protectedHeader.crit) {
1697
- if (!recognized.has(parameter)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
1698
- if (joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
1699
- if (recognized.get(parameter) && protectedHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
1700
- }
1701
- return new Set(protectedHeader.crit);
1702
- }
1703
- //#endregion
1704
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/validate_algorithms.js
1705
- const validateAlgorithms = (option, algorithms) => {
1706
- if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) throw new TypeError(`"${option}" option must be an array of strings`);
1707
- if (!algorithms) return;
1708
- return new Set(algorithms);
1709
- };
1710
- //#endregion
1711
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/subtle_dsa.js
1712
- function subtleDsa(alg, algorithm) {
1713
- const hash = `SHA-${alg.slice(-3)}`;
1714
- switch (alg) {
1715
- case "HS256":
1716
- case "HS384":
1717
- case "HS512": return {
1718
- hash,
1719
- name: "HMAC"
1720
- };
1721
- case "PS256":
1722
- case "PS384":
1723
- case "PS512": return {
1724
- hash,
1725
- name: "RSA-PSS",
1726
- saltLength: alg.slice(-3) >> 3
1727
- };
1728
- case "RS256":
1729
- case "RS384":
1730
- case "RS512": return {
1731
- hash,
1732
- name: "RSASSA-PKCS1-v1_5"
1733
- };
1734
- case "ES256":
1735
- case "ES384":
1736
- case "ES512": return {
1737
- hash,
1738
- name: "ECDSA",
1739
- namedCurve: algorithm.namedCurve
1740
- };
1741
- case "Ed25519": return { name: "Ed25519" };
1742
- case "EdDSA": return { name: algorithm.name };
1743
- default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
1744
- }
1745
- }
1746
- //#endregion
1747
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/get_sign_verify_key.js
1748
- async function getCryptoKey(alg, key, usage) {
1749
- if (usage === "sign") key = await normalize_key_default.normalizePrivateKey(key, alg);
1750
- if (usage === "verify") key = await normalize_key_default.normalizePublicKey(key, alg);
1751
- if (isCryptoKey(key)) {
1752
- checkSigCryptoKey(key, alg, usage);
1753
- return key;
1754
- }
1755
- if (key instanceof Uint8Array) {
1756
- if (!alg.startsWith("HS")) throw new TypeError(invalid_key_input_default(key, ...types));
1757
- return webcrypto_default.subtle.importKey("raw", key, {
1758
- hash: `SHA-${alg.slice(-3)}`,
1759
- name: "HMAC"
1760
- }, false, [usage]);
1761
- }
1762
- throw new TypeError(invalid_key_input_default(key, ...types, "Uint8Array", "JSON Web Key"));
1763
- }
1764
- //#endregion
1765
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/verify.js
1766
- const verify = async (alg, key, signature, data) => {
1767
- const cryptoKey = await getCryptoKey(alg, key, "verify");
1768
- check_key_length_default(alg, cryptoKey);
1769
- const algorithm = subtleDsa(alg, cryptoKey.algorithm);
1770
- try {
1771
- return await webcrypto_default.subtle.verify(algorithm, cryptoKey, signature, data);
1772
- } catch {
1773
- return false;
1774
- }
1775
- };
1776
- //#endregion
1777
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/jws/flattened/verify.js
1778
- async function flattenedVerify(jws, key, options) {
1779
- if (!isObject(jws)) throw new JWSInvalid("Flattened JWS must be an object");
1780
- if (jws.protected === void 0 && jws.header === void 0) throw new JWSInvalid("Flattened JWS must have either of the \"protected\" or \"header\" members");
1781
- if (jws.protected !== void 0 && typeof jws.protected !== "string") throw new JWSInvalid("JWS Protected Header incorrect type");
1782
- if (jws.payload === void 0) throw new JWSInvalid("JWS Payload missing");
1783
- if (typeof jws.signature !== "string") throw new JWSInvalid("JWS Signature missing or incorrect type");
1784
- if (jws.header !== void 0 && !isObject(jws.header)) throw new JWSInvalid("JWS Unprotected Header incorrect type");
1785
- let parsedProt = {};
1786
- if (jws.protected) try {
1787
- const protectedHeader = decode$1(jws.protected);
1788
- parsedProt = JSON.parse(decoder.decode(protectedHeader));
1789
- } catch {
1790
- throw new JWSInvalid("JWS Protected Header is invalid");
1791
- }
1792
- if (!isDisjoint(parsedProt, jws.header)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
1793
- const joseHeader = {
1794
- ...parsedProt,
1795
- ...jws.header
1796
- };
1797
- const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
1798
- let b64 = true;
1799
- if (extensions.has("b64")) {
1800
- b64 = parsedProt.b64;
1801
- if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
1802
- }
1803
- const { alg } = joseHeader;
1804
- if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
1805
- const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
1806
- if (algorithms && !algorithms.has(alg)) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
1807
- if (b64) {
1808
- if (typeof jws.payload !== "string") throw new JWSInvalid("JWS Payload must be a string");
1809
- } else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
1810
- let resolvedKey = false;
1811
- if (typeof key === "function") {
1812
- key = await key(parsedProt, jws);
1813
- resolvedKey = true;
1814
- checkKeyTypeWithJwk(alg, key, "verify");
1815
- if (isJWK(key)) key = await importJWK(key, alg);
1816
- } else checkKeyTypeWithJwk(alg, key, "verify");
1817
- const data = concat(encoder.encode(jws.protected ?? ""), encoder.encode("."), typeof jws.payload === "string" ? encoder.encode(jws.payload) : jws.payload);
1818
- let signature;
1819
- try {
1820
- signature = decode$1(jws.signature);
1821
- } catch {
1822
- throw new JWSInvalid("Failed to base64url decode the signature");
1823
- }
1824
- if (!await verify(alg, key, signature, data)) throw new JWSSignatureVerificationFailed();
1825
- let payload;
1826
- if (b64) try {
1827
- payload = decode$1(jws.payload);
1828
- } catch {
1829
- throw new JWSInvalid("Failed to base64url decode the payload");
1830
- }
1831
- else if (typeof jws.payload === "string") payload = encoder.encode(jws.payload);
1832
- else payload = jws.payload;
1833
- const result = { payload };
1834
- if (jws.protected !== void 0) result.protectedHeader = parsedProt;
1835
- if (jws.header !== void 0) result.unprotectedHeader = jws.header;
1836
- if (resolvedKey) return {
1837
- ...result,
1838
- key
1839
- };
1840
- return result;
1841
- }
1842
- //#endregion
1843
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/jws/compact/verify.js
1844
- async function compactVerify(jws, key, options) {
1845
- if (jws instanceof Uint8Array) jws = decoder.decode(jws);
1846
- if (typeof jws !== "string") throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
1847
- const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
1848
- if (length !== 3) throw new JWSInvalid("Invalid Compact JWS");
1849
- const verified = await flattenedVerify({
1850
- payload,
1851
- protected: protectedHeader,
1852
- signature
1853
- }, key, options);
1854
- const result = {
1855
- payload: verified.payload,
1856
- protectedHeader: verified.protectedHeader
1857
- };
1858
- if (typeof key === "function") return {
1859
- ...result,
1860
- key: verified.key
1861
- };
1862
- return result;
1863
- }
1864
- //#endregion
1865
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/epoch.js
1866
- var epoch_default = (date) => Math.floor(date.getTime() / 1e3);
1867
- //#endregion
1868
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/secs.js
1869
- const minute = 60;
1870
- const hour = minute * 60;
1871
- const day = hour * 24;
1872
- const week = day * 7;
1873
- const year = day * 365.25;
1874
- const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
1875
- var secs_default = (str) => {
1876
- const matched = REGEX.exec(str);
1877
- if (!matched || matched[4] && matched[1]) throw new TypeError("Invalid time period format");
1878
- const value = parseFloat(matched[2]);
1879
- const unit = matched[3].toLowerCase();
1880
- let numericDate;
1881
- switch (unit) {
1882
- case "sec":
1883
- case "secs":
1884
- case "second":
1885
- case "seconds":
1886
- case "s":
1887
- numericDate = Math.round(value);
1888
- break;
1889
- case "minute":
1890
- case "minutes":
1891
- case "min":
1892
- case "mins":
1893
- case "m":
1894
- numericDate = Math.round(value * minute);
1895
- break;
1896
- case "hour":
1897
- case "hours":
1898
- case "hr":
1899
- case "hrs":
1900
- case "h":
1901
- numericDate = Math.round(value * hour);
1902
- break;
1903
- case "day":
1904
- case "days":
1905
- case "d":
1906
- numericDate = Math.round(value * day);
1907
- break;
1908
- case "week":
1909
- case "weeks":
1910
- case "w":
1911
- numericDate = Math.round(value * week);
1912
- break;
1913
- default:
1914
- numericDate = Math.round(value * year);
1915
- break;
1916
- }
1917
- if (matched[1] === "-" || matched[4] === "ago") return -numericDate;
1918
- return numericDate;
1919
- };
1920
- //#endregion
1921
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/lib/jwt_claims_set.js
1922
- const normalizeTyp = (value) => value.toLowerCase().replace(/^application\//, "");
1923
- const checkAudiencePresence = (audPayload, audOption) => {
1924
- if (typeof audPayload === "string") return audOption.includes(audPayload);
1925
- if (Array.isArray(audPayload)) return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
1926
- return false;
1927
- };
1928
- var jwt_claims_set_default = (protectedHeader, encodedPayload, options = {}) => {
1929
- let payload;
1930
- try {
1931
- payload = JSON.parse(decoder.decode(encodedPayload));
1932
- } catch {}
1933
- if (!isObject(payload)) throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
1934
- const { typ } = options;
1935
- if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) throw new JWTClaimValidationFailed("unexpected \"typ\" JWT header value", payload, "typ", "check_failed");
1936
- const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
1937
- const presenceCheck = [...requiredClaims];
1938
- if (maxTokenAge !== void 0) presenceCheck.push("iat");
1939
- if (audience !== void 0) presenceCheck.push("aud");
1940
- if (subject !== void 0) presenceCheck.push("sub");
1941
- if (issuer !== void 0) presenceCheck.push("iss");
1942
- for (const claim of new Set(presenceCheck.reverse())) if (!(claim in payload)) throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
1943
- if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) throw new JWTClaimValidationFailed("unexpected \"iss\" claim value", payload, "iss", "check_failed");
1944
- if (subject && payload.sub !== subject) throw new JWTClaimValidationFailed("unexpected \"sub\" claim value", payload, "sub", "check_failed");
1945
- if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) throw new JWTClaimValidationFailed("unexpected \"aud\" claim value", payload, "aud", "check_failed");
1946
- let tolerance;
1947
- switch (typeof options.clockTolerance) {
1948
- case "string":
1949
- tolerance = secs_default(options.clockTolerance);
1950
- break;
1951
- case "number":
1952
- tolerance = options.clockTolerance;
1953
- break;
1954
- case "undefined":
1955
- tolerance = 0;
1956
- break;
1957
- default: throw new TypeError("Invalid clockTolerance option type");
1958
- }
1959
- const { currentDate } = options;
1960
- const now = epoch_default(currentDate || /* @__PURE__ */ new Date());
1961
- if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") throw new JWTClaimValidationFailed("\"iat\" claim must be a number", payload, "iat", "invalid");
1962
- if (payload.nbf !== void 0) {
1963
- if (typeof payload.nbf !== "number") throw new JWTClaimValidationFailed("\"nbf\" claim must be a number", payload, "nbf", "invalid");
1964
- if (payload.nbf > now + tolerance) throw new JWTClaimValidationFailed("\"nbf\" claim timestamp check failed", payload, "nbf", "check_failed");
1965
- }
1966
- if (payload.exp !== void 0) {
1967
- if (typeof payload.exp !== "number") throw new JWTClaimValidationFailed("\"exp\" claim must be a number", payload, "exp", "invalid");
1968
- if (payload.exp <= now - tolerance) throw new JWTExpired("\"exp\" claim timestamp check failed", payload, "exp", "check_failed");
1969
- }
1970
- if (maxTokenAge) {
1971
- const age = now - payload.iat;
1972
- const max = typeof maxTokenAge === "number" ? maxTokenAge : secs_default(maxTokenAge);
1973
- if (age - tolerance > max) throw new JWTExpired("\"iat\" claim timestamp check failed (too far in the past)", payload, "iat", "check_failed");
1974
- if (age < 0 - tolerance) throw new JWTClaimValidationFailed("\"iat\" claim timestamp check failed (it should be in the past)", payload, "iat", "check_failed");
1975
- }
1976
- return payload;
1977
- };
1978
- //#endregion
1979
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/jwt/verify.js
1980
- async function jwtVerify(jwt, key, options) {
1981
- const verified = await compactVerify(jwt, key, options);
1982
- if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
1983
- const result = {
1984
- payload: jwt_claims_set_default(verified.protectedHeader, verified.payload, options),
1985
- protectedHeader: verified.protectedHeader
1986
- };
1987
- if (typeof key === "function") return {
1988
- ...result,
1989
- key: verified.key
1990
- };
1991
- return result;
1992
- }
1993
- //#endregion
1994
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/jwks/local.js
1995
- function getKtyFromAlg(alg) {
1996
- switch (typeof alg === "string" && alg.slice(0, 2)) {
1997
- case "RS":
1998
- case "PS": return "RSA";
1999
- case "ES": return "EC";
2000
- case "Ed": return "OKP";
2001
- default: throw new JOSENotSupported("Unsupported \"alg\" value for a JSON Web Key Set");
2002
- }
2003
- }
2004
- function isJWKSLike(jwks) {
2005
- return jwks && typeof jwks === "object" && Array.isArray(jwks.keys) && jwks.keys.every(isJWKLike);
2006
- }
2007
- function isJWKLike(key) {
2008
- return isObject(key);
2009
- }
2010
- function clone(obj) {
2011
- if (typeof structuredClone === "function") return structuredClone(obj);
2012
- return JSON.parse(JSON.stringify(obj));
2013
- }
2014
- var LocalJWKSet = class {
2015
- constructor(jwks) {
2016
- this._cached = /* @__PURE__ */ new WeakMap();
2017
- if (!isJWKSLike(jwks)) throw new JWKSInvalid("JSON Web Key Set malformed");
2018
- this._jwks = clone(jwks);
2019
- }
2020
- async getKey(protectedHeader, token) {
2021
- const { alg, kid } = {
2022
- ...protectedHeader,
2023
- ...token?.header
2024
- };
2025
- const kty = getKtyFromAlg(alg);
2026
- const candidates = this._jwks.keys.filter((jwk) => {
2027
- let candidate = kty === jwk.kty;
2028
- if (candidate && typeof kid === "string") candidate = kid === jwk.kid;
2029
- if (candidate && typeof jwk.alg === "string") candidate = alg === jwk.alg;
2030
- if (candidate && typeof jwk.use === "string") candidate = jwk.use === "sig";
2031
- if (candidate && Array.isArray(jwk.key_ops)) candidate = jwk.key_ops.includes("verify");
2032
- if (candidate) switch (alg) {
2033
- case "ES256":
2034
- candidate = jwk.crv === "P-256";
2035
- break;
2036
- case "ES256K":
2037
- candidate = jwk.crv === "secp256k1";
2038
- break;
2039
- case "ES384":
2040
- candidate = jwk.crv === "P-384";
2041
- break;
2042
- case "ES512":
2043
- candidate = jwk.crv === "P-521";
2044
- break;
2045
- case "Ed25519":
2046
- candidate = jwk.crv === "Ed25519";
2047
- break;
2048
- case "EdDSA":
2049
- candidate = jwk.crv === "Ed25519" || jwk.crv === "Ed448";
2050
- break;
2051
- }
2052
- return candidate;
2053
- });
2054
- const { 0: jwk, length } = candidates;
2055
- if (length === 0) throw new JWKSNoMatchingKey();
2056
- if (length !== 1) {
2057
- const error = new JWKSMultipleMatchingKeys();
2058
- const { _cached } = this;
2059
- error[Symbol.asyncIterator] = async function* () {
2060
- for (const jwk of candidates) try {
2061
- yield await importWithAlgCache(_cached, jwk, alg);
2062
- } catch {}
2063
- };
2064
- throw error;
2065
- }
2066
- return importWithAlgCache(this._cached, jwk, alg);
2067
- }
2068
- };
2069
- async function importWithAlgCache(cache, jwk, alg) {
2070
- const cached = cache.get(jwk) || cache.set(jwk, {}).get(jwk);
2071
- if (cached[alg] === void 0) {
2072
- const key = await importJWK({
2073
- ...jwk,
2074
- ext: true
2075
- }, alg);
2076
- if (key instanceof Uint8Array || key.type !== "public") throw new JWKSInvalid("JSON Web Key Set members must be public keys");
2077
- cached[alg] = key;
2078
- }
2079
- return cached[alg];
2080
- }
2081
- function createLocalJWKSet(jwks) {
2082
- const set = new LocalJWKSet(jwks);
2083
- const localJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
2084
- Object.defineProperties(localJWKSet, { jwks: {
2085
- value: () => clone(set._jwks),
2086
- enumerable: true,
2087
- configurable: false,
2088
- writable: false
2089
- } });
2090
- return localJWKSet;
2091
- }
2092
- //#endregion
2093
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/runtime/fetch_jwks.js
2094
- const fetchJwks = async (url, timeout, options) => {
2095
- let controller;
2096
- let id;
2097
- let timedOut = false;
2098
- if (typeof AbortController === "function") {
2099
- controller = new AbortController();
2100
- id = setTimeout(() => {
2101
- timedOut = true;
2102
- controller.abort();
2103
- }, timeout);
2104
- }
2105
- const response = await fetch(url.href, {
2106
- signal: controller ? controller.signal : void 0,
2107
- redirect: "manual",
2108
- headers: options.headers
2109
- }).catch((err) => {
2110
- if (timedOut) throw new JWKSTimeout();
2111
- throw err;
2112
- });
2113
- if (id !== void 0) clearTimeout(id);
2114
- if (response.status !== 200) throw new JOSEError("Expected 200 OK from the JSON Web Key Set HTTP response");
2115
- try {
2116
- return await response.json();
2117
- } catch {
2118
- throw new JOSEError("Failed to parse the JSON Web Key Set HTTP response as JSON");
2119
- }
2120
- };
2121
- //#endregion
2122
- //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/jwks/remote.js
2123
- function isCloudflareWorkers() {
2124
- return typeof WebSocketPair !== "undefined" || typeof navigator !== "undefined" && navigator.userAgent === "Cloudflare-Workers" || typeof EdgeRuntime !== "undefined" && EdgeRuntime === "vercel";
2125
- }
2126
- let USER_AGENT;
2127
- if (typeof navigator === "undefined" || !navigator.userAgent?.startsWith?.("Mozilla/5.0 ")) USER_AGENT = `jose/v5.10.0`;
2128
- const jwksCache = Symbol();
2129
- function isFreshJwksCache(input, cacheMaxAge) {
2130
- if (typeof input !== "object" || input === null) return false;
2131
- if (!("uat" in input) || typeof input.uat !== "number" || Date.now() - input.uat >= cacheMaxAge) return false;
2132
- if (!("jwks" in input) || !isObject(input.jwks) || !Array.isArray(input.jwks.keys) || !Array.prototype.every.call(input.jwks.keys, isObject)) return false;
2133
- return true;
2134
- }
2135
- var RemoteJWKSet = class {
2136
- constructor(url, options) {
2137
- if (!(url instanceof URL)) throw new TypeError("url must be an instance of URL");
2138
- this._url = new URL(url.href);
2139
- this._options = {
2140
- agent: options?.agent,
2141
- headers: options?.headers
2142
- };
2143
- this._timeoutDuration = typeof options?.timeoutDuration === "number" ? options?.timeoutDuration : 5e3;
2144
- this._cooldownDuration = typeof options?.cooldownDuration === "number" ? options?.cooldownDuration : 3e4;
2145
- this._cacheMaxAge = typeof options?.cacheMaxAge === "number" ? options?.cacheMaxAge : 6e5;
2146
- if (options?.[jwksCache] !== void 0) {
2147
- this._cache = options?.[jwksCache];
2148
- if (isFreshJwksCache(options?.[jwksCache], this._cacheMaxAge)) {
2149
- this._jwksTimestamp = this._cache.uat;
2150
- this._local = createLocalJWKSet(this._cache.jwks);
2151
- }
2152
- }
2153
- }
2154
- coolingDown() {
2155
- return typeof this._jwksTimestamp === "number" ? Date.now() < this._jwksTimestamp + this._cooldownDuration : false;
2156
- }
2157
- fresh() {
2158
- return typeof this._jwksTimestamp === "number" ? Date.now() < this._jwksTimestamp + this._cacheMaxAge : false;
2159
- }
2160
- async getKey(protectedHeader, token) {
2161
- if (!this._local || !this.fresh()) await this.reload();
2162
- try {
2163
- return await this._local(protectedHeader, token);
2164
- } catch (err) {
2165
- if (err instanceof JWKSNoMatchingKey) {
2166
- if (this.coolingDown() === false) {
2167
- await this.reload();
2168
- return this._local(protectedHeader, token);
2169
- }
2170
- }
2171
- throw err;
2172
- }
2173
- }
2174
- async reload() {
2175
- if (this._pendingFetch && isCloudflareWorkers()) this._pendingFetch = void 0;
2176
- const headers = new Headers(this._options.headers);
2177
- if (USER_AGENT && !headers.has("User-Agent")) {
2178
- headers.set("User-Agent", USER_AGENT);
2179
- this._options.headers = Object.fromEntries(headers.entries());
2180
- }
2181
- this._pendingFetch || (this._pendingFetch = fetchJwks(this._url, this._timeoutDuration, this._options).then((json) => {
2182
- this._local = createLocalJWKSet(json);
2183
- if (this._cache) {
2184
- this._cache.uat = Date.now();
2185
- this._cache.jwks = json;
2186
- }
2187
- this._jwksTimestamp = Date.now();
2188
- this._pendingFetch = void 0;
2189
- }).catch((err) => {
2190
- this._pendingFetch = void 0;
2191
- throw err;
2192
- }));
2193
- await this._pendingFetch;
2194
- }
2195
- };
2196
- function createRemoteJWKSet(url, options) {
2197
- const set = new RemoteJWKSet(url, options);
2198
- const remoteJWKSet = async (protectedHeader, token) => set.getKey(protectedHeader, token);
2199
- Object.defineProperties(remoteJWKSet, {
2200
- coolingDown: {
2201
- get: () => set.coolingDown(),
2202
- enumerable: true,
2203
- configurable: false
2204
- },
2205
- fresh: {
2206
- get: () => set.fresh(),
2207
- enumerable: true,
2208
- configurable: false
2209
- },
2210
- reload: {
2211
- value: () => set.reload(),
2212
- enumerable: true,
2213
- configurable: false,
2214
- writable: false
2215
- },
2216
- reloading: {
2217
- get: () => !!set._pendingFetch,
2218
- enumerable: true,
2219
- configurable: false
2220
- },
2221
- jwks: {
2222
- value: () => set._local?.jwks(),
2223
- enumerable: true,
2224
- configurable: false,
2225
- writable: false
2226
- }
2227
- });
2228
- return remoteJWKSet;
2229
- }
2230
1298
  const decode = decode$1;
2231
1299
  //#endregion
2232
1300
  //#region ../../../node_modules/.pnpm/jose@5.10.0/node_modules/jose/dist/browser/util/decode_jwt.js
@@ -2393,25 +1461,6 @@ function getTokenTimeRemaining(token) {
2393
1461
  return 0;
2394
1462
  }
2395
1463
  }
2396
- /**
2397
- * Verify a JWT token's signature using a JWKS endpoint and extract its payload.
2398
- *
2399
- * Unlike {@link decodeToken}, this function cryptographically verifies
2400
- * that the token was signed by a trusted key.
2401
- *
2402
- * @param token - The JWT token string
2403
- * @param jwksUrl - URL of the JWKS endpoint
2404
- * @returns The verified JWT payload, or null if verification fails
2405
- */
2406
- async function verifyToken(token, jwksUrl) {
2407
- try {
2408
- const { payload } = await jwtVerify(token, createRemoteJWKSet(new URL(jwksUrl)));
2409
- return extractPayloadFromJose(payload);
2410
- } catch (error) {
2411
- console.error("[FluidAuth] JWT signature verification failed:", error);
2412
- return null;
2413
- }
2414
- }
2415
1464
  //#endregion
2416
1465
  //#region ../../platform/auth/src/token-storage.ts
2417
1466
  /**
@@ -2630,36 +1679,6 @@ function extractAllTokensFromUrl(userTokenKey = URL_PARAMS.USER_TOKEN, companyTo
2630
1679
  };
2631
1680
  }
2632
1681
  }
2633
- //#endregion
2634
- //#region ../../platform/auth/src/dev-utils.ts
2635
- /**
2636
- * Check if dev bypass should be active.
2637
- * Requires both the config flag AND Vite dev mode.
2638
- */
2639
- function isDevBypassActive(devBypass) {
2640
- if (!devBypass) return false;
2641
- try {
2642
- return import.meta.env?.DEV === true;
2643
- } catch {
2644
- return false;
2645
- }
2646
- }
2647
- /**
2648
- * Create a synthetic dev user for local development.
2649
- * This user has realistic data for UI rendering but no real auth.
2650
- */
2651
- function createDevUser() {
2652
- return {
2653
- id: 99999,
2654
- email: "dev@localhost",
2655
- full_name: "Dev User",
2656
- user_type: USER_TYPES.rep,
2657
- og_user_type: void 0,
2658
- company_id: 99999,
2659
- exp: void 0,
2660
- auth_type: "dev_bypass"
2661
- };
2662
- }
2663
1682
  z.object({
2664
1683
  id: z.number(),
2665
1684
  name: z.string(),
@@ -2747,17 +1766,6 @@ function createDefaultAuthRedirect(authUrl) {
2747
1766
  window.location.href = `${base}/?redirect_url=${currentUrl}`;
2748
1767
  };
2749
1768
  }
2750
- /**
2751
- * Resolves the effective auth failure handler.
2752
- * Returns the custom callback if provided, otherwise creates a default redirect.
2753
- *
2754
- * @param onAuthFailure - Custom callback from user config
2755
- * @param authUrl - Custom auth URL (only used when creating the default redirect)
2756
- * @returns The resolved handler function
2757
- */
2758
- function resolveAuthFailureHandler(onAuthFailure, authUrl) {
2759
- return onAuthFailure ?? createDefaultAuthRedirect(authUrl);
2760
- }
2761
1769
  //#endregion
2762
1770
  //#region ../core/src/theme/types.ts
2763
1771
  const SEMANTIC_COLOR_NAMES = [
@@ -3718,6 +2726,13 @@ function extractErrorMessage(data, fallback) {
3718
2726
  return fallback;
3719
2727
  }
3720
2728
  /**
2729
+ * Type guard to detect whether a parsed JSON value is an API envelope.
2730
+ * Envelopes always have numeric `status` and a `data` key.
2731
+ */
2732
+ function isApiEnvelope(value) {
2733
+ return typeof value === "object" && value !== null && "status" in value && typeof value.status === "number" && "data" in value;
2734
+ }
2735
+ /**
3721
2736
  * Creates a configured Fluid API client instance
3722
2737
  */
3723
2738
  function createFluidClient(config) {
@@ -3727,22 +2742,19 @@ function createFluidClient(config) {
3727
2742
  baseUrl,
3728
2743
  ...getAuthToken ? { getAuthToken } : {},
3729
2744
  onAuthError: effectiveOnAuthError,
3730
- defaultHeaders
2745
+ defaultHeaders,
2746
+ credentials: "include"
3731
2747
  });
3732
2748
  /**
3733
- * Build headers for a request
2749
+ * Build headers for a request.
2750
+ * Auth is handled by session cookies via `credentials: 'include'` on fetch calls.
3734
2751
  */
3735
- async function buildHeaders(customHeaders) {
3736
- const headers = {
2752
+ function buildHeaders(customHeaders) {
2753
+ return {
3737
2754
  "Content-Type": "application/json",
3738
2755
  ...defaultHeaders,
3739
2756
  ...customHeaders
3740
2757
  };
3741
- if (getAuthToken) {
3742
- const token = await getAuthToken();
3743
- if (token) headers.Authorization = `Bearer ${token}`;
3744
- }
3745
- return headers;
3746
2758
  }
3747
2759
  /**
3748
2760
  * Build URL with query parameters (Rails-compatible)
@@ -3750,7 +2762,7 @@ function createFluidClient(config) {
3750
2762
  function buildUrl(endpoint, params) {
3751
2763
  const normalizedBase = baseUrl.endsWith("/") ? baseUrl.slice(0, -1) : baseUrl;
3752
2764
  const normalizedEndpoint = endpoint.startsWith("/") ? endpoint : `/${endpoint}`;
3753
- const url = new URL(normalizedBase + normalizedEndpoint);
2765
+ const url = normalizedBase ? new URL(normalizedBase + normalizedEndpoint) : new URL(normalizedEndpoint, typeof window !== "undefined" ? window.location.origin : "http://localhost");
3754
2766
  if (params) for (const [key, value] of Object.entries(params)) {
3755
2767
  if (value === void 0 || value === null) continue;
3756
2768
  if (Array.isArray(value)) for (const item of value) url.searchParams.append(`${key}[]`, String(item));
@@ -3774,12 +2786,13 @@ function createFluidClient(config) {
3774
2786
  async function request(endpoint, options = {}) {
3775
2787
  const { method = defaultRequestOptions.method, headers: customHeaders, params, body, signal } = options;
3776
2788
  const url = buildUrl(endpoint, method === HTTP_METHODS.GET ? params : void 0);
3777
- const headers = await buildHeaders(customHeaders);
2789
+ const headers = buildHeaders(customHeaders);
3778
2790
  let response;
3779
2791
  try {
3780
2792
  const fetchOptions = {
3781
2793
  method,
3782
- headers
2794
+ headers,
2795
+ credentials: "include"
3783
2796
  };
3784
2797
  if (signal !== void 0) fetchOptions.signal = signal;
3785
2798
  if (body && method !== HTTP_METHODS.GET) fetchOptions.body = JSON.stringify(body);
@@ -3802,9 +2815,9 @@ function createFluidClient(config) {
3802
2815
  }
3803
2816
  if (response.status === 204 || response.headers.get("content-length") === "0") return null;
3804
2817
  try {
3805
- const data = await response.json();
3806
- if (data === null || data === void 0) throw new ApiError("Unexpected null/undefined in JSON response", response.status, null);
3807
- return data;
2818
+ const raw = await response.json();
2819
+ if (raw === null || raw === void 0) throw new ApiError("Unexpected null/undefined in JSON response", response.status, null);
2820
+ return isApiEnvelope(raw) ? raw.data : raw;
3808
2821
  } catch (parseError) {
3809
2822
  if (isApiError(parseError)) throw parseError;
3810
2823
  throw new ApiError("Failed to parse response as JSON", response.status, null);
@@ -3839,6 +2852,51 @@ function createFluidClient(config) {
3839
2852
  }
3840
2853
  }
3841
2854
  /**
2855
+ * Request wrapper for paginated list endpoints.
2856
+ * Parses the API envelope and returns both `data` and cursor pagination metadata.
2857
+ * Falls back gracefully when the response is not an envelope.
2858
+ */
2859
+ async function requestPaginated(endpoint, options = {}) {
2860
+ const { method = defaultRequestOptions.method, headers: customHeaders, params, body, signal } = options;
2861
+ const url = buildUrl(endpoint, method === HTTP_METHODS.GET ? params : void 0);
2862
+ const headers = buildHeaders(customHeaders);
2863
+ let response;
2864
+ try {
2865
+ const fetchOptions = {
2866
+ method,
2867
+ headers,
2868
+ credentials: "include"
2869
+ };
2870
+ if (signal !== void 0) fetchOptions.signal = signal;
2871
+ if (body && method !== HTTP_METHODS.GET) fetchOptions.body = JSON.stringify(body);
2872
+ response = await fetch(url, fetchOptions);
2873
+ } catch (networkError) {
2874
+ throw new ApiError(`Network error: ${networkError instanceof Error ? networkError.message : "Unknown network error"}`, 0, null);
2875
+ }
2876
+ if (response.status === 401) {
2877
+ effectiveOnAuthError();
2878
+ throw new ApiError("Authentication required", 401, null);
2879
+ }
2880
+ if (!response.ok) try {
2881
+ if (response.headers.get("content-type")?.includes("application/json")) {
2882
+ const errorData = await response.json();
2883
+ throw new ApiError(extractErrorMessage(errorData, `${method} request failed`), response.status, "errors" in errorData ? errorData.errors : errorData);
2884
+ } else throw new ApiError(`${method} request failed with status ${response.status}`, response.status, null);
2885
+ } catch (error) {
2886
+ if (isApiError(error)) throw error;
2887
+ throw new ApiError(`${method} request failed with status ${response.status}`, response.status, null);
2888
+ }
2889
+ const raw = await response.json();
2890
+ if (isApiEnvelope(raw)) return {
2891
+ data: raw.data,
2892
+ pagination: raw.meta.pagination
2893
+ };
2894
+ return {
2895
+ data: raw,
2896
+ pagination: void 0
2897
+ };
2898
+ }
2899
+ /**
3842
2900
  * Helper to safely convert typed params to Record<string, unknown>.
3843
2901
  * Type assertion required: TypeScript's structural typing allows any object
3844
2902
  * to be treated as Record<string, unknown> when we only need to iterate
@@ -3888,11 +2946,17 @@ function createFluidClient(config) {
3888
2946
  patch,
3889
2947
  delete: del,
3890
2948
  products: {
3891
- list: (params) => get("/api/company/v1/products", params),
2949
+ list: (params) => requestPaginated("/api/company/v1/products", {
2950
+ method: HTTP_METHODS.GET,
2951
+ params: toParams(params)
2952
+ }),
3892
2953
  get: (id) => get(`/api/company/v1/products/${id}`),
3893
- search: (query, params) => get("/api/company/v1/products", {
3894
- search_query: query,
3895
- ...params
2954
+ search: (query, params) => requestPaginated("/api/company/v1/products", {
2955
+ method: HTTP_METHODS.GET,
2956
+ params: {
2957
+ search_query: query,
2958
+ ...toParams(params)
2959
+ }
3896
2960
  })
3897
2961
  },
3898
2962
  orders: {
@@ -4000,9 +3064,17 @@ function useThemeContext() {
4000
3064
  /**
4001
3065
  * FluidAuthProvider - Authentication Provider for Fluid Portal SDK
4002
3066
  *
4003
- * Handles JWT token extraction from URL, validation, storage, and
4004
- * provides authentication context to child components.
3067
+ * Session-based authentication: Rails establishes an HTTP-only session cookie
3068
+ * during the Hub Tenant handoff. The SPA checks session state via a BFF
3069
+ * endpoint (`/api/me`).
3070
+ *
3071
+ * When the session is missing or expires, the provider reloads the page rather
3072
+ * than redirecting client-side. This delegates redirect logic to Rails, which
3073
+ * correctly resolves the Portal Hub URL for any hostname pattern — including
3074
+ * CNAMEs like `portal.acme.com` where client-side hostname parsing would fail.
4005
3075
  */
3076
+ /** BFF endpoint that returns the current user from the server session. */
3077
+ const SESSION_ENDPOINT = "/api/me";
4006
3078
  /**
4007
3079
  * Auth context - null when outside provider
4008
3080
  */
@@ -4011,7 +3083,7 @@ function authReducer(state, action) {
4011
3083
  switch (action.type) {
4012
3084
  case "SET_AUTH": return {
4013
3085
  isLoading: false,
4014
- token: action.token,
3086
+ token: null,
4015
3087
  user: action.user,
4016
3088
  error: action.error
4017
3089
  };
@@ -4037,12 +3109,13 @@ const initialAuthState = {
4037
3109
  * Authentication provider for Fluid portal applications.
4038
3110
  *
4039
3111
  * On mount, this provider:
4040
- * 1. Checks for a token in the URL (passed from parent app)
4041
- * 2. Cleans token from URL immediately (security)
4042
- * 3. Falls back to stored token (cookie/localStorage)
4043
- * 4. Validates the token (checks expiration)
4044
- * 5. Stores valid tokens for future use
4045
- * 6. Calls onAuthFailure if no valid token found
3112
+ * 1. Checks the server session via `GET /api/me` (BFF endpoint)
3113
+ * 2. If 401 no session — reloads the page so Rails can redirect to the Hub
3114
+ * 3. Populates auth state from the API response
3115
+ *
3116
+ * The Hub Tenant handoff is fully server-side: Rails consumes a short-lived
3117
+ * DB token and establishes an HTTP-only session cookie before the SPA boots.
3118
+ * Unauthenticated HTML requests are 302'd to the Portal Hub by Rails.
4046
3119
  *
4047
3120
  * @example
4048
3121
  * ```tsx
@@ -4050,13 +3123,7 @@ const initialAuthState = {
4050
3123
  *
4051
3124
  * function App() {
4052
3125
  * return (
4053
- * <FluidAuthProvider
4054
- * config={{
4055
- * onAuthFailure: () => {
4056
- * window.location.href = "/login";
4057
- * },
4058
- * }}
4059
- * >
3126
+ * <FluidAuthProvider>
4060
3127
  * <YourApp />
4061
3128
  * </FluidAuthProvider>
4062
3129
  * );
@@ -4070,107 +3137,37 @@ function FluidAuthProvider({ children, config }) {
4070
3137
  const { isLoading, token, user, error } = state;
4071
3138
  useEffect(() => {
4072
3139
  const initializeAuth = async () => {
4073
- const handleAuthFailure = () => {
3140
+ const handleUnauthenticated = () => {
4074
3141
  const current = configRef.current;
4075
- resolveAuthFailureHandler(current?.onAuthFailure, current?.authUrl)();
4076
- };
4077
- try {
4078
- if (isDevBypassActive(config?.devBypass)) {
4079
- const envToken = import.meta.env.VITE_DEV_TOKEN;
4080
- if (envToken) {
4081
- const validation = validateToken(envToken, config?.gracePeriodMs);
4082
- if (validation.isValid && validation.payload) {
4083
- storeToken(envToken, config);
4084
- dispatch({
4085
- type: "SET_AUTH",
4086
- token: envToken,
4087
- user: validation.payload,
4088
- error: null
4089
- });
4090
- return;
4091
- }
4092
- console.warn("[FluidAuth] VITE_DEV_TOKEN is invalid or expired, falling back to mock user");
4093
- }
4094
- console.warn("[FluidAuth] Dev bypass active - using mock user. API calls will fail without a real token.");
4095
- dispatch({
4096
- type: "SET_AUTH",
4097
- token: null,
4098
- user: createDevUser(),
4099
- error: null
4100
- });
3142
+ if (current?.onAuthFailure) {
3143
+ current.onAuthFailure();
4101
3144
  return;
4102
3145
  }
4103
- const tokenKey = config?.tokenKey ?? "fluidUserToken";
4104
- let candidateToken = extractTokenFromUrl(tokenKey);
4105
- if (!candidateToken && tokenKey !== "jwt") candidateToken = extractTokenFromUrl("jwt");
4106
- cleanTokenFromUrl(tokenKey);
4107
- cleanTokenFromUrl("jwt");
4108
- if (!candidateToken) candidateToken = getStoredToken(config);
4109
- if (candidateToken) {
4110
- let payload = null;
4111
- if (config?.jwksUrl) {
4112
- payload = await verifyToken(candidateToken, config.jwksUrl);
4113
- if (!payload) {
4114
- clearTokens(config);
4115
- dispatch({
4116
- type: "SET_AUTH",
4117
- token: null,
4118
- user: null,
4119
- error: /* @__PURE__ */ new Error("JWT signature verification failed")
4120
- });
4121
- handleAuthFailure();
4122
- return;
4123
- }
4124
- if (isTokenExpired(candidateToken, config?.gracePeriodMs)) {
4125
- clearTokens(config);
4126
- dispatch({
4127
- type: "SET_AUTH",
4128
- token: null,
4129
- user: null,
4130
- error: /* @__PURE__ */ new Error("Token has expired")
4131
- });
4132
- handleAuthFailure();
4133
- return;
4134
- }
4135
- } else {
4136
- const validation = validateToken(candidateToken, config?.gracePeriodMs);
4137
- if (validation.isValid && validation.payload) payload = validation.payload;
4138
- else {
4139
- clearTokens(config);
4140
- dispatch({
4141
- type: "SET_AUTH",
4142
- token: null,
4143
- user: null,
4144
- error: new Error(validation.error ?? "Invalid token")
4145
- });
4146
- handleAuthFailure();
4147
- return;
4148
- }
4149
- }
4150
- storeToken(candidateToken, config);
4151
- dispatch({
4152
- type: "SET_AUTH",
4153
- token: candidateToken,
4154
- user: payload,
4155
- error: null
4156
- });
4157
- } else {
3146
+ window.location.reload();
3147
+ };
3148
+ try {
3149
+ const response = await fetch(SESSION_ENDPOINT, { credentials: "include" });
3150
+ if (response.status === 401) {
4158
3151
  dispatch({
4159
3152
  type: "SET_AUTH",
4160
- token: null,
4161
3153
  user: null,
4162
- error: /* @__PURE__ */ new Error("No authentication token found")
3154
+ error: /* @__PURE__ */ new Error("No active session")
4163
3155
  });
4164
- handleAuthFailure();
3156
+ handleUnauthenticated();
3157
+ return;
4165
3158
  }
3159
+ if (!response.ok) throw new Error(`Session check failed with status ${String(response.status)}`);
3160
+ dispatch({
3161
+ type: "SET_AUTH",
3162
+ user: (await response.json()).data,
3163
+ error: null
3164
+ });
4166
3165
  } catch (err) {
4167
3166
  dispatch({
4168
3167
  type: "SET_AUTH",
4169
- token: null,
4170
3168
  user: null,
4171
3169
  error: err instanceof Error ? err : /* @__PURE__ */ new Error("Authentication error")
4172
3170
  });
4173
- handleAuthFailure();
4174
3171
  } finally {
4175
3172
  dispatch({ type: "DONE_LOADING" });
4176
3173
  }
@@ -4178,7 +3175,6 @@ function FluidAuthProvider({ children, config }) {
4178
3175
  initializeAuth();
4179
3176
  }, []);
4180
3177
  const clearAuth = useCallback(() => {
4181
- clearTokens(configRef.current);
4182
3178
  dispatch({ type: "CLEAR_AUTH" });
4183
3179
  }, []);
4184
3180
  const contextValue = useMemo(() => ({
@@ -4322,10 +3318,7 @@ const FluidContext = createContext(null);
4322
3318
  * function App() {
4323
3319
  * return (
4324
3320
  * <FluidProvider
4325
- * config={{
4326
- * baseUrl: "https://api.fluid.app/api",
4327
- * getAuthToken: () => localStorage.getItem("token"),
4328
- * }}
3321
+ * config={{ baseUrl: "" }}
4329
3322
  * >
4330
3323
  * <YourApp />
4331
3324
  * </FluidProvider>
@@ -4354,13 +3347,7 @@ function FluidProvider({ config, children, queryClient, initialTheme, themeConta
4354
3347
  config: configRef.current
4355
3348
  }), [client]);
4356
3349
  const getApiHeaders = useCallback(() => {
4357
- const headers = { "Content-Type": "application/json" };
4358
- const getAuthToken = configRef.current.getAuthToken;
4359
- if (typeof getAuthToken === "function") {
4360
- const tokenOrPromise = getAuthToken();
4361
- if (typeof tokenOrPromise === "string") headers.Authorization = `Bearer ${tokenOrPromise}`;
4362
- }
4363
- return headers;
3350
+ return { "Content-Type": "application/json" };
4364
3351
  }, []);
4365
3352
  const dataSourceBaseUrl = useMemo(() => {
4366
3353
  const base = config.baseUrl.replace(/\/+$/, "");
@@ -4458,4 +3445,4 @@ function useFluidContext() {
4458
3445
  //#endregion
4459
3446
  export { extractTokenFromUrl as $, DEFAULT_FONT_SIZES as A, mergeDarkOverrides as B, buildThemeDefinition as C, serialiseTheme as D, deserialiseTheme as E, getDefaultThemeDefinition as F, RADIUS_KEYS as G, resolveTheme as H, generateThemeCSS as I, DEFAULT_AUTH_URL as J, SEMANTIC_COLOR_NAMES as K, deriveDarkVariant as L, DEFAULT_SPACING as M, DEFAULT_THEME_ID as N, DEFAULT_COLORS as O, DEFAULT_THEME_NAME as P, extractCompanyTokenFromUrl as Q, generateShades as R, removeTheme as S, createFetchClient as St, transformThemes as T, FONT_FAMILY_KEYS as U, parseColor as V, FONT_SIZE_KEYS as W, cleanTokenFromUrl as X, createDefaultAuthRedirect as Y, extractAllTokensFromUrl as Z, toNavigationItem as _, createPersister as _t, createScreen as a, decodeToken as at, applyTheme as b, useFluidPayApi as bt, FluidAuthProvider as c, isTokenExpired as ct, useThemeContext as d, AUTH_CONSTANTS as dt, hasTokenInUrl as et, ApiError as f, STORAGE_KEYS as ft, transformManifestToRepAppData as g, useFluidOsApiOptional as gt, toRawManifest as h, isUserType as ht, widgetPropertySchemas as i, storeToken as it, DEFAULT_RADII as j, DEFAULT_FONT_FAMILIES as k, useFluidAuthContext as l, isValidToken as lt, isApiError as m, USER_TYPES as mt, useFluidContext as n, getStoredToken as nt, createWidgetFromShareable as o, getTokenExpiration as ot, createFluidClient as p, URL_PARAMS as pt, SHADE_STEPS as q, DEFAULT_SDK_WIDGET_REGISTRY as r, hasStoredToken as rt, createWidgetRegistry as s, getTokenTimeRemaining as st, FluidProvider as t, clearTokens as tt, FluidThemeProvider as u, validateToken as ut, normalizeComponentTree as v, deleteDatabase as vt, getActiveThemeId as w, removeAllThemes as x, ApiError$1 as xt, toScreenDefinition as y, useCountryStates as yt, getForegroundColor as z };
4460
3447
 
4461
- //# sourceMappingURL=FluidProvider-CWYquEIF.mjs.map
3448
+ //# sourceMappingURL=FluidProvider-B59bzF__.mjs.map