@scalar/api-client
Version:
the open source API testing client
29 lines (28 loc) • 935 B
JavaScript
import { isDefined as i } from "@scalar/helpers/array/is-defined";
import { safeLocalStorage as n, CLIENT_LS_KEYS as S } from "@scalar/helpers/object/local-storage";
const O = (a, d) => {
try {
const { collectionMutators: c, securitySchemes: o, securitySchemeMutators: m } = a, u = JSON.parse(n().getItem(S.AUTH) ?? "{}"), s = Object.keys(o).reduce(
(e, r) => {
const t = o[r];
return t && (e[t.nameKey] = t.uid), e;
},
{}
);
Object.entries(u).forEach(([e, r]) => {
const t = s[e];
t && Object.entries(r).forEach(([h, l]) => {
m.edit(t, h, l);
});
});
const f = JSON.parse(
n().getItem(S.SELECTED_SECURITY_SCHEMES) ?? "[]"
).map((e) => Array.isArray(e) ? e.map((r) => s[r]).filter(i) : s[e]).filter(i);
c.edit(d, "selectedSecuritySchemeUids", f);
} catch (c) {
console.error(c);
}
};
export {
O as restoreAuthFromLocalStorage
};