@better-auth/api-key 1.5.0 → 1.5.1-beta.2

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/index.mjs CHANGED
@@ -9,10 +9,9 @@ import { mergeSchema } from "better-auth/db";
9
9
  import { APIError as APIError$1 } from "@better-auth/core/error";
10
10
  import { generateId } from "@better-auth/core/utils/id";
11
11
  import { safeJSONParse } from "@better-auth/core/utils/json";
12
- import * as z$1 from "zod";
12
+ import * as z from "zod";
13
13
  import { isDevelopment, isTest } from "@better-auth/core/env";
14
14
  import { isValidIP, normalizeIP } from "@better-auth/core/utils/ip";
15
- import * as z from "zod/v4";
16
15
  import { role } from "better-auth/plugins/access";
17
16
  import { parseJSON } from "better-auth/client";
18
17
 
@@ -576,21 +575,21 @@ function getIp(req, options) {
576
575
 
577
576
  //#endregion
578
577
  //#region src/routes/create-api-key.ts
579
- const createApiKeyBodySchema = z$1.object({
580
- configId: z$1.string().meta({ description: "The configuration ID to use for the API key. If not provided, the default configuration will be used." }).optional(),
581
- name: z$1.string().meta({ description: "Name of the Api Key" }).optional(),
582
- expiresIn: z$1.number().meta({ description: "Expiration time of the Api Key in seconds" }).min(1).optional().nullable().default(null),
583
- prefix: z$1.string().meta({ description: "Prefix of the Api Key" }).regex(/^[a-zA-Z0-9_-]+$/, { message: "Invalid prefix format, must be alphanumeric and contain only underscores and hyphens." }).optional(),
584
- remaining: z$1.number().meta({ description: "Remaining number of requests. Server side only" }).min(0).optional().nullable().default(null),
585
- metadata: z$1.any().optional(),
586
- refillAmount: z$1.number().meta({ description: "Amount to refill the remaining count of the Api Key. server-only. Eg: 100" }).min(1).optional(),
587
- refillInterval: z$1.number().meta({ description: "Interval to refill the Api Key in milliseconds. server-only. Eg: 1000" }).optional(),
588
- rateLimitTimeWindow: z$1.number().meta({ description: "The duration in milliseconds where each request is counted. Once the `maxRequests` is reached, the request will be rejected until the `timeWindow` has passed, at which point the `timeWindow` will be reset. server-only. Eg: 1000" }).optional(),
589
- rateLimitMax: z$1.number().meta({ description: "Maximum amount of requests allowed within a window. Once the `maxRequests` is reached, the request will be rejected until the `timeWindow` has passed, at which point the `timeWindow` will be reset. server-only. Eg: 100" }).optional(),
590
- rateLimitEnabled: z$1.boolean().meta({ description: "Whether the key has rate limiting enabled. server-only. Eg: true" }).optional(),
591
- permissions: z$1.record(z$1.string(), z$1.array(z$1.string())).meta({ description: "Permissions of the Api Key." }).optional(),
592
- userId: z$1.coerce.string().meta({ description: "User Id of the user that the Api Key belongs to. server-only. Eg: \"user-id\"" }).optional(),
593
- organizationId: z$1.coerce.string().meta({ description: "Organization Id of the organization that the Api Key belongs to. Eg: 'org-id'" }).optional()
578
+ const createApiKeyBodySchema = z.object({
579
+ configId: z.string().meta({ description: "The configuration ID to use for the API key. If not provided, the default configuration will be used." }).optional(),
580
+ name: z.string().meta({ description: "Name of the Api Key" }).optional(),
581
+ expiresIn: z.number().meta({ description: "Expiration time of the Api Key in seconds" }).min(1).optional().nullable().default(null),
582
+ prefix: z.string().meta({ description: "Prefix of the Api Key" }).regex(/^[a-zA-Z0-9_-]+$/, { message: "Invalid prefix format, must be alphanumeric and contain only underscores and hyphens." }).optional(),
583
+ remaining: z.number().meta({ description: "Remaining number of requests. Server side only" }).min(0).optional().nullable().default(null),
584
+ metadata: z.any().optional(),
585
+ refillAmount: z.number().meta({ description: "Amount to refill the remaining count of the Api Key. server-only. Eg: 100" }).min(1).optional(),
586
+ refillInterval: z.number().meta({ description: "Interval to refill the Api Key in milliseconds. server-only. Eg: 1000" }).optional(),
587
+ rateLimitTimeWindow: z.number().meta({ description: "The duration in milliseconds where each request is counted. Once the `maxRequests` is reached, the request will be rejected until the `timeWindow` has passed, at which point the `timeWindow` will be reset. server-only. Eg: 1000" }).optional(),
588
+ rateLimitMax: z.number().meta({ description: "Maximum amount of requests allowed within a window. Once the `maxRequests` is reached, the request will be rejected until the `timeWindow` has passed, at which point the `timeWindow` will be reset. server-only. Eg: 100" }).optional(),
589
+ rateLimitEnabled: z.boolean().meta({ description: "Whether the key has rate limiting enabled. server-only. Eg: true" }).optional(),
590
+ permissions: z.record(z.string(), z.array(z.string())).meta({ description: "Permissions of the Api Key." }).optional(),
591
+ userId: z.coerce.string().meta({ description: "User Id of the user that the Api Key belongs to. server-only. Eg: \"user-id\"" }).optional(),
592
+ organizationId: z.coerce.string().meta({ description: "Organization Id of the organization that the Api Key belongs to. Eg: 'org-id'" }).optional()
594
593
  });
595
594
  function createApiKey({ defaultKeyGenerator, configurations, schema, deleteAllExpiredApiKeys }) {
596
595
  return createAuthEndpoint("/api-key/create", {
@@ -880,9 +879,9 @@ function deleteAllExpiredApiKeysEndpoint({ deleteAllExpiredApiKeys }) {
880
879
 
881
880
  //#endregion
882
881
  //#region src/routes/delete-api-key.ts
883
- const deleteApiKeyBodySchema = z$1.object({
884
- configId: z$1.string().meta({ description: "The configuration ID to use for the API key lookup. If not provided, the default configuration will be used." }).optional(),
885
- keyId: z$1.string().meta({ description: "The id of the Api Key" })
882
+ const deleteApiKeyBodySchema = z.object({
883
+ configId: z.string().meta({ description: "The configuration ID to use for the API key lookup. If not provided, the default configuration will be used." }).optional(),
884
+ keyId: z.string().meta({ description: "The id of the Api Key" })
886
885
  });
887
886
  function deleteApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
888
887
  return createAuthEndpoint("/api-key/delete", {
@@ -951,9 +950,9 @@ function deleteApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
951
950
 
952
951
  //#endregion
953
952
  //#region src/routes/get-api-key.ts
954
- const getApiKeyQuerySchema = z$1.object({
955
- configId: z$1.string().meta({ description: "The configuration ID to use for the API key lookup. If not provided, the default configuration will be used." }).optional(),
956
- id: z$1.string().meta({ description: "The id of the Api Key" })
953
+ const getApiKeyQuerySchema = z.object({
954
+ configId: z.string().meta({ description: "The configuration ID to use for the API key lookup. If not provided, the default configuration will be used." }).optional(),
955
+ id: z.string().meta({ description: "The id of the Api Key" })
957
956
  });
958
957
  function getApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
959
958
  return createAuthEndpoint("/api-key/get", {
@@ -1340,21 +1339,21 @@ function listApiKeys({ configurations, schema, deleteAllExpiredApiKeys }) {
1340
1339
 
1341
1340
  //#endregion
1342
1341
  //#region src/routes/update-api-key.ts
1343
- const updateApiKeyBodySchema = z$1.object({
1344
- configId: z$1.string().meta({ description: "The configuration ID to use for the API key lookup. If not provided, the default configuration will be used." }).optional(),
1345
- keyId: z$1.string().meta({ description: "The id of the Api Key" }),
1346
- userId: z$1.coerce.string().meta({ description: "The id of the user which the api key belongs to. server-only. Eg: \"some-user-id\"" }).optional(),
1347
- name: z$1.string().meta({ description: "The name of the key" }).optional(),
1348
- enabled: z$1.boolean().meta({ description: "Whether the Api Key is enabled or not" }).optional(),
1349
- remaining: z$1.number().meta({ description: "The number of remaining requests" }).min(1).optional(),
1350
- refillAmount: z$1.number().meta({ description: "The refill amount" }).optional(),
1351
- refillInterval: z$1.number().meta({ description: "The refill interval" }).optional(),
1352
- metadata: z$1.any().optional(),
1353
- expiresIn: z$1.number().meta({ description: "Expiration time of the Api Key in seconds" }).min(1).optional().nullable(),
1354
- rateLimitEnabled: z$1.boolean().meta({ description: "Whether the key has rate limiting enabled." }).optional(),
1355
- rateLimitTimeWindow: z$1.number().meta({ description: "The duration in milliseconds where each request is counted. server-only. Eg: 1000" }).optional(),
1356
- rateLimitMax: z$1.number().meta({ description: "Maximum amount of requests allowed within a window. Once the `maxRequests` is reached, the request will be rejected until the `timeWindow` has passed, at which point the `timeWindow` will be reset. server-only. Eg: 100" }).optional(),
1357
- permissions: z$1.record(z$1.string(), z$1.array(z$1.string())).meta({ description: "Update the permissions on the API Key. server-only." }).optional().nullable()
1342
+ const updateApiKeyBodySchema = z.object({
1343
+ configId: z.string().meta({ description: "The configuration ID to use for the API key lookup. If not provided, the default configuration will be used." }).optional(),
1344
+ keyId: z.string().meta({ description: "The id of the Api Key" }),
1345
+ userId: z.coerce.string().meta({ description: "The id of the user which the api key belongs to. server-only. Eg: \"some-user-id\"" }).optional(),
1346
+ name: z.string().meta({ description: "The name of the key" }).optional(),
1347
+ enabled: z.boolean().meta({ description: "Whether the Api Key is enabled or not" }).optional(),
1348
+ remaining: z.number().meta({ description: "The number of remaining requests" }).min(1).optional(),
1349
+ refillAmount: z.number().meta({ description: "The refill amount" }).optional(),
1350
+ refillInterval: z.number().meta({ description: "The refill interval" }).optional(),
1351
+ metadata: z.any().optional(),
1352
+ expiresIn: z.number().meta({ description: "Expiration time of the Api Key in seconds" }).min(1).optional().nullable(),
1353
+ rateLimitEnabled: z.boolean().meta({ description: "Whether the key has rate limiting enabled." }).optional(),
1354
+ rateLimitTimeWindow: z.number().meta({ description: "The duration in milliseconds where each request is counted. server-only. Eg: 1000" }).optional(),
1355
+ rateLimitMax: z.number().meta({ description: "Maximum amount of requests allowed within a window. Once the `maxRequests` is reached, the request will be rejected until the `timeWindow` has passed, at which point the `timeWindow` will be reset. server-only. Eg: 100" }).optional(),
1356
+ permissions: z.record(z.string(), z.array(z.string())).meta({ description: "Update the permissions on the API Key. server-only." }).optional().nullable()
1358
1357
  });
1359
1358
  function updateApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
1360
1359
  return createAuthEndpoint("/api-key/update", {
@@ -1783,10 +1782,10 @@ async function validateApiKey({ hashedKey, ctx, opts, schema, permissions }) {
1783
1782
  }
1784
1783
  return newApiKey;
1785
1784
  }
1786
- const verifyApiKeyBodySchema = z$1.object({
1787
- configId: z$1.string().meta({ description: "The configuration ID to use for verification. If not provided, the default configuration will be used." }).optional(),
1788
- key: z$1.string().meta({ description: "The key to verify" }),
1789
- permissions: z$1.record(z$1.string(), z$1.array(z$1.string())).meta({ description: "The permissions to verify." }).optional()
1785
+ const verifyApiKeyBodySchema = z.object({
1786
+ configId: z.string().meta({ description: "The configuration ID to use for verification. If not provided, the default configuration will be used." }).optional(),
1787
+ key: z.string().meta({ description: "The key to verify" }),
1788
+ permissions: z.record(z.string(), z.array(z.string())).meta({ description: "The permissions to verify." }).optional()
1790
1789
  });
1791
1790
  function verifyApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
1792
1791
  return createAuthEndpoint({