@atcute/oauth-browser-client 1.0.16 → 1.0.18
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/agents/server-agent.d.ts +1 -1
- package/dist/agents/sessions.d.ts +4 -4
- package/dist/agents/user-agent.d.ts +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/resolvers.d.ts +2 -2
- package/dist/store/db.d.ts +1 -1
- package/dist/types/identity.d.ts +1 -1
- package/dist/types/token.d.ts +1 -1
- package/dist/utils/strings.d.ts +1 -1
- package/lib/agents/server-agent.ts +2 -2
- package/lib/agents/sessions.ts +6 -6
- package/lib/agents/user-agent.ts +1 -1
- package/lib/errors.ts +1 -1
- package/lib/resolvers.ts +3 -3
- package/lib/store/db.ts +1 -1
- package/lib/types/identity.ts +1 -1
- package/lib/types/token.ts +1 -1
- package/lib/utils/strings.ts +1 -1
- package/package.json +3 -3
|
@@ -5,7 +5,7 @@ export interface SessionGetOptions {
|
|
|
5
5
|
noCache?: boolean;
|
|
6
6
|
allowStale?: boolean;
|
|
7
7
|
}
|
|
8
|
-
export declare const getSession: (sub: At.
|
|
9
|
-
export declare const storeSession: (sub: At.
|
|
10
|
-
export declare const deleteStoredSession: (sub: At.
|
|
11
|
-
export declare const listStoredSessions: () => At.
|
|
8
|
+
export declare const getSession: (sub: At.Did, options?: SessionGetOptions) => Promise<Session>;
|
|
9
|
+
export declare const storeSession: (sub: At.Did, newSession: Session) => Promise<void>;
|
|
10
|
+
export declare const deleteStoredSession: (sub: At.Did) => void;
|
|
11
|
+
export declare const listStoredSessions: () => At.Did[];
|
|
@@ -6,7 +6,7 @@ export declare class OAuthUserAgent implements FetchHandlerObject {
|
|
|
6
6
|
#private;
|
|
7
7
|
session: Session;
|
|
8
8
|
constructor(session: Session);
|
|
9
|
-
get sub(): At.
|
|
9
|
+
get sub(): At.Did;
|
|
10
10
|
getSession(options?: SessionGetOptions): Promise<Session>;
|
|
11
11
|
signOut(): Promise<void>;
|
|
12
12
|
handle(pathname: string, init?: RequestInit): Promise<Response>;
|
package/dist/errors.d.ts
CHANGED
|
@@ -9,9 +9,9 @@ export declare class ResolverError extends Error {
|
|
|
9
9
|
name: string;
|
|
10
10
|
}
|
|
11
11
|
export declare class TokenRefreshError extends Error {
|
|
12
|
-
readonly sub: At.
|
|
12
|
+
readonly sub: At.Did;
|
|
13
13
|
name: string;
|
|
14
|
-
constructor(sub: At.
|
|
14
|
+
constructor(sub: At.Did, message: string, options?: ErrorOptions);
|
|
15
15
|
}
|
|
16
16
|
export declare class OAuthResponseError extends Error {
|
|
17
17
|
readonly response: Response;
|
package/dist/resolvers.d.ts
CHANGED
|
@@ -8,13 +8,13 @@ import type { AuthorizationServerMetadata, ProtectedResourceMetadata } from './t
|
|
|
8
8
|
* @param handle Domain handle to resolve
|
|
9
9
|
* @returns DID identifier resolved from the domain handle
|
|
10
10
|
*/
|
|
11
|
-
export declare const resolveHandle: (handle: string) => Promise<At.
|
|
11
|
+
export declare const resolveHandle: (handle: string) => Promise<At.Did>;
|
|
12
12
|
/**
|
|
13
13
|
* Get DID documents of did:plc (via plc.directory) and did:web identifiers
|
|
14
14
|
* @param did DID identifier we're seeking DID doc from
|
|
15
15
|
* @returns Retrieved DID document
|
|
16
16
|
*/
|
|
17
|
-
export declare const getDidDocument: (did: At.
|
|
17
|
+
export declare const getDidDocument: (did: At.Did) => Promise<DidDocument>;
|
|
18
18
|
/**
|
|
19
19
|
* Get OAuth protected resource metadata from a host
|
|
20
20
|
* @param host URL of the host
|
package/dist/store/db.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export interface OAuthDatabaseOptions {
|
|
|
8
8
|
export type OAuthDatabase = ReturnType<typeof createOAuthDatabase>;
|
|
9
9
|
export declare const createOAuthDatabase: ({ name }: OAuthDatabaseOptions) => {
|
|
10
10
|
dispose: () => void;
|
|
11
|
-
sessions: SimpleStore<`did:${string}`, Session>;
|
|
11
|
+
sessions: SimpleStore<`did:${string}:${string}`, Session>;
|
|
12
12
|
states: SimpleStore<string, {
|
|
13
13
|
dpopKey: DPoPKey;
|
|
14
14
|
metadata: AuthorizationServerMetadata;
|
package/dist/types/identity.d.ts
CHANGED
package/dist/types/token.d.ts
CHANGED
package/dist/utils/strings.d.ts
CHANGED
|
@@ -74,7 +74,7 @@ export class OAuthServerAgent {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
async refresh({ sub, token }: { sub: At.
|
|
77
|
+
async refresh({ sub, token }: { sub: At.Did; token: TokenInfo }): Promise<TokenInfo> {
|
|
78
78
|
if (!token.refresh) {
|
|
79
79
|
throw new TokenRefreshError(sub, 'no refresh token available');
|
|
80
80
|
}
|
|
@@ -133,7 +133,7 @@ export class OAuthServerAgent {
|
|
|
133
133
|
return {
|
|
134
134
|
token: token,
|
|
135
135
|
info: {
|
|
136
|
-
sub: sub as At.
|
|
136
|
+
sub: sub as At.Did,
|
|
137
137
|
aud: resolved.identity.pds.href,
|
|
138
138
|
server: pick(resolved.metadata, [
|
|
139
139
|
'issuer',
|
package/lib/agents/sessions.ts
CHANGED
|
@@ -14,9 +14,9 @@ export interface SessionGetOptions {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
type PendingItem<V> = Promise<{ value: V; isFresh: boolean }>;
|
|
17
|
-
const pending = new Map<At.
|
|
17
|
+
const pending = new Map<At.Did, PendingItem<Session>>();
|
|
18
18
|
|
|
19
|
-
export const getSession = async (sub: At.
|
|
19
|
+
export const getSession = async (sub: At.Did, options?: SessionGetOptions): Promise<Session> => {
|
|
20
20
|
options?.signal?.throwIfAborted();
|
|
21
21
|
|
|
22
22
|
let allowStored = isTokenUsable;
|
|
@@ -89,7 +89,7 @@ export const getSession = async (sub: At.DID, options?: SessionGetOptions): Prom
|
|
|
89
89
|
return value;
|
|
90
90
|
};
|
|
91
91
|
|
|
92
|
-
export const storeSession = async (sub: At.
|
|
92
|
+
export const storeSession = async (sub: At.Did, newSession: Session): Promise<void> => {
|
|
93
93
|
try {
|
|
94
94
|
database.sessions.set(sub, newSession);
|
|
95
95
|
} catch (err) {
|
|
@@ -98,18 +98,18 @@ export const storeSession = async (sub: At.DID, newSession: Session): Promise<vo
|
|
|
98
98
|
}
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
export const deleteStoredSession = (sub: At.
|
|
101
|
+
export const deleteStoredSession = (sub: At.Did): void => {
|
|
102
102
|
database.sessions.delete(sub);
|
|
103
103
|
};
|
|
104
104
|
|
|
105
|
-
export const listStoredSessions = (): At.
|
|
105
|
+
export const listStoredSessions = (): At.Did[] => {
|
|
106
106
|
return database.sessions.keys();
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
const returnTrue = () => true;
|
|
110
110
|
const returnFalse = () => false;
|
|
111
111
|
|
|
112
|
-
const refreshToken = async (sub: At.
|
|
112
|
+
const refreshToken = async (sub: At.Did, storedSession: Session | undefined): Promise<Session> => {
|
|
113
113
|
if (storedSession === undefined) {
|
|
114
114
|
throw new TokenRefreshError(sub, `session deleted by another tab`);
|
|
115
115
|
}
|
package/lib/agents/user-agent.ts
CHANGED
package/lib/errors.ts
CHANGED
package/lib/resolvers.ts
CHANGED
|
@@ -16,7 +16,7 @@ const DID_WEB_RE = /^([a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*(?:\.[a-zA-Z]{2,}))$/;
|
|
|
16
16
|
* @param handle Domain handle to resolve
|
|
17
17
|
* @returns DID identifier resolved from the domain handle
|
|
18
18
|
*/
|
|
19
|
-
export const resolveHandle = async (handle: string): Promise<At.
|
|
19
|
+
export const resolveHandle = async (handle: string): Promise<At.Did> => {
|
|
20
20
|
const url = DEFAULT_APPVIEW_URL + `/xrpc/com.atproto.identity.resolveHandle` + `?handle=${handle}`;
|
|
21
21
|
|
|
22
22
|
const response = await fetch(url);
|
|
@@ -35,7 +35,7 @@ export const resolveHandle = async (handle: string): Promise<At.DID> => {
|
|
|
35
35
|
* @param did DID identifier we're seeking DID doc from
|
|
36
36
|
* @returns Retrieved DID document
|
|
37
37
|
*/
|
|
38
|
-
export const getDidDocument = async (did: At.
|
|
38
|
+
export const getDidDocument = async (did: At.Did): Promise<DidDocument> => {
|
|
39
39
|
const colon_index = did.indexOf(':', 4);
|
|
40
40
|
|
|
41
41
|
const type = did.slice(4, colon_index);
|
|
@@ -151,7 +151,7 @@ export const getAuthorizationServerMetadata = async (host: string): Promise<Auth
|
|
|
151
151
|
export const resolveFromIdentity = async (
|
|
152
152
|
ident: string,
|
|
153
153
|
): Promise<{ identity: IdentityMetadata; metadata: AuthorizationServerMetadata }> => {
|
|
154
|
-
let did: At.
|
|
154
|
+
let did: At.Did;
|
|
155
155
|
if (isDid(ident)) {
|
|
156
156
|
did = ident;
|
|
157
157
|
} else {
|
package/lib/store/db.ts
CHANGED
package/lib/types/identity.ts
CHANGED
package/lib/types/token.ts
CHANGED
package/lib/utils/strings.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@atcute/oauth-browser-client",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.18",
|
|
5
5
|
"description": "minimal OAuth browser client implementation for AT Protocol",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
},
|
|
20
20
|
"sideEffects": false,
|
|
21
21
|
"dependencies": {
|
|
22
|
+
"@atcute/client": "^3.1.0",
|
|
22
23
|
"@atcute/uint8array": "^1.0.1",
|
|
23
|
-
"@atcute/multibase": "^1.1.
|
|
24
|
-
"@atcute/client": "^2.0.9"
|
|
24
|
+
"@atcute/multibase": "^1.1.3"
|
|
25
25
|
},
|
|
26
26
|
"devDependencies": {
|
|
27
27
|
"@types/bun": "^1.2.1"
|