UNPKG

@scalar/api-client

Version:

the open source API testing client

242 lines (241 loc) 9.97 kB
import { defineComponent as z, computed as F, ref as P, onMounted as R, createElementBlock as i, openBlock as l, Fragment as s, renderList as U, createBlock as m, createCommentVNode as v, unref as d, withCtx as n, createVNode as u, createElementVNode as $, toDisplayString as A, mergeProps as V, createTextVNode as w, normalizeClass as I, capitalize as x } from "vue"; import { ScalarMarkdown as D } from "@scalar/components"; import { safeLocalStorage as N, CLIENT_LS_KEYS as j } from "@scalar/helpers/object/local-storage"; import { isDefined as B } from "@scalar/oas-utils/helpers"; import { useWorkspace as H } from "../../../../store/store.js"; import { updateScheme as Q } from "../helpers/update-scheme.js"; import q from "./OAuth2.vue.js"; import k from "./RequestAuthDataTableInput.vue.js"; import f from "../../../../components/DataTable/DataTableRow.vue.js"; import L from "../../../../components/DataTable/DataTableCell.vue.js"; const J = { class: "bg-b-1 text-c-2 outline-b-3 top-0 z-1 h-full w-full overflow-hidden px-3 py-1.25 text-ellipsis group-hover/auth:absolute group-hover/auth:h-auto group-hover/auth:border-b *:first:line-clamp-1 *:first:text-ellipsis group-hover/auth:*:first:line-clamp-none" }, Y = { key: 0, class: "flex min-h-8 border-t text-base" }, W = { class: "flex h-8 max-w-full gap-2.5 overflow-x-auto px-3" }, G = ["onClick"], X = { class: "relative z-10" }, ie = /* @__PURE__ */ z({ __name: "RequestAuthTab", props: { collection: {}, environment: {}, envVariables: {}, layout: {}, persistAuth: { type: Boolean, default: !1 }, securitySchemeUids: {}, server: {}, workspace: {} }, setup(c) { const C = H(), { collectionMutators: M, securitySchemes: _, securitySchemeMutators: O } = C, S = F( () => c.securitySchemeUids.map((t) => ({ scheme: _[t] })) ), p = P(""), T = (t) => { const r = t.description ? `: ${t.description}` : "", e = `${x(t.nameKey)}${r || `: ${t.type}`}`; if (t.type === "apiKey") return `${x(t.nameKey)}${r || `: ${t.in}`}`; if (t.type === "oauth2") { const o = Object.values(t.flows ?? {})[0]; return `${x(t.nameKey)}: ${p.value ? p.value : (o == null ? void 0 : o.type) ?? ""}${r}`; } return t.type === "http" ? `${x(t.nameKey)}: ${t.scheme}${r}` : `${e}${r}`; }, g = (t, r, e) => { Q(t, r, e, C, c.persistAuth); }; R(() => { if (!c.persistAuth) return; const t = JSON.parse( N().getItem(j.AUTH) ?? "{}" ), r = Object.keys(_).reduce( (e, o) => { const a = _[o]; return a && (e[a.nameKey] = a.uid), e; }, {} ); Object.entries(t).forEach(([e, o]) => { const a = r[e]; a && Object.entries(o).forEach(([E, K]) => { O.edit(a, E, K); }); }); try { const o = JSON.parse( N().getItem(j.SELECTED_SECURITY_SCHEMES) ?? "" ).map((a) => Array.isArray(a) ? a.map((b) => r[b]).filter(B) : r[a]).filter(B); M.edit(c.collection.uid, "selectedSecuritySchemeUids", o); } catch { } }); const y = { environment: c.environment, envVariables: c.envVariables, workspace: c.workspace }; return (t, r) => (l(!0), i(s, null, U(S.value, ({ scheme: e }) => (l(), i(s, { key: e == null ? void 0 : e.uid }, [ S.value.length > 1 && e ? (l(), m(d(f), { key: 0 }, { default: n(() => [ u(d(L), { "aria-label": T(e), class: "text-c-2 group/auth flex items-center leading-[22px] whitespace-nowrap outline-none hover:whitespace-normal" }, { default: n(() => [ $("p", J, A(T(e)), 1) ]), _: 2 }, 1032, ["aria-label"]) ]), _: 2 }, 1024)) : v("", !0), e != null && e.description && S.value.length <= 1 ? (l(), m(d(f), { key: 1 }, { default: n(() => [ u(d(L), { "aria-label": e.description, class: "text-c-2 group/auth auth-description-container flex items-center whitespace-nowrap outline-none hover:whitespace-normal" }, { default: n(() => [ u(d(D), { class: "auth-description bg-b-1 text-c-2 outline-b-3 top-0 z-1 h-full w-full px-3 py-1.25 group-hover/auth:absolute group-hover/auth:h-auto group-hover/auth:border-b *:first:line-clamp-1 *:first:text-ellipsis group-hover/auth:*:first:line-clamp-none", value: e.description }, null, 8, ["value"]) ]), _: 2 }, 1032, ["aria-label"]) ]), _: 2 }, 1024)) : v("", !0), (e == null ? void 0 : e.type) === "http" ? (l(), i(s, { key: 2 }, [ e.scheme === "bearer" ? (l(), m(d(f), { key: 0 }, { default: n(() => [ u(k, V({ ref_for: !0 }, y, { containerClass: t.layout === "reference" && "border-t", modelValue: e.token, placeholder: "Token", type: "password", "onUpdate:modelValue": (o) => g(e.uid, "token", o) }), { default: n(() => r[0] || (r[0] = [ w(" Bearer Token ") ])), _: 2, __: [0] }, 1040, ["containerClass", "modelValue", "onUpdate:modelValue"]) ]), _: 2 }, 1024)) : (e == null ? void 0 : e.scheme) === "basic" ? (l(), i(s, { key: 1 }, [ u(d(f), null, { default: n(() => [ u(k, V({ ref_for: !0 }, y, { class: "text-c-2", modelValue: e.username, placeholder: "janedoe", required: "", "onUpdate:modelValue": (o) => g(e.uid, "username", o) }), { default: n(() => r[1] || (r[1] = [ w(" Username ") ])), _: 2, __: [1] }, 1040, ["modelValue", "onUpdate:modelValue"]) ]), _: 2 }, 1024), u(d(f), null, { default: n(() => [ u(k, V({ ref_for: !0 }, y, { modelValue: e.password, placeholder: "********", type: "password", "onUpdate:modelValue": (o) => g(e.uid, "password", o) }), { default: n(() => r[2] || (r[2] = [ w(" Password ") ])), _: 2, __: [2] }, 1040, ["modelValue", "onUpdate:modelValue"]) ]), _: 2 }, 1024) ], 64)) : v("", !0) ], 64)) : (e == null ? void 0 : e.type) === "apiKey" ? (l(), i(s, { key: 3 }, [ u(d(f), null, { default: n(() => [ u(k, V({ ref_for: !0 }, y, { containerClass: t.layout === "reference" && "border-t", modelValue: e.name, placeholder: "api-key", "onUpdate:modelValue": (o) => g(e.uid, "name", o) }), { default: n(() => r[3] || (r[3] = [ w(" Name ") ])), _: 2, __: [3] }, 1040, ["containerClass", "modelValue", "onUpdate:modelValue"]) ]), _: 2 }, 1024), u(d(f), null, { default: n(() => [ u(k, V({ ref_for: !0 }, y, { modelValue: e.value, placeholder: "QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT", type: "password", "onUpdate:modelValue": (o) => g(e.uid, "value", o) }), { default: n(() => r[4] || (r[4] = [ w(" Value ") ])), _: 2, __: [4] }, 1040, ["modelValue", "onUpdate:modelValue"]) ]), _: 2 }, 1024) ], 64)) : (e == null ? void 0 : e.type) === "oauth2" ? (l(), i(s, { key: 4 }, [ u(d(f), null, { default: n(() => [ Object.keys(e.flows).length > 1 ? (l(), i("div", Y, [ $("div", W, [ (l(!0), i(s, null, U(e == null ? void 0 : e.flows, (o, a, b) => (l(), i("button", { key: a, class: I(["floating-bg text-c-3 relative cursor-pointer border-b-[1px] border-transparent py-1 text-base font-medium", { "!text-c-1 !rounded-none border-b-[1px] !border-current": t.layout !== "reference" && (p.value === a || b === 0 && !p.value), "!text-c-1 !rounded-none border-b-[1px] !border-current opacity-100": t.layout === "reference" && (p.value === a || b === 0 && !p.value) }]), type: "button", onClick: (E) => p.value = a }, [ $("span", X, A(a), 1) ], 10, G))), 128)) ]) ])) : v("", !0) ]), _: 2 }, 1024), (l(!0), i(s, null, U(e == null ? void 0 : e.flows, (o, a, b) => (l(), i(s, { key: a }, [ p.value === a || b === 0 && !p.value ? (l(), m(q, V({ key: 0, ref_for: !0 }, y, { collection: t.collection, flow: o, persistAuth: t.persistAuth, scheme: e, server: t.server, workspace: t.workspace }), null, 16, ["collection", "flow", "persistAuth", "scheme", "server", "workspace"])) : v("", !0) ], 64))), 128)) ], 64)) : (e == null ? void 0 : e.type) === "openIdConnect" ? (l(), i("div", { key: 5, class: I(["text-c-3 bg-b-1 flex min-h-[calc(4rem+1px)] items-center justify-center border-t border-b-0 px-4 text-base", { "rounded-b-lg": t.layout === "reference" }]) }, " Coming soon ", 2)) : v("", !0) ], 64))), 128)); } }); export { ie as default };