@deveye/types 0.18.3 → 0.19.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.
@@ -11,17 +11,18 @@ import { devicePlatformSchema, deviceSchema } from '../domain/device';
11
11
  * 4. The user confirms the device in the Clients page to activate it.
12
12
  */
13
13
 
14
- /** Hard cap on a custom code lifetime (30 days), to bound never-pruned rows. */
14
+ /**
15
+ * Hard cap on a code lifetime (30 days). A link code is a standing key to the
16
+ * workspace: it always expires.
17
+ */
15
18
  export const LINK_CODE_TTL_MAX_SECONDS = 30 * 24 * 60 * 60;
16
19
 
17
20
  /**
18
- * Request a new link code. `ttlSeconds`:
19
- * - omitted → server default lifetime,
20
- * - `null` → no expiry (valid until used or deleted),
21
- * - a number → custom lifetime in seconds.
21
+ * Request a new link code. `ttlSeconds` omitted → server default lifetime,
22
+ * otherwise a lifetime in seconds.
22
23
  */
23
24
  export const linkCodeRequestSchema = z.object({
24
- ttlSeconds: z.number().int().positive().max(LINK_CODE_TTL_MAX_SECONDS).nullable().optional(),
25
+ ttlSeconds: z.number().int().positive().max(LINK_CODE_TTL_MAX_SECONDS).optional(),
25
26
  /**
26
27
  * Approve the device the moment it enrols with this code, instead of
27
28
  * leaving it `pending` for manual approval. Defaults to `false`.
@@ -60,17 +61,20 @@ export const enrollDeviceRequestSchema = z.object({
60
61
  code: z.string().min(6).max(32),
61
62
  name: z.string().min(1).max(128),
62
63
  fingerprint: z.string().min(1).max(128),
63
- platform: devicePlatformSchema.default('linux'),
64
- /** X25519 public key (base64) for command signature verification. */
65
- publicKey: z.string().min(1).max(256)
64
+ platform: devicePlatformSchema.default('linux')
66
65
  });
67
66
 
68
67
  export type EnrollDeviceRequest = z.infer<typeof enrollDeviceRequestSchema>;
69
68
 
70
69
  export const enrollDeviceResponseSchema = z.object({
71
70
  deviceId: z.uuid(),
72
- /** Long-lived device token (JWT). Stored only on the agent. */
71
+ /** Device token (JWT), rotated by the server before it expires. Stored only on the agent. */
73
72
  deviceToken: z.string().min(1),
73
+ /**
74
+ * The server's order-signing public key (Ed25519, base64): the agent pins it
75
+ * and refuses any high-impact order that does not carry its signature.
76
+ */
77
+ orderSigningKey: z.string().length(44),
74
78
  device: deviceSchema
75
79
  });
76
80
 
package/src/index.ts CHANGED
@@ -183,12 +183,18 @@ export {
183
183
  packageListPushSchema,
184
184
  packageProgressPushSchema,
185
185
  packageStartedPushSchema,
186
+ AGENT_TOKEN_ROTATE,
187
+ agentTokenRotatePayloadSchema,
188
+ orderSignatureSchema,
189
+ SIGNED_AGENT_COMMANDS,
186
190
  syncIndexEntrySchema,
187
191
  syncShareAssignmentSchema
188
192
  } from './protocol/agent';
189
193
  export type {
190
194
  AgentClientMessage,
191
195
  AgentConfigPayload,
196
+ AgentTokenRotatePayload,
197
+ OrderSignature,
192
198
  AgentFilesAnalyzePayload,
193
199
  AgentFilesDownloadPayload,
194
200
  AgentFilesListPayload,
@@ -386,8 +392,21 @@ export type {
386
392
  FileSearchFilter,
387
393
  FileUsageEntry
388
394
  } from './domain/deviceFiles';
389
- export { projectStatusSchema } from './domain/project';
390
- export type { ProjectStatus } from './domain/project';
395
+ export {
396
+ itemProjectGroupSchema,
397
+ itemProjectSchema,
398
+ itemProjectsBlockerSchema,
399
+ itemProjectsStateSchema,
400
+ projectStatusSchema,
401
+ PROJECT_STATUS_LABELS
402
+ } from './domain/project';
403
+ export type {
404
+ ItemProject,
405
+ ItemProjectGroup,
406
+ ItemProjectsBlocker,
407
+ ItemProjectsState,
408
+ ProjectStatus
409
+ } from './domain/project';
391
410
  export { presenceEventSchema } from './domain/presence';
392
411
  export type { PresenceEvent, PresenceRow } from './domain/presence';
393
412
  export { userRoleSchema } from './domain/role';
@@ -553,6 +572,7 @@ export { packageManagerIdSchema, packageManagerSchema } from './domain/packages'
553
572
  export type { PackageManager, PackageManagerId } from './domain/packages';
554
573
  export {
555
574
  agentInfoSchema,
575
+ agentPolicySchema,
556
576
  agentServiceScopeSchema,
557
577
  AUTH_LOGIN_LIMIT,
558
578
  AUTH_SOURCE_LIMIT,
@@ -579,6 +599,7 @@ export {
579
599
  } from './domain/report';
580
600
  export type {
581
601
  AgentInfo,
602
+ AgentPolicy,
582
603
  AgentServiceScope,
583
604
  AuthLogin,
584
605
  AuthSource,
@@ -681,7 +702,12 @@ export {
681
702
  shareSet,
682
703
  sharingCommands
683
704
  } from './features/sharing';
684
- export { SHAREABLE_FEATURES, SHARE_WIRED_FEATURES } from './domain/featureRegistry';
705
+ export { linksCommands, projectLinksGet, projectLinksSet } from './features/links';
706
+ export {
707
+ PROJECT_LINKED_FEATURES,
708
+ SHAREABLE_FEATURES,
709
+ SHARE_WIRED_FEATURES
710
+ } from './domain/featureRegistry';
685
711
  export {
686
712
  DNS_RECORD_TYPES,
687
713
  FEATURE_DOMAIN_HOST_MAX,
@@ -733,16 +759,12 @@ export type {
733
759
  export {
734
760
  adminCommands,
735
761
  adminDeleteUser,
736
- adminInviteCreate,
737
- adminInviteList,
738
- adminInviteRevoke,
739
- adminInviteSchema,
740
762
  adminSetUserRole,
741
763
  adminSetUserStatus,
742
764
  adminUserList,
743
765
  adminUserSchema
744
766
  } from './features/admin';
745
- export type { AdminInvite, AdminUser } from './features/admin';
767
+ export type { AdminUser } from './features/admin';
746
768
  export {
747
769
  workspaceActivate,
748
770
  workspaceAdd,
@@ -766,7 +788,9 @@ export {
766
788
  THEME_SLOT_COUNT,
767
789
  THEME_SLOT_IMAGE_MAX_LENGTH,
768
790
  themeStateSchema,
791
+ accountPlanSchema,
769
792
  userCommands,
793
+ userPlan,
770
794
  userSetAvatar,
771
795
  userSetColor,
772
796
  userSetSetting,
@@ -831,6 +855,7 @@ export {
831
855
  secrecyHold,
832
856
  secrecyLock,
833
857
  secrecyRecover,
858
+ secrecyRegenerateRecovery,
834
859
  secrecySetReauth,
835
860
  secrecyStatus,
836
861
  secrecyTouch,
@@ -865,9 +890,17 @@ export {
865
890
  loginRequestSchema,
866
891
  loginResponseSchema,
867
892
  meResponseSchema,
893
+ passwordSchema,
868
894
  refreshResponseSchema,
869
- registerRequestSchema,
870
895
  sessionBundleSchema,
896
+ signupAvailabilitySchema,
897
+ signupCompleteRequestSchema,
898
+ signupCompleteResponseSchema,
899
+ signupStartRequestSchema,
900
+ signupStartResponseSchema,
901
+ signupStatusSchema,
902
+ signupVerifyRequestSchema,
903
+ signupVerifyResponseSchema,
871
904
  twoFactorChallengeRequestSchema
872
905
  } from './http/auth';
873
906
  export type {
@@ -877,8 +910,15 @@ export type {
877
910
  LoginResponse,
878
911
  MeResponse,
879
912
  RefreshResponse,
880
- RegisterRequest,
881
913
  SessionBundle,
914
+ SignupAvailability,
915
+ SignupCompleteRequest,
916
+ SignupCompleteResponse,
917
+ SignupStartRequest,
918
+ SignupStartResponse,
919
+ SignupStatus,
920
+ SignupVerifyRequest,
921
+ SignupVerifyResponse,
882
922
  TwoFactorChallengeRequest
883
923
  } from './http/auth';
884
924
  export {
@@ -580,6 +580,10 @@ export const AGENT_COLLECT = 'agent.collect' as const;
580
580
  export const AGENT_SCAN = 'agent.scan' as const;
581
581
  /** Push the per-device collection config (cadences + capture mode) to the agent. */
582
582
  export const AGENT_CONFIG = 'agent.config' as const;
583
+ /** Server → agent: a fresh device token replacing the one about to expire; the agent persists it. */
584
+ export const AGENT_TOKEN_ROTATE = 'agent.tokenRotate' as const;
585
+ export const agentTokenRotatePayloadSchema = z.object({ token: z.string().min(1).max(4096) });
586
+ export type AgentTokenRotatePayload = z.infer<typeof agentTokenRotatePayloadSchema>;
583
587
  /** Tell the agent to self-destruct (wipe its local config + binary) and exit. */
584
588
  export const AGENT_DESTROY = 'agent.destroy' as const;
585
589
  /** Tell the agent to download, verify and swap in a newer signed binary. */
@@ -1107,11 +1111,45 @@ export const agentServerMessageSchema = z.discriminatedUnion('command', [
1107
1111
  z.object({
1108
1112
  command: z.literal(AGENT_SYNC_DELETE),
1109
1113
  payload: agentSyncDeletePayloadSchema
1114
+ }),
1115
+ z.object({
1116
+ command: z.literal(AGENT_TOKEN_ROTATE),
1117
+ payload: agentTokenRotatePayloadSchema
1110
1118
  })
1111
1119
  ]);
1112
1120
 
1113
1121
  export type AgentServerMessage = z.infer<typeof agentServerMessageSchema>;
1114
1122
 
1123
+ /**
1124
+ * Signature of a high-impact order, carried next to `command` and `payload` as
1125
+ * `sig`. Ed25519 over `command \n nonce \n issuedAt \n` followed by the exact
1126
+ * bytes of the payload as sent. The agent verifies it against the key pinned at
1127
+ * enrolment, refuses an `issuedAt` more than five minutes off, and refuses a
1128
+ * nonce it has already seen.
1129
+ */
1130
+ export const orderSignatureSchema = z.object({
1131
+ nonce: z.string().length(32),
1132
+ issuedAt: z.number().int().positive(),
1133
+ signature: z.string().length(88)
1134
+ });
1135
+ export type OrderSignature = z.infer<typeof orderSignatureSchema>;
1136
+
1137
+ /**
1138
+ * The orders the server signs (`ORDER_SIGNING_KEY`) and the agent refuses
1139
+ * unsigned: what runs code, writes or deletes files, changes the agent's
1140
+ * privileges or its life. Mirror of `SIGNED_COMMANDS` in `agent/src/protocol.rs`.
1141
+ */
1142
+ export const SIGNED_AGENT_COMMANDS: ReadonlySet<string> = new Set([
1143
+ AGENT_TERM_OPEN,
1144
+ AGENT_FILES_MUTATE,
1145
+ AGENT_FILES_UPLOAD,
1146
+ AGENT_SERVICE,
1147
+ AGENT_POWER,
1148
+ AGENT_DESTROY,
1149
+ AGENT_PKG_UPGRADE,
1150
+ AGENT_LIFECYCLE
1151
+ ]);
1152
+
1115
1153
  /**
1116
1154
  * Server -> web client push events (no requestId), carried in the standard
1117
1155
  * ServerMessage envelope. These constants name those unsolicited events.
@@ -9,6 +9,9 @@ export const ErrorCodeSchema = z.enum([
9
9
  'conflict',
10
10
  'validation',
11
11
  'rate_limited',
12
+ // The account's plan does not allow one more of what the command creates.
13
+ // `details` carries `{ feature, key, limit, plan }`.
14
+ 'quota_exceeded',
12
15
  'internal',
13
16
  'unsupported_version',
14
17
  // Password-based encryption is enabled but the session has not yet been
@@ -31,7 +31,7 @@ declare module 'deveye-sdk-client' {
31
31
  User,
32
32
  WorkspaceCapability
33
33
  } from '@deveye/types';
34
- import type { FeatureManifest, ManifestCommand } from '@deveye/types/sdk';
34
+ import type { AccountPlan, FeatureManifest, ManifestCommand } from '@deveye/types/sdk';
35
35
  import type { SdkDeviceSummary } from '@deveye/types/sdk/client';
36
36
 
37
37
  // ── UI kit ─────────────────────────────────────────────────────────────
@@ -73,6 +73,31 @@ declare module 'deveye-sdk-client' {
73
73
  'aria-label'?: string;
74
74
  disabled?: boolean;
75
75
  }): ReactNode;
76
+ /**
77
+ * A single choice where each option explains itself: one card per option,
78
+ * label and consequences together. For two or three choices that commit
79
+ * the user; a harmless setting stays a `SegmentedControl`. A description
80
+ * may hold its own clickable elements without checking the card.
81
+ */
82
+ export function ChoiceCards<T extends string>(props: {
83
+ value: T;
84
+ options: readonly {
85
+ value: T;
86
+ label: string;
87
+ description: ReactNode;
88
+ /** Icon class (`icon-lock`...), shown next to the label. */
89
+ icon?: string;
90
+ /** Why the option is not offered: makes it inert, shown under the description. */
91
+ unavailable?: ReactNode;
92
+ }[];
93
+ onChange: (value: T) => void;
94
+ disabled?: boolean;
95
+ /** The choice being applied: its card says so, the others wait. */
96
+ pending?: T | null;
97
+ /** A pointer click on a card, the current choice included: for a choice that advances a step. */
98
+ onPick?: (value: T) => void;
99
+ 'aria-label'?: string;
100
+ }): ReactNode;
76
101
  /**
77
102
  * Le bouton d'enregistrement d'un panneau de réglages : « Enregistrement… »
78
103
  * pendant l'aller-retour, « Enregistré » quelques secondes, puis l'intitulé
@@ -135,6 +160,15 @@ declare module 'deveye-sdk-client' {
135
160
  body: ReactNode;
136
161
  width?: number;
137
162
  }): Promise<unknown>;
163
+ /** The technical terms the app's glossary defines. */
164
+ export type GlossaryTermId =
165
+ 'zeroKnowledge' | 'encryption' | 'twoFactor' | 'webhook' | 'imap' | 'smtp' | 'proxy';
166
+ /**
167
+ * A technical term inside a sentence: reads like the surrounding text and
168
+ * opens its plain-language definition on click. `children` is the term as
169
+ * the sentence spells it; it defaults to the definition's title.
170
+ */
171
+ export function Term(props: { id: GlossaryTermId; children?: ReactNode }): ReactNode;
138
172
  /** Request the enclosing Dialog's guarded close (the unsaved-changes prompt included). */
139
173
  export function useDialogClose(): () => void;
140
174
  /** Register `fn` as the enclosing Dialog's primary action (Enter triggers it); `null` clears it. */
@@ -423,6 +457,12 @@ declare module 'deveye-sdk-client' {
423
457
  /** Device paths as the agent reports them: Windows or POSIX, joined accordingly. */
424
458
  export function isWinPath(p: string): boolean;
425
459
  export function joinPath(base: string, name: string): string;
460
+ /**
461
+ * The `href` for a link whose address comes from data (a remote feed, another
462
+ * member's input, a probe): only http(s) and mailto come out, anything else is
463
+ * `undefined`. Use it on every `<a href>` you do not write yourself.
464
+ */
465
+ export function safeHref(url: string | null | undefined): string | undefined;
426
466
  /**
427
467
  * The DevEye version this interface was built from: what an agent's
428
468
  * reported version is compared against to offer a self-update.
@@ -436,6 +476,13 @@ declare module 'deveye-sdk-client' {
436
476
  export function httpGet<T>(path: string, outputSchema?: ZodType<T>): Promise<T>;
437
477
  /** Renews the access cookie before a raw `fetch` that bypasses the client (a download). */
438
478
  export function ensureFreshAccess(): Promise<void>;
479
+ /**
480
+ * The account's plan, kept live. `null` while loading AND when this DevEye
481
+ * has no plan provider (everything unlimited): never read it as "free".
482
+ */
483
+ export function useAccountPlan(): AccountPlan | null;
484
+ /** Opens an account view (`manifest.accountEntry`): the given module's, or the first one. No-op without any. */
485
+ export function openAccountView(featureId?: string): void;
439
486
  export interface LiveOutlineProps {
440
487
  'data-live-peer'?: true;
441
488
  style?: CSSProperties;
package/src/sdk/client.ts CHANGED
@@ -42,6 +42,15 @@ export interface FeatureViewProps {
42
42
  closeFeature(): void;
43
43
  }
44
44
 
45
+ /** Props of {@link FeatureClient.AccountView}. */
46
+ export interface AccountViewProps {
47
+ close(): void;
48
+ /** The viewer is a global administrator of this DevEye. */
49
+ isAdmin: boolean;
50
+ /** The hint a sign-up carried (`manifest.accountEntry.signupHint`), delivered once. */
51
+ hint?: string;
52
+ }
53
+
45
54
  /**
46
55
  * Your package's `./client` export.
47
56
  */
@@ -51,9 +60,11 @@ export interface FeatureClient {
51
60
  * data comes from `useResource`, so the card and the full view share one
52
61
  * cache and refresh together.
53
62
  */
54
- Widget: ComponentType;
55
- /** The full view, opened when the card expands. */
56
- Full: ComponentType<FeatureViewProps>;
63
+ Widget?: ComponentType;
64
+ /** The full view, opened when the card expands. Required with `Widget` unless `manifest.accountOnly`. */
65
+ Full?: ComponentType<FeatureViewProps>;
66
+ /** The view `manifest.accountEntry` opens from the user menu. */
67
+ AccountView?: ComponentType<AccountViewProps>;
57
68
  /**
58
69
  * The vignette shown on your card in the home grid's add market and on
59
70
  * your "About" sheet. Without one, the host draws a neutral module mark:
@@ -102,6 +113,38 @@ export interface FeatureClient {
102
113
  * Deliberately a subset of the module's own contract: what a linked-service
103
114
  * block needs, and nothing the module may want to change later.
104
115
  */
116
+ /**
117
+ * One figure of a project's dashboard tile. The module formats it, the host only
118
+ * places it: neither has to know the other's vocabulary.
119
+ */
120
+ export interface SdkTileMetric {
121
+ /** Stable key of the figure inside its tile, so the host never orders by accident. */
122
+ key: string;
123
+ label: string;
124
+ /** Already formatted by the module (« 1 240 », « 99,95 % », « il y a 3 h »). */
125
+ value: string;
126
+ /** What the theme must say of this value. Never a colour. */
127
+ tone?: 'neutral' | 'accent' | 'good' | 'warn' | 'bad';
128
+ }
129
+
130
+ /**
131
+ * What a module answers about ONE of its items, for a dashboard tile. Always one
132
+ * entry per id asked for, so the host never has to guess which one is missing.
133
+ */
134
+ export interface SdkTileSummary {
135
+ itemId: number;
136
+ /** The item's name; the host makes it the tile's heading. */
137
+ title: string;
138
+ /** Two or three figures, never more: a tile is not a screen. */
139
+ metrics: readonly SdkTileMetric[];
140
+ /**
141
+ * Why it cannot be measured, in one sentence (item gone, token revoked,
142
+ * monitoring off). The host shows it inside the tile and does NOT turn it
143
+ * into a screen error: a dashboard shows what it can.
144
+ */
145
+ unavailable?: string;
146
+ }
147
+
105
148
  export interface UptimeLinkedService {
106
149
  id: number;
107
150
  name: string;
@@ -160,6 +203,13 @@ export interface SdkDeviceSummary {
160
203
  export interface UptimeClientProvider {
161
204
  /** The workspace's services, as `uptime.list` returns them. */
162
205
  listServices(): Promise<readonly UptimeLinkedService[]>;
206
+ /**
207
+ * The given services, summarised for a project's dashboard tile. ONE round
208
+ * trip whatever their number: a dashboard that opened one per tile would
209
+ * cost far more than the figures are worth. An id the caller cannot read,
210
+ * or that is gone, comes back `unavailable`, never as a throw.
211
+ */
212
+ summarize(serviceIds: readonly number[]): Promise<readonly SdkTileSummary[]>;
163
213
  /**
164
214
  * A service's history for the strip. `stamp` is what re-reads it (pass
165
215
  * `service.lastCheckedAt`); no timer.
@@ -215,6 +265,13 @@ export interface DatabaseLinkedCandidate {
215
265
  export interface DatabaseClientProvider {
216
266
  /** The workspace's databases, as `database.list` returns them. */
217
267
  listDatabases(): Promise<readonly DatabaseLinkedCandidate[]>;
268
+ /**
269
+ * The given databases, summarised for a project's dashboard tile. ONE round
270
+ * trip whatever their number: a dashboard that opened one per tile would
271
+ * cost far more than the figures are worth. An id the caller cannot read,
272
+ * or that is gone, comes back `unavailable`, never as a throw.
273
+ */
274
+ summarize(databaseIds: readonly number[]): Promise<readonly SdkTileSummary[]>;
218
275
  /**
219
276
  * A database linked to a project, shown in full: header (name, address,
220
277
  * actions, its own settings button), state, alerts, table explorer. Loads
@@ -252,6 +309,13 @@ export interface DeployLinkedCandidate {
252
309
  export interface DeployClientProvider {
253
310
  /** The workspace's targets, as `deploy.list` returns them. */
254
311
  listTargets(): Promise<readonly DeployLinkedCandidate[]>;
312
+ /**
313
+ * The given targets, summarised for a project's dashboard tile. ONE round
314
+ * trip whatever their number: a dashboard that opened one per tile would
315
+ * cost far more than the figures are worth. An id the caller cannot read,
316
+ * or that is gone, comes back `unavailable`, never as a throw.
317
+ */
318
+ summarize(targetIds: readonly number[]): Promise<readonly SdkTileSummary[]>;
255
319
  /**
256
320
  * A target linked to a project, shown in full: identity, last deployment,
257
321
  * trigger, its own settings button. Loads itself by `deploy.get`, follows
@@ -292,6 +356,13 @@ export interface GitLinkedCandidate {
292
356
  export interface GitClientProvider {
293
357
  /** The workspace's repositories, as `git.repoList` returns them. */
294
358
  listRepos(): Promise<readonly GitLinkedCandidate[]>;
359
+ /**
360
+ * The given repositories, summarised for a project's dashboard tile. ONE round
361
+ * trip whatever their number: a dashboard that opened one per tile would
362
+ * cost far more than the figures are worth. An id the caller cannot read,
363
+ * or that is gone, comes back `unavailable`, never as a throw.
364
+ */
365
+ summarize(repoIds: readonly number[]): Promise<readonly SdkTileSummary[]>;
295
366
  /**
296
367
  * A repository linked to a project, shown in full: header (name, sync
297
368
  * state, actions, its own settings button), graph and panels. Loads
@@ -323,6 +394,13 @@ export interface AudienceLinkedCandidate {
323
394
  export interface AudienceClientProvider {
324
395
  /** The workspace's sites, as `audience.list` returns them. */
325
396
  listSites(): Promise<readonly AudienceLinkedCandidate[]>;
397
+ /**
398
+ * The given sites, summarised for a project's dashboard tile. ONE round
399
+ * trip whatever their number: a dashboard that opened one per tile would
400
+ * cost far more than the figures are worth. An id the caller cannot read,
401
+ * or that is gone, comes back `unavailable`, never as a throw.
402
+ */
403
+ summarize(siteIds: readonly number[]): Promise<readonly SdkTileSummary[]>;
326
404
  /**
327
405
  * A site linked to a project, shown in full: its sticky heading, actions
328
406
  * (install, its own settings button), stats, funnels. Loads itself by
@@ -133,3 +133,30 @@ test('validateManifest refuses a tab id it does not know', () => {
133
133
  /unknown settings tab/
134
134
  );
135
135
  });
136
+
137
+ test('validateManifest checks quotas and the account entry', () => {
138
+ const rejects = (patch: Partial<FeatureManifest>, fragment: string) =>
139
+ assert.throws(() => validateManifest({ ...base, ...patch }), new RegExp(fragment));
140
+ assert.doesNotThrow(() =>
141
+ validateManifest({
142
+ ...base,
143
+ quotas: [{ key: 'monitors', label: 'monitors' }],
144
+ accountEntry: { label: 'Subscription' },
145
+ accountOnly: true
146
+ })
147
+ );
148
+ rejects({ quotas: [{ key: 'Bad key', label: 'x' }] }, 'invalid quota key');
149
+ rejects(
150
+ {
151
+ quotas: [
152
+ { key: 'monitors', label: 'a' },
153
+ { key: 'monitors', label: 'b' }
154
+ ]
155
+ },
156
+ 'duplicate quota key'
157
+ );
158
+ rejects({ quotas: [{ key: 'monitors', label: ' ' }] }, 'empty label');
159
+ rejects({ accountOnly: true }, 'accountOnly requires accountEntry');
160
+ rejects({ accountOnly: true, accountEntry: { label: 'S' }, tile: {} }, 'no tile');
161
+ rejects({ accountEntry: { label: ' ' } }, 'requires a label');
162
+ });
@@ -59,6 +59,23 @@ export type ExtraPermissionSpec =
59
59
  ownerValue: string;
60
60
  };
61
61
 
62
+ /** Hard cap on `quotas`. */
63
+ export const MAX_FEATURE_QUOTAS = 8;
64
+
65
+ /**
66
+ * Something your feature creates that an account plan may bound (monitors,
67
+ * paired agents). You count, the host decides: see `SdkQuota`. Without a plan
68
+ * provider installed (a self-hosted DevEye), every quota is unlimited.
69
+ */
70
+ export interface FeatureQuotaSpec {
71
+ /** Same shape as an extra permission key. The plan names it `<featureId>.<key>`. */
72
+ key: string;
73
+ /** Plural noun, as a limit reads: "5 monitors". For `bytes`, what is measured: "of storage". */
74
+ label: string;
75
+ /** What the number counts. `bytes`: the host writes the limit as a size ("1 GB"). Default: things. */
76
+ unit?: 'bytes';
77
+ }
78
+
62
79
  /** Hard cap on `extraPermissions`: keeps role editors legible. */
63
80
  export const MAX_EXTRA_PERMISSIONS = 10;
64
81
 
@@ -107,7 +124,13 @@ export type NativeCapability =
107
124
  * of your own. Declared, because it lets a module put bytes on someone
108
125
  * else's socket without them asking. See `SdkLive.publish`.
109
126
  */
110
- | 'live.publish';
127
+ | 'live.publish'
128
+ /**
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).
132
+ */
133
+ | 'accounts.read';
111
134
 
112
135
  /**
113
136
  * Settings tabs the shell can render for you.
@@ -258,6 +281,23 @@ export interface FeatureManifest<Id extends FeatureId = FeatureId> {
258
281
  extraPermissions?: readonly ExtraPermissionSpec[];
259
282
  /** See {@link NativeCapability}. */
260
283
  nativeCapabilities?: readonly NativeCapability[];
284
+ /** See {@link FeatureQuotaSpec}. At most {@link MAX_FEATURE_QUOTAS}. */
285
+ quotas?: readonly FeatureQuotaSpec[];
286
+
287
+ /**
288
+ * An entry of the user menu, under "Security", drawn with the module's
289
+ * `icon` and opening `FeatureClient.AccountView`. For what belongs to the
290
+ * account, whatever the active workspace. `signupHint`: the view opens by itself right after
291
+ * a sign-up that carried a hint (`/signup?plan=…`), and receives it. One
292
+ * installed module at most may ask for it.
293
+ */
294
+ accountEntry?: { label: string; signupHint?: boolean };
295
+ /**
296
+ * The module lives in the user menu only: no card, no row in the roles
297
+ * screen, `Widget` and `Full` not required. Requires `accountEntry`, no
298
+ * items, and every command scoped to the account (`access.scope`).
299
+ */
300
+ accountOnly?: boolean;
261
301
 
262
302
  /**
263
303
  * Resource keys this feature owns, `<id>.<name>` (by convention, the
@@ -388,6 +428,25 @@ export function validateManifest(m: FeatureManifest): void {
388
428
  }
389
429
  }
390
430
 
431
+ const quotas = m.quotas ?? [];
432
+ if (quotas.length > MAX_FEATURE_QUOTAS) fail(m.id, `more than ${MAX_FEATURE_QUOTAS} quotas`);
433
+ const quotaKeys = new Set<string>();
434
+ for (const quota of quotas) {
435
+ if (!EXTRA_KEY_PATTERN.test(quota.key)) fail(m.id, `invalid quota key « ${quota.key} »`);
436
+ if (quotaKeys.has(quota.key)) fail(m.id, `duplicate quota key « ${quota.key} »`);
437
+ quotaKeys.add(quota.key);
438
+ if (!quota.label.trim()) fail(m.id, `quota « ${quota.key} »: empty label`);
439
+ }
440
+
441
+ if (m.accountEntry && !m.accountEntry.label.trim()) fail(m.id, 'accountEntry requires a label');
442
+ if (m.accountOnly) {
443
+ if (!m.accountEntry) fail(m.id, 'accountOnly requires accountEntry');
444
+ if (m.hasItems) fail(m.id, 'accountOnly modules own no items');
445
+ if (m.tile || m.topbarWidget || m.settings) {
446
+ fail(m.id, 'accountOnly modules have no tile, topbar widget or settings');
447
+ }
448
+ }
449
+
391
450
  const extras = m.extraPermissions ?? [];
392
451
  if (extras.length > MAX_EXTRA_PERMISSIONS) {
393
452
  fail(m.id, `more than ${MAX_EXTRA_PERMISSIONS} extra permissions`);