@cosmicdrift/kumiko-server-runtime 0.329.0 → 0.330.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.
Files changed (90) hide show
  1. package/README.md +15 -0
  2. package/dist/boot/apply-boot-seeds.d.ts +8 -0
  3. package/{src/boot/apply-boot-seeds.ts → dist/boot/apply-boot-seeds.js} +2 -10
  4. package/dist/boot/boot-crypto.d.ts +9 -0
  5. package/dist/boot/boot-crypto.js +39 -0
  6. package/dist/boot/job-run-logger.d.ts +19 -0
  7. package/dist/boot/job-run-logger.js +44 -0
  8. package/dist/boot/pii-event-backfill-on-boot.d.ts +13 -0
  9. package/dist/boot/pii-event-backfill-on-boot.js +25 -0
  10. package/dist/build-prod-bundle.d.ts +103 -0
  11. package/dist/build-prod-bundle.js +751 -0
  12. package/dist/bun-serve-options.d.ts +32 -0
  13. package/dist/bun-serve-options.js +49 -0
  14. package/dist/compose-features.d.ts +31 -0
  15. package/dist/compose-features.js +124 -0
  16. package/dist/extra-routes-deps.d.ts +30 -0
  17. package/dist/extra-routes-deps.js +4 -0
  18. package/dist/index.d.ts +6 -0
  19. package/dist/index.js +7 -0
  20. package/dist/pii-boot-gate.d.ts +13 -0
  21. package/dist/pii-boot-gate.js +46 -0
  22. package/dist/renderer-web-fonts.d.ts +9 -0
  23. package/{src/renderer-web-fonts.ts → dist/renderer-web-fonts.js} +14 -18
  24. package/dist/resolve-tailwind-cli.d.ts +14 -0
  25. package/dist/resolve-tailwind-cli.js +36 -0
  26. package/dist/run-prod-app-boot-context.d.ts +43 -0
  27. package/dist/run-prod-app-boot-context.js +198 -0
  28. package/dist/run-prod-app-static-files.d.ts +32 -0
  29. package/dist/run-prod-app-static-files.js +280 -0
  30. package/dist/run-prod-app.d.ts +471 -0
  31. package/dist/run-prod-app.js +741 -0
  32. package/dist/run-worker-app.d.ts +92 -0
  33. package/dist/run-worker-app.js +220 -0
  34. package/dist/security-headers.d.ts +20 -0
  35. package/dist/security-headers.js +49 -0
  36. package/dist/session-boot-gate.d.ts +11 -0
  37. package/dist/session-boot-gate.js +22 -0
  38. package/dist/session-wiring.d.ts +11 -0
  39. package/{src/session-wiring.ts → dist/session-wiring.js} +2 -6
  40. package/dist/try-hono-first.d.ts +24 -0
  41. package/{src/try-hono-first.ts → dist/try-hono-first.js} +8 -36
  42. package/package.json +102 -36
  43. package/src/changes.json +6 -0
  44. package/src/__tests__/boot-extra-context.test.ts +0 -163
  45. package/src/__tests__/boot-probe-fixture.ts +0 -64
  46. package/src/__tests__/build-prod-bundle.inprocess.test.ts +0 -233
  47. package/src/__tests__/build-prod-bundle.test.ts +0 -724
  48. package/src/__tests__/cache-headers.test.ts +0 -83
  49. package/src/__tests__/compose-features-mfa-wiring.integration.test.ts +0 -308
  50. package/src/__tests__/compose-features-wiring.integration.test.ts +0 -609
  51. package/src/__tests__/compose-features.test.ts +0 -206
  52. package/src/__tests__/config-seed-boot.integration.test.ts +0 -158
  53. package/src/__tests__/pii-boot-gate.test.ts +0 -112
  54. package/src/__tests__/renderer-web-css-relocation.integration.test.ts +0 -85
  55. package/src/__tests__/renderer-web-shell-sentinel.test.ts +0 -35
  56. package/src/__tests__/renderer-web-theme-plugin.integration.test.ts +0 -77
  57. package/src/__tests__/require-env.test.ts +0 -34
  58. package/src/__tests__/resolve-auth-mail.test.ts +0 -144
  59. package/src/__tests__/resolve-tailwind-cli.test.ts +0 -81
  60. package/src/__tests__/run-prod-app-dry-run.test.ts +0 -135
  61. package/src/__tests__/run-prod-app-env-source.test.ts +0 -118
  62. package/src/__tests__/run-prod-app-kms-slots.test.ts +0 -108
  63. package/src/__tests__/run-prod-app-spec.test.ts +0 -167
  64. package/src/__tests__/run-prod-app-static-files.test.ts +0 -298
  65. package/src/__tests__/run-prod-app.integration.test.ts +0 -1525
  66. package/src/__tests__/run-worker-app-boot.test.ts +0 -183
  67. package/src/__tests__/run-worker-app.integration.test.ts +0 -218
  68. package/src/__tests__/security-headers.test.ts +0 -88
  69. package/src/__tests__/session-boot-gate.test.ts +0 -70
  70. package/src/__tests__/session-wiring.test.ts +0 -16
  71. package/src/__tests__/try-hono-first.test.ts +0 -108
  72. package/src/__tests__/websocket-route.integration.test.ts +0 -695
  73. package/src/boot/__tests__/job-run-logger.integration.test.ts +0 -262
  74. package/src/boot/__tests__/job-run-logger.test.ts +0 -26
  75. package/src/boot/boot-crypto.ts +0 -67
  76. package/src/boot/job-run-logger.ts +0 -63
  77. package/src/boot/pii-event-backfill-on-boot.ts +0 -43
  78. package/src/build-prod-bundle.ts +0 -996
  79. package/src/bun-serve-options.ts +0 -110
  80. package/src/compose-features.ts +0 -197
  81. package/src/extra-routes-deps.ts +0 -38
  82. package/src/index.ts +0 -27
  83. package/src/pii-boot-gate.ts +0 -80
  84. package/src/resolve-tailwind-cli.ts +0 -45
  85. package/src/run-prod-app-boot-context.ts +0 -319
  86. package/src/run-prod-app-static-files.ts +0 -359
  87. package/src/run-prod-app.ts +0 -1420
  88. package/src/run-worker-app.ts +0 -366
  89. package/src/security-headers.ts +0 -67
  90. package/src/session-boot-gate.ts +0 -34
@@ -1,83 +0,0 @@
1
- // Unit-Tests für staticCachePolicy — die Cache-Strategie hinter
2
- // runProdApp's static-fallback. Pure function, leicht zu testen.
3
- //
4
- // Strategie (siehe run-prod-app.ts):
5
- // /assets/* → immutable
6
- // /, /index.html → revalidate (max-age=0, must-revalidate)
7
- // /manifest.json, /sw.js,
8
- // /build-info.json → no-cache
9
- // alles andere → none
10
-
11
- import { describe, expect, test } from "bun:test";
12
- import { cacheControlHeader } from "@cosmicdrift/kumiko-framework/api";
13
- import { staticCachePolicy } from "../run-prod-app";
14
-
15
- function cacheControlFor(pathname: string): Record<string, string> {
16
- const header = cacheControlHeader(staticCachePolicy(pathname));
17
- return header === undefined ? {} : { "cache-control": header };
18
- }
19
-
20
- describe("staticCachePolicy", () => {
21
- test("hashed asset → immutable + 1 Jahr", () => {
22
- expect(cacheControlFor("/assets/client-abc123.js")).toEqual({
23
- "cache-control": "public, max-age=31536000, immutable",
24
- });
25
- });
26
-
27
- test("hashed CSS asset → immutable + 1 Jahr", () => {
28
- expect(cacheControlFor("/assets/styles-def456.css")).toEqual({
29
- "cache-control": "public, max-age=31536000, immutable",
30
- });
31
- });
32
-
33
- test("nested asset path → immutable", () => {
34
- expect(cacheControlFor("/assets/chunks/foo-789.js")).toEqual({
35
- "cache-control": "public, max-age=31536000, immutable",
36
- });
37
- });
38
-
39
- test("/ → revalidate", () => {
40
- expect(cacheControlFor("/")).toEqual({
41
- "cache-control": "public, max-age=0, must-revalidate",
42
- });
43
- });
44
-
45
- test("/index.html → revalidate", () => {
46
- expect(cacheControlFor("/index.html")).toEqual({
47
- "cache-control": "public, max-age=0, must-revalidate",
48
- });
49
- });
50
-
51
- test("/manifest.json → no-cache", () => {
52
- expect(cacheControlFor("/manifest.json")).toEqual({
53
- "cache-control": "no-cache",
54
- });
55
- });
56
-
57
- test("/sw.js → no-cache", () => {
58
- expect(cacheControlFor("/sw.js")).toEqual({
59
- "cache-control": "no-cache",
60
- });
61
- });
62
-
63
- test("/build-info.json → no-cache (sonst pollt UpdateChecker eine veraltete id)", () => {
64
- expect(cacheControlFor("/build-info.json")).toEqual({
65
- "cache-control": "no-cache",
66
- });
67
- });
68
-
69
- test("public-folder file (favicon) → kein expliziter Header", () => {
70
- expect(cacheControlFor("/favicon.ico")).toEqual({});
71
- });
72
-
73
- test("public-folder file (og-image) → kein expliziter Header", () => {
74
- expect(cacheControlFor("/og-image.png")).toEqual({});
75
- });
76
-
77
- test("path mit assets als Substring (kein /assets/ prefix) → kein immutable", () => {
78
- // Schutz: /myassets/foo.js soll NICHT immutable kriegen — wäre ein Bug
79
- // weil die nicht gehashed sind.
80
- expect(cacheControlFor("/myassets/foo.js")).toEqual({});
81
- expect(cacheControlFor("/foo/assets/bar.js")).toEqual({});
82
- });
83
- });
@@ -1,308 +0,0 @@
1
- // Full-stack wiring test for kumiko-framework#266 Step 6: proves the exact
2
- // bootstrap path runProdApp/runDevApp produce — composeFeatures() auto-
3
- // detecting a mounted auth-mfa app-feature and wiring its status-checker
4
- // into the login handler — actually completes a two-step login over real
5
- // HTTP. compose-features-wiring.integration.test.ts pins the same pattern
6
- // for passwordReset/emailVerification; this is the auth-mfa analogue.
7
- //
8
- // No mocking: setupTestStack boots a real DB + Redis.
9
-
10
- import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
11
- import {
12
- AuthHandlers,
13
- hashPassword,
14
- } from "@cosmicdrift/kumiko-bundled-features/auth-email-password";
15
- import {
16
- AuthMfaHandlers,
17
- base32Decode,
18
- bindMfaRevokeAllOtherSessionsFromFeature,
19
- createAuthMfaFeature,
20
- mfaRequiredConfigHandle,
21
- userMfaEntity,
22
- } from "@cosmicdrift/kumiko-bundled-features/auth-mfa";
23
- import { currentTotpCode } from "@cosmicdrift/kumiko-bundled-features/auth-mfa/testing";
24
- import {
25
- configValuesTable,
26
- createConfigResolver,
27
- } from "@cosmicdrift/kumiko-bundled-features/config";
28
- import {
29
- createSessionCallbacks,
30
- userSessionEntity,
31
- } from "@cosmicdrift/kumiko-bundled-features/sessions";
32
- import { tenantEntity, tenantMembershipsTable } from "@cosmicdrift/kumiko-bundled-features/tenant";
33
- import { seedTenantMembership } from "@cosmicdrift/kumiko-bundled-features/tenant/testing";
34
- import { UserHandlers, userEntity, userTable } from "@cosmicdrift/kumiko-bundled-features/user";
35
- import { configureEntityFieldEncryption } from "@cosmicdrift/kumiko-framework/db";
36
- import type { TenantId } from "@cosmicdrift/kumiko-framework/engine";
37
- import {
38
- setupTestStack,
39
- type TestStack,
40
- TestUsers,
41
- unsafeCreateEntityTable,
42
- unsafePushTables,
43
- } from "@cosmicdrift/kumiko-framework/stack";
44
- import { createTestEnvelopeCipher, deleteRows } from "@cosmicdrift/kumiko-framework/testing";
45
- import { composeFeatures } from "../compose-features";
46
-
47
- const CHALLENGE_TOKEN_SECRET = "test-mfa-challenge-secret-at-least-32-bytes!!";
48
- const SETUP_TOKEN_SECRET = "test-mfa-setup-secret-at-least-32-bytes-long!!";
49
- const TEST_TENANT_ID: TenantId = "00000000-0000-4000-8000-000000000001" as TenantId;
50
- const systemAdmin = TestUsers.systemAdmin;
51
-
52
- async function bootStack(): Promise<TestStack> {
53
- configureEntityFieldEncryption(createTestEnvelopeCipher());
54
- const mfaFeature = createAuthMfaFeature({
55
- setupTokenSecret: SETUP_TOKEN_SECRET,
56
- challengeTokenSecret: CHALLENGE_TOKEN_SECRET,
57
- issuer: "Kumiko Test",
58
- });
59
-
60
- // Exactly what runProdApp/runDevApp do: composeFeatures sees auth-mfa in
61
- // the app-feature list and threads mfaStatusChecker into the bundled
62
- // auth-email-password feature's login handler on its own — no authOptions
63
- // override needed here, which is the thing this test proves.
64
- const features = composeFeatures([mfaFeature], { includeBundled: true });
65
-
66
- const stack = await setupTestStack({
67
- features,
68
- extraContext: () => ({ configResolver: createConfigResolver() }),
69
- authConfig: {
70
- membershipQuery: "tenant:query:memberships",
71
- loginHandler: AuthHandlers.login,
72
- mfaVerifyHandler: AuthMfaHandlers.verify,
73
- },
74
- });
75
-
76
- const sessionCallbacks = createSessionCallbacks({ db: stack.db });
77
- bindMfaRevokeAllOtherSessionsFromFeature(mfaFeature)?.(sessionCallbacks.sessionRevokeAllOthers);
78
-
79
- await unsafeCreateEntityTable(stack.db, userEntity);
80
- await unsafeCreateEntityTable(stack.db, tenantEntity);
81
- await unsafeCreateEntityTable(stack.db, userMfaEntity);
82
- await unsafeCreateEntityTable(stack.db, userSessionEntity);
83
- await unsafePushTables(stack.db, { configValuesTable, tenantMembershipsTable });
84
-
85
- return stack;
86
- }
87
-
88
- async function seedUser(
89
- stack: TestStack,
90
- opts: { email: string; password: string; roles?: readonly string[] },
91
- ): Promise<{ id: string }> {
92
- const hash = await hashPassword(opts.password);
93
- const created = await stack.http.writeOk<{ id: string }>(
94
- UserHandlers.create,
95
- { email: opts.email, passwordHash: hash, displayName: opts.email.split("@")[0] ?? "user" },
96
- systemAdmin,
97
- );
98
- await seedTenantMembership(stack.db, {
99
- userId: created.id,
100
- tenantId: TEST_TENANT_ID,
101
- roles: opts.roles ?? ["User"],
102
- });
103
- return { id: created.id };
104
- }
105
-
106
- describe("composeFeatures wiring — auth-mfa (kumiko-framework#266 Step 6)", () => {
107
- let stack: TestStack;
108
-
109
- beforeAll(async () => {
110
- stack = await bootStack();
111
- });
112
-
113
- afterAll(async () => {
114
- await stack.cleanup();
115
- });
116
-
117
- beforeEach(async () => {
118
- await deleteRows(stack.db, userTable, {});
119
- await deleteRows(stack.db, tenantMembershipsTable, {});
120
- });
121
-
122
- test("full login-with-MFA flow: password login → mfa-challenge → /auth/mfa/verify → session", async () => {
123
- const user = await seedUser(stack, {
124
- email: "alice@example.com",
125
- password: "correct-password-1234",
126
- });
127
-
128
- const start = await stack.http.writeOk<{ setupToken: string; otpauthUri: string }>(
129
- AuthMfaHandlers.enableStart,
130
- { accountLabel: "alice@example.com" },
131
- { id: user.id, tenantId: TEST_TENANT_ID, roles: ["User"] },
132
- );
133
- const secretParam = new URLSearchParams(start.otpauthUri.split("?")[1]).get("secret") ?? "";
134
- const secret = base32Decode(secretParam);
135
- await stack.http.writeOk(
136
- AuthMfaHandlers.enableConfirm,
137
- { setupToken: start.setupToken, code: currentTotpCode(secret) },
138
- { id: user.id, tenantId: TEST_TENANT_ID, roles: ["User"] },
139
- );
140
-
141
- // Step 1: a correct password no longer mints a session directly — it
142
- // hands back a challenge, proving composeFeatures actually wired
143
- // mfaStatusChecker into the login handler (without the wiring this
144
- // would 200 straight to a session and the test would fail below).
145
- const loginRes = await stack.http.raw("POST", "/api/auth/login", {
146
- email: "alice@example.com",
147
- password: "correct-password-1234",
148
- });
149
- expect(loginRes.status).toBe(200);
150
- const loginBody = (await loginRes.json()) as {
151
- isSuccess: boolean;
152
- mfaRequired?: boolean;
153
- challengeToken?: string;
154
- };
155
- expect(loginBody.mfaRequired).toBe(true);
156
- expect(loginBody.challengeToken).toBeTruthy();
157
- const challengeToken = loginBody.challengeToken;
158
- if (!challengeToken) throw new Error("no challengeToken in login response");
159
-
160
- // Step 2: completing the challenge over the REAL /api/auth/mfa/verify
161
- // route (not a direct handler dispatch) mints the session.
162
- const verifyRes = await stack.http.raw("POST", "/api/auth/mfa/verify", {
163
- challengeToken,
164
- code: currentTotpCode(secret),
165
- });
166
- expect(verifyRes.status).toBe(200);
167
- const verifyBody = (await verifyRes.json()) as {
168
- isSuccess: boolean;
169
- token: string;
170
- user: { id: string; tenantId: string };
171
- };
172
- expect(verifyBody.isSuccess).toBe(true);
173
- expect(verifyBody.token).toBeTruthy();
174
- expect(verifyBody.user.id).toBe(user.id);
175
- });
176
-
177
- test("a user without MFA enabled logs in with a straight session (no challenge)", async () => {
178
- await seedUser(stack, { email: "bob@example.com", password: "any-password-1234" });
179
-
180
- const res = await stack.http.raw("POST", "/api/auth/login", {
181
- email: "bob@example.com",
182
- password: "any-password-1234",
183
- });
184
- expect(res.status).toBe(200);
185
- const body = (await res.json()) as {
186
- isSuccess: boolean;
187
- mfaRequired?: boolean;
188
- token?: string;
189
- };
190
- expect(body.mfaRequired).toBeUndefined();
191
- expect(body.token).toBeTruthy();
192
- });
193
- });
194
-
195
- async function setPolicy(stack: TestStack, policy: "optional" | "admins" | "all"): Promise<void> {
196
- await stack.http.writeOk(
197
- "config:write:set",
198
- { key: mfaRequiredConfigHandle.name, value: policy },
199
- { id: systemAdmin.id, tenantId: TEST_TENANT_ID, roles: ["SystemAdmin"] },
200
- );
201
- }
202
-
203
- // Step 7: enforcement policy only matters for UNENROLLED users — an
204
- // enrolled user always gets a challenge regardless of policy (they opted
205
- // in themselves). ponytail (see auth-mfa's config.ts): "admins"/"all"
206
- // hard-block an unenrolled matching user with mfaSetupRequired — there is
207
- // no enrollment-during-login UI yet (PR3). By design for this backend step.
208
- describe("composeFeatures wiring — auth-mfa enforcement policy (kumiko-framework#266 Step 7)", () => {
209
- let stack: TestStack;
210
-
211
- beforeAll(async () => {
212
- stack = await bootStack();
213
- });
214
-
215
- afterAll(async () => {
216
- await stack.cleanup();
217
- });
218
-
219
- beforeEach(async () => {
220
- await deleteRows(stack.db, userTable, {});
221
- await deleteRows(stack.db, tenantMembershipsTable, {});
222
- await setPolicy(stack, "optional");
223
- });
224
-
225
- test("optional (default): unenrolled user still gets a straight session", async () => {
226
- await seedUser(stack, { email: "carol@example.com", password: "any-password-1234" });
227
- const res = await stack.http.raw("POST", "/api/auth/login", {
228
- email: "carol@example.com",
229
- password: "any-password-1234",
230
- });
231
- expect(res.status).toBe(200);
232
- const body = (await res.json()) as { mfaSetupRequired?: boolean; token?: string };
233
- expect(body.mfaSetupRequired).toBeUndefined();
234
- expect(body.token).toBeTruthy();
235
- });
236
-
237
- test("all: unenrolled user is blocked with mfaSetupRequired, no session/challenge", async () => {
238
- await setPolicy(stack, "all");
239
- await seedUser(stack, { email: "dave@example.com", password: "any-password-1234" });
240
- const res = await stack.http.raw("POST", "/api/auth/login", {
241
- email: "dave@example.com",
242
- password: "any-password-1234",
243
- });
244
- expect(res.status).toBe(200);
245
- const body = (await res.json()) as {
246
- mfaSetupRequired?: boolean;
247
- mfaRequired?: boolean;
248
- token?: string;
249
- };
250
- expect(body.mfaSetupRequired).toBe(true);
251
- expect(body.mfaRequired).toBeUndefined();
252
- expect(body.token).toBeUndefined();
253
- });
254
-
255
- test("all: an already-enrolled user still gets a challenge, not a block", async () => {
256
- await setPolicy(stack, "all");
257
- const user = await seedUser(stack, {
258
- email: "erin@example.com",
259
- password: "any-password-1234",
260
- });
261
- const start = await stack.http.writeOk<{ setupToken: string; otpauthUri: string }>(
262
- AuthMfaHandlers.enableStart,
263
- { accountLabel: "erin@example.com" },
264
- { id: user.id, tenantId: TEST_TENANT_ID, roles: ["User"] },
265
- );
266
- const secretParam = new URLSearchParams(start.otpauthUri.split("?")[1]).get("secret") ?? "";
267
- const secret = base32Decode(secretParam);
268
- await stack.http.writeOk(
269
- AuthMfaHandlers.enableConfirm,
270
- { setupToken: start.setupToken, code: currentTotpCode(secret) },
271
- { id: user.id, tenantId: TEST_TENANT_ID, roles: ["User"] },
272
- );
273
-
274
- const res = await stack.http.raw("POST", "/api/auth/login", {
275
- email: "erin@example.com",
276
- password: "any-password-1234",
277
- });
278
- expect(res.status).toBe(200);
279
- const body = (await res.json()) as { mfaSetupRequired?: boolean; mfaRequired?: boolean };
280
- expect(body.mfaRequired).toBe(true);
281
- expect(body.mfaSetupRequired).toBeUndefined();
282
- });
283
-
284
- test("admins: unenrolled admin is blocked, unenrolled non-admin logs in normally", async () => {
285
- await setPolicy(stack, "admins");
286
- await seedUser(stack, {
287
- email: "frank-admin@example.com",
288
- password: "any-password-1234",
289
- roles: ["Admin"],
290
- });
291
- await seedUser(stack, { email: "gina-user@example.com", password: "any-password-1234" });
292
-
293
- const adminRes = await stack.http.raw("POST", "/api/auth/login", {
294
- email: "frank-admin@example.com",
295
- password: "any-password-1234",
296
- });
297
- const adminBody = (await adminRes.json()) as { mfaSetupRequired?: boolean };
298
- expect(adminBody.mfaSetupRequired).toBe(true);
299
-
300
- const userRes = await stack.http.raw("POST", "/api/auth/login", {
301
- email: "gina-user@example.com",
302
- password: "any-password-1234",
303
- });
304
- const userBody = (await userRes.json()) as { mfaSetupRequired?: boolean; token?: string };
305
- expect(userBody.mfaSetupRequired).toBeUndefined();
306
- expect(userBody.token).toBeTruthy();
307
- });
308
- });