lazypock 0.19.2 → 0.20.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 +17 -0
- package/dist/index.cjs +155 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +186 -2
- package/dist/index.d.ts +186 -2
- package/dist/index.global.js +154 -0
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +154 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/http.ts +16 -0
- package/src/index.ts +12 -0
- package/src/lazypock.ts +27 -0
- package/src/mail.ts +290 -0
- package/src/types.ts +1 -1
package/dist/index.js
CHANGED
|
@@ -354,6 +354,17 @@ var HttpClient = class {
|
|
|
354
354
|
post(path, body, options) {
|
|
355
355
|
return this.request("POST", path, body, options);
|
|
356
356
|
}
|
|
357
|
+
/**
|
|
358
|
+
* HTTP PUT — a full replacement. Used where the server models a resource as a
|
|
359
|
+
* complete unit rather than a set of patches (e.g. a mail template, which only
|
|
360
|
+
* exists once all three of its parts do).
|
|
361
|
+
* @param path URL path.
|
|
362
|
+
* @param body Request body.
|
|
363
|
+
* @param options Optional request options.
|
|
364
|
+
*/
|
|
365
|
+
put(path, body, options) {
|
|
366
|
+
return this.request("PUT", path, body, options);
|
|
367
|
+
}
|
|
357
368
|
/**
|
|
358
369
|
* HTTP PATCH.
|
|
359
370
|
* @param path URL path.
|
|
@@ -2425,6 +2436,147 @@ function normalizeAction2(event) {
|
|
|
2425
2436
|
return "update";
|
|
2426
2437
|
}
|
|
2427
2438
|
|
|
2439
|
+
// src/mail.ts
|
|
2440
|
+
function templatePath(name) {
|
|
2441
|
+
return "/mail/templates/" + encodeURIComponent(name.trim());
|
|
2442
|
+
}
|
|
2443
|
+
var MailService = class {
|
|
2444
|
+
constructor(http) {
|
|
2445
|
+
this.http = http;
|
|
2446
|
+
}
|
|
2447
|
+
/**
|
|
2448
|
+
* Queue one message for delivery.
|
|
2449
|
+
*
|
|
2450
|
+
* Either a `template` or a `subject` with a body. The type requires one of
|
|
2451
|
+
* them — a message with neither does not compile — while the server refuses a
|
|
2452
|
+
* message that carries both, and a template with a raw body.
|
|
2453
|
+
*
|
|
2454
|
+
* The address is shape-checked server-side; the SMTP server remains the
|
|
2455
|
+
* authority on whether it exists.
|
|
2456
|
+
*
|
|
2457
|
+
* @param message The template or raw message to send.
|
|
2458
|
+
* @param options Optional request options (signal, custom fetch).
|
|
2459
|
+
* @returns The queued job (`{ queued: true, id }`).
|
|
2460
|
+
*
|
|
2461
|
+
* @example
|
|
2462
|
+
* ```ts
|
|
2463
|
+
* // A template
|
|
2464
|
+
* await client.mail.send({ to: 'ada@example.com', template: 'receipt', assigns: { total: 42 } });
|
|
2465
|
+
*
|
|
2466
|
+
* // A raw message
|
|
2467
|
+
* await client.mail.send({ to: 'ada@example.com', subject: 'Hello', text: 'Hi there' });
|
|
2468
|
+
* ```
|
|
2469
|
+
*/
|
|
2470
|
+
async send(message, options) {
|
|
2471
|
+
const body = "template" in message ? {
|
|
2472
|
+
to: message.to,
|
|
2473
|
+
toName: message.toName,
|
|
2474
|
+
template: message.template,
|
|
2475
|
+
assigns: message.assigns
|
|
2476
|
+
} : {
|
|
2477
|
+
to: message.to,
|
|
2478
|
+
toName: message.toName,
|
|
2479
|
+
subject: message.subject,
|
|
2480
|
+
html: message.html,
|
|
2481
|
+
text: message.text
|
|
2482
|
+
};
|
|
2483
|
+
const data = await this.http.request("POST", "/mail", body, options);
|
|
2484
|
+
return data ?? { queued: false, id: "" };
|
|
2485
|
+
}
|
|
2486
|
+
/**
|
|
2487
|
+
* List every template the server can send, with the body each part
|
|
2488
|
+
* currently resolves to and the layer it came from (superuser).
|
|
2489
|
+
*
|
|
2490
|
+
* Unpaginated: there are as many templates as the deployment defined, not
|
|
2491
|
+
* as many as it has sent.
|
|
2492
|
+
*/
|
|
2493
|
+
async listTemplates(options) {
|
|
2494
|
+
const data = await this.http.request(
|
|
2495
|
+
"GET",
|
|
2496
|
+
"/mail/templates",
|
|
2497
|
+
void 0,
|
|
2498
|
+
options
|
|
2499
|
+
);
|
|
2500
|
+
return data?.items ?? [];
|
|
2501
|
+
}
|
|
2502
|
+
/** Fetch one template by name (superuser). */
|
|
2503
|
+
async getTemplate(name, options) {
|
|
2504
|
+
const data = await this.http.request(
|
|
2505
|
+
"GET",
|
|
2506
|
+
templatePath(name),
|
|
2507
|
+
void 0,
|
|
2508
|
+
options
|
|
2509
|
+
);
|
|
2510
|
+
return data;
|
|
2511
|
+
}
|
|
2512
|
+
/**
|
|
2513
|
+
* Save all three parts of a template, replacing whatever was stored for them.
|
|
2514
|
+
*
|
|
2515
|
+
* All three at once rather than one at a time: a template is only allowed to
|
|
2516
|
+
* exist once it is complete, so a part-at-a-time write could leave a subject
|
|
2517
|
+
* saved against a body that does not parse. The server parses the bodies
|
|
2518
|
+
* before storing them, so a syntax error is a rejected save rather than a
|
|
2519
|
+
* queued email that fails where nobody is watching (superuser).
|
|
2520
|
+
*/
|
|
2521
|
+
async saveTemplate(name, parts, options) {
|
|
2522
|
+
const data = await this.http.put(
|
|
2523
|
+
templatePath(name),
|
|
2524
|
+
{ subject: parts.subject, html: parts.html, text: parts.text },
|
|
2525
|
+
options
|
|
2526
|
+
);
|
|
2527
|
+
return data;
|
|
2528
|
+
}
|
|
2529
|
+
/**
|
|
2530
|
+
* Remove the stored bodies, so the template falls back to its file or its
|
|
2531
|
+
* built-in (superuser).
|
|
2532
|
+
*
|
|
2533
|
+
* Deleting one that was never saved succeeds with `deleted: 0` — it is
|
|
2534
|
+
* already at its default — but an unknown *name* is a 404, so a typo cannot
|
|
2535
|
+
* look like a reset that worked.
|
|
2536
|
+
*/
|
|
2537
|
+
async deleteTemplate(name, options) {
|
|
2538
|
+
const data = await this.http.request(
|
|
2539
|
+
"DELETE",
|
|
2540
|
+
templatePath(name),
|
|
2541
|
+
void 0,
|
|
2542
|
+
options
|
|
2543
|
+
);
|
|
2544
|
+
return data ?? { name: name.trim(), deleted: 0 };
|
|
2545
|
+
}
|
|
2546
|
+
/**
|
|
2547
|
+
* Render a template the way a send would, without storing or sending
|
|
2548
|
+
* anything (superuser).
|
|
2549
|
+
*
|
|
2550
|
+
* Any of `subject`/`html`/`text` given in `draft` is rendered in place of the
|
|
2551
|
+
* stored part, which is what makes this useful while a body is still being
|
|
2552
|
+
* written. A draft over a name the server does not know is previewed as the
|
|
2553
|
+
* new template it is being written as, so such a draft has to arrive
|
|
2554
|
+
* complete (all three parts).
|
|
2555
|
+
*
|
|
2556
|
+
* Previews share one auto-cancellation key (`POST /mail/templates/<name>/preview`),
|
|
2557
|
+
* so a newer preview aborts an older one: the older promise rejects with an
|
|
2558
|
+
* `ApiError` whose `isAbort` is `true`. That is what an editor wants when a
|
|
2559
|
+
* keystroke supersedes the last render, but pass `{ requestKey: null }` to
|
|
2560
|
+
* keep every preview if you would rather have them all.
|
|
2561
|
+
*/
|
|
2562
|
+
async preview(name, draft, options) {
|
|
2563
|
+
const body = {
|
|
2564
|
+
assigns: draft?.assigns,
|
|
2565
|
+
toName: draft?.toName,
|
|
2566
|
+
subject: draft?.subject,
|
|
2567
|
+
html: draft?.html,
|
|
2568
|
+
text: draft?.text
|
|
2569
|
+
};
|
|
2570
|
+
const data = await this.http.request(
|
|
2571
|
+
"POST",
|
|
2572
|
+
templatePath(name) + "/preview",
|
|
2573
|
+
body,
|
|
2574
|
+
options
|
|
2575
|
+
);
|
|
2576
|
+
return data;
|
|
2577
|
+
}
|
|
2578
|
+
};
|
|
2579
|
+
|
|
2428
2580
|
// src/lazypock.ts
|
|
2429
2581
|
function createConnectionId() {
|
|
2430
2582
|
try {
|
|
@@ -2456,6 +2608,7 @@ var LazypockClient = class {
|
|
|
2456
2608
|
this.authStore.onChange(() => this.realtime.refresh());
|
|
2457
2609
|
this.authReady.then(() => this.realtime.refresh());
|
|
2458
2610
|
this.files = new FilesService(this.http);
|
|
2611
|
+
this.mail = new MailService(this.http);
|
|
2459
2612
|
this.collections = new CollectionsService(this.http, this.realtime);
|
|
2460
2613
|
if (options.types?.schemas) {
|
|
2461
2614
|
this.schemaByName = new Map(
|
|
@@ -2693,6 +2846,7 @@ export {
|
|
|
2693
2846
|
FilterExpr,
|
|
2694
2847
|
HttpClient,
|
|
2695
2848
|
LazypockClient,
|
|
2849
|
+
MailService,
|
|
2696
2850
|
RealtimeService,
|
|
2697
2851
|
TypedClient,
|
|
2698
2852
|
collectionTypeName,
|