@pithy-sh/email 0.1.4 → 0.1.6
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settingsCheck.d.ts","sourceRoot":"","sources":["../../src/provision/settingsCheck.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAInB,MAAM,wCAAwC,CAAC;
|
|
1
|
+
{"version":3,"file":"settingsCheck.d.ts","sourceRoot":"","sources":["../../src/provision/settingsCheck.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,kBAAkB,EAInB,MAAM,wCAAwC,CAAC;AAKhD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAIrD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,uGAAuG;AACvG,MAAM,WAAW,kBAAkB;IACjC,qFAAqF;IACrF,WAAW,EAAE,MAAM,CAAC;IACpB,oEAAoE;IACpE,OAAO,EAAE,MAAM,CAAC;IAChB,iEAAiE;IACjE,KAAK,CAAC,EAAE,UAAU,CAAC;CACpB;AA4LD,wGAAwG;AACxG,wBAAgB,aAAa,CAAC,MAAM,EAAE,kBAAkB,GAAG,kBAAkB,CAK5E"}
|
|
@@ -4,6 +4,7 @@ import { EMAIL_LINK_SIGNING_KEY } from "../crypto/signingKey.js";
|
|
|
4
4
|
import { emailHostEnv } from "../workflows/hostEnv.js";
|
|
5
5
|
import { suppressionDatabaseName } from "./provisionEmail.js";
|
|
6
6
|
import { hostEnvFindings } from "@pithy-sh/core/src/capability/settings";
|
|
7
|
+
import "@pithy-sh/core/src/naming/domains";
|
|
7
8
|
import { checkHostEnv } from "@pithy-sh/core/src/workflow/hostEnv";
|
|
8
9
|
//#region src/provision/settingsCheck.ts
|
|
9
10
|
/**
|
|
@@ -60,6 +61,21 @@ function localHostEnv(config) {
|
|
|
60
61
|
return hostEnvFindings(checkHostEnv(emailHostEnv, candidate), null);
|
|
61
62
|
}
|
|
62
63
|
/**
|
|
64
|
+
* Whether a URL points at this machine — {@link LOCAL_ORIGIN} and every spelling of it, port or none.
|
|
65
|
+
*
|
|
66
|
+
* Matched on the host rather than the whole origin because the derived value carries no port and a
|
|
67
|
+
* hand-written one usually does (`http://localhost:8787`), and the two are the same claim: a loopback
|
|
68
|
+
* address is not an origin anything is deployed on, so it can only ever be the local answer.
|
|
69
|
+
*/
|
|
70
|
+
function isLoopback(url) {
|
|
71
|
+
try {
|
|
72
|
+
const host = new URL(url).hostname.replace(/^\[|\]$/g, "");
|
|
73
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1";
|
|
74
|
+
} catch {
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
63
79
|
* Whether the configured base URL is an origin this project actually answers on.
|
|
64
80
|
*
|
|
65
81
|
* `pithy email provision` stamps each host's `BASE_URL` from that environment's *resolved worker address*,
|
|
@@ -67,10 +83,29 @@ function localHostEnv(config) {
|
|
|
67
83
|
* against and what the repository states its intent with, and a value matching no declared origin is a
|
|
68
84
|
* link to a host nothing serves. Asked only when some environment declares one: a project before its first
|
|
69
85
|
* domain has nothing to compare against, and `Origins:` already reports that.
|
|
86
|
+
*
|
|
87
|
+
* **{@link LOCAL_ORIGIN} is passed over, and that is the whole of #510.** The recommended shape is
|
|
88
|
+
* `email({ baseUrl: PUBLIC_ORIGIN })` over `originFor(compositionEnvironment(), DOMAINS)`, and every
|
|
89
|
+
* caller of this loads the config **once, under `dev`** — an environment `domains` declares by design
|
|
90
|
+
* (`docs/NAMING.md`), so `resolveOrigin` correctly answers `http://localhost`. That value is then compared
|
|
91
|
+
* against staging's and prod's origins, matches neither, and the project is told to set `baseUrl` to one
|
|
92
|
+
* of them **by name**.
|
|
93
|
+
*
|
|
94
|
+
* Which is the mistake `docs/CLI.md` exists to prevent, offered to the projects that got it right: write
|
|
95
|
+
* one environment's origin into that key and a staging deploy mails real users links into production. A
|
|
96
|
+
* report that is easy to follow and wrong is worse than none, and this one named two specific origins.
|
|
97
|
+
*
|
|
98
|
+
* A hardcoded `http://localhost` is genuinely indistinguishable from a derived one here — same string,
|
|
99
|
+
* same key, and no environment in hand to tell them apart. So the question is left to where it can be
|
|
100
|
+
* answered: `resolveOrigin`'s own contract puts it on `pithy deploy --env <name>`, which refuses an
|
|
101
|
+
* environment whose origin its config does not declare (#253), and on `Origins:`, which reports the
|
|
102
|
+
* placeholder before a deploy is attempted. Two checks already own it; this one was the third and the
|
|
103
|
+
* only one without the environment it needed.
|
|
70
104
|
*/
|
|
71
105
|
function localBaseUrlOrigin(config, context) {
|
|
72
106
|
const declared = context.environments.map((environment) => environment.origin === null ? null : originOf(environment.origin)).filter((origin) => origin !== null);
|
|
73
107
|
const configured = originOf(config.baseUrl);
|
|
108
|
+
if (isLoopback(config.baseUrl)) return [];
|
|
74
109
|
if (declared.length === 0 || configured === null || declared.includes(configured)) return [];
|
|
75
110
|
return [{
|
|
76
111
|
setting: "BASE_URL",
|
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
/** This package's npm name — the join key against a release feed. */
|
|
4
4
|
export declare const PACKAGE_NAME = "@pithy-sh/email";
|
|
5
5
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
6
|
-
export declare const PACKAGE_VERSION = "0.1.
|
|
6
|
+
export declare const PACKAGE_VERSION = "0.1.6";
|
|
7
7
|
//# sourceMappingURL=version.generated.d.ts.map
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
/** This package's npm name — the join key against a release feed. */
|
|
5
5
|
const PACKAGE_NAME = "@pithy-sh/email";
|
|
6
6
|
/** This package's version, stamped from its own package.json at generation time. */
|
|
7
|
-
const PACKAGE_VERSION = "0.1.
|
|
7
|
+
const PACKAGE_VERSION = "0.1.6";
|
|
8
8
|
//#endregion
|
|
9
9
|
export { PACKAGE_NAME, PACKAGE_VERSION };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pithy-sh/email",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"@cloudflare/workers-types": "^5.20260729.1",
|
|
40
40
|
"@hono/zod-validator": "^0.9.0",
|
|
41
|
-
"@pithy-sh/core": "^0.
|
|
42
|
-
"@pithy-sh/secrets": "^0.1.
|
|
41
|
+
"@pithy-sh/core": "^0.2.0",
|
|
42
|
+
"@pithy-sh/secrets": "^0.1.5",
|
|
43
43
|
"handlebars": "^4.7.9",
|
|
44
44
|
"postal-mime": "^3.0.0"
|
|
45
45
|
},
|
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
SettingsFinding,
|
|
10
10
|
} from "@pithy-sh/core/src/capability/settings";
|
|
11
11
|
import { hostEnvFindings } from "@pithy-sh/core/src/capability/settings";
|
|
12
|
+
import { LOCAL_ORIGIN } from "@pithy-sh/core/src/naming/domains";
|
|
12
13
|
import { checkHostEnv } from "@pithy-sh/core/src/workflow/hostEnv";
|
|
13
14
|
import { EMAIL_LINK_SIGNING_KEY } from "../crypto/signingKey";
|
|
14
15
|
import type { EmailTheme } from "../templates/theme";
|
|
@@ -112,6 +113,22 @@ function localHostEnv(config: EmailSettingsInput): SettingsFinding[] {
|
|
|
112
113
|
return hostEnvFindings(checkHostEnv(emailHostEnv, candidate), null);
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Whether a URL points at this machine — {@link LOCAL_ORIGIN} and every spelling of it, port or none.
|
|
118
|
+
*
|
|
119
|
+
* Matched on the host rather than the whole origin because the derived value carries no port and a
|
|
120
|
+
* hand-written one usually does (`http://localhost:8787`), and the two are the same claim: a loopback
|
|
121
|
+
* address is not an origin anything is deployed on, so it can only ever be the local answer.
|
|
122
|
+
*/
|
|
123
|
+
function isLoopback(url: string): boolean {
|
|
124
|
+
try {
|
|
125
|
+
const host = new URL(url).hostname.replace(/^\[|\]$/g, "");
|
|
126
|
+
return host === "localhost" || host === "127.0.0.1" || host === "::1";
|
|
127
|
+
} catch {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
115
132
|
/**
|
|
116
133
|
* Whether the configured base URL is an origin this project actually answers on.
|
|
117
134
|
*
|
|
@@ -120,12 +137,31 @@ function localHostEnv(config: EmailSettingsInput): SettingsFinding[] {
|
|
|
120
137
|
* against and what the repository states its intent with, and a value matching no declared origin is a
|
|
121
138
|
* link to a host nothing serves. Asked only when some environment declares one: a project before its first
|
|
122
139
|
* domain has nothing to compare against, and `Origins:` already reports that.
|
|
140
|
+
*
|
|
141
|
+
* **{@link LOCAL_ORIGIN} is passed over, and that is the whole of #510.** The recommended shape is
|
|
142
|
+
* `email({ baseUrl: PUBLIC_ORIGIN })` over `originFor(compositionEnvironment(), DOMAINS)`, and every
|
|
143
|
+
* caller of this loads the config **once, under `dev`** — an environment `domains` declares by design
|
|
144
|
+
* (`docs/NAMING.md`), so `resolveOrigin` correctly answers `http://localhost`. That value is then compared
|
|
145
|
+
* against staging's and prod's origins, matches neither, and the project is told to set `baseUrl` to one
|
|
146
|
+
* of them **by name**.
|
|
147
|
+
*
|
|
148
|
+
* Which is the mistake `docs/CLI.md` exists to prevent, offered to the projects that got it right: write
|
|
149
|
+
* one environment's origin into that key and a staging deploy mails real users links into production. A
|
|
150
|
+
* report that is easy to follow and wrong is worse than none, and this one named two specific origins.
|
|
151
|
+
*
|
|
152
|
+
* A hardcoded `http://localhost` is genuinely indistinguishable from a derived one here — same string,
|
|
153
|
+
* same key, and no environment in hand to tell them apart. So the question is left to where it can be
|
|
154
|
+
* answered: `resolveOrigin`'s own contract puts it on `pithy deploy --env <name>`, which refuses an
|
|
155
|
+
* environment whose origin its config does not declare (#253), and on `Origins:`, which reports the
|
|
156
|
+
* placeholder before a deploy is attempted. Two checks already own it; this one was the third and the
|
|
157
|
+
* only one without the environment it needed.
|
|
123
158
|
*/
|
|
124
159
|
function localBaseUrlOrigin(config: EmailSettingsInput, context: SettingsCheckContext): SettingsFinding[] {
|
|
125
160
|
const declared = context.environments
|
|
126
161
|
.map((environment) => (environment.origin === null ? null : originOf(environment.origin)))
|
|
127
162
|
.filter((origin): origin is string => origin !== null);
|
|
128
163
|
const configured = originOf(config.baseUrl);
|
|
164
|
+
if (isLoopback(config.baseUrl)) return [];
|
|
129
165
|
if (declared.length === 0 || configured === null || declared.includes(configured)) return [];
|
|
130
166
|
return [
|
|
131
167
|
{
|
package/src/version.generated.ts
CHANGED