better-call 1.0.18 → 1.0.20
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/README.md +41 -2
- package/dist/client.d.cts +1 -1
- package/dist/client.d.ts +1 -1
- package/dist/index.cjs +43 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +44 -6
- package/dist/index.js.map +1 -1
- package/dist/node.d.cts +1 -1
- package/dist/node.d.ts +1 -1
- package/dist/router-BDQGRZdc.d.cts +2816 -0
- package/dist/router-BDQGRZdc.d.ts +2816 -0
- package/package.json +2 -1
- package/dist/router-DcqXHY8X.d.cts +0 -1285
- package/dist/router-DcqXHY8X.d.ts +0 -1285
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, W as HasRequiredKeys, v as InferBody, I as InferBodyInput, J as InferHeaders, K as InferHeadersInput, z as InferInputMethod, y as InferMethod, N as InferMiddlewareBody, Q as InferMiddlewareQuery, B as InferParam, D as InferParamInput, a0 as InferParamPath, a1 as InferParamWildCard, x as InferQuery, w as InferQueryInput, F as InferRequest, G as InferRequestInput, L as InferUse, T as InputContext, Y as IsEmptyObject, $ as MergeObject, u as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, X as Prettify, V as RequiredKeysOf, j as Router, R as RouterConfig, a2 as StandardSchemaV1, S as Status, Z as UnionToIntersection, _ as _statusCode, c as createEndpoint, U as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, r as hideInternalStackFrames, t as makeErrorForHideStackFrame, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-
|
|
1
|
+
export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, W as HasRequiredKeys, v as InferBody, I as InferBodyInput, J as InferHeaders, K as InferHeadersInput, z as InferInputMethod, y as InferMethod, N as InferMiddlewareBody, Q as InferMiddlewareQuery, B as InferParam, D as InferParamInput, a0 as InferParamPath, a1 as InferParamWildCard, x as InferQuery, w as InferQueryInput, F as InferRequest, G as InferRequestInput, L as InferUse, T as InputContext, Y as IsEmptyObject, $ as MergeObject, u as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, X as Prettify, V as RequiredKeysOf, j as Router, R as RouterConfig, a2 as StandardSchemaV1, S as Status, Z as UnionToIntersection, _ as _statusCode, c as createEndpoint, U as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, r as hideInternalStackFrames, t as makeErrorForHideStackFrame, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-BDQGRZdc.cjs';
|
|
2
2
|
|
|
3
3
|
type JSONResponse = {
|
|
4
4
|
body: Record<string, any>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, W as HasRequiredKeys, v as InferBody, I as InferBodyInput, J as InferHeaders, K as InferHeadersInput, z as InferInputMethod, y as InferMethod, N as InferMiddlewareBody, Q as InferMiddlewareQuery, B as InferParam, D as InferParamInput, a0 as InferParamPath, a1 as InferParamWildCard, x as InferQuery, w as InferQueryInput, F as InferRequest, G as InferRequestInput, L as InferUse, T as InputContext, Y as IsEmptyObject, $ as MergeObject, u as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, X as Prettify, V as RequiredKeysOf, j as Router, R as RouterConfig, a2 as StandardSchemaV1, S as Status, Z as UnionToIntersection, _ as _statusCode, c as createEndpoint, U as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, r as hideInternalStackFrames, t as makeErrorForHideStackFrame, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-
|
|
1
|
+
export { A as APIError, k as CookieOptions, C as CookiePrefixOptions, b as Endpoint, a as EndpointContext, E as EndpointOptions, H as HTTPMethod, W as HasRequiredKeys, v as InferBody, I as InferBodyInput, J as InferHeaders, K as InferHeadersInput, z as InferInputMethod, y as InferMethod, N as InferMiddlewareBody, Q as InferMiddlewareQuery, B as InferParam, D as InferParamInput, a0 as InferParamPath, a1 as InferParamWildCard, x as InferQuery, w as InferQueryInput, F as InferRequest, G as InferRequestInput, L as InferUse, T as InputContext, Y as IsEmptyObject, $ as MergeObject, u as Method, h as Middleware, e as MiddlewareContext, g as MiddlewareInputContext, M as MiddlewareOptions, d as MiddlewareResponse, n as OpenAPIParameter, O as OpenAPISchemaType, P as Path, X as Prettify, V as RequiredKeysOf, j as Router, R as RouterConfig, a2 as StandardSchemaV1, S as Status, Z as UnionToIntersection, _ as _statusCode, c as createEndpoint, U as createInternalContext, f as createMiddleware, i as createRouter, o as generator, l as getCookieKey, q as getHTML, r as hideInternalStackFrames, t as makeErrorForHideStackFrame, p as parseCookies, s as serializeCookie, m as serializeSignedCookie } from './router-BDQGRZdc.js';
|
|
2
2
|
|
|
3
3
|
type JSONResponse = {
|
|
4
4
|
body: Record<string, any>;
|
package/dist/index.js
CHANGED
|
@@ -349,11 +349,14 @@ function fromError(error, validating) {
|
|
|
349
349
|
}
|
|
350
350
|
|
|
351
351
|
// src/crypto.ts
|
|
352
|
-
import {
|
|
352
|
+
import { getWebcryptoSubtle } from "@better-auth/utils";
|
|
353
353
|
var algorithm = { name: "HMAC", hash: "SHA-256" };
|
|
354
354
|
var getCryptoKey = async (secret) => {
|
|
355
355
|
const secretBuf = typeof secret === "string" ? new TextEncoder().encode(secret) : secret;
|
|
356
|
-
return await
|
|
356
|
+
return await getWebcryptoSubtle().importKey("raw", secretBuf, algorithm, false, [
|
|
357
|
+
"sign",
|
|
358
|
+
"verify"
|
|
359
|
+
]);
|
|
357
360
|
};
|
|
358
361
|
var verifySignature = async (base64Signature, value, secret) => {
|
|
359
362
|
try {
|
|
@@ -362,14 +365,23 @@ var verifySignature = async (base64Signature, value, secret) => {
|
|
|
362
365
|
for (let i = 0, len = signatureBinStr.length; i < len; i++) {
|
|
363
366
|
signature[i] = signatureBinStr.charCodeAt(i);
|
|
364
367
|
}
|
|
365
|
-
return await
|
|
368
|
+
return await getWebcryptoSubtle().verify(
|
|
369
|
+
algorithm,
|
|
370
|
+
secret,
|
|
371
|
+
signature,
|
|
372
|
+
new TextEncoder().encode(value)
|
|
373
|
+
);
|
|
366
374
|
} catch (e) {
|
|
367
375
|
return false;
|
|
368
376
|
}
|
|
369
377
|
};
|
|
370
378
|
var makeSignature = async (value, secret) => {
|
|
371
379
|
const key = await getCryptoKey(secret);
|
|
372
|
-
const signature = await
|
|
380
|
+
const signature = await getWebcryptoSubtle().sign(
|
|
381
|
+
algorithm.name,
|
|
382
|
+
key,
|
|
383
|
+
new TextEncoder().encode(value)
|
|
384
|
+
);
|
|
373
385
|
return btoa(String.fromCharCode(...new Uint8Array(signature)));
|
|
374
386
|
};
|
|
375
387
|
var signCookieValue = async (value, secret) => {
|
|
@@ -654,6 +666,7 @@ createMiddleware.create = (opts) => {
|
|
|
654
666
|
};
|
|
655
667
|
|
|
656
668
|
// src/endpoint.ts
|
|
669
|
+
var originalHandlerSymbol = Symbol("kOriginalHandler");
|
|
657
670
|
var createEndpoint2 = (path, options, handler) => {
|
|
658
671
|
const internalHandler = async (...inputCtx) => {
|
|
659
672
|
const context = inputCtx[0] || {};
|
|
@@ -661,7 +674,9 @@ var createEndpoint2 = (path, options, handler) => {
|
|
|
661
674
|
options,
|
|
662
675
|
path
|
|
663
676
|
});
|
|
664
|
-
const response = await
|
|
677
|
+
const response = await internalHandler[originalHandlerSymbol](
|
|
678
|
+
internalContext
|
|
679
|
+
).catch(async (e) => {
|
|
665
680
|
if (isAPIError(e)) {
|
|
666
681
|
const onAPIError = options.onAPIError;
|
|
667
682
|
if (onAPIError) {
|
|
@@ -681,6 +696,13 @@ var createEndpoint2 = (path, options, handler) => {
|
|
|
681
696
|
response
|
|
682
697
|
} : response;
|
|
683
698
|
};
|
|
699
|
+
internalHandler[originalHandlerSymbol] = handler;
|
|
700
|
+
internalHandler.wrap = (fn) => {
|
|
701
|
+
const wrappedFn = async (context) => {
|
|
702
|
+
return fn(context, internalHandler[originalHandlerSymbol]);
|
|
703
|
+
};
|
|
704
|
+
return createEndpoint2(path, options, wrappedFn);
|
|
705
|
+
};
|
|
684
706
|
internalHandler.options = options;
|
|
685
707
|
internalHandler.path = path;
|
|
686
708
|
return internalHandler;
|
|
@@ -699,7 +721,7 @@ createEndpoint2.create = (opts) => {
|
|
|
699
721
|
};
|
|
700
722
|
|
|
701
723
|
// src/router.ts
|
|
702
|
-
import { createRouter as createRou3Router,
|
|
724
|
+
import { addRoute, createRouter as createRou3Router, findAllRoutes, findRoute } from "rou3";
|
|
703
725
|
|
|
704
726
|
// node_modules/.pnpm/zod@4.0.1/node_modules/zod/v4/core/core.js
|
|
705
727
|
var NEVER = Object.freeze({
|
|
@@ -3140,6 +3162,22 @@ var createRouter = (endpoints, config2) => {
|
|
|
3140
3162
|
const response = await handler(context);
|
|
3141
3163
|
return response;
|
|
3142
3164
|
} catch (error) {
|
|
3165
|
+
if (config2?.onError) {
|
|
3166
|
+
try {
|
|
3167
|
+
const errorResponse = await config2.onError(error);
|
|
3168
|
+
if (errorResponse instanceof Response) {
|
|
3169
|
+
return toResponse(errorResponse);
|
|
3170
|
+
}
|
|
3171
|
+
} catch (error2) {
|
|
3172
|
+
if (isAPIError(error2)) {
|
|
3173
|
+
return toResponse(error2);
|
|
3174
|
+
}
|
|
3175
|
+
throw error2;
|
|
3176
|
+
}
|
|
3177
|
+
}
|
|
3178
|
+
if (config2?.throwError) {
|
|
3179
|
+
throw error;
|
|
3180
|
+
}
|
|
3143
3181
|
if (isAPIError(error)) {
|
|
3144
3182
|
return toResponse(error);
|
|
3145
3183
|
}
|