create-ailk 0.37.1 → 0.38.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 +129 -0
- package/component-catalog.json +44 -6
- package/component-catalog.md +6 -5
- package/dist/add-module.js +16 -1
- package/dist/add-route.d.ts +2 -2
- package/dist/add-route.js +18 -11
- package/dist/cli.js +52 -0
- package/dist/declined-routes.d.ts +13 -0
- package/dist/declined-routes.js +74 -0
- package/dist/derive-architecture.d.ts +0 -6
- package/dist/derive-architecture.js +9 -15
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/language-import.d.ts +93 -0
- package/dist/language-import.js +270 -43
- package/dist/lib/import-mdx.js +1 -1
- package/dist/lib/scaffold-render-sweep.d.ts +6 -3
- package/dist/lib/scaffold-render-sweep.js +8 -4
- package/dist/migrate-content.d.ts +6 -2
- package/dist/migrate-content.js +62 -5
- package/dist/module-architecture.js +139 -103
- package/dist/paid-sections.d.ts +13 -0
- package/dist/paid-sections.js +35 -5
- package/dist/programmatic.js +6 -16
- package/dist/remove-module.js +67 -0
- package/dist/routes.d.ts +103 -0
- package/dist/routes.js +708 -0
- package/dist/site-manifest.js +1 -1
- package/dist/site-roster.d.ts +2 -1
- package/dist/site-roster.js +30 -8
- package/dist/spoke-checkout.d.ts +28 -27
- package/dist/spoke-checkout.js +71 -102
- package/dist/surfaces.d.ts +18 -0
- package/dist/surfaces.js +47 -282
- package/dist/sync-routes.d.ts +14 -1
- package/dist/sync-routes.js +86 -5
- package/dist/topology.d.ts +15 -1
- package/dist/topology.js +20 -4
- package/dist/update.d.ts +17 -2
- package/dist/update.js +480 -77
- package/package.json +3 -3
- package/templates/README.md +1 -1
- package/templates/apps/mcp/CLAUDE.md +5 -3
- package/templates/apps/web/CLAUDE.md +62 -20
- package/templates/apps/web/account.config.tsx +101 -0
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/[slug]/page.tsx +3 -161
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/page.tsx +3 -139
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/page.tsx +3 -406
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/versions/[version]/file/route.ts +2 -190
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/page.tsx +3 -182
- package/templates/apps/web/app/[locale]/(authed)/account/billing/page.tsx +8 -420
- package/templates/apps/web/app/[locale]/(authed)/account/connect/page.tsx +1 -1
- package/templates/apps/web/app/[locale]/(authed)/account/general/page.tsx +8 -214
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/[kind]/[id]/page.tsx +8 -115
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/route.ts +2 -80
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/page.tsx +8 -121
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/page.tsx +3 -154
- package/templates/apps/web/app/[locale]/(authed)/account/layout.tsx +7 -149
- package/templates/apps/web/app/[locale]/(authed)/account/notifications/page.tsx +3 -143
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/page.tsx +3 -126
- package/templates/apps/web/app/[locale]/(authed)/account/page.tsx +8 -302
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/export/route.ts +2 -102
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/page.tsx +3 -240
- package/templates/apps/web/app/[locale]/(authed)/account/security/page.tsx +3 -131
- package/templates/apps/web/app/[locale]/(authed)/account/settings/page.tsx +2 -24
- package/templates/apps/web/app/[locale]/(authed)/account/support/page.tsx +3 -60
- package/templates/apps/web/app/[locale]/layout.tsx +45 -28
- package/templates/apps/web/app/apple-icon.tsx +72 -0
- package/templates/apps/web/app/llms.txt/__tests__/site-listing.test.ts +22 -12
- package/templates/apps/web/app/og/__tests__/__snapshots__/card.test.tsx.snap +3 -0
- package/templates/apps/web/app/og/__tests__/card.test.tsx +129 -0
- package/templates/apps/web/app/og/__tests__/route.test.ts +3 -4
- package/templates/apps/web/app/og/route.tsx +155 -72
- package/templates/apps/web/app/sitemap.xml/__tests__/site-listing.test.ts +12 -0
- package/templates/apps/web/i18n/request.ts +44 -1
- package/templates/apps/web/jest.config.cjs +13 -1
- package/templates/apps/web/lib/__tests__/auth-phone.test.ts +11 -0
- package/templates/apps/web/lib/__tests__/fixtures/site-topology.ts +70 -0
- package/templates/apps/web/lib/__tests__/nav-label-keys.test.ts +14 -0
- package/templates/apps/web/lib/__tests__/profile-back-link.test.ts +148 -61
- package/templates/apps/web/lib/__tests__/served-pages.test.ts +77 -0
- package/templates/apps/web/lib/__tests__/server-api.test.ts +37 -5
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +26 -13
- package/templates/apps/web/lib/listings.tsx +2 -2
- package/templates/apps/web/lib/nav-label-keys.ts +16 -2
- package/templates/apps/web/lib/paid-section-contracts.ts +35 -6
- package/templates/apps/web/lib/paid-sections.generated.ts +8 -0
- package/templates/apps/web/lib/profile-back-link.ts +105 -32
- package/templates/apps/web/lib/served-pages.ts +95 -0
- package/templates/apps/web/lib/site-brand.tsx +3 -5
- package/templates/apps/web/messages/en.json +8 -684
- package/templates/apps/web/middleware.ts +3 -1
- package/templates/apps/web/next.config.mjs +27 -0
- package/templates/apps/web/package.json +1 -0
- package/templates/customizations.yaml +9 -0
- package/templates/package.json +3 -1
- package/templates/tools/lint-architecture.ts +164 -11
- package/versions.json +48 -47
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/account-frame-sign-out.test.tsx +0 -175
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/agreements-prompt.test.tsx +0 -301
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/billing.test.tsx +0 -515
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/general.test.tsx +0 -883
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/hub-mode.test.tsx +0 -758
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/item.test.tsx +0 -264
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout-sign-out.test.tsx +0 -167
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/layout.test.tsx +0 -730
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-menu.test.tsx +0 -355
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/new-popups.test.tsx +0 -97
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/notifications.test.tsx +0 -375
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/onboarding.test.tsx +0 -323
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/page.test.tsx +0 -1208
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/popups.test.tsx +0 -418
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/privacy.test.tsx +0 -462
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/rich-translator.ts +0 -63
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/security.test.tsx +0 -406
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/settings.test.tsx +0 -93
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/support.test.tsx +0 -208
- package/templates/apps/web/app/[locale]/(authed)/account/__tests__/thread.test.tsx +0 -340
- package/templates/apps/web/app/[locale]/(authed)/account/account-data.ts +0 -182
- package/templates/apps/web/app/[locale]/(authed)/account/account-frame.tsx +0 -353
- package/templates/apps/web/app/[locale]/(authed)/account/actions.ts +0 -57
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-actions.ts +0 -58
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-gate.ts +0 -61
- package/templates/apps/web/app/[locale]/(authed)/account/agreements-prompt.tsx +0 -184
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/__tests__/page.test.tsx +0 -426
- package/templates/apps/web/app/[locale]/(authed)/account/appointments/appointments-data.ts +0 -76
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/pay-form.tsx +0 -65
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/[pieceId]/review-form.tsx +0 -172
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/file-route.test.ts +0 -333
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/page.test.tsx +0 -936
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/pay.test.tsx +0 -193
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/__tests__/review.test.tsx +0 -476
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-actions.ts +0 -184
- package/templates/apps/web/app/[locale]/(authed)/account/artifacts/artifact-data.ts +0 -197
- package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts +0 -99
- package/templates/apps/web/app/[locale]/(authed)/account/billing/offerings.ts +0 -123
- package/templates/apps/web/app/[locale]/(authed)/account/billing-source.ts +0 -303
- package/templates/apps/web/app/[locale]/(authed)/account/components/request-quote.tsx +0 -274
- package/templates/apps/web/app/[locale]/(authed)/account/error-row.tsx +0 -35
- package/templates/apps/web/app/[locale]/(authed)/account/for-you-labels.ts +0 -36
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/phone-verification.test.tsx +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/general/__tests__/seam-imports.test.ts +0 -65
- package/templates/apps/web/app/[locale]/(authed)/account/general/account-name.ts +0 -36
- package/templates/apps/web/app/[locale]/(authed)/account/general/billing-anchor.tsx +0 -27
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-actions.ts +0 -149
- package/templates/apps/web/app/[locale]/(authed)/account/general/contact-details.tsx +0 -42
- package/templates/apps/web/app/[locale]/(authed)/account/general/deletion-request.tsx +0 -132
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-actions.ts +0 -122
- package/templates/apps/web/app/[locale]/(authed)/account/general/phone-verification.tsx +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/general/photo-actions.ts +0 -73
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-form.tsx +0 -107
- package/templates/apps/web/app/[locale]/(authed)/account/general/profile-source.ts +0 -87
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/message/[id]/file/__tests__/route.test.ts +0 -215
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx +0 -43
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-data.ts +0 -88
- package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/thread-write.ts +0 -31
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/invitation-id.test.ts +0 -35
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/__tests__/page.test.tsx +0 -266
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/actions.ts +0 -116
- package/templates/apps/web/app/[locale]/(authed)/account/invitations/[invitationId]/invitation-id.ts +0 -12
- package/templates/apps/web/app/[locale]/(authed)/account/new-actions.ts +0 -219
- package/templates/apps/web/app/[locale]/(authed)/account/new-menu.tsx +0 -365
- package/templates/apps/web/app/[locale]/(authed)/account/new-popups.tsx +0 -86
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/actions.ts +0 -120
- package/templates/apps/web/app/[locale]/(authed)/account/onboarding/onboarding-form.tsx +0 -322
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/__tests__/export-route.test.ts +0 -173
- package/templates/apps/web/app/[locale]/(authed)/account/privacy/actions.ts +0 -103
- package/templates/apps/web/app/[locale]/(authed)/account/profile-actions.ts +0 -116
- package/templates/apps/web/app/[locale]/(authed)/account/retry-button.tsx +0 -27
- package/templates/apps/web/app/[locale]/(authed)/account/security/__tests__/hub-variant.test.tsx +0 -258
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-panel.tsx +0 -130
- package/templates/apps/web/app/[locale]/(authed)/account/security/security-source.ts +0 -92
- package/templates/apps/web/app/[locale]/(authed)/account/settings-frame.tsx +0 -121
- package/templates/apps/web/app/[locale]/(authed)/account/sign-in-method.ts +0 -37
- package/templates/apps/web/app/[locale]/(authed)/account/support/support-form.tsx +0 -98
- package/templates/apps/web/app/[locale]/(authed)/account/support-actions.ts +0 -100
- package/templates/apps/web/app/[locale]/checkout/__tests__/pages.test.tsx +0 -139
- package/templates/apps/web/app/[locale]/checkout/__tests__/thank-you-account.test.tsx +0 -146
- package/templates/apps/web/app/[locale]/checkout/thank-you/page.tsx +0 -114
- package/templates/apps/web/app/[locale]/checkout/unavailable/page.tsx +0 -51
- package/templates/apps/web/app/[locale]/flows/[slug]/FlowStepperClient.tsx +0 -614
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.count.test.tsx +0 -43
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.deliverable.test.tsx +0 -214
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.ending.test.tsx +0 -197
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.invite.test.tsx +0 -286
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.permalink.test.tsx +0 -520
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.test.tsx +0 -376
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/FlowStepperClient.thanks-by-tier.test.tsx +0 -306
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/account-invite.actions.test.ts +0 -69
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/flow.actions.test.ts +0 -398
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/magnet-page.test.tsx +0 -704
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/save.actions.test.ts +0 -173
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/two-route-tool.test.tsx +0 -141
- package/templates/apps/web/app/[locale]/flows/[slug]/__tests__/verify.test.tsx +0 -249
- package/templates/apps/web/app/[locale]/flows/[slug]/account-invite.actions.ts +0 -35
- package/templates/apps/web/app/[locale]/flows/[slug]/email-moment.ts +0 -92
- package/templates/apps/web/app/[locale]/flows/[slug]/flow.actions.ts +0 -177
- package/templates/apps/web/app/[locale]/flows/[slug]/magnet-page.tsx +0 -472
- package/templates/apps/web/app/[locale]/flows/[slug]/page.tsx +0 -48
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/LevelChart.tsx +0 -100
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsCard.tsx +0 -99
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsClient.tsx +0 -820
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/ResultsEmailStep.tsx +0 -203
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.no-commerce.test.tsx +0 -194
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/ResultsClient.report.test.tsx +0 -284
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/by-result.test.tsx +0 -302
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/cards.test.tsx +0 -402
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/landing.test.tsx +0 -293
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/page.test.tsx +0 -485
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/__tests__/score.test.tsx +0 -231
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/checkout-seam.ts +0 -74
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/meeting-seam.ts +0 -36
- package/templates/apps/web/app/[locale]/flows/[slug]/results/[payload]/page.tsx +0 -420
- package/templates/apps/web/app/[locale]/flows/[slug]/save.actions.ts +0 -85
- package/templates/apps/web/app/[locale]/flows/[slug]/served-flow.ts +0 -91
- package/templates/apps/web/app/[locale]/flows/[slug]/start/page.tsx +0 -32
- package/templates/apps/web/app/[locale]/flows/[slug]/verify/page.tsx +0 -153
- package/templates/apps/web/app/[locale]/flows/[slug]/verify.actions.ts +0 -151
- package/templates/apps/web/app/[locale]/meet/confirmed/BookingHandOff.tsx +0 -128
- package/templates/apps/web/app/[locale]/meet/confirmed/__tests__/BookingHandOff.test.tsx +0 -126
- package/templates/apps/web/app/[locale]/purchase/__tests__/cancel.test.tsx +0 -162
- package/templates/apps/web/app/[locale]/purchase/__tests__/module-scope.test.ts +0 -68
- package/templates/apps/web/app/[locale]/purchase/__tests__/success.test.tsx +0 -411
- package/templates/apps/web/app/[locale]/purchase/cancel/page.tsx +0 -115
- package/templates/apps/web/app/[locale]/purchase/success/page.tsx +0 -348
- package/templates/apps/web/lib/__tests__/account-config.test.ts +0 -704
- package/templates/apps/web/lib/account-config.ts +0 -678
- package/templates/apps/web/lib/checkout-config.ts +0 -16
- package/templates/apps/web/src/lib/__tests__/commerce-sections.test.ts +0 -57
- package/templates/apps/web/src/lib/commerce-sections.ts +0 -55
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment node
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The member file read, re-served by the spoke (#7920; SEC-7877-D) —
|
|
7
|
-
* `GET /[locale]/account/inbox/message/:id/file`.
|
|
8
|
-
*
|
|
9
|
-
* A message's file action links here: the browser holds neither the hub
|
|
10
|
-
* credential (sealed in the `hub-session` cookie) nor the spoke key, so the
|
|
11
|
-
* spoke's server reads `GET /v1/member/messages/:id/file` with
|
|
12
|
-
* `forwardedCookieInit()` and streams the bytes back. The api-client's
|
|
13
|
-
* `member.messageFile` is the one external boundary mocked; the seal, the
|
|
14
|
-
* cookie read and the route's decisions are real. Covers:
|
|
15
|
-
* - on a single site (`SIGN_IN_PROVIDER` `"site"`) the read carries the
|
|
16
|
-
* caller's session cookie to the site's own API, and serves the same
|
|
17
|
-
* way (#8231 D9) — the route itself tests no topology;
|
|
18
|
-
* - the read carries the signed-in caller's own credential, and the bytes
|
|
19
|
-
* come back with all five hub headers unchanged;
|
|
20
|
-
* - a hub answer missing any of the five is refused 502 — never bytes on
|
|
21
|
-
* this origin without them;
|
|
22
|
-
* - refusals map to a status with no body and `private, no-store`.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
const mockMessageFile = jest.fn();
|
|
26
|
-
jest.mock("@working-theory/api-client", () => ({
|
|
27
|
-
__esModule: true,
|
|
28
|
-
member: { messageFile: (...args: unknown[]) => mockMessageFile(...args) },
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
const mockProvider: { value: "site" | "hub" | "none" } = { value: "hub" };
|
|
32
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: the sign-in provider is a generated constant (#7894 D8), not a runtime input; the seam IS the boundary between a hub and a hub-mode spoke build, and no env or HTTP surface selects it.
|
|
33
|
-
jest.mock("../../../../../../../../../lib/topology.generated", () => ({
|
|
34
|
-
__esModule: true,
|
|
35
|
-
get SIGN_IN_PROVIDER() {
|
|
36
|
-
return mockProvider.value;
|
|
37
|
-
},
|
|
38
|
-
}));
|
|
39
|
-
|
|
40
|
-
const mockHeaders = jest.fn();
|
|
41
|
-
const mockCookies = jest.fn();
|
|
42
|
-
jest.mock("next/headers", () => ({
|
|
43
|
-
__esModule: true,
|
|
44
|
-
headers: (...args: unknown[]) => mockHeaders(...args),
|
|
45
|
-
cookies: (...args: unknown[]) => mockCookies(...args),
|
|
46
|
-
}));
|
|
47
|
-
|
|
48
|
-
import { seal } from "../../../../../../../../../lib/hub-session/seal";
|
|
49
|
-
import { GET } from "../route";
|
|
50
|
-
|
|
51
|
-
const ENV = process.env;
|
|
52
|
-
const SITE = "https://spoke.example.com";
|
|
53
|
-
const SESSION_SECRET = "s".repeat(43);
|
|
54
|
-
const COOKIE = "__Host-ailk-hub-session";
|
|
55
|
-
const CREDENTIAL = `ailk_hst_${"t".repeat(43)}`;
|
|
56
|
-
const ID = "intx_01920000-0000-7000-8000-000000000004";
|
|
57
|
-
|
|
58
|
-
const FILE_HEADERS = {
|
|
59
|
-
contentType: "application/pdf",
|
|
60
|
-
contentDisposition: 'attachment; filename="brand-guide.pdf"',
|
|
61
|
-
contentTypeOptions: "nosniff",
|
|
62
|
-
contentSecurityPolicy: "default-src 'none'; sandbox",
|
|
63
|
-
cacheControl: "private, no-store",
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
function fileResult(headers: Partial<Record<keyof typeof FILE_HEADERS, string | null>> = {}) {
|
|
67
|
-
return {
|
|
68
|
-
ok: true,
|
|
69
|
-
body: {
|
|
70
|
-
stream: new Response("%PDF-1.7 bytes").body,
|
|
71
|
-
headers: { ...FILE_HEADERS, ...headers },
|
|
72
|
-
},
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function signedIn(): void {
|
|
77
|
-
const sealed = seal(
|
|
78
|
-
{
|
|
79
|
-
v: 1,
|
|
80
|
-
accessToken: CREDENTIAL,
|
|
81
|
-
expiresAt: Date.now() + 60_000,
|
|
82
|
-
user: { name: "Ada", email: "ada@example.com", emailVerified: true, createdAt: "2026-09-01T00:00:00.000Z" },
|
|
83
|
-
},
|
|
84
|
-
SESSION_SECRET,
|
|
85
|
-
"session",
|
|
86
|
-
COOKIE,
|
|
87
|
-
);
|
|
88
|
-
mockHeaders.mockResolvedValue(new Headers({ cookie: `${COOKIE}=${sealed}` }));
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function get(id = ID): Promise<Response> {
|
|
92
|
-
return GET(new Request(`${SITE}/account/inbox/message/${id}/file`), {
|
|
93
|
-
params: Promise.resolve({ locale: "en", id }),
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
beforeEach(() => {
|
|
98
|
-
process.env = {
|
|
99
|
-
...ENV,
|
|
100
|
-
AILK_HUB_SIGN_IN_URL: "https://hub.example.com",
|
|
101
|
-
AILK_HUB_CLIENT_ID: "spoke_0001",
|
|
102
|
-
AILK_HUB_CLIENT_SECRET: `ailk_hcs_${"c".repeat(43)}`,
|
|
103
|
-
AILK_HUB_SESSION_SECRET: SESSION_SECRET,
|
|
104
|
-
NEXT_PUBLIC_BASE_URL: SITE,
|
|
105
|
-
};
|
|
106
|
-
mockProvider.value = "hub";
|
|
107
|
-
mockHeaders.mockReset().mockResolvedValue(new Headers());
|
|
108
|
-
mockCookies.mockReset().mockResolvedValue({ toString: () => "" });
|
|
109
|
-
mockMessageFile.mockReset().mockResolvedValue(fileResult());
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
afterAll(() => {
|
|
113
|
-
process.env = ENV;
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
describe("the member file read on a spoke that signs in through its hub", () => {
|
|
117
|
-
it("reads the file with the caller's own credential and re-serves it with all five headers unchanged", async () => {
|
|
118
|
-
signedIn();
|
|
119
|
-
const res = await get();
|
|
120
|
-
expect(mockMessageFile).toHaveBeenCalledWith(ID, {
|
|
121
|
-
headers: { authorization: `Bearer ${CREDENTIAL}` },
|
|
122
|
-
});
|
|
123
|
-
expect(res.status).toBe(200);
|
|
124
|
-
expect(res.headers.get("content-type")).toBe(FILE_HEADERS.contentType);
|
|
125
|
-
expect(res.headers.get("content-disposition")).toBe(FILE_HEADERS.contentDisposition);
|
|
126
|
-
expect(res.headers.get("x-content-type-options")).toBe(FILE_HEADERS.contentTypeOptions);
|
|
127
|
-
expect(res.headers.get("content-security-policy")).toBe(FILE_HEADERS.contentSecurityPolicy);
|
|
128
|
-
expect(res.headers.get("cache-control")).toBe(FILE_HEADERS.cacheControl);
|
|
129
|
-
await expect(res.text()).resolves.toBe("%PDF-1.7 bytes");
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
it.each(Object.keys(FILE_HEADERS) as (keyof typeof FILE_HEADERS)[])(
|
|
133
|
-
"refuses 502 with no bytes when the hub's answer lacks %s",
|
|
134
|
-
async (name) => {
|
|
135
|
-
signedIn();
|
|
136
|
-
const result = fileResult({ [name]: null });
|
|
137
|
-
const cancel = jest.spyOn(result.body.stream as ReadableStream, "cancel");
|
|
138
|
-
mockMessageFile.mockResolvedValue(result);
|
|
139
|
-
const refused = await get();
|
|
140
|
-
expect(refused.status).toBe(502);
|
|
141
|
-
expect(cancel).toHaveBeenCalled();
|
|
142
|
-
expect(refused.headers.get("cache-control")).toBe("private, no-store");
|
|
143
|
-
expect(refused.headers.get("content-disposition")).toBeNull();
|
|
144
|
-
await expect(refused.text()).resolves.toBe("");
|
|
145
|
-
},
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
it("signed out, the read goes with no credential and its refusal answers 401", async () => {
|
|
149
|
-
mockMessageFile.mockResolvedValue({
|
|
150
|
-
ok: false,
|
|
151
|
-
status: 0,
|
|
152
|
-
body: { ok: false, error: { code: "unauthorized", message: "No usable credential" } },
|
|
153
|
-
});
|
|
154
|
-
const res = await get();
|
|
155
|
-
expect(mockMessageFile).toHaveBeenCalledWith(ID, { headers: {} });
|
|
156
|
-
expect(res.status).toBe(401);
|
|
157
|
-
expect(res.headers.get("cache-control")).toBe("private, no-store");
|
|
158
|
-
await expect(res.text()).resolves.toBe("");
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
it.each([
|
|
162
|
-
[404, 404],
|
|
163
|
-
[401, 401],
|
|
164
|
-
[403, 403],
|
|
165
|
-
[429, 429],
|
|
166
|
-
[500, 502],
|
|
167
|
-
[503, 502],
|
|
168
|
-
])("a hub %i answers %i, with no body", async (hubStatus, status) => {
|
|
169
|
-
signedIn();
|
|
170
|
-
mockMessageFile.mockResolvedValue({
|
|
171
|
-
ok: false,
|
|
172
|
-
status: hubStatus,
|
|
173
|
-
body: { ok: false, error: { code: "x", message: "x" } },
|
|
174
|
-
});
|
|
175
|
-
const res = await get();
|
|
176
|
-
expect(res.status).toBe(status);
|
|
177
|
-
expect(res.headers.get("cache-control")).toBe("private, no-store");
|
|
178
|
-
await expect(res.text()).resolves.toBe("");
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it("an API base the api-client refuses (insecure_transport) answers 502", async () => {
|
|
182
|
-
signedIn();
|
|
183
|
-
mockMessageFile.mockResolvedValue({
|
|
184
|
-
ok: false,
|
|
185
|
-
status: 0,
|
|
186
|
-
body: { ok: false, error: { code: "insecure_transport", message: "x" } },
|
|
187
|
-
});
|
|
188
|
-
expect((await get()).status).toBe(502);
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it("a hub call that throws (network failure, a redirect under redirect: error) answers 502 with no body", async () => {
|
|
192
|
-
signedIn();
|
|
193
|
-
mockMessageFile.mockRejectedValue(new TypeError("fetch failed"));
|
|
194
|
-
const res = await get();
|
|
195
|
-
expect(res.status).toBe(502);
|
|
196
|
-
expect(res.headers.get("cache-control")).toBe("private, no-store");
|
|
197
|
-
await expect(res.text()).resolves.toBe("");
|
|
198
|
-
});
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
describe("on a single site — its own sign-in (#8231 D9)", () => {
|
|
202
|
-
it("reads the file with the caller's session cookie and serves it with all five headers unchanged", async () => {
|
|
203
|
-
mockProvider.value = "site";
|
|
204
|
-
mockCookies.mockResolvedValue({ toString: () => "session=abc" });
|
|
205
|
-
const res = await get();
|
|
206
|
-
expect(mockMessageFile).toHaveBeenCalledWith(ID, { headers: { cookie: "session=abc" } });
|
|
207
|
-
expect(res.status).toBe(200);
|
|
208
|
-
expect(res.headers.get("content-type")).toBe(FILE_HEADERS.contentType);
|
|
209
|
-
expect(res.headers.get("content-disposition")).toBe(FILE_HEADERS.contentDisposition);
|
|
210
|
-
expect(res.headers.get("x-content-type-options")).toBe(FILE_HEADERS.contentTypeOptions);
|
|
211
|
-
expect(res.headers.get("content-security-policy")).toBe(FILE_HEADERS.contentSecurityPolicy);
|
|
212
|
-
expect(res.headers.get("cache-control")).toBe(FILE_HEADERS.cacheControl);
|
|
213
|
-
await expect(res.text()).resolves.toBe("%PDF-1.7 bytes");
|
|
214
|
-
});
|
|
215
|
-
});
|
package/templates/apps/web/app/[locale]/(authed)/account/inbox/thread/member-thread-composer.tsx
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use client"; // binds the shared composer to the member write and the route refresh
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* MemberThreadComposer — the member thread page's composer (#11152): the
|
|
5
|
-
* shared `ThreadComposer` (`@working-theory/templates/account`, the control
|
|
6
|
-
* the Admin's inbox thread shares) bound to `postThreadMessage` and to the
|
|
7
|
-
* router. A sent message refreshes the route, so the page's Server
|
|
8
|
-
* Components read the thread again and the new bubble appears with no
|
|
9
|
-
* reload (the New menu's own idiom after a post); a refusal shows the plain
|
|
10
|
-
* line its code maps to, with the body kept. Only strings cross to the
|
|
11
|
-
* client: the labels and the refusal lines, never the session.
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { ThreadComposer, type ThreadComposerLabels } from "@working-theory/templates/account";
|
|
15
|
-
import { MESSAGE_BODY_MAX } from "@working-theory/validation";
|
|
16
|
-
import { useRouter } from "next/navigation";
|
|
17
|
-
import type { ReactElement } from "react";
|
|
18
|
-
|
|
19
|
-
import type { NewActionErrorCode } from "../../new-actions";
|
|
20
|
-
|
|
21
|
-
import { postThreadMessage } from "./thread-write";
|
|
22
|
-
|
|
23
|
-
export interface MemberThreadComposerProps {
|
|
24
|
-
labels: ThreadComposerLabels;
|
|
25
|
-
/** Each refusal code's plain line (`new.errors.*`). */
|
|
26
|
-
errors: Record<NewActionErrorCode, string>;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function MemberThreadComposer({ labels, errors }: MemberThreadComposerProps): ReactElement {
|
|
30
|
-
const router = useRouter();
|
|
31
|
-
return (
|
|
32
|
-
<ThreadComposer
|
|
33
|
-
labels={labels}
|
|
34
|
-
maxLength={MESSAGE_BODY_MAX}
|
|
35
|
-
send={async (body) => {
|
|
36
|
-
const state = await postThreadMessage(body);
|
|
37
|
-
if (state.kind === "success") return { kind: "sent" };
|
|
38
|
-
return { kind: "refused", message: errors[state.kind === "error" ? state.code : "failed"] };
|
|
39
|
-
}}
|
|
40
|
-
onSent={() => router.refresh()}
|
|
41
|
-
/>
|
|
42
|
-
);
|
|
43
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* thread-data.ts — the member thread page's reads (#11152).
|
|
3
|
-
*
|
|
4
|
-
* The thread is every message between the signed-in person and this
|
|
5
|
-
* workspace: the conversation kinds of `lib/account-config.ts`
|
|
6
|
-
* (`accountChatKinds`) — the provider's messages (`message`,
|
|
7
|
-
* `GET /v1/member/messages`) and the person's own sent requests and messages
|
|
8
|
-
* (`request`, `GET /v1/member/requests`) — merged and sorted OLDEST FIRST,
|
|
9
|
-
* the Admin thread's order, each entry keeping the kind that loaded it so
|
|
10
|
-
* the page renders the same bubble the item page shows. A kind's rejected
|
|
11
|
-
* read sets `failed` (D12: the page shows the error row above what did
|
|
12
|
-
* load, never a silently partial thread); a 404 is already `[]` inside the
|
|
13
|
-
* kind's own `load`.
|
|
14
|
-
*
|
|
15
|
-
* One stream per (person, workspace) — the design decision this page rests
|
|
16
|
-
* on (issue #11152, operator question of 2026-11-08, recorded here because
|
|
17
|
-
* the issue carries no spec): the data model keys every message on exactly
|
|
18
|
-
* that pair (`Interaction` rows on the person's `Person` in this workspace;
|
|
19
|
-
* the member reads above resolve the pair from the credential), and the
|
|
20
|
-
* Admin's thread page is one stream per person. A second stream would need
|
|
21
|
-
* a new subject entity on both sides — a thread id stamped on each
|
|
22
|
-
* `Interaction`, a member read and write that take it, an Admin thread list
|
|
23
|
-
* and page keyed on it — and is not this page's.
|
|
24
|
-
*
|
|
25
|
-
* `threadSubject` — the member composer has one field, no Subject (#11007's
|
|
26
|
-
* composer shape), yet `POST /v1/member/messages` requires one: the subject
|
|
27
|
-
* is cut from the body's first non-blank line, whitespace collapsed and
|
|
28
|
-
* clipped to the server's cap. A blank body yields `""`, which the server
|
|
29
|
-
* refuses — the composer never posts a blank body.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import type {
|
|
33
|
-
AccountContext,
|
|
34
|
-
AccountInboxItem,
|
|
35
|
-
AccountInboxKind,
|
|
36
|
-
} from "@working-theory/templates/account";
|
|
37
|
-
import { MESSAGE_SUBJECT_MAX } from "@working-theory/validation";
|
|
38
|
-
|
|
39
|
-
import { accountChatKinds, accountInboxKinds } from "../../../../../../lib/account-config";
|
|
40
|
-
import { logReadFailure } from "../../account-data";
|
|
41
|
-
|
|
42
|
-
/** One loaded message with the kind it came from — what a bubble is built from. */
|
|
43
|
-
export interface ThreadEntry {
|
|
44
|
-
kind: AccountInboxKind;
|
|
45
|
-
item: AccountInboxItem;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface LoadedThread {
|
|
49
|
-
/** Oldest first. */
|
|
50
|
-
entries: ThreadEntry[];
|
|
51
|
-
/** True when a kind's read rejected (D12). */
|
|
52
|
-
failed: boolean;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/** The conversation kinds, in the config's order. */
|
|
56
|
-
const threadKinds = accountInboxKinds.filter((kind) => accountChatKinds.has(kind.kind));
|
|
57
|
-
|
|
58
|
-
// Both conversation kinds set `at` from the row's `createdAt`; the `""`
|
|
59
|
-
// fallback (an entry with no time sorts first) is `account-data.ts`'s idiom,
|
|
60
|
-
// kept so a kind that omitted it would still render rather than throw.
|
|
61
|
-
const oldestFirst = (a: ThreadEntry, b: ThreadEntry): number =>
|
|
62
|
-
(a.item.at ?? "").localeCompare(b.item.at ?? "");
|
|
63
|
-
|
|
64
|
-
/** Every conversation kind's items, oldest first. A rejected kind sets `failed`. */
|
|
65
|
-
export async function loadThread(ctx: AccountContext): Promise<LoadedThread> {
|
|
66
|
-
const settled = await Promise.allSettled(
|
|
67
|
-
threadKinds.map(async (kind) => (await kind.load(ctx)).map((item) => ({ kind, item }))),
|
|
68
|
-
);
|
|
69
|
-
settled.forEach((r, i) => {
|
|
70
|
-
if (r.status === "rejected") logReadFailure(`thread:${threadKinds[i]!.kind}`, r.reason);
|
|
71
|
-
});
|
|
72
|
-
return {
|
|
73
|
-
entries: settled
|
|
74
|
-
.flatMap((r) => (r.status === "fulfilled" ? r.value : []))
|
|
75
|
-
.sort(oldestFirst),
|
|
76
|
-
failed: settled.some((r) => r.status === "rejected"),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/** The subject the member write needs, cut from the body's first non-blank line. */
|
|
81
|
-
export function threadSubject(body: string): string {
|
|
82
|
-
const line =
|
|
83
|
-
body
|
|
84
|
-
.split(/\r?\n/)
|
|
85
|
-
.map((part) => part.replace(/\s+/g, " ").trim())
|
|
86
|
-
.find((part) => part !== "") ?? "";
|
|
87
|
-
return line.slice(0, MESSAGE_SUBJECT_MAX);
|
|
88
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* thread-write.ts — the member thread composer's post (#11152).
|
|
5
|
-
*
|
|
6
|
-
* The thread's composer has one field; the member write it runs is the
|
|
7
|
-
* EXISTING one — `sendMessage` (`../../new-actions.ts`, #8170's
|
|
8
|
-
* `member.sendMessage`, `POST /v1/member/messages`) — handed the body as
|
|
9
|
-
* typed and a subject cut from its first line (`threadSubject`). No new
|
|
10
|
-
* write, no new route: the message lands as the same inbound `Interaction`
|
|
11
|
-
* on the person's Person the retired lightbox wrote, so the Admin's thread
|
|
12
|
-
* for that person shows it (#11157). The refusal codes are `sendMessage`'s
|
|
13
|
-
* own; the composer's host maps each to its line.
|
|
14
|
-
*
|
|
15
|
-
* Not a `*.actions.ts` file and no `*Action`-suffixed export, for the same
|
|
16
|
-
* reason `new-actions.ts` is not (apps/mcp's parity test reads that suffix;
|
|
17
|
-
* the member writes have no MCP twin by decision). Action input is
|
|
18
|
-
* untrusted: anything but a string is `invalid_input`.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import { sendMessage, type NewActionState } from "../../new-actions";
|
|
22
|
-
|
|
23
|
-
import { threadSubject } from "./thread-data";
|
|
24
|
-
|
|
25
|
-
export async function postThreadMessage(body: unknown): Promise<NewActionState> {
|
|
26
|
-
if (typeof body !== "string") return { kind: "error", code: "invalid_input" };
|
|
27
|
-
const formData = new FormData();
|
|
28
|
-
formData.set("subject", threadSubject(body));
|
|
29
|
-
formData.set("body", body);
|
|
30
|
-
return sendMessage({ kind: "idle" }, formData);
|
|
31
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jest-environment node
|
|
3
|
-
*/
|
|
4
|
-
// `isInvitationId` (#11141): the `invite_` + uuid check the invitation page
|
|
5
|
-
// and its actions run before any call. It lives in a plain module — a
|
|
6
|
-
// synchronous export of the "use server" actions file fails `next build`.
|
|
7
|
-
|
|
8
|
-
import { readFileSync } from "node:fs";
|
|
9
|
-
import { join } from "node:path";
|
|
10
|
-
|
|
11
|
-
import { isInvitationId } from "../invitation-id";
|
|
12
|
-
|
|
13
|
-
describe("isInvitationId", () => {
|
|
14
|
-
it("accepts `invite_` + a lowercase uuid", () => {
|
|
15
|
-
expect(isInvitationId("invite_01920000-0000-7000-8000-000000000001")).toBe(true);
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
it.each([
|
|
19
|
-
"",
|
|
20
|
-
"01920000-0000-7000-8000-000000000001",
|
|
21
|
-
"invite_01920000-0000-7000-8000-00000000000",
|
|
22
|
-
"invite_01920000-0000-7000-8000-0000000000011",
|
|
23
|
-
"invite_01920000-0000-7000-8000-00000000000G",
|
|
24
|
-
"INVITE_01920000-0000-7000-8000-000000000001",
|
|
25
|
-
"invite_01920000-0000-7000-8000-000000000001/accept",
|
|
26
|
-
"../invite_01920000-0000-7000-8000-000000000001",
|
|
27
|
-
])("rejects %j", (value) => {
|
|
28
|
-
expect(isInvitationId(value)).toBe(false);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
it('is not a "use server" module', () => {
|
|
32
|
-
const source = readFileSync(join(__dirname, "..", "invitation-id.ts"), "utf8");
|
|
33
|
-
expect(source).not.toMatch(/^\s*["']use server["']/m);
|
|
34
|
-
});
|
|
35
|
-
});
|
|
@@ -1,266 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The account invitation page (#11106, spec
|
|
3
|
-
* docs/specs/11106-the-workforce-foundation-roles-by-spec.md D5; AC-3's page
|
|
4
|
-
* bullet).
|
|
5
|
-
*
|
|
6
|
-
* - Signed out, the `(authed)` gate redirects the page to
|
|
7
|
-
* `/sign-in?next=…` (asserted on the thrown `NEXT_REDIRECT`), and the
|
|
8
|
-
* mailed URL renders `/sign-in` with the email input's value set.
|
|
9
|
-
* - Signed in: a pending invitation renders the organization, the inviter,
|
|
10
|
-
* the role and Accept — a form POST. A GET of the page reads once and
|
|
11
|
-
* writes nothing.
|
|
12
|
-
* - Accept POSTs `/v1/invitations/:id/accept` with no email in its body and
|
|
13
|
-
* returns to the page with `?joined=1`, or `?error=<code>` on a refusal.
|
|
14
|
-
* - Another address's invitation renders the refusal; a missing one is
|
|
15
|
-
* `notFound()`.
|
|
16
|
-
*
|
|
17
|
-
* The API is the boundary: `fetch` answers here. `next-intl/server` reads the
|
|
18
|
-
* real en.json with placeholders filled.
|
|
19
|
-
*/
|
|
20
|
-
import { render, screen, within } from "@testing-library/react";
|
|
21
|
-
|
|
22
|
-
const mockGetActiveProviderIds = jest.fn();
|
|
23
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: auth-env.ts is a pure env-introspection module with no external boundary to mock instead; a PARTIAL mock, so every predicate the gate and /sign-in call is declared.
|
|
24
|
-
jest.mock("../../../../../../../lib/auth-env", () => ({
|
|
25
|
-
__esModule: true,
|
|
26
|
-
getActiveProviderIds: () => mockGetActiveProviderIds(),
|
|
27
|
-
isResetAvailable: () => false,
|
|
28
|
-
resetSendConfigured: () => false,
|
|
29
|
-
}));
|
|
30
|
-
|
|
31
|
-
const mockGetSession = jest.fn();
|
|
32
|
-
// eslint-disable-next-line no-restricted-syntax -- #507: auth.ts is Better Auth's server singleton (a DB/HTTP boundary); the gate reads its session and /sign-in its secret.
|
|
33
|
-
jest.mock("../../../../../../../auth", () => ({
|
|
34
|
-
__esModule: true,
|
|
35
|
-
auth: { api: { getSession: (...args: unknown[]) => mockGetSession(...args) } },
|
|
36
|
-
resolveSecret: () => "test-secret-for-the-invitation-page-suite",
|
|
37
|
-
}));
|
|
38
|
-
|
|
39
|
-
let mockRequestPathname: string | undefined;
|
|
40
|
-
jest.mock("next/headers", () => ({
|
|
41
|
-
__esModule: true,
|
|
42
|
-
headers: jest.fn(async () => {
|
|
43
|
-
const h = new Headers({ origin: "https://hub.example" });
|
|
44
|
-
if (mockRequestPathname) h.set("x-pathname", mockRequestPathname);
|
|
45
|
-
return h;
|
|
46
|
-
}),
|
|
47
|
-
cookies: jest.fn(async () => ({
|
|
48
|
-
toString: () => "better-auth.session_token=abc",
|
|
49
|
-
get: () => undefined,
|
|
50
|
-
})),
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
jest.mock("next/navigation", () => ({
|
|
54
|
-
__esModule: true,
|
|
55
|
-
redirect: (url: string): never => {
|
|
56
|
-
throw new Error(`NEXT_REDIRECT ${url}`);
|
|
57
|
-
},
|
|
58
|
-
notFound: (): never => {
|
|
59
|
-
throw new Error("NEXT_NOT_FOUND");
|
|
60
|
-
},
|
|
61
|
-
}));
|
|
62
|
-
|
|
63
|
-
jest.mock("@working-theory/web-i18n", () => ({
|
|
64
|
-
__esModule: true,
|
|
65
|
-
readLocales: jest.fn().mockReturnValue(["en", "fr"]),
|
|
66
|
-
}));
|
|
67
|
-
|
|
68
|
-
jest.mock("better-auth/react", () => ({
|
|
69
|
-
__esModule: true,
|
|
70
|
-
createAuthClient: () => ({ signIn: { social: jest.fn(), email: jest.fn() } }),
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
jest.mock("@working-theory/api-client", () => ({
|
|
74
|
-
__esModule: true,
|
|
75
|
-
getApiBase: () => "https://api.hub.example",
|
|
76
|
-
hubSignIn: { clientInfo: jest.fn() },
|
|
77
|
-
}));
|
|
78
|
-
|
|
79
|
-
jest.mock("next-intl/server", () => {
|
|
80
|
-
const messages = jest.requireActual("../../../../../../../messages/en.json") as Record<string, unknown>;
|
|
81
|
-
const lookup = (namespace: string, key: string): unknown =>
|
|
82
|
-
`${namespace}.${key}`
|
|
83
|
-
.split(".")
|
|
84
|
-
.reduce<unknown>(
|
|
85
|
-
(node, part) => (node && typeof node === "object" ? (node as Record<string, unknown>)[part] : undefined),
|
|
86
|
-
messages,
|
|
87
|
-
);
|
|
88
|
-
return {
|
|
89
|
-
__esModule: true,
|
|
90
|
-
getTranslations: async ({ namespace }: { namespace: string }) => {
|
|
91
|
-
const t = (key: string, values?: Record<string, string>): string => {
|
|
92
|
-
const found = lookup(namespace, key);
|
|
93
|
-
return (typeof found === "string" ? found : `${namespace}.${key}`).replace(
|
|
94
|
-
/\{(\w+)\}/g,
|
|
95
|
-
(match, name: string) => values?.[name] ?? match,
|
|
96
|
-
);
|
|
97
|
-
};
|
|
98
|
-
t.has = (key: string): boolean => typeof lookup(namespace, key) === "string";
|
|
99
|
-
return t;
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
import en from "../../../../../../../messages/en.json";
|
|
105
|
-
import SignInPage from "../../../../../(auth)/sign-in/page";
|
|
106
|
-
import AuthedLayout from "../../../../layout";
|
|
107
|
-
import { acceptInvitation } from "../actions";
|
|
108
|
-
import InvitationPage from "../page";
|
|
109
|
-
|
|
110
|
-
const ID = "invite_01920000-0000-7000-8000-000000000001";
|
|
111
|
-
const ADDRESS = "invitee@example.test";
|
|
112
|
-
|
|
113
|
-
type Call = { url: string; method: string; body: unknown; headers: Record<string, string> };
|
|
114
|
-
const calls: Call[] = [];
|
|
115
|
-
let answer: { status: number; body: unknown } = { status: 200, body: null };
|
|
116
|
-
|
|
117
|
-
const realFetch = globalThis.fetch;
|
|
118
|
-
beforeEach(() => {
|
|
119
|
-
calls.length = 0;
|
|
120
|
-
mockRequestPathname = undefined;
|
|
121
|
-
mockGetActiveProviderIds.mockReset().mockReturnValue(["google", "email", "magic-link"]);
|
|
122
|
-
mockGetSession.mockReset().mockResolvedValue({ user: { email: ADDRESS, emailVerified: true } });
|
|
123
|
-
globalThis.fetch = jest.fn(async (input: RequestInfo | URL, init?: RequestInit) => {
|
|
124
|
-
calls.push({
|
|
125
|
-
url: String(input),
|
|
126
|
-
method: init?.method ?? "GET",
|
|
127
|
-
body: init?.body ?? null,
|
|
128
|
-
headers: (init?.headers ?? {}) as Record<string, string>,
|
|
129
|
-
});
|
|
130
|
-
// A minimal answer: jsdom's global scope has no `Response`.
|
|
131
|
-
const { status, body } = answer;
|
|
132
|
-
// eslint-disable-next-line no-restricted-syntax -- the fetch boundary's double: the actions read only `status` and `json()`, and jsdom has no Response to build a real one.
|
|
133
|
-
return { status, json: async () => body } as unknown as Response;
|
|
134
|
-
}) as typeof fetch;
|
|
135
|
-
});
|
|
136
|
-
afterAll(() => {
|
|
137
|
-
globalThis.fetch = realFetch;
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
const pending = {
|
|
141
|
-
ok: true,
|
|
142
|
-
data: {
|
|
143
|
-
organizationName: "Acme Studio",
|
|
144
|
-
inviterName: "Sam Rivera",
|
|
145
|
-
role: "editor",
|
|
146
|
-
status: "pending",
|
|
147
|
-
expiresAt: new Date(Date.now() + 86_400_000).toISOString(),
|
|
148
|
-
},
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
async function renderInvitation(search: Record<string, string> = {}): Promise<void> {
|
|
152
|
-
const el = await InvitationPage({
|
|
153
|
-
params: Promise.resolve({ locale: "en", invitationId: ID }),
|
|
154
|
-
searchParams: Promise.resolve(search),
|
|
155
|
-
});
|
|
156
|
-
render(el);
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
describe("signed out", () => {
|
|
160
|
-
it("the (authed) gate redirects the page to /sign-in?next=…", async () => {
|
|
161
|
-
mockGetSession.mockResolvedValue(null);
|
|
162
|
-
mockRequestPathname = `/account/invitations/${ID}`;
|
|
163
|
-
await expect(
|
|
164
|
-
AuthedLayout({ children: null, params: Promise.resolve({ locale: "en" }) }),
|
|
165
|
-
).rejects.toThrow(`NEXT_REDIRECT /sign-in?next=${encodeURIComponent(`/account/invitations/${ID}`)}`);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
it("the mailed URL renders /sign-in with the invited address in the email input", async () => {
|
|
169
|
-
const mailed = new URL(
|
|
170
|
-
`https://hub.example/sign-in?next=%2Faccount%2Finvitations%2F${ID}&email=${encodeURIComponent(ADDRESS)}`,
|
|
171
|
-
);
|
|
172
|
-
const el = await SignInPage({
|
|
173
|
-
params: Promise.resolve({ locale: "en" }),
|
|
174
|
-
searchParams: Promise.resolve(Object.fromEntries(mailed.searchParams)),
|
|
175
|
-
});
|
|
176
|
-
render(el);
|
|
177
|
-
expect(mailed.pathname).toBe("/sign-in");
|
|
178
|
-
expect(screen.getByTestId("auth-email")).toHaveValue(ADDRESS);
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
describe("signed in", () => {
|
|
183
|
-
it("a pending invitation renders the organization, inviter and role, and Accept is a form POST", async () => {
|
|
184
|
-
answer = { status: 200, body: pending };
|
|
185
|
-
await renderInvitation();
|
|
186
|
-
expect(screen.getByTestId("account-invitation-lead")).toHaveTextContent(
|
|
187
|
-
"Sam Rivera invited you to join Acme Studio as an editor.",
|
|
188
|
-
);
|
|
189
|
-
const form = screen.getByTestId("account-invitation-form");
|
|
190
|
-
expect(form.tagName).toBe("FORM");
|
|
191
|
-
expect(within(form).getByTestId("account-invitation-accept")).toHaveAttribute("type", "submit");
|
|
192
|
-
expect(within(form).getByTestId("account-invitation-accept")).toHaveTextContent(en.account.invitation.accept);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("a GET of the page reads once and writes nothing", async () => {
|
|
196
|
-
answer = { status: 200, body: pending };
|
|
197
|
-
await renderInvitation();
|
|
198
|
-
expect(calls).toHaveLength(1);
|
|
199
|
-
expect(calls[0]).toMatchObject({ url: `https://api.hub.example/v1/invitations/${ID}`, method: "GET" });
|
|
200
|
-
expect(calls[0]!.headers.cookie).toBe("better-auth.session_token=abc");
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
it("another address's invitation renders the refusal", async () => {
|
|
204
|
-
answer = {
|
|
205
|
-
status: 403,
|
|
206
|
-
body: { ok: false, error: { code: "invitation_for_another_address", message: "Forbidden" } },
|
|
207
|
-
};
|
|
208
|
-
await renderInvitation();
|
|
209
|
-
expect(screen.getByTestId("account-invitation-other-address")).toHaveTextContent(
|
|
210
|
-
"This invitation is for a different email address. Sign out and sign in with the invited address.",
|
|
211
|
-
);
|
|
212
|
-
expect(screen.queryByTestId("account-invitation-form")).toBeNull();
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("a missing invitation, or a malformed id, is notFound()", async () => {
|
|
216
|
-
answer = { status: 404, body: { ok: false, error: { code: "not_found", message: "Not found" } } };
|
|
217
|
-
await expect(renderInvitation()).rejects.toThrow("NEXT_NOT_FOUND");
|
|
218
|
-
calls.length = 0;
|
|
219
|
-
await expect(
|
|
220
|
-
InvitationPage({
|
|
221
|
-
params: Promise.resolve({ locale: "en", invitationId: "../../admin" }),
|
|
222
|
-
searchParams: Promise.resolve({}),
|
|
223
|
-
}),
|
|
224
|
-
).rejects.toThrow("NEXT_NOT_FOUND");
|
|
225
|
-
expect(calls).toHaveLength(0);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it("after joining it reads You've joined <organization>.", async () => {
|
|
229
|
-
answer = { status: 200, body: { ok: true, data: { ...pending.data, status: "accepted" } } };
|
|
230
|
-
await renderInvitation({ joined: "1" });
|
|
231
|
-
expect(screen.getByTestId("account-invitation-joined")).toHaveTextContent("You've joined Acme Studio.");
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
it("a refusal returned by accept shows its line beside the form", async () => {
|
|
235
|
-
answer = { status: 200, body: pending };
|
|
236
|
-
await renderInvitation({ error: "invitation_expired" });
|
|
237
|
-
expect(screen.getByTestId("account-invitation-error")).toHaveTextContent(en.account.invitation.expired);
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
describe("acceptInvitation", () => {
|
|
242
|
-
it("POSTs accept with the session and no email, then returns with ?joined=1", async () => {
|
|
243
|
-
answer = { status: 200, body: { ok: true, data: { status: "accepted", organizationName: "Acme Studio", role: "editor" } } };
|
|
244
|
-
await expect(acceptInvitation(ID, "en")).rejects.toThrow(`NEXT_REDIRECT /account/invitations/${ID}?joined=1`);
|
|
245
|
-
expect(calls).toHaveLength(1);
|
|
246
|
-
expect(calls[0]).toMatchObject({ url: `https://api.hub.example/v1/invitations/${ID}/accept`, method: "POST", body: "{}" });
|
|
247
|
-
expect(calls[0]!.headers.origin).toBe("https://hub.example");
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
it.each([
|
|
251
|
-
["invitation_expired", 409],
|
|
252
|
-
["invitation_for_another_address", 403],
|
|
253
|
-
["invitation_void", 409],
|
|
254
|
-
])("a %s refusal returns with ?error=%s", async (code, status) => {
|
|
255
|
-
answer = { status, body: { ok: false, error: { code, message: "x" } } };
|
|
256
|
-
await expect(acceptInvitation(ID, "en")).rejects.toThrow(`NEXT_REDIRECT /account/invitations/${ID}?error=${code}`);
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
it("anything else, or a malformed id, returns ?error=failed", async () => {
|
|
260
|
-
answer = { status: 500, body: null };
|
|
261
|
-
await expect(acceptInvitation(ID, "en")).rejects.toThrow(`?error=failed`);
|
|
262
|
-
calls.length = 0;
|
|
263
|
-
await expect(acceptInvitation("nope", "en")).rejects.toThrow(`?error=failed`);
|
|
264
|
-
expect(calls).toHaveLength(0);
|
|
265
|
-
});
|
|
266
|
-
});
|