@gatwech/core 0.0.11 → 1.0.0-beta.19

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