@cosmicdrift/kumiko-samples 0.409.0 → 0.411.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 +36 -1
- package/packages/bundled-features/src/auth-email-password/changes.json +24 -0
- package/packages/bundled-features/src/auth-email-password/handlers/login-options.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/handlers/self-registration-status.query.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/seeding.ts +84 -6
- package/packages/bundled-features/src/auth-email-password/web/i18n.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/web/signup-screen.tsx +48 -3
- package/packages/bundled-features/src/auth-email-password/web/static-account.ts +190 -0
- package/packages/bundled-features/src/auth-email-password/web/static-client.ts +226 -0
- package/packages/bundled-features/src/compliance-profiles/handlers/sub-processors.query.ts +4 -1
- package/packages/bundled-features/src/contact/changes.json +6 -0
- package/packages/bundled-features/src/contact/client/contact-website-client.ts +29 -0
- package/packages/bundled-features/src/contact/client/index.ts +9 -0
- package/packages/bundled-features/src/contact/feature.ts +3 -0
- package/packages/bundled-features/src/contact/handlers/access.ts +1 -1
- package/packages/bundled-features/src/contact/handlers/challenge.query.ts +1 -1
- package/packages/bundled-features/src/contact/handlers/submit.write.ts +1 -1
- package/packages/bundled-features/src/contact/i18n.ts +4 -1
- package/packages/bundled-features/src/contact/options.ts +1 -1
- package/packages/bundled-features/src/contact/screens.ts +1 -0
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +1 -1
- package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +1 -1
- package/packages/bundled-features/src/foundation-shared/demo-admin-env.ts +11 -0
- package/packages/bundled-features/src/foundation-shared/index.ts +5 -1
- package/packages/bundled-features/src/inbound-provider-imap/changes.json +6 -0
- package/packages/bundled-features/src/inbound-provider-imap/imap-client.ts +3 -1
- package/packages/bundled-features/src/managed-pages/handlers/branding.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/managed-pages/handlers/by-tenant-published.query.ts +1 -1
- package/packages/bundled-features/src/presence/changes.json +8 -0
- package/packages/bundled-features/src/presence/feature.ts +25 -0
- package/packages/bundled-features/src/presence/handlers/heartbeat.write.ts +52 -0
- package/packages/bundled-features/src/presence/handlers/leave.write.ts +41 -0
- package/packages/bundled-features/src/presence/handlers/list.query.ts +39 -0
- package/packages/bundled-features/src/presence/index.ts +7 -0
- package/packages/bundled-features/src/presence/options.ts +30 -0
- package/packages/bundled-features/src/presence/payloads.ts +26 -0
- package/packages/bundled-features/src/presence/room.ts +65 -0
- package/packages/bundled-features/src/presence/store.ts +185 -0
- package/packages/bundled-features/src/seo/handlers/seo-config.query.ts +1 -1
- package/packages/bundled-features/src/sessions/feature.ts +6 -2
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +19 -0
- package/packages/bundled-features/src/subscription-paddle/checkout-config.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/by-slug.query.ts +1 -1
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +12 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +14 -6
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +4 -1
- package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +2 -1
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +5 -1
- package/packages/bundled-features/src/tenant-inactivity/options.ts +1 -0
- package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +6 -1
- package/packages/bundled-features/src/tenant-inactivity/static-keep-account.ts +37 -0
- package/packages/bundled-features/src/tenant-lifecycle/constants.ts +2 -0
- package/packages/bundled-features/src/tenant-lifecycle/handlers/cancel-destruction.write.ts +6 -2
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +2 -1
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +4 -1
- package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/handlers/request-deletion-by-email.write.ts +4 -1
- package/packages/bundled-features/src/waitlist/changes.json +12 -0
- package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +1 -2
- package/packages/bundled-features/src/waitlist/static-submit.ts +56 -0
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +143 -0
- package/samples/apps/styleguide/src/features/widgets/web/VariantsDemo.tsx +276 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +3 -0
- package/samples/apps/styleguide/src/features/workboard/feature.ts +1 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +26 -25
- package/samples/apps/use-all-bundled/playwright.config.ts +0 -2
- package/samples/apps/use-all-bundled/src/run-config.ts +6 -15
- package/samples/recipes/anonymous-access/README.md +2 -0
- package/samples/recipes/anonymous-access/src/feature.ts +7 -1
- package/samples/recipes/contact/README.md +10 -4
- package/samples/recipes/contact/src/feature.ts +1 -1
- package/samples/recipes/realtime-sse/README.md +1 -0
- package/samples/recipes/realtime-sse/package.json +1 -0
- package/samples/recipes/realtime-sse/src/feature.ts +9 -0
- package/samples/recipes/record-detail-layout/README.md +1 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +10 -0
- package/samples/recipes/wizard-form/README.md +9 -0
- package/samples/recipes/wizard-form/src/feature.ts +13 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-samples",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.411.0",
|
|
4
4
|
"description": "Source trees of the Kumiko sample recipes, sample apps and bundled features in repo layout, for tooling such as few-shot corpus builds.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-bundled-features",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.411.0",
|
|
4
4
|
"description": "Built-in features — tenant, user, auth, delivery. The stuff you'd rewrite anyway, already typed.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -94,6 +94,8 @@
|
|
|
94
94
|
"./tenant/web": "./src/tenant/web/index.ts",
|
|
95
95
|
"./tenant/seeding": "./src/tenant/seeding.ts",
|
|
96
96
|
"./tenant-inactivity": "./src/tenant-inactivity/index.ts",
|
|
97
|
+
"./tenant-inactivity/constants": "./src/tenant-inactivity/constants.ts",
|
|
98
|
+
"./tenant-inactivity/static-keep-account": "./src/tenant-inactivity/static-keep-account.ts",
|
|
97
99
|
"./tenant-inactivity/email-templates": "./src/tenant-inactivity/email-templates.ts",
|
|
98
100
|
"./tenant-lifecycle": "./src/tenant-lifecycle/index.ts",
|
|
99
101
|
"./tenant-lifecycle/testing": "./src/tenant-lifecycle/testing.ts",
|
|
@@ -108,6 +110,8 @@
|
|
|
108
110
|
"./auth-email-password/constants": "./src/auth-email-password/web/constants.ts",
|
|
109
111
|
"./auth-email-password/return-path": "./src/auth-email-password/web/return-path.ts",
|
|
110
112
|
"./auth-email-password/static-login": "./src/auth-email-password/web/static-login.ts",
|
|
113
|
+
"./auth-email-password/static-account": "./src/auth-email-password/web/static-account.ts",
|
|
114
|
+
"./auth-email-password/static-client": "./src/auth-email-password/web/static-client.ts",
|
|
111
115
|
"./auth-email-password/email-templates": "./src/auth-email-password/email-templates.ts",
|
|
112
116
|
"./auth-email-password/seeding": "./src/auth-email-password/seeding.ts",
|
|
113
117
|
"./auth-email-password/testing": "./src/auth-email-password/testing.ts",
|
|
@@ -154,8 +158,11 @@
|
|
|
154
158
|
"./legal-pages/constants": "./src/legal-pages/web/constants.ts",
|
|
155
159
|
"./legal-pages/web": "./src/legal-pages/web/index.ts",
|
|
156
160
|
"./contact": "./src/contact/index.ts",
|
|
161
|
+
"./presence": "./src/presence/index.ts",
|
|
157
162
|
"./contact/web": "./src/contact/web/index.ts",
|
|
163
|
+
"./contact/client": "./src/contact/client/index.ts",
|
|
158
164
|
"./waitlist": "./src/waitlist/index.ts",
|
|
165
|
+
"./waitlist/static-submit": "./src/waitlist/static-submit.ts",
|
|
159
166
|
"./page-render": "./src/page-render/index.ts",
|
|
160
167
|
"./page-render/web": "./src/page-render/web.ts",
|
|
161
168
|
"./managed-pages": "./src/managed-pages/index.ts",
|
|
@@ -488,6 +495,14 @@
|
|
|
488
495
|
"types": "./dist/tenant-inactivity/index.d.ts",
|
|
489
496
|
"default": "./dist/tenant-inactivity/index.js"
|
|
490
497
|
},
|
|
498
|
+
"./tenant-inactivity/constants": {
|
|
499
|
+
"types": "./dist/tenant-inactivity/constants.d.ts",
|
|
500
|
+
"default": "./dist/tenant-inactivity/constants.js"
|
|
501
|
+
},
|
|
502
|
+
"./tenant-inactivity/static-keep-account": {
|
|
503
|
+
"types": "./dist/tenant-inactivity/static-keep-account.d.ts",
|
|
504
|
+
"default": "./dist/tenant-inactivity/static-keep-account.js"
|
|
505
|
+
},
|
|
491
506
|
"./tenant-inactivity/email-templates": {
|
|
492
507
|
"types": "./dist/tenant-inactivity/email-templates.d.ts",
|
|
493
508
|
"default": "./dist/tenant-inactivity/email-templates.js"
|
|
@@ -548,6 +563,14 @@
|
|
|
548
563
|
"types": "./dist/auth-email-password/web/static-login.d.ts",
|
|
549
564
|
"default": "./dist/auth-email-password/web/static-login.js"
|
|
550
565
|
},
|
|
566
|
+
"./auth-email-password/static-account": {
|
|
567
|
+
"types": "./dist/auth-email-password/web/static-account.d.ts",
|
|
568
|
+
"default": "./dist/auth-email-password/web/static-account.js"
|
|
569
|
+
},
|
|
570
|
+
"./auth-email-password/static-client": {
|
|
571
|
+
"types": "./dist/auth-email-password/web/static-client.d.ts",
|
|
572
|
+
"default": "./dist/auth-email-password/web/static-client.js"
|
|
573
|
+
},
|
|
551
574
|
"./auth-email-password/seeding": {
|
|
552
575
|
"types": "./dist/auth-email-password/seeding.d.ts",
|
|
553
576
|
"default": "./dist/auth-email-password/seeding.js"
|
|
@@ -728,14 +751,26 @@
|
|
|
728
751
|
"types": "./dist/contact/index.d.ts",
|
|
729
752
|
"default": "./dist/contact/index.js"
|
|
730
753
|
},
|
|
754
|
+
"./presence": {
|
|
755
|
+
"types": "./dist/presence/index.d.ts",
|
|
756
|
+
"default": "./dist/presence/index.js"
|
|
757
|
+
},
|
|
731
758
|
"./contact/web": {
|
|
732
759
|
"types": "./dist/contact/web/index.d.ts",
|
|
733
760
|
"default": "./dist/contact/web/index.js"
|
|
734
761
|
},
|
|
762
|
+
"./contact/client": {
|
|
763
|
+
"types": "./dist/contact/client/index.d.ts",
|
|
764
|
+
"default": "./dist/contact/client/index.js"
|
|
765
|
+
},
|
|
735
766
|
"./waitlist": {
|
|
736
767
|
"types": "./dist/waitlist/index.d.ts",
|
|
737
768
|
"default": "./dist/waitlist/index.js"
|
|
738
769
|
},
|
|
770
|
+
"./waitlist/static-submit": {
|
|
771
|
+
"types": "./dist/waitlist/static-submit.d.ts",
|
|
772
|
+
"default": "./dist/waitlist/static-submit.js"
|
|
773
|
+
},
|
|
739
774
|
"./page-render": {
|
|
740
775
|
"types": "./dist/page-render/index.d.ts",
|
|
741
776
|
"default": "./dist/page-render/index.js"
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.411.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "SignupScreen shows a closed state while self-registration is off",
|
|
6
|
+
"detail": "With a mounted dispatcher the screen asks `auth-email-password:query:signup-registration-status`. While `enabled` is false it renders the notice `auth.signup.closed` (de: \"Die Registrierung ist derzeit nur mit Einladung möglich.\") plus the login link instead of the form, and sends nothing. A failed status query reads as open. The status query needs a mounted `DispatcherProvider`; in standalone auth mounts without one the form always shows and the server still rejects `signup-request`. New key `auth.signup.closed` in en, de, es, fr and it."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.411.0",
|
|
10
|
+
"type": "improvement",
|
|
11
|
+
"title": "auth-email-password/static-account, DOM-free account page clients",
|
|
12
|
+
"detail": "`@cosmicdrift/kumiko-bundled-features/auth-email-password/static-account` exports `fetchSignupRegistrationStatus`, `requestPasswordReset`, `resetPassword`, `verifyEmail`, `requestAccountUnlock`, `confirmAccountUnlock`, `logout`, `isSignedOutFailure`, `fetchInviteInfo`, `acceptInviteSignedIn`, `acceptInviteWithLogin` and `acceptInviteWithNewAccount` for plain Astro scripts, plus `takeUrlToken(\"query\" | \"fragment\")` to read a mail-link token and remove it from the address bar. Every call returns a `kind: \"success\" | \"failure\"` union with a `reason` and, for rate limits, `retryAfterSeconds`; a 401 without an error code reads as `unauthenticated`; none throws for an expected failure; a malformed CSRF cookie sends no CSRF header instead of failing the request. A `landingPath` from the server is passed on only when it is a safe same-origin path. The shared request core with the result types is exported as `auth-email-password/static-client`."
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"version": "0.411.0",
|
|
16
|
+
"type": "improvement",
|
|
17
|
+
"title": "seedAdmin works without a password",
|
|
18
|
+
"detail": "`SeedAdminOptions.password` is optional. Without it the account is created without a password hash and sets one through the password-reset flow. An existing account with the same email keeps its hash, as before."
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"version": "0.411.0",
|
|
22
|
+
"type": "fix",
|
|
23
|
+
"title": "Bootstrap admin seed is one-shot",
|
|
24
|
+
"detail": "`seedBootstrapAdmin` skips when the target tenant already has another member (also a removed one), so a deleted owner or one who changed their email is not re-created as a passwordless SystemAdmin on the next boot. Our own passwordless account without membership is still completed, and the has-password skip now re-checks the row right before the grants."
|
|
25
|
+
},
|
|
2
26
|
{
|
|
3
27
|
"version": "0.405.0",
|
|
4
28
|
"type": "improvement",
|
|
@@ -8,7 +8,7 @@ import { AuthHandlers } from "../web/constants.ts";
|
|
|
8
8
|
export const loginOptionsQuery = defineQueryHandler({
|
|
9
9
|
name: "login-options",
|
|
10
10
|
schema: z.object({}),
|
|
11
|
-
access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
|
|
11
|
+
access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
|
|
12
12
|
rateLimit: { per: "ip+handler", limit: 30, windowSeconds: 60 },
|
|
13
13
|
description:
|
|
14
14
|
"Reports which optional login-page flows (password reset, account unlock) are available, readable without signing in, so the login screen links only to flows that exist.",
|
package/packages/bundled-features/src/auth-email-password/handlers/self-registration-status.query.ts
CHANGED
|
@@ -13,7 +13,7 @@ import { AUTH_SELF_REGISTRATION_FEATURE } from "../self-registration-toggle.ts";
|
|
|
13
13
|
export const selfRegistrationStatusQuery = defineQueryHandler({
|
|
14
14
|
name: "signup-registration-status",
|
|
15
15
|
schema: z.object({}),
|
|
16
|
-
access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"] },
|
|
16
|
+
access: { roles: ["anonymous", "User", "TenantAdmin", "SystemAdmin"], anySignedIn: true },
|
|
17
17
|
rateLimit: { per: "ip+handler", limit: 30, windowSeconds: 60 },
|
|
18
18
|
description:
|
|
19
19
|
"Reports whether self-registration is currently switched on, readable without signing in, so a signup page can hide its own form instead of collecting an address that would be silently ignored.",
|
|
@@ -29,6 +29,8 @@ import {
|
|
|
29
29
|
import { ConflictError } from "@cosmicdrift/kumiko-framework/errors";
|
|
30
30
|
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
31
31
|
import { hashPassword } from "../shared/index.ts";
|
|
32
|
+
// kumiko-lint-ignore cross-feature-import bootstrap admin seed checks whether the tenant already has members
|
|
33
|
+
import { tenantMembershipsTable } from "../tenant/membership-table.ts";
|
|
32
34
|
// kumiko-lint-ignore cross-feature-import auth-tests need user+tenant seed-helpers
|
|
33
35
|
import { type SeedTenantHooks, seedTenant, seedTenantMembership } from "../tenant/seeding.ts";
|
|
34
36
|
// kumiko-lint-ignore cross-feature-import signup create-only guard reads the user projection by email
|
|
@@ -195,7 +197,8 @@ export async function provisionSignupAccount(
|
|
|
195
197
|
|
|
196
198
|
export type SeedAdminOptions = {
|
|
197
199
|
readonly email: string;
|
|
198
|
-
|
|
200
|
+
/** Omit to seed an account without a password; it sets one via password reset. */
|
|
201
|
+
readonly password?: string;
|
|
199
202
|
readonly displayName: string;
|
|
200
203
|
/** Tenants where the admin is added as a member. Each tenant can have
|
|
201
204
|
* its own role list, which lets the sample TenantSwitcher show different
|
|
@@ -234,14 +237,17 @@ export async function seedAdmin(
|
|
|
234
237
|
await seedTenant(db, { id: m.tenantId, key: m.tenantKey, name: m.tenantName, ...byOption });
|
|
235
238
|
}
|
|
236
239
|
|
|
237
|
-
const
|
|
240
|
+
const userFields = {
|
|
238
241
|
email: options.email,
|
|
239
|
-
password: options.password,
|
|
240
242
|
displayName: options.displayName,
|
|
241
243
|
...(options.globalRoles !== undefined && { roles: options.globalRoles }),
|
|
242
244
|
...(options.emailVerified !== undefined && { emailVerified: options.emailVerified }),
|
|
243
245
|
...byOption,
|
|
244
|
-
}
|
|
246
|
+
};
|
|
247
|
+
const { id: userId } =
|
|
248
|
+
options.password === undefined
|
|
249
|
+
? await seedUser(db, userFields)
|
|
250
|
+
: await seedUserWithPassword(db, { ...userFields, password: options.password });
|
|
245
251
|
|
|
246
252
|
for (const m of options.memberships) {
|
|
247
253
|
await seedTenantMembership(db, {
|
|
@@ -344,6 +350,18 @@ async function findExistingUserIdForEmail(
|
|
|
344
350
|
return matches.length === 0 ? undefined : pickCanonicalUserId(matches);
|
|
345
351
|
}
|
|
346
352
|
|
|
353
|
+
async function seedAdminPlaintext(
|
|
354
|
+
db: DbConnection,
|
|
355
|
+
options: SeedAdminOptions,
|
|
356
|
+
mayGrantToExisting: ((row: Record<string, unknown>) => boolean) | undefined,
|
|
357
|
+
): Promise<{ id: string }> {
|
|
358
|
+
if (mayGrantToExisting) {
|
|
359
|
+
const row = await fetchOne(db, userTable, { email: options.email, isDeleted: false });
|
|
360
|
+
if (row && !mayGrantToExisting(row)) return { id: String(row["id"]) };
|
|
361
|
+
}
|
|
362
|
+
return seedAdmin(db, options);
|
|
363
|
+
}
|
|
364
|
+
|
|
347
365
|
/**
|
|
348
366
|
* Boot-seed variant of seedAdmin that survives a blind-index miss on an
|
|
349
367
|
* otherwise-existing account (see the module comment above). Not for the
|
|
@@ -361,9 +379,10 @@ async function findExistingUserIdForEmail(
|
|
|
361
379
|
export async function seedAdminGuarded(
|
|
362
380
|
db: DbConnection,
|
|
363
381
|
options: SeedAdminOptions,
|
|
382
|
+
mayGrantToExisting?: (row: Record<string, unknown>) => boolean,
|
|
364
383
|
): Promise<{ id: string }> {
|
|
365
384
|
const kms = configuredPiiSubjectKms();
|
|
366
|
-
if (kms === undefined) return
|
|
385
|
+
if (kms === undefined) return seedAdminPlaintext(db, options, mayGrantToExisting);
|
|
367
386
|
|
|
368
387
|
// Without a bidx key every row seeded here gets a NULL email_bidx, which
|
|
369
388
|
// neither seedAdmin's lookup nor the partial unique index can ever see.
|
|
@@ -383,8 +402,9 @@ export async function seedAdminGuarded(
|
|
|
383
402
|
// Re-write the email so email_bidx is recomputed; without it the account
|
|
384
403
|
// stays unfindable for login and every boot re-scans the whole table.
|
|
385
404
|
await rewriteSeededUserEmail(db, existingRow, options.email, by);
|
|
405
|
+
const refreshed = (await fetchOne(db, userTable, { id: existingId })) ?? existingRow;
|
|
406
|
+
if (mayGrantToExisting && !mayGrantToExisting(refreshed)) return { id: existingId };
|
|
386
407
|
if (options.emailVerified === true) {
|
|
387
|
-
const refreshed = (await fetchOne(db, userTable, { id: existingId })) ?? existingRow;
|
|
388
408
|
await reconcileSeededUserEmailVerified(db, refreshed, by);
|
|
389
409
|
}
|
|
390
410
|
}
|
|
@@ -399,3 +419,61 @@ export async function seedAdminGuarded(
|
|
|
399
419
|
}
|
|
400
420
|
return { id: existingId };
|
|
401
421
|
}
|
|
422
|
+
|
|
423
|
+
async function findExistingUserRowForEmail(db: DbConnection, email: string) {
|
|
424
|
+
const kms = configuredPiiSubjectKms();
|
|
425
|
+
if (kms === undefined) return fetchOne(db, userTable, { email, isDeleted: false });
|
|
426
|
+
const existingId = await findExistingUserIdForEmail(db, kms, email);
|
|
427
|
+
return existingId === undefined ? undefined : fetchOne(db, userTable, { id: existingId });
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
function hasPassword(row: Record<string, unknown>): boolean {
|
|
431
|
+
return typeof row["passwordHash"] === "string" && row["passwordHash"] !== "";
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
/** Tenant already has a member other than `ownUserId` (soft-deleted memberships count). */
|
|
435
|
+
async function tenantHasForeignMember(
|
|
436
|
+
db: DbConnection,
|
|
437
|
+
tenantId: TenantId,
|
|
438
|
+
ownUserId: string | undefined,
|
|
439
|
+
): Promise<boolean> {
|
|
440
|
+
const members = await selectMany(db, tenantMembershipsTable, { tenantId });
|
|
441
|
+
return members.some((member) => member["userId"] !== ownUserId);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
/**
|
|
445
|
+
* One-shot boot seed for an account that sets its password later (password
|
|
446
|
+
* reset). Skipped when the account already has a password (owner after their
|
|
447
|
+
* reset, or a foreign self-registration: granting admin to the latter would be
|
|
448
|
+
* an escalation) and when the target tenant already has another member (owner
|
|
449
|
+
* deleted or changed their email: re-seeding would mint a new passwordless
|
|
450
|
+
* SystemAdmin). Only our own passwordless account is completed, so a partial
|
|
451
|
+
* earlier seed converges.
|
|
452
|
+
*/
|
|
453
|
+
export async function seedBootstrapAdmin(
|
|
454
|
+
db: DbConnection,
|
|
455
|
+
options: SeedAdminOptions,
|
|
456
|
+
): Promise<{ id: string } | { skipped: "has-password" | "tenant-has-members" }> {
|
|
457
|
+
const existing = await findExistingUserRowForEmail(db, options.email);
|
|
458
|
+
if (existing && hasPassword(existing)) {
|
|
459
|
+
log.info("seedBootstrapAdmin: the account already has a password, bootstrap seed skipped");
|
|
460
|
+
return { skipped: "has-password" };
|
|
461
|
+
}
|
|
462
|
+
const ownUserId = typeof existing?.["id"] === "string" ? existing["id"] : undefined;
|
|
463
|
+
for (const membership of options.memberships) {
|
|
464
|
+
if (await tenantHasForeignMember(db, membership.tenantId, ownUserId)) {
|
|
465
|
+
log.info("seedBootstrapAdmin: the tenant already has members, bootstrap seed skipped");
|
|
466
|
+
return { skipped: "tenant-has-members" };
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
let passwordAppeared = false;
|
|
470
|
+
const seeded = await seedAdminGuarded(db, options, (row) => {
|
|
471
|
+
passwordAppeared = hasPassword(row);
|
|
472
|
+
return !passwordAppeared;
|
|
473
|
+
});
|
|
474
|
+
if (passwordAppeared) {
|
|
475
|
+
log.info("seedBootstrapAdmin: the account got a password meanwhile, bootstrap seed skipped");
|
|
476
|
+
return { skipped: "has-password" };
|
|
477
|
+
}
|
|
478
|
+
return seeded;
|
|
479
|
+
}
|
|
@@ -98,6 +98,7 @@ export const defaultTranslations: TranslationsByLocale = {
|
|
|
98
98
|
"auth.signup.title": "Create account",
|
|
99
99
|
"auth.signup.intro":
|
|
100
100
|
"Enter your email. We'll send you an activation link to set your password.",
|
|
101
|
+
"auth.signup.closed": "Sign-up is currently by invitation only.",
|
|
101
102
|
"auth.signup.email": "Email",
|
|
102
103
|
"auth.signup.submit": "Send activation link",
|
|
103
104
|
"auth.signup.submitting": "…",
|
|
@@ -11,12 +11,18 @@
|
|
|
11
11
|
// AuthGate). An apex marketing site can route its "Start for free" link to
|
|
12
12
|
// the /signup path.
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
useOptionalDispatcher,
|
|
16
|
+
usePrimitives,
|
|
17
|
+
useQuery,
|
|
18
|
+
useTranslation,
|
|
19
|
+
} from "@cosmicdrift/kumiko-renderer";
|
|
15
20
|
import { type FormEvent, type ReactNode, useState } from "react";
|
|
16
21
|
import { requestSignup } from "./auth-client.ts";
|
|
17
22
|
import { retryAfterMinutes } from "./auth-form-logic.ts";
|
|
18
23
|
import { AuthCard } from "./auth-form-primitives.tsx";
|
|
19
24
|
import { readReturnToFromWindow } from "./auth-redirect.ts";
|
|
25
|
+
import { AuthQueries } from "./constants.ts";
|
|
20
26
|
import { isSafeReturnPath } from "./return-path.ts";
|
|
21
27
|
|
|
22
28
|
export type SignupScreenProps = {
|
|
@@ -34,12 +40,13 @@ function resolveReturnTo(prop: string | undefined): string | undefined {
|
|
|
34
40
|
return (isSafeReturnPath(prop) ? prop : readReturnToFromWindow()) ?? undefined;
|
|
35
41
|
}
|
|
36
42
|
|
|
37
|
-
|
|
43
|
+
function SignupScreenBody({
|
|
38
44
|
title,
|
|
39
45
|
subtitle,
|
|
40
46
|
loginHref = "/login",
|
|
41
47
|
returnTo,
|
|
42
|
-
|
|
48
|
+
registrationOpen,
|
|
49
|
+
}: SignupScreenProps & { readonly registrationOpen: boolean | "unknown" }): ReactNode {
|
|
43
50
|
const t = useTranslation();
|
|
44
51
|
const { Form, Field, Input, Button, Banner, Link } = usePrimitives();
|
|
45
52
|
const [email, setEmail] = useState("");
|
|
@@ -91,6 +98,25 @@ export function SignupScreen({
|
|
|
91
98
|
|
|
92
99
|
const effectiveTitle = title ?? t("auth.signup.title");
|
|
93
100
|
|
|
101
|
+
if (registrationOpen === "unknown") {
|
|
102
|
+
return (
|
|
103
|
+
<AuthCard title={effectiveTitle} subtitle={subtitle}>
|
|
104
|
+
{null}
|
|
105
|
+
</AuthCard>
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!registrationOpen) {
|
|
110
|
+
return (
|
|
111
|
+
<AuthCard title={effectiveTitle} subtitle={subtitle}>
|
|
112
|
+
<Banner variant="info">{t("auth.signup.closed")}</Banner>
|
|
113
|
+
<Link href={loginHref} variant="muted">
|
|
114
|
+
{t("auth.signup.haveAccount")}
|
|
115
|
+
</Link>
|
|
116
|
+
</AuthCard>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
94
120
|
return (
|
|
95
121
|
<AuthCard title={effectiveTitle} subtitle={subtitle}>
|
|
96
122
|
{done ? (
|
|
@@ -135,3 +161,22 @@ export function SignupScreen({
|
|
|
135
161
|
</AuthCard>
|
|
136
162
|
);
|
|
137
163
|
}
|
|
164
|
+
|
|
165
|
+
type RegistrationStatus = { readonly enabled: boolean };
|
|
166
|
+
|
|
167
|
+
// A failed status query reads as open: signup-request itself stays the authority.
|
|
168
|
+
function SignupScreenWithQueriedStatus(props: SignupScreenProps): ReactNode {
|
|
169
|
+
const { data, loading } = useQuery<RegistrationStatus>(AuthQueries.signupRegistrationStatus, {});
|
|
170
|
+
const registrationOpen = loading && data === null ? "unknown" : data?.enabled !== false;
|
|
171
|
+
return <SignupScreenBody {...props} registrationOpen={registrationOpen} />;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Without a mounted dispatcher (standalone mounts, tests) the status is not asked and the form shows.
|
|
175
|
+
export function SignupScreen(props: SignupScreenProps): ReactNode {
|
|
176
|
+
const dispatcher = useOptionalDispatcher();
|
|
177
|
+
return dispatcher === undefined ? (
|
|
178
|
+
<SignupScreenBody {...props} registrationOpen />
|
|
179
|
+
) : (
|
|
180
|
+
<SignupScreenWithQueriedStatus {...props} />
|
|
181
|
+
);
|
|
182
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// DOM-free account pages for static sites (plain Astro scripts): password reset, e-mail
|
|
2
|
+
// verification, invite acceptance and the signup registration status. Same import rules as
|
|
3
|
+
// static-login.ts: fetch plus pure logic, nothing that touches `window` at import time.
|
|
4
|
+
|
|
5
|
+
import { AuthQueries } from "./constants.ts";
|
|
6
|
+
import { isRecord } from "./login-failure.ts";
|
|
7
|
+
import { isSafeReturnPath } from "./return-path.ts";
|
|
8
|
+
import {
|
|
9
|
+
dispatchQuery,
|
|
10
|
+
postJson,
|
|
11
|
+
type StaticRequestOptions,
|
|
12
|
+
type StaticResult,
|
|
13
|
+
staticFailure,
|
|
14
|
+
staticSuccess,
|
|
15
|
+
} from "./static-client.ts";
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
hrefWithoutUrlToken,
|
|
19
|
+
readUrlToken,
|
|
20
|
+
STATIC_MALFORMED_TOKEN_REASON,
|
|
21
|
+
STATIC_NETWORK_REASON,
|
|
22
|
+
STATIC_RATE_LIMITED_REASON,
|
|
23
|
+
type StaticFailure,
|
|
24
|
+
type StaticRequestOptions,
|
|
25
|
+
type StaticResult,
|
|
26
|
+
type StaticSuccess,
|
|
27
|
+
takeUrlToken,
|
|
28
|
+
type UrlTokenSource,
|
|
29
|
+
} from "./static-client.ts";
|
|
30
|
+
|
|
31
|
+
const UNEXPECTED_RESPONSE_REASON = "unexpected_response";
|
|
32
|
+
|
|
33
|
+
export type SignupRegistrationStatus = { readonly enabled: boolean };
|
|
34
|
+
|
|
35
|
+
/** A failed lookup should be read as open: signup-request itself stays the authority. */
|
|
36
|
+
export async function fetchSignupRegistrationStatus(): Promise<
|
|
37
|
+
StaticResult<SignupRegistrationStatus>
|
|
38
|
+
> {
|
|
39
|
+
const result = await dispatchQuery(AuthQueries.signupRegistrationStatus, {});
|
|
40
|
+
if (result.kind === "failure") return result;
|
|
41
|
+
if (!isRecord(result.data) || typeof result.data["enabled"] !== "boolean") {
|
|
42
|
+
return staticFailure(UNEXPECTED_RESPONSE_REASON);
|
|
43
|
+
}
|
|
44
|
+
return staticSuccess({ enabled: result.data["enabled"] });
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async function postAuthRoute(
|
|
48
|
+
path: string,
|
|
49
|
+
payload: Record<string, unknown>,
|
|
50
|
+
options?: StaticRequestOptions,
|
|
51
|
+
): Promise<StaticResult<undefined>> {
|
|
52
|
+
const result = await postJson(path, payload, options);
|
|
53
|
+
return result.kind === "success" ? staticSuccess(undefined) : result;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Answers success whether or not the address has an account, so it cannot be used to probe. */
|
|
57
|
+
export function requestPasswordReset(
|
|
58
|
+
email: string,
|
|
59
|
+
options: StaticRequestOptions & { readonly returnTo?: string } = {},
|
|
60
|
+
): Promise<StaticResult<undefined>> {
|
|
61
|
+
const { returnTo, ...requestOptions } = options;
|
|
62
|
+
return postAuthRoute(
|
|
63
|
+
"/api/auth/request-password-reset",
|
|
64
|
+
{ email, ...(isSafeReturnPath(returnTo) && { returnTo }) },
|
|
65
|
+
requestOptions,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function resetPassword(
|
|
70
|
+
token: string,
|
|
71
|
+
newPassword: string,
|
|
72
|
+
options?: StaticRequestOptions,
|
|
73
|
+
): Promise<StaticResult<undefined>> {
|
|
74
|
+
return postAuthRoute("/api/auth/reset-password", { token, newPassword }, options);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function verifyEmail(
|
|
78
|
+
token: string,
|
|
79
|
+
options?: StaticRequestOptions,
|
|
80
|
+
): Promise<StaticResult<undefined>> {
|
|
81
|
+
return postAuthRoute("/api/auth/verify-email", { token }, options);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Ends the current session; the server also clears the auth and CSRF cookies. */
|
|
85
|
+
export function logout(options?: StaticRequestOptions): Promise<StaticResult<undefined>> {
|
|
86
|
+
return postAuthRoute("/api/auth/logout", {}, options);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export { isSignedOutFailure } from "./static-client.ts";
|
|
90
|
+
|
|
91
|
+
export type InviteInfo = { readonly email: string; readonly hasAccount: boolean };
|
|
92
|
+
|
|
93
|
+
/** Reads the pending invitation without consuming the token. */
|
|
94
|
+
export async function fetchInviteInfo(
|
|
95
|
+
token: string,
|
|
96
|
+
options?: StaticRequestOptions,
|
|
97
|
+
): Promise<StaticResult<InviteInfo>> {
|
|
98
|
+
const result = await postJson("/api/auth/invite-info", { token }, options);
|
|
99
|
+
if (result.kind === "failure") return result;
|
|
100
|
+
const { email, hasAccount } = result.data;
|
|
101
|
+
if (typeof email !== "string" || typeof hasAccount !== "boolean") {
|
|
102
|
+
return staticFailure(UNEXPECTED_RESPONSE_REASON);
|
|
103
|
+
}
|
|
104
|
+
return staticSuccess({ email, hasAccount });
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export type InviteAccepted =
|
|
108
|
+
| {
|
|
109
|
+
readonly status: "accepted";
|
|
110
|
+
readonly tenantId: string;
|
|
111
|
+
readonly roles: readonly string[];
|
|
112
|
+
readonly landingPath?: string;
|
|
113
|
+
}
|
|
114
|
+
// The invitation is used up but no session was minted (MFA gate): send the user to login.
|
|
115
|
+
| { readonly status: "mfa-pending" };
|
|
116
|
+
|
|
117
|
+
function grantedRoles(body: Record<string, unknown>): readonly string[] {
|
|
118
|
+
const user = body["user"];
|
|
119
|
+
const sessionRoles = isRecord(user) ? user["roles"] : undefined;
|
|
120
|
+
if (Array.isArray(sessionRoles)) {
|
|
121
|
+
return sessionRoles.filter((role): role is string => typeof role === "string");
|
|
122
|
+
}
|
|
123
|
+
return typeof body["role"] === "string" ? [body["role"]] : [];
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
async function postInviteAccept(
|
|
127
|
+
path: string,
|
|
128
|
+
payload: Record<string, unknown>,
|
|
129
|
+
options?: StaticRequestOptions,
|
|
130
|
+
): Promise<StaticResult<InviteAccepted>> {
|
|
131
|
+
const result = await postJson(path, payload, options);
|
|
132
|
+
if (result.kind === "failure") return result;
|
|
133
|
+
const body = result.data;
|
|
134
|
+
const tenantId = body["tenantId"];
|
|
135
|
+
if (typeof tenantId !== "string") return staticSuccess({ status: "mfa-pending" });
|
|
136
|
+
const landingPath = body["landingPath"];
|
|
137
|
+
return staticSuccess({
|
|
138
|
+
status: "accepted",
|
|
139
|
+
tenantId,
|
|
140
|
+
roles: grantedRoles(body),
|
|
141
|
+
...(isSafeReturnPath(landingPath) && { landingPath }),
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/** Visitor is signed in on this origin: attaches the invitation to that session. */
|
|
146
|
+
export function acceptInviteSignedIn(
|
|
147
|
+
token: string,
|
|
148
|
+
options?: StaticRequestOptions,
|
|
149
|
+
): Promise<StaticResult<InviteAccepted>> {
|
|
150
|
+
return postInviteAccept("/api/auth/invite-accept", { token }, options);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Invited address already has an account: signs in and accepts. */
|
|
154
|
+
export function acceptInviteWithLogin(
|
|
155
|
+
token: string,
|
|
156
|
+
email: string,
|
|
157
|
+
password: string,
|
|
158
|
+
options?: StaticRequestOptions,
|
|
159
|
+
): Promise<StaticResult<InviteAccepted>> {
|
|
160
|
+
return postInviteAccept(
|
|
161
|
+
"/api/auth/invite-accept-with-login",
|
|
162
|
+
{ token, email, password },
|
|
163
|
+
options,
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Invited address has no account yet: creates it with `password` and accepts. */
|
|
168
|
+
export function acceptInviteWithNewAccount(
|
|
169
|
+
token: string,
|
|
170
|
+
password: string,
|
|
171
|
+
options?: StaticRequestOptions,
|
|
172
|
+
): Promise<StaticResult<InviteAccepted>> {
|
|
173
|
+
return postInviteAccept("/api/auth/invite-signup-complete", { token, password }, options);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Answers success whether or not the address exists or is locked, so it cannot be used to probe. */
|
|
177
|
+
export function requestAccountUnlock(
|
|
178
|
+
email: string,
|
|
179
|
+
options?: StaticRequestOptions,
|
|
180
|
+
): Promise<StaticResult<undefined>> {
|
|
181
|
+
return postAuthRoute("/api/auth/request-account-unlock", { email }, options);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/** The mail link carries the token in the query (`?token=`). Confirming an unlocked account is a no-op. */
|
|
185
|
+
export function confirmAccountUnlock(
|
|
186
|
+
token: string,
|
|
187
|
+
options?: StaticRequestOptions,
|
|
188
|
+
): Promise<StaticResult<undefined>> {
|
|
189
|
+
return postAuthRoute("/api/auth/confirm-account-unlock", { token }, options);
|
|
190
|
+
}
|