@better-auth/api-key 1.7.0-beta.4 → 1.7.0-beta.5

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
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";
2
+ import { i as API_KEY_ERROR_CODES, n as apiKey } from "./index-BWgvCest.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-L3icplj1.mjs";
1
+ import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-DsrnkkeB.mjs";
2
2
  //#region src/client.ts
3
3
  const apiKeyClient = () => {
4
4
  return {
@@ -187,7 +187,7 @@ declare function apiKey(_configurations?: (ApiKeyConfigurationOptions & ApiKeyOp
187
187
  image?: string | null | undefined;
188
188
  } & Record<string, any>;
189
189
  } | null) => void;
190
- socialProviders: better_auth0.OAuthProvider[];
190
+ socialProviders: better_auth0.UpstreamProvider[];
191
191
  authCookies: better_auth0.BetterAuthCookies;
192
192
  logger: ReturnType<typeof better_auth0.createLogger>;
193
193
  rateLimit: {
package/dist/index.d.mts CHANGED
@@ -1,3 +1,3 @@
1
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";
2
+ import { i as API_KEY_ERROR_CODES, n as apiKey, r as defaultKeyHasher, t as API_KEY_TABLE_NAME } from "./index-BWgvCest.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-L3icplj1.mjs";
1
+ import { n as API_KEY_ERROR_CODES, t as PACKAGE_VERSION } from "./version-DsrnkkeB.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";
@@ -720,7 +720,7 @@ function createApiKey({ defaultKeyGenerator, configurations, schema, deleteAllEx
720
720
  const { configId, name, expiresIn, prefix, remaining, metadata, refillAmount, refillInterval, permissions, rateLimitMax, rateLimitTimeWindow, rateLimitEnabled } = ctx.body;
721
721
  const opts = resolveConfiguration(ctx.context, configurations, configId);
722
722
  const keyGenerator = opts.customKeyGenerator || defaultKeyGenerator;
723
- const session = await getSessionFromCtx(ctx);
723
+ const session = await getSessionFromCtx(ctx, { disableCookieCache: true });
724
724
  const isClientRequest = ctx.request || ctx.headers;
725
725
  if (isClientRequest && (refillAmount !== void 0 || refillInterval !== void 0 || rateLimitMax !== void 0 || rateLimitTimeWindow !== void 0 || rateLimitEnabled !== void 0 || permissions !== void 0 || remaining !== null)) throw APIError$1.from("BAD_REQUEST", API_KEY_ERROR_CODES.SERVER_ONLY_PROPERTY);
726
726
  if (ctx.request && ctx.body.userId !== void 0) throw APIError$1.from("UNAUTHORIZED", API_KEY_ERROR_CODES.UNAUTHORIZED_SESSION);
@@ -1633,7 +1633,8 @@ function isRateLimited(apiKey, opts) {
1633
1633
  //#endregion
1634
1634
  //#region src/routes/verify-api-key.ts
1635
1635
  async function validateApiKey({ key, ctx, lookupOpts, configurations, schema, permissions, expectedConfigId, runCustomValidator }) {
1636
- const apiKey = await getApiKey$1(ctx, lookupOpts.disableKeyHashing ? key : await defaultKeyHasher(key), lookupOpts);
1636
+ const hashedKey = lookupOpts.disableKeyHashing ? key : await defaultKeyHasher(key);
1637
+ const apiKey = await getApiKey$1(ctx, hashedKey, lookupOpts);
1637
1638
  if (!apiKey) throw APIError$1.from("UNAUTHORIZED", API_KEY_ERROR_CODES.INVALID_API_KEY);
1638
1639
  if (expectedConfigId !== void 0 && !configIdMatches(apiKey.configId, expectedConfigId)) throw APIError$1.from("UNAUTHORIZED", API_KEY_ERROR_CODES.INVALID_API_KEY);
1639
1640
  const opts = resolveConfiguration(ctx.context, configurations, apiKey.configId);
@@ -1724,13 +1725,16 @@ async function validateApiKey({ key, ctx, lookupOpts, configurations, schema, pe
1724
1725
  code: "RATE_LIMITED",
1725
1726
  details: { tryAgainIn }
1726
1727
  });
1727
- const updated = {
1728
- ...apiKey,
1728
+ const mutations = {
1729
1729
  ...update,
1730
1730
  remaining,
1731
1731
  lastRefillAt,
1732
1732
  updatedAt: /* @__PURE__ */ new Date()
1733
1733
  };
1734
+ const updated = {
1735
+ ...apiKey,
1736
+ ...mutations
1737
+ };
1734
1738
  const performUpdate = async () => {
1735
1739
  if (opts.storage === "database") return ctx.context.adapter.update({
1736
1740
  model: API_KEY_TABLE_NAME,
@@ -1738,10 +1742,7 @@ async function validateApiKey({ key, ctx, lookupOpts, configurations, schema, pe
1738
1742
  field: "id",
1739
1743
  value: apiKey.id
1740
1744
  }],
1741
- update: {
1742
- ...updated,
1743
- id: void 0
1744
- }
1745
+ update: mutations
1745
1746
  });
1746
1747
  else if (opts.storage === "secondary-storage" && opts.fallbackToDatabase) {
1747
1748
  const dbUpdated = await ctx.context.adapter.update({
@@ -1750,16 +1751,19 @@ async function validateApiKey({ key, ctx, lookupOpts, configurations, schema, pe
1750
1751
  field: "id",
1751
1752
  value: apiKey.id
1752
1753
  }],
1753
- update: {
1754
- ...updated,
1755
- id: void 0
1756
- }
1754
+ update: mutations
1757
1755
  });
1758
1756
  if (dbUpdated) await setApiKey(ctx, dbUpdated, opts);
1759
1757
  return dbUpdated;
1760
1758
  } else {
1761
- await setApiKey(ctx, updated, opts);
1762
- return updated;
1759
+ const fresh = await getApiKey$1(ctx, hashedKey, opts);
1760
+ if (!fresh) return null;
1761
+ const merged = {
1762
+ ...fresh,
1763
+ ...mutations
1764
+ };
1765
+ await setApiKey(ctx, merged, opts);
1766
+ return merged;
1763
1767
  }
1764
1768
  };
1765
1769
  let newApiKey = null;
@@ -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.7.0-beta.4";
38
+ const PACKAGE_VERSION = "1.7.0-beta.5";
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.7.0-beta.4",
3
+ "version": "1.7.0-beta.5",
4
4
  "description": "API Key plugin for Better Auth.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -61,14 +61,14 @@
61
61
  },
62
62
  "devDependencies": {
63
63
  "tsdown": "0.21.1",
64
- "@better-auth/core": "1.7.0-beta.4",
65
- "better-auth": "1.7.0-beta.4"
64
+ "@better-auth/core": "1.7.0-beta.5",
65
+ "better-auth": "1.7.0-beta.5"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "@better-auth/utils": "0.4.1",
69
- "better-call": "1.3.5",
70
- "@better-auth/core": "^1.7.0-beta.4",
71
- "better-auth": "^1.7.0-beta.4"
69
+ "better-call": "1.3.6",
70
+ "@better-auth/core": "^1.7.0-beta.5",
71
+ "better-auth": "^1.7.0-beta.5"
72
72
  },
73
73
  "scripts": {
74
74
  "build": "tsdown",