local-lite 1.0.3 → 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 CHANGED
@@ -361,9 +361,10 @@ const emailAction = await client.actions.sendEmail({
361
361
 
362
362
  // ⚡ 2. Direct email dispatch (Nodemailer SMTP, Resend, SendGrid, Postmark, or HTTP webhook)
363
363
  import { createEmailHandler } from 'local-lite/email';
364
+ import { createNodemailerHandler } from 'local-lite/server';
364
365
 
365
- // Nodemailer transport:
366
- client.actions.registerEmailHandler(createEmailHandler({
366
+ // Nodemailer transport (server only):
367
+ client.actions.registerEmailHandler(createNodemailerHandler({
367
368
  transport: { host: 'smtp.example.com', port: 587, auth: { user: '...', pass: '...' } },
368
369
  defaultFrom: 'Support <support@mycompany.com>',
369
370
  }));
@@ -371,7 +372,7 @@ client.actions.registerEmailHandler(createEmailHandler({
371
372
  // Or HTTP provider (e.g., Resend):
372
373
  // client.actions.registerEmailHandler(createEmailHandler({ provider: 'resend', apiKey: '...' }));
373
374
 
374
- // Or configure directly in defineSyncConfig({ email: { transport: { ... } } })!
375
+ // HTTP providers can be configured directly in defineSyncConfig.
375
376
 
376
377
  // ⚡ 3. Enqueue arbitrary asynchronous actions (e.g., push notifications, analytics)
377
378
  await client.actions.enqueue({
@@ -105,6 +105,9 @@ async function createSyncClient(config) {
105
105
  }
106
106
  // 6. Direct Email Dispatch (Nodemailer, Resend, SendGrid, Postmark, HTTP, etc.)
107
107
  if (config.email) {
108
+ if (config.email.transport || config.email.provider === 'nodemailer') {
109
+ throw new Error("Nodemailer email delivery is server-only. Import 'local-lite/server' and register createNodemailerHandler from your server runtime.");
110
+ }
108
111
  const { createEmailHandler } = await import('../email/index.js');
109
112
  const emailHandler = createEmailHandler({
110
113
  provider: config.email.provider,
@@ -1,4 +1,3 @@
1
- import type { Transporter, SendMailOptions, TransportOptions } from 'nodemailer';
2
1
  import type { ActionHandlerContext, ActionRecord, EmailAttachment, EmailPayload } from '../actions/types.js';
3
2
  export type EmailProviderType = 'nodemailer' | 'resend' | 'sendgrid' | 'postmark' | 'http' | 'dev' | 'preview' | 'custom';
4
3
  export interface EmailHandlerOptions {
@@ -10,7 +9,7 @@ export interface EmailHandlerOptions {
10
9
  /**
11
10
  * Additional default options merged into every outgoing email.
12
11
  */
13
- defaults?: Partial<SendMailOptions> & Record<string, any>;
12
+ defaults?: Partial<EmailMailOptions> & Record<string, any>;
14
13
  /**
15
14
  * Custom template renderer invoked when `template` or `templateData` is provided in EmailPayload.
16
15
  */
@@ -53,7 +52,19 @@ export interface EmailDeliveryConfig extends EmailHandlerOptions {
53
52
  silentDev?: boolean;
54
53
  }
55
54
  export type NodemailerHandlerOptions = EmailHandlerOptions;
56
- export type NodemailerTransportInput = Transporter | TransportOptions | string | any;
55
+ export interface EmailMailOptions {
56
+ to?: any;
57
+ from?: any;
58
+ subject?: string;
59
+ text?: string;
60
+ html?: string;
61
+ cc?: any;
62
+ bcc?: any;
63
+ replyTo?: any;
64
+ headers?: Record<string, any>;
65
+ attachments?: any[];
66
+ [key: string]: any;
67
+ }
57
68
  export interface EmailSendResult {
58
69
  messageId: string;
59
70
  response?: any;
@@ -66,7 +77,7 @@ export type ConcreteEmailHandler = (payload: EmailPayload, record: ActionRecord<
66
77
  export interface DevSentEmail {
67
78
  id: string;
68
79
  sentAt: number;
69
- mailOptions: SendMailOptions;
80
+ mailOptions: EmailMailOptions;
70
81
  payload: EmailPayload;
71
82
  record: ActionRecord<EmailPayload>;
72
83
  }
@@ -80,14 +91,6 @@ export declare class DevMailbox {
80
91
  static clear(): void;
81
92
  static record(email: DevSentEmail): void;
82
93
  }
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
94
  /**
92
95
  * Renders a React element or JSX component into clean HTML and plaintext fallback.
93
96
  */
@@ -102,12 +105,8 @@ export declare function hydrateAttachment(att: EmailAttachment): Promise<any>;
102
105
  /**
103
106
  * Maps an offline Local-Lite EmailPayload to standard email options.
104
107
  */
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;
108
+ export declare function buildMailOptions(payload: EmailPayload, options?: EmailHandlerOptions): EmailMailOptions;
109
+ export declare function prepareMailOptions(payload: EmailPayload, options: EmailHandlerOptions, record: ActionRecord<EmailPayload>): Promise<EmailMailOptions>;
111
110
  /**
112
111
  * Creates an EmailHandler for local-lite ActionManager that dispatches emails
113
112
  * via HTTP APIs (e.g. Resend, SendGrid, Postmark, or custom webhooks/endpoints).
@@ -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.createNodemailerHandler = createNodemailerHandler;
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];
@@ -216,36 +192,6 @@ async function prepareMailOptions(payload, options, record) {
216
192
  }
217
193
  return mailOptions;
218
194
  }
219
- /**
220
- * Creates an EmailHandler for local-lite ActionManager that sends emails
221
- * directly via Nodemailer (SMTP, Sendmail, SES, etc.).
222
- */
223
- function createNodemailerHandler(transporterOrOptions, handlerOptions = {}) {
224
- let cachedTransporter = transporterOrOptions &&
225
- typeof transporterOrOptions.sendMail === 'function'
226
- ? transporterOrOptions
227
- : null;
228
- const getTransporter = async () => {
229
- if (!cachedTransporter) {
230
- cachedTransporter = await resolveTransporter(transporterOrOptions, handlerOptions.defaults);
231
- }
232
- return cachedTransporter;
233
- };
234
- return async (payload, record, _context) => {
235
- const transporter = await getTransporter();
236
- const mailOptions = await prepareMailOptions(payload, handlerOptions, record);
237
- const info = await transporter.sendMail(mailOptions);
238
- if (handlerOptions.afterSend) {
239
- await handlerOptions.afterSend(info, payload, record);
240
- }
241
- return {
242
- messageId: info.messageId,
243
- response: info.response,
244
- accepted: info.accepted,
245
- rejected: info.rejected,
246
- };
247
- };
248
- }
249
195
  /**
250
196
  * Creates an EmailHandler for local-lite ActionManager that dispatches emails
251
197
  * via HTTP APIs (e.g. Resend, SendGrid, Postmark, or custom webhooks/endpoints).
@@ -440,7 +386,7 @@ function createEmailHandler(config) {
440
386
  return createDevEmailHandler({ ...config, silent: config.silentDev });
441
387
  }
442
388
  if (config.transport || config.provider === 'nodemailer') {
443
- return createNodemailerHandler(config.transport || config, config);
389
+ throw new Error("Nodemailer email delivery is server-only. Import 'local-lite/server' for SMTP delivery.");
444
390
  }
445
391
  if (config.provider === 'resend' ||
446
392
  config.provider === 'sendgrid' ||
@@ -1,4 +1,12 @@
1
1
  import type { ApiEndpoint } from './index.js';
2
+ import { type ConcreteEmailHandler, type EmailHandlerOptions, type EmailMailOptions } from '../email/index.js';
3
+ export type NodemailerTransportInput = {
4
+ sendMail?: (options: EmailMailOptions) => Promise<any>;
5
+ [key: string]: any;
6
+ } | string;
7
+ export declare function loadNodemailer(): Promise<any>;
8
+ export declare function resolveTransporter(input: NodemailerTransportInput, defaults?: Partial<EmailMailOptions>): Promise<any>;
9
+ export declare function createNodemailerHandler(transporterOrOptions: NodemailerTransportInput, handlerOptions?: EmailHandlerOptions): ConcreteEmailHandler;
2
10
  export interface EmailEndpointOptions {
3
11
  /**
4
12
  * Secret token required in `Authorization: Bearer <secret>` or `x-app-secret` header.
@@ -1,6 +1,51 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.loadNodemailer = loadNodemailer;
4
+ exports.resolveTransporter = resolveTransporter;
5
+ exports.createNodemailerHandler = createNodemailerHandler;
3
6
  exports.createEmailEndpoint = createEmailEndpoint;
7
+ const index_js_1 = require("../email/index.js");
8
+ async function loadNodemailer() {
9
+ try {
10
+ const mod = await import('nodemailer');
11
+ return mod.default || mod;
12
+ }
13
+ catch {
14
+ throw new Error("The 'nodemailer' package is required to send emails via Nodemailer transport. Please install it via 'npm install nodemailer'.");
15
+ }
16
+ }
17
+ async function resolveTransporter(input, defaults) {
18
+ if (input && typeof input !== 'string' && typeof input.sendMail === 'function') {
19
+ return input;
20
+ }
21
+ const nodemailer = await loadNodemailer();
22
+ return nodemailer.createTransport(input, defaults);
23
+ }
24
+ function createNodemailerHandler(transporterOrOptions, handlerOptions = {}) {
25
+ let cachedTransporter = transporterOrOptions &&
26
+ typeof transporterOrOptions !== 'string' &&
27
+ typeof transporterOrOptions.sendMail === 'function'
28
+ ? transporterOrOptions
29
+ : null;
30
+ const getTransporter = async () => {
31
+ if (!cachedTransporter) {
32
+ cachedTransporter = await resolveTransporter(transporterOrOptions, handlerOptions.defaults);
33
+ }
34
+ return cachedTransporter;
35
+ };
36
+ return async (payload, record, _context) => {
37
+ const transporter = await getTransporter();
38
+ const mailOptions = await (0, index_js_1.prepareMailOptions)(payload, handlerOptions, record);
39
+ const info = await transporter.sendMail(mailOptions);
40
+ await handlerOptions.afterSend?.(info, payload, record);
41
+ return {
42
+ messageId: info.messageId,
43
+ response: info.response,
44
+ accepted: info.accepted,
45
+ rejected: info.rejected,
46
+ };
47
+ };
48
+ }
4
49
  /**
5
50
  * Creates a turnkey Request/Response API endpoint for receiving offline-enqueued emails
6
51
  * from local-lite clients and dispatching them via Nodemailer or cloud providers.
@@ -47,7 +92,6 @@ function createEmailEndpoint(options = {}) {
47
92
  result = await options.dispatch(payload, request);
48
93
  }
49
94
  else if (options.transport || (!options.provider && !options.apiKey)) {
50
- const { createNodemailerHandler } = await import('../email/index.js');
51
95
  const handler = createNodemailerHandler(options.transport || {}, {
52
96
  defaultFrom: options.defaultFrom,
53
97
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "local-lite",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
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",