local-lite 1.0.2 → 1.0.4
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 +4 -3
- package/dist/actions/manager.js +6 -2
- package/dist/actions/store.js +33 -19
- package/dist/adapters/local/expo-sqlite.js +4 -2
- package/dist/adapters/local/libsql.js +3 -1
- package/dist/adapters/local/op-sqlite.js +2 -1
- package/dist/adapters/network/index.js +10 -5
- package/dist/adapters/remote/convex.js +37 -10
- package/dist/adapters/remote/firestore.js +11 -4
- package/dist/adapters/remote/self-hosted.js +8 -4
- package/dist/adapters/remote/supabase.js +95 -29
- package/dist/auth/apple.js +8 -4
- package/dist/auth/github.js +15 -7
- package/dist/auth/google.js +7 -4
- package/dist/auth/identity.js +5 -1
- package/dist/auth/local.js +74 -21
- package/dist/auth/microsoft.js +22 -8
- package/dist/auth/session.js +45 -34
- package/dist/auth/unified.js +3 -2
- package/dist/backups/cloud-storage.js +10 -7
- package/dist/backups/encryption.js +4 -2
- package/dist/backups/onedrive.js +3 -3
- package/dist/backups/operations.js +4 -2
- package/dist/config/index.d.ts +1 -1
- package/dist/config/index.js +3 -0
- package/dist/config/resolve-local.js +18 -6
- package/dist/config/resolve-remote.js +2 -1
- package/dist/core/client.d.ts +2 -2
- package/dist/core/client.js +64 -26
- package/dist/core/index.d.ts +1 -1
- package/dist/core/maintenance.js +5 -4
- package/dist/core/meta-store.js +3 -3
- package/dist/core/outbox-store.js +32 -25
- package/dist/core/query-builder.js +23 -10
- package/dist/core/query.js +19 -7
- package/dist/core/schema-manager.js +6 -2
- package/dist/core/sync-worker.js +38 -12
- package/dist/core/table-manager.js +8 -2
- package/dist/core/types.d.ts +1 -1
- package/dist/devtools/BenchmarkModal.d.ts +1 -1
- package/dist/devtools/BenchmarkModal.js +234 -54
- package/dist/devtools/SyncInspector.js +260 -37
- package/dist/email/index.d.ts +17 -18
- package/dist/email/index.js +46 -72
- package/dist/keys/generator.js +4 -1
- package/dist/keys/manager.js +22 -4
- package/dist/keys/signed-token.js +12 -4
- package/dist/keys/store.js +23 -16
- package/dist/kv/manager.js +5 -2
- package/dist/kv/store.js +13 -13
- package/dist/react/auth.js +12 -12
- package/dist/react/backups.js +1 -1
- package/dist/react/index.js +14 -9
- package/dist/react/runner.js +1 -1
- package/dist/react/status.js +6 -2
- package/dist/reactive/event-emitter.js +2 -2
- package/dist/scheduler/cron.js +3 -1
- package/dist/scheduler/store.js +37 -31
- package/dist/schema/generator.js +37 -34
- package/dist/search/manager.js +3 -1
- package/dist/search/store.js +17 -16
- package/dist/server/email.d.ts +8 -0
- package/dist/server/email.js +48 -3
- package/dist/server/index.js +4 -4
- package/dist/server/sync.js +11 -4
- package/dist/storage/driver.js +2 -1
- package/dist/storage/expo.js +5 -2
- package/dist/storage/manager.js +3 -1
- package/dist/storage/store.js +26 -25
- package/dist/utils/dynamic.js +4 -2
- package/dist/utils/logger.js +13 -6
- package/dist/utils/portability.js +21 -9
- package/package.json +1 -1
package/dist/email/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DevMailbox = void 0;
|
|
4
|
-
exports.loadNodemailer = loadNodemailer;
|
|
5
|
-
exports.resolveTransporter = resolveTransporter;
|
|
6
4
|
exports.renderReactEmail = renderReactEmail;
|
|
7
5
|
exports.hydrateAttachment = hydrateAttachment;
|
|
8
6
|
exports.buildMailOptions = buildMailOptions;
|
|
9
|
-
exports.
|
|
7
|
+
exports.prepareMailOptions = prepareMailOptions;
|
|
10
8
|
exports.createHttpEmailHandler = createHttpEmailHandler;
|
|
11
9
|
exports.createDevEmailHandler = createDevEmailHandler;
|
|
12
10
|
exports.createEmailHandler = createEmailHandler;
|
|
@@ -30,28 +28,6 @@ class DevMailbox {
|
|
|
30
28
|
}
|
|
31
29
|
}
|
|
32
30
|
exports.DevMailbox = DevMailbox;
|
|
33
|
-
/**
|
|
34
|
-
* Dynamically loads the nodemailer module if not already available.
|
|
35
|
-
*/
|
|
36
|
-
async function loadNodemailer() {
|
|
37
|
-
try {
|
|
38
|
-
const mod = await import('nodemailer');
|
|
39
|
-
return mod.default || mod;
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
throw new Error("The 'nodemailer' package is required to send emails via Nodemailer transport. Please install it via 'npm install nodemailer'.");
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Resolves or instantiates a Nodemailer Transporter instance.
|
|
47
|
-
*/
|
|
48
|
-
async function resolveTransporter(input, defaults) {
|
|
49
|
-
if (input && typeof input.sendMail === 'function') {
|
|
50
|
-
return input;
|
|
51
|
-
}
|
|
52
|
-
const nm = await loadNodemailer();
|
|
53
|
-
return nm.createTransport(input, defaults);
|
|
54
|
-
}
|
|
55
31
|
function interpolate(templateStr, data) {
|
|
56
32
|
return templateStr.replace(/\{\{\s*([\w.]+)\s*\}\}/g, (_, key) => {
|
|
57
33
|
const val = data[key];
|
|
@@ -79,7 +55,8 @@ async function renderReactEmail(element) {
|
|
|
79
55
|
// 2. Try react-dom/server
|
|
80
56
|
try {
|
|
81
57
|
const ReactDOMServer = await (0, dynamic_js_1.safeDynamicImport)('react-dom/server');
|
|
82
|
-
const renderToStaticMarkup = ReactDOMServer?.renderToStaticMarkup ||
|
|
58
|
+
const renderToStaticMarkup = ReactDOMServer?.renderToStaticMarkup ||
|
|
59
|
+
ReactDOMServer?.default?.renderToStaticMarkup;
|
|
83
60
|
if (typeof renderToStaticMarkup === 'function') {
|
|
84
61
|
const html = renderToStaticMarkup(component);
|
|
85
62
|
const text = html.replace(/<[^>]*>/g, '').trim();
|
|
@@ -101,7 +78,9 @@ async function hydrateAttachment(att) {
|
|
|
101
78
|
if (att.url) {
|
|
102
79
|
const rawUrl = att.url;
|
|
103
80
|
if (rawUrl.startsWith('file://') ||
|
|
104
|
-
(!rawUrl.startsWith('http://') &&
|
|
81
|
+
(!rawUrl.startsWith('http://') &&
|
|
82
|
+
!rawUrl.startsWith('https://') &&
|
|
83
|
+
!rawUrl.startsWith('data:'))) {
|
|
105
84
|
const filePath = rawUrl.startsWith('file://') ? rawUrl.slice(7) : rawUrl;
|
|
106
85
|
try {
|
|
107
86
|
const fs = await import('node:fs/promises');
|
|
@@ -140,7 +119,9 @@ function buildMailOptions(payload, options = {}) {
|
|
|
140
119
|
mailOptions.replyTo = payload.replyTo;
|
|
141
120
|
if (payload.headers) {
|
|
142
121
|
mailOptions.headers = {
|
|
143
|
-
...(typeof options.defaults?.headers === 'object'
|
|
122
|
+
...(typeof options.defaults?.headers === 'object'
|
|
123
|
+
? options.defaults.headers
|
|
124
|
+
: {}),
|
|
144
125
|
...payload.headers,
|
|
145
126
|
};
|
|
146
127
|
}
|
|
@@ -211,35 +192,6 @@ async function prepareMailOptions(payload, options, record) {
|
|
|
211
192
|
}
|
|
212
193
|
return mailOptions;
|
|
213
194
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Creates an EmailHandler for local-lite ActionManager that sends emails
|
|
216
|
-
* directly via Nodemailer (SMTP, Sendmail, SES, etc.).
|
|
217
|
-
*/
|
|
218
|
-
function createNodemailerHandler(transporterOrOptions, handlerOptions = {}) {
|
|
219
|
-
let cachedTransporter = transporterOrOptions && typeof transporterOrOptions.sendMail === 'function'
|
|
220
|
-
? transporterOrOptions
|
|
221
|
-
: null;
|
|
222
|
-
const getTransporter = async () => {
|
|
223
|
-
if (!cachedTransporter) {
|
|
224
|
-
cachedTransporter = await resolveTransporter(transporterOrOptions, handlerOptions.defaults);
|
|
225
|
-
}
|
|
226
|
-
return cachedTransporter;
|
|
227
|
-
};
|
|
228
|
-
return async (payload, record, _context) => {
|
|
229
|
-
const transporter = await getTransporter();
|
|
230
|
-
const mailOptions = await prepareMailOptions(payload, handlerOptions, record);
|
|
231
|
-
const info = await transporter.sendMail(mailOptions);
|
|
232
|
-
if (handlerOptions.afterSend) {
|
|
233
|
-
await handlerOptions.afterSend(info, payload, record);
|
|
234
|
-
}
|
|
235
|
-
return {
|
|
236
|
-
messageId: info.messageId,
|
|
237
|
-
response: info.response,
|
|
238
|
-
accepted: info.accepted,
|
|
239
|
-
rejected: info.rejected,
|
|
240
|
-
};
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
195
|
/**
|
|
244
196
|
* Creates an EmailHandler for local-lite ActionManager that dispatches emails
|
|
245
197
|
* via HTTP APIs (e.g. Resend, SendGrid, Postmark, or custom webhooks/endpoints).
|
|
@@ -281,17 +233,23 @@ function createHttpEmailHandler(options) {
|
|
|
281
233
|
if (options.apiKey) {
|
|
282
234
|
headers['Authorization'] = `Bearer ${options.apiKey}`;
|
|
283
235
|
}
|
|
284
|
-
const toAddresses = Array.isArray(mailOptions.to)
|
|
236
|
+
const toAddresses = Array.isArray(mailOptions.to)
|
|
237
|
+
? mailOptions.to
|
|
238
|
+
: [mailOptions.to];
|
|
285
239
|
const personalizations = {
|
|
286
|
-
to: toAddresses.map((email) =>
|
|
240
|
+
to: toAddresses.map((email) => typeof email === 'string' ? { email } : email),
|
|
287
241
|
};
|
|
288
242
|
if (mailOptions.cc) {
|
|
289
|
-
const ccAddresses = Array.isArray(mailOptions.cc)
|
|
290
|
-
|
|
243
|
+
const ccAddresses = Array.isArray(mailOptions.cc)
|
|
244
|
+
? mailOptions.cc
|
|
245
|
+
: [mailOptions.cc];
|
|
246
|
+
personalizations.cc = ccAddresses.map((email) => typeof email === 'string' ? { email } : email);
|
|
291
247
|
}
|
|
292
248
|
if (mailOptions.bcc) {
|
|
293
|
-
const bccAddresses = Array.isArray(mailOptions.bcc)
|
|
294
|
-
|
|
249
|
+
const bccAddresses = Array.isArray(mailOptions.bcc)
|
|
250
|
+
? mailOptions.bcc
|
|
251
|
+
: [mailOptions.bcc];
|
|
252
|
+
personalizations.bcc = bccAddresses.map((email) => typeof email === 'string' ? { email } : email);
|
|
295
253
|
}
|
|
296
254
|
const content = [];
|
|
297
255
|
if (mailOptions.text)
|
|
@@ -300,7 +258,9 @@ function createHttpEmailHandler(options) {
|
|
|
300
258
|
content.push({ type: 'text/html', value: String(mailOptions.html) });
|
|
301
259
|
body = {
|
|
302
260
|
personalizations: [personalizations],
|
|
303
|
-
from: typeof mailOptions.from === 'string'
|
|
261
|
+
from: typeof mailOptions.from === 'string'
|
|
262
|
+
? { email: mailOptions.from }
|
|
263
|
+
: mailOptions.from,
|
|
304
264
|
subject: mailOptions.subject,
|
|
305
265
|
content: content.length > 0 ? content : [{ type: 'text/plain', value: '' }],
|
|
306
266
|
};
|
|
@@ -312,12 +272,18 @@ function createHttpEmailHandler(options) {
|
|
|
312
272
|
}
|
|
313
273
|
body = {
|
|
314
274
|
From: mailOptions.from,
|
|
315
|
-
To: Array.isArray(mailOptions.to)
|
|
275
|
+
To: Array.isArray(mailOptions.to)
|
|
276
|
+
? mailOptions.to.join(',')
|
|
277
|
+
: mailOptions.to,
|
|
316
278
|
Subject: mailOptions.subject,
|
|
317
279
|
HtmlBody: mailOptions.html,
|
|
318
280
|
TextBody: mailOptions.text,
|
|
319
|
-
Cc: Array.isArray(mailOptions.cc)
|
|
320
|
-
|
|
281
|
+
Cc: Array.isArray(mailOptions.cc)
|
|
282
|
+
? mailOptions.cc.join(',')
|
|
283
|
+
: mailOptions.cc,
|
|
284
|
+
Bcc: Array.isArray(mailOptions.bcc)
|
|
285
|
+
? mailOptions.bcc.join(',')
|
|
286
|
+
: mailOptions.bcc,
|
|
321
287
|
ReplyTo: mailOptions.replyTo,
|
|
322
288
|
};
|
|
323
289
|
}
|
|
@@ -363,7 +329,9 @@ function createHttpEmailHandler(options) {
|
|
|
363
329
|
const sendResult = {
|
|
364
330
|
messageId,
|
|
365
331
|
response: resultData,
|
|
366
|
-
accepted: Array.isArray(mailOptions.to)
|
|
332
|
+
accepted: Array.isArray(mailOptions.to)
|
|
333
|
+
? mailOptions.to
|
|
334
|
+
: [mailOptions.to],
|
|
367
335
|
};
|
|
368
336
|
if (options.afterSend) {
|
|
369
337
|
await options.afterSend(sendResult, payload, record);
|
|
@@ -387,14 +355,20 @@ function createDevEmailHandler(options = {}) {
|
|
|
387
355
|
};
|
|
388
356
|
DevMailbox.record(sentRecord);
|
|
389
357
|
if (!options.silent) {
|
|
390
|
-
const toStr = Array.isArray(mailOptions.to)
|
|
391
|
-
|
|
358
|
+
const toStr = Array.isArray(mailOptions.to)
|
|
359
|
+
? mailOptions.to.join(', ')
|
|
360
|
+
: mailOptions.to;
|
|
361
|
+
const previewText = (mailOptions.text || mailOptions.html || '')
|
|
362
|
+
.toString()
|
|
363
|
+
.slice(0, 120);
|
|
392
364
|
console.log(`[local-lite:email:dev] Dispatched to: ${toStr} | Subject: "${mailOptions.subject}" | Body: "${previewText}"`);
|
|
393
365
|
}
|
|
394
366
|
const result = {
|
|
395
367
|
messageId: sentRecord.id,
|
|
396
368
|
response: { dev: true, previewUrl: `dev://mailbox/${sentRecord.id}` },
|
|
397
|
-
accepted: Array.isArray(mailOptions.to)
|
|
369
|
+
accepted: Array.isArray(mailOptions.to)
|
|
370
|
+
? mailOptions.to
|
|
371
|
+
: [mailOptions.to],
|
|
398
372
|
};
|
|
399
373
|
if (options.afterSend) {
|
|
400
374
|
await options.afterSend(result, payload, record);
|
|
@@ -412,7 +386,7 @@ function createEmailHandler(config) {
|
|
|
412
386
|
return createDevEmailHandler({ ...config, silent: config.silentDev });
|
|
413
387
|
}
|
|
414
388
|
if (config.transport || config.provider === 'nodemailer') {
|
|
415
|
-
|
|
389
|
+
throw new Error("Nodemailer email delivery is server-only. Import 'local-lite/server' for SMTP delivery.");
|
|
416
390
|
}
|
|
417
391
|
if (config.provider === 'resend' ||
|
|
418
392
|
config.provider === 'sendgrid' ||
|
package/dist/keys/generator.js
CHANGED
|
@@ -86,7 +86,10 @@ function hashApiKey(key) {
|
|
|
86
86
|
* prop_a7F9x2K1m8P0qW4z_c4f910e2
|
|
87
87
|
*/
|
|
88
88
|
function generateApiKey(options = {}) {
|
|
89
|
-
const prefix = (options.prefix || 'key')
|
|
89
|
+
const prefix = (options.prefix || 'key')
|
|
90
|
+
.trim()
|
|
91
|
+
.toLowerCase()
|
|
92
|
+
.replace(/[^a-z0-9_-]/g, '');
|
|
90
93
|
const byteLength = options.byteLength ?? 24;
|
|
91
94
|
const withChecksum = options.withChecksum ?? true;
|
|
92
95
|
const entropyBytes = getRandomBytes(byteLength);
|
package/dist/keys/manager.js
CHANGED
|
@@ -55,11 +55,19 @@ class ApiKeyManager {
|
|
|
55
55
|
*/
|
|
56
56
|
async verify(rawKey, options = {}) {
|
|
57
57
|
if (!rawKey || typeof rawKey !== 'string') {
|
|
58
|
-
return {
|
|
58
|
+
return {
|
|
59
|
+
valid: false,
|
|
60
|
+
status: 'MALFORMED',
|
|
61
|
+
error: 'API key is missing or not a string',
|
|
62
|
+
};
|
|
59
63
|
}
|
|
60
64
|
// 1. Instant syntactic & checksum format verification
|
|
61
65
|
if (!(0, generator_js_1.verifyApiKeyFormat)(rawKey, options.expectedPrefix)) {
|
|
62
|
-
return {
|
|
66
|
+
return {
|
|
67
|
+
valid: false,
|
|
68
|
+
status: 'MALFORMED',
|
|
69
|
+
error: 'Invalid API key format or checksum',
|
|
70
|
+
};
|
|
63
71
|
}
|
|
64
72
|
// 2. Hash and lookup in database
|
|
65
73
|
const computedHash = (0, generator_js_1.hashApiKey)(rawKey);
|
|
@@ -69,11 +77,21 @@ class ApiKeyManager {
|
|
|
69
77
|
}
|
|
70
78
|
// 3. Check revocation
|
|
71
79
|
if (record.revoked) {
|
|
72
|
-
return {
|
|
80
|
+
return {
|
|
81
|
+
valid: false,
|
|
82
|
+
status: 'REVOKED',
|
|
83
|
+
record,
|
|
84
|
+
error: 'API key has been revoked',
|
|
85
|
+
};
|
|
73
86
|
}
|
|
74
87
|
// 4. Check expiration
|
|
75
88
|
if (record.expiresAt && record.expiresAt <= Date.now()) {
|
|
76
|
-
return {
|
|
89
|
+
return {
|
|
90
|
+
valid: false,
|
|
91
|
+
status: 'EXPIRED',
|
|
92
|
+
record,
|
|
93
|
+
error: 'API key has expired',
|
|
94
|
+
};
|
|
77
95
|
}
|
|
78
96
|
// 5. Update last_used_at timestamp
|
|
79
97
|
if (options.updateLastUsed !== false) {
|
|
@@ -22,9 +22,11 @@ function base64UrlEncode(bytes) {
|
|
|
22
22
|
const second = bytes[i + 1];
|
|
23
23
|
const third = bytes[i + 2];
|
|
24
24
|
result += B64URL_ALPHABET[first >> 2];
|
|
25
|
-
result +=
|
|
25
|
+
result +=
|
|
26
|
+
B64URL_ALPHABET[((first & 3) << 4) | (second === undefined ? 0 : second >> 4)];
|
|
26
27
|
if (second !== undefined) {
|
|
27
|
-
result +=
|
|
28
|
+
result +=
|
|
29
|
+
B64URL_ALPHABET[((second & 15) << 2) | (third === undefined ? 0 : third >> 6)];
|
|
28
30
|
}
|
|
29
31
|
if (third !== undefined) {
|
|
30
32
|
result += B64URL_ALPHABET[third & 63];
|
|
@@ -109,7 +111,10 @@ function verifySignedToken(token, secret, options = {}) {
|
|
|
109
111
|
}
|
|
110
112
|
const parts = token.trim().split('.');
|
|
111
113
|
if (parts.length !== 3) {
|
|
112
|
-
return {
|
|
114
|
+
return {
|
|
115
|
+
valid: false,
|
|
116
|
+
error: 'Malformed token structure: expected 3 parts',
|
|
117
|
+
};
|
|
113
118
|
}
|
|
114
119
|
const [headerB64, payloadB64, signature] = parts;
|
|
115
120
|
const content = `${headerB64}.${payloadB64}`;
|
|
@@ -125,7 +130,10 @@ function verifySignedToken(token, secret, options = {}) {
|
|
|
125
130
|
parsedPayload = JSON.parse(jsonStr);
|
|
126
131
|
}
|
|
127
132
|
catch (err) {
|
|
128
|
-
return {
|
|
133
|
+
return {
|
|
134
|
+
valid: false,
|
|
135
|
+
error: `Failed to decode token payload: ${err?.message || err}`,
|
|
136
|
+
};
|
|
129
137
|
}
|
|
130
138
|
// 3. Verify Expiration
|
|
131
139
|
const clockSkewMs = (options.clockSkewSeconds ?? 60) * 1000;
|
package/dist/keys/store.js
CHANGED
|
@@ -10,7 +10,11 @@ function mapKeyRow(r) {
|
|
|
10
10
|
prefix: r.prefix,
|
|
11
11
|
display: r.display,
|
|
12
12
|
keyHash: r.key_hash,
|
|
13
|
-
metadata: r.metadata
|
|
13
|
+
metadata: r.metadata
|
|
14
|
+
? typeof r.metadata === 'string'
|
|
15
|
+
? JSON.parse(r.metadata)
|
|
16
|
+
: r.metadata
|
|
17
|
+
: undefined,
|
|
14
18
|
createdAt: Number(r.created_at || 0),
|
|
15
19
|
expiresAt: r.expires_at != null ? Number(r.expires_at) : null,
|
|
16
20
|
lastUsedAt: r.last_used_at != null ? Number(r.last_used_at) : null,
|
|
@@ -23,25 +27,25 @@ class KeyStore {
|
|
|
23
27
|
* Initializes the API keys schema and indexes if they do not exist.
|
|
24
28
|
*/
|
|
25
29
|
static async ensureSchema(db, tableName = exports.DEFAULT_KEYS_TABLE) {
|
|
26
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
27
|
-
id TEXT PRIMARY KEY,
|
|
28
|
-
name TEXT NOT NULL,
|
|
29
|
-
prefix TEXT NOT NULL,
|
|
30
|
-
display TEXT NOT NULL,
|
|
31
|
-
key_hash TEXT NOT NULL UNIQUE,
|
|
32
|
-
metadata TEXT,
|
|
33
|
-
created_at INTEGER NOT NULL,
|
|
34
|
-
expires_at INTEGER,
|
|
35
|
-
last_used_at INTEGER,
|
|
36
|
-
revoked INTEGER NOT NULL DEFAULT 0,
|
|
37
|
-
revoked_at INTEGER
|
|
30
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
31
|
+
id TEXT PRIMARY KEY,
|
|
32
|
+
name TEXT NOT NULL,
|
|
33
|
+
prefix TEXT NOT NULL,
|
|
34
|
+
display TEXT NOT NULL,
|
|
35
|
+
key_hash TEXT NOT NULL UNIQUE,
|
|
36
|
+
metadata TEXT,
|
|
37
|
+
created_at INTEGER NOT NULL,
|
|
38
|
+
expires_at INTEGER,
|
|
39
|
+
last_used_at INTEGER,
|
|
40
|
+
revoked INTEGER NOT NULL DEFAULT 0,
|
|
41
|
+
revoked_at INTEGER
|
|
38
42
|
);`);
|
|
39
43
|
await db.execute(`CREATE INDEX IF NOT EXISTS idx_${tableName}_hash ON ${tableName} (key_hash);`);
|
|
40
44
|
await db.execute(`CREATE INDEX IF NOT EXISTS idx_${tableName}_revoked ON ${tableName} (revoked, expires_at);`);
|
|
41
45
|
}
|
|
42
46
|
static async insertRecord(db, tableName = exports.DEFAULT_KEYS_TABLE, record) {
|
|
43
|
-
await db.execute(`INSERT INTO ${tableName} (
|
|
44
|
-
id, name, prefix, display, key_hash, metadata, created_at, expires_at, last_used_at, revoked, revoked_at
|
|
47
|
+
await db.execute(`INSERT INTO ${tableName} (
|
|
48
|
+
id, name, prefix, display, key_hash, metadata, created_at, expires_at, last_used_at, revoked, revoked_at
|
|
45
49
|
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`, [
|
|
46
50
|
record.id,
|
|
47
51
|
record.name,
|
|
@@ -69,7 +73,10 @@ class KeyStore {
|
|
|
69
73
|
return mapKeyRow(rows[0]);
|
|
70
74
|
}
|
|
71
75
|
static async updateLastUsed(db, tableName = exports.DEFAULT_KEYS_TABLE, id, timestamp) {
|
|
72
|
-
await db.execute(`UPDATE ${tableName} SET last_used_at = ? WHERE id = ?;`, [
|
|
76
|
+
await db.execute(`UPDATE ${tableName} SET last_used_at = ? WHERE id = ?;`, [
|
|
77
|
+
timestamp,
|
|
78
|
+
id,
|
|
79
|
+
]);
|
|
73
80
|
}
|
|
74
81
|
static async revoke(db, tableName = exports.DEFAULT_KEYS_TABLE, id) {
|
|
75
82
|
const now = Date.now();
|
package/dist/kv/manager.js
CHANGED
|
@@ -11,7 +11,8 @@ class KVManager {
|
|
|
11
11
|
constructor(db, eventsOrOptions, options) {
|
|
12
12
|
this.db = db;
|
|
13
13
|
let opts = {};
|
|
14
|
-
if (eventsOrOptions &&
|
|
14
|
+
if (eventsOrOptions &&
|
|
15
|
+
typeof eventsOrOptions.emit === 'function') {
|
|
15
16
|
this.events = eventsOrOptions;
|
|
16
17
|
opts = options || {};
|
|
17
18
|
}
|
|
@@ -117,7 +118,9 @@ class KVManager {
|
|
|
117
118
|
if (!options.passphrase) {
|
|
118
119
|
throw new Error('Passphrase is required to store encrypted secret.');
|
|
119
120
|
}
|
|
120
|
-
const strValue = typeof secretValue === 'string'
|
|
121
|
+
const strValue = typeof secretValue === 'string'
|
|
122
|
+
? secretValue
|
|
123
|
+
: JSON.stringify(secretValue);
|
|
121
124
|
const plainBytes = new TextEncoder().encode(strValue);
|
|
122
125
|
const encryptedBytes = await (0, encryption_js_1.encryptBackupData)(plainBytes, options.passphrase);
|
|
123
126
|
const encryptedBase64 = (0, signed_token_js_1.base64UrlEncode)(encryptedBytes);
|
package/dist/kv/store.js
CHANGED
|
@@ -31,23 +31,23 @@ function mapKVRow(r) {
|
|
|
31
31
|
}
|
|
32
32
|
class KVStore {
|
|
33
33
|
static async ensureSchema(db, tableName = exports.DEFAULT_KV_TABLE) {
|
|
34
|
-
await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
35
|
-
key TEXT PRIMARY KEY,
|
|
36
|
-
value TEXT NOT NULL,
|
|
37
|
-
type TEXT NOT NULL,
|
|
38
|
-
created_at INTEGER NOT NULL,
|
|
39
|
-
updated_at INTEGER NOT NULL,
|
|
40
|
-
expires_at INTEGER
|
|
34
|
+
await db.execute(`CREATE TABLE IF NOT EXISTS ${tableName} (
|
|
35
|
+
key TEXT PRIMARY KEY,
|
|
36
|
+
value TEXT NOT NULL,
|
|
37
|
+
type TEXT NOT NULL,
|
|
38
|
+
created_at INTEGER NOT NULL,
|
|
39
|
+
updated_at INTEGER NOT NULL,
|
|
40
|
+
expires_at INTEGER
|
|
41
41
|
);`);
|
|
42
42
|
await db.execute(`CREATE INDEX IF NOT EXISTS idx_${tableName}_expires ON ${tableName} (expires_at);`);
|
|
43
43
|
}
|
|
44
44
|
static async set(db, tableName = exports.DEFAULT_KV_TABLE, key, valueStr, type, now, expiresAt) {
|
|
45
|
-
await db.execute(`INSERT INTO ${tableName} (key, value, type, created_at, updated_at, expires_at)
|
|
46
|
-
VALUES (?, ?, ?, ?, ?, ?)
|
|
47
|
-
ON CONFLICT(key) DO UPDATE SET
|
|
48
|
-
value = excluded.value,
|
|
49
|
-
type = excluded.type,
|
|
50
|
-
updated_at = excluded.updated_at,
|
|
45
|
+
await db.execute(`INSERT INTO ${tableName} (key, value, type, created_at, updated_at, expires_at)
|
|
46
|
+
VALUES (?, ?, ?, ?, ?, ?)
|
|
47
|
+
ON CONFLICT(key) DO UPDATE SET
|
|
48
|
+
value = excluded.value,
|
|
49
|
+
type = excluded.type,
|
|
50
|
+
updated_at = excluded.updated_at,
|
|
51
51
|
expires_at = excluded.expires_at;`, [key, valueStr, type, now, now, expiresAt]);
|
|
52
52
|
}
|
|
53
53
|
static async get(db, tableName = exports.DEFAULT_KV_TABLE, key) {
|
package/dist/react/auth.js
CHANGED
|
@@ -19,19 +19,19 @@ function useGoogleAuth(client) {
|
|
|
19
19
|
let isMounted = true;
|
|
20
20
|
client
|
|
21
21
|
.getUser()
|
|
22
|
-
.then(currentUser => {
|
|
22
|
+
.then((currentUser) => {
|
|
23
23
|
if (isMounted) {
|
|
24
24
|
setUser(currentUser);
|
|
25
25
|
setLoading(false);
|
|
26
26
|
}
|
|
27
27
|
})
|
|
28
|
-
.catch(err => {
|
|
28
|
+
.catch((err) => {
|
|
29
29
|
if (isMounted) {
|
|
30
30
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
31
31
|
setLoading(false);
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
|
-
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
34
|
+
const unsubscribe = client.onAuthStateChange((updatedUser) => {
|
|
35
35
|
if (isMounted) {
|
|
36
36
|
setUser(updatedUser);
|
|
37
37
|
}
|
|
@@ -108,19 +108,19 @@ function useMicrosoftAuth(client) {
|
|
|
108
108
|
let isMounted = true;
|
|
109
109
|
client
|
|
110
110
|
.getUser()
|
|
111
|
-
.then(currentUser => {
|
|
111
|
+
.then((currentUser) => {
|
|
112
112
|
if (isMounted) {
|
|
113
113
|
setUser(currentUser);
|
|
114
114
|
setLoading(false);
|
|
115
115
|
}
|
|
116
116
|
})
|
|
117
|
-
.catch(err => {
|
|
117
|
+
.catch((err) => {
|
|
118
118
|
if (isMounted) {
|
|
119
119
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
120
120
|
setLoading(false);
|
|
121
121
|
}
|
|
122
122
|
});
|
|
123
|
-
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
123
|
+
const unsubscribe = client.onAuthStateChange((updatedUser) => {
|
|
124
124
|
if (isMounted) {
|
|
125
125
|
setUser(updatedUser);
|
|
126
126
|
}
|
|
@@ -197,19 +197,19 @@ function useGitHubAuth(client) {
|
|
|
197
197
|
let isMounted = true;
|
|
198
198
|
client
|
|
199
199
|
.getUser()
|
|
200
|
-
.then(currentUser => {
|
|
200
|
+
.then((currentUser) => {
|
|
201
201
|
if (isMounted) {
|
|
202
202
|
setUser(currentUser);
|
|
203
203
|
setLoading(false);
|
|
204
204
|
}
|
|
205
205
|
})
|
|
206
|
-
.catch(err => {
|
|
206
|
+
.catch((err) => {
|
|
207
207
|
if (isMounted) {
|
|
208
208
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
209
209
|
setLoading(false);
|
|
210
210
|
}
|
|
211
211
|
});
|
|
212
|
-
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
212
|
+
const unsubscribe = client.onAuthStateChange((updatedUser) => {
|
|
213
213
|
if (isMounted) {
|
|
214
214
|
setUser(updatedUser);
|
|
215
215
|
}
|
|
@@ -286,19 +286,19 @@ function useAppleAuth(client) {
|
|
|
286
286
|
let isMounted = true;
|
|
287
287
|
client
|
|
288
288
|
.getUser()
|
|
289
|
-
.then(currentUser => {
|
|
289
|
+
.then((currentUser) => {
|
|
290
290
|
if (isMounted) {
|
|
291
291
|
setUser(currentUser);
|
|
292
292
|
setLoading(false);
|
|
293
293
|
}
|
|
294
294
|
})
|
|
295
|
-
.catch(err => {
|
|
295
|
+
.catch((err) => {
|
|
296
296
|
if (isMounted) {
|
|
297
297
|
setError(err instanceof Error ? err : new Error(String(err)));
|
|
298
298
|
setLoading(false);
|
|
299
299
|
}
|
|
300
300
|
});
|
|
301
|
-
const unsubscribe = client.onAuthStateChange(updatedUser => {
|
|
301
|
+
const unsubscribe = client.onAuthStateChange((updatedUser) => {
|
|
302
302
|
if (isMounted) {
|
|
303
303
|
setUser(updatedUser);
|
|
304
304
|
}
|
package/dist/react/backups.js
CHANGED
package/dist/react/index.js
CHANGED
|
@@ -52,10 +52,7 @@ function areRowsEqual(a, b) {
|
|
|
52
52
|
const bVal = bObj[k];
|
|
53
53
|
if (aVal === bVal)
|
|
54
54
|
continue;
|
|
55
|
-
if (aVal &&
|
|
56
|
-
bVal &&
|
|
57
|
-
typeof aVal === 'object' &&
|
|
58
|
-
typeof bVal === 'object') {
|
|
55
|
+
if (aVal && bVal && typeof aVal === 'object' && typeof bVal === 'object') {
|
|
59
56
|
if (Array.isArray(aVal) !== Array.isArray(bVal))
|
|
60
57
|
return false;
|
|
61
58
|
if (JSON.stringify(aVal) !== JSON.stringify(bVal))
|
|
@@ -331,7 +328,7 @@ function normalizeMultiQueries(input) {
|
|
|
331
328
|
*/
|
|
332
329
|
function useLiveQueries(client, queries) {
|
|
333
330
|
const signature = (0, react_1.useMemo)(() => {
|
|
334
|
-
return JSON.stringify(queries, (_, val) =>
|
|
331
|
+
return JSON.stringify(queries, (_, val) => typeof val === 'function' ? 'fn' : val);
|
|
335
332
|
}, [queries]);
|
|
336
333
|
const items = (0, react_1.useMemo)(() => normalizeMultiQueries(queries), [signature]);
|
|
337
334
|
const clientScope = getClientScope(client);
|
|
@@ -374,7 +371,8 @@ function useLiveQueries(client, queries) {
|
|
|
374
371
|
}
|
|
375
372
|
catch (err) {
|
|
376
373
|
const msg = String(err?.message || err || '');
|
|
377
|
-
if (msg.includes('no such column') ||
|
|
374
|
+
if (msg.includes('no such column') ||
|
|
375
|
+
msg.includes('no such table')) {
|
|
378
376
|
return { key: item.key, rows: [] };
|
|
379
377
|
}
|
|
380
378
|
console.error(`Error in useLiveQueries("${item.table}"):`, err);
|
|
@@ -474,7 +472,10 @@ function useLiveRow(client, tableName, rowId, options) {
|
|
|
474
472
|
const unsubscribe = client.events.on(tableName, (event) => {
|
|
475
473
|
advanceTableVersion(client, tableName);
|
|
476
474
|
// Precise row-level invalidation: only refetch if event affects this rowId or is a bulk event
|
|
477
|
-
if (!event ||
|
|
475
|
+
if (!event ||
|
|
476
|
+
!event.rowId ||
|
|
477
|
+
event.rowId === rowId ||
|
|
478
|
+
event.rowId === 'batch') {
|
|
478
479
|
scheduleRefetch();
|
|
479
480
|
}
|
|
480
481
|
});
|
|
@@ -578,8 +579,12 @@ function useLiveInfiniteQuery(client, tableName, options = {}) {
|
|
|
578
579
|
function useMutations(client) {
|
|
579
580
|
return (0, react_1.useMemo)(() => ({
|
|
580
581
|
client,
|
|
581
|
-
insert: (table, payload, opts) => client
|
|
582
|
-
|
|
582
|
+
insert: (table, payload, opts) => client
|
|
583
|
+
? client.insert(table, payload, opts)
|
|
584
|
+
: Promise.resolve(undefined),
|
|
585
|
+
insertMany: (table, records, opts) => client
|
|
586
|
+
? client.insertMany(table, records, opts)
|
|
587
|
+
: Promise.resolve(undefined),
|
|
583
588
|
update: (table, id, payload, opts) => client ? client.update(table, id, payload, opts) : Promise.resolve(),
|
|
584
589
|
updateMany: (table, updates, opts) => client ? client.updateMany(table, updates, opts) : Promise.resolve(),
|
|
585
590
|
delete: (table, id, opts) => client ? client.delete(table, id, opts) : Promise.resolve(),
|
package/dist/react/runner.js
CHANGED
package/dist/react/status.js
CHANGED
|
@@ -37,7 +37,9 @@ function useSyncStatus(client) {
|
|
|
37
37
|
if (records) {
|
|
38
38
|
setPendingRecords(records);
|
|
39
39
|
const activeCount = metrics
|
|
40
|
-
? metrics.outboxPendingCount +
|
|
40
|
+
? metrics.outboxPendingCount +
|
|
41
|
+
metrics.outboxProcessingCount +
|
|
42
|
+
metrics.outboxFailedCount
|
|
41
43
|
: records.length;
|
|
42
44
|
setPendingCount(activeCount);
|
|
43
45
|
}
|
|
@@ -71,7 +73,9 @@ function useSyncStatus(client) {
|
|
|
71
73
|
setLastSyncedAt(ts > 0 ? ts : null);
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
|
-
catch {
|
|
76
|
+
catch {
|
|
77
|
+
/* ignored */
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
});
|
|
77
81
|
return () => {
|
|
@@ -23,12 +23,12 @@ class EventEmitter {
|
|
|
23
23
|
emit(event, data) {
|
|
24
24
|
const eventSet = this.listeners.get(event);
|
|
25
25
|
if (eventSet) {
|
|
26
|
-
eventSet.forEach(callback => {
|
|
26
|
+
eventSet.forEach((callback) => {
|
|
27
27
|
try {
|
|
28
28
|
callback(data);
|
|
29
29
|
}
|
|
30
30
|
catch (err) {
|
|
31
|
-
console.error(
|
|
31
|
+
console.error('Emitter error:', err);
|
|
32
32
|
}
|
|
33
33
|
});
|
|
34
34
|
}
|
package/dist/scheduler/cron.js
CHANGED
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseScheduleToIntervalMs = parseScheduleToIntervalMs;
|
|
4
4
|
exports.calculateNextRun = calculateNextRun;
|
|
5
5
|
function parseScheduleToIntervalMs(schedule) {
|
|
6
|
-
if (typeof schedule === 'object' &&
|
|
6
|
+
if (typeof schedule === 'object' &&
|
|
7
|
+
schedule !== null &&
|
|
8
|
+
'intervalMs' in schedule) {
|
|
7
9
|
return Math.max(1000, Number(schedule.intervalMs) || 60000);
|
|
8
10
|
}
|
|
9
11
|
if (typeof schedule === 'number') {
|