@draftlab/auth 0.15.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.
Files changed (51) hide show
  1. package/dist/adapters/node.d.mts +0 -1
  2. package/dist/client.d.mts +293 -287
  3. package/dist/client.mjs +1 -0
  4. package/dist/core.d.mts +22 -23
  5. package/dist/core.mjs +3 -3
  6. package/dist/error.d.mts +53 -53
  7. package/dist/keys.d.mts +0 -1
  8. package/dist/mutex.d.mts +14 -14
  9. package/dist/provider/apple.d.mts +34 -35
  10. package/dist/provider/code.d.mts +75 -85
  11. package/dist/provider/discord.d.mts +49 -50
  12. package/dist/provider/facebook.d.mts +49 -50
  13. package/dist/provider/github.d.mts +50 -51
  14. package/dist/provider/gitlab.d.mts +34 -35
  15. package/dist/provider/google.d.mts +49 -50
  16. package/dist/provider/linkedin.d.mts +47 -48
  17. package/dist/provider/magiclink.d.mts +28 -38
  18. package/dist/provider/microsoft.d.mts +67 -68
  19. package/dist/provider/oauth2.d.mts +75 -76
  20. package/dist/provider/passkey.d.mts +20 -21
  21. package/dist/provider/password.d.mts +174 -202
  22. package/dist/provider/provider.d.mts +105 -107
  23. package/dist/provider/reddit.d.mts +33 -34
  24. package/dist/provider/slack.d.mts +34 -35
  25. package/dist/provider/spotify.d.mts +34 -35
  26. package/dist/provider/totp.d.mts +43 -44
  27. package/dist/provider/twitch.d.mts +33 -34
  28. package/dist/provider/vercel.d.mts +65 -66
  29. package/dist/revocation.d.mts +29 -30
  30. package/dist/storage/memory.d.mts +11 -12
  31. package/dist/storage/storage.d.mts +110 -110
  32. package/dist/storage/turso.d.mts +0 -1
  33. package/dist/storage/unstorage.d.mts +0 -1
  34. package/dist/subject.d.mts +0 -1
  35. package/dist/themes/theme.d.mts +101 -101
  36. package/dist/toolkit/client.d.mts +56 -57
  37. package/dist/toolkit/providers/facebook.d.mts +0 -1
  38. package/dist/toolkit/providers/github.d.mts +0 -1
  39. package/dist/toolkit/providers/google.d.mts +0 -1
  40. package/dist/toolkit/storage.d.mts +8 -8
  41. package/dist/ui/base.d.mts +0 -1
  42. package/dist/ui/code.d.mts +5 -6
  43. package/dist/ui/form.d.mts +6 -7
  44. package/dist/ui/icon.d.mts +0 -1
  45. package/dist/ui/magiclink.d.mts +5 -6
  46. package/dist/ui/passkey.d.mts +0 -1
  47. package/dist/ui/password.d.mts +2 -3
  48. package/dist/ui/select.d.mts +0 -1
  49. package/dist/ui/totp.d.mts +0 -1
  50. package/dist/util.d.mts +0 -1
  51. package/package.json +3 -3
@@ -46,12 +46,12 @@
46
46
  */
47
47
  interface ColorScheme {
48
48
  /**
49
- * The value for dark mode.
50
- */
49
+ * The value for dark mode.
50
+ */
51
51
  dark: string;
52
52
  /**
53
- * The value for light mode.
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
- * 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
- */
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
- * 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
- */
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
- * The border radius of the UI elements.
85
- *
86
- * @example
87
- * ```ts
88
- * {
89
- * radius: "none"
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
- * 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
- */
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
- * 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
- */
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
- * 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
- */
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
- * The font family and scale of the theme.
135
- */
134
+ * The font family and scale of the theme.
135
+ */
136
136
  font?: {
137
137
  /**
138
- * The font family of the theme.
139
- *
140
- * @example
141
- * ```ts
142
- * {
143
- * font: {
144
- * family: "Geist Mono, monospace"
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
- * 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
- */
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
- * 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
- */
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
- * Initiate OAuth authorization flow.
64
- *
65
- * @param provider - Provider name (key from providers config)
66
- * @param options - Authorization options
67
- * @returns Authorization URL to redirect user to
68
- *
69
- * @example
70
- * ```ts
71
- * // Basic usage
72
- * const { url } = await client.authorize('github')
73
- * window.location.href = url
74
- *
75
- * // With custom scopes
76
- * const { url } = await client.authorize('google', {
77
- * scopes: ['openid', 'email', 'profile']
78
- * })
79
- *
80
- * // With additional params
81
- * const { url } = await client.authorize('github', {
82
- * params: { prompt: 'consent' }
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
- * Handle OAuth callback and exchange code for tokens.
92
- *
93
- * @param callbackUrl - Full callback URL with query parameters
94
- * @returns Token exchange result
95
- *
96
- * @throws {Error} If callback URL is invalid, state mismatch, or token exchange fails
97
- *
98
- * @example
99
- * ```ts
100
- * // Client-side
101
- * const result = await client.handleCallback(window.location.href)
102
- * console.log(result.accessToken, result.provider)
103
- *
104
- * // Server-side (Next.js)
105
- * export async function GET(req: Request) {
106
- * const result = await client.handleCallback(req.url)
107
- * // Store tokens, create session, etc.
108
- * return Response.redirect('/')
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
- * Get user info from OAuth provider using access token.
115
- *
116
- * @param provider - Provider name
117
- * @param accessToken - Access token from provider
118
- * @returns User info from provider
119
- *
120
- * @example
121
- * ```ts
122
- * const userInfo = await client.getUserInfo('github', accessToken)
123
- * console.log(userInfo.email, userInfo.name)
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
  /**
@@ -1,7 +1,6 @@
1
1
  import { OAuthStrategy } from "./strategy.mjs";
2
2
 
3
3
  //#region src/toolkit/providers/facebook.d.ts
4
-
5
4
  /**
6
5
  * Facebook OAuth 2.0 strategy.
7
6
  *
@@ -1,7 +1,6 @@
1
1
  import { OAuthStrategy } from "./strategy.mjs";
2
2
 
3
3
  //#region src/toolkit/providers/github.d.ts
4
-
5
4
  /**
6
5
  * GitHub OAuth 2.0 strategy.
7
6
  *
@@ -1,7 +1,6 @@
1
1
  import { OAuthStrategy } from "./strategy.mjs";
2
2
 
3
3
  //#region src/toolkit/providers/google.d.ts
4
-
5
4
  /**
6
5
  * Google OAuth 2.0 / OpenID Connect strategy.
7
6
  *
@@ -23,18 +23,18 @@ interface PKCEState {
23
23
  */
24
24
  interface AuthStorage {
25
25
  /**
26
- * Store PKCE state data.
27
- * @param state - PKCE state to persist
28
- */
26
+ * Store PKCE state data.
27
+ * @param state - PKCE state to persist
28
+ */
29
29
  set(state: PKCEState): void | Promise<void>;
30
30
  /**
31
- * Retrieve stored PKCE state data.
32
- * @returns Stored state or null if not found
33
- */
31
+ * Retrieve stored PKCE state data.
32
+ * @returns Stored state or null if not found
33
+ */
34
34
  get(): PKCEState | null | Promise<PKCEState | null>;
35
35
  /**
36
- * Clear stored PKCE state data.
37
- */
36
+ * Clear stored PKCE state data.
37
+ */
38
38
  clear(): void | Promise<void>;
39
39
  }
40
40
  /**
@@ -3,7 +3,6 @@ import * as preact0 from "preact";
3
3
  import { ComponentChildren } from "preact";
4
4
 
5
5
  //#region src/ui/base.d.ts
6
-
7
6
  /**
8
7
  * Props for the Layout component
9
8
  */
@@ -1,7 +1,6 @@
1
1
  import { CodeProviderOptions } from "../provider/code.mjs";
2
2
 
3
3
  //#region src/ui/code.d.ts
4
-
5
4
  /**
6
5
  * Type for customizable UI copy text
7
6
  */
@@ -26,13 +25,13 @@ type CodeUIMode = "email" | "phone";
26
25
  */
27
26
  interface CodeUIOptions extends Pick<CodeProviderOptions, "sendCode"> {
28
27
  /**
29
- * Input mode determining the type of contact information to collect
30
- * @default "email"
31
- */
28
+ * Input mode determining the type of contact information to collect
29
+ * @default "email"
30
+ */
32
31
  readonly mode?: CodeUIMode;
33
32
  /**
34
- * Custom text copy for UI labels, messages, and errors
35
- */
33
+ * Custom text copy for UI labels, messages, and errors
34
+ */
36
35
  readonly copy?: Partial<CodeUICopy>;
37
36
  }
38
37
  /**
@@ -1,7 +1,6 @@
1
1
  import { ComponentChildren } from "preact";
2
2
 
3
3
  //#region src/ui/form.d.ts
4
-
5
4
  /**
6
5
  * Alert color variant determining the visual style and icon.
7
6
  */
@@ -11,14 +10,14 @@ type FormAlertColor = "danger" | "success";
11
10
  */
12
11
  interface FormAlertProps {
13
12
  /**
14
- * The message text to display in the alert.
15
- * If not provided, the alert will not render.
16
- */
13
+ * The message text to display in the alert.
14
+ * If not provided, the alert will not render.
15
+ */
17
16
  readonly message?: string;
18
17
  /**
19
- * Visual style variant for the alert.
20
- * @default "danger"
21
- */
18
+ * Visual style variant for the alert.
19
+ * @default "danger"
20
+ */
22
21
  readonly color?: FormAlertColor;
23
22
  }
24
23
  /**
@@ -1,7 +1,6 @@
1
1
  import { ComponentChildren } from "preact";
2
2
 
3
3
  //#region src/ui/icon.d.ts
4
-
5
4
  /**
6
5
  * GitHub brand icon with official logo design.
7
6
  */
@@ -1,7 +1,6 @@
1
1
  import { MagicLinkConfig } from "../provider/magiclink.mjs";
2
2
 
3
3
  //#region src/ui/magiclink.d.ts
4
-
5
4
  /**
6
5
  * Type for customizable UI copy text
7
6
  */
@@ -24,13 +23,13 @@ type MagicLinkUIMode = "email" | "phone";
24
23
  */
25
24
  interface MagicLinkUIOptions<Claims extends Record<string, string> = Record<string, string>> extends Pick<MagicLinkConfig<Claims>, "sendLink"> {
26
25
  /**
27
- * Input mode determining the type of contact information to collect
28
- * @default "email"
29
- */
26
+ * Input mode determining the type of contact information to collect
27
+ * @default "email"
28
+ */
30
29
  readonly mode?: MagicLinkUIMode;
31
30
  /**
32
- * Custom text copy for UI labels, messages, and errors
33
- */
31
+ * Custom text copy for UI labels, messages, and errors
32
+ */
34
33
  readonly copy?: Partial<MagicLinkUICopy>;
35
34
  }
36
35
  /**
@@ -1,7 +1,6 @@
1
1
  import { PasskeyProviderConfig } from "../provider/passkey.mjs";
2
2
 
3
3
  //#region src/ui/passkey.d.ts
4
-
5
4
  /**
6
5
  * Strongly typed copy text configuration for passkey UI
7
6
  */
@@ -1,7 +1,6 @@
1
1
  import { PasswordConfig } from "../provider/password.mjs";
2
2
 
3
3
  //#region src/ui/password.d.ts
4
-
5
4
  /**
6
5
  * Strongly typed copy text configuration for password UI
7
6
  */
@@ -30,8 +29,8 @@ interface PasswordUICopy {
30
29
  */
31
30
  interface PasswordUIOptions extends Pick<PasswordConfig, "sendCode" | "validatePassword"> {
32
31
  /**
33
- * Custom text copy for UI labels, messages, and errors
34
- */
32
+ * Custom text copy for UI labels, messages, and errors
33
+ */
35
34
  readonly copy?: Partial<PasswordUICopy>;
36
35
  }
37
36
  /**
@@ -1,7 +1,6 @@
1
1
  import { Theme } from "../themes/theme.mjs";
2
2
 
3
3
  //#region src/ui/select.d.ts
4
-
5
4
  /**
6
5
  * Provider configuration for the select UI
7
6
  */
@@ -1,7 +1,6 @@
1
1
  import { TOTPProviderConfig } from "../provider/totp.mjs";
2
2
 
3
3
  //#region src/ui/totp.d.ts
4
-
5
4
  /**
6
5
  * Strongly typed copy text configuration for TOTP UI
7
6
  */
package/dist/util.d.mts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { RouterContext } from "./router/types.mjs";
2
2
 
3
3
  //#region src/util.d.ts
4
-
5
4
  /**
6
5
  * Utility type that flattens complex types for better IntelliSense display.
7
6
  * Converts intersections and complex mapped types into cleaner object types.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@draftlab/auth",
3
- "version": "0.15.0",
3
+ "version": "0.15.1",
4
4
  "type": "module",
5
5
  "description": "Core implementation for @draftlab/auth",
6
6
  "author": "Matheus Pergoli",
@@ -37,9 +37,9 @@
37
37
  ],
38
38
  "license": "MIT",
39
39
  "devDependencies": {
40
- "@types/node": "^25.0.3",
40
+ "@types/node": "^25.0.9",
41
41
  "@types/qrcode": "^1.5.6",
42
- "tsdown": "0.19.0-beta.5",
42
+ "tsdown": "0.20.0-beta.3",
43
43
  "typescript": "^5.9.3",
44
44
  "@draftlab/tsconfig": "0.1.0"
45
45
  },