@neetru/sdk 3.4.5 → 3.4.6
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 +15 -0
- package/dist/ai.cjs +1 -1
- package/dist/ai.cjs.map +1 -1
- package/dist/ai.mjs +1 -1
- package/dist/ai.mjs.map +1 -1
- package/dist/auth.cjs +31 -70
- package/dist/auth.cjs.map +1 -1
- package/dist/auth.d.cts +52 -1
- package/dist/auth.d.ts +52 -1
- package/dist/auth.mjs +30 -71
- package/dist/auth.mjs.map +1 -1
- package/dist/entitlements.cjs +16 -263
- package/dist/entitlements.cjs.map +1 -1
- package/dist/entitlements.d.cts +11 -9
- package/dist/entitlements.d.ts +11 -9
- package/dist/entitlements.mjs +16 -263
- package/dist/entitlements.mjs.map +1 -1
- package/dist/index.cjs +28 -71
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +28 -72
- package/dist/index.mjs.map +1 -1
- package/dist/notifications.cjs +1 -1
- package/dist/notifications.cjs.map +1 -1
- package/dist/notifications.mjs +1 -1
- package/dist/notifications.mjs.map +1 -1
- package/dist/react.cjs +6 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +6 -2
- package/dist/react.mjs.map +1 -1
- package/dist/support.cjs +1 -1
- package/dist/support.cjs.map +1 -1
- package/dist/support.mjs +1 -1
- package/dist/support.mjs.map +1 -1
- package/dist/usage.cjs +1 -1
- package/dist/usage.cjs.map +1 -1
- package/dist/usage.mjs +1 -1
- package/dist/usage.mjs.map +1 -1
- package/dist/webhooks.cjs +1 -1
- package/dist/webhooks.cjs.map +1 -1
- package/dist/webhooks.mjs +1 -1
- package/dist/webhooks.mjs.map +1 -1
- package/package.json +1 -1
package/dist/auth.d.cts
CHANGED
|
@@ -25,5 +25,56 @@ declare function __resetJwksCacheForTests(): void;
|
|
|
25
25
|
* @throws {NeetruError} `invalid_config` se fetch não disponível no runtime.
|
|
26
26
|
*/
|
|
27
27
|
declare function createNeetruClient(config?: NeetruClientConfig): NeetruClient;
|
|
28
|
+
/**
|
|
29
|
+
* Singleton server-side de `NeetruClient`, cacheado via `globalThis`.
|
|
30
|
+
*
|
|
31
|
+
* bug_d0d4e5bf: `client.db` server-side (Node.js, sem IndexedDB) cai em
|
|
32
|
+
* `MemoryStore` — um store 100% em memória, isolado POR INSTÂNCIA de client.
|
|
33
|
+
* Chamar `createNeetruClient(...)` mais de uma vez (ex.: uma vez por Server
|
|
34
|
+
* Action, outra por Route Handler) cria MemoryStores diferentes e ISOLADOS:
|
|
35
|
+
* um `set()` numa instância nunca fica visível pra um `get()`/`onSnapshot()`
|
|
36
|
+
* noutra, mesmo dentro do MESMO processo Node — não é um bug de rede nem de
|
|
37
|
+
* timing, é ausência de estado compartilhado.
|
|
38
|
+
*
|
|
39
|
+
* Use esta função em vez de `createNeetruClient` direto em qualquer código
|
|
40
|
+
* SERVER-ONLY (Server Actions, Route Handlers, Server Components) que use
|
|
41
|
+
* `client.db`:
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { getServerNeetruClient } from '@neetru/sdk';
|
|
45
|
+
*
|
|
46
|
+
* export async function myServerAction() {
|
|
47
|
+
* const client = getServerNeetruClient({ apiKey: process.env.NEETRU_API_KEY });
|
|
48
|
+
* await client.db.collection('orders').set('123', { status: 'paid' });
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* export async function GET() {
|
|
52
|
+
* const client = getServerNeetruClient(); // config já cacheada, argumento ignorado
|
|
53
|
+
* const order = await client.db.collection('orders').get('123');
|
|
54
|
+
* // ...
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* `config` só é lida na PRIMEIRA chamada (cria a instância); chamadas
|
|
59
|
+
* subsequentes a ignoram e devolvem a instância já cacheada — o padrão
|
|
60
|
+
* esperado é config ESTÁTICA por processo (lida de env vars no boot), não
|
|
61
|
+
* variável por-request. Se o produto precisa de múltiplos clients com config
|
|
62
|
+
* diferente no mesmo processo (raro), use `createNeetruClient` direto e
|
|
63
|
+
* gerencie o cache você mesmo.
|
|
64
|
+
*
|
|
65
|
+
* NÃO é necessário (nem recomendado) em código client-side (browser): lá o
|
|
66
|
+
* `IndexedDB` real persiste entre chamadas do jeito esperado, e o padrão
|
|
67
|
+
* usual é criar o client uma vez num Provider/Context React.
|
|
68
|
+
*
|
|
69
|
+
* @throws {NeetruError} `invalid_config` se `fetch` não disponível no runtime
|
|
70
|
+
* (mesma validação de `createNeetruClient`, só na primeira chamada).
|
|
71
|
+
*/
|
|
72
|
+
declare function getServerNeetruClient(config?: NeetruClientConfig): NeetruClient;
|
|
73
|
+
/**
|
|
74
|
+
* @internal Reseta o singleton server-side cacheado via `globalThis`.
|
|
75
|
+
* Uso exclusivo de testes — evita vazamento de estado entre `it()` blocks
|
|
76
|
+
* que chamam `getServerNeetruClient`.
|
|
77
|
+
*/
|
|
78
|
+
declare function __resetServerNeetruClientForTests(): void;
|
|
28
79
|
|
|
29
|
-
export { __resetJwksCacheForTests, createNeetruClient };
|
|
80
|
+
export { __resetJwksCacheForTests, __resetServerNeetruClientForTests, createNeetruClient, getServerNeetruClient };
|
package/dist/auth.d.ts
CHANGED
|
@@ -25,5 +25,56 @@ declare function __resetJwksCacheForTests(): void;
|
|
|
25
25
|
* @throws {NeetruError} `invalid_config` se fetch não disponível no runtime.
|
|
26
26
|
*/
|
|
27
27
|
declare function createNeetruClient(config?: NeetruClientConfig): NeetruClient;
|
|
28
|
+
/**
|
|
29
|
+
* Singleton server-side de `NeetruClient`, cacheado via `globalThis`.
|
|
30
|
+
*
|
|
31
|
+
* bug_d0d4e5bf: `client.db` server-side (Node.js, sem IndexedDB) cai em
|
|
32
|
+
* `MemoryStore` — um store 100% em memória, isolado POR INSTÂNCIA de client.
|
|
33
|
+
* Chamar `createNeetruClient(...)` mais de uma vez (ex.: uma vez por Server
|
|
34
|
+
* Action, outra por Route Handler) cria MemoryStores diferentes e ISOLADOS:
|
|
35
|
+
* um `set()` numa instância nunca fica visível pra um `get()`/`onSnapshot()`
|
|
36
|
+
* noutra, mesmo dentro do MESMO processo Node — não é um bug de rede nem de
|
|
37
|
+
* timing, é ausência de estado compartilhado.
|
|
38
|
+
*
|
|
39
|
+
* Use esta função em vez de `createNeetruClient` direto em qualquer código
|
|
40
|
+
* SERVER-ONLY (Server Actions, Route Handlers, Server Components) que use
|
|
41
|
+
* `client.db`:
|
|
42
|
+
*
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { getServerNeetruClient } from '@neetru/sdk';
|
|
45
|
+
*
|
|
46
|
+
* export async function myServerAction() {
|
|
47
|
+
* const client = getServerNeetruClient({ apiKey: process.env.NEETRU_API_KEY });
|
|
48
|
+
* await client.db.collection('orders').set('123', { status: 'paid' });
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* export async function GET() {
|
|
52
|
+
* const client = getServerNeetruClient(); // config já cacheada, argumento ignorado
|
|
53
|
+
* const order = await client.db.collection('orders').get('123');
|
|
54
|
+
* // ...
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*
|
|
58
|
+
* `config` só é lida na PRIMEIRA chamada (cria a instância); chamadas
|
|
59
|
+
* subsequentes a ignoram e devolvem a instância já cacheada — o padrão
|
|
60
|
+
* esperado é config ESTÁTICA por processo (lida de env vars no boot), não
|
|
61
|
+
* variável por-request. Se o produto precisa de múltiplos clients com config
|
|
62
|
+
* diferente no mesmo processo (raro), use `createNeetruClient` direto e
|
|
63
|
+
* gerencie o cache você mesmo.
|
|
64
|
+
*
|
|
65
|
+
* NÃO é necessário (nem recomendado) em código client-side (browser): lá o
|
|
66
|
+
* `IndexedDB` real persiste entre chamadas do jeito esperado, e o padrão
|
|
67
|
+
* usual é criar o client uma vez num Provider/Context React.
|
|
68
|
+
*
|
|
69
|
+
* @throws {NeetruError} `invalid_config` se `fetch` não disponível no runtime
|
|
70
|
+
* (mesma validação de `createNeetruClient`, só na primeira chamada).
|
|
71
|
+
*/
|
|
72
|
+
declare function getServerNeetruClient(config?: NeetruClientConfig): NeetruClient;
|
|
73
|
+
/**
|
|
74
|
+
* @internal Reseta o singleton server-side cacheado via `globalThis`.
|
|
75
|
+
* Uso exclusivo de testes — evita vazamento de estado entre `it()` blocks
|
|
76
|
+
* que chamam `getServerNeetruClient`.
|
|
77
|
+
*/
|
|
78
|
+
declare function __resetServerNeetruClientForTests(): void;
|
|
28
79
|
|
|
29
|
-
export { __resetJwksCacheForTests, createNeetruClient };
|
|
80
|
+
export { __resetJwksCacheForTests, __resetServerNeetruClientForTests, createNeetruClient, getServerNeetruClient };
|
package/dist/auth.mjs
CHANGED
|
@@ -1189,80 +1189,28 @@ function createCatalogNamespace(config) {
|
|
|
1189
1189
|
|
|
1190
1190
|
// src/entitlements.ts
|
|
1191
1191
|
init_errors();
|
|
1192
|
-
|
|
1193
|
-
function
|
|
1194
|
-
|
|
1195
|
-
throw new NeetruError("invalid_response", "Entitlement response is not an object");
|
|
1196
|
-
}
|
|
1197
|
-
const r = raw;
|
|
1198
|
-
if (typeof r.allowed !== "boolean") {
|
|
1199
|
-
throw new NeetruError("invalid_response", "Entitlement response missing `allowed` boolean");
|
|
1200
|
-
}
|
|
1201
|
-
return {
|
|
1202
|
-
allowed: r.allowed,
|
|
1203
|
-
productSlug: typeof r.productSlug === "string" ? r.productSlug : "",
|
|
1204
|
-
feature: typeof r.feature === "string" ? r.feature : "",
|
|
1205
|
-
reason: typeof r.reason === "string" ? r.reason : void 0
|
|
1206
|
-
};
|
|
1192
|
+
var DEPRECATION_MESSAGE = "client.entitlements.check()/checkDetailed() est\xE3o DEPRECADOS \u2014 apontavam para GET /api/v1/sdk/entitlements/check, um endpoint que o Core nunca escreve (sempre retornava not_subscribed). Use client.usage.check(resource, { productId, tenantId }) no lugar \u2014 mesmo resultado (allowed/reason/remaining/limit/behavior), endpoint real.";
|
|
1193
|
+
function throwDeprecated() {
|
|
1194
|
+
throw new NeetruError("validation_failed", DEPRECATION_MESSAGE);
|
|
1207
1195
|
}
|
|
1208
|
-
|
|
1209
|
-
var CACHE_MAX = 100;
|
|
1210
|
-
function createEntitlementsNamespace(config) {
|
|
1211
|
-
const cache = /* @__PURE__ */ new Map();
|
|
1212
|
-
function cacheKey(productSlug, feature) {
|
|
1213
|
-
return `${productSlug}::${feature}`;
|
|
1214
|
-
}
|
|
1215
|
-
function readCache(key) {
|
|
1216
|
-
const entry = cache.get(key);
|
|
1217
|
-
if (!entry) return null;
|
|
1218
|
-
if (entry.expiresAt < Date.now()) {
|
|
1219
|
-
cache.delete(key);
|
|
1220
|
-
return null;
|
|
1221
|
-
}
|
|
1222
|
-
cache.delete(key);
|
|
1223
|
-
cache.set(key, entry);
|
|
1224
|
-
return entry.value;
|
|
1225
|
-
}
|
|
1226
|
-
function writeCache(key, value) {
|
|
1227
|
-
if (cache.size >= CACHE_MAX) {
|
|
1228
|
-
const oldest = cache.keys().next().value;
|
|
1229
|
-
if (oldest !== void 0) cache.delete(oldest);
|
|
1230
|
-
}
|
|
1231
|
-
cache.set(key, { value, expiresAt: Date.now() + CACHE_TTL_MS });
|
|
1232
|
-
}
|
|
1233
|
-
async function checkDetailed(productSlug, feature, opts = {}) {
|
|
1234
|
-
if (!productSlug) throw new NeetruError("validation_failed", "productSlug is required");
|
|
1235
|
-
if (!feature) throw new NeetruError("validation_failed", "feature is required");
|
|
1236
|
-
const key = cacheKey(productSlug, feature);
|
|
1237
|
-
if (!opts.cacheBust) {
|
|
1238
|
-
const cached = readCache(key);
|
|
1239
|
-
if (cached) return cached;
|
|
1240
|
-
}
|
|
1241
|
-
const raw = await httpRequest(config, {
|
|
1242
|
-
method: "GET",
|
|
1243
|
-
path: "/api/v1/sdk/entitlements/check",
|
|
1244
|
-
query: { slug: productSlug, feature },
|
|
1245
|
-
requireAuth: true
|
|
1246
|
-
});
|
|
1247
|
-
const result = toEntitlementCheck(raw);
|
|
1248
|
-
writeCache(key, result);
|
|
1249
|
-
return result;
|
|
1250
|
-
}
|
|
1196
|
+
function createEntitlementsNamespace(_config) {
|
|
1251
1197
|
return {
|
|
1252
1198
|
/**
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1255
|
-
|
|
1256
|
-
|
|
1199
|
+
* @deprecated Endpoint morto no Core — sempre retornava `not_subscribed`.
|
|
1200
|
+
* Lança `NeetruError`. Use `client.usage.check(resource, {productId, tenantId})`.
|
|
1201
|
+
*/
|
|
1202
|
+
async check(_productSlug, _feature, _opts) {
|
|
1203
|
+
throwDeprecated();
|
|
1204
|
+
},
|
|
1205
|
+
/**
|
|
1206
|
+
* @deprecated Endpoint morto no Core — sempre retornava `not_subscribed`.
|
|
1207
|
+
* Lança `NeetruError`. Use `client.usage.check(resource, {productId, tenantId})`.
|
|
1257
1208
|
*/
|
|
1258
|
-
async
|
|
1259
|
-
|
|
1260
|
-
return result.allowed;
|
|
1209
|
+
async checkDetailed(_productSlug, _feature, _opts) {
|
|
1210
|
+
throwDeprecated();
|
|
1261
1211
|
},
|
|
1262
|
-
|
|
1263
|
-
/** Test helper: limpa o cache LRU. */
|
|
1212
|
+
/** Test helper legado — no-op (não há mais cache). Mantido por compat. */
|
|
1264
1213
|
__resetCache() {
|
|
1265
|
-
cache.clear();
|
|
1266
1214
|
}
|
|
1267
1215
|
};
|
|
1268
1216
|
}
|
|
@@ -1500,7 +1448,7 @@ init_http();
|
|
|
1500
1448
|
|
|
1501
1449
|
// src/validators.ts
|
|
1502
1450
|
init_errors();
|
|
1503
|
-
var SDK_ID_RE = /^[a-z0-9][a-z0-9_-]{0,62}
|
|
1451
|
+
var SDK_ID_RE = /^[a-z0-9][a-z0-9_-]{0,62}$/i;
|
|
1504
1452
|
function assertValidSdkId(field, value) {
|
|
1505
1453
|
if (typeof value !== "string" || !SDK_ID_RE.test(value)) {
|
|
1506
1454
|
throw new NeetruError(
|
|
@@ -7618,7 +7566,7 @@ function createNeetruClient(config = {}) {
|
|
|
7618
7566
|
const auth = config.mocks?.auth ?? (isDev ? new MockAuth({ ...DEV_FIXTURE_USER }) : createOidcAuthNamespace(resolved));
|
|
7619
7567
|
const usage = config.mocks?.usage ?? (isDev ? new MockUsage() : createUsageNamespace(resolved));
|
|
7620
7568
|
const support = config.mocks?.support ?? (isDev ? new MockSupport() : createSupportNamespace(resolved));
|
|
7621
|
-
const entitlements = config.mocks?.entitlements ?? (isDev ? new MockEntitlements() : createEntitlementsNamespace(
|
|
7569
|
+
const entitlements = config.mocks?.entitlements ?? (isDev ? new MockEntitlements() : createEntitlementsNamespace());
|
|
7622
7570
|
const db = config.mocks?.db ?? createNeetruDb(resolved, config.db);
|
|
7623
7571
|
const webhooks = config.mocks?.webhooks ?? (isDev ? new MockWebhooks() : createWebhooksNamespace(resolved));
|
|
7624
7572
|
const notifications = config.mocks?.notifications ?? (isDev ? new MockNotifications() : createNotificationsNamespace(resolved));
|
|
@@ -7639,7 +7587,18 @@ function createNeetruClient(config = {}) {
|
|
|
7639
7587
|
});
|
|
7640
7588
|
return client;
|
|
7641
7589
|
}
|
|
7590
|
+
var NEETRU_SERVER_CLIENT_KEY = /* @__PURE__ */ Symbol.for("@neetru/sdk:serverClient");
|
|
7591
|
+
function getServerNeetruClient(config = {}) {
|
|
7592
|
+
const g = globalThis;
|
|
7593
|
+
if (!g[NEETRU_SERVER_CLIENT_KEY]) {
|
|
7594
|
+
g[NEETRU_SERVER_CLIENT_KEY] = createNeetruClient(config);
|
|
7595
|
+
}
|
|
7596
|
+
return g[NEETRU_SERVER_CLIENT_KEY];
|
|
7597
|
+
}
|
|
7598
|
+
function __resetServerNeetruClientForTests() {
|
|
7599
|
+
delete globalThis[NEETRU_SERVER_CLIENT_KEY];
|
|
7600
|
+
}
|
|
7642
7601
|
|
|
7643
|
-
export { __resetJwksCacheForTests, createNeetruClient };
|
|
7602
|
+
export { __resetJwksCacheForTests, __resetServerNeetruClientForTests, createNeetruClient, getServerNeetruClient };
|
|
7644
7603
|
//# sourceMappingURL=auth.mjs.map
|
|
7645
7604
|
//# sourceMappingURL=auth.mjs.map
|