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/README.md
CHANGED
|
@@ -449,6 +449,23 @@ PocketBase-style service for the collections themselves (admin):
|
|
|
449
449
|
- `getThumbUrl(baseUrl, fileId, size)` — Construct a thumbnail URL for a pre-configured thumb size
|
|
450
450
|
- `getScaleUrl(baseUrl, fileId, size)` — Construct an on-demand scaled image URL (e.g. `100x100`, `400x`)
|
|
451
451
|
|
|
452
|
+
### Mail (`client.mail`)
|
|
453
|
+
|
|
454
|
+
Send email through the deployment's SMTP settings, and manage its templates. Sending **queues** a
|
|
455
|
+
job (it does not deliver inline); failures surface on the job in `GET /api/logs`.
|
|
456
|
+
|
|
457
|
+
- `mail.send({ to, template, assigns? }, options?)` — Queue a message from a template (API-keyable)
|
|
458
|
+
- `mail.send({ to, subject, html?, text? }, options?)` — Queue a raw message (API-keyable)
|
|
459
|
+
- `mail.listTemplates(options?)` — Every template, with resolved bodies and the layer each part came from (superuser)
|
|
460
|
+
- `mail.getTemplate(name, options?)` — One template (superuser)
|
|
461
|
+
- `mail.saveTemplate(name, { subject, html, text }, options?)` — Replace all three parts; parsed before it is stored (superuser)
|
|
462
|
+
- `mail.deleteTemplate(name, options?)` — Remove the stored parts, falling back to the file or the built-in (superuser)
|
|
463
|
+
- `mail.preview(name, { assigns?, toName?, subject?, html?, text? }, options?)` — Render without storing or sending (superuser)
|
|
464
|
+
|
|
465
|
+
Defining a template is deliberately **not** API-keyable: a template is rendered with the variables of
|
|
466
|
+
an auth email — a verification or password-reset token — so whoever can write one can mail
|
|
467
|
+
themselves somebody else's token.
|
|
468
|
+
|
|
452
469
|
### Realtime
|
|
453
470
|
|
|
454
471
|
- `realtime.connect(opts)` — Open the SSE stream (`{ url, token }`)
|
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ __export(index_exports, {
|
|
|
29
29
|
FilterExpr: () => FilterExpr,
|
|
30
30
|
HttpClient: () => HttpClient,
|
|
31
31
|
LazypockClient: () => LazypockClient,
|
|
32
|
+
MailService: () => MailService,
|
|
32
33
|
RealtimeService: () => RealtimeService,
|
|
33
34
|
TypedClient: () => TypedClient,
|
|
34
35
|
collectionTypeName: () => collectionTypeName,
|
|
@@ -393,6 +394,17 @@ var HttpClient = class {
|
|
|
393
394
|
post(path, body, options) {
|
|
394
395
|
return this.request("POST", path, body, options);
|
|
395
396
|
}
|
|
397
|
+
/**
|
|
398
|
+
* HTTP PUT — a full replacement. Used where the server models a resource as a
|
|
399
|
+
* complete unit rather than a set of patches (e.g. a mail template, which only
|
|
400
|
+
* exists once all three of its parts do).
|
|
401
|
+
* @param path URL path.
|
|
402
|
+
* @param body Request body.
|
|
403
|
+
* @param options Optional request options.
|
|
404
|
+
*/
|
|
405
|
+
put(path, body, options) {
|
|
406
|
+
return this.request("PUT", path, body, options);
|
|
407
|
+
}
|
|
396
408
|
/**
|
|
397
409
|
* HTTP PATCH.
|
|
398
410
|
* @param path URL path.
|
|
@@ -2464,6 +2476,147 @@ function normalizeAction2(event) {
|
|
|
2464
2476
|
return "update";
|
|
2465
2477
|
}
|
|
2466
2478
|
|
|
2479
|
+
// src/mail.ts
|
|
2480
|
+
function templatePath(name) {
|
|
2481
|
+
return "/mail/templates/" + encodeURIComponent(name.trim());
|
|
2482
|
+
}
|
|
2483
|
+
var MailService = class {
|
|
2484
|
+
constructor(http) {
|
|
2485
|
+
this.http = http;
|
|
2486
|
+
}
|
|
2487
|
+
/**
|
|
2488
|
+
* Queue one message for delivery.
|
|
2489
|
+
*
|
|
2490
|
+
* Either a `template` or a `subject` with a body. The type requires one of
|
|
2491
|
+
* them — a message with neither does not compile — while the server refuses a
|
|
2492
|
+
* message that carries both, and a template with a raw body.
|
|
2493
|
+
*
|
|
2494
|
+
* The address is shape-checked server-side; the SMTP server remains the
|
|
2495
|
+
* authority on whether it exists.
|
|
2496
|
+
*
|
|
2497
|
+
* @param message The template or raw message to send.
|
|
2498
|
+
* @param options Optional request options (signal, custom fetch).
|
|
2499
|
+
* @returns The queued job (`{ queued: true, id }`).
|
|
2500
|
+
*
|
|
2501
|
+
* @example
|
|
2502
|
+
* ```ts
|
|
2503
|
+
* // A template
|
|
2504
|
+
* await client.mail.send({ to: 'ada@example.com', template: 'receipt', assigns: { total: 42 } });
|
|
2505
|
+
*
|
|
2506
|
+
* // A raw message
|
|
2507
|
+
* await client.mail.send({ to: 'ada@example.com', subject: 'Hello', text: 'Hi there' });
|
|
2508
|
+
* ```
|
|
2509
|
+
*/
|
|
2510
|
+
async send(message, options) {
|
|
2511
|
+
const body = "template" in message ? {
|
|
2512
|
+
to: message.to,
|
|
2513
|
+
toName: message.toName,
|
|
2514
|
+
template: message.template,
|
|
2515
|
+
assigns: message.assigns
|
|
2516
|
+
} : {
|
|
2517
|
+
to: message.to,
|
|
2518
|
+
toName: message.toName,
|
|
2519
|
+
subject: message.subject,
|
|
2520
|
+
html: message.html,
|
|
2521
|
+
text: message.text
|
|
2522
|
+
};
|
|
2523
|
+
const data = await this.http.request("POST", "/mail", body, options);
|
|
2524
|
+
return data ?? { queued: false, id: "" };
|
|
2525
|
+
}
|
|
2526
|
+
/**
|
|
2527
|
+
* List every template the server can send, with the body each part
|
|
2528
|
+
* currently resolves to and the layer it came from (superuser).
|
|
2529
|
+
*
|
|
2530
|
+
* Unpaginated: there are as many templates as the deployment defined, not
|
|
2531
|
+
* as many as it has sent.
|
|
2532
|
+
*/
|
|
2533
|
+
async listTemplates(options) {
|
|
2534
|
+
const data = await this.http.request(
|
|
2535
|
+
"GET",
|
|
2536
|
+
"/mail/templates",
|
|
2537
|
+
void 0,
|
|
2538
|
+
options
|
|
2539
|
+
);
|
|
2540
|
+
return data?.items ?? [];
|
|
2541
|
+
}
|
|
2542
|
+
/** Fetch one template by name (superuser). */
|
|
2543
|
+
async getTemplate(name, options) {
|
|
2544
|
+
const data = await this.http.request(
|
|
2545
|
+
"GET",
|
|
2546
|
+
templatePath(name),
|
|
2547
|
+
void 0,
|
|
2548
|
+
options
|
|
2549
|
+
);
|
|
2550
|
+
return data;
|
|
2551
|
+
}
|
|
2552
|
+
/**
|
|
2553
|
+
* Save all three parts of a template, replacing whatever was stored for them.
|
|
2554
|
+
*
|
|
2555
|
+
* All three at once rather than one at a time: a template is only allowed to
|
|
2556
|
+
* exist once it is complete, so a part-at-a-time write could leave a subject
|
|
2557
|
+
* saved against a body that does not parse. The server parses the bodies
|
|
2558
|
+
* before storing them, so a syntax error is a rejected save rather than a
|
|
2559
|
+
* queued email that fails where nobody is watching (superuser).
|
|
2560
|
+
*/
|
|
2561
|
+
async saveTemplate(name, parts, options) {
|
|
2562
|
+
const data = await this.http.put(
|
|
2563
|
+
templatePath(name),
|
|
2564
|
+
{ subject: parts.subject, html: parts.html, text: parts.text },
|
|
2565
|
+
options
|
|
2566
|
+
);
|
|
2567
|
+
return data;
|
|
2568
|
+
}
|
|
2569
|
+
/**
|
|
2570
|
+
* Remove the stored bodies, so the template falls back to its file or its
|
|
2571
|
+
* built-in (superuser).
|
|
2572
|
+
*
|
|
2573
|
+
* Deleting one that was never saved succeeds with `deleted: 0` — it is
|
|
2574
|
+
* already at its default — but an unknown *name* is a 404, so a typo cannot
|
|
2575
|
+
* look like a reset that worked.
|
|
2576
|
+
*/
|
|
2577
|
+
async deleteTemplate(name, options) {
|
|
2578
|
+
const data = await this.http.request(
|
|
2579
|
+
"DELETE",
|
|
2580
|
+
templatePath(name),
|
|
2581
|
+
void 0,
|
|
2582
|
+
options
|
|
2583
|
+
);
|
|
2584
|
+
return data ?? { name: name.trim(), deleted: 0 };
|
|
2585
|
+
}
|
|
2586
|
+
/**
|
|
2587
|
+
* Render a template the way a send would, without storing or sending
|
|
2588
|
+
* anything (superuser).
|
|
2589
|
+
*
|
|
2590
|
+
* Any of `subject`/`html`/`text` given in `draft` is rendered in place of the
|
|
2591
|
+
* stored part, which is what makes this useful while a body is still being
|
|
2592
|
+
* written. A draft over a name the server does not know is previewed as the
|
|
2593
|
+
* new template it is being written as, so such a draft has to arrive
|
|
2594
|
+
* complete (all three parts).
|
|
2595
|
+
*
|
|
2596
|
+
* Previews share one auto-cancellation key (`POST /mail/templates/<name>/preview`),
|
|
2597
|
+
* so a newer preview aborts an older one: the older promise rejects with an
|
|
2598
|
+
* `ApiError` whose `isAbort` is `true`. That is what an editor wants when a
|
|
2599
|
+
* keystroke supersedes the last render, but pass `{ requestKey: null }` to
|
|
2600
|
+
* keep every preview if you would rather have them all.
|
|
2601
|
+
*/
|
|
2602
|
+
async preview(name, draft, options) {
|
|
2603
|
+
const body = {
|
|
2604
|
+
assigns: draft?.assigns,
|
|
2605
|
+
toName: draft?.toName,
|
|
2606
|
+
subject: draft?.subject,
|
|
2607
|
+
html: draft?.html,
|
|
2608
|
+
text: draft?.text
|
|
2609
|
+
};
|
|
2610
|
+
const data = await this.http.request(
|
|
2611
|
+
"POST",
|
|
2612
|
+
templatePath(name) + "/preview",
|
|
2613
|
+
body,
|
|
2614
|
+
options
|
|
2615
|
+
);
|
|
2616
|
+
return data;
|
|
2617
|
+
}
|
|
2618
|
+
};
|
|
2619
|
+
|
|
2467
2620
|
// src/typegen.ts
|
|
2468
2621
|
function fieldTypeScriptType(field, fallback = "unknown") {
|
|
2469
2622
|
const opts = field.options ?? {};
|
|
@@ -2835,6 +2988,7 @@ var LazypockClient = class {
|
|
|
2835
2988
|
this.authStore.onChange(() => this.realtime.refresh());
|
|
2836
2989
|
this.authReady.then(() => this.realtime.refresh());
|
|
2837
2990
|
this.files = new FilesService(this.http);
|
|
2991
|
+
this.mail = new MailService(this.http);
|
|
2838
2992
|
this.collections = new CollectionsService(this.http, this.realtime);
|
|
2839
2993
|
if (options.types?.schemas) {
|
|
2840
2994
|
this.schemaByName = new Map(
|
|
@@ -3073,6 +3227,7 @@ function createClient(options) {
|
|
|
3073
3227
|
FilterExpr,
|
|
3074
3228
|
HttpClient,
|
|
3075
3229
|
LazypockClient,
|
|
3230
|
+
MailService,
|
|
3076
3231
|
RealtimeService,
|
|
3077
3232
|
TypedClient,
|
|
3078
3233
|
collectionTypeName,
|