@better-auth/api-key 1.6.11 → 1.6.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/client.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { i as API_KEY_ERROR_CODES, n as apiKey } from "./index-CajK1bx0.mjs";
2
- import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-CCe5L05Y.mjs";
1
+ import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-BR70O3Q3.mjs";
2
+ import { i as API_KEY_ERROR_CODES, n as apiKey } from "./index-CI6mGUwK.mjs";
3
3
  import * as better_auth0 from "better-auth";
4
4
 
5
5
  //#region src/client.d.ts
package/dist/client.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-CwRZx9_C.mjs";
1
+ import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-D9MWdfX3.mjs";
2
2
  //#region src/client.ts
3
3
  const apiKeyClient = () => {
4
4
  return {
@@ -1,846 +1,10 @@
1
- import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-CCe5L05Y.mjs";
1
+ import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-BR70O3Q3.mjs";
2
2
  import * as better_auth0 from "better-auth";
3
3
  import * as zod from "zod";
4
+ import * as better_call0 from "better-call";
4
5
  import * as zod_v4_core0 from "zod/v4/core";
5
6
  import { HookEndpointContext } from "@better-auth/core";
6
7
 
7
- //#region ../../node_modules/.pnpm/better-call@1.3.5_zod@4.3.6/node_modules/better-call/dist/helper.d.mts
8
- type Prettify<T> = { [K in keyof T]: T[K] } & {};
9
- type IsEmptyObject<T> = keyof T extends never ? true : false;
10
- type UnionToIntersection<Union> = (Union extends unknown ? (distributedUnion: Union) => void : never) extends ((mergedIntersection: infer Intersection) => void) ? Intersection & Union : never;
11
- 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> : {};
12
- 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
13
- //#endregion
14
- //#region ../../node_modules/.pnpm/better-call@1.3.5_zod@4.3.6/node_modules/better-call/dist/standard-schema.d.mts
15
- //#region src/standard-schema.d.ts
16
- /** The Standard Schema interface. */
17
- interface StandardSchemaV1<Input = unknown, Output = Input> {
18
- /** The Standard Schema properties. */
19
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
20
- }
21
- declare namespace StandardSchemaV1 {
22
- /** The Standard Schema properties interface. */
23
- interface Props<Input = unknown, Output = Input> {
24
- /** The version number of the standard. */
25
- readonly version: 1;
26
- /** The vendor name of the schema library. */
27
- readonly vendor: string;
28
- /** Validates unknown input values. */
29
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
30
- /** Inferred types associated with the schema. */
31
- readonly types?: Types<Input, Output> | undefined;
32
- }
33
- /** The result interface of the validate function. */
34
- type Result<Output> = SuccessResult<Output> | FailureResult;
35
- /** The result interface if validation succeeds. */
36
- interface SuccessResult<Output> {
37
- /** The typed output value. */
38
- readonly value: Output;
39
- /** The non-existent issues. */
40
- readonly issues?: undefined;
41
- }
42
- /** The result interface if validation fails. */
43
- interface FailureResult {
44
- /** The issues of failed validation. */
45
- readonly issues: ReadonlyArray<Issue>;
46
- }
47
- /** The issue interface of the failure output. */
48
- interface Issue {
49
- /** The error message of the issue. */
50
- readonly message: string;
51
- /** The path of the issue, if any. */
52
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
53
- }
54
- /** The path segment interface of the issue. */
55
- interface PathSegment {
56
- /** The key representing a path segment. */
57
- readonly key: PropertyKey;
58
- }
59
- /** The Standard Schema types interface. */
60
- interface Types<Input = unknown, Output = Input> {
61
- /** The input type of the schema. */
62
- readonly input: Input;
63
- /** The output type of the schema. */
64
- readonly output: Output;
65
- }
66
- /** Infers the input type of a Standard Schema. */
67
- type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
68
- /** Infers the output type of a Standard Schema. */
69
- type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
70
- } //#endregion
71
- //#endregion
72
- //#region ../../node_modules/.pnpm/better-call@1.3.5_zod@4.3.6/node_modules/better-call/dist/error.d.mts
73
- declare const statusCodes: {
74
- OK: number;
75
- CREATED: number;
76
- ACCEPTED: number;
77
- NO_CONTENT: number;
78
- MULTIPLE_CHOICES: number;
79
- MOVED_PERMANENTLY: number;
80
- FOUND: number;
81
- SEE_OTHER: number;
82
- NOT_MODIFIED: number;
83
- TEMPORARY_REDIRECT: number;
84
- BAD_REQUEST: number;
85
- UNAUTHORIZED: number;
86
- PAYMENT_REQUIRED: number;
87
- FORBIDDEN: number;
88
- NOT_FOUND: number;
89
- METHOD_NOT_ALLOWED: number;
90
- NOT_ACCEPTABLE: number;
91
- PROXY_AUTHENTICATION_REQUIRED: number;
92
- REQUEST_TIMEOUT: number;
93
- CONFLICT: number;
94
- GONE: number;
95
- LENGTH_REQUIRED: number;
96
- PRECONDITION_FAILED: number;
97
- PAYLOAD_TOO_LARGE: number;
98
- URI_TOO_LONG: number;
99
- UNSUPPORTED_MEDIA_TYPE: number;
100
- RANGE_NOT_SATISFIABLE: number;
101
- EXPECTATION_FAILED: number;
102
- "I'M_A_TEAPOT": number;
103
- MISDIRECTED_REQUEST: number;
104
- UNPROCESSABLE_ENTITY: number;
105
- LOCKED: number;
106
- FAILED_DEPENDENCY: number;
107
- TOO_EARLY: number;
108
- UPGRADE_REQUIRED: number;
109
- PRECONDITION_REQUIRED: number;
110
- TOO_MANY_REQUESTS: number;
111
- REQUEST_HEADER_FIELDS_TOO_LARGE: number;
112
- UNAVAILABLE_FOR_LEGAL_REASONS: number;
113
- INTERNAL_SERVER_ERROR: number;
114
- NOT_IMPLEMENTED: number;
115
- BAD_GATEWAY: number;
116
- SERVICE_UNAVAILABLE: number;
117
- GATEWAY_TIMEOUT: number;
118
- HTTP_VERSION_NOT_SUPPORTED: number;
119
- VARIANT_ALSO_NEGOTIATES: number;
120
- INSUFFICIENT_STORAGE: number;
121
- LOOP_DETECTED: number;
122
- NOT_EXTENDED: number;
123
- NETWORK_AUTHENTICATION_REQUIRED: number;
124
- };
125
- type Status = 100 | 101 | 102 | 103 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 226 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 421 | 422 | 423 | 424 | 425 | 426 | 428 | 429 | 431 | 451 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 510 | 511;
126
- declare class InternalAPIError extends Error {
127
- status: keyof typeof statusCodes | Status;
128
- body: ({
129
- message?: string;
130
- code?: string;
131
- cause?: unknown;
132
- } & Record<string, any>) | undefined;
133
- headers: HeadersInit;
134
- statusCode: number;
135
- constructor(status?: keyof typeof statusCodes | Status, body?: ({
136
- message?: string;
137
- code?: string;
138
- cause?: unknown;
139
- } & Record<string, any>) | undefined, headers?: HeadersInit, statusCode?: number);
140
- }
141
- type APIError = InstanceType<typeof InternalAPIError>;
142
- declare const APIError: new (status?: Status | "OK" | "CREATED" | "ACCEPTED" | "NO_CONTENT" | "MULTIPLE_CHOICES" | "MOVED_PERMANENTLY" | "FOUND" | "SEE_OTHER" | "NOT_MODIFIED" | "TEMPORARY_REDIRECT" | "BAD_REQUEST" | "UNAUTHORIZED" | "PAYMENT_REQUIRED" | "FORBIDDEN" | "NOT_FOUND" | "METHOD_NOT_ALLOWED" | "NOT_ACCEPTABLE" | "PROXY_AUTHENTICATION_REQUIRED" | "REQUEST_TIMEOUT" | "CONFLICT" | "GONE" | "LENGTH_REQUIRED" | "PRECONDITION_FAILED" | "PAYLOAD_TOO_LARGE" | "URI_TOO_LONG" | "UNSUPPORTED_MEDIA_TYPE" | "RANGE_NOT_SATISFIABLE" | "EXPECTATION_FAILED" | "I'M_A_TEAPOT" | "MISDIRECTED_REQUEST" | "UNPROCESSABLE_ENTITY" | "LOCKED" | "FAILED_DEPENDENCY" | "TOO_EARLY" | "UPGRADE_REQUIRED" | "PRECONDITION_REQUIRED" | "TOO_MANY_REQUESTS" | "REQUEST_HEADER_FIELDS_TOO_LARGE" | "UNAVAILABLE_FOR_LEGAL_REASONS" | "INTERNAL_SERVER_ERROR" | "NOT_IMPLEMENTED" | "BAD_GATEWAY" | "SERVICE_UNAVAILABLE" | "GATEWAY_TIMEOUT" | "HTTP_VERSION_NOT_SUPPORTED" | "VARIANT_ALSO_NEGOTIATES" | "INSUFFICIENT_STORAGE" | "LOOP_DETECTED" | "NOT_EXTENDED" | "NETWORK_AUTHENTICATION_REQUIRED" | undefined, body?: ({
143
- message?: string;
144
- code?: string;
145
- cause?: unknown;
146
- } & Record<string, any>) | undefined, headers?: HeadersInit | undefined, statusCode?: number | undefined) => InternalAPIError & {
147
- errorStack: string | undefined;
148
- }; //#endregion
149
- //#endregion
150
- //#region ../../node_modules/.pnpm/better-call@1.3.5_zod@4.3.6/node_modules/better-call/dist/cookies.d.mts
151
- //#region src/cookies.d.ts
152
- type CookiePrefixOptions = "host" | "secure";
153
- type CookieOptions = {
154
- /**
155
- * Domain of the cookie
156
- *
157
- * The Domain attribute specifies which server can receive a cookie. If specified, cookies are
158
- * available on the specified server and its subdomains. If the it is not
159
- * specified, the cookies are available on the server that sets it but not on
160
- * its subdomains.
161
- *
162
- * @example
163
- * `domain: "example.com"`
164
- */
165
- domain?: string;
166
- /**
167
- * A lifetime of a cookie. Permanent cookies are deleted after the date specified in the
168
- * Expires attribute:
169
- *
170
- * Expires has been available for longer than Max-Age, however Max-Age is less error-prone, and
171
- * takes precedence when both are set. The rationale behind this is that when you set an
172
- * Expires date and time, they're relative to the client the cookie is being set on. If the
173
- * server is set to a different time, this could cause errors
174
- */
175
- expires?: Date;
176
- /**
177
- * Forbids JavaScript from accessing the cookie, for example, through the Document.cookie
178
- * property. Note that a cookie that has been created with HttpOnly will still be sent with
179
- * JavaScript-initiated requests, for example, when calling XMLHttpRequest.send() or fetch().
180
- * This mitigates attacks against cross-site scripting
181
- */
182
- httpOnly?: boolean;
183
- /**
184
- * Indicates the number of seconds until the cookie expires. A zero or negative number will
185
- * expire the cookie immediately. If both Expires and Max-Age are set, Max-Age has precedence.
186
- *
187
- * @example 604800 - 7 days
188
- */
189
- maxAge?: number;
190
- /**
191
- * Indicates the path that must exist in the requested URL for the browser to send the Cookie
192
- * header.
193
- *
194
- * @example
195
- * "/docs"
196
- * // -> the request paths /docs, /docs/, /docs/Web/, and /docs/Web/HTTP will all match. the request paths /, /fr/docs will not match.
197
- */
198
- path?: string;
199
- /**
200
- * Indicates that the cookie is sent to the server only when a request is made with the https:
201
- * scheme (except on localhost), and therefore, is more resistant to man-in-the-middle attacks.
202
- */
203
- secure?: boolean;
204
- /**
205
- * Controls whether or not a cookie is sent with cross-site requests, providing some protection
206
- * against cross-site request forgery attacks (CSRF).
207
- *
208
- * Strict - Means that the browser sends the cookie only for same-site requests, that is,
209
- * requests originating from the same site that set the cookie. If a request originates from a
210
- * different domain or scheme (even with the same domain), no cookies with the SameSite=Strict
211
- * attribute are sent.
212
- *
213
- * Lax - Means that the cookie is not sent on cross-site requests, such as on requests to load
214
- * images or frames, but is sent when a user is navigating to the origin site from an external
215
- * site (for example, when following a link). This is the default behavior if the SameSite
216
- * attribute is not specified.
217
- *
218
- * None - Means that the browser sends the cookie with both cross-site and same-site requests.
219
- * The Secure attribute must also be set when setting this value.
220
- */
221
- sameSite?: "Strict" | "Lax" | "None" | "strict" | "lax" | "none";
222
- /**
223
- * Indicates that the cookie should be stored using partitioned storage. Note that if this is
224
- * set, the Secure directive must also be set.
225
- *
226
- * @see https://developer.mozilla.org/en-US/docs/Web/Privacy/Privacy_sandbox/Partitioned_cookies
227
- */
228
- partitioned?: boolean;
229
- /**
230
- * Cooke Prefix
231
- *
232
- * - secure: `__Secure-` -> `__Secure-cookie-name`
233
- * - host: `__Host-` -> `__Host-cookie-name`
234
- *
235
- * `secure` must be set to true to use prefixes
236
- */
237
- prefix?: CookiePrefixOptions;
238
- };
239
- //#endregion
240
- //#region ../../node_modules/.pnpm/better-call@1.3.5_zod@4.3.6/node_modules/better-call/dist/openapi.d.mts
241
- //#region src/openapi.d.ts
242
- type OpenAPISchemaType = "string" | "number" | "integer" | "boolean" | "array" | "object";
243
- interface OpenAPIParameter {
244
- in: "query" | "path" | "header" | "cookie";
245
- name?: string;
246
- description?: string;
247
- required?: boolean;
248
- schema?: {
249
- type: OpenAPISchemaType;
250
- format?: string | undefined;
251
- items?: {
252
- type: OpenAPISchemaType;
253
- };
254
- enum?: string[];
255
- minLength?: number;
256
- description?: string | undefined;
257
- default?: string | undefined;
258
- example?: string | undefined;
259
- };
260
- }
261
- //#endregion
262
- //#region ../../node_modules/.pnpm/better-call@1.3.5_zod@4.3.6/node_modules/better-call/dist/endpoint.d.mts
263
- //#region src/endpoint.d.ts
264
- interface EndpointBaseOptions {
265
- /**
266
- * Query Schema
267
- */
268
- query?: StandardSchemaV1;
269
- /**
270
- * Error Schema
271
- */
272
- error?: StandardSchemaV1;
273
- /**
274
- * If true headers will be required to be passed in the context
275
- */
276
- requireHeaders?: boolean;
277
- /**
278
- * If true request object will be required
279
- */
280
- requireRequest?: boolean;
281
- /**
282
- * Clone the request object from the router
283
- */
284
- cloneRequest?: boolean;
285
- /**
286
- * If true the body will be undefined
287
- */
288
- disableBody?: boolean;
289
- /**
290
- * Endpoint metadata
291
- */
292
- metadata?: {
293
- /**
294
- * Open API definition
295
- */
296
- openapi?: {
297
- summary?: string;
298
- description?: string;
299
- tags?: string[];
300
- operationId?: string;
301
- parameters?: OpenAPIParameter[];
302
- requestBody?: {
303
- content: {
304
- "application/json": {
305
- schema: {
306
- type?: OpenAPISchemaType;
307
- properties?: Record<string, any>;
308
- required?: string[];
309
- $ref?: string;
310
- };
311
- };
312
- };
313
- };
314
- responses?: {
315
- [status: string]: {
316
- description: string;
317
- content?: {
318
- "application/json"?: {
319
- schema: {
320
- type?: OpenAPISchemaType;
321
- properties?: Record<string, any>;
322
- required?: string[];
323
- $ref?: string;
324
- };
325
- };
326
- "text/plain"?: {
327
- schema?: {
328
- type?: OpenAPISchemaType;
329
- properties?: Record<string, any>;
330
- required?: string[];
331
- $ref?: string;
332
- };
333
- };
334
- "text/html"?: {
335
- schema?: {
336
- type?: OpenAPISchemaType;
337
- properties?: Record<string, any>;
338
- required?: string[];
339
- $ref?: string;
340
- };
341
- };
342
- };
343
- };
344
- };
345
- };
346
- /**
347
- * Infer body and query type from ts interface
348
- *
349
- * useful for generic and dynamic types
350
- *
351
- * @example
352
- * ```ts
353
- * const endpoint = createEndpoint("/path", {
354
- * method: "POST",
355
- * body: z.record(z.string()),
356
- * $Infer: {
357
- * body: {} as {
358
- * type: InferTypeFromOptions<Option> // custom type inference
359
- * }
360
- * }
361
- * }, async(ctx)=>{
362
- * const body = ctx.body
363
- * })
364
- * ```
365
- */
366
- $Infer?: {
367
- /**
368
- * Body
369
- */
370
- body?: any;
371
- /**
372
- * Query
373
- */
374
- query?: Record<string, any>;
375
- };
376
- /**
377
- * If enabled, endpoint won't be exposed over a router
378
- * @deprecated Use path-less endpoints instead
379
- */
380
- SERVER_ONLY?: boolean;
381
- /**
382
- * If enabled, endpoint won't be exposed as an action to the client
383
- * @deprecated Use path-less endpoints instead
384
- */
385
- isAction?: boolean;
386
- /**
387
- * Defines the places where the endpoint will be available
388
- *
389
- * Possible options:
390
- * - `rpc` - the endpoint is exposed to the router, can be invoked directly and is available to the client
391
- * - `server` - the endpoint is exposed to the router, can be invoked directly, but is not available to the client
392
- * - `http` - the endpoint is only exposed to the router
393
- * @default "rpc"
394
- */
395
- scope?: "rpc" | "server" | "http";
396
- /**
397
- * List of allowed media types (MIME types) for the endpoint
398
- *
399
- * if provided, only the media types in the list will be allowed to be passed in the body
400
- *
401
- * @example
402
- * ```ts
403
- * const endpoint = createEndpoint("/path", {
404
- * method: "POST",
405
- * allowedMediaTypes: ["application/json", "application/x-www-form-urlencoded"],
406
- * }, async(ctx)=>{
407
- * const body = ctx.body
408
- * })
409
- * ```
410
- */
411
- allowedMediaTypes?: string[];
412
- /**
413
- * Extra metadata
414
- */
415
- [key: string]: any;
416
- };
417
- /**
418
- * List of middlewares to use
419
- */
420
- use?: Middleware[];
421
- /**
422
- * A callback to run before any API error is throw or returned
423
- *
424
- * @param e - The API error
425
- * @returns - The response to return
426
- */
427
- onAPIError?: (e: APIError) => void | Promise<void>;
428
- /**
429
- * A callback to run before a validation error is thrown
430
- * You can customize the validation error message by throwing your own APIError
431
- */
432
- onValidationError?: ({
433
- issues,
434
- message
435
- }: {
436
- message: string;
437
- issues: readonly StandardSchemaV1.Issue[];
438
- }) => void | Promise<void>;
439
- }
440
- type EndpointBodyMethodOptions = {
441
- /**
442
- * Request Method
443
- */
444
- method: "POST" | "PUT" | "DELETE" | "PATCH" | ("POST" | "PUT" | "DELETE" | "PATCH")[];
445
- /**
446
- * Body Schema
447
- */
448
- body?: StandardSchemaV1;
449
- } | {
450
- /**
451
- * Request Method
452
- */
453
- method: "GET" | "HEAD" | ("GET" | "HEAD")[];
454
- /**
455
- * Body Schema
456
- */
457
- body?: never;
458
- } | {
459
- /**
460
- * Request Method
461
- */
462
- method: "*";
463
- /**
464
- * Body Schema
465
- */
466
- body?: StandardSchemaV1;
467
- } | {
468
- /**
469
- * Request Method
470
- */
471
- method: ("POST" | "PUT" | "DELETE" | "PATCH" | "GET" | "HEAD")[];
472
- /**
473
- * Body Schema
474
- */
475
- body?: StandardSchemaV1;
476
- };
477
- type EndpointOptions = EndpointBaseOptions & EndpointBodyMethodOptions;
478
- type EndpointContext<Path extends string, Options extends EndpointOptions, Context = {}> = {
479
- /**
480
- * Method
481
- *
482
- * The request method
483
- */
484
- method: InferMethod<Options>;
485
- /**
486
- * Path
487
- *
488
- * The path of the endpoint
489
- */
490
- path: Path;
491
- /**
492
- * Body
493
- *
494
- * The body object will be the parsed JSON from the request and validated
495
- * against the body schema if it exists.
496
- */
497
- body: InferBody<Options>;
498
- /**
499
- * Query
500
- *
501
- * The query object will be the parsed query string from the request
502
- * and validated against the query schema if it exists
503
- */
504
- query: InferQuery<Options>;
505
- /**
506
- * Params
507
- *
508
- * If the path is `/user/:id` and the request is `/user/1` then the params will
509
- * be `{ id: "1" }` and if the path includes a wildcard like `/user/*` then the
510
- * params will be `{ _: "1" }` where `_` is the wildcard key. If the wildcard
511
- * is named like `/user/**:name` then the params will be `{ name: string }`
512
- */
513
- params: InferParam<Path>;
514
- /**
515
- * Request object
516
- *
517
- * If `requireRequest` is set to true in the endpoint options this will be
518
- * required
519
- */
520
- request: InferRequest<Options>;
521
- /**
522
- * Headers
523
- *
524
- * If `requireHeaders` is set to true in the endpoint options this will be
525
- * required
526
- */
527
- headers: InferHeaders<Options>;
528
- /**
529
- * Set header
530
- *
531
- * If it's called outside of a request it will just be ignored.
532
- */
533
- setHeader: (key: string, value: string) => void;
534
- /**
535
- * Set the response status code
536
- */
537
- setStatus: (status: Status) => void;
538
- /**
539
- * Get header
540
- *
541
- * If it's called outside of a request it will just return null
542
- *
543
- * @param key - The key of the header
544
- * @returns
545
- */
546
- getHeader: (key: string) => string | null;
547
- /**
548
- * Get a cookie value from the request
549
- *
550
- * @param key - The key of the cookie
551
- * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
552
- * @returns - The value of the cookie
553
- */
554
- getCookie: (key: string, prefix?: CookiePrefixOptions) => string | null;
555
- /**
556
- * Get a signed cookie value from the request
557
- *
558
- * @param key - The key of the cookie
559
- * @param secret - The secret of the signed cookie
560
- * @param prefix - The prefix of the cookie between `__Secure-` and `__Host-`
561
- * @returns - The value of the cookie or null if the cookie is not found or false if the signature is invalid
562
- */
563
- getSignedCookie: (key: string, secret: string, prefix?: CookiePrefixOptions) => Promise<string | null | false>;
564
- /**
565
- * Set a cookie value in the response
566
- *
567
- * @param key - The key of the cookie
568
- * @param value - The value to set
569
- * @param options - The options of the cookie
570
- * @returns - The cookie string
571
- */
572
- setCookie: (key: string, value: string, options?: CookieOptions) => string;
573
- /**
574
- * Set signed cookie
575
- *
576
- * @param key - The key of the cookie
577
- * @param value - The value to set
578
- * @param secret - The secret to sign the cookie with
579
- * @param options - The options of the cookie
580
- * @returns - The cookie string
581
- */
582
- setSignedCookie: (key: string, value: string, secret: string, options?: CookieOptions) => Promise<string>;
583
- /**
584
- * JSON
585
- *
586
- * a helper function to create a JSON response with
587
- * the correct headers
588
- * and status code. If `asResponse` is set to true in
589
- * the context then
590
- * it will return a Response object instead of the
591
- * JSON object.
592
- *
593
- * @param json - The JSON object to return
594
- * @param routerResponse - The response object to
595
- * return if `asResponse` is
596
- * true in the context this will take precedence
597
- */
598
- json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
599
- status?: number;
600
- headers?: Record<string, string>;
601
- response?: Response;
602
- body?: Record<string, string>;
603
- } | Response) => Promise<R>;
604
- /**
605
- * Middleware context
606
- */
607
- context: Prettify<Context & InferUse<Options["use"]>>;
608
- /**
609
- * Redirect to a new URL
610
- */
611
- redirect: (url: string) => APIError;
612
- /**
613
- * Return error
614
- */
615
- error: (status: keyof typeof statusCodes | Status, body?: {
616
- message?: string;
617
- code?: string;
618
- } & Record<string, any>, headers?: HeadersInit) => APIError;
619
- };
620
- type StrictEndpoint<Path extends string, Options extends EndpointOptions, R = any> = {
621
- (context: InputContext<Path, Options> & {
622
- asResponse: true;
623
- }): Promise<Response>;
624
- (context: InputContext<Path, Options> & {
625
- returnHeaders: true;
626
- returnStatus: true;
627
- }): Promise<{
628
- headers: Headers;
629
- status: number;
630
- response: Awaited<R>;
631
- }>;
632
- (context: InputContext<Path, Options> & {
633
- returnHeaders: true;
634
- returnStatus: false;
635
- }): Promise<{
636
- headers: Headers;
637
- response: Awaited<R>;
638
- }>;
639
- (context: InputContext<Path, Options> & {
640
- returnHeaders: false;
641
- returnStatus: true;
642
- }): Promise<{
643
- status: number;
644
- response: Awaited<R>;
645
- }>;
646
- (context: InputContext<Path, Options> & {
647
- returnHeaders: false;
648
- returnStatus: false;
649
- }): Promise<R>;
650
- (context: InputContext<Path, Options> & {
651
- returnHeaders: true;
652
- }): Promise<{
653
- headers: Headers;
654
- response: Awaited<R>;
655
- }>;
656
- (context: InputContext<Path, Options> & {
657
- returnStatus: true;
658
- }): Promise<{
659
- status: number;
660
- response: Awaited<R>;
661
- }>;
662
- (context?: InputContext<Path, Options>): Promise<R>;
663
- options: Options;
664
- path: Path;
665
- };
666
- //#endregion
667
- //#region ../../node_modules/.pnpm/better-call@1.3.5_zod@4.3.6/node_modules/better-call/dist/middleware.d.mts
668
- //#region src/middleware.d.ts
669
- interface MiddlewareOptions extends Omit<EndpointOptions, "method"> {}
670
- type MiddlewareContext<Options extends MiddlewareOptions, Context = {}> = EndpointContext<string, Options & {
671
- method: "*";
672
- }> & {
673
- /**
674
- * Method
675
- *
676
- * The request method
677
- */
678
- method: string;
679
- /**
680
- * Path
681
- *
682
- * The path of the endpoint
683
- */
684
- path: string;
685
- /**
686
- * Body
687
- *
688
- * The body object will be the parsed JSON from the request and validated
689
- * against the body schema if it exists
690
- */
691
- body: InferMiddlewareBody<Options>;
692
- /**
693
- * Query
694
- *
695
- * The query object will be the parsed query string from the request
696
- * and validated against the query schema if it exists
697
- */
698
- query: InferMiddlewareQuery<Options>;
699
- /**
700
- * Params
701
- *
702
- * If the path is `/user/:id` and the request is `/user/1` then the
703
- * params will
704
- * be `{ id: "1" }` and if the path includes a wildcard like `/user/*`
705
- * then the
706
- * params will be `{ _: "1" }` where `_` is the wildcard key. If the
707
- * wildcard
708
- * is named like `/user/**:name` then the params will be `{ name: string }`
709
- */
710
- params: string;
711
- /**
712
- * Request object
713
- *
714
- * If `requireRequest` is set to true in the endpoint options this will be
715
- * required
716
- */
717
- request: InferRequest<Options>;
718
- /**
719
- * Headers
720
- *
721
- * If `requireHeaders` is set to true in the endpoint options this will be
722
- * required
723
- */
724
- headers: InferHeaders<Options>;
725
- /**
726
- * Set header
727
- *
728
- * If it's called outside of a request it will just be ignored.
729
- */
730
- setHeader: (key: string, value: string) => void;
731
- /**
732
- * Get header
733
- *
734
- * If it's called outside of a request it will just return null
735
- *
736
- * @param key - The key of the header
737
- * @returns
738
- */
739
- getHeader: (key: string) => string | null;
740
- /**
741
- * JSON
742
- *
743
- * a helper function to create a JSON response with
744
- * the correct headers
745
- * and status code. If `asResponse` is set to true in
746
- * the context then
747
- * it will return a Response object instead of the
748
- * JSON object.
749
- *
750
- * @param json - The JSON object to return
751
- * @param routerResponse - The response object to
752
- * return if `asResponse` is
753
- * true in the context this will take precedence
754
- */
755
- json: <R extends Record<string, any> | null>(json: R, routerResponse?: {
756
- status?: number;
757
- headers?: Record<string, string>;
758
- response?: Response;
759
- } | Response) => Promise<R>;
760
- /**
761
- * Middleware context
762
- */
763
- context: Prettify<Context>;
764
- };
765
- type MiddlewareInputContext<Options extends MiddlewareOptions> = InferBodyInput<Options> & InferQueryInput<Options> & InferRequestInput<Options> & InferHeadersInput<Options> & {
766
- asResponse?: boolean;
767
- returnHeaders?: boolean;
768
- use?: Middleware[];
769
- };
770
- type Middleware<Options extends MiddlewareOptions = MiddlewareOptions, Handler extends (inputCtx: any) => Promise<any> = any> = Handler & {
771
- options: Options;
772
- }; //#endregion
773
- //#endregion
774
- //#region ../../node_modules/.pnpm/better-call@1.3.5_zod@4.3.6/node_modules/better-call/dist/context.d.mts
775
- //#region src/context.d.ts
776
- type HTTPMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH";
777
- type Method = HTTPMethod | "*";
778
- type InferBodyInput<Options extends EndpointOptions | MiddlewareOptions, Body = (Options["metadata"] extends {
779
- $Infer: {
780
- body: infer B;
781
- };
782
- } ? B : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["body"]> : undefined)> = undefined extends Body ? {
783
- body?: Body;
784
- } : {
785
- body: Body;
786
- };
787
- type InferBody<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
788
- $Infer: {
789
- body: infer Body;
790
- };
791
- } ? Body : Options["body"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["body"]> : any;
792
- type InferQueryInput<Options extends EndpointOptions | MiddlewareOptions, Query = (Options["metadata"] extends {
793
- $Infer: {
794
- query: infer Query;
795
- };
796
- } ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferInput<Options["query"]> : Record<string, any> | undefined)> = undefined extends Query ? {
797
- query?: Query;
798
- } : {
799
- query: Query;
800
- };
801
- type InferQuery<Options extends EndpointOptions | MiddlewareOptions> = Options["metadata"] extends {
802
- $Infer: {
803
- query: infer Query;
804
- };
805
- } ? Query : Options["query"] extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<Options["query"]> : Record<string, any> | undefined;
806
- type InferMethod<Options extends EndpointOptions> = Options["method"] extends Array<Method> ? Options["method"][number] : Options["method"] extends "*" ? HTTPMethod : Options["method"];
807
- 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 ? {
808
- method?: Method;
809
- } : {
810
- method: Method;
811
- };
812
- 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>>;
813
- type InferParamInput<Path extends string> = [Path] extends [never] ? {
814
- params?: Record<string, any>;
815
- } : IsEmptyObject<InferParamPath<Path> & InferParamWildCard<Path>> extends true ? {
816
- params?: Record<string, any>;
817
- } : {
818
- params: Prettify<InferParamPath<Path> & InferParamWildCard<Path>>;
819
- };
820
- type InferRequest<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? Request : Request | undefined;
821
- type InferRequestInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireRequest"] extends true ? {
822
- request: Request;
823
- } : {
824
- request?: Request;
825
- };
826
- type InferHeaders<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? Headers : Headers | undefined;
827
- type InferHeadersInput<Option extends EndpointOptions | MiddlewareOptions> = Option["requireHeaders"] extends true ? {
828
- headers: HeadersInit;
829
- } : {
830
- headers?: HeadersInit;
831
- };
832
- type InferUse<Opts extends EndpointOptions["use"]> = Opts extends Middleware[] ? UnionToIntersection<Awaited<ReturnType<Opts[number]>>> : {};
833
- type InferMiddlewareBody<Options extends MiddlewareOptions> = Options["body"] extends StandardSchemaV1<infer T> ? T : any;
834
- type InferMiddlewareQuery<Options extends MiddlewareOptions> = Options["query"] extends StandardSchemaV1<infer T> ? T : Record<string, any> | undefined;
835
- type InputContext<Path extends string, Options extends EndpointOptions> = InferBodyInput<Options> & InferInputMethod<Options> & InferQueryInput<Options> & InferParamInput<Path> & InferRequestInput<Options> & InferHeadersInput<Options> & {
836
- asResponse?: boolean;
837
- returnHeaders?: boolean;
838
- returnStatus?: boolean;
839
- use?: Middleware[];
840
- path?: string;
841
- context?: Record<string, any>;
842
- };
843
- //#endregion
844
8
  //#region src/error-codes.d.ts
845
9
  declare const API_KEY_ERROR_CODES: {
846
10
  INVALID_METADATA_TYPE: better_auth0.RawError<"INVALID_METADATA_TYPE">;
@@ -925,7 +89,7 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
925
89
  hooks: {
926
90
  before: {
927
91
  matcher: (ctx: HookEndpointContext) => boolean;
928
- handler: (inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<{
92
+ handler: (inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
929
93
  user: {
930
94
  id: string;
931
95
  createdAt: Date;
@@ -946,7 +110,7 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
946
110
  expiresAt: Date;
947
111
  };
948
112
  } | {
949
- context: MiddlewareContext<MiddlewareOptions, {
113
+ context: better_call0.MiddlewareContext<better_call0.MiddlewareOptions, {
950
114
  returned?: unknown | undefined;
951
115
  responseHeaders?: Headers | undefined;
952
116
  } & better_auth0.PluginContext<better_auth0.BetterAuthOptions> & better_auth0.InfoContext & {
@@ -1034,7 +198,7 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
1034
198
  } & Omit<better_auth0.BetterAuthRateLimitOptions, "enabled" | "window" | "max" | "storage">;
1035
199
  adapter: better_auth0.DBAdapter<better_auth0.BetterAuthOptions>;
1036
200
  internalAdapter: better_auth0.InternalAdapter<better_auth0.BetterAuthOptions>;
1037
- createAuthCookie: (cookieName: string, overrideAttributes?: Partial<CookieOptions> | undefined) => better_auth0.BetterAuthCookie;
201
+ createAuthCookie: (cookieName: string, overrideAttributes?: Partial<better_call0.CookieOptions> | undefined) => better_auth0.BetterAuthCookie;
1038
202
  secret: string;
1039
203
  secretConfig: string | better_auth0.SecretConfig;
1040
204
  sessionConfig: {
@@ -1094,7 +258,7 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
1094
258
  *
1095
259
  * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/api-key#api-method-api-key-create)
1096
260
  */
1097
- createApiKey: StrictEndpoint<"/api-key/create", {
261
+ createApiKey: better_call0.StrictEndpoint<"/api-key/create", {
1098
262
  method: "POST";
1099
263
  body: zod.ZodObject<{
1100
264
  configId: zod.ZodOptional<zod.ZodString>;
@@ -1277,7 +441,7 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
1277
441
  *
1278
442
  * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/api-key#api-method-api-key-verify)
1279
443
  */
1280
- verifyApiKey: StrictEndpoint<string, {
444
+ verifyApiKey: better_call0.StrictEndpoint<string, {
1281
445
  method: "POST";
1282
446
  body: zod.ZodObject<{
1283
447
  configId: zod.ZodOptional<zod.ZodString>;
@@ -1326,13 +490,13 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
1326
490
  *
1327
491
  * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/api-key#api-method-api-key-get)
1328
492
  */
1329
- getApiKey: StrictEndpoint<"/api-key/get", {
493
+ getApiKey: better_call0.StrictEndpoint<"/api-key/get", {
1330
494
  method: "GET";
1331
495
  query: zod.ZodObject<{
1332
496
  configId: zod.ZodOptional<zod.ZodString>;
1333
497
  id: zod.ZodString;
1334
498
  }, zod_v4_core0.$strip>;
1335
- use: ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<{
499
+ use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
1336
500
  session: {
1337
501
  session: Record<string, any> & {
1338
502
  id: string;
@@ -1515,7 +679,7 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
1515
679
  *
1516
680
  * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/api-key#api-method-api-key-update)
1517
681
  */
1518
- updateApiKey: StrictEndpoint<"/api-key/update", {
682
+ updateApiKey: better_call0.StrictEndpoint<"/api-key/update", {
1519
683
  method: "POST";
1520
684
  body: zod.ZodObject<{
1521
685
  configId: zod.ZodOptional<zod.ZodString>;
@@ -1693,13 +857,13 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
1693
857
  *
1694
858
  * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/api-key#api-method-api-key-delete)
1695
859
  */
1696
- deleteApiKey: StrictEndpoint<"/api-key/delete", {
860
+ deleteApiKey: better_call0.StrictEndpoint<"/api-key/delete", {
1697
861
  method: "POST";
1698
862
  body: zod.ZodObject<{
1699
863
  configId: zod.ZodOptional<zod.ZodString>;
1700
864
  keyId: zod.ZodString;
1701
865
  }, zod_v4_core0.$strip>;
1702
- use: ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<{
866
+ use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
1703
867
  session: {
1704
868
  session: Record<string, any> & {
1705
869
  id: string;
@@ -1780,9 +944,9 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
1780
944
  *
1781
945
  * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/api-key#api-method-api-key-list)
1782
946
  */
1783
- listApiKeys: StrictEndpoint<"/api-key/list", {
947
+ listApiKeys: better_call0.StrictEndpoint<"/api-key/list", {
1784
948
  method: "GET";
1785
- use: ((inputContext: MiddlewareInputContext<MiddlewareOptions>) => Promise<{
949
+ use: ((inputContext: better_call0.MiddlewareInputContext<better_call0.MiddlewareOptions>) => Promise<{
1786
950
  session: {
1787
951
  session: Record<string, any> & {
1788
952
  id: string;
@@ -2001,7 +1165,7 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
2001
1165
  *
2002
1166
  * @see [Read our docs to learn more.](https://better-auth.com/docs/plugins/api-key#api-method-api-key-delete-all-expired-api-keys)
2003
1167
  */
2004
- deleteAllExpiredApiKeys: StrictEndpoint<string, {
1168
+ deleteAllExpiredApiKeys: better_call0.StrictEndpoint<string, {
2005
1169
  method: "POST";
2006
1170
  }, {
2007
1171
  success: boolean;
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
- import { i as API_KEY_ERROR_CODES, n as apiKey, r as defaultKeyHasher, t as API_KEY_TABLE_NAME } from "./index-CajK1bx0.mjs";
2
- import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-CCe5L05Y.mjs";
1
+ import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-BR70O3Q3.mjs";
2
+ import { i as API_KEY_ERROR_CODES, n as apiKey, r as defaultKeyHasher, t as API_KEY_TABLE_NAME } from "./index-CI6mGUwK.mjs";
3
3
  export { API_KEY_ERROR_CODES, API_KEY_TABLE_NAME, ApiKey, ApiKeyConfigurationOptions, ApiKeyOptions, apiKey, defaultKeyHasher };
package/dist/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-CwRZx9_C.mjs";
1
+ import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-D9MWdfX3.mjs";
2
2
  import { createAuthEndpoint, createAuthMiddleware } from "@better-auth/core/api";
3
3
  import { base64Url } from "@better-auth/utils/base64";
4
4
  import { createHash } from "@better-auth/utils/hash";
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-CCe5L05Y.mjs";
1
+ import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-BR70O3Q3.mjs";
2
2
  export { ApiKey, ApiKeyConfigurationOptions, ApiKeyOptions };
@@ -35,6 +35,6 @@ const API_KEY_ERROR_CODES = defineErrorCodes({
35
35
  });
36
36
  //#endregion
37
37
  //#region src/version.ts
38
- const PACKAGE_VERSION = "1.6.11";
38
+ const PACKAGE_VERSION = "1.6.12";
39
39
  //#endregion
40
40
  export { API_KEY_ERROR_CODES as n, PACKAGE_VERSION as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/api-key",
3
- "version": "1.6.11",
3
+ "version": "1.6.12",
4
4
  "description": "API Key plugin for Better Auth.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -61,13 +61,14 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "tsdown": "0.21.1",
64
- "@better-auth/core": "1.6.11",
65
- "better-auth": "1.6.11"
64
+ "@better-auth/core": "1.6.12",
65
+ "better-auth": "1.6.12"
66
66
  },
67
67
  "peerDependencies": {
68
- "@better-auth/utils": "0.4.0",
69
- "@better-auth/core": "^1.6.11",
70
- "better-auth": "^1.6.11"
68
+ "@better-auth/utils": "0.4.1",
69
+ "better-call": "1.3.5",
70
+ "@better-auth/core": "^1.6.12",
71
+ "better-auth": "^1.6.12"
71
72
  },
72
73
  "scripts": {
73
74
  "build": "tsdown",