@cosmicdrift/kumiko-bundled-features 0.424.0 → 0.424.1
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/auth-email-password/handlers/login.write.d.ts +10 -1
- package/dist/auth-email-password/handlers/login.write.js +29 -0
- package/dist/auth-email-password/index.d.ts +1 -0
- package/dist/auth-email-password/index.js +1 -0
- package/dist/channel-push/push-channel.d.ts +2 -6
- package/package.json +11 -11
- package/src/channel-push/changes.json +8 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { HandlerContext } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
-
import { type SessionUser, type TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { type SessionUser, type TenantId, type WriteResult } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import type { WriteFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
import { type AuthUserRow } from "../auth-user-row.ts";
|
|
@@ -72,6 +72,15 @@ export declare function gateBuildSession(ctx: HandlerContext, userId: string, te
|
|
|
72
72
|
readonly kind: "auth-session";
|
|
73
73
|
readonly session: SessionUser;
|
|
74
74
|
}>;
|
|
75
|
+
export type VerifiedUserLookup = {
|
|
76
|
+
readonly email: string;
|
|
77
|
+
} | {
|
|
78
|
+
readonly userId: string;
|
|
79
|
+
};
|
|
80
|
+
export declare function sessionForVerifiedUser(ctx: HandlerContext, lookup: VerifiedUserLookup): Promise<WriteResult<{
|
|
81
|
+
readonly kind: "auth-session";
|
|
82
|
+
readonly session: SessionUser;
|
|
83
|
+
}>>;
|
|
75
84
|
export declare function createLoginHandler(opts?: LoginHandlerOptions): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"login", z.ZodObject<{
|
|
76
85
|
email: z.ZodEmail;
|
|
77
86
|
password: z.ZodString;
|
|
@@ -8,6 +8,7 @@ import { accountLocked, accountRestricted, emailNotVerified, invalidCredentials,
|
|
|
8
8
|
import { clearLockoutState, getLockoutState, recordFailedAttempt } from "../lockout-store.js";
|
|
9
9
|
import { AUTH_LOCKOUT_DEFAULT_DURATION_MINUTES, AUTH_LOCKOUT_DEFAULT_MAX_FAILED_ATTEMPTS, } from "../web/constants.js";
|
|
10
10
|
const SYSTEM_USER_ID = "00000000-0000-4000-8000-000000000000";
|
|
11
|
+
const MembershipList = z.array(z.object({ tenantId: z.string(), roles: z.array(z.string()) }));
|
|
11
12
|
function reject(result) {
|
|
12
13
|
return { ok: false, result };
|
|
13
14
|
}
|
|
@@ -153,6 +154,34 @@ export async function gateBuildSession(ctx, userId, tenantId, mergedRoles, timez
|
|
|
153
154
|
const session = Object.keys(claims).length > 0 ? { ...baseSession, claims } : baseSession;
|
|
154
155
|
return { kind: "auth-session", session };
|
|
155
156
|
}
|
|
157
|
+
// Login gate chain AFTER an app-defined method (ID token, email code) proved
|
|
158
|
+
// the identity: account status, membership choice, claims. No password or
|
|
159
|
+
// lockout gate. A lookup by email requires a verified address,
|
|
160
|
+
// otherwise an attacker who pre-registered the victim's email with a known
|
|
161
|
+
// password would share the account the victim later reaches via this method.
|
|
162
|
+
// A lookup by userId trusts that the app linked the identity itself. There is
|
|
163
|
+
// no MFA gate: boot refuses to combine auth-mfa with sessionExchangeHandlers.
|
|
164
|
+
export async function sessionForVerifiedUser(ctx, lookup) {
|
|
165
|
+
const systemUser = createSystemUser(SYSTEM_USER_ID);
|
|
166
|
+
const found = parseAuthUserRow(await ctx.dispatch.queryAs(systemUser, UserQueries.findForAuth, "email" in lookup ? { email: lookup.email } : { id: lookup.userId }));
|
|
167
|
+
if (!found || found.isDeleted)
|
|
168
|
+
return invalidCredentials();
|
|
169
|
+
if ("email" in lookup) {
|
|
170
|
+
const emailGate = gateEnforceEmailVerified(found, true);
|
|
171
|
+
if (!emailGate.ok)
|
|
172
|
+
return emailGate.result;
|
|
173
|
+
}
|
|
174
|
+
const statusGate = gateEnforceAccountStatus(found);
|
|
175
|
+
if (!statusGate.ok)
|
|
176
|
+
return statusGate.result;
|
|
177
|
+
const memberships = MembershipList.parse(await ctx.dispatch.queryAs(systemUser, TENANT_MEMBERSHIPS_QUERY, { userId: found.id }));
|
|
178
|
+
const membershipGate = await gateResolveMembership(ctx, found, memberships);
|
|
179
|
+
if (!membershipGate.ok)
|
|
180
|
+
return membershipGate.result;
|
|
181
|
+
const { chosen, mergedRoles } = membershipGate.value;
|
|
182
|
+
const session = await gateBuildSession(ctx, found.id, chosen.tenantId, mergedRoles, found.timezone, found.locale);
|
|
183
|
+
return { isSuccess: true, data: session };
|
|
184
|
+
}
|
|
156
185
|
// Login — unauthenticated entry point. The route is wired public (no JWT
|
|
157
186
|
// middleware), dispatching with the framework's anonymous identity for the
|
|
158
187
|
// handler's access check. Everything inside the handler goes through
|
|
@@ -5,6 +5,7 @@ export { BootstrapPlanError, BootstrapWriteError, bootstrapTenants } from "./boo
|
|
|
5
5
|
export type { AuthMailLocale } from "./email-templates.ts";
|
|
6
6
|
export type { AccountLockoutOptions, AccountUnlockOptions, AuthEmailPasswordOptions, EmailVerificationOptions, InviteOptions, PasswordResetOptions, SignupOptions, } from "./feature.ts";
|
|
7
7
|
export { authEmailPasswordEnvSchema, createAuthEmailPasswordFeature } from "./feature.ts";
|
|
8
|
+
export { sessionForVerifiedUser, type VerifiedUserLookup, } from "./handlers/login.write.ts";
|
|
8
9
|
export { AuthMailNotificationTypes } from "./mail-notifications.ts";
|
|
9
10
|
export { AUTH_SELF_REGISTRATION_FEATURE, createAuthSelfRegistrationToggleFeature, } from "./self-registration-toggle.ts";
|
|
10
11
|
export { signToken, TokenPurpose, type VerifyResult, verifyToken } from "./signed-token.ts";
|
|
@@ -8,6 +8,7 @@ export { normalizeEmail } from "../shared/index.js";
|
|
|
8
8
|
export { hashPassword, verifyPassword } from "../shared/password-hashing.js";
|
|
9
9
|
export { BootstrapPlanError, BootstrapWriteError, bootstrapTenants } from "./bootstrap.js";
|
|
10
10
|
export { authEmailPasswordEnvSchema, createAuthEmailPasswordFeature } from "./feature.js";
|
|
11
|
+
export { sessionForVerifiedUser, } from "./handlers/login.write.js";
|
|
11
12
|
export { AuthMailNotificationTypes } from "./mail-notifications.js";
|
|
12
13
|
export { AUTH_SELF_REGISTRATION_FEATURE, createAuthSelfRegistrationToggleFeature, } from "./self-registration-toggle.js";
|
|
13
14
|
// Generic HMAC-signed single-purpose token helpers. Re-exported so
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DeliveryChannel } from "../delivery/index.ts";
|
|
1
|
+
import type { ChannelContext, DeliveryChannel } from "../delivery/index.ts";
|
|
3
2
|
import type { PushTransport } from "./types.ts";
|
|
4
3
|
export type PushChannelOptions = {
|
|
5
4
|
readonly transport: PushTransport;
|
|
6
|
-
readonly resolveToken: (userId: string, ctx:
|
|
7
|
-
db: unknown;
|
|
8
|
-
tenantId: TenantId;
|
|
9
|
-
}) => Promise<string | null>;
|
|
5
|
+
readonly resolveToken: (userId: string, ctx: Pick<ChannelContext, "db" | "tenantId">) => Promise<string | null>;
|
|
10
6
|
};
|
|
11
7
|
export declare function createPushChannel(options: PushChannelOptions): DeliveryChannel;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-bundled-features",
|
|
3
|
-
"version": "0.424.
|
|
3
|
+
"version": "0.424.1",
|
|
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>",
|
|
@@ -654,9 +654,9 @@
|
|
|
654
654
|
}
|
|
655
655
|
},
|
|
656
656
|
"dependencies": {
|
|
657
|
-
"@cosmicdrift/kumiko-framework": "0.424.
|
|
658
|
-
"@cosmicdrift/kumiko-renderer": "0.424.
|
|
659
|
-
"@cosmicdrift/kumiko-types": "0.424.
|
|
657
|
+
"@cosmicdrift/kumiko-framework": "0.424.1",
|
|
658
|
+
"@cosmicdrift/kumiko-renderer": "0.424.1",
|
|
659
|
+
"@cosmicdrift/kumiko-types": "0.424.1",
|
|
660
660
|
"@fontsource/arimo": "^5.3.0",
|
|
661
661
|
"@fontsource/caladea": "^5.3.0",
|
|
662
662
|
"@fontsource/carlito": "^5.3.0",
|
|
@@ -1339,19 +1339,19 @@
|
|
|
1339
1339
|
"LICENSE"
|
|
1340
1340
|
],
|
|
1341
1341
|
"devDependencies": {
|
|
1342
|
-
"@cosmicdrift/kumiko-locale-de": "0.424.
|
|
1343
|
-
"@cosmicdrift/kumiko-locale-es": "0.424.
|
|
1344
|
-
"@cosmicdrift/kumiko-locale-fr": "0.424.
|
|
1345
|
-
"@cosmicdrift/kumiko-locale-it": "0.424.
|
|
1346
|
-
"@cosmicdrift/kumiko-renderer-mail-html": "0.424.
|
|
1347
|
-
"@cosmicdrift/kumiko-testing": "0.424.
|
|
1342
|
+
"@cosmicdrift/kumiko-locale-de": "0.424.1",
|
|
1343
|
+
"@cosmicdrift/kumiko-locale-es": "0.424.1",
|
|
1344
|
+
"@cosmicdrift/kumiko-locale-fr": "0.424.1",
|
|
1345
|
+
"@cosmicdrift/kumiko-locale-it": "0.424.1",
|
|
1346
|
+
"@cosmicdrift/kumiko-renderer-mail-html": "0.424.1",
|
|
1347
|
+
"@cosmicdrift/kumiko-testing": "0.424.1",
|
|
1348
1348
|
"@testing-library/user-event": "^14.6.8",
|
|
1349
1349
|
"@types/sanitize-html": "^2.16.2",
|
|
1350
1350
|
"jsqr": "^1.4.0",
|
|
1351
1351
|
"unpdf": "^1.9.1"
|
|
1352
1352
|
},
|
|
1353
1353
|
"peerDependencies": {
|
|
1354
|
-
"@cosmicdrift/kumiko-testing": "0.424.
|
|
1354
|
+
"@cosmicdrift/kumiko-testing": "0.424.1"
|
|
1355
1355
|
},
|
|
1356
1356
|
"peerDependenciesMeta": {
|
|
1357
1357
|
"@cosmicdrift/kumiko-testing": {
|
|
@@ -1 +1,8 @@
|
|
|
1
|
-
[
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.424.1",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "resolveToken receives a typed db",
|
|
6
|
+
"detail": "The `ctx.db` passed to `resolveToken` is now typed as the delivery channel's `TenantDb` instead of `unknown`, so an app can query its device entity without a guard or cast. Existing callbacks that take `unknown` still compile."
|
|
7
|
+
}
|
|
8
|
+
]
|