@dbx-tools/shared-email 0.6.86 → 0.6.88
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 +35 -3
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
# @dbx-tools/shared-email
|
|
2
2
|
|
|
3
|
-
Browser-safe email schemas and inferred types
|
|
3
|
+
Browser-safe email schemas and inferred types, for both things email is used for
|
|
4
|
+
here: SENDING a message, and using an emailed code to LOG IN.
|
|
4
5
|
|
|
5
6
|
Import this package when a UI, Mastra tool schema, server route, or test needs
|
|
6
7
|
to validate the same email payloads that
|
|
7
|
-
[`@dbx-tools/email`](../../node/email) sends
|
|
8
|
+
[`@dbx-tools/email`](../../node/email) sends, or the same one-time-code login
|
|
9
|
+
payloads that [`@dbx-tools/tunnel`](../../node/tunnel) and
|
|
10
|
+
[`@dbx-tools/cli-tunnel`](../../cli/tunnel) gate traffic with.
|
|
8
11
|
|
|
9
12
|
Key features:
|
|
10
13
|
|
|
@@ -16,6 +19,9 @@ Key features:
|
|
|
16
19
|
a browser client.
|
|
17
20
|
- Model/tool-friendly schemas that avoid JSON Schema constraints known to cause
|
|
18
21
|
problems with some serving endpoints.
|
|
22
|
+
- Email one-time-code ACCESS GATE contract: the request/verify/status payloads
|
|
23
|
+
and the one session cookie name, so the two server paths that implement the
|
|
24
|
+
gate and the React `AuthGate` that drives it validate against one definition.
|
|
19
25
|
|
|
20
26
|
## Validate A Drafted Message
|
|
21
27
|
|
|
@@ -54,11 +60,37 @@ const senders = email.emailSendersSchema.parse(
|
|
|
54
60
|
The sender schema describes the concrete `From` choices for the current user,
|
|
55
61
|
the default sender, and whether the list is restricted by policy.
|
|
56
62
|
|
|
57
|
-
##
|
|
63
|
+
## Gate An App Behind An Emailed Code
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
import { auth, SESSION_COOKIE_NAME } from "@dbx-tools/shared-email";
|
|
67
|
+
|
|
68
|
+
const { email } = auth.authRequestSchema.parse(await request.json());
|
|
69
|
+
const status = auth.authStatusSchema.parse(await (await fetch("/api/email/auth/status")).json());
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
The flow is `POST /request` (email) → a 6-digit code is emailed → `POST /verify`
|
|
73
|
+
(email + code) → an HttpOnly session cookie named `SESSION_COOKIE_NAME` is set →
|
|
74
|
+
`GET /status` reports whether the caller is authenticated.
|
|
75
|
+
|
|
76
|
+
`request` ALWAYS reports success. That is deliberate anti-enumeration: the
|
|
77
|
+
response never reveals whether an address is allow-listed or was actually sent a
|
|
78
|
+
code, so a client cannot use the login form to discover who has access. Treat a
|
|
79
|
+
`{ ok: true }` from `request` as "the request was accepted", never as "that
|
|
80
|
+
address exists".
|
|
81
|
+
|
|
82
|
+
`SESSION_COOKIE_NAME` lives here rather than in either server package because
|
|
83
|
+
both the in-process gate and the CLI reverse proxy SET it, and browser code
|
|
84
|
+
reads it — three places that must agree on one string.
|
|
85
|
+
|
|
86
|
+
## Modules
|
|
58
87
|
|
|
59
88
|
- `email` - `emailAttachmentSchema`, `emailMessageSchema`,
|
|
60
89
|
`emailResultSchema`, `emailSendersSchema`, and flat inferred types:
|
|
61
90
|
`EmailAttachment`, `EmailMessage`, `EmailResult`, and `EmailSenders`.
|
|
91
|
+
- `auth` - the OTP gate wire format: `authRequestSchema`,
|
|
92
|
+
`authRequestResultSchema`, `authVerifySchema`, `authVerifyResultSchema`,
|
|
93
|
+
`authStatusSchema`, `SESSION_COOKIE_NAME`, and their inferred types.
|
|
62
94
|
|
|
63
95
|
The schemas intentionally avoid array `.min()` constraints so they can be reused
|
|
64
96
|
as model/tool JSON schemas for serving endpoints that reject `minItems`.
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"typescript": "^5.9.3"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@dbx-tools/shared-core": "0.6.
|
|
26
|
+
"@dbx-tools/shared-core": "0.6.88",
|
|
27
27
|
"zod": "4.3.6"
|
|
28
28
|
},
|
|
29
29
|
"main": "./lib/index.js",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"./package.json": "./package.json"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
-
"version": "0.6.
|
|
43
|
+
"version": "0.6.88",
|
|
44
44
|
"types": "./lib/index.d.ts",
|
|
45
45
|
"type": "module",
|
|
46
46
|
"exports": {
|