@neetru/sdk 3.7.0 → 3.8.1
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 +75 -0
- package/README.md +66 -1
- package/dist/ai.cjs +221 -177
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +221 -177
- package/dist/auth.cjs +1051 -868
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +1048 -865
- package/dist/catalog.cjs +164 -97
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +164 -97
- package/dist/checkout.cjs +182 -115
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +181 -114
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db.cjs +437 -345
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +455 -363
- package/dist/entitlements.cjs +17 -10
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs +17 -10
- package/dist/errors.cjs +15 -8
- package/dist/errors.d.cts +24 -3
- package/dist/errors.d.ts +24 -3
- package/dist/errors.mjs +14 -7
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/index.cjs +1544 -1190
- package/dist/index.d.cts +177 -3
- package/dist/index.d.ts +177 -3
- package/dist/index.mjs +1676 -1329
- package/dist/mobile.cjs +400 -181
- package/dist/mobile.d.cts +59 -4
- package/dist/mobile.d.ts +59 -4
- package/dist/mobile.mjs +400 -181
- package/dist/mocks.cjs +9 -2
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.mjs +9 -2
- package/dist/notifications.cjs +197 -130
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +196 -129
- package/dist/react.cjs +303 -282
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +295 -274
- package/dist/support.cjs +299 -229
- package/dist/support.d.cts +8 -4
- package/dist/support.d.ts +8 -4
- package/dist/support.mjs +298 -228
- package/dist/telemetry.cjs +234 -167
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +234 -167
- package/dist/{types-Dx0IrOSF.d.ts → types-BYPk_3HR.d.ts} +104 -17
- package/dist/{types-Bx4kTLmk.d.cts → types-yv3EDKg2.d.cts} +104 -17
- package/dist/usage.cjs +183 -116
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +183 -116
- package/dist/webhooks.cjs +215 -148
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +212 -145
- package/package.json +2 -1
package/dist/usage.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
// src/errors.ts
|
|
4
|
-
var
|
|
4
|
+
var d = class e extends Error {
|
|
5
5
|
code;
|
|
6
6
|
status;
|
|
7
7
|
requestId;
|
|
@@ -14,98 +14,161 @@ var s = class e extends Error {
|
|
|
14
14
|
* para um `NeetruDbErrorCode` mais específico (recuperável vs não).
|
|
15
15
|
*/
|
|
16
16
|
reason;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
/**
|
|
18
|
+
* 3.8.0: `x-correlation-id` da requisição que falhou. O SDK gera um UUID por
|
|
19
|
+
* chamada (ou usa o que o chamador passou) e manda no header; o Core grava o
|
|
20
|
+
* mesmo id nos logs/auditoria — cite-o ao abrir um ticket de suporte.
|
|
21
|
+
* `undefined` em erros que acontecem antes de qualquer requisição.
|
|
22
|
+
*/
|
|
23
|
+
correlationId;
|
|
24
|
+
constructor(t, r, n, i, o, a) {
|
|
25
|
+
super(r), this.name = "NeetruError", this.code = t, this.status = n, this.requestId = i, this.reason = o, this.correlationId = a, Object.setPrototypeOf(this, e.prototype);
|
|
19
26
|
}
|
|
20
27
|
};
|
|
21
28
|
|
|
22
29
|
// src/idempotency.ts
|
|
23
|
-
function
|
|
30
|
+
function T() {
|
|
24
31
|
let e = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
25
32
|
if (e && typeof e.randomUUID == "function")
|
|
26
33
|
return e.randomUUID();
|
|
27
|
-
throw new
|
|
34
|
+
throw new d(
|
|
28
35
|
"runtime_unsupported",
|
|
29
36
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
30
37
|
);
|
|
31
38
|
}
|
|
32
39
|
|
|
40
|
+
// src/correlation.ts
|
|
41
|
+
var S = "x-correlation-id";
|
|
42
|
+
var j = /^[A-Za-z0-9._:\-]+$/;
|
|
43
|
+
function x(e) {
|
|
44
|
+
return typeof e == "string" && e.length > 0 && e.length <= 128 && j.test(e);
|
|
45
|
+
}
|
|
46
|
+
function F() {
|
|
47
|
+
let e = globalThis.crypto;
|
|
48
|
+
try {
|
|
49
|
+
if (e && typeof e.randomUUID == "function") return e.randomUUID();
|
|
50
|
+
} catch {
|
|
51
|
+
}
|
|
52
|
+
let t = new Uint8Array(16), r = false;
|
|
53
|
+
try {
|
|
54
|
+
e && typeof e.getRandomValues == "function" && (e.getRandomValues(t), r = !0);
|
|
55
|
+
} catch {
|
|
56
|
+
r = false;
|
|
57
|
+
}
|
|
58
|
+
if (!r)
|
|
59
|
+
for (let i = 0; i < t.length; i++) t[i] = Math.floor(Math.random() * 256);
|
|
60
|
+
t[6] = t[6] & 15 | 64, t[8] = t[8] & 63 | 128;
|
|
61
|
+
let n = Array.from(t, (i) => i.toString(16).padStart(2, "0")).join("");
|
|
62
|
+
return `${n.slice(0, 8)}-${n.slice(8, 12)}-${n.slice(12, 16)}-${n.slice(16, 20)}-${n.slice(20)}`;
|
|
63
|
+
}
|
|
64
|
+
function D(e, t) {
|
|
65
|
+
let r, n = {};
|
|
66
|
+
for (let [o, a] of Object.entries(e)) {
|
|
67
|
+
if (o.toLowerCase() === S) {
|
|
68
|
+
x(a) && (r = a);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
n[o] = a;
|
|
72
|
+
}
|
|
73
|
+
let i = r ?? (x(t) ? t : void 0) ?? F();
|
|
74
|
+
return n[S] = i, { headers: n, correlationId: i };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/server-only-key.ts
|
|
78
|
+
function A() {
|
|
79
|
+
try {
|
|
80
|
+
let e = globalThis.navigator;
|
|
81
|
+
if (e && e.product === "ReactNative") return "react-native";
|
|
82
|
+
} catch {
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
let e = globalThis;
|
|
86
|
+
if (typeof e.window < "u" && typeof e.document < "u") return "browser";
|
|
87
|
+
} catch {
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
33
92
|
// src/http.ts
|
|
34
|
-
var
|
|
93
|
+
var H = {
|
|
35
94
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
36
95
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
37
96
|
3: "2026.05.1"
|
|
38
97
|
};
|
|
39
|
-
function
|
|
98
|
+
function v(e) {
|
|
40
99
|
return e.split("+")[0] ?? e;
|
|
41
100
|
}
|
|
42
|
-
function
|
|
43
|
-
let r =
|
|
44
|
-
for (let
|
|
45
|
-
let a = r[
|
|
46
|
-
if (a !==
|
|
101
|
+
function V(e, t) {
|
|
102
|
+
let r = v(e).split(".").map(Number), n = v(t).split(".").map(Number), i = Math.max(r.length, n.length);
|
|
103
|
+
for (let o = 0; o < i; o++) {
|
|
104
|
+
let a = r[o] ?? 0, c = n[o] ?? 0;
|
|
105
|
+
if (a !== c) return a - c;
|
|
47
106
|
}
|
|
48
107
|
return 0;
|
|
49
108
|
}
|
|
50
|
-
function
|
|
109
|
+
function q() {
|
|
51
110
|
try {
|
|
52
|
-
return "3.
|
|
111
|
+
return "3.8.1";
|
|
53
112
|
} catch {
|
|
54
113
|
return;
|
|
55
114
|
}
|
|
56
115
|
}
|
|
57
|
-
function
|
|
58
|
-
let e =
|
|
116
|
+
function z() {
|
|
117
|
+
let e = q();
|
|
59
118
|
return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
|
|
60
119
|
}
|
|
61
|
-
var
|
|
62
|
-
function
|
|
120
|
+
var C = /* @__PURE__ */ new Set();
|
|
121
|
+
function B(e) {
|
|
63
122
|
if (!e) return;
|
|
64
|
-
let t =
|
|
123
|
+
let t = z(), r = H[t];
|
|
65
124
|
if (!r) return;
|
|
66
|
-
let
|
|
67
|
-
if (
|
|
68
|
-
let
|
|
69
|
-
|
|
125
|
+
let n = v(e);
|
|
126
|
+
if (V(n, r) < 0) {
|
|
127
|
+
let i = `${t}:${n}`;
|
|
128
|
+
C.has(i) || (C.add(i), console.warn(
|
|
70
129
|
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${e}" \xE9 anterior ao m\xEDnimo recomendado "${r}" para SDK major ${t}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
71
130
|
));
|
|
72
131
|
}
|
|
73
132
|
}
|
|
74
|
-
|
|
133
|
+
function G() {
|
|
134
|
+
let e = "This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var.";
|
|
135
|
+
return A() ? "Esta opera\xE7\xE3o exige a credencial nrt_ do produto, que \xE9 S\xD3 DE SERVIDOR. No navegador/app, chame a API do seu produto (ex.: https://<produto>.neetru.com/api/v1) com o token do usu\xE1rio \u2014 o backend do produto faz esta chamada com o SDK e a chave. (" + e + ")" : e;
|
|
136
|
+
}
|
|
137
|
+
var X = 2, Y = 0, J = /* @__PURE__ */ new Set(["GET", "HEAD"]), W = /* @__PURE__ */ new Set([
|
|
75
138
|
"rate_limited",
|
|
76
139
|
"server_error",
|
|
77
140
|
"network_error"
|
|
78
141
|
]);
|
|
79
|
-
function
|
|
142
|
+
function O(e) {
|
|
80
143
|
let t = 200 * Math.pow(4, e), r = t * 0.2 * (Math.random() * 2 - 1);
|
|
81
144
|
return Math.max(50, Math.round(t + r));
|
|
82
145
|
}
|
|
83
|
-
var
|
|
84
|
-
function
|
|
146
|
+
var K = 6e4;
|
|
147
|
+
function Z(e) {
|
|
85
148
|
if (!e) return null;
|
|
86
149
|
let t = Number(e);
|
|
87
|
-
if (Number.isFinite(t) && t >= 0) return Math.min(Math.round(t * 1e3),
|
|
150
|
+
if (Number.isFinite(t) && t >= 0) return Math.min(Math.round(t * 1e3), K);
|
|
88
151
|
let r = Date.parse(e);
|
|
89
152
|
if (Number.isFinite(r)) {
|
|
90
|
-
let
|
|
91
|
-
if (
|
|
153
|
+
let n = r - Date.now();
|
|
154
|
+
if (n > 0) return Math.min(n, K);
|
|
92
155
|
}
|
|
93
156
|
return null;
|
|
94
157
|
}
|
|
95
|
-
function
|
|
158
|
+
function M(e) {
|
|
96
159
|
return new Promise((t) => setTimeout(t, e));
|
|
97
160
|
}
|
|
98
|
-
function
|
|
161
|
+
function Q(e) {
|
|
99
162
|
return e === 401 ? "unauthorized" : e === 403 ? "forbidden" : e === 404 ? "not_found" : e === 409 ? "conflict" : e === 410 ? "gone" : e === 422 || e === 400 ? "validation_failed" : e === 429 ? "rate_limited" : e >= 500 ? "server_error" : "unknown";
|
|
100
163
|
}
|
|
101
|
-
function
|
|
102
|
-
let
|
|
164
|
+
function ee(e, t, r) {
|
|
165
|
+
let n = e.replace(/\/+$/, ""), i = t.startsWith("/") ? t : `/${t}`, o = new URL(`${n}${i}`);
|
|
103
166
|
if (r)
|
|
104
|
-
for (let [a,
|
|
105
|
-
|
|
106
|
-
return
|
|
167
|
+
for (let [a, c] of Object.entries(r))
|
|
168
|
+
c !== void 0 && o.searchParams.set(a, String(c));
|
|
169
|
+
return o.toString();
|
|
107
170
|
}
|
|
108
|
-
async function
|
|
171
|
+
async function U(e) {
|
|
109
172
|
let t = await e.text();
|
|
110
173
|
if (t)
|
|
111
174
|
try {
|
|
@@ -114,86 +177,90 @@ async function A(e) {
|
|
|
114
177
|
return;
|
|
115
178
|
}
|
|
116
179
|
}
|
|
117
|
-
async function
|
|
118
|
-
let r = t.method ?? "GET",
|
|
119
|
-
accept: "application/json",
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (
|
|
180
|
+
async function E(e, t) {
|
|
181
|
+
let r = t.method ?? "GET", n = ee(e.baseUrl, t.path, t.query), i = J.has(r) ? X : Y, o = t.retries ?? i, { headers: a, correlationId: c } = D(
|
|
182
|
+
{ accept: "application/json", ...t.headers },
|
|
183
|
+
t.correlationId
|
|
184
|
+
), R = q();
|
|
185
|
+
if (R && (a["x-neetru-sdk-version"] = R), t.requireAuth) {
|
|
123
186
|
if (!e.apiKey)
|
|
124
|
-
throw new
|
|
125
|
-
"missing_api_key",
|
|
126
|
-
"This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
|
|
127
|
-
);
|
|
187
|
+
throw new d("missing_api_key", G());
|
|
128
188
|
a.authorization = `Bearer ${e.apiKey}`;
|
|
129
189
|
}
|
|
130
190
|
if (t.idempotencyKey) {
|
|
131
|
-
let
|
|
132
|
-
a["idempotency-key"] =
|
|
191
|
+
let p = typeof t.idempotencyKey == "string" ? t.idempotencyKey : T();
|
|
192
|
+
a["idempotency-key"] = p;
|
|
133
193
|
}
|
|
134
|
-
let
|
|
135
|
-
|
|
136
|
-
let g = null,
|
|
137
|
-
for (let
|
|
138
|
-
if (
|
|
139
|
-
throw g ?? new
|
|
194
|
+
let b = t.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(t.body) : void 0;
|
|
195
|
+
b !== void 0 && (a["content-type"] = "application/json");
|
|
196
|
+
let g = null, f = t.deadlineMs != null ? Date.now() + t.deadlineMs : null;
|
|
197
|
+
for (let p = 0; p <= o; p++) {
|
|
198
|
+
if (f != null && Date.now() >= f)
|
|
199
|
+
throw g ?? new d(
|
|
200
|
+
"network_error",
|
|
201
|
+
"Deadline excedido antes de completar a request",
|
|
202
|
+
void 0,
|
|
203
|
+
void 0,
|
|
204
|
+
void 0,
|
|
205
|
+
c
|
|
206
|
+
);
|
|
140
207
|
let w = { method: r, headers: a };
|
|
141
|
-
|
|
142
|
-
let
|
|
143
|
-
w.signal = AbortSignal.timeout(
|
|
208
|
+
b !== void 0 && (w.body = b);
|
|
209
|
+
let $ = f != null ? Math.max(1, Math.min(3e4, f - Date.now())) : 3e4;
|
|
210
|
+
w.signal = AbortSignal.timeout($);
|
|
144
211
|
let u;
|
|
145
212
|
try {
|
|
146
|
-
u = await e.fetch(
|
|
147
|
-
} catch (
|
|
148
|
-
let h =
|
|
149
|
-
if (g = new
|
|
150
|
-
let
|
|
151
|
-
if (
|
|
152
|
-
await
|
|
213
|
+
u = await e.fetch(n, w);
|
|
214
|
+
} catch (s) {
|
|
215
|
+
let h = s instanceof DOMException && s.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${s instanceof Error ? s.message : "fetch failed"}`;
|
|
216
|
+
if (g = new d("network_error", h, void 0, void 0, void 0, c), p < o) {
|
|
217
|
+
let k = O(p);
|
|
218
|
+
if (f == null || Date.now() + k < f) {
|
|
219
|
+
await M(k);
|
|
153
220
|
continue;
|
|
154
221
|
}
|
|
155
222
|
}
|
|
156
223
|
throw g;
|
|
157
224
|
}
|
|
158
|
-
let
|
|
225
|
+
let L = u.headers.get("x-request-id") ?? u.headers.get("x-correlation-id") ?? void 0;
|
|
159
226
|
if (u.ok) {
|
|
160
|
-
let
|
|
161
|
-
return
|
|
227
|
+
let s = u.headers.get("x-neetru-version");
|
|
228
|
+
return s && B(s), await U(u);
|
|
162
229
|
}
|
|
163
|
-
let
|
|
164
|
-
if (
|
|
165
|
-
let
|
|
166
|
-
typeof
|
|
230
|
+
let l = await U(u), _ = Q(u.status), m = `HTTP ${u.status}`, I;
|
|
231
|
+
if (l && typeof l == "object") {
|
|
232
|
+
let s = l.error;
|
|
233
|
+
typeof s == "string" ? m = s : s && typeof s == "object" ? (typeof s.code == "string" && (_ = s.code), typeof s.message == "string" && (m = s.message), typeof s.reason == "string" && (I = s.reason)) : (typeof l.code == "string" && (_ = l.code), typeof l.message == "string" && (m = l.message)), typeof l.reason == "string" && (I = l.reason);
|
|
167
234
|
}
|
|
168
235
|
if (u.status === 410) {
|
|
169
|
-
let
|
|
170
|
-
m === `HTTP ${u.status}` && (m = `Endpoint ${t.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`),
|
|
236
|
+
let s = u.headers.get("x-neetru-replacement");
|
|
237
|
+
m === `HTTP ${u.status}` && (m = `Endpoint ${t.path} foi removido do Core (HTTP 410 Gone) \u2014 atualize o @neetru/sdk e migre para a API substituta.`), s && !m.includes(s) && (m += ` Substituto: ${s}.`);
|
|
171
238
|
}
|
|
172
|
-
let
|
|
173
|
-
if (g =
|
|
174
|
-
let h =
|
|
175
|
-
if (
|
|
176
|
-
await
|
|
239
|
+
let N = new d(_, m, u.status, L, I, c);
|
|
240
|
+
if (g = N, W.has(_) && p < o) {
|
|
241
|
+
let h = Z(u.headers.get("retry-after")) ?? O(p);
|
|
242
|
+
if (f == null || Date.now() + h < f) {
|
|
243
|
+
await M(h);
|
|
177
244
|
continue;
|
|
178
245
|
}
|
|
179
246
|
}
|
|
180
|
-
throw
|
|
247
|
+
throw N;
|
|
181
248
|
}
|
|
182
|
-
throw g ?? new
|
|
249
|
+
throw g ?? new d("unknown", "unexpected httpRequest exit", void 0, void 0, void 0, c);
|
|
183
250
|
}
|
|
184
251
|
|
|
185
252
|
// src/validators.ts
|
|
186
|
-
var
|
|
253
|
+
var P = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
|
|
187
254
|
function y(e, t) {
|
|
188
|
-
if (typeof t != "string" || !
|
|
189
|
-
throw new
|
|
255
|
+
if (typeof t != "string" || !P.test(t))
|
|
256
|
+
throw new d(
|
|
190
257
|
"validation_failed",
|
|
191
|
-
`${e} must match ${
|
|
258
|
+
`${e} must match ${P.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
|
|
192
259
|
);
|
|
193
260
|
}
|
|
194
261
|
|
|
195
262
|
// src/usage.ts
|
|
196
|
-
function
|
|
263
|
+
function ye(e) {
|
|
197
264
|
return {
|
|
198
265
|
/**
|
|
199
266
|
* Reporta consumo metered de um resource. Hit no endpoint canônico
|
|
@@ -207,32 +274,32 @@ function ie(e) {
|
|
|
207
274
|
* await client.usage.report('api_call', 5, { productId: 'gestovendas', tenantId: 't-acme' });
|
|
208
275
|
* ```
|
|
209
276
|
*/
|
|
210
|
-
async report(t, r = 1,
|
|
277
|
+
async report(t, r = 1, n) {
|
|
211
278
|
if (!t || typeof t != "string")
|
|
212
|
-
throw new
|
|
279
|
+
throw new d("validation_failed", "resource is required");
|
|
213
280
|
if (!Number.isFinite(r) || r <= 0 || !Number.isInteger(r))
|
|
214
|
-
throw new
|
|
215
|
-
let
|
|
216
|
-
if (!
|
|
217
|
-
throw new
|
|
281
|
+
throw new d("validation_failed", "qty must be a positive integer");
|
|
282
|
+
let i = n?.productId ?? e.productId, o = n?.tenantId ?? e.tenantId;
|
|
283
|
+
if (!i)
|
|
284
|
+
throw new d(
|
|
218
285
|
"validation_failed",
|
|
219
286
|
"productId required (pass to options or set on createNeetruClient)"
|
|
220
287
|
);
|
|
221
|
-
if (!
|
|
222
|
-
throw new
|
|
288
|
+
if (!o)
|
|
289
|
+
throw new d(
|
|
223
290
|
"validation_failed",
|
|
224
291
|
"tenantId required (pass to options or set on createNeetruClient)"
|
|
225
292
|
);
|
|
226
|
-
y("productId",
|
|
227
|
-
let a = await
|
|
293
|
+
y("productId", i), y("tenantId", o);
|
|
294
|
+
let a = await E(e, {
|
|
228
295
|
method: "POST",
|
|
229
296
|
path: "/api/sdk/v1/usage/record",
|
|
230
|
-
body: { productId:
|
|
297
|
+
body: { productId: i, tenantId: o, resource: t, qty: Math.floor(r) },
|
|
231
298
|
requireAuth: true,
|
|
232
299
|
idempotencyKey: true
|
|
233
300
|
});
|
|
234
301
|
if (!a || a.ok !== true)
|
|
235
|
-
throw new
|
|
302
|
+
throw new d("invalid_response", "usage.report response missing ok");
|
|
236
303
|
return {
|
|
237
304
|
ok: true,
|
|
238
305
|
counterId: a.counterId,
|
|
@@ -250,34 +317,34 @@ function ie(e) {
|
|
|
250
317
|
*/
|
|
251
318
|
async check(t, r) {
|
|
252
319
|
if (!t || typeof t != "string")
|
|
253
|
-
throw new
|
|
254
|
-
let
|
|
255
|
-
if (!
|
|
256
|
-
throw new
|
|
320
|
+
throw new d("validation_failed", "resource is required");
|
|
321
|
+
let n = r?.productId ?? e.productId, i = r?.tenantId ?? e.tenantId;
|
|
322
|
+
if (!n || !i)
|
|
323
|
+
throw new d(
|
|
257
324
|
"validation_failed",
|
|
258
325
|
"productId and tenantId required (pass to options or set on createNeetruClient)"
|
|
259
326
|
);
|
|
260
|
-
y("productId",
|
|
261
|
-
let
|
|
327
|
+
y("productId", n), y("tenantId", i);
|
|
328
|
+
let o = await E(e, {
|
|
262
329
|
method: "GET",
|
|
263
330
|
path: "/api/sdk/v1/entitlements",
|
|
264
|
-
query: { productId:
|
|
331
|
+
query: { productId: n, tenantId: i, feature: t },
|
|
265
332
|
requireAuth: true
|
|
266
333
|
});
|
|
267
|
-
if (!
|
|
268
|
-
throw new
|
|
269
|
-
let a =
|
|
334
|
+
if (!o || typeof o.allowed != "boolean")
|
|
335
|
+
throw new d("invalid_response", "usage.check response missing allowed");
|
|
336
|
+
let a = o.behavior ?? (o.reason === "limit_exceeded" ? "readonly" : null);
|
|
270
337
|
return {
|
|
271
|
-
allowed:
|
|
272
|
-
reason:
|
|
273
|
-
remaining:
|
|
274
|
-
limit:
|
|
275
|
-
planId:
|
|
276
|
-
planFeatures:
|
|
338
|
+
allowed: o.allowed,
|
|
339
|
+
reason: o.reason,
|
|
340
|
+
remaining: o.remaining,
|
|
341
|
+
limit: o.limit,
|
|
342
|
+
planId: o.planId,
|
|
343
|
+
planFeatures: o.planFeatures,
|
|
277
344
|
behavior: a
|
|
278
345
|
};
|
|
279
346
|
}
|
|
280
347
|
};
|
|
281
348
|
}
|
|
282
349
|
|
|
283
|
-
exports.createUsageNamespace =
|
|
350
|
+
exports.createUsageNamespace = ye;
|
package/dist/usage.d.cts
CHANGED
package/dist/usage.d.ts
CHANGED