@cosmicdrift/kumiko-samples 0.405.0 → 0.409.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/package.json +1 -1
- package/packages/bundled-features/package.json +26 -4
- package/packages/bundled-features/src/account-security/feature.ts +9 -1
- package/packages/bundled-features/src/admin-shell/changes.json +6 -0
- package/packages/bundled-features/src/admin-shell/feature.ts +4 -1
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +1 -0
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +1 -0
- package/packages/bundled-features/src/agent-tools/types.ts +4 -0
- package/packages/bundled-features/src/audit/event-classification.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/bootstrap.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/errors.ts +18 -66
- package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +30 -64
- package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +2 -2
- package/packages/bundled-features/src/auth-email-password/web/confirm-account-unlock-screen.tsx +20 -66
- package/packages/bundled-features/src/auth-email-password/web/index.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/web/read-path-param.ts +8 -0
- package/packages/bundled-features/src/auth-email-password/web/return-path.ts +3 -2
- package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +97 -0
- package/packages/bundled-features/src/auth-email-password/web/verify-email-screen.tsx +20 -68
- package/packages/bundled-features/src/auth-foundation/boot-checks.ts +22 -15
- package/packages/bundled-features/src/auth-foundation/boot-rules.ts +33 -0
- package/packages/bundled-features/src/auth-mfa/errors.ts +12 -42
- package/packages/bundled-features/src/auth-mfa/feature-exports.ts +6 -45
- package/packages/bundled-features/src/auth-mfa/feature.ts +8 -19
- package/packages/bundled-features/src/auth-mfa/web/mfa-client.ts +19 -33
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts +1 -0
- package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +20 -7
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/changes.json +7 -0
- package/packages/bundled-features/src/channel-in-app/feature.ts +2 -0
- package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +35 -0
- package/packages/bundled-features/src/channel-in-app/in-app-channel.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/tables.ts +5 -1
- package/packages/bundled-features/src/contact/challenge.ts +41 -0
- package/packages/bundled-features/src/contact/changes.json +27 -0
- package/packages/bundled-features/src/contact/client/contact-client-source.ts +203 -0
- package/packages/bundled-features/src/contact/entity.ts +168 -0
- package/packages/bundled-features/src/contact/feature.ts +171 -0
- package/packages/bundled-features/src/contact/handlers/access.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/attempts.ts +76 -0
- package/packages/bundled-features/src/contact/handlers/challenge.query.ts +44 -0
- package/packages/bundled-features/src/contact/handlers/forward-request.write.ts +98 -0
- package/packages/bundled-features/src/contact/handlers/mark-done.write.ts +40 -0
- package/packages/bundled-features/src/contact/handlers/notify-reporter-in-app.write.ts +48 -0
- package/packages/bundled-features/src/contact/handlers/open-count.query.ts +15 -0
- package/packages/bundled-features/src/contact/handlers/open-count.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/replies.query.ts +29 -0
- package/packages/bundled-features/src/contact/handlers/reply.write.ts +197 -0
- package/packages/bundled-features/src/contact/handlers/report.write.ts +126 -0
- package/packages/bundled-features/src/contact/handlers/request-delivery.query.ts +143 -0
- package/packages/bundled-features/src/contact/handlers/request-detail.query.ts +50 -0
- package/packages/bundled-features/src/contact/handlers/request-list.query.ts +14 -0
- package/packages/bundled-features/src/contact/handlers/send-reply-mail.write.ts +124 -0
- package/packages/bundled-features/src/contact/handlers/send-test.write.ts +45 -0
- package/packages/bundled-features/src/contact/handlers/submit.write.ts +194 -0
- package/packages/bundled-features/src/contact/handlers/take-over-uploads.ts +47 -0
- package/packages/bundled-features/src/contact/i18n.ts +189 -0
- package/packages/bundled-features/src/contact/index.ts +29 -0
- package/packages/bundled-features/src/contact/lib.ts +176 -0
- package/packages/bundled-features/src/contact/mail.ts +401 -0
- package/packages/bundled-features/src/contact/options.ts +95 -0
- package/packages/bundled-features/src/contact/panels.ts +28 -0
- package/packages/bundled-features/src/contact/payloads.ts +106 -0
- package/packages/bundled-features/src/contact/pow.ts +22 -0
- package/packages/bundled-features/src/contact/screens.ts +506 -0
- package/packages/bundled-features/src/contact/subject.ts +13 -0
- package/packages/bundled-features/src/contact/user-agent.ts +39 -0
- package/packages/bundled-features/src/contact/user-data-hooks.ts +180 -0
- package/packages/bundled-features/src/contact/web/constants.ts +160 -0
- package/packages/bundled-features/src/contact/web/index.ts +29 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +5 -16
- package/packages/bundled-features/src/data-retention/changes.json +6 -0
- package/packages/bundled-features/src/data-retention/feature.ts +16 -2
- package/packages/bundled-features/src/data-retention/index.ts +5 -0
- package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +138 -41
- package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +196 -0
- package/packages/bundled-features/src/delivery/address-opt-out.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +7 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +2 -0
- package/packages/bundled-features/src/delivery/delivery-service.ts +29 -5
- package/packages/bundled-features/src/delivery/events.ts +2 -0
- package/packages/bundled-features/src/delivery/feature.ts +3 -2
- package/packages/bundled-features/src/delivery/handlers/attempts-by-keys.query.ts +55 -0
- package/packages/bundled-features/src/delivery/handlers/log.query.ts +1 -1
- package/packages/bundled-features/src/delivery/jobs.ts +5 -0
- package/packages/bundled-features/src/delivery/tables.ts +13 -2
- package/packages/bundled-features/src/delivery/types.ts +3 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +2 -0
- package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +3 -2
- package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/boot-checks.ts +14 -9
- package/packages/bundled-features/src/document-ingest-foundation/boot-rules.ts +22 -0
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/events.ts +17 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +39 -1
- package/packages/bundled-features/src/document-ingest-foundation/index.ts +10 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +43 -0
- package/packages/bundled-features/src/document-ingest-foundation/tables.ts +43 -0
- package/packages/bundled-features/src/files-tenant-data/changes.json +6 -0
- package/packages/bundled-features/src/files-tenant-data/hooks.ts +4 -1
- package/packages/bundled-features/src/folders/web/folder-manager.tsx +8 -9
- package/packages/bundled-features/src/folders/web/folder-section.tsx +1 -1
- package/packages/bundled-features/src/form-draft-user-data/index.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +13 -0
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +6 -6
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +7 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts +6 -2
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts +3 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.ts +19 -0
- package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +150 -0
- package/packages/bundled-features/src/inbound-mail-foundation/types.ts +1 -0
- package/packages/bundled-features/src/jobs/job-run-logger.ts +24 -25
- package/packages/bundled-features/src/ledger/handlers/reports.query.ts +46 -31
- package/packages/bundled-features/src/ledger/recurring.ts +1 -0
- package/packages/bundled-features/src/notes-history/web/notes-section.tsx +3 -1
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +9 -17
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -7
- package/packages/bundled-features/src/secrets/changes.json +6 -0
- package/packages/bundled-features/src/secrets/handlers/delete.write.ts +8 -4
- package/packages/bundled-features/src/secrets/handlers/list.query.ts +6 -3
- package/packages/bundled-features/src/secrets/handlers/set.write.ts +9 -4
- package/packages/bundled-features/src/secrets/secret-scope.ts +33 -0
- package/packages/bundled-features/src/sessions/changes.json +6 -0
- package/packages/bundled-features/src/sessions/feature.ts +21 -18
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.query.ts +53 -0
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +39 -0
- package/packages/bundled-features/src/sessions/screens.ts +1 -0
- package/packages/bundled-features/src/sessions/session-callbacks.ts +13 -12
- package/packages/bundled-features/src/sessions/web/i18n.ts +4 -1
- package/packages/bundled-features/src/shared/assert-billing-live.ts +14 -0
- package/packages/bundled-features/src/shared/collect-extension-options.ts +12 -0
- package/packages/bundled-features/src/shared/index.ts +16 -0
- package/packages/bundled-features/src/shared/late-bound-slot.ts +19 -0
- package/packages/bundled-features/src/shared/mail-locale-templates.ts +7 -1
- package/packages/bundled-features/src/shared/price-env-shape.ts +44 -0
- package/packages/bundled-features/src/shared/purge-row-file-refs.ts +1 -1
- package/packages/bundled-features/src/shared/read-feature-export-fn.ts +16 -0
- package/packages/bundled-features/src/shared/signup-handover.ts +3 -4
- package/packages/bundled-features/src/shared/tenant-destruction-hold.ts +49 -0
- package/packages/bundled-features/src/shared/unprocessable.ts +19 -0
- package/packages/bundled-features/src/shared/web/index.ts +3 -0
- package/packages/bundled-features/src/subscription-paddle/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-paddle/runtime.ts +4 -7
- package/packages/bundled-features/src/subscription-stripe/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +4 -7
- package/packages/bundled-features/src/tags/entity.ts +1 -0
- package/packages/bundled-features/src/tags/web/tag-chip.tsx +14 -0
- package/packages/bundled-features/src/tags/web/tag-filter.tsx +4 -5
- package/packages/bundled-features/src/tags/web/tag-manager.tsx +1 -1
- package/packages/bundled-features/src/tags/web/tag-section.tsx +3 -6
- package/packages/bundled-features/src/tags/web/tags-cell.tsx +4 -5
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +27 -15
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +11 -8
- package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +5 -5
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/linked-resources.ts +11 -6
- package/packages/bundled-features/src/template-resolver/store-template-resource.ts +15 -12
- package/packages/bundled-features/src/template-resolver/web/document-images.ts +6 -6
- package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +41 -36
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -12
- package/packages/bundled-features/src/template-resolver/web/tiptap-attribute-parse-rule.ts +19 -0
- package/packages/bundled-features/src/tenant/i18n.ts +3 -0
- package/packages/bundled-features/src/tenant/schema/tenant.ts +1 -0
- package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +8 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +260 -0
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +12 -0
- package/packages/bundled-features/src/tenant-inactivity/email-templates.ts +24 -0
- package/packages/bundled-features/src/tenant-inactivity/feature.ts +66 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +49 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +56 -0
- package/packages/bundled-features/src/tenant-inactivity/inactivity-plan.ts +187 -0
- package/packages/bundled-features/src/tenant-inactivity/index.ts +5 -0
- package/packages/bundled-features/src/tenant-inactivity/keep-token.ts +44 -0
- package/packages/bundled-features/src/tenant-inactivity/mail-notifications.ts +62 -0
- package/packages/bundled-features/src/tenant-inactivity/options.ts +38 -0
- package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +32 -0
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +71 -0
- package/packages/bundled-features/src/tenant-inactivity/state-table.ts +50 -0
- package/packages/bundled-features/src/tenant-lifecycle/boot-checks.ts +8 -6
- package/packages/bundled-features/src/tenant-lifecycle/boot-rules.ts +16 -0
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +30 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/events.ts +2 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +25 -2
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/request-tenant-destruction.ts +108 -0
- package/packages/bundled-features/src/tenant-lifecycle/retention-config-destroy-hooks.ts +62 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +131 -11
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +39 -4
- package/packages/bundled-features/src/tenant-lifecycle/testing.ts +1 -1
- package/packages/bundled-features/src/tier-engine/caps-for-tier-from-map.ts +16 -0
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/compose-app.ts +21 -20
- package/packages/bundled-features/src/tier-engine/index.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/feature.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/zip-path.ts +1 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +11 -8
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.ts +42 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +2 -6
- package/packages/bundled-features/src/user-profile/web/profile-screen.tsx +2 -3
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +6 -0
- package/samples/apps/styleguide/src/features/widgets/web/InboxReaderExamples.tsx +158 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +2 -0
- package/samples/apps/styleguide/src/features/widgets/web/sample-pdf.ts +28 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +134 -2
- package/samples/apps/use-all-bundled/kumiko/migrations/0063_contact.rebuild.json +4 -0
- package/samples/apps/use-all-bundled/package.json +1 -0
- package/samples/apps/use-all-bundled/playwright.config.ts +2 -0
- package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
- package/samples/apps/use-all-bundled/src/app/screens-feature.ts +46 -2
- package/samples/apps/use-all-bundled/src/run-config.ts +38 -4
- package/samples/recipes/contact/README.md +46 -0
- package/samples/recipes/contact/package.json +12 -0
- package/samples/recipes/contact/src/feature.ts +27 -0
- package/samples/recipes/delivery-notifications/src/feature.ts +3 -0
- package/samples/recipes/lane-routing/README.md +1 -0
- package/samples/recipes/lane-routing/src/feature.ts +8 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +9 -1
- package/samples/recipes/search/README.md +2 -0
- package/samples/recipes/search/src/feature.ts +27 -2
- package/samples/recipes/secrets-demo/README.md +1 -0
- package/samples/recipes/secrets-demo/src/feature.ts +56 -0
- package/samples/recipes/tenant-inactivity/README.md +21 -0
- package/samples/recipes/tenant-inactivity/package.json +12 -0
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Shared by the server (mail link) and the web pages (landing page), so it is plain string logic:
|
|
2
2
|
// no DOM, no window, no `new URL` (React Native's URL getters throw).
|
|
3
3
|
|
|
4
|
+
import { readPathParam } from "./read-path-param.ts";
|
|
5
|
+
|
|
4
6
|
export const RETURN_TO_QUERY_PARAM = "returnTo";
|
|
5
7
|
export const MAX_RETURN_PATH_LENGTH = 2048;
|
|
6
8
|
|
|
@@ -30,6 +32,5 @@ export function isSafeReturnPath(candidate: unknown): candidate is string {
|
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
export function readReturnToFromSearch(search: string): string | null {
|
|
33
|
-
|
|
34
|
-
return isSafeReturnPath(candidate) ? candidate : null;
|
|
35
|
+
return readPathParam(search, RETURN_TO_QUERY_PARAM, isSafeReturnPath);
|
|
35
36
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Reads `?token=...` from the URL, auto-posts it on mount and shows success/error. The server
|
|
2
|
+
// side is idempotent, so a repeated call is safe.
|
|
3
|
+
//
|
|
4
|
+
// useEffect with empty deps + a once-guard so React Strict Mode's double
|
|
5
|
+
// useEffect dispatch in dev fires the confirm call only once.
|
|
6
|
+
|
|
7
|
+
import { usePrimitives } from "@cosmicdrift/kumiko-renderer";
|
|
8
|
+
import { type ReactNode, useEffect, useRef, useState } from "react";
|
|
9
|
+
import { AuthCard, useUrlToken } from "./auth-form-primitives.tsx";
|
|
10
|
+
|
|
11
|
+
export type TokenConfirmLabels = {
|
|
12
|
+
readonly errorTitle: string;
|
|
13
|
+
readonly missingToken: string;
|
|
14
|
+
readonly goToLogin: string;
|
|
15
|
+
readonly verifying: string;
|
|
16
|
+
readonly successTitle: string;
|
|
17
|
+
readonly successBody: string;
|
|
18
|
+
readonly errorBody: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type TokenConfirmScreenProps = {
|
|
22
|
+
readonly title?: string | undefined;
|
|
23
|
+
readonly token?: string | undefined;
|
|
24
|
+
readonly loginHref: string;
|
|
25
|
+
readonly confirm: (token: string) => Promise<{ readonly ok: boolean }>;
|
|
26
|
+
readonly labels: TokenConfirmLabels;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
type Status = "verifying" | "success" | "error" | "missing-token";
|
|
30
|
+
|
|
31
|
+
export function TokenConfirmScreen({
|
|
32
|
+
title,
|
|
33
|
+
token: tokenProp,
|
|
34
|
+
loginHref,
|
|
35
|
+
confirm,
|
|
36
|
+
labels,
|
|
37
|
+
}: TokenConfirmScreenProps): ReactNode {
|
|
38
|
+
const { Link } = usePrimitives();
|
|
39
|
+
const token = useUrlToken(tokenProp);
|
|
40
|
+
const [status, setStatus] = useState<Status>(token === "" ? "missing-token" : "verifying");
|
|
41
|
+
const startedRef = useRef(false);
|
|
42
|
+
|
|
43
|
+
// kumiko-lint-ignore no-raw-hooks not yet converted to the framework hook set
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
if (status !== "verifying") return;
|
|
46
|
+
if (startedRef.current) return;
|
|
47
|
+
startedRef.current = true;
|
|
48
|
+
void (async () => {
|
|
49
|
+
const res = await confirm(token);
|
|
50
|
+
setStatus(res.ok ? "success" : "error");
|
|
51
|
+
})();
|
|
52
|
+
}, [status, token, confirm]);
|
|
53
|
+
|
|
54
|
+
if (status === "missing-token") {
|
|
55
|
+
return (
|
|
56
|
+
<AuthCard title={title ?? labels.errorTitle}>
|
|
57
|
+
<p className="text-sm text-muted-foreground">{labels.missingToken}</p>
|
|
58
|
+
<Link href={loginHref} variant="muted">
|
|
59
|
+
{labels.goToLogin}
|
|
60
|
+
</Link>
|
|
61
|
+
</AuthCard>
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (status === "verifying") {
|
|
66
|
+
return (
|
|
67
|
+
<AuthCard>
|
|
68
|
+
<div className="p-6">
|
|
69
|
+
<p className="text-sm text-muted-foreground" role="status">
|
|
70
|
+
{labels.verifying}
|
|
71
|
+
</p>
|
|
72
|
+
</div>
|
|
73
|
+
</AuthCard>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (status === "success") {
|
|
78
|
+
return (
|
|
79
|
+
<AuthCard title={title ?? labels.successTitle}>
|
|
80
|
+
<p className="text-sm text-muted-foreground">{labels.successBody}</p>
|
|
81
|
+
<Link href={loginHref} variant="button">
|
|
82
|
+
{labels.goToLogin}
|
|
83
|
+
</Link>
|
|
84
|
+
</AuthCard>
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// status === "error"
|
|
89
|
+
return (
|
|
90
|
+
<AuthCard title={title ?? labels.errorTitle}>
|
|
91
|
+
<p className="text-sm text-muted-foreground">{labels.errorBody}</p>
|
|
92
|
+
<Link href={loginHref} variant="muted">
|
|
93
|
+
{labels.goToLogin}
|
|
94
|
+
</Link>
|
|
95
|
+
</AuthCard>
|
|
96
|
+
);
|
|
97
|
+
}
|
|
@@ -2,16 +2,11 @@
|
|
|
2
2
|
// /api/auth/verify-email on mount, then shows success/error. The server-side
|
|
3
3
|
// operation is idempotent (repeating it sets emailVerified=true again), so
|
|
4
4
|
// retries are safe.
|
|
5
|
-
//
|
|
6
|
-
// The empty-deps effect and once guard prevent React Strict Mode from firing
|
|
7
|
-
// the verification call twice (Strict Mode dispatches useEffect twice in dev).
|
|
8
|
-
// The token roundtrip is single-use server-side, but this avoids showing an
|
|
9
|
-
// invalid-token banner after the first valid mount call.
|
|
10
5
|
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
6
|
+
import { useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
7
|
+
import type { ReactNode } from "react";
|
|
13
8
|
import { verifyEmail } from "./auth-client.ts";
|
|
14
|
-
import {
|
|
9
|
+
import { TokenConfirmScreen } from "./token-confirm-screen.tsx";
|
|
15
10
|
|
|
16
11
|
export type VerifyEmailScreenProps = {
|
|
17
12
|
readonly title?: string;
|
|
@@ -21,71 +16,28 @@ export type VerifyEmailScreenProps = {
|
|
|
21
16
|
readonly loginHref?: string;
|
|
22
17
|
};
|
|
23
18
|
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
// guard:dup-ok TokenConfirmScreen holds the logic; each screen only supplies its own literal label keys
|
|
26
20
|
export function VerifyEmailScreen({
|
|
27
21
|
title,
|
|
28
|
-
token
|
|
22
|
+
token,
|
|
29
23
|
loginHref = "/login",
|
|
30
24
|
}: VerifyEmailScreenProps): ReactNode {
|
|
31
25
|
const t = useTranslation();
|
|
32
|
-
const { Link } = usePrimitives();
|
|
33
|
-
const token = useUrlToken(tokenProp);
|
|
34
|
-
const [status, setStatus] = useState<Status>(token === "" ? "missing-token" : "verifying");
|
|
35
|
-
const startedRef = useRef(false);
|
|
36
|
-
|
|
37
|
-
// kumiko-lint-ignore no-raw-hooks not yet converted to the framework hook set
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
if (status !== "verifying") return;
|
|
40
|
-
if (startedRef.current) return;
|
|
41
|
-
startedRef.current = true;
|
|
42
|
-
void (async () => {
|
|
43
|
-
const res = await verifyEmail(token);
|
|
44
|
-
setStatus(res.ok ? "success" : "error");
|
|
45
|
-
})();
|
|
46
|
-
}, [status, token]);
|
|
47
|
-
|
|
48
|
-
if (status === "missing-token") {
|
|
49
|
-
return (
|
|
50
|
-
<AuthCard title={title ?? t("auth.verifyEmail.errorTitle")}>
|
|
51
|
-
<p className="text-sm text-muted-foreground">{t("auth.verifyEmail.missingToken")}</p>
|
|
52
|
-
<Link href={loginHref} variant="muted">
|
|
53
|
-
{t("auth.verifyEmail.goToLogin")}
|
|
54
|
-
</Link>
|
|
55
|
-
</AuthCard>
|
|
56
|
-
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (status === "verifying") {
|
|
60
|
-
return (
|
|
61
|
-
<AuthCard>
|
|
62
|
-
<div className="p-6">
|
|
63
|
-
<p className="text-sm text-muted-foreground" role="status">
|
|
64
|
-
{t("auth.verifyEmail.verifying")}
|
|
65
|
-
</p>
|
|
66
|
-
</div>
|
|
67
|
-
</AuthCard>
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (status === "success") {
|
|
72
|
-
return (
|
|
73
|
-
<AuthCard title={title ?? t("auth.verifyEmail.successTitle")}>
|
|
74
|
-
<p className="text-sm text-muted-foreground">{t("auth.verifyEmail.successBody")}</p>
|
|
75
|
-
<Link href={loginHref} variant="button">
|
|
76
|
-
{t("auth.verifyEmail.goToLogin")}
|
|
77
|
-
</Link>
|
|
78
|
-
</AuthCard>
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// status === "error"
|
|
83
26
|
return (
|
|
84
|
-
<
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
27
|
+
<TokenConfirmScreen
|
|
28
|
+
title={title}
|
|
29
|
+
token={token}
|
|
30
|
+
loginHref={loginHref}
|
|
31
|
+
confirm={verifyEmail}
|
|
32
|
+
labels={{
|
|
33
|
+
errorTitle: t("auth.verifyEmail.errorTitle"),
|
|
34
|
+
missingToken: t("auth.verifyEmail.missingToken"),
|
|
35
|
+
goToLogin: t("auth.verifyEmail.goToLogin"),
|
|
36
|
+
verifying: t("auth.verifyEmail.verifying"),
|
|
37
|
+
successTitle: t("auth.verifyEmail.successTitle"),
|
|
38
|
+
successBody: t("auth.verifyEmail.successBody"),
|
|
39
|
+
errorBody: t("auth.verifyEmail.errorBody"),
|
|
40
|
+
}}
|
|
41
|
+
/>
|
|
90
42
|
);
|
|
91
43
|
}
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
// the right time to catch it).
|
|
14
14
|
|
|
15
15
|
import type { FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
|
|
16
|
+
import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
|
|
17
|
+
import { AUTH_FOUNDATION_BOOT_RULES } from "./boot-rules.ts";
|
|
16
18
|
import {
|
|
17
19
|
EXT_SESSION_STORE,
|
|
18
20
|
EXT_TENANT_EXISTENCE,
|
|
@@ -32,10 +34,11 @@ export function validateTokenVerifierMultiplicity(features: readonly FeatureDefi
|
|
|
32
34
|
for (const usage of feature.extensionUsages) {
|
|
33
35
|
if (usage.extensionName !== EXT_TOKEN_VERIFIER) continue;
|
|
34
36
|
if (!isAuthProviderPlugin(usage.options)) {
|
|
35
|
-
throw
|
|
36
|
-
|
|
37
|
+
throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.tokenVerifierInvalidPlugin, {
|
|
38
|
+
message:
|
|
39
|
+
`[auth-foundation] tokenVerifier provider "${usage.entityName}" (feature "${feature.name}") ` +
|
|
37
40
|
`registered without a valid AuthProviderPlugin — options must have a { shape, build } shape.`,
|
|
38
|
-
);
|
|
41
|
+
});
|
|
39
42
|
}
|
|
40
43
|
const key = tokenShapeKey(usage.options.shape);
|
|
41
44
|
const names = namesByShape.get(key) ?? [];
|
|
@@ -53,20 +56,22 @@ export function validateTokenVerifierMultiplicity(features: readonly FeatureDefi
|
|
|
53
56
|
if (usage.extensionName === EXT_SESSION_STORE) return;
|
|
54
57
|
}
|
|
55
58
|
}
|
|
56
|
-
throw
|
|
57
|
-
|
|
59
|
+
throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.noTokenVerifierOrSessionStore, {
|
|
60
|
+
message:
|
|
61
|
+
"[auth-foundation] no tokenVerifier providers and no sessionStore registered — mount " +
|
|
58
62
|
"at least one auth-provider-* feature (e.g. auth-provider-jwt / personal-access-tokens) " +
|
|
59
63
|
"or a sessionStore (e.g. sessions) alongside auth-foundation.",
|
|
60
|
-
);
|
|
64
|
+
});
|
|
61
65
|
}
|
|
62
66
|
|
|
63
67
|
for (const [key, names] of namesByShape) {
|
|
64
68
|
if (names.length >= 2) {
|
|
65
|
-
throw
|
|
66
|
-
|
|
69
|
+
throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.tokenVerifierShapeCollision, {
|
|
70
|
+
message:
|
|
71
|
+
`[auth-foundation] ${names.length} tokenVerifier providers claim the same shape "${key}" ` +
|
|
67
72
|
`(${names.join(", ")}) — resolveTokenVerifier can't route between them unambiguously. ` +
|
|
68
73
|
`Give each provider a distinct shape.`,
|
|
69
|
-
);
|
|
74
|
+
});
|
|
70
75
|
}
|
|
71
76
|
}
|
|
72
77
|
}
|
|
@@ -97,20 +102,22 @@ function validateSingleProvider(
|
|
|
97
102
|
for (const usage of feature.extensionUsages) {
|
|
98
103
|
if (usage.extensionName !== ext) continue;
|
|
99
104
|
if (!guard(usage.options)) {
|
|
100
|
-
throw
|
|
101
|
-
|
|
105
|
+
throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.singleProviderInvalidShape, {
|
|
106
|
+
message:
|
|
107
|
+
`[auth-foundation] ${label} provider "${usage.entityName}" (feature "${feature.name}") ` +
|
|
102
108
|
`registered without a valid ${shapeHint}.`,
|
|
103
|
-
);
|
|
109
|
+
});
|
|
104
110
|
}
|
|
105
111
|
names.push(usage.entityName);
|
|
106
112
|
}
|
|
107
113
|
}
|
|
108
114
|
|
|
109
115
|
if (names.length >= 2) {
|
|
110
|
-
throw
|
|
111
|
-
|
|
116
|
+
throw bootRuleError(AUTH_FOUNDATION_BOOT_RULES.singleProviderMultiple, {
|
|
117
|
+
message:
|
|
118
|
+
`[auth-foundation] ${names.length} ${label} providers registered (${names.join(", ")}) — ` +
|
|
112
119
|
`only one ${label} provider may be mounted at a time.`,
|
|
113
|
-
);
|
|
120
|
+
});
|
|
114
121
|
}
|
|
115
122
|
}
|
|
116
123
|
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { BootRuleTable } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
|
|
3
|
+
export const AUTH_FOUNDATION_BOOT_RULES = {
|
|
4
|
+
tokenVerifierInvalidPlugin: {
|
|
5
|
+
id: "auth-foundation/token-verifier-invalid-plugin",
|
|
6
|
+
summary:
|
|
7
|
+
"A tokenVerifier provider registers a valid AuthProviderPlugin with a { shape, build } options shape.",
|
|
8
|
+
fix: "Register the provider with options of shape { shape, build }.",
|
|
9
|
+
},
|
|
10
|
+
noTokenVerifierOrSessionStore: {
|
|
11
|
+
id: "auth-foundation/no-token-verifier-or-session-store",
|
|
12
|
+
summary:
|
|
13
|
+
"At least one tokenVerifier provider or a sessionStore is registered alongside auth-foundation.",
|
|
14
|
+
fix: "Mount an auth-provider-* feature (e.g. auth-provider-jwt / personal-access-tokens) or a sessionStore (e.g. sessions).",
|
|
15
|
+
},
|
|
16
|
+
tokenVerifierShapeCollision: {
|
|
17
|
+
id: "auth-foundation/token-verifier-shape-collision",
|
|
18
|
+
summary:
|
|
19
|
+
"No two tokenVerifier providers claim the same token shape, so resolveTokenVerifier can route unambiguously.",
|
|
20
|
+
fix: "Give each provider a distinct shape.",
|
|
21
|
+
},
|
|
22
|
+
singleProviderInvalidShape: {
|
|
23
|
+
id: "auth-foundation/single-provider-invalid-shape",
|
|
24
|
+
summary:
|
|
25
|
+
"A single-provider extension registration carries the options shape its provider type requires.",
|
|
26
|
+
fix: "Register the provider with the options shape named in the error message.",
|
|
27
|
+
},
|
|
28
|
+
singleProviderMultiple: {
|
|
29
|
+
id: "auth-foundation/single-provider-multiple",
|
|
30
|
+
summary: "At most one provider of a single-provider extension is mounted at a time.",
|
|
31
|
+
fix: "Unmount all but one provider.",
|
|
32
|
+
},
|
|
33
|
+
} as const satisfies BootRuleTable;
|
|
@@ -1,66 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
writeFailure,
|
|
5
|
-
} from "@cosmicdrift/kumiko-framework/errors";
|
|
6
|
-
import { AuthMfaErrorCodes } from "./web/constants.ts";
|
|
1
|
+
import type { WriteFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
2
|
+
import { unprocessable } from "../shared/index.ts";
|
|
3
|
+
import { AuthMfaErrorCodes as Code } from "./web/constants.ts";
|
|
7
4
|
|
|
8
5
|
export { AuthMfaErrorCodes as AuthMfaErrors } from "./web/constants.ts";
|
|
9
6
|
|
|
10
7
|
export function mfaAlreadyEnabled(): WriteFailure {
|
|
11
|
-
return
|
|
12
|
-
new UnprocessableError(AuthMfaErrorCodes.mfaAlreadyEnabled, {
|
|
13
|
-
i18nKey: "auth.mfa.errors.mfaAlreadyEnabled",
|
|
14
|
-
}),
|
|
15
|
-
);
|
|
8
|
+
return unprocessable(Code.mfaAlreadyEnabled, "auth.mfa.errors.mfaAlreadyEnabled");
|
|
16
9
|
}
|
|
17
10
|
|
|
18
11
|
export function mfaNotEnabled(): WriteFailure {
|
|
19
|
-
return
|
|
20
|
-
new UnprocessableError(AuthMfaErrorCodes.mfaNotEnabled, {
|
|
21
|
-
i18nKey: "auth.mfa.errors.mfaNotEnabled",
|
|
22
|
-
}),
|
|
23
|
-
);
|
|
12
|
+
return unprocessable(Code.mfaNotEnabled, "auth.mfa.errors.mfaNotEnabled");
|
|
24
13
|
}
|
|
25
14
|
|
|
26
15
|
export function invalidSetupToken(): WriteFailure {
|
|
27
|
-
return
|
|
28
|
-
new UnprocessableError(AuthMfaErrorCodes.invalidSetupToken, {
|
|
29
|
-
i18nKey: "auth.mfa.errors.invalidSetupToken",
|
|
30
|
-
}),
|
|
31
|
-
);
|
|
16
|
+
return unprocessable(Code.invalidSetupToken, "auth.mfa.errors.invalidSetupToken");
|
|
32
17
|
}
|
|
33
18
|
|
|
34
19
|
export function invalidTotpCode(): WriteFailure {
|
|
35
|
-
return
|
|
36
|
-
new UnprocessableError(AuthMfaErrorCodes.invalidTotpCode, {
|
|
37
|
-
i18nKey: "auth.mfa.errors.invalidTotpCode",
|
|
38
|
-
}),
|
|
39
|
-
);
|
|
20
|
+
return unprocessable(Code.invalidTotpCode, "auth.mfa.errors.invalidTotpCode");
|
|
40
21
|
}
|
|
41
22
|
|
|
42
23
|
export function invalidRecoveryCode(): WriteFailure {
|
|
43
|
-
return
|
|
44
|
-
new UnprocessableError(AuthMfaErrorCodes.invalidRecoveryCode, {
|
|
45
|
-
i18nKey: "auth.mfa.errors.invalidRecoveryCode",
|
|
46
|
-
}),
|
|
47
|
-
);
|
|
24
|
+
return unprocessable(Code.invalidRecoveryCode, "auth.mfa.errors.invalidRecoveryCode");
|
|
48
25
|
}
|
|
49
26
|
|
|
50
27
|
export function invalidChallengeToken(): WriteFailure {
|
|
51
|
-
return
|
|
52
|
-
new UnprocessableError(AuthMfaErrorCodes.invalidChallengeToken, {
|
|
53
|
-
i18nKey: "auth.mfa.errors.invalidChallengeToken",
|
|
54
|
-
}),
|
|
55
|
-
);
|
|
28
|
+
return unprocessable(Code.invalidChallengeToken, "auth.mfa.errors.invalidChallengeToken");
|
|
56
29
|
}
|
|
57
30
|
|
|
58
31
|
// retryAfterSeconds drives the login UI countdown — must stay > 0.
|
|
59
32
|
export function tooManyAttempts(retryAfterSeconds: number): WriteFailure {
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
details: { retryAfterSeconds },
|
|
64
|
-
}),
|
|
65
|
-
);
|
|
33
|
+
return unprocessable(Code.tooManyAttempts, "auth.mfa.errors.tooManyAttempts", {
|
|
34
|
+
retryAfterSeconds,
|
|
35
|
+
});
|
|
66
36
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { readFeatureExportFn } from "../shared/index.ts";
|
|
2
3
|
import type { MfaCodeVerifier } from "./mfa-code-verifier.ts";
|
|
3
4
|
import type { MfaStatusChecker } from "./mfa-status-checker.ts";
|
|
4
5
|
import type { MfaTokenSecretsEnv } from "./token-secrets.ts";
|
|
@@ -17,15 +18,7 @@ export type BindMfaRevokeAllOtherSessions = (
|
|
|
17
18
|
export function bindMfaRevokeAllOtherSessionsFromFeature(
|
|
18
19
|
feature: FeatureDefinition,
|
|
19
20
|
): BindMfaRevokeAllOtherSessions | undefined {
|
|
20
|
-
|
|
21
|
-
if (exports && typeof exports === "object" && "bindRevokeAllOtherSessions" in exports) {
|
|
22
|
-
const { bindRevokeAllOtherSessions } = exports;
|
|
23
|
-
if (typeof bindRevokeAllOtherSessions === "function") {
|
|
24
|
-
// @cast-boundary feature-exports — feature.exports is untyped by design
|
|
25
|
-
return bindRevokeAllOtherSessions as BindMfaRevokeAllOtherSessions;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return undefined;
|
|
21
|
+
return readFeatureExportFn<BindMfaRevokeAllOtherSessions>(feature, "bindRevokeAllOtherSessions");
|
|
29
22
|
}
|
|
30
23
|
|
|
31
24
|
// Reads the eagerly-built `checkMfaStatus` off a mounted auth-mfa feature's
|
|
@@ -33,15 +26,7 @@ export function bindMfaRevokeAllOtherSessionsFromFeature(
|
|
|
33
26
|
export function mfaStatusCheckerFromFeature(
|
|
34
27
|
feature: FeatureDefinition,
|
|
35
28
|
): MfaStatusChecker | undefined {
|
|
36
|
-
|
|
37
|
-
if (exports && typeof exports === "object" && "checkMfaStatus" in exports) {
|
|
38
|
-
const { checkMfaStatus } = exports;
|
|
39
|
-
if (typeof checkMfaStatus === "function") {
|
|
40
|
-
// @cast-boundary feature-exports — feature.exports is untyped by design
|
|
41
|
-
return checkMfaStatus as MfaStatusChecker;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return undefined;
|
|
29
|
+
return readFeatureExportFn<MfaStatusChecker>(feature, "checkMfaStatus");
|
|
45
30
|
}
|
|
46
31
|
|
|
47
32
|
// Reads the eagerly-built `verifyMfaCode` off a mounted auth-mfa feature's
|
|
@@ -49,15 +34,7 @@ export function mfaStatusCheckerFromFeature(
|
|
|
49
34
|
// mfaVerifier (re-auth gate for minting a token). Same no-bind-setter
|
|
50
35
|
// reasoning as checkMfaStatus above.
|
|
51
36
|
export function mfaVerifierFromFeature(feature: FeatureDefinition): MfaCodeVerifier | undefined {
|
|
52
|
-
|
|
53
|
-
if (exports && typeof exports === "object" && "verifyMfaCode" in exports) {
|
|
54
|
-
const { verifyMfaCode } = exports;
|
|
55
|
-
if (typeof verifyMfaCode === "function") {
|
|
56
|
-
// @cast-boundary feature-exports — feature.exports is untyped by design
|
|
57
|
-
return verifyMfaCode as MfaCodeVerifier;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
return undefined;
|
|
37
|
+
return readFeatureExportFn<MfaCodeVerifier>(feature, "verifyMfaCode");
|
|
61
38
|
}
|
|
62
39
|
|
|
63
40
|
export type BindMfaTokenSecrets = (masterSecret: string, env: MfaTokenSecretsEnv) => void;
|
|
@@ -68,15 +45,7 @@ export type BindMfaTokenSecrets = (masterSecret: string, env: MfaTokenSecretsEnv
|
|
|
68
45
|
export function bindMfaTokenSecretsFromFeature(
|
|
69
46
|
feature: FeatureDefinition,
|
|
70
47
|
): BindMfaTokenSecrets | undefined {
|
|
71
|
-
|
|
72
|
-
if (exports && typeof exports === "object" && "bindTokenSecrets" in exports) {
|
|
73
|
-
const { bindTokenSecrets } = exports;
|
|
74
|
-
if (typeof bindTokenSecrets === "function") {
|
|
75
|
-
// @cast-boundary feature-exports — feature.exports is untyped by design
|
|
76
|
-
return bindTokenSecrets as BindMfaTokenSecrets;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
return undefined;
|
|
48
|
+
return readFeatureExportFn<BindMfaTokenSecrets>(feature, "bindTokenSecrets");
|
|
80
49
|
}
|
|
81
50
|
|
|
82
51
|
export type BindRevokeAllPatTokens = (revoker: (userId: string) => Promise<number>) => () => void;
|
|
@@ -88,13 +57,5 @@ export type BindRevokeAllPatTokens = (revoker: (userId: string) => Promise<numbe
|
|
|
88
57
|
export function bindRevokeAllPatTokensFromFeature(
|
|
89
58
|
feature: FeatureDefinition,
|
|
90
59
|
): BindRevokeAllPatTokens | undefined {
|
|
91
|
-
|
|
92
|
-
if (exports && typeof exports === "object" && "bindRevokeAllPatTokens" in exports) {
|
|
93
|
-
const { bindRevokeAllPatTokens } = exports;
|
|
94
|
-
if (typeof bindRevokeAllPatTokens === "function") {
|
|
95
|
-
// @cast-boundary feature-exports — feature.exports is untyped by design
|
|
96
|
-
return bindRevokeAllPatTokens as BindRevokeAllPatTokens;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
return undefined;
|
|
60
|
+
return readFeatureExportFn<BindRevokeAllPatTokens>(feature, "bindRevokeAllPatTokens");
|
|
100
61
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { DbConnection } from "@cosmicdrift/kumiko-framework/db";
|
|
2
2
|
import { defineFeature, type FeatureDefinition } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import { type FeatureWithEnvSchema, featureWithEnvSchema } from "@cosmicdrift/kumiko-framework/env";
|
|
4
|
+
import { createLateBoundSlot } from "../shared/index.ts";
|
|
4
5
|
import { type MfaRequiredPolicy, mfaRequiredConfigKey } from "./config.ts";
|
|
5
6
|
import { authMfaEnvSchema } from "./env.ts";
|
|
6
7
|
import type {
|
|
@@ -111,19 +112,18 @@ export function createAuthMfaFeature(
|
|
|
111
112
|
// sessions' own bindAutoRevokeOnPasswordChange. Shared by every handler
|
|
112
113
|
// that changes MFA state (enable/disable/regenerate), so each one's
|
|
113
114
|
// "log out every other session" behavior tracks the same wiring.
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
| undefined;
|
|
115
|
+
const otherSessionsRevokerSlot =
|
|
116
|
+
createLateBoundSlot<(userId: string, currentSid: string | undefined) => Promise<number>>();
|
|
117
117
|
const sharedRevoker = (userId: string, currentSid: string | undefined): Promise<number> =>
|
|
118
|
-
|
|
118
|
+
otherSessionsRevokerSlot.current()?.(userId, currentSid) ?? Promise.resolve(0);
|
|
119
119
|
|
|
120
120
|
// Same late-bind shape as sharedRevoker above, for the personal-access-
|
|
121
121
|
// tokens feature (if mounted). Wired to enable-confirm(-preauth)/disable
|
|
122
122
|
// only — regenerate-recovery doesn't change enrollment state, so it's
|
|
123
123
|
// out of scope for the "MFA-enable/disable" finding this mirrors.
|
|
124
|
-
|
|
124
|
+
const patTokensRevokerSlot = createLateBoundSlot<(userId: string) => Promise<number>>();
|
|
125
125
|
const sharedPatRevoker = (userId: string): Promise<number> =>
|
|
126
|
-
|
|
126
|
+
patTokensRevokerSlot.current()?.(userId) ?? Promise.resolve(0);
|
|
127
127
|
|
|
128
128
|
// Handlers and the status checker read the secrets through these getters
|
|
129
129
|
// on each call, so the boot can bind them after env validation. Never
|
|
@@ -218,19 +218,8 @@ export function createAuthMfaFeature(
|
|
|
218
218
|
// HandlerContext the caller already has.
|
|
219
219
|
const verifyMfaCode = createMfaCodeVerifier();
|
|
220
220
|
|
|
221
|
-
const bindRevokeAllOtherSessions: BindMfaRevokeAllOtherSessions =
|
|
222
|
-
|
|
223
|
-
return () => {
|
|
224
|
-
if (revokeAllOtherSessions === revoker) revokeAllOtherSessions = undefined;
|
|
225
|
-
};
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
const bindRevokeAllPatTokens: BindRevokeAllPatTokens = (revoker) => {
|
|
229
|
-
revokeAllPatTokens = revoker;
|
|
230
|
-
return () => {
|
|
231
|
-
if (revokeAllPatTokens === revoker) revokeAllPatTokens = undefined;
|
|
232
|
-
};
|
|
233
|
-
};
|
|
221
|
+
const bindRevokeAllOtherSessions: BindMfaRevokeAllOtherSessions = otherSessionsRevokerSlot.bind;
|
|
222
|
+
const bindRevokeAllPatTokens: BindRevokeAllPatTokens = patTokensRevokerSlot.bind;
|
|
234
223
|
|
|
235
224
|
return {
|
|
236
225
|
handlers,
|
|
@@ -14,19 +14,23 @@ import {
|
|
|
14
14
|
toLoginResponse,
|
|
15
15
|
} from "../../auth-email-password/web/index.ts";
|
|
16
16
|
|
|
17
|
+
const VERIFY_PATH = "/api/auth/mfa/verify";
|
|
18
|
+
const PREAUTH_CONFIRM_PATH = "/api/auth/mfa/preauth-confirm";
|
|
19
|
+
|
|
17
20
|
export type MfaVerifyResult =
|
|
18
21
|
| { readonly kind: "success"; readonly data: LoginResponse }
|
|
19
22
|
| { readonly kind: "failure"; readonly error: LoginFailure };
|
|
20
23
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
+
async function postMfaLogin(
|
|
25
|
+
path: string,
|
|
26
|
+
payload: Record<string, string>,
|
|
27
|
+
fallbackReason: string,
|
|
24
28
|
): Promise<MfaVerifyResult> {
|
|
25
|
-
const res = await fetch(
|
|
29
|
+
const res = await fetch(path, {
|
|
26
30
|
method: "POST",
|
|
27
31
|
credentials: "same-origin",
|
|
28
32
|
headers: { "Content-Type": "application/json" },
|
|
29
|
-
body: JSON.stringify(
|
|
33
|
+
body: JSON.stringify(payload),
|
|
30
34
|
});
|
|
31
35
|
if (res.status === 429) {
|
|
32
36
|
return { kind: "failure", error: { reason: "rate_limited" } };
|
|
@@ -45,7 +49,14 @@ export async function verifyMfaChallenge(
|
|
|
45
49
|
data: toLoginResponse(body.token, body.user, body.landingPath),
|
|
46
50
|
};
|
|
47
51
|
}
|
|
48
|
-
return { kind: "failure", error: failureFromErrorField(body.error,
|
|
52
|
+
return { kind: "failure", error: failureFromErrorField(body.error, fallbackReason) };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export async function verifyMfaChallenge(
|
|
56
|
+
challengeToken: string,
|
|
57
|
+
code: string,
|
|
58
|
+
): Promise<MfaVerifyResult> {
|
|
59
|
+
return postMfaLogin(VERIFY_PATH, { challengeToken, code }, "mfa_verify_failed");
|
|
49
60
|
}
|
|
50
61
|
|
|
51
62
|
export type MfaSetupPreauthStart = {
|
|
@@ -106,35 +117,10 @@ export async function startMfaSetupPreauth(
|
|
|
106
117
|
// Browser side of POST /api/auth/mfa/preauth-confirm — completes both the
|
|
107
118
|
// enrollment started by startMfaSetupPreauth and the login
|
|
108
119
|
// mfa-setup-required block. Its response mirrors /auth/mfa/verify's and is
|
|
109
|
-
// minted via the same mintSessionAndRespond()
|
|
110
|
-
// so this file's two already-tested request shapes stay independently
|
|
111
|
-
// editable.
|
|
120
|
+
// minted via the same mintSessionAndRespond(), so both share postMfaLogin.
|
|
112
121
|
export async function confirmMfaSetupPreauth(
|
|
113
122
|
setupToken: string,
|
|
114
123
|
code: string,
|
|
115
124
|
): Promise<MfaVerifyResult> {
|
|
116
|
-
|
|
117
|
-
method: "POST",
|
|
118
|
-
credentials: "same-origin",
|
|
119
|
-
headers: { "Content-Type": "application/json" },
|
|
120
|
-
body: JSON.stringify({ setupToken, code }),
|
|
121
|
-
});
|
|
122
|
-
if (res.status === 429) {
|
|
123
|
-
return { kind: "failure", error: { reason: "rate_limited" } };
|
|
124
|
-
}
|
|
125
|
-
// @cast-boundary engine-payload — HTTP-API contract, server-side schema-validated
|
|
126
|
-
const body = (await res.json().catch(() => ({}))) as {
|
|
127
|
-
isSuccess?: boolean;
|
|
128
|
-
token?: string;
|
|
129
|
-
user?: LoginResponse["user"];
|
|
130
|
-
landingPath?: string;
|
|
131
|
-
error?: unknown;
|
|
132
|
-
};
|
|
133
|
-
if (body.isSuccess === true && body.token !== undefined && body.user !== undefined) {
|
|
134
|
-
return {
|
|
135
|
-
kind: "success",
|
|
136
|
-
data: toLoginResponse(body.token, body.user, body.landingPath),
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
return { kind: "failure", error: failureFromErrorField(body.error, "mfa_setup_confirm_failed") };
|
|
125
|
+
return postMfaLogin(PREAUTH_CONFIRM_PATH, { setupToken, code }, "mfa_setup_confirm_failed");
|
|
140
126
|
}
|
package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type OperatorNoticePlan = {
|
|
|
18
18
|
readonly providerCancel?: ProviderCancelOutcome;
|
|
19
19
|
};
|
|
20
20
|
|
|
21
|
+
// guard:dup-ok narrows one optional ctx member with this feature's own mount hint
|
|
21
22
|
export function requireNotify(ctx: HandlerContext): NonNullable<HandlerContext["notify"]> {
|
|
22
23
|
if (!ctx.notify) {
|
|
23
24
|
throw new InternalError({
|