@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/client.d.mts +2 -4
- package/dist/index-CP8iCAEj.d.mts +1308 -0
- package/dist/index.d.mts +3 -1268
- package/dist/index.mjs +41 -42
- package/dist/index.mjs.map +1 -1
- package/dist/types-CCe5L05Y.d.mts +555 -0
- package/dist/types.d.mts +2 -358
- package/package.json +6 -6
- package/dist/error-codes-xCoIeQ-k.d.mts +0 -50
- package/dist/schema-D2f7--fy.d.mts +0 -201
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
|
|
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
|
|
580
|
-
configId: z
|
|
581
|
-
name: z
|
|
582
|
-
expiresIn: z
|
|
583
|
-
prefix: z
|
|
584
|
-
remaining: z
|
|
585
|
-
metadata: z
|
|
586
|
-
refillAmount: z
|
|
587
|
-
refillInterval: z
|
|
588
|
-
rateLimitTimeWindow: z
|
|
589
|
-
rateLimitMax: z
|
|
590
|
-
rateLimitEnabled: z
|
|
591
|
-
permissions: z
|
|
592
|
-
userId: z
|
|
593
|
-
organizationId: z
|
|
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
|
|
884
|
-
configId: z
|
|
885
|
-
keyId: z
|
|
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
|
|
955
|
-
configId: z
|
|
956
|
-
id: z
|
|
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
|
|
1344
|
-
configId: z
|
|
1345
|
-
keyId: z
|
|
1346
|
-
userId: z
|
|
1347
|
-
name: z
|
|
1348
|
-
enabled: z
|
|
1349
|
-
remaining: z
|
|
1350
|
-
refillAmount: z
|
|
1351
|
-
refillInterval: z
|
|
1352
|
-
metadata: z
|
|
1353
|
-
expiresIn: z
|
|
1354
|
-
rateLimitEnabled: z
|
|
1355
|
-
rateLimitTimeWindow: z
|
|
1356
|
-
rateLimitMax: z
|
|
1357
|
-
permissions: z
|
|
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
|
|
1787
|
-
configId: z
|
|
1788
|
-
key: z
|
|
1789
|
-
permissions: z
|
|
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({
|