@better-auth/api-key 1.5.6 → 1.6.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client.d.mts +3 -3
- package/dist/client.mjs +2 -4
- package/dist/index-QFsA1o28.d.mts +1966 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +3 -18
- package/dist/types-CCe5L05Y.d.mts +1 -2
- package/dist/types.mjs +1 -1
- package/dist/{error-codes-vwTWW2ez.mjs → version-CvcHiYgF.mjs} +4 -4
- package/package.json +9 -8
- package/dist/client.mjs.map +0 -1
- package/dist/error-codes-vwTWW2ez.mjs.map +0 -1
- package/dist/index-CLXIQyX5.d.mts +0 -1300
- package/dist/index.mjs.map +0 -1
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-QFsA1o28.mjs";
|
|
1
2
|
import { n as ApiKeyConfigurationOptions, r as ApiKeyOptions, t as ApiKey } from "./types-CCe5L05Y.mjs";
|
|
2
|
-
import { i as API_KEY_ERROR_CODES, n as apiKey, r as defaultKeyHasher, t as API_KEY_TABLE_NAME } from "./index-CLXIQyX5.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 {
|
|
1
|
+
import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-CvcHiYgF.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";
|
|
@@ -14,7 +14,6 @@ import { isDevelopment, isTest } from "@better-auth/core/env";
|
|
|
14
14
|
import { isValidIP, normalizeIP } from "@better-auth/core/utils/ip";
|
|
15
15
|
import { role } from "better-auth/plugins/access";
|
|
16
16
|
import { parseJSON } from "better-auth/client";
|
|
17
|
-
|
|
18
17
|
//#region src/adapter.ts
|
|
19
18
|
/**
|
|
20
19
|
* Parses double-stringified metadata synchronously without updating the database.
|
|
@@ -477,7 +476,6 @@ async function listApiKeys$1(ctx, referenceId, opts, paginationOpts) {
|
|
|
477
476
|
total
|
|
478
477
|
};
|
|
479
478
|
}
|
|
480
|
-
|
|
481
479
|
//#endregion
|
|
482
480
|
//#region src/org-authorization.ts
|
|
483
481
|
/**
|
|
@@ -549,7 +547,6 @@ async function checkPermission(ctx, role, organizationId, action, orgOptions) {
|
|
|
549
547
|
return false;
|
|
550
548
|
}
|
|
551
549
|
}
|
|
552
|
-
|
|
553
550
|
//#endregion
|
|
554
551
|
//#region src/utils.ts
|
|
555
552
|
const getDate = (span, unit = "ms") => {
|
|
@@ -573,7 +570,6 @@ function getIp(req, options) {
|
|
|
573
570
|
if (isTest() || isDevelopment()) return LOCALHOST_IP;
|
|
574
571
|
return null;
|
|
575
572
|
}
|
|
576
|
-
|
|
577
573
|
//#endregion
|
|
578
574
|
//#region src/routes/create-api-key.ts
|
|
579
575
|
const createApiKeyBodySchema = z.object({
|
|
@@ -839,7 +835,7 @@ function createApiKey({ defaultKeyGenerator, configurations, schema, deleteAllEx
|
|
|
839
835
|
});
|
|
840
836
|
await setApiKey(ctx, apiKey, opts);
|
|
841
837
|
} else if (opts.storage === "secondary-storage") {
|
|
842
|
-
const id = ctx.context.generateId({ model:
|
|
838
|
+
const id = ctx.context.generateId({ model: "apikey" }) || generateId();
|
|
843
839
|
apiKey = {
|
|
844
840
|
...data,
|
|
845
841
|
id
|
|
@@ -857,7 +853,6 @@ function createApiKey({ defaultKeyGenerator, configurations, schema, deleteAllEx
|
|
|
857
853
|
});
|
|
858
854
|
});
|
|
859
855
|
}
|
|
860
|
-
|
|
861
856
|
//#endregion
|
|
862
857
|
//#region src/routes/delete-all-expired-api-keys.ts
|
|
863
858
|
function deleteAllExpiredApiKeysEndpoint({ deleteAllExpiredApiKeys }) {
|
|
@@ -877,7 +872,6 @@ function deleteAllExpiredApiKeysEndpoint({ deleteAllExpiredApiKeys }) {
|
|
|
877
872
|
});
|
|
878
873
|
});
|
|
879
874
|
}
|
|
880
|
-
|
|
881
875
|
//#endregion
|
|
882
876
|
//#region src/routes/delete-api-key.ts
|
|
883
877
|
const deleteApiKeyBodySchema = z.object({
|
|
@@ -948,7 +942,6 @@ function deleteApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
|
|
|
948
942
|
return ctx.json({ success: true });
|
|
949
943
|
});
|
|
950
944
|
}
|
|
951
|
-
|
|
952
945
|
//#endregion
|
|
953
946
|
//#region src/routes/get-api-key.ts
|
|
954
947
|
const getApiKeyQuerySchema = z.object({
|
|
@@ -1101,7 +1094,6 @@ function getApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
|
|
|
1101
1094
|
});
|
|
1102
1095
|
});
|
|
1103
1096
|
}
|
|
1104
|
-
|
|
1105
1097
|
//#endregion
|
|
1106
1098
|
//#region src/routes/list-api-keys.ts
|
|
1107
1099
|
/**
|
|
@@ -1337,7 +1329,6 @@ function listApiKeys({ configurations, schema, deleteAllExpiredApiKeys }) {
|
|
|
1337
1329
|
});
|
|
1338
1330
|
});
|
|
1339
1331
|
}
|
|
1340
|
-
|
|
1341
1332
|
//#endregion
|
|
1342
1333
|
//#region src/routes/update-api-key.ts
|
|
1343
1334
|
const updateApiKeyBodySchema = z.object({
|
|
@@ -1577,7 +1568,6 @@ function updateApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
|
|
|
1577
1568
|
});
|
|
1578
1569
|
});
|
|
1579
1570
|
}
|
|
1580
|
-
|
|
1581
1571
|
//#endregion
|
|
1582
1572
|
//#region src/rate-limit.ts
|
|
1583
1573
|
/**
|
|
@@ -1646,7 +1636,6 @@ function isRateLimited(apiKey, opts) {
|
|
|
1646
1636
|
}
|
|
1647
1637
|
};
|
|
1648
1638
|
}
|
|
1649
|
-
|
|
1650
1639
|
//#endregion
|
|
1651
1640
|
//#region src/routes/verify-api-key.ts
|
|
1652
1641
|
async function validateApiKey({ hashedKey, ctx, opts, schema, permissions }) {
|
|
@@ -1859,7 +1848,6 @@ function verifyApiKey({ configurations, schema, deleteAllExpiredApiKeys }) {
|
|
|
1859
1848
|
});
|
|
1860
1849
|
});
|
|
1861
1850
|
}
|
|
1862
|
-
|
|
1863
1851
|
//#endregion
|
|
1864
1852
|
//#region src/routes/index.ts
|
|
1865
1853
|
function resolveConfiguration(authContext, configurations, configId) {
|
|
@@ -1951,7 +1939,6 @@ function createApiKeyRoutes({ defaultKeyGenerator, configurations, schema }) {
|
|
|
1951
1939
|
deleteAllExpiredApiKeys: deleteAllExpiredApiKeysEndpoint({ deleteAllExpiredApiKeys })
|
|
1952
1940
|
};
|
|
1953
1941
|
}
|
|
1954
|
-
|
|
1955
1942
|
//#endregion
|
|
1956
1943
|
//#region src/schema.ts
|
|
1957
1944
|
const apiKeySchema = ({ defaultRateLimitMax, defaultTimeWindow }) => ({ apikey: { fields: {
|
|
@@ -2079,7 +2066,6 @@ const apiKeySchema = ({ defaultRateLimitMax, defaultTimeWindow }) => ({ apikey:
|
|
|
2079
2066
|
}
|
|
2080
2067
|
}
|
|
2081
2068
|
} } });
|
|
2082
|
-
|
|
2083
2069
|
//#endregion
|
|
2084
2070
|
//#region src/index.ts
|
|
2085
2071
|
const defaultKeyHasher = async (key) => {
|
|
@@ -2163,6 +2149,7 @@ function apiKey(_configurations, _options) {
|
|
|
2163
2149
|
});
|
|
2164
2150
|
return {
|
|
2165
2151
|
id: "api-key",
|
|
2152
|
+
version: PACKAGE_VERSION,
|
|
2166
2153
|
$ERROR_CODES: API_KEY_ERROR_CODES,
|
|
2167
2154
|
hooks: { before: [{
|
|
2168
2155
|
matcher: (ctx) => !!findApiKeyAndConfig(ctx),
|
|
@@ -2225,7 +2212,5 @@ function apiKey(_configurations, _options) {
|
|
|
2225
2212
|
schema
|
|
2226
2213
|
};
|
|
2227
2214
|
}
|
|
2228
|
-
|
|
2229
2215
|
//#endregion
|
|
2230
2216
|
export { API_KEY_ERROR_CODES, API_KEY_TABLE_NAME, apiKey, defaultKeyHasher };
|
|
2231
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -551,5 +551,4 @@ type ApiKey = {
|
|
|
551
551
|
} | null) | undefined;
|
|
552
552
|
};
|
|
553
553
|
//#endregion
|
|
554
|
-
export { ApiKeyConfigurationOptions as n, ApiKeyOptions as r, ApiKey as t };
|
|
555
|
-
//# sourceMappingURL=types-CCe5L05Y.d.mts.map
|
|
554
|
+
export { ApiKeyConfigurationOptions as n, ApiKeyOptions as r, ApiKey as t };
|
package/dist/types.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { defineErrorCodes } from "@better-auth/core/utils/error-codes";
|
|
2
|
-
|
|
3
2
|
//#region src/error-codes.ts
|
|
4
3
|
const API_KEY_ERROR_CODES = defineErrorCodes({
|
|
5
4
|
INVALID_METADATA_TYPE: "metadata must be an object or undefined",
|
|
@@ -34,7 +33,8 @@ const API_KEY_ERROR_CODES = defineErrorCodes({
|
|
|
34
33
|
NO_DEFAULT_API_KEY_CONFIGURATION_FOUND: "No default api-key configuration found.",
|
|
35
34
|
ORGANIZATION_PLUGIN_REQUIRED: "Organization plugin is required for organization-owned API keys. Please install and configure the organization plugin."
|
|
36
35
|
});
|
|
37
|
-
|
|
38
36
|
//#endregion
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
//#region src/version.ts
|
|
38
|
+
const PACKAGE_VERSION = "1.6.0-beta.0";
|
|
39
|
+
//#endregion
|
|
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.
|
|
3
|
+
"version": "1.6.0-beta.0",
|
|
4
4
|
"description": "API Key plugin for Better Auth.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
+
"sideEffects": false,
|
|
22
23
|
"files": [
|
|
23
24
|
"dist"
|
|
24
25
|
],
|
|
@@ -59,19 +60,19 @@
|
|
|
59
60
|
"zod": "^4.3.6"
|
|
60
61
|
},
|
|
61
62
|
"devDependencies": {
|
|
62
|
-
"tsdown": "0.21.
|
|
63
|
-
"@better-auth/core": "1.
|
|
64
|
-
"better-auth": "1.
|
|
63
|
+
"tsdown": "0.21.1",
|
|
64
|
+
"@better-auth/core": "1.6.0-beta.0",
|
|
65
|
+
"better-auth": "1.6.0-beta.0"
|
|
65
66
|
},
|
|
66
67
|
"peerDependencies": {
|
|
67
|
-
"@better-auth/utils": "0.
|
|
68
|
-
"@better-auth/core": "1.
|
|
69
|
-
"better-auth": "1.
|
|
68
|
+
"@better-auth/utils": "0.4.0",
|
|
69
|
+
"@better-auth/core": "^1.6.0-beta.0",
|
|
70
|
+
"better-auth": "^1.6.0-beta.0"
|
|
70
71
|
},
|
|
71
72
|
"scripts": {
|
|
72
73
|
"build": "tsdown",
|
|
73
74
|
"dev": "tsdown --watch",
|
|
74
|
-
"lint:package": "publint run --strict",
|
|
75
|
+
"lint:package": "publint run --strict --pack false",
|
|
75
76
|
"lint:types": "attw --profile esm-only --pack .",
|
|
76
77
|
"typecheck": "tsc --project tsconfig.json",
|
|
77
78
|
"test": "vitest",
|
package/dist/client.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.mjs","names":[],"sources":["../src/client.ts"],"sourcesContent":["import type { BetterAuthClientPlugin } from \"@better-auth/core\";\nimport type { apiKey } from \".\";\nimport { API_KEY_ERROR_CODES } from \"./error-codes\";\n\nexport * from \"./error-codes\";\n\nexport const apiKeyClient = () => {\n\treturn {\n\t\tid: \"api-key\",\n\t\t$InferServerPlugin: {} as ReturnType<typeof apiKey>,\n\t\tpathMethods: {\n\t\t\t\"/api-key/create\": \"POST\",\n\t\t\t\"/api-key/delete\": \"POST\",\n\t\t\t\"/api-key/delete-all-expired-api-keys\": \"POST\",\n\t\t},\n\t\t$ERROR_CODES: API_KEY_ERROR_CODES,\n\t} satisfies BetterAuthClientPlugin;\n};\n\nexport type ApiKeyClientPlugin = ReturnType<typeof apiKeyClient>;\n\nexport type * from \"./types\";\n"],"mappings":";;;AAMA,MAAa,qBAAqB;AACjC,QAAO;EACN,IAAI;EACJ,oBAAoB,EAAE;EACtB,aAAa;GACZ,mBAAmB;GACnB,mBAAmB;GACnB,wCAAwC;GACxC;EACD,cAAc;EACd"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"error-codes-vwTWW2ez.mjs","names":[],"sources":["../src/error-codes.ts"],"sourcesContent":["import { defineErrorCodes } from \"@better-auth/core/utils/error-codes\";\n\nexport const API_KEY_ERROR_CODES = defineErrorCodes({\n\tINVALID_METADATA_TYPE: \"metadata must be an object or undefined\",\n\tREFILL_AMOUNT_AND_INTERVAL_REQUIRED:\n\t\t\"refillAmount is required when refillInterval is provided\",\n\tREFILL_INTERVAL_AND_AMOUNT_REQUIRED:\n\t\t\"refillInterval is required when refillAmount is provided\",\n\tUSER_BANNED: \"User is banned\",\n\tUNAUTHORIZED_SESSION: \"Unauthorized or invalid session\",\n\tKEY_NOT_FOUND: \"API Key not found\",\n\tKEY_DISABLED: \"API Key is disabled\",\n\tKEY_EXPIRED: \"API Key has expired\",\n\tUSAGE_EXCEEDED: \"API Key has reached its usage limit\",\n\tKEY_NOT_RECOVERABLE: \"API Key is not recoverable\",\n\tEXPIRES_IN_IS_TOO_SMALL:\n\t\t\"The expiresIn is smaller than the predefined minimum value.\",\n\tEXPIRES_IN_IS_TOO_LARGE:\n\t\t\"The expiresIn is larger than the predefined maximum value.\",\n\tINVALID_REMAINING: \"The remaining count is either too large or too small.\",\n\tINVALID_PREFIX_LENGTH: \"The prefix length is either too large or too small.\",\n\tINVALID_NAME_LENGTH: \"The name length is either too large or too small.\",\n\tMETADATA_DISABLED: \"Metadata is disabled.\",\n\tRATE_LIMIT_EXCEEDED: \"Rate limit exceeded.\",\n\tNO_VALUES_TO_UPDATE: \"No values to update.\",\n\tKEY_DISABLED_EXPIRATION: \"Custom key expiration values are disabled.\",\n\tINVALID_API_KEY: \"Invalid API key.\",\n\tINVALID_USER_ID_FROM_API_KEY: \"The user id from the API key is invalid.\",\n\tINVALID_REFERENCE_ID_FROM_API_KEY:\n\t\t\"The reference id from the API key is invalid.\",\n\tINVALID_API_KEY_GETTER_RETURN_TYPE:\n\t\t\"API Key getter returned an invalid key type. Expected string.\",\n\tSERVER_ONLY_PROPERTY:\n\t\t\"The property you're trying to set can only be set from the server auth instance only.\",\n\tFAILED_TO_UPDATE_API_KEY: \"Failed to update API key\",\n\tNAME_REQUIRED: \"API Key name is required.\",\n\tORGANIZATION_ID_REQUIRED:\n\t\t\"Organization ID is required for organization-owned API keys.\",\n\tUSER_NOT_MEMBER_OF_ORGANIZATION:\n\t\t\"You are not a member of the organization that owns this API key.\",\n\tINSUFFICIENT_API_KEY_PERMISSIONS:\n\t\t\"You do not have permission to perform this action on organization API keys.\",\n\tNO_DEFAULT_API_KEY_CONFIGURATION_FOUND:\n\t\t\"No default api-key configuration found.\",\n\tORGANIZATION_PLUGIN_REQUIRED:\n\t\t\"Organization plugin is required for organization-owned API keys. Please install and configure the organization plugin.\",\n});\n"],"mappings":";;;AAEA,MAAa,sBAAsB,iBAAiB;CACnD,uBAAuB;CACvB,qCACC;CACD,qCACC;CACD,aAAa;CACb,sBAAsB;CACtB,eAAe;CACf,cAAc;CACd,aAAa;CACb,gBAAgB;CAChB,qBAAqB;CACrB,yBACC;CACD,yBACC;CACD,mBAAmB;CACnB,uBAAuB;CACvB,qBAAqB;CACrB,mBAAmB;CACnB,qBAAqB;CACrB,qBAAqB;CACrB,yBAAyB;CACzB,iBAAiB;CACjB,8BAA8B;CAC9B,mCACC;CACD,oCACC;CACD,sBACC;CACD,0BAA0B;CAC1B,eAAe;CACf,0BACC;CACD,iCACC;CACD,kCACC;CACD,wCACC;CACD,8BACC;CACD,CAAC"}
|