@neetru/sdk 3.4.7 → 3.5.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 (88) hide show
  1. package/CHANGELOG.md +24 -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 +57 -23
  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 +57 -23
  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 +58 -24
  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 +58 -24
  43. package/dist/index.mjs.map +1 -1
  44. package/dist/mocks.cjs +17 -0
  45. package/dist/mocks.cjs.map +1 -1
  46. package/dist/mocks.d.cts +5 -1
  47. package/dist/mocks.d.ts +5 -1
  48. package/dist/mocks.mjs +17 -0
  49. package/dist/mocks.mjs.map +1 -1
  50. package/dist/notifications.cjs +11 -3
  51. package/dist/notifications.cjs.map +1 -1
  52. package/dist/notifications.d.cts +1 -1
  53. package/dist/notifications.d.ts +1 -1
  54. package/dist/notifications.mjs +11 -3
  55. package/dist/notifications.mjs.map +1 -1
  56. package/dist/react.cjs +36 -2
  57. package/dist/react.cjs.map +1 -1
  58. package/dist/react.d.cts +1 -1
  59. package/dist/react.d.ts +1 -1
  60. package/dist/react.mjs +36 -2
  61. package/dist/react.mjs.map +1 -1
  62. package/dist/support.cjs +15 -4
  63. package/dist/support.cjs.map +1 -1
  64. package/dist/support.d.cts +1 -1
  65. package/dist/support.d.ts +1 -1
  66. package/dist/support.mjs +15 -4
  67. package/dist/support.mjs.map +1 -1
  68. package/dist/telemetry.cjs +11 -3
  69. package/dist/telemetry.cjs.map +1 -1
  70. package/dist/telemetry.d.cts +1 -1
  71. package/dist/telemetry.d.ts +1 -1
  72. package/dist/telemetry.mjs +11 -3
  73. package/dist/telemetry.mjs.map +1 -1
  74. package/dist/{types-nnztVk7G.d.ts → types-BPATkXYu.d.ts} +35 -7
  75. package/dist/{types-DIVZl7nO.d.cts → types-Du_iioJ7.d.cts} +35 -7
  76. package/dist/usage.cjs +11 -3
  77. package/dist/usage.cjs.map +1 -1
  78. package/dist/usage.d.cts +1 -1
  79. package/dist/usage.d.ts +1 -1
  80. package/dist/usage.mjs +11 -3
  81. package/dist/usage.mjs.map +1 -1
  82. package/dist/webhooks.cjs +17 -4
  83. package/dist/webhooks.cjs.map +1 -1
  84. package/dist/webhooks.d.cts +1 -1
  85. package/dist/webhooks.d.ts +1 -1
  86. package/dist/webhooks.mjs +17 -4
  87. package/dist/webhooks.mjs.map +1 -1
  88. package/package.json +4 -1
package/dist/index.d.cts CHANGED
@@ -1,9 +1,37 @@
1
1
  export { createNeetruClient, getServerNeetruClient } from './auth.cjs';
2
2
  export { NeetruError, NeetruErrorCode } from './errors.cjs';
3
- export { A as AiChatChoice, a as AiChatMessage, b as AiChatOptions, c as AiChatResult, d as AiChatUsage, e as AiContentPart, f as AiImageUrlPart, g as AiNamespace, h as AiResponseFormat, i as AiStreamHandle, j as AiStreamMeta, k as AiTextPart, l as AuthNamespace, m as AuthStateListener, C as CatalogListOptions, n as CatalogListResponse, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, v as CompleteSignInResult, y as CreateTicketInput, D as DEFAULT_BASE_URL, z as DbBatchOp, B as DbChangeType, E as DbCollectionRef, F as DbDoc, G as DbDocRef, H as DbGetResult, I as DbListResult, J as DbNamespace, K as DbQuery, L as DbSqlLease, M as DbWhereFilter, O as EntitlementCheck, P as FieldSentinel, Q as IncrementSentinel, R as ListNotificationsOptions, S as MockCheckout, T as MockNotifications, U as MockWebhooks, V as NEETRU_SENTINEL_KEY, W as NeetruClient, X as NeetruClientConfig, Y as NeetruDb, _ as NeetruDbEngine, $ as NeetruDbError, a0 as NeetruDbErrorCode, a1 as NeetruDbOptions, a2 as NeetruDbTransport, a3 as NeetruEnv, a4 as NeetruSqlClient, a5 as NeetruUser, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a8 as Product, a9 as ProductNotification, aa as ProductNotificationSeverity, ab as ProductPlan, ac as ProductStatus, ae as RedirectCallbackResult, af as RegisterWebhookInput, ag as ResolvedConfig, ah as SendNotificationInput, ai as ServerTimestampSentinel, aj as SignInOptions, al as SupportNamespace, am as SupportSeverity, an as SupportStatus, ao as SupportTicket, ar as TelemetryEventAck, as as TelemetryEventInput, aw as UsageEventInput, ax as UsageNamespace, ay as UsageQuota, az as VerifyTokenOptions, aA as VerifyWebhookRequestOptions, aB as VerifyWebhookRequestResult, aC as WebhookEndpoint, aD as WebhookEvent, aE as WebhookScopeOptions, aF as WebhookTestResult, aG as WebhooksNamespace, aH as WithFieldSentinels, aJ as createAiNamespace, aK as createCheckoutNamespace, aL as createNeetruDb, aM as createNotificationsNamespace, aO as createWebhooksNamespace, aQ as increment, aR as isFieldSentinel, aS as isIncrementSentinel, aT as isServerTimestampSentinel, aU as serverTimestamp, aV as verifyWebhookRequest, aW as verifyWebhookSignature } from './types-DIVZl7nO.cjs';
3
+ export { A as AiChatChoice, a as AiChatMessage, b as AiChatOptions, c as AiChatResult, d as AiChatUsage, e as AiContentPart, f as AiImageUrlPart, g as AiNamespace, h as AiResponseFormat, i as AiStreamHandle, j as AiStreamMeta, k as AiTextPart, l as AuthNamespace, m as AuthStateListener, C as CatalogListOptions, n as CatalogListResponse, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, v as CompleteSignInResult, y as CreateTicketInput, D as DEFAULT_BASE_URL, z as DbBatchOp, B as DbChangeType, E as DbCollectionRef, F as DbDoc, G as DbDocRef, H as DbGetResult, I as DbListResult, J as DbNamespace, K as DbQuery, L as DbSqlLease, M as DbWhereFilter, O as EntitlementCheck, P as FieldSentinel, Q as IncrementSentinel, R as ListNotificationsOptions, S as MockCheckout, T as MockNotifications, U as MockWebhooks, V as NEETRU_SENTINEL_KEY, W as NeetruClient, X as NeetruClientConfig, Y as NeetruDb, _ as NeetruDbEngine, $ as NeetruDbError, a0 as NeetruDbErrorCode, a1 as NeetruDbOptions, a2 as NeetruDbTransport, a3 as NeetruEnv, a4 as NeetruSqlClient, a5 as NeetruUser, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a8 as Product, a9 as ProductNotification, aa as ProductNotificationSeverity, ab as ProductPlan, ac as ProductStatus, ae as RedirectCallbackResult, af as RegisterWebhookInput, ag as ResolvedConfig, ah as SendNotificationInput, ai as ServerTimestampSentinel, aj as SignInOptions, al as SupportNamespace, am as SupportSeverity, an as SupportStatus, ao as SupportTicket, ar as TelemetryEventAck, as as TelemetryEventInput, aw as UsageEventInput, ax as UsageNamespace, ay as UsageQuota, az as VerifyTokenOptions, aA as VerifyWebhookRequestOptions, aB as VerifyWebhookRequestResult, aC as WebhookEndpoint, aD as WebhookEvent, aE as WebhookScopeOptions, aF as WebhookTestResult, aG as WebhooksNamespace, aH as WithFieldSentinels, aJ as createAiNamespace, aK as createCheckoutNamespace, aL as createNeetruDb, aM as createNotificationsNamespace, aO as createWebhooksNamespace, aQ as increment, aR as isFieldSentinel, aS as isIncrementSentinel, aT as isServerTimestampSentinel, aU as serverTimestamp, aV as verifyWebhookRequest, aW as verifyWebhookSignature } from './types-Du_iioJ7.cjs';
4
4
  export { DEV_FIXTURE_USER, MockAi, MockAuth, MockAuthOptions, MockDb, MockEntitlements, MockSupport, MockUsage } from './mocks.cjs';
5
5
  import 'drizzle-orm/node-postgres';
6
6
 
7
+ /**
8
+ * HTTP transport interno do SDK.
9
+ *
10
+ * Responsabilidades:
11
+ * - Construir URL absoluta a partir de `baseUrl` + path
12
+ * - Injetar Bearer token quando `requireAuth=true`
13
+ * - Mapear status HTTP → `NeetruError` com `code` estável
14
+ * - Parse defensivo de JSON (não lança em body vazio em 204)
15
+ * - Retry/backoff exponencial em `rate_limited` (429), `server_error` (5xx)
16
+ * e `network_error` (timeout/falha de rede). Honra `Retry-After` quando
17
+ * presente.
18
+ * - **Captura `X-Neetru-Version`** das respostas e emite `console.warn` quando
19
+ * o Core está abaixo da versão mínima para a major do SDK.
20
+ *
21
+ * Política de retries (mudança breaking 3.0):
22
+ * - GET/HEAD: default 2 retries (3 tentativas total) — idempotente, seguro.
23
+ * - POST/PUT/PATCH/DELETE: default **0 retries** — mutations podem duplicar
24
+ * side effects (ex: `usage.report` incrementa contador). Caller pode
25
+ * reativar passando `retries: N` explicitamente ou usar `Idempotency-Key`
26
+ * header (gerado automaticamente se `opts.idempotencyKey=true`).
27
+ *
28
+ * Idempotency-Key (3.0):
29
+ * - `opts.idempotencyKey === true` → SDK gera UUID v4 e injeta header.
30
+ * - `opts.idempotencyKey === 'uuid-string'` → usa o valor passado.
31
+ * - Caller mantém retentos client-side se quiser; Core dedup serverside
32
+ * (vide `docs/CORE_CHANGES_REQUIRED.md` §2).
33
+ */
34
+
7
35
  /**
8
36
  * Verifica se a versão do Core (`X-Neetru-Version`) é compatível com a SDK major.
9
37
  * Emite `console.warn` quando incompatível (uma vez por processo por versão detectada).
@@ -42,6 +70,6 @@ declare function checkCoreVersionCompat(coreVersion: string): void;
42
70
  */
43
71
 
44
72
  /** Versão do SDK — exportada explicitamente pra detecção em runtime. */
45
- declare const VERSION: "3.4.6";
73
+ declare const VERSION: "3.5.0";
46
74
 
47
75
  export { VERSION, checkCoreVersionCompat };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,37 @@
1
1
  export { createNeetruClient, getServerNeetruClient } from './auth.js';
2
2
  export { NeetruError, NeetruErrorCode } from './errors.js';
3
- export { A as AiChatChoice, a as AiChatMessage, b as AiChatOptions, c as AiChatResult, d as AiChatUsage, e as AiContentPart, f as AiImageUrlPart, g as AiNamespace, h as AiResponseFormat, i as AiStreamHandle, j as AiStreamMeta, k as AiTextPart, l as AuthNamespace, m as AuthStateListener, C as CatalogListOptions, n as CatalogListResponse, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, v as CompleteSignInResult, y as CreateTicketInput, D as DEFAULT_BASE_URL, z as DbBatchOp, B as DbChangeType, E as DbCollectionRef, F as DbDoc, G as DbDocRef, H as DbGetResult, I as DbListResult, J as DbNamespace, K as DbQuery, L as DbSqlLease, M as DbWhereFilter, O as EntitlementCheck, P as FieldSentinel, Q as IncrementSentinel, R as ListNotificationsOptions, S as MockCheckout, T as MockNotifications, U as MockWebhooks, V as NEETRU_SENTINEL_KEY, W as NeetruClient, X as NeetruClientConfig, Y as NeetruDb, _ as NeetruDbEngine, $ as NeetruDbError, a0 as NeetruDbErrorCode, a1 as NeetruDbOptions, a2 as NeetruDbTransport, a3 as NeetruEnv, a4 as NeetruSqlClient, a5 as NeetruUser, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a8 as Product, a9 as ProductNotification, aa as ProductNotificationSeverity, ab as ProductPlan, ac as ProductStatus, ae as RedirectCallbackResult, af as RegisterWebhookInput, ag as ResolvedConfig, ah as SendNotificationInput, ai as ServerTimestampSentinel, aj as SignInOptions, al as SupportNamespace, am as SupportSeverity, an as SupportStatus, ao as SupportTicket, ar as TelemetryEventAck, as as TelemetryEventInput, aw as UsageEventInput, ax as UsageNamespace, ay as UsageQuota, az as VerifyTokenOptions, aA as VerifyWebhookRequestOptions, aB as VerifyWebhookRequestResult, aC as WebhookEndpoint, aD as WebhookEvent, aE as WebhookScopeOptions, aF as WebhookTestResult, aG as WebhooksNamespace, aH as WithFieldSentinels, aJ as createAiNamespace, aK as createCheckoutNamespace, aL as createNeetruDb, aM as createNotificationsNamespace, aO as createWebhooksNamespace, aQ as increment, aR as isFieldSentinel, aS as isIncrementSentinel, aT as isServerTimestampSentinel, aU as serverTimestamp, aV as verifyWebhookRequest, aW as verifyWebhookSignature } from './types-nnztVk7G.js';
3
+ export { A as AiChatChoice, a as AiChatMessage, b as AiChatOptions, c as AiChatResult, d as AiChatUsage, e as AiContentPart, f as AiImageUrlPart, g as AiNamespace, h as AiResponseFormat, i as AiStreamHandle, j as AiStreamMeta, k as AiTextPart, l as AuthNamespace, m as AuthStateListener, C as CatalogListOptions, n as CatalogListResponse, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, v as CompleteSignInResult, y as CreateTicketInput, D as DEFAULT_BASE_URL, z as DbBatchOp, B as DbChangeType, E as DbCollectionRef, F as DbDoc, G as DbDocRef, H as DbGetResult, I as DbListResult, J as DbNamespace, K as DbQuery, L as DbSqlLease, M as DbWhereFilter, O as EntitlementCheck, P as FieldSentinel, Q as IncrementSentinel, R as ListNotificationsOptions, S as MockCheckout, T as MockNotifications, U as MockWebhooks, V as NEETRU_SENTINEL_KEY, W as NeetruClient, X as NeetruClientConfig, Y as NeetruDb, _ as NeetruDbEngine, $ as NeetruDbError, a0 as NeetruDbErrorCode, a1 as NeetruDbOptions, a2 as NeetruDbTransport, a3 as NeetruEnv, a4 as NeetruSqlClient, a5 as NeetruUser, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a8 as Product, a9 as ProductNotification, aa as ProductNotificationSeverity, ab as ProductPlan, ac as ProductStatus, ae as RedirectCallbackResult, af as RegisterWebhookInput, ag as ResolvedConfig, ah as SendNotificationInput, ai as ServerTimestampSentinel, aj as SignInOptions, al as SupportNamespace, am as SupportSeverity, an as SupportStatus, ao as SupportTicket, ar as TelemetryEventAck, as as TelemetryEventInput, aw as UsageEventInput, ax as UsageNamespace, ay as UsageQuota, az as VerifyTokenOptions, aA as VerifyWebhookRequestOptions, aB as VerifyWebhookRequestResult, aC as WebhookEndpoint, aD as WebhookEvent, aE as WebhookScopeOptions, aF as WebhookTestResult, aG as WebhooksNamespace, aH as WithFieldSentinels, aJ as createAiNamespace, aK as createCheckoutNamespace, aL as createNeetruDb, aM as createNotificationsNamespace, aO as createWebhooksNamespace, aQ as increment, aR as isFieldSentinel, aS as isIncrementSentinel, aT as isServerTimestampSentinel, aU as serverTimestamp, aV as verifyWebhookRequest, aW as verifyWebhookSignature } from './types-BPATkXYu.js';
4
4
  export { DEV_FIXTURE_USER, MockAi, MockAuth, MockAuthOptions, MockDb, MockEntitlements, MockSupport, MockUsage } from './mocks.js';
5
5
  import 'drizzle-orm/node-postgres';
6
6
 
7
+ /**
8
+ * HTTP transport interno do SDK.
9
+ *
10
+ * Responsabilidades:
11
+ * - Construir URL absoluta a partir de `baseUrl` + path
12
+ * - Injetar Bearer token quando `requireAuth=true`
13
+ * - Mapear status HTTP → `NeetruError` com `code` estável
14
+ * - Parse defensivo de JSON (não lança em body vazio em 204)
15
+ * - Retry/backoff exponencial em `rate_limited` (429), `server_error` (5xx)
16
+ * e `network_error` (timeout/falha de rede). Honra `Retry-After` quando
17
+ * presente.
18
+ * - **Captura `X-Neetru-Version`** das respostas e emite `console.warn` quando
19
+ * o Core está abaixo da versão mínima para a major do SDK.
20
+ *
21
+ * Política de retries (mudança breaking 3.0):
22
+ * - GET/HEAD: default 2 retries (3 tentativas total) — idempotente, seguro.
23
+ * - POST/PUT/PATCH/DELETE: default **0 retries** — mutations podem duplicar
24
+ * side effects (ex: `usage.report` incrementa contador). Caller pode
25
+ * reativar passando `retries: N` explicitamente ou usar `Idempotency-Key`
26
+ * header (gerado automaticamente se `opts.idempotencyKey=true`).
27
+ *
28
+ * Idempotency-Key (3.0):
29
+ * - `opts.idempotencyKey === true` → SDK gera UUID v4 e injeta header.
30
+ * - `opts.idempotencyKey === 'uuid-string'` → usa o valor passado.
31
+ * - Caller mantém retentos client-side se quiser; Core dedup serverside
32
+ * (vide `docs/CORE_CHANGES_REQUIRED.md` §2).
33
+ */
34
+
7
35
  /**
8
36
  * Verifica se a versão do Core (`X-Neetru-Version`) é compatível com a SDK major.
9
37
  * Emite `console.warn` quando incompatível (uma vez por processo por versão detectada).
@@ -42,6 +70,6 @@ declare function checkCoreVersionCompat(coreVersion: string): void;
42
70
  */
43
71
 
44
72
  /** Versão do SDK — exportada explicitamente pra detecção em runtime. */
45
- declare const VERSION: "3.4.6";
73
+ declare const VERSION: "3.5.0";
46
74
 
47
75
  export { VERSION, checkCoreVersionCompat };
package/dist/index.mjs CHANGED
@@ -62,7 +62,8 @@ var init_idempotency = __esm({
62
62
  var http_exports = {};
63
63
  __export(http_exports, {
64
64
  checkCoreVersionCompat: () => checkCoreVersionCompat,
65
- httpRequest: () => httpRequest
65
+ httpRequest: () => httpRequest,
66
+ statusToCode: () => statusToCode
66
67
  });
67
68
  function stripRevision(v) {
68
69
  return v.split("+")[0] ?? v;
@@ -78,12 +79,16 @@ function compareCalVer(a, b) {
78
79
  }
79
80
  return 0;
80
81
  }
81
- function getSdkMajor() {
82
+ function readInjectedSdkVersion() {
82
83
  try {
83
- const ver = globalThis.__NEETRU_SDK_VERSION__;
84
- if (ver) return parseInt(ver.split(".")[0] ?? "3", 10);
84
+ return "3.5.0";
85
85
  } catch {
86
+ return void 0;
86
87
  }
88
+ }
89
+ function getSdkMajor() {
90
+ const ver = readInjectedSdkVersion();
91
+ if (ver) return parseInt(ver.split(".")[0] ?? "3", 10);
87
92
  return 3;
88
93
  }
89
94
  function checkCoreVersionCompat(coreVersion) {
@@ -161,6 +166,10 @@ async function httpRequest(config, opts) {
161
166
  accept: "application/json",
162
167
  ...opts.headers
163
168
  };
169
+ const sdkVersion = readInjectedSdkVersion();
170
+ if (sdkVersion) {
171
+ headers["x-neetru-sdk-version"] = sdkVersion;
172
+ }
164
173
  if (opts.requireAuth) {
165
174
  if (!config.apiKey) {
166
175
  throw new NeetruError(
@@ -525,7 +534,7 @@ var init_lease = __esm({
525
534
  void this._doRenew();
526
535
  }, MIN_RENEWAL_DELAY_MS);
527
536
  console.warn(
528
- `[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):`,
537
+ `[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):`,
529
538
  err instanceof Error ? err.message : err
530
539
  );
531
540
  return;
@@ -536,8 +545,9 @@ var init_lease = __esm({
536
545
  /**
537
546
  * Recuperação REATIVA: chamado pelo wrapper resiliente (`resilient-pool.ts`)
538
547
  * quando uma query plana falha num erro de ESTABELECIMENTO de conexão (cert
539
- * mTLS expirado no meio de uma request, ou timer de renovação que não
540
- * disparou). Emite um lease NOVO e faz o swap do pool interno do wrapper com
548
+ * TLS efêmero do servidor expirado no meio de uma request, ou timer de
549
+ * renovação que não disparou). Emite um lease NOVO e faz o swap do pool interno
550
+ * do wrapper com
541
551
  * o certificado fresco; o wrapper então re-tenta a query 1x no pool novo.
542
552
  *
543
553
  * Vai DIRETO ao lease novo (sem `leaseId`) — a conexão falhou porque o
@@ -1137,7 +1147,14 @@ function toProduct(raw) {
1137
1147
  if (Array.isArray(r.plans)) {
1138
1148
  product.plans = r.plans.filter(
1139
1149
  (p) => typeof p === "object" && p !== null && typeof p.id === "string" && typeof p.name === "string"
1140
- );
1150
+ ).map((p) => {
1151
+ const plan = { id: p.id, name: p.name };
1152
+ if (typeof p.amountCents === "number") plan.amountCents = p.amountCents;
1153
+ if (Array.isArray(p.features) && p.features.every((f) => typeof f === "string")) {
1154
+ plan.features = p.features;
1155
+ }
1156
+ return plan;
1157
+ });
1141
1158
  }
1142
1159
  return product;
1143
1160
  }
@@ -1717,7 +1734,10 @@ function createSupportNamespace(config) {
1717
1734
  await httpRequest(config, {
1718
1735
  method: "POST",
1719
1736
  path: `/api/sdk/v1/support/tickets/${encodeURIComponent(ticketId)}/satisfaction-attempt`,
1720
- requireAuth: true
1737
+ requireAuth: true,
1738
+ // Incrementa satisfactionAttempts += 1 no Core — sem idempotencyKey,
1739
+ // um retry de rede infla o contador (mesmo padrão de createTicket acima).
1740
+ idempotencyKey: true
1721
1741
  });
1722
1742
  },
1723
1743
  /**
@@ -5919,7 +5939,12 @@ function createWebhooksNamespace(config) {
5919
5939
  events: input.events,
5920
5940
  ...input.secret ? { secret: input.secret } : {}
5921
5941
  },
5922
- requireAuth: true
5942
+ requireAuth: true,
5943
+ // Sem isso, um retry de rede (app-level; SDK default é 0 retries em
5944
+ // POST) podia registrar o MESMO webhook duas vezes → entrega
5945
+ // duplicada de todo evento futuro pro endpoint do cliente. Core
5946
+ // dedup TTL 24h (mesmo padrão de usage.report/support.createTicket).
5947
+ idempotencyKey: true
5923
5948
  });
5924
5949
  return toEndpoint(raw);
5925
5950
  },
@@ -6472,16 +6497,6 @@ async function safeJson2(res) {
6472
6497
  return void 0;
6473
6498
  }
6474
6499
  }
6475
- function statusToCode2(status) {
6476
- if (status === 401) return "unauthorized";
6477
- if (status === 403) return "forbidden";
6478
- if (status === 404) return "not_found";
6479
- if (status === 409) return "conflict";
6480
- if (status === 422 || status === 400) return "validation_failed";
6481
- if (status === 429) return "rate_limited";
6482
- if (status >= 500) return "server_error";
6483
- return "unknown";
6484
- }
6485
6500
  function joinUrl(baseUrl, path) {
6486
6501
  const base = baseUrl.replace(/\/+$/, "");
6487
6502
  const p = path.startsWith("/") ? path : `/${path}`;
@@ -6516,7 +6531,7 @@ async function aiFetch(config, body, signal, stream) {
6516
6531
  const requestId = res.headers.get("x-request-id") ?? res.headers.get("x-correlation-id") ?? void 0;
6517
6532
  if (!res.ok) {
6518
6533
  const parsed = await safeJson2(res);
6519
- let code = statusToCode2(res.status);
6534
+ let code = statusToCode(res.status);
6520
6535
  let message = `HTTP ${res.status}`;
6521
6536
  if (parsed && typeof parsed === "object" && "error" in parsed) {
6522
6537
  const errField = parsed.error;
@@ -6635,6 +6650,19 @@ function createAiNamespace(config) {
6635
6650
  // src/mocks.ts
6636
6651
  init_db_errors();
6637
6652
  init_errors();
6653
+
6654
+ // src/runtime-env.ts
6655
+ function isProductionRuntime() {
6656
+ try {
6657
+ if (typeof process !== "undefined" && process.env) {
6658
+ return process.env.NODE_ENV === "production";
6659
+ }
6660
+ } catch {
6661
+ }
6662
+ return false;
6663
+ }
6664
+
6665
+ // src/mocks.ts
6638
6666
  var DEV_FIXTURE_USER = Object.freeze({
6639
6667
  uid: "dev-fixture-uid-0001",
6640
6668
  email: "dev@neetru.local",
@@ -6651,6 +6679,12 @@ var MockAuth = class {
6651
6679
  this._user = initialUser;
6652
6680
  this._listeners = /* @__PURE__ */ new Set();
6653
6681
  this._allowUnsignedDecode = options?.allowUnsignedDecode ?? false;
6682
+ if (this._allowUnsignedDecode && isProductionRuntime()) {
6683
+ throw new NeetruError(
6684
+ "invalid_config",
6685
+ "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."
6686
+ );
6687
+ }
6654
6688
  if (this._allowUnsignedDecode) {
6655
6689
  const isTestEnv = typeof process !== "undefined" && (process.env?.NODE_ENV === "test" || process.env?.VITEST === "true" || process.env?.VITEST != null);
6656
6690
  if (!isTestEnv && typeof console !== "undefined") {
@@ -7386,7 +7420,7 @@ function resolveEnv(configEnv) {
7386
7420
  }
7387
7421
  try {
7388
7422
  const g = globalThis.NEETRU_ENV;
7389
- if (g === "dev" || g === "workspace" || g === "prod") return g;
7423
+ if (g === "workspace" || g === "prod") return g;
7390
7424
  } catch {
7391
7425
  }
7392
7426
  return "prod";
@@ -7971,7 +8005,7 @@ function createNeetruClient(config = {}) {
7971
8005
  productId: config.productId,
7972
8006
  tenantId: config.tenantId
7973
8007
  });
7974
- const isDev = env === "dev";
8008
+ const isDev = env === "dev" && !isProductionRuntime();
7975
8009
  const auth = config.mocks?.auth ?? (isDev ? new MockAuth({ ...DEV_FIXTURE_USER }) : createOidcAuthNamespace(resolved));
7976
8010
  const usage = config.mocks?.usage ?? (isDev ? new MockUsage() : createUsageNamespace(resolved));
7977
8011
  const support = config.mocks?.support ?? (isDev ? new MockSupport() : createSupportNamespace(resolved));
@@ -8009,7 +8043,7 @@ function getServerNeetruClient(config = {}) {
8009
8043
  init_errors();
8010
8044
  init_db_errors();
8011
8045
  init_http();
8012
- var VERSION = "3.4.6";
8046
+ var VERSION = "3.5.0";
8013
8047
 
8014
8048
  export { DEFAULT_BASE_URL, DEV_FIXTURE_USER, MockAi, MockAuth, MockCheckout, MockDb, MockEntitlements, MockNotifications, MockSupport, MockUsage, MockWebhooks, NEETRU_SENTINEL_KEY, NeetruDbError, NeetruError, VERSION, checkCoreVersionCompat, createAiNamespace, createCheckoutNamespace, createNeetruClient, createNeetruDb, createNotificationsNamespace, createWebhooksNamespace, getServerNeetruClient, increment, isFieldSentinel, isIncrementSentinel, isServerTimestampSentinel, serverTimestamp, verifyWebhookRequest, verifyWebhookSignature };
8015
8049
  //# sourceMappingURL=index.mjs.map