@neetru/sdk 3.4.7 → 3.6.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 (94) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/dist/ai.cjs +17 -13
  3. package/dist/ai.cjs.map +1 -1
  4. package/dist/ai.d.cts +1 -1
  5. package/dist/ai.d.ts +1 -1
  6. package/dist/ai.mjs +17 -13
  7. package/dist/ai.mjs.map +1 -1
  8. package/dist/auth.cjs +159 -107
  9. package/dist/auth.cjs.map +1 -1
  10. package/dist/auth.d.cts +2 -2
  11. package/dist/auth.d.ts +2 -2
  12. package/dist/auth.mjs +159 -107
  13. package/dist/auth.mjs.map +1 -1
  14. package/dist/catalog.cjs +19 -4
  15. package/dist/catalog.cjs.map +1 -1
  16. package/dist/catalog.d.cts +1 -1
  17. package/dist/catalog.d.ts +1 -1
  18. package/dist/catalog.mjs +19 -4
  19. package/dist/catalog.mjs.map +1 -1
  20. package/dist/checkout.cjs +11 -3
  21. package/dist/checkout.cjs.map +1 -1
  22. package/dist/checkout.d.cts +1 -1
  23. package/dist/checkout.d.ts +1 -1
  24. package/dist/checkout.mjs +11 -3
  25. package/dist/checkout.mjs.map +1 -1
  26. package/dist/db-react.d.cts +1 -1
  27. package/dist/db-react.d.ts +1 -1
  28. package/dist/db.cjs +17 -7
  29. package/dist/db.cjs.map +1 -1
  30. package/dist/db.d.cts +1 -1
  31. package/dist/db.d.ts +1 -1
  32. package/dist/db.mjs +17 -7
  33. package/dist/db.mjs.map +1 -1
  34. package/dist/entitlements.d.cts +1 -1
  35. package/dist/entitlements.d.ts +1 -1
  36. package/dist/firestore-compat.d.cts +1 -1
  37. package/dist/firestore-compat.d.ts +1 -1
  38. package/dist/index.cjs +160 -108
  39. package/dist/index.cjs.map +1 -1
  40. package/dist/index.d.cts +30 -2
  41. package/dist/index.d.ts +30 -2
  42. package/dist/index.mjs +160 -108
  43. package/dist/index.mjs.map +1 -1
  44. package/dist/mobile.cjs +515 -0
  45. package/dist/mobile.cjs.map +1 -0
  46. package/dist/mobile.d.cts +89 -0
  47. package/dist/mobile.d.ts +89 -0
  48. package/dist/mobile.mjs +513 -0
  49. package/dist/mobile.mjs.map +1 -0
  50. package/dist/mocks.cjs +17 -0
  51. package/dist/mocks.cjs.map +1 -1
  52. package/dist/mocks.d.cts +5 -1
  53. package/dist/mocks.d.ts +5 -1
  54. package/dist/mocks.mjs +17 -0
  55. package/dist/mocks.mjs.map +1 -1
  56. package/dist/notifications.cjs +11 -3
  57. package/dist/notifications.cjs.map +1 -1
  58. package/dist/notifications.d.cts +1 -1
  59. package/dist/notifications.d.ts +1 -1
  60. package/dist/notifications.mjs +11 -3
  61. package/dist/notifications.mjs.map +1 -1
  62. package/dist/react.cjs +36 -2
  63. package/dist/react.cjs.map +1 -1
  64. package/dist/react.d.cts +1 -1
  65. package/dist/react.d.ts +1 -1
  66. package/dist/react.mjs +36 -2
  67. package/dist/react.mjs.map +1 -1
  68. package/dist/support.cjs +15 -4
  69. package/dist/support.cjs.map +1 -1
  70. package/dist/support.d.cts +1 -1
  71. package/dist/support.d.ts +1 -1
  72. package/dist/support.mjs +15 -4
  73. package/dist/support.mjs.map +1 -1
  74. package/dist/telemetry.cjs +11 -3
  75. package/dist/telemetry.cjs.map +1 -1
  76. package/dist/telemetry.d.cts +1 -1
  77. package/dist/telemetry.d.ts +1 -1
  78. package/dist/telemetry.mjs +11 -3
  79. package/dist/telemetry.mjs.map +1 -1
  80. package/dist/{types-nnztVk7G.d.ts → types-BPATkXYu.d.ts} +35 -7
  81. package/dist/{types-DIVZl7nO.d.cts → types-Du_iioJ7.d.cts} +35 -7
  82. package/dist/usage.cjs +11 -3
  83. package/dist/usage.cjs.map +1 -1
  84. package/dist/usage.d.cts +1 -1
  85. package/dist/usage.d.ts +1 -1
  86. package/dist/usage.mjs +11 -3
  87. package/dist/usage.mjs.map +1 -1
  88. package/dist/webhooks.cjs +17 -4
  89. package/dist/webhooks.cjs.map +1 -1
  90. package/dist/webhooks.d.cts +1 -1
  91. package/dist/webhooks.d.ts +1 -1
  92. package/dist/webhooks.mjs +17 -4
  93. package/dist/webhooks.mjs.map +1 -1
  94. package/package.json +9 -1
@@ -1,4 +1,4 @@
1
- import { ag as ResolvedConfig, O as EntitlementCheck } from './types-DIVZl7nO.cjs';
1
+ import { ag as ResolvedConfig, O as EntitlementCheck } from './types-Du_iioJ7.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { ag as ResolvedConfig, O as EntitlementCheck } from './types-nnztVk7G.js';
1
+ import { ag as ResolvedConfig, O as EntitlementCheck } from './types-BPATkXYu.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { Y as NeetruDb, E as DbCollectionRef, P as FieldSentinel, K as DbQuery } from './types-DIVZl7nO.cjs';
1
+ import { Y as NeetruDb, E as DbCollectionRef, P as FieldSentinel, K as DbQuery } from './types-Du_iioJ7.cjs';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.cjs';
4
4
 
@@ -1,4 +1,4 @@
1
- import { Y as NeetruDb, E as DbCollectionRef, P as FieldSentinel, K as DbQuery } from './types-nnztVk7G.js';
1
+ import { Y as NeetruDb, E as DbCollectionRef, P as FieldSentinel, K as DbQuery } from './types-BPATkXYu.js';
2
2
  import 'drizzle-orm/node-postgres';
3
3
  import './errors.js';
4
4
 
package/dist/index.cjs CHANGED
@@ -64,7 +64,8 @@ var init_idempotency = __esm({
64
64
  var http_exports = {};
65
65
  __export(http_exports, {
66
66
  checkCoreVersionCompat: () => checkCoreVersionCompat,
67
- httpRequest: () => httpRequest
67
+ httpRequest: () => httpRequest,
68
+ statusToCode: () => statusToCode
68
69
  });
69
70
  function stripRevision(v) {
70
71
  return v.split("+")[0] ?? v;
@@ -80,12 +81,16 @@ function compareCalVer(a, b) {
80
81
  }
81
82
  return 0;
82
83
  }
83
- function getSdkMajor() {
84
+ function readInjectedSdkVersion() {
84
85
  try {
85
- const ver = globalThis.__NEETRU_SDK_VERSION__;
86
- if (ver) return parseInt(ver.split(".")[0] ?? "3", 10);
86
+ return "3.6.0";
87
87
  } catch {
88
+ return void 0;
88
89
  }
90
+ }
91
+ function getSdkMajor() {
92
+ const ver = readInjectedSdkVersion();
93
+ if (ver) return parseInt(ver.split(".")[0] ?? "3", 10);
89
94
  return 3;
90
95
  }
91
96
  function checkCoreVersionCompat(coreVersion) {
@@ -163,6 +168,10 @@ async function httpRequest(config, opts) {
163
168
  accept: "application/json",
164
169
  ...opts.headers
165
170
  };
171
+ const sdkVersion = readInjectedSdkVersion();
172
+ if (sdkVersion) {
173
+ headers["x-neetru-sdk-version"] = sdkVersion;
174
+ }
166
175
  if (opts.requireAuth) {
167
176
  if (!config.apiKey) {
168
177
  throw new exports.NeetruError(
@@ -527,7 +536,7 @@ var init_lease = __esm({
527
536
  void this._doRenew();
528
537
  }, MIN_RENEWAL_DELAY_MS);
529
538
  console.warn(
530
- `[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${MIN_RENEWAL_DELAY_MS}ms (cert mTLS expira ~15min ap\xF3s o \xFAltimo swap):`,
539
+ `[SqlLeaseManager] renova\xE7\xE3o E emiss\xE3o de lease novo falharam; re-tentando em ${MIN_RENEWAL_DELAY_MS}ms (cert TLS ef\xEAmero do servidor expira ~15min ap\xF3s o \xFAltimo swap):`,
531
540
  err instanceof Error ? err.message : err
532
541
  );
533
542
  return;
@@ -538,8 +547,9 @@ var init_lease = __esm({
538
547
  /**
539
548
  * Recuperação REATIVA: chamado pelo wrapper resiliente (`resilient-pool.ts`)
540
549
  * quando uma query plana falha num erro de ESTABELECIMENTO de conexão (cert
541
- * mTLS expirado no meio de uma request, ou timer de renovação que não
542
- * disparou). Emite um lease NOVO e faz o swap do pool interno do wrapper com
550
+ * TLS efêmero do servidor expirado no meio de uma request, ou timer de
551
+ * renovação que não disparou). Emite um lease NOVO e faz o swap do pool interno
552
+ * do wrapper com
543
553
  * o certificado fresco; o wrapper então re-tenta a query 1x no pool novo.
544
554
  *
545
555
  * Vai DIRETO ao lease novo (sem `leaseId`) — a conexão falhou porque o
@@ -1139,7 +1149,14 @@ function toProduct(raw) {
1139
1149
  if (Array.isArray(r.plans)) {
1140
1150
  product.plans = r.plans.filter(
1141
1151
  (p) => typeof p === "object" && p !== null && typeof p.id === "string" && typeof p.name === "string"
1142
- );
1152
+ ).map((p) => {
1153
+ const plan = { id: p.id, name: p.name };
1154
+ if (typeof p.amountCents === "number") plan.amountCents = p.amountCents;
1155
+ if (Array.isArray(p.features) && p.features.every((f) => typeof f === "string")) {
1156
+ plan.features = p.features;
1157
+ }
1158
+ return plan;
1159
+ });
1143
1160
  }
1144
1161
  return product;
1145
1162
  }
@@ -1719,7 +1736,10 @@ function createSupportNamespace(config) {
1719
1736
  await httpRequest(config, {
1720
1737
  method: "POST",
1721
1738
  path: `/api/sdk/v1/support/tickets/${encodeURIComponent(ticketId)}/satisfaction-attempt`,
1722
- requireAuth: true
1739
+ requireAuth: true,
1740
+ // Incrementa satisfactionAttempts += 1 no Core — sem idempotencyKey,
1741
+ // um retry de rede infla o contador (mesmo padrão de createTicket acima).
1742
+ idempotencyKey: true
1723
1743
  });
1724
1744
  },
1725
1745
  /**
@@ -5921,7 +5941,12 @@ function createWebhooksNamespace(config) {
5921
5941
  events: input.events,
5922
5942
  ...input.secret ? { secret: input.secret } : {}
5923
5943
  },
5924
- requireAuth: true
5944
+ requireAuth: true,
5945
+ // Sem isso, um retry de rede (app-level; SDK default é 0 retries em
5946
+ // POST) podia registrar o MESMO webhook duas vezes → entrega
5947
+ // duplicada de todo evento futuro pro endpoint do cliente. Core
5948
+ // dedup TTL 24h (mesmo padrão de usage.report/support.createTicket).
5949
+ idempotencyKey: true
5925
5950
  });
5926
5951
  return toEndpoint(raw);
5927
5952
  },
@@ -6474,16 +6499,6 @@ async function safeJson2(res) {
6474
6499
  return void 0;
6475
6500
  }
6476
6501
  }
6477
- function statusToCode2(status) {
6478
- if (status === 401) return "unauthorized";
6479
- if (status === 403) return "forbidden";
6480
- if (status === 404) return "not_found";
6481
- if (status === 409) return "conflict";
6482
- if (status === 422 || status === 400) return "validation_failed";
6483
- if (status === 429) return "rate_limited";
6484
- if (status >= 500) return "server_error";
6485
- return "unknown";
6486
- }
6487
6502
  function joinUrl(baseUrl, path) {
6488
6503
  const base = baseUrl.replace(/\/+$/, "");
6489
6504
  const p = path.startsWith("/") ? path : `/${path}`;
@@ -6518,7 +6533,7 @@ async function aiFetch(config, body, signal, stream) {
6518
6533
  const requestId = res.headers.get("x-request-id") ?? res.headers.get("x-correlation-id") ?? void 0;
6519
6534
  if (!res.ok) {
6520
6535
  const parsed = await safeJson2(res);
6521
- let code = statusToCode2(res.status);
6536
+ let code = statusToCode(res.status);
6522
6537
  let message = `HTTP ${res.status}`;
6523
6538
  if (parsed && typeof parsed === "object" && "error" in parsed) {
6524
6539
  const errField = parsed.error;
@@ -6637,6 +6652,19 @@ function createAiNamespace(config) {
6637
6652
  // src/mocks.ts
6638
6653
  init_db_errors();
6639
6654
  init_errors();
6655
+
6656
+ // src/runtime-env.ts
6657
+ function isProductionRuntime() {
6658
+ try {
6659
+ if (typeof process !== "undefined" && process.env) {
6660
+ return process.env.NODE_ENV === "production";
6661
+ }
6662
+ } catch {
6663
+ }
6664
+ return false;
6665
+ }
6666
+
6667
+ // src/mocks.ts
6640
6668
  var DEV_FIXTURE_USER = Object.freeze({
6641
6669
  uid: "dev-fixture-uid-0001",
6642
6670
  email: "dev@neetru.local",
@@ -6653,6 +6681,12 @@ var MockAuth = class {
6653
6681
  this._user = initialUser;
6654
6682
  this._listeners = /* @__PURE__ */ new Set();
6655
6683
  this._allowUnsignedDecode = options?.allowUnsignedDecode ?? false;
6684
+ if (this._allowUnsignedDecode && isProductionRuntime()) {
6685
+ throw new exports.NeetruError(
6686
+ "invalid_config",
6687
+ "MockAuth com allowUnsignedDecode=true \xE9 PROIBIDO em produ\xE7\xE3o (NODE_ENV=production): decodificar JWT sem verificar assinatura \xE9 bypass de autentica\xE7\xE3o. Este modo existe exclusivamente para testes."
6688
+ );
6689
+ }
6656
6690
  if (this._allowUnsignedDecode) {
6657
6691
  const isTestEnv = typeof process !== "undefined" && (process.env?.NODE_ENV === "test" || process.env?.VITEST === "true" || process.env?.VITEST != null);
6658
6692
  if (!isTestEnv && typeof console !== "undefined") {
@@ -7368,6 +7402,94 @@ var MockAi = class {
7368
7402
  }
7369
7403
  };
7370
7404
 
7405
+ // src/auth-pkce-shared.ts
7406
+ init_errors();
7407
+ function getWebCrypto() {
7408
+ const c = globalThis.crypto;
7409
+ if (!c || typeof c.getRandomValues !== "function" || !c.subtle) {
7410
+ throw new exports.NeetruError(
7411
+ "runtime_unsupported",
7412
+ "auth.signIn requer WebCrypto (crypto.subtle) \u2014 indispon\xEDvel neste runtime. Use HTTPS (ou http://localhost) num browser moderno, ou instale um polyfill WebCrypto (ex: react-native-quick-crypto) em React Native."
7413
+ );
7414
+ }
7415
+ return c;
7416
+ }
7417
+ function base64UrlFromBytes(bytes) {
7418
+ let str = "";
7419
+ for (const b of bytes) str += String.fromCharCode(b);
7420
+ const b64 = typeof btoa === "function" ? btoa(str) : Buffer.from(str, "binary").toString("base64");
7421
+ return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
7422
+ }
7423
+ function randomUrlSafe(crypto2, byteLen) {
7424
+ const bytes = new Uint8Array(byteLen);
7425
+ crypto2.getRandomValues(bytes);
7426
+ return base64UrlFromBytes(bytes);
7427
+ }
7428
+ async function pkceChallengeS256(crypto2, verifier) {
7429
+ const data = new TextEncoder().encode(verifier);
7430
+ const digest = await crypto2.subtle.digest("SHA-256", data);
7431
+ return base64UrlFromBytes(new Uint8Array(digest));
7432
+ }
7433
+ function resolveIdpOrigin(baseUrl) {
7434
+ const overrideAuthUrl = typeof globalThis.NEETRU_AUTH_URL === "string" ? globalThis.NEETRU_AUTH_URL : null;
7435
+ return overrideAuthUrl ?? baseUrl.replace(/^https?:\/\/api\./, "https://auth.");
7436
+ }
7437
+ function resolveOidcClientId(config) {
7438
+ let clientId = config.oidcClientId;
7439
+ if (!clientId && config.apiKey) {
7440
+ clientId = parseApiKey(config.apiKey).keyId;
7441
+ }
7442
+ if (!clientId) {
7443
+ throw new exports.NeetruError(
7444
+ "invalid_config",
7445
+ "auth OIDC requer `oidcClientId` (ou `apiKey`) configurado para montar o client_id."
7446
+ );
7447
+ }
7448
+ return clientId;
7449
+ }
7450
+ function buildAuthorizeUrl(params) {
7451
+ const url = new URL("/api/v1/oauth/authorize", params.idpOrigin);
7452
+ url.searchParams.set("response_type", "code");
7453
+ url.searchParams.set("client_id", params.clientId);
7454
+ url.searchParams.set("redirect_uri", params.redirectUri);
7455
+ url.searchParams.set("scope", params.scope);
7456
+ url.searchParams.set("state", params.state);
7457
+ url.searchParams.set("nonce", params.nonce);
7458
+ url.searchParams.set("code_challenge", params.codeChallenge);
7459
+ url.searchParams.set("code_challenge_method", "S256");
7460
+ return url;
7461
+ }
7462
+ function decodeJwtPayload(token) {
7463
+ const parts = token.split(".");
7464
+ if (parts.length !== 3) return null;
7465
+ try {
7466
+ const b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
7467
+ const pad = "=".repeat((4 - b64.length % 4) % 4);
7468
+ const decoded = typeof atob === "function" ? atob(b64 + pad) : Buffer.from(b64 + pad, "base64").toString("utf-8");
7469
+ return JSON.parse(decoded);
7470
+ } catch {
7471
+ return null;
7472
+ }
7473
+ }
7474
+ function jwtToNeetruUser(token) {
7475
+ const payload = decodeJwtPayload(token);
7476
+ if (!payload || typeof payload.sub !== "string") return null;
7477
+ if (typeof payload.exp === "number" && payload.exp * 1e3 < Date.now()) {
7478
+ return null;
7479
+ }
7480
+ return {
7481
+ uid: payload.sub,
7482
+ email: typeof payload.email === "string" ? payload.email : "",
7483
+ emailVerified: typeof payload.email_verified === "boolean" ? payload.email_verified : void 0,
7484
+ displayName: typeof payload.name === "string" ? payload.name : void 0,
7485
+ photoURL: typeof payload.picture === "string" ? payload.picture : void 0,
7486
+ isStaff: payload.is_staff === true,
7487
+ isCustomer: payload.is_customer === true,
7488
+ tenantId: typeof payload.tenant_id === "string" ? payload.tenant_id : void 0,
7489
+ ...payload
7490
+ };
7491
+ }
7492
+
7371
7493
  // src/auth.ts
7372
7494
  function readEnvApiKey() {
7373
7495
  try {
@@ -7388,7 +7510,7 @@ function resolveEnv(configEnv) {
7388
7510
  }
7389
7511
  try {
7390
7512
  const g = globalThis.NEETRU_ENV;
7391
- if (g === "dev" || g === "workspace" || g === "prod") return g;
7513
+ if (g === "workspace" || g === "prod") return g;
7392
7514
  } catch {
7393
7515
  }
7394
7516
  return "prod";
@@ -7422,36 +7544,6 @@ function _jwtPayloadToUser(payload) {
7422
7544
  };
7423
7545
  }
7424
7546
  var OIDC_TX_KEY = "neetru_oauth_tx";
7425
- function resolveIdpOrigin(baseUrl) {
7426
- const overrideAuthUrl = typeof globalThis.NEETRU_AUTH_URL === "string" ? globalThis.NEETRU_AUTH_URL : null;
7427
- return overrideAuthUrl ?? baseUrl.replace(/^https?:\/\/api\./, "https://auth.");
7428
- }
7429
- function getWebCrypto() {
7430
- const c = globalThis.crypto;
7431
- if (!c || typeof c.getRandomValues !== "function" || !c.subtle) {
7432
- throw new exports.NeetruError(
7433
- "runtime_unsupported",
7434
- "auth.signIn requer WebCrypto (crypto.subtle) \u2014 indispon\xEDvel neste runtime. Use HTTPS (ou http://localhost) num browser moderno."
7435
- );
7436
- }
7437
- return c;
7438
- }
7439
- function base64UrlFromBytes(bytes) {
7440
- let str = "";
7441
- for (const b of bytes) str += String.fromCharCode(b);
7442
- const b64 = typeof btoa === "function" ? btoa(str) : Buffer.from(str, "binary").toString("base64");
7443
- return b64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
7444
- }
7445
- function randomUrlSafe(crypto2, byteLen) {
7446
- const bytes = new Uint8Array(byteLen);
7447
- crypto2.getRandomValues(bytes);
7448
- return base64UrlFromBytes(bytes);
7449
- }
7450
- async function pkceChallengeS256(crypto2, verifier) {
7451
- const data = new TextEncoder().encode(verifier);
7452
- const digest = await crypto2.subtle.digest("SHA-256", data);
7453
- return base64UrlFromBytes(new Uint8Array(digest));
7454
- }
7455
7547
  function cleanCallbackUrl(parsed) {
7456
7548
  try {
7457
7549
  const history = globalThis.history;
@@ -7485,36 +7577,6 @@ function createOidcAuthNamespace(config) {
7485
7577
  return null;
7486
7578
  }
7487
7579
  }
7488
- function decodeJwtPayload(token) {
7489
- const parts = token.split(".");
7490
- if (parts.length !== 3) return null;
7491
- try {
7492
- const b64 = parts[1].replace(/-/g, "+").replace(/_/g, "/");
7493
- const pad = "=".repeat((4 - b64.length % 4) % 4);
7494
- const decoded = typeof atob === "function" ? atob(b64 + pad) : Buffer.from(b64 + pad, "base64").toString("utf-8");
7495
- return JSON.parse(decoded);
7496
- } catch {
7497
- return null;
7498
- }
7499
- }
7500
- function tokenToUser(token) {
7501
- const payload = decodeJwtPayload(token);
7502
- if (!payload || typeof payload.sub !== "string") return null;
7503
- if (typeof payload.exp === "number" && payload.exp * 1e3 < Date.now()) {
7504
- return null;
7505
- }
7506
- return {
7507
- uid: payload.sub,
7508
- email: typeof payload.email === "string" ? payload.email : "",
7509
- emailVerified: typeof payload.email_verified === "boolean" ? payload.email_verified : void 0,
7510
- displayName: typeof payload.name === "string" ? payload.name : void 0,
7511
- photoURL: typeof payload.picture === "string" ? payload.picture : void 0,
7512
- isStaff: payload.is_staff === true,
7513
- isCustomer: payload.is_customer === true,
7514
- tenantId: typeof payload.tenant_id === "string" ? payload.tenant_id : void 0,
7515
- ...payload
7516
- };
7517
- }
7518
7580
  function loadCachedUser() {
7519
7581
  if (cachedUser) {
7520
7582
  const exp = cachedUser.exp;
@@ -7535,7 +7597,7 @@ function createOidcAuthNamespace(config) {
7535
7597
  attemptSilentRefresh();
7536
7598
  return null;
7537
7599
  }
7538
- const user = tokenToUser(token);
7600
+ const user = jwtToNeetruUser(token);
7539
7601
  if (!user) {
7540
7602
  storage.removeItem(STORAGE_KEY);
7541
7603
  attemptSilentRefresh();
@@ -7606,7 +7668,7 @@ function createOidcAuthNamespace(config) {
7606
7668
  if (!res.ok || typeof payload?.error === "string") return false;
7607
7669
  const idToken = payload?.id_token;
7608
7670
  if (typeof idToken !== "string" || idToken.length === 0) return false;
7609
- const user = tokenToUser(idToken);
7671
+ const user = jwtToNeetruUser(idToken);
7610
7672
  if (!user) return false;
7611
7673
  const storage = getStorage();
7612
7674
  storage?.setItem(STORAGE_KEY, idToken);
@@ -7652,17 +7714,7 @@ function createOidcAuthNamespace(config) {
7652
7714
  }, msUntilExpiry + 1);
7653
7715
  }
7654
7716
  function resolveClientId() {
7655
- let clientId = config.oidcClientId;
7656
- if (!clientId && config.apiKey) {
7657
- clientId = parseApiKey(config.apiKey).keyId;
7658
- }
7659
- if (!clientId) {
7660
- throw new exports.NeetruError(
7661
- "invalid_config",
7662
- "auth OIDC requer `oidcClientId` (ou `apiKey`) configurado para montar o client_id."
7663
- );
7664
- }
7665
- return clientId;
7717
+ return resolveOidcClientId(config);
7666
7718
  }
7667
7719
  async function handleRedirectCallback(currentUrl) {
7668
7720
  const href = currentUrl ?? (typeof globalThis.location !== "undefined" ? globalThis.location.href : void 0);
@@ -7780,7 +7832,7 @@ function createOidcAuthNamespace(config) {
7780
7832
  "nonce do id_token n\xE3o confere com o da transa\xE7\xE3o OIDC (poss\xEDvel replay). Token descartado."
7781
7833
  );
7782
7834
  }
7783
- const user = tokenToUser(idToken);
7835
+ const user = jwtToNeetruUser(idToken);
7784
7836
  if (!user) {
7785
7837
  throw new exports.NeetruError(
7786
7838
  "token_exchange_failed",
@@ -7825,15 +7877,15 @@ function createOidcAuthNamespace(config) {
7825
7877
  };
7826
7878
  session.setItem(OIDC_TX_KEY, JSON.stringify(tx));
7827
7879
  const idpOrigin = resolveIdpOrigin(config.baseUrl);
7828
- const url = new URL("/api/v1/oauth/authorize", idpOrigin);
7829
- url.searchParams.set("response_type", "code");
7830
- url.searchParams.set("client_id", clientId);
7831
- url.searchParams.set("redirect_uri", redirectUri);
7832
- url.searchParams.set("scope", scope);
7833
- url.searchParams.set("state", state);
7834
- url.searchParams.set("nonce", nonce);
7835
- url.searchParams.set("code_challenge", codeChallenge);
7836
- url.searchParams.set("code_challenge_method", "S256");
7880
+ const url = buildAuthorizeUrl({
7881
+ idpOrigin,
7882
+ clientId,
7883
+ redirectUri,
7884
+ scope,
7885
+ state,
7886
+ nonce,
7887
+ codeChallenge
7888
+ });
7837
7889
  globalThis.location.assign(url.toString());
7838
7890
  return;
7839
7891
  }
@@ -7848,7 +7900,7 @@ function createOidcAuthNamespace(config) {
7848
7900
  const storage = getStorage();
7849
7901
  const token = storage?.getItem(STORAGE_KEY) ?? null;
7850
7902
  if (!token) return null;
7851
- return tokenToUser(token) ? token : null;
7903
+ return jwtToNeetruUser(token) ? token : null;
7852
7904
  },
7853
7905
  async signOut() {
7854
7906
  const storage = getStorage();
@@ -7973,7 +8025,7 @@ function createNeetruClient(config = {}) {
7973
8025
  productId: config.productId,
7974
8026
  tenantId: config.tenantId
7975
8027
  });
7976
- const isDev = env === "dev";
8028
+ const isDev = env === "dev" && !isProductionRuntime();
7977
8029
  const auth = config.mocks?.auth ?? (isDev ? new MockAuth({ ...DEV_FIXTURE_USER }) : createOidcAuthNamespace(resolved));
7978
8030
  const usage = config.mocks?.usage ?? (isDev ? new MockUsage() : createUsageNamespace(resolved));
7979
8031
  const support = config.mocks?.support ?? (isDev ? new MockSupport() : createSupportNamespace(resolved));
@@ -8011,7 +8063,7 @@ function getServerNeetruClient(config = {}) {
8011
8063
  init_errors();
8012
8064
  init_db_errors();
8013
8065
  init_http();
8014
- var VERSION = "3.4.6";
8066
+ var VERSION = "3.6.0";
8015
8067
 
8016
8068
  exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
8017
8069
  exports.DEV_FIXTURE_USER = DEV_FIXTURE_USER;