UNPKG

@scalar/api-client

Version:

the open source API testing client

247 lines (246 loc) 8.73 kB
import { defineComponent as g, createElementBlock as U, openBlock as d, Fragment as x, createBlock as k, createCommentVNode as w, createVNode as a, unref as r, withCtx as t, mergeProps as i, createTextVNode as u, createElementVNode as v, renderSlot as T } from "vue"; import { useLoadingState as P, ScalarButton as $ } from "@scalar/components"; import { pkceOptions as A } from "@scalar/oas-utils/entities/spec"; import { useToasts as B } from "@scalar/use-toasts"; import { useWorkspace as R } from "../../../../store/store.js"; import { updateScheme as F } from "../helpers/update-scheme.js"; import I from "./OAuthScopesInput.vue.js"; import m from "./RequestAuthDataTableInput.vue.js"; import s from "../../../../components/DataTable/DataTableRow.vue.js"; import { authorizeOauth2 as N } from "../../libs/oauth2.js"; const O = { class: "flex h-8 items-center justify-end border-t" }, j = { class: "flex h-8 w-full items-center justify-end border-t" }, Y = /* @__PURE__ */ g({ __name: "OAuth2", props: { collection: {}, environment: {}, envVariables: {}, flow: {}, persistAuth: { type: Boolean, default: !1 }, scheme: {}, server: {}, workspace: {} }, emits: ["authorized"], setup(l, { emit: z }) { const b = z, y = P(), { toast: c } = B(), C = R(), n = (V, e) => F(l.scheme.uid, V, e, C, l.persistAuth), S = async () => { if (y.isActive || !l.collection?.uid) return; if (!l.server) { c("No server selected", "error"); return; } y.start(); const [V, e] = await N( l.flow, l.server, l.workspace?.proxyUrl ); await y.clear(), e ? (n(`flows.${l.flow.type}.token`, e), b("authorized")) : (console.error(V), c(V?.message ?? "Failed to authorize", "error")); }, f = { environment: l.environment, envVariables: l.envVariables, workspace: l.workspace }; return (V, e) => (d(), U(x, null, [ l.flow.token ? (d(), U(x, { key: 0 }, [ a(r(s), null, { default: t(() => [ a(m, i(f, { class: "border-r-transparent", modelValue: l.flow.token, placeholder: "QUxMIFlPVVIgQkFTRSBBUkUgQkVMT05HIFRPIFVT", type: "password", "onUpdate:modelValue": e[0] || (e[0] = (o) => n(`flows.${l.flow.type}.token`, o)) }), { default: t(() => [...e[10] || (e[10] = [ u(" Access Token ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 }), a(r(s), { class: "min-w-full" }, { default: t(() => [ v("div", O, [ a(r($), { class: "mr-1 p-0 px-2 py-0.5", loader: r(y), size: "sm", variant: "outlined", onClick: e[1] || (e[1] = (o) => n(`flows.${l.flow.type}.token`, "")) }, { default: t(() => [...e[11] || (e[11] = [ u(" Clear ", -1) ])]), _: 1 }, 8, ["loader"]), T(V.$slots, "oauth-actions") ]) ]), _: 3 }) ], 64)) : (d(), U(x, { key: 1 }, [ a(r(s), null, { default: t(() => [ "authorizationUrl" in l.flow ? (d(), k(m, i({ key: 0 }, f, { containerClass: "border-r-0", modelValue: l.flow.authorizationUrl, placeholder: "https://galaxy.scalar.com/authorize", "onUpdate:modelValue": e[2] || (e[2] = (o) => n(`flows.${l.flow.type}.authorizationUrl`, o)) }), { default: t(() => [...e[12] || (e[12] = [ u(" Auth URL ", -1) ])]), _: 1 }, 16, ["modelValue"])) : w("", !0), "tokenUrl" in l.flow ? (d(), k(m, i({ key: 1 }, f, { modelValue: l.flow.tokenUrl, placeholder: "https://galaxy.scalar.com/token", "onUpdate:modelValue": e[3] || (e[3] = (o) => n(`flows.${l.flow.type}.tokenUrl`, o)) }), { default: t(() => [...e[13] || (e[13] = [ u(" Token URL ", -1) ])]), _: 1 }, 16, ["modelValue"])) : w("", !0) ]), _: 1 }), "x-scalar-redirect-uri" in l.flow ? (d(), k(r(s), { key: 0 }, { default: t(() => [ a(m, i(f, { modelValue: l.flow["x-scalar-redirect-uri"], placeholder: "https://galaxy.scalar.com/callback", "onUpdate:modelValue": e[4] || (e[4] = (o) => n(`flows.${l.flow.type}.x-scalar-redirect-uri`, o)) }), { default: t(() => [...e[14] || (e[14] = [ u(" Redirect URL ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 })) : w("", !0), l.flow.type === "password" ? (d(), U(x, { key: 1 }, [ a(r(s), null, { default: t(() => [ a(m, i(f, { class: "text-c-2", modelValue: l.flow.username, placeholder: "janedoe", "onUpdate:modelValue": e[5] || (e[5] = (o) => n(`flows.${l.flow.type}.username`, o)) }), { default: t(() => [...e[15] || (e[15] = [ u(" Username ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 }), a(r(s), null, { default: t(() => [ a(m, i(f, { modelValue: l.flow.password, placeholder: "********", type: "password", "onUpdate:modelValue": e[6] || (e[6] = (o) => n(`flows.${l.flow.type}.password`, o)) }), { default: t(() => [...e[16] || (e[16] = [ u(" Password ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 }) ], 64)) : w("", !0), a(r(s), null, { default: t(() => [ a(m, i(f, { modelValue: l.flow["x-scalar-client-id"], placeholder: "12345", "onUpdate:modelValue": e[7] || (e[7] = (o) => n(`flows.${l.flow.type}.x-scalar-client-id`, o)) }), { default: t(() => [...e[17] || (e[17] = [ u(" Client ID ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 }), "clientSecret" in l.flow ? (d(), k(r(s), { key: 2 }, { default: t(() => [ a(m, i(f, { modelValue: l.flow.clientSecret, placeholder: "XYZ123", type: "password", "onUpdate:modelValue": e[8] || (e[8] = (o) => n(`flows.${l.flow.type}.clientSecret`, o)) }), { default: t(() => [...e[18] || (e[18] = [ u(" Client Secret ", -1) ])]), _: 1 }, 16, ["modelValue"]) ]), _: 1 })) : w("", !0), "x-usePkce" in l.flow ? (d(), k(r(s), { key: 3 }, { default: t(() => [ a(m, i(f, { enum: r(A), modelValue: l.flow["x-usePkce"], readOnly: "", "onUpdate:modelValue": e[9] || (e[9] = (o) => n( `flows.${l.flow.type}.x-usePkce`, o )) }), { default: t(() => [...e[19] || (e[19] = [ u(" Use PKCE ", -1) ])]), _: 1 }, 16, ["enum", "modelValue"]) ]), _: 1 })) : w("", !0), Object.keys(l.flow.scopes ?? {}).length ? (d(), k(r(s), { key: 4 }, { default: t(() => [ a(I, { flow: l.flow, updateScheme: n }, null, 8, ["flow"]) ]), _: 1 })) : w("", !0) ], 64)), l.flow.token ? w("", !0) : (d(), k(r(s), { key: 2, class: "min-w-full" }, { default: t(() => [ v("div", j, [ a(r($), { class: "mr-0.75 p-0 px-2 py-0.5", loader: r(y), size: "sm", variant: "outlined", onClick: S }, { default: t(() => [...e[20] || (e[20] = [ u(" Authorize ", -1) ])]), _: 1 }, 8, ["loader"]) ]) ]), _: 1 })) ], 64)); } }); export { Y as default };