@zveltio/sdk 3.0.0-beta.90 → 3.0.0-beta.92
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 +12 -2
- package/dist/extension/index.d.ts.map +1 -1
- package/dist/extension/index.js +7 -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 +15 -0
- package/dist/tests/validate-sdui-data-endpoints.test.d.ts +2 -0
- package/dist/tests/validate-sdui-data-endpoints.test.d.ts.map +1 -0
- package/dist/tests/validate-sdui-data-endpoints.test.js +41 -0
- package/dist/validate/index.d.ts +4 -0
- package/dist/validate/index.d.ts.map +1 -1
- package/dist/validate/index.js +28 -4
- 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/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","sourceRoot":"","sources":["../src/sync-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAUjD,MAAM,MAAM,sBAAsB,GAAG,KAAK,GAAG,QAAQ,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oDAAoD;IAEpD,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAC9C,mHAAmH;IACnH,kBAAk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;IAY3D,KAAK,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IA+BhD;;;;;OAKG;IACH,UAAU,CAAC,IAAI,EAAE,MAAM;QAEnB,2CAA2C;;;;;QAU3C,6CAA6C;kBAC7B,MAAM;;;;QAUtB,0CAA0C;uBAErB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;QAYxC,0CAA0C;qBAEvB,MAAM,QAAQ,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;;;QAapD,+CAA+C;qBAC5B,MAAM;QAMzB,qDAAqD;8BAE/B,CAAC,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI;QA8C9C,8CAA8C;;QAK9C,kCAAkC;8BAEN,MAAM,gBAAgB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC;;IAQzE,oCAAoC;IAC9B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;YAwGhB,eAAe;IAmB7B;;;;;;;;OAQG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAI3B;;;;;;;;;;;;;;;;;;OAkBG;IACG,IAAI,CAAC,WAAW,EAAE,MAAM,EAAE,EAAE,QAAQ,SAAM,GAAG,OAAO,CAAC,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,19 @@ 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
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('manifest collections', () => {
|
|
48
|
+
const bad = (collections) => validateManifest({ manifest: { ...base, collections } }).filter((e) => e.code === 'MANIFEST_BAD_COLLECTIONS');
|
|
49
|
+
it('takes collection names, once each', () => {
|
|
50
|
+
expect(bad(['tasks', 'task_lists'])).toEqual([]);
|
|
51
|
+
expect(bad('tasks')).toHaveLength(1);
|
|
52
|
+
expect(bad(['Tasks'])).toHaveLength(1);
|
|
53
|
+
expect(bad(['tasks', 'tasks'])).toHaveLength(1);
|
|
54
|
+
});
|
|
40
55
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-sdui-data-endpoints.test.d.ts","sourceRoot":"","sources":["../../src/tests/validate-sdui-data-endpoints.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// A declarative page may name the data API of a collection its extension declares
|
|
2
|
+
// (ADR 0012), and of no other; every other core endpoint stays foreign.
|
|
3
|
+
import { describe, expect, it } from 'bun:test';
|
|
4
|
+
import { validateSduiSchema } from '../validate/index.js';
|
|
5
|
+
const foreign = (endpoint, collections) => validateSduiSchema({
|
|
6
|
+
schema: { title: 't', resources: [{ name: 'r', dataSource: endpoint }] },
|
|
7
|
+
extName: 'projects/management',
|
|
8
|
+
collections,
|
|
9
|
+
})
|
|
10
|
+
.filter((e) => e.code === 'SDUI_ENDPOINT_FOREIGN')
|
|
11
|
+
.map((e) => e.message.split('"')[1]);
|
|
12
|
+
describe('SDUI data API endpoints', () => {
|
|
13
|
+
it('allows its own collection and one of its records', () => {
|
|
14
|
+
for (const e of [
|
|
15
|
+
'/api/data/projects',
|
|
16
|
+
'/api/data/projects?limit=5',
|
|
17
|
+
'/api/data/projects/{id}',
|
|
18
|
+
'/api/data/projects/:id',
|
|
19
|
+
'/api/data/tasks/0b9c5c3e-1d2a-4f6b-9a1e-2c3d4e5f6a7b',
|
|
20
|
+
]) {
|
|
21
|
+
expect(foreign(e, ['projects', 'tasks'])).toEqual([]);
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
it('refuses a collection it does not declare, and any data path without a declaration', () => {
|
|
25
|
+
expect(foreign('/api/data/invoices', ['projects'])).toEqual(['/api/data/invoices']);
|
|
26
|
+
expect(foreign('/api/data/projects')).toEqual(['/api/data/projects']);
|
|
27
|
+
});
|
|
28
|
+
it('refuses every other path, a deeper one and a dot segment included', () => {
|
|
29
|
+
for (const e of [
|
|
30
|
+
'/api/users',
|
|
31
|
+
'/api/data',
|
|
32
|
+
'/api/data/projects/{id}/history',
|
|
33
|
+
'/api/data/projects/../users',
|
|
34
|
+
'/api/data/projects/..',
|
|
35
|
+
'/api/collections/projects',
|
|
36
|
+
'/api/data/Projects',
|
|
37
|
+
]) {
|
|
38
|
+
expect(foreign(e, ['projects'])).toEqual([e]);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
});
|
package/dist/validate/index.d.ts
CHANGED
|
@@ -108,6 +108,10 @@ export interface SduiValidationInput {
|
|
|
108
108
|
* A schema may read a dependency's `/ext/<dep>/` routes (relation pickers),
|
|
109
109
|
* which is otherwise treated as foreign. */
|
|
110
110
|
dependencies?: string[];
|
|
111
|
+
/** The collections this extension declares (manifest `collections`, ADR 0012):
|
|
112
|
+
* a schema may name `/api/data/<collection>` and `/api/data/<collection>/<id>`
|
|
113
|
+
* for these, and for no other collection. */
|
|
114
|
+
collections?: string[];
|
|
111
115
|
/** Message keys this schema may resolve against: the extension's own
|
|
112
116
|
* `studio/messages/en.json` keys, unioned with `SHARED_MESSAGE_KEYS`.
|
|
113
117
|
* Omit to skip the i18n checks (endpoint checks still run). */
|
|
@@ -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,MAAM,CAAC;IACd,6EAA6E;IAC7E,QAAQ,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC;AAED,MAAM,WAAW,gBAAgB;IAC/B,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,oDAAoD;IACpD,KAAK,EAAE;QACL,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,MAAM,CAAC;QACnB,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC;CACH;AAmDD,MAAM,WAAW,uBAAuB;IACtC,+DAA+D;IAC/D,QAAQ,EAAE,OAAO,CAAC;IAClB,0EAA0E;IAC1E,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,uBAAuB,GAAG,eAAe,EAAE,
|
|
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,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Q,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
|
@@ -169,12 +169,29 @@ export function validateManifest(input) {
|
|
|
169
169
|
return true;
|
|
170
170
|
});
|
|
171
171
|
};
|
|
172
|
+
// Declared collections (ADR 0012): names; the CLI checks each one's schema file.
|
|
173
|
+
if (obj.collections !== undefined) {
|
|
174
|
+
const names = Array.isArray(obj.collections) ? obj.collections : [];
|
|
175
|
+
const ok = Array.isArray(obj.collections) &&
|
|
176
|
+
names.every((n) => typeof n === 'string' && n.length <= 63 && /^[a-z][a-z0-9_]*$/.test(n));
|
|
177
|
+
if (!ok) {
|
|
178
|
+
out.push(err('MANIFEST_BAD_COLLECTIONS', '"collections" must be an array of collection names'));
|
|
179
|
+
}
|
|
180
|
+
else if (new Set(names).size !== names.length) {
|
|
181
|
+
out.push(err('MANIFEST_BAD_COLLECTIONS', 'a collection is declared twice in "collections"'));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
172
184
|
const jobs = entries('jobs', 'MANIFEST_BAD_JOB');
|
|
173
185
|
const resources = Array.isArray(obj.resources) ? obj.resources : [];
|
|
174
|
-
|
|
186
|
+
const actions = entries('actions', 'MANIFEST_BAD_ACTION');
|
|
187
|
+
// A collection the actions or jobs read or write may gate an action too (extension model v3).
|
|
188
|
+
const collections = [...actions, ...jobs].flatMap((e) => ['reads', 'writes'].flatMap((k) => (Array.isArray(e[k]) ? e[k] : [])));
|
|
189
|
+
for (const a of actions) {
|
|
175
190
|
const p = a.permission;
|
|
176
|
-
if (!isObject(p) ||
|
|
177
|
-
|
|
191
|
+
if (!isObject(p) ||
|
|
192
|
+
typeof p.resource !== 'string' ||
|
|
193
|
+
!(resources.includes(p.resource) || collections.includes(p.resource))) {
|
|
194
|
+
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
195
|
}
|
|
179
196
|
else if (p.action !== undefined && (typeof p.action !== 'string' || !p.action)) {
|
|
180
197
|
out.push(err('MANIFEST_BAD_ACTION', `action "${a.name}": "permission.action" must be a name`));
|
|
@@ -548,6 +565,9 @@ export const SDUI_SHARED_READ_ALLOWLIST = new Set([
|
|
|
548
565
|
'/api/collections',
|
|
549
566
|
'/api/views',
|
|
550
567
|
]);
|
|
568
|
+
/** `/api/data/<collection>` or `/api/data/<collection>/<id>`; the id a token, a
|
|
569
|
+
* param or a plain key, never a dot segment. Group 1 is the collection. */
|
|
570
|
+
const SDUI_DATA_ENDPOINT = /^\/api\/data\/([a-z][a-z0-9_]*)(?:\/(?:\{[^{}/]+\}|:[A-Za-z_]\w*|[A-Za-z0-9_-]+))?$/;
|
|
551
571
|
/** Collapse `{token}` and `:param` path segments so a schema endpoint
|
|
552
572
|
* (`/periods/{id}/generate`) matches an engine route (`/periods/:id/generate`). */
|
|
553
573
|
function normalizeRoute(p) {
|
|
@@ -730,8 +750,12 @@ export function validateSduiSchema(input) {
|
|
|
730
750
|
// A dependency's namespace is allowed (relation pickers etc.).
|
|
731
751
|
if (depMounts.some((m) => inMount(bare, m)))
|
|
732
752
|
continue;
|
|
753
|
+
// Its own collections, through the data API, which authorizes the caller.
|
|
754
|
+
const data = SDUI_DATA_ENDPOINT.exec(bare);
|
|
755
|
+
if (data && (input.collections ?? []).includes(data[1]))
|
|
756
|
+
continue;
|
|
733
757
|
if (!inMount(bare, mount)) {
|
|
734
|
-
out.push(err('SDUI_ENDPOINT_FOREIGN', `endpoint "${raw}" is outside this extension's namespace "${mount}/" (or a declared dependency, or the shared-read allowlist). Schemas may only call their own routes.`, file));
|
|
758
|
+
out.push(err('SDUI_ENDPOINT_FOREIGN', `endpoint "${raw}" is outside this extension's namespace "${mount}/" (or a declared dependency, the data API of a collection it declares, or the shared-read allowlist). Schemas may only call their own routes.`, file));
|
|
735
759
|
continue;
|
|
736
760
|
}
|
|
737
761
|
if (provided) {
|
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.92",
|
|
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"}
|