UNPKG

@scalar/api-client

Version:

the open source API testing client

218 lines (217 loc) 8.74 kB
import { defineComponent as A, computed as N, ref as P, createElementBlock as s, openBlock as r, Fragment as d, renderList as C, createBlock as v, createCommentVNode as m, unref as i, withCtx as l, createVNode as n, createElementVNode as k, toDisplayString as R, createTextVNode as y, normalizeClass as z, capitalize as Q } from "vue"; import { ScalarMarkdownSummary as q } from "@scalar/components"; import { getResolvedRef as D } from "@scalar/workspace-store/helpers/get-resolved-ref"; import E from "./OAuth2.vue.js"; import b from "./RequestAuthDataTableInput.vue.js"; import c from "../../../components/data-table/DataTableRow.vue.js"; import I from "../../../components/data-table/DataTableCell.vue.js"; const H = { 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" }, L = { class: "flex min-h-8 border-t text-base" }, _ = { class: "flex h-8 max-w-full gap-2.5 overflow-x-auto px-3" }, G = ["onClick"], J = { class: "relative z-10" }, re = /* @__PURE__ */ A({ __name: "RequestAuthTab", props: { environment: {}, isStatic: { type: Boolean }, selectedSecuritySchemas: {}, securitySchemes: {}, server: {} }, emits: ["update:securityScheme", "update:selectedScopes"], setup(f, { emit: K }) { const x = K, U = N( () => Object.entries(f.selectedSecuritySchemas).map(([o, e]) => ({ scheme: D(f.securitySchemes[o]), name: o, scopes: e })) ), w = P(""), h = N(() => U.value.length > 1), F = (o, e) => { const t = Q(o), u = e.description ? `: ${e.description}` : ""; switch (e.type) { case "apiKey": return `${t}${u || `: ${e.in}`}`; case "oauth2": { const V = Object.keys(e.flows ?? {})[0], a = w.value || V; return `${t}: ${a}${u}`; } case "http": return `${t}: ${e.scheme}${u}`; default: return `${t}${u || `: ${e.type}`}`; } }, T = (o, e) => w.value === o || e === 0 && !w.value, B = () => f.isStatic && "border-t", g = (o, e) => x("update:securityScheme", { type: "http", [o]: e }), j = (o, e) => x("update:securityScheme", { type: "apiKey", [o]: e }), M = (o, e) => { x("update:selectedScopes", { id: Object.keys(f.selectedSecuritySchemas), name: o, ...e }); }, O = (o, e) => { const t = "floating-bg text-c-3 relative cursor-pointer border-b border-transparent py-1 text-base font-medium"; return T(o, e) ? `${t} !text-c-1 !rounded-none border-b !border-current ${f.isStatic ? "opacity-100" : ""}` : t; }; return (o, e) => (r(!0), s(d, null, C(U.value, ({ scheme: t, name: u, scopes: V }) => (r(), s(d, { key: u }, [ h.value && t ? (r(), v(i(c), { key: 0 }, { default: l(() => [ n(i(I), { "aria-label": F(u, t), class: "text-c-2 group/auth flex items-center leading-[22px] whitespace-nowrap outline-none hover:whitespace-normal" }, { default: l(() => [ k("p", H, R(F(u, t)), 1) ]), _: 2 }, 1032, ["aria-label"]) ]), _: 2 }, 1024)) : m("", !0), t?.description && !h.value ? (r(), v(i(c), { key: 1 }, { default: l(() => [ n(i(I), { "aria-label": t.description, class: "max-h-[auto]" }, { default: l(() => [ n(i(q), { class: "auth-description bg-b-1 text-c-2 min-w-0 flex-1 px-3 py-1.25", value: t.description }, null, 8, ["value"]) ]), _: 2 }, 1032, ["aria-label"]) ]), _: 2 }, 1024)) : m("", !0), t?.type === "http" ? (r(), s(d, { key: 2 }, [ t.scheme === "bearer" ? (r(), v(i(c), { key: 0 }, { default: l(() => [ n(b, { containerClass: B(), environment: o.environment, modelValue: t["x-scalar-secret-token"], placeholder: "Token", type: "password", "onUpdate:modelValue": e[0] || (e[0] = (a) => g("x-scalar-secret-token", a)) }, { default: l(() => [...e[6] || (e[6] = [ y(" Bearer Token ", -1) ])]), _: 1 }, 8, ["containerClass", "environment", "modelValue"]) ]), _: 2 }, 1024)) : t?.scheme === "basic" ? (r(), s(d, { key: 1 }, [ n(i(c), null, { default: l(() => [ n(b, { class: "text-c-2", environment: o.environment, modelValue: t["x-scalar-secret-username"], placeholder: "janedoe", required: "", "onUpdate:modelValue": e[1] || (e[1] = (a) => g("x-scalar-secret-username", a)) }, { default: l(() => [...e[7] || (e[7] = [ y(" Username ", -1) ])]), _: 1 }, 8, ["environment", "modelValue"]) ]), _: 2 }, 1024), n(i(c), null, { default: l(() => [ n(b, { environment: o.environment, modelValue: t["x-scalar-secret-password"], placeholder: "********", type: "password", "onUpdate:modelValue": e[2] || (e[2] = (a) => g("x-scalar-secret-password", a)) }, { default: l(() => [...e[8] || (e[8] = [ y(" Password ", -1) ])]), _: 1 }, 8, ["environment", "modelValue"]) ]), _: 2 }, 1024) ], 64)) : m("", !0) ], 64)) : t?.type === "apiKey" ? (r(), s(d, { key: 3 }, [ n(i(c), null, { default: l(() => [ n(b, { containerClass: B(), environment: o.environment, modelValue: t.name, placeholder: "api-key", "onUpdate:modelValue": e[3] || (e[3] = (a) => j("name", a)) }, { default: l(() => [...e[9] || (e[9] = [ y(" Name ", -1) ])]), _: 1 }, 8, ["containerClass", "environment", "modelValue"]) ]), _: 2 }, 1024), n(i(c), null, { default: l(() => [ n(b, { environment: o.environment, modelValue: t["x-scalar-secret-token"], placeholder: "QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT", type: "password", "onUpdate:modelValue": e[4] || (e[4] = (a) => j("x-scalar-secret-token", a)) }, { default: l(() => [...e[10] || (e[10] = [ y(" Value ", -1) ])]), _: 1 }, 8, ["environment", "modelValue"]) ]), _: 2 }, 1024) ], 64)) : t?.type === "oauth2" ? (r(), s(d, { key: 4 }, [ Object.keys(t.flows).length > 1 ? (r(), v(i(c), { key: 0 }, { default: l(() => [ k("div", L, [ k("div", _, [ (r(!0), s(d, null, C(t.flows, (a, p, $) => (r(), s("button", { key: p, class: z(O(p, $)), type: "button", onClick: (S) => w.value = p }, [ k("span", J, R(p), 1) ], 10, G))), 128)) ]) ]) ]), _: 2 }, 1024)) : m("", !0), (r(!0), s(d, null, C(t.flows, (a, p, $) => (r(), s(d, { key: p }, [ T(p, $) ? (r(), v(E, { key: 0, environment: o.environment, flows: t.flows, proxyUrl: "", selectedScopes: V, server: o.server, type: p, "onUpdate:securityScheme": e[5] || (e[5] = (S) => x("update:securityScheme", S)), "onUpdate:selectedScopes": (S) => M(u, S) }, null, 8, ["environment", "flows", "selectedScopes", "server", "type", "onUpdate:selectedScopes"])) : m("", !0) ], 64))), 128)) ], 64)) : t?.type === "openIdConnect" ? (r(), s("div", { key: 5, class: z(["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": o.isStatic }]) }, " Coming soon ", 2)) : m("", !0) ], 64))), 128)); } }); export { re as default };