adula 2.1.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 (269) hide show
  1. package/README.md +149 -18
  2. package/build/agent/AGENTS.template.md +4 -4
  3. package/build/agent/capabilities.md +22 -12
  4. package/build/agent/skills/adula-frontend-design/SKILL.md +6 -4
  5. package/build/agent/skills/idea-review/SKILL.md +2 -2
  6. package/build/commands/adula_assistant_prune.d.ts +10 -0
  7. package/build/commands/adula_assistant_prune.js +12 -0
  8. package/build/commands/adula_outbox.d.ts +10 -0
  9. package/build/commands/adula_outbox.js +11 -0
  10. package/build/commands/adula_restore_reconcile.d.ts +10 -0
  11. package/build/commands/adula_restore_reconcile.js +34 -0
  12. package/build/commands/adula_runtime_health.d.ts +10 -0
  13. package/build/commands/adula_runtime_health.js +27 -0
  14. package/build/commands/adula_uploads_prune.d.ts +10 -0
  15. package/build/commands/adula_uploads_prune.js +16 -0
  16. package/build/commands/app.d.ts +10 -0
  17. package/build/commands/app.js +64 -0
  18. package/build/commands/backup_create.d.ts +11 -0
  19. package/build/commands/backup_create.js +99 -0
  20. package/build/commands/backup_open.d.ts +16 -0
  21. package/build/commands/backup_open.js +48 -0
  22. package/build/commands/backup_restore_files.d.ts +11 -0
  23. package/build/commands/backup_restore_files.js +44 -0
  24. package/build/commands/backup_restore_test.d.ts +12 -0
  25. package/build/commands/backup_restore_test.js +188 -0
  26. package/build/commands/backup_seal.d.ts +12 -0
  27. package/build/commands/backup_seal.js +36 -0
  28. package/build/commands/backup_services.d.ts +33 -0
  29. package/build/commands/backup_services.js +6 -0
  30. package/build/commands/backup_verify.d.ts +9 -0
  31. package/build/commands/backup_verify.js +59 -0
  32. package/build/commands/backup_verify_snapshot.d.ts +10 -0
  33. package/build/commands/backup_verify_snapshot.js +37 -0
  34. package/build/commands/client.d.ts +16 -0
  35. package/build/commands/client.js +71 -0
  36. package/build/commands/doctor.js +21 -1
  37. package/build/commands/install.d.ts +8 -0
  38. package/build/commands/install.js +69 -45
  39. package/build/commands/main.d.ts +3 -2
  40. package/build/commands/main.js +32 -0
  41. package/build/commands/module_add.js +4 -20
  42. package/build/commands/resource.d.ts +2 -0
  43. package/build/commands/resource.js +12 -3
  44. package/build/commands/resource_migration.d.ts +15 -0
  45. package/build/commands/resource_migration.js +81 -0
  46. package/build/commands/resource_snapshot.d.ts +2 -0
  47. package/build/commands/resource_snapshot.js +21 -4
  48. package/build/commands/sla_evaluate.d.ts +14 -0
  49. package/build/commands/sla_evaluate.js +16 -0
  50. package/build/commands/ui.js +4 -2
  51. package/build/commands/ui_css.d.ts +9 -0
  52. package/build/commands/ui_css.js +19 -0
  53. package/build/commands/upgrade.d.ts +1 -1
  54. package/build/commands/upgrade.js +1 -1
  55. package/build/configure.js +1 -1
  56. package/build/database/migrations/1770000000020_two_factor.d.ts +5 -0
  57. package/build/database/migrations/1770000000020_two_factor.js +10 -0
  58. package/build/database/migrations/1770000000041_import_modes.d.ts +5 -0
  59. package/build/database/migrations/1770000000041_import_modes.js +10 -0
  60. package/build/database/migrations/1770000000042_sync_jobs.d.ts +5 -0
  61. package/build/database/migrations/1770000000042_sync_jobs.js +10 -0
  62. package/build/database/migrations/1770000000043_notification_channels.d.ts +5 -0
  63. package/build/database/migrations/1770000000043_notification_channels.js +10 -0
  64. package/build/database/migrations/1770000000044_channel_confirmations.d.ts +5 -0
  65. package/build/database/migrations/1770000000044_channel_confirmations.js +10 -0
  66. package/build/database/migrations/1770000000045_import_leases.d.ts +5 -0
  67. package/build/database/migrations/1770000000045_import_leases.js +10 -0
  68. package/build/database/migrations/1770000000046_workflow_delegation_sla.d.ts +5 -0
  69. package/build/database/migrations/1770000000046_workflow_delegation_sla.js +10 -0
  70. package/build/database/migrations/1770000000049_print_templates.d.ts +5 -0
  71. package/build/database/migrations/1770000000049_print_templates.js +10 -0
  72. package/build/database/migrations/1770000000051_comment_notifications.d.ts +5 -0
  73. package/build/database/migrations/1770000000051_comment_notifications.js +10 -0
  74. package/build/database/migrations/1770000000054_cloud_backups.d.ts +5 -0
  75. package/build/database/migrations/1770000000054_cloud_backups.js +10 -0
  76. package/build/database/migrations/1770000000055_ai_assistant.d.ts +5 -0
  77. package/build/database/migrations/1770000000055_ai_assistant.js +10 -0
  78. package/build/database/migrations/1770000000056_appearance.d.ts +5 -0
  79. package/build/database/migrations/1770000000056_appearance.js +10 -0
  80. package/build/index.d.ts +87 -11
  81. package/build/index.js +50 -7
  82. package/build/providers/adula_provider.d.ts +2 -0
  83. package/build/providers/adula_provider.js +7 -0
  84. package/build/src/admin/contracts.js +1 -1
  85. package/build/src/admin/controller.d.ts +14 -1
  86. package/build/src/admin/controller.js +91 -13
  87. package/build/src/admin/errors.d.ts +32 -0
  88. package/build/src/admin/errors.js +63 -1
  89. package/build/src/admin/presentation.d.ts +21 -2
  90. package/build/src/admin/resource/editor.d.ts +60 -0
  91. package/build/src/admin/resource/editor.js +345 -0
  92. package/build/src/admin/resource/export.d.ts +54 -0
  93. package/build/src/admin/resource/export.js +262 -0
  94. package/build/src/admin/resource/lifecycle.d.ts +23 -0
  95. package/build/src/admin/resource/lifecycle.js +91 -0
  96. package/build/src/admin/resource/query.d.ts +111 -0
  97. package/build/src/admin/resource/query.js +595 -0
  98. package/build/src/admin/resource/read.d.ts +109 -0
  99. package/build/src/admin/resource/read.js +388 -0
  100. package/build/src/admin/resource/shared.d.ts +93 -0
  101. package/build/src/admin/resource/shared.js +265 -0
  102. package/build/src/admin/resource/trash.d.ts +10 -0
  103. package/build/src/admin/resource/trash.js +56 -0
  104. package/build/src/admin/resource/write.d.ts +57 -0
  105. package/build/src/admin/resource/write.js +603 -0
  106. package/build/src/admin/resource_service.d.ts +80 -193
  107. package/build/src/admin/resource_service.js +81 -1343
  108. package/build/src/admin/resource_tools.d.ts +111 -0
  109. package/build/src/admin/resource_tools.js +139 -0
  110. package/build/src/ai/assistant.d.ts +100 -0
  111. package/build/src/ai/assistant.js +487 -0
  112. package/build/src/ai/client.d.ts +49 -0
  113. package/build/src/ai/client.js +85 -0
  114. package/build/src/ai/prompt.d.ts +23 -0
  115. package/build/src/ai/prompt.js +83 -0
  116. package/build/src/ai/settings.d.ts +56 -0
  117. package/build/src/ai/settings.js +214 -0
  118. package/build/src/ai/usage.d.ts +16 -0
  119. package/build/src/ai/usage.js +33 -0
  120. package/build/src/appearance/appearance.d.ts +134 -0
  121. package/build/src/appearance/appearance.js +461 -0
  122. package/build/src/appearance/colors.d.ts +43 -0
  123. package/build/src/appearance/colors.js +99 -0
  124. package/build/src/appearance/logo.d.ts +32 -0
  125. package/build/src/appearance/logo.js +112 -0
  126. package/build/src/attachments/attachment_service.d.ts +46 -2
  127. package/build/src/attachments/attachment_service.js +96 -4
  128. package/build/src/auth/actor_store.d.ts +5 -1
  129. package/build/src/auth/actor_store.js +8 -4
  130. package/build/src/auth/conditions.d.ts +5 -0
  131. package/build/src/auth/conditions.js +26 -3
  132. package/build/src/auth/sql.js +17 -5
  133. package/build/src/auth/two_factor.d.ts +96 -0
  134. package/build/src/auth/two_factor.js +259 -0
  135. package/build/src/backups/archive.d.ts +52 -0
  136. package/build/src/backups/archive.js +362 -0
  137. package/build/src/backups/cloud_backups.d.ts +133 -0
  138. package/build/src/backups/cloud_backups.js +650 -0
  139. package/build/src/backups/doctor.d.ts +7 -0
  140. package/build/src/backups/doctor.js +55 -0
  141. package/build/src/backups/providers.d.ts +81 -0
  142. package/build/src/backups/providers.js +470 -0
  143. package/build/src/collaboration/assignments.d.ts +59 -2
  144. package/build/src/collaboration/assignments.js +196 -74
  145. package/build/src/collaboration/record_collaboration.d.ts +21 -4
  146. package/build/src/collaboration/record_collaboration.js +126 -51
  147. package/build/src/collaboration/shared.d.ts +24 -0
  148. package/build/src/collaboration/shared.js +34 -0
  149. package/build/src/commands/app_scaffold.d.ts +72 -0
  150. package/build/src/commands/app_scaffold.js +285 -0
  151. package/build/src/commands/capabilities.js +35 -9
  152. package/build/src/commands/doctor.d.ts +24 -2
  153. package/build/src/commands/doctor.js +81 -6
  154. package/build/src/commands/gap_report.d.ts +1 -1
  155. package/build/src/commands/gap_report.js +2 -2
  156. package/build/src/commands/generator.d.ts +37 -1
  157. package/build/src/commands/generator.js +61 -18
  158. package/build/src/commands/snapshot.d.ts +24 -13
  159. package/build/src/commands/snapshot.js +54 -14
  160. package/build/src/commands/source_markers.d.ts +10 -0
  161. package/build/src/commands/source_markers.js +29 -0
  162. package/build/src/core/activity.d.ts +2 -0
  163. package/build/src/core/activity.js +7 -1
  164. package/build/src/core/administrators.d.ts +38 -0
  165. package/build/src/core/administrators.js +145 -0
  166. package/build/src/core/avatar_image.d.ts +33 -0
  167. package/build/src/core/avatar_image.js +278 -0
  168. package/build/src/core/html_sanitizer.d.ts +20 -0
  169. package/build/src/core/html_sanitizer.js +261 -0
  170. package/build/src/core/like.d.ts +5 -0
  171. package/build/src/core/like.js +5 -0
  172. package/build/src/core/lookups.d.ts +80 -0
  173. package/build/src/core/lookups.js +319 -0
  174. package/build/src/core/mail_settings.d.ts +83 -0
  175. package/build/src/core/mail_settings.js +274 -0
  176. package/build/src/core/mail_test.d.ts +16 -0
  177. package/build/src/core/mail_test.js +81 -6
  178. package/build/src/core/message_templates.d.ts +15 -2
  179. package/build/src/core/message_templates.js +81 -11
  180. package/build/src/core/module_seed.js +2 -1
  181. package/build/src/core/notification_channels.d.ts +235 -0
  182. package/build/src/core/notification_channels.js +660 -0
  183. package/build/src/core/roles.js +26 -9
  184. package/build/src/core/saved_views.d.ts +8 -1
  185. package/build/src/core/saved_views.js +91 -26
  186. package/build/src/core/sequences.d.ts +32 -0
  187. package/build/src/core/sequences.js +97 -0
  188. package/build/src/core/settings.d.ts +5 -0
  189. package/build/src/core/settings.js +31 -3
  190. package/build/src/core/template_language.d.ts +61 -0
  191. package/build/src/core/template_language.js +141 -0
  192. package/build/src/core/ui_preferences.d.ts +10 -0
  193. package/build/src/core/ui_preferences.js +15 -1
  194. package/build/src/core/user_avatars.d.ts +79 -0
  195. package/build/src/core/user_avatars.js +186 -0
  196. package/build/src/core/user_invitations.d.ts +5 -1
  197. package/build/src/core/user_invitations.js +7 -1
  198. package/build/src/core/user_preferences.d.ts +36 -0
  199. package/build/src/core/user_preferences.js +125 -0
  200. package/build/src/core/users.d.ts +2 -0
  201. package/build/src/core/users.js +5 -3
  202. package/build/src/database/calendar_days.d.ts +19 -0
  203. package/build/src/database/calendar_days.js +36 -0
  204. package/build/src/database/schema.d.ts +201 -2
  205. package/build/src/database/schema.js +713 -59
  206. package/build/src/database/schema_diff.d.ts +70 -0
  207. package/build/src/database/schema_diff.js +190 -0
  208. package/build/src/events/record_mutation.d.ts +2 -1
  209. package/build/src/events/record_mutation.js +1 -0
  210. package/build/src/integrations/api_client.d.ts +37 -0
  211. package/build/src/integrations/api_client.js +567 -0
  212. package/build/src/integrations/import_adapters.d.ts +37 -0
  213. package/build/src/integrations/import_adapters.js +35 -0
  214. package/build/src/integrations/imports.d.ts +130 -16
  215. package/build/src/integrations/imports.js +434 -73
  216. package/build/src/integrations/openapi.d.ts +3 -1
  217. package/build/src/integrations/openapi.js +465 -31
  218. package/build/src/integrations/outbound.d.ts +94 -0
  219. package/build/src/integrations/outbound.js +276 -0
  220. package/build/src/integrations/print.d.ts +22 -1
  221. package/build/src/integrations/print.js +68 -22
  222. package/build/src/integrations/print_templates.d.ts +216 -0
  223. package/build/src/integrations/print_templates.js +1017 -0
  224. package/build/src/integrations/sync_jobs.d.ts +139 -0
  225. package/build/src/integrations/sync_jobs.js +416 -0
  226. package/build/src/integrations/webhooks.d.ts +12 -12
  227. package/build/src/integrations/webhooks.js +34 -43
  228. package/build/src/integrations/xlsx.d.ts +41 -0
  229. package/build/src/integrations/xlsx.js +519 -0
  230. package/build/src/languages/ar.d.ts +11 -0
  231. package/build/src/languages/ar.js +358 -0
  232. package/build/src/languages/ar_ui.d.ts +461 -0
  233. package/build/src/languages/ar_ui.js +464 -0
  234. package/build/src/languages/catalog.d.ts +66 -0
  235. package/build/src/languages/catalog.js +152 -0
  236. package/build/src/languages/en.d.ts +7 -0
  237. package/build/src/languages/en.js +352 -0
  238. package/build/src/languages/en_ui.d.ts +3 -0
  239. package/build/src/languages/en_ui.js +458 -0
  240. package/build/src/languages/validation.d.ts +26 -0
  241. package/build/src/languages/validation.js +60 -0
  242. package/build/src/lists/bulk_actions.d.ts +89 -0
  243. package/build/src/lists/bulk_actions.js +268 -0
  244. package/build/src/lists/dashboards.d.ts +138 -0
  245. package/build/src/lists/dashboards.js +290 -0
  246. package/build/src/mcp/tools.js +9 -104
  247. package/build/src/resource/define_resource.d.ts +18 -1
  248. package/build/src/resource/define_resource.js +212 -18
  249. package/build/src/resource/definition.d.ts +44 -0
  250. package/build/src/resource/definition.js +171 -0
  251. package/build/src/resource/registry.js +15 -4
  252. package/build/src/resource/types.d.ts +313 -16
  253. package/build/src/resource/values.d.ts +56 -1
  254. package/build/src/resource/values.js +237 -5
  255. package/build/src/services/settings.d.ts +2 -0
  256. package/build/src/services/settings.js +5 -1
  257. package/build/src/upgrade/legacy.js +2 -2
  258. package/build/src/workflows/calendar.d.ts +9 -0
  259. package/build/src/workflows/calendar.js +44 -0
  260. package/build/src/workflows/define_workflow.d.ts +48 -3
  261. package/build/src/workflows/define_workflow.js +57 -13
  262. package/build/src/workflows/delegations.d.ts +107 -0
  263. package/build/src/workflows/delegations.js +326 -0
  264. package/build/src/workflows/engine.d.ts +80 -4
  265. package/build/src/workflows/engine.js +466 -86
  266. package/build/src/workflows/sla.d.ts +15 -0
  267. package/build/src/workflows/sla.js +8 -0
  268. package/build/stubs/resource_contract.txt +12 -1
  269. package/package.json +9 -2
@@ -1,8 +1,7 @@
1
1
  import { createHmac, randomBytes, randomUUID } from 'node:crypto';
2
- import { lookup } from 'node:dns/promises';
3
- import { isIP } from 'node:net';
4
2
  import { AdulaError } from '../admin/errors.js';
5
3
  import { notifyWithTemplate } from '../core/message_templates.js';
4
+ import { OutboundTargetError, createOutboundPoster, outboundErrorCategory, resolveOutboundTarget, } from './outbound.js';
6
5
  const EVENT_VERBS = ['created', 'updated', 'deleted', 'submitted', 'cancelled', 'amended'];
7
6
  const BACKOFF_MINUTES = [1, 5, 30, 120, 720];
8
7
  export const WEBHOOK_MAX_ATTEMPTS = BACKOFF_MINUTES.length + 1;
@@ -11,30 +10,6 @@ const NAME_LIMIT = 100;
11
10
  export function signWebhook(secret, timestamp, body) {
12
11
  return createHmac('sha256', secret).update(`${timestamp}.${body}`).digest('hex');
13
12
  }
14
- function privateAddress(address) {
15
- if (isIP(address) === 6) {
16
- const lower = address.toLowerCase();
17
- if (lower.startsWith('::ffff:'))
18
- return privateAddress(lower.slice(7));
19
- return (lower === '::1' ||
20
- lower === '::' ||
21
- lower.startsWith('fc') ||
22
- lower.startsWith('fd') ||
23
- lower.startsWith('fe8') ||
24
- lower.startsWith('fe9') ||
25
- lower.startsWith('fea') ||
26
- lower.startsWith('feb'));
27
- }
28
- const [a, b] = address.split('.').map(Number);
29
- return (a === 10 ||
30
- a === 127 ||
31
- a === 0 ||
32
- (a === 169 && b === 254) ||
33
- (a === 172 && b >= 16 && b <= 31) ||
34
- (a === 192 && b === 168) ||
35
- (a === 100 && b >= 64 && b <= 127) ||
36
- a >= 224);
37
- }
38
13
  /**
39
14
  * Outgoing webhooks: administrators subscribe HTTPS endpoints to domain events.
40
15
  * Deliveries are queued exactly once per event inside the listener transaction,
@@ -150,7 +125,7 @@ export class Webhooks {
150
125
  * Sends due deliveries. Each row is claimed with SKIP LOCKED; a crash after the
151
126
  * HTTP call may repeat a delivery, so receivers deduplicate on X-Adula-Delivery.
152
127
  */
153
- async deliver(post, limit = 20) {
128
+ async deliver(post = createOutboundPoster(this.options), limit = 20) {
154
129
  const claimed = await this.db.transaction(async (trx) => {
155
130
  const rows = await trx('webhook_deliveries as d')
156
131
  .join('webhooks as w', 'w.id', 'd.webhook_id')
@@ -179,9 +154,12 @@ export class Webhooks {
179
154
  let error = null;
180
155
  try {
181
156
  const secret = this.secrets.open(String(row.secret));
182
- if (!secret)
157
+ if (!secret) {
158
+ error = 'secret';
183
159
  throw new Error('Webhook secret cannot be opened with the current key');
184
- await this.assertTarget(String(row.url));
160
+ }
161
+ // Resolve once; the poster connects to this validated address only.
162
+ const target = await this.resolveTarget(String(row.url));
185
163
  const response = await post(String(row.url), {
186
164
  headers: {
187
165
  'Content-Type': 'application/json',
@@ -193,13 +171,15 @@ export class Webhooks {
193
171
  },
194
172
  body,
195
173
  signal: AbortSignal.timeout(10000),
174
+ target,
196
175
  });
197
176
  status = response.status;
198
177
  if (status < 200 || status >= 300)
199
- error = `HTTP ${status}`;
178
+ error = `http-status:${status}`;
200
179
  }
201
180
  catch (caught) {
202
- error = String(caught?.message ?? caught).slice(0, 500);
181
+ // Store a category only; raw messages may echo internal hosts or bodies.
182
+ error ??= outboundErrorCategory(caught);
203
183
  }
204
184
  if (!error) {
205
185
  await this.db('webhook_deliveries').where('id', row.id).update({
@@ -258,6 +238,28 @@ export class Webhooks {
258
238
  }
259
239
  /** Refuses non-HTTPS URLs and hosts resolving to private addresses (SSRF). */
260
240
  async assertTarget(value) {
241
+ const url = this.parseTarget(value);
242
+ if (this.options.allowPrivateTargets === true)
243
+ return;
244
+ try {
245
+ await resolveOutboundTarget(url, this.options);
246
+ }
247
+ catch {
248
+ throw new AdulaError(422, 'E_WEBHOOK_URL', 'لا يُسمح بعناوين الشبكة الداخلية');
249
+ }
250
+ }
251
+ /** Re-validates a stored URL at delivery time and returns the address to pin. */
252
+ async resolveTarget(value) {
253
+ let url;
254
+ try {
255
+ url = this.parseTarget(value);
256
+ }
257
+ catch {
258
+ throw new OutboundTargetError('blocked-target');
259
+ }
260
+ return resolveOutboundTarget(url, this.options);
261
+ }
262
+ parseTarget(value) {
261
263
  let url;
262
264
  try {
263
265
  url = new URL(value);
@@ -270,18 +272,7 @@ export class Webhooks {
270
272
  throw new AdulaError(422, 'E_WEBHOOK_URL', 'يجب أن يبدأ العنوان بـ https://');
271
273
  if (url.username || url.password || value.length > 2000)
272
274
  throw new AdulaError(422, 'E_WEBHOOK_URL', 'عنوان URL غير مسموح');
273
- if (allowPrivate)
274
- return;
275
- const host = url.hostname.replace(/^\[|\]$/g, '');
276
- const addresses = isIP(host)
277
- ? [host]
278
- : await (this.options.resolve ??
279
- (async (name) => {
280
- const entries = await lookup(name, { all: true });
281
- return entries.map((entry) => entry.address);
282
- }))(host).catch(() => []);
283
- if (!addresses.length || addresses.some(privateAddress))
284
- throw new AdulaError(422, 'E_WEBHOOK_URL', 'لا يُسمح بعناوين الشبكة الداخلية');
275
+ return url;
285
276
  }
286
277
  present(row) {
287
278
  return {
@@ -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;
@@ -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
+ };