@deveye/types 0.18.1 → 0.18.3
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/featureDomain.ts +46 -0
- package/src/domain/featureRegistry.ts +12 -0
- package/src/domain/feedback.ts +1 -1
- package/src/domain/home.ts +2 -1
- package/src/domain/live.ts +14 -9
- package/src/domain/user.ts +11 -0
- package/src/domain/workspaceRole.ts +8 -1
- package/src/features/domain.ts +40 -0
- package/src/features/registry.ts +2 -0
- package/src/features/user.ts +18 -2
- package/src/http/auth.ts +2 -6
- package/src/index.ts +18 -1
- package/src/sdk/client-ambient.d.ts +18 -0
- package/src/sdk/client.ts +45 -12
- package/src/sdk/domains.test.ts +30 -0
- package/src/sdk/domains.ts +29 -0
- package/src/sdk/manifest.test.ts +33 -0
- package/src/sdk/manifest.ts +37 -3
- package/src/sdk/move.test.ts +7 -6
- package/src/sdk/providers.ts +62 -30
- package/src/sdk/server.ts +115 -7
- package/src/sdk/testing.test.ts +33 -1
- package/src/sdk/testing.ts +101 -0
package/package.json
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* A domain name a feature serves under, declared in the feature's settings
|
|
5
|
+
* and verified in two stages: ownership (a TXT record DevEye checks itself),
|
|
6
|
+
* then service (the owning feature's own probe).
|
|
7
|
+
*
|
|
8
|
+
* Host and token travel in the clear: both are published in the DNS.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export const DNS_RECORD_TYPES = ['A', 'AAAA', 'CNAME', 'MX', 'TXT', 'SRV'] as const;
|
|
12
|
+
|
|
13
|
+
export const dnsRecordSchema = z.object({
|
|
14
|
+
type: z.enum(DNS_RECORD_TYPES),
|
|
15
|
+
/** Fully qualified, without the trailing dot. */
|
|
16
|
+
name: z.string().min(1).max(255),
|
|
17
|
+
value: z.string().min(1).max(4096),
|
|
18
|
+
/** MX and SRV only. */
|
|
19
|
+
priority: z.number().int().nonnegative().optional()
|
|
20
|
+
});
|
|
21
|
+
export type DnsRecord = z.infer<typeof dnsRecordSchema>;
|
|
22
|
+
|
|
23
|
+
/** `pending` until the first check has run. */
|
|
24
|
+
export const domainStateSchema = z.enum(['pending', 'ok', 'failed']);
|
|
25
|
+
export type DomainState = z.infer<typeof domainStateSchema>;
|
|
26
|
+
|
|
27
|
+
export const FEATURE_DOMAIN_HOST_MAX = 253;
|
|
28
|
+
|
|
29
|
+
export const featureDomainSchema = z.object({
|
|
30
|
+
id: z.number().int().positive(),
|
|
31
|
+
host: z.string().min(1).max(FEATURE_DOMAIN_HOST_MAX),
|
|
32
|
+
/** The TXT record that proves ownership. */
|
|
33
|
+
ownership: dnsRecordSchema,
|
|
34
|
+
/** What the owning feature asks to publish on top of it. */
|
|
35
|
+
records: z.array(dnsRecordSchema),
|
|
36
|
+
dnsState: domainStateSchema,
|
|
37
|
+
dnsError: z.string(),
|
|
38
|
+
probeState: domainStateSchema,
|
|
39
|
+
probeError: z.string(),
|
|
40
|
+
/** Unix seconds. Null until both stages have passed once. */
|
|
41
|
+
verifiedAt: z.number().int().nullable(),
|
|
42
|
+
checkedAt: z.number().int().nullable(),
|
|
43
|
+
/** How many of the feature's items designate this domain. */
|
|
44
|
+
useCount: z.number().int().nonnegative()
|
|
45
|
+
});
|
|
46
|
+
export type FeatureDomain = z.infer<typeof featureDomainSchema>;
|
|
@@ -270,6 +270,18 @@ export const FEATURE_REGISTRY: readonly (FeatureDescriptor & { id: WorkspaceFeat
|
|
|
270
270
|
sources: {
|
|
271
271
|
hint: 'La clé d’API du NVD, facultative : sans elle le catalogue se remplit quand même, elle ne fait que relever le quota de requêtes.'
|
|
272
272
|
}
|
|
273
|
+
},
|
|
274
|
+
{
|
|
275
|
+
id: 'mailserver',
|
|
276
|
+
label: 'Serveur mail',
|
|
277
|
+
description:
|
|
278
|
+
'Lecture : les adresses hébergées et leur activité. Écriture : créer une adresse, régler son quota, déclarer un domaine.',
|
|
279
|
+
icon: 'at',
|
|
280
|
+
notifies: false,
|
|
281
|
+
hasItems: true,
|
|
282
|
+
itemNoun: 'adresse',
|
|
283
|
+
itemNounGender: 'f',
|
|
284
|
+
shareTier: 'open'
|
|
273
285
|
}
|
|
274
286
|
];
|
|
275
287
|
|
package/src/domain/feedback.ts
CHANGED
|
@@ -60,7 +60,7 @@ export type FeedbackErrorTrace = z.infer<typeof feedbackErrorTraceSchema>;
|
|
|
60
60
|
/** A view the user opened, in order: the shortest path to a reproduction. */
|
|
61
61
|
export const feedbackViewTraceSchema = z.object({
|
|
62
62
|
ago: z.number().int().nonnegative(),
|
|
63
|
-
/** View id (`logs`, `x-audit`, `
|
|
63
|
+
/** View id (`logs`, `x-audit`, `devices`), or `home` when it closed. */
|
|
64
64
|
view: z.string().max(64)
|
|
65
65
|
});
|
|
66
66
|
export type FeedbackViewTrace = z.infer<typeof feedbackViewTraceSchema>;
|
package/src/domain/home.ts
CHANGED
package/src/domain/live.ts
CHANGED
|
@@ -21,8 +21,8 @@ import {
|
|
|
21
21
|
*
|
|
22
22
|
* Le `kind` identifie le **niveau** (`view`, `account`, `folder`…), la valeur
|
|
23
23
|
* identifie le nœud à ce niveau. La valeur peut elle-même contenir des
|
|
24
|
-
* deux-points
|
|
25
|
-
* au premier deux-points, jamais avec un `split` complet.**
|
|
24
|
+
* deux-points : la coquille de réglages d'un élément est `settings:item:devices`,
|
|
25
|
+
* donc **on découpe au premier deux-points, jamais avec un `split` complet.**
|
|
26
26
|
*/
|
|
27
27
|
export const livePathSegmentSchema = z
|
|
28
28
|
.string()
|
|
@@ -142,7 +142,13 @@ export const nativeLiveTopicSchema = z.enum([
|
|
|
142
142
|
* quelle fonctionnalité, et un canal change pour toutes à la fois alors que
|
|
143
143
|
* `mutates` est déclaré par commande.
|
|
144
144
|
*/
|
|
145
|
-
'notify'
|
|
145
|
+
'notify',
|
|
146
|
+
/**
|
|
147
|
+
* Les domaines déclarés par une fonctionnalité de l'espace, et leur état de
|
|
148
|
+
* vérification. À part pour la même raison que `notify` : ils se relisent
|
|
149
|
+
* depuis les réglages de n'importe quelle fonctionnalité qui en gère.
|
|
150
|
+
*/
|
|
151
|
+
'domain'
|
|
146
152
|
]);
|
|
147
153
|
export type NativeLiveTopic = z.infer<typeof nativeLiveTopicSchema>;
|
|
148
154
|
|
|
@@ -193,6 +199,7 @@ export const TOPIC_FEATURE: Record<NativeLiveTopic, WorkspaceFeatureId | null> =
|
|
|
193
199
|
audience: 'audience',
|
|
194
200
|
osint: 'osint',
|
|
195
201
|
cve: 'cve',
|
|
202
|
+
mailserver: 'mailserver',
|
|
196
203
|
workspace: null,
|
|
197
204
|
home: null,
|
|
198
205
|
account: null,
|
|
@@ -201,7 +208,10 @@ export const TOPIC_FEATURE: Record<NativeLiveTopic, WorkspaceFeatureId | null> =
|
|
|
201
208
|
admin: null,
|
|
202
209
|
// Aucun droit de feature à vérifier : la relecture déclenchée est gardée
|
|
203
210
|
// côté commande. Même nature que `workspace`.
|
|
204
|
-
notify: null
|
|
211
|
+
notify: null,
|
|
212
|
+
// Même régime : la trame ne porte aucune donnée, et `domain.list` vérifie
|
|
213
|
+
// le droit sur la fonctionnalité visée.
|
|
214
|
+
domain: null
|
|
205
215
|
};
|
|
206
216
|
|
|
207
217
|
/**
|
|
@@ -213,8 +223,6 @@ export const TOPIC_FEATURE: Record<NativeLiveTopic, WorkspaceFeatureId | null> =
|
|
|
213
223
|
*/
|
|
214
224
|
export type LivePathGate = FeatureId | 'public' | 'private';
|
|
215
225
|
|
|
216
|
-
const DEVICE_VIEW_PREFIX = 'device:';
|
|
217
|
-
|
|
218
226
|
export function livePathGate(rootSegment: string | undefined): LivePathGate {
|
|
219
227
|
if (!rootSegment) return 'public';
|
|
220
228
|
if (segmentKind(rootSegment) !== 'view') return 'private';
|
|
@@ -224,8 +232,5 @@ export function livePathGate(rootSegment: string | undefined): LivePathGate {
|
|
|
224
232
|
// Une vue de module externe est gardée par le droit du module, comme une
|
|
225
233
|
// feature native : même règle, reconnue au préfixe plutôt qu'à l'enum.
|
|
226
234
|
if (isExternalFeatureId(viewId)) return viewId;
|
|
227
|
-
// La page Appareils et chaque vue d'appareil relèvent du même droit — miroir
|
|
228
|
-
// exact de `featureBehind` côté client.
|
|
229
|
-
if (viewId === 'clients' || viewId.startsWith(DEVICE_VIEW_PREFIX)) return 'devices';
|
|
230
235
|
return 'private';
|
|
231
236
|
}
|
package/src/domain/user.ts
CHANGED
|
@@ -41,6 +41,17 @@ export function defaultUserColor(userId: number): UserColor {
|
|
|
41
41
|
return USER_COLORS[Math.abs(userId) % USER_COLORS.length];
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/**
|
|
45
|
+
* The account name: what one logs in with, and what the other members see.
|
|
46
|
+
* Unique across the site (`users.username` carries a UNIQUE index), and narrow
|
|
47
|
+
* enough to travel through a URL, a log line or a shell without escaping.
|
|
48
|
+
*/
|
|
49
|
+
export const usernameSchema = z
|
|
50
|
+
.string()
|
|
51
|
+
.min(3)
|
|
52
|
+
.max(64)
|
|
53
|
+
.regex(/^[a-zA-Z0-9_.-]+$/, 'username may only contain letters, digits, _ . -');
|
|
54
|
+
|
|
44
55
|
export const minimalUserSchema = z.object({
|
|
45
56
|
id: z.number().int().nonnegative(),
|
|
46
57
|
email: z.string().email(),
|
|
@@ -88,7 +88,14 @@ export const workspaceFeatureIdSchema = z.enum([
|
|
|
88
88
|
* Veille CVE. `read` = lire le fil et chercher dans le catalogue, `write` =
|
|
89
89
|
* épingler une CVE pour tout l'espace et poser la clé d'API du NVD.
|
|
90
90
|
*/
|
|
91
|
-
'cve'
|
|
91
|
+
'cve',
|
|
92
|
+
/**
|
|
93
|
+
* Serveur mail. `read` = voir les adresses hébergées et leur activité,
|
|
94
|
+
* `write` = créer une adresse, régler son quota, déclarer un domaine.
|
|
95
|
+
* Réinitialiser un mot de passe et purger la file d'envoi sont des
|
|
96
|
+
* permissions propres du module.
|
|
97
|
+
*/
|
|
98
|
+
'mailserver'
|
|
92
99
|
]);
|
|
93
100
|
|
|
94
101
|
export type WorkspaceFeatureId = z.infer<typeof workspaceFeatureIdSchema>;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { FEATURE_DOMAIN_HOST_MAX, featureDomainSchema } from '../domain/featureDomain';
|
|
3
|
+
import { featureIdSchema } from '../domain/workspaceRole';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The domains of one feature in the active workspace. Cross-cutting: the
|
|
7
|
+
* feature is an input, and each command authorizes against it (read to list,
|
|
8
|
+
* write for the rest). A feature whose manifest declares no `domains` is
|
|
9
|
+
* refused.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
export const domainList = {
|
|
13
|
+
command: 'domain.list' as const,
|
|
14
|
+
input: z.object({ feature: featureIdSchema }),
|
|
15
|
+
output: z.object({ domains: z.array(featureDomainSchema) })
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const domainAdd = {
|
|
19
|
+
command: 'domain.add' as const,
|
|
20
|
+
input: z.object({
|
|
21
|
+
feature: featureIdSchema,
|
|
22
|
+
host: z.string().min(1).max(FEATURE_DOMAIN_HOST_MAX)
|
|
23
|
+
}),
|
|
24
|
+
output: z.object({ domain: featureDomainSchema })
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/** Runs both stages now instead of waiting for the background pass. */
|
|
28
|
+
export const domainVerify = {
|
|
29
|
+
command: 'domain.verify' as const,
|
|
30
|
+
input: z.object({ feature: featureIdSchema, id: z.number().int().positive() }),
|
|
31
|
+
output: z.object({ domain: featureDomainSchema })
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const domainRemove = {
|
|
35
|
+
command: 'domain.remove' as const,
|
|
36
|
+
input: z.object({ feature: featureIdSchema, id: z.number().int().positive() }),
|
|
37
|
+
output: z.object({ ok: z.literal(true) })
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const domainCommands = [domainList, domainAdd, domainVerify, domainRemove] as const;
|
package/src/features/registry.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { agentCommands } from './agent';
|
|
3
|
+
import { domainCommands } from './domain';
|
|
3
4
|
import { feedbackCommands } from './feedback';
|
|
4
5
|
import { homeCommands } from './home';
|
|
5
6
|
import { liveCommands } from './live';
|
|
@@ -30,6 +31,7 @@ export const featureCommands = [
|
|
|
30
31
|
...homeCommands,
|
|
31
32
|
...notifyCommands,
|
|
32
33
|
...sharingCommands,
|
|
34
|
+
...domainCommands,
|
|
33
35
|
...liveCommands
|
|
34
36
|
] as const;
|
|
35
37
|
|
package/src/features/user.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { userColorSchema, userSettingFlagSchema } from '../domain/user';
|
|
2
|
+
import { usernameSchema, userColorSchema, userSettingFlagSchema } from '../domain/user';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Upper bound on the avatar data URL length (characters ≈ bytes for base64
|
|
@@ -83,4 +83,20 @@ export const userSetSetting = {
|
|
|
83
83
|
output: z.object({ settings: z.array(z.string()) })
|
|
84
84
|
};
|
|
85
85
|
|
|
86
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Renames the account. Same rule as registration (`usernameSchema`), and the
|
|
88
|
+
* same uniqueness: the server rejects a name another account already holds.
|
|
89
|
+
*/
|
|
90
|
+
export const userSetUsername = {
|
|
91
|
+
command: 'user.setUsername' as const,
|
|
92
|
+
input: z.object({ username: usernameSchema }),
|
|
93
|
+
output: z.object({ username: usernameSchema })
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
export const userCommands = [
|
|
97
|
+
userSetAvatar,
|
|
98
|
+
userSetTheme,
|
|
99
|
+
userSetColor,
|
|
100
|
+
userSetSetting,
|
|
101
|
+
userSetUsername
|
|
102
|
+
] as const;
|
package/src/http/auth.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { homeLayoutSchema } from '../domain/home';
|
|
3
|
-
import { userSchema } from '../domain/user';
|
|
3
|
+
import { usernameSchema, userSchema } from '../domain/user';
|
|
4
4
|
import { workspaceSchema } from '../domain/workspace';
|
|
5
5
|
import { workspacePermissionsSchema } from '../domain/workspaceRole';
|
|
6
6
|
import { themeStateSchema } from '../features/user';
|
|
@@ -41,11 +41,7 @@ export type LoginRequest = z.infer<typeof loginRequestSchema>;
|
|
|
41
41
|
/** L'inscription exige un jeton d'invitation émis par un administrateur. */
|
|
42
42
|
export const registerRequestSchema = z.object({
|
|
43
43
|
inviteToken: z.string().min(1),
|
|
44
|
-
username:
|
|
45
|
-
.string()
|
|
46
|
-
.min(3)
|
|
47
|
-
.max(64)
|
|
48
|
-
.regex(/^[a-zA-Z0-9_.-]+$/, 'username may only contain letters, digits, _ . -'),
|
|
44
|
+
username: usernameSchema,
|
|
49
45
|
email: z.string().email().max(320),
|
|
50
46
|
password: z.string().min(8).max(512)
|
|
51
47
|
});
|
package/src/index.ts
CHANGED
|
@@ -488,6 +488,7 @@ export {
|
|
|
488
488
|
minimalUserSchema,
|
|
489
489
|
USER_COLORS,
|
|
490
490
|
userColorSchema,
|
|
491
|
+
usernameSchema,
|
|
491
492
|
userSchema,
|
|
492
493
|
userSecuritySchema,
|
|
493
494
|
userSettingFlagSchema,
|
|
@@ -681,6 +682,21 @@ export {
|
|
|
681
682
|
sharingCommands
|
|
682
683
|
} from './features/sharing';
|
|
683
684
|
export { SHAREABLE_FEATURES, SHARE_WIRED_FEATURES } from './domain/featureRegistry';
|
|
685
|
+
export {
|
|
686
|
+
DNS_RECORD_TYPES,
|
|
687
|
+
FEATURE_DOMAIN_HOST_MAX,
|
|
688
|
+
dnsRecordSchema,
|
|
689
|
+
domainStateSchema,
|
|
690
|
+
featureDomainSchema
|
|
691
|
+
} from './domain/featureDomain';
|
|
692
|
+
export type { DnsRecord, DomainState, FeatureDomain } from './domain/featureDomain';
|
|
693
|
+
export {
|
|
694
|
+
domainAdd,
|
|
695
|
+
domainCommands,
|
|
696
|
+
domainList,
|
|
697
|
+
domainRemove,
|
|
698
|
+
domainVerify
|
|
699
|
+
} from './features/domain';
|
|
684
700
|
export {
|
|
685
701
|
metricSeriesPointSchema,
|
|
686
702
|
metricSnapshotSchema,
|
|
@@ -754,7 +770,8 @@ export {
|
|
|
754
770
|
userSetAvatar,
|
|
755
771
|
userSetColor,
|
|
756
772
|
userSetSetting,
|
|
757
|
-
userSetTheme
|
|
773
|
+
userSetTheme,
|
|
774
|
+
userSetUsername
|
|
758
775
|
} from './features/user';
|
|
759
776
|
export type { ThemeStateDTO } from './features/user';
|
|
760
777
|
export {
|
|
@@ -25,6 +25,7 @@ declare module 'deveye-sdk-client' {
|
|
|
25
25
|
} from 'react';
|
|
26
26
|
import type {
|
|
27
27
|
FeatureAccess,
|
|
28
|
+
FeatureDomain,
|
|
28
29
|
FeatureId,
|
|
29
30
|
MinimalUser,
|
|
30
31
|
User,
|
|
@@ -185,6 +186,12 @@ declare module 'deveye-sdk-client' {
|
|
|
185
186
|
* nothing else announces the item. The shell never declares the level.
|
|
186
187
|
*/
|
|
187
188
|
onOpenChange?: (open: boolean) => void;
|
|
189
|
+
/**
|
|
190
|
+
* The item was deleted or moved to another workspace from inside the
|
|
191
|
+
* shell, which has closed: the view that mounted the button leaves the
|
|
192
|
+
* item (the same handler as its back button).
|
|
193
|
+
*/
|
|
194
|
+
onGone?: () => void;
|
|
188
195
|
}>;
|
|
189
196
|
/**
|
|
190
197
|
* One provider of a feature and the key it wants. The row carries the state
|
|
@@ -458,6 +465,17 @@ declare module 'deveye-sdk-client' {
|
|
|
458
465
|
export function useFeatureLifecycle(hooks: { onUnmount?: () => void }): void;
|
|
459
466
|
/** The members of the active workspace, as the session lists them (empty before it answers). */
|
|
460
467
|
export function useWorkspaceMembers(): readonly MinimalUser[];
|
|
468
|
+
/**
|
|
469
|
+
* The domains of a feature whose manifest declares `domains`, in the
|
|
470
|
+
* active workspace, kept live. For a form that designates one (filter on
|
|
471
|
+
* `verifiedAt !== null`); declaring and verifying happen in the Domains
|
|
472
|
+
* tab, opened with `<FeatureSettingsButton initialSection='domains' />`.
|
|
473
|
+
*/
|
|
474
|
+
export function useDomains(feature: FeatureId): {
|
|
475
|
+
domains: readonly FeatureDomain[];
|
|
476
|
+
loading: boolean;
|
|
477
|
+
error: string | null;
|
|
478
|
+
};
|
|
461
479
|
/**
|
|
462
480
|
* A member's identity dot: their avatar, or the default picture until they
|
|
463
481
|
* upload one. `user` may be undefined: a deleted account must not break a
|
package/src/sdk/client.ts
CHANGED
|
@@ -23,12 +23,18 @@ export interface SettingsPanelProps {
|
|
|
23
23
|
/** Caller has `write` on the feature. Render read-only when false. */
|
|
24
24
|
canWrite: boolean;
|
|
25
25
|
/**
|
|
26
|
-
* Closes the settings dialog. For a
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* Not a substitute for saving — every other change applies in place.
|
|
26
|
+
* Closes the settings dialog, nothing more. For a gesture best followed on
|
|
27
|
+
* the screen underneath (a full resync whose progress the item's view
|
|
28
|
+
* draws). Not a substitute for saving: every other change applies in place.
|
|
30
29
|
*/
|
|
31
30
|
close(): void;
|
|
31
|
+
/**
|
|
32
|
+
* The item being configured no longer exists here (deleted, moved to
|
|
33
|
+
* another workspace): the shell closes, then the view that opened it
|
|
34
|
+
* leaves the item. The scope it was opened on is gone, and the shell would
|
|
35
|
+
* otherwise fall back to the feature's own tabs under the item's name.
|
|
36
|
+
*/
|
|
37
|
+
gone(): void;
|
|
32
38
|
}
|
|
33
39
|
|
|
34
40
|
export interface FeatureViewProps {
|
|
@@ -101,6 +107,8 @@ export interface UptimeLinkedService {
|
|
|
101
107
|
name: string;
|
|
102
108
|
url: string;
|
|
103
109
|
enabled: boolean;
|
|
110
|
+
/** Projected here from another workspace. */
|
|
111
|
+
foreign?: boolean;
|
|
104
112
|
status: string;
|
|
105
113
|
lastCheckedAt: number | null;
|
|
106
114
|
ratio24h: number | null;
|
|
@@ -122,9 +130,8 @@ export type UptimeHistoryResolution = 'raw' | 'hour' | 'day';
|
|
|
122
130
|
|
|
123
131
|
/**
|
|
124
132
|
* What the Devices module offers the app's own screens (`DEVICES_CLIENT_PROVIDER`):
|
|
125
|
-
* the workspace's devices as a live store, the
|
|
126
|
-
*
|
|
127
|
-
* module the home places no device and the topbar counts none.
|
|
133
|
+
* the workspace's devices as a live store, and the compact tile of one of them.
|
|
134
|
+
* Without the module the home places no device and the topbar counts none.
|
|
128
135
|
*/
|
|
129
136
|
export interface DevicesClientProvider {
|
|
130
137
|
/** The active workspace's devices, refreshed by the `devices` live topic. */
|
|
@@ -132,7 +139,6 @@ export interface DevicesClientProvider {
|
|
|
132
139
|
refreshDevices(): void;
|
|
133
140
|
/** Forgets every loaded device (the app calls it when the session ends). */
|
|
134
141
|
resetDevices(): void;
|
|
135
|
-
DevicePanel: ComponentType<{ deviceId: string }>;
|
|
136
142
|
DeviceWidget: ComponentType<{ deviceId: string; hideStatus?: boolean }>;
|
|
137
143
|
}
|
|
138
144
|
|
|
@@ -177,10 +183,9 @@ export interface UptimeClientProvider {
|
|
|
177
183
|
}>;
|
|
178
184
|
/** The three-window availability ratios of a service. */
|
|
179
185
|
Ratios: ComponentType<{ service: UptimeLinkedService; compact?: boolean }>;
|
|
180
|
-
/** The feature's service form
|
|
186
|
+
/** The feature's service form, to declare a new service from a project. */
|
|
181
187
|
ServiceDialog: ComponentType<{
|
|
182
188
|
open: boolean;
|
|
183
|
-
service: UptimeLinkedService | null;
|
|
184
189
|
onClose: () => void;
|
|
185
190
|
onSaved: (service: UptimeLinkedService) => void;
|
|
186
191
|
}>;
|
|
@@ -194,6 +199,8 @@ export interface UptimeClientProvider {
|
|
|
194
199
|
export interface DatabaseLinkedCandidate {
|
|
195
200
|
id: number;
|
|
196
201
|
name: string;
|
|
202
|
+
/** Projected here from another workspace. */
|
|
203
|
+
foreign?: boolean;
|
|
197
204
|
/** The engine as the module labels it (« MySQL », « PostgreSQL »). */
|
|
198
205
|
engineLabel: string;
|
|
199
206
|
/** How many projects of the workspace already use it. */
|
|
@@ -231,6 +238,8 @@ export interface DatabaseClientProvider {
|
|
|
231
238
|
export interface DeployLinkedCandidate {
|
|
232
239
|
id: number;
|
|
233
240
|
name: string;
|
|
241
|
+
/** Projected here from another workspace. */
|
|
242
|
+
foreign?: boolean;
|
|
234
243
|
/** The instance host, as the module labels it (« dokploy.example.com »). */
|
|
235
244
|
host: string;
|
|
236
245
|
}
|
|
@@ -271,6 +280,8 @@ export interface GitLinkedCandidate {
|
|
|
271
280
|
id: number;
|
|
272
281
|
owner: string;
|
|
273
282
|
repo: string;
|
|
283
|
+
/** Projected here from another workspace. */
|
|
284
|
+
foreign?: boolean;
|
|
274
285
|
}
|
|
275
286
|
|
|
276
287
|
/**
|
|
@@ -300,6 +311,8 @@ export interface GitClientProvider {
|
|
|
300
311
|
export interface AudienceLinkedCandidate {
|
|
301
312
|
id: number;
|
|
302
313
|
name: string;
|
|
314
|
+
/** Projected here from another workspace. */
|
|
315
|
+
foreign?: boolean;
|
|
303
316
|
}
|
|
304
317
|
|
|
305
318
|
/**
|
|
@@ -330,13 +343,33 @@ export interface AudienceClientProvider {
|
|
|
330
343
|
* the ready senders (open tier, enabled) an email notification channel picks
|
|
331
344
|
* from, and the feature's own account dialog.
|
|
332
345
|
*/
|
|
346
|
+
/** What a caller already knows of the mailbox it sends to Mail's account form. */
|
|
347
|
+
export interface MailAccountPrefill {
|
|
348
|
+
displayName: string;
|
|
349
|
+
emailAddress: string;
|
|
350
|
+
imap: { host: string; port: number; username: string; password: string };
|
|
351
|
+
smtp: { host: string; port: number; username: string; password: string };
|
|
352
|
+
}
|
|
353
|
+
|
|
333
354
|
export interface MailClientProvider {
|
|
334
355
|
/** The workspace's ready senders, as the module lists them. */
|
|
335
356
|
listSenders(): Promise<readonly { id: number; label: string; address: string }[]>;
|
|
357
|
+
/**
|
|
358
|
+
* The account holding this address among those the caller can read, or
|
|
359
|
+
* null. A guarded account of a locked session does not show its address:
|
|
360
|
+
* it reads as absent.
|
|
361
|
+
*/
|
|
362
|
+
findByAddress(address: string): Promise<{ id: number } | null>;
|
|
336
363
|
/**
|
|
337
364
|
* The feature's account form (manual connection or OAuth consent), to
|
|
338
365
|
* declare a mailbox from the channel form. `onSaved` fires when a mailbox
|
|
339
|
-
* came out of it; the host re-lists to find which.
|
|
366
|
+
* came out of it; the host re-lists to find which. With `prefill`, the
|
|
367
|
+
* form opens on the manual connection, filled in and ready to save.
|
|
340
368
|
*/
|
|
341
|
-
AccountDialog: ComponentType<{
|
|
369
|
+
AccountDialog: ComponentType<{
|
|
370
|
+
open: boolean;
|
|
371
|
+
onClose: () => void;
|
|
372
|
+
onSaved: () => void;
|
|
373
|
+
prefill?: MailAccountPrefill;
|
|
374
|
+
}>;
|
|
342
375
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import assert from 'node:assert/strict';
|
|
2
|
+
import { test } from 'node:test';
|
|
3
|
+
|
|
4
|
+
import { DOMAIN_HOST_PATTERN, domainOwnershipRecord, normaliseDomainHost } from './domains';
|
|
5
|
+
|
|
6
|
+
test('normaliseDomainHost drops case, port and trailing dots', () => {
|
|
7
|
+
assert.equal(normaliseDomainHost(' Rdv.Example.COM:8443 '), 'rdv.example.com');
|
|
8
|
+
assert.equal(normaliseDomainHost('example.com..'), 'example.com');
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('DOMAIN_HOST_PATTERN wants at least two plain labels', () => {
|
|
12
|
+
assert.ok(DOMAIN_HOST_PATTERN.test('mail.example.com'));
|
|
13
|
+
assert.ok(DOMAIN_HOST_PATTERN.test('xn--bcher-kva.example'));
|
|
14
|
+
assert.ok(!DOMAIN_HOST_PATTERN.test('localhost'));
|
|
15
|
+
assert.ok(!DOMAIN_HOST_PATTERN.test('exa mple.com'));
|
|
16
|
+
assert.ok(!DOMAIN_HOST_PATTERN.test('https://example.com'));
|
|
17
|
+
assert.ok(!DOMAIN_HOST_PATTERN.test(`${'a'.repeat(64)}.com`));
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
test('the ownership record names the feature by its slug', () => {
|
|
21
|
+
assert.deepEqual(domainOwnershipRecord('x-rdv', 'example.com', 'abc'), {
|
|
22
|
+
type: 'TXT',
|
|
23
|
+
name: '_deveye.example.com',
|
|
24
|
+
value: 'deveye-rdv=abc'
|
|
25
|
+
});
|
|
26
|
+
assert.equal(
|
|
27
|
+
domainOwnershipRecord('mailserver', 'example.com', 'abc').value,
|
|
28
|
+
'deveye-mailserver=abc'
|
|
29
|
+
);
|
|
30
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Domain names a feature serves under: the pure half, shared by the server
|
|
3
|
+
* contract, the app and the test harness. No I/O here.
|
|
4
|
+
*/
|
|
5
|
+
import type { DnsRecord } from '../domain/featureDomain';
|
|
6
|
+
|
|
7
|
+
export type SdkDnsRecord = DnsRecord;
|
|
8
|
+
|
|
9
|
+
/** A bare host name: labels of letters, digits and hyphens, at least two. Punycode passes as is. */
|
|
10
|
+
export const DOMAIN_HOST_PATTERN = /^(?=.{1,253}$)[a-z0-9-]{1,63}(\.[a-z0-9-]{1,63})+$/;
|
|
11
|
+
|
|
12
|
+
/** Lowercase, port and trailing dots dropped. Accepts a raw `Host` header. */
|
|
13
|
+
export function normaliseDomainHost(raw: string): string {
|
|
14
|
+
return raw.trim().toLowerCase().split(':')[0].replace(/\.+$/, '');
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The ownership proof DevEye checks itself: `_deveye.<host>` holding
|
|
19
|
+
* `deveye-<slug>=<token>`, the slug being the feature id without its `x-`.
|
|
20
|
+
* Several features can prove the same host: each adds its own value.
|
|
21
|
+
*/
|
|
22
|
+
export function domainOwnershipRecord(
|
|
23
|
+
featureId: string,
|
|
24
|
+
host: string,
|
|
25
|
+
token: string
|
|
26
|
+
): SdkDnsRecord {
|
|
27
|
+
const slug = featureId.replace(/^x-/, '');
|
|
28
|
+
return { type: 'TXT', name: `_deveye.${host}`, value: `deveye-${slug}=${token}` };
|
|
29
|
+
}
|
package/src/sdk/manifest.test.ts
CHANGED
|
@@ -100,3 +100,36 @@ test('resolveExtras: the owner holds everything, a member what the grant says, u
|
|
|
100
100
|
assert.equal(owner.extraValue('reset'), '');
|
|
101
101
|
assert.equal(resolveExtras(undefined, true, { reset: true }).canExtra('reset'), false);
|
|
102
102
|
});
|
|
103
|
+
|
|
104
|
+
test('validateManifest ties the domains tab to the domains field', () => {
|
|
105
|
+
const domains = { hint: 'Your own names.', service: 'Point the name here.' };
|
|
106
|
+
assert.doesNotThrow(() =>
|
|
107
|
+
validateManifest({ ...base, domains, settings: { feature: ['domains'] } })
|
|
108
|
+
);
|
|
109
|
+
assert.throws(
|
|
110
|
+
() => validateManifest({ ...base, settings: { feature: ['domains'] } }),
|
|
111
|
+
/domains tab requires domains/
|
|
112
|
+
);
|
|
113
|
+
assert.throws(
|
|
114
|
+
() =>
|
|
115
|
+
validateManifest({
|
|
116
|
+
...base,
|
|
117
|
+
hasItems: true,
|
|
118
|
+
itemNoun: 'thing',
|
|
119
|
+
domains,
|
|
120
|
+
settings: { item: ['domains'] }
|
|
121
|
+
}),
|
|
122
|
+
/feature-scope/
|
|
123
|
+
);
|
|
124
|
+
assert.throws(
|
|
125
|
+
() => validateManifest({ ...base, domains: { ...domains, service: ' ' } }),
|
|
126
|
+
/empty service/
|
|
127
|
+
);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('validateManifest refuses a tab id it does not know', () => {
|
|
131
|
+
assert.throws(
|
|
132
|
+
() => validateManifest({ ...base, settings: { feature: ['nope' as 'general'] } }),
|
|
133
|
+
/unknown settings tab/
|
|
134
|
+
);
|
|
135
|
+
});
|
package/src/sdk/manifest.ts
CHANGED
|
@@ -111,8 +111,10 @@ export type NativeCapability =
|
|
|
111
111
|
|
|
112
112
|
/**
|
|
113
113
|
* Settings tabs the shell can render for you.
|
|
114
|
-
* - `'notifications'` and `'
|
|
115
|
-
* them from the manifest alone, you write no component.
|
|
114
|
+
* - `'notifications'`, `'permissions'` and `'domains'` are fully generic:
|
|
115
|
+
* DevEye renders them from the manifest alone, you write no component.
|
|
116
|
+
* `'domains'` (feature scope only) needs the manifest's `domains` and a
|
|
117
|
+
* `domains` entry on the server side.
|
|
116
118
|
* - `'general'`, `'sources'`, `'sync'` and `'encryption'` need a panel
|
|
117
119
|
* component, provided by your client entry (`settingsPanels`), keyed by
|
|
118
120
|
* the tab id. `'sync'` (item scope only) is the cadence and maintenance of
|
|
@@ -122,7 +124,7 @@ export type NativeCapability =
|
|
|
122
124
|
* places the tab, the module owns the choice.
|
|
123
125
|
*/
|
|
124
126
|
export type SettingsTab =
|
|
125
|
-
'general' | 'sources' | 'notifications' | 'permissions' | 'sync' | 'encryption';
|
|
127
|
+
'general' | 'sources' | 'domains' | 'notifications' | 'permissions' | 'sync' | 'encryption';
|
|
126
128
|
|
|
127
129
|
/** A custom settings tab. Needs a matching panel in `settingsPanels`. */
|
|
128
130
|
export interface CustomTabRef {
|
|
@@ -144,6 +146,7 @@ const CUSTOM_TAB_PATTERN = /^[a-z][a-z0-9]{1,23}$/;
|
|
|
144
146
|
const BUILTIN_TABS: readonly string[] = [
|
|
145
147
|
'general',
|
|
146
148
|
'sources',
|
|
149
|
+
'domains',
|
|
147
150
|
'notifications',
|
|
148
151
|
'permissions',
|
|
149
152
|
'sync',
|
|
@@ -151,6 +154,9 @@ const BUILTIN_TABS: readonly string[] = [
|
|
|
151
154
|
'sharing'
|
|
152
155
|
];
|
|
153
156
|
|
|
157
|
+
/** The built-in ids a manifest may list: `sharing` is the shell's alone. */
|
|
158
|
+
const DECLARABLE_TABS: readonly string[] = BUILTIN_TABS.filter((id) => id !== 'sharing');
|
|
159
|
+
|
|
154
160
|
/** See {@link FeatureManifest.alsoInvalidatedBy}. */
|
|
155
161
|
export interface CrossTopicInvalidation {
|
|
156
162
|
/** A NATIVE live topic that is not this feature's own. */
|
|
@@ -207,6 +213,22 @@ export interface FeatureManifest<Id extends FeatureId = FeatureId> {
|
|
|
207
213
|
itemNounGender?: 'm' | 'f';
|
|
208
214
|
/** Feature-scope reusable settings (API keys, destinations). Opens the Sources tab. */
|
|
209
215
|
sources?: { hint: string };
|
|
216
|
+
/**
|
|
217
|
+
* The feature serves something under domain names the workspace owns (a
|
|
218
|
+
* public page, a mailbox). Opens the Domains tab, which DevEye renders:
|
|
219
|
+
* declaring, the DNS records to publish, verification. Commits the server
|
|
220
|
+
* entry to `domains` (`FeatureDomainsEntry`).
|
|
221
|
+
*/
|
|
222
|
+
domains?: {
|
|
223
|
+
/** Lead sentence of the tab. */
|
|
224
|
+
hint: string;
|
|
225
|
+
/** The one sentence of the second step: how the domain gets wired to what you serve. */
|
|
226
|
+
service: string;
|
|
227
|
+
/** Placeholder of the host field. */
|
|
228
|
+
placeholder?: string;
|
|
229
|
+
/** Warning of the removal confirm when items designate the domain. */
|
|
230
|
+
removal?: string;
|
|
231
|
+
};
|
|
210
232
|
/**
|
|
211
233
|
* Whether an item can be projected into another workspace. Decided by
|
|
212
234
|
* encryption: only the open tier is readable by the server alone. Anything
|
|
@@ -392,6 +414,11 @@ export function validateManifest(m: FeatureManifest): void {
|
|
|
392
414
|
}
|
|
393
415
|
}
|
|
394
416
|
|
|
417
|
+
if (m.domains) {
|
|
418
|
+
if (!m.domains.hint.trim()) fail(m.id, 'domains: empty hint');
|
|
419
|
+
if (!m.domains.service.trim()) fail(m.id, 'domains: empty service');
|
|
420
|
+
}
|
|
421
|
+
|
|
395
422
|
for (const scope of ['feature', 'item'] as const) {
|
|
396
423
|
for (const tab of m.settings?.[scope] ?? []) {
|
|
397
424
|
if (typeof tab === 'string') {
|
|
@@ -402,9 +429,16 @@ export function validateManifest(m: FeatureManifest): void {
|
|
|
402
429
|
if (tab === 'sources' && scope === 'item') {
|
|
403
430
|
fail(m.id, 'sources is a feature-scope tab');
|
|
404
431
|
}
|
|
432
|
+
if (tab === 'domains' && !m.domains) fail(m.id, 'domains tab requires domains');
|
|
433
|
+
if (tab === 'domains' && scope === 'item') {
|
|
434
|
+
fail(m.id, 'domains is a feature-scope tab');
|
|
435
|
+
}
|
|
405
436
|
if (tab === 'encryption' && scope === 'feature') {
|
|
406
437
|
fail(m.id, 'encryption is an item-scope tab');
|
|
407
438
|
}
|
|
439
|
+
if (!DECLARABLE_TABS.includes(tab)) {
|
|
440
|
+
fail(m.id, `unknown settings tab « ${String(tab)} »`);
|
|
441
|
+
}
|
|
408
442
|
} else {
|
|
409
443
|
if (!CUSTOM_TAB_PATTERN.test(tab.id) || BUILTIN_TABS.includes(tab.id)) {
|
|
410
444
|
fail(m.id, `invalid custom tab id « ${tab.id} »`);
|
package/src/sdk/move.test.ts
CHANGED
|
@@ -79,17 +79,18 @@ describe('resealCells', () => {
|
|
|
79
79
|
});
|
|
80
80
|
|
|
81
81
|
assert.equal(await resealCells(q, CELLS, 7, ciphers), 3);
|
|
82
|
+
// Une écriture par colonne, toutes ses lignes en un paquet.
|
|
82
83
|
assert.deepEqual(
|
|
83
84
|
writes.map((w) => w.params),
|
|
84
85
|
[
|
|
85
|
-
['B:corps', 7, 7],
|
|
86
|
-
['B:un', 1, 7]
|
|
87
|
-
['B:deux', 2, 7]
|
|
86
|
+
[7, 'B:corps', 7, 7],
|
|
87
|
+
[1, 'B:un', 2, 'B:deux', 1, 2, 7]
|
|
88
88
|
]
|
|
89
89
|
);
|
|
90
90
|
// La ligne se cible par son identifiant ET son propriétaire : une
|
|
91
91
|
// conversion ne peut pas déborder sur un voisin.
|
|
92
|
-
assert.match(writes[1]!.sql, /
|
|
92
|
+
assert.match(writes[1]!.sql, /CASE id WHEN \? THEN \? WHEN \? THEN \? END/);
|
|
93
|
+
assert.match(writes[1]!.sql, /WHERE id IN \(\?, \?\) AND item_id = \?/);
|
|
93
94
|
});
|
|
94
95
|
|
|
95
96
|
it('annule tout sur une cellule illisible, sans avoir écrit une seule ligne', async () => {
|
|
@@ -121,9 +122,9 @@ describe('resealCells', () => {
|
|
|
121
122
|
await resealCells(q, indirect, 7, ciphers);
|
|
122
123
|
assert.match(
|
|
123
124
|
writes[0]!.sql,
|
|
124
|
-
/WHERE id
|
|
125
|
+
/WHERE id IN \(\?\) AND child_id IN \(SELECT id FROM ft_x_children WHERE item_id = \?\)/
|
|
125
126
|
);
|
|
126
|
-
assert.deepEqual(writes[0]!.params, ['B:feuille', 5, 7]);
|
|
127
|
+
assert.deepEqual(writes[0]!.params, [5, 'B:feuille', 5, 7]);
|
|
127
128
|
});
|
|
128
129
|
|
|
129
130
|
it('compte ce qu’il y aurait à convertir sans rien convertir', async () => {
|
package/src/sdk/providers.ts
CHANGED
|
@@ -97,12 +97,14 @@ export interface DatabaseBackupProvider {
|
|
|
97
97
|
export const DATABASE_ITEMS_PROVIDER = 'database.items' as const;
|
|
98
98
|
|
|
99
99
|
export interface DatabaseItemsProvider {
|
|
100
|
-
/**
|
|
100
|
+
/** Is this database visible from this workspace: its home, or one it is projected into? */
|
|
101
101
|
exists(databaseId: number, workspaceId: number): Promise<boolean>;
|
|
102
102
|
/**
|
|
103
|
-
* The item's display name
|
|
104
|
-
*
|
|
105
|
-
*
|
|
103
|
+
* The item's display name as seen from `workspaceId` (its home, or a
|
|
104
|
+
* workspace it is projected into): the provider resolves the home and its
|
|
105
|
+
* OPEN cipher itself. `null` when it is gone or unreadable. What a window
|
|
106
|
+
* onto a projected project shows for a link it cannot open: a name, never
|
|
107
|
+
* an id.
|
|
106
108
|
*/
|
|
107
109
|
labelOf(databaseId: number, workspaceId: number): Promise<string | null>;
|
|
108
110
|
}
|
|
@@ -123,20 +125,40 @@ export interface MailSender {
|
|
|
123
125
|
address: string;
|
|
124
126
|
}
|
|
125
127
|
|
|
128
|
+
/**
|
|
129
|
+
* A file carried along a message: the `.ics` invitation of a booking, a small
|
|
130
|
+
* report. `Uint8Array` rather than `Buffer`: the published package does not
|
|
131
|
+
* depend on Node's types beyond `node:net`, and the adapter bridges it.
|
|
132
|
+
*/
|
|
133
|
+
export interface MailAttachment {
|
|
134
|
+
filename: string;
|
|
135
|
+
contentType: string;
|
|
136
|
+
content: Uint8Array;
|
|
137
|
+
}
|
|
138
|
+
|
|
126
139
|
export interface MailTransportProvider {
|
|
127
140
|
/** The workspace's ready senders (open tier, enabled). */
|
|
128
141
|
listSenders(workspaceId: number): Promise<readonly MailSender[]>;
|
|
129
142
|
/** Is this account a ready sender of this workspace right now? */
|
|
130
143
|
isReady(accountId: number, workspaceId: number): Promise<boolean>;
|
|
131
144
|
/**
|
|
132
|
-
* Sends one
|
|
133
|
-
*
|
|
134
|
-
*
|
|
145
|
+
* Sends one message from this account. Resolves `true` when the provider
|
|
146
|
+
* accepted it; `false` (never a throw) when the account is not a ready
|
|
147
|
+
* sender or the send failed, the failure logged by the module.
|
|
148
|
+
*
|
|
149
|
+
* `text` stays mandatory whatever else is given: a recipient whose client
|
|
150
|
+
* shows no HTML must lose nothing.
|
|
135
151
|
*/
|
|
136
152
|
send(
|
|
137
153
|
accountId: number,
|
|
138
154
|
workspaceId: number,
|
|
139
|
-
message: {
|
|
155
|
+
message: {
|
|
156
|
+
to: string;
|
|
157
|
+
subject: string;
|
|
158
|
+
text: string;
|
|
159
|
+
html?: string;
|
|
160
|
+
attachments?: readonly MailAttachment[];
|
|
161
|
+
}
|
|
140
162
|
): Promise<boolean>;
|
|
141
163
|
}
|
|
142
164
|
|
|
@@ -156,12 +178,14 @@ export const MAIL_CLIENT_PROVIDER = 'mail.client' as const;
|
|
|
156
178
|
export const AUDIENCE_ITEMS_PROVIDER = 'audience.items' as const;
|
|
157
179
|
|
|
158
180
|
export interface AudienceItemsProvider {
|
|
159
|
-
/**
|
|
181
|
+
/** Is this site visible from this workspace: its home, or one it is projected into? */
|
|
160
182
|
exists(siteId: number, workspaceId: number): Promise<boolean>;
|
|
161
183
|
/**
|
|
162
|
-
* The item's display name
|
|
163
|
-
*
|
|
164
|
-
*
|
|
184
|
+
* The item's display name as seen from `workspaceId` (its home, or a
|
|
185
|
+
* workspace it is projected into): the provider resolves the home and its
|
|
186
|
+
* OPEN cipher itself. `null` when it is gone or unreadable. What a window
|
|
187
|
+
* onto a projected project shows for a link it cannot open: a name, never
|
|
188
|
+
* an id.
|
|
165
189
|
*/
|
|
166
190
|
labelOf(siteId: number, workspaceId: number): Promise<string | null>;
|
|
167
191
|
}
|
|
@@ -182,12 +206,14 @@ export const AUDIENCE_CLIENT_PROVIDER = 'audience.client' as const;
|
|
|
182
206
|
export const GIT_ITEMS_PROVIDER = 'git.items' as const;
|
|
183
207
|
|
|
184
208
|
export interface GitItemsProvider {
|
|
185
|
-
/**
|
|
209
|
+
/** Is this repository visible from this workspace: its home, or one it is projected into? */
|
|
186
210
|
exists(repoId: number, workspaceId: number): Promise<boolean>;
|
|
187
211
|
/**
|
|
188
|
-
* The item's display name
|
|
189
|
-
*
|
|
190
|
-
*
|
|
212
|
+
* The item's display name as seen from `workspaceId` (its home, or a
|
|
213
|
+
* workspace it is projected into): the provider resolves the home and its
|
|
214
|
+
* OPEN cipher itself. `null` when it is gone or unreadable. What a window
|
|
215
|
+
* onto a projected project shows for a link it cannot open: a name, never
|
|
216
|
+
* an id.
|
|
191
217
|
*/
|
|
192
218
|
labelOf(repoId: number, workspaceId: number): Promise<string | null>;
|
|
193
219
|
}
|
|
@@ -208,12 +234,14 @@ export const GIT_CLIENT_PROVIDER = 'git.client' as const;
|
|
|
208
234
|
export const DEPLOY_ITEMS_PROVIDER = 'deploy.items' as const;
|
|
209
235
|
|
|
210
236
|
export interface DeployItemsProvider {
|
|
211
|
-
/**
|
|
237
|
+
/** Is this target visible from this workspace: its home, or one it is projected into? */
|
|
212
238
|
exists(targetId: number, workspaceId: number): Promise<boolean>;
|
|
213
239
|
/**
|
|
214
|
-
* The item's display name
|
|
215
|
-
*
|
|
216
|
-
*
|
|
240
|
+
* The item's display name as seen from `workspaceId` (its home, or a
|
|
241
|
+
* workspace it is projected into): the provider resolves the home and its
|
|
242
|
+
* OPEN cipher itself. `null` when it is gone or unreadable. What a window
|
|
243
|
+
* onto a projected project shows for a link it cannot open: a name, never
|
|
244
|
+
* an id.
|
|
217
245
|
*/
|
|
218
246
|
labelOf(targetId: number, workspaceId: number): Promise<string | null>;
|
|
219
247
|
}
|
|
@@ -262,13 +290,15 @@ export interface ProjectsUsageProvider {
|
|
|
262
290
|
/** How many projects of the workspace link each item of this feature (absent = zero). */
|
|
263
291
|
countByItem(feature: string, workspaceId: number): Promise<ReadonlyMap<number, number>>;
|
|
264
292
|
/**
|
|
265
|
-
* The item
|
|
266
|
-
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
293
|
+
* The item is no longer visible from the workspace (deleted, moved away,
|
|
294
|
+
* or its projection withdrawn): drop every link pointing at it from there,
|
|
295
|
+
* and answer how many projects lost one. A link lives in the project's
|
|
296
|
+
* workspace and points at an item visible there, so an item that leaves
|
|
297
|
+
* takes none with it; left alone the rows would keep naming an item that
|
|
298
|
+
* is not there any more.
|
|
269
299
|
*
|
|
270
|
-
* Called by the app
|
|
271
|
-
*
|
|
300
|
+
* Called by the app, never by the module that owns the item. Idempotent,
|
|
301
|
+
* and zero for a feature that links nothing.
|
|
272
302
|
*/
|
|
273
303
|
detach(feature: string, itemId: number, workspaceId: number): Promise<number>;
|
|
274
304
|
/**
|
|
@@ -306,12 +336,14 @@ export interface ProjectsUsageProvider {
|
|
|
306
336
|
export const UPTIME_ITEMS_PROVIDER = 'uptime.items' as const;
|
|
307
337
|
|
|
308
338
|
export interface UptimeItemsProvider {
|
|
309
|
-
/**
|
|
339
|
+
/** Is this service visible from this workspace: its home, or one it is projected into? */
|
|
310
340
|
exists(serviceId: number, workspaceId: number): Promise<boolean>;
|
|
311
341
|
/**
|
|
312
|
-
* The item's display name
|
|
313
|
-
*
|
|
314
|
-
*
|
|
342
|
+
* The item's display name as seen from `workspaceId` (its home, or a
|
|
343
|
+
* workspace it is projected into): the provider resolves the home and its
|
|
344
|
+
* OPEN cipher itself. `null` when it is gone or unreadable. What a window
|
|
345
|
+
* onto a projected project shows for a link it cannot open: a name, never
|
|
346
|
+
* an id.
|
|
315
347
|
*/
|
|
316
348
|
labelOf(serviceId: number, workspaceId: number): Promise<string | null>;
|
|
317
349
|
}
|
package/src/sdk/server.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { AuthWindow, DeviceReport, IntegrityReport, ReportProcess } from '.
|
|
|
7
7
|
import type { AgentManifest } from '../http/device';
|
|
8
8
|
import type { MetricSnapshot } from '../domain/metrics';
|
|
9
9
|
import type { UserColor } from '../domain/user';
|
|
10
|
+
import type { SdkDnsRecord } from './domains';
|
|
10
11
|
import type {
|
|
11
12
|
AgentSyncAckPayload,
|
|
12
13
|
AgentSyncApplyChunkPayload,
|
|
@@ -30,6 +31,12 @@ import type {
|
|
|
30
31
|
} from '../protocol/agent';
|
|
31
32
|
|
|
32
33
|
export { isPublicIp, isSafePublicUrl } from './net';
|
|
34
|
+
export {
|
|
35
|
+
DOMAIN_HOST_PATTERN,
|
|
36
|
+
domainOwnershipRecord,
|
|
37
|
+
normaliseDomainHost,
|
|
38
|
+
type SdkDnsRecord
|
|
39
|
+
} from './domains';
|
|
33
40
|
|
|
34
41
|
/**
|
|
35
42
|
* Server-side SDK surface: what a feature module's handlers and background
|
|
@@ -579,6 +586,77 @@ export interface SdkFleetDevices {
|
|
|
579
586
|
isOnline(deviceId: string): boolean;
|
|
580
587
|
}
|
|
581
588
|
|
|
589
|
+
/**
|
|
590
|
+
* One of your feature's domains (manifest `domains`). Declared and verified
|
|
591
|
+
* in the Domains tab the shell renders; your module only reads them.
|
|
592
|
+
*/
|
|
593
|
+
export interface SdkDomain {
|
|
594
|
+
id: number;
|
|
595
|
+
workspaceId: number;
|
|
596
|
+
host: string;
|
|
597
|
+
/** Published in the DNS by nature, so not a secret. */
|
|
598
|
+
token: string;
|
|
599
|
+
/** Both stages have passed, and neither has failed three times in a row since. */
|
|
600
|
+
verified: boolean;
|
|
601
|
+
verifiedAt: number | null;
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
/** Your feature's domains in the caller's workspace. Throws `forbidden` unless the manifest declares `domains`. */
|
|
605
|
+
export interface SdkDomains {
|
|
606
|
+
list(): Promise<readonly SdkDomain[]>;
|
|
607
|
+
get(id: number): Promise<SdkDomain | null>;
|
|
608
|
+
verified(): Promise<readonly SdkDomain[]>;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/** Your feature's domains, sessionless: for a service or a public route. */
|
|
612
|
+
export interface SdkFleetDomains {
|
|
613
|
+
/** Whatever the workspace. `host` is normalised for you: pass the raw `Host` header. */
|
|
614
|
+
findByHost(host: string): Promise<SdkDomain | null>;
|
|
615
|
+
get(workspaceId: number, id: number): Promise<SdkDomain | null>;
|
|
616
|
+
listVerified(workspaceId: number): Promise<readonly SdkDomain[]>;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
/** DNS lookups, injected so a probe is testable. A name that does not exist yields `[]`, not a throw. */
|
|
620
|
+
export interface SdkDns {
|
|
621
|
+
/** One string per record, the 255-byte chunks rejoined. */
|
|
622
|
+
txt(name: string): Promise<string[]>;
|
|
623
|
+
mx(name: string): Promise<{ exchange: string; priority: number }[]>;
|
|
624
|
+
cname(name: string): Promise<string[]>;
|
|
625
|
+
}
|
|
626
|
+
|
|
627
|
+
/** What the domain hooks receive. Sessionless: they also run from the background pass. */
|
|
628
|
+
export interface FeatureDomainsContext<Repo = unknown> {
|
|
629
|
+
repo: Repo;
|
|
630
|
+
origins: { app: string; public: string };
|
|
631
|
+
/** Open tier only. */
|
|
632
|
+
cipherFor(workspaceId: number): SdkCipher;
|
|
633
|
+
storeFor(workspaceId: number): SessionlessFeatureStore;
|
|
634
|
+
keys: SdkServerKeys;
|
|
635
|
+
dns: SdkDns;
|
|
636
|
+
logger: SdkLogger;
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
export type SdkDomainProbe = { ok: true } | { ok: false; error: string };
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* Your half of domain verification, required when the manifest declares
|
|
643
|
+
* `domains`. Ownership (the TXT record) is always DevEye's check; yours is
|
|
644
|
+
* the second stage: is the domain really wired to what you serve?
|
|
645
|
+
*/
|
|
646
|
+
export interface FeatureDomainsEntry<Repo = unknown> {
|
|
647
|
+
/** What to publish on top of the ownership record (a CNAME, an MX...). Shown in the records dialog. */
|
|
648
|
+
records(ctx: FeatureDomainsContext<Repo>, domain: SdkDomain): Promise<readonly SdkDnsRecord[]>;
|
|
649
|
+
/** Called only once ownership holds. A failed check is a returned sentence, never a throw. */
|
|
650
|
+
probe(ctx: FeatureDomainsContext<Repo>, domain: SdkDomain): Promise<SdkDomainProbe>;
|
|
651
|
+
/** How many of your items designate each domain, by domain id. Shown on the row and in the removal warning. */
|
|
652
|
+
useCount?(
|
|
653
|
+
ctx: FeatureDomainsContext<Repo>,
|
|
654
|
+
workspaceId: number
|
|
655
|
+
): Promise<ReadonlyMap<number, number>>;
|
|
656
|
+
/** Runs before the row is deleted: drop your references. A throw aborts the removal. */
|
|
657
|
+
onRemoved?(ctx: FeatureDomainsContext<Repo>, domain: SdkDomain): Promise<void>;
|
|
658
|
+
}
|
|
659
|
+
|
|
582
660
|
/** What a handler receives. One request, one workspace, rights pre-resolved. */
|
|
583
661
|
export interface SdkFeatureContext<Repo = unknown> {
|
|
584
662
|
userId: number;
|
|
@@ -613,6 +691,8 @@ export interface SdkFeatureContext<Repo = unknown> {
|
|
|
613
691
|
items: SdkItems;
|
|
614
692
|
/** Projections into the active workspace. Throws `forbidden` when the manifest says `shareTier: 'never'`. */
|
|
615
693
|
sharing: SdkSharing;
|
|
694
|
+
/** Your feature's domains in this workspace (manifest `domains`). */
|
|
695
|
+
domains: SdkDomains;
|
|
616
696
|
/** The named contracts the host holds, see `SdkProviders`. */
|
|
617
697
|
providers: SdkProviders;
|
|
618
698
|
/** Fire-and-forget audit line; actor, IP and workspace are pre-bound. */
|
|
@@ -690,6 +770,18 @@ export interface SdkPublicRequest {
|
|
|
690
770
|
* What a ticketed GET (a download URL, an OAuth callback) carries.
|
|
691
771
|
*/
|
|
692
772
|
query?: unknown;
|
|
773
|
+
/**
|
|
774
|
+
* Path parameters the host decoded (`/rdv/:ref` reads `{ ref: 'abc' }`).
|
|
775
|
+
* `unknown` like `body` and `query`: re-read it through a schema. Absent
|
|
776
|
+
* from a route that declares none.
|
|
777
|
+
*/
|
|
778
|
+
params?: unknown;
|
|
779
|
+
/**
|
|
780
|
+
* The request's host, normalised by the host: `Host`, or `X-Forwarded-Host`
|
|
781
|
+
* behind a trusted proxy, port included. UNTRUSTED data: it proves nothing,
|
|
782
|
+
* it only picks among what the database already verified.
|
|
783
|
+
*/
|
|
784
|
+
host?: string;
|
|
693
785
|
ip: string;
|
|
694
786
|
}
|
|
695
787
|
|
|
@@ -797,6 +889,8 @@ export interface FeatureServiceDeps<Repo = unknown> {
|
|
|
797
889
|
secrecy: { redeem(ticket: string): Promise<SdkRedeemedTicket | null> };
|
|
798
890
|
/** Where DevEye lives (the same `origins` a request context gets): for a page or a link a route hands to the browser. */
|
|
799
891
|
origins: { app: string; public: string };
|
|
892
|
+
/** Your feature's domains, whatever the workspace (manifest `domains`). */
|
|
893
|
+
domains: SdkFleetDomains;
|
|
800
894
|
/** The named contracts the host holds, see `SdkProviders`. */
|
|
801
895
|
providers: SdkProviders;
|
|
802
896
|
/**
|
|
@@ -829,6 +923,8 @@ export interface FeatureServer<Repo = unknown> {
|
|
|
829
923
|
* notifies (the channels screen names the item a route points to).
|
|
830
924
|
*/
|
|
831
925
|
items?: FeatureItemsEntry<Repo>;
|
|
926
|
+
/** Required when the manifest declares `domains`, refused otherwise. */
|
|
927
|
+
domains?: FeatureDomainsEntry<Repo>;
|
|
832
928
|
}
|
|
833
929
|
|
|
834
930
|
/**
|
|
@@ -981,6 +1077,9 @@ function ownerFilter(cell: MovableCell): string {
|
|
|
981
1077
|
: `${cell.ownerColumn} = ?`;
|
|
982
1078
|
}
|
|
983
1079
|
|
|
1080
|
+
/** Rows rewritten per `UPDATE` by {@link resealCells}. */
|
|
1081
|
+
const RESEAL_BATCH = 100;
|
|
1082
|
+
|
|
984
1083
|
/** How many cells {@link resealCells} would convert: a `plan`'s `rows`. */
|
|
985
1084
|
export async function countMovableCells(
|
|
986
1085
|
q: SdkQueryable,
|
|
@@ -1035,13 +1134,22 @@ export async function resealCells(
|
|
|
1035
1134
|
}
|
|
1036
1135
|
}
|
|
1037
1136
|
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1137
|
+
// Par paquets et non ligne à ligne : un dépôt de quelques milliers de
|
|
1138
|
+
// commits vaut autant d'allers-retours, et le geste doit tenir en secondes.
|
|
1139
|
+
for (const cell of cells) {
|
|
1140
|
+
const mine = pending.filter((p) => p.cell === cell);
|
|
1141
|
+
for (let at = 0; at < mine.length; at += RESEAL_BATCH) {
|
|
1142
|
+
const batch = mine.slice(at, at + RESEAL_BATCH);
|
|
1143
|
+
const cases = batch.map(() => 'WHEN ? THEN ?').join(' ');
|
|
1144
|
+
const ids = batch.map(() => '?').join(', ');
|
|
1145
|
+
// La garde du propriétaire dans le `WHERE` même quand l'identifiant
|
|
1146
|
+
// suffit : une conversion ne peut alors pas déborder sur un voisin.
|
|
1147
|
+
await q.execute(
|
|
1148
|
+
`UPDATE ${cell.table} SET ${cell.column} = CASE ${cell.idColumn} ${cases} END
|
|
1149
|
+
WHERE ${cell.idColumn} IN (${ids}) AND ${ownerFilter(cell)}`,
|
|
1150
|
+
[...batch.flatMap((p) => [p.id, p.value]), ...batch.map((p) => p.id), ownerId]
|
|
1151
|
+
);
|
|
1152
|
+
}
|
|
1045
1153
|
}
|
|
1046
1154
|
return pending.length;
|
|
1047
1155
|
}
|
package/src/sdk/testing.test.ts
CHANGED
|
@@ -2,7 +2,13 @@ import assert from 'node:assert/strict';
|
|
|
2
2
|
import { test } from 'node:test';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
createTestContext,
|
|
7
|
+
createTestDomainsContext,
|
|
8
|
+
createTestServiceDeps,
|
|
9
|
+
testDevice,
|
|
10
|
+
testDomain
|
|
11
|
+
} from './testing';
|
|
6
12
|
|
|
7
13
|
test('createTestContext follows the manifest for extras, and records what handlers do', async () => {
|
|
8
14
|
const manifest = {
|
|
@@ -60,3 +66,29 @@ test('createTestServiceDeps: one store per workspace, hand-driven tickers, a wra
|
|
|
60
66
|
assert.equal(deps.devicesFor(1).isOnline('d1'), false);
|
|
61
67
|
assert.equal((await deps.devicesFor(1).list()).length, 1);
|
|
62
68
|
});
|
|
69
|
+
|
|
70
|
+
test('the harness scopes domains to the workspace, and finds a host whatever its spelling', async () => {
|
|
71
|
+
const domains = [
|
|
72
|
+
testDomain({ id: 1, host: 'a.example.com' }),
|
|
73
|
+
testDomain({ id: 2, host: 'b.example.com', verified: false, verifiedAt: null }),
|
|
74
|
+
testDomain({ id: 3, host: 'c.example.com', workspaceId: 2 })
|
|
75
|
+
];
|
|
76
|
+
const ctx = createTestContext({ domains });
|
|
77
|
+
assert.deepEqual(
|
|
78
|
+
(await ctx.domains.list()).map((d) => d.id),
|
|
79
|
+
[1, 2]
|
|
80
|
+
);
|
|
81
|
+
assert.deepEqual(
|
|
82
|
+
(await ctx.domains.verified()).map((d) => d.id),
|
|
83
|
+
[1]
|
|
84
|
+
);
|
|
85
|
+
assert.equal(await ctx.domains.get(3), null, 'another workspace');
|
|
86
|
+
|
|
87
|
+
const deps = createTestServiceDeps({ domains });
|
|
88
|
+
assert.equal((await deps.domains.findByHost('C.Example.com:443.'))?.id, 3);
|
|
89
|
+
assert.equal(await deps.domains.findByHost('nope.example.com'), null);
|
|
90
|
+
|
|
91
|
+
const hooks = createTestDomainsContext({ dns: { txt: () => Promise.resolve(['v=spf1']) } });
|
|
92
|
+
assert.deepEqual(await hooks.dns.txt('x'), ['v=spf1']);
|
|
93
|
+
assert.deepEqual(await hooks.dns.mx('x'), []);
|
|
94
|
+
});
|
package/src/sdk/testing.ts
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { ZodType } from 'zod';
|
|
2
2
|
import type { ItemAccess } from '../domain/sharing';
|
|
3
|
+
import { normaliseDomainHost } from './domains';
|
|
3
4
|
import { resolveExtras, type FeatureManifest } from './manifest';
|
|
4
5
|
import {
|
|
5
6
|
FeatureError,
|
|
6
7
|
type DevEyeFacade,
|
|
8
|
+
type FeatureDomainsContext,
|
|
9
|
+
type SdkDns,
|
|
10
|
+
type SdkDomain,
|
|
7
11
|
type FeatureServiceDeps,
|
|
8
12
|
type FeatureStore,
|
|
9
13
|
type SdkCipher,
|
|
@@ -236,6 +240,20 @@ function fakeDerive(salt: string, info: string, length: number): Uint8Array {
|
|
|
236
240
|
return out;
|
|
237
241
|
}
|
|
238
242
|
|
|
243
|
+
function memoryDomains(domains: readonly SdkDomain[]) {
|
|
244
|
+
return {
|
|
245
|
+
in: (workspaceId: number) => domains.filter((d) => d.workspaceId === workspaceId),
|
|
246
|
+
byHost: (host: string) => domains.find((d) => d.host === normaliseDomainHost(host)) ?? null
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
/** Lookups that find nothing, unless the test says otherwise. */
|
|
251
|
+
const emptyDns: SdkDns = {
|
|
252
|
+
txt: () => Promise.resolve([]),
|
|
253
|
+
mx: () => Promise.resolve([]),
|
|
254
|
+
cname: () => Promise.resolve([])
|
|
255
|
+
};
|
|
256
|
+
|
|
239
257
|
/** The named contracts a test hands to the module (`providers` override). */
|
|
240
258
|
function fakeProviders(table: Readonly<Record<string, unknown>>): SdkProviders {
|
|
241
259
|
return { get: <T>(key: string) => table[key] as T | undefined };
|
|
@@ -296,6 +314,8 @@ export interface TestContextOverrides<Repo> {
|
|
|
296
314
|
* identity cipher either way.
|
|
297
315
|
*/
|
|
298
316
|
shares?: Readonly<Record<string, number>>;
|
|
317
|
+
/** The feature's domains, every workspace mixed: `ctx.domains` answers for the active one. Default none. */
|
|
318
|
+
domains?: readonly SdkDomain[];
|
|
299
319
|
/** The named contracts the host holds (`ctx.providers.get(key)`). */
|
|
300
320
|
providers?: Readonly<Record<string, unknown>>;
|
|
301
321
|
}
|
|
@@ -418,6 +438,21 @@ export function createTestContext<Repo = undefined>(
|
|
|
418
438
|
sendSyncChunk: () => 0,
|
|
419
439
|
syncChunkBuffered: () => 0
|
|
420
440
|
},
|
|
441
|
+
domains: {
|
|
442
|
+
list: () => Promise.resolve(memoryDomains(overrides.domains ?? []).in(workspaceId)),
|
|
443
|
+
get: (id) =>
|
|
444
|
+
Promise.resolve(
|
|
445
|
+
memoryDomains(overrides.domains ?? [])
|
|
446
|
+
.in(workspaceId)
|
|
447
|
+
.find((d) => d.id === id) ?? null
|
|
448
|
+
),
|
|
449
|
+
verified: () =>
|
|
450
|
+
Promise.resolve(
|
|
451
|
+
memoryDomains(overrides.domains ?? [])
|
|
452
|
+
.in(workspaceId)
|
|
453
|
+
.filter((d) => d.verified)
|
|
454
|
+
)
|
|
455
|
+
},
|
|
421
456
|
providers: fakeProviders(overrides.providers ?? {}),
|
|
422
457
|
audit: (entry) => {
|
|
423
458
|
recorded.audits.push({ action: entry.action, description: entry.description });
|
|
@@ -462,6 +497,8 @@ export interface TestServiceOverrides<Repo> {
|
|
|
462
497
|
origins?: { app: string; public: string };
|
|
463
498
|
/** Instants `telemetry.snapshot` answers (matched within a second). Default none. */
|
|
464
499
|
snapshots?: readonly SdkTelemetrySnapshot[];
|
|
500
|
+
/** The feature's domains, every workspace mixed. Default none. */
|
|
501
|
+
domains?: readonly SdkDomain[];
|
|
465
502
|
/** The named contracts the host holds (`deps.providers.get(key)`). */
|
|
466
503
|
providers?: Readonly<Record<string, unknown>>;
|
|
467
504
|
}
|
|
@@ -564,6 +601,22 @@ export function createTestServiceDeps<Repo = undefined>(
|
|
|
564
601
|
openBytes: (sealed) => sealedBytes.get(sealed) ?? null,
|
|
565
602
|
derive: fakeDerive
|
|
566
603
|
},
|
|
604
|
+
domains: {
|
|
605
|
+
findByHost: (host) =>
|
|
606
|
+
Promise.resolve(memoryDomains(overrides.domains ?? []).byHost(host)),
|
|
607
|
+
get: (workspaceId, id) =>
|
|
608
|
+
Promise.resolve(
|
|
609
|
+
memoryDomains(overrides.domains ?? [])
|
|
610
|
+
.in(workspaceId)
|
|
611
|
+
.find((d) => d.id === id) ?? null
|
|
612
|
+
),
|
|
613
|
+
listVerified: (workspaceId) =>
|
|
614
|
+
Promise.resolve(
|
|
615
|
+
memoryDomains(overrides.domains ?? [])
|
|
616
|
+
.in(workspaceId)
|
|
617
|
+
.filter((d) => d.verified)
|
|
618
|
+
)
|
|
619
|
+
},
|
|
567
620
|
providers: fakeProviders(overrides.providers ?? {}),
|
|
568
621
|
createTicker({ intervalMs, tick }) {
|
|
569
622
|
recorded.tickers.push({ intervalMs, tick });
|
|
@@ -572,3 +625,51 @@ export function createTestServiceDeps<Repo = undefined>(
|
|
|
572
625
|
logger: silentLogger
|
|
573
626
|
};
|
|
574
627
|
}
|
|
628
|
+
|
|
629
|
+
/** A domain row for a test, verified by default. */
|
|
630
|
+
export function testDomain(over: Partial<SdkDomain> & { id: number; host: string }): SdkDomain {
|
|
631
|
+
return { workspaceId: 1, token: 'a'.repeat(32), verified: true, verifiedAt: 1, ...over };
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
/**
|
|
635
|
+
* What the `domains` hooks of a server entry receive, in memory: identity
|
|
636
|
+
* cipher, one store per workspace, and lookups that find nothing unless `dns`
|
|
637
|
+
* says otherwise.
|
|
638
|
+
*/
|
|
639
|
+
export function createTestDomainsContext<Repo = undefined>(
|
|
640
|
+
overrides: {
|
|
641
|
+
repo?: Repo;
|
|
642
|
+
dns?: Partial<SdkDns>;
|
|
643
|
+
origins?: { app: string; public: string };
|
|
644
|
+
} = {}
|
|
645
|
+
): FeatureDomainsContext<Repo> {
|
|
646
|
+
const stores = new Map<number, TestFeatureStore>();
|
|
647
|
+
const sealedBytes = new Map<string, Uint8Array>();
|
|
648
|
+
return {
|
|
649
|
+
repo: overrides.repo as Repo,
|
|
650
|
+
origins: overrides.origins ?? {
|
|
651
|
+
app: 'https://deveye.test',
|
|
652
|
+
public: 'https://public.deveye.test'
|
|
653
|
+
},
|
|
654
|
+
cipherFor: () => identityCipher,
|
|
655
|
+
storeFor(workspaceId) {
|
|
656
|
+
let store = stores.get(workspaceId);
|
|
657
|
+
if (!store) {
|
|
658
|
+
store = memoryStore();
|
|
659
|
+
stores.set(workspaceId, store);
|
|
660
|
+
}
|
|
661
|
+
return store;
|
|
662
|
+
},
|
|
663
|
+
keys: {
|
|
664
|
+
sealBytes: (plain) => {
|
|
665
|
+
const handle = `sealed:${sealedBytes.size}`;
|
|
666
|
+
sealedBytes.set(handle, Uint8Array.from(plain));
|
|
667
|
+
return handle;
|
|
668
|
+
},
|
|
669
|
+
openBytes: (sealed) => sealedBytes.get(sealed) ?? null,
|
|
670
|
+
derive: fakeDerive
|
|
671
|
+
},
|
|
672
|
+
dns: { ...emptyDns, ...overrides.dns },
|
|
673
|
+
logger: silentLogger
|
|
674
|
+
};
|
|
675
|
+
}
|