@deveye/types 0.24.6 → 0.25.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.
@@ -26,6 +26,7 @@ import {
26
26
  type SdkCipher,
27
27
  type SdkDevice,
28
28
  type SdkFeatureContext,
29
+ type SdkInstanceAlert,
29
30
  type SdkLogger,
30
31
  type SdkObjectStore,
31
32
  type SdkOrigins,
@@ -142,6 +143,8 @@ export interface RecordedCalls {
142
143
  livePublishes: { workspaceId: number; event: string; payload: unknown }[];
143
144
  /** Accounts beaten through `live.accountChanged`, in order. */
144
145
  accountChanges: number[];
146
+ /** How many times `live.pendingChanged` was called. */
147
+ pendingChanges: number;
145
148
  }
146
149
 
147
150
  /** What a command's test context records on top of {@link RecordedCalls}. */
@@ -220,6 +223,7 @@ function recordingDevices(
220
223
  )
221
224
  )
222
225
  : Promise.resolve(devices.find((d) => d.id === id) ?? testDevice({ id })),
226
+ assertControl: () => Promise.resolve(),
223
227
  list: () => Promise.resolve([...devices]),
224
228
  isOnline: (id) => devices.find((d) => d.id === id)?.online ?? true
225
229
  };
@@ -541,6 +545,7 @@ export function createTestContext<Repo = undefined>(
541
545
  pinnedInstants: [],
542
546
  livePublishes: [],
543
547
  accountChanges: [],
548
+ pendingChanges: 0,
544
549
  progress: []
545
550
  };
546
551
  const isOwner = overrides.isOwner ?? true;
@@ -573,6 +578,7 @@ export function createTestContext<Repo = undefined>(
573
578
  email: `user${overrides.userId ?? 1}@deveye.test`,
574
579
  username: `user${overrides.userId ?? 1}`,
575
580
  isAdmin: overrides.isAdmin ?? false,
581
+ canModerate: overrides.isAdmin ?? false,
576
582
  e2e: false,
577
583
  suspended: false,
578
584
  created: 0
@@ -616,7 +622,19 @@ export function createTestContext<Repo = undefined>(
616
622
  ticket: (payload) =>
617
623
  Promise.resolve(
618
624
  `ticket:${JSON.stringify({ userId: overrides.userId ?? 1, workspaceId, payload, unlocked: overrides.unlocked ?? true })}`
619
- )
625
+ ),
626
+ // Only a ticket this caller minted, in this workspace, reads back.
627
+ redeem: (ticket) => {
628
+ if (!ticket.startsWith('ticket:')) return Promise.resolve(null);
629
+ const parsed = JSON.parse(ticket.slice('ticket:'.length)) as {
630
+ userId: number;
631
+ workspaceId: number;
632
+ payload: unknown;
633
+ };
634
+ const mine =
635
+ parsed.userId === (overrides.userId ?? 1) && parsed.workspaceId === workspaceId;
636
+ return Promise.resolve(mine ? { payload: parsed.payload } : null);
637
+ }
620
638
  },
621
639
  keys: {
622
640
  sealBytes: (plain) => `sealed:${Buffer.from(plain).toString('base64')}`,
@@ -629,6 +647,9 @@ export function createTestContext<Repo = undefined>(
629
647
  },
630
648
  accountChanged(userId) {
631
649
  recorded.accountChanges.push(userId);
650
+ },
651
+ pendingChanged() {
652
+ recorded.pendingChanges++;
632
653
  }
633
654
  },
634
655
  quota: {
@@ -658,19 +679,19 @@ export function createTestContext<Repo = undefined>(
658
679
  },
659
680
  items: {
660
681
  restrictions: () => Promise.resolve(restrictions),
661
- // The exact rule of the app's dispatcher: the feature first (a
662
- // restriction can only lower), then the row.
682
+ // The app's rule: the item's override replaces the feature level,
683
+ // in both directions; without one, the feature level decides.
663
684
  assert(itemId, level = 'read') {
664
- if (level === 'write' && !canWrite) {
665
- return Promise.reject(new FeatureError('forbidden', 'write required'));
666
- }
667
685
  const restriction = restrictions.get(itemId);
668
686
  if (restriction === 'none') {
669
687
  return Promise.reject(new FeatureError('forbidden', 'item hidden'));
670
688
  }
671
- if (restriction === 'read' && level === 'write') {
689
+ if (level === 'write' && restriction === 'read') {
672
690
  return Promise.reject(new FeatureError('forbidden', 'item read-only'));
673
691
  }
692
+ if (level === 'write' && restriction === undefined && !canWrite) {
693
+ return Promise.reject(new FeatureError('forbidden', 'write required'));
694
+ }
674
695
  return Promise.resolve();
675
696
  },
676
697
  canExtra(itemId, key) {
@@ -756,8 +777,10 @@ export interface RecordedServiceCalls extends RecordedCalls {
756
777
  liveChanges: number[];
757
778
  /** `live.changed` calls that named topics, as `{ workspaceId, topics }` (a bare beat is not listed here). */
758
779
  liveTopicChanges: { workspaceId: number; topics: readonly string[] }[];
759
- /** Emails `accountMail.send` and `sendToAdmins` accepted, with the address they went to. */
780
+ /** Emails `accountMail.send` and `sendToModerators` accepted, with the address they went to. */
760
781
  mails: { userId: number; to: string; message: SdkAccountMailMessage }[];
782
+ /** What `alertInstance` raised, in order, keys as the module gave them. */
783
+ instanceAlerts: SdkInstanceAlert[];
761
784
  }
762
785
 
763
786
  export interface TestServiceDeps<Repo> extends FeatureServiceDeps<Repo> {
@@ -835,10 +858,12 @@ export function createTestServiceDeps<Repo = undefined>(
835
858
  pinnedInstants: [],
836
859
  livePublishes: [],
837
860
  accountChanges: [],
861
+ pendingChanges: 0,
838
862
  tickers: [],
839
863
  liveChanges: [],
840
864
  liveTopicChanges: [],
841
- mails: []
865
+ mails: [],
866
+ instanceAlerts: []
842
867
  };
843
868
  const stores = new Map<number, TestFeatureStore>();
844
869
  const sealedBytes = new Map<string, Uint8Array>();
@@ -915,6 +940,9 @@ export function createTestServiceDeps<Repo = undefined>(
915
940
  },
916
941
  accountChanged(userId) {
917
942
  recorded.accountChanges.push(userId);
943
+ },
944
+ pendingChanged() {
945
+ recorded.pendingChanges++;
918
946
  }
919
947
  },
920
948
  quotaFor: () => ({
@@ -995,13 +1023,17 @@ export function createTestServiceDeps<Repo = undefined>(
995
1023
  recorded.mails.push({ userId, to, message });
996
1024
  return Promise.resolve(to);
997
1025
  },
998
- sendToAdmins(message) {
1026
+ sendToModerators(message) {
999
1027
  if (overrides.mailConfigured === false) {
1000
1028
  return Promise.reject(new FeatureError('conflict', 'no mail transport'));
1001
1029
  }
1002
- const admins = (overrides.accounts ?? []).filter((a) => a.isAdmin && !a.suspended);
1003
- for (const a of admins) recorded.mails.push({ userId: a.id, to: a.email, message });
1004
- return Promise.resolve(admins.map((a) => a.email));
1030
+ const moderators = (overrides.accounts ?? []).filter(
1031
+ (a) => a.canModerate && !a.suspended
1032
+ );
1033
+ for (const a of moderators) {
1034
+ recorded.mails.push({ userId: a.id, to: a.email, message });
1035
+ }
1036
+ return Promise.resolve(moderators.map((a) => a.email));
1005
1037
  }
1006
1038
  },
1007
1039
  audit: (entry) => {
@@ -1041,6 +1073,9 @@ export function createTestServiceDeps<Repo = undefined>(
1041
1073
  )
1042
1074
  },
1043
1075
  providers: fakeProviders(overrides.providers ?? {}),
1076
+ alertInstance(alert) {
1077
+ recorded.instanceAlerts.push(alert);
1078
+ },
1044
1079
  createTicker({ intervalMs, tick }) {
1045
1080
  recorded.tickers.push({ intervalMs, tick });
1046
1081
  return { start: () => undefined, stop: () => undefined };