@cosmicdrift/kumiko-framework 0.405.0 → 0.409.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-db.md +1 -0
- package/agents/api/framework-engine.md +18 -2
- package/agents/api/framework-ui-types.md +15 -0
- package/agents/api/renderer-web.md +156 -2
- package/agents/api/types.md +113 -71
- package/agents/api.md +4 -4
- package/agents/boot-rules.md +743 -0
- package/agents/examples/contact.md +167 -0
- package/agents/examples/delivery-notifications.md +34 -1
- package/agents/examples/lane-routing.md +13 -0
- package/agents/examples/record-detail-layout.md +13 -2
- package/agents/examples/search.md +65 -3
- package/agents/examples/secrets-demo.md +96 -2
- package/agents/examples/tenant-inactivity.md +138 -0
- package/agents/examples.md +2 -0
- package/agents/features-index.md +4 -0
- package/agents/features.md +24 -1
- package/agents/widgets.md +12 -1
- package/dist/api/export/export-rows.js +1 -0
- package/dist/compliance/index.d.ts +1 -1
- package/dist/db/event-store-executor-read-where.js +15 -5
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +1 -1
- package/dist/db/migrate-generator.js +3 -1
- package/dist/db/queries/event-consumer.js +11 -7
- package/dist/db/queries/event-store.d.ts +2 -1
- package/dist/db/queries/event-store.js +25 -6
- package/dist/db/queries/rls-boot-catalog.js +3 -1
- package/dist/db/queries/session-advisory-lock.d.ts +7 -0
- package/dist/db/queries/session-advisory-lock.js +23 -0
- package/dist/db/query.js +7 -10
- package/dist/db/row-level-security-connection.js +4 -2
- package/dist/engine/active-membership.js +1 -0
- package/dist/engine/boot-validator/access-declarations.js +57 -33
- package/dist/engine/boot-validator/action-wiring.js +8 -6
- package/dist/engine/boot-validator/agent-effect-rules.d.ts +12 -0
- package/dist/engine/boot-validator/agent-effect-rules.js +12 -0
- package/dist/engine/boot-validator/agent-effect.d.ts +2 -0
- package/dist/engine/boot-validator/agent-effect.js +20 -0
- package/dist/engine/boot-validator/boot-context.js +5 -1
- package/dist/engine/boot-validator/boot-environment-rules.d.ts +12 -0
- package/dist/engine/boot-validator/boot-environment-rules.js +12 -0
- package/dist/engine/boot-validator/boot-phases-app.js +5 -1
- package/dist/engine/boot-validator/boot-phases.js +3 -1
- package/dist/engine/boot-validator/boot-rules.d.ts +2619 -0
- package/dist/engine/boot-validator/boot-rules.js +58 -0
- package/dist/engine/boot-validator/bundled-lists-table.js +23 -9
- package/dist/engine/boot-validator/config-deps.js +71 -23
- package/dist/engine/boot-validator/config-edit-action-rules.d.ts +17 -0
- package/dist/engine/boot-validator/config-edit-action-rules.js +17 -0
- package/dist/engine/boot-validator/config-key-rules.d.ts +117 -0
- package/dist/engine/boot-validator/config-key-rules.js +117 -0
- package/dist/engine/boot-validator/custom-screen-write-qns.js +6 -2
- package/dist/engine/boot-validator/derived-sql-fields-rules.d.ts +77 -0
- package/dist/engine/boot-validator/derived-sql-fields-rules.js +77 -0
- package/dist/engine/boot-validator/derived-sql-fields.js +53 -17
- package/dist/engine/boot-validator/detail-screens.js +10 -4
- package/dist/engine/boot-validator/entity-declaration-rules.d.ts +92 -0
- package/dist/engine/boot-validator/entity-declaration-rules.js +92 -0
- package/dist/engine/boot-validator/entity-handler-access-rules.d.ts +102 -0
- package/dist/engine/boot-validator/entity-handler-access-rules.js +102 -0
- package/dist/engine/boot-validator/entity-handler.d.ts +0 -7
- package/dist/engine/boot-validator/entity-handler.js +259 -355
- package/dist/engine/boot-validator/entity-image-variants.d.ts +2 -0
- package/dist/engine/boot-validator/entity-image-variants.js +91 -0
- package/dist/engine/boot-validator/entity-list-aggregate-options.js +8 -2
- package/dist/engine/boot-validator/entity-reference-embedded-rules.d.ts +117 -0
- package/dist/engine/boot-validator/entity-reference-embedded-rules.js +117 -0
- package/dist/engine/boot-validator/entity-select-image-rules.d.ts +122 -0
- package/dist/engine/boot-validator/entity-select-image-rules.js +122 -0
- package/dist/engine/boot-validator/entity-select.d.ts +8 -0
- package/dist/engine/boot-validator/entity-select.js +197 -0
- package/dist/engine/boot-validator/entity-structure-rules.d.ts +107 -0
- package/dist/engine/boot-validator/entity-structure-rules.js +107 -0
- package/dist/engine/boot-validator/field-conditions-rules.d.ts +92 -0
- package/dist/engine/boot-validator/field-conditions-rules.js +92 -0
- package/dist/engine/boot-validator/field-conditions.js +67 -22
- package/dist/engine/boot-validator/form-derivations-rules.d.ts +77 -0
- package/dist/engine/boot-validator/form-derivations-rules.js +77 -0
- package/dist/engine/boot-validator/form-derivations.js +52 -18
- package/dist/engine/boot-validator/global-tenancy.js +13 -7
- package/dist/engine/boot-validator/handler-declaration-rules.d.ts +72 -0
- package/dist/engine/boot-validator/handler-declaration-rules.js +72 -0
- package/dist/engine/boot-validator/handler-field-references-rules.d.ts +22 -0
- package/dist/engine/boot-validator/handler-field-references-rules.js +22 -0
- package/dist/engine/boot-validator/handler-field-references.js +14 -6
- package/dist/engine/boot-validator/list-bulk-actions-rules.d.ts +42 -0
- package/dist/engine/boot-validator/list-bulk-actions-rules.js +42 -0
- package/dist/engine/boot-validator/list-bulk-actions.js +29 -11
- package/dist/engine/boot-validator/list-column-layout.js +22 -10
- package/dist/engine/boot-validator/list-query-rules.d.ts +107 -0
- package/dist/engine/boot-validator/list-query-rules.js +107 -0
- package/dist/engine/boot-validator/list-table-aggregate-options.js +43 -15
- package/dist/engine/boot-validator/list-table-aggregate-query.js +7 -3
- package/dist/engine/boot-validator/list-table-aggregate-rules.d.ts +82 -0
- package/dist/engine/boot-validator/list-table-aggregate-rules.js +82 -0
- package/dist/engine/boot-validator/list-table-export-options.js +19 -7
- package/dist/engine/boot-validator/list-table-options.js +33 -13
- package/dist/engine/boot-validator/list-table-reject-unknown-keys.js +6 -2
- package/dist/engine/boot-validator/list-table-rules.d.ts +132 -0
- package/dist/engine/boot-validator/list-table-rules.js +132 -0
- package/dist/engine/boot-validator/nav-rules.d.ts +42 -0
- package/dist/engine/boot-validator/nav-rules.js +42 -0
- package/dist/engine/boot-validator/nav.js +29 -15
- package/dist/engine/boot-validator/ownership-rules.d.ts +27 -0
- package/dist/engine/boot-validator/ownership-rules.js +27 -0
- package/dist/engine/boot-validator/ownership.js +28 -12
- package/dist/engine/boot-validator/parent-ref.js +32 -20
- package/dist/engine/boot-validator/projection-list-screens.js +76 -35
- package/dist/engine/boot-validator/query-output-columns.js +9 -3
- package/dist/engine/boot-validator/query-refs.js +20 -10
- package/dist/engine/boot-validator/query-rules.d.ts +37 -0
- package/dist/engine/boot-validator/query-rules.js +37 -0
- package/dist/engine/boot-validator/read-gate.js +14 -10
- package/dist/engine/boot-validator/record-owned.js +5 -1
- package/dist/engine/boot-validator/related-list-table-rules.js +17 -7
- package/dist/engine/boot-validator/screens-actions-rules.d.ts +185 -0
- package/dist/engine/boot-validator/screens-actions-rules.js +185 -0
- package/dist/engine/boot-validator/screens-actions.js +169 -93
- package/dist/engine/boot-validator/screens-dashboard-chart-rules.d.ts +87 -0
- package/dist/engine/boot-validator/screens-dashboard-chart-rules.js +87 -0
- package/dist/engine/boot-validator/screens-dashboard-rules.d.ts +227 -0
- package/dist/engine/boot-validator/screens-dashboard-rules.js +227 -0
- package/dist/engine/boot-validator/screens-dashboard.js +222 -85
- package/dist/engine/boot-validator/screens-forms-layout-rules.d.ts +122 -0
- package/dist/engine/boot-validator/screens-forms-layout-rules.js +122 -0
- package/dist/engine/boot-validator/screens-forms-rules.d.ts +152 -0
- package/dist/engine/boot-validator/screens-forms-rules.js +152 -0
- package/dist/engine/boot-validator/screens-forms.js +240 -112
- package/dist/engine/boot-validator/screens-kind-config-edit.js +72 -16
- package/dist/engine/boot-validator/screens-kind-entity-edit.js +15 -7
- package/dist/engine/boot-validator/screens-kind-entity-list.js +57 -32
- package/dist/engine/boot-validator/screens-kind-projection-detail-rules.d.ts +92 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail-rules.js +92 -0
- package/dist/engine/boot-validator/screens-kind-projection-detail.js +85 -47
- package/dist/engine/boot-validator/screens-kind-rules.d.ts +137 -0
- package/dist/engine/boot-validator/screens-kind-rules.js +137 -0
- package/dist/engine/boot-validator/screens-kind-secret-mint.js +18 -8
- package/dist/engine/boot-validator/screens-kind-shared.js +40 -22
- package/dist/engine/boot-validator/screens-lists-rules.d.ts +82 -0
- package/dist/engine/boot-validator/screens-lists-rules.js +82 -0
- package/dist/engine/boot-validator/screens-lists.js +90 -45
- package/dist/engine/boot-validator/screens-rules.d.ts +57 -0
- package/dist/engine/boot-validator/screens-rules.js +57 -0
- package/dist/engine/boot-validator/screens.js +17 -12
- package/dist/engine/boot-validator/transaction-phases.js +12 -4
- package/dist/engine/boot-validator/transfer-graph.js +17 -11
- package/dist/engine/boot-validator/url-prefill-fields.js +9 -5
- package/dist/engine/boot-validator/workspaces.js +11 -5
- package/dist/engine/boot-validator/zod-shape.js +6 -2
- package/dist/engine/entity-handlers.d.ts +1 -0
- package/dist/engine/entity-handlers.js +3 -0
- package/dist/engine/entity-list-runtime-options.js +23 -29
- package/dist/engine/extensions/tenant-data.d.ts +3 -0
- package/dist/engine/extensions/tenant-resource.d.ts +1 -0
- package/dist/engine/factories.d.ts +1 -1
- package/dist/engine/factories.js +4 -3
- package/dist/engine/feature-config-events-jobs.js +7 -0
- package/dist/engine/index.d.ts +4 -2
- package/dist/engine/index.js +2 -0
- package/dist/engine/project-app-schema-for-roles.js +29 -14
- package/dist/engine/registry-facade.js +7 -8
- package/dist/engine/registry-validate.js +5 -1
- package/dist/engine/soft-delete-cleanup.d.ts +1 -0
- package/dist/engine/soft-delete-cleanup.js +5 -0
- package/dist/engine/steps/describe-workflow-step-error.js +1 -0
- package/dist/es-ops/operations-schema.d.ts +1 -1
- package/dist/event-store/ensure-dead-letter-table.d.ts +2 -0
- package/dist/event-store/ensure-dead-letter-table.js +10 -0
- package/dist/event-store/rebuild-dead-letter.js +2 -8
- package/dist/event-store/upcaster-dead-letter.js +2 -8
- package/dist/files/copy-pending-file-refs-to-tenant.d.ts +28 -0
- package/dist/files/copy-pending-file-refs-to-tenant.js +87 -0
- package/dist/files/file-routes.d.ts +1 -1
- package/dist/files/file-routes.js +21 -6
- package/dist/files/index.d.ts +2 -0
- package/dist/files/index.js +1 -0
- package/dist/i18n/required-surface-keys.js +1 -0
- package/dist/jobs/job-runner-helpers.js +1 -0
- package/dist/jobs/job-runner-schedulers.d.ts +2 -2
- package/dist/jobs/job-runner-schedulers.js +8 -4
- package/dist/jobs/job-runner.js +14 -16
- package/dist/logging/utils.js +30 -60
- package/dist/observability/metrics-handle.js +10 -21
- package/dist/pipeline/cascade-handler.js +7 -6
- package/dist/pipeline/dispatch-query.js +18 -5
- package/dist/pipeline/dispatch-shared.d.ts +1 -0
- package/dist/pipeline/dispatch-shared.js +3 -1
- package/dist/pipeline/dispatch-write.js +10 -12
- package/dist/pipeline/dispatcher.js +12 -14
- package/dist/pipeline/event-dispatcher-admin.js +9 -8
- package/dist/pipeline/event-dispatcher-delivery.d.ts +19 -1
- package/dist/pipeline/event-dispatcher-delivery.js +121 -29
- package/dist/pipeline/event-dispatcher.d.ts +5 -1
- package/dist/pipeline/event-dispatcher.js +28 -21
- package/dist/pipeline/handler-context-phase-denials.js +2 -0
- package/dist/pipeline/multi-stream-apply-context.js +12 -20
- package/dist/pipeline/system-hooks.d.ts +4 -1
- package/dist/pipeline/system-hooks.js +79 -6
- package/dist/pipeline/system-identity-switch.js +10 -7
- package/dist/search/build-search-snippet.d.ts +9 -0
- package/dist/search/build-search-snippet.js +40 -0
- package/dist/search/index.d.ts +1 -0
- package/dist/search/index.js +1 -0
- package/dist/search/meilisearch-adapter.d.ts +32 -0
- package/dist/search/meilisearch-adapter.js +153 -56
- package/dist/search/meilisearch-chunking.d.ts +21 -0
- package/dist/search/meilisearch-chunking.js +96 -0
- package/dist/search/reindex-entity.d.ts +1 -0
- package/dist/search/reindex-entity.js +97 -52
- package/dist/ui-types/index.d.ts +1 -1
- package/dist/upgrade-cli.js +3 -14
- package/package.json +3 -3
- package/src/changes.json +85 -0
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
import { filterByPhase, filterOwned } from "./registry-state.js";
|
|
2
|
+
function isFeatureSystemScoped(state, featureName) {
|
|
3
|
+
if (!featureName)
|
|
4
|
+
return false;
|
|
5
|
+
return state.featureMap.get(featureName)?.systemScope ?? false;
|
|
6
|
+
}
|
|
2
7
|
// Builds the public Registry surface (64 getters) bound to a specific
|
|
3
8
|
// RegistryState instance — pure move-diff from createRegistry's former
|
|
4
9
|
// return-object literal, only the closure-captured variable changed
|
|
@@ -102,16 +107,10 @@ export function buildRegistryFacade(state) {
|
|
|
102
107
|
return state.handlerEntityMap.get(qualifiedHandler);
|
|
103
108
|
},
|
|
104
109
|
isHandlerSystemScoped(qualifiedHandler) {
|
|
105
|
-
|
|
106
|
-
if (!featureName)
|
|
107
|
-
return false;
|
|
108
|
-
return state.featureMap.get(featureName)?.systemScope ?? false;
|
|
110
|
+
return isFeatureSystemScoped(state, state.handlerFeatureMap.get(qualifiedHandler));
|
|
109
111
|
},
|
|
110
112
|
isJobSystemScoped(qualifiedJobName) {
|
|
111
|
-
|
|
112
|
-
if (!featureName)
|
|
113
|
-
return false;
|
|
114
|
-
return state.featureMap.get(featureName)?.systemScope ?? false;
|
|
113
|
+
return isFeatureSystemScoped(state, state.jobFeatureMap.get(qualifiedJobName));
|
|
115
114
|
},
|
|
116
115
|
getHandlerFeature(qualifiedHandler) {
|
|
117
116
|
return state.handlerFeatureMap.get(qualifiedHandler);
|
|
@@ -198,6 +198,10 @@ function buildSortableReferenceField(entityName, fieldName, field) {
|
|
|
198
198
|
labelField: field.labelField,
|
|
199
199
|
};
|
|
200
200
|
}
|
|
201
|
+
// longText becomes searchable only through `find: "fuzzy"` (indexed in chunks by the SearchAdapter).
|
|
202
|
+
function isSearchableStringField(field) {
|
|
203
|
+
return (field.type === "text" || field.type === "longText") && field.searchable === true;
|
|
204
|
+
}
|
|
201
205
|
// Precompute: searchable/sortable fields, searchable + sortable reference fields.
|
|
202
206
|
export function buildSearchableSortableCaches(state) {
|
|
203
207
|
for (const [name, entity] of state.entityMap) {
|
|
@@ -206,7 +210,7 @@ export function buildSearchableSortableCaches(state) {
|
|
|
206
210
|
const searchableReferences = [];
|
|
207
211
|
const sortableReferences = [];
|
|
208
212
|
for (const [fieldName, field] of Object.entries(entity.fields)) {
|
|
209
|
-
if (field
|
|
213
|
+
if (isSearchableStringField(field))
|
|
210
214
|
searchable.push(fieldName);
|
|
211
215
|
if (field.type === "text" && field.sortable === true)
|
|
212
216
|
sortable.push(fieldName);
|
|
@@ -5,6 +5,7 @@ export declare const SOFT_DELETE_CLEANUP_SYSTEM_JOB = "soft-delete:job:cleanup-s
|
|
|
5
5
|
export declare const SOFT_DELETE_GRACE_DAYS_KEY = "soft-delete:config:grace-days";
|
|
6
6
|
export declare const DEFAULT_GRACE_DAYS = 30;
|
|
7
7
|
export declare const softDeleteGraceDaysConfig: ConfigKeyDefinition;
|
|
8
|
+
export declare function readSoftDeleteGraceDays(config: ((qualifiedKey: string) => Promise<unknown>) | undefined): Promise<number>;
|
|
8
9
|
export declare function isSystemScopedSoftDeleteTable(table: unknown, entity: Pick<EntityDefinition, "tenancy">): boolean;
|
|
9
10
|
export declare const softDeleteCleanupJob: JobHandlerFn;
|
|
10
11
|
export declare const softDeleteCleanupSystemJob: JobHandlerFn;
|
|
@@ -36,6 +36,11 @@ export const softDeleteGraceDaysConfig = {
|
|
|
36
36
|
// existing silent-below-bound / audited-crossing behavior.
|
|
37
37
|
bounds: { min: 1 },
|
|
38
38
|
};
|
|
39
|
+
// ctx.config skips the key's read roles, so a plain user's trash query can show the period.
|
|
40
|
+
export async function readSoftDeleteGraceDays(config) {
|
|
41
|
+
const value = await config?.(SOFT_DELETE_GRACE_DAYS_KEY);
|
|
42
|
+
return typeof value === "number" && value >= 1 ? value : DEFAULT_GRACE_DAYS;
|
|
43
|
+
}
|
|
39
44
|
function hasTenantIdColumn(table) {
|
|
40
45
|
return hasFieldProperty(table, "tenantId");
|
|
41
46
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// raw error message can echo recipients or payload fragments. Events carry only
|
|
3
3
|
// this generic text; the raw error goes to the log.
|
|
4
4
|
import { unwrapWorkflowStepError } from "./workflow-step-error.js";
|
|
5
|
+
// guard:dup-ok one template-literal message; only the shape matches unrelated string builders
|
|
5
6
|
export function describeWorkflowStepError(error) {
|
|
6
7
|
const original = unwrapWorkflowStepError(error);
|
|
7
8
|
return `workflow step failed (${original instanceof Error ? original.name : "unknown error"})`;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type DbConnection } from "../db/index.ts";
|
|
2
|
-
export type EsOperationType = "seed-migration" | "stream-migration";
|
|
2
|
+
export type EsOperationType = "seed-migration" | "stream-migration" | "search-reindex";
|
|
3
3
|
export type EsOperationAppliedBy = "boot" | "cli" | "ci-pipeline";
|
|
4
4
|
export declare const esOperationsTable: import("@cosmicdrift/kumiko-types/executor-brand").WritableSchemaTable;
|
|
5
5
|
export declare function createEsOperationsTable(db: DbConnection): Promise<void>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { tableExists } from "../db/schema-inspection.js";
|
|
2
|
+
import { ensureTableRowLevelSecurity, unsafePushTables } from "../db/table-push.js";
|
|
3
|
+
export async function ensureDeadLetterTable(db, qualifiedName, pushKey, table) {
|
|
4
|
+
// skip: table already exists — bootstrap called from multiple paths
|
|
5
|
+
if (await tableExists(db, qualifiedName)) {
|
|
6
|
+
await ensureTableRowLevelSecurity(db, table);
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
await unsafePushTables(db, { [pushKey]: table });
|
|
10
|
+
}
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
// `kumiko_rebuild_dead_letters`, and the replay continues. Replay-after-fix
|
|
14
14
|
// is a separate ops step — same stance as the upcaster dead-letter.
|
|
15
15
|
import { bigint, index, jsonb, table as pgTable, text, timestamp, uuid } from "../db/dialect.js";
|
|
16
|
-
import {
|
|
17
|
-
import { ensureTableRowLevelSecurity, unsafePushTables } from "../db/table-push.js";
|
|
16
|
+
import { ensureDeadLetterTable } from "./ensure-dead-letter-table.js";
|
|
18
17
|
export const rebuildDeadLetterTable = pgTable("kumiko_rebuild_dead_letters", {
|
|
19
18
|
// Surrogate PK — the same event can land here across multiple rebuild
|
|
20
19
|
// attempts before the fix ships, without unique-violation noise.
|
|
@@ -38,12 +37,7 @@ export const rebuildDeadLetterTable = pgTable("kumiko_rebuild_dead_letters", {
|
|
|
38
37
|
// tx whenever quarantine mode is active, so the opt-in works on databases
|
|
39
38
|
// provisioned before this table existed.
|
|
40
39
|
export async function createRebuildDeadLetterTable(db) {
|
|
41
|
-
|
|
42
|
-
if (await tableExists(db, "public.kumiko_rebuild_dead_letters")) {
|
|
43
|
-
await ensureTableRowLevelSecurity(db, rebuildDeadLetterTable);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
await unsafePushTables(db, { kumikoRebuildDeadLetters: rebuildDeadLetterTable });
|
|
40
|
+
await ensureDeadLetterTable(db, "public.kumiko_rebuild_dead_letters", "kumikoRebuildDeadLetters", rebuildDeadLetterTable);
|
|
47
41
|
}
|
|
48
42
|
// Bulk-write, called ONCE at the end of a quarantining rebuild (inside its
|
|
49
43
|
// tx). Unqualified insert — during the rebuild the search_path points at the
|
|
@@ -12,8 +12,7 @@
|
|
|
12
12
|
// ops tooling. Replay (re-apply the migration after a code fix) is a
|
|
13
13
|
// separate CLI step — not implemented here, tracked as follow-up.
|
|
14
14
|
import { bigint, index, integer, jsonb, table as pgTable, text, timestamp, uuid, } from "../db/dialect.js";
|
|
15
|
-
import {
|
|
16
|
-
import { ensureTableRowLevelSecurity, unsafePushTables } from "../db/table-push.js";
|
|
15
|
+
import { ensureDeadLetterTable } from "./ensure-dead-letter-table.js";
|
|
17
16
|
export const upcasterDeadLetterTable = pgTable("kumiko_upcaster_dead_letters", {
|
|
18
17
|
// Surrogate PK. We don't reuse eventId so a single event can land
|
|
19
18
|
// here multiple times (retry attempts across deploys before the fix
|
|
@@ -39,12 +38,7 @@ export const upcasterDeadLetterTable = pgTable("kumiko_upcaster_dead_letters", {
|
|
|
39
38
|
// Idempotent table-create. Called from setupTestStack for suites that
|
|
40
39
|
// exercise the quarantine path; production boot uses drizzle-kit push.
|
|
41
40
|
export async function createUpcasterDeadLetterTable(db) {
|
|
42
|
-
|
|
43
|
-
if (await tableExists(db, "public.kumiko_upcaster_dead_letters")) {
|
|
44
|
-
await ensureTableRowLevelSecurity(db, upcasterDeadLetterTable);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
await unsafePushTables(db, { kumikoUpcasterDeadLetters: upcasterDeadLetterTable });
|
|
41
|
+
await ensureDeadLetterTable(db, "public.kumiko_upcaster_dead_letters", "kumikoUpcasterDeadLetters", upcasterDeadLetterTable);
|
|
48
42
|
}
|
|
49
43
|
// Writes a dead-letter row. Called by upcastStoredEvent when errorPolicy
|
|
50
44
|
// is "quarantine" and a transform threw. Returns the inserted row id —
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { WriteResult } from "@cosmicdrift/kumiko-types/handlers";
|
|
2
|
+
import type { TenantDb } from "../db/tenant-db.ts";
|
|
3
|
+
import type { Registry, SessionUser } from "../engine/types/index.ts";
|
|
4
|
+
import type { FileContext } from "./file-handle.ts";
|
|
5
|
+
export type PendingUploadSource = {
|
|
6
|
+
readonly db: TenantDb;
|
|
7
|
+
readonly user: SessionUser;
|
|
8
|
+
readonly files: FileContext | undefined;
|
|
9
|
+
/** Where the upload is pending: the actionForm screen QN and its files field. */
|
|
10
|
+
readonly entityType: string;
|
|
11
|
+
readonly fieldName: string;
|
|
12
|
+
};
|
|
13
|
+
export type FileRefCopyTarget = {
|
|
14
|
+
readonly db: TenantDb;
|
|
15
|
+
readonly user: SessionUser;
|
|
16
|
+
readonly registry: Registry;
|
|
17
|
+
readonly files: FileContext | undefined;
|
|
18
|
+
readonly attachTo: {
|
|
19
|
+
readonly entityType: string;
|
|
20
|
+
readonly fieldName: string;
|
|
21
|
+
readonly entityId: string;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export declare function copyPendingFileRefsToTenant(args: {
|
|
25
|
+
readonly source: PendingUploadSource;
|
|
26
|
+
readonly target: FileRefCopyTarget;
|
|
27
|
+
readonly fileIds: readonly string[];
|
|
28
|
+
}): Promise<WriteResult<readonly string[]>>;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { FrameworkReasons, InternalError, reraiseAsKumikoError, UnprocessableError, writeFailure, } from "../errors/index.js";
|
|
2
|
+
import { bindPendingFileRef, loadPendingFileRef } from "./bind-pending-file-refs.js";
|
|
3
|
+
import { getFileRefExecutor } from "./create-file-ref.js";
|
|
4
|
+
import { createFileRefFromBytes } from "./create-file-ref-from-bytes.js";
|
|
5
|
+
function fileNotPending(fileRefId) {
|
|
6
|
+
return writeFailure(new UnprocessableError(FrameworkReasons.fileRejected, {
|
|
7
|
+
details: { error: `file ${fileRefId} is not a pending upload of the caller` },
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
// Cross-tenant copy reads and re-stores the bytes, so the target field's accept/maxSize apply and
|
|
11
|
+
// the source uploads are deleted afterwards; within one tenant the uploads are bound in place.
|
|
12
|
+
export async function copyPendingFileRefsToTenant(args) {
|
|
13
|
+
const { source, target } = args;
|
|
14
|
+
const fileIds = [...new Set(args.fileIds)];
|
|
15
|
+
if (source.user.tenantId === target.user.tenantId) {
|
|
16
|
+
return bindInPlace(source, target, fileIds);
|
|
17
|
+
}
|
|
18
|
+
if (source.files === undefined || target.files === undefined) {
|
|
19
|
+
return writeFailure(new InternalError({
|
|
20
|
+
message: "copyPendingFileRefsToTenant: file storage is unavailable for source or target",
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
const executor = getFileRefExecutor();
|
|
24
|
+
const uploads = [];
|
|
25
|
+
for (const fileRefId of fileIds) {
|
|
26
|
+
const pending = await loadPendingFileRef({
|
|
27
|
+
fileRefId,
|
|
28
|
+
entityName: source.entityType,
|
|
29
|
+
fieldName: source.fieldName,
|
|
30
|
+
user: source.user,
|
|
31
|
+
db: source.db,
|
|
32
|
+
});
|
|
33
|
+
if (pending === undefined)
|
|
34
|
+
return fileNotPending(fileRefId);
|
|
35
|
+
// Read through the executor so an encrypted file name arrives as plain text.
|
|
36
|
+
const detail = await executor.detail({ id: fileRefId }, source.user, source.db);
|
|
37
|
+
if (detail === null)
|
|
38
|
+
return fileNotPending(fileRefId);
|
|
39
|
+
uploads.push({
|
|
40
|
+
id: fileRefId,
|
|
41
|
+
storageKey: pending.storageKey,
|
|
42
|
+
mimeType: pending.mimeType,
|
|
43
|
+
fileName: detail.fileName,
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
const copiedIds = [];
|
|
47
|
+
for (const upload of uploads) {
|
|
48
|
+
const data = await source.files.ref(upload.storageKey).read();
|
|
49
|
+
const created = await createFileRefFromBytes({
|
|
50
|
+
db: target.db,
|
|
51
|
+
services: { files: target.files },
|
|
52
|
+
registry: target.registry,
|
|
53
|
+
user: target.user,
|
|
54
|
+
}, {
|
|
55
|
+
fileName: upload.fileName,
|
|
56
|
+
mimeType: upload.mimeType,
|
|
57
|
+
data,
|
|
58
|
+
attachTo: target.attachTo,
|
|
59
|
+
});
|
|
60
|
+
if (!created.isSuccess)
|
|
61
|
+
return created;
|
|
62
|
+
copiedIds.push(created.data.id);
|
|
63
|
+
}
|
|
64
|
+
for (const upload of uploads) {
|
|
65
|
+
const removed = await executor.delete({ id: upload.id }, source.user, source.db);
|
|
66
|
+
if (!removed.isSuccess)
|
|
67
|
+
throw reraiseAsKumikoError(removed.error);
|
|
68
|
+
}
|
|
69
|
+
return { isSuccess: true, data: copiedIds };
|
|
70
|
+
}
|
|
71
|
+
async function bindInPlace(source, target, fileIds) {
|
|
72
|
+
for (const fileRefId of fileIds) {
|
|
73
|
+
const outcome = await bindPendingFileRef({
|
|
74
|
+
fileRefId,
|
|
75
|
+
entityName: source.entityType,
|
|
76
|
+
fieldName: source.fieldName,
|
|
77
|
+
entityId: target.attachTo.entityId,
|
|
78
|
+
bindTo: { entityName: target.attachTo.entityType, fieldName: target.attachTo.fieldName },
|
|
79
|
+
registry: target.registry,
|
|
80
|
+
user: source.user,
|
|
81
|
+
db: source.db,
|
|
82
|
+
});
|
|
83
|
+
if (outcome !== "bound")
|
|
84
|
+
return fileNotPending(fileRefId);
|
|
85
|
+
}
|
|
86
|
+
return { isSuccess: true, data: fileIds };
|
|
87
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { RateLimitResolver } from "@cosmicdrift/kumiko-types/rate-limit-typ
|
|
|
2
2
|
import type { WriteErrorInfo } from "@cosmicdrift/kumiko-types/write-error-info-types";
|
|
3
3
|
import { Hono } from "hono";
|
|
4
4
|
import type { DbConnection } from "../db/connection.ts";
|
|
5
|
-
import type
|
|
5
|
+
import { type Registry, type SessionUser, type TenantId } from "../engine/types/index.ts";
|
|
6
6
|
import type { FileProviderResolver } from "./provider-resolver.ts";
|
|
7
7
|
import type { RecordReadCheck } from "./record-read-check.ts";
|
|
8
8
|
import { type RecordWriteCheck } from "./record-write-check.ts";
|
|
@@ -4,6 +4,7 @@ import { Hono } from "hono";
|
|
|
4
4
|
import { bodyLimit } from "hono/body-limit";
|
|
5
5
|
import { getUser } from "../api/auth-middleware.js";
|
|
6
6
|
import { requestContext } from "../api/request-context.js";
|
|
7
|
+
import { ROLES } from "../auth/roles.js";
|
|
7
8
|
import { collectPiiSubjectFields, configuredPiiSubjectKms, decryptPiiFieldValues, isPiiCiphertext, PII_ERASED_SENTINEL, } from "../crypto/index.js";
|
|
8
9
|
import { selectMany } from "../db/query.js";
|
|
9
10
|
import { runInRowLevelSecurityScope, tenantRowLevelSecurityScope, } from "../db/row-level-security-scope.js";
|
|
@@ -12,6 +13,7 @@ import { createDerivativesContext, resolveRenderer } from "../derivatives/deriva
|
|
|
12
13
|
import { resolveFieldVariant } from "../derivatives/index.js";
|
|
13
14
|
import { isFileField } from "../engine/field-helpers.js";
|
|
14
15
|
import { isAnonymousSessionUser } from "../engine/system-user.js";
|
|
16
|
+
import { SYSTEM_TENANT_ID, } from "../engine/types/index.js";
|
|
15
17
|
import { createFailOpenReporter, respondRateLimited } from "../rate-limit/middleware.js";
|
|
16
18
|
import { listActionFormFileFields, mayUseActionForm } from "./action-form-upload.js";
|
|
17
19
|
import { buildContentDispositionHeader } from "./content-disposition.js";
|
|
@@ -91,6 +93,9 @@ export function configuredMaxUploadBytes(registry) {
|
|
|
91
93
|
const configured = readFilesRouteOptions(registry).maxUploadSize;
|
|
92
94
|
return configured === undefined ? undefined : parseMaxSize(configured);
|
|
93
95
|
}
|
|
96
|
+
function canReadSystemTenantFile(user, fileTenantId) {
|
|
97
|
+
return fileTenantId === SYSTEM_TENANT_ID && user.roles.includes(ROLES.SystemAdmin);
|
|
98
|
+
}
|
|
94
99
|
export function createFileRoutes(options) {
|
|
95
100
|
const { db, metaBatchRateLimitResolver } = options;
|
|
96
101
|
const reportMetaBatchLimiterFailOpen = createFailOpenReporter("files-meta-batch");
|
|
@@ -292,7 +297,7 @@ export function createFileRoutes(options) {
|
|
|
292
297
|
// GET /files/:id — download.
|
|
293
298
|
//
|
|
294
299
|
// Authorization stack:
|
|
295
|
-
// 1. tenantId must match (hard isolation
|
|
300
|
+
// 1. tenantId must match (hard isolation); the one crossing is a SystemAdmin reading a SYSTEM_TENANT_ID file.
|
|
296
301
|
// 2. The configured FileAccessGuard decides read access. Default:
|
|
297
302
|
// unattached → allow; attached → uploader, privileged role or a
|
|
298
303
|
// reader of the record.
|
|
@@ -300,7 +305,7 @@ export function createFileRoutes(options) {
|
|
|
300
305
|
api.get("/files/:id", async (c) => {
|
|
301
306
|
const user = getUser(c);
|
|
302
307
|
const id = c.req.param("id");
|
|
303
|
-
const fileRef = await
|
|
308
|
+
const fileRef = await loadReadableFileRef(id, user);
|
|
304
309
|
if (!fileRef)
|
|
305
310
|
return c.json({ error: "not_found" }, 404);
|
|
306
311
|
const decision = await guard({ fileRef, user, operation: "read" });
|
|
@@ -309,7 +314,7 @@ export function createFileRoutes(options) {
|
|
|
309
314
|
// an unauthorised caller — matches the tenant-miss response.
|
|
310
315
|
return c.json({ error: "not_found" }, 404);
|
|
311
316
|
}
|
|
312
|
-
const storageProvider = await options.resolveProvider(
|
|
317
|
+
const storageProvider = await options.resolveProvider(fileRef.tenantId);
|
|
313
318
|
const data = await storageProvider.read(fileRef.storageKey);
|
|
314
319
|
// The stored mimeType is client-declared (file.type off the upload) and
|
|
315
320
|
// never verified against the bytes — serving it as-is would let a
|
|
@@ -428,7 +433,7 @@ export function createFileRoutes(options) {
|
|
|
428
433
|
api.get("/files/:id/download-url", async (c) => {
|
|
429
434
|
const user = getUser(c);
|
|
430
435
|
const id = c.req.param("id");
|
|
431
|
-
const fileRef = await
|
|
436
|
+
const fileRef = await loadReadableFileRef(id, user);
|
|
432
437
|
if (!fileRef)
|
|
433
438
|
return c.json({ error: "not_found" }, 404);
|
|
434
439
|
const decision = await guard({ fileRef, user, operation: "read" });
|
|
@@ -436,7 +441,7 @@ export function createFileRoutes(options) {
|
|
|
436
441
|
return c.json({ error: "not_found" }, 404);
|
|
437
442
|
// Resolve after access-check: tenant-scoped provider, and capability
|
|
438
443
|
// disclosure (501) stays behind the auth+guard gate.
|
|
439
|
-
const storageProvider = await options.resolveProvider(
|
|
444
|
+
const storageProvider = await options.resolveProvider(fileRef.tenantId);
|
|
440
445
|
if (!storageProvider.getSignedUrl) {
|
|
441
446
|
return c.json({
|
|
442
447
|
error: "signed_urls_not_supported: this provider does not support signed URLs — use GET /files/:id to stream",
|
|
@@ -474,8 +479,9 @@ export function createFileRoutes(options) {
|
|
|
474
479
|
// detail()'s "pass"-ownership read widens to tenantId IN (self, SYSTEM),
|
|
475
480
|
// narrower in loadFileForTenant's selectMany. Restore that here so meta
|
|
476
481
|
// doesn't leak reference-tenant rows.
|
|
477
|
-
if (fileRef.tenantId !== user.tenantId)
|
|
482
|
+
if (fileRef.tenantId !== user.tenantId && !canReadSystemTenantFile(user, fileRef.tenantId)) {
|
|
478
483
|
return null;
|
|
484
|
+
}
|
|
479
485
|
const decision = await guard({ fileRef, user, operation: "read" });
|
|
480
486
|
if (decision === "deny")
|
|
481
487
|
return null;
|
|
@@ -493,6 +499,15 @@ export function createFileRoutes(options) {
|
|
|
493
499
|
const meta = await loadReadableFileMeta(c.req.param("id"), getUser(c));
|
|
494
500
|
return meta ? c.json(meta) : c.json({ error: "not_found" }, 404);
|
|
495
501
|
});
|
|
502
|
+
// Read-only crossing: SYSTEM_TENANT_ID files (e.g. contact attachments) are
|
|
503
|
+
// visible to a SystemAdmin whose session sits in another tenant. Delete,
|
|
504
|
+
// variant and upload keep using loadFileForTenant and stay tenant-equal.
|
|
505
|
+
async function loadReadableFileRef(id, user) {
|
|
506
|
+
const own = await loadFileForTenant(id, user.tenantId);
|
|
507
|
+
if (own || !canReadSystemTenantFile(user, SYSTEM_TENANT_ID))
|
|
508
|
+
return own;
|
|
509
|
+
return loadFileForTenant(id, SYSTEM_TENANT_ID);
|
|
510
|
+
}
|
|
496
511
|
async function loadFileForTenant(id, tenantId) {
|
|
497
512
|
// fileRefsTable.id is a UUID column — a malformed id must fail here, not
|
|
498
513
|
// at Postgres (22P02 poisons the pooled connection). 404, not
|
package/dist/files/index.d.ts
CHANGED
|
@@ -3,6 +3,8 @@ export type { PendingFileRef } from "./bind-pending-file-refs.ts";
|
|
|
3
3
|
export { bindPendingFileRef, loadPendingFileRef } from "./bind-pending-file-refs.ts";
|
|
4
4
|
export type { CanReadFileRefContext } from "./can-caller-read-file-ref.ts";
|
|
5
5
|
export { canCallerReadFileRef } from "./can-caller-read-file-ref.ts";
|
|
6
|
+
export type { FileRefCopyTarget, PendingUploadSource } from "./copy-pending-file-refs-to-tenant.ts";
|
|
7
|
+
export { copyPendingFileRefsToTenant } from "./copy-pending-file-refs-to-tenant.ts";
|
|
6
8
|
export type { CreatedFileRef, CreateFileRefInput, UploadedFileBytes, } from "./create-file-ref-from-bytes.ts";
|
|
7
9
|
export { createFileRefFromBytes, createFileRefFromUploadedBytes, uploadFileBytesBeforeTransaction, } from "./create-file-ref-from-bytes.ts";
|
|
8
10
|
export { createDefaultGuard } from "./default-file-guard.ts";
|
package/dist/files/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { listActionFormFileFields, resolveActionFormFileField } from "./action-form-upload.js";
|
|
2
2
|
export { bindPendingFileRef, loadPendingFileRef } from "./bind-pending-file-refs.js";
|
|
3
3
|
export { canCallerReadFileRef } from "./can-caller-read-file-ref.js";
|
|
4
|
+
export { copyPendingFileRefsToTenant } from "./copy-pending-file-refs-to-tenant.js";
|
|
4
5
|
export { createFileRefFromBytes, createFileRefFromUploadedBytes, uploadFileBytesBeforeTransaction, } from "./create-file-ref-from-bytes.js";
|
|
5
6
|
export { createDefaultGuard } from "./default-file-guard.js";
|
|
6
7
|
export { deleteFileRefsBoundToRecord } from "./delete-record-file-refs.js";
|
|
@@ -299,6 +299,7 @@ function collectActionFormKeys(ctx, form) {
|
|
|
299
299
|
pushKey(ctx.out, link.label);
|
|
300
300
|
for (const fact of form.successFacts ?? [])
|
|
301
301
|
pushKey(ctx.out, fact.label);
|
|
302
|
+
pushKey(ctx.out, form.successItems?.link?.label);
|
|
302
303
|
for (const fieldName of Object.keys(form.fields)) {
|
|
303
304
|
pushFieldLabelOrOverrideKey(ctx, ACTION_FORM_ENTITY, fieldName, form.fieldLabels);
|
|
304
305
|
}
|
|
@@ -117,6 +117,7 @@ export async function resolveJobTz(config, context, logger) {
|
|
|
117
117
|
export function missingDbProxy(jobName) {
|
|
118
118
|
// @cast-boundary db-operator — every access throws, so no TenantDb member is ever returned
|
|
119
119
|
return new Proxy({}, {
|
|
120
|
+
// guard:dup-ok a throw-only proxy trap; the message is its whole content
|
|
120
121
|
get() {
|
|
121
122
|
throw new InternalError({
|
|
122
123
|
message: `[jobs] job runner constructed without a db connection — ctx.db is unavailable for "${jobName}"`,
|
|
@@ -10,7 +10,7 @@ export declare const ACTIVE_TENANT_IDS_QUERY_NAME = "tenant:query:active-tenant-
|
|
|
10
10
|
* leaking permanent `repeat:*` hashes (taskforcesh/bullmq#3828,
|
|
11
11
|
* publicstatus Redis OOM). Strip `.` and `:` from the job QN.
|
|
12
12
|
*/
|
|
13
|
-
export declare function schedulerIdForJobName(jobName: string): string;
|
|
13
|
+
export declare function schedulerIdForJobName(jobName: string, wakesSleepingApp?: boolean): string;
|
|
14
14
|
export declare function bootJobIdForJobName(jobName: string): string;
|
|
15
15
|
export declare const ORPHAN_SCHEDULER_GRACE_MS: number;
|
|
16
16
|
export declare function markSchedulersSeen(queue: Queue, schedulerIds: ReadonlySet<string>): Promise<void>;
|
|
@@ -18,6 +18,6 @@ type OrphanSchedulerLog = {
|
|
|
18
18
|
info(msg: string, data?: Record<string, unknown>): void;
|
|
19
19
|
warn(msg: string, data?: Record<string, unknown>): void;
|
|
20
20
|
};
|
|
21
|
-
export declare function removeOrphanJobSchedulers(queue: Queue, expectedSchedulerIds: ReadonlySet<string>, lane: JobRunIn, log: OrphanSchedulerLog): Promise<void>;
|
|
21
|
+
export declare function removeOrphanJobSchedulers(queue: Queue, expectedSchedulerIds: ReadonlySet<string>, supersededSchedulerIds: ReadonlySet<string>, lane: JobRunIn, log: OrphanSchedulerLog): Promise<void>;
|
|
22
22
|
export declare function perTenantChildJobId(wrapperJobId: string, tenantId: string): string;
|
|
23
23
|
export {};
|
|
@@ -22,9 +22,12 @@ export const ACTIVE_TENANT_IDS_QUERY_NAME = "tenant:query:active-tenant-ids";
|
|
|
22
22
|
* leaking permanent `repeat:*` hashes (taskforcesh/bullmq#3828,
|
|
23
23
|
* publicstatus Redis OOM). Strip `.` and `:` from the job QN.
|
|
24
24
|
*/
|
|
25
|
-
export function schedulerIdForJobName(jobName) {
|
|
26
|
-
|
|
25
|
+
export function schedulerIdForJobName(jobName, wakesSleepingApp = true) {
|
|
26
|
+
const prefix = wakesSleepingApp ? "scheduler-" : NO_WAKE_SCHEDULER_PREFIX;
|
|
27
|
+
return `${prefix}${jobName.replace(/[.:]/g, "-")}`;
|
|
27
28
|
}
|
|
29
|
+
// Contract with the infra waker of sleeping shared apps: it skips due jobs under this prefix.
|
|
30
|
+
const NO_WAKE_SCHEDULER_PREFIX = "scheduler-nowake-";
|
|
28
31
|
// Same colon-in-BullMQ-id hazard as schedulerIdForJobName —
|
|
29
32
|
// a QN like "publicstatus:job:uptime-probe" must not leave ":" in the id.
|
|
30
33
|
export function bootJobIdForJobName(jobName) {
|
|
@@ -53,7 +56,7 @@ export async function markSchedulersSeen(queue, schedulerIds) {
|
|
|
53
56
|
// A cron job dropped from the app (or an older scheduler-id format) leaves its
|
|
54
57
|
// scheduler in Redis, where it keeps firing jobs the worker no longer knows
|
|
55
58
|
// ("Unknown job"). Best-effort: a Redis hiccup here must not stop the start.
|
|
56
|
-
export async function removeOrphanJobSchedulers(queue, expectedSchedulerIds, lane, log) {
|
|
59
|
+
export async function removeOrphanJobSchedulers(queue, expectedSchedulerIds, supersededSchedulerIds, lane, log) {
|
|
57
60
|
try {
|
|
58
61
|
// Collect first: removing while paging would shift the indices.
|
|
59
62
|
const existingKeys = [];
|
|
@@ -71,7 +74,8 @@ export async function removeOrphanJobSchedulers(queue, expectedSchedulerIds, lan
|
|
|
71
74
|
if (expectedSchedulerIds.has(key))
|
|
72
75
|
continue;
|
|
73
76
|
const lastSeen = Number(seenAt[key]);
|
|
74
|
-
|
|
77
|
+
const isWithinGrace = key in seenAt && now - lastSeen < ORPHAN_SCHEDULER_GRACE_MS;
|
|
78
|
+
if (isWithinGrace && !supersededSchedulerIds.has(key))
|
|
75
79
|
continue;
|
|
76
80
|
await queue.removeJobScheduler(key);
|
|
77
81
|
await client.hdel(schedulerSeenKey(queue), key);
|
package/dist/jobs/job-runner.js
CHANGED
|
@@ -53,6 +53,10 @@ export function createJobRunner(options) {
|
|
|
53
53
|
// an expected "Connection is closed." Downgrading to debug once stopping
|
|
54
54
|
// is true keeps those out of error-rate alerts without losing them.
|
|
55
55
|
let stopping = false;
|
|
56
|
+
const logRedisConnectionError = (label, err) => {
|
|
57
|
+
const log = stopping ? errorLogger.debug : errorLogger.error;
|
|
58
|
+
log(`${label} redis connection error`, { error: err.message });
|
|
59
|
+
};
|
|
56
60
|
// Default for perTenant fan-out when the caller didn't supply
|
|
57
61
|
// options.getActiveTenantIds: if the tenant feature is mounted (its
|
|
58
62
|
// active-tenant-ids query is in the registry), resolve tenants through
|
|
@@ -140,10 +144,7 @@ export function createJobRunner(options) {
|
|
|
140
144
|
// Without a listener, a post-close 'error' (e.g. a teardown-race
|
|
141
145
|
// "Connection is closed") is unhandled and crashes the process — in
|
|
142
146
|
// bun:test it gets attributed to whichever test happens to run next.
|
|
143
|
-
lockRedis.on("error", (err) =>
|
|
144
|
-
const log = stopping ? errorLogger.debug : errorLogger.error;
|
|
145
|
-
log("lock redis connection error", { error: err.message });
|
|
146
|
-
});
|
|
147
|
+
lockRedis.on("error", (err) => logRedisConnectionError("lock", err));
|
|
147
148
|
const lockScope = consumerLane ?? "enqueue";
|
|
148
149
|
// Scoped by queueNamePrefix like the queues themselves, so runners
|
|
149
150
|
// isolated by prefix on a shared Redis don't contend for the same lock.
|
|
@@ -176,10 +177,7 @@ export function createJobRunner(options) {
|
|
|
176
177
|
// Same unhandled-'error'-crash hazard as lockRedis above, just via
|
|
177
178
|
// BullMQ's internal ioredis client.
|
|
178
179
|
for (const queue of Object.values(queues)) {
|
|
179
|
-
queue.on("error", (err) =>
|
|
180
|
-
const log = stopping ? errorLogger.debug : errorLogger.error;
|
|
181
|
-
log("queue redis connection error", { error: err.message });
|
|
182
|
-
});
|
|
180
|
+
queue.on("error", (err) => logRedisConnectionError("queue", err));
|
|
183
181
|
}
|
|
184
182
|
let worker = null;
|
|
185
183
|
let queueDepthTimer = null;
|
|
@@ -294,11 +292,14 @@ export function createJobRunner(options) {
|
|
|
294
292
|
}
|
|
295
293
|
}
|
|
296
294
|
}
|
|
297
|
-
|
|
295
|
+
// `superseded`: the id the job would have with the other wake flag. No runner of any version
|
|
296
|
+
// expects both ids of one job, so a leftover under that id goes without the orphan grace period.
|
|
297
|
+
function cronSchedulerIdsForLane(lane, superseded = false) {
|
|
298
298
|
const ids = new Set();
|
|
299
299
|
for (const [name, jobDef] of allJobs) {
|
|
300
300
|
if (laneForJob(jobDef) === lane && isScheduledTrigger(jobDef.trigger)) {
|
|
301
|
-
|
|
301
|
+
const wakesSleepingApp = jobDef.trigger.wakesSleepingApp !== false;
|
|
302
|
+
ids.add(schedulerIdForJobName(name, superseded ? !wakesSleepingApp : wakesSleepingApp));
|
|
302
303
|
}
|
|
303
304
|
}
|
|
304
305
|
return ids;
|
|
@@ -308,7 +309,7 @@ export function createJobRunner(options) {
|
|
|
308
309
|
if (laneForJob(jobDef) !== lane)
|
|
309
310
|
continue;
|
|
310
311
|
if (isScheduledTrigger(jobDef.trigger)) {
|
|
311
|
-
await queue.upsertJobScheduler(schedulerIdForJobName(name), scheduleRepeatOptions(jobDef.trigger, options.maintenanceWindow), {
|
|
312
|
+
await queue.upsertJobScheduler(schedulerIdForJobName(name, jobDef.trigger.wakesSleepingApp !== false), scheduleRepeatOptions(jobDef.trigger, options.maintenanceWindow), {
|
|
312
313
|
name: jobDef.perTenant ? `${PER_TENANT_PREFIX}${name}` : name,
|
|
313
314
|
data: {},
|
|
314
315
|
// Queue-level defaultJobOptions (jobRetentionOpts) covers
|
|
@@ -381,10 +382,7 @@ export function createJobRunner(options) {
|
|
|
381
382
|
// previous run must not execute against an unmet boot precondition.
|
|
382
383
|
autorun: false,
|
|
383
384
|
});
|
|
384
|
-
worker.on("error", (err) =>
|
|
385
|
-
const log = stopping ? errorLogger.debug : errorLogger.error;
|
|
386
|
-
log("worker redis connection error", { error: err.message });
|
|
387
|
-
});
|
|
385
|
+
worker.on("error", (err) => logRedisConnectionError("worker", err));
|
|
388
386
|
// A caller that calls stop() right after start() otherwise races the
|
|
389
387
|
// still-settling blocking connection: it rejects in-flight commands
|
|
390
388
|
// via ioredis's flushQueue() during close(), which isn't a listenable
|
|
@@ -423,7 +421,7 @@ export function createJobRunner(options) {
|
|
|
423
421
|
});
|
|
424
422
|
});
|
|
425
423
|
await upsertCronSchedulers(consumerQueue, consumerLane);
|
|
426
|
-
await removeOrphanJobSchedulers(consumerQueue, expectedSchedulerIds, consumerLane, {
|
|
424
|
+
await removeOrphanJobSchedulers(consumerQueue, expectedSchedulerIds, cronSchedulerIdsForLane(consumerLane, true), consumerLane, {
|
|
427
425
|
info: (msg, data) => context.log ? context.log.info(msg, data) : errorLogger.debug(msg, data),
|
|
428
426
|
warn: errorLogger.warn,
|
|
429
427
|
});
|