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

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