@softure-ai/auth 0.0.0-stage → 0.1.5

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 (239) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +381 -2
  3. package/dist/contract.d.ts +44 -0
  4. package/dist/contract.d.ts.map +1 -0
  5. package/dist/contract.js +2 -0
  6. package/dist/contract.js.map +1 -0
  7. package/dist/index.d.ts +188 -0
  8. package/dist/index.d.ts.map +1 -0
  9. package/dist/index.js +84 -0
  10. package/dist/index.js.map +1 -0
  11. package/dist/mailing/index.d.ts +2 -0
  12. package/dist/mailing/index.d.ts.map +1 -0
  13. package/dist/mailing/index.js +4 -0
  14. package/dist/mailing/index.js.map +1 -0
  15. package/dist/mailing/reset-mail.d.ts +27 -0
  16. package/dist/mailing/reset-mail.d.ts.map +1 -0
  17. package/dist/mailing/reset-mail.js +55 -0
  18. package/dist/mailing/reset-mail.js.map +1 -0
  19. package/dist/messages/en.d.ts +97 -0
  20. package/dist/messages/en.d.ts.map +1 -0
  21. package/dist/messages/en.js +92 -0
  22. package/dist/messages/en.js.map +1 -0
  23. package/dist/messages/index.d.ts +199 -0
  24. package/dist/messages/index.d.ts.map +1 -0
  25. package/dist/messages/index.js +11 -0
  26. package/dist/messages/index.js.map +1 -0
  27. package/dist/messages/pl.d.ts +3 -0
  28. package/dist/messages/pl.d.ts.map +1 -0
  29. package/dist/messages/pl.js +91 -0
  30. package/dist/messages/pl.js.map +1 -0
  31. package/dist/next/actions.d.ts +19 -0
  32. package/dist/next/actions.d.ts.map +1 -0
  33. package/dist/next/actions.js +210 -0
  34. package/dist/next/actions.js.map +1 -0
  35. package/dist/next/context.d.ts +4 -0
  36. package/dist/next/context.d.ts.map +1 -0
  37. package/dist/next/context.js +13 -0
  38. package/dist/next/context.js.map +1 -0
  39. package/dist/next/current-user.d.ts +34 -0
  40. package/dist/next/current-user.d.ts.map +1 -0
  41. package/dist/next/current-user.js +77 -0
  42. package/dist/next/current-user.js.map +1 -0
  43. package/dist/next/index.d.ts +8 -0
  44. package/dist/next/index.d.ts.map +1 -0
  45. package/dist/next/index.js +9 -0
  46. package/dist/next/index.js.map +1 -0
  47. package/dist/next/logout-button.d.ts +7 -0
  48. package/dist/next/logout-button.d.ts.map +1 -0
  49. package/dist/next/logout-button.js +12 -0
  50. package/dist/next/logout-button.js.map +1 -0
  51. package/dist/next/messages.d.ts +5 -0
  52. package/dist/next/messages.d.ts.map +1 -0
  53. package/dist/next/messages.js +7 -0
  54. package/dist/next/messages.js.map +1 -0
  55. package/dist/next/pages.d.ts +18 -0
  56. package/dist/next/pages.d.ts.map +1 -0
  57. package/dist/next/pages.js +92 -0
  58. package/dist/next/pages.js.map +1 -0
  59. package/dist/next/params.d.ts +3 -0
  60. package/dist/next/params.d.ts.map +1 -0
  61. package/dist/next/params.js +4 -0
  62. package/dist/next/params.js.map +1 -0
  63. package/dist/next/route.d.ts +3 -0
  64. package/dist/next/route.d.ts.map +1 -0
  65. package/dist/next/route.js +17 -0
  66. package/dist/next/route.js.map +1 -0
  67. package/dist/next/search-params.d.ts +5 -0
  68. package/dist/next/search-params.d.ts.map +1 -0
  69. package/dist/next/search-params.js +13 -0
  70. package/dist/next/search-params.js.map +1 -0
  71. package/dist/next/session-cookie.d.ts +8 -0
  72. package/dist/next/session-cookie.d.ts.map +1 -0
  73. package/dist/next/session-cookie.js +34 -0
  74. package/dist/next/session-cookie.js.map +1 -0
  75. package/dist/options.d.ts +63 -0
  76. package/dist/options.d.ts.map +1 -0
  77. package/dist/options.js +74 -0
  78. package/dist/options.js.map +1 -0
  79. package/dist/password-reset-sender.d.ts +21 -0
  80. package/dist/password-reset-sender.d.ts.map +1 -0
  81. package/dist/password-reset-sender.js +12 -0
  82. package/dist/password-reset-sender.js.map +1 -0
  83. package/dist/proxy/index.d.ts +9 -0
  84. package/dist/proxy/index.d.ts.map +1 -0
  85. package/dist/proxy/index.js +41 -0
  86. package/dist/proxy/index.js.map +1 -0
  87. package/dist/redirect-target.d.ts +7 -0
  88. package/dist/redirect-target.d.ts.map +1 -0
  89. package/dist/redirect-target.js +25 -0
  90. package/dist/redirect-target.js.map +1 -0
  91. package/dist/roles.d.ts +5 -0
  92. package/dist/roles.d.ts.map +1 -0
  93. package/dist/roles.js +6 -0
  94. package/dist/roles.js.map +1 -0
  95. package/dist/safe-next-path.d.ts +3 -0
  96. package/dist/safe-next-path.d.ts.map +1 -0
  97. package/dist/safe-next-path.js +19 -0
  98. package/dist/safe-next-path.js.map +1 -0
  99. package/dist/schema.d.ts +302 -0
  100. package/dist/schema.d.ts.map +1 -0
  101. package/dist/schema.js +37 -0
  102. package/dist/schema.js.map +1 -0
  103. package/dist/scripts/index.d.ts +2 -0
  104. package/dist/scripts/index.d.ts.map +1 -0
  105. package/dist/scripts/index.js +3 -0
  106. package/dist/scripts/index.js.map +1 -0
  107. package/dist/scripts/role-scripts.d.ts +15 -0
  108. package/dist/scripts/role-scripts.d.ts.map +1 -0
  109. package/dist/scripts/role-scripts.js +76 -0
  110. package/dist/scripts/role-scripts.js.map +1 -0
  111. package/dist/server/change-password.d.ts +14 -0
  112. package/dist/server/change-password.d.ts.map +1 -0
  113. package/dist/server/change-password.js +47 -0
  114. package/dist/server/change-password.js.map +1 -0
  115. package/dist/server/health.d.ts +3 -0
  116. package/dist/server/health.d.ts.map +1 -0
  117. package/dist/server/health.js +15 -0
  118. package/dist/server/health.js.map +1 -0
  119. package/dist/server/index.d.ts +12 -0
  120. package/dist/server/index.d.ts.map +1 -0
  121. package/dist/server/index.js +14 -0
  122. package/dist/server/index.js.map +1 -0
  123. package/dist/server/login.d.ts +14 -0
  124. package/dist/server/login.d.ts.map +1 -0
  125. package/dist/server/login.js +49 -0
  126. package/dist/server/login.js.map +1 -0
  127. package/dist/server/options.d.ts +17 -0
  128. package/dist/server/options.d.ts.map +1 -0
  129. package/dist/server/options.js +36 -0
  130. package/dist/server/options.js.map +1 -0
  131. package/dist/server/password-reset.d.ts +54 -0
  132. package/dist/server/password-reset.d.ts.map +1 -0
  133. package/dist/server/password-reset.js +134 -0
  134. package/dist/server/password-reset.js.map +1 -0
  135. package/dist/server/password.d.ts +18 -0
  136. package/dist/server/password.d.ts.map +1 -0
  137. package/dist/server/password.js +77 -0
  138. package/dist/server/password.js.map +1 -0
  139. package/dist/server/privacy.d.ts +33 -0
  140. package/dist/server/privacy.d.ts.map +1 -0
  141. package/dist/server/privacy.js +52 -0
  142. package/dist/server/privacy.js.map +1 -0
  143. package/dist/server/rate-limits.d.ts +21 -0
  144. package/dist/server/rate-limits.d.ts.map +1 -0
  145. package/dist/server/rate-limits.js +39 -0
  146. package/dist/server/rate-limits.js.map +1 -0
  147. package/dist/server/reauthenticate.d.ts +7 -0
  148. package/dist/server/reauthenticate.d.ts.map +1 -0
  149. package/dist/server/reauthenticate.js +16 -0
  150. package/dist/server/reauthenticate.js.map +1 -0
  151. package/dist/server/register.d.ts +21 -0
  152. package/dist/server/register.d.ts.map +1 -0
  153. package/dist/server/register.js +52 -0
  154. package/dist/server/register.js.map +1 -0
  155. package/dist/server/roles.d.ts +25 -0
  156. package/dist/server/roles.d.ts.map +1 -0
  157. package/dist/server/roles.js +56 -0
  158. package/dist/server/roles.js.map +1 -0
  159. package/dist/server/session-token.d.ts +8 -0
  160. package/dist/server/session-token.d.ts.map +1 -0
  161. package/dist/server/session-token.js +18 -0
  162. package/dist/server/session-token.js.map +1 -0
  163. package/dist/server/sessions.d.ts +15 -0
  164. package/dist/server/sessions.d.ts.map +1 -0
  165. package/dist/server/sessions.js +41 -0
  166. package/dist/server/sessions.js.map +1 -0
  167. package/dist/server/switches.d.ts +9 -0
  168. package/dist/server/switches.d.ts.map +1 -0
  169. package/dist/server/switches.js +34 -0
  170. package/dist/server/switches.js.map +1 -0
  171. package/dist/server/validation.d.ts +10 -0
  172. package/dist/server/validation.d.ts.map +1 -0
  173. package/dist/server/validation.js +32 -0
  174. package/dist/server/validation.js.map +1 -0
  175. package/dist/session-cookie.d.ts +14 -0
  176. package/dist/session-cookie.d.ts.map +1 -0
  177. package/dist/session-cookie.js +31 -0
  178. package/dist/session-cookie.js.map +1 -0
  179. package/dist/ui/auth-forms.d.ts +57 -0
  180. package/dist/ui/auth-forms.d.ts.map +1 -0
  181. package/dist/ui/auth-forms.js +65 -0
  182. package/dist/ui/auth-forms.js.map +1 -0
  183. package/dist/ui/index.d.ts +2 -0
  184. package/dist/ui/index.d.ts.map +1 -0
  185. package/dist/ui/index.js +4 -0
  186. package/dist/ui/index.js.map +1 -0
  187. package/migrations/0001_create_users_and_sessions.sql +25 -0
  188. package/migrations/0002_create_user_roles.sql +10 -0
  189. package/migrations/0003_create_password_resets.sql +15 -0
  190. package/migrations/0004_index_users_created_at.sql +5 -0
  191. package/module.json +34 -0
  192. package/package.json +85 -4
  193. package/src/contract.ts +64 -0
  194. package/src/index.ts +100 -0
  195. package/src/mailing/index.ts +3 -0
  196. package/src/mailing/reset-mail.ts +73 -0
  197. package/src/messages/en.ts +91 -0
  198. package/src/messages/index.ts +15 -0
  199. package/src/messages/pl.ts +92 -0
  200. package/src/next/actions.ts +216 -0
  201. package/src/next/context.ts +14 -0
  202. package/src/next/current-user.ts +90 -0
  203. package/src/next/index.ts +24 -0
  204. package/src/next/logout-button.tsx +22 -0
  205. package/src/next/messages.ts +9 -0
  206. package/src/next/next-modules.d.ts +16 -0
  207. package/src/next/pages.tsx +179 -0
  208. package/src/next/params.ts +4 -0
  209. package/src/next/route.ts +17 -0
  210. package/src/next/search-params.ts +14 -0
  211. package/src/next/session-cookie.ts +39 -0
  212. package/src/options.ts +108 -0
  213. package/src/password-reset-sender.ts +33 -0
  214. package/src/proxy/index.ts +58 -0
  215. package/src/redirect-target.ts +24 -0
  216. package/src/roles.ts +7 -0
  217. package/src/safe-next-path.ts +15 -0
  218. package/src/schema.ts +45 -0
  219. package/src/scripts/index.ts +2 -0
  220. package/src/scripts/role-scripts.ts +98 -0
  221. package/src/server/change-password.ts +61 -0
  222. package/src/server/health.ts +16 -0
  223. package/src/server/index.ts +38 -0
  224. package/src/server/login.ts +61 -0
  225. package/src/server/options.ts +49 -0
  226. package/src/server/password-reset.ts +164 -0
  227. package/src/server/password.ts +90 -0
  228. package/src/server/privacy.ts +70 -0
  229. package/src/server/rate-limits.ts +44 -0
  230. package/src/server/reauthenticate.ts +16 -0
  231. package/src/server/register.ts +72 -0
  232. package/src/server/roles.ts +72 -0
  233. package/src/server/session-token.ts +21 -0
  234. package/src/server/sessions.ts +50 -0
  235. package/src/server/switches.ts +31 -0
  236. package/src/server/validation.ts +37 -0
  237. package/src/session-cookie.ts +47 -0
  238. package/src/ui/auth-forms.tsx +364 -0
  239. package/src/ui/index.ts +16 -0
@@ -0,0 +1,302 @@
1
+ export declare const authSchema: import("drizzle-orm/pg-core").PgSchema<"auth">;
2
+ export declare const users: import("drizzle-orm/pg-core").PgTableWithColumns<{
3
+ name: "users";
4
+ schema: "auth";
5
+ columns: {
6
+ id: import("drizzle-orm/pg-core").PgColumn<{
7
+ name: "id";
8
+ tableName: "users";
9
+ dataType: "string";
10
+ columnType: "PgUUID";
11
+ data: string;
12
+ driverParam: string;
13
+ notNull: true;
14
+ hasDefault: true;
15
+ isPrimaryKey: true;
16
+ isAutoincrement: false;
17
+ hasRuntimeDefault: false;
18
+ enumValues: undefined;
19
+ baseColumn: never;
20
+ identity: undefined;
21
+ generated: undefined;
22
+ }, {}, {}>;
23
+ email: import("drizzle-orm/pg-core").PgColumn<{
24
+ name: "email";
25
+ tableName: "users";
26
+ dataType: "string";
27
+ columnType: "PgText";
28
+ data: string;
29
+ driverParam: string;
30
+ notNull: true;
31
+ hasDefault: false;
32
+ isPrimaryKey: false;
33
+ isAutoincrement: false;
34
+ hasRuntimeDefault: false;
35
+ enumValues: [string, ...string[]];
36
+ baseColumn: never;
37
+ identity: undefined;
38
+ generated: undefined;
39
+ }, {}, {}>;
40
+ passwordHash: import("drizzle-orm/pg-core").PgColumn<{
41
+ name: "password_hash";
42
+ tableName: "users";
43
+ dataType: "string";
44
+ columnType: "PgText";
45
+ data: string;
46
+ driverParam: string;
47
+ notNull: true;
48
+ hasDefault: false;
49
+ isPrimaryKey: false;
50
+ isAutoincrement: false;
51
+ hasRuntimeDefault: false;
52
+ enumValues: [string, ...string[]];
53
+ baseColumn: never;
54
+ identity: undefined;
55
+ generated: undefined;
56
+ }, {}, {}>;
57
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
58
+ name: "created_at";
59
+ tableName: "users";
60
+ dataType: "date";
61
+ columnType: "PgTimestamp";
62
+ data: Date;
63
+ driverParam: string;
64
+ notNull: true;
65
+ hasDefault: false;
66
+ isPrimaryKey: false;
67
+ isAutoincrement: false;
68
+ hasRuntimeDefault: false;
69
+ enumValues: undefined;
70
+ baseColumn: never;
71
+ identity: undefined;
72
+ generated: undefined;
73
+ }, {}, {}>;
74
+ passwordChangedAt: import("drizzle-orm/pg-core").PgColumn<{
75
+ name: "password_changed_at";
76
+ tableName: "users";
77
+ dataType: "date";
78
+ columnType: "PgTimestamp";
79
+ data: Date;
80
+ driverParam: string;
81
+ notNull: true;
82
+ hasDefault: false;
83
+ isPrimaryKey: false;
84
+ isAutoincrement: false;
85
+ hasRuntimeDefault: false;
86
+ enumValues: undefined;
87
+ baseColumn: never;
88
+ identity: undefined;
89
+ generated: undefined;
90
+ }, {}, {}>;
91
+ };
92
+ dialect: "pg";
93
+ }>;
94
+ export declare const sessions: import("drizzle-orm/pg-core").PgTableWithColumns<{
95
+ name: "sessions";
96
+ schema: "auth";
97
+ columns: {
98
+ tokenHash: import("drizzle-orm/pg-core").PgColumn<{
99
+ name: "token_hash";
100
+ tableName: "sessions";
101
+ dataType: "string";
102
+ columnType: "PgText";
103
+ data: string;
104
+ driverParam: string;
105
+ notNull: true;
106
+ hasDefault: false;
107
+ isPrimaryKey: true;
108
+ isAutoincrement: false;
109
+ hasRuntimeDefault: false;
110
+ enumValues: [string, ...string[]];
111
+ baseColumn: never;
112
+ identity: undefined;
113
+ generated: undefined;
114
+ }, {}, {}>;
115
+ userId: import("drizzle-orm/pg-core").PgColumn<{
116
+ name: "user_id";
117
+ tableName: "sessions";
118
+ dataType: "string";
119
+ columnType: "PgUUID";
120
+ data: string;
121
+ driverParam: string;
122
+ notNull: true;
123
+ hasDefault: false;
124
+ isPrimaryKey: false;
125
+ isAutoincrement: false;
126
+ hasRuntimeDefault: false;
127
+ enumValues: undefined;
128
+ baseColumn: never;
129
+ identity: undefined;
130
+ generated: undefined;
131
+ }, {}, {}>;
132
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
133
+ name: "created_at";
134
+ tableName: "sessions";
135
+ dataType: "date";
136
+ columnType: "PgTimestamp";
137
+ data: Date;
138
+ driverParam: string;
139
+ notNull: true;
140
+ hasDefault: false;
141
+ isPrimaryKey: false;
142
+ isAutoincrement: false;
143
+ hasRuntimeDefault: false;
144
+ enumValues: undefined;
145
+ baseColumn: never;
146
+ identity: undefined;
147
+ generated: undefined;
148
+ }, {}, {}>;
149
+ expiresAt: import("drizzle-orm/pg-core").PgColumn<{
150
+ name: "expires_at";
151
+ tableName: "sessions";
152
+ dataType: "date";
153
+ columnType: "PgTimestamp";
154
+ data: Date;
155
+ driverParam: string;
156
+ notNull: true;
157
+ hasDefault: false;
158
+ isPrimaryKey: false;
159
+ isAutoincrement: false;
160
+ hasRuntimeDefault: false;
161
+ enumValues: undefined;
162
+ baseColumn: never;
163
+ identity: undefined;
164
+ generated: undefined;
165
+ }, {}, {}>;
166
+ };
167
+ dialect: "pg";
168
+ }>;
169
+ export declare const userRoles: import("drizzle-orm/pg-core").PgTableWithColumns<{
170
+ name: "user_roles";
171
+ schema: "auth";
172
+ columns: {
173
+ userId: import("drizzle-orm/pg-core").PgColumn<{
174
+ name: "user_id";
175
+ tableName: "user_roles";
176
+ dataType: "string";
177
+ columnType: "PgUUID";
178
+ data: string;
179
+ driverParam: string;
180
+ notNull: true;
181
+ hasDefault: false;
182
+ isPrimaryKey: false;
183
+ isAutoincrement: false;
184
+ hasRuntimeDefault: false;
185
+ enumValues: undefined;
186
+ baseColumn: never;
187
+ identity: undefined;
188
+ generated: undefined;
189
+ }, {}, {}>;
190
+ role: import("drizzle-orm/pg-core").PgColumn<{
191
+ name: "role";
192
+ tableName: "user_roles";
193
+ dataType: "string";
194
+ columnType: "PgText";
195
+ data: string;
196
+ driverParam: string;
197
+ notNull: true;
198
+ hasDefault: false;
199
+ isPrimaryKey: false;
200
+ isAutoincrement: false;
201
+ hasRuntimeDefault: false;
202
+ enumValues: [string, ...string[]];
203
+ baseColumn: never;
204
+ identity: undefined;
205
+ generated: undefined;
206
+ }, {}, {}>;
207
+ grantedAt: import("drizzle-orm/pg-core").PgColumn<{
208
+ name: "granted_at";
209
+ tableName: "user_roles";
210
+ dataType: "date";
211
+ columnType: "PgTimestamp";
212
+ data: Date;
213
+ driverParam: string;
214
+ notNull: true;
215
+ hasDefault: false;
216
+ isPrimaryKey: false;
217
+ isAutoincrement: false;
218
+ hasRuntimeDefault: false;
219
+ enumValues: undefined;
220
+ baseColumn: never;
221
+ identity: undefined;
222
+ generated: undefined;
223
+ }, {}, {}>;
224
+ };
225
+ dialect: "pg";
226
+ }>;
227
+ export declare const passwordResets: import("drizzle-orm/pg-core").PgTableWithColumns<{
228
+ name: "password_resets";
229
+ schema: "auth";
230
+ columns: {
231
+ userId: import("drizzle-orm/pg-core").PgColumn<{
232
+ name: "user_id";
233
+ tableName: "password_resets";
234
+ dataType: "string";
235
+ columnType: "PgUUID";
236
+ data: string;
237
+ driverParam: string;
238
+ notNull: true;
239
+ hasDefault: false;
240
+ isPrimaryKey: true;
241
+ isAutoincrement: false;
242
+ hasRuntimeDefault: false;
243
+ enumValues: undefined;
244
+ baseColumn: never;
245
+ identity: undefined;
246
+ generated: undefined;
247
+ }, {}, {}>;
248
+ tokenHash: import("drizzle-orm/pg-core").PgColumn<{
249
+ name: "token_hash";
250
+ tableName: "password_resets";
251
+ dataType: "string";
252
+ columnType: "PgText";
253
+ data: string;
254
+ driverParam: string;
255
+ notNull: true;
256
+ hasDefault: false;
257
+ isPrimaryKey: false;
258
+ isAutoincrement: false;
259
+ hasRuntimeDefault: false;
260
+ enumValues: [string, ...string[]];
261
+ baseColumn: never;
262
+ identity: undefined;
263
+ generated: undefined;
264
+ }, {}, {}>;
265
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
266
+ name: "created_at";
267
+ tableName: "password_resets";
268
+ dataType: "date";
269
+ columnType: "PgTimestamp";
270
+ data: Date;
271
+ driverParam: string;
272
+ notNull: true;
273
+ hasDefault: false;
274
+ isPrimaryKey: false;
275
+ isAutoincrement: false;
276
+ hasRuntimeDefault: false;
277
+ enumValues: undefined;
278
+ baseColumn: never;
279
+ identity: undefined;
280
+ generated: undefined;
281
+ }, {}, {}>;
282
+ expiresAt: import("drizzle-orm/pg-core").PgColumn<{
283
+ name: "expires_at";
284
+ tableName: "password_resets";
285
+ dataType: "date";
286
+ columnType: "PgTimestamp";
287
+ data: Date;
288
+ driverParam: string;
289
+ notNull: true;
290
+ hasDefault: false;
291
+ isPrimaryKey: false;
292
+ isAutoincrement: false;
293
+ hasRuntimeDefault: false;
294
+ enumValues: undefined;
295
+ baseColumn: never;
296
+ identity: undefined;
297
+ generated: undefined;
298
+ }, {}, {}>;
299
+ };
300
+ dialect: "pg";
301
+ }>;
302
+ //# sourceMappingURL=schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,UAAU,gDAAmB,CAAC;AAE3C,eAAO,MAAM,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMhB,CAAC;AAEH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOnB,CAAC;AAEH,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUrB,CAAC;AAEF,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAOzB,CAAC"}
package/dist/schema.js ADDED
@@ -0,0 +1,37 @@
1
+ // Drizzle view of the module's tables (migrations/0001_create_users_and_sessions.sql,
2
+ // 0002_create_user_roles.sql, 0003_create_password_resets.sql and the users.created_at index of
3
+ // 0004_index_users_created_at.sql). The migrations are the source of truth; this file only types
4
+ // the queries. App tables may reference `users.id`.
5
+ import { pgSchema, primaryKey, text, timestamp, uuid } from "drizzle-orm/pg-core";
6
+ export const authSchema = pgSchema("auth");
7
+ export const users = authSchema.table("users", {
8
+ id: uuid("id").primaryKey().defaultRandom(),
9
+ email: text("email").notNull().unique("users_email_key"),
10
+ passwordHash: text("password_hash").notNull(),
11
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
12
+ passwordChangedAt: timestamp("password_changed_at", { withTimezone: true }).notNull(),
13
+ });
14
+ export const sessions = authSchema.table("sessions", {
15
+ tokenHash: text("token_hash").primaryKey(),
16
+ userId: uuid("user_id")
17
+ .notNull()
18
+ .references(() => users.id, { onDelete: "cascade" }),
19
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
20
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
21
+ });
22
+ export const userRoles = authSchema.table("user_roles", {
23
+ userId: uuid("user_id")
24
+ .notNull()
25
+ .references(() => users.id, { onDelete: "cascade" }),
26
+ role: text("role").notNull(),
27
+ grantedAt: timestamp("granted_at", { withTimezone: true }).notNull(),
28
+ }, (table) => [primaryKey({ columns: [table.userId, table.role] })]);
29
+ export const passwordResets = authSchema.table("password_resets", {
30
+ userId: uuid("user_id")
31
+ .primaryKey()
32
+ .references(() => users.id, { onDelete: "cascade" }),
33
+ tokenHash: text("token_hash").notNull().unique("password_resets_token_hash_key"),
34
+ createdAt: timestamp("created_at", { withTimezone: true }).notNull(),
35
+ expiresAt: timestamp("expires_at", { withTimezone: true }).notNull(),
36
+ });
37
+ //# sourceMappingURL=schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,sFAAsF;AACtF,gGAAgG;AAChG,iGAAiG;AACjG,oDAAoD;AACpD,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAElF,MAAM,CAAC,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;AAE3C,MAAM,CAAC,MAAM,KAAK,GAAG,UAAU,CAAC,KAAK,CAAC,OAAO,EAAE;IAC7C,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE;IAC3C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,iBAAiB,CAAC;IACxD,YAAY,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC,OAAO,EAAE;IAC7C,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;IACpE,iBAAiB,EAAE,SAAS,CAAC,qBAAqB,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;CACtF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,UAAU,EAAE;IACnD,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,UAAU,EAAE;IAC1C,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC;SACpB,OAAO,EAAE;SACT,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,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,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE;CACrE,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { createGrantRoleScript, createRevokeRoleScript, type RoleScriptArgs, type RoleScriptOptions } from "./role-scripts.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,KAAK,cAAc,EAAE,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,3 @@
1
+ // `@softure-ai/auth/scripts`: ops scripts that grant and revoke roles (see the README, "Roles").
2
+ export { createGrantRoleScript, createRevokeRoleScript } from "./role-scripts.js";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/scripts/index.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAA+C,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import { type Clock, type SoftureConfig } from "@softure-ai/core";
2
+ import { type OpsScript } from "@softure-ai/ops/scripts";
3
+ export interface RoleScriptArgs {
4
+ readonly email: string;
5
+ readonly role: string;
6
+ }
7
+ export interface RoleScriptOptions {
8
+ /** The time stored as `granted_at`; the system clock by default. */
9
+ readonly clock?: Clock;
10
+ }
11
+ /** `grant-role --email=… --role=…`: stores a declared role for one account. */
12
+ export declare function createGrantRoleScript(config: SoftureConfig, options?: RoleScriptOptions): OpsScript<RoleScriptArgs>;
13
+ /** `revoke-role --email=… --role=…`: deletes a stored role of one account. */
14
+ export declare function createRevokeRoleScript(config: SoftureConfig, options?: RoleScriptOptions): OpsScript<RoleScriptArgs>;
15
+ //# sourceMappingURL=role-scripts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-scripts.d.ts","sourceRoot":"","sources":["../../src/scripts/role-scripts.ts"],"names":[],"mappings":"AAGA,OAAO,EAAmB,KAAK,KAAK,EAAE,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEnF,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAS3F,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,iBAAiB;IAChC,oEAAoE;IACpE,QAAQ,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC;CACxB;AA2BD,+EAA+E;AAC/E,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,iBAAsB,GAAG,SAAS,CAAC,cAAc,CAAC,CAoBvH;AAED,8EAA8E;AAC9E,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,GAAE,iBAAsB,GAAG,SAAS,CAAC,cAAc,CAAC,CAwBxH"}
@@ -0,0 +1,76 @@
1
+ // The operator's way to grant and revoke roles: safe ops scripts (`@softure-ai/ops/scripts`), dry
2
+ // run by default, `--commit` writes. The app bundles them like its migrate step and runs them with
3
+ // its database URL. Reports carry the user id and roles, never the email.
4
+ import { ok, systemClock } from "@softure-ai/core";
5
+ import { defineOpsScript, refuseOpsScript } from "@softure-ai/ops/scripts";
6
+ import { eq } from "drizzle-orm";
7
+ import { z } from "zod";
8
+ import { ADMIN_ROLE } from "../roles.js";
9
+ import { users } from "../schema.js";
10
+ import { getDeclaredRoles, findUserRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole } from "../server/roles.js";
11
+ import { normalizeEmail } from "../server/validation.js";
12
+ const roleScriptArgs = z.strictObject({
13
+ email: z.string().min(1, "--email=<account email> is required"),
14
+ role: z.string().min(1, "--role=<role> is required"),
15
+ });
16
+ const USAGE = ["--email=<account email>", "--role=<declared role, e.g. admin>"];
17
+ async function findAccount(db, email) {
18
+ const [row] = await db.select({ id: users.id, email: users.email }).from(users).where(eq(users.email, normalizeEmail(email))).limit(1);
19
+ return row;
20
+ }
21
+ async function describeRoles(ctx, account) {
22
+ return { userId: account.id, roles: [...(await findUserRoles(ctx, account))].sort() };
23
+ }
24
+ function describeDeclared(config) {
25
+ return [...getDeclaredRoles(config)].join(", ");
26
+ }
27
+ /** `grant-role --email=… --role=…`: stores a declared role for one account. */
28
+ export function createGrantRoleScript(config, options = {}) {
29
+ const clock = options.clock ?? systemClock;
30
+ return defineOpsScript({
31
+ name: "grant-role",
32
+ description: "Grants a declared role to the account with the given email.",
33
+ usage: USAGE,
34
+ args: roleScriptArgs,
35
+ run: async (tx, args) => {
36
+ const ctx = { db: tx, clock, config };
37
+ if (!isDeclaredRole(config, args.role)) {
38
+ return refuseOpsScript(`role "${args.role}" is not declared (declared: ${describeDeclared(config)})`);
39
+ }
40
+ const account = await findAccount(tx, args.email);
41
+ if (account === undefined)
42
+ return refuseOpsScript("no account has this email");
43
+ const before = await describeRoles(ctx, account);
44
+ const granted = await grantRole(ctx, { userId: account.id, role: args.role });
45
+ if (!granted.ok)
46
+ return refuseOpsScript(`the account already has role "${args.role}"`);
47
+ return ok({ before, after: await describeRoles(ctx, account) });
48
+ },
49
+ });
50
+ }
51
+ /** `revoke-role --email=… --role=…`: deletes a stored role of one account. */
52
+ export function createRevokeRoleScript(config, options = {}) {
53
+ const clock = options.clock ?? systemClock;
54
+ return defineOpsScript({
55
+ name: "revoke-role",
56
+ description: "Revokes a stored role from the account with the given email.",
57
+ usage: USAGE,
58
+ args: roleScriptArgs,
59
+ run: async (tx, args) => {
60
+ const ctx = { db: tx, clock, config };
61
+ const account = await findAccount(tx, args.email);
62
+ if (account === undefined)
63
+ return refuseOpsScript("no account has this email");
64
+ const before = await describeRoles(ctx, account);
65
+ const revoked = await revokeRole(ctx, { userId: account.id, role: args.role });
66
+ if (!revoked.ok) {
67
+ const isFromConfig = args.role === ADMIN_ROLE && isConfiguredAdmin(config, account);
68
+ return refuseOpsScript(isFromConfig
69
+ ? "admin comes from auth({ adminEmails }) in softure.config.ts; remove the email there"
70
+ : `the account has no stored role "${args.role}"`);
71
+ }
72
+ return ok({ before, after: await describeRoles(ctx, account) });
73
+ },
74
+ });
75
+ }
76
+ //# sourceMappingURL=role-scripts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"role-scripts.js","sourceRoot":"","sources":["../../src/scripts/role-scripts.ts"],"names":[],"mappings":"AAAA,kGAAkG;AAClG,mGAAmG;AACnG,0EAA0E;AAC1E,OAAO,EAAE,EAAE,EAAE,WAAW,EAAkC,MAAM,kBAAkB,CAAC;AAEnF,OAAO,EAAE,eAAe,EAAE,eAAe,EAAkB,MAAM,yBAAyB,CAAC;AAC3F,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,SAAS,EAAE,iBAAiB,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAE/H,OAAO,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAYzD,MAAM,cAAc,GAAG,CAAC,CAAC,YAAY,CAAC;IACpC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,qCAAqC,CAAC;IAC/D,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,2BAA2B,CAAC;CACrD,CAAC,CAAC;AAEH,MAAM,KAAK,GAAG,CAAC,yBAAyB,EAAE,oCAAoC,CAAC,CAAC;AAOhF,KAAK,UAAU,WAAW,CAA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AAI,OAAO,KAAK,SAAS;gBAAE,OAAO,eAAe,CAAC,2BAA2B,CAAC,CAAC;YAC/E,MAAM,MAAM,GAAG,MAAM,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACjD,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC/E,IAAI,CAAC,OAAO,CAAC,EAAE,EAAE,CAAC;gBAChB,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,KAAK,UAAU,IAAI,iBAAiB,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBACpF,OAAO,eAAe,CACpB,YAAY;oBACV,CAAC,CAAC,qFAAqF;oBACvF,CAAC,CAAC,mCAAmC,IAAI,CAAC,IAAI,GAAG,CACpD,CAAC;YACJ,CAAC;YACD,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC,CAAC;QAClE,CAAC;KACF,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type Err, type Ok } from "@softure-ai/core";
2
+ import type { RateLimitRejection } from "@softure-ai/security";
3
+ import { type AuthContext } from "./sessions.js";
4
+ export interface ChangePasswordInput {
5
+ /** The token of the session making the change; it stays valid. */
6
+ readonly sessionToken: string;
7
+ readonly currentPassword: string;
8
+ readonly newPassword: string;
9
+ }
10
+ export type ChangePasswordErrorCode = "auth.unauthenticated" | "auth.current_password_invalid" | "auth.password_too_short" | "auth.password_too_long";
11
+ export type ChangePasswordResult = Ok<undefined> | Err<ChangePasswordErrorCode> | RateLimitRejection;
12
+ /** Changes the password of the session's user and ends their other sessions. Database errors propagate. */
13
+ export declare function changePassword(ctx: AuthContext, input: ChangePasswordInput): Promise<ChangePasswordResult>;
14
+ //# sourceMappingURL=change-password.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change-password.d.ts","sourceRoot":"","sources":["../../src/server/change-password.ts"],"names":[],"mappings":"AAEA,OAAO,EAAW,KAAK,GAAG,EAAE,KAAK,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAO/D,OAAO,EAAmB,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAIlE,MAAM,WAAW,mBAAmB;IAClC,kEAAkE;IAClE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED,MAAM,MAAM,uBAAuB,GAC/B,sBAAsB,GACtB,+BAA+B,GAC/B,yBAAyB,GACzB,wBAAwB,CAAC;AAE7B,MAAM,MAAM,oBAAoB,GAAG,EAAE,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,uBAAuB,CAAC,GAAG,kBAAkB,CAAC;AAErG,2GAA2G;AAC3G,wBAAsB,cAAc,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC,CA8BhH"}
@@ -0,0 +1,47 @@
1
+ // Password change for a signed-in user. The new hash, the end of every other session of the user
2
+ // and of a pending reset link happen in one transaction; the session that made the change stays signed in.
3
+ import { err, ok } from "@softure-ai/core";
4
+ import { consumeRateLimit } from "@softure-ai/security/server";
5
+ import { and, eq, ne } from "drizzle-orm";
6
+ import { passwordResets, sessions, users } from "../schema.js";
7
+ import { getAuthOptions } from "./options.js";
8
+ import { hashPassword, verifyPassword } from "./password.js";
9
+ import { assertAuthBuckets, BUCKETS, userSubjectKey } from "./rate-limits.js";
10
+ import { findSessionUser } from "./sessions.js";
11
+ import { hashSessionToken } from "./session-token.js";
12
+ import { checkNewPassword } from "./validation.js";
13
+ /** Changes the password of the session's user and ends their other sessions. Database errors propagate. */
14
+ export async function changePassword(ctx, input) {
15
+ const options = getAuthOptions(ctx.config);
16
+ assertAuthBuckets(ctx.config);
17
+ const user = await findSessionUser(ctx, input.sessionToken);
18
+ if (user === null)
19
+ return err("auth.unauthenticated");
20
+ const limit = await consumeRateLimit(ctx, { bucket: BUCKETS.changePassword, key: userSubjectKey(user.id) });
21
+ if (!limit.ok)
22
+ return limit;
23
+ const policy = checkNewPassword(input.newPassword, options.password.minLength);
24
+ if (!policy.ok)
25
+ return policy;
26
+ const [stored] = await ctx.db.select({ passwordHash: users.passwordHash }).from(users).where(eq(users.id, user.id)).limit(1);
27
+ if (stored === undefined)
28
+ return err("auth.unauthenticated");
29
+ if (!(await verifyPassword(input.currentPassword, stored.passwordHash)))
30
+ return err("auth.current_password_invalid");
31
+ const passwordHash = await hashPassword(input.newPassword, options.password.scrypt);
32
+ return ctx.db.transaction(async (tx) => {
33
+ // Conditional on the hash just verified: two parallel changes cannot both win.
34
+ const updated = await tx
35
+ .update(users)
36
+ .set({ passwordHash, passwordChangedAt: ctx.clock.now() })
37
+ .where(and(eq(users.id, user.id), eq(users.passwordHash, stored.passwordHash)))
38
+ .returning();
39
+ if (updated.length === 0)
40
+ return err("auth.current_password_invalid");
41
+ await tx.delete(sessions).where(and(eq(sessions.userId, user.id), ne(sessions.tokenHash, hashSessionToken(input.sessionToken))));
42
+ // A reset link requested before the change must not outlive it.
43
+ await tx.delete(passwordResets).where(eq(passwordResets.userId, user.id));
44
+ return ok();
45
+ });
46
+ }
47
+ //# sourceMappingURL=change-password.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"change-password.js","sourceRoot":"","sources":["../../src/server/change-password.ts"],"names":[],"mappings":"AAAA,iGAAiG;AACjG,2GAA2G;AAC3G,OAAO,EAAE,GAAG,EAAE,EAAE,EAAqB,MAAM,kBAAkB,CAAC;AAE9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,G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QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,EAAE,gBAAgB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC;QACjI,gEAAgE;QAChE,MAAM,EAAE,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAC1E,OAAO,EAAE,EAAE,CAAC;IACd,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,3 @@
1
+ import { type HealthCheck } from "@softure-ai/core";
2
+ export declare const checkAuthTables: HealthCheck;
3
+ //# sourceMappingURL=health.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AAGA,OAAO,EAAM,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIxD,eAAO,MAAM,eAAe,EAAE,WAQ7B,CAAC"}
@@ -0,0 +1,15 @@
1
+ // auth's readiness probe for `GET /api/health` of `@softure-ai/ops` (core's `defineModule({ health })`):
2
+ // auth can serve only when all of its tables exist and answer, i.e. after `softure migrate`. It
3
+ // reads no rows, so it stays cheap and runs as the row-limited app role.
4
+ import { ok } from "@softure-ai/core";
5
+ import { sql } from "drizzle-orm";
6
+ export const checkAuthTables = async (context) => {
7
+ // Core types `db` as unknown; the health route passes the @softure-ai/db handle.
8
+ const db = context.db;
9
+ await db.execute(sql `select 1 from auth.users limit 0`);
10
+ await db.execute(sql `select 1 from auth.sessions limit 0`);
11
+ await db.execute(sql `select 1 from auth.user_roles limit 0`);
12
+ await db.execute(sql `select 1 from auth.password_resets limit 0`);
13
+ return ok();
14
+ };
15
+ //# sourceMappingURL=health.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"health.js","sourceRoot":"","sources":["../../src/server/health.ts"],"names":[],"mappings":"AAAA,yGAAyG;AACzG,gGAAgG;AAChG,yEAAyE;AACzE,OAAO,EAAE,EAAE,EAAoB,MAAM,kBAAkB,CAAC;AAExD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,MAAM,CAAC,MAAM,eAAe,GAAgB,KAAK,EAAE,OAAO,EAAE,EAAE;IAC5D,iFAAiF;IACjF,MAAM,EAAE,GAAG,OAAO,CAAC,EAAe,CAAC;IACnC,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA,kCAAkC,CAAC,CAAC;IACxD,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA,qCAAqC,CAAC,CAAC;IAC3D,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA,uCAAuC,CAAC,CAAC;IAC7D,MAAM,EAAE,CAAC,OAAO,CAAC,GAAG,CAAA,4CAA4C,CAAC,CAAC;IAClE,OAAO,EAAE,EAAE,CAAC;AACd,CAAC,CAAC"}
@@ -0,0 +1,12 @@
1
+ export { changePassword, type ChangePasswordErrorCode, type ChangePasswordInput, type ChangePasswordResult } from "./change-password.js";
2
+ export { loginUser, type LoginInput, type LoginResult } from "./login.js";
3
+ export { getAuthOptions, getAuthRoutes, type AuthRoutes } from "./options.js";
4
+ export { hashPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword } from "./password.js";
5
+ export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, type PasswordResetRequestInput, type PasswordResetRequestResult, type ResetPasswordErrorCode, type ResetPasswordInput, type ResetPasswordResult, } from "./password-reset.js";
6
+ export { assertDeclaredRole, findUserRoles, getDeclaredRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole, type RoleChange, type RoleErrorCode, } from "./roles.js";
7
+ export { authPrivacyContributor, deleteAuthUserData, exportAuthUserData, type AuthUserData } from "./privacy.js";
8
+ export { isCurrentPassword } from "./reauthenticate.js";
9
+ export { registerUser, type RegisterErrorCode, type RegisterInput, type RegisterResult } from "./register.js";
10
+ export { createSession, findSessionUser, logoutSession, pruneSessions, type AuthContext } from "./sessions.js";
11
+ export { isRegistrationClosed } from "./switches.js";
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,KAAK,uBAAuB,EAAE,KAAK,mBAAmB,EAAE,KAAK,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,KAAK,UAAU,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,EACjB,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAC/B,KAAK,sBAAsB,EAC3B,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,EACV,KAAK,UAAU,EACf,KAAK,aAAa,GACnB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAE,KAAK,iBAAiB,EAAE,KAAK,aAAa,EAAE,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAC9G,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAC/G,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,14 @@
1
+ // Server-only API of @softure-ai/auth. Every function receives the module context
2
+ // (`{ db, clock, config }`) and never reads request scope; tokens and client keys come in as values.
3
+ export { changePassword } from "./change-password.js";
4
+ export { loginUser } from "./login.js";
5
+ export { getAuthOptions, getAuthRoutes } from "./options.js";
6
+ export { hashPassword, MAX_PASSWORD_LENGTH, needsRehash, verifyPassword } from "./password.js";
7
+ export { deliverPasswordReset, findPasswordResetUser, getPasswordResetLink, isPasswordResetEnabled, issuePasswordReset, prunePasswordResets, requestPasswordReset, resetPassword, RESET_TOKEN_PARAM, } from "./password-reset.js";
8
+ export { assertDeclaredRole, findUserRoles, getDeclaredRoles, grantRole, isConfiguredAdmin, isDeclaredRole, revokeRole, } from "./roles.js";
9
+ export { authPrivacyContributor, deleteAuthUserData, exportAuthUserData } from "./privacy.js";
10
+ export { isCurrentPassword } from "./reauthenticate.js";
11
+ export { registerUser } from "./register.js";
12
+ export { createSession, findSessionUser, logoutSession, pruneSessions } from "./sessions.js";
13
+ export { isRegistrationClosed } from "./switches.js";
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,qGAAqG;AACrG,OAAO,EAAE,cAAc,EAAqF,MAAM,sBAAsB,CAAC;AACzI,OAAO,EAAE,SAAS,EAAqC,MAAM,YAAY,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,aAAa,EAAmB,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAC/F,OAAO,EACL,oBAAoB,EACpB,qBAAqB,EACrB,oBAAoB,EACpB,sBAAsB,EACtB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,iBAAiB,GAMlB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,kBAAkB,EAClB,aAAa,EACb,gBAAgB,EAChB,SAAS,EACT,iBAAiB,EACjB,cAAc,EACd,UAAU,GAGX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,kBAAkB,EAAqB,MAAM,cAAc,CAAC;AACjH,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,YAAY,EAAmE,MAAM,eAAe,CAAC;AAC9G,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,aAAa,EAAoB,MAAM,eAAe,CAAC;AAC/G,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { type Err, type Ok } from "@softure-ai/core";
2
+ import type { RateLimitRejection } from "@softure-ai/security";
3
+ import type { SignedIn } from "../contract.js";
4
+ import { type AuthContext } from "./sessions.js";
5
+ export interface LoginInput {
6
+ readonly email: string;
7
+ readonly password: string;
8
+ /** The client's rate limit key (`identifyClient`). */
9
+ readonly clientKey: string;
10
+ }
11
+ export type LoginResult = Ok<SignedIn> | Err<"auth.invalid_credentials"> | RateLimitRejection;
12
+ /** Checks the credentials and opens a session. Database errors propagate. */
13
+ export declare function loginUser(ctx: AuthContext, input: LoginInput): Promise<LoginResult>;
14
+ //# sourceMappingURL=login.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"login.d.ts","sourceRoot":"","sources":["../../src/server/login.ts"],"names":[],"mappings":"AAGA,OAAO,EAAW,KAAK,GAAG,EAAE,KAAK,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAK/C,OAAO,EAAwC,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAGvF,MAAM,WAAW,UAAU;IACzB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,sDAAsD;IACtD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;CAC5B;AAED,MAAM,MAAM,WAAW,GAAG,EAAE,CAAC,QAAQ,CAAC,GAAG,GAAG,CAAC,0BAA0B,CAAC,GAAG,kBAAkB,CAAC;AAE9F,6EAA6E;AAC7E,wBAAsB,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,WAAW,CAAC,CAmCzF"}