create-ailk 0.37.0 → 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 +149 -2
- 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 +7 -2
- package/dist/add-route.js +28 -13
- 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 +28 -1
- package/dist/sync-routes.js +144 -11
- package/dist/template-record.d.ts +11 -0
- package/dist/template-record.js +18 -0
- package/dist/topology.d.ts +15 -1
- package/dist/topology.js +20 -4
- package/dist/update.d.ts +31 -2
- package/dist/update.js +627 -99
- 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,122 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* general/phone-actions.ts — User settings › General's phone step (#11106,
|
|
5
|
-
* spec docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9).
|
|
6
|
-
*
|
|
7
|
-
* Three server actions over Better Auth's phone plugin, each a SERVER call
|
|
8
|
-
* with the request's own headers, so the plugin and its guard (`auth.ts`'s
|
|
9
|
-
* `phoneVerificationGuard`) see the person's session:
|
|
10
|
-
*
|
|
11
|
-
* - `sendPhoneCode` → `auth.api.sendPhoneNumberOTP` — texts a six-digit
|
|
12
|
-
* code through the apps/api relay;
|
|
13
|
-
* - `verifyPhoneCode` → `auth.api.verifyPhoneNumber({ updatePhoneNumber:
|
|
14
|
-
* true })` — the one writer of `phoneNumber` and `phoneNumberVerified`;
|
|
15
|
-
* - `removePhone` → `auth.api.updateUser({ phoneNumber: null })`, which
|
|
16
|
-
* the plugin turns into `phoneNumberVerified: false`.
|
|
17
|
-
*
|
|
18
|
-
* Each reaches the plugin through the generated seam's `loadPhoneApi`
|
|
19
|
-
* (`lib/topology.generated.ts`, #11138), never `auth.ts` directly, so a spoke
|
|
20
|
-
* that signs in through its hub keeps this file: there the seam answers null
|
|
21
|
-
* and every action answers `unavailable`.
|
|
22
|
-
*
|
|
23
|
-
* They take no identity argument: who comes from the session alone. Each
|
|
24
|
-
* answers `{ ok: true }` or a refusal `reason` the island maps to its own
|
|
25
|
-
* line. No log line, and no answer, carries the number or the code: a log
|
|
26
|
-
* line names the action and the plugin's error code only.
|
|
27
|
-
*
|
|
28
|
-
* Not a `*.actions.ts` file and no `*Action`-suffixed export: the phone step
|
|
29
|
-
* is a person's own act on the hub, with no MCP twin (apps/mcp's parity test
|
|
30
|
-
* reads that suffix).
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
import { headers } from "next/headers";
|
|
34
|
-
|
|
35
|
-
import { loadPhoneApi } from "../../../../../lib/topology.generated";
|
|
36
|
-
|
|
37
|
-
export type PhoneActionResult =
|
|
38
|
-
| { ok: true }
|
|
39
|
-
| {
|
|
40
|
-
ok: false;
|
|
41
|
-
reason:
|
|
42
|
-
| "invalid_number"
|
|
43
|
-
| "invalid_code"
|
|
44
|
-
| "taken"
|
|
45
|
-
| "too_many"
|
|
46
|
-
| "unverified"
|
|
47
|
-
| "signed_out"
|
|
48
|
-
| "unavailable"
|
|
49
|
-
| "failed";
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
/** The plugin's error code of a thrown `APIError`, when it has one. */
|
|
53
|
-
function errorCode(err: unknown): string | null {
|
|
54
|
-
const code = (err as { body?: { code?: unknown } } | null)?.body?.code;
|
|
55
|
-
return typeof code === "string" ? code : null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const REASONS: Record<string, Exclude<PhoneActionResult, { ok: true }>["reason"]> = {
|
|
59
|
-
INVALID_PHONE_NUMBER: "invalid_number",
|
|
60
|
-
INVALID_OTP: "invalid_code",
|
|
61
|
-
OTP_EXPIRED: "invalid_code",
|
|
62
|
-
OTP_NOT_FOUND: "invalid_code",
|
|
63
|
-
TOO_MANY_ATTEMPTS: "too_many",
|
|
64
|
-
PHONE_NUMBER_EXIST: "taken",
|
|
65
|
-
EMAIL_NOT_VERIFIED: "unverified",
|
|
66
|
-
SESSION_REQUIRED: "signed_out",
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
function refused(action: string, err: unknown): PhoneActionResult {
|
|
70
|
-
const code = errorCode(err);
|
|
71
|
-
console.error(`[phone-actions] ${action} refused code=${code ?? "none"}`);
|
|
72
|
-
return { ok: false, reason: (code && REASONS[code]) || "failed" };
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const isText = (value: unknown, max: number): value is string =>
|
|
76
|
-
typeof value === "string" && value.length > 0 && value.length <= max;
|
|
77
|
-
|
|
78
|
-
export async function sendPhoneCode(phoneNumber: unknown): Promise<PhoneActionResult> {
|
|
79
|
-
// Action input is untrusted: the plugin's validator is the real check.
|
|
80
|
-
if (!isText(phoneNumber, 16)) return { ok: false, reason: "invalid_number" };
|
|
81
|
-
// The generated seam: null on a spoke or a build without the step.
|
|
82
|
-
const api = await loadPhoneApi();
|
|
83
|
-
if (!api) return { ok: false, reason: "unavailable" };
|
|
84
|
-
try {
|
|
85
|
-
await api.sendPhoneNumberOTP({ body: { phoneNumber }, headers: await headers() });
|
|
86
|
-
return { ok: true };
|
|
87
|
-
} catch (err) {
|
|
88
|
-
return refused("sendPhoneCode", err);
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export async function verifyPhoneCode(
|
|
93
|
-
phoneNumber: unknown,
|
|
94
|
-
code: unknown,
|
|
95
|
-
): Promise<PhoneActionResult> {
|
|
96
|
-
if (!isText(phoneNumber, 16)) return { ok: false, reason: "invalid_number" };
|
|
97
|
-
if (!isText(code, 6)) return { ok: false, reason: "invalid_code" };
|
|
98
|
-
const api = await loadPhoneApi();
|
|
99
|
-
if (!api) return { ok: false, reason: "unavailable" };
|
|
100
|
-
try {
|
|
101
|
-
await api.verifyPhoneNumber({
|
|
102
|
-
body: { phoneNumber, code, updatePhoneNumber: true },
|
|
103
|
-
headers: await headers(),
|
|
104
|
-
});
|
|
105
|
-
return { ok: true };
|
|
106
|
-
} catch (err) {
|
|
107
|
-
return refused("verifyPhoneCode", err);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
export async function removePhone(): Promise<PhoneActionResult> {
|
|
112
|
-
const api = await loadPhoneApi();
|
|
113
|
-
if (!api) return { ok: false, reason: "unavailable" };
|
|
114
|
-
try {
|
|
115
|
-
// The plugin's own clearing write (`phoneNumber: null` also sets
|
|
116
|
-
// `phoneNumberVerified: false`).
|
|
117
|
-
await api.updateUser({ body: { phoneNumber: null }, headers: await headers() });
|
|
118
|
-
return { ok: true };
|
|
119
|
-
} catch (err) {
|
|
120
|
-
return refused("removePhone", err);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
@@ -1,215 +0,0 @@
|
|
|
1
|
-
"use client"; // owns the number and code fields and the three action calls
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* PhoneVerification — User settings › General's phone step (#11106, spec
|
|
5
|
-
* docs/specs/11106-the-workforce-foundation-roles-by-spec.md D9).
|
|
6
|
-
*
|
|
7
|
-
* The one place a person sets their own phone. Two states:
|
|
8
|
-
*
|
|
9
|
-
* - no verified number: the number field and Send code; once a code is
|
|
10
|
-
* sent, the code field and Verify (`verifyPhoneCode`, which writes the
|
|
11
|
-
* number only after the code matches);
|
|
12
|
-
* - a verified number: the number with "Verified" and Remove.
|
|
13
|
-
*
|
|
14
|
-
* `available: false` (a build without the step) renders the not-available
|
|
15
|
-
* line, and an unverified email renders the confirm-email line, with no
|
|
16
|
-
* form. Every string arrives as a prop from the page's `account.profile.*`
|
|
17
|
-
* messages; the number and the code never leave this island except to the
|
|
18
|
-
* server actions, which log neither.
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
import {
|
|
22
|
-
Badge,
|
|
23
|
-
Button,
|
|
24
|
-
Field,
|
|
25
|
-
Heading,
|
|
26
|
-
InlineMessage,
|
|
27
|
-
Input,
|
|
28
|
-
Text,
|
|
29
|
-
} from "@working-theory/ui/primitives";
|
|
30
|
-
import { useRouter } from "next/navigation";
|
|
31
|
-
import { useState, useTransition, type FormEvent, type ReactElement } from "react";
|
|
32
|
-
|
|
33
|
-
import {
|
|
34
|
-
removePhone,
|
|
35
|
-
sendPhoneCode,
|
|
36
|
-
verifyPhoneCode,
|
|
37
|
-
type PhoneActionResult,
|
|
38
|
-
} from "./phone-actions";
|
|
39
|
-
|
|
40
|
-
export interface PhoneVerificationLabels {
|
|
41
|
-
title: string;
|
|
42
|
-
lead: string;
|
|
43
|
-
number: string;
|
|
44
|
-
numberHint: string;
|
|
45
|
-
sendCode: string;
|
|
46
|
-
sending: string;
|
|
47
|
-
code: string;
|
|
48
|
-
codeHint: string;
|
|
49
|
-
verify: string;
|
|
50
|
-
verifying: string;
|
|
51
|
-
verified: string;
|
|
52
|
-
remove: string;
|
|
53
|
-
sent: string;
|
|
54
|
-
unavailable: string;
|
|
55
|
-
unverifiedEmail: string;
|
|
56
|
-
errors: Record<Exclude<PhoneActionResult, { ok: true }>["reason"], string>;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export function PhoneVerification({
|
|
60
|
-
available,
|
|
61
|
-
emailVerified,
|
|
62
|
-
phone,
|
|
63
|
-
labels,
|
|
64
|
-
}: {
|
|
65
|
-
available: boolean;
|
|
66
|
-
emailVerified: boolean;
|
|
67
|
-
phone: { number: string; verified: boolean } | null;
|
|
68
|
-
labels: PhoneVerificationLabels;
|
|
69
|
-
}): ReactElement {
|
|
70
|
-
const router = useRouter();
|
|
71
|
-
const [number, setNumber] = useState("");
|
|
72
|
-
const [code, setCode] = useState("");
|
|
73
|
-
const [codeSent, setCodeSent] = useState(false);
|
|
74
|
-
const [error, setError] = useState<string | null>(null);
|
|
75
|
-
const [pending, startTransition] = useTransition();
|
|
76
|
-
|
|
77
|
-
const run = (action: () => Promise<PhoneActionResult>, onOk: () => void) => {
|
|
78
|
-
setError(null);
|
|
79
|
-
startTransition(async () => {
|
|
80
|
-
const result = await action();
|
|
81
|
-
if (result.ok) onOk();
|
|
82
|
-
else setError(labels.errors[result.reason]);
|
|
83
|
-
});
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const onSend = (event: FormEvent<HTMLFormElement>) => {
|
|
87
|
-
event.preventDefault();
|
|
88
|
-
run(
|
|
89
|
-
() => sendPhoneCode(number.trim()),
|
|
90
|
-
() => setCodeSent(true),
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const onVerify = (event: FormEvent<HTMLFormElement>) => {
|
|
95
|
-
event.preventDefault();
|
|
96
|
-
run(
|
|
97
|
-
() => verifyPhoneCode(number.trim(), code.trim()),
|
|
98
|
-
() => {
|
|
99
|
-
setCode("");
|
|
100
|
-
setCodeSent(false);
|
|
101
|
-
router.refresh();
|
|
102
|
-
},
|
|
103
|
-
);
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const onRemove = () => run(removePhone, () => router.refresh());
|
|
107
|
-
|
|
108
|
-
let body: ReactElement;
|
|
109
|
-
if (!available) {
|
|
110
|
-
body = (
|
|
111
|
-
<Text as="p" variant="body-sm" tone="muted" data-testid="account-phone-unavailable">
|
|
112
|
-
{labels.unavailable}
|
|
113
|
-
</Text>
|
|
114
|
-
);
|
|
115
|
-
} else if (phone?.verified) {
|
|
116
|
-
body = (
|
|
117
|
-
<div className="flex flex-wrap items-center gap-3" data-testid="account-phone-verified">
|
|
118
|
-
<Text as="span" variant="body" data-testid="account-phone-number">
|
|
119
|
-
{phone.number}
|
|
120
|
-
</Text>
|
|
121
|
-
<Badge data-testid="account-phone-verified-badge">{labels.verified}</Badge>
|
|
122
|
-
<Button
|
|
123
|
-
type="button"
|
|
124
|
-
variant="ghost"
|
|
125
|
-
size="big"
|
|
126
|
-
disabled={pending}
|
|
127
|
-
onClick={onRemove}
|
|
128
|
-
data-testid="account-phone-remove"
|
|
129
|
-
>
|
|
130
|
-
{labels.remove}
|
|
131
|
-
</Button>
|
|
132
|
-
</div>
|
|
133
|
-
);
|
|
134
|
-
} else if (!emailVerified) {
|
|
135
|
-
body = (
|
|
136
|
-
<Text as="p" variant="body-sm" tone="muted" data-testid="account-phone-unverified-email">
|
|
137
|
-
{labels.unverifiedEmail}
|
|
138
|
-
</Text>
|
|
139
|
-
);
|
|
140
|
-
} else {
|
|
141
|
-
body = (
|
|
142
|
-
<div className="flex flex-col gap-4">
|
|
143
|
-
<form onSubmit={onSend} className="flex flex-col gap-3" data-testid="account-phone-send-form">
|
|
144
|
-
<Field label={labels.number} htmlFor="account-phone-number-input" helperText={labels.numberHint}>
|
|
145
|
-
<Input
|
|
146
|
-
type="tel"
|
|
147
|
-
size="big"
|
|
148
|
-
inputMode="tel"
|
|
149
|
-
autoComplete="tel"
|
|
150
|
-
value={number}
|
|
151
|
-
onChange={(e) => setNumber(e.target.value)}
|
|
152
|
-
required
|
|
153
|
-
data-testid="account-phone-number-input"
|
|
154
|
-
/>
|
|
155
|
-
</Field>
|
|
156
|
-
<Button
|
|
157
|
-
type="submit"
|
|
158
|
-
variant="secondary"
|
|
159
|
-
size="big"
|
|
160
|
-
disabled={pending || number.trim() === ""}
|
|
161
|
-
data-testid="account-phone-send"
|
|
162
|
-
>
|
|
163
|
-
{pending && !codeSent ? labels.sending : labels.sendCode}
|
|
164
|
-
</Button>
|
|
165
|
-
</form>
|
|
166
|
-
{codeSent ? (
|
|
167
|
-
<form onSubmit={onVerify} className="flex flex-col gap-3" data-testid="account-phone-verify-form">
|
|
168
|
-
<InlineMessage variant="success" role="status" data-testid="account-phone-sent">
|
|
169
|
-
{labels.sent}
|
|
170
|
-
</InlineMessage>
|
|
171
|
-
<Field label={labels.code} htmlFor="account-phone-code-input" helperText={labels.codeHint}>
|
|
172
|
-
<Input
|
|
173
|
-
type="text"
|
|
174
|
-
size="big"
|
|
175
|
-
inputMode="numeric"
|
|
176
|
-
autoComplete="one-time-code"
|
|
177
|
-
maxLength={6}
|
|
178
|
-
value={code}
|
|
179
|
-
onChange={(e) => setCode(e.target.value)}
|
|
180
|
-
required
|
|
181
|
-
data-testid="account-phone-code-input"
|
|
182
|
-
/>
|
|
183
|
-
</Field>
|
|
184
|
-
<Button
|
|
185
|
-
type="submit"
|
|
186
|
-
size="big"
|
|
187
|
-
disabled={pending || code.trim() === ""}
|
|
188
|
-
data-testid="account-phone-verify"
|
|
189
|
-
>
|
|
190
|
-
{pending ? labels.verifying : labels.verify}
|
|
191
|
-
</Button>
|
|
192
|
-
</form>
|
|
193
|
-
) : null}
|
|
194
|
-
</div>
|
|
195
|
-
);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return (
|
|
199
|
-
<section className="flex flex-col gap-3" data-testid="account-phone-section" aria-labelledby="account-phone-title">
|
|
200
|
-
{/* A level-2 heading: one group of the pane, beside Contact details (#11167 ruling 11). */}
|
|
201
|
-
<Heading level={2} visual={4} id="account-phone-title">
|
|
202
|
-
{labels.title}
|
|
203
|
-
</Heading>
|
|
204
|
-
<Text as="p" variant="body-sm" tone="muted">
|
|
205
|
-
{labels.lead}
|
|
206
|
-
</Text>
|
|
207
|
-
{body}
|
|
208
|
-
{error ? (
|
|
209
|
-
<InlineMessage variant="error" role="alert" data-testid="account-phone-error">
|
|
210
|
-
{error}
|
|
211
|
-
</InlineMessage>
|
|
212
|
-
) : null}
|
|
213
|
-
</section>
|
|
214
|
-
);
|
|
215
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* general/photo-actions.ts — User settings › General's photo write on the
|
|
5
|
-
* member path (#11167 ruling 5).
|
|
6
|
-
*
|
|
7
|
-
* The member General renders no Name field: the account name follows the
|
|
8
|
-
* contact's first and last names (`contact-actions.ts`), so the profile form
|
|
9
|
-
* saves the photo alone — `member.updateProfile({ image })`, `PATCH
|
|
10
|
-
* /v1/member/profile` with no `name` key, so a person who has not set a name
|
|
11
|
-
* yet can still set their photo. `null` (or a blank link) clears it. The
|
|
12
|
-
* session is not re-sealed: a hub session carries no photo (`profile-source.ts`
|
|
13
|
-
* reads it from the member API instead).
|
|
14
|
-
*
|
|
15
|
-
* It sends `forwardedCookieInit()`'s init, as `profile-actions.ts`'s
|
|
16
|
-
* `saveProfile` does, and maps the same refusals: `photo` (`400
|
|
17
|
-
* link_not_https`), `unverified` (`403`), `unavailable` (`404`, `503`), else
|
|
18
|
-
* `failed`. Logs carry a status or `err.name` only — never a link.
|
|
19
|
-
*
|
|
20
|
-
* Not a `*.actions.ts` file and no `*Action`-suffixed export: the write has no
|
|
21
|
-
* MCP twin by decision (8170's header), and apps/mcp's parity test reads that
|
|
22
|
-
* suffix.
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
|
-
import { member } from "@working-theory/api-client";
|
|
26
|
-
|
|
27
|
-
import { forwardedCookieInit } from "../../../../../lib/server-api";
|
|
28
|
-
|
|
29
|
-
/** PII-safe error identity for logs (the `profile-actions.ts` idiom: `err.name` only). */
|
|
30
|
-
function errorName(err: unknown): string {
|
|
31
|
-
return err instanceof Error ? err.name : "unknown";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/** The `error.code` of a member write's refusal body, when it has one. */
|
|
35
|
-
function errorCode(body: unknown): string | null {
|
|
36
|
-
if (typeof body !== "object" || body === null) return null;
|
|
37
|
-
const error = (body as { error?: unknown }).error;
|
|
38
|
-
if (typeof error !== "object" || error === null) return null;
|
|
39
|
-
const code = (error as { code?: unknown }).code;
|
|
40
|
-
return typeof code === "string" ? code : null;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export type SavePhotoResult =
|
|
44
|
-
| { ok: true; image: string | null }
|
|
45
|
-
| { ok: false; reason: "photo" | "unverified" | "unavailable" | "failed" };
|
|
46
|
-
|
|
47
|
-
/** Saves the member's photo alone: `null` or a blank link clears it. */
|
|
48
|
-
export async function savePhoto(
|
|
49
|
-
image: string | null,
|
|
50
|
-
): Promise<SavePhotoResult> {
|
|
51
|
-
// Action input is untrusted: anything but a string or null is refused,
|
|
52
|
-
// never read as "clear the photo".
|
|
53
|
-
if (image !== null && typeof image !== "string")
|
|
54
|
-
return { ok: false, reason: "photo" };
|
|
55
|
-
try {
|
|
56
|
-
const res = await member.updateProfile(
|
|
57
|
-
{ image: image?.trim() || null },
|
|
58
|
-
await forwardedCookieInit(),
|
|
59
|
-
);
|
|
60
|
-
if (res.ok) return { ok: true, image: res.body.image };
|
|
61
|
-
console.error(`[photo-actions] savePhoto status=${res.status}`);
|
|
62
|
-
if (res.status === 400 && errorCode(res.body) === "link_not_https") {
|
|
63
|
-
return { ok: false, reason: "photo" };
|
|
64
|
-
}
|
|
65
|
-
if (res.status === 403) return { ok: false, reason: "unverified" };
|
|
66
|
-
if (res.status === 404 || res.status === 503)
|
|
67
|
-
return { ok: false, reason: "unavailable" };
|
|
68
|
-
return { ok: false, reason: "failed" };
|
|
69
|
-
} catch (err) {
|
|
70
|
-
console.error(`[photo-actions] savePhoto errName=${errorName(err)}`);
|
|
71
|
-
return { ok: false, reason: "failed" };
|
|
72
|
-
}
|
|
73
|
-
}
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use client"; // owns the save call and the router.refresh() that follows it
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* GeneralSettings — User settings › General's adapter over the shared
|
|
5
|
-
* `AccountSettings` composition (#8339 D8; builds on #8232 D3, D4).
|
|
6
|
-
*
|
|
7
|
-
* Rewritten in place from `ProfileForm` (#7430 → #8232), which rendered its
|
|
8
|
-
* own form. The form, the color logic and the markup now live in
|
|
9
|
-
* `@working-theory/templates/account`'s `AccountSettings` (spec 8339 D4);
|
|
10
|
-
* this file supplies `profile` and `onSave` from `via` (General's
|
|
11
|
-
* `loadProfileSource`, D3):
|
|
12
|
-
*
|
|
13
|
-
* - `member` — no Name field (#11167 ruling 5: the account name follows
|
|
14
|
-
* the contact's first and last names, `contact-actions.ts`), so the form
|
|
15
|
-
* saves the photo alone through `savePhoto` (`PATCH /v1/member/profile`
|
|
16
|
-
* with `image` only); a refusal keeps the field as typed.
|
|
17
|
-
* - `session` — a build with no member API: the name saves through
|
|
18
|
-
* Better Auth's own `updateUser`, and no photo field shows
|
|
19
|
-
* (`profile="name-only"`).
|
|
20
|
-
* - `none` — a hub-mode spoke whose hub answers no member route: no form,
|
|
21
|
-
* the name as read-only text (`profile="read-only"`).
|
|
22
|
-
*
|
|
23
|
-
* On success, both paths call `router.refresh()` so the rail's name follows
|
|
24
|
-
* the save.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
import {
|
|
28
|
-
AccountSettings,
|
|
29
|
-
type AccountGeneralLabels,
|
|
30
|
-
type AccountSaveResult,
|
|
31
|
-
type AccountSettingsFrameProps,
|
|
32
|
-
} from "@working-theory/templates/account";
|
|
33
|
-
import { createAuthClient } from "better-auth/react";
|
|
34
|
-
import { useRouter } from "next/navigation";
|
|
35
|
-
import type { ReactElement, ReactNode } from "react";
|
|
36
|
-
|
|
37
|
-
import { savePhoto } from "./photo-actions";
|
|
38
|
-
|
|
39
|
-
const authClient = createAuthClient();
|
|
40
|
-
|
|
41
|
-
export interface GeneralSettingsLabels extends AccountGeneralLabels {
|
|
42
|
-
/** The `saveProfile` refusal lines not already in `AccountGeneralLabels`. */
|
|
43
|
-
unverified: string;
|
|
44
|
-
unavailable: string;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export function GeneralSettings({
|
|
48
|
-
frame,
|
|
49
|
-
user,
|
|
50
|
-
labels,
|
|
51
|
-
colorMode,
|
|
52
|
-
via,
|
|
53
|
-
children,
|
|
54
|
-
}: {
|
|
55
|
-
frame: Omit<AccountSettingsFrameProps, "name" | "children">;
|
|
56
|
-
user: { name: string; email: string; image: string | null };
|
|
57
|
-
labels: GeneralSettingsLabels;
|
|
58
|
-
colorMode: { cookieName: string } | null;
|
|
59
|
-
via: "member" | "session" | "none";
|
|
60
|
-
children?: ReactNode;
|
|
61
|
-
}): ReactElement {
|
|
62
|
-
const router = useRouter();
|
|
63
|
-
|
|
64
|
-
async function onSave({
|
|
65
|
-
name,
|
|
66
|
-
image,
|
|
67
|
-
imageChanged,
|
|
68
|
-
}: {
|
|
69
|
-
name: string;
|
|
70
|
-
image: string | null;
|
|
71
|
-
imageChanged: boolean;
|
|
72
|
-
}): Promise<AccountSaveResult> {
|
|
73
|
-
if (via === "session") {
|
|
74
|
-
const { error } = await authClient.updateUser({ name });
|
|
75
|
-
if (error) return { ok: false, message: labels.saveError };
|
|
76
|
-
router.refresh();
|
|
77
|
-
return { ok: true };
|
|
78
|
-
}
|
|
79
|
-
// The member path saves the photo alone; `name` is the account's as it
|
|
80
|
-
// stands and never written here. Only a changed photo reaches here (Save
|
|
81
|
-
// is disabled otherwise), so the untouched-field rule (8232 D4/D6) holds.
|
|
82
|
-
if (!imageChanged) return { ok: true };
|
|
83
|
-
const res = await savePhoto(image);
|
|
84
|
-
if (!res.ok) {
|
|
85
|
-
if (res.reason === "photo") return { ok: false, field: "photo", message: labels.photoInvalid };
|
|
86
|
-
if (res.reason === "unverified") return { ok: false, message: labels.unverified };
|
|
87
|
-
if (res.reason === "unavailable") return { ok: false, message: labels.unavailable };
|
|
88
|
-
return { ok: false, message: labels.saveError };
|
|
89
|
-
}
|
|
90
|
-
router.refresh();
|
|
91
|
-
return { ok: true, image: res.image };
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return (
|
|
95
|
-
<AccountSettings
|
|
96
|
-
frame={frame}
|
|
97
|
-
user={user}
|
|
98
|
-
labels={labels}
|
|
99
|
-
colorMode={colorMode}
|
|
100
|
-
profile={via === "member" ? "editable" : via === "session" ? "name-only" : "read-only"}
|
|
101
|
-
nameField={via !== "member"}
|
|
102
|
-
{...(via === "none" ? {} : { onSave })}
|
|
103
|
-
>
|
|
104
|
-
{children}
|
|
105
|
-
</AccountSettings>
|
|
106
|
-
);
|
|
107
|
-
}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* general/profile-source.ts (server code) — who saves User settings ›
|
|
3
|
-
* General's profile and takes its deletion request, and the photo the
|
|
4
|
-
* profile form starts with (#8232, spec
|
|
5
|
-
* docs/specs/8232-member-settings-account-general-and-spec.md D3, C2, C5).
|
|
6
|
-
*
|
|
7
|
-
* `via` — whether the member API answers, read once per request from
|
|
8
|
-
* `member.pieces`, the cheapest member read:
|
|
9
|
-
*
|
|
10
|
-
* - `member` — any answer but a 404: a 2xx, any other refusal, a preflight
|
|
11
|
-
* refusal (status 0) or a throw. A refusal of another kind belongs to the
|
|
12
|
-
* write, which reports it honestly. A `503 tenant_unresolved` is
|
|
13
|
-
* `member` too: the writes answer the same 503, shown as unavailable.
|
|
14
|
-
* - on a 404, the sign-in seam (`signInMethod()`, D7) says who holds the
|
|
15
|
-
* account. A `site` sign-in gives `session`: this site's own sign-in
|
|
16
|
-
* holds it, and the 404 is a build with no tenancy module — every member
|
|
17
|
-
* read and write registers in one module block — so the name saves
|
|
18
|
-
* through Better Auth as before and deletion points at Support. A `hub`
|
|
19
|
-
* sign-in gives `none`: the hub holds the account and answers no member
|
|
20
|
-
* route for this spoke, and the spoke has no `/api/auth` of its own, so
|
|
21
|
-
* no write can reach the account from here.
|
|
22
|
-
*
|
|
23
|
-
* A 404 is a module-presence test, as `read()` in `lib/account-config.ts`
|
|
24
|
-
* already makes; this file names no topology constant itself.
|
|
25
|
-
*
|
|
26
|
-
* `image` — on the `member` path, the photo the member API holds for the
|
|
27
|
-
* caller's own row (`GET /v1/member/profile`, #11167): a spoke's hub session
|
|
28
|
-
* carries no photo, and this is how the Admin's Google photo reaches the
|
|
29
|
-
* spoke's General. A failed or refused read falls back to the session's photo,
|
|
30
|
-
* which Better Auth's session carries at run time though the generated
|
|
31
|
-
* `SiteSession` type does not declare it (a hub session carries none, C5).
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
import { member } from "@working-theory/api-client";
|
|
35
|
-
import type { AccountContext } from "@working-theory/templates/account";
|
|
36
|
-
import { headers } from "next/headers";
|
|
37
|
-
import { cache } from "react";
|
|
38
|
-
|
|
39
|
-
import { readSession } from "../../../../../lib/topology.generated";
|
|
40
|
-
import { signInMethod } from "../sign-in-method";
|
|
41
|
-
|
|
42
|
-
export interface ProfileSource {
|
|
43
|
-
via: "member" | "session" | "none";
|
|
44
|
-
image: string | null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** `user.image` as a trimmed non-blank string, else `null`. */
|
|
48
|
-
function sessionImage(session: unknown): string | null {
|
|
49
|
-
if (typeof session !== "object" || session === null) return null;
|
|
50
|
-
const user = (session as { user?: unknown }).user;
|
|
51
|
-
if (typeof user !== "object" || user === null) return null;
|
|
52
|
-
const image = (user as { image?: unknown }).image;
|
|
53
|
-
return typeof image === "string" && image.trim() !== "" ? image.trim() : null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
async function memberApiAnswers(ctx: AccountContext): Promise<boolean> {
|
|
57
|
-
try {
|
|
58
|
-
const res = await member.pieces(ctx.init);
|
|
59
|
-
return res.ok || res.status !== 404;
|
|
60
|
-
} catch {
|
|
61
|
-
return true;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/** The caller's stored photo, or `null` when the read fails or holds none. */
|
|
66
|
-
async function memberImage(ctx: AccountContext): Promise<string | null> {
|
|
67
|
-
try {
|
|
68
|
-
const res = await member.profile(ctx.init);
|
|
69
|
-
return res.ok ? res.body.image?.trim() || null : null;
|
|
70
|
-
} catch {
|
|
71
|
-
return null;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const loadProfileSource = cache(async (ctx: AccountContext): Promise<ProfileSource> => {
|
|
76
|
-
// The photo is optional: a failed session read starts the field empty
|
|
77
|
-
// rather than failing the page.
|
|
78
|
-
const [answers, session] = await Promise.all([
|
|
79
|
-
memberApiAnswers(ctx),
|
|
80
|
-
headers()
|
|
81
|
-
.then((h) => readSession(h))
|
|
82
|
-
.catch(() => null),
|
|
83
|
-
]);
|
|
84
|
-
const via = answers ? "member" : signInMethod().kind === "site" ? "session" : "none";
|
|
85
|
-
const image = (via === "member" ? await memberImage(ctx) : null) ?? sessionImage(session);
|
|
86
|
-
return { via, image };
|
|
87
|
-
});
|