@draftlab/auth 0.15.0 → 0.16.0

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 (272) hide show
  1. package/dist/esm/allow.js +26 -0
  2. package/dist/esm/client.js +254 -0
  3. package/dist/esm/core.js +597 -0
  4. package/dist/esm/css.d.js +0 -0
  5. package/dist/esm/error.js +88 -0
  6. package/dist/esm/index.js +5 -0
  7. package/dist/esm/keys.js +126 -0
  8. package/dist/esm/mutex.js +53 -0
  9. package/dist/esm/pkce.js +87 -0
  10. package/dist/esm/provider/apple.js +15 -0
  11. package/dist/esm/provider/code.js +62 -0
  12. package/dist/esm/provider/discord.js +15 -0
  13. package/dist/esm/provider/facebook.js +15 -0
  14. package/dist/esm/provider/github.js +15 -0
  15. package/dist/esm/provider/gitlab.js +15 -0
  16. package/dist/esm/provider/google.js +16 -0
  17. package/dist/esm/provider/linkedin.js +15 -0
  18. package/dist/esm/provider/magiclink.js +83 -0
  19. package/dist/esm/provider/microsoft.js +15 -0
  20. package/dist/esm/provider/oauth2.js +130 -0
  21. package/dist/esm/provider/password.js +331 -0
  22. package/dist/esm/provider/provider.js +18 -0
  23. package/dist/esm/provider/reddit.js +15 -0
  24. package/dist/esm/provider/slack.js +15 -0
  25. package/dist/esm/provider/spotify.js +15 -0
  26. package/dist/esm/provider/twitch.js +15 -0
  27. package/dist/esm/provider/vercel.js +17 -0
  28. package/dist/esm/random.js +40 -0
  29. package/dist/esm/revocation.js +27 -0
  30. package/dist/esm/storage/memory.js +110 -0
  31. package/dist/esm/storage/storage.js +56 -0
  32. package/dist/esm/storage/turso.js +93 -0
  33. package/dist/esm/storage/unstorage.js +78 -0
  34. package/dist/esm/subject.js +7 -0
  35. package/dist/esm/themes/theme.js +115 -0
  36. package/dist/esm/toolkit/client.js +119 -0
  37. package/dist/esm/toolkit/index.js +25 -0
  38. package/dist/esm/toolkit/providers/facebook.js +11 -0
  39. package/dist/esm/toolkit/providers/github.js +11 -0
  40. package/dist/esm/toolkit/providers/google.js +11 -0
  41. package/dist/esm/toolkit/providers/strategy.js +0 -0
  42. package/dist/esm/toolkit/storage.js +81 -0
  43. package/dist/esm/toolkit/utils.js +18 -0
  44. package/dist/esm/types.js +0 -0
  45. package/dist/esm/ui/base.js +478 -0
  46. package/dist/esm/ui/code.js +186 -0
  47. package/dist/esm/ui/form.js +46 -0
  48. package/dist/esm/ui/icon.js +242 -0
  49. package/dist/esm/ui/magiclink.js +158 -0
  50. package/dist/esm/ui/password.js +435 -0
  51. package/dist/esm/ui/select.js +102 -0
  52. package/dist/esm/util.js +59 -0
  53. package/dist/{allow.d.mts → types/allow.d.ts} +9 -11
  54. package/dist/types/allow.d.ts.map +1 -0
  55. package/dist/types/client.d.ts +462 -0
  56. package/dist/types/client.d.ts.map +1 -0
  57. package/dist/types/core.d.ts +113 -0
  58. package/dist/types/core.d.ts.map +1 -0
  59. package/dist/{error.d.mts → types/error.d.ts} +95 -97
  60. package/dist/types/error.d.ts.map +1 -0
  61. package/dist/types/index.d.ts +2 -0
  62. package/dist/types/index.d.ts.map +1 -0
  63. package/dist/{keys.d.mts → types/keys.d.ts} +20 -24
  64. package/dist/types/keys.d.ts.map +1 -0
  65. package/dist/types/mutex.d.ts +42 -0
  66. package/dist/types/mutex.d.ts.map +1 -0
  67. package/dist/{pkce.d.mts → types/pkce.d.ts} +10 -11
  68. package/dist/types/pkce.d.ts.map +1 -0
  69. package/dist/types/provider/apple.d.ts +197 -0
  70. package/dist/types/provider/apple.d.ts.map +1 -0
  71. package/dist/types/provider/code.d.ts +288 -0
  72. package/dist/types/provider/code.d.ts.map +1 -0
  73. package/dist/types/provider/discord.d.ts +206 -0
  74. package/dist/types/provider/discord.d.ts.map +1 -0
  75. package/dist/types/provider/facebook.d.ts +200 -0
  76. package/dist/types/provider/facebook.d.ts.map +1 -0
  77. package/dist/types/provider/github.d.ts +220 -0
  78. package/dist/types/provider/github.d.ts.map +1 -0
  79. package/dist/types/provider/gitlab.d.ts +180 -0
  80. package/dist/types/provider/gitlab.d.ts.map +1 -0
  81. package/dist/types/provider/google.d.ts +158 -0
  82. package/dist/types/provider/google.d.ts.map +1 -0
  83. package/dist/types/provider/linkedin.d.ts +190 -0
  84. package/dist/types/provider/linkedin.d.ts.map +1 -0
  85. package/dist/types/provider/magiclink.d.ts +141 -0
  86. package/dist/types/provider/magiclink.d.ts.map +1 -0
  87. package/dist/types/provider/microsoft.d.ts +247 -0
  88. package/dist/types/provider/microsoft.d.ts.map +1 -0
  89. package/dist/types/provider/oauth2.d.ts +229 -0
  90. package/dist/types/provider/oauth2.d.ts.map +1 -0
  91. package/dist/types/provider/password.d.ts +408 -0
  92. package/dist/types/provider/password.d.ts.map +1 -0
  93. package/dist/types/provider/provider.d.ts +226 -0
  94. package/dist/types/provider/provider.d.ts.map +1 -0
  95. package/dist/types/provider/reddit.d.ts +159 -0
  96. package/dist/types/provider/reddit.d.ts.map +1 -0
  97. package/dist/types/provider/slack.d.ts +171 -0
  98. package/dist/types/provider/slack.d.ts.map +1 -0
  99. package/dist/types/provider/spotify.d.ts +168 -0
  100. package/dist/types/provider/spotify.d.ts.map +1 -0
  101. package/dist/types/provider/twitch.d.ts +163 -0
  102. package/dist/types/provider/twitch.d.ts.map +1 -0
  103. package/dist/types/provider/vercel.d.ts +294 -0
  104. package/dist/types/provider/vercel.d.ts.map +1 -0
  105. package/dist/{random.d.mts → types/random.d.ts} +4 -6
  106. package/dist/types/random.d.ts.map +1 -0
  107. package/dist/types/revocation.d.ts +76 -0
  108. package/dist/types/revocation.d.ts.map +1 -0
  109. package/dist/{storage/memory.d.mts → types/storage/memory.d.ts} +17 -21
  110. package/dist/types/storage/memory.d.ts.map +1 -0
  111. package/dist/types/storage/storage.d.ts +177 -0
  112. package/dist/types/storage/storage.d.ts.map +1 -0
  113. package/dist/{storage/turso.d.mts → types/storage/turso.d.ts} +4 -8
  114. package/dist/types/storage/turso.d.ts.map +1 -0
  115. package/dist/{storage/unstorage.d.mts → types/storage/unstorage.d.ts} +12 -11
  116. package/dist/types/storage/unstorage.d.ts.map +1 -0
  117. package/dist/types/subject.d.ts +115 -0
  118. package/dist/types/subject.d.ts.map +1 -0
  119. package/dist/types/themes/theme.d.ts +207 -0
  120. package/dist/types/themes/theme.d.ts.map +1 -0
  121. package/dist/types/toolkit/client.d.ts +235 -0
  122. package/dist/types/toolkit/client.d.ts.map +1 -0
  123. package/dist/types/toolkit/index.d.ts +45 -0
  124. package/dist/types/toolkit/index.d.ts.map +1 -0
  125. package/dist/types/toolkit/providers/facebook.d.ts +8 -0
  126. package/dist/types/toolkit/providers/facebook.d.ts.map +1 -0
  127. package/dist/types/toolkit/providers/github.d.ts +8 -0
  128. package/dist/types/toolkit/providers/github.d.ts.map +1 -0
  129. package/dist/types/toolkit/providers/google.d.ts +8 -0
  130. package/dist/types/toolkit/providers/google.d.ts.map +1 -0
  131. package/dist/types/toolkit/providers/strategy.d.ts +38 -0
  132. package/dist/types/toolkit/providers/strategy.d.ts.map +1 -0
  133. package/dist/{toolkit/storage.d.mts → types/toolkit/storage.d.ts} +37 -39
  134. package/dist/types/toolkit/storage.d.ts.map +1 -0
  135. package/dist/{toolkit/utils.d.mts → types/toolkit/utils.d.ts} +2 -4
  136. package/dist/types/toolkit/utils.d.ts.map +1 -0
  137. package/dist/types/types.d.ts +92 -0
  138. package/dist/types/types.d.ts.map +1 -0
  139. package/dist/types/ui/base.d.ts +18 -0
  140. package/dist/types/ui/base.d.ts.map +1 -0
  141. package/dist/types/ui/code.d.ts +43 -0
  142. package/dist/types/ui/code.d.ts.map +1 -0
  143. package/dist/types/ui/form.d.ts +24 -0
  144. package/dist/types/ui/form.d.ts.map +1 -0
  145. package/dist/types/ui/icon.d.ts +60 -0
  146. package/dist/types/ui/icon.d.ts.map +1 -0
  147. package/dist/types/ui/magiclink.d.ts +41 -0
  148. package/dist/types/ui/magiclink.d.ts.map +1 -0
  149. package/dist/types/ui/password.d.ts +43 -0
  150. package/dist/types/ui/password.d.ts.map +1 -0
  151. package/dist/types/ui/select.d.ts +33 -0
  152. package/dist/types/ui/select.d.ts.map +1 -0
  153. package/dist/{util.d.mts → types/util.d.ts} +11 -13
  154. package/dist/types/util.d.ts.map +1 -0
  155. package/package.json +10 -16
  156. package/dist/adapters/node.d.mts +0 -18
  157. package/dist/adapters/node.mjs +0 -69
  158. package/dist/allow.mjs +0 -63
  159. package/dist/client.d.mts +0 -456
  160. package/dist/client.mjs +0 -283
  161. package/dist/core.d.mts +0 -110
  162. package/dist/core.mjs +0 -595
  163. package/dist/error.mjs +0 -237
  164. package/dist/index.d.mts +0 -2
  165. package/dist/index.mjs +0 -3
  166. package/dist/keys.mjs +0 -146
  167. package/dist/mutex.d.mts +0 -44
  168. package/dist/mutex.mjs +0 -110
  169. package/dist/pkce.mjs +0 -157
  170. package/dist/provider/apple.d.mts +0 -111
  171. package/dist/provider/apple.mjs +0 -164
  172. package/dist/provider/code.d.mts +0 -228
  173. package/dist/provider/code.mjs +0 -246
  174. package/dist/provider/discord.d.mts +0 -146
  175. package/dist/provider/discord.mjs +0 -156
  176. package/dist/provider/facebook.d.mts +0 -142
  177. package/dist/provider/facebook.mjs +0 -150
  178. package/dist/provider/github.d.mts +0 -140
  179. package/dist/provider/github.mjs +0 -169
  180. package/dist/provider/gitlab.d.mts +0 -106
  181. package/dist/provider/gitlab.mjs +0 -147
  182. package/dist/provider/google.d.mts +0 -112
  183. package/dist/provider/google.mjs +0 -109
  184. package/dist/provider/linkedin.d.mts +0 -132
  185. package/dist/provider/linkedin.mjs +0 -142
  186. package/dist/provider/magiclink.d.mts +0 -89
  187. package/dist/provider/magiclink.mjs +0 -143
  188. package/dist/provider/microsoft.d.mts +0 -178
  189. package/dist/provider/microsoft.mjs +0 -177
  190. package/dist/provider/oauth2.d.mts +0 -176
  191. package/dist/provider/oauth2.mjs +0 -222
  192. package/dist/provider/passkey.d.mts +0 -104
  193. package/dist/provider/passkey.mjs +0 -320
  194. package/dist/provider/password.d.mts +0 -412
  195. package/dist/provider/password.mjs +0 -363
  196. package/dist/provider/provider.d.mts +0 -227
  197. package/dist/provider/provider.mjs +0 -44
  198. package/dist/provider/reddit.d.mts +0 -107
  199. package/dist/provider/reddit.mjs +0 -127
  200. package/dist/provider/slack.d.mts +0 -114
  201. package/dist/provider/slack.mjs +0 -138
  202. package/dist/provider/spotify.d.mts +0 -113
  203. package/dist/provider/spotify.mjs +0 -135
  204. package/dist/provider/totp.d.mts +0 -112
  205. package/dist/provider/totp.mjs +0 -191
  206. package/dist/provider/twitch.d.mts +0 -108
  207. package/dist/provider/twitch.mjs +0 -131
  208. package/dist/provider/vercel.d.mts +0 -177
  209. package/dist/provider/vercel.mjs +0 -230
  210. package/dist/random.mjs +0 -86
  211. package/dist/revocation.d.mts +0 -55
  212. package/dist/revocation.mjs +0 -63
  213. package/dist/router/context.d.mts +0 -21
  214. package/dist/router/context.mjs +0 -193
  215. package/dist/router/cookies.d.mts +0 -8
  216. package/dist/router/cookies.mjs +0 -13
  217. package/dist/router/index.d.mts +0 -21
  218. package/dist/router/index.mjs +0 -107
  219. package/dist/router/matcher.d.mts +0 -15
  220. package/dist/router/matcher.mjs +0 -76
  221. package/dist/router/middleware/cors.d.mts +0 -15
  222. package/dist/router/middleware/cors.mjs +0 -114
  223. package/dist/router/safe-request.d.mts +0 -52
  224. package/dist/router/safe-request.mjs +0 -160
  225. package/dist/router/types.d.mts +0 -67
  226. package/dist/router/types.mjs +0 -1
  227. package/dist/router/variables.d.mts +0 -12
  228. package/dist/router/variables.mjs +0 -20
  229. package/dist/storage/memory.mjs +0 -125
  230. package/dist/storage/storage.d.mts +0 -179
  231. package/dist/storage/storage.mjs +0 -104
  232. package/dist/storage/turso.mjs +0 -117
  233. package/dist/storage/unstorage.mjs +0 -103
  234. package/dist/subject.d.mts +0 -62
  235. package/dist/subject.mjs +0 -36
  236. package/dist/themes/theme.d.mts +0 -209
  237. package/dist/themes/theme.mjs +0 -120
  238. package/dist/toolkit/client.d.mts +0 -169
  239. package/dist/toolkit/client.mjs +0 -209
  240. package/dist/toolkit/index.d.mts +0 -9
  241. package/dist/toolkit/index.mjs +0 -9
  242. package/dist/toolkit/providers/facebook.d.mts +0 -12
  243. package/dist/toolkit/providers/facebook.mjs +0 -16
  244. package/dist/toolkit/providers/github.d.mts +0 -12
  245. package/dist/toolkit/providers/github.mjs +0 -16
  246. package/dist/toolkit/providers/google.d.mts +0 -12
  247. package/dist/toolkit/providers/google.mjs +0 -20
  248. package/dist/toolkit/providers/strategy.d.mts +0 -40
  249. package/dist/toolkit/providers/strategy.mjs +0 -1
  250. package/dist/toolkit/storage.mjs +0 -157
  251. package/dist/toolkit/utils.mjs +0 -30
  252. package/dist/types.d.mts +0 -94
  253. package/dist/types.mjs +0 -1
  254. package/dist/ui/base.d.mts +0 -30
  255. package/dist/ui/base.mjs +0 -407
  256. package/dist/ui/code.d.mts +0 -43
  257. package/dist/ui/code.mjs +0 -173
  258. package/dist/ui/form.d.mts +0 -32
  259. package/dist/ui/form.mjs +0 -49
  260. package/dist/ui/icon.d.mts +0 -58
  261. package/dist/ui/icon.mjs +0 -247
  262. package/dist/ui/magiclink.d.mts +0 -41
  263. package/dist/ui/magiclink.mjs +0 -152
  264. package/dist/ui/passkey.d.mts +0 -27
  265. package/dist/ui/passkey.mjs +0 -323
  266. package/dist/ui/password.d.mts +0 -42
  267. package/dist/ui/password.mjs +0 -402
  268. package/dist/ui/select.d.mts +0 -34
  269. package/dist/ui/select.mjs +0 -98
  270. package/dist/ui/totp.d.mts +0 -34
  271. package/dist/ui/totp.mjs +0 -270
  272. package/dist/util.mjs +0 -128
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Use one of the built-in themes.
3
+ *
4
+ * @example
5
+ *
6
+ * ```ts
7
+ * import { THEME_SST } from "@draftlab/auth/themes/theme"
8
+ *
9
+ * export default issuer({
10
+ * theme: THEME_SST,
11
+ * // ...
12
+ * })
13
+ * ```
14
+ *
15
+ * Or define your own.
16
+ *
17
+ * ```ts
18
+ * import type { Theme } from "@draftlab/auth/themes/theme"
19
+ *
20
+ * const MY_THEME: Theme = {
21
+ * title: "Acne",
22
+ * radius: "none",
23
+ * favicon: "https://www.example.com/favicon.svg",
24
+ * // ...
25
+ * }
26
+ *
27
+ * export default issuer({
28
+ * theme: MY_THEME,
29
+ * // ...
30
+ * })
31
+ * ```
32
+ *
33
+ * @packageDocumentation
34
+ */
35
+ /**
36
+ * A type to define values for light and dark mode.
37
+ *
38
+ * @example
39
+ * ```ts
40
+ * {
41
+ * light: "#FFF",
42
+ * dark: "#000"
43
+ * }
44
+ * ```
45
+ */
46
+ export interface ColorScheme {
47
+ /**
48
+ * The value for dark mode.
49
+ */
50
+ dark: string;
51
+ /**
52
+ * The value for light mode.
53
+ */
54
+ light: string;
55
+ }
56
+ /**
57
+ * A type to define your custom theme.
58
+ */
59
+ export interface Theme {
60
+ /**
61
+ * The name of your app. Also used as the title of the page.
62
+ *
63
+ * @example
64
+ * ```ts
65
+ * {
66
+ * title: "Acne"
67
+ * }
68
+ * ```
69
+ */
70
+ title?: string;
71
+ /**
72
+ * A URL to the favicon of your app.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * {
77
+ * favicon: "https://www.example.com/favicon.svg"
78
+ * }
79
+ * ```
80
+ */
81
+ favicon?: string;
82
+ /**
83
+ * The border radius of the UI elements.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * {
88
+ * radius: "none"
89
+ * }
90
+ * ```
91
+ */
92
+ radius?: "none" | "sm" | "md" | "lg" | "full";
93
+ /**
94
+ * The primary color of the theme.
95
+ *
96
+ * Takes a color or both light and dark colors.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * {
101
+ * primary: "#FF5E00"
102
+ * }
103
+ * ```
104
+ */
105
+ primary: string | ColorScheme;
106
+ /**
107
+ * The background color of the theme.
108
+ *
109
+ * Takes a color or both light and dark colors.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * {
114
+ * background: "#FFF"
115
+ * }
116
+ * ```
117
+ */
118
+ background?: string | ColorScheme;
119
+ /**
120
+ * A URL to the logo of your app.
121
+ *
122
+ * Takes a single image or both light and dark mode versions.
123
+ *
124
+ * @example
125
+ * ```ts
126
+ * {
127
+ * logo: "https://www.example.com/logo.svg"
128
+ * }
129
+ * ```
130
+ */
131
+ logo?: string | ColorScheme;
132
+ /**
133
+ * The font family and scale of the theme.
134
+ */
135
+ font?: {
136
+ /**
137
+ * The font family of the theme.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * {
142
+ * font: {
143
+ * family: "Geist Mono, monospace"
144
+ * }
145
+ * }
146
+ * ```
147
+ */
148
+ family?: string;
149
+ /**
150
+ * The font scale of the theme. Can be used to increase or decrease the font sizes across
151
+ * the UI.
152
+ *
153
+ * @default "1"
154
+ * @example
155
+ * ```ts
156
+ * {
157
+ * font: {
158
+ * scale: "1.25"
159
+ * }
160
+ * }
161
+ * ```
162
+ */
163
+ scale?: string;
164
+ };
165
+ /**
166
+ * Custom CSS that's added to the page in a `<style>` tag.
167
+ *
168
+ * This can be used to import custom fonts.
169
+ *
170
+ * @example
171
+ * ```ts
172
+ * {
173
+ * css: `@import url('https://fonts.googleapis.com/css2?family=Rubik:wght@100;200;300;400;500;600;700;800;900&display=swap');`
174
+ * }
175
+ * ```
176
+ */
177
+ css?: string;
178
+ }
179
+ /**
180
+ * Built-in default Draft Auth theme.
181
+ */
182
+ export declare const THEME_DRAFTAUTH: Theme;
183
+ /**
184
+ * Built-in theme based on [Terminal](https://terminal.shop).
185
+ */
186
+ export declare const THEME_TERMINAL: Theme;
187
+ /**
188
+ * Built-in theme based on [SST](https://sst.dev).
189
+ */
190
+ export declare const THEME_SST: Theme;
191
+ /**
192
+ * Built-in theme based on [Supabase](https://supabase.com).
193
+ */
194
+ export declare const THEME_SUPABASE: Theme;
195
+ /**
196
+ * Built-in theme based on [Vercel](https://vercel.com).
197
+ */
198
+ export declare const THEME_VERCEL: Theme;
199
+ /**
200
+ * @internal
201
+ */
202
+ export declare const setTheme: (value: Theme) => void;
203
+ /**
204
+ * @internal
205
+ */
206
+ export declare const getTheme: () => any;
207
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/themes/theme.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH;;;;;;;;;;GAUG;AACH,MAAM,WAAW,WAAW;IAC3B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,KAAK,EAAE,MAAM,CAAA;CACb;AAED;;GAEG;AACH,MAAM,WAAW,KAAK;IACrB;;;;;;;;;OASG;IACH,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;;;;;;;OASG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB;;;;;;;;;OASG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,GAAG,MAAM,CAAA;IAC7C;;;;;;;;;;;OAWG;IACH,OAAO,EAAE,MAAM,GAAG,WAAW,CAAA;IAC7B;;;;;;;;;;;OAWG;IACH,UAAU,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;IACjC;;;;;;;;;;;OAWG;IACH,IAAI,CAAC,EAAE,MAAM,GAAG,WAAW,CAAA;IAC3B;;OAEG;IACH,IAAI,CAAC,EAAE;QACN;;;;;;;;;;;WAWG;QACH,MAAM,CAAC,EAAE,MAAM,CAAA;QACf;;;;;;;;;;;;;WAaG;QACH,KAAK,CAAC,EAAE,MAAM,CAAA;KACd,CAAA;IACD;;;;;;;;;;;OAWG;IACH,GAAG,CAAC,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,KAiB7B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,KAmB5B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,SAAS,EAAE,KAkBvB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,EAAE,KAqB5B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,KAoB1B,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,OAAO,KAAK,SAGpC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,WAGpB,CAAA"}
@@ -0,0 +1,235 @@
1
+ /**
2
+ * Lightweight OAuth 2.0 client toolkit for DraftAuth.
3
+ *
4
+ * Provides a simple, framework-agnostic way to implement OAuth 2.0 authentication
5
+ * with PKCE support. Works in both client-side (SPA) and server-side (Next.js, Remix) environments.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * // Client-side SPA (React, Vue, Solid, etc.)
10
+ * import { createOAuthClient } from '@draftlab/auth/toolkit/client'
11
+ * import { GitHubStrategy, GoogleStrategy } from '@draftlab/auth/toolkit/providers'
12
+ * import { createSessionStorage } from '@draftlab/auth/toolkit/storage'
13
+ *
14
+ * const client = createOAuthClient({
15
+ * providers: {
16
+ * github: {
17
+ * strategy: GitHubStrategy,
18
+ * clientId: 'YOUR_CLIENT_ID',
19
+ * clientSecret: 'YOUR_CLIENT_SECRET',
20
+ * redirectUri: 'http://localhost:3000/auth/callback'
21
+ * },
22
+ * google: {
23
+ * strategy: GoogleStrategy,
24
+ * clientId: 'YOUR_CLIENT_ID',
25
+ * clientSecret: 'YOUR_CLIENT_SECRET',
26
+ * redirectUri: 'http://localhost:3000/auth/callback'
27
+ * }
28
+ * },
29
+ * storage: createSessionStorage()
30
+ * })
31
+ *
32
+ * // Initiate login
33
+ * const { url } = await client.authorize('github', { scopes: ['user:email'] })
34
+ * window.location.href = url
35
+ *
36
+ * // Handle callback
37
+ * const result = await client.handleCallback(window.location.href)
38
+ * console.log(result.accessToken, result.provider)
39
+ * ```
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * // Server-side (Next.js App Router)
44
+ * import { createOAuthClient } from '@draftlab/auth/toolkit/client'
45
+ * import { GitHubStrategy } from '@draftlab/auth/toolkit/providers'
46
+ * import { createCookieStorage } from '@draftlab/auth/toolkit/storage'
47
+ * import { cookies } from 'next/headers'
48
+ *
49
+ * export async function GET(req: Request) {
50
+ * const client = createOAuthClient({
51
+ * providers: {
52
+ * github: {
53
+ * strategy: GitHubStrategy,
54
+ * clientId: process.env.GITHUB_CLIENT_ID!,
55
+ * clientSecret: process.env.GITHUB_CLIENT_SECRET!,
56
+ * redirectUri: 'https://myapp.com/auth/callback'
57
+ * }
58
+ * },
59
+ * storage: createCookieStorage({
60
+ * getCookie: (name) => cookies().get(name)?.value ?? null,
61
+ * setCookie: (name, value, opts) => cookies().set(name, value, opts),
62
+ * deleteCookie: (name) => cookies().delete(name)
63
+ * })
64
+ * })
65
+ *
66
+ * const { url } = await client.authorize('github')
67
+ * return Response.redirect(url)
68
+ * }
69
+ * ```
70
+ */
71
+ import type { OAuthStrategy } from "./providers/strategy";
72
+ import { type AuthStorage } from "./storage";
73
+ /**
74
+ * Configuration for a single OAuth provider.
75
+ */
76
+ export interface ProviderConfig<TStrategy extends OAuthStrategy> {
77
+ /** OAuth strategy defining endpoints and defaults */
78
+ readonly strategy: TStrategy;
79
+ /** OAuth client ID from provider */
80
+ readonly clientId: string;
81
+ /** OAuth client secret from provider */
82
+ readonly clientSecret: string;
83
+ /** Redirect URI registered with provider */
84
+ readonly redirectUri: string;
85
+ /** Optional default scopes for this provider */
86
+ readonly scopes?: string[];
87
+ }
88
+ /**
89
+ * Options for initiating OAuth authorization flow.
90
+ */
91
+ export interface AuthorizeOptions {
92
+ /** Optional scopes to request (overrides provider defaults) */
93
+ readonly scopes?: string[];
94
+ /** Optional additional parameters to include in authorization URL */
95
+ readonly params?: Record<string, string>;
96
+ /** Optional nonce for additional security */
97
+ readonly nonce?: string;
98
+ }
99
+ /**
100
+ * Result of successful OAuth callback handling.
101
+ */
102
+ export interface CallbackResult {
103
+ /** OAuth provider that was used */
104
+ readonly provider: string;
105
+ /** Access token from provider */
106
+ readonly accessToken: string;
107
+ /** Optional refresh token from provider */
108
+ readonly refreshToken?: string;
109
+ /** Token expiration time in seconds */
110
+ readonly expiresIn?: number;
111
+ /** Token type (usually "Bearer") */
112
+ readonly tokenType?: string;
113
+ /** Optional ID token (OpenID Connect) */
114
+ readonly idToken?: string;
115
+ }
116
+ /**
117
+ * OAuth 2.0 client configuration.
118
+ */
119
+ export interface OAuthClientConfig<TProviders extends Record<string, ProviderConfig<OAuthStrategy>>> {
120
+ /** Provider configurations keyed by provider name */
121
+ readonly providers: TProviders;
122
+ /** Storage adapter for PKCE state (defaults to sessionStorage in browser) */
123
+ readonly storage?: AuthStorage;
124
+ }
125
+ /**
126
+ * OAuth 2.0 client for managing authentication flows.
127
+ */
128
+ export interface OAuthClient<TProviders extends Record<string, ProviderConfig<OAuthStrategy>>> {
129
+ /**
130
+ * Initiate OAuth authorization flow.
131
+ *
132
+ * @param provider - Provider name (key from providers config)
133
+ * @param options - Authorization options
134
+ * @returns Authorization URL to redirect user to
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * // Basic usage
139
+ * const { url } = await client.authorize('github')
140
+ * window.location.href = url
141
+ *
142
+ * // With custom scopes
143
+ * const { url } = await client.authorize('google', {
144
+ * scopes: ['openid', 'email', 'profile']
145
+ * })
146
+ *
147
+ * // With additional params
148
+ * const { url } = await client.authorize('github', {
149
+ * params: { prompt: 'consent' }
150
+ * })
151
+ * ```
152
+ */
153
+ authorize(provider: (string & {}) | keyof TProviders, options?: AuthorizeOptions): Promise<{
154
+ url: string;
155
+ state: string;
156
+ }>;
157
+ /**
158
+ * Handle OAuth callback and exchange code for tokens.
159
+ *
160
+ * @param callbackUrl - Full callback URL with query parameters
161
+ * @returns Token exchange result
162
+ *
163
+ * @throws {Error} If callback URL is invalid, state mismatch, or token exchange fails
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * // Client-side
168
+ * const result = await client.handleCallback(window.location.href)
169
+ * console.log(result.accessToken, result.provider)
170
+ *
171
+ * // Server-side (Next.js)
172
+ * export async function GET(req: Request) {
173
+ * const result = await client.handleCallback(req.url)
174
+ * // Store tokens, create session, etc.
175
+ * return Response.redirect('/')
176
+ * }
177
+ * ```
178
+ */
179
+ handleCallback(callbackUrl: string): Promise<CallbackResult>;
180
+ /**
181
+ * Get user info from OAuth provider using access token.
182
+ *
183
+ * @param provider - Provider name
184
+ * @param accessToken - Access token from provider
185
+ * @returns User info from provider
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * const userInfo = await client.getUserInfo('github', accessToken)
190
+ * console.log(userInfo.email, userInfo.name)
191
+ * ```
192
+ */
193
+ getUserInfo(provider: (string & {}) | keyof TProviders, accessToken: string): Promise<Record<string, unknown>>;
194
+ }
195
+ /**
196
+ * Creates an OAuth 2.0 client for managing authentication flows.
197
+ *
198
+ * Supports PKCE (Proof Key for Code Exchange) for enhanced security.
199
+ * Works in both client-side (browser) and server-side (Node.js) environments.
200
+ *
201
+ * @param config - OAuth client configuration
202
+ * @returns OAuth client instance
203
+ *
204
+ * @example
205
+ * ```ts
206
+ * import { createOAuthClient } from '@draftlab/auth/toolkit/client'
207
+ * import { GitHubStrategy, GoogleStrategy } from '@draftlab/auth/toolkit/providers'
208
+ *
209
+ * const client = createOAuthClient({
210
+ * providers: {
211
+ * github: {
212
+ * strategy: GitHubStrategy,
213
+ * clientId: 'YOUR_CLIENT_ID',
214
+ * clientSecret: 'YOUR_CLIENT_SECRET',
215
+ * redirectUri: 'http://localhost:3000/auth/callback'
216
+ * },
217
+ * google: {
218
+ * strategy: GoogleStrategy,
219
+ * clientId: 'YOUR_CLIENT_ID',
220
+ * clientSecret: 'YOUR_CLIENT_SECRET',
221
+ * redirectUri: 'http://localhost:3000/auth/callback',
222
+ * scopes: ['openid', 'email', 'profile']
223
+ * }
224
+ * }
225
+ * })
226
+ *
227
+ * // Initiate login
228
+ * const { url } = await client.authorize('github')
229
+ *
230
+ * // Handle callback
231
+ * const result = await client.handleCallback(callbackUrl)
232
+ * ```
233
+ */
234
+ export declare const createOAuthClient: <TProviders extends Record<string, ProviderConfig<OAuthStrategy>>>(config: OAuthClientConfig<TProviders>) => OAuthClient<TProviders>;
235
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/toolkit/client.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * DraftAuth Toolkit - Lightweight OAuth 2.0 Client
3
+ *
4
+ * A simple, framework-agnostic OAuth 2.0 client with PKCE support.
5
+ * Works in both client-side (browser) and server-side (Node.js) environments.
6
+ *
7
+ * @packageDocumentation
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * // Quick Start - Client-side SPA
12
+ * import { createOAuthClient, GitHubStrategy, createSessionStorage } from '@draftlab/auth/toolkit'
13
+ *
14
+ * const client = createOAuthClient({
15
+ * providers: {
16
+ * github: {
17
+ * strategy: GitHubStrategy,
18
+ * clientId: 'YOUR_CLIENT_ID',
19
+ * clientSecret: 'YOUR_CLIENT_SECRET',
20
+ * redirectUri: 'http://localhost:3000/auth/callback'
21
+ * }
22
+ * },
23
+ * storage: createSessionStorage()
24
+ * })
25
+ *
26
+ * // Login
27
+ * const { url } = await client.authorize('github')
28
+ * window.location.href = url
29
+ *
30
+ * // Callback
31
+ * const result = await client.handleCallback(window.location.href)
32
+ * console.log(result.accessToken)
33
+ * ```
34
+ */
35
+ export { generatePKCE } from "../pkce";
36
+ export type { AuthorizeOptions, CallbackResult, OAuthClient, OAuthClientConfig, ProviderConfig } from "./client";
37
+ export { createOAuthClient } from "./client";
38
+ export { FacebookStrategy } from "./providers/facebook";
39
+ export { GitHubStrategy } from "./providers/github";
40
+ export { GoogleStrategy } from "./providers/google";
41
+ export type { OAuth2TokenResponse, OAuthStrategy } from "./providers/strategy";
42
+ export type { AuthStorage, PKCEState } from "./storage";
43
+ export { createCookieStorage, createLocalStorage, createMemoryStorage, createSessionStorage } from "./storage";
44
+ export { generateSecureRandom } from "./utils";
45
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/toolkit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AACtC,YAAY,EACX,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,iBAAiB,EACjB,cAAc,EACd,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAE5C,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AACnD,YAAY,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AAC9E,YAAY,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAEvD,OAAO,EACN,mBAAmB,EACnB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,MAAM,WAAW,CAAA;AAElB,OAAO,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { OAuthStrategy } from "./strategy";
2
+ /**
3
+ * Facebook OAuth 2.0 strategy.
4
+ *
5
+ * @see https://developers.facebook.com/docs/facebook-login/guides/advanced/manual-flow
6
+ */
7
+ export declare const FacebookStrategy: OAuthStrategy;
8
+ //# sourceMappingURL=facebook.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facebook.d.ts","sourceRoot":"","sources":["../../../../src/toolkit/providers/facebook.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,EAAE,aAM9B,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { OAuthStrategy } from "./strategy";
2
+ /**
3
+ * GitHub OAuth 2.0 strategy.
4
+ *
5
+ * @see https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authorizing-oauth-apps
6
+ */
7
+ export declare const GitHubStrategy: OAuthStrategy;
8
+ //# sourceMappingURL=github.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"github.d.ts","sourceRoot":"","sources":["../../../../src/toolkit/providers/github.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,aAM5B,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { OAuthStrategy } from "./strategy";
2
+ /**
3
+ * Google OAuth 2.0 / OpenID Connect strategy.
4
+ *
5
+ * @see https://developers.google.com/identity/protocols/oauth2
6
+ */
7
+ export declare const GoogleStrategy: OAuthStrategy;
8
+ //# sourceMappingURL=google.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../../src/toolkit/providers/google.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C;;;;GAIG;AACH,eAAO,MAAM,cAAc,EAAE,aAM5B,CAAA"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * OAuth 2.0 strategy interface and types for provider configurations.
3
+ */
4
+ /**
5
+ * OAuth 2.0 token response from provider's token endpoint.
6
+ * Based on RFC 6749 Section 5.1.
7
+ */
8
+ export interface OAuth2TokenResponse {
9
+ /** The access token issued by the authorization server */
10
+ access_token: string;
11
+ /** The type of token (usually "Bearer") */
12
+ token_type?: string;
13
+ /** The lifetime in seconds of the access token */
14
+ expires_in?: number;
15
+ /** The refresh token for obtaining new access tokens */
16
+ refresh_token?: string;
17
+ /** The scope of the access token (space-separated list) */
18
+ scope?: string;
19
+ /** OpenID Connect ID token (JWT) */
20
+ id_token?: string;
21
+ }
22
+ /**
23
+ * OAuth 2.0 provider strategy definition.
24
+ * Defines the endpoints and default configuration for an OAuth provider.
25
+ */
26
+ export interface OAuthStrategy {
27
+ /** Provider name (e.g., "github", "google") */
28
+ readonly name: string;
29
+ /** OAuth authorization endpoint URL */
30
+ readonly authorizationEndpoint: string;
31
+ /** OAuth token exchange endpoint URL */
32
+ readonly tokenEndpoint: string;
33
+ /** Optional user info endpoint URL (for OpenID Connect) */
34
+ readonly userInfoEndpoint?: string;
35
+ /** Default scopes to request */
36
+ readonly scopes: string[];
37
+ }
38
+ //# sourceMappingURL=strategy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategy.d.ts","sourceRoot":"","sources":["../../../../src/toolkit/providers/strategy.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,0DAA0D;IAC1D,YAAY,EAAE,MAAM,CAAA;IACpB,2CAA2C;IAC3C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,wDAAwD;IACxD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,2DAA2D;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAA;CACjB;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,+CAA+C;IAC/C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,uCAAuC;IACvC,QAAQ,CAAC,qBAAqB,EAAE,MAAM,CAAA;IACtC,wCAAwC;IACxC,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAA;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAA;IAClC,gCAAgC;IAChC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CACzB"}