@zveltio/sdk 3.0.0-beta.89 → 3.0.0-beta.91
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/README.md +1 -1
- package/dist/client.d.ts +75 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +78 -15
- package/dist/extension/index.d.ts +39 -2
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/extension/index.js +1 -0
- package/dist/extension/reserved-paths.d.ts +10 -0
- package/dist/extension/reserved-paths.d.ts.map +1 -0
- package/dist/extension/reserved-paths.js +23 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/local-store.d.ts +1 -1
- package/dist/local-store.d.ts.map +1 -1
- package/dist/local-store.js +5 -3
- package/dist/offline/index.d.ts +5 -4
- package/dist/offline/index.d.ts.map +1 -1
- package/dist/offline/index.js +5 -4
- package/dist/sync-manager.d.ts +8 -0
- package/dist/sync-manager.d.ts.map +1 -1
- package/dist/sync-manager.js +14 -1
- package/dist/tests/client.test.js +103 -0
- package/dist/tests/offline-provider-crdt.test.js +4 -2
- package/dist/tests/realtime.test.js +2 -91
- package/dist/tests/reserved-paths.test.d.ts +2 -0
- package/dist/tests/reserved-paths.test.d.ts.map +1 -0
- package/dist/tests/reserved-paths.test.js +21 -0
- package/dist/tests/sync-manager.test.js +58 -0
- package/dist/tests/validate-manifest-actions.test.js +6 -0
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +8 -3
- package/package.json +3 -3
- package/dist/client/Auth.d.ts +0 -19
- package/dist/client/Auth.d.ts.map +0 -1
- package/dist/client/Auth.js +0 -48
- package/dist/client/QueryBuilder.d.ts +0 -17
- package/dist/client/QueryBuilder.d.ts.map +0 -1
- package/dist/client/QueryBuilder.js +0 -89
- package/dist/client/RealtimeClient.d.ts +0 -40
- package/dist/client/RealtimeClient.d.ts.map +0 -1
- package/dist/client/RealtimeClient.js +0 -148
- package/dist/client/ZveltioClient.d.ts +0 -20
- package/dist/client/ZveltioClient.d.ts.map +0 -1
- package/dist/client/ZveltioClient.js +0 -89
package/dist/offline/index.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Offline-sync provider abstraction.
|
|
3
3
|
*
|
|
4
|
-
* The SDK ships TWO sync strategies for the Postgres ↔ client
|
|
4
|
+
* The SDK ships TWO sync strategies for the Postgres ↔ client store
|
|
5
5
|
* loop, picked at construction time:
|
|
6
6
|
*
|
|
7
7
|
* - **`crdt`** (default) — bespoke field-level Last-Write-Wins merge on
|
|
8
|
-
* top of IndexedDB
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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).
|
|
11
12
|
*
|
|
12
13
|
* - **`electric`** — Electric 1.x shapes, served THROUGH the engine:
|
|
13
14
|
* `GET {engineUrl}/api/electric/v1/shape?collection=…`. The engine decides
|
package/dist/sync-manager.d.ts
CHANGED
|
@@ -105,6 +105,14 @@ export declare class SyncManager {
|
|
|
105
105
|
conflicts: number;
|
|
106
106
|
isOnline: boolean;
|
|
107
107
|
}>;
|
|
108
|
+
/**
|
|
109
|
+
* Delete everything the local store holds — records, pending writes, blobs,
|
|
110
|
+
* pull positions — so the next user of this browser neither sees this user's
|
|
111
|
+
* data nor sends this user's queued writes under their own session. Call it
|
|
112
|
+
* after sign-out (a sync started then is refused and stores nothing); call
|
|
113
|
+
* `syncNow()` before sign-out to push what is pending, which is lost otherwise.
|
|
114
|
+
*/
|
|
115
|
+
clearLocalData(): Promise<void>;
|
|
108
116
|
stop(): Promise<void>;
|
|
109
117
|
}
|
|
110
118
|
//# sourceMappingURL=sync-manager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-manager.d.ts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,MAAM,CAAC;YAgBpD,WAAW;IAoCzB,6EAA6E;YAC/D,SAAS;IAsBvB,wDAAwD;IAClD,SAAS,IAAI,OAAO,CAAC;QACzB,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,QAAQ,EAAE,OAAO,CAAC;KACnB,CAAC;IAUF;;;;;;OAMG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAM/B,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAY5B"}
|
package/dist/sync-manager.js
CHANGED
|
@@ -388,7 +388,7 @@ export class SyncManager {
|
|
|
388
388
|
for (const name of collections) {
|
|
389
389
|
for (let page = 1;; page++) {
|
|
390
390
|
const result = await this.client.collection(name).list({ page, limit: pageSize });
|
|
391
|
-
const rows = result?.
|
|
391
|
+
const rows = result?.records ?? [];
|
|
392
392
|
for (const row of rows) {
|
|
393
393
|
const id = row.id;
|
|
394
394
|
if (!id)
|
|
@@ -416,6 +416,19 @@ export class SyncManager {
|
|
|
416
416
|
isOnline: this.isOnline,
|
|
417
417
|
};
|
|
418
418
|
}
|
|
419
|
+
/**
|
|
420
|
+
* Delete everything the local store holds — records, pending writes, blobs,
|
|
421
|
+
* pull positions — so the next user of this browser neither sees this user's
|
|
422
|
+
* data nor sends this user's queued writes under their own session. Call it
|
|
423
|
+
* after sign-out (a sync started then is refused and stores nothing); call
|
|
424
|
+
* `syncNow()` before sign-out to push what is pending, which is lost otherwise.
|
|
425
|
+
*/
|
|
426
|
+
async clearLocalData() {
|
|
427
|
+
// ponytail: polls the in-flight sync; a stored promise if it ever matters.
|
|
428
|
+
while (this.isSyncing)
|
|
429
|
+
await new Promise((r) => setTimeout(r, 50));
|
|
430
|
+
await this.store.clear();
|
|
431
|
+
}
|
|
419
432
|
async stop() {
|
|
420
433
|
this.stopped = true;
|
|
421
434
|
if (this.syncTimer)
|
|
@@ -33,6 +33,16 @@ describe('ZveltioClient URL building', () => {
|
|
|
33
33
|
await client.auth.apiKey();
|
|
34
34
|
expect(urls).toEqual(['https://engine.test/api/api-keys/self']);
|
|
35
35
|
});
|
|
36
|
+
it("reaches the member's own keys at /api/me/api-keys", async () => {
|
|
37
|
+
const urls = captureUrls();
|
|
38
|
+
const client = createZveltioClient({ baseUrl: 'https://engine.test' });
|
|
39
|
+
await client.auth.apiKeys.list();
|
|
40
|
+
await client.auth.apiKeys.revoke('a/b');
|
|
41
|
+
expect(urls).toEqual([
|
|
42
|
+
'https://engine.test/api/me/api-keys',
|
|
43
|
+
'https://engine.test/api/me/api-keys/a%2Fb',
|
|
44
|
+
]);
|
|
45
|
+
});
|
|
36
46
|
it('encodes the storage folder into the query string', async () => {
|
|
37
47
|
const urls = captureUrls();
|
|
38
48
|
const client = createZveltioClient({ baseUrl: 'https://engine.test' });
|
|
@@ -59,3 +69,96 @@ describe('ZveltioClient URL building', () => {
|
|
|
59
69
|
]);
|
|
60
70
|
});
|
|
61
71
|
});
|
|
72
|
+
describe('ZveltioClient session token (bearer mode)', () => {
|
|
73
|
+
function engine(issue) {
|
|
74
|
+
const sent = [];
|
|
75
|
+
globalThis.fetch = (async (_input, init) => {
|
|
76
|
+
sent.push({
|
|
77
|
+
auth: new Headers(init?.headers).get('Authorization'),
|
|
78
|
+
credentials: init?.credentials,
|
|
79
|
+
});
|
|
80
|
+
const headers = { 'content-type': 'application/json' };
|
|
81
|
+
if (issue)
|
|
82
|
+
headers['set-auth-token'] = issue;
|
|
83
|
+
return new Response('{}', { status: 200, headers });
|
|
84
|
+
});
|
|
85
|
+
return sent;
|
|
86
|
+
}
|
|
87
|
+
it('captures the token at sign-in, sends it as a bearer, and forgets it on logout', async () => {
|
|
88
|
+
const seen = [];
|
|
89
|
+
const sent = engine('tok.sig');
|
|
90
|
+
const client = createZveltioClient({
|
|
91
|
+
baseUrl: 'https://engine.test',
|
|
92
|
+
onSessionToken: (t) => seen.push(t),
|
|
93
|
+
});
|
|
94
|
+
await client.auth.login('a@b.c', 'pw');
|
|
95
|
+
const next = engine(null);
|
|
96
|
+
await client.collection('products').list();
|
|
97
|
+
await client.auth.logout();
|
|
98
|
+
await client.collection('products').list();
|
|
99
|
+
expect(sent[0]).toEqual({ auth: null, credentials: 'omit' });
|
|
100
|
+
expect(next.map((s) => s.auth)).toEqual(['Bearer tok.sig', 'Bearer tok.sig', null]);
|
|
101
|
+
expect(seen).toEqual(['tok.sig', null]);
|
|
102
|
+
expect(client.getSessionToken()).toBeNull();
|
|
103
|
+
});
|
|
104
|
+
it('a browser client keeps cookies and ignores an issued token', async () => {
|
|
105
|
+
const sent = engine('tok.sig');
|
|
106
|
+
const client = createZveltioClient({ baseUrl: 'https://engine.test' });
|
|
107
|
+
await client.auth.login('a@b.c', 'pw');
|
|
108
|
+
await client.collection('products').list();
|
|
109
|
+
expect(sent.map((s) => [s.auth, s.credentials])).toEqual([
|
|
110
|
+
[null, 'include'],
|
|
111
|
+
[null, 'include'],
|
|
112
|
+
]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
describe('ZveltioClient step-up', () => {
|
|
116
|
+
function engine() {
|
|
117
|
+
const sent = [];
|
|
118
|
+
globalThis.fetch = (async (_input, init) => {
|
|
119
|
+
const token = new Headers(init?.headers).get('X-Zveltio-Step-Up');
|
|
120
|
+
sent.push(token);
|
|
121
|
+
if (token === 'su-1')
|
|
122
|
+
return new Response('{"ok":true}', { status: 200 });
|
|
123
|
+
return new Response(JSON.stringify({
|
|
124
|
+
type: 'about:blank',
|
|
125
|
+
title: 'Forbidden',
|
|
126
|
+
status: 403,
|
|
127
|
+
code: 'step_up_required',
|
|
128
|
+
errors: { action: 'config' },
|
|
129
|
+
}), { status: 403, headers: { 'content-type': 'application/problem+json' } });
|
|
130
|
+
});
|
|
131
|
+
return sent;
|
|
132
|
+
}
|
|
133
|
+
it('asks for a step-up on 403 step_up_required and sends once more with the token', async () => {
|
|
134
|
+
const sent = engine();
|
|
135
|
+
const asked = [];
|
|
136
|
+
const client = createZveltioClient({
|
|
137
|
+
baseUrl: 'https://engine.test',
|
|
138
|
+
onStepUpRequired: async (action) => {
|
|
139
|
+
asked.push(action);
|
|
140
|
+
return 'su-1';
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
expect(await client.post('/api/collections', { name: 'x' })).toEqual({
|
|
144
|
+
ok: true,
|
|
145
|
+
});
|
|
146
|
+
expect(asked).toEqual(['config']);
|
|
147
|
+
expect(sent).toEqual([null, 'su-1']);
|
|
148
|
+
});
|
|
149
|
+
it('throws the 403 when the hook gives up, and without a hook', async () => {
|
|
150
|
+
const sent = engine();
|
|
151
|
+
const giveUp = createZveltioClient({
|
|
152
|
+
baseUrl: 'https://engine.test',
|
|
153
|
+
onStepUpRequired: async () => null,
|
|
154
|
+
});
|
|
155
|
+
await expect(giveUp.post('/api/collections', {})).rejects.toMatchObject({
|
|
156
|
+
code: 'step_up_required',
|
|
157
|
+
});
|
|
158
|
+
const plain = createZveltioClient({ baseUrl: 'https://engine.test' });
|
|
159
|
+
await expect(plain.post('/api/collections', {})).rejects.toMatchObject({
|
|
160
|
+
code: 'step_up_required',
|
|
161
|
+
});
|
|
162
|
+
expect(sent).toEqual([null, null]);
|
|
163
|
+
});
|
|
164
|
+
});
|
|
@@ -78,8 +78,10 @@ beforeEach(async () => {
|
|
|
78
78
|
const name = match?.[1] ?? '';
|
|
79
79
|
const page = Number(new URL(url).searchParams.get('page') ?? '1');
|
|
80
80
|
// One page only: page 2 comes back empty, which is how `pull` stops.
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
// The shape `listRecords` sends. This fake answered `{ data, … }`, the shape
|
|
82
|
+
// the SDK's type wrongly declared, so the test agreed with the bug.
|
|
83
|
+
const records = page === 1 ? (served[name] ?? []) : [];
|
|
84
|
+
return json({ records, pagination: { total: records.length, page, limit: 200 } });
|
|
83
85
|
});
|
|
84
86
|
const store = new LocalStore();
|
|
85
87
|
await store.open();
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { describe, it, expect, afterEach, jest, spyOn } from 'bun:test';
|
|
2
2
|
import { rm } from 'node:fs/promises';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
|
-
import { RealtimeClient } from '../client/RealtimeClient.js';
|
|
5
|
-
import { ZveltioClient } from '../client/ZveltioClient.js';
|
|
6
4
|
import { ZveltioRealtime } from '../realtime.js';
|
|
7
5
|
import { watchSchema } from '../schema-watcher.js';
|
|
8
6
|
const RealWebSocket = globalThis.WebSocket;
|
|
@@ -42,8 +40,7 @@ describe('ZveltioRealtime upgrade headers', () => {
|
|
|
42
40
|
rt.disconnect();
|
|
43
41
|
});
|
|
44
42
|
// A browser reads the second argument as subprotocols and throws a
|
|
45
|
-
// SyntaxError on an object
|
|
46
|
-
// on `realtime.connect()`. There the socket opens on the session cookie.
|
|
43
|
+
// SyntaxError on an object. There the socket opens on the session cookie.
|
|
47
44
|
it('opens without headers where the constructor refuses them (a browser)', () => {
|
|
48
45
|
const calls = [];
|
|
49
46
|
globalThis.WebSocket = class {
|
|
@@ -58,12 +55,9 @@ describe('ZveltioRealtime upgrade headers', () => {
|
|
|
58
55
|
close() { }
|
|
59
56
|
send() { }
|
|
60
57
|
};
|
|
61
|
-
const zv = new ZveltioClient({ baseUrl: 'https://engine.test', apiKey: 'zvk_x' });
|
|
62
|
-
zv.realtime.connect();
|
|
63
58
|
const rt = new ZveltioRealtime('https://engine.test', { headers: { 'X-API-Key': 'zvk_x' } });
|
|
64
59
|
rt.connect();
|
|
65
|
-
expect(calls).toEqual([['wss://engine.test/api/ws']
|
|
66
|
-
zv.realtime.disconnect();
|
|
60
|
+
expect(calls).toEqual([['wss://engine.test/api/ws']]);
|
|
67
61
|
rt.disconnect();
|
|
68
62
|
});
|
|
69
63
|
});
|
|
@@ -129,89 +123,6 @@ describe('a socket the engine closed for revoked credentials', () => {
|
|
|
129
123
|
expect(told).toBe(0);
|
|
130
124
|
rt.disconnect();
|
|
131
125
|
});
|
|
132
|
-
it('RealtimeClient stops reconnecting on 4001 and says so', () => {
|
|
133
|
-
jest.useFakeTimers();
|
|
134
|
-
const made = fakeSockets();
|
|
135
|
-
const rt = new RealtimeClient('http://engine.test');
|
|
136
|
-
let told = 0;
|
|
137
|
-
rt.onUnauthorized(() => told++);
|
|
138
|
-
rt.connect();
|
|
139
|
-
closeWith(made[0], 4001);
|
|
140
|
-
jest.advanceTimersByTime(60_000);
|
|
141
|
-
expect(made).toHaveLength(1);
|
|
142
|
-
expect(told).toBe(1);
|
|
143
|
-
rt.disconnect();
|
|
144
|
-
});
|
|
145
|
-
it('RealtimeClient still reconnects on any other close', () => {
|
|
146
|
-
jest.useFakeTimers();
|
|
147
|
-
const made = fakeSockets();
|
|
148
|
-
const rt = new RealtimeClient('http://engine.test');
|
|
149
|
-
rt.connect();
|
|
150
|
-
closeWith(made[0], 1006);
|
|
151
|
-
jest.advanceTimersByTime(1_000);
|
|
152
|
-
expect(made).toHaveLength(2);
|
|
153
|
-
rt.disconnect();
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
describe('RealtimeClient after a revocation and while the engine refuses it', () => {
|
|
157
|
-
afterEach(() => jest.useRealTimers());
|
|
158
|
-
it('after 4001, subscribe() only records; an explicit connect() sends it', () => {
|
|
159
|
-
jest.useFakeTimers();
|
|
160
|
-
const made = fakeSockets();
|
|
161
|
-
const rt = new RealtimeClient('http://engine.test');
|
|
162
|
-
rt.connect();
|
|
163
|
-
closeWith(made[0], 4001);
|
|
164
|
-
// It used to dial again here, be refused with 401 (seen as 1006) and back
|
|
165
|
-
// off forever.
|
|
166
|
-
rt.subscribe('orders', '*', () => { });
|
|
167
|
-
jest.advanceTimersByTime(600_000);
|
|
168
|
-
expect(made).toHaveLength(1);
|
|
169
|
-
rt.connect(); // the app re-authenticated
|
|
170
|
-
expect(made).toHaveLength(2);
|
|
171
|
-
accept(made[1]);
|
|
172
|
-
expect(made[1].sent).toEqual([JSON.stringify({ type: 'subscribe', channel: 'orders:*' })]);
|
|
173
|
-
rt.disconnect();
|
|
174
|
-
});
|
|
175
|
-
it('stops after a bounded number of reconnects', () => {
|
|
176
|
-
jest.useFakeTimers();
|
|
177
|
-
const made = fakeSockets();
|
|
178
|
-
const rt = new RealtimeClient('http://engine.test');
|
|
179
|
-
rt.connect();
|
|
180
|
-
// A refused handshake: no runtime shows the 401, only a 1006/1002 close.
|
|
181
|
-
for (let i = 0; i < 20; i++) {
|
|
182
|
-
closeWith(made[made.length - 1], 1006);
|
|
183
|
-
jest.advanceTimersByTime(30_000);
|
|
184
|
-
}
|
|
185
|
-
expect(made).toHaveLength(11); // the first dial and ten retries
|
|
186
|
-
rt.disconnect();
|
|
187
|
-
});
|
|
188
|
-
it('sends its headers with the upgrade', () => {
|
|
189
|
-
const made = fakeSockets();
|
|
190
|
-
const rt = new RealtimeClient('https://engine.test', { headers: { 'X-API-Key': 'zvk_x' } });
|
|
191
|
-
rt.connect();
|
|
192
|
-
expect(made[0].args).toEqual([
|
|
193
|
-
'wss://engine.test/api/ws',
|
|
194
|
-
{ headers: { 'X-API-Key': 'zvk_x' } },
|
|
195
|
-
]);
|
|
196
|
-
rt.disconnect();
|
|
197
|
-
});
|
|
198
|
-
it('ZveltioClient sends its API key on the socket and reports a 4001 as unauthorized', () => {
|
|
199
|
-
const made = fakeSockets();
|
|
200
|
-
let told = 0;
|
|
201
|
-
const client = new ZveltioClient({
|
|
202
|
-
baseUrl: 'https://engine.test',
|
|
203
|
-
apiKey: 'zvk_y',
|
|
204
|
-
onUnauthorized: () => told++,
|
|
205
|
-
});
|
|
206
|
-
client.realtime.connect();
|
|
207
|
-
expect(made[0].args).toEqual([
|
|
208
|
-
'wss://engine.test/api/ws',
|
|
209
|
-
{ headers: { 'X-API-Key': 'zvk_y' } },
|
|
210
|
-
]);
|
|
211
|
-
closeWith(made[0], 4001);
|
|
212
|
-
expect(told).toBe(1);
|
|
213
|
-
client.realtime.disconnect();
|
|
214
|
-
});
|
|
215
126
|
});
|
|
216
127
|
describe('watchSchema', () => {
|
|
217
128
|
// It dialled the socket with no credentials, so the engine refused every
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reserved-paths.test.d.ts","sourceRoot":"","sources":["../../src/tests/reserved-paths.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
import { isReservedPath } from '../extension/index.js';
|
|
3
|
+
describe('isReservedPath', () => {
|
|
4
|
+
it('refuses a path whose first segment the engine or the App owns', () => {
|
|
5
|
+
for (const p of [
|
|
6
|
+
'admin',
|
|
7
|
+
'/admin',
|
|
8
|
+
'app/crm',
|
|
9
|
+
'/API/x',
|
|
10
|
+
'auth',
|
|
11
|
+
'.well-known/x',
|
|
12
|
+
'favicon.ico',
|
|
13
|
+
'robots.txt',
|
|
14
|
+
])
|
|
15
|
+
expect(isReservedPath(p)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
it('accepts a path that only starts with the same letters', () => {
|
|
18
|
+
for (const p of ['apps', 'about', 'administrator', 'blog/admin', '', '/'])
|
|
19
|
+
expect(isReservedPath(p)).toBe(false);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import './setup';
|
|
2
2
|
import { describe, it, expect, afterEach } from 'bun:test';
|
|
3
3
|
import { SyncManager } from '../sync-manager.js';
|
|
4
|
+
import { LocalStore } from '../local-store.js';
|
|
4
5
|
/**
|
|
5
6
|
* A client whose `get` answers the server's copy of a record — the only call the
|
|
6
7
|
* realtime handler makes.
|
|
@@ -63,3 +64,60 @@ describe('SyncManager — stop() before start() settles', () => {
|
|
|
63
64
|
expect(sync.syncTimer).toBeNull();
|
|
64
65
|
});
|
|
65
66
|
});
|
|
67
|
+
describe('SyncManager — clearLocalData', () => {
|
|
68
|
+
// The next user of the browser must neither see this user's records nor send
|
|
69
|
+
// this user's queued writes under their own session.
|
|
70
|
+
it('drops records and pending writes, open or not', async () => {
|
|
71
|
+
sync = new SyncManager(fakeClient(), { syncInterval: 60_000 });
|
|
72
|
+
await sync.start();
|
|
73
|
+
const store = sync.store;
|
|
74
|
+
await sync.collection('posts').create({ title: 'mine' });
|
|
75
|
+
expect(await store.getPendingOps()).not.toEqual([]);
|
|
76
|
+
await sync.clearLocalData();
|
|
77
|
+
expect(await store.list('posts')).toEqual([]);
|
|
78
|
+
expect(await store.getPendingOps()).toEqual([]);
|
|
79
|
+
});
|
|
80
|
+
it('clears a store this manager never opened', async () => {
|
|
81
|
+
const other = new LocalStore();
|
|
82
|
+
await other.open();
|
|
83
|
+
await other.put('posts', 'p9', { title: 'left behind' });
|
|
84
|
+
await other.close();
|
|
85
|
+
sync = new SyncManager(fakeClient(), { syncInterval: 60_000 });
|
|
86
|
+
await sync.clearLocalData();
|
|
87
|
+
await other.open();
|
|
88
|
+
expect(await other.list('posts')).toEqual([]);
|
|
89
|
+
expect(await other.getPendingOps()).toEqual([]);
|
|
90
|
+
await other.close();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('SyncManager — paged pull reads the list the engine sends', () => {
|
|
94
|
+
// A client the sync routes refuse (an API key, 403) pages `list()` instead.
|
|
95
|
+
// That path read `result.data`, which `GET /api/data/:collection` has never
|
|
96
|
+
// sent — it answers `{ records, pagination }` — so it applied nothing.
|
|
97
|
+
it('applies the records of each page', async () => {
|
|
98
|
+
const realFetch = globalThis.fetch;
|
|
99
|
+
globalThis.fetch = (async (input) => {
|
|
100
|
+
const url = String(input instanceof Request ? input.url : input);
|
|
101
|
+
if (url.endsWith('/api/sync/pull')) {
|
|
102
|
+
return Response.json({ status: 403, title: 'Forbidden' }, { status: 403 });
|
|
103
|
+
}
|
|
104
|
+
const page = Number(new URL(url).searchParams.get('page'));
|
|
105
|
+
const records = page === 1 ? [{ id: 'p1' }, { id: 'p2' }] : [{ id: 'p3' }];
|
|
106
|
+
return Response.json({ records, pagination: { total: 3, page, limit: 2, pages: 2 } });
|
|
107
|
+
});
|
|
108
|
+
try {
|
|
109
|
+
const { ZveltioClient } = await import('../client.js');
|
|
110
|
+
sync = new SyncManager(new ZveltioClient({ baseUrl: 'http://engine.test' }), {
|
|
111
|
+
syncInterval: 60_000,
|
|
112
|
+
});
|
|
113
|
+
await sync.start();
|
|
114
|
+
const store = sync.store;
|
|
115
|
+
await store.clear();
|
|
116
|
+
expect(await sync.pull(['posts'], 2)).toBe(3);
|
|
117
|
+
expect((await store.list('posts')).map((r) => r.id).sort()).toEqual(['p1', 'p2', 'p3']);
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
globalThis.fetch = realFetch;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
});
|
|
@@ -37,4 +37,10 @@ describe('manifest actions and jobs', () => {
|
|
|
37
37
|
expect(errors({ jobs: [{ ...job, retry: { limit: 11 } }] })).toHaveLength(1);
|
|
38
38
|
expect(errors({ jobs: [{ ...job, retry: { backoff: 'yes' } }] })).toHaveLength(1);
|
|
39
39
|
});
|
|
40
|
+
it('accepts an action gated on a collection the actions or jobs read or write', () => {
|
|
41
|
+
const gated = { ...action, permission: { resource: 'leads' } };
|
|
42
|
+
expect(errors({ actions: [{ ...gated, writes: ['leads'] }], jobs: [job] })).toEqual([]);
|
|
43
|
+
expect(errors({ actions: [gated], jobs: [{ ...job, reads: ['leads'] }] })).toEqual([]);
|
|
44
|
+
expect(errors({ actions: [gated], jobs: [job] })).toHaveLength(1);
|
|
45
|
+
});
|
|
40
46
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/validate/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAK/D,MAAM,WAAW,eAAe;IAC9B,oEAAoE;IACpE,IAAI,EAAE,MAAM,CAAC;IACb,+BAA+B;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,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AS,MAAM,EAW5C,CAAC;AAwHF,MAAM,WAAW,mBAAmB;IAClC,2DAA2D;IAC3D,MAAM,EAAE,OAAO,CAAC;IAChB,uDAAuD;IACvD,OAAO,EAAE,MAAM,CAAC;IAChB;;;+CAG2C;IAC3C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;gDAE4C;IAC5C,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB;;mEAE+D;IAC/D,WAAW,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC/B,uBAAuB;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,mBAAmB,GAAG,eAAe,EAAE,CAuFhF;AAsBD;;;;;;;;;;eAUe;AACf,wBAAgB,mBAAmB,CAAC,iBAAiB,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAoBzE;AAID,MAAM,WAAW,sBAAsB;IACrC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,QAAQ,EAAE,uBAAuB,CAAC;IAClC,UAAU,EAAE,yBAAyB,CAAC;IACtC,YAAY,EAAE,iBAAiB,CAAC;IAChC,UAAU,CAAC,EAAE,eAAe,CAAC;IAC7B,qEAAqE;IACrE,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;CAC/C;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,sBAAsB,GAAG,gBAAgB,CAkBjF"}
|
package/dist/validate/index.js
CHANGED
|
@@ -171,10 +171,15 @@ export function validateManifest(input) {
|
|
|
171
171
|
};
|
|
172
172
|
const jobs = entries('jobs', 'MANIFEST_BAD_JOB');
|
|
173
173
|
const resources = Array.isArray(obj.resources) ? obj.resources : [];
|
|
174
|
-
|
|
174
|
+
const actions = entries('actions', 'MANIFEST_BAD_ACTION');
|
|
175
|
+
// A collection the actions or jobs read or write may gate an action too (extension model v3).
|
|
176
|
+
const collections = [...actions, ...jobs].flatMap((e) => ['reads', 'writes'].flatMap((k) => (Array.isArray(e[k]) ? e[k] : [])));
|
|
177
|
+
for (const a of actions) {
|
|
175
178
|
const p = a.permission;
|
|
176
|
-
if (!isObject(p) ||
|
|
177
|
-
|
|
179
|
+
if (!isObject(p) ||
|
|
180
|
+
typeof p.resource !== 'string' ||
|
|
181
|
+
!(resources.includes(p.resource) || collections.includes(p.resource))) {
|
|
182
|
+
out.push(err('MANIFEST_BAD_ACTION', `action "${a.name}": "permission.resource" must be in resources or a collection the actions or jobs read or write`));
|
|
178
183
|
}
|
|
179
184
|
else if (p.action !== undefined && (typeof p.action !== 'string' || !p.action)) {
|
|
180
185
|
out.push(err('MANIFEST_BAD_ACTION', `action "${a.name}": "permission.action" must be a name`));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zveltio/sdk",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.91",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -68,9 +68,9 @@
|
|
|
68
68
|
"@types/pg": "^8.23.1",
|
|
69
69
|
"fake-indexeddb": "^6.2.5",
|
|
70
70
|
"hono": "^4.13.8",
|
|
71
|
-
"kysely": "^0.29.
|
|
71
|
+
"kysely": "^0.29.7",
|
|
72
72
|
"pg": "^8.23.1",
|
|
73
|
-
"typescript": "^
|
|
73
|
+
"typescript": "^6.0.3"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
76
76
|
"@testcontainers/postgresql": "^11.0.0",
|
package/dist/client/Auth.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { ZveltioConfig } from '../types/index.js';
|
|
2
|
-
export declare class Auth {
|
|
3
|
-
private config;
|
|
4
|
-
constructor(config: ZveltioConfig);
|
|
5
|
-
signIn(email: string, password: string): Promise<{
|
|
6
|
-
user: any;
|
|
7
|
-
session: any;
|
|
8
|
-
}>;
|
|
9
|
-
signUp(name: string, email: string, password: string): Promise<{
|
|
10
|
-
user: any;
|
|
11
|
-
}>;
|
|
12
|
-
signOut(): Promise<void>;
|
|
13
|
-
getSession(): Promise<{
|
|
14
|
-
user: any;
|
|
15
|
-
session: any;
|
|
16
|
-
} | null>;
|
|
17
|
-
signInWithOAuth(provider: 'google' | 'github' | 'microsoft'): void;
|
|
18
|
-
}
|
|
19
|
-
//# sourceMappingURL=Auth.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Auth.d.ts","sourceRoot":"","sources":["../../src/client/Auth.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEvD,qBAAa,IAAI;IACf,OAAO,CAAC,MAAM,CAAgB;gBAElB,MAAM,EAAE,aAAa;IAK3B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IAY7E,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,CAAA;KAAE,CAAC;IAW7E,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQxB,UAAU,IAAI,OAAO,CAAC;QAAE,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,GAAG,IAAI,CAAC;IAQ/D,eAAe,CAAC,QAAQ,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,GAAG,IAAI;CAGnE"}
|
package/dist/client/Auth.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
export class Auth {
|
|
2
|
-
config;
|
|
3
|
-
constructor(config) {
|
|
4
|
-
this.config = config;
|
|
5
|
-
}
|
|
6
|
-
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
7
|
-
async signIn(email, password) {
|
|
8
|
-
const res = await fetch(`${this.config.baseUrl}/api/auth/sign-in/email`, {
|
|
9
|
-
method: 'POST',
|
|
10
|
-
credentials: 'include',
|
|
11
|
-
headers: { 'Content-Type': 'application/json' },
|
|
12
|
-
body: JSON.stringify({ email, password }),
|
|
13
|
-
});
|
|
14
|
-
if (!res.ok)
|
|
15
|
-
throw new Error((await res.json()).message || 'Sign in failed');
|
|
16
|
-
return res.json();
|
|
17
|
-
}
|
|
18
|
-
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
19
|
-
async signUp(name, email, password) {
|
|
20
|
-
const res = await fetch(`${this.config.baseUrl}/api/auth/sign-up/email`, {
|
|
21
|
-
method: 'POST',
|
|
22
|
-
credentials: 'include',
|
|
23
|
-
headers: { 'Content-Type': 'application/json' },
|
|
24
|
-
body: JSON.stringify({ name, email, password }),
|
|
25
|
-
});
|
|
26
|
-
if (!res.ok)
|
|
27
|
-
throw new Error((await res.json()).message || 'Sign up failed');
|
|
28
|
-
return res.json();
|
|
29
|
-
}
|
|
30
|
-
async signOut() {
|
|
31
|
-
await fetch(`${this.config.baseUrl}/api/auth/sign-out`, {
|
|
32
|
-
method: 'POST',
|
|
33
|
-
credentials: 'include',
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
// biome-ignore lint/suspicious/noExplicitAny: legacy any; tracked in hardening plan item H-01
|
|
37
|
-
async getSession() {
|
|
38
|
-
const res = await fetch(`${this.config.baseUrl}/api/me`, { credentials: 'include' });
|
|
39
|
-
if (!res.ok)
|
|
40
|
-
return null;
|
|
41
|
-
const data = await res.json();
|
|
42
|
-
return { user: data.user, session: {} };
|
|
43
|
-
}
|
|
44
|
-
// OAuth redirect
|
|
45
|
-
signInWithOAuth(provider) {
|
|
46
|
-
window.location.href = `${this.config.baseUrl}/api/auth/sign-in/${provider}`;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { ZveltioConfig, QueryOptions, QueryResponse } from '../types/index.js';
|
|
2
|
-
export declare class QueryBuilder {
|
|
3
|
-
private _collection;
|
|
4
|
-
private _config;
|
|
5
|
-
private _filters;
|
|
6
|
-
private _options;
|
|
7
|
-
constructor(collection: string, config: ZveltioConfig);
|
|
8
|
-
where(field: string, value: any): this;
|
|
9
|
-
where(field: string, op: string, value: any): this;
|
|
10
|
-
page(n: number): this;
|
|
11
|
-
limit(n: number): this;
|
|
12
|
-
sortBy(field: string, order?: 'asc' | 'desc'): this;
|
|
13
|
-
search(q: string): this;
|
|
14
|
-
query<T = any>(overrideOptions?: QueryOptions): Promise<QueryResponse<T>>;
|
|
15
|
-
[Symbol.asyncIterator]<T = any>(): AsyncGenerator<T[]>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=QueryBuilder.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryBuilder.d.ts","sourceRoot":"","sources":["../../src/client/QueryBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEpF,qBAAa,YAAY;IACvB,OAAO,CAAC,WAAW,CAAS;IAC5B,OAAO,CAAC,OAAO,CAAgB;IAE/B,OAAO,CAAC,QAAQ,CAA2B;IAC3C,OAAO,CAAC,QAAQ,CAAoB;gBAExB,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,aAAa;IAOrD,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAEtC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAYlD,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAIrB,KAAK,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAMtB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAE,KAAK,GAAG,MAAc,GAAG,IAAI;IAO1D,MAAM,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI;IAOjB,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,eAAe,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAkCxE,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,GAAG,GAAG,KAAK,cAAc,CAAC,CAAC,EAAE,CAAC;CAY9D"}
|