@deveye/types 0.24.5 → 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.5",
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",
@@ -348,6 +348,20 @@ export const FEATURE_REGISTRY: readonly (FeatureDescriptor & { id: WorkspaceFeat
348
348
  hasItems: true,
349
349
  itemNoun: 'client',
350
350
  shareTier: 'never'
351
+ },
352
+ {
353
+ id: 'shortlinks',
354
+ label: 'Liens courts',
355
+ description:
356
+ 'Lecture : les liens et leurs statistiques. Écriture : créer un lien, changer sa destination et ses réglages, le supprimer.',
357
+ icon: 'shortlinks',
358
+ notifies: true,
359
+ notifications: {
360
+ hint: 'Envoyées quand la destination d’un lien ne répond plus, quand elle répond de nouveau, et quand les visites du mois approchent ou atteignent la limite de votre offre.'
361
+ },
362
+ hasItems: true,
363
+ itemNoun: 'lien',
364
+ shareTier: 'open'
351
365
  }
352
366
  ];
353
367
 
@@ -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. */
@@ -40,7 +40,8 @@ export const nativeHomeFeatureIdSchema = z.enum([
40
40
  'cve',
41
41
  'mailserver',
42
42
  'convert',
43
- 'invoicing'
43
+ 'invoicing',
44
+ 'shortlinks'
44
45
  ]);
45
46
  export type NativeHomeFeatureId = z.infer<typeof nativeHomeFeatureIdSchema>;
46
47
 
@@ -248,6 +249,19 @@ export const homeLayoutSchema = z.object({
248
249
  });
249
250
  export type HomeLayout = z.infer<typeof homeLayoutSchema>;
250
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
+
251
265
  /**
252
266
  * Normalized preview returned for a rich shortcut template, so the client has a
253
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
@@ -202,12 +208,15 @@ export const TOPIC_FEATURE: Record<NativeLiveTopic, WorkspaceFeatureId | null> =
202
208
  mailserver: 'mailserver',
203
209
  convert: 'convert',
204
210
  invoicing: 'invoicing',
211
+ shortlinks: 'shortlinks',
205
212
  workspace: null,
206
213
  home: null,
207
214
  account: null,
208
215
  // Réservé aux administrateurs, mais la garde est à l'émission : seuls
209
216
  // leurs comptes reçoivent la trame.
210
217
  admin: null,
218
+ // Même régime que `admin` : seuls les comptes qui modèrent reçoivent la trame.
219
+ pending: null,
211
220
  // Aucun droit de feature à vérifier : la relecture déclenchée est gardée
212
221
  // côté commande. Même nature que `workspace`.
213
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>;
@@ -44,7 +44,8 @@ export const nativeNotificationFeatureSchema = z.enum([
44
44
  'backup',
45
45
  'convert',
46
46
  'invoicing',
47
- 'finance'
47
+ 'finance',
48
+ 'shortlinks'
48
49
  ]);
49
50
  export type NativeNotificationFeature = z.infer<typeof nativeNotificationFeatureSchema>;
50
51
 
@@ -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>;
@@ -58,18 +58,24 @@ export const minimalUserSchema = z.object({
58
58
  username: z.string().min(1),
59
59
  avatar: z.string(),
60
60
  color: userColorSchema,
61
- /** Époque Unix de la dernière connexion ; `0` pour un compte jamais venu. */
62
- lastLogin: z.number().int().nonnegative(),
61
+ /** Seconds. The last time the account opened or used the app, to within a few minutes; `0` if it never came. */
62
+ lastSeen: z.number().int().nonnegative(),
63
63
  created: z.number().int().nonnegative()
64
64
  });
65
65
 
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,7 +160,14 @@ 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;
167
+ /** Seconds. The last password sign-in; a session renews without one for weeks. */
157
168
  last_login: number;
169
+ /** Seconds. The last time the account opened or used the app, to within a few minutes. */
170
+ last_seen: number;
158
171
  created: number;
159
172
  /** Seconds. When the terms of use were accepted at sign-up; `null` for an account created without a site. */
160
173
  terms_accepted_at: number | null;
@@ -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',
@@ -108,7 +108,12 @@ export const workspaceFeatureIdSchema = z.enum([
108
108
  * brouillon, enregistrer un règlement. Émettre un document et changer
109
109
  * l'identité de l'émetteur sont des permissions propres du module.
110
110
  */
111
- 'invoicing'
111
+ 'invoicing',
112
+ /**
113
+ * Liens courts. `read` = voir les liens et leurs statistiques, `write` =
114
+ * créer un lien, changer sa destination et ses réglages, le supprimer.
115
+ */
116
+ 'shortlinks'
112
117
  ]);
113
118
 
114
119
  export type WorkspaceFeatureId = z.infer<typeof workspaceFeatureIdSchema>;
@@ -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,