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
@@ -0,0 +1,519 @@
1
+ import { crc32 } from 'node:zlib';
2
+ import { Inflate, zipSync } from 'fflate';
3
+ import { readSheet } from 'read-excel-file/universal';
4
+ import { AdulaError } from '../admin/errors.js';
5
+ import { extensionOf } from './import_adapters.js';
6
+ /**
7
+ * Limits for an uploaded workbook. Sizes are counted on the bytes actually inflated, never
8
+ * on the sizes the archive declares. Rows include the header row.
9
+ */
10
+ export const XLSX_LIMITS = Object.freeze({
11
+ compressed: 5 * 1024 * 1024,
12
+ decompressedTotal: 64 * 1024 * 1024,
13
+ decompressedEntry: 48 * 1024 * 1024,
14
+ entries: 200,
15
+ sharedStrings: 500_000,
16
+ rows: 5001,
17
+ columns: 100,
18
+ });
19
+ export const XLSX_MIME_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
20
+ const MALFORMED = 'تعذر قراءة ملف Excel: الملف تالف أو ليس بصيغة xlsx';
21
+ const ENCRYPTED = 'الملف محمي بكلمة مرور أو بصيغة Excel قديمة (xls). احفظه بصيغة xlsx دون حماية ثم أعد رفعه';
22
+ const TOO_LARGE = 'حجم محتوى الملف بعد فك الضغط يتجاوز الحد المسموح';
23
+ function fail(message) {
24
+ throw new AdulaError(422, 'E_IMPORT_FILE', message);
25
+ }
26
+ const LOCAL = 0x04034b50;
27
+ const CENTRAL = 0x02014b50;
28
+ const END = 0x06054b50;
29
+ const DESCRIPTOR = 0x08074b50;
30
+ /** Small input steps bound how much one push can inflate (deflate expands at most ~1032x). */
31
+ const CHUNK = 4096;
32
+ function endOfCentralDirectory(view) {
33
+ const last = view.byteLength - 22;
34
+ for (let at = last; at >= Math.max(0, last - 0xffff); at--)
35
+ if (view.getUint32(at, true) === END &&
36
+ at + 22 + view.getUint16(at + 20, true) === view.byteLength)
37
+ return at;
38
+ return fail(MALFORMED);
39
+ }
40
+ function decodeName(bytes) {
41
+ try {
42
+ return new TextDecoder('utf-8', { fatal: true }).decode(bytes);
43
+ }
44
+ catch {
45
+ return fail(MALFORMED);
46
+ }
47
+ }
48
+ /** Reads the central directory and checks every local header against it. */
49
+ function entries(bytes, limits) {
50
+ const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
51
+ const eocd = endOfCentralDirectory(view);
52
+ const count = view.getUint16(eocd + 10, true);
53
+ const size = view.getUint32(eocd + 12, true);
54
+ const start = view.getUint32(eocd + 16, true);
55
+ // Multi-disk and ZIP64 archives are never needed for a 5 MB workbook.
56
+ if (view.getUint16(eocd + 4, true) !== 0 || view.getUint16(eocd + 8, true) !== count)
57
+ fail(MALFORMED);
58
+ if (count === 0xffff || start === 0xffffffff || start + size !== eocd)
59
+ fail(MALFORMED);
60
+ if (count > limits.entries)
61
+ fail(MALFORMED);
62
+ const found = [];
63
+ const names = new Set();
64
+ let at = start;
65
+ for (let index = 0; index < count; index++) {
66
+ if (at + 46 > eocd || view.getUint32(at, true) !== CENTRAL)
67
+ fail(MALFORMED);
68
+ const flags = view.getUint16(at + 8, true);
69
+ const method = view.getUint16(at + 10, true);
70
+ const crc = view.getUint32(at + 16, true);
71
+ const compressedSize = view.getUint32(at + 20, true);
72
+ const nameLength = view.getUint16(at + 28, true);
73
+ const extraLength = view.getUint16(at + 30, true);
74
+ const commentLength = view.getUint16(at + 32, true);
75
+ const offset = view.getUint32(at + 42, true);
76
+ if (flags & 1)
77
+ fail(ENCRYPTED);
78
+ if (method !== 0 && method !== 8)
79
+ fail(MALFORMED);
80
+ if (at + 46 + nameLength > eocd)
81
+ fail(MALFORMED);
82
+ const nameBytes = bytes.subarray(at + 46, at + 46 + nameLength);
83
+ const name = decodeName(nameBytes);
84
+ if (!name || names.has(name) || name.includes('\\') || name.includes('\0'))
85
+ fail(MALFORMED);
86
+ names.add(name);
87
+ // The local header must name the same entry with the same method, unencrypted.
88
+ if (offset + 30 > start || view.getUint32(offset, true) !== LOCAL)
89
+ fail(MALFORMED);
90
+ const localNameLength = view.getUint16(offset + 26, true);
91
+ const localExtra = view.getUint16(offset + 28, true);
92
+ if (view.getUint16(offset + 8, true) !== method ||
93
+ (view.getUint16(offset + 6, true) & 1) !== 0 ||
94
+ localNameLength !== nameLength ||
95
+ offset + 30 + nameLength > start ||
96
+ Buffer.compare(bytes.subarray(offset + 30, offset + 30 + nameLength), nameBytes) !== 0)
97
+ fail(MALFORMED);
98
+ const dataStart = offset + 30 + localNameLength + localExtra;
99
+ let end = dataStart + compressedSize;
100
+ if (end > start)
101
+ fail(MALFORMED);
102
+ if (flags & 8) {
103
+ const signed = end + 4 <= start && view.getUint32(end, true) === DESCRIPTOR;
104
+ end += signed ? 16 : 12;
105
+ if (end > start)
106
+ fail(MALFORMED);
107
+ }
108
+ found.push({ name, method, crc, compressedSize, offset, dataStart, end });
109
+ at += 46 + nameLength + extraLength + commentLength;
110
+ }
111
+ if (at !== eocd)
112
+ fail(MALFORMED);
113
+ // Entries must tile the file before the central directory: nothing hides between them
114
+ // (an entry present only in local headers would be read by some parsers and not others).
115
+ let cursor = 0;
116
+ for (const entry of [...found].sort((a, b) => a.offset - b.offset)) {
117
+ if (entry.offset !== cursor)
118
+ fail(MALFORMED);
119
+ cursor = entry.end;
120
+ }
121
+ if (cursor !== start)
122
+ fail(MALFORMED);
123
+ return found;
124
+ }
125
+ /** Inflates one entry, counting real output bytes and checking its CRC. */
126
+ function inflateEntry(bytes, entry, store, budget, limits) {
127
+ const data = bytes.subarray(entry.dataStart, entry.dataStart + entry.compressedSize);
128
+ const chunks = [];
129
+ let size = 0;
130
+ let crc = 0;
131
+ const take = (chunk) => {
132
+ size += chunk.byteLength;
133
+ budget.total += chunk.byteLength;
134
+ if (size > limits.decompressedEntry || budget.total > limits.decompressedTotal)
135
+ fail(TOO_LARGE);
136
+ crc = crc32(chunk, crc);
137
+ if (store)
138
+ chunks.push(chunk);
139
+ };
140
+ if (entry.method === 0)
141
+ take(data);
142
+ else {
143
+ let done = false;
144
+ const inflate = new Inflate((chunk, final) => {
145
+ take(chunk);
146
+ if (final)
147
+ done = true;
148
+ });
149
+ try {
150
+ if (!data.byteLength)
151
+ inflate.push(new Uint8Array(0), true);
152
+ for (let at = 0; at < data.byteLength; at += CHUNK) {
153
+ const end = Math.min(at + CHUNK, data.byteLength);
154
+ inflate.push(data.subarray(at, end), end === data.byteLength);
155
+ }
156
+ }
157
+ catch (error) {
158
+ if (error instanceof AdulaError)
159
+ throw error;
160
+ fail(MALFORMED);
161
+ }
162
+ if (!done)
163
+ fail(MALFORMED);
164
+ }
165
+ if (crc >>> 0 !== entry.crc >>> 0)
166
+ fail(MALFORMED);
167
+ return store ? Buffer.concat(chunks) : null;
168
+ }
169
+ /** Inflates every entry against one budget; keeps only the requested parts. */
170
+ function inflateAll(bytes, list, keep, limits) {
171
+ const kept = new Map();
172
+ const budget = { total: 0 };
173
+ for (const entry of list) {
174
+ const part = inflateEntry(bytes, entry, keep(entry.name), budget, limits);
175
+ if (part)
176
+ kept.set(entry.name, part);
177
+ }
178
+ return kept;
179
+ }
180
+ /** Decodes an XML part as UTF-8 and refuses DTDs (entity expansion, external entities). */
181
+ function xmlText(bytes) {
182
+ if ((bytes[0] === 0xfe && bytes[1] === 0xff) ||
183
+ (bytes[0] === 0xff && bytes[1] === 0xfe) ||
184
+ (bytes[0] === 0x00 && bytes[1] === 0x3c) ||
185
+ (bytes[0] === 0x3c && bytes[1] === 0x00))
186
+ fail(MALFORMED);
187
+ let text = '';
188
+ try {
189
+ text = new TextDecoder('utf-8', { fatal: true }).decode(bytes);
190
+ }
191
+ catch {
192
+ fail(MALFORMED);
193
+ }
194
+ const declared = /^\uFEFF?<\?xml[^>]*\bencoding\s*=\s*["']([^"']+)["']/i.exec(text)?.[1];
195
+ if (declared && declared.toLowerCase().replace('_', '-') !== 'utf-8')
196
+ fail(MALFORMED);
197
+ if (/<!DOCTYPE|<!ENTITY/i.test(text))
198
+ fail(MALFORMED);
199
+ return text;
200
+ }
201
+ const NAMED_ENTITIES = {
202
+ lt: '<',
203
+ gt: '>',
204
+ amp: '&',
205
+ quot: '"',
206
+ apos: "'",
207
+ };
208
+ const REFERENCE = /&(#x[\da-fA-F]{1,6}|#\d{1,7}|[a-z]+);/g;
209
+ /**
210
+ * Character and predefined entity references decoded as the XML parser decodes them. An
211
+ * ampersand that does not start such a reference is refused rather than guessed at.
212
+ */
213
+ function decodeEntities(value) {
214
+ if (!value.includes('&'))
215
+ return value;
216
+ if (value.replace(REFERENCE, '').includes('&'))
217
+ fail(MALFORMED);
218
+ return value.replace(REFERENCE, (_, reference) => {
219
+ if (reference[0] !== '#')
220
+ return NAMED_ENTITIES[reference] ?? fail(MALFORMED);
221
+ const code = reference[1] === 'x' ? Number.parseInt(reference.slice(2), 16) : Number(reference.slice(1));
222
+ return code > 0 && code <= 0x10ffff ? String.fromCodePoint(code) : fail(MALFORMED);
223
+ });
224
+ }
225
+ /**
226
+ * Attributes as the reader sees them: values decoded, names without their namespace prefix
227
+ * (`x:r` is `r`), `xmlns` declarations left out. Two attributes with the same local name are
228
+ * refused, because the parser would keep only one of them.
229
+ */
230
+ function attributes(source) {
231
+ const found = {};
232
+ for (const match of source.matchAll(/([A-Za-z_][\w.:-]*)\s*=\s*(?:"([^"]*)"|'([^']*)')/g)) {
233
+ const name = match[1];
234
+ if (name === 'xmlns' || name.startsWith('xmlns:'))
235
+ continue;
236
+ const local = name.includes(':') ? name.slice(name.lastIndexOf(':') + 1) : name;
237
+ if (Object.hasOwn(found, local))
238
+ fail(MALFORMED);
239
+ found[local] = decodeEntities(match[2] ?? match[3]);
240
+ }
241
+ return found;
242
+ }
243
+ const TAG = /<(\/)?((?:[A-Za-z_][\w.-]*:)?[A-Za-z_][\w.-]*)((?:\s+[A-Za-z_][\w.:-]*\s*=\s*(?:"[^"<]*"|'[^'<]*'))*)\s*(\/)?>/y;
244
+ /**
245
+ * The elements of an XML part, read strictly: after the XML declaration every `<` must open
246
+ * or close an element with well-formed attributes. Comments, CDATA sections, processing
247
+ * instructions and anything else the guard could read differently from the parser are refused.
248
+ */
249
+ function* xmlElements(text) {
250
+ const declaration = /^\uFEFF?<\?xml\s[^<>]*\?>/.exec(text);
251
+ let position = declaration ? declaration[0].length : 0;
252
+ for (;;) {
253
+ const start = text.indexOf('<', position);
254
+ if (start === -1)
255
+ return;
256
+ TAG.lastIndex = start;
257
+ const match = TAG.exec(text);
258
+ if (!match)
259
+ return fail(MALFORMED);
260
+ position = TAG.lastIndex;
261
+ const qualified = match[2];
262
+ yield {
263
+ name: qualified.includes(':') ? qualified.slice(qualified.indexOf(':') + 1) : qualified,
264
+ closing: Boolean(match[1]),
265
+ selfClosing: Boolean(match[4]),
266
+ attributes: match[1] ? {} : attributes(match[3]),
267
+ };
268
+ }
269
+ }
270
+ /** Resolves a relationship target the way the reader does. */
271
+ const partPath = (target) => (target.startsWith('/') ? target.slice(1) : `xl/${target}`);
272
+ function columnNumber(letters) {
273
+ let value = 0;
274
+ for (const letter of letters)
275
+ value = value * 26 + (letter.charCodeAt(0) - 64);
276
+ return value;
277
+ }
278
+ function sizeMessage(limits) {
279
+ return `يجب ألا يتجاوز الملف ${limits.rows - 1} صف بيانات و${limits.columns} عمودًا`;
280
+ }
281
+ /** A row number: a positive integer without sign, spaces or leading zeros. */
282
+ const ROW_REFERENCE = /^[1-9]\d{0,6}$/;
283
+ /** A cell reference: one to three capital letters, then the row number. */
284
+ const CELL_REFERENCE = /^([A-Z]{1,3})([1-9]\d{0,6})$/;
285
+ /**
286
+ * Counts rows and cells against the limits, reading `r` exactly as the parser does. A row
287
+ * or cell reference that is not in its standard form is refused, so no reference can grow
288
+ * the parser's arrays beyond what was counted here.
289
+ */
290
+ function measureSheet(text, limits) {
291
+ let maxRow = 0;
292
+ let maxColumn = 0;
293
+ let rows = 0;
294
+ let row = 0;
295
+ let column = 0;
296
+ let cells = 0;
297
+ let inRow = false;
298
+ for (const element of xmlElements(text)) {
299
+ if (element.name === 'row') {
300
+ if (element.closing) {
301
+ if (!inRow)
302
+ fail(MALFORMED);
303
+ inRow = false;
304
+ continue;
305
+ }
306
+ if (inRow)
307
+ fail(MALFORMED);
308
+ const reference = element.attributes.r;
309
+ if (reference !== undefined && !ROW_REFERENCE.test(reference))
310
+ fail(MALFORMED);
311
+ const number = reference === undefined ? maxRow + 1 : Number(reference);
312
+ if (number <= maxRow)
313
+ fail(MALFORMED);
314
+ rows++;
315
+ row = number;
316
+ maxRow = number;
317
+ column = 0;
318
+ cells = 0;
319
+ if (rows > limits.rows || maxRow > limits.rows)
320
+ fail(sizeMessage(limits));
321
+ inRow = !element.selfClosing;
322
+ }
323
+ else if (element.name === 'c' && !element.closing) {
324
+ if (!inRow)
325
+ fail(MALFORMED);
326
+ const reference = element.attributes.r;
327
+ let number = column + 1;
328
+ if (reference !== undefined) {
329
+ const parts = CELL_REFERENCE.exec(reference);
330
+ if (!parts || Number(parts[2]) !== row)
331
+ return fail(MALFORMED);
332
+ number = columnNumber(parts[1]);
333
+ }
334
+ if (number <= column)
335
+ fail(MALFORMED);
336
+ column = number;
337
+ cells++;
338
+ maxColumn = Math.max(maxColumn, column);
339
+ if (cells > limits.columns || maxColumn > limits.columns)
340
+ fail(sizeMessage(limits));
341
+ }
342
+ }
343
+ if (inRow)
344
+ fail(MALFORMED);
345
+ return { maxRow, maxColumn };
346
+ }
347
+ /**
348
+ * The worksheet the reader opens first (the first `<sheet>` with a name), and the shared
349
+ * strings and styles parts, resolved as the reader resolves relationships.
350
+ */
351
+ function workbookParts(workbook, relationships) {
352
+ let relationId;
353
+ for (const element of xmlElements(workbook))
354
+ if (element.name === 'sheet' && !element.closing && element.attributes.name) {
355
+ relationId = element.attributes.id;
356
+ break;
357
+ }
358
+ if (!relationId)
359
+ return fail(MALFORMED);
360
+ let sheetPath;
361
+ const sharedStrings = new Set(['xl/sharedStrings.xml']);
362
+ const styles = new Set(['xl/styles.xml']);
363
+ const ids = new Set();
364
+ for (const element of xmlElements(relationships)) {
365
+ if (element.name !== 'Relationship' || element.closing)
366
+ continue;
367
+ const { Id: id, Type: type = '', Target: target } = element.attributes;
368
+ // The reader keeps the last relationship of an id; a repeated id is refused instead.
369
+ if (id !== undefined) {
370
+ if (ids.has(id))
371
+ fail(MALFORMED);
372
+ ids.add(id);
373
+ }
374
+ if (!target)
375
+ continue;
376
+ if (id === relationId && type.endsWith('/worksheet'))
377
+ sheetPath = partPath(target);
378
+ if (type.endsWith('/sharedStrings'))
379
+ sharedStrings.add(partPath(target));
380
+ if (type.endsWith('/styles'))
381
+ styles.add(partPath(target));
382
+ }
383
+ if (!sheetPath)
384
+ return fail(MALFORMED);
385
+ return { sheetPath, sharedStrings, styles };
386
+ }
387
+ const FIXED_PARTS = [
388
+ '[Content_Types].xml',
389
+ '_rels/.rels',
390
+ 'xl/workbook.xml',
391
+ 'xl/_rels/workbook.xml.rels',
392
+ ];
393
+ /** Reads every element of a part, so a malformed part fails here and not in the parser. */
394
+ function checkPart(text) {
395
+ for (const element of xmlElements(text))
396
+ void element;
397
+ }
398
+ /**
399
+ * Checks an uploaded workbook before any spreadsheet parser sees it (#161): signature,
400
+ * encryption, a consistent zip structure, the real decompressed size of every entry, UTF-8
401
+ * XML without DTDs, comments, CDATA or ambiguous references, and the sheet's row, column and
402
+ * shared-string counts. Returns a rebuilt archive with only the allow-listed parts, so the
403
+ * parser reads exactly what was checked.
404
+ */
405
+ export function guardXlsx(bytes, limits = XLSX_LIMITS) {
406
+ if (bytes.byteLength > limits.compressed)
407
+ fail('حجم الملف يتجاوز 5 ميغابايت');
408
+ if (bytes[0] === 0xd0 && bytes[1] === 0xcf && bytes[2] === 0x11 && bytes[3] === 0xe0)
409
+ fail(ENCRYPTED);
410
+ if (bytes.byteLength < 30 ||
411
+ bytes[0] !== 0x50 ||
412
+ bytes[1] !== 0x4b ||
413
+ bytes[2] !== 3 ||
414
+ bytes[3] !== 4)
415
+ fail(MALFORMED);
416
+ const list = entries(bytes, limits);
417
+ const names = new Set(list.map((entry) => entry.name));
418
+ // First pass: every entry is inflated and counted; the workbook parts are kept.
419
+ const first = inflateAll(bytes, list, (name) => FIXED_PARTS.includes(name), limits);
420
+ const workbook = first.get('xl/workbook.xml');
421
+ const relationships = first.get('xl/_rels/workbook.xml.rels');
422
+ if (!workbook || !relationships)
423
+ return fail(MALFORMED);
424
+ for (const part of first.values())
425
+ checkPart(xmlText(part));
426
+ const parts = workbookParts(xmlText(workbook), xmlText(relationships));
427
+ const { sheetPath } = parts;
428
+ if (!names.has(sheetPath))
429
+ fail(MALFORMED);
430
+ const wanted = new Set([sheetPath, ...parts.sharedStrings, ...parts.styles].filter((name) => names.has(name)));
431
+ // Second pass for the parts the first one did not keep, under the same limits.
432
+ const second = inflateAll(bytes, list, (name) => wanted.has(name), limits);
433
+ let sharedStrings = 0;
434
+ for (const [name, part] of second) {
435
+ const text = xmlText(part);
436
+ if (name === sheetPath)
437
+ continue;
438
+ if (!parts.sharedStrings.has(name)) {
439
+ checkPart(text);
440
+ continue;
441
+ }
442
+ for (const element of xmlElements(text))
443
+ if (element.name === 'si' && !element.closing && ++sharedStrings > limits.sharedStrings)
444
+ fail(TOO_LARGE);
445
+ }
446
+ const { maxRow, maxColumn } = measureSheet(xmlText(second.get(sheetPath)), limits);
447
+ const clean = {};
448
+ for (const [name, part] of [...first, ...second])
449
+ clean[name] = part;
450
+ return { sheetPath, sharedStrings, maxRow, maxColumn, archive: zipSync(clean, { level: 0 }) };
451
+ }
452
+ /** A cell value as import text: dates as ISO dates, booleans as نعم/لا, numbers without exponent. */
453
+ export function xlsxCellText(value) {
454
+ if (value === null || value === undefined)
455
+ return '';
456
+ if (typeof value === 'string')
457
+ return value;
458
+ if (typeof value === 'boolean')
459
+ return value ? 'نعم' : 'لا';
460
+ if (typeof value === 'number') {
461
+ if (!Number.isFinite(value))
462
+ fail(MALFORMED);
463
+ const text = String(value);
464
+ return /e/i.test(text)
465
+ ? value.toLocaleString('en-US', { useGrouping: false, maximumFractionDigits: 100 })
466
+ : text;
467
+ }
468
+ if (value instanceof Date) {
469
+ if (Number.isNaN(value.getTime()))
470
+ fail(MALFORMED);
471
+ const iso = value.toISOString();
472
+ return iso.endsWith('T00:00:00.000Z') ? iso.slice(0, 10) : iso;
473
+ }
474
+ return String(value);
475
+ }
476
+ /** Drops trailing empty rows and trailing empty columns. */
477
+ function trimTable(rows) {
478
+ let height = rows.length;
479
+ while (height && rows[height - 1].every((cell) => cell.trim() === ''))
480
+ height--;
481
+ const kept = rows.slice(0, height);
482
+ let width = 0;
483
+ for (const row of kept)
484
+ for (let index = row.length - 1; index >= width; index--)
485
+ if (row[index].trim() !== '') {
486
+ width = index + 1;
487
+ break;
488
+ }
489
+ return kept.map((row) => Array.from({ length: width }, (_, index) => row[index] ?? ''));
490
+ }
491
+ /** The first sheet of a guarded workbook as an import table. */
492
+ export async function readXlsxTable(bytes, limits = XLSX_LIMITS) {
493
+ const { archive } = guardXlsx(bytes, limits);
494
+ const input = archive.buffer.slice(archive.byteOffset, archive.byteOffset + archive.byteLength);
495
+ let data;
496
+ try {
497
+ data = (await readSheet(input, 1));
498
+ }
499
+ catch {
500
+ return fail(MALFORMED);
501
+ }
502
+ const [headers = [], ...rows] = trimTable(data.map((row) => row.map(xlsxCellText)));
503
+ if (headers.length > limits.columns || rows.length > limits.rows - 1)
504
+ fail(sizeMessage(limits));
505
+ return { headers, rows };
506
+ }
507
+ /** The built-in Excel adapter: the first sheet of an .xlsx workbook, checked by guardXlsx. */
508
+ export const xlsxImportAdapter = {
509
+ name: 'xlsx',
510
+ extensions: ['xlsx'],
511
+ mimeTypes: [XLSX_MIME_TYPE],
512
+ binary: true,
513
+ detect: (file) => extensionOf(file.fileName) === 'xlsx' ||
514
+ (file.bytes[0] === 0x50 &&
515
+ file.bytes[1] === 0x4b &&
516
+ file.bytes[2] === 3 &&
517
+ file.bytes[3] === 4),
518
+ parse: (file) => readXlsxTable(file.bytes),
519
+ };
@@ -110,6 +110,15 @@ export const arabicMessages = Object.freeze({
110
110
  'errors.E_SELF_ADMIN_ACCESS': 'لا يمكنك إزالة صلاحية إدارة النظام من حسابك الحالي. اطلب من مدير آخر تعديلها.',
111
111
  'errors.E_MAIL_TEST_COOLDOWN': 'انتظر قليلًا قبل إعادة إرسال البريد التجريبي',
112
112
  'errors.E_MAIL_TEST_SEND': 'تعذّر إرسال البريد التجريبي. راجع إعدادات البريد ثم أعد المحاولة.',
113
+ 'errors.E_MAIL_TEST_SEND.authentication': 'رفض خادم البريد اسم المستخدم أو كلمة المرور. راجع SMTP_USERNAME وSMTP_PASSWORD، واستخدم كلمة مرور التطبيق إن طلبها مزودك.',
114
+ 'errors.E_MAIL_TEST_SEND.connection': 'رفض خادم البريد الاتصال. راجع SMTP_HOST وSMTP_PORT، وتأكد أن الجدار الناري يسمح بالمنفذ.',
115
+ 'errors.E_MAIL_TEST_SEND.host_not_found': 'تعذّر العثور على خادم البريد. راجع كتابة SMTP_HOST.',
116
+ 'errors.E_MAIL_TEST_SEND.tls': 'فشل الاتصال المشفّر بخادم البريد. استخدم SMTP_SECURE=true مع المنفذ 465، أو SMTP_SECURE=false مع المنفذ 587.',
117
+ 'errors.E_MAIL_TEST_SEND.timeout': 'انتهت مهلة الاتصال بخادم البريد. راجع SMTP_HOST وSMTP_PORT، وتأكد أن الخادم يسمح بالاتصال الصادر.',
118
+ 'errors.E_MAIL_TEST_SEND.sender_rejected': 'رفض خادم البريد عنوان المرسل. استخدم في MAIL_FROM_ADDRESS عنوانًا موثّقًا لدى مزودك.',
119
+ 'errors.E_MAIL_TEST_SEND.recipient_rejected': 'رفض خادم البريد عنوان المستلم. راجع بريد حسابك ثم أعد المحاولة.',
120
+ 'errors.E_MAIL_TEST_SEND.password_unreadable': 'تعذّر فتح كلمة مرور البريد المحفوظة، غالبًا بعد تغيير APP_KEY. أدخل كلمة المرور من جديد في تبويب «البريد»، ثم أعد المحاولة.',
121
+ 'errors.E_MAIL_NOT_CONFIGURED': 'إعداد البريد غير مكتمل. افتح «إعداد البريد» وأكمل المتغيرات الناقصة، ثم أعد تشغيل الخادم.',
113
122
  'errors.E_MAIL_TEST_ANSWER': 'اختر هل وصلت الرسالة أم لم تصل',
114
123
  'errors.E_MAIL_TEST_STALE': 'هذه التجربة لم تعد قابلة للتأكيد. أرسل رسالة تجريبية جديدة.',
115
124
  'errors.E_TEMPLATE_SUBJECT': 'العنوان مطلوب ولا يتجاوز 200 حرف',
@@ -221,6 +230,15 @@ export const arabicMessages = Object.freeze({
221
230
  'errors.E_FORBIDDEN.7': 'ليس لديك صلاحية لرفع مرفق لهذا الحقل',
222
231
  'errors.E_UPLOAD_LIMIT': 'لديك ملفات مرفوعة كثيرة لم تُحفظ في سجل. احفظ السجلات المفتوحة أو انتظر حتى تُنظَّف.',
223
232
  'errors.E_FILE_REQUIRED': 'اختر ملفاً للرفع',
233
+ 'errors.E_AVATAR_TYPE': 'الصورة الشخصية يجب أن تكون بصيغة PNG أو WebP',
234
+ 'errors.E_AVATAR_TYPE.animated': 'الصورة الشخصية يجب أن تكون صورة ثابتة',
235
+ 'errors.E_AVATAR_CORRUPT': 'ملف الصورة تالف أو غير مكتمل',
236
+ 'errors.E_AVATAR_SIZE': 'حجم الصورة الشخصية يتجاوز ١ ميغابايت',
237
+ 'errors.E_AVATAR_DIMENSIONS': 'أبعاد الصورة الشخصية يجب أن تكون بين ٣٢ و٥١٢ بكسل',
238
+ 'errors.E_AVATAR_REQUIRED': 'اختر صورة للرفع',
239
+ 'errors.E_AVATAR_IMPERSONATING': 'لا يمكن تغيير الصورة الشخصية أثناء انتحال الهوية',
240
+ 'flash.avatar.updated': 'تم حفظ الصورة الشخصية.',
241
+ 'flash.avatar.removed': 'تمت إزالة الصورة الشخصية.',
224
242
  'errors.E_ATTACHMENT_FILE_MISSING': 'ملف المرفق غير متاح على وحدة التخزين',
225
243
  'flash.password_reset_controller.1': 'إن كان البريد مسجلاً لدينا فستصلك رسالة تحوي رابط إعادة التعيين خلال دقائق.',
226
244
  'flash.password_reset_controller.2': 'رابط إعادة التعيين غير صالح أو انتهت صلاحيته. اطلب رابطاً جديداً.',
@@ -232,6 +250,7 @@ export const arabicMessages = Object.freeze({
232
250
  'flash.user_invitations_controller.1': 'تم إرسال الدعوة بالبريد. يمكن إعادة إرسالها بعد دقيقة؛ عندها يُلغى الرابط السابق.',
233
251
  'flash.user_invitations_controller.2': 'تم إنشاء حسابك. سجّل الدخول بكلمة مرورك الجديدة؛ يعيّن المسؤول صلاحيات العمل.',
234
252
  'errors.E_BAD_CSRF_TOKEN': 'انتهت صلاحية الطلب. حدّث الصفحة وحاول مجدداً.',
253
+ 'errors.E_UNAUTHORIZED_ACCESS': 'سجّل الدخول للمتابعة.',
235
254
  'errors.E_FORBIDDEN.8': 'هذه المنطقة للمديرين فقط',
236
255
  'errors.E_ACCOUNT_DISABLED': 'هذا الحساب معطّل',
237
256
  'errors.E_TOKEN_SCOPE': 'صلاحية الرمز لا تسمح بهذا الطلب',
@@ -248,6 +267,8 @@ export const arabicMessages = Object.freeze({
248
267
  'errors.E_ROUTE_NOT_FOUND.1': 'الصفحة غير موجودة',
249
268
  'errors.E_ROUTE_NOT_FOUND.2': 'الجلسة غير موجودة',
250
269
  'errors.E_FORBIDDEN.9': 'غير مصرح لك بالوصول إلى هذه الصفحة',
270
+ 'errors.parentView': 'حفظ {child} يتطلب صلاحية عرض {parent}',
271
+ 'errors.E_FORBIDDEN.10': 'مشاركة العرض تتطلب صلاحية تعديل هذا الكيان',
251
272
  'errors.E_TOO_MANY_REQUESTS': 'محاولات كثيرة في وقت قصير. انتظر دقيقة ثم حاول مجدداً.',
252
273
  'errors.E_IMPORT_FILE.4': 'اختر ملف CSV',
253
274
  'errors.E_NOT_FOUND.4': 'المعرّف غير صالح',
@@ -314,6 +335,7 @@ export const arabicMessages = Object.freeze({
314
335
  'list.value.yes': 'نعم',
315
336
  'list.value.no': 'لا',
316
337
  'list.value.none': 'غير محدد',
338
+ 'list.value.unavailable': 'سجل غير متاح',
317
339
  'list.status.0': 'مسودة',
318
340
  'list.status.1': 'معتمد',
319
341
  'list.status.2': 'ملغي',