local-lite 0.2.6 → 1.0.0
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 +64 -0
- package/dist/adapters/remote/self-hosted.js +126 -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 +77 -0
- package/dist/server/sync.js +178 -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 +53 -1
- package/skills/local-lite-setup/SKILL.md +18 -5
- package/skills/local-lite-upgrade/SKILL.md +9 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MemoryServerSyncStorage = void 0;
|
|
4
|
+
exports.createSyncEndpoint = createSyncEndpoint;
|
|
5
|
+
/**
|
|
6
|
+
* In-memory server sync storage.
|
|
7
|
+
* Ideal for development, testing, serverless functions, or lightweight microservices.
|
|
8
|
+
*/
|
|
9
|
+
class MemoryServerSyncStorage {
|
|
10
|
+
tables = new Map();
|
|
11
|
+
changeLog = [];
|
|
12
|
+
monotonicCursor = 0;
|
|
13
|
+
async applyOperations(operations, overrideTime) {
|
|
14
|
+
const serverTime = overrideTime ?? Date.now();
|
|
15
|
+
let applied = 0;
|
|
16
|
+
const successfulIds = [];
|
|
17
|
+
for (const op of operations) {
|
|
18
|
+
if (!op.tableName || !op.rowId)
|
|
19
|
+
continue;
|
|
20
|
+
if (!this.tables.has(op.tableName)) {
|
|
21
|
+
this.tables.set(op.tableName, new Map());
|
|
22
|
+
}
|
|
23
|
+
const tableMap = this.tables.get(op.tableName);
|
|
24
|
+
const existing = tableMap.get(String(op.rowId));
|
|
25
|
+
const opTime = op.timestamp ?? serverTime;
|
|
26
|
+
// Last-Write-Wins: if existing record is newer than the operation, skip overwriting
|
|
27
|
+
if (existing && existing.timestamp > opTime) {
|
|
28
|
+
successfulIds.push(op.id);
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
this.monotonicCursor += 1;
|
|
32
|
+
const isDelete = op.operation === 'DELETE';
|
|
33
|
+
const recordPayload = isDelete
|
|
34
|
+
? { id: op.rowId, deleted: true }
|
|
35
|
+
: { ...(existing?.payload || {}), ...(op.payload || {}), id: op.rowId };
|
|
36
|
+
const record = {
|
|
37
|
+
rowId: String(op.rowId),
|
|
38
|
+
tableName: op.tableName,
|
|
39
|
+
payload: recordPayload,
|
|
40
|
+
timestamp: Math.max(opTime, serverTime),
|
|
41
|
+
operation: op.operation,
|
|
42
|
+
cursor: this.monotonicCursor,
|
|
43
|
+
};
|
|
44
|
+
tableMap.set(record.rowId, record);
|
|
45
|
+
this.changeLog.push(record);
|
|
46
|
+
applied += 1;
|
|
47
|
+
successfulIds.push(op.id);
|
|
48
|
+
}
|
|
49
|
+
return { applied, successfulIds, serverTime, cursor: this.monotonicCursor };
|
|
50
|
+
}
|
|
51
|
+
async getDeltas(tables, since, limit = 1000) {
|
|
52
|
+
const serverTime = Date.now();
|
|
53
|
+
// Filter log entries that belong to requested tables and happened strictly after `since`
|
|
54
|
+
const candidateEntries = this.changeLog.filter((entry) => (tables.length === 0 || tables.includes(entry.tableName)) &&
|
|
55
|
+
(entry.cursor > since || entry.timestamp > since));
|
|
56
|
+
const hasMore = candidateEntries.length > limit;
|
|
57
|
+
const paged = candidateEntries.slice(0, limit);
|
|
58
|
+
// Deduplicate by (tableName, rowId) to return the most recent delta for each row
|
|
59
|
+
const latestMap = new Map();
|
|
60
|
+
let maxCursor = since;
|
|
61
|
+
for (const entry of paged) {
|
|
62
|
+
const key = `${entry.tableName}:${entry.rowId}`;
|
|
63
|
+
latestMap.set(key, entry);
|
|
64
|
+
if (entry.cursor > maxCursor)
|
|
65
|
+
maxCursor = entry.cursor;
|
|
66
|
+
if (entry.timestamp > maxCursor)
|
|
67
|
+
maxCursor = entry.timestamp;
|
|
68
|
+
}
|
|
69
|
+
const deltaList = Array.from(latestMap.values()).map((entry) => ({
|
|
70
|
+
tableName: entry.tableName,
|
|
71
|
+
operation: entry.operation,
|
|
72
|
+
rowId: entry.rowId,
|
|
73
|
+
payload: entry.payload,
|
|
74
|
+
timestamp: entry.timestamp,
|
|
75
|
+
}));
|
|
76
|
+
return {
|
|
77
|
+
changes: {
|
|
78
|
+
timestamp: serverTime,
|
|
79
|
+
changes: deltaList,
|
|
80
|
+
},
|
|
81
|
+
cursor: maxCursor,
|
|
82
|
+
hasMore,
|
|
83
|
+
serverTime,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Resets all in-memory tables and logs.
|
|
88
|
+
*/
|
|
89
|
+
clear() {
|
|
90
|
+
this.tables.clear();
|
|
91
|
+
this.changeLog = [];
|
|
92
|
+
this.monotonicCursor = 0;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
exports.MemoryServerSyncStorage = MemoryServerSyncStorage;
|
|
96
|
+
/**
|
|
97
|
+
* Creates turnkey push and pull API endpoints for self-hosted multi-device data synchronization.
|
|
98
|
+
*/
|
|
99
|
+
function createSyncEndpoint(options = {}) {
|
|
100
|
+
const storage = options.storage || new MemoryServerSyncStorage();
|
|
101
|
+
const corsHeaders = {
|
|
102
|
+
'Access-Control-Allow-Origin': options.corsOrigin || '*',
|
|
103
|
+
'Access-Control-Allow-Methods': 'GET, POST, OPTIONS',
|
|
104
|
+
'Access-Control-Allow-Headers': 'Content-Type, Authorization, X-Sync-Secret',
|
|
105
|
+
};
|
|
106
|
+
const verifyAuth = (request) => {
|
|
107
|
+
if (!options.secret)
|
|
108
|
+
return true;
|
|
109
|
+
const authHeader = request.headers.get('authorization') || request.headers.get('x-sync-secret');
|
|
110
|
+
return authHeader === `Bearer ${options.secret}` || authHeader === options.secret;
|
|
111
|
+
};
|
|
112
|
+
// POST: Push batch of mutations (or combined push+pull batch)
|
|
113
|
+
const handlePost = async ({ request }) => {
|
|
114
|
+
if (!verifyAuth(request)) {
|
|
115
|
+
return Response.json({ error: 'Unauthorized: Invalid sync secret' }, { status: 401, headers: corsHeaders });
|
|
116
|
+
}
|
|
117
|
+
let body;
|
|
118
|
+
try {
|
|
119
|
+
body = await request.json();
|
|
120
|
+
}
|
|
121
|
+
catch {
|
|
122
|
+
return Response.json({ error: 'Bad Request: Invalid JSON body' }, { status: 400, headers: corsHeaders });
|
|
123
|
+
}
|
|
124
|
+
let operations = Array.isArray(body?.operations) ? body.operations : [];
|
|
125
|
+
if (options.onBeforePush) {
|
|
126
|
+
const modified = await options.onBeforePush(operations, request);
|
|
127
|
+
if (Array.isArray(modified))
|
|
128
|
+
operations = modified;
|
|
129
|
+
}
|
|
130
|
+
const pushResult = await storage.applyOperations(operations);
|
|
131
|
+
// If client requested a combined batch sync (push + pull in single roundtrip):
|
|
132
|
+
if (Array.isArray(body?.tables)) {
|
|
133
|
+
const since = Number(body.since ?? 0);
|
|
134
|
+
const pullResult = await storage.getDeltas(body.tables, since, body.limit ? Number(body.limit) : 500);
|
|
135
|
+
return Response.json({
|
|
136
|
+
success: true,
|
|
137
|
+
push: pushResult,
|
|
138
|
+
pull: pullResult,
|
|
139
|
+
}, { status: 200, headers: corsHeaders });
|
|
140
|
+
}
|
|
141
|
+
return Response.json({
|
|
142
|
+
success: true,
|
|
143
|
+
successfulIds: pushResult.successfulIds,
|
|
144
|
+
processed: pushResult.applied,
|
|
145
|
+
serverTime: pushResult.serverTime,
|
|
146
|
+
cursor: pushResult.cursor,
|
|
147
|
+
}, { status: 200, headers: corsHeaders });
|
|
148
|
+
};
|
|
149
|
+
// GET: Pull deltas since cursor/timestamp
|
|
150
|
+
const handleGet = async ({ request }) => {
|
|
151
|
+
if (!verifyAuth(request)) {
|
|
152
|
+
return Response.json({ error: 'Unauthorized: Invalid sync secret' }, { status: 401, headers: corsHeaders });
|
|
153
|
+
}
|
|
154
|
+
const url = new URL(request.url);
|
|
155
|
+
const tablesParam = url.searchParams.get('tables');
|
|
156
|
+
const sinceParam = url.searchParams.get('since');
|
|
157
|
+
const limitParam = url.searchParams.get('limit');
|
|
158
|
+
const tables = tablesParam ? tablesParam.split(',').map((t) => t.trim()).filter(Boolean) : [];
|
|
159
|
+
const since = sinceParam ? Number(sinceParam) : 0;
|
|
160
|
+
const limit = limitParam ? Number(limitParam) : 500;
|
|
161
|
+
const result = await storage.getDeltas(tables, since, limit);
|
|
162
|
+
return Response.json({
|
|
163
|
+
success: true,
|
|
164
|
+
changes: result.changes,
|
|
165
|
+
cursor: result.cursor,
|
|
166
|
+
hasMore: result.hasMore,
|
|
167
|
+
serverTime: result.serverTime,
|
|
168
|
+
}, { status: 200, headers: corsHeaders });
|
|
169
|
+
};
|
|
170
|
+
const handleOptions = async () => {
|
|
171
|
+
return new Response(null, { status: 204, headers: corsHeaders });
|
|
172
|
+
};
|
|
173
|
+
return {
|
|
174
|
+
POST: handlePost,
|
|
175
|
+
GET: handleGet,
|
|
176
|
+
OPTIONS: handleOptions,
|
|
177
|
+
};
|
|
178
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "local-lite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Never let a lost connection break a promise. Local-first sync that faithfully keeps data safe until you're back online.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -150,6 +150,11 @@
|
|
|
150
150
|
"types": "./dist/scheduler/index.d.ts",
|
|
151
151
|
"import": "./dist/scheduler/index.js",
|
|
152
152
|
"default": "./dist/scheduler/index.js"
|
|
153
|
+
},
|
|
154
|
+
"./email": {
|
|
155
|
+
"types": "./dist/email/index.d.ts",
|
|
156
|
+
"import": "./dist/email/index.js",
|
|
157
|
+
"default": "./dist/email/index.js"
|
|
153
158
|
}
|
|
154
159
|
},
|
|
155
160
|
"scripts": {
|
|
@@ -168,10 +173,14 @@
|
|
|
168
173
|
"expo-file-system": ">=58.0.0",
|
|
169
174
|
"expo-sqlite": ">=58.0.0",
|
|
170
175
|
"firebase": ">=9.0.0",
|
|
176
|
+
"nodemailer": ">=6.9.0",
|
|
171
177
|
"react": ">=18.0.0",
|
|
172
178
|
"sql.js": "^1.8.0"
|
|
173
179
|
},
|
|
174
180
|
"peerDependenciesMeta": {
|
|
181
|
+
"nodemailer": {
|
|
182
|
+
"optional": true
|
|
183
|
+
},
|
|
175
184
|
"react": {
|
|
176
185
|
"optional": true
|
|
177
186
|
},
|
|
@@ -206,9 +215,11 @@
|
|
|
206
215
|
"devDependencies": {
|
|
207
216
|
"@supabase/supabase-js": "^2.118.0",
|
|
208
217
|
"@types/node": "^26.6.5",
|
|
218
|
+
"@types/nodemailer": "^8.0.2",
|
|
209
219
|
"@types/react": "^19.3.0",
|
|
210
220
|
"@types/uuid": "^11.0.0",
|
|
211
221
|
"expo-sqlite": "^58.0.14",
|
|
222
|
+
"nodemailer": "^10.5.0",
|
|
212
223
|
"react": "^19.3.1",
|
|
213
224
|
"typescript": "^7.0.2",
|
|
214
225
|
"vitest": "^5.0.5"
|
|
@@ -21,6 +21,9 @@ Implement `RemoteDBAdapter` (exported from `local-lite`, with `SyncOperation`, `
|
|
|
21
21
|
- `scope` may be an object or a (possibly async) function. If setup is async, guard against cleanup running before setup finishes (generation counter or cancelled flag) so listeners do not leak.
|
|
22
22
|
- `setSyncScope?(scope)`: optional; implement it if the backend filters by scope, and re-subscribe live listeners when scope changes.
|
|
23
23
|
|
|
24
|
+
> [!TIP]
|
|
25
|
+
> **Built-in Self-Hosted Adapter**: Before writing a custom adapter from scratch, consider using `SelfHostedRemoteAdapter` (or `server: { url, token }` in `defineSyncConfig`) paired with `createSyncEndpoint()` from `local-lite/server`. It implements an idempotent push/pull sync protocol out-of-the-box.
|
|
26
|
+
|
|
24
27
|
## Skeleton
|
|
25
28
|
|
|
26
29
|
```typescript
|
|
@@ -13,45 +13,86 @@ Guide for executing queued actions, running background jobs, persisting key-valu
|
|
|
13
13
|
|
|
14
14
|
The Action Manager handles complex business logic mutations that must be queued offline and executed reliably when connectivity is restored:
|
|
15
15
|
|
|
16
|
-
###
|
|
17
|
-
|
|
18
|
-
import { getSyncClient } from './sync.config';
|
|
19
|
-
|
|
20
|
-
const client = await getSyncClient();
|
|
16
|
+
### Type-Safe Action Contracts (`defineAction`)
|
|
17
|
+
Validate payloads before writing to SQLite using runtime schema validators (custom predicates or Zod/TypeBox schemas):
|
|
21
18
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
19
|
+
```typescript
|
|
20
|
+
// Define action with runtime schema validation
|
|
21
|
+
client.actions.defineAction({
|
|
22
|
+
name: 'PROCESS_PAYMENT',
|
|
23
|
+
schema: (payload: any) => {
|
|
24
|
+
if (!payload.amount || payload.amount <= 0) throw new Error('Positive amount required');
|
|
25
|
+
if (!payload.currency) throw new Error('Currency required');
|
|
26
|
+
return payload;
|
|
27
|
+
},
|
|
28
|
+
handler: async (action, context) => {
|
|
29
|
+
const res = await fetch('https://api.stripe.com/v1/payment_intents', {
|
|
30
|
+
method: 'POST',
|
|
31
|
+
body: JSON.stringify(action.payload),
|
|
32
|
+
});
|
|
33
|
+
return await res.json();
|
|
28
34
|
},
|
|
29
|
-
maxRetries: 5,
|
|
30
|
-
retryDelayMs: 2000,
|
|
31
35
|
});
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Rate Limiting & Concurrency Control
|
|
39
|
+
Configure worker concurrency and token-bucket rate limiting to avoid tripping downstream API rate limits:
|
|
32
40
|
|
|
33
|
-
|
|
41
|
+
```typescript
|
|
42
|
+
const client = await createSyncClient({
|
|
43
|
+
database: 'app.db',
|
|
44
|
+
// Concurrency & rate-limiting for action outbox
|
|
45
|
+
// ActionManager options can be configured directly or on client actions
|
|
46
|
+
});
|
|
34
47
|
```
|
|
35
48
|
|
|
36
|
-
###
|
|
37
|
-
|
|
49
|
+
### Inbuilt Offline Email Queue (`client.actions.sendEmail`)
|
|
50
|
+
Enqueue transactional emails with 0ms local write latency:
|
|
38
51
|
|
|
39
52
|
```typescript
|
|
40
|
-
client.actions.
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return await res.json();
|
|
53
|
+
const emailAction = await client.actions.sendEmail({
|
|
54
|
+
to: 'user@example.com',
|
|
55
|
+
subject: 'Order #{{orderId}} Confirmed',
|
|
56
|
+
html: '<h2>Thanks {{name}}!</h2>',
|
|
57
|
+
templateData: { name: 'Alice', orderId: 1042 },
|
|
58
|
+
idempotencyKey: 'order_1042',
|
|
59
|
+
attachments: [
|
|
60
|
+
{ filename: 'receipt.pdf', url: 'file:///data/user/0/receipt.pdf' } // Auto-hydrates mobile file:// URIs
|
|
61
|
+
],
|
|
62
|
+
react: <ReceiptEmail orderId={1042} />, // Optional React Email JSX rendering
|
|
52
63
|
});
|
|
53
64
|
```
|
|
54
65
|
|
|
66
|
+
### Unified Email Providers (`local-lite/email`)
|
|
67
|
+
Dispatch via Nodemailer SMTP, HTTP APIs (Resend, SendGrid, Postmark), or In-Memory Dev Mode:
|
|
68
|
+
|
|
69
|
+
```typescript
|
|
70
|
+
import { createEmailHandler, DevMailbox } from 'local-lite/email';
|
|
71
|
+
|
|
72
|
+
// 1. In-Memory Dev Mode (no external credentials needed in development)
|
|
73
|
+
client.actions.registerEmailHandler(
|
|
74
|
+
createEmailHandler({ provider: 'dev' })
|
|
75
|
+
);
|
|
76
|
+
console.log('Dev Mailbox:', DevMailbox.getInbox());
|
|
77
|
+
|
|
78
|
+
// 2. Nodemailer SMTP
|
|
79
|
+
client.actions.registerEmailHandler(
|
|
80
|
+
createEmailHandler({
|
|
81
|
+
transport: { host: 'smtp.mailgun.org', port: 587, auth: { user: '...', pass: '...' } },
|
|
82
|
+
defaultFrom: '"Support" <support@myapp.com>',
|
|
83
|
+
})
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// 3. HTTP Provider (Resend, SendGrid, Postmark)
|
|
87
|
+
client.actions.registerEmailHandler(
|
|
88
|
+
createEmailHandler({
|
|
89
|
+
provider: 'resend',
|
|
90
|
+
apiKey: process.env.RESEND_API_KEY,
|
|
91
|
+
defaultFrom: 'onboarding@resend.dev',
|
|
92
|
+
})
|
|
93
|
+
);
|
|
94
|
+
```
|
|
95
|
+
|
|
55
96
|
---
|
|
56
97
|
|
|
57
98
|
## 2. Key-Value Store & Secret Preferences (`client.kv`)
|
|
@@ -122,3 +122,20 @@ export function SettingsScreen({ client }) {
|
|
|
122
122
|
2. **Selective Column Projections**: In high-frequency queries, select only required columns (`SELECT id, title FROM ...`) instead of `SELECT *` to reduce SQLite serialization overhead.
|
|
123
123
|
3. **Batch Mutations**: Wrap bulk inserts in transactions or `client.mutateBatch()` rather than issuing individual `INSERT` statements in loops.
|
|
124
124
|
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
## 6. DevTools & Debugging (`<SyncInspector />`)
|
|
128
|
+
|
|
129
|
+
Inspect database tables, live outbox operations, and trigger one-tap manual flushes of mutations and queued emails using the developer widget:
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
import { SyncInspector } from 'local-lite/devtools';
|
|
133
|
+
|
|
134
|
+
export function DevOverlay({ client }) {
|
|
135
|
+
if (__DEV__) {
|
|
136
|
+
return <SyncInspector client={client} position="bottom-right" defaultOpen={false} />;
|
|
137
|
+
}
|
|
138
|
+
return null;
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: local-lite-server
|
|
3
|
-
description: Configure and implement framework-neutral REST API routing and
|
|
3
|
+
description: Configure and implement framework-neutral REST API routing, turnkey self-hosted sync endpoints, and email dispatch endpoints with local-lite/server. Use when setting up server endpoints (defineServerConfig, createServer, createSyncEndpoint, createEmailEndpoint), declaring route parameters, implementing middleware pipelines, managing HTTP methods (GET, POST, PUT, DELETE, OPTIONS), 405 Method Not Allowed handling, or dispatching single fetch() requests in Edge, Node, Next.js, or Expo Router API routes.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# local-lite Server API Routing
|
|
@@ -125,3 +125,55 @@ export default {
|
|
|
125
125
|
* **Not Found (404)**: Unmatched paths return a standardized `{ error: 'Not Found' }` with status `404`.
|
|
126
126
|
* **Safe Error Handling (500)**: Unhandled errors in middleware or endpoints trigger `onError` server-side and return `{ error: 'Internal Server Error' }` without exposing internal implementation details.
|
|
127
127
|
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## 6. Turnkey Self-Hosted Sync Endpoint (`createSyncEndpoint`)
|
|
131
|
+
|
|
132
|
+
Zero-boilerplate multi-device synchronization endpoint replacing third-party backends (Supabase, Convex, Firebase):
|
|
133
|
+
|
|
134
|
+
```typescript
|
|
135
|
+
import { defineServerConfig, createServer, createSyncEndpoint, MemoryServerSyncStorage } from 'local-lite/server';
|
|
136
|
+
|
|
137
|
+
export const apiServer = createServer(
|
|
138
|
+
defineServerConfig({
|
|
139
|
+
config: {},
|
|
140
|
+
endpoints: {
|
|
141
|
+
// Mount turnkey sync endpoint (POST for push/batch, GET for pull)
|
|
142
|
+
'/api/sync': createSyncEndpoint({
|
|
143
|
+
secret: process.env.SYNC_SECRET_TOKEN,
|
|
144
|
+
storage: new MemoryServerSyncStorage(), // Or persistent database storage
|
|
145
|
+
}),
|
|
146
|
+
},
|
|
147
|
+
})
|
|
148
|
+
);
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Clients connect to this simply by setting `server: { url: 'https://api.domain.com/api/sync', token: '...' }` in `defineSyncConfig`.
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## 7. Turnkey Email Relay Endpoint (`createEmailEndpoint`)
|
|
156
|
+
|
|
157
|
+
Mount a pre-built email endpoint that receives offline-queued emails from mobile/Expo apps and sends them via Nodemailer or cloud providers:
|
|
158
|
+
|
|
159
|
+
```typescript
|
|
160
|
+
import { createServer, defineServerConfig, createEmailEndpoint } from 'local-lite/server';
|
|
161
|
+
|
|
162
|
+
export const apiServer = createServer(
|
|
163
|
+
defineServerConfig({
|
|
164
|
+
config: {},
|
|
165
|
+
endpoints: {
|
|
166
|
+
'/api/send-email': createEmailEndpoint({
|
|
167
|
+
secret: process.env.EMAIL_API_SECRET,
|
|
168
|
+
transport: {
|
|
169
|
+
host: 'smtp.mailgun.org',
|
|
170
|
+
port: 587,
|
|
171
|
+
auth: { user: process.env.SMTP_USER, pass: process.env.SMTP_PASS },
|
|
172
|
+
},
|
|
173
|
+
defaultFrom: '"My App" <noreply@myapp.com>',
|
|
174
|
+
}),
|
|
175
|
+
},
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
```
|
|
179
|
+
|
|
@@ -121,13 +121,26 @@ export const syncConfig = defineSyncConfig({
|
|
|
121
121
|
},
|
|
122
122
|
|
|
123
123
|
// 7. Remote Backend (choose one or omit for local-only)
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
url:
|
|
127
|
-
|
|
124
|
+
// Option A: Turnkey Self-Hosted Server (Zero cloud dependencies)
|
|
125
|
+
server: {
|
|
126
|
+
url: 'https://api.mydomain.com/api/sync',
|
|
127
|
+
token: process.env.EXPO_PUBLIC_SYNC_SECRET,
|
|
128
|
+
},
|
|
129
|
+
// Option B: Supabase
|
|
130
|
+
// supabase: { url: process.env.EXPO_PUBLIC_SUPABASE_URL!, anonKey: process.env.EXPO_PUBLIC_SUPABASE_ANON_KEY! },
|
|
131
|
+
// Option C: Convex
|
|
132
|
+
// convex: { client: convexClient },
|
|
133
|
+
// Option D: Pure Local-Only
|
|
134
|
+
// localOnly: true,
|
|
135
|
+
|
|
136
|
+
// 8. Offline Email Delivery Configuration
|
|
137
|
+
email: {
|
|
138
|
+
provider: 'resend', // 'nodemailer' | 'resend' | 'sendgrid' | 'postmark' | 'dev'
|
|
139
|
+
apiKey: process.env.EXPO_PUBLIC_RESEND_API_KEY,
|
|
140
|
+
defaults: { from: 'Support <support@mydomain.com>' },
|
|
128
141
|
},
|
|
129
142
|
|
|
130
|
-
//
|
|
143
|
+
// 9. Sync tuning
|
|
131
144
|
pushIntervalMs: 500,
|
|
132
145
|
pullIntervalMs: 5000,
|
|
133
146
|
conflictResolver: 'last-write-wins',
|
|
@@ -35,6 +35,15 @@ Search the codebase for each affected pattern and apply the migration:
|
|
|
35
35
|
* **Old**: Injecting `fileSystem` via legacy `expo-file-system`.
|
|
36
36
|
* **New**: Uses standard Expo SDK 58+ `File`, `Directory`, and `Paths` APIs. Remove legacy `fileSystem` option.
|
|
37
37
|
|
|
38
|
+
### Email Module Imports (`local-lite/nodemailer` ➔ `local-lite/email`)
|
|
39
|
+
* **Old**: `import { ... } from 'local-lite/nodemailer'`
|
|
40
|
+
* **New**: `import { ... } from 'local-lite/email'`
|
|
41
|
+
* **Action**: Update imports to the unified email module supporting Nodemailer, Resend, SendGrid, Postmark, and Dev Mailbox.
|
|
42
|
+
|
|
43
|
+
### Self-Hosted Sync
|
|
44
|
+
* **Old**: Requiring Supabase or Convex for multi-client synchronization.
|
|
45
|
+
* **New**: Use `defineSyncConfig({ server: { url: 'https://api.yourdomain.com/sync', token: '...' } })` with turnkey `createSyncEndpoint()` from `local-lite/server`.
|
|
46
|
+
|
|
38
47
|
---
|
|
39
48
|
|
|
40
49
|
## 2. Review Workflow
|