@cosmicdrift/kumiko-bundled-features 0.415.0 → 0.417.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/dist/agent-tools/tool-catalog.js +20 -1
- package/dist/agent-tools/tool-dispatch.js +14 -5
- package/dist/channel-whatsapp/constants.d.ts +1 -0
- package/dist/channel-whatsapp/constants.js +1 -0
- package/dist/channel-whatsapp/graph-client.d.ts +2 -0
- package/dist/channel-whatsapp/graph-client.js +29 -2
- package/dist/handbook-knowledge/constants.d.ts +6 -0
- package/dist/handbook-knowledge/constants.js +6 -0
- package/dist/handbook-knowledge/feature.d.ts +9 -0
- package/dist/handbook-knowledge/feature.js +17 -0
- package/dist/handbook-knowledge/handbook-index.d.ts +26 -0
- package/dist/handbook-knowledge/handbook-index.js +51 -0
- package/dist/handbook-knowledge/handlers.d.ts +28 -0
- package/dist/handbook-knowledge/handlers.js +67 -0
- package/dist/handbook-knowledge/index.d.ts +3 -0
- package/dist/handbook-knowledge/index.js +2 -0
- package/dist/helpdesk/screens.js +5 -1
- package/dist/signature/entity.d.ts +552 -0
- package/dist/signature/entity.js +156 -0
- package/dist/signature/feature.d.ts +3 -0
- package/dist/signature/feature.js +97 -0
- package/dist/signature/files.d.ts +23 -0
- package/dist/signature/files.js +64 -0
- package/dist/signature/grant.d.ts +32 -0
- package/dist/signature/grant.js +44 -0
- package/dist/signature/handlers/anonymous.write.d.ts +14 -0
- package/dist/signature/handlers/anonymous.write.js +52 -0
- package/dist/signature/handlers/cancel.write.d.ts +7 -0
- package/dist/signature/handlers/cancel.write.js +37 -0
- package/dist/signature/handlers/issue-link.write.d.ts +10 -0
- package/dist/signature/handlers/issue-link.write.js +60 -0
- package/dist/signature/handlers/lifecycle.write.d.ts +16 -0
- package/dist/signature/handlers/lifecycle.write.js +70 -0
- package/dist/signature/handlers/link-internal.write.d.ts +23 -0
- package/dist/signature/handlers/link-internal.write.js +186 -0
- package/dist/signature/handlers/request.write.d.ts +20 -0
- package/dist/signature/handlers/request.write.js +86 -0
- package/dist/signature/handlers/revoke-link.write.d.ts +7 -0
- package/dist/signature/handlers/revoke-link.write.js +27 -0
- package/dist/signature/handlers/sign-in-person.write.d.ts +9 -0
- package/dist/signature/handlers/sign-in-person.write.js +55 -0
- package/dist/signature/i18n.d.ts +6 -0
- package/dist/signature/i18n.js +49 -0
- package/dist/signature/index.d.ts +5 -0
- package/dist/signature/index.js +2 -0
- package/dist/signature/lib.d.ts +54 -0
- package/dist/signature/lib.js +68 -0
- package/dist/signature/options.d.ts +40 -0
- package/dist/signature/options.js +5 -0
- package/dist/signature/payloads.d.ts +60 -0
- package/dist/signature/payloads.js +53 -0
- package/dist/signature/png.d.ts +11 -0
- package/dist/signature/png.js +159 -0
- package/dist/signature/screens.d.ts +3 -0
- package/dist/signature/screens.js +97 -0
- package/dist/signature/signature-page.d.ts +25 -0
- package/dist/signature/signature-page.js +62 -0
- package/dist/signature/signing.d.ts +19 -0
- package/dist/signature/signing.js +46 -0
- package/dist/signature/static-sign.d.ts +19 -0
- package/dist/signature/static-sign.js +45 -0
- package/dist/signature/subject-queries.d.ts +5 -0
- package/dist/signature/subject-queries.js +113 -0
- package/dist/signature/subject-scope.d.ts +11 -0
- package/dist/signature/subject-scope.js +20 -0
- package/dist/signature/sweep.d.ts +3 -0
- package/dist/signature/sweep.js +113 -0
- package/dist/signature/user-data.d.ts +3 -0
- package/dist/signature/user-data.js +135 -0
- package/dist/signature/web/constants.d.ts +69 -0
- package/dist/signature/web/constants.js +68 -0
- package/dist/signature/web/index.d.ts +3 -0
- package/dist/signature/web/index.js +2 -0
- package/dist/signature/web/pad.d.ts +20 -0
- package/dist/signature/web/pad.js +104 -0
- package/dist/signature/web/signature-pad.d.ts +19 -0
- package/dist/signature/web/signature-pad.js +36 -0
- package/dist/subscription-stripe/feature.d.ts +6 -0
- package/dist/subscription-stripe/feature.js +3 -0
- package/dist/subscription-stripe/plugin-methods.d.ts +3 -1
- package/dist/subscription-stripe/plugin-methods.js +2 -1
- package/package.json +43 -11
- package/src/agent-tools/changes.json +6 -0
- package/src/channel-whatsapp/changes.json +6 -0
- package/src/handbook-knowledge/changes.json +8 -0
- package/src/signature/changes.json +22 -0
- package/src/subscription-stripe/changes.json +6 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type StaticRequestOptions, type StaticResult } from "@cosmicdrift/kumiko-bundled-features/auth-email-password/static-client";
|
|
2
|
+
import { SIGNATURE_INVALID_LINK_REASON } from "./web/constants.ts";
|
|
3
|
+
export { hrefWithoutUrlToken, readUrlToken, STATIC_NETWORK_REASON, STATIC_RATE_LIMITED_REASON, type StaticFailure, type StaticRequestOptions, type StaticResult, type StaticSuccess, } from "@cosmicdrift/kumiko-bundled-features/auth-email-password/static-client";
|
|
4
|
+
export { bytesToBase64, createSignaturePad, type SignaturePad, type SignaturePadCanvas, type SignaturePadOptions, } from "./web/pad.ts";
|
|
5
|
+
export { SIGNATURE_INVALID_LINK_REASON };
|
|
6
|
+
export type SignatureLinkView = {
|
|
7
|
+
readonly title: string;
|
|
8
|
+
readonly signerName: string;
|
|
9
|
+
readonly role: string | null;
|
|
10
|
+
/** Short-lived URL of the PDF; null when the storage provider cannot sign URLs. */
|
|
11
|
+
readonly documentUrl: string | null;
|
|
12
|
+
};
|
|
13
|
+
/** Reads `#token=` from the current page and removes it from the address bar. Browser only. */
|
|
14
|
+
export declare function takeSignatureToken(): string;
|
|
15
|
+
/** Counts a view but does not use up the link. A bad, used or expired link fails with `invalid_or_expired_link`. */
|
|
16
|
+
export declare function openSignatureLink(token: string, options?: StaticRequestOptions): Promise<StaticResult<SignatureLinkView>>;
|
|
17
|
+
/** `imagePngBase64` comes from `SignaturePad.toPngBase64()`. Uses up the link on success. */
|
|
18
|
+
export declare function signByLink(token: string, imagePngBase64: string, options?: StaticRequestOptions): Promise<StaticResult<undefined>>;
|
|
19
|
+
export declare function declineByLink(token: string, reason?: string, options?: StaticRequestOptions): Promise<StaticResult<undefined>>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// DOM-free signing page for static sites: fetch, canvas and Pointer Events only, no React. The link
|
|
2
|
+
// a signer receives carries the token in the URL fragment (`#token=`), which browsers never send to a
|
|
3
|
+
// server or in a Referer.
|
|
4
|
+
import { dispatchWrite, staticFailure, staticSuccess, takeUrlToken, } from "@cosmicdrift/kumiko-bundled-features/auth-email-password/static-client";
|
|
5
|
+
import { SIGNATURE_INVALID_LINK_REASON, SignatureHandlers } from "./web/constants.js";
|
|
6
|
+
export { hrefWithoutUrlToken, readUrlToken, STATIC_NETWORK_REASON, STATIC_RATE_LIMITED_REASON, } from "@cosmicdrift/kumiko-bundled-features/auth-email-password/static-client";
|
|
7
|
+
export { bytesToBase64, createSignaturePad, } from "./web/pad.js";
|
|
8
|
+
export { SIGNATURE_INVALID_LINK_REASON };
|
|
9
|
+
/** Reads `#token=` from the current page and removes it from the address bar. Browser only. */
|
|
10
|
+
export function takeSignatureToken() {
|
|
11
|
+
return takeUrlToken("fragment");
|
|
12
|
+
}
|
|
13
|
+
function isRecord(value) {
|
|
14
|
+
return typeof value === "object" && value !== null;
|
|
15
|
+
}
|
|
16
|
+
function parseLinkView(data) {
|
|
17
|
+
if (!isRecord(data))
|
|
18
|
+
return null;
|
|
19
|
+
const { title, signerName, role, documentUrl } = data;
|
|
20
|
+
if (typeof title !== "string" || typeof signerName !== "string")
|
|
21
|
+
return null;
|
|
22
|
+
return {
|
|
23
|
+
title,
|
|
24
|
+
signerName,
|
|
25
|
+
role: typeof role === "string" ? role : null,
|
|
26
|
+
documentUrl: typeof documentUrl === "string" ? documentUrl : null,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
/** Counts a view but does not use up the link. A bad, used or expired link fails with `invalid_or_expired_link`. */
|
|
30
|
+
export async function openSignatureLink(token, options) {
|
|
31
|
+
const result = await dispatchWrite(SignatureHandlers.openByLink, { token }, options);
|
|
32
|
+
if (result.kind !== "success")
|
|
33
|
+
return result;
|
|
34
|
+
const view = parseLinkView(result.data);
|
|
35
|
+
return view === null ? staticFailure("unknown") : staticSuccess(view);
|
|
36
|
+
}
|
|
37
|
+
/** `imagePngBase64` comes from `SignaturePad.toPngBase64()`. Uses up the link on success. */
|
|
38
|
+
export async function signByLink(token, imagePngBase64, options) {
|
|
39
|
+
const result = await dispatchWrite(SignatureHandlers.signByLink, { token, imagePngBase64 }, options);
|
|
40
|
+
return result.kind === "success" ? staticSuccess(undefined) : result;
|
|
41
|
+
}
|
|
42
|
+
export async function declineByLink(token, reason, options) {
|
|
43
|
+
const result = await dispatchWrite(SignatureHandlers.declineByLink, { token, ...(reason !== undefined && reason !== "" && { reason }) }, options);
|
|
44
|
+
return result.kind === "success" ? staticSuccess(undefined) : result;
|
|
45
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type QueryHandlerDef } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import type { SubjectScope } from "./subject-scope.ts";
|
|
3
|
+
export declare function scopeRequestList(base: QueryHandlerDef, scope: SubjectScope): QueryHandlerDef;
|
|
4
|
+
export declare function scopeRequestDetail(base: QueryHandlerDef, scope: SubjectScope): QueryHandlerDef;
|
|
5
|
+
export declare function scopeSignerList(base: QueryHandlerDef, scope: SubjectScope): QueryHandlerDef;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { DEFAULT_LIST_LIMIT, entityListSchema, MAX_LIST_LIMIT, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { AccessDeniedError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import { requestExecutor } from "./entity.js";
|
|
4
|
+
function allFilters(payload) {
|
|
5
|
+
return [...(payload.filter === undefined ? [] : [payload.filter]), ...(payload.filters ?? [])];
|
|
6
|
+
}
|
|
7
|
+
function emptyPage(payload) {
|
|
8
|
+
return { rows: [], nextCursor: null, ...(payload.totalCount === true && { total: 0 }) };
|
|
9
|
+
}
|
|
10
|
+
function onlyFilterOn(payload, field) {
|
|
11
|
+
const matching = allFilters(payload).filter((filter) => filter.field === field);
|
|
12
|
+
const [first] = matching;
|
|
13
|
+
return matching.length === 1 && first !== undefined ? first : null;
|
|
14
|
+
}
|
|
15
|
+
function isRowsPage(value) {
|
|
16
|
+
return (typeof value === "object" && value !== null && "rows" in value && Array.isArray(value.rows));
|
|
17
|
+
}
|
|
18
|
+
function subjectKey(subject) {
|
|
19
|
+
return `${String(subject.subjectType)}\u0000${String(subject.subjectId)}`;
|
|
20
|
+
}
|
|
21
|
+
// ponytail: at most this many base pages per answer; a user who may see almost none of the
|
|
22
|
+
// tenant's requests gets short pages and scrolls on. Upgrade to a subject-joined query if that hurts.
|
|
23
|
+
const MAX_BASE_PAGES_PER_ANSWER = 10;
|
|
24
|
+
// authorizeSubject usually queries the database; a page of 200 subjects must not take the whole pool.
|
|
25
|
+
const SUBJECT_CHECKS_IN_PARALLEL = 10;
|
|
26
|
+
export function scopeRequestList(base, scope) {
|
|
27
|
+
return {
|
|
28
|
+
...base,
|
|
29
|
+
handler: async (query, ctx) => {
|
|
30
|
+
const user = query.user;
|
|
31
|
+
if (!scope.isScoped(user))
|
|
32
|
+
return base.handler(query, ctx);
|
|
33
|
+
const payload = entityListSchema.parse(query.payload);
|
|
34
|
+
// Group counts would include requests of foreign subjects, and an offset counts base rows,
|
|
35
|
+
// not the rows this user sees; the screen pages by cursor.
|
|
36
|
+
if (payload.aggregate !== undefined || (payload.offset ?? 0) > 0) {
|
|
37
|
+
throw new AccessDeniedError();
|
|
38
|
+
}
|
|
39
|
+
const limit = payload.limit ?? DEFAULT_LIST_LIMIT;
|
|
40
|
+
const verdicts = new Map();
|
|
41
|
+
const visibleRows = [];
|
|
42
|
+
let page = await base.handler(query, ctx);
|
|
43
|
+
for (let fetched = 1;; fetched++) {
|
|
44
|
+
if (!isRowsPage(page))
|
|
45
|
+
throw new Error("signature request list did not return a rows page");
|
|
46
|
+
const unknownSubjects = new Map(page.rows
|
|
47
|
+
.map((row) => [subjectKey(subjectOf(row)), subjectOf(row)])
|
|
48
|
+
.filter(([key]) => !verdicts.has(key)));
|
|
49
|
+
const pending = [...unknownSubjects];
|
|
50
|
+
for (let start = 0; start < pending.length; start += SUBJECT_CHECKS_IN_PARALLEL) {
|
|
51
|
+
await Promise.all(pending.slice(start, start + SUBJECT_CHECKS_IN_PARALLEL).map(async ([key, subject]) => {
|
|
52
|
+
verdicts.set(key, await scope.allowsRequest(ctx, user, subject));
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
visibleRows.push(...page.rows.filter((row) => verdicts.get(subjectKey(subjectOf(row)))));
|
|
56
|
+
const nextCursor = page["nextCursor"];
|
|
57
|
+
if (visibleRows.length >= limit ||
|
|
58
|
+
typeof nextCursor !== "string" ||
|
|
59
|
+
fetched >= MAX_BASE_PAGES_PER_ANSWER ||
|
|
60
|
+
verdicts.size >= MAX_LIST_LIMIT) {
|
|
61
|
+
// `total` would count requests of foreign subjects; the cursor continues after the last base page.
|
|
62
|
+
const { total: _total, rows: _rows, ...rest } = page;
|
|
63
|
+
return { ...rest, rows: visibleRows };
|
|
64
|
+
}
|
|
65
|
+
page = await base.handler({
|
|
66
|
+
...query,
|
|
67
|
+
payload: { ...payload, cursor: nextCursor, limit: limit - visibleRows.length },
|
|
68
|
+
}, ctx);
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
export function scopeRequestDetail(base, scope) {
|
|
74
|
+
return {
|
|
75
|
+
...base,
|
|
76
|
+
handler: async (query, ctx) => {
|
|
77
|
+
const row = await base.handler(query, ctx);
|
|
78
|
+
if (row === null || !scope.isScoped(query.user))
|
|
79
|
+
return row;
|
|
80
|
+
return (await scope.allowsRequest(ctx, query.user, subjectOf(row))) ? row : null;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function subjectOf(row) {
|
|
85
|
+
if (typeof row !== "object" || row === null)
|
|
86
|
+
return {};
|
|
87
|
+
return {
|
|
88
|
+
subjectType: "subjectType" in row ? row.subjectType : undefined,
|
|
89
|
+
subjectId: "subjectId" in row ? row.subjectId : undefined,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
export function scopeSignerList(base, scope) {
|
|
93
|
+
return {
|
|
94
|
+
...base,
|
|
95
|
+
handler: async (query, ctx) => {
|
|
96
|
+
const user = query.user;
|
|
97
|
+
if (!scope.isScoped(user))
|
|
98
|
+
return base.handler(query, ctx);
|
|
99
|
+
const payload = entityListSchema.parse(query.payload);
|
|
100
|
+
const requestFilter = onlyFilterOn(payload, "requestId");
|
|
101
|
+
if (requestFilter === null ||
|
|
102
|
+
requestFilter.op !== "eq" ||
|
|
103
|
+
typeof requestFilter.value !== "string") {
|
|
104
|
+
throw new AccessDeniedError();
|
|
105
|
+
}
|
|
106
|
+
const request = await requestExecutor.detail({ id: requestFilter.value }, user, ctx.db);
|
|
107
|
+
if (request === null || !(await scope.allowsRequest(ctx, user, request))) {
|
|
108
|
+
return emptyPage(payload);
|
|
109
|
+
}
|
|
110
|
+
return base.handler(query, ctx);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HandlerContext, SessionUser } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import type { SignatureOptions } from "./options.ts";
|
|
3
|
+
export type SubjectScope = {
|
|
4
|
+
isScoped(user: SessionUser): boolean;
|
|
5
|
+
allows(ctx: HandlerContext, user: SessionUser, subjectType: unknown, subjectId: unknown): Promise<boolean>;
|
|
6
|
+
allowsRequest(ctx: HandlerContext, user: SessionUser, request: {
|
|
7
|
+
readonly subjectType?: unknown;
|
|
8
|
+
readonly subjectId?: unknown;
|
|
9
|
+
}): Promise<boolean>;
|
|
10
|
+
};
|
|
11
|
+
export declare function createSubjectScope(opts: Pick<SignatureOptions, "authorizeSubject" | "unscopedRoles">): SubjectScope;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function isNonEmptyString(value) {
|
|
2
|
+
return typeof value === "string" && value !== "";
|
|
3
|
+
}
|
|
4
|
+
export function createSubjectScope(opts) {
|
|
5
|
+
const { authorizeSubject } = opts;
|
|
6
|
+
const unscopedRoles = opts.unscopedRoles ?? [];
|
|
7
|
+
const isScoped = (user) => authorizeSubject !== undefined && !user.roles.some((role) => unscopedRoles.includes(role));
|
|
8
|
+
const allows = async (ctx, user, subjectType, subjectId) => {
|
|
9
|
+
if (authorizeSubject === undefined || !isScoped(user))
|
|
10
|
+
return true;
|
|
11
|
+
if (!isNonEmptyString(subjectType) || !isNonEmptyString(subjectId))
|
|
12
|
+
return false;
|
|
13
|
+
return authorizeSubject(ctx, user, { subjectType, subjectId });
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
isScoped,
|
|
17
|
+
allows,
|
|
18
|
+
allowsRequest: (ctx, user, request) => allows(ctx, user, request.subjectType, request.subjectId),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { Temporal } from "@cosmicdrift/kumiko-types/temporal";
|
|
2
|
+
import { propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
3
|
+
import { requestExecutor } from "./entity.js";
|
|
4
|
+
import { discardGeneratedFile, PDF_MIME_TYPE, readTenantFile, sha256Hex, storeGeneratedFile, } from "./files.js";
|
|
5
|
+
import { instantOrNull, isPastInstant, listSigners, } from "./lib.js";
|
|
6
|
+
import { appendPdfPages, buildSignaturePageHtml, DEFAULT_SIGNATURE_PAGE_LABELS, } from "./signature-page.js";
|
|
7
|
+
import { SIGNATURE_METHOD, SIGNATURE_REQUEST_STATUS, SignatureInternalHandlers, } from "./web/constants.js";
|
|
8
|
+
// Equals the executor's MAX_LIST_LIMIT.
|
|
9
|
+
const SWEEP_PAGE_SIZE = 200;
|
|
10
|
+
// Keyset-paged, so rows that leave the status while the sweep works on them cannot shift the next page.
|
|
11
|
+
async function forEachRequestWithStatus(ctx, status, visit) {
|
|
12
|
+
let cursor = null;
|
|
13
|
+
do {
|
|
14
|
+
const page = await requestExecutor.list({
|
|
15
|
+
filter: { field: "status", op: "eq", value: status },
|
|
16
|
+
limit: SWEEP_PAGE_SIZE,
|
|
17
|
+
...(cursor !== null && { cursor }),
|
|
18
|
+
}, ctx.systemUser, ctx.db);
|
|
19
|
+
for (const request of page.rows)
|
|
20
|
+
await visit(request);
|
|
21
|
+
cursor = page.nextCursor;
|
|
22
|
+
} while (cursor !== null);
|
|
23
|
+
}
|
|
24
|
+
function bySignedAt(left, right) {
|
|
25
|
+
const a = instantOrNull(left.signedAt);
|
|
26
|
+
const b = instantOrNull(right.signedAt);
|
|
27
|
+
if (a === null || b === null)
|
|
28
|
+
return 0;
|
|
29
|
+
return Temporal.Instant.compare(a, b);
|
|
30
|
+
}
|
|
31
|
+
async function signaturePageEntries(ctx, signers) {
|
|
32
|
+
const entries = [];
|
|
33
|
+
for (const signer of [...signers].sort(bySignedAt)) {
|
|
34
|
+
const signedAt = instantOrNull(signer.signedAt);
|
|
35
|
+
if (signedAt === null || typeof signer.imageFileId !== "string")
|
|
36
|
+
return null;
|
|
37
|
+
const image = await readTenantFile(ctx, ctx.systemUser.tenantId, signer.imageFileId);
|
|
38
|
+
if (image === null)
|
|
39
|
+
return null;
|
|
40
|
+
entries.push({
|
|
41
|
+
name: signer.name,
|
|
42
|
+
role: signer.role ?? null,
|
|
43
|
+
signedAtIso: signedAt.toString(),
|
|
44
|
+
method: signer.method === SIGNATURE_METHOD.Link ? SIGNATURE_METHOD.Link : SIGNATURE_METHOD.InPerson,
|
|
45
|
+
imagePng: image.content,
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return entries;
|
|
49
|
+
}
|
|
50
|
+
// Appends the signature page to the unchanged original. A renderer outage throws, the request
|
|
51
|
+
// stays all-signed and the next run tries again.
|
|
52
|
+
async function finalizeRequest(ctx, opts, request) {
|
|
53
|
+
const original = await readTenantFile(ctx, ctx.systemUser.tenantId, request.documentFileId);
|
|
54
|
+
if (original === null || sha256Hex(original.content) !== request.documentSha256) {
|
|
55
|
+
ctx.obs.log.warn("[signature:sweep] original document missing or changed, not completing", {
|
|
56
|
+
requestId: request.id,
|
|
57
|
+
});
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
const entries = await signaturePageEntries(ctx, await listSigners(ctx, ctx.systemUser, request.id));
|
|
61
|
+
if (entries === null) {
|
|
62
|
+
ctx.obs.log.warn("[signature:sweep] signature image missing, not completing", {
|
|
63
|
+
requestId: request.id,
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const html = buildSignaturePageHtml({
|
|
68
|
+
title: request.title,
|
|
69
|
+
documentSha256: request.documentSha256,
|
|
70
|
+
entries,
|
|
71
|
+
labels: DEFAULT_SIGNATURE_PAGE_LABELS,
|
|
72
|
+
});
|
|
73
|
+
const signaturePages = await opts.renderHtmlToPdf(html);
|
|
74
|
+
const completed = await appendPdfPages(original.content, signaturePages);
|
|
75
|
+
const stored = await storeGeneratedFile(ctx, ctx.systemUser, {
|
|
76
|
+
fileName: "signed-document.pdf",
|
|
77
|
+
mimeType: PDF_MIME_TYPE,
|
|
78
|
+
data: completed,
|
|
79
|
+
});
|
|
80
|
+
if (!stored.isSuccess) {
|
|
81
|
+
ctx.obs.log.warn("[signature:sweep] storing the completed pdf failed", {
|
|
82
|
+
requestId: request.id,
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const finished = await ctx.dispatch.write(SignatureInternalHandlers.finish, {
|
|
87
|
+
requestId: request.id,
|
|
88
|
+
completedFileId: stored.data.id,
|
|
89
|
+
});
|
|
90
|
+
if (!finished.isSuccess || propertyOf(finished.data, "finished") !== true) {
|
|
91
|
+
await discardGeneratedFile(ctx, ctx.systemUser, stored.data);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export async function sweepSignatureRequests(ctx, opts) {
|
|
95
|
+
const now = ctx.tz.now();
|
|
96
|
+
await forEachRequestWithStatus(ctx, SIGNATURE_REQUEST_STATUS.Open, async (request) => {
|
|
97
|
+
const qn = isPastInstant(request.expiresAt, now)
|
|
98
|
+
? SignatureInternalHandlers.expire
|
|
99
|
+
: SignatureInternalHandlers.reconcile;
|
|
100
|
+
await ctx.dispatch.write(qn, { requestId: request.id });
|
|
101
|
+
});
|
|
102
|
+
await forEachRequestWithStatus(ctx, SIGNATURE_REQUEST_STATUS.AllSigned, async (request) => {
|
|
103
|
+
try {
|
|
104
|
+
await finalizeRequest(ctx, opts, request);
|
|
105
|
+
}
|
|
106
|
+
catch (error) {
|
|
107
|
+
ctx.obs.log.warn("[signature:sweep] completing failed, retrying on the next run", {
|
|
108
|
+
requestId: request.id,
|
|
109
|
+
error: error instanceof Error ? error.message : String(error),
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { configuredPiiSubjectKms } from "@cosmicdrift/kumiko-framework/crypto";
|
|
2
|
+
import { WritePurposes } from "@cosmicdrift/kumiko-framework/db";
|
|
3
|
+
import { deleteStoredFileAndDerivatives } from "@cosmicdrift/kumiko-framework/derivatives";
|
|
4
|
+
import { createSystemUser, } from "@cosmicdrift/kumiko-framework/engine";
|
|
5
|
+
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
6
|
+
import { fileRefsTable } from "@cosmicdrift/kumiko-framework/files";
|
|
7
|
+
import { collectErasureFailure, throwIfErasureFailed } from "../shared/index.js";
|
|
8
|
+
import { resolveVerifiedUserEmail } from "../user/index.js";
|
|
9
|
+
import { requestExecutor, signatureSignerTable, signerExecutor } from "./entity.js";
|
|
10
|
+
import { deleteFileRef } from "./files.js";
|
|
11
|
+
import { setRequestStatus } from "./lib.js";
|
|
12
|
+
import { SIGNATURE_REQUEST_STATUS, SIGNATURE_SIGNER_ENTITY } from "./web/constants.js";
|
|
13
|
+
const PII_DECRYPT_REASON = "signature:user-data";
|
|
14
|
+
const ANONYMIZED_NAME = "anonymized";
|
|
15
|
+
const ERASE_REASON = "signature:subject-forget";
|
|
16
|
+
// A signer has no user account: the only link to a user is the signer's email, which is stored
|
|
17
|
+
// lowercase and findable by exact match. Without a verified email nothing matches.
|
|
18
|
+
async function findSignerRows(ctx) {
|
|
19
|
+
const email = await resolveVerifiedUserEmail(ctx, PII_DECRYPT_REASON);
|
|
20
|
+
if (email === null)
|
|
21
|
+
return [];
|
|
22
|
+
return ctx.db.selectMany(signatureSignerTable, {
|
|
23
|
+
tenantId: ctx.tenantId,
|
|
24
|
+
email: email.toLowerCase(),
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
function stringOrNull(value) {
|
|
28
|
+
return typeof value === "string" ? value : null;
|
|
29
|
+
}
|
|
30
|
+
// The signer's fields belong to the row's own record key, not to the user's key, so the user
|
|
31
|
+
// forget run does not shred them; and anonymizing only empties the current row, the old events
|
|
32
|
+
// still hold the ciphertext. Without a mounted KMS this erases nothing: record-owned fields stay
|
|
33
|
+
// plaintext framework-wide (see notes-history-user-data), so apps that need Art. 17 coverage mount one.
|
|
34
|
+
async function shredSignerKey(ctx, signerId) {
|
|
35
|
+
// skip: no KMS adapter mounted, nothing is encrypted per record
|
|
36
|
+
await configuredPiiSubjectKms()?.eraseKey({ kind: "record", entity: SIGNATURE_SIGNER_ENTITY, id: signerId }, { requestId: ERASE_REASON, userId: ctx.userId, eraseReason: ERASE_REASON });
|
|
37
|
+
}
|
|
38
|
+
export const signatureExportHook = async (ctx) => {
|
|
39
|
+
const rows = await findSignerRows(ctx);
|
|
40
|
+
if (rows.length === 0)
|
|
41
|
+
return null;
|
|
42
|
+
return {
|
|
43
|
+
entity: SIGNATURE_SIGNER_ENTITY,
|
|
44
|
+
rows: rows.map((row) => ({
|
|
45
|
+
requestId: row["requestId"],
|
|
46
|
+
name: row["name"],
|
|
47
|
+
role: row["role"],
|
|
48
|
+
status: row["status"],
|
|
49
|
+
method: row["method"],
|
|
50
|
+
signedAt: String(row["signedAt"] ?? ""),
|
|
51
|
+
signedFromIp: row["signedFromIp"],
|
|
52
|
+
signedUserAgent: row["signedUserAgent"],
|
|
53
|
+
declineReason: row["declineReason"],
|
|
54
|
+
})),
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
async function purgeSignatureImage(ctx, systemUser, imageFileId) {
|
|
58
|
+
const [ref] = await ctx.db.selectMany(fileRefsTable, {
|
|
59
|
+
id: imageFileId,
|
|
60
|
+
});
|
|
61
|
+
// skip: the image is already gone, nothing left to erase
|
|
62
|
+
if (ref === undefined)
|
|
63
|
+
return;
|
|
64
|
+
const provider = await ctx.buildStorageProvider?.(ctx.tenantId);
|
|
65
|
+
if (!provider) {
|
|
66
|
+
throw new InternalError({
|
|
67
|
+
message: `[signature:user-data] no file storage resolvable, signature image ${imageFileId} cannot be erased`,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
const failed = await deleteStoredFileAndDerivatives(ref.storageKey, provider, PII_DECRYPT_REASON);
|
|
71
|
+
if (failed.length > 0) {
|
|
72
|
+
throw new InternalError({
|
|
73
|
+
message: `[signature:user-data] ${failed.length} byte delete(s) failed for signature image ${imageFileId}`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
await deleteFileRef(ctx.db, systemUser, imageFileId);
|
|
77
|
+
}
|
|
78
|
+
async function cancelUnfinishedRequest(ctx, systemUser, requestId) {
|
|
79
|
+
const request = await requestExecutor.detail({ id: requestId }, systemUser, ctx.db);
|
|
80
|
+
const status = request?.status;
|
|
81
|
+
if (status !== SIGNATURE_REQUEST_STATUS.Open && status !== SIGNATURE_REQUEST_STATUS.AllSigned) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
await setRequestStatus(ctx, systemUser, requestId, status, {
|
|
85
|
+
status: SIGNATURE_REQUEST_STATUS.Cancelled,
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
// Erasure wins over retention for the person's own data: name, email, drawn image, IP address,
|
|
89
|
+
// user agent and refusal reason are removed (strategy delete: the whole row). What stays is the
|
|
90
|
+
// completed PDF with its signature page, which belongs to the request's owner as proof of the
|
|
91
|
+
// contract (Art. 17(3)(e) GDPR), and the row's status and timestamps under "anonymize". A forgotten
|
|
92
|
+
// signer would let the others complete the request without them (delete) or leave an all-signed
|
|
93
|
+
// request without the image it needs (anonymize), so an open or all-signed request is cancelled.
|
|
94
|
+
export const signatureDeleteHook = async (ctx, strategy) => {
|
|
95
|
+
const systemUser = createSystemUser(ctx.tenantId);
|
|
96
|
+
const failures = [];
|
|
97
|
+
for (const row of await findSignerRows(ctx)) {
|
|
98
|
+
const id = stringOrNull(row["id"]);
|
|
99
|
+
if (id === null)
|
|
100
|
+
continue;
|
|
101
|
+
const imageFileId = stringOrNull(row["imageFileId"]);
|
|
102
|
+
if (imageFileId !== null)
|
|
103
|
+
await purgeSignatureImage(ctx, systemUser, imageFileId);
|
|
104
|
+
const requestId = stringOrNull(row["requestId"]);
|
|
105
|
+
if (strategy === "delete") {
|
|
106
|
+
const forgotten = await signerExecutor.forget({ id }, systemUser, ctx.db);
|
|
107
|
+
collectErasureFailure(forgotten, SIGNATURE_SIGNER_ENTITY, id, failures);
|
|
108
|
+
if (forgotten.isSuccess && requestId !== null) {
|
|
109
|
+
await cancelUnfinishedRequest(ctx, systemUser, requestId);
|
|
110
|
+
}
|
|
111
|
+
if (forgotten.isSuccess)
|
|
112
|
+
await shredSignerKey(ctx, id);
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
115
|
+
const anonymized = await signerExecutor.update({
|
|
116
|
+
id,
|
|
117
|
+
changes: {
|
|
118
|
+
name: ANONYMIZED_NAME,
|
|
119
|
+
email: null,
|
|
120
|
+
imageFileId: null,
|
|
121
|
+
signedFromIp: null,
|
|
122
|
+
signedUserAgent: null,
|
|
123
|
+
declineReason: null,
|
|
124
|
+
linkAnchor: null,
|
|
125
|
+
},
|
|
126
|
+
}, systemUser, ctx.db, { skipOptimisticLock: true, writePurpose: WritePurposes.erasure });
|
|
127
|
+
collectErasureFailure(anonymized, SIGNATURE_SIGNER_ENTITY, id, failures);
|
|
128
|
+
if (!anonymized.isSuccess)
|
|
129
|
+
continue;
|
|
130
|
+
if (requestId !== null)
|
|
131
|
+
await cancelUnfinishedRequest(ctx, systemUser, requestId);
|
|
132
|
+
await shredSignerKey(ctx, id);
|
|
133
|
+
}
|
|
134
|
+
throwIfErasureFailed(failures);
|
|
135
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export declare const SIGNATURE_FEATURE: "signature";
|
|
2
|
+
export declare const SIGNATURE_REQUEST_ENTITY: "signatureRequest";
|
|
3
|
+
export declare const SIGNATURE_SIGNER_ENTITY: "signatureSigner";
|
|
4
|
+
export declare const SIGNATURE_LEVEL: {
|
|
5
|
+
readonly Simple: "simple";
|
|
6
|
+
};
|
|
7
|
+
export type SignatureLevel = (typeof SIGNATURE_LEVEL)[keyof typeof SIGNATURE_LEVEL];
|
|
8
|
+
export declare const SIGNATURE_REQUEST_STATUS: {
|
|
9
|
+
readonly Open: "open";
|
|
10
|
+
readonly AllSigned: "all-signed";
|
|
11
|
+
readonly Completed: "completed";
|
|
12
|
+
readonly Declined: "declined";
|
|
13
|
+
readonly Expired: "expired";
|
|
14
|
+
readonly Cancelled: "cancelled";
|
|
15
|
+
};
|
|
16
|
+
export type SignatureRequestStatus = (typeof SIGNATURE_REQUEST_STATUS)[keyof typeof SIGNATURE_REQUEST_STATUS];
|
|
17
|
+
export declare const SIGNATURE_SIGNER_STATUS: {
|
|
18
|
+
readonly Pending: "pending";
|
|
19
|
+
readonly Viewed: "viewed";
|
|
20
|
+
readonly Signed: "signed";
|
|
21
|
+
readonly Declined: "declined";
|
|
22
|
+
};
|
|
23
|
+
export type SignatureSignerStatus = (typeof SIGNATURE_SIGNER_STATUS)[keyof typeof SIGNATURE_SIGNER_STATUS];
|
|
24
|
+
export declare const SIGNATURE_METHOD: {
|
|
25
|
+
readonly InPerson: "in-person";
|
|
26
|
+
readonly Link: "link";
|
|
27
|
+
};
|
|
28
|
+
export type SignatureMethod = (typeof SIGNATURE_METHOD)[keyof typeof SIGNATURE_METHOD];
|
|
29
|
+
export declare const SignatureHandlers: {
|
|
30
|
+
readonly request: "signature:write:request";
|
|
31
|
+
readonly signInPerson: "signature:write:sign-in-person";
|
|
32
|
+
readonly issueLink: "signature:write:issue-link";
|
|
33
|
+
readonly revokeLink: "signature:write:revoke-link";
|
|
34
|
+
readonly cancel: "signature:write:cancel";
|
|
35
|
+
readonly openByLink: "signature:write:open-by-link";
|
|
36
|
+
readonly signByLink: "signature:write:sign-by-link";
|
|
37
|
+
readonly declineByLink: "signature:write:decline-by-link";
|
|
38
|
+
};
|
|
39
|
+
export declare const SignatureQueries: {
|
|
40
|
+
readonly list: "signature:query:signature-request:list";
|
|
41
|
+
readonly detail: "signature:query:signature-request:detail";
|
|
42
|
+
readonly signerList: "signature:query:signature-signer:list";
|
|
43
|
+
};
|
|
44
|
+
export declare const SignatureJobs: {
|
|
45
|
+
readonly sweep: "signature:job:sweep";
|
|
46
|
+
};
|
|
47
|
+
export declare const SIGNATURE_EVENT_SHORT: {
|
|
48
|
+
readonly completed: "completed";
|
|
49
|
+
readonly declined: "declined";
|
|
50
|
+
readonly expired: "expired";
|
|
51
|
+
};
|
|
52
|
+
export declare const SignatureEvents: {
|
|
53
|
+
readonly completed: "signature:event:completed";
|
|
54
|
+
readonly declined: "signature:event:declined";
|
|
55
|
+
readonly expired: "signature:event:expired";
|
|
56
|
+
};
|
|
57
|
+
export declare const SIGNATURE_INVALID_LINK_REASON = "invalid_or_expired_link";
|
|
58
|
+
export declare const SIGNATURE_INVALID_IMAGE_REASON = "invalid_signature_image";
|
|
59
|
+
export declare const SIGNATURE_LINK_TTL_DAYS = 14;
|
|
60
|
+
export declare const SIGNATURE_MAX_LINK_OPENS = 20;
|
|
61
|
+
export declare const SIGNATURE_DEFAULT_VALIDITY_DAYS = 14;
|
|
62
|
+
export declare const SignatureInternalHandlers: {
|
|
63
|
+
readonly linkOpen: "signature:write:link-open";
|
|
64
|
+
readonly linkSign: "signature:write:link-sign";
|
|
65
|
+
readonly linkDecline: "signature:write:link-decline";
|
|
66
|
+
readonly finish: "signature:write:finish";
|
|
67
|
+
readonly expire: "signature:write:expire";
|
|
68
|
+
readonly reconcile: "signature:write:reconcile";
|
|
69
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// Pure string constants, safe for browser code (static-sign imports this file).
|
|
2
|
+
export const SIGNATURE_FEATURE = "signature";
|
|
3
|
+
export const SIGNATURE_REQUEST_ENTITY = "signatureRequest";
|
|
4
|
+
export const SIGNATURE_SIGNER_ENTITY = "signatureSigner";
|
|
5
|
+
export const SIGNATURE_LEVEL = {
|
|
6
|
+
Simple: "simple",
|
|
7
|
+
};
|
|
8
|
+
export const SIGNATURE_REQUEST_STATUS = {
|
|
9
|
+
Open: "open",
|
|
10
|
+
AllSigned: "all-signed",
|
|
11
|
+
Completed: "completed",
|
|
12
|
+
Declined: "declined",
|
|
13
|
+
Expired: "expired",
|
|
14
|
+
Cancelled: "cancelled",
|
|
15
|
+
};
|
|
16
|
+
export const SIGNATURE_SIGNER_STATUS = {
|
|
17
|
+
Pending: "pending",
|
|
18
|
+
Viewed: "viewed",
|
|
19
|
+
Signed: "signed",
|
|
20
|
+
Declined: "declined",
|
|
21
|
+
};
|
|
22
|
+
export const SIGNATURE_METHOD = {
|
|
23
|
+
InPerson: "in-person",
|
|
24
|
+
Link: "link",
|
|
25
|
+
};
|
|
26
|
+
export const SignatureHandlers = {
|
|
27
|
+
request: `${SIGNATURE_FEATURE}:write:request`,
|
|
28
|
+
signInPerson: `${SIGNATURE_FEATURE}:write:sign-in-person`,
|
|
29
|
+
issueLink: `${SIGNATURE_FEATURE}:write:issue-link`,
|
|
30
|
+
revokeLink: `${SIGNATURE_FEATURE}:write:revoke-link`,
|
|
31
|
+
cancel: `${SIGNATURE_FEATURE}:write:cancel`,
|
|
32
|
+
openByLink: `${SIGNATURE_FEATURE}:write:open-by-link`,
|
|
33
|
+
signByLink: `${SIGNATURE_FEATURE}:write:sign-by-link`,
|
|
34
|
+
declineByLink: `${SIGNATURE_FEATURE}:write:decline-by-link`,
|
|
35
|
+
};
|
|
36
|
+
export const SignatureQueries = {
|
|
37
|
+
list: `${SIGNATURE_FEATURE}:query:signature-request:list`,
|
|
38
|
+
detail: `${SIGNATURE_FEATURE}:query:signature-request:detail`,
|
|
39
|
+
signerList: `${SIGNATURE_FEATURE}:query:signature-signer:list`,
|
|
40
|
+
};
|
|
41
|
+
export const SignatureJobs = {
|
|
42
|
+
sweep: `${SIGNATURE_FEATURE}:job:sweep`,
|
|
43
|
+
};
|
|
44
|
+
export const SIGNATURE_EVENT_SHORT = {
|
|
45
|
+
completed: "completed",
|
|
46
|
+
declined: "declined",
|
|
47
|
+
expired: "expired",
|
|
48
|
+
};
|
|
49
|
+
export const SignatureEvents = {
|
|
50
|
+
completed: `${SIGNATURE_FEATURE}:event:${SIGNATURE_EVENT_SHORT.completed}`,
|
|
51
|
+
declined: `${SIGNATURE_FEATURE}:event:${SIGNATURE_EVENT_SHORT.declined}`,
|
|
52
|
+
expired: `${SIGNATURE_FEATURE}:event:${SIGNATURE_EVENT_SHORT.expired}`,
|
|
53
|
+
};
|
|
54
|
+
// Every link rejection (forged, expired, revoked, used up, already signed) carries this reason, so
|
|
55
|
+
// a caller cannot tell the cases apart.
|
|
56
|
+
export const SIGNATURE_INVALID_LINK_REASON = "invalid_or_expired_link";
|
|
57
|
+
export const SIGNATURE_INVALID_IMAGE_REASON = "invalid_signature_image";
|
|
58
|
+
export const SIGNATURE_LINK_TTL_DAYS = 14;
|
|
59
|
+
export const SIGNATURE_MAX_LINK_OPENS = 20;
|
|
60
|
+
export const SIGNATURE_DEFAULT_VALIDITY_DAYS = 14;
|
|
61
|
+
export const SignatureInternalHandlers = {
|
|
62
|
+
linkOpen: `${SIGNATURE_FEATURE}:write:link-open`,
|
|
63
|
+
linkSign: `${SIGNATURE_FEATURE}:write:link-sign`,
|
|
64
|
+
linkDecline: `${SIGNATURE_FEATURE}:write:link-decline`,
|
|
65
|
+
finish: `${SIGNATURE_FEATURE}:write:finish`,
|
|
66
|
+
expire: `${SIGNATURE_FEATURE}:write:expire`,
|
|
67
|
+
reconcile: `${SIGNATURE_FEATURE}:write:reconcile`,
|
|
68
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { SIGNATURE_DEFAULT_VALIDITY_DAYS, SIGNATURE_EVENT_SHORT, SIGNATURE_FEATURE, SIGNATURE_INVALID_IMAGE_REASON, SIGNATURE_INVALID_LINK_REASON, SIGNATURE_LEVEL, SIGNATURE_LINK_TTL_DAYS, SIGNATURE_MAX_LINK_OPENS, SIGNATURE_METHOD, SIGNATURE_REQUEST_ENTITY, SIGNATURE_REQUEST_STATUS, SIGNATURE_SIGNER_ENTITY, SIGNATURE_SIGNER_STATUS, SignatureEvents, SignatureHandlers, SignatureInternalHandlers, SignatureJobs, type SignatureLevel, type SignatureMethod, SignatureQueries, type SignatureRequestStatus, type SignatureSignerStatus, } from "./constants.ts";
|
|
2
|
+
export type { SignaturePad as SignaturePadController, SignaturePadOptions } from "./pad.ts";
|
|
3
|
+
export { DEFAULT_SIGNATURE_PAD_LABELS, SignaturePad, type SignaturePadLabels, type SignaturePadProps, } from "./signature-pad.tsx";
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
export { SIGNATURE_DEFAULT_VALIDITY_DAYS, SIGNATURE_EVENT_SHORT, SIGNATURE_FEATURE, SIGNATURE_INVALID_IMAGE_REASON, SIGNATURE_INVALID_LINK_REASON, SIGNATURE_LEVEL, SIGNATURE_LINK_TTL_DAYS, SIGNATURE_MAX_LINK_OPENS, SIGNATURE_METHOD, SIGNATURE_REQUEST_ENTITY, SIGNATURE_REQUEST_STATUS, SIGNATURE_SIGNER_ENTITY, SIGNATURE_SIGNER_STATUS, SignatureEvents, SignatureHandlers, SignatureInternalHandlers, SignatureJobs, SignatureQueries, } from "./constants.js";
|
|
2
|
+
export { DEFAULT_SIGNATURE_PAD_LABELS, SignaturePad, } from "./signature-pad.js";
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type SignaturePadCanvas = Pick<HTMLCanvasElement, "width" | "height" | "addEventListener" | "removeEventListener" | "getBoundingClientRect" | "getContext" | "toBlob" | "setPointerCapture" | "releasePointerCapture"> & {
|
|
2
|
+
readonly style: Pick<CSSStyleDeclaration, "touchAction">;
|
|
3
|
+
};
|
|
4
|
+
export type SignaturePadOptions = {
|
|
5
|
+
/** Stroke width in canvas pixels. Default 3. */
|
|
6
|
+
readonly lineWidth?: number;
|
|
7
|
+
/** Stroke colour. Default near-black. */
|
|
8
|
+
readonly strokeStyle?: string;
|
|
9
|
+
/** Called whenever the field switches between empty and drawn. */
|
|
10
|
+
readonly onChange?: (isEmpty: boolean) => void;
|
|
11
|
+
};
|
|
12
|
+
export type SignaturePad = {
|
|
13
|
+
readonly clear: () => void;
|
|
14
|
+
readonly isEmpty: () => boolean;
|
|
15
|
+
/** PNG with transparent background as base64 without the data-URL prefix. */
|
|
16
|
+
readonly toPngBase64: () => Promise<string>;
|
|
17
|
+
readonly destroy: () => void;
|
|
18
|
+
};
|
|
19
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
20
|
+
export declare function createSignaturePad(canvas: SignaturePadCanvas, options?: SignaturePadOptions): SignaturePad;
|