lazypock 0.19.1 → 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 +165 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +187 -3
- package/dist/index.d.ts +187 -3
- package/dist/index.global.js +164 -3
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +164 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/collection.ts +16 -2
- package/src/collections.ts +3 -2
- 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.
|
|
@@ -904,6 +915,11 @@ function authorizeWithOAuth2Popup(opts) {
|
|
|
904
915
|
}
|
|
905
916
|
|
|
906
917
|
// src/collection.ts
|
|
918
|
+
var MAX_PER_PAGE = 500;
|
|
919
|
+
function clampBatch(batch) {
|
|
920
|
+
if (!Number.isFinite(batch)) return MAX_PER_PAGE;
|
|
921
|
+
return Math.min(Math.max(1, Math.floor(batch)), MAX_PER_PAGE);
|
|
922
|
+
}
|
|
907
923
|
function stableStringify(value) {
|
|
908
924
|
const seen = /* @__PURE__ */ new Set();
|
|
909
925
|
const sort = (v) => {
|
|
@@ -1400,13 +1416,14 @@ var CollectionService = class _CollectionService {
|
|
|
1400
1416
|
return result;
|
|
1401
1417
|
}
|
|
1402
1418
|
/**
|
|
1403
|
-
* Fetch all records at once (auto-paginates). Mirrors PocketBase's
|
|
1419
|
+
* Fetch all records at once (auto-paginates; `batch` defaults to and is capped at 500, the server max `perPage`). Mirrors PocketBase's
|
|
1404
1420
|
* `pb.collection(name).getFullList()`.
|
|
1405
1421
|
*
|
|
1406
1422
|
* @param options Query params (`sort`, `filter`, `batch`, etc.) + request options.
|
|
1407
1423
|
*/
|
|
1408
1424
|
async getFullList(options) {
|
|
1409
|
-
const { batch =
|
|
1425
|
+
const { batch: requestedBatch = MAX_PER_PAGE, ...rest } = options ?? {};
|
|
1426
|
+
const batch = clampBatch(requestedBatch);
|
|
1410
1427
|
if (typeof rest.filter === "function") {
|
|
1411
1428
|
rest.filter = this.resolveFilter(rest.filter);
|
|
1412
1429
|
}
|
|
@@ -2299,7 +2316,8 @@ var CollectionsService = class {
|
|
|
2299
2316
|
*/
|
|
2300
2317
|
async getFullList(options) {
|
|
2301
2318
|
if (!this.http) return [];
|
|
2302
|
-
const { batch =
|
|
2319
|
+
const { batch: requestedBatch = MAX_PER_PAGE, ...rest } = options ?? {};
|
|
2320
|
+
const batch = clampBatch(requestedBatch);
|
|
2303
2321
|
const {
|
|
2304
2322
|
requestKey: reqKey,
|
|
2305
2323
|
singleFlight: _singleFlight,
|
|
@@ -2418,6 +2436,147 @@ function normalizeAction2(event) {
|
|
|
2418
2436
|
return "update";
|
|
2419
2437
|
}
|
|
2420
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
|
+
|
|
2421
2580
|
// src/lazypock.ts
|
|
2422
2581
|
function createConnectionId() {
|
|
2423
2582
|
try {
|
|
@@ -2449,6 +2608,7 @@ var LazypockClient = class {
|
|
|
2449
2608
|
this.authStore.onChange(() => this.realtime.refresh());
|
|
2450
2609
|
this.authReady.then(() => this.realtime.refresh());
|
|
2451
2610
|
this.files = new FilesService(this.http);
|
|
2611
|
+
this.mail = new MailService(this.http);
|
|
2452
2612
|
this.collections = new CollectionsService(this.http, this.realtime);
|
|
2453
2613
|
if (options.types?.schemas) {
|
|
2454
2614
|
this.schemaByName = new Map(
|
|
@@ -2686,6 +2846,7 @@ export {
|
|
|
2686
2846
|
FilterExpr,
|
|
2687
2847
|
HttpClient,
|
|
2688
2848
|
LazypockClient,
|
|
2849
|
+
MailService,
|
|
2689
2850
|
RealtimeService,
|
|
2690
2851
|
TypedClient,
|
|
2691
2852
|
collectionTypeName,
|