adula 2.2.0 → 2.3.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.
Files changed (132) hide show
  1. package/README.md +1 -1
  2. package/build/agent/capabilities.md +2 -3
  3. package/build/agent/skills/adula-frontend-design/SKILL.md +5 -3
  4. package/build/commands/adula_assistant_prune.d.ts +10 -0
  5. package/build/commands/adula_assistant_prune.js +12 -0
  6. package/build/commands/backup_open.d.ts +16 -0
  7. package/build/commands/backup_open.js +48 -0
  8. package/build/commands/backup_restore_test.js +3 -0
  9. package/build/commands/backup_seal.d.ts +12 -0
  10. package/build/commands/backup_seal.js +36 -0
  11. package/build/commands/backup_services.d.ts +3 -1
  12. package/build/commands/doctor.js +18 -1
  13. package/build/commands/install.js +6 -0
  14. package/build/commands/main.d.ts +2 -2
  15. package/build/commands/main.js +6 -0
  16. package/build/commands/resource_migration.js +12 -3
  17. package/build/commands/resource_snapshot.js +18 -4
  18. package/build/database/migrations/1770000000051_comment_notifications.d.ts +5 -0
  19. package/build/database/migrations/1770000000051_comment_notifications.js +10 -0
  20. package/build/database/migrations/1770000000054_cloud_backups.d.ts +5 -0
  21. package/build/database/migrations/1770000000054_cloud_backups.js +10 -0
  22. package/build/database/migrations/1770000000055_ai_assistant.d.ts +5 -0
  23. package/build/database/migrations/1770000000055_ai_assistant.js +10 -0
  24. package/build/database/migrations/1770000000056_appearance.d.ts +5 -0
  25. package/build/database/migrations/1770000000056_appearance.js +10 -0
  26. package/build/index.d.ts +36 -6
  27. package/build/index.js +18 -3
  28. package/build/src/admin/controller.js +18 -4
  29. package/build/src/admin/resource/editor.d.ts +1 -0
  30. package/build/src/admin/resource/editor.js +26 -4
  31. package/build/src/admin/resource/export.d.ts +21 -4
  32. package/build/src/admin/resource/export.js +117 -36
  33. package/build/src/admin/resource/lifecycle.d.ts +2 -0
  34. package/build/src/admin/resource/query.d.ts +14 -3
  35. package/build/src/admin/resource/query.js +98 -11
  36. package/build/src/admin/resource/read.d.ts +3 -0
  37. package/build/src/admin/resource/read.js +75 -14
  38. package/build/src/admin/resource/shared.d.ts +16 -0
  39. package/build/src/admin/resource/shared.js +47 -4
  40. package/build/src/admin/resource/write.js +37 -8
  41. package/build/src/admin/resource_service.d.ts +17 -3
  42. package/build/src/admin/resource_service.js +16 -2
  43. package/build/src/admin/resource_tools.d.ts +111 -0
  44. package/build/src/admin/resource_tools.js +139 -0
  45. package/build/src/ai/assistant.d.ts +100 -0
  46. package/build/src/ai/assistant.js +487 -0
  47. package/build/src/ai/client.d.ts +49 -0
  48. package/build/src/ai/client.js +85 -0
  49. package/build/src/ai/prompt.d.ts +23 -0
  50. package/build/src/ai/prompt.js +83 -0
  51. package/build/src/ai/settings.d.ts +56 -0
  52. package/build/src/ai/settings.js +214 -0
  53. package/build/src/ai/usage.d.ts +16 -0
  54. package/build/src/ai/usage.js +33 -0
  55. package/build/src/appearance/appearance.d.ts +134 -0
  56. package/build/src/appearance/appearance.js +461 -0
  57. package/build/src/appearance/colors.d.ts +43 -0
  58. package/build/src/appearance/colors.js +99 -0
  59. package/build/src/appearance/logo.d.ts +32 -0
  60. package/build/src/appearance/logo.js +112 -0
  61. package/build/src/auth/actor_store.d.ts +5 -1
  62. package/build/src/auth/actor_store.js +8 -4
  63. package/build/src/backups/archive.d.ts +52 -0
  64. package/build/src/backups/archive.js +362 -0
  65. package/build/src/backups/cloud_backups.d.ts +133 -0
  66. package/build/src/backups/cloud_backups.js +650 -0
  67. package/build/src/backups/doctor.d.ts +7 -0
  68. package/build/src/backups/doctor.js +55 -0
  69. package/build/src/backups/providers.d.ts +81 -0
  70. package/build/src/backups/providers.js +470 -0
  71. package/build/src/collaboration/assignments.d.ts +24 -2
  72. package/build/src/collaboration/assignments.js +88 -32
  73. package/build/src/collaboration/record_collaboration.d.ts +19 -1
  74. package/build/src/collaboration/record_collaboration.js +109 -37
  75. package/build/src/collaboration/shared.d.ts +10 -2
  76. package/build/src/collaboration/shared.js +14 -1
  77. package/build/src/commands/capabilities.js +1 -1
  78. package/build/src/commands/doctor.d.ts +10 -0
  79. package/build/src/commands/doctor.js +31 -1
  80. package/build/src/commands/snapshot.d.ts +14 -0
  81. package/build/src/commands/snapshot.js +23 -0
  82. package/build/src/core/administrators.js +19 -3
  83. package/build/src/core/avatar_image.d.ts +33 -0
  84. package/build/src/core/avatar_image.js +278 -0
  85. package/build/src/core/mail_settings.d.ts +83 -0
  86. package/build/src/core/mail_settings.js +274 -0
  87. package/build/src/core/mail_test.d.ts +16 -0
  88. package/build/src/core/mail_test.js +81 -6
  89. package/build/src/core/message_templates.d.ts +8 -0
  90. package/build/src/core/message_templates.js +12 -3
  91. package/build/src/core/roles.js +24 -7
  92. package/build/src/core/saved_views.js +55 -24
  93. package/build/src/core/settings.d.ts +2 -2
  94. package/build/src/core/settings.js +15 -4
  95. package/build/src/core/ui_preferences.d.ts +6 -0
  96. package/build/src/core/ui_preferences.js +12 -1
  97. package/build/src/core/user_avatars.d.ts +79 -0
  98. package/build/src/core/user_avatars.js +186 -0
  99. package/build/src/core/user_preferences.d.ts +36 -0
  100. package/build/src/core/user_preferences.js +125 -0
  101. package/build/src/core/users.d.ts +2 -0
  102. package/build/src/core/users.js +4 -2
  103. package/build/src/database/schema.d.ts +46 -0
  104. package/build/src/database/schema.js +182 -0
  105. package/build/src/database/schema_diff.d.ts +16 -2
  106. package/build/src/database/schema_diff.js +40 -7
  107. package/build/src/integrations/api_client.js +18 -3
  108. package/build/src/integrations/imports.d.ts +16 -4
  109. package/build/src/integrations/imports.js +36 -8
  110. package/build/src/integrations/openapi.js +15 -4
  111. package/build/src/integrations/outbound.d.ts +43 -0
  112. package/build/src/integrations/outbound.js +98 -17
  113. package/build/src/integrations/print.d.ts +2 -1
  114. package/build/src/integrations/print.js +7 -3
  115. package/build/src/integrations/print_templates.js +3 -1
  116. package/build/src/integrations/xlsx.d.ts +41 -0
  117. package/build/src/integrations/xlsx.js +519 -0
  118. package/build/src/languages/ar.js +22 -0
  119. package/build/src/languages/ar_ui.d.ts +143 -14
  120. package/build/src/languages/ar_ui.js +145 -14
  121. package/build/src/languages/en.js +22 -0
  122. package/build/src/languages/en_ui.js +144 -14
  123. package/build/src/lists/dashboards.d.ts +42 -0
  124. package/build/src/lists/dashboards.js +49 -0
  125. package/build/src/mcp/tools.js +9 -104
  126. package/build/src/resource/define_resource.js +7 -0
  127. package/build/src/resource/types.d.ts +9 -0
  128. package/build/src/workflows/delegations.d.ts +15 -1
  129. package/build/src/workflows/delegations.js +49 -10
  130. package/build/src/workflows/engine.d.ts +11 -0
  131. package/build/src/workflows/engine.js +29 -7
  132. package/package.json +5 -1
@@ -100,7 +100,27 @@ export function isBlockedAddress(address) {
100
100
  return isBlockedAddress(embeddedIPv4(groups));
101
101
  return ipv6Blocked.check(groups.map((group) => group.toString(16)).join(':'), 'ipv6');
102
102
  }
103
- const defaultResolve = async (host) => {
103
+ /** True for a link-local address, including IPv4-mapped, IPv4-translated and NAT64 forms. */
104
+ export function isLinkLocalAddress(address) {
105
+ const value = address.replace(/^\[|\]$/g, '');
106
+ const version = isIP(value);
107
+ if (version === 4) {
108
+ const [first, second] = value.split('.').map(Number);
109
+ return first === 169 && second === 254;
110
+ }
111
+ if (version !== 6)
112
+ return false;
113
+ const groups = ipv6Groups(value);
114
+ if (!groups)
115
+ return false;
116
+ const prefix96 = groups.slice(0, 6);
117
+ if (prefix96.every((group, index) => group === (index === 5 ? 0xffff : 0)) ||
118
+ prefix96.every((group, index) => group === (index === 4 ? 0xffff : 0)) ||
119
+ (groups[0] === 0x64 && groups[1] === 0xff9b && prefix96.slice(2).every((group) => group === 0)))
120
+ return isLinkLocalAddress(embeddedIPv4(groups));
121
+ return (groups[0] & 0xffc0) === 0xfe80;
122
+ }
123
+ export const defaultResolve = async (host) => {
104
124
  const entries = await lookup(host, { all: true });
105
125
  return entries.map((entry) => entry.address);
106
126
  };
@@ -128,8 +148,17 @@ export async function resolveOutboundTarget(url, options = {}) {
128
148
  const [address] = addresses;
129
149
  return { address, family: isIP(address) === 6 ? 6 : 4 };
130
150
  }
131
- /** Sends a POST whose TCP connection goes to the pinned address; redirects are not followed. */
132
- export function pinnedPost(url, init) {
151
+ /** Raised when a response body exceeds the caller's bound. */
152
+ export class OutboundResponseTooLargeError extends Error {
153
+ constructor() {
154
+ super('Response body is too large');
155
+ }
156
+ }
157
+ /**
158
+ * Sends a request whose TCP connection goes to the pinned address; redirects are not
159
+ * followed and the response body is bounded.
160
+ */
161
+ export function pinnedRequest(url, init) {
133
162
  const { address, family } = init.target;
134
163
  const pinnedLookup = (_host, options, callback) => {
135
164
  if (options.all)
@@ -139,22 +168,58 @@ export function pinnedPost(url, init) {
139
168
  };
140
169
  const host = url.hostname.replace(/^\[|\]$/g, '');
141
170
  const send = url.protocol === 'https:' ? httpsRequest : httpRequest;
171
+ const limit = init.maxResponseBytes ?? 0;
172
+ const body = init.body ?? '';
142
173
  return new Promise((resolve, reject) => {
143
174
  const request = send(url, {
144
- method: 'POST',
145
- headers: { ...init.headers, 'Content-Length': String(Buffer.byteLength(init.body)) },
175
+ method: init.method,
176
+ headers: { ...init.headers, 'Content-Length': String(Buffer.byteLength(body)) },
146
177
  lookup: pinnedLookup,
147
178
  servername: isIP(host) ? undefined : host,
148
179
  signal: init.signal,
149
180
  }, (response) => {
150
- // The body is never read or stored.
151
- response.resume();
152
- resolve({ status: response.statusCode ?? 0 });
181
+ const result = { status: response.statusCode ?? 0, headers: response.headers };
182
+ if (limit <= 0) {
183
+ response.resume();
184
+ return resolve({ ...result, body: Buffer.alloc(0) });
185
+ }
186
+ const chunks = [];
187
+ let size = 0;
188
+ response.on('data', (chunk) => {
189
+ size += chunk.length;
190
+ if (size > limit) {
191
+ response.destroy();
192
+ request.destroy();
193
+ return reject(new OutboundResponseTooLargeError());
194
+ }
195
+ chunks.push(chunk);
196
+ });
197
+ response.on('end', () => resolve({ ...result, body: Buffer.concat(chunks) }));
198
+ response.on('error', reject);
153
199
  });
154
200
  request.on('error', reject);
155
- request.end(init.body);
201
+ request.end(body);
156
202
  });
157
203
  }
204
+ /** Sends a POST whose TCP connection goes to the pinned address; redirects are not followed. */
205
+ export async function pinnedPost(url, init) {
206
+ // The body is never read or stored.
207
+ const { status } = await pinnedRequest(url, { ...init, method: 'POST', maxResponseBytes: 0 });
208
+ return { status };
209
+ }
210
+ /**
211
+ * Validates an absolute URL for an outbound request: https only (http when private targets
212
+ * are allowed), no credentials, and a resolved address that is public unless allowed.
213
+ */
214
+ export async function guardOutboundUrl(value, options = {}) {
215
+ const url = new URL(value);
216
+ if (url.protocol !== 'https:' && !(options.allowPrivateTargets && url.protocol === 'http:'))
217
+ throw new OutboundTargetError('blocked-target');
218
+ if (url.username || url.password)
219
+ throw new OutboundTargetError('blocked-target');
220
+ const target = await resolveOutboundTarget(url, options);
221
+ return { url, target };
222
+ }
158
223
  /**
159
224
  * The guarded outbound HTTP client: validates the URL, resolves its host once,
160
225
  * refuses private targets unless allowed and connects to the validated address.
@@ -162,17 +227,33 @@ export function pinnedPost(url, init) {
162
227
  */
163
228
  export function createOutboundPoster(options = {}) {
164
229
  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');
230
+ const { url, target } = await guardedTarget(value, options, init.target);
173
231
  return pinnedPost(url, { ...init, target });
174
232
  };
175
233
  }
234
+ /**
235
+ * The guarded client for calls that need the response body (an API answer, ADR 052): the
236
+ * same URL, address and redirect rules as createOutboundPoster, through pinnedRequest with
237
+ * the body bounded by `maxResponseBytes` (OutboundResponseTooLargeError above it).
238
+ */
239
+ export function createOutboundRequester(options = {}) {
240
+ return async (value, init) => {
241
+ const { url, target } = await guardedTarget(value, options, init.target);
242
+ return pinnedRequest(url, { ...init, method: 'POST', target });
243
+ };
244
+ }
245
+ /** URL checks of guardOutboundUrl; a caller-supplied target is re-checked, not re-resolved. */
246
+ async function guardedTarget(value, options, target) {
247
+ const url = new URL(value);
248
+ if (url.protocol !== 'https:' && !(options.allowPrivateTargets && url.protocol === 'http:'))
249
+ throw new OutboundTargetError('blocked-target');
250
+ if (url.username || url.password)
251
+ throw new OutboundTargetError('blocked-target');
252
+ const resolved = target ?? (await resolveOutboundTarget(url, options));
253
+ if (options.allowPrivateTargets !== true && isBlockedAddress(resolved.address))
254
+ throw new OutboundTargetError('blocked-target');
255
+ return { url, target: resolved };
256
+ }
176
257
  const TLS_CODES = /^(ERR_TLS|ERR_SSL|CERT_|UNABLE_TO_|DEPTH_ZERO|SELF_SIGNED|HOSTNAME_MISMATCH)/;
177
258
  const DNS_CODES = new Set(['ENOTFOUND', 'EAI_AGAIN', 'EAI_FAIL', 'ENODATA', 'ESERVFAIL']);
178
259
  /** Maps a delivery failure to a stored category without keeping its message. */
@@ -32,7 +32,8 @@ export type PrintInput = {
32
32
  export declare const escapeHtml: (value: string) => string;
33
33
  /**
34
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`.
35
+ * (user rows) the first non-meta text value, else `#id`. A record the reader may not view
36
+ * has no related row and is printed with a neutral label, never its id.
36
37
  */
37
38
  export declare function relationTitle(rows: SerializedRecord[] | undefined, value: JsonValue | undefined): string;
38
39
  /**
@@ -1,3 +1,4 @@
1
+ import { translate } from '../languages/catalog.js';
1
2
  const IMAGE_TYPES = {
2
3
  png: 'image/png',
3
4
  jpg: 'image/jpeg',
@@ -26,13 +27,14 @@ export const escapeHtml = (value) => value
26
27
  const RELATION_META = new Set(['id', 'version', 'docStatus', 'orgUnitId']);
27
28
  /**
28
29
  * 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
+ * (user rows) the first non-meta text value, else `#id`. A record the reader may not view
31
+ * has no related row and is printed with a neutral label, never its id.
30
32
  */
31
33
  export function relationTitle(rows, value) {
32
34
  const fallback = value === null || value === undefined ? '—' : `#${String(value)}`;
33
35
  const row = rows?.find((entry) => String(entry.id) === String(value));
34
36
  if (!row)
35
- return fallback;
37
+ return fallback === '—' ? fallback : translate('list.value.unavailable');
36
38
  if ('_title' in row)
37
39
  return typeof row._title === 'string' && row._title ? row._title : fallback;
38
40
  const label = Object.entries(row).find(([key, entry]) => !RELATION_META.has(key) && typeof entry === 'string' && entry);
@@ -113,12 +115,14 @@ export function renderPrintHtml(input) {
113
115
  <html lang="ar" dir="rtl">
114
116
  <head>
115
117
  <meta charset="utf-8">
118
+ <meta name="color-scheme" content="light">
116
119
  <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">
117
120
  <title>${escapeHtml(input.resource.label)} #${escapeHtml(String(input.record.id))}</title>
118
121
  <style>
119
122
  @page { size: A4; margin: 18mm 16mm; }
120
123
  * { box-sizing: border-box; }
121
- body { font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif; color: #1c1917; font-size: 12pt; margin: 0; }
124
+ :root { color-scheme: light; }
125
+ body { font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif; color: #1c1917; background: #fff; font-size: 12pt; margin: 0; }
122
126
  header { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid #1c1917; padding-bottom: 8mm; margin-bottom: 8mm; }
123
127
  header h1 { font-size: 18pt; margin: 0; }
124
128
  header p { margin: 2mm 0 0; color: #57534e; font-size: 10pt; }
@@ -487,12 +487,14 @@ function page(input, printed) {
487
487
  <html lang="ar" dir="rtl">
488
488
  <head>
489
489
  <meta charset="utf-8">
490
+ <meta name="color-scheme" content="light">
490
491
  <meta http-equiv="Content-Security-Policy" content="default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:">
491
492
  <title>${escapeHtml(input.title)}</title>
492
493
  <style>
493
494
  @page { size: ${PAGE_SIZES[input.paper]} ${input.orientation}; margin: 16mm 14mm; }
494
495
  * { box-sizing: border-box; }
495
- body { font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif; color: #1c1917; font-size: 11pt; margin: 0; }
496
+ :root { color-scheme: light; }
497
+ body { font-family: "Noto Sans Arabic", "Segoe UI", Tahoma, sans-serif; color: #1c1917; background: #fff; font-size: 11pt; margin: 0; }
496
498
  header.doc { display: flex; align-items: center; justify-content: space-between; border-bottom: 2px solid #1c1917; padding-bottom: 6mm; margin-bottom: 6mm; }
497
499
  h1 { font-size: 17pt; margin: 0; } h2 { font-size: 12.5pt; margin: 7mm 0 3mm; } h3, h4 { margin: 4mm 0 2mm; }
498
500
  p { margin: 1.5mm 0; }
@@ -0,0 +1,41 @@
1
+ import { type ImportAdapter, type ImportTable } from './import_adapters.js';
2
+ /**
3
+ * Limits for an uploaded workbook. Sizes are counted on the bytes actually inflated, never
4
+ * on the sizes the archive declares. Rows include the header row.
5
+ */
6
+ export declare const XLSX_LIMITS: Readonly<{
7
+ compressed: number;
8
+ decompressedTotal: number;
9
+ decompressedEntry: number;
10
+ entries: 200;
11
+ sharedStrings: 500000;
12
+ rows: 5001;
13
+ columns: 100;
14
+ }>;
15
+ export type XlsxLimits = {
16
+ readonly [key in keyof typeof XLSX_LIMITS]: number;
17
+ };
18
+ export declare const XLSX_MIME_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
19
+ /** What the guard found: the checked first sheet and a clean archive for the reader. */
20
+ export type GuardedXlsx = {
21
+ sheetPath: string;
22
+ sharedStrings: number;
23
+ maxRow: number;
24
+ maxColumn: number;
25
+ /** A rebuilt, uncompressed archive holding only the parts the reader needs. */
26
+ archive: Uint8Array;
27
+ };
28
+ /**
29
+ * Checks an uploaded workbook before any spreadsheet parser sees it (#161): signature,
30
+ * encryption, a consistent zip structure, the real decompressed size of every entry, UTF-8
31
+ * XML without DTDs, comments, CDATA or ambiguous references, and the sheet's row, column and
32
+ * shared-string counts. Returns a rebuilt archive with only the allow-listed parts, so the
33
+ * parser reads exactly what was checked.
34
+ */
35
+ export declare function guardXlsx(bytes: Uint8Array, limits?: XlsxLimits): GuardedXlsx;
36
+ /** A cell value as import text: dates as ISO dates, booleans as نعم/لا, numbers without exponent. */
37
+ export declare function xlsxCellText(value: unknown): string;
38
+ /** The first sheet of a guarded workbook as an import table. */
39
+ export declare function readXlsxTable(bytes: Uint8Array, limits?: XlsxLimits): Promise<ImportTable>;
40
+ /** The built-in Excel adapter: the first sheet of an .xlsx workbook, checked by guardXlsx. */
41
+ export declare const xlsxImportAdapter: ImportAdapter;