@deveye/types 0.19.1 → 0.19.2

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/README.md CHANGED
@@ -21,3 +21,9 @@ DevEye vérifie mécaniquement que le vrai barrel l'honore.
21
21
 
22
22
  Pour écrire un module : partir du
23
23
  [template](https://github.com/Gerem66/DevEye-Feature-Template) et sa doc.
24
+
25
+ ## Licence
26
+
27
+ [MIT](LICENSE). Un module bâti sur ce paquet se licencie comme son auteur
28
+ l'entend : le cœur de DevEye est sous AGPL-3.0, avec une exception pour ce qui
29
+ ne passe que par ce SDK (`LICENSING.md` du dépôt de l'app).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deveye/types",
3
- "version": "0.19.1",
3
+ "version": "0.19.2",
4
4
  "description": "Shared contracts (types + zod schemas) for DevEye apps",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -282,6 +282,16 @@ export const FEATURE_REGISTRY: readonly (FeatureDescriptor & { id: WorkspaceFeat
282
282
  itemNoun: 'adresse',
283
283
  itemNounGender: 'f',
284
284
  shareTier: 'open'
285
+ },
286
+ {
287
+ id: 'convert',
288
+ label: 'Convertisseur',
289
+ description:
290
+ 'Lecture : les devises, les unités, et ses propres conversions. Écriture : convertir un fichier, annuler une conversion, retirer un résultat.',
291
+ icon: 'convert',
292
+ notifies: true,
293
+ hasItems: false,
294
+ shareTier: 'never'
285
295
  }
286
296
  ];
287
297
 
@@ -38,7 +38,8 @@ export const nativeHomeFeatureIdSchema = z.enum([
38
38
  'audience',
39
39
  'osint',
40
40
  'cve',
41
- 'mailserver'
41
+ 'mailserver',
42
+ 'convert'
42
43
  ]);
43
44
  export type NativeHomeFeatureId = z.infer<typeof nativeHomeFeatureIdSchema>;
44
45
 
@@ -200,6 +200,7 @@ export const TOPIC_FEATURE: Record<NativeLiveTopic, WorkspaceFeatureId | null> =
200
200
  osint: 'osint',
201
201
  cve: 'cve',
202
202
  mailserver: 'mailserver',
203
+ convert: 'convert',
203
204
  workspace: null,
204
205
  home: null,
205
206
  account: null,
@@ -41,7 +41,8 @@ export const nativeNotificationFeatureSchema = z.enum([
41
41
  'sentinel',
42
42
  'database',
43
43
  'deploy',
44
- 'backup'
44
+ 'backup',
45
+ 'convert'
45
46
  ]);
46
47
  export type NativeNotificationFeature = z.infer<typeof nativeNotificationFeatureSchema>;
47
48
 
@@ -95,7 +95,13 @@ export const workspaceFeatureIdSchema = z.enum([
95
95
  * Réinitialiser un mot de passe et purger la file d'envoi sont des
96
96
  * permissions propres du module.
97
97
  */
98
- 'mailserver'
98
+ 'mailserver',
99
+ /**
100
+ * Convertisseur. `read` = les devises, les unités, et ses propres
101
+ * conversions ; `write` = convertir un fichier, annuler, retirer. Personne
102
+ * ne voit les conversions d'un autre membre.
103
+ */
104
+ 'convert'
99
105
  ]);
100
106
 
101
107
  export type WorkspaceFeatureId = z.infer<typeof workspaceFeatureIdSchema>;
@@ -63,9 +63,76 @@ declare module 'deveye-sdk-client' {
63
63
  disabled?: boolean;
64
64
  'aria-label'?: string;
65
65
  }>;
66
+ /**
67
+ * The app's number field: a native number input between two ± buttons.
68
+ * `null` is an empty field. What is being typed is never rewritten while
69
+ * the field has focus; the value is clamped to `min`/`max` on blur. `live`
70
+ * reports every in-range keystroke, for what shows at once (a preview).
71
+ * On the focused field only, the wheel steps by `step`, by fifty steps with
72
+ * Ctrl or Shift held; anywhere else it scrolls the page.
73
+ */
74
+ export const NumberInput: ComponentType<{
75
+ value: number | null;
76
+ onChange: (value: number | null) => void;
77
+ min?: number;
78
+ max?: number;
79
+ step?: number;
80
+ placeholder?: string;
81
+ disabled?: boolean;
82
+ live?: boolean;
83
+ /** For a wrapping `<label htmlFor>`: without it, clicking the label would press "−". */
84
+ id?: string;
85
+ 'aria-label'?: string;
86
+ className?: string;
87
+ }>;
88
+ /** One choice of a `SearchSelect`. `prefix` is decorative (a flag, an avatar); `keywords` widen what the search reads. */
89
+ export interface SearchSelectOption<T extends string = string> {
90
+ value: T;
91
+ label: string;
92
+ prefix?: ReactNode;
93
+ detail?: string;
94
+ keywords?: readonly string[];
95
+ }
96
+ /**
97
+ * A dropdown one can search in (accent- and case-insensitive), for a list too
98
+ * long to scan: currencies, units, countries. Under ten choices or so,
99
+ * `SelectInput` stays simpler. Safe inside a Dialog: the panel is portaled.
100
+ */
101
+ export function SearchSelect<T extends string>(props: {
102
+ value: T;
103
+ options: readonly SearchSelectOption<T>[];
104
+ onChange: (value: T) => void;
105
+ 'aria-label': string;
106
+ /** What the trigger shows when no option carries the current value. */
107
+ placeholder?: string;
108
+ searchPlaceholder?: string;
109
+ emptyText?: string;
110
+ disabled?: boolean;
111
+ className?: string;
112
+ }): ReactNode;
113
+ /**
114
+ * A labelled range input. `valueLabel` is how the value reads ("24", "80 %");
115
+ * `marks` sit under the track; `indicator` draws a discreet tick at a
116
+ * reference value (decorative: say what it means in `hint`).
117
+ */
118
+ export const Slider: ComponentType<{
119
+ value: number;
120
+ onChange: (value: number) => void;
121
+ min: number;
122
+ max: number;
123
+ step?: number;
124
+ label: string;
125
+ valueLabel?: string;
126
+ marks?: readonly string[];
127
+ indicator?: number;
128
+ hint?: string;
129
+ disabled?: boolean;
130
+ className?: string;
131
+ }>;
66
132
  export function SegmentedControl<T extends string>(props: {
67
133
  value: T;
68
- options: readonly { value: T; label: string; title?: string }[];
134
+ /** `detail`: a small line under the label, what the choice amounts to here ("Original", then "30 fps"). */
135
+ options: readonly { value: T; label: string; title?: string; detail?: string }[];
69
136
  onChange: (value: T) => void;
70
137
  /** Étire le groupe sur la ligne, chaque choix en prenant une part égale. */
71
138
  fullWidth?: boolean;
@@ -98,6 +165,22 @@ declare module 'deveye-sdk-client' {
98
165
  onPick?: (value: T) => void;
99
166
  'aria-label'?: string;
100
167
  }): ReactNode;
168
+ /** One choice of a `CountBadge`: what it counts, and whether it asks to be seen. */
169
+ export interface CountBadgeProps {
170
+ count: number;
171
+ /** `accent` (default): unread, something to act on. `neutral`: a plain count. */
172
+ tone?: 'accent' | 'neutral';
173
+ /** Above it, the badge reads "99+". Default 99. */
174
+ max?: number;
175
+ /** Needed when the number alone does not say what it counts. */
176
+ 'aria-label'?: string;
177
+ className?: string;
178
+ }
179
+ /**
180
+ * A counter pill: a number in a round. Round on one digit, a capsule beyond,
181
+ * its content centred both ways, which plain padding does not give.
182
+ */
183
+ export const CountBadge: ComponentType<CountBadgeProps>;
101
184
  /**
102
185
  * Le bouton d'enregistrement d'un panneau de réglages : « Enregistrement… »
103
186
  * pendant l'aller-retour, « Enregistré » quelques secondes, puis l'intitulé
@@ -463,6 +546,19 @@ declare module 'deveye-sdk-client' {
463
546
  * `undefined`. Use it on every `<a href>` you do not write yourself.
464
547
  */
465
548
  export function safeHref(url: string | null | undefined): string | undefined;
549
+ /**
550
+ * A v4 UUID, secure context or not. `crypto.randomUUID` is only exposed over
551
+ * HTTPS or on localhost, so an instance served in the clear on a LAN address
552
+ * does not have it: use this instead of calling it yourself.
553
+ */
554
+ export function randomUuid(): string;
555
+ /**
556
+ * Writes `value` to the clipboard and says whether it worked: on `false` the
557
+ * gesture still needs to be confirmed some other way, never silently dropped.
558
+ * `navigator.clipboard` only exists in a secure context, so this falls back to
559
+ * an offscreen selection. Never call the browser API directly.
560
+ */
561
+ export function copyText(value: string): Promise<boolean>;
466
562
  /**
467
563
  * The DevEye version this interface was built from: what an agent's
468
564
  * reported version is compared against to offer a self-update.
@@ -127,8 +127,9 @@ export type NativeCapability =
127
127
  | 'live.publish'
128
128
  /**
129
129
  * Read accounts (id, email, username, creation date): the caller's own in a
130
- * handler, any account from a service. For what belongs to an account and
131
- * not to a workspace (a subscription, a receipt to address).
130
+ * handler, any account from a service, by id, by email or by search. For
131
+ * what belongs to an account and not to a workspace (a subscription, a
132
+ * receipt to address).
132
133
  */
133
134
  | 'accounts.read';
134
135
 
package/src/sdk/server.ts CHANGED
@@ -307,6 +307,13 @@ export interface SdkAccounts {
307
307
  find(userId: number): Promise<SdkAccount | null>;
308
308
  findByEmail(email: string): Promise<SdkAccount | null>;
309
309
  list(userIds: readonly number[]): Promise<readonly SdkAccount[]>;
310
+ /**
311
+ * Accounts whose username or email contains `query`, case-insensitively,
312
+ * by username. An all-digit query also matches that account id, listed
313
+ * first. An empty query returns the first accounts. `limit` defaults to 20
314
+ * and is capped at 50.
315
+ */
316
+ search(query: string, limit?: number): Promise<readonly SdkAccount[]>;
310
317
  }
311
318
 
312
319
  /**
@@ -901,6 +908,37 @@ export interface SdkRedeemedTicket {
901
908
 
902
909
  export type SdkPublicHandler = (req: SdkPublicRequest, reply: SdkPublicReply) => Promise<unknown>;
903
910
 
911
+ /**
912
+ * The body of a streamed route: never decoded, never buffered. The HOST counts
913
+ * the bytes and cuts the connection at `maxBytes`, so a module that forgets to
914
+ * count cannot open a bottomless pit.
915
+ */
916
+ export interface SdkPublicStreamBody {
917
+ /** The announced `Content-Length`, `null` when chunked. Unverified: compare it with what you read. */
918
+ contentLength: number | null;
919
+ /** The bytes, in order. Throws `FeatureError('validation')` past `maxBytes`. Consumable once. */
920
+ bytes(): AsyncIterable<Buffer>;
921
+ }
922
+
923
+ /** The request of a streamed route: the same, its decoded body replaced by its bytes. */
924
+ export interface SdkPublicStreamRequest extends Omit<SdkPublicRequest, 'body' | 'rawBody'> {
925
+ body: SdkPublicStreamBody;
926
+ }
927
+
928
+ export interface SdkPublicStreamRouteOptions {
929
+ /** Counts REQUESTS, not bytes: a 5 GiB upload is one request. Not what protects the disk. */
930
+ rateLimit?: { max: number; timeWindow: string };
931
+ /** Absolute ceiling of the body, enforced by the host. A per-account ceiling is yours to check on top. */
932
+ maxBytes: number;
933
+ /** Written, not defaulted: a route that swallows gigabytes never opens on the public listener by omission. */
934
+ exposure: 'app';
935
+ }
936
+
937
+ export type SdkPublicStreamHandler = (
938
+ req: SdkPublicStreamRequest,
939
+ reply: SdkPublicReply
940
+ ) => Promise<unknown>;
941
+
904
942
  /**
905
943
  * Where a module declares its public routes (capability `'routes.public'`).
906
944
  * Paths are absolute (`/t.js`, `/api/t/b`); a path the host already serves
@@ -909,6 +947,17 @@ export type SdkPublicHandler = (req: SdkPublicRequest, reply: SdkPublicReply) =>
909
947
  export interface SdkPublicApp {
910
948
  get(path: string, opts: SdkPublicRouteOptions, handler: SdkPublicHandler): void;
911
949
  post(path: string, opts: SdkPublicRouteOptions, handler: SdkPublicHandler): void;
950
+ /**
951
+ * A POST whose body is NOT decoded: the host hands it over as a bounded
952
+ * stream, whatever its content type. For what no parser should ever hold in
953
+ * full, an uploaded file. No path parameter, app origin only, and kept out
954
+ * of the CORS-widened paths: authenticate it with a ticket (`SdkSecrecy.ticket`).
955
+ */
956
+ postStream(
957
+ path: string,
958
+ opts: SdkPublicStreamRouteOptions,
959
+ handler: SdkPublicStreamHandler
960
+ ): void;
912
961
  }
913
962
 
914
963
  /**
@@ -67,6 +67,28 @@ test('createTestServiceDeps: one store per workspace, hand-driven tickers, a wra
67
67
  assert.equal((await deps.devicesFor(1).list()).length, 1);
68
68
  });
69
69
 
70
+ test('the harness searches accounts like the app: substring, exact id first, capped', async () => {
71
+ const account = (id: number, username: string) => ({
72
+ id,
73
+ username,
74
+ email: `${username}@example.com`,
75
+ isAdmin: false,
76
+ created: 0
77
+ });
78
+ const { accounts } = createTestServiceDeps({
79
+ accounts: [account(7, 'zoe'), account(12, 'Alice'), account(3, 'bob12')]
80
+ });
81
+ const ids = async (query: string, limit?: number) =>
82
+ (await accounts.search(query, limit)).map((a) => a.id);
83
+
84
+ assert.deepEqual(await ids(' '), [12, 3, 7], 'an empty query lists by username');
85
+ assert.deepEqual(await ids('aLiCe@EXAMPLE'), [12]);
86
+ assert.deepEqual(await ids('12'), [12, 3], 'the exact id comes before a substring hit');
87
+ assert.deepEqual(await ids('12abc'), []);
88
+ assert.deepEqual(await ids('', 1), [12]);
89
+ assert.equal((await ids('', 0)).length, 1, 'a limit below one is raised to one');
90
+ });
91
+
70
92
  test('the harness scopes domains to the workspace, and finds a host whatever its spelling', async () => {
71
93
  const domains = [
72
94
  testDomain({ id: 1, host: 'a.example.com' }),
@@ -673,7 +673,27 @@ export function createTestServiceDeps<Repo = undefined>(
673
673
  ) ?? null
674
674
  ),
675
675
  list: (userIds) =>
676
- Promise.resolve((overrides.accounts ?? []).filter((a) => userIds.includes(a.id)))
676
+ Promise.resolve((overrides.accounts ?? []).filter((a) => userIds.includes(a.id))),
677
+ search: (query, limit) => {
678
+ const needle = query.trim().toLowerCase();
679
+ const id = /^\d+$/.test(needle) ? Number(needle) : null;
680
+ const found = (overrides.accounts ?? [])
681
+ .filter(
682
+ (a) =>
683
+ needle === '' ||
684
+ a.id === id ||
685
+ a.username.toLowerCase().includes(needle) ||
686
+ a.email.toLowerCase().includes(needle)
687
+ )
688
+ .sort(
689
+ (a, b) =>
690
+ Number(b.id === id) - Number(a.id === id) ||
691
+ a.username.localeCompare(b.username)
692
+ );
693
+ return Promise.resolve(
694
+ found.slice(0, Math.min(Math.max(1, Math.trunc(limit ?? 20)), 50))
695
+ );
696
+ }
677
697
  },
678
698
  audit: (entry) => {
679
699
  recorded.audits.push({ action: entry.action, description: entry.description });