@atproto/lex-client 0.0.2 → 0.0.3
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 +21 -0
- package/dist/agent.d.ts +3 -3
- package/dist/agent.d.ts.map +1 -1
- package/dist/agent.js.map +1 -1
- package/dist/client.d.ts +62 -234
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1 -1
- package/dist/client.js.map +1 -1
- package/dist/error.d.ts +12 -16
- package/dist/error.d.ts.map +1 -1
- package/dist/error.js +7 -5
- package/dist/error.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts +12 -58
- package/dist/lexicons/com/atproto/repo/createRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js +10 -12
- package/dist/lexicons/com/atproto/repo/createRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/defs.defs.d.ts +3 -3
- package/dist/lexicons/com/atproto/repo/defs.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/defs.defs.js +1 -1
- package/dist/lexicons/com/atproto/repo/defs.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts +8 -36
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js +7 -4
- package/dist/lexicons/com/atproto/repo/deleteRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts +4 -40
- package/dist/lexicons/com/atproto/repo/getRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js +5 -4
- package/dist/lexicons/com/atproto/repo/getRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts +13 -41
- package/dist/lexicons/com/atproto/repo/listRecords.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js +8 -11
- package/dist/lexicons/com/atproto/repo/listRecords.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts +12 -60
- package/dist/lexicons/com/atproto/repo/putRecord.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js +10 -15
- package/dist/lexicons/com/atproto/repo/putRecord.defs.js.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts +8 -12
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.d.ts.map +1 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js +3 -1
- package/dist/lexicons/com/atproto/repo/uploadBlob.defs.js.map +1 -1
- package/dist/types.d.ts +4 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/xrpc.d.ts +2 -2
- package/dist/xrpc.d.ts.map +1 -1
- package/dist/xrpc.js +1 -1
- package/dist/xrpc.js.map +1 -1
- package/package.json +20 -12
- package/src/agent.ts +3 -3
- package/src/client.ts +29 -27
- package/src/error.ts +13 -22
- package/src/lexicons/com/atproto/repo/createRecord.defs.ts +58 -0
- package/src/lexicons/com/atproto/repo/createRecord.ts +6 -0
- package/src/lexicons/com/atproto/repo/defs.defs.ts +28 -0
- package/src/lexicons/com/atproto/repo/defs.ts +6 -0
- package/src/lexicons/com/atproto/repo/deleteRecord.defs.ts +54 -0
- package/src/lexicons/com/atproto/repo/deleteRecord.ts +6 -0
- package/src/lexicons/com/atproto/repo/getRecord.defs.ts +42 -0
- package/src/lexicons/com/atproto/repo/getRecord.ts +6 -0
- package/src/lexicons/com/atproto/repo/listRecords.defs.ts +63 -0
- package/src/lexicons/com/atproto/repo/listRecords.ts +6 -0
- package/src/lexicons/com/atproto/repo/putRecord.defs.ts +59 -0
- package/src/lexicons/com/atproto/repo/putRecord.ts +6 -0
- package/src/lexicons/com/atproto/repo/uploadBlob.defs.ts +35 -0
- package/src/lexicons/com/atproto/repo/uploadBlob.ts +6 -0
- package/src/lexicons/com/atproto/repo.ts +11 -0
- package/src/lexicons/com/atproto.ts +5 -0
- package/src/lexicons/com.ts +5 -0
- package/src/types.ts +4 -4
- package/src/xrpc.ts +3 -3
- package/jest.config.js +0 -5
- package/scripts/lex-build.mjs +0 -40
- package/tests/client.test.ts +0 -370
- package/tsconfig.build.tsbuildinfo +0 -1
- package/tsconfig.tests.tsbuildinfo +0 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { l } from '@atproto/lex-schema'
|
|
6
|
+
|
|
7
|
+
const $nsid = 'com.atproto.repo.listRecords'
|
|
8
|
+
|
|
9
|
+
export { $nsid }
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* List a range of records in a repository, matching a specific collection. Does not require auth.
|
|
13
|
+
*/
|
|
14
|
+
const main =
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
l.query(
|
|
17
|
+
$nsid,
|
|
18
|
+
/*#__PURE__*/ l.params({
|
|
19
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
20
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
21
|
+
limit: /*#__PURE__*/ l.optional(
|
|
22
|
+
/*#__PURE__*/ l.integer({ minimum: 1, maximum: 100, default: 50 }),
|
|
23
|
+
),
|
|
24
|
+
cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
25
|
+
reverse: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
26
|
+
}),
|
|
27
|
+
/*#__PURE__*/ l.payload(
|
|
28
|
+
'application/json',
|
|
29
|
+
/*#__PURE__*/ l.object({
|
|
30
|
+
cursor: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
31
|
+
records: /*#__PURE__*/ l.array(
|
|
32
|
+
/*#__PURE__*/ l.ref<Def$0>((() => def$0) as any),
|
|
33
|
+
),
|
|
34
|
+
}),
|
|
35
|
+
),
|
|
36
|
+
)
|
|
37
|
+
export { main }
|
|
38
|
+
|
|
39
|
+
export const $params = main.parameters,
|
|
40
|
+
$output = main.output
|
|
41
|
+
|
|
42
|
+
export type Params = l.InferQueryParameters<typeof main>
|
|
43
|
+
export type Output = l.InferQueryOutputBody<typeof main>
|
|
44
|
+
type Def$0 = {
|
|
45
|
+
$type?: 'com.atproto.repo.listRecords#record'
|
|
46
|
+
uri: l.AtUriString
|
|
47
|
+
cid: l.CidString
|
|
48
|
+
value: l.UnknownObject
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export type { Def$0 as DefRecord }
|
|
52
|
+
|
|
53
|
+
const def$0 = /*#__PURE__*/ l.typedObject<Def$0>(
|
|
54
|
+
$nsid,
|
|
55
|
+
'record',
|
|
56
|
+
/*#__PURE__*/ l.object({
|
|
57
|
+
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
58
|
+
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
59
|
+
value: /*#__PURE__*/ l.unknownObject(),
|
|
60
|
+
}),
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
export { def$0 as record }
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { l } from '@atproto/lex-schema'
|
|
6
|
+
import * as RepoDefs from './defs.defs.js'
|
|
7
|
+
|
|
8
|
+
const $nsid = 'com.atproto.repo.putRecord'
|
|
9
|
+
|
|
10
|
+
export { $nsid }
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Write a repository record, creating or updating it as needed. Requires auth, implemented by PDS.
|
|
14
|
+
*/
|
|
15
|
+
const main =
|
|
16
|
+
/*#__PURE__*/
|
|
17
|
+
l.procedure(
|
|
18
|
+
$nsid,
|
|
19
|
+
/*#__PURE__*/ l.params({}),
|
|
20
|
+
/*#__PURE__*/ l.payload(
|
|
21
|
+
'application/json',
|
|
22
|
+
/*#__PURE__*/ l.object({
|
|
23
|
+
repo: /*#__PURE__*/ l.string({ format: 'at-identifier' }),
|
|
24
|
+
collection: /*#__PURE__*/ l.string({ format: 'nsid' }),
|
|
25
|
+
rkey: /*#__PURE__*/ l.string({ format: 'record-key', maxLength: 512 }),
|
|
26
|
+
validate: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.boolean()),
|
|
27
|
+
record: /*#__PURE__*/ l.unknownObject(),
|
|
28
|
+
swapRecord: /*#__PURE__*/ l.optional(
|
|
29
|
+
/*#__PURE__*/ l.nullable(/*#__PURE__*/ l.string({ format: 'cid' })),
|
|
30
|
+
),
|
|
31
|
+
swapCommit: /*#__PURE__*/ l.optional(
|
|
32
|
+
/*#__PURE__*/ l.string({ format: 'cid' }),
|
|
33
|
+
),
|
|
34
|
+
}),
|
|
35
|
+
),
|
|
36
|
+
/*#__PURE__*/ l.payload(
|
|
37
|
+
'application/json',
|
|
38
|
+
/*#__PURE__*/ l.object({
|
|
39
|
+
uri: /*#__PURE__*/ l.string({ format: 'at-uri' }),
|
|
40
|
+
cid: /*#__PURE__*/ l.string({ format: 'cid' }),
|
|
41
|
+
commit: /*#__PURE__*/ l.optional(
|
|
42
|
+
/*#__PURE__*/ l.ref<RepoDefs.CommitMeta>(
|
|
43
|
+
(() => RepoDefs.commitMeta) as any,
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
validationStatus: /*#__PURE__*/ l.optional(/*#__PURE__*/ l.string()),
|
|
47
|
+
}),
|
|
48
|
+
),
|
|
49
|
+
['InvalidSwap'],
|
|
50
|
+
)
|
|
51
|
+
export { main }
|
|
52
|
+
|
|
53
|
+
export const $params = /*#__PURE__*/ main.parameters,
|
|
54
|
+
$input = /*#__PURE__*/ main.input,
|
|
55
|
+
$output = /*#__PURE__*/ main.output
|
|
56
|
+
|
|
57
|
+
export type Params = l.InferProcedureParameters<typeof main>
|
|
58
|
+
export type Input = l.InferProcedureInputBody<typeof main>
|
|
59
|
+
export type Output = l.InferProcedureOutputBody<typeof main>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { l } from '@atproto/lex-schema'
|
|
6
|
+
|
|
7
|
+
const $nsid = 'com.atproto.repo.uploadBlob'
|
|
8
|
+
|
|
9
|
+
export { $nsid }
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Upload a new blob, to be referenced from a repository record. The blob will be deleted if it is not referenced within a time window (eg, minutes). Blob restrictions (mimetype, size, etc) are enforced when the reference is created. Requires auth, implemented by PDS.
|
|
13
|
+
*/
|
|
14
|
+
const main =
|
|
15
|
+
/*#__PURE__*/
|
|
16
|
+
l.procedure(
|
|
17
|
+
$nsid,
|
|
18
|
+
/*#__PURE__*/ l.params({}),
|
|
19
|
+
/*#__PURE__*/ l.payload('*/*'),
|
|
20
|
+
/*#__PURE__*/ l.payload(
|
|
21
|
+
'application/json',
|
|
22
|
+
/*#__PURE__*/ l.object({
|
|
23
|
+
blob: /*#__PURE__*/ l.blob({ allowLegacy: false }),
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
)
|
|
27
|
+
export { main }
|
|
28
|
+
|
|
29
|
+
export const $params = /*#__PURE__*/ main.parameters,
|
|
30
|
+
$input = /*#__PURE__*/ main.input,
|
|
31
|
+
$output = /*#__PURE__*/ main.output
|
|
32
|
+
|
|
33
|
+
export type Params = l.InferProcedureParameters<typeof main>
|
|
34
|
+
export type Input = l.InferProcedureInputBody<typeof main>
|
|
35
|
+
export type Output = l.InferProcedureOutputBody<typeof main>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* THIS FILE WAS GENERATED BY "@atproto/lex". DO NOT EDIT.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
export * as createRecord from './repo/createRecord.js'
|
|
6
|
+
export * as deleteRecord from './repo/deleteRecord.js'
|
|
7
|
+
export * as getRecord from './repo/getRecord.js'
|
|
8
|
+
export * as listRecords from './repo/listRecords.js'
|
|
9
|
+
export * as putRecord from './repo/putRecord.js'
|
|
10
|
+
export * as uploadBlob from './repo/uploadBlob.js'
|
|
11
|
+
export * as defs from './repo/defs.js'
|
package/src/types.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DidString, UnknownString } from '@atproto/lex-schema'
|
|
2
2
|
|
|
3
|
-
export type {
|
|
3
|
+
export type { DidString, UnknownString }
|
|
4
4
|
|
|
5
5
|
export type DidServiceIdentifier = 'atproto_labeler' | UnknownString
|
|
6
|
-
export type Service = `${
|
|
6
|
+
export type Service = `${DidString}#${DidServiceIdentifier}`
|
|
7
7
|
|
|
8
8
|
export type CallOptions = {
|
|
9
|
-
labelers?: Iterable<
|
|
9
|
+
labelers?: Iterable<DidString>
|
|
10
10
|
signal?: AbortSignal
|
|
11
11
|
headers?: HeadersInit
|
|
12
12
|
service?: Service
|
package/src/xrpc.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { LexValue } from '@atproto/lex-data'
|
|
2
2
|
import { lexParse, lexStringify } from '@atproto/lex-json'
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
DidString,
|
|
5
5
|
InferParamsSchema,
|
|
6
6
|
InferPayloadBody,
|
|
7
7
|
Params,
|
|
@@ -136,7 +136,7 @@ export function xrpcRequestInit<T extends Procedure | Query>(
|
|
|
136
136
|
export function xrpcRequestHeaders(options: {
|
|
137
137
|
headers?: HeadersInit
|
|
138
138
|
service?: Service
|
|
139
|
-
labelers?: Iterable<
|
|
139
|
+
labelers?: Iterable<DidString>
|
|
140
140
|
}): Headers {
|
|
141
141
|
const headers = new Headers(options.headers)
|
|
142
142
|
|
|
@@ -209,7 +209,7 @@ export async function xrpcResponseHandler<M extends Procedure | Query>(
|
|
|
209
209
|
if (
|
|
210
210
|
body != null &&
|
|
211
211
|
encoding === 'application/json' &&
|
|
212
|
-
xrpcErrorBodySchema.
|
|
212
|
+
xrpcErrorBodySchema.matches(body)
|
|
213
213
|
) {
|
|
214
214
|
throw new XrpcResponseError(
|
|
215
215
|
response.status,
|
package/jest.config.js
DELETED
package/scripts/lex-build.mjs
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
/* eslint-env node */
|
|
2
|
-
|
|
3
|
-
import { build } from '@atproto/lex-builder'
|
|
4
|
-
|
|
5
|
-
Promise.all([
|
|
6
|
-
// For src
|
|
7
|
-
build({
|
|
8
|
-
lexicons: '../../../lexicons',
|
|
9
|
-
out: './src/lexicons',
|
|
10
|
-
override: true,
|
|
11
|
-
include: [
|
|
12
|
-
'com.atproto.repo.createRecord',
|
|
13
|
-
'com.atproto.repo.deleteRecord',
|
|
14
|
-
'com.atproto.repo.getRecord',
|
|
15
|
-
'com.atproto.repo.putRecord',
|
|
16
|
-
'com.atproto.repo.listRecords',
|
|
17
|
-
'com.atproto.repo.uploadBlob',
|
|
18
|
-
],
|
|
19
|
-
lib: '@atproto/lex-schema',
|
|
20
|
-
pretty: true,
|
|
21
|
-
pureAnnotations: true,
|
|
22
|
-
}),
|
|
23
|
-
|
|
24
|
-
// For tests
|
|
25
|
-
build({
|
|
26
|
-
lexicons: '../../../lexicons',
|
|
27
|
-
out: './tests/lexicons',
|
|
28
|
-
override: true,
|
|
29
|
-
include: [
|
|
30
|
-
'app.bsky.*',
|
|
31
|
-
'com.atproto.repo.createRecord',
|
|
32
|
-
'com.atproto.repo.getRecord',
|
|
33
|
-
],
|
|
34
|
-
lib: '@atproto/lex-schema',
|
|
35
|
-
pretty: true,
|
|
36
|
-
}),
|
|
37
|
-
]).catch((err) => {
|
|
38
|
-
console.error('Error building lexicon schemas:', err)
|
|
39
|
-
process.exit(1)
|
|
40
|
-
})
|
package/tests/client.test.ts
DELETED
|
@@ -1,370 +0,0 @@
|
|
|
1
|
-
import { LexValue, cidForLex } from '@atproto/lex-cbor'
|
|
2
|
-
import { lexParse } from '@atproto/lex-json'
|
|
3
|
-
import { Action, Client } from '..'
|
|
4
|
-
import * as app from './lexicons/app.js'
|
|
5
|
-
import * as com from './lexicons/com.js'
|
|
6
|
-
|
|
7
|
-
type Preference = app.bsky.actor.defs.Preferences[number]
|
|
8
|
-
|
|
9
|
-
describe('utils', () => {
|
|
10
|
-
describe('TypedObjectSchema', () => {
|
|
11
|
-
it('overrides $type when building an object', () => {
|
|
12
|
-
const _r = app.bsky.actor.defs.adultContentPref.build({
|
|
13
|
-
$type: 'foo',
|
|
14
|
-
enabled: true,
|
|
15
|
-
})
|
|
16
|
-
expect(_r.$type).toBe('app.bsky.actor.defs#adultContentPref')
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
describe('Client', () => {
|
|
22
|
-
describe('actions', () => {
|
|
23
|
-
it('updatePreferences', async () => {
|
|
24
|
-
const fetchHandler = jest.fn(
|
|
25
|
-
async (url: string, init?: RequestInit): Promise<Response> => {
|
|
26
|
-
if (url === '/xrpc/app.bsky.actor.getPreferences') {
|
|
27
|
-
return new Response(
|
|
28
|
-
JSON.stringify({ preferences: storedPreferences }),
|
|
29
|
-
{
|
|
30
|
-
status: 200,
|
|
31
|
-
headers: { 'Content-Type': 'application/json' },
|
|
32
|
-
},
|
|
33
|
-
)
|
|
34
|
-
} else if (url === '/xrpc/app.bsky.actor.putPreferences') {
|
|
35
|
-
expect(typeof init?.body).toBe('string')
|
|
36
|
-
const { preferences } =
|
|
37
|
-
app.bsky.actor.putPreferences.$input.schema.parse(
|
|
38
|
-
lexParse(init?.body as string),
|
|
39
|
-
)
|
|
40
|
-
storedPreferences = preferences
|
|
41
|
-
return new Response(null, { status: 204 })
|
|
42
|
-
} else {
|
|
43
|
-
return new Response('Not Found', { status: 404 })
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
const client = new Client({ fetchHandler })
|
|
49
|
-
|
|
50
|
-
const updatePreferences: Action<
|
|
51
|
-
(pref: Preference[]) => false | Preference[],
|
|
52
|
-
Preference[]
|
|
53
|
-
> = async function (client, updatePreferences, options) {
|
|
54
|
-
const data = await client.call(app.bsky.actor.getPreferences, options)
|
|
55
|
-
|
|
56
|
-
const preferences = updatePreferences(data.preferences)
|
|
57
|
-
if (preferences === false) return data.preferences
|
|
58
|
-
|
|
59
|
-
options?.signal?.throwIfAborted()
|
|
60
|
-
|
|
61
|
-
await client.call(
|
|
62
|
-
app.bsky.actor.putPreferences,
|
|
63
|
-
{ preferences },
|
|
64
|
-
options,
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
return preferences
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const upsertPreference: Action<Preference, Preference[]> =
|
|
71
|
-
async function (client, pref, options) {
|
|
72
|
-
return updatePreferences(
|
|
73
|
-
client,
|
|
74
|
-
(prefs) => [...prefs.filter((p) => p.$type !== pref.$type), pref],
|
|
75
|
-
options,
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
let storedPreferences: Preference[] = [
|
|
80
|
-
app.bsky.actor.defs.adultContentPref.build({
|
|
81
|
-
enabled: false,
|
|
82
|
-
}),
|
|
83
|
-
app.bsky.actor.defs.contentLabelPref.build({
|
|
84
|
-
label: 'my-label',
|
|
85
|
-
visibility: 'warn',
|
|
86
|
-
}),
|
|
87
|
-
]
|
|
88
|
-
|
|
89
|
-
expect(fetchHandler).toHaveBeenCalledTimes(0)
|
|
90
|
-
expect(storedPreferences).toEqual([
|
|
91
|
-
{
|
|
92
|
-
$type: 'app.bsky.actor.defs#adultContentPref',
|
|
93
|
-
enabled: false,
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
$type: 'app.bsky.actor.defs#contentLabelPref',
|
|
97
|
-
label: 'my-label',
|
|
98
|
-
visibility: 'warn',
|
|
99
|
-
},
|
|
100
|
-
])
|
|
101
|
-
|
|
102
|
-
// Upsert adult content preference
|
|
103
|
-
await client.call(
|
|
104
|
-
upsertPreference,
|
|
105
|
-
app.bsky.actor.defs.adultContentPref.build({
|
|
106
|
-
enabled: true,
|
|
107
|
-
}),
|
|
108
|
-
)
|
|
109
|
-
|
|
110
|
-
expect(fetchHandler).toHaveBeenCalledTimes(2)
|
|
111
|
-
expect(storedPreferences).toEqual([
|
|
112
|
-
{
|
|
113
|
-
$type: 'app.bsky.actor.defs#contentLabelPref',
|
|
114
|
-
label: 'my-label',
|
|
115
|
-
visibility: 'warn',
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
$type: 'app.bsky.actor.defs#adultContentPref',
|
|
119
|
-
enabled: true,
|
|
120
|
-
},
|
|
121
|
-
])
|
|
122
|
-
|
|
123
|
-
// @ts-expect-error invalid preference value
|
|
124
|
-
await client.call(upsertPreference, {
|
|
125
|
-
$type: 'app.bsky.actor.defs#adultContentPref',
|
|
126
|
-
// enabled: true,
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
expect(fetchHandler).toHaveBeenCalledTimes(4)
|
|
130
|
-
expect(storedPreferences).toEqual([
|
|
131
|
-
{
|
|
132
|
-
$type: 'app.bsky.actor.defs#contentLabelPref',
|
|
133
|
-
label: 'my-label',
|
|
134
|
-
visibility: 'warn',
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
$type: 'app.bsky.actor.defs#adultContentPref',
|
|
138
|
-
enabled: false, // "false" default will be enforced when parsing the body
|
|
139
|
-
},
|
|
140
|
-
])
|
|
141
|
-
|
|
142
|
-
expect(async () => {
|
|
143
|
-
// @ts-expect-error invalid preference value
|
|
144
|
-
await client.call(upsertPreference, {
|
|
145
|
-
$type: 'app.bsky.actor.defs#adultContentPref',
|
|
146
|
-
enabled: 'not-a-boolean',
|
|
147
|
-
})
|
|
148
|
-
}).rejects.toThrow()
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
|
|
152
|
-
describe('query', () => {
|
|
153
|
-
it('allows perfoming a GET request and parsing the response', async () => {
|
|
154
|
-
const fetchHandler = jest.fn(
|
|
155
|
-
async (url: string, init?: RequestInit): Promise<Response> => {
|
|
156
|
-
expect(url).toBe('/xrpc/app.bsky.actor.getPreferences')
|
|
157
|
-
expect(init?.method).toBe('GET')
|
|
158
|
-
|
|
159
|
-
const responsePayload = {
|
|
160
|
-
preferences: [
|
|
161
|
-
{
|
|
162
|
-
$type: 'app.bsky.actor.defs#adultContentPref',
|
|
163
|
-
enabled: false,
|
|
164
|
-
},
|
|
165
|
-
{
|
|
166
|
-
$type: 'app.bsky.actor.defs#someOtherPref',
|
|
167
|
-
otherField: 'some value',
|
|
168
|
-
},
|
|
169
|
-
],
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return new Response(JSON.stringify(responsePayload), {
|
|
173
|
-
status: 200,
|
|
174
|
-
headers: { 'Content-Type': 'application/json' },
|
|
175
|
-
})
|
|
176
|
-
},
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
const client = new Client({ fetchHandler })
|
|
180
|
-
|
|
181
|
-
const { preferences } = await client.call(app.bsky.actor.getPreferences)
|
|
182
|
-
|
|
183
|
-
expect(preferences).toEqual([
|
|
184
|
-
{
|
|
185
|
-
$type: 'app.bsky.actor.defs#adultContentPref',
|
|
186
|
-
enabled: false,
|
|
187
|
-
},
|
|
188
|
-
{
|
|
189
|
-
$type: 'app.bsky.actor.defs#someOtherPref',
|
|
190
|
-
otherField: 'some value',
|
|
191
|
-
},
|
|
192
|
-
])
|
|
193
|
-
|
|
194
|
-
expect(fetchHandler).toHaveBeenCalledTimes(1)
|
|
195
|
-
|
|
196
|
-
const adultContentPref = preferences.find((p) =>
|
|
197
|
-
app.bsky.actor.defs.adultContentPref.isTypeOf(p),
|
|
198
|
-
)
|
|
199
|
-
|
|
200
|
-
expect(adultContentPref).toEqual({
|
|
201
|
-
$type: 'app.bsky.actor.defs#adultContentPref',
|
|
202
|
-
enabled: false,
|
|
203
|
-
})
|
|
204
|
-
})
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
describe('records', () => {
|
|
208
|
-
it('allows creating records', async () => {
|
|
209
|
-
let currentTid = 0
|
|
210
|
-
// Only works 8 times
|
|
211
|
-
const nextTid = jest.fn(() => `2222222222${2 + currentTid++}22`)
|
|
212
|
-
|
|
213
|
-
const did = 'did:plc:alice'
|
|
214
|
-
const fetchHandler = jest.fn(
|
|
215
|
-
async (url: string, init?: RequestInit): Promise<Response> => {
|
|
216
|
-
expect(url).toBe('/xrpc/com.atproto.repo.createRecord')
|
|
217
|
-
expect(init?.method).toBe('POST')
|
|
218
|
-
expect(typeof init?.body).toBe('string')
|
|
219
|
-
const payload = com.atproto.repo.createRecord.main.input.schema.parse(
|
|
220
|
-
lexParse(init?.body as string),
|
|
221
|
-
)
|
|
222
|
-
|
|
223
|
-
expect(payload).toMatchObject({
|
|
224
|
-
repo: did,
|
|
225
|
-
collection: expect.any(String),
|
|
226
|
-
record: expect.any(Object),
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
const rkey = payload.rkey || nextTid()
|
|
230
|
-
const cid = await cidForLex(payload.record as LexValue)
|
|
231
|
-
|
|
232
|
-
const responsePayload: com.atproto.repo.createRecord.Output = {
|
|
233
|
-
cid: cid.toString(),
|
|
234
|
-
uri: `at://${payload.repo}/${payload.collection}/${rkey}`,
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
return new Response(JSON.stringify(responsePayload), {
|
|
238
|
-
status: 200,
|
|
239
|
-
headers: { 'Content-Type': 'application/json' },
|
|
240
|
-
})
|
|
241
|
-
},
|
|
242
|
-
)
|
|
243
|
-
|
|
244
|
-
const client = new Client({ fetchHandler, did })
|
|
245
|
-
|
|
246
|
-
await expect(async () => {
|
|
247
|
-
await client.create(
|
|
248
|
-
app.bsky.feed.generator,
|
|
249
|
-
{
|
|
250
|
-
// @ts-expect-error invalid DID
|
|
251
|
-
did: 'not-a-did',
|
|
252
|
-
displayName: 'Alice Generator',
|
|
253
|
-
createdAt: '2024-01-01T00:00:00Z',
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
rkey: 'alice-generator',
|
|
257
|
-
validate: true,
|
|
258
|
-
},
|
|
259
|
-
)
|
|
260
|
-
}).rejects.toThrow()
|
|
261
|
-
|
|
262
|
-
// validate performs schema validation before making the request
|
|
263
|
-
expect(fetchHandler).toHaveBeenCalledTimes(0)
|
|
264
|
-
|
|
265
|
-
const newGenerator = await client.create(
|
|
266
|
-
app.bsky.feed.generator,
|
|
267
|
-
{
|
|
268
|
-
did,
|
|
269
|
-
displayName: 'Alice Generator',
|
|
270
|
-
createdAt: '2024-01-01T00:00:00Z',
|
|
271
|
-
},
|
|
272
|
-
{
|
|
273
|
-
rkey: 'alice-generator',
|
|
274
|
-
validate: true,
|
|
275
|
-
},
|
|
276
|
-
)
|
|
277
|
-
|
|
278
|
-
expect(fetchHandler).toHaveBeenCalledTimes(1)
|
|
279
|
-
expect(newGenerator.cid).toBe(
|
|
280
|
-
'bafyreihx5eurnmsnj6ulfby3icl4ebh6pliwuqaze25z4ejitnt23b4vw4',
|
|
281
|
-
)
|
|
282
|
-
|
|
283
|
-
const aliceGenerator = await client.create(
|
|
284
|
-
// @ts-expect-error an "rkey" option is required for feed generator records
|
|
285
|
-
app.bsky.feed.generator,
|
|
286
|
-
{
|
|
287
|
-
did: 'no-a-did',
|
|
288
|
-
displayName: 'Alice Generator',
|
|
289
|
-
createdAt: new Date().toISOString(),
|
|
290
|
-
},
|
|
291
|
-
)
|
|
292
|
-
|
|
293
|
-
expect(nextTid).toHaveBeenCalledTimes(1)
|
|
294
|
-
expect(aliceGenerator.uri).toBe(
|
|
295
|
-
`at://${did}/app.bsky.feed.generator/${'2'.repeat(13)}`,
|
|
296
|
-
)
|
|
297
|
-
|
|
298
|
-
const newProfile = await client.create(app.bsky.actor.profile, {
|
|
299
|
-
displayName: 'Alice',
|
|
300
|
-
})
|
|
301
|
-
|
|
302
|
-
expect(nextTid).toHaveBeenCalledTimes(1)
|
|
303
|
-
expect(fetchHandler).toHaveBeenCalledTimes(3)
|
|
304
|
-
expect(newProfile.uri).toBe(
|
|
305
|
-
'at://did:plc:alice/app.bsky.actor.profile/self',
|
|
306
|
-
)
|
|
307
|
-
|
|
308
|
-
const newPost = await client.create(app.bsky.feed.post, {
|
|
309
|
-
text: 'Hello, world!',
|
|
310
|
-
createdAt: new Date().toISOString(),
|
|
311
|
-
})
|
|
312
|
-
|
|
313
|
-
expect(nextTid).toHaveBeenCalledTimes(2)
|
|
314
|
-
expect(fetchHandler).toHaveBeenCalledTimes(4)
|
|
315
|
-
expect(newPost.uri).toBe(`at://${did}/app.bsky.feed.post/2222222222322`)
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
it('allows fetching records', async () => {
|
|
319
|
-
const did = 'did:plc:alice'
|
|
320
|
-
const fetchHandler = jest.fn(
|
|
321
|
-
async (url: string, init?: RequestInit): Promise<Response> => {
|
|
322
|
-
expect(init?.method).toBe('GET')
|
|
323
|
-
const urlObj = new URL(url, 'https://example.com')
|
|
324
|
-
expect(urlObj.pathname).toBe('/xrpc/com.atproto.repo.getRecord')
|
|
325
|
-
|
|
326
|
-
const repo = urlObj.searchParams.get('repo')
|
|
327
|
-
const collection = urlObj.searchParams.get('collection')
|
|
328
|
-
const rkey = urlObj.searchParams.get('rkey')
|
|
329
|
-
|
|
330
|
-
expect(repo).toBe(did)
|
|
331
|
-
expect(collection).toBe(app.bsky.feed.post.$type)
|
|
332
|
-
expect(rkey).toBe('2222222222222')
|
|
333
|
-
|
|
334
|
-
const record = app.bsky.feed.post.$build({
|
|
335
|
-
text: 'This is an old post',
|
|
336
|
-
createdAt: '2024-01-01T00:00:00Z',
|
|
337
|
-
})
|
|
338
|
-
|
|
339
|
-
const cid = await cidForLex(record)
|
|
340
|
-
|
|
341
|
-
const responsePayload: com.atproto.repo.getRecord.Output = {
|
|
342
|
-
cid: cid.toString(),
|
|
343
|
-
uri: `at://${repo!}/${collection!}/${rkey!}` as any,
|
|
344
|
-
value: record,
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
return new Response(JSON.stringify(responsePayload), {
|
|
348
|
-
status: 200,
|
|
349
|
-
headers: { 'Content-Type': 'application/json' },
|
|
350
|
-
})
|
|
351
|
-
},
|
|
352
|
-
)
|
|
353
|
-
|
|
354
|
-
const client = new Client({ fetchHandler, did })
|
|
355
|
-
|
|
356
|
-
const { value: post } = await client.get(app.bsky.feed.post, {
|
|
357
|
-
rkey: '2222222222222',
|
|
358
|
-
})
|
|
359
|
-
|
|
360
|
-
expect(fetchHandler).toHaveBeenCalledTimes(1)
|
|
361
|
-
expect(post).toMatchObject({
|
|
362
|
-
$type: 'app.bsky.feed.post',
|
|
363
|
-
text: 'This is an old post',
|
|
364
|
-
createdAt: '2024-01-01T00:00:00Z',
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
// @TODO: using getRecord method (to check we got the cid)
|
|
368
|
-
})
|
|
369
|
-
})
|
|
370
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"root":["./src/agent.ts","./src/client.ts","./src/error.ts","./src/index.ts","./src/response.ts","./src/types.ts","./src/xrpc.ts","./src/lexicons/com.ts","./src/lexicons/com/atproto.ts","./src/lexicons/com/atproto/repo.ts","./src/lexicons/com/atproto/repo/createRecord.defs.ts","./src/lexicons/com/atproto/repo/createRecord.ts","./src/lexicons/com/atproto/repo/defs.defs.ts","./src/lexicons/com/atproto/repo/defs.ts","./src/lexicons/com/atproto/repo/deleteRecord.defs.ts","./src/lexicons/com/atproto/repo/deleteRecord.ts","./src/lexicons/com/atproto/repo/getRecord.defs.ts","./src/lexicons/com/atproto/repo/getRecord.ts","./src/lexicons/com/atproto/repo/listRecords.defs.ts","./src/lexicons/com/atproto/repo/listRecords.ts","./src/lexicons/com/atproto/repo/putRecord.defs.ts","./src/lexicons/com/atproto/repo/putRecord.ts","./src/lexicons/com/atproto/repo/uploadBlob.defs.ts","./src/lexicons/com/atproto/repo/uploadBlob.ts"],"version":"5.8.3"}
|