@better-auth/electron 1.5.6 → 1.6.0-beta.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.
@@ -241,14 +241,7 @@ interface ElectronProxyClientOptions extends ElectronSharedClientOptions {
241
241
  //#region src/authenticate.d.ts
242
242
  declare const kElectron: unique symbol;
243
243
  declare const requestAuthOptionsSchema: z.ZodObject<{
244
- provider: z.ZodOptional<z.ZodString>;
245
- callbackURL: z.ZodOptional<z.ZodString>;
246
- newUserCallbackURL: z.ZodOptional<z.ZodString>;
247
- errorCallbackURL: z.ZodOptional<z.ZodString>;
248
- disableRedirect: z.ZodOptional<z.ZodBoolean>;
249
- scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
250
- requestSignUp: z.ZodOptional<z.ZodBoolean>;
251
- additionalData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
244
+ [x: string]: any;
252
245
  }, z.core.$strip>;
253
246
  type ElectronRequestAuthOptions = z.infer<typeof requestAuthOptionsSchema>;
254
247
  /**
@@ -314,11 +307,13 @@ declare function handleDeepLink({
314
307
  //#region src/client.d.ts
315
308
  declare const electronClient: <O extends ElectronClientOptions>(options: O) => {
316
309
  id: "electron";
310
+ version: string;
317
311
  fetchPlugins: {
318
312
  id: string;
319
313
  name: string;
320
314
  init(url: string, options: ({
321
315
  priority?: RequestPriority | undefined;
316
+ mode?: RequestMode | undefined;
322
317
  cache?: RequestCache | undefined;
323
318
  credentials?: RequestCredentials | undefined;
324
319
  headers?: (HeadersInit & (HeadersInit | {
@@ -329,7 +324,6 @@ declare const electronClient: <O extends ElectronClientOptions>(options: O) => {
329
324
  integrity?: string | undefined;
330
325
  keepalive?: boolean | undefined;
331
326
  method?: string | undefined;
332
- mode?: RequestMode | undefined;
333
327
  redirect?: RequestRedirect | undefined;
334
328
  referrer?: string | undefined;
335
329
  referrerPolicy?: ReferrerPolicy | undefined;
@@ -374,6 +368,7 @@ declare const electronClient: <O extends ElectronClientOptions>(options: O) => {
374
368
  url: string;
375
369
  options: {
376
370
  priority?: RequestPriority | undefined;
371
+ mode?: RequestMode | undefined;
377
372
  cache?: RequestCache | undefined;
378
373
  credentials?: RequestCredentials | undefined;
379
374
  headers?: (HeadersInit & (HeadersInit | {
@@ -384,7 +379,6 @@ declare const electronClient: <O extends ElectronClientOptions>(options: O) => {
384
379
  integrity?: string | undefined;
385
380
  keepalive?: boolean | undefined;
386
381
  method?: string | undefined;
387
- mode?: RequestMode | undefined;
388
382
  redirect?: RequestRedirect | undefined;
389
383
  referrer?: string | undefined;
390
384
  referrerPolicy?: ReferrerPolicy | undefined;
package/dist/client.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { _ as setupRenderer, a as authenticate, c as ElectronClientOptions, d as Storage, f as FetchUserImageResult, g as SetupRendererConfig, h as ExposedBridges, i as ElectronRequestAuthOptions, l as ElectronProxyClientOptions, m as normalizeUserOutput, n as handleDeepLink, o as kElectron, p as fetchUserImage, r as ElectronAuthenticateOptions, s as requestAuth, t as electronClient, u as ElectronSharedClientOptions, y as ElectronSharedOptions } from "./client-DVs5eLfi.mjs";
1
+ import { _ as setupRenderer, a as authenticate, c as ElectronClientOptions, d as Storage, f as FetchUserImageResult, g as SetupRendererConfig, h as ExposedBridges, i as ElectronRequestAuthOptions, l as ElectronProxyClientOptions, m as normalizeUserOutput, n as handleDeepLink, o as kElectron, p as fetchUserImage, r as ElectronAuthenticateOptions, s as requestAuth, t as electronClient, u as ElectronSharedClientOptions, y as ElectronSharedOptions } from "./client-CMv-uqSO.mjs";
2
2
  export { ElectronAuthenticateOptions, ElectronClientOptions, ElectronProxyClientOptions, ElectronRequestAuthOptions, ElectronSharedClientOptions, ElectronSharedOptions, ExposedBridges, FetchUserImageResult, SetupRendererConfig, Storage, authenticate, electronClient, fetchUserImage, handleDeepLink, kElectron, normalizeUserOutput, requestAuth, setupRenderer };
package/dist/client.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import { n as isProcessType, r as parseProtocolScheme, t as getChannelPrefixWithDelimiter } from "./utils-DecLU66o.mjs";
1
+ import { t as PACKAGE_VERSION } from "./version-BqMHXjG-.mjs";
2
+ import { n as isProcessType, r as parseProtocolScheme, t as getChannelPrefixWithDelimiter } from "./utils-DxDKRT6e.mjs";
2
3
  import { BetterAuthError } from "@better-auth/core/error";
3
4
  import { base64, base64Url } from "@better-auth/utils/base64";
4
5
  import { APIError as APIError$1, getBaseURL, isDevelopment, isTest, safeJSONParse } from "better-auth";
@@ -11,7 +12,6 @@ import { parseSetCookieHeader } from "better-auth/cookies";
11
12
  import electron, { shell } from "electron";
12
13
  import { isDevelopment as isDevelopment$1 } from "@better-auth/core/env";
13
14
  import { resolve } from "node:path";
14
-
15
15
  //#region src/user.ts
16
16
  const { net } = electron;
17
17
  const DEFAULT_MAX_BYTES = 1024 * 1024 * 5;
@@ -151,7 +151,6 @@ function detectImageType(bytes) {
151
151
  if (brand === "heix" || brand === "hevc" || brand === "mif1" || brand === "msf1") return "image/heic";
152
152
  return null;
153
153
  }
154
-
155
154
  //#endregion
156
155
  //#region src/authenticate.ts
157
156
  const kElectron = Symbol.for("better-auth:electron");
@@ -224,7 +223,6 @@ async function authenticate({ $fetch, options, token, getWindow, fetchOptions })
224
223
  }
225
224
  });
226
225
  }
227
-
228
226
  //#endregion
229
227
  //#region src/browser.ts
230
228
  const { app: app$1, session, protocol, BrowserWindow, ipcMain, webContents: webContents$1 } = electron;
@@ -467,7 +465,6 @@ function setupUserImageProxy(ctx, opts, clientOptions) {
467
465
  });
468
466
  });
469
467
  }
470
-
471
468
  //#endregion
472
469
  //#region src/cookies.ts
473
470
  function getSetCookie(header, prevCookie) {
@@ -553,7 +550,6 @@ function hasBetterAuthCookies(setCookieHeader, cookiePrefix) {
553
550
  }
554
551
  return false;
555
552
  }
556
-
557
553
  //#endregion
558
554
  //#region src/client.ts
559
555
  const { app, safeStorage, webContents } = electron;
@@ -601,6 +597,7 @@ const electronClient = (options) => {
601
597
  if ((isDevelopment() || isTest()) && /^(?!\.)(?!.*\.\.)(?!.*\.$)[^.]+\.[^.]+$/.test(scheme)) console.warn("The provided scheme does not follow the reverse domain name notation. For example: `app.example.com` -> `com.example.app`.");
602
598
  return {
603
599
  id: "electron",
600
+ version: PACKAGE_VERSION,
604
601
  fetchPlugins: [{
605
602
  id: "electron",
606
603
  name: "Electron",
@@ -683,6 +680,5 @@ const electronClient = (options) => {
683
680
  }
684
681
  };
685
682
  };
686
-
687
683
  //#endregion
688
- export { electronClient, handleDeepLink, normalizeUserOutput };
684
+ export { electronClient, handleDeepLink, normalizeUserOutput };
package/dist/index.d.mts CHANGED
@@ -1,6 +1,5 @@
1
- import { f as FetchUserImageResult, m as normalizeUserOutput, p as fetchUserImage, v as ElectronOptions, y as ElectronSharedOptions } from "./client-DVs5eLfi.mjs";
1
+ import { f as FetchUserImageResult, m as normalizeUserOutput, p as fetchUserImage, v as ElectronOptions, y as ElectronSharedOptions } from "./client-CMv-uqSO.mjs";
2
2
  import * as better_auth0 from "better-auth";
3
- import * as z from "zod";
4
3
  import * as _better_auth_core0 from "@better-auth/core";
5
4
  import { HookEndpointContext } from "@better-auth/core";
6
5
  import * as better_call0 from "better-call";
@@ -15,16 +14,17 @@ declare module "@better-auth/core" {
15
14
  }
16
15
  declare const electron: (options?: ElectronOptions | undefined) => {
17
16
  id: "electron";
17
+ version: string;
18
18
  onRequest(request: Request, _ctx: better_auth0.AuthContext): Promise<{
19
19
  request: Request;
20
20
  } | undefined>;
21
21
  hooks: {
22
22
  after: ({
23
23
  matcher: (ctx: HookEndpointContext) => boolean;
24
- handler: (inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<void>;
24
+ handler: better_call0.Middleware<(inputContext: Record<string, any>) => Promise<void>>;
25
25
  } | {
26
26
  matcher: (ctx: HookEndpointContext) => boolean;
27
- handler: (inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<better_call0.MiddlewareContext<better_call0.MiddlewareOptions, {
27
+ handler: better_call0.Middleware<(inputContext: Record<string, any>) => Promise<better_call0.MiddlewareContext<{
28
28
  returned?: unknown | undefined;
29
29
  responseHeaders?: Headers | undefined;
30
30
  } & better_auth0.PluginContext<better_auth0.BetterAuthOptions> & better_auth0.InfoContext & {
@@ -154,171 +154,156 @@ declare const electron: (options?: ElectronOptions | undefined) => {
154
154
  runInBackgroundOrAwait: (promise: Promise<unknown> | void) => better_auth0.Awaitable<unknown>;
155
155
  }> | {
156
156
  electron_authorization_code: string;
157
- } | undefined>;
157
+ } | undefined>>;
158
158
  })[];
159
159
  };
160
160
  endpoints: {
161
- electronToken: better_call0.StrictEndpoint<"/electron/token", {
162
- method: "POST";
163
- body: z.ZodObject<{
164
- token: z.ZodString;
165
- state: z.ZodString;
166
- code_verifier: z.ZodString;
167
- }, z.core.$strip>;
168
- metadata: {
169
- scope: "http";
170
- openapi: {
171
- description: string;
172
- operationId: string;
173
- responses: {
174
- 200: {
175
- description: string;
176
- content: {
177
- "application/json": {
178
- schema: {
179
- type: "object";
180
- properties: {
181
- token: {
182
- type: string;
183
- };
184
- user: {
185
- type: string;
186
- $ref: string;
187
- };
188
- };
189
- required: string[];
190
- };
191
- };
192
- };
193
- };
194
- };
195
- };
196
- };
197
- }, {
161
+ electronToken: better_call0.Endpoint<"/electron/token", "POST", {
162
+ token: string;
163
+ state: string;
164
+ code_verifier: string;
165
+ }, Record<string, any> | undefined, [], {
198
166
  token: string;
199
167
  user: better_auth0.User & Record<string, any>;
200
- }>;
201
- electronInitOAuthProxy: better_call0.StrictEndpoint<"/electron/init-oauth-proxy", {
202
- method: "GET";
203
- query: z.ZodObject<{
204
- provider: z.ZodString;
205
- state: z.ZodString;
206
- code_challenge: z.ZodString;
207
- code_challenge_method: z.ZodOptional<z.ZodString>;
208
- }, z.core.$strip>;
209
- metadata: {
210
- scope: "http";
211
- openapi: {
212
- description: string;
213
- operationId: string;
214
- responses: {
215
- 200: {
216
- description: string;
217
- content: {
218
- "application/json": {
219
- schema: {
220
- type: "object";
221
- properties: {
222
- url: {
223
- type: string;
224
- nullable: boolean;
225
- };
226
- redirect: {
227
- type: string;
228
- };
229
- user: {
230
- type: string;
231
- $ref: string;
232
- };
233
- token: {
234
- type: string;
235
- };
168
+ }, {
169
+ scope: "http";
170
+ openapi: {
171
+ description: string;
172
+ operationId: string;
173
+ responses: {
174
+ 200: {
175
+ description: string;
176
+ content: {
177
+ "application/json": {
178
+ schema: {
179
+ type: "object";
180
+ properties: {
181
+ token: {
182
+ type: string;
183
+ };
184
+ user: {
185
+ type: string;
186
+ $ref: string;
236
187
  };
237
- required: string[];
238
188
  };
189
+ required: string[];
239
190
  };
240
191
  };
241
192
  };
242
193
  };
243
194
  };
244
195
  };
245
- }, {
196
+ }, undefined>;
197
+ electronInitOAuthProxy: better_call0.Endpoint<"/electron/init-oauth-proxy", "GET", undefined, {
198
+ provider: string;
199
+ state: string;
200
+ code_challenge: string;
201
+ code_challenge_method?: string | undefined;
202
+ }, [], {
246
203
  url: string | undefined;
247
204
  redirect: boolean;
248
205
  user?: better_auth0.User & Record<string, any>;
249
206
  token?: string;
250
- } | undefined>;
251
- electronTransferUser: better_call0.StrictEndpoint<"/electron/transfer-user", {
252
- method: "POST";
253
- query: z.ZodObject<{
254
- client_id: z.ZodString;
255
- state: z.ZodString;
256
- code_challenge: z.ZodString;
257
- code_challenge_method: z.ZodOptional<z.ZodString>;
258
- }, z.core.$strip>;
259
- body: z.ZodObject<{
260
- callbackURL: z.ZodOptional<z.ZodString>;
261
- }, z.core.$strip>;
262
- use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
263
- session: {
264
- session: Record<string, any> & {
265
- id: string;
266
- createdAt: Date;
267
- updatedAt: Date;
268
- userId: string;
269
- expiresAt: Date;
270
- token: string;
271
- ipAddress?: string | null | undefined;
272
- userAgent?: string | null | undefined;
273
- };
274
- user: Record<string, any> & {
275
- id: string;
276
- createdAt: Date;
277
- updatedAt: Date;
278
- email: string;
279
- emailVerified: boolean;
280
- name: string;
281
- image?: string | null | undefined;
282
- };
283
- };
284
- }>)[];
285
- requireHeaders: true;
286
- metadata: {
287
- openapi: {
288
- description: string;
289
- operationId: string;
290
- responses: {
291
- 200: {
292
- description: string;
293
- content: {
294
- "application/json": {
295
- schema: {
296
- type: "object";
297
- properties: {
298
- url: {
299
- type: string;
300
- nullable: boolean;
301
- };
302
- redirect: {
303
- type: string;
304
- };
305
- electron_authorization_code: {
306
- type: string;
307
- };
207
+ } | undefined, {
208
+ scope: "http";
209
+ openapi: {
210
+ description: string;
211
+ operationId: string;
212
+ responses: {
213
+ 200: {
214
+ description: string;
215
+ content: {
216
+ "application/json": {
217
+ schema: {
218
+ type: "object";
219
+ properties: {
220
+ url: {
221
+ type: string;
222
+ nullable: boolean;
223
+ };
224
+ redirect: {
225
+ type: string;
226
+ };
227
+ user: {
228
+ type: string;
229
+ $ref: string;
230
+ };
231
+ token: {
232
+ type: string;
308
233
  };
309
- required: string[];
310
234
  };
235
+ required: string[];
311
236
  };
312
237
  };
313
238
  };
314
239
  };
315
240
  };
316
241
  };
242
+ }, undefined>;
243
+ electronTransferUser: better_call0.Endpoint<"/electron/transfer-user", "POST", {
244
+ callbackURL?: string | undefined;
317
245
  }, {
246
+ client_id: string;
247
+ state: string;
248
+ code_challenge: string;
249
+ code_challenge_method?: string | undefined;
250
+ }, [better_call0.Middleware<(inputContext: Record<string, any>) => Promise<{
251
+ session: {
252
+ session: Record<string, any> & {
253
+ id: string;
254
+ createdAt: Date;
255
+ updatedAt: Date;
256
+ userId: string;
257
+ expiresAt: Date;
258
+ token: string;
259
+ ipAddress?: string | null | undefined;
260
+ userAgent?: string | null | undefined;
261
+ };
262
+ user: Record<string, any> & {
263
+ id: string;
264
+ createdAt: Date;
265
+ updatedAt: Date;
266
+ email: string;
267
+ emailVerified: boolean;
268
+ name: string;
269
+ image?: string | null | undefined;
270
+ };
271
+ };
272
+ }>>], {
318
273
  url: string | null;
319
274
  redirect: boolean;
320
275
  electron_authorization_code: string;
321
- }>;
276
+ }, {
277
+ openapi: {
278
+ description: string;
279
+ operationId: string;
280
+ responses: {
281
+ 200: {
282
+ description: string;
283
+ content: {
284
+ "application/json": {
285
+ schema: {
286
+ type: "object";
287
+ properties: {
288
+ url: {
289
+ type: string;
290
+ nullable: boolean;
291
+ };
292
+ redirect: {
293
+ type: string;
294
+ };
295
+ electron_authorization_code: {
296
+ type: string;
297
+ };
298
+ };
299
+ required: string[];
300
+ };
301
+ };
302
+ };
303
+ };
304
+ };
305
+ };
306
+ }, undefined>;
322
307
  };
323
308
  options: {
324
309
  codeExpiresIn: number;
package/dist/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
+ import { t as PACKAGE_VERSION } from "./version-BqMHXjG-.mjs";
1
2
  import { createAuthMiddleware } from "@better-auth/core/api";
2
3
  import { APIError, BASE_ERROR_CODES } from "@better-auth/core/error";
3
4
  import { base64Url } from "@better-auth/utils/base64";
@@ -13,7 +14,6 @@ import { betterFetch } from "@better-fetch/fetch";
13
14
  import { createAuthEndpoint, sessionMiddleware } from "better-auth/api";
14
15
  import { setSessionCookie } from "better-auth/cookies";
15
16
  import { parseUserOutput } from "better-auth/db";
16
-
17
17
  //#region src/error-codes.ts
18
18
  const ELECTRON_ERROR_CODES = defineErrorCodes({
19
19
  INVALID_CLIENT_ID: "Invalid client ID",
@@ -24,7 +24,6 @@ const ELECTRON_ERROR_CODES = defineErrorCodes({
24
24
  MISSING_STATE: "state is required",
25
25
  MISSING_PKCE: "pkce is required"
26
26
  });
27
-
28
27
  //#endregion
29
28
  //#region src/routes.ts
30
29
  const electronTokenBodySchema = z.object({
@@ -191,7 +190,6 @@ const electronTransferUser = (_opts, { handleTransfer }) => createAuthEndpoint("
191
190
  electron_authorization_code: identifier
192
191
  });
193
192
  });
194
-
195
193
  //#endregion
196
194
  //#region src/index.ts
197
195
  const electron = (options) => {
@@ -238,6 +236,7 @@ const electron = (options) => {
238
236
  };
239
237
  return {
240
238
  id: "electron",
239
+ version: PACKAGE_VERSION,
241
240
  async onRequest(request, _ctx) {
242
241
  if (opts.disableOriginOverride || request.headers.get("origin")) return;
243
242
  const electronOrigin = request.headers.get("electron-origin");
@@ -298,6 +297,5 @@ const electron = (options) => {
298
297
  $ERROR_CODES: ELECTRON_ERROR_CODES
299
298
  };
300
299
  };
301
-
302
300
  //#endregion
303
- export { electron };
301
+ export { electron };