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.
package/dist/index.cjs ADDED
@@ -0,0 +1,114 @@
1
+ const require_fetch = require('./fetch-v3PWCtqe.cjs');
2
+ let zod = require("zod");
3
+
4
+ //#region src/types/schemas.ts
5
+ const userSchema = zod.z.object({
6
+ id: zod.z.uuid(),
7
+ name: zod.z.string().nonempty(),
8
+ email: zod.z.email(),
9
+ email_verified: zod.z.boolean(),
10
+ image: zod.z.string().nullish(),
11
+ created_at: zod.z.iso.datetime(),
12
+ updated_at: zod.z.iso.datetime()
13
+ });
14
+ const accountSchema = zod.z.object({
15
+ id: zod.z.uuid(),
16
+ user_id: zod.z.string().nonempty(),
17
+ account_id: zod.z.string().nonempty(),
18
+ provider_id: zod.z.string().nonempty(),
19
+ access_token: zod.z.string().nullish(),
20
+ refresh_token: zod.z.string().nullish(),
21
+ id_token: zod.z.string().nullish(),
22
+ access_token_expires_at: zod.z.iso.datetime().nullish(),
23
+ refresh_token_expires_at: zod.z.iso.datetime().nullish(),
24
+ scope: zod.z.string().nullish(),
25
+ password: zod.z.string().nullish(),
26
+ created_at: zod.z.iso.datetime(),
27
+ updated_at: zod.z.iso.datetime()
28
+ });
29
+ const sessionSchema = zod.z.object({
30
+ id: zod.z.uuid(),
31
+ user_id: zod.z.string().nonempty(),
32
+ token: zod.z.string().nonempty(),
33
+ expires_at: zod.z.iso.datetime(),
34
+ ip_address: zod.z.string().nullish(),
35
+ user_agent: zod.z.string().nullish(),
36
+ created_at: zod.z.iso.datetime(),
37
+ updated_at: zod.z.iso.datetime()
38
+ });
39
+ const verificationTypeSchema = zod.z.enum([
40
+ "email_verification",
41
+ "password_reset_request",
42
+ "email_reset_request"
43
+ ]);
44
+ const verificationSchema = zod.z.object({
45
+ id: zod.z.uuid(),
46
+ user_id: zod.z.string().nullish(),
47
+ identifier: zod.z.string().nonempty(),
48
+ token: zod.z.string().nonempty(),
49
+ type: verificationTypeSchema,
50
+ expires_at: zod.z.iso.datetime(),
51
+ created_at: zod.z.iso.datetime(),
52
+ updated_at: zod.z.iso.datetime()
53
+ });
54
+
55
+ //#endregion
56
+ //#region src/client.ts
57
+ var GoBetterAuthClient = class {
58
+ config;
59
+ plugins;
60
+ beforeFetchHooks = [];
61
+ afterFetchHooks = [];
62
+ constructor(options) {
63
+ this.plugins = options.plugins;
64
+ const { plugins, ...rest } = options;
65
+ this.config = rest;
66
+ for (const plugin of this.plugins) {
67
+ if ("attachCookies" in plugin && this.config.cookies) plugin.attachCookies(this.config.cookies);
68
+ this[plugin.id] = plugin.init(this);
69
+ }
70
+ }
71
+ registerBeforeFetch(hook) {
72
+ this.beforeFetchHooks.push(hook);
73
+ }
74
+ registerAfterFetch(hook) {
75
+ this.afterFetchHooks.push(hook);
76
+ }
77
+ async runBeforeFetch(ctx) {
78
+ for (const hook of this.beforeFetchHooks) await hook(ctx);
79
+ }
80
+ async runAfterFetch(ctx, res) {
81
+ for (const hook of this.afterFetchHooks) if (await hook(ctx, res) === "retry") return "retry";
82
+ }
83
+ async getMe() {
84
+ return require_fetch.wrappedFetch(this, "/me", { method: "GET" });
85
+ }
86
+ async signOut(data) {
87
+ return require_fetch.wrappedFetch(this, "/sign-out", {
88
+ method: "POST",
89
+ body: data.session_id ? {
90
+ session_id: data.session_id,
91
+ sign_out_all: data.sign_out_all
92
+ } : {}
93
+ });
94
+ }
95
+ getPlugin(id) {
96
+ return this.plugins.find((plugin) => plugin.id === id);
97
+ }
98
+ };
99
+
100
+ //#endregion
101
+ //#region src/sdk.ts
102
+ function createClient(options) {
103
+ return new GoBetterAuthClient(options);
104
+ }
105
+
106
+ //#endregion
107
+ exports.GoBetterAuthClient = GoBetterAuthClient;
108
+ exports.accountSchema = accountSchema;
109
+ exports.createClient = createClient;
110
+ exports.sessionSchema = sessionSchema;
111
+ exports.userSchema = userSchema;
112
+ exports.verificationSchema = verificationSchema;
113
+ exports.verificationTypeSchema = verificationTypeSchema;
114
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["z","wrappedFetch"],"sources":["../src/types/schemas.ts","../src/client.ts","../src/sdk.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const userSchema = z.object({\n id: z.uuid(),\n name: z.string().nonempty(),\n email: z.email(),\n email_verified: z.boolean(),\n image: z.string().nullish(),\n created_at: z.iso.datetime(),\n updated_at: z.iso.datetime(),\n});\nexport type User = z.infer<typeof userSchema>;\n\nexport const accountSchema = z.object({\n id: z.uuid(),\n user_id: z.string().nonempty(),\n account_id: z.string().nonempty(),\n provider_id: z.string().nonempty(),\n access_token: z.string().nullish(),\n refresh_token: z.string().nullish(),\n id_token: z.string().nullish(),\n access_token_expires_at: z.iso.datetime().nullish(),\n refresh_token_expires_at: z.iso.datetime().nullish(),\n scope: z.string().nullish(),\n password: z.string().nullish(),\n created_at: z.iso.datetime(),\n updated_at: z.iso.datetime(),\n});\nexport type Account = z.infer<typeof accountSchema>;\n\nexport const sessionSchema = z.object({\n id: z.uuid(),\n user_id: z.string().nonempty(),\n token: z.string().nonempty(),\n expires_at: z.iso.datetime(),\n ip_address: z.string().nullish(),\n user_agent: z.string().nullish(),\n created_at: z.iso.datetime(),\n updated_at: z.iso.datetime(),\n});\nexport type Session = z.infer<typeof sessionSchema>;\n\nexport const verificationTypeSchema = z.enum([\n \"email_verification\",\n \"password_reset_request\",\n \"email_reset_request\",\n]);\nexport type VerificationType = z.infer<typeof verificationTypeSchema>;\n\nexport const verificationSchema = z.object({\n id: z.uuid(),\n user_id: z.string().nullish(),\n identifier: z.string().nonempty(),\n token: z.string().nonempty(),\n type: verificationTypeSchema,\n expires_at: z.iso.datetime(),\n created_at: z.iso.datetime(),\n updated_at: z.iso.datetime(),\n});\nexport type Verification = z.infer<typeof verificationSchema>;\n","import { wrappedFetch } from \"./fetch\";\nimport type {\n FetchContext,\n GoBetterAuthClientConfig,\n GoBetterAuthClientOptions,\n SignOutRequest,\n SignOutResponse,\n Plugin,\n BeforeFetchHook,\n AfterFetchHook,\n} from \"./types\";\n\nexport class GoBetterAuthClient {\n public readonly config: GoBetterAuthClientConfig;\n private readonly plugins: Array<Plugin>;\n private readonly beforeFetchHooks: BeforeFetchHook[] = [];\n private readonly afterFetchHooks: AfterFetchHook[] = [];\n\n constructor(options: GoBetterAuthClientOptions) {\n this.plugins = options.plugins;\n\n const { plugins, ...rest } = options;\n this.config = rest;\n\n for (const plugin of this.plugins) {\n if (\"attachCookies\" in plugin && this.config.cookies) {\n (plugin as any).attachCookies(this.config.cookies);\n }\n\n (this as any)[plugin.id] = plugin.init(this);\n }\n }\n\n public registerBeforeFetch(hook: BeforeFetchHook) {\n this.beforeFetchHooks.push(hook);\n }\n\n public registerAfterFetch(hook: AfterFetchHook) {\n this.afterFetchHooks.push(hook);\n }\n\n public async runBeforeFetch(ctx: FetchContext) {\n for (const hook of this.beforeFetchHooks) {\n await hook(ctx);\n }\n }\n\n public async runAfterFetch(ctx: FetchContext, res: Response) {\n for (const hook of this.afterFetchHooks) {\n const result = await hook(ctx, res);\n if (result === \"retry\") return \"retry\";\n }\n }\n\n public async getMe<T = unknown>(): Promise<T> {\n return wrappedFetch<T>(this, \"/me\", {\n method: \"GET\",\n });\n }\n\n public async signOut(data: SignOutRequest): Promise<SignOutResponse> {\n return wrappedFetch<SignOutResponse>(this, \"/sign-out\", {\n method: \"POST\",\n body: data.session_id\n ? { session_id: data.session_id, sign_out_all: data.sign_out_all }\n : {},\n });\n }\n\n public getPlugin<T extends Plugin>(id: string): T | undefined {\n return this.plugins.find((plugin) => plugin.id === id) as T | undefined;\n }\n}\n","import { GoBetterAuthClient } from \"./client\";\nimport type { GoBetterAuthClientOptions, Plugin } from \"./types\";\n\n// Helper to extract plugin methods\nexport type InferPluginMethods<P> = P extends { init: (client: any) => infer M }\n ? M\n : never;\n\nexport type ClientWithPlugins<T extends readonly Plugin[]> =\n GoBetterAuthClient & {\n [P in T[number] as P[\"id\"]]: InferPluginMethods<P>;\n };\n\nexport function createClient<const T extends readonly Plugin[]>(\n options: Omit<GoBetterAuthClientOptions, \"plugins\"> & { plugins: T },\n): ClientWithPlugins<T> {\n return new GoBetterAuthClient(options as any) as ClientWithPlugins<T>;\n}\n"],"mappings":";;;;AAEA,MAAa,aAAaA,MAAE,OAAO;CACjC,IAAIA,MAAE,MAAM;CACZ,MAAMA,MAAE,QAAQ,CAAC,UAAU;CAC3B,OAAOA,MAAE,OAAO;CAChB,gBAAgBA,MAAE,SAAS;CAC3B,OAAOA,MAAE,QAAQ,CAAC,SAAS;CAC3B,YAAYA,MAAE,IAAI,UAAU;CAC5B,YAAYA,MAAE,IAAI,UAAU;CAC7B,CAAC;AAGF,MAAa,gBAAgBA,MAAE,OAAO;CACpC,IAAIA,MAAE,MAAM;CACZ,SAASA,MAAE,QAAQ,CAAC,UAAU;CAC9B,YAAYA,MAAE,QAAQ,CAAC,UAAU;CACjC,aAAaA,MAAE,QAAQ,CAAC,UAAU;CAClC,cAAcA,MAAE,QAAQ,CAAC,SAAS;CAClC,eAAeA,MAAE,QAAQ,CAAC,SAAS;CACnC,UAAUA,MAAE,QAAQ,CAAC,SAAS;CAC9B,yBAAyBA,MAAE,IAAI,UAAU,CAAC,SAAS;CACnD,0BAA0BA,MAAE,IAAI,UAAU,CAAC,SAAS;CACpD,OAAOA,MAAE,QAAQ,CAAC,SAAS;CAC3B,UAAUA,MAAE,QAAQ,CAAC,SAAS;CAC9B,YAAYA,MAAE,IAAI,UAAU;CAC5B,YAAYA,MAAE,IAAI,UAAU;CAC7B,CAAC;AAGF,MAAa,gBAAgBA,MAAE,OAAO;CACpC,IAAIA,MAAE,MAAM;CACZ,SAASA,MAAE,QAAQ,CAAC,UAAU;CAC9B,OAAOA,MAAE,QAAQ,CAAC,UAAU;CAC5B,YAAYA,MAAE,IAAI,UAAU;CAC5B,YAAYA,MAAE,QAAQ,CAAC,SAAS;CAChC,YAAYA,MAAE,QAAQ,CAAC,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,CAAC;;CAGJ,MAAa,QAAQ,MAAgD;AACnE,SAAOA,2BAA8B,MAAM,aAAa;GACtD,QAAQ;GACR,MAAM,KAAK,aACP;IAAE,YAAY,KAAK;IAAY,cAAc,KAAK;IAAc,GAChE,EAAE;GACP,CAAC;;CAGJ,AAAO,UAA4B,IAA2B;AAC5D,SAAO,KAAK,QAAQ,MAAM,WAAW,OAAO,OAAO,GAAG;;;;;;ACzD1D,SAAgB,aACd,SACsB;AACtB,QAAO,IAAI,mBAAmB,QAAe"}
@@ -0,0 +1,2 @@
1
+ import { C as AfterFetchHook, E as FetchRequestOptions, S as verificationTypeSchema, T as FetchContext, _ as VerificationType, a as SignOutResponse, b as userSchema, c as GoBetterAuthClientOptions, d as CookieProvider, f as CookieStore, g as Verification, h as User, i as SignOutRequest, l as Plugin, m as Session, n as createClient, o as FetchOptions, p as Account, r as GetMeResponse, s as GoBetterAuthClientConfig, u as GoBetterAuthClient, v as accountSchema, w as BeforeFetchHook, x as verificationSchema, y as sessionSchema } from "./sdk-cpbPBWuc.cjs";
2
+ export { Account, AfterFetchHook, BeforeFetchHook, CookieProvider, CookieStore, FetchContext, FetchOptions, FetchRequestOptions, GetMeResponse, GoBetterAuthClient, GoBetterAuthClientConfig, GoBetterAuthClientOptions, Plugin, Session, SignOutRequest, SignOutResponse, User, Verification, VerificationType, accountSchema, createClient, sessionSchema, userSchema, verificationSchema, verificationTypeSchema };
@@ -0,0 +1,2 @@
1
+ import { C as AfterFetchHook, E as FetchRequestOptions, S as verificationTypeSchema, T as FetchContext, _ as VerificationType, a as SignOutResponse, b as userSchema, c as GoBetterAuthClientOptions, d as CookieProvider, f as CookieStore, g as Verification, h as User, i as SignOutRequest, l as Plugin, m as Session, n as createClient, o as FetchOptions, p as Account, r as GetMeResponse, s as GoBetterAuthClientConfig, u as GoBetterAuthClient, v as accountSchema, w as BeforeFetchHook, x as verificationSchema, y as sessionSchema } from "./sdk-DJhCsA2I.js";
2
+ export { Account, AfterFetchHook, BeforeFetchHook, CookieProvider, CookieStore, FetchContext, FetchOptions, FetchRequestOptions, GetMeResponse, GoBetterAuthClient, GoBetterAuthClientConfig, GoBetterAuthClientOptions, Plugin, Session, SignOutRequest, SignOutResponse, User, Verification, VerificationType, accountSchema, createClient, sessionSchema, userSchema, verificationSchema, verificationTypeSchema };
package/dist/index.js ADDED
@@ -0,0 +1,108 @@
1
+ import { t as wrappedFetch } from "./fetch-Cp9z9f4v.js";
2
+ import { z } from "zod";
3
+
4
+ //#region src/types/schemas.ts
5
+ const userSchema = z.object({
6
+ id: z.uuid(),
7
+ name: z.string().nonempty(),
8
+ email: z.email(),
9
+ email_verified: z.boolean(),
10
+ image: z.string().nullish(),
11
+ created_at: z.iso.datetime(),
12
+ updated_at: z.iso.datetime()
13
+ });
14
+ const accountSchema = z.object({
15
+ id: z.uuid(),
16
+ user_id: z.string().nonempty(),
17
+ account_id: z.string().nonempty(),
18
+ provider_id: z.string().nonempty(),
19
+ access_token: z.string().nullish(),
20
+ refresh_token: z.string().nullish(),
21
+ id_token: z.string().nullish(),
22
+ access_token_expires_at: z.iso.datetime().nullish(),
23
+ refresh_token_expires_at: z.iso.datetime().nullish(),
24
+ scope: z.string().nullish(),
25
+ password: z.string().nullish(),
26
+ created_at: z.iso.datetime(),
27
+ updated_at: z.iso.datetime()
28
+ });
29
+ const sessionSchema = z.object({
30
+ id: z.uuid(),
31
+ user_id: z.string().nonempty(),
32
+ token: z.string().nonempty(),
33
+ expires_at: z.iso.datetime(),
34
+ ip_address: z.string().nullish(),
35
+ user_agent: z.string().nullish(),
36
+ created_at: z.iso.datetime(),
37
+ updated_at: z.iso.datetime()
38
+ });
39
+ const verificationTypeSchema = z.enum([
40
+ "email_verification",
41
+ "password_reset_request",
42
+ "email_reset_request"
43
+ ]);
44
+ const verificationSchema = z.object({
45
+ id: z.uuid(),
46
+ user_id: z.string().nullish(),
47
+ identifier: z.string().nonempty(),
48
+ token: z.string().nonempty(),
49
+ type: verificationTypeSchema,
50
+ expires_at: z.iso.datetime(),
51
+ created_at: z.iso.datetime(),
52
+ updated_at: z.iso.datetime()
53
+ });
54
+
55
+ //#endregion
56
+ //#region src/client.ts
57
+ var GoBetterAuthClient = class {
58
+ config;
59
+ plugins;
60
+ beforeFetchHooks = [];
61
+ afterFetchHooks = [];
62
+ constructor(options) {
63
+ this.plugins = options.plugins;
64
+ const { plugins, ...rest } = options;
65
+ this.config = rest;
66
+ for (const plugin of this.plugins) {
67
+ if ("attachCookies" in plugin && this.config.cookies) plugin.attachCookies(this.config.cookies);
68
+ this[plugin.id] = plugin.init(this);
69
+ }
70
+ }
71
+ registerBeforeFetch(hook) {
72
+ this.beforeFetchHooks.push(hook);
73
+ }
74
+ registerAfterFetch(hook) {
75
+ this.afterFetchHooks.push(hook);
76
+ }
77
+ async runBeforeFetch(ctx) {
78
+ for (const hook of this.beforeFetchHooks) await hook(ctx);
79
+ }
80
+ async runAfterFetch(ctx, res) {
81
+ for (const hook of this.afterFetchHooks) if (await hook(ctx, res) === "retry") return "retry";
82
+ }
83
+ async getMe() {
84
+ return wrappedFetch(this, "/me", { method: "GET" });
85
+ }
86
+ async signOut(data) {
87
+ return wrappedFetch(this, "/sign-out", {
88
+ method: "POST",
89
+ body: data.session_id ? {
90
+ session_id: data.session_id,
91
+ sign_out_all: data.sign_out_all
92
+ } : {}
93
+ });
94
+ }
95
+ getPlugin(id) {
96
+ return this.plugins.find((plugin) => plugin.id === id);
97
+ }
98
+ };
99
+
100
+ //#endregion
101
+ //#region src/sdk.ts
102
+ function createClient(options) {
103
+ return new GoBetterAuthClient(options);
104
+ }
105
+
106
+ //#endregion
107
+ export { GoBetterAuthClient, accountSchema, createClient, sessionSchema, userSchema, verificationSchema, verificationTypeSchema };
108
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/types/schemas.ts","../src/client.ts","../src/sdk.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const userSchema = z.object({\n id: z.uuid(),\n name: z.string().nonempty(),\n email: z.email(),\n email_verified: z.boolean(),\n image: z.string().nullish(),\n created_at: z.iso.datetime(),\n updated_at: z.iso.datetime(),\n});\nexport type User = z.infer<typeof userSchema>;\n\nexport const accountSchema = z.object({\n id: z.uuid(),\n user_id: z.string().nonempty(),\n account_id: z.string().nonempty(),\n provider_id: z.string().nonempty(),\n access_token: z.string().nullish(),\n refresh_token: z.string().nullish(),\n id_token: z.string().nullish(),\n access_token_expires_at: z.iso.datetime().nullish(),\n refresh_token_expires_at: z.iso.datetime().nullish(),\n scope: z.string().nullish(),\n password: z.string().nullish(),\n created_at: z.iso.datetime(),\n updated_at: z.iso.datetime(),\n});\nexport type Account = z.infer<typeof accountSchema>;\n\nexport const sessionSchema = z.object({\n id: z.uuid(),\n user_id: z.string().nonempty(),\n token: z.string().nonempty(),\n expires_at: z.iso.datetime(),\n ip_address: z.string().nullish(),\n user_agent: z.string().nullish(),\n created_at: z.iso.datetime(),\n updated_at: z.iso.datetime(),\n});\nexport type Session = z.infer<typeof sessionSchema>;\n\nexport const verificationTypeSchema = z.enum([\n \"email_verification\",\n \"password_reset_request\",\n \"email_reset_request\",\n]);\nexport type VerificationType = z.infer<typeof verificationTypeSchema>;\n\nexport const verificationSchema = z.object({\n id: z.uuid(),\n user_id: z.string().nullish(),\n identifier: z.string().nonempty(),\n token: z.string().nonempty(),\n type: verificationTypeSchema,\n expires_at: z.iso.datetime(),\n created_at: z.iso.datetime(),\n updated_at: z.iso.datetime(),\n});\nexport type Verification = z.infer<typeof verificationSchema>;\n","import { wrappedFetch } from \"./fetch\";\nimport type {\n FetchContext,\n GoBetterAuthClientConfig,\n GoBetterAuthClientOptions,\n SignOutRequest,\n SignOutResponse,\n Plugin,\n BeforeFetchHook,\n AfterFetchHook,\n} from \"./types\";\n\nexport class GoBetterAuthClient {\n public readonly config: GoBetterAuthClientConfig;\n private readonly plugins: Array<Plugin>;\n private readonly beforeFetchHooks: BeforeFetchHook[] = [];\n private readonly afterFetchHooks: AfterFetchHook[] = [];\n\n constructor(options: GoBetterAuthClientOptions) {\n this.plugins = options.plugins;\n\n const { plugins, ...rest } = options;\n this.config = rest;\n\n for (const plugin of this.plugins) {\n if (\"attachCookies\" in plugin && this.config.cookies) {\n (plugin as any).attachCookies(this.config.cookies);\n }\n\n (this as any)[plugin.id] = plugin.init(this);\n }\n }\n\n public registerBeforeFetch(hook: BeforeFetchHook) {\n this.beforeFetchHooks.push(hook);\n }\n\n public registerAfterFetch(hook: AfterFetchHook) {\n this.afterFetchHooks.push(hook);\n }\n\n public async runBeforeFetch(ctx: FetchContext) {\n for (const hook of this.beforeFetchHooks) {\n await hook(ctx);\n }\n }\n\n public async runAfterFetch(ctx: FetchContext, res: Response) {\n for (const hook of this.afterFetchHooks) {\n const result = await hook(ctx, res);\n if (result === \"retry\") return \"retry\";\n }\n }\n\n public async getMe<T = unknown>(): Promise<T> {\n return wrappedFetch<T>(this, \"/me\", {\n method: \"GET\",\n });\n }\n\n public async signOut(data: SignOutRequest): Promise<SignOutResponse> {\n return wrappedFetch<SignOutResponse>(this, \"/sign-out\", {\n method: \"POST\",\n body: data.session_id\n ? { session_id: data.session_id, sign_out_all: data.sign_out_all }\n : {},\n });\n }\n\n public getPlugin<T extends Plugin>(id: string): T | undefined {\n return this.plugins.find((plugin) => plugin.id === id) as T | undefined;\n }\n}\n","import { GoBetterAuthClient } from \"./client\";\nimport type { GoBetterAuthClientOptions, Plugin } from \"./types\";\n\n// Helper to extract plugin methods\nexport type InferPluginMethods<P> = P extends { init: (client: any) => infer M }\n ? M\n : never;\n\nexport type ClientWithPlugins<T extends readonly Plugin[]> =\n GoBetterAuthClient & {\n [P in T[number] as P[\"id\"]]: InferPluginMethods<P>;\n };\n\nexport function createClient<const T extends readonly Plugin[]>(\n options: Omit<GoBetterAuthClientOptions, \"plugins\"> & { plugins: T },\n): ClientWithPlugins<T> {\n return new GoBetterAuthClient(options as any) as ClientWithPlugins<T>;\n}\n"],"mappings":";;;;AAEA,MA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OAAO,GAAG;;;;;;ACzD1D,SAAgB,aACd,SACsB;AACtB,QAAO,IAAI,mBAAmB,QAAe"}
@@ -0,0 +1,180 @@
1
+ const require_fetch = require('../fetch-v3PWCtqe.cjs');
2
+ let cookie = require("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 require_fetch.wrappedFetch(client, "/sign-up", {
11
+ method: "POST",
12
+ body: data
13
+ });
14
+ },
15
+ signIn: async (data) => {
16
+ return require_fetch.wrappedFetch(client, "/sign-in", {
17
+ method: "POST",
18
+ body: data
19
+ });
20
+ },
21
+ sendEmailVerification: async (data) => {
22
+ return require_fetch.wrappedFetch(client, `/send-email-verification`, {
23
+ method: "POST",
24
+ body: data
25
+ });
26
+ },
27
+ requestPasswordReset: async (data) => {
28
+ return require_fetch.wrappedFetch(client, `/request-password-reset`, {
29
+ method: "POST",
30
+ body: data
31
+ });
32
+ },
33
+ changePassword: async (data) => {
34
+ return require_fetch.wrappedFetch(client, `/change-password`, {
35
+ method: "POST",
36
+ body: data
37
+ });
38
+ },
39
+ requestEmailChange: async (data) => {
40
+ return require_fetch.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 require_fetch.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 = (0, cookie.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 require_fetch.wrappedFetch(client, "/token/refresh", {
110
+ method: "POST",
111
+ body: data
112
+ });
113
+ },
114
+ getJWKSKeys: async () => {
115
+ return require_fetch.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
+ exports.BearerPlugin = BearerPlugin;
176
+ exports.CSRFPlugin = CSRFPlugin;
177
+ exports.EmailPasswordPlugin = EmailPasswordPlugin;
178
+ exports.JWTPlugin = JWTPlugin;
179
+ exports.OAuth2Plugin = OAuth2Plugin;
180
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","names":["wrappedFetch","wrappedFetch","wrappedFetch"],"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;AACtC,SAAO;GACL,QAAQ,OAAU,SAAoC;AACpD,WAAOA,2BAAgB,QAAQ,YAAY;KACzC,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,QAAQ,OAAU,SAAoC;AACpD,WAAOA,2BAAgB,QAAQ,YAAY;KACzC,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,uBAAuB,OACrB,SACkB;AAClB,WAAOA,2BAAa,QAA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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,135 @@
1
+ import { l as Plugin, t as ClientWithPlugins, u as GoBetterAuthClient } from "../sdk-cpbPBWuc.cjs";
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.cts.map