@cosmicdrift/kumiko-bundled-features 0.344.0 → 0.345.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/dist/audit/run-escape-hatch-retention.js +25 -12
- package/dist/auth-email-password/constants.d.ts +1 -0
- package/dist/auth-email-password/constants.js +1 -0
- package/dist/auth-email-password/feature.js +6 -2
- package/dist/auth-email-password/handlers/invite-signup-complete.write.d.ts +6 -2
- package/dist/auth-email-password/handlers/invite-signup-complete.write.js +14 -4
- package/dist/auth-email-password/handlers/signup-confirm.write.d.ts +6 -2
- package/dist/auth-email-password/handlers/signup-confirm.write.js +8 -1
- package/dist/auth-email-password/handlers/switch-tenant-mfa-gate.write.d.ts +9 -0
- package/dist/auth-email-password/handlers/switch-tenant-mfa-gate.write.js +39 -0
- package/dist/auth-email-password/handlers/token-request-handler.js +7 -1
- package/dist/auth-email-password/i18n.js +1 -0
- package/dist/auth-email-password/web/auth-client.d.ts +6 -1
- package/dist/auth-email-password/web/auth-client.js +6 -2
- package/dist/auth-email-password/web/signup-complete-screen.js +9 -1
- package/dist/step-dispatcher/feature.js +2 -1
- package/dist/step-dispatcher/webhook-runner.d.ts +2 -0
- package/dist/step-dispatcher/webhook-runner.js +7 -0
- package/package.json +9 -9
- package/src/audit/changes.json +6 -0
- package/src/auth-email-password/changes.json +24 -0
- package/src/step-dispatcher/changes.json +6 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { selectMany } from "@cosmicdrift/kumiko-framework/bun-db";
|
|
1
|
+
import { aggregateWhere, selectMany } from "@cosmicdrift/kumiko-framework/bun-db";
|
|
2
2
|
import { COMPLIANCE_PROFILES, subtractRetentionSpec, } from "@cosmicdrift/kumiko-framework/compliance";
|
|
3
3
|
import { parseTenantId, SYSTEM_TENANT_ID, } from "@cosmicdrift/kumiko-framework/engine";
|
|
4
4
|
import { eventsTable } from "@cosmicdrift/kumiko-framework/event-store";
|
|
@@ -38,10 +38,14 @@ function targetTenantOf(payload) {
|
|
|
38
38
|
const parsed = escapeHatchUsedSchema.safeParse(payload);
|
|
39
39
|
return parsed.success ? parseTenantId(parsed.data.targetTenantId) : null;
|
|
40
40
|
}
|
|
41
|
-
async function
|
|
42
|
-
const
|
|
43
|
-
|
|
41
|
+
async function storingTenantIds(db) {
|
|
42
|
+
const groups = await aggregateWhere(db, eventsTable, { measure: { fn: "count" }, groupBy: [{ field: "tenantId" }] }, { aggregateType: ESCAPE_HATCH_USE_AGGREGATE_TYPE });
|
|
43
|
+
return groups.flatMap((group) => {
|
|
44
|
+
const tenantId = parseTenantId(group.keys[0]);
|
|
45
|
+
return tenantId ? [tenantId] : [];
|
|
44
46
|
});
|
|
47
|
+
}
|
|
48
|
+
async function pruneByTenantProfiles(db) {
|
|
45
49
|
const now = getTemporal().Now.instant();
|
|
46
50
|
const cutoffByTenant = new Map();
|
|
47
51
|
const cutoffOf = async (tenantId) => {
|
|
@@ -52,15 +56,24 @@ async function pruneByTenantProfiles(db) {
|
|
|
52
56
|
cutoffByTenant.set(tenantId, cutoff);
|
|
53
57
|
return cutoff;
|
|
54
58
|
};
|
|
59
|
+
// The effective cutoff is never later than the storing tenant's, so only rows older than
|
|
60
|
+
// that one can expire; everything younger stays in the database.
|
|
55
61
|
const expiredAggregateIds = [];
|
|
56
|
-
for (const
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
: storeCutoff
|
|
62
|
-
|
|
63
|
-
|
|
62
|
+
for (const storingTenantId of await storingTenantIds(db)) {
|
|
63
|
+
const storeCutoff = await cutoffOf(storingTenantId);
|
|
64
|
+
const candidates = await selectMany(db, eventsTable, {
|
|
65
|
+
aggregateType: ESCAPE_HATCH_USE_AGGREGATE_TYPE,
|
|
66
|
+
tenantId: storingTenantId,
|
|
67
|
+
createdAt: { lt: storeCutoff },
|
|
68
|
+
});
|
|
69
|
+
for (const row of candidates) {
|
|
70
|
+
const targetTenantId = targetTenantOf(row.payload);
|
|
71
|
+
const cutoff = targetTenantId
|
|
72
|
+
? earlierInstant(storeCutoff, await cutoffOf(targetTenantId))
|
|
73
|
+
: storeCutoff;
|
|
74
|
+
if (Temporal.Instant.compare(row.createdAt, cutoff) < 0) {
|
|
75
|
+
expiredAggregateIds.push(row.aggregateId);
|
|
76
|
+
}
|
|
64
77
|
}
|
|
65
78
|
}
|
|
66
79
|
let deletedCount = 0;
|
|
@@ -17,6 +17,7 @@ export declare const AuthHandlers: {
|
|
|
17
17
|
readonly inviteAccept: "auth-email-password:write:invite-accept";
|
|
18
18
|
readonly inviteAcceptWithLogin: "auth-email-password:write:invite-accept-with-login";
|
|
19
19
|
readonly inviteSignupComplete: "auth-email-password:write:invite-signup-complete";
|
|
20
|
+
readonly switchTenantMfaGate: "auth-email-password:write:switch-tenant-mfa-gate";
|
|
20
21
|
readonly inviteCancel: "auth-email-password:write:invite-cancel";
|
|
21
22
|
};
|
|
22
23
|
export declare const AuthQueries: {
|
|
@@ -44,6 +44,7 @@ export const AuthHandlers = {
|
|
|
44
44
|
inviteAccept: "auth-email-password:write:invite-accept",
|
|
45
45
|
inviteAcceptWithLogin: "auth-email-password:write:invite-accept-with-login",
|
|
46
46
|
inviteSignupComplete: "auth-email-password:write:invite-signup-complete",
|
|
47
|
+
switchTenantMfaGate: "auth-email-password:write:switch-tenant-mfa-gate",
|
|
47
48
|
inviteCancel: "auth-email-password:write:invite-cancel",
|
|
48
49
|
};
|
|
49
50
|
// Qualified query names. Anonymous-readable status so the (unauthenticated)
|
|
@@ -17,6 +17,7 @@ import { createResetPasswordHandler } from "./handlers/reset-password.write.js";
|
|
|
17
17
|
import { selfRegistrationStatusQuery } from "./handlers/self-registration-status.query.js";
|
|
18
18
|
import { createSignupConfirmHandler } from "./handlers/signup-confirm.write.js";
|
|
19
19
|
import { createSignupRequestHandler, } from "./handlers/signup-request.write.js";
|
|
20
|
+
import { createSwitchTenantMfaGateHandler } from "./handlers/switch-tenant-mfa-gate.write.js";
|
|
20
21
|
import { createVerifyEmailHandler } from "./handlers/verify-email.write.js";
|
|
21
22
|
/**
|
|
22
23
|
* Env-vars contract for the `auth-email-password` feature.
|
|
@@ -101,6 +102,9 @@ export function createAuthEmailPasswordFeature(opts = {}) {
|
|
|
101
102
|
changePassword: r.writeHandler(changePasswordWrite),
|
|
102
103
|
logout: r.writeHandler(logoutWrite),
|
|
103
104
|
};
|
|
105
|
+
if (opts.mfaStatusChecker) {
|
|
106
|
+
r.writeHandler(createSwitchTenantMfaGateHandler({ mfaStatusChecker: opts.mfaStatusChecker }));
|
|
107
|
+
}
|
|
104
108
|
if (opts.passwordReset) {
|
|
105
109
|
r.writeHandler(createRequestPasswordResetHandler(opts.passwordReset));
|
|
106
110
|
r.writeHandler(createResetPasswordHandler(opts.passwordReset));
|
|
@@ -119,7 +123,7 @@ export function createAuthEmailPasswordFeature(opts = {}) {
|
|
|
119
123
|
};
|
|
120
124
|
if (opts.signup) {
|
|
121
125
|
r.writeHandler(createSignupRequestHandler(opts.signup));
|
|
122
|
-
r.writeHandler(createSignupConfirmHandler());
|
|
126
|
+
r.writeHandler(createSignupConfirmHandler({ mfaStatusChecker: opts.mfaStatusChecker }));
|
|
123
127
|
}
|
|
124
128
|
if (opts.invite) {
|
|
125
129
|
r.writeHandler(createInviteCreateHandler(opts.invite));
|
|
@@ -132,7 +136,7 @@ export function createAuthEmailPasswordFeature(opts = {}) {
|
|
|
132
136
|
accountLockout: opts.accountLockout,
|
|
133
137
|
strictEmailVerification: strictVerification,
|
|
134
138
|
}));
|
|
135
|
-
r.writeHandler(createInviteSignupCompleteHandler());
|
|
139
|
+
r.writeHandler(createInviteSignupCompleteHandler({ mfaStatusChecker: opts.mfaStatusChecker }));
|
|
136
140
|
}
|
|
137
141
|
if (opts.accountUnlock) {
|
|
138
142
|
r.writeHandler(createRequestAccountUnlockHandler(opts.accountUnlock));
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { type SessionUser, type TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
+
import { type LoginHandlerOptions, type LoginResult } from "./login.write.js";
|
|
3
4
|
export type InviteSignupCompleteData = {
|
|
4
5
|
readonly kind: "auth-session";
|
|
5
6
|
readonly session: SessionUser;
|
|
6
7
|
readonly tenantId: TenantId;
|
|
7
8
|
readonly role: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
9
|
+
} | Exclude<LoginResult, {
|
|
10
|
+
readonly kind: "auth-session";
|
|
11
|
+
}>;
|
|
12
|
+
export type InviteSignupCompleteOptions = Pick<LoginHandlerOptions, "mfaStatusChecker">;
|
|
13
|
+
export declare function createInviteSignupCompleteHandler(opts?: InviteSignupCompleteOptions): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"invite-signup-complete", z.ZodObject<{
|
|
10
14
|
token: z.ZodString;
|
|
11
15
|
password: z.ZodString;
|
|
12
16
|
}, z.core.$strip>, InviteSignupCompleteData, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;
|
|
@@ -37,13 +37,14 @@ import { burnInviteToken, deleteInviteToken, getInvitationIdForToken, unburnInvi
|
|
|
37
37
|
import { passwordSchema } from "../password-policy.js";
|
|
38
38
|
// kumiko-lint-ignore cross-feature-import provisioning needs cross-feature seeding helpers
|
|
39
39
|
import { seedUserWithPassword } from "../seeding.js";
|
|
40
|
+
import { gateEnforceMfa } from "./login.write.js";
|
|
40
41
|
const InviteSignupCompleteSchema = z.object({
|
|
41
42
|
token: z.string().min(1),
|
|
42
43
|
password: passwordSchema,
|
|
43
44
|
});
|
|
44
45
|
const invitationExecutor = createEventStoreExecutor(tenantInvitationsTable, tenantInvitationEntity, { entityName: "tenant-invitation" });
|
|
45
46
|
const INVITE_SIGNUP_COMPLETE_ESCAPE_HATCH_REASON = "reads the pending invitation by id; the invitee is not yet a member of the invitation's tenant. Creates the user and adds the membership and accepts the invitation in the invitation's tenant, before any caller tenant context exists.";
|
|
46
|
-
export function createInviteSignupCompleteHandler() {
|
|
47
|
+
export function createInviteSignupCompleteHandler(opts = {}) {
|
|
47
48
|
return defineWriteHandler({
|
|
48
49
|
name: "invite-signup-complete",
|
|
49
50
|
schema: InviteSignupCompleteSchema,
|
|
@@ -119,13 +120,22 @@ export function createInviteSignupCompleteHandler() {
|
|
|
119
120
|
}, createSystemUser(invitationTenantId), invitationTdb);
|
|
120
121
|
if (!updateResult.isSuccess)
|
|
121
122
|
return updateResult;
|
|
123
|
+
// buildSessionRoles calls stripForbiddenMembershipRoles internally —
|
|
124
|
+
// a reserved role on the invitation itself must never reach the session.
|
|
125
|
+
const mergedRoles = buildSessionRoles(invitationGlobalRoles, [invitationRole]);
|
|
126
|
+
// Same gate as invite-accept-with-login: the account exists after this
|
|
127
|
+
// call, but an MFA-gated role gets the MFA step instead of a session.
|
|
128
|
+
// It runs before the token is deleted so a throwing check leaves the link retryable.
|
|
129
|
+
const mfaGate = await gateEnforceMfa(ctx, { mfaStatusChecker: opts.mfaStatusChecker }, userId, invitationTenantId, mergedRoles);
|
|
122
130
|
await deleteInviteToken(ctx.redis, { invitationId, token: event.payload.token });
|
|
131
|
+
if (mfaGate !== undefined) {
|
|
132
|
+
committed = true;
|
|
133
|
+
return { isSuccess: true, data: mfaGate };
|
|
134
|
+
}
|
|
123
135
|
const session = {
|
|
124
136
|
id: userId,
|
|
125
137
|
tenantId: invitationTenantId,
|
|
126
|
-
|
|
127
|
-
// a reserved role on the invitation itself must never reach the session.
|
|
128
|
-
roles: buildSessionRoles(invitationGlobalRoles, [invitationRole]),
|
|
138
|
+
roles: mergedRoles,
|
|
129
139
|
};
|
|
130
140
|
committed = true;
|
|
131
141
|
return {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { type SessionUser } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import * as z from "zod";
|
|
3
|
+
import { type LoginHandlerOptions, type LoginResult } from "./login.write.js";
|
|
3
4
|
export type SignupConfirmData = {
|
|
4
5
|
readonly kind: "auth-session";
|
|
5
6
|
readonly session: SessionUser;
|
|
@@ -8,8 +9,11 @@ export type SignupConfirmData = {
|
|
|
8
9
|
readonly entityType: string;
|
|
9
10
|
readonly id: string;
|
|
10
11
|
};
|
|
11
|
-
}
|
|
12
|
-
|
|
12
|
+
} | Exclude<LoginResult, {
|
|
13
|
+
readonly kind: "auth-session";
|
|
14
|
+
}>;
|
|
15
|
+
export type SignupConfirmOptions = Pick<LoginHandlerOptions, "mfaStatusChecker">;
|
|
16
|
+
export declare function createSignupConfirmHandler(opts?: SignupConfirmOptions): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"signup-confirm", z.ZodObject<{
|
|
13
17
|
token: z.ZodString;
|
|
14
18
|
password: z.ZodString;
|
|
15
19
|
}, z.core.$strip>, SignupConfirmData, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;
|
|
@@ -32,6 +32,7 @@ import { passwordSchema } from "../password-policy.js";
|
|
|
32
32
|
// kumiko-lint-ignore cross-feature-import provisioning needs cross-feature seeding helpers
|
|
33
33
|
import { INITIAL_SIGNUP_ROLES, provisionSignupAccount } from "../seeding.js";
|
|
34
34
|
import { burnSignupToken, deleteSignupHandover, deleteSignupToken, getEmailForSignupToken, getSignupHandover, unburnSignupToken, } from "../signup-token-store.js";
|
|
35
|
+
import { gateEnforceMfa } from "./login.write.js";
|
|
35
36
|
const SignupConfirmSchema = z.object({
|
|
36
37
|
token: z.string().min(8),
|
|
37
38
|
password: passwordSchema,
|
|
@@ -70,7 +71,7 @@ async function claimBoundHandover(ctx, session, binding) {
|
|
|
70
71
|
});
|
|
71
72
|
return undefined;
|
|
72
73
|
}
|
|
73
|
-
export function createSignupConfirmHandler() {
|
|
74
|
+
export function createSignupConfirmHandler(opts = {}) {
|
|
74
75
|
return defineWriteHandler({
|
|
75
76
|
name: "signup-confirm",
|
|
76
77
|
schema: SignupConfirmSchema,
|
|
@@ -158,11 +159,17 @@ export function createSignupConfirmHandler() {
|
|
|
158
159
|
const handover = handoverBinding
|
|
159
160
|
? await claimBoundHandover(ctx, session, handoverBinding)
|
|
160
161
|
: undefined;
|
|
162
|
+
// Before the token keys go: a throwing MFA check must leave the link retryable.
|
|
163
|
+
const mfaGate = await gateEnforceMfa(ctx, { mfaStatusChecker: opts.mfaStatusChecker }, provisioned.userId, provisioned.tenantId, session.roles);
|
|
161
164
|
// Drop both token lookup keys; the burn key stays for its remaining
|
|
162
165
|
// TTL as replay protection.
|
|
163
166
|
await deleteSignupToken(ctx.redis, { email, token: event.payload.token });
|
|
164
167
|
if (handoverBinding)
|
|
165
168
|
await deleteSignupHandover(ctx.redis, event.payload.token);
|
|
169
|
+
if (mfaGate !== undefined) {
|
|
170
|
+
committed = true;
|
|
171
|
+
return { isSuccess: true, data: mfaGate };
|
|
172
|
+
}
|
|
166
173
|
committed = true;
|
|
167
174
|
return {
|
|
168
175
|
isSuccess: true,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { gateEnforceMfa, type LoginHandlerOptions } from "./login.write.js";
|
|
3
|
+
export type SwitchTenantMfaGateData = {
|
|
4
|
+
readonly kind: "mfa-gate-clear";
|
|
5
|
+
} | NonNullable<Awaited<ReturnType<typeof gateEnforceMfa>>>;
|
|
6
|
+
export declare function createSwitchTenantMfaGateHandler(opts: Pick<LoginHandlerOptions, "mfaStatusChecker">): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"switch-tenant-mfa-gate", z.ZodObject<{
|
|
7
|
+
userId: z.ZodString;
|
|
8
|
+
tenantId: z.ZodPipe<z.ZodString, z.ZodTransform<string, string>>;
|
|
9
|
+
}, z.core.$strip>, SwitchTenantMfaGateData, import("@cosmicdrift/kumiko-types/event-type-map").KumikoEventTypeMap>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { buildSessionRoles, createSystemUser, defineWriteHandler, SYSTEM_ROLE, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { parseRoles } from "@cosmicdrift/kumiko-framework/utils";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
import { UserQueries } from "../../user/index.js";
|
|
5
|
+
import { parseAuthUserRow } from "../auth-user-row.js";
|
|
6
|
+
import { noMembership } from "../errors.js";
|
|
7
|
+
import { gateEnforceMfa } from "./login.write.js";
|
|
8
|
+
const SwitchTenantMfaGateSchema = z.object({
|
|
9
|
+
userId: z.string().min(1),
|
|
10
|
+
tenantId: z
|
|
11
|
+
.string()
|
|
12
|
+
.min(1)
|
|
13
|
+
.transform((id) => id),
|
|
14
|
+
});
|
|
15
|
+
// Dispatched by POST /auth/switch-tenant with the system identity. The handler
|
|
16
|
+
// resolves membership and roles itself, so the gate never trusts caller-supplied
|
|
17
|
+
// roles; system-only access keeps it out of reach of /api/write callers.
|
|
18
|
+
export function createSwitchTenantMfaGateHandler(opts) {
|
|
19
|
+
return defineWriteHandler({
|
|
20
|
+
name: "switch-tenant-mfa-gate",
|
|
21
|
+
schema: SwitchTenantMfaGateSchema,
|
|
22
|
+
access: { roles: [SYSTEM_ROLE] },
|
|
23
|
+
escapeHatch: {
|
|
24
|
+
reason: "reads the MFA enrollment of the switch target tenant, not the caller's current tenant, via the mfaStatusChecker callback (it uses ctx.db.unsafeRaw())",
|
|
25
|
+
},
|
|
26
|
+
agent: { expose: false },
|
|
27
|
+
description: "Runs the MFA gate of the login for a tenant switch and answers with an MFA challenge, a setup requirement, or clearance.",
|
|
28
|
+
handler: async (event, ctx) => {
|
|
29
|
+
const { userId, tenantId } = event.payload;
|
|
30
|
+
const active = await ctx.resolveActiveMembership(userId, tenantId);
|
|
31
|
+
if (active.kind === "rejected")
|
|
32
|
+
return noMembership();
|
|
33
|
+
const userRow = parseAuthUserRow(await ctx.queryAs(createSystemUser(tenantId), UserQueries.findForAuth, { id: userId }));
|
|
34
|
+
const roles = buildSessionRoles(parseRoles(userRow?.roles ?? null), active.membership.roles);
|
|
35
|
+
const mfaGate = await gateEnforceMfa(ctx, opts, userId, tenantId, roles);
|
|
36
|
+
return { isSuccess: true, data: mfaGate ?? { kind: "mfa-gate-clear" } };
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
// spec rather than duplicated across two near-identical handler bodies.
|
|
14
14
|
import { createSystemUser, defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
15
15
|
import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
16
|
+
import { isValidIanaTimeZone } from "@cosmicdrift/kumiko-framework/time";
|
|
16
17
|
import * as z from "zod";
|
|
17
18
|
import { UserQueries } from "../../user/index.js";
|
|
18
19
|
import { parseAuthUserRow } from "../auth-user-row.js";
|
|
@@ -20,6 +21,11 @@ import { dispatchMagicLinkMail, resolveHandlerMailLocale } from "../magic-link-m
|
|
|
20
21
|
const RequestTokenSchema = z.object({
|
|
21
22
|
email: z.email(),
|
|
22
23
|
});
|
|
24
|
+
// The requester is anonymous, so ctx.tz.user is only the tenant default; the recipient's
|
|
25
|
+
// own profile zone is the one the expiry should be read in.
|
|
26
|
+
function recipientTimeZone(user, fallbackTimeZone) {
|
|
27
|
+
return user.timezone && isValidIanaTimeZone(user.timezone) ? user.timezone : fallbackTimeZone;
|
|
28
|
+
}
|
|
23
29
|
export function createTokenRequestHandler(spec, opts) {
|
|
24
30
|
const ttl = opts.tokenTtlMinutes ?? spec.defaultTtlMinutes;
|
|
25
31
|
return defineWriteHandler({
|
|
@@ -69,7 +75,7 @@ export function createTokenRequestHandler(spec, opts) {
|
|
|
69
75
|
token,
|
|
70
76
|
expiresAt: expiresAt.toString(),
|
|
71
77
|
issuedAt,
|
|
72
|
-
timeZone: ctx.tz.user,
|
|
78
|
+
timeZone: recipientTimeZone(user, ctx.tz.user),
|
|
73
79
|
...(opts.appName !== undefined && { appName: opts.appName }),
|
|
74
80
|
locale,
|
|
75
81
|
});
|
|
@@ -99,6 +99,7 @@ export const defaultTranslations = {
|
|
|
99
99
|
"auth.signupComplete.submit": "Activate account",
|
|
100
100
|
"auth.signupComplete.submitting": "…",
|
|
101
101
|
"auth.signupComplete.missingToken": "Activation link is missing a token. Please request a new one.",
|
|
102
|
+
"auth.signupComplete.activatedMfaPending": "Your account is active. Sign in to set up two-factor authentication.",
|
|
102
103
|
"auth.signupComplete.activatedTitle": "Account activated",
|
|
103
104
|
"auth.signupComplete.activated": "Your account is active and you're signed in.",
|
|
104
105
|
"auth.signupComplete.continue": "Continue",
|
|
@@ -112,9 +112,14 @@ export type SignupConfirmSuccess = {
|
|
|
112
112
|
};
|
|
113
113
|
readonly landingPath?: string;
|
|
114
114
|
};
|
|
115
|
+
export type SignupConfirmResult = ({
|
|
116
|
+
readonly kind: "signed-in";
|
|
117
|
+
} & SignupConfirmSuccess) | {
|
|
118
|
+
readonly kind: "mfa-pending";
|
|
119
|
+
};
|
|
115
120
|
export declare function confirmSignup(token: string, password: string): Promise<{
|
|
116
121
|
ok: true;
|
|
117
|
-
data:
|
|
122
|
+
data: SignupConfirmResult;
|
|
118
123
|
} | {
|
|
119
124
|
ok: false;
|
|
120
125
|
error: AuthTokenFailure;
|
|
@@ -229,8 +229,12 @@ export async function confirmSignup(token, password) {
|
|
|
229
229
|
body: JSON.stringify({ token, password }),
|
|
230
230
|
});
|
|
231
231
|
if (res.ok) {
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
// @cast-boundary engine-payload
|
|
233
|
+
const body = (await res.json());
|
|
234
|
+
if (body.mfaRequired === true || body.mfaSetupRequired === true) {
|
|
235
|
+
return { ok: true, data: { kind: "mfa-pending" } };
|
|
236
|
+
}
|
|
237
|
+
return { ok: true, data: { kind: "signed-in", ...body } };
|
|
234
238
|
}
|
|
235
239
|
return { ok: false, error: await parseTokenFailure(res) };
|
|
236
240
|
}
|
|
@@ -31,6 +31,7 @@ export function SignupCompleteScreen({ title, token: tokenProp, loggedInHref = "
|
|
|
31
31
|
const [submitting, setSubmitting] = useState(false);
|
|
32
32
|
const [error, setError] = useState(null);
|
|
33
33
|
const [continueHref, setContinueHref] = useState(null);
|
|
34
|
+
const [mfaPending, setMfaPending] = useState(false);
|
|
34
35
|
const doSubmit = async () => {
|
|
35
36
|
setError(null);
|
|
36
37
|
const issue = passwordPairIssue(password, confirmPassword);
|
|
@@ -46,6 +47,11 @@ export function SignupCompleteScreen({ title, token: tokenProp, loggedInHref = "
|
|
|
46
47
|
const res = await confirmSignup(token, password);
|
|
47
48
|
setSubmitting(false);
|
|
48
49
|
if (res.ok) {
|
|
50
|
+
if (res.data.kind === "mfa-pending") {
|
|
51
|
+
setMfaPending(true);
|
|
52
|
+
setContinueHref(loginHref);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
49
55
|
// Cookies are already set (auto-login). Show a confirmation with an
|
|
50
56
|
// explicit continue button instead of navigating away silently —
|
|
51
57
|
// the user otherwise gets no signal that activation worked.
|
|
@@ -80,7 +86,9 @@ export function SignupCompleteScreen({ title, token: tokenProp, loggedInHref = "
|
|
|
80
86
|
return (_jsxs(AuthCard, { title: effectiveTitle, children: [_jsx("p", { className: "text-sm text-muted-foreground", children: t("auth.signupComplete.missingToken") }), _jsx(Link, { href: loginHref, variant: "muted", children: t("auth.signup.haveAccount") })] }));
|
|
81
87
|
}
|
|
82
88
|
if (continueHref !== null) {
|
|
83
|
-
return (_jsxs(AuthCard, { title: effectiveTitle, children: [_jsx("p", { className: "text-sm text-muted-foreground", role: "status", children: t(
|
|
89
|
+
return (_jsxs(AuthCard, { title: effectiveTitle, children: [_jsx("p", { className: "text-sm text-muted-foreground", role: "status", children: t(mfaPending
|
|
90
|
+
? "auth.signupComplete.activatedMfaPending"
|
|
91
|
+
: "auth.signupComplete.activated") }), _jsx(Link, { href: continueHref, variant: "button", children: t("auth.signupComplete.continue") })] }));
|
|
84
92
|
}
|
|
85
93
|
return (_jsxs(AuthCard, { title: effectiveTitle, children: [_jsx("p", { className: "text-sm text-muted-foreground", children: t("auth.signupComplete.intro") }), _jsxs(Form, { onSubmit: onSubmit, children: [_jsx(Field, { id: "signup-password", label: t("auth.signupComplete.password"), required: true, children: _jsx(Input, { kind: "password", id: "signup-password", name: "signup-password", value: password, onChange: setPassword, disabled: submitting, required: true, autoComplete: "new-password" }) }), _jsx(Field, { id: "signup-confirm-password", label: t("auth.signupComplete.confirmPassword"), required: true, children: _jsx(Input, { kind: "password", id: "signup-confirm-password", name: "signup-confirm-password", value: confirmPassword, onChange: setConfirmPassword, disabled: submitting, required: true, autoComplete: "new-password" }) }), error !== null && _jsx(Banner, { variant: "error", children: error }), _jsx(Button, { type: "submit", loading: submitting, disabled: submitting, children: submitting ? t("auth.signupComplete.submitting") : t("auth.signupComplete.submit") })] })] }));
|
|
86
94
|
}
|
|
@@ -144,7 +144,7 @@ function buildDispatchSpec(payload, fields) {
|
|
|
144
144
|
}
|
|
145
145
|
export function createStepDispatcherFeature() {
|
|
146
146
|
return defineFeature("step-dispatcher", (r) => {
|
|
147
|
-
r.describe("Internal system feature that drains deferred Tier-2 side-effects (currently `webhook.send` and `mail.send`) after their originating transaction commits. Listens via `r.multiStreamProjection` on the `kumiko:system:step.dispatch-requested` system event, performs the actual HTTP or mail delivery, then appends `kumiko:system:step.dispatched` or `kumiko:system:step.dispatch-failed` back onto the same stream so the outcome is recorded in the event log without a separate status table. Mount this feature explicitly via `createStepDispatcherFeature()` in your app's feature list alongside any features that use `r.step.webhook.send` or `r.step.mail.send`. Requires the `secrets` feature (`createSecretsFeature()`) to be mounted — `webhook.send` auth resolves per-tenant through it, under `step-dispatcher:webhook-auth.<name>`.");
|
|
147
|
+
r.describe("Internal system feature that drains deferred Tier-2 side-effects (currently `webhook.send` and `mail.send`) after their originating transaction commits. Listens via `r.multiStreamProjection` on the `kumiko:system:step.dispatch-requested` system event, performs the actual HTTP or mail delivery, then appends `kumiko:system:step.dispatched` or `kumiko:system:step.dispatch-failed` back onto the same stream so the outcome is recorded in the event log without a separate status table. Mount this feature explicitly via `createStepDispatcherFeature()` in your app's feature list alongside any features that use `r.step.webhook.send` or `r.step.mail.send`. Requires the `secrets` feature (`createSecretsFeature()`) to be mounted — `webhook.send` auth resolves per-tenant through it, under `step-dispatcher:webhook-auth.<name>`. Every `webhook.send` request carries `Idempotency-Key: <dispatch stream id>`, stable across redeliveries of the same dispatch request; an explicit `Idempotency-Key` in `headers` takes precedence.");
|
|
148
148
|
r.secretNamespace("webhook-auth", WEBHOOK_AUTH_SECRET_NAMESPACE_OPTIONS);
|
|
149
149
|
r.uiHints({
|
|
150
150
|
displayLabel: "Step Dispatcher · Deferred Side-Effects",
|
|
@@ -206,6 +206,7 @@ export function createStepDispatcherFeature() {
|
|
|
206
206
|
tenantId: event.tenantId,
|
|
207
207
|
userId: event.metadata.userId || SYSTEM_USER_ID,
|
|
208
208
|
secrets: ctx.secrets,
|
|
209
|
+
idempotencyKey: event.aggregateId,
|
|
209
210
|
})
|
|
210
211
|
: await performMailDispatch(dispatchSpec.spec);
|
|
211
212
|
if (result.ok) {
|
|
@@ -45,5 +45,7 @@ export type WebhookDispatchDeps = {
|
|
|
45
45
|
readonly tenantId: TenantId;
|
|
46
46
|
readonly userId: string;
|
|
47
47
|
readonly secrets: SecretsContext | undefined;
|
|
48
|
+
readonly idempotencyKey: string;
|
|
48
49
|
};
|
|
50
|
+
export declare const WEBHOOK_IDEMPOTENCY_KEY_HEADER = "idempotency-key";
|
|
49
51
|
export declare function performWebhookDispatch(spec: WebhookSpec, deps: WebhookDispatchDeps): Promise<WebhookDispatchResult>;
|
|
@@ -83,8 +83,15 @@ export function setWebhookFetch(fn) {
|
|
|
83
83
|
// tenant-chosen name, but the error still reaches the tenant via the
|
|
84
84
|
// dispatch-failed event, so it stays generic.
|
|
85
85
|
const WEBHOOK_AUTH_SECRET_UNAVAILABLE_ERROR = "webhook auth secret is not available";
|
|
86
|
+
export const WEBHOOK_IDEMPOTENCY_KEY_HEADER = "idempotency-key";
|
|
87
|
+
function hasIdempotencyKeyHeader(headers) {
|
|
88
|
+
return Object.keys(headers).some((name) => name.toLowerCase() === WEBHOOK_IDEMPOTENCY_KEY_HEADER);
|
|
89
|
+
}
|
|
86
90
|
async function buildWebhookHeaders(spec, deps) {
|
|
87
91
|
const headers = { "content-type": "application/json", ...spec.headers };
|
|
92
|
+
if (!hasIdempotencyKeyHeader(headers)) {
|
|
93
|
+
headers[WEBHOOK_IDEMPOTENCY_KEY_HEADER] = deps.idempotencyKey;
|
|
94
|
+
}
|
|
88
95
|
if (!spec.auth)
|
|
89
96
|
return { ok: true, headers };
|
|
90
97
|
if (!deps.secrets)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-bundled-features",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.345.0",
|
|
4
4
|
"description": "Built-in features — tenant, user, auth, delivery. The stuff you'd rewrite anyway, already typed.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -503,12 +503,12 @@
|
|
|
503
503
|
}
|
|
504
504
|
},
|
|
505
505
|
"dependencies": {
|
|
506
|
-
"@cosmicdrift/kumiko-dispatcher-live": "0.
|
|
507
|
-
"@cosmicdrift/kumiko-framework": "0.
|
|
508
|
-
"@cosmicdrift/kumiko-headless": "0.
|
|
509
|
-
"@cosmicdrift/kumiko-renderer": "0.
|
|
510
|
-
"@cosmicdrift/kumiko-renderer-web": "0.
|
|
511
|
-
"@cosmicdrift/kumiko-types": "0.
|
|
506
|
+
"@cosmicdrift/kumiko-dispatcher-live": "0.345.0",
|
|
507
|
+
"@cosmicdrift/kumiko-framework": "0.345.0",
|
|
508
|
+
"@cosmicdrift/kumiko-headless": "0.345.0",
|
|
509
|
+
"@cosmicdrift/kumiko-renderer": "0.345.0",
|
|
510
|
+
"@cosmicdrift/kumiko-renderer-web": "0.345.0",
|
|
511
|
+
"@cosmicdrift/kumiko-types": "0.345.0",
|
|
512
512
|
"@mollie/api-client": "^4.5.0",
|
|
513
513
|
"@node-rs/argon2": "^2.0.2",
|
|
514
514
|
"@types/mailparser": "^3.4.6",
|
|
@@ -1025,8 +1025,8 @@
|
|
|
1025
1025
|
],
|
|
1026
1026
|
"devDependencies": {
|
|
1027
1027
|
"@testing-library/user-event": "^14.6.1",
|
|
1028
|
-
"@cosmicdrift/kumiko-locale-de": "0.
|
|
1029
|
-
"@cosmicdrift/kumiko-locale-es": "0.
|
|
1028
|
+
"@cosmicdrift/kumiko-locale-de": "0.345.0",
|
|
1029
|
+
"@cosmicdrift/kumiko-locale-es": "0.345.0",
|
|
1030
1030
|
"jsqr": "^1.4.0"
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
package/src/audit/changes.json
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.345.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Escape-hatch retention loads only expirable rows",
|
|
6
|
+
"detail": "Escape-hatch audit retention loads only rows that can expire\nThe retention job used to load every escapeHatchUse event to decide which ones to prune. It now reads the storing tenants with one grouped query and loads only events older than each storing tenant's cutoff. The same rows are pruned as before."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.343.0",
|
|
4
10
|
"type": "improvement",
|
|
@@ -1,4 +1,28 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.345.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "invite-signup-complete enforces the MFA gate before issuing a session",
|
|
6
|
+
"detail": "`invite-signup-complete` now applies the same MFA gate as `invite-accept-with-login`. The account is still created and the invitation accepted, but an invitee whose role requires MFA (for example an admin invitation under the `admins` policy) receives the MFA step instead of a session. Member invitations keep receiving a session directly."
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"version": "0.345.0",
|
|
10
|
+
"type": "fix",
|
|
11
|
+
"title": "signup-confirm enforces the MFA gate before issuing a session",
|
|
12
|
+
"detail": "`POST /auth/signup-confirm` now runs the login's MFA gate before it issues the first session. Self-signup makes the new user TenantAdmin of a fresh tenant, so under an MFA policy that covers admins the route used to hand out an admin session without a second factor. The account, the tenant and a bound handover claim are still created, but when the gate applies the route answers with the login contract (`mfaSetupRequired` plus `preauthSetupToken`, or `mfaRequired` plus `challengeToken`) and sets no cookies. `SignupCompleteScreen` then tells the user the account is active and sends them to sign in, where they set up the second factor. Without `mfaStatusChecker` nothing changes. Two exported types change shape: `SignupConfirmData` gains the two MFA variants, and `confirmSignup` now resolves to `SignupConfirmResult` with `kind: \"signed-in\"` (the previous `SignupConfirmSuccess` fields) or `kind: \"mfa-pending\"`. The handler and `invite-signup-complete` also run the gate before they delete the token, so an error in the MFA check leaves the link usable for a retry."
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"version": "0.345.0",
|
|
16
|
+
"type": "fix",
|
|
17
|
+
"title": "switch-tenant enforces the MFA gate before issuing a session",
|
|
18
|
+
"detail": "`POST /auth/switch-tenant` now runs the same MFA gate as login before it issues the new session. A user who is a plain member in one tenant and an admin in another can no longer reach an admin session without a second factor by switching. When the target tenant requires MFA the route answers with the login contract (`mfaRequired` plus `challengeToken`, or `mfaSetupRequired` plus `preauthSetupToken`) and sets no cookies. The gate runs in a new system-only handler, `auth-email-password:write:switch-tenant-mfa-gate`, which resolves the membership and roles itself; `runDevApp` and `runProdApp` wire it as `switchTenantMfaGateHandler` whenever auth-mfa is mounted."
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"version": "0.345.0",
|
|
22
|
+
"type": "fix",
|
|
23
|
+
"title": "Token mail expiry uses the recipient's profile time zone",
|
|
24
|
+
"detail": "Token mails show the expiry in the recipient's own time zone\nPassword reset, email verification and account unlock are requested anonymously, so `ctx.tz.user` only held the tenant default or UTC. These mails now use the recipient's profile time zone when it is a valid IANA zone and fall back to the previous value otherwise. Signup and invite mails keep the fallback because the recipient has no profile yet."
|
|
25
|
+
},
|
|
2
26
|
{
|
|
3
27
|
"version": "0.343.0",
|
|
4
28
|
"type": "improvement",
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.345.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Webhook sends carry an Idempotency-Key header that is stable across redeliveries",
|
|
6
|
+
"detail": "Webhook sends carry an Idempotency-Key header\nEvery `r.step.webhook.send` request now has `Idempotency-Key: <dispatch stream id>`. The value stays the same when the same dispatch request is delivered again, so receivers can deduplicate. An explicit `Idempotency-Key` in `headers` (any casing) takes precedence."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.335.0",
|
|
4
10
|
"type": "fix",
|