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,184 +0,0 @@
|
|
|
1
|
-
"use server";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* artifacts/artifact-actions.ts — the review write (#8234, spec
|
|
5
|
-
* docs/specs/8234-member-artifacts-account-artifacts-and-spec.md D6; the
|
|
6
|
-
* write is #8170's `POST /v1/member/artifacts/:pieceId/review`) and a
|
|
7
|
-
* proposal's payment (#8516, spec
|
|
8
|
-
* docs/specs/8516-proposals-as-an-artifact-kind-spec.md D19; the write is
|
|
9
|
-
* `POST /v1/member/artifacts/:pieceId/payment`).
|
|
10
|
-
*
|
|
11
|
-
* `submitArtifactReview`, the review form's action, posts
|
|
12
|
-
* Approve or Request changes on a piece's latest version through
|
|
13
|
-
* `member.reviewArtifact` with `forwardedCookieInit()`'s init as built — the
|
|
14
|
-
* session cookie plus the request's `Origin` on a single site, the hub
|
|
15
|
-
* credential on a hub-mode spoke — so nothing here tests the topology. The
|
|
16
|
-
* body is the strict `MemberReviewBody` (`version`, `review`, `comment`), so
|
|
17
|
-
* no title, stage, note or link can be posted (AC-MAA-05). The posted
|
|
18
|
-
* `pieceId` and `version` are untrusted: they are shape-checked here, and the
|
|
19
|
-
* API scopes them to the Person the credential resolves.
|
|
20
|
-
*
|
|
21
|
-
* A proposal's payment (#8516 D19). An approval whose answered artifact owes
|
|
22
|
-
* a payment (`paymentDue`) goes straight on to it; `payForProposal`, the Pay
|
|
23
|
-
* now form's action, does the same from the artifact page. Both run the one
|
|
24
|
-
* private `startProposalPayment`: `member.payArtifact` with the same init,
|
|
25
|
-
* then `redirect()` — only to a URL `isStripeCheckoutUrl` admits, so the
|
|
26
|
-
* client is never sent anywhere but Stripe's hosted Checkout page. The
|
|
27
|
-
* amount is the API's, from the stored proposal; nothing posted here names
|
|
28
|
-
* one. Any other outcome is `payment_failed`, and the review stays recorded,
|
|
29
|
-
* so the page offers Pay now. `redirect()` throws `NEXT_REDIRECT` by design,
|
|
30
|
-
* so it is called outside any try/catch (`../actions.ts`'s idiom).
|
|
31
|
-
*
|
|
32
|
-
* Not a `*.actions.ts` file and no `*Action`-suffixed export: apps/mcp's
|
|
33
|
-
* parity test reads that suffix, and the member writes have no MCP twin by
|
|
34
|
-
* decision (8170's header). The reads the pages share live in
|
|
35
|
-
* `artifact-data.ts`, never here — every export of this module is a POST
|
|
36
|
-
* endpoint. A log line carries `err.name` only — never the comment, an id
|
|
37
|
-
* or a Checkout URL.
|
|
38
|
-
*/
|
|
39
|
-
|
|
40
|
-
import { member } from "@working-theory/api-client";
|
|
41
|
-
import {
|
|
42
|
-
isStripeCheckoutUrl,
|
|
43
|
-
memberReviewBodySchema,
|
|
44
|
-
memberReviewParamsSchema,
|
|
45
|
-
type MemberReviewBody,
|
|
46
|
-
} from "@working-theory/validation";
|
|
47
|
-
import { redirect } from "next/navigation";
|
|
48
|
-
|
|
49
|
-
import { forwardedCookieInit } from "../../../../../lib/server-api";
|
|
50
|
-
|
|
51
|
-
import { paymentDue } from "./artifact-data";
|
|
52
|
-
|
|
53
|
-
/** What the review form shows after a submit. */
|
|
54
|
-
export type ArtifactReviewState =
|
|
55
|
-
| { kind: "idle" }
|
|
56
|
-
| { kind: "reviewed" }
|
|
57
|
-
| {
|
|
58
|
-
kind: "error";
|
|
59
|
-
reason:
|
|
60
|
-
| "comment_required"
|
|
61
|
-
| "closed"
|
|
62
|
-
| "not_latest"
|
|
63
|
-
| "rate_limited"
|
|
64
|
-
| "failed"
|
|
65
|
-
| "payment_failed";
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export type ArtifactReviewReason = Extract<
|
|
69
|
-
ArtifactReviewState,
|
|
70
|
-
{ kind: "error" }
|
|
71
|
-
>["reason"];
|
|
72
|
-
|
|
73
|
-
/** What the Pay now form shows after a submit that did not leave for Stripe. */
|
|
74
|
-
export type ProposalPayState =
|
|
75
|
-
{ kind: "idle" } | { kind: "error"; reason: "payment_failed" };
|
|
76
|
-
|
|
77
|
-
const PAYMENT_FAILED = { kind: "error", reason: "payment_failed" } as const;
|
|
78
|
-
|
|
79
|
-
function error(reason: ArtifactReviewReason): ArtifactReviewState {
|
|
80
|
-
return { kind: "error", reason };
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** A form field as a string; a missing or file field is empty. */
|
|
84
|
-
function field(formData: FormData, name: string): string {
|
|
85
|
-
const value = formData.get(name);
|
|
86
|
-
return typeof value === "string" ? value : "";
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/** The refusal's reason, from the api-client's `{ ok: false, status, body }`. */
|
|
90
|
-
function refusalReason(status: number, body: unknown): ArtifactReviewReason {
|
|
91
|
-
const code = (body as { error?: { code?: unknown } } | null)?.error?.code;
|
|
92
|
-
if (code === "review_closed") return "closed";
|
|
93
|
-
if (code === "version_not_latest") return "not_latest";
|
|
94
|
-
// The route's own budget answers `too_many_requests`; the hub's
|
|
95
|
-
// per-person budget and the per-IP limiter answer `429 rate_limited`.
|
|
96
|
-
if (code === "too_many_requests" || status === 429) return "rate_limited";
|
|
97
|
-
return "failed";
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/** Approve, or request changes with a comment, on a piece's latest version. */
|
|
101
|
-
export async function submitArtifactReview(
|
|
102
|
-
_prev: ArtifactReviewState,
|
|
103
|
-
formData: FormData,
|
|
104
|
-
): Promise<ArtifactReviewState> {
|
|
105
|
-
const pieceId = field(formData, "pieceId");
|
|
106
|
-
const review = field(formData, "review");
|
|
107
|
-
const comment = field(formData, "comment").trim();
|
|
108
|
-
|
|
109
|
-
if (review === "changes-requested" && comment === "")
|
|
110
|
-
return error("comment_required");
|
|
111
|
-
|
|
112
|
-
const candidate = {
|
|
113
|
-
version: Number(field(formData, "version")),
|
|
114
|
-
review,
|
|
115
|
-
...(comment !== "" ? { comment } : {}),
|
|
116
|
-
};
|
|
117
|
-
if (!memberReviewParamsSchema.safeParse({ pieceId }).success)
|
|
118
|
-
return error("failed");
|
|
119
|
-
const parsed = memberReviewBodySchema.safeParse(candidate);
|
|
120
|
-
if (!parsed.success) {
|
|
121
|
-
// A comment of control or bidi characters only is stripped to nothing
|
|
122
|
-
// by the server's `plainText`; to the person that is a missing comment.
|
|
123
|
-
const onComment = parsed.error.issues.some(
|
|
124
|
-
(issue) => issue.path[0] === "comment",
|
|
125
|
-
);
|
|
126
|
-
return error(
|
|
127
|
-
review === "changes-requested" && onComment
|
|
128
|
-
? "comment_required"
|
|
129
|
-
: "failed",
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
const body: MemberReviewBody = parsed.data;
|
|
133
|
-
|
|
134
|
-
let res: Awaited<ReturnType<typeof member.reviewArtifact>>;
|
|
135
|
-
try {
|
|
136
|
-
res = await member.reviewArtifact(
|
|
137
|
-
pieceId,
|
|
138
|
-
body,
|
|
139
|
-
await forwardedCookieInit(),
|
|
140
|
-
);
|
|
141
|
-
} catch (err) {
|
|
142
|
-
console.error(
|
|
143
|
-
`[account] review failed errName=${err instanceof Error ? err.name : "unknown"}`,
|
|
144
|
-
);
|
|
145
|
-
return error("failed");
|
|
146
|
-
}
|
|
147
|
-
if (!res.ok) return error(refusalReason(res.status, res.body));
|
|
148
|
-
if (body.review === "approved" && paymentDue(res.body.artifact))
|
|
149
|
-
return startProposalPayment(pieceId);
|
|
150
|
-
return { kind: "reviewed" };
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/** Pay now: open the approved proposal's payment and go to it. */
|
|
154
|
-
export async function payForProposal(
|
|
155
|
-
_prev: ProposalPayState,
|
|
156
|
-
formData: FormData,
|
|
157
|
-
): Promise<ProposalPayState> {
|
|
158
|
-
const pieceId = field(formData, "pieceId");
|
|
159
|
-
if (!memberReviewParamsSchema.safeParse({ pieceId }).success)
|
|
160
|
-
return PAYMENT_FAILED;
|
|
161
|
-
return startProposalPayment(pieceId);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Ask the API for the proposal's Stripe Checkout page and redirect there.
|
|
166
|
-
* Never returns on success; anything short of a Stripe Checkout URL is
|
|
167
|
-
* `payment_failed`.
|
|
168
|
-
*/
|
|
169
|
-
async function startProposalPayment(
|
|
170
|
-
pieceId: string,
|
|
171
|
-
): Promise<typeof PAYMENT_FAILED> {
|
|
172
|
-
let url: string | null = null;
|
|
173
|
-
try {
|
|
174
|
-
const res = await member.payArtifact(pieceId, await forwardedCookieInit());
|
|
175
|
-
if (res.ok && isStripeCheckoutUrl(res.body.url)) url = res.body.url;
|
|
176
|
-
} catch (err) {
|
|
177
|
-
console.error(
|
|
178
|
-
`[account] payment failed errName=${err instanceof Error ? err.name : "unknown"}`,
|
|
179
|
-
);
|
|
180
|
-
}
|
|
181
|
-
if (url === null) return PAYMENT_FAILED;
|
|
182
|
-
// Outside any try/catch on purpose — see the file header.
|
|
183
|
-
redirect(url);
|
|
184
|
-
}
|
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* artifacts/artifact-data.ts — the Artifacts pages' read and its helpers
|
|
3
|
-
* (#8234, spec docs/specs/8234-member-artifacts-account-artifacts-and-spec.md
|
|
4
|
-
* D2, C6; #11161).
|
|
5
|
-
*
|
|
6
|
-
* The list and the artifact page read the same artifacts, so the read lives
|
|
7
|
-
* here — not in `artifact-actions.ts`, where every export of a
|
|
8
|
-
* `"use server"` module is a POST endpoint, and not in
|
|
9
|
-
* `lib/account-config.ts`, whose `read()` stays private. The account area's
|
|
10
|
-
* read rule is restated: a 404 (no tenancy module, or a spoke route the hub
|
|
11
|
-
* does not admit) is "nothing delivered"; a 401 or 403 is the same while the
|
|
12
|
-
* person's email is unverified; anything else throws, so the page shows its
|
|
13
|
-
* error row with Retry (spec 7423 D12), never an empty list.
|
|
14
|
-
*
|
|
15
|
-
* The read serves versions newest first and at least one (8169 D6), so
|
|
16
|
-
* `versions[0]` is the latest version. Items keep the read's order — newest
|
|
17
|
-
* delivery first — and are never re-sorted here.
|
|
18
|
-
*
|
|
19
|
-
* #11161 (operator rulings 2026-11-08): the member's Status is the piece's
|
|
20
|
-
* STAGE — the provider's own pipeline, served per artifact as `stage` with
|
|
21
|
-
* its `stageLabel`, and as the workspace's declared list `stages` with
|
|
22
|
-
* `stageLabels`, in declared order. The version review (approved / changes
|
|
23
|
-
* requested / none) is a tag beside it, never a status of its own. A stage
|
|
24
|
-
* reads for a member by its LABEL — the one the provider set in the Admin's
|
|
25
|
-
* Artifact stages section (point 6), never the slug; the terminal default
|
|
26
|
-
* reads "Delivered" until the provider renames it. A hub older than the
|
|
27
|
-
* labels serves the slug alone, which reads as its default label
|
|
28
|
-
* (`defaultPieceStageLabel`); one older still serves no stage, so its
|
|
29
|
-
* artifacts have no stage facet and the facet group is the four defaults.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
import { member } from "@working-theory/api-client";
|
|
33
|
-
import type { AccountContext } from "@working-theory/templates/account";
|
|
34
|
-
import { localeHref } from "@working-theory/ui";
|
|
35
|
-
import {
|
|
36
|
-
defaultPieceStageLabel,
|
|
37
|
-
type MemberArtifact,
|
|
38
|
-
type MemberPieceVersion,
|
|
39
|
-
} from "@working-theory/validation";
|
|
40
|
-
import { cache } from "react";
|
|
41
|
-
|
|
42
|
-
import { unwrapApiResult } from "../../../../../lib/server-api";
|
|
43
|
-
|
|
44
|
-
/** One declared stage: the slug (the key) and the label a member reads. */
|
|
45
|
-
export interface MemberStage {
|
|
46
|
-
slug: string;
|
|
47
|
-
label: string;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface MemberArtifacts {
|
|
51
|
-
/** Newest delivery first, the read's order. */
|
|
52
|
-
items: MemberArtifact[];
|
|
53
|
-
/** The workspace's declared stages, in declared order, each with its label. */
|
|
54
|
-
stages: MemberStage[];
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/** The four product-default stages, for an older hub that serves no list. */
|
|
58
|
-
const DEFAULT_STAGES = ["requested", "in-progress", "in-review", "delivered"];
|
|
59
|
-
|
|
60
|
-
const stagesOf = (slugs: readonly string[], labels: readonly string[] = []): MemberStage[] =>
|
|
61
|
-
slugs.map((slug, index) => ({ slug, label: labels[index] ?? defaultPieceStageLabel(slug) }));
|
|
62
|
-
|
|
63
|
-
const EMPTY: MemberArtifacts = { items: [], stages: stagesOf(DEFAULT_STAGES) };
|
|
64
|
-
|
|
65
|
-
/** The member's artifacts and the workspace's stages. One read per request. */
|
|
66
|
-
export const loadArtifacts = cache(
|
|
67
|
-
async (ctx: AccountContext): Promise<MemberArtifacts> => {
|
|
68
|
-
const res = await member.artifacts(ctx.init);
|
|
69
|
-
if (!res.ok) {
|
|
70
|
-
if (res.status === 404) return EMPTY;
|
|
71
|
-
if (!ctx.user.emailVerified && (res.status === 401 || res.status === 403)) return EMPTY;
|
|
72
|
-
}
|
|
73
|
-
const body = await unwrapApiResult(Promise.resolve(res));
|
|
74
|
-
return {
|
|
75
|
-
items: body.items,
|
|
76
|
-
stages: body.stages === undefined ? EMPTY.stages : stagesOf(body.stages, body.stageLabels),
|
|
77
|
-
};
|
|
78
|
-
},
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
export type ArtifactState = "approved" | "changes-requested" | "ready";
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* The `account` catalog key that names each review state as a TAG — none for
|
|
85
|
-
* `ready`, whose artifact carries no review tag (#11161).
|
|
86
|
-
*/
|
|
87
|
-
export const STATE_KEYS = {
|
|
88
|
-
approved: "artifacts.states.approved",
|
|
89
|
-
"changes-requested": "artifacts.states.changesRequested",
|
|
90
|
-
} as const satisfies Partial<Record<ArtifactState, string>>;
|
|
91
|
-
|
|
92
|
-
/** The artifact's review state, from its approval and its latest version. */
|
|
93
|
-
export function artifactState(a: MemberArtifact): ArtifactState {
|
|
94
|
-
if (a.approvedAt !== null) return "approved";
|
|
95
|
-
return a.versions[0]?.review === "changes-requested"
|
|
96
|
-
? "changes-requested"
|
|
97
|
-
: "ready";
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* An artifact's stage as a member reads it (#11161): the label the hub served
|
|
102
|
-
* with it; for a hub older than the labels, the slug's default label; for one
|
|
103
|
-
* that serves no stage, `null`.
|
|
104
|
-
*/
|
|
105
|
-
export function artifactStageLabel(a: MemberArtifact): string | null {
|
|
106
|
-
if (a.stage === undefined) return null;
|
|
107
|
-
return a.stageLabel ?? defaultPieceStageLabel(a.stage);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** A facet's glyph by its place in the declared order: first dashed, last a check, the rest a dot. */
|
|
111
|
-
export function stageGlyph(
|
|
112
|
-
index: number,
|
|
113
|
-
count: number,
|
|
114
|
-
): "circle-dashed" | "circle-dot" | "circle-check" {
|
|
115
|
-
if (index === 0) return "circle-dashed";
|
|
116
|
-
if (index === count - 1) return "circle-check";
|
|
117
|
-
return "circle-dot";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/** The `artifacts.types.*` key naming a version's file type — the Admin's own labels (#11161). */
|
|
121
|
-
const TYPE_KEYS = {
|
|
122
|
-
"application/pdf": "artifacts.types.pdf",
|
|
123
|
-
"image/png": "artifacts.types.png",
|
|
124
|
-
"image/jpeg": "artifacts.types.jpeg",
|
|
125
|
-
"image/gif": "artifacts.types.gif",
|
|
126
|
-
"image/webp": "artifacts.types.webp",
|
|
127
|
-
"image/avif": "artifacts.types.avif",
|
|
128
|
-
} as const;
|
|
129
|
-
type TypeKey =
|
|
130
|
-
| (typeof TYPE_KEYS)[keyof typeof TYPE_KEYS]
|
|
131
|
-
| "artifacts.types.file"
|
|
132
|
-
| "artifacts.types.link";
|
|
133
|
-
|
|
134
|
-
const isNamedType = (contentType: string): contentType is keyof typeof TYPE_KEYS =>
|
|
135
|
-
Object.prototype.hasOwnProperty.call(TYPE_KEYS, contentType);
|
|
136
|
-
|
|
137
|
-
/** The Type cell: the latest version's file type, or Link (#11161). Read as the preview reads it: parameters dropped, case folded. */
|
|
138
|
-
export function versionTypeKey(v: MemberPieceVersion): TypeKey {
|
|
139
|
-
if (v.file === null) return "artifacts.types.link";
|
|
140
|
-
const type = (v.file.contentType.split(";")[0] ?? "").trim().toLowerCase();
|
|
141
|
-
return isNamedType(type) ? TYPE_KEYS[type] : "artifacts.types.file";
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* True while the latest version can be reviewed: the artifact is not
|
|
146
|
-
* approved and that version has no review yet (8170 C7 — a reviewed version
|
|
147
|
-
* is `review_closed` until the provider delivers the next one).
|
|
148
|
-
*/
|
|
149
|
-
export function isReviewable(a: MemberArtifact): boolean {
|
|
150
|
-
return a.approvedAt === null && a.versions[0]?.review === null;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* True for a proposal (#8516 D19). An older hub serves no `kind` (D4: the
|
|
155
|
-
* key is optional), and such an artifact is a deliverable.
|
|
156
|
-
*/
|
|
157
|
-
export function isProposal(a: MemberArtifact): boolean {
|
|
158
|
-
return a.kind === "proposal";
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* True while an approved, priced proposal waits on the client's payment
|
|
163
|
-
* (#8516 D19). The API serves `due` only where a payment surface answers,
|
|
164
|
-
* so anything else — `null`, `paid` or an older hub's missing key — is not.
|
|
165
|
-
*/
|
|
166
|
-
export function paymentDue(a: MemberArtifact): boolean {
|
|
167
|
-
return a.payment?.status === "due";
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/** The artifact page of one piece. */
|
|
171
|
-
export function artifactHref(locale: string, pieceId: string): string {
|
|
172
|
-
return localeHref(
|
|
173
|
-
locale,
|
|
174
|
-
`/account/artifacts/${encodeURIComponent(pieceId)}`,
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** The download route of one version's file. */
|
|
179
|
-
export function versionFileHref(
|
|
180
|
-
locale: string,
|
|
181
|
-
pieceId: string,
|
|
182
|
-
version: number,
|
|
183
|
-
): string {
|
|
184
|
-
return `${artifactHref(locale, pieceId)}/versions/${version}/file`;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* The preview route of one version's file (#11161): the same route, asked
|
|
189
|
-
* to answer inline — which it does for an image or a PDF only.
|
|
190
|
-
*/
|
|
191
|
-
export function versionPreviewHref(
|
|
192
|
-
locale: string,
|
|
193
|
-
pieceId: string,
|
|
194
|
-
version: number,
|
|
195
|
-
): string {
|
|
196
|
-
return `${versionFileHref(locale, pieceId, version)}?inline=1`;
|
|
197
|
-
}
|
package/templates/apps/web/app/[locale]/(authed)/account/billing/__tests__/offerings.test.ts
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `billingOfferings` (#11165 AC-2, AC-3) — the shown set's share of User
|
|
3
|
-
* settings › Billing, as a pure function: the base plan (the lowest-priced
|
|
4
|
-
* live plan), the Upgrade target (the next live plan above it by price —
|
|
5
|
-
* Essentials → Growth on a three-plan set), the first live offer, and the
|
|
6
|
-
* no-plan case. Sits beside the module: architecture.yaml bans a relative
|
|
7
|
-
* `../billing/` import from the account tree's own suites.
|
|
8
|
-
*/
|
|
9
|
-
import type { OfferingsProduct, WorkspaceShownSetWire } from "@working-theory/validation";
|
|
10
|
-
|
|
11
|
-
import { billingOfferings } from "../offerings";
|
|
12
|
-
|
|
13
|
-
function plan(slug: string, name: string, amount: number, extra: Partial<OfferingsProduct> = {}): OfferingsProduct {
|
|
14
|
-
return {
|
|
15
|
-
productId: `prod_${slug.replace(/-/g, "")}`,
|
|
16
|
-
plan: slug,
|
|
17
|
-
name,
|
|
18
|
-
description: null,
|
|
19
|
-
marketingFeatures: [],
|
|
20
|
-
unitLabel: null,
|
|
21
|
-
note: null,
|
|
22
|
-
termsNote: null,
|
|
23
|
-
ailkGroup: "plan",
|
|
24
|
-
ailkOrder: null,
|
|
25
|
-
prices: [
|
|
26
|
-
{
|
|
27
|
-
priceId: `price_${slug.replace(/-/g, "")}_monthly`,
|
|
28
|
-
lookupKey: `${slug}_monthly`,
|
|
29
|
-
plan: slug,
|
|
30
|
-
period: "monthly",
|
|
31
|
-
interval: "month",
|
|
32
|
-
amount,
|
|
33
|
-
currency: "usd",
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
recommended: false,
|
|
37
|
-
...extra,
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const OFFER: OfferingsProduct = {
|
|
42
|
-
...plan("welcome", "Two weeks of Growth, on us", 0),
|
|
43
|
-
productId: "prod_welcome",
|
|
44
|
-
description: "Try the Growth plan for two weeks before you commit.",
|
|
45
|
-
ailkGroup: "offer",
|
|
46
|
-
prices: [
|
|
47
|
-
{ priceId: "price_welcome_once", lookupKey: "welcome_once", plan: "welcome", period: "once", interval: null, amount: 0, currency: "usd" },
|
|
48
|
-
],
|
|
49
|
-
image: "https://files.stripe.com/links/offer.png",
|
|
50
|
-
promotionCode: "WELCOME20",
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
/** Growth listed before Essentials, so the order under test is the price's, not the snapshot's. */
|
|
54
|
-
function threePlans(offerings: OfferingsProduct[] = [plan("growth", "Growth", 2_500_000), plan("essentials", "Essentials", 1_250_000), plan("scale", "Scale", 5_000_000)]): WorkspaceShownSetWire {
|
|
55
|
-
return {
|
|
56
|
-
productIds: offerings.map((o) => o.productId),
|
|
57
|
-
recommended: { plan: null, addon: null },
|
|
58
|
-
offerings,
|
|
59
|
-
state: "current",
|
|
60
|
-
snapshotAt: "2026-11-08T00:00:00.000Z",
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
describe("billingOfferings — the shown set's share (#11165 AC-2, AC-3)", () => {
|
|
66
|
-
it("pins Essentials → Growth on the three-plan set, by price and not by the snapshot's order, and the first offer", () => {
|
|
67
|
-
const out = billingOfferings(threePlans([OFFER, plan("growth", "Growth", 2_500_000), plan("essentials", "Essentials", 1_250_000), plan("scale", "Scale", 5_000_000)]));
|
|
68
|
-
expect(out.base).toMatchObject({ name: "Essentials", price: { amountMinor: 1_250_000, currency: "usd", interval: "month" }, checkoutHref: "/api/offerings/checkout/essentials_monthly" });
|
|
69
|
-
expect(out.next).toMatchObject({ name: "Growth", checkoutHref: "/api/offerings/checkout/growth_monthly" });
|
|
70
|
-
expect(out.offer).toEqual({
|
|
71
|
-
productId: "prod_welcome",
|
|
72
|
-
name: "Two weeks of Growth, on us",
|
|
73
|
-
description: "Try the Growth plan for two weeks before you commit.",
|
|
74
|
-
image: "https://files.stripe.com/links/offer.png",
|
|
75
|
-
claimHref: "/api/offerings/checkout/welcome_once?promo=WELCOME20",
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("the no-plan case: a set of add-ons and offers only, an expired set, or an unparsable body contributes nothing", () => {
|
|
80
|
-
const empty = { base: null, next: null, offer: null };
|
|
81
|
-
expect(billingOfferings(threePlans([{ ...plan("seo", "SEO audit", 1000), ailkGroup: "addon" }]))).toEqual(empty);
|
|
82
|
-
expect(billingOfferings({ ...threePlans(), state: "expired", offerings: [] })).toEqual(empty);
|
|
83
|
-
expect(billingOfferings({ nonsense: true })).toEqual(empty);
|
|
84
|
-
expect(billingOfferings(threePlans([OFFER])).base).toBeNull();
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it("one plan has a base and no next; an offer with no promotion code or image links its checkout bare", () => {
|
|
88
|
-
const out = billingOfferings(threePlans([plan("essentials", "Essentials", 1_250_000), { ...OFFER, promotionCode: undefined, image: undefined }]));
|
|
89
|
-
expect(out.base?.name).toBe("Essentials");
|
|
90
|
-
expect(out.next).toBeNull();
|
|
91
|
-
expect(out.offer).toMatchObject({ claimHref: "/api/offerings/checkout/welcome_once", image: null });
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
it("strips format characters from Stripe text and turns a description's line breaks into spaces", () => {
|
|
95
|
-
const out = billingOfferings(threePlans([plan("essentials", "Essentials", 1_250_000, { description: "Two sites,\none seat." })]));
|
|
96
|
-
expect(out.base?.name).toBe("Essentials");
|
|
97
|
-
expect(out.base?.description).toBe("Two sites, one seat.");
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* account/billing/offerings.ts — what the shown set contributes to User
|
|
3
|
-
* settings › Billing (#11165 rulings A and B2): the base plan a member
|
|
4
|
-
* without a subscription starts on, the plan Upgrade goes to, and the offer
|
|
5
|
-
* card.
|
|
6
|
-
*
|
|
7
|
-
* One pure function over the Offerings shown set (`GET /v1/content/shown-offerings`,
|
|
8
|
-
* #8924 — the read `/pricing` renders from, parsed by the same schema):
|
|
9
|
-
*
|
|
10
|
-
* - `base` — the shown set's lowest-priced LIVE plan: every `plan` Product
|
|
11
|
-
* of a `current` set, ordered by its card price (its first shown Price —
|
|
12
|
-
* monthly before yearly before one-time, the order the snapshot keeps).
|
|
13
|
-
* A set with no live plan has none, and the page renders no plan card.
|
|
14
|
-
* - `next` — the plan Upgrade goes to: the next live plan above the base
|
|
15
|
-
* by price. Stripe has no upgrade relation and neither does our model,
|
|
16
|
-
* so next-by-price is the rule (operator, 2026-11-08). None with one plan.
|
|
17
|
-
* - `offer` — the first live `offer` Product (#11166): its name, description,
|
|
18
|
-
* first image and the Claim offer target — the Offerings checkout for its
|
|
19
|
-
* first Price (`offeringsCheckoutHref`, T3) with the product's promotion
|
|
20
|
-
* code carried as `?promo=` when it has one. Applying that code at Checkout
|
|
21
|
-
* is the buy route's and the checkout API's — neither reads it yet, so the
|
|
22
|
-
* link reaches Checkout at the Price's own amount (a follow-up named on
|
|
23
|
-
* #11165).
|
|
24
|
-
*
|
|
25
|
-
* Stripe text crosses into markup here, so contract 8879 T2 binds it: every
|
|
26
|
-
* string is emitted as plain text, format characters removed.
|
|
27
|
-
*/
|
|
28
|
-
import {
|
|
29
|
-
workspaceShownSetWireSchema,
|
|
30
|
-
type MemberBillingPlan,
|
|
31
|
-
type OfferingsPrice,
|
|
32
|
-
type OfferingsProduct,
|
|
33
|
-
} from "@working-theory/validation";
|
|
34
|
-
|
|
35
|
-
import { offeringsCheckoutHref } from "../../../../../lib/offerings-pricing";
|
|
36
|
-
|
|
37
|
-
export interface BillingPlanView {
|
|
38
|
-
productId: string;
|
|
39
|
-
name: string;
|
|
40
|
-
description: string | null;
|
|
41
|
-
/** The card price, in the hub read's own shape so one label serves both. */
|
|
42
|
-
price: NonNullable<MemberBillingPlan["price"]>;
|
|
43
|
-
/** The Offerings checkout for the plan's card price, or `null` when its key is outside the grammar. */
|
|
44
|
-
checkoutHref: string | null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface BillingOfferView {
|
|
48
|
-
productId: string;
|
|
49
|
-
name: string;
|
|
50
|
-
description: string | null;
|
|
51
|
-
image: string | null;
|
|
52
|
-
/** The Offerings checkout for the offer's first Price, or `null` when its key is outside the grammar. */
|
|
53
|
-
claimHref: string | null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export interface BillingOfferings {
|
|
57
|
-
base: BillingPlanView | null;
|
|
58
|
-
next: BillingPlanView | null;
|
|
59
|
-
offer: BillingOfferView | null;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const NO_BILLING_OFFERINGS: BillingOfferings = { base: null, next: null, offer: null };
|
|
63
|
-
|
|
64
|
-
// Cc, Cf, Zl, Zp and Cs — the T1 classes, the last guard before markup.
|
|
65
|
-
const FORMAT_CHARACTERS = /[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Cs}]/gu;
|
|
66
|
-
|
|
67
|
-
function plain(text: string | null): string | null {
|
|
68
|
-
if (text === null) return null;
|
|
69
|
-
const stripped = text.replace(FORMAT_CHARACTERS, (ch) => (ch === "\n" ? " " : "")).trim();
|
|
70
|
-
return stripped.length > 0 ? stripped : null;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/** The Price a plan's card shows: its first shown Price, in the snapshot's period order. */
|
|
74
|
-
function cardPrice(product: OfferingsProduct): OfferingsPrice | undefined {
|
|
75
|
-
return product.prices[0];
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function planView(product: OfferingsProduct, price: OfferingsPrice): BillingPlanView {
|
|
79
|
-
return {
|
|
80
|
-
productId: product.productId,
|
|
81
|
-
name: plain(product.name) ?? product.productId,
|
|
82
|
-
description: plain(product.description),
|
|
83
|
-
price: { amountMinor: price.amount, currency: price.currency, interval: price.interval },
|
|
84
|
-
checkoutHref: offeringsCheckoutHref(price.lookupKey),
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/** The Claim offer target: the checkout for the offer's price, carrying its promotion code. */
|
|
89
|
-
function claimHrefOf(product: OfferingsProduct): string | null {
|
|
90
|
-
const price = cardPrice(product);
|
|
91
|
-
const href = price === undefined ? null : offeringsCheckoutHref(price.lookupKey);
|
|
92
|
-
if (href === null) return null;
|
|
93
|
-
return product.promotionCode === undefined ? href : `${href}?promo=${encodeURIComponent(product.promotionCode)}`;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/** The Billing page's share of a shown set; anything but a current, parsable set contributes nothing. */
|
|
97
|
-
export function billingOfferings(shownSet: unknown): BillingOfferings {
|
|
98
|
-
const parsed = workspaceShownSetWireSchema.safeParse(shownSet);
|
|
99
|
-
if (!parsed.success || parsed.data.state !== "current") return NO_BILLING_OFFERINGS;
|
|
100
|
-
|
|
101
|
-
const plans = parsed.data.offerings
|
|
102
|
-
.filter((product) => product.ailkGroup === "plan")
|
|
103
|
-
.map((product) => ({ product, price: cardPrice(product) }))
|
|
104
|
-
.filter((entry): entry is { product: OfferingsProduct; price: OfferingsPrice } => entry.price !== undefined)
|
|
105
|
-
// A stable sort, so two plans at one price keep the snapshot's order.
|
|
106
|
-
.sort((a, b) => a.price.amount - b.price.amount);
|
|
107
|
-
const base = plans[0] === undefined ? null : planView(plans[0].product, plans[0].price);
|
|
108
|
-
const next = plans[1] === undefined ? null : planView(plans[1].product, plans[1].price);
|
|
109
|
-
|
|
110
|
-
const first = parsed.data.offerings.find((product) => product.ailkGroup === "offer");
|
|
111
|
-
const offer: BillingOfferView | null =
|
|
112
|
-
first === undefined
|
|
113
|
-
? null
|
|
114
|
-
: {
|
|
115
|
-
productId: first.productId,
|
|
116
|
-
name: plain(first.name) ?? first.productId,
|
|
117
|
-
description: plain(first.description),
|
|
118
|
-
image: first.image ?? null,
|
|
119
|
-
claimHref: claimHrefOf(first),
|
|
120
|
-
};
|
|
121
|
-
|
|
122
|
-
return { base, next, offer };
|
|
123
|
-
}
|