@scalar/api-client
Version:
the open source API testing client
65 lines (64 loc) • 1.79 kB
JavaScript
import { generateHash as b } from "@scalar/helpers/string/generate-hash";
import { getResolvedRef as h } from "@scalar/workspace-store/helpers/get-resolved-ref";
import { authOptions as S } from "./auth-options.js";
const l = ({ name: o, value: i }) => ({
id: b(JSON.stringify(i)),
label: o,
value: i,
isDeletable: !0
}), g = (o) => l({
name: Object.keys(o).join(" & "),
value: o
}), u = (o, i) => {
const n = Object.keys(o);
if (n.length > 1)
return g(o);
if (n[0])
return h(i[n[0]]) ? l({ name: n[0], value: o }) : void 0;
}, y = (o, i, n, c = !1) => {
const { requiredFormatted: f, requiredSchemeNames: p, existingIds: d } = o.reduce(
(e, t) => {
const s = u(t, i);
s && (e.requiredFormatted.push(s), e.existingIds.add(s.id));
for (const r of Object.keys(t))
e.requiredSchemeNames.add(r);
return e;
},
{
requiredFormatted: [],
requiredSchemeNames: /* @__PURE__ */ new Set(),
existingIds: /* @__PURE__ */ new Set()
}
), a = [];
for (const [e, t] of Object.entries(i)) {
if (p.has(e))
continue;
if (h(t)) {
const r = l({ name: e, value: { [e]: [] } });
a.push(r), d.add(r.id);
}
}
for (const e of n) {
const t = u(e, i);
t && !d.has(t.id) && (a.push(t), d.add(t.id));
}
const m = [
{ label: "Required authentication", options: f },
{ label: "Available authentication", options: a }
];
return c ? (m.push({
label: "Add new authentication",
options: Object.entries(S).map(([e, t]) => ({
id: e,
label: t.label,
value: { [e]: [] },
payload: t.payload,
isDeletable: !1
}))
}), m) : f.length ? m : a;
};
export {
g as formatComplexScheme,
l as formatScheme,
y as getSecuritySchemeOptions
};