@atcute/oauth-browser-client 1.0.16 → 1.0.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.
@@ -16,7 +16,7 @@ export declare class OAuthServerAgent {
16
16
  token: TokenInfo;
17
17
  }>;
18
18
  refresh({ sub, token }: {
19
- sub: At.DID;
19
+ sub: At.Did;
20
20
  token: TokenInfo;
21
21
  }): Promise<TokenInfo>;
22
22
  }
@@ -5,7 +5,7 @@ export interface SessionGetOptions {
5
5
  noCache?: boolean;
6
6
  allowStale?: boolean;
7
7
  }
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[];
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.DID;
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.DID;
12
+ readonly sub: At.Did;
13
13
  name: string;
14
- constructor(sub: At.DID, message: string, options?: ErrorOptions);
14
+ constructor(sub: At.Did, message: string, options?: ErrorOptions);
15
15
  }
16
16
  export declare class OAuthResponseError extends Error {
17
17
  readonly response: Response;
@@ -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.DID>;
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.DID) => Promise<DidDocument>;
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
@@ -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;
@@ -1,6 +1,6 @@
1
1
  import type { At } from '@atcute/client/lexicons';
2
2
  export interface IdentityMetadata {
3
- id: At.DID;
3
+ id: At.Did;
4
4
  raw: string;
5
5
  pds: URL;
6
6
  }
@@ -27,7 +27,7 @@ export interface TokenInfo {
27
27
  access: string;
28
28
  }
29
29
  export interface ExchangeInfo {
30
- sub: At.DID;
30
+ sub: At.Did;
31
31
  aud: string;
32
32
  server: PersistedAuthorizationServerMetadata;
33
33
  }
@@ -1,3 +1,3 @@
1
1
  import type { At } from '@atcute/client/lexicons';
2
- export declare const isDid: (value: string) => value is At.DID;
2
+ export declare const isDid: (value: string) => value is At.Did;
3
3
  export declare const isValidUrl: (urlString: string) => boolean;
@@ -74,7 +74,7 @@ export class OAuthServerAgent {
74
74
  }
75
75
  }
76
76
 
77
- async refresh({ sub, token }: { sub: At.DID; token: TokenInfo }): Promise<TokenInfo> {
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.DID,
136
+ sub: sub as At.Did,
137
137
  aud: resolved.identity.pds.href,
138
138
  server: pick(resolved.metadata, [
139
139
  'issuer',
@@ -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.DID, PendingItem<Session>>();
17
+ const pending = new Map<At.Did, PendingItem<Session>>();
18
18
 
19
- export const getSession = async (sub: At.DID, options?: SessionGetOptions): Promise<Session> => {
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.DID, newSession: Session): Promise<void> => {
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.DID): void => {
101
+ export const deleteStoredSession = (sub: At.Did): void => {
102
102
  database.sessions.delete(sub);
103
103
  };
104
104
 
105
- export const listStoredSessions = (): At.DID[] => {
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.DID, storedSession: Session | undefined): Promise<Session> => {
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
  }
@@ -16,7 +16,7 @@ export class OAuthUserAgent implements FetchHandlerObject {
16
16
  this.#fetch = createDPoPFetch(CLIENT_ID, session.dpopKey, false);
17
17
  }
18
18
 
19
- get sub(): At.DID {
19
+ get sub(): At.Did {
20
20
  return this.session.info.sub;
21
21
  }
22
22
 
package/lib/errors.ts CHANGED
@@ -16,7 +16,7 @@ export class TokenRefreshError extends Error {
16
16
  override name = 'TokenRefreshError';
17
17
 
18
18
  constructor(
19
- public readonly sub: At.DID,
19
+ public readonly sub: At.Did,
20
20
  message: string,
21
21
  options?: ErrorOptions,
22
22
  ) {
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.DID> => {
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.DID): Promise<DidDocument> => {
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.DID;
154
+ let did: At.Did;
155
155
  if (isDid(ident)) {
156
156
  did = ident;
157
157
  } else {
package/lib/store/db.ts CHANGED
@@ -18,7 +18,7 @@ interface SchemaItem<T> {
18
18
 
19
19
  interface Schema {
20
20
  sessions: {
21
- key: At.DID;
21
+ key: At.Did;
22
22
  value: Session;
23
23
  indexes: {
24
24
  expiresAt: number;
@@ -1,7 +1,7 @@
1
1
  import type { At } from '@atcute/client/lexicons';
2
2
 
3
3
  export interface IdentityMetadata {
4
- id: At.DID;
4
+ id: At.Did;
5
5
  raw: string;
6
6
  pds: URL;
7
7
  }
@@ -34,7 +34,7 @@ export interface TokenInfo {
34
34
  }
35
35
 
36
36
  export interface ExchangeInfo {
37
- sub: At.DID;
37
+ sub: At.Did;
38
38
  aud: string;
39
39
  server: PersistedAuthorizationServerMetadata;
40
40
  }
@@ -2,7 +2,7 @@ import type { At } from '@atcute/client/lexicons';
2
2
 
3
3
  const isUrlParseSupported = 'parse' in URL;
4
4
 
5
- export const isDid = (value: string): value is At.DID => {
5
+ export const isDid = (value: string): value is At.Did => {
6
6
  return value.startsWith('did:');
7
7
  };
8
8
 
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.16",
4
+ "version": "1.0.17",
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/uint8array": "^1.0.1",
23
- "@atcute/multibase": "^1.1.2",
24
- "@atcute/client": "^2.0.9"
22
+ "@atcute/client": "^3.0.0",
23
+ "@atcute/multibase": "^1.1.3",
24
+ "@atcute/uint8array": "^1.0.1"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/bun": "^1.2.1"