@atcute/client 1.0.0 → 2.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.
- package/README.md +6 -7
- package/dist/{middlewares/auth.d.ts → credential-manager.d.ts} +16 -14
- package/dist/credential-manager.js +177 -0
- package/dist/credential-manager.js.map +1 -0
- package/dist/fetch-handler.d.ts +12 -0
- package/dist/fetch-handler.js +13 -0
- package/dist/fetch-handler.js.map +1 -0
- package/dist/index.d.ts +3 -177
- package/dist/index.js +3 -206
- package/dist/index.js.map +1 -1
- package/dist/lexicons.d.ts +38 -14
- package/dist/rpc.d.ts +96 -0
- package/dist/rpc.js +173 -0
- package/dist/rpc.js.map +1 -0
- package/dist/utils/did.d.ts +3 -1
- package/dist/utils/did.js +3 -1
- package/dist/utils/did.js.map +1 -1
- package/dist/utils/http.d.ts +7 -0
- package/dist/utils/http.js +20 -0
- package/dist/utils/http.js.map +1 -0
- package/package.json +7 -4
- package/dist/middlewares/auth.js +0 -150
- package/dist/middlewares/auth.js.map +0 -1
- package/dist/middlewares/mod.d.ts +0 -24
- package/dist/middlewares/mod.js +0 -24
- package/dist/middlewares/mod.js.map +0 -1
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module
|
|
3
|
+
* Assortment of HTTP utilities
|
|
4
|
+
* This module is exported for convenience and is no way part of public API,
|
|
5
|
+
* it can be removed at any time.
|
|
6
|
+
*/
|
|
7
|
+
export const mergeHeaders = (init, defaults) => {
|
|
8
|
+
let headers;
|
|
9
|
+
for (const name in defaults) {
|
|
10
|
+
const value = defaults[name];
|
|
11
|
+
if (value !== null) {
|
|
12
|
+
headers ??= new Headers(init);
|
|
13
|
+
if (!headers.has(name)) {
|
|
14
|
+
headers.set(name, value);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return headers ?? init;
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../lib/utils/http.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAC3B,IAA6B,EAC7B,QAAuC,EACb,EAAE;IAC5B,IAAI,OAA4B,CAAC;IAEjC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC7B,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QAE7B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;YACpB,OAAO,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;YAE9B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;gBACxB,OAAO,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1B,CAAC;QACF,CAAC;IACF,CAAC;IAED,OAAO,OAAO,IAAI,IAAI,CAAC;AACxB,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@atcute/client",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.1",
|
|
5
5
|
"description": "lightweight and cute API client for AT Protocol",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -13,16 +13,19 @@
|
|
|
13
13
|
"exports": {
|
|
14
14
|
".": "./dist/index.js",
|
|
15
15
|
"./lexicons": "./dist/lexicons.js",
|
|
16
|
-
"./middlewares/auth": "./dist/middlewares/auth.js",
|
|
17
|
-
"./middlewares/mod": "./dist/middlewares/mod.js",
|
|
18
16
|
"./utils/did": "./dist/utils/did.js",
|
|
17
|
+
"./utils/http": "./dist/utils/http.js",
|
|
19
18
|
"./utils/jwt": "./dist/utils/jwt.js"
|
|
20
19
|
},
|
|
21
20
|
"devDependencies": {
|
|
21
|
+
"@vitest/coverage-v8": "^2.0.5",
|
|
22
|
+
"vitest": "^2.0.5",
|
|
23
|
+
"@atcute/internal-dev-env": "^1.0.0",
|
|
22
24
|
"@atcute/lex-cli": "^1.0.0"
|
|
23
25
|
},
|
|
24
26
|
"scripts": {
|
|
25
|
-
"build": "tsc",
|
|
27
|
+
"build": "tsc --project tsconfig.build.json",
|
|
28
|
+
"test": "vitest run",
|
|
26
29
|
"generate": "./scripts/generate-lexicons.sh",
|
|
27
30
|
"prepublish": "rm -rf dist; pnpm run build"
|
|
28
31
|
}
|
package/dist/middlewares/auth.js
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module
|
|
3
|
-
* Contains a middleware that handles authentication to a personal data server.
|
|
4
|
-
*/
|
|
5
|
-
import { fetchHandler, isErrorResponse, XRPCError } from '../index.js';
|
|
6
|
-
import { getPdsEndpoint } from '../utils/did.js';
|
|
7
|
-
import { decodeJwt } from '../utils/jwt.js';
|
|
8
|
-
/** Authentication/session management middleware */
|
|
9
|
-
export class AtpAuth {
|
|
10
|
-
#rpc;
|
|
11
|
-
#refreshSessionPromise;
|
|
12
|
-
#onExpired;
|
|
13
|
-
#onRefresh;
|
|
14
|
-
#onSessionUpdate;
|
|
15
|
-
/** Current session state */
|
|
16
|
-
session;
|
|
17
|
-
constructor(rpc, { onExpired, onRefresh, onSessionUpdate } = {}) {
|
|
18
|
-
this.#rpc = rpc;
|
|
19
|
-
this.#onRefresh = onRefresh;
|
|
20
|
-
this.#onExpired = onExpired;
|
|
21
|
-
this.#onSessionUpdate = onSessionUpdate;
|
|
22
|
-
rpc.hook((next) => async (request) => {
|
|
23
|
-
await this.#refreshSessionPromise;
|
|
24
|
-
let res = await next(this.#decorateRequest(request));
|
|
25
|
-
if (isErrorResponse(res.body, ['ExpiredToken']) && this.session?.refreshJwt) {
|
|
26
|
-
await this.#refreshSession();
|
|
27
|
-
if (this.session) {
|
|
28
|
-
// retry fetch
|
|
29
|
-
res = await next(this.#decorateRequest(request));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return res;
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
#decorateRequest(req) {
|
|
36
|
-
const session = this.session;
|
|
37
|
-
if (session && !req.headers['Authorization']) {
|
|
38
|
-
return {
|
|
39
|
-
...req,
|
|
40
|
-
service: session.pdsUri || req.service,
|
|
41
|
-
headers: {
|
|
42
|
-
...req.headers,
|
|
43
|
-
Authorization: `Bearer ${session.accessJwt}`,
|
|
44
|
-
},
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
return req;
|
|
48
|
-
}
|
|
49
|
-
#refreshSession() {
|
|
50
|
-
return (this.#refreshSessionPromise ||= this.#refreshSessionInner().finally(() => {
|
|
51
|
-
this.#refreshSessionPromise = undefined;
|
|
52
|
-
}));
|
|
53
|
-
}
|
|
54
|
-
async #refreshSessionInner() {
|
|
55
|
-
const session = this.session;
|
|
56
|
-
if (!session || !session.refreshJwt) {
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
const res = await fetchHandler({
|
|
60
|
-
service: session.pdsUri || this.#rpc.service,
|
|
61
|
-
type: 'post',
|
|
62
|
-
nsid: 'com.atproto.server.refreshSession',
|
|
63
|
-
headers: {
|
|
64
|
-
Authorization: `Bearer ${session.refreshJwt}`,
|
|
65
|
-
},
|
|
66
|
-
params: {},
|
|
67
|
-
});
|
|
68
|
-
if (isErrorResponse(res.body, ['ExpiredToken', 'InvalidToken'])) {
|
|
69
|
-
// failed due to a bad refresh token
|
|
70
|
-
this.session = undefined;
|
|
71
|
-
this.#onExpired?.(session);
|
|
72
|
-
}
|
|
73
|
-
else if (res.status === 200) {
|
|
74
|
-
// succeeded, update the session
|
|
75
|
-
this.#updateSession({ ...session, ...res.body });
|
|
76
|
-
this.#onRefresh?.(this.session);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
#updateSession(raw) {
|
|
80
|
-
const didDoc = raw.didDoc;
|
|
81
|
-
let pdsUri;
|
|
82
|
-
if (didDoc) {
|
|
83
|
-
pdsUri = getPdsEndpoint(didDoc);
|
|
84
|
-
}
|
|
85
|
-
const newSession = {
|
|
86
|
-
accessJwt: raw.accessJwt,
|
|
87
|
-
refreshJwt: raw.refreshJwt,
|
|
88
|
-
handle: raw.handle,
|
|
89
|
-
did: raw.did,
|
|
90
|
-
pdsUri: pdsUri,
|
|
91
|
-
email: raw.email,
|
|
92
|
-
emailConfirmed: raw.emailConfirmed,
|
|
93
|
-
emailAuthFactor: raw.emailConfirmed,
|
|
94
|
-
active: raw.active ?? true,
|
|
95
|
-
inactiveStatus: raw.status,
|
|
96
|
-
};
|
|
97
|
-
this.session = newSession;
|
|
98
|
-
this.#onSessionUpdate?.(newSession);
|
|
99
|
-
return newSession;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Resume a saved session
|
|
103
|
-
* @param session Session information, taken from `AtpAuth#session` after login
|
|
104
|
-
*/
|
|
105
|
-
async resume(session) {
|
|
106
|
-
const now = Date.now() / 1000 + 60 * 5;
|
|
107
|
-
const refreshToken = decodeJwt(session.refreshJwt);
|
|
108
|
-
if (now >= refreshToken.exp) {
|
|
109
|
-
throw new XRPCError(401, { kind: 'InvalidToken' });
|
|
110
|
-
}
|
|
111
|
-
const accessToken = decodeJwt(session.accessJwt);
|
|
112
|
-
this.session = session;
|
|
113
|
-
if (now >= accessToken.exp) {
|
|
114
|
-
await this.#refreshSession();
|
|
115
|
-
}
|
|
116
|
-
else {
|
|
117
|
-
const promise = this.#rpc.get('com.atproto.server.getSession', {});
|
|
118
|
-
promise.then((response) => {
|
|
119
|
-
const existing = this.session;
|
|
120
|
-
const next = response.data;
|
|
121
|
-
if (!existing) {
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
this.#updateSession({ ...existing, ...next });
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
if (!this.session) {
|
|
128
|
-
throw new XRPCError(401, { kind: 'InvalidToken' });
|
|
129
|
-
}
|
|
130
|
-
return this.session;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* Perform a login operation
|
|
134
|
-
* @param options Login options
|
|
135
|
-
* @returns Session data that can be saved for later
|
|
136
|
-
*/
|
|
137
|
-
async login(options) {
|
|
138
|
-
// Reset the session
|
|
139
|
-
this.session = undefined;
|
|
140
|
-
const res = await this.#rpc.call('com.atproto.server.createSession', {
|
|
141
|
-
data: {
|
|
142
|
-
identifier: options.identifier,
|
|
143
|
-
password: options.password,
|
|
144
|
-
authFactorToken: options.code,
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
return this.#updateSession(res.data);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
//# sourceMappingURL=auth.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../lib/middlewares/auth.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,SAAS,EAA+B,MAAM,aAAa,CAAC;AAGpG,OAAO,EAAE,cAAc,EAAoB,MAAM,iBAAiB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAgE5C,mDAAmD;AACnD,MAAM,OAAO,OAAO;IACnB,IAAI,CAAO;IACX,sBAAsB,CAAiB;IAEvC,UAAU,CAA8B;IACxC,UAAU,CAA8B;IACxC,gBAAgB,CAAoC;IAEpD,4BAA4B;IAC5B,OAAO,CAAkB;IAEzB,YAAY,GAAS,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,KAAqB,EAAE;QACpF,IAAI,CAAC,IAAI,GAAG,GAAG,CAAC;QAEhB,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,gBAAgB,GAAG,eAAe,CAAC;QAExC,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,KAAK,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BACR,CAAC;gBAED,IAAI,CAAC,cAAc,CAAC,EAAE,GAAG,QAAQ,EAAE,GAAG,IAAI,EAAE,CAAC,CAAC;YAC/C,CAAC,CAAC,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACnB,MAAM,IAAI,SAAS,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC,CAAC;QACpD,CAAC;QAED,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,KAAK,CAAC,OAAyB;QACpC,oBAAoB;QACpB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QAEzB,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,kCAAkC,EAAE;YACpE,IAAI,EAAE;gBACL,UAAU,EAAE,OAAO,CAAC,UAAU;gBAC9B,QAAQ,EAAE,OAAO,CAAC,QAAQ;gBAC1B,eAAe,EAAE,OAAO,CAAC,IAAI;aAC7B;SACD,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACtC,CAAC;CACD"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module
|
|
3
|
-
* Contains a middleware that adds `atproto-accept-labelers` header to requests.
|
|
4
|
-
*/
|
|
5
|
-
import type { XRPC } from '../index.js';
|
|
6
|
-
import type { At } from '../lexicons.js';
|
|
7
|
-
/** Options for constructing a moderation middleware */
|
|
8
|
-
export interface AtpModOptions {
|
|
9
|
-
/** Array of moderation services to use */
|
|
10
|
-
labelers?: ModerationService[];
|
|
11
|
-
}
|
|
12
|
-
/** Moderation middleware, unstable. */
|
|
13
|
-
export declare class AtpMod {
|
|
14
|
-
/** Array of moderation services that gets forwarded as a header */
|
|
15
|
-
labelers: ModerationService[];
|
|
16
|
-
constructor(rpc: XRPC, { labelers }?: AtpModOptions);
|
|
17
|
-
}
|
|
18
|
-
/** Interface detailing what moderator service to use and how it should be used. */
|
|
19
|
-
export interface ModerationService {
|
|
20
|
-
/** Moderator service to use */
|
|
21
|
-
did: At.DID;
|
|
22
|
-
/** Whether it should apply takedowns made by this service. */
|
|
23
|
-
redact?: boolean;
|
|
24
|
-
}
|
package/dist/middlewares/mod.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @module
|
|
3
|
-
* Contains a middleware that adds `atproto-accept-labelers` header to requests.
|
|
4
|
-
*/
|
|
5
|
-
/** Moderation middleware, unstable. */
|
|
6
|
-
export class AtpMod {
|
|
7
|
-
/** Array of moderation services that gets forwarded as a header */
|
|
8
|
-
labelers;
|
|
9
|
-
constructor(rpc, { labelers = [] } = {}) {
|
|
10
|
-
this.labelers = labelers;
|
|
11
|
-
rpc.hook((next) => (request) => {
|
|
12
|
-
return next({
|
|
13
|
-
...request,
|
|
14
|
-
headers: {
|
|
15
|
-
...request.headers,
|
|
16
|
-
'atproto-accept-labelers': this.labelers
|
|
17
|
-
.map((labeler) => labeler.did + (labeler.redact ? `;redact` : ``))
|
|
18
|
-
.join(', '),
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
//# sourceMappingURL=mod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.js","sourceRoot":"","sources":["../../lib/middlewares/mod.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,uCAAuC;AACvC,MAAM,OAAO,MAAM;IAClB,mEAAmE;IACnE,QAAQ,CAAsB;IAE9B,YAAY,GAAS,EAAE,EAAE,QAAQ,GAAG,EAAE,KAAoB,EAAE;QAC3D,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,GAAG,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,OAAO,EAAE,EAAE;YAC9B,OAAO,IAAI,CAAC;gBACX,GAAG,OAAO;gBACV,OAAO,EAAE;oBACR,GAAG,OAAO,CAAC,OAAO;oBAClB,yBAAyB,EAAE,IAAI,CAAC,QAAQ;yBACtC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;yBACjE,IAAI,CAAC,IAAI,CAAC;iBACZ;aACD,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;IACJ,CAAC;CACD"}
|