@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,88 @@
1
+ import type { BetterFetch, BetterFetchOption, BetterFetchPlugin } from "@better-fetch/fetch";
2
+ import type { LiteralString } from "./helper";
3
+ import type { PayvoAuthPlugin } from "./plugin";
4
+ import type { Atom, WritableAtom } from "nanostores";
5
+ import type { PayvoAuthOptions } from "./init-options";
6
+ export interface ClientStore {
7
+ notify: (signal: string) => void;
8
+ listen: (signal: string, listener: () => void) => void;
9
+ atoms: Record<string, WritableAtom<any>>;
10
+ }
11
+ export type ClientAtomListener = {
12
+ matcher: (path: string) => boolean;
13
+ signal: "$sessionSignal" | Omit<string, "$sessionSignal">;
14
+ };
15
+ export interface RevalidateOptions {
16
+ /**
17
+ * A time interval (in seconds) after which the session will be re-fetched.
18
+ * If set to `0` (default), the session is not polled.
19
+ *
20
+ * This helps prevent session expiry during idle periods by periodically
21
+ * refreshing the session.
22
+ *
23
+ * @default 0
24
+ */
25
+ refetchInterval?: number | undefined;
26
+ /**
27
+ * Automatically refetch the session when the user switches back to the window/tab.
28
+ * This option activates this behavior if set to `true` (default).
29
+ *
30
+ * Prevents expired sessions when users switch tabs and come back later.
31
+ *
32
+ * @default true
33
+ */
34
+ refetchOnWindowFocus?: boolean | undefined;
35
+ /**
36
+ * Set to `false` to stop polling when the device has no internet access
37
+ * (determined by `navigator.onLine`).
38
+ *
39
+ * @default false
40
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/NavigatorOnLine/onLine
41
+ */
42
+ refetchWhenOffline?: boolean | undefined;
43
+ }
44
+ export interface PayvoAuthClientOptions {
45
+ fetchOptions?: BetterFetchOption | undefined;
46
+ plugins?: PayvoAuthClientPlugin[] | undefined;
47
+ baseURL?: string | undefined;
48
+ basePath?: string | undefined;
49
+ disableDefaultFetchPlugins?: boolean | undefined;
50
+ $InferAuth?: PayvoAuthOptions | undefined;
51
+ sessionOptions?: RevalidateOptions | undefined;
52
+ }
53
+ export interface PayvoAuthClientPlugin {
54
+ id: LiteralString;
55
+ /**
56
+ * only used for type inference. don't pass the
57
+ * actual plugin
58
+ */
59
+ $InferServerPlugin?: PayvoAuthPlugin | undefined;
60
+ /**
61
+ * Custom actions
62
+ */
63
+ getActions?: ($fetch: BetterFetch, $store: ClientStore,
64
+ /**
65
+ * payvo-auth client options
66
+ */
67
+ options: PayvoAuthClientOptions | undefined) => Record<string, any>;
68
+ /**
69
+ * State atoms that'll be resolved by each framework
70
+ * auth store.
71
+ */
72
+ getAtoms?: (($fetch: BetterFetch) => Record<string, Atom<any>>) | undefined;
73
+ /**
74
+ * specify path methods for server plugin inferred
75
+ * endpoints to force a specific method.
76
+ */
77
+ pathMethods?: Record<string, "POST" | "GET"> | undefined;
78
+ /**
79
+ * Better fetch plugins
80
+ */
81
+ fetchPlugins?: BetterFetchPlugin[] | undefined;
82
+ /**
83
+ * a list of recaller based on a matcher function.
84
+ * The signal name needs to match a signal in this
85
+ * plugin or any plugin the user might have added.
86
+ */
87
+ atomListeners?: ClientAtomListener[] | undefined;
88
+ }
@@ -0,0 +1,120 @@
1
+ import type { Endpoint, EndpointContext, InputContext, Middleware } from "better-call";
2
+ import type { Migration } from "kysely";
3
+ import type { AuthMiddleware } from "../api";
4
+ import type { PayvoAuthPluginDBSchema } from "../db";
5
+ import type { AuthContext } from "./context";
6
+ import type { LiteralString } from "./helper";
7
+ import type { PayvoAuthOptions } from "./init-options";
8
+ type Awaitable<T> = T | Promise<T>;
9
+ type DeepPartial<T> = T extends Function ? T : T extends object ? {
10
+ [K in keyof T]?: DeepPartial<T[K]>;
11
+ } : T;
12
+ export type HookEndpointContext = Partial<EndpointContext<string, any> & Omit<InputContext<string, any>, "method">> & {
13
+ path: string;
14
+ context: AuthContext & {
15
+ returned?: unknown | undefined;
16
+ responseHeaders?: Headers | undefined;
17
+ };
18
+ headers?: Headers | undefined;
19
+ };
20
+ export type PayvoAuthPlugin = {
21
+ id: LiteralString;
22
+ /**
23
+ * The init function is called when the plugin is initialized.
24
+ * You can return a new context or modify the existing context.
25
+ */
26
+ init?: ((ctx: AuthContext) => Awaitable<{
27
+ context?: DeepPartial<Omit<AuthContext, "options">>;
28
+ options?: Partial<PayvoAuthOptions>;
29
+ }> | void | Promise<void>) | undefined;
30
+ endpoints?: {
31
+ [key: string]: Endpoint;
32
+ } | undefined;
33
+ middlewares?: {
34
+ path: string;
35
+ middleware: Middleware;
36
+ }[] | undefined;
37
+ onRequest?: ((request: Request, ctx: AuthContext) => Promise<{
38
+ response: Response;
39
+ } | {
40
+ request: Request;
41
+ } | void>) | undefined;
42
+ onResponse?: ((response: Response, ctx: AuthContext) => Promise<{
43
+ response: Response;
44
+ } | void>) | undefined;
45
+ hooks?: {
46
+ before?: {
47
+ matcher: (context: HookEndpointContext) => boolean;
48
+ handler: AuthMiddleware;
49
+ }[];
50
+ after?: {
51
+ matcher: (context: HookEndpointContext) => boolean;
52
+ handler: AuthMiddleware;
53
+ }[];
54
+ } | undefined;
55
+ /**
56
+ * Schema the plugin needs
57
+ *
58
+ * This will also be used to migrate the database. If the fields are dynamic from the plugins
59
+ * configuration each time the configuration is changed a new migration will be created.
60
+ *
61
+ * NOTE: If you want to create migrations manually using
62
+ * migrations option or any other way you
63
+ * can disable migration per table basis.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * schema: {
68
+ * user: {
69
+ * fields: {
70
+ * email: {
71
+ * type: "string",
72
+ * },
73
+ * emailVerified: {
74
+ * type: "boolean",
75
+ * defaultValue: false,
76
+ * },
77
+ * },
78
+ * }
79
+ * } as AuthPluginSchema
80
+ * ```
81
+ */
82
+ schema?: PayvoAuthPluginDBSchema | undefined;
83
+ /**
84
+ * The migrations of the plugin. If you define schema that will automatically create
85
+ * migrations for you.
86
+ *
87
+ * ⚠️ Only uses this if you dont't want to use the schema option and you disabled migrations for
88
+ * the tables.
89
+ */
90
+ migrations?: Record<string, Migration> | undefined;
91
+ /**
92
+ * The options of the plugin
93
+ */
94
+ options?: Record<string, any> | undefined;
95
+ /**
96
+ * types to be inferred
97
+ */
98
+ $Infer?: Record<string, any> | undefined;
99
+ /**
100
+ * The rate limit rules to apply to specific paths.
101
+ */
102
+ rateLimit?: {
103
+ window: number;
104
+ max: number;
105
+ pathMatcher: (path: string) => boolean;
106
+ }[] | undefined;
107
+ /**
108
+ * The error codes returned by the plugin
109
+ */
110
+ $ERROR_CODES?: Record<string, string> | undefined;
111
+ /**
112
+ * All database operations that are performed by the plugin
113
+ *
114
+ * This will override the default database operations
115
+ */
116
+ adapter?: {
117
+ [key: string]: (...args: any[]) => Promise<any> | any;
118
+ };
119
+ };
120
+ export {};
@@ -0,0 +1,9 @@
1
+ type UpperLetter = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z";
2
+ type SpecialCharacter = "_";
3
+ type IsValidUpperSnakeCase<S extends string> = S extends `${infer F}${infer R}` ? F extends UpperLetter | SpecialCharacter ? IsValidUpperSnakeCase<R> : false : true;
4
+ type InvalidKeyError<K extends string> = `Invalid error code key: "${K}" - must only contain uppercase letters (A-Z) and underscores (_)`;
5
+ type ValidateErrorCodes<T> = {
6
+ [K in keyof T]: K extends string ? IsValidUpperSnakeCase<K> extends false ? InvalidKeyError<K> : T[K] : T[K];
7
+ };
8
+ export declare function defineErrorCodes<const T extends Record<string, string>>(codes: ValidateErrorCodes<T>): T;
9
+ export {};
@@ -1,3 +1,3 @@
1
- import { t as defineErrorCodes } from "../utils-BFQCAfNW.mjs";
1
+ import { t as defineErrorCodes } from "../utils-CTOwq_Nj.mjs";
2
2
 
3
3
  export { defineErrorCodes };
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@gatwech/core",
3
- "version": "0.0.11",
3
+ "version": "1.0.0-beta.19",
4
4
  "description": "",
5
5
  "type": "module",
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
6
9
  "main": "./dist/index.mjs",
7
10
  "module": "./dist/index.mjs",
8
11
  "exports": {
@@ -100,13 +103,13 @@
100
103
  }
101
104
  },
102
105
  "devDependencies": {
103
- "@gatwech/utils": "0.5.3",
104
106
  "@better-fetch/fetch": "1.1.18",
107
+ "@gatwech/utils": "0.5.3",
105
108
  "@types/better-sqlite3": "^7.6.13",
106
109
  "better-call": "1.0.19",
107
110
  "better-sqlite3": "^12.4.1",
108
111
  "jose": "^6.1.0",
109
- "kysely": "^0.28.5",
112
+ "kysely": "^0.28.8",
110
113
  "nanostores": "^1.0.1",
111
114
  "tsdown": "0.16.1"
112
115
  },
@@ -115,15 +118,18 @@
115
118
  "zod": "^4.1.5"
116
119
  },
117
120
  "peerDependencies": {
118
- "@gatwech/utils": "0.5.3",
119
121
  "@better-fetch/fetch": "1.1.18",
122
+ "@gatwech/utils": "0.5.3",
120
123
  "better-call": "1.0.19",
121
124
  "jose": "^6.1.0",
122
125
  "kysely": "^0.28.5",
123
126
  "nanostores": "^1.0.1"
124
127
  },
128
+ "files": [
129
+ "dist"
130
+ ],
125
131
  "scripts": {
126
- "build": "tsdown",
132
+ "build": "tsdown --tsconfig tsconfig.build.json",
127
133
  "dev": "tsdown --watch",
128
134
  "typecheck": "tsc --project tsconfig.json",
129
135
  "test": "vitest"
@@ -1,42 +0,0 @@
1
-
2
- > @gatwech/core@0.0.11 build /home/runner/work/payvo-auth/payvo-auth/packages/core
3
- > tsdown
4
-
5
- ℹ tsdown v0.16.1 powered by rolldown v1.0.0-beta.47
6
- ℹ Using tsdown config: /home/runner/work/payvo-auth/payvo-auth/packages/core/tsdown.config.ts
7
- ℹ entry: src/index.ts, src/api/index.ts, src/async_hooks/index.ts, src/context/index.ts, src/db/index.ts, src/env/index.ts, src/error/index.ts, src/oauth2/index.ts, src/social-providers/index.ts, src/utils/index.ts, src/db/adapter/index.ts
8
- ℹ tsconfig: tsconfig.json
9
- ℹ Build start
10
- ℹ dist/social-providers/index.mjs  77.58 kB │ gzip: 10.13 kB
11
- ℹ dist/db/index.mjs  1.64 kB │ gzip: 0.50 kB
12
- ℹ dist/api/index.mjs  0.83 kB │ gzip: 0.40 kB
13
- ℹ dist/context/index.mjs  0.74 kB │ gzip: 0.27 kB
14
- ℹ dist/oauth2/index.mjs  0.61 kB │ gzip: 0.24 kB
15
- ℹ dist/env/index.mjs  0.44 kB │ gzip: 0.25 kB
16
- ℹ dist/error/index.mjs  0.16 kB │ gzip: 0.13 kB
17
- ℹ dist/async_hooks/index.mjs  0.11 kB │ gzip: 0.10 kB
18
- ℹ dist/utils/index.mjs  0.09 kB │ gzip: 0.09 kB
19
- ℹ dist/db/adapter/index.mjs  0.01 kB │ gzip: 0.03 kB
20
- ℹ dist/index.mjs  0.01 kB │ gzip: 0.03 kB
21
- ℹ dist/oauth2-DyI7_CNv.mjs  9.16 kB │ gzip: 2.13 kB
22
- ℹ dist/env-JMSMESs1.mjs  7.67 kB │ gzip: 2.55 kB
23
- ℹ dist/context-DxzHfoWW.mjs  3.91 kB │ gzip: 1.03 kB
24
- ℹ dist/error-41YsFQ8b.mjs  1.76 kB │ gzip: 0.79 kB
25
- ℹ dist/async_hooks-BrLqUNsE.mjs  0.86 kB │ gzip: 0.46 kB
26
- ℹ dist/utils-BFQCAfNW.mjs  0.13 kB │ gzip: 0.12 kB
27
- ℹ dist/social-providers/index.d.mts  3.78 kB │ gzip: 1.17 kB
28
- ℹ dist/context/index.d.mts  2.74 kB │ gzip: 0.78 kB
29
- ℹ dist/error/index.d.mts  1.84 kB │ gzip: 0.72 kB
30
- ℹ dist/db/index.d.mts  1.00 kB │ gzip: 0.38 kB
31
- ℹ dist/utils/index.d.mts  0.84 kB │ gzip: 0.43 kB
32
- ℹ dist/index.d.mts  0.81 kB │ gzip: 0.32 kB
33
- ℹ dist/oauth2/index.d.mts  0.79 kB │ gzip: 0.29 kB
34
- ℹ dist/env/index.d.mts  0.59 kB │ gzip: 0.30 kB
35
- ℹ dist/db/adapter/index.d.mts  0.47 kB │ gzip: 0.22 kB
36
- ℹ dist/api/index.d.mts  0.29 kB │ gzip: 0.15 kB
37
- ℹ dist/async_hooks/index.d.mts  0.14 kB │ gzip: 0.10 kB
38
- ℹ dist/index-DjrJweYn.d.mts 204.61 kB │ gzip: 31.91 kB
39
- ℹ dist/index-DLP-K0uY.d.mts  3.31 kB │ gzip: 1.12 kB
40
- ℹ dist/index-CRg-E-VF.d.mts  0.24 kB │ gzip: 0.16 kB
41
- ℹ 31 files, total: 327.18 kB
42
- ✔ Build complete in 6544ms