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,261 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-house allowlist sanitizer for administrator-written print markup (ADR 048). It is
|
|
3
|
+
* not a general HTML parser: it keeps a fixed set of structural tags and four attributes
|
|
4
|
+
* and drops everything else, so the output can only lay out escaped text.
|
|
5
|
+
*
|
|
6
|
+
* - Allowed tags: ALLOWED_TAGS. Any other tag is removed; the contents of DROPPED_WITH_CONTENT
|
|
7
|
+
* (script, style, iframe, svg, form, …) are removed with it.
|
|
8
|
+
* - Allowed attributes: class (word characters and dashes), colspan/rowspan (1–99),
|
|
9
|
+
* dir (rtl/ltr/auto) and style restricted by sanitizeStyle. Every other attribute,
|
|
10
|
+
* including on* handlers, href and src, is removed.
|
|
11
|
+
* - An attribute value with `&`, `\`, `{{` or `}}` is removed: entities and CSS escapes
|
|
12
|
+
* could hide a URL, and template values may not flow into attributes.
|
|
13
|
+
* - Comments, doctype and processing instructions are removed; a stray `<` becomes `<`.
|
|
14
|
+
* - Closing tags are balanced against the open allowed tags; unclosed ones are closed.
|
|
15
|
+
*/
|
|
16
|
+
export const ALLOWED_TAGS = new Set([
|
|
17
|
+
'div',
|
|
18
|
+
'section',
|
|
19
|
+
'header',
|
|
20
|
+
'footer',
|
|
21
|
+
'p',
|
|
22
|
+
'span',
|
|
23
|
+
'strong',
|
|
24
|
+
'em',
|
|
25
|
+
'b',
|
|
26
|
+
'i',
|
|
27
|
+
'u',
|
|
28
|
+
'br',
|
|
29
|
+
'hr',
|
|
30
|
+
'h1',
|
|
31
|
+
'h2',
|
|
32
|
+
'h3',
|
|
33
|
+
'h4',
|
|
34
|
+
'table',
|
|
35
|
+
'thead',
|
|
36
|
+
'tbody',
|
|
37
|
+
'tfoot',
|
|
38
|
+
'tr',
|
|
39
|
+
'th',
|
|
40
|
+
'td',
|
|
41
|
+
'ul',
|
|
42
|
+
'ol',
|
|
43
|
+
'li',
|
|
44
|
+
'small',
|
|
45
|
+
]);
|
|
46
|
+
const VOID = new Set(['br', 'hr']);
|
|
47
|
+
const DROPPED_WITH_CONTENT = new Set([
|
|
48
|
+
'script',
|
|
49
|
+
'style',
|
|
50
|
+
'iframe',
|
|
51
|
+
'frame',
|
|
52
|
+
'frameset',
|
|
53
|
+
'object',
|
|
54
|
+
'embed',
|
|
55
|
+
'applet',
|
|
56
|
+
'svg',
|
|
57
|
+
'math',
|
|
58
|
+
'template',
|
|
59
|
+
'noscript',
|
|
60
|
+
'noembed',
|
|
61
|
+
'noframes',
|
|
62
|
+
'textarea',
|
|
63
|
+
'title',
|
|
64
|
+
'select',
|
|
65
|
+
'form',
|
|
66
|
+
'button',
|
|
67
|
+
'xmp',
|
|
68
|
+
'plaintext',
|
|
69
|
+
'video',
|
|
70
|
+
'audio',
|
|
71
|
+
'canvas',
|
|
72
|
+
'picture',
|
|
73
|
+
'head',
|
|
74
|
+
]);
|
|
75
|
+
/** CSS properties a style attribute may set. Values are checked by CSS_VALUE. */
|
|
76
|
+
const CSS_PROPERTIES = new Set([
|
|
77
|
+
'color',
|
|
78
|
+
'background-color',
|
|
79
|
+
'font-size',
|
|
80
|
+
'font-weight',
|
|
81
|
+
'font-style',
|
|
82
|
+
'text-align',
|
|
83
|
+
'text-decoration',
|
|
84
|
+
'vertical-align',
|
|
85
|
+
'line-height',
|
|
86
|
+
'letter-spacing',
|
|
87
|
+
'white-space',
|
|
88
|
+
'direction',
|
|
89
|
+
'width',
|
|
90
|
+
'min-width',
|
|
91
|
+
'max-width',
|
|
92
|
+
'height',
|
|
93
|
+
'min-height',
|
|
94
|
+
'border',
|
|
95
|
+
'border-top',
|
|
96
|
+
'border-bottom',
|
|
97
|
+
'border-left',
|
|
98
|
+
'border-right',
|
|
99
|
+
'border-color',
|
|
100
|
+
'border-style',
|
|
101
|
+
'border-width',
|
|
102
|
+
'border-collapse',
|
|
103
|
+
'border-radius',
|
|
104
|
+
'margin',
|
|
105
|
+
'margin-top',
|
|
106
|
+
'margin-bottom',
|
|
107
|
+
'margin-left',
|
|
108
|
+
'margin-right',
|
|
109
|
+
'margin-inline-start',
|
|
110
|
+
'margin-inline-end',
|
|
111
|
+
'padding',
|
|
112
|
+
'padding-top',
|
|
113
|
+
'padding-bottom',
|
|
114
|
+
'padding-left',
|
|
115
|
+
'padding-right',
|
|
116
|
+
'padding-inline-start',
|
|
117
|
+
'padding-inline-end',
|
|
118
|
+
'page-break-before',
|
|
119
|
+
'page-break-after',
|
|
120
|
+
'page-break-inside',
|
|
121
|
+
'break-before',
|
|
122
|
+
'break-after',
|
|
123
|
+
'break-inside',
|
|
124
|
+
]);
|
|
125
|
+
/** Plain lengths, keywords, hex colours and rgb()/hsl() colours; no other function. */
|
|
126
|
+
const CSS_VALUE = /^[#%.,\w\s-]*$/;
|
|
127
|
+
const CSS_COLOR_FUNCTION = /\b(?:rgba?|hsla?)\(\s*[\d.%,\s]+\)/gi;
|
|
128
|
+
const CSS_FORBIDDEN = /url|expression|import|javascript|behavio|binding|image|attr|var|@|\/\/|:/i;
|
|
129
|
+
/** Longest style attribute kept; longer ones are dropped whole. */
|
|
130
|
+
const STYLE_LIMIT = 500;
|
|
131
|
+
/** A style attribute reduced to allowlisted properties with plain values; '' when none survive. */
|
|
132
|
+
export function sanitizeStyle(style) {
|
|
133
|
+
if (style.length > STYLE_LIMIT)
|
|
134
|
+
return '';
|
|
135
|
+
if (/[\\&<>"'`{}]|\/\*/.test(style))
|
|
136
|
+
return '';
|
|
137
|
+
const declarations = [];
|
|
138
|
+
for (const part of style.split(';')) {
|
|
139
|
+
const colon = part.indexOf(':');
|
|
140
|
+
if (colon === -1)
|
|
141
|
+
continue;
|
|
142
|
+
const property = part.slice(0, colon).trim().toLowerCase();
|
|
143
|
+
const value = part
|
|
144
|
+
.slice(colon + 1)
|
|
145
|
+
.trim()
|
|
146
|
+
.replace(/\s+/g, ' ');
|
|
147
|
+
if (!CSS_PROPERTIES.has(property) || !value || value.length > 200)
|
|
148
|
+
continue;
|
|
149
|
+
if (CSS_FORBIDDEN.test(value))
|
|
150
|
+
continue;
|
|
151
|
+
if (!CSS_VALUE.test(value.replace(CSS_COLOR_FUNCTION, 'color')))
|
|
152
|
+
continue;
|
|
153
|
+
declarations.push(`${property}: ${value}`);
|
|
154
|
+
}
|
|
155
|
+
return declarations.join('; ');
|
|
156
|
+
}
|
|
157
|
+
function attributeValue(name, value) {
|
|
158
|
+
if (/[&\\]|\{\{|\}\}/.test(value))
|
|
159
|
+
return null;
|
|
160
|
+
switch (name) {
|
|
161
|
+
case 'class':
|
|
162
|
+
return /^[\w\s-]{0,200}$/.test(value) ? value.trim().replace(/\s+/g, ' ') : null;
|
|
163
|
+
case 'colspan':
|
|
164
|
+
case 'rowspan':
|
|
165
|
+
return /^[1-9]\d?$/.test(value.trim()) ? value.trim() : null;
|
|
166
|
+
case 'dir':
|
|
167
|
+
return ['rtl', 'ltr', 'auto'].includes(value.trim().toLowerCase())
|
|
168
|
+
? value.trim().toLowerCase()
|
|
169
|
+
: null;
|
|
170
|
+
case 'style': {
|
|
171
|
+
const style = sanitizeStyle(value);
|
|
172
|
+
return style || null;
|
|
173
|
+
}
|
|
174
|
+
default:
|
|
175
|
+
return null;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const ATTRIBUTE = /([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g;
|
|
179
|
+
function attributes(source) {
|
|
180
|
+
const kept = [];
|
|
181
|
+
const seen = new Set();
|
|
182
|
+
for (const match of source.matchAll(ATTRIBUTE)) {
|
|
183
|
+
const name = match[1].toLowerCase();
|
|
184
|
+
if (seen.has(name))
|
|
185
|
+
continue;
|
|
186
|
+
seen.add(name);
|
|
187
|
+
const value = attributeValue(name, match[2] ?? match[3] ?? match[4] ?? '');
|
|
188
|
+
if (value !== null)
|
|
189
|
+
kept.push(` ${name}="${value.replaceAll('"', '"')}"`);
|
|
190
|
+
}
|
|
191
|
+
return kept.join('');
|
|
192
|
+
}
|
|
193
|
+
/** Text between tags: kept as written, except that a `>` is escaped. */
|
|
194
|
+
const text = (value) => value.replaceAll('>', '>');
|
|
195
|
+
/**
|
|
196
|
+
* A tag from `<` to its `>`. Attribute text cannot contain `<` or `>`, so a scan never runs
|
|
197
|
+
* past the next angle bracket and the sanitizer stays linear in the input length.
|
|
198
|
+
*/
|
|
199
|
+
const TAG = /<(\/?)([a-zA-Z][a-zA-Z0-9-]*)((?:[^<>"']|"[^"<>]*"|'[^'<>]*')*)>/y;
|
|
200
|
+
/** Deeper nesting is flattened: tags beyond it are dropped, their text kept. */
|
|
201
|
+
const MAX_DEPTH = 100;
|
|
202
|
+
/** Sanitizes administrator print markup; see the module comment for the rules. */
|
|
203
|
+
export function sanitizePrintHtml(input) {
|
|
204
|
+
let output = '';
|
|
205
|
+
const open = [];
|
|
206
|
+
let index = 0;
|
|
207
|
+
while (index < input.length) {
|
|
208
|
+
const lt = input.indexOf('<', index);
|
|
209
|
+
if (lt === -1) {
|
|
210
|
+
output += text(input.slice(index));
|
|
211
|
+
break;
|
|
212
|
+
}
|
|
213
|
+
output += text(input.slice(index, lt));
|
|
214
|
+
if (input.startsWith('<!--', lt)) {
|
|
215
|
+
const end = input.indexOf('-->', lt + 4);
|
|
216
|
+
index = end === -1 ? input.length : end + 3;
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
if (input[lt + 1] === '!' || input[lt + 1] === '?') {
|
|
220
|
+
const end = input.indexOf('>', lt);
|
|
221
|
+
index = end === -1 ? input.length : end + 1;
|
|
222
|
+
continue;
|
|
223
|
+
}
|
|
224
|
+
TAG.lastIndex = lt;
|
|
225
|
+
const tag = TAG.exec(input);
|
|
226
|
+
if (!tag) {
|
|
227
|
+
output += '<';
|
|
228
|
+
index = lt + 1;
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
index = lt + tag[0].length;
|
|
232
|
+
const closing = tag[1] === '/';
|
|
233
|
+
const name = tag[2].toLowerCase();
|
|
234
|
+
if (!closing && DROPPED_WITH_CONTENT.has(name)) {
|
|
235
|
+
// Skip to the matching close tag (or the end): its contents never reach the page.
|
|
236
|
+
const close = new RegExp(`</${name}\\s*>`, 'gi');
|
|
237
|
+
close.lastIndex = index;
|
|
238
|
+
const end = close.exec(input);
|
|
239
|
+
index = end ? end.index + end[0].length : input.length;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (!ALLOWED_TAGS.has(name))
|
|
243
|
+
continue;
|
|
244
|
+
if (closing) {
|
|
245
|
+
const position = open.lastIndexOf(name);
|
|
246
|
+
if (position === -1)
|
|
247
|
+
continue;
|
|
248
|
+
while (open.length > position)
|
|
249
|
+
output += `</${open.pop()}>`;
|
|
250
|
+
continue;
|
|
251
|
+
}
|
|
252
|
+
if (!VOID.has(name) && open.length >= MAX_DEPTH)
|
|
253
|
+
continue;
|
|
254
|
+
output += `<${name}${attributes(tag[3])}>`;
|
|
255
|
+
if (!VOID.has(name))
|
|
256
|
+
open.push(name);
|
|
257
|
+
}
|
|
258
|
+
while (open.length)
|
|
259
|
+
output += `</${open.pop()}>`;
|
|
260
|
+
return output;
|
|
261
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { Knex } from 'knex';
|
|
2
|
+
import type { ResourceRegistry } from '../resource/registry.js';
|
|
3
|
+
/** A resource field that stores values of a lookup group. */
|
|
4
|
+
export type LookupFieldUse = {
|
|
5
|
+
resource: string;
|
|
6
|
+
field: string;
|
|
7
|
+
label: string;
|
|
8
|
+
};
|
|
9
|
+
export type LookupGroupSummary = {
|
|
10
|
+
group: string;
|
|
11
|
+
total: number;
|
|
12
|
+
active: number;
|
|
13
|
+
/** Registered resource fields that store this group's keys. */
|
|
14
|
+
fields: LookupFieldUse[];
|
|
15
|
+
/** Declared by a registered module, which seeds it on installation. */
|
|
16
|
+
declared: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type LookupValue = {
|
|
19
|
+
id: number;
|
|
20
|
+
group: string;
|
|
21
|
+
key: string;
|
|
22
|
+
labelAr: string;
|
|
23
|
+
labelEn: string;
|
|
24
|
+
sort: number;
|
|
25
|
+
active: boolean;
|
|
26
|
+
/** Stored records (including deleted ones) holding this key; null without a registry. */
|
|
27
|
+
usage: number | null;
|
|
28
|
+
/** Declared by a registered module; such values are never deleted. */
|
|
29
|
+
declared: boolean;
|
|
30
|
+
};
|
|
31
|
+
export type LookupInput = {
|
|
32
|
+
group: unknown;
|
|
33
|
+
key: unknown;
|
|
34
|
+
labelAr: unknown;
|
|
35
|
+
labelEn?: unknown;
|
|
36
|
+
sort?: unknown;
|
|
37
|
+
};
|
|
38
|
+
export type LookupUpdate = {
|
|
39
|
+
labelAr?: unknown;
|
|
40
|
+
labelEn?: unknown;
|
|
41
|
+
sort?: unknown;
|
|
42
|
+
key?: unknown;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Administration of lookup values (lookups table). Values are never renamed or removed while
|
|
46
|
+
* records hold them: the key is immutable, a value stored by any record cannot be disabled
|
|
47
|
+
* (the record validator requires an active value on every save, so a disabled stored value
|
|
48
|
+
* would block editing those records), and only an unused value that no registered module
|
|
49
|
+
* declares may be deleted (a declared value would be seeded again on the next installation).
|
|
50
|
+
* Usage is counted from the registered resources' lookup fields; without a registry it is
|
|
51
|
+
* unknown and disabling or deleting is refused.
|
|
52
|
+
*/
|
|
53
|
+
export declare class LookupsAdmin {
|
|
54
|
+
private db;
|
|
55
|
+
private registry?;
|
|
56
|
+
constructor(db: Knex, registry?: ResourceRegistry | undefined);
|
|
57
|
+
/** Lookup fields of the registered resources, by group. */
|
|
58
|
+
fields(name?: string): (LookupFieldUse & {
|
|
59
|
+
table: string;
|
|
60
|
+
column: string;
|
|
61
|
+
group: string;
|
|
62
|
+
})[];
|
|
63
|
+
private declared;
|
|
64
|
+
groups(): Promise<LookupGroupSummary[]>;
|
|
65
|
+
values(name: unknown): Promise<LookupValue[]>;
|
|
66
|
+
create(actorId: number, input: LookupInput): Promise<LookupValue>;
|
|
67
|
+
update(actorId: number, id: unknown, input: LookupUpdate): Promise<LookupValue>;
|
|
68
|
+
/** Sets the order of a whole group: `ids` lists every value of the group once, first to last. */
|
|
69
|
+
reorder(actorId: number, name: unknown, ids: unknown): Promise<LookupValue[]>;
|
|
70
|
+
disable(actorId: number, id: unknown): Promise<LookupValue>;
|
|
71
|
+
enable(actorId: number, id: unknown): Promise<LookupValue>;
|
|
72
|
+
delete(actorId: number, id: unknown): Promise<void>;
|
|
73
|
+
private setActive;
|
|
74
|
+
private refuseInUse;
|
|
75
|
+
private lock;
|
|
76
|
+
private withUsage;
|
|
77
|
+
/** Records holding each key, over every registered field of the group; null without a registry. */
|
|
78
|
+
private usageByKey;
|
|
79
|
+
private toValue;
|
|
80
|
+
}
|
|
@@ -0,0 +1,319 @@
|
|
|
1
|
+
import { columnName } from '../resource/define_resource.js';
|
|
2
|
+
import { AdulaError } from '../admin/errors.js';
|
|
3
|
+
import { logActivity } from './activity.js';
|
|
4
|
+
const RESOURCE = 'core.lookups';
|
|
5
|
+
const GROUP = /^[a-z][a-z0-9_]{0,99}$/;
|
|
6
|
+
const KEY = /^[a-z0-9][a-z0-9_-]{0,99}$/;
|
|
7
|
+
function group(value) {
|
|
8
|
+
if (typeof value !== 'string' || !GROUP.test(value))
|
|
9
|
+
throw new AdulaError(422, 'E_LOOKUP_GROUP', 'اسم القائمة يبدأ بحرف إنجليزي صغير ويحوي حروفاً صغيرة وأرقاماً وشرطة سفلية فقط');
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
function key(value) {
|
|
13
|
+
if (typeof value !== 'string' || !KEY.test(value))
|
|
14
|
+
throw new AdulaError(422, 'E_LOOKUP_KEY', 'المفتاح يحوي حروفاً إنجليزية صغيرة وأرقاماً وشرطة أو شرطة سفلية فقط');
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
17
|
+
function label(value, required) {
|
|
18
|
+
const text = typeof value === 'string' ? value.trim() : '';
|
|
19
|
+
if (value !== undefined && value !== null && typeof value !== 'string')
|
|
20
|
+
throw new AdulaError(422, 'E_LOOKUP_LABEL', 'التسمية يجب أن تكون نصاً');
|
|
21
|
+
if (required && !text)
|
|
22
|
+
throw new AdulaError(422, 'E_LOOKUP_LABEL', 'التسمية العربية مطلوبة');
|
|
23
|
+
if (text.length > 255)
|
|
24
|
+
throw new AdulaError(422, 'E_LOOKUP_LABEL', 'التسمية لا تتجاوز 255 حرفاً');
|
|
25
|
+
return text;
|
|
26
|
+
}
|
|
27
|
+
function sort(value) {
|
|
28
|
+
const number = typeof value === 'string' && value.trim() ? Number(value) : value;
|
|
29
|
+
if (typeof number !== 'number' || !Number.isSafeInteger(number) || Math.abs(number) > 2 ** 31 - 1)
|
|
30
|
+
throw new AdulaError(422, 'E_LOOKUP_SORT', 'الترتيب يجب أن يكون عدداً صحيحاً');
|
|
31
|
+
return number;
|
|
32
|
+
}
|
|
33
|
+
function lookupId(value) {
|
|
34
|
+
const id = Number(value);
|
|
35
|
+
if (!Number.isSafeInteger(id) || id <= 0)
|
|
36
|
+
throw new AdulaError(404, 'E_LOOKUP_NOT_FOUND', 'القيمة غير موجودة');
|
|
37
|
+
return id;
|
|
38
|
+
}
|
|
39
|
+
/** The English label column is required; a value without one shows its key, as imports match it. */
|
|
40
|
+
const english = (text, fallback) => text || fallback;
|
|
41
|
+
/**
|
|
42
|
+
* Administration of lookup values (lookups table). Values are never renamed or removed while
|
|
43
|
+
* records hold them: the key is immutable, a value stored by any record cannot be disabled
|
|
44
|
+
* (the record validator requires an active value on every save, so a disabled stored value
|
|
45
|
+
* would block editing those records), and only an unused value that no registered module
|
|
46
|
+
* declares may be deleted (a declared value would be seeded again on the next installation).
|
|
47
|
+
* Usage is counted from the registered resources' lookup fields; without a registry it is
|
|
48
|
+
* unknown and disabling or deleting is refused.
|
|
49
|
+
*/
|
|
50
|
+
export class LookupsAdmin {
|
|
51
|
+
db;
|
|
52
|
+
registry;
|
|
53
|
+
constructor(db, registry) {
|
|
54
|
+
this.db = db;
|
|
55
|
+
this.registry = registry;
|
|
56
|
+
}
|
|
57
|
+
/** Lookup fields of the registered resources, by group. */
|
|
58
|
+
fields(name) {
|
|
59
|
+
if (!this.registry)
|
|
60
|
+
return [];
|
|
61
|
+
return this.registry.all().flatMap((resource) => Object.entries(resource.fields).flatMap(([field, definition]) => definition.type === 'lookup' && (name === undefined || definition.group === name)
|
|
62
|
+
? [
|
|
63
|
+
{
|
|
64
|
+
resource: resource.name,
|
|
65
|
+
field,
|
|
66
|
+
label: definition.label.ar,
|
|
67
|
+
table: resource.name,
|
|
68
|
+
column: definition.column ?? columnName(field),
|
|
69
|
+
group: definition.group,
|
|
70
|
+
},
|
|
71
|
+
]
|
|
72
|
+
: []));
|
|
73
|
+
}
|
|
74
|
+
declared() {
|
|
75
|
+
const keys = new Set();
|
|
76
|
+
for (const module of this.registry?.modules() ?? [])
|
|
77
|
+
for (const [name, rows] of Object.entries(module.lookups ?? {}))
|
|
78
|
+
for (const row of rows)
|
|
79
|
+
keys.add(`${name}\u0000${row.key}`);
|
|
80
|
+
return keys;
|
|
81
|
+
}
|
|
82
|
+
async groups() {
|
|
83
|
+
const rows = await this.db('lookups')
|
|
84
|
+
.select('group')
|
|
85
|
+
.count('* as total')
|
|
86
|
+
.select(this.db.raw('count(*) FILTER (WHERE active) AS active'))
|
|
87
|
+
.groupBy('group');
|
|
88
|
+
const declared = [...this.declared()].map((entry) => entry.split('\u0000')[0]);
|
|
89
|
+
const names = new Set([
|
|
90
|
+
...rows.map((row) => String(row.group)),
|
|
91
|
+
...this.fields().map((field) => field.group),
|
|
92
|
+
...declared,
|
|
93
|
+
]);
|
|
94
|
+
return [...names].sort().map((name) => {
|
|
95
|
+
const row = rows.find((entry) => entry.group === name);
|
|
96
|
+
return {
|
|
97
|
+
group: name,
|
|
98
|
+
total: Number(row?.total ?? 0),
|
|
99
|
+
active: Number(row?.active ?? 0),
|
|
100
|
+
fields: this.fields(name).map(({ resource, field, label: text }) => ({
|
|
101
|
+
resource,
|
|
102
|
+
field,
|
|
103
|
+
label: text,
|
|
104
|
+
})),
|
|
105
|
+
declared: declared.includes(name),
|
|
106
|
+
};
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async values(name) {
|
|
110
|
+
// A group named by a registered field is listed even when it predates the slug rule.
|
|
111
|
+
const selected = typeof name === 'string' && this.fields(name).length ? name : group(name);
|
|
112
|
+
const rows = await this.db('lookups').where('group', selected).orderBy(['sort', 'key']);
|
|
113
|
+
const usage = await this.usageByKey(this.db, selected, rows.map((row) => String(row.key)));
|
|
114
|
+
const declared = this.declared();
|
|
115
|
+
return rows.map((row) => ({
|
|
116
|
+
...this.toValue(row, declared),
|
|
117
|
+
usage: usage ? (usage.get(String(row.key)) ?? 0) : null,
|
|
118
|
+
}));
|
|
119
|
+
}
|
|
120
|
+
async create(actorId, input) {
|
|
121
|
+
const values = {
|
|
122
|
+
group: group(input.group),
|
|
123
|
+
key: key(input.key),
|
|
124
|
+
labelAr: label(input.labelAr, true),
|
|
125
|
+
labelEn: label(input.labelEn, false),
|
|
126
|
+
};
|
|
127
|
+
return this.db.transaction(async (trx) => {
|
|
128
|
+
if (await trx('lookups').where({ group: values.group, key: values.key }).first('id'))
|
|
129
|
+
throw new AdulaError(409, 'E_LOOKUP_EXISTS', 'هذا المفتاح موجود في القائمة');
|
|
130
|
+
const last = await trx('lookups').where('group', values.group).max('sort as max').first();
|
|
131
|
+
const position = input.sort === undefined || input.sort === null || input.sort === ''
|
|
132
|
+
? Number(last?.max ?? -1) + 1
|
|
133
|
+
: sort(input.sort);
|
|
134
|
+
const [row] = await trx('lookups')
|
|
135
|
+
.insert({
|
|
136
|
+
group: values.group,
|
|
137
|
+
key: values.key,
|
|
138
|
+
label_ar: values.labelAr,
|
|
139
|
+
label_en: english(values.labelEn, values.key),
|
|
140
|
+
sort: position,
|
|
141
|
+
active: true,
|
|
142
|
+
})
|
|
143
|
+
.returning('*');
|
|
144
|
+
await logActivity(trx, {
|
|
145
|
+
resource: RESOURCE,
|
|
146
|
+
recordId: row.id,
|
|
147
|
+
actorId,
|
|
148
|
+
action: 'create',
|
|
149
|
+
changes: {
|
|
150
|
+
group: row.group,
|
|
151
|
+
key: row.key,
|
|
152
|
+
labelAr: row.label_ar,
|
|
153
|
+
labelEn: row.label_en,
|
|
154
|
+
sort: row.sort,
|
|
155
|
+
},
|
|
156
|
+
});
|
|
157
|
+
return { ...this.toValue(row, this.declared()), usage: 0 };
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
async update(actorId, id, input) {
|
|
161
|
+
const recordId = lookupId(id);
|
|
162
|
+
return this.db.transaction(async (trx) => {
|
|
163
|
+
const row = await this.lock(trx, recordId);
|
|
164
|
+
if (input.key !== undefined && input.key !== row.key)
|
|
165
|
+
throw new AdulaError(422, 'E_LOOKUP_KEY_IMMUTABLE', 'لا يمكن تغيير المفتاح لأن السجلات تحفظه؛ أضف قيمة جديدة وعطّل القديمة');
|
|
166
|
+
const next = {};
|
|
167
|
+
if (input.labelAr !== undefined)
|
|
168
|
+
next.label_ar = label(input.labelAr, true);
|
|
169
|
+
if (input.labelEn !== undefined)
|
|
170
|
+
next.label_en = english(label(input.labelEn, false), row.key);
|
|
171
|
+
if (input.sort !== undefined)
|
|
172
|
+
next.sort = sort(input.sort);
|
|
173
|
+
const changes = Object.fromEntries(Object.entries(next).filter(([column, value]) => row[column] !== value));
|
|
174
|
+
if (!Object.keys(changes).length)
|
|
175
|
+
return this.withUsage(trx, row);
|
|
176
|
+
const [updated] = await trx('lookups').where('id', recordId).update(changes).returning('*');
|
|
177
|
+
await logActivity(trx, {
|
|
178
|
+
resource: RESOURCE,
|
|
179
|
+
recordId,
|
|
180
|
+
actorId,
|
|
181
|
+
action: 'update',
|
|
182
|
+
changes: {
|
|
183
|
+
group: row.group,
|
|
184
|
+
key: row.key,
|
|
185
|
+
...Object.fromEntries(Object.entries(changes).map(([column, value]) => [
|
|
186
|
+
{ label_ar: 'labelAr', label_en: 'labelEn', sort: 'sort' }[column],
|
|
187
|
+
{ from: row[column], to: value },
|
|
188
|
+
])),
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
return this.withUsage(trx, updated);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/** Sets the order of a whole group: `ids` lists every value of the group once, first to last. */
|
|
195
|
+
async reorder(actorId, name, ids) {
|
|
196
|
+
const selected = group(name);
|
|
197
|
+
if (!Array.isArray(ids) || !ids.length)
|
|
198
|
+
throw new AdulaError(422, 'E_LOOKUP_ORDER', 'أرسل ترتيب قيم القائمة كاملة');
|
|
199
|
+
const order = ids.map((id) => lookupId(id));
|
|
200
|
+
return this.db.transaction(async (trx) => {
|
|
201
|
+
const rows = await trx('lookups').where('group', selected).forUpdate().select('*');
|
|
202
|
+
const known = new Set(rows.map((row) => Number(row.id)));
|
|
203
|
+
if (!rows.length ||
|
|
204
|
+
new Set(order).size !== order.length ||
|
|
205
|
+
order.length !== rows.length ||
|
|
206
|
+
order.some((id) => !known.has(id)))
|
|
207
|
+
throw new AdulaError(422, 'E_LOOKUP_ORDER', 'الترتيب يجب أن يذكر كل قيم القائمة مرة واحدة فقط');
|
|
208
|
+
for (const [position, id] of order.entries()) {
|
|
209
|
+
const row = rows.find((entry) => Number(entry.id) === id);
|
|
210
|
+
if (row.sort === position)
|
|
211
|
+
continue;
|
|
212
|
+
await trx('lookups').where('id', id).update({ sort: position });
|
|
213
|
+
await logActivity(trx, {
|
|
214
|
+
resource: RESOURCE,
|
|
215
|
+
recordId: id,
|
|
216
|
+
actorId,
|
|
217
|
+
action: 'reorder',
|
|
218
|
+
changes: { group: selected, key: row.key, sort: { from: row.sort, to: position } },
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
return new LookupsAdmin(trx, this.registry).values(selected);
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
async disable(actorId, id) {
|
|
225
|
+
return this.setActive(actorId, lookupId(id), false);
|
|
226
|
+
}
|
|
227
|
+
async enable(actorId, id) {
|
|
228
|
+
return this.setActive(actorId, lookupId(id), true);
|
|
229
|
+
}
|
|
230
|
+
async delete(actorId, id) {
|
|
231
|
+
const recordId = lookupId(id);
|
|
232
|
+
return this.db.transaction(async (trx) => {
|
|
233
|
+
const row = await this.lock(trx, recordId);
|
|
234
|
+
if (this.declared().has(`${row.group}\u0000${row.key}`))
|
|
235
|
+
throw new AdulaError(409, 'E_LOOKUP_DECLARED', 'هذه القيمة معرّفة في أحد التطبيقات وتعود عند التثبيت؛ عطّلها بدلاً من حذفها');
|
|
236
|
+
await this.refuseInUse(trx, row, 'حذفها');
|
|
237
|
+
await trx('lookups').where('id', recordId).delete();
|
|
238
|
+
await logActivity(trx, {
|
|
239
|
+
resource: RESOURCE,
|
|
240
|
+
recordId,
|
|
241
|
+
actorId,
|
|
242
|
+
action: 'delete',
|
|
243
|
+
changes: { group: row.group, key: row.key, labelAr: row.label_ar },
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
async setActive(actorId, id, active) {
|
|
248
|
+
return this.db.transaction(async (trx) => {
|
|
249
|
+
const row = await this.lock(trx, id);
|
|
250
|
+
if (row.active === active)
|
|
251
|
+
return this.withUsage(trx, row);
|
|
252
|
+
if (!active)
|
|
253
|
+
await this.refuseInUse(trx, row, 'تعطيلها');
|
|
254
|
+
const [updated] = await trx('lookups').where('id', id).update({ active }).returning('*');
|
|
255
|
+
await logActivity(trx, {
|
|
256
|
+
resource: RESOURCE,
|
|
257
|
+
recordId: id,
|
|
258
|
+
actorId,
|
|
259
|
+
action: active ? 'enable' : 'disable',
|
|
260
|
+
changes: { group: row.group, key: row.key },
|
|
261
|
+
});
|
|
262
|
+
return this.withUsage(trx, updated);
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
async refuseInUse(db, row, verb) {
|
|
266
|
+
const usage = await this.usageByKey(db, row.group, [row.key]);
|
|
267
|
+
if (!usage)
|
|
268
|
+
throw new AdulaError(409, 'E_LOOKUP_USAGE_UNKNOWN', `تعذّر التحقق من استخدام القيمة، لذلك لا يمكن ${verb}`);
|
|
269
|
+
const count = usage.get(row.key) ?? 0;
|
|
270
|
+
if (count > 0)
|
|
271
|
+
throw new AdulaError(409, 'E_LOOKUP_IN_USE', `لا يمكن ${verb}: القيمة «${row.label_ar}» محفوظة في ${count} سجل. غيّر قيمة هذه السجلات أولاً.`);
|
|
272
|
+
}
|
|
273
|
+
async lock(trx, id) {
|
|
274
|
+
const row = await trx('lookups').where('id', id).forUpdate().first();
|
|
275
|
+
if (!row)
|
|
276
|
+
throw new AdulaError(404, 'E_LOOKUP_NOT_FOUND', 'القيمة غير موجودة');
|
|
277
|
+
return row;
|
|
278
|
+
}
|
|
279
|
+
async withUsage(db, row) {
|
|
280
|
+
const usage = await this.usageByKey(db, row.group, [row.key]);
|
|
281
|
+
return {
|
|
282
|
+
...this.toValue(row, this.declared()),
|
|
283
|
+
usage: usage ? (usage.get(row.key) ?? 0) : null,
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/** Records holding each key, over every registered field of the group; null without a registry. */
|
|
287
|
+
async usageByKey(db, name, keys) {
|
|
288
|
+
if (!this.registry)
|
|
289
|
+
return null;
|
|
290
|
+
const counts = new Map();
|
|
291
|
+
if (!keys.length)
|
|
292
|
+
return counts;
|
|
293
|
+
for (const field of this.fields(name)) {
|
|
294
|
+
const exists = await db.raw('SELECT to_regclass(?) AS name', [field.table]);
|
|
295
|
+
if (!exists.rows[0]?.name)
|
|
296
|
+
continue;
|
|
297
|
+
const rows = await db(field.table)
|
|
298
|
+
.whereIn(field.column, keys)
|
|
299
|
+
.groupBy(field.column)
|
|
300
|
+
.select(`${field.column} as key`)
|
|
301
|
+
.count('* as count');
|
|
302
|
+
for (const row of rows)
|
|
303
|
+
counts.set(String(row.key), (counts.get(String(row.key)) ?? 0) + Number(row.count));
|
|
304
|
+
}
|
|
305
|
+
return counts;
|
|
306
|
+
}
|
|
307
|
+
toValue(row, declared) {
|
|
308
|
+
return {
|
|
309
|
+
id: Number(row.id),
|
|
310
|
+
group: String(row.group),
|
|
311
|
+
key: String(row.key),
|
|
312
|
+
labelAr: String(row.label_ar),
|
|
313
|
+
labelEn: String(row.label_en),
|
|
314
|
+
sort: Number(row.sort),
|
|
315
|
+
active: Boolean(row.active),
|
|
316
|
+
declared: declared.has(`${row.group}\u0000${row.key}`),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
@@ -48,9 +48,14 @@ export declare class MessageTemplates {
|
|
|
48
48
|
};
|
|
49
49
|
private definition;
|
|
50
50
|
}
|
|
51
|
+
/** The built-in channels: the notification row itself and the mail_state e-mail queue. */
|
|
52
|
+
export declare const IN_APP_CHANNEL = "in_app";
|
|
53
|
+
export declare const MAIL_CHANNEL = "mail";
|
|
51
54
|
/**
|
|
52
|
-
* Inserts a templated notification in the caller's transaction.
|
|
53
|
-
*
|
|
55
|
+
* Inserts a templated notification in the caller's transaction. A template with mail
|
|
56
|
+
* (external delivery) enabled marks the row for the mail worker (deliverNotificationMail)
|
|
57
|
+
* unless the user turned e-mail off, and queues one notification_deliveries row per
|
|
58
|
+
* other channel the user enabled with an address (see core/notification_channels.ts).
|
|
54
59
|
*/
|
|
55
60
|
export declare function notifyWithTemplate(db: Knex, userId: number, key: string, variables: Record<string, unknown>, templates?: MessageTemplates, target?: NotificationTarget | null): Promise<void>;
|
|
56
61
|
export type MailSender = (message: {
|