@deveye/types 0.24.6 → 0.25.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.24.6",
3
+ "version": "0.25.0",
4
4
  "description": "Shared contracts (types + zod schemas) for DevEye apps",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -117,8 +117,8 @@ export const feedbackSnapshotSchema = z.object({
117
117
  export type FeedbackSnapshot = z.infer<typeof feedbackSnapshotSchema>;
118
118
 
119
119
  /**
120
- * A report as served to the admin view. `username` and `handledByName` are
121
- * resolved server-side from the ids (null when the account is gone).
120
+ * A report as served to the moderation view. `username` and `handledByName`
121
+ * are resolved server-side from the ids (null when the account is gone).
122
122
  */
123
123
  export const feedbackEntrySchema = z.object({
124
124
  id: z.number().int().positive(),
@@ -131,7 +131,8 @@ export const feedbackEntrySchema = z.object({
131
131
  /** Workspace open at submit time — context only, never a scope. */
132
132
  workspaceId: z.number().int().positive().nullable(),
133
133
  message: z.string(),
134
- ip: z.string(),
134
+ /** Null for a moderator: only an administrator sees where a report came from. */
135
+ ip: z.string().nullable(),
135
136
  /** Server version at submit time. */
136
137
  appVersion: z.string(),
137
138
  /** The bug report; null for a plain remark. */
@@ -249,6 +249,19 @@ export const homeLayoutSchema = z.object({
249
249
  });
250
250
  export type HomeLayout = z.infer<typeof homeLayoutSchema>;
251
251
 
252
+ /**
253
+ * Every feature on the grid, folder contents included: a feature filed in a
254
+ * folder counts as placed, so the "not twice" rule needs no knowledge of folders.
255
+ */
256
+ export function placedFeatureIds(layout: HomeLayout): HomeFeatureId[] {
257
+ return layout.sections.flatMap((section) =>
258
+ section.items.flatMap((tile) => {
259
+ if (isHomeFolder(tile)) return tile.items;
260
+ return isFeatureTile(tile) ? [tile] : [];
261
+ })
262
+ );
263
+ }
264
+
252
265
  /**
253
266
  * Normalized preview returned for a rich shortcut template, so the client has a
254
267
  * single renderer regardless of the source. `ok: false` means the source could
@@ -136,6 +136,12 @@ export const nativeLiveTopicSchema = z.enum([
136
136
  * sont visés par compte (`userChanged`).
137
137
  */
138
138
  'admin',
139
+ /**
140
+ * Ce qui attend un modérateur ou un administrateur : signalements ouverts,
141
+ * retours non lus, files en retard. Comme `admin`, jamais diffusé dans une
142
+ * salle : les comptes qui modèrent sont visés un par un.
143
+ */
144
+ 'pending',
139
145
  /**
140
146
  * Les canaux d'alerte de l'espace et les routes qui pointent dessus. Un
141
147
  * sujet à part : les canaux se relisent depuis les réglages de n'importe
@@ -209,6 +215,8 @@ export const TOPIC_FEATURE: Record<NativeLiveTopic, WorkspaceFeatureId | null> =
209
215
  // Réservé aux administrateurs, mais la garde est à l'émission : seuls
210
216
  // leurs comptes reçoivent la trame.
211
217
  admin: null,
218
+ // Même régime que `admin` : seuls les comptes qui modèrent reçoivent la trame.
219
+ pending: null,
212
220
  // Aucun droit de feature à vérifier : la relecture déclenchée est gardée
213
221
  // côté commande. Même nature que `workspace`.
214
222
  notify: null,
@@ -0,0 +1,38 @@
1
+ import { z } from 'zod';
2
+
3
+ /** How long a trusted browser stays trusted without a login, in days. */
4
+ export const TRUSTED_BROWSER_DAYS = 90;
5
+
6
+ /** A browser whose logins skip the mailed and texted codes. */
7
+ export const trustedBrowserSchema = z.object({
8
+ id: z.number().int().positive(),
9
+ /** Browser and system, from the user agent (`Firefox sur Linux`). */
10
+ label: z.string(),
11
+ /** Epoch seconds. */
12
+ createdAt: z.number().int(),
13
+ /** Epoch seconds: its last login. */
14
+ lastUsedAt: z.number().int()
15
+ });
16
+
17
+ export type TrustedBrowser = z.infer<typeof trustedBrowserSchema>;
18
+
19
+ /** The checks a login meets on a browser the account does not know. */
20
+ export const loginChecksStatusSchema = z.object({
21
+ email: z.object({
22
+ /** This server sends mail (`SMTP_HOST`): without it, the check does not exist. */
23
+ available: z.boolean(),
24
+ enabled: z.boolean(),
25
+ /** The account's address, masked. */
26
+ to: z.string()
27
+ }),
28
+ sms: z.object({
29
+ /** This server sends texts (`SMS_OVH_*`): without it, the check does not exist. */
30
+ available: z.boolean(),
31
+ enabled: z.boolean(),
32
+ /** The verified number, masked; `null` without one. */
33
+ phone: z.string().nullable()
34
+ }),
35
+ browsers: z.array(trustedBrowserSchema)
36
+ });
37
+
38
+ export type LoginChecksStatus = z.infer<typeof loginChecksStatusSchema>;
@@ -1,8 +1,14 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  /**
4
- * Global account role. `admin` may manage every device and confirm/revoke
5
- * machines belonging to other users; `user` only manages its own devices.
4
+ * Global account role. `admin` runs the instance (system pages, every device
5
+ * of the fleet); `moderator` is a `user` who also handles what awaits a human
6
+ * decision (reports, user feedback); `user` only manages its own things.
6
7
  */
7
- export const userRoleSchema = z.enum(['user', 'admin']);
8
+ export const userRoleSchema = z.enum(['user', 'moderator', 'admin']);
8
9
  export type UserRole = z.infer<typeof userRoleSchema>;
10
+
11
+ /** The role opens the moderation pages: a moderator, or an administrator. */
12
+ export function canModerate(role: UserRole): boolean {
13
+ return role === 'moderator' || role === 'admin';
14
+ }
@@ -0,0 +1,27 @@
1
+ import { z } from 'zod';
2
+
3
+ /**
4
+ * Driving a machine (its terminal, its files, its containers, its power, its
5
+ * network, a new one paired) needs a code from the account's authenticator app,
6
+ * typed in the same session less than `minutes` ago. Seeing a machine needs
7
+ * nothing: a stolen password or cookie watches, it does not drive.
8
+ */
9
+ export const STEP_UP_MINUTES_MIN = 1;
10
+ export const STEP_UP_MINUTES_MAX = 480;
11
+ export const STEP_UP_MINUTES_DEFAULT = 15;
12
+
13
+ export const stepUpStatusSchema = z.object({
14
+ /** The account has an authenticator app: without one, no machine can be driven. */
15
+ twoFactor: z.boolean(),
16
+ /** Minutes without driving after which the code is asked again. */
17
+ minutes: z.number().int().min(STEP_UP_MINUTES_MIN).max(STEP_UP_MINUTES_MAX),
18
+ /** When this session's confirmation lapses (epoch ms), `null` without one. */
19
+ confirmedUntil: z.number().int().nullable()
20
+ });
21
+
22
+ export type StepUpStatus = z.infer<typeof stepUpStatusSchema>;
23
+
24
+ /** `details` of a `stepup_required` refusal. */
25
+ export const stepUpRequiredDetailsSchema = z.object({ twoFactor: z.boolean() });
26
+
27
+ export type StepUpRequiredDetails = z.infer<typeof stepUpRequiredDetailsSchema>;
@@ -66,10 +66,16 @@ export const minimalUserSchema = z.object({
66
66
  export type MinimalUser = z.infer<typeof minimalUserSchema>;
67
67
 
68
68
  /**
69
- * Account security posture, surfaced in the profile as "Sécurité → x / 3".
70
- * Each flag is one of the three main protections.
69
+ * Account security posture, surfaced in the profile as "Sécurité → x / y".
70
+ * Each flag is one of the main protections.
71
71
  */
72
72
  export const userSecuritySchema = z.object({
73
+ /**
74
+ * A browser the account does not know confirms a login with a mailed or
75
+ * texted code. `null` when this server sends neither: the protection does
76
+ * not exist here and is not counted.
77
+ */
78
+ loginConfirmation: z.boolean().nullable(),
73
79
  /** TOTP two-factor authentication is enabled. */
74
80
  twoFactor: z.boolean(),
75
81
  /** Password-based encryption (DEK wrapped by the user's password) is on. */
@@ -154,6 +160,10 @@ export interface UserRow {
154
160
  /** Espace favori chargé en premier ; `null` → l'espace personnel. */
155
161
  default_workspace_id: number | null;
156
162
  re_auth_interval: number | null;
163
+ /** Seconds without driving a machine after which the authenticator code is asked again. */
164
+ step_up_interval: number;
165
+ /** 1: a browser this account does not know confirms a login with a mailed code. */
166
+ login_email_check: number;
157
167
  /** Seconds. The last password sign-in; a session renews without one for weeks. */
158
168
  last_login: number;
159
169
  /** Seconds. The last time the account opened or used the app, to within a few minutes. */
@@ -58,3 +58,24 @@ export interface WorkspaceMemberRow {
58
58
  workspace_id: number;
59
59
  date: number;
60
60
  }
61
+
62
+ /** How long an invitation stays open, in seconds. */
63
+ export const WORKSPACE_INVITATION_TTL_SECONDS = 14 * 24 * 3600;
64
+
65
+ /**
66
+ * A standing invitation to join a workspace, addressed to an email (lower
67
+ * case) rather than to an account: the address may not have one yet. `role_id`
68
+ * is the role the invitee gets on accepting, fixed when the invitation was
69
+ * sent, so it is the one the inviter was allowed to hand out.
70
+ */
71
+ export interface WorkspaceInvitationRow {
72
+ id: number;
73
+ workspace_id: number;
74
+ email: string;
75
+ role_id: number | null;
76
+ invited_by: number;
77
+ /** Seconds. */
78
+ created_at: number;
79
+ /** Seconds. */
80
+ expires_at: number;
81
+ }
@@ -14,7 +14,7 @@ import { z } from 'zod';
14
14
  export const workspaceCapabilitySchema = z.enum([
15
15
  /** Renommer l'espace, changer son logo, le supprimer. */
16
16
  'workspace.manage',
17
- /** Ajouter un membre par son adresse, l'exclure, lui attribuer un rôle. */
17
+ /** Inviter un membre, l'exclure, lui attribuer un rôle. */
18
18
  'workspace.members',
19
19
  /** Créer, modifier, supprimer et ordonner les rôles. */
20
20
  'workspace.roles',
@@ -8,8 +8,8 @@ import { userStatusSchema } from '../domain/user';
8
8
  /**
9
9
  * Administration des comptes, à l'échelle du site et non d'un espace.
10
10
  *
11
- * Toutes ces commandes déclarent `admin: true` côté serveur : elles sont
12
- * réservées au rôle global, seul niveau au-dessus des espaces.
11
+ * Ces commandes déclarent `admin: true` côté serveur, sauf `admin.pending`
12
+ * (`moderation: true`) : le rôle global est le seul niveau au-dessus des espaces.
13
13
  */
14
14
 
15
15
  /** Un compte, tel que la page Utilisateurs l'affiche. */
@@ -199,6 +199,61 @@ export const adminExternalServices = {
199
199
  output: adminExternalServicesSchema
200
200
  };
201
201
 
202
+ /**
203
+ * Ce qui attend une décision humaine, ce qui allume les badges du menu. Un
204
+ * modérateur ne reçoit que les onglets de modération des fonctionnalités qu'il
205
+ * peut ouvrir et les retours ; un administrateur reçoit tout.
206
+ */
207
+ export const adminPendingSchema = z.object({
208
+ /** Les retours non lus ; 0 quand les retours sont fermés sur l'instance. */
209
+ feedback: z.number().int().nonnegative(),
210
+ /** Par fonctionnalité puis par onglet (`manifest.adminTabs`), seulement ce qui n'est pas nul. */
211
+ features: z.record(z.string(), z.record(z.string(), z.number().int().positive()))
212
+ });
213
+ export type AdminPending = z.infer<typeof adminPendingSchema>;
214
+
215
+ export const adminPending = {
216
+ command: 'admin.pending' as const,
217
+ input: z.object({}),
218
+ output: adminPendingSchema
219
+ };
220
+
221
+ /** Un chiffre d'une fonctionnalité pour l'administrateur : un nombre, ou une taille en octets. */
222
+ export const adminFeatureFactSchema = z.object({
223
+ label: z.string().min(1),
224
+ value: z.number().nonnegative(),
225
+ unit: z.enum(['count', 'bytes'])
226
+ });
227
+ export type AdminFeatureFact = z.infer<typeof adminFeatureFactSchema>;
228
+
229
+ /** Les chiffres globaux d'une fonctionnalité, tous comptes confondus. */
230
+ export const adminFeatureStatsSchema = z.object({
231
+ /** Espaces dont l'accueil porte la fonctionnalité, dossiers compris ; `null` sans tuile (menu du compte seul). */
232
+ workspaces: z.number().int().nonnegative().nullable(),
233
+ /** Comptes distincts membres de ces espaces, propriétaires compris ; `null` sans tuile. */
234
+ accounts: z.number().int().nonnegative().nullable(),
235
+ /** Ses tables, d'après les statistiques de MySQL : des estimations, qui peuvent retarder. */
236
+ storage: z.object({
237
+ tables: z.number().int().nonnegative(),
238
+ rows: z.number().int().nonnegative(),
239
+ bytes: z.number().int().nonnegative()
240
+ }),
241
+ /** Le total de chaque quota mesurable, tous espaces confondus, sous le libellé du quota. */
242
+ quotas: z.array(adminFeatureFactSchema),
243
+ /** Les chiffres propres du module ; `null` quand il n'a pas répondu. */
244
+ facts: z.array(adminFeatureFactSchema).nullable(),
245
+ /** Millisecondes : quand ces chiffres ont été calculés. */
246
+ computedAt: z.number().int().nonnegative()
247
+ });
248
+ export type AdminFeatureStats = z.infer<typeof adminFeatureStatsSchema>;
249
+
250
+ /** `refresh` : recompter maintenant plutôt que rendre le dernier calcul (gardé quelques minutes). */
251
+ export const adminFeatureStats = {
252
+ command: 'admin.featureStats' as const,
253
+ input: z.object({ featureId: z.string().min(1).max(64), refresh: z.boolean() }),
254
+ output: adminFeatureStatsSchema
255
+ };
256
+
202
257
  export const adminCommands = [
203
258
  adminUserList,
204
259
  adminSetUserRole,
@@ -211,5 +266,7 @@ export const adminCommands = [
211
266
  adminMaintenanceSignups,
212
267
  adminMaintenanceSeats,
213
268
  adminMaintenanceDismissNotice,
214
- adminExternalServices
269
+ adminExternalServices,
270
+ adminPending,
271
+ adminFeatureStats
215
272
  ] as const;
@@ -13,7 +13,7 @@ export const FEEDBACK_PAGE_DEFAULT = 30;
13
13
 
14
14
  /**
15
15
  * Submit a report. Open to any signed-in account, and the only command here
16
- * that is: reading feedback is an admin matter, writing one is not.
16
+ * that is: reading feedback is a moderation matter, writing one is not.
17
17
  *
18
18
  * The snapshot only makes sense on a `bug` — the server drops it otherwise, so
19
19
  * a remark can never quietly carry a technical report.
@@ -29,8 +29,8 @@ export const feedbackSubmit = {
29
29
  };
30
30
 
31
31
  /**
32
- * AND-combined filter for the admin list; every field is optional. All omitted
33
- * → the unfiltered, newest-first feed.
32
+ * AND-combined filter for the moderation list; every field is optional. All
33
+ * omitted → the unfiltered, newest-first feed.
34
34
  */
35
35
  export const feedbackFilterSchema = z.object({
36
36
  kind: feedbackKindSchema.optional(),
@@ -43,8 +43,9 @@ export const feedbackFilterSchema = z.object({
43
43
  export type FeedbackFilter = z.infer<typeof feedbackFilterSchema>;
44
44
 
45
45
  /**
46
- * Page through reports newest-first. Admin-only. `total` counts what matches
47
- * the filter, ignoring paging; `hasMore` says whether a page follows.
46
+ * Page through reports newest-first. Moderators and administrators. `total`
47
+ * counts what matches the filter, ignoring paging; `hasMore` says whether a
48
+ * page follows.
48
49
  */
49
50
  export const feedbackList = {
50
51
  command: 'feedback.list' as const,
@@ -61,7 +62,7 @@ export const feedbackList = {
61
62
  })
62
63
  };
63
64
 
64
- /** Move a report through triage. Admin-only. */
65
+ /** Move a report through triage. Moderators and administrators. */
65
66
  export const feedbackSetStatus = {
66
67
  command: 'feedback.setStatus' as const,
67
68
  input: z.object({
@@ -71,7 +72,7 @@ export const feedbackSetStatus = {
71
72
  output: z.object({ entry: feedbackEntrySchema })
72
73
  };
73
74
 
74
- /** Drop a report for good. Admin-only. */
75
+ /** Drop a report for good. Moderators and administrators. */
75
76
  export const feedbackDelete = {
76
77
  command: 'feedback.delete' as const,
77
78
  input: z.object({ id: z.number().int().positive() }),
@@ -0,0 +1,80 @@
1
+ import { z } from 'zod';
2
+ import { loginChecksStatusSchema } from '../domain/loginChecks';
3
+
4
+ const output = z.object({ status: loginChecksStatusSchema });
5
+
6
+ export const loginChecksStatus = {
7
+ command: 'loginChecks.status' as const,
8
+ input: z.object({}),
9
+ output
10
+ };
11
+
12
+ /**
13
+ * Turn the mailed code on or off. Turning it off asks for the account password:
14
+ * a stolen session must not lower the guard of the next login.
15
+ */
16
+ export const loginChecksSetEmail = {
17
+ command: 'loginChecks.setEmail' as const,
18
+ input: z.object({ enabled: z.boolean(), password: z.string().min(1).max(512).optional() }),
19
+ output
20
+ };
21
+
22
+ /**
23
+ * Turn the texted code on or off, for the verified number. Turning it off asks
24
+ * for the account password, as for the mailed code.
25
+ */
26
+ export const loginChecksSetSms = {
27
+ command: 'loginChecks.setSms' as const,
28
+ input: z.object({ enabled: z.boolean(), password: z.string().min(1).max(512).optional() }),
29
+ output
30
+ };
31
+
32
+ /**
33
+ * Send a code to a new number, to prove it is the account's. The account
34
+ * password is asked: a stolen session must not move the texted code to its own
35
+ * phone. Answers where the code went, masked.
36
+ */
37
+ export const loginChecksPhoneStart = {
38
+ command: 'loginChecks.phoneStart' as const,
39
+ input: z.object({ phone: z.string().min(4).max(32), password: z.string().min(1).max(512) }),
40
+ output: z.object({ to: z.string() })
41
+ };
42
+
43
+ /** The code received: the number becomes the account's, the texted code turned on. */
44
+ export const loginChecksPhoneConfirm = {
45
+ command: 'loginChecks.phoneConfirm' as const,
46
+ input: z.object({ code: z.string().length(6) }),
47
+ output
48
+ };
49
+
50
+ /** Forget the account's number, and the texted code with it. */
51
+ export const loginChecksPhoneRemove = {
52
+ command: 'loginChecks.phoneRemove' as const,
53
+ input: z.object({ password: z.string().min(1).max(512) }),
54
+ output
55
+ };
56
+
57
+ /** Stop trusting one browser: its next login asks for the codes again. */
58
+ export const loginChecksForgetBrowser = {
59
+ command: 'loginChecks.forgetBrowser' as const,
60
+ input: z.object({ id: z.number().int().positive() }),
61
+ output
62
+ };
63
+
64
+ /** Stop trusting every browser of the account. */
65
+ export const loginChecksForgetBrowsers = {
66
+ command: 'loginChecks.forgetBrowsers' as const,
67
+ input: z.object({}),
68
+ output
69
+ };
70
+
71
+ export const loginChecksCommands = [
72
+ loginChecksStatus,
73
+ loginChecksSetEmail,
74
+ loginChecksSetSms,
75
+ loginChecksPhoneStart,
76
+ loginChecksPhoneConfirm,
77
+ loginChecksPhoneRemove,
78
+ loginChecksForgetBrowser,
79
+ loginChecksForgetBrowsers
80
+ ] as const;
@@ -10,6 +10,8 @@ import { notifyCommands } from './notify';
10
10
  import { remoteCommands } from './remote';
11
11
  import { sharingCommands } from './sharing';
12
12
  import { secrecyCommands } from './secrecy';
13
+ import { loginChecksCommands } from './loginChecks';
14
+ import { stepUpCommands } from './stepUp';
13
15
  import { twoFactorCommands } from './twoFactor';
14
16
  import { userCommands } from './user';
15
17
  import { adminCommands } from './admin';
@@ -30,6 +32,8 @@ export const featureCommands = [
30
32
  ...userCommands,
31
33
  ...agentCommands,
32
34
  ...twoFactorCommands,
35
+ ...stepUpCommands,
36
+ ...loginChecksCommands,
33
37
  ...secrecyCommands,
34
38
  ...logsCommands,
35
39
  ...feedbackCommands,
@@ -0,0 +1,26 @@
1
+ import { z } from 'zod';
2
+ import { STEP_UP_MINUTES_MAX, STEP_UP_MINUTES_MIN, stepUpStatusSchema } from '../domain/stepUp';
3
+
4
+ export const stepUpStatus = {
5
+ command: 'stepup.status' as const,
6
+ input: z.object({}),
7
+ output: z.object({ status: stepUpStatusSchema })
8
+ };
9
+
10
+ /** Confirm with a current authenticator code, or a recovery code (spent). */
11
+ export const stepUpConfirm = {
12
+ command: 'stepup.confirm' as const,
13
+ input: z.object({ code: z.string().min(6).max(24) }),
14
+ output: z.object({ status: stepUpStatusSchema })
15
+ };
16
+
17
+ /** How long a confirmation lasts without driving a machine. */
18
+ export const stepUpSetInterval = {
19
+ command: 'stepup.setInterval' as const,
20
+ input: z.object({
21
+ minutes: z.number().int().min(STEP_UP_MINUTES_MIN).max(STEP_UP_MINUTES_MAX)
22
+ }),
23
+ output: z.object({ status: stepUpStatusSchema })
24
+ };
25
+
26
+ export const stepUpCommands = [stepUpStatus, stepUpConfirm, stepUpSetInterval] as const;
@@ -1,16 +1,23 @@
1
1
  import { z } from 'zod';
2
2
  import { twoFactorSetupSchema, twoFactorStatusSchema } from '../domain/twoFactor';
3
3
 
4
+ /** The code of the account's app, or one of its recovery codes. */
5
+ const authenticatorCode = z.string().min(6).max(24);
6
+
4
7
  export const twoFactorGetStatus = {
5
8
  command: 'twofa.status' as const,
6
9
  input: z.object({}),
7
10
  output: z.object({ status: twoFactorStatusSchema })
8
11
  };
9
12
 
10
- /** Begin enrollment: returns a fresh secret, otpauth URL and backup codes. */
13
+ /**
14
+ * Begin enrollment: returns a fresh secret, otpauth URL and backup codes. The
15
+ * account password is asked: a stolen session must not plant its own app,
16
+ * which would then open the machines (`stepup.confirm`).
17
+ */
11
18
  export const twoFactorSetup = {
12
19
  command: 'twofa.setup' as const,
13
- input: z.object({}),
20
+ input: z.object({ password: z.string().min(1).max(512) }),
14
21
  output: z.object({ setup: twoFactorSetupSchema })
15
22
  };
16
23
 
@@ -24,17 +31,17 @@ export const twoFactorEnable = {
24
31
  /** Disable 2FA (requires a valid current code or backup code). */
25
32
  export const twoFactorDisable = {
26
33
  command: 'twofa.disable' as const,
27
- input: z.object({ code: z.string().min(6).max(24) }),
34
+ input: z.object({ code: authenticatorCode }),
28
35
  output: z.object({ status: twoFactorStatusSchema })
29
36
  };
30
37
 
31
38
  /**
32
- * Regenerate recovery codes (invalidates previous ones). Authenticated by the
33
- * live session — no fresh TOTP code is required, only that 2FA be enabled.
39
+ * Regenerate recovery codes (invalidates previous ones). A current code is
40
+ * asked: the new codes open the machines as the app does.
34
41
  */
35
42
  export const twoFactorRegenBackup = {
36
43
  command: 'twofa.regenBackup' as const,
37
- input: z.object({}),
44
+ input: z.object({ code: authenticatorCode }),
38
45
  output: z.object({ backupCodes: z.array(z.string().min(1)) })
39
46
  };
40
47
 
@@ -184,8 +184,31 @@ export const userExportPrepare = {
184
184
  })
185
185
  };
186
186
 
187
+ /**
188
+ * Les invitations adressées à l'adresse du compte, encore ouvertes : l'espace
189
+ * qui invite et qui a invité, de quoi accepter ou refuser en connaissance.
190
+ */
191
+ export const userInvitations = {
192
+ command: 'user.invitations' as const,
193
+ input: z.object({}),
194
+ output: z.object({
195
+ invitations: z.array(
196
+ z.object({
197
+ id: z.number().int().positive(),
198
+ workspaceId: z.number().int().positive(),
199
+ workspaceName: z.string(),
200
+ /** Username of the member who sent it. */
201
+ invitedBy: z.string(),
202
+ /** Seconds. */
203
+ expiresAt: z.number().int().nonnegative()
204
+ })
205
+ )
206
+ })
207
+ };
208
+
187
209
  export const userCommands = [
188
210
  userDeleteAccount,
211
+ userInvitations,
189
212
  userExportPreview,
190
213
  userExportPrepare,
191
214
  userPlan,
@@ -66,7 +66,20 @@ export const workspaceLeave = {
66
66
  output: z.object({ workspaceId: z.number().int().positive() })
67
67
  };
68
68
 
69
- /** Exclut un membre de l'espace actif. Réservé au propriétaire. */
69
+ /**
70
+ * Ce qu'un départ emporte avec le membre : les projections qu'il avait réglées
71
+ * entre cet espace et d'autres, dans les deux sens, nommées pour la
72
+ * confirmation. Pour soi-même, ou pour un autre avec `workspace.members`.
73
+ */
74
+ export const workspaceMemberShares = {
75
+ command: 'workspace.memberShares' as const,
76
+ input: z.object({ userId: z.number().int().positive() }),
77
+ output: z.object({
78
+ shares: z.array(z.object({ feature: z.string(), label: z.string() }))
79
+ })
80
+ };
81
+
82
+ /** Exclut un membre de l'espace actif, et retire ses projections avec lui. */
70
83
  export const workspaceRemoveMember = {
71
84
  command: 'workspace.removeMember' as const,
72
85
  input: z.object({ userId: z.number().int().positive() }),
@@ -74,16 +87,54 @@ export const workspaceRemoveMember = {
74
87
  };
75
88
 
76
89
  /**
77
- * Ajoute un membre à l'espace actif, désigné par son adresse. Pas de lien ni
78
- * d'acceptation : le compte existe déjà, et un lien serait un secret
79
- * transmissible de plus.
90
+ * Invite une adresse à rejoindre l'espace actif. La réponse ne dit jamais si un
91
+ * compte porte cette adresse : l'invitation est posée telle quelle, et c'est le
92
+ * compte qui l'accepte (`workspace.acceptInvite`) ou la refuse.
80
93
  */
81
- export const workspaceAddMember = {
82
- command: 'workspace.addMember' as const,
94
+ export const workspaceInvite = {
95
+ command: 'workspace.invite' as const,
83
96
  input: z.object({ email: z.string().email() }),
97
+ output: z.object({})
98
+ };
99
+
100
+ /** Les invitations en attente de l'espace actif, pour qui gère ses membres. */
101
+ export const workspaceInvitations = {
102
+ command: 'workspace.invitations' as const,
103
+ input: z.object({}),
104
+ output: z.object({
105
+ invitations: z.array(
106
+ z.object({
107
+ id: z.number().int().positive(),
108
+ email: z.string(),
109
+ /** Seconds. */
110
+ expiresAt: z.number().int().nonnegative()
111
+ })
112
+ )
113
+ })
114
+ };
115
+
116
+ export const workspaceCancelInvite = {
117
+ command: 'workspace.cancelInvite' as const,
118
+ input: z.object({ invitationId: z.number().int().positive() }),
119
+ output: z.object({ invitationId: z.number().int().positive() })
120
+ };
121
+
122
+ /**
123
+ * Accepte une invitation adressée à l'appelant : il devient membre de l'espace,
124
+ * avec le rôle fixé à l'invitation. L'espace rendu est celui qu'il rejoint.
125
+ */
126
+ export const workspaceAcceptInvite = {
127
+ command: 'workspace.acceptInvite' as const,
128
+ input: z.object({ invitationId: z.number().int().positive() }),
84
129
  output: z.object({ workspace: workspaceSchema })
85
130
  };
86
131
 
132
+ export const workspaceDeclineInvite = {
133
+ command: 'workspace.declineInvite' as const,
134
+ input: z.object({ invitationId: z.number().int().positive() }),
135
+ output: z.object({ invitationId: z.number().int().positive() })
136
+ };
137
+
87
138
  /** Le contenu modifiable d'un rôle. */
88
139
  const roleDraftSchema = z.object({
89
140
  name: z.string().min(1).max(WORKSPACE_ROLE_NAME_MAX),
@@ -157,8 +208,13 @@ export const workspaceCommands = [
157
208
  workspaceAssignRole,
158
209
  workspaceRename,
159
210
  workspaceLeave,
211
+ workspaceMemberShares,
160
212
  workspaceRemoveMember,
161
- workspaceAddMember,
213
+ workspaceInvite,
214
+ workspaceInvitations,
215
+ workspaceCancelInvite,
216
+ workspaceAcceptInvite,
217
+ workspaceDeclineInvite,
162
218
  workspaceAdd,
163
219
  workspaceDelete,
164
220
  workspaceActivate,