@deveye/types 0.26.1 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveye/types",
3
- "version": "0.26.1",
3
+ "version": "0.27.0",
4
4
  "description": "Shared contracts (types + zod schemas) for DevEye apps",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -296,9 +296,12 @@ export const FEATURE_REGISTRY: readonly (FeatureDescriptor & { id: WorkspaceFeat
296
296
  id: 'cve',
297
297
  label: 'Veille CVE',
298
298
  description:
299
- 'Lecture : le fil des vulnérabilités et la recherche. Écriture : épingler, et poser la clé du NVD.',
299
+ 'Lecture : ce qui touche l’espace, l’inventaire, le fil des vulnérabilités et la recherche. Écriture : ignorer un constat, relire ou sortir un élément de la veille, régler la détection, épingler, et poser la clé du NVD.',
300
300
  icon: 'bug',
301
- notifies: false,
301
+ notifies: true,
302
+ notifications: {
303
+ hint: 'Envoyées quand une faille publiée touche ce que l’espace fait tourner : un dépôt, et ce qu’il emploie. Une alerte par faille, qui nomme les éléments touchés ; chaque genre d’alerte se coupe dans l’onglet Détection.'
304
+ },
302
305
  hasItems: false,
303
306
  shareTier: 'never',
304
307
  sources: {
@@ -383,6 +386,24 @@ export const FEATURE_REGISTRY: readonly (FeatureDescriptor & { id: WorkspaceFeat
383
386
  hasItems: true,
384
387
  itemNoun: 'tableau',
385
388
  shareTier: 'open'
389
+ },
390
+ {
391
+ id: 'appstores',
392
+ label: 'Stores',
393
+ description:
394
+ 'Lecture : les téléchargements, les notes et les avis des apps. Écriture : suivre une app, relier un compte de store, répondre aux avis. Les revenus demandent leur propre permission.',
395
+ icon: 'appstores',
396
+ notifies: true,
397
+ notifications: {
398
+ hint: 'Envoyées à l’arrivée de nouveaux avis, quand Apple change l’état d’une version, quand le taux de plantage d’une app franchit le seuil de Google Play, et quand un compte de store refuse sa clé puis l’accepte de nouveau.'
399
+ },
400
+ hasItems: true,
401
+ itemNoun: 'app',
402
+ itemNounGender: 'f',
403
+ sources: {
404
+ hint: 'Les comptes App Store Connect et Google Play de l’espace, chacun avec sa clé. Chaque app choisit le sien pour chaque store ; ses chiffres et ses avis arrivent alors seuls.'
405
+ },
406
+ shareTier: 'open'
386
407
  }
387
408
  ];
388
409
 
@@ -518,7 +539,8 @@ export const PROJECT_LINKED_FEATURES: readonly FeatureId[] = [
518
539
  'deploy',
519
540
  'uptime',
520
541
  'x-hosting',
521
- 'whiteboard'
542
+ 'whiteboard',
543
+ 'appstores'
522
544
  ];
523
545
 
524
546
  /** Les fonctionnalités qui savent prévenir, dans l'ordre du registre. */
@@ -43,7 +43,8 @@ export const nativeHomeFeatureIdSchema = z.enum([
43
43
  'pdf',
44
44
  'invoicing',
45
45
  'shortlinks',
46
- 'whiteboard'
46
+ 'whiteboard',
47
+ 'appstores'
47
48
  ]);
48
49
  export type NativeHomeFeatureId = z.infer<typeof nativeHomeFeatureIdSchema>;
49
50
 
@@ -224,6 +224,7 @@ export const TOPIC_FEATURE: Record<NativeLiveTopic, WorkspaceFeatureId | null> =
224
224
  invoicing: 'invoicing',
225
225
  shortlinks: 'shortlinks',
226
226
  whiteboard: 'whiteboard',
227
+ appstores: 'appstores',
227
228
  workspace: null,
228
229
  home: null,
229
230
  account: null,
@@ -1,5 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
+ import { taskRosterSchema } from './task';
4
+
3
5
  /**
4
6
  * Maintenance, site-wide or per feature, set by the global admin (or by the
5
7
  * database and the `MAINTENANCE` variable when the interface is out of reach).
@@ -50,12 +52,15 @@ export const MAINTENANCE_MESSAGE_MAX = 1000;
50
52
  /**
51
53
  * The `session` frame that opens every socket. `version` is the server's app
52
54
  * version, which a client compares with its own bundle to reload after an
53
- * update. `version` and `maintenance` are optional: a remote instance on an
54
- * older version does not send them.
55
+ * update. `tasks` is what the operations area of the account shows, so a page
56
+ * that reloads finds its long operations again. `version`, `maintenance` and
57
+ * `tasks` are optional: a remote instance on an older version does not send
58
+ * them.
55
59
  */
56
60
  export const sessionFrameSchema = z.object({
57
61
  userId: z.number().int().positive(),
58
62
  version: z.string().optional(),
59
- maintenance: maintenanceStateSchema.optional()
63
+ maintenance: maintenanceStateSchema.optional(),
64
+ tasks: taskRosterSchema.optional()
60
65
  });
61
66
  export type SessionFrame = z.infer<typeof sessionFrameSchema>;
@@ -45,7 +45,9 @@ export const nativeNotificationFeatureSchema = z.enum([
45
45
  'convert',
46
46
  'invoicing',
47
47
  'finance',
48
- 'shortlinks'
48
+ 'shortlinks',
49
+ 'cve',
50
+ 'appstores'
49
51
  ]);
50
52
  export type NativeNotificationFeature = z.infer<typeof nativeNotificationFeatureSchema>;
51
53
 
@@ -0,0 +1,74 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+
4
+ import { sessionFrameSchema } from './maintenance';
5
+ import { taskRemovedSchema, taskRosterSchema, taskSchema } from './task';
6
+
7
+ const ID = '0b6f5e0a-2a57-4a55-9a56-0d7c1d2a3b4c';
8
+
9
+ const running = {
10
+ id: ID,
11
+ state: 'running',
12
+ title: 'Suppression du point de restauration',
13
+ subject: 'Documents',
14
+ feature: 'cloudsync',
15
+ itemId: '12',
16
+ key: 'snapshot.delete',
17
+ workspaceId: 3,
18
+ startedAt: 1_794_000_000_000,
19
+ endedAt: null,
20
+ progress: { done: 2, total: 8, step: 'Libération' },
21
+ cancellable: false,
22
+ done: 'Point de restauration supprimé.',
23
+ failed: 'Suppression impossible.',
24
+ error: null
25
+ };
26
+
27
+ describe('taskSchema', () => {
28
+ it('reads a running operation, measured or not', () => {
29
+ assert.equal(taskSchema.parse(running).progress?.done, 2);
30
+ assert.equal(taskSchema.parse({ ...running, progress: null }).progress, null);
31
+ assert.equal(taskSchema.parse({ ...running, progress: {} }).progress?.total, undefined);
32
+ });
33
+
34
+ it('carries the code and the sentence of a failure, nothing else', () => {
35
+ const failed = taskSchema.parse({
36
+ ...running,
37
+ state: 'failed',
38
+ endedAt: 1_794_000_009_000,
39
+ error: { code: 'conflict', message: 'Déjà en cours.', details: { input: 'secret' } }
40
+ });
41
+ assert.deepEqual(failed.error, { code: 'conflict', message: 'Déjà en cours.' });
42
+ assert.equal(
43
+ taskSchema.safeParse({
44
+ ...running,
45
+ state: 'failed',
46
+ error: { code: 'nope', message: 'x' }
47
+ }).success,
48
+ false
49
+ );
50
+ });
51
+
52
+ it('refuses a state the area does not know and an operation without a workspace', () => {
53
+ assert.equal(taskSchema.safeParse({ ...running, state: 'lost' }).success, false);
54
+ assert.equal(taskSchema.safeParse({ ...running, workspaceId: 0 }).success, false);
55
+ });
56
+ });
57
+
58
+ describe('the roster of the session frame', () => {
59
+ it('travels with the frame, which stays valid without it', () => {
60
+ const frame = { userId: 1, version: '0.26.1' };
61
+ assert.equal(sessionFrameSchema.parse(frame).tasks, undefined);
62
+ const withTasks = sessionFrameSchema.parse({
63
+ ...frame,
64
+ tasks: { epoch: 'a', list: [running] }
65
+ });
66
+ assert.equal(withTasks.tasks?.list[0]?.id, ID);
67
+ assert.equal(taskRosterSchema.safeParse({ epoch: '', list: [] }).success, false);
68
+ });
69
+
70
+ it('names the operations a dismissal removes', () => {
71
+ assert.deepEqual(taskRemovedSchema.parse({ ids: [ID] }).ids, [ID]);
72
+ assert.equal(taskRemovedSchema.safeParse({ ids: ['../x'] }).success, false);
73
+ });
74
+ });
@@ -0,0 +1,64 @@
1
+ import { z } from 'zod';
2
+
3
+ import {
4
+ TASK_TEXT_MAX,
5
+ TASK_TITLE_MAX,
6
+ requestProgressSchema,
7
+ taskIdSchema
8
+ } from '../protocol/envelope';
9
+ import { ErrorCodeSchema } from '../protocol/error';
10
+
11
+ /**
12
+ * A long operation, as the server follows it and as the operations area of the
13
+ * top bar shows it: a command a client tagged, or the work a service runs for
14
+ * an account. It belongs to the account that started it and is never shown to
15
+ * the other members of the workspace.
16
+ *
17
+ * The server keeps it in memory only: a restart forgets every operation, and
18
+ * the `epoch` of the roster tells a client that it happened.
19
+ */
20
+ export const taskStateSchema = z.enum(['running', 'done', 'failed']);
21
+ export type TaskState = z.infer<typeof taskStateSchema>;
22
+
23
+ export const taskSchema = z.object({
24
+ id: taskIdSchema,
25
+ state: taskStateSchema,
26
+ title: z.string().max(TASK_TITLE_MAX),
27
+ subject: z.string().max(TASK_TEXT_MAX).nullable(),
28
+ feature: z.string().max(64).nullable(),
29
+ itemId: z.string().max(64).nullable(),
30
+ key: z.string().max(64).nullable(),
31
+ /** The workspace the command ran in. */
32
+ workspaceId: z.number().int().positive(),
33
+ /** Milliseconds since the epoch. */
34
+ startedAt: z.number().int(),
35
+ endedAt: z.number().int().nullable(),
36
+ progress: requestProgressSchema.omit({ requestId: true }).nullable(),
37
+ /** The account may ask it to stop (`task.cancel`): an operation a service runs and knows how to stop. */
38
+ cancellable: z.boolean(),
39
+ /** The caller's sentences, for a tab that did not start the operation. */
40
+ done: z.string().max(TASK_TEXT_MAX).nullable(),
41
+ failed: z.string().max(TASK_TEXT_MAX).nullable(),
42
+ /** Why it failed. Never the `details` of the refusal: they may quote the input. */
43
+ error: z.object({ code: ErrorCodeSchema, message: z.string().max(500) }).nullable()
44
+ });
45
+ export type TaskSnapshot = z.infer<typeof taskSchema>;
46
+
47
+ /** An operation appeared, moved on or ended. Payload: {@link taskSchema}. */
48
+ export const TASK_UPDATE_EVENT = 'task.update' as const;
49
+
50
+ /** Operations were dismissed, here or in another tab. */
51
+ export const TASK_REMOVED_EVENT = 'task.removed' as const;
52
+ export const taskRemovedSchema = z.object({ ids: z.array(taskIdSchema).max(200) });
53
+ export type TaskRemoved = z.infer<typeof taskRemovedSchema>;
54
+
55
+ /**
56
+ * The operations of the account when a socket opens, carried by the `session`
57
+ * frame. `epoch` changes with every start of the server: an operation a client
58
+ * still shows as running and that a new epoch does not list was interrupted.
59
+ */
60
+ export const taskRosterSchema = z.object({
61
+ epoch: z.string().min(1).max(64),
62
+ list: z.array(taskSchema).max(200)
63
+ });
64
+ export type TaskRoster = z.infer<typeof taskRosterSchema>;
@@ -125,7 +125,13 @@ export const workspaceFeatureIdSchema = z.enum([
125
125
  * dessine, `write` = créer un tableau, dessiner, y coller des images, le
126
126
  * renommer, le supprimer.
127
127
  */
128
- 'whiteboard'
128
+ 'whiteboard',
129
+ /**
130
+ * Stores. `read` = consulter les chiffres, les notes et les avis des apps,
131
+ * `write` = suivre une app, relier un compte de store et sa clé, répondre
132
+ * aux avis. Les revenus sont une permission propre du module.
133
+ */
134
+ 'appstores'
129
135
  ]);
130
136
 
131
137
  export type WorkspaceFeatureId = z.infer<typeof workspaceFeatureIdSchema>;
@@ -263,6 +263,24 @@ export const debugE2eSweep = {
263
263
  output: z.object({ accounts: z.number().int().nonnegative() })
264
264
  };
265
265
 
266
+ /**
267
+ * A slow command that reports its progress, then succeeds or fails on demand:
268
+ * what the gallery runs to show a long operation the server follows. `quiet`
269
+ * keeps it silent until the end, like a handler that reports nothing.
270
+ * `background` answers at once and lets the work go on as an operation a
271
+ * service runs, which the area can cancel.
272
+ */
273
+ export const debugTaskSample = {
274
+ command: 'debug.taskSample' as const,
275
+ input: z.object({
276
+ seconds: z.number().int().min(1).max(120),
277
+ fail: z.boolean().optional(),
278
+ quiet: z.boolean().optional(),
279
+ background: z.boolean().optional()
280
+ }),
281
+ output: z.object({ steps: z.number().int().nonnegative() })
282
+ };
283
+
266
284
  export const debugProbeSchema = z.object({
267
285
  id: z.string(),
268
286
  label: z.string(),
@@ -486,6 +504,7 @@ export const debugCommands = [
486
504
  debugE2eCatalog,
487
505
  debugE2eStart,
488
506
  debugE2eSweep,
507
+ debugTaskSample,
489
508
  debugBenchCatalog,
490
509
  debugBenchStart,
491
510
  debugPing,
@@ -112,6 +112,38 @@ export const notifyRouteTest = {
112
112
  output: notificationTestSchema
113
113
  };
114
114
 
115
+ /**
116
+ * The "nothing would be sent" notice of one page, as the caller left it: a
117
+ * feature's list in the envelope's workspace (no `itemId`), or an item's
118
+ * sheet. Hidden for that account only, until it brings them all back.
119
+ */
120
+ export const notifyNoticeGet = {
121
+ command: 'notify.noticeGet' as const,
122
+ input: notificationRouteTargetSchema,
123
+ output: z.object({ hidden: z.boolean() })
124
+ };
125
+
126
+ /** Hides that notice for the caller, on that page only. */
127
+ export const notifyNoticeHide = {
128
+ command: 'notify.noticeHide' as const,
129
+ input: notificationRouteTargetSchema,
130
+ output: z.object({})
131
+ };
132
+
133
+ /** How many pages the account hid the notice on, every workspace included. */
134
+ export const notifyNoticeCount = {
135
+ command: 'notify.noticeCount' as const,
136
+ input: z.object({}),
137
+ output: z.object({ count: z.number().int().nonnegative() })
138
+ };
139
+
140
+ /** Brings the notice back on every page the account hid it on. */
141
+ export const notifyNoticeReset = {
142
+ command: 'notify.noticeReset' as const,
143
+ input: z.object({}),
144
+ output: z.object({})
145
+ };
146
+
115
147
  export const notifyCommands = [
116
148
  notifyChannelList,
117
149
  notifyChannelAdd,
@@ -122,5 +154,9 @@ export const notifyCommands = [
122
154
  notifyChannelTest,
123
155
  notifyRouteGet,
124
156
  notifyRouteSet,
125
- notifyRouteTest
157
+ notifyRouteTest,
158
+ notifyNoticeGet,
159
+ notifyNoticeHide,
160
+ notifyNoticeCount,
161
+ notifyNoticeReset
126
162
  ] as const;
@@ -12,6 +12,7 @@ import { sharingCommands } from './sharing';
12
12
  import { secrecyCommands } from './secrecy';
13
13
  import { loginChecksCommands } from './loginChecks';
14
14
  import { stepUpCommands } from './stepUp';
15
+ import { taskCommands } from './task';
15
16
  import { twoFactorCommands } from './twoFactor';
16
17
  import { userCommands } from './user';
17
18
  import { adminCommands } from './admin';
@@ -33,6 +34,7 @@ export const featureCommands = [
33
34
  ...agentCommands,
34
35
  ...twoFactorCommands,
35
36
  ...stepUpCommands,
37
+ ...taskCommands,
36
38
  ...loginChecksCommands,
37
39
  ...secrecyCommands,
38
40
  ...logsCommands,
@@ -0,0 +1,44 @@
1
+ import { z } from 'zod';
2
+ import { taskIdSchema } from '../protocol/envelope';
3
+
4
+ /**
5
+ * Claims the operations whose request this page still awaits, after its socket
6
+ * came back: the server sends their answer to this socket when they end, or at
7
+ * once when they already have. `lost`: the ones it no longer knows (it
8
+ * restarted, the answer expired) or that this page did not start.
9
+ */
10
+ export const taskAttach = {
11
+ command: 'task.attach' as const,
12
+ input: z.object({
13
+ claims: z
14
+ .array(z.object({ id: taskIdSchema, requestId: z.string().min(1).max(64) }))
15
+ .min(1)
16
+ .max(50)
17
+ }),
18
+ output: z.object({ lost: z.array(taskIdSchema) })
19
+ };
20
+
21
+ /**
22
+ * Removes operations from the account's area, in every tab. On one that still
23
+ * runs it only stops following it: the command goes on. Unknown ids are
24
+ * ignored; the answer lists the ones removed.
25
+ */
26
+ export const taskDismiss = {
27
+ command: 'task.dismiss' as const,
28
+ input: z.object({ ids: z.array(taskIdSchema).min(1).max(50) }),
29
+ output: z.object({ ids: z.array(taskIdSchema) })
30
+ };
31
+
32
+ /**
33
+ * Asks a running operation to stop: one a service runs and declared it can
34
+ * stop. `accepted` is false when it cannot (not cancellable, already ended,
35
+ * the account lost the feature); the operation leaves the area when the
36
+ * service has actually stopped.
37
+ */
38
+ export const taskCancel = {
39
+ command: 'task.cancel' as const,
40
+ input: z.object({ id: taskIdSchema }),
41
+ output: z.object({ accepted: z.boolean() })
42
+ };
43
+
44
+ export const taskCommands = [taskAttach, taskDismiss, taskCancel] as const;
package/src/index.ts CHANGED
@@ -1,15 +1,29 @@
1
1
  export {
2
2
  clientMessageSchema,
3
+ commandTaskSchema,
3
4
  REQUEST_PROGRESS_EVENT,
4
5
  requestProgressSchema,
5
- serverMessageSchema
6
+ serverMessageSchema,
7
+ TASK_TEXT_MAX,
8
+ TASK_TITLE_MAX,
9
+ taskIdSchema
6
10
  } from './protocol/envelope';
7
11
  export type {
8
12
  ClientMessage,
13
+ CommandTask,
9
14
  ConnectionState,
10
15
  RequestProgress,
11
16
  ServerMessage
12
17
  } from './protocol/envelope';
18
+ export {
19
+ TASK_REMOVED_EVENT,
20
+ TASK_UPDATE_EVENT,
21
+ taskRemovedSchema,
22
+ taskRosterSchema,
23
+ taskSchema,
24
+ taskStateSchema
25
+ } from './domain/task';
26
+ export type { TaskRemoved, TaskRoster, TaskSnapshot, TaskState } from './domain/task';
13
27
  export { ErrorCodeSchema, ProtocolErrorSchema } from './protocol/error';
14
28
  export type { ErrorCode, ProtocolError } from './protocol/error';
15
29
  export { err, ok, resultSchema } from './protocol/result';
@@ -53,6 +67,12 @@ export {
53
67
  AGENT_DOCKER_DONE,
54
68
  AGENT_DOCKER_INVENTORY,
55
69
  AGENT_DOCKER_INVENTORY_RESULT,
70
+ AGENT_PKG_INVENTORY,
71
+ AGENT_PKG_INVENTORY_PROBE,
72
+ AGENT_PKG_INVENTORY_RESULT,
73
+ agentPkgInventoryResultPayloadSchema,
74
+ installedPackageSchema,
75
+ packageInventorySchema,
56
76
  AGENT_DOCKER_PROGRESS,
57
77
  AGENT_DOCKER_STATS,
58
78
  AGENT_DOCKER_STATS_RESULT,
@@ -326,8 +346,10 @@ export type {
326
346
  DeviceTermExitPush,
327
347
  DeviceTermOutputPush,
328
348
  MetricsPush,
349
+ InstalledPackage,
329
350
  PackageCountPush,
330
351
  PackageDonePush,
352
+ PackageInventory,
331
353
  PackageListPush,
332
354
  PackageProgressPush,
333
355
  PackageStartedPush,
@@ -1015,6 +1037,7 @@ export {
1015
1037
  debugRunList,
1016
1038
  debugRunSchema,
1017
1039
  debugRunStatusSchema,
1040
+ debugTaskSample,
1018
1041
  debugStepStatusSchema,
1019
1042
  debugTrackingClear,
1020
1043
  debugTrackingCompanionSchema,
@@ -1137,11 +1160,16 @@ export {
1137
1160
  notifyChannelUpdate,
1138
1161
  notifyChannelUsage,
1139
1162
  notifyCommands,
1163
+ notifyNoticeCount,
1164
+ notifyNoticeGet,
1165
+ notifyNoticeHide,
1166
+ notifyNoticeReset,
1140
1167
  notifyRouteGet,
1141
1168
  notifyRouteSet,
1142
1169
  notifyRouteTest
1143
1170
  } from './features/notify';
1144
1171
  export { stepUpCommands, stepUpConfirm, stepUpSetInterval, stepUpStatus } from './features/stepUp';
1172
+ export { taskAttach, taskCancel, taskCommands, taskDismiss } from './features/task';
1145
1173
  export {
1146
1174
  loginChecksCommands,
1147
1175
  loginChecksForgetBrowser,
@@ -122,6 +122,33 @@ export const agentPkgListResultPayloadSchema = z.object({
122
122
  * count. A tool whose probe fails still gets its frame (`null`), so the
123
123
  * screen never waits for a count that will not come.
124
124
  */
125
+ /**
126
+ * Reply to `pkg.inventory`: the packages installed on the host, for the CVE
127
+ * watch. `source` is the source package a Debian advisory names; `manager`
128
+ * is `null` when no supported database was found (`error` says why).
129
+ */
130
+ export const AGENT_PKG_INVENTORY_RESULT = 'pkg.inventoryResult' as const;
131
+ export const installedPackageSchema = z.object({
132
+ name: z.string().min(1).max(200),
133
+ version: z.string().min(1).max(200),
134
+ arch: z.string().max(40),
135
+ source: z.string().max(200).optional()
136
+ });
137
+ export type InstalledPackage = z.infer<typeof installedPackageSchema>;
138
+ export const packageInventorySchema = z.object({
139
+ /** `ID` and `VERSION_ID` of os-release. */
140
+ distroId: z.string().max(64).nullable(),
141
+ distroVersion: z.string().max(64).nullable(),
142
+ manager: z.enum(['dpkg', 'rpm', 'apk']).nullable(),
143
+ packages: z.array(installedPackageSchema).max(20_000),
144
+ error: z.string().max(500).nullable()
145
+ });
146
+ export type PackageInventory = z.infer<typeof packageInventorySchema>;
147
+ export const agentPkgInventoryResultPayloadSchema = z.object({
148
+ deviceId: z.uuid(),
149
+ inventory: packageInventorySchema
150
+ });
151
+
125
152
  export const AGENT_PKG_COUNT = 'pkg.count' as const;
126
153
 
127
154
  export const agentPkgCountPayloadSchema = z.object({
@@ -689,6 +716,10 @@ export const agentClientMessageSchema = z.discriminatedUnion('command', [
689
716
  command: z.literal(AGENT_DOCKER_INVENTORY_RESULT),
690
717
  payload: agentDockerInventoryResultPayloadSchema
691
718
  }),
719
+ z.object({
720
+ command: z.literal(AGENT_PKG_INVENTORY_RESULT),
721
+ payload: agentPkgInventoryResultPayloadSchema
722
+ }),
692
723
  z.object({
693
724
  command: z.literal(AGENT_DOCKER_STATS_RESULT),
694
725
  payload: agentDockerStatsResultPayloadSchema
@@ -885,6 +916,10 @@ export type AgentPkgUpgradePayload = z.infer<typeof agentPkgUpgradePayloadSchema
885
916
 
886
917
  /** Ask the agent for its container inventory (`docker.inventoryResult`). */
887
918
  export const AGENT_DOCKER_INVENTORY = 'docker.inventory' as const;
919
+ /** List the installed system packages (replies `pkg.inventoryResult`). Read-only, unsigned. */
920
+ export const AGENT_PKG_INVENTORY = 'pkg.inventory' as const;
921
+ /** What an agent that knows `pkg.inventory` declares in `report.agent.probes`. */
922
+ export const AGENT_PKG_INVENTORY_PROBE = 'pkgInventory';
888
923
 
889
924
  /** Ask the agent for a one-shot resource sample of the running containers. */
890
925
  export const AGENT_DOCKER_STATS = 'docker.stats' as const;
@@ -1433,6 +1468,10 @@ export const agentServerMessageSchema = z.discriminatedUnion('command', [
1433
1468
  command: z.literal(AGENT_DOCKER_INVENTORY),
1434
1469
  payload: z.object({})
1435
1470
  }),
1471
+ z.object({
1472
+ command: z.literal(AGENT_PKG_INVENTORY),
1473
+ payload: z.object({})
1474
+ }),
1436
1475
  z.object({
1437
1476
  command: z.literal(AGENT_DOCKER_STATS),
1438
1477
  payload: z.object({})
@@ -0,0 +1,44 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+
4
+ import { clientMessageSchema, commandTaskSchema, TASK_TITLE_MAX } from './envelope';
5
+
6
+ const ID = '0b6f5e0a-2a57-4a55-9a56-0d7c1d2a3b4c';
7
+
8
+ describe('commandTaskSchema', () => {
9
+ it('accepts the label a client sends with a long command', () => {
10
+ const tag = commandTaskSchema.parse({
11
+ id: ID,
12
+ title: ' Suppression du partage ',
13
+ subject: 'Documents',
14
+ feature: 'cloudsync',
15
+ itemId: '12',
16
+ key: 'share.delete',
17
+ done: 'Partage supprimé.',
18
+ failed: 'Suppression impossible.'
19
+ });
20
+ assert.equal(tag.title, 'Suppression du partage');
21
+ });
22
+
23
+ it('refuses an id that is not one, an empty title and a title too long', () => {
24
+ assert.equal(commandTaskSchema.safeParse({ id: 'short', title: 'x' }).success, false);
25
+ assert.equal(commandTaskSchema.safeParse({ id: `${ID}/../x`, title: 'x' }).success, false);
26
+ assert.equal(commandTaskSchema.safeParse({ id: ID, title: ' ' }).success, false);
27
+ assert.equal(
28
+ commandTaskSchema.safeParse({ id: ID, title: 'x'.repeat(TASK_TITLE_MAX + 1) }).success,
29
+ false
30
+ );
31
+ });
32
+ });
33
+
34
+ describe('clientMessageSchema', () => {
35
+ it('carries the task tag beside the workspace, and stays valid without it', () => {
36
+ const base = { requestId: 'r-1', command: 'cloudSync.deleteShare', payload: {} };
37
+ assert.equal(clientMessageSchema.parse(base).task, undefined);
38
+ assert.equal(
39
+ clientMessageSchema.parse({ ...base, task: { id: ID, title: 'Suppression' } }).task?.id,
40
+ ID
41
+ );
42
+ assert.equal(clientMessageSchema.safeParse({ ...base, task: { id: ID } }).success, false);
43
+ });
44
+ });
@@ -10,6 +10,40 @@ import { ProtocolErrorSchema } from './error';
10
10
  * unsolicited events with no `requestId`.
11
11
  */
12
12
 
13
+ export const TASK_TITLE_MAX = 120;
14
+ export const TASK_TEXT_MAX = 300;
15
+
16
+ /** The id of a long operation: chosen by the client that starts it, shown to the whole account. */
17
+ export const taskIdSchema = z
18
+ .string()
19
+ .min(8)
20
+ .max(64)
21
+ .regex(/^[A-Za-z0-9-]+$/);
22
+
23
+ /**
24
+ * What marks a command as a long operation the server follows (`domain/task`):
25
+ * its answer is kept for a while and its progress is shown to the caller's
26
+ * other tabs. The labels are the caller's: the interface sentences live in the
27
+ * client, and they only ever go back to the account that sent them. The id is
28
+ * not the `requestId`: the id is broadcast, the `requestId` never is, and
29
+ * claiming the kept answer takes both.
30
+ */
31
+ export const commandTaskSchema = z.object({
32
+ id: taskIdSchema,
33
+ title: z.string().trim().min(1).max(TASK_TITLE_MAX),
34
+ /** What it acts on, to tell two operations with the same title apart. */
35
+ subject: z.string().trim().min(1).max(TASK_TEXT_MAX).optional(),
36
+ feature: z.string().min(1).max(64).optional(),
37
+ itemId: z.string().min(1).max(64).optional(),
38
+ /** The kind of operation, as the screens of the feature filter on it. */
39
+ key: z.string().min(1).max(64).optional(),
40
+ /** The sentence of a success and the fallback sentence of a failure, for a tab that did not start it. */
41
+ done: z.string().trim().min(1).max(TASK_TEXT_MAX).optional(),
42
+ failed: z.string().trim().min(1).max(TASK_TEXT_MAX).optional()
43
+ });
44
+
45
+ export type CommandTask = z.infer<typeof commandTaskSchema>;
46
+
13
47
  export const clientMessageSchema = z.object({
14
48
  requestId: z.string().min(1),
15
49
  command: z.string().min(1),
@@ -20,6 +54,8 @@ export const clientMessageSchema = z.object({
20
54
  * d'autorisation, et chaque message se décrit lui-même, reconnexions comprises.
21
55
  */
22
56
  workspaceId: z.number().int().positive().optional(),
57
+ /** See {@link commandTaskSchema}. */
58
+ task: commandTaskSchema.optional(),
23
59
  payload: z.unknown()
24
60
  });
25
61