UNPKG

@scalar/api-client

Version:

the open source API testing client

32 lines (30 loc) 1.64 kB
import { replaceEnvVariables as n } from "@scalar/helpers/regex/replace-variables"; import { xScalarCookieSchema as l } from "@scalar/workspace-store/schemas/extensions/general/x-scalar-cookies"; import { coerceValue as d } from "@scalar/workspace-store/schemas/typebox-coerce"; import { matchesDomain as f } from "../../../../libs/send-request/set-request-cookies.js"; const c = "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. `, p = (a, o) => { const r = a.map((t) => `${t.name}=${t.value}`).join("; "); return o && r ? `${o}; ${r}` : o || r || ""; }, R = ({ paramCookies: a, globalCookies: o, env: r, path: t, originalCookieHeader: i, url: m, useCustomCookieHeader: u }) => { const h = o.flatMap((e) => e.isDisabled || !e.name || e.domain && !f(m, e.domain) || e.path && !t.startsWith(e.path) ? [] : d(l, { ...e, name: n(e.name, r), value: n(e.value, r) })), s = p([...h, ...a], i); return s ? u ? (console.warn(c), { name: "X-Scalar-Cookie", value: s }) : (console.warn(b), { name: "Cookie", value: s }) : null; }; export { R as buildRequestCookieHeader, p as getCookieHeader };