@draftlab/auth 0.14.0 → 0.15.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/dist/adapters/node.d.mts +0 -1
- package/dist/client.d.mts +293 -287
- package/dist/client.mjs +1 -0
- package/dist/core.d.mts +23 -24
- package/dist/core.mjs +6 -6
- package/dist/error.d.mts +53 -53
- package/dist/keys.d.mts +0 -1
- package/dist/mutex.d.mts +14 -14
- package/dist/provider/apple.d.mts +34 -35
- package/dist/provider/code.d.mts +75 -85
- package/dist/provider/code.mjs +83 -0
- package/dist/provider/discord.d.mts +49 -50
- package/dist/provider/facebook.d.mts +49 -50
- package/dist/provider/github.d.mts +50 -51
- package/dist/provider/gitlab.d.mts +34 -35
- package/dist/provider/google.d.mts +49 -50
- package/dist/provider/linkedin.d.mts +47 -48
- package/dist/provider/magiclink.d.mts +28 -38
- package/dist/provider/magiclink.mjs +57 -0
- package/dist/provider/microsoft.d.mts +67 -68
- package/dist/provider/oauth2.d.mts +75 -76
- package/dist/provider/oauth2.mjs +57 -0
- package/dist/provider/passkey.d.mts +20 -21
- package/dist/provider/password.d.mts +174 -202
- package/dist/provider/provider.d.mts +107 -109
- package/dist/provider/reddit.d.mts +33 -34
- package/dist/provider/slack.d.mts +34 -35
- package/dist/provider/spotify.d.mts +34 -35
- package/dist/provider/totp.d.mts +43 -44
- package/dist/provider/twitch.d.mts +33 -34
- package/dist/provider/vercel.d.mts +65 -66
- package/dist/revocation.d.mts +29 -30
- package/dist/router/context.d.mts +21 -0
- package/dist/router/context.mjs +193 -0
- package/dist/router/cookies.d.mts +8 -0
- package/dist/router/cookies.mjs +13 -0
- package/dist/router/index.d.mts +21 -0
- package/dist/router/index.mjs +107 -0
- package/dist/router/matcher.d.mts +15 -0
- package/dist/router/matcher.mjs +76 -0
- package/dist/router/middleware/cors.d.mts +15 -0
- package/dist/router/middleware/cors.mjs +114 -0
- package/dist/router/safe-request.d.mts +52 -0
- package/dist/router/safe-request.mjs +160 -0
- package/dist/router/types.d.mts +67 -0
- package/dist/router/types.mjs +1 -0
- package/dist/router/variables.d.mts +12 -0
- package/dist/router/variables.mjs +20 -0
- package/dist/storage/memory.d.mts +11 -12
- package/dist/storage/storage.d.mts +110 -110
- package/dist/storage/turso.d.mts +0 -1
- package/dist/storage/unstorage.d.mts +0 -1
- package/dist/subject.d.mts +0 -1
- package/dist/themes/theme.d.mts +101 -101
- package/dist/toolkit/client.d.mts +56 -57
- package/dist/toolkit/providers/facebook.d.mts +0 -1
- package/dist/toolkit/providers/github.d.mts +0 -1
- package/dist/toolkit/providers/google.d.mts +0 -1
- package/dist/toolkit/storage.d.mts +8 -8
- package/dist/ui/base.d.mts +0 -1
- package/dist/ui/code.d.mts +5 -6
- package/dist/ui/form.d.mts +6 -7
- package/dist/ui/icon.d.mts +0 -1
- package/dist/ui/magiclink.d.mts +5 -6
- package/dist/ui/passkey.d.mts +0 -1
- package/dist/ui/password.d.mts +2 -3
- package/dist/ui/select.d.mts +0 -1
- package/dist/ui/totp.d.mts +0 -1
- package/dist/util.d.mts +1 -2
- package/package.json +6 -7
|
@@ -10,34 +10,34 @@
|
|
|
10
10
|
*/
|
|
11
11
|
interface StorageAdapter {
|
|
12
12
|
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
* Retrieves a value by its key path.
|
|
14
|
+
*
|
|
15
|
+
* @param key - Array of key segments forming the storage path
|
|
16
|
+
* @returns Promise resolving to the stored value or undefined if not found
|
|
17
|
+
*/
|
|
18
18
|
get(key: string[]): Promise<Record<string, unknown> | undefined>;
|
|
19
19
|
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
* Removes a value by its key path.
|
|
21
|
+
*
|
|
22
|
+
* @param key - Array of key segments forming the storage path
|
|
23
|
+
* @returns Promise that resolves when removal is complete
|
|
24
|
+
*/
|
|
25
25
|
remove(key: string[]): Promise<void>;
|
|
26
26
|
/**
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
* Stores a value with an optional expiration date.
|
|
28
|
+
*
|
|
29
|
+
* @param key - Array of key segments forming the storage path
|
|
30
|
+
* @param value - The value to store
|
|
31
|
+
* @param expiry - Optional expiration date for automatic cleanup
|
|
32
|
+
* @returns Promise that resolves when storage is complete
|
|
33
|
+
*/
|
|
34
34
|
set(key: string[], value: unknown, expiry?: Date): Promise<void>;
|
|
35
35
|
/**
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
* Scans for keys matching a prefix pattern.
|
|
37
|
+
*
|
|
38
|
+
* @param prefix - Array of key segments to use as prefix filter
|
|
39
|
+
* @returns Async iterable of key-value pairs matching the prefix
|
|
40
|
+
*/
|
|
41
41
|
scan(prefix: string[]): AsyncIterable<readonly [string[], unknown]>;
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
@@ -75,104 +75,104 @@ declare const splitKey: (key: string) => string[];
|
|
|
75
75
|
*/
|
|
76
76
|
declare const Storage: {
|
|
77
77
|
/**
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
* Encodes key segments by escaping special characters.
|
|
79
|
+
* Ensures storage keys don't contain unescaped separator characters that could cause collisions.
|
|
80
|
+
*
|
|
81
|
+
* @param key - Array of key segments to encode
|
|
82
|
+
* @returns Array of properly escaped key segments
|
|
83
|
+
*
|
|
84
|
+
* @throws {Error} If any segment is empty or whitespace-only
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* Storage.encode(['user', 'data\x1fwith\x1fseparators'])
|
|
89
|
+
* // Returns: ['user', 'data\\x1fwith\\x1fseparators']
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
92
|
readonly encode: (key: string[]) => string[];
|
|
93
93
|
/**
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
94
|
+
* Decodes key segments by unescaping special characters.
|
|
95
|
+
* Reverse operation of encode().
|
|
96
|
+
*
|
|
97
|
+
* @param key - Array of encoded key segments
|
|
98
|
+
* @returns Array of decoded key segments
|
|
99
|
+
*
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
102
|
readonly decode: (key: string[]) => string[];
|
|
103
103
|
/**
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
104
|
+
* Retrieves a typed value from storage.
|
|
105
|
+
*
|
|
106
|
+
* @template T - Expected type of the stored value
|
|
107
|
+
* @param adapter - Storage adapter to use
|
|
108
|
+
* @param key - Array of key segments identifying the value
|
|
109
|
+
* @returns Promise resolving to the typed value or null if not found
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```ts
|
|
113
|
+
* interface UserSession {
|
|
114
|
+
* userId: string
|
|
115
|
+
* expiresAt: number
|
|
116
|
+
* }
|
|
117
|
+
*
|
|
118
|
+
* const session = await Storage.get<UserSession>(adapter, ['sessions', sessionId])
|
|
119
|
+
* if (session) {
|
|
120
|
+
* // Fully typed: session.userId
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
124
|
readonly get: <T = Record<string, unknown>>(adapter: StorageAdapter, key: string[]) => Promise<T | null>;
|
|
125
125
|
/**
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
126
|
+
* Stores a value with optional time-to-live in seconds.
|
|
127
|
+
* Validates that TTL is a positive integer to prevent edge cases like negative or overflow values.
|
|
128
|
+
*
|
|
129
|
+
* @param adapter - Storage adapter to use
|
|
130
|
+
* @param key - Array of key segments identifying where to store
|
|
131
|
+
* @param value - The value to store
|
|
132
|
+
* @param ttlSeconds - Optional TTL in seconds for automatic expiration
|
|
133
|
+
* @returns Promise that resolves when storage is complete
|
|
134
|
+
*
|
|
135
|
+
* @throws {RangeError} If TTL is invalid (negative, non-integer, or exceeds maximum)
|
|
136
|
+
*
|
|
137
|
+
* @example
|
|
138
|
+
* ```ts
|
|
139
|
+
* // Store with 1 hour TTL
|
|
140
|
+
* await Storage.set(adapter, ['sessions', sessionId], sessionData, 3600)
|
|
141
|
+
*
|
|
142
|
+
* // Store permanently (no expiration)
|
|
143
|
+
* await Storage.set(adapter, ['users', userId], userData)
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
146
|
readonly set: (adapter: StorageAdapter, key: string[], value: unknown, ttlSeconds?: number) => Promise<void>;
|
|
147
147
|
/**
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
148
|
+
* Removes a value from storage.
|
|
149
|
+
*
|
|
150
|
+
* @param adapter - Storage adapter to use
|
|
151
|
+
* @param key - Array of key segments identifying the value to remove
|
|
152
|
+
* @returns Promise that resolves when removal is complete
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```ts
|
|
156
|
+
* await Storage.remove(adapter, ['sessions', expiredSessionId])
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
159
|
readonly remove: (adapter: StorageAdapter, key: string[]) => Promise<void>;
|
|
160
160
|
/**
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
161
|
+
* Scans for entries matching a key prefix with type safety.
|
|
162
|
+
*
|
|
163
|
+
* @template T - Expected type of the stored values
|
|
164
|
+
* @param adapter - Storage adapter to use
|
|
165
|
+
* @param prefix - Array of key segments to use as prefix filter
|
|
166
|
+
* @returns Async iterable of typed key-value pairs
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* // Find all user sessions
|
|
171
|
+
* for await (const [key, session] of Storage.scan<UserSession>(adapter, ['sessions'])) {
|
|
172
|
+
* // Session: `${key.join('/')} expires at ${session.expiresAt}`
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
176
|
readonly scan: <T = Record<string, unknown>>(adapter: StorageAdapter, prefix: string[]) => AsyncIterable<readonly [string[], T]>;
|
|
177
177
|
};
|
|
178
178
|
//#endregion
|
package/dist/storage/turso.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { StorageAdapter } from "./storage.mjs";
|
|
|
2
2
|
import { Client } from "@libsql/client";
|
|
3
3
|
|
|
4
4
|
//#region src/storage/turso.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Creates a Turso storage adapter using the provided LibSQL client.
|
|
8
7
|
* Automatically initializes the required database table and implements
|
|
@@ -2,7 +2,6 @@ import { StorageAdapter } from "./storage.mjs";
|
|
|
2
2
|
import { Driver } from "unstorage";
|
|
3
3
|
|
|
4
4
|
//#region src/storage/unstorage.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Creates a Draft Auth storage adapter using Unstorage drivers.
|
|
8
7
|
* Supports automatic expiration, error handling, and any Unstorage driver.
|
package/dist/subject.d.mts
CHANGED
|
@@ -2,7 +2,6 @@ import { Prettify } from "./util.mjs";
|
|
|
2
2
|
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
3
|
|
|
4
4
|
//#region src/subject.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Schema definition for subjects, mapping subject type names to their validation schemas.
|
|
8
7
|
* Each key represents a subject type, and each value is a schema that validates
|
package/dist/themes/theme.d.mts
CHANGED
|
@@ -46,12 +46,12 @@
|
|
|
46
46
|
*/
|
|
47
47
|
interface ColorScheme {
|
|
48
48
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
* The value for dark mode.
|
|
50
|
+
*/
|
|
51
51
|
dark: string;
|
|
52
52
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
* The value for light mode.
|
|
54
|
+
*/
|
|
55
55
|
light: string;
|
|
56
56
|
}
|
|
57
57
|
/**
|
|
@@ -59,122 +59,122 @@ interface ColorScheme {
|
|
|
59
59
|
*/
|
|
60
60
|
interface Theme {
|
|
61
61
|
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
62
|
+
* The name of your app. Also used as the title of the page.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* {
|
|
67
|
+
* title: "Acne"
|
|
68
|
+
* }
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
71
|
title?: string;
|
|
72
72
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
73
|
+
* A URL to the favicon of your app.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* {
|
|
78
|
+
* favicon: "https://www.example.com/favicon.svg"
|
|
79
|
+
* }
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
82
|
favicon?: string;
|
|
83
83
|
/**
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
84
|
+
* The border radius of the UI elements.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* {
|
|
89
|
+
* radius: "none"
|
|
90
|
+
* }
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
93
|
radius?: "none" | "sm" | "md" | "lg" | "full";
|
|
94
94
|
/**
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
95
|
+
* The primary color of the theme.
|
|
96
|
+
*
|
|
97
|
+
* Takes a color or both light and dark colors.
|
|
98
|
+
*
|
|
99
|
+
* @example
|
|
100
|
+
* ```ts
|
|
101
|
+
* {
|
|
102
|
+
* primary: "#FF5E00"
|
|
103
|
+
* }
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
106
|
primary: string | ColorScheme;
|
|
107
107
|
/**
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
* The background color of the theme.
|
|
109
|
+
*
|
|
110
|
+
* Takes a color or both light and dark colors.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* {
|
|
115
|
+
* background: "#FFF"
|
|
116
|
+
* }
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
119
|
background?: string | ColorScheme;
|
|
120
120
|
/**
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
121
|
+
* A URL to the logo of your app.
|
|
122
|
+
*
|
|
123
|
+
* Takes a single image or both light and dark mode versions.
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* {
|
|
128
|
+
* logo: "https://www.example.com/logo.svg"
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
132
|
logo?: string | ColorScheme;
|
|
133
133
|
/**
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
* The font family and scale of the theme.
|
|
135
|
+
*/
|
|
136
136
|
font?: {
|
|
137
137
|
/**
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
138
|
+
* The font family of the theme.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```ts
|
|
142
|
+
* {
|
|
143
|
+
* font: {
|
|
144
|
+
* family: "Geist Mono, monospace"
|
|
145
|
+
* }
|
|
146
|
+
* }
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
149
|
family?: string;
|
|
150
150
|
/**
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
151
|
+
* The font scale of the theme. Can be used to increase or decrease the font sizes across
|
|
152
|
+
* the UI.
|
|
153
|
+
*
|
|
154
|
+
* @default "1"
|
|
155
|
+
* @example
|
|
156
|
+
* ```ts
|
|
157
|
+
* {
|
|
158
|
+
* font: {
|
|
159
|
+
* scale: "1.25"
|
|
160
|
+
* }
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
164
|
scale?: string;
|
|
165
165
|
};
|
|
166
166
|
/**
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
167
|
+
* Custom CSS that's added to the page in a `<style>` tag.
|
|
168
|
+
*
|
|
169
|
+
* This can be used to import custom fonts.
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```ts
|
|
173
|
+
* {
|
|
174
|
+
* css: `@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@100;200;300;400;500;600;700;800;900&display=swap');`
|
|
175
|
+
* }
|
|
176
|
+
* ```
|
|
177
|
+
*/
|
|
178
178
|
css?: string;
|
|
179
179
|
}
|
|
180
180
|
/**
|
|
@@ -2,7 +2,6 @@ import { OAuthStrategy } from "./providers/strategy.mjs";
|
|
|
2
2
|
import { AuthStorage } from "./storage.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/toolkit/client.d.ts
|
|
5
|
-
|
|
6
5
|
/**
|
|
7
6
|
* Configuration for a single OAuth provider.
|
|
8
7
|
*/
|
|
@@ -60,69 +59,69 @@ interface OAuthClientConfig<TProviders extends Record<string, ProviderConfig<OAu
|
|
|
60
59
|
*/
|
|
61
60
|
interface OAuthClient<TProviders extends Record<string, ProviderConfig<OAuthStrategy>>> {
|
|
62
61
|
/**
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
62
|
+
* Initiate OAuth authorization flow.
|
|
63
|
+
*
|
|
64
|
+
* @param provider - Provider name (key from providers config)
|
|
65
|
+
* @param options - Authorization options
|
|
66
|
+
* @returns Authorization URL to redirect user to
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* // Basic usage
|
|
71
|
+
* const { url } = await client.authorize('github')
|
|
72
|
+
* window.location.href = url
|
|
73
|
+
*
|
|
74
|
+
* // With custom scopes
|
|
75
|
+
* const { url } = await client.authorize('google', {
|
|
76
|
+
* scopes: ['openid', 'email', 'profile']
|
|
77
|
+
* })
|
|
78
|
+
*
|
|
79
|
+
* // With additional params
|
|
80
|
+
* const { url } = await client.authorize('github', {
|
|
81
|
+
* params: { prompt: 'consent' }
|
|
82
|
+
* })
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
86
85
|
authorize(provider: (string & {}) | keyof TProviders, options?: AuthorizeOptions): Promise<{
|
|
87
86
|
url: string;
|
|
88
87
|
state: string;
|
|
89
88
|
}>;
|
|
90
89
|
/**
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
90
|
+
* Handle OAuth callback and exchange code for tokens.
|
|
91
|
+
*
|
|
92
|
+
* @param callbackUrl - Full callback URL with query parameters
|
|
93
|
+
* @returns Token exchange result
|
|
94
|
+
*
|
|
95
|
+
* @throws {Error} If callback URL is invalid, state mismatch, or token exchange fails
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* // Client-side
|
|
100
|
+
* const result = await client.handleCallback(window.location.href)
|
|
101
|
+
* console.log(result.accessToken, result.provider)
|
|
102
|
+
*
|
|
103
|
+
* // Server-side (Next.js)
|
|
104
|
+
* export async function GET(req: Request) {
|
|
105
|
+
* const result = await client.handleCallback(req.url)
|
|
106
|
+
* // Store tokens, create session, etc.
|
|
107
|
+
* return Response.redirect('/')
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
112
111
|
handleCallback(callbackUrl: string): Promise<CallbackResult>;
|
|
113
112
|
/**
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
113
|
+
* Get user info from OAuth provider using access token.
|
|
114
|
+
*
|
|
115
|
+
* @param provider - Provider name
|
|
116
|
+
* @param accessToken - Access token from provider
|
|
117
|
+
* @returns User info from provider
|
|
118
|
+
*
|
|
119
|
+
* @example
|
|
120
|
+
* ```ts
|
|
121
|
+
* const userInfo = await client.getUserInfo('github', accessToken)
|
|
122
|
+
* console.log(userInfo.email, userInfo.name)
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
126
125
|
getUserInfo(provider: (string & {}) | keyof TProviders, accessToken: string): Promise<Record<string, unknown>>;
|
|
127
126
|
}
|
|
128
127
|
/**
|