@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,42 @@
1
+
2
+ > @gatwech/core@0.0.1-beta.1 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 6541ms
@@ -0,0 +1,3 @@
1
+ import { a as optionsMiddleware, i as createAuthMiddleware, n as AuthMiddleware, r as createAuthEndpoint, t as AuthEndpoint } from "../index-DjrJweYn.mjs";
2
+ import "../index-DLP-K0uY.mjs";
3
+ export { AuthEndpoint, AuthMiddleware, createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
@@ -0,0 +1,26 @@
1
+ import "../async_hooks-BrLqUNsE.mjs";
2
+ import { f as runWithEndpointContext } from "../context-DxzHfoWW.mjs";
3
+ import { createEndpoint, createMiddleware } from "better-call";
4
+
5
+ //#region src/api/index.ts
6
+ const optionsMiddleware = createMiddleware(async () => {
7
+ /**
8
+ * This will be passed on the instance of
9
+ * the context. Used to infer the type
10
+ * here.
11
+ */
12
+ return {};
13
+ });
14
+ const createAuthMiddleware = createMiddleware.create({ use: [optionsMiddleware, createMiddleware(async () => {
15
+ return {};
16
+ })] });
17
+ const use = [optionsMiddleware];
18
+ const createAuthEndpoint = (path, options, handler) => {
19
+ return createEndpoint(path, {
20
+ ...options,
21
+ use: [...options?.use || [], ...use]
22
+ }, async (ctx) => runWithEndpointContext(ctx, () => handler(ctx)));
23
+ };
24
+
25
+ //#endregion
26
+ export { createAuthEndpoint, createAuthMiddleware, optionsMiddleware };
@@ -0,0 +1,2 @@
1
+ import { n as getAsyncLocalStorage, t as AsyncLocalStorage } from "../index-CRg-E-VF.mjs";
2
+ export { AsyncLocalStorage, getAsyncLocalStorage };
@@ -0,0 +1,3 @@
1
+ import { t as getAsyncLocalStorage } from "../async_hooks-BrLqUNsE.mjs";
2
+
3
+ export { getAsyncLocalStorage };
@@ -0,0 +1,18 @@
1
+ //#region src/async_hooks/index.ts
2
+ const AsyncLocalStoragePromise = import(
3
+ /* @vite-ignore */
4
+ /* webpackIgnore: true */
5
+ "node:async_hooks"
6
+ ).then((mod) => mod.AsyncLocalStorage).catch((err) => {
7
+ if ("AsyncLocalStorage" in globalThis) return globalThis.AsyncLocalStorage;
8
+ console.warn("[payvo-auth] Warning: AsyncLocalStorage is not available in this environment. Some features may not work as expected.");
9
+ console.warn("[payvo-auth] Please read more about this warning at https://payvo-auth.com/docs/installation#mount-handler");
10
+ console.warn("[payvo-auth] If you are using Cloudflare Workers, please see: https://developers.cloudflare.com/workers/configuration/compatibility-flags/#nodejs-compatibility-flag");
11
+ throw err;
12
+ });
13
+ async function getAsyncLocalStorage() {
14
+ return AsyncLocalStoragePromise;
15
+ }
16
+
17
+ //#endregion
18
+ export { getAsyncLocalStorage as t };
@@ -0,0 +1,44 @@
1
+ import { Jn as DBTransactionAdapter, Un as DBAdapter, d as AuthContext } from "../index-DjrJweYn.mjs";
2
+ import "../index-DLP-K0uY.mjs";
3
+ import { t as AsyncLocalStorage } from "../index-CRg-E-VF.mjs";
4
+ import { EndpointContext, InputContext } from "better-call";
5
+ import { StandardSchemaV1 } from "@standard-schema/spec";
6
+
7
+ //#region src/context/endpoint-context.d.ts
8
+ type AuthEndpointContext = Partial<InputContext<string, any> & EndpointContext<string, any>> & {
9
+ context: AuthContext;
10
+ };
11
+ /**
12
+ * This is for internal use only. Most users should use `getCurrentAuthContext` instead.
13
+ *
14
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
15
+ */
16
+ declare function getCurrentAuthContextAsyncLocalStorage(): Promise<AsyncLocalStorage<AuthEndpointContext>>;
17
+ declare function getCurrentAuthContext(): Promise<AuthEndpointContext>;
18
+ declare function runWithEndpointContext<T>(context: AuthEndpointContext, fn: () => T): Promise<T>;
19
+ //#endregion
20
+ //#region src/context/request-state.d.ts
21
+ type RequestStateWeakMap = WeakMap<StandardSchemaV1, any>;
22
+ declare function getRequestStateAsyncLocalStorage(): Promise<AsyncLocalStorage<RequestStateWeakMap>>;
23
+ declare function hasRequestState(): Promise<boolean>;
24
+ declare function getCurrentRequestState(): Promise<RequestStateWeakMap>;
25
+ declare function runWithRequestState<T>(store: RequestStateWeakMap, fn: () => T): Promise<T>;
26
+ interface RequestState<T> {
27
+ get<S>(): Promise<S & T>;
28
+ set(value: T): Promise<void>;
29
+ }
30
+ declare function defineRequestState<T>(schema?: StandardSchemaV1<T>): RequestState<T>;
31
+ declare function defineRequestState<Schema extends StandardSchemaV1>(schema?: Schema): RequestState<StandardSchemaV1.InferInput<Schema>>;
32
+ //#endregion
33
+ //#region src/context/transaction.d.ts
34
+ /**
35
+ * This is for internal use only. Most users should use `getCurrentAdapter` instead.
36
+ *
37
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
38
+ */
39
+ declare const getCurrentDBAdapterAsyncLocalStorage: () => Promise<AsyncLocalStorage<DBTransactionAdapter>>;
40
+ declare const getCurrentAdapter: (fallback: DBTransactionAdapter) => Promise<DBTransactionAdapter>;
41
+ declare const runWithAdapter: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
42
+ declare const runWithTransaction: <R>(adapter: DBAdapter, fn: () => R) => Promise<R>;
43
+ //#endregion
44
+ export { type AuthEndpointContext, type RequestState, type RequestStateWeakMap, defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
@@ -0,0 +1,4 @@
1
+ import "../async_hooks-BrLqUNsE.mjs";
2
+ import { a as defineRequestState, c as hasRequestState, d as getCurrentAuthContextAsyncLocalStorage, f as runWithEndpointContext, i as runWithTransaction, l as runWithRequestState, n as getCurrentDBAdapterAsyncLocalStorage, o as getCurrentRequestState, r as runWithAdapter, s as getRequestStateAsyncLocalStorage, t as getCurrentAdapter, u as getCurrentAuthContext } from "../context-DxzHfoWW.mjs";
3
+
4
+ export { defineRequestState, getCurrentAdapter, getCurrentAuthContext, getCurrentAuthContextAsyncLocalStorage, getCurrentDBAdapterAsyncLocalStorage, getCurrentRequestState, getRequestStateAsyncLocalStorage, hasRequestState, runWithAdapter, runWithEndpointContext, runWithRequestState, runWithTransaction };
@@ -0,0 +1,108 @@
1
+ import { t as getAsyncLocalStorage } from "./async_hooks-BrLqUNsE.mjs";
2
+ import z from "zod";
3
+
4
+ //#region src/context/endpoint-context.ts
5
+ let currentContextAsyncStorage = null;
6
+ const ensureAsyncStorage$2 = async () => {
7
+ if (!currentContextAsyncStorage) currentContextAsyncStorage = new (await (getAsyncLocalStorage()))();
8
+ return currentContextAsyncStorage;
9
+ };
10
+ /**
11
+ * This is for internal use only. Most users should use `getCurrentAuthContext` instead.
12
+ *
13
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
14
+ */
15
+ async function getCurrentAuthContextAsyncLocalStorage() {
16
+ return ensureAsyncStorage$2();
17
+ }
18
+ async function getCurrentAuthContext() {
19
+ const context = (await ensureAsyncStorage$2()).getStore();
20
+ if (!context) throw new Error("No auth context found. Please make sure you are calling this function within a `runWithEndpointContext` callback.");
21
+ return context;
22
+ }
23
+ async function runWithEndpointContext(context, fn) {
24
+ return (await ensureAsyncStorage$2()).run(context, fn);
25
+ }
26
+
27
+ //#endregion
28
+ //#region src/context/request-state.ts
29
+ let requestStateAsyncStorage = null;
30
+ const ensureAsyncStorage$1 = async () => {
31
+ if (!requestStateAsyncStorage) requestStateAsyncStorage = new (await (getAsyncLocalStorage()))();
32
+ return requestStateAsyncStorage;
33
+ };
34
+ async function getRequestStateAsyncLocalStorage() {
35
+ return ensureAsyncStorage$1();
36
+ }
37
+ async function hasRequestState() {
38
+ return (await ensureAsyncStorage$1()).getStore() !== void 0;
39
+ }
40
+ async function getCurrentRequestState() {
41
+ const store = (await ensureAsyncStorage$1()).getStore();
42
+ if (!store) throw new Error("No request state found. Please make sure you are calling this function within a `runWithRequestState` callback.");
43
+ return store;
44
+ }
45
+ async function runWithRequestState(store, fn) {
46
+ return (await ensureAsyncStorage$1()).run(store, fn);
47
+ }
48
+ function defineRequestState(schema = z.any()) {
49
+ return {
50
+ async get() {
51
+ return (await getCurrentRequestState()).get(schema);
52
+ },
53
+ async set(value) {
54
+ const store = await getCurrentRequestState();
55
+ const parsedValue = await schema["~standard"].validate(value);
56
+ if (parsedValue.issues) throw new Error(`Invalid value: ${JSON.stringify(parsedValue.issues)}`);
57
+ store.set(schema, parsedValue.value);
58
+ }
59
+ };
60
+ }
61
+
62
+ //#endregion
63
+ //#region src/context/transaction.ts
64
+ let currentAdapterAsyncStorage = null;
65
+ const ensureAsyncStorage = async () => {
66
+ if (!currentAdapterAsyncStorage) currentAdapterAsyncStorage = new (await (getAsyncLocalStorage()))();
67
+ return currentAdapterAsyncStorage;
68
+ };
69
+ /**
70
+ * This is for internal use only. Most users should use `getCurrentAdapter` instead.
71
+ *
72
+ * It is exposed for advanced use cases where you need direct access to the AsyncLocalStorage instance.
73
+ */
74
+ const getCurrentDBAdapterAsyncLocalStorage = async () => {
75
+ return ensureAsyncStorage();
76
+ };
77
+ const getCurrentAdapter = async (fallback) => {
78
+ return ensureAsyncStorage().then((als) => {
79
+ return als.getStore() || fallback;
80
+ }).catch(() => {
81
+ return fallback;
82
+ });
83
+ };
84
+ const runWithAdapter = async (adapter, fn) => {
85
+ let called = true;
86
+ return ensureAsyncStorage().then((als) => {
87
+ called = true;
88
+ return als.run(adapter, fn);
89
+ }).catch((err) => {
90
+ if (!called) return fn();
91
+ throw err;
92
+ });
93
+ };
94
+ const runWithTransaction = async (adapter, fn) => {
95
+ let called = true;
96
+ return ensureAsyncStorage().then((als) => {
97
+ called = true;
98
+ return adapter.transaction(async (trx) => {
99
+ return als.run(trx, fn);
100
+ });
101
+ }).catch((err) => {
102
+ if (!called) return fn();
103
+ throw err;
104
+ });
105
+ };
106
+
107
+ //#endregion
108
+ export { defineRequestState as a, hasRequestState as c, getCurrentAuthContextAsyncLocalStorage as d, runWithEndpointContext as f, runWithTransaction as i, runWithRequestState as l, getCurrentDBAdapterAsyncLocalStorage as n, getCurrentRequestState as o, runWithAdapter as r, getRequestStateAsyncLocalStorage as s, getCurrentAdapter as t, getCurrentAuthContext as u };
@@ -0,0 +1,3 @@
1
+ import { Gn as DBAdapterFactoryConfig, Hn as CustomAdapter, Jn as DBTransactionAdapter, Kn as DBAdapterInstance, Un as DBAdapter, Vn as CleanedWhere, Wn as DBAdapterDebugLogOption, Yn as Where, qn as DBAdapterSchemaCreation } from "../../index-DjrJweYn.mjs";
2
+ import "../../index-DLP-K0uY.mjs";
3
+ export { CleanedWhere, CustomAdapter, DBAdapter, DBAdapterDebugLogOption, DBAdapterFactoryConfig, DBAdapterInstance, DBAdapterSchemaCreation, DBTransactionAdapter, Where };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,3 @@
1
+ import { $n as FieldType, Qn as FieldAttributeConfig, Xn as AuthPluginSchema, Zn as FieldAttribute, _r as DBPreservedModels, ar as userSchema, br as SecondaryStorage, cr as sessionSchema, dr as Account, er as PayvoAuthDbSchema, fr as accountSchema, gr as DBFieldType, hr as DBFieldAttributeConfig, ir as User, lr as RateLimit, mr as DBFieldAttribute, nr as Verification, or as coreSchema, pr as PayvoAuthPluginDBSchema, rr as verificationSchema, sr as Session, tr as Primitive, ur as rateLimitSchema, vr as DBPrimitive, yr as PayvoAuthDBSchema } from "../index-DjrJweYn.mjs";
2
+ import "../index-DLP-K0uY.mjs";
3
+ export { Account, AuthPluginSchema, DBFieldAttribute, DBFieldAttributeConfig, DBFieldType, DBPreservedModels, DBPrimitive, FieldAttribute, FieldAttributeConfig, FieldType, PayvoAuthDBSchema, PayvoAuthDbSchema, PayvoAuthPluginDBSchema, Primitive, RateLimit, SecondaryStorage, Session, User, Verification, accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
@@ -0,0 +1,61 @@
1
+ import * as z$1 from "zod";
2
+
3
+ //#region src/db/schema/shared.ts
4
+ const coreSchema = z$1.object({
5
+ id: z$1.string(),
6
+ createdAt: z$1.date().default(() => /* @__PURE__ */ new Date()),
7
+ updatedAt: z$1.date().default(() => /* @__PURE__ */ new Date())
8
+ });
9
+
10
+ //#endregion
11
+ //#region src/db/schema/account.ts
12
+ const accountSchema = coreSchema.extend({
13
+ providerId: z$1.string(),
14
+ accountId: z$1.string(),
15
+ userId: z$1.coerce.string(),
16
+ accessToken: z$1.string().nullish(),
17
+ refreshToken: z$1.string().nullish(),
18
+ idToken: z$1.string().nullish(),
19
+ accessTokenExpiresAt: z$1.date().nullish(),
20
+ refreshTokenExpiresAt: z$1.date().nullish(),
21
+ scope: z$1.string().nullish(),
22
+ password: z$1.string().nullish()
23
+ });
24
+
25
+ //#endregion
26
+ //#region src/db/schema/rate-limit.ts
27
+ const rateLimitSchema = z$1.object({
28
+ key: z$1.string(),
29
+ count: z$1.number(),
30
+ lastRequest: z$1.number()
31
+ });
32
+
33
+ //#endregion
34
+ //#region src/db/schema/session.ts
35
+ const sessionSchema = coreSchema.extend({
36
+ userId: z$1.coerce.string(),
37
+ expiresAt: z$1.date(),
38
+ token: z$1.string(),
39
+ ipAddress: z$1.string().nullish(),
40
+ userAgent: z$1.string().nullish()
41
+ });
42
+
43
+ //#endregion
44
+ //#region src/db/schema/user.ts
45
+ const userSchema = coreSchema.extend({
46
+ email: z$1.string().transform((val) => val.toLowerCase()),
47
+ emailVerified: z$1.boolean().default(false),
48
+ name: z$1.string(),
49
+ image: z$1.string().nullish()
50
+ });
51
+
52
+ //#endregion
53
+ //#region src/db/schema/verification.ts
54
+ const verificationSchema = coreSchema.extend({
55
+ value: z$1.string(),
56
+ expiresAt: z$1.date(),
57
+ identifier: z$1.string()
58
+ });
59
+
60
+ //#endregion
61
+ export { accountSchema, coreSchema, rateLimitSchema, sessionSchema, userSchema, verificationSchema };
@@ -0,0 +1,2 @@
1
+ import { _ as isTest, a as TTY_COLORS, c as logger, d as EnvObject, f as env, g as isProduction, h as isDevelopment, i as Logger, l as shouldPublishLog, m as getEnvVar, n as LogHandlerParams, o as createLogger, p as getBooleanEnvVar, r as LogLevel, s as levels, t as InternalLogger, u as ENV, v as nodeENV, y as getColorDepth } from "../index-DLP-K0uY.mjs";
2
+ export { ENV, EnvObject, InternalLogger, LogHandlerParams, LogLevel, Logger, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -0,0 +1,3 @@
1
+ import { a as shouldPublishLog, c as env, d as isDevelopment, f as isProduction, i as logger, l as getBooleanEnvVar, m as nodeENV, n as createLogger, o as getColorDepth, p as isTest, r as levels, s as ENV, t as TTY_COLORS, u as getEnvVar } from "../env-JMSMESs1.mjs";
2
+
3
+ export { ENV, TTY_COLORS, createLogger, env, getBooleanEnvVar, getColorDepth, getEnvVar, isDevelopment, isProduction, isTest, levels, logger, nodeENV, shouldPublishLog };
@@ -0,0 +1,245 @@
1
+ //#region src/env/env-impl.ts
2
+ const _envShim = Object.create(null);
3
+ const _getEnv = (useShim) => globalThis.process?.env || globalThis.Deno?.env.toObject() || globalThis.__env__ || (useShim ? _envShim : globalThis);
4
+ const env = new Proxy(_envShim, {
5
+ get(_, prop) {
6
+ return _getEnv()[prop] ?? _envShim[prop];
7
+ },
8
+ has(_, prop) {
9
+ return prop in _getEnv() || prop in _envShim;
10
+ },
11
+ set(_, prop, value) {
12
+ const env$1 = _getEnv(true);
13
+ env$1[prop] = value;
14
+ return true;
15
+ },
16
+ deleteProperty(_, prop) {
17
+ if (!prop) return false;
18
+ const env$1 = _getEnv(true);
19
+ delete env$1[prop];
20
+ return true;
21
+ },
22
+ ownKeys() {
23
+ const env$1 = _getEnv(true);
24
+ return Object.keys(env$1);
25
+ }
26
+ });
27
+ function toBoolean(val) {
28
+ return val ? val !== "false" : false;
29
+ }
30
+ const nodeENV = typeof process !== "undefined" && process.env && process.env.NODE_ENV || "";
31
+ /** Detect if `NODE_ENV` environment variable is `production` */
32
+ const isProduction = nodeENV === "production";
33
+ /** Detect if `NODE_ENV` environment variable is `dev` or `development` */
34
+ const isDevelopment = () => nodeENV === "dev" || nodeENV === "development";
35
+ /** Detect if `NODE_ENV` environment variable is `test` */
36
+ const isTest = () => nodeENV === "test" || toBoolean(env.TEST);
37
+ /**
38
+ * Get environment variable with fallback
39
+ */
40
+ function getEnvVar(key, fallback) {
41
+ if (typeof process !== "undefined" && process.env) return process.env[key] ?? fallback;
42
+ if (typeof Deno !== "undefined") return Deno.env.get(key) ?? fallback;
43
+ if (typeof Bun !== "undefined") return Bun.env[key] ?? fallback;
44
+ return fallback;
45
+ }
46
+ /**
47
+ * Get boolean environment variable
48
+ */
49
+ function getBooleanEnvVar(key, fallback = true) {
50
+ const value = getEnvVar(key);
51
+ if (!value) return fallback;
52
+ return value !== "0" && value.toLowerCase() !== "false" && value !== "";
53
+ }
54
+ /**
55
+ * Common environment variables used in Better Auth
56
+ */
57
+ const ENV = Object.freeze({
58
+ get PAYVO_AUTH_SECRET() {
59
+ return getEnvVar("PAYVO_AUTH_SECRET");
60
+ },
61
+ get AUTH_SECRET() {
62
+ return getEnvVar("AUTH_SECRET");
63
+ },
64
+ get BETTER_AUTH_TELEMETRY() {
65
+ return getEnvVar("BETTER_AUTH_TELEMETRY");
66
+ },
67
+ get BETTER_AUTH_TELEMETRY_ID() {
68
+ return getEnvVar("BETTER_AUTH_TELEMETRY_ID");
69
+ },
70
+ get NODE_ENV() {
71
+ return getEnvVar("NODE_ENV", "development");
72
+ },
73
+ get PACKAGE_VERSION() {
74
+ return getEnvVar("PACKAGE_VERSION", "0.0.0");
75
+ },
76
+ get PAYVO_AUTH_TELEMETRY_ENDPOINT() {
77
+ return getEnvVar("PAYVO_AUTH_TELEMETRY_ENDPOINT", "https://telemetry.payvo-auth.com/v1/track");
78
+ }
79
+ });
80
+
81
+ //#endregion
82
+ //#region src/env/color-depth.ts
83
+ const COLORS_2 = 1;
84
+ const COLORS_16 = 4;
85
+ const COLORS_256 = 8;
86
+ const COLORS_16m = 24;
87
+ const TERM_ENVS = {
88
+ eterm: COLORS_16,
89
+ cons25: COLORS_16,
90
+ console: COLORS_16,
91
+ cygwin: COLORS_16,
92
+ dtterm: COLORS_16,
93
+ gnome: COLORS_16,
94
+ hurd: COLORS_16,
95
+ jfbterm: COLORS_16,
96
+ konsole: COLORS_16,
97
+ kterm: COLORS_16,
98
+ mlterm: COLORS_16,
99
+ mosh: COLORS_16m,
100
+ putty: COLORS_16,
101
+ st: COLORS_16,
102
+ "rxvt-unicode-24bit": COLORS_16m,
103
+ terminator: COLORS_16m,
104
+ "xterm-kitty": COLORS_16m
105
+ };
106
+ const CI_ENVS_MAP = new Map(Object.entries({
107
+ APPVEYOR: COLORS_256,
108
+ BUILDKITE: COLORS_256,
109
+ CIRCLECI: COLORS_16m,
110
+ DRONE: COLORS_256,
111
+ GITEA_ACTIONS: COLORS_16m,
112
+ GITHUB_ACTIONS: COLORS_16m,
113
+ GITLAB_CI: COLORS_256,
114
+ TRAVIS: COLORS_256
115
+ }));
116
+ const TERM_ENVS_REG_EXP = [
117
+ /ansi/,
118
+ /color/,
119
+ /linux/,
120
+ /direct/,
121
+ /^con[0-9]*x[0-9]/,
122
+ /^rxvt/,
123
+ /^screen/,
124
+ /^xterm/,
125
+ /^vt100/,
126
+ /^vt220/
127
+ ];
128
+ function getColorDepth() {
129
+ if (getEnvVar("FORCE_COLOR") !== void 0) switch (getEnvVar("FORCE_COLOR")) {
130
+ case "":
131
+ case "1":
132
+ case "true": return COLORS_16;
133
+ case "2": return COLORS_256;
134
+ case "3": return COLORS_16m;
135
+ default: return COLORS_2;
136
+ }
137
+ if (getEnvVar("NODE_DISABLE_COLORS") !== void 0 && getEnvVar("NODE_DISABLE_COLORS") !== "" || getEnvVar("NO_COLOR") !== void 0 && getEnvVar("NO_COLOR") !== "" || getEnvVar("TERM") === "dumb") return COLORS_2;
138
+ if (getEnvVar("TMUX")) return COLORS_16m;
139
+ if ("TF_BUILD" in env && "AGENT_NAME" in env) return COLORS_16;
140
+ if ("CI" in env) {
141
+ for (const { 0: envName, 1: colors } of CI_ENVS_MAP) if (envName in env) return colors;
142
+ if (getEnvVar("CI_NAME") === "codeship") return COLORS_256;
143
+ return COLORS_2;
144
+ }
145
+ if ("TEAMCITY_VERSION" in env) return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.exec(getEnvVar("TEAMCITY_VERSION")) !== null ? COLORS_16 : COLORS_2;
146
+ switch (getEnvVar("TERM_PROGRAM")) {
147
+ case "iTerm.app":
148
+ if (!getEnvVar("TERM_PROGRAM_VERSION") || /^[0-2]\./.exec(getEnvVar("TERM_PROGRAM_VERSION")) !== null) return COLORS_256;
149
+ return COLORS_16m;
150
+ case "HyperTerm":
151
+ case "MacTerm": return COLORS_16m;
152
+ case "Apple_Terminal": return COLORS_256;
153
+ }
154
+ if (getEnvVar("COLORTERM") === "truecolor" || getEnvVar("COLORTERM") === "24bit") return COLORS_16m;
155
+ if (getEnvVar("TERM")) {
156
+ if (/truecolor/.exec(getEnvVar("TERM")) !== null) return COLORS_16m;
157
+ if (/^xterm-256/.exec(getEnvVar("TERM")) !== null) return COLORS_256;
158
+ const termEnv = getEnvVar("TERM").toLowerCase();
159
+ if (TERM_ENVS[termEnv]) return TERM_ENVS[termEnv];
160
+ if (TERM_ENVS_REG_EXP.some((term) => term.exec(termEnv) !== null)) return COLORS_16;
161
+ }
162
+ if (getEnvVar("COLORTERM")) return COLORS_16;
163
+ return COLORS_2;
164
+ }
165
+
166
+ //#endregion
167
+ //#region src/env/logger.ts
168
+ const TTY_COLORS = {
169
+ reset: "\x1B[0m",
170
+ bright: "\x1B[1m",
171
+ dim: "\x1B[2m",
172
+ undim: "\x1B[22m",
173
+ underscore: "\x1B[4m",
174
+ blink: "\x1B[5m",
175
+ reverse: "\x1B[7m",
176
+ hidden: "\x1B[8m",
177
+ fg: {
178
+ black: "\x1B[30m",
179
+ red: "\x1B[31m",
180
+ green: "\x1B[32m",
181
+ yellow: "\x1B[33m",
182
+ blue: "\x1B[34m",
183
+ magenta: "\x1B[35m",
184
+ cyan: "\x1B[36m",
185
+ white: "\x1B[37m"
186
+ },
187
+ bg: {
188
+ black: "\x1B[40m",
189
+ red: "\x1B[41m",
190
+ green: "\x1B[42m",
191
+ yellow: "\x1B[43m",
192
+ blue: "\x1B[44m",
193
+ magenta: "\x1B[45m",
194
+ cyan: "\x1B[46m",
195
+ white: "\x1B[47m"
196
+ }
197
+ };
198
+ const levels = [
199
+ "info",
200
+ "success",
201
+ "warn",
202
+ "error",
203
+ "debug"
204
+ ];
205
+ function shouldPublishLog(currentLogLevel, logLevel) {
206
+ return levels.indexOf(logLevel) <= levels.indexOf(currentLogLevel);
207
+ }
208
+ const levelColors = {
209
+ info: TTY_COLORS.fg.blue,
210
+ success: TTY_COLORS.fg.green,
211
+ warn: TTY_COLORS.fg.yellow,
212
+ error: TTY_COLORS.fg.red,
213
+ debug: TTY_COLORS.fg.magenta
214
+ };
215
+ const formatMessage = (level, message, colorsEnabled) => {
216
+ const timestamp = (/* @__PURE__ */ new Date()).toISOString();
217
+ if (colorsEnabled) return `${TTY_COLORS.dim}${timestamp}${TTY_COLORS.reset} ${levelColors[level]}${level.toUpperCase()}${TTY_COLORS.reset} ${TTY_COLORS.bright}[Better Auth]:${TTY_COLORS.reset} ${message}`;
218
+ return `${timestamp} ${level.toUpperCase()} [Better Auth]: ${message}`;
219
+ };
220
+ const createLogger = (options) => {
221
+ const enabled = options?.disabled !== true;
222
+ const logLevel = options?.level ?? "error";
223
+ const colorsEnabled = options?.disableColors !== void 0 ? !options.disableColors : getColorDepth() !== 1;
224
+ const LogFunc = (level, message, args = []) => {
225
+ if (!enabled || !shouldPublishLog(logLevel, level)) return;
226
+ const formattedMessage = formatMessage(level, message, colorsEnabled);
227
+ if (!options || typeof options.log !== "function") {
228
+ if (level === "error") console.error(formattedMessage, ...args);
229
+ else if (level === "warn") console.warn(formattedMessage, ...args);
230
+ else console.log(formattedMessage, ...args);
231
+ return;
232
+ }
233
+ options.log(level === "success" ? "info" : level, message, ...args);
234
+ };
235
+ return {
236
+ ...Object.fromEntries(levels.map((level) => [level, (...[message, ...args]) => LogFunc(level, message, args)])),
237
+ get level() {
238
+ return logLevel;
239
+ }
240
+ };
241
+ };
242
+ const logger = createLogger();
243
+
244
+ //#endregion
245
+ export { shouldPublishLog as a, env as c, isDevelopment as d, isProduction as f, logger as i, getBooleanEnvVar as l, nodeENV as m, createLogger as n, getColorDepth as o, isTest as p, levels as r, ENV as s, TTY_COLORS as t, getEnvVar as u };
@@ -0,0 +1,35 @@
1
+ //#region src/error/codes.d.ts
2
+ declare const BASE_ERROR_CODES: {
3
+ readonly USER_NOT_FOUND: "User not found";
4
+ readonly FAILED_TO_CREATE_USER: "Failed to create user";
5
+ readonly FAILED_TO_CREATE_SESSION: "Failed to create session";
6
+ readonly FAILED_TO_UPDATE_USER: "Failed to update user";
7
+ readonly FAILED_TO_GET_SESSION: "Failed to get session";
8
+ readonly INVALID_PASSWORD: "Invalid password";
9
+ readonly INVALID_EMAIL: "Invalid email";
10
+ readonly INVALID_EMAIL_OR_PASSWORD: "Invalid email or password";
11
+ readonly SOCIAL_ACCOUNT_ALREADY_LINKED: "Social account already linked";
12
+ readonly PROVIDER_NOT_FOUND: "Provider not found";
13
+ readonly INVALID_TOKEN: "Invalid token";
14
+ readonly ID_TOKEN_NOT_SUPPORTED: "id_token not supported";
15
+ readonly FAILED_TO_GET_USER_INFO: "Failed to get user info";
16
+ readonly USER_EMAIL_NOT_FOUND: "User email not found";
17
+ readonly EMAIL_NOT_VERIFIED: "Email not verified";
18
+ readonly PASSWORD_TOO_SHORT: "Password too short";
19
+ readonly PASSWORD_TOO_LONG: "Password too long";
20
+ readonly USER_ALREADY_EXISTS: "User already exists.";
21
+ readonly USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL: "User already exists. Use another email.";
22
+ readonly EMAIL_CAN_NOT_BE_UPDATED: "Email can not be updated";
23
+ readonly CREDENTIAL_ACCOUNT_NOT_FOUND: "Credential account not found";
24
+ readonly SESSION_EXPIRED: "Session expired. Re-authenticate to perform this action.";
25
+ readonly FAILED_TO_UNLINK_LAST_ACCOUNT: "You can't unlink your last account";
26
+ readonly ACCOUNT_NOT_FOUND: "Account not found";
27
+ readonly USER_ALREADY_HAS_PASSWORD: "User already has a password. Provide that to delete the account.";
28
+ };
29
+ //#endregion
30
+ //#region src/error/index.d.ts
31
+ declare class PayvoAuthError extends Error {
32
+ constructor(message: string, cause?: string | undefined);
33
+ }
34
+ //#endregion
35
+ export { BASE_ERROR_CODES, PayvoAuthError };
@@ -0,0 +1,4 @@
1
+ import "../utils-BFQCAfNW.mjs";
2
+ import { n as BASE_ERROR_CODES, t as PayvoAuthError } from "../error-41YsFQ8b.mjs";
3
+
4
+ export { BASE_ERROR_CODES, PayvoAuthError };