adula 2.1.0 → 2.2.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/README.md +149 -18
- package/build/agent/AGENTS.template.md +4 -4
- package/build/agent/capabilities.md +22 -11
- package/build/agent/skills/adula-frontend-design/SKILL.md +1 -1
- package/build/agent/skills/idea-review/SKILL.md +2 -2
- package/build/commands/adula_outbox.d.ts +10 -0
- package/build/commands/adula_outbox.js +11 -0
- package/build/commands/adula_restore_reconcile.d.ts +10 -0
- package/build/commands/adula_restore_reconcile.js +34 -0
- package/build/commands/adula_runtime_health.d.ts +10 -0
- package/build/commands/adula_runtime_health.js +27 -0
- package/build/commands/adula_uploads_prune.d.ts +10 -0
- package/build/commands/adula_uploads_prune.js +16 -0
- package/build/commands/app.d.ts +10 -0
- package/build/commands/app.js +64 -0
- package/build/commands/backup_create.d.ts +11 -0
- package/build/commands/backup_create.js +99 -0
- package/build/commands/backup_restore_files.d.ts +11 -0
- package/build/commands/backup_restore_files.js +44 -0
- package/build/commands/backup_restore_test.d.ts +12 -0
- package/build/commands/backup_restore_test.js +185 -0
- package/build/commands/backup_services.d.ts +31 -0
- package/build/commands/backup_services.js +6 -0
- package/build/commands/backup_verify.d.ts +9 -0
- package/build/commands/backup_verify.js +59 -0
- package/build/commands/backup_verify_snapshot.d.ts +10 -0
- package/build/commands/backup_verify_snapshot.js +37 -0
- package/build/commands/client.d.ts +16 -0
- package/build/commands/client.js +71 -0
- package/build/commands/doctor.js +4 -1
- package/build/commands/install.d.ts +8 -0
- package/build/commands/install.js +63 -45
- package/build/commands/main.d.ts +3 -2
- package/build/commands/main.js +26 -0
- package/build/commands/module_add.js +4 -20
- package/build/commands/resource.d.ts +2 -0
- package/build/commands/resource.js +12 -3
- package/build/commands/resource_migration.d.ts +15 -0
- package/build/commands/resource_migration.js +72 -0
- package/build/commands/resource_snapshot.d.ts +2 -0
- package/build/commands/resource_snapshot.js +3 -0
- package/build/commands/sla_evaluate.d.ts +14 -0
- package/build/commands/sla_evaluate.js +16 -0
- package/build/commands/ui.js +4 -2
- package/build/commands/ui_css.d.ts +9 -0
- package/build/commands/ui_css.js +19 -0
- package/build/commands/upgrade.d.ts +1 -1
- package/build/commands/upgrade.js +1 -1
- package/build/configure.js +1 -1
- package/build/database/migrations/1770000000020_two_factor.d.ts +5 -0
- package/build/database/migrations/1770000000020_two_factor.js +10 -0
- package/build/database/migrations/1770000000041_import_modes.d.ts +5 -0
- package/build/database/migrations/1770000000041_import_modes.js +10 -0
- package/build/database/migrations/1770000000042_sync_jobs.d.ts +5 -0
- package/build/database/migrations/1770000000042_sync_jobs.js +10 -0
- package/build/database/migrations/1770000000043_notification_channels.d.ts +5 -0
- package/build/database/migrations/1770000000043_notification_channels.js +10 -0
- package/build/database/migrations/1770000000044_channel_confirmations.d.ts +5 -0
- package/build/database/migrations/1770000000044_channel_confirmations.js +10 -0
- package/build/database/migrations/1770000000045_import_leases.d.ts +5 -0
- package/build/database/migrations/1770000000045_import_leases.js +10 -0
- package/build/database/migrations/1770000000046_workflow_delegation_sla.d.ts +5 -0
- package/build/database/migrations/1770000000046_workflow_delegation_sla.js +10 -0
- package/build/database/migrations/1770000000049_print_templates.d.ts +5 -0
- package/build/database/migrations/1770000000049_print_templates.js +10 -0
- package/build/index.d.ts +56 -10
- package/build/index.js +34 -6
- package/build/providers/adula_provider.d.ts +2 -0
- package/build/providers/adula_provider.js +7 -0
- package/build/src/admin/contracts.js +1 -1
- package/build/src/admin/controller.d.ts +14 -1
- package/build/src/admin/controller.js +77 -13
- package/build/src/admin/errors.d.ts +32 -0
- package/build/src/admin/errors.js +63 -1
- package/build/src/admin/presentation.d.ts +21 -2
- package/build/src/admin/resource/editor.d.ts +59 -0
- package/build/src/admin/resource/editor.js +323 -0
- package/build/src/admin/resource/export.d.ts +37 -0
- package/build/src/admin/resource/export.js +181 -0
- package/build/src/admin/resource/lifecycle.d.ts +21 -0
- package/build/src/admin/resource/lifecycle.js +91 -0
- package/build/src/admin/resource/query.d.ts +100 -0
- package/build/src/admin/resource/query.js +508 -0
- package/build/src/admin/resource/read.d.ts +106 -0
- package/build/src/admin/resource/read.js +327 -0
- package/build/src/admin/resource/shared.d.ts +77 -0
- package/build/src/admin/resource/shared.js +222 -0
- package/build/src/admin/resource/trash.d.ts +10 -0
- package/build/src/admin/resource/trash.js +56 -0
- package/build/src/admin/resource/write.d.ts +57 -0
- package/build/src/admin/resource/write.js +574 -0
- package/build/src/admin/resource_service.d.ts +66 -193
- package/build/src/admin/resource_service.js +69 -1345
- package/build/src/attachments/attachment_service.d.ts +46 -2
- package/build/src/attachments/attachment_service.js +96 -4
- package/build/src/auth/conditions.d.ts +5 -0
- package/build/src/auth/conditions.js +26 -3
- package/build/src/auth/sql.js +17 -5
- package/build/src/auth/two_factor.d.ts +96 -0
- package/build/src/auth/two_factor.js +259 -0
- package/build/src/collaboration/assignments.d.ts +36 -1
- package/build/src/collaboration/assignments.js +132 -66
- package/build/src/collaboration/record_collaboration.d.ts +2 -3
- package/build/src/collaboration/record_collaboration.js +19 -16
- package/build/src/collaboration/shared.d.ts +16 -0
- package/build/src/collaboration/shared.js +21 -0
- package/build/src/commands/app_scaffold.d.ts +72 -0
- package/build/src/commands/app_scaffold.js +285 -0
- package/build/src/commands/capabilities.js +34 -8
- package/build/src/commands/doctor.d.ts +14 -2
- package/build/src/commands/doctor.js +50 -5
- package/build/src/commands/gap_report.d.ts +1 -1
- package/build/src/commands/gap_report.js +2 -2
- package/build/src/commands/generator.d.ts +37 -1
- package/build/src/commands/generator.js +61 -18
- package/build/src/commands/snapshot.d.ts +10 -13
- package/build/src/commands/snapshot.js +31 -14
- package/build/src/commands/source_markers.d.ts +10 -0
- package/build/src/commands/source_markers.js +29 -0
- package/build/src/core/activity.d.ts +2 -0
- package/build/src/core/activity.js +7 -1
- package/build/src/core/administrators.d.ts +38 -0
- package/build/src/core/administrators.js +129 -0
- package/build/src/core/html_sanitizer.d.ts +20 -0
- package/build/src/core/html_sanitizer.js +261 -0
- package/build/src/core/like.d.ts +5 -0
- package/build/src/core/like.js +5 -0
- package/build/src/core/lookups.d.ts +80 -0
- package/build/src/core/lookups.js +319 -0
- package/build/src/core/message_templates.d.ts +7 -2
- package/build/src/core/message_templates.js +72 -11
- package/build/src/core/module_seed.js +2 -1
- package/build/src/core/notification_channels.d.ts +235 -0
- package/build/src/core/notification_channels.js +660 -0
- package/build/src/core/roles.js +2 -2
- package/build/src/core/saved_views.d.ts +8 -1
- package/build/src/core/saved_views.js +36 -2
- package/build/src/core/sequences.d.ts +32 -0
- package/build/src/core/sequences.js +97 -0
- package/build/src/core/settings.d.ts +5 -0
- package/build/src/core/settings.js +19 -2
- package/build/src/core/template_language.d.ts +61 -0
- package/build/src/core/template_language.js +141 -0
- package/build/src/core/ui_preferences.d.ts +4 -0
- package/build/src/core/ui_preferences.js +4 -1
- package/build/src/core/user_invitations.d.ts +5 -1
- package/build/src/core/user_invitations.js +7 -1
- package/build/src/core/users.js +1 -1
- package/build/src/database/calendar_days.d.ts +19 -0
- package/build/src/database/calendar_days.js +36 -0
- package/build/src/database/schema.d.ts +155 -2
- package/build/src/database/schema.js +531 -59
- package/build/src/database/schema_diff.d.ts +56 -0
- package/build/src/database/schema_diff.js +157 -0
- package/build/src/events/record_mutation.d.ts +2 -1
- package/build/src/events/record_mutation.js +1 -0
- package/build/src/integrations/api_client.d.ts +37 -0
- package/build/src/integrations/api_client.js +552 -0
- package/build/src/integrations/import_adapters.d.ts +37 -0
- package/build/src/integrations/import_adapters.js +35 -0
- package/build/src/integrations/imports.d.ts +118 -16
- package/build/src/integrations/imports.js +406 -73
- package/build/src/integrations/openapi.d.ts +3 -1
- package/build/src/integrations/openapi.js +454 -31
- package/build/src/integrations/outbound.d.ts +51 -0
- package/build/src/integrations/outbound.js +195 -0
- package/build/src/integrations/print.d.ts +21 -1
- package/build/src/integrations/print.js +63 -21
- package/build/src/integrations/print_templates.d.ts +216 -0
- package/build/src/integrations/print_templates.js +1015 -0
- package/build/src/integrations/sync_jobs.d.ts +139 -0
- package/build/src/integrations/sync_jobs.js +416 -0
- package/build/src/integrations/webhooks.d.ts +12 -12
- package/build/src/integrations/webhooks.js +34 -43
- package/build/src/languages/ar.d.ts +11 -0
- package/build/src/languages/ar.js +336 -0
- package/build/src/languages/ar_ui.d.ts +332 -0
- package/build/src/languages/ar_ui.js +333 -0
- package/build/src/languages/catalog.d.ts +66 -0
- package/build/src/languages/catalog.js +152 -0
- package/build/src/languages/en.d.ts +7 -0
- package/build/src/languages/en.js +330 -0
- package/build/src/languages/en_ui.d.ts +3 -0
- package/build/src/languages/en_ui.js +328 -0
- package/build/src/languages/validation.d.ts +26 -0
- package/build/src/languages/validation.js +60 -0
- package/build/src/lists/bulk_actions.d.ts +89 -0
- package/build/src/lists/bulk_actions.js +268 -0
- package/build/src/lists/dashboards.d.ts +96 -0
- package/build/src/lists/dashboards.js +241 -0
- package/build/src/mcp/tools.js +1 -1
- package/build/src/resource/define_resource.d.ts +18 -1
- package/build/src/resource/define_resource.js +205 -18
- package/build/src/resource/definition.d.ts +44 -0
- package/build/src/resource/definition.js +171 -0
- package/build/src/resource/registry.js +15 -4
- package/build/src/resource/types.d.ts +304 -16
- package/build/src/resource/values.d.ts +56 -1
- package/build/src/resource/values.js +237 -5
- package/build/src/services/settings.d.ts +2 -0
- package/build/src/services/settings.js +5 -1
- package/build/src/upgrade/legacy.js +2 -2
- package/build/src/workflows/calendar.d.ts +9 -0
- package/build/src/workflows/calendar.js +44 -0
- package/build/src/workflows/define_workflow.d.ts +48 -3
- package/build/src/workflows/define_workflow.js +57 -13
- package/build/src/workflows/delegations.d.ts +93 -0
- package/build/src/workflows/delegations.js +287 -0
- package/build/src/workflows/engine.d.ts +69 -4
- package/build/src/workflows/engine.js +441 -83
- package/build/src/workflows/sla.d.ts +15 -0
- package/build/src/workflows/sla.js +8 -0
- package/build/stubs/resource_contract.txt +12 -1
- package/package.json +5 -2
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/** A validated address the outbound connection is pinned to. */
|
|
2
|
+
export type OutboundTarget = {
|
|
3
|
+
address: string;
|
|
4
|
+
family: 4 | 6;
|
|
5
|
+
};
|
|
6
|
+
export type OutboundOptions = {
|
|
7
|
+
/** Allow http:// and private or loopback addresses (explicit opt-in only). */
|
|
8
|
+
allowPrivateTargets?: boolean;
|
|
9
|
+
/** Hostname resolution; replaceable in tests. */
|
|
10
|
+
resolve?: (host: string) => Promise<string[]>;
|
|
11
|
+
};
|
|
12
|
+
export type OutboundRequest = {
|
|
13
|
+
headers: Record<string, string>;
|
|
14
|
+
body: string;
|
|
15
|
+
signal: AbortSignal;
|
|
16
|
+
/** The address validated before the request; the connection must use it. */
|
|
17
|
+
target?: OutboundTarget;
|
|
18
|
+
};
|
|
19
|
+
/** Stored failure categories; raw error messages and response bodies are never kept. */
|
|
20
|
+
export type OutboundErrorCategory = 'dns' | 'connect' | 'tls' | 'timeout' | 'blocked-target' | 'secret' | `http-status:${number}`;
|
|
21
|
+
/** Raised when a target is not allowed or cannot be resolved. */
|
|
22
|
+
export declare class OutboundTargetError extends Error {
|
|
23
|
+
category: 'blocked-target' | 'dns';
|
|
24
|
+
constructor(category: 'blocked-target' | 'dns');
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* True when an IP literal is not a public unicast address. IPv4-mapped and
|
|
28
|
+
* NAT64 (64:ff9b::/96) addresses are checked by the IPv4 address they embed.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isBlockedAddress(address: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Resolves a URL's host once and returns the address to pin the connection to.
|
|
33
|
+
* Every resolved address must be public unless private targets are allowed.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveOutboundTarget(url: URL, options?: OutboundOptions): Promise<OutboundTarget>;
|
|
36
|
+
/** Sends a POST whose TCP connection goes to the pinned address; redirects are not followed. */
|
|
37
|
+
export declare function pinnedPost(url: URL, init: OutboundRequest & {
|
|
38
|
+
target: OutboundTarget;
|
|
39
|
+
}): Promise<{
|
|
40
|
+
status: number;
|
|
41
|
+
}>;
|
|
42
|
+
/**
|
|
43
|
+
* The guarded outbound HTTP client: validates the URL, resolves its host once,
|
|
44
|
+
* refuses private targets unless allowed and connects to the validated address.
|
|
45
|
+
* A `target` supplied by the caller (already validated) is used as-is.
|
|
46
|
+
*/
|
|
47
|
+
export declare function createOutboundPoster(options?: OutboundOptions): (value: string, init: OutboundRequest) => Promise<{
|
|
48
|
+
status: number;
|
|
49
|
+
}>;
|
|
50
|
+
/** Maps a delivery failure to a stored category without keeping its message. */
|
|
51
|
+
export declare function outboundErrorCategory(error: unknown): OutboundErrorCategory;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { lookup } from 'node:dns/promises';
|
|
2
|
+
import { request as httpRequest } from 'node:http';
|
|
3
|
+
import { request as httpsRequest } from 'node:https';
|
|
4
|
+
import { BlockList, isIP } from 'node:net';
|
|
5
|
+
/** Raised when a target is not allowed or cannot be resolved. */
|
|
6
|
+
export class OutboundTargetError extends Error {
|
|
7
|
+
category;
|
|
8
|
+
constructor(category) {
|
|
9
|
+
super(category === 'dns' ? 'Target host cannot be resolved' : 'Target address is not allowed');
|
|
10
|
+
this.category = category;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
// IANA special-purpose and non-public ranges.
|
|
14
|
+
const IPV4_BLOCKED = [
|
|
15
|
+
['0.0.0.0', 8],
|
|
16
|
+
['10.0.0.0', 8],
|
|
17
|
+
['100.64.0.0', 10],
|
|
18
|
+
['127.0.0.0', 8],
|
|
19
|
+
['169.254.0.0', 16],
|
|
20
|
+
['172.16.0.0', 12],
|
|
21
|
+
['192.0.0.0', 24],
|
|
22
|
+
['192.0.2.0', 24],
|
|
23
|
+
['192.88.99.0', 24],
|
|
24
|
+
['192.31.196.0', 24], // AS112
|
|
25
|
+
['192.52.193.0', 24], // AMT
|
|
26
|
+
['192.168.0.0', 16],
|
|
27
|
+
['192.175.48.0', 24], // AS112 direct delegation
|
|
28
|
+
['198.18.0.0', 15],
|
|
29
|
+
['198.51.100.0', 24],
|
|
30
|
+
['203.0.113.0', 24],
|
|
31
|
+
['224.0.0.0', 4],
|
|
32
|
+
['240.0.0.0', 4],
|
|
33
|
+
];
|
|
34
|
+
const IPV6_BLOCKED = [
|
|
35
|
+
['::', 96], // unspecified, loopback and deprecated IPv4-compatible addresses
|
|
36
|
+
['64:ff9b:1::', 48], // local-use NAT64
|
|
37
|
+
['100::', 64], // discard-only
|
|
38
|
+
['2001::', 23], // IETF protocol assignments, including Teredo
|
|
39
|
+
['2001:db8::', 32], // documentation
|
|
40
|
+
['2002::', 16], // 6to4 can tunnel to any IPv4 address
|
|
41
|
+
['3fff::', 20], // documentation
|
|
42
|
+
['5f00::', 16], // SRv6 SIDs
|
|
43
|
+
['fc00::', 7], // unique local
|
|
44
|
+
['fe80::', 10], // link-local
|
|
45
|
+
['fec0::', 10], // deprecated site-local
|
|
46
|
+
['ff00::', 8], // multicast
|
|
47
|
+
];
|
|
48
|
+
const ipv4Blocked = new BlockList();
|
|
49
|
+
for (const [network, prefix] of IPV4_BLOCKED)
|
|
50
|
+
ipv4Blocked.addSubnet(network, prefix, 'ipv4');
|
|
51
|
+
ipv4Blocked.addAddress('255.255.255.255', 'ipv4');
|
|
52
|
+
const ipv6Blocked = new BlockList();
|
|
53
|
+
for (const [network, prefix] of IPV6_BLOCKED)
|
|
54
|
+
ipv6Blocked.addSubnet(network, prefix, 'ipv6');
|
|
55
|
+
/** Expands an IPv6 address (optionally with a dotted IPv4 tail) to eight 16-bit groups. */
|
|
56
|
+
function ipv6Groups(address) {
|
|
57
|
+
let value = address.toLowerCase().split('%')[0];
|
|
58
|
+
const dotted = value.match(/(\d+\.\d+\.\d+\.\d+)$/);
|
|
59
|
+
if (dotted) {
|
|
60
|
+
const octets = dotted[1].split('.').map(Number);
|
|
61
|
+
value =
|
|
62
|
+
value.slice(0, -dotted[1].length) +
|
|
63
|
+
`${((octets[0] << 8) | octets[1]).toString(16)}:${((octets[2] << 8) | octets[3]).toString(16)}`;
|
|
64
|
+
}
|
|
65
|
+
const [head, tail] = value.split('::');
|
|
66
|
+
const left = head ? head.split(':') : [];
|
|
67
|
+
const right = tail ? tail.split(':') : [];
|
|
68
|
+
const missing = 8 - left.length - right.length;
|
|
69
|
+
if (value.includes('::') ? missing < 1 : missing !== 0)
|
|
70
|
+
return null;
|
|
71
|
+
const groups = [...left, ...Array(value.includes('::') ? missing : 0).fill('0'), ...right].map((group) => Number.parseInt(group, 16));
|
|
72
|
+
return groups.length === 8 && groups.every((group) => group >= 0 && group <= 0xffff)
|
|
73
|
+
? groups
|
|
74
|
+
: null;
|
|
75
|
+
}
|
|
76
|
+
function embeddedIPv4(groups) {
|
|
77
|
+
return [groups[6] >> 8, groups[6] & 0xff, groups[7] >> 8, groups[7] & 0xff].join('.');
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* True when an IP literal is not a public unicast address. IPv4-mapped and
|
|
81
|
+
* NAT64 (64:ff9b::/96) addresses are checked by the IPv4 address they embed.
|
|
82
|
+
*/
|
|
83
|
+
export function isBlockedAddress(address) {
|
|
84
|
+
const value = address.replace(/^\[|\]$/g, '');
|
|
85
|
+
const version = isIP(value);
|
|
86
|
+
if (version === 4)
|
|
87
|
+
return ipv4Blocked.check(value, 'ipv4');
|
|
88
|
+
if (version !== 6)
|
|
89
|
+
return true;
|
|
90
|
+
const groups = ipv6Groups(value);
|
|
91
|
+
if (!groups)
|
|
92
|
+
return true;
|
|
93
|
+
const prefix96 = groups.slice(0, 6);
|
|
94
|
+
// IPv4-mapped ::ffff:0:0/96 and IPv4-translated ::ffff:0:0:0/96.
|
|
95
|
+
if (prefix96.every((group, index) => group === (index === 5 ? 0xffff : 0)))
|
|
96
|
+
return isBlockedAddress(embeddedIPv4(groups));
|
|
97
|
+
if (prefix96.every((group, index) => group === (index === 4 ? 0xffff : 0)))
|
|
98
|
+
return isBlockedAddress(embeddedIPv4(groups));
|
|
99
|
+
if (groups[0] === 0x64 && groups[1] === 0xff9b && prefix96.slice(2).every((group) => group === 0))
|
|
100
|
+
return isBlockedAddress(embeddedIPv4(groups));
|
|
101
|
+
return ipv6Blocked.check(groups.map((group) => group.toString(16)).join(':'), 'ipv6');
|
|
102
|
+
}
|
|
103
|
+
const defaultResolve = async (host) => {
|
|
104
|
+
const entries = await lookup(host, { all: true });
|
|
105
|
+
return entries.map((entry) => entry.address);
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* Resolves a URL's host once and returns the address to pin the connection to.
|
|
109
|
+
* Every resolved address must be public unless private targets are allowed.
|
|
110
|
+
*/
|
|
111
|
+
export async function resolveOutboundTarget(url, options = {}) {
|
|
112
|
+
const host = url.hostname.replace(/^\[|\]$/g, '');
|
|
113
|
+
let addresses;
|
|
114
|
+
if (isIP(host))
|
|
115
|
+
addresses = [host];
|
|
116
|
+
else {
|
|
117
|
+
try {
|
|
118
|
+
addresses = await (options.resolve ?? defaultResolve)(host);
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
throw new OutboundTargetError('dns');
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!addresses.length || addresses.some((address) => !isIP(address)))
|
|
125
|
+
throw new OutboundTargetError('dns');
|
|
126
|
+
if (options.allowPrivateTargets !== true && addresses.some(isBlockedAddress))
|
|
127
|
+
throw new OutboundTargetError('blocked-target');
|
|
128
|
+
const [address] = addresses;
|
|
129
|
+
return { address, family: isIP(address) === 6 ? 6 : 4 };
|
|
130
|
+
}
|
|
131
|
+
/** Sends a POST whose TCP connection goes to the pinned address; redirects are not followed. */
|
|
132
|
+
export function pinnedPost(url, init) {
|
|
133
|
+
const { address, family } = init.target;
|
|
134
|
+
const pinnedLookup = (_host, options, callback) => {
|
|
135
|
+
if (options.all)
|
|
136
|
+
callback(null, [{ address, family }]);
|
|
137
|
+
else
|
|
138
|
+
callback(null, address, family);
|
|
139
|
+
};
|
|
140
|
+
const host = url.hostname.replace(/^\[|\]$/g, '');
|
|
141
|
+
const send = url.protocol === 'https:' ? httpsRequest : httpRequest;
|
|
142
|
+
return new Promise((resolve, reject) => {
|
|
143
|
+
const request = send(url, {
|
|
144
|
+
method: 'POST',
|
|
145
|
+
headers: { ...init.headers, 'Content-Length': String(Buffer.byteLength(init.body)) },
|
|
146
|
+
lookup: pinnedLookup,
|
|
147
|
+
servername: isIP(host) ? undefined : host,
|
|
148
|
+
signal: init.signal,
|
|
149
|
+
}, (response) => {
|
|
150
|
+
// The body is never read or stored.
|
|
151
|
+
response.resume();
|
|
152
|
+
resolve({ status: response.statusCode ?? 0 });
|
|
153
|
+
});
|
|
154
|
+
request.on('error', reject);
|
|
155
|
+
request.end(init.body);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* The guarded outbound HTTP client: validates the URL, resolves its host once,
|
|
160
|
+
* refuses private targets unless allowed and connects to the validated address.
|
|
161
|
+
* A `target` supplied by the caller (already validated) is used as-is.
|
|
162
|
+
*/
|
|
163
|
+
export function createOutboundPoster(options = {}) {
|
|
164
|
+
return async (value, init) => {
|
|
165
|
+
const url = new URL(value);
|
|
166
|
+
if (url.protocol !== 'https:' && !(options.allowPrivateTargets && url.protocol === 'http:'))
|
|
167
|
+
throw new OutboundTargetError('blocked-target');
|
|
168
|
+
if (url.username || url.password)
|
|
169
|
+
throw new OutboundTargetError('blocked-target');
|
|
170
|
+
const target = init.target ?? (await resolveOutboundTarget(url, options));
|
|
171
|
+
if (options.allowPrivateTargets !== true && isBlockedAddress(target.address))
|
|
172
|
+
throw new OutboundTargetError('blocked-target');
|
|
173
|
+
return pinnedPost(url, { ...init, target });
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
const TLS_CODES = /^(ERR_TLS|ERR_SSL|CERT_|UNABLE_TO_|DEPTH_ZERO|SELF_SIGNED|HOSTNAME_MISMATCH)/;
|
|
177
|
+
const DNS_CODES = new Set(['ENOTFOUND', 'EAI_AGAIN', 'EAI_FAIL', 'ENODATA', 'ESERVFAIL']);
|
|
178
|
+
/** Maps a delivery failure to a stored category without keeping its message. */
|
|
179
|
+
export function outboundErrorCategory(error) {
|
|
180
|
+
for (let current = error, depth = 0; current && depth < 5; depth++) {
|
|
181
|
+
if (current instanceof OutboundTargetError)
|
|
182
|
+
return current.category;
|
|
183
|
+
const { name, code } = current;
|
|
184
|
+
if (name === 'TimeoutError' || name === 'AbortError' || code === 'ABORT_ERR')
|
|
185
|
+
return 'timeout';
|
|
186
|
+
if (code === 'ETIMEDOUT' || code === 'UND_ERR_CONNECT_TIMEOUT')
|
|
187
|
+
return 'timeout';
|
|
188
|
+
if (code && DNS_CODES.has(code))
|
|
189
|
+
return 'dns';
|
|
190
|
+
if (code && TLS_CODES.test(code))
|
|
191
|
+
return 'tls';
|
|
192
|
+
current = current.cause;
|
|
193
|
+
}
|
|
194
|
+
return 'connect';
|
|
195
|
+
}
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { ResourceDescription } from '../admin/presentation.js';
|
|
2
|
-
import type { SerializedRecord } from '../resource/types.js';
|
|
2
|
+
import type { JsonValue, SerializedRecord } from '../resource/types.js';
|
|
3
|
+
/**
|
|
4
|
+
* `logoUrl` must be a base64 image data URI (see imageDataUri). Any other URL is
|
|
5
|
+
* dropped: the PDF renderer would fetch it from inside the deployment network.
|
|
6
|
+
*/
|
|
3
7
|
export type PrintIdentity = {
|
|
4
8
|
name: string;
|
|
5
9
|
logoUrl?: string | null;
|
|
6
10
|
};
|
|
11
|
+
/** Largest logo inlined into printed documents. */
|
|
12
|
+
export declare const PRINT_LOGO_LIMIT: number;
|
|
13
|
+
/** Inlines a logo file as a data URI for printing; null for unknown types or oversize files. */
|
|
14
|
+
export declare function imageDataUri(bytes: Uint8Array, fileName: string): string | null;
|
|
7
15
|
export type PrintInput = {
|
|
8
16
|
identity: PrintIdentity;
|
|
9
17
|
resource: ResourceDescription;
|
|
@@ -20,6 +28,18 @@ export type PrintInput = {
|
|
|
20
28
|
printedBy: string;
|
|
21
29
|
printedAt?: Date;
|
|
22
30
|
};
|
|
31
|
+
/** HTML-escapes text for printed documents (&, <, >, " and '). */
|
|
32
|
+
export declare const escapeHtml: (value: string) => string;
|
|
33
|
+
/**
|
|
34
|
+
* The label of a related record, as the UI's relationLabel: the server's `_title`, else
|
|
35
|
+
* (user rows) the first non-meta text value, else `#id`.
|
|
36
|
+
*/
|
|
37
|
+
export declare function relationTitle(rows: SerializedRecord[] | undefined, value: JsonValue | undefined): string;
|
|
38
|
+
/**
|
|
39
|
+
* The `<img>` of an inlined logo, or '' for anything that is not a bounded base64 image
|
|
40
|
+
* data URI: the PDF renderer must never fetch a URL (SSRF from its network).
|
|
41
|
+
*/
|
|
42
|
+
export declare function printLogoHtml(identity: PrintIdentity): string;
|
|
23
43
|
/**
|
|
24
44
|
* The generic printable view of one record: RTL A4 HTML, every value escaped.
|
|
25
45
|
* Only fields already serialized for the caller are printed, so printing can
|
|
@@ -1,9 +1,43 @@
|
|
|
1
|
-
const
|
|
1
|
+
const IMAGE_TYPES = {
|
|
2
|
+
png: 'image/png',
|
|
3
|
+
jpg: 'image/jpeg',
|
|
4
|
+
jpeg: 'image/jpeg',
|
|
5
|
+
gif: 'image/gif',
|
|
6
|
+
webp: 'image/webp',
|
|
7
|
+
svg: 'image/svg+xml',
|
|
8
|
+
};
|
|
9
|
+
const DATA_IMAGE = /^data:image\/(png|jpeg|gif|webp|svg\+xml);base64,[A-Za-z0-9+/]+={0,2}$/;
|
|
10
|
+
/** Largest logo inlined into printed documents. */
|
|
11
|
+
export const PRINT_LOGO_LIMIT = 512 * 1024;
|
|
12
|
+
/** Inlines a logo file as a data URI for printing; null for unknown types or oversize files. */
|
|
13
|
+
export function imageDataUri(bytes, fileName) {
|
|
14
|
+
const type = IMAGE_TYPES[fileName.split('.').pop()?.toLowerCase() ?? ''];
|
|
15
|
+
if (!type || !bytes.byteLength || bytes.byteLength > PRINT_LOGO_LIMIT)
|
|
16
|
+
return null;
|
|
17
|
+
return `data:${type};base64,${Buffer.from(bytes).toString('base64')}`;
|
|
18
|
+
}
|
|
19
|
+
/** HTML-escapes text for printed documents (&, <, >, " and '). */
|
|
20
|
+
export const escapeHtml = (value) => value
|
|
2
21
|
.replaceAll('&', '&')
|
|
3
22
|
.replaceAll('<', '<')
|
|
4
23
|
.replaceAll('>', '>')
|
|
5
24
|
.replaceAll('"', '"')
|
|
6
25
|
.replaceAll("'", ''');
|
|
26
|
+
const RELATION_META = new Set(['id', 'version', 'docStatus', 'orgUnitId']);
|
|
27
|
+
/**
|
|
28
|
+
* The label of a related record, as the UI's relationLabel: the server's `_title`, else
|
|
29
|
+
* (user rows) the first non-meta text value, else `#id`.
|
|
30
|
+
*/
|
|
31
|
+
export function relationTitle(rows, value) {
|
|
32
|
+
const fallback = value === null || value === undefined ? '—' : `#${String(value)}`;
|
|
33
|
+
const row = rows?.find((entry) => String(entry.id) === String(value));
|
|
34
|
+
if (!row)
|
|
35
|
+
return fallback;
|
|
36
|
+
if ('_title' in row)
|
|
37
|
+
return typeof row._title === 'string' && row._title ? row._title : fallback;
|
|
38
|
+
const label = Object.entries(row).find(([key, entry]) => !RELATION_META.has(key) && typeof entry === 'string' && entry);
|
|
39
|
+
return label ? String(label[1]) : fallback;
|
|
40
|
+
}
|
|
7
41
|
function text(field, value, input) {
|
|
8
42
|
if (value === null || value === undefined || value === '')
|
|
9
43
|
return '—';
|
|
@@ -21,15 +55,14 @@ function text(field, value, input) {
|
|
|
21
55
|
case 'lookup':
|
|
22
56
|
return (input.lookups?.[field.key]?.find((option) => option.value === value)?.label ?? String(value));
|
|
23
57
|
case 'user':
|
|
24
|
-
case 'belongsTo':
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
case 'attachment':
|
|
30
|
-
return typeof value === 'object' && !Array.isArray(value) && value.name
|
|
31
|
-
? String(value.name)
|
|
58
|
+
case 'belongsTo':
|
|
59
|
+
return relationTitle(input.related?.[field.key], value);
|
|
60
|
+
case 'attachment': {
|
|
61
|
+
const name = (entry) => entry && typeof entry === 'object' && !Array.isArray(entry) && 'name' in entry
|
|
62
|
+
? String(entry.name)
|
|
32
63
|
: 'مرفق';
|
|
64
|
+
return Array.isArray(value) ? value.map(name).join('، ') : name(value);
|
|
65
|
+
}
|
|
33
66
|
case 'datetime':
|
|
34
67
|
return new Date(String(value)).toLocaleString('ar-u-nu-latn-ca-gregory', { timeZone: 'UTC' });
|
|
35
68
|
case 'json':
|
|
@@ -38,6 +71,16 @@ function text(field, value, input) {
|
|
|
38
71
|
return String(value);
|
|
39
72
|
}
|
|
40
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* The `<img>` of an inlined logo, or '' for anything that is not a bounded base64 image
|
|
76
|
+
* data URI: the PDF renderer must never fetch a URL (SSRF from its network).
|
|
77
|
+
*/
|
|
78
|
+
export function printLogoHtml(identity) {
|
|
79
|
+
const logoUrl = identity.logoUrl;
|
|
80
|
+
return logoUrl && logoUrl.length <= PRINT_LOGO_LIMIT * 2 && DATA_IMAGE.test(logoUrl)
|
|
81
|
+
? `<img class="logo" src="${escapeHtml(logoUrl)}" alt="">`
|
|
82
|
+
: '';
|
|
83
|
+
}
|
|
41
84
|
/**
|
|
42
85
|
* The generic printable view of one record: RTL A4 HTML, every value escaped.
|
|
43
86
|
* Only fields already serialized for the caller are printed, so printing can
|
|
@@ -52,27 +95,26 @@ export function renderPrintHtml(input) {
|
|
|
52
95
|
? ['مسودة', 'معتمد', 'ملغي'][input.record.docStatus]
|
|
53
96
|
: null;
|
|
54
97
|
const rows = fields
|
|
55
|
-
.map((field) => `<tr><th scope="row">${
|
|
98
|
+
.map((field) => `<tr><th scope="row">${escapeHtml(field.label.ar)}</th><td>${escapeHtml(text(field, input.record[field.key], input))}</td></tr>`)
|
|
56
99
|
.join('');
|
|
57
100
|
const children = Object.entries(input.children ?? {})
|
|
58
101
|
.map(([key, group]) => {
|
|
59
102
|
const label = input.resource.fields.find((field) => field.key === key)?.label.ar ?? key;
|
|
60
103
|
const columns = group.fields.filter((field) => field.type !== 'hasMany');
|
|
61
|
-
return `<section><h2>${
|
|
62
|
-
.map((column) => `<th scope="col">${
|
|
104
|
+
return `<section><h2>${escapeHtml(label)}</h2><table class="lines"><thead><tr>${columns
|
|
105
|
+
.map((column) => `<th scope="col">${escapeHtml(column.label.ar)}</th>`)
|
|
63
106
|
.join('')}</tr></thead><tbody>${group.rows
|
|
64
|
-
.map((row) => `<tr>${columns.map((column) => `<td>${
|
|
107
|
+
.map((row) => `<tr>${columns.map((column) => `<td>${escapeHtml(text(column, row[column.key], input))}</td>`).join('')}</tr>`)
|
|
65
108
|
.join('')}</tbody></table></section>`;
|
|
66
109
|
})
|
|
67
110
|
.join('');
|
|
68
|
-
const logo = input.identity
|
|
69
|
-
? `<img class="logo" src="${escape(input.identity.logoUrl)}" alt="">`
|
|
70
|
-
: '';
|
|
111
|
+
const logo = printLogoHtml(input.identity);
|
|
71
112
|
return `<!doctype html>
|
|
72
113
|
<html lang="ar" dir="rtl">
|
|
73
114
|
<head>
|
|
74
115
|
<meta charset="utf-8">
|
|
75
|
-
<
|
|
116
|
+
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">
|
|
117
|
+
<title>${escapeHtml(input.resource.label)} #${escapeHtml(String(input.record.id))}</title>
|
|
76
118
|
<style>
|
|
77
119
|
@page { size: A4; margin: 18mm 16mm; }
|
|
78
120
|
* { box-sizing: border-box; }
|
|
@@ -94,14 +136,14 @@ footer { margin-top: 10mm; color: #78716c; font-size: 9pt; }
|
|
|
94
136
|
<body>
|
|
95
137
|
<header>
|
|
96
138
|
<div>
|
|
97
|
-
<h1>${
|
|
98
|
-
<p>${
|
|
139
|
+
<h1>${escapeHtml(input.resource.label)} #${escapeHtml(String(input.record.id))}</h1>
|
|
140
|
+
<p>${escapeHtml(input.identity.name)}</p>
|
|
99
141
|
</div>
|
|
100
|
-
<div>${status ? `<span class="status">${
|
|
142
|
+
<div>${status ? `<span class="status">${escapeHtml(status)}</span>` : ''}${logo}</div>
|
|
101
143
|
</header>
|
|
102
144
|
<table class="fields"><tbody>${rows}</tbody></table>
|
|
103
145
|
${children}
|
|
104
|
-
<footer>طُبع بواسطة ${
|
|
146
|
+
<footer>طُبع بواسطة ${escapeHtml(input.printedBy)} في ${escapeHtml(printedAt.toISOString().slice(0, 16).replace('T', ' '))} UTC</footer>
|
|
105
147
|
</body>
|
|
106
148
|
</html>`;
|
|
107
149
|
}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import type { Actor } from '../auth/ability.js';
|
|
3
|
+
import type { ResourceService } from '../admin/resource_service.js';
|
|
4
|
+
import type { ResourceDescription, ResourceField } from '../admin/presentation.js';
|
|
5
|
+
import type { ResourceRegistry } from '../resource/registry.js';
|
|
6
|
+
import type { Field, Label, PrintOrientation, PrintPaper, PrintTemplate, Resource, SerializedRecord } from '../resource/types.js';
|
|
7
|
+
import { type TemplateNode } from '../core/template_language.js';
|
|
8
|
+
import { type CalendarPreference, type DigitsPreference } from '../core/ui_preferences.js';
|
|
9
|
+
import { type PrintIdentity } from './print.js';
|
|
10
|
+
/** The implicit template of every resource: the generic layout of renderPrintHtml. */
|
|
11
|
+
export declare const DEFAULT_PRINT_TEMPLATE = "default";
|
|
12
|
+
export declare const PRINT_PAPERS: readonly PrintPaper[];
|
|
13
|
+
export declare const PRINT_ORIENTATIONS: readonly PrintOrientation[];
|
|
14
|
+
/** Helpers a template may call; nothing else is callable. */
|
|
15
|
+
export declare const PRINT_HELPERS: readonly ["date", "money", "number", "digits", "label", "total"];
|
|
16
|
+
/** Document values addressable by bare name. */
|
|
17
|
+
export declare const PRINT_VALUES: readonly ["id", "resource", "template", "company", "status", "printedBy", "printedAt", "rowNumber", "logo"];
|
|
18
|
+
/** What a template may name: the resource's stored fields and its line groups' columns. */
|
|
19
|
+
export type PrintSchema = {
|
|
20
|
+
fields: Record<string, Field>;
|
|
21
|
+
groups: Record<string, Record<string, Field>>;
|
|
22
|
+
};
|
|
23
|
+
export type PrintTemplateSource = 'generic' | 'code' | 'custom';
|
|
24
|
+
export type PrintTemplateOption = {
|
|
25
|
+
key: string;
|
|
26
|
+
label: Label;
|
|
27
|
+
source: PrintTemplateSource;
|
|
28
|
+
};
|
|
29
|
+
export type PrintTemplateSummary = {
|
|
30
|
+
resource: string;
|
|
31
|
+
resourceLabel: string;
|
|
32
|
+
key: string;
|
|
33
|
+
label: string;
|
|
34
|
+
source: 'code' | 'custom';
|
|
35
|
+
/** The current version: an integer for custom templates, `code:<hash>` for code ones. */
|
|
36
|
+
version: string;
|
|
37
|
+
active: boolean;
|
|
38
|
+
paper: PrintPaper;
|
|
39
|
+
orientation: PrintOrientation;
|
|
40
|
+
updatedAt: string | null;
|
|
41
|
+
};
|
|
42
|
+
export type PrintTemplateDraft = {
|
|
43
|
+
label: string;
|
|
44
|
+
body: string;
|
|
45
|
+
paper: PrintPaper;
|
|
46
|
+
orientation: PrintOrientation;
|
|
47
|
+
header: string;
|
|
48
|
+
footer: string;
|
|
49
|
+
};
|
|
50
|
+
export type PrintTemplateDetail = PrintTemplateSummary & PrintTemplateDraft;
|
|
51
|
+
export type PrintTemplateVersion = PrintTemplateDraft & {
|
|
52
|
+
version: number;
|
|
53
|
+
createdBy: string | null;
|
|
54
|
+
createdAt: string;
|
|
55
|
+
};
|
|
56
|
+
export type PrintTemplateInput = {
|
|
57
|
+
key?: unknown;
|
|
58
|
+
label?: unknown;
|
|
59
|
+
body?: unknown;
|
|
60
|
+
paper?: unknown;
|
|
61
|
+
orientation?: unknown;
|
|
62
|
+
header?: unknown;
|
|
63
|
+
footer?: unknown;
|
|
64
|
+
active?: unknown;
|
|
65
|
+
/** Update only: the version the editor started from (optimistic lock, 409 on mismatch). */
|
|
66
|
+
expectedVersion?: unknown;
|
|
67
|
+
};
|
|
68
|
+
export type PrintOptions = {
|
|
69
|
+
identity: PrintIdentity;
|
|
70
|
+
printedBy: string;
|
|
71
|
+
printedAt?: Date;
|
|
72
|
+
/** Defaults to the stored ui.preferences (calendar and digits). */
|
|
73
|
+
calendar?: CalendarPreference;
|
|
74
|
+
digits?: DigitsPreference;
|
|
75
|
+
/** IANA zone of printed date-times and the print time; defaults to UTC. */
|
|
76
|
+
timeZone?: string;
|
|
77
|
+
};
|
|
78
|
+
export type PrintedDocument = {
|
|
79
|
+
html: string;
|
|
80
|
+
template: {
|
|
81
|
+
key: string;
|
|
82
|
+
version: string;
|
|
83
|
+
source: PrintTemplateSource;
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
/** Checks the printTemplates of one resource definition; called by defineResource. */
|
|
87
|
+
export declare function assertPrintTemplates(resource: Pick<Resource, 'name' | 'fields' | 'printTemplates'>): void;
|
|
88
|
+
/** Checks line columns of code templates against the child resources; called on register. */
|
|
89
|
+
export declare function assertPrintTemplateColumns(resource: Resource, registry: ResourceRegistry): void;
|
|
90
|
+
/** Most lines one printed group holds; a longer document is refused, never truncated. */
|
|
91
|
+
export declare const PRINT_LINE_LIMIT = 1000;
|
|
92
|
+
/**
|
|
93
|
+
* The hasMany fields a print may read: those the record exposes (`serialize`, or `list`
|
|
94
|
+
* and `show`) and those the resource's own code print templates declare. The resource
|
|
95
|
+
* author decides both; an administrator template cannot reach any other line group.
|
|
96
|
+
*/
|
|
97
|
+
export declare function printableGroups(resource: Resource): string[];
|
|
98
|
+
/** The names a template of this registered resource may use. */
|
|
99
|
+
export declare function printSchema(registry: ResourceRegistry, name: string): PrintSchema;
|
|
100
|
+
/**
|
|
101
|
+
* Refuses unknown names and helpers and misplaced values with a 422 E_PRINT_TEMPLATE.
|
|
102
|
+
* `text` mode (header and footer) allows only document values and record fields.
|
|
103
|
+
*/
|
|
104
|
+
export declare function checkTemplate(nodes: TemplateNode[], schema: PrintSchema, mode?: 'html' | 'text'): void;
|
|
105
|
+
/** A version label of a code template: a hash of its declaration, so a change is visible. */
|
|
106
|
+
export declare function codeTemplateVersion(template: PrintTemplate): string;
|
|
107
|
+
/** A record as one reader may read it: the input of renderTemplateDocument. */
|
|
108
|
+
export type PrintSource = {
|
|
109
|
+
/** The reader's description: only its fields are printable. */
|
|
110
|
+
resource: ResourceDescription;
|
|
111
|
+
record: SerializedRecord;
|
|
112
|
+
related?: Record<string, SerializedRecord[]>;
|
|
113
|
+
lookups?: Record<string, {
|
|
114
|
+
value: string;
|
|
115
|
+
label: string;
|
|
116
|
+
}[]>;
|
|
117
|
+
/** Line groups with the reader's description of the line resource. */
|
|
118
|
+
lines?: Record<string, {
|
|
119
|
+
label: Label;
|
|
120
|
+
fields: ResourceField[];
|
|
121
|
+
rows: SerializedRecord[];
|
|
122
|
+
related?: Record<string, SerializedRecord[]>;
|
|
123
|
+
lookups?: Record<string, {
|
|
124
|
+
value: string;
|
|
125
|
+
label: string;
|
|
126
|
+
}[]>;
|
|
127
|
+
}>;
|
|
128
|
+
};
|
|
129
|
+
/** What to print: administrator markup (`body`) or a code template (`code`). */
|
|
130
|
+
export type PrintLayout = {
|
|
131
|
+
title: string;
|
|
132
|
+
paper: PrintPaper;
|
|
133
|
+
orientation: PrintOrientation;
|
|
134
|
+
header?: string;
|
|
135
|
+
footer?: string;
|
|
136
|
+
} & ({
|
|
137
|
+
body: string;
|
|
138
|
+
} | {
|
|
139
|
+
code: PrintTemplate;
|
|
140
|
+
});
|
|
141
|
+
/**
|
|
142
|
+
* Renders a print template for one reader (ADR 048). A value prints only when its field
|
|
143
|
+
* is in the reader's description (`source.resource.fields`, `lines[*].fields`), even if
|
|
144
|
+
* the record object holds more; the markup is sanitized again and every value escaped.
|
|
145
|
+
*/
|
|
146
|
+
export declare function renderTemplateDocument(source: PrintSource, layout: PrintLayout, options: PrintOptions): string;
|
|
147
|
+
/**
|
|
148
|
+
* Print templates (ADR 048): code templates declared on resources, administrator
|
|
149
|
+
* templates stored with immutable versions in print_templates / print_template_versions,
|
|
150
|
+
* and the generic layout as the implicit `default`. Every print reads the record through
|
|
151
|
+
* ResourceService as the actor, so the printed values are those the record page shows.
|
|
152
|
+
*/
|
|
153
|
+
export declare class PrintTemplates {
|
|
154
|
+
private db;
|
|
155
|
+
private registry;
|
|
156
|
+
constructor(db: Knex, registry: ResourceRegistry);
|
|
157
|
+
private resource;
|
|
158
|
+
/** Every template of every registered resource, for the administration screen. */
|
|
159
|
+
list(): Promise<PrintTemplateSummary[]>;
|
|
160
|
+
private summary;
|
|
161
|
+
/** One administrator template with the content of its current version. */
|
|
162
|
+
get(name: string, key: string): Promise<PrintTemplateDetail>;
|
|
163
|
+
/** The version history of an administrator template, newest first. */
|
|
164
|
+
versions(name: string, key: string): Promise<PrintTemplateVersion[]>;
|
|
165
|
+
/**
|
|
166
|
+
* Checks and sanitizes a draft: the markup goes through sanitizePrintHtml, then every
|
|
167
|
+
* name and helper is checked against the resource. Returns the stored form.
|
|
168
|
+
*/
|
|
169
|
+
validate(name: string, input: PrintTemplateInput): PrintTemplateDraft;
|
|
170
|
+
/** Creates an administrator template at version 1; 409 when the key already exists. */
|
|
171
|
+
create(name: string, input: PrintTemplateInput, actorId: number): Promise<{
|
|
172
|
+
resource: string;
|
|
173
|
+
key: string;
|
|
174
|
+
version: number;
|
|
175
|
+
}>;
|
|
176
|
+
/**
|
|
177
|
+
* Saves a new version of an existing administrator template (404 when there is none).
|
|
178
|
+
* `active` keeps its stored value when the input leaves it out. `expectedVersion` must
|
|
179
|
+
* equal the current version, so a concurrent edit is refused (409) rather than lost.
|
|
180
|
+
*/
|
|
181
|
+
update(name: string, key: string, input: PrintTemplateInput, actorId: number): Promise<{
|
|
182
|
+
resource: string;
|
|
183
|
+
key: string;
|
|
184
|
+
version: number;
|
|
185
|
+
}>;
|
|
186
|
+
/** Versions are never changed; the template row points to the current one. */
|
|
187
|
+
private save;
|
|
188
|
+
/** Templates the actor may print a record of this resource with (403 without view). */
|
|
189
|
+
available(resources: ResourceService, name: string, actor: Actor): Promise<PrintTemplateOption[]>;
|
|
190
|
+
/** The record as the actor may read it, with its lines and display maps. */
|
|
191
|
+
/** The record, its lines and display maps as the actor may read them. */
|
|
192
|
+
private source;
|
|
193
|
+
private formatting;
|
|
194
|
+
/**
|
|
195
|
+
* Renders one record with a template (`default` for the generic layout). Call
|
|
196
|
+
* recordPrinted once the document was delivered (after a PDF conversion succeeded).
|
|
197
|
+
*/
|
|
198
|
+
print(resources: ResourceService, name: string, id: number, actor: Actor, options: PrintOptions & {
|
|
199
|
+
template?: string;
|
|
200
|
+
}): Promise<PrintedDocument>;
|
|
201
|
+
/**
|
|
202
|
+
* Records a `printed` activity on the record with the template key, version and format.
|
|
203
|
+
* Call it after the document was produced (HTML rendered, or PDF converted).
|
|
204
|
+
*/
|
|
205
|
+
recordPrinted(name: string, id: number, actor: Actor, template: PrintedDocument['template'], format: 'html' | 'pdf'): Promise<void>;
|
|
206
|
+
/**
|
|
207
|
+
* Renders an unsaved draft against a record the actor may read: `recordId`, or the
|
|
208
|
+
* newest record of the actor's list. Nothing is stored or audited.
|
|
209
|
+
*/
|
|
210
|
+
preview(resources: ResourceService, name: string, input: PrintTemplateInput, actor: Actor, options: PrintOptions & {
|
|
211
|
+
recordId?: number | null;
|
|
212
|
+
}): Promise<{
|
|
213
|
+
html: string;
|
|
214
|
+
recordId: number;
|
|
215
|
+
}>;
|
|
216
|
+
}
|