@cosmicdrift/kumiko-samples 0.414.0 → 0.415.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/package.json +1 -1
- package/packages/bundled-features/package.json +1 -1
- package/packages/bundled-features/src/auth-email-password/signup-token-store.ts +2 -3
- package/packages/bundled-features/src/auth-email-password/web/session.tsx +2 -1
- package/packages/bundled-features/src/auth-mfa/changes.json +6 -0
- package/packages/bundled-features/src/billing-foundation/changes.json +24 -0
- package/packages/bundled-features/src/billing-foundation/checkout-core.ts +11 -0
- package/packages/bundled-features/src/billing-foundation/checkout-ledger.ts +8 -0
- package/packages/bundled-features/src/billing-foundation/events.ts +7 -5
- package/packages/bundled-features/src/billing-foundation/handlers/create-checkout-session.write.ts +2 -0
- package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +76 -24
- package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +5 -4
- package/packages/bundled-features/src/billing-foundation/handlers/start-plan-checkout.write.ts +2 -0
- package/packages/bundled-features/src/billing-foundation/webhook-handler.ts +2 -2
- package/packages/bundled-features/src/channel-whatsapp/changes.json +24 -0
- package/packages/bundled-features/src/channel-whatsapp/events.ts +4 -3
- package/packages/bundled-features/src/channel-whatsapp/inbound-handlers.ts +23 -2
- package/packages/bundled-features/src/channel-whatsapp/webhook-normalize.ts +27 -6
- package/packages/bundled-features/src/compliance-profiles/changes.json +5 -0
- package/packages/bundled-features/src/compliance-profiles/handlers/set-profile.write.ts +2 -0
- package/packages/bundled-features/src/data-retention/feature.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +6 -0
- package/packages/bundled-features/src/delivery/handlers/opted-in-user-ids.query.ts +12 -3
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +3 -1
- package/packages/bundled-features/src/documents/changes.json +6 -0
- package/packages/bundled-features/src/documents/feature.ts +10 -5
- package/packages/bundled-features/src/form-draft/feature.ts +1 -0
- package/packages/bundled-features/src/helpdesk/changes.json +6 -0
- package/packages/bundled-features/src/helpdesk/feature.ts +1 -0
- package/packages/bundled-features/src/helpdesk/handlers/reply.write.ts +3 -3
- package/packages/bundled-features/src/helpdesk/handlers/report.write.ts +3 -2
- package/packages/bundled-features/src/helpdesk/handlers/submit.write.ts +3 -2
- package/packages/bundled-features/src/helpdesk/legacy-contact-streams.ts +3 -1
- package/packages/bundled-features/src/helpdesk/lib.ts +9 -4
- package/packages/bundled-features/src/inbound-mail-foundation/account-poll.ts +4 -1
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/content-refetch.ts +11 -4
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +18 -9
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +18 -9
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts +2 -1
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/forget-message.write.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message-schema.ts +18 -5
- package/packages/bundled-features/src/inbound-mail-foundation/normalize-inbound-message.ts +22 -8
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +2 -5
- package/packages/bundled-features/src/managed-pages/web/page-edit-screen.tsx +11 -5
- package/packages/bundled-features/src/shared/changes.json +6 -0
- package/packages/bundled-features/src/shared/hmac-signature.ts +4 -2
- package/packages/bundled-features/src/shared/index.ts +2 -1
- package/packages/bundled-features/src/shared/normalize-email.ts +3 -0
- package/packages/bundled-features/src/shared/send-best-effort.ts +16 -6
- package/packages/bundled-features/src/step-dispatcher/changes.json +6 -0
- package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +5 -2
- package/packages/bundled-features/src/step-dispatcher/feature.ts +14 -0
- package/packages/bundled-features/src/step-dispatcher/sweep-abandoned.ts +4 -0
- package/packages/bundled-features/src/subscription-paddle/backfill-checkout-ledger.ts +2 -0
- package/packages/bundled-features/src/subscription-paddle/changes.json +6 -0
- package/packages/bundled-features/src/subscription-paddle/redeliver-legacy-checkout.ts +23 -2
- package/packages/bundled-features/src/subscription-stripe/changes.json +6 -0
- package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +19 -5
- package/packages/bundled-features/src/template-resolver/changes.json +12 -0
- package/packages/bundled-features/src/template-resolver/seeding.ts +37 -7
- package/packages/bundled-features/src/template-resolver/web/web-preview-renderer.tsx +7 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +6 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +34 -16
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +6 -0
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +12 -1
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +1 -0
- package/packages/bundled-features/src/user/resolve-verified-user-email.ts +3 -3
- package/packages/bundled-features/src/user-data-rights/feature.ts +1 -0
- package/packages/bundled-features/src/waitlist/handlers/reject.write.ts +1 -1
- package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +2 -2
- package/packages/bundled-features/src/waitlist/import.ts +2 -1
- package/packages/bundled-features/src/waitlist/lib.ts +1 -5
- package/packages/bundled-features/src/waitlist/link-on-signup.ts +2 -2
- package/packages/bundled-features/src/workflow-runner/changes.json +6 -0
- package/packages/bundled-features/src/workflow-runner/handlers/resume-run.write.ts +4 -2
- package/samples/apps/admin-console/src/app/shell.tsx +1 -0
- package/samples/recipes/crypto-shredding-hr/README.md +11 -0
- package/samples/recipes/crypto-shredding-hr/src/feature.ts +27 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +36 -5
- package/samples/recipes/record-detail-layout/src/order-board.ts +10 -2
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
import { createFallbackLogger } from "@cosmicdrift/kumiko-framework/logging";
|
|
33
33
|
import type { Dispatcher } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
34
34
|
import { runEventStoreSeed, type SeedIfExists } from "@cosmicdrift/kumiko-framework/seeding";
|
|
35
|
+
import { SYSTEM_USER_ID } from "@cosmicdrift/kumiko-types/identifiers";
|
|
35
36
|
import { isPlainObject, propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
36
37
|
import { executor } from "./handlers/shared.ts";
|
|
37
38
|
import { evaluateTemplateWrite } from "./handlers/template-gates.ts";
|
|
@@ -407,20 +408,33 @@ const ALREADY_REMOVED_ERROR_CODES: ReadonlySet<string> = new Set([
|
|
|
407
408
|
|
|
408
409
|
const NOTIFICATION_SLUG_PATTERN = /^([^:]+):notify:[^:]+$/;
|
|
409
410
|
|
|
410
|
-
|
|
411
|
+
type OrphanVerdict = "renamed-away" | "unknown-to-registry" | "not-orphaned";
|
|
412
|
+
|
|
413
|
+
function orphanVerdictOf(registry: Registry, slug: string): OrphanVerdict {
|
|
411
414
|
const feature = NOTIFICATION_SLUG_PATTERN.exec(slug)?.[1];
|
|
412
|
-
if (feature === undefined) return
|
|
415
|
+
if (feature === undefined) return "not-orphaned";
|
|
413
416
|
const notifications = registry.getAllNotifications();
|
|
414
|
-
if (notifications.has(slug)) return
|
|
417
|
+
if (notifications.has(slug)) return "not-orphaned";
|
|
415
418
|
const renamedAway = Array.from(notifications.values()).some((notification) =>
|
|
416
419
|
notification.renamedFrom?.includes(slug),
|
|
417
420
|
);
|
|
418
|
-
|
|
421
|
+
if (renamedAway) return "renamed-away";
|
|
422
|
+
return registry.getFeature(feature) !== undefined ? "unknown-to-registry" : "not-orphaned";
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
// Seeds write as the system user; a row only the system user ever touched still holds seed text.
|
|
426
|
+
function isUneditedSeedRow(row: TemplateResourceRow): boolean {
|
|
427
|
+
return (
|
|
428
|
+
row.insertedById === SYSTEM_USER_ID &&
|
|
429
|
+
(row.modifiedById === null || row.modifiedById === SYSTEM_USER_ID)
|
|
430
|
+
);
|
|
419
431
|
}
|
|
420
432
|
|
|
421
433
|
// A removed or renamed notification leaves its seeded system rows behind; they would keep
|
|
422
|
-
// showing up in the template overview.
|
|
423
|
-
//
|
|
434
|
+
// showing up in the template overview. A notification that is merely unknown to this boot
|
|
435
|
+
// (conditional registration, older pod during a rolling deploy) only loses rows nobody edited.
|
|
436
|
+
// Tenant overrides may hold customer text, so they stay and are only reported. Slugs of
|
|
437
|
+
// unmounted features are not ours to judge.
|
|
424
438
|
async function removeOrphanedNotificationTemplates(
|
|
425
439
|
db: DbConnection,
|
|
426
440
|
registry: Registry,
|
|
@@ -428,7 +442,23 @@ async function removeOrphanedNotificationTemplates(
|
|
|
428
442
|
const rows = await selectMany<TemplateResourceRow>(db, templateResourcesTable, {
|
|
429
443
|
kind: "mail",
|
|
430
444
|
});
|
|
431
|
-
const orphans =
|
|
445
|
+
const orphans: TemplateResourceRow[] = [];
|
|
446
|
+
for (const row of rows) {
|
|
447
|
+
const verdict = orphanVerdictOf(registry, row.slug);
|
|
448
|
+
if (verdict === "not-orphaned") continue;
|
|
449
|
+
if (
|
|
450
|
+
verdict === "unknown-to-registry" &&
|
|
451
|
+
row.tenantId === SYSTEM_TENANT_ID &&
|
|
452
|
+
!isUneditedSeedRow(row)
|
|
453
|
+
) {
|
|
454
|
+
log.warn("edited system template of a notification unknown to this boot is kept", {
|
|
455
|
+
slug: row.slug,
|
|
456
|
+
locale: row.locale,
|
|
457
|
+
});
|
|
458
|
+
continue;
|
|
459
|
+
}
|
|
460
|
+
orphans.push(row);
|
|
461
|
+
}
|
|
432
462
|
// skip: nothing orphaned
|
|
433
463
|
if (orphans.length === 0) return;
|
|
434
464
|
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "@cosmicdrift/kumiko-renderer/web";
|
|
18
18
|
import { isPlainObject } from "@cosmicdrift/kumiko-types/type-guards";
|
|
19
19
|
import { type ReactNode, useState } from "react";
|
|
20
|
+
import { fillDocumentVariables } from "./fill-document-variables.ts";
|
|
20
21
|
import { TemplateResolverQueries } from "./qualified-names.ts";
|
|
21
22
|
import { stringValuesOf } from "./string-values.ts";
|
|
22
23
|
|
|
@@ -117,9 +118,14 @@ export const WebPreviewRenderer: PreviewRenderer = ({
|
|
|
117
118
|
variables,
|
|
118
119
|
}: PreviewRendererProps): ReactNode => {
|
|
119
120
|
const isDocument = editFormat === "document";
|
|
121
|
+
const examples = stringValuesOf(variables);
|
|
120
122
|
return (
|
|
121
123
|
<BodyPreviewFrame
|
|
122
|
-
body={
|
|
124
|
+
body={
|
|
125
|
+
isDocument
|
|
126
|
+
? fillDocumentVariables(content, examples)
|
|
127
|
+
: substituteVariables(content, examples)
|
|
128
|
+
}
|
|
123
129
|
bodyFormat={isDocument ? "document" : "markdown"}
|
|
124
130
|
/>
|
|
125
131
|
);
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Keep-link redemption and the destruction request are serialized",
|
|
6
|
+
"detail": "The inactivity job checks the cycle and files the destruction request in one transaction under an advisory lock that the keep-account handler also takes. If the redemption wins, the job skips the request. If the request wins, the link is rejected as invalid instead of reporting a kept account for a tenant that is already in destroyRequested."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.411.0",
|
|
4
10
|
"type": "improvement",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { fetchOne, type TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
-
import type { JobContext, TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
1
|
+
import { fetchOne, runInOwnTransaction, type TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import type { JobContext, Registry, TenantId } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import { hasMailTranslations, mailT } from "@cosmicdrift/kumiko-framework/i18n";
|
|
4
4
|
import { parseRoles } from "@cosmicdrift/kumiko-framework/utils";
|
|
5
5
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
isInactivityCycleCurrent,
|
|
31
31
|
loadInactivityState,
|
|
32
32
|
loadNewestSessionActivity,
|
|
33
|
+
lockInactivityCycle,
|
|
33
34
|
type StoredInactivityState,
|
|
34
35
|
saveInactivityState,
|
|
35
36
|
} from "./state-store.ts";
|
|
@@ -179,6 +180,35 @@ async function sendWarningMails(args: {
|
|
|
179
180
|
return delivered;
|
|
180
181
|
}
|
|
181
182
|
|
|
183
|
+
// The probes and mails before this are slow; a keep link redeemed meanwhile must not end in a
|
|
184
|
+
// deletion request. Check and request share one transaction under the lock the redemption takes.
|
|
185
|
+
async function requestDestructionUnlessKept(
|
|
186
|
+
ctx: JobContext,
|
|
187
|
+
registry: Registry,
|
|
188
|
+
tenantId: TenantId,
|
|
189
|
+
stored: StoredInactivityState | null,
|
|
190
|
+
now: Temporal.Instant,
|
|
191
|
+
): Promise<boolean> {
|
|
192
|
+
return runInOwnTransaction(ctx.db, async (txDb) => {
|
|
193
|
+
const runner = txDb.unsafeRaw();
|
|
194
|
+
await lockInactivityCycle(runner, tenantId);
|
|
195
|
+
if (stored !== null && !(await isInactivityCycleCurrent(txDb, stored.cycleId))) return false;
|
|
196
|
+
const result = await requestTenantDestruction({
|
|
197
|
+
tenantId,
|
|
198
|
+
actor: ctx.systemUser,
|
|
199
|
+
now,
|
|
200
|
+
db: txDb,
|
|
201
|
+
runner,
|
|
202
|
+
registry,
|
|
203
|
+
revokeSessions: true,
|
|
204
|
+
});
|
|
205
|
+
if (!result.isSuccess) {
|
|
206
|
+
throw new Error(`tenant-inactivity: destruction request for ${tenantId} failed`);
|
|
207
|
+
}
|
|
208
|
+
return true;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
|
|
182
212
|
async function evaluate(
|
|
183
213
|
ctx: JobContext,
|
|
184
214
|
options: TenantInactivityOptions,
|
|
@@ -220,20 +250,8 @@ async function evaluate(
|
|
|
220
250
|
}
|
|
221
251
|
|
|
222
252
|
if (!ctx.registry) throw new Error("tenant-inactivity: ctx.registry required");
|
|
223
|
-
|
|
224
|
-
if (
|
|
225
|
-
const result = await requestTenantDestruction({
|
|
226
|
-
tenantId,
|
|
227
|
-
actor: ctx.systemUser,
|
|
228
|
-
now,
|
|
229
|
-
db: ctx.db,
|
|
230
|
-
runner: ctx.db.unsafeRaw(),
|
|
231
|
-
registry: ctx.registry,
|
|
232
|
-
revokeSessions: true,
|
|
233
|
-
});
|
|
234
|
-
if (!result.isSuccess) {
|
|
235
|
-
throw new Error(`tenant-inactivity: destruction request for ${tenantId} failed`);
|
|
236
|
-
}
|
|
253
|
+
const requested = await requestDestructionUnlessKept(ctx, ctx.registry, tenantId, stored, now);
|
|
254
|
+
if (!requested) return state;
|
|
237
255
|
// If the owner cancels the request, a fresh cycle starts instead of an instant second request.
|
|
238
256
|
return startNewCycle({ ...state, lastActivityAt: now });
|
|
239
257
|
}
|
|
@@ -2,7 +2,9 @@ import { fetchOne, updateMany } from "@cosmicdrift/kumiko-framework/db";
|
|
|
2
2
|
import { defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import { UnprocessableError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
4
|
import * as z from "zod";
|
|
5
|
+
import { tenantTable } from "../../tenant/index.ts";
|
|
5
6
|
import { redeemKeepAccountToken } from "../keep-token.ts";
|
|
7
|
+
import { lockInactivityCycle } from "../state-store.ts";
|
|
6
8
|
import { tenantInactivityStateTable } from "../state-table.ts";
|
|
7
9
|
|
|
8
10
|
const KEEP_ACCOUNT_ESCAPE_HATCH_REASON =
|
|
@@ -37,6 +39,10 @@ export function createKeepAccountHandler(opts: { readonly keepAccountTokenSecret
|
|
|
37
39
|
return row?.cycleId ?? null;
|
|
38
40
|
},
|
|
39
41
|
commitKeep: async (tenantId, cycleId) => {
|
|
42
|
+
await lockInactivityCycle(runner, tenantId);
|
|
43
|
+
// A destruction request that won the lock owns the tenant now; reporting "kept" would be a lie.
|
|
44
|
+
const tenant = await fetchOne<{ status: string }>(runner, tenantTable, { id: tenantId });
|
|
45
|
+
if (tenant?.status !== "active") return false;
|
|
40
46
|
const updated = await updateMany(
|
|
41
47
|
runner,
|
|
42
48
|
tenantInactivityStateTable,
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {
|
|
2
|
+
acquireNamespacedAdvisoryLock,
|
|
3
|
+
type DbRunner,
|
|
4
|
+
type TenantDb,
|
|
5
|
+
} from "@cosmicdrift/kumiko-framework/db";
|
|
2
6
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
3
7
|
import { userSessionTable } from "../sessions/index.ts";
|
|
4
8
|
import type { InactivityState } from "./inactivity-plan.ts";
|
|
@@ -8,6 +12,7 @@ export type StoredInactivityState = InactivityState & { readonly cycleId: string
|
|
|
8
12
|
|
|
9
13
|
type StateRow = StoredInactivityState & { readonly id: string };
|
|
10
14
|
|
|
15
|
+
const CYCLE_LOCK_NAMESPACE = 0x696e6163; // 'inac'
|
|
11
16
|
const EPOCH = Temporal.Instant.fromEpochMilliseconds(0);
|
|
12
17
|
|
|
13
18
|
export async function loadInactivityState(db: TenantDb): Promise<StoredInactivityState | null> {
|
|
@@ -64,6 +69,12 @@ export async function saveInactivityState(
|
|
|
64
69
|
}
|
|
65
70
|
}
|
|
66
71
|
|
|
72
|
+
// Serializes the destruction request against keep-link redemption: both hold this lock while they
|
|
73
|
+
// decide, so exactly one of them wins and the other sees the result.
|
|
74
|
+
export async function lockInactivityCycle(runner: DbRunner, tenantId: string): Promise<void> {
|
|
75
|
+
await acquireNamespacedAdvisoryLock(runner, CYCLE_LOCK_NAMESPACE, tenantId);
|
|
76
|
+
}
|
|
77
|
+
|
|
67
78
|
export async function isInactivityCycleCurrent(db: TenantDb, cycleId: string): Promise<boolean> {
|
|
68
79
|
const row = await db.fetchOne<StateRow>(tenantInactivityStateTable, { tenantId: db.tenantId });
|
|
69
80
|
return !row || row.cycleId === cycleId;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Held-tenant destruction test tolerates the scheduled sweep finishing first",
|
|
6
|
+
"detail": "After the retention job releases a destroyHeld tenant, the scheduled sweep may already have moved it on to destroyed. The test now accepts destroying or destroyed and only asserts the retention override while the status is still destroying, reading the overrides first so the check stays meaningful."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.414.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -157,6 +157,7 @@ export function createTenantLifecycleFeature(): FeatureDefinition {
|
|
|
157
157
|
r.job({
|
|
158
158
|
name: "run-tenant-destruction",
|
|
159
159
|
trigger: { cron: "0 * * * * *", wakesSleepingApp: false },
|
|
160
|
+
irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
|
|
160
161
|
concurrency: "skip",
|
|
161
162
|
escapeHatch: { reason: RUN_TENANT_DESTRUCTION_REASON },
|
|
162
163
|
handler: async (_payload, ctx) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UserDataHookCtx } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
-
import { decryptStoredPii } from "../shared/index.ts";
|
|
2
|
+
import { decryptStoredPii, normalizeEmail } from "../shared/index.ts";
|
|
3
3
|
import { userTable } from "./schema/user.ts";
|
|
4
4
|
|
|
5
5
|
// Only a verified owner may see or erase rows matched by email. Forget keeps emailVerified but has
|
|
@@ -12,6 +12,6 @@ export async function resolveVerifiedUserEmail(
|
|
|
12
12
|
id: ctx.userId,
|
|
13
13
|
});
|
|
14
14
|
if (row?.emailVerified !== true) return null;
|
|
15
|
-
if (ctx.userEmailBeforeDelete) return ctx.userEmailBeforeDelete
|
|
16
|
-
return (await decryptStoredPii(row.email, "email", piiDecryptReason))
|
|
15
|
+
if (ctx.userEmailBeforeDelete) return normalizeEmail(ctx.userEmailBeforeDelete);
|
|
16
|
+
return normalizeEmail(await decryptStoredPii(row.email, "email", piiDecryptReason));
|
|
17
17
|
}
|
|
@@ -708,6 +708,7 @@ export function createUserDataRightsFeature(opts: UserDataRightsOptions = {}): F
|
|
|
708
708
|
r.job({
|
|
709
709
|
name: "run-forget-cleanup",
|
|
710
710
|
trigger: { maintenance: true },
|
|
711
|
+
irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
|
|
711
712
|
concurrency: "skip",
|
|
712
713
|
escapeHatch: { reason: RUN_FORGET_CLEANUP_REASON },
|
|
713
714
|
handler: async (_payload, ctx) => {
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
type WriteFailure,
|
|
13
13
|
writeFailure,
|
|
14
14
|
} from "@cosmicdrift/kumiko-framework/errors";
|
|
15
|
+
import { normalizeEmail } from "../../shared/index.ts";
|
|
15
16
|
import {
|
|
16
17
|
cancelPendingInvitation,
|
|
17
18
|
INVITATION_STATUS,
|
|
@@ -21,7 +22,6 @@ import { isOpenWaitlistStatus } from "../entity.ts";
|
|
|
21
22
|
import {
|
|
22
23
|
adminAccess,
|
|
23
24
|
isTenantMember,
|
|
24
|
-
normalizeEmail,
|
|
25
25
|
platformActor,
|
|
26
26
|
waitlistDb,
|
|
27
27
|
waitlistExecutor,
|
|
@@ -12,8 +12,8 @@ import {
|
|
|
12
12
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
13
13
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
14
14
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
15
|
-
import { sendBestEffort } from "../../shared/index.ts";
|
|
16
|
-
import {
|
|
15
|
+
import { normalizeEmail, sendBestEffort } from "../../shared/index.ts";
|
|
16
|
+
import { platformActor, waitlistDb, waitlistExecutor } from "../lib.ts";
|
|
17
17
|
import {
|
|
18
18
|
resolveWaitlistMailLocale,
|
|
19
19
|
waitlistAdminNoticeVariables,
|
|
@@ -2,7 +2,8 @@ import { createHash } from "node:crypto";
|
|
|
2
2
|
import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
3
3
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
4
|
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
5
|
-
import { normalizeEmail
|
|
5
|
+
import { normalizeEmail } from "../shared/index.ts";
|
|
6
|
+
import { platformActor, waitlistExecutor } from "./lib.ts";
|
|
6
7
|
import { WAITLIST_FIELD_LIMITS, type WaitlistStatus } from "./web/constants.ts";
|
|
7
8
|
|
|
8
9
|
export type WaitlistImportEntry = {
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
SYSTEM_TENANT_ID,
|
|
12
12
|
type TenantId,
|
|
13
13
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
14
|
-
import { acknowledgedSystemDb } from "../shared/index.ts";
|
|
14
|
+
import { acknowledgedSystemDb, normalizeEmail } from "../shared/index.ts";
|
|
15
15
|
import { tenantMembershipsTable } from "../tenant/index.ts";
|
|
16
16
|
import { userTable } from "../user/index.ts";
|
|
17
17
|
import { waitlistEntryEntity, waitlistEntryTable } from "./entity.ts";
|
|
@@ -24,10 +24,6 @@ export const waitlistExecutor = createEventStoreExecutor(waitlistEntryTable, wai
|
|
|
24
24
|
entityName: "waitlistEntry",
|
|
25
25
|
});
|
|
26
26
|
|
|
27
|
-
export function normalizeEmail(email: string): string {
|
|
28
|
-
return email.toLowerCase();
|
|
29
|
-
}
|
|
30
|
-
|
|
31
27
|
export function waitlistDb(ctx: Pick<AppContext, "systemDb">): TenantDb {
|
|
32
28
|
return acknowledgedSystemDb(ctx, "waitlist", WAITLIST_CROSS_TENANT_REASON);
|
|
33
29
|
}
|
|
@@ -7,10 +7,10 @@ import {
|
|
|
7
7
|
import { type MultiStreamApplyFn, SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
|
|
8
8
|
import { parseRoles } from "@cosmicdrift/kumiko-framework/utils";
|
|
9
9
|
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
10
|
-
import { decryptStoredPii } from "../shared/index.ts";
|
|
10
|
+
import { decryptStoredPii, normalizeEmail } from "../shared/index.ts";
|
|
11
11
|
import { tenantMembershipsTable } from "../tenant/index.ts";
|
|
12
12
|
import { userTable } from "../user/index.ts";
|
|
13
|
-
import {
|
|
13
|
+
import { platformActor, waitlistExecutor } from "./lib.ts";
|
|
14
14
|
import { DEFAULT_OWN_TENANT_INVITE_ROLE, WAITLIST_STATUS } from "./web/constants.ts";
|
|
15
15
|
|
|
16
16
|
const PII_DECRYPT_REASON = "waitlist:link-on-signup";
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "Resumed steps receive a registered TenantDb",
|
|
6
|
+
"detail": "The resume-run handler handed steps a spread copy of the tenant db. Framework helpers that look a TenantDb up by identity (executors, runInOwnTransaction) rejected that copy with \"TenantDb not built by createTenantDb\". The steps now get the same db with outsideTransaction dropped in place."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.391.1",
|
|
4
10
|
"type": "improvement",
|
|
@@ -32,6 +32,7 @@
|
|
|
32
32
|
|
|
33
33
|
import { fetchOne, type TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
34
34
|
import {
|
|
35
|
+
attachOutsideTransaction,
|
|
35
36
|
buildPipelineSteps,
|
|
36
37
|
computeDefinitionFingerprint,
|
|
37
38
|
describeWorkflowStepError,
|
|
@@ -362,11 +363,12 @@ async function runResumedPipeline(ctx: HandlerContext, db: TenantDb, input: Resu
|
|
|
362
363
|
stepIndex,
|
|
363
364
|
);
|
|
364
365
|
|
|
365
|
-
// The handler is system-scoped, so ctx.db is unusable; the steps
|
|
366
|
+
// The handler is system-scoped, so ctx.db is unusable; the steps get the tenant db without
|
|
367
|
+
// outsideTransaction. Dropped in place: a copy would fall out of the identity-keyed TenantDb registries.
|
|
366
368
|
const outcome = await runStepList(
|
|
367
369
|
steps,
|
|
368
370
|
triggerEvent,
|
|
369
|
-
{ ...ctx, db:
|
|
371
|
+
{ ...ctx, db: attachOutsideTransaction(db, undefined) },
|
|
370
372
|
stepsAcc,
|
|
371
373
|
{},
|
|
372
374
|
workflowCtx,
|
|
@@ -72,3 +72,14 @@ deletion grace period.
|
|
|
72
72
|
blind index immediately (`nullBlindIndexesForSubject`), and every
|
|
73
73
|
projection rebuild recomputes it from the (now undecryptable) ciphertext
|
|
74
74
|
to `NULL`.
|
|
75
|
+
|
|
76
|
+
## Irreversible operations in jobs
|
|
77
|
+
|
|
78
|
+
`forget`, hard deletes, `kms.eraseKey` and writes to `readAsInstruction` fields are gated: they run only from a
|
|
79
|
+
handler marked `agent: { risk: "high" }`. A job or an event consumer has no handler entry, so it must declare
|
|
80
|
+
`irreversibleWithoutEntryHandler` on `r.job` or `r.multiStreamProjection`, or the gate refuses with
|
|
81
|
+
`irreversible_operation_without_entry_handler`. The value names why no entry handler exists:
|
|
82
|
+
`rebuildable-derived-data` (the data is derived and a rebuild recreates it), `high-risk-or-cron-pipeline`
|
|
83
|
+
(a maintenance pipeline that is high-risk by design, like `purge-archived-comments`) or
|
|
84
|
+
`per-dispatch-record-key` (the key belongs to one dispatch record). Hooks and routes never inherit the
|
|
85
|
+
declaration; they dispatch a `risk: "high"` handler instead.
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { buildEntityTable, createEventStoreExecutor } from "@cosmicdrift/kumiko-framework/db";
|
|
1
2
|
import { createEntity, createTextField, defineFeature } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import * as z from "zod";
|
|
2
4
|
|
|
3
5
|
export const employeeEntity = createEntity({
|
|
4
6
|
table: "read_hr_employees",
|
|
@@ -20,6 +22,13 @@ export const hrCommentEntity = createEntity({
|
|
|
20
22
|
softDelete: true,
|
|
21
23
|
});
|
|
22
24
|
|
|
25
|
+
const hrCommentTable = buildEntityTable("hr-comment", hrCommentEntity);
|
|
26
|
+
const hrCommentExecutor = createEventStoreExecutor(hrCommentTable, hrCommentEntity, {
|
|
27
|
+
entityName: "hr-comment",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const purgeArchivedCommentsPayload = z.object({ commentIds: z.array(z.uuid()) });
|
|
31
|
+
|
|
23
32
|
const hrWrite = { access: { roles: ["Admin"] } } as const;
|
|
24
33
|
const hrRead = { access: { roles: ["Admin"] } } as const;
|
|
25
34
|
|
|
@@ -35,4 +44,22 @@ export const hrFeature = defineFeature("hr", (r) => {
|
|
|
35
44
|
read: hrRead,
|
|
36
45
|
verbs: { update: false, delete: false, restore: false, list: false },
|
|
37
46
|
});
|
|
47
|
+
|
|
48
|
+
// A job runs without a write-handler entry, so the irreversible-operation gate refuses
|
|
49
|
+
// `forget` here unless the job declares why it may. Remove the declaration and the run fails.
|
|
50
|
+
r.job(
|
|
51
|
+
"purge-archived-comments",
|
|
52
|
+
{
|
|
53
|
+
trigger: { maintenance: true },
|
|
54
|
+
runIn: "worker",
|
|
55
|
+
irreversibleWithoutEntryHandler: "high-risk-or-cron-pipeline",
|
|
56
|
+
},
|
|
57
|
+
async (payload, ctx) => {
|
|
58
|
+
const { commentIds } = purgeArchivedCommentsPayload.parse(payload);
|
|
59
|
+
for (const id of commentIds) {
|
|
60
|
+
const result = await hrCommentExecutor.forget({ id }, ctx.systemUser, ctx.db);
|
|
61
|
+
if (!result.isSuccess) throw new Error(`purge of hr-comment ${id} failed`);
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
);
|
|
38
65
|
});
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
// 10. `focus: true` gives the detail a focused shell; phones get a top bar with the
|
|
28
28
|
// record title, a back arrow to the list and the page-header overflow menu.
|
|
29
29
|
//
|
|
30
|
+
// 11. Phone card values: two `showOnNarrowOnly` columns with `narrowInline` stand side by side on one line.
|
|
31
|
+
// The named-filter select sits behind the filter icon on phones (`narrowPlacement: "behind-filter"`),
|
|
32
|
+
// and the "reminder due" empty state fills its description from a query (`emptyState.paramsQuery`).
|
|
33
|
+
//
|
|
30
34
|
// projectionDetail binds to an explicit query, not an entity: every field name below
|
|
31
35
|
// (header, metrics, fields) is a column of that query's row.
|
|
32
36
|
|
|
@@ -37,6 +41,7 @@ import {
|
|
|
37
41
|
answerCustomers,
|
|
38
42
|
answerDeadlines,
|
|
39
43
|
answerMoney,
|
|
44
|
+
answerNextReminder,
|
|
40
45
|
answerNowList,
|
|
41
46
|
answerOrderDetail,
|
|
42
47
|
answerOrderList,
|
|
@@ -76,6 +81,13 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
76
81
|
access: accessRoles,
|
|
77
82
|
});
|
|
78
83
|
|
|
84
|
+
r.queryHandler({
|
|
85
|
+
name: "order:next-reminder",
|
|
86
|
+
schema: noPayloadSchema,
|
|
87
|
+
handler: async () => answerNextReminder(),
|
|
88
|
+
access: accessRoles,
|
|
89
|
+
});
|
|
90
|
+
|
|
79
91
|
r.queryHandler({
|
|
80
92
|
name: "order:briefing",
|
|
81
93
|
schema: noPayloadSchema,
|
|
@@ -163,6 +175,7 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
163
175
|
"order-desk.orders.nothing-open": { en: "Nothing to do" },
|
|
164
176
|
"order-desk.orders.all-done": { en: "All done" },
|
|
165
177
|
"order-desk.orders.all-done-hint": { en: "No order needs you right now." },
|
|
178
|
+
"order-desk.orders.next-reminder": { en: "Next reminder: {customer}, due {due}." },
|
|
166
179
|
"order-desk.filter.action-needed": { en: "Needs action" },
|
|
167
180
|
"order-desk.filter.reminder-due": { en: "Reminder due" },
|
|
168
181
|
"order-desk.filter.ending-soon": { en: "Ending soon" },
|
|
@@ -188,7 +201,8 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
188
201
|
"order-desk.today.inbox-link": { en: "All orders" },
|
|
189
202
|
"order-desk.today.deadlines": { en: "Deadlines" },
|
|
190
203
|
"order-desk.today.deadlines-all": { en: "All deadlines" },
|
|
191
|
-
"order-desk.col.narrow-
|
|
204
|
+
"order-desk.col.narrow-open": { en: "Open amount" },
|
|
205
|
+
"order-desk.col.narrow-status": { en: "Status" },
|
|
192
206
|
"order-desk.today.customers": { en: "Customers" },
|
|
193
207
|
"order-desk.today.money": { en: "Money" },
|
|
194
208
|
"order-desk.today.money-sub": { en: "Across all open orders" },
|
|
@@ -232,7 +246,7 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
232
246
|
rowToneField: "tone",
|
|
233
247
|
columns: [
|
|
234
248
|
{ field: "orderNumber", label: "order-desk.col.order" },
|
|
235
|
-
{ field: "customerName", label: "order-desk.col.customer" },
|
|
249
|
+
{ field: "customerName", label: "order-desk.col.customer", hideOnNarrow: true },
|
|
236
250
|
{
|
|
237
251
|
field: "urgencyLabel",
|
|
238
252
|
label: "order-desk.col.urgency",
|
|
@@ -254,7 +268,18 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
254
268
|
minWidth: 240,
|
|
255
269
|
},
|
|
256
270
|
{ field: "openAmount", label: "order-desk.col.open-amount", hideOnNarrow: true },
|
|
257
|
-
{
|
|
271
|
+
{
|
|
272
|
+
field: "narrowOpen",
|
|
273
|
+
label: "order-desk.col.narrow-open",
|
|
274
|
+
showOnNarrowOnly: true,
|
|
275
|
+
narrowInline: true,
|
|
276
|
+
},
|
|
277
|
+
{
|
|
278
|
+
field: "narrowStatus",
|
|
279
|
+
label: "order-desk.col.narrow-status",
|
|
280
|
+
showOnNarrowOnly: true,
|
|
281
|
+
narrowInline: true,
|
|
282
|
+
},
|
|
258
283
|
],
|
|
259
284
|
defaultSort: { field: "urgency", dir: "desc" },
|
|
260
285
|
sortOptions: [
|
|
@@ -276,12 +301,18 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
276
301
|
label: "order-desk.filter.reminder-due",
|
|
277
302
|
emptyState: {
|
|
278
303
|
title: "order-desk.orders.all-done",
|
|
279
|
-
description: "order-desk.orders.
|
|
304
|
+
description: "order-desk.orders.next-reminder",
|
|
305
|
+
paramsQuery: "order-desk:query:order:next-reminder",
|
|
280
306
|
},
|
|
281
307
|
},
|
|
282
308
|
{ id: "ending-soon", label: "order-desk.filter.ending-soon" },
|
|
283
309
|
],
|
|
284
|
-
namedFilterFacet: {
|
|
310
|
+
namedFilterFacet: {
|
|
311
|
+
display: "select",
|
|
312
|
+
showCounts: true,
|
|
313
|
+
label: "order-desk.orders.todo",
|
|
314
|
+
narrowPlacement: "behind-filter",
|
|
315
|
+
},
|
|
285
316
|
narrowFacets: "pills",
|
|
286
317
|
table: {
|
|
287
318
|
frame: "card",
|
|
@@ -266,7 +266,8 @@ export type OrderListAnswer =
|
|
|
266
266
|
}
|
|
267
267
|
| {
|
|
268
268
|
readonly rows: readonly (OrderRow & {
|
|
269
|
-
readonly
|
|
269
|
+
readonly narrowOpen: string;
|
|
270
|
+
readonly narrowStatus: string;
|
|
270
271
|
readonly actionScreen?: string;
|
|
271
272
|
readonly actionParams?: { readonly entityId: string };
|
|
272
273
|
})[];
|
|
@@ -294,7 +295,8 @@ export function answerOrderList(payload: OrderListPayload): OrderListAnswer {
|
|
|
294
295
|
const offset = payload.offset ?? 0;
|
|
295
296
|
const rows = ordered.slice(offset, offset + (payload.limit ?? DEFAULT_PAGE_SIZE)).map((row) => ({
|
|
296
297
|
...row,
|
|
297
|
-
|
|
298
|
+
narrowOpen: `${euro(row.openAmount)} open`,
|
|
299
|
+
narrowStatus: row.status,
|
|
298
300
|
nextStepShort: row.nextStepDue === "" ? "" : `${row.nextStepDue} · ${euro(row.openAmount)}`,
|
|
299
301
|
...(row.nextStep !== "" && {
|
|
300
302
|
actionScreen: ORDER_DETAIL_SCREEN_QN,
|
|
@@ -349,6 +351,12 @@ export function answerNowList() {
|
|
|
349
351
|
};
|
|
350
352
|
}
|
|
351
353
|
|
|
354
|
+
// The params of the "reminder due" empty state; null while no order is waiting for a reminder.
|
|
355
|
+
export function answerNextReminder(): { readonly customer: string; readonly due: string } | null {
|
|
356
|
+
const next = ORDER_ROWS.find((row) => row.canRemind);
|
|
357
|
+
return next === undefined ? null : { customer: next.customerName, due: next.nextStepDue };
|
|
358
|
+
}
|
|
359
|
+
|
|
352
360
|
export function answerBriefing() {
|
|
353
361
|
const open = actionNeededRows(ORDER_ROWS.length);
|
|
354
362
|
const [first] = open;
|