@better-auth/infra 0.4.9 → 0.4.10

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/CHANGELOG.md CHANGED
@@ -5,11 +5,21 @@ All notable changes to `@better-auth/infra` are documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0/).
7
7
 
8
+ ## [0.4.10] - 2026-09-21
9
+
10
+ ### Added
11
+
12
+ - **`GET /dash/directory-sync/connection-count`** — Project-wide directory sync connection count (`{ count, mode }`). Managed mode counts `active` / `decommissioning` connections; legacy mode counts `scimProvider` rows. Returns 404 when directory sync is unavailable.
13
+
14
+ ### Fixed
15
+
16
+ - **Stored vs resolved auth base** — Platform-stored `baseURL` + `basePath` always rejoin (a path on stored `baseURL` no longer overrides a saved `basePath`). Request-scoped mount resolution still follows Better Auth path-in-`baseURL` via `context.baseURL` (dash config, Sentinel).
17
+
8
18
  ## [0.4.9] - 2026-09-09
9
19
 
10
20
  ### Fixed
11
21
 
12
- - **Auth base URL resolution** — Correctly handle Better Auth `baseURL` with an embedded path and dynamic `allowedHosts` (1.5+): dash config, invitation callbacks, SSO/SCIM endpoints, and Sentinel no longer use the wrong mount path or break on object `baseURL`.
22
+ - **Auth base URL / path** — `GET /dash/config` reports origin + effective mount path when `baseURL` embeds a path or uses dynamic `allowedHosts`. Invitation callbacks, SSO/SCIM endpoint URLs, and Sentinel route matching use the same resolved mount.
13
23
 
14
24
  ## [0.4.8] - 2026-09-09
15
25
 
package/dist/client.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as DashGetAllAuditLogsInput, i as DashClientOptions, n as DashAuditLog, o as DashGetAuditLogsInput, r as DashAuditLogsResponse, s as dashClient, t as IdentifyClientOptions } from "./identify-client-options-DgKA4Eq8.mjs";
1
+ import { a as DashGetAllAuditLogsInput, i as DashClientOptions, n as DashAuditLog, o as DashGetAuditLogsInput, r as DashAuditLogsResponse, s as dashClient, t as IdentifyClientOptions } from "./identify-client-options-BfGftEgh.mjs";
2
2
  import { BetterFetchPlugin } from "@better-fetch/fetch";
3
3
  //#region src/sentinel/client.d.ts
4
4
  interface SentinelClientOptions {
@@ -34,9 +34,9 @@ interface SentinelClientOptions {
34
34
  */
35
35
  onChallengeFailed?: (error: Error) => void;
36
36
  }
37
- declare const sentinelClient: (options?: SentinelClientOptions) => {
37
+ export declare const sentinelClient: (options?: SentinelClientOptions) => {
38
38
  id: "sentinel";
39
39
  fetchPlugins: BetterFetchPlugin[];
40
40
  };
41
41
  //#endregion
42
- export { type DashAuditLog, type DashAuditLogsResponse, type DashClientOptions, type DashGetAllAuditLogsInput, type DashGetAuditLogsInput, type SentinelClientOptions, dashClient, sentinelClient };
42
+ export { type DashAuditLog, type DashAuditLogsResponse, type DashClientOptions, type DashGetAllAuditLogsInput, type DashGetAuditLogsInput, type SentinelClientOptions, dashClient };
package/dist/client.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { n as hash, o as createKV } from "./crypto-DDadesq-.mjs";
2
- import { a as resolveSentinelClientIdentifyUrl, c as identify, i as solvePoWChallenge, l as dashClient, n as decodePoWChallenge, o as resolveIdentifyClientRetry, r as encodePoWSolution, s as generateRequestId, t as createPowRetryTimeout } from "./pow-retry-DRUkPcBn.mjs";
1
+ import { n as hash, o as createKV } from "./crypto-Doziv2tH.mjs";
2
+ import { a as resolveSentinelClientIdentifyUrl, c as identify, i as solvePoWChallenge, l as dashClient, n as decodePoWChallenge, o as resolveIdentifyClientRetry, r as encodePoWSolution, s as generateRequestId, t as createPowRetryTimeout } from "./pow-retry-DIkxDwZf.mjs";
3
3
  import { env } from "@better-auth/core/env";
4
4
  //#region src/sentinel/fingerprint.ts
5
5
  function murmurhash3(str, seed = 0) {
@@ -1,7 +1,7 @@
1
1
  import { env } from "@better-auth/core/env";
2
2
  //#endregion
3
3
  //#region src/version.ts
4
- const PLUGIN_VERSION = "0.4.9";
4
+ const PLUGIN_VERSION = "0.4.10";
5
5
  //#endregion
6
6
  //#region src/constants.ts
7
7
  /**
@@ -1,4 +1,4 @@
1
- import { i as INFRA_USER_AGENT } from "./constants-CdZodAXp.mjs";
1
+ import { i as INFRA_USER_AGENT } from "./constants-DLZKaIkd.mjs";
2
2
  import { createFetch } from "@better-fetch/fetch";
3
3
  import { sha256 } from "@noble/hashes/sha2.js";
4
4
  //#region src/fetch.ts
package/dist/email.d.mts CHANGED
@@ -8,7 +8,7 @@
8
8
  /**
9
9
  * Email template definitions with their required variables
10
10
  */
11
- declare const EMAIL_TEMPLATES: {
11
+ export declare const EMAIL_TEMPLATES: {
12
12
  readonly "verify-email": {
13
13
  readonly variables: {
14
14
  verificationCode?: string;
@@ -136,14 +136,14 @@ declare const EMAIL_TEMPLATES: {
136
136
  };
137
137
  };
138
138
  };
139
- type EmailTemplateId = keyof typeof EMAIL_TEMPLATES;
140
- type EmailTemplateVariables<T extends EmailTemplateId> = (typeof EMAIL_TEMPLATES)[T]["variables"];
141
- interface SendEmailResult {
139
+ export type EmailTemplateId = keyof typeof EMAIL_TEMPLATES;
140
+ export type EmailTemplateVariables<T extends EmailTemplateId> = (typeof EMAIL_TEMPLATES)[T]["variables"];
141
+ export interface SendEmailResult {
142
142
  success: boolean;
143
143
  messageId?: string;
144
144
  error?: string;
145
145
  }
146
- interface EmailConfig {
146
+ export interface EmailConfig {
147
147
  apiKey?: string;
148
148
  apiUrl?: string;
149
149
  /**
@@ -171,7 +171,7 @@ interface EmailConfig {
171
171
  /**
172
172
  * Type-safe send email options
173
173
  */
174
- type SendEmailOptions<T extends EmailTemplateId = EmailTemplateId> = {
174
+ export type SendEmailOptions<T extends EmailTemplateId = EmailTemplateId> = {
175
175
  /**
176
176
  * The template ID to use
177
177
  */
@@ -192,7 +192,7 @@ type SendEmailOptions<T extends EmailTemplateId = EmailTemplateId> = {
192
192
  /**
193
193
  * Options for sending bulk emails
194
194
  */
195
- type SendBulkEmailsOptions<T extends EmailTemplateId = EmailTemplateId> = {
195
+ export type SendBulkEmailsOptions<T extends EmailTemplateId = EmailTemplateId> = {
196
196
  /**
197
197
  * The template ID to use for all emails
198
198
  */
@@ -216,7 +216,7 @@ type SendBulkEmailsOptions<T extends EmailTemplateId = EmailTemplateId> = {
216
216
  /**
217
217
  * Result of a bulk email send operation
218
218
  */
219
- interface SendBulkEmailsResult {
219
+ export interface SendBulkEmailsResult {
220
220
  success: boolean;
221
221
  failures?: Record<string, {
222
222
  error?: string;
@@ -226,7 +226,7 @@ interface SendBulkEmailsResult {
226
226
  /**
227
227
  * Create an email sender instance
228
228
  */
229
- declare function createEmailSender(config?: EmailConfig): {
229
+ export declare function createEmailSender(config?: EmailConfig): {
230
230
  send: <T extends EmailTemplateId>(options: SendEmailOptions<T>) => Promise<SendEmailResult>;
231
231
  sendBulk: <T extends EmailTemplateId>(options: SendBulkEmailsOptions<T>) => Promise<SendBulkEmailsResult>;
232
232
  getTemplates: () => Promise<{
@@ -253,7 +253,7 @@ declare function createEmailSender(config?: EmailConfig): {
253
253
  * });
254
254
  * ```
255
255
  */
256
- declare function sendEmail<T extends EmailTemplateId>(options: SendEmailOptions<T>, config?: EmailConfig): Promise<SendEmailResult>;
256
+ export declare function sendEmail<T extends EmailTemplateId>(options: SendEmailOptions<T>, config?: EmailConfig): Promise<SendEmailResult>;
257
257
  /**
258
258
  * Send bulk emails using the Better Auth dashboard's email templates.
259
259
  *
@@ -270,6 +270,5 @@ declare function sendEmail<T extends EmailTemplateId>(options: SendEmailOptions<
270
270
  * });
271
271
  * ```
272
272
  */
273
- declare function sendBulkEmails<T extends EmailTemplateId>(options: SendBulkEmailsOptions<T>, config?: EmailConfig): Promise<SendBulkEmailsResult>;
274
- //#endregion
275
- export { EMAIL_TEMPLATES, EmailConfig, EmailTemplateId, EmailTemplateVariables, SendBulkEmailsOptions, SendBulkEmailsResult, SendEmailOptions, SendEmailResult, createEmailSender, sendBulkEmails, sendEmail };
273
+ export declare function sendBulkEmails<T extends EmailTemplateId>(options: SendBulkEmailsOptions<T>, config?: EmailConfig): Promise<SendBulkEmailsResult>;
274
+ //#endregion
package/dist/email.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as INFRA_USER_AGENT, n as INFRA_API_URL } from "./constants-CdZodAXp.mjs";
1
+ import { i as INFRA_USER_AGENT, n as INFRA_API_URL } from "./constants-DLZKaIkd.mjs";
2
2
  import { logger } from "better-auth";
3
3
  import { env } from "@better-auth/core/env";
4
4
  import { createFetch } from "@better-fetch/fetch";
@@ -1,4 +1,4 @@
1
- import { g as KvRetryOptions } from "./types-BkUWsMpe.mjs";
1
+ import { g as KvRetryOptions } from "./types-sFD6YavS.mjs";
2
2
  import { BetterAuthClientOptions, ClientStore } from "better-auth";
3
3
  import { BetterFetch } from "@better-fetch/fetch";
4
4
  //#region src/dash-client.d.ts
package/dist/index.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { A as SecurityOptions, C as createAuthMiddleware, D as ImpossibleTravelResult, E as CredentialStuffingResult, M as StaleUserResult, N as ThresholdConfig, O as SecurityEvent, S as asInfraContext, T as CompromisedPasswordResult, _ as KvRetryOptionsResolved, a as DashOptionsInternal, b as SentinelOptions, c as EndpointOptions, d as InfraEndpointContextValue, f as InfraPluginConnectionOptions, g as KvRetryOptions, h as KvOptionsResolved, i as DashOptions, j as SecurityVerdict, k as SecurityEventType, l as InfraAuthContext, m as KvOptions, n as ApiOptions, o as DashOptionsResolved, p as InfraPluginConnectionOptionsInternal, r as ApiOptionsResolved, s as Endpoint, t as APIError, u as InfraEndpointContext, v as LocationData, w as sentinel, x as SentinelOptionsInternal, y as LocationDataContext } from "./types-BkUWsMpe.mjs";
1
+ import { A as SecurityOptions, C as createAuthMiddleware, D as ImpossibleTravelResult, E as CredentialStuffingResult, M as StaleUserResult, N as ThresholdConfig, O as SecurityEvent, S as asInfraContext, T as CompromisedPasswordResult, _ as KvRetryOptionsResolved, a as DashOptionsInternal, b as SentinelOptions, c as EndpointOptions, d as InfraEndpointContextValue, f as InfraPluginConnectionOptions, g as KvRetryOptions, h as KvOptionsResolved, i as DashOptions, j as SecurityVerdict, k as SecurityEventType, l as InfraAuthContext, m as KvOptions, n as ApiOptions, o as DashOptionsResolved, p as InfraPluginConnectionOptionsInternal, r as ApiOptionsResolved, s as Endpoint, t as APIError, u as InfraEndpointContext, v as LocationData, w as sentinel, x as SentinelOptionsInternal, y as LocationDataContext } from "./types-sFD6YavS.mjs";
2
2
  import { EMAIL_TEMPLATES, EmailConfig, EmailTemplateId, EmailTemplateVariables, SendBulkEmailsOptions, SendBulkEmailsResult, SendEmailOptions, SendEmailResult, createEmailSender, sendBulkEmails, sendEmail } from "./email.mjs";
3
3
  import { Account, AuthContext, GenericEndpointContext, Session, User } from "better-auth";
4
4
  import z from "zod";
@@ -30,26 +30,26 @@ interface PoWSolution {
30
30
  counter: number;
31
31
  }
32
32
  /** Default difficulty in bits (18 = ~500ms solve time) */
33
- declare const DEFAULT_DIFFICULTY = 18;
33
+ export declare const DEFAULT_DIFFICULTY = 18;
34
34
  /** Challenge TTL in seconds */
35
- declare const CHALLENGE_TTL = 60;
35
+ export declare const CHALLENGE_TTL = 60;
36
36
  /**
37
37
  * Solve a PoW challenge (browser-compatible)
38
38
  * This function is designed to run in a browser environment
39
39
  */
40
- declare function solvePoWChallenge(challenge: PoWChallenge): Promise<PoWSolution>;
40
+ export declare function solvePoWChallenge(challenge: PoWChallenge): Promise<PoWSolution>;
41
41
  /**
42
42
  * Decode a base64-encoded challenge string (browser-compatible)
43
43
  */
44
- declare function decodePoWChallenge(encoded: string): PoWChallenge | null;
44
+ export declare function decodePoWChallenge(encoded: string): PoWChallenge | null;
45
45
  /**
46
46
  * Encode a solution string (browser-compatible)
47
47
  */
48
- declare function encodePoWSolution(solution: PoWSolution): string;
48
+ export declare function encodePoWSolution(solution: PoWSolution): string;
49
49
  /**
50
50
  * Verify a PoW solution locally (for testing purposes)
51
51
  */
52
- declare function verifyPoWSolution(nonce: string, counter: number, difficulty: number): Promise<boolean>;
52
+ export declare function verifyPoWSolution(nonce: string, counter: number, difficulty: number): Promise<boolean>;
53
53
  //#endregion
54
54
  //#region src/sms.d.ts
55
55
  /**
@@ -61,7 +61,7 @@ declare function verifyPoWSolution(nonce: string, counter: number, difficulty: n
61
61
  /**
62
62
  * SMS template definitions with their required variables
63
63
  */
64
- declare const SMS_TEMPLATES: {
64
+ export declare const SMS_TEMPLATES: {
65
65
  readonly "phone-verification": {
66
66
  readonly variables: {
67
67
  code: string;
@@ -140,7 +140,7 @@ interface SendSMSOptions {
140
140
  /**
141
141
  * Create an SMS sender instance
142
142
  */
143
- declare function createSMSSender(config?: SMSConfig): {
143
+ export declare function createSMSSender(config?: SMSConfig): {
144
144
  send: (options: SendSMSOptions) => Promise<SendSMSResult>;
145
145
  };
146
146
  /**
@@ -171,7 +171,7 @@ declare function createSMSSender(config?: SMSConfig): {
171
171
  * });
172
172
  * ```
173
173
  */
174
- declare function sendSMS(options: SendSMSOptions, config?: SMSConfig): Promise<SendSMSResult>;
174
+ export declare function sendSMS(options: SendSMSOptions, config?: SMSConfig): Promise<SendSMSResult>;
175
175
  //#endregion
176
176
  //#region src/routes/auth/types.d.ts
177
177
  type DBField = {
@@ -370,6 +370,10 @@ interface DashDirectoryRegenerateTokenResponse {
370
370
  scimToken: string;
371
371
  scimEndpoint: string;
372
372
  }
373
+ interface DashDirectorySyncConnectionCountResponse {
374
+ count: number;
375
+ mode: "managed" | "legacy";
376
+ }
373
377
  //#endregion
374
378
  //#region src/events/constants.d.ts
375
379
  declare const EVENT_TYPES: {
@@ -416,7 +420,7 @@ declare const ORGANIZATION_EVENT_TYPES: {
416
420
  readonly ORGANIZATION_TEAM_MEMBER_REMOVED: "organization_team_member_removed";
417
421
  };
418
422
  /** All audit event type string constants (user + organization). */
419
- declare const USER_EVENT_TYPES: {
423
+ export declare const USER_EVENT_TYPES: {
420
424
  readonly ORGANIZATION_CREATED: "organization_created";
421
425
  readonly ORGANIZATION_UPDATED: "organization_updated";
422
426
  readonly ORGANIZATION_MEMBER_ADDED: "organization_member_added";
@@ -791,10 +795,10 @@ interface DashCheckUserExistsResponse {
791
795
  * @param email - Raw email to normalize
792
796
  * @param context - Auth context
793
797
  */
794
- declare function normalizeEmail(email: string, context: AuthContext): string;
798
+ export declare function normalizeEmail(email: string, context: AuthContext): string;
795
799
  //#endregion
796
800
  //#region src/index.d.ts
797
- declare const dash: <O extends DashOptions>(options?: O) => {
801
+ export declare const dash: <O extends DashOptions>(options?: O) => {
798
802
  id: "dash";
799
803
  options: DashOptionsResolved;
800
804
  version: string;
@@ -838,7 +842,7 @@ declare const dash: <O extends DashOptions>(options?: O) => {
838
842
  };
839
843
  session: {
840
844
  create: {
841
- before(session: {
845
+ before(_session: {
842
846
  id: string;
843
847
  createdAt: Date;
844
848
  updatedAt: Date;
@@ -847,7 +851,7 @@ declare const dash: <O extends DashOptions>(options?: O) => {
847
851
  token: string;
848
852
  ipAddress?: string | null | undefined;
849
853
  userAgent?: string | null | undefined;
850
- } & Record<string, unknown>, _ctx: GenericEndpointContext | null): Promise<{
854
+ } & Record<string, unknown>, untypedCtx: GenericEndpointContext | null): Promise<{
851
855
  data: {
852
856
  loginMethod: string | null;
853
857
  };
@@ -861,7 +865,7 @@ declare const dash: <O extends DashOptions>(options?: O) => {
861
865
  token: string;
862
866
  ipAddress?: string | null | undefined;
863
867
  userAgent?: string | null | undefined;
864
- } & Record<string, unknown>, _ctx: GenericEndpointContext | null): Promise<void>;
868
+ } & Record<string, unknown>, untypedCtx: GenericEndpointContext | null): Promise<void>;
865
869
  };
866
870
  delete: {
867
871
  after(session: {
@@ -2197,6 +2201,12 @@ declare const dash: <O extends DashOptions>(options?: O) => {
2197
2201
  }>>[];
2198
2202
  body: import("zod").ZodObject<{}, import("zod/v4/core").$strip>;
2199
2203
  }, DirectorySyncConnection>;
2204
+ countDashDirectorySyncConnections: import("better-call").StrictEndpoint<"/dash/directory-sync/connection-count", {
2205
+ method: "GET";
2206
+ use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
2207
+ payload: Record<string, unknown>;
2208
+ }>>[];
2209
+ }, DashDirectorySyncConnectionCountResponse>;
2200
2210
  dashExecuteAdapter: import("better-call").StrictEndpoint<"/dash/execute-adapter", {
2201
2211
  method: "POST";
2202
2212
  use: import("better-call").Middleware<import("better-call").MiddlewareOptions, (inputContext: import("better-call").MiddlewareInputContext<import("better-call").MiddlewareOptions>) => Promise<{
@@ -2341,4 +2351,4 @@ declare const dash: <O extends DashOptions>(options?: O) => {
2341
2351
  } : {});
2342
2352
  };
2343
2353
  //#endregion
2344
- export { type APIError, type ApiOptions, type ApiOptionsResolved, CHALLENGE_TTL, type CompromisedPasswordResult, type CredentialStuffingResult, type DBField, DEFAULT_DIFFICULTY, type DashAddTeamMemberResponse, type DashBanManyResponse, type DashCheckUserByEmailResponse, type DashCheckUserExistsResponse, type DashCompleteInvitationResponse, type DashConfigResponse, type DashCreateOrganizationBody, type DashCreateOrganizationResponse, type DashCreateTeamResponse, type DashCreateUserResponse, type DashDeleteManyUsersResponse, type DashDirectoryCreateResponse, type DashDirectoryCredential, type DashDirectoryDeleteResponse, type DashDirectoryEvent, type DashDirectoryEventsResponse, type DashDirectoryItem, type DashDirectoryRegenerateTokenResponse, type DashDirectoryRotateCredentialResponse, type DashDirectorySyncSSOPairing, type DashExecuteAdapterCountResponse, type DashExecuteAdapterFindManyResponse, type DashExecuteAdapterFindOneResponse, type DashExecuteAdapterMutationResponse, type DashExecuteAdapterResponse, type DashExportOrganizationsResponse, type DashIdRow, type DashInviteMemberResponse, type DashMaybeSuccessResponse, type DashOptions, type DashOptionsInternal, type DashOptionsResolved, type DashOrganizationAddMemberResponse, type DashOrganizationDeleteManyResponse, type DashOrganizationDetailResponse, type DashOrganizationInvitationItem, type DashOrganizationInvitationListResponse, type DashOrganizationInvitationStatusItem, type DashOrganizationListResponse, type DashOrganizationMember, type DashOrganizationMemberListItem, type DashOrganizationMemberListResponse, type DashOrganizationMemberUser, type DashOrganizationOptionsResponse, type DashOrganizationTeamItem, type DashOrganizationTeamListResponse, type DashOrganizationUpdateMemberRoleResponse, type DashOrganizationUpdateResponse, type DashSCIMManagedConnectionEventType, type DashSCIMManagedCredentialStatus, type DashSCIMScope, type DashSendManyVerificationEmailsResponse, type DashSessionRevokeManyResponse, type DashSsoCreateProviderResponse, type DashSsoDeleteResponse, type DashSsoMarkDomainVerifiedResponse, type DashSsoProviderItem, type DashSsoProviderSummary, type DashSsoUpdateProviderResponse, type DashSsoVerificationTokenResponse, type DashSsoVerifyDomainResponse, type DashSuccessResponse, type DashTeam, type DashTeamMember, type DashTeamMemberListResponse, type DashTwoFactorBackupCodesResponse, type DashTwoFactorEnableResponse, type DashTwoFactorStatus, type DashTwoFactorTotpViewResponse, type DashUpdateTeamResponse, type DashUpdateUserResponse, type DashUserDetailsResponse, type DashUserGraphDataResponse, type DashUserListResponse, type DashUserOrganizationsResponse, type DashUserRetentionDataResponse, type DashUserStatsActivePeriod, type DashUserStatsResponse, type DashUserStatsSignUpPeriod, type DashValidateResponse, type DirectorySyncConnection, type DirectorySyncConnectionStatus, type DirectorySyncMode, EMAIL_TEMPLATES, type EmailConfig, type EmailTemplateId, type EmailTemplateVariables, type Endpoint, type EndpointOptions, type EventLocation, type EventTypesResponse, type ImpossibleTravelResult, type InfraAuthContext, type InfraEndpointContext, type InfraEndpointContextValue, type InfraPluginConnectionOptions, type InfraPluginConnectionOptionsInternal, type KvOptions, type KvOptionsResolved, type KvRetryOptions, type KvRetryOptionsResolved, type LegacyDashDirectoryCreateResponse, type LegacyDashDirectoryItem, type LocationData, type LocationDataContext, type ORGANIZATION_USER_PREVIEW_SELECT, type OrganizationUserPreview, type PoWChallenge, type PoWSolution, type SCIMPlugin, type SMSConfig, type SMSTemplateId, type SMSTemplateVariables, SMS_TEMPLATES, type SecurityEvent, type SecurityEventType, type SecurityOptions, type SecurityVerdict, type SendBulkEmailsOptions, type SendBulkEmailsResult, type SendEmailOptions, type SendEmailResult, type SendSMSOptions, type SendSMSResult, type SentinelOptions, type SentinelOptionsInternal, type StaleUserResult, type ThresholdConfig, USER_EVENT_TYPES, type UserEvent, type UserEventType, type UserEventsResponse, type asInfraContext, type createAuthMiddleware, createEmailSender, createSMSSender, dash, decodePoWChallenge, encodePoWSolution, normalizeEmail, sendBulkEmails, sendEmail, sendSMS, sentinel, solvePoWChallenge, verifyPoWSolution };
2354
+ export { type APIError, type ApiOptions, type ApiOptionsResolved, type CompromisedPasswordResult, type CredentialStuffingResult, type DBField, type DashAddTeamMemberResponse, type DashBanManyResponse, type DashCheckUserByEmailResponse, type DashCheckUserExistsResponse, type DashCompleteInvitationResponse, type DashConfigResponse, type DashCreateOrganizationBody, type DashCreateOrganizationResponse, type DashCreateTeamResponse, type DashCreateUserResponse, type DashDeleteManyUsersResponse, type DashDirectoryCreateResponse, type DashDirectoryCredential, type DashDirectoryDeleteResponse, type DashDirectoryEvent, type DashDirectoryEventsResponse, type DashDirectoryItem, type DashDirectoryRegenerateTokenResponse, type DashDirectoryRotateCredentialResponse, type DashDirectorySyncConnectionCountResponse, type DashDirectorySyncSSOPairing, type DashExecuteAdapterCountResponse, type DashExecuteAdapterFindManyResponse, type DashExecuteAdapterFindOneResponse, type DashExecuteAdapterMutationResponse, type DashExecuteAdapterResponse, type DashExportOrganizationsResponse, type DashIdRow, type DashInviteMemberResponse, type DashMaybeSuccessResponse, type DashOptions, type DashOptionsInternal, type DashOptionsResolved, type DashOrganizationAddMemberResponse, type DashOrganizationDeleteManyResponse, type DashOrganizationDetailResponse, type DashOrganizationInvitationItem, type DashOrganizationInvitationListResponse, type DashOrganizationInvitationStatusItem, type DashOrganizationListResponse, type DashOrganizationMember, type DashOrganizationMemberListItem, type DashOrganizationMemberListResponse, type DashOrganizationMemberUser, type DashOrganizationOptionsResponse, type DashOrganizationTeamItem, type DashOrganizationTeamListResponse, type DashOrganizationUpdateMemberRoleResponse, type DashOrganizationUpdateResponse, type DashSCIMManagedConnectionEventType, type DashSCIMManagedCredentialStatus, type DashSCIMScope, type DashSendManyVerificationEmailsResponse, type DashSessionRevokeManyResponse, type DashSsoCreateProviderResponse, type DashSsoDeleteResponse, type DashSsoMarkDomainVerifiedResponse, type DashSsoProviderItem, type DashSsoProviderSummary, type DashSsoUpdateProviderResponse, type DashSsoVerificationTokenResponse, type DashSsoVerifyDomainResponse, type DashSuccessResponse, type DashTeam, type DashTeamMember, type DashTeamMemberListResponse, type DashTwoFactorBackupCodesResponse, type DashTwoFactorEnableResponse, type DashTwoFactorStatus, type DashTwoFactorTotpViewResponse, type DashUpdateTeamResponse, type DashUpdateUserResponse, type DashUserDetailsResponse, type DashUserGraphDataResponse, type DashUserListResponse, type DashUserOrganizationsResponse, type DashUserRetentionDataResponse, type DashUserStatsActivePeriod, type DashUserStatsResponse, type DashUserStatsSignUpPeriod, type DashValidateResponse, type DirectorySyncConnection, type DirectorySyncConnectionStatus, type DirectorySyncMode, EMAIL_TEMPLATES, type EmailConfig, type EmailTemplateId, type EmailTemplateVariables, type Endpoint, type EndpointOptions, type EventLocation, type EventTypesResponse, type ImpossibleTravelResult, type InfraAuthContext, type InfraEndpointContext, type InfraEndpointContextValue, type InfraPluginConnectionOptions, type InfraPluginConnectionOptionsInternal, type KvOptions, type KvOptionsResolved, type KvRetryOptions, type KvRetryOptionsResolved, type LegacyDashDirectoryCreateResponse, type LegacyDashDirectoryItem, type LocationData, type LocationDataContext, type ORGANIZATION_USER_PREVIEW_SELECT, type OrganizationUserPreview, type PoWChallenge, type PoWSolution, type SCIMPlugin, type SMSConfig, type SMSTemplateId, type SMSTemplateVariables, type SecurityEvent, type SecurityEventType, type SecurityOptions, type SecurityVerdict, type SendBulkEmailsOptions, type SendBulkEmailsResult, type SendEmailOptions, type SendEmailResult, type SendSMSOptions, type SendSMSResult, type SentinelOptions, type SentinelOptionsInternal, type StaleUserResult, type ThresholdConfig, type UserEvent, type UserEventType, type UserEventsResponse, type asInfraContext, type createAuthMiddleware, createEmailSender, sendBulkEmails, sendEmail, sentinel };
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { i as INFRA_USER_AGENT, n as INFRA_API_URL, o as PLUGIN_VERSION, r as INFRA_KV_URL } from "./constants-CdZodAXp.mjs";
2
- import { a as createAPI, n as hash$1, o as createKV, r as hmacSha256Hex } from "./crypto-DDadesq-.mjs";
1
+ import { i as INFRA_USER_AGENT, n as INFRA_API_URL, o as PLUGIN_VERSION, r as INFRA_KV_URL } from "./constants-DLZKaIkd.mjs";
2
+ import { a as createAPI, n as hash$1, o as createKV, r as hmacSha256Hex } from "./crypto-Doziv2tH.mjs";
3
3
  import { EMAIL_TEMPLATES, createEmailSender, sendBulkEmails, sendEmail } from "./email.mjs";
4
4
  import { getCurrentAdapter, getCurrentAuthContext, getCurrentDBAdapterAsyncLocalStorage, runWithTransaction } from "@better-auth/core/context";
5
5
  import { APIError, generateId, getAuthTables, logger } from "better-auth";
@@ -13,14 +13,24 @@ import z, { z as z$1 } from "zod";
13
13
  import { DOMParser } from "@xmldom/xmldom";
14
14
  import { base64Url } from "@better-auth/utils/base64";
15
15
  import { createLocalJWKSet, jwtVerify } from "jose";
16
- import { generateRandomString, symmetricEncrypt } from "better-auth/crypto";
16
+ import { generateRandomString, symmetricDecrypt, symmetricEncrypt } from "better-auth/crypto";
17
17
  import { createOTP } from "@better-auth/utils/otp";
18
18
  //#region src/options.ts
19
+ /** @internal */
20
+ function resolveApiKeys(raw) {
21
+ const apiKeys = (raw?.trim() || env.BETTER_AUTH_API_KEY?.trim() || "").split(",").map((k) => k.trim()).filter((k) => k.length > 0);
22
+ return {
23
+ apiKey: apiKeys[0] ?? "",
24
+ apiKeys
25
+ };
26
+ }
19
27
  function resolveConnectionOptions(options) {
28
+ const { apiKey, apiKeys } = resolveApiKeys(options?.apiKey);
20
29
  return {
21
30
  apiUrl: options?.apiUrl || INFRA_API_URL,
22
31
  kvUrl: options?.kvUrl || INFRA_KV_URL,
23
- apiKey: options?.apiKey || env.BETTER_AUTH_API_KEY || "",
32
+ apiKey,
33
+ apiKeys,
24
34
  apiOptions: {
25
35
  timeout: options?.apiOptions?.timeout ?? options?.apiTimeout ?? 3e3,
26
36
  headers: options?.apiOptions?.headers
@@ -128,18 +138,19 @@ function resolveProjectBasePath(basePath) {
128
138
  return basePath?.trim() || "/api/auth";
129
139
  }
130
140
  /**
131
- * Normalized project auth base URL + path (blank basePath → default).
132
- * If `baseURL` already has a non-root pathname, that path wins over `basePath`
133
- * (Better Auth path-in-baseURL form).
141
+ * Split a Better Auth **already-resolved** mount URL (`ctx.context.baseURL`).
142
+ * Path embedded in that URL is the effective mount (BA path-in-baseURL /
143
+ * withPath result). `fallbackBasePath` is used only when the mount URL has no
144
+ * path (e.g. dynamic allowedHosts before a request sets the full URL).
134
145
  */
135
- function resolveProjectAuthBase(baseURL, basePath) {
146
+ function resolveAuthMountBase(mountURL, fallbackBasePath) {
136
147
  try {
137
- const url = new URL(baseURL);
148
+ const url = new URL(mountURL);
138
149
  const pathname = url.pathname.replace(/\/+$/, "") || "";
139
150
  if (pathname && pathname !== "/") return resolveBaseUrlPath(url.origin, pathname);
140
- return resolveBaseUrlPath(url.origin, resolveProjectBasePath(basePath));
151
+ return resolveBaseUrlPath(url.origin, resolveProjectBasePath(fallbackBasePath));
141
152
  } catch {
142
- return resolveBaseUrlPath(baseURL, resolveProjectBasePath(basePath));
153
+ return resolveBaseUrlPath(mountURL, resolveProjectBasePath(fallbackBasePath));
143
154
  }
144
155
  }
145
156
  function toAllowedOriginSet(allowedOrigins) {
@@ -1341,7 +1352,7 @@ function createIdentificationMiddleware($kv, options) {
1341
1352
  if (!skipIdentification) {
1342
1353
  const extracted = extractIdentificationHeaders(ctx.request);
1343
1354
  headerVisitorId = extracted.visitorId;
1344
- requestId = extracted.requestId ?? ctx.getCookie("__infra-rid") ?? null;
1355
+ requestId = extracted.requestId ?? ctx.getCookie(IDENTIFICATION_COOKIE_NAME) ?? null;
1345
1356
  }
1346
1357
  ctx.context.requestId = requestId;
1347
1358
  if (skipIdentification) ctx.context.identification = null;
@@ -2632,7 +2643,7 @@ const sentinel = (options) => {
2632
2643
  id: "sentinel",
2633
2644
  init(ctx) {
2634
2645
  activityTrackingEnabled = (ctx.getPlugin("dash")?.options)?.activityTracking?.enabled === true;
2635
- const basePath = ctx.baseURL ? resolveProjectAuthBase(ctx.baseURL, ctx.options.basePath).basePath : resolveProjectBasePath(ctx.options.basePath);
2646
+ const basePath = ctx.baseURL ? resolveAuthMountBase(ctx.baseURL, ctx.options.basePath).basePath : resolveProjectBasePath(ctx.options.basePath);
2636
2647
  const ipHeaders = ctx.options.advanced?.ipAddress?.ipAddressHeaders || null;
2637
2648
  const disableIpTracking = ctx.options.advanced?.ipAddress?.disableIpTracking === true;
2638
2649
  /**
@@ -4282,14 +4293,14 @@ const jwtMiddleware = (options, schema, getJWT) => {
4282
4293
  throw ctx.error("UNAUTHORIZED", { message: "Invalid API key" });
4283
4294
  });
4284
4295
  const apiKeyHash = payload.apiKeyHash;
4285
- if (typeof apiKeyHash !== "string" || !options.apiKey) {
4296
+ if (typeof apiKeyHash !== "string" || options.apiKeys.length === 0) {
4286
4297
  ctx.context.logger.warn("[Dash] API key hash is missing or invalid", {
4287
4298
  apiKeyHash,
4288
- apiKey: options.apiKey ? "present" : "missing"
4299
+ apiKey: options.apiKeys.length > 0 ? "present" : "missing"
4289
4300
  });
4290
4301
  throw ctx.error("UNAUTHORIZED", { message: "Invalid API key" });
4291
4302
  }
4292
- if (!timingSafeEqualHash(apiKeyHash, await hash(options.apiKey))) {
4303
+ if (!await apiKeyHashMatchesAny(apiKeyHash, options.apiKeys)) {
4293
4304
  ctx.context.logger.warn("[Dash] API key hash mismatch");
4294
4305
  throw ctx.error("UNAUTHORIZED", { message: "Invalid API key" });
4295
4306
  }
@@ -4337,20 +4348,25 @@ const jwtValidateMiddleware = (options) => {
4337
4348
  throw ctx.error("UNAUTHORIZED", { message: "Invalid API key" });
4338
4349
  });
4339
4350
  const apiKeyHash = payload.apiKeyHash;
4340
- if (typeof apiKeyHash !== "string" || !options.apiKey) {
4351
+ if (typeof apiKeyHash !== "string" || options.apiKeys.length === 0) {
4341
4352
  ctx.context.logger.warn("[Dash] API key hash is missing or invalid", {
4342
4353
  apiKeyHash: typeof apiKeyHash,
4343
- apiKey: options.apiKey ? "present" : "missing"
4354
+ apiKey: options.apiKeys.length > 0 ? "present" : "missing"
4344
4355
  });
4345
4356
  throw ctx.error("UNAUTHORIZED", { message: "Invalid API key" });
4346
4357
  }
4347
- if (!timingSafeEqualHash(apiKeyHash, await hash(options.apiKey))) {
4358
+ if (!await apiKeyHashMatchesAny(apiKeyHash, options.apiKeys)) {
4348
4359
  ctx.context.logger.warn("[Dash] API key hash mismatch");
4349
4360
  throw ctx.error("UNAUTHORIZED", { message: "Invalid API key" });
4350
4361
  }
4351
4362
  return { payload };
4352
4363
  });
4353
4364
  };
4365
+ async function apiKeyHashMatchesAny(apiKeyHash, apiKeys) {
4366
+ let matched = false;
4367
+ for (const key of apiKeys) if (timingSafeEqualHash(apiKeyHash, await hash(key))) matched = true;
4368
+ return matched;
4369
+ }
4354
4370
  //#endregion
4355
4371
  //#region src/lib/safe-url.ts
4356
4372
  function isSafeHttpUrl(value) {
@@ -4482,7 +4498,7 @@ const getConfig = (options) => {
4482
4498
  }, async (ctx) => {
4483
4499
  const advancedOptions = ctx.context.options.advanced;
4484
4500
  const organizationPlugin = ctx.context.getPlugin("organization");
4485
- const authBase = resolveProjectAuthBase(getAuthBaseUrl(ctx), ctx.context.options.basePath);
4501
+ const authBase = resolveAuthMountBase(getAuthBaseUrl(ctx), ctx.context.options.basePath);
4486
4502
  return redactDashSettings({
4487
4503
  version: ctx.context.version || null,
4488
4504
  socialProviders: Object.keys(ctx.context.options.socialProviders || {}),
@@ -5664,6 +5680,36 @@ function isDuplicateDirectorySyncError(e) {
5664
5680
  if (e instanceof Error) return /unique constraint|duplicate key|already exists|P2002/i.test(e.message);
5665
5681
  return false;
5666
5682
  }
5683
+ const countDirectorySyncConnections = (options) => {
5684
+ return createAuthEndpoint("/dash/directory-sync/connection-count", {
5685
+ method: "GET",
5686
+ use: [jwtMiddleware(options)]
5687
+ }, async (ctx) => {
5688
+ const mode = resolveMode(ctx);
5689
+ if (mode === "managed") return {
5690
+ count: await ctx.context.adapter.count({
5691
+ model: "directorySyncConnection",
5692
+ where: [{
5693
+ field: "status",
5694
+ value: ["active", "decommissioning"],
5695
+ operator: "in"
5696
+ }]
5697
+ }),
5698
+ mode: "managed"
5699
+ };
5700
+ if (mode === "legacy") {
5701
+ if (!isOrganizationEnabled(ctx)) return {
5702
+ count: 0,
5703
+ mode: "legacy"
5704
+ };
5705
+ return {
5706
+ count: await ctx.context.adapter.count({ model: "scimProvider" }),
5707
+ mode: "legacy"
5708
+ };
5709
+ }
5710
+ throw ctx.error("NOT_FOUND", { message: "Directory sync connection count unavailable" });
5711
+ });
5712
+ };
5667
5713
  const listOrganizationDirectories = (options) => {
5668
5714
  return createAuthEndpoint("/dash/organization/:id/directories", {
5669
5715
  method: "GET",
@@ -8996,7 +9042,6 @@ const enableTwoFactor = (options) => createAuthEndpoint("/dash/enable-two-factor
8996
9042
  value: userId
8997
9043
  }]
8998
9044
  });
8999
- const { generateRandomString, symmetricEncrypt } = await import("better-auth/crypto");
9000
9045
  const secret = generateRandomString(32);
9001
9046
  const { backupCodes, encryptedBackupCodes } = await generateBackupCodes$1(ctx.context.secret, resolveBackupCodeOptions(twoFactorPlugin));
9002
9047
  const encryptedSecret = await symmetricEncrypt({
@@ -9079,7 +9124,6 @@ const viewTwoFactorTotpUri = (options) => createAuthEndpoint("/dash/view-two-fac
9079
9124
  if (!twoFactorRecord) throw new APIError("NOT_FOUND", { message: "Two-factor authentication not set up for this user" });
9080
9125
  let secret = twoFactorRecord.secret;
9081
9126
  try {
9082
- const { symmetricDecrypt } = await import("better-auth/crypto");
9083
9127
  secret = await symmetricDecrypt({
9084
9128
  key: ctx.context.secret,
9085
9129
  data: twoFactorRecord.secret
@@ -10930,13 +10974,13 @@ const dash = (options) => {
10930
10974
  },
10931
10975
  session: {
10932
10976
  create: {
10933
- async before(session, _ctx) {
10934
- const ctx = _ctx;
10977
+ async before(_session, untypedCtx) {
10978
+ const ctx = untypedCtx;
10935
10979
  if (!ctx) return;
10936
10980
  return { data: { loginMethod: getLoginMethod(ctx) } };
10937
10981
  },
10938
- async after(session, _ctx) {
10939
- const ctx = _ctx;
10982
+ async after(session, untypedCtx) {
10983
+ const ctx = untypedCtx;
10940
10984
  if (!ctx || !session.userId) return;
10941
10985
  const location = ctx.context.location;
10942
10986
  const loginMethod = getLoginMethod(ctx) ?? void 0;
@@ -11199,6 +11243,7 @@ const dash = (options) => {
11199
11243
  listDashManagedDirectoryEvents: listDirectoryEvents(settings),
11200
11244
  decommissionDashManagedOrganizationDirectory: decommissionOrganizationDirectory(settings),
11201
11245
  unpairDashManagedOrganizationDirectory: unpairOrganizationDirectory(settings),
11246
+ countDashDirectorySyncConnections: countDirectorySyncConnections(settings),
11202
11247
  dashExecuteAdapter: executeAdapter(settings)
11203
11248
  },
11204
11249
  schema: {
package/dist/native.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as DashGetAllAuditLogsInput, i as DashClientOptions, n as DashAuditLog, o as DashGetAuditLogsInput, r as DashAuditLogsResponse, s as dashClient, t as IdentifyClientOptions } from "./identify-client-options-DgKA4Eq8.mjs";
1
+ import { a as DashGetAllAuditLogsInput, i as DashClientOptions, n as DashAuditLog, o as DashGetAuditLogsInput, r as DashAuditLogsResponse, s as dashClient, t as IdentifyClientOptions } from "./identify-client-options-BfGftEgh.mjs";
2
2
  import { BetterAuthClientPlugin } from "better-auth";
3
3
  //#region src/sentinel/native/client.d.ts
4
4
  interface SentinelNativeClientOptions {
@@ -22,6 +22,6 @@ interface SentinelNativeClientOptions {
22
22
  setItem: (key: string, value: string) => Promise<void>;
23
23
  };
24
24
  }
25
- declare const sentinelNativeClient: (options?: SentinelNativeClientOptions) => BetterAuthClientPlugin;
25
+ export declare const sentinelNativeClient: (options?: SentinelNativeClientOptions) => BetterAuthClientPlugin;
26
26
  //#endregion
27
- export { type DashAuditLog, type DashAuditLogsResponse, type DashClientOptions, type DashGetAllAuditLogsInput, type DashGetAuditLogsInput, type SentinelNativeClientOptions, dashClient, sentinelNativeClient };
27
+ export { type DashAuditLog, type DashAuditLogsResponse, type DashClientOptions, type DashGetAllAuditLogsInput, type DashGetAuditLogsInput, type SentinelNativeClientOptions, dashClient };
package/dist/native.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { o as createKV, t as bytesToHex } from "./crypto-DDadesq-.mjs";
2
- import { a as resolveSentinelClientIdentifyUrl, c as identify, i as solvePoWChallenge, l as dashClient, n as decodePoWChallenge, o as resolveIdentifyClientRetry, r as encodePoWSolution, t as createPowRetryTimeout } from "./pow-retry-DRUkPcBn.mjs";
1
+ import { o as createKV, t as bytesToHex } from "./crypto-Doziv2tH.mjs";
2
+ import { a as resolveSentinelClientIdentifyUrl, c as identify, i as solvePoWChallenge, l as dashClient, n as decodePoWChallenge, o as resolveIdentifyClientRetry, r as encodePoWSolution, t as createPowRetryTimeout } from "./pow-retry-DIkxDwZf.mjs";
3
3
  import { env } from "@better-auth/core/env";
4
4
  import { Dimensions, InteractionManager, PixelRatio, Platform } from "react-native";
5
5
  //#region src/sentinel/native/components.ts
@@ -1,4 +1,4 @@
1
- import { i as randomBytes, n as hash, t as bytesToHex } from "./crypto-DDadesq-.mjs";
1
+ import { i as randomBytes, n as hash, t as bytesToHex } from "./crypto-Doziv2tH.mjs";
2
2
  //#region src/dash-client.ts
3
3
  function resolveDashUserId(input, options) {
4
4
  return input.userId || options?.resolveUserId?.({
@@ -481,6 +481,8 @@ interface InfraPluginConnectionOptionsInternal extends Omit<InfraPluginConnectio
481
481
  apiUrl: string;
482
482
  kvUrl: string;
483
483
  apiKey: string;
484
+ /** @internal */
485
+ apiKeys: string[];
484
486
  apiOptions: ApiOptionsResolved;
485
487
  kvOptions: KvOptionsResolved;
486
488
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@better-auth/infra",
3
- "version": "0.4.9",
3
+ "version": "0.4.10",
4
4
  "description": "Dashboard and analytics plugin for Better Auth",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -66,32 +66,32 @@
66
66
  },
67
67
  "homepage": "https://better-auth.com",
68
68
  "devDependencies": {
69
- "@better-auth/kysely-adapter": "1.7.3",
70
- "@better-auth/scim": "1.7.3",
71
- "@better-auth/sso": "1.7.3",
69
+ "@better-auth/kysely-adapter": "1.7.5",
70
+ "@better-auth/scim": "1.7.5",
71
+ "@better-auth/sso": "1.7.5",
72
72
  "@infra/mocks": "0.0.0",
73
73
  "@infra/utils": "0.0.0",
74
74
  "@types/bun": "latest",
75
75
  "@types/node": "^24.12.0",
76
76
  "@vitest/browser-playwright": "5.0.0",
77
77
  "@vitest/coverage-istanbul": "^5.0.0",
78
- "better-auth": "1.7.3",
79
- "expo-crypto": "^57.0.1",
78
+ "better-auth": "1.7.5",
79
+ "expo-crypto": "^57.0.3",
80
80
  "msw": "^2.14.6",
81
81
  "playwright": "^1.63.0",
82
- "tsdown": "^0.22.14",
82
+ "tsdown": "^0.23.0",
83
83
  "typescript": "^6.0.3",
84
84
  "vitest": "^5.0.0",
85
85
  "zod": "4.5.4"
86
86
  },
87
87
  "dependencies": {
88
88
  "@better-auth/utils": "^0.4.2",
89
- "@better-fetch/fetch": "1.3.1",
89
+ "@better-fetch/fetch": "1.3.2",
90
90
  "@noble/hashes": "^2.2.0",
91
91
  "@xmldom/xmldom": "^0.9.10",
92
92
  "better-call": "1.4.0",
93
- "jose": "^6.2.10",
94
- "libphonenumber-js": "^1.13.11"
93
+ "jose": "^6.2.12",
94
+ "libphonenumber-js": "^1.13.13"
95
95
  },
96
96
  "peerDependencies": {
97
97
  "better-auth": ">=1.4.0",