@tokenoftrust/storefront-runner 7.15.0 → 8.0.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/apps/storefront/env.d.ts +4 -0
- package/apps/storefront/src/config/compliance/rulesets.ts +475 -50
- package/apps/storefront/src/lib/checkout/commerce/finalCartAuthorization.ts +6 -0
- package/apps/storefront/src/lib/compliance/enforcement.ts +29 -0
- package/apps/storefront/src/lib/engagement/newsletter/consent.ts +115 -6
- package/apps/storefront/src/lib/engagement/newsletter/subscribers.ts +155 -23
- package/apps/storefront/src/pages/api/commerce/final-cart-authorization.ts +6 -0
- package/apps/storefront/src/pages/api/newsletter/[collection]/subscribe.ts +57 -23
- package/package.json +1 -1
- package/packages/public-runtime/src/compliance/evaluate.ts +600 -126
- package/packages/public-runtime/src/compliance/evidence-signals.ts +3 -1
- package/packages/public-runtime/src/compliance/profile.ts +184 -166
- package/packages/public-runtime/src/compliance/ruleset.ts +743 -78
- package/packages/public-runtime/src/compliance/state-directory.ts +116 -4
- package/packages/public-runtime/src/tenant.ts +1 -1
- package/packages/public-runtime/tests/fixtures/compliance-decisions.golden.json +100 -38
- package/apps/storefront/src/pages/api/newsletter/confirm.ts +0 -75
- package/apps/storefront/src/pages/api/newsletter/unsubscribe.ts +0 -89
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Newsletter one-click unsubscribe (newsletter-send epic, N3) — the endpoint the
|
|
3
|
-
* unsubscribe footer link and the RFC 8058 `List-Unsubscribe` header both point at.
|
|
4
|
-
* (N4 composes those headers/links; this unit is only the target they hit.)
|
|
5
|
-
*
|
|
6
|
-
* - GET /api/newsletter/unsubscribe?token=… — a clicked email-footer link. Flips
|
|
7
|
-
* the subscriber to `unsubscribed` and renders a plain confirmation page.
|
|
8
|
-
* - POST /api/newsletter/unsubscribe?token=… — the RFC 8058 `List-Unsubscribe-Post:
|
|
9
|
-
* List-Unsubscribe=One-Click` request a mailbox provider (Gmail/Yahoo) fires. Same
|
|
10
|
-
* effect, 200 with no interstitial and no confirmation step.
|
|
11
|
-
*
|
|
12
|
-
* The `token` (query string only — never the email in the URL) is an opaque per-
|
|
13
|
-
* subscriber capability, so this succeeds WITHOUT login in one click. It is idempotent
|
|
14
|
-
* (re-unsubscribing is a no-op success) and NON-LEAKING: an unknown token gets the exact
|
|
15
|
-
* same response as a real one, so an observer can't probe which tokens exist.
|
|
16
|
-
*
|
|
17
|
-
* The front door's cross-site form check admits this route's POST (lib/publication/shared/cdnForward.ts
|
|
18
|
-
* `MACHINE_POST_ROUTES`), so the mailbox provider's origin-less form POST reaches this handler.
|
|
19
|
-
*/
|
|
20
|
-
import type { APIContext } from "astro";
|
|
21
|
-
import { readD1 } from "@/lib/publication/shared/env";
|
|
22
|
-
import { fromD1 } from "@/lib/catalog/d1/catalog";
|
|
23
|
-
import { unsubscribeByToken } from "@/lib/engagement/newsletter/subscribers";
|
|
24
|
-
|
|
25
|
-
export const prerender = false;
|
|
26
|
-
|
|
27
|
-
/** Confirmation page for the clicked-link (GET) path. `noindex`; house serif style. */
|
|
28
|
-
function confirmationPage(): Response {
|
|
29
|
-
const html = `<!doctype html>
|
|
30
|
-
<html lang="en">
|
|
31
|
-
<head>
|
|
32
|
-
<meta charset="utf-8" />
|
|
33
|
-
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
34
|
-
<meta name="robots" content="noindex" />
|
|
35
|
-
<title>Unsubscribed</title>
|
|
36
|
-
<style>
|
|
37
|
-
:root { color-scheme: light dark; }
|
|
38
|
-
body { font-family: ui-serif, Georgia, serif; margin: 0; min-height: 100vh;
|
|
39
|
-
display: grid; place-items: center; padding: 2rem; text-align: center;
|
|
40
|
-
background: #f4f1ea; color: #2f3a34; }
|
|
41
|
-
.card { max-width: 30rem; }
|
|
42
|
-
h1 { font-size: clamp(1.6rem, 4vw, 2.2rem); margin: 0 0 0.75rem; }
|
|
43
|
-
p { color: #5a655e; line-height: 1.6; }
|
|
44
|
-
a { color: #2f3a34; font-weight: 600; }
|
|
45
|
-
</style>
|
|
46
|
-
</head>
|
|
47
|
-
<body>
|
|
48
|
-
<div class="card">
|
|
49
|
-
<h1>You're unsubscribed.</h1>
|
|
50
|
-
<p>You won't receive any more of these emails. Changed your mind? You can always sign up again.</p>
|
|
51
|
-
<p><a href="/">Back to the shop →</a></p>
|
|
52
|
-
</div>
|
|
53
|
-
</body>
|
|
54
|
-
</html>`;
|
|
55
|
-
return new Response(html, {
|
|
56
|
-
status: 200,
|
|
57
|
-
headers: { "content-type": "text/html; charset=utf-8", "cache-control": "no-store" },
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/** Apply the unsubscribe for the token in the query string. Best-effort: never throws,
|
|
62
|
-
* and returns the same value regardless of whether the token was real (non-leaking).
|
|
63
|
-
* When no D1 binding is present (local/dev) it's a silent no-op — the response shape
|
|
64
|
-
* is identical either way. */
|
|
65
|
-
async function applyUnsubscribe(context: APIContext): Promise<void> {
|
|
66
|
-
try {
|
|
67
|
-
const token = new URL(context.request.url).searchParams.get("token") ?? "";
|
|
68
|
-
const d1 = await readD1("STOREFRONT_APPS_DB");
|
|
69
|
-
if (!d1) return;
|
|
70
|
-
await unsubscribeByToken(fromD1(d1), token, new Date().toISOString());
|
|
71
|
-
} catch {
|
|
72
|
-
// Unsubscribe must never error out at the reader — degrade to the same success
|
|
73
|
-
// response. (A failed write is preferable to showing a subscriber an error.)
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export async function GET(context: APIContext): Promise<Response> {
|
|
78
|
-
await applyUnsubscribe(context);
|
|
79
|
-
return confirmationPage();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export async function POST(context: APIContext): Promise<Response> {
|
|
83
|
-
await applyUnsubscribe(context);
|
|
84
|
-
// RFC 8058 one-click: a bare 200, no body of consequence, no confirmation step.
|
|
85
|
-
return new Response("Unsubscribed", {
|
|
86
|
-
status: 200,
|
|
87
|
-
headers: { "content-type": "text/plain; charset=utf-8", "cache-control": "no-store" },
|
|
88
|
-
});
|
|
89
|
-
}
|