@deveye/types 0.18.3 → 0.19.1

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 (40) hide show
  1. package/package.json +1 -1
  2. package/src/domain/device.ts +6 -2
  3. package/src/domain/featureRegistry.ts +16 -0
  4. package/src/domain/home.ts +5 -3
  5. package/src/domain/live.ts +3 -3
  6. package/src/domain/project.ts +56 -0
  7. package/src/domain/remoteInstance.test.ts +35 -0
  8. package/src/domain/remoteInstance.ts +70 -0
  9. package/src/domain/report.ts +34 -2
  10. package/src/domain/secrecy.ts +3 -0
  11. package/src/domain/sharing.ts +46 -1
  12. package/src/domain/twoFactor.ts +7 -3
  13. package/src/domain/workspace.ts +1 -1
  14. package/src/domain/workspaceRole.ts +1 -1
  15. package/src/features/admin.ts +1 -51
  16. package/src/features/home.ts +1 -1
  17. package/src/features/links.ts +37 -0
  18. package/src/features/registry.ts +4 -0
  19. package/src/features/remote.ts +52 -0
  20. package/src/features/secrecy.ts +22 -8
  21. package/src/features/sharing.ts +78 -2
  22. package/src/features/twoFactor.ts +1 -1
  23. package/src/features/user.ts +32 -4
  24. package/src/features/workspace.ts +2 -2
  25. package/src/http/auth.ts +113 -15
  26. package/src/http/device.ts +14 -10
  27. package/src/http/status.ts +2 -0
  28. package/src/index.ts +89 -12
  29. package/src/protocol/agent.ts +38 -0
  30. package/src/protocol/error.ts +3 -0
  31. package/src/sdk/client-ambient.d.ts +60 -5
  32. package/src/sdk/client.ts +81 -3
  33. package/src/sdk/copy.test.ts +374 -0
  34. package/src/sdk/copy.ts +435 -0
  35. package/src/sdk/manifest.test.ts +27 -0
  36. package/src/sdk/manifest.ts +60 -1
  37. package/src/sdk/providers.ts +102 -0
  38. package/src/sdk/server.ts +188 -10
  39. package/src/sdk/testing.test.ts +22 -0
  40. package/src/sdk/testing.ts +91 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveye/types",
3
- "version": "0.18.3",
3
+ "version": "0.19.1",
4
4
  "description": "Shared contracts (types + zod schemas) for DevEye apps",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -120,10 +120,14 @@ export interface DeviceRow {
120
120
  fingerprint: string;
121
121
  platform: string;
122
122
  status: DeviceStatus;
123
- /** X25519 public key (base64) used for command signature verification. */
124
- public_key: string | null;
125
123
  /** SHA-256 hash of the device token (the raw token lives only on the agent). */
126
124
  token_hash: string;
125
+ /**
126
+ * Hash of the token being replaced, during a rotation: accepted until the
127
+ * agent has authenticated once with the new one (a rotation frame can be
128
+ * lost in flight), then cleared.
129
+ */
130
+ token_hash_prev: string | null;
127
131
  last_seen: number | null;
128
132
  created: number;
129
133
  /** Agent version from the last `agent.hello`; null until first connection. */
@@ -403,6 +403,22 @@ export const SHAREABLE_FEATURES: readonly WorkspaceFeatureId[] = FEATURE_REGISTR
403
403
  */
404
404
  export const SHARE_WIRED_FEATURES: readonly WorkspaceFeatureId[] = ['backup'];
405
405
 
406
+ /**
407
+ * Celles dont un projet relie les éléments : le module Projets tient une table
408
+ * de liaison par famille, et son contrat d'usage (`PROJECTS_USAGE_PROVIDER`) ne
409
+ * connaît que celles-ci. Partagée entre client et serveur, comme
410
+ * {@link SHARE_WIRED_FEATURES} : le serveur rend une liste vide pour une autre,
411
+ * le client n'affiche pas l'onglet. En relier une de plus, c'est une entrée ici
412
+ * et une dans le `Record` du contrat.
413
+ */
414
+ export const PROJECT_LINKED_FEATURES: readonly WorkspaceFeatureId[] = [
415
+ 'git',
416
+ 'database',
417
+ 'audience',
418
+ 'deploy',
419
+ 'uptime'
420
+ ];
421
+
406
422
  /** Les fonctionnalités qui savent prévenir, dans l'ordre du registre. */
407
423
  export const NOTIFYING_FEATURES: readonly WorkspaceFeatureId[] = FEATURE_REGISTRY.filter(
408
424
  (f) => f.notifies
@@ -12,7 +12,7 @@ import {
12
12
  * tenant des tuiles ordonnées de n'importe quels genres (appareil,
13
13
  * fonctionnalité, raccourci, dossier). Aucune section par défaut ; l'intitulé
14
14
  * est facultatif. Stockée en clair : métadonnée de personnalisation, jamais de
15
- * charge zero-knowledge.
15
+ * contenu utilisateur.
16
16
  */
17
17
 
18
18
  /**
@@ -108,7 +108,9 @@ export const shortcutItemSchema = z.object({
108
108
  id: z.string().min(1).max(64),
109
109
  /** Unknown/legacy templates degrade to a generic link rather than dropping the tile. */
110
110
  template: shortcutTemplateSchema.catch('link'),
111
- url: z.string().url().max(SHORTCUT_URL_MAX_LENGTH),
111
+ // http(s) seulement : `z.string().url()` accepte `javascript:` et `data:`, et
112
+ // cette valeur devient le `href` d'une tuile.
113
+ url: z.url({ protocol: /^https?$/ }).max(SHORTCUT_URL_MAX_LENGTH),
112
114
  /** Optional: empty → the tile falls back to the fetched name (account, og:title…). */
113
115
  title: z.string().max(80),
114
116
  description: z.string().max(200).optional(),
@@ -245,7 +247,7 @@ export const shortcutPreviewSchema = z.object({
245
247
  ok: z.boolean(),
246
248
  title: z.string().nullable(),
247
249
  subtitle: z.string().nullable(),
248
- imageUrl: z.string().url().nullable(),
250
+ imageUrl: z.url({ protocol: /^https?$/ }).nullable(),
249
251
  stats: z.array(z.object({ label: z.string(), value: z.string() })).max(4),
250
252
  /**
251
253
  * Optional live/online status, rendered as a small green/red dot in the tile
@@ -131,9 +131,9 @@ export const nativeLiveTopicSchema = z.enum([
131
131
  /** Réglages de compte (avatar, couleur, thème, chiffrement). */
132
132
  'account',
133
133
  /**
134
- * Les comptes du site et leurs invitations : ce que la page Utilisateurs
135
- * montre. Jamais diffusé dans une salle, la page n'appartient à aucun
136
- * espace : les administrateurs sont visés par compte (`userChanged`).
134
+ * Les comptes du site : ce que la page Utilisateurs montre. Jamais diffusé
135
+ * dans une salle, la page n'appartient à aucun espace : les administrateurs
136
+ * sont visés par compte (`userChanged`).
137
137
  */
138
138
  'admin',
139
139
  /**
@@ -7,3 +7,59 @@ import { z } from 'zod';
7
7
  */
8
8
  export const projectStatusSchema = z.enum(['draft', 'active', 'paused', 'done']);
9
9
  export type ProjectStatus = z.infer<typeof projectStatusSchema>;
10
+
11
+ /**
12
+ * Les intitulés des états, pour les écrans qui parlent des projets sans être
13
+ * Projets : la fiche d'une base, la coquille de réglages d'un élément.
14
+ */
15
+ export const PROJECT_STATUS_LABELS: Record<ProjectStatus, string> = {
16
+ draft: 'Brouillon',
17
+ active: 'En cours',
18
+ paused: 'En pause',
19
+ done: 'Terminé'
20
+ };
21
+
22
+ /** Pourquoi il n'y a rien à relier. Une raison plutôt qu'une liste vide : les deux sont structurelles. */
23
+ export const itemProjectsBlockerSchema = z.enum([
24
+ /** Le module Projets n'est pas installé sur ce serveur. */
25
+ 'module',
26
+ /** Un projet ne relie pas les éléments de cette fonctionnalité. */
27
+ 'feature'
28
+ ]);
29
+ export type ItemProjectsBlocker = z.infer<typeof itemProjectsBlockerSchema>;
30
+
31
+ /** Un projet auquel l'élément réglé est relié, ou pourrait l'être. */
32
+ export const itemProjectSchema = z.object({
33
+ projectId: z.number().int().positive(),
34
+ title: z.string(),
35
+ status: projectStatusSchema,
36
+ /** Rangé : montré parce qu'il relie encore l'élément, jamais proposé à vide. */
37
+ archived: z.boolean(),
38
+ linked: z.boolean()
39
+ });
40
+ export type ItemProject = z.infer<typeof itemProjectSchema>;
41
+
42
+ /** Les projets d'un espace, tels que l'écran les groupe. */
43
+ export const itemProjectGroupSchema = z.object({
44
+ workspaceId: z.number().int().positive(),
45
+ workspaceName: z.string(),
46
+ /** L'espace actif : l'écran le met en tête. */
47
+ isActive: z.boolean(),
48
+ /** L'espace d'origine de l'élément ; ailleurs il n'y est que projeté. */
49
+ isHome: z.boolean(),
50
+ /** L'appelant tient `projects: write` ici. Faux : les cases sont inertes, la liste reste lisible. */
51
+ writable: z.boolean(),
52
+ projects: z.array(itemProjectSchema)
53
+ });
54
+ export type ItemProjectGroup = z.infer<typeof itemProjectGroupSchema>;
55
+
56
+ /**
57
+ * Les projets qui relient cet élément, dans chacun des espaces de l'appelant où
58
+ * il est visible. Un espace où l'appelant n'a pas accès à Projets n'y figure
59
+ * pas : les titres des projets d'un espace ne se lisent pas de l'extérieur.
60
+ */
61
+ export const itemProjectsStateSchema = z.object({
62
+ groups: z.array(itemProjectGroupSchema),
63
+ blocker: itemProjectsBlockerSchema.nullable()
64
+ });
65
+ export type ItemProjectsState = z.infer<typeof itemProjectsStateSchema>;
@@ -0,0 +1,35 @@
1
+ import assert from 'node:assert/strict';
2
+ import { describe, it } from 'node:test';
3
+
4
+ import { normalizeRemoteOrigin } from './remoteInstance';
5
+
6
+ describe('normalizeRemoteOrigin', () => {
7
+ it('ramène une adresse à son origine', () => {
8
+ assert.equal(
9
+ normalizeRemoteOrigin(' https://DevEye.Exemple.fr/ '),
10
+ 'https://deveye.exemple.fr'
11
+ );
12
+ assert.equal(
13
+ normalizeRemoteOrigin('https://deveye.exemple.fr:443'),
14
+ 'https://deveye.exemple.fr'
15
+ );
16
+ assert.equal(normalizeRemoteOrigin('http://10.0.0.4:3000'), 'http://10.0.0.4:3000');
17
+ });
18
+
19
+ it('refuse tout ce qui déborderait dans un en-tête CSP', () => {
20
+ for (const input of [
21
+ 'deveye.exemple.fr',
22
+ 'ftp://deveye.exemple.fr',
23
+ 'https://*.exemple.fr',
24
+ 'https://user:pass@exemple.fr',
25
+ 'https://exemple.fr/chemin',
26
+ 'https://exemple.fr/?q=1',
27
+ 'https://exemple.fr/#a',
28
+ 'https://[::1]:3000',
29
+ "https://exemple.fr; script-src 'unsafe-inline'",
30
+ 'https://exemple.fr evil.example'
31
+ ]) {
32
+ assert.equal(normalizeRemoteOrigin(input), null, input);
33
+ }
34
+ });
35
+ });
@@ -0,0 +1,70 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Une instance distante : un AUTRE serveur DevEye dont le compte range les
5
+ * espaces à côté des siens. Le serveur d'accueil n'en retient que l'adresse et
6
+ * un libellé, et ne la contacte jamais : c'est le navigateur qui y ouvre sa
7
+ * propre session, avec les identifiants de là-bas, qu'aucun serveur ne garde.
8
+ */
9
+
10
+ /** Instances distantes par compte. Chacune élargit la politique de contenu de sa page. */
11
+ export const REMOTE_INSTANCES_MAX = 5;
12
+
13
+ export const REMOTE_LABEL_MAX = 60;
14
+
15
+ /** Nom d'hôte ou IPv4. Une IPv6 littérale n'a pas de forme dans une source CSP. */
16
+ const HOST_PATTERN = /^[a-z0-9]([a-z0-9.-]*[a-z0-9])?$/;
17
+
18
+ /**
19
+ * Ramène une adresse saisie à son origine (`https://hôte[:port]`), ou `null`.
20
+ * Stricte parce que l'origine finit dans un en-tête `Content-Security-Policy` :
21
+ * ni chemin, ni identifiants, ni joker, rien qui puisse y injecter une directive.
22
+ */
23
+ export function normalizeRemoteOrigin(input: string): string | null {
24
+ let url: URL;
25
+ try {
26
+ url = new URL(input.trim());
27
+ } catch {
28
+ return null;
29
+ }
30
+ if (url.protocol !== 'https:' && url.protocol !== 'http:') return null;
31
+ if (url.username || url.password || url.search || url.hash) return null;
32
+ if (url.pathname !== '/' && url.pathname !== '') return null;
33
+ if (!HOST_PATTERN.test(url.hostname)) return null;
34
+ return url.origin;
35
+ }
36
+
37
+ export const remoteOriginSchema = z
38
+ .string()
39
+ .min(1)
40
+ .max(255)
41
+ .transform((value, ctx) => {
42
+ const origin = normalizeRemoteOrigin(value);
43
+ if (origin === null) {
44
+ ctx.addIssue({
45
+ code: z.ZodIssueCode.custom,
46
+ message: 'Adresse attendue sous la forme https://hôte ou https://hôte:port'
47
+ });
48
+ return z.NEVER;
49
+ }
50
+ return origin;
51
+ });
52
+
53
+ export const remoteInstanceSchema = z.object({
54
+ id: z.number().int().positive(),
55
+ label: z.string().min(1).max(REMOTE_LABEL_MAX),
56
+ origin: z.string().min(1).max(255),
57
+ created: z.number().int().nonnegative()
58
+ });
59
+
60
+ export type RemoteInstance = z.infer<typeof remoteInstanceSchema>;
61
+
62
+ /** Ligne SQL (serveur uniquement). */
63
+ export interface RemoteInstanceRow {
64
+ id: number;
65
+ user_id: number;
66
+ label: string;
67
+ origin: string;
68
+ sort_order: number;
69
+ created: number;
70
+ }
@@ -204,6 +204,22 @@ export type TcpConnection = z.infer<typeof tcpConnectionSchema>;
204
204
  export const agentServiceScopeSchema = z.enum(['none', 'user', 'system']);
205
205
  export type AgentServiceScope = z.infer<typeof agentServiceScopeSchema>;
206
206
 
207
+ /**
208
+ * What the machine's own operator allows this server to order, read from the
209
+ * `[policy]` section of `agent.toml`. No frame can change it: it is the one
210
+ * thing on the device the server does not decide. `false` = the agent refuses
211
+ * the order, whatever the caller's permissions say.
212
+ */
213
+ export const agentPolicySchema = z.object({
214
+ terminal: z.boolean(),
215
+ filesWrite: z.boolean(),
216
+ power: z.boolean(),
217
+ pkgUpgrade: z.boolean(),
218
+ serviceElevate: z.boolean(),
219
+ destroy: z.boolean()
220
+ });
221
+ export type AgentPolicy = z.infer<typeof agentPolicySchema>;
222
+
207
223
  export const agentInfoSchema = z.object({
208
224
  /** Running as root (Unix euid 0) / elevated (Windows). */
209
225
  privileged: z.boolean(),
@@ -223,7 +239,17 @@ export const agentInfoSchema = z.object({
223
239
  * ne dit pas (elle vaut `0.0.0` sur une construction locale). Vide par
224
240
  * défaut : un agent qui ne dit rien n'a pas ces sondes.
225
241
  */
226
- probes: z.array(z.string().max(32)).max(16).default([])
242
+ probes: z.array(z.string().max(32)).max(16).default([]),
243
+ policy: agentPolicySchema.default({
244
+ terminal: true,
245
+ filesWrite: true,
246
+ power: true,
247
+ pkgUpgrade: true,
248
+ serviceElevate: true,
249
+ destroy: true
250
+ }),
251
+ /** The agent reaches this server over plain http/ws (opted in locally): everything, shell included, travels in clear. */
252
+ insecureTransport: z.boolean().default(false)
227
253
  });
228
254
 
229
255
  export type AgentInfo = z.infer<typeof agentInfoSchema>;
@@ -446,6 +472,12 @@ export const authWindowSchema = z.object({
446
472
  * La source n'a pas pu être lue (pas de journal, pas les droits) : sans ce
447
473
  * drapeau, une machine aveugle passerait pour une machine tranquille.
448
474
  */
449
- unavailable: z.boolean().default(false)
475
+ unavailable: z.boolean().default(false),
476
+ /**
477
+ * Le plafond de lignes a été atteint : seules les plus récentes ont été
478
+ * comptées, les compteurs sont donc minorés. Un flot qui sature le relevé
479
+ * ne doit pas se lire comme une fenêtre calme.
480
+ */
481
+ truncated: z.boolean().default(false)
450
482
  });
451
483
  export type AuthWindow = z.infer<typeof authWindowSchema>;
@@ -58,7 +58,10 @@ export interface UserSecretKeyRow {
58
58
  kdf_salt: Uint8Array | null;
59
59
  recovery_wrapped: string | null;
60
60
  recovery_salt: Uint8Array | null;
61
+ /** Argon2id profile the password wrap was derived under; rows re-wrap to the current one on unlock. */
61
62
  version: number;
63
+ /** Argon2id profile of the recovery wrap; upgraded when the code is next used or renewed. */
64
+ recovery_version: number;
62
65
  created: number;
63
66
  updated: number;
64
67
  }
@@ -64,10 +64,55 @@ export const itemShareStateSchema = z.object({
64
64
  * pas pourquoi : c'est `share.movePreview`, une fois la cible choisie, qui
65
65
  * porte les motifs.
66
66
  */
67
- movable: z.boolean().default(false)
67
+ movable: z.boolean().default(false),
68
+ /**
69
+ * L'élément peut être copié ailleurs : sa fonctionnalité sait décrire ce
70
+ * dont il est fait, et l'appelant peut le lire. Vers où, c'est l'écran qui
71
+ * le propose : la cible peut être une autre instance, que ce serveur ignore.
72
+ */
73
+ copyable: z.boolean().default(false)
68
74
  });
69
75
  export type ItemShareState = z.infer<typeof itemShareStateSchema>;
70
76
 
77
+ /** Le palier d'un élément : sous la clé de l'espace, ou sous celle du mot de passe de son auteur. */
78
+ export const itemTierSchema = z.enum(['open', 'private']);
79
+
80
+ /** Ce que la SOURCE dit d'une copie, avant d'avoir rien lu. */
81
+ export const itemCopyPlanSchema = z.object({
82
+ /** L'intitulé de l'élément, pour la confirmation ; `null` quand il est illisible d'ici. */
83
+ label: z.string().nullable(),
84
+ tier: itemTierSchema,
85
+ /** Pourquoi la copie est impossible, en phrases prêtes à afficher. Vide : elle peut partir. */
86
+ blockers: z.array(z.string()),
87
+ /** Ce que la copie n'emportera pas, à énumérer dans la confirmation. */
88
+ drops: z.array(z.string())
89
+ });
90
+ export type ItemCopyPlan = z.infer<typeof itemCopyPlanSchema>;
91
+
92
+ /** Ce que la DESTINATION dit d'une copie, avant de rien recevoir. */
93
+ export const itemCopyTargetSchema = z.object({
94
+ workspaceName: z.string(),
95
+ /**
96
+ * Le palier que la copie aura là-bas. Une copie `private` devient `open`
97
+ * dans un espace partagé, qui n'a pas de palier gardé : ses membres la liront.
98
+ */
99
+ tier: itemTierSchema,
100
+ blockers: z.array(z.string())
101
+ });
102
+ export type ItemCopyTarget = z.infer<typeof itemCopyTargetSchema>;
103
+
104
+ /** Un paquet de copie découpé : de quoi le transporter, et vérifier à l'arrivée qu'il est entier. */
105
+ export const itemCopyManifestSchema = z.object({
106
+ bytes: z.number().int().nonnegative(),
107
+ chunks: z.number().int().positive().max(4096),
108
+ /** Condensé du paquet entier : la destination refuse ce qui a changé en route. */
109
+ sha256: z.string().regex(/^[0-9a-f]{64}$/)
110
+ });
111
+ export type ItemCopyManifest = z.infer<typeof itemCopyManifestSchema>;
112
+
113
+ /** Taille d'une tranche, en caractères : bien sous le plafond d'une trame. */
114
+ export const ITEM_COPY_CHUNK_CHARS = 512 * 1024;
115
+
71
116
  /**
72
117
  * Une liaison que le déplacement va rompre. Une liaison ne traverse jamais un
73
118
  * espace : ce qui vise l'élément depuis celui qu'il quitte est retiré, et
@@ -11,11 +11,13 @@ export type TwoFactorStatus = z.infer<typeof twoFactorStatusSchema>;
11
11
 
12
12
  /**
13
13
  * One-time provisioning payload returned when starting 2FA setup. The secret
14
- * and otpauth URL are shown once; the client renders the QR code locally.
14
+ * and otpauth URL are shown once; the QR code comes drawn by the server.
15
15
  */
16
16
  export const twoFactorSetupSchema = z.object({
17
17
  secret: z.string().min(1),
18
18
  otpauthUrl: z.string().min(1),
19
+ /** The otpauth URL as a PNG data URL, drawn by the server: the secret goes to no third party. */
20
+ qrDataUrl: z.string().startsWith('data:image/png;base64,'),
19
21
  backupCodes: z.array(z.string().min(1))
20
22
  });
21
23
 
@@ -23,17 +25,19 @@ export type TwoFactorSetup = z.infer<typeof twoFactorSetupSchema>;
23
25
 
24
26
  export interface TwoFactorRow {
25
27
  user_id: number;
26
- /** Encrypted TOTP secret (zero-knowledge: never stored in clear). */
28
+ /** TOTP secret sealed under the server key (encrypted at rest, server-readable). */
27
29
  secret_enc: string;
28
30
  enabled: number;
29
31
  created: number;
30
32
  confirmed_at: number | null;
33
+ /** Time step of the last accepted TOTP code; a step at or before it is refused (replay). */
34
+ last_used_counter: number | null;
31
35
  }
32
36
 
33
37
  export interface BackupCodeRow {
34
38
  id: number;
35
39
  user_id: number;
36
- /** SHA-256 hash of the recovery code; raw codes are shown once to the user. */
40
+ /** HMAC-SHA256 of the normalized code under a key derived from the server key; raw codes are shown once. */
37
41
  code_hash: string;
38
42
  used_at: number | null;
39
43
  created: number;
@@ -7,7 +7,7 @@ import { minimalUserSchema } from './user';
7
7
  * - `personal` : créé avec le compte, un seul membre (son propriétaire), ni
8
8
  * quittable ni supprimable, jamais partageable. C'est le repli implicite quand
9
9
  * une commande ne vise aucun espace en particulier.
10
- * - `shared` : créé à la demande, plusieurs membres, rôles et invitations.
10
+ * - `shared` : créé à la demande, plusieurs membres et rôles.
11
11
  */
12
12
  export const workspaceKindSchema = z.enum(['personal', 'shared']);
13
13
  export type WorkspaceKind = z.infer<typeof workspaceKindSchema>;
@@ -188,7 +188,7 @@ export const workspaceRoleSchema = z.object({
188
188
  position: z.number().int().nonnegative(),
189
189
  capabilities: z.array(workspaceCapabilitySchema),
190
190
  features: z.array(workspaceFeatureGrantSchema),
191
- /** Attribué d'office à qui rejoint l'espace par invitation. */
191
+ /** Attribué d'office à qui rejoint l'espace. */
192
192
  isDefault: z.boolean(),
193
193
  memberCount: z.number().int().nonnegative()
194
194
  });
@@ -25,23 +25,6 @@ export const adminUserSchema = z.object({
25
25
 
26
26
  export type AdminUser = z.infer<typeof adminUserSchema>;
27
27
 
28
- /** Invitation à créer un compte, en attente d'être consommée. */
29
- export const adminInviteSchema = z.object({
30
- token: z.string(),
31
- url: z.string(),
32
- /** Adresse sur laquelle l'invitation est verrouillée, ou `null`. */
33
- email: z.string().nullable(),
34
- /** Espace rejoint dès la création du compte, ou `null`. */
35
- workspaceName: z.string().nullable(),
36
- expiresAt: z.number().int().nullable(),
37
- maxUses: z.number().int().positive().nullable(),
38
- uses: z.number().int().nonnegative(),
39
- createdBy: z.string(),
40
- created: z.number().int().nonnegative()
41
- });
42
-
43
- export type AdminInvite = z.infer<typeof adminInviteSchema>;
44
-
45
28
  export const adminUserList = {
46
29
  command: 'admin.userList' as const,
47
30
  input: z.object({}),
@@ -71,42 +54,9 @@ export const adminDeleteUser = {
71
54
  output: z.object({ userId: z.number().int().positive() })
72
55
  };
73
56
 
74
- export const adminInviteList = {
75
- command: 'admin.inviteList' as const,
76
- input: z.object({}),
77
- output: z.object({ invites: z.array(adminInviteSchema) })
78
- };
79
-
80
- export const adminInviteCreate = {
81
- command: 'admin.inviteCreate' as const,
82
- input: z.object({
83
- /** Verrouille l'invitation sur une adresse ; vide = ouverte. */
84
- email: z.string().max(320),
85
- /** Espace rejoint à la création du compte ; `null` = aucun. */
86
- workspaceId: z.number().int().positive().nullable(),
87
- ttlSeconds: z
88
- .number()
89
- .int()
90
- .positive()
91
- .max(30 * 24 * 3600)
92
- .nullable(),
93
- maxUses: z.number().int().positive().max(100).nullable()
94
- }),
95
- output: z.object({ invite: adminInviteSchema })
96
- };
97
-
98
- export const adminInviteRevoke = {
99
- command: 'admin.inviteRevoke' as const,
100
- input: z.object({ token: z.string().min(1) }),
101
- output: z.object({ token: z.string().min(1) })
102
- };
103
-
104
57
  export const adminCommands = [
105
58
  adminUserList,
106
59
  adminSetUserRole,
107
60
  adminSetUserStatus,
108
- adminDeleteUser,
109
- adminInviteList,
110
- adminInviteCreate,
111
- adminInviteRevoke
61
+ adminDeleteUser
112
62
  ] as const;
@@ -22,7 +22,7 @@ export const homeShortcutPreview = {
22
22
  command: 'home.shortcutPreview' as const,
23
23
  input: z.object({
24
24
  template: shortcutTemplateSchema,
25
- url: z.string().url().max(SHORTCUT_URL_MAX_LENGTH),
25
+ url: z.url({ protocol: /^https?$/ }).max(SHORTCUT_URL_MAX_LENGTH),
26
26
  /** Bypass the server cache and re-fetch (Ctrl/Cmd-click on the tile). */
27
27
  refresh: z.boolean().optional()
28
28
  }),
@@ -0,0 +1,37 @@
1
+ import { z } from 'zod';
2
+
3
+ import { itemProjectsStateSchema } from '../domain/project';
4
+ import { itemRefSchema } from '../domain/sharing';
5
+
6
+ /**
7
+ * Ce qui relie un élément d'espace aux projets qui l'utilisent, réglé depuis
8
+ * les réglages de l'élément. Transversal comme `share.*` : le couple
9
+ * `(feature, itemId)` est une donnée d'entrée, et le geste porte sur un espace
10
+ * qui n'est pas forcément l'actif, ce qu'aucune commande de module ne peut
11
+ * faire. Les liaisons restent celles de Projets, qui les tient par son contrat
12
+ * d'usage.
13
+ */
14
+
15
+ /** Les projets qui relient cet élément, espace par espace. */
16
+ export const projectLinksGet = {
17
+ command: 'links.projectsGet' as const,
18
+ input: itemRefSchema,
19
+ output: itemProjectsStateSchema
20
+ };
21
+
22
+ /**
23
+ * Attache l'élément à un projet, ou l'en retire. Un seul projet par appel : la
24
+ * case de l'écran est la commande, et un échec ne laisse pas les autres dans un
25
+ * état incertain.
26
+ */
27
+ export const projectLinksSet = {
28
+ command: 'links.projectsSet' as const,
29
+ input: itemRefSchema.extend({
30
+ workspaceId: z.number().int().positive(),
31
+ projectId: z.number().int().positive(),
32
+ linked: z.boolean()
33
+ }),
34
+ output: itemProjectsStateSchema
35
+ };
36
+
37
+ export const linksCommands = [projectLinksGet, projectLinksSet] as const;
@@ -3,9 +3,11 @@ import { agentCommands } from './agent';
3
3
  import { domainCommands } from './domain';
4
4
  import { feedbackCommands } from './feedback';
5
5
  import { homeCommands } from './home';
6
+ import { linksCommands } from './links';
6
7
  import { liveCommands } from './live';
7
8
  import { logsCommands } from './logs';
8
9
  import { notifyCommands } from './notify';
10
+ import { remoteCommands } from './remote';
9
11
  import { sharingCommands } from './sharing';
10
12
  import { secrecyCommands } from './secrecy';
11
13
  import { twoFactorCommands } from './twoFactor';
@@ -21,6 +23,7 @@ export interface FeatureCommandDescriptor<C extends string = string> {
21
23
 
22
24
  export const featureCommands = [
23
25
  ...workspaceCommands,
26
+ ...remoteCommands,
24
27
  ...adminCommands,
25
28
  ...userCommands,
26
29
  ...agentCommands,
@@ -31,6 +34,7 @@ export const featureCommands = [
31
34
  ...homeCommands,
32
35
  ...notifyCommands,
33
36
  ...sharingCommands,
37
+ ...linksCommands,
34
38
  ...domainCommands,
35
39
  ...liveCommands
36
40
  ] as const;
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+ import {
3
+ REMOTE_LABEL_MAX,
4
+ remoteInstanceSchema,
5
+ remoteOriginSchema
6
+ } from '../domain/remoteInstance';
7
+
8
+ /**
9
+ * Les instances distantes du compte. Commandes de compte : elles visent la
10
+ * ligne de l'appelant quel que soit l'espace porté par l'enveloppe.
11
+ */
12
+
13
+ const labelSchema = z.string().trim().min(1).max(REMOTE_LABEL_MAX);
14
+
15
+ export const remoteList = {
16
+ command: 'remote.list' as const,
17
+ input: z.object({}),
18
+ output: z.object({ instances: z.array(remoteInstanceSchema) })
19
+ };
20
+
21
+ export const remoteAdd = {
22
+ command: 'remote.add' as const,
23
+ input: z.object({ label: labelSchema, origin: remoteOriginSchema }),
24
+ output: z.object({ instance: remoteInstanceSchema })
25
+ };
26
+
27
+ export const remoteRename = {
28
+ command: 'remote.rename' as const,
29
+ input: z.object({ id: z.number().int().positive(), label: labelSchema }),
30
+ output: z.object({ instance: remoteInstanceSchema })
31
+ };
32
+
33
+ export const remoteRemove = {
34
+ command: 'remote.remove' as const,
35
+ input: z.object({ id: z.number().int().positive() }),
36
+ output: z.object({ id: z.number().int().positive() })
37
+ };
38
+
39
+ /** L'ordre complet des instances, tel que le menu des espaces les range. */
40
+ export const remoteReorder = {
41
+ command: 'remote.reorder' as const,
42
+ input: z.object({ ids: z.array(z.number().int().positive()).max(32) }),
43
+ output: z.object({ instances: z.array(remoteInstanceSchema) })
44
+ };
45
+
46
+ export const remoteCommands = [
47
+ remoteList,
48
+ remoteAdd,
49
+ remoteRename,
50
+ remoteRemove,
51
+ remoteReorder
52
+ ] as const;