UNPKG

@scalar/api-client

Version:

the open source API testing client

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