@deveye/types 0.18.3 → 0.19.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 +1 -1
- package/src/domain/device.ts +6 -2
- package/src/domain/featureRegistry.ts +16 -0
- package/src/domain/home.ts +5 -3
- package/src/domain/live.ts +3 -3
- package/src/domain/project.ts +56 -0
- package/src/domain/report.ts +34 -2
- package/src/domain/secrecy.ts +3 -0
- package/src/domain/twoFactor.ts +7 -3
- package/src/domain/workspace.ts +1 -1
- package/src/domain/workspaceRole.ts +1 -1
- package/src/features/admin.ts +1 -51
- package/src/features/home.ts +1 -1
- package/src/features/links.ts +37 -0
- package/src/features/registry.ts +2 -0
- package/src/features/secrecy.ts +22 -8
- package/src/features/twoFactor.ts +1 -1
- package/src/features/user.ts +32 -4
- package/src/features/workspace.ts +2 -2
- package/src/http/auth.ts +64 -11
- package/src/http/device.ts +14 -10
- package/src/index.ts +50 -10
- package/src/protocol/agent.ts +38 -0
- package/src/protocol/error.ts +3 -0
- package/src/sdk/client-ambient.d.ts +48 -1
- package/src/sdk/client.ts +81 -3
- package/src/sdk/manifest.test.ts +27 -0
- package/src/sdk/manifest.ts +60 -1
- package/src/sdk/providers.ts +102 -0
- package/src/sdk/server.ts +102 -10
- package/src/sdk/testing.test.ts +22 -0
- package/src/sdk/testing.ts +91 -2
package/package.json
CHANGED
package/src/domain/device.ts
CHANGED
|
@@ -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
|
package/src/domain/home.ts
CHANGED
|
@@ -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
|
-
*
|
|
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
|
-
|
|
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.
|
|
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
|
package/src/domain/live.ts
CHANGED
|
@@ -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
|
|
135
|
-
*
|
|
136
|
-
*
|
|
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
|
/**
|
package/src/domain/project.ts
CHANGED
|
@@ -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>;
|
package/src/domain/report.ts
CHANGED
|
@@ -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>;
|
package/src/domain/secrecy.ts
CHANGED
|
@@ -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
|
}
|
package/src/domain/twoFactor.ts
CHANGED
|
@@ -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
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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;
|
package/src/domain/workspace.ts
CHANGED
|
@@ -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
|
|
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
|
|
191
|
+
/** Attribué d'office à qui rejoint l'espace. */
|
|
192
192
|
isDefault: z.boolean(),
|
|
193
193
|
memberCount: z.number().int().nonnegative()
|
|
194
194
|
});
|
package/src/features/admin.ts
CHANGED
|
@@ -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;
|
package/src/features/home.ts
CHANGED
|
@@ -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.
|
|
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;
|
package/src/features/registry.ts
CHANGED
|
@@ -3,6 +3,7 @@ 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';
|
|
@@ -31,6 +32,7 @@ export const featureCommands = [
|
|
|
31
32
|
...homeCommands,
|
|
32
33
|
...notifyCommands,
|
|
33
34
|
...sharingCommands,
|
|
35
|
+
...linksCommands,
|
|
34
36
|
...domainCommands,
|
|
35
37
|
...liveCommands
|
|
36
38
|
] as const;
|
package/src/features/secrecy.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { secrecyStatusSchema } from '../domain/secrecy';
|
|
3
|
+
import { passwordSchema } from '../http/auth';
|
|
4
|
+
|
|
5
|
+
/** A password being verified: whatever the account already has. Bounded so Argon2 never eats a megabyte. */
|
|
6
|
+
const existingPassword = z.string().min(1).max(512);
|
|
7
|
+
const newPassword = passwordSchema;
|
|
3
8
|
|
|
4
9
|
/** Current state of password-based encryption for the caller. */
|
|
5
10
|
export const secrecyStatus = {
|
|
@@ -14,7 +19,7 @@ export const secrecyStatus = {
|
|
|
14
19
|
*/
|
|
15
20
|
export const secrecyUnlock = {
|
|
16
21
|
command: 'secrecy.unlock' as const,
|
|
17
|
-
input: z.object({ password:
|
|
22
|
+
input: z.object({ password: existingPassword }),
|
|
18
23
|
output: z.object({ status: secrecyStatusSchema })
|
|
19
24
|
};
|
|
20
25
|
|
|
@@ -26,7 +31,7 @@ export const secrecyUnlock = {
|
|
|
26
31
|
export const secrecyEnable = {
|
|
27
32
|
command: 'secrecy.enable' as const,
|
|
28
33
|
input: z.object({
|
|
29
|
-
password:
|
|
34
|
+
password: existingPassword,
|
|
30
35
|
recovery: z.boolean()
|
|
31
36
|
}),
|
|
32
37
|
output: z.object({
|
|
@@ -39,7 +44,7 @@ export const secrecyEnable = {
|
|
|
39
44
|
/** Disable the feature: re-wrap the DEK with the server key. */
|
|
40
45
|
export const secrecyDisable = {
|
|
41
46
|
command: 'secrecy.disable' as const,
|
|
42
|
-
input: z.object({ password:
|
|
47
|
+
input: z.object({ password: existingPassword }),
|
|
43
48
|
output: z.object({ status: secrecyStatusSchema })
|
|
44
49
|
};
|
|
45
50
|
|
|
@@ -91,15 +96,23 @@ export const secrecyLock = {
|
|
|
91
96
|
|
|
92
97
|
/**
|
|
93
98
|
* Recover access after a forgotten password using the recovery code, choosing
|
|
94
|
-
* a new password to re-wrap the DEK with.
|
|
99
|
+
* a new password to re-wrap the DEK with. The code that served is replaced: the
|
|
100
|
+
* new one is returned exactly once. Every other session of the account closes.
|
|
95
101
|
*/
|
|
96
102
|
export const secrecyRecover = {
|
|
97
103
|
command: 'secrecy.recover' as const,
|
|
98
104
|
input: z.object({
|
|
99
|
-
recoveryCode: z.string().min(1),
|
|
100
|
-
newPassword
|
|
105
|
+
recoveryCode: z.string().min(1).max(64),
|
|
106
|
+
newPassword
|
|
101
107
|
}),
|
|
102
|
-
output: z.object({ status: secrecyStatusSchema })
|
|
108
|
+
output: z.object({ status: secrecyStatusSchema, recoveryCode: z.string().min(1) })
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** Replace the recovery code (password required). The previous code stops working at once. */
|
|
112
|
+
export const secrecyRegenerateRecovery = {
|
|
113
|
+
command: 'secrecy.regenerateRecovery' as const,
|
|
114
|
+
input: z.object({ password: existingPassword }),
|
|
115
|
+
output: z.object({ status: secrecyStatusSchema, recoveryCode: z.string().min(1) })
|
|
103
116
|
};
|
|
104
117
|
|
|
105
118
|
export const secrecyCommands = [
|
|
@@ -111,5 +124,6 @@ export const secrecyCommands = [
|
|
|
111
124
|
secrecyHold,
|
|
112
125
|
secrecyTouch,
|
|
113
126
|
secrecyLock,
|
|
114
|
-
secrecyRecover
|
|
127
|
+
secrecyRecover,
|
|
128
|
+
secrecyRegenerateRecovery
|
|
115
129
|
] as const;
|
|
@@ -24,7 +24,7 @@ export const twoFactorEnable = {
|
|
|
24
24
|
/** Disable 2FA (requires a valid current code or backup code). */
|
|
25
25
|
export const twoFactorDisable = {
|
|
26
26
|
command: 'twofa.disable' as const,
|
|
27
|
-
input: z.object({ code: z.string().min(6).max(
|
|
27
|
+
input: z.object({ code: z.string().min(6).max(24) }),
|
|
28
28
|
output: z.object({ status: twoFactorStatusSchema })
|
|
29
29
|
};
|
|
30
30
|
|
package/src/features/user.ts
CHANGED
|
@@ -37,17 +37,29 @@ export const THEME_SLOT_COUNT = 5;
|
|
|
37
37
|
*/
|
|
38
38
|
export const THEME_SLOT_IMAGE_MAX_LENGTH = 1_500_000;
|
|
39
39
|
|
|
40
|
+
/**
|
|
41
|
+
* A wallpaper value: an image data URL, or an https URL. The theme belongs to
|
|
42
|
+
* the workspace, so every member's browser loads what one member saved: a free
|
|
43
|
+
* string would let `http:` or any other scheme through to all of them.
|
|
44
|
+
*/
|
|
45
|
+
const THEME_IMAGE =
|
|
46
|
+
/^(data:image\/(png|jpeg|webp|avif|gif);base64,[A-Za-z0-9+/]+=*|https:\/\/[^\s"'()\\]+)$/;
|
|
47
|
+
|
|
40
48
|
export const themeStateSchema = z.object({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
49
|
+
/** A hex colour: it is written as-is into CSS custom properties on every member's page. */
|
|
50
|
+
accent: z
|
|
51
|
+
.string()
|
|
52
|
+
.regex(/^#[0-9a-fA-F]{6}$/)
|
|
53
|
+
.nullable(),
|
|
54
|
+
bgPreset: z.string().max(40).nullable(),
|
|
55
|
+
bgImage: z.string().max(THEME_IMAGE_MAX_LENGTH).regex(THEME_IMAGE).nullable(),
|
|
44
56
|
/**
|
|
45
57
|
* Saved background gallery: up to THEME_SLOT_COUNT slots, each a compressed
|
|
46
58
|
* data URL / raw URL, or null for an empty slot. Defaults to empty so themes
|
|
47
59
|
* saved before this field parse cleanly.
|
|
48
60
|
*/
|
|
49
61
|
bgImages: z
|
|
50
|
-
.array(z.string().max(THEME_SLOT_IMAGE_MAX_LENGTH).nullable())
|
|
62
|
+
.array(z.string().max(THEME_SLOT_IMAGE_MAX_LENGTH).regex(THEME_IMAGE).nullable())
|
|
51
63
|
.max(THEME_SLOT_COUNT)
|
|
52
64
|
.default([]),
|
|
53
65
|
bgDim: z.number().int().min(0).max(100),
|
|
@@ -93,7 +105,23 @@ export const userSetUsername = {
|
|
|
93
105
|
output: z.object({ username: usernameSchema })
|
|
94
106
|
};
|
|
95
107
|
|
|
108
|
+
/** The plan of an account, as a plan provider states it (`sdk/providers.ts`). */
|
|
109
|
+
export const accountPlanSchema = z.object({
|
|
110
|
+
id: z.string(),
|
|
111
|
+
label: z.string(),
|
|
112
|
+
limits: z.record(z.string(), z.number().int().nonnegative()),
|
|
113
|
+
trialEndsAt: z.number().int().nonnegative().optional()
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
/** The caller's plan. `null`: this DevEye has no plan provider, everything is unlimited. */
|
|
117
|
+
export const userPlan = {
|
|
118
|
+
command: 'user.plan' as const,
|
|
119
|
+
input: z.object({}),
|
|
120
|
+
output: z.object({ plan: accountPlanSchema.nullable() })
|
|
121
|
+
};
|
|
122
|
+
|
|
96
123
|
export const userCommands = [
|
|
124
|
+
userPlan,
|
|
97
125
|
userSetAvatar,
|
|
98
126
|
userSetTheme,
|
|
99
127
|
userSetColor,
|
|
@@ -75,8 +75,8 @@ export const workspaceRemoveMember = {
|
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* Ajoute un membre à l'espace actif, désigné par son adresse. Pas de lien ni
|
|
78
|
-
* d'acceptation : le compte existe
|
|
79
|
-
*
|
|
78
|
+
* d'acceptation : le compte existe déjà, et un lien serait un secret
|
|
79
|
+
* transmissible de plus.
|
|
80
80
|
*/
|
|
81
81
|
export const workspaceAddMember = {
|
|
82
82
|
command: 'workspace.addMember' as const,
|
package/src/http/auth.ts
CHANGED
|
@@ -38,19 +38,12 @@ export const loginRequestSchema = z.object({
|
|
|
38
38
|
|
|
39
39
|
export type LoginRequest = z.infer<typeof loginRequestSchema>;
|
|
40
40
|
|
|
41
|
-
/**
|
|
42
|
-
export const
|
|
43
|
-
inviteToken: z.string().min(1),
|
|
44
|
-
username: usernameSchema,
|
|
45
|
-
email: z.string().email().max(320),
|
|
46
|
-
password: z.string().min(8).max(512)
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
export type RegisterRequest = z.infer<typeof registerRequestSchema>;
|
|
41
|
+
/** A password being chosen: the one account policy, at sign-up and at change. */
|
|
42
|
+
export const passwordSchema = z.string().min(8).max(512);
|
|
50
43
|
|
|
51
44
|
export const changePasswordRequestSchema = z.object({
|
|
52
45
|
currentPassword: z.string().min(1).max(512),
|
|
53
|
-
newPassword:
|
|
46
|
+
newPassword: passwordSchema
|
|
54
47
|
});
|
|
55
48
|
|
|
56
49
|
export type ChangePasswordRequest = z.infer<typeof changePasswordRequestSchema>;
|
|
@@ -75,7 +68,7 @@ export type LoginResponse = z.infer<typeof loginResponseSchema>;
|
|
|
75
68
|
|
|
76
69
|
export const twoFactorChallengeRequestSchema = z.object({
|
|
77
70
|
/** A 6-digit TOTP code or a recovery backup code. */
|
|
78
|
-
code: z.string().min(6).max(
|
|
71
|
+
code: z.string().min(6).max(24)
|
|
79
72
|
});
|
|
80
73
|
|
|
81
74
|
export type TwoFactorChallengeRequest = z.infer<typeof twoFactorChallengeRequestSchema>;
|
|
@@ -87,3 +80,63 @@ export type RefreshResponse = z.infer<typeof refreshResponseSchema>;
|
|
|
87
80
|
export const meResponseSchema = sessionBundleSchema;
|
|
88
81
|
|
|
89
82
|
export type MeResponse = z.infer<typeof meResponseSchema>;
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Self-service sign-up, in three steps: ask (`/signup`), open the mailed link
|
|
86
|
+
* (`/signup/verify`), choose a password (`/signup/complete`). No account exists
|
|
87
|
+
* before the last one.
|
|
88
|
+
*/
|
|
89
|
+
export const signupAvailabilitySchema = z.object({
|
|
90
|
+
/** Can an account be self-created here: the server allows it, or no account exists yet. */
|
|
91
|
+
open: z.boolean()
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export type SignupAvailability = z.infer<typeof signupAvailabilitySchema>;
|
|
95
|
+
|
|
96
|
+
export const signupStartRequestSchema = z.object({
|
|
97
|
+
username: usernameSchema,
|
|
98
|
+
email: z.string().email().max(320),
|
|
99
|
+
/** Opaque hint carried to the first session (`signupPlan`), for whoever sent the visitor. */
|
|
100
|
+
plan: z
|
|
101
|
+
.string()
|
|
102
|
+
.regex(/^[a-z0-9_-]{1,64}$/)
|
|
103
|
+
.optional()
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
export type SignupStartRequest = z.infer<typeof signupStartRequestSchema>;
|
|
107
|
+
|
|
108
|
+
export const signupStartResponseSchema = z.object({
|
|
109
|
+
/** Lets the asking tab follow the request (`X-Signup-Watch`). It is NOT the mailed token. */
|
|
110
|
+
watchToken: z.string()
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
export type SignupStartResponse = z.infer<typeof signupStartResponseSchema>;
|
|
114
|
+
|
|
115
|
+
export const signupStatusSchema = z.object({
|
|
116
|
+
/** `opened`: the mailed link was followed. An unknown watch token reads `pending`. */
|
|
117
|
+
state: z.enum(['pending', 'opened', 'done', 'expired'])
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
export type SignupStatus = z.infer<typeof signupStatusSchema>;
|
|
121
|
+
|
|
122
|
+
export const signupVerifyRequestSchema = z.object({ token: z.string().min(1).max(128) });
|
|
123
|
+
|
|
124
|
+
export type SignupVerifyRequest = z.infer<typeof signupVerifyRequestSchema>;
|
|
125
|
+
|
|
126
|
+
export const signupVerifyResponseSchema = z.object({ username: z.string(), email: z.string() });
|
|
127
|
+
|
|
128
|
+
export type SignupVerifyResponse = z.infer<typeof signupVerifyResponseSchema>;
|
|
129
|
+
|
|
130
|
+
export const signupCompleteRequestSchema = z.object({
|
|
131
|
+
token: z.string().min(1).max(128),
|
|
132
|
+
password: passwordSchema
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export type SignupCompleteRequest = z.infer<typeof signupCompleteRequestSchema>;
|
|
136
|
+
|
|
137
|
+
export const signupCompleteResponseSchema = sessionBundleSchema.extend({
|
|
138
|
+
/** The `plan` hint given at the first step, delivered once. */
|
|
139
|
+
signupPlan: z.string().nullable()
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
export type SignupCompleteResponse = z.infer<typeof signupCompleteResponseSchema>;
|