@kabobcompany/lift 0.2.0 → 0.3.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 CHANGED
@@ -30,6 +30,10 @@ and `storage` are the rest. An app reaches only its own files.
30
30
  `handleJob(request, handlers)` answers Lift's call when a job or a schedule from the app's
31
31
  `lift.json` is due; `jobRuns`, `jobRun`, `cancelJob` and `jobs` show how they went.
32
32
 
33
+ `sendEmail({ to, subject, text, html })` sends an email from the app's own address and
34
+ `sendSms({ to, text })` a text message to one phone, both on Kabob's account and within
35
+ the limits Lift sets; `email()` and `sms()` say what those are and what was sent today.
36
+
33
37
  A refusal is thrown as a `LiftError` with `status`, `code`, `message` and, on a 422,
34
38
  `issues`.
35
39
 
package/dist/index.d.ts CHANGED
@@ -427,4 +427,73 @@ export declare const jobs: () => Promise<{
427
427
  * is tried again. Make handlers safe to repeat.
428
428
  */
429
429
  export declare function handleJob(request: Request, handlers: Record<string, JobHandler>): Promise<Response>;
430
+ export type SentEmail = {
431
+ id: string;
432
+ from: string;
433
+ to: string[];
434
+ };
435
+ /**
436
+ * Send an email:
437
+ *
438
+ * await sendEmail({ to: customer.email, subject: "Your try-on", html, text }, { tag: `brand-${brand.id}` })
439
+ *
440
+ * It comes from the app's own address (`<app>@lift.kabob.io`) under the
441
+ * app's name; set `replyTo` to where answers should go. Give `text`, `html`
442
+ * or both (256 KB together at most), to 10 addresses at most. There are no
443
+ * attachments: put the file in storage and link to it with `fileUrl`.
444
+ *
445
+ * Throws a `LiftError`: 429 `daily_limit` (the app sent its day's worth),
446
+ * 429 `recipient_limit` (that address got enough from this app for now),
447
+ * 422 `refused` (the mail service won't send this one; `message` says why).
448
+ */
449
+ export declare function sendEmail(message: {
450
+ to: string | string[];
451
+ subject: string;
452
+ text?: string;
453
+ html?: string;
454
+ replyTo?: string | string[];
455
+ }, options?: Paid): Promise<SentEmail>;
456
+ /** The app's address, how many emails it sent today, and its limits. */
457
+ export declare const email: (options?: Paid) => Promise<{
458
+ from: string;
459
+ sent_today: number;
460
+ limits: {
461
+ app_per_day: number;
462
+ max_recipients: number;
463
+ max_bytes: number;
464
+ };
465
+ }>;
466
+ export type SentSms = {
467
+ id: string;
468
+ to: string;
469
+ segments: number;
470
+ };
471
+ /**
472
+ * Send a text message to one phone:
473
+ *
474
+ * await sendSms({ to: "+886912345678", text: `Your code is ${code}` }, { tag })
475
+ *
476
+ * `to` has its country code; Lift only texts the countries it lists
477
+ * (`sms()`), Taiwan unless set otherwise. Every message costs money by
478
+ * segment: 160 plain letters, or 70 with Chinese or emoji, and three
479
+ * segments at most. Send one only when a person asked for it, and never let
480
+ * a visitor choose the text.
481
+ *
482
+ * Throws a `LiftError`: 403 `country_not_allowed`, 413 `too_long`, 429
483
+ * `daily_limit`, 429 `recipient_limit` (a number gets a few an hour), 422
484
+ * `refused` (the network won't send this one; `message` says why).
485
+ */
486
+ export declare function sendSms(message: {
487
+ to: string;
488
+ text: string;
489
+ }, options?: Paid): Promise<SentSms>;
490
+ /** How many segments the app sent today, its limits, and the countries Lift texts. */
491
+ export declare const sms: (options?: Paid) => Promise<{
492
+ sent_today: number;
493
+ limits: {
494
+ app_per_day: number;
495
+ max_segments: number;
496
+ countries: string[];
497
+ };
498
+ }>;
430
499
  export {};
package/dist/index.js CHANGED
@@ -421,3 +421,48 @@ export async function handleJob(request, handlers) {
421
421
  return reply(500, { error: "job_failed", message: error instanceof Error ? error.message : String(error) });
422
422
  }
423
423
  }
424
+ // Email and text messages, on Kabob's account. Lift decides who they come
425
+ // from and limits how much an app sends and how many one person gets.
426
+ // Needs the app's Email or Text messages switch on Lift.
427
+ const sending = async (service, method, path, body, options) => paidAnswer(await paid(service, method, path, body, { timeoutMs: 25_000, ...options }), "Lift");
428
+ /**
429
+ * Send an email:
430
+ *
431
+ * await sendEmail({ to: customer.email, subject: "Your try-on", html, text }, { tag: `brand-${brand.id}` })
432
+ *
433
+ * It comes from the app's own address (`<app>@lift.kabob.io`) under the
434
+ * app's name; set `replyTo` to where answers should go. Give `text`, `html`
435
+ * or both (256 KB together at most), to 10 addresses at most. There are no
436
+ * attachments: put the file in storage and link to it with `fileUrl`.
437
+ *
438
+ * Throws a `LiftError`: 429 `daily_limit` (the app sent its day's worth),
439
+ * 429 `recipient_limit` (that address got enough from this app for now),
440
+ * 422 `refused` (the mail service won't send this one; `message` says why).
441
+ */
442
+ export async function sendEmail(message, options = {}) {
443
+ const { replyTo, ...rest } = message;
444
+ const body = { ...rest, ...(replyTo != null && { reply_to: replyTo }) };
445
+ return (await sending("email", "POST", "messages", body, options)).message;
446
+ }
447
+ /** The app's address, how many emails it sent today, and its limits. */
448
+ export const email = (options = {}) => sending("email", "GET", "", undefined, options);
449
+ /**
450
+ * Send a text message to one phone:
451
+ *
452
+ * await sendSms({ to: "+886912345678", text: `Your code is ${code}` }, { tag })
453
+ *
454
+ * `to` has its country code; Lift only texts the countries it lists
455
+ * (`sms()`), Taiwan unless set otherwise. Every message costs money by
456
+ * segment: 160 plain letters, or 70 with Chinese or emoji, and three
457
+ * segments at most. Send one only when a person asked for it, and never let
458
+ * a visitor choose the text.
459
+ *
460
+ * Throws a `LiftError`: 403 `country_not_allowed`, 413 `too_long`, 429
461
+ * `daily_limit`, 429 `recipient_limit` (a number gets a few an hour), 422
462
+ * `refused` (the network won't send this one; `message` says why).
463
+ */
464
+ export async function sendSms(message, options = {}) {
465
+ return (await sending("sms", "POST", "messages", message, options)).message;
466
+ }
467
+ /** How many segments the app sent today, its limits, and the countries Lift texts. */
468
+ export const sms = (options = {}) => sending("sms", "GET", "", undefined, options);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kabobcompany/lift",
3
- "version": "0.2.0",
4
- "description": "For apps hosted on Lift: call Kabob products (Lookr) as the signed-in person, run public actions, use OpenAI and Seedance on Kabob's account, keep files in Lift's storage, and run background jobs.",
3
+ "version": "0.3.0",
4
+ "description": "For apps hosted on Lift: call Kabob products (Lookr) as the signed-in person, run public actions, use OpenAI and Seedance on Kabob's account, keep files in Lift's storage, run background jobs, and send email and text messages.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
7
7
  "main": "./dist/index.js",