@neetru/sdk 3.4.5 → 3.4.7
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 +29 -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 +22 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.mjs +22 -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/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createNeetruClient } from './auth.cjs';
|
|
1
|
+
export { createNeetruClient, getServerNeetruClient } from './auth.cjs';
|
|
2
2
|
export { NeetruError, NeetruErrorCode } from './errors.cjs';
|
|
3
3
|
export { A as AiChatChoice, a as AiChatMessage, b as AiChatOptions, c as AiChatResult, d as AiChatUsage, e as AiContentPart, f as AiImageUrlPart, g as AiNamespace, h as AiResponseFormat, i as AiStreamHandle, j as AiStreamMeta, k as AiTextPart, l as AuthNamespace, m as AuthStateListener, C as CatalogListOptions, n as CatalogListResponse, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, v as CompleteSignInResult, y as CreateTicketInput, D as DEFAULT_BASE_URL, z as DbBatchOp, B as DbChangeType, E as DbCollectionRef, F as DbDoc, G as DbDocRef, H as DbGetResult, I as DbListResult, J as DbNamespace, K as DbQuery, L as DbSqlLease, M as DbWhereFilter, O as EntitlementCheck, P as FieldSentinel, Q as IncrementSentinel, R as ListNotificationsOptions, S as MockCheckout, T as MockNotifications, U as MockWebhooks, V as NEETRU_SENTINEL_KEY, W as NeetruClient, X as NeetruClientConfig, Y as NeetruDb, _ as NeetruDbEngine, $ as NeetruDbError, a0 as NeetruDbErrorCode, a1 as NeetruDbOptions, a2 as NeetruDbTransport, a3 as NeetruEnv, a4 as NeetruSqlClient, a5 as NeetruUser, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a8 as Product, a9 as ProductNotification, aa as ProductNotificationSeverity, ab as ProductPlan, ac as ProductStatus, ae as RedirectCallbackResult, af as RegisterWebhookInput, ag as ResolvedConfig, ah as SendNotificationInput, ai as ServerTimestampSentinel, aj as SignInOptions, al as SupportNamespace, am as SupportSeverity, an as SupportStatus, ao as SupportTicket, ar as TelemetryEventAck, as as TelemetryEventInput, aw as UsageEventInput, ax as UsageNamespace, ay as UsageQuota, az as VerifyTokenOptions, aA as VerifyWebhookRequestOptions, aB as VerifyWebhookRequestResult, aC as WebhookEndpoint, aD as WebhookEvent, aE as WebhookScopeOptions, aF as WebhookTestResult, aG as WebhooksNamespace, aH as WithFieldSentinels, aJ as createAiNamespace, aK as createCheckoutNamespace, aL as createNeetruDb, aM as createNotificationsNamespace, aO as createWebhooksNamespace, aQ as increment, aR as isFieldSentinel, aS as isIncrementSentinel, aT as isServerTimestampSentinel, aU as serverTimestamp, aV as verifyWebhookRequest, aW as verifyWebhookSignature } from './types-DIVZl7nO.cjs';
|
|
4
4
|
export { DEV_FIXTURE_USER, MockAi, MockAuth, MockAuthOptions, MockDb, MockEntitlements, MockSupport, MockUsage } from './mocks.cjs';
|
|
@@ -42,6 +42,6 @@ declare function checkCoreVersionCompat(coreVersion: string): void;
|
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
/** Versão do SDK — exportada explicitamente pra detecção em runtime. */
|
|
45
|
-
declare const VERSION: "3.4.
|
|
45
|
+
declare const VERSION: "3.4.6";
|
|
46
46
|
|
|
47
47
|
export { VERSION, checkCoreVersionCompat };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { createNeetruClient } from './auth.js';
|
|
1
|
+
export { createNeetruClient, getServerNeetruClient } from './auth.js';
|
|
2
2
|
export { NeetruError, NeetruErrorCode } from './errors.js';
|
|
3
3
|
export { A as AiChatChoice, a as AiChatMessage, b as AiChatOptions, c as AiChatResult, d as AiChatUsage, e as AiContentPart, f as AiImageUrlPart, g as AiNamespace, h as AiResponseFormat, i as AiStreamHandle, j as AiStreamMeta, k as AiTextPart, l as AuthNamespace, m as AuthStateListener, C as CatalogListOptions, n as CatalogListResponse, p as CheckoutIntentInfo, q as CheckoutIntentStatus, r as CheckoutNamespace, s as CheckoutStartInput, t as CheckoutStartResult, u as CheckoutTenantType, v as CompleteSignInResult, y as CreateTicketInput, D as DEFAULT_BASE_URL, z as DbBatchOp, B as DbChangeType, E as DbCollectionRef, F as DbDoc, G as DbDocRef, H as DbGetResult, I as DbListResult, J as DbNamespace, K as DbQuery, L as DbSqlLease, M as DbWhereFilter, O as EntitlementCheck, P as FieldSentinel, Q as IncrementSentinel, R as ListNotificationsOptions, S as MockCheckout, T as MockNotifications, U as MockWebhooks, V as NEETRU_SENTINEL_KEY, W as NeetruClient, X as NeetruClientConfig, Y as NeetruDb, _ as NeetruDbEngine, $ as NeetruDbError, a0 as NeetruDbErrorCode, a1 as NeetruDbOptions, a2 as NeetruDbTransport, a3 as NeetruEnv, a4 as NeetruSqlClient, a5 as NeetruUser, a6 as NotificationScopeOptions, a7 as NotificationsNamespace, a8 as Product, a9 as ProductNotification, aa as ProductNotificationSeverity, ab as ProductPlan, ac as ProductStatus, ae as RedirectCallbackResult, af as RegisterWebhookInput, ag as ResolvedConfig, ah as SendNotificationInput, ai as ServerTimestampSentinel, aj as SignInOptions, al as SupportNamespace, am as SupportSeverity, an as SupportStatus, ao as SupportTicket, ar as TelemetryEventAck, as as TelemetryEventInput, aw as UsageEventInput, ax as UsageNamespace, ay as UsageQuota, az as VerifyTokenOptions, aA as VerifyWebhookRequestOptions, aB as VerifyWebhookRequestResult, aC as WebhookEndpoint, aD as WebhookEvent, aE as WebhookScopeOptions, aF as WebhookTestResult, aG as WebhooksNamespace, aH as WithFieldSentinels, aJ as createAiNamespace, aK as createCheckoutNamespace, aL as createNeetruDb, aM as createNotificationsNamespace, aO as createWebhooksNamespace, aQ as increment, aR as isFieldSentinel, aS as isIncrementSentinel, aT as isServerTimestampSentinel, aU as serverTimestamp, aV as verifyWebhookRequest, aW as verifyWebhookSignature } from './types-nnztVk7G.js';
|
|
4
4
|
export { DEV_FIXTURE_USER, MockAi, MockAuth, MockAuthOptions, MockDb, MockEntitlements, MockSupport, MockUsage } from './mocks.js';
|
|
@@ -42,6 +42,6 @@ declare function checkCoreVersionCompat(coreVersion: string): void;
|
|
|
42
42
|
*/
|
|
43
43
|
|
|
44
44
|
/** Versão do SDK — exportada explicitamente pra detecção em runtime. */
|
|
45
|
-
declare const VERSION: "3.4.
|
|
45
|
+
declare const VERSION: "3.4.6";
|
|
46
46
|
|
|
47
47
|
export { VERSION, checkCoreVersionCompat };
|
package/dist/index.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
|
-
* Use `checkDetailed` se precisar do `reason` pra mensagem de upgrade.
|
|
1199
|
+
* @deprecated Endpoint morto no Core — sempre retornava `not_subscribed`.
|
|
1200
|
+
* Lança `NeetruError`. Use `client.usage.check(resource, {productId, tenantId})`.
|
|
1257
1201
|
*/
|
|
1258
|
-
async check(
|
|
1259
|
-
|
|
1260
|
-
return result.allowed;
|
|
1202
|
+
async check(_productSlug, _feature, _opts) {
|
|
1203
|
+
throwDeprecated();
|
|
1261
1204
|
},
|
|
1262
|
-
|
|
1263
|
-
|
|
1205
|
+
/**
|
|
1206
|
+
* @deprecated Endpoint morto no Core — sempre retornava `not_subscribed`.
|
|
1207
|
+
* Lança `NeetruError`. Use `client.usage.check(resource, {productId, tenantId})`.
|
|
1208
|
+
*/
|
|
1209
|
+
async checkDetailed(_productSlug, _feature, _opts) {
|
|
1210
|
+
throwDeprecated();
|
|
1211
|
+
},
|
|
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(
|
|
@@ -8027,7 +7975,7 @@ function createNeetruClient(config = {}) {
|
|
|
8027
7975
|
const auth = config.mocks?.auth ?? (isDev ? new MockAuth({ ...DEV_FIXTURE_USER }) : createOidcAuthNamespace(resolved));
|
|
8028
7976
|
const usage = config.mocks?.usage ?? (isDev ? new MockUsage() : createUsageNamespace(resolved));
|
|
8029
7977
|
const support = config.mocks?.support ?? (isDev ? new MockSupport() : createSupportNamespace(resolved));
|
|
8030
|
-
const entitlements = config.mocks?.entitlements ?? (isDev ? new MockEntitlements() : createEntitlementsNamespace(
|
|
7978
|
+
const entitlements = config.mocks?.entitlements ?? (isDev ? new MockEntitlements() : createEntitlementsNamespace());
|
|
8031
7979
|
const db = config.mocks?.db ?? createNeetruDb(resolved, config.db);
|
|
8032
7980
|
const webhooks = config.mocks?.webhooks ?? (isDev ? new MockWebhooks() : createWebhooksNamespace(resolved));
|
|
8033
7981
|
const notifications = config.mocks?.notifications ?? (isDev ? new MockNotifications() : createNotificationsNamespace(resolved));
|
|
@@ -8048,13 +7996,21 @@ function createNeetruClient(config = {}) {
|
|
|
8048
7996
|
});
|
|
8049
7997
|
return client;
|
|
8050
7998
|
}
|
|
7999
|
+
var NEETRU_SERVER_CLIENT_KEY = /* @__PURE__ */ Symbol.for("@neetru/sdk:serverClient");
|
|
8000
|
+
function getServerNeetruClient(config = {}) {
|
|
8001
|
+
const g = globalThis;
|
|
8002
|
+
if (!g[NEETRU_SERVER_CLIENT_KEY]) {
|
|
8003
|
+
g[NEETRU_SERVER_CLIENT_KEY] = createNeetruClient(config);
|
|
8004
|
+
}
|
|
8005
|
+
return g[NEETRU_SERVER_CLIENT_KEY];
|
|
8006
|
+
}
|
|
8051
8007
|
|
|
8052
8008
|
// src/index.ts
|
|
8053
8009
|
init_errors();
|
|
8054
8010
|
init_db_errors();
|
|
8055
8011
|
init_http();
|
|
8056
|
-
var VERSION = "3.4.
|
|
8012
|
+
var VERSION = "3.4.6";
|
|
8057
8013
|
|
|
8058
|
-
export { DEFAULT_BASE_URL, DEV_FIXTURE_USER, MockAi, MockAuth, MockCheckout, MockDb, MockEntitlements, MockNotifications, MockSupport, MockUsage, MockWebhooks, NEETRU_SENTINEL_KEY, NeetruDbError, NeetruError, VERSION, checkCoreVersionCompat, createAiNamespace, createCheckoutNamespace, createNeetruClient, createNeetruDb, createNotificationsNamespace, createWebhooksNamespace, increment, isFieldSentinel, isIncrementSentinel, isServerTimestampSentinel, serverTimestamp, verifyWebhookRequest, verifyWebhookSignature };
|
|
8014
|
+
export { DEFAULT_BASE_URL, DEV_FIXTURE_USER, MockAi, MockAuth, MockCheckout, MockDb, MockEntitlements, MockNotifications, MockSupport, MockUsage, MockWebhooks, NEETRU_SENTINEL_KEY, NeetruDbError, NeetruError, VERSION, checkCoreVersionCompat, createAiNamespace, createCheckoutNamespace, createNeetruClient, createNeetruDb, createNotificationsNamespace, createWebhooksNamespace, getServerNeetruClient, increment, isFieldSentinel, isIncrementSentinel, isServerTimestampSentinel, serverTimestamp, verifyWebhookRequest, verifyWebhookSignature };
|
|
8059
8015
|
//# sourceMappingURL=index.mjs.map
|
|
8060
8016
|
//# sourceMappingURL=index.mjs.map
|