@sovereignfs/sdk 1.25.0 → 2.0.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/LICENSE +373 -661
- package/README.md +103 -0
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +4 -0
- package/dist/chunk-NYL4LLXF.js +65 -0
- package/dist/index.d.ts +57 -529
- package/dist/index.js +1283 -572
- package/dist/next.d.ts +37 -0
- package/dist/next.js +68 -0
- package/dist/session-DJl2XYMc.d.ts +44 -0
- package/dist/sovereign-CazGKEVc.d.ts +517 -0
- package/dist/testing.d.ts +181 -0
- package/dist/testing.js +560 -0
- package/package.json +53 -27
- package/dist/chunk-MLKGABMK.js +0 -9
- package/dist/chunk-NQLGPAL6.js +0 -62
- package/dist/e2ee-crypto.d.ts +0 -84
- package/dist/e2ee-crypto.js +0 -162
- package/dist/e2ee-device.d.ts +0 -21
- package/dist/e2ee-device.js +0 -13
- package/dist/e2ee-object.d.ts +0 -50
- package/dist/e2ee-object.js +0 -75
- package/dist/e2ee-state-U-GEJ7oL.d.ts +0 -411
- package/dist/e2ee-state.d.ts +0 -1
- package/dist/e2ee-state.js +0 -36
- package/src/__tests__/e2ee-crypto.test.ts +0 -156
- package/src/__tests__/e2ee-object.test.ts +0 -90
- package/src/__tests__/e2ee-state.test.ts +0 -83
- package/src/__tests__/sdk.test.ts +0 -427
- package/src/__tests__/sessions.test.ts +0 -63
- package/src/activity.ts +0 -19
- package/src/auth.ts +0 -134
- package/src/connections.ts +0 -106
- package/src/data.ts +0 -88
- package/src/db.ts +0 -34
- package/src/directory.ts +0 -31
- package/src/e2ee-crypto.ts +0 -260
- package/src/e2ee-device.ts +0 -75
- package/src/e2ee-object.ts +0 -118
- package/src/e2ee-state.ts +0 -72
- package/src/e2ee.ts +0 -65
- package/src/env.ts +0 -37
- package/src/errors.ts +0 -46
- package/src/host.ts +0 -251
- package/src/index.ts +0 -160
- package/src/mailer.ts +0 -7
- package/src/notifications.ts +0 -36
- package/src/platform.ts +0 -10
- package/src/plugins.ts +0 -146
- package/src/portability.ts +0 -176
- package/src/secrets.ts +0 -68
- package/src/sessions.ts +0 -36
- package/src/storage.ts +0 -49
- package/src/types.ts +0 -418
- package/src/unimplemented.ts +0 -48
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { SessionStore } from './index.js';
|
|
2
|
+
|
|
3
|
+
/** A person the fake core knows. */
|
|
4
|
+
type FakePerson = {
|
|
5
|
+
sub: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
picture?: string | null;
|
|
8
|
+
/** False for a deactivated account (the Directory returns it with `active: false`). */
|
|
9
|
+
active?: boolean;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* How the fake core can be told to fail (sdk §11), one for each way §6 lists:
|
|
13
|
+
*
|
|
14
|
+
* - `down`: the connection is refused, as with core stopped. Nothing reaches the fake.
|
|
15
|
+
* - `lost-answer`: the request is handled and its answer never arrives. For a refresh, core has rotated the token.
|
|
16
|
+
* - `timeout`: the answer takes longer than any timeout.
|
|
17
|
+
* - `status`: core answers with this failure status (5xx is unavailable, 429 sets `Retry-After`).
|
|
18
|
+
*/
|
|
19
|
+
type Failure = {
|
|
20
|
+
kind: 'down';
|
|
21
|
+
} | {
|
|
22
|
+
kind: 'lost-answer';
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'timeout';
|
|
25
|
+
} | {
|
|
26
|
+
kind: 'status';
|
|
27
|
+
status: number;
|
|
28
|
+
retryAfter?: number;
|
|
29
|
+
};
|
|
30
|
+
/** The ways a logout token can be wrong, each of which an app must refuse. */
|
|
31
|
+
type WrongLogoutToken = 'signature' | 'issuer' | 'audience' | 'expired' | 'future' | 'event' | 'nonce' | 'type' | 'no-subject' | 'no-jti';
|
|
32
|
+
/** Which requests a failure applies to. */
|
|
33
|
+
type Target = 'any' | 'token' | 'api' | 'instance' | 'discovery';
|
|
34
|
+
type FakeCoreOptions = {
|
|
35
|
+
/** The instance's address. */
|
|
36
|
+
url?: string;
|
|
37
|
+
/** The app's credentials in this core. */
|
|
38
|
+
clientId?: string;
|
|
39
|
+
clientSecret?: string;
|
|
40
|
+
/** The clock, in milliseconds. Defaults to the real one. */
|
|
41
|
+
now?: () => number;
|
|
42
|
+
/** How long an access token lives, in seconds. 900, as core's does. */
|
|
43
|
+
accessTokenSeconds?: number;
|
|
44
|
+
/**
|
|
45
|
+
* What the instance document says is served. `undefined` is a core that publishes no `api` (an old core), and it serves
|
|
46
|
+
* the Directory only. Defaults to a core that serves the Directory.
|
|
47
|
+
*/
|
|
48
|
+
api?: {
|
|
49
|
+
versions: string[];
|
|
50
|
+
capabilities: string[];
|
|
51
|
+
} | undefined;
|
|
52
|
+
/** Whether the app may ask for a token for itself. On by default. */
|
|
53
|
+
appTokens?: boolean;
|
|
54
|
+
instance?: {
|
|
55
|
+
name?: string;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
/** A notification an app sent through the fake core. */
|
|
59
|
+
type FakeNotification = {
|
|
60
|
+
id: string;
|
|
61
|
+
to: string;
|
|
62
|
+
title: string;
|
|
63
|
+
body?: string;
|
|
64
|
+
url?: string;
|
|
65
|
+
category?: string;
|
|
66
|
+
createdAt: number;
|
|
67
|
+
readAt: number | null;
|
|
68
|
+
dismissed: boolean;
|
|
69
|
+
};
|
|
70
|
+
/** An email an app sent through the fake core. Whether it was delivered is never said, here or in core. */
|
|
71
|
+
type FakeEmail = {
|
|
72
|
+
id: string;
|
|
73
|
+
to: string;
|
|
74
|
+
subject: string;
|
|
75
|
+
body: string;
|
|
76
|
+
link?: string;
|
|
77
|
+
key?: string;
|
|
78
|
+
sentAt: number;
|
|
79
|
+
};
|
|
80
|
+
/** An entry an app recorded through the fake core. There is no call to read it back, as in core: a test reads it here. */
|
|
81
|
+
type FakeActivity = {
|
|
82
|
+
id: string;
|
|
83
|
+
to: string;
|
|
84
|
+
summary: string;
|
|
85
|
+
link?: string;
|
|
86
|
+
at: number;
|
|
87
|
+
key?: string;
|
|
88
|
+
recordedAt: number;
|
|
89
|
+
};
|
|
90
|
+
/** One request the fake received, with nothing secret in it. `status` is 0 when it was never answered. */
|
|
91
|
+
type Received = {
|
|
92
|
+
method: string;
|
|
93
|
+
path: string;
|
|
94
|
+
status: number;
|
|
95
|
+
};
|
|
96
|
+
type FakeCore = {
|
|
97
|
+
/** The instance's address, to give `createSovereign` as `coreUrl`. */
|
|
98
|
+
readonly url: string;
|
|
99
|
+
/** The app's credentials in this core. */
|
|
100
|
+
readonly credentials: {
|
|
101
|
+
clientId: string;
|
|
102
|
+
clientSecret: string;
|
|
103
|
+
};
|
|
104
|
+
/** Answers like core does. Give it to `createSovereign({ fetch })`: no server, no port. */
|
|
105
|
+
readonly fetch: typeof fetch;
|
|
106
|
+
/** What apps have sent through this core, in order, whether or not it was read or dismissed. */
|
|
107
|
+
readonly notificationsSent: readonly FakeNotification[];
|
|
108
|
+
/** The emails apps sent to people the fake has, in order. A send to anyone else is accepted and dropped, as core does. */
|
|
109
|
+
readonly emailsSent: readonly FakeEmail[];
|
|
110
|
+
/** What apps recorded about people the fake has, in order. A record about anyone else is accepted and dropped, as core does. */
|
|
111
|
+
readonly activityRecorded: readonly FakeActivity[];
|
|
112
|
+
/** Adds a person to the Directory. */
|
|
113
|
+
addPerson(person: FakePerson): void;
|
|
114
|
+
/** Signs a person in, and returns the refresh token an app would have stored for them. */
|
|
115
|
+
signIn(sub: string): string;
|
|
116
|
+
/** Makes the next requests fail. `times` limits how many (default: until `heal`). */
|
|
117
|
+
fail(failure: Failure, options?: {
|
|
118
|
+
target?: Target;
|
|
119
|
+
times?: number;
|
|
120
|
+
}): void;
|
|
121
|
+
/** Ends every failure. */
|
|
122
|
+
heal(): void;
|
|
123
|
+
/**
|
|
124
|
+
* The person agrees at core's sign-in page: given the address `beginSignIn` returned, this is the address core sends the
|
|
125
|
+
* browser back to, with the code and `state`. It checks the request as core does (PKCE `S256`, a registered redirect).
|
|
126
|
+
*/
|
|
127
|
+
authorize(authorizationUrl: string, sub: string, options?: {
|
|
128
|
+
roles?: string[];
|
|
129
|
+
}): string;
|
|
130
|
+
/** The core session id (`sid`) of the person's latest sign-in. */
|
|
131
|
+
sessionIdOf(sub: string): string | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* A signed logout token, as core sends to an app's back-channel address when a session ends (core-app §3.6.5). `wrong` makes
|
|
134
|
+
* one that is wrong in one way, for testing that an app refuses it.
|
|
135
|
+
*/
|
|
136
|
+
logoutToken(who: {
|
|
137
|
+
sub?: string;
|
|
138
|
+
sid?: string;
|
|
139
|
+
}, options?: {
|
|
140
|
+
wrong?: WrongLogoutToken;
|
|
141
|
+
}): Promise<string>;
|
|
142
|
+
/**
|
|
143
|
+
* A signed account-deleted token, as core sends to an app's account-deleted address when a person who used it deleted their account
|
|
144
|
+
* (core-app §4.5). `wrong` makes one that is wrong in one way, as for `logoutToken`.
|
|
145
|
+
*/
|
|
146
|
+
accountDeletedToken(who: {
|
|
147
|
+
sub: string;
|
|
148
|
+
}, options?: {
|
|
149
|
+
wrong?: WrongLogoutToken;
|
|
150
|
+
}): Promise<string>;
|
|
151
|
+
/** Ends a person's tokens, as core does when their sessions end: the next use of any is refused. */
|
|
152
|
+
revoke(sub: string): void;
|
|
153
|
+
/** Ends every access token but keeps the refresh tokens, so the next call must refresh. */
|
|
154
|
+
expireAccessTokens(): void;
|
|
155
|
+
/** What happened. */
|
|
156
|
+
readonly seen: {
|
|
157
|
+
/** Every request, in order. */
|
|
158
|
+
readonly requests: readonly Received[];
|
|
159
|
+
/** How many times a refresh token was exchanged. */
|
|
160
|
+
readonly refreshes: number;
|
|
161
|
+
/** How many times an app token was asked for. */
|
|
162
|
+
readonly appTokens: number;
|
|
163
|
+
/** How many times an already-used refresh token was sent, which core treats as theft and answers by ending the person's tokens. */
|
|
164
|
+
readonly reused: number;
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* A core for an app's tests that needs no server (sdk §11). It answers the contract's operations and the token endpoint
|
|
169
|
+
* the way core does, including rotating a refresh token on every use and ending a person's tokens when one is used twice,
|
|
170
|
+
* and it can be told to fail in each way the specification lists. The SDK's own tests check its answers against the
|
|
171
|
+
* contract.
|
|
172
|
+
*/
|
|
173
|
+
declare function createFakeCore(options?: FakeCoreOptions): FakeCore;
|
|
174
|
+
/**
|
|
175
|
+
* A session store for an app's tests (sdk §9.1): records in memory, with the expiry the contract asks for. An app's own is a
|
|
176
|
+
* database table or a cache; this is only for tests.
|
|
177
|
+
*/
|
|
178
|
+
declare function memorySessionStore(now?: () => number): SessionStore;
|
|
179
|
+
|
|
180
|
+
export { createFakeCore, memorySessionStore };
|
|
181
|
+
export type { Failure, FakeActivity, FakeCore, FakeCoreOptions, FakeEmail, FakeNotification, FakePerson, Received, Target, WrongLogoutToken };
|