@neetru/sdk 2.2.0 → 2.3.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/dist/index.d.cts CHANGED
@@ -1,5 +1,5 @@
1
- import { o as NeetruClientConfig, N as NeetruClient } from './types-DlDxttiG.cjs';
2
- export { A as AuthNamespace, a as AuthStateListener, C as CatalogListOptions, b as CatalogListResponse, c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, i as CreateTicketInput, D as DEFAULT_BASE_URL, j as DbNamespace, k as DbSqlLease, l as DbWhereFilter, E as EntitlementCheck, L as ListNotificationsOptions, M as MockCheckout, m as MockNotifications, n as MockWebhooks, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruEnv, v as NeetruSqlClient, w as NeetruUser, x as NotificationsNamespace, P as Product, y as ProductNotification, z as ProductNotificationSeverity, B as ProductPlan, F as ProductStatus, R as RegisterWebhookInput, G as ResolvedConfig, S as SendNotificationInput, H as SignInOptions, J as SupportNamespace, K as SupportSeverity, O as SupportStatus, Q as SupportTicket, T as TelemetryEventAck, U as TelemetryEventInput, X as UsageEventInput, Y as UsageNamespace, Z as UsageQuota, _ as VerifyTokenOptions, $ as WebhookEndpoint, a0 as WebhookEvent, a1 as WebhookTestResult, a2 as WebhooksNamespace, a3 as createCheckoutNamespace, a4 as createNeetruDb, a5 as createNotificationsNamespace, a7 as createWebhooksNamespace } from './types-DlDxttiG.cjs';
1
+ import { o as NeetruClientConfig, N as NeetruClient } from './types-B6YJrynl.cjs';
2
+ export { A as AuthNamespace, a as AuthStateListener, C as CatalogListOptions, b as CatalogListResponse, c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, i as CreateTicketInput, D as DEFAULT_BASE_URL, j as DbNamespace, k as DbSqlLease, l as DbWhereFilter, E as EntitlementCheck, L as ListNotificationsOptions, M as MockCheckout, m as MockNotifications, n as MockWebhooks, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, v as NeetruEnv, w as NeetruSqlClient, x as NeetruUser, y as NotificationsNamespace, P as Product, z as ProductNotification, B as ProductNotificationSeverity, F as ProductPlan, G as ProductStatus, R as RegisterWebhookInput, H as ResolvedConfig, S as SendNotificationInput, I as SignInOptions, K as SupportNamespace, O as SupportSeverity, Q as SupportStatus, T as SupportTicket, U as TelemetryEventAck, V as TelemetryEventInput, Y as UsageEventInput, Z as UsageNamespace, _ as UsageQuota, $ as VerifyTokenOptions, a0 as WebhookEndpoint, a1 as WebhookEvent, a2 as WebhookTestResult, a3 as WebhooksNamespace, a4 as createCheckoutNamespace, a5 as createNeetruDb, a6 as createNotificationsNamespace, a8 as createWebhooksNamespace } from './types-B6YJrynl.cjs';
3
3
  export { createNeetruClient } from './auth.cjs';
4
4
  export { NeetruError, NeetruErrorCode } from './errors.cjs';
5
5
  export { D as DbBatchOp, b as DbChangeType, c as DbCollectionRef, d as DbDoc, e as DbDocRef, f as DbGetResult, g as DbListResult, h as DbQuery } from './collection-ref-DqAAhuhX.cjs';
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { o as NeetruClientConfig, N as NeetruClient } from './types-CvTje138.js';
2
- export { A as AuthNamespace, a as AuthStateListener, C as CatalogListOptions, b as CatalogListResponse, c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, i as CreateTicketInput, D as DEFAULT_BASE_URL, j as DbNamespace, k as DbSqlLease, l as DbWhereFilter, E as EntitlementCheck, L as ListNotificationsOptions, M as MockCheckout, m as MockNotifications, n as MockWebhooks, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruEnv, v as NeetruSqlClient, w as NeetruUser, x as NotificationsNamespace, P as Product, y as ProductNotification, z as ProductNotificationSeverity, B as ProductPlan, F as ProductStatus, R as RegisterWebhookInput, G as ResolvedConfig, S as SendNotificationInput, H as SignInOptions, J as SupportNamespace, K as SupportSeverity, O as SupportStatus, Q as SupportTicket, T as TelemetryEventAck, U as TelemetryEventInput, X as UsageEventInput, Y as UsageNamespace, Z as UsageQuota, _ as VerifyTokenOptions, $ as WebhookEndpoint, a0 as WebhookEvent, a1 as WebhookTestResult, a2 as WebhooksNamespace, a3 as createCheckoutNamespace, a4 as createNeetruDb, a5 as createNotificationsNamespace, a7 as createWebhooksNamespace } from './types-CvTje138.js';
1
+ import { o as NeetruClientConfig, N as NeetruClient } from './types-DvhtZ4bi.js';
2
+ export { A as AuthNamespace, a as AuthStateListener, C as CatalogListOptions, b as CatalogListResponse, c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, i as CreateTicketInput, D as DEFAULT_BASE_URL, j as DbNamespace, k as DbSqlLease, l as DbWhereFilter, E as EntitlementCheck, L as ListNotificationsOptions, M as MockCheckout, m as MockNotifications, n as MockWebhooks, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, v as NeetruEnv, w as NeetruSqlClient, x as NeetruUser, y as NotificationsNamespace, P as Product, z as ProductNotification, B as ProductNotificationSeverity, F as ProductPlan, G as ProductStatus, R as RegisterWebhookInput, H as ResolvedConfig, S as SendNotificationInput, I as SignInOptions, K as SupportNamespace, O as SupportSeverity, Q as SupportStatus, T as SupportTicket, U as TelemetryEventAck, V as TelemetryEventInput, Y as UsageEventInput, Z as UsageNamespace, _ as UsageQuota, $ as VerifyTokenOptions, a0 as WebhookEndpoint, a1 as WebhookEvent, a2 as WebhookTestResult, a3 as WebhooksNamespace, a4 as createCheckoutNamespace, a5 as createNeetruDb, a6 as createNotificationsNamespace, a8 as createWebhooksNamespace } from './types-DvhtZ4bi.js';
3
3
  export { createNeetruClient } from './auth.js';
4
4
  export { NeetruError, NeetruErrorCode } from './errors.js';
5
5
  export { D as DbBatchOp, b as DbChangeType, c as DbCollectionRef, d as DbDoc, e as DbDocRef, f as DbGetResult, g as DbListResult, h as DbQuery } from './collection-ref-DqAAhuhX.js';
package/dist/index.mjs CHANGED
@@ -1161,6 +1161,125 @@ var LocalStore = class {
1161
1161
  }
1162
1162
  };
1163
1163
 
1164
+ // src/db/offline/memory-store.ts
1165
+ var MemoryStore = class {
1166
+ // store `documents` — key: `${collection}\0${id}`
1167
+ _docs = /* @__PURE__ */ new Map();
1168
+ // store `mutations` — key: mutationId
1169
+ _mutations = /* @__PURE__ */ new Map();
1170
+ // store `sync_meta` — key: string
1171
+ _meta = /* @__PURE__ */ new Map();
1172
+ // store `conflict_log` — autoIncrement int key
1173
+ _conflicts = [];
1174
+ _conflictSeq = 0;
1175
+ // store `query_cache` — key: queryHash
1176
+ _queryCache = /* @__PURE__ */ new Map();
1177
+ // ─── Ciclo de vida (no-ops) ─────────────────────────────────────────────────
1178
+ async open() {
1179
+ }
1180
+ async close() {
1181
+ this._docs.clear();
1182
+ this._mutations.clear();
1183
+ this._meta.clear();
1184
+ this._conflicts.splice(0);
1185
+ this._conflictSeq = 0;
1186
+ this._queryCache.clear();
1187
+ }
1188
+ // ─── Documents ─────────────────────────────────────────────────────────────
1189
+ async getDoc(collection, id) {
1190
+ const key = `${collection}\0${id}`;
1191
+ return this._docs.get(key) ?? null;
1192
+ }
1193
+ async putDoc(doc) {
1194
+ const key = `${doc.collection}\0${doc.id}`;
1195
+ this._docs.set(key, doc);
1196
+ }
1197
+ async deleteDoc(collection, id) {
1198
+ const key = `${collection}\0${id}`;
1199
+ const existing = this._docs.get(key);
1200
+ if (!existing) return;
1201
+ this._docs.set(key, {
1202
+ ...existing,
1203
+ meta: {
1204
+ ...existing.meta,
1205
+ deleted: true,
1206
+ updatedAtLocal: Date.now()
1207
+ }
1208
+ });
1209
+ }
1210
+ async listDocs(collection, query) {
1211
+ const rawDocs = Array.from(this._docs.values()).filter(
1212
+ (d) => d.collection === collection
1213
+ );
1214
+ return QueryEngine.evaluate(rawDocs, query);
1215
+ }
1216
+ // ─── Sync meta ──────────────────────────────────────────────────────────────
1217
+ async getMeta(key) {
1218
+ return this._meta.get(key) ?? null;
1219
+ }
1220
+ async setMeta(key, value) {
1221
+ this._meta.set(key, value);
1222
+ }
1223
+ // ─── Conflict log ────────────────────────────────────────────────────────────
1224
+ async appendConflict(record) {
1225
+ const id = ++this._conflictSeq;
1226
+ const full = { ...record, id };
1227
+ this._conflicts.push(full);
1228
+ return full;
1229
+ }
1230
+ async listConflicts(options) {
1231
+ if (options?.delivered !== void 0) {
1232
+ return this._conflicts.filter((r) => r.delivered === options.delivered);
1233
+ }
1234
+ return [...this._conflicts];
1235
+ }
1236
+ async markConflictDelivered(id) {
1237
+ const entry = this._conflicts.find((r) => r.id === id);
1238
+ if (entry) entry.delivered = true;
1239
+ }
1240
+ // ─── Mutations ───────────────────────────────────────────────────────────────
1241
+ async putMutation(mutation) {
1242
+ this._mutations.set(mutation.mutationId, { ...mutation });
1243
+ }
1244
+ async getMutation(mutationId) {
1245
+ return this._mutations.get(mutationId) ?? null;
1246
+ }
1247
+ async listMutations(options) {
1248
+ let all = Array.from(this._mutations.values());
1249
+ if (options?.status !== void 0) {
1250
+ all = all.filter((m) => m.status === options.status);
1251
+ } else if (options?.collection !== void 0 && options.docId !== void 0) {
1252
+ all = all.filter(
1253
+ (m) => m.collection === options.collection && m.docId === options.docId
1254
+ );
1255
+ } else if (options?.collection !== void 0) {
1256
+ all = all.filter((m) => m.collection === options.collection);
1257
+ }
1258
+ return all.sort((a, b) => a.seq - b.seq);
1259
+ }
1260
+ async deleteMutation(mutationId) {
1261
+ this._mutations.delete(mutationId);
1262
+ }
1263
+ // ─── Collection discovery ────────────────────────────────────────────────────
1264
+ async listCollections() {
1265
+ const collections = /* @__PURE__ */ new Set();
1266
+ for (const doc of this._docs.values()) {
1267
+ collections.add(doc.collection);
1268
+ }
1269
+ return Array.from(collections);
1270
+ }
1271
+ // ─── Query cache ─────────────────────────────────────────────────────────────
1272
+ async getQueryCache(queryHash) {
1273
+ return this._queryCache.get(queryHash) ?? null;
1274
+ }
1275
+ async putQueryCache(entry) {
1276
+ this._queryCache.set(entry.queryHash, { ...entry });
1277
+ }
1278
+ async deleteQueryCache(queryHash) {
1279
+ this._queryCache.delete(queryHash);
1280
+ }
1281
+ };
1282
+
1164
1283
  // src/db/offline/mutation-queue.ts
1165
1284
  function generateUUIDv4() {
1166
1285
  if (typeof crypto !== "undefined" && typeof crypto.randomUUID === "function") {
@@ -2707,6 +2826,9 @@ var TabCoordinator = class {
2707
2826
  };
2708
2827
 
2709
2828
  // src/db/collection-ref.ts
2829
+ function isIndexedDBUnavailable() {
2830
+ return typeof indexedDB === "undefined" || typeof window === "undefined";
2831
+ }
2710
2832
  var COLL_RE = /^[a-z0-9][a-z0-9_-]{0,62}$/;
2711
2833
  function assertValidCollection(name) {
2712
2834
  if (!COLL_RE.test(name)) {
@@ -3248,7 +3370,7 @@ var NeetruDbDocumentsImpl = class {
3248
3370
  }
3249
3371
  };
3250
3372
  async function createOfflineDocumentsNamespace(opts) {
3251
- const store = new LocalStore(opts.dbName);
3373
+ const store = isIndexedDBUnavailable() ? new MemoryStore() : new LocalStore(opts.dbName);
3252
3374
  await store.open();
3253
3375
  const queue = new MutationQueue(store);
3254
3376
  const resolver = new ConflictResolver();
@@ -4018,16 +4140,16 @@ var defaultWebSocketFactory = (url) => {
4018
4140
  // src/db/client-db.ts
4019
4141
  var DATASTORE_COLLECTION_ENDPOINT = (collection) => `/api/sdk/v1/datastore/${encodeURIComponent(collection)}`;
4020
4142
  var DATASTORE_DOC_ENDPOINT = (collection, docId) => `/api/sdk/v1/datastore/${encodeURIComponent(collection)}/${encodeURIComponent(docId)}`;
4021
- function resolveTransport(engine, opts, config) {
4143
+ function resolveTransport(transport, opts, config) {
4022
4144
  if (opts._transport) {
4023
4145
  return opts._transport;
4024
4146
  }
4025
- if (engine === "firestore") {
4147
+ if (transport === "firestore") {
4026
4148
  if (opts.firestoreTransport) {
4027
4149
  return opts.firestoreTransport;
4028
4150
  }
4029
4151
  }
4030
- if (engine === "nosql-vm" && opts.realtimeGatewayUrl) {
4152
+ if (transport === "nosql-vm" && opts.realtimeGatewayUrl) {
4031
4153
  return createWebSocketSyncTransport(opts.realtimeGatewayUrl, config, opts);
4032
4154
  }
4033
4155
  return createRestSyncTransport(config);
@@ -4171,8 +4293,18 @@ function buildTicketProvider(config, opts) {
4171
4293
  };
4172
4294
  }
4173
4295
  function createNeetruDb(config, dbOpts = {}) {
4174
- const engine = dbOpts.engine ?? "rest";
4175
- const transport = resolveTransport(engine, dbOpts, config);
4296
+ let resolvedTransport;
4297
+ if (dbOpts.transport !== void 0) {
4298
+ resolvedTransport = dbOpts.transport;
4299
+ } else if (dbOpts.engine !== void 0) {
4300
+ console.warn(
4301
+ '[neetru/sdk] NeetruDbOptions.engine est\xE1 depreciado e ser\xE1 removido em v3.0. Use NeetruDbOptions.transport em vez de engine. Valores v\xE1lidos: "rest" | "firestore" | "nosql-vm". Nota: "engine" no SDK configura o TRANSPORTE (REST/Firestore/WebSocket), n\xE3o o storage engine do admin database (firestore-instance, cloud-sql-postgres, \u2026).'
4302
+ );
4303
+ resolvedTransport = dbOpts.engine;
4304
+ } else {
4305
+ resolvedTransport = "rest";
4306
+ }
4307
+ const transport = resolveTransport(resolvedTransport, dbOpts, config);
4176
4308
  const dbId = dbOpts.dbId ?? "default";
4177
4309
  const dbName = dbOpts.dbName ?? `neetru-db__${config.productId ?? "sdk"}__${dbId}__${config.env}`;
4178
4310
  let _docsPromise = null;