@neetru/sdk 2.3.5 → 3.0.0

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 (83) hide show
  1. package/CHANGELOG.md +184 -0
  2. package/README.md +59 -22
  3. package/dist/auth.cjs +368 -142
  4. package/dist/auth.cjs.map +1 -1
  5. package/dist/auth.d.cts +1 -1
  6. package/dist/auth.d.ts +1 -1
  7. package/dist/auth.mjs +368 -142
  8. package/dist/auth.mjs.map +1 -1
  9. package/dist/catalog.cjs +21 -2
  10. package/dist/catalog.cjs.map +1 -1
  11. package/dist/catalog.d.cts +1 -1
  12. package/dist/catalog.d.ts +1 -1
  13. package/dist/catalog.mjs +21 -2
  14. package/dist/catalog.mjs.map +1 -1
  15. package/dist/checkout.cjs +21 -2
  16. package/dist/checkout.cjs.map +1 -1
  17. package/dist/checkout.d.cts +1 -1
  18. package/dist/checkout.d.ts +1 -1
  19. package/dist/checkout.mjs +21 -2
  20. package/dist/checkout.mjs.map +1 -1
  21. package/dist/db.cjs +36 -5
  22. package/dist/db.cjs.map +1 -1
  23. package/dist/db.d.cts +1 -1
  24. package/dist/db.d.ts +1 -1
  25. package/dist/db.mjs +36 -5
  26. package/dist/db.mjs.map +1 -1
  27. package/dist/entitlements.cjs +21 -2
  28. package/dist/entitlements.cjs.map +1 -1
  29. package/dist/entitlements.d.cts +1 -1
  30. package/dist/entitlements.d.ts +1 -1
  31. package/dist/entitlements.mjs +21 -2
  32. package/dist/entitlements.mjs.map +1 -1
  33. package/dist/errors.cjs.map +1 -1
  34. package/dist/errors.d.cts +3 -1
  35. package/dist/errors.d.ts +3 -1
  36. package/dist/errors.mjs.map +1 -1
  37. package/dist/index.cjs +432 -152
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +31 -19
  40. package/dist/index.d.ts +31 -19
  41. package/dist/index.mjs +432 -152
  42. package/dist/index.mjs.map +1 -1
  43. package/dist/mocks.cjs +49 -37
  44. package/dist/mocks.cjs.map +1 -1
  45. package/dist/mocks.d.cts +23 -19
  46. package/dist/mocks.d.ts +23 -19
  47. package/dist/mocks.mjs +49 -37
  48. package/dist/mocks.mjs.map +1 -1
  49. package/dist/notifications.cjs +80 -14
  50. package/dist/notifications.cjs.map +1 -1
  51. package/dist/notifications.d.cts +1 -1
  52. package/dist/notifications.d.ts +1 -1
  53. package/dist/notifications.mjs +80 -14
  54. package/dist/notifications.mjs.map +1 -1
  55. package/dist/react.d.cts +1 -1
  56. package/dist/react.d.ts +1 -1
  57. package/dist/support.cjs +72 -12
  58. package/dist/support.cjs.map +1 -1
  59. package/dist/support.d.cts +1 -1
  60. package/dist/support.d.ts +1 -1
  61. package/dist/support.mjs +72 -12
  62. package/dist/support.mjs.map +1 -1
  63. package/dist/telemetry.cjs +23 -4
  64. package/dist/telemetry.cjs.map +1 -1
  65. package/dist/telemetry.d.cts +1 -1
  66. package/dist/telemetry.d.ts +1 -1
  67. package/dist/telemetry.mjs +23 -4
  68. package/dist/telemetry.mjs.map +1 -1
  69. package/dist/{types-sGGN1vkg.d.cts → types-DLOvkeAP.d.cts} +110 -49
  70. package/dist/{types-CSC-RIdS.d.ts → types-dw19bdID.d.ts} +110 -49
  71. package/dist/usage.cjs +57 -63
  72. package/dist/usage.cjs.map +1 -1
  73. package/dist/usage.d.cts +1 -1
  74. package/dist/usage.d.ts +1 -1
  75. package/dist/usage.mjs +57 -63
  76. package/dist/usage.mjs.map +1 -1
  77. package/dist/webhooks.cjs +110 -33
  78. package/dist/webhooks.cjs.map +1 -1
  79. package/dist/webhooks.d.cts +1 -1
  80. package/dist/webhooks.d.ts +1 -1
  81. package/dist/webhooks.mjs +110 -33
  82. package/dist/webhooks.mjs.map +1 -1
  83. package/package.json +2 -2
package/dist/db.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { C as ConflictRecord, a as CreateOfflineDocumentsOptions, D as DbBatchOp, b as DbChangeType, c as DbCollectionRef, d as DbDoc, e as DbDocRef, f as DbGetResult, g as DbListResult, h as DbQuery, i as DbWhereFilter, N as NeetruDbDocuments, R as RealtimeTransport, S as SyncState } from './collection-ref-DqAAhuhX.cjs';
2
- export { k as DbSqlLease, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, w as NeetruSqlClient, J as SqlOptions, a5 as createNeetruDb, a7 as createRestSyncTransport, a9 as getWebSocketRealtimeClient } from './types-sGGN1vkg.cjs';
2
+ export { k as DbSqlLease, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, w as NeetruSqlClient, K as SqlOptions, a7 as createNeetruDb, a9 as createRestSyncTransport, ab as getWebSocketRealtimeClient } from './types-DLOvkeAP.cjs';
3
3
  import '@neetru/realtime-protocol';
4
4
  import 'drizzle-orm/node-postgres';
5
5
  import './errors.cjs';
package/dist/db.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { C as ConflictRecord, a as CreateOfflineDocumentsOptions, D as DbBatchOp, b as DbChangeType, c as DbCollectionRef, d as DbDoc, e as DbDocRef, f as DbGetResult, g as DbListResult, h as DbQuery, i as DbWhereFilter, N as NeetruDbDocuments, R as RealtimeTransport, S as SyncState } from './collection-ref-DqAAhuhX.js';
2
- export { k as DbSqlLease, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, w as NeetruSqlClient, J as SqlOptions, a5 as createNeetruDb, a7 as createRestSyncTransport, a9 as getWebSocketRealtimeClient } from './types-CSC-RIdS.js';
2
+ export { k as DbSqlLease, p as NeetruDb, q as NeetruDbEngine, r as NeetruDbError, s as NeetruDbErrorCode, t as NeetruDbOptions, u as NeetruDbTransport, w as NeetruSqlClient, K as SqlOptions, a7 as createNeetruDb, a9 as createRestSyncTransport, ab as getWebSocketRealtimeClient } from './types-dw19bdID.js';
3
3
  import '@neetru/realtime-protocol';
4
4
  import 'drizzle-orm/node-postgres';
5
5
  import './errors.js';
package/dist/db.mjs CHANGED
@@ -65,6 +65,23 @@ var init_db_errors = __esm({
65
65
  }
66
66
  });
67
67
 
68
+ // src/idempotency.ts
69
+ function generateIdempotencyKey() {
70
+ const cryptoObj = typeof globalThis !== "undefined" && "crypto" in globalThis ? globalThis.crypto : void 0;
71
+ if (cryptoObj && typeof cryptoObj.randomUUID === "function") {
72
+ return cryptoObj.randomUUID();
73
+ }
74
+ throw new NeetruError(
75
+ "runtime_unsupported",
76
+ "crypto.randomUUID not available in this runtime. SDK 3.0 requires Node \u226520 or modern browser/Edge."
77
+ );
78
+ }
79
+ var init_idempotency = __esm({
80
+ "src/idempotency.ts"() {
81
+ init_errors();
82
+ }
83
+ });
84
+
68
85
  // src/http.ts
69
86
  var http_exports = {};
70
87
  __export(http_exports, {
@@ -122,7 +139,8 @@ async function safeJson(res) {
122
139
  async function httpRequest(config, opts) {
123
140
  const method = opts.method ?? "GET";
124
141
  const url = buildUrl(config.baseUrl, opts.path, opts.query);
125
- const maxRetries = opts.retries ?? DEFAULT_RETRIES;
142
+ const defaultRetries = READ_METHODS.has(method) ? DEFAULT_RETRIES_READ : DEFAULT_RETRIES_WRITE;
143
+ const maxRetries = opts.retries ?? defaultRetries;
126
144
  const headers = {
127
145
  accept: "application/json",
128
146
  ...opts.headers
@@ -136,6 +154,10 @@ async function httpRequest(config, opts) {
136
154
  }
137
155
  headers.authorization = `Bearer ${config.apiKey}`;
138
156
  }
157
+ if (opts.idempotencyKey) {
158
+ const key = typeof opts.idempotencyKey === "string" ? opts.idempotencyKey : generateIdempotencyKey();
159
+ headers["idempotency-key"] = key;
160
+ }
139
161
  const bodyString = opts.body !== void 0 && method !== "GET" && method !== "DELETE" ? JSON.stringify(opts.body) : void 0;
140
162
  if (bodyString !== void 0) {
141
163
  headers["content-type"] = "application/json";
@@ -187,11 +209,14 @@ async function httpRequest(config, opts) {
187
209
  }
188
210
  throw lastError ?? new NeetruError("unknown", "unexpected httpRequest exit");
189
211
  }
190
- var DEFAULT_RETRIES, RETRYABLE_CODES2;
212
+ var DEFAULT_RETRIES_READ, DEFAULT_RETRIES_WRITE, READ_METHODS, RETRYABLE_CODES2;
191
213
  var init_http = __esm({
192
214
  "src/http.ts"() {
193
215
  init_errors();
194
- DEFAULT_RETRIES = 2;
216
+ init_idempotency();
217
+ DEFAULT_RETRIES_READ = 2;
218
+ DEFAULT_RETRIES_WRITE = 0;
219
+ READ_METHODS = /* @__PURE__ */ new Set(["GET", "HEAD"]);
195
220
  RETRYABLE_CODES2 = /* @__PURE__ */ new Set([
196
221
  "rate_limited",
197
222
  "server_error",
@@ -447,7 +472,10 @@ function parseLease(raw) {
447
472
  };
448
473
  }
449
474
  async function createPgPool(lease) {
450
- const { Pool } = await import('pg');
475
+ const { Pool } = await import(
476
+ /* webpackIgnore: true */
477
+ 'pg'
478
+ );
451
479
  const ssl = lease.sslca ? {
452
480
  ca: lease.sslca,
453
481
  cert: lease.clientCert ?? void 0,
@@ -467,7 +495,10 @@ async function createPgPool(lease) {
467
495
  });
468
496
  }
469
497
  async function createDrizzleHandle(pool, schema) {
470
- const { drizzle } = await import('drizzle-orm/node-postgres');
498
+ const { drizzle } = await import(
499
+ /* webpackIgnore: true */
500
+ 'drizzle-orm/node-postgres'
501
+ );
471
502
  return drizzle(pool, { schema });
472
503
  }
473
504
  async function createSqlClientWithDeps(deps, options) {