@deveye/types 0.18.3 → 0.19.1

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.
Files changed (40) hide show
  1. package/package.json +1 -1
  2. package/src/domain/device.ts +6 -2
  3. package/src/domain/featureRegistry.ts +16 -0
  4. package/src/domain/home.ts +5 -3
  5. package/src/domain/live.ts +3 -3
  6. package/src/domain/project.ts +56 -0
  7. package/src/domain/remoteInstance.test.ts +35 -0
  8. package/src/domain/remoteInstance.ts +70 -0
  9. package/src/domain/report.ts +34 -2
  10. package/src/domain/secrecy.ts +3 -0
  11. package/src/domain/sharing.ts +46 -1
  12. package/src/domain/twoFactor.ts +7 -3
  13. package/src/domain/workspace.ts +1 -1
  14. package/src/domain/workspaceRole.ts +1 -1
  15. package/src/features/admin.ts +1 -51
  16. package/src/features/home.ts +1 -1
  17. package/src/features/links.ts +37 -0
  18. package/src/features/registry.ts +4 -0
  19. package/src/features/remote.ts +52 -0
  20. package/src/features/secrecy.ts +22 -8
  21. package/src/features/sharing.ts +78 -2
  22. package/src/features/twoFactor.ts +1 -1
  23. package/src/features/user.ts +32 -4
  24. package/src/features/workspace.ts +2 -2
  25. package/src/http/auth.ts +113 -15
  26. package/src/http/device.ts +14 -10
  27. package/src/http/status.ts +2 -0
  28. package/src/index.ts +89 -12
  29. package/src/protocol/agent.ts +38 -0
  30. package/src/protocol/error.ts +3 -0
  31. package/src/sdk/client-ambient.d.ts +60 -5
  32. package/src/sdk/client.ts +81 -3
  33. package/src/sdk/copy.test.ts +374 -0
  34. package/src/sdk/copy.ts +435 -0
  35. package/src/sdk/manifest.test.ts +27 -0
  36. package/src/sdk/manifest.ts +60 -1
  37. package/src/sdk/providers.ts +102 -0
  38. package/src/sdk/server.ts +188 -10
  39. package/src/sdk/testing.test.ts +22 -0
  40. package/src/sdk/testing.ts +91 -2
package/src/sdk/server.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { ItemTree, ItemTreeRows } from './copy';
1
2
  import type { z, ZodType } from 'zod';
2
3
  import type { ErrorCode } from '../protocol/error';
3
4
  import type { FeatureAccess } from '../domain/workspaceRole';
@@ -283,6 +284,51 @@ export interface DevEyeFacade {
283
284
  telemetry: SdkTelemetry;
284
285
  /** Requires capability `'agents'`. Same object as the service deps' `agents`. */
285
286
  agents: AgentsFacade;
287
+ /** Requires capability `'accounts.read'`. */
288
+ accounts: {
289
+ /** The CALLER's own account, never someone else's. */
290
+ me(): Promise<SdkAccount>;
291
+ };
292
+ }
293
+
294
+ /** An account of this DevEye, as `'accounts.read'` shows it. */
295
+ export interface SdkAccount {
296
+ id: number;
297
+ email: string;
298
+ username: string;
299
+ /** A global administrator of this DevEye. */
300
+ isAdmin: boolean;
301
+ /** Milliseconds since the epoch. */
302
+ created: number;
303
+ }
304
+
305
+ /** Any account, sessionless (capability `'accounts.read'`), for services. */
306
+ export interface SdkAccounts {
307
+ find(userId: number): Promise<SdkAccount | null>;
308
+ findByEmail(email: string): Promise<SdkAccount | null>;
309
+ list(userIds: readonly number[]): Promise<readonly SdkAccount[]>;
310
+ }
311
+
312
+ /**
313
+ * What the account's plan allows of YOUR `manifest.quotas`. The account is the
314
+ * OWNER of the workspace of the call: in a shared workspace, what a member
315
+ * creates counts against its owner. Without a plan provider installed,
316
+ * everything is unlimited.
317
+ */
318
+ export interface SdkQuota {
319
+ /** `null` = unlimited. An undeclared key throws `validation`. */
320
+ limit(key: string): Promise<number | null>;
321
+ /**
322
+ * Call it BEFORE creating. `countAfter` receives the ids of every workspace
323
+ * the owner account owns and returns how many there would be once created;
324
+ * it is never called when unlimited. Throws `quota_exceeded` beyond the
325
+ * limit. Only creation is bounded: what exists stays usable after a
326
+ * downgrade.
327
+ */
328
+ assert(
329
+ key: string,
330
+ countAfter: (ownerWorkspaceIds: readonly number[]) => Promise<number>
331
+ ): Promise<void>;
286
332
  }
287
333
 
288
334
  /** A workspace as the fleet sees it: enough to attach a device to it. */
@@ -418,14 +464,20 @@ export interface SdkProviders {
418
464
  }
419
465
 
420
466
  /**
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.
467
+ * Raw bytes under the SERVER key, for wrapping module-owned key material; never
468
+ * for user data, which goes through ciphers and the store. The host seals under
469
+ * a sub-key of its own for each module: a blob sealed by one module never opens
470
+ * in another, nor as one of the app's own sealed keys.
424
471
  */
425
472
  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;
473
+ /**
474
+ * `context` binds the blob to the row it belongs to (authenticated, not
475
+ * stored): pass the same string to `openBytes`. Recommended shape
476
+ * `<table>:<column>:<id>`, so a blob copied onto another row does not open.
477
+ */
478
+ sealBytes(plain: Uint8Array, context?: string): string;
479
+ /** null when the sealed blob cannot be opened (tampered, wrong context, or server keys changed). */
480
+ openBytes(sealed: string, context?: string): Uint8Array | null;
429
481
  /**
430
482
  * A key DERIVED from the server key (HKDF-SHA256 over the same material
431
483
  * as `sealBytes`), never stored anywhere. For material that must survive
@@ -481,9 +533,10 @@ export interface SdkSecrecy {
481
533
  export interface SdkItems {
482
534
  /**
483
535
  * 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.
536
+ * hidden, `'read'` read-only, `'write'` writable where the feature grants
537
+ * reading only. An override REPLACES what the feature gives, in both
538
+ * directions. Empty for the owner and for a member without a role.
539
+ * Listings filter with it.
487
540
  */
488
541
  restrictions(): Promise<ReadonlyMap<string, ItemAccess>>;
489
542
  /**
@@ -492,6 +545,13 @@ export interface SdkItems {
492
545
  * item call it first.
493
546
  */
494
547
  assert(itemId: string, level?: FeatureAccess): Promise<void>;
548
+ /**
549
+ * Does the caller hold this extra permission ON THIS ITEM: the item's
550
+ * override when it carries one, the role's grant otherwise. For a guard
551
+ * that covers only part of a command (the dates of a card, say). A command
552
+ * gated as a whole declares `access.extras` and needs nothing here.
553
+ */
554
+ canExtra(itemId: string, key: string): Promise<boolean>;
495
555
  /**
496
556
  * The item no longer exists: drops its projections, its role restrictions
497
557
  * and its notification route. Call it from your delete handler; nothing
@@ -567,6 +627,8 @@ export interface SdkLive {
567
627
  * is never attached, so it can never be mistaken for a reply.
568
628
  */
569
629
  publish(workspaceId: number, event: string, payload: unknown): void;
630
+ /** {@link SdkContextLive.accountChanged}, from a service (a webhook, a ticker). */
631
+ accountChanged(userId: number): void;
570
632
  }
571
633
 
572
634
  /**
@@ -577,6 +639,12 @@ export interface SdkLive {
577
639
  export interface SdkContextLive {
578
640
  /** {@link SdkLive.publish}, in the workspace of the call. */
579
641
  publish(event: string, payload: unknown): void;
642
+ /**
643
+ * Something of this ACCOUNT changed (its plan, its subscription): its open
644
+ * clients, in whatever workspace they sit, re-fetch the account plan and
645
+ * your declared resources. No payload, so no capability.
646
+ */
647
+ accountChanged(userId: number): void;
580
648
  }
581
649
 
582
650
  /** The whole fleet, sessionless (capability `'devices.read'`), for services. */
@@ -689,6 +757,7 @@ export interface SdkFeatureContext<Repo = unknown> {
689
757
  secrecy: SdkSecrecy;
690
758
  /** Your items as the roles see them (restrictions), and their removal bookkeeping. */
691
759
  items: SdkItems;
760
+ quota: SdkQuota;
692
761
  /** Projections into the active workspace. Throws `forbidden` when the manifest says `shareTier: 'never'`. */
693
762
  sharing: SdkSharing;
694
763
  /** Your feature's domains in this workspace (manifest `domains`). */
@@ -739,8 +808,16 @@ export interface SdkFeatureDefinition<
739
808
  * `admin`: the caller must be a global administrator; the feature check
740
809
  * still applies. Your feature id is implied: you cannot gate on another
741
810
  * feature's rights.
811
+ * `scope: 'account'`: the command acts on the caller's ACCOUNT, not on a
812
+ * workspace. The host runs it in the caller's personal workspace whatever
813
+ * the client sent, so the role held in a shared workspace never decides.
742
814
  */
743
- access?: { level?: FeatureAccess; extras?: readonly string[]; admin?: boolean };
815
+ access?: {
816
+ level?: FeatureAccess;
817
+ extras?: readonly string[];
818
+ admin?: boolean;
819
+ scope?: 'account';
820
+ };
744
821
  /**
745
822
  * This command changes data other members can see. `true` beats your
746
823
  * feature's own live topic (its id); a list names the topics to beat
@@ -764,6 +841,12 @@ export interface SdkPublicRequest {
764
841
  headers: Readonly<Record<string, string | string[] | undefined>>;
765
842
  /** The JSON body, already decoded (`undefined` when absent or unreadable). */
766
843
  body: unknown;
844
+ /**
845
+ * The body exactly as received, on a route that asked for it
846
+ * (`SdkPublicRouteOptions.rawBody`). What a webhook signature is computed
847
+ * over: re-serialising `body` would not give the same bytes.
848
+ */
849
+ rawBody?: string;
767
850
  /**
768
851
  * The query string, decoded by the host into an object (`?a=1&b=2` reads
769
852
  * `{ a: '1', b: '2' }`). `unknown` like `body`: read it through a schema.
@@ -803,6 +886,8 @@ export interface SdkPublicRouteOptions {
803
886
  * callback that lands back in the app).
804
887
  */
805
888
  exposure?: 'everywhere' | 'app';
889
+ /** Also hand the handler the undecoded body (`SdkPublicRequest.rawBody`). JSON bodies only. */
890
+ rawBody?: boolean;
806
891
  }
807
892
 
808
893
  /** What a redeemed ticket gives a public route back (see `SdkSecrecy.ticket`). */
@@ -866,6 +951,14 @@ export interface FeatureServiceDeps<Repo = unknown> {
866
951
  devicesFor(workspaceId: number): Pick<DevEyeFacade['devices'], 'list' | 'isOnline'>;
867
952
  /** The whole fleet by id, sessionless (capability `'devices.read'`). */
868
953
  devices: SdkFleetDevices;
954
+ /** Capability `'accounts.read'`. */
955
+ accounts: SdkAccounts;
956
+ /**
957
+ * {@link SdkQuota} for a workspace, sessionless: for what gets created
958
+ * outside any command (bytes an agent uploads). Same account rule, the
959
+ * owner of that workspace.
960
+ */
961
+ quotaFor(workspaceId: number): SdkQuota;
869
962
  /** The devices' telemetry, sessionless (capability `'telemetry.read'`). */
870
963
  telemetry: SdkTelemetry;
871
964
  /** Live invalidation of your feature's resources, from a service. */
@@ -970,6 +1063,74 @@ export interface FeatureItemsEntry<Repo = unknown> {
970
1063
  * credential, a destination) that cannot follow it.
971
1064
  */
972
1065
  move?: FeatureItemsMove<Repo>;
1066
+ /**
1067
+ * Copy this item to another workspace, of this DevEye or of ANOTHER one.
1068
+ * You describe what the item is made of, the app reads and writes it (see
1069
+ * `copy.ts`). Omit it and your items cannot be copied: the screen says so.
1070
+ */
1071
+ copy?: FeatureItemsCopy<Repo>;
1072
+ }
1073
+
1074
+ /** What copying one item leaves behind, decided on the SOURCE before a row is read. */
1075
+ export interface SdkCopyPlan {
1076
+ /** Why the copy is impossible, in sentences the screen shows as they are. Empty means it can go. */
1077
+ blockers: readonly string[];
1078
+ /**
1079
+ * What the copy will NOT carry, named one by one for the confirmation: a
1080
+ * token of the origin workspace, a history the destination rebuilds.
1081
+ */
1082
+ drops: readonly string[];
1083
+ }
1084
+
1085
+ /** See {@link FeatureItemsEntry.copy}. */
1086
+ export interface FeatureItemsCopy<Repo = unknown> {
1087
+ /**
1088
+ * What an item is made of. Build your `move` cells from the same tree
1089
+ * (`movableCellsOf`) and you hold one list instead of two.
1090
+ */
1091
+ tree: ItemTree;
1092
+ /** SOURCE side. Reads only; the destination is unknown here, it may be another DevEye. */
1093
+ plan?(ctx: FeatureItemsCopyPlanContext<Repo>): Promise<SdkCopyPlan>;
1094
+ /**
1095
+ * DESTINATION side, inside the transaction, before the first row is
1096
+ * written. Refuse by throwing a `FeatureError` (a name already taken there,
1097
+ * a quota reached), or amend `rows` in place: they are in the clear (a
1098
+ * title to suffix, a derived column to recompute).
1099
+ */
1100
+ admit?(ctx: FeatureItemsCopyAdmitContext<Repo>): Promise<void>;
1101
+ /**
1102
+ * DESTINATION side, same transaction, once the rows are written: give the
1103
+ * copy its place (the end of its list).
1104
+ */
1105
+ settle?(ctx: FeatureItemsCopySettleContext<Repo>): Promise<void>;
1106
+ }
1107
+
1108
+ export interface FeatureItemsCopyPlanContext<Repo = unknown> {
1109
+ q: SdkQueryable;
1110
+ repo: Repo;
1111
+ itemId: string;
1112
+ workspaceId: number;
1113
+ }
1114
+
1115
+ export interface FeatureItemsCopyAdmitContext<Repo = unknown> {
1116
+ /** Transactional, see {@link FeatureItemsMoveContext.q}. */
1117
+ q: SdkQueryable;
1118
+ /** Your repo. For reads only. */
1119
+ repo: Repo;
1120
+ toWorkspaceId: number;
1121
+ /** The rows about to be written, sealed cells in the clear. Yours to amend. */
1122
+ rows: ItemTreeRows;
1123
+ /** The quotas of the DESTINATION workspace's owner, as `ctx.quota` in a handler. */
1124
+ quota: SdkQuota;
1125
+ }
1126
+
1127
+ export interface FeatureItemsCopySettleContext<Repo = unknown> {
1128
+ /** Transactional, see {@link FeatureItemsMoveContext.q}. */
1129
+ q: SdkQueryable;
1130
+ repo: Repo;
1131
+ toWorkspaceId: number;
1132
+ /** The id the copy was given. */
1133
+ itemId: string;
973
1134
  }
974
1135
 
975
1136
  /**
@@ -1154,6 +1315,23 @@ export async function resealCells(
1154
1315
  return pending.length;
1155
1316
  }
1156
1317
 
1318
+ export {
1319
+ countItemTreeRows,
1320
+ exportItemTree,
1321
+ importItemTree,
1322
+ itemTierOf,
1323
+ itemTreeProblem,
1324
+ movableCellsOf
1325
+ } from './copy';
1326
+ export type {
1327
+ ItemTier,
1328
+ ItemTree,
1329
+ ItemTreeDestination,
1330
+ ItemTreeRow,
1331
+ ItemTreeRows,
1332
+ ItemTreeTable
1333
+ } from './copy';
1334
+
1157
1335
  // Le conteneur chiffré que CloudSync et Backup partagent (voir `devb.ts`).
1158
1336
  export {
1159
1337
  BLOB_CHUNK_BYTES,
@@ -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
  },