@cosmicdrift/kumiko-samples 0.416.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/package.json +1 -1
- package/packages/bundled-features/package.json +1 -1
- package/packages/bundled-features/src/helpdesk/screens.ts +5 -1
- package/packages/bundled-features/src/signature/README.md +7 -0
- package/packages/bundled-features/src/signature/changes.json +7 -0
- package/packages/bundled-features/src/signature/feature.ts +26 -26
- package/packages/bundled-features/src/signature/handlers/cancel.write.ts +11 -3
- package/packages/bundled-features/src/signature/handlers/issue-link.write.ts +5 -0
- package/packages/bundled-features/src/signature/handlers/request.write.ts +37 -3
- package/packages/bundled-features/src/signature/handlers/revoke-link.write.ts +15 -1
- package/packages/bundled-features/src/signature/handlers/sign-in-person.write.ts +5 -1
- package/packages/bundled-features/src/signature/index.ts +2 -0
- package/packages/bundled-features/src/signature/options.ts +15 -0
- package/packages/bundled-features/src/signature/screens.ts +2 -0
- package/packages/bundled-features/src/signature/static-sign.ts +2 -1
- package/packages/bundled-features/src/signature/subject-queries.ts +144 -0
- package/packages/bundled-features/src/signature/subject-scope.ts +43 -0
- package/samples/recipes/dashboard-stats/README.md +4 -0
- package/samples/recipes/dashboard-stats/src/feature.ts +47 -0
- package/samples/recipes/event-sourcing/src/feature.ts +31 -0
- package/samples/recipes/list-table-options/README.md +9 -0
- package/samples/recipes/list-table-options/src/feature.ts +47 -2
- package/samples/recipes/managed-config/src/feature.ts +9 -1
- package/samples/recipes/record-detail-layout/README.md +7 -0
- package/samples/recipes/record-detail-layout/src/feature.ts +40 -2
- package/samples/recipes/record-detail-layout/src/order-board.ts +1 -0
- package/samples/recipes/secrets-demo/README.md +1 -1
- package/samples/recipes/secrets-demo/src/feature.ts +2 -0
- package/samples/recipes/writeform-section/README.md +4 -0
- package/samples/recipes/writeform-section/src/feature.ts +97 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-samples",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.417.0",
|
|
4
4
|
"description": "Source trees of the Kumiko sample recipes, sample apps and bundled features in repo layout, for tooling such as few-shot corpus builds.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cosmicdrift/kumiko-bundled-features",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.417.0",
|
|
4
4
|
"description": "Built-in features — tenant, user, auth, delivery. The stuff you'd rewrite anyway, already typed.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Marc Frost <marc@cosmicdriftgamestudio.com>",
|
|
@@ -323,7 +323,11 @@ function createRequestDetailScreen(
|
|
|
323
323
|
field: "authorName",
|
|
324
324
|
label: `${HELPDESK_FEATURE}:entity:helpdesk-reply:field:authorName`,
|
|
325
325
|
},
|
|
326
|
-
{
|
|
326
|
+
{
|
|
327
|
+
field: "message",
|
|
328
|
+
label: `${HELPDESK_FEATURE}:entity:helpdesk-reply:field:message`,
|
|
329
|
+
multiline: true,
|
|
330
|
+
},
|
|
327
331
|
],
|
|
328
332
|
},
|
|
329
333
|
{
|
|
@@ -32,6 +32,13 @@ the `files` feature. Order of signatures is free.
|
|
|
32
32
|
| `signaturePageUrl` | required | URL of the app's signature page; the token is appended as `#<token>` |
|
|
33
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
34
|
|
|
35
|
+
Subject scope: `authorizeSubject(ctx, user, { subjectType, subjectId })` limits requests to the
|
|
36
|
+
subjects a user may see. It runs for every signed-in handler and query; `false` answers like a missing
|
|
37
|
+
record. `unscopedRoles` (e.g. `["TenantAdmin"]`) skip it. For a scoped user `signatureRequest:list` keeps only the
|
|
38
|
+
rows of allowed subjects, reading up to ten base pages per answer (it can still hold fewer rows than `limit`), and has no `total`; screens
|
|
39
|
+
and nav stay at `access`. `signatureSigner:list` needs a `requestId` eq filter, otherwise 403. `request` also
|
|
40
|
+
refuses a document the caller cannot open through `GET /files/:id`.
|
|
41
|
+
|
|
35
42
|
## Handlers
|
|
36
43
|
|
|
37
44
|
Signed in: `request`, `sign-in-person`, `issue-link`, `revoke-link`, `cancel`.
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
[
|
|
2
|
+
{
|
|
3
|
+
"version": "0.417.0",
|
|
4
|
+
"type": "breaking",
|
|
5
|
+
"title": "Subject check for the signature feature and a readable-file check on requests",
|
|
6
|
+
"detail": "`createSignatureFeature({ ..., authorizeSubject, unscopedRoles })`: `authorizeSubject(ctx, user, { subjectType, subjectId })` runs for `request`, `cancel`, `issue-link`, `revoke-link`, `sign-in-person` and the queries, except for users holding a role of `unscopedRoles`; `false` answers like a missing record (not found, `null` or an empty page). `signatureRequest:list` keeps only the rows of allowed subjects for a scoped user and reads up to ten base pages to fill one answer (no 403; an answer can still hold fewer rows than `limit`, and it has no `total`); screens and nav stay at `access`. A scoped user must pass a `requestId` eq filter to `signatureSigner:list`, otherwise the query answers 403. `request` now also checks that the caller may read the document through the same decision as GET /files/:id; a file that is unknown or not readable answers `document_not_a_pdf`. `SIGNATURE_INVALID_LINK_REASON` is exported from `signature/static-sign`.",
|
|
7
|
+
"migration": "Apps that request a signature on a file the caller cannot open through GET /files/:id bind it to a record the caller can read first. Apps with authorizeSubject pass a requestId eq filter to signatureSigner:list and do not rely on `total` of signatureRequest:list for scoped users."
|
|
8
|
+
},
|
|
2
9
|
{
|
|
3
10
|
"version": "0.416.0",
|
|
4
11
|
"type": "improvement",
|
|
@@ -24,6 +24,8 @@ import {
|
|
|
24
24
|
SignatureExpiredEventSchema,
|
|
25
25
|
} from "./payloads.ts";
|
|
26
26
|
import { createSignatureDetailScreen, createSignatureListScreen } from "./screens.ts";
|
|
27
|
+
import { scopeRequestDetail, scopeRequestList, scopeSignerList } from "./subject-queries.ts";
|
|
28
|
+
import { createSubjectScope } from "./subject-scope.ts";
|
|
27
29
|
import { sweepSignatureRequests } from "./sweep.ts";
|
|
28
30
|
import { signatureDeleteHook, signatureExportHook } from "./user-data.ts";
|
|
29
31
|
import {
|
|
@@ -34,6 +36,7 @@ import {
|
|
|
34
36
|
|
|
35
37
|
export function createSignatureFeature(opts: SignatureOptions): FeatureDefinition {
|
|
36
38
|
const signedInAccess = opts.access ?? DEFAULT_SIGNATURE_ACCESS;
|
|
39
|
+
const scope = createSubjectScope(opts);
|
|
37
40
|
const requestEntity = createSignatureRequestEntity(opts.retention);
|
|
38
41
|
const signerEntity = createSignatureSignerEntity(opts.retention);
|
|
39
42
|
const anonymous = createAnonymousLinkHandlers(LINK_RATE_LIMIT);
|
|
@@ -61,11 +64,11 @@ export function createSignatureFeature(opts: SignatureOptions): FeatureDefinitio
|
|
|
61
64
|
piiFields: "none",
|
|
62
65
|
});
|
|
63
66
|
|
|
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));
|
|
67
|
+
r.writeHandler(createRequestHandler(signedInAccess, scope));
|
|
68
|
+
r.writeHandler(createSignInPersonHandler(signedInAccess, scope));
|
|
69
|
+
r.writeHandler(createIssueLinkHandler(signedInAccess, scope, opts));
|
|
70
|
+
r.writeHandler(createRevokeLinkHandler(signedInAccess, scope));
|
|
71
|
+
r.writeHandler(createCancelHandler(signedInAccess, scope));
|
|
69
72
|
r.writeHandler(anonymous.openByLink);
|
|
70
73
|
r.writeHandler(anonymous.signByLink);
|
|
71
74
|
r.writeHandler(anonymous.declineByLink);
|
|
@@ -76,27 +79,24 @@ export function createSignatureFeature(opts: SignatureOptions): FeatureDefinitio
|
|
|
76
79
|
r.writeHandler(expireHandler);
|
|
77
80
|
r.writeHandler(reconcileHandler);
|
|
78
81
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
"Lists the signers of requests with their status and way of signing; carries the signers' personal data.",
|
|
98
|
-
}),
|
|
99
|
-
);
|
|
82
|
+
const requestList = defineEntityListHandler(SIGNATURE_REQUEST_ENTITY, requestEntity, {
|
|
83
|
+
access: signedInAccess,
|
|
84
|
+
description:
|
|
85
|
+
"Lists signature requests with status, deadline and the object they belong to; paging, search over the title and sorting.",
|
|
86
|
+
});
|
|
87
|
+
const requestDetail = defineEntityDetailHandler(SIGNATURE_REQUEST_ENTITY, requestEntity, {
|
|
88
|
+
access: signedInAccess,
|
|
89
|
+
description: "Returns one signature request.",
|
|
90
|
+
});
|
|
91
|
+
const signerList = defineEntityListHandler(SIGNATURE_SIGNER_ENTITY, signerEntity, {
|
|
92
|
+
access: signedInAccess,
|
|
93
|
+
agent: { expose: false },
|
|
94
|
+
description:
|
|
95
|
+
"Lists the signers of requests with their status and way of signing; carries the signers' personal data.",
|
|
96
|
+
});
|
|
97
|
+
r.queryHandler(scopeRequestList(requestList, scope));
|
|
98
|
+
r.queryHandler(scopeRequestDetail(requestDetail, scope));
|
|
99
|
+
r.queryHandler(scopeSignerList(signerList, scope));
|
|
100
100
|
|
|
101
101
|
r.useExtension(EXT_USER_DATA, SIGNATURE_SIGNER_ENTITY, {
|
|
102
102
|
export: signatureExportHook,
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { type AccessRule, defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
-
import {
|
|
2
|
+
import { NotFoundError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import { requestExecutor, signerExecutor } from "../entity.ts";
|
|
3
4
|
import { isUnsignedSigner, listSigners, setRequestStatus } from "../lib.ts";
|
|
4
5
|
import { RequestIdSchema } from "../payloads.ts";
|
|
5
|
-
import {
|
|
6
|
+
import type { SubjectScope } from "../subject-scope.ts";
|
|
7
|
+
import { SIGNATURE_REQUEST_ENTITY, SIGNATURE_REQUEST_STATUS } from "../web/constants.ts";
|
|
6
8
|
|
|
7
9
|
// Cancelling moves the request out of `open`, which already makes every link of it fail; the
|
|
8
10
|
// anchors are cleared as well so no token verifies against a cancelled request.
|
|
9
|
-
export function createCancelHandler(access: AccessRule) {
|
|
11
|
+
export function createCancelHandler(access: AccessRule, scope: SubjectScope) {
|
|
10
12
|
return defineWriteHandler<"cancel", typeof RequestIdSchema, { readonly cancelled: true }>({
|
|
11
13
|
name: "cancel",
|
|
12
14
|
schema: RequestIdSchema,
|
|
@@ -16,6 +18,12 @@ export function createCancelHandler(access: AccessRule) {
|
|
|
16
18
|
"Cancels an open signature request; all its signing links stop working. Signatures already given stay on record.",
|
|
17
19
|
handler: async (event, ctx) => {
|
|
18
20
|
const user = event.user;
|
|
21
|
+
if (scope.isScoped(user)) {
|
|
22
|
+
const request = await requestExecutor.detail({ id: event.payload.requestId }, user, ctx.db);
|
|
23
|
+
if (request === null || !(await scope.allowsRequest(ctx, user, request))) {
|
|
24
|
+
return writeFailure(new NotFoundError(SIGNATURE_REQUEST_ENTITY, event.payload.requestId));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
19
27
|
const moved = await setRequestStatus(
|
|
20
28
|
ctx,
|
|
21
29
|
user,
|
|
@@ -10,12 +10,14 @@ import { signSignatureLinkToken } from "../grant.ts";
|
|
|
10
10
|
import { isOpenRequest, isUnsignedSigner, loadRequestOfSigner } from "../lib.ts";
|
|
11
11
|
import type { SignatureOptions } from "../options.ts";
|
|
12
12
|
import { SignerIdSchema } from "../payloads.ts";
|
|
13
|
+
import type { SubjectScope } from "../subject-scope.ts";
|
|
13
14
|
|
|
14
15
|
export type IssueLinkData = { readonly signerId: string; readonly linkSentAt: string };
|
|
15
16
|
|
|
16
17
|
// A new link replaces the previous one: the anchor moves on, so the old token stops verifying.
|
|
17
18
|
export function createIssueLinkHandler(
|
|
18
19
|
access: AccessRule,
|
|
20
|
+
scope: SubjectScope,
|
|
19
21
|
opts: Pick<SignatureOptions, "linkSecret" | "deliverLink" | "signaturePageUrl">,
|
|
20
22
|
) {
|
|
21
23
|
return defineWriteHandler<"issue-link", typeof SignerIdSchema, IssueLinkData>({
|
|
@@ -30,6 +32,9 @@ export function createIssueLinkHandler(
|
|
|
30
32
|
const signer = await signerExecutor.detail({ id: event.payload.signerId }, user, ctx.db);
|
|
31
33
|
if (signer === null) return writeFailure(new NotFoundError("signer", event.payload.signerId));
|
|
32
34
|
const request = await loadRequestOfSigner(ctx, user, signer);
|
|
35
|
+
if (request !== null && !(await scope.allowsRequest(ctx, user, request))) {
|
|
36
|
+
return writeFailure(new NotFoundError("signer", event.payload.signerId));
|
|
37
|
+
}
|
|
33
38
|
const now = ctx.tz.now();
|
|
34
39
|
if (request === null || !isOpenRequest(request, now) || !isUnsignedSigner(signer)) {
|
|
35
40
|
return writeFailure(new UnprocessableError("link_not_possible"));
|
|
@@ -1,11 +1,28 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { selectMany } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import {
|
|
3
|
+
type AccessRule,
|
|
4
|
+
defineWriteHandler,
|
|
5
|
+
type HandlerContext,
|
|
6
|
+
isUuid,
|
|
7
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
8
|
+
import {
|
|
9
|
+
NotFoundError,
|
|
10
|
+
UnprocessableError,
|
|
11
|
+
writeFailure,
|
|
12
|
+
} from "@cosmicdrift/kumiko-framework/errors";
|
|
13
|
+
import {
|
|
14
|
+
canCallerReadFileRef,
|
|
15
|
+
type FileRef,
|
|
16
|
+
fileRefsTable,
|
|
17
|
+
} from "@cosmicdrift/kumiko-framework/files";
|
|
3
18
|
import { PDFDocument } from "pdf-lib";
|
|
4
19
|
import { requestExecutor, signerExecutor } from "../entity.ts";
|
|
5
20
|
import { readTenantFile, sha256Hex } from "../files.ts";
|
|
6
21
|
import { RequestSignatureSchema } from "../payloads.ts";
|
|
22
|
+
import type { SubjectScope } from "../subject-scope.ts";
|
|
7
23
|
import {
|
|
8
24
|
SIGNATURE_DEFAULT_VALIDITY_DAYS,
|
|
25
|
+
SIGNATURE_REQUEST_ENTITY,
|
|
9
26
|
SIGNATURE_REQUEST_STATUS,
|
|
10
27
|
SIGNATURE_SIGNER_STATUS,
|
|
11
28
|
} from "../web/constants.ts";
|
|
@@ -28,7 +45,18 @@ async function isLoadablePdf(bytes: Uint8Array): Promise<boolean> {
|
|
|
28
45
|
}
|
|
29
46
|
}
|
|
30
47
|
|
|
31
|
-
|
|
48
|
+
// A file the caller may not open through GET /files/:id answers like an unknown id, so ids cannot be probed.
|
|
49
|
+
async function isReadableTenantFile(ctx: HandlerContext, fileRefId: string): Promise<boolean> {
|
|
50
|
+
if (!isUuid(fileRefId)) return false;
|
|
51
|
+
const [fileRef] = await selectMany<FileRef>(ctx.db, fileRefsTable, {
|
|
52
|
+
id: fileRefId,
|
|
53
|
+
tenantId: ctx.user.tenantId,
|
|
54
|
+
isDeleted: false,
|
|
55
|
+
});
|
|
56
|
+
return fileRef !== undefined && (await canCallerReadFileRef(ctx, fileRef));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function createRequestHandler(access: AccessRule, scope: SubjectScope) {
|
|
32
60
|
return defineWriteHandler<"request", typeof RequestSignatureSchema, RequestSignatureData>({
|
|
33
61
|
name: "request",
|
|
34
62
|
schema: RequestSignatureSchema,
|
|
@@ -39,6 +67,12 @@ export function createRequestHandler(access: AccessRule) {
|
|
|
39
67
|
handler: async (event, ctx) => {
|
|
40
68
|
const payload = event.payload;
|
|
41
69
|
const user = event.user;
|
|
70
|
+
if (!(await scope.allows(ctx, user, payload.subjectType, payload.subjectId))) {
|
|
71
|
+
return writeFailure(new NotFoundError(SIGNATURE_REQUEST_ENTITY));
|
|
72
|
+
}
|
|
73
|
+
if (!(await isReadableTenantFile(ctx, payload.documentFileId))) {
|
|
74
|
+
return writeFailure(new UnprocessableError("document_not_a_pdf"));
|
|
75
|
+
}
|
|
42
76
|
const document = await readTenantFile(ctx, user.tenantId, payload.documentFileId);
|
|
43
77
|
if (document === null || !(await isLoadablePdf(document.content))) {
|
|
44
78
|
return writeFailure(new UnprocessableError("document_not_a_pdf"));
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { type AccessRule, defineWriteHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { NotFoundError, writeFailure } from "@cosmicdrift/kumiko-framework/errors";
|
|
2
3
|
import { signerExecutor } from "../entity.ts";
|
|
4
|
+
import { loadRequestOfSigner } from "../lib.ts";
|
|
3
5
|
import { SignerIdSchema } from "../payloads.ts";
|
|
6
|
+
import type { SubjectScope } from "../subject-scope.ts";
|
|
4
7
|
|
|
5
|
-
export function createRevokeLinkHandler(access: AccessRule) {
|
|
8
|
+
export function createRevokeLinkHandler(access: AccessRule, scope: SubjectScope) {
|
|
6
9
|
return defineWriteHandler<"revoke-link", typeof SignerIdSchema, { readonly revoked: true }>({
|
|
7
10
|
name: "revoke-link",
|
|
8
11
|
schema: SignerIdSchema,
|
|
@@ -10,6 +13,17 @@ export function createRevokeLinkHandler(access: AccessRule) {
|
|
|
10
13
|
agent: { expose: false },
|
|
11
14
|
description: "Revokes the signing link of one signer; the token stops working at once.",
|
|
12
15
|
handler: async (event, ctx) => {
|
|
16
|
+
if (scope.isScoped(event.user)) {
|
|
17
|
+
const signer = await signerExecutor.detail(
|
|
18
|
+
{ id: event.payload.signerId },
|
|
19
|
+
event.user,
|
|
20
|
+
ctx.db,
|
|
21
|
+
);
|
|
22
|
+
const request = signer === null ? null : await loadRequestOfSigner(ctx, event.user, signer);
|
|
23
|
+
if (request === null || !(await scope.allowsRequest(ctx, event.user, request))) {
|
|
24
|
+
return writeFailure(new NotFoundError("signer", event.payload.signerId));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
13
27
|
const updated = await signerExecutor.update(
|
|
14
28
|
{ id: event.payload.signerId, changes: { linkAnchor: null } },
|
|
15
29
|
event.user,
|
|
@@ -19,11 +19,12 @@ import {
|
|
|
19
19
|
recordInPersonSignature,
|
|
20
20
|
storeSignatureImage,
|
|
21
21
|
} from "../signing.ts";
|
|
22
|
+
import type { SubjectScope } from "../subject-scope.ts";
|
|
22
23
|
import { SIGNATURE_METHOD, SIGNATURE_REQUEST_STATUS } from "../web/constants.ts";
|
|
23
24
|
|
|
24
25
|
export type SignInPersonData = { readonly requestStatus: string };
|
|
25
26
|
|
|
26
|
-
export function createSignInPersonHandler(access: AccessRule) {
|
|
27
|
+
export function createSignInPersonHandler(access: AccessRule, scope: SubjectScope) {
|
|
27
28
|
return defineWriteHandler<"sign-in-person", typeof SignInPersonSchema, SignInPersonData>({
|
|
28
29
|
name: "sign-in-person",
|
|
29
30
|
schema: SignInPersonSchema,
|
|
@@ -36,6 +37,9 @@ export function createSignInPersonHandler(access: AccessRule) {
|
|
|
36
37
|
const signer = await signerExecutor.detail({ id: event.payload.signerId }, user, ctx.db);
|
|
37
38
|
if (signer === null) return writeFailure(new NotFoundError("signer", event.payload.signerId));
|
|
38
39
|
const request = await loadRequestOfSigner(ctx, user, signer);
|
|
40
|
+
if (request !== null && !(await scope.allowsRequest(ctx, user, request))) {
|
|
41
|
+
return writeFailure(new NotFoundError("signer", event.payload.signerId));
|
|
42
|
+
}
|
|
39
43
|
const now = ctx.tz.now();
|
|
40
44
|
if (request === null || !isOpenRequest(request, now) || !isUnsignedSigner(signer)) {
|
|
41
45
|
return writeFailure(new UnprocessableError("signature_not_possible"));
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export type { SignatureRetention } from "./entity.ts";
|
|
2
2
|
export { createSignatureFeature } from "./feature.ts";
|
|
3
3
|
export type {
|
|
4
|
+
AuthorizeSignatureSubject,
|
|
4
5
|
DeliverSignatureLink,
|
|
5
6
|
RenderSignatureHtmlToPdf,
|
|
6
7
|
SignatureLinkDelivery,
|
|
7
8
|
SignatureOptions,
|
|
9
|
+
SignatureSubject,
|
|
8
10
|
} from "./options.ts";
|
|
9
11
|
export type { SignaturePageLabels } from "./signature-page.ts";
|
|
10
12
|
export {
|
|
@@ -27,6 +27,17 @@ export type DeliverSignatureLink = (
|
|
|
27
27
|
delivery: SignatureLinkDelivery,
|
|
28
28
|
) => Promise<void>;
|
|
29
29
|
|
|
30
|
+
export type SignatureSubject = {
|
|
31
|
+
readonly subjectType: string;
|
|
32
|
+
readonly subjectId: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export type AuthorizeSignatureSubject = (
|
|
36
|
+
ctx: HandlerContext,
|
|
37
|
+
user: SessionUser,
|
|
38
|
+
subject: SignatureSubject,
|
|
39
|
+
) => Promise<boolean>;
|
|
40
|
+
|
|
30
41
|
export type SignatureOptions = {
|
|
31
42
|
/** How long requests and signers are kept, data-retention keepFor syntax, counted from creation. */
|
|
32
43
|
readonly retention: SignatureRetention;
|
|
@@ -40,6 +51,10 @@ export type SignatureOptions = {
|
|
|
40
51
|
readonly signaturePageUrl: string;
|
|
41
52
|
/** Access rule of the signed-in handlers, queries, screens and nav. Default `{ roles: ["TenantAdmin", "TenantMember"] }`; set it when the app hands out other roles. The link handlers stay anonymous. */
|
|
42
53
|
readonly access?: AccessRule;
|
|
54
|
+
/** Runs for every signed-in handler and query on the subject of the request, except for `unscopedRoles`. `false` answers like "does not exist". Without it every user with `access` sees every request of the tenant. */
|
|
55
|
+
readonly authorizeSubject?: AuthorizeSignatureSubject;
|
|
56
|
+
/** Roles that skip `authorizeSubject`, e.g. admins. */
|
|
57
|
+
readonly unscopedRoles?: readonly string[];
|
|
43
58
|
};
|
|
44
59
|
|
|
45
60
|
export const LINK_RATE_LIMIT: RateLimitDeclaration = {
|
|
@@ -44,6 +44,8 @@ export function createSignatureListScreen(
|
|
|
44
44
|
{ field: "completedAt", hideOnNarrow: true },
|
|
45
45
|
],
|
|
46
46
|
defaultSort: { field: "expiresAt", dir: "desc" },
|
|
47
|
+
// A user bound by authorizeSubject gets no total, so the list pages by cursor.
|
|
48
|
+
pagination: "infinite",
|
|
47
49
|
access,
|
|
48
50
|
searchable: true,
|
|
49
51
|
rowActions: [
|
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
staticSuccess,
|
|
11
11
|
takeUrlToken,
|
|
12
12
|
} from "@cosmicdrift/kumiko-bundled-features/auth-email-password/static-client";
|
|
13
|
-
import { SignatureHandlers } from "./web/constants.ts";
|
|
13
|
+
import { SIGNATURE_INVALID_LINK_REASON, SignatureHandlers } from "./web/constants.ts";
|
|
14
14
|
|
|
15
15
|
export {
|
|
16
16
|
hrefWithoutUrlToken,
|
|
@@ -29,6 +29,7 @@ export {
|
|
|
29
29
|
type SignaturePadCanvas,
|
|
30
30
|
type SignaturePadOptions,
|
|
31
31
|
} from "./web/pad.ts";
|
|
32
|
+
export { SIGNATURE_INVALID_LINK_REASON };
|
|
32
33
|
|
|
33
34
|
export type SignatureLinkView = {
|
|
34
35
|
readonly title: string;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_LIST_LIMIT,
|
|
3
|
+
entityListSchema,
|
|
4
|
+
type HandlerContext,
|
|
5
|
+
MAX_LIST_LIMIT,
|
|
6
|
+
type QueryHandlerDef,
|
|
7
|
+
type SessionUser,
|
|
8
|
+
} from "@cosmicdrift/kumiko-framework/engine";
|
|
9
|
+
import { AccessDeniedError } from "@cosmicdrift/kumiko-framework/errors";
|
|
10
|
+
import { requestExecutor } from "./entity.ts";
|
|
11
|
+
import type { SubjectScope } from "./subject-scope.ts";
|
|
12
|
+
|
|
13
|
+
type ListPayload = ReturnType<typeof entityListSchema.parse>;
|
|
14
|
+
type ListFilter = NonNullable<ListPayload["filter"]>;
|
|
15
|
+
|
|
16
|
+
function allFilters(payload: ListPayload): readonly ListFilter[] {
|
|
17
|
+
return [...(payload.filter === undefined ? [] : [payload.filter]), ...(payload.filters ?? [])];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function emptyPage(payload: ListPayload) {
|
|
21
|
+
return { rows: [], nextCursor: null, ...(payload.totalCount === true && { total: 0 }) };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function onlyFilterOn(payload: ListPayload, field: string): ListFilter | null {
|
|
25
|
+
const matching = allFilters(payload).filter((filter) => filter.field === field);
|
|
26
|
+
const [first] = matching;
|
|
27
|
+
return matching.length === 1 && first !== undefined ? first : null;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type RowsPage = { rows: unknown[] } & Record<string, unknown>;
|
|
31
|
+
|
|
32
|
+
function isRowsPage(value: unknown): value is RowsPage {
|
|
33
|
+
return (
|
|
34
|
+
typeof value === "object" && value !== null && "rows" in value && Array.isArray(value.rows)
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function subjectKey(subject: { subjectType?: unknown; subjectId?: unknown }): string {
|
|
39
|
+
return `${String(subject.subjectType)}\u0000${String(subject.subjectId)}`;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// ponytail: at most this many base pages per answer; a user who may see almost none of the
|
|
43
|
+
// tenant's requests gets short pages and scrolls on. Upgrade to a subject-joined query if that hurts.
|
|
44
|
+
const MAX_BASE_PAGES_PER_ANSWER = 10;
|
|
45
|
+
// authorizeSubject usually queries the database; a page of 200 subjects must not take the whole pool.
|
|
46
|
+
const SUBJECT_CHECKS_IN_PARALLEL = 10;
|
|
47
|
+
|
|
48
|
+
export function scopeRequestList(base: QueryHandlerDef, scope: SubjectScope): QueryHandlerDef {
|
|
49
|
+
return {
|
|
50
|
+
...base,
|
|
51
|
+
handler: async (query, ctx) => {
|
|
52
|
+
const user = query.user;
|
|
53
|
+
if (!scope.isScoped(user)) return base.handler(query, ctx);
|
|
54
|
+
const payload = entityListSchema.parse(query.payload);
|
|
55
|
+
// Group counts would include requests of foreign subjects, and an offset counts base rows,
|
|
56
|
+
// not the rows this user sees; the screen pages by cursor.
|
|
57
|
+
if (payload.aggregate !== undefined || (payload.offset ?? 0) > 0) {
|
|
58
|
+
throw new AccessDeniedError();
|
|
59
|
+
}
|
|
60
|
+
const limit = payload.limit ?? DEFAULT_LIST_LIMIT;
|
|
61
|
+
const verdicts = new Map<string, boolean>();
|
|
62
|
+
const visibleRows: unknown[] = [];
|
|
63
|
+
let page: unknown = await base.handler(query, ctx);
|
|
64
|
+
for (let fetched = 1; ; fetched++) {
|
|
65
|
+
if (!isRowsPage(page)) throw new Error("signature request list did not return a rows page");
|
|
66
|
+
const unknownSubjects = new Map(
|
|
67
|
+
page.rows
|
|
68
|
+
.map((row) => [subjectKey(subjectOf(row)), subjectOf(row)] as const)
|
|
69
|
+
.filter(([key]) => !verdicts.has(key)),
|
|
70
|
+
);
|
|
71
|
+
const pending = [...unknownSubjects];
|
|
72
|
+
for (let start = 0; start < pending.length; start += SUBJECT_CHECKS_IN_PARALLEL) {
|
|
73
|
+
await Promise.all(
|
|
74
|
+
pending.slice(start, start + SUBJECT_CHECKS_IN_PARALLEL).map(async ([key, subject]) => {
|
|
75
|
+
verdicts.set(key, await scope.allowsRequest(ctx, user, subject));
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
visibleRows.push(...page.rows.filter((row) => verdicts.get(subjectKey(subjectOf(row)))));
|
|
80
|
+
const nextCursor = page["nextCursor"];
|
|
81
|
+
if (
|
|
82
|
+
visibleRows.length >= limit ||
|
|
83
|
+
typeof nextCursor !== "string" ||
|
|
84
|
+
fetched >= MAX_BASE_PAGES_PER_ANSWER ||
|
|
85
|
+
verdicts.size >= MAX_LIST_LIMIT
|
|
86
|
+
) {
|
|
87
|
+
// `total` would count requests of foreign subjects; the cursor continues after the last base page.
|
|
88
|
+
const { total: _total, rows: _rows, ...rest } = page;
|
|
89
|
+
return { ...rest, rows: visibleRows };
|
|
90
|
+
}
|
|
91
|
+
page = await base.handler(
|
|
92
|
+
{
|
|
93
|
+
...query,
|
|
94
|
+
payload: { ...payload, cursor: nextCursor, limit: limit - visibleRows.length },
|
|
95
|
+
},
|
|
96
|
+
ctx,
|
|
97
|
+
);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function scopeRequestDetail(base: QueryHandlerDef, scope: SubjectScope): QueryHandlerDef {
|
|
104
|
+
return {
|
|
105
|
+
...base,
|
|
106
|
+
handler: async (query, ctx) => {
|
|
107
|
+
const row = await base.handler(query, ctx);
|
|
108
|
+
if (row === null || !scope.isScoped(query.user)) return row;
|
|
109
|
+
return (await scope.allowsRequest(ctx, query.user, subjectOf(row))) ? row : null;
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function subjectOf(row: unknown): { subjectType?: unknown; subjectId?: unknown } {
|
|
115
|
+
if (typeof row !== "object" || row === null) return {};
|
|
116
|
+
return {
|
|
117
|
+
subjectType: "subjectType" in row ? row.subjectType : undefined,
|
|
118
|
+
subjectId: "subjectId" in row ? row.subjectId : undefined,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function scopeSignerList(base: QueryHandlerDef, scope: SubjectScope): QueryHandlerDef {
|
|
123
|
+
return {
|
|
124
|
+
...base,
|
|
125
|
+
handler: async (query, ctx: HandlerContext) => {
|
|
126
|
+
const user: SessionUser = query.user;
|
|
127
|
+
if (!scope.isScoped(user)) return base.handler(query, ctx);
|
|
128
|
+
const payload = entityListSchema.parse(query.payload);
|
|
129
|
+
const requestFilter = onlyFilterOn(payload, "requestId");
|
|
130
|
+
if (
|
|
131
|
+
requestFilter === null ||
|
|
132
|
+
requestFilter.op !== "eq" ||
|
|
133
|
+
typeof requestFilter.value !== "string"
|
|
134
|
+
) {
|
|
135
|
+
throw new AccessDeniedError();
|
|
136
|
+
}
|
|
137
|
+
const request = await requestExecutor.detail({ id: requestFilter.value }, user, ctx.db);
|
|
138
|
+
if (request === null || !(await scope.allowsRequest(ctx, user, request))) {
|
|
139
|
+
return emptyPage(payload);
|
|
140
|
+
}
|
|
141
|
+
return base.handler(query, ctx);
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { HandlerContext, SessionUser } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import type { SignatureOptions } from "./options.ts";
|
|
3
|
+
|
|
4
|
+
export type SubjectScope = {
|
|
5
|
+
isScoped(user: SessionUser): boolean;
|
|
6
|
+
allows(
|
|
7
|
+
ctx: HandlerContext,
|
|
8
|
+
user: SessionUser,
|
|
9
|
+
subjectType: unknown,
|
|
10
|
+
subjectId: unknown,
|
|
11
|
+
): Promise<boolean>;
|
|
12
|
+
allowsRequest(
|
|
13
|
+
ctx: HandlerContext,
|
|
14
|
+
user: SessionUser,
|
|
15
|
+
request: { readonly subjectType?: unknown; readonly subjectId?: unknown },
|
|
16
|
+
): Promise<boolean>;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function isNonEmptyString(value: unknown): value is string {
|
|
20
|
+
return typeof value === "string" && value !== "";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function createSubjectScope(
|
|
24
|
+
opts: Pick<SignatureOptions, "authorizeSubject" | "unscopedRoles">,
|
|
25
|
+
): SubjectScope {
|
|
26
|
+
const { authorizeSubject } = opts;
|
|
27
|
+
const unscopedRoles = opts.unscopedRoles ?? [];
|
|
28
|
+
const isScoped = (user: SessionUser): boolean =>
|
|
29
|
+
authorizeSubject !== undefined && !user.roles.some((role) => unscopedRoles.includes(role));
|
|
30
|
+
|
|
31
|
+
const allows: SubjectScope["allows"] = async (ctx, user, subjectType, subjectId) => {
|
|
32
|
+
if (authorizeSubject === undefined || !isScoped(user)) return true;
|
|
33
|
+
if (!isNonEmptyString(subjectType) || !isNonEmptyString(subjectId)) return false;
|
|
34
|
+
return authorizeSubject(ctx, user, { subjectType, subjectId });
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
isScoped,
|
|
39
|
+
allows,
|
|
40
|
+
allowsRequest: (ctx, user, request) =>
|
|
41
|
+
allows(ctx, user, request.subjectType, request.subjectId),
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -20,6 +20,10 @@ query and the fields to read, the query does the counting.
|
|
|
20
20
|
`list` with `filter`, `limit: 1` and `totalCount: true`. The total is counted
|
|
21
21
|
over the whole WHERE clause, so no rows are loaded just to be counted.
|
|
22
22
|
- **Labels are translation keys**: declared with `r.translations`.
|
|
23
|
+
- **`progress-list` head from the answer**: `labelParams` fills the `{month}` of the
|
|
24
|
+
label from the query answer and `subtitleField` shows the period muted at the head's right.
|
|
25
|
+
- **List footer without a link**: `footerLink` with only `moreText` (no `label`)
|
|
26
|
+
shows the muted "k more" count under the list.
|
|
23
27
|
- **Record-bound dashboard**: `ticket-record-dashboard` binds to a record with `record`
|
|
24
28
|
and embeds the `ticket-card` projectionDetail as a screen panel; the record id
|
|
25
29
|
becomes its entityId.
|
|
@@ -99,8 +99,33 @@ export const ticketFeature = defineFeature("tickets", (r) => {
|
|
|
99
99
|
access: readerRoles,
|
|
100
100
|
});
|
|
101
101
|
|
|
102
|
+
// Three newest rows plus the total, so the panel can say how many more exist.
|
|
103
|
+
r.queryHandler({
|
|
104
|
+
name: "ticket:recent",
|
|
105
|
+
schema: z.object({}),
|
|
106
|
+
handler: async (query, ctx) => {
|
|
107
|
+
const page = await ticketExecutor.list({ limit: 3, totalCount: true }, query.user, ctx.db);
|
|
108
|
+
return { rows: page.rows, nextCursor: null, total: page.total ?? page.rows.length };
|
|
109
|
+
},
|
|
110
|
+
access: readerRoles,
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
r.queryHandler({
|
|
114
|
+
name: "ticket:quota",
|
|
115
|
+
schema: z.object({}),
|
|
116
|
+
handler: async () => ({
|
|
117
|
+
month: "November",
|
|
118
|
+
period: "01.11. - 30.11.",
|
|
119
|
+
rows: [{ label: "Tickets handled", used: 18, limit: 25, sub: "7 left" }],
|
|
120
|
+
}),
|
|
121
|
+
access: readerRoles,
|
|
122
|
+
});
|
|
123
|
+
|
|
102
124
|
r.translations({
|
|
103
125
|
keys: {
|
|
126
|
+
"tickets.dashboard.recent": { en: "Recent tickets" },
|
|
127
|
+
"tickets.dashboard.recent-more": { en: "{count} more tickets" },
|
|
128
|
+
"tickets.dashboard.quota": { en: "Quota {month}" },
|
|
104
129
|
"screen:ticket-list.title": { en: "Tickets" },
|
|
105
130
|
"screen:ticket-card.title": { en: "Ticket" },
|
|
106
131
|
"screen:ticket-record-dashboard.title": { en: "Ticket overview" },
|
|
@@ -114,6 +139,7 @@ export const ticketFeature = defineFeature("tickets", (r) => {
|
|
|
114
139
|
"tickets.dashboard.open": { en: "Open" },
|
|
115
140
|
"tickets.dashboard.closed": { en: "Closed" },
|
|
116
141
|
"tickets.dashboard.total": { en: "All tickets" },
|
|
142
|
+
"tickets.dashboard.total-narrow": { en: { one: "{count} ticket", other: "{count} tickets" } },
|
|
117
143
|
"tickets.dashboard.open-work": { en: "Open work" },
|
|
118
144
|
"tickets.filter.open-work": { en: "Open work" },
|
|
119
145
|
"screen:ticket-queue.title": { en: "Ticket queue" },
|
|
@@ -149,6 +175,8 @@ export const ticketFeature = defineFeature("tickets", (r) => {
|
|
|
149
175
|
kind: "stat",
|
|
150
176
|
id: "total",
|
|
151
177
|
label: "tickets.dashboard.total",
|
|
178
|
+
// Below sm the label is replaced by this plural key, resolved with { count: <value> }.
|
|
179
|
+
labelNarrow: "tickets.dashboard.total-narrow",
|
|
152
180
|
query: TICKET_STATS_QUERY,
|
|
153
181
|
valueField: "total",
|
|
154
182
|
},
|
|
@@ -162,6 +190,25 @@ export const ticketFeature = defineFeature("tickets", (r) => {
|
|
|
162
190
|
params: { namedFilter: "open-work", limit: 1, totalCount: true },
|
|
163
191
|
navigate: { screen: "ticket-queue", namedFilter: "open-work" },
|
|
164
192
|
},
|
|
193
|
+
// Without `label` the footer is only the muted "k more" count, no link.
|
|
194
|
+
{
|
|
195
|
+
kind: "list",
|
|
196
|
+
id: "recent",
|
|
197
|
+
label: "tickets.dashboard.recent",
|
|
198
|
+
query: "tickets:query:ticket:recent",
|
|
199
|
+
// `badgeIcon: "sparkles"` draws an AI-prepared value as the soft blue AI pill with an icon.
|
|
200
|
+
columns: ["title", { field: "status", display: "badge", badgeIcon: "sparkles" }],
|
|
201
|
+
footerLink: { moreText: "tickets.dashboard.recent-more", screen: "ticket-queue" },
|
|
202
|
+
},
|
|
203
|
+
// The title takes its month from the answer and the period shows muted at the head's right.
|
|
204
|
+
{
|
|
205
|
+
kind: "progress-list",
|
|
206
|
+
id: "quota",
|
|
207
|
+
label: "tickets.dashboard.quota",
|
|
208
|
+
labelParams: { month: "month" },
|
|
209
|
+
subtitleField: "period",
|
|
210
|
+
query: "tickets:query:ticket:quota",
|
|
211
|
+
},
|
|
165
212
|
],
|
|
166
213
|
access: readerRoles,
|
|
167
214
|
});
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
// - r.projection — single-stream read model (inline in the write TX)
|
|
11
11
|
// - r.multiStreamProjection — cross-aggregate async read model
|
|
12
12
|
// - ctx.events.load with { asOf } — point-in-time aggregate state
|
|
13
|
+
// - ctx.events.loadByTypes — events of many aggregates, filtered by type, in one query
|
|
13
14
|
// - ctx.events.archive / ctx.events.restore — Marten ArchiveStream
|
|
14
15
|
// - ctx.dispatch.queryProjection — tenant-scoped read of a projection table
|
|
15
16
|
// - ctx.events.snapshot + ctx.events.loadWithSnapshot — perf path
|
|
@@ -398,6 +399,36 @@ export const invoiceFeature = defineFeature("showcase", (r) => {
|
|
|
398
399
|
},
|
|
399
400
|
});
|
|
400
401
|
|
|
402
|
+
// List page over many invoices: ONE query for just the approved/paid events of the
|
|
403
|
+
// requested aggregates instead of ctx.events.load per invoice.
|
|
404
|
+
r.queryHandler({
|
|
405
|
+
name: "invoice:payment-statuses",
|
|
406
|
+
schema: z.object({ ids: z.array(z.uuid()).max(200) }),
|
|
407
|
+
handler: async (query, ctx) => {
|
|
408
|
+
const events = await ctx.events.loadByTypes({
|
|
409
|
+
aggregateIds: query.payload.ids,
|
|
410
|
+
eventTypes: [approved.name, paid.name],
|
|
411
|
+
});
|
|
412
|
+
const lastEventByInvoice = new Map<string, string>();
|
|
413
|
+
for (const evt of events) {
|
|
414
|
+
lastEventByInvoice.set(evt.aggregateId, evt.type);
|
|
415
|
+
}
|
|
416
|
+
return {
|
|
417
|
+
statuses: [...lastEventByInvoice].map(([id, lastEventType]) => ({
|
|
418
|
+
id,
|
|
419
|
+
status: lastEventType === paid.name ? "paid" : "approved",
|
|
420
|
+
})),
|
|
421
|
+
};
|
|
422
|
+
},
|
|
423
|
+
access: {
|
|
424
|
+
openToAll: {
|
|
425
|
+
reason:
|
|
426
|
+
"demo recipe: any signed-in user may read invoice payment statuses; " +
|
|
427
|
+
"there is no per-user invoice ownership in this sample",
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
});
|
|
431
|
+
|
|
401
432
|
// Snapshot-aware fast path. Uses the latest snapshot if available and
|
|
402
433
|
// only replays delta events past it. Identical state shape to
|
|
403
434
|
// invoice:state — the two are interchangeable modulo the perf profile.
|
|
@@ -27,6 +27,15 @@ the `table` block renders and behaves as before.
|
|
|
27
27
|
offers grouping by priority or none.
|
|
28
28
|
- `table.totals`: a footer row with the estimate sum over the filtered list.
|
|
29
29
|
- `facets.estimateHours: { display: "range" }`: from/to inputs for a number field.
|
|
30
|
+
- `mutedRowField: "parked"`: a parked task is drawn entirely in the muted colour.
|
|
31
|
+
- `toolbarSort: true`: the desktop "Sorted by" select in the filter row (opt-in).
|
|
32
|
+
- Column options: `ellipsis` (one truncated line), `multiline` (line breaks stay),
|
|
33
|
+
`tone: "muted"`, `cardAbove` (phone card line above the title), `hideWhenDocked`,
|
|
34
|
+
`emptyPlaceholder` (`false` keeps the cell blank, a string shows muted text),
|
|
35
|
+
`cardBadge` (phone-card pill), `dateOnlyAfterDays` on a timestamp column,
|
|
36
|
+
`pillField` / `pillToneField` (a second pill beside the cell value).
|
|
37
|
+
- Row action `display: "text"`: muted text without a button, shown for done tasks.
|
|
38
|
+
- `hideCountFooter` is not set here: no screen declaration reaches it (relatedList sets it itself).
|
|
30
39
|
- The same block on a `projectionList`, and `task:workload`, a hand-written list
|
|
31
40
|
query that keeps grouping and totals by accepting `aggregate`
|
|
32
41
|
(`entityListSchema`) and answering it with `answerListAggregate`.
|
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
createEventStoreExecutor,
|
|
5
5
|
} from "@cosmicdrift/kumiko-framework/db";
|
|
6
6
|
import {
|
|
7
|
+
createBooleanField,
|
|
7
8
|
createDateField,
|
|
8
9
|
createEntity,
|
|
9
10
|
createNumberField,
|
|
10
11
|
createSelectField,
|
|
11
12
|
createTextField,
|
|
13
|
+
createTimestampField,
|
|
12
14
|
defineFeature,
|
|
13
15
|
entityListSchema,
|
|
14
16
|
type FeatureDefinition,
|
|
@@ -41,6 +43,14 @@ export const taskEntity = createEntity({
|
|
|
41
43
|
dueDate: createDateField({ sortable: true }),
|
|
42
44
|
assignee: createTextField({ personal: false, reason: "is_business_data", sortable: true }),
|
|
43
45
|
estimateHours: createNumberField({ sortable: true, filterable: true }),
|
|
46
|
+
parked: createBooleanField({ default: false }),
|
|
47
|
+
note: createTextField({ personal: false, reason: "is_business_data" }),
|
|
48
|
+
team: createTextField({ personal: false, reason: "is_business_data" }),
|
|
49
|
+
teamTone: createSelectField({
|
|
50
|
+
options: ["positive", "warn", "negative", "neutral"] as const,
|
|
51
|
+
default: "neutral",
|
|
52
|
+
}),
|
|
53
|
+
lastUpdate: createTimestampField({ sortable: true }),
|
|
44
54
|
},
|
|
45
55
|
});
|
|
46
56
|
|
|
@@ -76,9 +86,29 @@ export function createTaskBoardFeature(
|
|
|
76
86
|
// Starts pinned left; width and minWidth are start values for resizing.
|
|
77
87
|
{ field: "title", pinned: "left", width: 280, minWidth: 160 },
|
|
78
88
|
"status",
|
|
79
|
-
|
|
89
|
+
// The phone card shows the priority as its outlined pill instead of the first select column.
|
|
90
|
+
{ field: "priority", cardBadge: true },
|
|
80
91
|
{ field: "dueDate", hideOnNarrow: true },
|
|
81
|
-
|
|
92
|
+
// The team pill sits beside the assignee name; its tone comes from the row.
|
|
93
|
+
{
|
|
94
|
+
field: "assignee",
|
|
95
|
+
hideOnNarrow: true,
|
|
96
|
+
pillField: "team",
|
|
97
|
+
pillToneField: "teamTone",
|
|
98
|
+
emptyPlaceholder: "Unassigned",
|
|
99
|
+
},
|
|
100
|
+
// One truncated line in the table; a line break starts a new line on the phone card.
|
|
101
|
+
{
|
|
102
|
+
field: "note",
|
|
103
|
+
ellipsis: true,
|
|
104
|
+
multiline: true,
|
|
105
|
+
tone: "muted",
|
|
106
|
+
cardAbove: true,
|
|
107
|
+
hideWhenDocked: true,
|
|
108
|
+
emptyPlaceholder: false,
|
|
109
|
+
},
|
|
110
|
+
// Recent edits show date and time, older ones the date only.
|
|
111
|
+
{ field: "lastUpdate", dateOnlyAfterDays: 7, hideOnNarrow: true },
|
|
82
112
|
// Starts hidden; the user can add it back in the view menu.
|
|
83
113
|
{ field: "estimateHours", hidden: true, hideOnNarrow: true },
|
|
84
114
|
],
|
|
@@ -86,7 +116,22 @@ export function createTaskBoardFeature(
|
|
|
86
116
|
defaultSort: { field: "dueDate", dir: "asc" },
|
|
87
117
|
searchable: true,
|
|
88
118
|
table: taskTable,
|
|
119
|
+
mutedRowField: "parked",
|
|
120
|
+
toolbarSort: true,
|
|
121
|
+
sortOptions: [
|
|
122
|
+
{ field: "dueDate", dir: "asc", label: "Due date" },
|
|
123
|
+
{ field: "priority", dir: "desc", label: "Priority" },
|
|
124
|
+
],
|
|
89
125
|
rowActions: [
|
|
126
|
+
// A closed state as muted text instead of a button.
|
|
127
|
+
{
|
|
128
|
+
kind: "navigate",
|
|
129
|
+
id: "closed",
|
|
130
|
+
label: "Closed",
|
|
131
|
+
screen: "task-edit",
|
|
132
|
+
display: "text",
|
|
133
|
+
visible: { field: "status", eq: "done" },
|
|
134
|
+
},
|
|
90
135
|
{ kind: "navigate", id: "open", label: "Open", screen: "task-edit", rowClick: true },
|
|
91
136
|
{
|
|
92
137
|
kind: "writeHandler",
|
|
@@ -61,7 +61,14 @@ export const integrationsFeature = defineFeature(FEATURE, (r) => {
|
|
|
61
61
|
default: "smtp.platform.example",
|
|
62
62
|
write: access.roles("SystemAdmin", "Admin"),
|
|
63
63
|
read: access.admin,
|
|
64
|
-
|
|
64
|
+
// compact: the generated screen drops origin icons and accent bars; section: groups the key under its own titled section.
|
|
65
|
+
mask: {
|
|
66
|
+
title: "integrations.smtp-host",
|
|
67
|
+
icon: "mail",
|
|
68
|
+
order: 2,
|
|
69
|
+
compact: true,
|
|
70
|
+
section: "integrations.mail",
|
|
71
|
+
},
|
|
65
72
|
}),
|
|
66
73
|
},
|
|
67
74
|
});
|
|
@@ -83,6 +90,7 @@ export const integrationsFeature = defineFeature(FEATURE, (r) => {
|
|
|
83
90
|
"integrations.settings": { de: "Integrationen", en: "Integrations" },
|
|
84
91
|
"integrations.payment-api-key": { de: "Zahlungs-API-Schlüssel", en: "Payment API Key" },
|
|
85
92
|
"integrations.smtp-host": { de: "SMTP-Server", en: "SMTP Host" },
|
|
93
|
+
"integrations.mail": { de: "E-Mail-Versand", en: "Mail delivery" },
|
|
86
94
|
},
|
|
87
95
|
});
|
|
88
96
|
});
|
|
@@ -43,6 +43,13 @@ header, a metrics band, and a tabbed layout instead of one long stacked form.
|
|
|
43
43
|
- round 6 (board gaps): `rowLink.screenField` / `paramsField` (target screen from a query field),
|
|
44
44
|
list panel `icon`, `narrow.moreText`, `narrow.field` as any query output field,
|
|
45
45
|
`footerLink.narrowOnly`, `narrow.titleField` on cards and `rowToneMarker: "dot"`
|
|
46
|
+
- round 7 (board look): `header.narrowTitle` (short phone top-bar title), banner `iconless`,
|
|
47
|
+
`metricsPlacement: { narrow: "before-steps" }`, `mobileSummary` (one line instead of the
|
|
48
|
+
metrics below `sm`), `MetricSpec.visibleWhen`, field option `concealed` (muted value with a lock),
|
|
49
|
+
section `hideOnNarrow` and `after` (a registered component under the items tab card), and a
|
|
50
|
+
second screen `order-facts` with a stacked layout and `pageNavigation: false`
|
|
51
|
+
- not shown: `photosBeside` (needs a stored image file for `photoGrid`) and `recordSections.omitFirstTitle`
|
|
52
|
+
(a renderer prop, not reachable from a screen declaration)
|
|
46
53
|
- boot-validator catching two common author mistakes: a `metrics` entry
|
|
47
54
|
with an empty `label`, and a `tabs` layout with fewer than two
|
|
48
55
|
sections
|
|
@@ -230,6 +230,10 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
230
230
|
"order-desk.metric.outstandingAmount": { en: "Outstanding" },
|
|
231
231
|
"order-desk.metric.itemCount": { en: "Items" },
|
|
232
232
|
"order-desk.metric.placedAt": { en: "Placed" },
|
|
233
|
+
"order-desk.header.narrow-title": { en: "Order" },
|
|
234
|
+
"screen:order-facts.title": { en: "Order facts" },
|
|
235
|
+
"order-desk.facts.contact": { en: "Contact" },
|
|
236
|
+
"order-desk.facts.address": { en: "Address" },
|
|
233
237
|
"order-desk.tab.items": { en: "Items" },
|
|
234
238
|
"order-desk.tab.payments": { en: "Payments" },
|
|
235
239
|
"order-desk.tab.details": { en: "Details" },
|
|
@@ -282,6 +286,7 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
282
286
|
},
|
|
283
287
|
],
|
|
284
288
|
defaultSort: { field: "urgency", dir: "desc" },
|
|
289
|
+
toolbarSort: true,
|
|
285
290
|
sortOptions: [
|
|
286
291
|
{ field: "urgency", dir: "desc", label: "order-desk.sort.urgency" },
|
|
287
292
|
{ field: "customerName", dir: "asc", label: "order-desk.sort.customer" },
|
|
@@ -523,6 +528,7 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
523
528
|
header: {
|
|
524
529
|
title: "customerName",
|
|
525
530
|
shortTitle: "shortTitle",
|
|
531
|
+
narrowTitle: "order-desk.header.narrow-title",
|
|
526
532
|
// Parts are joined by a separator; `format` formats the raw field value.
|
|
527
533
|
narrowSubtitle: "narrowSubtitle",
|
|
528
534
|
subtitle: [
|
|
@@ -535,6 +541,7 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
535
541
|
summary: { field: "summaryLine", narrowField: "summaryShort", toneField: "summaryTone" },
|
|
536
542
|
banner: {
|
|
537
543
|
field: "notice",
|
|
544
|
+
iconless: true,
|
|
538
545
|
actions: [
|
|
539
546
|
{
|
|
540
547
|
kind: "navigate",
|
|
@@ -572,8 +579,9 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
572
579
|
},
|
|
573
580
|
],
|
|
574
581
|
},
|
|
582
|
+
mobileSummary: "mobileLine",
|
|
575
583
|
metricsStyle: "tiles",
|
|
576
|
-
metricsPlacement: { narrow: "
|
|
584
|
+
metricsPlacement: { narrow: "before-steps" },
|
|
577
585
|
metrics: [
|
|
578
586
|
{
|
|
579
587
|
field: "totalAmount",
|
|
@@ -587,6 +595,7 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
587
595
|
subField: "outstandingNote",
|
|
588
596
|
tone: "warn",
|
|
589
597
|
toneField: "outstandingTone",
|
|
598
|
+
visibleWhen: { field: "status", ne: "delivered" },
|
|
590
599
|
navigate: { tab: "payments" },
|
|
591
600
|
},
|
|
592
601
|
{
|
|
@@ -604,6 +613,7 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
604
613
|
kind: "relatedList",
|
|
605
614
|
title: "order-desk.tab.items",
|
|
606
615
|
countField: "itemsCount",
|
|
616
|
+
after: { react: { __component: "OrderItemsFooter" } },
|
|
607
617
|
query: "order-desk:query:order:items",
|
|
608
618
|
columns: [
|
|
609
619
|
{ field: "sku", label: "order-desk.col.sku" },
|
|
@@ -646,11 +656,12 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
646
656
|
id: "details",
|
|
647
657
|
kind: "fields",
|
|
648
658
|
title: "order-desk.tab.details",
|
|
649
|
-
fields: ["shippingAddress", "billingAddress", "salesRep"],
|
|
659
|
+
fields: ["shippingAddress", { field: "billingAddress", concealed: true }, "salesRep"],
|
|
650
660
|
},
|
|
651
661
|
{
|
|
652
662
|
id: "internal-note",
|
|
653
663
|
kind: "extension",
|
|
664
|
+
hideOnNarrow: true,
|
|
654
665
|
title: "order-desk.tab.internalNote",
|
|
655
666
|
component: { react: { __component: "OrderInternalNote" } },
|
|
656
667
|
entityName: "order",
|
|
@@ -684,5 +695,32 @@ export function createOrderDeskFeature(): FeatureDefinition {
|
|
|
684
695
|
inlineActions: ["download-invoice"],
|
|
685
696
|
access: accessRoles,
|
|
686
697
|
});
|
|
698
|
+
|
|
699
|
+
r.screen({
|
|
700
|
+
id: "order-facts",
|
|
701
|
+
type: "projectionDetail",
|
|
702
|
+
query: "order-desk:query:order:detail",
|
|
703
|
+
listScreenId: "orders",
|
|
704
|
+
header: { title: "customerName" },
|
|
705
|
+
// Two short stacked sections need no "On this page" index.
|
|
706
|
+
pageNavigation: false,
|
|
707
|
+
layout: {
|
|
708
|
+
sections: [
|
|
709
|
+
{
|
|
710
|
+
id: "contact",
|
|
711
|
+
kind: "fields",
|
|
712
|
+
title: "order-desk.facts.contact",
|
|
713
|
+
fields: ["salesRep"],
|
|
714
|
+
},
|
|
715
|
+
{
|
|
716
|
+
id: "address",
|
|
717
|
+
kind: "fields",
|
|
718
|
+
title: "order-desk.facts.address",
|
|
719
|
+
fields: ["shippingAddress", "billingAddress"],
|
|
720
|
+
},
|
|
721
|
+
],
|
|
722
|
+
},
|
|
723
|
+
access: accessRoles,
|
|
724
|
+
});
|
|
687
725
|
});
|
|
688
726
|
}
|
|
@@ -494,6 +494,7 @@ export function answerOrderDetail(id: string) {
|
|
|
494
494
|
path: [{ label: "Orders" }, { label: "Aiko Tanaka" }, { label: "SO-10482" }],
|
|
495
495
|
summaryLine: "Waiting for the second payment",
|
|
496
496
|
summaryShort: "Second payment open.",
|
|
497
|
+
mobileLine: "€ 312.00 open of € 1,248.00",
|
|
497
498
|
summaryTone: "warn",
|
|
498
499
|
narrowSubtitle: "SO-10482 · placed 21 Aug",
|
|
499
500
|
notice: { title: "Payment overdue", text: "312 EUR is 14 days overdue", tone: "bad" },
|
|
@@ -6,7 +6,7 @@ Tenant-owned secrets with envelope encryption, DEK cache, and KEK rotation.
|
|
|
6
6
|
|
|
7
7
|
- `r.secret` + `ctx.services.secrets.get` (audited reads)
|
|
8
8
|
- Charge-style handler that never returns the plaintext key
|
|
9
|
-
- A system-scope secret edited on a `configEdit` screen (`secretKeys`) with a handler button row (`actions`)
|
|
9
|
+
- A system-scope secret edited on a `configEdit` screen (`secretKeys`) with a handler button row (`actions`) and `compact: true` (no origin icon, reset link or accent bar)
|
|
10
10
|
|
|
11
11
|
## Source
|
|
12
12
|
|
|
@@ -130,6 +130,8 @@ export function createBillingFeature(): FeatureDefinition {
|
|
|
130
130
|
}),
|
|
131
131
|
},
|
|
132
132
|
layout: { variant: "settings-list", sections: [{ fields: ["signingKey"] }] },
|
|
133
|
+
// One write-only field needs no origin icon, reset link or accent bar.
|
|
134
|
+
compact: true,
|
|
133
135
|
// A button row calls a handler with {} on the stored values; it is disabled while the
|
|
134
136
|
// form has unsaved changes.
|
|
135
137
|
actions: [
|
|
@@ -12,6 +12,10 @@ shared chrome (footer, submit button) can be compared side by side.
|
|
|
12
12
|
- `note-detail`, a `projectionDetail` screen whose only section is
|
|
13
13
|
`kind: "writeForm"` with the identical field set, dispatching its own
|
|
14
14
|
`note-desk:write:note:comment` handler on submit
|
|
15
|
+
- `note-triage`, an `actionForm`: `infoBand` draws the `assist` banner; the layout field
|
|
16
|
+
options `badge` (`{ label, tone }`) and `hintField` (a value field as muted hint) and a
|
|
17
|
+
`suffix` behind the number field. `FormProps.topBanner` is not shown: no screen
|
|
18
|
+
declaration reaches it
|
|
15
19
|
- an e2e layout-parity spec (`e2e/writeform-parity.spec.ts`) proving both
|
|
16
20
|
submit buttons render the same width, sit right-aligned in their form's
|
|
17
21
|
footer, and never stretch full-width — the regression this recipe guards
|
|
@@ -52,11 +52,21 @@ const commentPayloadSchema = z.object({
|
|
|
52
52
|
priority: z.number().optional(),
|
|
53
53
|
});
|
|
54
54
|
|
|
55
|
+
const approvePayloadSchema = z.object({
|
|
56
|
+
noteId: z.string(),
|
|
57
|
+
title: z.string().optional(),
|
|
58
|
+
body: z.string().optional(),
|
|
59
|
+
});
|
|
60
|
+
|
|
55
61
|
export const noteDeskFeature = defineFeature("note-desk", (r) => {
|
|
56
62
|
r.translations({
|
|
57
63
|
keys: {
|
|
58
64
|
"screen:note-edit.title": { en: "Edit note" },
|
|
59
65
|
"screen:note-detail.title": { en: "Note" },
|
|
66
|
+
"screen:note-triage.title": { en: "Triage note" },
|
|
67
|
+
"note-desk:triage.info-band": { en: "Check the category, then send the note on." },
|
|
68
|
+
"note-desk:triage.badge-review": { en: "Needs review" },
|
|
69
|
+
"note-desk:triage.priority-suffix": { en: "pts" },
|
|
60
70
|
"note-desk:entity:note:field:title": { en: "Title" },
|
|
61
71
|
"note-desk:entity:note:field:body": { en: "Body" },
|
|
62
72
|
"note-desk:entity:note:field:category": { en: "Category" },
|
|
@@ -120,4 +130,91 @@ export const noteDeskFeature = defineFeature("note-desk", (r) => {
|
|
|
120
130
|
},
|
|
121
131
|
access: open.access,
|
|
122
132
|
});
|
|
133
|
+
|
|
134
|
+
// An actionForm reaches the "assist" banner through `infoBand`; the layout field options
|
|
135
|
+
// `badge`, `hintField` and `suffix` work on any form layout.
|
|
136
|
+
r.screen({
|
|
137
|
+
id: "note-triage",
|
|
138
|
+
type: "actionForm",
|
|
139
|
+
handler: "note-desk:write:note:comment",
|
|
140
|
+
dormant: true,
|
|
141
|
+
infoBand: "note-desk:triage.info-band",
|
|
142
|
+
fields: {
|
|
143
|
+
title: NOTE_FIELDS.title,
|
|
144
|
+
body: NOTE_FIELDS.body,
|
|
145
|
+
category: NOTE_FIELDS.category,
|
|
146
|
+
priority: NOTE_FIELDS.priority,
|
|
147
|
+
},
|
|
148
|
+
layout: {
|
|
149
|
+
sections: [
|
|
150
|
+
{
|
|
151
|
+
columns: 1,
|
|
152
|
+
fields: [
|
|
153
|
+
{ field: "title", badge: { label: "note-desk:triage.badge-review", tone: "warn" } },
|
|
154
|
+
{ field: "category" },
|
|
155
|
+
{ field: "body", hintField: "category" },
|
|
156
|
+
{ field: "priority", suffix: "note-desk:triage.priority-suffix" },
|
|
157
|
+
],
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
},
|
|
161
|
+
access: open.access,
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
r.writeHandler({
|
|
165
|
+
name: "note:approve",
|
|
166
|
+
schema: approvePayloadSchema,
|
|
167
|
+
handler: async () => ({ isSuccess: true as const, data: null }),
|
|
168
|
+
...open,
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
// The footer action "approve" submits the form: one write with its own payload (noteId)
|
|
172
|
+
// plus the form values, after form validation. The tab strip is phone-free; the "Review"
|
|
173
|
+
// section stands above the "History" section there.
|
|
174
|
+
r.screen({
|
|
175
|
+
id: "note-approval",
|
|
176
|
+
type: "projectionDetail",
|
|
177
|
+
query: "note-desk:query:note:summary",
|
|
178
|
+
layout: {
|
|
179
|
+
mode: "tabs",
|
|
180
|
+
narrowTabs: false,
|
|
181
|
+
sections: [
|
|
182
|
+
{
|
|
183
|
+
id: "review",
|
|
184
|
+
tabLabel: "Review",
|
|
185
|
+
kind: "writeForm",
|
|
186
|
+
title: "Decision",
|
|
187
|
+
description: "Confirm the note and leave a reason.",
|
|
188
|
+
descriptionNarrow: "Leave a reason.",
|
|
189
|
+
columns: 1,
|
|
190
|
+
fieldDefs: {
|
|
191
|
+
title: NOTE_FIELDS.title,
|
|
192
|
+
body: NOTE_FIELDS.body,
|
|
193
|
+
},
|
|
194
|
+
fields: ["title", { field: "body", hideOnNarrow: true }],
|
|
195
|
+
handler: "note-desk:write:note:approve",
|
|
196
|
+
submitWith: "approve",
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: "history",
|
|
200
|
+
tabLabel: "History",
|
|
201
|
+
title: "History",
|
|
202
|
+
titleOnNarrow: false,
|
|
203
|
+
fields: ["category", "priority"],
|
|
204
|
+
},
|
|
205
|
+
],
|
|
206
|
+
},
|
|
207
|
+
actions: [
|
|
208
|
+
{
|
|
209
|
+
id: "approve",
|
|
210
|
+
label: "Approve",
|
|
211
|
+
handler: "note-desk:write:note:approve",
|
|
212
|
+
payload: { map: { noteId: "id" } },
|
|
213
|
+
// Tabs layout: only the tab that mounts the form may show the action.
|
|
214
|
+
showOnTabs: ["review"],
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
footerActions: ["approve"],
|
|
218
|
+
access: open.access,
|
|
219
|
+
});
|
|
123
220
|
});
|