@cosmicdrift/kumiko-samples 0.414.0 → 0.416.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/packages/bundled-features/package.json +21 -1
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/agent-tools/tool-catalog.ts +20 -1
- package/packages/bundled-features/src/agent-tools/tool-dispatch.ts +19 -5
- 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 +30 -0
- package/packages/bundled-features/src/channel-whatsapp/constants.ts +1 -0
- package/packages/bundled-features/src/channel-whatsapp/events.ts +4 -3
- package/packages/bundled-features/src/channel-whatsapp/graph-client.ts +37 -1
- 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/handbook-knowledge/README.md +64 -0
- package/packages/bundled-features/src/handbook-knowledge/changes.json +8 -0
- package/packages/bundled-features/src/handbook-knowledge/constants.ts +8 -0
- package/packages/bundled-features/src/handbook-knowledge/feature.ts +34 -0
- package/packages/bundled-features/src/handbook-knowledge/handbook-index.ts +66 -0
- package/packages/bundled-features/src/handbook-knowledge/handlers.ts +77 -0
- package/packages/bundled-features/src/handbook-knowledge/index.ts +10 -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/signature/README.md +59 -0
- package/packages/bundled-features/src/signature/changes.json +15 -0
- package/packages/bundled-features/src/signature/entity.ts +192 -0
- package/packages/bundled-features/src/signature/feature.ts +125 -0
- package/packages/bundled-features/src/signature/files.ts +107 -0
- package/packages/bundled-features/src/signature/grant.ts +79 -0
- package/packages/bundled-features/src/signature/handlers/anonymous.write.ts +88 -0
- package/packages/bundled-features/src/signature/handlers/cancel.write.ts +40 -0
- package/packages/bundled-features/src/signature/handlers/issue-link.write.ts +72 -0
- package/packages/bundled-features/src/signature/handlers/lifecycle.write.ts +99 -0
- package/packages/bundled-features/src/signature/handlers/link-internal.write.ts +261 -0
- package/packages/bundled-features/src/signature/handlers/request.write.ts +86 -0
- package/packages/bundled-features/src/signature/handlers/revoke-link.write.ts +23 -0
- package/packages/bundled-features/src/signature/handlers/sign-in-person.write.ts +69 -0
- package/packages/bundled-features/src/signature/i18n.ts +52 -0
- package/packages/bundled-features/src/signature/index.ts +33 -0
- package/packages/bundled-features/src/signature/lib.ts +125 -0
- package/packages/bundled-features/src/signature/options.ts +49 -0
- package/packages/bundled-features/src/signature/payloads.ts +71 -0
- package/packages/bundled-features/src/signature/png.ts +169 -0
- package/packages/bundled-features/src/signature/screens.ts +115 -0
- package/packages/bundled-features/src/signature/signature-page.ts +93 -0
- package/packages/bundled-features/src/signature/signing.ts +77 -0
- package/packages/bundled-features/src/signature/static-sign.ts +98 -0
- package/packages/bundled-features/src/signature/sweep.ts +161 -0
- package/packages/bundled-features/src/signature/user-data.ts +159 -0
- package/packages/bundled-features/src/signature/web/constants.ts +92 -0
- package/packages/bundled-features/src/signature/web/index.ts +31 -0
- package/packages/bundled-features/src/signature/web/pad.ts +147 -0
- package/packages/bundled-features/src/signature/web/signature-pad.tsx +82 -0
- 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 +12 -0
- package/packages/bundled-features/src/subscription-stripe/feature.ts +9 -0
- package/packages/bundled-features/src/subscription-stripe/plugin-methods.ts +7 -1
- 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/apps/use-all-bundled/feature-manifest.json +63 -1
- package/samples/apps/use-all-bundled/kumiko/migrations/0068_signature.rebuild.json +4 -0
- package/samples/apps/use-all-bundled/src/run-config.ts +35 -1
- package/samples/recipes/crypto-shredding-hr/README.md +11 -0
- package/samples/recipes/crypto-shredding-hr/src/feature.ts +27 -0
- package/samples/recipes/embedded/README.md +4 -0
- package/samples/recipes/embedded/src/entities/invoice.ts +6 -0
- package/samples/recipes/embedded/src/feature.ts +7 -1
- package/samples/recipes/embedded/src/handlers/invoice-receive.write.ts +1 -0
- package/samples/recipes/embedded/src/screens/invoice-receive.screen.ts +2 -0
- package/samples/recipes/handbook-knowledge/README.md +22 -0
- package/samples/recipes/handbook-knowledge/package.json +12 -0
- package/samples/recipes/handbook-knowledge/src/feature.ts +42 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +36 -5
- package/samples/recipes/record-detail-layout/src/order-board.ts +10 -2
- package/samples/recipes/signature/README.md +21 -0
- package/samples/recipes/signature/package.json +13 -0
- package/samples/recipes/signature/src/feature.ts +26 -0
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
useUnsavedInputSource,
|
|
10
10
|
} from "@cosmicdrift/kumiko-renderer";
|
|
11
11
|
import { EditorWorkbench, LoadingState, StatusBadge } from "@cosmicdrift/kumiko-renderer/web";
|
|
12
|
-
import { type ReactNode, useState } from "react";
|
|
12
|
+
import { type ReactNode, useRef, useState } from "react";
|
|
13
13
|
import { DocumentContentEditor } from "../../template-resolver/web/index.ts";
|
|
14
14
|
import {
|
|
15
15
|
PAGE_CREATE_HANDLER,
|
|
@@ -51,8 +51,10 @@ function PageEditor({
|
|
|
51
51
|
}): ReactNode {
|
|
52
52
|
const t = useTranslation();
|
|
53
53
|
const { Banner } = usePrimitives();
|
|
54
|
-
|
|
55
|
-
const
|
|
54
|
+
// Computed once: the editor is remounted per record version, and every keystroke re-renders it.
|
|
55
|
+
const [initial] = useState(() => (record === null ? EMPTY_PAGE_DRAFT : draftOfRecord(record)));
|
|
56
|
+
const [lossyOnOpen] = useState(() => (record === null ? [] : lossyFeaturesOfRecord(record)));
|
|
57
|
+
const savedRef = useRef(false);
|
|
56
58
|
const [draft, setDraft] = useState<PageDraft>(initial);
|
|
57
59
|
const [bodyEdited, setBodyEdited] = useState(false);
|
|
58
60
|
const [resetCount, setResetCount] = useState(0);
|
|
@@ -60,10 +62,13 @@ function PageEditor({
|
|
|
60
62
|
const create = useMutation<{ readonly id?: string }>(PAGE_CREATE_HANDLER);
|
|
61
63
|
const update = useMutation(PAGE_UPDATE_HANDLER);
|
|
62
64
|
const dirty = isDraftDirty(draft, initial);
|
|
63
|
-
|
|
65
|
+
// The leave guard runs synchronously after save, before React re-renders with the saved state.
|
|
66
|
+
useUnsavedInputSource(() => dirty && !savedRef.current);
|
|
64
67
|
|
|
65
|
-
const patch = (changes: Partial<PageDraft>): void =>
|
|
68
|
+
const patch = (changes: Partial<PageDraft>): void => {
|
|
69
|
+
savedRef.current = false;
|
|
66
70
|
setDraft((current) => ({ ...current, ...changes }));
|
|
71
|
+
};
|
|
67
72
|
const canSave = dirty && draft.slug !== "" && draft.title !== "";
|
|
68
73
|
|
|
69
74
|
const save = async (): Promise<void> => {
|
|
@@ -80,6 +85,7 @@ function PageEditor({
|
|
|
80
85
|
setSaveError(dispatcherErrorTextWithFieldIssues(result.error, t));
|
|
81
86
|
return;
|
|
82
87
|
}
|
|
88
|
+
savedRef.current = true;
|
|
83
89
|
onSaved(record === null ? createdIdOf(result.data) : record.id);
|
|
84
90
|
};
|
|
85
91
|
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.415.0",
|
|
4
|
+
"type": "fix",
|
|
5
|
+
"title": "One normalizeEmail for helpdesk, waitlist, signup tokens and user-data lookups",
|
|
6
|
+
"detail": "The copies in helpdesk, waitlist, signup-token-store and the inline toLowerCase in resolveVerifiedUserEmail now use shared/normalizeEmail, so a changed normalization cannot make export and erasure miss stored rows."
|
|
7
|
+
},
|
|
2
8
|
{
|
|
3
9
|
"version": "0.414.0",
|
|
4
10
|
"type": "fix",
|
|
@@ -8,8 +8,10 @@ export function hmacSignatureMatches(
|
|
|
8
8
|
expectedBase64Url: string,
|
|
9
9
|
providedBase64Url: string,
|
|
10
10
|
): boolean {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
// The text is compared, not the decoded bytes: decoding ignores the unused trailing bits of the
|
|
12
|
+
// last character, so one signature would have several accepted spellings.
|
|
13
|
+
const expectedBuf = Buffer.from(expectedBase64Url);
|
|
14
|
+
const providedBuf = Buffer.from(providedBase64Url);
|
|
13
15
|
// timingSafeEqual throws on a length mismatch, and the throw itself is a timing signal.
|
|
14
16
|
return expectedBuf.length === providedBuf.length && timingSafeEqual(expectedBuf, providedBuf);
|
|
15
17
|
}
|
|
@@ -36,6 +36,7 @@ export {
|
|
|
36
36
|
mailRepeatedRows,
|
|
37
37
|
} from "./mail-template-body.ts";
|
|
38
38
|
export { mapWithConcurrency } from "./map-with-concurrency.ts";
|
|
39
|
+
export { normalizeEmail } from "./normalize-email.ts";
|
|
39
40
|
export {
|
|
40
41
|
denyUnlessJoinRowParentVisible,
|
|
41
42
|
hostRowIsGone,
|
|
@@ -92,7 +93,7 @@ export {
|
|
|
92
93
|
signRowBoundGrant,
|
|
93
94
|
} from "./row-bound-grant.ts";
|
|
94
95
|
export { runInSubTransaction } from "./run-in-sub-transaction.ts";
|
|
95
|
-
export { sendBestEffort } from "./send-best-effort.ts";
|
|
96
|
+
export { runBestEffort, sendBestEffort } from "./send-best-effort.ts";
|
|
96
97
|
export { registrationLocaleFromRequest, sessionLocaleField } from "./session-locale-field.ts";
|
|
97
98
|
export { sessionTimezoneField } from "./session-timezone-field.ts";
|
|
98
99
|
export { assertNotSvg, MAX_INPUT_PIXELS, SHARP_INPUT_OPTIONS } from "./sharp-input-limits.ts";
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import type { HandlerContext } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
2
|
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
3
|
|
|
4
|
+
export async function runBestEffort(
|
|
5
|
+
ctx: Pick<HandlerContext, "obs">,
|
|
6
|
+
logMessage: string,
|
|
7
|
+
run: () => Promise<unknown>,
|
|
8
|
+
): Promise<void> {
|
|
9
|
+
try {
|
|
10
|
+
await run();
|
|
11
|
+
} catch (err) {
|
|
12
|
+
ctx.obs.log?.warn(logMessage, {
|
|
13
|
+
error: err instanceof Error ? err.message : String(err),
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
4
18
|
export async function sendBestEffort(
|
|
5
19
|
ctx: Pick<HandlerContext, "notify" | "obs">,
|
|
6
20
|
logMessage: string,
|
|
7
21
|
send: (notify: NonNullable<HandlerContext["notify"]>) => Promise<unknown>,
|
|
8
22
|
): Promise<void> {
|
|
9
|
-
|
|
23
|
+
await runBestEffort(ctx, logMessage, async () => {
|
|
10
24
|
if (!ctx.notify) {
|
|
11
25
|
throw new InternalError({ message: "ctx.notify unavailable — mount the delivery feature" });
|
|
12
26
|
}
|
|
13
27
|
await send(ctx.notify);
|
|
14
|
-
}
|
|
15
|
-
ctx.obs.log?.warn(logMessage, {
|
|
16
|
-
error: err instanceof Error ? err.message : String(err),
|
|
17
|
-
});
|
|
18
|
-
}
|
|
28
|
+
});
|
|
19
29
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# signature
|
|
2
|
+
|
|
3
|
+
Signature requests: a signed-in user asks several people to sign one PDF of the tenant. Each
|
|
4
|
+
signer draws a signature on a display in person or through a link. The last signature
|
|
5
|
+
moves the request to `all-signed`; a job appends a signature page to the unchanged original and
|
|
6
|
+
completes it. Level `simple` only: a drawn image plus the audit values, not a qualified signature.
|
|
7
|
+
|
|
8
|
+
## Setup
|
|
9
|
+
|
|
10
|
+
```typescript
|
|
11
|
+
import { createSignatureFeature } from "@cosmicdrift/kumiko-bundled-features/signature";
|
|
12
|
+
import { renderHtmlToPdf } from "@cosmicdrift/kumiko-renderer-puppeteer-client";
|
|
13
|
+
|
|
14
|
+
createSignatureFeature({
|
|
15
|
+
retention: { keepFor: "10y" },
|
|
16
|
+
linkSecret: process.env.SIGNATURE_LINK_SECRET,
|
|
17
|
+
renderHtmlToPdf,
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
`bundled-features` never imports the print client; the app injects `renderHtmlToPdf`. Requires
|
|
22
|
+
the `files` feature. Order of signatures is free.
|
|
23
|
+
|
|
24
|
+
## Options
|
|
25
|
+
|
|
26
|
+
| Option | Default | Effect |
|
|
27
|
+
| ------------------ | -------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
28
|
+
| `retention` | required | `{ keepFor }`, counted from creation, hard delete |
|
|
29
|
+
| `renderHtmlToPdf` | required | Renders the signature page; an outage leaves `all-signed`, the job retries |
|
|
30
|
+
| `linkSecret` | required | HMAC secret of the links; empty rejects every link |
|
|
31
|
+
| `deliverLink` | required | `(ctx, delivery)`: sends the link to the signer (mail) inside `issue-link`'s transaction; `delivery.issuedBy` is the issuing user. The token is never in a handler result |
|
|
32
|
+
| `signaturePageUrl` | required | URL of the app's signature page; the token is appended as `#<token>` |
|
|
33
|
+
| `access` | `{ roles: ["TenantAdmin", "TenantMember"] }` | `AccessRule` of the signed-in handlers, queries, screens and nav; set it when the app hands out other roles. Link handlers stay anonymous |
|
|
34
|
+
|
|
35
|
+
## Handlers
|
|
36
|
+
|
|
37
|
+
Signed in: `request`, `sign-in-person`, `issue-link`, `revoke-link`, `cancel`.
|
|
38
|
+
Anonymous (rate limited): `open-by-link`, `sign-by-link`, `decline-by-link`. Signing is never an
|
|
39
|
+
agent tool. `request`, `issue-link` and `cancel` are agent tools with `risk: "mid"`.
|
|
40
|
+
|
|
41
|
+
## Links
|
|
42
|
+
|
|
43
|
+
`issue-link` hands the link (`https://app/sign#<token>`) to `deliverLink`, which must not store it where other users or the assistant read it, and returns only `{ signerId, linkSentAt }`; an older link of the
|
|
44
|
+
same signer stops working. A link lives 14 days, opens at most 20 times (`open-by-link` does not consume it)
|
|
45
|
+
and dies with the first signature or refusal. Forged, expired, revoked, used up and already signed links
|
|
46
|
+
all get the same 422. Of two simultaneous `sign-by-link` calls exactly one wins.
|
|
47
|
+
|
|
48
|
+
## Events
|
|
49
|
+
|
|
50
|
+
`signature:event:completed`, `signature:event:declined`, `signature:event:expired`, each with
|
|
51
|
+
request id, subject type and id (and the file id or signer id). A cron job (`signature:job:sweep`, every
|
|
52
|
+
5 minutes, per tenant) expires requests, completes `all-signed` ones and re-checks races.
|
|
53
|
+
|
|
54
|
+
## Client
|
|
55
|
+
|
|
56
|
+
- `/signature/web`: `SignaturePad`, a React wrapper of the core pad; keyboard users get a visible
|
|
57
|
+
"sign on paper" exit through `onSignOnPaper`.
|
|
58
|
+
- `/signature/static-sign`: no React, no DOM at import; `takeSignatureToken`, `openSignatureLink`,
|
|
59
|
+
`signByLink`, `declineByLink` and the framework-free `createSignaturePad(canvas)`.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.416.0",
|
|
4
|
+
"type": "improvement",
|
|
5
|
+
"title": "Signature requests with in-person and link signing",
|
|
6
|
+
"detail": "`createSignatureFeature({ retention, linkSecret, renderHtmlToPdf, deliverLink, signaturePageUrl })` adds the entities `signatureRequest` and `signatureSigner`, the handlers `request`, `sign-in-person`, `issue-link` (sends the link through `deliverLink(ctx, { signerId, url, ..., issuedBy })` inside its own transaction, so the app can dispatch its mail write and pick the issuer's mailbox; it never returns the token), `revoke-link`, `cancel` and the anonymous, rate-limited `open-by-link`, `sign-by-link`, `decline-by-link`. Links carry a row-bound grant in the URL fragment (14 days, 20 opens, single-use signing, one answer for every rejection). The last signature sets the request to `all-signed`; the `signature:job:sweep` cron renders the signature page through the injected print function, appends it with pdf-lib and completes the request; the events `completed`, `declined` and `expired` report the outcome. The subpaths `./signature/web` (`SignaturePad`) and `./signature/static-sign` (no React) ship the signature field.",
|
|
7
|
+
"migration": "The feature adds the tables `read_signature_requests` and `read_signature_signers`; apps that mount it run the schema pipeline migration."
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
"version": "0.416.0",
|
|
11
|
+
"type": "improvement",
|
|
12
|
+
"title": "Access rule option for the signature feature",
|
|
13
|
+
"detail": "`createSignatureFeature({ ..., access })` replaces the default `{ roles: [\"TenantAdmin\", \"TenantMember\"] }` on the signed-in handlers, queries, screens and nav, like `createLedgerFeature({ access })`. Without it, nested `ctx.dispatch` calls fail for users that only hold an app-specific role."
|
|
14
|
+
}
|
|
15
|
+
]
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createEntity,
|
|
3
|
+
createEntityExecutor,
|
|
4
|
+
createLongTextField,
|
|
5
|
+
createNumberField,
|
|
6
|
+
createSelectField,
|
|
7
|
+
createTextField,
|
|
8
|
+
createTimestampField,
|
|
9
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
10
|
+
import {
|
|
11
|
+
SIGNATURE_LEVEL,
|
|
12
|
+
SIGNATURE_METHOD,
|
|
13
|
+
SIGNATURE_REQUEST_ENTITY,
|
|
14
|
+
SIGNATURE_REQUEST_STATUS,
|
|
15
|
+
SIGNATURE_SIGNER_ENTITY,
|
|
16
|
+
SIGNATURE_SIGNER_STATUS,
|
|
17
|
+
} from "./web/constants.ts";
|
|
18
|
+
|
|
19
|
+
const LEVEL_OPTIONS = [SIGNATURE_LEVEL.Simple] as const;
|
|
20
|
+
const REQUEST_STATUS_OPTIONS = [
|
|
21
|
+
SIGNATURE_REQUEST_STATUS.Open,
|
|
22
|
+
SIGNATURE_REQUEST_STATUS.AllSigned,
|
|
23
|
+
SIGNATURE_REQUEST_STATUS.Completed,
|
|
24
|
+
SIGNATURE_REQUEST_STATUS.Declined,
|
|
25
|
+
SIGNATURE_REQUEST_STATUS.Expired,
|
|
26
|
+
SIGNATURE_REQUEST_STATUS.Cancelled,
|
|
27
|
+
] as const;
|
|
28
|
+
const SIGNER_STATUS_OPTIONS = [
|
|
29
|
+
SIGNATURE_SIGNER_STATUS.Pending,
|
|
30
|
+
SIGNATURE_SIGNER_STATUS.Viewed,
|
|
31
|
+
SIGNATURE_SIGNER_STATUS.Signed,
|
|
32
|
+
SIGNATURE_SIGNER_STATUS.Declined,
|
|
33
|
+
] as const;
|
|
34
|
+
const METHOD_OPTIONS = [SIGNATURE_METHOD.InPerson, SIGNATURE_METHOD.Link] as const;
|
|
35
|
+
|
|
36
|
+
export const DEFAULT_SIGNATURE_RETENTION_KEEP_FOR = "10y";
|
|
37
|
+
|
|
38
|
+
export type SignatureRetention = { readonly keepFor: string };
|
|
39
|
+
|
|
40
|
+
// A signer has no user account, so the signer row itself is the crypto-shredding subject for the
|
|
41
|
+
// name, email, signature image and the audit values (IP, user agent) stored with the signature.
|
|
42
|
+
// find: "none" except the email, which the user-data hook looks up by exact match.
|
|
43
|
+
const SIGNER_PERSONAL = { personal: "self", find: "none" } as const;
|
|
44
|
+
|
|
45
|
+
export function createSignatureRequestEntity(
|
|
46
|
+
retention: SignatureRetention = { keepFor: DEFAULT_SIGNATURE_RETENTION_KEEP_FOR },
|
|
47
|
+
) {
|
|
48
|
+
return createEntity({
|
|
49
|
+
table: "read_signature_requests",
|
|
50
|
+
description:
|
|
51
|
+
"A request to sign one PDF document by several people, on a display in person or through a link, tracked through open, all-signed, completed, declined, expired and cancelled; the document is referenced by file id and hash and never changed.",
|
|
52
|
+
retention: { keepFor: retention.keepFor, strategy: "hardDelete", reference: "createdAt" },
|
|
53
|
+
fields: {
|
|
54
|
+
documentFileId: createTextField({
|
|
55
|
+
required: true,
|
|
56
|
+
personal: false,
|
|
57
|
+
reason: "technical_reference",
|
|
58
|
+
maxLength: 64,
|
|
59
|
+
}),
|
|
60
|
+
documentSha256: createTextField({
|
|
61
|
+
required: true,
|
|
62
|
+
personal: false,
|
|
63
|
+
reason: "is_document_hash",
|
|
64
|
+
maxLength: 64,
|
|
65
|
+
}),
|
|
66
|
+
title: createTextField({
|
|
67
|
+
required: true,
|
|
68
|
+
personal: false,
|
|
69
|
+
reason: "is_business_data",
|
|
70
|
+
searchable: true,
|
|
71
|
+
}),
|
|
72
|
+
level: createSelectField({ options: LEVEL_OPTIONS, required: true, filterable: true }),
|
|
73
|
+
subjectType: createTextField({
|
|
74
|
+
required: true,
|
|
75
|
+
personal: false,
|
|
76
|
+
reason: "technical_reference",
|
|
77
|
+
filterable: true,
|
|
78
|
+
maxLength: 100,
|
|
79
|
+
}),
|
|
80
|
+
subjectId: createTextField({
|
|
81
|
+
required: true,
|
|
82
|
+
personal: false,
|
|
83
|
+
reason: "technical_reference",
|
|
84
|
+
maxLength: 100,
|
|
85
|
+
}),
|
|
86
|
+
status: createSelectField({
|
|
87
|
+
options: REQUEST_STATUS_OPTIONS,
|
|
88
|
+
required: true,
|
|
89
|
+
default: SIGNATURE_REQUEST_STATUS.Open,
|
|
90
|
+
filterable: true,
|
|
91
|
+
sortable: true,
|
|
92
|
+
optionTones: {
|
|
93
|
+
[SIGNATURE_REQUEST_STATUS.Open]: "warn",
|
|
94
|
+
[SIGNATURE_REQUEST_STATUS.AllSigned]: "accent",
|
|
95
|
+
[SIGNATURE_REQUEST_STATUS.Completed]: "ok",
|
|
96
|
+
[SIGNATURE_REQUEST_STATUS.Declined]: "bad",
|
|
97
|
+
[SIGNATURE_REQUEST_STATUS.Expired]: "neutral",
|
|
98
|
+
[SIGNATURE_REQUEST_STATUS.Cancelled]: "neutral",
|
|
99
|
+
},
|
|
100
|
+
}),
|
|
101
|
+
expiresAt: createTimestampField({
|
|
102
|
+
required: true,
|
|
103
|
+
personal: false,
|
|
104
|
+
reason: "is_deadline",
|
|
105
|
+
sortable: true,
|
|
106
|
+
}),
|
|
107
|
+
completedFileId: createTextField({
|
|
108
|
+
personal: false,
|
|
109
|
+
reason: "technical_reference",
|
|
110
|
+
maxLength: 64,
|
|
111
|
+
}),
|
|
112
|
+
completedAt: createTimestampField({
|
|
113
|
+
personal: false,
|
|
114
|
+
reason: "is_business_timestamp",
|
|
115
|
+
sortable: true,
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
indexes: [
|
|
119
|
+
{ columns: ["tenantId", "status"] },
|
|
120
|
+
{ columns: ["tenantId", "subjectType", "subjectId"] },
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function createSignatureSignerEntity(
|
|
126
|
+
retention: SignatureRetention = { keepFor: DEFAULT_SIGNATURE_RETENTION_KEEP_FOR },
|
|
127
|
+
) {
|
|
128
|
+
return createEntity({
|
|
129
|
+
table: "read_signature_signers",
|
|
130
|
+
description:
|
|
131
|
+
"One person who has to sign a signature request, with their way of signing (in person or link), the signature image and the audit values stored when they signed or declined; name, email, image, IP address and user agent are the signer's personal data.",
|
|
132
|
+
retention: { keepFor: retention.keepFor, strategy: "hardDelete", reference: "createdAt" },
|
|
133
|
+
fields: {
|
|
134
|
+
requestId: createTextField({
|
|
135
|
+
required: true,
|
|
136
|
+
personal: false,
|
|
137
|
+
reason: "technical_reference",
|
|
138
|
+
maxLength: 64,
|
|
139
|
+
}),
|
|
140
|
+
name: createTextField({ required: true, ...SIGNER_PERSONAL }),
|
|
141
|
+
role: createTextField({
|
|
142
|
+
personal: false,
|
|
143
|
+
reason: "is_business_data",
|
|
144
|
+
maxLength: 100,
|
|
145
|
+
}),
|
|
146
|
+
contactId: createTextField({
|
|
147
|
+
personal: false,
|
|
148
|
+
reason: "pseudonymous_fk",
|
|
149
|
+
maxLength: 64,
|
|
150
|
+
}),
|
|
151
|
+
email: createTextField({ personal: "self", find: "exact", maxLength: 320 }),
|
|
152
|
+
status: createSelectField({
|
|
153
|
+
options: SIGNER_STATUS_OPTIONS,
|
|
154
|
+
required: true,
|
|
155
|
+
default: SIGNATURE_SIGNER_STATUS.Pending,
|
|
156
|
+
filterable: true,
|
|
157
|
+
sortable: true,
|
|
158
|
+
}),
|
|
159
|
+
method: createSelectField({ options: METHOD_OPTIONS }),
|
|
160
|
+
signedAt: createTimestampField({
|
|
161
|
+
personal: false,
|
|
162
|
+
reason: "is_business_timestamp",
|
|
163
|
+
sortable: true,
|
|
164
|
+
}),
|
|
165
|
+
imageFileId: createTextField({ ...SIGNER_PERSONAL, maxLength: 64 }),
|
|
166
|
+
linkAnchor: createTextField({
|
|
167
|
+
personal: false,
|
|
168
|
+
reason: "is_grant_anchor",
|
|
169
|
+
maxLength: 64,
|
|
170
|
+
}),
|
|
171
|
+
linkSentAt: createTimestampField({ personal: false, reason: "is_business_timestamp" }),
|
|
172
|
+
viewedAt: createTimestampField({ personal: false, reason: "is_business_timestamp" }),
|
|
173
|
+
viewCount: createNumberField({ default: 0 }),
|
|
174
|
+
signedFromIp: createTextField({ ...SIGNER_PERSONAL, maxLength: 64 }),
|
|
175
|
+
signedUserAgent: createTextField({ ...SIGNER_PERSONAL, maxLength: 500 }),
|
|
176
|
+
declineReason: createLongTextField({ personal: "self", find: "none" }),
|
|
177
|
+
},
|
|
178
|
+
indexes: [{ columns: ["tenantId", "requestId"] }],
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export const signatureRequestEntity = createSignatureRequestEntity();
|
|
183
|
+
export const signatureSignerEntity = createSignatureSignerEntity();
|
|
184
|
+
|
|
185
|
+
export const { executor: requestExecutor, table: signatureRequestTable } = createEntityExecutor(
|
|
186
|
+
SIGNATURE_REQUEST_ENTITY,
|
|
187
|
+
signatureRequestEntity,
|
|
188
|
+
);
|
|
189
|
+
export const { executor: signerExecutor, table: signatureSignerTable } = createEntityExecutor(
|
|
190
|
+
SIGNATURE_SIGNER_ENTITY,
|
|
191
|
+
signatureSignerEntity,
|
|
192
|
+
);
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
defineEntityDetailHandler,
|
|
3
|
+
defineEntityListHandler,
|
|
4
|
+
defineFeature,
|
|
5
|
+
EXT_USER_DATA,
|
|
6
|
+
type FeatureDefinition,
|
|
7
|
+
i18nKey,
|
|
8
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
9
|
+
import { createSignatureRequestEntity, createSignatureSignerEntity } from "./entity.ts";
|
|
10
|
+
import { createAnonymousLinkHandlers } from "./handlers/anonymous.write.ts";
|
|
11
|
+
import { createCancelHandler } from "./handlers/cancel.write.ts";
|
|
12
|
+
import { createIssueLinkHandler } from "./handlers/issue-link.write.ts";
|
|
13
|
+
import { expireHandler, finishHandler, reconcileHandler } from "./handlers/lifecycle.write.ts";
|
|
14
|
+
import { createLinkInternalHandlers } from "./handlers/link-internal.write.ts";
|
|
15
|
+
import { createRequestHandler } from "./handlers/request.write.ts";
|
|
16
|
+
import { createRevokeLinkHandler } from "./handlers/revoke-link.write.ts";
|
|
17
|
+
import { createSignInPersonHandler } from "./handlers/sign-in-person.write.ts";
|
|
18
|
+
import { SIGNATURE_I18N } from "./i18n.ts";
|
|
19
|
+
import { DEFAULT_SIGNATURE_ACCESS } from "./lib.ts";
|
|
20
|
+
import { LINK_RATE_LIMIT, type SignatureOptions } from "./options.ts";
|
|
21
|
+
import {
|
|
22
|
+
SignatureCompletedEventSchema,
|
|
23
|
+
SignatureDeclinedEventSchema,
|
|
24
|
+
SignatureExpiredEventSchema,
|
|
25
|
+
} from "./payloads.ts";
|
|
26
|
+
import { createSignatureDetailScreen, createSignatureListScreen } from "./screens.ts";
|
|
27
|
+
import { sweepSignatureRequests } from "./sweep.ts";
|
|
28
|
+
import { signatureDeleteHook, signatureExportHook } from "./user-data.ts";
|
|
29
|
+
import {
|
|
30
|
+
SIGNATURE_FEATURE,
|
|
31
|
+
SIGNATURE_REQUEST_ENTITY,
|
|
32
|
+
SIGNATURE_SIGNER_ENTITY,
|
|
33
|
+
} from "./web/constants.ts";
|
|
34
|
+
|
|
35
|
+
export function createSignatureFeature(opts: SignatureOptions): FeatureDefinition {
|
|
36
|
+
const signedInAccess = opts.access ?? DEFAULT_SIGNATURE_ACCESS;
|
|
37
|
+
const requestEntity = createSignatureRequestEntity(opts.retention);
|
|
38
|
+
const signerEntity = createSignatureSignerEntity(opts.retention);
|
|
39
|
+
const anonymous = createAnonymousLinkHandlers(LINK_RATE_LIMIT);
|
|
40
|
+
const link = createLinkInternalHandlers(opts.linkSecret);
|
|
41
|
+
|
|
42
|
+
return defineFeature(SIGNATURE_FEATURE, (r) => {
|
|
43
|
+
r.describe(
|
|
44
|
+
"Signature requests: a signed-in user asks several people to sign one PDF of the tenant. Each signer draws a signature on a display in person or through a link in the URL fragment (14 days, limited opens, revocable, single-use, one answer for every rejection). The last signature moves the request to all-signed; a job renders a signature page through the injected print function, appends it to the unchanged original and completes the request. Events completed, declined and expired report the outcome; signer name, email, image, IP and user agent are personal data.",
|
|
45
|
+
);
|
|
46
|
+
r.uiHints({ displayLabel: "Signatures", category: "data", recommended: false });
|
|
47
|
+
r.requires({ features: ["files", "user-data-rights"] });
|
|
48
|
+
r.adoptsBundledLists();
|
|
49
|
+
r.translations({ keys: SIGNATURE_I18N });
|
|
50
|
+
|
|
51
|
+
r.entity({ name: "signatureRequest", ...requestEntity });
|
|
52
|
+
r.entity({ name: "signatureSigner", ...signerEntity });
|
|
53
|
+
|
|
54
|
+
r.defineEvent("completed", SignatureCompletedEventSchema, {
|
|
55
|
+
piiFields: "none",
|
|
56
|
+
});
|
|
57
|
+
r.defineEvent("declined", SignatureDeclinedEventSchema, {
|
|
58
|
+
piiFields: "none",
|
|
59
|
+
});
|
|
60
|
+
r.defineEvent("expired", SignatureExpiredEventSchema, {
|
|
61
|
+
piiFields: "none",
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
r.writeHandler(createRequestHandler(signedInAccess));
|
|
65
|
+
r.writeHandler(createSignInPersonHandler(signedInAccess));
|
|
66
|
+
r.writeHandler(createIssueLinkHandler(signedInAccess, opts));
|
|
67
|
+
r.writeHandler(createRevokeLinkHandler(signedInAccess));
|
|
68
|
+
r.writeHandler(createCancelHandler(signedInAccess));
|
|
69
|
+
r.writeHandler(anonymous.openByLink);
|
|
70
|
+
r.writeHandler(anonymous.signByLink);
|
|
71
|
+
r.writeHandler(anonymous.declineByLink);
|
|
72
|
+
r.writeHandler(link.linkOpen);
|
|
73
|
+
r.writeHandler(link.linkSign);
|
|
74
|
+
r.writeHandler(link.linkDecline);
|
|
75
|
+
r.writeHandler(finishHandler);
|
|
76
|
+
r.writeHandler(expireHandler);
|
|
77
|
+
r.writeHandler(reconcileHandler);
|
|
78
|
+
|
|
79
|
+
r.queryHandler(
|
|
80
|
+
defineEntityListHandler(SIGNATURE_REQUEST_ENTITY, requestEntity, {
|
|
81
|
+
access: signedInAccess,
|
|
82
|
+
description:
|
|
83
|
+
"Lists signature requests with status, deadline and the object they belong to; paging, search over the title and sorting.",
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
r.queryHandler(
|
|
87
|
+
defineEntityDetailHandler(SIGNATURE_REQUEST_ENTITY, requestEntity, {
|
|
88
|
+
access: signedInAccess,
|
|
89
|
+
description: "Returns one signature request.",
|
|
90
|
+
}),
|
|
91
|
+
);
|
|
92
|
+
r.queryHandler(
|
|
93
|
+
defineEntityListHandler(SIGNATURE_SIGNER_ENTITY, signerEntity, {
|
|
94
|
+
access: signedInAccess,
|
|
95
|
+
agent: { expose: false },
|
|
96
|
+
description:
|
|
97
|
+
"Lists the signers of requests with their status and way of signing; carries the signers' personal data.",
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
r.useExtension(EXT_USER_DATA, SIGNATURE_SIGNER_ENTITY, {
|
|
102
|
+
export: signatureExportHook,
|
|
103
|
+
delete: signatureDeleteHook,
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
r.job({
|
|
107
|
+
name: "sweep",
|
|
108
|
+
trigger: { cron: "*/5 * * * *" },
|
|
109
|
+
perTenant: true,
|
|
110
|
+
concurrency: "skip",
|
|
111
|
+
handler: (_payload, ctx) => sweepSignatureRequests(ctx, opts),
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
r.screen(createSignatureListScreen(signedInAccess));
|
|
115
|
+
r.screen(createSignatureDetailScreen(signedInAccess));
|
|
116
|
+
r.nav({
|
|
117
|
+
id: "signature",
|
|
118
|
+
label: i18nKey("signature.nav.signature"),
|
|
119
|
+
screen: "signature:screen:signature-list",
|
|
120
|
+
icon: "file",
|
|
121
|
+
order: 40,
|
|
122
|
+
access: signedInAccess,
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { createHash } from "node:crypto";
|
|
2
|
+
import {
|
|
3
|
+
createEventStoreExecutor,
|
|
4
|
+
selectMany,
|
|
5
|
+
type TenantDb,
|
|
6
|
+
} from "@cosmicdrift/kumiko-framework/db";
|
|
7
|
+
import type { HandlerContext, Registry, SessionUser } from "@cosmicdrift/kumiko-framework/engine";
|
|
8
|
+
import {
|
|
9
|
+
type CreatedFileRef,
|
|
10
|
+
createFileRefFromBytes,
|
|
11
|
+
fileRefEntity,
|
|
12
|
+
fileRefsTable,
|
|
13
|
+
} from "@cosmicdrift/kumiko-framework/files";
|
|
14
|
+
import type { WriteResult } from "@cosmicdrift/kumiko-types/handlers";
|
|
15
|
+
import {
|
|
16
|
+
type FileRefContent,
|
|
17
|
+
FileRefTooLargeError,
|
|
18
|
+
fileContextForTenant,
|
|
19
|
+
readFileRefContent,
|
|
20
|
+
} from "../file-foundation/index.ts";
|
|
21
|
+
|
|
22
|
+
export const PDF_MIME_TYPE = "application/pdf";
|
|
23
|
+
const MAX_DOCUMENT_BYTES = 25 * 1024 * 1024;
|
|
24
|
+
const SIGNED_URL_SECONDS = 15 * 60;
|
|
25
|
+
|
|
26
|
+
type FileContext = Pick<GeneratedFileContext, "db" | "services">;
|
|
27
|
+
|
|
28
|
+
export type GeneratedFileContext = {
|
|
29
|
+
readonly db: TenantDb;
|
|
30
|
+
readonly services: HandlerContext["services"];
|
|
31
|
+
readonly registry: Registry;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// The tenant's file refs only: a caller cannot point a request at another tenant's file.
|
|
35
|
+
export async function readTenantFile(
|
|
36
|
+
ctx: FileContext,
|
|
37
|
+
tenantId: string,
|
|
38
|
+
fileRefId: string,
|
|
39
|
+
): Promise<FileRefContent | null> {
|
|
40
|
+
try {
|
|
41
|
+
return await readFileRefContent({
|
|
42
|
+
db: ctx.db,
|
|
43
|
+
filesForTenant: (ownerTenantId) => fileContextForTenant(ctx, tenantId, ownerTenantId),
|
|
44
|
+
fileRefId,
|
|
45
|
+
allowedTenantIds: [tenantId],
|
|
46
|
+
maxBytes: MAX_DOCUMENT_BYTES,
|
|
47
|
+
});
|
|
48
|
+
} catch (error) {
|
|
49
|
+
if (error instanceof FileRefTooLargeError) return null;
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function storeGeneratedFile(
|
|
55
|
+
ctx: GeneratedFileContext,
|
|
56
|
+
user: SessionUser,
|
|
57
|
+
file: { readonly fileName: string; readonly mimeType: string; readonly data: Uint8Array },
|
|
58
|
+
): Promise<WriteResult<CreatedFileRef>> {
|
|
59
|
+
return createFileRefFromBytes({ ...ctx, user }, file);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Only the opening page of a link gets a URL, and a short-lived one. Providers without presigned
|
|
63
|
+
// URLs (filesystem) yield null; the page then shows the document another way or not at all.
|
|
64
|
+
export async function signedDocumentUrl(
|
|
65
|
+
ctx: FileContext,
|
|
66
|
+
user: SessionUser,
|
|
67
|
+
fileRefId: string,
|
|
68
|
+
): Promise<string | null> {
|
|
69
|
+
const resolver = ctx.services._fileProviderResolver;
|
|
70
|
+
if (resolver === undefined) return null;
|
|
71
|
+
const [row] = await selectMany<{ storageKey: string }>(ctx.db, fileRefsTable, {
|
|
72
|
+
id: fileRefId,
|
|
73
|
+
tenantId: user.tenantId,
|
|
74
|
+
isDeleted: false,
|
|
75
|
+
});
|
|
76
|
+
if (row === undefined) return null;
|
|
77
|
+
const provider = await resolver(user.tenantId);
|
|
78
|
+
if (provider.getSignedUrl === undefined) return null;
|
|
79
|
+
return provider.getSignedUrl(row.storageKey, SIGNED_URL_SECONDS, {
|
|
80
|
+
contentDisposition: 'inline; filename="document.pdf"',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function sha256Hex(bytes: Uint8Array): string {
|
|
85
|
+
return createHash("sha256").update(bytes).digest("hex");
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const fileRefExecutor = createEventStoreExecutor(fileRefsTable, fileRefEntity, {
|
|
89
|
+
entityName: "fileRef",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// For a stored file whose owner row was never written (a lost sign race): removes ref and bytes so
|
|
93
|
+
// no signature image of a person who did not sign stays behind. The ledger entry is not touched:
|
|
94
|
+
// this runs inside the transaction that already took it, and a second connection deleting that
|
|
95
|
+
// row would wait on the lock this transaction holds.
|
|
96
|
+
export async function discardGeneratedFile(
|
|
97
|
+
ctx: GeneratedFileContext,
|
|
98
|
+
user: SessionUser,
|
|
99
|
+
file: CreatedFileRef,
|
|
100
|
+
): Promise<void> {
|
|
101
|
+
await deleteFileRef(ctx.db, user, file.id);
|
|
102
|
+
await ctx.services.files?.ref(file.storageKey).delete();
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export async function deleteFileRef(db: TenantDb, user: SessionUser, id: string): Promise<void> {
|
|
106
|
+
await fileRefExecutor.delete({ id }, user, db);
|
|
107
|
+
}
|