@colibri-social/space 0.1.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.
Files changed (51) hide show
  1. package/README.md +78 -0
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/credentials.d.ts +43 -0
  4. package/dist/credentials.d.ts.map +1 -0
  5. package/dist/credentials.js +120 -0
  6. package/dist/credentials.js.map +1 -0
  7. package/dist/dpop.d.ts +15 -0
  8. package/dist/dpop.d.ts.map +1 -0
  9. package/dist/dpop.js +32 -0
  10. package/dist/dpop.js.map +1 -0
  11. package/dist/errors.d.ts +21 -0
  12. package/dist/errors.d.ts.map +1 -0
  13. package/dist/errors.js +41 -0
  14. package/dist/errors.js.map +1 -0
  15. package/dist/host.d.ts +21 -0
  16. package/dist/host.d.ts.map +1 -0
  17. package/dist/host.js +48 -0
  18. package/dist/host.js.map +1 -0
  19. package/dist/http.d.ts +40 -0
  20. package/dist/http.d.ts.map +1 -0
  21. package/dist/http.js +103 -0
  22. package/dist/http.js.map +1 -0
  23. package/dist/index.d.ts +12 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/index.js +12 -0
  26. package/dist/index.js.map +1 -0
  27. package/dist/pds.d.ts +125 -0
  28. package/dist/pds.d.ts.map +1 -0
  29. package/dist/pds.js +131 -0
  30. package/dist/pds.js.map +1 -0
  31. package/dist/repo.d.ts +30 -0
  32. package/dist/repo.d.ts.map +1 -0
  33. package/dist/repo.js +33 -0
  34. package/dist/repo.js.map +1 -0
  35. package/dist/session.d.ts +26 -0
  36. package/dist/session.d.ts.map +1 -0
  37. package/dist/session.js +57 -0
  38. package/dist/session.js.map +1 -0
  39. package/dist/space-client.d.ts +92 -0
  40. package/dist/space-client.d.ts.map +1 -0
  41. package/dist/space-client.js +137 -0
  42. package/dist/space-client.js.map +1 -0
  43. package/dist/space-ref.d.ts +20 -0
  44. package/dist/space-ref.d.ts.map +1 -0
  45. package/dist/space-ref.js +55 -0
  46. package/dist/space-ref.js.map +1 -0
  47. package/dist/tid.d.ts +3 -0
  48. package/dist/tid.d.ts.map +1 -0
  49. package/dist/tid.js +4 -0
  50. package/dist/tid.js.map +1 -0
  51. package/package.json +42 -0
@@ -0,0 +1,137 @@
1
+ import { fromBase64 } from "@atproto/lex-data";
2
+ import { XrpcClient } from "./http.js";
3
+ import { parseSpaceRef } from "./space-ref.js";
4
+ export const decodeSignedCommit = (wire) => ({
5
+ ver: wire.ver,
6
+ hash: fromBase64(wire.hash.$bytes),
7
+ ikm: fromBase64(wire.ikm.$bytes),
8
+ sig: fromBase64(wire.sig.$bytes),
9
+ mac: fromBase64(wire.mac.$bytes),
10
+ rev: wire.rev,
11
+ });
12
+ export class SpaceClient {
13
+ options;
14
+ clients = new Map();
15
+ constructor(options) {
16
+ this.options = options;
17
+ }
18
+ clientFor(service) {
19
+ const existing = this.clients.get(service);
20
+ if (existing)
21
+ return existing;
22
+ const client = new XrpcClient({
23
+ service,
24
+ fetch: this.options.fetch,
25
+ timeoutMs: this.options.timeoutMs,
26
+ });
27
+ this.clients.set(service, client);
28
+ return client;
29
+ }
30
+ async authFor(space) {
31
+ const credential = await this.options.credentials.acquire(space);
32
+ return {
33
+ auth: { kind: "dpopCredential", credential: credential.credential, key: credential.key },
34
+ credential,
35
+ };
36
+ }
37
+ hostForAuthority(space) {
38
+ return this.options.hosts.hostFor(parseSpaceRef(space).authority);
39
+ }
40
+ async listRepos(space, options = {}) {
41
+ const client = this.clientFor(await this.hostForAuthority(space));
42
+ const { auth } = await this.authFor(space);
43
+ const response = await client.query("com.atproto.space.listRepos", { space, ...options }, auth);
44
+ return {
45
+ repos: response.repos.map((repo) => ({
46
+ did: repo.did,
47
+ rev: repo.rev,
48
+ hash: fromBase64(repo.hash.$bytes),
49
+ })),
50
+ cursor: response.cursor ?? null,
51
+ };
52
+ }
53
+ async *allRepos(space) {
54
+ let cursor;
55
+ do {
56
+ const page = await this.listRepos(space, { limit: 1000, cursor });
57
+ yield* page.repos;
58
+ cursor = page.cursor ?? undefined;
59
+ } while (cursor);
60
+ }
61
+ async listRepoOps(space, repoHost, repo, options = {}) {
62
+ const client = this.clientFor(repoHost);
63
+ const { auth } = await this.authFor(space);
64
+ const response = await client.query("com.atproto.space.listRepoOps", { space, repo, ...options }, auth);
65
+ return {
66
+ ops: response.ops,
67
+ commit: response.commit ? decodeSignedCommit(response.commit) : null,
68
+ cursor: response.cursor ?? null,
69
+ };
70
+ }
71
+ async getLatestCommit(space, repoHost, repo) {
72
+ const client = this.clientFor(repoHost);
73
+ const { auth } = await this.authFor(space);
74
+ const response = await client.query("com.atproto.space.getLatestCommit", { space, repo }, auth);
75
+ return response.commit ? decodeSignedCommit(response.commit) : null;
76
+ }
77
+ async getRepoCar(space, repoHost, repo) {
78
+ const client = this.clientFor(repoHost);
79
+ const { auth } = await this.authFor(space);
80
+ const response = await client.stream("com.atproto.space.getRepo", { space, repo }, auth);
81
+ return streamBytes(response);
82
+ }
83
+ async getRecord(space, repoHost, repo, collection, rkey) {
84
+ const client = this.clientFor(repoHost);
85
+ const { auth } = await this.authFor(space);
86
+ return client.query("com.atproto.space.getRecord", { space, repo, collection, rkey }, auth);
87
+ }
88
+ async listRecords(space, repoHost, repo, options = {}) {
89
+ const client = this.clientFor(repoHost);
90
+ const { auth } = await this.authFor(space);
91
+ const response = await client.query("com.atproto.space.listRecords", { space, repo, ...options }, auth);
92
+ return { records: response.records, cursor: response.cursor ?? null };
93
+ }
94
+ async getBlob(space, repoHost, repo, cid) {
95
+ const client = this.clientFor(repoHost);
96
+ const { auth } = await this.authFor(space);
97
+ return client.stream("com.atproto.space.getBlob", { space, did: repo, cid }, auth);
98
+ }
99
+ async listBlobs(space, repoHost, repo, options = {}) {
100
+ const client = this.clientFor(repoHost);
101
+ const { auth } = await this.authFor(space);
102
+ const response = await client.query("com.atproto.space.listBlobs", { space, repo, ...options }, auth);
103
+ return { cids: response.cids, cursor: response.cursor ?? null };
104
+ }
105
+ async registerNotify(space, service) {
106
+ const client = this.clientFor(await this.hostForAuthority(space));
107
+ const { auth } = await this.authFor(space);
108
+ const response = await client.procedure("com.atproto.space.registerNotify", { space, service }, auth);
109
+ return { expiresAt: new Date(response.expiresAt) };
110
+ }
111
+ async unregisterNotify(space, service) {
112
+ const client = this.clientFor(await this.hostForAuthority(space));
113
+ const { auth } = await this.authFor(space);
114
+ await client.procedure("com.atproto.space.unregisterNotify", { space, service }, auth);
115
+ }
116
+ }
117
+ const streamBytes = (response) => {
118
+ const body = response.body;
119
+ if (!body)
120
+ return (async function* () { })();
121
+ return (async function* () {
122
+ const reader = body.getReader();
123
+ try {
124
+ while (true) {
125
+ const { done, value } = await reader.read();
126
+ if (done)
127
+ return;
128
+ if (value)
129
+ yield value;
130
+ }
131
+ }
132
+ finally {
133
+ reader.releaseLock();
134
+ }
135
+ })();
136
+ };
137
+ //# sourceMappingURL=space-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space-client.js","sourceRoot":"","sources":["../src/space-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI/C,OAAO,EAAa,UAAU,EAAE,MAAM,WAAW,CAAC;AAClD,OAAO,EAAE,aAAa,EAAuB,MAAM,gBAAgB,CAAC;AAapE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAsB,EAAgB,EAAE,CAAC,CAAC;IAC5E,GAAG,EAAE,IAAI,CAAC,GAAQ;IAClB,IAAI,EAAE,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC;IAClC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IAChC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IAChC,GAAG,EAAE,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC;IAChC,GAAG,EAAE,IAAI,CAAC,GAAG;CACb,CAAC,CAAC;AAoCH,MAAM,OAAO,W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EAA6B,EAAE;IACrE,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;IAC3B,IAAI,CAAC,IAAI;QAAE,OAAO,CAAC,KAAK,SAAS,CAAC,MAAK,CAAC,CAAC,EAAE,CAAC;IAC5C,OAAO,CAAC,KAAK,SAAS,CAAC;QACtB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC;QAChC,IAAI,CAAC;YACJ,OAAO,IAAI,EAAE,CAAC;gBACb,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;gBAC5C,IAAI,IAAI;oBAAE,OAAO;gBACjB,IAAI,KAAK;oBAAE,MAAM,KAAK,CAAC;YACxB,CAAC;QACF,CAAC;gBAAS,CAAC;YACV,MAAM,CAAC,WAAW,EAAE,CAAC;QACtB,CAAC;IACF,CAAC,CAAC,EAAE,CAAC;AACN,CAAC,CAAC"}
@@ -0,0 +1,20 @@
1
+ export type SpaceRefString = string;
2
+ export type SpaceRecordUri = string;
3
+ export type ParsedSpaceRef = {
4
+ authority: string;
5
+ spaceType: string;
6
+ skey: string;
7
+ uri: SpaceRefString;
8
+ };
9
+ export type ParsedSpaceRecord = ParsedSpaceRef & {
10
+ author: string;
11
+ collection: string;
12
+ rkey: string;
13
+ };
14
+ export declare const spaceRef: (authority: string, spaceType: string, skey: string) => SpaceRefString;
15
+ export declare const parseSpaceRef: (value: string) => ParsedSpaceRef;
16
+ export declare const tryParseSpaceRef: (value: string) => ParsedSpaceRef | null;
17
+ export declare const spaceRecordUri: (space: SpaceRefString, author: string, collection: string, rkey: string) => SpaceRecordUri;
18
+ export declare const parseSpaceRecordUri: (value: string) => ParsedSpaceRecord;
19
+ export declare const recordPath: (collection: string, rkey: string) => string;
20
+ //# sourceMappingURL=space-ref.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space-ref.d.ts","sourceRoot":"","sources":["../src/space-ref.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AACpC,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC;AAepC,MAAM,MAAM,cAAc,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,cAAc,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,cAAc,GAAG;IAChD,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;CACb,CAAC;AAEF,eAAO,MAAM,QAAQ,cAAe,MAAM,aAAa,MAAM,QAAQ,MAAM,KAAG,cACX,CAAC;AAEpE,eAAO,MAAM,aAAa,UAAW,MAAM,KAAG,cAa7C,CAAC;AAEF,eAAO,MAAM,gBAAgB,UAAW,MAAM,KAAG,cAAc,GAAG,IAMjE,CAAC;AAEF,eAAO,MAAM,cAAc,UACnB,cAAc,UACb,MAAM,cACF,MAAM,QACZ,MAAM,KACV,cAGF,CAAC;AAEF,eAAO,MAAM,mBAAmB,UAAW,MAAM,KAAG,iBAanD,CAAC;AAEF,eAAO,MAAM,UAAU,eAAgB,MAAM,QAAQ,MAAM,WAA4B,CAAC"}
@@ -0,0 +1,55 @@
1
+ import { AtUri, ensureValidDid, ensureValidNsid, SpaceRef } from "@atproto/syntax";
2
+ import { SpaceRefError } from "./errors.js";
3
+ const asDid = (value) => {
4
+ ensureValidDid(value);
5
+ return value;
6
+ };
7
+ const asNsid = (value) => {
8
+ ensureValidNsid(value);
9
+ return value;
10
+ };
11
+ export const spaceRef = (authority, spaceType, skey) => new SpaceRef(asDid(authority), asNsid(spaceType), skey).toString();
12
+ export const parseSpaceRef = (value) => {
13
+ let parsed;
14
+ try {
15
+ parsed = SpaceRef.parse(value);
16
+ }
17
+ catch {
18
+ throw new SpaceRefError(value);
19
+ }
20
+ return {
21
+ authority: parsed.spaceDid,
22
+ spaceType: parsed.spaceType,
23
+ skey: parsed.skey,
24
+ uri: parsed.toString(),
25
+ };
26
+ };
27
+ export const tryParseSpaceRef = (value) => {
28
+ try {
29
+ return parseSpaceRef(value);
30
+ }
31
+ catch {
32
+ return null;
33
+ }
34
+ };
35
+ export const spaceRecordUri = (space, author, collection, rkey) => {
36
+ const { authority, spaceType, skey } = parseSpaceRef(space);
37
+ return AtUri.makeSpace(authority, spaceType, skey, author, collection, rkey).toString();
38
+ };
39
+ export const parseSpaceRecordUri = (value) => {
40
+ const uri = new AtUri(value);
41
+ const ref = uri.spaceRef();
42
+ if (!ref || !uri.authorDid || !uri.collection || !uri.rkey)
43
+ throw new SpaceRefError(value);
44
+ return {
45
+ authority: ref.spaceDid,
46
+ spaceType: ref.spaceType,
47
+ skey: ref.skey,
48
+ uri: ref.toString(),
49
+ author: uri.authorDid,
50
+ collection: uri.collection,
51
+ rkey: uri.rkey,
52
+ };
53
+ };
54
+ export const recordPath = (collection, rkey) => `${collection}/${rkey}`;
55
+ //# sourceMappingURL=space-ref.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"space-ref.js","sourceRoot":"","sources":["../src/space-ref.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAQ5C,MAAM,KAAK,GAAG,CAAC,KAAa,EAAa,EAAE;IAC1C,cAAc,CAAC,KAAK,CAAC,CAAC;IACtB,OAAO,KAAkB,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,MAAM,GAAG,CAAC,KAAa,EAAc,EAAE;IAC5C,eAAe,CAAC,KAAK,CAAC,CAAC;IACvB,OAAO,KAAmB,CAAC;AAC5B,CAAC,CAAC;AAeF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,SAAiB,EAAE,SAAiB,EAAE,IAAY,EAAkB,EAAE,CAC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AC,CAAC;IAC7B,MAAM,GAAG,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;IAC3B,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,SAAS,IAAI,CAAC,GAAG,CAAC,UAAU,IAAI,CAAC,GAAG,CAAC,IAAI;QAAE,MAAM,IAAI,aAAa,CAAC,KAAK,CAAC,CAAC;IAC3F,OAAO;QACN,SAAS,EAAE,GAAG,CAAC,QAAQ;QACvB,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,IAAI,EAAE,GAAG,CAAC,IAAI;QACd,GAAG,EAAE,GAAG,CAAC,QAAQ,EAAE;QACnB,MAAM,EAAE,GAAG,CAAC,SAAS;QACrB,UAAU,EAAE,GAAG,CAAC,UAAU;QAC1B,IAAI,EAAE,GAAG,CAAC,IAAI;KACd,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,UAAkB,EAAE,IAAY,EAAE,EAAE,CAAC,GAAG,UAAU,IAAI,IAAI,EAAE,CAAC"}
package/dist/tid.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export declare const nextTid: () => string;
2
+ export declare const isTid: (value: string) => boolean;
3
+ //# sourceMappingURL=tid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tid.d.ts","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,QAAO,MAAuB,CAAC;AAEnD,eAAO,MAAM,KAAK,UAAW,MAAM,KAAG,OAAwB,CAAC"}
package/dist/tid.js ADDED
@@ -0,0 +1,4 @@
1
+ import { TID } from "@atproto/common";
2
+ export const nextTid = () => TID.nextStr();
3
+ export const isTid = (value) => TID.is(value);
4
+ //# sourceMappingURL=tid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tid.js","sourceRoot":"","sources":["../src/tid.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAEtC,MAAM,CAAC,MAAM,OAAO,GAAG,GAAW,EAAE,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;AAEnD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,KAAa,EAAW,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@colibri-social/space",
3
+ "version": "0.1.0",
4
+ "description": "Client for com.atproto.space and com.atproto.simplespace: delegation tokens, DPoP-bound space credentials, and verified repo reads",
5
+ "type": "module",
6
+ "exports": {
7
+ ".": {
8
+ "types": "./dist/index.d.ts",
9
+ "colibri-source": "./src/index.ts",
10
+ "default": "./dist/index.js"
11
+ }
12
+ },
13
+ "main": "./dist/index.js",
14
+ "types": "./dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "license": "MIT",
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/colibri-social/api.git",
22
+ "directory": "packages/space"
23
+ },
24
+ "publishConfig": {
25
+ "access": "public"
26
+ },
27
+ "dependencies": {
28
+ "@atproto/common": "0.0.0-spaces-alpha-20260818163953",
29
+ "@atproto/crypto": "0.0.0-spaces-alpha-20260818163953",
30
+ "@atproto/identity": "0.0.0-spaces-alpha-20260818163953",
31
+ "@atproto/jwk": "^0.7.4",
32
+ "@atproto/jwk-jose": "^0.2.4",
33
+ "@atproto/lex-data": "^0.1.7",
34
+ "@atproto/space": "0.0.0-spaces-alpha-20260818163953",
35
+ "@atproto/syntax": "0.0.0-spaces-alpha-20260818163953",
36
+ "undici": "^8.10.0"
37
+ },
38
+ "scripts": {
39
+ "build": "tsc --build",
40
+ "clean": "tsc --build --clean"
41
+ }
42
+ }