UNPKG

@scalar/api-client

Version:

the open source API testing client

154 lines (153 loc) 5.99 kB
import { defineComponent as A, computed as n, ref as O, watchEffect as b, createBlock as N, openBlock as s, createSlots as U, withCtx as u, createElementVNode as r, normalizeClass as v, createVNode as h, unref as y, createElementBlock as f, Fragment as S, createTextVNode as i } from "vue"; import { ScalarToggle as R } from "@scalar/components"; import { isHttpMethod as V } from "@scalar/helpers/http/is-http-method"; import { getResolvedRef as q } from "@scalar/workspace-store/helpers/get-resolved-ref"; import { unpackProxyObject as C } from "@scalar/workspace-store/helpers/unpack-proxy"; import { getDefaultOperationSecurityToggle as E } from "../helpers/get-default-operation-security-toggle.js"; import M from "../../settings/components/Section.vue.js"; import { getActiveProxyUrl as P } from "../../../helpers/get-active-proxy-url.js"; import { getSelectedSecurity as g } from "../../operation/helpers/get-selected-security.js"; import { getServers as D } from "../../../helpers/get-servers.js"; import $ from "../../../blocks/scalar-auth-selector-block/components/AuthSelector.vue.js"; const j = { class: "flex h-8 items-center" }, Y = /* @__PURE__ */ A({ __name: "Authentication", props: { documentSlug: {}, document: {}, eventBus: {}, layout: {}, path: {}, method: {}, exampleName: {}, environment: {}, securitySchemes: {}, workspaceStore: {}, activeWorkspace: {}, plugins: {}, customThemes: {}, currentTheme: {}, isDarkMode: { type: Boolean }, collectionType: {} }, setup(e) { const c = n(() => e.collectionType === "operation" ? { type: "operation", path: e.path ?? "", method: e.method ?? "get" } : { type: "document" }), l = n(() => e.collectionType === "operation" ? !e.path || !V(e.method) ? null : q(e.document?.paths?.[e.path]?.[e.method]) : null), a = O(!1); b(() => { a.value = E({ authStore: e.workspaceStore.auth, documentName: e.documentSlug, ...c.value }); }); const m = n(() => { if (e.collectionType === "operation") { const t = e.workspaceStore.auth.getAuthSelectedSchemas({ type: "operation", documentName: e.documentSlug, path: e.path ?? "", method: e.method ?? "get" }); return g( void 0, t, l.value?.security ?? [] ); } const o = e.workspaceStore.auth.getAuthSelectedSchemas({ type: "document", documentName: e.documentSlug }); return g(o, void 0, e.document?.security ?? []); }), p = n(() => e.collectionType === "operation" ? l.value?.security ?? [] : e.document?.security ?? []), k = n( () => P( e.workspaceStore.workspace["x-scalar-active-proxy"], e.layout ) ?? "" ), d = n(() => D(l.value?.servers ?? e.document?.servers, { documentUrl: e.document?.["x-scalar-original-source-url"] })), x = n(() => { const o = e.document?.["x-scalar-selected-server"], w = l.value?.["x-scalar-selected-server"] ?? o; return d.value.find(({ url: B }) => B === w) ?? d.value[0] ?? null; }), T = (o) => { if (c.value.type === "operation") { if (a.value = o, o) { const { selectedSchemes: t } = m.value; return e.eventBus.emit("auth:update:selected-security-schemes", { selectedRequirements: C(t, { depth: 1 }), newSchemes: [], meta: c.value }); } return e.eventBus.emit("auth:clear:selected-security-schemes", { meta: c.value }); } }; return (o, t) => (s(), N(M, null, U({ title: u(() => [ t[0] || (t[0] = i("Authentication", -1)) ]), description: u(() => [ e.collectionType === "operation" ? (s(), f(S, { key: 0 }, [ t[1] || (t[1] = r("span", { class: "block" }, " Override authentication for this operation with the toggle. ", -1)), t[2] || (t[2] = r("span", { class: "mt-1 block" }, [ r("strong", null, "On"), i(" — Authentication below applies only to this operation. ") ], -1)), t[3] || (t[3] = r("span", { class: "mt-1 block" }, [ r("strong", null, "Off"), i(" — This operation uses document-level authentication from the OpenAPI spec. ") ], -1)) ], 64)) : (s(), f(S, { key: 1 }, [ i(" Configure authentication for this document. Selected authentication applies to all operations unless overridden at the operation level. ") ], 64)) ]), default: u(() => [ r("div", { class: v( e.collectionType === "operation" && !a.value && "cursor-not-allowed" ) }, [ h(y($), { class: v([ "scalar-collection-auth border-none!", e.collectionType === "operation" && !a.value && "pointer-events-none opacity-50 mix-blend-luminosity" ]), createAnySecurityScheme: !0, environment: e.environment, eventBus: e.eventBus, isStatic: "", meta: c.value, proxyUrl: k.value, securityRequirements: p.value, securitySchemes: e.securitySchemes, selectedSecurity: m.value, server: x.value, title: "Authentication" }, null, 8, ["class", "environment", "eventBus", "meta", "proxyUrl", "securityRequirements", "securitySchemes", "selectedSecurity", "server"]) ], 2) ]), _: 2 }, [ e.collectionType === "operation" ? { name: "actions", fn: u(() => [ r("div", j, [ h(y(R), { class: "w-4", modelValue: a.value, "onUpdate:modelValue": T }, null, 8, ["modelValue"]) ]) ]), key: "0" } : void 0 ]), 1024)); } }); export { Y as default };