go-better-auth 0.1.0 → 0.2.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/README.md CHANGED
@@ -1,6 +1,16 @@
1
- # GoBetterAuth Node.js SDK
1
+ <p align="center">
2
+ GoBetterAuth Node.js SDK
3
+ </p>
2
4
 
3
- Official GoBetterAuth SDK. This SDK provides seamless integration with GoBetterAuth authentication server for both client-side and server-side applications and is framework agnostic (React, Vue.js and more).
5
+ <p align="center">
6
+ <img src="./project-logo.png" width="100" />
7
+ </p>
8
+
9
+ <p align="center">
10
+ Official GoBetterAuth Node.js SDK. This SDK provides seamless integration with GoBetterAuth authentication server for both client-side and server-side applications and is framework agnostic (React, Vue.js and more).
11
+ </p>
12
+
13
+ ---
4
14
 
5
15
  ## Features
6
16
 
@@ -33,9 +43,7 @@ import { EmailPasswordPlugin } from "go-better-auth/plugins";
33
43
  // Create a client instance
34
44
  const goBetterAuthClient = createClient({
35
45
  url: "http://localhost:8080", // Your GoBetterAuth server URL
36
- plugins: [
37
- new EmailPasswordPlugin()
38
- ]
46
+ plugins: [new EmailPasswordPlugin()],
39
47
  });
40
48
 
41
49
  // Now you can use the client to perform authentication operations
@@ -58,9 +66,9 @@ const goBetterAuthClient = createClient({
58
66
  new EmailPasswordPlugin(),
59
67
  new CSRFPlugin({
60
68
  cookieName: "csrf_token",
61
- headerName: "X-CSRF-TOKEN"
62
- })
63
- ]
69
+ headerName: "X-CSRF-TOKEN",
70
+ }),
71
+ ],
64
72
  });
65
73
  ```
66
74
 
@@ -75,38 +83,36 @@ import { EmailPasswordPlugin } from "go-better-auth/plugins";
75
83
 
76
84
  const goBetterAuthClient = createClient({
77
85
  url: "http://localhost:8080",
78
- plugins: [
79
- new EmailPasswordPlugin()
80
- ]
86
+ plugins: [new EmailPasswordPlugin()],
81
87
  });
82
88
 
83
89
  // Sign up
84
90
  await goBetterAuthClient.emailPassword.signUp({
85
91
  name: "John Doe",
86
92
  email: "john@example.com",
87
- password: "securePassword123"
93
+ password: "securePassword123",
88
94
  });
89
95
 
90
96
  // Sign in
91
97
  const response = await goBetterAuthClient.emailPassword.signIn({
92
98
  email: "john@example.com",
93
- password: "securePassword123"
99
+ password: "securePassword123",
94
100
  });
95
101
 
96
102
  // Send email verification
97
103
  await goBetterAuthClient.emailPassword.sendEmailVerification({
98
- email: "john@example.com"
104
+ email: "john@example.com",
99
105
  });
100
106
 
101
107
  // Request password reset
102
108
  await goBetterAuthClient.emailPassword.requestPasswordReset({
103
- email: "john@example.com"
109
+ email: "john@example.com",
104
110
  });
105
111
 
106
112
  // Change password
107
113
  await goBetterAuthClient.emailPassword.changePassword({
108
114
  token: "reset-token",
109
- password: "newSecurePassword123"
115
+ password: "newSecurePassword123",
110
116
  });
111
117
  ```
112
118
 
@@ -119,15 +125,13 @@ import { OAuth2Plugin } from "go-better-auth/plugins";
119
125
 
120
126
  const goBetterAuthClient = createClient({
121
127
  url: "http://localhost:8080/auth",
122
- plugins: [
123
- new OAuth2Plugin()
124
- ]
128
+ plugins: [new OAuth2Plugin()],
125
129
  });
126
130
 
127
131
  // Redirect user to OAuth2 provider
128
132
  const response = await goBetterAuthClient.oauth2.signIn({
129
133
  provider: "google", // or "github", "discord"
130
- redirect_to: "http://localhost:3000/callback"
134
+ redirect_to: "http://localhost:3000/callback",
131
135
  });
132
136
 
133
137
  // Redirect user to the authUrl
@@ -164,14 +168,12 @@ import { JWTPlugin } from "go-better-auth/plugins";
164
168
 
165
169
  const goBetterAuthClient = createClient({
166
170
  url: "http://localhost:8080/auth",
167
- plugins: [
168
- new JWTPlugin()
169
- ]
171
+ plugins: [new JWTPlugin()],
170
172
  });
171
173
 
172
174
  // Refresh JWT tokens
173
175
  const tokens = await goBetterAuthClient.jwt.refreshToken({
174
- refresh_token: "your-refresh-token"
176
+ refresh_token: "your-refresh-token",
175
177
  });
176
178
 
177
179
  // Get JWKS keys
@@ -190,9 +192,9 @@ const goBetterAuthClient = createClient({
190
192
  plugins: [
191
193
  new JWTPlugin(),
192
194
  new BearerPlugin({
193
- headerName: "Authorization" // Can be omitted as default is Authorization
194
- })
195
- ]
195
+ headerName: "Authorization", // Can be omitted as default is Authorization
196
+ }),
197
+ ],
196
198
  });
197
199
 
198
200
  // The Bearer plugin will automatically:
@@ -211,11 +213,11 @@ Configure fetch behavior with timeout and other options:
211
213
  const goBetterAuthClient = createClient({
212
214
  url: "http://localhost:8080/auth",
213
215
  fetchOptions: {
214
- abortTimeout: 30 // Timeout in seconds
216
+ abortTimeout: 30, // Timeout in seconds
215
217
  },
216
218
  plugins: [
217
219
  // your plugins
218
- ]
220
+ ],
219
221
  });
220
222
  ```
221
223
 
@@ -226,9 +228,7 @@ Add custom before/after fetch hooks for advanced customization:
226
228
  ```typescript
227
229
  const goBetterAuthClient = createClient({
228
230
  url: "http://localhost:8080/auth",
229
- plugins: [
230
- new EmailPasswordPlugin()
231
- ]
231
+ plugins: [new EmailPasswordPlugin()],
232
232
  });
233
233
 
234
234
  // Register a before fetch hook
@@ -237,7 +237,7 @@ goBetterAuthClient.registerBeforeFetch(async (ctx) => {
237
237
  // Modify context if needed
238
238
  ctx.init.headers = {
239
239
  ...ctx.init.headers,
240
- "X-Custom-Header": "value"
240
+ "X-Custom-Header": "value",
241
241
  };
242
242
  });
243
243
 
@@ -261,10 +261,10 @@ goBetterAuthClient.registerAfterFetch(async (ctx, response) => {
261
261
  // Optional fetch configuration
262
262
  fetchOptions?: {
263
263
  // Request timeout in seconds
264
- abortTimeout?: number
264
+ abortTimeout?: number
265
265
  },
266
266
  // Cookie provider for SSR compatibility
267
- cookies?: () => CookieStore
267
+ cookies?: () => CookieStore
268
268
  }
269
269
  ```
270
270
 
@@ -276,27 +276,27 @@ Once plugins are initialized, they expose methods on the client:
276
276
 
277
277
  `EmailPassword Plugin`:
278
278
 
279
- | Method | Description |
280
- |---------------------------------------------|------------------------------|
281
- | `client.emailPassword.signUp(data)` | Create a new user account |
282
- | `client.emailPassword.signIn(data)` | Authenticate a user |
283
- | `client.emailPassword.sendEmailVerification(data)` | Send email verification |
284
- | `client.emailPassword.requestPasswordReset(data)` | Request password reset |
285
- | `client.emailPassword.changePassword(data)` | Change user password |
286
- | `client.emailPassword.requestEmailChange(data)` | Request email change |
279
+ | Method | Description |
280
+ | -------------------------------------------------- | ------------------------- |
281
+ | `client.emailPassword.signUp(data)` | Create a new user account |
282
+ | `client.emailPassword.signIn(data)` | Authenticate a user |
283
+ | `client.emailPassword.sendEmailVerification(data)` | Send email verification |
284
+ | `client.emailPassword.requestPasswordReset(data)` | Request password reset |
285
+ | `client.emailPassword.changePassword(data)` | Change user password |
286
+ | `client.emailPassword.requestEmailChange(data)` | Request email change |
287
287
 
288
288
  `OAuth2 Plugin`:
289
289
 
290
- | Method | Description |
291
- |---------------------------------------------|------------------------------|
292
- | `client.oauth2.signIn(data)` | Initiate OAuth2 flow |
290
+ | Method | Description |
291
+ | ---------------------------- | -------------------- |
292
+ | `client.oauth2.signIn(data)` | Initiate OAuth2 flow |
293
293
 
294
294
  `JWT Plugin`:
295
295
 
296
- | Method | Description |
297
- |---------------------------------------------|------------------------------|
298
- | `client.jwt.refreshToken(data)` | Refresh JWT tokens |
299
- | `client.jwt.getJWKSKeys()` | Get JWKS keys |
296
+ | Method | Description |
297
+ | ------------------------------- | ------------------ |
298
+ | `client.jwt.refreshToken(data)` | Refresh JWT tokens |
299
+ | `client.jwt.getJWKSKeys()` | Get JWKS keys |
300
300
 
301
301
  ## Error Handling
302
302
 
@@ -306,7 +306,7 @@ All methods return promises that can be caught for error handling:
306
306
  try {
307
307
  const response = await goBetterAuthClient.emailPassword.signIn({
308
308
  email: "user@example.com",
309
- password: "password"
309
+ password: "password",
310
310
  });
311
311
  console.log("Signed in successfully", response);
312
312
  } catch (error) {
@@ -1,3 +1,5 @@
1
+ import { toCamelCaseKeys, toSnakeCaseKeys } from "es-toolkit";
2
+
1
3
  //#region src/fetch.ts
2
4
  async function wrappedFetch(client, endpoint, options = {}) {
3
5
  const headers = new Headers(options.headers || {});
@@ -15,7 +17,7 @@ async function wrappedFetch(client, endpoint, options = {}) {
15
17
  init: {
16
18
  method: options.method ?? "GET",
17
19
  headers,
18
- body: options.body ? JSON.stringify(options.body) : void 0,
20
+ body: options.body ? JSON.stringify(toSnakeCaseKeys(options.body)) : void 0,
19
21
  credentials: "include",
20
22
  signal: controller.signal
21
23
  },
@@ -29,7 +31,7 @@ async function wrappedFetch(client, endpoint, options = {}) {
29
31
  }
30
32
  const setCookieHeaders = res.headers.getSetCookie?.() ?? res.headers.get("set-cookie")?.split(", ") ?? null;
31
33
  if (!res.ok) throw new Error(await res.text());
32
- const data = await res.json();
34
+ const resData = await res.json();
33
35
  if (cookieStore && setCookieHeaders) for (const raw of setCookieHeaders) {
34
36
  const [pair, ...attrs] = raw.split(";");
35
37
  const [name, value] = pair.split("=");
@@ -60,9 +62,9 @@ async function wrappedFetch(client, endpoint, options = {}) {
60
62
  }
61
63
  cookieStore.set(name.trim(), decodeURIComponent(value.trim()), options);
62
64
  }
63
- return data;
65
+ return toCamelCaseKeys(resData);
64
66
  }
65
67
 
66
68
  //#endregion
67
69
  export { wrappedFetch as t };
68
- //# sourceMappingURL=fetch-Cp9z9f4v.js.map
70
+ //# sourceMappingURL=fetch-CSMExG79.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-CSMExG79.js","names":[],"sources":["../src/fetch.ts"],"sourcesContent":["import { toCamelCaseKeys, toSnakeCaseKeys } from \"es-toolkit\";\n\nimport type { GoBetterAuthClient } from \"./client\";\nimport type { CookieStore, FetchContext, FetchRequestOptions } from \"./types\";\n\nexport async function wrappedFetch<T>(\n client: GoBetterAuthClient,\n endpoint: string,\n options: FetchRequestOptions = {},\n): Promise<T> {\n const headers = new Headers(options.headers || {});\n\n let cookieStore: CookieStore | null = null;\n\n if (client.config.cookies) {\n cookieStore = await client.config.cookies();\n\n const cookieHeader = cookieStore\n .getAll()\n .map((c) => `${c.name}=${c.value}`)\n .join(\"; \");\n\n if (cookieHeader) {\n headers.set(\"cookie\", cookieHeader);\n }\n }\n\n const controller = new AbortController();\n const abortTimeout = client.config.fetchOptions?.abortTimeout;\n\n if (abortTimeout) {\n setTimeout(() => controller.abort(), abortTimeout * 1000);\n }\n\n const ctx: FetchContext = {\n url: `${client.config.url}${endpoint}`,\n init: {\n method: options.method ?? \"GET\",\n headers,\n body: options.body\n ? JSON.stringify(toSnakeCaseKeys(options.body))\n : undefined,\n credentials: \"include\",\n signal: controller.signal,\n },\n meta: {},\n };\n\n await client.runBeforeFetch(ctx);\n\n let res = await fetch(ctx.url, ctx.init);\n\n const action = await client.runAfterFetch(ctx, res);\n if (action === \"retry\" && !ctx.meta.retry) {\n ctx.meta.retry = true;\n res = await fetch(ctx.url, ctx.init);\n }\n\n const setCookieHeaders =\n res.headers.getSetCookie?.() ??\n res.headers.get(\"set-cookie\")?.split(\", \") ??\n null;\n\n if (!res.ok) {\n throw new Error(await res.text());\n }\n\n const resData = await res.json();\n\n // Apply Set-Cookie back into Next.js store (SSR only)\n if (cookieStore && setCookieHeaders) {\n for (const raw of setCookieHeaders) {\n const [pair, ...attrs] = raw.split(\";\");\n const [name, value] = pair.split(\"=\");\n\n if (!name || !value) continue;\n\n const options: Record<string, any> = {};\n\n for (const attr of attrs) {\n const [k, v] = attr.trim().split(\"=\");\n\n switch (k.toLowerCase()) {\n case \"path\":\n options.path = v;\n break;\n case \"expires\":\n options.expires = new Date(v);\n break;\n case \"max-age\":\n options.maxAge = Number(v);\n break;\n case \"httponly\":\n options.httpOnly = true;\n break;\n case \"secure\":\n options.secure = true;\n break;\n case \"samesite\":\n options.sameSite = v?.toLowerCase();\n break;\n }\n }\n\n cookieStore.set(name.trim(), decodeURIComponent(value.trim()), options);\n }\n }\n\n return toCamelCaseKeys(resData) as T;\n}\n"],"mappings":";;;AAKA,eAAsB,aACpB,QACA,UACA,UAA+B,EAAE,EACrB;CACZ,MAAM,UAAU,IAAI,QAAQ,QAAQ,WAAW,EAAE,CAAC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EAErB,MAAM,UAA+B,EAAE;AAEvC,OAAK,MAAM,QAAQ,OAAO;GACxB,MAAM,CAAC,GAAG,KAAK,KAAK,MAAM,CAAC,MAAM,IAAI;AAErC,WAAQ,EAAE,aAAa,EAAvB;IACE,KAAK;AACH,aAAQ,OAAO;AACf;IACF,KAAK;AACH,aAAQ,UAAU,IAAI,KAAK,EAAE;AAC7B;IACF,KAAK;AACH,aAAQ,SAAS,OAAO,EAAE;AAC1B;IACF,KAAK;AACH,aAAQ,WAAW;AACnB;IACF,KAAK;AACH,aAAQ,SAAS;AACjB;IACF,KAAK;AACH,aAAQ,WAAW,GAAG,aAAa;AACnC;;;AAIN,cAAY,IAAI,KAAK,MAAM,EAAE,mBAAmB,MAAM,MAAM,CAAC,EAAE,QAAQ;;AAI3E,QAAO,gBAAgB,QAAQ"}
@@ -1,3 +1,4 @@
1
+ let es_toolkit = require("es-toolkit");
1
2
 
2
3
  //#region src/fetch.ts
3
4
  async function wrappedFetch(client, endpoint, options = {}) {
@@ -16,7 +17,7 @@ async function wrappedFetch(client, endpoint, options = {}) {
16
17
  init: {
17
18
  method: options.method ?? "GET",
18
19
  headers,
19
- body: options.body ? JSON.stringify(options.body) : void 0,
20
+ body: options.body ? JSON.stringify((0, es_toolkit.toSnakeCaseKeys)(options.body)) : void 0,
20
21
  credentials: "include",
21
22
  signal: controller.signal
22
23
  },
@@ -30,7 +31,7 @@ async function wrappedFetch(client, endpoint, options = {}) {
30
31
  }
31
32
  const setCookieHeaders = res.headers.getSetCookie?.() ?? res.headers.get("set-cookie")?.split(", ") ?? null;
32
33
  if (!res.ok) throw new Error(await res.text());
33
- const data = await res.json();
34
+ const resData = await res.json();
34
35
  if (cookieStore && setCookieHeaders) for (const raw of setCookieHeaders) {
35
36
  const [pair, ...attrs] = raw.split(";");
36
37
  const [name, value] = pair.split("=");
@@ -61,7 +62,7 @@ async function wrappedFetch(client, endpoint, options = {}) {
61
62
  }
62
63
  cookieStore.set(name.trim(), decodeURIComponent(value.trim()), options);
63
64
  }
64
- return data;
65
+ return (0, es_toolkit.toCamelCaseKeys)(resData);
65
66
  }
66
67
 
67
68
  //#endregion
@@ -71,4 +72,4 @@ Object.defineProperty(exports, 'wrappedFetch', {
71
72
  return wrappedFetch;
72
73
  }
73
74
  });
74
- //# sourceMappingURL=fetch-v3PWCtqe.cjs.map
75
+ //# sourceMappingURL=fetch-Dk9jHtCR.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-Dk9jHtCR.cjs","names":[],"sources":["../src/fetch.ts"],"sourcesContent":["import { toCamelCaseKeys, toSnakeCaseKeys } from \"es-toolkit\";\n\nimport type { GoBetterAuthClient } from \"./client\";\nimport type { CookieStore, FetchContext, FetchRequestOptions } from \"./types\";\n\nexport async function wrappedFetch<T>(\n client: GoBetterAuthClient,\n endpoint: string,\n options: FetchRequestOptions = {},\n): Promise<T> {\n const headers = new Headers(options.headers || {});\n\n let cookieStore: CookieStore | null = null;\n\n if (client.config.cookies) {\n cookieStore = await client.config.cookies();\n\n const cookieHeader = cookieStore\n .getAll()\n .map((c) => `${c.name}=${c.value}`)\n .join(\"; \");\n\n if (cookieHeader) {\n headers.set(\"cookie\", cookieHeader);\n }\n }\n\n const controller = new AbortController();\n const abortTimeout = client.config.fetchOptions?.abortTimeout;\n\n if (abortTimeout) {\n setTimeout(() => controller.abort(), abortTimeout * 1000);\n }\n\n const ctx: FetchContext = {\n url: `${client.config.url}${endpoint}`,\n init: {\n method: options.method ?? \"GET\",\n headers,\n body: options.body\n ? JSON.stringify(toSnakeCaseKeys(options.body))\n : undefined,\n credentials: \"include\",\n signal: controller.signal,\n },\n meta: {},\n };\n\n await client.runBeforeFetch(ctx);\n\n let res = await fetch(ctx.url, ctx.init);\n\n const action = await client.runAfterFetch(ctx, res);\n if (action === \"retry\" && !ctx.meta.retry) {\n ctx.meta.retry = true;\n res = await fetch(ctx.url, ctx.init);\n }\n\n const setCookieHeaders =\n res.headers.getSetCookie?.() ??\n res.headers.get(\"set-cookie\")?.split(\", \") ??\n null;\n\n if (!res.ok) {\n throw new Error(await res.text());\n }\n\n const resData = await res.json();\n\n // Apply Set-Cookie back into Next.js store (SSR only)\n if (cookieStore && setCookieHeaders) {\n for (const raw of setCookieHeaders) {\n const [pair, ...attrs] = raw.split(\";\");\n const [name, value] = pair.split(\"=\");\n\n if (!name || !value) continue;\n\n const options: Record<string, any> = {};\n\n for (const attr of attrs) {\n const [k, v] = attr.trim().split(\"=\");\n\n switch (k.toLowerCase()) {\n case \"path\":\n options.path = v;\n break;\n case \"expires\":\n options.expires = new Date(v);\n break;\n case \"max-age\":\n options.maxAge = Number(v);\n break;\n case \"httponly\":\n options.httpOnly = true;\n break;\n case \"secure\":\n options.secure = true;\n break;\n case \"samesite\":\n options.sameSite = v?.toLowerCase();\n break;\n }\n }\n\n cookieStore.set(name.trim(), decodeURIComponent(value.trim()), options);\n }\n }\n\n return toCamelCaseKeys(resData) as T;\n}\n"],"mappings":";;;AAKA,eAAsB,aACpB,QACA,UACA,UAA+B,EAAE,EACrB;CACZ,MAAM,UAAU,IAAI,QAAQ,QAAQ,WAAW,EAAE,CAAC;CAElD,IAAI,cAAkC;AAEtC,KAAI,OAAO,OAAO,SAAS;AACzB,gBAAc,MAAM,OAAO,OAAO,SAAS;EAE3C,MAAM,eAAe,YAClB,QAAQ,CACR,KAAK,MAAM,GAAG,EAAE,KAAK,GAAG,EAAE,QAAQ,CAClC,KAAK,KAAK;AAEb,MAAI,aACF,SAAQ,IAAI,UAAU,aAAa;;CAIvC,MAAM,aAAa,IAAI,iBAAiB;CACxC,MAAM,eAAe,OAAO,OAAO,cAAc;AAEjD,KAAI,aACF,kBAAiB,WAAW,OAAO,EAAE,eAAe,IAAK;CAG3D,MAAM,MAAoB;EACxB,KAAK,GAAG,OAAO,OAAO,MAAM;EAC5B,MAAM;GACJ,QAAQ,QAAQ,UAAU;GAC1B;GACA,MAAM,QAAQ,OACV,KAAK,0CAA0B,QAAQ,KAAK,CAAC,GAC7C;G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1,41 @@
1
- const require_fetch = require('./fetch-v3PWCtqe.cjs');
1
+ const require_fetch = require('./fetch-Dk9jHtCR.cjs');
2
2
  let zod = require("zod");
3
+ let es_toolkit = require("es-toolkit");
3
4
 
4
5
  //#region src/types/schemas.ts
5
6
  const userSchema = zod.z.object({
6
7
  id: zod.z.uuid(),
7
8
  name: zod.z.string().nonempty(),
8
9
  email: zod.z.email(),
9
- email_verified: zod.z.boolean(),
10
+ emailVerified: zod.z.boolean(),
10
11
  image: zod.z.string().nullish(),
11
- created_at: zod.z.iso.datetime(),
12
- updated_at: zod.z.iso.datetime()
12
+ createdAt: zod.z.iso.datetime(),
13
+ updatedAt: zod.z.iso.datetime()
13
14
  });
14
15
  const accountSchema = zod.z.object({
15
16
  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(),
17
+ userId: zod.z.string().nonempty(),
18
+ accountId: zod.z.string().nonempty(),
19
+ providerId: zod.z.string().nonempty(),
20
+ accessToken: zod.z.string().nullish(),
21
+ refreshToken: zod.z.string().nullish(),
22
+ idToken: zod.z.string().nullish(),
23
+ accessTokenExpiresAt: zod.z.iso.datetime().nullish(),
24
+ refreshTokenExpiresAt: zod.z.iso.datetime().nullish(),
24
25
  scope: zod.z.string().nullish(),
25
26
  password: zod.z.string().nullish(),
26
- created_at: zod.z.iso.datetime(),
27
- updated_at: zod.z.iso.datetime()
27
+ createdAt: zod.z.iso.datetime(),
28
+ updatedAt: zod.z.iso.datetime()
28
29
  });
29
30
  const sessionSchema = zod.z.object({
30
31
  id: zod.z.uuid(),
31
- user_id: zod.z.string().nonempty(),
32
+ userId: zod.z.string().nonempty(),
32
33
  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()
34
+ expiresAt: zod.z.iso.datetime(),
35
+ ipAddress: zod.z.string().nullish(),
36
+ userAgent: zod.z.string().nullish(),
37
+ createdAt: zod.z.iso.datetime(),
38
+ updatedAt: zod.z.iso.datetime()
38
39
  });
39
40
  const verificationTypeSchema = zod.z.enum([
40
41
  "email_verification",
@@ -43,13 +44,13 @@ const verificationTypeSchema = zod.z.enum([
43
44
  ]);
44
45
  const verificationSchema = zod.z.object({
45
46
  id: zod.z.uuid(),
46
- user_id: zod.z.string().nullish(),
47
+ userId: zod.z.string().nullish(),
47
48
  identifier: zod.z.string().nonempty(),
48
49
  token: zod.z.string().nonempty(),
49
50
  type: verificationTypeSchema,
50
- expires_at: zod.z.iso.datetime(),
51
- created_at: zod.z.iso.datetime(),
52
- updated_at: zod.z.iso.datetime()
51
+ expiresAt: zod.z.iso.datetime(),
52
+ createdAt: zod.z.iso.datetime(),
53
+ updatedAt: zod.z.iso.datetime()
53
54
  });
54
55
 
55
56
  //#endregion
@@ -86,10 +87,7 @@ var GoBetterAuthClient = class {
86
87
  async signOut(data) {
87
88
  return require_fetch.wrappedFetch(this, "/sign-out", {
88
89
  method: "POST",
89
- body: data.session_id ? {
90
- session_id: data.session_id,
91
- sign_out_all: data.sign_out_all
92
- } : {}
90
+ body: (0, es_toolkit.toSnakeCaseKeys)(data)
93
91
  });
94
92
  }
95
93
  getPlugin(id) {
@@ -1 +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,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AAO,IAAI,mBAAmB,QAAe"}
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 emailVerified: z.boolean(),\n image: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type User = z.infer<typeof userSchema>;\n\nexport const accountSchema = z.object({\n id: z.uuid(),\n userId: z.string().nonempty(),\n accountId: z.string().nonempty(),\n providerId: z.string().nonempty(),\n accessToken: z.string().nullish(),\n refreshToken: z.string().nullish(),\n idToken: z.string().nullish(),\n accessTokenExpiresAt: z.iso.datetime().nullish(),\n refreshTokenExpiresAt: z.iso.datetime().nullish(),\n scope: z.string().nullish(),\n password: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Account = z.infer<typeof accountSchema>;\n\nexport const sessionSchema = z.object({\n id: z.uuid(),\n userId: z.string().nonempty(),\n token: z.string().nonempty(),\n expiresAt: z.iso.datetime(),\n ipAddress: z.string().nullish(),\n userAgent: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: 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 userId: z.string().nullish(),\n identifier: z.string().nonempty(),\n token: z.string().nonempty(),\n type: verificationTypeSchema,\n expiresAt: z.iso.datetime(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Verification = z.infer<typeof verificationSchema>;\n","import { toSnakeCaseKeys } from \"es-toolkit\";\n\nimport { 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 (this as any)[plugin.id] = plugin.init(this);\n }\n }\n\n public registerBeforeFetch(hook: BeforeFetchHook): void {\n this.beforeFetchHooks.push(hook);\n }\n\n public registerAfterFetch(hook: AfterFetchHook): void {\n this.afterFetchHooks.push(hook);\n }\n\n public async runBeforeFetch(ctx: FetchContext): Promise<void> {\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\") {\n return \"retry\";\n }\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: toSnakeCaseKeys(data),\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,eAAeA,MAAE,SAAS;CAC1B,OAAOA,MAAE,QAAQ,CAAC,SAAS;CAC3B,WAAWA,MAAE,IAAI,UAAU;CAC3B,WAAWA,MAAE,IAAI,UAAU;CAC5B,CAAC;AAGF,MAAa,gBAAgBA,MAAE,OAAO;CACpC,IAAIA,MAAE,MAAM;CACZ,QAAQA,MAAE,QAAQ,CAAC,UAAU;CAC7B,WAAWA,MAAE,QAAQ,CAAC,UAAU;CAChC,YAAYA,MAAE,QAAQ,CAAC,UAAU;CACjC,aAAaA,MAAE,QAAQ,CAAC,SAAS;CACjC,cAAcA,MAAE,QAAQ,CAAC,SAAS;CAClC,SAASA,MAAE,QAAQ,CAAC,SAAS;CAC7B,sBAAsBA,MAAE,IAAI,UAAU,CAAC,SAAS;CAChD,uBAAuBA,MAAE,IAAI,UAAU,CAAC,SAAS;CACjD,OAAOA,MAAE,QAAQ,CAAC,SAAS;CAC3B,UAAUA,MAAE,QAAQ,CAAC,SAAS;CAC9B,WAAWA,MAAE,IAAI,UAAU;CAC3B,WAAWA,MAAE,IAAI,UAAU;CAC5B,CAAC;AAGF,MAAa,gBAAgBA,MAAE,OAAO;CACpC,IAAIA,MAAE,MAAM;CACZ,QAAQA,MAAE,QAAQ,CAAC,UAAU;CAC7B,OAAOA,MAAE,QAAQ,CAAC,UAAU;CAC5B,WAAWA,MAAE,IAAI,UAAU;CAC3B,WAAWA,MAAE,QAAQ,CAAC,SAAS;CAC/B,WAAWA,MAAE,QAAQ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Q,OACT,CAAC;;CAGJ,MAAa,QAAQ,MAAgD;AACnE,SAAOA,2BAA8B,MAAM,aAAa;GACtD,QAAQ;GACR,sCAAsB,KAAK;GAC5B,CAAC;;CAGJ,AAAO,UAA4B,IAA2B;AAC5D,SAAO,KAAK,QAAQ,MAAM,WAAW,OAAO,OAAO,GAAG;;;;;;AC1D1D,SAAgB,aACd,SACsB;AACtB,QAAO,IAAI,mBAAmB,QAAe"}
package/dist/index.d.cts CHANGED
@@ -1,2 +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";
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-1FEcNixu.cjs";
2
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.d.ts CHANGED
@@ -1,2 +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";
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-NIFb1TeL.js";
2
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 CHANGED
@@ -1,40 +1,41 @@
1
- import { t as wrappedFetch } from "./fetch-Cp9z9f4v.js";
1
+ import { t as wrappedFetch } from "./fetch-CSMExG79.js";
2
2
  import { z } from "zod";
3
+ import { toSnakeCaseKeys } from "es-toolkit";
3
4
 
4
5
  //#region src/types/schemas.ts
5
6
  const userSchema = z.object({
6
7
  id: z.uuid(),
7
8
  name: z.string().nonempty(),
8
9
  email: z.email(),
9
- email_verified: z.boolean(),
10
+ emailVerified: z.boolean(),
10
11
  image: z.string().nullish(),
11
- created_at: z.iso.datetime(),
12
- updated_at: z.iso.datetime()
12
+ createdAt: z.iso.datetime(),
13
+ updatedAt: z.iso.datetime()
13
14
  });
14
15
  const accountSchema = z.object({
15
16
  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(),
17
+ userId: z.string().nonempty(),
18
+ accountId: z.string().nonempty(),
19
+ providerId: z.string().nonempty(),
20
+ accessToken: z.string().nullish(),
21
+ refreshToken: z.string().nullish(),
22
+ idToken: z.string().nullish(),
23
+ accessTokenExpiresAt: z.iso.datetime().nullish(),
24
+ refreshTokenExpiresAt: z.iso.datetime().nullish(),
24
25
  scope: z.string().nullish(),
25
26
  password: z.string().nullish(),
26
- created_at: z.iso.datetime(),
27
- updated_at: z.iso.datetime()
27
+ createdAt: z.iso.datetime(),
28
+ updatedAt: z.iso.datetime()
28
29
  });
29
30
  const sessionSchema = z.object({
30
31
  id: z.uuid(),
31
- user_id: z.string().nonempty(),
32
+ userId: z.string().nonempty(),
32
33
  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()
34
+ expiresAt: z.iso.datetime(),
35
+ ipAddress: z.string().nullish(),
36
+ userAgent: z.string().nullish(),
37
+ createdAt: z.iso.datetime(),
38
+ updatedAt: z.iso.datetime()
38
39
  });
39
40
  const verificationTypeSchema = z.enum([
40
41
  "email_verification",
@@ -43,13 +44,13 @@ const verificationTypeSchema = z.enum([
43
44
  ]);
44
45
  const verificationSchema = z.object({
45
46
  id: z.uuid(),
46
- user_id: z.string().nullish(),
47
+ userId: z.string().nullish(),
47
48
  identifier: z.string().nonempty(),
48
49
  token: z.string().nonempty(),
49
50
  type: verificationTypeSchema,
50
- expires_at: z.iso.datetime(),
51
- created_at: z.iso.datetime(),
52
- updated_at: z.iso.datetime()
51
+ expiresAt: z.iso.datetime(),
52
+ createdAt: z.iso.datetime(),
53
+ updatedAt: z.iso.datetime()
53
54
  });
54
55
 
55
56
  //#endregion
@@ -86,10 +87,7 @@ var GoBetterAuthClient = class {
86
87
  async signOut(data) {
87
88
  return wrappedFetch(this, "/sign-out", {
88
89
  method: "POST",
89
- body: data.session_id ? {
90
- session_id: data.session_id,
91
- sign_out_all: data.sign_out_all
92
- } : {}
90
+ body: toSnakeCaseKeys(data)
93
91
  });
94
92
  }
95
93
  getPlugin(id) {
package/dist/index.js.map CHANGED
@@ -1 +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,MAAa,aAAa,EAAE,OAAO;CACjC,IAAI,EAAE,MAAM;CACZ,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,OAAO,EAAE,OAAO;CAChB,gBAAgB,EAAE,SAAS;CAC3B,OAAO,EAAE,QAAQ,CAAC,SAAS;CAC3B,YAAY,EAAE,IAAI,UAAU;CAC5B,YAAY,EAAE,IAAI,UAAU;CAC7B,CAAC;AAGF,MAAa,gBAAgB,EAAE,OAAO;CACpC,IAAI,EAAE,MAAM;CACZ,SAAS,EAAE,QAAQ,CAAC,UAAU;CAC9B,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,aAAa,EAAE,QAAQ,CAAC,UAAU;CAClC,cAAc,EAAE,QAAQ,CAAC,SAAS;CAClC,eAAe,EAAE,QAAQ,CAAC,SAAS;CACnC,UAAU,EAAE,QAAQ,CAAC,SAAS;CAC9B,yBAAyB,EAAE,IAAI,UAAU,CAAC,SAAS;CACnD,0BAA0B,EAAE,IAAI,UAAU,CAAC,SAAS;CACpD,OAAO,EAAE,QAAQ,CAAC,SAAS;CAC3B,UAAU,EAAE,QAAQ,CAAC,SAAS;CAC9B,YAAY,EAAE,IAAI,UAAU;CAC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AAe,KAAmB;AAC7C,OAAK,MAAM,QAAQ,KAAK,iBACtB,OAAM,KAAK,IAAI;;CAInB,MAAa,cAAc,KAAmB,KAAe;AAC3D,OAAK,MAAM,QAAQ,KAAK,gBAEtB,KADe,MAAM,KAAK,KAAK,IAAI,KACpB,QAAS,QAAO;;CAInC,MAAa,QAAiC;AAC5C,SAAO,aAAgB,MAAM,OAAO,EAClC,QAAQ,OACT,CAAC;;CAGJ,MAAa,QAAQ,MAAgD;AACnE,SAAO,aAA8B,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"}
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 emailVerified: z.boolean(),\n image: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type User = z.infer<typeof userSchema>;\n\nexport const accountSchema = z.object({\n id: z.uuid(),\n userId: z.string().nonempty(),\n accountId: z.string().nonempty(),\n providerId: z.string().nonempty(),\n accessToken: z.string().nullish(),\n refreshToken: z.string().nullish(),\n idToken: z.string().nullish(),\n accessTokenExpiresAt: z.iso.datetime().nullish(),\n refreshTokenExpiresAt: z.iso.datetime().nullish(),\n scope: z.string().nullish(),\n password: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Account = z.infer<typeof accountSchema>;\n\nexport const sessionSchema = z.object({\n id: z.uuid(),\n userId: z.string().nonempty(),\n token: z.string().nonempty(),\n expiresAt: z.iso.datetime(),\n ipAddress: z.string().nullish(),\n userAgent: z.string().nullish(),\n createdAt: z.iso.datetime(),\n updatedAt: 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 userId: z.string().nullish(),\n identifier: z.string().nonempty(),\n token: z.string().nonempty(),\n type: verificationTypeSchema,\n expiresAt: z.iso.datetime(),\n createdAt: z.iso.datetime(),\n updatedAt: z.iso.datetime(),\n});\nexport type Verification = z.infer<typeof verificationSchema>;\n","import { toSnakeCaseKeys } from \"es-toolkit\";\n\nimport { 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 (this as any)[plugin.id] = plugin.init(this);\n }\n }\n\n public registerBeforeFetch(hook: BeforeFetchHook): void {\n this.beforeFetchHooks.push(hook);\n }\n\n public registerAfterFetch(hook: AfterFetchHook): void {\n this.afterFetchHooks.push(hook);\n }\n\n public async runBeforeFetch(ctx: FetchContext): Promise<void> {\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\") {\n return \"retry\";\n }\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: toSnakeCaseKeys(data),\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,aAAa,EAAE,OAAO;CACjC,IAAI,EAAE,MAAM;CACZ,MAAM,EAAE,QAAQ,CAAC,UAAU;CAC3B,OAAO,EAAE,OAAO;CAChB,eAAe,EAAE,SAAS;CAC1B,OAAO,EAAE,QAAQ,CAAC,SAAS;CAC3B,WAAW,EAAE,IAAI,UAAU;CAC3B,WAAW,EAAE,IAAI,UAAU;CAC5B,CAAC;AAGF,MAAa,gBAAgB,EAAE,OAAO;CACpC,IAAI,EAAE,MAAM;CACZ,QAAQ,EAAE,QAAQ,CAAC,UAAU;CAC7B,WAAW,EAAE,QAAQ,CAAC,UAAU;CAChC,YAAY,EAAE,QAAQ,CAAC,UAAU;CACjC,aAAa,EAAE,QAAQ,CAAC,SAAS;CACjC,cAAc,EAAE,QAAQ,CAAC,SAAS;C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AAO,QAC3C,CAAC,OAAe,cAAc,KAAK,OAAO,QAAQ;AAEpD,GAAC,KAAa,OAAO,MAAM,OAAO,KAAK,KAAK;;;CAIhD,AAAO,oBAAoB,MAA6B;AACtD,OAAK,iBAAiB,KAAK,KAAK;;CAGlC,AAAO,mBAAmB,MAA4B;AACpD,OAAK,gBAAgB,KAAK,KAAK;;CAGjC,MAAa,eAAe,KAAkC;AAC5D,OAAK,MAAM,QAAQ,KAAK,iBACtB,OAAM,KAAK,IAAI;;CAInB,MAAa,cAAc,KAAmB,KAAe;AAC3D,OAAK,MAAM,QAAQ,KAAK,gBAEtB,KADe,MAAM,KAAK,KAAK,IAAI,KACpB,QACb,QAAO;;CAKb,MAAa,QAAiC;AAC5C,SAAO,aAAgB,MAAM,OAAO,EAClC,QAAQ,OACT,CAAC;;CAGJ,MAAa,QAAQ,MAAgD;AACnE,SAAO,aAA8B,MAAM,aAAa;GACtD,QAAQ;GACR,MAAM,gBAAgB,KAAK;GAC5B,CAAC;;CAGJ,AAAO,UAA4B,IAA2B;AAC5D,SAAO,KAAK,QAAQ,MAAM,WAAW,OAAO,OAAO,GAAG;;;;;;AC1D1D,SAAgB,aACd,SACsB;AACtB,QAAO,IAAI,mBAAmB,QAAe"}
@@ -1,4 +1,4 @@
1
- const require_fetch = require('../fetch-v3PWCtqe.cjs');
1
+ const require_fetch = require('../fetch-Dk9jHtCR.cjs');
2
2
  let cookie = require("cookie");
3
3
 
4
4
  //#region src/plugins/email-password/plugin.ts
@@ -52,7 +52,7 @@ var OAuth2Plugin = class {
52
52
  id = "oauth2";
53
53
  init(client) {
54
54
  return { signIn: async (data) => {
55
- return require_fetch.wrappedFetch(client, `/oauth2/authorize/${data.provider}?redirect_to=${data.redirect_to}`, { method: "GET" });
55
+ return require_fetch.wrappedFetch(client, `/oauth2/authorize/${data.provider}?redirect_to=${data.redirectTo}`, { method: "GET" });
56
56
  } };
57
57
  }
58
58
  };
@@ -148,10 +148,10 @@ var BearerPlugin = class {
148
148
  }
149
149
  if (!this.refreshPromise) this.refreshPromise = (async () => {
150
150
  try {
151
- const response = await client.jwt.refreshToken({ refresh_token: refreshToken });
151
+ const response = await client.jwt.refreshToken({ refreshToken });
152
152
  if (!response) return null;
153
- localStorage.setItem("accessToken", response.access_token);
154
- localStorage.setItem("refreshToken", response.refresh_token);
153
+ localStorage.setItem("accessToken", response.accessToken);
154
+ localStorage.setItem("refreshToken", response.refreshToken);
155
155
  return response;
156
156
  } finally {
157
157
  this.refreshPromise = null;
@@ -162,9 +162,8 @@ var BearerPlugin = class {
162
162
  const headerName = this.options?.headerName ?? "Authorization";
163
163
  ctx.init.headers = {
164
164
  ...ctx.init.headers,
165
- [headerName]: `Bearer ${refreshed.access_token}`
165
+ [headerName]: `Bearer ${refreshed.accessToken}`
166
166
  };
167
- ctx.meta.retry = true;
168
167
  return "retry";
169
168
  });
170
169
  return {};
@@ -1 +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,QAAQ,4BAA4B;KACtD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,sBAAsB,OACpB,SACkB;AAClB,WAAOA,2BAAa,QAAQ,2BAA2B;KACrD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,gBAAgB,OAAO,SAA+C;AACpE,WAAOA,2BAAa,QAAQ,oBAAoB;KAC9C,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,oBAAoB,OAClB,SACkB;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AK;KACX,aAAa,UAAU,UAAU;IACnC;AAED,OAAI,KAAK,QAAQ;AACjB,UAAO;IACP;AAEF,SAAO,EAAE"}
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.redirectTo}`,\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\") {\n return;\n }\n if (res.status !== 401) {\n return;\n }\n if (ctx.meta.retry) {\n return;\n }\n\n const refreshToken = localStorage.getItem(\"refreshToken\");\n if (!refreshToken) {\n return;\n }\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 refreshToken: refreshToken,\n });\n if (!response) {\n return null;\n }\n\n localStorage.setItem(\"accessToken\", response.accessToken);\n localStorage.setItem(\"refreshToken\", response.refreshToken);\n\n return response;\n } finally {\n this.refreshPromise = null;\n }\n })();\n }\n\n const refreshed = await this.refreshPromise;\n if (!refreshed) {\n return;\n }\n\n const headerName = this.options?.headerName ?? \"Authorization\";\n ctx.init.headers = {\n ...ctx.init.headers,\n [headerName]: `Bearer ${refreshed.accessToken}`,\n };\n\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,QAAQ,4BAA4B;KACtD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,sBAAsB,OACpB,SACkB;AAClB,WAAOA,2BAAa,QAAQ,2BAA2B;KACrD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,gBAAgB,OAAO,SAA+C;AACpE,WAAOA,2BAAa,QAAQ,oBAAoB;KAC9C,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,oBAAoB,OAClB,SACkB;AAClB,WAAOA,2BAAa,QAAQ,yBAAyB;KACnD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEL;;;;;;ACnDL,IAAa,eAAb,MAA4C;CAC1C,AAAgB,KAAK;CAErB,AAAO,KAAK,QAA4B;AACtC,SAAO,EACL,QAAQ,OACN,SACsC;AACtC,UAAOC,2BACL,QACA,qBAAqB,KAAK,SAAS,eAAe,KAAK,cACvD,EACE,QAAQ,OACT,CACF;KAEJ;;;;;;AClBL,IAAa,aAAb,MAA0C;CACxC,AAAgB,KAAK;CAErB,YAAY,AAAiB,SAA4B;EAA5B;;CAE7B,AAAO,KAAK,QAA4B;AACtC,SAAO,oBAAoB,OAAO,QAAsB;AAEtD,OAAI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,aAAa,QAAQ,cAAc;AACjD,OAAI,MACF,KAAI,KAAK,UAAU;IACjB,GAAG,IAAI,KAAK;KACX,aAAa,UAAU;IACzB;IAEH;AAEF,SAAO,mBAAmB,OAAO,KAAmB,QAAkB;AACpE,OAAI,OAAO,aAAa,YACtB;AAEF,OAAI,IAAI,WAAW,IACjB;AAEF,OAAI,IAAI,KAAK,MACX;GAGF,MAAM,eAAe,aAAa,QAAQ,eAAe;AACzD,OAAI,CAAC,aACH;AAGF,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,EAC/B,cACf,CAAC;AACF,SAAI,CAAC,SACH,QAAO;AAGT,kBAAa,QAAQ,eAAe,SAAS,YAAY;AACzD,kBAAa,QAAQ,gBAAgB,SAAS,aAAa;AAE3D,YAAO;cACC;AACR,UAAK,iBAAiB;;OAEtB;GAGN,MAAM,YAAY,MAAM,KAAK;AAC7B,OAAI,CAAC,UACH;GAGF,MAAM,aAAa,KAAK,SAAS,cAAc;AAC/C,OAAI,KAAK,UAAU;IACjB,GAAG,IAAI,KAAK;KACX,aAAa,UAAU,UAAU;IACnC;AAED,UAAO;IACP;AAEF,SAAO,EAAE"}
@@ -1,4 +1,4 @@
1
- import { l as Plugin, t as ClientWithPlugins, u as GoBetterAuthClient } from "../sdk-cpbPBWuc.cjs";
1
+ import { l as Plugin, t as ClientWithPlugins, u as GoBetterAuthClient } from "../sdk-1FEcNixu.cjs";
2
2
 
3
3
  //#region src/plugins/email-password/types.d.ts
4
4
  type SignUpRequest = {
@@ -56,10 +56,10 @@ type OAuth2ProviderType = "discord" | "github" | "google";
56
56
  */
57
57
  type SignInWithOAuth2Request = {
58
58
  /** OAuth2 provider to use */provider: OAuth2ProviderType;
59
- redirect_to?: string;
59
+ redirectTo?: string;
60
60
  };
61
61
  type SignInWithOAuth2Response = {
62
- auth_url: string;
62
+ authUrl: string;
63
63
  };
64
64
  //#endregion
65
65
  //#region src/plugins/oauth2/plugin.d.ts
@@ -88,11 +88,11 @@ declare class CSRFPlugin implements Plugin {
88
88
  //#endregion
89
89
  //#region src/plugins/jwt/types.d.ts
90
90
  type TokenRefreshRequest = {
91
- refresh_token: string;
91
+ refreshToken: string;
92
92
  };
93
93
  type TokenRefreshResponse = {
94
- access_token: string;
95
- refresh_token: string;
94
+ accessToken: string;
95
+ refreshToken: string;
96
96
  };
97
97
  type JWTAlgorithm = "eddsa" | "rs256" | "ps256" | "es256" | "es512" | "ecdh-es";
98
98
  type JWKSKey = {
@@ -118,8 +118,8 @@ type BearerPluginOptions = {
118
118
  headerName?: string;
119
119
  };
120
120
  type JWTTokensResponse = {
121
- access_token: string;
122
- refresh_token: string;
121
+ accessToken: string;
122
+ refreshToken: string;
123
123
  };
124
124
  //#endregion
125
125
  //#region src/plugins/bearer/plugin.d.ts
@@ -1,4 +1,4 @@
1
- import { l as Plugin, t as ClientWithPlugins, u as GoBetterAuthClient } from "../sdk-DJhCsA2I.js";
1
+ import { l as Plugin, t as ClientWithPlugins, u as GoBetterAuthClient } from "../sdk-NIFb1TeL.js";
2
2
 
3
3
  //#region src/plugins/email-password/types.d.ts
4
4
  type SignUpRequest = {
@@ -56,10 +56,10 @@ type OAuth2ProviderType = "discord" | "github" | "google";
56
56
  */
57
57
  type SignInWithOAuth2Request = {
58
58
  /** OAuth2 provider to use */provider: OAuth2ProviderType;
59
- redirect_to?: string;
59
+ redirectTo?: string;
60
60
  };
61
61
  type SignInWithOAuth2Response = {
62
- auth_url: string;
62
+ authUrl: string;
63
63
  };
64
64
  //#endregion
65
65
  //#region src/plugins/oauth2/plugin.d.ts
@@ -88,11 +88,11 @@ declare class CSRFPlugin implements Plugin {
88
88
  //#endregion
89
89
  //#region src/plugins/jwt/types.d.ts
90
90
  type TokenRefreshRequest = {
91
- refresh_token: string;
91
+ refreshToken: string;
92
92
  };
93
93
  type TokenRefreshResponse = {
94
- access_token: string;
95
- refresh_token: string;
94
+ accessToken: string;
95
+ refreshToken: string;
96
96
  };
97
97
  type JWTAlgorithm = "eddsa" | "rs256" | "ps256" | "es256" | "es512" | "ecdh-es";
98
98
  type JWKSKey = {
@@ -118,8 +118,8 @@ type BearerPluginOptions = {
118
118
  headerName?: string;
119
119
  };
120
120
  type JWTTokensResponse = {
121
- access_token: string;
122
- refresh_token: string;
121
+ accessToken: string;
122
+ refreshToken: string;
123
123
  };
124
124
  //#endregion
125
125
  //#region src/plugins/bearer/plugin.d.ts
@@ -1,4 +1,4 @@
1
- import { t as wrappedFetch } from "../fetch-Cp9z9f4v.js";
1
+ import { t as wrappedFetch } from "../fetch-CSMExG79.js";
2
2
  import { parse } from "cookie";
3
3
 
4
4
  //#region src/plugins/email-password/plugin.ts
@@ -52,7 +52,7 @@ var OAuth2Plugin = class {
52
52
  id = "oauth2";
53
53
  init(client) {
54
54
  return { signIn: async (data) => {
55
- return wrappedFetch(client, `/oauth2/authorize/${data.provider}?redirect_to=${data.redirect_to}`, { method: "GET" });
55
+ return wrappedFetch(client, `/oauth2/authorize/${data.provider}?redirect_to=${data.redirectTo}`, { method: "GET" });
56
56
  } };
57
57
  }
58
58
  };
@@ -148,10 +148,10 @@ var BearerPlugin = class {
148
148
  }
149
149
  if (!this.refreshPromise) this.refreshPromise = (async () => {
150
150
  try {
151
- const response = await client.jwt.refreshToken({ refresh_token: refreshToken });
151
+ const response = await client.jwt.refreshToken({ refreshToken });
152
152
  if (!response) return null;
153
- localStorage.setItem("accessToken", response.access_token);
154
- localStorage.setItem("refreshToken", response.refresh_token);
153
+ localStorage.setItem("accessToken", response.accessToken);
154
+ localStorage.setItem("refreshToken", response.refreshToken);
155
155
  return response;
156
156
  } finally {
157
157
  this.refreshPromise = null;
@@ -162,9 +162,8 @@ var BearerPlugin = class {
162
162
  const headerName = this.options?.headerName ?? "Authorization";
163
163
  ctx.init.headers = {
164
164
  ...ctx.init.headers,
165
- [headerName]: `Bearer ${refreshed.access_token}`
165
+ [headerName]: `Bearer ${refreshed.accessToken}`
166
166
  };
167
- ctx.meta.retry = true;
168
167
  return "retry";
169
168
  });
170
169
  return {};
@@ -1 +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;AACtC,SAAO;GACL,QAAQ,OAAU,SAAoC;AACpD,WAAO,aAAgB,QAAQ,YAAY;KACzC,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,QAAQ,OAAU,SAAoC;AACpD,WAAO,aAAgB,QAAQ,YAAY;KACzC,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,uBAAuB,OACrB,SACkB;AAClB,WAAO,aAAa,QAAQ,4BAA4B;KACtD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,sBAAsB,OACpB,SACkB;AAClB,WAAO,aAAa,QAAQ,2BAA2B;KACrD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,gBAAgB,OAAO,SAA+C;AACpE,WAAO,aAAa,QAAQ,oBAAoB;KAC9C,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,oBAAoB,OAClB,SACkB;AAClB,WAAO,aAAa,QAAQ,yBAAyB;KACnD,QAAQ;KACR,MAAM;KACP,CAAC;;GAEL;;;;;;ACnDL,IAAa,eAAb,MAA4C;CAC1C,AAAgB,KAAK;CAErB,AAAO,KAAK,QAA4B;AACtC,SAAO,EACL,QAAQ,OACN,SACsC;AACtC,UAAO,aACL,QACA,qBAAqB,KAAK,SAAS,eAAe,KAAK,eACvD,EACE,QAAQ,OACT,CACF;KAEJ;;;;;;AClBL,IAAa,aAAb,MAA0C;CACxC,AAAgB,KAAK;CAErB,YAAY,AAAiB,SAA4B;EAA5B;;CAE7B,AAAO,KAAK,QAA4B;AACtC,SAAO,oBAAoB,OAAO,QAAsB;AAEtD,OAAI,OAAO,aAAa,aAAa;AACn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jD,OAAI,MACF,KAAI,KAAK,UAAU;IACjB,GAAG,IAAI,KAAK;KACX,aAAa,UAAU;IACzB;IAEH;AAEF,SAAO,mBAAmB,OAAO,KAAmB,QAAkB;AACpE,OAAI,OAAO,aAAa,YAAa;AACrC,OAAI,IAAI,WAAW,IAAK;AACxB,OAAI,IAAI,KAAK,MAAO;GAEpB,MAAM,eAAe,aAAa,QAAQ,eAAe;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"}
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.redirectTo}`,\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\") {\n return;\n }\n if (res.status !== 401) {\n return;\n }\n if (ctx.meta.retry) {\n return;\n }\n\n const refreshToken = localStorage.getItem(\"refreshToken\");\n if (!refreshToken) {\n return;\n }\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 refreshToken: refreshToken,\n });\n if (!response) {\n return null;\n }\n\n localStorage.setItem(\"accessToken\", response.accessToken);\n localStorage.setItem(\"refreshToken\", response.refreshToken);\n\n return response;\n } finally {\n this.refreshPromise = null;\n }\n })();\n }\n\n const refreshed = await this.refreshPromise;\n if (!refreshed) {\n return;\n }\n\n const headerName = this.options?.headerName ?? \"Authorization\";\n ctx.init.headers = {\n ...ctx.init.headers,\n [headerName]: `Bearer ${refreshed.accessToken}`,\n };\n\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,WAAO,aAAgB,QAAQ,YAAY;KACzC,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,QAAQ,OAAU,SAAoC;AACpD,WAAO,aAAgB,QAAQ,YAAY;KACzC,QAAQ;KACR,MAAM;KACP,CAAC;;GAEJ,uBAAuB,OACrB,SACkB;AAClB,WAAO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GT,kBAAa,QAAQ,eAAe,SAAS,YAAY;AACzD,kBAAa,QAAQ,gBAAgB,SAAS,aAAa;AAE3D,YAAO;cACC;AACR,UAAK,iBAAiB;;OAEtB;GAGN,MAAM,YAAY,MAAM,KAAK;AAC7B,OAAI,CAAC,UACH;GAGF,MAAM,aAAa,KAAK,SAAS,cAAc;AAC/C,OAAI,KAAK,UAAU;IACjB,GAAG,IAAI,KAAK;KACX,aAAa,UAAU,UAAU;IACnC;AAED,UAAO;IACP;AAEF,SAAO,EAAE"}
@@ -25,37 +25,37 @@ declare const userSchema: z.ZodObject<{
25
25
  id: z.ZodUUID;
26
26
  name: z.ZodString;
27
27
  email: z.ZodEmail;
28
- email_verified: z.ZodBoolean;
28
+ emailVerified: z.ZodBoolean;
29
29
  image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
- created_at: z.ZodISODateTime;
31
- updated_at: z.ZodISODateTime;
30
+ createdAt: z.ZodISODateTime;
31
+ updatedAt: z.ZodISODateTime;
32
32
  }, z.core.$strip>;
33
33
  type User = z.infer<typeof userSchema>;
34
34
  declare const accountSchema: z.ZodObject<{
35
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>>;
36
+ userId: z.ZodString;
37
+ accountId: z.ZodString;
38
+ providerId: z.ZodString;
39
+ accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
40
+ refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
41
+ idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
42
+ accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
43
+ refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
44
44
  scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
45
  password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
- created_at: z.ZodISODateTime;
47
- updated_at: z.ZodISODateTime;
46
+ createdAt: z.ZodISODateTime;
47
+ updatedAt: z.ZodISODateTime;
48
48
  }, z.core.$strip>;
49
49
  type Account = z.infer<typeof accountSchema>;
50
50
  declare const sessionSchema: z.ZodObject<{
51
51
  id: z.ZodUUID;
52
- user_id: z.ZodString;
52
+ userId: z.ZodString;
53
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;
54
+ expiresAt: z.ZodISODateTime;
55
+ ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
57
+ createdAt: z.ZodISODateTime;
58
+ updatedAt: z.ZodISODateTime;
59
59
  }, z.core.$strip>;
60
60
  type Session = z.infer<typeof sessionSchema>;
61
61
  declare const verificationTypeSchema: z.ZodEnum<{
@@ -66,7 +66,7 @@ declare const verificationTypeSchema: z.ZodEnum<{
66
66
  type VerificationType = z.infer<typeof verificationTypeSchema>;
67
67
  declare const verificationSchema: z.ZodObject<{
68
68
  id: z.ZodUUID;
69
- user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
+ userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
70
70
  identifier: z.ZodString;
71
71
  token: z.ZodString;
72
72
  type: z.ZodEnum<{
@@ -74,9 +74,9 @@ declare const verificationSchema: z.ZodObject<{
74
74
  password_reset_request: "password_reset_request";
75
75
  email_reset_request: "email_reset_request";
76
76
  }>;
77
- expires_at: z.ZodISODateTime;
78
- created_at: z.ZodISODateTime;
79
- updated_at: z.ZodISODateTime;
77
+ expiresAt: z.ZodISODateTime;
78
+ createdAt: z.ZodISODateTime;
79
+ updatedAt: z.ZodISODateTime;
80
80
  }, z.core.$strip>;
81
81
  type Verification = z.infer<typeof verificationSchema>;
82
82
  //#endregion
@@ -142,8 +142,8 @@ type GetMeResponse = {
142
142
  session: Session;
143
143
  };
144
144
  type SignOutRequest = {
145
- session_id?: string;
146
- sign_out_all?: boolean;
145
+ sessionId?: string;
146
+ signOutAll?: boolean;
147
147
  };
148
148
  type SignOutResponse = {
149
149
  message: string;
@@ -159,4 +159,4 @@ declare function createClient<const T extends readonly Plugin[]>(options: Omit<G
159
159
  }): ClientWithPlugins<T>;
160
160
  //#endregion
161
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
162
+ //# sourceMappingURL=sdk-1FEcNixu.d.cts.map
@@ -25,37 +25,37 @@ declare const userSchema: z.ZodObject<{
25
25
  id: z.ZodUUID;
26
26
  name: z.ZodString;
27
27
  email: z.ZodEmail;
28
- email_verified: z.ZodBoolean;
28
+ emailVerified: z.ZodBoolean;
29
29
  image: z.ZodOptional<z.ZodNullable<z.ZodString>>;
30
- created_at: z.ZodISODateTime;
31
- updated_at: z.ZodISODateTime;
30
+ createdAt: z.ZodISODateTime;
31
+ updatedAt: z.ZodISODateTime;
32
32
  }, z.core.$strip>;
33
33
  type User = z.infer<typeof userSchema>;
34
34
  declare const accountSchema: z.ZodObject<{
35
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>>;
36
+ userId: z.ZodString;
37
+ accountId: z.ZodString;
38
+ providerId: z.ZodString;
39
+ accessToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
40
+ refreshToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
41
+ idToken: z.ZodOptional<z.ZodNullable<z.ZodString>>;
42
+ accessTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
43
+ refreshTokenExpiresAt: z.ZodOptional<z.ZodNullable<z.ZodISODateTime>>;
44
44
  scope: z.ZodOptional<z.ZodNullable<z.ZodString>>;
45
45
  password: z.ZodOptional<z.ZodNullable<z.ZodString>>;
46
- created_at: z.ZodISODateTime;
47
- updated_at: z.ZodISODateTime;
46
+ createdAt: z.ZodISODateTime;
47
+ updatedAt: z.ZodISODateTime;
48
48
  }, z.core.$strip>;
49
49
  type Account = z.infer<typeof accountSchema>;
50
50
  declare const sessionSchema: z.ZodObject<{
51
51
  id: z.ZodUUID;
52
- user_id: z.ZodString;
52
+ userId: z.ZodString;
53
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;
54
+ expiresAt: z.ZodISODateTime;
55
+ ipAddress: z.ZodOptional<z.ZodNullable<z.ZodString>>;
56
+ userAgent: z.ZodOptional<z.ZodNullable<z.ZodString>>;
57
+ createdAt: z.ZodISODateTime;
58
+ updatedAt: z.ZodISODateTime;
59
59
  }, z.core.$strip>;
60
60
  type Session = z.infer<typeof sessionSchema>;
61
61
  declare const verificationTypeSchema: z.ZodEnum<{
@@ -66,7 +66,7 @@ declare const verificationTypeSchema: z.ZodEnum<{
66
66
  type VerificationType = z.infer<typeof verificationTypeSchema>;
67
67
  declare const verificationSchema: z.ZodObject<{
68
68
  id: z.ZodUUID;
69
- user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
69
+ userId: z.ZodOptional<z.ZodNullable<z.ZodString>>;
70
70
  identifier: z.ZodString;
71
71
  token: z.ZodString;
72
72
  type: z.ZodEnum<{
@@ -74,9 +74,9 @@ declare const verificationSchema: z.ZodObject<{
74
74
  password_reset_request: "password_reset_request";
75
75
  email_reset_request: "email_reset_request";
76
76
  }>;
77
- expires_at: z.ZodISODateTime;
78
- created_at: z.ZodISODateTime;
79
- updated_at: z.ZodISODateTime;
77
+ expiresAt: z.ZodISODateTime;
78
+ createdAt: z.ZodISODateTime;
79
+ updatedAt: z.ZodISODateTime;
80
80
  }, z.core.$strip>;
81
81
  type Verification = z.infer<typeof verificationSchema>;
82
82
  //#endregion
@@ -142,8 +142,8 @@ type GetMeResponse = {
142
142
  session: Session;
143
143
  };
144
144
  type SignOutRequest = {
145
- session_id?: string;
146
- sign_out_all?: boolean;
145
+ sessionId?: string;
146
+ signOutAll?: boolean;
147
147
  };
148
148
  type SignOutResponse = {
149
149
  message: string;
@@ -159,4 +159,4 @@ declare function createClient<const T extends readonly Plugin[]>(options: Omit<G
159
159
  }): ClientWithPlugins<T>;
160
160
  //#endregion
161
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
162
+ //# sourceMappingURL=sdk-NIFb1TeL.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "go-better-auth",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "description": "Official SDK for GoBetterAuth.",
6
6
  "license": "Apache-2.0",
7
7
  "homepage": "https://github.com/GoBetterAuth/go-better-auth-node-sdk#readme",
@@ -34,14 +34,16 @@
34
34
  "dev": "tsdown --watch",
35
35
  "typecheck": "tsc --noEmit",
36
36
  "test": "vitest run",
37
+ "test:watch": "vitest --watch",
37
38
  "prepublishOnly": "pnpm run build"
38
39
  },
39
40
  "dependencies": {
40
41
  "cookie": "^1.1.1",
42
+ "es-toolkit": "^1.44.0",
41
43
  "zod": "^4.3.6"
42
44
  },
43
45
  "devDependencies": {
44
- "@types/node": "^25.0.10",
46
+ "@types/node": "^25.1.0",
45
47
  "bumpp": "^10.4.0",
46
48
  "tsdown": "^0.20.1",
47
49
  "typescript": "^5.9.3",
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch-Cp9z9f4v.js","names":[],"sources":["../src/fetch.ts"],"sourcesContent":["import type { GoBetterAuthClient } from \"./client\";\nimport type { CookieStore, FetchContext, FetchRequestOptions } from \"./types\";\n\nexport async function wrappedFetch<T>(\n client: GoBetterAuthClient,\n endpoint: string,\n options: FetchRequestOptions = {},\n): Promise<T> {\n const headers = new Headers(options.headers || {});\n\n let cookieStore: CookieStore | null = null;\n\n if (client.config.cookies) {\n cookieStore = await client.config.cookies();\n\n const cookieHeader = cookieStore\n .getAll()\n .map((c) => `${c.name}=${c.value}`)\n .join(\"; \");\n\n if (cookieHeader) {\n headers.set(\"cookie\", cookieHeader);\n }\n }\n\n const controller = new AbortController();\n const abortTimeout = client.config.fetchOptions?.abortTimeout;\n\n if (abortTimeout) {\n setTimeout(() => controller.abort(), abortTimeout * 1000);\n }\n\n const ctx: FetchContext = {\n url: `${client.config.url}${endpoint}`,\n init: {\n method: options.method ?? \"GET\",\n headers,\n body: options.body ? JSON.stringify(options.body) : undefined,\n credentials: \"include\",\n signal: controller.signal,\n },\n meta: {},\n };\n\n await client.runBeforeFetch(ctx);\n\n let res = await fetch(ctx.url, ctx.init);\n\n const action = await client.runAfterFetch(ctx, res);\n if (action === \"retry\" && !ctx.meta.retry) {\n ctx.meta.retry = true;\n res = await fetch(ctx.url, ctx.init);\n }\n\n const setCookieHeaders =\n res.headers.getSetCookie?.() ??\n res.headers.get(\"set-cookie\")?.split(\", \") ??\n null;\n\n if (!res.ok) {\n throw new Error(await res.text());\n }\n\n const data = await res.json();\n\n // Apply Set-Cookie back into Next.js store (SSR only)\n if (cookieStore && setCookieHeaders) {\n for (const raw of setCookieHeaders) {\n const [pair, ...attrs] = raw.split(\";\");\n const [name, value] = pair.split(\"=\");\n\n if (!name || !value) continue;\n\n const options: Record<string, any> = {};\n\n for (const attr of attrs) {\n const [k, v] = attr.trim().split(\"=\");\n\n switch (k.toLowerCase()) {\n case \"path\":\n options.path = v;\n break;\n case \"expires\":\n options.expires = new Date(v);\n break;\n case \"max-age\":\n options.maxAge = Number(v);\n break;\n case \"httponly\":\n options.httpOnly = true;\n break;\n case \"secure\":\n options.secure = true;\n break;\n case \"samesite\":\n options.sameSite = v?.toLowerCase();\n break;\n }\n }\n\n cookieStore.set(name.trim(), decodeURIComponent(value.trim()), options);\n }\n }\n\n return data as T;\n}\n"],"mappings":";AAGA,eAAsB,aACpB,QACA,UACA,UAA+B,EAAE,EACrB;CACZ,MAAM,UAAU,IAAI,QAAQ,QAAQ,WAAW,EAAE,CAAC;CAElD,IAAI,cAAkC;AAEtC,KAAI,OAAO,OAAO,SAAS;AACzB,gBAAc,MAAM,OAAO,OAAO,SAAS;EAE3C,MAAM,eAAe,YAClB,QAAQ,CACR,KAAK,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vB;IACE,KAAK;AACH,aAAQ,OAAO;AACf;IACF,KAAK;AACH,aAAQ,UAAU,IAAI,KAAK,EAAE;AAC7B;IACF,KAAK;AACH,aAAQ,SAAS,OAAO,EAAE;AAC1B;IACF,KAAK;AACH,aAAQ,WAAW;AACnB;IACF,KAAK;AACH,aAAQ,SAAS;AACjB;IACF,KAAK;AACH,aAAQ,WAAW,GAAG,aAAa;AACnC;;;AAIN,cAAY,IAAI,KAAK,MAAM,EAAE,mBAAmB,MAAM,MAAM,CAAC,EAAE,QAAQ;;AAI3E,QAAO"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch-v3PWCtqe.cjs","names":[],"sources":["../src/fetch.ts"],"sourcesContent":["import type { GoBetterAuthClient } from \"./client\";\nimport type { CookieStore, FetchContext, FetchRequestOptions } from \"./types\";\n\nexport async function wrappedFetch<T>(\n client: GoBetterAuthClient,\n endpoint: string,\n options: FetchRequestOptions = {},\n): Promise<T> {\n const headers = new Headers(options.headers || {});\n\n let cookieStore: CookieStore | null = null;\n\n if (client.config.cookies) {\n cookieStore = await client.config.cookies();\n\n const cookieHeader = cookieStore\n .getAll()\n .map((c) => `${c.name}=${c.value}`)\n .join(\"; \");\n\n if (cookieHeader) {\n headers.set(\"cookie\", cookieHeader);\n }\n }\n\n const controller = new AbortController();\n const abortTimeout = client.config.fetchOptions?.abortTimeout;\n\n if (abortTimeout) {\n setTimeout(() => controller.abort(), abortTimeout * 1000);\n }\n\n const ctx: FetchContext = {\n url: `${client.config.url}${endpoint}`,\n init: {\n method: options.method ?? \"GET\",\n headers,\n body: options.body ? JSON.stringify(options.body) : undefined,\n credentials: \"include\",\n signal: controller.signal,\n },\n meta: {},\n };\n\n await client.runBeforeFetch(ctx);\n\n let res = await fetch(ctx.url, ctx.init);\n\n const action = await client.runAfterFetch(ctx, res);\n if (action === \"retry\" && !ctx.meta.retry) {\n ctx.meta.retry = true;\n res = await fetch(ctx.url, ctx.init);\n }\n\n const setCookieHeaders =\n res.headers.getSetCookie?.() ??\n res.headers.get(\"set-cookie\")?.split(\", \") ??\n null;\n\n if (!res.ok) {\n throw new Error(await res.text());\n }\n\n const data = await res.json();\n\n // Apply Set-Cookie back into Next.js store (SSR only)\n if (cookieStore && setCookieHeaders) {\n for (const raw of setCookieHeaders) {\n const [pair, ...attrs] = raw.split(\";\");\n const [name, value] = pair.split(\"=\");\n\n if (!name || !value) continue;\n\n const options: Record<string, any> = {};\n\n for (const attr of attrs) {\n const [k, v] = attr.trim().split(\"=\");\n\n switch (k.toLowerCase()) {\n case \"path\":\n options.path = v;\n break;\n case \"expires\":\n options.expires = new Date(v);\n break;\n case \"max-age\":\n options.maxAge = Number(v);\n break;\n case \"httponly\":\n options.httpOnly = true;\n break;\n case \"secure\":\n options.secure = true;\n break;\n case \"samesite\":\n options.sameSite = v?.toLowerCase();\n break;\n }\n }\n\n cookieStore.set(name.trim(), decodeURIComponent(value.trim()), options);\n }\n }\n\n return data as T;\n}\n"],"mappings":";;AAGA,eAAsB,aACpB,QACA,UACA,UAA+B,EAAE,EACrB;CACZ,MAAM,UAAU,IAAI,QAAQ,QAAQ,WAAW,EAAE,CAAC;CAElD,IAAI,cAAkC;AAEtC,KAAI,OAAO,OAAO,SAAS;AACzB,gBAAc,MAAM,OAAO,OAAO,SAAS;EAE3C,MAAM,eAAe,YAClB,QAAQ,CACR,KAAK,MAAM,GAAG,EAAE,KAAK,GAAG,EAAE,QAAQ,CAClC,KAAK,KAAK;AAEb,MAAI,aACF,SAAQ,IAAI,UAAU,aAAa;;CAIvC,MAAM,aAAa,IAAI,iBAAiB;CACxC,MAAM,eAAe,OAAO,OAAO,cAAc;AAEjD,KAAI,aACF,kBAAiB,WAAW,OAAO,EAAE,eAAe,IAAK;CAG3D,MAAM,MAAoB;EACxB,KAAK,GAAG,OAAO,OAAO,MAAM;EAC5B,MAAM;GACJ,QAAQ,QAAQ,UAAU;GAC1B;GACA,MAAM,QAAQ,OAAO,KAAK,UAAU,QAAQ,KAAK,GAAG;GACp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