@deveye/types 0.24.6 → 0.25.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveye/types",
3
- "version": "0.24.6",
3
+ "version": "0.25.1",
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,14 +131,21 @@ 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. */
138
139
  snapshot: feedbackSnapshotSchema.nullable(),
139
140
  handledAt: z.number().int().nonnegative().nullable(),
140
141
  handledBy: z.number().int().positive().nullable(),
141
- handledByName: z.string().nullable()
142
+ handledByName: z.string().nullable(),
143
+ /**
144
+ * When the report lost its author, message, address and the browser
145
+ * details that describe a person, keeping its technical part; null while
146
+ * intact.
147
+ */
148
+ anonymizedAt: z.number().int().nonnegative().nullable()
142
149
  });
143
150
  export type FeedbackEntry = z.infer<typeof feedbackEntrySchema>;
144
151
 
@@ -156,4 +163,5 @@ export interface FeedbackRow {
156
163
  created: number;
157
164
  handled_at: number | null;
158
165
  handled_by: number | null;
166
+ anonymized_at: number | null;
159
167
  }
@@ -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,72 @@
1
+ import { z } from 'zod';
2
+ import { loginStepSchema } from '../http/auth';
3
+
4
+ /** How long a trusted browser stays trusted without a login, in days. */
5
+ export const TRUSTED_BROWSER_DAYS = 90;
6
+
7
+ /** How long a successful login stays in the account's history, in days. */
8
+ export const LOGIN_HISTORY_DAYS = 90;
9
+
10
+ /** The part of that history the account is shown by default, in days. */
11
+ export const LOGIN_HISTORY_WINDOW_DAYS = 30;
12
+
13
+ /** More trusted browsers than this no longer counts as a protection of the account. */
14
+ export const TRUSTED_BROWSERS_MAX = 3;
15
+
16
+ /** A browser whose logins skip the mailed and texted codes. */
17
+ export const trustedBrowserSchema = z.object({
18
+ id: z.number().int().positive(),
19
+ /** Browser and system, from the user agent (`Firefox sur Linux`). */
20
+ label: z.string(),
21
+ /** Epoch seconds. */
22
+ createdAt: z.number().int(),
23
+ /** Epoch seconds: its last login. */
24
+ lastUsedAt: z.number().int()
25
+ });
26
+
27
+ export type TrustedBrowser = z.infer<typeof trustedBrowserSchema>;
28
+
29
+ /**
30
+ * One successful login of the account, kept so a login from a device that is
31
+ * not the account's can be spotted. Never removed by the account: an intruder
32
+ * must not be able to erase their trace.
33
+ */
34
+ export const loginEntrySchema = z.object({
35
+ id: z.number().int().positive(),
36
+ /** Epoch seconds. */
37
+ at: z.number().int(),
38
+ /** Browser and system, from the user agent (`Firefox sur Linux`). */
39
+ label: z.string(),
40
+ ip: z.string(),
41
+ /** The codes the login went through after the password; none for a trusted browser. */
42
+ steps: z.array(loginStepSchema),
43
+ /** The browser was trusted at the time. */
44
+ trusted: z.boolean(),
45
+ /** The login that opened the session asking. */
46
+ current: z.boolean()
47
+ });
48
+
49
+ export type LoginEntry = z.infer<typeof loginEntrySchema>;
50
+
51
+ /** The checks a login meets on a browser the account does not know. */
52
+ export const loginChecksStatusSchema = z.object({
53
+ email: z.object({
54
+ /** This server sends mail (`SMTP_HOST`): without it, the check does not exist. */
55
+ available: z.boolean(),
56
+ enabled: z.boolean(),
57
+ /** The account's address, masked. */
58
+ to: z.string()
59
+ }),
60
+ sms: z.object({
61
+ /** This server sends texts (`SMS_OVH_*`): without it, the check does not exist. */
62
+ available: z.boolean(),
63
+ enabled: z.boolean(),
64
+ /** The verified number, masked; `null` without one. */
65
+ phone: z.string().nullable()
66
+ }),
67
+ browsers: z.array(trustedBrowserSchema),
68
+ /** Successful logins over the last `LOGIN_HISTORY_WINDOW_DAYS` days. */
69
+ recentLogins: z.number().int().nonnegative()
70
+ });
71
+
72
+ 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,29 @@
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
+ /** Asked again after this many minutes or less: short enough to count as a protection. */
13
+ export const STEP_UP_STRICT_MINUTES = 30;
14
+
15
+ export const stepUpStatusSchema = z.object({
16
+ /** The account has an authenticator app: without one, no machine can be driven. */
17
+ twoFactor: z.boolean(),
18
+ /** Minutes without driving after which the code is asked again. */
19
+ minutes: z.number().int().min(STEP_UP_MINUTES_MIN).max(STEP_UP_MINUTES_MAX),
20
+ /** When this session's confirmation lapses (epoch ms), `null` without one. */
21
+ confirmedUntil: z.number().int().nullable()
22
+ });
23
+
24
+ export type StepUpStatus = z.infer<typeof stepUpStatusSchema>;
25
+
26
+ /** `details` of a `stepup_required` refusal. */
27
+ export const stepUpRequiredDetailsSchema = z.object({ twoFactor: z.boolean() });
28
+
29
+ export type StepUpRequiredDetails = z.infer<typeof stepUpRequiredDetailsSchema>;
@@ -66,18 +66,33 @@ 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(),
79
+ /**
80
+ * Login confirmation is on and at most `TRUSTED_BROWSERS_MAX` browsers
81
+ * skip it. `null` with `loginConfirmation`.
82
+ */
83
+ trustedBrowsers: z.boolean().nullable(),
73
84
  /** TOTP two-factor authentication is enabled. */
74
85
  twoFactor: z.boolean(),
86
+ /**
87
+ * Two-factor is on and the code to drive a machine is asked again after
88
+ * `STEP_UP_STRICT_MINUTES` or less without driving.
89
+ */
90
+ stepUpValidation: z.boolean(),
75
91
  /** Password-based encryption (DEK wrapped by the user's password) is on. */
76
92
  passwordEncryption: z.boolean(),
77
93
  /**
78
- * Password re-validation window is configured to a strict value: enabled and
79
- * short enough (≤ 5 min) to count as a protection. Disabled (0) or a long
80
- * window does not count.
94
+ * Password-based encryption is on and its re-validation window is short
95
+ * enough (5 min or less, 0 being the strongest) to count as a protection.
81
96
  */
82
97
  reAuthValidation: z.boolean()
83
98
  });
@@ -154,6 +169,10 @@ export interface UserRow {
154
169
  /** Espace favori chargé en premier ; `null` → l'espace personnel. */
155
170
  default_workspace_id: number | null;
156
171
  re_auth_interval: number | null;
172
+ /** Seconds without driving a machine after which the authenticator code is asked again. */
173
+ step_up_interval: number;
174
+ /** 1: a browser this account does not know confirms a login with a mailed code. */
175
+ login_email_check: number;
157
176
  /** Seconds. The last password sign-in; a session renews without one for weeks. */
158
177
  last_login: number;
159
178
  /** 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,102 @@
1
+ import { z } from 'zod';
2
+ import { loginChecksStatusSchema, loginEntrySchema } 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
+ /**
72
+ * The account's successful logins over the last `LOGIN_HISTORY_WINDOW_DAYS`
73
+ * days, newest first, and how many older ones the history still holds.
74
+ */
75
+ export const loginChecksHistory = {
76
+ command: 'loginChecks.history' as const,
77
+ input: z.object({}),
78
+ output: z.object({ entries: z.array(loginEntrySchema), older: z.number().int().nonnegative() })
79
+ };
80
+
81
+ /**
82
+ * Close every session of the account but the one asking: what to do after
83
+ * spotting a login that is not one's own. Answers how many sessions closed.
84
+ */
85
+ export const loginChecksLogoutOthers = {
86
+ command: 'loginChecks.logoutOthers' as const,
87
+ input: z.object({}),
88
+ output: z.object({ closed: z.number().int().nonnegative() })
89
+ };
90
+
91
+ export const loginChecksCommands = [
92
+ loginChecksStatus,
93
+ loginChecksSetEmail,
94
+ loginChecksSetSms,
95
+ loginChecksPhoneStart,
96
+ loginChecksPhoneConfirm,
97
+ loginChecksPhoneRemove,
98
+ loginChecksForgetBrowser,
99
+ loginChecksForgetBrowsers,
100
+ loginChecksHistory,
101
+ loginChecksLogoutOthers
102
+ ] 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,