@better-auth/infra 0.2.10 → 0.2.11
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.mjs +48 -41
- package/dist/index.d.mts +1 -1
- package/dist/index.mjs +1 -1
- package/dist/native.mjs +47 -40
- package/package.json +1 -1
package/dist/client.mjs
CHANGED
|
@@ -422,6 +422,8 @@ async function waitForIdentify(timeoutMs) {
|
|
|
422
422
|
}
|
|
423
423
|
//#endregion
|
|
424
424
|
//#region src/sentinel/client.ts
|
|
425
|
+
/** One recovery round after a consumed or superseded challenge (e.g. double-submit). */
|
|
426
|
+
const MAX_POW_CHALLENGE_ROUNDS = 2;
|
|
425
427
|
const sentinelClient = (options) => {
|
|
426
428
|
const autoSolve = options?.autoSolveChallenge !== false;
|
|
427
429
|
const $kv = createKV({
|
|
@@ -470,50 +472,55 @@ const sentinelClient = (options) => {
|
|
|
470
472
|
async onResponse(context) {
|
|
471
473
|
if (typeof window === "undefined") return context;
|
|
472
474
|
if (context.response.status !== 423 || !autoSolve) return context;
|
|
473
|
-
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
const
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
const
|
|
481
|
-
|
|
482
|
-
const
|
|
483
|
-
options?.
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
const retryHeaders = new Headers();
|
|
487
|
-
retryHeaders.set("X-PoW-Solution", encodePoWSolution(solution));
|
|
488
|
-
if (fingerprint) {
|
|
489
|
-
retryHeaders.set("X-Visitor-Id", fingerprint.visitorId);
|
|
490
|
-
retryHeaders.set("X-Request-Id", fingerprint.requestId);
|
|
491
|
-
}
|
|
492
|
-
retryHeaders.set("Content-Type", "application/json");
|
|
493
|
-
let body;
|
|
494
|
-
if (context.request && context.request.body) body = context.request._originalBody;
|
|
495
|
-
const req = context.request;
|
|
496
|
-
const powRetry = createPowRetryTimeout(req.timeout);
|
|
475
|
+
if (!context.response.headers.get("X-PoW-Challenge")) return context;
|
|
476
|
+
const req = context.request;
|
|
477
|
+
let response = context.response;
|
|
478
|
+
const url = response.url;
|
|
479
|
+
const body = req._originalBody;
|
|
480
|
+
for (let round = 0; round < MAX_POW_CHALLENGE_ROUNDS; round++) {
|
|
481
|
+
if (response.status !== 423) break;
|
|
482
|
+
const challengeHeader = response.headers.get("X-PoW-Challenge");
|
|
483
|
+
if (!challengeHeader) break;
|
|
484
|
+
const reason = response.headers.get("X-PoW-Reason") || "";
|
|
485
|
+
options?.onChallengeReceived?.(reason);
|
|
486
|
+
const challenge = decodePoWChallenge(challengeHeader);
|
|
487
|
+
if (!challenge) break;
|
|
497
488
|
try {
|
|
498
|
-
const
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
489
|
+
const startTime = Date.now();
|
|
490
|
+
const solution = await solvePoWChallenge(challenge);
|
|
491
|
+
options?.onChallengeSolved?.(Date.now() - startTime);
|
|
492
|
+
const fingerprint = await getFingerprint();
|
|
493
|
+
const retryHeaders = new Headers();
|
|
494
|
+
retryHeaders.set("X-PoW-Solution", encodePoWSolution(solution));
|
|
495
|
+
if (fingerprint) {
|
|
496
|
+
retryHeaders.set("X-Visitor-Id", fingerprint.visitorId);
|
|
497
|
+
retryHeaders.set("X-Request-Id", fingerprint.requestId);
|
|
498
|
+
}
|
|
499
|
+
retryHeaders.set("Content-Type", "application/json");
|
|
500
|
+
const powRetry = createPowRetryTimeout(req.timeout);
|
|
501
|
+
try {
|
|
502
|
+
response = await fetch(url, {
|
|
503
|
+
method: req.method || "POST",
|
|
504
|
+
headers: retryHeaders,
|
|
505
|
+
body,
|
|
506
|
+
credentials: "include",
|
|
507
|
+
...powRetry.signal ? { signal: powRetry.signal } : {}
|
|
508
|
+
});
|
|
509
|
+
} finally {
|
|
510
|
+
powRetry.cleanup?.();
|
|
511
|
+
}
|
|
512
|
+
if (response.status !== 423) break;
|
|
513
|
+
if (!response.headers.get("X-PoW-Challenge")) break;
|
|
514
|
+
} catch (error) {
|
|
515
|
+
console.error("[Sentinel] Failed to solve PoW challenge:", error);
|
|
516
|
+
options?.onChallengeFailed?.(error instanceof Error ? error : new Error(String(error)));
|
|
517
|
+
return context;
|
|
511
518
|
}
|
|
512
|
-
} catch (error) {
|
|
513
|
-
console.error("[Sentinel] Failed to solve PoW challenge:", error);
|
|
514
|
-
options?.onChallengeFailed?.(error instanceof Error ? error : new Error(String(error)));
|
|
515
|
-
return context;
|
|
516
519
|
}
|
|
520
|
+
return {
|
|
521
|
+
...context,
|
|
522
|
+
response
|
|
523
|
+
};
|
|
517
524
|
},
|
|
518
525
|
async onRequest(context) {
|
|
519
526
|
if (context.body) context._originalBody = context.body;
|
package/dist/index.d.mts
CHANGED
|
@@ -770,7 +770,7 @@ interface DashIdRow {
|
|
|
770
770
|
id: string;
|
|
771
771
|
}
|
|
772
772
|
//#endregion
|
|
773
|
-
//#region ../../node_modules/.bun/@better-auth+scim@1.6.11+
|
|
773
|
+
//#region ../../node_modules/.bun/@better-auth+scim@1.6.11+25e6a1339d5195dd/node_modules/@better-auth/scim/dist/index.d.mts
|
|
774
774
|
//#region src/types.d.ts
|
|
775
775
|
interface SCIMProvider {
|
|
776
776
|
id: string;
|
package/dist/index.mjs
CHANGED
|
@@ -2794,7 +2794,7 @@ const jwtValidateMiddleware = (options) => {
|
|
|
2794
2794
|
};
|
|
2795
2795
|
//#endregion
|
|
2796
2796
|
//#region src/version.ts
|
|
2797
|
-
const PLUGIN_VERSION = "0.2.
|
|
2797
|
+
const PLUGIN_VERSION = "0.2.11";
|
|
2798
2798
|
//#endregion
|
|
2799
2799
|
//#region src/routes/auth/config.ts
|
|
2800
2800
|
const PLUGIN_OPTIONS_EXCLUDE_KEYS = { stripe: new Set(["stripeClient"]) };
|
package/dist/native.mjs
CHANGED
|
@@ -190,6 +190,8 @@ async function getOrCreateVisitorId(storage) {
|
|
|
190
190
|
}
|
|
191
191
|
//#endregion
|
|
192
192
|
//#region src/sentinel/native/client.ts
|
|
193
|
+
/** One recovery round after a consumed or superseded challenge (e.g. double-submit). */
|
|
194
|
+
const MAX_POW_CHALLENGE_ROUNDS = 2;
|
|
193
195
|
function scheduleIdentify(send) {
|
|
194
196
|
const run = () => {
|
|
195
197
|
try {
|
|
@@ -248,49 +250,54 @@ const sentinelNativeClient = (options) => {
|
|
|
248
250
|
hooks: {
|
|
249
251
|
async onResponse(context) {
|
|
250
252
|
if (context.response.status !== 423 || !autoSolve) return context;
|
|
251
|
-
|
|
252
|
-
const
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
const
|
|
261
|
-
options?.
|
|
262
|
-
const
|
|
263
|
-
|
|
264
|
-
const retryHeaders = new Headers();
|
|
265
|
-
retryHeaders.set("X-PoW-Solution", encodePoWSolution(solution));
|
|
266
|
-
if (fingerprint) {
|
|
267
|
-
retryHeaders.set("X-Visitor-Id", fingerprint.visitorId);
|
|
268
|
-
retryHeaders.set("X-Request-Id", fingerprint.requestId);
|
|
269
|
-
}
|
|
270
|
-
retryHeaders.set("Content-Type", "application/json");
|
|
271
|
-
let body;
|
|
272
|
-
if (context.request?.body) body = context.request._originalBody;
|
|
273
|
-
const req = context.request;
|
|
274
|
-
const powRetry = createPowRetryTimeout(req.timeout);
|
|
253
|
+
if (!context.response.headers.get("X-PoW-Challenge")) return context;
|
|
254
|
+
const req = context.request;
|
|
255
|
+
let response = context.response;
|
|
256
|
+
const url = response.url;
|
|
257
|
+
const body = req._originalBody;
|
|
258
|
+
for (let round = 0; round < MAX_POW_CHALLENGE_ROUNDS; round++) {
|
|
259
|
+
if (response.status !== 423) break;
|
|
260
|
+
const challengeHeader = response.headers.get("X-PoW-Challenge");
|
|
261
|
+
if (!challengeHeader) break;
|
|
262
|
+
const reason = response.headers.get("X-PoW-Reason") || "";
|
|
263
|
+
options?.onChallengeReceived?.(reason);
|
|
264
|
+
const challenge = decodePoWChallenge(challengeHeader);
|
|
265
|
+
if (!challenge) break;
|
|
275
266
|
try {
|
|
276
|
-
const
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
powRetry.
|
|
267
|
+
const startTime = Date.now();
|
|
268
|
+
const solution = await solvePoWChallenge(challenge);
|
|
269
|
+
options?.onChallengeSolved?.(Date.now() - startTime);
|
|
270
|
+
const fingerprint = await runtime.getFingerprint();
|
|
271
|
+
const retryHeaders = new Headers();
|
|
272
|
+
retryHeaders.set("X-PoW-Solution", encodePoWSolution(solution));
|
|
273
|
+
if (fingerprint) {
|
|
274
|
+
retryHeaders.set("X-Visitor-Id", fingerprint.visitorId);
|
|
275
|
+
retryHeaders.set("X-Request-Id", fingerprint.requestId);
|
|
276
|
+
}
|
|
277
|
+
retryHeaders.set("Content-Type", "application/json");
|
|
278
|
+
const powRetry = createPowRetryTimeout(req.timeout);
|
|
279
|
+
try {
|
|
280
|
+
response = await fetch(url, {
|
|
281
|
+
method: req.method || "POST",
|
|
282
|
+
headers: retryHeaders,
|
|
283
|
+
body,
|
|
284
|
+
...powRetry.signal ? { signal: powRetry.signal } : {}
|
|
285
|
+
});
|
|
286
|
+
} finally {
|
|
287
|
+
powRetry.cleanup?.();
|
|
288
|
+
}
|
|
289
|
+
if (response.status !== 423) break;
|
|
290
|
+
if (!response.headers.get("X-PoW-Challenge")) break;
|
|
291
|
+
} catch (err) {
|
|
292
|
+
console.error("[Sentinel native] Failed to solve PoW challenge:", err);
|
|
293
|
+
options?.onChallengeFailed?.(err instanceof Error ? err : new Error(String(err)));
|
|
294
|
+
return context;
|
|
288
295
|
}
|
|
289
|
-
} catch (err) {
|
|
290
|
-
console.error("[Sentinel native] Failed to solve PoW challenge:", err);
|
|
291
|
-
options?.onChallengeFailed?.(err instanceof Error ? err : new Error(String(err)));
|
|
292
|
-
return context;
|
|
293
296
|
}
|
|
297
|
+
return {
|
|
298
|
+
...context,
|
|
299
|
+
response
|
|
300
|
+
};
|
|
294
301
|
},
|
|
295
302
|
async onRequest(context) {
|
|
296
303
|
if (context.body) {
|