@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.
@@ -306,6 +306,14 @@ type Where = {
306
306
  * @default AND
307
307
  */
308
308
  connector?: ("AND" | "OR") | undefined;
309
+ /**
310
+ * Case sensitivity for string comparisons.
311
+ * When "insensitive", string equality and pattern matching (contains, starts_with, ends_with)
312
+ * will be case-insensitive. Only applies to string values.
313
+ *
314
+ * @default "sensitive"
315
+ */
316
+ mode?: "sensitive" | "insensitive" | undefined;
309
317
  };
310
318
  /**
311
319
  * JoinOption configuration for relational queries.
@@ -3934,14 +3942,97 @@ type BaseAccount = z.infer<typeof accountSchema>;
3934
3942
  */
3935
3943
  type Account<DBOptions extends BetterAuthOptions["account"] = BetterAuthOptions["account"], Plugins extends BetterAuthOptions["plugins"] = BetterAuthOptions["plugins"]> = Prettify$1<BaseAccount & InferDBFieldsFromOptions<DBOptions> & InferDBFieldsFromPlugins<"account", Plugins>>; //#endregion
3936
3944
  //#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
3945
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/cookies.d.mts
3946
+ //#region src/cookies.d.ts
3947
+ type CookiePrefixOptions = "host" | "secure";
3948
+ type CookieOptions = {
3949
+ /**
3950
+ * Domain of the cookie
3951
+ *
3952
+ * The Domain attribute specifies which server can receive a cookie. If specified, cookies are
3953
+ * available on the specified server and its subdomains. If the it is not
3954
+ * specified, the cookies are available on the server that sets it but not on
3955
+ * its subdomains.
3956
+ *
3957
+ * @example
3958
+ * `domain: "example.com"`
3959
+ */
3960
+ domain?: string;
3961
+ /**
3962
+ * A lifetime of a cookie. Permanent cookies are deleted after the date specified in the
3963
+ * Expires attribute:
3964
+ *
3965
+ * Expires has been available for longer than Max-Age, however Max-Age is less error-prone, and
3966
+ * takes precedence when both are set. The rationale behind this is that when you set an
3967
+ * Expires date and time, they're relative to the client the cookie is being set on. If the
3968
+ * server is set to a different time, this could cause errors
3969
+ */
3970
+ expires?: Date;
3971
+ /**
3972
+ * Forbids JavaScript from accessing the cookie, for example, through the Document.cookie
3973
+ * property. Note that a cookie that has been created with HttpOnly will still be sent with
3974
+ * JavaScript-initiated requests, for example, when calling XMLHttpRequest.send() or fetch().
3975
+ * This mitigates attacks against cross-site scripting
3976
+ */
3977
+ httpOnly?: boolean;
3978
+ /**
3979
+ * Indicates the number of seconds until the cookie expires. A zero or negative number will
3980
+ * expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.
3981
+ *
3982
+ * @example 604800 - 7 days
3983
+ */
3984
+ maxAge?: number;
3985
+ /**
3986
+ * Indicates the path that must exist in the requested URL for the browser to send the Cookie
3987
+ * header.
3988
+ *
3989
+ * @example
3990
+ * "/docs"
3991
+ * // -> the request paths /docs, /docs/, /docs/Web/, and /docs/Web/HTTP will all match. the request paths /, /fr/docs will not match.
3992
+ */
3993
+ path?: string;
3994
+ /**
3995
+ * Indicates that the cookie is sent to the server only when a request is made with the https:
3996
+ * scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.
3997
+ */
3998
+ secure?: boolean;
3999
+ /**
4000
+ * Controls whether or not a cookie is sent with cross-site requests, providing some protection
4001
+ * against cross-site request forgery attacks (CSRF).
4002
+ *
4003
+ * Strict - Means that the browser sends the cookie only for same-site requests, that is,
4004
+ * requests originating from the same site that set the cookie. If a request originates from a
4005
+ * different domain or scheme (even with the same domain), no cookies with the SameSite=Strict
4006
+ * attribute are sent.
4007
+ *
4008
+ * Lax - Means that the cookie is not sent on cross-site requests, such as on requests to load
4009
+ * images or frames, but is sent when a user is navigating to the origin site from an external
4010
+ * site (for example, when following a link). This is the default behavior if the SameSite
4011
+ * attribute is not specified.
4012
+ *
4013
+ * None - Means that the browser sends the cookie with both cross-site and same-site requests.
4014
+ * The Secure attribute must also be set when setting this value.
4015
+ */
4016
+ sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
4017
+ /**
4018
+ * Indicates that the cookie should be stored using partitioned storage. Note that if this is
4019
+ * set, the Secure directive must also be set.
4020
+ *
4021
+ * @see https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
4022
+ */
4023
+ partitioned?: boolean;
4024
+ /**
4025
+ * Cooke Prefix
4026
+ *
4027
+ * - secure: `__Secure-` -> `__Secure-cookie-name`
4028
+ * - host: `__Host-` -> `__Host-cookie-name`
4029
+ *
4030
+ * `secure` must be set to true to use prefixes
4031
+ */
4032
+ prefix?: CookiePrefixOptions;
4033
+ };
3943
4034
  //#endregion
3944
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/standard-schema.d.mts
4035
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/standard-schema.d.mts
3945
4036
  //#region src/standard-schema.d.ts
3946
4037
  /** The Standard Schema interface. */
3947
4038
  interface StandardSchemaV1$1<Input = unknown, Output = Input> {
@@ -3999,7 +4090,7 @@ declare namespace StandardSchemaV1$1 {
3999
4090
  type InferOutput<Schema extends StandardSchemaV1$1> = NonNullable<Schema["~standard"]["types"]>["output"];
4000
4091
  } //#endregion
4001
4092
  //#endregion
4002
- //#region ../../node_modules/.pnpm/better-call@1.3.2_zod@4.3.6/node_modules/better-call/dist/error.d.mts
4093
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/error.d.mts
4003
4094
  declare const statusCodes: {
4004
4095
  OK: number;
4005
4096
  CREATED: number;
@@ -4077,341 +4168,284 @@ declare const APIError: new (status?: Status | "OK" | "CREATED" | "ACCEPTED" | "
4077
4168
  errorStack: string | undefined;
4078
4169
  }; //#endregion
4079
4170
  //#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 = {
4171
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/helper.d.mts
4172
+ type Prettify<T> = 0 extends 1 & T ? any : { [K in keyof T]: T[K] } & {};
4173
+ type IsEmptyObject<T> = keyof T extends never ? true : false;
4174
+ type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
4175
+ 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> : {};
4176
+ 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
4177
+ //#endregion
4178
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/middleware.d.mts
4179
+ //#region src/middleware.d.ts
4180
+ type MiddlewareContext<Context = {}> = {
4084
4181
  /**
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.
4182
+ * Method
4091
4183
  *
4092
- * @example
4093
- * `domain: "example.com"`
4184
+ * The request method
4094
4185
  */
4095
- domain?: string;
4186
+ method: string;
4096
4187
  /**
4097
- * A lifetime of a cookie. Permanent cookies are deleted after the date specified in the
4098
- * Expires attribute:
4188
+ * Path
4099
4189
  *
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
4190
+ * The path of the endpoint
4111
4191
  */
4112
- httpOnly?: boolean;
4192
+ path: string;
4113
4193
  /**
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.
4194
+ * Body
4116
4195
  *
4117
- * @example 604800 - 7 days
4196
+ * The body object will be the parsed JSON from the request and validated
4197
+ * against the body schema if it exists
4118
4198
  */
4119
- maxAge?: number;
4199
+ body: any;
4120
4200
  /**
4121
- * Indicates the path that must exist in the requested URL for the browser to send the Cookie
4122
- * header.
4201
+ * Query
4123
4202
  *
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.
4203
+ * The query object will be the parsed query string from the request
4204
+ * and validated against the query schema if it exists
4127
4205
  */
4128
- path?: string;
4206
+ query: Record<string, any> | undefined;
4129
4207
  /**
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.
4208
+ * Params
4209
+ *
4210
+ * If the path is `/user/:id` and the request is `/user/1` then the
4211
+ * params will be `{ id: "1" }` and if the path includes a wildcard like
4212
+ * `/user/*` then the params will be `{ _: "1" }` where `_` is the wildcard
4213
+ * key. If the wildcard is named like `/user/**:name` then the params will
4214
+ * be `{ name: string }`
4132
4215
  */
4133
- secure?: boolean;
4216
+ params: Record<string, any> | undefined;
4134
4217
  /**
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.
4218
+ * Request object
4147
4219
  *
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.
4220
+ * If `requireRequest` is set to true in the endpoint options this will be
4221
+ * required
4150
4222
  */
4151
- sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
4223
+ request: Request | undefined;
4152
4224
  /**
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.
4225
+ * Headers
4155
4226
  *
4156
- * @see https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
4227
+ * If `requireHeaders` is set to true in the endpoint options this will be
4228
+ * required
4157
4229
  */
4158
- partitioned?: boolean;
4230
+ headers: Headers | undefined;
4159
4231
  /**
4160
- * Cooke Prefix
4161
- *
4162
- * - secure: `__Secure-` -> `__Secure-cookie-name`
4163
- * - host: `__Host-` -> `__Host-cookie-name`
4232
+ * Set header
4164
4233
  *
4165
- * `secure` must be set to true to use prefixes
4234
+ * If it's called outside of a request it will just be ignored.
4166
4235
  */
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 {
4236
+ setHeader: (key: string, value: string) => void;
4195
4237
  /**
4196
- * Query Schema
4238
+ * Set the response status code
4197
4239
  */
4198
- query?: StandardSchemaV1$1;
4240
+ setStatus: (status: Status) => void;
4199
4241
  /**
4200
- * Error Schema
4242
+ * Get header
4243
+ *
4244
+ * If it's called outside of a request it will just return null
4245
+ *
4246
+ * @param key - The key of the header
4201
4247
  */
4202
- error?: StandardSchemaV1$1;
4248
+ getHeader: (key: string) => string | null;
4203
4249
  /**
4204
- * If true headers will be required to be passed in the context
4250
+ * Get a cookie value from the request
4251
+ *
4252
+ * @param key - The key of the cookie
4253
+ * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
4254
+ * @returns The value of the cookie
4205
4255
  */
4206
- requireHeaders?: boolean;
4256
+ getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
4207
4257
  /**
4208
- * If true request object will be required
4258
+ * Get a signed cookie value from the request
4259
+ *
4260
+ * @param key - The key of the cookie
4261
+ * @param secret - The secret of the signed cookie
4262
+ * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
4263
+ * @returns The value of the cookie or null if the cookie is not found or false if the signature is invalid
4209
4264
  */
4210
- requireRequest?: boolean;
4265
+ getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | null | false>;
4211
4266
  /**
4212
- * Clone the request object from the router
4267
+ * Set a cookie value in the response
4268
+ *
4269
+ * @param key - The key of the cookie
4270
+ * @param value - The value to set
4271
+ * @param options - The options of the cookie
4272
+ * @returns The cookie string
4213
4273
  */
4214
- cloneRequest?: boolean;
4274
+ setCookie: (key: string, value: string, options?: CookieOptions) => string;
4215
4275
  /**
4216
- * If true the body will be undefined
4276
+ * Set signed cookie
4277
+ *
4278
+ * @param key - The key of the cookie
4279
+ * @param value - The value to set
4280
+ * @param secret - The secret to sign the cookie with
4281
+ * @param options - The options of the cookie
4282
+ * @returns The cookie string
4217
4283
  */
4218
- disableBody?: boolean;
4284
+ setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
4219
4285
  /**
4220
- * Endpoint metadata
4221
- */
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
- };
4347
- /**
4348
- * List of middlewares to use
4349
- */
4350
- use?: Middleware[];
4351
- /**
4352
- * A callback to run before any API error is throw or returned
4286
+ * JSON
4353
4287
  *
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
4361
- */
4362
- onValidationError?: ({
4363
- issues,
4364
- message
4365
- }: {
4366
- message: string;
4367
- issues: readonly StandardSchemaV1$1.Issue[];
4368
- }) => void | Promise<void>;
4369
- }
4370
- type EndpointBodyMethodOptions = {
4371
- /**
4372
- * Request Method
4373
- */
4374
- method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
4375
- /**
4376
- * Body Schema
4377
- */
4378
- body?: StandardSchemaV1$1;
4379
- } | {
4380
- /**
4381
- * Request Method
4382
- */
4383
- method: "GET" | "HEAD" | ("GET" | "HEAD")[];
4384
- /**
4385
- * Body Schema
4386
- */
4387
- body?: never;
4388
- } | {
4389
- /**
4390
- * Request Method
4288
+ * A helper function to create a JSON response with the correct headers
4289
+ * and status code. If `asResponse` is set to true in the context then
4290
+ * it will return a Response object instead of the JSON object.
4291
+ *
4292
+ * @param json - The JSON object to return
4293
+ * @param routerResponse - The response object to return if `asResponse` is
4294
+ * true in the context this will take precedence
4391
4295
  */
4392
- method: "*";
4296
+ json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
4297
+ status?: number;
4298
+ headers?: Record<string, string>;
4299
+ response?: Response;
4300
+ body?: Record<string, any>;
4301
+ } | Response) => R;
4393
4302
  /**
4394
- * Body Schema
4303
+ * Middleware context
4395
4304
  */
4396
- body?: StandardSchemaV1$1;
4397
- } | {
4305
+ context: Prettify<Context>;
4398
4306
  /**
4399
- * Request Method
4307
+ * Redirect to a new URL
4400
4308
  */
4401
- method: ("POST" | "PUT" | "DELETE" | "PATCH" | "GET" | "HEAD")[];
4309
+ redirect: (url: string) => APIError;
4402
4310
  /**
4403
- * Body Schema
4311
+ * Return error
4404
4312
  */
4405
- body?: StandardSchemaV1$1;
4313
+ error: (status: keyof typeof statusCodes | Status, body?: {
4314
+ message?: string;
4315
+ code?: string;
4316
+ } & Record<string, any>, headers?: HeadersInit) => APIError;
4317
+ asResponse?: boolean;
4318
+ returnHeaders?: boolean;
4319
+ returnStatus?: boolean;
4320
+ responseHeaders: Headers;
4321
+ };
4322
+ type DefaultHandler = (inputCtx: MiddlewareContext<any>) => Promise<any>;
4323
+ type Middleware<Handler extends (inputCtx: MiddlewareContext<any>) => Promise<any> = DefaultHandler> = Handler & {
4324
+ options: Record<string, any>;
4406
4325
  };
4407
- type EndpointOptions = EndpointBaseOptions & EndpointBodyMethodOptions;
4408
- type EndpointContext<Path extends string, Options extends EndpointOptions, Context = {}> = {
4326
+ //#endregion
4327
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/types.d.mts
4328
+ //#region src/types.d.ts
4329
+ type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
4330
+ /**
4331
+ * Resolves a method type parameter to its effective runtime type.
4332
+ */
4333
+ type ResolveMethod<M> = M extends Array<infer U> ? U : M extends "*" ? HTTPMethod : M;
4334
+ /**
4335
+ * Resolve a $Infer value: if it's a StandardSchemaV1 schema, extract the
4336
+ * output type; otherwise use as-is.
4337
+ */
4338
+ type ResolveInferValue<T> = T extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferOutput<T> : T;
4339
+ /**
4340
+ * Resolves a body schema to its output type.
4341
+ */
4342
+ type ResolveBody<S, Meta = undefined> = Meta extends {
4343
+ $Infer: {
4344
+ body: infer B;
4345
+ };
4346
+ } ? ResolveInferValue<B> : S extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferOutput<S> : any;
4347
+ /**
4348
+ * Resolves a query schema to its output type.
4349
+ */
4350
+ type ResolveQuery<S, Meta = undefined> = Meta extends {
4351
+ $Infer: {
4352
+ query: infer Q;
4353
+ };
4354
+ } ? ResolveInferValue<Q> : S extends StandardSchemaV1$1 ? StandardSchemaV1$1.InferOutput<S> : Record<string, any> | undefined;
4355
+ /**
4356
+ * Resolves body schema to its input type (for InputContext at call-site).
4357
+ */
4358
+ /**
4359
+ * Infer param types from a path string.
4360
+ */
4361
+ 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>>;
4362
+ /**
4363
+ * Infer param input (required vs optional based on whether path has params).
4364
+ */
4365
+ type InferParamInput<Path extends string> = [Path] extends [never] ? {
4366
+ params?: Record<string, any>;
4367
+ } : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? {
4368
+ params?: Record<string, any>;
4369
+ } : {
4370
+ params: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
4371
+ };
4372
+ /**
4373
+ * Infer body input from an already-resolved body type.
4374
+ * Body is the plain resolved type (not a schema).
4375
+ */
4376
+ type InferBodyInput<Body> = undefined extends Body ? {
4377
+ body?: Body;
4378
+ } : {
4379
+ body: Body;
4380
+ };
4381
+ /**
4382
+ * Infer query input from an already-resolved query type.
4383
+ * Query is the plain resolved type (not a schema).
4384
+ */
4385
+ type InferQueryInput<Query> = undefined extends Query ? {
4386
+ query?: Query;
4387
+ } : {
4388
+ query: Query;
4389
+ };
4390
+ /**
4391
+ * Infer method input: required for wildcard, optional for arrays and single methods.
4392
+ */
4393
+ type InferMethodInput<M> = 0 extends 1 & M ? {
4394
+ method?: HTTPMethod | undefined;
4395
+ } : M extends "*" ? {
4396
+ method: HTTPMethod;
4397
+ } : M extends Array<any> ? {
4398
+ method?: M[number] | undefined;
4399
+ } : {
4400
+ method?: M | undefined;
4401
+ };
4402
+ /**
4403
+ * Infer request input.
4404
+ */
4405
+ type InferRequestInput<ReqRequest extends boolean> = 0 extends 1 & ReqRequest ? {
4406
+ request?: Request;
4407
+ } : ReqRequest extends true ? {
4408
+ request: Request;
4409
+ } : {
4410
+ request?: Request;
4411
+ };
4412
+ /**
4413
+ * Infer headers input.
4414
+ */
4415
+ type InferHeadersInput<ReqHeaders extends boolean> = 0 extends 1 & ReqHeaders ? {
4416
+ headers?: HeadersInit;
4417
+ } : ReqHeaders extends true ? {
4418
+ headers: HeadersInit;
4419
+ } : {
4420
+ headers?: HeadersInit;
4421
+ };
4422
+ /**
4423
+ * Infer the use (middleware) context union.
4424
+ * Guards against `any` and `[]` to avoid poisoning the Context type.
4425
+ */
4426
+ type InferUse<Opts extends Middleware[] | undefined> = 0 extends 1 & Opts ? any : Opts extends Middleware[] ? Opts extends [] ? {} : UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
4427
+ /**
4428
+ * The full InputContext type for the Endpoint call signature.
4429
+ * Body and Query are already-resolved plain types.
4430
+ */
4431
+ 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> & {
4432
+ asResponse?: boolean;
4433
+ returnHeaders?: boolean;
4434
+ returnStatus?: boolean;
4435
+ use?: Middleware[];
4436
+ path?: string;
4437
+ context?: Record<string, any>;
4438
+ }; //#endregion
4439
+ //#endregion
4440
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/context.d.mts
4441
+ //#region src/context.d.ts
4442
+ 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
4443
  /**
4410
4444
  * Method
4411
4445
  *
4412
4446
  * The request method
4413
4447
  */
4414
- method: InferMethod<Options>;
4448
+ method: ResolveMethod<M>;
4415
4449
  /**
4416
4450
  * Path
4417
4451
  *
@@ -4424,14 +4458,14 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4424
4458
  * The body object will be the parsed JSON from the request and validated
4425
4459
  * against the body schema if it exists.
4426
4460
  */
4427
- body: InferBody<Options>;
4461
+ body: ResolveBody<BodySchema, Meta>;
4428
4462
  /**
4429
4463
  * Query
4430
4464
  *
4431
4465
  * The query object will be the parsed query string from the request
4432
4466
  * and validated against the query schema if it exists
4433
4467
  */
4434
- query: InferQuery<Options>;
4468
+ query: ResolveQuery<QuerySchema, Meta>;
4435
4469
  /**
4436
4470
  * Params
4437
4471
  *
@@ -4447,14 +4481,14 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4447
4481
  * If `requireRequest` is set to true in the endpoint options this will be
4448
4482
  * required
4449
4483
  */
4450
- request: InferRequest<Options>;
4484
+ request: ReqRequest extends true ? Request : Request | undefined;
4451
4485
  /**
4452
4486
  * Headers
4453
4487
  *
4454
4488
  * If `requireHeaders` is set to true in the endpoint options this will be
4455
4489
  * required
4456
4490
  */
4457
- headers: InferHeaders<Options>;
4491
+ headers: ReqHeaders extends true ? Headers : Headers | undefined;
4458
4492
  /**
4459
4493
  * Set header
4460
4494
  *
@@ -4470,8 +4504,7 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4470
4504
  *
4471
4505
  * If it's called outside of a request it will just return null
4472
4506
  *
4473
- * @param key - The key of the header
4474
- * @returns
4507
+ * @param key - The key of the header
4475
4508
  */
4476
4509
  getHeader: (key: string) => string | null;
4477
4510
  /**
@@ -4479,7 +4512,7 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4479
4512
  *
4480
4513
  * @param key - The key of the cookie
4481
4514
  * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
4482
- * @returns - The value of the cookie
4515
+ * @returns The value of the cookie
4483
4516
  */
4484
4517
  getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
4485
4518
  /**
@@ -4488,7 +4521,7 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4488
4521
  * @param key - The key of the cookie
4489
4522
  * @param secret - The secret of the signed cookie
4490
4523
  * @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
4524
+ * @returns The value of the cookie or null if the cookie is not found or false if the signature is invalid
4492
4525
  */
4493
4526
  getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | null | false>;
4494
4527
  /**
@@ -4497,44 +4530,40 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4497
4530
  * @param key - The key of the cookie
4498
4531
  * @param value - The value to set
4499
4532
  * @param options - The options of the cookie
4500
- * @returns - The cookie string
4533
+ * @returns The cookie string
4501
4534
  */
4502
4535
  setCookie: (key: string, value: string, options?: CookieOptions) => string;
4503
4536
  /**
4504
4537
  * Set signed cookie
4505
4538
  *
4506
4539
  * @param key - The key of the cookie
4507
- * @param value - The value to set
4540
+ * @param value - The value to set
4508
4541
  * @param secret - The secret to sign the cookie with
4509
4542
  * @param options - The options of the cookie
4510
- * @returns - The cookie string
4543
+ * @returns The cookie string
4511
4544
  */
4512
4545
  setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
4513
4546
  /**
4514
4547
  * JSON
4515
4548
  *
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.
4549
+ * A helper function to create a JSON response with the correct headers
4550
+ * and status code. If `asResponse` is set to true in the context then
4551
+ * it will return a Response object instead of the JSON object.
4522
4552
  *
4523
4553
  * @param json - The JSON object to return
4524
- * @param routerResponse - The response object to
4525
- * return if `asResponse` is
4554
+ * @param routerResponse - The response object to return if `asResponse` is
4526
4555
  * true in the context this will take precedence
4527
4556
  */
4528
4557
  json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
4529
4558
  status?: number;
4530
4559
  headers?: Record<string, string>;
4531
4560
  response?: Response;
4532
- body?: Record<string, string>;
4533
- } | Response) => Promise<R>;
4561
+ body?: Record<string, any>;
4562
+ } | Response) => R;
4534
4563
  /**
4535
4564
  * Middleware context
4536
4565
  */
4537
- context: Prettify<Context & InferUse<Options["use"]>>;
4566
+ context: 0 extends 1 & Use ? Prettify<Context> : Prettify<Context & InferUse<Use>>;
4538
4567
  /**
4539
4568
  * Redirect to a new URL
4540
4569
  */
@@ -4546,188 +4575,242 @@ type EndpointContext<Path extends string, Options extends EndpointOptions, Conte
4546
4575
  message?: string;
4547
4576
  code?: string;
4548
4577
  } & 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
4578
  }; //#endregion
4554
4579
  //#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
- }> & {
4580
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/endpoint.d.mts
4581
+ //#region src/endpoint.d.ts
4582
+ interface EndpointMetadata {
4561
4583
  /**
4562
- * Method
4563
- *
4564
- * The request method
4584
+ * Open API definition
4565
4585
  */
4566
- method: string;
4586
+ openapi?: {
4587
+ summary?: string;
4588
+ description?: string;
4589
+ tags?: string[];
4590
+ operationId?: string;
4591
+ parameters?: OpenAPIParameter[];
4592
+ requestBody?: {
4593
+ content: {
4594
+ "application/json": {
4595
+ schema: {
4596
+ type?: OpenAPISchemaType;
4597
+ properties?: Record<string, any>;
4598
+ required?: string[];
4599
+ $ref?: string;
4600
+ };
4601
+ };
4602
+ };
4603
+ };
4604
+ responses?: {
4605
+ [status: string]: {
4606
+ description: string;
4607
+ content?: {
4608
+ "application/json"?: {
4609
+ schema: {
4610
+ type?: OpenAPISchemaType;
4611
+ properties?: Record<string, any>;
4612
+ required?: string[];
4613
+ $ref?: string;
4614
+ };
4615
+ };
4616
+ "text/plain"?: {
4617
+ schema?: {
4618
+ type?: OpenAPISchemaType;
4619
+ properties?: Record<string, any>;
4620
+ required?: string[];
4621
+ $ref?: string;
4622
+ };
4623
+ };
4624
+ "text/html"?: {
4625
+ schema?: {
4626
+ type?: OpenAPISchemaType;
4627
+ properties?: Record<string, any>;
4628
+ required?: string[];
4629
+ $ref?: string;
4630
+ };
4631
+ };
4632
+ };
4633
+ };
4634
+ };
4635
+ };
4567
4636
  /**
4568
- * Path
4637
+ * Infer body and query type from ts interface
4569
4638
  *
4570
- * The path of the endpoint
4639
+ * useful for generic and dynamic types
4640
+ *
4641
+ * @example
4642
+ * ```ts
4643
+ * const endpoint = createEndpoint("/path", {
4644
+ * method: "POST",
4645
+ * body: z.record(z.string()),
4646
+ * $Infer: {
4647
+ * body: {} as {
4648
+ * type: InferTypeFromOptions<Option> // custom type inference
4649
+ * }
4650
+ * }
4651
+ * }, async(ctx)=>{
4652
+ * const body = ctx.body
4653
+ * })
4654
+ * ```
4571
4655
  */
4572
- path: string;
4656
+ $Infer?: {
4657
+ /**
4658
+ * Body
4659
+ */
4660
+ body?: any;
4661
+ /**
4662
+ * Query
4663
+ */
4664
+ query?: Record<string, any>;
4665
+ /**
4666
+ * Error
4667
+ */
4668
+ error?: any;
4669
+ };
4573
4670
  /**
4574
- * Body
4575
- *
4576
- * The body object will be the parsed JSON from the request and validated
4577
- * against the body schema if it exists
4671
+ * If enabled, endpoint won't be exposed over a router
4672
+ * @deprecated Use path-less endpoints instead
4578
4673
  */
4579
- body: InferMiddlewareBody<Options>;
4674
+ SERVER_ONLY?: boolean;
4580
4675
  /**
4581
- * Query
4582
- *
4583
- * The query object will be the parsed query string from the request
4584
- * and validated against the query schema if it exists
4676
+ * If enabled, endpoint won't be exposed as an action to the client
4677
+ * @deprecated Use path-less endpoints instead
4585
4678
  */
4586
- query: InferMiddlewareQuery<Options>;
4679
+ isAction?: boolean;
4587
4680
  /**
4588
- * Params
4681
+ * Defines the places where the endpoint will be available
4589
4682
  *
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 }`
4683
+ * Possible options:
4684
+ * - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
4685
+ * - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
4686
+ * - `http` - the endpoint is only exposed to the router
4687
+ * @default "rpc"
4597
4688
  */
4598
- params: string;
4689
+ scope?: "rpc" | "server" | "http";
4599
4690
  /**
4600
- * Request object
4691
+ * List of allowed media types (MIME types) for the endpoint
4601
4692
  *
4602
- * If `requireRequest` is set to true in the endpoint options this will be
4603
- * required
4693
+ * if provided, only the media types in the list will be allowed to be passed in the body
4694
+ *
4695
+ * @example
4696
+ * ```ts
4697
+ * const endpoint = createEndpoint("/path", {
4698
+ * method: "POST",
4699
+ * allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
4700
+ * }, async(ctx)=>{
4701
+ * const body = ctx.body
4702
+ * })
4703
+ * ```
4604
4704
  */
4605
- request: InferRequest<Options>;
4705
+ allowedMediaTypes?: string[];
4606
4706
  /**
4607
- * Headers
4608
- *
4609
- * If `requireHeaders` is set to true in the endpoint options this will be
4610
- * required
4707
+ * Extra metadata
4611
4708
  */
4612
- headers: InferHeaders<Options>;
4709
+ [key: string]: any;
4710
+ }
4711
+ interface EndpointRuntimeOptions {
4712
+ method: string | string[];
4713
+ body?: StandardSchemaV1$1;
4613
4714
  /**
4614
- * Set header
4615
- *
4616
- * If it's called outside of a request it will just be ignored.
4715
+ * Query Schema
4617
4716
  */
4618
- setHeader: (key: string, value: string) => void;
4717
+ query?: StandardSchemaV1$1;
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
+ * Error Schema
4626
4720
  */
4627
- getHeader: (key: string) => string | null;
4721
+ error?: StandardSchemaV1$1;
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
+ * If true headers will be required to be passed in the context
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
+ requireHeaders?: boolean;
4648
4726
  /**
4649
- * Middleware context
4727
+ * If true request object will be required
4728
+ */
4729
+ requireRequest?: boolean;
4730
+ /**
4731
+ * Clone the request object from the router
4732
+ */
4733
+ cloneRequest?: boolean;
4734
+ /**
4735
+ * If true the body will be undefined
4736
+ */
4737
+ disableBody?: boolean;
4738
+ /**
4739
+ * Endpoint metadata
4740
+ */
4741
+ metadata?: EndpointMetadata;
4742
+ /**
4743
+ * List of middlewares to use
4650
4744
  */
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
4745
  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;
4746
+ /**
4747
+ * A callback to run before any API error is thrown or returned
4748
+ *
4749
+ * @param e - The API error
4750
+ */
4751
+ onAPIError?: (e: APIError) => void | Promise<void>;
4752
+ /**
4753
+ * A callback to run before a validation error is thrown.
4754
+ * You can customize the validation error message by throwing your own APIError.
4755
+ */
4756
+ onValidationError?: (info: {
4757
+ message: string;
4758
+ issues: readonly StandardSchemaV1$1.Issue[];
4759
+ }) => void | Promise<void>;
4760
+ }
4761
+ 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> = {
4762
+ (context: InputContext<Path, Method, Body, Query, false, false> & {
4763
+ asResponse: true;
4764
+ }): Promise<Response>;
4765
+ (context: InputContext<Path, Method, Body, Query, false, false> & {
4766
+ returnHeaders: true;
4767
+ returnStatus: true;
4768
+ }): Promise<{
4769
+ headers: Headers;
4770
+ status: number;
4771
+ response: Awaited<R>;
4772
+ }>;
4773
+ (context: InputContext<Path, Method, Body, Query, false, false> & {
4774
+ returnHeaders: true;
4775
+ }): Promise<{
4776
+ headers: Headers;
4777
+ response: Awaited<R>;
4778
+ }>;
4779
+ (context: InputContext<Path, Method, Body, Query, false, false> & {
4780
+ returnStatus: true;
4781
+ }): Promise<{
4782
+ status: number;
4783
+ response: Awaited<R>;
4784
+ }>;
4785
+ (context?: InputContext<Path, Method, Body, Query, false, false>): Promise<Awaited<R>>;
4786
+ readonly options: Omit<EndpointRuntimeOptions, "method" | "metadata"> & {
4787
+ readonly method: Method;
4788
+ readonly metadata?: Meta;
4683
4789
  };
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;
4790
+ readonly path: Path;
4688
4791
  };
4689
- type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
4690
- $Infer: {
4691
- query: infer Query;
4792
+ //#endregion
4793
+ //#region ../../node_modules/.pnpm/better-call@2.0.3_zod@4.3.6/node_modules/better-call/dist/openapi.d.mts
4794
+ //#region src/openapi.d.ts
4795
+ type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
4796
+ interface OpenAPIParameter {
4797
+ in: "query" | "path" | "header" | "cookie";
4798
+ name?: string;
4799
+ description?: string;
4800
+ required?: boolean;
4801
+ schema?: {
4802
+ type: OpenAPISchemaType;
4803
+ format?: string | undefined;
4804
+ items?: {
4805
+ type: OpenAPISchemaType;
4806
+ };
4807
+ enum?: string[];
4808
+ minLength?: number;
4809
+ description?: string | undefined;
4810
+ default?: string | undefined;
4811
+ example?: string | undefined;
4692
4812
  };
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
- };
4813
+ }
4731
4814
  //#endregion
4732
4815
  //#region ../core/dist/types/cookie.d.mts
4733
4816
  //#region src/types/cookie.d.ts
@@ -4776,6 +4859,7 @@ type InferPluginOptions<O extends BetterAuthOptions, ID extends BetterAuthPlugin
4776
4859
  *
4777
4860
  * const createMyPlugin = <Options extends MyPluginOptions>(options?: Options) => ({
4778
4861
  * id: 'my-plugin',
4862
+ * version: '1.0.0',
4779
4863
  * options,
4780
4864
  * } satisfies BetterAuthPlugin);
4781
4865
  *
@@ -4790,9 +4874,7 @@ type InferPluginOptions<O extends BetterAuthOptions, ID extends BetterAuthPlugin
4790
4874
  */
4791
4875
  interface BetterAuthPluginRegistry<AuthOptions, Options> {}
4792
4876
  type BetterAuthPluginRegistryIdentifier = keyof BetterAuthPluginRegistry<unknown, unknown>;
4793
- type GenericEndpointContext<Options extends BetterAuthOptions = BetterAuthOptions> = EndpointContext<string, any> & {
4794
- context: AuthContext<Options>;
4795
- };
4877
+ type GenericEndpointContext<Options extends BetterAuthOptions = BetterAuthOptions> = EndpointContext<string, any, any, any, any, any, any, AuthContext<Options>>;
4796
4878
  interface InternalAdapter<_Options extends BetterAuthOptions = BetterAuthOptions> {
4797
4879
  createOAuthUser(user: Omit<User, "id" | "createdAt" | "updatedAt">, account: Omit<Account, "userId" | "id" | "createdAt" | "updatedAt"> & Partial<Account>): Promise<{
4798
4880
  user: User;
@@ -5015,267 +5097,13 @@ type AuthContext<Options extends BetterAuthOptions = BetterAuthOptions> = Plugin
5015
5097
  }; //#endregion
5016
5098
  //#endregion
5017
5099
  //#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
5100
+ /**
5101
+ * The handler type for plugin hooks.
5102
+ *
5103
+ * Accepts both `Middleware` instances (from `createAuthMiddleware`)
5104
+ * and plain async functions for better-call v1/v2 compatibility.
5105
+ */
5106
+ type AuthMiddleware = (inputContext: Record<string, any>) => Promise<unknown>; //#endregion
5279
5107
  //#endregion
5280
5108
  //#region ../core/dist/types/init-options.d.mts
5281
5109
  //#region src/types/init-options.d.ts
@@ -5426,7 +5254,9 @@ type BetterAuthAdvancedOptions = {
5426
5254
  ipv6Subnet?: 128 | 64 | 48 | 32;
5427
5255
  } | undefined;
5428
5256
  /**
5429
- * Use secure cookies
5257
+ * Force cookies to always use the `Secure` attribute. By default,
5258
+ * cookies are secure in production environments. Set this to `true`
5259
+ * to enforce secure cookies in all environments.
5430
5260
  *
5431
5261
  * @default false
5432
5262
  */
@@ -5575,9 +5405,11 @@ type BetterAuthAdvancedOptions = {
5575
5405
  };
5576
5406
  type BetterAuthOptions = {
5577
5407
  /**
5578
- * The name of the application
5408
+ * The name of your application. Used as a display name in contexts
5409
+ * where your app needs to be identified — for example, as the default
5410
+ * issuer name in authenticator apps when users set up 2FA/TOTP.
5579
5411
  *
5580
- * process.env.APP_NAME
5412
+ * Can also be set via the `APP_NAME` environment variable.
5581
5413
  *
5582
5414
  * @default "Better Auth"
5583
5415
  */
@@ -6276,7 +6108,12 @@ type BetterAuthOptions = {
6276
6108
  storeInDatabase?: boolean;
6277
6109
  }) | undefined;
6278
6110
  /**
6279
- * List of trusted origins.
6111
+ * Additional trusted origins. By default, Better Auth trusts your
6112
+ * app's {@link baseURL}. Use this option to allow additional origins
6113
+ * (e.g. a separate frontend domain).
6114
+ *
6115
+ * Can be a static array, a function that returns origins dynamically,
6116
+ * or use wildcard patterns (e.g. `"https://*.example.com"`).
6280
6117
  *
6281
6118
  * @param request - The request object.
6282
6119
  * It'll be undefined if no request was
@@ -6784,7 +6621,10 @@ type RawError<K extends string = string> = {
6784
6621
  //#region ../core/dist/types/plugin.d.mts
6785
6622
  //#region src/types/plugin.d.ts
6786
6623
  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">> & {
6624
+ type HookEndpointContext = Partial<EndpointContext<string, any, any, any, any, any, any, AuthContext & {
6625
+ returned?: unknown | undefined;
6626
+ responseHeaders?: Headers | undefined;
6627
+ }> & Omit<InputContext<string, any, any, any, any, any>, "method">> & {
6788
6628
  path?: string;
6789
6629
  context: AuthContext & {
6790
6630
  returned?: unknown | undefined;
@@ -6800,6 +6640,7 @@ type BetterAuthPluginErrorCodePart = {
6800
6640
  };
6801
6641
  type BetterAuthPlugin = BetterAuthPluginErrorCodePart & {
6802
6642
  id: LiteralString;
6643
+ version?: string | undefined;
6803
6644
  /**
6804
6645
  * The init function is called when the plugin is initialized.
6805
6646
  * You can return a new context or modify the existing context.
@@ -7031,14 +6872,7 @@ interface ElectronClientOptions extends ElectronSharedClientOptions {
7031
6872
  //#endregion
7032
6873
  //#region src/authenticate.d.ts
7033
6874
  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>>;
6875
+ [x: string]: any;
7042
6876
  }, z.core.$strip>;
7043
6877
  type ElectronRequestAuthOptions = z.infer<typeof requestAuthOptionsSchema>;
7044
6878
  //#endregion