go-better-auth 0.1.0

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.
@@ -0,0 +1,135 @@
1
+ import { l as Plugin, t as ClientWithPlugins, u as GoBetterAuthClient } from "../sdk-DJhCsA2I.js";
2
+
3
+ //#region src/plugins/email-password/types.d.ts
4
+ type SignUpRequest = {
5
+ name: string;
6
+ email: string;
7
+ password: string;
8
+ callbackUrl?: string;
9
+ };
10
+ type SignInRequest = {
11
+ email: string;
12
+ password: string;
13
+ callbackUrl?: string;
14
+ };
15
+ type VerifyEmailRequest = {
16
+ token: string;
17
+ callbackUrl?: string;
18
+ };
19
+ type SendEmailVerificationRequest = {
20
+ email: string;
21
+ callbackUrl?: string;
22
+ };
23
+ type RequestPasswordResetRequest = {
24
+ email: string;
25
+ callbackUrl?: string;
26
+ };
27
+ type ChangePasswordRequest = {
28
+ token: string;
29
+ password: string;
30
+ };
31
+ type RequestEmailChangeRequest = {
32
+ email: string;
33
+ callbackUrl?: string;
34
+ };
35
+ //#endregion
36
+ //#region src/plugins/email-password/plugin.d.ts
37
+ declare class EmailPasswordPlugin implements Plugin {
38
+ readonly id = "emailPassword";
39
+ init(client: GoBetterAuthClient): {
40
+ signUp: <T>(data: SignUpRequest) => Promise<T>;
41
+ signIn: <T>(data: SignInRequest) => Promise<T>;
42
+ sendEmailVerification: (data: SendEmailVerificationRequest) => Promise<void>;
43
+ requestPasswordReset: (data: RequestPasswordResetRequest) => Promise<void>;
44
+ changePassword: (data: ChangePasswordRequest) => Promise<void>;
45
+ requestEmailChange: (data: RequestEmailChangeRequest) => Promise<void>;
46
+ };
47
+ }
48
+ //#endregion
49
+ //#region src/plugins/oauth2/types.d.ts
50
+ /**
51
+ * OAuth2 provider types supported by GoBetterAuth
52
+ */
53
+ type OAuth2ProviderType = "discord" | "github" | "google";
54
+ /**
55
+ * OAuth2 authorization options
56
+ */
57
+ type SignInWithOAuth2Request = {
58
+ /** OAuth2 provider to use */provider: OAuth2ProviderType;
59
+ redirect_to?: string;
60
+ };
61
+ type SignInWithOAuth2Response = {
62
+ auth_url: string;
63
+ };
64
+ //#endregion
65
+ //#region src/plugins/oauth2/plugin.d.ts
66
+ declare class OAuth2Plugin implements Plugin {
67
+ readonly id = "oauth2";
68
+ init(client: GoBetterAuthClient): {
69
+ signIn: (data: SignInWithOAuth2Request) => Promise<SignInWithOAuth2Response>;
70
+ };
71
+ }
72
+ //#endregion
73
+ //#region src/plugins/csrf/types.d.ts
74
+ type CSRFPluginOptions = {
75
+ cookieName: string;
76
+ headerName: string;
77
+ };
78
+ //#endregion
79
+ //#region src/plugins/csrf/plugin.d.ts
80
+ declare class CSRFPlugin implements Plugin {
81
+ private readonly options;
82
+ readonly id = "csrf";
83
+ constructor(options: CSRFPluginOptions);
84
+ init(client: GoBetterAuthClient): {};
85
+ private cookies?;
86
+ attachCookies(fn: () => Promise<any>): void;
87
+ }
88
+ //#endregion
89
+ //#region src/plugins/jwt/types.d.ts
90
+ type TokenRefreshRequest = {
91
+ refresh_token: string;
92
+ };
93
+ type TokenRefreshResponse = {
94
+ access_token: string;
95
+ refresh_token: string;
96
+ };
97
+ type JWTAlgorithm = "eddsa" | "rs256" | "ps256" | "es256" | "es512" | "ecdh-es";
98
+ type JWKSKey = {
99
+ alg: JWTAlgorithm;
100
+ crv: string;
101
+ kid: string;
102
+ kty: string;
103
+ x: string;
104
+ };
105
+ //#endregion
106
+ //#region src/plugins/jwt/plugin.d.ts
107
+ declare class JWTPlugin implements Plugin {
108
+ readonly id = "jwt";
109
+ constructor();
110
+ init(client: GoBetterAuthClient): {
111
+ refreshToken: (data: TokenRefreshRequest) => Promise<TokenRefreshResponse>;
112
+ getJWKSKeys: () => Promise<Array<JWKSKey>>;
113
+ };
114
+ }
115
+ //#endregion
116
+ //#region src/plugins/bearer/types.d.ts
117
+ type BearerPluginOptions = {
118
+ headerName?: string;
119
+ };
120
+ type JWTTokensResponse = {
121
+ access_token: string;
122
+ refresh_token: string;
123
+ };
124
+ //#endregion
125
+ //#region src/plugins/bearer/plugin.d.ts
126
+ declare class BearerPlugin implements Plugin {
127
+ private readonly options?;
128
+ readonly id = "bearer";
129
+ private refreshPromise;
130
+ constructor(options?: BearerPluginOptions | undefined);
131
+ init(client: ClientWithPlugins<[JWTPlugin]>): {};
132
+ }
133
+ //#endregion
134
+ export { BearerPlugin, BearerPluginOptions, CSRFPlugin, CSRFPluginOptions, ChangePasswordRequest, EmailPasswordPlugin, JWKSKey, JWTAlgorithm, JWTPlugin, JWTTokensResponse, OAuth2Plugin, OAuth2ProviderType, RequestEmailChangeRequest, RequestPasswordResetRequest, SendEmailVerificationRequest, SignInRequest, SignInWithOAuth2Request, SignInWithOAuth2Response, SignUpRequest, TokenRefreshRequest, TokenRefreshResponse, VerifyEmailRequest };
135
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1,176 @@
1
+ import { t as wrappedFetch } from "../fetch-Cp9z9f4v.js";
2
+ import { parse } from "cookie";
3
+
4
+ //#region src/plugins/email-password/plugin.ts
5
+ var EmailPasswordPlugin = class {
6
+ id = "emailPassword";
7
+ init(client) {
8
+ return {
9
+ signUp: async (data) => {
10
+ return wrappedFetch(client, "/sign-up", {
11
+ method: "POST",
12
+ body: data
13
+ });
14
+ },
15
+ signIn: async (data) => {
16
+ return wrappedFetch(client, "/sign-in", {
17
+ method: "POST",
18
+ body: data
19
+ });
20
+ },
21
+ sendEmailVerification: async (data) => {
22
+ return wrappedFetch(client, `/send-email-verification`, {
23
+ method: "POST",
24
+ body: data
25
+ });
26
+ },
27
+ requestPasswordReset: async (data) => {
28
+ return wrappedFetch(client, `/request-password-reset`, {
29
+ method: "POST",
30
+ body: data
31
+ });
32
+ },
33
+ changePassword: async (data) => {
34
+ return wrappedFetch(client, `/change-password`, {
35
+ method: "POST",
36
+ body: data
37
+ });
38
+ },
39
+ requestEmailChange: async (data) => {
40
+ return wrappedFetch(client, `/request-email-change`, {
41
+ method: "POST",
42
+ body: data
43
+ });
44
+ }
45
+ };
46
+ }
47
+ };
48
+
49
+ //#endregion
50
+ //#region src/plugins/oauth2/plugin.ts
51
+ var OAuth2Plugin = class {
52
+ id = "oauth2";
53
+ init(client) {
54
+ return { signIn: async (data) => {
55
+ return wrappedFetch(client, `/oauth2/authorize/${data.provider}?redirect_to=${data.redirect_to}`, { method: "GET" });
56
+ } };
57
+ }
58
+ };
59
+
60
+ //#endregion
61
+ //#region src/plugins/csrf/plugin.ts
62
+ var CSRFPlugin = class {
63
+ id = "csrf";
64
+ constructor(options) {
65
+ this.options = options;
66
+ }
67
+ init(client) {
68
+ client.registerBeforeFetch(async (ctx) => {
69
+ if (typeof document !== "undefined") {
70
+ if ([
71
+ "OPTIONS",
72
+ "HEAD",
73
+ "GET"
74
+ ].includes(ctx.init.method || "GET")) return;
75
+ const value = parse(document.cookie)[this.options.cookieName];
76
+ if (!value) return;
77
+ ctx.init.headers = new Headers(ctx.init.headers);
78
+ ctx.init.headers.set(this.options.headerName, value);
79
+ return;
80
+ }
81
+ if (this.cookies) {
82
+ if ([
83
+ "OPTIONS",
84
+ "HEAD",
85
+ "GET"
86
+ ].includes(ctx.init.method || "GET")) return;
87
+ const cookie = (await this.cookies()).get(this.options.cookieName);
88
+ if (!cookie) return;
89
+ ctx.init.headers = new Headers(ctx.init.headers);
90
+ ctx.init.headers.set(this.options.headerName, cookie.value);
91
+ }
92
+ });
93
+ return {};
94
+ }
95
+ cookies;
96
+ attachCookies(fn) {
97
+ this.cookies = fn;
98
+ }
99
+ };
100
+
101
+ //#endregion
102
+ //#region src/plugins/jwt/plugin.ts
103
+ var JWTPlugin = class {
104
+ id = "jwt";
105
+ constructor() {}
106
+ init(client) {
107
+ return {
108
+ refreshToken: async (data) => {
109
+ return wrappedFetch(client, "/token/refresh", {
110
+ method: "POST",
111
+ body: data
112
+ });
113
+ },
114
+ getJWKSKeys: async () => {
115
+ return wrappedFetch(client, "/.well-known/jwks.json", { method: "GET" });
116
+ }
117
+ };
118
+ }
119
+ };
120
+
121
+ //#endregion
122
+ //#region src/plugins/bearer/plugin.ts
123
+ var BearerPlugin = class {
124
+ id = "bearer";
125
+ refreshPromise = null;
126
+ constructor(options) {
127
+ this.options = options;
128
+ }
129
+ init(client) {
130
+ client.registerBeforeFetch(async (ctx) => {
131
+ if (typeof document === "undefined") return;
132
+ const headerName = this.options?.headerName ?? "Authorization";
133
+ const token = localStorage.getItem("accessToken");
134
+ if (token) ctx.init.headers = {
135
+ ...ctx.init.headers,
136
+ [headerName]: `Bearer ${token}`
137
+ };
138
+ });
139
+ client.registerAfterFetch(async (ctx, res) => {
140
+ if (typeof document === "undefined") return;
141
+ if (res.status !== 401) return;
142
+ if (ctx.meta.retry) return;
143
+ const refreshToken = localStorage.getItem("refreshToken");
144
+ if (!refreshToken) return;
145
+ if (!client.jwt) {
146
+ console.warn("JWT Plugin is required for Bearer token refresh.");
147
+ return;
148
+ }
149
+ if (!this.refreshPromise) this.refreshPromise = (async () => {
150
+ try {
151
+ const response = await client.jwt.refreshToken({ refresh_token: refreshToken });
152
+ if (!response) return null;
153
+ localStorage.setItem("accessToken", response.access_token);
154
+ localStorage.setItem("refreshToken", response.refresh_token);
155
+ return response;
156
+ } finally {
157
+ this.refreshPromise = null;
158
+ }
159
+ })();
160
+ const refreshed = await this.refreshPromise;
161
+ if (!refreshed) return;
162
+ const headerName = this.options?.headerName ?? "Authorization";
163
+ ctx.init.headers = {
164
+ ...ctx.init.headers,
165
+ [headerName]: `Bearer ${refreshed.access_token}`
166
+ };
167
+ ctx.meta.retry = true;
168
+ return "retry";
169
+ });
170
+ return {};
171
+ }
172
+ };
173
+
174
+ //#endregion
175
+ export { BearerPlugin, CSRFPlugin, EmailPasswordPlugin, JWTPlugin, OAuth2Plugin };
176
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/plugins/email-password/plugin.ts","../../src/plugins/oauth2/plugin.ts","../../src/plugins/csrf/plugin.ts","../../src/plugins/jwt/plugin.ts","../../src/plugins/bearer/plugin.ts"],"sourcesContent":["import type { GoBetterAuthClient } from \"@/client\";\nimport { wrappedFetch } from \"@/fetch\";\nimport type { Plugin } from \"@/types\";\nimport type {\n ChangePasswordRequest,\n RequestEmailChangeRequest,\n RequestPasswordResetRequest,\n SendEmailVerificationRequest,\n SignInRequest,\n SignUpRequest,\n} from \"./types\";\n\nexport class EmailPasswordPlugin implements Plugin {\n public readonly id = \"emailPassword\";\n\n public init(client: GoBetterAuthClient) {\n return {\n signUp: async <T>(data: SignUpRequest): Promise<T> => {\n return wrappedFetch<T>(client, \"/sign-up\", {\n method: \"POST\",\n body: data,\n });\n },\n signIn: async <T>(data: SignInRequest): Promise<T> => {\n return wrappedFetch<T>(client, \"/sign-in\", {\n method: \"POST\",\n body: data,\n });\n },\n sendEmailVerification: async (\n data: SendEmailVerificationRequest,\n ): Promise<void> => {\n return wrappedFetch(client, `/send-email-verification`, {\n method: \"POST\",\n body: data,\n });\n },\n requestPasswordReset: async (\n data: RequestPasswordResetRequest,\n ): Promise<void> => {\n return wrappedFetch(client, `/request-password-reset`, {\n method: \"POST\",\n body: data,\n });\n },\n changePassword: async (data: ChangePasswordRequest): Promise<void> => {\n return wrappedFetch(client, `/change-password`, {\n method: \"POST\",\n body: data,\n });\n },\n requestEmailChange: async (\n data: RequestEmailChangeRequest,\n ): Promise<void> => {\n return wrappedFetch(client, `/request-email-change`, {\n method: \"POST\",\n body: data,\n });\n },\n };\n }\n}\n","import type { GoBetterAuthClient } from \"@/client\";\nimport { wrappedFetch } from \"@/fetch\";\nimport type { Plugin } from \"@/types/plugins\";\nimport type {\n SignInWithOAuth2Request,\n SignInWithOAuth2Response,\n} from \"./types\";\n\nexport class OAuth2Plugin implements Plugin {\n public readonly id = \"oauth2\";\n\n public init(client: GoBetterAuthClient) {\n return {\n signIn: async (\n data: SignInWithOAuth2Request,\n ): Promise<SignInWithOAuth2Response> => {\n return wrappedFetch(\n client,\n `/oauth2/authorize/${data.provider}?redirect_to=${data.redirect_to}`,\n {\n method: \"GET\",\n },\n );\n },\n };\n }\n}\n","import { parse } from \"cookie\";\n\nimport type { FetchContext, Plugin } from \"@/types\";\nimport type { CSRFPluginOptions } from \"./types\";\nimport type { GoBetterAuthClient } from \"@/client\";\n\nexport class CSRFPlugin implements Plugin {\n public readonly id = \"csrf\";\n\n constructor(private readonly options: CSRFPluginOptions) {}\n\n public init(client: GoBetterAuthClient) {\n client.registerBeforeFetch(async (ctx: FetchContext) => {\n // Client-side\n if (typeof document !== \"undefined\") {\n if ([\"OPTIONS\", \"HEAD\", \"GET\"].includes(ctx.init.method || \"GET\")) {\n return;\n }\n\n const cookies = parse(document.cookie);\n const value = cookies[this.options.cookieName];\n\n if (!value) return;\n\n ctx.init.headers = new Headers(ctx.init.headers);\n ctx.init.headers.set(this.options.headerName, value);\n return;\n }\n\n // SSR\n if (this.cookies) {\n if ([\"OPTIONS\", \"HEAD\", \"GET\"].includes(ctx.init.method || \"GET\")) {\n return;\n }\n\n const store = await this.cookies();\n const cookie = store.get(this.options.cookieName);\n\n if (!cookie) return;\n\n ctx.init.headers = new Headers(ctx.init.headers);\n ctx.init.headers.set(this.options.headerName, cookie.value);\n }\n });\n\n return {};\n }\n\n // Injected by client\n private cookies?: () => Promise<any>;\n attachCookies(fn: () => Promise<any>) {\n this.cookies = fn;\n }\n}\n","import type { GoBetterAuthClient } from \"@/client\";\nimport { wrappedFetch } from \"@/fetch\";\nimport type { Plugin } from \"@/types\";\nimport type {\n JWKSKey,\n TokenRefreshRequest,\n TokenRefreshResponse,\n} from \"./types\";\n\nexport class JWTPlugin implements Plugin {\n public readonly id = \"jwt\";\n\n constructor() {}\n\n public init(client: GoBetterAuthClient) {\n return {\n refreshToken: async (\n data: TokenRefreshRequest,\n ): Promise<TokenRefreshResponse> => {\n return wrappedFetch(client, \"/token/refresh\", {\n method: \"POST\",\n body: data,\n });\n },\n getJWKSKeys: async (): Promise<Array<JWKSKey>> => {\n return wrappedFetch(client, \"/.well-known/jwks.json\", {\n method: \"GET\",\n });\n },\n };\n }\n}\n","import type { FetchContext, Plugin } from \"@/types\";\nimport type { BearerPluginOptions } from \"./types\";\nimport type { JWTPlugin } from \"../jwt/plugin\";\nimport type { ClientWithPlugins } from \"@/sdk\";\n\nexport class BearerPlugin implements Plugin {\n public readonly id = \"bearer\";\n private refreshPromise: Promise<any> | null = null;\n\n constructor(private readonly options?: BearerPluginOptions) {}\n\n public init(client: ClientWithPlugins<[JWTPlugin]>) {\n client.registerBeforeFetch(async (ctx: FetchContext) => {\n if (typeof document === \"undefined\") {\n return;\n }\n\n const headerName = this.options?.headerName ?? \"Authorization\";\n const token = localStorage.getItem(\"accessToken\");\n if (token) {\n ctx.init.headers = {\n ...ctx.init.headers,\n [headerName]: `Bearer ${token}`,\n };\n }\n });\n\n client.registerAfterFetch(async (ctx: FetchContext, res: Response) => {\n if (typeof document === \"undefined\") return;\n if (res.status !== 401) return;\n if (ctx.meta.retry) return;\n\n const refreshToken = localStorage.getItem(\"refreshToken\");\n if (!refreshToken) return;\n\n if (!client.jwt) {\n console.warn(\"JWT Plugin is required for Bearer token refresh.\");\n return;\n }\n\n // 🔒 SINGLE FLIGHT REFRESH\n if (!this.refreshPromise) {\n this.refreshPromise = (async () => {\n try {\n const response = await client.jwt.refreshToken({\n refresh_token: refreshToken,\n });\n\n if (!response) return null;\n\n localStorage.setItem(\"accessToken\", response.access_token);\n localStorage.setItem(\"refreshToken\", response.refresh_token);\n\n return response;\n } finally {\n this.refreshPromise = null;\n }\n })();\n }\n\n const refreshed = await this.refreshPromise;\n if (!refreshed) return;\n\n const headerName = this.options?.headerName ?? \"Authorization\";\n ctx.init.headers = {\n ...ctx.init.headers,\n [headerName]: `Bearer ${refreshed.access_token}`,\n };\n\n ctx.meta.retry = true;\n return \"retry\";\n });\n\n return {};\n }\n}\n"],"mappings":";;;;AAYA,IAAa,sBAAb,MAAmD;CACjD,AAAgB,KAAK;CAErB,AAAO,KAAK,QAA4B;AACt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e;AACzD,OAAI,CAAC,aAAc;AAEnB,OAAI,CAAC,OAAO,KAAK;AACf,YAAQ,KAAK,mDAAmD;AAChE;;AAIF,OAAI,CAAC,KAAK,eACR,MAAK,kBAAkB,YAAY;AACjC,QAAI;KACF,MAAM,WAAW,MAAM,OAAO,IAAI,aAAa,EAC7C,eAAe,cAChB,CAAC;AAEF,SAAI,CAAC,SAAU,QAAO;AAEtB,kBAAa,QAAQ,eAAe,SAAS,aAAa;AAC1D,kBAAa,QAAQ,gBAAgB,SAAS,cAAc;AAE5D,YAAO;cACC;AACR,UAAK,iBAAiB;;OAEtB;GAGN,MAAM,YAAY,MAAM,KAAK;AAC7B,OAAI,CAAC,UAAW;GAEhB,MAAM,aAAa,KAAK,SAAS,cAAc;AAC/C,OAAI,KAAK,UAAU;IACjB,GAAG,IAAI,KAAK;KACX,aAAa,UAAU,UAAU;IACnC;AAED,OAAI,KAAK,QAAQ;AACjB,UAAO;IACP;AAEF,SAAO,EAAE"}
@@ -0,0 +1,162 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/types/http.d.ts
4
+ type FetchContext = {
5
+ url: string;
6
+ init: RequestInit; /** internal metadata for plugins */
7
+ meta: {
8
+ retry?: boolean;
9
+ };
10
+ };
11
+ type BeforeFetchHook = (ctx: FetchContext) => Promise<void> | void;
12
+ type AfterFetchHook = (ctx: FetchContext, res: Response) => Promise<"retry" | void> | "retry" | void;
13
+ /**
14
+ * Fetch options for internal API calls
15
+ */
16
+ type FetchRequestOptions = {
17
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
18
+ headers?: Record<string, string>;
19
+ body?: Record<string, unknown>;
20
+ callbackUrl?: string;
21
+ };
22
+ //#endregion
23
+ //#region src/types/schemas.d.ts
24
+ declare const userSchema: z.ZodObject<{
25
+ id: z.ZodUUID;
26
+ name: z.ZodString;
27
+ email: z.ZodEmail;
28
+ email_verified: z.ZodBoolean;
29
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
+ created_at: z.ZodISODateTime;
31
+ updated_at: z.ZodISODateTime;
32
+ }, z.core.$strip>;
33
+ type User = z.infer<typeof userSchema>;
34
+ declare const accountSchema: z.ZodObject<{
35
+ id: z.ZodUUID;
36
+ user_id: z.ZodString;
37
+ account_id: z.ZodString;
38
+ provider_id: z.ZodString;
39
+ access_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
40
+ refresh_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
41
+ id_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
42
+ access_token_expires_at: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
43
+ refresh_token_expires_at: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
44
+ scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
+ password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
+ created_at: z.ZodISODateTime;
47
+ updated_at: z.ZodISODateTime;
48
+ }, z.core.$strip>;
49
+ type Account = z.infer<typeof accountSchema>;
50
+ declare const sessionSchema: z.ZodObject<{
51
+ id: z.ZodUUID;
52
+ user_id: z.ZodString;
53
+ token: z.ZodString;
54
+ expires_at: z.ZodISODateTime;
55
+ ip_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ user_agent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
57
+ created_at: z.ZodISODateTime;
58
+ updated_at: z.ZodISODateTime;
59
+ }, z.core.$strip>;
60
+ type Session = z.infer<typeof sessionSchema>;
61
+ declare const verificationTypeSchema: z.ZodEnum<{
62
+ email_verification: "email_verification";
63
+ password_reset_request: "password_reset_request";
64
+ email_reset_request: "email_reset_request";
65
+ }>;
66
+ type VerificationType = z.infer<typeof verificationTypeSchema>;
67
+ declare const verificationSchema: z.ZodObject<{
68
+ id: z.ZodUUID;
69
+ user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
70
+ identifier: z.ZodString;
71
+ token: z.ZodString;
72
+ type: z.ZodEnum<{
73
+ email_verification: "email_verification";
74
+ password_reset_request: "password_reset_request";
75
+ email_reset_request: "email_reset_request";
76
+ }>;
77
+ expires_at: z.ZodISODateTime;
78
+ created_at: z.ZodISODateTime;
79
+ updated_at: z.ZodISODateTime;
80
+ }, z.core.$strip>;
81
+ type Verification = z.infer<typeof verificationSchema>;
82
+ //#endregion
83
+ //#region src/types/cookies.d.ts
84
+ type CookieStore = {
85
+ getAll(): {
86
+ name: string;
87
+ value: string;
88
+ }[];
89
+ set(name: string, value: string, options?: Record<string, any>): void;
90
+ delete?(name: string): void;
91
+ };
92
+ type CookieProvider = (() => Promise<CookieStore>) | (() => CookieStore);
93
+ //#endregion
94
+ //#region src/client.d.ts
95
+ declare class GoBetterAuthClient {
96
+ readonly config: GoBetterAuthClientConfig;
97
+ private readonly plugins;
98
+ private readonly beforeFetchHooks;
99
+ private readonly afterFetchHooks;
100
+ constructor(options: GoBetterAuthClientOptions);
101
+ registerBeforeFetch(hook: BeforeFetchHook): void;
102
+ registerAfterFetch(hook: AfterFetchHook): void;
103
+ runBeforeFetch(ctx: FetchContext): Promise<void>;
104
+ runAfterFetch(ctx: FetchContext, res: Response): Promise<"retry" | undefined>;
105
+ getMe<T = unknown>(): Promise<T>;
106
+ signOut(data: SignOutRequest): Promise<SignOutResponse>;
107
+ getPlugin<T extends Plugin>(id: string): T | undefined;
108
+ }
109
+ //#endregion
110
+ //#region src/types/plugins.d.ts
111
+ interface Plugin {
112
+ readonly id: string;
113
+ init(client: GoBetterAuthClient): any;
114
+ }
115
+ //#endregion
116
+ //#region src/types/config.d.ts
117
+ type FetchOptions = {
118
+ /**
119
+ * The abort timeout in seconds
120
+ */
121
+ abortTimeout?: number;
122
+ };
123
+ type GoBetterAuthClientConfig = {
124
+ /**
125
+ * The URL of your GoBetterAuth server
126
+ * @example 'http://localhost:8080/auth'
127
+ */
128
+ url: string;
129
+ fetchOptions?: FetchOptions;
130
+ cookies?: CookieProvider;
131
+ };
132
+ type GoBetterAuthClientOptions = GoBetterAuthClientConfig & {
133
+ /**
134
+ * The list of plugins to use
135
+ */
136
+ plugins: Array<Plugin>;
137
+ };
138
+ //#endregion
139
+ //#region src/types/methods.d.ts
140
+ type GetMeResponse = {
141
+ user: User;
142
+ session: Session;
143
+ };
144
+ type SignOutRequest = {
145
+ session_id?: string;
146
+ sign_out_all?: boolean;
147
+ };
148
+ type SignOutResponse = {
149
+ message: string;
150
+ };
151
+ //#endregion
152
+ //#region src/sdk.d.ts
153
+ type InferPluginMethods<P> = P extends {
154
+ init: (client: any) => infer M;
155
+ } ? M : never;
156
+ type ClientWithPlugins<T extends readonly Plugin[]> = GoBetterAuthClient & { [P in T[number] as P["id"]]: InferPluginMethods<P> };
157
+ declare function createClient<const T extends readonly Plugin[]>(options: Omit<GoBetterAuthClientOptions, "plugins"> & {
158
+ plugins: T;
159
+ }): ClientWithPlugins<T>;
160
+ //#endregion
161
+ export { AfterFetchHook as C, FetchRequestOptions as E, verificationTypeSchema as S, FetchContext as T, VerificationType as _, SignOutResponse as a, userSchema as b, GoBetterAuthClientOptions as c, CookieProvider as d, CookieStore as f, Verification as g, User as h, SignOutRequest as i, Plugin as l, Session as m, createClient as n, FetchOptions as o, Account as p, GetMeResponse as r, GoBetterAuthClientConfig as s, ClientWithPlugins as t, GoBetterAuthClient as u, accountSchema as v, BeforeFetchHook as w, verificationSchema as x, sessionSchema as y };
162
+ //# sourceMappingURL=sdk-DJhCsA2I.d.ts.map
@@ -0,0 +1,162 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/types/http.d.ts
4
+ type FetchContext = {
5
+ url: string;
6
+ init: RequestInit; /** internal metadata for plugins */
7
+ meta: {
8
+ retry?: boolean;
9
+ };
10
+ };
11
+ type BeforeFetchHook = (ctx: FetchContext) => Promise<void> | void;
12
+ type AfterFetchHook = (ctx: FetchContext, res: Response) => Promise<"retry" | void> | "retry" | void;
13
+ /**
14
+ * Fetch options for internal API calls
15
+ */
16
+ type FetchRequestOptions = {
17
+ method?: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
18
+ headers?: Record<string, string>;
19
+ body?: Record<string, unknown>;
20
+ callbackUrl?: string;
21
+ };
22
+ //#endregion
23
+ //#region src/types/schemas.d.ts
24
+ declare const userSchema: z.ZodObject<{
25
+ id: z.ZodUUID;
26
+ name: z.ZodString;
27
+ email: z.ZodEmail;
28
+ email_verified: z.ZodBoolean;
29
+ image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
+ created_at: z.ZodISODateTime;
31
+ updated_at: z.ZodISODateTime;
32
+ }, z.core.$strip>;
33
+ type User = z.infer<typeof userSchema>;
34
+ declare const accountSchema: z.ZodObject<{
35
+ id: z.ZodUUID;
36
+ user_id: z.ZodString;
37
+ account_id: z.ZodString;
38
+ provider_id: z.ZodString;
39
+ access_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
40
+ refresh_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
41
+ id_token: z.ZodOptional<z.ZodNullable<z.ZodString>>;
42
+ access_token_expires_at: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
43
+ refresh_token_expires_at: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
44
+ scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
+ password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
+ created_at: z.ZodISODateTime;
47
+ updated_at: z.ZodISODateTime;
48
+ }, z.core.$strip>;
49
+ type Account = z.infer<typeof accountSchema>;
50
+ declare const sessionSchema: z.ZodObject<{
51
+ id: z.ZodUUID;
52
+ user_id: z.ZodString;
53
+ token: z.ZodString;
54
+ expires_at: z.ZodISODateTime;
55
+ ip_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ user_agent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
57
+ created_at: z.ZodISODateTime;
58
+ updated_at: z.ZodISODateTime;
59
+ }, z.core.$strip>;
60
+ type Session = z.infer<typeof sessionSchema>;
61
+ declare const verificationTypeSchema: z.ZodEnum<{
62
+ email_verification: "email_verification";
63
+ password_reset_request: "password_reset_request";
64
+ email_reset_request: "email_reset_request";
65
+ }>;
66
+ type VerificationType = z.infer<typeof verificationTypeSchema>;
67
+ declare const verificationSchema: z.ZodObject<{
68
+ id: z.ZodUUID;
69
+ user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
70
+ identifier: z.ZodString;
71
+ token: z.ZodString;
72
+ type: z.ZodEnum<{
73
+ email_verification: "email_verification";
74
+ password_reset_request: "password_reset_request";
75
+ email_reset_request: "email_reset_request";
76
+ }>;
77
+ expires_at: z.ZodISODateTime;
78
+ created_at: z.ZodISODateTime;
79
+ updated_at: z.ZodISODateTime;
80
+ }, z.core.$strip>;
81
+ type Verification = z.infer<typeof verificationSchema>;
82
+ //#endregion
83
+ //#region src/types/cookies.d.ts
84
+ type CookieStore = {
85
+ getAll(): {
86
+ name: string;
87
+ value: string;
88
+ }[];
89
+ set(name: string, value: string, options?: Record<string, any>): void;
90
+ delete?(name: string): void;
91
+ };
92
+ type CookieProvider = (() => Promise<CookieStore>) | (() => CookieStore);
93
+ //#endregion
94
+ //#region src/client.d.ts
95
+ declare class GoBetterAuthClient {
96
+ readonly config: GoBetterAuthClientConfig;
97
+ private readonly plugins;
98
+ private readonly beforeFetchHooks;
99
+ private readonly afterFetchHooks;
100
+ constructor(options: GoBetterAuthClientOptions);
101
+ registerBeforeFetch(hook: BeforeFetchHook): void;
102
+ registerAfterFetch(hook: AfterFetchHook): void;
103
+ runBeforeFetch(ctx: FetchContext): Promise<void>;
104
+ runAfterFetch(ctx: FetchContext, res: Response): Promise<"retry" | undefined>;
105
+ getMe<T = unknown>(): Promise<T>;
106
+ signOut(data: SignOutRequest): Promise<SignOutResponse>;
107
+ getPlugin<T extends Plugin>(id: string): T | undefined;
108
+ }
109
+ //#endregion
110
+ //#region src/types/plugins.d.ts
111
+ interface Plugin {
112
+ readonly id: string;
113
+ init(client: GoBetterAuthClient): any;
114
+ }
115
+ //#endregion
116
+ //#region src/types/config.d.ts
117
+ type FetchOptions = {
118
+ /**
119
+ * The abort timeout in seconds
120
+ */
121
+ abortTimeout?: number;
122
+ };
123
+ type GoBetterAuthClientConfig = {
124
+ /**
125
+ * The URL of your GoBetterAuth server
126
+ * @example 'http://localhost:8080/auth'
127
+ */
128
+ url: string;
129
+ fetchOptions?: FetchOptions;
130
+ cookies?: CookieProvider;
131
+ };
132
+ type GoBetterAuthClientOptions = GoBetterAuthClientConfig & {
133
+ /**
134
+ * The list of plugins to use
135
+ */
136
+ plugins: Array<Plugin>;
137
+ };
138
+ //#endregion
139
+ //#region src/types/methods.d.ts
140
+ type GetMeResponse = {
141
+ user: User;
142
+ session: Session;
143
+ };
144
+ type SignOutRequest = {
145
+ session_id?: string;
146
+ sign_out_all?: boolean;
147
+ };
148
+ type SignOutResponse = {
149
+ message: string;
150
+ };
151
+ //#endregion
152
+ //#region src/sdk.d.ts
153
+ type InferPluginMethods<P> = P extends {
154
+ init: (client: any) => infer M;
155
+ } ? M : never;
156
+ type ClientWithPlugins<T extends readonly Plugin[]> = GoBetterAuthClient & { [P in T[number] as P["id"]]: InferPluginMethods<P> };
157
+ declare function createClient<const T extends readonly Plugin[]>(options: Omit<GoBetterAuthClientOptions, "plugins"> & {
158
+ plugins: T;
159
+ }): ClientWithPlugins<T>;
160
+ //#endregion
161
+ export { AfterFetchHook as C, FetchRequestOptions as E, verificationTypeSchema as S, FetchContext as T, VerificationType as _, SignOutResponse as a, userSchema as b, GoBetterAuthClientOptions as c, CookieProvider as d, CookieStore as f, Verification as g, User as h, SignOutRequest as i, Plugin as l, Session as m, createClient as n, FetchOptions as o, Account as p, GetMeResponse as r, GoBetterAuthClientConfig as s, ClientWithPlugins as t, GoBetterAuthClient as u, accountSchema as v, BeforeFetchHook as w, verificationSchema as x, sessionSchema as y };
162
+ //# sourceMappingURL=sdk-cpbPBWuc.d.cts.map