@cosmicdrift/kumiko-samples 0.417.0 → 0.419.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 +6 -1
- package/packages/bundled-features/src/agent-tools/api-docs/schema-fields.ts +14 -0
- package/packages/bundled-features/src/agent-tools/changes.json +6 -0
- package/packages/bundled-features/src/auth-email-password/index.ts +1 -1
- package/packages/bundled-features/src/auth-email-password/signup-activation.ts +2 -5
- package/packages/bundled-features/src/auth-email-password/signup-token-store.ts +0 -6
- package/packages/bundled-features/src/cap-counter/changes.json +6 -0
- package/packages/bundled-features/src/cap-counter/stock-cap-guard.ts +46 -13
- package/packages/bundled-features/src/channel-whatsapp/changes.json +1 -1
- package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
- package/packages/bundled-features/src/document-ingest-foundation/feature.ts +13 -1
- package/packages/bundled-features/src/document-ingest-foundation/report-ingest-progress.ts +23 -6
- package/packages/bundled-features/src/signature/README.md +4 -4
- package/packages/bundled-features/src/signature/changes.json +18 -0
- package/packages/bundled-features/src/signature/entity.ts +3 -1
- package/packages/bundled-features/src/signature/feature.ts +16 -3
- package/packages/bundled-features/src/signature/handlers/lifecycle.write.ts +33 -1
- package/packages/bundled-features/src/signature/i18n.ts +1 -0
- package/packages/bundled-features/src/signature/list-cursor-seal.ts +59 -0
- package/packages/bundled-features/src/signature/options.ts +2 -2
- package/packages/bundled-features/src/signature/payloads.ts +14 -2
- package/packages/bundled-features/src/signature/png.ts +25 -4
- package/packages/bundled-features/src/signature/subject-queries.ts +47 -7
- package/packages/bundled-features/src/signature/sweep.ts +32 -8
- package/packages/bundled-features/src/signature/web/constants.ts +12 -0
- package/packages/bundled-features/src/subscription-paddle/changes.json +1 -1
- package/packages/bundled-features/src/subscription-stripe/changes.json +6 -0
- package/packages/bundled-features/src/subscription-stripe/plugin-methods.ts +2 -0
- package/packages/bundled-features/src/subscription-stripe/verify-webhook.ts +21 -16
- package/packages/bundled-features/src/template-resolver/changes.json +38 -0
- package/packages/bundled-features/src/template-resolver/compile-document-body.ts +3 -8
- package/packages/bundled-features/src/template-resolver/compile-document-styles.ts +102 -0
- package/packages/bundled-features/src/template-resolver/document-frames.ts +25 -0
- package/packages/bundled-features/src/template-resolver/document-op-blocks.ts +568 -0
- package/packages/bundled-features/src/template-resolver/document-ops.ts +136 -126
- package/packages/bundled-features/src/template-resolver/document-print-only.ts +41 -0
- package/packages/bundled-features/src/template-resolver/document-sanitizer.ts +41 -19
- package/packages/bundled-features/src/template-resolver/feature.ts +15 -0
- package/packages/bundled-features/src/template-resolver/handlers/apply-layout.write.ts +137 -0
- package/packages/bundled-features/src/template-resolver/handlers/create-layout.write.ts +87 -0
- package/packages/bundled-features/src/template-resolver/handlers/document-base.ts +2 -2
- package/packages/bundled-features/src/template-resolver/handlers/document-blocks.query.ts +13 -8
- package/packages/bundled-features/src/template-resolver/handlers/document-region.ts +47 -0
- package/packages/bundled-features/src/template-resolver/handlers/failure-reason.ts +13 -0
- package/packages/bundled-features/src/template-resolver/handlers/import-bundle-system.write.ts +3 -0
- package/packages/bundled-features/src/template-resolver/handlers/layout-source.query.ts +17 -5
- package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +16 -4
- package/packages/bundled-features/src/template-resolver/handlers/patch-draft.write.ts +19 -6
- package/packages/bundled-features/src/template-resolver/handlers/publish-templates.write.ts +69 -0
- package/packages/bundled-features/src/template-resolver/handlers/set.write.ts +7 -0
- package/packages/bundled-features/src/template-resolver/handlers/template-write.ts +15 -3
- package/packages/bundled-features/src/template-resolver/handlers/tenant-settings.ts +122 -0
- package/packages/bundled-features/src/template-resolver/handlers/toggle-status.write.ts +25 -10
- package/packages/bundled-features/src/template-resolver/handlers/upsert-system.write.ts +7 -3
- package/packages/bundled-features/src/template-resolver/handlers/usage.query.ts +131 -18
- package/packages/bundled-features/src/template-resolver/handlers/validate.query.ts +10 -0
- package/packages/bundled-features/src/template-resolver/i18n.ts +3 -0
- package/packages/bundled-features/src/template-resolver/index.ts +29 -0
- package/packages/bundled-features/src/template-resolver/layout-regions.ts +54 -16
- package/packages/bundled-features/src/template-resolver/print-document.ts +3 -1
- package/packages/bundled-features/src/template-resolver/seeding.ts +4 -0
- package/packages/bundled-features/src/template-resolver/template-delivery-policy.ts +11 -1
- package/packages/bundled-features/src/template-resolver/template-edit-policy.ts +37 -1
- package/packages/bundled-features/src/template-resolver/template-meta.ts +25 -6
- package/packages/bundled-features/src/template-resolver/template-preview.ts +6 -7
- package/packages/bundled-features/src/template-resolver/template-validation.ts +10 -3
- package/packages/bundled-features/src/template-resolver/web/constants.ts +29 -0
- package/packages/bundled-features/src/template-resolver/web/document-blocks.ts +5 -0
- package/packages/bundled-features/src/template-resolver/web/document-editor-extensions.ts +34 -2
- package/packages/bundled-features/src/template-resolver/web/document-editor-fonts.ts +13 -0
- package/packages/bundled-features/src/template-resolver/web/document-fonts.ts +21 -0
- package/packages/bundled-features/src/template-resolver/web/document-frame-control.ts +428 -0
- package/packages/bundled-features/src/template-resolver/web/document-frame-node-view.tsx +207 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-decorations.ts +196 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-defaults.ts +59 -0
- package/packages/bundled-features/src/template-resolver/web/document-print-style.ts +246 -0
- package/packages/bundled-features/src/template-resolver/web/document-repeat-strip.ts +104 -0
- package/packages/bundled-features/src/template-resolver/web/document-schema.ts +29 -9
- package/packages/bundled-features/src/template-resolver/web/document-style-css.ts +107 -0
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +24 -2
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-content.tsx +66 -7
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +13 -1
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +24 -4
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +149 -4
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +290 -10
- package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar.tsx +90 -8
- package/packages/bundled-features/src/template-resolver/web/document-toolbar-blocks.ts +20 -0
- package/packages/bundled-features/src/template-resolver/web/fontsource-css.d.ts +2 -0
- package/packages/bundled-features/src/template-resolver/web/i18n.ts +28 -0
- package/packages/bundled-features/src/template-resolver/web/index.ts +34 -0
- package/packages/bundled-features/src/template-resolver/web/pdf-constants.ts +6 -0
- package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +7 -0
- package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +74 -5
- package/packages/bundled-features/src/tenant/company-config.ts +48 -0
- package/packages/bundled-features/src/tenant/feature.ts +11 -0
- package/packages/bundled-features/src/tenant/i18n.ts +14 -0
- package/packages/bundled-features/src/tenant-inactivity/handlers/keep-account.write.ts +7 -3
- package/packages/bundled-features/src/tenant-lifecycle/changes.json +6 -0
- package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +90 -42
- package/samples/apps/ui-walkthrough/src/app/auth-constants.ts +51 -0
- package/samples/apps/ui-walkthrough/src/app/seed-print-editor-tenants.ts +118 -0
- package/samples/apps/ui-walkthrough/src/app/seed-templates.ts +2 -0
- package/samples/apps/ui-walkthrough/src/app/server.ts +9 -1
- package/samples/apps/ui-walkthrough/src/app/template-seed-data.ts +27 -1
- package/samples/apps/ui-walkthrough/src/run-config.ts +1 -0
- package/samples/apps/use-all-bundled/feature-manifest.json +238 -1
- package/samples/recipes/crypto-shredding-hr/README.md +1 -1
- package/samples/recipes/crypto-shredding-hr/src/feature.ts +1 -1
- package/samples/recipes/list-table-options/README.md +9 -3
- package/samples/recipes/list-table-options/src/feature.ts +123 -3
- package/samples/recipes/pdf-letterhead/README.md +23 -0
- package/samples/recipes/pdf-letterhead/package.json +12 -0
- package/samples/recipes/pdf-letterhead/src/letterhead.ts +92 -0
|
@@ -19,6 +19,7 @@ import { requireForTenant } from "../../shared/index.ts";
|
|
|
19
19
|
import type { TemplateWriteScope } from "../layout-regions.ts";
|
|
20
20
|
import { type TemplateResourceRow, templateResourcesTable } from "../table.ts";
|
|
21
21
|
import { activationChanges, serializeTemplateDraft } from "../template-draft.ts";
|
|
22
|
+
import { refuseReservedSystemLayoutSlug } from "../template-edit-policy.ts";
|
|
22
23
|
import { isSystemOnlyTemplate } from "../template-system-only.ts";
|
|
23
24
|
import type { TemplateValidation } from "../template-validation.ts";
|
|
24
25
|
import type { ContentFormat, TemplateKind } from "../web/constants.ts";
|
|
@@ -169,6 +170,19 @@ function versionConflictFor(
|
|
|
169
170
|
);
|
|
170
171
|
}
|
|
171
172
|
|
|
173
|
+
function refuseScopeViolation(
|
|
174
|
+
registry: HandlerContext["registry"],
|
|
175
|
+
scope: TemplateWriteScope,
|
|
176
|
+
tenantId: TenantId,
|
|
177
|
+
payload: TemplateRowWrite["payload"],
|
|
178
|
+
): WriteResult<never> | WriteFailure | null {
|
|
179
|
+
return (
|
|
180
|
+
refuseTenantScopeUnderSystemTenant(scope, tenantId) ??
|
|
181
|
+
refuseReservedSystemLayoutSlug(scope, payload, "slug") ??
|
|
182
|
+
refuseSystemOnlyTenantOverride(registry, scope, payload.slug, payload.kind)
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
172
186
|
// Shared by every template write: validate through the one pipeline, then
|
|
173
187
|
// create or update the (tenant, slug, kind, locale) row via the event-store
|
|
174
188
|
// executor. linkedResources is never part of an update; resources are attached
|
|
@@ -177,9 +191,7 @@ export async function writeTemplateRow(
|
|
|
177
191
|
args: TemplateRowWrite,
|
|
178
192
|
): Promise<WriteResult<WrittenTemplateRow>> {
|
|
179
193
|
const { ctx, user, tenantId, scope, status, payload } = args;
|
|
180
|
-
const refused =
|
|
181
|
-
refuseTenantScopeUnderSystemTenant(scope, tenantId) ??
|
|
182
|
-
refuseSystemOnlyTenantOverride(ctx.registry, scope, payload.slug, payload.kind);
|
|
194
|
+
const refused = refuseScopeViolation(ctx.registry, scope, tenantId, payload);
|
|
183
195
|
if (refused !== null) return refused;
|
|
184
196
|
const { db, streamTenantId } = requireForTenant(ctx, tenantId);
|
|
185
197
|
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import type { HandlerContext } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { toKebab } from "@cosmicdrift/kumiko-types/kebab-case";
|
|
3
|
+
import { createTemplateResolverApi, TemplateNotFoundError } from "../api.ts";
|
|
4
|
+
import { withParsedDocument } from "../document-sanitizer.ts";
|
|
5
|
+
import { parseTemplateMeta, readPdfTemplateMeta } from "../template-meta.ts";
|
|
6
|
+
import {
|
|
7
|
+
COMPANY_PLACEHOLDERS,
|
|
8
|
+
DEFAULT_PDF_LAYOUT_SLUG,
|
|
9
|
+
DEFAULT_PDF_LAYOUT_SLUG_CONFIG_KEY,
|
|
10
|
+
FALLBACK_LOCALE,
|
|
11
|
+
} from "../web/constants.ts";
|
|
12
|
+
|
|
13
|
+
const TENANT_CONFIG_PREFIX = "tenant:config:";
|
|
14
|
+
|
|
15
|
+
export function companyConfigKey(name: string): string {
|
|
16
|
+
return `${TENANT_CONFIG_PREFIX}${toKebab(name)}`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// A key only exists in the registry when its feature is mounted; reading an unregistered key
|
|
20
|
+
// through the accessor would throw instead of falling back.
|
|
21
|
+
export async function readTenantConfigText(
|
|
22
|
+
ctx: Pick<HandlerContext, "config" | "registry">,
|
|
23
|
+
qualifiedKey: string,
|
|
24
|
+
): Promise<string> {
|
|
25
|
+
if (ctx.config === undefined || ctx.registry.getConfigKey(qualifiedKey) === undefined) return "";
|
|
26
|
+
const value = await ctx.config(qualifiedKey);
|
|
27
|
+
return typeof value === "string" ? value : "";
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type DefaultLayoutContext = Pick<HandlerContext, "config" | "registry"> & {
|
|
31
|
+
readonly db: Parameters<typeof createTemplateResolverApi>[0];
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
// A configured default that no longer resolves (archived or deleted) must not leave documents
|
|
35
|
+
// without letterhead, so it falls back to the built-in layout.
|
|
36
|
+
export async function defaultPdfLayoutSlug(
|
|
37
|
+
ctx: DefaultLayoutContext,
|
|
38
|
+
tenantId: string,
|
|
39
|
+
locale: string = FALLBACK_LOCALE,
|
|
40
|
+
): Promise<string> {
|
|
41
|
+
const slug = await readTenantConfigText(ctx, DEFAULT_PDF_LAYOUT_SLUG_CONFIG_KEY);
|
|
42
|
+
if (slug === "") return DEFAULT_PDF_LAYOUT_SLUG;
|
|
43
|
+
try {
|
|
44
|
+
await createTemplateResolverApi(ctx.db, ctx.registry).resolveLayout({
|
|
45
|
+
tenantId,
|
|
46
|
+
slug,
|
|
47
|
+
kind: "pdf-layout",
|
|
48
|
+
locale,
|
|
49
|
+
});
|
|
50
|
+
return slug;
|
|
51
|
+
} catch (e) {
|
|
52
|
+
if (e instanceof TemplateNotFoundError) return DEFAULT_PDF_LAYOUT_SLUG;
|
|
53
|
+
throw e;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function isCompanyPlaceholder(name: string): boolean {
|
|
58
|
+
return COMPANY_PLACEHOLDERS.some((candidate) => candidate === name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function companyPlaceholdersIn(html: string): readonly string[] {
|
|
62
|
+
return withParsedDocument(html, (body) => [
|
|
63
|
+
...Array.from(body.querySelectorAll("span[data-variable]")).flatMap((element) => {
|
|
64
|
+
const name = element.getAttribute("data-variable") ?? "";
|
|
65
|
+
return isCompanyPlaceholder(name) ? [name] : [];
|
|
66
|
+
}),
|
|
67
|
+
]);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The layout the document is rendered into: its own choice, else the tenant default, else the built-in one.
|
|
71
|
+
async function layoutHtmlOf(
|
|
72
|
+
ctx: HandlerContext,
|
|
73
|
+
tenantId: string,
|
|
74
|
+
meta: unknown,
|
|
75
|
+
locale: string | undefined,
|
|
76
|
+
): Promise<string> {
|
|
77
|
+
const parsedMeta = parseTemplateMeta("document-pdf", meta);
|
|
78
|
+
const pdfMeta = parsedMeta.ok ? readPdfTemplateMeta(parsedMeta.meta) : null;
|
|
79
|
+
const effectiveLocale = locale ?? FALLBACK_LOCALE;
|
|
80
|
+
const slug = pdfMeta?.layoutSlug ?? (await defaultPdfLayoutSlug(ctx, tenantId, effectiveLocale));
|
|
81
|
+
try {
|
|
82
|
+
const layout = await createTemplateResolverApi(ctx.db, ctx.registry).resolveLayout({
|
|
83
|
+
tenantId,
|
|
84
|
+
slug,
|
|
85
|
+
kind: "pdf-layout",
|
|
86
|
+
locale: effectiveLocale,
|
|
87
|
+
});
|
|
88
|
+
return layout.content ?? "";
|
|
89
|
+
} catch (e) {
|
|
90
|
+
if (e instanceof TemplateNotFoundError) return "";
|
|
91
|
+
throw e;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// Company placeholders the draft or its layout prints without the tenant having entered a value.
|
|
96
|
+
export async function emptyCompanyData(
|
|
97
|
+
ctx: HandlerContext,
|
|
98
|
+
input: {
|
|
99
|
+
readonly kind: string;
|
|
100
|
+
readonly body: string;
|
|
101
|
+
readonly meta: unknown;
|
|
102
|
+
readonly locale: string | undefined;
|
|
103
|
+
readonly tenantId: string;
|
|
104
|
+
},
|
|
105
|
+
): Promise<readonly string[]> {
|
|
106
|
+
if (input.kind !== "document-pdf" && input.kind !== "pdf-layout") return [];
|
|
107
|
+
const layoutHtml =
|
|
108
|
+
input.kind === "document-pdf"
|
|
109
|
+
? await layoutHtmlOf(ctx, input.tenantId, input.meta, input.locale)
|
|
110
|
+
: "";
|
|
111
|
+
const used = new Set([
|
|
112
|
+
...companyPlaceholdersIn(input.body),
|
|
113
|
+
...companyPlaceholdersIn(layoutHtml),
|
|
114
|
+
]);
|
|
115
|
+
const empty: string[] = [];
|
|
116
|
+
for (const name of COMPANY_PLACEHOLDERS) {
|
|
117
|
+
if (!used.has(name)) continue;
|
|
118
|
+
const value = await readTenantConfigText(ctx, companyConfigKey(name));
|
|
119
|
+
if (value.trim() === "") empty.push(name);
|
|
120
|
+
}
|
|
121
|
+
return empty;
|
|
122
|
+
}
|
|
@@ -2,7 +2,9 @@ import { fetchOne } from "@cosmicdrift/kumiko-framework/db";
|
|
|
2
2
|
import {
|
|
3
3
|
defineWriteHandler,
|
|
4
4
|
type HandlerContext,
|
|
5
|
+
type SessionUser,
|
|
5
6
|
SYSTEM_TENANT_ID,
|
|
7
|
+
type WriteResult,
|
|
6
8
|
} from "@cosmicdrift/kumiko-framework/engine";
|
|
7
9
|
import {
|
|
8
10
|
NotFoundError,
|
|
@@ -72,6 +74,28 @@ function planStatusChange(
|
|
|
72
74
|
return { ok: true, changes: { ...parseTemplateDraft(row.draft), ...activationChanges(row) } };
|
|
73
75
|
}
|
|
74
76
|
|
|
77
|
+
type LoadedTarget = Pick<Awaited<ReturnType<typeof loadTargetRow>>, "db" | "scoped">;
|
|
78
|
+
|
|
79
|
+
// The gated status change every publish and archive path shares.
|
|
80
|
+
export async function changeRowStatus(
|
|
81
|
+
ctx: HandlerContext,
|
|
82
|
+
user: SessionUser,
|
|
83
|
+
target: LoadedTarget,
|
|
84
|
+
row: TemplateResourceRow,
|
|
85
|
+
status: TemplateStatus,
|
|
86
|
+
): Promise<WriteResult<{ readonly id: string; readonly status: TemplateStatus }>> {
|
|
87
|
+
const plan = planStatusChange(ctx, row, status);
|
|
88
|
+
if (!plan.ok) return plan.failure;
|
|
89
|
+
const result = await executor.update(
|
|
90
|
+
{ id: row.id, version: row.version, changes: plan.changes },
|
|
91
|
+
user,
|
|
92
|
+
target.db,
|
|
93
|
+
target.scoped ? { streamTenantId: target.scoped.streamTenantId } : undefined,
|
|
94
|
+
);
|
|
95
|
+
if (!result.isSuccess) return result;
|
|
96
|
+
return { isSuccess: true, data: { id: String(row.id), status } };
|
|
97
|
+
}
|
|
98
|
+
|
|
75
99
|
function createStatusUpdateHandler(
|
|
76
100
|
policy: TemplateEditPolicy,
|
|
77
101
|
name: string,
|
|
@@ -96,16 +120,7 @@ function createStatusUpdateHandler(
|
|
|
96
120
|
const refused = refuseTemplateEdit(policy, event.user, row);
|
|
97
121
|
if (refused !== null) return refused;
|
|
98
122
|
}
|
|
99
|
-
|
|
100
|
-
if (!plan.ok) return plan.failure;
|
|
101
|
-
const result = await executor.update(
|
|
102
|
-
{ id: row.id, version: row.version, changes: plan.changes },
|
|
103
|
-
event.user,
|
|
104
|
-
db,
|
|
105
|
-
scoped ? { streamTenantId: scoped.streamTenantId } : undefined,
|
|
106
|
-
);
|
|
107
|
-
if (!result.isSuccess) return result;
|
|
108
|
-
return { isSuccess: true as const, data: { id: String(row.id), status } };
|
|
123
|
+
return changeRowStatus(ctx, event.user, { db, scoped }, row, status);
|
|
109
124
|
},
|
|
110
125
|
});
|
|
111
126
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { defineWriteHandler, SYSTEM_TENANT_ID } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { refuseReservedLayoutSlug } from "../template-edit-policy.ts";
|
|
2
3
|
import { resolveTemplateVariables } from "../template-validation.ts";
|
|
3
4
|
import { upsertPayloadSchema } from "./shared.ts";
|
|
4
5
|
import { writeTemplateRow } from "./template-write.ts";
|
|
@@ -12,8 +13,10 @@ export const upsertSystemWrite = defineWriteHandler({
|
|
|
12
13
|
access: { roles: ["SystemAdmin"] },
|
|
13
14
|
description:
|
|
14
15
|
"Creates or overwrites a system-default template under the system tenant with its full variable schema (resource files go through the resource upload), active straight away with no draft stage; SystemAdmin only, since tenants shadow these defaults through upsert-tenant instead.",
|
|
15
|
-
handler: (event, ctx) =>
|
|
16
|
-
|
|
16
|
+
handler: async (event, ctx) => {
|
|
17
|
+
const refused = refuseReservedLayoutSlug(event.payload, "slug");
|
|
18
|
+
if (refused !== null) return refused;
|
|
19
|
+
return writeTemplateRow({
|
|
17
20
|
ctx,
|
|
18
21
|
user: event.user,
|
|
19
22
|
tenantId: SYSTEM_TENANT_ID,
|
|
@@ -25,5 +28,6 @@ export const upsertSystemWrite = defineWriteHandler({
|
|
|
25
28
|
event.payload.variableSchema,
|
|
26
29
|
),
|
|
27
30
|
payload: event.payload,
|
|
28
|
-
})
|
|
31
|
+
});
|
|
32
|
+
},
|
|
29
33
|
});
|
|
@@ -1,15 +1,127 @@
|
|
|
1
1
|
import { selectMany } from "@cosmicdrift/kumiko-framework/db";
|
|
2
|
-
import { defineQueryHandler } from "@cosmicdrift/kumiko-framework/engine";
|
|
2
|
+
import { defineQueryHandler, type HandlerContext } from "@cosmicdrift/kumiko-framework/engine";
|
|
3
3
|
import * as z from "zod";
|
|
4
4
|
import { type TemplateResourceRow, templateResourcesTable } from "../table.ts";
|
|
5
5
|
import { deliveryPolicyOf } from "../template-delivery-policy.ts";
|
|
6
|
+
import { draftViewerTenantId, parseTemplateDraft, servedVersionOf } from "../template-draft.ts";
|
|
6
7
|
import type { TemplateEditPolicy } from "../template-edit-policy.ts";
|
|
7
8
|
import { templateSlugSchema } from "../template-meta.ts";
|
|
8
9
|
import { collectTemplateUsage } from "../template-usage.ts";
|
|
9
10
|
import { TEMPLATE_KINDS } from "../web/constants.ts";
|
|
10
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
effectiveMailLayoutSlugs,
|
|
13
|
+
effectiveRowsOf,
|
|
14
|
+
isRowVisibleToCaller,
|
|
15
|
+
ownLayoutSlugOf,
|
|
16
|
+
} from "./overview.query.ts";
|
|
17
|
+
import { storedRecord } from "./template-gates.ts";
|
|
18
|
+
import { defaultPdfLayoutSlug } from "./tenant-settings.ts";
|
|
11
19
|
|
|
12
|
-
const
|
|
20
|
+
const USAGE_ROW_LIMIT = 5000;
|
|
21
|
+
|
|
22
|
+
export type PdfLayoutUser = {
|
|
23
|
+
readonly slug: string;
|
|
24
|
+
readonly locale: string;
|
|
25
|
+
readonly title: string;
|
|
26
|
+
readonly hasOwnLayout: boolean;
|
|
27
|
+
readonly isSystem: boolean;
|
|
28
|
+
/** "draft" when an open draft names this layout, else the served status. */
|
|
29
|
+
readonly status: "draft" | "active";
|
|
30
|
+
readonly version: number;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
async function visibleRowsOfKind(
|
|
34
|
+
ctx: HandlerContext,
|
|
35
|
+
policy: TemplateEditPolicy,
|
|
36
|
+
user: Parameters<typeof isRowVisibleToCaller>[1],
|
|
37
|
+
kind: "mail" | "document-pdf",
|
|
38
|
+
): Promise<TemplateResourceRow[]> {
|
|
39
|
+
const fetchedRows = await selectMany<TemplateResourceRow>(
|
|
40
|
+
ctx.db,
|
|
41
|
+
templateResourcesTable,
|
|
42
|
+
{ kind },
|
|
43
|
+
{ orderBy: { col: "id", direction: "asc" }, limit: USAGE_ROW_LIMIT + 1 },
|
|
44
|
+
);
|
|
45
|
+
if (fetchedRows.length > USAGE_ROW_LIMIT) {
|
|
46
|
+
ctx.obs.log?.warn("template usage: row limit reached, result is incomplete", {
|
|
47
|
+
limit: USAGE_ROW_LIMIT,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
return fetchedRows
|
|
51
|
+
.slice(0, USAGE_ROW_LIMIT)
|
|
52
|
+
.filter((row) => isRowVisibleToCaller(policy, user, ctx.registry, row));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// An open draft lives beside the served row, so its layout choice sits in the draft's own meta.
|
|
56
|
+
function draftLayoutOf(
|
|
57
|
+
user: Parameters<typeof draftViewerTenantId>[0],
|
|
58
|
+
row: TemplateResourceRow,
|
|
59
|
+
): { readonly layoutSlug: string | null } | null {
|
|
60
|
+
if (row.tenantId !== draftViewerTenantId(user, row)) return null;
|
|
61
|
+
const draft = parseTemplateDraft(row.draft);
|
|
62
|
+
if (draft === null) return null;
|
|
63
|
+
const layoutSlug = storedRecord(draft.meta)["layoutSlug"];
|
|
64
|
+
return { layoutSlug: typeof layoutSlug === "string" ? layoutSlug : null };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function servedRowOf(
|
|
68
|
+
group: readonly TemplateResourceRow[],
|
|
69
|
+
policy: ReturnType<typeof deliveryPolicyOf>,
|
|
70
|
+
): { readonly served: TemplateResourceRow; readonly isSystem: boolean } | null {
|
|
71
|
+
const effective = effectiveRowsOf(group, policy);
|
|
72
|
+
if (effective === null || (effective.lockedOverride && effective.origin === "tenant"))
|
|
73
|
+
return null;
|
|
74
|
+
const served = effective.rows[0];
|
|
75
|
+
if (served === undefined || served.status === "archived") return null;
|
|
76
|
+
return { served, isSystem: effective.origin === "system" };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function pdfLayoutUserOf(
|
|
80
|
+
group: readonly TemplateResourceRow[],
|
|
81
|
+
layoutSlug: string,
|
|
82
|
+
defaultSlug: string,
|
|
83
|
+
policy: ReturnType<typeof deliveryPolicyOf>,
|
|
84
|
+
user: Parameters<typeof draftViewerTenantId>[0],
|
|
85
|
+
): PdfLayoutUser | null {
|
|
86
|
+
const found = servedRowOf(group, policy);
|
|
87
|
+
if (found === null) return null;
|
|
88
|
+
const { served, isSystem } = found;
|
|
89
|
+
const ownLayout = ownLayoutSlugOf(served);
|
|
90
|
+
const servedUses = (ownLayout ?? defaultSlug) === layoutSlug;
|
|
91
|
+
const draft = draftLayoutOf(user, served);
|
|
92
|
+
const draftUses = draft !== null && (draft.layoutSlug ?? defaultSlug) === layoutSlug;
|
|
93
|
+
if (!servedUses && !draftUses) return null;
|
|
94
|
+
return {
|
|
95
|
+
slug: served.slug,
|
|
96
|
+
locale: served.locale,
|
|
97
|
+
title: served.title ?? served.slug,
|
|
98
|
+
hasOwnLayout: draftUses ? draft.layoutSlug !== null : ownLayout !== null,
|
|
99
|
+
isSystem,
|
|
100
|
+
status: draftUses || served.status === "draft" ? "draft" : "active",
|
|
101
|
+
version: draftUses ? served.version : servedVersionOf(served),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The served version of every document and locale decides: its own layout, else the tenant default.
|
|
106
|
+
// A saved draft that names the layout counts too, so a template shows up as soon as it is applied.
|
|
107
|
+
function pdfLayoutUsers(
|
|
108
|
+
rows: readonly TemplateResourceRow[],
|
|
109
|
+
layoutSlug: string,
|
|
110
|
+
defaultSlug: string,
|
|
111
|
+
policy: ReturnType<typeof deliveryPolicyOf>,
|
|
112
|
+
user: Parameters<typeof draftViewerTenantId>[0],
|
|
113
|
+
): PdfLayoutUser[] {
|
|
114
|
+
const groups = new Map<string, TemplateResourceRow[]>();
|
|
115
|
+
for (const row of rows) {
|
|
116
|
+
const key = `${row.slug}\u0000${row.locale}`;
|
|
117
|
+
groups.set(key, [...(groups.get(key) ?? []), row]);
|
|
118
|
+
}
|
|
119
|
+
const users = [...groups.values()].flatMap((group) => {
|
|
120
|
+
const layoutUser = pdfLayoutUserOf(group, layoutSlug, defaultSlug, policy, user);
|
|
121
|
+
return layoutUser === null ? [] : [layoutUser];
|
|
122
|
+
});
|
|
123
|
+
return users.sort((a, b) => a.slug.localeCompare(b.slug) || a.locale.localeCompare(b.locale));
|
|
124
|
+
}
|
|
13
125
|
|
|
14
126
|
export function makeUsageQuery(policy: TemplateEditPolicy) {
|
|
15
127
|
return defineQueryHandler({
|
|
@@ -17,24 +129,25 @@ export function makeUsageQuery(policy: TemplateEditPolicy) {
|
|
|
17
129
|
schema: z.object({ slug: templateSlugSchema, kind: z.enum(TEMPLATE_KINDS) }),
|
|
18
130
|
access: { roles: ["TenantAdmin", "SystemAdmin"] },
|
|
19
131
|
description:
|
|
20
|
-
"Lists
|
|
132
|
+
"Lists what uses one template: a mail template is used by the notification whose qualified name is its slug and that has a code template, a mail layout by every mail notification whose effective template (own override, else system) names it, or whose code meta does when no stored template exists, or that falls back to the default layout (`usedBy`); a PDF layout is used by every visible PDF template and locale whose served version names it or, naming none, falls back to it through the tenant's default PDF layout (`usedByTemplates` with slug, locale, title, `hasOwnLayout`, `isSystem`, `status` and `version`; a template whose saved draft names the layout is listed too, with status draft); use it to show what a change to a template affects.",
|
|
21
133
|
handler: async (query, ctx) => {
|
|
22
134
|
const { slug, kind } = query.payload;
|
|
23
|
-
if (kind
|
|
24
|
-
|
|
25
|
-
ctx.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
135
|
+
if (kind === "pdf-layout") {
|
|
136
|
+
const defaultSlug = await defaultPdfLayoutSlug(ctx, query.user.tenantId);
|
|
137
|
+
const rows = await visibleRowsOfKind(ctx, policy, query.user, "document-pdf");
|
|
138
|
+
return {
|
|
139
|
+
usedBy: [],
|
|
140
|
+
usedByTemplates: pdfLayoutUsers(
|
|
141
|
+
rows,
|
|
142
|
+
slug,
|
|
143
|
+
defaultSlug,
|
|
144
|
+
deliveryPolicyOf(ctx.registry),
|
|
145
|
+
query.user,
|
|
146
|
+
),
|
|
147
|
+
};
|
|
34
148
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
.filter((row) => isRowVisibleToCaller(policy, query.user, ctx.registry, row));
|
|
149
|
+
if (kind !== "mail-layout") return { usedBy: collectTemplateUsage(ctx.registry, slug, kind) };
|
|
150
|
+
const visibleRows = await visibleRowsOfKind(ctx, policy, query.user, "mail");
|
|
38
151
|
return {
|
|
39
152
|
usedBy: collectTemplateUsage(
|
|
40
153
|
ctx.registry,
|
|
@@ -16,6 +16,7 @@ import { resolveTemplateVariables, systemPlaceholdersFor } from "../template-val
|
|
|
16
16
|
import type { ContentFormat, UpsertKind } from "../web/constants.ts";
|
|
17
17
|
import { contentFormatSchema, kindSchema, localeSchema, templateSlugSchema } from "./shared.ts";
|
|
18
18
|
import { evaluateTemplateWrite } from "./template-gates.ts";
|
|
19
|
+
import { emptyCompanyData } from "./tenant-settings.ts";
|
|
19
20
|
|
|
20
21
|
async function knownResourceKeys(
|
|
21
22
|
db: Parameters<typeof selectMany>[0],
|
|
@@ -116,6 +117,15 @@ export async function validateTemplateDraft(
|
|
|
116
117
|
})),
|
|
117
118
|
variables,
|
|
118
119
|
systemPlaceholders: [...systemPlaceholdersFor(kind)].sort(),
|
|
120
|
+
emptyCompanyData: [
|
|
121
|
+
...(await emptyCompanyData(ctx, {
|
|
122
|
+
kind,
|
|
123
|
+
body: payload.contentFormat === "html" ? payload.content : "",
|
|
124
|
+
meta: payload.meta,
|
|
125
|
+
locale,
|
|
126
|
+
tenantId: user.tenantId,
|
|
127
|
+
})),
|
|
128
|
+
],
|
|
119
129
|
};
|
|
120
130
|
return { response, evaluation };
|
|
121
131
|
}
|
|
@@ -22,4 +22,7 @@ export const TEMPLATE_RESOLVER_I18N: Readonly<Record<string, { readonly en: stri
|
|
|
22
22
|
[handlerTitleKey(H.resourceLinkPdf)]: { en: "Attach PDF template" },
|
|
23
23
|
[handlerTitleKey(H.sendTest)]: { en: "Send test mail" },
|
|
24
24
|
[handlerTitleKey(H.patchDraft)]: { en: "Edit template draft" },
|
|
25
|
+
[handlerTitleKey(H.applyLayout)]: { en: "Apply PDF layout" },
|
|
26
|
+
[handlerTitleKey(H.createLayout)]: { en: "Create PDF layout" },
|
|
27
|
+
[handlerTitleKey(H.publishTemplates)]: { en: "Publish several templates" },
|
|
25
28
|
};
|
|
@@ -14,6 +14,7 @@ export {
|
|
|
14
14
|
compileDocumentBodyToHandlebars,
|
|
15
15
|
toResourceDataUri,
|
|
16
16
|
} from "./compile-document-body.ts";
|
|
17
|
+
export { flattenFramesForPreview, readTopLevelFrames } from "./document-frames.ts";
|
|
17
18
|
export {
|
|
18
19
|
type DocumentViolation,
|
|
19
20
|
type DocumentViolationCode,
|
|
@@ -34,6 +35,11 @@ export type {
|
|
|
34
35
|
OverviewUsage,
|
|
35
36
|
} from "./handlers/overview.query.ts";
|
|
36
37
|
export { localeSchema } from "./handlers/shared.ts";
|
|
38
|
+
export {
|
|
39
|
+
companyConfigKey,
|
|
40
|
+
defaultPdfLayoutSlug,
|
|
41
|
+
readTenantConfigText,
|
|
42
|
+
} from "./handlers/tenant-settings.ts";
|
|
37
43
|
export {
|
|
38
44
|
isHexColor,
|
|
39
45
|
type MailLayoutAppearance,
|
|
@@ -84,10 +90,12 @@ export {
|
|
|
84
90
|
type MailLayoutMeta,
|
|
85
91
|
type MailTemplateMeta,
|
|
86
92
|
type MailTone,
|
|
93
|
+
type PdfLayoutMeta,
|
|
87
94
|
type PdfTemplateMeta,
|
|
88
95
|
parseTemplateMeta,
|
|
89
96
|
pdfAttachmentFileNamePatternSchema,
|
|
90
97
|
readMailLayoutMeta,
|
|
98
|
+
readPdfLayoutMeta,
|
|
91
99
|
readPdfTemplateMeta,
|
|
92
100
|
type TemplateMeta,
|
|
93
101
|
type TemplateMetaIssue,
|
|
@@ -112,28 +120,34 @@ export {
|
|
|
112
120
|
userContentEntryEntity,
|
|
113
121
|
} from "./user-content-table.ts";
|
|
114
122
|
export {
|
|
123
|
+
COMPANY_PLACEHOLDERS,
|
|
115
124
|
CONTENT_FORMATS,
|
|
116
125
|
type ContentFormat,
|
|
117
126
|
DEFAULT_MAIL_LAYOUT_SLUG,
|
|
118
127
|
DEFAULT_PDF_LAYOUT_SLUG,
|
|
128
|
+
DEFAULT_PDF_LAYOUT_SLUG_CONFIG_KEY,
|
|
119
129
|
DOCUMENT_HTML_KINDS,
|
|
120
130
|
type DocumentHtmlKind,
|
|
121
131
|
FALLBACK_LOCALE,
|
|
122
132
|
NON_RENDER_KINDS,
|
|
123
133
|
type NonRenderKind,
|
|
134
|
+
PDF_DEFAULT_FONT_SIZE_PT,
|
|
124
135
|
PDF_DEFAULT_MARGIN_MM,
|
|
125
136
|
PDF_FOOTER_MARGIN_MM,
|
|
126
137
|
PDF_HEADER_MARGIN_MM,
|
|
127
138
|
PDF_ORIENTATIONS,
|
|
128
139
|
PDF_PAGE_FORMATS,
|
|
140
|
+
PDF_TABLE_STYLES,
|
|
129
141
|
type PdfOrientation,
|
|
130
142
|
type PdfPageFormat,
|
|
143
|
+
type PdfTableStyle,
|
|
131
144
|
RENDER_KINDS,
|
|
132
145
|
type RenderKind,
|
|
133
146
|
SYSTEM_TENANT_ID,
|
|
134
147
|
TEMPLATE_KINDS,
|
|
135
148
|
TEMPLATE_SCOPES,
|
|
136
149
|
TEMPLATE_STATUSES,
|
|
150
|
+
TENANT_LAYOUT_SLUG_PREFIX,
|
|
137
151
|
TEXT_BLOCK_KIND,
|
|
138
152
|
type TemplateKind,
|
|
139
153
|
type TemplateScope,
|
|
@@ -141,6 +155,13 @@ export {
|
|
|
141
155
|
UPSERT_KINDS,
|
|
142
156
|
type UpsertKind,
|
|
143
157
|
} from "./web/constants.ts";
|
|
158
|
+
export {
|
|
159
|
+
DOCUMENT_FONT_LABELS,
|
|
160
|
+
DOCUMENT_FONT_PRINT_STACKS,
|
|
161
|
+
DOCUMENT_FONTS,
|
|
162
|
+
type DocumentFont,
|
|
163
|
+
} from "./web/document-fonts.ts";
|
|
164
|
+
export type { DocumentFrameAttributes } from "./web/document-print-style.ts";
|
|
144
165
|
export {
|
|
145
166
|
DOCUMENT_CONDITION_ATTRIBUTE,
|
|
146
167
|
DOCUMENT_NODE_NAMES,
|
|
@@ -165,6 +186,14 @@ export {
|
|
|
165
186
|
isDocumentReferenceName,
|
|
166
187
|
isDocumentResourceKey,
|
|
167
188
|
} from "./web/document-schema.ts";
|
|
189
|
+
export {
|
|
190
|
+
addressParagraphCss,
|
|
191
|
+
DOCUMENT_LINE_VARIABLE,
|
|
192
|
+
documentLinePt,
|
|
193
|
+
FRAME_FLOW_GAP_MM,
|
|
194
|
+
PARAGRAPH_DEFAULT_LINE_HEIGHT,
|
|
195
|
+
SENDER_LINE_SIZE_PT,
|
|
196
|
+
} from "./web/document-style-css.ts";
|
|
168
197
|
export {
|
|
169
198
|
TEMPLATE_RESOLVER_FEATURE,
|
|
170
199
|
TemplateResolverErrors,
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// the renderer did not plan for.
|
|
5
5
|
|
|
6
6
|
import type { Element as ScanElement } from "happy-dom";
|
|
7
|
+
import { hasFrame, IMAGES_BLOCK_SELECTOR, scanPrintOnlyFeatures } from "./document-print-only.ts";
|
|
7
8
|
import {
|
|
8
9
|
type DocumentViolation,
|
|
9
10
|
type SanitizeBodyResult,
|
|
@@ -19,11 +20,10 @@ type RegionAttribute = (typeof REGION_ATTRIBUTES)[number];
|
|
|
19
20
|
|
|
20
21
|
const MAIL_LAYOUT_CONTENT_SLOT = /\{\{\{\s*content\s*\}\}\}/g;
|
|
21
22
|
|
|
22
|
-
export
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
};
|
|
23
|
+
export const LAYOUT_REGION_NAMES = ["header", "signature", "footer"] as const;
|
|
24
|
+
export type LayoutRegionName = (typeof LAYOUT_REGION_NAMES)[number];
|
|
25
|
+
|
|
26
|
+
export type LayoutRegions = Readonly<Record<LayoutRegionName, string>>;
|
|
27
27
|
|
|
28
28
|
export type SanitizeLayoutResult =
|
|
29
29
|
| { readonly ok: true; readonly html: string }
|
|
@@ -103,23 +103,28 @@ export function sanitizeLayoutHtml(html: string): SanitizeLayoutResult {
|
|
|
103
103
|
for (const name of ["data-header", "data-signature", "data-footer"] as const) {
|
|
104
104
|
const inner = parsed.innerHtml[name];
|
|
105
105
|
if (inner === undefined || inner.trim() === "") continue;
|
|
106
|
+
if (withParsedDocument(inner, hasFrame)) {
|
|
107
|
+
violations.push(
|
|
108
|
+
violation(
|
|
109
|
+
"frame_not_top_level",
|
|
110
|
+
name,
|
|
111
|
+
`Frames are not allowed in the ${name} region; they belong in the document body`,
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
106
116
|
const result = sanitizeDocumentHtml(inner);
|
|
107
117
|
if (result.ok) cleanedHtml[name] = result.html;
|
|
108
118
|
else violations.push(...result.violations);
|
|
109
119
|
}
|
|
110
120
|
if (violations.length > 0) return { ok: false, violations };
|
|
111
|
-
const part = (name: RegionAttribute) => {
|
|
112
|
-
const regionHtml = cleanedHtml[name];
|
|
113
|
-
return regionHtml === undefined ? "" : `<div ${name}>${regionHtml}</div>`;
|
|
114
|
-
};
|
|
115
121
|
return {
|
|
116
122
|
ok: true,
|
|
117
|
-
html:
|
|
118
|
-
|
|
119
|
-
"
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
].join(""),
|
|
123
|
+
html: composeLayoutHtml({
|
|
124
|
+
header: cleanedHtml["data-header"] ?? "",
|
|
125
|
+
signature: cleanedHtml["data-signature"] ?? "",
|
|
126
|
+
footer: cleanedHtml["data-footer"] ?? "",
|
|
127
|
+
}),
|
|
123
128
|
};
|
|
124
129
|
}
|
|
125
130
|
|
|
@@ -132,6 +137,18 @@ export function readLayoutRegions(html: string): LayoutRegions {
|
|
|
132
137
|
};
|
|
133
138
|
}
|
|
134
139
|
|
|
140
|
+
// Empty regions are left out, the form the sanitizer stores.
|
|
141
|
+
export function composeLayoutHtml(regions: LayoutRegions): string {
|
|
142
|
+
const part = (name: RegionAttribute, regionHtml: string) =>
|
|
143
|
+
regionHtml.trim() === "" ? "" : `<div ${name}>${regionHtml}</div>`;
|
|
144
|
+
return [
|
|
145
|
+
part("data-header", regions.header),
|
|
146
|
+
"<div data-content></div>",
|
|
147
|
+
part("data-signature", regions.signature),
|
|
148
|
+
part("data-footer", regions.footer),
|
|
149
|
+
].join("");
|
|
150
|
+
}
|
|
151
|
+
|
|
135
152
|
export type TemplateWriteScope = "system" | "tenant";
|
|
136
153
|
|
|
137
154
|
function rejected(violationItem: DocumentViolation): SanitizeBodyResult {
|
|
@@ -143,7 +160,7 @@ function sanitizeMailLayout(
|
|
|
143
160
|
contentFormat: ContentFormat,
|
|
144
161
|
content: string,
|
|
145
162
|
): SanitizeBodyResult {
|
|
146
|
-
if (contentFormat === "html") return
|
|
163
|
+
if (contentFormat === "html") return refusePrintOnlyFeatures(sanitizeLayoutHtml(content));
|
|
147
164
|
if (contentFormat !== "mjml") {
|
|
148
165
|
return rejected(
|
|
149
166
|
violation(
|
|
@@ -174,6 +191,27 @@ function sanitizeMailLayout(
|
|
|
174
191
|
return { ok: true, content };
|
|
175
192
|
}
|
|
176
193
|
|
|
194
|
+
// The shared document model survives the rebuild in a mail layout, but only a PDF applies print styling.
|
|
195
|
+
function refusePrintOnlyFeatures(result: SanitizeLayoutResult): SanitizeBodyResult {
|
|
196
|
+
if (!result.ok) return result;
|
|
197
|
+
const found = withParsedDocument(result.html, scanPrintOnlyFeatures);
|
|
198
|
+
const selectors = [
|
|
199
|
+
...found.printStyleSelectors,
|
|
200
|
+
...(found.hasImagesBlock ? [IMAGES_BLOCK_SELECTOR] : []),
|
|
201
|
+
];
|
|
202
|
+
if (selectors.length === 0) return { ok: true, content: result.html };
|
|
203
|
+
return {
|
|
204
|
+
ok: false,
|
|
205
|
+
violations: selectors.map((selector) =>
|
|
206
|
+
violation(
|
|
207
|
+
"print_style_pdf_only",
|
|
208
|
+
selector,
|
|
209
|
+
`Print styling (${selector}) is only allowed in layouts of kind pdf-layout`,
|
|
210
|
+
),
|
|
211
|
+
),
|
|
212
|
+
};
|
|
213
|
+
}
|
|
214
|
+
|
|
177
215
|
function fromLayoutResult(result: SanitizeLayoutResult): SanitizeBodyResult {
|
|
178
216
|
return result.ok ? { ok: true, content: result.html } : result;
|
|
179
217
|
}
|
|
@@ -33,7 +33,9 @@ function moveRepeatHeadersIntoThead(table: ScanElement): void {
|
|
|
33
33
|
row.removeAttribute(REPEAT_HEADER_ATTRIBUTE);
|
|
34
34
|
thead.appendChild(row);
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
// A colgroup has to stay the first child of the table.
|
|
37
|
+
const colgroup = Array.from(table.children).find((child) => child.tagName === "COLGROUP");
|
|
38
|
+
table.insertBefore(thead, colgroup === undefined ? table.firstChild : colgroup.nextSibling);
|
|
37
39
|
}
|
|
38
40
|
|
|
39
41
|
export function prepareDocumentForPrint(html: string): string {
|