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