@better-auth/infra 0.3.7 → 0.4.1

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/native.d.mts CHANGED
@@ -1,12 +1,16 @@
1
- import { a as DashGetAuditLogsInput, i as DashGetAllAuditLogsInput, n as DashAuditLogsResponse, o as dashClient, r as DashClientOptions, t as DashAuditLog } from "./dash-client-DXuu2ctl.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-CgijjwVT.mjs";
2
2
  import { BetterAuthClientPlugin } from "better-auth";
3
-
4
3
  //#region src/sentinel/native/client.d.ts
5
4
  interface SentinelNativeClientOptions {
6
5
  identifyUrl?: string;
7
6
  /**
8
- * Timeout for KV identify and related HTTP requests (milliseconds).
7
+ * Identify HTTP client options.
8
+ */
9
+ identifyOptions?: IdentifyClientOptions;
10
+ /**
11
+ * Timeout for identify and related HTTP requests (milliseconds).
9
12
  * @default 1000
13
+ * @deprecated Use `identifyOptions.timeout` instead.
10
14
  */
11
15
  kvTimeout?: number;
12
16
  autoSolveChallenge?: boolean;
package/dist/native.mjs CHANGED
@@ -1,11 +1,11 @@
1
- import { o as createKV, t as bytesToHex } from "./crypto--3ycICW4.mjs";
2
- import { a as resolveSentinelClientIdentifyUrl, c as dashClient, i as solvePoWChallenge, n as decodePoWChallenge, r as encodePoWSolution, s as identify, t as createPowRetryTimeout } from "./pow-retry-Dy1D-TKx.mjs";
1
+ import { o as createKV, t as bytesToHex } from "./crypto-CV91nSbp.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-7sPi32Ow.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
6
6
  /**
7
7
  * Default first-party component payload for React Native / Expo.
8
- * Avoids browser-style entropy; sets `clientRuntime` for durable-kv bot scoring.
8
+ * Avoids browser-style entropy; sets `clientRuntime` for identify bot scoring.
9
9
  */
10
10
  async function defaultCollectNativeComponents() {
11
11
  const windowDims = Dimensions.get("window");
@@ -224,26 +224,17 @@ function scheduleIdentify(send) {
224
224
  }
225
225
  const sentinelNativeClient = (options) => {
226
226
  const autoSolve = options?.autoSolveChallenge !== false;
227
+ const identifyUrl = resolveSentinelClientIdentifyUrl({
228
+ identifyUrl: options?.identifyUrl,
229
+ envKvUrl: env.BETTER_AUTH_KV_URL
230
+ });
227
231
  const runtime = createNativeFingerprintRuntime({
228
232
  $kv: createKV({
229
- kvUrl: resolveSentinelClientIdentifyUrl({
230
- identifyUrl: options?.identifyUrl,
231
- envKvUrl: env.BETTER_AUTH_KV_URL
232
- }),
233
- kvTimeout: options?.kvTimeout
233
+ kvUrl: identifyUrl,
234
+ timeout: options?.identifyOptions?.timeout ?? options?.kvTimeout
234
235
  }, {
235
236
  throw: true,
236
- retry: {
237
- type: "exponential",
238
- attempts: 2,
239
- baseDelay: 400,
240
- maxDelay: 600,
241
- shouldRetry(response) {
242
- if (response === null) return true;
243
- if (response.status === 429) return true;
244
- return response.status >= 500;
245
- }
246
- }
237
+ retry: resolveIdentifyClientRetry(options?.identifyOptions?.retry)
247
238
  }),
248
239
  getOrCreateVisitorId: () => getOrCreateVisitorId(options?.storage)
249
240
  });
@@ -1,4 +1,4 @@
1
- import { i as randomBytes, n as hash, t as bytesToHex } from "./crypto--3ycICW4.mjs";
1
+ import { i as randomBytes, n as hash, t as bytesToHex } from "./crypto-CV91nSbp.mjs";
2
2
  //#region src/dash-client.ts
3
3
  function resolveDashUserId(input, options) {
4
4
  return input.userId || options?.resolveUserId?.({
@@ -58,6 +58,21 @@ async function identify($kv, payload) {
58
58
  });
59
59
  }
60
60
  //#endregion
61
+ //#region src/sentinel/identify-client-options.ts
62
+ function resolveIdentifyClientRetry(retry) {
63
+ return {
64
+ type: "exponential",
65
+ attempts: retry?.attempts ?? 2,
66
+ baseDelay: retry?.baseDelay ?? 400,
67
+ maxDelay: retry?.maxDelay ?? 600,
68
+ shouldRetry(response) {
69
+ if (response === null) return true;
70
+ if (response.status === 429) return true;
71
+ return response.status >= 500;
72
+ }
73
+ };
74
+ }
75
+ //#endregion
61
76
  //#region src/sentinel/identify-url.ts
62
77
  const DEFAULT_IDENTIFY_URL = "https://kv.better-auth.com";
63
78
  function normalizeIdentifyUrl(url) {
@@ -105,7 +120,8 @@ async function solvePoWChallenge(challenge) {
105
120
  const { nonce, difficulty } = challenge;
106
121
  let counter = 0;
107
122
  while (true) {
108
- if (hasLeadingZeroBits(await hash(`${nonce}:${counter}`), difficulty)) return {
123
+ const input = `${nonce}:${counter}`;
124
+ if (hasLeadingZeroBits(await hash(input), difficulty)) return {
109
125
  nonce,
110
126
  counter
111
127
  };
@@ -167,4 +183,4 @@ function createPowRetryTimeout(timeoutMs) {
167
183
  };
168
184
  }
169
185
  //#endregion
170
- export { resolveSentinelClientIdentifyUrl as a, dashClient as c, solvePoWChallenge as i, decodePoWChallenge as n, generateRequestId as o, encodePoWSolution as r, identify as s, createPowRetryTimeout as t };
186
+ export { resolveSentinelClientIdentifyUrl as a, identify as c, solvePoWChallenge as i, dashClient as l, decodePoWChallenge as n, resolveIdentifyClientRetry as o, encodePoWSolution as r, generateRequestId as s, createPowRetryTimeout as t };
@@ -0,0 +1,12 @@
1
+ //#region src/directory-sync/saml-policy.ts
2
+ /**
3
+ * `deriveSAMLServiceProviderPolicy` ships in `@better-auth/sso` 1.7.0+.
4
+ * Load it at runtime so typecheck against older matrix versions still succeeds.
5
+ */
6
+ async function requiresSignedSAMLAssertions(config) {
7
+ const sso = await import("@better-auth/sso");
8
+ if (typeof sso.deriveSAMLServiceProviderPolicy === "function") return sso.deriveSAMLServiceProviderPolicy(config).wantAssertionsSigned;
9
+ return config.wantAssertionsSigned === true;
10
+ }
11
+ //#endregion
12
+ export { requiresSignedSAMLAssertions };