@better-auth/electron 1.5.6 → 1.5.7-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3934,14 +3934,97 @@ type BaseAccount = z.infer<typeof accountSchema>;
3934
3934
  */
3935
3935
  type Account<DBOptions extends BetterAuthOptions["account"] = BetterAuthOptions["account"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify$1<BaseAccount & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"account", Plugins>>; //#endregion
3936
3936
  //#endregion
3937
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/helper.d.mts
3938
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
3939
- type IsEmptyObject<T> = keyof T extends never ? true : false;
3940
- type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
3941
- type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}:${infer Param}` ? { [K in Param]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
3942
- type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}/*` ? { [K in "_"]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamWildCard<Rest> : {}; //#endregion
3937
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/cookies.d.mts
3938
+ //#region src/cookies.d.ts
3939
+ type CookiePrefixOptions = "host" | "secure";
3940
+ type CookieOptions = {
3941
+ /**
3942
+ * Domain of the cookie
3943
+ *
3944
+ * The Domain attribute specifies which server can receive a cookie. If specified, cookies are
3945
+ * available on the specified server and its subdomains. If the it is not
3946
+ * specified, the cookies are available on the server that sets it but not on
3947
+ * its subdomains.
3948
+ *
3949
+ * @example
3950
+ * `domain: "example.com"`
3951
+ */
3952
+ domain?: string;
3953
+ /**
3954
+ * A lifetime of a cookie. Permanent cookies are deleted after the date specified in the
3955
+ * Expires attribute:
3956
+ *
3957
+ * Expires has been available for longer than Max-Age, however Max-Age is less error-prone, and
3958
+ * takes precedence when both are set. The rationale behind this is that when you set an
3959
+ * Expires date and time, they're relative to the client the cookie is being set on. If the
3960
+ * server is set to a different time, this could cause errors
3961
+ */
3962
+ expires?: Date;
3963
+ /**
3964
+ * Forbids JavaScript from accessing the cookie, for example, through the Document.cookie
3965
+ * property. Note that a cookie that has been created with HttpOnly will still be sent with
3966
+ * JavaScript-initiated requests, for example, when calling XMLHttpRequest.send() or fetch().
3967
+ * This mitigates attacks against cross-site scripting
3968
+ */
3969
+ httpOnly?: boolean;
3970
+ /**
3971
+ * Indicates the number of seconds until the cookie expires. A zero or negative number will
3972
+ * expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.
3973
+ *
3974
+ * @example 604800 - 7 days
3975
+ */
3976
+ maxAge?: number;
3977
+ /**
3978
+ * Indicates the path that must exist in the requested URL for the browser to send the Cookie
3979
+ * header.
3980
+ *
3981
+ * @example
3982
+ * "/docs"
3983
+ * // -> the request paths /docs, /docs/, /docs/Web/, and /docs/Web/HTTP will all match. the request paths /, /fr/docs will not match.
3984
+ */
3985
+ path?: string;
3986
+ /**
3987
+ * Indicates that the cookie is sent to the server only when a request is made with the https:
3988
+ * scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.
3989
+ */
3990
+ secure?: boolean;
3991
+ /**
3992
+ * Controls whether or not a cookie is sent with cross-site requests, providing some protection
3993
+ * against cross-site request forgery attacks (CSRF).
3994
+ *
3995
+ * Strict - Means that the browser sends the cookie only for same-site requests, that is,
3996
+ * requests originating from the same site that set the cookie. If a request originates from a
3997
+ * different domain or scheme (even with the same domain), no cookies with the SameSite=Strict
3998
+ * attribute are sent.
3999
+ *
4000
+ * Lax - Means that the cookie is not sent on cross-site requests, such as on requests to load
4001
+ * images or frames, but is sent when a user is navigating to the origin site from an external
4002
+ * site (for example, when following a link). This is the default behavior if the SameSite
4003
+ * attribute is not specified.
4004
+ *
4005
+ * None - Means that the browser sends the cookie with both cross-site and same-site requests.
4006
+ * The Secure attribute must also be set when setting this value.
4007
+ */
4008
+ sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
4009
+ /**
4010
+ * Indicates that the cookie should be stored using partitioned storage. Note that if this is
4011
+ * set, the Secure directive must also be set.
4012
+ *
4013
+ * @see https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
4014
+ */
4015
+ partitioned?: boolean;
4016
+ /**
4017
+ * Cooke Prefix
4018
+ *
4019
+ * - secure: `__Secure-` -> `__Secure-cookie-name`
4020
+ * - host: `__Host-` -> `__Host-cookie-name`
4021
+ *
4022
+ * `secure` must be set to true to use prefixes
4023
+ */
4024
+ prefix?: CookiePrefixOptions;
4025
+ };
3943
4026
  //#endregion
3944
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/standard-schema.d.mts
4027
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/standard-schema.d.mts
3945
4028
  //#region src/standard-schema.d.ts
3946
4029
  /** The Standard Schema interface. */
3947
4030
  interface StandardSchemaV1$1<Input = unknown, Output = Input> {
@@ -3999,7 +4082,7 @@ declare namespace StandardSchemaV1$1 {
3999
4082
  type InferOutput<Schema extends StandardSchemaV1$1> = NonNullable<Schema["~standard"]["types"]>["output"];
4000
4083
  } //#endregion
4001
4084
  //#endregion
4002
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/error.d.mts
4085
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/error.d.mts
4003
4086
  declare const statusCodes: {
4004
4087
  OK: number;
4005
4088
  CREATED: number;
@@ -4077,341 +4160,284 @@ declare const APIError: new (status?: Status | "OK" | "CREATED" | "ACCEPTED" | "
4077
4160
  errorStack: string | undefined;
4078
4161
  }; //#endregion
4079
4162
  //#endregion
4080
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/cookies.d.mts
4081
- //#region src/cookies.d.ts
4082
- type CookiePrefixOptions = "host" | "secure";
4083
- type CookieOptions = {
4163
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/helper.d.mts
4164
+ type Prettify<T> = 0 extends 1 & T ? any : { [K in keyof T]: T[K] } & {};
4165
+ type IsEmptyObject<T> = keyof T extends never ? true : false;
4166
+ type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
4167
+ type InferParamPath<Path> = Path extends `${infer _Start}:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}:${infer Param}` ? { [K in Param]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamPath<Rest> : {};
4168
+ type InferParamWildCard<Path> = Path extends `${infer _Start}/*:${infer Param}/${infer Rest}` | `${infer _Start}/**:${infer Param}/${infer Rest}` ? { [K in Param | keyof InferParamPath<Rest>]: string } : Path extends `${infer _Start}/*` ? { [K in "_"]: string } : Path extends `${infer _Start}/${infer Rest}` ? InferParamWildCard<Rest> : {}; //#endregion
4169
+ //#endregion
4170
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/middleware.d.mts
4171
+ //#region src/middleware.d.ts
4172
+ type MiddlewareContext<Context = {}> = {
4084
4173
  /**
4085
- * Domain of the cookie
4086
- *
4087
- * The Domain attribute specifies which server can receive a cookie. If specified, cookies are
4088
- * available on the specified server and its subdomains. If the it is not
4089
- * specified, the cookies are available on the server that sets it but not on
4090
- * its subdomains.
4174
+ * Method
4091
4175
  *
4092
- * @example
4093
- * `domain: "example.com"`
4176
+ * The request method
4094
4177
  */
4095
- domain?: string;
4178
+ method: string;
4096
4179
  /**
4097
- * A lifetime of a cookie. Permanent cookies are deleted after the date specified in the
4098
- * Expires attribute:
4180
+ * Path
4099
4181
  *
4100
- * Expires has been available for longer than Max-Age, however Max-Age is less error-prone, and
4101
- * takes precedence when both are set. The rationale behind this is that when you set an
4102
- * Expires date and time, they're relative to the client the cookie is being set on. If the
4103
- * server is set to a different time, this could cause errors
4104
- */
4105
- expires?: Date;
4106
- /**
4107
- * Forbids JavaScript from accessing the cookie, for example, through the Document.cookie
4108
- * property. Note that a cookie that has been created with HttpOnly will still be sent with
4109
- * JavaScript-initiated requests, for example, when calling XMLHttpRequest.send() or fetch().
4110
- * This mitigates attacks against cross-site scripting
4182
+ * The path of the endpoint
4111
4183
  */
4112
- httpOnly?: boolean;
4184
+ path: string;
4113
4185
  /**
4114
- * Indicates the number of seconds until the cookie expires. A zero or negative number will
4115
- * expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.
4186
+ * Body
4116
4187
  *
4117
- * @example 604800 - 7 days
4188
+ * The body object will be the parsed JSON from the request and validated
4189
+ * against the body schema if it exists
4118
4190
  */
4119
- maxAge?: number;
4191
+ body: any;
4120
4192
  /**
4121
- * Indicates the path that must exist in the requested URL for the browser to send the Cookie
4122
- * header.
4193
+ * Query
4123
4194
  *
4124
- * @example
4125
- * "/docs"
4126
- * // -> the request paths /docs, /docs/, /docs/Web/, and /docs/Web/HTTP will all match. the request paths /, /fr/docs will not match.
4127
- */
4128
- path?: string;
4129
- /**
4130
- * Indicates that the cookie is sent to the server only when a request is made with the https:
4131
- * scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.
4195
+ * The query object will be the parsed query string from the request
4196
+ * and validated against the query schema if it exists
4132
4197
  */
4133
- secure?: boolean;
4198
+ query: Record<string, any> | undefined;
4134
4199
  /**
4135
- * Controls whether or not a cookie is sent with cross-site requests, providing some protection
4136
- * against cross-site request forgery attacks (CSRF).
4137
- *
4138
- * Strict - Means that the browser sends the cookie only for same-site requests, that is,
4139
- * requests originating from the same site that set the cookie. If a request originates from a
4140
- * different domain or scheme (even with the same domain), no cookies with the SameSite=Strict
4141
- * attribute are sent.
4142
- *
4143
- * Lax - Means that the cookie is not sent on cross-site requests, such as on requests to load
4144
- * images or frames, but is sent when a user is navigating to the origin site from an external
4145
- * site (for example, when following a link). This is the default behavior if the SameSite
4146
- * attribute is not specified.
4200
+ * Params
4147
4201
  *
4148
- * None - Means that the browser sends the cookie with both cross-site and same-site requests.
4149
- * The Secure attribute must also be set when setting this value.
4202
+ * If the path is `/user/:id` and the request is `/user/1` then the
4203
+ * params will be `{ id: "1" }` and if the path includes a wildcard like
4204
+ * `/user/*` then the params will be `{ _: "1" }` where `_` is the wildcard
4205
+ * key. If the wildcard is named like `/user/**:name` then the params will
4206
+ * be `{ name: string }`
4150
4207
  */
4151
- sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
4208
+ params: Record<string, any> | undefined;
4152
4209
  /**
4153
- * Indicates that the cookie should be stored using partitioned storage. Note that if this is
4154
- * set, the Secure directive must also be set.
4210
+ * Request object
4155
4211
  *
4156
- * @see https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
4212
+ * If `requireRequest` is set to true in the endpoint options this will be
4213
+ * required
4157
4214
  */
4158
- partitioned?: boolean;
4215
+ request: Request | undefined;
4159
4216
  /**
4160
- * Cooke Prefix
4161
- *
4162
- * - secure: `__Secure-` -> `__Secure-cookie-name`
4163
- * - host: `__Host-` -> `__Host-cookie-name`
4217
+ * Headers
4164
4218
  *
4165
- * `secure` must be set to true to use prefixes
4166
- */
4167
- prefix?: CookiePrefixOptions;
4168
- };
4169
- //#endregion
4170
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/openapi.d.mts
4171
- //#region src/openapi.d.ts
4172
- type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
4173
- interface OpenAPIParameter {
4174
- in: "query" | "path" | "header" | "cookie";
4175
- name?: string;
4176
- description?: string;
4177
- required?: boolean;
4178
- schema?: {
4179
- type: OpenAPISchemaType;
4180
- format?: string;
4181
- items?: {
4182
- type: OpenAPISchemaType;
4183
- };
4184
- enum?: string[];
4185
- minLength?: number;
4186
- description?: string;
4187
- default?: string;
4188
- example?: string;
4189
- };
4190
- }
4191
- //#endregion
4192
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/endpoint.d.mts
4193
- //#region src/endpoint.d.ts
4194
- interface EndpointBaseOptions {
4195
- /**
4196
- * Query Schema
4197
- */
4198
- query?: StandardSchemaV1$1;
4199
- /**
4200
- * Error Schema
4201
- */
4202
- error?: StandardSchemaV1$1;
4203
- /**
4204
- * If true headers will be required to be passed in the context
4205
- */
4206
- requireHeaders?: boolean;
4207
- /**
4208
- * If true request object will be required
4209
- */
4210
- requireRequest?: boolean;
4211
- /**
4212
- * Clone the request object from the router
4213
- */
4214
- cloneRequest?: boolean;
4215
- /**
4216
- * If true the body will be undefined
4219
+ * If `requireHeaders` is set to true in the endpoint options this will be
4220
+ * required
4217
4221
  */
4218
- disableBody?: boolean;
4222
+ headers: Headers | undefined;
4219
4223
  /**
4220
- * Endpoint metadata
4224
+ * Set header
4225
+ *
4226
+ * If it's called outside of a request it will just be ignored.
4221
4227
  */
4222
- metadata?: {
4223
- /**
4224
- * Open API definition
4225
- */
4226
- openapi?: {
4227
- summary?: string;
4228
- description?: string;
4229
- tags?: string[];
4230
- operationId?: string;
4231
- parameters?: OpenAPIParameter[];
4232
- requestBody?: {
4233
- content: {
4234
- "application/json": {
4235
- schema: {
4236
- type?: OpenAPISchemaType;
4237
- properties?: Record<string, any>;
4238
- required?: string[];
4239
- $ref?: string;
4240
- };
4241
- };
4242
- };
4243
- };
4244
- responses?: {
4245
- [status: string]: {
4246
- description: string;
4247
- content?: {
4248
- "application/json"?: {
4249
- schema: {
4250
- type?: OpenAPISchemaType;
4251
- properties?: Record<string, any>;
4252
- required?: string[];
4253
- $ref?: string;
4254
- };
4255
- };
4256
- "text/plain"?: {
4257
- schema?: {
4258
- type?: OpenAPISchemaType;
4259
- properties?: Record<string, any>;
4260
- required?: string[];
4261
- $ref?: string;
4262
- };
4263
- };
4264
- "text/html"?: {
4265
- schema?: {
4266
- type?: OpenAPISchemaType;
4267
- properties?: Record<string, any>;
4268
- required?: string[];
4269
- $ref?: string;
4270
- };
4271
- };
4272
- };
4273
- };
4274
- };
4275
- };
4276
- /**
4277
- * Infer body and query type from ts interface
4278
- *
4279
- * useful for generic and dynamic types
4280
- *
4281
- * @example
4282
- * ```ts
4283
- * const endpoint = createEndpoint("/path", {
4284
- * method: "POST",
4285
- * body: z.record(z.string()),
4286
- * $Infer: {
4287
- * body: {} as {
4288
- * type: InferTypeFromOptions<Option> // custom type inference
4289
- * }
4290
- * }
4291
- * }, async(ctx)=>{
4292
- * const body = ctx.body
4293
- * })
4294
- * ```
4295
- */
4296
- $Infer?: {
4297
- /**
4298
- * Body
4299
- */
4300
- body?: any;
4301
- /**
4302
- * Query
4303
- */
4304
- query?: Record<string, any>;
4305
- };
4306
- /**
4307
- * If enabled, endpoint won't be exposed over a router
4308
- * @deprecated Use path-less endpoints instead
4309
- */
4310
- SERVER_ONLY?: boolean;
4311
- /**
4312
- * If enabled, endpoint won't be exposed as an action to the client
4313
- * @deprecated Use path-less endpoints instead
4314
- */
4315
- isAction?: boolean;
4316
- /**
4317
- * Defines the places where the endpoint will be available
4318
- *
4319
- * Possible options:
4320
- * - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
4321
- * - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
4322
- * - `http` - the endpoint is only exposed to the router
4323
- * @default "rpc"
4324
- */
4325
- scope?: "rpc" | "server" | "http";
4326
- /**
4327
- * List of allowed media types (MIME types) for the endpoint
4328
- *
4329
- * if provided, only the media types in the list will be allowed to be passed in the body
4330
- *
4331
- * @example
4332
- * ```ts
4333
- * const endpoint = createEndpoint("/path", {
4334
- * method: "POST",
4335
- * allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
4336
- * }, async(ctx)=>{
4337
- * const body = ctx.body
4338
- * })
4339
- * ```
4340
- */
4341
- allowedMediaTypes?: string[];
4342
- /**
4343
- * Extra metadata
4344
- */
4345
- [key: string]: any;
4346
- };
4228
+ setHeader: (key: string, value: string) => void;
4347
4229
  /**
4348
- * List of middlewares to use
4230
+ * Set the response status code
4349
4231
  */
4350
- use?: Middleware[];
4232
+ setStatus: (status: Status) => void;
4351
4233
  /**
4352
- * A callback to run before any API error is throw or returned
4234
+ * Get header
4353
4235
  *
4354
- * @param e - The API error
4355
- * @returns - The response to return
4356
- */
4357
- onAPIError?: (e: APIError) => void | Promise<void>;
4358
- /**
4359
- * A callback to run before a validation error is thrown
4360
- * You can customize the validation error message by throwing your own APIError
4236
+ * If it's called outside of a request it will just return null
4237
+ *
4238
+ * @param key - The key of the header
4361
4239
  */
4362
- onValidationError?: ({
4363
- issues,
4364
- message
4365
- }: {
4366
- message: string;
4367
- issues: readonly StandardSchemaV1$1.Issue[];
4368
- }) => void | Promise<void>;
4369
- }
4370
- type EndpointBodyMethodOptions = {
4240
+ getHeader: (key: string) => string | null;
4371
4241
  /**
4372
- * Request Method
4242
+ * Get a cookie value from the request
4243
+ *
4244
+ * @param key - The key of the cookie
4245
+ * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
4246
+ * @returns The value of the cookie
4373
4247
  */
4374
- method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
4248
+ getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
4375
4249
  /**
4376
- * Body Schema
4250
+ * Get a signed cookie value from the request
4251
+ *
4252
+ * @param key - The key of the cookie
4253
+ * @param secret - The secret of the signed cookie
4254
+ * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
4255
+ * @returns The value of the cookie or null if the cookie is not found or false if the signature is invalid
4377
4256
  */
4378
- body?: StandardSchemaV1$1;
4379
- } | {
4257
+ getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | null | false>;
4380
4258
  /**
4381
- * Request Method
4259
+ * Set a cookie value in the response
4260
+ *
4261
+ * @param key - The key of the cookie
4262
+ * @param value - The value to set
4263
+ * @param options - The options of the cookie
4264
+ * @returns The cookie string
4382
4265
  */
4383
- method: "GET" | "HEAD" | ("GET" | "HEAD")[];
4266
+ setCookie: (key: string, value: string, options?: CookieOptions) => string;
4384
4267
  /**
4385
- * Body Schema
4268
+ * Set signed cookie
4269
+ *
4270
+ * @param key - The key of the cookie
4271
+ * @param value - The value to set
4272
+ * @param secret - The secret to sign the cookie with
4273
+ * @param options - The options of the cookie
4274
+ * @returns The cookie string
4386
4275
  */
4387
- body?: never;
4388
- } | {
4276
+ setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
4389
4277
  /**
4390
- * Request Method
4278
+ * JSON
4279
+ *
4280
+ * A helper function to create a JSON response with the correct headers
4281
+ * and status code. If `asResponse` is set to true in the context then
4282
+ * it will return a Response object instead of the JSON object.
4283
+ *
4284
+ * @param json - The JSON object to return
4285
+ * @param routerResponse - The response object to return if `asResponse` is
4286
+ * true in the context this will take precedence
4391
4287
  */
4392
- method: "*";
4288
+ json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
4289
+ status?: number;
4290
+ headers?: Record<string, string>;
4291
+ response?: Response;
4292
+ body?: Record<string, any>;
4293
+ } | Response) => R;
4393
4294
  /**
4394
- * Body Schema
4295
+ * Middleware context
4395
4296
  */
4396
- body?: StandardSchemaV1$1;
4397
- } | {
4297
+ context: Prettify<Context>;
4398
4298
  /**
4399
- * Request Method
4299
+ * Redirect to a new URL
4400
4300
  */
4401
- method: ("POST" | "PUT" | "DELETE" | "PATCH" | "GET" | "HEAD")[];
4301
+ redirect: (url: string) => APIError;
4402
4302
  /**
4403
- * Body Schema
4303
+ * Return error
4404
4304
  */
4405
- body?: StandardSchemaV1$1;
4305
+ error: (status: keyof typeof statusCodes | Status, body?: {
4306
+ message?: string;
4307
+ code?: string;
4308
+ } & Record<string, any>, headers?: HeadersInit) => APIError;
4309
+ asResponse?: boolean;
4310
+ returnHeaders?: boolean;
4311
+ returnStatus?: boolean;
4312
+ responseHeaders: Headers;
4313
+ };
4314
+ type DefaultHandler = (inputCtx: MiddlewareContext<any>) => Promise<any>;
4315
+ type Middleware<Handler extends (inputCtx: MiddlewareContext<any>) => Promise<any> = DefaultHandler> = Handler & {
4316
+ options: Record<string, any>;
4406
4317
  };
4407
- type EndpointOptions = EndpointBaseOptions & EndpointBodyMethodOptions;
4408
- type EndpointContext<Path extends string, Options extends EndpointOptions, Context = {}> = {
4318
+ //#endregion
4319
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/types.d.mts
4320
+ //#region src/types.d.ts
4321
+ type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
4322
+ /**
4323
+ * Resolves a method type parameter to its effective runtime type.
4324
+ */
4325
+ type ResolveMethod<M> = M extends Array<infer U> ? U : M extends "*" ? HTTPMethod : M;
4326
+ /**
4327
+ * Resolve a $Infer value: if it's a StandardSchemaV1 schema, extract the
4328
+ * output type; otherwise use as-is.
4329
+ */
4330
+ type ResolveInferValue<T> = T extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferOutput<T> : T;
4331
+ /**
4332
+ * Resolves a body schema to its output type.
4333
+ */
4334
+ type ResolveBody<S, Meta = undefined> = Meta extends {
4335
+ $Infer: {
4336
+ body: infer B;
4337
+ };
4338
+ } ? ResolveInferValue<B> : S extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferOutput<S> : any;
4339
+ /**
4340
+ * Resolves a query schema to its output type.
4341
+ */
4342
+ type ResolveQuery<S, Meta = undefined> = Meta extends {
4343
+ $Infer: {
4344
+ query: infer Q;
4345
+ };
4346
+ } ? ResolveInferValue<Q> : S extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferOutput<S> : Record<string, any> | undefined;
4347
+ /**
4348
+ * Resolves body schema to its input type (for InputContext at call-site).
4349
+ */
4350
+ /**
4351
+ * Infer param types from a path string.
4352
+ */
4353
+ type InferParam<Path extends string> = [Path] extends [never] ? Record<string, any> | undefined : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? Record<string, any> | undefined : Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
4354
+ /**
4355
+ * Infer param input (required vs optional based on whether path has params).
4356
+ */
4357
+ type InferParamInput<Path extends string> = [Path] extends [never] ? {
4358
+ params?: Record<string, any>;
4359
+ } : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? {
4360
+ params?: Record<string, any>;
4361
+ } : {
4362
+ params: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
4363
+ };
4364
+ /**
4365
+ * Infer body input from an already-resolved body type.
4366
+ * Body is the plain resolved type (not a schema).
4367
+ */
4368
+ type InferBodyInput<Body> = undefined extends Body ? {
4369
+ body?: Body;
4370
+ } : {
4371
+ body: Body;
4372
+ };
4373
+ /**
4374
+ * Infer query input from an already-resolved query type.
4375
+ * Query is the plain resolved type (not a schema).
4376
+ */
4377
+ type InferQueryInput<Query> = undefined extends Query ? {
4378
+ query?: Query;
4379
+ } : {
4380
+ query: Query;
4381
+ };
4382
+ /**
4383
+ * Infer method input: required for wildcard, optional for arrays and single methods.
4384
+ */
4385
+ type InferMethodInput<M> = 0 extends 1 & M ? {
4386
+ method?: HTTPMethod | undefined;
4387
+ } : M extends "*" ? {
4388
+ method: HTTPMethod;
4389
+ } : M extends Array<any> ? {
4390
+ method?: M[number] | undefined;
4391
+ } : {
4392
+ method?: M | undefined;
4393
+ };
4394
+ /**
4395
+ * Infer request input.
4396
+ */
4397
+ type InferRequestInput<ReqRequest extends boolean> = 0 extends 1 & ReqRequest ? {
4398
+ request?: Request;
4399
+ } : ReqRequest extends true ? {
4400
+ request: Request;
4401
+ } : {
4402
+ request?: Request;
4403
+ };
4404
+ /**
4405
+ * Infer headers input.
4406
+ */
4407
+ type InferHeadersInput<ReqHeaders extends boolean> = 0 extends 1 & ReqHeaders ? {
4408
+ headers?: HeadersInit;
4409
+ } : ReqHeaders extends true ? {
4410
+ headers: HeadersInit;
4411
+ } : {
4412
+ headers?: HeadersInit;
4413
+ };
4414
+ /**
4415
+ * Infer the use (middleware) context union.
4416
+ * Guards against `any` and `[]` to avoid poisoning the Context type.
4417
+ */
4418
+ type InferUse<Opts extends Middleware[] | undefined> = 0 extends 1 & Opts ? any : Opts extends Middleware[] ? Opts extends [] ? {} : UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
4419
+ /**
4420
+ * The full InputContext type for the Endpoint call signature.
4421
+ * Body and Query are already-resolved plain types.
4422
+ */
4423
+ type InputContext<Path extends string, M, Body, Query, ReqHeaders extends boolean, ReqRequest extends boolean> = InferBodyInput<Body> & InferMethodInput<M> & InferQueryInput<Query> & InferParamInput<Path> & InferRequestInput<ReqRequest> & InferHeadersInput<ReqHeaders> & {
4424
+ asResponse?: boolean;
4425
+ returnHeaders?: boolean;
4426
+ returnStatus?: boolean;
4427
+ use?: Middleware[];
4428
+ path?: string;
4429
+ context?: Record<string, any>;
4430
+ }; //#endregion
4431
+ //#endregion
4432
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/context.d.mts
4433
+ //#region src/context.d.ts
4434
+ type EndpointContext<Path extends string, M, BodySchema extends object | undefined, QuerySchema extends object | undefined, Use extends Middleware[], ReqHeaders extends boolean, ReqRequest extends boolean, Context = {}, Meta = undefined> = {
4409
4435
  /**
4410
4436
  * Method
4411
4437
  *
4412
4438
  * The request method
4413
4439
  */
4414
- method: InferMethod<Options>;
4440
+ method: ResolveMethod<M>;
4415
4441
  /**
4416
4442
  * Path
4417
4443
  *
@@ -4424,14 +4450,14 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4424
4450
  * The body object will be the parsed JSON from the request and validated
4425
4451
  * against the body schema if it exists.
4426
4452
  */
4427
- body: InferBody<Options>;
4453
+ body: ResolveBody<BodySchema, Meta>;
4428
4454
  /**
4429
4455
  * Query
4430
4456
  *
4431
4457
  * The query object will be the parsed query string from the request
4432
4458
  * and validated against the query schema if it exists
4433
4459
  */
4434
- query: InferQuery<Options>;
4460
+ query: ResolveQuery<QuerySchema, Meta>;
4435
4461
  /**
4436
4462
  * Params
4437
4463
  *
@@ -4447,14 +4473,14 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4447
4473
  * If `requireRequest` is set to true in the endpoint options this will be
4448
4474
  * required
4449
4475
  */
4450
- request: InferRequest<Options>;
4476
+ request: ReqRequest extends true ? Request : Request | undefined;
4451
4477
  /**
4452
4478
  * Headers
4453
4479
  *
4454
4480
  * If `requireHeaders` is set to true in the endpoint options this will be
4455
4481
  * required
4456
4482
  */
4457
- headers: InferHeaders<Options>;
4483
+ headers: ReqHeaders extends true ? Headers : Headers | undefined;
4458
4484
  /**
4459
4485
  * Set header
4460
4486
  *
@@ -4470,8 +4496,7 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4470
4496
  *
4471
4497
  * If it's called outside of a request it will just return null
4472
4498
  *
4473
- * @param key - The key of the header
4474
- * @returns
4499
+ * @param key - The key of the header
4475
4500
  */
4476
4501
  getHeader: (key: string) => string | null;
4477
4502
  /**
@@ -4479,7 +4504,7 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4479
4504
  *
4480
4505
  * @param key - The key of the cookie
4481
4506
  * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
4482
- * @returns - The value of the cookie
4507
+ * @returns The value of the cookie
4483
4508
  */
4484
4509
  getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
4485
4510
  /**
@@ -4488,7 +4513,7 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4488
4513
  * @param key - The key of the cookie
4489
4514
  * @param secret - The secret of the signed cookie
4490
4515
  * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
4491
- * @returns - The value of the cookie or null if the cookie is not found or false if the signature is invalid
4516
+ * @returns The value of the cookie or null if the cookie is not found or false if the signature is invalid
4492
4517
  */
4493
4518
  getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | null | false>;
4494
4519
  /**
@@ -4497,44 +4522,40 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4497
4522
  * @param key - The key of the cookie
4498
4523
  * @param value - The value to set
4499
4524
  * @param options - The options of the cookie
4500
- * @returns - The cookie string
4525
+ * @returns The cookie string
4501
4526
  */
4502
4527
  setCookie: (key: string, value: string, options?: CookieOptions) => string;
4503
4528
  /**
4504
4529
  * Set signed cookie
4505
4530
  *
4506
4531
  * @param key - The key of the cookie
4507
- * @param value - The value to set
4532
+ * @param value - The value to set
4508
4533
  * @param secret - The secret to sign the cookie with
4509
4534
  * @param options - The options of the cookie
4510
- * @returns - The cookie string
4535
+ * @returns The cookie string
4511
4536
  */
4512
4537
  setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
4513
4538
  /**
4514
4539
  * JSON
4515
4540
  *
4516
- * a helper function to create a JSON response with
4517
- * the correct headers
4518
- * and status code. If `asResponse` is set to true in
4519
- * the context then
4520
- * it will return a Response object instead of the
4521
- * JSON object.
4541
+ * A helper function to create a JSON response with the correct headers
4542
+ * and status code. If `asResponse` is set to true in the context then
4543
+ * it will return a Response object instead of the JSON object.
4522
4544
  *
4523
4545
  * @param json - The JSON object to return
4524
- * @param routerResponse - The response object to
4525
- * return if `asResponse` is
4546
+ * @param routerResponse - The response object to return if `asResponse` is
4526
4547
  * true in the context this will take precedence
4527
4548
  */
4528
4549
  json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
4529
4550
  status?: number;
4530
4551
  headers?: Record<string, string>;
4531
4552
  response?: Response;
4532
- body?: Record<string, string>;
4533
- } | Response) => Promise<R>;
4553
+ body?: Record<string, any>;
4554
+ } | Response) => R;
4534
4555
  /**
4535
4556
  * Middleware context
4536
4557
  */
4537
- context: Prettify<Context & InferUse<Options["use"]>>;
4558
+ context: 0 extends 1 & Use ? Prettify<Context> : Prettify<Context & InferUse<Use>>;
4538
4559
  /**
4539
4560
  * Redirect to a new URL
4540
4561
  */
@@ -4546,188 +4567,242 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4546
4567
  message?: string;
4547
4568
  code?: string;
4548
4569
  } & Record<string, any>, headers?: HeadersInit) => APIError;
4549
- };
4550
- type Endpoint<Path extends string = string, Options extends EndpointOptions = EndpointOptions, Handler extends (inputCtx: any) => Promise<any> = (inputCtx: any) => Promise<any>> = Handler & {
4551
- options: Options;
4552
- path: Path;
4553
4570
  }; //#endregion
4554
4571
  //#endregion
4555
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/middleware.d.mts
4556
- //#region src/middleware.d.ts
4557
- interface MiddlewareOptions extends Omit<EndpointOptions, "method"> {}
4558
- type MiddlewareContext<Options extends MiddlewareOptions, Context = {}> = EndpointContext<string, Options & {
4559
- method: "*";
4560
- }> & {
4572
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/endpoint.d.mts
4573
+ //#region src/endpoint.d.ts
4574
+ interface EndpointMetadata {
4575
+ /**
4576
+ * Open API definition
4577
+ */
4578
+ openapi?: {
4579
+ summary?: string;
4580
+ description?: string;
4581
+ tags?: string[];
4582
+ operationId?: string;
4583
+ parameters?: OpenAPIParameter[];
4584
+ requestBody?: {
4585
+ content: {
4586
+ "application/json": {
4587
+ schema: {
4588
+ type?: OpenAPISchemaType;
4589
+ properties?: Record<string, any>;
4590
+ required?: string[];
4591
+ $ref?: string;
4592
+ };
4593
+ };
4594
+ };
4595
+ };
4596
+ responses?: {
4597
+ [status: string]: {
4598
+ description: string;
4599
+ content?: {
4600
+ "application/json"?: {
4601
+ schema: {
4602
+ type?: OpenAPISchemaType;
4603
+ properties?: Record<string, any>;
4604
+ required?: string[];
4605
+ $ref?: string;
4606
+ };
4607
+ };
4608
+ "text/plain"?: {
4609
+ schema?: {
4610
+ type?: OpenAPISchemaType;
4611
+ properties?: Record<string, any>;
4612
+ required?: string[];
4613
+ $ref?: string;
4614
+ };
4615
+ };
4616
+ "text/html"?: {
4617
+ schema?: {
4618
+ type?: OpenAPISchemaType;
4619
+ properties?: Record<string, any>;
4620
+ required?: string[];
4621
+ $ref?: string;
4622
+ };
4623
+ };
4624
+ };
4625
+ };
4626
+ };
4627
+ };
4628
+ /**
4629
+ * Infer body and query type from ts interface
4630
+ *
4631
+ * useful for generic and dynamic types
4632
+ *
4633
+ * @example
4634
+ * ```ts
4635
+ * const endpoint = createEndpoint("/path", {
4636
+ * method: "POST",
4637
+ * body: z.record(z.string()),
4638
+ * $Infer: {
4639
+ * body: {} as {
4640
+ * type: InferTypeFromOptions<Option> // custom type inference
4641
+ * }
4642
+ * }
4643
+ * }, async(ctx)=>{
4644
+ * const body = ctx.body
4645
+ * })
4646
+ * ```
4647
+ */
4648
+ $Infer?: {
4649
+ /**
4650
+ * Body
4651
+ */
4652
+ body?: any;
4653
+ /**
4654
+ * Query
4655
+ */
4656
+ query?: Record<string, any>;
4657
+ /**
4658
+ * Error
4659
+ */
4660
+ error?: any;
4661
+ };
4561
4662
  /**
4562
- * Method
4563
- *
4564
- * The request method
4663
+ * If enabled, endpoint won't be exposed over a router
4664
+ * @deprecated Use path-less endpoints instead
4565
4665
  */
4566
- method: string;
4666
+ SERVER_ONLY?: boolean;
4567
4667
  /**
4568
- * Path
4569
- *
4570
- * The path of the endpoint
4668
+ * If enabled, endpoint won't be exposed as an action to the client
4669
+ * @deprecated Use path-less endpoints instead
4571
4670
  */
4572
- path: string;
4671
+ isAction?: boolean;
4573
4672
  /**
4574
- * Body
4673
+ * Defines the places where the endpoint will be available
4575
4674
  *
4576
- * The body object will be the parsed JSON from the request and validated
4577
- * against the body schema if it exists
4675
+ * Possible options:
4676
+ * - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
4677
+ * - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
4678
+ * - `http` - the endpoint is only exposed to the router
4679
+ * @default "rpc"
4578
4680
  */
4579
- body: InferMiddlewareBody<Options>;
4681
+ scope?: "rpc" | "server" | "http";
4580
4682
  /**
4581
- * Query
4683
+ * List of allowed media types (MIME types) for the endpoint
4582
4684
  *
4583
- * The query object will be the parsed query string from the request
4584
- * and validated against the query schema if it exists
4685
+ * if provided, only the media types in the list will be allowed to be passed in the body
4686
+ *
4687
+ * @example
4688
+ * ```ts
4689
+ * const endpoint = createEndpoint("/path", {
4690
+ * method: "POST",
4691
+ * allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
4692
+ * }, async(ctx)=>{
4693
+ * const body = ctx.body
4694
+ * })
4695
+ * ```
4585
4696
  */
4586
- query: InferMiddlewareQuery<Options>;
4697
+ allowedMediaTypes?: string[];
4587
4698
  /**
4588
- * Params
4589
- *
4590
- * If the path is `/user/:id` and the request is `/user/1` then the
4591
- * params will
4592
- * be `{ id: "1" }` and if the path includes a wildcard like `/user/*`
4593
- * then the
4594
- * params will be `{ _: "1" }` where `_` is the wildcard key. If the
4595
- * wildcard
4596
- * is named like `/user/**:name` then the params will be `{ name: string }`
4699
+ * Extra metadata
4597
4700
  */
4598
- params: string;
4701
+ [key: string]: any;
4702
+ }
4703
+ interface EndpointRuntimeOptions {
4704
+ method: string | string[];
4705
+ body?: StandardSchemaV1$1;
4599
4706
  /**
4600
- * Request object
4601
- *
4602
- * If `requireRequest` is set to true in the endpoint options this will be
4603
- * required
4707
+ * Query Schema
4604
4708
  */
4605
- request: InferRequest<Options>;
4709
+ query?: StandardSchemaV1$1;
4606
4710
  /**
4607
- * Headers
4608
- *
4609
- * If `requireHeaders` is set to true in the endpoint options this will be
4610
- * required
4711
+ * Error Schema
4611
4712
  */
4612
- headers: InferHeaders<Options>;
4713
+ error?: StandardSchemaV1$1;
4613
4714
  /**
4614
- * Set header
4615
- *
4616
- * If it's called outside of a request it will just be ignored.
4715
+ * If true headers will be required to be passed in the context
4617
4716
  */
4618
- setHeader: (key: string, value: string) => void;
4717
+ requireHeaders?: boolean;
4619
4718
  /**
4620
- * Get header
4621
- *
4622
- * If it's called outside of a request it will just return null
4623
- *
4624
- * @param key - The key of the header
4625
- * @returns
4719
+ * If true request object will be required
4626
4720
  */
4627
- getHeader: (key: string) => string | null;
4721
+ requireRequest?: boolean;
4628
4722
  /**
4629
- * JSON
4630
- *
4631
- * a helper function to create a JSON response with
4632
- * the correct headers
4633
- * and status code. If `asResponse` is set to true in
4634
- * the context then
4635
- * it will return a Response object instead of the
4636
- * JSON object.
4637
- *
4638
- * @param json - The JSON object to return
4639
- * @param routerResponse - The response object to
4640
- * return if `asResponse` is
4641
- * true in the context this will take precedence
4723
+ * Clone the request object from the router
4642
4724
  */
4643
- json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
4644
- status?: number;
4645
- headers?: Record<string, string>;
4646
- response?: Response;
4647
- } | Response) => Promise<R>;
4725
+ cloneRequest?: boolean;
4648
4726
  /**
4649
- * Middleware context
4727
+ * If true the body will be undefined
4728
+ */
4729
+ disableBody?: boolean;
4730
+ /**
4731
+ * Endpoint metadata
4732
+ */
4733
+ metadata?: EndpointMetadata;
4734
+ /**
4735
+ * List of middlewares to use
4650
4736
  */
4651
- context: Prettify<Context>;
4652
- };
4653
- type MiddlewareInputContext<Options extends MiddlewareOptions> = InferBodyInput<Options> & InferQueryInput<Options> & InferRequestInput<Options> & InferHeadersInput<Options> & {
4654
- asResponse?: boolean;
4655
- returnHeaders?: boolean;
4656
4737
  use?: Middleware[];
4657
- };
4658
- type Middleware<Options extends MiddlewareOptions = MiddlewareOptions, Handler extends (inputCtx: any) => Promise<any> = any> = Handler & {
4659
- options: Options;
4660
- }; //#endregion
4661
- //#endregion
4662
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/context.d.mts
4663
- //#region src/context.d.ts
4664
- type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
4665
- type Method = HTTPMethod | "*";
4666
- type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions, Body = (Options["metadata"] extends {
4667
- $Infer: {
4668
- body: infer B;
4669
- };
4670
- } ? B : Options["body"] extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferInput<Options["body"]> : undefined)> = undefined extends Body ? {
4671
- body?: Body;
4672
- } : {
4673
- body: Body;
4674
- };
4675
- type InferBody<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
4676
- $Infer: {
4677
- body: infer Body;
4678
- };
4679
- } ? Body : Options["body"] extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferOutput<Options["body"]> : any;
4680
- type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions, Query = (Options["metadata"] extends {
4681
- $Infer: {
4682
- query: infer Query;
4738
+ /**
4739
+ * A callback to run before any API error is thrown or returned
4740
+ *
4741
+ * @param e - The API error
4742
+ */
4743
+ onAPIError?: (e: APIError) => void | Promise<void>;
4744
+ /**
4745
+ * A callback to run before a validation error is thrown.
4746
+ * You can customize the validation error message by throwing your own APIError.
4747
+ */
4748
+ onValidationError?: (info: {
4749
+ message: string;
4750
+ issues: readonly StandardSchemaV1$1.Issue[];
4751
+ }) => void | Promise<void>;
4752
+ }
4753
+ type Endpoint<Path extends string = string, Method = any, Body = any, Query = any, Use extends Middleware[] = any, R = any, Meta extends EndpointMetadata | undefined = EndpointMetadata | undefined, Error = any> = {
4754
+ (context: InputContext<Path, Method, Body, Query, false, false> & {
4755
+ asResponse: true;
4756
+ }): Promise<Response>;
4757
+ (context: InputContext<Path, Method, Body, Query, false, false> & {
4758
+ returnHeaders: true;
4759
+ returnStatus: true;
4760
+ }): Promise<{
4761
+ headers: Headers;
4762
+ status: number;
4763
+ response: Awaited<R>;
4764
+ }>;
4765
+ (context: InputContext<Path, Method, Body, Query, false, false> & {
4766
+ returnHeaders: true;
4767
+ }): Promise<{
4768
+ headers: Headers;
4769
+ response: Awaited<R>;
4770
+ }>;
4771
+ (context: InputContext<Path, Method, Body, Query, false, false> & {
4772
+ returnStatus: true;
4773
+ }): Promise<{
4774
+ status: number;
4775
+ response: Awaited<R>;
4776
+ }>;
4777
+ (context?: InputContext<Path, Method, Body, Query, false, false>): Promise<Awaited<R>>;
4778
+ options: Omit<EndpointRuntimeOptions, "method" | "metadata"> & {
4779
+ method: Method;
4780
+ metadata?: Meta;
4683
4781
  };
4684
- } ? Query : Options["query"] extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferInput<Options["query"]> : Record<string, any> | undefined)> = undefined extends Query ? {
4685
- query?: Query;
4686
- } : {
4687
- query: Query;
4782
+ path: Path;
4688
4783
  };
4689
- type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
4690
- $Infer: {
4691
- query: infer Query;
4784
+ //#endregion
4785
+ //#region ../../node_modules/.pnpm/better-call@2.0.2_zod@4.3.6/node_modules/better-call/dist/openapi.d.mts
4786
+ //#region src/openapi.d.ts
4787
+ type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
4788
+ interface OpenAPIParameter {
4789
+ in: "query" | "path" | "header" | "cookie";
4790
+ name?: string;
4791
+ description?: string;
4792
+ required?: boolean;
4793
+ schema?: {
4794
+ type: OpenAPISchemaType;
4795
+ format?: string;
4796
+ items?: {
4797
+ type: OpenAPISchemaType;
4798
+ };
4799
+ enum?: string[];
4800
+ minLength?: number;
4801
+ description?: string;
4802
+ default?: string;
4803
+ example?: string;
4692
4804
  };
4693
- } ? Query : Options["query"] extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferOutput<Options["query"]> : Record<string, any> | undefined;
4694
- type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"];
4695
- type InferInputMethod<Options extends EndpointOptions, Method = (Options["method"] extends Array<any> ? Options["method"][number] | undefined : Options["method"] extends "*" ? HTTPMethod : Options["method"] | undefined)> = undefined extends Method ? {
4696
- method?: Method;
4697
- } : {
4698
- method: Method;
4699
- };
4700
- type InferParam<Path extends string> = [Path] extends [never] ? Record<string, any> | undefined : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? Record<string, any> | undefined : Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
4701
- type InferParamInput<Path extends string> = [Path] extends [never] ? {
4702
- params?: Record<string, any>;
4703
- } : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? {
4704
- params?: Record<string, any>;
4705
- } : {
4706
- params: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
4707
- };
4708
- type InferRequest<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? Request : Request | undefined;
4709
- type InferRequestInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? {
4710
- request: Request;
4711
- } : {
4712
- request?: Request;
4713
- };
4714
- type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
4715
- type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? {
4716
- headers: HeadersInit;
4717
- } : {
4718
- headers?: HeadersInit;
4719
- };
4720
- type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Middleware[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
4721
- type InferMiddlewareBody<Options extends MiddlewareOptions> = Options["body"] extends StandardSchemaV1$1<infer T> ? T : any;
4722
- type InferMiddlewareQuery<Options extends MiddlewareOptions> = Options["query"] extends StandardSchemaV1$1<infer T> ? T : Record<string, any> | undefined;
4723
- type InputContext<Path extends string, Options extends EndpointOptions> = InferBodyInput<Options> & InferInputMethod<Options> & InferQueryInput<Options> & InferParamInput<Path> & InferRequestInput<Options> & InferHeadersInput<Options> & {
4724
- asResponse?: boolean;
4725
- returnHeaders?: boolean;
4726
- returnStatus?: boolean;
4727
- use?: Middleware[];
4728
- path?: string;
4729
- context?: Record<string, any>;
4730
- };
4805
+ }
4731
4806
  //#endregion
4732
4807
  //#region ../core/dist/types/cookie.d.mts
4733
4808
  //#region src/types/cookie.d.ts
@@ -4790,9 +4865,7 @@ type InferPluginOptions<O extends BetterAuthOptions, ID extends BetterAuthPlugin
4790
4865
  */
4791
4866
  interface BetterAuthPluginRegistry<AuthOptions, Options> {}
4792
4867
  type BetterAuthPluginRegistryIdentifier = keyof BetterAuthPluginRegistry<unknown, unknown>;
4793
- type GenericEndpointContext<Options extends BetterAuthOptions = BetterAuthOptions> = EndpointContext<string, any> & {
4794
- context: AuthContext<Options>;
4795
- };
4868
+ type GenericEndpointContext<Options extends BetterAuthOptions = BetterAuthOptions> = EndpointContext<string, any, any, any, any, any, any, AuthContext<Options>>;
4796
4869
  interface InternalAdapter<_Options extends BetterAuthOptions = BetterAuthOptions> {
4797
4870
  createOAuthUser(user: Omit<User, "id" | "createdAt" | "updatedAt">, account: Omit<Account, "userId" | "id" | "createdAt" | "updatedAt"> & Partial<Account>): Promise<{
4798
4871
  user: User;
@@ -5015,267 +5088,13 @@ type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> = Plugin
5015
5088
  }; //#endregion
5016
5089
  //#endregion
5017
5090
  //#region ../core/dist/api/index.d.mts
5018
- declare const createAuthMiddleware: {
5019
- <Options extends MiddlewareOptions, R>(options: Options, handler: (ctx: MiddlewareContext<Options, {
5020
- returned?: unknown | undefined;
5021
- responseHeaders?: Headers | undefined;
5022
- } & PluginContext<BetterAuthOptions> & InfoContext & {
5023
- options: BetterAuthOptions;
5024
- trustedOrigins: string[];
5025
- trustedProviders: string[];
5026
- isTrustedOrigin: (url: string, settings?: {
5027
- allowRelativePaths: boolean;
5028
- }) => boolean;
5029
- oauthConfig: {
5030
- skipStateCookieCheck?: boolean | undefined;
5031
- storeStateStrategy: "database" | "cookie";
5032
- };
5033
- newSession: {
5034
- session: {
5035
- id: string;
5036
- createdAt: Date;
5037
- updatedAt: Date;
5038
- userId: string;
5039
- expiresAt: Date;
5040
- token: string;
5041
- ipAddress?: string | null | undefined;
5042
- userAgent?: string | null | undefined;
5043
- } & Record<string, any>;
5044
- user: {
5045
- id: string;
5046
- createdAt: Date;
5047
- updatedAt: Date;
5048
- email: string;
5049
- emailVerified: boolean;
5050
- name: string;
5051
- image?: string | null | undefined;
5052
- } & Record<string, any>;
5053
- } | null;
5054
- session: {
5055
- session: {
5056
- id: string;
5057
- createdAt: Date;
5058
- updatedAt: Date;
5059
- userId: string;
5060
- expiresAt: Date;
5061
- token: string;
5062
- ipAddress?: string | null | undefined;
5063
- userAgent?: string | null | undefined;
5064
- } & Record<string, any>;
5065
- user: {
5066
- id: string;
5067
- createdAt: Date;
5068
- updatedAt: Date;
5069
- email: string;
5070
- emailVerified: boolean;
5071
- name: string;
5072
- image?: string | null | undefined;
5073
- } & Record<string, any>;
5074
- } | null;
5075
- setNewSession: (session: {
5076
- session: {
5077
- id: string;
5078
- createdAt: Date;
5079
- updatedAt: Date;
5080
- userId: string;
5081
- expiresAt: Date;
5082
- token: string;
5083
- ipAddress?: string | null | undefined;
5084
- userAgent?: string | null | undefined;
5085
- } & Record<string, any>;
5086
- user: {
5087
- id: string;
5088
- createdAt: Date;
5089
- updatedAt: Date;
5090
- email: string;
5091
- emailVerified: boolean;
5092
- name: string;
5093
- image?: string | null | undefined;
5094
- } & Record<string, any>;
5095
- } | null) => void;
5096
- socialProviders: OAuthProvider[];
5097
- authCookies: BetterAuthCookies;
5098
- logger: ReturnType<typeof createLogger>;
5099
- rateLimit: {
5100
- enabled: boolean;
5101
- window: number;
5102
- max: number;
5103
- storage: "memory" | "database" | "secondary-storage";
5104
- } & Omit<BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
5105
- adapter: DBAdapter<BetterAuthOptions>;
5106
- internalAdapter: InternalAdapter<BetterAuthOptions>;
5107
- createAuthCookie: (cookieName: string, overrideAttributes?: Partial<CookieOptions> | undefined) => BetterAuthCookie;
5108
- secret: string;
5109
- secretConfig: string | SecretConfig;
5110
- sessionConfig: {
5111
- updateAge: number;
5112
- expiresIn: number;
5113
- freshAge: number;
5114
- cookieRefreshCache: false | {
5115
- enabled: true;
5116
- updateAge: number;
5117
- };
5118
- };
5119
- generateId: (options: {
5120
- model: ModelNames;
5121
- size?: number | undefined;
5122
- }) => string | false;
5123
- secondaryStorage: SecondaryStorage | undefined;
5124
- password: {
5125
- hash: (password: string) => Promise<string>;
5126
- verify: (data: {
5127
- password: string;
5128
- hash: string;
5129
- }) => Promise<boolean>;
5130
- config: {
5131
- minPasswordLength: number;
5132
- maxPasswordLength: number;
5133
- };
5134
- checkPassword: (userId: string, ctx: GenericEndpointContext<BetterAuthOptions>) => Promise<boolean>;
5135
- };
5136
- tables: BetterAuthDBSchema;
5137
- runMigrations: () => Promise<void>;
5138
- publishTelemetry: (event: {
5139
- type: string;
5140
- anonymousId?: string | undefined;
5141
- payload: Record<string, any>;
5142
- }) => Promise<void>;
5143
- skipOriginCheck: boolean | string[];
5144
- skipCSRFCheck: boolean;
5145
- runInBackground: (promise: Promise<unknown>) => void;
5146
- runInBackgroundOrAwait: (promise: Promise<unknown> | void) => Awaitable<unknown>;
5147
- }>) => Promise<R>): (inputContext: MiddlewareInputContext<Options>) => Promise<R>;
5148
- <Options extends MiddlewareOptions, R_1>(handler: (ctx: MiddlewareContext<Options, {
5149
- returned?: unknown | undefined;
5150
- responseHeaders?: Headers | undefined;
5151
- } & PluginContext<BetterAuthOptions> & InfoContext & {
5152
- options: BetterAuthOptions;
5153
- trustedOrigins: string[];
5154
- trustedProviders: string[];
5155
- isTrustedOrigin: (url: string, settings?: {
5156
- allowRelativePaths: boolean;
5157
- }) => boolean;
5158
- oauthConfig: {
5159
- skipStateCookieCheck?: boolean | undefined;
5160
- storeStateStrategy: "database" | "cookie";
5161
- };
5162
- newSession: {
5163
- session: {
5164
- id: string;
5165
- createdAt: Date;
5166
- updatedAt: Date;
5167
- userId: string;
5168
- expiresAt: Date;
5169
- token: string;
5170
- ipAddress?: string | null | undefined;
5171
- userAgent?: string | null | undefined;
5172
- } & Record<string, any>;
5173
- user: {
5174
- id: string;
5175
- createdAt: Date;
5176
- updatedAt: Date;
5177
- email: string;
5178
- emailVerified: boolean;
5179
- name: string;
5180
- image?: string | null | undefined;
5181
- } & Record<string, any>;
5182
- } | null;
5183
- session: {
5184
- session: {
5185
- id: string;
5186
- createdAt: Date;
5187
- updatedAt: Date;
5188
- userId: string;
5189
- expiresAt: Date;
5190
- token: string;
5191
- ipAddress?: string | null | undefined;
5192
- userAgent?: string | null | undefined;
5193
- } & Record<string, any>;
5194
- user: {
5195
- id: string;
5196
- createdAt: Date;
5197
- updatedAt: Date;
5198
- email: string;
5199
- emailVerified: boolean;
5200
- name: string;
5201
- image?: string | null | undefined;
5202
- } & Record<string, any>;
5203
- } | null;
5204
- setNewSession: (session: {
5205
- session: {
5206
- id: string;
5207
- createdAt: Date;
5208
- updatedAt: Date;
5209
- userId: string;
5210
- expiresAt: Date;
5211
- token: string;
5212
- ipAddress?: string | null | undefined;
5213
- userAgent?: string | null | undefined;
5214
- } & Record<string, any>;
5215
- user: {
5216
- id: string;
5217
- createdAt: Date;
5218
- updatedAt: Date;
5219
- email: string;
5220
- emailVerified: boolean;
5221
- name: string;
5222
- image?: string | null | undefined;
5223
- } & Record<string, any>;
5224
- } | null) => void;
5225
- socialProviders: OAuthProvider[];
5226
- authCookies: BetterAuthCookies;
5227
- logger: ReturnType<typeof createLogger>;
5228
- rateLimit: {
5229
- enabled: boolean;
5230
- window: number;
5231
- max: number;
5232
- storage: "memory" | "database" | "secondary-storage";
5233
- } & Omit<BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
5234
- adapter: DBAdapter<BetterAuthOptions>;
5235
- internalAdapter: InternalAdapter<BetterAuthOptions>;
5236
- createAuthCookie: (cookieName: string, overrideAttributes?: Partial<CookieOptions> | undefined) => BetterAuthCookie;
5237
- secret: string;
5238
- secretConfig: string | SecretConfig;
5239
- sessionConfig: {
5240
- updateAge: number;
5241
- expiresIn: number;
5242
- freshAge: number;
5243
- cookieRefreshCache: false | {
5244
- enabled: true;
5245
- updateAge: number;
5246
- };
5247
- };
5248
- generateId: (options: {
5249
- model: ModelNames;
5250
- size?: number | undefined;
5251
- }) => string | false;
5252
- secondaryStorage: SecondaryStorage | undefined;
5253
- password: {
5254
- hash: (password: string) => Promise<string>;
5255
- verify: (data: {
5256
- password: string;
5257
- hash: string;
5258
- }) => Promise<boolean>;
5259
- config: {
5260
- minPasswordLength: number;
5261
- maxPasswordLength: number;
5262
- };
5263
- checkPassword: (userId: string, ctx: GenericEndpointContext<BetterAuthOptions>) => Promise<boolean>;
5264
- };
5265
- tables: BetterAuthDBSchema;
5266
- runMigrations: () => Promise<void>;
5267
- publishTelemetry: (event: {
5268
- type: string;
5269
- anonymousId?: string | undefined;
5270
- payload: Record<string, any>;
5271
- }) => Promise<void>;
5272
- skipOriginCheck: boolean | string[];
5273
- skipCSRFCheck: boolean;
5274
- runInBackground: (promise: Promise<unknown>) => void;
5275
- runInBackgroundOrAwait: (promise: Promise<unknown> | void) => Awaitable<unknown>;
5276
- }>) => Promise<R_1>): (inputContext: MiddlewareInputContext<Options>) => Promise<R_1>;
5277
- };
5278
- type AuthMiddleware = ReturnType<typeof createAuthMiddleware>; //#endregion
5091
+ /**
5092
+ * The handler type for plugin hooks.
5093
+ *
5094
+ * Accepts both `Middleware` instances (from `createAuthMiddleware`)
5095
+ * and plain async functions for better-call v1/v2 compatibility.
5096
+ */
5097
+ type AuthMiddleware = (inputContext: Record<string, any>) => Promise<unknown>; //#endregion
5279
5098
  //#endregion
5280
5099
  //#region ../core/dist/types/init-options.d.mts
5281
5100
  //#region src/types/init-options.d.ts
@@ -6784,7 +6603,10 @@ type RawError<K extends string = string> = {
6784
6603
  //#region ../core/dist/types/plugin.d.mts
6785
6604
  //#region src/types/plugin.d.ts
6786
6605
  type DeepPartial<T> = T extends Function ? T : T extends object ? { [K in keyof T]?: DeepPartial<T[K]> } : T;
6787
- type HookEndpointContext = Partial<EndpointContext<string, any> & Omit<InputContext<string, any>, "method">> & {
6606
+ type HookEndpointContext = Partial<EndpointContext<string, any, any, any, any, any, any, AuthContext & {
6607
+ returned?: unknown | undefined;
6608
+ responseHeaders?: Headers | undefined;
6609
+ }> & Omit<InputContext<string, any, any, any, any, any>, "method">> & {
6788
6610
  path?: string;
6789
6611
  context: AuthContext & {
6790
6612
  returned?: unknown | undefined;
@@ -7031,14 +6853,7 @@ interface ElectronClientOptions extends ElectronSharedClientOptions {
7031
6853
  //#endregion
7032
6854
  //#region src/authenticate.d.ts
7033
6855
  declare const requestAuthOptionsSchema: z.ZodObject<{
7034
- provider: z.ZodOptional<z.ZodString>;
7035
- callbackURL: z.ZodOptional<z.ZodString>;
7036
- newUserCallbackURL: z.ZodOptional<z.ZodString>;
7037
- errorCallbackURL: z.ZodOptional<z.ZodString>;
7038
- disableRedirect: z.ZodOptional<z.ZodBoolean>;
7039
- scopes: z.ZodOptional<z.ZodArray<z.ZodString>>;
7040
- requestSignUp: z.ZodOptional<z.ZodBoolean>;
7041
- additionalData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>;
6856
+ [x: string]: any;
7042
6857
  }, z.core.$strip>;
7043
6858
  type ElectronRequestAuthOptions = z.infer<typeof requestAuthOptionsSchema>;
7044
6859
  //#endregion