@neetru/sdk 3.5.0 → 3.7.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 +71 -1
- package/dist/ai.cjs +254 -391
- package/dist/ai.d.cts +1 -1
- package/dist/ai.d.ts +1 -1
- package/dist/ai.mjs +254 -391
- package/dist/auth.cjs +3560 -4993
- package/dist/auth.d.cts +1 -1
- package/dist/auth.d.ts +1 -1
- package/dist/auth.mjs +3557 -4990
- package/dist/build-guard.cjs +101 -119
- package/dist/build-guard.mjs +91 -109
- package/dist/catalog.cjs +152 -224
- package/dist/catalog.d.cts +1 -1
- package/dist/catalog.d.ts +1 -1
- package/dist/catalog.mjs +152 -224
- package/dist/checkout.cjs +237 -320
- package/dist/checkout.d.cts +1 -1
- package/dist/checkout.d.ts +1 -1
- package/dist/checkout.mjs +236 -319
- package/dist/db-react.cjs +59 -87
- package/dist/db-react.d.cts +1 -1
- package/dist/db-react.d.ts +1 -1
- package/dist/db-react.mjs +56 -84
- package/dist/db.cjs +2055 -3013
- package/dist/db.d.cts +1 -1
- package/dist/db.d.ts +1 -1
- package/dist/db.mjs +2068 -3026
- package/dist/entitlements.cjs +12 -20
- package/dist/entitlements.d.cts +1 -1
- package/dist/entitlements.d.ts +1 -1
- package/dist/entitlements.mjs +12 -20
- package/dist/errors.cjs +9 -12
- package/dist/errors.d.cts +37 -2
- package/dist/errors.d.ts +37 -2
- package/dist/errors.mjs +8 -12
- package/dist/firestore-compat.cjs +241 -297
- package/dist/firestore-compat.d.cts +1 -1
- package/dist/firestore-compat.d.ts +1 -1
- package/dist/firestore-compat.mjs +215 -271
- package/dist/index.cjs +3627 -5135
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.mjs +3731 -5239
- package/dist/mobile.cjs +411 -0
- package/dist/mobile.d.cts +89 -0
- package/dist/mobile.d.ts +89 -0
- package/dist/mobile.mjs +409 -0
- package/dist/mocks.cjs +312 -447
- package/dist/mocks.d.cts +1 -1
- package/dist/mocks.d.ts +1 -1
- package/dist/mocks.mjs +306 -441
- package/dist/notifications.cjs +226 -314
- package/dist/notifications.d.cts +1 -1
- package/dist/notifications.d.ts +1 -1
- package/dist/notifications.mjs +225 -313
- package/dist/react.cjs +522 -693
- package/dist/react.d.cts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.mjs +512 -683
- package/dist/support.cjs +329 -325
- package/dist/support.d.cts +25 -3
- package/dist/support.d.ts +25 -3
- package/dist/support.mjs +328 -325
- package/dist/telemetry.cjs +197 -301
- package/dist/telemetry.d.cts +1 -1
- package/dist/telemetry.d.ts +1 -1
- package/dist/telemetry.mjs +197 -301
- package/dist/{types-Du_iioJ7.d.cts → types-Bx4kTLmk.d.cts} +26 -0
- package/dist/{types-BPATkXYu.d.ts → types-Dx0IrOSF.d.ts} +26 -0
- package/dist/usage.cjs +163 -227
- package/dist/usage.d.cts +1 -1
- package/dist/usage.d.ts +1 -1
- package/dist/usage.mjs +163 -227
- package/dist/webhooks.cjs +258 -359
- package/dist/webhooks.d.cts +1 -1
- package/dist/webhooks.d.ts +1 -1
- package/dist/webhooks.mjs +255 -356
- package/package.json +9 -3
- package/dist/ai.cjs.map +0 -1
- package/dist/ai.mjs.map +0 -1
- package/dist/auth.cjs.map +0 -1
- package/dist/auth.mjs.map +0 -1
- package/dist/build-guard.cjs.map +0 -1
- package/dist/build-guard.mjs.map +0 -1
- package/dist/catalog.cjs.map +0 -1
- package/dist/catalog.mjs.map +0 -1
- package/dist/checkout.cjs.map +0 -1
- package/dist/checkout.mjs.map +0 -1
- package/dist/db-react.cjs.map +0 -1
- package/dist/db-react.mjs.map +0 -1
- package/dist/db.cjs.map +0 -1
- package/dist/db.mjs.map +0 -1
- package/dist/entitlements.cjs.map +0 -1
- package/dist/entitlements.mjs.map +0 -1
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/firestore-compat.cjs.map +0 -1
- package/dist/firestore-compat.mjs.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.mjs.map +0 -1
- package/dist/mocks.cjs.map +0 -1
- package/dist/mocks.mjs.map +0 -1
- package/dist/notifications.cjs.map +0 -1
- package/dist/notifications.mjs.map +0 -1
- package/dist/react.cjs.map +0 -1
- package/dist/react.mjs.map +0 -1
- package/dist/support.cjs.map +0 -1
- package/dist/support.mjs.map +0 -1
- package/dist/telemetry.cjs.map +0 -1
- package/dist/telemetry.mjs.map +0 -1
- package/dist/usage.cjs.map +0 -1
- package/dist/usage.mjs.map +0 -1
- package/dist/webhooks.cjs.map +0 -1
- package/dist/webhooks.mjs.map +0 -1
package/dist/usage.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/errors.ts
|
|
2
|
-
var
|
|
2
|
+
var s = class e extends Error {
|
|
3
3
|
code;
|
|
4
4
|
status;
|
|
5
5
|
requestId;
|
|
@@ -12,236 +12,186 @@ var NeetruError = class _NeetruError extends Error {
|
|
|
12
12
|
* para um `NeetruDbErrorCode` mais específico (recuperável vs não).
|
|
13
13
|
*/
|
|
14
14
|
reason;
|
|
15
|
-
constructor(
|
|
16
|
-
super(
|
|
17
|
-
this.name = "NeetruError";
|
|
18
|
-
this.code = code;
|
|
19
|
-
this.status = status;
|
|
20
|
-
this.requestId = requestId;
|
|
21
|
-
this.reason = reason;
|
|
22
|
-
Object.setPrototypeOf(this, _NeetruError.prototype);
|
|
15
|
+
constructor(t, r, i, d, n) {
|
|
16
|
+
super(r), this.name = "NeetruError", this.code = t, this.status = i, this.requestId = d, this.reason = n, Object.setPrototypeOf(this, e.prototype);
|
|
23
17
|
}
|
|
24
18
|
};
|
|
25
19
|
|
|
26
20
|
// src/idempotency.ts
|
|
27
|
-
function
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
return
|
|
31
|
-
|
|
32
|
-
throw new NeetruError(
|
|
21
|
+
function k() {
|
|
22
|
+
let e = typeof globalThis < "u" && "crypto" in globalThis ? globalThis.crypto : void 0;
|
|
23
|
+
if (e && typeof e.randomUUID == "function")
|
|
24
|
+
return e.randomUUID();
|
|
25
|
+
throw new s(
|
|
33
26
|
"runtime_unsupported",
|
|
34
27
|
"crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
|
|
35
28
|
);
|
|
36
29
|
}
|
|
37
30
|
|
|
38
31
|
// src/http.ts
|
|
39
|
-
var
|
|
32
|
+
var O = {
|
|
40
33
|
// SDK major 3.x requer Core ≥ 2026.05.1 (suporte a X-Neetru-Version header,
|
|
41
34
|
// runTransaction write-after-read, verifyWebhookRequest, webhooks 3.0+)
|
|
42
35
|
3: "2026.05.1"
|
|
43
36
|
};
|
|
44
|
-
function
|
|
45
|
-
return
|
|
37
|
+
function E(e) {
|
|
38
|
+
return e.split("+")[0] ?? e;
|
|
46
39
|
}
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const pa = partsA[i] ?? 0;
|
|
53
|
-
const pb = partsB[i] ?? 0;
|
|
54
|
-
if (pa !== pb) return pa - pb;
|
|
40
|
+
function $(e, t) {
|
|
41
|
+
let r = E(e).split(".").map(Number), i = E(t).split(".").map(Number), d = Math.max(r.length, i.length);
|
|
42
|
+
for (let n = 0; n < d; n++) {
|
|
43
|
+
let a = r[n] ?? 0, l = i[n] ?? 0;
|
|
44
|
+
if (a !== l) return a - l;
|
|
55
45
|
}
|
|
56
46
|
return 0;
|
|
57
47
|
}
|
|
58
|
-
function
|
|
48
|
+
function C() {
|
|
59
49
|
try {
|
|
60
|
-
return "3.
|
|
50
|
+
return "3.7.0";
|
|
61
51
|
} catch {
|
|
62
|
-
return
|
|
52
|
+
return;
|
|
63
53
|
}
|
|
64
54
|
}
|
|
65
|
-
function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
return 3;
|
|
55
|
+
function P() {
|
|
56
|
+
let e = C();
|
|
57
|
+
return e ? parseInt(e.split(".")[0] ?? "3", 10) : 3;
|
|
69
58
|
}
|
|
70
|
-
var
|
|
71
|
-
function
|
|
72
|
-
if (!
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
console.warn(
|
|
82
|
-
`[Neetru SDK] Aten\xE7\xE3o: Core vers\xE3o "${coreVersion}" \xE9 anterior ao m\xEDnimo recomendado "${minCore}" para SDK major ${sdkMajor}. Alguns recursos podem n\xE3o funcionar corretamente. Atualize o Core para a vers\xE3o mais recente.`
|
|
83
|
-
);
|
|
84
|
-
}
|
|
59
|
+
var N = /* @__PURE__ */ new Set();
|
|
60
|
+
function K(e) {
|
|
61
|
+
if (!e) return;
|
|
62
|
+
let t = P(), r = O[t];
|
|
63
|
+
if (!r) return;
|
|
64
|
+
let i = E(e);
|
|
65
|
+
if ($(i, r) < 0) {
|
|
66
|
+
let d = `${t}:${i}`;
|
|
67
|
+
N.has(d) || (N.add(d), console.warn(
|
|
68
|
+
`[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
|
+
));
|
|
85
70
|
}
|
|
86
71
|
}
|
|
87
|
-
var
|
|
88
|
-
var DEFAULT_RETRIES_WRITE = 0;
|
|
89
|
-
var READ_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD"]);
|
|
90
|
-
var RETRYABLE_CODES = /* @__PURE__ */ new Set([
|
|
72
|
+
var j = 2, F = 0, H = /* @__PURE__ */ new Set(["GET", "HEAD"]), z = /* @__PURE__ */ new Set([
|
|
91
73
|
"rate_limited",
|
|
92
74
|
"server_error",
|
|
93
75
|
"network_error"
|
|
94
76
|
]);
|
|
95
|
-
function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return Math.max(50, Math.round(base + jitter));
|
|
77
|
+
function x(e) {
|
|
78
|
+
let t = 200 * Math.pow(4, e), r = t * 0.2 * (Math.random() * 2 - 1);
|
|
79
|
+
return Math.max(50, Math.round(t + r));
|
|
99
80
|
}
|
|
100
|
-
var
|
|
101
|
-
function
|
|
102
|
-
if (!
|
|
103
|
-
|
|
104
|
-
if (Number.isFinite(
|
|
105
|
-
|
|
106
|
-
if (Number.isFinite(
|
|
107
|
-
|
|
108
|
-
if (
|
|
81
|
+
var D = 6e4;
|
|
82
|
+
function V(e) {
|
|
83
|
+
if (!e) return null;
|
|
84
|
+
let t = Number(e);
|
|
85
|
+
if (Number.isFinite(t) && t >= 0) return Math.min(Math.round(t * 1e3), D);
|
|
86
|
+
let r = Date.parse(e);
|
|
87
|
+
if (Number.isFinite(r)) {
|
|
88
|
+
let i = r - Date.now();
|
|
89
|
+
if (i > 0) return Math.min(i, D);
|
|
109
90
|
}
|
|
110
91
|
return null;
|
|
111
92
|
}
|
|
112
|
-
function
|
|
113
|
-
return new Promise((
|
|
93
|
+
function q(e) {
|
|
94
|
+
return new Promise((t) => setTimeout(t, e));
|
|
114
95
|
}
|
|
115
|
-
function
|
|
116
|
-
|
|
117
|
-
if (status === 403) return "forbidden";
|
|
118
|
-
if (status === 404) return "not_found";
|
|
119
|
-
if (status === 409) return "conflict";
|
|
120
|
-
if (status === 422 || status === 400) return "validation_failed";
|
|
121
|
-
if (status === 429) return "rate_limited";
|
|
122
|
-
if (status >= 500) return "server_error";
|
|
123
|
-
return "unknown";
|
|
96
|
+
function G(e) {
|
|
97
|
+
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";
|
|
124
98
|
}
|
|
125
|
-
function
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if (v === void 0) continue;
|
|
132
|
-
url.searchParams.set(k, String(v));
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
return url.toString();
|
|
99
|
+
function L(e, t, r) {
|
|
100
|
+
let i = e.replace(/\/+$/, ""), d = t.startsWith("/") ? t : `/${t}`, n = new URL(`${i}${d}`);
|
|
101
|
+
if (r)
|
|
102
|
+
for (let [a, l] of Object.entries(r))
|
|
103
|
+
l !== void 0 && n.searchParams.set(a, String(l));
|
|
104
|
+
return n.toString();
|
|
136
105
|
}
|
|
137
|
-
async function
|
|
138
|
-
|
|
139
|
-
if (
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
106
|
+
async function A(e) {
|
|
107
|
+
let t = await e.text();
|
|
108
|
+
if (t)
|
|
109
|
+
try {
|
|
110
|
+
return JSON.parse(t);
|
|
111
|
+
} catch {
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
145
114
|
}
|
|
146
|
-
async function
|
|
147
|
-
|
|
148
|
-
const url = buildUrl(config.baseUrl, opts.path, opts.query);
|
|
149
|
-
const defaultRetries = READ_METHODS.has(method) ? DEFAULT_RETRIES_READ : DEFAULT_RETRIES_WRITE;
|
|
150
|
-
const maxRetries = opts.retries ?? defaultRetries;
|
|
151
|
-
const headers = {
|
|
115
|
+
async function v(e, t) {
|
|
116
|
+
let r = t.method ?? "GET", i = L(e.baseUrl, t.path, t.query), d = H.has(r) ? j : F, n = t.retries ?? d, a = {
|
|
152
117
|
accept: "application/json",
|
|
153
|
-
...
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
}
|
|
159
|
-
if (opts.requireAuth) {
|
|
160
|
-
if (!config.apiKey) {
|
|
161
|
-
throw new NeetruError(
|
|
118
|
+
...t.headers
|
|
119
|
+
}, l = C();
|
|
120
|
+
if (l && (a["x-neetru-sdk-version"] = l), t.requireAuth) {
|
|
121
|
+
if (!e.apiKey)
|
|
122
|
+
throw new s(
|
|
162
123
|
"missing_api_key",
|
|
163
124
|
"This operation requires an apiKey. Pass it to createNeetruClient({ apiKey }) or set NEETRU_API_KEY env var."
|
|
164
125
|
);
|
|
165
|
-
}
|
|
166
|
-
headers.authorization = `Bearer ${config.apiKey}`;
|
|
167
|
-
}
|
|
168
|
-
if (opts.idempotencyKey) {
|
|
169
|
-
const key = typeof opts.idempotencyKey === "string" ? opts.idempotencyKey : generateIdempotencyKey();
|
|
170
|
-
headers["idempotency-key"] = key;
|
|
126
|
+
a.authorization = `Bearer ${e.apiKey}`;
|
|
171
127
|
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
128
|
+
if (t.idempotencyKey) {
|
|
129
|
+
let f = typeof t.idempotencyKey == "string" ? t.idempotencyKey : k();
|
|
130
|
+
a["idempotency-key"] = f;
|
|
175
131
|
}
|
|
176
|
-
let
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
132
|
+
let _ = t.body !== void 0 && r !== "GET" && r !== "DELETE" ? JSON.stringify(t.body) : void 0;
|
|
133
|
+
_ !== void 0 && (a["content-type"] = "application/json");
|
|
134
|
+
let g = null, p = t.deadlineMs != null ? Date.now() + t.deadlineMs : null;
|
|
135
|
+
for (let f = 0; f <= n; f++) {
|
|
136
|
+
if (p != null && Date.now() >= p)
|
|
137
|
+
throw g ?? new s("network_error", "Deadline excedido antes de completar a request");
|
|
138
|
+
let w = { method: r, headers: a };
|
|
139
|
+
_ !== void 0 && (w.body = _);
|
|
140
|
+
let M = p != null ? Math.max(1, Math.min(3e4, p - Date.now())) : 3e4;
|
|
141
|
+
w.signal = AbortSignal.timeout(M);
|
|
142
|
+
let u;
|
|
182
143
|
try {
|
|
183
|
-
|
|
184
|
-
} catch (
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
144
|
+
u = await e.fetch(i, w);
|
|
145
|
+
} catch (o) {
|
|
146
|
+
let h = o instanceof DOMException && o.name === "TimeoutError" ? "Network error: timeout after 30s" : `Network error: ${o instanceof Error ? o.message : "fetch failed"}`;
|
|
147
|
+
if (g = new s("network_error", h), f < n) {
|
|
148
|
+
let T = x(f);
|
|
149
|
+
if (p == null || Date.now() + T < p) {
|
|
150
|
+
await q(T);
|
|
151
|
+
continue;
|
|
152
|
+
}
|
|
190
153
|
}
|
|
191
|
-
throw
|
|
154
|
+
throw g;
|
|
192
155
|
}
|
|
193
|
-
|
|
194
|
-
if (
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const parsed = await safeJson(res);
|
|
198
|
-
return parsed;
|
|
156
|
+
let U = u.headers.get("x-request-id") ?? u.headers.get("x-correlation-id") ?? void 0;
|
|
157
|
+
if (u.ok) {
|
|
158
|
+
let o = u.headers.get("x-neetru-version");
|
|
159
|
+
return o && K(o), await A(u);
|
|
199
160
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (body && typeof body === "object") {
|
|
205
|
-
const errField = body.error;
|
|
206
|
-
if (typeof errField === "string") {
|
|
207
|
-
message = errField;
|
|
208
|
-
} else if (errField && typeof errField === "object") {
|
|
209
|
-
if (typeof errField.code === "string") code = errField.code;
|
|
210
|
-
if (typeof errField.message === "string") message = errField.message;
|
|
211
|
-
if (typeof errField.reason === "string") reason = errField.reason;
|
|
212
|
-
} else {
|
|
213
|
-
if (typeof body.code === "string") code = body.code;
|
|
214
|
-
if (typeof body.message === "string") message = body.message;
|
|
215
|
-
}
|
|
216
|
-
if (typeof body.reason === "string") reason = body.reason;
|
|
161
|
+
let c = await A(u), b = G(u.status), m = `HTTP ${u.status}`, I;
|
|
162
|
+
if (c && typeof c == "object") {
|
|
163
|
+
let o = c.error;
|
|
164
|
+
typeof o == "string" ? m = o : o && typeof o == "object" ? (typeof o.code == "string" && (b = o.code), typeof o.message == "string" && (m = o.message), typeof o.reason == "string" && (I = o.reason)) : (typeof c.code == "string" && (b = c.code), typeof c.message == "string" && (m = c.message)), typeof c.reason == "string" && (I = c.reason);
|
|
217
165
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
if (isRetryable && attempt < maxRetries) {
|
|
222
|
-
const retryAfter = parseRetryAfter(res.headers.get("retry-after"));
|
|
223
|
-
const delay = retryAfter ?? backoffMs(attempt);
|
|
224
|
-
await sleep(delay);
|
|
225
|
-
continue;
|
|
166
|
+
if (u.status === 410) {
|
|
167
|
+
let o = u.headers.get("x-neetru-replacement");
|
|
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.`), o && !m.includes(o) && (m += ` Substituto: ${o}.`);
|
|
226
169
|
}
|
|
227
|
-
|
|
170
|
+
let R = new s(b, m, u.status, U, I);
|
|
171
|
+
if (g = R, z.has(b) && f < n) {
|
|
172
|
+
let h = V(u.headers.get("retry-after")) ?? x(f);
|
|
173
|
+
if (p == null || Date.now() + h < p) {
|
|
174
|
+
await q(h);
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
throw R;
|
|
228
179
|
}
|
|
229
|
-
throw
|
|
180
|
+
throw g ?? new s("unknown", "unexpected httpRequest exit");
|
|
230
181
|
}
|
|
231
182
|
|
|
232
183
|
// src/validators.ts
|
|
233
|
-
var
|
|
234
|
-
function
|
|
235
|
-
if (typeof
|
|
236
|
-
throw new
|
|
184
|
+
var S = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
|
|
185
|
+
function y(e, t) {
|
|
186
|
+
if (typeof t != "string" || !S.test(t))
|
|
187
|
+
throw new s(
|
|
237
188
|
"validation_failed",
|
|
238
|
-
`${
|
|
189
|
+
`${e} must match ${S.source} (lowercase alphanumeric, _, -; first char must be alphanumeric; max 63 chars)`
|
|
239
190
|
);
|
|
240
|
-
}
|
|
241
191
|
}
|
|
242
192
|
|
|
243
193
|
// src/usage.ts
|
|
244
|
-
function
|
|
194
|
+
function ie(e) {
|
|
245
195
|
return {
|
|
246
196
|
/**
|
|
247
197
|
* Reporta consumo metered de um resource. Hit no endpoint canônico
|
|
@@ -255,46 +205,39 @@ function createUsageNamespace(config) {
|
|
|
255
205
|
* await client.usage.report('api_call', 5, { productId: 'gestovendas', tenantId: 't-acme' });
|
|
256
206
|
* ```
|
|
257
207
|
*/
|
|
258
|
-
async report(
|
|
259
|
-
if (!
|
|
260
|
-
throw new
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
const tenantId = options?.tenantId ?? config.tenantId;
|
|
267
|
-
if (!productId) {
|
|
268
|
-
throw new NeetruError(
|
|
208
|
+
async report(t, r = 1, i) {
|
|
209
|
+
if (!t || typeof t != "string")
|
|
210
|
+
throw new s("validation_failed", "resource is required");
|
|
211
|
+
if (!Number.isFinite(r) || r <= 0 || !Number.isInteger(r))
|
|
212
|
+
throw new s("validation_failed", "qty must be a positive integer");
|
|
213
|
+
let d = i?.productId ?? e.productId, n = i?.tenantId ?? e.tenantId;
|
|
214
|
+
if (!d)
|
|
215
|
+
throw new s(
|
|
269
216
|
"validation_failed",
|
|
270
217
|
"productId required (pass to options or set on createNeetruClient)"
|
|
271
218
|
);
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
throw new NeetruError(
|
|
219
|
+
if (!n)
|
|
220
|
+
throw new s(
|
|
275
221
|
"validation_failed",
|
|
276
222
|
"tenantId required (pass to options or set on createNeetruClient)"
|
|
277
223
|
);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
assertValidSdkId("tenantId", tenantId);
|
|
281
|
-
const raw = await httpRequest(config, {
|
|
224
|
+
y("productId", d), y("tenantId", n);
|
|
225
|
+
let a = await v(e, {
|
|
282
226
|
method: "POST",
|
|
283
227
|
path: "/api/sdk/v1/usage/record",
|
|
284
|
-
body: { productId, tenantId, resource, qty: Math.floor(
|
|
228
|
+
body: { productId: d, tenantId: n, resource: t, qty: Math.floor(r) },
|
|
285
229
|
requireAuth: true,
|
|
286
230
|
idempotencyKey: true
|
|
287
231
|
});
|
|
288
|
-
if (!
|
|
289
|
-
throw new
|
|
290
|
-
}
|
|
232
|
+
if (!a || a.ok !== true)
|
|
233
|
+
throw new s("invalid_response", "usage.report response missing ok");
|
|
291
234
|
return {
|
|
292
235
|
ok: true,
|
|
293
|
-
counterId:
|
|
294
|
-
value:
|
|
295
|
-
limit:
|
|
296
|
-
remaining:
|
|
297
|
-
status:
|
|
236
|
+
counterId: a.counterId,
|
|
237
|
+
value: a.value,
|
|
238
|
+
limit: a.limit,
|
|
239
|
+
remaining: a.remaining,
|
|
240
|
+
status: a.status
|
|
298
241
|
};
|
|
299
242
|
},
|
|
300
243
|
/**
|
|
@@ -303,43 +246,36 @@ function createUsageNamespace(config) {
|
|
|
303
246
|
* 'subscription_inactive' | 'feature_not_in_plan' | 'limit_exceeded'),
|
|
304
247
|
* `remaining`, `limit`, `planId`, `planFeatures`.
|
|
305
248
|
*/
|
|
306
|
-
async check(
|
|
307
|
-
if (!
|
|
308
|
-
throw new
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (!productId || !tenantId) {
|
|
313
|
-
throw new NeetruError(
|
|
249
|
+
async check(t, r) {
|
|
250
|
+
if (!t || typeof t != "string")
|
|
251
|
+
throw new s("validation_failed", "resource is required");
|
|
252
|
+
let i = r?.productId ?? e.productId, d = r?.tenantId ?? e.tenantId;
|
|
253
|
+
if (!i || !d)
|
|
254
|
+
throw new s(
|
|
314
255
|
"validation_failed",
|
|
315
256
|
"productId and tenantId required (pass to options or set on createNeetruClient)"
|
|
316
257
|
);
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
assertValidSdkId("tenantId", tenantId);
|
|
320
|
-
const raw = await httpRequest(config, {
|
|
258
|
+
y("productId", i), y("tenantId", d);
|
|
259
|
+
let n = await v(e, {
|
|
321
260
|
method: "GET",
|
|
322
261
|
path: "/api/sdk/v1/entitlements",
|
|
323
|
-
query: { productId, tenantId, feature:
|
|
262
|
+
query: { productId: i, tenantId: d, feature: t },
|
|
324
263
|
requireAuth: true
|
|
325
264
|
});
|
|
326
|
-
if (!
|
|
327
|
-
throw new
|
|
328
|
-
|
|
329
|
-
const behavior = raw.behavior ?? (raw.reason === "limit_exceeded" ? "readonly" : null);
|
|
265
|
+
if (!n || typeof n.allowed != "boolean")
|
|
266
|
+
throw new s("invalid_response", "usage.check response missing allowed");
|
|
267
|
+
let a = n.behavior ?? (n.reason === "limit_exceeded" ? "readonly" : null);
|
|
330
268
|
return {
|
|
331
|
-
allowed:
|
|
332
|
-
reason:
|
|
333
|
-
remaining:
|
|
334
|
-
limit:
|
|
335
|
-
planId:
|
|
336
|
-
planFeatures:
|
|
337
|
-
behavior
|
|
269
|
+
allowed: n.allowed,
|
|
270
|
+
reason: n.reason,
|
|
271
|
+
remaining: n.remaining,
|
|
272
|
+
limit: n.limit,
|
|
273
|
+
planId: n.planId,
|
|
274
|
+
planFeatures: n.planFeatures,
|
|
275
|
+
behavior: a
|
|
338
276
|
};
|
|
339
277
|
}
|
|
340
278
|
};
|
|
341
279
|
}
|
|
342
280
|
|
|
343
|
-
export { createUsageNamespace };
|
|
344
|
-
//# sourceMappingURL=usage.mjs.map
|
|
345
|
-
//# sourceMappingURL=usage.mjs.map
|
|
281
|
+
export { ie as createUsageNamespace };
|