@neetru/sdk 2.1.0 → 2.1.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.
Files changed (50) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/dist/auth.cjs +29 -7
  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 +29 -7
  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-BBvTTXoG.d.cts → collection-ref-DqAAhuhX.d.cts} +56 -7
  13. package/dist/{collection-ref-BBvTTXoG.d.ts → collection-ref-DqAAhuhX.d.ts} +56 -7
  14. package/dist/db-react.d.cts +1 -1
  15. package/dist/db-react.d.ts +1 -1
  16. package/dist/db.cjs +29 -7
  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 +29 -7
  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 +49 -21
  25. package/dist/index.cjs.map +1 -1
  26. package/dist/index.d.cts +3 -3
  27. package/dist/index.d.ts +3 -3
  28. package/dist/index.mjs +49 -21
  29. package/dist/index.mjs.map +1 -1
  30. package/dist/mocks.cjs +20 -14
  31. package/dist/mocks.cjs.map +1 -1
  32. package/dist/mocks.d.cts +2 -2
  33. package/dist/mocks.d.ts +2 -2
  34. package/dist/mocks.mjs +20 -14
  35. package/dist/mocks.mjs.map +1 -1
  36. package/dist/notifications.d.cts +2 -2
  37. package/dist/notifications.d.ts +2 -2
  38. package/dist/react.d.cts +2 -2
  39. package/dist/react.d.ts +2 -2
  40. package/dist/support.d.cts +2 -2
  41. package/dist/support.d.ts +2 -2
  42. package/dist/telemetry.d.cts +2 -2
  43. package/dist/telemetry.d.ts +2 -2
  44. package/dist/{types-Kmt4y1FQ.d.cts → types-Cfb-qeDg.d.cts} +1 -1
  45. package/dist/{types-B1jylbMC.d.ts → types-V1EfjR1p.d.ts} +1 -1
  46. package/dist/usage.d.cts +2 -2
  47. package/dist/usage.d.ts +2 -2
  48. package/dist/webhooks.d.cts +2 -2
  49. package/dist/webhooks.d.ts +2 -2
  50. package/package.json +2 -2
@@ -1,5 +1,5 @@
1
- import { G as ResolvedConfig, C as CatalogListOptions, b as CatalogListResponse, P as Product } from './types-Kmt4y1FQ.cjs';
2
- import './collection-ref-BBvTTXoG.cjs';
1
+ import { G as ResolvedConfig, C as CatalogListOptions, b as CatalogListResponse, P as Product } from './types-Cfb-qeDg.cjs';
2
+ import './collection-ref-DqAAhuhX.cjs';
3
3
  import '@neetru/realtime-protocol';
4
4
  import 'drizzle-orm/node-postgres';
5
5
  import './errors.cjs';
package/dist/catalog.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { G as ResolvedConfig, C as CatalogListOptions, b as CatalogListResponse, P as Product } from './types-B1jylbMC.js';
2
- import './collection-ref-BBvTTXoG.js';
1
+ import { G as ResolvedConfig, C as CatalogListOptions, b as CatalogListResponse, P as Product } from './types-V1EfjR1p.js';
2
+ import './collection-ref-DqAAhuhX.js';
3
3
  import '@neetru/realtime-protocol';
4
4
  import 'drizzle-orm/node-postgres';
5
5
  import './errors.js';
@@ -1,5 +1,5 @@
1
- export { c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, M as MockCheckout, a2 as createCheckoutNamespace } from './types-Kmt4y1FQ.cjs';
2
- import './collection-ref-BBvTTXoG.cjs';
1
+ export { c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, M as MockCheckout, a2 as createCheckoutNamespace } from './types-Cfb-qeDg.cjs';
2
+ import './collection-ref-DqAAhuhX.cjs';
3
3
  import '@neetru/realtime-protocol';
4
4
  import 'drizzle-orm/node-postgres';
5
5
  import './errors.cjs';
@@ -1,5 +1,5 @@
1
- export { c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, M as MockCheckout, a2 as createCheckoutNamespace } from './types-B1jylbMC.js';
2
- import './collection-ref-BBvTTXoG.js';
1
+ export { c as CheckoutIntentInfo, d as CheckoutIntentStatus, e as CheckoutNamespace, f as CheckoutStartInput, g as CheckoutStartResult, h as CheckoutTenantType, M as MockCheckout, a2 as createCheckoutNamespace } from './types-V1EfjR1p.js';
2
+ import './collection-ref-DqAAhuhX.js';
3
3
  import '@neetru/realtime-protocol';
4
4
  import 'drizzle-orm/node-postgres';
5
5
  import './errors.js';
@@ -293,12 +293,43 @@ interface DbGetResult<T = Record<string, unknown>> {
293
293
  }>;
294
294
  }
295
295
  type DbChangeType = 'added' | 'modified' | 'removed';
296
- interface DbBatchOp {
297
- op: 'add' | 'set' | 'update' | 'remove';
298
- collection: string;
299
- id?: string;
300
- data?: Record<string, unknown>;
301
- }
296
+ /**
297
+ * Operação atômica para uso em `DbCollectionRef.batch()`.
298
+ *
299
+ * Discriminated union pelo campo `kind` — cada variante deixa claro
300
+ * quais campos são obrigatórios:
301
+ *
302
+ * - `add` — insere com id gerado pelo cliente; `data` obrigatório.
303
+ * - `set` — cria ou sobrescreve pelo `id`; `data` obrigatório.
304
+ * - `update` — mescla campos em doc existente pelo `id`; `data` obrigatório.
305
+ * - `remove` — tombstone pelo `id`; sem `data`.
306
+ *
307
+ * @example
308
+ * ```ts
309
+ * const ops: DbBatchOp[] = [
310
+ * { kind: 'add', data: { name: 'produto A', price: 10 } },
311
+ * { kind: 'set', id: 'sku-1', data: { name: 'produto B', price: 20 } },
312
+ * { kind: 'update', id: 'sku-2', data: { price: 25 } },
313
+ * { kind: 'remove', id: 'sku-3' },
314
+ * ];
315
+ * await col.batch(ops);
316
+ * ```
317
+ */
318
+ type DbBatchOp<T = Record<string, unknown>> = {
319
+ kind: 'add';
320
+ data: Omit<T, 'id'>;
321
+ } | {
322
+ kind: 'set';
323
+ id: string;
324
+ data: Omit<T, 'id'>;
325
+ } | {
326
+ kind: 'update';
327
+ id: string;
328
+ data: Partial<Omit<T, 'id'>>;
329
+ } | {
330
+ kind: 'remove';
331
+ id: string;
332
+ };
302
333
  /**
303
334
  * Contrato do transporte de realtime — injetado no namespace.
304
335
  *
@@ -313,8 +344,26 @@ type RealtimeTransport = SyncTransport;
313
344
  /**
314
345
  * Referência a um documento específico.
315
346
  * Parte da superfície `DbCollectionRef.doc(id)`.
347
+ *
348
+ * Expõe as propriedades de identidade do documento de forma análoga ao
349
+ * `DocumentReference` do Firestore SDK, evitando a necessidade de adaptadores
350
+ * externos que reattachavam `collection` + `id` manualmente.
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * const ref = orders.doc('order-123');
355
+ * console.log(ref.id); // "order-123"
356
+ * console.log(ref.collection); // "orders"
357
+ * console.log(ref.path); // "orders/order-123"
358
+ * ```
316
359
  */
317
360
  interface DbDocRef<T = Record<string, unknown>> {
361
+ /** ID do documento dentro da coleção. */
362
+ readonly id: string;
363
+ /** Caminho completo no formato "collection/docId". */
364
+ readonly path: string;
365
+ /** Nome da coleção parent. */
366
+ readonly collection: string;
318
367
  get(): Promise<DbGetResult<T> | null>;
319
368
  set(data: Omit<T, 'id'>): Promise<{
320
369
  ok: true;
@@ -355,7 +404,7 @@ interface DbCollectionRef<T = Record<string, unknown>> {
355
404
  ok: true;
356
405
  }>;
357
406
  /** Aplica múltiplas operações atomicamente na fila. */
358
- batch(ops: DbBatchOp[]): Promise<{
407
+ batch(ops: DbBatchOp<T>[]): Promise<{
359
408
  ok: true;
360
409
  }>;
361
410
  /** Escuta um documento específico. */
@@ -293,12 +293,43 @@ interface DbGetResult<T = Record<string, unknown>> {
293
293
  }>;
294
294
  }
295
295
  type DbChangeType = 'added' | 'modified' | 'removed';
296
- interface DbBatchOp {
297
- op: 'add' | 'set' | 'update' | 'remove';
298
- collection: string;
299
- id?: string;
300
- data?: Record<string, unknown>;
301
- }
296
+ /**
297
+ * Operação atômica para uso em `DbCollectionRef.batch()`.
298
+ *
299
+ * Discriminated union pelo campo `kind` — cada variante deixa claro
300
+ * quais campos são obrigatórios:
301
+ *
302
+ * - `add` — insere com id gerado pelo cliente; `data` obrigatório.
303
+ * - `set` — cria ou sobrescreve pelo `id`; `data` obrigatório.
304
+ * - `update` — mescla campos em doc existente pelo `id`; `data` obrigatório.
305
+ * - `remove` — tombstone pelo `id`; sem `data`.
306
+ *
307
+ * @example
308
+ * ```ts
309
+ * const ops: DbBatchOp[] = [
310
+ * { kind: 'add', data: { name: 'produto A', price: 10 } },
311
+ * { kind: 'set', id: 'sku-1', data: { name: 'produto B', price: 20 } },
312
+ * { kind: 'update', id: 'sku-2', data: { price: 25 } },
313
+ * { kind: 'remove', id: 'sku-3' },
314
+ * ];
315
+ * await col.batch(ops);
316
+ * ```
317
+ */
318
+ type DbBatchOp<T = Record<string, unknown>> = {
319
+ kind: 'add';
320
+ data: Omit<T, 'id'>;
321
+ } | {
322
+ kind: 'set';
323
+ id: string;
324
+ data: Omit<T, 'id'>;
325
+ } | {
326
+ kind: 'update';
327
+ id: string;
328
+ data: Partial<Omit<T, 'id'>>;
329
+ } | {
330
+ kind: 'remove';
331
+ id: string;
332
+ };
302
333
  /**
303
334
  * Contrato do transporte de realtime — injetado no namespace.
304
335
  *
@@ -313,8 +344,26 @@ type RealtimeTransport = SyncTransport;
313
344
  /**
314
345
  * Referência a um documento específico.
315
346
  * Parte da superfície `DbCollectionRef.doc(id)`.
347
+ *
348
+ * Expõe as propriedades de identidade do documento de forma análoga ao
349
+ * `DocumentReference` do Firestore SDK, evitando a necessidade de adaptadores
350
+ * externos que reattachavam `collection` + `id` manualmente.
351
+ *
352
+ * @example
353
+ * ```ts
354
+ * const ref = orders.doc('order-123');
355
+ * console.log(ref.id); // "order-123"
356
+ * console.log(ref.collection); // "orders"
357
+ * console.log(ref.path); // "orders/order-123"
358
+ * ```
316
359
  */
317
360
  interface DbDocRef<T = Record<string, unknown>> {
361
+ /** ID do documento dentro da coleção. */
362
+ readonly id: string;
363
+ /** Caminho completo no formato "collection/docId". */
364
+ readonly path: string;
365
+ /** Nome da coleção parent. */
366
+ readonly collection: string;
318
367
  get(): Promise<DbGetResult<T> | null>;
319
368
  set(data: Omit<T, 'id'>): Promise<{
320
369
  ok: true;
@@ -355,7 +404,7 @@ interface DbCollectionRef<T = Record<string, unknown>> {
355
404
  ok: true;
356
405
  }>;
357
406
  /** Aplica múltiplas operações atomicamente na fila. */
358
- batch(ops: DbBatchOp[]): Promise<{
407
+ batch(ops: DbBatchOp<T>[]): Promise<{
359
408
  ok: true;
360
409
  }>;
361
410
  /** Escuta um documento específico. */
@@ -1,4 +1,4 @@
1
- import { S as SyncState, U as Unsubscribe, d as DbDoc, c as DbCollectionRef, h as DbQuery } from './collection-ref-BBvTTXoG.cjs';
1
+ import { S as SyncState, U as Unsubscribe, d as DbDoc, c as DbCollectionRef, h as DbQuery } from './collection-ref-DqAAhuhX.cjs';
2
2
 
3
3
  /**
4
4
  * Resultado de `useDocument`.
@@ -1,4 +1,4 @@
1
- import { S as SyncState, U as Unsubscribe, d as DbDoc, c as DbCollectionRef, h as DbQuery } from './collection-ref-BBvTTXoG.js';
1
+ import { S as SyncState, U as Unsubscribe, d as DbDoc, c as DbCollectionRef, h as DbQuery } from './collection-ref-DqAAhuhX.js';
2
2
 
3
3
  /**
4
4
  * Resultado de `useDocument`.
package/dist/db.cjs CHANGED
@@ -2377,10 +2377,9 @@ var DbCollectionRefImpl = class {
2377
2377
  const batchId = `batch-${Date.now()}-${Math.random().toString(36).slice(2)}`;
2378
2378
  const busChanges = [];
2379
2379
  for (const op of ops) {
2380
- const id = op.id ?? `${Date.now()}-${Math.random().toString(36).slice(2)}`;
2381
- const data = op.data ?? {};
2382
- const collection = op.collection;
2383
- if (op.op === "add") {
2380
+ const collection = this._collection;
2381
+ if (op.kind === "add") {
2382
+ const data = op.data;
2384
2383
  const mutation = await this._queue.enqueue({
2385
2384
  collection,
2386
2385
  op: "add",
@@ -2404,7 +2403,9 @@ var DbCollectionRefImpl = class {
2404
2403
  }
2405
2404
  });
2406
2405
  busChanges.push({ type: "added", collection, doc: { id: docId, data } });
2407
- } else if (op.op === "set") {
2406
+ } else if (op.kind === "set") {
2407
+ const id = op.id;
2408
+ const data = op.data;
2408
2409
  const existing = await this._store.getDoc(collection, id);
2409
2410
  const mutation = await this._queue.enqueue({
2410
2411
  collection,
@@ -2433,7 +2434,9 @@ var DbCollectionRefImpl = class {
2433
2434
  collection,
2434
2435
  doc: { id, data }
2435
2436
  });
2436
- } else if (op.op === "update") {
2437
+ } else if (op.kind === "update") {
2438
+ const id = op.id;
2439
+ const data = op.data;
2437
2440
  const existing = await this._store.getDoc(collection, id);
2438
2441
  const merged = { ...existing?.data ?? {}, ...data };
2439
2442
  const mutation = await this._queue.enqueue({
@@ -2462,7 +2465,8 @@ var DbCollectionRefImpl = class {
2462
2465
  }
2463
2466
  });
2464
2467
  busChanges.push({ type: "modified", collection, doc: { id, data: merged } });
2465
- } else if (op.op === "remove") {
2468
+ } else if (op.kind === "remove") {
2469
+ const id = op.id;
2466
2470
  const existing = await this._store.getDoc(collection, id);
2467
2471
  await this._queue.enqueue({
2468
2472
  collection,
@@ -2571,6 +2575,15 @@ var DbCollectionRefImpl = class {
2571
2575
  assertValidId(id);
2572
2576
  const self = this;
2573
2577
  return {
2578
+ get id() {
2579
+ return id;
2580
+ },
2581
+ get path() {
2582
+ return `${self._collection}/${id}`;
2583
+ },
2584
+ get collection() {
2585
+ return self._collection;
2586
+ },
2574
2587
  async get() {
2575
2588
  return self._buildGetResult(id);
2576
2589
  },
@@ -3707,6 +3720,15 @@ function createLazyCollectionRef(name, getDocsPromise) {
3707
3720
  },
3708
3721
  doc(id) {
3709
3722
  return {
3723
+ get id() {
3724
+ return id;
3725
+ },
3726
+ get path() {
3727
+ return `${name}/${id}`;
3728
+ },
3729
+ get collection() {
3730
+ return name;
3731
+ },
3710
3732
  async get() {
3711
3733
  return (await getRef()).doc(id).get();
3712
3734
  },