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