@cosmicdrift/kumiko-bundled-features 0.79.2 → 0.79.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cosmicdrift/kumiko-bundled-features",
3
- "version": "0.79.2",
3
+ "version": "0.79.3",
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>",
@@ -84,11 +84,11 @@
84
84
  "./step-dispatcher": "./src/step-dispatcher/index.ts"
85
85
  },
86
86
  "dependencies": {
87
- "@cosmicdrift/kumiko-dispatcher-live": "0.79.2",
88
- "@cosmicdrift/kumiko-framework": "0.79.2",
89
- "@cosmicdrift/kumiko-headless": "0.79.2",
90
- "@cosmicdrift/kumiko-renderer": "0.79.2",
91
- "@cosmicdrift/kumiko-renderer-web": "0.79.2",
87
+ "@cosmicdrift/kumiko-dispatcher-live": "0.79.3",
88
+ "@cosmicdrift/kumiko-framework": "0.79.3",
89
+ "@cosmicdrift/kumiko-headless": "0.79.3",
90
+ "@cosmicdrift/kumiko-renderer": "0.79.3",
91
+ "@cosmicdrift/kumiko-renderer-web": "0.79.3",
92
92
  "@mollie/api-client": "^4.5.0",
93
93
  "@node-rs/argon2": "^2.0.2",
94
94
  "@types/nodemailer": "^8.0.0",
@@ -374,19 +374,22 @@ describe("download-by-token :: error paths", () => {
374
374
  });
375
375
 
376
376
  describe("download-by-job :: happy path", () => {
377
- test("session-auth: Job-Owner → returns signed URL + audit", async () => {
377
+ test("session-auth: Job-Owner → returns signed URL + audit (IP aus X-Forwarded-For)", async () => {
378
378
  const { jobId } = await seedDoneJobWithToken();
379
379
 
380
- const result = await stack.http.queryOk<{ url: string }>(
380
+ // Der UI-Klick laeuft als direkter download-by-job-Query (Client traegt
381
+ // X-CSRF-Token). Die Audit-IP kommt server-trusted aus dem RequestContext
382
+ // (X-Forwarded-For, erster Hop), nicht aus einem vom Client mitgeschickten
383
+ // Feld.
384
+ const res = await stack.http.queryWithHeaders(
381
385
  "user-data-rights:query:download-by-job",
382
- {
383
- jobId,
384
- auditMeta: { ip: "10.0.0.5", userAgent: "Mozilla/5.0" },
385
- },
386
+ { jobId },
386
387
  aliceUser,
388
+ { "x-forwarded-for": "10.0.0.5, 10.0.0.1" },
387
389
  );
388
-
389
- expect(result.url).toMatch(/^memory:\/\//);
390
+ expect(res.status).toBe(200);
391
+ const body = (await res.json()) as { data: { url: string } };
392
+ expect(body.data.url).toMatch(/^memory:\/\//);
390
393
 
391
394
  // UI-Klick zaehlt auch als Use → audit-row updated
392
395
  const [row] = (await selectMany(stack.db, exportDownloadTokensTable, { jobId })) as Array<{
@@ -13,6 +13,7 @@ export const PRIVACY_CENTER_SCREEN_ID = "privacy-center" as const;
13
13
  export const UserDataRightsQueries = {
14
14
  exportStatus: "user-data-rights:query:export-status",
15
15
  myAuditLog: "user-data-rights:query:my-audit-log",
16
+ downloadByJob: "user-data-rights:query:download-by-job",
16
17
  } as const;
17
18
 
18
19
  export const UserDataRightsHandlers = {
@@ -28,13 +29,6 @@ export const UserDataRightsHandlers = {
28
29
  // Screen-Test vergleicht gegen UserQueries.me.
29
30
  export const USER_ME_QUERY = "user:query:user:me" as const;
30
31
 
31
- // Download-Pfad des fertigen Export-Bundles: der dokumentierte UI-Klick-Pfad
32
- // (r.httpRoute in feature.ts), der per 302 auf die signed Storage-URL
33
- // weiterleitet. Anchor-navigierbar (Cookie-Auth wird mitgesendet).
34
- export function userExportByJobPath(jobId: string): string {
35
- return `/user-export/by-job/${jobId}`;
36
- }
37
-
38
32
  // Client-safe Mirror von EXPORT_JOB_STATUS (schema/export-job.ts ist
39
33
  // server-only via Drizzle-Import). Drift-Schutz: der Screen-Test vergleicht
40
34
  // gegen die Schema-Originale.
@@ -220,17 +220,18 @@ export function createUserDataRightsFeature(opts: UserDataRightsOptions = {}): F
220
220
  access: { openToAll: true },
221
221
  });
222
222
 
223
- // r.httpRoute-Wrapper: Magic-Link-Pfad (anonymous) + UI-Klick-Pfad.
223
+ // Magic-Link-Pfad (anonymous): GET /user-export/by-token?token=<plain>.
224
+ // Ruft via app.fetch /api/query → success: 302-Redirect zur signed-URL →
225
+ // Browser folgt → Download startet beim Object-Store. Bei error:
226
+ // passthrough (404/410/501) als JSON.
224
227
  //
225
- // Beide rufen via app.fetch /api/query wenn success: 302-Redirect
226
- // zur signed-URL Browser folgt → Download startet beim Object-Store.
227
- // Bei error: passthrough (404/410/501) als JSON.
228
+ // Path liegt AUSSERHALB /api/* weil r.httpRoute den /api-namespace nicht
229
+ // claimen darf (reserved fuer write/query/batch/auth/sse-dispatcher).
228
230
  //
229
- // **Token-Pfad (anonymous):** GET /user-export/by-token?token=<plain>
230
- //
231
- // Path liegt AUSSERHALB /api/* weil r.httpRoute den /api-namespace
232
- // nicht claimen darf (reserved fuer write/query/batch/auth/sse-
233
- // dispatcher).
231
+ // Der Session-Pfad (eingeloggter Download) braucht KEINEN httpRoute-
232
+ // Wrapper: der Client ruft download-by-job direkt via Dispatcher (traegt
233
+ // X-CSRF-Token mit) und navigiert auf die zurueckgegebene signed-URL —
234
+ // siehe postWithDownload im privacy-center-screen.
234
235
  r.httpRoute({
235
236
  method: "GET",
236
237
  path: "/user-export/by-token",
@@ -255,33 +256,6 @@ export function createUserDataRightsFeature(opts: UserDataRightsOptions = {}): F
255
256
  },
256
257
  });
257
258
 
258
- // **Session-Pfad (auth):** GET /user-export/by-job/:jobId
259
- r.httpRoute({
260
- method: "GET",
261
- path: "/user-export/by-job/:jobId",
262
- handler: async (c, { app }) => {
263
- const url = new URL(c.req.url);
264
- const jobId = c.req.param("jobId");
265
- if (!jobId) {
266
- return c.json({ error: "missing_job_id" }, 400);
267
- }
268
- const queryRes = await app.fetch(
269
- new Request(`${url.origin}/api/query`, {
270
- method: "POST",
271
- headers: {
272
- "content-type": "application/json",
273
- ...forwardAuthHeaders(c.req.raw.headers),
274
- },
275
- body: JSON.stringify({
276
- type: "user-data-rights:query:download-by-job",
277
- payload: { jobId, auditMeta: extractAuditMeta(c.req.raw.headers) },
278
- }),
279
- }),
280
- );
281
- return mapQueryResponseToRedirect(c, queryRes);
282
- },
283
- });
284
-
285
259
  // S2.U3 Atom 3b — Worker fuer Async Export-Pipeline. Cron-getriggert.
286
260
  r.job(
287
261
  "run-export-jobs",
@@ -363,15 +337,6 @@ async function mapQueryResponseToRedirect(
363
337
  return c.redirect(body.data.url, 302);
364
338
  }
365
339
 
366
- function forwardAuthHeaders(headers: Headers): Record<string, string> {
367
- const out: Record<string, string> = {};
368
- const auth = headers.get("authorization");
369
- if (auth) out["authorization"] = auth;
370
- const cookie = headers.get("cookie");
371
- if (cookie) out["cookie"] = cookie;
372
- return out;
373
- }
374
-
375
340
  // Extract Audit-Meta (IP + UA) aus den HTTP-Headers + steck es in die
376
341
  // query-payload. Der httpRoute-Wrapper ist trusted-source — er hat den
377
342
  // raw-request gesehen, nicht der direkter /api/query-Caller. User der
@@ -23,6 +23,7 @@
23
23
  // 6. Audit-Update: useCount + 1, IP, UA, lastUsedAt (best-effort)
24
24
  // 7. Return {url, expiresAt}
25
25
 
26
+ import { requestContext } from "@cosmicdrift/kumiko-framework/api";
26
27
  import { fetchOne } from "@cosmicdrift/kumiko-framework/bun-db";
27
28
  import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
28
29
  import { NotFoundError, UnprocessableError } from "@cosmicdrift/kumiko-framework/errors";
@@ -54,12 +55,6 @@ export const downloadByJobQuery = defineQueryHandler({
54
55
  name: "download-by-job",
55
56
  schema: z.object({
56
57
  jobId: z.string().min(1, "jobId required"),
57
- auditMeta: z
58
- .object({
59
- ip: z.string().nullable(),
60
- userAgent: z.string().nullable(),
61
- })
62
- .optional(),
63
58
  }),
64
59
  access: { openToAll: true }, // openToAll = auth-required, kein anonymous
65
60
  handler: async (query, ctx) => {
@@ -68,8 +63,13 @@ export const downloadByJobQuery = defineQueryHandler({
68
63
  const userId = query.user.id;
69
64
  const jobId = query.payload.jobId;
70
65
  const tenantId = query.user.tenantId;
71
- const auditIp = query.payload.auditMeta?.ip ?? null;
72
- const auditUa = query.payload.auditMeta?.userAgent ?? null;
66
+ // IP aus dem request-scoped Kontext (von requestIdMiddleware aus
67
+ // x-forwarded-for befuellt) server-trusted, anders als ein vom Client
68
+ // mitgeschickter Wert. UA steht nicht im RequestContext; der Audit-Row
69
+ // laesst sie null (best-effort, via requestId in den Server-Logs
70
+ // cross-referenzierbar).
71
+ const auditIp = requestContext.get()?.ip ?? null;
72
+ const auditUa: string | null = null;
73
73
 
74
74
  // Step 1-2: job-lookup + cross-user-isolation
75
75
  // ctx.db.raw weil tenant-agnostisch — Alice in Tenant B sucht den
@@ -179,8 +179,8 @@ export const downloadByJobQuery = defineQueryHandler({
179
179
  tokenUseCount: tokenRow.useCount ?? 0,
180
180
  tenantId: jobRow.requestedFromTenantId,
181
181
  now,
182
- ip: query.payload.auditMeta?.ip ?? null,
183
- userAgent: query.payload.auditMeta?.userAgent ?? null,
182
+ ip: auditIp,
183
+ userAgent: auditUa,
184
184
  });
185
185
  }
186
186
  // Wenn tokenRow fehlt (sollte nicht passieren wenn Atom 4a sauber
@@ -139,7 +139,7 @@ describe.skip("PrivacyCenterScreen", () => {
139
139
  expect(view.container.textContent).not.toContain("userDataRights.privacyCenter");
140
140
  });
141
141
 
142
- test("export done: Download-Link auf den by-job-Pfad + Verfügbar-bis-Datum", async () => {
142
+ test("export done: Download-Button + Verfügbar-bis-Datum", async () => {
143
143
  const { view } = renderCenter({
144
144
  me: activeMe,
145
145
  exportStatus: {
@@ -148,8 +148,7 @@ describe.skip("PrivacyCenterScreen", () => {
148
148
  },
149
149
  });
150
150
  await waitForMount(view);
151
- const link = view.getByTestId("privacy-export-download") as HTMLAnchorElement;
152
- expect(link.getAttribute("href")).toBe("/user-export/by-job/job-123");
151
+ expect(view.getByTestId("privacy-export-download")).toBeTruthy();
153
152
  const ready = view.getByTestId("privacy-export-ready");
154
153
  expect(ready.textContent).toContain("2026-07-11");
155
154
  expect(ready.textContent).not.toContain("T00:00");
@@ -19,6 +19,7 @@ import {
19
19
  useQuery,
20
20
  useTranslation,
21
21
  } from "@cosmicdrift/kumiko-renderer";
22
+ import { postWithDownload } from "@cosmicdrift/kumiko-renderer-web";
22
23
  import { type ReactNode, useEffect, useState } from "react";
23
24
  import {
24
25
  EXPORT_JOB_STATUS,
@@ -26,7 +27,6 @@ import {
26
27
  USER_ME_QUERY,
27
28
  UserDataRightsHandlers,
28
29
  UserDataRightsQueries,
29
- userExportByJobPath,
30
30
  } from "../constants";
31
31
 
32
32
  const STATUS_DELETION_REQUESTED = "deletionRequested";
@@ -104,6 +104,15 @@ function ExportSection(): ReactNode {
104
104
  void statusQuery.refetch?.();
105
105
  };
106
106
 
107
+ // Download laeuft ueber den Dispatcher (traegt X-CSRF-Token) statt ueber
108
+ // eine <a>-Navigation: download-by-job liefert eine signed URL zurueck, auf
109
+ // die postWithDownload den Browser navigiert (content-disposition:
110
+ // attachment → laedt herunter).
111
+ const downloadExport = async (jobId: string): Promise<void> => {
112
+ const err = await postWithDownload(dispatcher, UserDataRightsQueries.downloadByJob, { jobId });
113
+ if (err) setStatus({ kind: "error", messageKey: failureKey(err) });
114
+ };
115
+
107
116
  const result = statusQuery.data;
108
117
  const job = result && result.hasJob ? result.job : null;
109
118
  const submitting = status.kind === "submitting";
@@ -150,13 +159,15 @@ function ExportSection(): ReactNode {
150
159
  })}
151
160
  </p>
152
161
  )}
153
- <a
154
- href={userExportByJobPath(job.id)}
155
- data-testid="privacy-export-download"
156
- className="mt-2 inline-block font-medium underline"
157
- >
158
- {t("userDataRights.privacyCenter.export.download")}
159
- </a>
162
+ <div className="mt-2">
163
+ <Button
164
+ variant="secondary"
165
+ onClick={() => void downloadExport(job.id)}
166
+ testId="privacy-export-download"
167
+ >
168
+ {t("userDataRights.privacyCenter.export.download")}
169
+ </Button>
170
+ </div>
160
171
  </Banner>
161
172
  )}
162
173
  <StatusBanner status={status} />