@cosmicdrift/kumiko-bundled-features 0.422.0 → 0.424.1
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/auth-email-password/handlers/login.write.d.ts +10 -1
- package/dist/auth-email-password/handlers/login.write.js +29 -0
- package/dist/auth-email-password/index.d.ts +1 -0
- package/dist/auth-email-password/index.js +1 -0
- package/dist/channel-push/push-channel.d.ts +2 -6
- package/dist/document-draft/entity.d.ts +320 -0
- package/dist/document-draft/entity.js +98 -0
- package/dist/document-draft/feature.d.ts +3 -0
- package/dist/document-draft/feature.js +42 -0
- package/dist/document-draft/handlers/blocks.query.d.ts +28 -0
- package/dist/document-draft/handlers/blocks.query.js +48 -0
- package/dist/document-draft/handlers/by-subject.query.d.ts +16 -0
- package/dist/document-draft/handlers/by-subject.query.js +42 -0
- package/dist/document-draft/handlers/create.write.d.ts +17 -0
- package/dist/document-draft/handlers/create.write.js +83 -0
- package/dist/document-draft/handlers/discard.write.d.ts +8 -0
- package/dist/document-draft/handlers/discard.write.js +27 -0
- package/dist/document-draft/handlers/finalize.write.d.ts +21 -0
- package/dist/document-draft/handlers/finalize.write.js +73 -0
- package/dist/document-draft/handlers/patch.write.d.ts +1420 -0
- package/dist/document-draft/handlers/patch.write.js +65 -0
- package/dist/document-draft/handlers/revise.write.d.ts +12 -0
- package/dist/document-draft/handlers/revise.write.js +39 -0
- package/dist/document-draft/handlers/save.write.d.ts +12 -0
- package/dist/document-draft/handlers/save.write.js +40 -0
- package/dist/document-draft/i18n.d.ts +6 -0
- package/dist/document-draft/i18n.js +20 -0
- package/dist/document-draft/index.d.ts +5 -0
- package/dist/document-draft/index.js +3 -0
- package/dist/document-draft/lib.d.ts +13 -0
- package/dist/document-draft/lib.js +42 -0
- package/dist/document-draft/options.d.ts +35 -0
- package/dist/document-draft/options.js +1 -0
- package/dist/document-draft/payloads.d.ts +1440 -0
- package/dist/document-draft/payloads.js +35 -0
- package/dist/document-draft/screens/editor-screen.d.ts +3 -0
- package/dist/document-draft/screens/editor-screen.js +13 -0
- package/dist/document-draft/user-data.d.ts +13 -0
- package/dist/document-draft/user-data.js +43 -0
- package/dist/document-draft/web/client-plugin.d.ts +7 -0
- package/dist/document-draft/web/client-plugin.js +13 -0
- package/dist/document-draft/web/constants.d.ts +41 -0
- package/dist/document-draft/web/constants.js +42 -0
- package/dist/document-draft/web/editor-screen.d.ts +2 -0
- package/dist/document-draft/web/editor-screen.js +181 -0
- package/dist/document-draft/web/i18n.d.ts +99 -0
- package/dist/document-draft/web/i18n.js +52 -0
- package/dist/document-draft/web/index.d.ts +3 -0
- package/dist/document-draft/web/index.js +3 -0
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.js +1 -0
- package/dist/shared/subject-scope.d.ts +21 -0
- package/dist/signature/feature.js +1 -1
- package/dist/signature/handlers/cancel.write.d.ts +1 -1
- package/dist/signature/handlers/issue-link.write.d.ts +1 -1
- package/dist/signature/handlers/request.write.d.ts +1 -1
- package/dist/signature/handlers/revoke-link.write.d.ts +1 -1
- package/dist/signature/handlers/sign-in-person.write.d.ts +1 -1
- package/dist/signature/options.d.ts +2 -1
- package/dist/signature/subject-queries.d.ts +1 -1
- package/dist/template-resolver/api.d.ts +3 -1
- package/dist/template-resolver/boot-rules.d.ts +5 -0
- package/dist/template-resolver/boot-rules.js +5 -0
- package/dist/template-resolver/feature.d.ts +2 -0
- package/dist/template-resolver/feature.js +15 -1
- package/dist/template-resolver/handlers/create-variant.write.d.ts +17 -0
- package/dist/template-resolver/handlers/create-variant.write.js +112 -0
- package/dist/template-resolver/handlers/document-base.d.ts +1 -0
- package/dist/template-resolver/handlers/document-base.js +2 -0
- package/dist/template-resolver/handlers/overview.query.d.ts +6 -0
- package/dist/template-resolver/handlers/overview.query.js +29 -3
- package/dist/template-resolver/handlers/patch-draft.write.js +9 -1
- package/dist/template-resolver/handlers/template-write.d.ts +8 -2
- package/dist/template-resolver/handlers/template-write.js +87 -12
- package/dist/template-resolver/handlers/toggle-status.write.js +26 -5
- package/dist/template-resolver/handlers/upsert-tenant.write.js +1 -0
- package/dist/template-resolver/handlers/variants.query.d.ts +11 -0
- package/dist/template-resolver/handlers/variants.query.js +62 -0
- package/dist/template-resolver/i18n.js +1 -0
- package/dist/template-resolver/index.d.ts +5 -1
- package/dist/template-resolver/index.js +5 -1
- package/dist/template-resolver/seeding.d.ts +2 -0
- package/dist/template-resolver/seeding.js +12 -1
- package/dist/template-resolver/template-delivery-policy.d.ts +13 -4
- package/dist/template-resolver/template-delivery-policy.js +38 -2
- package/dist/template-resolver/template-edit-policy.d.ts +3 -0
- package/dist/template-resolver/template-edit-policy.js +2 -2
- package/dist/template-resolver/template-meta.d.ts +1 -0
- package/dist/template-resolver/template-meta.js +1 -0
- package/dist/template-resolver/template-variants.d.ts +11 -0
- package/dist/template-resolver/template-variants.js +43 -0
- package/dist/template-resolver/web/document-tiptap-content.js +7 -2
- package/dist/template-resolver/web/document-tiptap-toolbar.js +8 -4
- package/dist/template-resolver/web/i18n.js +22 -0
- package/dist/template-resolver/web/index.d.ts +1 -0
- package/dist/template-resolver/web/index.js +1 -0
- package/dist/template-resolver/web/qualified-names.d.ts +5 -0
- package/dist/template-resolver/web/qualified-names.js +5 -0
- package/dist/template-resolver/web/system-placeholders.d.ts +4 -0
- package/dist/template-resolver/web/system-placeholders.js +13 -0
- package/dist/tenant/handlers/update-member-roles.write.js +1 -1
- package/dist/tenant/i18n.js +0 -1
- package/dist/tenant-inactivity/constants.d.ts +1 -1
- package/dist/tenant-inactivity/constants.js +1 -1
- package/dist/tenant-lifecycle/constants.d.ts +1 -1
- package/dist/tenant-lifecycle/constants.js +1 -1
- package/package.json +27 -11
- package/src/channel-push/changes.json +8 -1
- package/src/document-draft/changes.json +8 -0
- package/src/helpdesk/changes.json +6 -0
- package/src/signature/changes.json +6 -0
- package/src/template-resolver/changes.json +30 -0
- package/src/tenant/changes.json +7 -0
- package/src/tenant-inactivity/changes.json +7 -0
- package/src/tenant-lifecycle/changes.json +7 -0
- package/dist/signature/subject-scope.d.ts +0 -11
- /package/dist/{signature → shared}/subject-scope.js +0 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
import { documentOpsSchema, localeSchema, templateSlugSchema } from "../template-resolver/index.js";
|
|
3
|
+
import { DOCUMENT_DRAFT_DEFAULT_LOCALE, DOCUMENT_DRAFT_MAX_CONTENT_LENGTH, } from "./web/constants.js";
|
|
4
|
+
const draftIdSchema = z.uuid();
|
|
5
|
+
const baseVersionSchema = z.number().int().nonnegative();
|
|
6
|
+
const subjectIdSchema = z.string().min(1).max(100);
|
|
7
|
+
export const DraftIdSchema = z.object({ id: draftIdSchema });
|
|
8
|
+
// `base` is the draft's version as the caller read it; a stale base fails with version_conflict.
|
|
9
|
+
export const DraftBaseSchema = z.object({ id: draftIdSchema, base: baseVersionSchema });
|
|
10
|
+
export const PatchDraftSchema = z.object({
|
|
11
|
+
id: draftIdSchema,
|
|
12
|
+
base: baseVersionSchema,
|
|
13
|
+
ops: documentOpsSchema,
|
|
14
|
+
});
|
|
15
|
+
export const SaveDraftSchema = z.object({
|
|
16
|
+
id: draftIdSchema,
|
|
17
|
+
base: baseVersionSchema,
|
|
18
|
+
content: z.string().max(DOCUMENT_DRAFT_MAX_CONTENT_LENGTH),
|
|
19
|
+
});
|
|
20
|
+
export const BySubjectSchema = z.object({
|
|
21
|
+
subjectType: z.string().min(1).max(100),
|
|
22
|
+
subjectId: subjectIdSchema,
|
|
23
|
+
});
|
|
24
|
+
export function createDraftSchema(subjectTypes) {
|
|
25
|
+
return z.object({
|
|
26
|
+
subjectType: z.enum(subjectTypes),
|
|
27
|
+
subjectId: subjectIdSchema,
|
|
28
|
+
templateSlug: templateSlugSchema,
|
|
29
|
+
/** Slug of a variant of `templateSlug` (`<templateSlug>:<name>`), used instead of the base. */
|
|
30
|
+
variant: templateSlugSchema.optional(),
|
|
31
|
+
locale: localeSchema.default(DOCUMENT_DRAFT_DEFAULT_LOCALE),
|
|
32
|
+
/** Values of the placeholders, frozen with the draft; they stay personal data of the draft. */
|
|
33
|
+
variables: z.record(z.string(), z.unknown()),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DOCUMENT_DRAFT_EDITOR_SCREEN_ID } from "../web/constants.js";
|
|
2
|
+
// Opened with the draft id as entityId from the screen of the object the draft belongs to; the
|
|
3
|
+
// client plugin mounts the component under this id. Navigation is the app's business, so it is dormant.
|
|
4
|
+
export function createDocumentDraftEditorScreen(access) {
|
|
5
|
+
return {
|
|
6
|
+
id: DOCUMENT_DRAFT_EDITOR_SCREEN_ID,
|
|
7
|
+
type: "custom",
|
|
8
|
+
renderer: { react: { __component: DOCUMENT_DRAFT_EDITOR_SCREEN_ID } },
|
|
9
|
+
description: "Edit one document draft: the text of the template copy with its placeholders and the deviations from the template beside it, then save, finalize to a PDF or discard.",
|
|
10
|
+
access,
|
|
11
|
+
dormant: true,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { TenantDb } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
+
import type { SessionUser } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
|
+
type DraftErasureContext = {
|
|
4
|
+
readonly db: TenantDb;
|
|
5
|
+
readonly user: SessionUser;
|
|
6
|
+
};
|
|
7
|
+
export declare function forgetDocumentDraftsOfSubject(ctx: DraftErasureContext, subject: {
|
|
8
|
+
readonly subjectType: string;
|
|
9
|
+
readonly subjectId: string;
|
|
10
|
+
}): Promise<{
|
|
11
|
+
readonly erased: number;
|
|
12
|
+
}>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { configuredPiiSubjectKms } from "@cosmicdrift/kumiko-framework/crypto";
|
|
2
|
+
import { InternalError } from "@cosmicdrift/kumiko-framework/errors";
|
|
3
|
+
import { documentDraftExecutor } from "./entity.js";
|
|
4
|
+
import { DOCUMENT_DRAFT_ENTITY } from "./web/constants.js";
|
|
5
|
+
const ERASE_REASON = "document-draft:subject-forget";
|
|
6
|
+
// Equals the executor's MAX_LIST_LIMIT.
|
|
7
|
+
const LIST_PAGE_SIZE = 200;
|
|
8
|
+
async function draftIdsOfSubject(ctx, subject) {
|
|
9
|
+
const ids = [];
|
|
10
|
+
for (;;) {
|
|
11
|
+
const page = await documentDraftExecutor.list({
|
|
12
|
+
filters: [
|
|
13
|
+
{ field: "subjectType", op: "eq", value: subject.subjectType },
|
|
14
|
+
{ field: "subjectId", op: "eq", value: subject.subjectId },
|
|
15
|
+
],
|
|
16
|
+
limit: LIST_PAGE_SIZE,
|
|
17
|
+
offset: ids.length,
|
|
18
|
+
}, ctx.user, ctx.db);
|
|
19
|
+
ids.push(...page.rows.map((row) => String(row.id)));
|
|
20
|
+
if (page.rows.length < LIST_PAGE_SIZE)
|
|
21
|
+
return ids;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// A draft's body, variables and last change belong to the draft's own record key, so the user
|
|
25
|
+
// forget run never shreds them: the app calls this when the object the drafts belong to is erased.
|
|
26
|
+
// The row is purged and its key erased, so the old events stay unreadable too. Without a mounted
|
|
27
|
+
// KMS the key erase is a no-op and the old events keep plaintext (record-owned fields are plaintext
|
|
28
|
+
// framework-wide, see signature user-data), so apps that need Art. 17 coverage mount one.
|
|
29
|
+
export async function forgetDocumentDraftsOfSubject(ctx, subject) {
|
|
30
|
+
const kms = configuredPiiSubjectKms();
|
|
31
|
+
const ids = await draftIdsOfSubject(ctx, subject);
|
|
32
|
+
for (const id of ids) {
|
|
33
|
+
const forgotten = await documentDraftExecutor.forget({ id }, ctx.user, ctx.db);
|
|
34
|
+
if (!forgotten.isSuccess) {
|
|
35
|
+
throw new InternalError({
|
|
36
|
+
message: `[document-draft] draft ${id} could not be forgotten: ${forgotten.error.message}`,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
// skip: no KMS adapter mounted, nothing is encrypted per record
|
|
40
|
+
await kms?.eraseKey({ kind: "record", entity: DOCUMENT_DRAFT_ENTITY, id }, { requestId: ERASE_REASON, userId: ctx.user.id, eraseReason: ERASE_REASON });
|
|
41
|
+
}
|
|
42
|
+
return { erased: ids.length };
|
|
43
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type TranslationsByLocale } from "@cosmicdrift/kumiko-renderer";
|
|
2
|
+
import type { ClientFeatureDefinition } from "@cosmicdrift/kumiko-renderer/web";
|
|
3
|
+
export type DocumentDraftClientOptions = {
|
|
4
|
+
/** Key-wise overrides of the default bundles (de/en). */
|
|
5
|
+
readonly translations?: TranslationsByLocale;
|
|
6
|
+
};
|
|
7
|
+
export declare function documentDraftClient(options?: DocumentDraftClientOptions): ClientFeatureDefinition;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { mergeTranslations } from "@cosmicdrift/kumiko-renderer";
|
|
2
|
+
import { WebPreviewRenderer } from "../../template-resolver/web/index.js";
|
|
3
|
+
import { DOCUMENT_DRAFT_EDITOR_SCREEN_ID, DOCUMENT_DRAFT_FEATURE } from "./constants.js";
|
|
4
|
+
import { DocumentDraftEditorScreen } from "./editor-screen.js";
|
|
5
|
+
import { defaultTranslations } from "./i18n.js";
|
|
6
|
+
export function documentDraftClient(options) {
|
|
7
|
+
return {
|
|
8
|
+
name: DOCUMENT_DRAFT_FEATURE,
|
|
9
|
+
translations: mergeTranslations(defaultTranslations, options?.translations ?? {}),
|
|
10
|
+
contentPreviews: { web: WebPreviewRenderer },
|
|
11
|
+
components: { [DOCUMENT_DRAFT_EDITOR_SCREEN_ID]: DocumentDraftEditorScreen },
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export declare const DOCUMENT_DRAFT_FEATURE: "document-draft";
|
|
2
|
+
export declare const DOCUMENT_DRAFT_ENTITY: "documentDraft";
|
|
3
|
+
export declare const DOCUMENT_DRAFT_STATUS: {
|
|
4
|
+
readonly Open: "open";
|
|
5
|
+
readonly Finalized: "finalized";
|
|
6
|
+
readonly Discarded: "discarded";
|
|
7
|
+
};
|
|
8
|
+
export type DocumentDraftStatus = (typeof DOCUMENT_DRAFT_STATUS)[keyof typeof DOCUMENT_DRAFT_STATUS];
|
|
9
|
+
export declare const DOCUMENT_DRAFT_STATUS_TONE: {
|
|
10
|
+
readonly open: "warn";
|
|
11
|
+
readonly finalized: "ok";
|
|
12
|
+
readonly discarded: "neutral";
|
|
13
|
+
};
|
|
14
|
+
export declare const DOCUMENT_DRAFT_LAST_CHANGE_SOURCE: {
|
|
15
|
+
readonly Create: "create";
|
|
16
|
+
readonly Ops: "ops";
|
|
17
|
+
readonly Editor: "editor";
|
|
18
|
+
};
|
|
19
|
+
export declare const DocumentDraftHandlers: {
|
|
20
|
+
readonly create: "document-draft:write:create";
|
|
21
|
+
readonly patch: "document-draft:write:patch";
|
|
22
|
+
readonly save: "document-draft:write:save";
|
|
23
|
+
readonly finalize: "document-draft:write:finalize";
|
|
24
|
+
readonly revise: "document-draft:write:revise";
|
|
25
|
+
readonly discard: "document-draft:write:discard";
|
|
26
|
+
};
|
|
27
|
+
export declare const DocumentDraftQueries: {
|
|
28
|
+
readonly blocks: "document-draft:query:blocks";
|
|
29
|
+
readonly bySubject: "document-draft:query:by-subject";
|
|
30
|
+
};
|
|
31
|
+
export declare const DOCUMENT_DRAFT_ERROR: {
|
|
32
|
+
readonly NotOpen: "document_draft_not_open";
|
|
33
|
+
readonly NotFinalized: "document_draft_not_finalized";
|
|
34
|
+
readonly TemplateNotFound: "template_not_found";
|
|
35
|
+
readonly OpNotAllowed: "op_not_allowed";
|
|
36
|
+
};
|
|
37
|
+
export declare const DOCUMENT_DRAFT_DEFAULT_LOCALE = "de";
|
|
38
|
+
export declare const DOCUMENT_DRAFT_MAX_CONTENT_LENGTH = 200000;
|
|
39
|
+
export declare const DOCUMENT_DRAFT_EDITOR_SCREEN_ID: "document-draft-editor";
|
|
40
|
+
/** Qualified name for targets in other features, e.g. an app actionForm `redirect`. */
|
|
41
|
+
export declare const DOCUMENT_DRAFT_EDITOR_SCREEN_QN: "document-draft:screen:document-draft-editor";
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Pure string constants, safe for browser code.
|
|
2
|
+
export const DOCUMENT_DRAFT_FEATURE = "document-draft";
|
|
3
|
+
export const DOCUMENT_DRAFT_ENTITY = "documentDraft";
|
|
4
|
+
export const DOCUMENT_DRAFT_STATUS = {
|
|
5
|
+
Open: "open",
|
|
6
|
+
Finalized: "finalized",
|
|
7
|
+
Discarded: "discarded",
|
|
8
|
+
};
|
|
9
|
+
export const DOCUMENT_DRAFT_STATUS_TONE = {
|
|
10
|
+
[DOCUMENT_DRAFT_STATUS.Open]: "warn",
|
|
11
|
+
[DOCUMENT_DRAFT_STATUS.Finalized]: "ok",
|
|
12
|
+
[DOCUMENT_DRAFT_STATUS.Discarded]: "neutral",
|
|
13
|
+
};
|
|
14
|
+
export const DOCUMENT_DRAFT_LAST_CHANGE_SOURCE = {
|
|
15
|
+
Create: "create",
|
|
16
|
+
Ops: "ops",
|
|
17
|
+
Editor: "editor",
|
|
18
|
+
};
|
|
19
|
+
export const DocumentDraftHandlers = {
|
|
20
|
+
create: `${DOCUMENT_DRAFT_FEATURE}:write:create`,
|
|
21
|
+
patch: `${DOCUMENT_DRAFT_FEATURE}:write:patch`,
|
|
22
|
+
save: `${DOCUMENT_DRAFT_FEATURE}:write:save`,
|
|
23
|
+
finalize: `${DOCUMENT_DRAFT_FEATURE}:write:finalize`,
|
|
24
|
+
revise: `${DOCUMENT_DRAFT_FEATURE}:write:revise`,
|
|
25
|
+
discard: `${DOCUMENT_DRAFT_FEATURE}:write:discard`,
|
|
26
|
+
};
|
|
27
|
+
export const DocumentDraftQueries = {
|
|
28
|
+
blocks: `${DOCUMENT_DRAFT_FEATURE}:query:blocks`,
|
|
29
|
+
bySubject: `${DOCUMENT_DRAFT_FEATURE}:query:by-subject`,
|
|
30
|
+
};
|
|
31
|
+
export const DOCUMENT_DRAFT_ERROR = {
|
|
32
|
+
NotOpen: "document_draft_not_open",
|
|
33
|
+
NotFinalized: "document_draft_not_finalized",
|
|
34
|
+
TemplateNotFound: "template_not_found",
|
|
35
|
+
OpNotAllowed: "op_not_allowed",
|
|
36
|
+
};
|
|
37
|
+
export const DOCUMENT_DRAFT_DEFAULT_LOCALE = "de";
|
|
38
|
+
export const DOCUMENT_DRAFT_MAX_CONTENT_LENGTH = 200_000;
|
|
39
|
+
// Short screen id as in the URL and in `r.screen`; the qualified name is `document-draft:screen:<id>`.
|
|
40
|
+
export const DOCUMENT_DRAFT_EDITOR_SCREEN_ID = "document-draft-editor";
|
|
41
|
+
/** Qualified name for targets in other features, e.g. an app actionForm `redirect`. */
|
|
42
|
+
export const DOCUMENT_DRAFT_EDITOR_SCREEN_QN = `${DOCUMENT_DRAFT_FEATURE}:screen:${DOCUMENT_DRAFT_EDITOR_SCREEN_ID}`;
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { dispatcherErrorTextWithFieldIssues, PreviewPane, statusToneForOptionTone, useMutation, useNav, usePrimitives, useQuery, useTenantCurrency, useTranslation, useUnsavedInputSource, } from "@cosmicdrift/kumiko-renderer";
|
|
3
|
+
import { DOCUMENT_FALLBACK_CURRENCY, formatDocumentDate, formatDocumentMoney, formatDocumentPercent, } from "@cosmicdrift/kumiko-renderer/headless";
|
|
4
|
+
import { EditorWorkbench, LoadingState, RailField, RailRow, RailSection, StatusBadge, } from "@cosmicdrift/kumiko-renderer/web";
|
|
5
|
+
import { isPlainObject, propertyOf } from "@cosmicdrift/kumiko-types/type-guards";
|
|
6
|
+
import { useRef, useState } from "react";
|
|
7
|
+
import { COMPANY_PLACEHOLDERS, DocumentContentEditor, PDF_DOCUMENT_BLOCKS, systemPlaceholderLabel, translatedOr, } from "../../template-resolver/web/index.js";
|
|
8
|
+
import { DOCUMENT_DRAFT_STATUS, DOCUMENT_DRAFT_STATUS_TONE, DocumentDraftHandlers, DocumentDraftQueries, } from "./constants.js";
|
|
9
|
+
const TEST_ID = "document-draft-workbench";
|
|
10
|
+
const BODY_EDITOR_ID = "document-draft-body";
|
|
11
|
+
const MAX_DEVIATION_TEXT_LENGTH = 120;
|
|
12
|
+
function isShownValue(value) {
|
|
13
|
+
return typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
14
|
+
}
|
|
15
|
+
function hasMoneyVariable(record) {
|
|
16
|
+
return Object.values(record.variableSchema).some((definition) => propertyOf(definition, "type") === "money");
|
|
17
|
+
}
|
|
18
|
+
// Same formatting the printed PDF applies, so the chip shows what the document will say.
|
|
19
|
+
// A money amount waits for the tenant currency instead of showing a raw number.
|
|
20
|
+
function formatVariable(value, type, locale, currency) {
|
|
21
|
+
if (type === "money" && currency !== undefined)
|
|
22
|
+
return formatDocumentMoney(value, currency, locale);
|
|
23
|
+
if (type === "date")
|
|
24
|
+
return formatDocumentDate(value, locale);
|
|
25
|
+
if (type === "percent")
|
|
26
|
+
return formatDocumentPercent(value, locale);
|
|
27
|
+
return String(value);
|
|
28
|
+
}
|
|
29
|
+
// Filled in only when the PDF is printed, so the chip names them like the template editor does.
|
|
30
|
+
const SYSTEM_VARIABLES = ["tenantName", ...COMPANY_PLACEHOLDERS];
|
|
31
|
+
function addDeclaredLabel(t, labels, key, label) {
|
|
32
|
+
if (typeof label === "string" && label !== "")
|
|
33
|
+
labels[key] = translatedOr(t, label, label);
|
|
34
|
+
}
|
|
35
|
+
// A chip with a value shows it formatted; without one it shows what the variable is called, never
|
|
36
|
+
// the raw key.
|
|
37
|
+
function variableLabelsOf(t, record, currency) {
|
|
38
|
+
const labels = {};
|
|
39
|
+
for (const name of SYSTEM_VARIABLES) {
|
|
40
|
+
labels[name] = systemPlaceholderLabel(t, name);
|
|
41
|
+
}
|
|
42
|
+
for (const [name, definition] of Object.entries(record.variableSchema)) {
|
|
43
|
+
const value = record.variables[name];
|
|
44
|
+
if (isShownValue(value) && String(value) !== "") {
|
|
45
|
+
labels[name] = formatVariable(value, propertyOf(definition, "type"), record.locale, currency);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
addDeclaredLabel(t, labels, name, propertyOf(definition, "label"));
|
|
49
|
+
// A chip inside a repeat row is addressed as `list.field`, like the template editor does.
|
|
50
|
+
const item = propertyOf(definition, "item");
|
|
51
|
+
if (isPlainObject(item)) {
|
|
52
|
+
for (const [itemName, itemDefinition] of Object.entries(item)) {
|
|
53
|
+
addDeclaredLabel(t, labels, `${name}.${itemName}`, propertyOf(itemDefinition, "label"));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return labels;
|
|
58
|
+
}
|
|
59
|
+
// A title may be an i18n key or plain text; t() returns the key itself without a translation.
|
|
60
|
+
function templateLabelOf(t, record) {
|
|
61
|
+
if (hasNoTitle(record))
|
|
62
|
+
return record.templateSlug;
|
|
63
|
+
return t(record.templateTitle ?? record.templateSlug);
|
|
64
|
+
}
|
|
65
|
+
function statusBadgeToneOf(status) {
|
|
66
|
+
return statusToneForOptionTone(DOCUMENT_DRAFT_STATUS_TONE[status]) ?? "muted";
|
|
67
|
+
}
|
|
68
|
+
function hasNoTitle(record) {
|
|
69
|
+
return record.templateTitle === null || record.templateTitle === "";
|
|
70
|
+
}
|
|
71
|
+
function plainTextOf(html) {
|
|
72
|
+
const text = html
|
|
73
|
+
.replace(/<[^>]*>/g, " ")
|
|
74
|
+
.replace(/\s+/g, " ")
|
|
75
|
+
.trim();
|
|
76
|
+
return text.length > MAX_DEVIATION_TEXT_LENGTH
|
|
77
|
+
? `${text.slice(0, MAX_DEVIATION_TEXT_LENGTH)}…`
|
|
78
|
+
: text;
|
|
79
|
+
}
|
|
80
|
+
// Deviations carry no id and two blocks can be identical, so the key counts repeats.
|
|
81
|
+
function keyedDeviations(deviations) {
|
|
82
|
+
const seen = new Map();
|
|
83
|
+
return deviations.map((deviation) => {
|
|
84
|
+
const base = `${deviation.change}:${deviation.content}`;
|
|
85
|
+
const count = (seen.get(base) ?? 0) + 1;
|
|
86
|
+
seen.set(base, count);
|
|
87
|
+
return { key: `${base}#${count}`, deviation };
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
function DraftRail({ record, actions, testId, }) {
|
|
91
|
+
const t = useTranslation();
|
|
92
|
+
const changed = record.deviations.filter((deviation) => deviation.change !== "same");
|
|
93
|
+
return (_jsxs(_Fragment, { children: [_jsxs(RailSection, { title: t("document-draft:editor.railTemplate"), testId: `${testId}-template`, children: [_jsx(RailRow, { label: t("document-draft:editor.template"), trailing: templateLabelOf(t, record) }), record.templateVariant !== null && hasNoTitle(record) && (_jsx(RailRow, { label: t("document-draft:editor.variant"), trailing: record.templateVariant })), _jsx(RailRow, { label: t("document-draft:editor.revision"), trailing: String(record.revision) }), record.fileName !== null && (_jsx(RailRow, { label: t("document-draft:editor.file"), trailing: record.fileName, testId: `${testId}-file` }))] }), _jsx(RailSection, { title: t("document-draft:editor.railDeviations"), testId: `${testId}-deviations`, children: changed.length === 0 ? (_jsx(RailRow, { label: t("document-draft:editor.noDeviations") })) : (keyedDeviations(changed).map(({ key, deviation }) => (_jsx(RailRow, { label: t(`document-draft:editor.deviation.${deviation.change}`), trailing: plainTextOf(deviation.content), testId: `${testId}-deviation` }, key)))) }), actions] }));
|
|
94
|
+
}
|
|
95
|
+
function DraftEditor({ record, onChanged, }) {
|
|
96
|
+
const t = useTranslation();
|
|
97
|
+
const { Button } = usePrimitives();
|
|
98
|
+
const nav = useNav();
|
|
99
|
+
const [html, setHtml] = useState(record.body);
|
|
100
|
+
const [resetCount, setResetCount] = useState(0);
|
|
101
|
+
const [actionError, setActionError] = useState(null);
|
|
102
|
+
const savedRef = useRef(false);
|
|
103
|
+
const tenantCurrency = useTenantCurrency(hasMoneyVariable(record), DOCUMENT_FALLBACK_CURRENCY);
|
|
104
|
+
const currency = tenantCurrency.status === "ready" ? tenantCurrency.currency : undefined;
|
|
105
|
+
const save = useMutation(DocumentDraftHandlers.save);
|
|
106
|
+
const finalize = useMutation(DocumentDraftHandlers.finalize);
|
|
107
|
+
const revise = useMutation(DocumentDraftHandlers.revise);
|
|
108
|
+
const discard = useMutation(DocumentDraftHandlers.discard);
|
|
109
|
+
const open = record.status === DOCUMENT_DRAFT_STATUS.Open;
|
|
110
|
+
const dirty = open && html !== record.body;
|
|
111
|
+
const busy = save.pending || finalize.pending || revise.pending || discard.pending;
|
|
112
|
+
useUnsavedInputSource(() => dirty && !savedRef.current);
|
|
113
|
+
const failureText = (error) => error.code === "version_conflict"
|
|
114
|
+
? t("document-draft:editor.versionConflict")
|
|
115
|
+
: dispatcherErrorTextWithFieldIssues(error, t);
|
|
116
|
+
const leaveToSubject = () => {
|
|
117
|
+
if (record.subjectScreen === null) {
|
|
118
|
+
onChanged();
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
nav.navigate({ screenId: record.subjectScreen, entityId: record.subjectId });
|
|
122
|
+
};
|
|
123
|
+
const run = async (mutation, payload, onDone) => {
|
|
124
|
+
setActionError(null);
|
|
125
|
+
const result = await mutation.mutate({ id: record.id, ...payload });
|
|
126
|
+
if (!result.isSuccess) {
|
|
127
|
+
setActionError(failureText(result.error));
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
onDone();
|
|
131
|
+
};
|
|
132
|
+
const onSave = () => {
|
|
133
|
+
void run(save, { base: record.version, content: html }, () => {
|
|
134
|
+
savedRef.current = true;
|
|
135
|
+
onChanged();
|
|
136
|
+
});
|
|
137
|
+
};
|
|
138
|
+
const onFinalize = () => {
|
|
139
|
+
void run(finalize, { base: record.version }, leaveToSubject);
|
|
140
|
+
};
|
|
141
|
+
const onDiscardDraft = () => {
|
|
142
|
+
void run(discard, { base: record.version }, leaveToSubject);
|
|
143
|
+
};
|
|
144
|
+
const onRevise = () => {
|
|
145
|
+
void run(revise, { base: record.version }, onChanged);
|
|
146
|
+
};
|
|
147
|
+
const onRevert = () => {
|
|
148
|
+
setHtml(record.body);
|
|
149
|
+
setActionError(null);
|
|
150
|
+
setResetCount((count) => count + 1);
|
|
151
|
+
};
|
|
152
|
+
const actions = (_jsx(RailSection, { title: t("document-draft:editor.railActions"), testId: `${TEST_ID}-actions`, children: _jsx(RailField, { children: open ? (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "primary", width: "full", disabled: dirty || busy, loading: finalize.pending, onClick: onFinalize, testId: `${TEST_ID}-finalize`, children: t("document-draft:editor.finalize") }), dirty && _jsx(RailRow, { label: t("document-draft:editor.finalizeNeedsSave") }), _jsx(Button, { variant: "danger-ghost", width: "full", disabled: busy, loading: discard.pending, onClick: onDiscardDraft, testId: `${TEST_ID}-discard`, children: t("document-draft:editor.discardDraft") })] })) : (_jsx(Button, { variant: "primary", width: "full", disabled: busy || record.status !== DOCUMENT_DRAFT_STATUS.Finalized, loading: revise.pending, onClick: onRevise, testId: `${TEST_ID}-revise`, children: t("document-draft:editor.revise") })) }) }));
|
|
153
|
+
const rail = _jsx(DraftRail, { record: record, actions: actions, testId: `${TEST_ID}-rail` });
|
|
154
|
+
return (_jsx(EditorWorkbench, { testId: TEST_ID, title: hasNoTitle(record) && record.templateVariant !== null
|
|
155
|
+
? `${record.templateSlug} / ${record.templateVariant}`
|
|
156
|
+
: templateLabelOf(t, record), status: _jsx(StatusBadge, { tone: statusBadgeToneOf(record.status), testId: `${TEST_ID}-status`, children: t(`document-draft:editor.status.${record.status}`) }), info: {
|
|
157
|
+
edit: open ? t("document-draft:editor.infoEdit") : t("document-draft:editor.infoFinalized"),
|
|
158
|
+
preview: t("document-draft:editor.infoPreview"),
|
|
159
|
+
}, edit: _jsx("div", { className: "min-h-0 min-w-0 flex-1 overflow-auto px-4 py-4 md:px-6", children: _jsx(DocumentContentEditor, { id: BODY_EDITOR_ID, value: html, onChange: setHtml, variables: Object.keys(record.variableSchema), variableLabels: variableLabelsOf(t, record, currency), systemVariables: SYSTEM_VARIABLES, blocks: PDF_DOCUMENT_BLOCKS, readOnly: !open }, resetCount) }), preview: _jsx(PreviewPane, { target: "web", content: html, editFormat: "document", variables: record.variables, subject: { kind: "body" } }), rail: { edit: rail, preview: rail }, save: {
|
|
160
|
+
busy: save.pending,
|
|
161
|
+
canSave: dirty && !busy,
|
|
162
|
+
dirty,
|
|
163
|
+
onSave,
|
|
164
|
+
onDiscard: onRevert,
|
|
165
|
+
saveError: actionError,
|
|
166
|
+
saveLabel: t("document-draft:editor.save"),
|
|
167
|
+
} }));
|
|
168
|
+
}
|
|
169
|
+
export function DocumentDraftEditorScreen() {
|
|
170
|
+
const t = useTranslation();
|
|
171
|
+
const { Banner } = usePrimitives();
|
|
172
|
+
const nav = useNav();
|
|
173
|
+
const entityId = nav.route?.entityId;
|
|
174
|
+
const detail = useQuery(DocumentDraftQueries.blocks, { id: entityId ?? "" }, { enabled: entityId !== undefined });
|
|
175
|
+
if (entityId === undefined || detail.error !== null) {
|
|
176
|
+
return _jsx(Banner, { variant: "error", children: t("document-draft:editor.loadFailed") });
|
|
177
|
+
}
|
|
178
|
+
if (detail.data === null)
|
|
179
|
+
return _jsx(LoadingState, {});
|
|
180
|
+
return (_jsx(DraftEditor, { record: detail.data, onChanged: () => void detail.refetch() }, `${detail.data.id}:${detail.data.version}`));
|
|
181
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export declare const DOCUMENT_DRAFT_EDITOR_I18N: {
|
|
2
|
+
readonly "document-draft:editor.railActions": {
|
|
3
|
+
readonly en: "Actions";
|
|
4
|
+
readonly de: "Aktionen";
|
|
5
|
+
};
|
|
6
|
+
readonly "screen:document-draft-editor.title": {
|
|
7
|
+
readonly en: "Document draft";
|
|
8
|
+
readonly de: "Dokumententwurf";
|
|
9
|
+
};
|
|
10
|
+
readonly "document-draft:editor.infoEdit": {
|
|
11
|
+
readonly en: "Edit the text. The placeholders keep the values the draft was created with.";
|
|
12
|
+
readonly de: "Text bearbeiten. Die Platzhalter behalten die Werte, mit denen der Entwurf angelegt wurde.";
|
|
13
|
+
};
|
|
14
|
+
readonly "document-draft:editor.infoPreview": {
|
|
15
|
+
readonly en: "Preview of the draft text.";
|
|
16
|
+
readonly de: "Vorschau des Entwurfstexts.";
|
|
17
|
+
};
|
|
18
|
+
readonly "document-draft:editor.infoFinalized": {
|
|
19
|
+
readonly en: "This draft is finalized. Reopen it to change the text.";
|
|
20
|
+
readonly de: "Dieser Entwurf ist abgeschlossen. Zum Ändern erneut bearbeiten.";
|
|
21
|
+
};
|
|
22
|
+
readonly "document-draft:editor.loadFailed": {
|
|
23
|
+
readonly en: "The draft could not be loaded.";
|
|
24
|
+
readonly de: "Der Entwurf konnte nicht geladen werden.";
|
|
25
|
+
};
|
|
26
|
+
readonly "document-draft:editor.railTemplate": {
|
|
27
|
+
readonly en: "Template";
|
|
28
|
+
readonly de: "Vorlage";
|
|
29
|
+
};
|
|
30
|
+
readonly "document-draft:editor.template": {
|
|
31
|
+
readonly en: "Template";
|
|
32
|
+
readonly de: "Vorlage";
|
|
33
|
+
};
|
|
34
|
+
readonly "document-draft:editor.variant": {
|
|
35
|
+
readonly en: "Variant";
|
|
36
|
+
readonly de: "Variante";
|
|
37
|
+
};
|
|
38
|
+
readonly "document-draft:editor.revision": {
|
|
39
|
+
readonly en: "Revision";
|
|
40
|
+
readonly de: "Revision";
|
|
41
|
+
};
|
|
42
|
+
readonly "document-draft:editor.file": {
|
|
43
|
+
readonly en: "File";
|
|
44
|
+
readonly de: "Datei";
|
|
45
|
+
};
|
|
46
|
+
readonly "document-draft:editor.railDeviations": {
|
|
47
|
+
readonly en: "Deviations from the template";
|
|
48
|
+
readonly de: "Abweichungen von der Vorlage";
|
|
49
|
+
};
|
|
50
|
+
readonly "document-draft:editor.noDeviations": {
|
|
51
|
+
readonly en: "The draft matches the template.";
|
|
52
|
+
readonly de: "Der Entwurf entspricht der Vorlage.";
|
|
53
|
+
};
|
|
54
|
+
readonly "document-draft:editor.deviation.added": {
|
|
55
|
+
readonly en: "Added";
|
|
56
|
+
readonly de: "Hinzugefügt";
|
|
57
|
+
};
|
|
58
|
+
readonly "document-draft:editor.deviation.removed": {
|
|
59
|
+
readonly en: "Removed";
|
|
60
|
+
readonly de: "Entfernt";
|
|
61
|
+
};
|
|
62
|
+
readonly "document-draft:editor.status.open": {
|
|
63
|
+
readonly en: "Open";
|
|
64
|
+
readonly de: "Offen";
|
|
65
|
+
};
|
|
66
|
+
readonly "document-draft:editor.status.finalized": {
|
|
67
|
+
readonly en: "Finalized";
|
|
68
|
+
readonly de: "Abgeschlossen";
|
|
69
|
+
};
|
|
70
|
+
readonly "document-draft:editor.status.discarded": {
|
|
71
|
+
readonly en: "Discarded";
|
|
72
|
+
readonly de: "Verworfen";
|
|
73
|
+
};
|
|
74
|
+
readonly "document-draft:editor.save": {
|
|
75
|
+
readonly en: "Save";
|
|
76
|
+
readonly de: "Speichern";
|
|
77
|
+
};
|
|
78
|
+
readonly "document-draft:editor.finalize": {
|
|
79
|
+
readonly en: "Finalize";
|
|
80
|
+
readonly de: "Abschließen";
|
|
81
|
+
};
|
|
82
|
+
readonly "document-draft:editor.finalizeNeedsSave": {
|
|
83
|
+
readonly en: "Save your changes before finalizing.";
|
|
84
|
+
readonly de: "Änderungen vor dem Abschließen speichern.";
|
|
85
|
+
};
|
|
86
|
+
readonly "document-draft:editor.discardDraft": {
|
|
87
|
+
readonly en: "Discard draft";
|
|
88
|
+
readonly de: "Entwurf verwerfen";
|
|
89
|
+
};
|
|
90
|
+
readonly "document-draft:editor.revise": {
|
|
91
|
+
readonly en: "Edit again";
|
|
92
|
+
readonly de: "Erneut bearbeiten";
|
|
93
|
+
};
|
|
94
|
+
readonly "document-draft:editor.versionConflict": {
|
|
95
|
+
readonly en: "The draft was changed elsewhere in the meantime. Reload it to continue with the current text.";
|
|
96
|
+
readonly de: "Der Entwurf wurde zwischenzeitlich anderswo geändert. Neu laden, um mit dem aktuellen Text weiterzuarbeiten.";
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
export declare const defaultTranslations: Readonly<Record<string, Readonly<Record<string, import("@cosmicdrift/kumiko-types/config").TranslationValue>>>>;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { translationsByLocaleFromKeys } from "@cosmicdrift/kumiko-renderer";
|
|
2
|
+
export const DOCUMENT_DRAFT_EDITOR_I18N = {
|
|
3
|
+
"document-draft:editor.railActions": { en: "Actions", de: "Aktionen" },
|
|
4
|
+
"screen:document-draft-editor.title": { en: "Document draft", de: "Dokumententwurf" },
|
|
5
|
+
"document-draft:editor.infoEdit": {
|
|
6
|
+
en: "Edit the text. The placeholders keep the values the draft was created with.",
|
|
7
|
+
de: "Text bearbeiten. Die Platzhalter behalten die Werte, mit denen der Entwurf angelegt wurde.",
|
|
8
|
+
},
|
|
9
|
+
"document-draft:editor.infoPreview": {
|
|
10
|
+
en: "Preview of the draft text.",
|
|
11
|
+
de: "Vorschau des Entwurfstexts.",
|
|
12
|
+
},
|
|
13
|
+
"document-draft:editor.infoFinalized": {
|
|
14
|
+
en: "This draft is finalized. Reopen it to change the text.",
|
|
15
|
+
de: "Dieser Entwurf ist abgeschlossen. Zum Ändern erneut bearbeiten.",
|
|
16
|
+
},
|
|
17
|
+
"document-draft:editor.loadFailed": {
|
|
18
|
+
en: "The draft could not be loaded.",
|
|
19
|
+
de: "Der Entwurf konnte nicht geladen werden.",
|
|
20
|
+
},
|
|
21
|
+
"document-draft:editor.railTemplate": { en: "Template", de: "Vorlage" },
|
|
22
|
+
"document-draft:editor.template": { en: "Template", de: "Vorlage" },
|
|
23
|
+
"document-draft:editor.variant": { en: "Variant", de: "Variante" },
|
|
24
|
+
"document-draft:editor.revision": { en: "Revision", de: "Revision" },
|
|
25
|
+
"document-draft:editor.file": { en: "File", de: "Datei" },
|
|
26
|
+
"document-draft:editor.railDeviations": {
|
|
27
|
+
en: "Deviations from the template",
|
|
28
|
+
de: "Abweichungen von der Vorlage",
|
|
29
|
+
},
|
|
30
|
+
"document-draft:editor.noDeviations": {
|
|
31
|
+
en: "The draft matches the template.",
|
|
32
|
+
de: "Der Entwurf entspricht der Vorlage.",
|
|
33
|
+
},
|
|
34
|
+
"document-draft:editor.deviation.added": { en: "Added", de: "Hinzugefügt" },
|
|
35
|
+
"document-draft:editor.deviation.removed": { en: "Removed", de: "Entfernt" },
|
|
36
|
+
"document-draft:editor.status.open": { en: "Open", de: "Offen" },
|
|
37
|
+
"document-draft:editor.status.finalized": { en: "Finalized", de: "Abgeschlossen" },
|
|
38
|
+
"document-draft:editor.status.discarded": { en: "Discarded", de: "Verworfen" },
|
|
39
|
+
"document-draft:editor.save": { en: "Save", de: "Speichern" },
|
|
40
|
+
"document-draft:editor.finalize": { en: "Finalize", de: "Abschließen" },
|
|
41
|
+
"document-draft:editor.finalizeNeedsSave": {
|
|
42
|
+
en: "Save your changes before finalizing.",
|
|
43
|
+
de: "Änderungen vor dem Abschließen speichern.",
|
|
44
|
+
},
|
|
45
|
+
"document-draft:editor.discardDraft": { en: "Discard draft", de: "Entwurf verwerfen" },
|
|
46
|
+
"document-draft:editor.revise": { en: "Edit again", de: "Erneut bearbeiten" },
|
|
47
|
+
"document-draft:editor.versionConflict": {
|
|
48
|
+
en: "The draft was changed elsewhere in the meantime. Reload it to continue with the current text.",
|
|
49
|
+
de: "Der Entwurf wurde zwischenzeitlich anderswo geändert. Neu laden, um mit dem aktuellen Text weiterzuarbeiten.",
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
export const defaultTranslations = translationsByLocaleFromKeys(DOCUMENT_DRAFT_EDITOR_I18N);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { type DocumentDraftClientOptions, documentDraftClient } from "./client-plugin.tsx";
|
|
2
|
+
export { DOCUMENT_DRAFT_EDITOR_SCREEN_ID, DOCUMENT_DRAFT_EDITOR_SCREEN_QN, DOCUMENT_DRAFT_ENTITY, DOCUMENT_DRAFT_ERROR, DOCUMENT_DRAFT_FEATURE, DOCUMENT_DRAFT_LAST_CHANGE_SOURCE, DOCUMENT_DRAFT_STATUS, DocumentDraftHandlers, DocumentDraftQueries, type DocumentDraftStatus, } from "./constants.ts";
|
|
3
|
+
export { defaultTranslations } from "./i18n.ts";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { documentDraftClient } from "./client-plugin.js";
|
|
2
|
+
export { DOCUMENT_DRAFT_EDITOR_SCREEN_ID, DOCUMENT_DRAFT_EDITOR_SCREEN_QN, DOCUMENT_DRAFT_ENTITY, DOCUMENT_DRAFT_ERROR, DOCUMENT_DRAFT_FEATURE, DOCUMENT_DRAFT_LAST_CHANGE_SOURCE, DOCUMENT_DRAFT_STATUS, DocumentDraftHandlers, DocumentDraftQueries, } from "./constants.js";
|
|
3
|
+
export { defaultTranslations } from "./i18n.js";
|
package/dist/shared/index.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export { EXT_SIGNUP_HANDOVER, findSignupHandoverProvider, isSignupHandoverProvid
|
|
|
45
45
|
export { createSingleUseTokenStore, hashSingleUseToken } from "./single-use-token-store.ts";
|
|
46
46
|
export { backfillAggregateStreamTenants, type StreamBackfillCandidate, type StreamBackfillFailure, type StreamBackfillOptions, type StreamBackfillResult, type StreamTenantTarget, } from "./stream-tenant-backfill.ts";
|
|
47
47
|
export { createSearchBucketCleanup, type DerivedStateMode, rebuildAndReindex, type StreamBackfillStepFailure, stepFailures, } from "./stream-tenant-derived-state.ts";
|
|
48
|
+
export { createSubjectScope, type SubjectScope, type SubjectScopeContext, type SubjectScopeOptions, } from "./subject-scope.ts";
|
|
48
49
|
export type { SystemQueryFn } from "./system-query.ts";
|
|
49
50
|
export { createTenantDbCache } from "./tenant-db-cache.ts";
|
|
50
51
|
export { EXT_TENANT_DESTRUCTION_HOLD, findTenantDestructionHoldProvider, type TenantDestructionHoldProvider, } from "./tenant-destruction-hold.ts";
|
package/dist/shared/index.js
CHANGED
|
@@ -45,6 +45,7 @@ export { EXT_SIGNUP_HANDOVER, findSignupHandoverProvider, isSignupHandoverProvid
|
|
|
45
45
|
export { createSingleUseTokenStore, hashSingleUseToken } from "./single-use-token-store.js";
|
|
46
46
|
export { backfillAggregateStreamTenants, } from "./stream-tenant-backfill.js";
|
|
47
47
|
export { createSearchBucketCleanup, rebuildAndReindex, stepFailures, } from "./stream-tenant-derived-state.js";
|
|
48
|
+
export { createSubjectScope, } from "./subject-scope.js";
|
|
48
49
|
export { createTenantDbCache } from "./tenant-db-cache.js";
|
|
49
50
|
export { EXT_TENANT_DESTRUCTION_HOLD, findTenantDestructionHoldProvider, } from "./tenant-destruction-hold.js";
|
|
50
51
|
export { parseTenantScopedSubject, peekTenantScopedSubject, tenantScopedSubject, } from "./tenant-scoped-subject.js";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HandlerContext, SessionUser } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
/** The part of the handler context that exists in `beforeTransaction` too, so scope checks can run before printing. */
|
|
3
|
+
export type SubjectScopeContext = Pick<HandlerContext, "db" | "registry" | "services">;
|
|
4
|
+
export type SubjectScopeOptions = {
|
|
5
|
+
/** Runs for every signed-in handler and query on a subject, except for `unscopedRoles`. `false` answers like "does not exist". */
|
|
6
|
+
readonly authorizeSubject?: (ctx: SubjectScopeContext, user: SessionUser, subject: {
|
|
7
|
+
readonly subjectType: string;
|
|
8
|
+
readonly subjectId: string;
|
|
9
|
+
}) => Promise<boolean>;
|
|
10
|
+
/** Roles that skip `authorizeSubject`, e.g. admins. */
|
|
11
|
+
readonly unscopedRoles?: readonly string[];
|
|
12
|
+
};
|
|
13
|
+
export type SubjectScope = {
|
|
14
|
+
isScoped(user: SessionUser): boolean;
|
|
15
|
+
allows(ctx: SubjectScopeContext, user: SessionUser, subjectType: unknown, subjectId: unknown): Promise<boolean>;
|
|
16
|
+
allowsRequest(ctx: SubjectScopeContext, user: SessionUser, request: {
|
|
17
|
+
readonly subjectType?: unknown;
|
|
18
|
+
readonly subjectId?: unknown;
|
|
19
|
+
}): Promise<boolean>;
|
|
20
|
+
};
|
|
21
|
+
export declare function createSubjectScope(opts: SubjectScopeOptions): SubjectScope;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineEntityDetailHandler, defineEntityListHandler, defineFeature, EXT_USER_DATA, i18nKey, } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { createSubjectScope } from "../shared/index.js";
|
|
2
3
|
import { createSignatureRequestEntity, createSignatureSignerEntity } from "./entity.js";
|
|
3
4
|
import { createAnonymousLinkHandlers } from "./handlers/anonymous.write.js";
|
|
4
5
|
import { createCancelHandler } from "./handlers/cancel.write.js";
|
|
@@ -14,7 +15,6 @@ import { LINK_RATE_LIMIT } from "./options.js";
|
|
|
14
15
|
import { SignatureCompletedEventSchema, SignatureDeclinedEventSchema, SignatureExpiredEventSchema, SignatureFailedEventSchema, } from "./payloads.js";
|
|
15
16
|
import { createSignatureDetailScreen, createSignatureListScreen } from "./screens.js";
|
|
16
17
|
import { scopeRequestDetail, scopeRequestList, scopeSignerList } from "./subject-queries.js";
|
|
17
|
-
import { createSubjectScope } from "./subject-scope.js";
|
|
18
18
|
import { sweepSignatureRequests } from "./sweep.js";
|
|
19
19
|
import { signatureDeleteHook, signatureExportHook } from "./user-data.js";
|
|
20
20
|
import { SIGNATURE_FEATURE, SIGNATURE_REQUEST_ENTITY, SIGNATURE_SIGNER_ENTITY, } from "./web/constants.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type AccessRule } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
-
import type { SubjectScope } from "
|
|
2
|
+
import type { SubjectScope } from "../../shared/index.ts";
|
|
3
3
|
export declare function createCancelHandler(access: AccessRule, scope: SubjectScope): import("@cosmicdrift/kumiko-types/define-handler").WriteHandlerDefinition<"cancel", import("zod").ZodObject<{
|
|
4
4
|
requestId: import("zod").ZodUUID;
|
|
5
5
|
}, import("zod/v4/core").$strip>, {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type AccessRule } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import type { SubjectScope } from "../../shared/index.ts";
|
|
2
3
|
import type { SignatureOptions } from "../options.ts";
|
|
3
|
-
import type { SubjectScope } from "../subject-scope.ts";
|
|
4
4
|
export type IssueLinkData = {
|
|
5
5
|
readonly signerId: string;
|
|
6
6
|
readonly linkSentAt: string;
|