@deveye/types 0.20.2 → 0.21.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.20.2",
3
+ "version": "0.21.0",
4
4
  "description": "Shared contracts (types + zod schemas) for DevEye apps",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -0,0 +1,37 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Simultaneous seats: how many free accounts and how many priority accounts
5
+ * (`AccountPlan.priority`) may hold a socket at once, set per server by the
6
+ * global admin. Beyond a cap, the next ones wait in line.
7
+ */
8
+
9
+ export const seatSchema = z.enum(['free', 'paid']);
10
+ export type Seat = z.infer<typeof seatSchema>;
11
+
12
+ /** `null`: no cap. */
13
+ export const seatCapsSchema = z.object({
14
+ free: z.number().int().min(1).max(1_000_000).nullable(),
15
+ paid: z.number().int().min(1).max(1_000_000).nullable()
16
+ });
17
+ export type SeatCaps = z.infer<typeof seatCapsSchema>;
18
+
19
+ /**
20
+ * WebSocket close code for an account waiting in line. The `session` frame
21
+ * before it carries the `queued` error, its details `{ position }`: the client
22
+ * shows the waiting room and tries again shortly.
23
+ */
24
+ export const QUEUE_CLOSE_CODE = 4429;
25
+
26
+ /**
27
+ * WebSocket close code for an account whose seat went to someone waiting,
28
+ * after a long time without any activity. The client does not reconnect until
29
+ * the person comes back.
30
+ */
31
+ export const IDLE_CLOSE_CODE = 4408;
32
+
33
+ /** Client frame, no reply: the person just used the page (at most once a minute). */
34
+ export const SESSION_ACTIVE_COMMAND = 'session.active' as const;
35
+
36
+ export const queueRefusalSchema = z.object({ position: z.number().int().positive() });
37
+ export type QueueRefusal = z.infer<typeof queueRefusalSchema>;
@@ -3,23 +3,18 @@ import { deviceReportSchema, processCaptureSchema } from './report';
3
3
 
4
4
  /**
5
5
  * Lifecycle of a monitored machine (the Rust agent):
6
- * - `pending`: enrolled via a link code but not yet confirmed in the UI.
7
- * - `active`: confirmed; allowed to push metrics.
8
- * - `revoked`: access withdrawn; the agent is rejected (can be reactivated).
6
+ * - `pending`: a machine the workspace already knew, linked again. Its
7
+ * agent is refused at the socket until someone approves it.
8
+ * - `active`: in service. A first link lands here directly.
9
9
  * - `pending_deletion`: deletion requested; on its next connection the agent is
10
10
  * told to self-destruct, then the device is archived. Can
11
11
  * be cancelled until the agent reconnects.
12
- * - `archived`: agent destroyed/removed; the device no longer exists for
13
- * management, but its monitoring history is kept frozen and
14
- * remains browsable (read-only) until explicitly purged.
12
+ * - `archived`: access revoked or agent removed. The token is wiped, the
13
+ * monitoring history stays browsable (read-only) until
14
+ * purged, and linking the machine again brings it back as
15
+ * `pending`.
15
16
  */
16
- export const deviceStatusSchema = z.enum([
17
- 'pending',
18
- 'active',
19
- 'revoked',
20
- 'pending_deletion',
21
- 'archived'
22
- ]);
17
+ export const deviceStatusSchema = z.enum(['pending', 'active', 'pending_deletion', 'archived']);
23
18
  export type DeviceStatus = z.infer<typeof deviceStatusSchema>;
24
19
 
25
20
  export const devicePlatformSchema = z.enum(['linux', 'macos', 'windows']);
@@ -68,9 +63,12 @@ export const deviceSchema = z.object({
68
63
  report: deviceReportSchema.nullable().default(null),
69
64
  /**
70
65
  * The agent's single collection interval in seconds — one tick yields
71
- * metrics *and* processes under one timestamp. Null → server default (60).
66
+ * metrics *and* processes under one timestamp. Null → the default of the
67
+ * owner's plan ({@link DEFAULT_METRIC_INTERVAL_SECONDS}).
72
68
  */
73
69
  metricIntervalSeconds: z.number().int().positive().nullable().default(null),
70
+ /** The cadence the agent actually runs at, resolved by the server (own setting or plan default). */
71
+ effectiveMetricIntervalSeconds: z.number().int().positive().default(60),
74
72
  /** How much of the process list each tick carries; null → server default (`all`). */
75
73
  processCapture: processCaptureSchema.nullable().default(null),
76
74
  /**
@@ -157,8 +155,9 @@ export interface DeviceRow {
157
155
  /**
158
156
  * Réglages appliqués à un appareil qui n'a rien choisi. Source unique : le
159
157
  * serveur les applique en construisant la config poussée à l'agent, et le
160
- * dialogue de configuration les affiche comme valeurs de départ.
158
+ * dialogue de configuration les affiche comme valeurs de départ. La cadence
159
+ * dépend de l'offre du propriétaire : c'est elle qui fait le volume écrit.
161
160
  */
162
- export const DEFAULT_METRIC_INTERVAL_SECONDS = 60;
161
+ export const DEFAULT_METRIC_INTERVAL_SECONDS = { paid: 60, free: 300 } as const;
163
162
  export const DEFAULT_PROCESS_CAPTURE = 'all' as const;
164
163
  export const DEFAULT_RETENTION_DAYS = 30;
@@ -471,12 +471,13 @@ export const SHARE_WIRED_FEATURES: readonly WorkspaceFeatureId[] = ['backup'];
471
471
  * le client n'affiche pas l'onglet. En relier une de plus, c'est une entrée ici
472
472
  * et une dans le `Record` du contrat.
473
473
  */
474
- export const PROJECT_LINKED_FEATURES: readonly WorkspaceFeatureId[] = [
474
+ export const PROJECT_LINKED_FEATURES: readonly FeatureId[] = [
475
475
  'git',
476
476
  'database',
477
477
  'audience',
478
478
  'deploy',
479
- 'uptime'
479
+ 'uptime',
480
+ 'x-hosting'
480
481
  ];
481
482
 
482
483
  /** Les fonctionnalités qui savent prévenir, dans l'ordre du registre. */
@@ -21,7 +21,13 @@ export const maintenanceStateSchema = z.object({
21
21
  /** The text shown to everyone the site maintenance keeps out. */
22
22
  message: z.string(),
23
23
  /** Features under maintenance only; an absent id is open. */
24
- features: z.record(z.string(), featureMaintenanceLevelSchema)
24
+ features: z.record(z.string(), featureMaintenanceLevelSchema),
25
+ /**
26
+ * Accounts whose plan has `priority` are served first: the others stay
27
+ * signed in, with everything they run paused. Defaults for a remote
28
+ * instance on an older version.
29
+ */
30
+ priority: z.boolean().default(false)
25
31
  });
26
32
  export type MaintenanceState = z.infer<typeof maintenanceStateSchema>;
27
33
 
@@ -48,6 +48,21 @@ export const nativeNotificationFeatureSchema = z.enum([
48
48
  ]);
49
49
  export type NativeNotificationFeature = z.infer<typeof nativeNotificationFeatureSchema>;
50
50
 
51
+ /**
52
+ * The instance's own alerts (server errors, crashes, restarts). Not a workspace
53
+ * feature: only a global admin who owns the workspace may declare its channels
54
+ * and route, and the server delivers to every such workspace.
55
+ */
56
+ export const SYSTEM_NOTIFICATION_TARGET = 'system';
57
+ export const systemNotificationTargetSchema = z.literal(SYSTEM_NOTIFICATION_TARGET);
58
+ export type SystemNotificationTarget = z.infer<typeof systemNotificationTargetSchema>;
59
+
60
+ /** What the settings screen shows for the system target, in place of a feature descriptor. */
61
+ export const SYSTEM_NOTIFICATION_INFO = {
62
+ label: 'Système',
63
+ hint: 'Les erreurs du serveur, ses plantages et ses redémarrages. Réservé aux administrateurs.'
64
+ } as const;
65
+
51
66
  /**
52
67
  * Un module externe peut prévenir aussi. Le schéma n'atteste que la **forme**
53
68
  * de l'id : la garde de fond (« ce module déclare bien `notifies` ») ne peut
@@ -56,6 +71,7 @@ export type NativeNotificationFeature = z.infer<typeof nativeNotificationFeature
56
71
  */
57
72
  export const notificationFeatureSchema = z.union([
58
73
  nativeNotificationFeatureSchema,
74
+ systemNotificationTargetSchema,
59
75
  externalFeatureIdSchema
60
76
  ]);
61
77
  export type NotificationFeature = z.infer<typeof notificationFeatureSchema>;
@@ -21,9 +21,41 @@ export const packageManagerIdSchema = z.enum([
21
21
 
22
22
  export type PackageManagerId = z.infer<typeof packageManagerIdSchema>;
23
23
 
24
- /** One detected manager + its pending-update state. */
24
+ /**
25
+ * Update tooling the agent recognises on a machine but DevEye does not drive:
26
+ * listed without a count, never upgraded, so a device's table says what else
27
+ * keeps it up to date (an atomic image's rpm-ostree, firmware through fwupd…).
28
+ */
29
+ export const unmanagedUpdaterIdSchema = z.enum([
30
+ 'rpm-ostree',
31
+ 'bootc',
32
+ 'fwupd',
33
+ 'nix',
34
+ 'apk',
35
+ 'xbps',
36
+ 'emerge',
37
+ 'eopkg',
38
+ 'mas',
39
+ 'macports',
40
+ 'choco',
41
+ 'scoop'
42
+ ]);
43
+
44
+ export type UnmanagedUpdaterId = z.infer<typeof unmanagedUpdaterIdSchema>;
45
+
46
+ /** Whether DevEye drives this tool (counts its updates and applies them). */
47
+ export function isManagedPackageManager(
48
+ id: PackageManagerId | UnmanagedUpdaterId
49
+ ): id is PackageManagerId {
50
+ return packageManagerIdSchema.safeParse(id).success;
51
+ }
52
+
53
+ /**
54
+ * One detected update tool + its pending-update state. An unmanaged one
55
+ * (`unmanagedUpdaterIdSchema`) carries no count and needs nothing.
56
+ */
25
57
  export const packageManagerSchema = z.object({
26
- id: packageManagerIdSchema,
58
+ id: z.union([packageManagerIdSchema, unmanagedUpdaterIdSchema]),
27
59
  /** Pending update count; `null` when unknown (slow/best-effort probe). */
28
60
  pendingCount: z.number().int().nonnegative().nullable(),
29
61
  /** Applying this manager's updates requires root/admin. */
@@ -212,13 +212,19 @@ export type AgentServiceScope = z.infer<typeof agentServiceScopeSchema>;
212
212
  */
213
213
  export const agentPolicySchema = z.object({
214
214
  terminal: z.boolean(),
215
+ /** Browsing, searching and downloading files. Defaulted, like the switches below: an agent older than them reports without them, and does not refuse. */
216
+ filesRead: z.boolean().default(true),
215
217
  filesWrite: z.boolean(),
216
218
  power: z.boolean(),
217
219
  pkgUpgrade: z.boolean(),
218
220
  serviceElevate: z.boolean(),
219
221
  destroy: z.boolean(),
220
- /** Deployments (`composeDeploy`). Defaulted: an agent older than the switch reports without it. */
221
- dockerDeploy: z.boolean().default(true)
222
+ /** Every container action (start, stop, prune, deploy). */
223
+ docker: z.boolean().default(true),
224
+ /** Deployments (`composeDeploy`), on top of `docker`. */
225
+ dockerDeploy: z.boolean().default(true),
226
+ /** CloudSync shares: the server reading and writing a synced folder. */
227
+ sync: z.boolean().default(true)
222
228
  });
223
229
  export type AgentPolicy = z.infer<typeof agentPolicySchema>;
224
230
 
@@ -244,12 +250,15 @@ export const agentInfoSchema = z.object({
244
250
  probes: z.array(z.string().max(32)).max(16).default([]),
245
251
  policy: agentPolicySchema.default({
246
252
  terminal: true,
253
+ filesRead: true,
247
254
  filesWrite: true,
248
255
  power: true,
249
256
  pkgUpgrade: true,
250
257
  serviceElevate: true,
251
258
  destroy: true,
252
- dockerDeploy: true
259
+ docker: true,
260
+ dockerDeploy: true,
261
+ sync: true
253
262
  }),
254
263
  /** The agent reaches this server over plain http/ws (opted in locally): everything, shell included, travels in clear. */
255
264
  insecureTransport: z.boolean().default(false)
@@ -35,6 +35,19 @@ export const secrecyStatusSchema = z.object({
35
35
 
36
36
  export type SecrecyStatus = z.infer<typeof secrecyStatusSchema>;
37
37
 
38
+ /**
39
+ * Pushed to every open socket of a session whenever the server caches or wipes
40
+ * its unlocked DEK (unlock, lock, grace expiry, disconnect of a sibling tab), so
41
+ * the client never shows a vault the server already forgot. Sliding the grace
42
+ * window is not pushed.
43
+ */
44
+ export const SECRECY_STATE_EVENT = 'secrecy.state' as const;
45
+ export const secrecyStatePushSchema = secrecyStatusSchema.pick({
46
+ unlocked: true,
47
+ unlockedUntil: true
48
+ });
49
+ export type SecrecyStatePush = z.infer<typeof secrecyStatePushSchema>;
50
+
38
51
  /** How the DEK is wrapped at rest. Mirrors the `wrap_mode` SQL column. */
39
52
  export const secrecyWrapModeSchema = z.enum(['server', 'password']);
40
53
  export type SecrecyWrapMode = z.infer<typeof secrecyWrapModeSchema>;
@@ -148,4 +148,6 @@ export interface UserRow {
148
148
  created: number;
149
149
  /** Seconds. When the terms of use were accepted at sign-up; `null` for an account created without a site. */
150
150
  terms_accepted_at: number | null;
151
+ /** The end-to-end run that created this throwaway account (`<instance tag>-<run id>`); `null` for a person. */
152
+ e2e_run: string | null;
151
153
  }
@@ -1,4 +1,5 @@
1
1
  import { z } from 'zod';
2
+ import { seatCapsSchema } from '../domain/admission';
2
3
  import { featureMaintenanceLevelSchema, MAINTENANCE_MESSAGE_MAX } from '../domain/maintenance';
3
4
  import { userRoleSchema } from '../domain/role';
4
5
  import { userStatusSchema } from '../domain/user';
@@ -21,7 +22,9 @@ export const adminUserSchema = z.object({
21
22
  /** Nombre d'espaces auxquels le compte a accès, personnel compris. */
22
23
  workspaceCount: z.number().int().nonnegative(),
23
24
  lastLogin: z.number().int().nonnegative(),
24
- created: z.number().int().nonnegative()
25
+ created: z.number().int().nonnegative(),
26
+ /** Un compte jetable d'un essai de bout en bout en cours, jamais une personne. */
27
+ test: z.boolean()
25
28
  });
26
29
 
27
30
  export type AdminUser = z.infer<typeof adminUserSchema>;
@@ -71,6 +74,35 @@ export const adminMaintenanceSchema = z.object({
71
74
  updated: z.number().int().nonnegative(),
72
75
  updatedBy: maintenanceAuthorSchema
73
76
  }),
77
+ /** La priorité aux abonnés, commune à tous les serveurs qui partagent la base. */
78
+ priority: z.object({
79
+ active: z.boolean(),
80
+ /** Sans module qui tient les offres, personne n'est abonné : rien à activer. */
81
+ available: z.boolean(),
82
+ updated: z.number().int().nonnegative().nullable(),
83
+ updatedBy: maintenanceAuthorSchema
84
+ }),
85
+ /** Les inscriptions de ce serveur seulement, rangées par origine publique. */
86
+ signups: z.object({
87
+ open: z.boolean(),
88
+ origin: z.string(),
89
+ updated: z.number().int().nonnegative().nullable(),
90
+ updatedBy: maintenanceAuthorSchema
91
+ }),
92
+ /** Les places simultanées de ce serveur seulement, et qui les occupe à l'instant. */
93
+ seats: seatCapsSchema.extend({
94
+ origin: z.string(),
95
+ updated: z.number().int().nonnegative().nullable(),
96
+ updatedBy: maintenanceAuthorSchema,
97
+ present: z.object({
98
+ free: z.number().int().nonnegative(),
99
+ paid: z.number().int().nonnegative()
100
+ }),
101
+ waiting: z.object({
102
+ free: z.number().int().nonnegative(),
103
+ paid: z.number().int().nonnegative()
104
+ })
105
+ }),
74
106
  /** Chaque module installé, ouvert ou non. */
75
107
  features: z.array(
76
108
  z.object({
@@ -112,6 +144,29 @@ export const adminMaintenanceFeature = {
112
144
  output: adminMaintenanceSchema
113
145
  };
114
146
 
147
+ /**
148
+ * Les comptes sans offre prioritaire restent connectés, mais tout ce qui tourne
149
+ * pour eux se met en pause et ils ne créent plus rien, jusqu'à la levée.
150
+ */
151
+ export const adminMaintenancePriority = {
152
+ command: 'admin.maintenancePriority' as const,
153
+ input: z.object({ active: z.boolean() }),
154
+ output: adminMaintenanceSchema
155
+ };
156
+
157
+ export const adminMaintenanceSignups = {
158
+ command: 'admin.maintenanceSignups' as const,
159
+ input: z.object({ open: z.boolean() }),
160
+ output: adminMaintenanceSchema
161
+ };
162
+
163
+ /** Baisser un plafond ne ferme aucune session : les suivants attendent. */
164
+ export const adminMaintenanceSeats = {
165
+ command: 'admin.maintenanceSeats' as const,
166
+ input: seatCapsSchema,
167
+ output: adminMaintenanceSchema
168
+ };
169
+
115
170
  /** Ferme le rappel de `MAINTENANCE=1`, pour tous les administrateurs. */
116
171
  export const adminMaintenanceDismissNotice = {
117
172
  command: 'admin.maintenanceDismissNotice' as const,
@@ -127,5 +182,8 @@ export const adminCommands = [
127
182
  adminMaintenanceGet,
128
183
  adminMaintenanceSite,
129
184
  adminMaintenanceFeature,
185
+ adminMaintenancePriority,
186
+ adminMaintenanceSignups,
187
+ adminMaintenanceSeats,
130
188
  adminMaintenanceDismissNotice
131
189
  ] as const;