@atcute/bluesky-threading 4.0.1 → 5.0.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/dist/index.d.ts +5 -5
- package/dist/index.js +32 -30
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +16 -13
- package/lib/index.ts +101 -82
- package/lib/types.ts +17 -13
- package/package.json +9 -12
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import '@atcute/
|
|
2
|
-
import { type
|
|
3
|
-
import type
|
|
1
|
+
import { type Client } from '@atcute/client';
|
|
2
|
+
import type { $type } from '@atcute/lexicons';
|
|
3
|
+
import type * as ComAtprotoRepoApplyWrites from '@atcute/atproto/types/repo/applyWrites';
|
|
4
4
|
import type { ComposedThread } from './types.js';
|
|
5
5
|
export type * from './types.js';
|
|
6
6
|
/**
|
|
@@ -9,10 +9,10 @@ export type * from './types.js';
|
|
|
9
9
|
* @param thread Composed thread
|
|
10
10
|
* @returns An array of post records that were published
|
|
11
11
|
*/
|
|
12
|
-
export declare function publishThread(rpc:
|
|
12
|
+
export declare function publishThread(rpc: Client, thread: Omit<ComposedThread, 'rpc'>): Promise<$type.enforce<ComAtprotoRepoApplyWrites.Create>[]>;
|
|
13
13
|
/**
|
|
14
14
|
* Create post records without publishing, allows you to do it yourself.
|
|
15
15
|
* @param thread Composed thread
|
|
16
16
|
* @returns An array of post records
|
|
17
17
|
*/
|
|
18
|
-
export declare function createThread(thread: ComposedThread): Promise
|
|
18
|
+
export declare function createThread(thread: ComposedThread): Promise<$type.enforce<ComAtprotoRepoApplyWrites.Create>[]>;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import '@atcute/
|
|
2
|
-
import { XRPCError } from '@atcute/client';
|
|
1
|
+
import { ClientResponseError, ok } from '@atcute/client';
|
|
3
2
|
import * as TID from '@atcute/tid';
|
|
4
3
|
import { serializeRecordCid } from './cbor.js';
|
|
5
4
|
import { getNow } from './time.js';
|
|
@@ -10,14 +9,14 @@ import { getNow } from './time.js';
|
|
|
10
9
|
* @returns An array of post records that were published
|
|
11
10
|
*/
|
|
12
11
|
export async function publishThread(rpc, thread) {
|
|
13
|
-
const records = await createThread({ ...thread, rpc });
|
|
14
|
-
await rpc.
|
|
12
|
+
const records = await createThread({ ...thread, client: rpc });
|
|
13
|
+
await ok(rpc.post('com.atproto.repo.applyWrites', {
|
|
15
14
|
signal: thread.signal,
|
|
16
|
-
|
|
15
|
+
input: {
|
|
17
16
|
repo: thread.author,
|
|
18
17
|
writes: records,
|
|
19
18
|
},
|
|
20
|
-
});
|
|
19
|
+
}));
|
|
21
20
|
return records;
|
|
22
21
|
}
|
|
23
22
|
/**
|
|
@@ -26,7 +25,7 @@ export async function publishThread(rpc, thread) {
|
|
|
26
25
|
* @returns An array of post records
|
|
27
26
|
*/
|
|
28
27
|
export async function createThread(thread) {
|
|
29
|
-
const
|
|
28
|
+
const client = thread.client;
|
|
30
29
|
const signal = thread.signal;
|
|
31
30
|
const did = thread.author;
|
|
32
31
|
const posts = thread.posts;
|
|
@@ -41,7 +40,7 @@ export async function createThread(thread) {
|
|
|
41
40
|
let post = thread.reply;
|
|
42
41
|
if (typeof post === 'string') {
|
|
43
42
|
// AT-URI being passed
|
|
44
|
-
|
|
43
|
+
assertClient(client, `ComposedThread.reply`);
|
|
45
44
|
post = await getPost(post);
|
|
46
45
|
}
|
|
47
46
|
let root;
|
|
@@ -157,7 +156,7 @@ export async function createThread(thread) {
|
|
|
157
156
|
let thumb;
|
|
158
157
|
if (rawThumb !== undefined) {
|
|
159
158
|
if (rawThumb instanceof Blob) {
|
|
160
|
-
|
|
159
|
+
assertClient(client, `PostExternalEmbed.thumbnail`);
|
|
161
160
|
thumb = await uploadBlob(rawThumb);
|
|
162
161
|
}
|
|
163
162
|
else {
|
|
@@ -181,7 +180,7 @@ export async function createThread(thread) {
|
|
|
181
180
|
const rawBlob = image.blob;
|
|
182
181
|
let blob;
|
|
183
182
|
if (rawBlob instanceof Blob) {
|
|
184
|
-
|
|
183
|
+
assertClient(client, `PostImageEmbed.images[].blob`);
|
|
185
184
|
blob = await uploadBlob(rawBlob);
|
|
186
185
|
}
|
|
187
186
|
else {
|
|
@@ -203,7 +202,7 @@ export async function createThread(thread) {
|
|
|
203
202
|
const rawBlob = embed.blob;
|
|
204
203
|
let blob;
|
|
205
204
|
if (rawBlob instanceof Blob) {
|
|
206
|
-
|
|
205
|
+
assertClient(client, `PostVideoEmbed.blob`);
|
|
207
206
|
blob = await uploadBlob(rawBlob);
|
|
208
207
|
}
|
|
209
208
|
else {
|
|
@@ -224,32 +223,32 @@ export async function createThread(thread) {
|
|
|
224
223
|
if (cid === undefined) {
|
|
225
224
|
const type = embed.type;
|
|
226
225
|
if (type === 'quote') {
|
|
227
|
-
|
|
226
|
+
assertClient(client, 'PostQuoteEmbed');
|
|
228
227
|
const post = await getPost(uri);
|
|
229
228
|
cid = post.cid;
|
|
230
229
|
}
|
|
231
230
|
else if (type === 'feed') {
|
|
232
|
-
|
|
233
|
-
const
|
|
231
|
+
assertClient(client, 'PostFeedEmbed');
|
|
232
|
+
const data = await ok(client.get('app.bsky.feed.getFeedGenerator', {
|
|
234
233
|
signal: signal,
|
|
235
234
|
params: { feed: uri },
|
|
236
|
-
});
|
|
235
|
+
}));
|
|
237
236
|
cid = data.view.cid;
|
|
238
237
|
}
|
|
239
238
|
else if (type === 'list') {
|
|
240
|
-
|
|
241
|
-
const
|
|
239
|
+
assertClient(client, 'PostListEmbed');
|
|
240
|
+
const data = await ok(client.get('app.bsky.graph.getList', {
|
|
242
241
|
signal: signal,
|
|
243
242
|
params: { list: uri, limit: 1 },
|
|
244
|
-
});
|
|
243
|
+
}));
|
|
245
244
|
cid = data.list.cid;
|
|
246
245
|
}
|
|
247
246
|
else if (type === 'starterpack') {
|
|
248
|
-
|
|
249
|
-
const
|
|
247
|
+
assertClient(client, 'PostStarterpackEmbed');
|
|
248
|
+
const data = await ok(client.get('app.bsky.graph.getStarterPack', {
|
|
250
249
|
signal: signal,
|
|
251
250
|
params: { starterPack: uri },
|
|
252
|
-
});
|
|
251
|
+
}));
|
|
253
252
|
cid = data.starterPack.cid;
|
|
254
253
|
}
|
|
255
254
|
else {
|
|
@@ -267,23 +266,26 @@ export async function createThread(thread) {
|
|
|
267
266
|
}
|
|
268
267
|
async function uploadBlob(blob) {
|
|
269
268
|
// `rpc` intentionally non-null asserted.
|
|
270
|
-
const
|
|
269
|
+
const data = await ok(client.post('com.atproto.repo.uploadBlob', {
|
|
271
270
|
signal: signal,
|
|
272
|
-
|
|
273
|
-
});
|
|
271
|
+
input: blob,
|
|
272
|
+
}));
|
|
274
273
|
return data.blob;
|
|
275
274
|
}
|
|
276
275
|
async function getPost(uri) {
|
|
277
276
|
// `rpc` intentionally non-null asserted.
|
|
278
|
-
const
|
|
277
|
+
const data = await ok(client.get('app.bsky.feed.getPosts', {
|
|
279
278
|
signal: signal,
|
|
280
279
|
params: {
|
|
281
280
|
uris: [uri],
|
|
282
281
|
},
|
|
283
|
-
});
|
|
282
|
+
}));
|
|
284
283
|
const post = data.posts[0];
|
|
285
284
|
if (!post) {
|
|
286
|
-
throw new
|
|
285
|
+
throw new ClientResponseError({
|
|
286
|
+
status: 400,
|
|
287
|
+
data: { error: 'NotFound', message: `Post not found: ${uri}` },
|
|
288
|
+
});
|
|
287
289
|
}
|
|
288
290
|
return post;
|
|
289
291
|
}
|
|
@@ -315,9 +317,9 @@ function assert(condition, message) {
|
|
|
315
317
|
throw new Error(message);
|
|
316
318
|
}
|
|
317
319
|
}
|
|
318
|
-
function
|
|
319
|
-
if (
|
|
320
|
-
throw new Error(`${thing} requires supplying
|
|
320
|
+
function assertClient(client, thing) {
|
|
321
|
+
if (client === undefined) {
|
|
322
|
+
throw new Error(`${thing} requires supplying Client instance`);
|
|
321
323
|
}
|
|
322
324
|
}
|
|
323
325
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,EAAE,EAAe,MAAM,gBAAgB,CAAC;AAmBtE,OAAO,KAAK,GAAG,MAAM,aAAa,CAAC;AAEnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAYnC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAClC,GAAW,EACX,MAAmC;IAEnC,MAAM,OAAO,GAAG,MAAM,YAAY,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAC;IAE/D,MAAM,EAAE,CACP,GAAG,CAAC,IAAI,CAAC,8BAA8B,EAAE;QACxC,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,KAAK,EAAE;YACN,IAAI,EAAE,MAAM,CAAC,MAAM;YACnB,MAAM,EAAE,OAAO;SACf;KACD,CAAC,CACF,CAAC;IAEF,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CACjC,MAAsB;IAEtB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAE7B,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC3B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC;IAC/B,MAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;IAEnC,MAAM,MAAM,GAAsD,EAAE,CAAC;IAErE,MAAM,GAAG,GAAG,MAAM,CAAC,S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C;QACzB,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC;QAExB,IAAI,IAAI,KAAK,OAAO,IAAI,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7C,OAAO,KAAK,CAAC,MAAM,CAAC;QACrB,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,MAAM,CAAC,SAAkB,EAAE,OAAe;IAClD,IAAI,CAAC,SAAS,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1B,CAAC;AACF,CAAC;AAED,SAAS,YAAY,CAAC,MAA0B,EAAE,KAAa;IAC9D,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,GAAG,KAAK,qCAAqC,CAAC,CAAC;IAChE,CAAC;AACF,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Client } from '@atcute/client';
|
|
2
|
+
import type { Blob as AtBlob, Did, GenericUri, ResourceUri } from '@atcute/lexicons';
|
|
3
|
+
import type * as AppBskyEmbedRecord from '@atcute/bluesky/types/app/embed/record';
|
|
4
|
+
import type * as AppBskyFeedDefs from '@atcute/bluesky/types/app/feed/defs';
|
|
5
|
+
import type * as AppBskyRichtextFacet from '@atcute/bluesky/types/app/richtext/facet';
|
|
3
6
|
/** Interface containing aspect ratio of the media */
|
|
4
7
|
export interface MediaAspectRatio {
|
|
5
8
|
/** Media width */
|
|
@@ -11,7 +14,7 @@ export interface MediaAspectRatio {
|
|
|
11
14
|
export interface PostExternalEmbed {
|
|
12
15
|
type: 'external';
|
|
13
16
|
/** Link to the page */
|
|
14
|
-
uri:
|
|
17
|
+
uri: GenericUri;
|
|
15
18
|
/** Page title */
|
|
16
19
|
title: string;
|
|
17
20
|
/** Page description */
|
|
@@ -22,7 +25,7 @@ export interface PostExternalEmbed {
|
|
|
22
25
|
* you to also supply an authenticated RPC instance for it to be able to make
|
|
23
26
|
* procedure calls.
|
|
24
27
|
*/
|
|
25
|
-
thumbnail?: Blob |
|
|
28
|
+
thumbnail?: Blob | AtBlob;
|
|
26
29
|
/** Labels to describe this external embed */
|
|
27
30
|
labels?: string[];
|
|
28
31
|
}
|
|
@@ -34,7 +37,7 @@ export interface ComposedImage {
|
|
|
34
37
|
* you to also supply an authenticated RPC instance for it to be able to make
|
|
35
38
|
* procedure calls.
|
|
36
39
|
*/
|
|
37
|
-
blob: Blob |
|
|
40
|
+
blob: Blob | AtBlob;
|
|
38
41
|
/**
|
|
39
42
|
* Alternative text for this image, helps describe images for low-vision users
|
|
40
43
|
* and provide context for everyone.
|
|
@@ -63,7 +66,7 @@ export interface PostVideoEmbed {
|
|
|
63
66
|
* you to also supply an authenticated RPC instance for it to be able to make
|
|
64
67
|
* procedure calls.
|
|
65
68
|
*/
|
|
66
|
-
blob: Blob |
|
|
69
|
+
blob: Blob | AtBlob;
|
|
67
70
|
/**
|
|
68
71
|
* Alternative text for this video, helps describe video for low-vision users
|
|
69
72
|
* and provide context for everyone.
|
|
@@ -85,7 +88,7 @@ export type PostMediaEmbed = PostExternalEmbed | PostImageEmbed | PostVideoEmbed
|
|
|
85
88
|
export interface PostFeedEmbed {
|
|
86
89
|
type: 'feed';
|
|
87
90
|
/** AT-URI of the feed */
|
|
88
|
-
uri:
|
|
91
|
+
uri: ResourceUri;
|
|
89
92
|
/**
|
|
90
93
|
* CID of the feed, if not supplied, requires you to also supply an RPC
|
|
91
94
|
* instance for it to be able to make query calls.
|
|
@@ -96,7 +99,7 @@ export interface PostFeedEmbed {
|
|
|
96
99
|
export interface PostListEmbed {
|
|
97
100
|
type: 'list';
|
|
98
101
|
/** AT-URI of the list */
|
|
99
|
-
uri:
|
|
102
|
+
uri: ResourceUri;
|
|
100
103
|
/**
|
|
101
104
|
* CID of the list, if not supplied, requires you to also supply an RPC
|
|
102
105
|
* instance for it to be able to make query calls.
|
|
@@ -107,7 +110,7 @@ export interface PostListEmbed {
|
|
|
107
110
|
export interface PostQuoteEmbed {
|
|
108
111
|
type: 'quote';
|
|
109
112
|
/** AT-URI of the post */
|
|
110
|
-
uri:
|
|
113
|
+
uri: ResourceUri;
|
|
111
114
|
/**
|
|
112
115
|
* CID of the post, if not supplied, requires you to also supply an RPC
|
|
113
116
|
* instance for it to be able to make query calls.
|
|
@@ -118,7 +121,7 @@ export interface PostQuoteEmbed {
|
|
|
118
121
|
export interface PostStarterpackEmbed {
|
|
119
122
|
type: 'starterpack';
|
|
120
123
|
/** AT-URI of the post */
|
|
121
|
-
uri:
|
|
124
|
+
uri: ResourceUri;
|
|
122
125
|
/**
|
|
123
126
|
* CID of the starter pack, if not supplied, requires you to also supply an
|
|
124
127
|
* RPC instance for it to be able to make query calls.
|
|
@@ -153,16 +156,16 @@ export interface ComposedThreadgate {
|
|
|
153
156
|
/** Allow replies from users mentioned in the post */
|
|
154
157
|
mentions?: boolean;
|
|
155
158
|
/** Allow replies from users that are in these user lists */
|
|
156
|
-
listUris?:
|
|
159
|
+
listUris?: ResourceUri[];
|
|
157
160
|
}
|
|
158
161
|
/** Base interface for the thread being composed */
|
|
159
162
|
export interface ComposedThread {
|
|
160
163
|
/** An RPC instance, necessary for some options that takes action on your behalf */
|
|
161
|
-
|
|
164
|
+
client?: Client;
|
|
162
165
|
/** Abort signal */
|
|
163
166
|
signal?: AbortSignal;
|
|
164
167
|
/** Author of the thread */
|
|
165
|
-
author:
|
|
168
|
+
author: Did;
|
|
166
169
|
/**
|
|
167
170
|
* The "creation time" for this thread,
|
|
168
171
|
* if not supplied, the current time is used
|
package/lib/index.ts
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
|
-
import '@atcute/
|
|
1
|
+
import { ClientResponseError, ok, type Client } from '@atcute/client';
|
|
2
|
+
import type { $type, Blob as AtBlob, CanonicalResourceUri, ResourceUri } from '@atcute/lexicons';
|
|
3
|
+
|
|
4
|
+
import type * as ComAtprotoLabelDefs from '@atcute/atproto/types/label/defs';
|
|
5
|
+
import type * as ComAtprotoRepoApplyWrites from '@atcute/atproto/types/repo/applyWrites';
|
|
6
|
+
import type * as ComAtprotoRepoStrongRef from '@atcute/atproto/types/repo/strongRef';
|
|
7
|
+
import type {} from '@atcute/atproto/types/repo/uploadBlob';
|
|
8
|
+
import type * as AppBskyEmbedExternal from '@atcute/bluesky/types/app/embed/external';
|
|
9
|
+
import type * as AppBskyEmbedImages from '@atcute/bluesky/types/app/embed/images';
|
|
10
|
+
import type * as AppBskyEmbedRecord from '@atcute/bluesky/types/app/embed/record';
|
|
11
|
+
import type * as AppBskyEmbedVideo from '@atcute/bluesky/types/app/embed/video';
|
|
12
|
+
import type * as AppBskyFeedDefs from '@atcute/bluesky/types/app/feed/defs';
|
|
13
|
+
import type {} from '@atcute/bluesky/types/app/feed/getFeedGenerator';
|
|
14
|
+
import type {} from '@atcute/bluesky/types/app/feed/getPosts';
|
|
15
|
+
import type * as AppBskyFeedPost from '@atcute/bluesky/types/app/feed/post';
|
|
16
|
+
import type * as AppBskyFeedThreadgate from '@atcute/bluesky/types/app/feed/threadgate';
|
|
17
|
+
import type {} from '@atcute/bluesky/types/app/graph/getList';
|
|
18
|
+
import type {} from '@atcute/bluesky/types/app/graph/getStarterPack';
|
|
2
19
|
|
|
3
|
-
import { XRPCError, type XRPC } from '@atcute/client';
|
|
4
|
-
import type {
|
|
5
|
-
AppBskyEmbedExternal,
|
|
6
|
-
AppBskyEmbedImages,
|
|
7
|
-
AppBskyEmbedRecord,
|
|
8
|
-
AppBskyEmbedVideo,
|
|
9
|
-
AppBskyFeedDefs,
|
|
10
|
-
AppBskyFeedPost,
|
|
11
|
-
AppBskyFeedThreadgate,
|
|
12
|
-
At,
|
|
13
|
-
Brand,
|
|
14
|
-
ComAtprotoLabelDefs,
|
|
15
|
-
ComAtprotoRepoApplyWrites,
|
|
16
|
-
ComAtprotoRepoStrongRef,
|
|
17
|
-
} from '@atcute/client/lexicons';
|
|
18
20
|
import * as TID from '@atcute/tid';
|
|
19
21
|
|
|
20
22
|
import { serializeRecordCid } from './cbor.js';
|
|
@@ -37,18 +39,20 @@ export type * from './types.js';
|
|
|
37
39
|
* @returns An array of post records that were published
|
|
38
40
|
*/
|
|
39
41
|
export async function publishThread(
|
|
40
|
-
rpc:
|
|
42
|
+
rpc: Client,
|
|
41
43
|
thread: Omit<ComposedThread, 'rpc'>,
|
|
42
|
-
): Promise
|
|
43
|
-
const records = await createThread({ ...thread, rpc });
|
|
44
|
-
|
|
45
|
-
await
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
44
|
+
): Promise<$type.enforce<ComAtprotoRepoApplyWrites.Create>[]> {
|
|
45
|
+
const records = await createThread({ ...thread, client: rpc });
|
|
46
|
+
|
|
47
|
+
await ok(
|
|
48
|
+
rpc.post('com.atproto.repo.applyWrites', {
|
|
49
|
+
signal: thread.signal,
|
|
50
|
+
input: {
|
|
51
|
+
repo: thread.author,
|
|
52
|
+
writes: records,
|
|
53
|
+
},
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
52
56
|
|
|
53
57
|
return records;
|
|
54
58
|
}
|
|
@@ -60,8 +64,8 @@ export async function publishThread(
|
|
|
60
64
|
*/
|
|
61
65
|
export async function createThread(
|
|
62
66
|
thread: ComposedThread,
|
|
63
|
-
): Promise
|
|
64
|
-
const
|
|
67
|
+
): Promise<$type.enforce<ComAtprotoRepoApplyWrites.Create>[]> {
|
|
68
|
+
const client = thread.client;
|
|
65
69
|
const signal = thread.signal;
|
|
66
70
|
|
|
67
71
|
const did = thread.author;
|
|
@@ -69,7 +73,7 @@ export async function createThread(
|
|
|
69
73
|
const threadgate = thread.gate;
|
|
70
74
|
const languages = thread.languages;
|
|
71
75
|
|
|
72
|
-
const writes:
|
|
76
|
+
const writes: $type.enforce<ComAtprotoRepoApplyWrites.Create>[] = [];
|
|
73
77
|
|
|
74
78
|
const now = thread.createdAt !== undefined ? new Date(thread.createdAt) : new Date(getNow(posts.length));
|
|
75
79
|
assert(!Number.isNaN(now.getTime()), `provided createdAt value is invalid`);
|
|
@@ -82,8 +86,8 @@ export async function createThread(
|
|
|
82
86
|
|
|
83
87
|
if (typeof post === 'string') {
|
|
84
88
|
// AT-URI being passed
|
|
85
|
-
|
|
86
|
-
post = await getPost(post as
|
|
89
|
+
assertClient(client, `ComposedThread.reply`);
|
|
90
|
+
post = await getPost(post as ResourceUri);
|
|
87
91
|
}
|
|
88
92
|
|
|
89
93
|
let root: ComAtprotoRepoStrongRef.Main | undefined;
|
|
@@ -92,12 +96,12 @@ export async function createThread(
|
|
|
92
96
|
if ('record' in post) {
|
|
93
97
|
// AppBskyFeedDefs.PostView being passed
|
|
94
98
|
|
|
95
|
-
root = (post.record as AppBskyFeedPost.
|
|
99
|
+
root = (post.record as AppBskyFeedPost.Main).reply?.root;
|
|
96
100
|
ref = { uri: post.uri, cid: post.cid };
|
|
97
101
|
} else if ('value' in post) {
|
|
98
102
|
// AppBskyEmbedRecord.ViewRecord being passed
|
|
99
103
|
|
|
100
|
-
root = (post.value as AppBskyFeedPost.
|
|
104
|
+
root = (post.value as AppBskyFeedPost.Main).reply?.root;
|
|
101
105
|
ref = { uri: post.uri, cid: post.cid };
|
|
102
106
|
} else {
|
|
103
107
|
assert(false, `Unexpected end of code`);
|
|
@@ -116,17 +120,17 @@ export async function createThread(
|
|
|
116
120
|
rkey = TID.createRaw(now.getTime(), Math.floor(Math.random() * 1023));
|
|
117
121
|
|
|
118
122
|
const post = posts[idx];
|
|
119
|
-
const uri:
|
|
123
|
+
const uri: CanonicalResourceUri = `at://${did}/app.bsky.feed.post/${rkey}`;
|
|
120
124
|
|
|
121
125
|
// Resolve embeds
|
|
122
|
-
let embed: AppBskyFeedPost.
|
|
126
|
+
let embed: AppBskyFeedPost.Main['embed'];
|
|
123
127
|
if (post.embed !== undefined) {
|
|
124
128
|
embed = await resolveEmbed(post.embed);
|
|
125
129
|
}
|
|
126
130
|
|
|
127
131
|
// Get the self-labels
|
|
128
132
|
const labels = getEmbedLabels(post.embed);
|
|
129
|
-
let selfLabels:
|
|
133
|
+
let selfLabels: $type.enforce<ComAtprotoLabelDefs.SelfLabels> | undefined;
|
|
130
134
|
|
|
131
135
|
if (labels?.length) {
|
|
132
136
|
selfLabels = {
|
|
@@ -138,7 +142,7 @@ export async function createThread(
|
|
|
138
142
|
// Now form the record
|
|
139
143
|
const content = post.content;
|
|
140
144
|
|
|
141
|
-
const record: AppBskyFeedPost.
|
|
145
|
+
const record: AppBskyFeedPost.Main = {
|
|
142
146
|
$type: 'app.bsky.feed.post',
|
|
143
147
|
createdAt: now.toISOString(),
|
|
144
148
|
text: content.text,
|
|
@@ -158,7 +162,7 @@ export async function createThread(
|
|
|
158
162
|
|
|
159
163
|
// If this is the first post, and we have a threadgate set, create one now.
|
|
160
164
|
if (idx === 0 && threadgate) {
|
|
161
|
-
const threadgateRecord: AppBskyFeedThreadgate.
|
|
165
|
+
const threadgateRecord: AppBskyFeedThreadgate.Main = {
|
|
162
166
|
$type: 'app.bsky.feed.threadgate',
|
|
163
167
|
createdAt: now.toISOString(),
|
|
164
168
|
post: uri,
|
|
@@ -195,7 +199,7 @@ export async function createThread(
|
|
|
195
199
|
|
|
196
200
|
return writes;
|
|
197
201
|
|
|
198
|
-
async function resolveEmbed(embed: PostEmbed): Promise<AppBskyFeedPost.
|
|
202
|
+
async function resolveEmbed(embed: PostEmbed): Promise<AppBskyFeedPost.Main['embed'] | undefined> {
|
|
199
203
|
const { media, record } = embed;
|
|
200
204
|
|
|
201
205
|
if (media && record) {
|
|
@@ -214,16 +218,16 @@ export async function createThread(
|
|
|
214
218
|
|
|
215
219
|
async function resolveMediaEmbed(
|
|
216
220
|
embed: PostMediaEmbed,
|
|
217
|
-
): Promise
|
|
221
|
+
): Promise<$type.enforce<AppBskyEmbedExternal.Main | AppBskyEmbedImages.Main | AppBskyEmbedVideo.Main>> {
|
|
218
222
|
const type = embed.type;
|
|
219
223
|
|
|
220
224
|
if (type === 'external') {
|
|
221
225
|
const rawThumb = embed.thumbnail;
|
|
222
|
-
let thumb:
|
|
226
|
+
let thumb: AtBlob<any> | undefined;
|
|
223
227
|
|
|
224
228
|
if (rawThumb !== undefined) {
|
|
225
229
|
if (rawThumb instanceof Blob) {
|
|
226
|
-
|
|
230
|
+
assertClient(client, `PostExternalEmbed.thumbnail`);
|
|
227
231
|
thumb = await uploadBlob(rawThumb);
|
|
228
232
|
} else {
|
|
229
233
|
thumb = rawThumb;
|
|
@@ -247,10 +251,10 @@ export async function createThread(
|
|
|
247
251
|
for (const image of embed.images) {
|
|
248
252
|
const aspectRatio = image.aspectRatio;
|
|
249
253
|
const rawBlob = image.blob;
|
|
250
|
-
let blob:
|
|
254
|
+
let blob: AtBlob<any>;
|
|
251
255
|
|
|
252
256
|
if (rawBlob instanceof Blob) {
|
|
253
|
-
|
|
257
|
+
assertClient(client, `PostImageEmbed.images[].blob`);
|
|
254
258
|
blob = await uploadBlob(rawBlob);
|
|
255
259
|
} else {
|
|
256
260
|
blob = rawBlob;
|
|
@@ -272,10 +276,10 @@ export async function createThread(
|
|
|
272
276
|
if (type === 'video') {
|
|
273
277
|
const aspectRatio = embed.aspectRatio;
|
|
274
278
|
const rawBlob = embed.blob;
|
|
275
|
-
let blob:
|
|
279
|
+
let blob: AtBlob<any> | undefined;
|
|
276
280
|
|
|
277
281
|
if (rawBlob instanceof Blob) {
|
|
278
|
-
|
|
282
|
+
assertClient(client, `PostVideoEmbed.blob`);
|
|
279
283
|
blob = await uploadBlob(rawBlob);
|
|
280
284
|
} else {
|
|
281
285
|
blob = rawBlob;
|
|
@@ -292,7 +296,9 @@ export async function createThread(
|
|
|
292
296
|
assert(false, `Unexpected end of code`);
|
|
293
297
|
}
|
|
294
298
|
|
|
295
|
-
async function resolveRecordEmbed(
|
|
299
|
+
async function resolveRecordEmbed(
|
|
300
|
+
embed: PostRecordEmbed,
|
|
301
|
+
): Promise<$type.enforce<AppBskyEmbedRecord.Main>> {
|
|
296
302
|
const uri = embed.uri;
|
|
297
303
|
let cid = embed.cid;
|
|
298
304
|
|
|
@@ -300,36 +306,42 @@ export async function createThread(
|
|
|
300
306
|
const type = embed.type;
|
|
301
307
|
|
|
302
308
|
if (type === 'quote') {
|
|
303
|
-
|
|
309
|
+
assertClient(client, 'PostQuoteEmbed');
|
|
304
310
|
|
|
305
311
|
const post = await getPost(uri);
|
|
306
312
|
|
|
307
313
|
cid = post.cid;
|
|
308
314
|
} else if (type === 'feed') {
|
|
309
|
-
|
|
315
|
+
assertClient(client, 'PostFeedEmbed');
|
|
310
316
|
|
|
311
|
-
const
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
317
|
+
const data = await ok(
|
|
318
|
+
client.get('app.bsky.feed.getFeedGenerator', {
|
|
319
|
+
signal: signal,
|
|
320
|
+
params: { feed: uri },
|
|
321
|
+
}),
|
|
322
|
+
);
|
|
315
323
|
|
|
316
324
|
cid = data.view.cid;
|
|
317
325
|
} else if (type === 'list') {
|
|
318
|
-
|
|
326
|
+
assertClient(client, 'PostListEmbed');
|
|
319
327
|
|
|
320
|
-
const
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
328
|
+
const data = await ok(
|
|
329
|
+
client.get('app.bsky.graph.getList', {
|
|
330
|
+
signal: signal,
|
|
331
|
+
params: { list: uri, limit: 1 },
|
|
332
|
+
}),
|
|
333
|
+
);
|
|
324
334
|
|
|
325
335
|
cid = data.list.cid;
|
|
326
336
|
} else if (type === 'starterpack') {
|
|
327
|
-
|
|
337
|
+
assertClient(client, 'PostStarterpackEmbed');
|
|
328
338
|
|
|
329
|
-
const
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
339
|
+
const data = await ok(
|
|
340
|
+
client.get('app.bsky.graph.getStarterPack', {
|
|
341
|
+
signal: signal,
|
|
342
|
+
params: { starterPack: uri },
|
|
343
|
+
}),
|
|
344
|
+
);
|
|
333
345
|
|
|
334
346
|
cid = data.starterPack.cid;
|
|
335
347
|
} else {
|
|
@@ -347,36 +359,43 @@ export async function createThread(
|
|
|
347
359
|
}
|
|
348
360
|
}
|
|
349
361
|
|
|
350
|
-
async function uploadBlob(blob: Blob): Promise<
|
|
362
|
+
async function uploadBlob(blob: Blob): Promise<AtBlob> {
|
|
351
363
|
// `rpc` intentionally non-null asserted.
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
364
|
+
const data = await ok(
|
|
365
|
+
client!.post('com.atproto.repo.uploadBlob', {
|
|
366
|
+
signal: signal,
|
|
367
|
+
input: blob,
|
|
368
|
+
}),
|
|
369
|
+
);
|
|
356
370
|
|
|
357
371
|
return data.blob;
|
|
358
372
|
}
|
|
359
373
|
|
|
360
|
-
async function getPost(uri:
|
|
374
|
+
async function getPost(uri: ResourceUri): Promise<AppBskyFeedDefs.PostView> {
|
|
361
375
|
// `rpc` intentionally non-null asserted.
|
|
362
|
-
const
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
376
|
+
const data = await ok(
|
|
377
|
+
client!.get('app.bsky.feed.getPosts', {
|
|
378
|
+
signal: signal,
|
|
379
|
+
params: {
|
|
380
|
+
uris: [uri],
|
|
381
|
+
},
|
|
382
|
+
}),
|
|
383
|
+
);
|
|
368
384
|
|
|
369
385
|
const post = data.posts[0];
|
|
370
386
|
if (!post) {
|
|
371
|
-
throw new
|
|
387
|
+
throw new ClientResponseError({
|
|
388
|
+
status: 400,
|
|
389
|
+
data: { error: 'NotFound', message: `Post not found: ${uri}` },
|
|
390
|
+
});
|
|
372
391
|
}
|
|
373
392
|
|
|
374
393
|
return post;
|
|
375
394
|
}
|
|
376
395
|
}
|
|
377
396
|
|
|
378
|
-
function resolveThreadgate(gate: ComposedThreadgate): AppBskyFeedThreadgate.
|
|
379
|
-
const rules: AppBskyFeedThreadgate.
|
|
397
|
+
function resolveThreadgate(gate: ComposedThreadgate): AppBskyFeedThreadgate.Main['allow'] {
|
|
398
|
+
const rules: AppBskyFeedThreadgate.Main['allow'] = [];
|
|
380
399
|
|
|
381
400
|
if (gate.follows) {
|
|
382
401
|
rules.push({ $type: 'app.bsky.feed.threadgate#followingRule' });
|
|
@@ -410,8 +429,8 @@ function assert(condition: boolean, message: string): asserts condition {
|
|
|
410
429
|
}
|
|
411
430
|
}
|
|
412
431
|
|
|
413
|
-
function
|
|
414
|
-
if (
|
|
415
|
-
throw new Error(`${thing} requires supplying
|
|
432
|
+
function assertClient(client: Client | undefined, thing: string): asserts client {
|
|
433
|
+
if (client === undefined) {
|
|
434
|
+
throw new Error(`${thing} requires supplying Client instance`);
|
|
416
435
|
}
|
|
417
436
|
}
|
package/lib/types.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { Client } from '@atcute/client';
|
|
2
|
+
import type { Blob as AtBlob, Did, GenericUri, ResourceUri } from '@atcute/lexicons';
|
|
3
|
+
|
|
4
|
+
import type * as AppBskyEmbedRecord from '@atcute/bluesky/types/app/embed/record';
|
|
5
|
+
import type * as AppBskyFeedDefs from '@atcute/bluesky/types/app/feed/defs';
|
|
6
|
+
import type * as AppBskyRichtextFacet from '@atcute/bluesky/types/app/richtext/facet';
|
|
3
7
|
|
|
4
8
|
/** Interface containing aspect ratio of the media */
|
|
5
9
|
export interface MediaAspectRatio {
|
|
@@ -13,7 +17,7 @@ export interface MediaAspectRatio {
|
|
|
13
17
|
export interface PostExternalEmbed {
|
|
14
18
|
type: 'external';
|
|
15
19
|
/** Link to the page */
|
|
16
|
-
uri:
|
|
20
|
+
uri: GenericUri;
|
|
17
21
|
/** Page title */
|
|
18
22
|
title: string;
|
|
19
23
|
/** Page description */
|
|
@@ -24,7 +28,7 @@ export interface PostExternalEmbed {
|
|
|
24
28
|
* you to also supply an authenticated RPC instance for it to be able to make
|
|
25
29
|
* procedure calls.
|
|
26
30
|
*/
|
|
27
|
-
thumbnail?: Blob |
|
|
31
|
+
thumbnail?: Blob | AtBlob;
|
|
28
32
|
/** Labels to describe this external embed */
|
|
29
33
|
labels?: string[];
|
|
30
34
|
}
|
|
@@ -37,7 +41,7 @@ export interface ComposedImage {
|
|
|
37
41
|
* you to also supply an authenticated RPC instance for it to be able to make
|
|
38
42
|
* procedure calls.
|
|
39
43
|
*/
|
|
40
|
-
blob: Blob |
|
|
44
|
+
blob: Blob | AtBlob;
|
|
41
45
|
/**
|
|
42
46
|
* Alternative text for this image, helps describe images for low-vision users
|
|
43
47
|
* and provide context for everyone.
|
|
@@ -68,7 +72,7 @@ export interface PostVideoEmbed {
|
|
|
68
72
|
* you to also supply an authenticated RPC instance for it to be able to make
|
|
69
73
|
* procedure calls.
|
|
70
74
|
*/
|
|
71
|
-
blob: Blob |
|
|
75
|
+
blob: Blob | AtBlob;
|
|
72
76
|
/**
|
|
73
77
|
* Alternative text for this video, helps describe video for low-vision users
|
|
74
78
|
* and provide context for everyone.
|
|
@@ -92,7 +96,7 @@ export type PostMediaEmbed = PostExternalEmbed | PostImageEmbed | PostVideoEmbed
|
|
|
92
96
|
export interface PostFeedEmbed {
|
|
93
97
|
type: 'feed';
|
|
94
98
|
/** AT-URI of the feed */
|
|
95
|
-
uri:
|
|
99
|
+
uri: ResourceUri;
|
|
96
100
|
/**
|
|
97
101
|
* CID of the feed, if not supplied, requires you to also supply an RPC
|
|
98
102
|
* instance for it to be able to make query calls.
|
|
@@ -104,7 +108,7 @@ export interface PostFeedEmbed {
|
|
|
104
108
|
export interface PostListEmbed {
|
|
105
109
|
type: 'list';
|
|
106
110
|
/** AT-URI of the list */
|
|
107
|
-
uri:
|
|
111
|
+
uri: ResourceUri;
|
|
108
112
|
/**
|
|
109
113
|
* CID of the list, if not supplied, requires you to also supply an RPC
|
|
110
114
|
* instance for it to be able to make query calls.
|
|
@@ -116,7 +120,7 @@ export interface PostListEmbed {
|
|
|
116
120
|
export interface PostQuoteEmbed {
|
|
117
121
|
type: 'quote';
|
|
118
122
|
/** AT-URI of the post */
|
|
119
|
-
uri:
|
|
123
|
+
uri: ResourceUri;
|
|
120
124
|
/**
|
|
121
125
|
* CID of the post, if not supplied, requires you to also supply an RPC
|
|
122
126
|
* instance for it to be able to make query calls.
|
|
@@ -128,7 +132,7 @@ export interface PostQuoteEmbed {
|
|
|
128
132
|
export interface PostStarterpackEmbed {
|
|
129
133
|
type: 'starterpack';
|
|
130
134
|
/** AT-URI of the post */
|
|
131
|
-
uri:
|
|
135
|
+
uri: ResourceUri;
|
|
132
136
|
/**
|
|
133
137
|
* CID of the starter pack, if not supplied, requires you to also supply an
|
|
134
138
|
* RPC instance for it to be able to make query calls.
|
|
@@ -167,17 +171,17 @@ export interface ComposedThreadgate {
|
|
|
167
171
|
/** Allow replies from users mentioned in the post */
|
|
168
172
|
mentions?: boolean;
|
|
169
173
|
/** Allow replies from users that are in these user lists */
|
|
170
|
-
listUris?:
|
|
174
|
+
listUris?: ResourceUri[];
|
|
171
175
|
}
|
|
172
176
|
|
|
173
177
|
/** Base interface for the thread being composed */
|
|
174
178
|
export interface ComposedThread {
|
|
175
179
|
/** An RPC instance, necessary for some options that takes action on your behalf */
|
|
176
|
-
|
|
180
|
+
client?: Client;
|
|
177
181
|
/** Abort signal */
|
|
178
182
|
signal?: AbortSignal;
|
|
179
183
|
/** Author of the thread */
|
|
180
|
-
author:
|
|
184
|
+
author: Did;
|
|
181
185
|
/**
|
|
182
186
|
* The "creation time" for this thread,
|
|
183
187
|
* if not supplied, the current time is used
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@atcute/bluesky-threading",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "5.0.0",
|
|
5
5
|
"description": "create Bluesky threads containing multiple posts with one write",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -18,20 +18,17 @@
|
|
|
18
18
|
".": "./dist/index.js"
|
|
19
19
|
},
|
|
20
20
|
"sideEffects": false,
|
|
21
|
-
"peerDependencies": {
|
|
22
|
-
"@atcute/bluesky": "^2.0.0",
|
|
23
|
-
"@atcute/client": "^3.0.0"
|
|
24
|
-
},
|
|
25
21
|
"dependencies": {
|
|
26
|
-
"@atcute/
|
|
27
|
-
"@atcute/
|
|
28
|
-
"@atcute/
|
|
22
|
+
"@atcute/atproto": "^3.0.0",
|
|
23
|
+
"@atcute/cbor": "^2.2.3",
|
|
24
|
+
"@atcute/cid": "^2.2.2",
|
|
25
|
+
"@atcute/lexicons": "^1.0.0",
|
|
26
|
+
"@atcute/client": "^4.0.0",
|
|
27
|
+
"@atcute/tid": "^1.0.2",
|
|
28
|
+
"@atcute/bluesky": "^3.0.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@types/bun": "^1.2.
|
|
32
|
-
"@atcute/bluesky-richtext-builder": "^2.0.0",
|
|
33
|
-
"@atcute/client": "^3.0.1",
|
|
34
|
-
"@atcute/bluesky": "^2.0.3"
|
|
31
|
+
"@types/bun": "^1.2.13"
|
|
35
32
|
},
|
|
36
33
|
"scripts": {
|
|
37
34
|
"build": "tsc --project tsconfig.build.json",
|