@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.
@@ -94,6 +94,39 @@ export interface DatabaseBackupProvider {
94
94
  * feature links to: same shape and reason as `UPTIME_ITEMS_PROVIDER`
95
95
  * (`project_database_links` is Projects' table).
96
96
  */
97
+ /**
98
+ * Key of the read-only measurement the Projects module consumes for its custom
99
+ * dashboard KPIs: the query goes through the SAME access as the monitoring (SSH
100
+ * tunnel or SOCKS proxy included), and only the Databases feature knows how to
101
+ * decrypt a connection.
102
+ */
103
+ export const DATABASE_MEASURE_PROVIDER = 'database.measure' as const;
104
+
105
+ /** One measured number, or the reason there is none. */
106
+ export interface DatabaseNumberOutcome {
107
+ value: number | null;
108
+ error: string | null;
109
+ }
110
+
111
+ export interface DatabaseMeasureProvider {
112
+ /**
113
+ * Measures read-only queries against a database visible from this
114
+ * workspace, in ONE session (tunnel included) whatever the number of
115
+ * queries: opening one per query would cost far more than the figures are
116
+ * worth.
117
+ *
118
+ * Each query must be a single read statement returning exactly one row and
119
+ * one column; one that is refused or faulty yields its error and does not
120
+ * interrupt the others, the way an alert's conditions behave. Answers
121
+ * `null`, never throws, when the database is not visible from there.
122
+ */
123
+ measure(
124
+ databaseId: number,
125
+ workspaceId: number,
126
+ queries: readonly string[]
127
+ ): Promise<readonly DatabaseNumberOutcome[] | null>;
128
+ }
129
+
97
130
  export const DATABASE_ITEMS_PROVIDER = 'database.items' as const;
98
131
 
99
132
  export interface DatabaseItemsProvider {
@@ -284,6 +317,21 @@ export interface ProjectUsage {
284
317
  status: 'draft' | 'active' | 'paused' | 'done';
285
318
  }
286
319
 
320
+ /**
321
+ * A project an item of another feature can be attached to, in ONE workspace.
322
+ * Open tier and at home only: a guarded project links nothing, and a link is
323
+ * posed in the project's own workspace, never through a projection of it.
324
+ */
325
+ export interface ProjectLinkTarget {
326
+ projectId: number;
327
+ title: string;
328
+ status: 'draft' | 'active' | 'paused' | 'done';
329
+ /** Filed away: listed only while it still links the item, so the link can be undone. */
330
+ archived: boolean;
331
+ /** This project already links the item asked about. */
332
+ linked: boolean;
333
+ }
334
+
287
335
  export interface ProjectsUsageProvider {
288
336
  /** The workspace's projects linking this item of this feature, in Projects' display order. */
289
337
  usageOf(feature: string, itemId: number, workspaceId: number): Promise<readonly ProjectUsage[]>;
@@ -301,6 +349,40 @@ export interface ProjectsUsageProvider {
301
349
  * and zero for a feature that links nothing.
302
350
  */
303
351
  detach(feature: string, itemId: number, workspaceId: number): Promise<number>;
352
+ /**
353
+ * The projects of ONE workspace an item of this feature can be attached to,
354
+ * each saying whether it already links it. What the app's settings shell
355
+ * lists on an item, workspace by workspace.
356
+ *
357
+ * Only projects living in that workspace at the open tier: a link is posed
358
+ * at the project's home, and a guarded project links nothing. Filed-away
359
+ * projects appear only while they still hold a link, so a dead link can be
360
+ * undone without unfiling the project.
361
+ *
362
+ * Empty for a feature this provider links nothing of, so a caller never has
363
+ * to know which features are linkable.
364
+ */
365
+ linkTargets(
366
+ feature: string,
367
+ itemId: number,
368
+ workspaceId: number
369
+ ): Promise<readonly ProjectLinkTarget[]>;
370
+ /**
371
+ * Attaches the item to one project of this workspace. Idempotent: the same
372
+ * link declared twice is the same fact, not an error.
373
+ *
374
+ * The caller owns the authorisation (`projects: write` in that workspace)
375
+ * and has checked the item is visible from there; this only refuses what
376
+ * its own tables cannot hold, silently: an unknown or projected project,
377
+ * and a guarded one.
378
+ */
379
+ link(feature: string, itemId: number, workspaceId: number, projectId: number): Promise<void>;
380
+ /**
381
+ * Drops that one link, and never touches the item itself. Idempotent.
382
+ * Unlike {@link ProjectsUsageProvider.detach}, which drops every link of an
383
+ * item that left the workspace, this answers one screen's single switch.
384
+ */
385
+ unlink(feature: string, itemId: number, workspaceId: number, projectId: number): Promise<void>;
304
386
  /**
305
387
  * Writes one line in a project's timeline (a deployment triggered from a
306
388
  * project's tab). Open tier only: an event aimed at a guarded project is
@@ -393,3 +475,23 @@ export interface SentinelAgentConfigProvider {
393
475
  /** The device's contribution, or null when Sentinel knows nothing about it (probes off). */
394
476
  configFor(deviceId: string): Promise<SentinelAgentConfig | null>;
395
477
  }
478
+
479
+ /**
480
+ * The plan of an account: what bounds the quotas modules declare
481
+ * (`manifest.quotas`). Offered by a billing module. WITHOUT it every quota is
482
+ * unlimited, which is what a self-hosted DevEye is.
483
+ */
484
+ export const ACCOUNT_PLAN_PROVIDER = 'account.plan';
485
+
486
+ export interface AccountPlan {
487
+ id: string;
488
+ label: string;
489
+ /** `<featureId>.<quotaKey>` to its maximum. An absent key is unlimited. */
490
+ limits: Readonly<Record<string, number>>;
491
+ /** The plan is a trial ending then (ms since the epoch). */
492
+ trialEndsAt?: number;
493
+ }
494
+
495
+ export interface AccountPlanProvider {
496
+ planFor(userId: number): Promise<AccountPlan>;
497
+ }
package/src/sdk/server.ts CHANGED
@@ -283,6 +283,51 @@ export interface DevEyeFacade {
283
283
  telemetry: SdkTelemetry;
284
284
  /** Requires capability `'agents'`. Same object as the service deps' `agents`. */
285
285
  agents: AgentsFacade;
286
+ /** Requires capability `'accounts.read'`. */
287
+ accounts: {
288
+ /** The CALLER's own account, never someone else's. */
289
+ me(): Promise<SdkAccount>;
290
+ };
291
+ }
292
+
293
+ /** An account of this DevEye, as `'accounts.read'` shows it. */
294
+ export interface SdkAccount {
295
+ id: number;
296
+ email: string;
297
+ username: string;
298
+ /** A global administrator of this DevEye. */
299
+ isAdmin: boolean;
300
+ /** Milliseconds since the epoch. */
301
+ created: number;
302
+ }
303
+
304
+ /** Any account, sessionless (capability `'accounts.read'`), for services. */
305
+ export interface SdkAccounts {
306
+ find(userId: number): Promise<SdkAccount | null>;
307
+ findByEmail(email: string): Promise<SdkAccount | null>;
308
+ list(userIds: readonly number[]): Promise<readonly SdkAccount[]>;
309
+ }
310
+
311
+ /**
312
+ * What the account's plan allows of YOUR `manifest.quotas`. The account is the
313
+ * OWNER of the workspace of the call: in a shared workspace, what a member
314
+ * creates counts against its owner. Without a plan provider installed,
315
+ * everything is unlimited.
316
+ */
317
+ export interface SdkQuota {
318
+ /** `null` = unlimited. An undeclared key throws `validation`. */
319
+ limit(key: string): Promise<number | null>;
320
+ /**
321
+ * Call it BEFORE creating. `countAfter` receives the ids of every workspace
322
+ * the owner account owns and returns how many there would be once created;
323
+ * it is never called when unlimited. Throws `quota_exceeded` beyond the
324
+ * limit. Only creation is bounded: what exists stays usable after a
325
+ * downgrade.
326
+ */
327
+ assert(
328
+ key: string,
329
+ countAfter: (ownerWorkspaceIds: readonly number[]) => Promise<number>
330
+ ): Promise<void>;
286
331
  }
287
332
 
288
333
  /** A workspace as the fleet sees it: enough to attach a device to it. */
@@ -418,14 +463,20 @@ export interface SdkProviders {
418
463
  }
419
464
 
420
465
  /**
421
- * Raw bytes under the SERVER key (the `Encryption.encryptWithKey` wire format,
422
- * byte-compatible with what native code wrote). For wrapping module-owned key
423
- * material; never for user data, which goes through ciphers and the store.
466
+ * Raw bytes under the SERVER key, for wrapping module-owned key material; never
467
+ * for user data, which goes through ciphers and the store. The host seals under
468
+ * a sub-key of its own for each module: a blob sealed by one module never opens
469
+ * in another, nor as one of the app's own sealed keys.
424
470
  */
425
471
  export interface SdkServerKeys {
426
- sealBytes(plain: Uint8Array): string;
427
- /** null when the sealed blob cannot be opened (tampered, or server keys changed). */
428
- openBytes(sealed: string): Uint8Array | null;
472
+ /**
473
+ * `context` binds the blob to the row it belongs to (authenticated, not
474
+ * stored): pass the same string to `openBytes`. Recommended shape
475
+ * `<table>:<column>:<id>`, so a blob copied onto another row does not open.
476
+ */
477
+ sealBytes(plain: Uint8Array, context?: string): string;
478
+ /** null when the sealed blob cannot be opened (tampered, wrong context, or server keys changed). */
479
+ openBytes(sealed: string, context?: string): Uint8Array | null;
429
480
  /**
430
481
  * A key DERIVED from the server key (HKDF-SHA256 over the same material
431
482
  * as `sealBytes`), never stored anywhere. For material that must survive
@@ -481,9 +532,10 @@ export interface SdkSecrecy {
481
532
  export interface SdkItems {
482
533
  /**
483
534
  * The items the caller's role sees differently from the others: `'none'`
484
- * hidden, `'read'` read-only. Restrictive only: it can lower what the
485
- * feature grants, never raise it. Empty for the owner and for a member
486
- * without a role. Listings filter with it.
535
+ * hidden, `'read'` read-only, `'write'` writable where the feature grants
536
+ * reading only. An override REPLACES what the feature gives, in both
537
+ * directions. Empty for the owner and for a member without a role.
538
+ * Listings filter with it.
487
539
  */
488
540
  restrictions(): Promise<ReadonlyMap<string, ItemAccess>>;
489
541
  /**
@@ -492,6 +544,13 @@ export interface SdkItems {
492
544
  * item call it first.
493
545
  */
494
546
  assert(itemId: string, level?: FeatureAccess): Promise<void>;
547
+ /**
548
+ * Does the caller hold this extra permission ON THIS ITEM: the item's
549
+ * override when it carries one, the role's grant otherwise. For a guard
550
+ * that covers only part of a command (the dates of a card, say). A command
551
+ * gated as a whole declares `access.extras` and needs nothing here.
552
+ */
553
+ canExtra(itemId: string, key: string): Promise<boolean>;
495
554
  /**
496
555
  * The item no longer exists: drops its projections, its role restrictions
497
556
  * and its notification route. Call it from your delete handler; nothing
@@ -567,6 +626,8 @@ export interface SdkLive {
567
626
  * is never attached, so it can never be mistaken for a reply.
568
627
  */
569
628
  publish(workspaceId: number, event: string, payload: unknown): void;
629
+ /** {@link SdkContextLive.accountChanged}, from a service (a webhook, a ticker). */
630
+ accountChanged(userId: number): void;
570
631
  }
571
632
 
572
633
  /**
@@ -577,6 +638,12 @@ export interface SdkLive {
577
638
  export interface SdkContextLive {
578
639
  /** {@link SdkLive.publish}, in the workspace of the call. */
579
640
  publish(event: string, payload: unknown): void;
641
+ /**
642
+ * Something of this ACCOUNT changed (its plan, its subscription): its open
643
+ * clients, in whatever workspace they sit, re-fetch the account plan and
644
+ * your declared resources. No payload, so no capability.
645
+ */
646
+ accountChanged(userId: number): void;
580
647
  }
581
648
 
582
649
  /** The whole fleet, sessionless (capability `'devices.read'`), for services. */
@@ -689,6 +756,7 @@ export interface SdkFeatureContext<Repo = unknown> {
689
756
  secrecy: SdkSecrecy;
690
757
  /** Your items as the roles see them (restrictions), and their removal bookkeeping. */
691
758
  items: SdkItems;
759
+ quota: SdkQuota;
692
760
  /** Projections into the active workspace. Throws `forbidden` when the manifest says `shareTier: 'never'`. */
693
761
  sharing: SdkSharing;
694
762
  /** Your feature's domains in this workspace (manifest `domains`). */
@@ -739,8 +807,16 @@ export interface SdkFeatureDefinition<
739
807
  * `admin`: the caller must be a global administrator; the feature check
740
808
  * still applies. Your feature id is implied: you cannot gate on another
741
809
  * feature's rights.
810
+ * `scope: 'account'`: the command acts on the caller's ACCOUNT, not on a
811
+ * workspace. The host runs it in the caller's personal workspace whatever
812
+ * the client sent, so the role held in a shared workspace never decides.
742
813
  */
743
- access?: { level?: FeatureAccess; extras?: readonly string[]; admin?: boolean };
814
+ access?: {
815
+ level?: FeatureAccess;
816
+ extras?: readonly string[];
817
+ admin?: boolean;
818
+ scope?: 'account';
819
+ };
744
820
  /**
745
821
  * This command changes data other members can see. `true` beats your
746
822
  * feature's own live topic (its id); a list names the topics to beat
@@ -764,6 +840,12 @@ export interface SdkPublicRequest {
764
840
  headers: Readonly<Record<string, string | string[] | undefined>>;
765
841
  /** The JSON body, already decoded (`undefined` when absent or unreadable). */
766
842
  body: unknown;
843
+ /**
844
+ * The body exactly as received, on a route that asked for it
845
+ * (`SdkPublicRouteOptions.rawBody`). What a webhook signature is computed
846
+ * over: re-serialising `body` would not give the same bytes.
847
+ */
848
+ rawBody?: string;
767
849
  /**
768
850
  * The query string, decoded by the host into an object (`?a=1&b=2` reads
769
851
  * `{ a: '1', b: '2' }`). `unknown` like `body`: read it through a schema.
@@ -803,6 +885,8 @@ export interface SdkPublicRouteOptions {
803
885
  * callback that lands back in the app).
804
886
  */
805
887
  exposure?: 'everywhere' | 'app';
888
+ /** Also hand the handler the undecoded body (`SdkPublicRequest.rawBody`). JSON bodies only. */
889
+ rawBody?: boolean;
806
890
  }
807
891
 
808
892
  /** What a redeemed ticket gives a public route back (see `SdkSecrecy.ticket`). */
@@ -866,6 +950,14 @@ export interface FeatureServiceDeps<Repo = unknown> {
866
950
  devicesFor(workspaceId: number): Pick<DevEyeFacade['devices'], 'list' | 'isOnline'>;
867
951
  /** The whole fleet by id, sessionless (capability `'devices.read'`). */
868
952
  devices: SdkFleetDevices;
953
+ /** Capability `'accounts.read'`. */
954
+ accounts: SdkAccounts;
955
+ /**
956
+ * {@link SdkQuota} for a workspace, sessionless: for what gets created
957
+ * outside any command (bytes an agent uploads). Same account rule, the
958
+ * owner of that workspace.
959
+ */
960
+ quotaFor(workspaceId: number): SdkQuota;
869
961
  /** The devices' telemetry, sessionless (capability `'telemetry.read'`). */
870
962
  telemetry: SdkTelemetry;
871
963
  /** Live invalidation of your feature's resources, from a service. */
@@ -92,3 +92,25 @@ test('the harness scopes domains to the workspace, and finds a host whatever its
92
92
  assert.deepEqual(await hooks.dns.txt('x'), ['v=spf1']);
93
93
  assert.deepEqual(await hooks.dns.mx('x'), []);
94
94
  });
95
+
96
+ test('the harness bounds a quota like the app: never counted when unlimited, refused past the limit', async () => {
97
+ let counted = 0;
98
+ const count = (ids: readonly number[]) => {
99
+ counted++;
100
+ return Promise.resolve(ids.length + 2);
101
+ };
102
+ const free = createTestContext();
103
+ await free.quota.assert('monitors', count);
104
+ assert.equal(counted, 0);
105
+
106
+ const bounded = createTestContext({ quotaLimits: { monitors: 3 }, ownerWorkspaceIds: [1, 2] });
107
+ await assert.rejects(bounded.quota.assert('monitors', count), /quota/);
108
+ await createTestContext({
109
+ quotaLimits: { monitors: 4 },
110
+ ownerWorkspaceIds: [1, 2]
111
+ }).quota.assert('monitors', count);
112
+ assert.equal(await bounded.quota.limit('monitors'), 3);
113
+
114
+ bounded.live.accountChanged(7);
115
+ assert.deepEqual(bounded.recorded.accountChanges, [7]);
116
+ });
@@ -10,6 +10,7 @@ import {
10
10
  type SdkDomain,
11
11
  type FeatureServiceDeps,
12
12
  type FeatureStore,
13
+ type SdkAccount,
13
14
  type SdkCipher,
14
15
  type SdkDevice,
15
16
  type SdkFeatureContext,
@@ -115,6 +116,8 @@ export interface RecordedCalls {
115
116
  pinnedInstants: { deviceId: string; ts: number }[];
116
117
  /** Frames pushed through `live.publish`, in order. */
117
118
  livePublishes: { workspaceId: number; event: string; payload: unknown }[];
119
+ /** Accounts beaten through `live.accountChanged`, in order. */
120
+ accountChanges: number[];
118
121
  }
119
122
 
120
123
  function recordingNotify(
@@ -276,6 +279,12 @@ export interface TestContextOverrides<Repo> {
276
279
  isAdmin?: boolean;
277
280
  /** What `deveye.workspaces.list()` answers. Default none. */
278
281
  workspaces?: readonly SdkWorkspaceSummary[];
282
+ /** What `deveye.accounts.me()` answers. Default: an account named after `userId`. */
283
+ account?: SdkAccount;
284
+ /** The plan's limits, by YOUR quota key. An absent key is unlimited. Default none. */
285
+ quotaLimits?: Record<string, number>;
286
+ /** The workspaces the owner account owns, handed to a quota counter. Default: the workspace of the call. */
287
+ ownerWorkspaceIds?: readonly number[];
279
288
  canWrite?: boolean;
280
289
  /** Extra permissions the caller holds, as the grant would carry them. */
281
290
  extras?: Record<string, boolean | string>;
@@ -308,6 +317,11 @@ export interface TestContextOverrides<Repo> {
308
317
  unlocked?: boolean;
309
318
  /** The caller's role restrictions on items, by item id. Default none. */
310
319
  itemRestrictions?: Readonly<Record<string, ItemAccess>>;
320
+ /**
321
+ * Extra permissions overridden on one item, by item id then key. What
322
+ * `items.canExtra` answers there; elsewhere it follows `extras`.
323
+ */
324
+ itemExtras?: Readonly<Record<string, Readonly<Record<string, boolean>>>>;
311
325
  /**
312
326
  * Items projected INTO the workspace, as `itemId → home workspace id`.
313
327
  * Default none: every item is at home. `sharing.scope().cipherFor` is the
@@ -329,7 +343,8 @@ export function createTestContext<Repo = undefined>(
329
343
  audits: [],
330
344
  agentRequests: [],
331
345
  pinnedInstants: [],
332
- livePublishes: []
346
+ livePublishes: [],
347
+ accountChanges: []
333
348
  };
334
349
  const isOwner = overrides.isOwner ?? true;
335
350
  const workspaceId = overrides.workspaceId ?? 1;
@@ -352,11 +367,28 @@ export function createTestContext<Repo = undefined>(
352
367
  devices: recordingDevices(overrides.devices ?? []),
353
368
  telemetry: recordingTelemetry(recorded, overrides.snapshots ?? []),
354
369
  agents: recordingAgents(recorded),
370
+ accounts: {
371
+ me: () =>
372
+ Promise.resolve(
373
+ overrides.account ?? {
374
+ id: overrides.userId ?? 1,
375
+ email: `user${overrides.userId ?? 1}@deveye.test`,
376
+ username: `user${overrides.userId ?? 1}`,
377
+ isAdmin: overrides.isAdmin ?? false,
378
+ created: 0
379
+ }
380
+ )
381
+ },
355
382
  ...overrides.deveye
356
383
  };
357
384
  const restrictions = new Map<string, ItemAccess>(
358
385
  Object.entries(overrides.itemRestrictions ?? {})
359
386
  );
387
+ const extras = resolveExtras(
388
+ overrides.manifest?.extraPermissions,
389
+ isOwner,
390
+ overrides.extras ?? {}
391
+ );
360
392
  const homes = new Map<string, number>(Object.entries(overrides.shares ?? {}));
361
393
  const forgotten: string[] = [];
362
394
  const orders: { itemId: string; order: number }[] = [];
@@ -380,6 +412,25 @@ export function createTestContext<Repo = undefined>(
380
412
  live: {
381
413
  publish(event, payload) {
382
414
  recorded.livePublishes.push({ workspaceId, event, payload });
415
+ },
416
+ accountChanged(userId) {
417
+ recorded.accountChanges.push(userId);
418
+ }
419
+ },
420
+ quota: {
421
+ limit: (key) => Promise.resolve(overrides.quotaLimits?.[key] ?? null),
422
+ // The exact rule of the app: never counted when unlimited, refused
423
+ // once the count AFTER creation passes the limit.
424
+ async assert(key, countAfter) {
425
+ const limit = overrides.quotaLimits?.[key];
426
+ if (limit === undefined) return;
427
+ const count = await countAfter(overrides.ownerWorkspaceIds ?? [workspaceId]);
428
+ if (count > limit) {
429
+ throw new FeatureError('quota_exceeded', `quota « ${key} » reached`, {
430
+ key,
431
+ limit
432
+ });
433
+ }
383
434
  }
384
435
  },
385
436
  items: {
@@ -399,6 +450,11 @@ export function createTestContext<Repo = undefined>(
399
450
  }
400
451
  return Promise.resolve();
401
452
  },
453
+ canExtra(itemId, key) {
454
+ return Promise.resolve(
455
+ overrides.itemExtras?.[itemId]?.[key] ?? extras.canExtra(key)
456
+ );
457
+ },
402
458
  forget(itemId) {
403
459
  forgotten.push(itemId);
404
460
  return Promise.resolve();
@@ -426,7 +482,7 @@ export function createTestContext<Repo = undefined>(
426
482
  isOwner,
427
483
  isAdmin: overrides.isAdmin ?? false,
428
484
  canWrite: overrides.canWrite ?? true,
429
- ...resolveExtras(overrides.manifest?.extraPermissions, isOwner, overrides.extras ?? {}),
485
+ ...extras,
430
486
  repo: overrides.repo as Repo,
431
487
  store: memoryStore(),
432
488
  cipher: (mode) =>
@@ -487,6 +543,10 @@ export interface TestServiceOverrides<Repo> {
487
543
  workspaceIds?: readonly number[];
488
544
  /** Devices every workspace reveals. Default none. */
489
545
  devices?: readonly SdkDevice[];
546
+ /** The accounts `deps.accounts` knows. Default none. */
547
+ accounts?: readonly SdkAccount[];
548
+ /** The plan's limits `deps.quotaFor` applies, by YOUR quota key. Default none (unlimited). */
549
+ quotaLimits?: Record<string, number>;
490
550
  /** What `deveyeFor(...).notify.hasRoute` answers. Default true. */
491
551
  hasRoute?: boolean;
492
552
  /** What `deveyeFor(...).notify.send` resolves. Default true; recorded either way. */
@@ -518,6 +578,7 @@ export function createTestServiceDeps<Repo = undefined>(
518
578
  agentRequests: [],
519
579
  pinnedInstants: [],
520
580
  livePublishes: [],
581
+ accountChanges: [],
521
582
  tickers: [],
522
583
  liveChanges: [],
523
584
  liveTopicChanges: []
@@ -584,8 +645,36 @@ export function createTestServiceDeps<Repo = undefined>(
584
645
  },
585
646
  publish(workspaceId, event, payload) {
586
647
  recorded.livePublishes.push({ workspaceId, event, payload });
648
+ },
649
+ accountChanged(userId) {
650
+ recorded.accountChanges.push(userId);
587
651
  }
588
652
  },
653
+ quotaFor: () => ({
654
+ limit: (key) => Promise.resolve(overrides.quotaLimits?.[key] ?? null),
655
+ async assert(key, countAfter) {
656
+ const limit = overrides.quotaLimits?.[key];
657
+ if (limit === undefined) return;
658
+ if ((await countAfter(overrides.workspaceIds ?? [1])) > limit) {
659
+ throw new FeatureError('quota_exceeded', `quota « ${key} » reached`, {
660
+ key,
661
+ limit
662
+ });
663
+ }
664
+ }
665
+ }),
666
+ accounts: {
667
+ find: (userId) =>
668
+ Promise.resolve((overrides.accounts ?? []).find((a) => a.id === userId) ?? null),
669
+ findByEmail: (email) =>
670
+ Promise.resolve(
671
+ (overrides.accounts ?? []).find(
672
+ (a) => a.email === email.trim().toLowerCase()
673
+ ) ?? null
674
+ ),
675
+ list: (userIds) =>
676
+ Promise.resolve((overrides.accounts ?? []).filter((a) => userIds.includes(a.id)))
677
+ },
589
678
  audit: (entry) => {
590
679
  recorded.audits.push({ action: entry.action, description: entry.description });
591
680
  },