@atproto/tap 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 +9 -0
- package/dist/client.d.ts +2 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +18 -4
- package/dist/client.js.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +10 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atproto/tap
|
|
2
2
|
|
|
3
|
+
## 0.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#4481](https://github.com/bluesky-social/atproto/pull/4481) [`e15e7cf`](https://github.com/bluesky-social/atproto/commit/e15e7cf1a07d6a4bdd7a9a3c591690613f5414b5) Thanks [@dholms](https://github.com/dholms)! - Fix URL formatting with trailing slash
|
|
8
|
+
|
|
9
|
+
- Updated dependencies []:
|
|
10
|
+
- @atproto/common@0.5.4
|
|
11
|
+
|
|
3
12
|
## 0.0.2
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/client.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export declare class Tap {
|
|
|
8
8
|
url: string;
|
|
9
9
|
private adminPassword?;
|
|
10
10
|
private authHeader?;
|
|
11
|
+
private addReposUrl;
|
|
12
|
+
private removeReposUrl;
|
|
11
13
|
constructor(url: string, config?: TapConfig);
|
|
12
14
|
private getHeaders;
|
|
13
15
|
channel(handler: TapHandler, opts?: TapWebsocketOptions): TapChannel;
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAe,MAAM,iBAAiB,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAA;AACvE,OAAO,EAAE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
package/dist/client.js
CHANGED
|
@@ -25,6 +25,18 @@ class Tap {
|
|
|
25
25
|
writable: true,
|
|
26
26
|
value: void 0
|
|
27
27
|
});
|
|
28
|
+
Object.defineProperty(this, "addReposUrl", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "removeReposUrl", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
28
40
|
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
29
41
|
throw new Error('Invalid URL, expected http:// or https://');
|
|
30
42
|
}
|
|
@@ -33,6 +45,8 @@ class Tap {
|
|
|
33
45
|
if (this.adminPassword) {
|
|
34
46
|
this.authHeader = (0, util_1.formatAdminAuthHeader)(this.adminPassword);
|
|
35
47
|
}
|
|
48
|
+
this.addReposUrl = new URL('/repos/add', this.url);
|
|
49
|
+
this.removeReposUrl = new URL('/repos/remove', this.url);
|
|
36
50
|
}
|
|
37
51
|
getHeaders() {
|
|
38
52
|
const headers = {
|
|
@@ -53,7 +67,7 @@ class Tap {
|
|
|
53
67
|
});
|
|
54
68
|
}
|
|
55
69
|
async addRepos(dids) {
|
|
56
|
-
const response = await fetch(
|
|
70
|
+
const response = await fetch(this.addReposUrl, {
|
|
57
71
|
method: 'POST',
|
|
58
72
|
headers: this.getHeaders(),
|
|
59
73
|
body: JSON.stringify({ dids }),
|
|
@@ -64,7 +78,7 @@ class Tap {
|
|
|
64
78
|
}
|
|
65
79
|
}
|
|
66
80
|
async removeRepos(dids) {
|
|
67
|
-
const response = await fetch(
|
|
81
|
+
const response = await fetch(this.removeReposUrl, {
|
|
68
82
|
method: 'POST',
|
|
69
83
|
headers: this.getHeaders(),
|
|
70
84
|
body: JSON.stringify({ dids }),
|
|
@@ -75,7 +89,7 @@ class Tap {
|
|
|
75
89
|
}
|
|
76
90
|
}
|
|
77
91
|
async resolveDid(did) {
|
|
78
|
-
const response = await fetch(
|
|
92
|
+
const response = await fetch(new URL(`/resolve/${did}`, this.url), {
|
|
79
93
|
method: 'GET',
|
|
80
94
|
headers: this.getHeaders(),
|
|
81
95
|
});
|
|
@@ -89,7 +103,7 @@ class Tap {
|
|
|
89
103
|
return common_1.didDocument.parse(await response.json());
|
|
90
104
|
}
|
|
91
105
|
async getRepoInfo(did) {
|
|
92
|
-
const response = await fetch(
|
|
106
|
+
const response = await fetch(new URL(`/info/${did}`, this.url), {
|
|
93
107
|
method: 'GET',
|
|
94
108
|
headers: this.getHeaders(),
|
|
95
109
|
});
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,4CAA0D;AAC1D,uCAAuE;AACvE,mCAAkD;AAClD,iCAA8C;AAM9C,MAAa,GAAG;
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":";;;AAAA,4CAA0D;AAC1D,uCAAuE;AACvE,mCAAkD;AAClD,iCAA8C;AAM9C,MAAa,GAAG;IAQd,YAAY,GAAW,EAAE,SAAoB,EAAE;QAP/C;;;;;WAAW;QACH;;;;;WAAsB;QACtB;;;;;WAAmB;QAEnB;;;;;WAAgB;QAChB;;;;;WAAmB;QAGzB,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;YAC9D,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAA;QAC9D,CAAC;QACD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,aAAa,GAAG,MAAM,CAAC,aAAa,CAAA;QACzC,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YACvB,IAAI,CAAC,UAA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A;IACjD,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,GAAW;QAC3B,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,SAAS,GAAG,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE;YAC9D,MAAM,EAAE,KAAK;YACb,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE;SAC3B,CAAC,CAAA;QAEF,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAA;YAC7B,MAAM,IAAI,KAAK,CAAC,4BAA4B,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAA;QACpE,CAAC;QAED,OAAO,sBAAc,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;IACpD,CAAC;CACF;AAhGD,kBAgGC","sourcesContent":["import { DidDocument, didDocument } from '@atproto/common'\nimport { TapChannel, TapHandler, TapWebsocketOptions } from './channel'\nimport { RepoInfo, repoInfoSchema } from './types'\nimport { formatAdminAuthHeader } from './util'\n\nexport interface TapConfig {\n adminPassword?: string\n}\n\nexport class Tap {\n url: string\n private adminPassword?: string\n private authHeader?: string\n\n private addReposUrl: URL\n private removeReposUrl: URL\n\n constructor(url: string, config: TapConfig = {}) {\n if (!url.startsWith('http://') && !url.startsWith('https://')) {\n throw new Error('Invalid URL, expected http:// or https://')\n }\n this.url = url\n this.adminPassword = config.adminPassword\n if (this.adminPassword) {\n this.authHeader = formatAdminAuthHeader(this.adminPassword)\n }\n\n this.addReposUrl = new URL('/repos/add', this.url)\n this.removeReposUrl = new URL('/repos/remove', this.url)\n }\n\n private getHeaders(): Record<string, string> {\n const headers: Record<string, string> = {\n 'Content-Type': 'application/json',\n }\n if (this.authHeader) {\n headers['Authorization'] = this.authHeader\n }\n return headers\n }\n\n channel(handler: TapHandler, opts?: TapWebsocketOptions): TapChannel {\n const url = new URL(this.url)\n url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'\n url.pathname = '/channel'\n return new TapChannel(url.toString(), handler, {\n adminPassword: this.adminPassword,\n ...opts,\n })\n }\n\n async addRepos(dids: string[]): Promise<void> {\n const response = await fetch(this.addReposUrl, {\n method: 'POST',\n headers: this.getHeaders(),\n body: JSON.stringify({ dids }),\n })\n await response.body?.cancel() // expect empty body\n\n if (!response.ok) {\n throw new Error(`Failed to add repos: ${response.statusText}`)\n }\n }\n\n async removeRepos(dids: string[]): Promise<void> {\n const response = await fetch(this.removeReposUrl, {\n method: 'POST',\n headers: this.getHeaders(),\n body: JSON.stringify({ dids }),\n })\n await response.body?.cancel() // expect empty body\n\n if (!response.ok) {\n throw new Error(`Failed to remove repos: ${response.statusText}`)\n }\n }\n\n async resolveDid(did: string): Promise<DidDocument | null> {\n const response = await fetch(new URL(`/resolve/${did}`, this.url), {\n method: 'GET',\n headers: this.getHeaders(),\n })\n\n if (response.status === 404) {\n return null\n } else if (!response.ok) {\n await response.body?.cancel()\n throw new Error(`Failed to resolve DID: ${response.statusText}`)\n }\n return didDocument.parse(await response.json())\n }\n\n async getRepoInfo(did: string): Promise<RepoInfo> {\n const response = await fetch(new URL(`/info/${did}`, this.url), {\n method: 'GET',\n headers: this.getHeaders(),\n })\n\n if (!response.ok) {\n await response.body?.cancel()\n throw new Error(`Failed to get repo info: ${response.statusText}`)\n }\n\n return repoInfoSchema.parse(await response.json())\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atproto/tap",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "atproto tap client",
|
|
6
6
|
"keywords": [
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"ws": "^8.12.0",
|
|
26
26
|
"zod": "^3.23.8",
|
|
27
|
-
"@atproto/common": "^0.5.
|
|
27
|
+
"@atproto/common": "^0.5.4",
|
|
28
28
|
"@atproto/syntax": "^0.4.2",
|
|
29
29
|
"@atproto/ws-client": "^0.0.4"
|
|
30
30
|
},
|
package/src/client.ts
CHANGED
|
@@ -12,6 +12,9 @@ export class Tap {
|
|
|
12
12
|
private adminPassword?: string
|
|
13
13
|
private authHeader?: string
|
|
14
14
|
|
|
15
|
+
private addReposUrl: URL
|
|
16
|
+
private removeReposUrl: URL
|
|
17
|
+
|
|
15
18
|
constructor(url: string, config: TapConfig = {}) {
|
|
16
19
|
if (!url.startsWith('http://') && !url.startsWith('https://')) {
|
|
17
20
|
throw new Error('Invalid URL, expected http:// or https://')
|
|
@@ -21,6 +24,9 @@ export class Tap {
|
|
|
21
24
|
if (this.adminPassword) {
|
|
22
25
|
this.authHeader = formatAdminAuthHeader(this.adminPassword)
|
|
23
26
|
}
|
|
27
|
+
|
|
28
|
+
this.addReposUrl = new URL('/repos/add', this.url)
|
|
29
|
+
this.removeReposUrl = new URL('/repos/remove', this.url)
|
|
24
30
|
}
|
|
25
31
|
|
|
26
32
|
private getHeaders(): Record<string, string> {
|
|
@@ -44,7 +50,7 @@ export class Tap {
|
|
|
44
50
|
}
|
|
45
51
|
|
|
46
52
|
async addRepos(dids: string[]): Promise<void> {
|
|
47
|
-
const response = await fetch(
|
|
53
|
+
const response = await fetch(this.addReposUrl, {
|
|
48
54
|
method: 'POST',
|
|
49
55
|
headers: this.getHeaders(),
|
|
50
56
|
body: JSON.stringify({ dids }),
|
|
@@ -57,7 +63,7 @@ export class Tap {
|
|
|
57
63
|
}
|
|
58
64
|
|
|
59
65
|
async removeRepos(dids: string[]): Promise<void> {
|
|
60
|
-
const response = await fetch(
|
|
66
|
+
const response = await fetch(this.removeReposUrl, {
|
|
61
67
|
method: 'POST',
|
|
62
68
|
headers: this.getHeaders(),
|
|
63
69
|
body: JSON.stringify({ dids }),
|
|
@@ -70,7 +76,7 @@ export class Tap {
|
|
|
70
76
|
}
|
|
71
77
|
|
|
72
78
|
async resolveDid(did: string): Promise<DidDocument | null> {
|
|
73
|
-
const response = await fetch(
|
|
79
|
+
const response = await fetch(new URL(`/resolve/${did}`, this.url), {
|
|
74
80
|
method: 'GET',
|
|
75
81
|
headers: this.getHeaders(),
|
|
76
82
|
})
|
|
@@ -85,7 +91,7 @@ export class Tap {
|
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
async getRepoInfo(did: string): Promise<RepoInfo> {
|
|
88
|
-
const response = await fetch(
|
|
94
|
+
const response = await fetch(new URL(`/info/${did}`, this.url), {
|
|
89
95
|
method: 'GET',
|
|
90
96
|
headers: this.getHeaders(),
|
|
91
97
|
})
|