@gatwech/core 0.0.1-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/.turbo/turbo-build.log +42 -0
  2. package/dist/api/index.d.mts +3 -0
  3. package/dist/api/index.mjs +26 -0
  4. package/dist/async_hooks/index.d.mts +2 -0
  5. package/dist/async_hooks/index.mjs +3 -0
  6. package/dist/async_hooks-BrLqUNsE.mjs +18 -0
  7. package/dist/context/index.d.mts +44 -0
  8. package/dist/context/index.mjs +4 -0
  9. package/dist/context-DxzHfoWW.mjs +108 -0
  10. package/dist/db/adapter/index.d.mts +3 -0
  11. package/dist/db/adapter/index.mjs +1 -0
  12. package/dist/db/index.d.mts +3 -0
  13. package/dist/db/index.mjs +61 -0
  14. package/dist/env/index.d.mts +2 -0
  15. package/dist/env/index.mjs +3 -0
  16. package/dist/env-JMSMESs1.mjs +245 -0
  17. package/dist/error/index.d.mts +35 -0
  18. package/dist/error/index.mjs +4 -0
  19. package/dist/error-41YsFQ8b.mjs +45 -0
  20. package/dist/index-CRg-E-VF.d.mts +7 -0
  21. package/dist/index-DLP-K0uY.d.mts +82 -0
  22. package/dist/index-DjrJweYn.d.mts +7312 -0
  23. package/dist/index.d.mts +3 -0
  24. package/dist/index.mjs +1 -0
  25. package/dist/oauth2/index.d.mts +3 -0
  26. package/dist/oauth2/index.mjs +3 -0
  27. package/dist/oauth2-DyI7_CNv.mjs +235 -0
  28. package/dist/social-providers/index.d.mts +3 -0
  29. package/dist/social-providers/index.mjs +2513 -0
  30. package/dist/utils/index.d.mts +9 -0
  31. package/dist/utils/index.mjs +3 -0
  32. package/dist/utils-BFQCAfNW.mjs +7 -0
  33. package/package.json +131 -0
  34. package/src/api/index.ts +57 -0
  35. package/src/async_hooks/index.ts +35 -0
  36. package/src/context/endpoint-context.ts +48 -0
  37. package/src/context/index.ts +21 -0
  38. package/src/context/request-state.test.ts +346 -0
  39. package/src/context/request-state.ts +75 -0
  40. package/src/context/transaction.ts +72 -0
  41. package/src/db/adapter/index.ts +466 -0
  42. package/src/db/index.ts +50 -0
  43. package/src/db/plugin.ts +11 -0
  44. package/src/db/schema/account.ts +34 -0
  45. package/src/db/schema/rate-limit.ts +21 -0
  46. package/src/db/schema/session.ts +17 -0
  47. package/src/db/schema/shared.ts +7 -0
  48. package/src/db/schema/user.ts +16 -0
  49. package/src/db/schema/verification.ts +15 -0
  50. package/src/db/type.ts +180 -0
  51. package/src/env/color-depth.ts +172 -0
  52. package/src/env/env-impl.ts +124 -0
  53. package/src/env/index.ts +23 -0
  54. package/src/env/logger.test.ts +33 -0
  55. package/src/env/logger.ts +145 -0
  56. package/src/error/codes.ts +31 -0
  57. package/src/error/index.ts +11 -0
  58. package/src/index.ts +1 -0
  59. package/src/oauth2/client-credentials-token.ts +102 -0
  60. package/src/oauth2/create-authorization-url.ts +85 -0
  61. package/src/oauth2/index.ts +21 -0
  62. package/src/oauth2/oauth-provider.ts +211 -0
  63. package/src/oauth2/refresh-access-token.ts +124 -0
  64. package/src/oauth2/utils.ts +36 -0
  65. package/src/oauth2/validate-authorization-code.ts +154 -0
  66. package/src/social-providers/apple.ts +213 -0
  67. package/src/social-providers/atlassian.ts +132 -0
  68. package/src/social-providers/cognito.ts +269 -0
  69. package/src/social-providers/discord.ts +169 -0
  70. package/src/social-providers/dropbox.ts +112 -0
  71. package/src/social-providers/facebook.ts +204 -0
  72. package/src/social-providers/figma.ts +115 -0
  73. package/src/social-providers/github.ts +154 -0
  74. package/src/social-providers/gitlab.ts +152 -0
  75. package/src/social-providers/google.ts +171 -0
  76. package/src/social-providers/huggingface.ts +118 -0
  77. package/src/social-providers/index.ts +124 -0
  78. package/src/social-providers/kakao.ts +178 -0
  79. package/src/social-providers/kick.ts +92 -0
  80. package/src/social-providers/line.ts +169 -0
  81. package/src/social-providers/linear.ts +120 -0
  82. package/src/social-providers/linkedin.ts +110 -0
  83. package/src/social-providers/microsoft-entra-id.ts +245 -0
  84. package/src/social-providers/naver.ts +112 -0
  85. package/src/social-providers/notion.ts +108 -0
  86. package/src/social-providers/paybin.ts +122 -0
  87. package/src/social-providers/paypal.ts +263 -0
  88. package/src/social-providers/polar.ts +107 -0
  89. package/src/social-providers/reddit.ts +122 -0
  90. package/src/social-providers/roblox.ts +110 -0
  91. package/src/social-providers/salesforce.ts +159 -0
  92. package/src/social-providers/slack.ts +111 -0
  93. package/src/social-providers/spotify.ts +93 -0
  94. package/src/social-providers/tiktok.ts +210 -0
  95. package/src/social-providers/twitch.ts +111 -0
  96. package/src/social-providers/twitter.ts +198 -0
  97. package/src/social-providers/vk.ts +126 -0
  98. package/src/social-providers/zoom.ts +217 -0
  99. package/src/types/context.ts +269 -0
  100. package/src/types/cookie.ts +7 -0
  101. package/src/types/helper.ts +6 -0
  102. package/src/types/index.ts +21 -0
  103. package/src/types/init-options.ts +1346 -0
  104. package/src/types/plugin-client.ts +100 -0
  105. package/src/types/plugin.ts +158 -0
  106. package/src/utils/error-codes.ts +51 -0
  107. package/src/utils/index.ts +1 -0
  108. package/tsconfig.json +7 -0
  109. package/tsdown.config.ts +20 -0
@@ -0,0 +1,75 @@
1
+ import type { StandardSchemaV1 } from "@standard-schema/spec";
2
+ import z from "zod";
3
+ import { type AsyncLocalStorage, getAsyncLocalStorage } from "../async_hooks";
4
+
5
+ export type RequestStateWeakMap = WeakMap<StandardSchemaV1, any>;
6
+
7
+ let requestStateAsyncStorage: AsyncLocalStorage<RequestStateWeakMap> | null =
8
+ null;
9
+
10
+ const ensureAsyncStorage = async () => {
11
+ if (!requestStateAsyncStorage) {
12
+ const AsyncLocalStorage = await getAsyncLocalStorage();
13
+ requestStateAsyncStorage = new AsyncLocalStorage();
14
+ }
15
+ return requestStateAsyncStorage;
16
+ };
17
+
18
+ export async function getRequestStateAsyncLocalStorage() {
19
+ return ensureAsyncStorage();
20
+ }
21
+
22
+ export async function hasRequestState() {
23
+ const als = await ensureAsyncStorage();
24
+ return als.getStore() !== undefined;
25
+ }
26
+
27
+ export async function getCurrentRequestState(): Promise<RequestStateWeakMap> {
28
+ const als = await ensureAsyncStorage();
29
+ const store = als.getStore();
30
+ if (!store) {
31
+ throw new Error(
32
+ "No request state found. Please make sure you are calling this function within a `runWithRequestState` callback.",
33
+ );
34
+ }
35
+ return store;
36
+ }
37
+
38
+ export async function runWithRequestState<T>(
39
+ store: RequestStateWeakMap,
40
+ fn: () => T,
41
+ ): Promise<T> {
42
+ const als = await ensureAsyncStorage();
43
+ return als.run(store, fn);
44
+ }
45
+
46
+ export interface RequestState<T> {
47
+ get<S>(): Promise<S & T>;
48
+ set(value: T): Promise<void>;
49
+ }
50
+
51
+ export function defineRequestState<T>(
52
+ schema?: StandardSchemaV1<T>,
53
+ ): RequestState<T>;
54
+ export function defineRequestState<Schema extends StandardSchemaV1>(
55
+ schema?: Schema,
56
+ ): RequestState<StandardSchemaV1.InferInput<Schema>>;
57
+ export function defineRequestState(
58
+ schema: StandardSchemaV1 = z.any(),
59
+ ): RequestState<any> {
60
+ return {
61
+ async get() {
62
+ const store = await getCurrentRequestState();
63
+ return store.get(schema);
64
+ },
65
+
66
+ async set(value) {
67
+ const store = await getCurrentRequestState();
68
+ const parsedValue = await schema["~standard"].validate(value);
69
+ if (parsedValue.issues) {
70
+ throw new Error(`Invalid value: ${JSON.stringify(parsedValue.issues)}`);
71
+ }
72
+ store.set(schema, parsedValue.value);
73
+ },
74
+ };
75
+ }
@@ -0,0 +1,72 @@
1
+ import { type AsyncLocalStorage, getAsyncLocalStorage } from "../async_hooks";
2
+ import type { DBAdapter, DBTransactionAdapter } from "../db/adapter";
3
+
4
+ let currentAdapterAsyncStorage: AsyncLocalStorage<DBTransactionAdapter> | null =
5
+ null;
6
+
7
+ const ensureAsyncStorage = async () => {
8
+ if (!currentAdapterAsyncStorage) {
9
+ const AsyncLocalStorage = await getAsyncLocalStorage();
10
+ currentAdapterAsyncStorage = new AsyncLocalStorage();
11
+ }
12
+ return currentAdapterAsyncStorage;
13
+ };
14
+
15
+ /**
16
+ * This is for internal use only. Most users should use `getCurrentAdapter` instead.
17
+ *
18
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
19
+ */
20
+ export const getCurrentDBAdapterAsyncLocalStorage = async () => {
21
+ return ensureAsyncStorage();
22
+ };
23
+
24
+ export const getCurrentAdapter = async (
25
+ fallback: DBTransactionAdapter,
26
+ ): Promise<DBTransactionAdapter> => {
27
+ return ensureAsyncStorage()
28
+ .then((als) => {
29
+ return als.getStore() || fallback;
30
+ })
31
+ .catch(() => {
32
+ return fallback;
33
+ });
34
+ };
35
+
36
+ export const runWithAdapter = async <R>(
37
+ adapter: DBAdapter,
38
+ fn: () => R,
39
+ ): Promise<R> => {
40
+ let called = true;
41
+ return ensureAsyncStorage()
42
+ .then((als) => {
43
+ called = true;
44
+ return als.run(adapter, fn);
45
+ })
46
+ .catch((err) => {
47
+ if (!called) {
48
+ return fn();
49
+ }
50
+ throw err;
51
+ });
52
+ };
53
+
54
+ export const runWithTransaction = async <R>(
55
+ adapter: DBAdapter,
56
+ fn: () => R,
57
+ ): Promise<R> => {
58
+ let called = true;
59
+ return ensureAsyncStorage()
60
+ .then((als) => {
61
+ called = true;
62
+ return adapter.transaction(async (trx) => {
63
+ return als.run(trx, fn);
64
+ });
65
+ })
66
+ .catch((err) => {
67
+ if (!called) {
68
+ return fn();
69
+ }
70
+ throw err;
71
+ });
72
+ };
@@ -0,0 +1,466 @@
1
+ import type { PayvoAuthOptions } from "../../types";
2
+ import type { PayvoAuthDBSchema, DBFieldAttribute } from "../type";
3
+
4
+ export type DBAdapterDebugLogOption =
5
+ | boolean
6
+ | {
7
+ /**
8
+ * Useful when you want to log only certain conditions.
9
+ */
10
+ logCondition?: (() => boolean) | undefined;
11
+ create?: boolean | undefined;
12
+ update?: boolean | undefined;
13
+ updateMany?: boolean | undefined;
14
+ findOne?: boolean | undefined;
15
+ findMany?: boolean | undefined;
16
+ delete?: boolean | undefined;
17
+ deleteMany?: boolean | undefined;
18
+ count?: boolean | undefined;
19
+ }
20
+ | {
21
+ /**
22
+ * Only used for adapter tests to show debug logs if a test fails.
23
+ *
24
+ * @deprecated Not actually deprecated. Doing this for IDEs to show this option at the very bottom and stop end-users from using this.
25
+ */
26
+ isRunningAdapterTests: boolean;
27
+ };
28
+
29
+ export type DBAdapterSchemaCreation = {
30
+ /**
31
+ * Code to be inserted into the file
32
+ */
33
+ code: string;
34
+ /**
35
+ * Path to the file, including the file name and extension.
36
+ * Relative paths are supported, with the current working directory of the developer's project as the base.
37
+ */
38
+ path: string;
39
+ /**
40
+ * Append the file if it already exists.
41
+ * Note: This will not apply if `overwrite` is set to true.
42
+ */
43
+ append?: boolean | undefined;
44
+ /**
45
+ * Overwrite the file if it already exists
46
+ */
47
+ overwrite?: boolean | undefined;
48
+ };
49
+
50
+ export interface DBAdapterFactoryConfig<
51
+ Options extends PayvoAuthOptions = PayvoAuthOptions,
52
+ > {
53
+ /**
54
+ * Use plural table names.
55
+ *
56
+ * All tables will be named with an `s` at the end.
57
+ *
58
+ * @default false
59
+ */
60
+ usePlural?: boolean | undefined;
61
+ /**
62
+ * Enable debug logs.
63
+ *
64
+ * @default false
65
+ */
66
+ debugLogs?: DBAdapterDebugLogOption | undefined;
67
+ /**
68
+ * Name of the adapter.
69
+ *
70
+ * This is used to identify the adapter in the debug logs.
71
+ *
72
+ * @default `adapterId`
73
+ */
74
+ adapterName?: string | undefined;
75
+ /**
76
+ * Adapter id
77
+ */
78
+ adapterId: string;
79
+ /**
80
+ * If the database supports numeric ids, set this to `true`.
81
+ *
82
+ * @default true
83
+ */
84
+ supportsNumericIds?: boolean | undefined;
85
+ /**
86
+ * If the database doesn't support JSON columns, set this to `false`.
87
+ *
88
+ * We will handle the translation between using `JSON` columns, and saving `string`s to the database.
89
+ *
90
+ * @default false
91
+ */
92
+ supportsJSON?: boolean | undefined;
93
+ /**
94
+ * If the database doesn't support dates, set this to `false`.
95
+ *
96
+ * We will handle the translation between using `Date` objects, and saving `string`s to the database.
97
+ *
98
+ * @default true
99
+ */
100
+ supportsDates?: boolean | undefined;
101
+ /**
102
+ * If the database doesn't support booleans, set this to `false`.
103
+ *
104
+ * We will handle the translation between using `boolean`s, and saving `0`s and `1`s to the database.
105
+ *
106
+ * @default true
107
+ */
108
+ supportsBooleans?: boolean | undefined;
109
+ /**
110
+ * Execute multiple operations in a transaction.
111
+ *
112
+ * If the database doesn't support transactions, set this to `false` and operations will be executed sequentially.
113
+ *
114
+ * @default false
115
+ */
116
+ transaction?:
117
+ | (
118
+ | false
119
+ | (<R>(
120
+ callback: (trx: DBTransactionAdapter<Options>) => Promise<R>
121
+ ) => Promise<R>)
122
+ )
123
+ | undefined;
124
+ /**
125
+ * Disable id generation for the `create` method.
126
+ *
127
+ * This is useful for databases that don't support custom id values and would auto-generate them for you.
128
+ *
129
+ * @default false
130
+ */
131
+ disableIdGeneration?: boolean | undefined;
132
+ /**
133
+ * Map the keys of the input data.
134
+ *
135
+ * This is useful for databases that expect a different key name for a given situation.
136
+ *
137
+ * For example, MongoDB uses `_id` while in Better-Auth we use `id`.
138
+ *
139
+ *
140
+ * @example
141
+ * Each key represents the old key to replace.
142
+ * The value represents the new key
143
+ *
144
+ * This can be a partial object that only transforms some keys.
145
+ *
146
+ * ```ts
147
+ * mapKeysTransformInput: {
148
+ * id: "_id" // We want to replace `id` to `_id` to save into MongoDB
149
+ * }
150
+ * ```
151
+ */
152
+ mapKeysTransformInput?: Record<string, string> | undefined;
153
+ /**
154
+ * Map the keys of the output data.
155
+ *
156
+ * This is useful for databases that expect a different key name for a given situation.
157
+ *
158
+ * For example, MongoDB uses `_id` while in Better-Auth we use `id`.
159
+ *
160
+ * @example
161
+ * Each key represents the old key to replace.
162
+ * The value represents the new key
163
+ *
164
+ * This can be a partial object that only transforms some keys.
165
+ *
166
+ * ```ts
167
+ * mapKeysTransformOutput: {
168
+ * _id: "id" // In MongoDB, we save `id` as `_id`. So we want to replace `_id` with `id` when we get the data back.
169
+ * }
170
+ * ```
171
+ */
172
+ mapKeysTransformOutput?: Record<string, string> | undefined;
173
+ /**
174
+ * Custom transform input function.
175
+ *
176
+ * This function is used to transform the input data before it is saved to the database.
177
+ */
178
+ customTransformInput?:
179
+ | ((props: {
180
+ data: any;
181
+ /**
182
+ * The fields of the model.
183
+ */
184
+ fieldAttributes: DBFieldAttribute;
185
+ /**
186
+ * The field to transform.
187
+ */
188
+ field: string;
189
+ /**
190
+ * The action which was called from the adapter.
191
+ */
192
+ action: "create" | "update";
193
+ /**
194
+ * The model name.
195
+ */
196
+ model: string;
197
+ /**
198
+ * The schema of the user's Better-Auth instance.
199
+ */
200
+ schema: PayvoAuthDBSchema;
201
+ /**
202
+ * The options of the user's Better-Auth instance.
203
+ */
204
+ options: Options;
205
+ }) => any)
206
+ | undefined;
207
+ /**
208
+ * Custom transform output function.
209
+ *
210
+ * This function is used to transform the output data before it is returned to the user.
211
+ */
212
+ customTransformOutput?:
213
+ | ((props: {
214
+ data: any;
215
+ /**
216
+ * The fields of the model.
217
+ */
218
+ fieldAttributes: DBFieldAttribute;
219
+ /**
220
+ * The field to transform.
221
+ */
222
+ field: string;
223
+ /**
224
+ * The fields to select.
225
+ */
226
+ select: string[];
227
+ /**
228
+ * The model name.
229
+ */
230
+ model: string;
231
+ /**
232
+ * The schema of the user's Better-Auth instance.
233
+ */
234
+ schema: PayvoAuthDBSchema;
235
+ /**
236
+ * The options of the user's Better-Auth instance.
237
+ */
238
+ options: Options;
239
+ }) => any)
240
+ | undefined;
241
+ /**
242
+ * Custom ID generator function.
243
+ *
244
+ * By default, we can handle ID generation for you, however if the database your adapter is for only supports a specific custom id generation,
245
+ * then you can use this function to generate your own IDs.
246
+ *
247
+ *
248
+ * Notes:
249
+ * - If the user enabled `useNumberId`, then this option will be ignored. Unless this adapter config has `supportsNumericIds` set to `false`.
250
+ * - If `generateId` is `false` in the user's Better-Auth config, then this option will be ignored.
251
+ * - If `generateId` is a function, then it will override this option.
252
+ *
253
+ * @example
254
+ *
255
+ * ```ts
256
+ * customIdGenerator: ({ model }) => {
257
+ * return "my-super-unique-id";
258
+ * }
259
+ * ```
260
+ */
261
+ customIdGenerator?: ((props: { model: string }) => string) | undefined;
262
+ /**
263
+ * Whether to disable the transform output.
264
+ * Do not use this option unless you know what you are doing.
265
+ * @default false
266
+ */
267
+ disableTransformOutput?: boolean | undefined;
268
+ /**
269
+ * Whether to disable the transform input.
270
+ * Do not use this option unless you know what you are doing.
271
+ * @default false
272
+ */
273
+ disableTransformInput?: boolean | undefined;
274
+ }
275
+
276
+ export type Where = {
277
+ /**
278
+ * @default eq
279
+ */
280
+ operator?:
281
+ | (
282
+ | "eq"
283
+ | "ne"
284
+ | "lt"
285
+ | "lte"
286
+ | "gt"
287
+ | "gte"
288
+ | "in"
289
+ | "not_in"
290
+ | "contains"
291
+ | "starts_with"
292
+ | "ends_with"
293
+ )
294
+ | undefined;
295
+ value: string | number | boolean | string[] | number[] | Date | null;
296
+ field: string;
297
+ /**
298
+ * @default AND
299
+ */
300
+ connector?: ("AND" | "OR") | undefined;
301
+ };
302
+
303
+ export type DBTransactionAdapter<
304
+ Options extends PayvoAuthOptions = PayvoAuthOptions,
305
+ > = Omit<DBAdapter<Options>, "transaction">;
306
+
307
+ export type DBAdapter<Options extends PayvoAuthOptions = PayvoAuthOptions> = {
308
+ id: string;
309
+ create: <T extends Record<string, any>, R = T>(data: {
310
+ model: string;
311
+ data: Omit<T, "id">;
312
+ select?: string[] | undefined;
313
+ /**
314
+ * By default, any `id` provided in `data` will be ignored.
315
+ *
316
+ * If you want to force the `id` to be the same as the `data.id`, set this to `true`.
317
+ */
318
+ forceAllowId?: boolean | undefined;
319
+ }) => Promise<R>;
320
+ findOne: <T>(data: {
321
+ model: string;
322
+ where: Where[];
323
+ select?: string[] | undefined;
324
+ }) => Promise<T | null>;
325
+ findMany: <T>(data: {
326
+ model: string;
327
+ where?: Where[] | undefined;
328
+ limit?: number | undefined;
329
+ sortBy?:
330
+ | {
331
+ field: string;
332
+ direction: "asc" | "desc";
333
+ }
334
+ | undefined;
335
+ offset?: number | undefined;
336
+ }) => Promise<T[]>;
337
+ count: (data: {
338
+ model: string;
339
+ where?: Where[] | undefined;
340
+ }) => Promise<number>;
341
+ /**
342
+ * ⚠︎ Update may not return the updated data
343
+ * if multiple where clauses are provided
344
+ */
345
+ update: <T>(data: {
346
+ model: string;
347
+ where: Where[];
348
+ update: Record<string, any>;
349
+ }) => Promise<T | null>;
350
+ updateMany: (data: {
351
+ model: string;
352
+ where: Where[];
353
+ update: Record<string, any>;
354
+ }) => Promise<number>;
355
+ delete: <T>(data: { model: string; where: Where[] }) => Promise<void>;
356
+ deleteMany: (data: { model: string; where: Where[] }) => Promise<number>;
357
+ /**
358
+ * Execute multiple operations in a transaction.
359
+ * If the adapter doesn't support transactions, operations will be executed sequentially.
360
+ */
361
+ transaction: <R>(
362
+ callback: (trx: DBTransactionAdapter<Options>) => Promise<R>
363
+ ) => Promise<R>;
364
+ /**
365
+ *
366
+ * @param options
367
+ * @param file - file path if provided by the user
368
+ */
369
+ createSchema?:
370
+ | ((options: Options, file?: string) => Promise<DBAdapterSchemaCreation>)
371
+ | undefined;
372
+ options?:
373
+ | ({
374
+ adapterConfig: DBAdapterFactoryConfig<Options>;
375
+ } & CustomAdapter["options"])
376
+ | undefined;
377
+ };
378
+
379
+ export type CleanedWhere = Required<Where>;
380
+
381
+ export interface CustomAdapter {
382
+ create: <T extends Record<string, any>>({
383
+ data,
384
+ model,
385
+ select,
386
+ }: {
387
+ model: string;
388
+ data: T;
389
+ select?: string[] | undefined;
390
+ }) => Promise<T>;
391
+ update: <T>(data: {
392
+ model: string;
393
+ where: CleanedWhere[];
394
+ update: T;
395
+ }) => Promise<T | null>;
396
+ updateMany: (data: {
397
+ model: string;
398
+ where: CleanedWhere[];
399
+ update: Record<string, any>;
400
+ }) => Promise<number>;
401
+ findOne: <T>({
402
+ model,
403
+ where,
404
+ select,
405
+ }: {
406
+ model: string;
407
+ where: CleanedWhere[];
408
+ select?: string[] | undefined;
409
+ }) => Promise<T | null>;
410
+ findMany: <T>({
411
+ model,
412
+ where,
413
+ limit,
414
+ sortBy,
415
+ offset,
416
+ }: {
417
+ model: string;
418
+ where?: CleanedWhere[] | undefined;
419
+ limit: number;
420
+ sortBy?: { field: string; direction: "asc" | "desc" } | undefined;
421
+ offset?: number | undefined;
422
+ }) => Promise<T[]>;
423
+ delete: ({
424
+ model,
425
+ where,
426
+ }: {
427
+ model: string;
428
+ where: CleanedWhere[];
429
+ }) => Promise<void>;
430
+ deleteMany: ({
431
+ model,
432
+ where,
433
+ }: {
434
+ model: string;
435
+ where: CleanedWhere[];
436
+ }) => Promise<number>;
437
+ count: ({
438
+ model,
439
+ where,
440
+ }: {
441
+ model: string;
442
+ where?: CleanedWhere[] | undefined;
443
+ }) => Promise<number>;
444
+ createSchema?:
445
+ | ((props: {
446
+ /**
447
+ * The file the user may have passed in to the `generate` command as the expected schema file output path.
448
+ */
449
+ file?: string;
450
+ /**
451
+ * The tables from the user's Better-Auth instance schema.
452
+ */
453
+ tables: PayvoAuthDBSchema;
454
+ }) => Promise<DBAdapterSchemaCreation>)
455
+ | undefined;
456
+ /**
457
+ * Your adapter's options.
458
+ */
459
+ options?: Record<string, any> | undefined;
460
+ }
461
+
462
+ export interface DBAdapterInstance<
463
+ Options extends PayvoAuthOptions = PayvoAuthOptions,
464
+ > {
465
+ (options: PayvoAuthOptions): DBAdapter<Options>;
466
+ }
@@ -0,0 +1,50 @@
1
+ import type { PayvoAuthPluginDBSchema } from "./plugin";
2
+ import type {
3
+ PayvoAuthDBSchema,
4
+ DBFieldAttribute,
5
+ DBFieldAttributeConfig,
6
+ DBFieldType,
7
+ DBPrimitive,
8
+ } from "./type";
9
+
10
+ export type { PayvoAuthPluginDBSchema } from "./plugin";
11
+ export { type Account, accountSchema } from "./schema/account";
12
+ export { type RateLimit, rateLimitSchema } from "./schema/rate-limit";
13
+ export { type Session, sessionSchema } from "./schema/session";
14
+ export { coreSchema } from "./schema/shared";
15
+ export { type User, userSchema } from "./schema/user";
16
+ export { type Verification, verificationSchema } from "./schema/verification";
17
+ export type {
18
+ PayvoAuthDBSchema,
19
+ DBFieldAttribute,
20
+ DBFieldAttributeConfig,
21
+ DBFieldType,
22
+ DBPreservedModels,
23
+ DBPrimitive,
24
+ SecondaryStorage,
25
+ } from "./type";
26
+
27
+ /**
28
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
29
+ */
30
+ export type AuthPluginSchema = PayvoAuthPluginDBSchema;
31
+ /**
32
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
33
+ */
34
+ export type FieldAttribute = DBFieldAttribute;
35
+ /**
36
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
37
+ */
38
+ export type FieldAttributeConfig = DBFieldAttributeConfig;
39
+ /**
40
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
41
+ */
42
+ export type FieldType = DBFieldType;
43
+ /**
44
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
45
+ */
46
+ export type Primitive = DBPrimitive;
47
+ /**
48
+ * @deprecated Backport for 1.3.x, we will remove this in 1.4.x
49
+ */
50
+ export type PayvoAuthDbSchema = PayvoAuthDBSchema;
@@ -0,0 +1,11 @@
1
+ import type { DBFieldAttribute } from "./type";
2
+
3
+ export type PayvoAuthPluginDBSchema = {
4
+ [table in string]: {
5
+ fields: {
6
+ [field: string]: DBFieldAttribute;
7
+ };
8
+ disableMigration?: boolean | undefined;
9
+ modelName?: string | undefined;
10
+ };
11
+ };
@@ -0,0 +1,34 @@
1
+ import * as z from "zod";
2
+ import { coreSchema } from "./shared";
3
+
4
+ export const accountSchema = coreSchema.extend({
5
+ providerId: z.string(),
6
+ accountId: z.string(),
7
+ userId: z.coerce.string(),
8
+ accessToken: z.string().nullish(),
9
+ refreshToken: z.string().nullish(),
10
+ idToken: z.string().nullish(),
11
+ /**
12
+ * Access token expires at
13
+ */
14
+ accessTokenExpiresAt: z.date().nullish(),
15
+ /**
16
+ * Refresh token expires at
17
+ */
18
+ refreshTokenExpiresAt: z.date().nullish(),
19
+ /**
20
+ * The scopes that the user has authorized
21
+ */
22
+ scope: z.string().nullish(),
23
+ /**
24
+ * Password is only stored in the credential provider
25
+ */
26
+ password: z.string().nullish(),
27
+ });
28
+
29
+ /**
30
+ * Account schema type used by payvo-auth, note that it's possible that account could have additional fields
31
+ *
32
+ * todo: we should use generics to extend this type with additional fields from plugins and options in the future
33
+ */
34
+ export type Account = z.infer<typeof accountSchema>;