@zveltio/sdk 2.0.8 → 3.0.0-beta.100

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 (157) hide show
  1. package/README.md +17 -4
  2. package/dist/build/index.d.ts +77 -0
  3. package/dist/build/index.d.ts.map +1 -0
  4. package/dist/build/index.js +157 -0
  5. package/dist/client.d.ts +103 -7
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +129 -28
  8. package/dist/core.d.ts.map +1 -1
  9. package/dist/core.js +21 -3
  10. package/dist/crdt.d.ts.map +1 -1
  11. package/dist/crdt.js +11 -2
  12. package/dist/ddl/index.d.ts +173 -0
  13. package/dist/ddl/index.d.ts.map +1 -0
  14. package/dist/ddl/index.js +33 -0
  15. package/dist/errors.d.ts +58 -0
  16. package/dist/errors.d.ts.map +1 -0
  17. package/dist/errors.js +124 -0
  18. package/dist/extension/action-refusal.d.ts +27 -0
  19. package/dist/extension/action-refusal.d.ts.map +1 -0
  20. package/dist/extension/action-refusal.js +29 -0
  21. package/dist/extension/capabilities.d.ts +71 -0
  22. package/dist/extension/capabilities.d.ts.map +1 -0
  23. package/dist/extension/capabilities.js +79 -0
  24. package/dist/extension/dates.d.ts +7 -0
  25. package/dist/extension/dates.d.ts.map +1 -0
  26. package/dist/extension/dates.js +14 -0
  27. package/dist/extension/index.d.ts +1570 -10
  28. package/dist/extension/index.d.ts.map +1 -1
  29. package/dist/extension/index.js +17 -1
  30. package/dist/extension/jsonb.d.ts +62 -0
  31. package/dist/extension/jsonb.d.ts.map +1 -0
  32. package/dist/extension/jsonb.js +64 -0
  33. package/dist/extension/multipart.d.ts +58 -0
  34. package/dist/extension/multipart.d.ts.map +1 -0
  35. package/dist/extension/multipart.js +61 -0
  36. package/dist/extension/numeric.d.ts +94 -0
  37. package/dist/extension/numeric.d.ts.map +1 -0
  38. package/dist/extension/numeric.js +162 -0
  39. package/dist/extension/permission-gate.d.ts +52 -0
  40. package/dist/extension/permission-gate.d.ts.map +1 -0
  41. package/dist/extension/permission-gate.js +125 -0
  42. package/dist/extension/reserved-paths.d.ts +10 -0
  43. package/dist/extension/reserved-paths.d.ts.map +1 -0
  44. package/dist/extension/reserved-paths.js +23 -0
  45. package/dist/index.d.ts +4 -2
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.js +1 -0
  48. package/dist/local-store.d.ts +14 -1
  49. package/dist/local-store.d.ts.map +1 -1
  50. package/dist/local-store.js +93 -16
  51. package/dist/offline/index.d.ts +75 -0
  52. package/dist/offline/index.d.ts.map +1 -0
  53. package/dist/offline/index.js +251 -0
  54. package/dist/publish/index.d.ts +94 -0
  55. package/dist/publish/index.d.ts.map +1 -0
  56. package/dist/publish/index.js +153 -0
  57. package/dist/realtime.d.ts +25 -1
  58. package/dist/realtime.d.ts.map +1 -1
  59. package/dist/realtime.js +53 -5
  60. package/dist/rpc/index.d.ts +68 -0
  61. package/dist/rpc/index.d.ts.map +1 -0
  62. package/dist/rpc/index.js +63 -0
  63. package/dist/schema-codegen.d.ts +84 -0
  64. package/dist/schema-codegen.d.ts.map +1 -0
  65. package/dist/schema-codegen.js +503 -0
  66. package/dist/schema-watcher.d.ts +10 -2
  67. package/dist/schema-watcher.d.ts.map +1 -1
  68. package/dist/schema-watcher.js +26 -13
  69. package/dist/studio/index.d.ts +85 -0
  70. package/dist/studio/index.d.ts.map +1 -0
  71. package/dist/studio/index.js +183 -0
  72. package/dist/studio/slot-owner-registry.d.ts +13 -0
  73. package/dist/studio/slot-owner-registry.d.ts.map +1 -0
  74. package/dist/studio/slot-owner-registry.js +21 -0
  75. package/dist/svelte.d.ts +1 -1
  76. package/dist/svelte.d.ts.map +1 -1
  77. package/dist/svelte.js +4 -2
  78. package/dist/sync-manager.d.ts +49 -4
  79. package/dist/sync-manager.d.ts.map +1 -1
  80. package/dist/sync-manager.js +175 -24
  81. package/dist/testing/index.d.ts +121 -0
  82. package/dist/testing/index.d.ts.map +1 -0
  83. package/dist/testing/index.js +305 -0
  84. package/dist/testing/with-test-db.d.ts +119 -0
  85. package/dist/testing/with-test-db.d.ts.map +1 -0
  86. package/dist/testing/with-test-db.js +320 -0
  87. package/dist/tests/action-refusal.test.d.ts +2 -0
  88. package/dist/tests/action-refusal.test.d.ts.map +1 -0
  89. package/dist/tests/action-refusal.test.js +13 -0
  90. package/dist/tests/client.test.d.ts +2 -0
  91. package/dist/tests/client.test.d.ts.map +1 -0
  92. package/dist/tests/client.test.js +164 -0
  93. package/dist/tests/crdt-orset.test.d.ts +2 -0
  94. package/dist/tests/crdt-orset.test.d.ts.map +1 -0
  95. package/dist/tests/crdt-orset.test.js +23 -0
  96. package/dist/tests/local-store.test.js +44 -0
  97. package/dist/tests/migration-parse.test.d.ts +2 -0
  98. package/dist/tests/migration-parse.test.d.ts.map +1 -0
  99. package/dist/tests/migration-parse.test.js +17 -0
  100. package/dist/tests/multipart.test.d.ts +2 -0
  101. package/dist/tests/multipart.test.d.ts.map +1 -0
  102. package/dist/tests/multipart.test.js +37 -0
  103. package/dist/tests/offline-provider-crdt.test.d.ts +2 -0
  104. package/dist/tests/offline-provider-crdt.test.d.ts.map +1 -0
  105. package/dist/tests/offline-provider-crdt.test.js +206 -0
  106. package/dist/tests/realtime.test.d.ts +2 -0
  107. package/dist/tests/realtime.test.d.ts.map +1 -0
  108. package/dist/tests/realtime.test.js +220 -0
  109. package/dist/tests/reserved-paths.test.d.ts +2 -0
  110. package/dist/tests/reserved-paths.test.d.ts.map +1 -0
  111. package/dist/tests/reserved-paths.test.js +21 -0
  112. package/dist/tests/sync-manager.test.d.ts +2 -0
  113. package/dist/tests/sync-manager.test.d.ts.map +1 -0
  114. package/dist/tests/sync-manager.test.js +123 -0
  115. package/dist/tests/today-in.test.d.ts +2 -0
  116. package/dist/tests/today-in.test.d.ts.map +1 -0
  117. package/dist/tests/today-in.test.js +14 -0
  118. package/dist/tests/validate-manifest-actions.test.d.ts +2 -0
  119. package/dist/tests/validate-manifest-actions.test.d.ts.map +1 -0
  120. package/dist/tests/validate-manifest-actions.test.js +82 -0
  121. package/dist/tests/validate-manifest-dependencies.test.d.ts +2 -0
  122. package/dist/tests/validate-manifest-dependencies.test.d.ts.map +1 -0
  123. package/dist/tests/validate-manifest-dependencies.test.js +27 -0
  124. package/dist/tests/validate-manifest-forward-credentials.test.d.ts +2 -0
  125. package/dist/tests/validate-manifest-forward-credentials.test.d.ts.map +1 -0
  126. package/dist/tests/validate-manifest-forward-credentials.test.js +35 -0
  127. package/dist/tests/validate-sdui-data-endpoints.test.d.ts +2 -0
  128. package/dist/tests/validate-sdui-data-endpoints.test.d.ts.map +1 -0
  129. package/dist/tests/validate-sdui-data-endpoints.test.js +41 -0
  130. package/dist/tests/with-test-db.test.d.ts +2 -0
  131. package/dist/tests/with-test-db.test.d.ts.map +1 -0
  132. package/dist/tests/with-test-db.test.js +57 -0
  133. package/dist/types/index.d.ts.map +1 -1
  134. package/dist/utils.d.ts.map +1 -1
  135. package/dist/utils.js +3 -1
  136. package/dist/validate/index.d.ts +148 -0
  137. package/dist/validate/index.d.ts.map +1 -0
  138. package/dist/validate/index.js +887 -0
  139. package/dist/validate/migration-parse.d.ts +22 -0
  140. package/dist/validate/migration-parse.d.ts.map +1 -0
  141. package/dist/validate/migration-parse.js +11 -0
  142. package/dist/validate/shared-message-keys.d.ts +16 -0
  143. package/dist/validate/shared-message-keys.d.ts.map +1 -0
  144. package/dist/validate/shared-message-keys.js +227 -0
  145. package/package.json +56 -4
  146. package/dist/client/Auth.d.ts +0 -19
  147. package/dist/client/Auth.d.ts.map +0 -1
  148. package/dist/client/Auth.js +0 -45
  149. package/dist/client/QueryBuilder.d.ts +0 -17
  150. package/dist/client/QueryBuilder.d.ts.map +0 -1
  151. package/dist/client/QueryBuilder.js +0 -76
  152. package/dist/client/RealtimeClient.d.ts +0 -22
  153. package/dist/client/RealtimeClient.d.ts.map +0 -1
  154. package/dist/client/RealtimeClient.js +0 -96
  155. package/dist/client/ZveltioClient.d.ts +0 -20
  156. package/dist/client/ZveltioClient.d.ts.map +0 -1
  157. package/dist/client/ZveltioClient.js +0 -78
@@ -0,0 +1 @@
1
+ {"version":3,"file":"permission-gate.d.ts","sourceRoot":"","sources":["../../src/extension/permission-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEtC,UAAU,OAAO;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,UAAU,aAAa;IACrB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,OAAO,CAAC;IACtB,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB;AAED,UAAU,WAAW;IACnB,eAAe,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IACxF;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;CAC/E;AAmGD,wBAAgB,cAAc,CAC5B,GAAG,EAAE,WAAW,EAChB,QAAQ,EAAE,MAAM,EAChB,IAAI,GAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAO,IAGzC,GAAG,GAAG,EAAE,MAAM,MAAM,YAAY,CAAC,OAAO,CAAC,kBAgCxD"}
@@ -0,0 +1,125 @@
1
+ /**
2
+ * `permissionGate` — minimal route-level RBAC for extensions.
3
+ *
4
+ * Default-deny: if no Casbin policy grants the resource/action, the request
5
+ * is rejected with 403. The god role bypasses the gate (handled by the
6
+ * engine's `checkPermission`).
7
+ *
8
+ * Action is derived from the HTTP method using the standard CRUD mapping
9
+ * (GET → read, POST → create, PATCH/PUT → update, DELETE → delete). The
10
+ * `resource` is the extension's logical name (e.g. `'crm'`, `'invoices'`);
11
+ * operators grant access by adding a Casbin policy:
12
+ *
13
+ * INSERT INTO zvd_permissions (ptype, v0, v1, v2)
14
+ * VALUES ('p', 'user_role', 'crm', 'read');
15
+ *
16
+ * Why this exists: many extensions historically only checked
17
+ * `auth.api.getSession(...)` — i.e. any authenticated user could
18
+ * read/write the entire extension. That's the right default for a
19
+ * single-tenant deployment but unacceptable in multi-tenant or
20
+ * role-segmented installs. The gate gives operators a single knob to
21
+ * tighten access without each extension having to roll its own RBAC.
22
+ *
23
+ * Usage in an extension's `routes.ts`:
24
+ *
25
+ * app.use('*', permissionGate(ctx, 'crm'));
26
+ *
27
+ * Place AFTER the auth-guard middleware that sets `c.set('user', ...)`.
28
+ */
29
+ async function refuse(ctx, c, resource, action) {
30
+ let denial = null;
31
+ try {
32
+ denial = (await ctx.describeDenial?.(resource, action)) ?? null;
33
+ }
34
+ catch {
35
+ /* the refusal matters more than the suggestion */
36
+ }
37
+ const names = denial?.canGrant.map((g) => g.name) ?? [];
38
+ const who = names.length === 0
39
+ ? 'An administrator of this workspace'
40
+ : names.length === 1
41
+ ? names[0]
42
+ : `${names.slice(0, -1).join(', ')} or ${names[names.length - 1]}`;
43
+ const what = denial?.confidential
44
+ ? `${resource} is confidential`
45
+ : `you do not have access to ${resource}`;
46
+ const detail = names.length === 0 ? `${what}. ${who} can grant it.` : `${what}. ${who} can give you access.`;
47
+ return c.json({
48
+ type: 'about:blank',
49
+ title: 'Forbidden',
50
+ status: 403,
51
+ code: 'permission_required',
52
+ detail,
53
+ resource,
54
+ action,
55
+ confidential: denial?.confidential ?? false,
56
+ can_grant: names.map((name) => ({ name })),
57
+ }, 403);
58
+ }
59
+ function methodToAction(method) {
60
+ const m = method.toUpperCase();
61
+ switch (m) {
62
+ case 'GET':
63
+ case 'HEAD':
64
+ case 'OPTIONS':
65
+ return 'read';
66
+ case 'POST':
67
+ return 'create';
68
+ case 'PATCH':
69
+ case 'PUT':
70
+ return 'update';
71
+ case 'DELETE':
72
+ return 'delete';
73
+ default:
74
+ // Unknown method → demand the most restrictive action so the gate
75
+ // never fails open.
76
+ return 'delete';
77
+ }
78
+ }
79
+ /**
80
+ * Operators can disable the gate temporarily during a permission backfill
81
+ * by setting `EXTENSION_RBAC=permissive`. When permissive, the gate becomes
82
+ * a no-op (any authenticated user passes) but still logs the denied
83
+ * attempts so the operator can preview what *would* have been blocked
84
+ * before flipping to strict.
85
+ *
86
+ * Strict (default) is the secure posture and what the SDK ships with.
87
+ */
88
+ function rbacMode() {
89
+ // biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
90
+ const v = globalThis.process?.env?.EXTENSION_RBAC;
91
+ return v === 'permissive' ? 'permissive' : 'strict';
92
+ }
93
+ export function permissionGate(ctx, resource, opts = {}) {
94
+ // biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
95
+ return async (c, next) => {
96
+ // CORS preflight (OPTIONS) must never be authorization-gated —
97
+ // browsers send it without credentials and a 401/403 here breaks
98
+ // the actual cross-origin request that would follow. The global
99
+ // CORS middleware in the engine returns the preflight response;
100
+ // we just need to let it through.
101
+ if (c.req.method === 'OPTIONS') {
102
+ await next();
103
+ return;
104
+ }
105
+ const user = c.get('user');
106
+ if (!user?.id) {
107
+ return c.json({ error: 'Unauthorized' }, 401);
108
+ }
109
+ const methodKey = c.req.method.toUpperCase();
110
+ const action = opts.actionOverrides?.[methodKey] ?? methodToAction(methodKey);
111
+ const allowed = await ctx.checkPermission(user.id, resource, action);
112
+ if (!allowed) {
113
+ if (rbacMode() === 'permissive') {
114
+ // Audit-log mode: surface what WOULD be blocked so operators can
115
+ // configure policies before flipping to strict. Stays a single
116
+ // console.warn — no DB writes on the hot path.
117
+ console.warn(`[permissionGate] WOULD DENY user=${user.id} ${c.req.method} ${c.req.path} → ${resource}:${action} (EXTENSION_RBAC=permissive — gate bypassed)`);
118
+ await next();
119
+ return;
120
+ }
121
+ return refuse(ctx, c, resource, action);
122
+ }
123
+ await next();
124
+ };
125
+ }
@@ -0,0 +1,10 @@
1
+ /**
2
+ * First path segments the engine and the App own: no extension may mint a public
3
+ * URL under them (a site page slug, a base path). `content/pages` refuses a slug
4
+ * that starts with one; any extension that mints public URLs reads this list.
5
+ * Root files (`robots.txt`, `sitemap.xml`, `favicon.*`) are reserved too.
6
+ */
7
+ export declare const RESERVED_PATH_SEGMENTS: readonly string[];
8
+ /** Whether `path` (`/admin/x`, `admin`, `favicon.ico`) starts with a reserved segment. */
9
+ export declare function isReservedPath(path: string): boolean;
10
+ //# sourceMappingURL=reserved-paths.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reserved-paths.d.ts","sourceRoot":"","sources":["../../src/extension/reserved-paths.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,EAAE,SAAS,MAAM,EAWlD,CAAC;AAEH,0FAA0F;AAC1F,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGpD"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * First path segments the engine and the App own: no extension may mint a public
3
+ * URL under them (a site page slug, a base path). `content/pages` refuses a slug
4
+ * that starts with one; any extension that mints public URLs reads this list.
5
+ * Root files (`robots.txt`, `sitemap.xml`, `favicon.*`) are reserved too.
6
+ */
7
+ export const RESERVED_PATH_SEGMENTS = Object.freeze([
8
+ 'api',
9
+ 'ext',
10
+ 'admin',
11
+ 'app',
12
+ 'auth',
13
+ '_app',
14
+ '_server',
15
+ '.well-known',
16
+ 'robots.txt',
17
+ 'sitemap.xml',
18
+ ]);
19
+ /** Whether `path` (`/admin/x`, `admin`, `favicon.ico`) starts with a reserved segment. */
20
+ export function isReservedPath(path) {
21
+ const first = path.replace(/^\/+/, '').split('/')[0]?.toLowerCase() ?? '';
22
+ return RESERVED_PATH_SEGMENTS.includes(first) || first.startsWith('favicon.');
23
+ }
package/dist/index.d.ts CHANGED
@@ -1,9 +1,11 @@
1
1
  export { ZveltioClient, createZveltioClient } from './client.js';
2
- export type { ZveltioClientConfig, ListParams, ListResult } from './client.js';
2
+ export type { ApiKeySelf, MemberApiKey, MemberApiKeyInput, ZveltioClientConfig, ListParams, ListResult, } from './client.js';
3
+ export { ZveltioApiError, PROBLEM_CONTENT_TYPE } from './errors.js';
4
+ export type { ProblemDetails } from './errors.js';
3
5
  export { ZveltioRealtime } from './realtime.js';
4
6
  export { LocalStore } from './local-store.js';
5
7
  export { SyncManager } from './sync-manager.js';
6
- export type { ZveltioExtension } from './extension/index.js';
8
+ export type { ZveltioExtension, ExtensionContext, FieldTypeRegistryAPI, StudioExtensionAPI, StudioRoute, StudioFieldType, AssetPreviewHandler, } from './extension/index.js';
7
9
  export type { LocalRecord, SyncQueueItem } from './local-store.js';
8
10
  export type { SyncManagerConfig } from './sync-manager.js';
9
11
  export { useSyncCollection, useSyncStatus } from './svelte.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACjE,YAAY,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAC/E,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/D,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAG1B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AACjE,YAAY,EACV,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,mBAAmB,EACnB,UAAU,EACV,UAAU,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACpE,YAAY,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,EACpB,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,mBAAmB,GACpB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACnE,YAAY,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC/D,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAG1B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACjE,YAAY,EAAE,gBAAgB,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { ZveltioClient, createZveltioClient } from './client.js';
2
+ export { ZveltioApiError, PROBLEM_CONTENT_TYPE } from './errors.js';
2
3
  export { ZveltioRealtime } from './realtime.js';
3
4
  export { LocalStore } from './local-store.js';
4
5
  export { SyncManager } from './sync-manager.js';
@@ -51,6 +51,19 @@ export declare class LocalStore {
51
51
  markFailed(queueItemId: string, error: string): Promise<void>;
52
52
  /** Apply data from server (via WebSocket or pull) */
53
53
  applyServerUpdate(collection: string, id: string, data: Record<string, any>, serverVersion: number): Promise<void>;
54
+ /**
55
+ * The server deleted a record: drop the local copy WITHOUT queueing a delete.
56
+ * `delete()` would queue one, echoing the server's own deletion back at it.
57
+ */
58
+ applyServerDelete(collection: string, id: string): Promise<void>;
59
+ /**
60
+ * Drop every copy the server confirmed, keeping local edits not yet pushed
61
+ * (`pending`) and unresolved `conflict`s. For a pull that restarts a
62
+ * collection from nothing: a synced row it does not send again is gone.
63
+ */
64
+ dropSynced(collection: string): Promise<void>;
65
+ getMeta<T>(key: string): Promise<T | undefined>;
66
+ setMeta(key: string, value: unknown): Promise<void>;
54
67
  /** Get records with conflicts for UI resolution */
55
68
  getConflicts(collection?: string): Promise<LocalRecord[]>;
56
69
  /** Resolve a conflict (user decides which version wins) */
@@ -61,7 +74,7 @@ export declare class LocalStore {
61
74
  getPendingBlobs(): Promise<OfflineBlob[]>;
62
75
  /** Delete an offline blob after successful upload */
63
76
  deleteBlob(id: string): Promise<void>;
64
- /** Clear all local data */
77
+ /** Clear all local data; a closed store is opened for it and closed again. */
65
78
  clear(): Promise<void>;
66
79
  close(): Promise<void>;
67
80
  }
@@ -1 +1 @@
1
- {"version":3,"file":"local-store.d.ts","sourceRoot":"","sources":["../src/local-store.ts"],"names":[],"mappings":"AACA,OAAO,EAAoD,KAAK,WAAW,EAAE,MAAM,WAAW,CAAC;AAG/F,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;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C,IAAI,CAAC;IAmEhB;;;OAGG;IACG,iBAAiB,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAKtE;;;;OAIG;IACG,UAAU,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAS7C,OAAO,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC;IAK/C,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAKzD,mDAAmD;IAC7C,YAAY,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAW/D,2DAA2D;IACrD,eAAe,CACnB,UAAU,EAAE,MAAM,EAClB,EAAE,EAAE,MAAM,EAEV,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IA4BhB,wEAAwE;IAClE,QAAQ,CAAC,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAehG,wCAAwC;IAClC,eAAe,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAK/C,qDAAqD;IAC/C,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK3C,8EAA8E;IACxE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAatB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B"}
@@ -46,6 +46,7 @@ export class LocalStore {
46
46
  await this.db.put('meta', { key: 'crdt_lamport', value: this.clock.current });
47
47
  }
48
48
  /** Write a local record and add to sync queue */
49
+ // biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
49
50
  async put(collection, id, data) {
50
51
  if (!this.db)
51
52
  throw new Error('LocalStore not opened');
@@ -134,9 +135,7 @@ export class LocalStore {
134
135
  // Remove from queue
135
136
  await tx.objectStore('sync_queue').delete(queueItemId);
136
137
  // Update record status
137
- const record = (await tx
138
- .objectStore('records')
139
- .get([collection, recordId]));
138
+ const record = (await tx.objectStore('records').get([collection, recordId]));
140
139
  if (record) {
141
140
  record._serverVersion = serverVersion;
142
141
  record._syncStatus = 'synced';
@@ -157,14 +156,33 @@ export class LocalStore {
157
156
  }
158
157
  }
159
158
  /** Apply data from server (via WebSocket or pull) */
160
- async applyServerUpdate(collection, id, data, serverVersion) {
159
+ async applyServerUpdate(collection, id,
160
+ // biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
161
+ data, serverVersion) {
161
162
  if (!this.db)
162
163
  throw new Error('LocalStore not opened');
163
164
  const existing = (await this.db.get('records', [collection, id]));
164
- // Conflict detection: local has changes not yet confirmed by server
165
- if (existing && existing._localVersion > existing._serverVersion) {
165
+ // Conflict detection: local has changes not yet confirmed by server.
166
+ //
167
+ // `_syncStatus` is the signal that survives contact with the SyncManager.
168
+ // The version comparison alone does not: `syncNow()` and `pull()` both pass
169
+ // `Date.now()` as the server version, because the collections API returns no
170
+ // version column — so after the first ACK `_serverVersion` is an epoch
171
+ // millisecond count while `_localVersion` is still a small counter, and
172
+ // `2 > 1790144009198` is false forever. Every local edit made after that
173
+ // first sync was overwritten in silence: status `synced`, no `_conflictData`,
174
+ // nothing in `getConflicts()`. The unit tests missed it because they hand
175
+ // this method versions on the same scale as the counter (1, 2, 3, 5).
176
+ //
177
+ // The version comparison is kept as a second signal: it still catches the
178
+ // race where an ACK for an earlier operation marks the record synced while a
179
+ // later one is queued.
180
+ if (existing &&
181
+ (existing._syncStatus !== 'synced' || existing._localVersion > existing._serverVersion)) {
166
182
  // CRDT field-level merge if both sides have CRDT docs
183
+ // biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
167
184
  if (existing._crdtDoc && data.__crdt) {
185
+ // biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
168
186
  const remoteCrdtDoc = data.__crdt;
169
187
  const merged = mergeLWW(existing._crdtDoc, remoteCrdtDoc);
170
188
  const mergedData = fromDocument(merged);
@@ -194,9 +212,47 @@ export class LocalStore {
194
212
  _serverVersion: serverVersion,
195
213
  _syncStatus: 'synced',
196
214
  _updatedAt: Date.now(),
215
+ // Carried over: rebuilding the record from scratch dropped the CRDT
216
+ // document, so the next merge had nothing on the local side to merge with
217
+ // and fell through to the manual-conflict branch.
218
+ ...(existing?._crdtDoc ? { _crdtDoc: existing._crdtDoc } : {}),
197
219
  };
198
220
  await this.db.put('records', record);
199
221
  }
222
+ /**
223
+ * The server deleted a record: drop the local copy WITHOUT queueing a delete.
224
+ * `delete()` would queue one, echoing the server's own deletion back at it.
225
+ */
226
+ async applyServerDelete(collection, id) {
227
+ if (!this.db)
228
+ throw new Error('LocalStore not opened');
229
+ await this.db.delete('records', [collection, id]);
230
+ }
231
+ /**
232
+ * Drop every copy the server confirmed, keeping local edits not yet pushed
233
+ * (`pending`) and unresolved `conflict`s. For a pull that restarts a
234
+ * collection from nothing: a synced row it does not send again is gone.
235
+ */
236
+ async dropSynced(collection) {
237
+ if (!this.db)
238
+ throw new Error('LocalStore not opened');
239
+ const tx = this.db.transaction('records', 'readwrite');
240
+ for (const r of (await tx.store.index('by-collection').getAll(collection))) {
241
+ if (r._syncStatus === 'synced')
242
+ await tx.store.delete([collection, r.id]);
243
+ }
244
+ await tx.done;
245
+ }
246
+ async getMeta(key) {
247
+ if (!this.db)
248
+ throw new Error('LocalStore not opened');
249
+ return (await this.db.get('meta', key))?.value;
250
+ }
251
+ async setMeta(key, value) {
252
+ if (!this.db)
253
+ throw new Error('LocalStore not opened');
254
+ await this.db.put('meta', { key, value });
255
+ }
200
256
  /** Get records with conflicts for UI resolution */
201
257
  async getConflicts(collection) {
202
258
  if (!this.db)
@@ -207,16 +263,35 @@ export class LocalStore {
207
263
  return all;
208
264
  }
209
265
  /** Resolve a conflict (user decides which version wins) */
210
- async resolveConflict(collection, id, resolvedData) {
266
+ async resolveConflict(collection, id,
267
+ // biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
268
+ resolvedData) {
211
269
  if (!this.db)
212
270
  throw new Error('LocalStore not opened');
213
271
  const record = (await this.db.get('records', [collection, id]));
214
- if (record) {
215
- record.data = resolvedData;
216
- record._syncStatus = 'pending'; // Re-sync with server
217
- record._localVersion += 1;
218
- await this.db.put('records', record);
219
- }
272
+ if (!record)
273
+ return;
274
+ record.data = resolvedData;
275
+ record._syncStatus = 'pending'; // Re-sync with server
276
+ record._localVersion += 1;
277
+ record._conflictData = undefined;
278
+ // Nothing re-synced it. The status said `pending` and the queue held no
279
+ // operation carrying the resolved data, so a resolution — whether a person
280
+ // chose it in the UI or the CRDT merge produced it — stayed on the device.
281
+ // The only operation for this record was the one the server had already
282
+ // rejected.
283
+ const tx = this.db.transaction(['records', 'sync_queue'], 'readwrite');
284
+ await tx.objectStore('records').put(record);
285
+ await tx.objectStore('sync_queue').add({
286
+ id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
287
+ collection,
288
+ recordId: id,
289
+ operation: 'update',
290
+ payload: resolvedData,
291
+ attempts: 0,
292
+ createdAt: Date.now(),
293
+ });
294
+ await tx.done;
220
295
  }
221
296
  /** Save an offline blob — returns a temporary ID 'local_blob_<UUID>' */
222
297
  async saveBlob(blob, collection, recordId, field) {
@@ -246,10 +321,12 @@ export class LocalStore {
246
321
  throw new Error('LocalStore not opened');
247
322
  await this.db.delete('offline_blobs', id);
248
323
  }
249
- /** Clear all local data */
324
+ /** Clear all local data; a closed store is opened for it and closed again. */
250
325
  async clear() {
251
- if (!this.db)
252
- throw new Error('LocalStore not opened');
326
+ if (!this.db) {
327
+ await this.open();
328
+ return this.clear().finally(() => this.close());
329
+ }
253
330
  const tx = this.db.transaction(['records', 'sync_queue', 'meta', 'offline_blobs'], 'readwrite');
254
331
  await tx.objectStore('records').clear();
255
332
  await tx.objectStore('sync_queue').clear();
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Offline-sync provider abstraction.
3
+ *
4
+ * The SDK ships TWO sync strategies for the Postgres ↔ client store
5
+ * loop, picked at construction time:
6
+ *
7
+ * - **`crdt`** (default) — bespoke field-level Last-Write-Wins merge on
8
+ * top of IndexedDB via `LocalStore` + `SyncManager`. Works offline,
9
+ * applies on reconnect, handles conflicts. No external dependency beyond
10
+ * the SDK + engine. Browser only: there is no store for React Native or
11
+ * Node (no SQLite backend).
12
+ *
13
+ * - **`electric`** — Electric 1.x shapes, served THROUGH the engine:
14
+ * `GET {engineUrl}/api/electric/v1/shape?collection=…`. The engine decides
15
+ * the table, rows and columns from the caller's grants, tenant, row rules
16
+ * and column permissions, and proxies Electric's Shape protocol (initial
17
+ * snapshot, then long-poll `live=true`). Read-only: writes go through the
18
+ * data API, and Electric streams them back. Requires the engine's
19
+ * ELECTRIC_URL + ELECTRIC_SECRET; the client never talks to Electric.
20
+ *
21
+ * `subscribe('contacts', cb)` keeps one live shape per collection and calls
22
+ * `cb` with every current row after each change. `pull()` brings each of
23
+ * `tables` up to date once.
24
+ */
25
+ export type OfflineProviderKind = 'crdt' | 'electric';
26
+ export interface OfflineProviderConfig {
27
+ /** Which sync engine to use. Default: 'crdt'. */
28
+ provider?: OfflineProviderKind;
29
+ /** Engine base URL — for CRDT push/pull and the Electric shape endpoint. */
30
+ engineUrl: string;
31
+ /** Collections to replicate. */
32
+ tables?: string[];
33
+ /**
34
+ * Override the `fetch` impl — handy for tests + SSR. Default: globalThis.fetch.
35
+ */
36
+ fetch?: typeof fetch;
37
+ /**
38
+ * Extra request headers for the Electric shape requests — an `X-API-Key` or
39
+ * `X-Tenant-Slug`. A browser session's cookie is sent without this.
40
+ */
41
+ headers?: Record<string, string>;
42
+ }
43
+ /**
44
+ * Public interface every provider implements. The CRDT provider wraps
45
+ * `SyncManager`; the Electric provider follows the engine's shape endpoint. Both
46
+ * expose the same surface.
47
+ */
48
+ export interface OfflineProvider {
49
+ readonly kind: OfflineProviderKind;
50
+ /** Pull remote rows into the local store. Cheap to call repeatedly. */
51
+ pull(): Promise<void>;
52
+ /** Push local mutations to the server. Returns the number of ops sent. */
53
+ push(): Promise<number>;
54
+ /** Subscribe to live changes on a table. Returns an unsubscribe fn. */
55
+ subscribe(table: string, cb: (rows: unknown[]) => void): () => void;
56
+ /** Stop background sync + release resources. */
57
+ close(): Promise<void>;
58
+ }
59
+ export declare class ElectricNotConfigured extends Error {
60
+ constructor(reason: string);
61
+ }
62
+ export declare class ElectricUnavailable extends Error {
63
+ constructor(reason: string);
64
+ }
65
+ /**
66
+ * Build the configured offline-sync provider.
67
+ *
68
+ * For `crdt` (default): returns a thin adapter around `SyncManager`.
69
+ *
70
+ * For `electric`: syncs `tables` once before resolving. Throws
71
+ * `ElectricNotConfigured` when there is no `fetch`, and `ElectricUnavailable`
72
+ * when the engine refuses a shape (401, 403, 409 with its reason, 503).
73
+ */
74
+ export declare function createOfflineProvider(config: OfflineProviderConfig): Promise<OfflineProvider>;
75
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/offline/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,UAAU,CAAC;AAEtD,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,QAAQ,CAAC,EAAE,mBAAmB,CAAC;IAC/B,4EAA4E;IAC5E,SAAS,EAAE,MAAM,CAAC;IAClB,gCAAgC;IAChC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,OAAO,KAAK,CAAC;IACrB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAClC;AAED;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,IAAI,EAAE,mBAAmB,CAAC;IACnC,uEAAuE;IACvE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACtB,0EAA0E;IAC1E,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;IACxB,uEAAuE;IACvE,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACpE,gDAAgD;IAChD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxB;AAED,qBAAa,qBAAsB,SAAQ,KAAK;gBAClC,MAAM,EAAE,MAAM;CAO3B;AAED,qBAAa,mBAAoB,SAAQ,KAAK;gBAChC,MAAM,EAAE,MAAM;CAQ3B;AAED;;;;;;;;GAQG;AACH,wBAAsB,qBAAqB,CACzC,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,eAAe,CAAC,CAQ1B"}