local-lite 0.2.6 → 1.0.1
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 +18 -13
- package/dist/actions/manager.d.ts +9 -1
- package/dist/actions/manager.js +143 -62
- package/dist/actions/types.d.ts +33 -0
- package/dist/adapters/remote/index.d.ts +1 -0
- package/dist/adapters/remote/index.js +1 -0
- package/dist/adapters/remote/self-hosted.d.ts +88 -0
- package/dist/adapters/remote/self-hosted.js +262 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.js +18 -1
- package/dist/config/resolve-remote.js +12 -0
- package/dist/config/types.d.ts +70 -0
- package/dist/devtools/SyncInspector.js +9 -2
- package/dist/email/index.d.ts +128 -0
- package/dist/email/index.js +431 -0
- package/dist/server/email.d.ts +41 -0
- package/dist/server/email.js +79 -0
- package/dist/server/index.d.ts +2 -0
- package/dist/server/index.js +16 -0
- package/dist/server/sync.d.ts +96 -0
- package/dist/server/sync.js +207 -0
- package/package.json +12 -1
- package/skills/local-lite-custom-adapter/SKILL.md +3 -0
- package/skills/local-lite-offline-actions/SKILL.md +69 -28
- package/skills/local-lite-react/SKILL.md +17 -0
- package/skills/local-lite-server/SKILL.md +132 -1
- package/skills/local-lite-setup/SKILL.md +18 -5
- package/skills/local-lite-upgrade/SKILL.md +9 -0
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SelfHostedRemoteAdapter = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Universal client remote adapter for self-hosted local-lite sync backends.
|
|
6
|
+
* Connects directly to server endpoints created via `createSyncEndpoint()` with zero vendor lock-in.
|
|
7
|
+
*/
|
|
8
|
+
class SelfHostedRemoteAdapter {
|
|
9
|
+
url;
|
|
10
|
+
token;
|
|
11
|
+
tables;
|
|
12
|
+
customHeaders;
|
|
13
|
+
fetchFn;
|
|
14
|
+
pollIntervalMs;
|
|
15
|
+
syncScope;
|
|
16
|
+
activeSubscribers = new Set();
|
|
17
|
+
pollTimer;
|
|
18
|
+
lastPollCursor = 0;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
if (!options.url) {
|
|
21
|
+
throw new Error("A valid 'url' is required for SelfHostedRemoteAdapter.");
|
|
22
|
+
}
|
|
23
|
+
this.url = options.url.replace(/\/$/, '');
|
|
24
|
+
this.token = options.token;
|
|
25
|
+
this.tables = options.tables ?? [];
|
|
26
|
+
this.customHeaders = options.headers ?? {};
|
|
27
|
+
this.fetchFn = options.fetch || globalThis.fetch;
|
|
28
|
+
this.pollIntervalMs = options.pollIntervalMs ?? 5000;
|
|
29
|
+
if (!this.fetchFn) {
|
|
30
|
+
throw new Error('A global or configured fetch function is required for SelfHostedRemoteAdapter.');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
getRequestHeaders() {
|
|
34
|
+
const headers = {
|
|
35
|
+
'Content-Type': 'application/json',
|
|
36
|
+
...this.customHeaders,
|
|
37
|
+
};
|
|
38
|
+
if (this.token) {
|
|
39
|
+
headers['Authorization'] = `Bearer ${this.token}`;
|
|
40
|
+
}
|
|
41
|
+
return headers;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Pushes client mutations to the self-hosted sync backend.
|
|
45
|
+
*/
|
|
46
|
+
async pushChanges(operations) {
|
|
47
|
+
if (operations.length === 0) {
|
|
48
|
+
return { success: true, successfulIds: [] };
|
|
49
|
+
}
|
|
50
|
+
const response = await this.fetchFn(this.url, {
|
|
51
|
+
method: 'POST',
|
|
52
|
+
headers: this.getRequestHeaders(),
|
|
53
|
+
body: JSON.stringify({ operations }),
|
|
54
|
+
});
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
const errText = await response.text().catch(() => response.statusText);
|
|
57
|
+
throw new Error(`Self-hosted sync push failed (${response.status}): ${errText}`);
|
|
58
|
+
}
|
|
59
|
+
const data = await response.json();
|
|
60
|
+
return {
|
|
61
|
+
success: true,
|
|
62
|
+
successfulIds: data.successfulIds ?? operations.map((op) => op.id),
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Pulls delta changes from the self-hosted sync backend since a given timestamp or cursor.
|
|
67
|
+
*/
|
|
68
|
+
async fetchChanges(sinceTimestamp, _scope) {
|
|
69
|
+
const tablesParam = encodeURIComponent(this.tables.join(','));
|
|
70
|
+
const url = `${this.url}?tables=${tablesParam}&since=${encodeURIComponent(String(sinceTimestamp))}`;
|
|
71
|
+
const response = await this.fetchFn(url, {
|
|
72
|
+
method: 'GET',
|
|
73
|
+
headers: this.getRequestHeaders(),
|
|
74
|
+
});
|
|
75
|
+
if (!response.ok) {
|
|
76
|
+
const errText = await response.text().catch(() => response.statusText);
|
|
77
|
+
throw new Error(`Self-hosted sync pull failed (${response.status}): ${errText}`);
|
|
78
|
+
}
|
|
79
|
+
const data = await response.json();
|
|
80
|
+
this.lastPollCursor = Math.max(this.lastPollCursor, data.cursor ?? sinceTimestamp);
|
|
81
|
+
return data.changes ?? { timestamp: Date.now(), changes: [] };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Subscribes to live server changes via periodic polling.
|
|
85
|
+
*/
|
|
86
|
+
subscribeToLiveChanges(callback, scope) {
|
|
87
|
+
if (scope) {
|
|
88
|
+
this.syncScope = scope;
|
|
89
|
+
}
|
|
90
|
+
this.activeSubscribers.add(callback);
|
|
91
|
+
if (!this.pollTimer) {
|
|
92
|
+
this.startPolling();
|
|
93
|
+
}
|
|
94
|
+
return () => {
|
|
95
|
+
this.activeSubscribers.delete(callback);
|
|
96
|
+
if (this.activeSubscribers.size === 0 && this.pollTimer) {
|
|
97
|
+
clearInterval(this.pollTimer);
|
|
98
|
+
this.pollTimer = undefined;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
startPolling() {
|
|
103
|
+
this.pollTimer = setInterval(async () => {
|
|
104
|
+
if (this.activeSubscribers.size === 0)
|
|
105
|
+
return;
|
|
106
|
+
try {
|
|
107
|
+
const changes = await this.fetchChanges(this.lastPollCursor);
|
|
108
|
+
const hasChanges = Object.values(changes).some((rows) => Array.isArray(rows) && rows.length > 0);
|
|
109
|
+
if (hasChanges) {
|
|
110
|
+
for (const subscriber of this.activeSubscribers) {
|
|
111
|
+
try {
|
|
112
|
+
subscriber(changes);
|
|
113
|
+
}
|
|
114
|
+
catch { }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
catch { }
|
|
119
|
+
}, this.pollIntervalMs);
|
|
120
|
+
}
|
|
121
|
+
setSyncScope(scope) {
|
|
122
|
+
this.syncScope = scope;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Executes a remote function call or RPC across self-hosted endpoints.
|
|
126
|
+
*/
|
|
127
|
+
async call(functionName, args = {}) {
|
|
128
|
+
const actionEndpoints = {
|
|
129
|
+
'payments/stk': '/payments/stk',
|
|
130
|
+
'contracts/renewal': '/contracts/renewal',
|
|
131
|
+
'contracts/termination': '/contracts/termination',
|
|
132
|
+
'tenant-self-service': '/tenant-self-service',
|
|
133
|
+
'email': '/email',
|
|
134
|
+
'backups/create': '/backups/create',
|
|
135
|
+
'backups/list': '/backups',
|
|
136
|
+
'crons/toggle': '/crons/toggle',
|
|
137
|
+
'crons/daily': '/crons/daily',
|
|
138
|
+
'business-access/invite': '/business-access/invite',
|
|
139
|
+
'business-access/accept': '/business-access/accept',
|
|
140
|
+
'business-access/reject': '/business-access/reject',
|
|
141
|
+
'business-access/update': '/business-access/update',
|
|
142
|
+
'business-access/revoke': '/business-access/revoke',
|
|
143
|
+
};
|
|
144
|
+
const normalized = functionName
|
|
145
|
+
.replace(/^functions\//, '')
|
|
146
|
+
.replace('contracts:sendRenewalReminder', 'contracts/renewal')
|
|
147
|
+
.replace('contracts:sendTerminationNotice', 'contracts/termination')
|
|
148
|
+
.replace('payments:initiateDaraja', 'payments/stk')
|
|
149
|
+
.replace('tenantSelfService:createSelfServiceLink', 'tenant-self-service')
|
|
150
|
+
.replace('email:send', 'email')
|
|
151
|
+
.replace('convexBackups:listMyBackups', 'backups/list')
|
|
152
|
+
.replace('convexBackups:createBackup', 'backups/create')
|
|
153
|
+
.replace('automations:listMine', 'crons')
|
|
154
|
+
.replace('automations:setEnabled', 'crons/toggle')
|
|
155
|
+
.replace(':', '/');
|
|
156
|
+
if (normalized === 'backups/list' || normalized === 'crons') {
|
|
157
|
+
const isBackups = normalized === 'backups/list';
|
|
158
|
+
const endpoint = isBackups ? '/backups' : '/crons';
|
|
159
|
+
const fullUrl = `${this.url}${endpoint}`;
|
|
160
|
+
const response = await this.fetchFn(fullUrl, {
|
|
161
|
+
method: 'GET',
|
|
162
|
+
headers: this.getRequestHeaders(),
|
|
163
|
+
});
|
|
164
|
+
if (!response.ok) {
|
|
165
|
+
const errText = await response.text().catch(() => response.statusText);
|
|
166
|
+
throw new Error(`Self-hosted function call "${functionName}" failed (${response.status}): ${errText}`);
|
|
167
|
+
}
|
|
168
|
+
const data = await response.json();
|
|
169
|
+
return (isBackups ? data.archives || [] : data.automations || []);
|
|
170
|
+
}
|
|
171
|
+
const endpoint = actionEndpoints[normalized] || `/${normalized}`;
|
|
172
|
+
const fullUrl = `${this.url}${endpoint.startsWith('/') ? endpoint : '/' + endpoint}`;
|
|
173
|
+
const response = await this.fetchFn(fullUrl, {
|
|
174
|
+
method: 'POST',
|
|
175
|
+
headers: this.getRequestHeaders(),
|
|
176
|
+
body: JSON.stringify(args),
|
|
177
|
+
});
|
|
178
|
+
if (!response.ok) {
|
|
179
|
+
const errText = await response.text().catch(() => response.statusText);
|
|
180
|
+
throw new Error(`Self-hosted function call "${functionName}" failed (${response.status}): ${errText}`);
|
|
181
|
+
}
|
|
182
|
+
const contentType = response.headers.get('content-type') || '';
|
|
183
|
+
if (contentType.includes('application/json')) {
|
|
184
|
+
return (await response.json());
|
|
185
|
+
}
|
|
186
|
+
return (await response.text());
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Queries a remote function or view across self-hosted endpoints.
|
|
190
|
+
*/
|
|
191
|
+
async queryRemote(queryName, args = {}) {
|
|
192
|
+
if (queryName.includes('listMyBackups') || queryName.includes('listBackups')) {
|
|
193
|
+
return (await this.listBackups());
|
|
194
|
+
}
|
|
195
|
+
if (queryName.includes('listMine') || queryName.includes('listAutomations')) {
|
|
196
|
+
return (await this.listAutomations());
|
|
197
|
+
}
|
|
198
|
+
return this.call(queryName, args);
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Lists cloud backup archives stored on self-hosted backend.
|
|
202
|
+
*/
|
|
203
|
+
async listBackups() {
|
|
204
|
+
const fullUrl = `${this.url}/backups`;
|
|
205
|
+
const response = await this.fetchFn(fullUrl, {
|
|
206
|
+
method: 'GET',
|
|
207
|
+
headers: this.getRequestHeaders(),
|
|
208
|
+
});
|
|
209
|
+
if (!response.ok) {
|
|
210
|
+
const errText = await response.text().catch(() => response.statusText);
|
|
211
|
+
throw new Error(`Self-hosted listBackups failed (${response.status}): ${errText}`);
|
|
212
|
+
}
|
|
213
|
+
const data = await response.json();
|
|
214
|
+
return (data.archives || []);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Gets a direct download URL for a file stored on self-hosted backend.
|
|
218
|
+
*/
|
|
219
|
+
async getDownloadUrl(fileIdOrKey) {
|
|
220
|
+
if (!fileIdOrKey)
|
|
221
|
+
return null;
|
|
222
|
+
return `${this.url}/backups/download/${encodeURIComponent(fileIdOrKey)}`;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Lists automated cron jobs configured on self-hosted backend.
|
|
226
|
+
*/
|
|
227
|
+
async listAutomations() {
|
|
228
|
+
const fullUrl = `${this.url}/crons`;
|
|
229
|
+
const response = await this.fetchFn(fullUrl, {
|
|
230
|
+
method: 'GET',
|
|
231
|
+
headers: this.getRequestHeaders(),
|
|
232
|
+
});
|
|
233
|
+
if (!response.ok) {
|
|
234
|
+
return [
|
|
235
|
+
{
|
|
236
|
+
id: 'daily_contract_reminders',
|
|
237
|
+
name: 'Daily Contract Reminders',
|
|
238
|
+
description: 'Automated contract expiration notifications and renewal checks',
|
|
239
|
+
enabled: true,
|
|
240
|
+
},
|
|
241
|
+
];
|
|
242
|
+
}
|
|
243
|
+
const data = await response.json();
|
|
244
|
+
return (data.automations || []);
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* Enables or disables an automated cron job on self-hosted backend.
|
|
248
|
+
*/
|
|
249
|
+
async setAutomationEnabled(jobId, enabled) {
|
|
250
|
+
const fullUrl = `${this.url}/crons/toggle`;
|
|
251
|
+
const response = await this.fetchFn(fullUrl, {
|
|
252
|
+
method: 'POST',
|
|
253
|
+
headers: this.getRequestHeaders(),
|
|
254
|
+
body: JSON.stringify({ jobId, enabled }),
|
|
255
|
+
});
|
|
256
|
+
if (!response.ok) {
|
|
257
|
+
const errText = await response.text().catch(() => response.statusText);
|
|
258
|
+
throw new Error(`Self-hosted setAutomationEnabled failed (${response.status}): ${errText}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
exports.SelfHostedRemoteAdapter = SelfHostedRemoteAdapter;
|
package/dist/config/index.d.ts
CHANGED
|
@@ -13,6 +13,7 @@ export { NodeSQLiteAdapter } from '../adapters/local/node-sqlite.js';
|
|
|
13
13
|
export { SupabaseRemoteAdapter } from '../adapters/remote/supabase.js';
|
|
14
14
|
export { ConvexRemoteAdapter } from '../adapters/remote/convex.js';
|
|
15
15
|
export { FirestoreRemoteAdapter } from '../adapters/remote/firestore.js';
|
|
16
|
+
export { SelfHostedRemoteAdapter } from '../adapters/remote/self-hosted.js';
|
|
16
17
|
export { MemoryDemoRemoteAdapter, NoopRemoteAdapter } from '../adapters/remote/demo.js';
|
|
17
18
|
export type { RemoteDBAdapter } from '../adapters/remote/index.js';
|
|
18
19
|
/**
|
package/dist/config/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.NoopRemoteAdapter = exports.MemoryDemoRemoteAdapter = exports.FirestoreRemoteAdapter = exports.ConvexRemoteAdapter = exports.SupabaseRemoteAdapter = exports.NodeSQLiteAdapter = exports.SqlJsAdapter = exports.LibSQLAdapter = exports.BetterSQLite3Adapter = exports.OpSQLiteAdapter = exports.ExpoSQLiteAdapter = exports.LocalFirstClient = exports.resolveRemoteAdapter = exports.resolveLocalAdapter = void 0;
|
|
17
|
+
exports.NoopRemoteAdapter = exports.MemoryDemoRemoteAdapter = exports.SelfHostedRemoteAdapter = exports.FirestoreRemoteAdapter = exports.ConvexRemoteAdapter = exports.SupabaseRemoteAdapter = exports.NodeSQLiteAdapter = exports.SqlJsAdapter = exports.LibSQLAdapter = exports.BetterSQLite3Adapter = exports.OpSQLiteAdapter = exports.ExpoSQLiteAdapter = exports.LocalFirstClient = exports.resolveRemoteAdapter = exports.resolveLocalAdapter = void 0;
|
|
18
18
|
exports.defineSyncConfig = defineSyncConfig;
|
|
19
19
|
exports.createSyncClient = createSyncClient;
|
|
20
20
|
const client_js_1 = require("../core/client.js");
|
|
@@ -49,6 +49,8 @@ var convex_js_1 = require("../adapters/remote/convex.js");
|
|
|
49
49
|
Object.defineProperty(exports, "ConvexRemoteAdapter", { enumerable: true, get: function () { return convex_js_1.ConvexRemoteAdapter; } });
|
|
50
50
|
var firestore_js_1 = require("../adapters/remote/firestore.js");
|
|
51
51
|
Object.defineProperty(exports, "FirestoreRemoteAdapter", { enumerable: true, get: function () { return firestore_js_1.FirestoreRemoteAdapter; } });
|
|
52
|
+
var self_hosted_js_1 = require("../adapters/remote/self-hosted.js");
|
|
53
|
+
Object.defineProperty(exports, "SelfHostedRemoteAdapter", { enumerable: true, get: function () { return self_hosted_js_1.SelfHostedRemoteAdapter; } });
|
|
52
54
|
var demo_js_1 = require("../adapters/remote/demo.js");
|
|
53
55
|
Object.defineProperty(exports, "MemoryDemoRemoteAdapter", { enumerable: true, get: function () { return demo_js_1.MemoryDemoRemoteAdapter; } });
|
|
54
56
|
Object.defineProperty(exports, "NoopRemoteAdapter", { enumerable: true, get: function () { return demo_js_1.NoopRemoteAdapter; } });
|
|
@@ -101,5 +103,20 @@ async function createSyncClient(config) {
|
|
|
101
103
|
if (config.autoInitialize !== false) {
|
|
102
104
|
await client.initialize();
|
|
103
105
|
}
|
|
106
|
+
// 6. Direct Email Dispatch (Nodemailer, Resend, SendGrid, Postmark, HTTP, etc.)
|
|
107
|
+
if (config.email) {
|
|
108
|
+
const { createEmailHandler } = await import('../email/index.js');
|
|
109
|
+
const emailHandler = createEmailHandler({
|
|
110
|
+
provider: config.email.provider,
|
|
111
|
+
transport: config.email.transport,
|
|
112
|
+
apiKey: config.email.apiKey,
|
|
113
|
+
endpoint: config.email.endpoint,
|
|
114
|
+
headers: config.email.headers,
|
|
115
|
+
defaultFrom: config.email.defaults?.from,
|
|
116
|
+
defaults: config.email.defaults,
|
|
117
|
+
...config.email.options,
|
|
118
|
+
});
|
|
119
|
+
client.actions.registerEmailHandler(emailHandler);
|
|
120
|
+
}
|
|
104
121
|
return client;
|
|
105
122
|
}
|
|
@@ -4,6 +4,7 @@ exports.resolveRemoteAdapter = resolveRemoteAdapter;
|
|
|
4
4
|
const supabase_js_1 = require("../adapters/remote/supabase.js");
|
|
5
5
|
const convex_js_1 = require("../adapters/remote/convex.js");
|
|
6
6
|
const firestore_js_1 = require("../adapters/remote/firestore.js");
|
|
7
|
+
const self_hosted_js_1 = require("../adapters/remote/self-hosted.js");
|
|
7
8
|
const demo_js_1 = require("../adapters/remote/demo.js");
|
|
8
9
|
const dynamic_js_1 = require("../utils/dynamic.js");
|
|
9
10
|
// Construct dynamically to prevent Metro, Webpack, and Rollup from treating
|
|
@@ -39,6 +40,17 @@ async function resolveRemoteAdapter(config) {
|
|
|
39
40
|
updatedAtColumn: config.convex.updatedAtColumn,
|
|
40
41
|
});
|
|
41
42
|
}
|
|
43
|
+
// 4. Self-hosted sync backend
|
|
44
|
+
if (config.server?.url) {
|
|
45
|
+
return new self_hosted_js_1.SelfHostedRemoteAdapter({
|
|
46
|
+
url: config.server.url,
|
|
47
|
+
token: config.server.token,
|
|
48
|
+
headers: config.server.headers,
|
|
49
|
+
tables: config.tables,
|
|
50
|
+
primaryKey: config.primaryKey,
|
|
51
|
+
pollIntervalMs: config.server.pollIntervalMs,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
42
54
|
const getSupabaseOptions = () => ({
|
|
43
55
|
tables: config.tables,
|
|
44
56
|
primaryKey: config.primaryKey,
|
package/dist/config/types.d.ts
CHANGED
|
@@ -69,6 +69,65 @@ export interface FirebaseConfigOptions {
|
|
|
69
69
|
*/
|
|
70
70
|
firestoreModule?: any;
|
|
71
71
|
}
|
|
72
|
+
export interface EmailConfig {
|
|
73
|
+
/**
|
|
74
|
+
* Email delivery provider:
|
|
75
|
+
* - 'nodemailer': Direct SMTP, Sendmail, SES, or custom transport via Nodemailer.
|
|
76
|
+
* - 'resend': Direct HTTP dispatch to Resend API.
|
|
77
|
+
* - 'sendgrid': Direct HTTP dispatch to SendGrid API.
|
|
78
|
+
* - 'postmark': Direct HTTP dispatch to Postmark API.
|
|
79
|
+
* - 'http': Custom HTTP endpoint or webhook.
|
|
80
|
+
*/
|
|
81
|
+
provider?: 'nodemailer' | 'resend' | 'sendgrid' | 'postmark' | 'http' | 'custom';
|
|
82
|
+
/**
|
|
83
|
+
* Transport configuration for Nodemailer:
|
|
84
|
+
* - A Nodemailer Transporter instance (e.g. from nodemailer.createTransport(...))
|
|
85
|
+
* - An SMTP configuration object ({ host, port, auth: { user, pass }, ... })
|
|
86
|
+
* - A connection URL string (e.g. 'smtps://user:pass@smtp.example.com')
|
|
87
|
+
*/
|
|
88
|
+
transport?: any;
|
|
89
|
+
/**
|
|
90
|
+
* API Key for HTTP email providers (Resend, SendGrid, Postmark).
|
|
91
|
+
*/
|
|
92
|
+
apiKey?: string;
|
|
93
|
+
/**
|
|
94
|
+
* Target endpoint URL for HTTP dispatch or custom webhook.
|
|
95
|
+
*/
|
|
96
|
+
endpoint?: string;
|
|
97
|
+
/**
|
|
98
|
+
* Custom HTTP request headers for HTTP providers.
|
|
99
|
+
*/
|
|
100
|
+
headers?: Record<string, string>;
|
|
101
|
+
/**
|
|
102
|
+
* Default email options (e.g. default 'from' address or headers).
|
|
103
|
+
*/
|
|
104
|
+
defaults?: {
|
|
105
|
+
from?: string;
|
|
106
|
+
[key: string]: any;
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Additional handler options (template renderer, beforeSend, afterSend).
|
|
110
|
+
*/
|
|
111
|
+
options?: any;
|
|
112
|
+
}
|
|
113
|
+
export interface SelfHostedServerConfigOptions {
|
|
114
|
+
/**
|
|
115
|
+
* Endpoint base URL for the sync API (e.g. 'https://api.mycompany.com/api/sync').
|
|
116
|
+
*/
|
|
117
|
+
url: string;
|
|
118
|
+
/**
|
|
119
|
+
* Optional secret or JWT auth token sent in `Authorization: Bearer <token>`.
|
|
120
|
+
*/
|
|
121
|
+
token?: string;
|
|
122
|
+
/**
|
|
123
|
+
* Custom HTTP request headers.
|
|
124
|
+
*/
|
|
125
|
+
headers?: Record<string, string>;
|
|
126
|
+
/**
|
|
127
|
+
* Polling interval in milliseconds for live change detection. Default: 5000.
|
|
128
|
+
*/
|
|
129
|
+
pollIntervalMs?: number;
|
|
130
|
+
}
|
|
72
131
|
export interface LocalLiteConfig {
|
|
73
132
|
/**
|
|
74
133
|
* Local SQLite Database instance, name, factory function, or LocalDBAdapter.
|
|
@@ -119,6 +178,11 @@ export interface LocalLiteConfig {
|
|
|
119
178
|
* Firebase / Firestore backend connection options.
|
|
120
179
|
*/
|
|
121
180
|
firebase?: FirebaseConfigOptions;
|
|
181
|
+
/**
|
|
182
|
+
* Self-hosted sync backend options (using endpoints created with createSyncEndpoint() in local-lite/server).
|
|
183
|
+
* Enables complete cloud-adapter independence and self-hosting data sovereignty.
|
|
184
|
+
*/
|
|
185
|
+
server?: SelfHostedServerConfigOptions;
|
|
122
186
|
/**
|
|
123
187
|
* Custom remote adapter (overrides Supabase / Convex / Firebase).
|
|
124
188
|
*/
|
|
@@ -211,4 +275,10 @@ export interface LocalLiteConfig {
|
|
|
211
275
|
*/
|
|
212
276
|
auth?: LocalAuthEngineOptions;
|
|
213
277
|
localAuth?: LocalAuthEngineOptions;
|
|
278
|
+
/**
|
|
279
|
+
* Direct email delivery configuration (Nodemailer SMTP, Resend, SendGrid, Postmark, or custom HTTP).
|
|
280
|
+
* When set, `local-lite` handles all offline-queued emails directly without needing Convex,
|
|
281
|
+
* Supabase, or any external database adapters.
|
|
282
|
+
*/
|
|
283
|
+
email?: EmailConfig;
|
|
214
284
|
}
|
|
@@ -125,7 +125,14 @@ function SyncInspector({ client, position = 'bottom-right', variant = 'pill', in
|
|
|
125
125
|
{ id: 'retry', label: '🔄 Retry Failed', onPress: handleRetryFailed, bg: currentTheme.actionBg, color: currentTheme.actionText },
|
|
126
126
|
{ id: 'reset', label: '⏪ Reset Cursor', onPress: handleResetCursor, bg: currentTheme.actionBg, color: currentTheme.actionText },
|
|
127
127
|
{ id: 'clear-outbox', label: 'Clear Stuck Outbox', onPress: handleClearOutbox, disabled: status.pendingCount === 0, bg: '#EF4444', color: '#FFFFFF' },
|
|
128
|
-
|
|
128
|
+
{
|
|
129
|
+
id: 'flush-actions',
|
|
130
|
+
label: '📨 Flush Actions & Email',
|
|
131
|
+
onPress: () => runAction('Flushing actions & email...', (res) => `Flushed: ${res?.completed ?? 0} sent, ${res?.failed ?? 0} failed`, () => client.actions.flush()),
|
|
132
|
+
bg: '#8B5CF6',
|
|
133
|
+
color: '#FFFFFF',
|
|
134
|
+
},
|
|
135
|
+
], [handlePush, handlePull, handleRetryFailed, handleResetCursor, handleClearOutbox, runAction, client, currentTheme.actionBg, currentTheme.actionText, status.pendingCount]);
|
|
129
136
|
const triggerLabel = variant === 'compact'
|
|
130
137
|
? status.pendingCount > 0
|
|
131
138
|
? `${status.pendingCount} queued`
|
|
@@ -181,7 +188,7 @@ function SyncInspector({ client, position = 'bottom-right', variant = 'pill', in
|
|
|
181
188
|
backgroundColor: currentTheme.card,
|
|
182
189
|
borderColor: currentTheme.border,
|
|
183
190
|
},
|
|
184
|
-
], children: [(0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.infoCardTitle, { color: currentTheme.textMuted }], children: "ENGINE ACTIONS" }), (0, jsx_runtime_1.jsx)(View, { style: rnStyles.btnRow, children: actionButtons.slice(0, 2).map((btn) => ((0, jsx_runtime_1.jsx)(TouchableOpacity, { onPress: btn.onPress, style: [rnStyles.actionBtn, { backgroundColor: btn.bg }], activeOpacity: 0.8, children: (0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.actionBtnText, { color: btn.color }], children: btn.label }) }, btn.id))) }), (0, jsx_runtime_1.jsx)(View, { style: [rnStyles.btnRow, { marginTop: 8 }], children: actionButtons.slice(2, 4).map((btn) => ((0, jsx_runtime_1.jsx)(TouchableOpacity, { onPress: btn.onPress, style: [rnStyles.actionBtn, { backgroundColor: btn.bg }, btn.disabled && { opacity: 0.5 }], disabled: btn.disabled, activeOpacity: 0.8, children: (0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.actionBtnText, { color: btn.color }], children: btn.label }) }, btn.id))) }), (0, jsx_runtime_1.jsx)(View, { style: [rnStyles.btnRow, { marginTop: 8 }], children: actionButtons.slice(4,
|
|
191
|
+
], children: [(0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.infoCardTitle, { color: currentTheme.textMuted }], children: "ENGINE ACTIONS" }), (0, jsx_runtime_1.jsx)(View, { style: rnStyles.btnRow, children: actionButtons.slice(0, 2).map((btn) => ((0, jsx_runtime_1.jsx)(TouchableOpacity, { onPress: btn.onPress, style: [rnStyles.actionBtn, { backgroundColor: btn.bg }], activeOpacity: 0.8, children: (0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.actionBtnText, { color: btn.color }], children: btn.label }) }, btn.id))) }), (0, jsx_runtime_1.jsx)(View, { style: [rnStyles.btnRow, { marginTop: 8 }], children: actionButtons.slice(2, 4).map((btn) => ((0, jsx_runtime_1.jsx)(TouchableOpacity, { onPress: btn.onPress, style: [rnStyles.actionBtn, { backgroundColor: btn.bg }, btn.disabled && { opacity: 0.5 }], disabled: btn.disabled, activeOpacity: 0.8, children: (0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.actionBtnText, { color: btn.color }], children: btn.label }) }, btn.id))) }), (0, jsx_runtime_1.jsx)(View, { style: [rnStyles.btnRow, { marginTop: 8 }], children: actionButtons.slice(4, 6).map((btn) => ((0, jsx_runtime_1.jsx)(TouchableOpacity, { onPress: btn.onPress, style: [rnStyles.actionBtn, { backgroundColor: btn.bg }, btn.disabled && { opacity: 0.5 }], disabled: btn.disabled, activeOpacity: 0.8, children: (0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.actionBtnText, { color: btn.color }], children: btn.label }) }, btn.id))) })] }), (metrics?.lastPushError || metrics?.lastPullError) && ((0, jsx_runtime_1.jsxs)(View, { style: [rnStyles.infoCard, { borderColor: '#EF444480', backgroundColor: '#7F1D1D20' }], children: [(0, jsx_runtime_1.jsx)(Text, { style: [rnStyles.infoCardTitle, { color: '#F87171' }], children: "SYNC ENGINE ERRORS" }), metrics?.lastPushError && ((0, jsx_runtime_1.jsxs)(View, { style: { marginBottom: 6 }, children: [(0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: '#FCA5A5', fontWeight: '700' }, children: "Last Push Error:" }), (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 12, color: '#FECACA' }, children: String(metrics.lastPushError) })] })), metrics?.lastPullError && ((0, jsx_runtime_1.jsxs)(View, { children: [(0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 11, color: '#FCA5A5', fontWeight: '700' }, children: "Last Pull Error:" }), (0, jsx_runtime_1.jsx)(Text, { style: { fontSize: 12, color: '#FECACA' }, children: String(metrics.lastPullError) })] }))] })), status.pendingRecords && status.pendingRecords.length > 0 && ((0, jsx_runtime_1.jsxs)(View, { style: [
|
|
185
192
|
rnStyles.infoCard,
|
|
186
193
|
{
|
|
187
194
|
backgroundColor: currentTheme.card,
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import type { Transporter, SendMailOptions, TransportOptions } from 'nodemailer';
|
|
2
|
+
import type { ActionHandlerContext, ActionRecord, EmailAttachment, EmailPayload } from '../actions/types.js';
|
|
3
|
+
export type EmailProviderType = 'nodemailer' | 'resend' | 'sendgrid' | 'postmark' | 'http' | 'dev' | 'preview' | 'custom';
|
|
4
|
+
export interface EmailHandlerOptions {
|
|
5
|
+
/**
|
|
6
|
+
* Default sender address (e.g. '"Support" <support@example.com>')
|
|
7
|
+
* used when an enqueued email does not specify `from`.
|
|
8
|
+
*/
|
|
9
|
+
defaultFrom?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Additional default options merged into every outgoing email.
|
|
12
|
+
*/
|
|
13
|
+
defaults?: Partial<SendMailOptions> & Record<string, any>;
|
|
14
|
+
/**
|
|
15
|
+
* Custom template renderer invoked when `template` or `templateData` is provided in EmailPayload.
|
|
16
|
+
*/
|
|
17
|
+
renderTemplate?: (template: any, data: Record<string, any> | undefined, payload: EmailPayload) => Promise<{
|
|
18
|
+
html?: string;
|
|
19
|
+
text?: string;
|
|
20
|
+
}> | {
|
|
21
|
+
html?: string;
|
|
22
|
+
text?: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Hook called before sending an email. Can inspect or modify outgoing options.
|
|
26
|
+
*/
|
|
27
|
+
beforeSend?: (mailOptions: any, payload: EmailPayload, record: ActionRecord<EmailPayload>) => Promise<any | void> | any | void;
|
|
28
|
+
/**
|
|
29
|
+
* Hook called after an email has been successfully dispatched.
|
|
30
|
+
*/
|
|
31
|
+
afterSend?: (result: any, payload: EmailPayload, record: ActionRecord<EmailPayload>) => Promise<void> | void;
|
|
32
|
+
}
|
|
33
|
+
export interface HttpEmailHandlerOptions extends EmailHandlerOptions {
|
|
34
|
+
provider?: 'resend' | 'sendgrid' | 'postmark' | 'http' | 'custom';
|
|
35
|
+
apiKey?: string;
|
|
36
|
+
endpoint?: string;
|
|
37
|
+
headers?: Record<string, string>;
|
|
38
|
+
fetch?: typeof fetch;
|
|
39
|
+
}
|
|
40
|
+
export interface EmailDeliveryConfig extends EmailHandlerOptions {
|
|
41
|
+
provider?: EmailProviderType;
|
|
42
|
+
/** Nodemailer transporter instance, connection URL, or transport options */
|
|
43
|
+
transport?: any;
|
|
44
|
+
/** API key for HTTP services (Resend, SendGrid, Postmark) */
|
|
45
|
+
apiKey?: string;
|
|
46
|
+
/** Target endpoint for generic HTTP or webhook dispatch */
|
|
47
|
+
endpoint?: string;
|
|
48
|
+
/** Custom HTTP request headers */
|
|
49
|
+
headers?: Record<string, string>;
|
|
50
|
+
/** Custom fetch implementation */
|
|
51
|
+
fetch?: typeof fetch;
|
|
52
|
+
/** Silent dev mode logging */
|
|
53
|
+
silentDev?: boolean;
|
|
54
|
+
}
|
|
55
|
+
export type NodemailerHandlerOptions = EmailHandlerOptions;
|
|
56
|
+
export type NodemailerTransportInput = Transporter | TransportOptions | string | any;
|
|
57
|
+
export interface EmailSendResult {
|
|
58
|
+
messageId: string;
|
|
59
|
+
response?: any;
|
|
60
|
+
accepted?: Array<string | any>;
|
|
61
|
+
rejected?: Array<string | any>;
|
|
62
|
+
[key: string]: any;
|
|
63
|
+
}
|
|
64
|
+
export type NodemailerSendResult = EmailSendResult;
|
|
65
|
+
export type ConcreteEmailHandler = (payload: EmailPayload, record: ActionRecord<EmailPayload>, context: ActionHandlerContext) => Promise<EmailSendResult>;
|
|
66
|
+
export interface DevSentEmail {
|
|
67
|
+
id: string;
|
|
68
|
+
sentAt: number;
|
|
69
|
+
mailOptions: SendMailOptions;
|
|
70
|
+
payload: EmailPayload;
|
|
71
|
+
record: ActionRecord<EmailPayload>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* In-memory Dev Mailbox for inspecting locally dispatched emails during development.
|
|
75
|
+
*/
|
|
76
|
+
export declare class DevMailbox {
|
|
77
|
+
private static inbox;
|
|
78
|
+
static getInbox(): DevSentEmail[];
|
|
79
|
+
static getLatest(): DevSentEmail | undefined;
|
|
80
|
+
static clear(): void;
|
|
81
|
+
static record(email: DevSentEmail): void;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Dynamically loads the nodemailer module if not already available.
|
|
85
|
+
*/
|
|
86
|
+
export declare function loadNodemailer(): Promise<any>;
|
|
87
|
+
/**
|
|
88
|
+
* Resolves or instantiates a Nodemailer Transporter instance.
|
|
89
|
+
*/
|
|
90
|
+
export declare function resolveTransporter(input: NodemailerTransportInput, defaults?: Partial<SendMailOptions>): Promise<Transporter>;
|
|
91
|
+
/**
|
|
92
|
+
* Renders a React element or JSX component into clean HTML and plaintext fallback.
|
|
93
|
+
*/
|
|
94
|
+
export declare function renderReactEmail(element: any): Promise<{
|
|
95
|
+
html: string;
|
|
96
|
+
text: string;
|
|
97
|
+
}>;
|
|
98
|
+
/**
|
|
99
|
+
* Hydrates an attachment from a mobile file:// URI or local file path if possible.
|
|
100
|
+
*/
|
|
101
|
+
export declare function hydrateAttachment(att: EmailAttachment): Promise<any>;
|
|
102
|
+
/**
|
|
103
|
+
* Maps an offline Local-Lite EmailPayload to standard email options.
|
|
104
|
+
*/
|
|
105
|
+
export declare function buildMailOptions(payload: EmailPayload, options?: EmailHandlerOptions): SendMailOptions;
|
|
106
|
+
/**
|
|
107
|
+
* Creates an EmailHandler for local-lite ActionManager that sends emails
|
|
108
|
+
* directly via Nodemailer (SMTP, Sendmail, SES, etc.).
|
|
109
|
+
*/
|
|
110
|
+
export declare function createNodemailerHandler(transporterOrOptions: NodemailerTransportInput, handlerOptions?: NodemailerHandlerOptions): ConcreteEmailHandler;
|
|
111
|
+
/**
|
|
112
|
+
* Creates an EmailHandler for local-lite ActionManager that dispatches emails
|
|
113
|
+
* via HTTP APIs (e.g. Resend, SendGrid, Postmark, or custom webhooks/endpoints).
|
|
114
|
+
*/
|
|
115
|
+
export declare function createHttpEmailHandler(options: HttpEmailHandlerOptions): ConcreteEmailHandler;
|
|
116
|
+
/**
|
|
117
|
+
* Creates a local dev email handler that stores outgoing emails in DevMailbox
|
|
118
|
+
* and logs an interactive terminal preview without sending real network requests.
|
|
119
|
+
*/
|
|
120
|
+
export declare function createDevEmailHandler(options?: EmailHandlerOptions & {
|
|
121
|
+
silent?: boolean;
|
|
122
|
+
}): ConcreteEmailHandler;
|
|
123
|
+
/**
|
|
124
|
+
* Universal email handler factory that creates a dispatch handler
|
|
125
|
+
* supporting Nodemailer (SMTP, Sendmail), HTTP providers (Resend, SendGrid, Postmark),
|
|
126
|
+
* local dev mailbox, or custom webhooks.
|
|
127
|
+
*/
|
|
128
|
+
export declare function createEmailHandler(config: EmailDeliveryConfig): ConcreteEmailHandler;
|