@gatwech/core 0.0.10 → 1.0.0-beta.18

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 (130) hide show
  1. package/dist/api/index.d.mts +2 -2
  2. package/dist/context/index.d.mts +2 -2
  3. package/dist/db/adapter/index.d.mts +2 -2
  4. package/dist/db/index.d.mts +2 -2
  5. package/dist/env/index.d.mts +1 -1
  6. package/dist/env/index.mjs +1 -1
  7. package/dist/{env-JMSMESs1.mjs → env-4_Lym7sj.mjs} +7 -7
  8. package/dist/index-65G5U5DB.d.mts +3002 -0
  9. package/dist/{index-DLP-K0uY.d.mts → index-CmdhhvA2.d.mts} +3 -3
  10. package/dist/index.d.mts +3 -3
  11. package/dist/oauth2/index.d.mts +2 -2
  12. package/dist/social-providers/index.d.mts +3 -3
  13. package/dist/social-providers/index.mjs +71 -2412
  14. package/dist/src/api/index.d.ts +119 -0
  15. package/dist/src/async_hooks/index.d.ts +6 -0
  16. package/dist/src/context/endpoint-context.d.ts +14 -0
  17. package/dist/src/context/index.d.ts +3 -0
  18. package/dist/src/context/request-state.d.ts +13 -0
  19. package/dist/src/context/transaction.d.ts +11 -0
  20. package/dist/src/db/adapter/index.d.ts +401 -0
  21. package/{src/db/index.ts → dist/src/db/index.d.ts} +2 -18
  22. package/dist/src/db/plugin.d.ts +10 -0
  23. package/dist/src/db/schema/account.d.ts +22 -0
  24. package/dist/src/db/schema/rate-limit.d.ts +10 -0
  25. package/dist/src/db/schema/session.d.ts +17 -0
  26. package/dist/src/db/schema/shared.d.ts +6 -0
  27. package/dist/src/db/schema/user.d.ts +16 -0
  28. package/{src/db/schema/verification.ts → dist/src/db/schema/verification.d.ts} +8 -8
  29. package/dist/src/db/type.d.ts +159 -0
  30. package/dist/src/env/color-depth.d.ts +1 -0
  31. package/dist/src/env/env-impl.d.ts +29 -0
  32. package/dist/src/env/index.d.ts +3 -0
  33. package/dist/src/env/logger.d.ts +50 -0
  34. package/dist/src/error/codes.d.ts +27 -0
  35. package/dist/src/error/index.d.ts +4 -0
  36. package/dist/src/oauth2/client-credentials-token.d.ts +21 -0
  37. package/dist/src/oauth2/create-authorization-url.d.ts +21 -0
  38. package/dist/src/oauth2/index.d.ts +6 -0
  39. package/dist/src/oauth2/oauth-provider.d.ts +178 -0
  40. package/dist/src/oauth2/refresh-access-token.d.ts +20 -0
  41. package/dist/src/oauth2/utils.d.ts +3 -0
  42. package/dist/src/oauth2/validate-authorization-code.d.ts +28 -0
  43. package/dist/src/social-providers/github.d.ts +89 -0
  44. package/dist/src/social-providers/google.d.ts +82 -0
  45. package/dist/src/social-providers/index.d.ts +93 -0
  46. package/dist/src/types/context.d.ts +177 -0
  47. package/dist/src/types/cookie.d.ts +15 -0
  48. package/dist/src/types/helper.d.ts +9 -0
  49. package/dist/src/types/index.d.ts +7 -0
  50. package/dist/src/types/init-options.d.ts +1140 -0
  51. package/dist/src/types/plugin-client.d.ts +88 -0
  52. package/dist/src/types/plugin.d.ts +120 -0
  53. package/dist/src/utils/error-codes.d.ts +9 -0
  54. package/package.json +11 -5
  55. package/.turbo/turbo-build.log +0 -42
  56. package/dist/index-DjrJweYn.d.mts +0 -7312
  57. package/src/api/index.ts +0 -57
  58. package/src/async_hooks/index.ts +0 -35
  59. package/src/context/endpoint-context.ts +0 -48
  60. package/src/context/index.ts +0 -21
  61. package/src/context/request-state.test.ts +0 -346
  62. package/src/context/request-state.ts +0 -75
  63. package/src/context/transaction.ts +0 -72
  64. package/src/db/adapter/index.ts +0 -466
  65. package/src/db/plugin.ts +0 -11
  66. package/src/db/schema/account.ts +0 -34
  67. package/src/db/schema/rate-limit.ts +0 -21
  68. package/src/db/schema/session.ts +0 -17
  69. package/src/db/schema/shared.ts +0 -7
  70. package/src/db/schema/user.ts +0 -16
  71. package/src/db/type.ts +0 -180
  72. package/src/env/color-depth.ts +0 -172
  73. package/src/env/env-impl.ts +0 -124
  74. package/src/env/index.ts +0 -23
  75. package/src/env/logger.test.ts +0 -33
  76. package/src/env/logger.ts +0 -145
  77. package/src/error/codes.ts +0 -31
  78. package/src/error/index.ts +0 -11
  79. package/src/oauth2/client-credentials-token.ts +0 -102
  80. package/src/oauth2/create-authorization-url.ts +0 -85
  81. package/src/oauth2/index.ts +0 -21
  82. package/src/oauth2/oauth-provider.ts +0 -211
  83. package/src/oauth2/refresh-access-token.ts +0 -124
  84. package/src/oauth2/utils.ts +0 -36
  85. package/src/oauth2/validate-authorization-code.ts +0 -154
  86. package/src/social-providers/apple.ts +0 -213
  87. package/src/social-providers/atlassian.ts +0 -132
  88. package/src/social-providers/cognito.ts +0 -269
  89. package/src/social-providers/discord.ts +0 -169
  90. package/src/social-providers/dropbox.ts +0 -112
  91. package/src/social-providers/facebook.ts +0 -204
  92. package/src/social-providers/figma.ts +0 -115
  93. package/src/social-providers/github.ts +0 -154
  94. package/src/social-providers/gitlab.ts +0 -152
  95. package/src/social-providers/google.ts +0 -171
  96. package/src/social-providers/huggingface.ts +0 -118
  97. package/src/social-providers/index.ts +0 -124
  98. package/src/social-providers/kakao.ts +0 -178
  99. package/src/social-providers/kick.ts +0 -92
  100. package/src/social-providers/line.ts +0 -169
  101. package/src/social-providers/linear.ts +0 -120
  102. package/src/social-providers/linkedin.ts +0 -110
  103. package/src/social-providers/microsoft-entra-id.ts +0 -245
  104. package/src/social-providers/naver.ts +0 -112
  105. package/src/social-providers/notion.ts +0 -108
  106. package/src/social-providers/paybin.ts +0 -122
  107. package/src/social-providers/paypal.ts +0 -263
  108. package/src/social-providers/polar.ts +0 -107
  109. package/src/social-providers/reddit.ts +0 -122
  110. package/src/social-providers/roblox.ts +0 -110
  111. package/src/social-providers/salesforce.ts +0 -159
  112. package/src/social-providers/slack.ts +0 -111
  113. package/src/social-providers/spotify.ts +0 -93
  114. package/src/social-providers/tiktok.ts +0 -210
  115. package/src/social-providers/twitch.ts +0 -111
  116. package/src/social-providers/twitter.ts +0 -198
  117. package/src/social-providers/vk.ts +0 -126
  118. package/src/social-providers/zoom.ts +0 -217
  119. package/src/types/context.ts +0 -269
  120. package/src/types/cookie.ts +0 -7
  121. package/src/types/helper.ts +0 -6
  122. package/src/types/index.ts +0 -21
  123. package/src/types/init-options.ts +0 -1346
  124. package/src/types/plugin-client.ts +0 -100
  125. package/src/types/plugin.ts +0 -158
  126. package/src/utils/error-codes.ts +0 -51
  127. package/tsconfig.json +0 -7
  128. package/tsdown.config.ts +0 -20
  129. /package/{src/index.ts → dist/src/index.d.ts} +0 -0
  130. /package/{src/utils/index.ts → dist/src/utils/index.d.ts} +0 -0
@@ -0,0 +1,3002 @@
1
+ import { i as Logger, o as createLogger } from "./index-CmdhhvA2.mjs";
2
+ import * as better_call0 from "better-call";
3
+ import { CookieOptions, Endpoint, EndpointContext, EndpointOptions, InputContext, Middleware } from "better-call";
4
+ import * as z$1 from "zod";
5
+ import { BetterFetch, BetterFetchOption, BetterFetchPlugin } from "@better-fetch/fetch";
6
+ import * as jose0 from "jose";
7
+ import { StandardSchemaV1, StandardSchemaV1 as StandardSchemaV1$1 } from "@standard-schema/spec";
8
+ import { Database } from "bun:sqlite";
9
+ import { DatabaseSync } from "node:sqlite";
10
+ import { Dialect, Kysely, Migration, MysqlPool, PostgresPool, SqliteDatabase } from "kysely";
11
+ import { Atom, WritableAtom } from "nanostores";
12
+
13
+ //#region src/db/type.d.ts
14
+ type DBPreservedModels = "user" | "account" | "session" | "verification" | "rate-limit" | "organization" | "member" | "invitation" | "jwks" | "passkey" | "two-factor";
15
+ type DBFieldType = "string" | "number" | "boolean" | "date" | "json" | `${"string" | "number"}[]` | Array<LiteralString>;
16
+ type DBPrimitive = string | number | boolean | Date | null | undefined | string[] | number[];
17
+ type DBFieldAttributeConfig = {
18
+ /**
19
+ * If the field should be required on a new record.
20
+ * @default true
21
+ */
22
+ required?: boolean | undefined;
23
+ /**
24
+ * If the value should be returned on a response body.
25
+ * @default true
26
+ */
27
+ returned?: boolean | undefined;
28
+ /**
29
+ * If a value should be provided when creating a new record.
30
+ * @default true
31
+ */
32
+ input?: boolean | undefined;
33
+ /**
34
+ * Default value for the field
35
+ *
36
+ * Note: This will not create a default value on the database level. It will only
37
+ * be used when creating a new record.
38
+ */
39
+ defaultValue?: (DBPrimitive | (() => DBPrimitive)) | undefined;
40
+ /**
41
+ * Update value for the field
42
+ *
43
+ * Note: This will create an onUpdate trigger on the database level for supported adapters.
44
+ * It will be called when updating a record.
45
+ */
46
+ onUpdate?: (() => DBPrimitive) | undefined;
47
+ /**
48
+ * transform the value before storing it.
49
+ */
50
+ transform?: {
51
+ input?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
52
+ output?: (value: DBPrimitive) => DBPrimitive | Promise<DBPrimitive>;
53
+ } | undefined;
54
+ /**
55
+ * Reference to another model.
56
+ */
57
+ references?: {
58
+ /**
59
+ * The model to reference.
60
+ */
61
+ model: string;
62
+ /**
63
+ * The field on the referenced model.
64
+ */
65
+ field: string;
66
+ /**
67
+ * The action to perform when the reference is deleted.
68
+ * @default "cascade"
69
+ */
70
+ onDelete?: "no action" | "restrict" | "cascade" | "set null" | "set default";
71
+ } | undefined;
72
+ unique?: boolean | undefined;
73
+ /**
74
+ * If the field should be a bigint on the database instead of integer.
75
+ */
76
+ bigint?: boolean | undefined;
77
+ /**
78
+ * A zod schema to validate the value.
79
+ */
80
+ validator?: {
81
+ input?: StandardSchemaV1;
82
+ output?: StandardSchemaV1;
83
+ } | undefined;
84
+ /**
85
+ * The name of the field on the database.
86
+ */
87
+ fieldName?: string | undefined;
88
+ /**
89
+ * If the field should be sortable.
90
+ *
91
+ * applicable only for `text` type.
92
+ * It's useful to mark fields varchar instead of text.
93
+ */
94
+ sortable?: boolean | undefined;
95
+ };
96
+ type DBFieldAttribute<T extends DBFieldType = DBFieldType> = {
97
+ type: T;
98
+ } & DBFieldAttributeConfig;
99
+ type PayvoAuthDBSchema = Record<string, {
100
+ /**
101
+ * The name of the table in the database
102
+ */
103
+ modelName: string;
104
+ /**
105
+ * The fields of the table
106
+ */
107
+ fields: Record<string, DBFieldAttribute>;
108
+ /**
109
+ * Whether to disable migrations for this table
110
+ * @default false
111
+ */
112
+ disableMigrations?: boolean | undefined;
113
+ /**
114
+ * The order of the table
115
+ */
116
+ order?: number | undefined;
117
+ }>;
118
+ interface SecondaryStorage {
119
+ /**
120
+ *
121
+ * @param key - Key to get
122
+ * @returns - Value of the key
123
+ */
124
+ get: (key: string) => Awaitable$1<unknown>;
125
+ /**
126
+ * Atomically get a value and delete it from storage.
127
+ *
128
+ * This is optional for backwards compatibility with existing secondary
129
+ * storage implementations. Single-use credential consumers use it when
130
+ * present to avoid a read-then-delete race.
131
+ *
132
+ * TODO(secondary-storage-atomic-consume): make this required in the next
133
+ * breaking release, or require database-backed verification storage for
134
+ * security-sensitive consume paths.
135
+ */
136
+ getAndDelete?: (key: string) => Awaitable$1<unknown>;
137
+ /**
138
+ * Atomically increment the counter at `key` by one, returning the
139
+ * post-increment value.
140
+ *
141
+ * When the key is absent, it is created with a value of `1` and the given
142
+ * `ttl` (in SECONDS). The TTL is applied only on creation; later increments
143
+ * never extend it, so the counter expires a fixed window after it was first
144
+ * created.
145
+ *
146
+ * This is optional for backwards compatibility with existing secondary
147
+ * storage implementations. TODO(secondary-storage-increment-required): make
148
+ * this required for secondary-storage-backed rate limiting in the next minor
149
+ * on `next`.
150
+ */
151
+ increment?: (key: string, ttl: number) => Awaitable$1<number>;
152
+ set: (
153
+ /**
154
+ * Key to store
155
+ */
156
+ key: string,
157
+ /**
158
+ * Value to store
159
+ */
160
+ value: string,
161
+ /**
162
+ * Time to live in seconds
163
+ */
164
+ ttl?: number | undefined) => Awaitable$1<void | null | unknown>;
165
+ /**
166
+ *
167
+ * @param key - Key to delete
168
+ */
169
+ delete: (key: string) => Awaitable$1<void | null | string>;
170
+ }
171
+ //#endregion
172
+ //#region src/db/plugin.d.ts
173
+ type PayvoAuthPluginDBSchema = { [table in string]: {
174
+ fields: {
175
+ [field: string]: DBFieldAttribute;
176
+ };
177
+ disableMigration?: boolean | undefined;
178
+ modelName?: string | undefined;
179
+ } };
180
+ //#endregion
181
+ //#region src/db/schema/account.d.ts
182
+ declare const accountSchema: z$1.ZodObject<{
183
+ id: z$1.ZodString;
184
+ createdAt: z$1.ZodDefault<z$1.ZodDate>;
185
+ updatedAt: z$1.ZodDefault<z$1.ZodDate>;
186
+ providerId: z$1.ZodString;
187
+ accountId: z$1.ZodString;
188
+ userId: z$1.ZodCoercedString<unknown>;
189
+ accessToken: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
190
+ refreshToken: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
191
+ idToken: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
192
+ accessTokenExpiresAt: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodDate>>;
193
+ refreshTokenExpiresAt: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodDate>>;
194
+ scope: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
195
+ password: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
196
+ }, z$1.core.$strip>;
197
+ /**
198
+ * Account schema type used by payvo-auth, note that it's possible that account could have additional fields
199
+ *
200
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
201
+ */
202
+ type Account = z$1.infer<typeof accountSchema>;
203
+ //#endregion
204
+ //#region src/db/schema/rate-limit.d.ts
205
+ declare const rateLimitSchema: z$1.ZodObject<{
206
+ key: z$1.ZodString;
207
+ count: z$1.ZodNumber;
208
+ lastRequest: z$1.ZodNumber;
209
+ }, z$1.core.$strip>;
210
+ /**
211
+ * Rate limit schema type used by payvo-auth for rate limiting
212
+ */
213
+ type RateLimit = z$1.infer<typeof rateLimitSchema>;
214
+ //#endregion
215
+ //#region src/db/schema/session.d.ts
216
+ declare const sessionSchema: z$1.ZodObject<{
217
+ id: z$1.ZodString;
218
+ createdAt: z$1.ZodDefault<z$1.ZodDate>;
219
+ updatedAt: z$1.ZodDefault<z$1.ZodDate>;
220
+ userId: z$1.ZodCoercedString<unknown>;
221
+ expiresAt: z$1.ZodDate;
222
+ token: z$1.ZodString;
223
+ ipAddress: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
224
+ userAgent: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
225
+ }, z$1.core.$strip>;
226
+ /**
227
+ * Session schema type used by payvo-auth, note that it's possible that session could have additional fields
228
+ *
229
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
230
+ */
231
+ type Session = z$1.infer<typeof sessionSchema>;
232
+ //#endregion
233
+ //#region src/db/schema/shared.d.ts
234
+ declare const coreSchema: z$1.ZodObject<{
235
+ id: z$1.ZodString;
236
+ createdAt: z$1.ZodDefault<z$1.ZodDate>;
237
+ updatedAt: z$1.ZodDefault<z$1.ZodDate>;
238
+ }, z$1.core.$strip>;
239
+ //#endregion
240
+ //#region src/db/schema/user.d.ts
241
+ declare const userSchema: z$1.ZodObject<{
242
+ id: z$1.ZodString;
243
+ createdAt: z$1.ZodDefault<z$1.ZodDate>;
244
+ updatedAt: z$1.ZodDefault<z$1.ZodDate>;
245
+ email: z$1.ZodPipe<z$1.ZodString, z$1.ZodTransform<string, string>>;
246
+ emailVerified: z$1.ZodDefault<z$1.ZodBoolean>;
247
+ name: z$1.ZodString;
248
+ image: z$1.ZodOptional<z$1.ZodNullable<z$1.ZodString>>;
249
+ }, z$1.core.$strip>;
250
+ /**
251
+ * User schema type used by payvo-auth, note that it's possible that user could have additional fields
252
+ *
253
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
254
+ */
255
+ type User = z$1.infer<typeof userSchema>;
256
+ //#endregion
257
+ //#region src/db/schema/verification.d.ts
258
+ declare const verificationSchema: z$1.ZodObject<{
259
+ id: z$1.ZodString;
260
+ createdAt: z$1.ZodDefault<z$1.ZodDate>;
261
+ updatedAt: z$1.ZodDefault<z$1.ZodDate>;
262
+ value: z$1.ZodString;
263
+ expiresAt: z$1.ZodDate;
264
+ identifier: z$1.ZodString;
265
+ }, z$1.core.$strip>;
266
+ /**
267
+ * Verification schema type used by payvo-auth, note that it's possible that verification could have additional fields
268
+ *
269
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
270
+ */
271
+ type Verification = z$1.infer<typeof verificationSchema>;
272
+ //#endregion
273
+ //#region src/db/index.d.ts
274
+ /**
275
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
276
+ */
277
+ type AuthPluginSchema = PayvoAuthPluginDBSchema;
278
+ /**
279
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
280
+ */
281
+ type FieldAttribute = DBFieldAttribute;
282
+ /**
283
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
284
+ */
285
+ type FieldAttributeConfig = DBFieldAttributeConfig;
286
+ /**
287
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
288
+ */
289
+ type FieldType = DBFieldType;
290
+ /**
291
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
292
+ */
293
+ type Primitive$1 = DBPrimitive;
294
+ /**
295
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
296
+ */
297
+ type PayvoAuthDbSchema = PayvoAuthDBSchema;
298
+ //#endregion
299
+ //#region src/db/adapter/index.d.ts
300
+ type DBAdapterDebugLogOption = boolean | {
301
+ /**
302
+ * Useful when you want to log only certain conditions.
303
+ */
304
+ logCondition?: (() => boolean) | undefined;
305
+ create?: boolean | undefined;
306
+ update?: boolean | undefined;
307
+ updateMany?: boolean | undefined;
308
+ findOne?: boolean | undefined;
309
+ findMany?: boolean | undefined;
310
+ delete?: boolean | undefined;
311
+ deleteMany?: boolean | undefined;
312
+ count?: boolean | undefined;
313
+ } | {
314
+ /**
315
+ * Only used for adapter tests to show debug logs if a test fails.
316
+ *
317
+ * @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
318
+ */
319
+ isRunningAdapterTests: boolean;
320
+ };
321
+ type DBAdapterSchemaCreation = {
322
+ /**
323
+ * Code to be inserted into the file
324
+ */
325
+ code: string;
326
+ /**
327
+ * Path to the file, including the file name and extension.
328
+ * Relative paths are supported, with the current working directory of the developer's project as the base.
329
+ */
330
+ path: string;
331
+ /**
332
+ * Append the file if it already exists.
333
+ * Note: This will not apply if `overwrite` is set to true.
334
+ */
335
+ append?: boolean | undefined;
336
+ /**
337
+ * Overwrite the file if it already exists
338
+ */
339
+ overwrite?: boolean | undefined;
340
+ };
341
+ interface DBAdapterFactoryConfig<Options extends PayvoAuthOptions = PayvoAuthOptions> {
342
+ /**
343
+ * Use plural table names.
344
+ *
345
+ * All tables will be named with an `s` at the end.
346
+ *
347
+ * @default false
348
+ */
349
+ usePlural?: boolean | undefined;
350
+ /**
351
+ * Enable debug logs.
352
+ *
353
+ * @default false
354
+ */
355
+ debugLogs?: DBAdapterDebugLogOption | undefined;
356
+ /**
357
+ * Name of the adapter.
358
+ *
359
+ * This is used to identify the adapter in the debug logs.
360
+ *
361
+ * @default `adapterId`
362
+ */
363
+ adapterName?: string | undefined;
364
+ /**
365
+ * Adapter id
366
+ */
367
+ adapterId: string;
368
+ /**
369
+ * If the database supports numeric ids, set this to `true`.
370
+ *
371
+ * @default true
372
+ */
373
+ supportsNumericIds?: boolean | undefined;
374
+ /**
375
+ * If the database doesn't support JSON columns, set this to `false`.
376
+ *
377
+ * We will handle the translation between using `JSON` columns, and saving `string`s to the database.
378
+ *
379
+ * @default false
380
+ */
381
+ supportsJSON?: boolean | undefined;
382
+ /**
383
+ * If the database doesn't support dates, set this to `false`.
384
+ *
385
+ * We will handle the translation between using `Date` objects, and saving `string`s to the database.
386
+ *
387
+ * @default true
388
+ */
389
+ supportsDates?: boolean | undefined;
390
+ /**
391
+ * If the database doesn't support booleans, set this to `false`.
392
+ *
393
+ * We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.
394
+ *
395
+ * @default true
396
+ */
397
+ supportsBooleans?: boolean | undefined;
398
+ /**
399
+ * Execute multiple operations in a transaction.
400
+ *
401
+ * If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
402
+ *
403
+ * @default false
404
+ */
405
+ transaction?: (false | (<R>(callback: (trx: DBTransactionAdapter<Options>) => Promise<R>) => Promise<R>)) | undefined;
406
+ /**
407
+ * Disable id generation for the `create` method.
408
+ *
409
+ * This is useful for databases that don't support custom id values and would auto-generate them for you.
410
+ *
411
+ * @default false
412
+ */
413
+ disableIdGeneration?: boolean | undefined;
414
+ /**
415
+ * Map the keys of the input data.
416
+ *
417
+ * This is useful for databases that expect a different key name for a given situation.
418
+ *
419
+ * For example, MongoDB uses `_id` while in Payvo-Auth we use `id`.
420
+ *
421
+ *
422
+ * @example
423
+ * Each key represents the old key to replace.
424
+ * The value represents the new key
425
+ *
426
+ * This can be a partial object that only transforms some keys.
427
+ *
428
+ * ```ts
429
+ * mapKeysTransformInput: {
430
+ * id: "_id" // We want to replace `id` to `_id` to save into MongoDB
431
+ * }
432
+ * ```
433
+ */
434
+ mapKeysTransformInput?: Record<string, string> | undefined;
435
+ /**
436
+ * Map the keys of the output data.
437
+ *
438
+ * This is useful for databases that expect a different key name for a given situation.
439
+ *
440
+ * For example, MongoDB uses `_id` while in Payvo-Auth we use `id`.
441
+ *
442
+ * @example
443
+ * Each key represents the old key to replace.
444
+ * The value represents the new key
445
+ *
446
+ * This can be a partial object that only transforms some keys.
447
+ *
448
+ * ```ts
449
+ * mapKeysTransformOutput: {
450
+ * _id: "id" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.
451
+ * }
452
+ * ```
453
+ */
454
+ mapKeysTransformOutput?: Record<string, string> | undefined;
455
+ /**
456
+ * Custom transform input function.
457
+ *
458
+ * This function is used to transform the input data before it is saved to the database.
459
+ */
460
+ customTransformInput?: ((props: {
461
+ data: any;
462
+ /**
463
+ * The fields of the model.
464
+ */
465
+ fieldAttributes: DBFieldAttribute;
466
+ /**
467
+ * The field to transform.
468
+ */
469
+ field: string;
470
+ /**
471
+ * The action which was called from the adapter.
472
+ */
473
+ action: "create" | "update";
474
+ /**
475
+ * The model name.
476
+ */
477
+ model: string;
478
+ /**
479
+ * The schema of the user's Payvo-Auth instance.
480
+ */
481
+ schema: PayvoAuthDBSchema;
482
+ /**
483
+ * The options of the user's Payvo-Auth instance.
484
+ */
485
+ options: Options;
486
+ }) => any) | undefined;
487
+ /**
488
+ * Custom transform output function.
489
+ *
490
+ * This function is used to transform the output data before it is returned to the user.
491
+ */
492
+ customTransformOutput?: ((props: {
493
+ data: any;
494
+ /**
495
+ * The fields of the model.
496
+ */
497
+ fieldAttributes: DBFieldAttribute;
498
+ /**
499
+ * The field to transform.
500
+ */
501
+ field: string;
502
+ /**
503
+ * The fields to select.
504
+ */
505
+ select: string[];
506
+ /**
507
+ * The model name.
508
+ */
509
+ model: string;
510
+ /**
511
+ * The schema of the user's Payvo-Auth instance.
512
+ */
513
+ schema: PayvoAuthDBSchema;
514
+ /**
515
+ * The options of the user's Payvo-Auth instance.
516
+ */
517
+ options: Options;
518
+ }) => any) | undefined;
519
+ /**
520
+ * Custom ID generator function.
521
+ *
522
+ * By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,
523
+ * then you can use this function to generate your own IDs.
524
+ *
525
+ *
526
+ * Notes:
527
+ * - If the user enabled `useNumberId`, then this option will be ignored. Unless this adapter config has `supportsNumericIds` set to `false`.
528
+ * - If `generateId` is `false` in the user's Payvo-Auth config, then this option will be ignored.
529
+ * - If `generateId` is a function, then it will override this option.
530
+ *
531
+ * @example
532
+ *
533
+ * ```ts
534
+ * customIdGenerator: ({ model }) => {
535
+ * return "my-super-unique-id";
536
+ * }
537
+ * ```
538
+ */
539
+ customIdGenerator?: ((props: {
540
+ model: string;
541
+ }) => string) | undefined;
542
+ /**
543
+ * Whether to disable the transform output.
544
+ * Do not use this option unless you know what you are doing.
545
+ * @default false
546
+ */
547
+ disableTransformOutput?: boolean | undefined;
548
+ /**
549
+ * Whether to disable the transform input.
550
+ * Do not use this option unless you know what you are doing.
551
+ * @default false
552
+ */
553
+ disableTransformInput?: boolean | undefined;
554
+ }
555
+ type Where = {
556
+ /**
557
+ * @default eq
558
+ */
559
+ operator?: ("eq" | "ne" | "lt" | "lte" | "gt" | "gte" | "in" | "not_in" | "contains" | "starts_with" | "ends_with") | undefined;
560
+ value: string | number | boolean | string[] | number[] | Date | null;
561
+ field: string;
562
+ /**
563
+ * @default AND
564
+ */
565
+ connector?: ("AND" | "OR") | undefined;
566
+ };
567
+ type DBTransactionAdapter<Options extends PayvoAuthOptions = PayvoAuthOptions> = Omit<DBAdapter<Options>, "transaction">;
568
+ type DBAdapter<Options extends PayvoAuthOptions = PayvoAuthOptions> = {
569
+ id: string;
570
+ create: <T extends Record<string, any>, R = T>(data: {
571
+ model: string;
572
+ data: Omit<T, "id">;
573
+ select?: string[] | undefined;
574
+ /**
575
+ * By default, any `id` provided in `data` will be ignored.
576
+ *
577
+ * If you want to force the `id` to be the same as the `data.id`, set this to `true`.
578
+ */
579
+ forceAllowId?: boolean | undefined;
580
+ }) => Promise<R>;
581
+ findOne: <T>(data: {
582
+ model: string;
583
+ where: Where[];
584
+ select?: string[] | undefined;
585
+ }) => Promise<T | null>;
586
+ findMany: <T>(data: {
587
+ model: string;
588
+ where?: Where[] | undefined;
589
+ limit?: number | undefined;
590
+ sortBy?: {
591
+ field: string;
592
+ direction: "asc" | "desc";
593
+ } | undefined;
594
+ offset?: number | undefined;
595
+ }) => Promise<T[]>;
596
+ count: (data: {
597
+ model: string;
598
+ where?: Where[] | undefined;
599
+ }) => Promise<number>;
600
+ /**
601
+ * ⚠︎ Update may not return the updated data
602
+ * if multiple where clauses are provided
603
+ */
604
+ update: <T>(data: {
605
+ model: string;
606
+ where: Where[];
607
+ update: Record<string, any>;
608
+ }) => Promise<T | null>;
609
+ updateMany: (data: {
610
+ model: string;
611
+ where: Where[];
612
+ update: Record<string, any>;
613
+ }) => Promise<number>;
614
+ delete: <T>(data: {
615
+ model: string;
616
+ where: Where[];
617
+ }) => Promise<void>;
618
+ deleteMany: (data: {
619
+ model: string;
620
+ where: Where[];
621
+ }) => Promise<number>;
622
+ /**
623
+ * Execute multiple operations in a transaction.
624
+ * If the adapter doesn't support transactions, operations will be executed sequentially.
625
+ */
626
+ transaction: <R>(callback: (trx: DBTransactionAdapter<Options>) => Promise<R>) => Promise<R>;
627
+ /**
628
+ *
629
+ * @param options
630
+ * @param file - file path if provided by the user
631
+ */
632
+ createSchema?: ((options: Options, file?: string) => Promise<DBAdapterSchemaCreation>) | undefined;
633
+ options?: ({
634
+ adapterConfig: DBAdapterFactoryConfig<Options>;
635
+ } & CustomAdapter["options"]) | undefined;
636
+ };
637
+ type CleanedWhere = Required<Where>;
638
+ interface CustomAdapter {
639
+ create: <T extends Record<string, any>>({
640
+ data,
641
+ model,
642
+ select
643
+ }: {
644
+ model: string;
645
+ data: T;
646
+ select?: string[] | undefined;
647
+ }) => Promise<T>;
648
+ update: <T>(data: {
649
+ model: string;
650
+ where: CleanedWhere[];
651
+ update: T;
652
+ }) => Promise<T | null>;
653
+ updateMany: (data: {
654
+ model: string;
655
+ where: CleanedWhere[];
656
+ update: Record<string, any>;
657
+ }) => Promise<number>;
658
+ findOne: <T>({
659
+ model,
660
+ where,
661
+ select
662
+ }: {
663
+ model: string;
664
+ where: CleanedWhere[];
665
+ select?: string[] | undefined;
666
+ }) => Promise<T | null>;
667
+ findMany: <T>({
668
+ model,
669
+ where,
670
+ limit,
671
+ sortBy,
672
+ offset
673
+ }: {
674
+ model: string;
675
+ where?: CleanedWhere[] | undefined;
676
+ limit: number;
677
+ sortBy?: {
678
+ field: string;
679
+ direction: "asc" | "desc";
680
+ } | undefined;
681
+ offset?: number | undefined;
682
+ }) => Promise<T[]>;
683
+ delete: ({
684
+ model,
685
+ where
686
+ }: {
687
+ model: string;
688
+ where: CleanedWhere[];
689
+ }) => Promise<void>;
690
+ deleteMany: ({
691
+ model,
692
+ where
693
+ }: {
694
+ model: string;
695
+ where: CleanedWhere[];
696
+ }) => Promise<number>;
697
+ count: ({
698
+ model,
699
+ where
700
+ }: {
701
+ model: string;
702
+ where?: CleanedWhere[] | undefined;
703
+ }) => Promise<number>;
704
+ createSchema?: ((props: {
705
+ /**
706
+ * The file the user may have passed in to the `generate` command as the expected schema file output path.
707
+ */
708
+ file?: string;
709
+ /**
710
+ * The tables from the user's Payvo-Auth instance schema.
711
+ */
712
+ tables: PayvoAuthDBSchema;
713
+ }) => Promise<DBAdapterSchemaCreation>) | undefined;
714
+ /**
715
+ * Your adapter's options.
716
+ */
717
+ options?: Record<string, any> | undefined;
718
+ }
719
+ interface DBAdapterInstance<Options extends PayvoAuthOptions = PayvoAuthOptions> {
720
+ (options: PayvoAuthOptions): DBAdapter<Options>;
721
+ }
722
+ //#endregion
723
+ //#region src/oauth2/oauth-provider.d.ts
724
+ interface OAuth2Tokens {
725
+ tokenType?: string | undefined;
726
+ accessToken?: string | undefined;
727
+ refreshToken?: string | undefined;
728
+ accessTokenExpiresAt?: Date | undefined;
729
+ refreshTokenExpiresAt?: Date | undefined;
730
+ scopes?: string[] | undefined;
731
+ idToken?: string | undefined;
732
+ }
733
+ type OAuth2UserInfo = {
734
+ id: string | number;
735
+ name?: string | undefined;
736
+ email?: (string | null) | undefined;
737
+ image?: string | undefined;
738
+ emailVerified: boolean;
739
+ };
740
+ interface OAuthProvider<T extends Record<string, any> = Record<string, any>, O extends Record<string, any> = Partial<ProviderOptions>> {
741
+ id: LiteralString;
742
+ createAuthorizationURL: (data: {
743
+ state: string;
744
+ codeVerifier: string;
745
+ scopes?: string[] | undefined;
746
+ redirectURI: string;
747
+ display?: string | undefined;
748
+ loginHint?: string | undefined;
749
+ }) => Promise<URL> | URL;
750
+ name: string;
751
+ validateAuthorizationCode: (data: {
752
+ code: string;
753
+ redirectURI: string;
754
+ codeVerifier?: string | undefined;
755
+ deviceId?: string | undefined;
756
+ }) => Promise<OAuth2Tokens>;
757
+ getUserInfo: (token: OAuth2Tokens & {
758
+ /**
759
+ * The user object from the provider
760
+ * This is only available for some providers like Apple
761
+ */
762
+ user?: {
763
+ name?: {
764
+ firstName?: string;
765
+ lastName?: string;
766
+ };
767
+ email?: string;
768
+ } | undefined;
769
+ }) => Promise<{
770
+ user: OAuth2UserInfo;
771
+ data: T;
772
+ } | null>;
773
+ /**
774
+ * Custom function to refresh a token
775
+ */
776
+ refreshAccessToken?: ((refreshToken: string) => Promise<OAuth2Tokens>) | undefined;
777
+ revokeToken?: ((token: string) => Promise<void>) | undefined;
778
+ /**
779
+ * Verify the id token
780
+ * @param token - The id token
781
+ * @param nonce - The nonce
782
+ * @returns True if the id token is valid, false otherwise
783
+ */
784
+ verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
785
+ /**
786
+ * Disable implicit sign up for new users. When set to true for the provider,
787
+ * sign-in need to be called with with requestSignUp as true to create new users.
788
+ */
789
+ disableImplicitSignUp?: boolean | undefined;
790
+ /**
791
+ * Disable sign up for new users.
792
+ */
793
+ disableSignUp?: boolean | undefined;
794
+ /**
795
+ * Options for the provider
796
+ */
797
+ options?: O | undefined;
798
+ }
799
+ type ProviderOptions<Profile extends Record<string, any> = any> = {
800
+ /**
801
+ * The client ID of your application.
802
+ *
803
+ * This is usually a string but can be any type depending on the provider.
804
+ */
805
+ clientId?: unknown | undefined;
806
+ /**
807
+ * The client secret of your application
808
+ */
809
+ clientSecret?: string | undefined;
810
+ /**
811
+ * The scopes you want to request from the provider
812
+ */
813
+ scope?: string[] | undefined;
814
+ /**
815
+ * Remove default scopes of the provider
816
+ */
817
+ disableDefaultScope?: boolean | undefined;
818
+ /**
819
+ * The redirect URL for your application. This is where the provider will
820
+ * redirect the user after the sign in process. Make sure this URL is
821
+ * whitelisted in the provider's dashboard.
822
+ */
823
+ redirectURI?: string | undefined;
824
+ /**
825
+ * The client key of your application
826
+ * Tiktok Social Provider uses this field instead of clientId
827
+ */
828
+ clientKey?: string | undefined;
829
+ /**
830
+ * Disable provider from allowing users to sign in
831
+ * with this provider with an id token sent from the
832
+ * client.
833
+ */
834
+ disableIdTokenSignIn?: boolean | undefined;
835
+ /**
836
+ * verifyIdToken function to verify the id token
837
+ */
838
+ verifyIdToken?: ((token: string, nonce?: string) => Promise<boolean>) | undefined;
839
+ /**
840
+ * Custom function to get user info from the provider
841
+ */
842
+ getUserInfo?: ((token: OAuth2Tokens) => Promise<{
843
+ user: {
844
+ id: string;
845
+ name?: string;
846
+ email?: string | null;
847
+ image?: string;
848
+ emailVerified: boolean;
849
+ [key: string]: any;
850
+ };
851
+ data: any;
852
+ }>) | undefined;
853
+ /**
854
+ * Custom function to refresh a token
855
+ */
856
+ refreshAccessToken?: ((refreshToken: string) => Promise<OAuth2Tokens>) | undefined;
857
+ /**
858
+ * Custom function to map the provider profile to a
859
+ * user.
860
+ */
861
+ mapProfileToUser?: ((profile: Profile) => {
862
+ id?: string;
863
+ name?: string;
864
+ email?: string | null;
865
+ image?: string;
866
+ emailVerified?: boolean;
867
+ [key: string]: any;
868
+ } | Promise<{
869
+ id?: string;
870
+ name?: string;
871
+ email?: string | null;
872
+ image?: string;
873
+ emailVerified?: boolean;
874
+ [key: string]: any;
875
+ }>) | undefined;
876
+ /**
877
+ * Disable implicit sign up for new users. When set to true for the provider,
878
+ * sign-in need to be called with with requestSignUp as true to create new users.
879
+ */
880
+ disableImplicitSignUp?: boolean | undefined;
881
+ /**
882
+ * Disable sign up for new users.
883
+ */
884
+ disableSignUp?: boolean | undefined;
885
+ /**
886
+ * The prompt to use for the authorization code request
887
+ */
888
+ prompt?: ("select_account" | "consent" | "login" | "none" | "select_account consent") | undefined;
889
+ /**
890
+ * The response mode to use for the authorization code request
891
+ */
892
+ responseMode?: ("query" | "form_post") | undefined;
893
+ /**
894
+ * If enabled, the user info will be overridden with the provider user info
895
+ * This is useful if you want to use the provider user info to update the user info
896
+ *
897
+ * @default false
898
+ */
899
+ overrideUserInfoOnSignIn?: boolean | undefined;
900
+ };
901
+ //#endregion
902
+ //#region src/oauth2/client-credentials-token.d.ts
903
+ declare function createClientCredentialsTokenRequest({
904
+ options,
905
+ scope,
906
+ authentication,
907
+ resource
908
+ }: {
909
+ options: ProviderOptions & {
910
+ clientSecret: string;
911
+ };
912
+ scope?: string | undefined;
913
+ authentication?: ("basic" | "post") | undefined;
914
+ resource?: (string | string[]) | undefined;
915
+ }): {
916
+ body: URLSearchParams;
917
+ headers: Record<string, any>;
918
+ };
919
+ declare function clientCredentialsToken({
920
+ options,
921
+ tokenEndpoint,
922
+ scope,
923
+ authentication,
924
+ resource
925
+ }: {
926
+ options: ProviderOptions & {
927
+ clientSecret: string;
928
+ };
929
+ tokenEndpoint: string;
930
+ scope: string;
931
+ authentication?: ("basic" | "post") | undefined;
932
+ resource?: (string | string[]) | undefined;
933
+ }): Promise<OAuth2Tokens>;
934
+ //#endregion
935
+ //#region src/oauth2/create-authorization-url.d.ts
936
+ declare function createAuthorizationURL({
937
+ id,
938
+ options,
939
+ authorizationEndpoint,
940
+ state,
941
+ codeVerifier,
942
+ scopes,
943
+ claims,
944
+ redirectURI,
945
+ duration,
946
+ prompt,
947
+ accessType,
948
+ responseType,
949
+ display,
950
+ loginHint,
951
+ hd,
952
+ responseMode,
953
+ additionalParams,
954
+ scopeJoiner
955
+ }: {
956
+ id: string;
957
+ options: ProviderOptions;
958
+ redirectURI: string;
959
+ authorizationEndpoint: string;
960
+ state: string;
961
+ codeVerifier?: string | undefined;
962
+ scopes: string[];
963
+ claims?: string[] | undefined;
964
+ duration?: string | undefined;
965
+ prompt?: string | undefined;
966
+ accessType?: string | undefined;
967
+ responseType?: string | undefined;
968
+ display?: string | undefined;
969
+ loginHint?: string | undefined;
970
+ hd?: string | undefined;
971
+ responseMode?: string | undefined;
972
+ additionalParams?: Record<string, string> | undefined;
973
+ scopeJoiner?: string | undefined;
974
+ }): Promise<URL>;
975
+ //#endregion
976
+ //#region src/oauth2/refresh-access-token.d.ts
977
+ declare function createRefreshAccessTokenRequest({
978
+ refreshToken,
979
+ options,
980
+ authentication,
981
+ extraParams,
982
+ resource
983
+ }: {
984
+ refreshToken: string;
985
+ options: Partial<ProviderOptions>;
986
+ authentication?: ("basic" | "post") | undefined;
987
+ extraParams?: Record<string, string> | undefined;
988
+ resource?: (string | string[]) | undefined;
989
+ }): {
990
+ body: URLSearchParams;
991
+ headers: Record<string, any>;
992
+ };
993
+ declare function refreshAccessToken({
994
+ refreshToken,
995
+ options,
996
+ tokenEndpoint,
997
+ authentication,
998
+ extraParams
999
+ }: {
1000
+ refreshToken: string;
1001
+ options: Partial<ProviderOptions>;
1002
+ tokenEndpoint: string;
1003
+ authentication?: ("basic" | "post") | undefined;
1004
+ extraParams?: Record<string, string> | undefined;
1005
+ /** @deprecated always "refresh_token" */
1006
+ grantType?: string | undefined;
1007
+ }): Promise<OAuth2Tokens>;
1008
+ //#endregion
1009
+ //#region src/oauth2/utils.d.ts
1010
+ declare function getOAuth2Tokens(data: Record<string, any>): OAuth2Tokens;
1011
+ declare function generateCodeChallenge(codeVerifier: string): Promise<string>;
1012
+ //#endregion
1013
+ //#region src/oauth2/validate-authorization-code.d.ts
1014
+ declare function createAuthorizationCodeRequest({
1015
+ code,
1016
+ codeVerifier,
1017
+ redirectURI,
1018
+ options,
1019
+ authentication,
1020
+ deviceId,
1021
+ headers,
1022
+ additionalParams,
1023
+ resource
1024
+ }: {
1025
+ code: string;
1026
+ redirectURI: string;
1027
+ options: Partial<ProviderOptions>;
1028
+ codeVerifier?: string | undefined;
1029
+ deviceId?: string | undefined;
1030
+ authentication?: ("basic" | "post") | undefined;
1031
+ headers?: Record<string, string> | undefined;
1032
+ additionalParams?: Record<string, string> | undefined;
1033
+ resource?: (string | string[]) | undefined;
1034
+ }): {
1035
+ body: URLSearchParams;
1036
+ headers: Record<string, any>;
1037
+ };
1038
+ declare function validateAuthorizationCode({
1039
+ code,
1040
+ codeVerifier,
1041
+ redirectURI,
1042
+ options,
1043
+ tokenEndpoint,
1044
+ authentication,
1045
+ deviceId,
1046
+ headers,
1047
+ additionalParams,
1048
+ resource
1049
+ }: {
1050
+ code: string;
1051
+ redirectURI: string;
1052
+ options: Partial<ProviderOptions>;
1053
+ codeVerifier?: string | undefined;
1054
+ deviceId?: string | undefined;
1055
+ tokenEndpoint: string;
1056
+ authentication?: ("basic" | "post") | undefined;
1057
+ headers?: Record<string, string> | undefined;
1058
+ additionalParams?: Record<string, string> | undefined;
1059
+ resource?: (string | string[]) | undefined;
1060
+ }): Promise<OAuth2Tokens>;
1061
+ declare function validateToken(token: string, jwksEndpoint: string): Promise<jose0.JWTVerifyResult<jose0.JWTPayload>>;
1062
+ //#endregion
1063
+ //#region src/types/cookie.d.ts
1064
+ type PayvoAuthCookies = {
1065
+ sessionToken: {
1066
+ name: string;
1067
+ options: CookieOptions;
1068
+ };
1069
+ sessionData: {
1070
+ name: string;
1071
+ options: CookieOptions;
1072
+ };
1073
+ dontRememberToken: {
1074
+ name: string;
1075
+ options: CookieOptions;
1076
+ };
1077
+ };
1078
+ //#endregion
1079
+ //#region src/types/helper.d.ts
1080
+ type Primitive = string | number | symbol | bigint | boolean | null | undefined;
1081
+ type Awaitable$1<T> = T | Promise<T>;
1082
+ type AwaitableFunction<T> = T | (() => Awaitable$1<T>);
1083
+ type LiteralString = "" | (string & Record<never, never>);
1084
+ type LiteralUnion<LiteralType, BaseType extends Primitive> = LiteralType | (BaseType & Record<never, never>);
1085
+ type Prettify<T> = { [K in keyof T]: T[K] } & {};
1086
+ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
1087
+ //#endregion
1088
+ //#region src/social-providers/github.d.ts
1089
+ interface GithubProfile {
1090
+ login: string;
1091
+ id: string;
1092
+ node_id: string;
1093
+ avatar_url: string;
1094
+ gravatar_id: string;
1095
+ url: string;
1096
+ html_url: string;
1097
+ followers_url: string;
1098
+ following_url: string;
1099
+ gists_url: string;
1100
+ starred_url: string;
1101
+ subscriptions_url: string;
1102
+ organizations_url: string;
1103
+ repos_url: string;
1104
+ events_url: string;
1105
+ received_events_url: string;
1106
+ type: string;
1107
+ site_admin: boolean;
1108
+ name: string;
1109
+ company: string;
1110
+ blog: string;
1111
+ location: string;
1112
+ email: string;
1113
+ hireable: boolean;
1114
+ bio: string;
1115
+ twitter_username: string;
1116
+ public_repos: string;
1117
+ public_gists: string;
1118
+ followers: string;
1119
+ following: string;
1120
+ created_at: string;
1121
+ updated_at: string;
1122
+ private_gists: string;
1123
+ total_private_repos: string;
1124
+ owned_private_repos: string;
1125
+ disk_usage: string;
1126
+ collaborators: string;
1127
+ two_factor_authentication: boolean;
1128
+ plan: {
1129
+ name: string;
1130
+ space: string;
1131
+ private_repos: string;
1132
+ collaborators: string;
1133
+ };
1134
+ }
1135
+ interface GithubOptions extends ProviderOptions<GithubProfile> {
1136
+ clientId: string;
1137
+ }
1138
+ declare const github: (options: GithubOptions) => {
1139
+ id: "github";
1140
+ name: string;
1141
+ createAuthorizationURL({
1142
+ state,
1143
+ scopes,
1144
+ loginHint,
1145
+ redirectURI
1146
+ }: {
1147
+ state: string;
1148
+ codeVerifier: string;
1149
+ scopes?: string[] | undefined;
1150
+ redirectURI: string;
1151
+ display?: string | undefined;
1152
+ loginHint?: string | undefined;
1153
+ }): Promise<URL>;
1154
+ validateAuthorizationCode: ({
1155
+ code,
1156
+ redirectURI
1157
+ }: {
1158
+ code: string;
1159
+ redirectURI: string;
1160
+ codeVerifier?: string | undefined;
1161
+ deviceId?: string | undefined;
1162
+ }) => Promise<OAuth2Tokens>;
1163
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
1164
+ getUserInfo(token: OAuth2Tokens & {
1165
+ user?: {
1166
+ name?: {
1167
+ firstName?: string;
1168
+ lastName?: string;
1169
+ };
1170
+ email?: string;
1171
+ } | undefined;
1172
+ }): Promise<{
1173
+ user: {
1174
+ id: string;
1175
+ name?: string;
1176
+ email?: string | null;
1177
+ image?: string;
1178
+ emailVerified: boolean;
1179
+ [key: string]: any;
1180
+ };
1181
+ data: any;
1182
+ } | null>;
1183
+ options: GithubOptions;
1184
+ };
1185
+ //#endregion
1186
+ //#region src/social-providers/google.d.ts
1187
+ interface GoogleProfile {
1188
+ aud: string;
1189
+ azp: string;
1190
+ email: string;
1191
+ email_verified: boolean;
1192
+ exp: number;
1193
+ /**
1194
+ * The family name of the user, or last name in most
1195
+ * Western languages.
1196
+ */
1197
+ family_name: string;
1198
+ /**
1199
+ * The given name of the user, or first name in most
1200
+ * Western languages.
1201
+ */
1202
+ given_name: string;
1203
+ hd?: string | undefined;
1204
+ iat: number;
1205
+ iss: string;
1206
+ jti?: string | undefined;
1207
+ locale?: string | undefined;
1208
+ name: string;
1209
+ nbf?: number | undefined;
1210
+ picture: string;
1211
+ sub: string;
1212
+ }
1213
+ interface GoogleOptions extends ProviderOptions<GoogleProfile> {
1214
+ clientId: string;
1215
+ /**
1216
+ * The access type to use for the authorization code request
1217
+ */
1218
+ accessType?: ("offline" | "online") | undefined;
1219
+ /**
1220
+ * The display mode to use for the authorization code request
1221
+ */
1222
+ display?: ("page" | "popup" | "touch" | "wap") | undefined;
1223
+ /**
1224
+ * The hosted domain of the user
1225
+ */
1226
+ hd?: string | undefined;
1227
+ }
1228
+ declare const google: (options: GoogleOptions) => {
1229
+ id: "google";
1230
+ name: string;
1231
+ createAuthorizationURL({
1232
+ state,
1233
+ scopes,
1234
+ codeVerifier,
1235
+ redirectURI,
1236
+ loginHint,
1237
+ display
1238
+ }: {
1239
+ state: string;
1240
+ codeVerifier: string;
1241
+ scopes?: string[] | undefined;
1242
+ redirectURI: string;
1243
+ display?: string | undefined;
1244
+ loginHint?: string | undefined;
1245
+ }): Promise<URL>;
1246
+ validateAuthorizationCode: ({
1247
+ code,
1248
+ codeVerifier,
1249
+ redirectURI
1250
+ }: {
1251
+ code: string;
1252
+ redirectURI: string;
1253
+ codeVerifier?: string | undefined;
1254
+ deviceId?: string | undefined;
1255
+ }) => Promise<OAuth2Tokens>;
1256
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
1257
+ verifyIdToken(token: string, nonce: string | undefined): Promise<boolean>;
1258
+ getUserInfo(token: OAuth2Tokens & {
1259
+ user?: {
1260
+ name?: {
1261
+ firstName?: string;
1262
+ lastName?: string;
1263
+ };
1264
+ email?: string;
1265
+ } | undefined;
1266
+ }): Promise<{
1267
+ user: {
1268
+ id: string;
1269
+ name?: string;
1270
+ email?: string | null;
1271
+ image?: string;
1272
+ emailVerified: boolean;
1273
+ [key: string]: any;
1274
+ };
1275
+ data: any;
1276
+ } | null>;
1277
+ options: GoogleOptions;
1278
+ };
1279
+ //#endregion
1280
+ //#region src/social-providers/index.d.ts
1281
+ declare const socialProviders: {
1282
+ github: (options: GithubOptions) => {
1283
+ id: "github";
1284
+ name: string;
1285
+ createAuthorizationURL({
1286
+ state,
1287
+ scopes,
1288
+ loginHint,
1289
+ redirectURI
1290
+ }: {
1291
+ state: string;
1292
+ codeVerifier: string;
1293
+ scopes?: string[] | undefined;
1294
+ redirectURI: string;
1295
+ display?: string | undefined;
1296
+ loginHint?: string | undefined;
1297
+ }): Promise<URL>;
1298
+ validateAuthorizationCode: ({
1299
+ code,
1300
+ redirectURI
1301
+ }: {
1302
+ code: string;
1303
+ redirectURI: string;
1304
+ codeVerifier?: string | undefined;
1305
+ deviceId?: string | undefined;
1306
+ }) => Promise<OAuth2Tokens>;
1307
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
1308
+ getUserInfo(token: OAuth2Tokens & {
1309
+ user?: {
1310
+ name?: {
1311
+ firstName?: string;
1312
+ lastName?: string;
1313
+ };
1314
+ email?: string;
1315
+ } | undefined;
1316
+ }): Promise<{
1317
+ user: {
1318
+ id: string;
1319
+ name?: string;
1320
+ email?: string | null;
1321
+ image?: string;
1322
+ emailVerified: boolean;
1323
+ [key: string]: any;
1324
+ };
1325
+ data: any;
1326
+ } | null>;
1327
+ options: GithubOptions;
1328
+ };
1329
+ google: (options: GoogleOptions) => {
1330
+ id: "google";
1331
+ name: string;
1332
+ createAuthorizationURL({
1333
+ state,
1334
+ scopes,
1335
+ codeVerifier,
1336
+ redirectURI,
1337
+ loginHint,
1338
+ display
1339
+ }: {
1340
+ state: string;
1341
+ codeVerifier: string;
1342
+ scopes?: string[] | undefined;
1343
+ redirectURI: string;
1344
+ display?: string | undefined;
1345
+ loginHint?: string | undefined;
1346
+ }): Promise<URL>;
1347
+ validateAuthorizationCode: ({
1348
+ code,
1349
+ codeVerifier,
1350
+ redirectURI
1351
+ }: {
1352
+ code: string;
1353
+ redirectURI: string;
1354
+ codeVerifier?: string | undefined;
1355
+ deviceId?: string | undefined;
1356
+ }) => Promise<OAuth2Tokens>;
1357
+ refreshAccessToken: (refreshToken: string) => Promise<OAuth2Tokens>;
1358
+ verifyIdToken(token: string, nonce: string | undefined): Promise<boolean>;
1359
+ getUserInfo(token: OAuth2Tokens & {
1360
+ user?: {
1361
+ name?: {
1362
+ firstName?: string;
1363
+ lastName?: string;
1364
+ };
1365
+ email?: string;
1366
+ } | undefined;
1367
+ }): Promise<{
1368
+ user: {
1369
+ id: string;
1370
+ name?: string;
1371
+ email?: string | null;
1372
+ image?: string;
1373
+ emailVerified: boolean;
1374
+ [key: string]: any;
1375
+ };
1376
+ data: any;
1377
+ } | null>;
1378
+ options: GoogleOptions;
1379
+ };
1380
+ };
1381
+ declare const socialProviderList: ["github", ...(keyof typeof socialProviders)[]];
1382
+ declare const SocialProviderListEnum: z$1.ZodType<SocialProviderList[number] | (string & {})>;
1383
+ type SocialProvider = z$1.infer<typeof SocialProviderListEnum>;
1384
+ type SocialProviders = { [K in SocialProviderList[number]]?: Parameters<(typeof socialProviders)[K]>[0] & {
1385
+ enabled?: boolean | undefined;
1386
+ } };
1387
+ type SocialProviderList = typeof socialProviderList;
1388
+ //#endregion
1389
+ //#region src/types/plugin.d.ts
1390
+ type Awaitable<T> = T | Promise<T>;
1391
+ type DeepPartial<T> = T extends Function ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;
1392
+ type HookEndpointContext = Partial<EndpointContext<string, any> & Omit<InputContext<string, any>, "method">> & {
1393
+ path: string;
1394
+ context: AuthContext & {
1395
+ returned?: unknown | undefined;
1396
+ responseHeaders?: Headers | undefined;
1397
+ };
1398
+ headers?: Headers | undefined;
1399
+ };
1400
+ type PayvoAuthPlugin = {
1401
+ id: LiteralString;
1402
+ /**
1403
+ * The init function is called when the plugin is initialized.
1404
+ * You can return a new context or modify the existing context.
1405
+ */
1406
+ init?: ((ctx: AuthContext) => Awaitable<{
1407
+ context?: DeepPartial<Omit<AuthContext, "options">>;
1408
+ options?: Partial<PayvoAuthOptions>;
1409
+ }> | void | Promise<void>) | undefined;
1410
+ endpoints?: {
1411
+ [key: string]: Endpoint;
1412
+ } | undefined;
1413
+ middlewares?: {
1414
+ path: string;
1415
+ middleware: Middleware;
1416
+ }[] | undefined;
1417
+ onRequest?: ((request: Request, ctx: AuthContext) => Promise<{
1418
+ response: Response;
1419
+ } | {
1420
+ request: Request;
1421
+ } | void>) | undefined;
1422
+ onResponse?: ((response: Response, ctx: AuthContext) => Promise<{
1423
+ response: Response;
1424
+ } | void>) | undefined;
1425
+ hooks?: {
1426
+ before?: {
1427
+ matcher: (context: HookEndpointContext) => boolean;
1428
+ handler: AuthMiddleware;
1429
+ }[];
1430
+ after?: {
1431
+ matcher: (context: HookEndpointContext) => boolean;
1432
+ handler: AuthMiddleware;
1433
+ }[];
1434
+ } | undefined;
1435
+ /**
1436
+ * Schema the plugin needs
1437
+ *
1438
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
1439
+ * configuration each time the configuration is changed a new migration will be created.
1440
+ *
1441
+ * NOTE: If you want to create migrations manually using
1442
+ * migrations option or any other way you
1443
+ * can disable migration per table basis.
1444
+ *
1445
+ * @example
1446
+ * ```ts
1447
+ * schema: {
1448
+ * user: {
1449
+ * fields: {
1450
+ * email: {
1451
+ * type: "string",
1452
+ * },
1453
+ * emailVerified: {
1454
+ * type: "boolean",
1455
+ * defaultValue: false,
1456
+ * },
1457
+ * },
1458
+ * }
1459
+ * } as AuthPluginSchema
1460
+ * ```
1461
+ */
1462
+ schema?: PayvoAuthPluginDBSchema | undefined;
1463
+ /**
1464
+ * The migrations of the plugin. If you define schema that will automatically create
1465
+ * migrations for you.
1466
+ *
1467
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
1468
+ * the tables.
1469
+ */
1470
+ migrations?: Record<string, Migration> | undefined;
1471
+ /**
1472
+ * The options of the plugin
1473
+ */
1474
+ options?: Record<string, any> | undefined;
1475
+ /**
1476
+ * types to be inferred
1477
+ */
1478
+ $Infer?: Record<string, any> | undefined;
1479
+ /**
1480
+ * The rate limit rules to apply to specific paths.
1481
+ */
1482
+ rateLimit?: {
1483
+ window: number;
1484
+ max: number;
1485
+ pathMatcher: (path: string) => boolean;
1486
+ }[] | undefined;
1487
+ /**
1488
+ * The error codes returned by the plugin
1489
+ */
1490
+ $ERROR_CODES?: Record<string, string> | undefined;
1491
+ /**
1492
+ * All database operations that are performed by the plugin
1493
+ *
1494
+ * This will override the default database operations
1495
+ */
1496
+ adapter?: {
1497
+ [key: string]: (...args: any[]) => Promise<any> | any;
1498
+ };
1499
+ };
1500
+ //#endregion
1501
+ //#region src/types/init-options.d.ts
1502
+ type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
1503
+ type OmitId<T extends {
1504
+ id: unknown;
1505
+ }> = Omit<T, "id">;
1506
+ type Optional<T> = { [P in keyof T]?: T[P] | undefined };
1507
+ type GenerateIdFn = (options: {
1508
+ model: LiteralUnion<DBPreservedModels, string>;
1509
+ size?: number | undefined;
1510
+ }) => string | false;
1511
+ type PayvoAuthRateLimitOptions = {
1512
+ /**
1513
+ * By default, rate limiting is only
1514
+ * enabled on production.
1515
+ */
1516
+ enabled?: boolean | undefined;
1517
+ /**
1518
+ * Default window to use for rate limiting. The value
1519
+ * should be in seconds.
1520
+ *
1521
+ * @default 10 seconds
1522
+ */
1523
+ window?: number | undefined;
1524
+ /**
1525
+ * The default maximum number of requests allowed within the window.
1526
+ *
1527
+ * @default 100 requests
1528
+ */
1529
+ max?: number | undefined;
1530
+ /**
1531
+ * Custom rate limit rules to apply to
1532
+ * specific paths.
1533
+ */
1534
+ customRules?: {
1535
+ [key: string]: {
1536
+ /**
1537
+ * The window to use for the custom rule.
1538
+ */
1539
+ window: number;
1540
+ /**
1541
+ * The maximum number of requests allowed within the window.
1542
+ */
1543
+ max: number;
1544
+ } | false | ((request: Request) => {
1545
+ window: number;
1546
+ max: number;
1547
+ } | false | Promise<{
1548
+ window: number;
1549
+ max: number;
1550
+ } | false>);
1551
+ } | undefined;
1552
+ /**
1553
+ * Storage configuration
1554
+ *
1555
+ * By default, rate limiting is stored in memory. If you passed a
1556
+ * secondary storage, rate limiting will be stored in the secondary
1557
+ * storage.
1558
+ *
1559
+ * @default "memory"
1560
+ */
1561
+ storage?: ("memory" | "database" | "secondary-storage") | undefined;
1562
+ /**
1563
+ * If database is used as storage, the name of the table to
1564
+ * use for rate limiting.
1565
+ *
1566
+ * @default "rateLimit"
1567
+ */
1568
+ modelName?: string | undefined;
1569
+ /**
1570
+ * Custom field names for the rate limit table
1571
+ */
1572
+ fields?: Record<keyof RateLimit, string> | undefined;
1573
+ /**
1574
+ * custom storage configuration.
1575
+ *
1576
+ * NOTE: If custom storage is used storage
1577
+ * is ignored
1578
+ */
1579
+ customStorage?: {
1580
+ get: (key: string) => Promise<RateLimit | undefined>;
1581
+ set: (key: string, value: RateLimit) => Promise<void>;
1582
+ };
1583
+ };
1584
+ type PayvoAuthAdvancedOptions = {
1585
+ /**
1586
+ * Ip address configuration
1587
+ */
1588
+ ipAddress?: {
1589
+ /**
1590
+ * List of headers to use for ip address
1591
+ *
1592
+ * Ip address is used for rate limiting and session tracking
1593
+ *
1594
+ * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
1595
+ *
1596
+ * @default
1597
+ * @link https://github.com/payvo-auth/payvo-auth/blob/main/packages/payvo-auth/src/utils/get-request-ip.ts#L8
1598
+ */
1599
+ ipAddressHeaders?: string[];
1600
+ /**
1601
+ * Disable ip tracking
1602
+ *
1603
+ * ⚠︎ This is a security risk and it may expose your application to abuse
1604
+ */
1605
+ disableIpTracking?: boolean;
1606
+ } | undefined;
1607
+ /**
1608
+ * Use secure cookies
1609
+ *
1610
+ * @default false
1611
+ */
1612
+ useSecureCookies?: boolean | undefined;
1613
+ /**
1614
+ * Disable trusted origins check
1615
+ *
1616
+ * ⚠︎ This is a security risk and it may expose your application to
1617
+ * CSRF attacks
1618
+ */
1619
+ disableCSRFCheck?: boolean | undefined;
1620
+ /**
1621
+ * Disable origin check
1622
+ *
1623
+ * ⚠︎ This may allow requests from any origin to be processed by
1624
+ * Payvo Auth. And could lead to security vulnerabilities.
1625
+ */
1626
+ disableOriginCheck?: boolean | undefined;
1627
+ /**
1628
+ * Configure cookies to be cross subdomains
1629
+ */
1630
+ crossSubDomainCookies?: {
1631
+ /**
1632
+ * Enable cross subdomain cookies
1633
+ */
1634
+ enabled: boolean;
1635
+ /**
1636
+ * Additional cookies to be shared across subdomains
1637
+ */
1638
+ additionalCookies?: string[];
1639
+ /**
1640
+ * The domain to use for the cookies
1641
+ *
1642
+ * By default, the domain will be the root
1643
+ * domain from the base URL.
1644
+ */
1645
+ domain?: string;
1646
+ } | undefined;
1647
+ cookies?: {
1648
+ [key: string]: {
1649
+ name?: string;
1650
+ attributes?: CookieOptions;
1651
+ };
1652
+ } | undefined;
1653
+ defaultCookieAttributes?: CookieOptions | undefined;
1654
+ /**
1655
+ * Prefix for cookies. If a cookie name is provided
1656
+ * in cookies config, this will be overridden.
1657
+ *
1658
+ * @default
1659
+ * ```txt
1660
+ * "appName" -> which defaults to "payvo-auth"
1661
+ * ```
1662
+ */
1663
+ cookiePrefix?: string | undefined;
1664
+ /**
1665
+ * Database configuration.
1666
+ */
1667
+ database?: {
1668
+ /**
1669
+ * The default number of records to return from the database
1670
+ * when using the `findMany` adapter method.
1671
+ *
1672
+ * @default 100
1673
+ */
1674
+ defaultFindManyLimit?: number;
1675
+ /**
1676
+ * If your database auto increments number ids, set this to `true`.
1677
+ *
1678
+ * Note: If enabled, we will not handle ID generation (including if you use `generateId`), and it would be expected that your database will provide the ID automatically.
1679
+ *
1680
+ * @default false
1681
+ *
1682
+ * @deprecated Please use `generateId` instead. This will be removed in future
1683
+ * releases.
1684
+ */
1685
+ useNumberId?: boolean;
1686
+ /**
1687
+ * Custom generateId function.
1688
+ *
1689
+ * If not provided, random ids will be generated.
1690
+ * If set to false, the database's auto generated id
1691
+ * will be used.
1692
+ *
1693
+ * If set to "serial", the database's auto generated
1694
+ * id will be used.
1695
+ *
1696
+ * If set to "uuid", we generate a random UUID for
1697
+ * the id. If postgres, we use the `gen_random_uuid()
1698
+ * ` function. If mysql or mssql, we use the `uuid()`
1699
+ * function.
1700
+ */
1701
+ generateId?: GenerateIdFn | false | "serial" | "uuid";
1702
+ } | undefined;
1703
+ /**
1704
+ * OAuth configuration
1705
+ */
1706
+ oauthConfig?: {
1707
+ /**
1708
+ * Skip state cookie check
1709
+ *
1710
+ * ⚠︎ this has security implications and should only be enabled if you know what you are doing.
1711
+ * @default false
1712
+ */
1713
+ skipStateCookieCheck?: boolean;
1714
+ /**
1715
+ * Strategy for storing OAuth state
1716
+ *
1717
+ * - "cookie": Store state in an encrypted cookie (stateless)
1718
+ * - "database": Store state in the database
1719
+ *
1720
+ * @default "cookie"
1721
+ */
1722
+ storeStateStrategy?: "database" | "cookie";
1723
+ } | undefined;
1724
+ };
1725
+ type PayvoAuthOptions = {
1726
+ /**
1727
+ * The name of the application
1728
+ *
1729
+ * process.env.APP_NAME
1730
+ *
1731
+ * @default "Payvo Auth"
1732
+ */
1733
+ appName?: string | undefined;
1734
+ /**
1735
+ * Base URL for the Payvo Auth. This is typically the
1736
+ * root URL where your application server is hosted.
1737
+ * If not explicitly set,
1738
+ * the system will check the following environment variable:
1739
+ *
1740
+ * process.env.PAYVO_AUTH_URL
1741
+ */
1742
+ baseURL?: string | undefined;
1743
+ /**
1744
+ * Base path for the Payvo Auth. This is typically
1745
+ * the path where the
1746
+ * Payvo Auth routes are mounted.
1747
+ *
1748
+ * @default "/api/auth"
1749
+ */
1750
+ basePath?: string | undefined;
1751
+ /**
1752
+ * The secret to use for encryption,
1753
+ * signing and hashing.
1754
+ *
1755
+ * By default Payvo Auth will look for
1756
+ * the following environment variables:
1757
+ * process.env.PAYVO_AUTH_SECRET,
1758
+ * process.env.AUTH_SECRET
1759
+ * If none of these environment
1760
+ * variables are set,
1761
+ * it will default to
1762
+ * "payvo-auth-secret-123456789".
1763
+ *
1764
+ * on production if it's not set
1765
+ * it will throw an error.
1766
+ *
1767
+ * you can generate a good secret
1768
+ * using the following command:
1769
+ * @example
1770
+ * ```bash
1771
+ * openssl rand -base64 32
1772
+ * ```
1773
+ */
1774
+ secret?: string | undefined;
1775
+ /**
1776
+ * Database configuration
1777
+ */
1778
+ database?: (PostgresPool | MysqlPool | SqliteDatabase | Dialect | DBAdapterInstance | Database | DatabaseSync | {
1779
+ dialect: Dialect;
1780
+ type: KyselyDatabaseType;
1781
+ /**
1782
+ * casing for table names
1783
+ *
1784
+ * @default "camel"
1785
+ */
1786
+ casing?: "snake" | "camel";
1787
+ /**
1788
+ * Enable debug logs for the adapter
1789
+ *
1790
+ * @default false
1791
+ */
1792
+ debugLogs?: DBAdapterDebugLogOption;
1793
+ /**
1794
+ * Whether to execute multiple operations in a transaction.
1795
+ * If the database doesn't support transactions,
1796
+ * set this to `false` and operations will be executed sequentially.
1797
+ * @default true
1798
+ */
1799
+ transaction?: boolean;
1800
+ } | {
1801
+ /**
1802
+ * Kysely instance
1803
+ */
1804
+ db: Kysely<any>;
1805
+ /**
1806
+ * Database type between postgres, mysql and sqlite
1807
+ */
1808
+ type: KyselyDatabaseType;
1809
+ /**
1810
+ * casing for table names
1811
+ *
1812
+ * @default "camel"
1813
+ */
1814
+ casing?: "snake" | "camel";
1815
+ /**
1816
+ * Enable debug logs for the adapter
1817
+ *
1818
+ * @default false
1819
+ */
1820
+ debugLogs?: DBAdapterDebugLogOption;
1821
+ /**
1822
+ * Whether to execute multiple operations in a transaction.
1823
+ * If the database doesn't support transactions,
1824
+ * set this to `false` and operations will be executed sequentially.
1825
+ * @default true
1826
+ */
1827
+ transaction?: boolean;
1828
+ }) | undefined;
1829
+ /**
1830
+ * Secondary storage configuration
1831
+ *
1832
+ * This is used to store session and rate limit data.
1833
+ */
1834
+ secondaryStorage?: SecondaryStorage | undefined;
1835
+ /**
1836
+ * Email verification configuration
1837
+ */
1838
+ emailVerification?: {
1839
+ /**
1840
+ * Send a verification email
1841
+ * @param data the data object
1842
+ * @param request the request object
1843
+ */
1844
+ sendVerificationEmail?: (
1845
+ /**
1846
+ * @param user the user to send the
1847
+ * verification email to
1848
+ * @param url the URL to send the verification email to
1849
+ * it contains the token as well
1850
+ * @param token the token to send the verification email to
1851
+ */
1852
+ data: {
1853
+ user: User;
1854
+ url: string;
1855
+ token: string;
1856
+ },
1857
+ /**
1858
+ * The request object
1859
+ */
1860
+ request?: Request) => Promise<void>;
1861
+ /**
1862
+ * Send a verification email automatically
1863
+ * after sign up
1864
+ *
1865
+ * @default false
1866
+ */
1867
+ sendOnSignUp?: boolean;
1868
+ /**
1869
+ * Send a verification email automatically
1870
+ * on sign in when the user's email is not verified
1871
+ *
1872
+ * @default false
1873
+ */
1874
+ sendOnSignIn?: boolean;
1875
+ /**
1876
+ * Auto signin the user after they verify their email
1877
+ */
1878
+ autoSignInAfterVerification?: boolean;
1879
+ /**
1880
+ * Number of seconds the verification token is
1881
+ * valid for.
1882
+ * @default 3600 seconds (1 hour)
1883
+ */
1884
+ expiresIn?: number;
1885
+ /**
1886
+ * A function that is called when a user verifies their email
1887
+ * @param user the user that verified their email
1888
+ * @param request the request object
1889
+ */
1890
+ onEmailVerification?: (user: User, request?: Request) => Promise<void>;
1891
+ /**
1892
+ * A function that is called when a user's email is updated to verified
1893
+ * @param user the user that verified their email
1894
+ * @param request the request object
1895
+ */
1896
+ afterEmailVerification?: (user: User, request?: Request) => Promise<void>;
1897
+ } | undefined;
1898
+ /**
1899
+ * Email and password authentication
1900
+ */
1901
+ emailAndPassword?: {
1902
+ /**
1903
+ * Enable email and password authentication
1904
+ *
1905
+ * @default false
1906
+ */
1907
+ enabled: boolean;
1908
+ /**
1909
+ * Disable email and password sign up
1910
+ *
1911
+ * @default false
1912
+ */
1913
+ disableSignUp?: boolean;
1914
+ /**
1915
+ * Require email verification before a session
1916
+ * can be created for the user.
1917
+ *
1918
+ * if the user is not verified, the user will not be able to sign in
1919
+ * and on sign in attempts, the user will be prompted to verify their email.
1920
+ */
1921
+ requireEmailVerification?: boolean;
1922
+ /**
1923
+ * The maximum length of the password.
1924
+ *
1925
+ * @default 128
1926
+ */
1927
+ maxPasswordLength?: number;
1928
+ /**
1929
+ * The minimum length of the password.
1930
+ *
1931
+ * @default 8
1932
+ */
1933
+ minPasswordLength?: number;
1934
+ /**
1935
+ * send reset password
1936
+ */
1937
+ sendResetPassword?: (
1938
+ /**
1939
+ * @param user the user to send the
1940
+ * reset password email to
1941
+ * @param url the URL to send the reset password email to
1942
+ * @param token the token to send to the user (could be used instead of sending the url
1943
+ * if you need to redirect the user to custom route)
1944
+ */
1945
+ data: {
1946
+ user: User;
1947
+ url: string;
1948
+ token: string;
1949
+ },
1950
+ /**
1951
+ * The request object
1952
+ */
1953
+ request?: Request) => Promise<void>;
1954
+ /**
1955
+ * Number of seconds the reset password token is
1956
+ * valid for.
1957
+ * @default 1 hour (60 * 60)
1958
+ */
1959
+ resetPasswordTokenExpiresIn?: number;
1960
+ /**
1961
+ * A callback function that is triggered
1962
+ * when a user's password is changed successfully.
1963
+ */
1964
+ onPasswordReset?: (data: {
1965
+ user: User;
1966
+ }, request?: Request) => Promise<void>;
1967
+ /**
1968
+ * Password hashing and verification
1969
+ *
1970
+ * By default Scrypt is used for password hashing and
1971
+ * verification. You can provide your own hashing and
1972
+ * verification function. if you want to use a
1973
+ * different algorithm.
1974
+ */
1975
+ password?: {
1976
+ hash?: (password: string) => Promise<string>;
1977
+ verify?: (data: {
1978
+ hash: string;
1979
+ password: string;
1980
+ }) => Promise<boolean>;
1981
+ };
1982
+ /**
1983
+ * Automatically sign in the user after sign up
1984
+ *
1985
+ * @default true
1986
+ */
1987
+ autoSignIn?: boolean;
1988
+ /**
1989
+ * Whether to revoke all other sessions when resetting password
1990
+ * @default false
1991
+ */
1992
+ revokeSessionsOnPasswordReset?: boolean;
1993
+ } | undefined;
1994
+ /**
1995
+ * list of social providers
1996
+ */
1997
+ socialProviders?: SocialProviders | undefined;
1998
+ /**
1999
+ * List of Payvo Auth plugins
2000
+ */
2001
+ plugins?: ([] | PayvoAuthPlugin[]) | undefined;
2002
+ /**
2003
+ * User configuration
2004
+ */
2005
+ user?: {
2006
+ /**
2007
+ * The model name for the user. Defaults to "user".
2008
+ */
2009
+ modelName?: string;
2010
+ /**
2011
+ * Map fields
2012
+ *
2013
+ * @example
2014
+ * ```ts
2015
+ * {
2016
+ * userId: "user_id"
2017
+ * }
2018
+ * ```
2019
+ */
2020
+ fields?: Partial<Record<keyof OmitId<User>, string>>;
2021
+ /**
2022
+ * Additional fields for the user
2023
+ */
2024
+ additionalFields?: {
2025
+ [key: string]: DBFieldAttribute;
2026
+ };
2027
+ /**
2028
+ * Changing email configuration
2029
+ */
2030
+ changeEmail?: {
2031
+ /**
2032
+ * Enable changing email
2033
+ * @default false
2034
+ */
2035
+ enabled: boolean;
2036
+ /**
2037
+ * Send a verification email when the user changes their email.
2038
+ * @param data the data object
2039
+ * @param request the request object
2040
+ */
2041
+ sendChangeEmailVerification?: (data: {
2042
+ user: User;
2043
+ newEmail: string;
2044
+ url: string;
2045
+ token: string;
2046
+ }, request?: Request) => Promise<void>;
2047
+ };
2048
+ /**
2049
+ * User deletion configuration
2050
+ */
2051
+ deleteUser?: {
2052
+ /**
2053
+ * Enable user deletion
2054
+ */
2055
+ enabled?: boolean;
2056
+ /**
2057
+ * Send a verification email when the user deletes their account.
2058
+ *
2059
+ * if this is not set, the user will be deleted immediately.
2060
+ * @param data the data object
2061
+ * @param request the request object
2062
+ */
2063
+ sendDeleteAccountVerification?: (data: {
2064
+ user: User;
2065
+ url: string;
2066
+ token: string;
2067
+ }, request?: Request) => Promise<void>;
2068
+ /**
2069
+ * A function that is called before a user is deleted.
2070
+ *
2071
+ * to interrupt with error you can throw `APIError`
2072
+ */
2073
+ beforeDelete?: (user: User, request?: Request) => Promise<void>;
2074
+ /**
2075
+ * A function that is called after a user is deleted.
2076
+ *
2077
+ * This is useful for cleaning up user data
2078
+ */
2079
+ afterDelete?: (user: User, request?: Request) => Promise<void>;
2080
+ /**
2081
+ * The expiration time for the delete token.
2082
+ *
2083
+ * @default 1 day (60 * 60 * 24) in seconds
2084
+ */
2085
+ deleteTokenExpiresIn?: number;
2086
+ };
2087
+ } | undefined;
2088
+ session?: {
2089
+ /**
2090
+ * The model name for the session.
2091
+ *
2092
+ * @default "session"
2093
+ */
2094
+ modelName?: string;
2095
+ /**
2096
+ * Map fields
2097
+ *
2098
+ * @example
2099
+ * ```ts
2100
+ * {
2101
+ * userId: "user_id"
2102
+ * }
2103
+ */
2104
+ fields?: Partial<Record<keyof OmitId<Session>, string>>;
2105
+ /**
2106
+ * Expiration time for the session token. The value
2107
+ * should be in seconds.
2108
+ * @default 7 days (60 * 60 * 24 * 7)
2109
+ */
2110
+ expiresIn?: number;
2111
+ /**
2112
+ * How often the session should be refreshed. The value
2113
+ * should be in seconds.
2114
+ * If set 0 the session will be refreshed every time it is used.
2115
+ * @default 1 day (60 * 60 * 24)
2116
+ */
2117
+ updateAge?: number;
2118
+ /**
2119
+ * Disable session refresh so that the session is not updated
2120
+ * regardless of the `updateAge` option.
2121
+ *
2122
+ * @default false
2123
+ */
2124
+ disableSessionRefresh?: boolean;
2125
+ /**
2126
+ * Additional fields for the session
2127
+ */
2128
+ additionalFields?: {
2129
+ [key: string]: DBFieldAttribute;
2130
+ };
2131
+ /**
2132
+ * By default if secondary storage is provided
2133
+ * the session is stored in the secondary storage.
2134
+ *
2135
+ * Set this to true to store the session in the database
2136
+ * as well.
2137
+ *
2138
+ * Reads are always done from the secondary storage.
2139
+ *
2140
+ * @default false
2141
+ */
2142
+ storeSessionInDatabase?: boolean;
2143
+ /**
2144
+ * By default, sessions are deleted from the database when secondary storage
2145
+ * is provided when session is revoked.
2146
+ *
2147
+ * Set this to true to preserve session records in the database,
2148
+ * even if they are deleted from the secondary storage.
2149
+ *
2150
+ * @default false
2151
+ */
2152
+ preserveSessionInDatabase?: boolean;
2153
+ /**
2154
+ * Enable caching session in cookie
2155
+ */
2156
+ cookieCache?: {
2157
+ /**
2158
+ * max age of the cookie
2159
+ * @default 5 minutes (5 * 60)
2160
+ */
2161
+ maxAge?: number;
2162
+ /**
2163
+ * Enable caching session in cookie
2164
+ * @default false
2165
+ */
2166
+ enabled?: boolean;
2167
+ /**
2168
+ * Strategy for encoding/decoding cookie cache
2169
+ *
2170
+ * - "compact": Uses base64url encoding with HMAC-SHA256 signature (compact format, no JWT spec overhead)
2171
+ * - "jwt": Uses JWT with HMAC signature (no encryption, follows JWT spec)
2172
+ * - "jwe": Uses JWE (JSON Web Encryption) with A256CBC-HS512 and HKDF key derivation for secure encrypted tokens
2173
+ *
2174
+ * @default "compact"
2175
+ */
2176
+ strategy?: "compact" | "jwt" | "jwe";
2177
+ /**
2178
+ * Controls stateless cookie cache refresh behavior.
2179
+ *
2180
+ * When enabled, the cookie cache will be automatically refreshed before expiry
2181
+ * WITHOUT querying the database. This is essential for fully stateless or DB-less scenarios.
2182
+ *
2183
+ * - `false`: Disable automatic refresh. Cache is only invalidated when it reaches maxAge expiry.
2184
+ * - `true`: Enable automatic refresh with default settings (refreshes when 80% of maxAge is reached).
2185
+ * - `object`: Custom refresh configuration with either `updateAge` or `shouldRefresh` function
2186
+ *
2187
+ * Note: When the cache expires (reaches maxAge), it will attempt to fetch from database if available.
2188
+ * The refreshCache option is specifically for refreshing BEFORE expiry in a stateless manner.
2189
+ *
2190
+ * @default false
2191
+ */
2192
+ refreshCache?: boolean | {
2193
+ /**
2194
+ * Time in seconds before expiry when the cache should be refreshed.
2195
+ * For example, if maxAge is 300 (5 minutes) and updateAge is 60,
2196
+ * the cache will be refreshed when it has 60 seconds left before expiry.
2197
+ *
2198
+ * @default 20% of maxAge
2199
+ */
2200
+ updateAge?: number;
2201
+ };
2202
+ /**
2203
+ * Version of the cookie cache
2204
+ *
2205
+ * If a cookie cache version is changed, all existing cookie caches with the old version
2206
+ * will be invalidated.
2207
+ *
2208
+ * It can be a string or a function that returns a string or a promise that returns a string.
2209
+ * If it's a function, it will be called with the session and user data
2210
+ *
2211
+ * @default "1"
2212
+ */
2213
+ version?: string | ((session: Session & Record<string, any>, user: User & Record<string, any>) => string) | ((session: Session & Record<string, any>, user: User & Record<string, any>) => Promise<string>);
2214
+ };
2215
+ /**
2216
+ * The age of the session to consider it fresh.
2217
+ *
2218
+ * This is used to check if the session is fresh
2219
+ * for sensitive operations. (e.g. deleting an account)
2220
+ *
2221
+ * If the session is not fresh, the user should be prompted
2222
+ * to sign in again.
2223
+ *
2224
+ * If set to 0, the session will be considered fresh every time. (⚠︎ not recommended)
2225
+ *
2226
+ * @default 1 day (60 * 60 * 24)
2227
+ */
2228
+ freshAge?: number;
2229
+ } | undefined;
2230
+ account?: {
2231
+ /**
2232
+ * The model name for the account. Defaults to "account".
2233
+ */
2234
+ modelName?: string;
2235
+ /**
2236
+ * Map fields
2237
+ */
2238
+ fields?: Partial<Record<keyof OmitId<Account>, string>>;
2239
+ /**
2240
+ * Additional fields for the account
2241
+ */
2242
+ additionalFields?: {
2243
+ [key: string]: DBFieldAttribute;
2244
+ };
2245
+ /**
2246
+ * When enabled (true), the user account data (accessToken, idToken, refreshToken, etc.)
2247
+ * will be updated on sign in with the latest data from the provider.
2248
+ *
2249
+ * @default true
2250
+ */
2251
+ updateAccountOnSignIn?: boolean;
2252
+ /**
2253
+ * Configuration for account linking.
2254
+ */
2255
+ accountLinking?: {
2256
+ /**
2257
+ * Enable account linking
2258
+ *
2259
+ * @default true
2260
+ */
2261
+ enabled?: boolean;
2262
+ /**
2263
+ * List of trusted providers
2264
+ */
2265
+ trustedProviders?: Array<LiteralUnion<SocialProviderList[number] | "email-password", string>>;
2266
+ /**
2267
+ * If enabled (true), this will allow users to manually linking accounts with different email addresses than the main user.
2268
+ *
2269
+ * @default false
2270
+ *
2271
+ * ⚠️ Warning: enabling this might lead to account takeovers, so proceed with caution.
2272
+ */
2273
+ allowDifferentEmails?: boolean;
2274
+ /**
2275
+ * If enabled (true), this will allow users to unlink all accounts.
2276
+ *
2277
+ * @default false
2278
+ */
2279
+ allowUnlinkingAll?: boolean;
2280
+ /**
2281
+ * If enabled (true), this will update the user information based on the newly linked account
2282
+ *
2283
+ * @default false
2284
+ */
2285
+ updateUserInfoOnLink?: boolean;
2286
+ };
2287
+ /**
2288
+ * Encrypt OAuth tokens
2289
+ *
2290
+ * By default, OAuth tokens (access tokens, refresh tokens, ID tokens) are stored in plain text in the database.
2291
+ * This poses a security risk if your database is compromised, as attackers could gain access to user accounts
2292
+ * on external services.
2293
+ *
2294
+ * When enabled, tokens are encrypted using AES-256-GCM before storage, providing protection against:
2295
+ * - Database breaches and unauthorized access to raw token data
2296
+ * - Internal threats from database administrators or compromised credentials
2297
+ * - Token exposure in database backups and logs
2298
+ * @default false
2299
+ */
2300
+ encryptOAuthTokens?: boolean;
2301
+ } | undefined;
2302
+ /**
2303
+ * Verification configuration
2304
+ */
2305
+ verification?: {
2306
+ /**
2307
+ * Change the modelName of the verification table
2308
+ */
2309
+ modelName?: string;
2310
+ /**
2311
+ * Map verification fields
2312
+ */
2313
+ fields?: Partial<Record<keyof OmitId<Verification>, string>>;
2314
+ /**
2315
+ * disable cleaning up expired values when a verification value is
2316
+ * fetched
2317
+ */
2318
+ disableCleanup?: boolean;
2319
+ } | undefined;
2320
+ /**
2321
+ * List of trusted origins.
2322
+ */
2323
+ trustedOrigins?: (string[] | ((request: Request) => string[] | Promise<string[]>)) | undefined;
2324
+ /**
2325
+ * Rate limiting configuration
2326
+ */
2327
+ rateLimit?: PayvoAuthRateLimitOptions | undefined;
2328
+ /**
2329
+ * Advanced options
2330
+ */
2331
+ advanced?: (PayvoAuthAdvancedOptions & {
2332
+ /**
2333
+ * @deprecated Please use `database.generateId` instead.
2334
+ */
2335
+ generateId?: never;
2336
+ }) | undefined;
2337
+ logger?: Logger | undefined;
2338
+ /**
2339
+ * allows you to define custom hooks that can be
2340
+ * executed during lifecycle of core database
2341
+ * operations.
2342
+ */
2343
+ databaseHooks?: {
2344
+ /**
2345
+ * User hooks
2346
+ */
2347
+ user?: {
2348
+ create?: {
2349
+ /**
2350
+ * Hook that is called before a user is created.
2351
+ * if the hook returns false, the user will not be created.
2352
+ * If the hook returns an object, it'll be used instead of the original data
2353
+ */
2354
+ before?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
2355
+ data: Optional<User> & Record<string, any>;
2356
+ }>;
2357
+ /**
2358
+ * Hook that is called after a user is created.
2359
+ */
2360
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2361
+ };
2362
+ update?: {
2363
+ /**
2364
+ * Hook that is called before a user is updated.
2365
+ * if the hook returns false, the user will not be updated.
2366
+ * If the hook returns an object, it'll be used instead of the original data
2367
+ */
2368
+ before?: (user: Partial<User> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
2369
+ data: Optional<User & Record<string, any>>;
2370
+ }>;
2371
+ /**
2372
+ * Hook that is called after a user is updated.
2373
+ */
2374
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2375
+ };
2376
+ delete?: {
2377
+ /**
2378
+ * Hook that is called before a user is deleted.
2379
+ * if the hook returns false, the user will not be deleted.
2380
+ */
2381
+ before?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
2382
+ /**
2383
+ * Hook that is called after a user is deleted.
2384
+ */
2385
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2386
+ };
2387
+ };
2388
+ /**
2389
+ * Session Hook
2390
+ */
2391
+ session?: {
2392
+ create?: {
2393
+ /**
2394
+ * Hook that is called before a session is created.
2395
+ * if the hook returns false, the session will not be created.
2396
+ * If the hook returns an object, it'll be used instead of the original data
2397
+ */
2398
+ before?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
2399
+ data: Optional<Session> & Record<string, any>;
2400
+ }>;
2401
+ /**
2402
+ * Hook that is called after a session is created.
2403
+ */
2404
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2405
+ };
2406
+ /**
2407
+ * Update hook
2408
+ */
2409
+ update?: {
2410
+ /**
2411
+ * Hook that is called before a user is updated.
2412
+ * if the hook returns false, the session will not be updated.
2413
+ * If the hook returns an object, it'll be used instead of the original data
2414
+ */
2415
+ before?: (session: Partial<Session> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
2416
+ data: Optional<Session & Record<string, any>>;
2417
+ }>;
2418
+ /**
2419
+ * Hook that is called after a session is updated.
2420
+ */
2421
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2422
+ };
2423
+ delete?: {
2424
+ /**
2425
+ * Hook that is called before a session is deleted.
2426
+ * if the hook returns false, the session will not be deleted.
2427
+ */
2428
+ before?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
2429
+ /**
2430
+ * Hook that is called after a session is deleted.
2431
+ */
2432
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2433
+ };
2434
+ };
2435
+ /**
2436
+ * Account Hook
2437
+ */
2438
+ account?: {
2439
+ create?: {
2440
+ /**
2441
+ * Hook that is called before a account is created.
2442
+ * If the hook returns false, the account will not be created.
2443
+ * If the hook returns an object, it'll be used instead of the original data
2444
+ */
2445
+ before?: (account: Account, context?: GenericEndpointContext) => Promise<boolean | void | {
2446
+ data: Optional<Account> & Record<string, any>;
2447
+ }>;
2448
+ /**
2449
+ * Hook that is called after a account is created.
2450
+ */
2451
+ after?: (account: Account, context?: GenericEndpointContext) => Promise<void>;
2452
+ };
2453
+ /**
2454
+ * Update hook
2455
+ */
2456
+ update?: {
2457
+ /**
2458
+ * Hook that is called before a account is update.
2459
+ * If the hook returns false, the user will not be updated.
2460
+ * If the hook returns an object, it'll be used instead of the original data
2461
+ */
2462
+ before?: (account: Partial<Account> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
2463
+ data: Optional<Account & Record<string, any>>;
2464
+ }>;
2465
+ /**
2466
+ * Hook that is called after a account is updated.
2467
+ */
2468
+ after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2469
+ };
2470
+ delete?: {
2471
+ /**
2472
+ * Hook that is called before an account is deleted.
2473
+ * if the hook returns false, the account will not be deleted.
2474
+ */
2475
+ before?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
2476
+ /**
2477
+ * Hook that is called after an account is deleted.
2478
+ */
2479
+ after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2480
+ };
2481
+ };
2482
+ /**
2483
+ * Verification Hook
2484
+ */
2485
+ verification?: {
2486
+ create?: {
2487
+ /**
2488
+ * Hook that is called before a verification is created.
2489
+ * if the hook returns false, the verification will not be created.
2490
+ * If the hook returns an object, it'll be used instead of the original data
2491
+ */
2492
+ before?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
2493
+ data: Optional<Verification> & Record<string, any>;
2494
+ }>;
2495
+ /**
2496
+ * Hook that is called after a verification is created.
2497
+ */
2498
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2499
+ };
2500
+ update?: {
2501
+ /**
2502
+ * Hook that is called before a verification is updated.
2503
+ * if the hook returns false, the verification will not be updated.
2504
+ * If the hook returns an object, it'll be used instead of the original data
2505
+ */
2506
+ before?: (verification: Partial<Verification> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
2507
+ data: Optional<Verification & Record<string, any>>;
2508
+ }>;
2509
+ /**
2510
+ * Hook that is called after a verification is updated.
2511
+ */
2512
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2513
+ };
2514
+ delete?: {
2515
+ /**
2516
+ * Hook that is called before a verification is deleted.
2517
+ * if the hook returns false, the verification will not be deleted.
2518
+ */
2519
+ before?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
2520
+ /**
2521
+ * Hook that is called after a verification is deleted.
2522
+ */
2523
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
2524
+ };
2525
+ };
2526
+ } | undefined;
2527
+ /**
2528
+ * API error handling
2529
+ */
2530
+ onAPIError?: {
2531
+ /**
2532
+ * Throw an error on API error
2533
+ *
2534
+ * @default false
2535
+ */
2536
+ throw?: boolean;
2537
+ /**
2538
+ * Custom error handler
2539
+ *
2540
+ * @param error
2541
+ * @param ctx - Auth context
2542
+ */
2543
+ onError?: (error: unknown, ctx: AuthContext) => void | Promise<void>;
2544
+ /**
2545
+ * The URL to redirect to on error
2546
+ *
2547
+ * When errorURL is provided, the error will be added to the URL as a query parameter
2548
+ * and the user will be redirected to the errorURL.
2549
+ *
2550
+ * @default - "/api/auth/error"
2551
+ */
2552
+ errorURL?: string;
2553
+ /**
2554
+ * Configure the default error page provided by Payvo-Auth
2555
+ * Start your dev server and go to /api/auth/error to see the error page.
2556
+ */
2557
+ customizeDefaultErrorPage?: {
2558
+ colors?: {
2559
+ background?: string;
2560
+ foreground?: string;
2561
+ primary?: string;
2562
+ primaryForeground?: string;
2563
+ mutedForeground?: string;
2564
+ border?: string;
2565
+ destructive?: string;
2566
+ titleBorder?: string;
2567
+ titleColor?: string;
2568
+ gridColor?: string;
2569
+ cardBackground?: string;
2570
+ cornerBorder?: string;
2571
+ };
2572
+ size?: {
2573
+ radiusSm?: string;
2574
+ radiusMd?: string;
2575
+ radiusLg?: string;
2576
+ textSm?: string;
2577
+ text2xl?: string;
2578
+ text4xl?: string;
2579
+ text6xl?: string;
2580
+ };
2581
+ font?: {
2582
+ defaultFamily?: string;
2583
+ monoFamily?: string;
2584
+ };
2585
+ disableTitleBorder?: boolean;
2586
+ disableCornerDecorations?: boolean;
2587
+ disableBackgroundGrid?: boolean;
2588
+ };
2589
+ } | undefined;
2590
+ /**
2591
+ * Hooks
2592
+ */
2593
+ hooks?: {
2594
+ /**
2595
+ * Before a request is processed
2596
+ */
2597
+ before?: AuthMiddleware;
2598
+ /**
2599
+ * After a request is processed
2600
+ */
2601
+ after?: AuthMiddleware;
2602
+ } | undefined;
2603
+ /**
2604
+ * Disabled paths
2605
+ *
2606
+ * Paths you want to disable.
2607
+ */
2608
+ disabledPaths?: string[] | undefined;
2609
+ /**
2610
+ * Telemetry configuration
2611
+ */
2612
+ telemetry?: {
2613
+ /**
2614
+ * Enable telemetry collection
2615
+ *
2616
+ * @default false
2617
+ */
2618
+ enabled?: boolean;
2619
+ /**
2620
+ * Enable debug mode
2621
+ *
2622
+ * @default false
2623
+ */
2624
+ debug?: boolean;
2625
+ } | undefined;
2626
+ };
2627
+ //#endregion
2628
+ //#region src/types/context.d.ts
2629
+ type GenericEndpointContext<Options extends PayvoAuthOptions = PayvoAuthOptions> = EndpointContext<string, any> & {
2630
+ context: AuthContext<Options>;
2631
+ };
2632
+ interface InternalAdapter<Options extends PayvoAuthOptions = PayvoAuthOptions> {
2633
+ createOAuthUser(user: Omit<User, "id" | "createdAt" | "updatedAt">, account: Omit<Account, "userId" | "id" | "createdAt" | "updatedAt"> & Partial<Account>): Promise<{
2634
+ user: User;
2635
+ account: Account;
2636
+ }>;
2637
+ createUser<T extends Record<string, any>>(user: Omit<User, "id" | "createdAt" | "updatedAt" | "emailVerified"> & Partial<User> & Record<string, any>): Promise<T & User>;
2638
+ createAccount<T extends Record<string, any>>(account: Omit<Account, "id" | "createdAt" | "updatedAt"> & Partial<Account> & T): Promise<T & Account>;
2639
+ listSessions(userId: string): Promise<Session[]>;
2640
+ listUsers(limit?: number | undefined, offset?: number | undefined, sortBy?: {
2641
+ field: string;
2642
+ direction: "asc" | "desc";
2643
+ } | undefined, where?: Where[] | undefined): Promise<User[]>;
2644
+ countTotalUsers(where?: Where[] | undefined): Promise<number>;
2645
+ deleteUser(userId: string): Promise<void>;
2646
+ createSession(userId: string, dontRememberMe?: boolean | undefined, override?: (Partial<Session> & Record<string, any>) | undefined, overrideAll?: boolean | undefined): Promise<Session>;
2647
+ findSession(token: string): Promise<{
2648
+ session: Session & Record<string, any>;
2649
+ user: User & Record<string, any>;
2650
+ } | null>;
2651
+ findSessions(sessionTokens: string[]): Promise<{
2652
+ session: Session;
2653
+ user: User;
2654
+ }[]>;
2655
+ updateSession(sessionToken: string, session: Partial<Session> & Record<string, any>): Promise<Session | null>;
2656
+ deleteSession(token: string): Promise<void>;
2657
+ deleteAccounts(userId: string): Promise<void>;
2658
+ deleteAccount(accountId: string): Promise<void>;
2659
+ deleteSessions(userIdOrSessionTokens: string | string[]): Promise<void>;
2660
+ findOAuthUser(email: string, accountId: string, providerId: string): Promise<{
2661
+ user: User;
2662
+ accounts: Account[];
2663
+ } | null>;
2664
+ findUserByEmail(email: string, options?: {
2665
+ includeAccounts: boolean;
2666
+ } | undefined): Promise<{
2667
+ user: User;
2668
+ accounts: Account[];
2669
+ } | null>;
2670
+ findUserById(userId: string): Promise<User | null>;
2671
+ linkAccount(account: Omit<Account, "id" | "createdAt" | "updatedAt"> & Partial<Account>): Promise<Account>;
2672
+ updateUser(userId: string, data: Partial<User> & Record<string, any>): Promise<any>;
2673
+ updateUserByEmail(email: string, data: Partial<User & Record<string, any>>): Promise<User>;
2674
+ updatePassword(userId: string, password: string): Promise<void>;
2675
+ findAccounts(userId: string): Promise<Account[]>;
2676
+ findAccount(accountId: string): Promise<Account | null>;
2677
+ findAccountByProviderId(accountId: string, providerId: string): Promise<Account | null>;
2678
+ findAccountByUserId(userId: string): Promise<Account[]>;
2679
+ updateAccount(id: string, data: Partial<Account>): Promise<Account>;
2680
+ createVerificationValue(data: Omit<Verification, "createdAt" | "id" | "updatedAt"> & Partial<Verification>): Promise<Verification>;
2681
+ findVerificationValue(identifier: string): Promise<Verification | null>;
2682
+ deleteVerificationValue(id: string): Promise<void>;
2683
+ deleteVerificationByIdentifier(identifier: string): Promise<void>;
2684
+ updateVerificationValue(id: string, data: Partial<Verification>): Promise<Verification>;
2685
+ }
2686
+ type CreateCookieGetterFn = (cookieName: string, overrideAttributes?: Partial<CookieOptions> | undefined) => {
2687
+ name: string;
2688
+ attributes: CookieOptions;
2689
+ };
2690
+ type CheckPasswordFn<Options extends PayvoAuthOptions = PayvoAuthOptions> = (userId: string, ctx: GenericEndpointContext<Options>) => Promise<boolean>;
2691
+ type AuthContext<Options extends PayvoAuthOptions = PayvoAuthOptions> = {
2692
+ options: Options;
2693
+ appName: string;
2694
+ baseURL: string;
2695
+ trustedOrigins: string[];
2696
+ oauthConfig: {
2697
+ /**
2698
+ * This is dangerous and should only be used in dev or staging environments.
2699
+ */
2700
+ skipStateCookieCheck?: boolean | undefined;
2701
+ /**
2702
+ * Strategy for storing OAuth state
2703
+ *
2704
+ * - "cookie": Store state in an encrypted cookie (stateless)
2705
+ * - "database": Store state in the database
2706
+ *
2707
+ * @default "cookie"
2708
+ */
2709
+ storeStateStrategy: "database" | "cookie";
2710
+ };
2711
+ /**
2712
+ * New session that will be set after the request
2713
+ * meaning: there is a `set-cookie` header that will set
2714
+ * the session cookie. This is the fetched session. And it's set
2715
+ * by `setNewSession` method.
2716
+ */
2717
+ newSession: {
2718
+ session: Session & Record<string, any>;
2719
+ user: User & Record<string, any>;
2720
+ } | null;
2721
+ session: {
2722
+ session: Session & Record<string, any>;
2723
+ user: User & Record<string, any>;
2724
+ } | null;
2725
+ setNewSession: (session: {
2726
+ session: Session & Record<string, any>;
2727
+ user: User & Record<string, any>;
2728
+ } | null) => void;
2729
+ socialProviders: OAuthProvider[];
2730
+ authCookies: PayvoAuthCookies;
2731
+ logger: ReturnType<typeof createLogger>;
2732
+ rateLimit: {
2733
+ enabled: boolean;
2734
+ window: number;
2735
+ max: number;
2736
+ storage: "memory" | "database" | "secondary-storage";
2737
+ } & PayvoAuthRateLimitOptions;
2738
+ adapter: DBAdapter<Options>;
2739
+ internalAdapter: InternalAdapter<Options>;
2740
+ createAuthCookie: CreateCookieGetterFn;
2741
+ secret: string;
2742
+ sessionConfig: {
2743
+ updateAge: number;
2744
+ expiresIn: number;
2745
+ freshAge: number;
2746
+ cookieRefreshCache: false | {
2747
+ enabled: true;
2748
+ updateAge: number;
2749
+ };
2750
+ };
2751
+ generateId: (options: {
2752
+ model: LiteralUnion<DBPreservedModels, string>;
2753
+ size?: number | undefined;
2754
+ }) => string | false;
2755
+ secondaryStorage: SecondaryStorage | undefined;
2756
+ password: {
2757
+ hash: (password: string) => Promise<string>;
2758
+ verify: (data: {
2759
+ password: string;
2760
+ hash: string;
2761
+ }) => Promise<boolean>;
2762
+ config: {
2763
+ minPasswordLength: number;
2764
+ maxPasswordLength: number;
2765
+ };
2766
+ checkPassword: CheckPasswordFn<Options>;
2767
+ };
2768
+ tables: PayvoAuthDBSchema;
2769
+ runMigrations: () => Promise<void>;
2770
+ publishTelemetry: (event: {
2771
+ type: string;
2772
+ anonymousId?: string | undefined;
2773
+ payload: Record<string, any>;
2774
+ }) => Promise<void>;
2775
+ /**
2776
+ * This skips the origin check for all requests.
2777
+ *
2778
+ * set to true by default for `test` environments and `false`
2779
+ * for other environments.
2780
+ *
2781
+ * It's inferred from the `options.advanced?.disableCSRFCheck`
2782
+ * option or `options.advanced?.disableOriginCheck` option.
2783
+ *
2784
+ * @default false
2785
+ */
2786
+ skipOriginCheck: boolean;
2787
+ /**
2788
+ * This skips the CSRF check for all requests.
2789
+ *
2790
+ * This is inferred from the `options.advanced?.
2791
+ * disableCSRFCheck` option.
2792
+ *
2793
+ * @default false
2794
+ */
2795
+ skipCSRFCheck: boolean;
2796
+ };
2797
+ //#endregion
2798
+ //#region src/types/plugin-client.d.ts
2799
+ interface ClientStore {
2800
+ notify: (signal: string) => void;
2801
+ listen: (signal: string, listener: () => void) => void;
2802
+ atoms: Record<string, WritableAtom<any>>;
2803
+ }
2804
+ type ClientAtomListener = {
2805
+ matcher: (path: string) => boolean;
2806
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
2807
+ };
2808
+ interface RevalidateOptions {
2809
+ /**
2810
+ * A time interval (in seconds) after which the session will be re-fetched.
2811
+ * If set to `0` (default), the session is not polled.
2812
+ *
2813
+ * This helps prevent session expiry during idle periods by periodically
2814
+ * refreshing the session.
2815
+ *
2816
+ * @default 0
2817
+ */
2818
+ refetchInterval?: number | undefined;
2819
+ /**
2820
+ * Automatically refetch the session when the user switches back to the window/tab.
2821
+ * This option activates this behavior if set to `true` (default).
2822
+ *
2823
+ * Prevents expired sessions when users switch tabs and come back later.
2824
+ *
2825
+ * @default true
2826
+ */
2827
+ refetchOnWindowFocus?: boolean | undefined;
2828
+ /**
2829
+ * Set to `false` to stop polling when the device has no internet access
2830
+ * (determined by `navigator.onLine`).
2831
+ *
2832
+ * @default false
2833
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine
2834
+ */
2835
+ refetchWhenOffline?: boolean | undefined;
2836
+ }
2837
+ interface PayvoAuthClientOptions {
2838
+ fetchOptions?: BetterFetchOption | undefined;
2839
+ plugins?: PayvoAuthClientPlugin[] | undefined;
2840
+ baseURL?: string | undefined;
2841
+ basePath?: string | undefined;
2842
+ disableDefaultFetchPlugins?: boolean | undefined;
2843
+ $InferAuth?: PayvoAuthOptions | undefined;
2844
+ sessionOptions?: RevalidateOptions | undefined;
2845
+ }
2846
+ interface PayvoAuthClientPlugin {
2847
+ id: LiteralString;
2848
+ /**
2849
+ * only used for type inference. don't pass the
2850
+ * actual plugin
2851
+ */
2852
+ $InferServerPlugin?: PayvoAuthPlugin | undefined;
2853
+ /**
2854
+ * Custom actions
2855
+ */
2856
+ getActions?: ($fetch: BetterFetch, $store: ClientStore,
2857
+ /**
2858
+ * payvo-auth client options
2859
+ */
2860
+ options: PayvoAuthClientOptions | undefined) => Record<string, any>;
2861
+ /**
2862
+ * State atoms that'll be resolved by each framework
2863
+ * auth store.
2864
+ */
2865
+ getAtoms?: (($fetch: BetterFetch) => Record<string, Atom<any>>) | undefined;
2866
+ /**
2867
+ * specify path methods for server plugin inferred
2868
+ * endpoints to force a specific method.
2869
+ */
2870
+ pathMethods?: Record<string, "POST" | "GET"> | undefined;
2871
+ /**
2872
+ * Better fetch plugins
2873
+ */
2874
+ fetchPlugins?: BetterFetchPlugin[] | undefined;
2875
+ /**
2876
+ * a list of recaller based on a matcher function.
2877
+ * The signal name needs to match a signal in this
2878
+ * plugin or any plugin the user might have added.
2879
+ */
2880
+ atomListeners?: ClientAtomListener[] | undefined;
2881
+ }
2882
+ //#endregion
2883
+ //#region src/api/index.d.ts
2884
+ declare const optionsMiddleware: <InputCtx extends better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>>(inputContext: InputCtx) => Promise<AuthContext>;
2885
+ declare const createAuthMiddleware: {
2886
+ <Options extends better_call0.MiddlewareOptions, R>(options: Options, handler: (ctx: better_call0.MiddlewareContext<Options, AuthContext & {
2887
+ returned?: unknown | undefined;
2888
+ responseHeaders?: Headers | undefined;
2889
+ }>) => Promise<R>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R>;
2890
+ <Options extends better_call0.MiddlewareOptions, R_1>(handler: (ctx: better_call0.MiddlewareContext<Options, AuthContext & {
2891
+ returned?: unknown | undefined;
2892
+ responseHeaders?: Headers | undefined;
2893
+ }>) => Promise<R_1>): (inputContext: better_call0.MiddlewareInputContext<Options>) => Promise<R_1>;
2894
+ };
2895
+ declare const createAuthEndpoint: <Path extends string, Opts extends EndpointOptions, R>(path: Path, options: Opts, handler: (ctx: EndpointContext<Path, Opts, AuthContext>) => Promise<R>) => {
2896
+ <AsResponse extends boolean = false, ReturnHeaders extends boolean = false>(...inputCtx: better_call0.HasRequiredKeys<better_call0.InputContext<Path, Opts & {
2897
+ use: any[];
2898
+ }>> extends true ? [better_call0.InferBodyInput<Opts & {
2899
+ use: any[];
2900
+ }, (Opts & {
2901
+ use: any[];
2902
+ })["metadata"] extends {
2903
+ $Infer: {
2904
+ body: infer B;
2905
+ };
2906
+ } ? B : (Opts & {
2907
+ use: any[];
2908
+ })["body"] extends better_call0.StandardSchemaV1<unknown, unknown> ? better_call0.StandardSchemaV1.InferInput<(Opts & {
2909
+ use: any[];
2910
+ })["body"]> : undefined> & better_call0.InferInputMethod<Opts & {
2911
+ use: any[];
2912
+ }, (Opts & {
2913
+ use: any[];
2914
+ })["method"] extends any[] ? (Opts & {
2915
+ use: any[];
2916
+ })["method"][number] : (Opts & {
2917
+ use: any[];
2918
+ })["method"] extends "*" ? better_call0.HTTPMethod : (Opts & {
2919
+ use: any[];
2920
+ })["method"] | undefined> & better_call0.InferQueryInput<Opts & {
2921
+ use: any[];
2922
+ }, (Opts & {
2923
+ use: any[];
2924
+ })["metadata"] extends {
2925
+ $Infer: {
2926
+ query: infer Query;
2927
+ };
2928
+ } ? Query : (Opts & {
2929
+ use: any[];
2930
+ })["query"] extends better_call0.StandardSchemaV1<unknown, unknown> ? better_call0.StandardSchemaV1.InferInput<(Opts & {
2931
+ use: any[];
2932
+ })["query"]> : Record<string, any> | undefined> & better_call0.InferParamInput<Path> & better_call0.InferRequestInput<Opts & {
2933
+ use: any[];
2934
+ }> & better_call0.InferHeadersInput<Opts & {
2935
+ use: any[];
2936
+ }> & {
2937
+ asResponse?: boolean;
2938
+ returnHeaders?: boolean;
2939
+ use?: better_call0.Middleware[];
2940
+ path?: string;
2941
+ } & {
2942
+ asResponse?: AsResponse | undefined;
2943
+ returnHeaders?: ReturnHeaders | undefined;
2944
+ }] : [((better_call0.InferBodyInput<Opts & {
2945
+ use: any[];
2946
+ }, (Opts & {
2947
+ use: any[];
2948
+ })["metadata"] extends {
2949
+ $Infer: {
2950
+ body: infer B;
2951
+ };
2952
+ } ? B : (Opts & {
2953
+ use: any[];
2954
+ })["body"] extends better_call0.StandardSchemaV1<unknown, unknown> ? better_call0.StandardSchemaV1.InferInput<(Opts & {
2955
+ use: any[];
2956
+ })["body"]> : undefined> & better_call0.InferInputMethod<Opts & {
2957
+ use: any[];
2958
+ }, (Opts & {
2959
+ use: any[];
2960
+ })["method"] extends any[] ? (Opts & {
2961
+ use: any[];
2962
+ })["method"][number] : (Opts & {
2963
+ use: any[];
2964
+ })["method"] extends "*" ? better_call0.HTTPMethod : (Opts & {
2965
+ use: any[];
2966
+ })["method"] | undefined> & better_call0.InferQueryInput<Opts & {
2967
+ use: any[];
2968
+ }, (Opts & {
2969
+ use: any[];
2970
+ })["metadata"] extends {
2971
+ $Infer: {
2972
+ query: infer Query;
2973
+ };
2974
+ } ? Query : (Opts & {
2975
+ use: any[];
2976
+ })["query"] extends better_call0.StandardSchemaV1<unknown, unknown> ? better_call0.StandardSchemaV1.InferInput<(Opts & {
2977
+ use: any[];
2978
+ })["query"]> : Record<string, any> | undefined> & better_call0.InferParamInput<Path> & better_call0.InferRequestInput<Opts & {
2979
+ use: any[];
2980
+ }> & better_call0.InferHeadersInput<Opts & {
2981
+ use: any[];
2982
+ }> & {
2983
+ asResponse?: boolean;
2984
+ returnHeaders?: boolean;
2985
+ use?: better_call0.Middleware[];
2986
+ path?: string;
2987
+ } & {
2988
+ asResponse?: AsResponse | undefined;
2989
+ returnHeaders?: ReturnHeaders | undefined;
2990
+ }) | undefined)?]): Promise<[AsResponse] extends [true] ? Response : [ReturnHeaders] extends [true] ? {
2991
+ headers: Headers;
2992
+ response: R;
2993
+ } : R>;
2994
+ options: Opts & {
2995
+ use: any[];
2996
+ };
2997
+ path: Path;
2998
+ };
2999
+ type AuthEndpoint = ReturnType<typeof createAuthEndpoint>;
3000
+ type AuthMiddleware = ReturnType<typeof createAuthMiddleware>;
3001
+ //#endregion
3002
+ export { ProviderOptions as $, GithubProfile as A, DBPreservedModels as At, createAuthorizationCodeRequest as B, SocialProviders as C, rateLimitSchema as Ct, GoogleProfile as D, DBFieldAttribute as Dt, GoogleOptions as E, PayvoAuthPluginDBSchema as Et, LiteralUnion as F, createRefreshAccessTokenRequest as G, validateToken as H, Prettify as I, clientCredentialsToken as J, refreshAccessToken as K, Primitive as L, Awaitable$1 as M, PayvoAuthDBSchema as Mt, AwaitableFunction as N, SecondaryStorage as Nt, google as O, DBFieldAttributeConfig as Ot, LiteralString as P, OAuthProvider as Q, UnionToIntersection as R, SocialProviderListEnum as S, RateLimit as St, socialProviders as T, accountSchema as Tt, generateCodeChallenge as U, validateAuthorizationCode as V, getOAuth2Tokens as W, OAuth2Tokens as X, createClientCredentialsTokenRequest as Y, OAuth2UserInfo as Z, PayvoAuthRateLimitOptions as _, User as _t, optionsMiddleware as a, DBAdapterInstance as at, SocialProvider as b, Session as bt, ClientStore as c, Where as ct, AuthContext as d, FieldAttributeConfig as dt, CleanedWhere as et, GenericEndpointContext as f, FieldType as ft, PayvoAuthOptions as g, verificationSchema as gt, PayvoAuthAdvancedOptions as h, Verification as ht, createAuthMiddleware as i, DBAdapterFactoryConfig as it, github as j, DBPrimitive as jt, GithubOptions as k, DBFieldType as kt, PayvoAuthClientOptions as l, AuthPluginSchema as lt, GenerateIdFn as m, Primitive$1 as mt, AuthMiddleware as n, DBAdapter as nt, StandardSchemaV1$1 as o, DBAdapterSchemaCreation as ot, InternalAdapter as p, PayvoAuthDbSchema as pt, createAuthorizationURL as q, createAuthEndpoint as r, DBAdapterDebugLogOption as rt, ClientAtomListener as s, DBTransactionAdapter as st, AuthEndpoint as t, CustomAdapter as tt, PayvoAuthClientPlugin as u, FieldAttribute as ut, HookEndpointContext as v, userSchema as vt, socialProviderList as w, Account as wt, SocialProviderList as x, sessionSchema as xt, PayvoAuthPlugin as y, coreSchema as yt, PayvoAuthCookies as z };