@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.
- package/.turbo/turbo-build.log +42 -0
- package/dist/api/index.d.mts +3 -0
- package/dist/api/index.mjs +26 -0
- package/dist/async_hooks/index.d.mts +2 -0
- package/dist/async_hooks/index.mjs +3 -0
- package/dist/async_hooks-BrLqUNsE.mjs +18 -0
- package/dist/context/index.d.mts +44 -0
- package/dist/context/index.mjs +4 -0
- package/dist/context-DxzHfoWW.mjs +108 -0
- package/dist/db/adapter/index.d.mts +3 -0
- package/dist/db/adapter/index.mjs +1 -0
- package/dist/db/index.d.mts +3 -0
- package/dist/db/index.mjs +61 -0
- package/dist/env/index.d.mts +2 -0
- package/dist/env/index.mjs +3 -0
- package/dist/env-JMSMESs1.mjs +245 -0
- package/dist/error/index.d.mts +35 -0
- package/dist/error/index.mjs +4 -0
- package/dist/error-41YsFQ8b.mjs +45 -0
- package/dist/index-CRg-E-VF.d.mts +7 -0
- package/dist/index-DLP-K0uY.d.mts +82 -0
- package/dist/index-DjrJweYn.d.mts +7312 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +1 -0
- package/dist/oauth2/index.d.mts +3 -0
- package/dist/oauth2/index.mjs +3 -0
- package/dist/oauth2-DyI7_CNv.mjs +235 -0
- package/dist/social-providers/index.d.mts +3 -0
- package/dist/social-providers/index.mjs +2513 -0
- package/dist/utils/index.d.mts +9 -0
- package/dist/utils/index.mjs +3 -0
- package/dist/utils-BFQCAfNW.mjs +7 -0
- package/package.json +131 -0
- package/src/api/index.ts +57 -0
- package/src/async_hooks/index.ts +35 -0
- package/src/context/endpoint-context.ts +48 -0
- package/src/context/index.ts +21 -0
- package/src/context/request-state.test.ts +346 -0
- package/src/context/request-state.ts +75 -0
- package/src/context/transaction.ts +72 -0
- package/src/db/adapter/index.ts +466 -0
- package/src/db/index.ts +50 -0
- package/src/db/plugin.ts +11 -0
- package/src/db/schema/account.ts +34 -0
- package/src/db/schema/rate-limit.ts +21 -0
- package/src/db/schema/session.ts +17 -0
- package/src/db/schema/shared.ts +7 -0
- package/src/db/schema/user.ts +16 -0
- package/src/db/schema/verification.ts +15 -0
- package/src/db/type.ts +180 -0
- package/src/env/color-depth.ts +172 -0
- package/src/env/env-impl.ts +124 -0
- package/src/env/index.ts +23 -0
- package/src/env/logger.test.ts +33 -0
- package/src/env/logger.ts +145 -0
- package/src/error/codes.ts +31 -0
- package/src/error/index.ts +11 -0
- package/src/index.ts +1 -0
- package/src/oauth2/client-credentials-token.ts +102 -0
- package/src/oauth2/create-authorization-url.ts +85 -0
- package/src/oauth2/index.ts +21 -0
- package/src/oauth2/oauth-provider.ts +211 -0
- package/src/oauth2/refresh-access-token.ts +124 -0
- package/src/oauth2/utils.ts +36 -0
- package/src/oauth2/validate-authorization-code.ts +154 -0
- package/src/social-providers/apple.ts +213 -0
- package/src/social-providers/atlassian.ts +132 -0
- package/src/social-providers/cognito.ts +269 -0
- package/src/social-providers/discord.ts +169 -0
- package/src/social-providers/dropbox.ts +112 -0
- package/src/social-providers/facebook.ts +204 -0
- package/src/social-providers/figma.ts +115 -0
- package/src/social-providers/github.ts +154 -0
- package/src/social-providers/gitlab.ts +152 -0
- package/src/social-providers/google.ts +171 -0
- package/src/social-providers/huggingface.ts +118 -0
- package/src/social-providers/index.ts +124 -0
- package/src/social-providers/kakao.ts +178 -0
- package/src/social-providers/kick.ts +92 -0
- package/src/social-providers/line.ts +169 -0
- package/src/social-providers/linear.ts +120 -0
- package/src/social-providers/linkedin.ts +110 -0
- package/src/social-providers/microsoft-entra-id.ts +245 -0
- package/src/social-providers/naver.ts +112 -0
- package/src/social-providers/notion.ts +108 -0
- package/src/social-providers/paybin.ts +122 -0
- package/src/social-providers/paypal.ts +263 -0
- package/src/social-providers/polar.ts +107 -0
- package/src/social-providers/reddit.ts +122 -0
- package/src/social-providers/roblox.ts +110 -0
- package/src/social-providers/salesforce.ts +159 -0
- package/src/social-providers/slack.ts +111 -0
- package/src/social-providers/spotify.ts +93 -0
- package/src/social-providers/tiktok.ts +210 -0
- package/src/social-providers/twitch.ts +111 -0
- package/src/social-providers/twitter.ts +198 -0
- package/src/social-providers/vk.ts +126 -0
- package/src/social-providers/zoom.ts +217 -0
- package/src/types/context.ts +269 -0
- package/src/types/cookie.ts +7 -0
- package/src/types/helper.ts +6 -0
- package/src/types/index.ts +21 -0
- package/src/types/init-options.ts +1346 -0
- package/src/types/plugin-client.ts +100 -0
- package/src/types/plugin.ts +158 -0
- package/src/utils/error-codes.ts +51 -0
- package/src/utils/index.ts +1 -0
- package/tsconfig.json +7 -0
- package/tsdown.config.ts +20 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
BetterFetch,
|
|
3
|
+
BetterFetchOption,
|
|
4
|
+
BetterFetchPlugin,
|
|
5
|
+
} from "@better-fetch/fetch";
|
|
6
|
+
import type { Atom, WritableAtom } from "nanostores";
|
|
7
|
+
import type { LiteralString } from "./helper";
|
|
8
|
+
import type { PayvoAuthOptions } from "./init-options";
|
|
9
|
+
import type { PayvoAuthPlugin } from "./plugin";
|
|
10
|
+
|
|
11
|
+
export interface ClientStore {
|
|
12
|
+
notify: (signal: string) => void;
|
|
13
|
+
listen: (signal: string, listener: () => void) => void;
|
|
14
|
+
atoms: Record<string, WritableAtom<any>>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type ClientAtomListener = {
|
|
18
|
+
matcher: (path: string) => boolean;
|
|
19
|
+
signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export interface RevalidateOptions {
|
|
23
|
+
/**
|
|
24
|
+
* A time interval (in seconds) after which the session will be re-fetched.
|
|
25
|
+
* If set to `0` (default), the session is not polled.
|
|
26
|
+
*
|
|
27
|
+
* This helps prevent session expiry during idle periods by periodically
|
|
28
|
+
* refreshing the session.
|
|
29
|
+
*
|
|
30
|
+
* @default 0
|
|
31
|
+
*/
|
|
32
|
+
refetchInterval?: number | undefined;
|
|
33
|
+
/**
|
|
34
|
+
* Automatically refetch the session when the user switches back to the window/tab.
|
|
35
|
+
* This option activates this behavior if set to `true` (default).
|
|
36
|
+
*
|
|
37
|
+
* Prevents expired sessions when users switch tabs and come back later.
|
|
38
|
+
*
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
refetchOnWindowFocus?: boolean | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Set to `false` to stop polling when the device has no internet access
|
|
44
|
+
* (determined by `navigator.onLine`).
|
|
45
|
+
*
|
|
46
|
+
* @default false
|
|
47
|
+
* @see https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine
|
|
48
|
+
*/
|
|
49
|
+
refetchWhenOffline?: boolean | undefined;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export interface PayvoAuthClientOptions {
|
|
53
|
+
fetchOptions?: BetterFetchOption | undefined;
|
|
54
|
+
plugins?: PayvoAuthClientPlugin[] | undefined;
|
|
55
|
+
baseURL?: string | undefined;
|
|
56
|
+
basePath?: string | undefined;
|
|
57
|
+
disableDefaultFetchPlugins?: boolean | undefined;
|
|
58
|
+
$InferAuth?: PayvoAuthOptions | undefined;
|
|
59
|
+
sessionOptions?: RevalidateOptions | undefined;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface PayvoAuthClientPlugin {
|
|
63
|
+
id: LiteralString;
|
|
64
|
+
/**
|
|
65
|
+
* only used for type inference. don't pass the
|
|
66
|
+
* actual plugin
|
|
67
|
+
*/
|
|
68
|
+
$InferServerPlugin?: PayvoAuthPlugin | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* Custom actions
|
|
71
|
+
*/
|
|
72
|
+
getActions?: (
|
|
73
|
+
$fetch: BetterFetch,
|
|
74
|
+
$store: ClientStore,
|
|
75
|
+
/**
|
|
76
|
+
* payvo-auth client options
|
|
77
|
+
*/
|
|
78
|
+
options: PayvoAuthClientOptions | undefined
|
|
79
|
+
) => Record<string, any>;
|
|
80
|
+
/**
|
|
81
|
+
* State atoms that'll be resolved by each framework
|
|
82
|
+
* auth store.
|
|
83
|
+
*/
|
|
84
|
+
getAtoms?: (($fetch: BetterFetch) => Record<string, Atom<any>>) | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* specify path methods for server plugin inferred
|
|
87
|
+
* endpoints to force a specific method.
|
|
88
|
+
*/
|
|
89
|
+
pathMethods?: Record<string, "POST" | "GET"> | undefined;
|
|
90
|
+
/**
|
|
91
|
+
* Better fetch plugins
|
|
92
|
+
*/
|
|
93
|
+
fetchPlugins?: BetterFetchPlugin[] | undefined;
|
|
94
|
+
/**
|
|
95
|
+
* a list of recaller based on a matcher function.
|
|
96
|
+
* The signal name needs to match a signal in this
|
|
97
|
+
* plugin or any plugin the user might have added.
|
|
98
|
+
*/
|
|
99
|
+
atomListeners?: ClientAtomListener[] | undefined;
|
|
100
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
Endpoint,
|
|
3
|
+
EndpointContext,
|
|
4
|
+
InputContext,
|
|
5
|
+
Middleware,
|
|
6
|
+
} from "better-call";
|
|
7
|
+
import type { Migration } from "kysely";
|
|
8
|
+
import type { AuthMiddleware } from "../api";
|
|
9
|
+
import type { PayvoAuthPluginDBSchema } from "../db";
|
|
10
|
+
import type { AuthContext } from "./context";
|
|
11
|
+
import type { LiteralString } from "./helper";
|
|
12
|
+
import type { PayvoAuthOptions } from "./init-options";
|
|
13
|
+
|
|
14
|
+
type Awaitable<T> = T | Promise<T>;
|
|
15
|
+
type DeepPartial<T> = T extends Function
|
|
16
|
+
? T
|
|
17
|
+
: T extends object
|
|
18
|
+
? { [K in keyof T]?: DeepPartial<T[K]> }
|
|
19
|
+
: T;
|
|
20
|
+
|
|
21
|
+
export type HookEndpointContext = Partial<
|
|
22
|
+
EndpointContext<string, any> & Omit<InputContext<string, any>, "method">
|
|
23
|
+
> & {
|
|
24
|
+
path: string;
|
|
25
|
+
context: AuthContext & {
|
|
26
|
+
returned?: unknown | undefined;
|
|
27
|
+
responseHeaders?: Headers | undefined;
|
|
28
|
+
};
|
|
29
|
+
headers?: Headers | undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export type PayvoAuthPlugin = {
|
|
33
|
+
id: LiteralString;
|
|
34
|
+
/**
|
|
35
|
+
* The init function is called when the plugin is initialized.
|
|
36
|
+
* You can return a new context or modify the existing context.
|
|
37
|
+
*/
|
|
38
|
+
init?:
|
|
39
|
+
| ((ctx: AuthContext) =>
|
|
40
|
+
| Awaitable<{
|
|
41
|
+
context?: DeepPartial<Omit<AuthContext, "options">>;
|
|
42
|
+
options?: Partial<PayvoAuthOptions>;
|
|
43
|
+
}>
|
|
44
|
+
| void
|
|
45
|
+
| Promise<void>)
|
|
46
|
+
| undefined;
|
|
47
|
+
endpoints?:
|
|
48
|
+
| {
|
|
49
|
+
[key: string]: Endpoint;
|
|
50
|
+
}
|
|
51
|
+
| undefined;
|
|
52
|
+
middlewares?:
|
|
53
|
+
| {
|
|
54
|
+
path: string;
|
|
55
|
+
middleware: Middleware;
|
|
56
|
+
}[]
|
|
57
|
+
| undefined;
|
|
58
|
+
onRequest?:
|
|
59
|
+
| ((
|
|
60
|
+
request: Request,
|
|
61
|
+
ctx: AuthContext
|
|
62
|
+
) => Promise<
|
|
63
|
+
| {
|
|
64
|
+
response: Response;
|
|
65
|
+
}
|
|
66
|
+
| {
|
|
67
|
+
request: Request;
|
|
68
|
+
}
|
|
69
|
+
| void
|
|
70
|
+
>)
|
|
71
|
+
| undefined;
|
|
72
|
+
onResponse?:
|
|
73
|
+
| ((
|
|
74
|
+
response: Response,
|
|
75
|
+
ctx: AuthContext
|
|
76
|
+
) => Promise<{
|
|
77
|
+
response: Response;
|
|
78
|
+
} | void>)
|
|
79
|
+
| undefined;
|
|
80
|
+
hooks?:
|
|
81
|
+
| {
|
|
82
|
+
before?: {
|
|
83
|
+
matcher: (context: HookEndpointContext) => boolean;
|
|
84
|
+
handler: AuthMiddleware;
|
|
85
|
+
}[];
|
|
86
|
+
after?: {
|
|
87
|
+
matcher: (context: HookEndpointContext) => boolean;
|
|
88
|
+
handler: AuthMiddleware;
|
|
89
|
+
}[];
|
|
90
|
+
}
|
|
91
|
+
| undefined;
|
|
92
|
+
/**
|
|
93
|
+
* Schema the plugin needs
|
|
94
|
+
*
|
|
95
|
+
* This will also be used to migrate the database. If the fields are dynamic from the plugins
|
|
96
|
+
* configuration each time the configuration is changed a new migration will be created.
|
|
97
|
+
*
|
|
98
|
+
* NOTE: If you want to create migrations manually using
|
|
99
|
+
* migrations option or any other way you
|
|
100
|
+
* can disable migration per table basis.
|
|
101
|
+
*
|
|
102
|
+
* @example
|
|
103
|
+
* ```ts
|
|
104
|
+
* schema: {
|
|
105
|
+
* user: {
|
|
106
|
+
* fields: {
|
|
107
|
+
* email: {
|
|
108
|
+
* type: "string",
|
|
109
|
+
* },
|
|
110
|
+
* emailVerified: {
|
|
111
|
+
* type: "boolean",
|
|
112
|
+
* defaultValue: false,
|
|
113
|
+
* },
|
|
114
|
+
* },
|
|
115
|
+
* }
|
|
116
|
+
* } as AuthPluginSchema
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
schema?: PayvoAuthPluginDBSchema | undefined;
|
|
120
|
+
/**
|
|
121
|
+
* The migrations of the plugin. If you define schema that will automatically create
|
|
122
|
+
* migrations for you.
|
|
123
|
+
*
|
|
124
|
+
* ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
|
|
125
|
+
* the tables.
|
|
126
|
+
*/
|
|
127
|
+
migrations?: Record<string, Migration> | undefined;
|
|
128
|
+
/**
|
|
129
|
+
* The options of the plugin
|
|
130
|
+
*/
|
|
131
|
+
options?: Record<string, any> | undefined;
|
|
132
|
+
/**
|
|
133
|
+
* types to be inferred
|
|
134
|
+
*/
|
|
135
|
+
$Infer?: Record<string, any> | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* The rate limit rules to apply to specific paths.
|
|
138
|
+
*/
|
|
139
|
+
rateLimit?:
|
|
140
|
+
| {
|
|
141
|
+
window: number;
|
|
142
|
+
max: number;
|
|
143
|
+
pathMatcher: (path: string) => boolean;
|
|
144
|
+
}[]
|
|
145
|
+
| undefined;
|
|
146
|
+
/**
|
|
147
|
+
* The error codes returned by the plugin
|
|
148
|
+
*/
|
|
149
|
+
$ERROR_CODES?: Record<string, string> | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* All database operations that are performed by the plugin
|
|
152
|
+
*
|
|
153
|
+
* This will override the default database operations
|
|
154
|
+
*/
|
|
155
|
+
adapter?: {
|
|
156
|
+
[key: string]: (...args: any[]) => Promise<any> | any;
|
|
157
|
+
};
|
|
158
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
type UpperLetter =
|
|
2
|
+
| "A"
|
|
3
|
+
| "B"
|
|
4
|
+
| "C"
|
|
5
|
+
| "D"
|
|
6
|
+
| "E"
|
|
7
|
+
| "F"
|
|
8
|
+
| "G"
|
|
9
|
+
| "H"
|
|
10
|
+
| "I"
|
|
11
|
+
| "J"
|
|
12
|
+
| "K"
|
|
13
|
+
| "L"
|
|
14
|
+
| "M"
|
|
15
|
+
| "N"
|
|
16
|
+
| "O"
|
|
17
|
+
| "P"
|
|
18
|
+
| "Q"
|
|
19
|
+
| "R"
|
|
20
|
+
| "S"
|
|
21
|
+
| "T"
|
|
22
|
+
| "U"
|
|
23
|
+
| "V"
|
|
24
|
+
| "W"
|
|
25
|
+
| "X"
|
|
26
|
+
| "Y"
|
|
27
|
+
| "Z";
|
|
28
|
+
type SpecialCharacter = "_";
|
|
29
|
+
|
|
30
|
+
type IsValidUpperSnakeCase<S extends string> = S extends `${infer F}${infer R}`
|
|
31
|
+
? F extends UpperLetter | SpecialCharacter
|
|
32
|
+
? IsValidUpperSnakeCase<R>
|
|
33
|
+
: false
|
|
34
|
+
: true;
|
|
35
|
+
|
|
36
|
+
type InvalidKeyError<K extends string> =
|
|
37
|
+
`Invalid error code key: "${K}" - must only contain uppercase letters (A-Z) and underscores (_)`;
|
|
38
|
+
|
|
39
|
+
type ValidateErrorCodes<T> = {
|
|
40
|
+
[K in keyof T]: K extends string
|
|
41
|
+
? IsValidUpperSnakeCase<K> extends false
|
|
42
|
+
? InvalidKeyError<K>
|
|
43
|
+
: T[K]
|
|
44
|
+
: T[K];
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
export function defineErrorCodes<const T extends Record<string, string>>(
|
|
48
|
+
codes: ValidateErrorCodes<T>,
|
|
49
|
+
): T {
|
|
50
|
+
return codes as T;
|
|
51
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { defineErrorCodes } from "./error-codes";
|
package/tsconfig.json
ADDED
package/tsdown.config.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { defineConfig } from "tsdown";
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
dts: { build: true, incremental: true },
|
|
5
|
+
format: ["esm"],
|
|
6
|
+
entry: [
|
|
7
|
+
"./src/index.ts",
|
|
8
|
+
"./src/db/index.ts",
|
|
9
|
+
"./src/db/adapter/index.ts",
|
|
10
|
+
"./src/async_hooks/index.ts",
|
|
11
|
+
"./src/context/index.ts",
|
|
12
|
+
"./src/env/index.ts",
|
|
13
|
+
"./src/oauth2/index.ts",
|
|
14
|
+
"./src/api/index.ts",
|
|
15
|
+
"./src/social-providers/index.ts",
|
|
16
|
+
"./src/utils/index.ts",
|
|
17
|
+
"./src/error/index.ts",
|
|
18
|
+
],
|
|
19
|
+
clean: true,
|
|
20
|
+
});
|