@cosmicdrift/kumiko-framework 0.414.0 → 0.416.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/agents/api/framework-engine.md +46 -8
- package/agents/api/framework-errors.md +1 -1
- package/agents/api/framework-ui-types.md +69 -4
- package/agents/api/renderer-web.md +27 -4
- package/agents/api/types.md +68 -16
- package/agents/api.md +2 -2
- package/agents/boot-rules.md +39 -7
- package/agents/examples/crypto-shredding-hr.md +63 -1
- package/agents/examples/embedded.md +24 -1
- package/agents/examples/handbook-knowledge.md +129 -0
- package/agents/examples/record-detail-layout.md +113 -7
- package/agents/examples/signature.md +186 -0
- package/agents/examples/writeform-section.md +1 -0
- package/agents/examples.md +2 -0
- package/agents/features-index.md +4 -0
- package/agents/features.md +14 -0
- package/agents/widgets.md +7 -0
- package/dist/api/request-context-internals.d.ts +2 -0
- package/dist/api/request-context-scopes.js +9 -2
- package/dist/api/request-context.js +1 -1
- package/dist/api/routes.js +4 -4
- package/dist/api/server-event-dispatcher.js +3 -0
- package/dist/api/server-routes.js +2 -0
- package/dist/db/parent-ref-clause.js +31 -3
- package/dist/db/parent-ref-global-hosts.d.ts +4 -1
- package/dist/db/parent-ref-global-hosts.js +50 -12
- package/dist/db/queries/rls-boot-catalog.js +5 -6
- package/dist/db/queries/rls-shape.d.ts +1 -0
- package/dist/db/queries/rls-shape.js +21 -6
- package/dist/db/table-builder.js +3 -1
- package/dist/engine/boot-validator/boot-phases.js +5 -0
- package/dist/engine/boot-validator/boot-rules.d.ts +144 -9
- package/dist/engine/boot-validator/card-meta-overflow-rules.d.ts +2 -2
- package/dist/engine/boot-validator/card-meta-overflow-rules.js +2 -2
- package/dist/engine/boot-validator/card-meta-overflow.js +7 -5
- package/dist/engine/boot-validator/cross-tenant-file-read.d.ts +3 -0
- package/dist/engine/boot-validator/cross-tenant-file-read.js +19 -0
- package/dist/engine/boot-validator/entity-declaration-rules.d.ts +10 -0
- package/dist/engine/boot-validator/entity-declaration-rules.js +10 -0
- package/dist/engine/boot-validator/entity-list-screens.js +2 -7
- package/dist/engine/boot-validator/list-row-guidance-rules.d.ts +17 -2
- package/dist/engine/boot-validator/list-row-guidance-rules.js +17 -2
- package/dist/engine/boot-validator/list-row-guidance.d.ts +7 -0
- package/dist/engine/boot-validator/list-row-guidance.js +45 -1
- package/dist/engine/boot-validator/list-sort-summary-rules.d.ts +2 -2
- package/dist/engine/boot-validator/list-sort-summary-rules.js +2 -2
- package/dist/engine/boot-validator/list-sort-summary.js +31 -20
- package/dist/engine/boot-validator/list-toolbar-options.js +3 -4
- package/dist/engine/boot-validator/named-filter-rules.d.ts +10 -0
- package/dist/engine/boot-validator/named-filter-rules.js +10 -0
- package/dist/engine/boot-validator/projection-list-screens.js +5 -4
- package/dist/engine/boot-validator/query-output-columns.js +18 -0
- package/dist/engine/boot-validator/query-output-guidance.js +3 -0
- package/dist/engine/boot-validator/query-refs.js +14 -1
- package/dist/engine/boot-validator/relative-time-format.d.ts +1 -0
- package/dist/engine/boot-validator/relative-time-format.js +51 -0
- package/dist/engine/boot-validator/screens-actions-rules.d.ts +16 -1
- package/dist/engine/boot-validator/screens-actions-rules.js +16 -1
- package/dist/engine/boot-validator/screens-actions.js +56 -16
- package/dist/engine/boot-validator/screens-dashboard-narrow.d.ts +2 -1
- package/dist/engine/boot-validator/screens-dashboard-narrow.js +43 -4
- package/dist/engine/boot-validator/screens-dashboard-rules.d.ts +12 -2
- package/dist/engine/boot-validator/screens-dashboard-rules.js +12 -2
- package/dist/engine/boot-validator/screens-dashboard.js +2 -1
- package/dist/engine/boot-validator/screens-forms-layout-rules.d.ts +5 -0
- package/dist/engine/boot-validator/screens-forms-layout-rules.js +5 -0
- package/dist/engine/boot-validator/screens-forms-rules.d.ts +60 -0
- package/dist/engine/boot-validator/screens-forms-rules.js +60 -0
- package/dist/engine/boot-validator/screens-forms.d.ts +1 -1
- package/dist/engine/boot-validator/screens-forms.js +108 -2
- package/dist/engine/boot-validator/screens-kind-config-edit.js +1 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail-rules.d.ts +5 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail-rules.js +5 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail.js +30 -0
- package/dist/engine/boot-validator/screens-lists-rules.d.ts +5 -0
- package/dist/engine/boot-validator/screens-lists-rules.js +5 -0
- package/dist/engine/boot-validator/screens-lists.js +4 -1
- package/dist/engine/build-config-feature-schema.js +5 -35
- package/dist/engine/config-access-rules.d.ts +3 -0
- package/dist/engine/config-access-rules.js +34 -0
- package/dist/engine/factories.d.ts +2 -0
- package/dist/engine/named-filter-roles.js +6 -14
- package/dist/engine/project-app-schema-for-roles.js +2 -0
- package/dist/engine/schema-builder.js +3 -1
- package/dist/engine/soft-delete-cleanup.js +2 -0
- package/dist/errors/reasons.d.ts +1 -0
- package/dist/errors/reasons.js +4 -0
- package/dist/files/file-routes.d.ts +2 -0
- package/dist/files/file-routes.js +85 -22
- package/dist/files/foreign-tenant-file-read.d.ts +13 -0
- package/dist/files/foreign-tenant-file-read.js +64 -0
- package/dist/i18n/required-surface-keys.js +28 -7
- package/dist/jobs/job-runner-execution.js +3 -0
- package/dist/jobs/job-runner-types.d.ts +1 -0
- package/dist/jobs/job-runner.js +8 -0
- package/dist/pipeline/context-services.d.ts +1 -1
- package/dist/pipeline/context-services.js +1 -1
- package/dist/pipeline/event-dispatcher-delivery.js +3 -0
- package/dist/pipeline/event-dispatcher.d.ts +2 -0
- package/dist/pipeline/handler-context-phase-denials.js +1 -1
- package/dist/pipeline/irreversible-operation-gate.js +36 -10
- package/dist/search/meilisearch-adapter-internals.d.ts +2 -0
- package/dist/search/meilisearch-adapter-internals.js +5 -0
- package/dist/search/meilisearch-adapter.d.ts +1 -0
- package/dist/search/meilisearch-adapter.js +3 -2
- package/dist/ui-types/card-column-roles.d.ts +2 -0
- package/dist/ui-types/card-column-roles.js +15 -0
- package/dist/ui-types/index.d.ts +2 -2
- package/dist/ui-types/index.js +1 -1
- package/package.json +3 -3
- package/presets/biome-plugins/no-date-api.grit +3 -1
- package/presets/biome-plugins/no-direct-fetch.grit +1 -1
- package/presets/biome-plugins/unsafe-json-parse.grit +7 -1
- package/presets/biome-rules.json +12 -10
- package/src/changes.json +99 -0
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
}
|
|
6
|
-
return access.roles;
|
|
7
|
-
}
|
|
8
|
-
// `roles` on a ref is framework-owned: an authored value is dropped so a screen cannot widen the
|
|
9
|
-
// entity's access rule on the client.
|
|
10
|
-
function refWithEntityRoles(ref, defs) {
|
|
11
|
-
const { roles: _authored, ...plain } = ref;
|
|
1
|
+
// `access` on a ref is framework-owned: an authored value is dropped so a screen cannot widen the
|
|
2
|
+
// entity filter's access rule on the client. A rule is plain data (roles, openToAll), safe to serialize.
|
|
3
|
+
function refWithEntityAccess(ref, defs) {
|
|
4
|
+
const { access: _authored, ...plain } = ref;
|
|
12
5
|
const def = Object.hasOwn(defs, ref.id) ? defs[ref.id] : undefined;
|
|
13
|
-
|
|
14
|
-
return roles === undefined ? plain : { ...plain, roles };
|
|
6
|
+
return def?.access === undefined ? plain : { ...plain, access: def.access };
|
|
15
7
|
}
|
|
16
8
|
export function projectNamedFilterRoles(screen, defs) {
|
|
17
9
|
if (screen.namedFilters === undefined)
|
|
18
10
|
return screen;
|
|
19
11
|
return {
|
|
20
12
|
...screen,
|
|
21
|
-
namedFilters: screen.namedFilters.map((ref) =>
|
|
13
|
+
namedFilters: screen.namedFilters.map((ref) => refWithEntityAccess(ref, defs ?? {})),
|
|
22
14
|
};
|
|
23
15
|
}
|
|
@@ -324,6 +324,8 @@ function projectEditSection(section, feature, indices, keptScreenQns) {
|
|
|
324
324
|
switch (section.kind) {
|
|
325
325
|
case "relatedList":
|
|
326
326
|
return projectRelatedListSection(section, feature, indices, keptScreenQns);
|
|
327
|
+
case "stepList":
|
|
328
|
+
return section;
|
|
327
329
|
case "extension": {
|
|
328
330
|
const { actions, ...rest } = section;
|
|
329
331
|
const kept = projectActionArray(actions, feature, indices, keptScreenQns);
|
|
@@ -347,7 +347,9 @@ export function fieldToZod(field, currencies, opts = {}) {
|
|
|
347
347
|
// validator's; checking it here would require a database round trip during
|
|
348
348
|
// parsing.
|
|
349
349
|
// Multi-mode accepts an array of UUIDs.
|
|
350
|
-
return field.multiple === true
|
|
350
|
+
return field.multiple === true
|
|
351
|
+
? z.array(z.uuid().meta({ references: field.entity }))
|
|
352
|
+
: z.uuid().meta({ references: field.entity });
|
|
351
353
|
default:
|
|
352
354
|
assertUnreachable(field, "field type");
|
|
353
355
|
}
|
|
@@ -167,6 +167,7 @@ export function buildSoftDeleteCleanupJob() {
|
|
|
167
167
|
includeSystemTenant: true,
|
|
168
168
|
concurrency: "skip",
|
|
169
169
|
runIn: "worker",
|
|
170
|
+
irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
|
|
170
171
|
};
|
|
171
172
|
}
|
|
172
173
|
export function buildSoftDeleteCleanupSystemJob() {
|
|
@@ -176,6 +177,7 @@ export function buildSoftDeleteCleanupSystemJob() {
|
|
|
176
177
|
trigger: { maintenance: true },
|
|
177
178
|
concurrency: "skip",
|
|
178
179
|
runIn: "worker",
|
|
180
|
+
irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
|
|
179
181
|
escapeHatch: {
|
|
180
182
|
reason: "hard-deletes expired soft-deleted rows of global entities (e.g. user) once, system-wide",
|
|
181
183
|
grants: ["unsafeRaw"],
|
package/dist/errors/reasons.d.ts
CHANGED
|
@@ -14,6 +14,7 @@ export declare const FrameworkReasons: {
|
|
|
14
14
|
readonly publicIntakeRequired: "public_intake_required";
|
|
15
15
|
readonly irreversibleOperationRequiresHighRisk: "irreversible_operation_requires_high_risk";
|
|
16
16
|
readonly instructionFieldWriteRequiresHighRisk: "instruction_field_write_requires_high_risk";
|
|
17
|
+
readonly irreversibleOperationWithoutEntryHandler: "irreversible_operation_without_entry_handler";
|
|
17
18
|
readonly subjectErased: "subject_erased";
|
|
18
19
|
readonly fileRejected: "file_rejected";
|
|
19
20
|
readonly fileViolatesBindTarget: "file_violates_bind_target";
|
package/dist/errors/reasons.js
CHANGED
|
@@ -65,6 +65,10 @@ export const FrameworkReasons = {
|
|
|
65
65
|
// delegation via ctx.dispatch.write/writeAs from a lower-risk handler does not
|
|
66
66
|
// inherit the gate.
|
|
67
67
|
instructionFieldWriteRequiresHighRisk: "instruction_field_write_requires_high_risk",
|
|
68
|
+
// AccessDeniedError: a job or consumer without a directly dispatched entry handler performs an
|
|
69
|
+
// irreversible operation but declared no irreversibleWithoutEntryHandler exception.
|
|
70
|
+
// details.handler names the job or consumer, details.gate the gate that refused.
|
|
71
|
+
irreversibleOperationWithoutEntryHandler: "irreversible_operation_without_entry_handler",
|
|
68
72
|
// ConflictError: a write touched a personal-data field of a data subject whose
|
|
69
73
|
// key was erased (crypto-shredding); the subject can no longer receive data.
|
|
70
74
|
subjectErased: "subject_erased",
|
|
@@ -4,6 +4,7 @@ import { Hono } from "hono";
|
|
|
4
4
|
import { type ClientIpResolver } from "../api/client-ip.ts";
|
|
5
5
|
import type { DbConnection } from "../db/connection.ts";
|
|
6
6
|
import { type Registry, type SessionUser, type TenantId } from "../engine/types/index.ts";
|
|
7
|
+
import { type ForeignTenantFileReadCheck } from "./foreign-tenant-file-read.ts";
|
|
7
8
|
import type { FileProviderResolver } from "./provider-resolver.ts";
|
|
8
9
|
import type { RecordReadCheck } from "./record-read-check.ts";
|
|
9
10
|
import { type RecordWriteCheck } from "./record-write-check.ts";
|
|
@@ -41,6 +42,7 @@ export type FileRoutesOptions = {
|
|
|
41
42
|
readonly unclaimedUploadReaders?: readonly string[];
|
|
42
43
|
readonly accessGuard?: FileAccessGuard;
|
|
43
44
|
readonly canReadRecord?: RecordReadCheck;
|
|
45
|
+
readonly canReadForeignTenantFile?: ForeignTenantFileReadCheck;
|
|
44
46
|
readonly canWriteRecord?: RecordWriteCheck;
|
|
45
47
|
};
|
|
46
48
|
export declare const ANONYMOUS_UPLOADS_PER_WINDOW = 20;
|
|
@@ -25,6 +25,7 @@ import { isFileSubField } from "./file-field-slots.js";
|
|
|
25
25
|
import { createFileContext, createTenantFileContext } from "./file-handle.js";
|
|
26
26
|
import { fileRefEntity } from "./file-ref-entity.js";
|
|
27
27
|
import { fileRefsTable } from "./file-ref-table.js";
|
|
28
|
+
import { collectCrossTenantFileReadQueries, foreignTenantFileReadDb, } from "./foreign-tenant-file-read.js";
|
|
28
29
|
import { collectRecordOnlyFileEntityTypes } from "./record-only-file-entity-types.js";
|
|
29
30
|
import { isStoredRecordLocked, RecordWriteDecisions, } from "./record-write-check.js";
|
|
30
31
|
import { neutralFileNameForMimeType } from "./resolve-content-type.js";
|
|
@@ -117,6 +118,10 @@ export function createFileRoutes(options) {
|
|
|
117
118
|
// Anonymous visitors share one user id and own no file by it; the check precedes an app's
|
|
118
119
|
// accessGuard so a custom guard cannot reopen reads or deletes between visitors.
|
|
119
120
|
const guard = (args) => isAnonymousSessionUser(args.user) ? "deny" : configuredGuard(args);
|
|
121
|
+
const crossTenantFileReadQueries = options.registry
|
|
122
|
+
? collectCrossTenantFileReadQueries(options.registry)
|
|
123
|
+
: new Map();
|
|
124
|
+
const canReadForeignTenantFile = crossTenantFileReadQueries.size > 0 ? options.canReadForeignTenantFile : undefined;
|
|
120
125
|
const executor = getFileRefExecutor();
|
|
121
126
|
const piiSubjectFields = collectPiiSubjectFields(fileRefEntity);
|
|
122
127
|
const api = new Hono();
|
|
@@ -365,10 +370,11 @@ export function createFileRoutes(options) {
|
|
|
365
370
|
api.get("/files/:id", async (c) => {
|
|
366
371
|
const user = getUser(c);
|
|
367
372
|
const id = c.req.param("id");
|
|
368
|
-
const
|
|
369
|
-
if (!
|
|
373
|
+
const readable = await loadReadableFile(id, user);
|
|
374
|
+
if (!readable)
|
|
370
375
|
return c.json({ error: "not_found" }, 404);
|
|
371
|
-
const
|
|
376
|
+
const { fileRef } = readable;
|
|
377
|
+
const decision = await readDecisionFor(readable, user);
|
|
372
378
|
if (decision === "deny") {
|
|
373
379
|
// 404 rather than 403 so the existence of the file isn't confirmed to
|
|
374
380
|
// an unauthorised caller — matches the tenant-miss response.
|
|
@@ -400,10 +406,11 @@ export function createFileRoutes(options) {
|
|
|
400
406
|
const user = getUser(c);
|
|
401
407
|
const id = c.req.param("id");
|
|
402
408
|
const name = c.req.param("name");
|
|
403
|
-
const
|
|
404
|
-
if (!
|
|
409
|
+
const readable = await loadOwnOrForeignFile(id, user);
|
|
410
|
+
if (!readable)
|
|
405
411
|
return c.json({ error: "not_found" }, 404);
|
|
406
|
-
const
|
|
412
|
+
const { fileRef } = readable;
|
|
413
|
+
const decision = await readDecisionFor(readable, user);
|
|
407
414
|
if (decision === "deny")
|
|
408
415
|
return c.json({ error: "not_found" }, 404);
|
|
409
416
|
// An unknown name and a denied file answer alike, so the route never
|
|
@@ -425,12 +432,12 @@ export function createFileRoutes(options) {
|
|
|
425
432
|
}
|
|
426
433
|
// Built per request: createFileContext caches the resolved provider, so
|
|
427
434
|
// one shared across requests would serve tenant A's store to tenant B.
|
|
428
|
-
const files = createFileContext(() => options.resolveProvider(
|
|
435
|
+
const files = createFileContext(() => options.resolveProvider(fileRef.tenantId), fileRef.tenantId);
|
|
429
436
|
const derivatives = createDerivativesContext({
|
|
430
437
|
files,
|
|
431
438
|
registry,
|
|
432
|
-
db,
|
|
433
|
-
tenantId:
|
|
439
|
+
db: readable.foreign ? foreignTenantFileReadDb(db) : db,
|
|
440
|
+
tenantId: fileRef.tenantId,
|
|
434
441
|
});
|
|
435
442
|
const result = await derivatives.variant(id, spec, name);
|
|
436
443
|
const data = await files.refFromFileRef(result).read();
|
|
@@ -493,10 +500,11 @@ export function createFileRoutes(options) {
|
|
|
493
500
|
api.get("/files/:id/download-url", async (c) => {
|
|
494
501
|
const user = getUser(c);
|
|
495
502
|
const id = c.req.param("id");
|
|
496
|
-
const
|
|
497
|
-
if (!
|
|
503
|
+
const readable = await loadReadableFile(id, user);
|
|
504
|
+
if (!readable)
|
|
498
505
|
return c.json({ error: "not_found" }, 404);
|
|
499
|
-
const
|
|
506
|
+
const { fileRef } = readable;
|
|
507
|
+
const decision = await readDecisionFor(readable, user);
|
|
500
508
|
if (decision === "deny")
|
|
501
509
|
return c.json({ error: "not_found" }, 404);
|
|
502
510
|
// Resolve after access-check: tenant-scoped provider, and capability
|
|
@@ -538,8 +546,8 @@ export function createFileRoutes(options) {
|
|
|
538
546
|
? await executor.detail({ id }, user, tenantDbFor(SYSTEM_TENANT_ID))
|
|
539
547
|
: null);
|
|
540
548
|
if (!row)
|
|
541
|
-
return
|
|
542
|
-
const fileRef = row;
|
|
549
|
+
return loadForeignFileMeta(id, user);
|
|
550
|
+
const fileRef = fileRefOfRow(row);
|
|
543
551
|
// detail()'s "pass"-ownership read widens to tenantId IN (self, SYSTEM),
|
|
544
552
|
// narrower in loadFileForTenant's selectMany. Restore that here so meta
|
|
545
553
|
// doesn't leak reference-tenant rows.
|
|
@@ -549,6 +557,21 @@ export function createFileRoutes(options) {
|
|
|
549
557
|
const decision = await guard({ fileRef, user, operation: "read" });
|
|
550
558
|
if (decision === "deny")
|
|
551
559
|
return null;
|
|
560
|
+
return metaOf(fileRef);
|
|
561
|
+
}
|
|
562
|
+
// The foreign file is located and authorized first; only then is it decrypted through detail()
|
|
563
|
+
// in the file's own tenant.
|
|
564
|
+
async function loadForeignFileMeta(id, user) {
|
|
565
|
+
const readable = await loadForeignFile(id, user);
|
|
566
|
+
if (!readable || (await readDecisionFor(readable, user)) === "deny")
|
|
567
|
+
return null;
|
|
568
|
+
const row = await executor.detail({ id }, user, tenantDbFor(readable.fileRef.tenantId));
|
|
569
|
+
return row ? metaOf(fileRefOfRow(row)) : null;
|
|
570
|
+
}
|
|
571
|
+
function fileRefOfRow(row) {
|
|
572
|
+
return row; // @cast-boundary db-row (file_refs rows, decrypted where read via executor.detail)
|
|
573
|
+
}
|
|
574
|
+
function metaOf(fileRef) {
|
|
552
575
|
return {
|
|
553
576
|
id: fileRef.id,
|
|
554
577
|
fileName: fileRef.fileName,
|
|
@@ -563,14 +586,54 @@ export function createFileRoutes(options) {
|
|
|
563
586
|
const meta = await loadReadableFileMeta(c.req.param("id"), getUser(c));
|
|
564
587
|
return meta ? c.json(meta) : c.json({ error: "not_found" }, 404);
|
|
565
588
|
});
|
|
566
|
-
// Read-only
|
|
567
|
-
//
|
|
568
|
-
//
|
|
569
|
-
|
|
589
|
+
// Read-only crossings: SYSTEM_TENANT_ID files (e.g. helpdesk attachments) are visible to a
|
|
590
|
+
// SystemAdmin whose session sits in another tenant, and files of entities that declare
|
|
591
|
+
// crossTenantFileRead to users their query admits. Delete and upload keep using
|
|
592
|
+
// loadFileForTenant and stay tenant-equal.
|
|
593
|
+
async function loadReadableFile(id, user) {
|
|
570
594
|
const own = await loadFileForTenant(id, user.tenantId);
|
|
571
|
-
if (own
|
|
572
|
-
return own;
|
|
573
|
-
|
|
595
|
+
if (own)
|
|
596
|
+
return { fileRef: own, foreign: false };
|
|
597
|
+
if (canReadSystemTenantFile(user, SYSTEM_TENANT_ID)) {
|
|
598
|
+
const system = await loadFileForTenant(id, SYSTEM_TENANT_ID, systemTenantReadDb(db));
|
|
599
|
+
if (system)
|
|
600
|
+
return { fileRef: system, foreign: false };
|
|
601
|
+
}
|
|
602
|
+
return loadForeignFile(id, user);
|
|
603
|
+
}
|
|
604
|
+
async function loadOwnOrForeignFile(id, user) {
|
|
605
|
+
const own = await loadFileForTenant(id, user.tenantId);
|
|
606
|
+
return own ? { fileRef: own, foreign: false } : loadForeignFile(id, user);
|
|
607
|
+
}
|
|
608
|
+
// Located across tenants only for declared entity types; whether the user may read it is decided
|
|
609
|
+
// by readDecisionFor, so a caller that skips it must not hand the file out.
|
|
610
|
+
async function loadForeignFile(id, user) {
|
|
611
|
+
if (canReadForeignTenantFile === undefined || isAnonymousSessionUser(user))
|
|
612
|
+
return null;
|
|
613
|
+
if (!isUuid(id))
|
|
614
|
+
return null;
|
|
615
|
+
const [row] = await selectMany(foreignTenantFileReadDb(db), fileRefsTable, {
|
|
616
|
+
id,
|
|
617
|
+
isDeleted: false,
|
|
618
|
+
});
|
|
619
|
+
const fileRef = row === undefined ? undefined : fileRefOfRow(row);
|
|
620
|
+
if (fileRef === undefined ||
|
|
621
|
+
fileRef.tenantId === user.tenantId ||
|
|
622
|
+
fileRef.entityType === null ||
|
|
623
|
+
fileRef.entityId === null ||
|
|
624
|
+
!crossTenantFileReadQueries.has(fileRef.entityType)) {
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
return { fileRef, foreign: true };
|
|
628
|
+
}
|
|
629
|
+
// A foreign tenant's file is decided by the declared query alone: the guard's privilegedRoles
|
|
630
|
+
// would otherwise hand it to any admin of any tenant.
|
|
631
|
+
async function readDecisionFor({ fileRef, foreign }, user) {
|
|
632
|
+
if (!foreign)
|
|
633
|
+
return guard({ fileRef, user, operation: "read" });
|
|
634
|
+
if (canReadForeignTenantFile === undefined || isAnonymousSessionUser(user))
|
|
635
|
+
return "deny";
|
|
636
|
+
return (await canReadForeignTenantFile({ fileRef, user })) ? "allow" : "deny";
|
|
574
637
|
}
|
|
575
638
|
async function loadFileForTenant(id, tenantId, readDb = db) {
|
|
576
639
|
// fileRefsTable.id is a UUID column — a malformed id must fail here, not
|
|
@@ -582,7 +645,7 @@ export function createFileRoutes(options) {
|
|
|
582
645
|
// isDeleted:false — soft-deleted (trashed) rows stay recoverable but must
|
|
583
646
|
// never surface to reads/guards.
|
|
584
647
|
const [row] = await selectMany(readDb, fileRefsTable, { id, tenantId, isDeleted: false });
|
|
585
|
-
return row
|
|
648
|
+
return row === undefined ? null : fileRefOfRow(row);
|
|
586
649
|
}
|
|
587
650
|
return api;
|
|
588
651
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TenantDb } from "@cosmicdrift/kumiko-types/tenant-db-types";
|
|
2
|
+
import type { DbConnection } from "../db/connection.ts";
|
|
3
|
+
import type { Registry, SessionUser } from "../engine/types/index.ts";
|
|
4
|
+
import type { FileRef } from "./file-routes.ts";
|
|
5
|
+
export type ForeignTenantFileReadCheck = (args: {
|
|
6
|
+
readonly fileRef: FileRef;
|
|
7
|
+
readonly user: SessionUser;
|
|
8
|
+
}) => Promise<boolean>;
|
|
9
|
+
type QueryAsUser = (type: string, payload: unknown, user: SessionUser) => Promise<unknown>;
|
|
10
|
+
export declare function collectCrossTenantFileReadQueries(registry: Registry): ReadonlyMap<string, string>;
|
|
11
|
+
export declare function createForeignTenantFileReadCheck(registry: Registry, query: QueryAsUser): ForeignTenantFileReadCheck;
|
|
12
|
+
export declare function foreignTenantFileReadDb(db: DbConnection): TenantDb;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
2
|
+
import { createTenantDb } from "../db/tenant-db.js";
|
|
3
|
+
import { SYSTEM_TENANT_ID } from "../engine/types/index.js";
|
|
4
|
+
import { isKumikoError } from "../errors/index.js";
|
|
5
|
+
import { createFallbackLogger } from "../logging/index.js";
|
|
6
|
+
const log = createFallbackLogger("files");
|
|
7
|
+
const cache = new WeakMap();
|
|
8
|
+
// Event-sourced read models (projection entities) are not in getAllEntities, so both sources count.
|
|
9
|
+
export function collectCrossTenantFileReadQueries(registry) {
|
|
10
|
+
const cached = cache.get(registry);
|
|
11
|
+
if (cached)
|
|
12
|
+
return cached;
|
|
13
|
+
const queryByEntityType = new Map();
|
|
14
|
+
for (const [name, entity] of registry.getAllEntities()) {
|
|
15
|
+
if (entity.crossTenantFileRead)
|
|
16
|
+
queryByEntityType.set(name, entity.crossTenantFileRead.query);
|
|
17
|
+
}
|
|
18
|
+
for (const projection of registry.getAllProjections().values()) {
|
|
19
|
+
const name = projection.source;
|
|
20
|
+
if (typeof name !== "string")
|
|
21
|
+
continue;
|
|
22
|
+
const declaration = registry.getReadModelEntity(name)?.crossTenantFileRead;
|
|
23
|
+
if (declaration)
|
|
24
|
+
queryByEntityType.set(name, declaration.query);
|
|
25
|
+
}
|
|
26
|
+
cache.set(registry, queryByEntityType);
|
|
27
|
+
return queryByEntityType;
|
|
28
|
+
}
|
|
29
|
+
// The declared query runs as the requesting user, so its own access and visibility rules decide.
|
|
30
|
+
// Only a record carrying the requested id counts; null, other shapes and access errors mean no; the caller's own guard never applies to a foreign tenant's file.
|
|
31
|
+
export function createForeignTenantFileReadCheck(registry, query) {
|
|
32
|
+
return async ({ fileRef, user }) => {
|
|
33
|
+
const { entityType, entityId } = fileRef;
|
|
34
|
+
if (entityType === null || entityId === null)
|
|
35
|
+
return false;
|
|
36
|
+
const queryQn = collectCrossTenantFileReadQueries(registry).get(entityType);
|
|
37
|
+
if (queryQn === undefined)
|
|
38
|
+
return false;
|
|
39
|
+
try {
|
|
40
|
+
const record = await query(queryQn, { id: entityId }, user);
|
|
41
|
+
return propertyOf(record, "id") === entityId;
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (!isKumikoError(error) || error.httpStatus >= 500) {
|
|
45
|
+
log.error("cross-tenant file read check failed; file access denied", {
|
|
46
|
+
entityType,
|
|
47
|
+
queryQn,
|
|
48
|
+
error: error instanceof Error ? error.message : String(error),
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
// Reads file_refs rows of every tenant, never writes; callers narrow to declared entity types.
|
|
56
|
+
export function foreignTenantFileReadDb(db) {
|
|
57
|
+
return createTenantDb({
|
|
58
|
+
db,
|
|
59
|
+
tenantId: SYSTEM_TENANT_ID,
|
|
60
|
+
mode: "system",
|
|
61
|
+
reason: "cross-tenant file read of entities that declare crossTenantFileRead",
|
|
62
|
+
grants: { writesDeniedReason: "on the cross-tenant file read handle" },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
@@ -73,6 +73,9 @@ function pushEditFieldTextKeys(out, spec, treatAsKey = false) {
|
|
|
73
73
|
pushKey(out, affix, treatAsKey);
|
|
74
74
|
}
|
|
75
75
|
pushKey(out, spec.fillAction?.label, treatAsKey);
|
|
76
|
+
for (const chip of spec.aiAssist?.chips ?? [])
|
|
77
|
+
pushKey(out, chip.label, treatAsKey);
|
|
78
|
+
pushKey(out, spec.aiAssist?.prompt?.placeholder, treatAsKey);
|
|
76
79
|
}
|
|
77
80
|
// Group titles are translated exactly like the section title (computeEditViewModel).
|
|
78
81
|
function pushSectionTitles(out, section, treatAsKey = false) {
|
|
@@ -91,7 +94,7 @@ function pushActionFormShapedKeys(out, featureName, step) {
|
|
|
91
94
|
pushKey(out, section.title);
|
|
92
95
|
continue;
|
|
93
96
|
}
|
|
94
|
-
if (section.kind === "relatedList")
|
|
97
|
+
if (section.kind === "relatedList" || section.kind === "stepList")
|
|
95
98
|
continue; // rejected at boot, unreachable here
|
|
96
99
|
pushSectionTitles(out, section);
|
|
97
100
|
for (const f of sectionFieldSpecs(section)) {
|
|
@@ -108,8 +111,9 @@ function pushRowActionKeys(out, action) {
|
|
|
108
111
|
pushKey(out, action.confirm);
|
|
109
112
|
pushKey(out, action.confirmLabel);
|
|
110
113
|
}
|
|
111
|
-
if (action.kind === "clientAction")
|
|
114
|
+
if (action.kind === "clientAction" && action.successMessage !== false) {
|
|
112
115
|
pushKey(out, action.successMessage);
|
|
116
|
+
}
|
|
113
117
|
if (action.kind === "drawer") {
|
|
114
118
|
pushKey(out, action.title);
|
|
115
119
|
pushKey(out, action.subtitle);
|
|
@@ -251,10 +255,13 @@ function pushExpandableRowKeys(out, section) {
|
|
|
251
255
|
pushRowActionKeys(out, section.emptyState.action);
|
|
252
256
|
}
|
|
253
257
|
}
|
|
258
|
+
function fieldTextRefKey(ref) {
|
|
259
|
+
return typeof ref === "string" ? ref : ref.key;
|
|
260
|
+
}
|
|
254
261
|
function pushFieldLabelOrOverrideKey(ctx, labelEntity, fieldName, fieldLabels, treatAsKey = false) {
|
|
255
262
|
const override = fieldLabels?.[fieldName];
|
|
256
263
|
if (override !== undefined)
|
|
257
|
-
pushKey(ctx.out, override, treatAsKey);
|
|
264
|
+
pushKey(ctx.out, fieldTextRefKey(override), treatAsKey);
|
|
258
265
|
else
|
|
259
266
|
ctx.out.add(fieldLabelKey(ctx.featureName, labelEntity, fieldName));
|
|
260
267
|
}
|
|
@@ -304,7 +311,7 @@ function pushEditLayoutSectionKeys(ctx, sections, labelEntity, fieldLabels) {
|
|
|
304
311
|
pushKey(ctx.out, section.title);
|
|
305
312
|
continue;
|
|
306
313
|
}
|
|
307
|
-
if (section.kind === "relatedList")
|
|
314
|
+
if (section.kind === "relatedList" || section.kind === "stepList")
|
|
308
315
|
continue; // rejected at boot, unreachable here
|
|
309
316
|
pushSectionTitles(ctx.out, section);
|
|
310
317
|
for (const f of sectionFieldSpecs(section)) {
|
|
@@ -324,6 +331,12 @@ function collectActionFormKeys(ctx, form) {
|
|
|
324
331
|
pushKey(ctx.out, form.summary?.subtitle);
|
|
325
332
|
for (const action of form.footerActions ?? [])
|
|
326
333
|
pushKey(ctx.out, action.label);
|
|
334
|
+
for (const ref of Object.values(form.fieldDescriptions ?? {})) {
|
|
335
|
+
pushKey(ctx.out, fieldTextRefKey(ref));
|
|
336
|
+
}
|
|
337
|
+
pushKey(ctx.out, form.infoBand);
|
|
338
|
+
for (const badge of Object.values(form.fieldBadges ?? {}))
|
|
339
|
+
pushKey(ctx.out, badge.label);
|
|
327
340
|
for (const link of form.successLinks ?? [])
|
|
328
341
|
pushKey(ctx.out, link.label);
|
|
329
342
|
for (const fact of form.successFacts ?? [])
|
|
@@ -358,7 +371,7 @@ function pushConfigEditSectionKeys(ctx, config) {
|
|
|
358
371
|
pushKey(out, section.title);
|
|
359
372
|
continue;
|
|
360
373
|
}
|
|
361
|
-
if (section.kind === "relatedList")
|
|
374
|
+
if (section.kind === "relatedList" || section.kind === "stepList")
|
|
362
375
|
continue; // rejected at boot, unreachable here
|
|
363
376
|
pushSectionTitles(out, section, treatDotFormAsKey);
|
|
364
377
|
pushKey(out, section.description, treatDotFormAsKey);
|
|
@@ -414,6 +427,10 @@ function collectProjectionDetailKeys(ctx, detail) {
|
|
|
414
427
|
pushKey(ctx.out, bulk.confirm);
|
|
415
428
|
continue;
|
|
416
429
|
}
|
|
430
|
+
if (section.kind === "stepList") {
|
|
431
|
+
pushKey(ctx.out, section.title);
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
417
434
|
if (isWriteFormEditSection(section)) {
|
|
418
435
|
pushWriteFormSectionKeys(ctx, section);
|
|
419
436
|
continue;
|
|
@@ -541,7 +558,8 @@ export function buildEffectiveTranslationKeys(features) {
|
|
|
541
558
|
function hasLocaleValue(value) {
|
|
542
559
|
if (value === undefined)
|
|
543
560
|
return false;
|
|
544
|
-
|
|
561
|
+
const forms = typeof value === "string" ? [value] : Object.values(value);
|
|
562
|
+
return forms.every((form) => form.trim() !== "");
|
|
545
563
|
}
|
|
546
564
|
/**
|
|
547
565
|
* Per feature, every translation key must carry every locale that any key of the
|
|
@@ -678,8 +696,11 @@ export function fieldValueTranslationKeysFromFeature(feature) {
|
|
|
678
696
|
if (!entity)
|
|
679
697
|
continue;
|
|
680
698
|
for (const section of screen.layout.sections) {
|
|
681
|
-
if (isExtensionEditSection(section) ||
|
|
699
|
+
if (isExtensionEditSection(section) ||
|
|
700
|
+
section.kind === "relatedList" ||
|
|
701
|
+
section.kind === "stepList") {
|
|
682
702
|
continue;
|
|
703
|
+
}
|
|
683
704
|
for (const spec of sectionFieldSpecs(section)) {
|
|
684
705
|
const field = editFieldName(spec);
|
|
685
706
|
const def = entity.fields[field];
|
|
@@ -41,6 +41,9 @@ async function runJobHandler(scope, run, correlation) {
|
|
|
41
41
|
handler: run.jobName,
|
|
42
42
|
feature: scope.registry.getJobFeature(run.jobName) ?? qnScope(run.jobName),
|
|
43
43
|
writeOrigin: run.writeOrigin,
|
|
44
|
+
...(run.jobDef.irreversibleWithoutEntryHandler && {
|
|
45
|
+
irreversibleWithoutEntryHandler: run.jobDef.irreversibleWithoutEntryHandler,
|
|
46
|
+
}),
|
|
44
47
|
tenantId: run.tenantId,
|
|
45
48
|
...(run.triggeredById !== null && { userId: run.triggeredById }),
|
|
46
49
|
}, async () => run.jobDef.handler(run.payload, {
|
|
@@ -48,6 +48,7 @@ export type JobRunner = {
|
|
|
48
48
|
handleCatchUpEvent(jobName: string, eventName: string, payload: Record<string, unknown>, user: SessionUser, triggerEvent: JobTriggerEvent): Promise<void>;
|
|
49
49
|
attachDispatcher(ref: DispatchWriteRef): void;
|
|
50
50
|
countPendingJobs(): Promise<number>;
|
|
51
|
+
isJobPending?(jobName: string, jobId: string): Promise<boolean>;
|
|
51
52
|
};
|
|
52
53
|
export type JobRunnerOptions = {
|
|
53
54
|
registry: Registry;
|
package/dist/jobs/job-runner.js
CHANGED
|
@@ -571,6 +571,14 @@ export function createJobRunner(options) {
|
|
|
571
571
|
attachDispatcher(ref) {
|
|
572
572
|
dispatchWriteRef = ref;
|
|
573
573
|
},
|
|
574
|
+
async isJobPending(jobName, jobId) {
|
|
575
|
+
const jobDef = allJobs.get(jobName);
|
|
576
|
+
if (!jobDef) {
|
|
577
|
+
throw new Error(`Unknown job: ${jobName}`);
|
|
578
|
+
}
|
|
579
|
+
const state = await queues[laneForJob(jobDef)].getJobState(jobId);
|
|
580
|
+
return state !== "completed" && state !== "failed" && state !== "unknown";
|
|
581
|
+
},
|
|
574
582
|
async countPendingJobs() {
|
|
575
583
|
let total = 0;
|
|
576
584
|
for (const queue of Object.values(queues)) {
|
|
@@ -20,7 +20,7 @@ export declare const APP_CONTEXT_KEY_ROLES: {
|
|
|
20
20
|
readonly _notifyFactory: "service";
|
|
21
21
|
readonly _notifyInTransactionFactory: "service";
|
|
22
22
|
readonly _notifyAfterCommitFactory: "service";
|
|
23
|
-
readonly _deliveryAttemptLogFactory: "
|
|
23
|
+
readonly _deliveryAttemptLogFactory: "wiring";
|
|
24
24
|
readonly _logOwnDeliveryAttempt: "service";
|
|
25
25
|
readonly _escapeHatchAuditSink: "service";
|
|
26
26
|
readonly db: "wiring";
|
|
@@ -20,7 +20,7 @@ export const APP_CONTEXT_KEY_ROLES = {
|
|
|
20
20
|
_notifyFactory: "service",
|
|
21
21
|
_notifyInTransactionFactory: "service",
|
|
22
22
|
_notifyAfterCommitFactory: "service",
|
|
23
|
-
_deliveryAttemptLogFactory: "
|
|
23
|
+
_deliveryAttemptLogFactory: "wiring",
|
|
24
24
|
_logOwnDeliveryAttempt: "service",
|
|
25
25
|
_escapeHatchAuditSink: "service",
|
|
26
26
|
db: "wiring",
|
|
@@ -350,6 +350,9 @@ function buildConsumerRequestScope(consumer, causationSource) {
|
|
|
350
350
|
handler: consumer.name,
|
|
351
351
|
feature: consumer.featureName ?? qnScope(consumer.name),
|
|
352
352
|
writeOrigin,
|
|
353
|
+
...(consumer.irreversibleWithoutEntryHandler && {
|
|
354
|
+
irreversibleWithoutEntryHandler: consumer.irreversibleWithoutEntryHandler,
|
|
355
|
+
}),
|
|
353
356
|
};
|
|
354
357
|
}
|
|
355
358
|
async function applyEvent(consumer, row, context) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { IrreversibleWithoutEntryHandler } from "@cosmicdrift/kumiko-types/config";
|
|
1
2
|
import type { Meter, Tracer } from "@cosmicdrift/kumiko-types/observability";
|
|
2
3
|
import type { PgListenClient } from "../db/connection.ts";
|
|
3
4
|
import type { AppContext } from "../engine/types/index.ts";
|
|
@@ -22,6 +23,7 @@ export type EventConsumer = {
|
|
|
22
23
|
readonly featureName?: string;
|
|
23
24
|
readonly delivery?: "shared" | "per-instance";
|
|
24
25
|
readonly startFrom?: "beginning" | "now";
|
|
26
|
+
readonly irreversibleWithoutEntryHandler?: IrreversibleWithoutEntryHandler;
|
|
25
27
|
};
|
|
26
28
|
export type DispatcherPassResult = {
|
|
27
29
|
readonly processed: number;
|
|
@@ -87,7 +87,7 @@ export function denyTransactionBoundSurfaces(handlerContext) {
|
|
|
87
87
|
// A notify factory builds a working notify, so a phase that denies ctx.notify must drop them too,
|
|
88
88
|
// along with the delivery attempt log that belongs to a delivery.
|
|
89
89
|
export function withoutNotifyFactories(services) {
|
|
90
|
-
const { _notifyFactory: _factory, _notifyInTransactionFactory: _inTransaction, _notifyAfterCommitFactory: _afterCommit,
|
|
90
|
+
const { _notifyFactory: _factory, _notifyInTransactionFactory: _inTransaction, _notifyAfterCommitFactory: _afterCommit, _logOwnDeliveryAttempt: _ownAttemptLog, ...rest } = services;
|
|
91
91
|
return rest;
|
|
92
92
|
}
|
|
93
93
|
// The beforeTransaction phase has no write need at all, so it also loses the outside-transaction
|