@adyen/adyen-platform-experience-web
Version:

90 lines (89 loc) • 2.64 kB
JavaScript
import a from "../Errors/AdyenPlatformExperienceError.js";
import { isNullish as i } from "../../utils/value/is.js";
const c = /^[^]*?filename[^;\n]*=\s*(?:UTF-\d['"]*)?(?:(['"])([^]*?)\1|([^;\n]*))?[^]*?$/;
var R = /* @__PURE__ */ ((e) => (e.HTTP_ERROR = "HTTP_ERROR", e.NETWORK_ERROR = "NETWORK_ERROR", e.CANCEL = "CANCEL", e.IMPLEMENTATION_ERROR = "IMPLEMENTATION_ERROR", e.ERROR = "ERROR", e.EXPIRED_TOKEN = "EXPIRED_TOKEN", e))(R || {});
const p = (e) => {
switch (e) {
case 401:
return "EXPIRED_TOKEN";
default:
return "HTTP_ERROR";
}
}, f = (e) => {
var n;
return (n = e.headers.get("Content-Type")) == null ? void 0 : n.split(";", 1)[0];
}, u = (e) => {
const t = (e.headers.get("Content-Disposition") ?? "").replace(c, "$2$3");
return decodeURIComponent(t);
}, E = (e, n) => {
switch (n) {
case "application/json":
return JSON.stringify(e);
case "multipart/form-data":
return e instanceof FormData ? e : new FormData();
default:
return String(e);
}
}, O = (e) => {
var s;
const { headers: n = [], method: t = "GET" } = e, r = "1.6.1", o = ((s = e.contentType) == null ? void 0 : s.toLowerCase()) ?? "application/json";
return {
method: t,
mode: "cors",
cache: "default",
credentials: "same-origin",
headers: {
Accept: "application/json, text/plain, */*",
...n,
// Skip Content-Type header for multipart/form-data requests
// The browser will automatically set the content-type for such requests
...o && o !== "multipart/form-data" && { "Content-Type": o },
"SDK-Version": r
},
redirect: "follow",
signal: e.signal,
referrerPolicy: "no-referrer-when-downgrade",
...t === "POST" && e.body && { body: E(e.body, o) }
};
};
function T({
message: e,
level: n,
errorCode: t,
type: r = "NETWORK_ERROR",
requestId: o
}) {
switch (n) {
case "silent":
break;
case "info":
case "warn":
console[n](e);
break;
case "error":
default:
throw new a(r, o, e, t);
}
}
function m(e) {
return e && e.errorCode && e.type && (e.detail || e.invalidFields) && e.status;
}
function h(e) {
const n = new URLSearchParams();
for (const t of Object.keys(e)) {
const r = e[t];
i(r) || (Array.isArray(r) ? r.forEach((o) => n.append(t, o)) : n.set(t, String(r)));
}
return n;
}
export {
R as ErrorTypes,
p as getErrorType,
E as getRequestBodyForContentType,
O as getRequestObject,
f as getResponseContentType,
u as getResponseDownloadFilename,
T as handleFetchError,
m as isAdyenErrorResponse,
h as parseSearchParams
};