@getcirrus/pds 0.18.0 → 0.20.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.
- package/README.md +67 -11
- package/dist/cli.js +1667 -373
- package/dist/index.d.ts +662 -405
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2617 -1815
- package/dist/index.js.map +1 -1
- package/package.json +7 -4
package/dist/index.d.ts
CHANGED
|
@@ -1,79 +1,14 @@
|
|
|
1
|
-
import { DurableObject } from "cloudflare:workers";
|
|
2
|
-
import { BlockMap, CommitData, ReadableBlockstore, Repo, RepoStorage } from "@atproto/repo";
|
|
3
|
-
import { Secp256k1Keypair } from "@atproto/crypto";
|
|
1
|
+
import { DurableObject, RpcTarget } from "cloudflare:workers";
|
|
4
2
|
import { CID } from "@atproto/lex-data";
|
|
5
|
-
import
|
|
3
|
+
import { BlockMap, CommitData, ReadableBlockstore, RecordWriteOp, Repo, RepoStorage } from "@atproto/repo";
|
|
6
4
|
import { AuthCodeData, ClientMetadata, LexiconPermissionSet, OAuthStorage, PARData, TokenData } from "@getcirrus/oauth-provider";
|
|
5
|
+
import { Secp256k1Keypair } from "@atproto/crypto";
|
|
7
6
|
import { Hono } from "hono";
|
|
7
|
+
import { SpaceDurableObject as SpaceDurableObject$1, SpaceHostConfig, SpaceIndexDurableObject as SpaceIndexDurableObject$1 } from "@getcirrus/spaces";
|
|
8
|
+
import "@atcute/identity";
|
|
8
9
|
import * as hono_types0 from "hono/types";
|
|
9
10
|
|
|
10
|
-
//#region src/
|
|
11
|
-
/**
|
|
12
|
-
* A cached permission-set lookup. `stale` means the entry has passed its
|
|
13
|
-
* 24h soft-expiry: it is still safe to use but should be refreshed
|
|
14
|
-
* opportunistically.
|
|
15
|
-
*/
|
|
16
|
-
interface CachedPermissionSet {
|
|
17
|
-
set: LexiconPermissionSet;
|
|
18
|
-
fetchedAt: number;
|
|
19
|
-
stale: boolean;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* SQLite-backed OAuth storage for Cloudflare Durable Objects.
|
|
23
|
-
*
|
|
24
|
-
* Implements the OAuthStorage interface from @getcirrus/oauth-provider,
|
|
25
|
-
* storing OAuth data in SQLite tables within a Durable Object.
|
|
26
|
-
*/
|
|
27
|
-
declare class SqliteOAuthStorage implements OAuthStorage {
|
|
28
|
-
private sql;
|
|
29
|
-
constructor(sql: SqlStorage);
|
|
30
|
-
/**
|
|
31
|
-
* Initialize the OAuth database schema. Should be called once on DO startup.
|
|
32
|
-
*/
|
|
33
|
-
initSchema(): void;
|
|
34
|
-
private migrateClientTable;
|
|
35
|
-
private migrateTokensTable;
|
|
36
|
-
private ensureTokenIndexes;
|
|
37
|
-
/**
|
|
38
|
-
* Clean up expired entries. Should be called periodically.
|
|
39
|
-
*/
|
|
40
|
-
cleanup(): void;
|
|
41
|
-
saveAuthCode(code: string, data: AuthCodeData): Promise<void>;
|
|
42
|
-
getAuthCode(code: string): Promise<AuthCodeData | null>;
|
|
43
|
-
deleteAuthCode(code: string): Promise<void>;
|
|
44
|
-
saveTokens(data: TokenData): Promise<void>;
|
|
45
|
-
getTokenByAccess(accessToken: string): Promise<TokenData | null>;
|
|
46
|
-
getTokenByRefresh(refreshToken: string): Promise<TokenData | null>;
|
|
47
|
-
revokeToken(accessToken: string): Promise<void>;
|
|
48
|
-
revokeAllTokens(sub: string): Promise<void>;
|
|
49
|
-
saveClient(clientId: string, metadata: ClientMetadata): Promise<void>;
|
|
50
|
-
getClient(clientId: string): Promise<ClientMetadata | null>;
|
|
51
|
-
savePAR(requestUri: string, data: PARData): Promise<void>;
|
|
52
|
-
getPAR(requestUri: string): Promise<PARData | null>;
|
|
53
|
-
deletePAR(requestUri: string): Promise<void>;
|
|
54
|
-
checkAndSaveNonce(nonce: string): Promise<boolean>;
|
|
55
|
-
/**
|
|
56
|
-
* Clear all OAuth data (for testing).
|
|
57
|
-
*/
|
|
58
|
-
destroy(): void;
|
|
59
|
-
/** Soft-expiry: serve stale, but try to refresh. */
|
|
60
|
-
static readonly PERMISSION_SET_STALE_MS: number;
|
|
61
|
-
/** Hard-expiry: drop entirely. */
|
|
62
|
-
static readonly PERMISSION_SET_EXPIRY_MS: number;
|
|
63
|
-
savePermissionSet(nsid: string, set: LexiconPermissionSet, now?: number): void;
|
|
64
|
-
getPermissionSet(nsid: string): CachedPermissionSet | null;
|
|
65
|
-
/**
|
|
66
|
-
* Save a WebAuthn challenge for later verification
|
|
67
|
-
*/
|
|
68
|
-
saveWebAuthnChallenge(challenge: string): void;
|
|
69
|
-
/**
|
|
70
|
-
* Consume a WebAuthn challenge (single-use, deleted after retrieval)
|
|
71
|
-
* @returns true if challenge was valid and consumed, false if not found or expired
|
|
72
|
-
*/
|
|
73
|
-
consumeWebAuthnChallenge(challenge: string): boolean;
|
|
74
|
-
}
|
|
75
|
-
//#endregion
|
|
76
|
-
//#region src/storage.d.ts
|
|
11
|
+
//#region src/repo/storage.d.ts
|
|
77
12
|
/**
|
|
78
13
|
* SQLite-backed repository storage for Cloudflare Durable Objects.
|
|
79
14
|
*
|
|
@@ -139,14 +74,6 @@ declare class SqliteRepoStorage extends ReadableBlockstore implements RepoStorag
|
|
|
139
74
|
* Count the number of blocks stored.
|
|
140
75
|
*/
|
|
141
76
|
countBlocks(): Promise<number>;
|
|
142
|
-
/**
|
|
143
|
-
* Get user preferences.
|
|
144
|
-
*/
|
|
145
|
-
getPreferences(): Promise<unknown[]>;
|
|
146
|
-
/**
|
|
147
|
-
* Update user preferences.
|
|
148
|
-
*/
|
|
149
|
-
putPreferences(preferences: unknown[]): Promise<void>;
|
|
150
77
|
/**
|
|
151
78
|
* Get the activation state of the account.
|
|
152
79
|
*/
|
|
@@ -155,14 +82,6 @@ declare class SqliteRepoStorage extends ReadableBlockstore implements RepoStorag
|
|
|
155
82
|
* Set the activation state of the account.
|
|
156
83
|
*/
|
|
157
84
|
setActive(active: boolean): Promise<void>;
|
|
158
|
-
/**
|
|
159
|
-
* Get the stored email address.
|
|
160
|
-
*/
|
|
161
|
-
getEmail(): string | null;
|
|
162
|
-
/**
|
|
163
|
-
* Set the email address.
|
|
164
|
-
*/
|
|
165
|
-
setEmail(email: string): void;
|
|
166
85
|
/**
|
|
167
86
|
* Get all cached collection names.
|
|
168
87
|
*/
|
|
@@ -195,6 +114,10 @@ declare class SqliteRepoStorage extends ReadableBlockstore implements RepoStorag
|
|
|
195
114
|
* Track an imported blob.
|
|
196
115
|
*/
|
|
197
116
|
trackImportedBlob(cid: string, size: number, mimeType: string): void;
|
|
117
|
+
/**
|
|
118
|
+
* Check if any record references a blob CID.
|
|
119
|
+
*/
|
|
120
|
+
isBlobReferenced(cid: string): boolean;
|
|
198
121
|
/**
|
|
199
122
|
* Check if a blob has been imported.
|
|
200
123
|
*/
|
|
@@ -221,6 +144,118 @@ declare class SqliteRepoStorage extends ReadableBlockstore implements RepoStorag
|
|
|
221
144
|
* Clear all blob tracking data (for testing).
|
|
222
145
|
*/
|
|
223
146
|
clearBlobTracking(): void;
|
|
147
|
+
}
|
|
148
|
+
//#endregion
|
|
149
|
+
//#region src/oauth-storage.d.ts
|
|
150
|
+
/**
|
|
151
|
+
* A cached permission-set lookup. `stale` means the entry has passed its
|
|
152
|
+
* 24h soft-expiry: it is still safe to use but should be refreshed
|
|
153
|
+
* opportunistically.
|
|
154
|
+
*/
|
|
155
|
+
interface CachedPermissionSet {
|
|
156
|
+
set: LexiconPermissionSet;
|
|
157
|
+
fetchedAt: number;
|
|
158
|
+
stale: boolean;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* SQLite-backed OAuth storage for Cloudflare Durable Objects.
|
|
162
|
+
*
|
|
163
|
+
* Implements the OAuthStorage interface from @getcirrus/oauth-provider,
|
|
164
|
+
* storing OAuth data in SQLite tables within a Durable Object.
|
|
165
|
+
*
|
|
166
|
+
* Extends RpcTarget so the Durable Object can hand it to the Worker as a
|
|
167
|
+
* stub (via authStore()) — callers invoke storage methods directly over
|
|
168
|
+
* RPC instead of going through per-method proxies on the DO class.
|
|
169
|
+
*/
|
|
170
|
+
declare class SqliteOAuthStorage extends RpcTarget implements OAuthStorage {
|
|
171
|
+
private sql;
|
|
172
|
+
constructor(sql: SqlStorage);
|
|
173
|
+
/**
|
|
174
|
+
* Initialize the OAuth database schema. Should be called once on DO startup.
|
|
175
|
+
*/
|
|
176
|
+
initSchema(): void;
|
|
177
|
+
private migrateClientTable;
|
|
178
|
+
private migrateTokensTable;
|
|
179
|
+
private ensureTokenIndexes;
|
|
180
|
+
/**
|
|
181
|
+
* Clean up expired entries. Should be called periodically.
|
|
182
|
+
*/
|
|
183
|
+
cleanup(): void;
|
|
184
|
+
saveAuthCode(code: string, data: AuthCodeData): Promise<void>;
|
|
185
|
+
getAuthCode(code: string): Promise<AuthCodeData | null>;
|
|
186
|
+
deleteAuthCode(code: string): Promise<void>;
|
|
187
|
+
saveTokens(data: TokenData): Promise<void>;
|
|
188
|
+
getTokenByAccess(accessToken: string): Promise<TokenData | null>;
|
|
189
|
+
getTokenByRefresh(refreshToken: string): Promise<TokenData | null>;
|
|
190
|
+
revokeToken(accessToken: string): Promise<void>;
|
|
191
|
+
revokeAllTokens(sub: string): Promise<void>;
|
|
192
|
+
saveClient(clientId: string, metadata: ClientMetadata): Promise<void>;
|
|
193
|
+
getClient(clientId: string): Promise<ClientMetadata | null>;
|
|
194
|
+
savePAR(requestUri: string, data: PARData): Promise<void>;
|
|
195
|
+
getPAR(requestUri: string): Promise<PARData | null>;
|
|
196
|
+
deletePAR(requestUri: string): Promise<void>;
|
|
197
|
+
checkAndSaveNonce(nonce: string): Promise<boolean>;
|
|
198
|
+
/**
|
|
199
|
+
* Clear all OAuth data (for testing).
|
|
200
|
+
*/
|
|
201
|
+
destroy(): void;
|
|
202
|
+
/** Soft-expiry: serve stale, but try to refresh. */
|
|
203
|
+
static readonly PERMISSION_SET_STALE_MS: number;
|
|
204
|
+
/** Hard-expiry: drop entirely. */
|
|
205
|
+
static readonly PERMISSION_SET_EXPIRY_MS: number;
|
|
206
|
+
savePermissionSet(nsid: string, set: LexiconPermissionSet, now?: number): void;
|
|
207
|
+
getPermissionSet(nsid: string): CachedPermissionSet | null;
|
|
208
|
+
/**
|
|
209
|
+
* Save a WebAuthn challenge for later verification
|
|
210
|
+
*/
|
|
211
|
+
saveWebAuthnChallenge(challenge: string): void;
|
|
212
|
+
/**
|
|
213
|
+
* Consume a WebAuthn challenge (single-use, deleted after retrieval)
|
|
214
|
+
* @returns true if challenge was valid and consumed, false if not found or expired
|
|
215
|
+
*/
|
|
216
|
+
consumeWebAuthnChallenge(challenge: string): boolean;
|
|
217
|
+
}
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/account/store.d.ts
|
|
220
|
+
/**
|
|
221
|
+
* SQLite-backed storage for person-account data: preferences, email,
|
|
222
|
+
* handle, passkeys, and app passwords. Shares the Durable Object's SQLite
|
|
223
|
+
* database with SqliteRepoStorage; the email accessors read the email column
|
|
224
|
+
* of the repo_state table, whose schema SqliteRepoStorage owns.
|
|
225
|
+
*
|
|
226
|
+
* Extends RpcTarget so the Durable Object can hand it to the Worker as a
|
|
227
|
+
* stub (via account()) — callers invoke store methods directly over RPC.
|
|
228
|
+
*/
|
|
229
|
+
declare class AccountStore extends RpcTarget {
|
|
230
|
+
private sql;
|
|
231
|
+
constructor(sql: SqlStorage);
|
|
232
|
+
initSchema(): void;
|
|
233
|
+
/**
|
|
234
|
+
* Get the account's current handle. Returns the handle stored by
|
|
235
|
+
* updateHandle, unless the HANDLE var has changed since it was stored,
|
|
236
|
+
* in which case the var wins.
|
|
237
|
+
*/
|
|
238
|
+
getHandle(envHandle: string): string;
|
|
239
|
+
/**
|
|
240
|
+
* Store a new handle, overriding the HANDLE var.
|
|
241
|
+
*/
|
|
242
|
+
setHandle(handle: string, envHandle: string): void;
|
|
243
|
+
/**
|
|
244
|
+
* Get user preferences.
|
|
245
|
+
*/
|
|
246
|
+
getPreferences(): Promise<unknown[]>;
|
|
247
|
+
/**
|
|
248
|
+
* Update user preferences.
|
|
249
|
+
*/
|
|
250
|
+
putPreferences(preferences: unknown[]): Promise<void>;
|
|
251
|
+
/**
|
|
252
|
+
* Get the stored email address.
|
|
253
|
+
*/
|
|
254
|
+
getEmail(): string | null;
|
|
255
|
+
/**
|
|
256
|
+
* Set the email address.
|
|
257
|
+
*/
|
|
258
|
+
setEmail(email: string): void;
|
|
224
259
|
/**
|
|
225
260
|
* Save a passkey credential.
|
|
226
261
|
*/
|
|
@@ -296,129 +331,234 @@ declare class SqliteRepoStorage extends ReadableBlockstore implements RepoStorag
|
|
|
296
331
|
}>;
|
|
297
332
|
}
|
|
298
333
|
//#endregion
|
|
299
|
-
//#region src/
|
|
334
|
+
//#region src/repo/sequencer.d.ts
|
|
300
335
|
/**
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
* - "auto": No location constraint (default, recommended)
|
|
304
|
-
* - "eu": European Union - hard guarantee data never leaves EU
|
|
305
|
-
* - Location hints (best-effort, not guaranteed):
|
|
306
|
-
* - "wnam": Western North America
|
|
307
|
-
* - "enam": Eastern North America
|
|
308
|
-
* - "sam": South America
|
|
309
|
-
* - "weur": Western Europe
|
|
310
|
-
* - "eeur": Eastern Europe
|
|
311
|
-
* - "apac": Asia-Pacific
|
|
312
|
-
* - "oc": Oceania
|
|
313
|
-
* - "afr": Africa
|
|
314
|
-
* - "me": Middle East
|
|
315
|
-
*
|
|
316
|
-
* IMPORTANT: This setting only affects newly-created Durable Objects.
|
|
317
|
-
* Changing this after initial deployment will NOT migrate existing data.
|
|
318
|
-
* To relocate data, you must export and re-import to a new PDS.
|
|
336
|
+
* Commit event payload for the firehose
|
|
319
337
|
*/
|
|
320
|
-
|
|
338
|
+
interface CommitEvent {
|
|
339
|
+
seq: number;
|
|
340
|
+
rebase: boolean;
|
|
341
|
+
tooBig: boolean;
|
|
342
|
+
repo: string;
|
|
343
|
+
commit: CID;
|
|
344
|
+
rev: string;
|
|
345
|
+
since: string | null;
|
|
346
|
+
prevData: CID | null;
|
|
347
|
+
blocks: Uint8Array;
|
|
348
|
+
ops: RepoOp[];
|
|
349
|
+
blobs: CID[];
|
|
350
|
+
time: string;
|
|
351
|
+
}
|
|
321
352
|
/**
|
|
322
|
-
*
|
|
323
|
-
* Consumers must provide these bindings in their wrangler config.
|
|
353
|
+
* Identity event payload for the firehose
|
|
324
354
|
*/
|
|
325
|
-
interface
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
/** Public hostname of the PDS */
|
|
331
|
-
PDS_HOSTNAME: string;
|
|
332
|
-
/** Bearer token for write operations */
|
|
333
|
-
AUTH_TOKEN: string;
|
|
334
|
-
/** Private signing key (hex-encoded) */
|
|
335
|
-
SIGNING_KEY: string;
|
|
336
|
-
/** Public signing key (multibase-encoded) */
|
|
337
|
-
SIGNING_KEY_PUBLIC: string;
|
|
338
|
-
/** Secret for signing session JWTs */
|
|
339
|
-
JWT_SECRET: string;
|
|
340
|
-
/** Bcrypt hash of account password */
|
|
341
|
-
PASSWORD_HASH: string;
|
|
342
|
-
/** Durable Object namespace for account storage */
|
|
343
|
-
ACCOUNT: DurableObjectNamespace<AccountDurableObject>;
|
|
344
|
-
/** R2 bucket for blob storage (optional) */
|
|
345
|
-
BLOBS?: R2Bucket;
|
|
346
|
-
/** Account email address (optional, used by some clients) */
|
|
347
|
-
EMAIL?: string;
|
|
348
|
-
/** Initial activation state for new accounts (default: true) */
|
|
349
|
-
INITIAL_ACTIVE?: string;
|
|
350
|
-
/**
|
|
351
|
-
* Data location for Durable Object placement.
|
|
352
|
-
*
|
|
353
|
-
* WARNING: DO NOT CHANGE THIS AFTER INITIAL DEPLOYMENT.
|
|
354
|
-
* This setting only affects newly-created DOs. Changing it will NOT
|
|
355
|
-
* migrate existing data and may cause issues.
|
|
356
|
-
*
|
|
357
|
-
* Options:
|
|
358
|
-
* - "auto" or unset: No location constraint (default, recommended)
|
|
359
|
-
* - "eu": European Union - hard guarantee data never leaves EU
|
|
360
|
-
* - Location hints (best-effort, not guaranteed):
|
|
361
|
-
* "wnam", "enam", "sam", "weur", "eeur", "apac", "oc", "afr", "me"
|
|
362
|
-
*/
|
|
363
|
-
DATA_LOCATION?: DataLocation;
|
|
355
|
+
interface IdentityEvent {
|
|
356
|
+
seq: number;
|
|
357
|
+
did: string;
|
|
358
|
+
handle?: string;
|
|
359
|
+
time: string;
|
|
364
360
|
}
|
|
365
|
-
//#endregion
|
|
366
|
-
//#region src/validation.d.ts
|
|
367
|
-
type ValidationStatus = "valid" | "unknown";
|
|
368
|
-
//#endregion
|
|
369
|
-
//#region src/account-do.d.ts
|
|
370
361
|
/**
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
*
|
|
374
|
-
* - SQLite-backed block storage for the repository
|
|
375
|
-
* - AT Protocol Repo instance for repository operations
|
|
376
|
-
* - Firehose WebSocket connections
|
|
377
|
-
* - Sequence number management
|
|
362
|
+
* Sync event payload — broadcast after operations that change repo state
|
|
363
|
+
* without a commit diff (rebase, key rotation, repo import).
|
|
364
|
+
* `blocks` is a CAR containing just the current commit block.
|
|
378
365
|
*/
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
366
|
+
interface SyncEvent {
|
|
367
|
+
seq: number;
|
|
368
|
+
did: string;
|
|
369
|
+
rev: string;
|
|
370
|
+
blocks: Uint8Array;
|
|
371
|
+
time: string;
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Account event payload — broadcast on activation, deactivation, takedown,
|
|
375
|
+
* or deletion. `status` is omitted when active=true.
|
|
376
|
+
*/
|
|
377
|
+
type AccountStatus = "takendown" | "suspended" | "deleted" | "deactivated";
|
|
378
|
+
interface AccountEvent {
|
|
379
|
+
seq: number;
|
|
380
|
+
did: string;
|
|
381
|
+
active: boolean;
|
|
382
|
+
status?: AccountStatus;
|
|
383
|
+
time: string;
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Repository operation in a commit
|
|
387
|
+
*/
|
|
388
|
+
interface RepoOp {
|
|
389
|
+
action: "create" | "update" | "delete";
|
|
390
|
+
path: string;
|
|
391
|
+
cid: CID | null;
|
|
392
|
+
prev?: CID;
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Sequenced commit event wrapper
|
|
396
|
+
*/
|
|
397
|
+
interface SeqCommitEvent {
|
|
398
|
+
seq: number;
|
|
399
|
+
type: "commit";
|
|
400
|
+
event: CommitEvent;
|
|
401
|
+
time: string;
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Sequenced identity event wrapper
|
|
405
|
+
*/
|
|
406
|
+
interface SeqIdentityEvent {
|
|
407
|
+
seq: number;
|
|
408
|
+
type: "identity";
|
|
409
|
+
event: IdentityEvent;
|
|
410
|
+
time: string;
|
|
411
|
+
}
|
|
412
|
+
/**
|
|
413
|
+
* Sequenced sync event wrapper
|
|
414
|
+
*/
|
|
415
|
+
interface SeqSyncEvent {
|
|
416
|
+
seq: number;
|
|
417
|
+
type: "sync";
|
|
418
|
+
event: SyncEvent;
|
|
419
|
+
time: string;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Sequenced account event wrapper
|
|
423
|
+
*/
|
|
424
|
+
interface SeqAccountEvent {
|
|
425
|
+
seq: number;
|
|
426
|
+
type: "account";
|
|
427
|
+
event: AccountEvent;
|
|
428
|
+
time: string;
|
|
429
|
+
}
|
|
430
|
+
/**
|
|
431
|
+
* Sequenced event (commit, identity, sync, or account)
|
|
432
|
+
*/
|
|
433
|
+
type SeqEvent = SeqCommitEvent | SeqIdentityEvent | SeqSyncEvent | SeqAccountEvent;
|
|
434
|
+
/**
|
|
435
|
+
* Data needed to sequence a commit. Pass `newBlocks` and `relevantBlocks`
|
|
436
|
+
* from @atproto/repo's CommitData; both are needed in the CAR slice so
|
|
437
|
+
* relays can run the sync 1.1 MST inversion check.
|
|
438
|
+
*/
|
|
439
|
+
interface CommitData$1 {
|
|
440
|
+
did: string;
|
|
441
|
+
commit: CID;
|
|
442
|
+
rev: string;
|
|
443
|
+
since: string | null;
|
|
444
|
+
prevData: CID | null;
|
|
445
|
+
newBlocks: BlockMap;
|
|
446
|
+
relevantBlocks: BlockMap;
|
|
447
|
+
ops: Array<RecordWriteOp & {
|
|
448
|
+
cid?: CID | null;
|
|
449
|
+
prev?: CID;
|
|
450
|
+
}>;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Data needed to sequence a sync event.
|
|
454
|
+
*/
|
|
455
|
+
interface SyncEventData {
|
|
456
|
+
did: string;
|
|
457
|
+
rev: string;
|
|
458
|
+
cid: CID;
|
|
459
|
+
blocks: BlockMap;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Sequencer manages the firehose event log.
|
|
463
|
+
*
|
|
464
|
+
* Stores commit events in SQLite and provides methods for:
|
|
465
|
+
* - Sequencing new commits, identity, sync, and account events
|
|
466
|
+
* - Backfilling events from a cursor
|
|
467
|
+
* - Getting the latest sequence number
|
|
468
|
+
*/
|
|
469
|
+
declare class Sequencer {
|
|
470
|
+
private sql;
|
|
471
|
+
constructor(sql: SqlStorage);
|
|
389
472
|
/**
|
|
390
|
-
*
|
|
473
|
+
* Add a commit to the firehose sequence.
|
|
474
|
+
* Returns the complete sequenced event for broadcasting.
|
|
391
475
|
*/
|
|
392
|
-
|
|
476
|
+
sequenceCommit(data: CommitData$1): Promise<SeqCommitEvent>;
|
|
393
477
|
/**
|
|
394
|
-
*
|
|
478
|
+
* Add an identity event to the firehose.
|
|
479
|
+
* `handle` is optional per sync 1.1; presence does not signal change.
|
|
395
480
|
*/
|
|
396
|
-
|
|
481
|
+
sequenceIdentity(input: {
|
|
482
|
+
did: string;
|
|
483
|
+
handle?: string;
|
|
484
|
+
}): Promise<SeqIdentityEvent>;
|
|
397
485
|
/**
|
|
398
|
-
*
|
|
399
|
-
*
|
|
486
|
+
* Add a sync event to the firehose.
|
|
487
|
+
* Used after repo state changes that don't produce a commit diff
|
|
488
|
+
* (import, rebase, key rotation, account activation).
|
|
400
489
|
*/
|
|
401
|
-
|
|
490
|
+
sequenceSync(data: SyncEventData): Promise<SeqSyncEvent>;
|
|
402
491
|
/**
|
|
403
|
-
*
|
|
492
|
+
* Add an account status event to the firehose.
|
|
404
493
|
*/
|
|
405
|
-
|
|
494
|
+
sequenceAccount(input: {
|
|
495
|
+
did: string;
|
|
496
|
+
active: boolean;
|
|
497
|
+
status?: AccountStatus;
|
|
498
|
+
}): Promise<SeqAccountEvent>;
|
|
406
499
|
/**
|
|
407
|
-
* Get
|
|
500
|
+
* Get events from a cursor position.
|
|
501
|
+
* Returns up to `limit` events after the cursor.
|
|
502
|
+
* Skips identity events that have empty payloads.
|
|
408
503
|
*/
|
|
409
|
-
|
|
504
|
+
getEventsSince(cursor: number, limit?: number): Promise<SeqEvent[]>;
|
|
410
505
|
/**
|
|
411
|
-
* Get the
|
|
506
|
+
* Get the latest sequence number.
|
|
507
|
+
* Returns 0 if no events have been sequenced yet.
|
|
412
508
|
*/
|
|
413
|
-
|
|
509
|
+
getLatestSeq(): number;
|
|
414
510
|
/**
|
|
415
|
-
* Get the
|
|
511
|
+
* Get the earliest sequence number still in the log.
|
|
512
|
+
* Used to detect cursors that fall before the backfill window
|
|
513
|
+
* (so the firehose can send an OutdatedCursor info frame).
|
|
416
514
|
*/
|
|
417
|
-
|
|
515
|
+
getEarliestSeq(): number | null;
|
|
418
516
|
/**
|
|
419
|
-
*
|
|
517
|
+
* Prune old events to keep the log from growing indefinitely.
|
|
518
|
+
* Keeps the most recent `keepCount` events.
|
|
420
519
|
*/
|
|
421
|
-
|
|
520
|
+
pruneOldEvents(keepCount?: number): Promise<void>;
|
|
521
|
+
}
|
|
522
|
+
//#endregion
|
|
523
|
+
//#region src/validation.d.ts
|
|
524
|
+
type ValidationStatus = "valid" | "unknown";
|
|
525
|
+
//#endregion
|
|
526
|
+
//#region src/repo/engine.d.ts
|
|
527
|
+
interface RepoEngineOpts {
|
|
528
|
+
storage: SqliteRepoStorage;
|
|
529
|
+
sequencer: Sequencer;
|
|
530
|
+
did: string;
|
|
531
|
+
signingKey: string;
|
|
532
|
+
/** Serializes repo initialization; the DO backs this with blockConcurrencyWhile. */
|
|
533
|
+
lock: <T>(fn: () => Promise<T>) => Promise<T>;
|
|
534
|
+
broadcast: (event: SeqEvent) => Promise<void>;
|
|
535
|
+
}
|
|
536
|
+
/**
|
|
537
|
+
* The repository engine: owns the @atproto/repo instance and signing
|
|
538
|
+
* keypair, and implements record reads and writes, firehose sequencing,
|
|
539
|
+
* account activation, CAR import and migration reset. Depends only on
|
|
540
|
+
* SQLite-backed storage, the sequencer and a broadcast callback — no
|
|
541
|
+
* Durable Object or person-account concerns.
|
|
542
|
+
*/
|
|
543
|
+
declare class RepoEngine {
|
|
544
|
+
private storage;
|
|
545
|
+
private sequencer;
|
|
546
|
+
private did;
|
|
547
|
+
private signingKey;
|
|
548
|
+
private lock;
|
|
549
|
+
private broadcast;
|
|
550
|
+
private repo;
|
|
551
|
+
private keypair;
|
|
552
|
+
private initialized;
|
|
553
|
+
constructor(opts: RepoEngineOpts);
|
|
554
|
+
/**
|
|
555
|
+
* Initialize the Repo instance. Called lazily on first repo access.
|
|
556
|
+
*/
|
|
557
|
+
private ensureInitialized;
|
|
558
|
+
/**
|
|
559
|
+
* Get the Repo instance for repository operations.
|
|
560
|
+
*/
|
|
561
|
+
getRepo(): Promise<Repo>;
|
|
422
562
|
/**
|
|
423
563
|
* Get the signing keypair for repository operations.
|
|
424
564
|
*/
|
|
@@ -426,7 +566,7 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
426
566
|
/**
|
|
427
567
|
* Update the Repo instance after mutations.
|
|
428
568
|
*/
|
|
429
|
-
setRepo(repo: Repo):
|
|
569
|
+
setRepo(repo: Repo): void;
|
|
430
570
|
/**
|
|
431
571
|
* Drop the in-memory repo so the next access reloads from storage.
|
|
432
572
|
* Used after a write fails post-applyWrites: Cloudflare rolls back the
|
|
@@ -434,26 +574,31 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
434
574
|
* end up ahead of storage. That mismatch produces firehose events whose
|
|
435
575
|
* `since` rev the relay never saw, causing it to mark us desynced.
|
|
436
576
|
*/
|
|
437
|
-
private
|
|
577
|
+
private invalidate;
|
|
578
|
+
/**
|
|
579
|
+
* Ensure the account is active. Throws error if deactivated.
|
|
580
|
+
*/
|
|
581
|
+
ensureActive(): Promise<void>;
|
|
438
582
|
/**
|
|
439
|
-
*
|
|
583
|
+
* Get repo metadata for describeRepo.
|
|
440
584
|
*/
|
|
441
|
-
|
|
585
|
+
describeRepo(): Promise<{
|
|
442
586
|
did: string;
|
|
443
587
|
collections: string[];
|
|
444
588
|
cid: string;
|
|
445
589
|
}>;
|
|
446
590
|
/**
|
|
447
|
-
*
|
|
591
|
+
* Get a single record.
|
|
448
592
|
*/
|
|
449
|
-
|
|
593
|
+
getRecord(collection: string, rkey: string): Promise<{
|
|
450
594
|
cid: string;
|
|
451
|
-
record:
|
|
595
|
+
record: unknown;
|
|
452
596
|
} | null>;
|
|
453
597
|
/**
|
|
454
|
-
*
|
|
598
|
+
* List records in a collection, newest first unless `reverse` is set.
|
|
599
|
+
* The cursor is the rkey of the last record returned.
|
|
455
600
|
*/
|
|
456
|
-
|
|
601
|
+
listRecords(collection: string, opts: {
|
|
457
602
|
limit: number;
|
|
458
603
|
cursor?: string;
|
|
459
604
|
reverse?: boolean;
|
|
@@ -466,9 +611,9 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
466
611
|
cursor?: string;
|
|
467
612
|
}>;
|
|
468
613
|
/**
|
|
469
|
-
*
|
|
614
|
+
* Create a record.
|
|
470
615
|
*/
|
|
471
|
-
|
|
616
|
+
createRecord(collection: string, rkey: string | undefined, record: unknown, validationStatus?: ValidationStatus): Promise<{
|
|
472
617
|
uri: string;
|
|
473
618
|
cid: string;
|
|
474
619
|
commit: {
|
|
@@ -478,18 +623,18 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
478
623
|
validationStatus?: ValidationStatus;
|
|
479
624
|
}>;
|
|
480
625
|
/**
|
|
481
|
-
*
|
|
626
|
+
* Delete a record.
|
|
482
627
|
*/
|
|
483
|
-
|
|
628
|
+
deleteRecord(collection: string, rkey: string): Promise<{
|
|
484
629
|
commit: {
|
|
485
630
|
cid: string;
|
|
486
631
|
rev: string;
|
|
487
632
|
};
|
|
488
633
|
} | null>;
|
|
489
634
|
/**
|
|
490
|
-
*
|
|
635
|
+
* Put a record (create or update).
|
|
491
636
|
*/
|
|
492
|
-
|
|
637
|
+
putRecord(collection: string, rkey: string, record: unknown, validationStatus?: ValidationStatus): Promise<{
|
|
493
638
|
uri: string;
|
|
494
639
|
cid: string;
|
|
495
640
|
commit: {
|
|
@@ -499,9 +644,9 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
499
644
|
validationStatus?: ValidationStatus;
|
|
500
645
|
}>;
|
|
501
646
|
/**
|
|
502
|
-
*
|
|
647
|
+
* Apply multiple writes (batch create/update/delete).
|
|
503
648
|
*/
|
|
504
|
-
|
|
649
|
+
applyWrites(writes: Array<{
|
|
505
650
|
$type: string;
|
|
506
651
|
collection: string;
|
|
507
652
|
rkey?: string;
|
|
@@ -520,41 +665,171 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
520
665
|
}>;
|
|
521
666
|
}>;
|
|
522
667
|
/**
|
|
523
|
-
*
|
|
668
|
+
* Get repo status.
|
|
524
669
|
*/
|
|
525
|
-
|
|
670
|
+
getStatus(): Promise<{
|
|
526
671
|
did: string;
|
|
527
672
|
head: string;
|
|
528
673
|
rev: string;
|
|
529
674
|
}>;
|
|
530
675
|
/**
|
|
531
|
-
*
|
|
676
|
+
* Count records in the repository.
|
|
532
677
|
*/
|
|
533
|
-
|
|
678
|
+
countRecords(): Promise<number>;
|
|
534
679
|
/**
|
|
535
|
-
*
|
|
536
|
-
*
|
|
680
|
+
* Activate the account.
|
|
681
|
+
* Emits #account + #identity + #sync per sync 1.1, so relays pick up
|
|
682
|
+
* the new state without polling. #sync is only emitted when a repo
|
|
683
|
+
* root exists (i.e. after migration import or initial commit).
|
|
684
|
+
*/
|
|
685
|
+
activateAccount(): Promise<void>;
|
|
686
|
+
/**
|
|
687
|
+
* Deactivate the account.
|
|
688
|
+
* Emits #account(active=false, status='deactivated') per sync 1.1.
|
|
537
689
|
*/
|
|
538
|
-
|
|
690
|
+
deactivateAccount(): Promise<void>;
|
|
539
691
|
/**
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
* the existence (or non-existence) of a record.
|
|
543
|
-
* Used by com.atproto.sync.getRecord for record verification.
|
|
692
|
+
* Emit an identity event to notify downstream services to refresh
|
|
693
|
+
* identity cache. `handle` is optional per sync 1.1.
|
|
544
694
|
*/
|
|
545
|
-
|
|
695
|
+
emitIdentityEvent(handle?: string): Promise<{
|
|
696
|
+
seq: number;
|
|
697
|
+
}>;
|
|
698
|
+
/**
|
|
699
|
+
* Import a repo from a CAR file. Used for account migration —
|
|
700
|
+
* importing an existing repository from another PDS.
|
|
701
|
+
*/
|
|
702
|
+
importRepo(carBytes: Uint8Array): Promise<{
|
|
703
|
+
did: string;
|
|
704
|
+
rev: string;
|
|
705
|
+
cid: string;
|
|
706
|
+
}>;
|
|
546
707
|
/**
|
|
547
|
-
*
|
|
548
|
-
*
|
|
549
|
-
*
|
|
708
|
+
* Reset migration state.
|
|
709
|
+
* Clears imported repo and blob tracking to allow re-import.
|
|
710
|
+
* Only works when account is deactivated.
|
|
550
711
|
*/
|
|
551
|
-
|
|
712
|
+
resetMigration(): Promise<{
|
|
713
|
+
blocksDeleted: number;
|
|
714
|
+
blobsCleared: number;
|
|
715
|
+
}>;
|
|
716
|
+
}
|
|
717
|
+
//#endregion
|
|
718
|
+
//#region src/repo/facet.d.ts
|
|
719
|
+
/**
|
|
720
|
+
* The repo host's remote surface: the subset of engine and storage
|
|
721
|
+
* operations that is safe to call over Workers RPC. The Durable Object
|
|
722
|
+
* hands this to the Worker as a stub (via repo()); methods returning
|
|
723
|
+
* non-serializable objects (Repo, Keypair) stay off it by design.
|
|
724
|
+
*/
|
|
725
|
+
declare class RepoFacet extends RpcTarget {
|
|
726
|
+
private engine;
|
|
727
|
+
private storage;
|
|
728
|
+
constructor(engine: RepoEngine, storage: SqliteRepoStorage);
|
|
729
|
+
describeRepo(): Promise<{
|
|
730
|
+
did: string;
|
|
731
|
+
collections: string[];
|
|
732
|
+
cid: string;
|
|
733
|
+
}>;
|
|
734
|
+
getRecord(collection: string, rkey: string): Promise<{
|
|
735
|
+
cid: string;
|
|
736
|
+
record: Rpc.Serializable<any>;
|
|
737
|
+
} | null>;
|
|
738
|
+
listRecords(collection: string, opts: {
|
|
739
|
+
limit: number;
|
|
740
|
+
cursor?: string;
|
|
741
|
+
reverse?: boolean;
|
|
742
|
+
}): Promise<{
|
|
743
|
+
records: Array<{
|
|
744
|
+
uri: string;
|
|
745
|
+
cid: string;
|
|
746
|
+
value: unknown;
|
|
747
|
+
}>;
|
|
748
|
+
cursor?: string;
|
|
749
|
+
}>;
|
|
750
|
+
createRecord(collection: string, rkey: string | undefined, record: unknown, validationStatus?: ValidationStatus): Promise<{
|
|
751
|
+
uri: string;
|
|
752
|
+
cid: string;
|
|
753
|
+
commit: {
|
|
754
|
+
cid: string;
|
|
755
|
+
rev: string;
|
|
756
|
+
};
|
|
757
|
+
validationStatus?: ValidationStatus;
|
|
758
|
+
}>;
|
|
759
|
+
deleteRecord(collection: string, rkey: string): Promise<{
|
|
760
|
+
commit: {
|
|
761
|
+
cid: string;
|
|
762
|
+
rev: string;
|
|
763
|
+
};
|
|
764
|
+
} | null>;
|
|
765
|
+
putRecord(collection: string, rkey: string, record: unknown, validationStatus?: ValidationStatus): Promise<{
|
|
766
|
+
uri: string;
|
|
767
|
+
cid: string;
|
|
768
|
+
commit: {
|
|
769
|
+
cid: string;
|
|
770
|
+
rev: string;
|
|
771
|
+
};
|
|
772
|
+
validationStatus?: ValidationStatus;
|
|
773
|
+
}>;
|
|
774
|
+
applyWrites(writes: Array<{
|
|
775
|
+
$type: string;
|
|
776
|
+
collection: string;
|
|
777
|
+
rkey?: string;
|
|
778
|
+
value?: unknown;
|
|
779
|
+
validationStatus?: ValidationStatus;
|
|
780
|
+
}>): Promise<{
|
|
781
|
+
commit: {
|
|
782
|
+
cid: string;
|
|
783
|
+
rev: string;
|
|
784
|
+
};
|
|
785
|
+
results: Array<{
|
|
786
|
+
$type: string;
|
|
787
|
+
uri?: string;
|
|
788
|
+
cid?: string;
|
|
789
|
+
validationStatus?: ValidationStatus;
|
|
790
|
+
}>;
|
|
791
|
+
}>;
|
|
792
|
+
getStatus(): Promise<{
|
|
793
|
+
did: string;
|
|
794
|
+
head: string;
|
|
795
|
+
rev: string;
|
|
796
|
+
}>;
|
|
797
|
+
getActive(): Promise<boolean>;
|
|
798
|
+
countRecords(): Promise<number>;
|
|
799
|
+
activateAccount(): Promise<void>;
|
|
800
|
+
deactivateAccount(): Promise<void>;
|
|
801
|
+
emitIdentityEvent(handle?: string): Promise<{
|
|
802
|
+
seq: number;
|
|
803
|
+
}>;
|
|
804
|
+
importRepo(carBytes: Uint8Array): Promise<{
|
|
552
805
|
did: string;
|
|
553
806
|
rev: string;
|
|
554
807
|
cid: string;
|
|
555
808
|
}>;
|
|
809
|
+
resetMigration(): Promise<{
|
|
810
|
+
blocksDeleted: number;
|
|
811
|
+
blobsCleared: number;
|
|
812
|
+
}>;
|
|
813
|
+
/**
|
|
814
|
+
* Get specific blocks by CID as a CAR file.
|
|
815
|
+
*/
|
|
816
|
+
getBlocks(cids: string[]): Promise<Uint8Array>;
|
|
556
817
|
/**
|
|
557
|
-
*
|
|
818
|
+
* Get a record with proof as a CAR file.
|
|
819
|
+
*/
|
|
820
|
+
getRecordProof(collection: string, rkey: string): Promise<Uint8Array>;
|
|
821
|
+
countBlocks(): Promise<number>;
|
|
822
|
+
countExpectedBlobs(): number;
|
|
823
|
+
countImportedBlobs(): number;
|
|
824
|
+
listMissingBlobs(limit?: number, cursor?: string): {
|
|
825
|
+
blobs: Array<{
|
|
826
|
+
cid: string;
|
|
827
|
+
recordUri: string;
|
|
828
|
+
}>;
|
|
829
|
+
cursor?: string;
|
|
830
|
+
};
|
|
831
|
+
/**
|
|
832
|
+
* Record an already-stored blob's metadata.
|
|
558
833
|
*
|
|
559
834
|
* The blob bytes are written to R2 by the stateless Worker, not here.
|
|
560
835
|
* This DO is single-threaded and also holds the relay's firehose
|
|
@@ -564,140 +839,187 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
564
839
|
* dropping the firehose and desyncing the relay. Only the tiny tracking
|
|
565
840
|
* row needs the DO's SQLite.
|
|
566
841
|
*/
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
842
|
+
trackBlob(cid: string, size: number, mimeType: string): {
|
|
843
|
+
referenced: boolean;
|
|
844
|
+
};
|
|
845
|
+
}
|
|
846
|
+
//#endregion
|
|
847
|
+
//#region src/spaces.d.ts
|
|
848
|
+
/**
|
|
849
|
+
* The account's space DO: host identity comes from the PDS environment.
|
|
850
|
+
* This is the only place `env.DID` crosses into the engine.
|
|
851
|
+
*/
|
|
852
|
+
declare class SpaceDurableObject extends SpaceDurableObject$1<PDSEnv> {
|
|
853
|
+
private keypairPromise;
|
|
854
|
+
protected getHostConfig(): SpaceHostConfig;
|
|
855
|
+
}
|
|
856
|
+
declare class SpaceIndexDurableObject extends SpaceIndexDurableObject$1<PDSEnv> {}
|
|
857
|
+
//#endregion
|
|
858
|
+
//#region src/types.d.ts
|
|
859
|
+
/**
|
|
860
|
+
* Data location options for Durable Object placement.
|
|
861
|
+
*
|
|
862
|
+
* - "auto": No location constraint (default, recommended)
|
|
863
|
+
* - "eu": European Union - hard guarantee data never leaves EU
|
|
864
|
+
* - Location hints (best-effort, not guaranteed):
|
|
865
|
+
* - "wnam": Western North America
|
|
866
|
+
* - "enam": Eastern North America
|
|
867
|
+
* - "sam": South America
|
|
868
|
+
* - "weur": Western Europe
|
|
869
|
+
* - "eeur": Eastern Europe
|
|
870
|
+
* - "apac": Asia-Pacific
|
|
871
|
+
* - "oc": Oceania
|
|
872
|
+
* - "afr": Africa
|
|
873
|
+
* - "me": Middle East
|
|
874
|
+
*
|
|
875
|
+
* IMPORTANT: This setting only affects newly-created Durable Objects.
|
|
876
|
+
* Changing this after initial deployment will NOT migrate existing data.
|
|
877
|
+
* To relocate data, you must export and re-import to a new PDS.
|
|
878
|
+
*/
|
|
879
|
+
type DataLocation = "auto" | "eu" | "wnam" | "enam" | "sam" | "weur" | "eeur" | "apac" | "oc" | "afr" | "me";
|
|
880
|
+
/**
|
|
881
|
+
* Environment bindings required by the PDS worker.
|
|
882
|
+
* Consumers must provide these bindings in their wrangler config.
|
|
883
|
+
*/
|
|
884
|
+
interface PDSEnv {
|
|
885
|
+
/** The account's DID (e.g., did:web:example.com) */
|
|
886
|
+
DID: string;
|
|
887
|
+
/** The account's handle (e.g., alice.example.com) */
|
|
888
|
+
HANDLE: string;
|
|
889
|
+
/** Public hostname of the PDS */
|
|
890
|
+
PDS_HOSTNAME: string;
|
|
891
|
+
/** Bearer token for write operations */
|
|
892
|
+
AUTH_TOKEN: string;
|
|
893
|
+
/** Private signing key (hex-encoded) */
|
|
894
|
+
SIGNING_KEY: string;
|
|
895
|
+
/** Public signing key (multibase-encoded) */
|
|
896
|
+
SIGNING_KEY_PUBLIC: string;
|
|
897
|
+
/** Secret for signing session JWTs */
|
|
898
|
+
JWT_SECRET: string;
|
|
899
|
+
/** Bcrypt hash of account password */
|
|
900
|
+
PASSWORD_HASH: string;
|
|
901
|
+
/** Durable Object namespace for account storage */
|
|
902
|
+
ACCOUNT: DurableObjectNamespace<AccountDurableObject>;
|
|
903
|
+
/** R2 bucket for blob storage (optional) */
|
|
904
|
+
BLOBS?: R2Bucket;
|
|
613
905
|
/**
|
|
614
|
-
*
|
|
906
|
+
* Comma-separated relay URLs to send requestCrawl to when a write
|
|
907
|
+
* commits with no firehose subscriber connected. Defaults to
|
|
908
|
+
* https://bsky.network
|
|
615
909
|
*/
|
|
616
|
-
|
|
617
|
-
preferences: unknown[];
|
|
618
|
-
}>;
|
|
910
|
+
RELAYS?: string;
|
|
619
911
|
/**
|
|
620
|
-
*
|
|
912
|
+
* Atproto spaces (alpha). Unset or anything but "true" disables every
|
|
913
|
+
* space and memberspace route; they fall through to the proxy like any
|
|
914
|
+
* unknown method.
|
|
621
915
|
*/
|
|
622
|
-
|
|
916
|
+
SPACES_ENABLED?: string;
|
|
623
917
|
/**
|
|
624
|
-
*
|
|
918
|
+
* The account's `#atproto_kem` P-256 private key (hex), with which the
|
|
919
|
+
* spaces alpha MACs space data for syncers. Secret.
|
|
625
920
|
*/
|
|
626
|
-
|
|
627
|
-
email: string | null;
|
|
628
|
-
}>;
|
|
921
|
+
SPACES_KEM_KEY?: string;
|
|
629
922
|
/**
|
|
630
|
-
*
|
|
923
|
+
* Public half of SPACES_KEM_KEY (multibase), published as the
|
|
924
|
+
* `#atproto_kem` verification method in the DID document.
|
|
631
925
|
*/
|
|
632
|
-
|
|
926
|
+
SPACES_KEM_KEY_PUBLIC?: string;
|
|
927
|
+
/** Durable Object namespace for spaces (one per space URI). */
|
|
928
|
+
SPACES?: DurableObjectNamespace<SpaceDurableObject>;
|
|
929
|
+
/** Durable Object namespace for the space index singleton. */
|
|
930
|
+
SPACES_INDEX?: DurableObjectNamespace<SpaceIndexDurableObject>;
|
|
931
|
+
/** Account email address (optional, used by some clients) */
|
|
932
|
+
EMAIL?: string;
|
|
933
|
+
/** Initial activation state for new accounts (default: true) */
|
|
934
|
+
INITIAL_ACTIVE?: string;
|
|
633
935
|
/**
|
|
634
|
-
*
|
|
936
|
+
* Data location for Durable Object placement.
|
|
937
|
+
*
|
|
938
|
+
* WARNING: DO NOT CHANGE THIS AFTER INITIAL DEPLOYMENT.
|
|
939
|
+
* This setting only affects newly-created DOs. Changing it will NOT
|
|
940
|
+
* migrate existing data and may cause issues.
|
|
941
|
+
*
|
|
942
|
+
* Options:
|
|
943
|
+
* - "auto" or unset: No location constraint (default, recommended)
|
|
944
|
+
* - "eu": European Union - hard guarantee data never leaves EU
|
|
945
|
+
* - Location hints (best-effort, not guaranteed):
|
|
946
|
+
* "wnam", "enam", "sam", "weur", "eeur", "apac", "oc", "afr", "me"
|
|
635
947
|
*/
|
|
636
|
-
|
|
948
|
+
DATA_LOCATION?: DataLocation;
|
|
949
|
+
}
|
|
950
|
+
//#endregion
|
|
951
|
+
//#region src/account-do.d.ts
|
|
952
|
+
/**
|
|
953
|
+
* Account Durable Object - manages a single user's AT Protocol repository.
|
|
954
|
+
*
|
|
955
|
+
* This DO provides:
|
|
956
|
+
* - SQLite-backed block storage for the repository
|
|
957
|
+
* - AT Protocol Repo instance for repository operations
|
|
958
|
+
* - Firehose WebSocket connections
|
|
959
|
+
* - Sequence number management
|
|
960
|
+
*
|
|
961
|
+
* The Worker talks to it through three RpcTarget facets — repo(),
|
|
962
|
+
* account() and authStore() — plus the fetch handler for WebSocket
|
|
963
|
+
* upgrades and streaming responses.
|
|
964
|
+
*/
|
|
965
|
+
declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
966
|
+
private storage;
|
|
967
|
+
private accountStore;
|
|
968
|
+
private oauthStorage;
|
|
969
|
+
private sequencer;
|
|
970
|
+
private firehose;
|
|
971
|
+
private engine;
|
|
972
|
+
private repoFacet;
|
|
973
|
+
private storageInitialized;
|
|
974
|
+
constructor(ctx: DurableObjectState, env: PDSEnv);
|
|
637
975
|
/**
|
|
638
|
-
*
|
|
639
|
-
* Emits #account + #identity + #sync per sync 1.1, so relays pick up
|
|
640
|
-
* the new state without polling. #sync is only emitted when a repo
|
|
641
|
-
* root exists (i.e. after migration import or initial commit).
|
|
976
|
+
* Initialize the storage adapter. Called lazily on first storage access.
|
|
642
977
|
*/
|
|
643
|
-
|
|
978
|
+
private ensureStorageInitialized;
|
|
644
979
|
/**
|
|
645
|
-
*
|
|
646
|
-
* Emits #account(active=false, status='deactivated') per sync 1.1.
|
|
980
|
+
* Run cleanup on storage to remove expired entries
|
|
647
981
|
*/
|
|
648
|
-
|
|
982
|
+
private runCleanup;
|
|
649
983
|
/**
|
|
650
|
-
*
|
|
984
|
+
* Alarm handler for periodic cleanup
|
|
985
|
+
* Called by Cloudflare Workers when the alarm fires
|
|
651
986
|
*/
|
|
652
|
-
|
|
987
|
+
alarm(): Promise<void>;
|
|
653
988
|
/**
|
|
654
|
-
*
|
|
989
|
+
* Get the storage adapter for direct access (used by tests and internal operations).
|
|
655
990
|
*/
|
|
656
|
-
|
|
991
|
+
getStorage(): Promise<SqliteRepoStorage>;
|
|
657
992
|
/**
|
|
658
|
-
*
|
|
993
|
+
* Get the repo engine for repository operations.
|
|
659
994
|
*/
|
|
660
|
-
|
|
995
|
+
private getEngine;
|
|
661
996
|
/**
|
|
662
|
-
* RPC
|
|
997
|
+
* RPC facet: repository operations (records, sync, migration, blobs).
|
|
663
998
|
*/
|
|
664
|
-
|
|
999
|
+
repo(): Promise<RepoFacet>;
|
|
665
1000
|
/**
|
|
666
|
-
* RPC
|
|
1001
|
+
* RPC facet: person-account data (passkeys, app passwords, preferences, email).
|
|
667
1002
|
*/
|
|
668
|
-
|
|
669
|
-
blobs: Array<{
|
|
670
|
-
cid: string;
|
|
671
|
-
recordUri: string;
|
|
672
|
-
}>;
|
|
673
|
-
cursor?: string;
|
|
674
|
-
}>;
|
|
1003
|
+
account(): Promise<AccountStore>;
|
|
675
1004
|
/**
|
|
676
|
-
* RPC
|
|
677
|
-
*
|
|
678
|
-
* Only works when account is deactivated.
|
|
1005
|
+
* RPC facet: OAuth storage (codes, tokens, clients, PAR, nonces,
|
|
1006
|
+
* permission sets, WebAuthn challenges).
|
|
679
1007
|
*/
|
|
680
|
-
|
|
681
|
-
blocksDeleted: number;
|
|
682
|
-
blobsCleared: number;
|
|
683
|
-
}>;
|
|
1008
|
+
authStore(): Promise<SqliteOAuthStorage>;
|
|
684
1009
|
/**
|
|
685
|
-
*
|
|
686
|
-
* `handle` is optional per sync 1.1.
|
|
1010
|
+
* Get the Repo instance for repository operations.
|
|
687
1011
|
*/
|
|
688
|
-
|
|
689
|
-
seq: number;
|
|
690
|
-
}>;
|
|
1012
|
+
getRepo(): Promise<Repo>;
|
|
691
1013
|
/**
|
|
692
1014
|
* RPC method: Health check - verifies storage is accessible
|
|
693
1015
|
*/
|
|
694
|
-
|
|
1016
|
+
healthCheck(): Promise<{
|
|
695
1017
|
ok: true;
|
|
696
1018
|
}>;
|
|
697
1019
|
/**
|
|
698
1020
|
* RPC method: Firehose status - returns subscriber count and latest sequence
|
|
699
1021
|
*/
|
|
700
|
-
|
|
1022
|
+
getFirehoseStatus(): Promise<{
|
|
701
1023
|
subscribers: Array<{
|
|
702
1024
|
connectedAt: number;
|
|
703
1025
|
cursor: number;
|
|
@@ -705,91 +1027,26 @@ declare class AccountDurableObject extends DurableObject<PDSEnv> {
|
|
|
705
1027
|
}>;
|
|
706
1028
|
latestSeq: number | null;
|
|
707
1029
|
}>;
|
|
708
|
-
/**
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
/**
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
/**
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
/**
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
/**
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
/** Save PAR data */
|
|
729
|
-
rpcSavePAR(requestUri: string, data: _getcirrus_oauth_provider0.PARData): Promise<void>;
|
|
730
|
-
/** Get PAR data */
|
|
731
|
-
rpcGetPAR(requestUri: string): Promise<_getcirrus_oauth_provider0.PARData | null>;
|
|
732
|
-
/** Delete PAR data */
|
|
733
|
-
rpcDeletePAR(requestUri: string): Promise<void>;
|
|
734
|
-
/** Check and save DPoP nonce */
|
|
735
|
-
rpcCheckAndSaveNonce(nonce: string): Promise<boolean>;
|
|
736
|
-
/**
|
|
737
|
-
* Look up a cached permission-set lexicon by NSID. Returns the cached
|
|
738
|
-
* value (with `stale: true` when past its 24h soft-expiry) or null when
|
|
739
|
-
* not cached or hard-expired.
|
|
740
|
-
*/
|
|
741
|
-
rpcGetPermissionSet(nsid: string): Promise<CachedPermissionSet | null>;
|
|
742
|
-
/** Cache a fetched permission-set lexicon. */
|
|
743
|
-
rpcSavePermissionSet(nsid: string, set: _getcirrus_oauth_provider0.LexiconPermissionSet): Promise<void>;
|
|
744
|
-
/** Save a passkey credential */
|
|
745
|
-
rpcSavePasskey(credentialId: string, publicKey: Uint8Array, counter: number, name?: string): Promise<void>;
|
|
746
|
-
/** Get a passkey by credential ID */
|
|
747
|
-
rpcGetPasskey(credentialId: string): Promise<{
|
|
748
|
-
credentialId: string;
|
|
749
|
-
publicKey: Uint8Array;
|
|
750
|
-
counter: number;
|
|
751
|
-
name: string | null;
|
|
752
|
-
createdAt: string;
|
|
753
|
-
lastUsedAt: string | null;
|
|
754
|
-
} | null>;
|
|
755
|
-
/** List all passkeys */
|
|
756
|
-
rpcListPasskeys(): Promise<Array<{
|
|
757
|
-
credentialId: string;
|
|
758
|
-
name: string | null;
|
|
759
|
-
createdAt: string;
|
|
760
|
-
lastUsedAt: string | null;
|
|
761
|
-
}>>;
|
|
762
|
-
/** Delete a passkey */
|
|
763
|
-
rpcDeletePasskey(credentialId: string): Promise<boolean>;
|
|
764
|
-
/** Update passkey counter after authentication */
|
|
765
|
-
rpcUpdatePasskeyCounter(credentialId: string, counter: number): Promise<void>;
|
|
766
|
-
/** Check if passkeys exist */
|
|
767
|
-
rpcHasPasskeys(): Promise<boolean>;
|
|
768
|
-
/** Save a registration token */
|
|
769
|
-
rpcSavePasskeyToken(token: string, challenge: string, expiresAt: number, name?: string): Promise<void>;
|
|
770
|
-
/** Consume a registration token */
|
|
771
|
-
rpcConsumePasskeyToken(token: string): Promise<{
|
|
772
|
-
challenge: string;
|
|
773
|
-
name: string | null;
|
|
774
|
-
} | null>;
|
|
775
|
-
/** Save a WebAuthn challenge for passkey authentication */
|
|
776
|
-
rpcSaveWebAuthnChallenge(challenge: string): Promise<void>;
|
|
777
|
-
/** Consume a WebAuthn challenge (single-use) */
|
|
778
|
-
rpcConsumeWebAuthnChallenge(challenge: string): Promise<boolean>;
|
|
779
|
-
/** Save an app password (bcrypt hash) */
|
|
780
|
-
rpcSaveAppPassword(name: string, passwordHash: string): Promise<void>;
|
|
781
|
-
/** List all app passwords (names and dates only) */
|
|
782
|
-
rpcListAppPasswords(): Promise<Array<{
|
|
783
|
-
name: string;
|
|
784
|
-
createdAt: string;
|
|
785
|
-
}>>;
|
|
786
|
-
/** Delete an app password by name */
|
|
787
|
-
rpcDeleteAppPassword(name: string): Promise<boolean>;
|
|
788
|
-
/** Get all app password hashes for login verification */
|
|
789
|
-
rpcGetAppPasswordHashes(): Promise<Array<{
|
|
790
|
-
name: string;
|
|
791
|
-
passwordHash: string;
|
|
792
|
-
}>>;
|
|
1030
|
+
/**
|
|
1031
|
+
* Handle streaming getRepo via fetch (not RPC, to enable streaming response).
|
|
1032
|
+
*/
|
|
1033
|
+
private handleGetRepo;
|
|
1034
|
+
/**
|
|
1035
|
+
* Handle WebSocket upgrade for firehose (subscribeRepos).
|
|
1036
|
+
*/
|
|
1037
|
+
handleFirehoseUpgrade(request: Request): Promise<Response>;
|
|
1038
|
+
/**
|
|
1039
|
+
* WebSocket message handler (hibernation API).
|
|
1040
|
+
*/
|
|
1041
|
+
webSocketMessage(_ws: WebSocket, _message: string | ArrayBuffer): void;
|
|
1042
|
+
/**
|
|
1043
|
+
* WebSocket close handler (hibernation API).
|
|
1044
|
+
*/
|
|
1045
|
+
webSocketClose(_ws: WebSocket, _code: number, _reason: string, _wasClean: boolean): void;
|
|
1046
|
+
/**
|
|
1047
|
+
* WebSocket error handler (hibernation API).
|
|
1048
|
+
*/
|
|
1049
|
+
webSocketError(_ws: WebSocket, error: Error): void;
|
|
793
1050
|
/**
|
|
794
1051
|
* HTTP fetch handler for WebSocket upgrades and streaming responses.
|
|
795
1052
|
* Used instead of RPC when the response can't be serialized (WebSocket)
|
|
@@ -803,5 +1060,5 @@ declare const app: Hono<{
|
|
|
803
1060
|
Bindings: PDSEnv;
|
|
804
1061
|
}, hono_types0.BlankSchema, "/">;
|
|
805
1062
|
//#endregion
|
|
806
|
-
export { AccountDurableObject, type DataLocation, type PDSEnv, app as default };
|
|
1063
|
+
export { AccountDurableObject, type DataLocation, type PDSEnv, SpaceDurableObject, SpaceIndexDurableObject, app as default };
|
|
807
1064
|
//# sourceMappingURL=index.d.ts.map
|