@neetru/sdk 3.0.1 → 3.0.2

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/dist/auth.cjs +61 -13
  3. package/dist/auth.cjs.map +1 -1
  4. package/dist/auth.d.cts +2 -2
  5. package/dist/auth.d.ts +2 -2
  6. package/dist/auth.mjs +61 -13
  7. package/dist/auth.mjs.map +1 -1
  8. package/dist/catalog.d.cts +2 -2
  9. package/dist/catalog.d.ts +2 -2
  10. package/dist/checkout.d.cts +2 -2
  11. package/dist/checkout.d.ts +2 -2
  12. package/dist/{collection-ref-DqAAhuhX.d.cts → collection-ref-BDdfD87k.d.cts} +118 -9
  13. package/dist/{collection-ref-DqAAhuhX.d.ts → collection-ref-BDdfD87k.d.ts} +118 -9
  14. package/dist/db-react.d.cts +1 -1
  15. package/dist/db-react.d.ts +1 -1
  16. package/dist/db.cjs +81 -16
  17. package/dist/db.cjs.map +1 -1
  18. package/dist/db.d.cts +2 -2
  19. package/dist/db.d.ts +2 -2
  20. package/dist/db.mjs +76 -17
  21. package/dist/db.mjs.map +1 -1
  22. package/dist/entitlements.d.cts +2 -2
  23. package/dist/entitlements.d.ts +2 -2
  24. package/dist/index.cjs +81 -16
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +2 -2
  27. package/dist/index.d.ts +2 -2
  28. package/dist/index.mjs +76 -17
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/mocks.d.cts +2 -2
  31. package/dist/mocks.d.ts +2 -2
  32. package/dist/notifications.d.cts +2 -2
  33. package/dist/notifications.d.ts +2 -2
  34. package/dist/react.d.cts +2 -2
  35. package/dist/react.d.ts +2 -2
  36. package/dist/support.d.cts +2 -2
  37. package/dist/support.d.ts +2 -2
  38. package/dist/telemetry.d.cts +2 -2
  39. package/dist/telemetry.d.ts +2 -2
  40. package/dist/{types-DALIhcbq.d.ts → types-D7zVkO3n.d.ts} +1 -1
  41. package/dist/{types-Lfd3LiAF.d.cts → types-Dc4bjrrt.d.cts} +1 -1
  42. package/dist/usage.d.cts +2 -2
  43. package/dist/usage.d.ts +2 -2
  44. package/dist/webhooks.d.cts +2 -2
  45. package/dist/webhooks.d.ts +2 -2
  46. package/package.json +1 -1
package/dist/index.d.cts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createNeetruClient } from './auth.cjs';
2
2
  export { NeetruError, NeetruErrorCode } from './errors.cjs';
3
- 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, N as NeetruClient, o as NeetruClientConfig, 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 NotificationScopeOptions, z as NotificationsNamespace, P as Product, B as ProductNotification, F as ProductNotificationSeverity, G as ProductPlan, H as ProductStatus, R as RegisterWebhookInput, I as ResolvedConfig, S as SendNotificationInput, J as SignInOptions, O as SupportNamespace, Q as SupportSeverity, T as SupportStatus, U as SupportTicket, V as TelemetryEventAck, W as TelemetryEventInput, Z as UsageEventInput, _ as UsageNamespace, $ as UsageQuota, a0 as VerifyTokenOptions, a1 as WebhookEndpoint, a2 as WebhookEvent, a3 as WebhookScopeOptions, a4 as WebhookTestResult, a5 as WebhooksNamespace, a6 as createCheckoutNamespace, a7 as createNeetruDb, a8 as createNotificationsNamespace, aa as createWebhooksNamespace, ac as verifyWebhookSignature } from './types-Lfd3LiAF.cjs';
4
- 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';
3
+ 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, N as NeetruClient, o as NeetruClientConfig, 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 NotificationScopeOptions, z as NotificationsNamespace, P as Product, B as ProductNotification, F as ProductNotificationSeverity, G as ProductPlan, H as ProductStatus, R as RegisterWebhookInput, I as ResolvedConfig, S as SendNotificationInput, J as SignInOptions, O as SupportNamespace, Q as SupportSeverity, T as SupportStatus, U as SupportTicket, V as TelemetryEventAck, W as TelemetryEventInput, Z as UsageEventInput, _ as UsageNamespace, $ as UsageQuota, a0 as VerifyTokenOptions, a1 as WebhookEndpoint, a2 as WebhookEvent, a3 as WebhookScopeOptions, a4 as WebhookTestResult, a5 as WebhooksNamespace, a6 as createCheckoutNamespace, a7 as createNeetruDb, a8 as createNotificationsNamespace, aa as createWebhooksNamespace, ac as verifyWebhookSignature } from './types-Dc4bjrrt.cjs';
4
+ 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, F as FieldSentinel, I as IncrementSentinel, N as NEETRU_SENTINEL_KEY, S as ServerTimestampSentinel, W as WithFieldSentinels, l as increment, m as isFieldSentinel, n as isIncrementSentinel, o as isServerTimestampSentinel, s as serverTimestamp } from './collection-ref-BDdfD87k.cjs';
5
5
  export { DEV_FIXTURE_USER, MockAuth, MockDb, MockEntitlements, MockSupport, MockUsage } from './mocks.cjs';
6
6
  import 'drizzle-orm/node-postgres';
7
7
 
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export { createNeetruClient } from './auth.js';
2
2
  export { NeetruError, NeetruErrorCode } from './errors.js';
3
- 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, N as NeetruClient, o as NeetruClientConfig, 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 NotificationScopeOptions, z as NotificationsNamespace, P as Product, B as ProductNotification, F as ProductNotificationSeverity, G as ProductPlan, H as ProductStatus, R as RegisterWebhookInput, I as ResolvedConfig, S as SendNotificationInput, J as SignInOptions, O as SupportNamespace, Q as SupportSeverity, T as SupportStatus, U as SupportTicket, V as TelemetryEventAck, W as TelemetryEventInput, Z as UsageEventInput, _ as UsageNamespace, $ as UsageQuota, a0 as VerifyTokenOptions, a1 as WebhookEndpoint, a2 as WebhookEvent, a3 as WebhookScopeOptions, a4 as WebhookTestResult, a5 as WebhooksNamespace, a6 as createCheckoutNamespace, a7 as createNeetruDb, a8 as createNotificationsNamespace, aa as createWebhooksNamespace, ac as verifyWebhookSignature } from './types-DALIhcbq.js';
4
- 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';
3
+ 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, N as NeetruClient, o as NeetruClientConfig, 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 NotificationScopeOptions, z as NotificationsNamespace, P as Product, B as ProductNotification, F as ProductNotificationSeverity, G as ProductPlan, H as ProductStatus, R as RegisterWebhookInput, I as ResolvedConfig, S as SendNotificationInput, J as SignInOptions, O as SupportNamespace, Q as SupportSeverity, T as SupportStatus, U as SupportTicket, V as TelemetryEventAck, W as TelemetryEventInput, Z as UsageEventInput, _ as UsageNamespace, $ as UsageQuota, a0 as VerifyTokenOptions, a1 as WebhookEndpoint, a2 as WebhookEvent, a3 as WebhookScopeOptions, a4 as WebhookTestResult, a5 as WebhooksNamespace, a6 as createCheckoutNamespace, a7 as createNeetruDb, a8 as createNotificationsNamespace, aa as createWebhooksNamespace, ac as verifyWebhookSignature } from './types-D7zVkO3n.js';
4
+ 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, F as FieldSentinel, I as IncrementSentinel, N as NEETRU_SENTINEL_KEY, S as ServerTimestampSentinel, W as WithFieldSentinels, l as increment, m as isFieldSentinel, n as isIncrementSentinel, o as isServerTimestampSentinel, s as serverTimestamp } from './collection-ref-BDdfD87k.js';
5
5
  export { DEV_FIXTURE_USER, MockAuth, MockDb, MockEntitlements, MockSupport, MockUsage } from './mocks.js';
6
6
  import 'drizzle-orm/node-postgres';
7
7
 
package/dist/index.mjs CHANGED
@@ -2229,7 +2229,7 @@ var SyncEngine = class {
2229
2229
  return true;
2230
2230
  }
2231
2231
  /** Atualiza o cache após confirmação de escrita (outcome=confirmed). */
2232
- async _applySyncedDoc(collection, docId, serverVersion, serverTimestamp, mut, busChanges) {
2232
+ async _applySyncedDoc(collection, docId, serverVersion, serverTimestamp2, mut, busChanges) {
2233
2233
  const existing = await this._store.getDoc(collection, docId);
2234
2234
  if (mut.op === "remove") {
2235
2235
  if (existing) {
@@ -2238,7 +2238,7 @@ var SyncEngine = class {
2238
2238
  meta: {
2239
2239
  ...existing.meta,
2240
2240
  serverVersion,
2241
- updatedAtServer: serverTimestamp,
2241
+ updatedAtServer: serverTimestamp2,
2242
2242
  updatedAtLocal: Date.now(),
2243
2243
  state: "synced",
2244
2244
  deleted: true,
@@ -2256,7 +2256,7 @@ var SyncEngine = class {
2256
2256
  data: mut.op === "update" ? { ...existing?.data ?? {}, ...newData } : newData,
2257
2257
  meta: {
2258
2258
  serverVersion,
2259
- updatedAtServer: serverTimestamp,
2259
+ updatedAtServer: serverTimestamp2,
2260
2260
  updatedAtLocal: Date.now(),
2261
2261
  state: "synced",
2262
2262
  pendingMutationIds: [],
@@ -3335,6 +3335,54 @@ var TabCoordinator = class {
3335
3335
 
3336
3336
  // src/db/collection-ref.ts
3337
3337
  init_db_errors();
3338
+
3339
+ // src/db/field-value.ts
3340
+ var NEETRU_SENTINEL_KEY = "__neetru__";
3341
+ function serverTimestamp() {
3342
+ return { __neetru__: "serverTimestamp" };
3343
+ }
3344
+ function increment(n) {
3345
+ if (typeof n !== "number" || !Number.isFinite(n)) {
3346
+ throw new TypeError(
3347
+ `increment(n): n deve ser um n\xFAmero finito (recebido: ${String(n)}).`
3348
+ );
3349
+ }
3350
+ return { __neetru__: "increment", operand: n };
3351
+ }
3352
+ function isFieldSentinel(v) {
3353
+ return typeof v === "object" && v !== null && NEETRU_SENTINEL_KEY in v && typeof v[NEETRU_SENTINEL_KEY] === "string";
3354
+ }
3355
+ function isServerTimestampSentinel(v) {
3356
+ return isFieldSentinel(v) && v.__neetru__ === "serverTimestamp";
3357
+ }
3358
+ function isIncrementSentinel(v) {
3359
+ return isFieldSentinel(v) && v.__neetru__ === "increment" && typeof v.operand === "number" && Number.isFinite(v.operand);
3360
+ }
3361
+ function resolveSentinelLocally(value, baseValue) {
3362
+ if (isServerTimestampSentinel(value)) {
3363
+ return Date.now();
3364
+ }
3365
+ if (isIncrementSentinel(value)) {
3366
+ const base = typeof baseValue === "number" && Number.isFinite(baseValue) ? baseValue : 0;
3367
+ return base + value.operand;
3368
+ }
3369
+ return value;
3370
+ }
3371
+ function resolveSentinelsLocally(data, existing) {
3372
+ let touched = false;
3373
+ const out = {};
3374
+ for (const [k, v] of Object.entries(data)) {
3375
+ if (isFieldSentinel(v)) {
3376
+ touched = true;
3377
+ out[k] = resolveSentinelLocally(v, existing?.[k]);
3378
+ } else {
3379
+ out[k] = v;
3380
+ }
3381
+ }
3382
+ return touched ? out : data;
3383
+ }
3384
+
3385
+ // src/db/collection-ref.ts
3338
3386
  function isIndexedDBUnavailable() {
3339
3387
  return typeof indexedDB === "undefined" || typeof window === "undefined";
3340
3388
  }
@@ -3463,10 +3511,12 @@ var DbCollectionRefImpl = class {
3463
3511
  return this._buildListResult(q);
3464
3512
  }
3465
3513
  async add(data) {
3514
+ const rawData = data;
3515
+ const localData = resolveSentinelsLocally(rawData, void 0);
3466
3516
  const mutation = await this._queue.enqueue({
3467
3517
  collection: this._collection,
3468
3518
  op: "add",
3469
- payload: data,
3519
+ payload: rawData,
3470
3520
  baseVersion: null,
3471
3521
  batchId: null
3472
3522
  });
@@ -3474,7 +3524,7 @@ var DbCollectionRefImpl = class {
3474
3524
  await this._store.putDoc({
3475
3525
  collection: this._collection,
3476
3526
  id: docId,
3477
- data,
3527
+ data: localData,
3478
3528
  meta: {
3479
3529
  serverVersion: null,
3480
3530
  updatedAtServer: null,
@@ -3488,25 +3538,27 @@ var DbCollectionRefImpl = class {
3488
3538
  this._bus.emit([{
3489
3539
  type: "added",
3490
3540
  collection: this._collection,
3491
- doc: { id: docId, data }
3541
+ doc: { id: docId, data: localData }
3492
3542
  }]);
3493
3543
  return { ok: true, id: docId };
3494
3544
  }
3495
3545
  async set(id, data) {
3496
3546
  assertValidId(id);
3497
3547
  const existing = await this._store.getDoc(this._collection, id);
3548
+ const rawData = data;
3549
+ const localData = resolveSentinelsLocally(rawData, void 0);
3498
3550
  const mutation = await this._queue.enqueue({
3499
3551
  collection: this._collection,
3500
3552
  docId: id,
3501
3553
  op: "set",
3502
- payload: data,
3554
+ payload: rawData,
3503
3555
  baseVersion: existing?.meta.serverVersion ?? null,
3504
3556
  batchId: null
3505
3557
  });
3506
3558
  await this._store.putDoc({
3507
3559
  collection: this._collection,
3508
3560
  id,
3509
- data,
3561
+ data: localData,
3510
3562
  meta: {
3511
3563
  serverVersion: existing?.meta.serverVersion ?? null,
3512
3564
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -3520,19 +3572,22 @@ var DbCollectionRefImpl = class {
3520
3572
  this._bus.emit([{
3521
3573
  type: existing && !existing.meta.deleted ? "modified" : "added",
3522
3574
  collection: this._collection,
3523
- doc: { id, data }
3575
+ doc: { id, data: localData }
3524
3576
  }]);
3525
3577
  return { ok: true };
3526
3578
  }
3527
3579
  async update(id, data) {
3528
3580
  assertValidId(id);
3529
3581
  const existing = await this._store.getDoc(this._collection, id);
3530
- const mergedData = existing?.meta.deleted ? { ...data } : { ...existing?.data ?? {}, ...data };
3582
+ const rawData = data;
3583
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3584
+ const localData = resolveSentinelsLocally(rawData, existingBase);
3585
+ const mergedData = existing?.meta.deleted ? { ...localData } : { ...existing?.data ?? {}, ...localData };
3531
3586
  const mutation = await this._queue.enqueue({
3532
3587
  collection: this._collection,
3533
3588
  docId: id,
3534
3589
  op: "update",
3535
- payload: data,
3590
+ payload: rawData,
3536
3591
  baseVersion: existing?.meta.serverVersion ?? null,
3537
3592
  batchId: null
3538
3593
  });
@@ -3589,6 +3644,7 @@ var DbCollectionRefImpl = class {
3589
3644
  const collection = this._collection;
3590
3645
  if (op.kind === "add") {
3591
3646
  const data = op.data;
3647
+ const localData = resolveSentinelsLocally(data, void 0);
3592
3648
  const mutation = await this._queue.enqueue({
3593
3649
  collection,
3594
3650
  op: "add",
@@ -3600,7 +3656,7 @@ var DbCollectionRefImpl = class {
3600
3656
  await this._store.putDoc({
3601
3657
  collection,
3602
3658
  id: docId,
3603
- data,
3659
+ data: localData,
3604
3660
  meta: {
3605
3661
  serverVersion: null,
3606
3662
  updatedAtServer: null,
@@ -3611,11 +3667,12 @@ var DbCollectionRefImpl = class {
3611
3667
  ownerId: null
3612
3668
  }
3613
3669
  });
3614
- busChanges.push({ type: "added", collection, doc: { id: docId, data } });
3670
+ busChanges.push({ type: "added", collection, doc: { id: docId, data: localData } });
3615
3671
  } else if (op.kind === "set") {
3616
3672
  const id = op.id;
3617
3673
  const data = op.data;
3618
3674
  const existing = await this._store.getDoc(collection, id);
3675
+ const localData = resolveSentinelsLocally(data, void 0);
3619
3676
  const mutation = await this._queue.enqueue({
3620
3677
  collection,
3621
3678
  docId: id,
@@ -3627,7 +3684,7 @@ var DbCollectionRefImpl = class {
3627
3684
  await this._store.putDoc({
3628
3685
  collection,
3629
3686
  id,
3630
- data,
3687
+ data: localData,
3631
3688
  meta: {
3632
3689
  serverVersion: existing?.meta.serverVersion ?? null,
3633
3690
  updatedAtServer: existing?.meta.updatedAtServer ?? null,
@@ -3641,13 +3698,15 @@ var DbCollectionRefImpl = class {
3641
3698
  busChanges.push({
3642
3699
  type: existing && !existing.meta.deleted ? "modified" : "added",
3643
3700
  collection,
3644
- doc: { id, data }
3701
+ doc: { id, data: localData }
3645
3702
  });
3646
3703
  } else if (op.kind === "update") {
3647
3704
  const id = op.id;
3648
3705
  const data = op.data;
3649
3706
  const existing = await this._store.getDoc(collection, id);
3650
- const merged = { ...existing?.data ?? {}, ...data };
3707
+ const existingBase = existing?.meta.deleted ? void 0 : existing?.data;
3708
+ const localData = resolveSentinelsLocally(data, existingBase);
3709
+ const merged = { ...existing?.data ?? {}, ...localData };
3651
3710
  const mutation = await this._queue.enqueue({
3652
3711
  collection,
3653
3712
  docId: id,
@@ -6083,6 +6142,6 @@ init_errors();
6083
6142
  init_db_errors();
6084
6143
  var VERSION = "3.0.1";
6085
6144
 
6086
- export { DEFAULT_BASE_URL, DEV_FIXTURE_USER, MockAuth, MockCheckout, MockDb, MockEntitlements, MockNotifications, MockSupport, MockUsage, MockWebhooks, NeetruDbError, NeetruError, VERSION, createCheckoutNamespace, createNeetruClient, createNeetruDb, createNotificationsNamespace, createWebhooksNamespace, verifyWebhookSignature };
6145
+ export { DEFAULT_BASE_URL, DEV_FIXTURE_USER, MockAuth, MockCheckout, MockDb, MockEntitlements, MockNotifications, MockSupport, MockUsage, MockWebhooks, NEETRU_SENTINEL_KEY, NeetruDbError, NeetruError, VERSION, createCheckoutNamespace, createNeetruClient, createNeetruDb, createNotificationsNamespace, createWebhooksNamespace, increment, isFieldSentinel, isIncrementSentinel, isServerTimestampSentinel, serverTimestamp, verifyWebhookSignature };
6087
6146
  //# sourceMappingURL=index.mjs.map
6088
6147
  //# sourceMappingURL=index.mjs.map