@cosmicdrift/kumiko-framework 0.167.0 → 0.167.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/package.json +3 -3
- package/src/api/__tests__/jwt.test.ts +12 -0
- package/src/api/auth-middleware.ts +1 -0
- package/src/api/jwt.ts +7 -0
- package/src/engine/__tests__/boot-validator-pii-retention.test.ts +20 -0
- package/src/engine/boot-validator/pii-retention.ts +7 -1
- package/src/pipeline/dispatch-query.ts +1 -1
- package/src/pipeline/dispatch-shared.ts +15 -9
- package/src/pipeline/dispatch-stream.ts +1 -1
- package/src/pipeline/dispatch-write.ts +1 -1
- package/src/time/tz-context.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-framework",
|
|
3
|
-
"version": "0.167.
|
|
3
|
+
"version": "0.167.1",
|
|
4
4
|
"description": "Framework core — engine, pipeline, API, DB, and every other bit that makes Kumiko go.",
|
|
5
5
|
"license": "BUSL-1.1",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -182,7 +182,7 @@
|
|
|
182
182
|
"./package.json": "./package.json"
|
|
183
183
|
},
|
|
184
184
|
"dependencies": {
|
|
185
|
-
"@cosmicdrift/kumiko-types": "0.167.
|
|
185
|
+
"@cosmicdrift/kumiko-types": "0.167.1",
|
|
186
186
|
"bullmq": "^5.76.7",
|
|
187
187
|
"bun-types": "^1.3.13",
|
|
188
188
|
"hono": "^4.12.27",
|
|
@@ -198,7 +198,7 @@
|
|
|
198
198
|
"zod": "^4.4.3"
|
|
199
199
|
},
|
|
200
200
|
"devDependencies": {
|
|
201
|
-
"@cosmicdrift/kumiko-dispatcher-live": "0.167.
|
|
201
|
+
"@cosmicdrift/kumiko-dispatcher-live": "0.167.1",
|
|
202
202
|
"bun-types": "^1.3.13",
|
|
203
203
|
"pino-pretty": "^13.1.3"
|
|
204
204
|
},
|
|
@@ -82,6 +82,18 @@ describe("createJwtHelper.verify — payload validation (KF-2)", () => {
|
|
|
82
82
|
.sign(new TextEncoder().encode(SECRET));
|
|
83
83
|
await expect(jwt.verify(token)).rejects.toThrow(/sub/);
|
|
84
84
|
});
|
|
85
|
+
|
|
86
|
+
// fw#1636 — SessionUser.timezone must survive the sign/verify roundtrip
|
|
87
|
+
// (jwt.sign silently drops any field it doesn't explicitly copy).
|
|
88
|
+
it("round-trips the timezone claim when set", async () => {
|
|
89
|
+
const payload = await jwt.verify(await jwt.sign({ ...user, timezone: "Asia/Tokyo" }));
|
|
90
|
+
expect(payload.timezone).toBe("Asia/Tokyo");
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("omits the timezone claim when unset", async () => {
|
|
94
|
+
const payload = await jwt.verify(await jwt.sign(user));
|
|
95
|
+
expect(payload.timezone).toBeUndefined();
|
|
96
|
+
});
|
|
85
97
|
});
|
|
86
98
|
|
|
87
99
|
describe("createJwtHelper — keyring form", () => {
|
|
@@ -307,6 +307,7 @@ export function authMiddleware(jwt: JwtHelper, options: AuthMiddlewareOptions =
|
|
|
307
307
|
id: payload.sub,
|
|
308
308
|
tenantId: payload.tenantId,
|
|
309
309
|
roles: payload.roles,
|
|
310
|
+
...(payload.timezone ? { timezone: payload.timezone } : {}),
|
|
310
311
|
...(payload.claims ? { claims: payload.claims } : {}),
|
|
311
312
|
...(payload.jti ? { sid: payload.jti } : {}),
|
|
312
313
|
};
|
package/src/api/jwt.ts
CHANGED
|
@@ -10,6 +10,9 @@ export type JwtPayload = {
|
|
|
10
10
|
sub: string;
|
|
11
11
|
tenantId: TenantId;
|
|
12
12
|
roles: string[];
|
|
13
|
+
// IANA zone from user.timezone, set at login — see SessionUser.timezone
|
|
14
|
+
// (fw#1636). Absent → ctx.tz.user falls back to ctx.tz.tenant.
|
|
15
|
+
timezone?: string;
|
|
13
16
|
// Optional — present when a feature has registered auth claims via the
|
|
14
17
|
// `r.authClaims()` hook system. Absent for stateless-JWT deployments
|
|
15
18
|
// without auth-claims wiring.
|
|
@@ -106,6 +109,7 @@ export function createJwtHelper(
|
|
|
106
109
|
tenantId: user.tenantId,
|
|
107
110
|
roles: [...user.roles],
|
|
108
111
|
};
|
|
112
|
+
if (user.timezone) body.timezone = user.timezone;
|
|
109
113
|
if (user.claims) body.claims = { ...user.claims };
|
|
110
114
|
|
|
111
115
|
const header: jose.JWTHeaderParameters = keyring.signKid
|
|
@@ -155,6 +159,9 @@ export function createJwtHelper(
|
|
|
155
159
|
tenantId,
|
|
156
160
|
roles,
|
|
157
161
|
};
|
|
162
|
+
if (typeof payload["timezone"] === "string") {
|
|
163
|
+
result.timezone = payload["timezone"];
|
|
164
|
+
}
|
|
158
165
|
const claims = payload["claims"];
|
|
159
166
|
if (claims && typeof claims === "object") {
|
|
160
167
|
result.claims = claims as DbRow;
|
|
@@ -558,6 +558,7 @@ describe("validateBoot — retention", () => {
|
|
|
558
558
|
createEntity({
|
|
559
559
|
fields: {
|
|
560
560
|
invoiceNumber: createTextField({ allowPlaintext: "is-business-data" }),
|
|
561
|
+
customerName: createTextField({ pii: true }),
|
|
561
562
|
},
|
|
562
563
|
retention: { keepFor: "10y", strategy: "blockDelete" },
|
|
563
564
|
}),
|
|
@@ -570,6 +571,25 @@ describe("validateBoot — retention", () => {
|
|
|
570
571
|
expect(matchingWarn).toBeDefined();
|
|
571
572
|
});
|
|
572
573
|
|
|
574
|
+
test("blockDelete without any subject-annotated field stays silent (#1622)", () => {
|
|
575
|
+
const feature = defineFeature("test", (r) => {
|
|
576
|
+
r.entity(
|
|
577
|
+
"lease",
|
|
578
|
+
createEntity({
|
|
579
|
+
fields: {
|
|
580
|
+
reference: createTextField({ allowPlaintext: "is-business-data" }),
|
|
581
|
+
},
|
|
582
|
+
retention: { keepFor: "10y", strategy: "blockDelete" },
|
|
583
|
+
}),
|
|
584
|
+
);
|
|
585
|
+
});
|
|
586
|
+
validateBoot([feature]);
|
|
587
|
+
const matchingWarn = warnSpy.mock.calls.find((args: unknown[]) =>
|
|
588
|
+
String(args[0]).includes('strategy="blockDelete" but no field has an anonymize-function'),
|
|
589
|
+
);
|
|
590
|
+
expect(matchingWarn).toBeUndefined();
|
|
591
|
+
});
|
|
592
|
+
|
|
573
593
|
test('retention.keepFor with invalid format "30days" warns', () => {
|
|
574
594
|
const feature = defineFeature("test", (r) => {
|
|
575
595
|
r.entity(
|
|
@@ -234,11 +234,17 @@ export function validatePiiAndRetention(feature: FeatureDefinition): void {
|
|
|
234
234
|
}
|
|
235
235
|
|
|
236
236
|
if (retention.strategy === "blockDelete") {
|
|
237
|
+
// blockDelete on an entity with no subject field is the correct
|
|
238
|
+
// "never auto-delete" choice; User-Forget never reaches those rows (#1622).
|
|
239
|
+
const hasSubjectField = Object.values(fieldsByName).some((f) => {
|
|
240
|
+
const a = f as PiiAnnotations; // @cast-boundary schema-walk
|
|
241
|
+
return Boolean(a.pii || a.userOwned || a.tenantOwned);
|
|
242
|
+
});
|
|
237
243
|
const hasAnonymize = Object.values(fieldsByName).some((f) => {
|
|
238
244
|
const a = f as PiiAnnotations; // @cast-boundary schema-walk
|
|
239
245
|
return Boolean(a.anonymize);
|
|
240
246
|
});
|
|
241
|
-
if (!hasAnonymize) {
|
|
247
|
+
if (hasSubjectField && !hasAnonymize) {
|
|
242
248
|
// biome-ignore lint/suspicious/noConsole: boot-time dev hint, no logger available yet
|
|
243
249
|
console.warn(
|
|
244
250
|
`[kumiko:boot] [Feature ${feature.name}] Entity "${entityName}" retention.strategy="blockDelete" but no field has an anonymize-function. User-Forget cannot anonymize — Forget will return error. Add { anonymize: () => null } or () => "[ANONYMIZED]" to PII fields.`,
|
|
@@ -79,7 +79,7 @@ async function executeQueryInner(
|
|
|
79
79
|
typeof parsed.data === "object" &&
|
|
80
80
|
parsed.data !== null &&
|
|
81
81
|
(parsed.data as Record<string, unknown>)["includeDeleted"] === true; // @cast-boundary validated-payload
|
|
82
|
-
const handlerContext = buildHandlerContext(ctx, type, user, tx, undefined, includeDeleted);
|
|
82
|
+
const handlerContext = await buildHandlerContext(ctx, type, user, tx, undefined, includeDeleted);
|
|
83
83
|
let result = await handler.handler({ type, payload: parsed.data, user }, handlerContext);
|
|
84
84
|
|
|
85
85
|
// postQuery-Hooks: fire BEFORE field-access-filter so hooks see raw data
|
|
@@ -146,14 +146,14 @@ async function appendDomainEvent(
|
|
|
146
146
|
);
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
export function buildHandlerContext(
|
|
149
|
+
export async function buildHandlerContext(
|
|
150
150
|
ctx: DispatchContext,
|
|
151
151
|
type: string,
|
|
152
152
|
user: SessionUser,
|
|
153
153
|
tx?: DbTx,
|
|
154
154
|
afterCommitHooks?: AfterCommitHook[],
|
|
155
155
|
includeDeleted?: boolean,
|
|
156
|
-
): HandlerContext {
|
|
156
|
+
): Promise<HandlerContext> {
|
|
157
157
|
const { registry, appContext: context, effectiveFeatures, jobRunner } = ctx;
|
|
158
158
|
const isSystem = registry.isHandlerSystemScoped(type);
|
|
159
159
|
// The outer dispatcher receives a DbConnection from the server/stack;
|
|
@@ -515,13 +515,19 @@ export function buildHandlerContext(
|
|
|
515
515
|
// HandlerContext. The spread-then-assign order matters: anything in
|
|
516
516
|
// `context` can be overridden, but we want the authoritative registry
|
|
517
517
|
// from the dispatcher's own closure to win.
|
|
518
|
-
// ctx.tz
|
|
519
|
-
//
|
|
520
|
-
//
|
|
521
|
-
//
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
)
|
|
518
|
+
// ctx.tz is always present. tenant reads tenant:config:timezone through
|
|
519
|
+
// the already-built `config` accessor (raw qualified-key — no import of
|
|
520
|
+
// the tenant feature, framework/pipeline stays bundled-features-free);
|
|
521
|
+
// falls back to "UTC" when config is missing or the key is unset. user
|
|
522
|
+
// comes from SessionUser.timezone (set at login), else falls back to
|
|
523
|
+
// tenant (createTzContext's own default). An app-injected GeoTzProvider
|
|
524
|
+
// (context.geoTzProvider) feeds ctx.tz.fromCoordinates / fromAddress.
|
|
525
|
+
const tenantTz = config !== undefined ? await config("tenant:config:timezone") : undefined;
|
|
526
|
+
const tz = createTzContext({
|
|
527
|
+
...(context.geoTzProvider !== undefined ? { geoTz: context.geoTzProvider } : {}),
|
|
528
|
+
tenant: typeof tenantTz === "string" ? tenantTz : "UTC",
|
|
529
|
+
...(user.timezone !== undefined && { user: user.timezone }),
|
|
530
|
+
});
|
|
525
531
|
|
|
526
532
|
return {
|
|
527
533
|
...context,
|
|
@@ -73,7 +73,7 @@ async function* executeStreamInner(
|
|
|
73
73
|
// await; close is fire-and-forget instead (#1563).
|
|
74
74
|
let abandonedForInvalidation = false;
|
|
75
75
|
try {
|
|
76
|
-
const handlerContext = buildHandlerContext(ctx, type, user);
|
|
76
|
+
const handlerContext = await buildHandlerContext(ctx, type, user);
|
|
77
77
|
const chunks = handler.handler({ type, payload: parsed.data, user }, handlerContext);
|
|
78
78
|
iterator = chunks[Symbol.asyncIterator]();
|
|
79
79
|
|
|
@@ -348,7 +348,7 @@ async function executeWriteInner(
|
|
|
348
348
|
}
|
|
349
349
|
}
|
|
350
350
|
|
|
351
|
-
const handlerContext = buildHandlerContext(ctx, type, user, tx, afterCommitHooks);
|
|
351
|
+
const handlerContext = await buildHandlerContext(ctx, type, user, tx, afterCommitHooks);
|
|
352
352
|
|
|
353
353
|
// Auto transition guard: if entity has transitions and handler doesn't skip it
|
|
354
354
|
if (entityName && !handler.unsafeSkipTransitionGuard) {
|
package/src/time/tz-context.ts
CHANGED
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
// Feature code should no longer call `new Date()` — the lint rule for that
|
|
11
11
|
// lands in a later iteration, once all existing usages are migrated.
|
|
12
12
|
//
|
|
13
|
-
// `tenant` + `user` are the TZ defaults for the current request
|
|
14
|
-
//
|
|
15
|
-
//
|
|
13
|
+
// `tenant` + `user` are the TZ defaults for the current request — resolved
|
|
14
|
+
// by buildHandlerContext (tenant:config:timezone, then SessionUser.timezone,
|
|
15
|
+
// falling back to "UTC" at each step) and passed in via TzContextOptions.
|
|
16
|
+
// This factory itself stays a pure default-filler.
|
|
16
17
|
//
|
|
17
18
|
// The pure type contracts (TzContext, TzContextOptions, LocatedTimestampJson)
|
|
18
19
|
// live in @cosmicdrift/kumiko-types/tz-context — only the factories are here.
|