@cedvict/http-guardian 0.0.1-next.8 → 0.0.1-next.9
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 +66 -0
- package/dist/guards/bearerRefreshGuard.d.ts +45 -0
- package/dist/guards/bearerRefreshGuard.d.ts.map +1 -0
- package/dist/guards/correlationIdGuard.d.ts +18 -0
- package/dist/guards/correlationIdGuard.d.ts.map +1 -0
- package/dist/guards/csrfGuard.d.ts +25 -0
- package/dist/guards/csrfGuard.d.ts.map +1 -0
- package/dist/guards/idempotencyGuard.d.ts +25 -0
- package/dist/guards/idempotencyGuard.d.ts.map +1 -0
- package/dist/index.cjs +325 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +321 -5
- package/dist/index.js.map +1 -1
- package/dist/internal/context.d.ts +26 -0
- package/dist/internal/context.d.ts.map +1 -1
- package/dist/parsing/apiParserStructured.d.ts +94 -0
- package/dist/parsing/apiParserStructured.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -5,6 +5,10 @@ export * from "./auth/authConfig.js";
|
|
|
5
5
|
export * from "./guards/types.js";
|
|
6
6
|
export * from "./guards/retryGuard.js";
|
|
7
7
|
export * from "./guards/cookieSafeRefreshGuard.js";
|
|
8
|
+
export * from "./guards/bearerRefreshGuard.js";
|
|
9
|
+
export * from "./guards/csrfGuard.js";
|
|
10
|
+
export * from "./guards/correlationIdGuard.js";
|
|
11
|
+
export * from "./guards/idempotencyGuard.js";
|
|
8
12
|
export * from "./guards/unauthorizedGuard.js";
|
|
9
13
|
export * from "./guards/instrumentGuard.js";
|
|
10
14
|
export * from "./cache/types.js";
|
|
@@ -12,11 +16,12 @@ export * from "./cache/memoryCache.js";
|
|
|
12
16
|
export * from "./parsing/shapeParser.js";
|
|
13
17
|
export * from "./parsing/schemaAdapter.js";
|
|
14
18
|
export * from "./parsing/presets.js";
|
|
19
|
+
export * from "./parsing/apiParserStructured.js";
|
|
15
20
|
export * from "./notify/types.js";
|
|
16
21
|
export * from "./notify/defaults.js";
|
|
17
22
|
export * from "./presets/presetBuilder.js";
|
|
18
23
|
export * from "./plugins/types.js";
|
|
19
24
|
export * from "./aliases.js";
|
|
20
|
-
export type { RequestContext } from "./internal/context.js";
|
|
25
|
+
export type { RequestContext, RequestContextMeta } from "./internal/context.js";
|
|
21
26
|
export type * from "./publicTypes.js";
|
|
22
27
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,sBAAsB,CAAC;AAErC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oCAAoC,CAAC;AACnD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAE5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AAEnC,cAAc,sBAAsB,CAAC;AAErC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,cAAc,oCAAoC,CAAC;AACnD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,6BAA6B,CAAC;AAE5C,cAAc,kBAAkB,CAAC;AACjC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,sBAAsB,CAAC;AACrC,cAAc,kCAAkC,CAAC;AAEjD,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AAErC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,oBAAoB,CAAC;AAGnC,cAAc,cAAc,CAAC;AAG7B,YAAY,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChF,mBAAmB,kBAAkB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -855,6 +855,250 @@ function cookieSafeRefreshGuard(opts) {
|
|
|
855
855
|
}
|
|
856
856
|
}
|
|
857
857
|
|
|
858
|
+
// src/guards/bearerRefreshGuard.ts
|
|
859
|
+
var REFRESH_FLAG2 = "__hg_bearer_refresh_in_flight__";
|
|
860
|
+
var RETRY_FLAG2 = "__hg_bearer_refresh_retry__";
|
|
861
|
+
function isReplayableBody2(body) {
|
|
862
|
+
if (body == null) return true;
|
|
863
|
+
if (typeof body === "string") return true;
|
|
864
|
+
if (typeof Blob !== "undefined" && body instanceof Blob) return true;
|
|
865
|
+
if (typeof FormData !== "undefined" && body instanceof FormData) return true;
|
|
866
|
+
if (typeof URLSearchParams !== "undefined" && body instanceof URLSearchParams) return true;
|
|
867
|
+
if (typeof ArrayBuffer !== "undefined" && body instanceof ArrayBuffer) return true;
|
|
868
|
+
if (typeof Uint8Array !== "undefined" && body instanceof Uint8Array) return true;
|
|
869
|
+
return false;
|
|
870
|
+
}
|
|
871
|
+
function bearerRefreshGuard(opts) {
|
|
872
|
+
const trigger = new Set(opts.triggerStatuses ?? [401]);
|
|
873
|
+
const queueTimeoutMs = opts.queueTimeoutMs ?? 3e4;
|
|
874
|
+
let refreshPromise = null;
|
|
875
|
+
return async (ctx, next) => {
|
|
876
|
+
const anyCtx = ctx;
|
|
877
|
+
if (ctx.noAuth) return next(ctx);
|
|
878
|
+
if (ctx.auth.mode !== "bearer") return next(ctx);
|
|
879
|
+
if (opts.skipRefreshFor?.(ctx)) return next(ctx);
|
|
880
|
+
if (anyCtx[RETRY_FLAG2]) return next(ctx);
|
|
881
|
+
if (anyCtx[REFRESH_FLAG2]) return next(ctx);
|
|
882
|
+
const res = await next(ctx);
|
|
883
|
+
if (!trigger.has(res.status)) return res;
|
|
884
|
+
if (!isReplayableBody2(ctx.body)) return res;
|
|
885
|
+
try {
|
|
886
|
+
await withTimeout(
|
|
887
|
+
refreshPromise ??= runRefresh(opts).finally(() => {
|
|
888
|
+
refreshPromise = null;
|
|
889
|
+
}),
|
|
890
|
+
queueTimeoutMs
|
|
891
|
+
);
|
|
892
|
+
} catch {
|
|
893
|
+
return res;
|
|
894
|
+
}
|
|
895
|
+
const retryCtx = cloneCtxForReplay(ctx);
|
|
896
|
+
retryCtx[RETRY_FLAG2] = true;
|
|
897
|
+
await applyBearerAuth(retryCtx, ctx.auth);
|
|
898
|
+
return next(retryCtx);
|
|
899
|
+
};
|
|
900
|
+
async function runRefresh(o) {
|
|
901
|
+
try {
|
|
902
|
+
const tokens = await o.refreshFn();
|
|
903
|
+
if (o.onTokenRefreshed) await o.onTokenRefreshed(tokens);
|
|
904
|
+
return tokens;
|
|
905
|
+
} catch (e) {
|
|
906
|
+
if (o.onAuthFailed) {
|
|
907
|
+
try {
|
|
908
|
+
await o.onAuthFailed(e);
|
|
909
|
+
} catch {
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
throw e;
|
|
913
|
+
}
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
function cloneCtxForReplay(ctx) {
|
|
917
|
+
return Object.assign({}, ctx, { attempt: ctx.attempt + 1 });
|
|
918
|
+
}
|
|
919
|
+
async function applyBearerAuth(ctx, auth) {
|
|
920
|
+
const headerName = auth.headerName ?? "Authorization";
|
|
921
|
+
const prefix = auth.prefix ?? "Bearer";
|
|
922
|
+
const token = await auth.getToken();
|
|
923
|
+
if (token == null || token === "") {
|
|
924
|
+
ctx.headers.delete(headerName);
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
ctx.headers.set(headerName, prefix ? `${prefix} ${token}` : String(token));
|
|
928
|
+
}
|
|
929
|
+
function withTimeout(p, ms) {
|
|
930
|
+
if (!Number.isFinite(ms) || ms <= 0) return p;
|
|
931
|
+
return new Promise((resolve, reject) => {
|
|
932
|
+
const t = setTimeout(() => reject(new Error(`bearerRefreshGuard: queue timeout after ${ms}ms`)), ms);
|
|
933
|
+
p.then(
|
|
934
|
+
(v) => {
|
|
935
|
+
clearTimeout(t);
|
|
936
|
+
resolve(v);
|
|
937
|
+
},
|
|
938
|
+
(e) => {
|
|
939
|
+
clearTimeout(t);
|
|
940
|
+
reject(e);
|
|
941
|
+
}
|
|
942
|
+
);
|
|
943
|
+
});
|
|
944
|
+
}
|
|
945
|
+
|
|
946
|
+
// src/guards/csrfGuard.ts
|
|
947
|
+
var DEFAULT_METHODS = ["POST", "PUT", "PATCH", "DELETE"];
|
|
948
|
+
function readCookie(name) {
|
|
949
|
+
if (typeof document === "undefined") return null;
|
|
950
|
+
const cookieStr = document.cookie;
|
|
951
|
+
if (typeof cookieStr !== "string" || cookieStr.length === 0) return null;
|
|
952
|
+
const target = encodeURIComponent(name);
|
|
953
|
+
const parts = cookieStr.split(";");
|
|
954
|
+
for (const part of parts) {
|
|
955
|
+
const eq = part.indexOf("=");
|
|
956
|
+
if (eq === -1) continue;
|
|
957
|
+
const k = part.slice(0, eq).trim();
|
|
958
|
+
if (k === name || k === target) {
|
|
959
|
+
return decodeURIComponent(part.slice(eq + 1).trim());
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
return null;
|
|
963
|
+
}
|
|
964
|
+
function csrfGuard(opts = {}) {
|
|
965
|
+
const headerName = opts.headerName ?? "X-CSRF-Token";
|
|
966
|
+
const methods = new Set((opts.applyTo ?? DEFAULT_METHODS).map((m) => m.toUpperCase()));
|
|
967
|
+
let cachedHeaderToken = null;
|
|
968
|
+
return async (ctx, next) => {
|
|
969
|
+
if (!methods.has(ctx.method)) return next(ctx);
|
|
970
|
+
if (ctx.headers.has(headerName)) {
|
|
971
|
+
const res2 = await next(ctx);
|
|
972
|
+
maybeReadResponseHeader(res2);
|
|
973
|
+
return res2;
|
|
974
|
+
}
|
|
975
|
+
const token = await resolveToken();
|
|
976
|
+
if (token != null && token !== "") {
|
|
977
|
+
ctx.headers.set(headerName, token);
|
|
978
|
+
}
|
|
979
|
+
const res = await next(ctx);
|
|
980
|
+
maybeReadResponseHeader(res);
|
|
981
|
+
return res;
|
|
982
|
+
};
|
|
983
|
+
async function resolveToken(_ctx) {
|
|
984
|
+
if (opts.tokenFromCookie) {
|
|
985
|
+
const t = readCookie(opts.tokenFromCookie);
|
|
986
|
+
if (t != null && t !== "") return t;
|
|
987
|
+
}
|
|
988
|
+
if (opts.tokenFromHeader && cachedHeaderToken != null) {
|
|
989
|
+
return cachedHeaderToken;
|
|
990
|
+
}
|
|
991
|
+
if (opts.tokenFromStorage) {
|
|
992
|
+
try {
|
|
993
|
+
const t = await opts.tokenFromStorage();
|
|
994
|
+
if (t != null && t !== "") return t;
|
|
995
|
+
} catch {
|
|
996
|
+
return null;
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
return null;
|
|
1000
|
+
}
|
|
1001
|
+
function maybeReadResponseHeader(res) {
|
|
1002
|
+
if (!opts.tokenFromHeader) return;
|
|
1003
|
+
try {
|
|
1004
|
+
const v = res.headers?.get?.(opts.tokenFromHeader);
|
|
1005
|
+
if (v != null && v !== "") cachedHeaderToken = v;
|
|
1006
|
+
} catch {
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
// src/guards/correlationIdGuard.ts
|
|
1012
|
+
var CORRELATION_FLAG = "__hg_correlation_id__";
|
|
1013
|
+
function defaultGenerator() {
|
|
1014
|
+
const c = globalThis.crypto;
|
|
1015
|
+
if (c && typeof c.randomUUID === "function") {
|
|
1016
|
+
try {
|
|
1017
|
+
return c.randomUUID();
|
|
1018
|
+
} catch {
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
const ts = Date.now().toString(36);
|
|
1022
|
+
const r1 = Math.floor(Math.random() * 4294967295).toString(36);
|
|
1023
|
+
const r2 = Math.floor(Math.random() * 4294967295).toString(36);
|
|
1024
|
+
return `${ts}-${r1}${r2}`;
|
|
1025
|
+
}
|
|
1026
|
+
function correlationIdGuard(opts = {}) {
|
|
1027
|
+
const headerName = opts.headerName ?? "X-Correlation-Id";
|
|
1028
|
+
const generator = opts.generator ?? defaultGenerator;
|
|
1029
|
+
const readResponseHeader = opts.readResponseHeader ?? true;
|
|
1030
|
+
return async (ctx, next) => {
|
|
1031
|
+
const anyCtx = ctx;
|
|
1032
|
+
let id = anyCtx[CORRELATION_FLAG] ?? void 0;
|
|
1033
|
+
if (id == null) {
|
|
1034
|
+
const existing = ctx.headers.get(headerName);
|
|
1035
|
+
id = existing != null && existing !== "" ? existing : generator();
|
|
1036
|
+
anyCtx[CORRELATION_FLAG] = id;
|
|
1037
|
+
}
|
|
1038
|
+
if (!ctx.headers.has(headerName)) {
|
|
1039
|
+
ctx.headers.set(headerName, id);
|
|
1040
|
+
}
|
|
1041
|
+
if (!ctx.meta) ctx.meta = {};
|
|
1042
|
+
if (!ctx.meta.correlationId) ctx.meta.correlationId = id;
|
|
1043
|
+
const res = await next(ctx);
|
|
1044
|
+
if (readResponseHeader) {
|
|
1045
|
+
try {
|
|
1046
|
+
const v = res.headers?.get?.(headerName);
|
|
1047
|
+
if (v != null && v !== "") {
|
|
1048
|
+
if (!ctx.meta) ctx.meta = {};
|
|
1049
|
+
ctx.meta.correlationId = v;
|
|
1050
|
+
}
|
|
1051
|
+
} catch {
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
return res;
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
// src/guards/idempotencyGuard.ts
|
|
1059
|
+
var DEFAULT_METHODS2 = ["POST", "PUT", "PATCH"];
|
|
1060
|
+
var IDEMPOTENCY_FLAG = "__hg_idempotency_key__";
|
|
1061
|
+
function defaultGenerator2() {
|
|
1062
|
+
const c = globalThis.crypto;
|
|
1063
|
+
if (c && typeof c.randomUUID === "function") {
|
|
1064
|
+
try {
|
|
1065
|
+
return c.randomUUID();
|
|
1066
|
+
} catch {
|
|
1067
|
+
}
|
|
1068
|
+
}
|
|
1069
|
+
const ts = Date.now().toString(36);
|
|
1070
|
+
const r1 = Math.floor(Math.random() * 4294967295).toString(36);
|
|
1071
|
+
const r2 = Math.floor(Math.random() * 4294967295).toString(36);
|
|
1072
|
+
return `${ts}-${r1}${r2}`;
|
|
1073
|
+
}
|
|
1074
|
+
function idempotencyGuard(opts = {}) {
|
|
1075
|
+
const headerName = opts.headerName ?? "X-Idempotency-Key";
|
|
1076
|
+
const methods = new Set((opts.applyTo ?? DEFAULT_METHODS2).map((m) => m.toUpperCase()));
|
|
1077
|
+
const generator = opts.generator ?? defaultGenerator2;
|
|
1078
|
+
const respectExisting = opts.respectExisting ?? true;
|
|
1079
|
+
return async (ctx, next) => {
|
|
1080
|
+
if (!methods.has(ctx.method)) return next(ctx);
|
|
1081
|
+
const anyCtx = ctx;
|
|
1082
|
+
let key = anyCtx[IDEMPOTENCY_FLAG] ?? void 0;
|
|
1083
|
+
if (key == null && respectExisting) {
|
|
1084
|
+
const fromHeader = ctx.headers.get(headerName);
|
|
1085
|
+
if (fromHeader != null && fromHeader !== "") {
|
|
1086
|
+
key = fromHeader;
|
|
1087
|
+
} else if (ctx.idempotencyKey != null && ctx.idempotencyKey !== "") {
|
|
1088
|
+
key = ctx.idempotencyKey;
|
|
1089
|
+
} else if (ctx.meta?.idempotencyKey != null && ctx.meta.idempotencyKey !== "") {
|
|
1090
|
+
key = ctx.meta.idempotencyKey;
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
if (key == null) key = generator();
|
|
1094
|
+
anyCtx[IDEMPOTENCY_FLAG] = key;
|
|
1095
|
+
if (!ctx.headers.has(headerName)) ctx.headers.set(headerName, key);
|
|
1096
|
+
if (!ctx.meta) ctx.meta = {};
|
|
1097
|
+
if (!ctx.meta.idempotencyKey) ctx.meta.idempotencyKey = key;
|
|
1098
|
+
return next(ctx);
|
|
1099
|
+
};
|
|
1100
|
+
}
|
|
1101
|
+
|
|
858
1102
|
// src/guards/unauthorizedGuard.ts
|
|
859
1103
|
function normalizePath2(url) {
|
|
860
1104
|
try {
|
|
@@ -902,8 +1146,8 @@ function unauthorizedGuard(opts) {
|
|
|
902
1146
|
}
|
|
903
1147
|
|
|
904
1148
|
// src/guards/instrumentGuard.ts
|
|
905
|
-
var
|
|
906
|
-
var
|
|
1149
|
+
var REFRESH_FLAG3 = "__hg_is_refresh__";
|
|
1150
|
+
var RETRY_FLAG3 = "__hg_refresh_retry__";
|
|
907
1151
|
function safeUrl(u) {
|
|
908
1152
|
try {
|
|
909
1153
|
const url = new URL(u);
|
|
@@ -947,8 +1191,8 @@ function instrumentGuard(opts, guard) {
|
|
|
947
1191
|
}
|
|
948
1192
|
const anyCtx = ctx;
|
|
949
1193
|
const attempt = ctx.attempt ?? 0;
|
|
950
|
-
const isRefresh = Boolean(anyCtx[
|
|
951
|
-
const retryCount = Number(anyCtx[
|
|
1194
|
+
const isRefresh = Boolean(anyCtx[REFRESH_FLAG3]);
|
|
1195
|
+
const retryCount = Number(anyCtx[RETRY_FLAG3] ?? 0);
|
|
952
1196
|
const noAuth2 = Boolean(ctx.noAuth);
|
|
953
1197
|
const baseLine = `[HG][#${id}][${opts.name}]`;
|
|
954
1198
|
log(`${baseLine} \u25B6 start`, {
|
|
@@ -1184,6 +1428,78 @@ function createApiParserGraphQL(opts) {
|
|
|
1184
1428
|
});
|
|
1185
1429
|
}
|
|
1186
1430
|
|
|
1431
|
+
// src/parsing/apiParserStructured.ts
|
|
1432
|
+
function isRecord(v) {
|
|
1433
|
+
return !!v && typeof v === "object" && !Array.isArray(v);
|
|
1434
|
+
}
|
|
1435
|
+
function pickString(o, key) {
|
|
1436
|
+
const v = o[key];
|
|
1437
|
+
return typeof v === "string" ? v : void 0;
|
|
1438
|
+
}
|
|
1439
|
+
function createApiParserStructured(opts = {}) {
|
|
1440
|
+
const exposeMeta = opts.exposeMeta ?? true;
|
|
1441
|
+
const honorRetryableHint = opts.honorRetryableHint ?? true;
|
|
1442
|
+
return createShapeParser({
|
|
1443
|
+
isSuccess: (raw, status) => {
|
|
1444
|
+
if (isRecord(raw) && "success" in raw) return raw["success"] === true;
|
|
1445
|
+
return status >= 200 && status < 400;
|
|
1446
|
+
},
|
|
1447
|
+
getData: (raw) => {
|
|
1448
|
+
if (isRecord(raw) && raw["success"] === true && "data" in raw) {
|
|
1449
|
+
return raw["data"];
|
|
1450
|
+
}
|
|
1451
|
+
return raw;
|
|
1452
|
+
},
|
|
1453
|
+
getErrors: (raw, status) => {
|
|
1454
|
+
if (!isRecord(raw)) {
|
|
1455
|
+
return [{ message: status ? `HTTP ${status}` : "Request failed" }];
|
|
1456
|
+
}
|
|
1457
|
+
const env = raw;
|
|
1458
|
+
const meta = isRecord(env["meta"]) ? env["meta"] : void 0;
|
|
1459
|
+
const traceId = meta?.traceId;
|
|
1460
|
+
const spanId = meta?.spanId;
|
|
1461
|
+
const issues = Array.isArray(env["issues"]) ? env["issues"] : [];
|
|
1462
|
+
const topMessage = pickString(env, "message");
|
|
1463
|
+
const topCode = pickString(env, "code");
|
|
1464
|
+
const topI18n = isRecord(env["i18n"]) ? env["i18n"] : void 0;
|
|
1465
|
+
const baseDetails = (extra = {}) => ({
|
|
1466
|
+
...traceId !== void 0 ? { traceId } : {},
|
|
1467
|
+
...spanId !== void 0 ? { spanId } : {},
|
|
1468
|
+
...exposeMeta ? { envelope: env } : {},
|
|
1469
|
+
...extra
|
|
1470
|
+
});
|
|
1471
|
+
if (issues.length > 0) {
|
|
1472
|
+
return issues.map((iss) => {
|
|
1473
|
+
const message = iss.message ?? topMessage ?? (status ? `HTTP ${status}` : "Request failed");
|
|
1474
|
+
const code = iss.code ?? topCode;
|
|
1475
|
+
const issueDetails = baseDetails({
|
|
1476
|
+
...iss.category !== void 0 ? { category: iss.category } : {},
|
|
1477
|
+
...iss.severity !== void 0 ? { severity: iss.severity } : {},
|
|
1478
|
+
...honorRetryableHint && iss.retryable !== void 0 ? { retryable: iss.retryable } : {},
|
|
1479
|
+
...iss.i18n !== void 0 ? { i18n: iss.i18n } : topI18n !== void 0 ? { i18n: topI18n } : {}
|
|
1480
|
+
});
|
|
1481
|
+
return {
|
|
1482
|
+
message,
|
|
1483
|
+
...code !== void 0 ? { code } : {},
|
|
1484
|
+
...iss.field !== void 0 ? { field: iss.field } : {},
|
|
1485
|
+
details: issueDetails
|
|
1486
|
+
};
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
const details = baseDetails({
|
|
1490
|
+
...topI18n !== void 0 ? { i18n: topI18n } : {}
|
|
1491
|
+
});
|
|
1492
|
+
return [
|
|
1493
|
+
{
|
|
1494
|
+
message: topMessage ?? (status ? `HTTP ${status}` : "Request failed"),
|
|
1495
|
+
...topCode !== void 0 ? { code: topCode } : {},
|
|
1496
|
+
details
|
|
1497
|
+
}
|
|
1498
|
+
];
|
|
1499
|
+
}
|
|
1500
|
+
});
|
|
1501
|
+
}
|
|
1502
|
+
|
|
1187
1503
|
// src/presets/presetBuilder.ts
|
|
1188
1504
|
function createPresetBuilder(init) {
|
|
1189
1505
|
const state = {
|
|
@@ -1374,6 +1690,6 @@ function createClient(opts) {
|
|
|
1374
1690
|
return createHttpClient(cfg);
|
|
1375
1691
|
}
|
|
1376
1692
|
|
|
1377
|
-
export { ILLEGAL_INVOCATION_HINT, NetworkError, ParseError, RedirectError, TimeoutError, alertNotifier, apiKeyAuth, basicAuth, bearerAuth, consoleNotifier, cookieAuth, cookieSafeRefreshGuard, createApiKeyClient, createApiParserGraphQL, createApiParserLaravel, createApiParserNest, createApiParserRestClassic, createBasicClient, createBearerClient, createClient, createCookieClient, createHttpClient, createPresetBuilder, createShapeParser, createSimpleClient, fromZod, instrumentGuard, memoryCache, noAuth, retryGuard, schema, tailwindAlertRenderer, unauthorizedGuard };
|
|
1693
|
+
export { ILLEGAL_INVOCATION_HINT, NetworkError, ParseError, RedirectError, TimeoutError, alertNotifier, apiKeyAuth, basicAuth, bearerAuth, bearerRefreshGuard, consoleNotifier, cookieAuth, cookieSafeRefreshGuard, correlationIdGuard, createApiKeyClient, createApiParserGraphQL, createApiParserLaravel, createApiParserNest, createApiParserRestClassic, createApiParserStructured, createBasicClient, createBearerClient, createClient, createCookieClient, createHttpClient, createPresetBuilder, createShapeParser, createSimpleClient, csrfGuard, fromZod, idempotencyGuard, instrumentGuard, memoryCache, noAuth, retryGuard, schema, tailwindAlertRenderer, unauthorizedGuard };
|
|
1378
1694
|
//# sourceMappingURL=index.js.map
|
|
1379
1695
|
//# sourceMappingURL=index.js.map
|