@atproto/api 0.6.16 → 0.6.17
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/CHANGELOG.md +6 -0
- package/dist/client/lexicons.d.ts +22 -0
- package/dist/client/types/app/bsky/feed/post.d.ts +1 -0
- package/dist/client/types/app/bsky/richtext/facet.d.ts +7 -1
- package/dist/index.js +33 -2
- package/dist/index.js.map +2 -2
- package/package.json +2 -2
- package/src/client/lexicons.ts +23 -0
- package/src/client/types/app/bsky/feed/post.ts +2 -0
- package/src/client/types/app/bsky/richtext/facet.ts +17 -1
- package/tests/agent.test.ts +15 -4
- package/tests/bsky-agent.test.ts +26 -13
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/api",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.17",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Client library for atproto and Bluesky",
|
|
6
6
|
"keywords": [
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"common-tags": "^1.8.2",
|
|
29
29
|
"@atproto/lex-cli": "^0.2.1",
|
|
30
|
-
"@atproto/pds": "^0.1.
|
|
30
|
+
"@atproto/pds": "^0.1.17"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"codegen": "pnpm docgen && node ./scripts/generate-code.mjs && lex gen-api ./src/client ../../lexicons/com/atproto/*/* ../../lexicons/app/bsky/*/*",
|
package/src/client/lexicons.ts
CHANGED
|
@@ -5622,6 +5622,16 @@ export const schemaDict = {
|
|
|
5622
5622
|
type: 'union',
|
|
5623
5623
|
refs: ['lex:com.atproto.label.defs#selfLabels'],
|
|
5624
5624
|
},
|
|
5625
|
+
tags: {
|
|
5626
|
+
type: 'array',
|
|
5627
|
+
maxLength: 8,
|
|
5628
|
+
items: {
|
|
5629
|
+
type: 'string',
|
|
5630
|
+
maxLength: 640,
|
|
5631
|
+
maxGraphemes: 64,
|
|
5632
|
+
},
|
|
5633
|
+
description: 'Additional non-inline tags describing this post.',
|
|
5634
|
+
},
|
|
5625
5635
|
createdAt: {
|
|
5626
5636
|
type: 'string',
|
|
5627
5637
|
format: 'datetime',
|
|
@@ -6761,6 +6771,7 @@ export const schemaDict = {
|
|
|
6761
6771
|
refs: [
|
|
6762
6772
|
'lex:app.bsky.richtext.facet#mention',
|
|
6763
6773
|
'lex:app.bsky.richtext.facet#link',
|
|
6774
|
+
'lex:app.bsky.richtext.facet#tag',
|
|
6764
6775
|
],
|
|
6765
6776
|
},
|
|
6766
6777
|
},
|
|
@@ -6788,6 +6799,18 @@ export const schemaDict = {
|
|
|
6788
6799
|
},
|
|
6789
6800
|
},
|
|
6790
6801
|
},
|
|
6802
|
+
tag: {
|
|
6803
|
+
type: 'object',
|
|
6804
|
+
description: 'A hashtag.',
|
|
6805
|
+
required: ['tag'],
|
|
6806
|
+
properties: {
|
|
6807
|
+
tag: {
|
|
6808
|
+
type: 'string',
|
|
6809
|
+
maxLength: 640,
|
|
6810
|
+
maxGraphemes: 64,
|
|
6811
|
+
},
|
|
6812
|
+
},
|
|
6813
|
+
},
|
|
6791
6814
|
byteSlice: {
|
|
6792
6815
|
type: 'object',
|
|
6793
6816
|
description:
|
|
@@ -8,7 +8,7 @@ import { CID } from 'multiformats/cid'
|
|
|
8
8
|
|
|
9
9
|
export interface Main {
|
|
10
10
|
index: ByteSlice
|
|
11
|
-
features: (Mention | Link | { $type: string; [k: string]: unknown })[]
|
|
11
|
+
features: (Mention | Link | Tag | { $type: string; [k: string]: unknown })[]
|
|
12
12
|
[k: string]: unknown
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -61,6 +61,22 @@ export function validateLink(v: unknown): ValidationResult {
|
|
|
61
61
|
return lexicons.validate('app.bsky.richtext.facet#link', v)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/** A hashtag. */
|
|
65
|
+
export interface Tag {
|
|
66
|
+
tag: string
|
|
67
|
+
[k: string]: unknown
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function isTag(v: unknown): v is Tag {
|
|
71
|
+
return (
|
|
72
|
+
isObj(v) && hasProp(v, '$type') && v.$type === 'app.bsky.richtext.facet#tag'
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function validateTag(v: unknown): ValidationResult {
|
|
77
|
+
return lexicons.validate('app.bsky.richtext.facet#tag', v)
|
|
78
|
+
}
|
|
79
|
+
|
|
64
80
|
/** A text segment. Start is inclusive, end is exclusive. Indices are for utf8-encoded strings. */
|
|
65
81
|
export interface ByteSlice {
|
|
66
82
|
byteStart: number
|
package/tests/agent.test.ts
CHANGED
|
@@ -197,7 +197,7 @@ describe('agent', () => {
|
|
|
197
197
|
|
|
198
198
|
// put the agent through the auth flow
|
|
199
199
|
AtpAgent.configure({ fetch: tokenExpiredFetchHandler })
|
|
200
|
-
const res1 = await agent
|
|
200
|
+
const res1 = await createPost(agent)
|
|
201
201
|
AtpAgent.configure({ fetch: defaultFetchHandler })
|
|
202
202
|
|
|
203
203
|
expect(res1.success).toEqual(true)
|
|
@@ -267,9 +267,9 @@ describe('agent', () => {
|
|
|
267
267
|
// put the agent through the auth flow
|
|
268
268
|
AtpAgent.configure({ fetch: tokenExpiredFetchHandler })
|
|
269
269
|
const [res1, res2, res3] = await Promise.all([
|
|
270
|
-
agent
|
|
271
|
-
agent
|
|
272
|
-
agent
|
|
270
|
+
createPost(agent),
|
|
271
|
+
createPost(agent),
|
|
272
|
+
createPost(agent),
|
|
273
273
|
])
|
|
274
274
|
AtpAgent.configure({ fetch: defaultFetchHandler })
|
|
275
275
|
|
|
@@ -462,3 +462,14 @@ describe('agent', () => {
|
|
|
462
462
|
})
|
|
463
463
|
})
|
|
464
464
|
})
|
|
465
|
+
|
|
466
|
+
const createPost = async (agent: AtpAgent) => {
|
|
467
|
+
return agent.api.com.atproto.repo.createRecord({
|
|
468
|
+
repo: agent.session?.did ?? '',
|
|
469
|
+
collection: 'app.bsky.feed.post',
|
|
470
|
+
record: {
|
|
471
|
+
text: 'hello there',
|
|
472
|
+
createdAt: new Date().toISOString(),
|
|
473
|
+
},
|
|
474
|
+
})
|
|
475
|
+
}
|
package/tests/bsky-agent.test.ts
CHANGED
|
@@ -20,6 +20,20 @@ describe('agent', () => {
|
|
|
20
20
|
await close()
|
|
21
21
|
})
|
|
22
22
|
|
|
23
|
+
const getProfileDisplayName = async (
|
|
24
|
+
agent: BskyAgent,
|
|
25
|
+
): Promise<string | undefined> => {
|
|
26
|
+
try {
|
|
27
|
+
const res = await agent.api.app.bsky.actor.profile.get({
|
|
28
|
+
repo: agent.session?.did || '',
|
|
29
|
+
rkey: 'self',
|
|
30
|
+
})
|
|
31
|
+
return res.value.displayName ?? ''
|
|
32
|
+
} catch (err) {
|
|
33
|
+
return undefined
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
23
37
|
it('upsertProfile correctly creates and updates profiles.', async () => {
|
|
24
38
|
const agent = new BskyAgent({ service: server.url })
|
|
25
39
|
|
|
@@ -28,9 +42,8 @@ describe('agent', () => {
|
|
|
28
42
|
email: 'user1@test.com',
|
|
29
43
|
password: 'password',
|
|
30
44
|
})
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
expect(profile1.data.displayName).toBeFalsy()
|
|
45
|
+
const displayName1 = await getProfileDisplayName(agent)
|
|
46
|
+
expect(displayName1).toBeFalsy()
|
|
34
47
|
|
|
35
48
|
await agent.upsertProfile((existing) => {
|
|
36
49
|
expect(existing).toBeFalsy()
|
|
@@ -39,8 +52,8 @@ describe('agent', () => {
|
|
|
39
52
|
}
|
|
40
53
|
})
|
|
41
54
|
|
|
42
|
-
const
|
|
43
|
-
expect(
|
|
55
|
+
const displayName2 = await getProfileDisplayName(agent)
|
|
56
|
+
expect(displayName2).toBe('Bob')
|
|
44
57
|
|
|
45
58
|
await agent.upsertProfile((existing) => {
|
|
46
59
|
expect(existing).toBeTruthy()
|
|
@@ -49,8 +62,8 @@ describe('agent', () => {
|
|
|
49
62
|
}
|
|
50
63
|
})
|
|
51
64
|
|
|
52
|
-
const
|
|
53
|
-
expect(
|
|
65
|
+
const displayName3 = await getProfileDisplayName(agent)
|
|
66
|
+
expect(displayName3).toBe('BOB')
|
|
54
67
|
})
|
|
55
68
|
|
|
56
69
|
it('upsertProfile correctly handles CAS failures.', async () => {
|
|
@@ -62,8 +75,8 @@ describe('agent', () => {
|
|
|
62
75
|
password: 'password',
|
|
63
76
|
})
|
|
64
77
|
|
|
65
|
-
const
|
|
66
|
-
expect(
|
|
78
|
+
const displayName1 = await getProfileDisplayName(agent)
|
|
79
|
+
expect(displayName1).toBeFalsy()
|
|
67
80
|
|
|
68
81
|
let hasConflicted = false
|
|
69
82
|
let ranTwice = false
|
|
@@ -88,8 +101,8 @@ describe('agent', () => {
|
|
|
88
101
|
})
|
|
89
102
|
expect(ranTwice).toBe(true)
|
|
90
103
|
|
|
91
|
-
const
|
|
92
|
-
expect(
|
|
104
|
+
const displayName2 = await getProfileDisplayName(agent)
|
|
105
|
+
expect(displayName2).toBe('Bob')
|
|
93
106
|
})
|
|
94
107
|
|
|
95
108
|
it('upsertProfile wont endlessly retry CAS failures.', async () => {
|
|
@@ -101,8 +114,8 @@ describe('agent', () => {
|
|
|
101
114
|
password: 'password',
|
|
102
115
|
})
|
|
103
116
|
|
|
104
|
-
const
|
|
105
|
-
expect(
|
|
117
|
+
const displayName1 = await getProfileDisplayName(agent)
|
|
118
|
+
expect(displayName1).toBeFalsy()
|
|
106
119
|
|
|
107
120
|
const p = agent.upsertProfile(async (_existing) => {
|
|
108
121
|
await agent.com.atproto.repo.putRecord({
|