@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.
- package/package.json +1 -1
- package/src/domain/feedback.ts +12 -4
- package/src/domain/home.ts +13 -0
- package/src/domain/live.ts +8 -0
- package/src/domain/loginChecks.ts +72 -0
- package/src/domain/role.ts +9 -3
- package/src/domain/stepUp.ts +29 -0
- package/src/domain/user.ts +24 -5
- package/src/domain/workspace.ts +21 -0
- package/src/domain/workspaceRole.ts +1 -1
- package/src/features/admin.ts +60 -3
- package/src/features/feedback.ts +8 -7
- package/src/features/loginChecks.ts +102 -0
- package/src/features/registry.ts +4 -0
- package/src/features/stepUp.ts +26 -0
- package/src/features/twoFactor.ts +13 -6
- package/src/features/user.ts +23 -0
- package/src/features/workspace.ts +63 -7
- package/src/http/auth.ts +44 -12
- package/src/http/device.ts +10 -1
- package/src/index.ts +69 -6
- package/src/protocol/agent.ts +25 -8
- package/src/protocol/error.ts +5 -1
- package/src/sdk/client-ambient.d.ts +39 -9
- package/src/sdk/client.ts +7 -7
- package/src/sdk/copy.test.ts +23 -0
- package/src/sdk/copy.ts +24 -2
- package/src/sdk/csv.test.ts +28 -0
- package/src/sdk/csv.ts +24 -0
- package/src/sdk/deviceRelay.ts +8 -2
- package/src/sdk/index.ts +1 -0
- package/src/sdk/manifest.ts +25 -7
- package/src/sdk/net.test.ts +10 -2
- package/src/sdk/net.ts +35 -30
- package/src/sdk/providers.ts +7 -0
- package/src/sdk/server.ts +132 -16
- package/src/sdk/testing.test.ts +1 -0
- package/src/sdk/testing.ts +48 -13
package/src/sdk/testing.ts
CHANGED
|
@@ -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
|
|
662
|
-
//
|
|
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 (
|
|
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 `
|
|
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
|
-
|
|
1026
|
+
sendToModerators(message) {
|
|
999
1027
|
if (overrides.mailConfigured === false) {
|
|
1000
1028
|
return Promise.reject(new FeatureError('conflict', 'no mail transport'));
|
|
1001
1029
|
}
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1004
|
-
|
|
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 };
|