@gatwech/core 0.0.11 → 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,1140 @@
1
+ import type { Database as BunDatabase } from "bun:sqlite";
2
+ import type { DatabaseSync } from "node:sqlite";
3
+ import type { CookieOptions } from "better-call";
4
+ import type { Dialect, Kysely, MysqlPool, PostgresPool, SqliteDatabase } from "kysely";
5
+ import type { AuthMiddleware } from "../api";
6
+ import type { Account, DBFieldAttribute, DBPreservedModels, RateLimit, SecondaryStorage, Session, User, Verification } from "../db";
7
+ import type { DBAdapterDebugLogOption, DBAdapterInstance } from "../db/adapter";
8
+ import type { Logger } from "../env";
9
+ import type { SocialProviderList, SocialProviders } from "../social-providers";
10
+ import type { AuthContext, GenericEndpointContext } from "./context";
11
+ import type { LiteralUnion } from "./helper";
12
+ import type { PayvoAuthPlugin } from "./plugin";
13
+ type KyselyDatabaseType = "postgres" | "mysql" | "sqlite" | "mssql";
14
+ type OmitId<T extends {
15
+ id: unknown;
16
+ }> = Omit<T, "id">;
17
+ type Optional<T> = {
18
+ [P in keyof T]?: T[P] | undefined;
19
+ };
20
+ export type GenerateIdFn = (options: {
21
+ model: LiteralUnion<DBPreservedModels, string>;
22
+ size?: number | undefined;
23
+ }) => string | false;
24
+ export type PayvoAuthRateLimitOptions = {
25
+ /**
26
+ * By default, rate limiting is only
27
+ * enabled on production.
28
+ */
29
+ enabled?: boolean | undefined;
30
+ /**
31
+ * Default window to use for rate limiting. The value
32
+ * should be in seconds.
33
+ *
34
+ * @default 10 seconds
35
+ */
36
+ window?: number | undefined;
37
+ /**
38
+ * The default maximum number of requests allowed within the window.
39
+ *
40
+ * @default 100 requests
41
+ */
42
+ max?: number | undefined;
43
+ /**
44
+ * Custom rate limit rules to apply to
45
+ * specific paths.
46
+ */
47
+ customRules?: {
48
+ [key: string]: {
49
+ /**
50
+ * The window to use for the custom rule.
51
+ */
52
+ window: number;
53
+ /**
54
+ * The maximum number of requests allowed within the window.
55
+ */
56
+ max: number;
57
+ } | false | ((request: Request) => {
58
+ window: number;
59
+ max: number;
60
+ } | false | Promise<{
61
+ window: number;
62
+ max: number;
63
+ } | false>);
64
+ } | undefined;
65
+ /**
66
+ * Storage configuration
67
+ *
68
+ * By default, rate limiting is stored in memory. If you passed a
69
+ * secondary storage, rate limiting will be stored in the secondary
70
+ * storage.
71
+ *
72
+ * @default "memory"
73
+ */
74
+ storage?: ("memory" | "database" | "secondary-storage") | undefined;
75
+ /**
76
+ * If database is used as storage, the name of the table to
77
+ * use for rate limiting.
78
+ *
79
+ * @default "rateLimit"
80
+ */
81
+ modelName?: string | undefined;
82
+ /**
83
+ * Custom field names for the rate limit table
84
+ */
85
+ fields?: Record<keyof RateLimit, string> | undefined;
86
+ /**
87
+ * custom storage configuration.
88
+ *
89
+ * NOTE: If custom storage is used storage
90
+ * is ignored
91
+ */
92
+ customStorage?: {
93
+ get: (key: string) => Promise<RateLimit | undefined>;
94
+ set: (key: string, value: RateLimit) => Promise<void>;
95
+ };
96
+ };
97
+ export type PayvoAuthAdvancedOptions = {
98
+ /**
99
+ * Ip address configuration
100
+ */
101
+ ipAddress?: {
102
+ /**
103
+ * List of headers to use for ip address
104
+ *
105
+ * Ip address is used for rate limiting and session tracking
106
+ *
107
+ * @example ["x-client-ip", "x-forwarded-for", "cf-connecting-ip"]
108
+ *
109
+ * @default
110
+ * @link https://github.com/payvo-auth/payvo-auth/blob/main/packages/payvo-auth/src/utils/get-request-ip.ts#L8
111
+ */
112
+ ipAddressHeaders?: string[];
113
+ /**
114
+ * Disable ip tracking
115
+ *
116
+ * ⚠︎ This is a security risk and it may expose your application to abuse
117
+ */
118
+ disableIpTracking?: boolean;
119
+ } | undefined;
120
+ /**
121
+ * Use secure cookies
122
+ *
123
+ * @default false
124
+ */
125
+ useSecureCookies?: boolean | undefined;
126
+ /**
127
+ * Disable trusted origins check
128
+ *
129
+ * ⚠︎ This is a security risk and it may expose your application to
130
+ * CSRF attacks
131
+ */
132
+ disableCSRFCheck?: boolean | undefined;
133
+ /**
134
+ * Disable origin check
135
+ *
136
+ * ⚠︎ This may allow requests from any origin to be processed by
137
+ * Payvo Auth. And could lead to security vulnerabilities.
138
+ */
139
+ disableOriginCheck?: boolean | undefined;
140
+ /**
141
+ * Configure cookies to be cross subdomains
142
+ */
143
+ crossSubDomainCookies?: {
144
+ /**
145
+ * Enable cross subdomain cookies
146
+ */
147
+ enabled: boolean;
148
+ /**
149
+ * Additional cookies to be shared across subdomains
150
+ */
151
+ additionalCookies?: string[];
152
+ /**
153
+ * The domain to use for the cookies
154
+ *
155
+ * By default, the domain will be the root
156
+ * domain from the base URL.
157
+ */
158
+ domain?: string;
159
+ } | undefined;
160
+ cookies?: {
161
+ [key: string]: {
162
+ name?: string;
163
+ attributes?: CookieOptions;
164
+ };
165
+ } | undefined;
166
+ defaultCookieAttributes?: CookieOptions | undefined;
167
+ /**
168
+ * Prefix for cookies. If a cookie name is provided
169
+ * in cookies config, this will be overridden.
170
+ *
171
+ * @default
172
+ * ```txt
173
+ * "appName" -> which defaults to "payvo-auth"
174
+ * ```
175
+ */
176
+ cookiePrefix?: string | undefined;
177
+ /**
178
+ * Database configuration.
179
+ */
180
+ database?: {
181
+ /**
182
+ * The default number of records to return from the database
183
+ * when using the `findMany` adapter method.
184
+ *
185
+ * @default 100
186
+ */
187
+ defaultFindManyLimit?: number;
188
+ /**
189
+ * If your database auto increments number ids, set this to `true`.
190
+ *
191
+ * 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.
192
+ *
193
+ * @default false
194
+ *
195
+ * @deprecated Please use `generateId` instead. This will be removed in future
196
+ * releases.
197
+ */
198
+ useNumberId?: boolean;
199
+ /**
200
+ * Custom generateId function.
201
+ *
202
+ * If not provided, random ids will be generated.
203
+ * If set to false, the database's auto generated id
204
+ * will be used.
205
+ *
206
+ * If set to "serial", the database's auto generated
207
+ * id will be used.
208
+ *
209
+ * If set to "uuid", we generate a random UUID for
210
+ * the id. If postgres, we use the `gen_random_uuid()
211
+ * ` function. If mysql or mssql, we use the `uuid()`
212
+ * function.
213
+ */
214
+ generateId?: GenerateIdFn | false | "serial" | "uuid";
215
+ } | undefined;
216
+ /**
217
+ * OAuth configuration
218
+ */
219
+ oauthConfig?: {
220
+ /**
221
+ * Skip state cookie check
222
+ *
223
+ * ⚠︎ this has security implications and should only be enabled if you know what you are doing.
224
+ * @default false
225
+ */
226
+ skipStateCookieCheck?: boolean;
227
+ /**
228
+ * Strategy for storing OAuth state
229
+ *
230
+ * - "cookie": Store state in an encrypted cookie (stateless)
231
+ * - "database": Store state in the database
232
+ *
233
+ * @default "cookie"
234
+ */
235
+ storeStateStrategy?: "database" | "cookie";
236
+ } | undefined;
237
+ };
238
+ export type PayvoAuthOptions = {
239
+ /**
240
+ * The name of the application
241
+ *
242
+ * process.env.APP_NAME
243
+ *
244
+ * @default "Payvo Auth"
245
+ */
246
+ appName?: string | undefined;
247
+ /**
248
+ * Base URL for the Payvo Auth. This is typically the
249
+ * root URL where your application server is hosted.
250
+ * If not explicitly set,
251
+ * the system will check the following environment variable:
252
+ *
253
+ * process.env.PAYVO_AUTH_URL
254
+ */
255
+ baseURL?: string | undefined;
256
+ /**
257
+ * Base path for the Payvo Auth. This is typically
258
+ * the path where the
259
+ * Payvo Auth routes are mounted.
260
+ *
261
+ * @default "/api/auth"
262
+ */
263
+ basePath?: string | undefined;
264
+ /**
265
+ * The secret to use for encryption,
266
+ * signing and hashing.
267
+ *
268
+ * By default Payvo Auth will look for
269
+ * the following environment variables:
270
+ * process.env.PAYVO_AUTH_SECRET,
271
+ * process.env.AUTH_SECRET
272
+ * If none of these environment
273
+ * variables are set,
274
+ * it will default to
275
+ * "payvo-auth-secret-123456789".
276
+ *
277
+ * on production if it's not set
278
+ * it will throw an error.
279
+ *
280
+ * you can generate a good secret
281
+ * using the following command:
282
+ * @example
283
+ * ```bash
284
+ * openssl rand -base64 32
285
+ * ```
286
+ */
287
+ secret?: string | undefined;
288
+ /**
289
+ * Database configuration
290
+ */
291
+ database?: (PostgresPool | MysqlPool | SqliteDatabase | Dialect | DBAdapterInstance | BunDatabase | DatabaseSync | {
292
+ dialect: Dialect;
293
+ type: KyselyDatabaseType;
294
+ /**
295
+ * casing for table names
296
+ *
297
+ * @default "camel"
298
+ */
299
+ casing?: "snake" | "camel";
300
+ /**
301
+ * Enable debug logs for the adapter
302
+ *
303
+ * @default false
304
+ */
305
+ debugLogs?: DBAdapterDebugLogOption;
306
+ /**
307
+ * Whether to execute multiple operations in a transaction.
308
+ * If the database doesn't support transactions,
309
+ * set this to `false` and operations will be executed sequentially.
310
+ * @default true
311
+ */
312
+ transaction?: boolean;
313
+ } | {
314
+ /**
315
+ * Kysely instance
316
+ */
317
+ db: Kysely<any>;
318
+ /**
319
+ * Database type between postgres, mysql and sqlite
320
+ */
321
+ type: KyselyDatabaseType;
322
+ /**
323
+ * casing for table names
324
+ *
325
+ * @default "camel"
326
+ */
327
+ casing?: "snake" | "camel";
328
+ /**
329
+ * Enable debug logs for the adapter
330
+ *
331
+ * @default false
332
+ */
333
+ debugLogs?: DBAdapterDebugLogOption;
334
+ /**
335
+ * Whether to execute multiple operations in a transaction.
336
+ * If the database doesn't support transactions,
337
+ * set this to `false` and operations will be executed sequentially.
338
+ * @default true
339
+ */
340
+ transaction?: boolean;
341
+ }) | undefined;
342
+ /**
343
+ * Secondary storage configuration
344
+ *
345
+ * This is used to store session and rate limit data.
346
+ */
347
+ secondaryStorage?: SecondaryStorage | undefined;
348
+ /**
349
+ * Email verification configuration
350
+ */
351
+ emailVerification?: {
352
+ /**
353
+ * Send a verification email
354
+ * @param data the data object
355
+ * @param request the request object
356
+ */
357
+ sendVerificationEmail?: (
358
+ /**
359
+ * @param user the user to send the
360
+ * verification email to
361
+ * @param url the URL to send the verification email to
362
+ * it contains the token as well
363
+ * @param token the token to send the verification email to
364
+ */
365
+ data: {
366
+ user: User;
367
+ url: string;
368
+ token: string;
369
+ },
370
+ /**
371
+ * The request object
372
+ */
373
+ request?: Request) => Promise<void>;
374
+ /**
375
+ * Send a verification email automatically
376
+ * after sign up
377
+ *
378
+ * @default false
379
+ */
380
+ sendOnSignUp?: boolean;
381
+ /**
382
+ * Send a verification email automatically
383
+ * on sign in when the user's email is not verified
384
+ *
385
+ * @default false
386
+ */
387
+ sendOnSignIn?: boolean;
388
+ /**
389
+ * Auto signin the user after they verify their email
390
+ */
391
+ autoSignInAfterVerification?: boolean;
392
+ /**
393
+ * Number of seconds the verification token is
394
+ * valid for.
395
+ * @default 3600 seconds (1 hour)
396
+ */
397
+ expiresIn?: number;
398
+ /**
399
+ * A function that is called when a user verifies their email
400
+ * @param user the user that verified their email
401
+ * @param request the request object
402
+ */
403
+ onEmailVerification?: (user: User, request?: Request) => Promise<void>;
404
+ /**
405
+ * A function that is called when a user's email is updated to verified
406
+ * @param user the user that verified their email
407
+ * @param request the request object
408
+ */
409
+ afterEmailVerification?: (user: User, request?: Request) => Promise<void>;
410
+ } | undefined;
411
+ /**
412
+ * Email and password authentication
413
+ */
414
+ emailAndPassword?: {
415
+ /**
416
+ * Enable email and password authentication
417
+ *
418
+ * @default false
419
+ */
420
+ enabled: boolean;
421
+ /**
422
+ * Disable email and password sign up
423
+ *
424
+ * @default false
425
+ */
426
+ disableSignUp?: boolean;
427
+ /**
428
+ * Require email verification before a session
429
+ * can be created for the user.
430
+ *
431
+ * if the user is not verified, the user will not be able to sign in
432
+ * and on sign in attempts, the user will be prompted to verify their email.
433
+ */
434
+ requireEmailVerification?: boolean;
435
+ /**
436
+ * The maximum length of the password.
437
+ *
438
+ * @default 128
439
+ */
440
+ maxPasswordLength?: number;
441
+ /**
442
+ * The minimum length of the password.
443
+ *
444
+ * @default 8
445
+ */
446
+ minPasswordLength?: number;
447
+ /**
448
+ * send reset password
449
+ */
450
+ sendResetPassword?: (
451
+ /**
452
+ * @param user the user to send the
453
+ * reset password email to
454
+ * @param url the URL to send the reset password email to
455
+ * @param token the token to send to the user (could be used instead of sending the url
456
+ * if you need to redirect the user to custom route)
457
+ */
458
+ data: {
459
+ user: User;
460
+ url: string;
461
+ token: string;
462
+ },
463
+ /**
464
+ * The request object
465
+ */
466
+ request?: Request) => Promise<void>;
467
+ /**
468
+ * Number of seconds the reset password token is
469
+ * valid for.
470
+ * @default 1 hour (60 * 60)
471
+ */
472
+ resetPasswordTokenExpiresIn?: number;
473
+ /**
474
+ * A callback function that is triggered
475
+ * when a user's password is changed successfully.
476
+ */
477
+ onPasswordReset?: (data: {
478
+ user: User;
479
+ }, request?: Request) => Promise<void>;
480
+ /**
481
+ * Password hashing and verification
482
+ *
483
+ * By default Scrypt is used for password hashing and
484
+ * verification. You can provide your own hashing and
485
+ * verification function. if you want to use a
486
+ * different algorithm.
487
+ */
488
+ password?: {
489
+ hash?: (password: string) => Promise<string>;
490
+ verify?: (data: {
491
+ hash: string;
492
+ password: string;
493
+ }) => Promise<boolean>;
494
+ };
495
+ /**
496
+ * Automatically sign in the user after sign up
497
+ *
498
+ * @default true
499
+ */
500
+ autoSignIn?: boolean;
501
+ /**
502
+ * Whether to revoke all other sessions when resetting password
503
+ * @default false
504
+ */
505
+ revokeSessionsOnPasswordReset?: boolean;
506
+ } | undefined;
507
+ /**
508
+ * list of social providers
509
+ */
510
+ socialProviders?: SocialProviders | undefined;
511
+ /**
512
+ * List of Payvo Auth plugins
513
+ */
514
+ plugins?: ([] | PayvoAuthPlugin[]) | undefined;
515
+ /**
516
+ * User configuration
517
+ */
518
+ user?: {
519
+ /**
520
+ * The model name for the user. Defaults to "user".
521
+ */
522
+ modelName?: string;
523
+ /**
524
+ * Map fields
525
+ *
526
+ * @example
527
+ * ```ts
528
+ * {
529
+ * userId: "user_id"
530
+ * }
531
+ * ```
532
+ */
533
+ fields?: Partial<Record<keyof OmitId<User>, string>>;
534
+ /**
535
+ * Additional fields for the user
536
+ */
537
+ additionalFields?: {
538
+ [key: string]: DBFieldAttribute;
539
+ };
540
+ /**
541
+ * Changing email configuration
542
+ */
543
+ changeEmail?: {
544
+ /**
545
+ * Enable changing email
546
+ * @default false
547
+ */
548
+ enabled: boolean;
549
+ /**
550
+ * Send a verification email when the user changes their email.
551
+ * @param data the data object
552
+ * @param request the request object
553
+ */
554
+ sendChangeEmailVerification?: (data: {
555
+ user: User;
556
+ newEmail: string;
557
+ url: string;
558
+ token: string;
559
+ }, request?: Request) => Promise<void>;
560
+ };
561
+ /**
562
+ * User deletion configuration
563
+ */
564
+ deleteUser?: {
565
+ /**
566
+ * Enable user deletion
567
+ */
568
+ enabled?: boolean;
569
+ /**
570
+ * Send a verification email when the user deletes their account.
571
+ *
572
+ * if this is not set, the user will be deleted immediately.
573
+ * @param data the data object
574
+ * @param request the request object
575
+ */
576
+ sendDeleteAccountVerification?: (data: {
577
+ user: User;
578
+ url: string;
579
+ token: string;
580
+ }, request?: Request) => Promise<void>;
581
+ /**
582
+ * A function that is called before a user is deleted.
583
+ *
584
+ * to interrupt with error you can throw `APIError`
585
+ */
586
+ beforeDelete?: (user: User, request?: Request) => Promise<void>;
587
+ /**
588
+ * A function that is called after a user is deleted.
589
+ *
590
+ * This is useful for cleaning up user data
591
+ */
592
+ afterDelete?: (user: User, request?: Request) => Promise<void>;
593
+ /**
594
+ * The expiration time for the delete token.
595
+ *
596
+ * @default 1 day (60 * 60 * 24) in seconds
597
+ */
598
+ deleteTokenExpiresIn?: number;
599
+ };
600
+ } | undefined;
601
+ session?: {
602
+ /**
603
+ * The model name for the session.
604
+ *
605
+ * @default "session"
606
+ */
607
+ modelName?: string;
608
+ /**
609
+ * Map fields
610
+ *
611
+ * @example
612
+ * ```ts
613
+ * {
614
+ * userId: "user_id"
615
+ * }
616
+ */
617
+ fields?: Partial<Record<keyof OmitId<Session>, string>>;
618
+ /**
619
+ * Expiration time for the session token. The value
620
+ * should be in seconds.
621
+ * @default 7 days (60 * 60 * 24 * 7)
622
+ */
623
+ expiresIn?: number;
624
+ /**
625
+ * How often the session should be refreshed. The value
626
+ * should be in seconds.
627
+ * If set 0 the session will be refreshed every time it is used.
628
+ * @default 1 day (60 * 60 * 24)
629
+ */
630
+ updateAge?: number;
631
+ /**
632
+ * Disable session refresh so that the session is not updated
633
+ * regardless of the `updateAge` option.
634
+ *
635
+ * @default false
636
+ */
637
+ disableSessionRefresh?: boolean;
638
+ /**
639
+ * Additional fields for the session
640
+ */
641
+ additionalFields?: {
642
+ [key: string]: DBFieldAttribute;
643
+ };
644
+ /**
645
+ * By default if secondary storage is provided
646
+ * the session is stored in the secondary storage.
647
+ *
648
+ * Set this to true to store the session in the database
649
+ * as well.
650
+ *
651
+ * Reads are always done from the secondary storage.
652
+ *
653
+ * @default false
654
+ */
655
+ storeSessionInDatabase?: boolean;
656
+ /**
657
+ * By default, sessions are deleted from the database when secondary storage
658
+ * is provided when session is revoked.
659
+ *
660
+ * Set this to true to preserve session records in the database,
661
+ * even if they are deleted from the secondary storage.
662
+ *
663
+ * @default false
664
+ */
665
+ preserveSessionInDatabase?: boolean;
666
+ /**
667
+ * Enable caching session in cookie
668
+ */
669
+ cookieCache?: {
670
+ /**
671
+ * max age of the cookie
672
+ * @default 5 minutes (5 * 60)
673
+ */
674
+ maxAge?: number;
675
+ /**
676
+ * Enable caching session in cookie
677
+ * @default false
678
+ */
679
+ enabled?: boolean;
680
+ /**
681
+ * Strategy for encoding/decoding cookie cache
682
+ *
683
+ * - "compact": Uses base64url encoding with HMAC-SHA256 signature (compact format, no JWT spec overhead)
684
+ * - "jwt": Uses JWT with HMAC signature (no encryption, follows JWT spec)
685
+ * - "jwe": Uses JWE (JSON Web Encryption) with A256CBC-HS512 and HKDF key derivation for secure encrypted tokens
686
+ *
687
+ * @default "compact"
688
+ */
689
+ strategy?: "compact" | "jwt" | "jwe";
690
+ /**
691
+ * Controls stateless cookie cache refresh behavior.
692
+ *
693
+ * When enabled, the cookie cache will be automatically refreshed before expiry
694
+ * WITHOUT querying the database. This is essential for fully stateless or DB-less scenarios.
695
+ *
696
+ * - `false`: Disable automatic refresh. Cache is only invalidated when it reaches maxAge expiry.
697
+ * - `true`: Enable automatic refresh with default settings (refreshes when 80% of maxAge is reached).
698
+ * - `object`: Custom refresh configuration with either `updateAge` or `shouldRefresh` function
699
+ *
700
+ * Note: When the cache expires (reaches maxAge), it will attempt to fetch from database if available.
701
+ * The refreshCache option is specifically for refreshing BEFORE expiry in a stateless manner.
702
+ *
703
+ * @default false
704
+ */
705
+ refreshCache?: boolean | {
706
+ /**
707
+ * Time in seconds before expiry when the cache should be refreshed.
708
+ * For example, if maxAge is 300 (5 minutes) and updateAge is 60,
709
+ * the cache will be refreshed when it has 60 seconds left before expiry.
710
+ *
711
+ * @default 20% of maxAge
712
+ */
713
+ updateAge?: number;
714
+ };
715
+ /**
716
+ * Version of the cookie cache
717
+ *
718
+ * If a cookie cache version is changed, all existing cookie caches with the old version
719
+ * will be invalidated.
720
+ *
721
+ * It can be a string or a function that returns a string or a promise that returns a string.
722
+ * If it's a function, it will be called with the session and user data
723
+ *
724
+ * @default "1"
725
+ */
726
+ 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>);
727
+ };
728
+ /**
729
+ * The age of the session to consider it fresh.
730
+ *
731
+ * This is used to check if the session is fresh
732
+ * for sensitive operations. (e.g. deleting an account)
733
+ *
734
+ * If the session is not fresh, the user should be prompted
735
+ * to sign in again.
736
+ *
737
+ * If set to 0, the session will be considered fresh every time. (⚠︎ not recommended)
738
+ *
739
+ * @default 1 day (60 * 60 * 24)
740
+ */
741
+ freshAge?: number;
742
+ } | undefined;
743
+ account?: {
744
+ /**
745
+ * The model name for the account. Defaults to "account".
746
+ */
747
+ modelName?: string;
748
+ /**
749
+ * Map fields
750
+ */
751
+ fields?: Partial<Record<keyof OmitId<Account>, string>>;
752
+ /**
753
+ * Additional fields for the account
754
+ */
755
+ additionalFields?: {
756
+ [key: string]: DBFieldAttribute;
757
+ };
758
+ /**
759
+ * When enabled (true), the user account data (accessToken, idToken, refreshToken, etc.)
760
+ * will be updated on sign in with the latest data from the provider.
761
+ *
762
+ * @default true
763
+ */
764
+ updateAccountOnSignIn?: boolean;
765
+ /**
766
+ * Configuration for account linking.
767
+ */
768
+ accountLinking?: {
769
+ /**
770
+ * Enable account linking
771
+ *
772
+ * @default true
773
+ */
774
+ enabled?: boolean;
775
+ /**
776
+ * List of trusted providers
777
+ */
778
+ trustedProviders?: Array<LiteralUnion<SocialProviderList[number] | "email-password", string>>;
779
+ /**
780
+ * If enabled (true), this will allow users to manually linking accounts with different email addresses than the main user.
781
+ *
782
+ * @default false
783
+ *
784
+ * ⚠️ Warning: enabling this might lead to account takeovers, so proceed with caution.
785
+ */
786
+ allowDifferentEmails?: boolean;
787
+ /**
788
+ * If enabled (true), this will allow users to unlink all accounts.
789
+ *
790
+ * @default false
791
+ */
792
+ allowUnlinkingAll?: boolean;
793
+ /**
794
+ * If enabled (true), this will update the user information based on the newly linked account
795
+ *
796
+ * @default false
797
+ */
798
+ updateUserInfoOnLink?: boolean;
799
+ };
800
+ /**
801
+ * Encrypt OAuth tokens
802
+ *
803
+ * By default, OAuth tokens (access tokens, refresh tokens, ID tokens) are stored in plain text in the database.
804
+ * This poses a security risk if your database is compromised, as attackers could gain access to user accounts
805
+ * on external services.
806
+ *
807
+ * When enabled, tokens are encrypted using AES-256-GCM before storage, providing protection against:
808
+ * - Database breaches and unauthorized access to raw token data
809
+ * - Internal threats from database administrators or compromised credentials
810
+ * - Token exposure in database backups and logs
811
+ * @default false
812
+ */
813
+ encryptOAuthTokens?: boolean;
814
+ } | undefined;
815
+ /**
816
+ * Verification configuration
817
+ */
818
+ verification?: {
819
+ /**
820
+ * Change the modelName of the verification table
821
+ */
822
+ modelName?: string;
823
+ /**
824
+ * Map verification fields
825
+ */
826
+ fields?: Partial<Record<keyof OmitId<Verification>, string>>;
827
+ /**
828
+ * disable cleaning up expired values when a verification value is
829
+ * fetched
830
+ */
831
+ disableCleanup?: boolean;
832
+ } | undefined;
833
+ /**
834
+ * List of trusted origins.
835
+ */
836
+ trustedOrigins?: (string[] | ((request: Request) => string[] | Promise<string[]>)) | undefined;
837
+ /**
838
+ * Rate limiting configuration
839
+ */
840
+ rateLimit?: PayvoAuthRateLimitOptions | undefined;
841
+ /**
842
+ * Advanced options
843
+ */
844
+ advanced?: (PayvoAuthAdvancedOptions & {
845
+ /**
846
+ * @deprecated Please use `database.generateId` instead.
847
+ */
848
+ generateId?: never;
849
+ }) | undefined;
850
+ logger?: Logger | undefined;
851
+ /**
852
+ * allows you to define custom hooks that can be
853
+ * executed during lifecycle of core database
854
+ * operations.
855
+ */
856
+ databaseHooks?: {
857
+ /**
858
+ * User hooks
859
+ */
860
+ user?: {
861
+ create?: {
862
+ /**
863
+ * Hook that is called before a user is created.
864
+ * if the hook returns false, the user will not be created.
865
+ * If the hook returns an object, it'll be used instead of the original data
866
+ */
867
+ before?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
868
+ data: Optional<User> & Record<string, any>;
869
+ }>;
870
+ /**
871
+ * Hook that is called after a user is created.
872
+ */
873
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
874
+ };
875
+ update?: {
876
+ /**
877
+ * Hook that is called before a user is updated.
878
+ * if the hook returns false, the user will not be updated.
879
+ * If the hook returns an object, it'll be used instead of the original data
880
+ */
881
+ before?: (user: Partial<User> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
882
+ data: Optional<User & Record<string, any>>;
883
+ }>;
884
+ /**
885
+ * Hook that is called after a user is updated.
886
+ */
887
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
888
+ };
889
+ delete?: {
890
+ /**
891
+ * Hook that is called before a user is deleted.
892
+ * if the hook returns false, the user will not be deleted.
893
+ */
894
+ before?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
895
+ /**
896
+ * Hook that is called after a user is deleted.
897
+ */
898
+ after?: (user: User & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
899
+ };
900
+ };
901
+ /**
902
+ * Session Hook
903
+ */
904
+ session?: {
905
+ create?: {
906
+ /**
907
+ * Hook that is called before a session is created.
908
+ * if the hook returns false, the session will not be created.
909
+ * If the hook returns an object, it'll be used instead of the original data
910
+ */
911
+ before?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
912
+ data: Optional<Session> & Record<string, any>;
913
+ }>;
914
+ /**
915
+ * Hook that is called after a session is created.
916
+ */
917
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
918
+ };
919
+ /**
920
+ * Update hook
921
+ */
922
+ update?: {
923
+ /**
924
+ * Hook that is called before a user is updated.
925
+ * if the hook returns false, the session will not be updated.
926
+ * If the hook returns an object, it'll be used instead of the original data
927
+ */
928
+ before?: (session: Partial<Session> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
929
+ data: Optional<Session & Record<string, any>>;
930
+ }>;
931
+ /**
932
+ * Hook that is called after a session is updated.
933
+ */
934
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
935
+ };
936
+ delete?: {
937
+ /**
938
+ * Hook that is called before a session is deleted.
939
+ * if the hook returns false, the session will not be deleted.
940
+ */
941
+ before?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
942
+ /**
943
+ * Hook that is called after a session is deleted.
944
+ */
945
+ after?: (session: Session & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
946
+ };
947
+ };
948
+ /**
949
+ * Account Hook
950
+ */
951
+ account?: {
952
+ create?: {
953
+ /**
954
+ * Hook that is called before a account is created.
955
+ * If the hook returns false, the account will not be created.
956
+ * If the hook returns an object, it'll be used instead of the original data
957
+ */
958
+ before?: (account: Account, context?: GenericEndpointContext) => Promise<boolean | void | {
959
+ data: Optional<Account> & Record<string, any>;
960
+ }>;
961
+ /**
962
+ * Hook that is called after a account is created.
963
+ */
964
+ after?: (account: Account, context?: GenericEndpointContext) => Promise<void>;
965
+ };
966
+ /**
967
+ * Update hook
968
+ */
969
+ update?: {
970
+ /**
971
+ * Hook that is called before a account is update.
972
+ * If the hook returns false, the user will not be updated.
973
+ * If the hook returns an object, it'll be used instead of the original data
974
+ */
975
+ before?: (account: Partial<Account> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
976
+ data: Optional<Account & Record<string, any>>;
977
+ }>;
978
+ /**
979
+ * Hook that is called after a account is updated.
980
+ */
981
+ after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
982
+ };
983
+ delete?: {
984
+ /**
985
+ * Hook that is called before an account is deleted.
986
+ * if the hook returns false, the account will not be deleted.
987
+ */
988
+ before?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
989
+ /**
990
+ * Hook that is called after an account is deleted.
991
+ */
992
+ after?: (account: Account & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
993
+ };
994
+ };
995
+ /**
996
+ * Verification Hook
997
+ */
998
+ verification?: {
999
+ create?: {
1000
+ /**
1001
+ * Hook that is called before a verification is created.
1002
+ * if the hook returns false, the verification will not be created.
1003
+ * If the hook returns an object, it'll be used instead of the original data
1004
+ */
1005
+ before?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1006
+ data: Optional<Verification> & Record<string, any>;
1007
+ }>;
1008
+ /**
1009
+ * Hook that is called after a verification is created.
1010
+ */
1011
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1012
+ };
1013
+ update?: {
1014
+ /**
1015
+ * Hook that is called before a verification is updated.
1016
+ * if the hook returns false, the verification will not be updated.
1017
+ * If the hook returns an object, it'll be used instead of the original data
1018
+ */
1019
+ before?: (verification: Partial<Verification> & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void | {
1020
+ data: Optional<Verification & Record<string, any>>;
1021
+ }>;
1022
+ /**
1023
+ * Hook that is called after a verification is updated.
1024
+ */
1025
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1026
+ };
1027
+ delete?: {
1028
+ /**
1029
+ * Hook that is called before a verification is deleted.
1030
+ * if the hook returns false, the verification will not be deleted.
1031
+ */
1032
+ before?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<boolean | void>;
1033
+ /**
1034
+ * Hook that is called after a verification is deleted.
1035
+ */
1036
+ after?: (verification: Verification & Record<string, unknown>, context?: GenericEndpointContext) => Promise<void>;
1037
+ };
1038
+ };
1039
+ } | undefined;
1040
+ /**
1041
+ * API error handling
1042
+ */
1043
+ onAPIError?: {
1044
+ /**
1045
+ * Throw an error on API error
1046
+ *
1047
+ * @default false
1048
+ */
1049
+ throw?: boolean;
1050
+ /**
1051
+ * Custom error handler
1052
+ *
1053
+ * @param error
1054
+ * @param ctx - Auth context
1055
+ */
1056
+ onError?: (error: unknown, ctx: AuthContext) => void | Promise<void>;
1057
+ /**
1058
+ * The URL to redirect to on error
1059
+ *
1060
+ * When errorURL is provided, the error will be added to the URL as a query parameter
1061
+ * and the user will be redirected to the errorURL.
1062
+ *
1063
+ * @default - "/api/auth/error"
1064
+ */
1065
+ errorURL?: string;
1066
+ /**
1067
+ * Configure the default error page provided by Payvo-Auth
1068
+ * Start your dev server and go to /api/auth/error to see the error page.
1069
+ */
1070
+ customizeDefaultErrorPage?: {
1071
+ colors?: {
1072
+ background?: string;
1073
+ foreground?: string;
1074
+ primary?: string;
1075
+ primaryForeground?: string;
1076
+ mutedForeground?: string;
1077
+ border?: string;
1078
+ destructive?: string;
1079
+ titleBorder?: string;
1080
+ titleColor?: string;
1081
+ gridColor?: string;
1082
+ cardBackground?: string;
1083
+ cornerBorder?: string;
1084
+ };
1085
+ size?: {
1086
+ radiusSm?: string;
1087
+ radiusMd?: string;
1088
+ radiusLg?: string;
1089
+ textSm?: string;
1090
+ text2xl?: string;
1091
+ text4xl?: string;
1092
+ text6xl?: string;
1093
+ };
1094
+ font?: {
1095
+ defaultFamily?: string;
1096
+ monoFamily?: string;
1097
+ };
1098
+ disableTitleBorder?: boolean;
1099
+ disableCornerDecorations?: boolean;
1100
+ disableBackgroundGrid?: boolean;
1101
+ };
1102
+ } | undefined;
1103
+ /**
1104
+ * Hooks
1105
+ */
1106
+ hooks?: {
1107
+ /**
1108
+ * Before a request is processed
1109
+ */
1110
+ before?: AuthMiddleware;
1111
+ /**
1112
+ * After a request is processed
1113
+ */
1114
+ after?: AuthMiddleware;
1115
+ } | undefined;
1116
+ /**
1117
+ * Disabled paths
1118
+ *
1119
+ * Paths you want to disable.
1120
+ */
1121
+ disabledPaths?: string[] | undefined;
1122
+ /**
1123
+ * Telemetry configuration
1124
+ */
1125
+ telemetry?: {
1126
+ /**
1127
+ * Enable telemetry collection
1128
+ *
1129
+ * @default false
1130
+ */
1131
+ enabled?: boolean;
1132
+ /**
1133
+ * Enable debug mode
1134
+ *
1135
+ * @default false
1136
+ */
1137
+ debug?: boolean;
1138
+ } | undefined;
1139
+ };
1140
+ export {};