@cosmicdrift/kumiko-samples 0.406.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/package.json +1 -1
- package/packages/bundled-features/package.json +26 -4
- package/packages/bundled-features/src/account-security/feature.ts +9 -1
- package/packages/bundled-features/src/admin-shell/changes.json +6 -0
- package/packages/bundled-features/src/admin-shell/feature.ts +4 -1
- package/packages/bundled-features/src/agent-tools/agent-manifest.ts +1 -0
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +1 -0
- package/packages/bundled-features/src/agent-tools/types.ts +4 -0
- package/packages/bundled-features/src/audit/event-classification.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/bootstrap.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/errors.ts +18 -66
- package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +30 -64
- package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +2 -2
- package/packages/bundled-features/src/auth-email-password/web/confirm-account-unlock-screen.tsx +20 -66
- package/packages/bundled-features/src/auth-email-password/web/index.ts +1 -0
- package/packages/bundled-features/src/auth-email-password/web/read-path-param.ts +8 -0
- package/packages/bundled-features/src/auth-email-password/web/return-path.ts +3 -2
- package/packages/bundled-features/src/auth-email-password/web/token-confirm-screen.tsx +97 -0
- package/packages/bundled-features/src/auth-email-password/web/verify-email-screen.tsx +20 -68
- package/packages/bundled-features/src/auth-foundation/boot-checks.ts +22 -15
- package/packages/bundled-features/src/auth-foundation/boot-rules.ts +33 -0
- package/packages/bundled-features/src/auth-mfa/errors.ts +12 -42
- package/packages/bundled-features/src/auth-mfa/feature-exports.ts +6 -45
- package/packages/bundled-features/src/auth-mfa/feature.ts +8 -19
- package/packages/bundled-features/src/auth-mfa/web/mfa-client.ts +19 -33
- package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-notify.ts +1 -0
- package/packages/bundled-features/src/billing-foundation/web/plan-price.ts +20 -7
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/changes.json +7 -0
- package/packages/bundled-features/src/channel-in-app/feature.ts +2 -0
- package/packages/bundled-features/src/channel-in-app/handlers/read-state-by-keys.query.ts +35 -0
- package/packages/bundled-features/src/channel-in-app/in-app-channel.ts +1 -0
- package/packages/bundled-features/src/channel-in-app/tables.ts +5 -1
- package/packages/bundled-features/src/contact/challenge.ts +41 -0
- package/packages/bundled-features/src/contact/changes.json +27 -0
- package/packages/bundled-features/src/contact/client/contact-client-source.ts +203 -0
- package/packages/bundled-features/src/contact/entity.ts +168 -0
- package/packages/bundled-features/src/contact/feature.ts +171 -0
- package/packages/bundled-features/src/contact/handlers/access.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/attempts.ts +76 -0
- package/packages/bundled-features/src/contact/handlers/challenge.query.ts +44 -0
- package/packages/bundled-features/src/contact/handlers/forward-request.write.ts +98 -0
- package/packages/bundled-features/src/contact/handlers/mark-done.write.ts +40 -0
- package/packages/bundled-features/src/contact/handlers/notify-reporter-in-app.write.ts +48 -0
- package/packages/bundled-features/src/contact/handlers/open-count.query.ts +15 -0
- package/packages/bundled-features/src/contact/handlers/open-count.ts +17 -0
- package/packages/bundled-features/src/contact/handlers/replies.query.ts +29 -0
- package/packages/bundled-features/src/contact/handlers/reply.write.ts +197 -0
- package/packages/bundled-features/src/contact/handlers/report.write.ts +126 -0
- package/packages/bundled-features/src/contact/handlers/request-delivery.query.ts +143 -0
- package/packages/bundled-features/src/contact/handlers/request-detail.query.ts +50 -0
- package/packages/bundled-features/src/contact/handlers/request-list.query.ts +14 -0
- package/packages/bundled-features/src/contact/handlers/send-reply-mail.write.ts +124 -0
- package/packages/bundled-features/src/contact/handlers/send-test.write.ts +45 -0
- package/packages/bundled-features/src/contact/handlers/submit.write.ts +194 -0
- package/packages/bundled-features/src/contact/handlers/take-over-uploads.ts +47 -0
- package/packages/bundled-features/src/contact/i18n.ts +189 -0
- package/packages/bundled-features/src/contact/index.ts +29 -0
- package/packages/bundled-features/src/contact/lib.ts +176 -0
- package/packages/bundled-features/src/contact/mail.ts +401 -0
- package/packages/bundled-features/src/contact/options.ts +95 -0
- package/packages/bundled-features/src/contact/panels.ts +28 -0
- package/packages/bundled-features/src/contact/payloads.ts +106 -0
- package/packages/bundled-features/src/contact/pow.ts +22 -0
- package/packages/bundled-features/src/contact/screens.ts +506 -0
- package/packages/bundled-features/src/contact/subject.ts +13 -0
- package/packages/bundled-features/src/contact/user-agent.ts +39 -0
- package/packages/bundled-features/src/contact/user-data-hooks.ts +180 -0
- package/packages/bundled-features/src/contact/web/constants.ts +160 -0
- package/packages/bundled-features/src/contact/web/index.ts +29 -0
- package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +5 -16
- package/packages/bundled-features/src/data-retention/changes.json +6 -0
- package/packages/bundled-features/src/data-retention/feature.ts +16 -2
- package/packages/bundled-features/src/data-retention/index.ts +5 -0
- package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +138 -41
- package/packages/bundled-features/src/data-retention/tenant-destruction-hold.ts +196 -0
- package/packages/bundled-features/src/delivery/address-opt-out.ts +1 -0
- package/packages/bundled-features/src/delivery/changes.json +7 -0
- package/packages/bundled-features/src/delivery/channel-context.ts +2 -0
- package/packages/bundled-features/src/delivery/delivery-service.ts +29 -5
- package/packages/bundled-features/src/delivery/events.ts +2 -0
- package/packages/bundled-features/src/delivery/feature.ts +3 -2
- package/packages/bundled-features/src/delivery/handlers/attempts-by-keys.query.ts +55 -0
- package/packages/bundled-features/src/delivery/handlers/log.query.ts +1 -1
- package/packages/bundled-features/src/delivery/jobs.ts +5 -0
- package/packages/bundled-features/src/delivery/tables.ts +13 -2
- package/packages/bundled-features/src/delivery/types.ts +3 -0
- package/packages/bundled-features/src/delivery/unsubscribe-page.ts +2 -0
- package/packages/bundled-features/src/delivery/web/delivery-channel-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-error-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-status-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/delivery-time-cell.tsx +3 -2
- package/packages/bundled-features/src/delivery/web/delivery-type-cell.tsx +1 -1
- package/packages/bundled-features/src/delivery/web/public-names.ts +1 -0
- package/packages/bundled-features/src/document-ingest-foundation/boot-checks.ts +14 -9
- package/packages/bundled-features/src/document-ingest-foundation/boot-rules.ts +22 -0
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/events.ts +17 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +39 -1
- package/packages/bundled-features/src/document-ingest-foundation/index.ts +10 -0
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +43 -0
- package/packages/bundled-features/src/document-ingest-foundation/tables.ts +43 -0
- package/packages/bundled-features/src/files-tenant-data/changes.json +6 -0
- package/packages/bundled-features/src/files-tenant-data/hooks.ts +4 -1
- package/packages/bundled-features/src/folders/web/folder-manager.tsx +8 -9
- package/packages/bundled-features/src/folders/web/folder-section.tsx +1 -1
- package/packages/bundled-features/src/form-draft-user-data/index.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/changes.json +13 -0
- package/packages/bundled-features/src/inbound-mail-foundation/entities.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/events.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +6 -6
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/attach-message-content.write.ts +7 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +6 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/list-messages.query.ts +6 -2
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.query.ts +3 -0
- package/packages/bundled-features/src/inbound-mail-foundation/handlers/message-content.ts +19 -0
- package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +2 -0
- package/packages/bundled-features/src/inbound-mail-foundation/sanitize-inbound-html.ts +150 -0
- package/packages/bundled-features/src/inbound-mail-foundation/types.ts +1 -0
- package/packages/bundled-features/src/jobs/job-run-logger.ts +24 -25
- package/packages/bundled-features/src/ledger/handlers/reports.query.ts +46 -31
- package/packages/bundled-features/src/ledger/recurring.ts +1 -0
- package/packages/bundled-features/src/notes-history/web/notes-section.tsx +3 -1
- package/packages/bundled-features/src/personal-access-tokens/feature.ts +9 -17
- package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -7
- package/packages/bundled-features/src/secrets/changes.json +6 -0
- package/packages/bundled-features/src/secrets/handlers/delete.write.ts +8 -4
- package/packages/bundled-features/src/secrets/handlers/list.query.ts +6 -3
- package/packages/bundled-features/src/secrets/handlers/set.write.ts +9 -4
- package/packages/bundled-features/src/secrets/secret-scope.ts +33 -0
- package/packages/bundled-features/src/sessions/changes.json +6 -0
- package/packages/bundled-features/src/sessions/feature.ts +21 -18
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.query.ts +53 -0
- package/packages/bundled-features/src/sessions/handlers/last-activity-probe.route.ts +39 -0
- package/packages/bundled-features/src/sessions/screens.ts +1 -0
- package/packages/bundled-features/src/sessions/session-callbacks.ts +13 -12
- package/packages/bundled-features/src/sessions/web/i18n.ts +4 -1
- package/packages/bundled-features/src/shared/assert-billing-live.ts +14 -0
- package/packages/bundled-features/src/shared/collect-extension-options.ts +12 -0
- package/packages/bundled-features/src/shared/index.ts +16 -0
- package/packages/bundled-features/src/shared/late-bound-slot.ts +19 -0
- package/packages/bundled-features/src/shared/mail-locale-templates.ts +7 -1
- package/packages/bundled-features/src/shared/price-env-shape.ts +44 -0
- package/packages/bundled-features/src/shared/purge-row-file-refs.ts +1 -1
- package/packages/bundled-features/src/shared/read-feature-export-fn.ts +16 -0
- package/packages/bundled-features/src/shared/signup-handover.ts +3 -4
- package/packages/bundled-features/src/shared/tenant-destruction-hold.ts +49 -0
- package/packages/bundled-features/src/shared/unprocessable.ts +19 -0
- package/packages/bundled-features/src/shared/web/index.ts +3 -0
- package/packages/bundled-features/src/subscription-paddle/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-paddle/runtime.ts +4 -7
- package/packages/bundled-features/src/subscription-stripe/feature.ts +7 -15
- package/packages/bundled-features/src/subscription-stripe/runtime.ts +4 -7
- package/packages/bundled-features/src/tags/entity.ts +1 -0
- package/packages/bundled-features/src/tags/web/tag-chip.tsx +14 -0
- package/packages/bundled-features/src/tags/web/tag-filter.tsx +4 -5
- package/packages/bundled-features/src/tags/web/tag-manager.tsx +1 -1
- package/packages/bundled-features/src/tags/web/tag-section.tsx +3 -6
- package/packages/bundled-features/src/tags/web/tags-cell.tsx +4 -5
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +27 -15
- package/packages/bundled-features/src/template-resolver/handlers/by-tenant.query.ts +11 -8
- package/packages/bundled-features/src/template-resolver/handlers/discard-draft.write.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +1 -0
- package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +5 -5
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/linked-resources.ts +11 -6
- package/packages/bundled-features/src/template-resolver/store-template-resource.ts +15 -12
- package/packages/bundled-features/src/template-resolver/web/document-images.ts +6 -6
- package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +41 -36
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +11 -12
- package/packages/bundled-features/src/template-resolver/web/tiptap-attribute-parse-rule.ts +19 -0
- package/packages/bundled-features/src/tenant/i18n.ts +3 -0
- package/packages/bundled-features/src/tenant/schema/tenant.ts +1 -0
- package/packages/bundled-features/src/tenant/web/member-roles-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant/web/member-status-cell.tsx +1 -1
- package/packages/bundled-features/src/tenant-inactivity/changes.json +8 -0
- package/packages/bundled-features/src/tenant-inactivity/check-inactive-tenants.ts +260 -0
- package/packages/bundled-features/src/tenant-inactivity/constants.ts +12 -0
- package/packages/bundled-features/src/tenant-inactivity/email-templates.ts +24 -0
- package/packages/bundled-features/src/tenant-inactivity/feature.ts +66 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/inactivity-state.query.ts +49 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +56 -0
- package/packages/bundled-features/src/tenant-inactivity/inactivity-plan.ts +187 -0
- package/packages/bundled-features/src/tenant-inactivity/index.ts +5 -0
- package/packages/bundled-features/src/tenant-inactivity/keep-token.ts +44 -0
- package/packages/bundled-features/src/tenant-inactivity/mail-notifications.ts +62 -0
- package/packages/bundled-features/src/tenant-inactivity/options.ts +38 -0
- package/packages/bundled-features/src/tenant-inactivity/remote-activity.ts +32 -0
- package/packages/bundled-features/src/tenant-inactivity/state-store.ts +71 -0
- package/packages/bundled-features/src/tenant-inactivity/state-table.ts +50 -0
- package/packages/bundled-features/src/tenant-lifecycle/boot-checks.ts +8 -6
- package/packages/bundled-features/src/tenant-lifecycle/boot-rules.ts +16 -0
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +18 -0
- package/packages/bundled-features/src/tenant-lifecycle/feature.ts +24 -1
- package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +12 -87
- package/packages/bundled-features/src/tenant-lifecycle/index.ts +4 -0
- package/packages/bundled-features/src/tenant-lifecycle/request-tenant-destruction.ts +108 -0
- package/packages/bundled-features/src/tenant-lifecycle/retention-config-destroy-hooks.ts +62 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +58 -5
- package/packages/bundled-features/src/tenant-lifecycle/stages.ts +31 -2
- package/packages/bundled-features/src/tenant-lifecycle/testing.ts +1 -1
- package/packages/bundled-features/src/tier-engine/caps-for-tier-from-map.ts +16 -0
- package/packages/bundled-features/src/tier-engine/changes.json +6 -0
- package/packages/bundled-features/src/tier-engine/compose-app.ts +21 -20
- package/packages/bundled-features/src/tier-engine/index.ts +1 -0
- package/packages/bundled-features/src/user-data-rights/feature.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +2 -0
- package/packages/bundled-features/src/user-data-rights/web/privacy-center-screen.tsx +1 -1
- package/packages/bundled-features/src/user-data-rights/zip-path.ts +1 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/config-value.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/delivery-attempt.userdata-hook.ts +11 -8
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/forget-own-rows-delete-hook.ts +42 -0
- package/packages/bundled-features/src/user-data-rights-defaults/hooks/notification-preference.userdata-hook.ts +8 -27
- package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +2 -6
- package/packages/bundled-features/src/user-profile/web/profile-screen.tsx +2 -3
- package/samples/apps/styleguide/src/features/widgets/i18n.ts +6 -0
- package/samples/apps/styleguide/src/features/widgets/web/InboxReaderExamples.tsx +158 -0
- package/samples/apps/styleguide/src/features/widgets/web/Widgets.tsx +2 -0
- package/samples/apps/styleguide/src/features/widgets/web/sample-pdf.ts +28 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +134 -2
- package/samples/apps/use-all-bundled/kumiko/migrations/0063_contact.rebuild.json +4 -0
- package/samples/apps/use-all-bundled/package.json +1 -0
- package/samples/apps/use-all-bundled/playwright.config.ts +2 -0
- package/samples/apps/use-all-bundled/src/app/client.tsx +3 -0
- package/samples/apps/use-all-bundled/src/app/screens-feature.ts +46 -2
- package/samples/apps/use-all-bundled/src/run-config.ts +38 -4
- package/samples/recipes/contact/README.md +46 -0
- package/samples/recipes/contact/package.json +12 -0
- package/samples/recipes/contact/src/feature.ts +27 -0
- package/samples/recipes/delivery-notifications/src/feature.ts +3 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +9 -1
- package/samples/recipes/search/README.md +2 -0
- package/samples/recipes/search/src/feature.ts +27 -2
- package/samples/recipes/secrets-demo/README.md +1 -0
- package/samples/recipes/secrets-demo/src/feature.ts +56 -0
- package/samples/recipes/tenant-inactivity/README.md +21 -0
- package/samples/recipes/tenant-inactivity/package.json +12 -0
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
DeliveryQueries,
|
|
25
25
|
} from "./constants.ts";
|
|
26
26
|
import { deliveryAttemptAddressErasedSchema, deliveryAttemptSchema } from "./events.ts";
|
|
27
|
+
import { attemptsByKeysQuery } from "./handlers/attempts-by-keys.query.ts";
|
|
27
28
|
import { logQuery } from "./handlers/log.query.ts";
|
|
28
29
|
import { preferencesQuery } from "./handlers/preferences.query.ts";
|
|
29
30
|
import { resubscribeAddressWrite } from "./handlers/resubscribe-address.write.ts";
|
|
@@ -153,6 +154,7 @@ export function createDeliveryFeature(options?: DeliveryFeatureOptions): Feature
|
|
|
153
154
|
error: p.error,
|
|
154
155
|
priority: p.priority,
|
|
155
156
|
confirmed: p.confirmed ?? null,
|
|
157
|
+
idempotencyKey: p.idempotencyKey ?? null,
|
|
156
158
|
},
|
|
157
159
|
{
|
|
158
160
|
status: p.status,
|
|
@@ -216,7 +218,6 @@ export function createDeliveryFeature(options?: DeliveryFeatureOptions): Feature
|
|
|
216
218
|
},
|
|
217
219
|
});
|
|
218
220
|
}
|
|
219
|
-
|
|
220
221
|
const handlers = {
|
|
221
222
|
setPreference: r.writeHandler(setPreferenceWrite),
|
|
222
223
|
unsubscribeAddress: r.writeHandler(unsubscribeAddressWrite),
|
|
@@ -224,10 +225,10 @@ export function createDeliveryFeature(options?: DeliveryFeatureOptions): Feature
|
|
|
224
225
|
resubscribeAddress: r.writeHandler(resubscribeAddressWrite),
|
|
225
226
|
resubscribeUser: r.writeHandler(resubscribeUserWrite),
|
|
226
227
|
};
|
|
227
|
-
|
|
228
228
|
const queries = {
|
|
229
229
|
log: r.queryHandler({ ...logQuery, access: { roles: resolvedAccess } }),
|
|
230
230
|
preferences: r.queryHandler(preferencesQuery),
|
|
231
|
+
attemptsByKeys: r.queryHandler(attemptsByKeysQuery),
|
|
231
232
|
unsubscribePageChrome: r.queryHandler(unsubscribePageChromeQuery),
|
|
232
233
|
};
|
|
233
234
|
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { selectMany } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import { access, defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
4
|
+
import type { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
5
|
+
import * as z from "zod";
|
|
6
|
+
import { deliveryAttemptsTable } from "../tables.ts";
|
|
7
|
+
import { toClientError } from "./log.query.ts";
|
|
8
|
+
|
|
9
|
+
const MAX_KEYS = 50;
|
|
10
|
+
|
|
11
|
+
export const attemptsByKeysQuery = defineQueryHandler({
|
|
12
|
+
name: "attempts-by-keys",
|
|
13
|
+
schema: z.object({ keys: z.array(z.string().min(1).max(256)).min(1).max(MAX_KEYS) }).strict(),
|
|
14
|
+
access: { roles: access.systemAdmin },
|
|
15
|
+
description:
|
|
16
|
+
"Returns the delivery attempts (channel, status, error code, time, recipient id, never an address) recorded for notify() calls made with one of the given idempotency keys, across all tenants; use it to show whether a notification a feature sent under a known key arrived.",
|
|
17
|
+
handler: async (query, ctx) => {
|
|
18
|
+
if (!ctx.systemDb) {
|
|
19
|
+
throw new InternalError({ message: "attempts-by-keys requires ctx.systemDb" });
|
|
20
|
+
}
|
|
21
|
+
const db = ctx.systemDb.acknowledgeCrossTenant(
|
|
22
|
+
"SystemAdmin reads delivery attempts of a notification across tenants",
|
|
23
|
+
);
|
|
24
|
+
const rows = await selectMany<{
|
|
25
|
+
id: string;
|
|
26
|
+
idempotencyKey: string | null;
|
|
27
|
+
notificationType: string;
|
|
28
|
+
channel: string;
|
|
29
|
+
recipientId: string | null;
|
|
30
|
+
status: string;
|
|
31
|
+
error: string | null;
|
|
32
|
+
createdAt: Temporal.Instant;
|
|
33
|
+
}>(
|
|
34
|
+
db,
|
|
35
|
+
deliveryAttemptsTable,
|
|
36
|
+
{ idempotencyKey: { in: query.payload.keys } },
|
|
37
|
+
{ orderBy: [{ col: "createdAt", direction: "asc" }] },
|
|
38
|
+
);
|
|
39
|
+
return {
|
|
40
|
+
rows: rows
|
|
41
|
+
// "*" rows only record that a duplicate key was skipped.
|
|
42
|
+
.filter((row) => row.channel !== "*")
|
|
43
|
+
.map((row) => ({
|
|
44
|
+
id: row.id,
|
|
45
|
+
key: row.idempotencyKey,
|
|
46
|
+
notificationType: row.notificationType,
|
|
47
|
+
channel: row.channel,
|
|
48
|
+
recipientId: row.recipientId,
|
|
49
|
+
status: row.status,
|
|
50
|
+
error: toClientError(row.error),
|
|
51
|
+
createdAt: row.createdAt,
|
|
52
|
+
})),
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
@@ -39,7 +39,7 @@ type DeliveryLogRow = {
|
|
|
39
39
|
createdAt: Temporal.Instant;
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
function toClientError(stored: string | null): DeliveryErrorCode | null {
|
|
42
|
+
export function toClientError(stored: string | null): DeliveryErrorCode | null {
|
|
43
43
|
if (stored === null) return null;
|
|
44
44
|
return isDeliveryErrorCode(stored) ? stored : "channel_error";
|
|
45
45
|
}
|
|
@@ -55,6 +55,8 @@ const renderJobBaseSchema = z.object({
|
|
|
55
55
|
priority: z.enum(["critical", "normal", "low"]),
|
|
56
56
|
message: channelMessageSchema,
|
|
57
57
|
idempotencyKey: z.string().optional(),
|
|
58
|
+
// The notify() key as given, for the channel context; idempotencyKey above is only the release key.
|
|
59
|
+
notifyIdempotencyKey: z.string().optional(),
|
|
58
60
|
});
|
|
59
61
|
|
|
60
62
|
const renderJobPayloadSchema = renderJobBaseSchema.and(recipientAddressFieldSchema);
|
|
@@ -258,6 +260,7 @@ async function renderStep(p: RenderJobPayload, ctx: JobContext): Promise<void> {
|
|
|
258
260
|
ctx.services.secrets,
|
|
259
261
|
ctx.config,
|
|
260
262
|
(fileTenantId) => fileContextForTenant(ctx, ctx.systemUser.tenantId, fileTenantId),
|
|
263
|
+
p.notifyIdempotencyKey,
|
|
261
264
|
);
|
|
262
265
|
|
|
263
266
|
let rendered: RenderedMessage;
|
|
@@ -284,6 +287,7 @@ async function renderStep(p: RenderJobPayload, ctx: JobContext): Promise<void> {
|
|
|
284
287
|
// Deliver via the channel using the rendered payload (if any). On failure:
|
|
285
288
|
// record the terminal failed event and rethrow so BullMQ retries the send with
|
|
286
289
|
// the same already-rendered HTML — no re-render needed.
|
|
290
|
+
// guard:dup-ok one job entry point per step; payload schema and step differ from deliveryRenderJob
|
|
287
291
|
export const deliverySendJob: JobHandlerFn = async (payload, ctx) => {
|
|
288
292
|
const p = sendJobPayloadSchema.parse(payload);
|
|
289
293
|
return releasingKeyOnTerminalFailure(ctx, p, () => sendStep(p, ctx));
|
|
@@ -301,6 +305,7 @@ async function sendStep(p: z.infer<typeof sendJobPayloadSchema>, ctx: JobContext
|
|
|
301
305
|
ctx.services.secrets,
|
|
302
306
|
ctx.config,
|
|
303
307
|
(fileTenantId) => fileContextForTenant(ctx, ctx.systemUser.tenantId, fileTenantId),
|
|
308
|
+
p.notifyIdempotencyKey,
|
|
304
309
|
);
|
|
305
310
|
|
|
306
311
|
try {
|
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
// its event stream 1:1 — same convention as jobRunsTable + tenantSecretsTable.
|
|
31
31
|
// Event replays stay idempotent (primary-key conflict instead of duplicate rows).
|
|
32
32
|
const DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX = "store_delivery_attempts_tenant_id_created_at_idx";
|
|
33
|
+
const DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX =
|
|
34
|
+
"store_delivery_attempts_tenant_id_idempotency_key_idx";
|
|
33
35
|
|
|
34
36
|
export const deliveryAttemptsTable = pgTable(
|
|
35
37
|
"store_delivery_attempts",
|
|
@@ -49,8 +51,13 @@ export const deliveryAttemptsTable = pgTable(
|
|
|
49
51
|
// notify() priority from the event payload.
|
|
50
52
|
priority: text("priority").notNull().default("normal").$type<"critical" | "normal" | "low">(),
|
|
51
53
|
createdAt: instant("created_at").default(sql`now()`).notNull(),
|
|
54
|
+
// Null for attempts of notify() calls without an idempotencyKey and for rows that predate the column.
|
|
55
|
+
idempotencyKey: text("idempotency_key"),
|
|
52
56
|
},
|
|
53
|
-
(t) => [
|
|
57
|
+
(t) => [
|
|
58
|
+
index(DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX).on(t.tenantId, t.createdAt),
|
|
59
|
+
index(DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX).on(t.tenantId, t.idempotencyKey),
|
|
60
|
+
],
|
|
54
61
|
);
|
|
55
62
|
|
|
56
63
|
// **Unmanaged table** — deliberately has no createEntity because:
|
|
@@ -64,7 +71,10 @@ export const deliveryAttemptsTable = pgTable(
|
|
|
64
71
|
// from this metadata.
|
|
65
72
|
export const deliveryAttemptsTableMeta: EntityTableMeta = defineUnmanagedTable({
|
|
66
73
|
tableName: "store_delivery_attempts",
|
|
67
|
-
indexes: [
|
|
74
|
+
indexes: [
|
|
75
|
+
{ name: DELIVERY_ATTEMPTS_TENANT_CREATED_INDEX, columns: ["tenant_id", "created_at"] },
|
|
76
|
+
{ name: DELIVERY_ATTEMPTS_TENANT_IDEMPOTENCY_INDEX, columns: ["tenant_id", "idempotency_key"] },
|
|
77
|
+
],
|
|
68
78
|
columns: [
|
|
69
79
|
{ name: "id", pgType: "uuid", notNull: true, primaryKey: true },
|
|
70
80
|
{ name: "tenant_id", pgType: "uuid", notNull: true },
|
|
@@ -77,6 +87,7 @@ export const deliveryAttemptsTableMeta: EntityTableMeta = defineUnmanagedTable({
|
|
|
77
87
|
{ name: "confirmed", pgType: "boolean", notNull: false },
|
|
78
88
|
{ name: "priority", pgType: "text", notNull: true, defaultSql: "'normal'" },
|
|
79
89
|
{ name: "created_at", pgType: "timestamptz", notNull: true, defaultSql: "now()" },
|
|
90
|
+
{ name: "idempotency_key", pgType: "text", notNull: false },
|
|
80
91
|
],
|
|
81
92
|
});
|
|
82
93
|
|
|
@@ -43,6 +43,8 @@ export type ChannelContext = {
|
|
|
43
43
|
// The tenant's own config accessor, built server-side for this tenantId. Absent when the
|
|
44
44
|
// delivery service has no tenantConfigFor and the job context carries no config.
|
|
45
45
|
readonly config?: ConfigAccessor | undefined;
|
|
46
|
+
// The notify() idempotencyKey of the call, so a channel can store it next to what it sends.
|
|
47
|
+
readonly idempotencyKey?: string | undefined;
|
|
46
48
|
// Renders a stored mail template, the tenant's own or the system fallback.
|
|
47
49
|
readonly renderMail?: (payload: MailPayload) => Promise<RenderedMail>;
|
|
48
50
|
// Reads the bytes behind an attachment ref at send time. Absent when no file storage is wired.
|
|
@@ -121,6 +123,7 @@ export type DeliveryLogEntry = {
|
|
|
121
123
|
readonly error: DeliveryErrorCode | null;
|
|
122
124
|
readonly priority: NotifyPriority;
|
|
123
125
|
readonly confirmed?: false;
|
|
126
|
+
readonly idempotencyKey?: string;
|
|
124
127
|
};
|
|
125
128
|
|
|
126
129
|
// --- Delivery Service ---
|
|
@@ -61,6 +61,7 @@ function linkHtml(link: MailChromeLink): string {
|
|
|
61
61
|
|
|
62
62
|
// The style block is static apart from the validated hex accent and the markup carries
|
|
63
63
|
// no style attributes, so the CSP admits exactly this block by its hash.
|
|
64
|
+
// guard:dup-ok one template-literal stylesheet; only the shape matches unrelated string builders
|
|
64
65
|
function pageStyle(accent: string): string {
|
|
65
66
|
return `@font-face{font-family:"IBM Plex Sans";font-style:normal;font-weight:400;font-display:swap;src:url("${FONT_URL_PREFIX}400.woff2") format("woff2")}
|
|
66
67
|
@font-face{font-family:"IBM Plex Sans";font-style:normal;font-weight:600;font-display:swap;src:url("${FONT_URL_PREFIX}600.woff2") format("woff2")}
|
|
@@ -125,6 +126,7 @@ function footerHtml(chrome: MailChrome): string {
|
|
|
125
126
|
return linesHtml === "" ? "" : `<footer class="footer">${linesHtml}</footer>`;
|
|
126
127
|
}
|
|
127
128
|
|
|
129
|
+
// guard:dup-ok one escaped template-literal form; only the shape matches other HTML snippets
|
|
128
130
|
function tokenForm(action: string, token: string, label: string, variant: string): string {
|
|
129
131
|
return `<form method="post" action="${escapeHtmlAttr(action)}">
|
|
130
132
|
<input type="hidden" name="token" value="${escapeHtmlAttr(token)}">
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import { type ColumnRendererProps, useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
5
5
|
import type { ReactNode } from "react";
|
|
6
|
-
import { translateOrRaw } from "../../shared/web/
|
|
6
|
+
import { translateOrRaw } from "../../shared/web/index.ts";
|
|
7
7
|
|
|
8
8
|
export function DeliveryChannelCell({ row }: ColumnRendererProps): ReactNode {
|
|
9
9
|
const t = useTranslation();
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { type ColumnRendererProps, useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
5
5
|
import { HTTP_ERROR_CODE_PATTERN } from "@cosmicdrift/kumiko-types/handlers";
|
|
6
6
|
import type { ReactNode } from "react";
|
|
7
|
-
import { translateOrRaw } from "../../shared/web/
|
|
7
|
+
import { translateOrRaw } from "../../shared/web/index.ts";
|
|
8
8
|
|
|
9
9
|
export function DeliveryErrorCell({ row }: ColumnRendererProps): ReactNode {
|
|
10
10
|
const t = useTranslation();
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
import { type ColumnRendererProps, useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
7
7
|
import { StatusBadge, type StatusTone } from "@cosmicdrift/kumiko-renderer/web";
|
|
8
8
|
import type { ReactNode } from "react";
|
|
9
|
-
import { translateOrRaw } from "../../shared/web/
|
|
9
|
+
import { translateOrRaw } from "../../shared/web/index.ts";
|
|
10
10
|
import { DeliveryStatus } from "./public-names.ts";
|
|
11
11
|
|
|
12
12
|
const STATUS_TONE: Readonly<Record<string, StatusTone>> = {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { type ColumnRendererProps, formatWhen } from "@cosmicdrift/kumiko-renderer";
|
|
1
|
+
import { type ColumnRendererProps, formatWhen, useLocale } from "@cosmicdrift/kumiko-renderer";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
3
|
|
|
4
4
|
export function DeliveryTimeCell({ row }: ColumnRendererProps): ReactNode {
|
|
5
|
+
const locale = useLocale().locale();
|
|
5
6
|
const createdAt = row["createdAt"];
|
|
6
|
-
return typeof createdAt === "string" ? formatWhen(createdAt) : "";
|
|
7
|
+
return typeof createdAt === "string" ? formatWhen(createdAt, locale) : "";
|
|
7
8
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { type ColumnRendererProps, useTranslation } from "@cosmicdrift/kumiko-renderer";
|
|
7
7
|
import type { ReactNode } from "react";
|
|
8
|
-
import { translateOrRaw } from "../../shared/web/
|
|
8
|
+
import { translateOrRaw } from "../../shared/web/index.ts";
|
|
9
9
|
|
|
10
10
|
const NOTIFICATION_QN_PATTERN = /^([^:]+):notify:(.+)$/;
|
|
11
11
|
|
|
@@ -24,6 +24,7 @@ export const DELIVERY_RESUBSCRIBE_PATH = "/api/delivery/resubscribe" as const;
|
|
|
24
24
|
export const DeliveryQueries = {
|
|
25
25
|
log: "delivery:query:log",
|
|
26
26
|
preferences: "delivery:query:preferences",
|
|
27
|
+
attemptsByKeys: "delivery:query:attempts-by-keys",
|
|
27
28
|
unsubscribePageChrome: "delivery:query:unsubscribe-page-chrome",
|
|
28
29
|
} as const;
|
|
29
30
|
|
|
@@ -3,6 +3,8 @@
|
|
|
3
3
|
// to it — otherwise requested ingests for that provider never get picked up.
|
|
4
4
|
|
|
5
5
|
import type { FeatureDefinition, JobDefinition } from "@cosmicdrift/kumiko-framework/engine";
|
|
6
|
+
import { bootRuleError } from "@cosmicdrift/kumiko-framework/engine";
|
|
7
|
+
import { DOCUMENT_INGEST_BOOT_RULES } from "./boot-rules.ts";
|
|
6
8
|
import { DOCUMENT_INGEST_REQUESTED_EVENT_QN } from "./events.ts";
|
|
7
9
|
import { resolveDocumentIngestProviders } from "./providers.ts";
|
|
8
10
|
|
|
@@ -28,20 +30,22 @@ export function validateDocumentIngestProviderWiring(features: readonly FeatureD
|
|
|
28
30
|
const provider = providerFilterOf(jobDef.trigger);
|
|
29
31
|
if (provider === undefined) continue;
|
|
30
32
|
if (provider === "") {
|
|
31
|
-
throw
|
|
32
|
-
|
|
33
|
+
throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.jobWithoutProviderFilter, {
|
|
34
|
+
message:
|
|
35
|
+
`[kumiko:boot] Job "${jobDef.name}" (feature "${feature.name}") triggers on ` +
|
|
33
36
|
`document-ingest-foundation's documentIngest.requested without a provider filter — every job on ` +
|
|
34
37
|
`this event must route through documentIngestProviderTrigger("<name>"), or it fires for every ` +
|
|
35
38
|
`provider's uploads. Use: trigger: documentIngestProviderTrigger("<name>").`,
|
|
36
|
-
);
|
|
39
|
+
});
|
|
37
40
|
}
|
|
38
41
|
if (!registeredProviderNames.has(provider)) {
|
|
39
|
-
throw
|
|
40
|
-
|
|
42
|
+
throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.jobUnknownProvider, {
|
|
43
|
+
message:
|
|
44
|
+
`[kumiko:boot] Job "${jobDef.name}" (feature "${feature.name}") filters documentIngest.requested to ` +
|
|
41
45
|
`provider "${provider}", but no feature registers that provider via ` +
|
|
42
46
|
`r.useExtension(EXT_DOCUMENT_INGEST_PROVIDER, "${provider}", ...). Known: ` +
|
|
43
47
|
`${[...registeredProviderNames].join(", ") || "<none>"}.`,
|
|
44
|
-
);
|
|
48
|
+
});
|
|
45
49
|
}
|
|
46
50
|
wiredProviderNames.add(provider);
|
|
47
51
|
}
|
|
@@ -49,10 +53,11 @@ export function validateDocumentIngestProviderWiring(features: readonly FeatureD
|
|
|
49
53
|
|
|
50
54
|
for (const name of registeredProviderNames) {
|
|
51
55
|
if (wiredProviderNames.has(name)) continue;
|
|
52
|
-
throw
|
|
53
|
-
|
|
56
|
+
throw bootRuleError(DOCUMENT_INGEST_BOOT_RULES.providerWithoutJob, {
|
|
57
|
+
message:
|
|
58
|
+
`[kumiko:boot] Provider "${name}" is registered via EXT_DOCUMENT_INGEST_PROVIDER but no job triggers on ` +
|
|
54
59
|
`documentIngestProviderTrigger("${name}") — files matching its mimeTypes would be requested for ingest ` +
|
|
55
60
|
`and never processed. Add an r.job with that trigger, or unmount the provider.`,
|
|
56
|
-
);
|
|
61
|
+
});
|
|
57
62
|
}
|
|
58
63
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BootRuleTable } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
|
|
3
|
+
export const DOCUMENT_INGEST_BOOT_RULES = {
|
|
4
|
+
jobWithoutProviderFilter: {
|
|
5
|
+
id: "document-ingest-foundation/job-without-provider-filter",
|
|
6
|
+
summary:
|
|
7
|
+
"A job triggered by documentIngest.requested filters to one provider, so it does not fire for every provider's uploads.",
|
|
8
|
+
fix: 'Use trigger: documentIngestProviderTrigger("<name>").',
|
|
9
|
+
},
|
|
10
|
+
jobUnknownProvider: {
|
|
11
|
+
id: "document-ingest-foundation/job-unknown-provider",
|
|
12
|
+
summary:
|
|
13
|
+
"A documentIngest.requested job filters to a provider that some feature registers via EXT_DOCUMENT_INGEST_PROVIDER.",
|
|
14
|
+
fix: 'Register the provider via r.useExtension(EXT_DOCUMENT_INGEST_PROVIDER, "<name>", ...) or fix the provider name.',
|
|
15
|
+
},
|
|
16
|
+
providerWithoutJob: {
|
|
17
|
+
id: "document-ingest-foundation/provider-without-job",
|
|
18
|
+
summary:
|
|
19
|
+
"A registered document-ingest provider has a job triggered by documentIngestProviderTrigger, otherwise requested files are never processed.",
|
|
20
|
+
fix: "Add an r.job with that trigger, or unmount the provider.",
|
|
21
|
+
},
|
|
22
|
+
} as const satisfies BootRuleTable;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.409.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Ingest progress per file via reportIngestProgress",
|
|
6
|
+
"detail": "reportIngestProgress(deps, { fileRefId, pagesDone, pagesTotal }) appends a documentIngest.progress event to the file's ingest stream and runs the ingest-progress projection, which keeps one row per file in store_document_ingest_progress (documentIngestProgressTable, read by tenantId and fileRefId). The payload is validated by documentIngestProgressPayloadSchema (pagesTotal at least 1, pagesDone not above pagesTotal). Provider jobs still trigger only on documentIngest.requested. Apps need a migration for the new table."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.389.0",
|
|
4
10
|
"type": "improvement",
|
|
@@ -48,6 +48,23 @@ export const documentIngestSkippedPayloadSchema = z.object({
|
|
|
48
48
|
});
|
|
49
49
|
export type DocumentIngestSkippedPayload = z.infer<typeof documentIngestSkippedPayloadSchema>;
|
|
50
50
|
|
|
51
|
+
export const DOCUMENT_INGEST_PROGRESS_EVENT_SHORT = "documentIngest.progress" as const;
|
|
52
|
+
|
|
53
|
+
export const DOCUMENT_INGEST_PROGRESS_EVENT_QN =
|
|
54
|
+
"document-ingest-foundation:event:document-ingest-progress" as const;
|
|
55
|
+
|
|
56
|
+
export const documentIngestProgressPayloadSchema = z
|
|
57
|
+
.object({
|
|
58
|
+
fileRefId: z.string().min(1),
|
|
59
|
+
pagesDone: z.number().int().min(0),
|
|
60
|
+
pagesTotal: z.number().int().min(1),
|
|
61
|
+
})
|
|
62
|
+
.refine((p) => p.pagesDone <= p.pagesTotal, {
|
|
63
|
+
message: "pagesDone must not exceed pagesTotal",
|
|
64
|
+
path: ["pagesDone"],
|
|
65
|
+
});
|
|
66
|
+
export type DocumentIngestProgressPayload = z.infer<typeof documentIngestProgressPayloadSchema>;
|
|
67
|
+
|
|
51
68
|
// Terminal events of a document-extract stream. The QNs belong to the provider that registers
|
|
52
69
|
// them; the foundation only owns the shared payload shape.
|
|
53
70
|
export const documentExtractReadyPayloadSchema = z.object({
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
// hardcoded mime allowlist or size cap — providers register via
|
|
5
5
|
// EXT_DOCUMENT_INGEST_PROVIDER (see providers.ts).
|
|
6
6
|
|
|
7
|
-
import { applyEntityEvent, entityEventName } from "@cosmicdrift/kumiko-framework/db";
|
|
7
|
+
import { applyEntityEvent, entityEventName, upsertByPk } from "@cosmicdrift/kumiko-framework/db";
|
|
8
8
|
import {
|
|
9
9
|
access,
|
|
10
10
|
createTenantConfig,
|
|
@@ -20,10 +20,13 @@ import { documentExtractEntity, documentExtractsTable } from "./entity.ts";
|
|
|
20
20
|
import {
|
|
21
21
|
DOCUMENT_EXTRACT_AGGREGATE_TYPE,
|
|
22
22
|
DOCUMENT_INGEST_AGGREGATE_TYPE,
|
|
23
|
+
DOCUMENT_INGEST_PROGRESS_EVENT_QN,
|
|
24
|
+
DOCUMENT_INGEST_PROGRESS_EVENT_SHORT,
|
|
23
25
|
DOCUMENT_INGEST_REQUESTED_EVENT_QN,
|
|
24
26
|
DOCUMENT_INGEST_REQUESTED_EVENT_SHORT,
|
|
25
27
|
DOCUMENT_INGEST_SKIPPED_EVENT_QN,
|
|
26
28
|
DOCUMENT_INGEST_SKIPPED_EVENT_SHORT,
|
|
29
|
+
documentIngestProgressPayloadSchema,
|
|
27
30
|
documentIngestRequestedPayloadSchema,
|
|
28
31
|
documentIngestSkippedPayloadSchema,
|
|
29
32
|
} from "./events.ts";
|
|
@@ -37,6 +40,7 @@ import {
|
|
|
37
40
|
resolveDocumentIngestProviders,
|
|
38
41
|
UNCLAIMED_PROVIDER_SENTINEL,
|
|
39
42
|
} from "./providers.ts";
|
|
43
|
+
import { documentIngestProgressTable, documentIngestProgressTableMeta } from "./tables.ts";
|
|
40
44
|
import { documentExtractTenantDestroyHook } from "./tenant-destroy-hook.ts";
|
|
41
45
|
|
|
42
46
|
const FEATURE_NAME = "document-ingest-foundation";
|
|
@@ -206,6 +210,40 @@ export function createDocumentIngestFoundationFeature() {
|
|
|
206
210
|
piiFields: "none",
|
|
207
211
|
});
|
|
208
212
|
|
|
213
|
+
r.defineEvent(DOCUMENT_INGEST_PROGRESS_EVENT_SHORT, documentIngestProgressPayloadSchema, {
|
|
214
|
+
piiFields: "none",
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
r.storeTable(documentIngestProgressTableMeta, {
|
|
218
|
+
reason: "read_side.document_ingest_progress",
|
|
219
|
+
});
|
|
220
|
+
r.projection({
|
|
221
|
+
name: "ingest-progress",
|
|
222
|
+
source: DOCUMENT_INGEST_AGGREGATE_TYPE,
|
|
223
|
+
table: documentIngestProgressTable,
|
|
224
|
+
apply: {
|
|
225
|
+
[DOCUMENT_INGEST_PROGRESS_EVENT_QN]: async (event, tx) => {
|
|
226
|
+
const progress = documentIngestProgressPayloadSchema.parse(event.payload);
|
|
227
|
+
await upsertByPk(
|
|
228
|
+
tx,
|
|
229
|
+
documentIngestProgressTable,
|
|
230
|
+
{
|
|
231
|
+
id: event.aggregateId,
|
|
232
|
+
tenantId: event.tenantId,
|
|
233
|
+
fileRefId: progress.fileRefId,
|
|
234
|
+
pagesDone: progress.pagesDone,
|
|
235
|
+
pagesTotal: progress.pagesTotal,
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
pagesDone: progress.pagesDone,
|
|
239
|
+
pagesTotal: progress.pagesTotal,
|
|
240
|
+
updatedAt: event.createdAt,
|
|
241
|
+
},
|
|
242
|
+
);
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
});
|
|
246
|
+
|
|
209
247
|
r.multiStreamProjection({
|
|
210
248
|
name: "request-ingest",
|
|
211
249
|
apply: {
|
|
@@ -17,16 +17,20 @@ export {
|
|
|
17
17
|
export {
|
|
18
18
|
DOCUMENT_EXTRACT_AGGREGATE_TYPE,
|
|
19
19
|
DOCUMENT_INGEST_AGGREGATE_TYPE,
|
|
20
|
+
DOCUMENT_INGEST_PROGRESS_EVENT_QN,
|
|
21
|
+
DOCUMENT_INGEST_PROGRESS_EVENT_SHORT,
|
|
20
22
|
DOCUMENT_INGEST_REQUESTED_EVENT_QN,
|
|
21
23
|
DOCUMENT_INGEST_REQUESTED_EVENT_SHORT,
|
|
22
24
|
DOCUMENT_INGEST_SKIPPED_EVENT_QN,
|
|
23
25
|
DOCUMENT_INGEST_SKIPPED_EVENT_SHORT,
|
|
24
26
|
type DocumentExtractFailedPayload,
|
|
25
27
|
type DocumentExtractReadyPayload,
|
|
28
|
+
type DocumentIngestProgressPayload,
|
|
26
29
|
type DocumentIngestRequestedPayload,
|
|
27
30
|
type DocumentIngestSkippedPayload,
|
|
28
31
|
documentExtractFailedPayloadSchema,
|
|
29
32
|
documentExtractReadyPayloadSchema,
|
|
33
|
+
documentIngestProgressPayloadSchema,
|
|
30
34
|
documentIngestRequestedPayloadSchema,
|
|
31
35
|
documentIngestSkippedPayloadSchema,
|
|
32
36
|
} from "./events.ts";
|
|
@@ -41,6 +45,12 @@ export {
|
|
|
41
45
|
type ResolvedDocumentIngestProvider,
|
|
42
46
|
resolveDocumentIngestProviders,
|
|
43
47
|
} from "./providers.ts";
|
|
48
|
+
export {
|
|
49
|
+
type ReportIngestProgressDeps,
|
|
50
|
+
type ReportIngestProgressInput,
|
|
51
|
+
reportIngestProgress,
|
|
52
|
+
} from "./report-ingest-progress.ts";
|
|
53
|
+
export { documentIngestProgressTable } from "./tables.ts";
|
|
44
54
|
export {
|
|
45
55
|
type DocumentExtractWriteResult,
|
|
46
56
|
writeDocumentExtractForLiveFileRef,
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { DbConnection } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import type { Registry } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
import { append, getStreamVersion } from "@cosmicdrift/kumiko-framework/event-store";
|
|
4
|
+
import { runProjectionsForEvent } from "@cosmicdrift/kumiko-framework/pipeline";
|
|
5
|
+
import { documentIngestAggregateId } from "./aggregate-id.ts";
|
|
6
|
+
import {
|
|
7
|
+
DOCUMENT_INGEST_AGGREGATE_TYPE,
|
|
8
|
+
DOCUMENT_INGEST_PROGRESS_EVENT_QN,
|
|
9
|
+
documentIngestProgressPayloadSchema,
|
|
10
|
+
} from "./events.ts";
|
|
11
|
+
|
|
12
|
+
export type ReportIngestProgressDeps = {
|
|
13
|
+
readonly db: DbConnection;
|
|
14
|
+
readonly registry: Registry;
|
|
15
|
+
readonly tenantId: string;
|
|
16
|
+
readonly actorId: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ReportIngestProgressInput = {
|
|
20
|
+
readonly fileRefId: string;
|
|
21
|
+
readonly pagesDone: number;
|
|
22
|
+
readonly pagesTotal: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// Low-level append() does not fire projections, so they run explicitly in the same call.
|
|
26
|
+
export async function reportIngestProgress(
|
|
27
|
+
deps: ReportIngestProgressDeps,
|
|
28
|
+
input: ReportIngestProgressInput,
|
|
29
|
+
): Promise<void> {
|
|
30
|
+
const payload = documentIngestProgressPayloadSchema.parse(input);
|
|
31
|
+
const aggregateId = documentIngestAggregateId(deps.tenantId, payload.fileRefId);
|
|
32
|
+
const expectedVersion = await getStreamVersion(deps.db, aggregateId, deps.tenantId);
|
|
33
|
+
const stored = await append(deps.db, {
|
|
34
|
+
aggregateId,
|
|
35
|
+
aggregateType: DOCUMENT_INGEST_AGGREGATE_TYPE,
|
|
36
|
+
tenantId: deps.tenantId,
|
|
37
|
+
expectedVersion,
|
|
38
|
+
type: DOCUMENT_INGEST_PROGRESS_EVENT_QN,
|
|
39
|
+
payload,
|
|
40
|
+
metadata: { userId: deps.actorId },
|
|
41
|
+
});
|
|
42
|
+
await runProjectionsForEvent(stored, deps.registry, deps.db);
|
|
43
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineUnmanagedTable,
|
|
3
|
+
type EntityTableMeta,
|
|
4
|
+
index,
|
|
5
|
+
instant,
|
|
6
|
+
integer,
|
|
7
|
+
table as pgTable,
|
|
8
|
+
sql,
|
|
9
|
+
text,
|
|
10
|
+
uuid,
|
|
11
|
+
} from "@cosmicdrift/kumiko-framework/db";
|
|
12
|
+
|
|
13
|
+
const INGEST_PROGRESS_FILE_REF_INDEX = "store_document_ingest_progress_tenant_id_file_ref_id_idx";
|
|
14
|
+
|
|
15
|
+
// One row per ingest stream (PK = documentIngestAggregateId), upserted by the
|
|
16
|
+
// "ingest-progress" projection on every documentIngest.progress event.
|
|
17
|
+
export const documentIngestProgressTable = pgTable(
|
|
18
|
+
"store_document_ingest_progress",
|
|
19
|
+
{
|
|
20
|
+
id: uuid("id").primaryKey(),
|
|
21
|
+
tenantId: uuid("tenant_id").notNull(),
|
|
22
|
+
fileRefId: text("file_ref_id").notNull(),
|
|
23
|
+
pagesDone: integer("pages_done").notNull(),
|
|
24
|
+
pagesTotal: integer("pages_total").notNull(),
|
|
25
|
+
updatedAt: instant("updated_at").default(sql`now()`).notNull(),
|
|
26
|
+
},
|
|
27
|
+
(t) => [index(INGEST_PROGRESS_FILE_REF_INDEX).on(t.tenantId, t.fileRefId)],
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
// Unmanaged: the id is the event-stream aggregate id and replays are idempotent via the PK upsert,
|
|
31
|
+
// so the managed base columns (version, audit columns) have no use here.
|
|
32
|
+
export const documentIngestProgressTableMeta: EntityTableMeta = defineUnmanagedTable({
|
|
33
|
+
tableName: "store_document_ingest_progress",
|
|
34
|
+
indexes: [{ name: INGEST_PROGRESS_FILE_REF_INDEX, columns: ["tenant_id", "file_ref_id"] }],
|
|
35
|
+
columns: [
|
|
36
|
+
{ name: "id", pgType: "uuid", notNull: true, primaryKey: true },
|
|
37
|
+
{ name: "tenant_id", pgType: "uuid", notNull: true },
|
|
38
|
+
{ name: "file_ref_id", pgType: "text", notNull: true },
|
|
39
|
+
{ name: "pages_done", pgType: "integer", notNull: true },
|
|
40
|
+
{ name: "pages_total", pgType: "integer", notNull: true },
|
|
41
|
+
{ name: "updated_at", pgType: "timestamptz", notNull: true, defaultSql: "now()" },
|
|
42
|
+
],
|
|
43
|
+
});
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.407.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Tenant destruction keeps files of held rows",
|
|
6
|
+
"detail": "The fileRef destroy hook skips the fileRefs listed in heldFileRefIds, and the files prefix sweep keeps their bytes. Without a configured file provider, the retention cleanup still removes the held fileRef rows after keepFor and logs that no bytes could be deleted, so the tenant does not stay in destroyHeld forever."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.364.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -100,7 +100,10 @@ export const fileRefTenantDestroyHook: TenantDataDestroyHook = async (ctx) => {
|
|
|
100
100
|
nextBatch: () =>
|
|
101
101
|
ctx.db.selectMany<{ id: string; storageKey: string }>(
|
|
102
102
|
fileRefsTable,
|
|
103
|
-
{
|
|
103
|
+
{
|
|
104
|
+
tenantId: ctx.tenantId,
|
|
105
|
+
id: { notIn: [...(ctx.heldFileRefIds ?? [])] },
|
|
106
|
+
},
|
|
104
107
|
{ limit: DESTROY_CHUNK_SIZE },
|
|
105
108
|
),
|
|
106
109
|
migrateRow: async (row) => {
|
|
@@ -26,10 +26,15 @@
|
|
|
26
26
|
// src (node_modules is ignored by default) or these classes never compile. money-
|
|
27
27
|
// horse already does; that scan is a real shipping requirement for any host.
|
|
28
28
|
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
toggleSetMember,
|
|
31
|
+
usePrimitives,
|
|
32
|
+
useQuery,
|
|
33
|
+
useTranslation,
|
|
34
|
+
} from "@cosmicdrift/kumiko-renderer";
|
|
30
35
|
import { ChevronRight, File, Folder, type LucideIcon, Pencil, Plus, Trash2 } from "lucide-react";
|
|
31
36
|
import { type DragEvent, type ReactNode, useEffect, useState } from "react";
|
|
32
|
-
import { useDispatchedWrites } from "../../shared/web/
|
|
37
|
+
import { useDispatchedWrites } from "../../shared/web/index.ts";
|
|
33
38
|
import { FoldersHandlers, FoldersQueries } from "./constants.ts";
|
|
34
39
|
import { buildFolderTree, type FolderNode, type FolderRow } from "./tree.ts";
|
|
35
40
|
|
|
@@ -153,13 +158,7 @@ export function FolderManager({
|
|
|
153
158
|
}
|
|
154
159
|
}
|
|
155
160
|
|
|
156
|
-
const toggleCollapse = (id: string): void =>
|
|
157
|
-
setCollapsed((prev) => {
|
|
158
|
-
const next = new Set(prev);
|
|
159
|
-
if (next.has(id)) next.delete(id);
|
|
160
|
-
else next.add(id);
|
|
161
|
-
return next;
|
|
162
|
-
});
|
|
161
|
+
const toggleCollapse = (id: string): void => setCollapsed((prev) => toggleSetMember(prev, id));
|
|
163
162
|
|
|
164
163
|
const openCreate = (parentId: string | null): void => {
|
|
165
164
|
setErrorKey(null);
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
useTranslation,
|
|
19
19
|
} from "@cosmicdrift/kumiko-renderer";
|
|
20
20
|
import { type ReactNode, useState } from "react";
|
|
21
|
-
import { useDispatchedWrites } from "../../shared/web/
|
|
21
|
+
import { useDispatchedWrites } from "../../shared/web/index.ts";
|
|
22
22
|
import { FoldersHandlers, FoldersQueries } from "./constants.ts";
|
|
23
23
|
import { type FolderRow, folderPath } from "./tree.ts";
|
|
24
24
|
|