kitty-agent 9.0.0 → 9.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.
Files changed (73) hide show
  1. package/out/agent.d.ts +206 -0
  2. package/out/agent.d.ts.map +1 -0
  3. package/out/agent.js +329 -0
  4. package/out/agent.js.map +1 -0
  5. package/out/cid.d.ts +5 -0
  6. package/out/cid.d.ts.map +1 -0
  7. package/out/cid.js +38 -0
  8. package/out/cid.js.map +1 -0
  9. package/out/handles/did-document.d.ts +41 -0
  10. package/out/handles/did-document.d.ts.map +1 -0
  11. package/out/handles/did-document.js +101 -0
  12. package/out/handles/did-document.js.map +1 -0
  13. package/out/handles/doh.d.ts +3 -0
  14. package/out/handles/doh.d.ts.map +1 -0
  15. package/out/handles/doh.js +77 -0
  16. package/out/handles/doh.js.map +1 -0
  17. package/out/handles/http.d.ts +3 -0
  18. package/out/handles/http.d.ts.map +1 -0
  19. package/out/handles/http.js +15 -0
  20. package/out/handles/http.js.map +1 -0
  21. package/out/handles/index.d.ts +3 -0
  22. package/out/handles/index.d.ts.map +1 -0
  23. package/out/handles/index.js +4 -0
  24. package/out/handles/index.js.map +1 -0
  25. package/out/handles/resolve.d.ts +2 -0
  26. package/out/handles/resolve.d.ts.map +1 -0
  27. package/out/handles/resolve.js +24 -0
  28. package/out/handles/resolve.js.map +1 -0
  29. package/out/index.d.ts +8 -0
  30. package/out/index.d.ts.map +1 -0
  31. package/out/index.js +8 -0
  32. package/out/index.js.map +1 -0
  33. package/out/oauth-nanostores.d.ts +309 -0
  34. package/out/oauth-nanostores.d.ts.map +1 -0
  35. package/out/oauth-nanostores.js +44 -0
  36. package/out/oauth-nanostores.js.map +1 -0
  37. package/out/oauth-solidjs.d.ts +74 -0
  38. package/out/oauth-solidjs.d.ts.map +1 -0
  39. package/out/oauth-solidjs.js +57 -0
  40. package/out/oauth-solidjs.js.map +1 -0
  41. package/out/oauth-stateful-base.d.ts +47 -0
  42. package/out/oauth-stateful-base.d.ts.map +1 -0
  43. package/out/oauth-stateful-base.js +58 -0
  44. package/out/oauth-stateful-base.js.map +1 -0
  45. package/out/oauth-svelte.d.ts +79 -0
  46. package/out/oauth-svelte.d.ts.map +1 -0
  47. package/out/oauth-svelte.js +102 -0
  48. package/out/oauth-svelte.js.map +1 -0
  49. package/out/oauth.d.ts +13 -0
  50. package/out/oauth.d.ts.map +1 -0
  51. package/out/oauth.js +79 -0
  52. package/out/oauth.js.map +1 -0
  53. package/out/pds-helpers.d.ts +8 -0
  54. package/out/pds-helpers.d.ts.map +1 -0
  55. package/out/pds-helpers.js +16 -0
  56. package/out/pds-helpers.js.map +1 -0
  57. package/out/rkey.d.ts +5 -0
  58. package/out/rkey.d.ts.map +1 -0
  59. package/out/rkey.js +10 -0
  60. package/out/rkey.js.map +1 -0
  61. package/out/sample-authenticated-client.d.ts +19 -0
  62. package/out/sample-authenticated-client.d.ts.map +1 -0
  63. package/out/sample-authenticated-client.js +13 -0
  64. package/out/sample-authenticated-client.js.map +1 -0
  65. package/out/shortid.d.ts +22 -0
  66. package/out/shortid.d.ts.map +1 -0
  67. package/out/shortid.js +50 -0
  68. package/out/shortid.js.map +1 -0
  69. package/out/type-helpers.d.ts +8 -0
  70. package/out/type-helpers.d.ts.map +1 -0
  71. package/out/type-helpers.js +3 -0
  72. package/out/type-helpers.js.map +1 -0
  73. package/package.json +3 -11
package/out/agent.d.ts ADDED
@@ -0,0 +1,206 @@
1
+ import { CredentialManager, Client, type ClientOptions, type CallRequestOptions, type ClientResponse, type ProcedureRequestOptions, type QueryRequestOptions } from "@atcute/client";
2
+ import { AtUri } from "@atproto/syntax";
3
+ import type { Records, XRPCProcedures, XRPCQueries } from "@atcute/lexicons/ambient";
4
+ import type { XRPCQueryMetadata, XRPCProcedureMetadata } from "@atcute/lexicons/validations";
5
+ import type { HasRequiredKeys, Namespaced } from "./type-helpers.js";
6
+ import type { ComAtprotoRepoApplyWrites, ComAtprotoRepoCreateRecord, ComAtprotoRepoDeleteRecord, ComAtprotoRepoGetRecord, ComAtprotoRepoListRecords, ComAtprotoRepoPutRecord, ComAtprotoSyncGetBlob } from '@atcute/atproto';
7
+ import type { ActorIdentifier, Blob, Cid, Did, ResourceUri } from "@atcute/lexicons";
8
+ import * as v from '@atcute/lexicons/validations';
9
+ interface GetRecordParams<K extends keyof Records> extends ComAtprotoRepoGetRecord.$params {
10
+ collection: K;
11
+ }
12
+ interface ListRecordsParams<K extends keyof Records> extends ComAtprotoRepoListRecords.$params {
13
+ collection: K;
14
+ }
15
+ interface PutRecordInput<K extends keyof Records> extends ComAtprotoRepoPutRecord.$input {
16
+ collection: K;
17
+ record: v.InferInput<Records[K]>;
18
+ }
19
+ interface CreateRecordInput<K extends keyof Records> extends ComAtprotoRepoCreateRecord.$input {
20
+ collection: K;
21
+ record: v.InferInput<Records[K]>;
22
+ }
23
+ interface DeleteRecordInput<K extends keyof Records> extends ComAtprotoRepoDeleteRecord.$input {
24
+ collection: K;
25
+ }
26
+ interface GetRecordOutput<K extends keyof Records> {
27
+ cid?: Cid;
28
+ readonly uri: AtUri;
29
+ value: v.InferInput<Records[K]>;
30
+ }
31
+ interface ListRecordsOutput<K extends keyof Records> {
32
+ records: {
33
+ cid: Cid;
34
+ readonly uri: AtUri;
35
+ value: v.InferInput<Records[K]>;
36
+ }[];
37
+ cursor?: string | undefined;
38
+ }
39
+ export declare function isInvalidSwapError(err: unknown): boolean;
40
+ export declare function isRecordNotFoundError(err: unknown): boolean;
41
+ export declare class KittyAgent {
42
+ readonly xrpc: Client;
43
+ constructor(opts: ClientOptions | Client);
44
+ /**
45
+ * Gets a read-only client for bsky.social PDSes.
46
+ */
47
+ static createUnauthed(service?: string): KittyAgent;
48
+ /**
49
+ * Gets a read-only client for the Bluesky AppView.
50
+ */
51
+ static createAppview(service?: string): KittyAgent;
52
+ private static readonly pdsAgentCache;
53
+ /**
54
+ * Gets a read-only client for the PDS hosting a specific account via handle or DID.
55
+ */
56
+ static getOrCreatePds(handleOrDid: string): Promise<KittyAgent>;
57
+ /**
58
+ * Gets an authenticated client for the PDS hosting a specific account via handle or DID.
59
+ */
60
+ static createPdsWithCredentials(handleOrDid: string): Promise<{
61
+ did: `did:${string}:${string}`;
62
+ manager: CredentialManager;
63
+ agent: KittyAgent;
64
+ }>;
65
+ /**
66
+ * clones this XRPC client
67
+ * @param opts options to merge with
68
+ * @returns the cloned XRPC client
69
+ */
70
+ clone({ handler, proxy }?: Partial<ClientOptions>): KittyAgent;
71
+ /**
72
+ * performs an XRPC query request (HTTP GET)
73
+ * @param name NSID of the query
74
+ * @param options query options
75
+ */
76
+ get<TName extends keyof XRPCQueries, TInit extends QueryRequestOptions<XRPCQueries[TName]>>(name: TName, ...options: HasRequiredKeys<TInit> extends true ? [init: TInit] : [init?: TInit]): Promise<ClientResponse<XRPCQueries[TName], TInit>>;
77
+ /**
78
+ * performs an XRPC procedure request (HTTP POST)
79
+ * @param name NSID of the procedure
80
+ * @param options procedure options
81
+ */
82
+ post<TName extends keyof XRPCProcedures, TInit extends ProcedureRequestOptions<XRPCProcedures[TName]>>(name: TName, ...options: HasRequiredKeys<TInit> extends true ? [init: TInit] : [init?: TInit]): Promise<ClientResponse<XRPCProcedures[TName], TInit>>;
83
+ /**
84
+ * performs an XRPC call with schema validation
85
+ * @param schema the lexicon schema for the endpoint, or a namespace containing mainSchema
86
+ * @param options call options
87
+ */
88
+ call<TMeta extends XRPCQueryMetadata | XRPCProcedureMetadata, TInit extends CallRequestOptions<TMeta>>(schema: TMeta | Namespaced<TMeta>, ...options: HasRequiredKeys<TInit> extends true ? [init: TInit] : [init?: TInit]): Promise<ClientResponse<TMeta, TInit>>;
89
+ private makeRecordTyped;
90
+ private makeRecordsTyped;
91
+ getRecord<K extends keyof Records>(params: GetRecordParams<K>): Promise<GetRecordOutput<K>>;
92
+ getBlob(params: ComAtprotoSyncGetBlob.$params | {
93
+ did: Did;
94
+ cid: Blob;
95
+ }): Promise<Uint8Array | string>;
96
+ /**
97
+ * Atcute likes to return blobs as text sometimes. I don't know why yet. This returns them as binary if that
98
+ * happens.
99
+ */
100
+ getBlobAsBinary(params: ComAtprotoSyncGetBlob.$params | {
101
+ did: Did;
102
+ cid: Blob;
103
+ }): Promise<Uint8Array<ArrayBufferLike>>;
104
+ /**
105
+ * Atcute likes to return blobs as text sometimes. I don't know why yet. This returns them as text no matter what,
106
+ * and also allows you to specify an encoding.
107
+ */
108
+ getBlobAsText(params: ComAtprotoSyncGetBlob.$params | {
109
+ did: Did;
110
+ cid: Blob;
111
+ }, encoding?: string): Promise<string>;
112
+ tryGetRecord<K extends keyof Records>(params: GetRecordParams<K>): Promise<GetRecordOutput<K> | {
113
+ uri: undefined;
114
+ value: undefined;
115
+ cid: undefined;
116
+ }>;
117
+ list<K extends keyof Records>(params: ListRecordsParams<K>): Promise<ListRecordsOutput<K>>;
118
+ put<K extends keyof Records>(params: PutRecordInput<K>): Promise<{
119
+ cid: string;
120
+ uri: ResourceUri;
121
+ commit?: {
122
+ cid: string;
123
+ rev: string;
124
+ $type?: "com.atproto.repo.defs#commitMeta" | undefined;
125
+ } | undefined;
126
+ validationStatus?: "unknown" | (string & {}) | "valid" | undefined;
127
+ }>;
128
+ uploadBlob(buf: Uint8Array | globalThis.Blob): Promise<Blob<string>>;
129
+ trySwap<K extends keyof Records>(params: PutRecordInput<K>): Promise<boolean>;
130
+ create<K extends keyof Records>(params: CreateRecordInput<K>): Promise<{
131
+ cid: string;
132
+ uri: ResourceUri;
133
+ commit?: {
134
+ cid: string;
135
+ rev: string;
136
+ $type?: "com.atproto.repo.defs#commitMeta" | undefined;
137
+ } | undefined;
138
+ validationStatus?: "unknown" | (string & {}) | "valid" | undefined;
139
+ }>;
140
+ delete<K extends keyof Records>(params: DeleteRecordInput<K>): Promise<{
141
+ commit?: {
142
+ cid: string;
143
+ rev: string;
144
+ $type?: "com.atproto.repo.defs#commitMeta" | undefined;
145
+ } | undefined;
146
+ }>;
147
+ private paginationHelper;
148
+ paginatedList<K extends keyof Records>(params: {
149
+ repo: ActorIdentifier;
150
+ collection: K;
151
+ reverse?: boolean;
152
+ limit?: number;
153
+ }): Promise<ListRecordsOutput<K>>;
154
+ paginatedListBlobs(params: {
155
+ did: Did;
156
+ limit?: number;
157
+ }): Promise<{
158
+ cids: string[];
159
+ } & {
160
+ cursor: string | undefined;
161
+ }>;
162
+ paginatedListRepos(params: {
163
+ did: Did;
164
+ limit?: number;
165
+ }): Promise<{
166
+ repos: {
167
+ did: `did:${string}:${string}`;
168
+ head: string;
169
+ rev: string;
170
+ $type?: "com.atproto.sync.listRepos#repo" | undefined;
171
+ active?: boolean | undefined;
172
+ status?: (string & {}) | "deactivated" | "suspended" | "takendown" | "throttled" | "deleted" | "desynchronized" | undefined;
173
+ }[];
174
+ } & {
175
+ cursor: string | undefined;
176
+ }>;
177
+ batchWrite(params: ComAtprotoRepoApplyWrites.$input): Promise<{
178
+ commit?: {
179
+ cid: string;
180
+ rev: string;
181
+ $type?: "com.atproto.repo.defs#commitMeta" | undefined;
182
+ } | undefined;
183
+ results?: (({
184
+ cid: string;
185
+ uri: ResourceUri;
186
+ $type?: "com.atproto.repo.applyWrites#createResult" | undefined;
187
+ validationStatus?: "unknown" | (string & {}) | "valid" | undefined;
188
+ } & {
189
+ $type: "com.atproto.repo.applyWrites#createResult";
190
+ }) | ({
191
+ $type?: "com.atproto.repo.applyWrites#deleteResult" | undefined;
192
+ } & {
193
+ $type: "com.atproto.repo.applyWrites#deleteResult";
194
+ }) | ({
195
+ cid: string;
196
+ uri: ResourceUri;
197
+ $type?: "com.atproto.repo.applyWrites#updateResult" | undefined;
198
+ validationStatus?: "unknown" | (string & {}) | "valid" | undefined;
199
+ } & {
200
+ $type: "com.atproto.repo.applyWrites#updateResult";
201
+ }))[] | undefined;
202
+ }>;
203
+ resolveHandle(handle: `${string}.${string}`): Promise<Did>;
204
+ }
205
+ export {};
206
+ //# sourceMappingURL=agent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.d.ts","s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EAAE,iBAAiB,CAAC,CAAC,CAAC;;;;;;;;;;IAY5D,MAAM,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC;;;;;;;YAYpD,gBAAgB;IAiDxB,aAAa,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,MAAM,EAAE;QACjD,IAAI,EAAE,eAAe,CAAC;QACtB,UAAU,EAAE,CAAC,CAAC;QACd,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IA6B3B,kBAAkB,CAAC,MAAM,EAAE;QAC7B,GAAG,EAAE,GAAG,CAAC;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB;;;gBA5EyC,MAAM,GAAG,SAAS;;IAqGtD,kBAAkB,CAAC,MAAM,EAAE;QAC7B,GAAG,EAAE,GAAG,CAAC;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;KAClB;;;;;;;;;;gBAxGyC,MAAM,GAAG,SAAS;;IAiItD,UAAU,CAAC,MAAM,EAAE,yBAAyB,CAAC,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;IAYnD,aAAa,CAAC,MAAM,EAAE,GAAG,MAAM,IAAI,MAAM,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;CAenE"}
package/out/agent.js ADDED
@@ -0,0 +1,329 @@
1
+ /* eslint-disable @typescript-eslint/no-empty-object-type */
2
+ import { CredentialManager, simpleFetchHandler, Client } from "@atcute/client";
3
+ import { AtUri } from "@atproto/syntax";
4
+ import { getDidAndPds } from "./pds-helpers.js";
5
+ import { resolveHandleAnonymously } from "./handles/resolve.js";
6
+ import * as v from '@atcute/lexicons/validations';
7
+ class XRPCError extends Error {
8
+ kind;
9
+ constructor(kind, message) {
10
+ super(message);
11
+ this.kind = kind;
12
+ }
13
+ }
14
+ export function isInvalidSwapError(err) {
15
+ return err instanceof XRPCError && err.kind === 'InvalidSwap';
16
+ }
17
+ export function isRecordNotFoundError(err) {
18
+ return err instanceof XRPCError && err.kind === 'RecordNotFound';
19
+ }
20
+ export class KittyAgent {
21
+ xrpc;
22
+ constructor(opts) {
23
+ this.xrpc = opts instanceof Client ? opts : new Client(opts);
24
+ }
25
+ /**
26
+ * Gets a read-only client for bsky.social PDSes.
27
+ */
28
+ static createUnauthed(service = 'https://bsky.social') {
29
+ return new KittyAgent({ handler: simpleFetchHandler({ service }) });
30
+ }
31
+ /**
32
+ * Gets a read-only client for the Bluesky AppView.
33
+ */
34
+ static createAppview(service = 'https://api.bsky.app') {
35
+ return new KittyAgent({ handler: simpleFetchHandler({ service }) });
36
+ }
37
+ static pdsAgentCache = new Map();
38
+ /**
39
+ * Gets a read-only client for the PDS hosting a specific account via handle or DID.
40
+ */
41
+ static async getOrCreatePds(handleOrDid) {
42
+ const did = await resolveHandleAnonymously(handleOrDid);
43
+ const existingAgent = KittyAgent.pdsAgentCache.get(did);
44
+ if (existingAgent)
45
+ return existingAgent;
46
+ const didAndPds = await getDidAndPds(did);
47
+ const agent = KittyAgent.createUnauthed(didAndPds.pds);
48
+ KittyAgent.pdsAgentCache.set(did, agent);
49
+ return agent;
50
+ }
51
+ /**
52
+ * Gets an authenticated client for the PDS hosting a specific account via handle or DID.
53
+ */
54
+ static async createPdsWithCredentials(handleOrDid) {
55
+ const { did, pds } = await getDidAndPds(handleOrDid);
56
+ const manager = new CredentialManager({ service: pds });
57
+ const agent = new KittyAgent({ handler: manager });
58
+ return { did, manager, agent };
59
+ }
60
+ /**
61
+ * clones this XRPC client
62
+ * @param opts options to merge with
63
+ * @returns the cloned XRPC client
64
+ */
65
+ clone({ handler = this.xrpc.handler, proxy = this.xrpc.proxy } = {}) {
66
+ return new KittyAgent({ handler, proxy });
67
+ }
68
+ /**
69
+ * performs an XRPC query request (HTTP GET)
70
+ * @param name NSID of the query
71
+ * @param options query options
72
+ */
73
+ get(name, ...options) {
74
+ return this.xrpc.get(name, ...options);
75
+ }
76
+ /**
77
+ * performs an XRPC procedure request (HTTP POST)
78
+ * @param name NSID of the procedure
79
+ * @param options procedure options
80
+ */
81
+ post(name, ...options) {
82
+ return this.xrpc.post(name, ...options);
83
+ }
84
+ /**
85
+ * performs an XRPC call with schema validation
86
+ * @param schema the lexicon schema for the endpoint, or a namespace containing mainSchema
87
+ * @param options call options
88
+ */
89
+ call(schema, ...options) {
90
+ return this.xrpc.call(schema, ...options);
91
+ }
92
+ makeRecordTyped(record) {
93
+ let memoizedAtUri;
94
+ const uri = record.uri; // closure variable
95
+ return {
96
+ ...record,
97
+ value: record.value,
98
+ get uri() {
99
+ return memoizedAtUri ??= new AtUri(uri);
100
+ }
101
+ };
102
+ }
103
+ makeRecordsTyped(value) {
104
+ return {
105
+ ...value,
106
+ records: value.records.map(this.makeRecordTyped.bind(this))
107
+ };
108
+ }
109
+ async getRecord(params) {
110
+ const response = await this.xrpc.get('com.atproto.repo.getRecord', {
111
+ params: {
112
+ repo: params.repo,
113
+ collection: params.collection,
114
+ rkey: params.rkey,
115
+ }
116
+ });
117
+ if (!response.ok) {
118
+ throw new XRPCError(response.data?.error || 'Unknown error', response.data?.message || 'An unknown error occurred');
119
+ }
120
+ return this.makeRecordTyped(response.data);
121
+ }
122
+ async getBlob(params) {
123
+ if (typeof params.cid !== 'string') {
124
+ params = {
125
+ cid: params.cid.ref.$link,
126
+ did: params.did,
127
+ };
128
+ }
129
+ const data = await this.get('com.atproto.sync.getBlob', {
130
+ as: 'bytes',
131
+ params: params
132
+ });
133
+ if (!data.ok) {
134
+ throw new XRPCError(data.data?.error || 'Unknown', data.data?.message || 'An unknown error occurred');
135
+ }
136
+ return data.data;
137
+ }
138
+ /**
139
+ * Atcute likes to return blobs as text sometimes. I don't know why yet. This returns them as binary if that
140
+ * happens.
141
+ */
142
+ async getBlobAsBinary(params) {
143
+ let blob = await this.getBlob(params);
144
+ if (typeof blob === 'string')
145
+ blob = new TextEncoder().encode(blob);
146
+ return blob;
147
+ }
148
+ /**
149
+ * Atcute likes to return blobs as text sometimes. I don't know why yet. This returns them as text no matter what,
150
+ * and also allows you to specify an encoding.
151
+ */
152
+ async getBlobAsText(params, encoding) {
153
+ let blob = await this.getBlob(params);
154
+ if (typeof blob !== 'string')
155
+ blob = new TextDecoder(encoding).decode(blob);
156
+ return blob;
157
+ }
158
+ async tryGetRecord(params) {
159
+ try {
160
+ return await this.getRecord(params);
161
+ }
162
+ catch (err) {
163
+ if (!isRecordNotFoundError(err))
164
+ throw err;
165
+ return {
166
+ uri: undefined,
167
+ value: undefined,
168
+ cid: undefined,
169
+ };
170
+ }
171
+ }
172
+ async list(params) {
173
+ const response = await this.get('com.atproto.repo.listRecords', {
174
+ as: 'json',
175
+ params
176
+ });
177
+ if (!response.ok) {
178
+ throw new XRPCError(response.data?.error || 'Unknown', response.data?.message || 'An unknown error occurred');
179
+ }
180
+ return this.makeRecordsTyped(response.data);
181
+ }
182
+ async put(params) {
183
+ const data = await this.post('com.atproto.repo.putRecord', {
184
+ input: params
185
+ });
186
+ if (!data.ok) {
187
+ throw new XRPCError(data.data?.error || 'Unknown', data.data?.message || 'An unknown error occurred');
188
+ }
189
+ return data.data;
190
+ }
191
+ async uploadBlob(buf) {
192
+ const data = await this.post('com.atproto.repo.uploadBlob', {
193
+ input: buf
194
+ });
195
+ if (!data.ok) {
196
+ throw new XRPCError(data.data?.error || 'Unknown', data.data?.message || 'An unknown error occurred');
197
+ }
198
+ return data.data.blob;
199
+ }
200
+ async trySwap(params) {
201
+ try {
202
+ await this.put(params);
203
+ return true;
204
+ }
205
+ catch (err) {
206
+ if (!isInvalidSwapError(err)) {
207
+ throw err;
208
+ }
209
+ return false;
210
+ }
211
+ }
212
+ async create(params) {
213
+ const data = await this.post('com.atproto.repo.createRecord', {
214
+ input: params
215
+ });
216
+ if (!data.ok) {
217
+ throw new XRPCError(data.data?.error || 'Unknown', data.data?.message || 'An unknown error occurred');
218
+ }
219
+ return data.data;
220
+ }
221
+ async delete(params) {
222
+ const data = await this.post('com.atproto.repo.deleteRecord', {
223
+ input: params
224
+ });
225
+ if (!data.ok) {
226
+ throw new XRPCError(data.data?.error || 'Unknown', data.data?.message || 'An unknown error occurred');
227
+ }
228
+ return data.data;
229
+ }
230
+ async paginationHelper(limit, key, query, getResults, resultsEqual) {
231
+ const PER_PAGE = 100;
232
+ const results = [];
233
+ let cursor = undefined;
234
+ do {
235
+ const data = await query(cursor, limit === undefined
236
+ ? PER_PAGE
237
+ : limit / PER_PAGE > 1
238
+ ? PER_PAGE
239
+ : limit);
240
+ const theseResults = getResults(data);
241
+ if (!theseResults.length ||
242
+ theseResults.every(e => results.find(e1 => resultsEqual(e1, e)))) {
243
+ break;
244
+ }
245
+ if (limit !== undefined) {
246
+ limit -= theseResults.length;
247
+ }
248
+ results.push(...theseResults);
249
+ cursor = data.cursor;
250
+ if (!cursor)
251
+ break;
252
+ } while (cursor);
253
+ return { [key]: results, cursor };
254
+ }
255
+ async paginatedList(params) {
256
+ const data = this.makeRecordsTyped(await this.paginationHelper(params.limit, 'records', async (cursor, limit) => {
257
+ const response = await this.get('com.atproto.repo.listRecords', {
258
+ as: 'json',
259
+ params: {
260
+ repo: params.repo,
261
+ collection: params.collection,
262
+ limit,
263
+ reverse: params.reverse ?? true,
264
+ cursor
265
+ }
266
+ });
267
+ if (!response.ok) {
268
+ throw new XRPCError(response.data?.error || 'Unknown', response.data?.message || 'An unknown error occurred');
269
+ }
270
+ return response.data;
271
+ }, output => output.records, (a, b) => a.uri === b.uri));
272
+ return data;
273
+ }
274
+ async paginatedListBlobs(params) {
275
+ return await this.paginationHelper(params.limit, 'cids', async (cursor, limit) => {
276
+ const response = await this.get('com.atproto.sync.listBlobs', {
277
+ as: 'json',
278
+ params: {
279
+ did: params.did,
280
+ limit,
281
+ cursor
282
+ }
283
+ });
284
+ if (!response.ok) {
285
+ throw new XRPCError(response.data?.error || 'Unknown', response.data?.message || 'An unknown error occurred');
286
+ }
287
+ return response.data;
288
+ }, output => output.cids, (a, b) => a === b);
289
+ }
290
+ async paginatedListRepos(params) {
291
+ return await this.paginationHelper(params.limit, 'repos', async (cursor, limit) => {
292
+ const response = await this.get('com.atproto.sync.listRepos', {
293
+ as: 'json',
294
+ params: {
295
+ // did: params.did,
296
+ limit,
297
+ cursor
298
+ }
299
+ });
300
+ if (!response.ok) {
301
+ throw new XRPCError(response.data?.error || 'Unknown', response.data?.message || 'An unknown error occurred');
302
+ }
303
+ return response.data;
304
+ }, output => output.repos, (a, b) => a.did === b.did);
305
+ }
306
+ async batchWrite(params) {
307
+ const response = await this.post('com.atproto.repo.applyWrites', {
308
+ input: params
309
+ });
310
+ if (!response.ok) {
311
+ throw new XRPCError(response.data?.error || 'Unknown', response.data?.message || 'An unknown error occurred');
312
+ }
313
+ return response.data;
314
+ }
315
+ async resolveHandle(handle) {
316
+ if (handle.startsWith('did:'))
317
+ return handle;
318
+ const response = await this.get('com.atproto.identity.resolveHandle', {
319
+ params: {
320
+ handle
321
+ }
322
+ });
323
+ if (!response.ok) {
324
+ throw new XRPCError(response.data?.error || 'Unknown', response.data?.message || 'An unknown error occurred');
325
+ }
326
+ return response.data.did;
327
+ }
328
+ }
329
+ //# sourceMappingURL=agent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAE5D,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,EAA4H,MAAM,gBAAgB,CAAC;AACzM,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AAMhE,OAAO,KAAK,CAAC,MAAM,8BAA8B,CAAC;AAuBlD,MAAM,SAAU,SAAQ,KAAK;IACzB,IAAI,CAAS;IACb,YAAY,IAAY,EAAE,OAAe;QACrC,KAA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;YACf,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,IAAI,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,2BAA2B,CAAC,CAAC;QAClH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC;IACzB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,MAA6B;QAC7C,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC;YAAE,OAAO,MAAa,CAAC;QAEpD,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,GAAG,CAAC,oCAAoC,EAAE;YAClE,MAAM,EAAE;gBACJ,MAAM;aACT;SACJ,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACf,MAAM,IAAI,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,IAAI,SAAS,EAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,IAAI,2BAA2B,CAAC,CAAC;QAClH,CAAC;QAED,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC;IAC7B,CAAC"}
package/out/cid.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { type Cid, type CidLink } from '@atcute/cid';
2
+ import type { Blob } from '@atcute/lexicons';
3
+ export declare function isCidMatching(data: BufferSource, blob: Blob): Promise<boolean>;
4
+ export declare function getSha256(cidOrBlob: Blob | CidLink | Cid): string;
5
+ //# sourceMappingURL=cid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cid.d.ts","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,OAAO,EAAe,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAE7C,wBAAsB,aAAa,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,oBAOjE;AAqBD,wBAAgB,SAAS,CAAC,SAAS,EAAE,IAAI,GAAG,OAAO,GAAG,GAAG,UAIxD"}
package/out/cid.js ADDED
@@ -0,0 +1,38 @@
1
+ // import { sha256 } from '@noble/hashes/sha256';
2
+ import { fromCidLink } from '@atcute/cid';
3
+ export async function isCidMatching(data, blob) {
4
+ const cid = fromCidLink(blob.ref);
5
+ const digest = cid.digest.contents;
6
+ const actualDigest = new Uint8Array(await crypto.subtle.digest('sha-256', data));
7
+ return isEqualBytes(digest, actualDigest);
8
+ }
9
+ // https://stackoverflow.com/a/77736145
10
+ function isEqualBytes(bytes1, bytes2) {
11
+ if (typeof indexedDB !== 'undefined' && indexedDB.cmp) {
12
+ return indexedDB.cmp(bytes1, bytes2) === 0;
13
+ }
14
+ if (bytes1.length !== bytes2.length) {
15
+ return false;
16
+ }
17
+ for (let i = 0; i < bytes1.length; i++) {
18
+ if (bytes1[i] !== bytes2[i]) {
19
+ return false;
20
+ }
21
+ }
22
+ return true;
23
+ }
24
+ export function getSha256(cidOrBlob) {
25
+ if ('ref' in cidOrBlob)
26
+ cidOrBlob = fromCidLink(cidOrBlob.ref);
27
+ if ('$link' in cidOrBlob)
28
+ cidOrBlob = fromCidLink(cidOrBlob);
29
+ return arrayToHex(cidOrBlob.digest.contents);
30
+ }
31
+ // https://stackoverflow.com/a/39225475
32
+ function arrayToHex(arr) {
33
+ return Array.from(arr).map(numberToHex).join('');
34
+ }
35
+ function numberToHex(i) {
36
+ return i.toString(16).padStart(2, '0');
37
+ }
38
+ //# sourceMappingURL=cid.js.map
package/out/cid.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cid.js","sourceRoot":"","sources":["../src/cid.ts"],"names":[],"mappings":"AAAA,iDAAiD;AACjD,OAAO,EAA0B,WAAW,EAAE,MAAM,aAAa,CAAC;AAGlE,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAkB,EAAE,IAAU;IAC9D,MAAM,GAAG,GAAG,WAAW,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC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C,WAAW,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;AACrD,CAAC;AAED,SAAS,WAAW,CAAC,CAAS;IAC1B,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAC3C,CAAC"}
@@ -0,0 +1,41 @@
1
+ /*!
2
+ https://github.com/mary-ext/atcute
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+ */
22
+ import type { DidDocument } from "@atcute/identity";
23
+ import type { Did } from "@atcute/lexicons";
24
+ /**
25
+ * Retrieves AT Protocol PDS endpoint from the DID document, if available
26
+ * @param doc DID document
27
+ * @returns The PDS endpoint, if available
28
+ */
29
+ export declare function getPdsEndpoint(doc: DidDocument): string | undefined;
30
+ /**
31
+ * Retrieve a service endpoint from the DID document, if available
32
+ * @param doc DID document
33
+ * @param serviceId Service ID
34
+ * @param serviceType Service type
35
+ * @returns The requested service endpoint, if available
36
+ */
37
+ export declare function getServiceEndpoint(doc: DidDocument, serviceId: string, serviceType: string): string | undefined;
38
+ export declare function getDidDocument(did: Did): Promise<DidDocument>;
39
+ export declare function getDid(didDoc: DidDocument): Did;
40
+ export declare function getHandle(didDoc: DidDocument): string | undefined;
41
+ //# sourceMappingURL=did-document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"did-document.d.ts","sourceRoot":"","sources":["../../src/handles/did-document.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;;EAoBE;AAEF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,MAAM,GAAG,SAAS,CAEnE;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAC9B,GAAG,EAAE,WAAW,EAChB,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GACpB,MAAM,GAAG,SAAS,CAWpB;AAiBD,wBAAsB,cAAc,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAC,WAAW,CAAC,CA2CnE;AAED,wBAAgB,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,GAAG,CAE/C;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,WAAW,sBAI5C"}