@wwchen/stack-notify 0.9.0 → 0.10.1

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
@@ -13,6 +13,9 @@ await mailer.send({ to, subject, text });
13
13
  | --- | --- |
14
14
  | `createMailer(options)` | a `Mailer` in `resend` or `sink` mode |
15
15
  | `mailerFromEnv(env)` | Resend in production, the sink elsewhere |
16
+ | `notifyEnv` | the env fragment for the stack's `defineEnv`: `RESEND_API_KEY` and `EMAIL_FROM` (both required in production), `MAGIC_LINK_SINK_PATH` |
16
17
  | `countSinkLines(path)` | how many links the sink holds now |
17
18
  | `waitForLink(path, afterLine, timeoutMs?)` | the first link after line `afterLine`, polling until the timeout |
18
19
 
20
+ `@wwchen/stack-notify/stack` exports `notify()` for the app's `stack.config.ts`: mail's agent rules, its `.gitignore` entry and its `.env.example` variables, written by `stack sync-blocks`, and its `stack doctor` check, a warning when `RESEND_API_KEY` is one variable for Production and Preview.
21
+
@@ -0,0 +1,8 @@
1
+ <!-- Owned by @wwchen/stack-notify: `stack sync-blocks` rewrites everything between these markers. Put your own text outside them. -->
2
+
3
+ ## Mail
4
+
5
+ Mail goes out through Resend's HTTP API, from `@wwchen/stack-notify`'s mailer. Outside production nothing is sent: the first link in each message is appended to the sink file (`MAGIC_LINK_SINK_PATH`, default `.magic-links.log`).
6
+
7
+ - `EMAIL_FROM` must be on a domain verified in Resend, which need not be `APP_URL`'s host; never derive one from the other.
8
+ - Never write a sender's address or domain in the repo. Name the variable (`EMAIL_FROM`).
@@ -0,0 +1,8 @@
1
+ <!-- Owned by @wwchen/stack-notify: `stack sync-blocks` rewrites everything between these markers. Put your own text outside them. -->
2
+
3
+ ## Mail
4
+
5
+ Mail goes out through Resend's HTTP API, from `@wwchen/stack-notify`'s mailer. Outside production nothing is sent: the first link in each message is appended to the sink file (`MAGIC_LINK_SINK_PATH`, default `.magic-links.log`), which is how development and the tests read it.
6
+
7
+ - `EMAIL_FROM` must be on a domain verified in Resend, which need not be `APP_URL`'s host; never derive one from the other.
8
+ - Name `EMAIL_FROM`, never a sender's address or domain, in code, docs and this file.
@@ -0,0 +1,6 @@
1
+ # Mail through Resend (required in production; elsewhere nothing is sent and the link goes to the sink file)
2
+ RESEND_API_KEY=
3
+ # Sender on a domain verified in Resend (required in production)
4
+ EMAIL_FROM=
5
+ # Where development and the tests write mailed links (default .magic-links.log)
6
+ MAGIC_LINK_SINK_PATH=
@@ -0,0 +1,2 @@
1
+ # Mailed links, written outside production
2
+ .magic-links.log
package/dist/env.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Mail's variables, an env fragment the app passes to the stack's `defineEnv({ fragments })`. Its shape is the stack's `EnvFragment`, written out here because this package imports no stack package.
4
+ */
5
+ export declare const notifyEnv: {
6
+ readonly name: "notifyEnv";
7
+ readonly schema: {
8
+ readonly RESEND_API_KEY: z.ZodOptional<z.ZodString>;
9
+ readonly EMAIL_FROM: z.ZodDefault<z.ZodString>;
10
+ readonly MAGIC_LINK_SINK_PATH: z.ZodDefault<z.ZodString>;
11
+ };
12
+ readonly productionRequired: readonly ["RESEND_API_KEY", "EMAIL_FROM"];
13
+ };
package/dist/env.js ADDED
@@ -0,0 +1,14 @@
1
+ import { z } from "zod";
2
+ /**
3
+ * Mail's variables, an env fragment the app passes to the stack's `defineEnv({ fragments })`. Its shape is the stack's `EnvFragment`, written out here because this package imports no stack package.
4
+ */
5
+ export const notifyEnv = {
6
+ name: "notifyEnv",
7
+ schema: {
8
+ // Sign-in mail. Production sends through Resend; elsewhere the link goes to the sink file.
9
+ RESEND_API_KEY: z.string().optional(),
10
+ EMAIL_FROM: z.string().default("App <no-reply@example.invalid>"),
11
+ MAGIC_LINK_SINK_PATH: z.string().default(".magic-links.log"),
12
+ },
13
+ productionRequired: ["RESEND_API_KEY", "EMAIL_FROM"],
14
+ };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ export { notifyEnv } from "./env.ts";
1
2
  /**
2
3
  * The one way an app sends mail: every message goes through `Mailer`, so one switch decides whether it is delivered or only recorded.
3
4
  *
@@ -24,7 +25,7 @@ export declare function createMailer(opts: MailerOptions): Mailer;
24
25
  /**
25
26
  * Production sends through Resend; every other environment uses the sink.
26
27
  *
27
- * A production run without `RESEND_API_KEY` or `EMAIL_FROM` gets a mailer that refuses every send, naming the missing variable, rather than a throw here: `next build` evaluates the app's mail module with `NODE_ENV=production` and no secrets (a build skips env validation), and must not fail on it. A booted production app never gets this far without them: the stack's env requires both in production.
28
+ * A production run without `RESEND_API_KEY` or `EMAIL_FROM` gets a mailer that refuses every send, naming the missing variable, rather than a throw here: `next build` evaluates the app's mail module with `NODE_ENV=production` and no secrets (a build skips env validation), and must not fail on it. A booted production app never gets this far without them: `notifyEnv` requires both in production.
28
29
  */
29
30
  export declare function mailerFromEnv(env: {
30
31
  NODE_ENV: string;
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import { appendFileSync, existsSync, readFileSync } from "node:fs";
2
+ export { notifyEnv } from "./env.js";
2
3
  const RESEND_ENDPOINT = "https://api.resend.com/emails";
3
4
  export function createMailer(opts) {
4
5
  if (opts.mode === "sink") {
@@ -34,7 +35,7 @@ export function createMailer(opts) {
34
35
  /**
35
36
  * Production sends through Resend; every other environment uses the sink.
36
37
  *
37
- * A production run without `RESEND_API_KEY` or `EMAIL_FROM` gets a mailer that refuses every send, naming the missing variable, rather than a throw here: `next build` evaluates the app's mail module with `NODE_ENV=production` and no secrets (a build skips env validation), and must not fail on it. A booted production app never gets this far without them: the stack's env requires both in production.
38
+ * A production run without `RESEND_API_KEY` or `EMAIL_FROM` gets a mailer that refuses every send, naming the missing variable, rather than a throw here: `next build` evaluates the app's mail module with `NODE_ENV=production` and no secrets (a build skips env validation), and must not fail on it. A booted production app never gets this far without them: `notifyEnv` requires both in production.
38
39
  */
39
40
  export function mailerFromEnv(env) {
40
41
  if (env.NODE_ENV !== "production") {
@@ -0,0 +1,27 @@
1
+ /** The files `stack sync-blocks` writes mail's blocks into: the core's `BLOCK_FILES`. */
2
+ declare const BLOCK_FILES: readonly ["AGENTS.md", "CLAUDE.md", ".gitignore", ".env.example"];
3
+ /** A file `stack sync-blocks` writes a marked block into, and the block's text. */
4
+ type Block = {
5
+ file: (typeof BLOCK_FILES)[number];
6
+ source: URL;
7
+ };
8
+ /** A finding of `stack doctor`, which runs the check below on the linked Vercel project's variable metadata: the core's `Finding`. */
9
+ type Finding = {
10
+ severity: "error" | "warning" | "info";
11
+ message: string;
12
+ };
13
+ type Facts = {
14
+ envs: {
15
+ key: string;
16
+ target: string[];
17
+ }[];
18
+ };
19
+ /**
20
+ * Mail's package for the app's `stack.config.ts`: its check for `stack doctor`, and its agent rules, `.gitignore` entries and `.env.example` variables, written by `stack sync-blocks`. Its shape is the stack's `StackPackage`, written out here because this package imports no stack package.
21
+ */
22
+ export declare function notify(): {
23
+ name: string;
24
+ doctorChecks: ((facts: Facts) => Promise<Finding[]>)[];
25
+ blocks: Block[];
26
+ };
27
+ export {};
package/dist/stack.js ADDED
@@ -0,0 +1,34 @@
1
+ /** The files `stack sync-blocks` writes mail's blocks into: the core's `BLOCK_FILES`. */
2
+ const BLOCK_FILES = ["AGENTS.md", "CLAUDE.md", ".gitignore", ".env.example"];
3
+ /** The core's `VERCEL_TARGET`, the two the check compares. */
4
+ const PRODUCTION = "production";
5
+ const PREVIEW = "preview";
6
+ /** Mail's secret, which a preview must hold its own value of. */
7
+ const RESEND_API_KEY = "RESEND_API_KEY";
8
+ /** `stack doctor`'s check of mail's variables: RESEND_API_KEY must hold Preview's own value, never production's (runbook §3). It mirrors `previewOwnSecretsCheck` from `@wwchen/stack/vercel`, predicate and message, because this package imports no stack package. */
9
+ async function sharedSecret({ envs }) {
10
+ const shared = envs.some((v) => v.key === RESEND_API_KEY && v.target.includes(PRODUCTION) && v.target.includes(PREVIEW));
11
+ if (!shared)
12
+ return [];
13
+ return [
14
+ {
15
+ severity: "warning",
16
+ message: `${RESEND_API_KEY} is one variable for Production and Preview: give Preview its own value, so a preview can never use production's.`,
17
+ },
18
+ ];
19
+ }
20
+ /** `blocks/` sits beside `src/` and `dist/`, so one relative path serves both and an installed package. A block is named for its file without the leading dot, because npm leaves a `.gitignore` out of a published package. */
21
+ const block = (file) => ({
22
+ file,
23
+ source: new URL(`../blocks/${file.replace(/^\./, "")}`, import.meta.url),
24
+ });
25
+ /**
26
+ * Mail's package for the app's `stack.config.ts`: its check for `stack doctor`, and its agent rules, `.gitignore` entries and `.env.example` variables, written by `stack sync-blocks`. Its shape is the stack's `StackPackage`, written out here because this package imports no stack package.
27
+ */
28
+ export function notify() {
29
+ return {
30
+ name: "@wwchen/stack-notify",
31
+ doctorChecks: [sharedSecret],
32
+ blocks: BLOCK_FILES.map(block),
33
+ };
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wwchen/stack-notify",
3
- "version": "0.9.0",
3
+ "version": "0.10.1",
4
4
  "description": "Send mail through Resend, or to a sink file in development and tests.",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -13,14 +13,22 @@
13
13
  "node": "24.x"
14
14
  },
15
15
  "files": [
16
- "dist"
16
+ "dist",
17
+ "blocks"
17
18
  ],
18
19
  "exports": {
19
20
  ".": {
20
21
  "types": "./dist/index.d.ts",
21
22
  "default": "./dist/index.js"
23
+ },
24
+ "./stack": {
25
+ "types": "./dist/stack.d.ts",
26
+ "default": "./dist/stack.js"
22
27
  }
23
28
  },
29
+ "dependencies": {
30
+ "zod": "4.6.7"
31
+ },
24
32
  "devDependencies": {
25
33
  "@types/node": "^24.19.2",
26
34
  "typescript": "~6.0.3",