@deveye/types 0.20.3 → 0.21.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/admission.ts +37 -0
- package/src/domain/device.ts +7 -3
- package/src/domain/featureRegistry.ts +3 -2
- package/src/domain/maintenance.ts +7 -1
- package/src/domain/notifications.ts +16 -0
- package/src/domain/packages.ts +34 -2
- package/src/domain/report.ts +12 -3
- package/src/domain/secrecy.ts +13 -0
- package/src/domain/user.ts +2 -0
- package/src/features/admin.ts +59 -1
- package/src/features/debug.ts +372 -0
- package/src/features/registry.ts +2 -0
- package/src/features/user.ts +46 -0
- package/src/http/device.ts +33 -15
- package/src/http/status.ts +6 -0
- package/src/index.ts +102 -6
- package/src/protocol/agent.ts +27 -2
- package/src/protocol/error.ts +4 -1
- package/src/sdk/accountExport.test.ts +115 -0
- package/src/sdk/accountExport.ts +254 -0
- package/src/sdk/client-ambient.d.ts +86 -0
- package/src/sdk/client.ts +44 -0
- package/src/sdk/devb.test.ts +148 -0
- package/src/sdk/devb.ts +146 -0
- package/src/sdk/download.test.ts +40 -0
- package/src/sdk/download.ts +48 -0
- package/src/sdk/manifest.test.ts +17 -1
- package/src/sdk/manifest.ts +51 -11
- package/src/sdk/net.test.ts +42 -1
- package/src/sdk/net.ts +100 -2
- package/src/sdk/pool.test.ts +36 -0
- package/src/sdk/pool.ts +26 -0
- package/src/sdk/providers.ts +107 -11
- package/src/sdk/server.ts +388 -13
- package/src/sdk/testing.test.ts +66 -0
- package/src/sdk/testing.ts +211 -2
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* La page « Tests et débogage », réservée à l'administrateur du site : essais
|
|
5
|
+
* de bout en bout, mesures, testeur de mails et suivi d'usage de DevEye.
|
|
6
|
+
*
|
|
7
|
+
* Toutes ces commandes déclarent `admin: true` côté serveur. Un essai dure
|
|
8
|
+
* plus longtemps qu'une commande : `debug.e2eStart` et `debug.benchStart`
|
|
9
|
+
* rendent aussitôt un identifiant, que la page suit par `debug.runGet`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const authorSchema = z.object({ id: z.number().int().positive(), username: z.string() });
|
|
13
|
+
|
|
14
|
+
export const debugInstanceSchema = z.object({
|
|
15
|
+
/** `PUBLIC_ORIGIN` : ce qui distingue deux serveurs sur la même base. */
|
|
16
|
+
origin: z.string(),
|
|
17
|
+
environment: z.enum(['dev', 'test', 'prod']),
|
|
18
|
+
version: z.string(),
|
|
19
|
+
/** Millisecondes. */
|
|
20
|
+
startedAt: z.number().int().nonnegative()
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const debugRunKindSchema = z.enum(['e2e', 'bench']);
|
|
24
|
+
export const debugRunStatusSchema = z.enum(['running', 'passed', 'failed', 'aborted']);
|
|
25
|
+
|
|
26
|
+
/** L'état d'une étape ou d'un scénario ; `pending` tant que son tour n'est pas venu. */
|
|
27
|
+
export const debugStepStatusSchema = z.enum(['pending', 'running', 'passed', 'failed', 'skipped']);
|
|
28
|
+
|
|
29
|
+
export const debugE2eStepSchema = z.object({
|
|
30
|
+
label: z.string(),
|
|
31
|
+
status: debugStepStatusSchema,
|
|
32
|
+
durationMs: z.number().nonnegative().nullable(),
|
|
33
|
+
/** Ce que l'étape a constaté, ou pourquoi elle a échoué. */
|
|
34
|
+
detail: z.string().nullable()
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
export const debugE2eScenarioReportSchema = z.object({
|
|
38
|
+
/** `<source>.<id>` : `core.account`, `notes.lifecycle`. */
|
|
39
|
+
id: z.string(),
|
|
40
|
+
label: z.string(),
|
|
41
|
+
sourceLabel: z.string(),
|
|
42
|
+
status: debugStepStatusSchema,
|
|
43
|
+
/** Pourquoi il n'a pas tourné, quand il est ignoré. */
|
|
44
|
+
skipReason: z.string().nullable(),
|
|
45
|
+
durationMs: z.number().nonnegative().nullable(),
|
|
46
|
+
steps: z.array(debugE2eStepSchema),
|
|
47
|
+
/** Le ménage de fin de scénario : ce qui n'a pas pu être défait. */
|
|
48
|
+
cleanup: z.object({ ok: z.boolean(), detail: z.string().nullable() }).nullable()
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
export const debugE2eReportSchema = z.object({
|
|
52
|
+
kind: z.literal('e2e'),
|
|
53
|
+
scenarios: z.array(debugE2eScenarioReportSchema),
|
|
54
|
+
/** Comptes de test encore présents après le ménage final ; `null` tant qu'il n'a pas eu lieu. */
|
|
55
|
+
residueAfter: z.number().int().nonnegative().nullable()
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const debugBenchProfileSchema = z.enum(['quick', 'full']);
|
|
59
|
+
|
|
60
|
+
/** Une sonde : ses durées en millisecondes, ou la raison qui l'a écartée. */
|
|
61
|
+
export const debugProbeResultSchema = z.object({
|
|
62
|
+
id: z.string(),
|
|
63
|
+
label: z.string(),
|
|
64
|
+
n: z.number().int().nonnegative(),
|
|
65
|
+
p50: z.number().nonnegative().nullable(),
|
|
66
|
+
p95: z.number().nonnegative().nullable(),
|
|
67
|
+
max: z.number().nonnegative().nullable(),
|
|
68
|
+
mean: z.number().nonnegative().nullable(),
|
|
69
|
+
errors: z.number().int().nonnegative(),
|
|
70
|
+
skipped: z.string().nullable()
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
/** Ce que faisait le serveur pendant la mesure : de quoi comparer deux mesures prises sous des charges différentes. */
|
|
74
|
+
export const debugBenchContextSchema = z.object({
|
|
75
|
+
loop: z.object({ p50: z.number(), p99: z.number(), max: z.number() }),
|
|
76
|
+
rssMb: z.number(),
|
|
77
|
+
heapMb: z.number(),
|
|
78
|
+
cpuPct: z.number(),
|
|
79
|
+
loadavg: z.tuple([z.number(), z.number(), z.number()]),
|
|
80
|
+
wsSockets: z.number().int().nonnegative(),
|
|
81
|
+
agentsOnline: z.number().int().nonnegative(),
|
|
82
|
+
uptimeS: z.number().nonnegative(),
|
|
83
|
+
version: z.string()
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
export const debugBenchReportSchema = z.object({
|
|
87
|
+
kind: z.literal('bench'),
|
|
88
|
+
profile: debugBenchProfileSchema,
|
|
89
|
+
probes: z.array(debugProbeResultSchema),
|
|
90
|
+
context: debugBenchContextSchema.nullable()
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
export const debugRunSchema = z.object({
|
|
94
|
+
id: z.number().int().positive(),
|
|
95
|
+
status: debugRunStatusSchema,
|
|
96
|
+
/** Millisecondes. */
|
|
97
|
+
startedAt: z.number().int().nonnegative(),
|
|
98
|
+
finishedAt: z.number().int().nonnegative().nullable(),
|
|
99
|
+
launchedBy: authorSchema.nullable(),
|
|
100
|
+
report: z.discriminatedUnion('kind', [debugE2eReportSchema, debugBenchReportSchema])
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
export type DebugE2eStep = z.infer<typeof debugE2eStepSchema>;
|
|
104
|
+
export type DebugE2eScenarioReport = z.infer<typeof debugE2eScenarioReportSchema>;
|
|
105
|
+
export type DebugE2eReport = z.infer<typeof debugE2eReportSchema>;
|
|
106
|
+
export type DebugProbeResult = z.infer<typeof debugProbeResultSchema>;
|
|
107
|
+
export type DebugBenchContext = z.infer<typeof debugBenchContextSchema>;
|
|
108
|
+
export type DebugBenchReport = z.infer<typeof debugBenchReportSchema>;
|
|
109
|
+
export type DebugRun = z.infer<typeof debugRunSchema>;
|
|
110
|
+
export type DebugRunKind = z.infer<typeof debugRunKindSchema>;
|
|
111
|
+
export type DebugBenchProfile = z.infer<typeof debugBenchProfileSchema>;
|
|
112
|
+
export type DebugStepStatus = z.infer<typeof debugStepStatusSchema>;
|
|
113
|
+
|
|
114
|
+
export const debugOverview = {
|
|
115
|
+
command: 'debug.overview' as const,
|
|
116
|
+
input: z.object({}),
|
|
117
|
+
output: z.object({
|
|
118
|
+
instance: debugInstanceSchema,
|
|
119
|
+
/** L'essai en cours, pour s'y rattacher après un rechargement de la page. */
|
|
120
|
+
activeRun: z
|
|
121
|
+
.object({ id: z.number().int().positive(), kind: debugRunKindSchema })
|
|
122
|
+
.nullable()
|
|
123
|
+
})
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const debugRunGet = {
|
|
127
|
+
command: 'debug.runGet' as const,
|
|
128
|
+
input: z.object({ runId: z.number().int().positive() }),
|
|
129
|
+
output: debugRunSchema
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/** Les derniers essais de ce serveur, du plus récent au plus ancien. */
|
|
133
|
+
export const debugRunList = {
|
|
134
|
+
command: 'debug.runList' as const,
|
|
135
|
+
input: z.object({ kind: debugRunKindSchema, limit: z.number().int().min(1).max(20) }),
|
|
136
|
+
output: z.object({ runs: z.array(debugRunSchema) })
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
/** Arrête l'essai en cours ; son ménage a lieu quand même. */
|
|
140
|
+
export const debugRunAbort = {
|
|
141
|
+
command: 'debug.runAbort' as const,
|
|
142
|
+
input: z.object({ runId: z.number().int().positive() }),
|
|
143
|
+
output: z.object({ runId: z.number().int().positive() })
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export const debugE2eScenarioSchema = z.object({
|
|
147
|
+
id: z.string(),
|
|
148
|
+
label: z.string(),
|
|
149
|
+
sourceLabel: z.string(),
|
|
150
|
+
/** Pourquoi il ne peut pas tourner ici maintenant ; `null` s'il le peut. */
|
|
151
|
+
skip: z.string().nullable()
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
export type DebugE2eScenario = z.infer<typeof debugE2eScenarioSchema>;
|
|
155
|
+
|
|
156
|
+
export const debugE2eCatalog = {
|
|
157
|
+
command: 'debug.e2eCatalog' as const,
|
|
158
|
+
input: z.object({}),
|
|
159
|
+
output: z.object({
|
|
160
|
+
scenarios: z.array(debugE2eScenarioSchema),
|
|
161
|
+
/** Comptes de test présents en base en dehors de tout essai : ce qu'un essai interrompu a laissé. */
|
|
162
|
+
residue: z.number().int().nonnegative(),
|
|
163
|
+
/** Pourquoi aucun essai ne peut partir (site en maintenance), ou `null`. */
|
|
164
|
+
blocked: z.string().nullable()
|
|
165
|
+
})
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const debugE2eStart = {
|
|
169
|
+
command: 'debug.e2eStart' as const,
|
|
170
|
+
input: z.object({ scenarios: z.array(z.string().min(1).max(80)).min(1).max(50) }),
|
|
171
|
+
output: z.object({ runId: z.number().int().positive() })
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/** Supprime ce que des essais interrompus ont laissé. */
|
|
175
|
+
export const debugE2eSweep = {
|
|
176
|
+
command: 'debug.e2eSweep' as const,
|
|
177
|
+
input: z.object({}),
|
|
178
|
+
output: z.object({ accounts: z.number().int().nonnegative() })
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export const debugProbeSchema = z.object({
|
|
182
|
+
id: z.string(),
|
|
183
|
+
label: z.string(),
|
|
184
|
+
description: z.string(),
|
|
185
|
+
/** Mesurée par le navigateur, puis transmise avec la demande. */
|
|
186
|
+
clientSide: z.boolean()
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
export type DebugProbe = z.infer<typeof debugProbeSchema>;
|
|
190
|
+
|
|
191
|
+
export const debugBenchCatalog = {
|
|
192
|
+
command: 'debug.benchCatalog' as const,
|
|
193
|
+
input: z.object({}),
|
|
194
|
+
output: z.object({ probes: z.array(debugProbeSchema) })
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
const clientSamplesSchema = z.array(z.number().nonnegative().max(60_000)).max(50);
|
|
198
|
+
|
|
199
|
+
export const debugBenchStart = {
|
|
200
|
+
command: 'debug.benchStart' as const,
|
|
201
|
+
input: z.object({
|
|
202
|
+
profile: debugBenchProfileSchema,
|
|
203
|
+
/** Ce que le navigateur a mesuré juste avant, en millisecondes. */
|
|
204
|
+
client: z.object({ wsRttMs: clientSamplesSchema, httpRttMs: clientSamplesSchema })
|
|
205
|
+
}),
|
|
206
|
+
output: z.object({ runId: z.number().int().positive() })
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
/** L'aller-retour le plus court possible : ce que le navigateur chronomètre. */
|
|
210
|
+
export const debugPing = {
|
|
211
|
+
command: 'debug.ping' as const,
|
|
212
|
+
input: z.object({}),
|
|
213
|
+
output: z.object({ at: z.number().int().nonnegative() })
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
export const debugMailSenderKindSchema = z.enum(['server', 'workspace']);
|
|
217
|
+
|
|
218
|
+
export const debugMailSampleSchema = z.object({
|
|
219
|
+
/** `<source>.<clé>` : `core.signupVerification`, `x-billing.renewal`. */
|
|
220
|
+
key: z.string(),
|
|
221
|
+
label: z.string(),
|
|
222
|
+
sourceLabel: z.string(),
|
|
223
|
+
sender: debugMailSenderKindSchema
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
export const debugWorkspaceSenderSchema = z.object({
|
|
227
|
+
workspaceId: z.number().int().positive(),
|
|
228
|
+
workspaceName: z.string(),
|
|
229
|
+
accountId: z.number().int().positive(),
|
|
230
|
+
label: z.string(),
|
|
231
|
+
address: z.string()
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
export type DebugMailSample = z.infer<typeof debugMailSampleSchema>;
|
|
235
|
+
export type DebugWorkspaceSender = z.infer<typeof debugWorkspaceSenderSchema>;
|
|
236
|
+
|
|
237
|
+
export const debugMailCatalog = {
|
|
238
|
+
command: 'debug.mailCatalog' as const,
|
|
239
|
+
input: z.object({}),
|
|
240
|
+
output: z.object({
|
|
241
|
+
samples: z.array(debugMailSampleSchema),
|
|
242
|
+
/** L'expéditeur du serveur (`SMTP_*`) : celui de l'inscription. */
|
|
243
|
+
server: z.object({ configured: z.boolean(), from: z.string().nullable() }),
|
|
244
|
+
/** Les boîtes prêtes à envoyer des espaces dont l'administrateur est propriétaire. */
|
|
245
|
+
senders: z.array(debugWorkspaceSenderSchema)
|
|
246
|
+
})
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
export const debugMailPreviewSchema = z.object({
|
|
250
|
+
subject: z.string(),
|
|
251
|
+
text: z.string(),
|
|
252
|
+
html: z.string().nullable(),
|
|
253
|
+
attachments: z.array(
|
|
254
|
+
z.object({
|
|
255
|
+
filename: z.string(),
|
|
256
|
+
contentType: z.string(),
|
|
257
|
+
size: z.number().int().nonnegative()
|
|
258
|
+
})
|
|
259
|
+
)
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
export type DebugMailPreview = z.infer<typeof debugMailPreviewSchema>;
|
|
263
|
+
|
|
264
|
+
export const debugMailPreview = {
|
|
265
|
+
command: 'debug.mailPreview' as const,
|
|
266
|
+
input: z.object({ key: z.string().min(1).max(120) }),
|
|
267
|
+
output: debugMailPreviewSchema
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export const debugMailSend = {
|
|
271
|
+
command: 'debug.mailSend' as const,
|
|
272
|
+
input: z.object({
|
|
273
|
+
key: z.string().min(1).max(120),
|
|
274
|
+
to: z.string().trim().toLowerCase().email().max(254),
|
|
275
|
+
sender: z.discriminatedUnion('kind', [
|
|
276
|
+
z.object({ kind: z.literal('server') }),
|
|
277
|
+
z.object({
|
|
278
|
+
kind: z.literal('workspace'),
|
|
279
|
+
workspaceId: z.number().int().positive(),
|
|
280
|
+
accountId: z.number().int().positive()
|
|
281
|
+
})
|
|
282
|
+
])
|
|
283
|
+
}),
|
|
284
|
+
output: z.object({
|
|
285
|
+
sentTo: z.string(),
|
|
286
|
+
/** Une adresse d'essai : le serveur a retenu le mail au lieu de l'envoyer. */
|
|
287
|
+
captured: z.boolean()
|
|
288
|
+
})
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
export const debugTrackingSchema = z.object({
|
|
292
|
+
/** L'origine de ce serveur : un réglage ne vaut que pour la sienne. */
|
|
293
|
+
origin: z.string(),
|
|
294
|
+
audienceInstalled: z.boolean(),
|
|
295
|
+
config: z
|
|
296
|
+
.object({
|
|
297
|
+
siteId: z.number().int().positive(),
|
|
298
|
+
/** `null` quand le site a disparu d'Audience. */
|
|
299
|
+
siteName: z.string().nullable(),
|
|
300
|
+
workspaceId: z.number().int().positive(),
|
|
301
|
+
/** Les derniers caractères de la clé : elle ne quitte jamais le serveur. */
|
|
302
|
+
keyHint: z.string(),
|
|
303
|
+
enabled: z.boolean(),
|
|
304
|
+
excludeAdmins: z.boolean(),
|
|
305
|
+
updated: z.number().int().nonnegative(),
|
|
306
|
+
updatedBy: authorSchema.nullable()
|
|
307
|
+
})
|
|
308
|
+
.nullable(),
|
|
309
|
+
/** Les réglages des autres serveurs qui partagent cette base, en lecture seule. */
|
|
310
|
+
others: z.array(z.object({ origin: z.string(), enabled: z.boolean() })),
|
|
311
|
+
/** Depuis le démarrage de ce serveur. */
|
|
312
|
+
counters: z.object({
|
|
313
|
+
sent: z.number().int().nonnegative(),
|
|
314
|
+
excluded: z.number().int().nonnegative()
|
|
315
|
+
})
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
export type DebugTracking = z.infer<typeof debugTrackingSchema>;
|
|
319
|
+
|
|
320
|
+
export const debugTrackingGet = {
|
|
321
|
+
command: 'debug.trackingGet' as const,
|
|
322
|
+
input: z.object({}),
|
|
323
|
+
output: debugTrackingSchema
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
/** Crée dans l'espace personnel de l'administrateur un site Audience réglé pour ce serveur, et s'y branche. */
|
|
327
|
+
export const debugTrackingCreate = {
|
|
328
|
+
command: 'debug.trackingCreate' as const,
|
|
329
|
+
input: z.object({}),
|
|
330
|
+
output: debugTrackingSchema
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
/** Se branche sur un site existant, par sa clé. */
|
|
334
|
+
export const debugTrackingUse = {
|
|
335
|
+
command: 'debug.trackingUse' as const,
|
|
336
|
+
input: z.object({ key: z.string().trim().min(8).max(64) }),
|
|
337
|
+
output: debugTrackingSchema
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
export const debugTrackingSet = {
|
|
341
|
+
command: 'debug.trackingSet' as const,
|
|
342
|
+
input: z.object({ enabled: z.boolean(), excludeAdmins: z.boolean() }),
|
|
343
|
+
output: debugTrackingSchema
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/** Débranche ce serveur ; le site et ses mesures restent dans Audience. */
|
|
347
|
+
export const debugTrackingClear = {
|
|
348
|
+
command: 'debug.trackingClear' as const,
|
|
349
|
+
input: z.object({}),
|
|
350
|
+
output: debugTrackingSchema
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
export const debugCommands = [
|
|
354
|
+
debugOverview,
|
|
355
|
+
debugRunGet,
|
|
356
|
+
debugRunList,
|
|
357
|
+
debugRunAbort,
|
|
358
|
+
debugE2eCatalog,
|
|
359
|
+
debugE2eStart,
|
|
360
|
+
debugE2eSweep,
|
|
361
|
+
debugBenchCatalog,
|
|
362
|
+
debugBenchStart,
|
|
363
|
+
debugPing,
|
|
364
|
+
debugMailCatalog,
|
|
365
|
+
debugMailPreview,
|
|
366
|
+
debugMailSend,
|
|
367
|
+
debugTrackingGet,
|
|
368
|
+
debugTrackingCreate,
|
|
369
|
+
debugTrackingUse,
|
|
370
|
+
debugTrackingSet,
|
|
371
|
+
debugTrackingClear
|
|
372
|
+
] as const;
|
package/src/features/registry.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { secrecyCommands } from './secrecy';
|
|
|
13
13
|
import { twoFactorCommands } from './twoFactor';
|
|
14
14
|
import { userCommands } from './user';
|
|
15
15
|
import { adminCommands } from './admin';
|
|
16
|
+
import { debugCommands } from './debug';
|
|
16
17
|
import { workspaceCommands } from './workspace';
|
|
17
18
|
|
|
18
19
|
export interface FeatureCommandDescriptor<C extends string = string> {
|
|
@@ -25,6 +26,7 @@ export const featureCommands = [
|
|
|
25
26
|
...workspaceCommands,
|
|
26
27
|
...remoteCommands,
|
|
27
28
|
...adminCommands,
|
|
29
|
+
...debugCommands,
|
|
28
30
|
...userCommands,
|
|
29
31
|
...agentCommands,
|
|
30
32
|
...twoFactorCommands,
|
package/src/features/user.ts
CHANGED
|
@@ -110,6 +110,7 @@ export const accountPlanSchema = z.object({
|
|
|
110
110
|
id: z.string(),
|
|
111
111
|
label: z.string(),
|
|
112
112
|
limits: z.record(z.string(), z.number().int().nonnegative()),
|
|
113
|
+
priority: z.boolean(),
|
|
113
114
|
trialEndsAt: z.number().int().nonnegative().optional(),
|
|
114
115
|
changesAt: z.number().int().nonnegative().optional()
|
|
115
116
|
});
|
|
@@ -140,8 +141,53 @@ export const userDeleteAccount = {
|
|
|
140
141
|
output: z.object({ ok: z.literal(true) })
|
|
141
142
|
};
|
|
142
143
|
|
|
144
|
+
/** A part of the data export made of large files, for the dialog. */
|
|
145
|
+
export const userExportPartSchema = z.object({
|
|
146
|
+
/** `<featureId>.<filesKey>`: what `leaveOut` names. */
|
|
147
|
+
key: z.string(),
|
|
148
|
+
/** In French, as the dialog names it: « les fichiers CloudSync ». */
|
|
149
|
+
label: z.string(),
|
|
150
|
+
bytes: z.number().int().nonnegative(),
|
|
151
|
+
/** The holder may leave it out. */
|
|
152
|
+
optional: z.boolean()
|
|
153
|
+
});
|
|
154
|
+
export type UserExportPart = z.infer<typeof userExportPartSchema>;
|
|
155
|
+
|
|
156
|
+
/** What an export of the caller's data will carry, for the dialog. No password: sizes only. */
|
|
157
|
+
export const userExportPreview = {
|
|
158
|
+
command: 'user.exportPreview' as const,
|
|
159
|
+
input: z.object({}),
|
|
160
|
+
output: z.object({
|
|
161
|
+
parts: z.array(userExportPartSchema),
|
|
162
|
+
/** Shared workspaces the caller belongs to without owning them: listed in the archive, not exported. */
|
|
163
|
+
foreignWorkspaces: z.number().int().nonnegative()
|
|
164
|
+
})
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Checks the password and hands back a single-use link, valid five minutes, to
|
|
169
|
+
* the caller's data export: a zip the server writes while it is downloaded,
|
|
170
|
+
* never stored. Everything in it is in the clear, password-protected data
|
|
171
|
+
* included. `leaveOut` names optional parts (`userExportPreview`).
|
|
172
|
+
*/
|
|
173
|
+
export const userExportPrepare = {
|
|
174
|
+
command: 'user.exportPrepare' as const,
|
|
175
|
+
input: z.object({
|
|
176
|
+
password: z.string().min(1).max(512),
|
|
177
|
+
leaveOut: z.array(z.string().max(64)).max(16)
|
|
178
|
+
}),
|
|
179
|
+
output: z.object({
|
|
180
|
+
/** Relative to this instance's origin, fetched with its cookie. */
|
|
181
|
+
url: z.string(),
|
|
182
|
+
/** Milliseconds: the link is dead after this. */
|
|
183
|
+
expiresAt: z.number().int().nonnegative()
|
|
184
|
+
})
|
|
185
|
+
};
|
|
186
|
+
|
|
143
187
|
export const userCommands = [
|
|
144
188
|
userDeleteAccount,
|
|
189
|
+
userExportPreview,
|
|
190
|
+
userExportPrepare,
|
|
145
191
|
userPlan,
|
|
146
192
|
userSetAvatar,
|
|
147
193
|
userSetTheme,
|
package/src/http/device.ts
CHANGED
|
@@ -5,40 +5,58 @@ import { devicePlatformSchema, deviceSchema } from '../domain/device';
|
|
|
5
5
|
* Device linking & enrollment (HTTP, distinct from the user feature protocol).
|
|
6
6
|
*
|
|
7
7
|
* Flow:
|
|
8
|
-
* 1. A member holding `devices: write` issues a
|
|
9
|
-
*
|
|
10
|
-
* 2. The agent posts the code and its machine fingerprint to enroll.
|
|
8
|
+
* 1. A member holding `devices: write` issues a link code for the active
|
|
9
|
+
* workspace: a lifetime and a number of uses (several for a fleet).
|
|
10
|
+
* 2. The agent posts the code and its machine fingerprint to enroll. Every
|
|
11
|
+
* successful enrollment spends one use; the code is gone once expired or
|
|
12
|
+
* spent. Failures lock the caller's IP out for a while, and a code whose
|
|
13
|
+
* issuer no longer manages the workspace's devices is refused.
|
|
11
14
|
* 3. A fingerprint new to the workspace is enrolled `active`, once the plan
|
|
12
|
-
* allows one more device (checked before
|
|
13
|
-
* fingerprint takes over that device record
|
|
14
|
-
*
|
|
15
|
+
* allows one more device (checked before a use is spent). A known
|
|
16
|
+
* fingerprint takes over that device record, but only through a
|
|
17
|
+
* single-use code: a fresh token replaces the old one and the device
|
|
18
|
+
* waits, `pending`, for someone to approve it. A multi-use code refuses it
|
|
19
|
+
* (`conflict`), so two clones of one machine never steal each other's
|
|
20
|
+
* record in silence.
|
|
15
21
|
*/
|
|
16
22
|
|
|
17
|
-
/** Hard cap on a code lifetime (
|
|
18
|
-
export const LINK_CODE_TTL_MAX_SECONDS = 60 * 60;
|
|
23
|
+
/** Hard cap on a code lifetime (seven days). A link code is a key to the workspace. */
|
|
24
|
+
export const LINK_CODE_TTL_MAX_SECONDS = 7 * 24 * 60 * 60;
|
|
25
|
+
|
|
26
|
+
/** Hard cap on the uses of one code. */
|
|
27
|
+
export const LINK_CODE_MAX_USES = 1000;
|
|
19
28
|
|
|
20
29
|
/**
|
|
21
|
-
* Request a new link code. `ttlSeconds` omitted → server default lifetime
|
|
22
|
-
*
|
|
30
|
+
* Request a new link code. `ttlSeconds` omitted → server default lifetime;
|
|
31
|
+
* `maxUses` omitted → a single use.
|
|
23
32
|
*/
|
|
24
33
|
export const linkCodeRequestSchema = z.object({
|
|
25
|
-
ttlSeconds: z.number().int().positive().max(LINK_CODE_TTL_MAX_SECONDS).optional()
|
|
34
|
+
ttlSeconds: z.number().int().positive().max(LINK_CODE_TTL_MAX_SECONDS).optional(),
|
|
35
|
+
maxUses: z.number().int().min(1).max(LINK_CODE_MAX_USES).optional()
|
|
26
36
|
});
|
|
27
37
|
|
|
28
38
|
export type LinkCodeRequest = z.infer<typeof linkCodeRequestSchema>;
|
|
29
39
|
|
|
30
40
|
export const linkCodeResponseSchema = z.object({
|
|
31
|
-
/**
|
|
41
|
+
/** Human-typable code (e.g. shown in the UI, entered on the agent). */
|
|
32
42
|
code: z.string().min(6).max(32),
|
|
33
43
|
/** Unix seconds when the code expires. */
|
|
34
|
-
expiresAt: z.number().int().positive()
|
|
44
|
+
expiresAt: z.number().int().positive(),
|
|
45
|
+
/** Enrollments the code allows in total. */
|
|
46
|
+
maxUses: z.number().int().min(1),
|
|
47
|
+
/** Enrollments already made with it. */
|
|
48
|
+
uses: z.number().int().min(0)
|
|
35
49
|
});
|
|
36
50
|
|
|
37
51
|
export type LinkCodeResponse = z.infer<typeof linkCodeResponseSchema>;
|
|
38
52
|
|
|
39
|
-
/** The workspace's link codes still usable (
|
|
53
|
+
/** The workspace's link codes still usable (uses left, unexpired). */
|
|
40
54
|
export const linkCodesListResponseSchema = z.object({
|
|
41
|
-
codes: z.array(linkCodeResponseSchema)
|
|
55
|
+
codes: z.array(linkCodeResponseSchema),
|
|
56
|
+
/** The server origin an agent enrolls with: what an install command names. */
|
|
57
|
+
server: z.string().min(1),
|
|
58
|
+
/** Where the workspace owner stands against the plan's device limit; `null` = unlimited. */
|
|
59
|
+
quota: z.object({ used: z.number().int().min(0), limit: z.number().int().min(0) }).nullable()
|
|
42
60
|
});
|
|
43
61
|
|
|
44
62
|
export type LinkCodesListResponse = z.infer<typeof linkCodesListResponseSchema>;
|
package/src/http/status.ts
CHANGED
|
@@ -37,6 +37,12 @@ export const serverStatusSchema = z.object({
|
|
|
37
37
|
version: z.string(),
|
|
38
38
|
/** Does this server let another instance's page open a session (`FEDERATION_ORIGINS`)? */
|
|
39
39
|
federation: z.boolean(),
|
|
40
|
+
/**
|
|
41
|
+
* The public status page watching this server (`STATUS_PAGE_URL`), which
|
|
42
|
+
* stays reachable when the server is down; `null` when none is set.
|
|
43
|
+
* Defaulted so an older remote instance still parses.
|
|
44
|
+
*/
|
|
45
|
+
statusPageUrl: z.string().url().nullable().default(null),
|
|
40
46
|
tasks: z.array(bootTaskSchema)
|
|
41
47
|
});
|
|
42
48
|
|