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