@scalar/api-client
Version:
the open source API testing client
32 lines (30 loc) • 1.61 kB
JavaScript
import { replaceEnvVariables as i } from "@scalar/helpers/regex/replace-variables";
import { xScalarCookieSchema as c } from "@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies";
import { coerceValue as h } from "@scalar/workspace-store/schemas/typebox-coerce";
import { filterGlobalCookie as f } from "./filter-global-cookies.js";
const d = "We're using a `X-Scalar-Cookie` custom header to the request. The proxy will forward this as a `Cookie` header. We do this to avoid the browser omitting the `Cookie` header for cross-origin requests for security reasons.", b = `We're trying to add a Cookie header, but browsers often omit them for cross-origin requests for various security reasons. If it's not working, that's probably why. Here are the requirements for it to work:
- The browser URL must be on the same domain as the server URL.
- The connection must be made over HTTPS.
`, C = (a, o) => {
const e = a.map((t) => `${t.name}=${t.value}`).join("; ");
return o && e ? `${o}; ${e}` : o || e || "";
}, E = ({
paramCookies: a,
globalCookies: o,
env: e,
originalCookieHeader: t,
url: n,
useCustomCookieHeader: u,
disabledGlobalCookies: m
}) => {
const l = o.filter((r) => f({ cookie: r, url: n, disabledGlobalCookies: m })).map((r) => h(c, {
...r,
name: i(r.name, e),
value: i(r.value, e)
})), s = C([...l, ...a], t ?? void 0);
return s ? u ? (console.warn(d), { name: "X-Scalar-Cookie", value: s }) : (console.warn(b), { name: "Cookie", value: s }) : null;
};
export {
E as buildRequestCookieHeader,
C as getCookieHeader
};