@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.
- package/CHANGELOG.md +24 -0
- package/dist/ai.cjs +17 -13
- package/dist/ai.cjs.map +1 -1
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +17 -13
- package/dist/ai.mjs.map +1 -1
- package/dist/auth.cjs +57 -23
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +2 -2
- package/dist/auth.d.ts +2 -2
- package/dist/auth.mjs +57 -23
- package/dist/auth.mjs.map +1 -1
- package/dist/catalog.cjs +19 -4
- package/dist/catalog.cjs.map +1 -1
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +19 -4
- package/dist/catalog.mjs.map +1 -1
- package/dist/checkout.cjs +11 -3
- package/dist/checkout.cjs.map +1 -1
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +11 -3
- package/dist/checkout.mjs.map +1 -1
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +17 -7
- package/dist/db.cjs.map +1 -1
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +17 -7
- package/dist/db.mjs.map +1 -1
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +58 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -2
- package/dist/index.d.ts +30 -2
- package/dist/index.mjs +58 -24
- package/dist/index.mjs.map +1 -1
- package/dist/mocks.cjs +17 -0
- package/dist/mocks.cjs.map +1 -1
- package/dist/mocks.d.cts +5 -1
- package/dist/mocks.d.ts +5 -1
- package/dist/mocks.mjs +17 -0
- package/dist/mocks.mjs.map +1 -1
- package/dist/notifications.cjs +11 -3
- package/dist/notifications.cjs.map +1 -1
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +11 -3
- package/dist/notifications.mjs.map +1 -1
- package/dist/react.cjs +36 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +36 -2
- package/dist/react.mjs.map +1 -1
- package/dist/support.cjs +15 -4
- package/dist/support.cjs.map +1 -1
- package/dist/support.d.cts +1 -1
- package/dist/support.d.ts +1 -1
- package/dist/support.mjs +15 -4
- package/dist/support.mjs.map +1 -1
- package/dist/telemetry.cjs +11 -3
- package/dist/telemetry.cjs.map +1 -1
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +11 -3
- package/dist/telemetry.mjs.map +1 -1
- package/dist/{types-nnztVk7G.d.ts → types-BPATkXYu.d.ts} +35 -7
- package/dist/{types-DIVZl7nO.d.cts → types-Du_iioJ7.d.cts} +35 -7
- package/dist/usage.cjs +11 -3
- package/dist/usage.cjs.map +1 -1
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +11 -3
- package/dist/usage.mjs.map +1 -1
- package/dist/webhooks.cjs +17 -4
- package/dist/webhooks.cjs.map +1 -1
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +17 -4
- package/dist/webhooks.mjs.map +1 -1
- package/package.json +4 -1
package/dist/entitlements.d.cts
CHANGED
package/dist/entitlements.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Y as NeetruDb, E as DbCollectionRef, P as FieldSentinel, K as DbQuery } from './types-
|
|
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-
|
|
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
|
|
84
|
+
function readInjectedSdkVersion() {
|
|
84
85
|
try {
|
|
85
|
-
|
|
86
|
-
if (ver) return parseInt(ver.split(".")[0] ?? "3", 10);
|
|
86
|
+
return "3.5.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
|
|
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
|
-
*
|
|
542
|
-
* disparou). Emite um lease NOVO e faz o swap do pool interno
|
|
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 =
|
|
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") {
|
|
@@ -7388,7 +7422,7 @@ function resolveEnv(configEnv) {
|
|
|
7388
7422
|
}
|
|
7389
7423
|
try {
|
|
7390
7424
|
const g = globalThis.NEETRU_ENV;
|
|
7391
|
-
if (g === "
|
|
7425
|
+
if (g === "workspace" || g === "prod") return g;
|
|
7392
7426
|
} catch {
|
|
7393
7427
|
}
|
|
7394
7428
|
return "prod";
|
|
@@ -7973,7 +8007,7 @@ function createNeetruClient(config = {}) {
|
|
|
7973
8007
|
productId: config.productId,
|
|
7974
8008
|
tenantId: config.tenantId
|
|
7975
8009
|
});
|
|
7976
|
-
const isDev = env === "dev";
|
|
8010
|
+
const isDev = env === "dev" && !isProductionRuntime();
|
|
7977
8011
|
const auth = config.mocks?.auth ?? (isDev ? new MockAuth({ ...DEV_FIXTURE_USER }) : createOidcAuthNamespace(resolved));
|
|
7978
8012
|
const usage = config.mocks?.usage ?? (isDev ? new MockUsage() : createUsageNamespace(resolved));
|
|
7979
8013
|
const support = config.mocks?.support ?? (isDev ? new MockSupport() : createSupportNamespace(resolved));
|
|
@@ -8011,7 +8045,7 @@ function getServerNeetruClient(config = {}) {
|
|
|
8011
8045
|
init_errors();
|
|
8012
8046
|
init_db_errors();
|
|
8013
8047
|
init_http();
|
|
8014
|
-
var VERSION = "3.
|
|
8048
|
+
var VERSION = "3.5.0";
|
|
8015
8049
|
|
|
8016
8050
|
exports.DEFAULT_BASE_URL = DEFAULT_BASE_URL;
|
|
8017
8051
|
exports.DEV_FIXTURE_USER = DEV_FIXTURE_USER;
|