@scalar/api-client 3.19.0 → 3.19.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/dist/style.css +55 -25
- package/dist/v2/blocks/request-block/RequestBlock.vue.script.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.js +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.script.js +21 -5
- package/dist/v2/blocks/request-block/components/RequestBody.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyRaw.vue.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyRaw.vue.js +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyRaw.vue.js.map +1 -1
- package/dist/v2/blocks/response-block/components/ResponseBodyRaw.vue.script.js +42 -16
- package/dist/v2/blocks/response-block/components/ResponseBodyRaw.vue.script.js.map +1 -1
- package/dist/v2/blocks/response-block/helpers/media-types.d.ts.map +1 -1
- package/dist/v2/blocks/response-block/helpers/media-types.js +5 -0
- package/dist/v2/blocks/response-block/helpers/media-types.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue.d.ts +16 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue.d.ts.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue.js +7 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue.js.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue.script.js +86 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue.script.js.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.script.js +19 -2
- package/dist/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue.script.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata.d.ts +6 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata.d.ts.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata.js +25 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata.js.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery.d.ts +1 -2
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery.js +2 -2
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js +13 -9
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows.d.ts +9 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows.d.ts.map +1 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows.js +36 -0
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows.js.map +1 -0
- package/dist/v2/components/code-input/CodeInput.vue.d.ts +2 -2
- package/dist/v2/components/code-input/CodeInput.vue.d.ts.map +1 -1
- package/dist/v2/components/code-input/CodeInput.vue.js +1 -1
- package/dist/v2/components/code-input/CodeInput.vue.js.map +1 -1
- package/dist/v2/components/code-input/CodeInput.vue.script.js +40 -9
- package/dist/v2/components/code-input/CodeInput.vue.script.js.map +1 -1
- package/dist/v2/components/server/ServerDropdown.vue.d.ts.map +1 -1
- package/dist/v2/components/server/ServerDropdown.vue.js.map +1 -1
- package/dist/v2/components/server/ServerDropdown.vue.script.js +1 -1
- package/dist/v2/components/server/ServerDropdown.vue.script.js.map +1 -1
- package/dist/v2/constants.js +1 -1
- package/dist/v2/features/modal/helpers/resolve-route-parameters.d.ts +9 -3
- package/dist/v2/features/modal/helpers/resolve-route-parameters.d.ts.map +1 -1
- package/dist/v2/features/modal/helpers/resolve-route-parameters.js.map +1 -1
- package/dist/vue-styles.css +33 -23
- package/package.json +16 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestBody.vue.script.js","names":[],"sources":["../../../../../src/v2/blocks/request-block/components/RequestBody.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport { ScalarIcon } from '@scalar/components/icon'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { ScalarListbox } from '@scalar/components/listbox'\nimport { CONTENT_TYPES } from '@scalar/helpers/http/content-types'\nimport { parseMimeType } from '@scalar/helpers/http/mime-type'\nimport { isObject } from '@scalar/helpers/object/is-object'\nimport { objectEntries } from '@scalar/helpers/object/object-entries'\nimport { ScalarIconMagicWand } from '@scalar/icons'\nimport type { ApiReferenceEvents } from '@scalar/workspace-store/events'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n getExampleFromBody,\n getSchemaExampleFromBody,\n getSelectedBodyContentType,\n} from '@scalar/workspace-store/request-example'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type {\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { isObjectSchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\nimport { computed, ref, watch } from 'vue'\n\nimport { useFileDialog } from '@/hooks/use-file-dialog'\nimport RequestBodyForm from '@/v2/blocks/request-block/components/RequestBodyForm.vue'\nimport RequestBodyStructured from '@/v2/blocks/request-block/components/RequestBodyStructured.vue'\nimport RequestBodyViewToggle from '@/v2/blocks/request-block/components/RequestBodyViewToggle.vue'\nimport { getFileName } from '@/v2/blocks/request-block/helpers/files'\nimport { getStructuredBodyCodec } from '@/v2/blocks/request-block/helpers/structured-body-codec'\nimport { CodeInput } from '@/v2/components/code-input'\nimport {\n DataTable,\n DataTableHeader,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { CollapsibleSection } from '@/v2/components/layout'\n\nconst {\n requestBody,\n exampleKey,\n environment,\n requestBodyCompositionSelection,\n title,\n defaultView = 'raw',\n} = defineProps<{\n /** Request body */\n requestBody?: RequestBodyObject\n /** Currently selected example key for the current operation */\n exampleKey: string\n /** Display title */\n title: string\n /** Selected environment */\n environment: XScalarEnvironment\n /** Selected anyOf/oneOf request-body variants keyed by schema path */\n requestBodyCompositionSelection?: Record<string, number>\n /**\n * Initial view for structured (JSON/YAML) bodies. Comes from the\n * `x-scalar-default-request-body-view` document extension and falls back to `raw`\n * whenever the body cannot be shown as a form.\n */\n defaultView?: 'form' | 'raw'\n}>()\n\nconst emits = defineEmits<{\n (e: 'update:contentType', payload: { value: string }): void\n /** We use this event to update raw values */\n (\n e: 'update:value',\n payload: Pick<\n ApiReferenceEvents['operation:update:requestBody:value'],\n 'payload' | 'contentType'\n >,\n ): void\n /** We use this event when updating form data only */\n (\n e: 'update:formValue',\n payload: Pick<\n ApiReferenceEvents['operation:update:requestBody:formValue'],\n 'payload' | 'contentType'\n >,\n ): void\n /**\n * Create a new example seeded with values generated from the request body schema.\n *\n * The block itself owns the document and operation identity needed to create an example, so we\n * only report the content type the user is currently looking at.\n */\n (e: 'generate:example', payload: { contentType: string }): void\n}>()\n\n// Map a content type to a language for the code editor\nconst contentTypeToLanguageMap = {\n 'application/json': 'json',\n 'application/xml': 'xml',\n 'application/yaml': 'yaml',\n} as const\n\n/** Selected content type with default */\nconst selectedContentType = computed(\n () => getSelectedBodyContentType(requestBody, exampleKey) ?? 'none',\n)\n\n/**\n * Strips MIME parameters (such as `charset=utf-8`) for dropdown labels, aligned with how we treat\n * media types elsewhere (see api-reference `normalizeMimeType` / WHATWG essence).\n */\nconst contentTypeLabel = (raw: string): string => parseMimeType(raw).essence\n\n/**\n * Build the dropdown options for the content type selector.\n *\n * The list is composed of two groups:\n * 1. The built-in content types we ship friendly labels for (JSON, XML, Multipart Form, etc.).\n * 2. Any additional content types defined on the OpenAPI request body that are not in the built-in list\n * (for example `text/csv`, `application/pdf`, vendor types like `application/vnd.api+json`, ...).\n *\n * The OpenAPI-defined extras are appended at the bottom so the well-known options stay on top, and\n * users can always pick the exact content type the operation actually accepts.\n */\nconst contentTypeOptions = computed<{ id: string; label: string }[]>(() => {\n const builtIn = objectEntries(CONTENT_TYPES).map(([id, label]) => ({\n id,\n label,\n }))\n\n const extras = Object.keys(requestBody?.content ?? {})\n .filter((type) => {\n if (type in CONTENT_TYPES) {\n return false\n }\n // Same essence as a built-in (e.g. `application/json; charset=utf-8`) — do not duplicate the row.\n return !(contentTypeLabel(type) in CONTENT_TYPES)\n })\n .map((type) => ({ id: type, label: contentTypeLabel(type) }))\n\n return [...builtIn, ...extras]\n})\n\nconst selectedContentTypeModel = computed<{ id: string; label: string }>({\n get: () => {\n const found = contentTypeOptions.value.find(\n (it) => it.id === selectedContentType.value,\n )\n if (found) {\n return found\n }\n\n const essence = contentTypeLabel(selectedContentType.value)\n const friendly =\n CONTENT_TYPES[essence as keyof typeof CONTENT_TYPES] ?? essence\n\n return {\n id: selectedContentType.value,\n label: friendly,\n }\n },\n set: (v) => {\n emits('update:contentType', { value: v.id })\n },\n})\n\nfunction handleFileUpload(callback: (file: File) => void) {\n const { open } = useFileDialog({\n onChange: (files) => {\n const file = files?.[0]\n if (file) {\n callback(file)\n }\n },\n multiple: false,\n accept: '*/*',\n })\n open()\n}\n\n/** Dereferenced example */\nconst example = computed(\n () =>\n requestBody &&\n getExampleFromBody(\n requestBody,\n selectedContentType.value,\n exampleKey,\n requestBodyCompositionSelection,\n ),\n)\n\n/** Convert the example value to a string for the code editor */\nconst bodyValue = computed(() => {\n if (!example.value) {\n return ''\n }\n\n const value = example.value.value\n if (typeof value === 'string') {\n return value\n }\n\n return JSON.stringify(value, null, 2)\n})\n\n/** Resolved schema for the request body */\nconst bodySchema = computed<SchemaObject | undefined>(() => {\n return resolve.schema(\n requestBody?.content?.[selectedContentType.value]?.schema,\n )\n})\n\n/** Codec for structured (JSON/YAML) bodies, undefined for everything else */\nconst structuredCodec = computed(() =>\n selectedContentType.value === 'none'\n ? undefined\n : getStructuredBodyCodec(selectedContentType.value),\n)\n\n/** Parsed body value for the form view — `ok: false` when the raw text is not parseable */\nconst parsedBody = computed<{ ok: boolean; value?: unknown }>(() => {\n const codec = structuredCodec.value\n if (!codec) {\n return { ok: false }\n }\n\n const raw = example.value?.value\n // An empty body is still form-editable: rows come from the schema.\n if (raw === undefined || raw === null || raw === '') {\n return { ok: true, value: {} }\n }\n if (typeof raw === 'string') {\n try {\n return { ok: true, value: codec.parse(raw) }\n } catch {\n return { ok: false }\n }\n }\n // Spec-provided examples can be stored as objects directly.\n return { ok: true, value: raw }\n})\n\n/**\n * An edited example normally takes precedence over schema-generated data. When a different\n * composition branch is selected, however, keeping that example leaves the editor showing the\n * previous branch. Track the selection itself instead of inspecting discriminator fields so this\n * also works for compositions whose members are distinguished only by their shape.\n */\nconst compositionSelectionKey = computed(() =>\n JSON.stringify(requestBodyCompositionSelection ?? {}),\n)\n\n// Switching operations changes the body (and often the selection) at once, which is not a branch\n// change, so we only regenerate the body when the selection changes while the operation and example\n// stay the same. Watching all three together and comparing against the watcher's own previous values\n// keeps this correct regardless of the order in which props update or watchers flush.\nwatch(\n [() => requestBody, () => exampleKey, compositionSelectionKey],\n (\n [, , selection],\n [previousRequestBody, previousExampleKey, previousSelection],\n ) => {\n const operationChanged =\n requestBody !== previousRequestBody || exampleKey !== previousExampleKey\n const selectionChanged = selection !== previousSelection\n\n // Going from no selection to a populated one is the modal applying the reference's selection as\n // the panel opens, not the user switching branches. Resetting here would discard the body's named\n // example on the very first open (issue #10075), so only a change between two populated selections\n // counts as a real branch switch.\n const hadNoPreviousSelection = previousSelection === '{}'\n\n // Only a genuine branch switch within the same operation should reset the edited body. An empty\n // selection means there is no composition to switch between (or the selection was cleared on an\n // operation change), so there is nothing to reset.\n if (\n operationChanged ||\n !selectionChanged ||\n hadNoPreviousSelection ||\n Object.keys(requestBodyCompositionSelection ?? {}).length === 0\n ) {\n return\n }\n\n const codec = structuredCodec.value\n if (!requestBody || !codec) {\n return\n }\n\n // Regenerate through the same helper the initial example uses so a reset produces exactly the\n // value a fresh render of this branch would, rather than a hand-copied second code path.\n const selectedValue = getSchemaExampleFromBody(\n requestBody,\n selectedContentType.value,\n requestBodyCompositionSelection,\n )\n\n emits('update:value', {\n // A branch with no writable content generates `null`/`undefined`; clear the editor rather than\n // writing the literal text `null` or leaving the previously selected branch's body behind.\n payload: selectedValue == null ? '' : codec.stringify(selectedValue),\n contentType: selectedContentType.value,\n })\n },\n)\n\n/** The form view only works on an object-shaped body root */\nconst isFormViewAvailable = computed(\n () => parsedBody.value.ok && isObject(parsedBody.value.value),\n)\n\n/**\n * Show the Form/Raw toggle for structured bodies that are (or per schema should be)\n * an object at the root. Non-object roots (arrays, primitives) stay raw-only.\n */\nconst showBodyViewToggle = computed(\n () =>\n Boolean(structuredCodec.value) &&\n (isFormViewAvailable.value ||\n Boolean(bodySchema.value && isObjectSchema(bodySchema.value))),\n)\n\n/** Selected body view, seeded from the document default (raw unless configured) */\nconst bodyView = ref<'form' | 'raw'>(defaultView)\n\n// Fall back to raw when the form view stops being available (e.g. the content type\n// changed to a non-structured one, or an external edit made the body unparseable).\nwatch(isFormViewAvailable, (ok) => {\n if (!ok) {\n bodyView.value = 'raw'\n }\n})\n\n/**\n * Whether we can offer to generate a fresh example from the schema.\n *\n * Only structured (JSON/YAML) bodies qualify: they have a schema to generate from and a text\n * representation we can seed the new example with. Binary and form bodies have their own editors,\n * so the button would have nothing meaningful to write.\n */\nconst canGenerateExample = computed(() =>\n Boolean(structuredCodec.value && bodySchema.value),\n)\n</script>\n<template>\n <CollapsibleSection>\n <template #title>{{ title }}</template>\n <DataTable\n :columns=\"['']\"\n presentational>\n <DataTableHeader\n class=\"relative col-span-full flex h-8 cursor-pointer items-center justify-between border-r-0 !p-0\">\n <ScalarListbox\n v-model=\"selectedContentTypeModel\"\n :options=\"contentTypeOptions\"\n teleport>\n <ScalarButton\n class=\"text-c-2 hover:text-c-1 flex h-full w-fit gap-1.5 px-3 font-normal\"\n fullWidth\n variant=\"ghost\">\n <span>{{ selectedContentTypeModel.label }}</span>\n <ScalarIcon\n icon=\"ChevronDown\"\n size=\"md\" />\n </ScalarButton>\n </ScalarListbox>\n <div class=\"flex items-center gap-1\">\n <!--\n Generates a new example from the schema so the auto-generated fields stay reachable\n even once the document ships custom examples.\n -->\n <ScalarIconButton\n v-if=\"canGenerateExample\"\n aria-label=\"Generate example from schema\"\n :icon=\"ScalarIconMagicWand\"\n label=\"Generate example from schema\"\n size=\"sm\"\n tooltip\n @click.stop=\"\n emits('generate:example', { contentType: selectedContentType })\n \" />\n <RequestBodyViewToggle\n v-if=\"showBodyViewToggle\"\n :disabled=\"!isFormViewAvailable\"\n :modelValue=\"bodyView\"\n @update:modelValue=\"(v) => (bodyView = v)\" />\n </div>\n </DataTableHeader>\n <DataTableRow>\n <!-- No Body -->\n <template v-if=\"selectedContentType === 'none'\">\n <div\n class=\"text-c-3 flex min-h-10 w-full items-center justify-center border-t p-2 text-sm\">\n <span>No Body</span>\n </div>\n </template>\n\n <!-- Binary File -->\n <template\n v-else-if=\"selectedContentType === 'application/octet-stream'\">\n <div\n class=\"flex items-center justify-center overflow-hidden border-t p-1.5\">\n <template\n v-if=\"\n getFileName(unpackProxyObject(example?.value)) !== undefined\n \">\n <span\n class=\"text-c-2 w-full max-w-full overflow-hidden rounded border px-1.5 py-1 text-xs whitespace-nowrap\">\n {{ getFileName(unpackProxyObject(example?.value)) }}\n </span>\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 ml-1 border-0 shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"\n emits('update:value', {\n payload: undefined,\n contentType: selectedContentType,\n })\n \">\n Delete\n </ScalarButton>\n </template>\n <template v-else>\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 border-0 shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"\n () =>\n handleFileUpload((file) =>\n emits('update:value', {\n payload: file,\n contentType: selectedContentType,\n }),\n )\n \">\n <span>Select File</span>\n <ScalarIcon\n class=\"ml-1\"\n icon=\"Upload\"\n size=\"xs\"\n thickness=\"2.5\" />\n </ScalarButton>\n </template>\n </div>\n </template>\n\n <!-- Form Data / URL Encoded -->\n <template\n v-else-if=\"\n selectedContentType === 'multipart/form-data' ||\n selectedContentType === 'application/x-www-form-urlencoded'\n \">\n <RequestBodyForm\n :bodySchema\n :environment\n :example\n :selectedContentType\n @update:formValue=\"\n (payload) =>\n emits('update:formValue', {\n payload,\n contentType: selectedContentType,\n })\n \" />\n </template>\n\n <!-- Code/Other -->\n <template v-else>\n <!-- Schema-driven form view for structured (JSON/YAML) bodies -->\n <RequestBodyStructured\n v-if=\"bodyView === 'form' && isFormViewAvailable\"\n :bodySchema\n :contentType=\"selectedContentType\"\n :environment\n :parsedValue=\"parsedBody.value\"\n @update:value=\"\n (value) =>\n emits('update:value', {\n payload: value,\n contentType: selectedContentType,\n })\n \" />\n <CodeInput\n v-else\n class=\"border-t px-3\"\n content=\"\"\n :environment=\"environment\"\n :language=\"\n contentTypeToLanguageMap[\n selectedContentType as keyof typeof contentTypeToLanguageMap\n ] ?? 'plaintext'\n \"\n lineNumbers\n lint\n :modelValue=\"bodyValue\"\n withFakeData\n @update:modelValue=\"\n (value) =>\n emits('update:value', {\n payload: value,\n contentType: selectedContentType,\n })\n \" />\n </template>\n </DataTableRow>\n </DataTable>\n </CollapsibleSection>\n</template>\n<style scoped>\n:deep(.cm-content) {\n font-size: var(--scalar-small);\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkEA,MAAM,QAAQ;EA4Bd,MAAM,2BAA2B;GAC/B,oBAAoB;GACpB,mBAAmB;GACnB,oBAAoB;EACtB;;EAGA,MAAM,sBAAsB,eACpB,2BAA2B,QAAA,aAAa,QAAA,UAAU,KAAK,MAC/D;;;;;EAMA,MAAM,oBAAoB,QAAwB,cAAc,GAAG,CAAC,CAAC;;;;;;;;;;;;EAarE,MAAM,qBAAqB,eAAgD;GACzE,MAAM,UAAU,cAAc,aAAa,CAAC,CAAC,KAAK,CAAC,IAAI,YAAY;IACjE;IACA;GACF,EAAE;GAEF,MAAM,SAAS,OAAO,KAAK,QAAA,aAAa,WAAW,CAAC,CAAC,CAAA,CAClD,QAAQ,SAAS;IAChB,IAAI,QAAQ,eACV,OAAO;IAGT,OAAO,EAAE,iBAAiB,IAAI,KAAK;GACrC,CAAC,CAAA,CACA,KAAK,UAAU;IAAE,IAAI;IAAM,OAAO,iBAAiB,IAAI;GAAE,EAAE;GAE9D,OAAO,CAAC,GAAG,SAAS,GAAG,MAAM;EAC/B,CAAC;EAED,MAAM,2BAA2B,SAAwC;GACvE,WAAW;IACT,MAAM,QAAQ,mBAAmB,MAAM,MACpC,OAAO,GAAG,OAAO,oBAAoB,KACxC;IACA,IAAI,OACF,OAAO;IAGT,MAAM,UAAU,iBAAiB,oBAAoB,KAAK;IAC1D,MAAM,WACJ,cAAc,YAA0C;IAE1D,OAAO;KACL,IAAI,oBAAoB;KACxB,OAAO;IACT;GACF;G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A,OAAA,OAAA,MAAkB,UAA0B,MAAK,gBAAA;iBAA8C;qBAAsC,oBAAA"}
|
|
1
|
+
{"version":3,"file":"RequestBody.vue.script.js","names":[],"sources":["../../../../../src/v2/blocks/request-block/components/RequestBody.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport { ScalarCodeBlockCopy } from '@scalar/components/code-block'\nimport { ScalarCopyBackdrop } from '@scalar/components/copy'\nimport { ScalarIcon } from '@scalar/components/icon'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { ScalarListbox } from '@scalar/components/listbox'\nimport { CONTENT_TYPES } from '@scalar/helpers/http/content-types'\nimport { parseMimeType } from '@scalar/helpers/http/mime-type'\nimport { isObject } from '@scalar/helpers/object/is-object'\nimport { objectEntries } from '@scalar/helpers/object/object-entries'\nimport { ScalarIconMagicWand } from '@scalar/icons'\nimport type { ApiReferenceEvents } from '@scalar/workspace-store/events'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n getExampleFromBody,\n getSchemaExampleFromBody,\n getSelectedBodyContentType,\n} from '@scalar/workspace-store/request-example'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type {\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { isObjectSchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\nimport { computed, ref, watch } from 'vue'\n\nimport { useFileDialog } from '@/hooks/use-file-dialog'\nimport RequestBodyForm from '@/v2/blocks/request-block/components/RequestBodyForm.vue'\nimport RequestBodyStructured from '@/v2/blocks/request-block/components/RequestBodyStructured.vue'\nimport RequestBodyViewToggle from '@/v2/blocks/request-block/components/RequestBodyViewToggle.vue'\nimport { getFileName } from '@/v2/blocks/request-block/helpers/files'\nimport { getStructuredBodyCodec } from '@/v2/blocks/request-block/helpers/structured-body-codec'\nimport { CodeInput } from '@/v2/components/code-input'\nimport {\n DataTable,\n DataTableHeader,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { CollapsibleSection } from '@/v2/components/layout'\n\nconst {\n requestBody,\n exampleKey,\n environment,\n requestBodyCompositionSelection,\n title,\n defaultView = 'raw',\n} = defineProps<{\n /** Request body */\n requestBody?: RequestBodyObject\n /** Currently selected example key for the current operation */\n exampleKey: string\n /** Display title */\n title: string\n /** Selected environment */\n environment: XScalarEnvironment\n /** Selected anyOf/oneOf request-body variants keyed by schema path */\n requestBodyCompositionSelection?: Record<string, number>\n /**\n * Initial view for structured (JSON/YAML) bodies. Comes from the\n * `x-scalar-default-request-body-view` document extension and falls back to `raw`\n * whenever the body cannot be shown as a form.\n */\n defaultView?: 'form' | 'raw'\n}>()\n\nconst emits = defineEmits<{\n (e: 'update:contentType', payload: { value: string }): void\n /** We use this event to update raw values */\n (\n e: 'update:value',\n payload: Pick<\n ApiReferenceEvents['operation:update:requestBody:value'],\n 'payload' | 'contentType'\n >,\n ): void\n /** We use this event when updating form data only */\n (\n e: 'update:formValue',\n payload: Pick<\n ApiReferenceEvents['operation:update:requestBody:formValue'],\n 'payload' | 'contentType'\n >,\n ): void\n /**\n * Create a new example seeded with values generated from the request body schema.\n *\n * The block itself owns the document and operation identity needed to create an example, so we\n * only report the content type the user is currently looking at.\n */\n (e: 'generate:example', payload: { contentType: string }): void\n}>()\n\n// Map a content type to a language for the code editor\nconst contentTypeToLanguageMap = {\n 'application/json': 'json',\n 'application/xml': 'xml',\n 'application/yaml': 'yaml',\n} as const\n\n/** Selected content type with default */\nconst selectedContentType = computed(\n () => getSelectedBodyContentType(requestBody, exampleKey) ?? 'none',\n)\n\n/** Keep the editor and copy label aligned with the selected content type. */\nconst selectedLanguage = computed(\n () =>\n contentTypeToLanguageMap[\n selectedContentType.value as keyof typeof contentTypeToLanguageMap\n ] ?? 'plaintext',\n)\n\n/**\n * Strips MIME parameters (such as `charset=utf-8`) for dropdown labels, aligned with how we treat\n * media types elsewhere (see api-reference `normalizeMimeType` / WHATWG essence).\n */\nconst contentTypeLabel = (raw: string): string => parseMimeType(raw).essence\n\n/**\n * Build the dropdown options for the content type selector.\n *\n * The list is composed of two groups:\n * 1. The built-in content types we ship friendly labels for (JSON, XML, Multipart Form, etc.).\n * 2. Any additional content types defined on the OpenAPI request body that are not in the built-in list\n * (for example `text/csv`, `application/pdf`, vendor types like `application/vnd.api+json`, ...).\n *\n * The OpenAPI-defined extras are appended at the bottom so the well-known options stay on top, and\n * users can always pick the exact content type the operation actually accepts.\n */\nconst contentTypeOptions = computed<{ id: string; label: string }[]>(() => {\n const builtIn = objectEntries(CONTENT_TYPES).map(([id, label]) => ({\n id,\n label,\n }))\n\n const extras = Object.keys(requestBody?.content ?? {})\n .filter((type) => {\n if (type in CONTENT_TYPES) {\n return false\n }\n // Same essence as a built-in (e.g. `application/json; charset=utf-8`) — do not duplicate the row.\n return !(contentTypeLabel(type) in CONTENT_TYPES)\n })\n .map((type) => ({ id: type, label: contentTypeLabel(type) }))\n\n return [...builtIn, ...extras]\n})\n\nconst selectedContentTypeModel = computed<{ id: string; label: string }>({\n get: () => {\n const found = contentTypeOptions.value.find(\n (it) => it.id === selectedContentType.value,\n )\n if (found) {\n return found\n }\n\n const essence = contentTypeLabel(selectedContentType.value)\n const friendly =\n CONTENT_TYPES[essence as keyof typeof CONTENT_TYPES] ?? essence\n\n return {\n id: selectedContentType.value,\n label: friendly,\n }\n },\n set: (v) => {\n emits('update:contentType', { value: v.id })\n },\n})\n\nfunction handleFileUpload(callback: (file: File) => void) {\n const { open } = useFileDialog({\n onChange: (files) => {\n const file = files?.[0]\n if (file) {\n callback(file)\n }\n },\n multiple: false,\n accept: '*/*',\n })\n open()\n}\n\n/** Dereferenced example */\nconst example = computed(\n () =>\n requestBody &&\n getExampleFromBody(\n requestBody,\n selectedContentType.value,\n exampleKey,\n requestBodyCompositionSelection,\n ),\n)\n\n/** Convert the example value to a string for the code editor */\nconst bodyValue = computed(() => {\n if (!example.value) {\n return ''\n }\n\n const value = example.value.value\n if (typeof value === 'string') {\n return value\n }\n\n return JSON.stringify(value, null, 2)\n})\n\n/** Resolved schema for the request body */\nconst bodySchema = computed<SchemaObject | undefined>(() => {\n return resolve.schema(\n requestBody?.content?.[selectedContentType.value]?.schema,\n )\n})\n\n/** Codec for structured (JSON/YAML) bodies, undefined for everything else */\nconst structuredCodec = computed(() =>\n selectedContentType.value === 'none'\n ? undefined\n : getStructuredBodyCodec(selectedContentType.value),\n)\n\n/** Parsed body value for the form view — `ok: false` when the raw text is not parseable */\nconst parsedBody = computed<{ ok: boolean; value?: unknown }>(() => {\n const codec = structuredCodec.value\n if (!codec) {\n return { ok: false }\n }\n\n const raw = example.value?.value\n // An empty body is still form-editable: rows come from the schema.\n if (raw === undefined || raw === null || raw === '') {\n return { ok: true, value: {} }\n }\n if (typeof raw === 'string') {\n try {\n return { ok: true, value: codec.parse(raw) }\n } catch {\n return { ok: false }\n }\n }\n // Spec-provided examples can be stored as objects directly.\n return { ok: true, value: raw }\n})\n\n/**\n * An edited example normally takes precedence over schema-generated data. When a different\n * composition branch is selected, however, keeping that example leaves the editor showing the\n * previous branch. Track the selection itself instead of inspecting discriminator fields so this\n * also works for compositions whose members are distinguished only by their shape.\n */\nconst compositionSelectionKey = computed(() =>\n JSON.stringify(requestBodyCompositionSelection ?? {}),\n)\n\n// Switching operations changes the body (and often the selection) at once, which is not a branch\n// change, so we only regenerate the body when the selection changes while the operation and example\n// stay the same. Watching all three together and comparing against the watcher's own previous values\n// keeps this correct regardless of the order in which props update or watchers flush.\nwatch(\n [() => requestBody, () => exampleKey, compositionSelectionKey],\n (\n [, , selection],\n [previousRequestBody, previousExampleKey, previousSelection],\n ) => {\n const operationChanged =\n requestBody !== previousRequestBody || exampleKey !== previousExampleKey\n const selectionChanged = selection !== previousSelection\n\n // Going from no selection to a populated one is the modal applying the reference's selection as\n // the panel opens, not the user switching branches. Resetting here would discard the body's named\n // example on the very first open (issue #10075), so only a change between two populated selections\n // counts as a real branch switch.\n const hadNoPreviousSelection = previousSelection === '{}'\n\n // Only a genuine branch switch within the same operation should reset the edited body. An empty\n // selection means there is no composition to switch between (or the selection was cleared on an\n // operation change), so there is nothing to reset.\n if (\n operationChanged ||\n !selectionChanged ||\n hadNoPreviousSelection ||\n Object.keys(requestBodyCompositionSelection ?? {}).length === 0\n ) {\n return\n }\n\n const codec = structuredCodec.value\n if (!requestBody || !codec) {\n return\n }\n\n // Regenerate through the same helper the initial example uses so a reset produces exactly the\n // value a fresh render of this branch would, rather than a hand-copied second code path.\n const selectedValue = getSchemaExampleFromBody(\n requestBody,\n selectedContentType.value,\n requestBodyCompositionSelection,\n )\n\n emits('update:value', {\n // A branch with no writable content generates `null`/`undefined`; clear the editor rather than\n // writing the literal text `null` or leaving the previously selected branch's body behind.\n payload: selectedValue == null ? '' : codec.stringify(selectedValue),\n contentType: selectedContentType.value,\n })\n },\n)\n\n/** The form view only works on an object-shaped body root */\nconst isFormViewAvailable = computed(\n () => parsedBody.value.ok && isObject(parsedBody.value.value),\n)\n\n/**\n * Show the Form/Raw toggle for structured bodies that are (or per schema should be)\n * an object at the root. Non-object roots (arrays, primitives) stay raw-only.\n */\nconst showBodyViewToggle = computed(\n () =>\n Boolean(structuredCodec.value) &&\n (isFormViewAvailable.value ||\n Boolean(bodySchema.value && isObjectSchema(bodySchema.value))),\n)\n\n/** Selected body view, seeded from the document default (raw unless configured) */\nconst bodyView = ref<'form' | 'raw'>(defaultView)\n\n// Fall back to raw when the form view stops being available (e.g. the content type\n// changed to a non-structured one, or an external edit made the body unparseable).\nwatch(isFormViewAvailable, (ok) => {\n if (!ok) {\n bodyView.value = 'raw'\n }\n})\n\n/**\n * Whether we can offer to generate a fresh example from the schema.\n *\n * Only structured (JSON/YAML) bodies qualify: they have a schema to generate from and a text\n * representation we can seed the new example with. Binary and form bodies have their own editors,\n * so the button would have nothing meaningful to write.\n */\nconst canGenerateExample = computed(() =>\n Boolean(structuredCodec.value && bodySchema.value),\n)\n</script>\n<template>\n <CollapsibleSection>\n <template #title>{{ title }}</template>\n <DataTable\n :columns=\"['']\"\n presentational>\n <DataTableHeader\n class=\"relative col-span-full flex h-8 cursor-pointer items-center justify-between border-r-0 !p-0\">\n <ScalarListbox\n v-model=\"selectedContentTypeModel\"\n :options=\"contentTypeOptions\"\n teleport>\n <ScalarButton\n class=\"text-c-2 hover:text-c-1 flex h-full w-fit gap-1.5 px-3 font-normal\"\n fullWidth\n variant=\"ghost\">\n <span>{{ selectedContentTypeModel.label }}</span>\n <ScalarIcon\n icon=\"ChevronDown\"\n size=\"md\" />\n </ScalarButton>\n </ScalarListbox>\n <div class=\"flex items-center gap-1\">\n <!--\n Generates a new example from the schema so the auto-generated fields stay reachable\n even once the document ships custom examples.\n -->\n <ScalarIconButton\n v-if=\"canGenerateExample\"\n aria-label=\"Generate example from schema\"\n :icon=\"ScalarIconMagicWand\"\n label=\"Generate example from schema\"\n size=\"sm\"\n tooltip\n @click.stop=\"\n emits('generate:example', { contentType: selectedContentType })\n \" />\n <RequestBodyViewToggle\n v-if=\"showBodyViewToggle\"\n :disabled=\"!isFormViewAvailable\"\n :modelValue=\"bodyView\"\n @update:modelValue=\"(v) => (bodyView = v)\" />\n </div>\n </DataTableHeader>\n <DataTableRow>\n <!-- No Body -->\n <template v-if=\"selectedContentType === 'none'\">\n <div\n class=\"text-c-3 flex min-h-10 w-full items-center justify-center border-t p-2 text-sm\">\n <span>No Body</span>\n </div>\n </template>\n\n <!-- Binary File -->\n <template\n v-else-if=\"selectedContentType === 'application/octet-stream'\">\n <div\n class=\"flex items-center justify-center overflow-hidden border-t p-1.5\">\n <template\n v-if=\"\n getFileName(unpackProxyObject(example?.value)) !== undefined\n \">\n <span\n class=\"text-c-2 w-full max-w-full overflow-hidden rounded border px-1.5 py-1 text-xs whitespace-nowrap\">\n {{ getFileName(unpackProxyObject(example?.value)) }}\n </span>\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 ml-1 border-0 shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"\n emits('update:value', {\n payload: undefined,\n contentType: selectedContentType,\n })\n \">\n Delete\n </ScalarButton>\n </template>\n <template v-else>\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 border-0 shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"\n () =>\n handleFileUpload((file) =>\n emits('update:value', {\n payload: file,\n contentType: selectedContentType,\n }),\n )\n \">\n <span>Select File</span>\n <ScalarIcon\n class=\"ml-1\"\n icon=\"Upload\"\n size=\"xs\"\n thickness=\"2.5\" />\n </ScalarButton>\n </template>\n </div>\n </template>\n\n <!-- Form Data / URL Encoded -->\n <template\n v-else-if=\"\n selectedContentType === 'multipart/form-data' ||\n selectedContentType === 'application/x-www-form-urlencoded'\n \">\n <RequestBodyForm\n :bodySchema\n :environment\n :example\n :selectedContentType\n @update:formValue=\"\n (payload) =>\n emits('update:formValue', {\n payload,\n contentType: selectedContentType,\n })\n \" />\n </template>\n\n <!-- Code/Other -->\n <template v-else>\n <!-- Schema-driven form view for structured (JSON/YAML) bodies -->\n <RequestBodyStructured\n v-if=\"bodyView === 'form' && isFormViewAvailable\"\n :bodySchema\n :contentType=\"selectedContentType\"\n :environment\n :parsedValue=\"parsedBody.value\"\n @update:value=\"\n (value) =>\n emits('update:value', {\n payload: value,\n contentType: selectedContentType,\n })\n \" />\n <!-- Editable raw body with a copy button revealed on hover/focus -->\n <div\n v-else\n class=\"group/code-block relative border-t\">\n <CodeInput\n class=\"px-3\"\n content=\"\"\n :environment=\"environment\"\n :language=\"selectedLanguage\"\n lineNumbers\n lint\n :modelValue=\"bodyValue\"\n withFakeData\n @update:modelValue=\"\n (value) =>\n emits('update:value', {\n payload: value,\n contentType: selectedContentType,\n })\n \" />\n <ScalarCodeBlockCopy\n v-if=\"bodyValue\"\n class=\"absolute top-1.5 right-1.5\"\n :content=\"bodyValue\"\n :lang=\"selectedLanguage\"\n showLang>\n <template #backdrop>\n <ScalarCopyBackdrop class=\"-top-1 -right-1.5\" />\n </template>\n </ScalarCodeBlockCopy>\n </div>\n </template>\n </DataTableRow>\n </DataTable>\n </CollapsibleSection>\n</template>\n<style scoped>\n:deep(.cm-content) {\n font-size: var(--scalar-small);\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoEA,MAAM,QAAQ;EA4Bd,MAAM,2BAA2B;GAC/B,oBAAoB;GACpB,mBAAmB;GACnB,oBAAoB;EACtB;;EAGA,MAAM,sBAAsB,eACpB,2BAA2B,QAAA,aAAa,QAAA,UAAU,KAAK,MAC/D;;EAGA,MAAM,mBAAmB,eAErB,yBACE,oBAAoB,UACjB,WACT;;;;;EAMA,MAAM,oBAAoB,QAAwB,cAAc,GAAG,CAAC,CAAC;;;;;;;;;;;;EAarE,MAAM,qBAAqB,eAAgD;GACzE,MAAM,UAAU,cAAc,aAAa,CAAC,CAAC,KAAK,CAAC,IAAI,YAAY;IACjE;IACA;GACF,EAAE;GAEF,MAAM,SAAS,OAAO,KAAK,QAAA,aAAa,WAAW,CAAC,CAAC,CAAA,CAClD,QAAQ,SAAS;IAChB,IAAI,QAAQ,eACV,OAAO;IAGT,OAAO,EAAE,iBAAiB,IAAI,KAAK;GACrC,CAAC,CAAA,CACA,KAAK,UAAU;IAAE,IAAI;IAAM,OAAO,iBAAiB,IAAI;GAAE,EAAE;GAE9D,OAAO,CAAC,GAAG,SAAS,GAAG,MAAM;EAC/B,CAAC;EAED,MAAM,2BAA2B,SAAwC;GACvE,WAAW;IACT,MAAM,QAAQ,mBAAmB,MAAM,MACpC,OAAO,GAAG,OAAO,oBAAoB,KACxC;IACA,IAAI,OACF,OAAO;IAGT,MAAM,UAAU,iBAAiB,oBAAoB,KAAK;IAC1D,MAAM,WACJ,cAAc,YAA0C;IAE1D,OAAO;KACL,IAAI,oBAAoB;KACxB,OAAO;IACT;GACF;GACA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AiB,OAAA,OAAA,OAAA,MAAoB,UAA4B,MAAK,gBAAA;iBAAgD;qBAAwC,oBAAA;;;;;;UAQzJ,UAAA,SAAA,UAAA,GADR,YASsB,MAAA,mBAAA,GAAA;;OAPpB,OAAM;OACL,SAAS,UAAA;OACT,MAAM,iBAAA;OACP,UAAA;;OACW,UAAQ,cAC+B,CAAhD,YAAgD,MAAA,kBAAA,GAAA,EAA5B,OAAM,oBAAmB,CAAA,CAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResponseBodyRaw.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/response-block/components/ResponseBodyRaw.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ResponseBodyRaw.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/response-block/components/ResponseBodyRaw.vue"],"names":[],"mappings":"AAwHA,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,wBAAwB,CAAA;AAK/B,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,OAAO,CAAA;IAChB,QAAQ,EAAE,kBAAkB,GAAG,SAAS,CAAA;IACxC,+GAA+G;IAC/G,eAAe,CAAC,EAAE,OAAO,CAAA;CAC1B,CAAC;AA0KF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -2,7 +2,7 @@ import _plugin_vue_export_helper_default from "../../../../_virtual/_plugin-vue_
|
|
|
2
2
|
import ResponseBodyRaw_vue_vue_type_script_setup_true_lang_default from "./ResponseBodyRaw.vue.script.js";
|
|
3
3
|
/* empty css */
|
|
4
4
|
//#region src/v2/blocks/response-block/components/ResponseBodyRaw.vue
|
|
5
|
-
var ResponseBodyRaw_default = /*#__PURE__*/ _plugin_vue_export_helper_default(ResponseBodyRaw_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-
|
|
5
|
+
var ResponseBodyRaw_default = /*#__PURE__*/ _plugin_vue_export_helper_default(ResponseBodyRaw_vue_vue_type_script_setup_true_lang_default, [["__scopeId", "data-v-6e055eb2"]]);
|
|
6
6
|
//#endregion
|
|
7
7
|
export { ResponseBodyRaw_default as default };
|
|
8
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResponseBodyRaw.vue.js","names":[],"sources":["../../../../../src/v2/blocks/response-block/components/ResponseBodyRaw.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { ScalarCodeBlockCopy } from '@scalar/components/code-block'\nimport { useCodeMirror
|
|
1
|
+
{"version":3,"file":"ResponseBodyRaw.vue.js","names":[],"sources":["../../../../../src/v2/blocks/response-block/components/ResponseBodyRaw.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { ScalarCodeBlockCopy } from '@scalar/components/code-block'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { ScalarIconArrowElbowDownLeft } from '@scalar/icons'\nimport {\n EditorView,\n useCodeMirror,\n type CodeMirrorLanguage,\n} from '@scalar/use-codemirror'\nimport { computed, ref, toRef, useId } from 'vue'\n\nimport { prettifyJsoncString } from '@/v2/blocks/response-block/helpers/prettify-jsonc-string'\n\nconst props = defineProps<{\n content: unknown\n language: CodeMirrorLanguage | undefined\n /** When true, JSON/JSONC strings are pretty-printed for the Preview tab (wire bytes stay unchanged in Raw). */\n prettyPrintJson?: boolean\n}>()\n\nconst codeMirrorRef = ref<HTMLDivElement | null>(null)\n/** Base id for the code block */\nconst id = useId()\n\nconst isLineWrapping = ref(false)\n\nconst displayContent = computed((): string => {\n const { content, language, prettyPrintJson = false } = props\n if (typeof content !== 'string') {\n if (content == null) {\n return ''\n }\n return String(content)\n }\n if (prettyPrintJson && language === 'json') {\n return prettifyJsoncString(content)\n }\n return content\n})\n\nconst extensions = computed(() =>\n isLineWrapping.value ? [EditorView.lineWrapping] : [],\n)\n\nconst { codeMirror } = useCodeMirror({\n codeMirrorRef,\n readOnly: true,\n lineNumbers: true,\n content: toRef(displayContent),\n language: toRef(() => props.language),\n forceFoldGutter: true,\n extensions,\n})\n\n// Function to get current content\nconst getCurrentContent = () => {\n return codeMirror.value?.state.doc.toString() || ''\n}\n\nconst toggleLineWrapping = (): void => {\n isLineWrapping.value = !isLineWrapping.value\n}\n</script>\n<template>\n <div\n class=\"scalar-code-block group/code-block relative grid min-h-0 overflow-hidden p-px outline-none has-focus-visible:outline\"\n data-testid=\"response-body-raw\">\n <div\n class=\"custom-scroll relative pr-1\"\n tabindex=\"0\">\n <!-- CodeMirror container -->\n <div ref=\"codeMirrorRef\" />\n </div>\n <!-- Action buttons -->\n <div\n v-if=\"getCurrentContent()\"\n class=\"absolute top-2 right-2 flex items-center gap-1.5 opacity-0 transition-opacity duration-150 group-hover/code-block:opacity-100 group-has-focus-visible/code-block:opacity-100\">\n <ScalarIconButton\n class=\"bg-b-2 text-c-2 hover:text-c-1 absolute right-18\"\n :icon=\"ScalarIconArrowElbowDownLeft\"\n :aria-pressed=\"isLineWrapping\"\n :aria-label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n :label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n size=\"sm\"\n tooltip\n variant=\"ghost\"\n @click=\"toggleLineWrapping\" />\n <ScalarCodeBlockCopy\n :aria-controls=\"id\"\n :content=\"getCurrentContent()\" />\n </div>\n </div>\n</template>\n<style scoped>\n:deep(.cm-editor) {\n background-color: transparent;\n font-size: var(--scalar-small);\n outline: none;\n}\n\n:deep(.cm-gutters) {\n background-color: var(--scalar-background-1);\n border-radius: var(--scalar-radius) 0 0 var(--scalar-radius);\n}\n\n:deep(.cm-scroller) {\n overflow: auto;\n min-width: 100%;\n}\n\n:deep(.cm-lineWrapping .cm-line) {\n word-break: break-all;\n}\n</style>\n"],"mappings":""}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { prettifyJsoncString } from "../helpers/prettify-jsonc-string.js";
|
|
2
|
-
import { computed,
|
|
3
|
-
import {
|
|
2
|
+
import { computed, createCommentVNode, createElementBlock, createElementVNode, createVNode, defineComponent, openBlock, ref, toRef, unref, useId } from "vue";
|
|
3
|
+
import { ScalarIconArrowElbowDownLeft } from "@scalar/icons";
|
|
4
|
+
import { ScalarIconButton } from "@scalar/components/icon-button";
|
|
5
|
+
import { EditorView, useCodeMirror } from "@scalar/use-codemirror";
|
|
4
6
|
import { ScalarCodeBlockCopy } from "@scalar/components/code-block";
|
|
5
7
|
//#region src/v2/blocks/response-block/components/ResponseBodyRaw.vue?vue&type=script&setup=true&lang.ts
|
|
6
8
|
var _hoisted_1 = {
|
|
@@ -11,6 +13,10 @@ var _hoisted_2 = {
|
|
|
11
13
|
class: "custom-scroll relative pr-1",
|
|
12
14
|
tabindex: "0"
|
|
13
15
|
};
|
|
16
|
+
var _hoisted_3 = {
|
|
17
|
+
key: 0,
|
|
18
|
+
class: "absolute top-2 right-2 flex items-center gap-1.5 opacity-0 transition-opacity duration-150 group-hover/code-block:opacity-100 group-has-focus-visible/code-block:opacity-100"
|
|
19
|
+
};
|
|
14
20
|
var ResponseBodyRaw_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
15
21
|
__name: "ResponseBodyRaw",
|
|
16
22
|
props: {
|
|
@@ -23,35 +29,55 @@ var ResponseBodyRaw_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/
|
|
|
23
29
|
const codeMirrorRef = ref(null);
|
|
24
30
|
/** Base id for the code block */
|
|
25
31
|
const id = useId();
|
|
32
|
+
const isLineWrapping = ref(false);
|
|
33
|
+
const displayContent = computed(() => {
|
|
34
|
+
const { content, language, prettyPrintJson = false } = props;
|
|
35
|
+
if (typeof content !== "string") {
|
|
36
|
+
if (content == null) return "";
|
|
37
|
+
return String(content);
|
|
38
|
+
}
|
|
39
|
+
if (prettyPrintJson && language === "json") return prettifyJsoncString(content);
|
|
40
|
+
return content;
|
|
41
|
+
});
|
|
42
|
+
const extensions = computed(() => isLineWrapping.value ? [EditorView.lineWrapping] : []);
|
|
26
43
|
const { codeMirror } = useCodeMirror({
|
|
27
44
|
codeMirrorRef,
|
|
28
45
|
readOnly: true,
|
|
29
46
|
lineNumbers: true,
|
|
30
|
-
content: toRef(
|
|
31
|
-
const { content, language, prettyPrintJson = false } = props;
|
|
32
|
-
if (typeof content !== "string") {
|
|
33
|
-
if (content == null) return "";
|
|
34
|
-
return String(content);
|
|
35
|
-
}
|
|
36
|
-
if (prettyPrintJson && language === "json") return prettifyJsoncString(content);
|
|
37
|
-
return content;
|
|
38
|
-
})),
|
|
47
|
+
content: toRef(displayContent),
|
|
39
48
|
language: toRef(() => props.language),
|
|
40
|
-
forceFoldGutter: true
|
|
49
|
+
forceFoldGutter: true,
|
|
50
|
+
extensions
|
|
41
51
|
});
|
|
42
52
|
const getCurrentContent = () => {
|
|
43
53
|
return codeMirror.value?.state.doc.toString() || "";
|
|
44
54
|
};
|
|
55
|
+
const toggleLineWrapping = () => {
|
|
56
|
+
isLineWrapping.value = !isLineWrapping.value;
|
|
57
|
+
};
|
|
45
58
|
return (_ctx, _cache) => {
|
|
46
59
|
return openBlock(), createElementBlock("div", _hoisted_1, [createElementVNode("div", _hoisted_2, [createElementVNode("div", {
|
|
47
60
|
ref_key: "codeMirrorRef",
|
|
48
61
|
ref: codeMirrorRef
|
|
49
|
-
}, null, 512)]), getCurrentContent() ? (openBlock(),
|
|
50
|
-
|
|
62
|
+
}, null, 512)]), getCurrentContent() ? (openBlock(), createElementBlock("div", _hoisted_3, [createVNode(unref(ScalarIconButton), {
|
|
63
|
+
class: "bg-b-2 text-c-2 hover:text-c-1 absolute right-18",
|
|
64
|
+
icon: unref(ScalarIconArrowElbowDownLeft),
|
|
65
|
+
"aria-pressed": isLineWrapping.value,
|
|
66
|
+
"aria-label": isLineWrapping.value ? "Disable line wrap" : "Wrap lines",
|
|
67
|
+
label: isLineWrapping.value ? "Disable line wrap" : "Wrap lines",
|
|
68
|
+
size: "sm",
|
|
69
|
+
tooltip: "",
|
|
70
|
+
variant: "ghost",
|
|
71
|
+
onClick: toggleLineWrapping
|
|
72
|
+
}, null, 8, [
|
|
73
|
+
"icon",
|
|
74
|
+
"aria-pressed",
|
|
75
|
+
"aria-label",
|
|
76
|
+
"label"
|
|
77
|
+
]), createVNode(unref(ScalarCodeBlockCopy), {
|
|
51
78
|
"aria-controls": unref(id),
|
|
52
|
-
class: "absolute top-2 right-2",
|
|
53
79
|
content: getCurrentContent()
|
|
54
|
-
}, null, 8, ["aria-controls", "content"])) : createCommentVNode("", true)]);
|
|
80
|
+
}, null, 8, ["aria-controls", "content"])])) : createCommentVNode("", true)]);
|
|
55
81
|
};
|
|
56
82
|
}
|
|
57
83
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ResponseBodyRaw.vue.script.js","names":[],"sources":["../../../../../src/v2/blocks/response-block/components/ResponseBodyRaw.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { ScalarCodeBlockCopy } from '@scalar/components/code-block'\nimport { useCodeMirror
|
|
1
|
+
{"version":3,"file":"ResponseBodyRaw.vue.script.js","names":[],"sources":["../../../../../src/v2/blocks/response-block/components/ResponseBodyRaw.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { ScalarCodeBlockCopy } from '@scalar/components/code-block'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { ScalarIconArrowElbowDownLeft } from '@scalar/icons'\nimport {\n EditorView,\n useCodeMirror,\n type CodeMirrorLanguage,\n} from '@scalar/use-codemirror'\nimport { computed, ref, toRef, useId } from 'vue'\n\nimport { prettifyJsoncString } from '@/v2/blocks/response-block/helpers/prettify-jsonc-string'\n\nconst props = defineProps<{\n content: unknown\n language: CodeMirrorLanguage | undefined\n /** When true, JSON/JSONC strings are pretty-printed for the Preview tab (wire bytes stay unchanged in Raw). */\n prettyPrintJson?: boolean\n}>()\n\nconst codeMirrorRef = ref<HTMLDivElement | null>(null)\n/** Base id for the code block */\nconst id = useId()\n\nconst isLineWrapping = ref(false)\n\nconst displayContent = computed((): string => {\n const { content, language, prettyPrintJson = false } = props\n if (typeof content !== 'string') {\n if (content == null) {\n return ''\n }\n return String(content)\n }\n if (prettyPrintJson && language === 'json') {\n return prettifyJsoncString(content)\n }\n return content\n})\n\nconst extensions = computed(() =>\n isLineWrapping.value ? [EditorView.lineWrapping] : [],\n)\n\nconst { codeMirror } = useCodeMirror({\n codeMirrorRef,\n readOnly: true,\n lineNumbers: true,\n content: toRef(displayContent),\n language: toRef(() => props.language),\n forceFoldGutter: true,\n extensions,\n})\n\n// Function to get current content\nconst getCurrentContent = () => {\n return codeMirror.value?.state.doc.toString() || ''\n}\n\nconst toggleLineWrapping = (): void => {\n isLineWrapping.value = !isLineWrapping.value\n}\n</script>\n<template>\n <div\n class=\"scalar-code-block group/code-block relative grid min-h-0 overflow-hidden p-px outline-none has-focus-visible:outline\"\n data-testid=\"response-body-raw\">\n <div\n class=\"custom-scroll relative pr-1\"\n tabindex=\"0\">\n <!-- CodeMirror container -->\n <div ref=\"codeMirrorRef\" />\n </div>\n <!-- Action buttons -->\n <div\n v-if=\"getCurrentContent()\"\n class=\"absolute top-2 right-2 flex items-center gap-1.5 opacity-0 transition-opacity duration-150 group-hover/code-block:opacity-100 group-has-focus-visible/code-block:opacity-100\">\n <ScalarIconButton\n class=\"bg-b-2 text-c-2 hover:text-c-1 absolute right-18\"\n :icon=\"ScalarIconArrowElbowDownLeft\"\n :aria-pressed=\"isLineWrapping\"\n :aria-label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n :label=\"isLineWrapping ? 'Disable line wrap' : 'Wrap lines'\"\n size=\"sm\"\n tooltip\n variant=\"ghost\"\n @click=\"toggleLineWrapping\" />\n <ScalarCodeBlockCopy\n :aria-controls=\"id\"\n :content=\"getCurrentContent()\" />\n </div>\n </div>\n</template>\n<style scoped>\n:deep(.cm-editor) {\n background-color: transparent;\n font-size: var(--scalar-small);\n outline: none;\n}\n\n:deep(.cm-gutters) {\n background-color: var(--scalar-background-1);\n border-radius: var(--scalar-radius) 0 0 var(--scalar-radius);\n}\n\n:deep(.cm-scroller) {\n overflow: auto;\n min-width: 100%;\n}\n\n:deep(.cm-lineWrapping .cm-line) {\n word-break: break-all;\n}\n</style>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;EAaA,MAAM,QAAQ;EAOd,MAAM,gBAAgB,IAA2B,IAAI;;EAErD,MAAM,KAAK,MAAM;EAEjB,MAAM,iBAAiB,IAAI,KAAK;EAEhC,MAAM,iBAAiB,eAAuB;GAC5C,MAAM,EAAE,SAAS,UAAU,kBAAkB,UAAU;GACvD,IAAI,OAAO,YAAY,UAAU;IAC/B,IAAI,WAAW,MACb,OAAO;IAET,OAAO,OAAO,OAAO;GACvB;GACA,IAAI,mBAAmB,aAAa,QAClC,OAAO,oBAAoB,OAAO;GAEpC,OAAO;EACT,CAAC;EAED,MAAM,aAAa,eACjB,eAAe,QAAQ,CAAC,WAAW,YAAY,IAAI,CAAC,CACtD;EAEA,MAAM,EAAE,eAAe,cAAc;GACnC;GACA,UAAU;GACV,aAAa;GACb,SAAS,MAAM,cAAc;GAC7B,UAAU,YAAY,MAAM,QAAQ;GACpC,iBAAiB;GACjB;EACF,CAAC;EAGD,MAAM,0BAA0B;GAC9B,OAAO,WAAW,OAAO,MAAM,IAAI,SAAS,KAAK;EACnD;EAEA,MAAM,2BAAiC;GACrC,eAAe,QAAQ,CAAC,eAAe;EACzC;;uBAGE,mBA2BM,OA3BN,YA2BM,CAxBJ,mBAKM,OALN,YAKM,CADJ,mBAA2B,OAAA;aAAlB;IAAJ,KAAI;oBAIH,kBAAiB,KAAA,UAAA,GADzB,mBAgBM,OAhBN,YAgBM,CAbJ,YASgC,MAAA,gBAAA,GAAA;IAR9B,OAAM;IACL,MAAM,MAAA,4BAAA;IACN,gBAAc,eAAA;IACd,cAAY,eAAA,QAAc,sBAAA;IAC1B,OAAO,eAAA,QAAc,sBAAA;IACtB,MAAK;IACL,SAAA;IACA,SAAQ;IACP,SAAO;;;;;;OACV,YAEmC,MAAA,mBAAA,GAAA;IADhC,iBAAe,MAAA,EAAA;IACf,SAAS,kBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-types.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/response-block/helpers/media-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAEhE,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAA;AAErF,KAAK,WAAW,GAAG;IACjB,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AA6JD,iEAAiE;AACjE,eAAO,MAAM,cAAc,EAAE,MAAM,EAEX,CAAA;AAExB,sCAAsC;AACtC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"media-types.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/response-block/helpers/media-types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAEhE,MAAM,MAAM,YAAY,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAA;AAErF,KAAK,WAAW,GAAG;IACjB,OAAO,CAAC,EAAE,YAAY,CAAA;IACtB,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,GAAG,CAAC,EAAE,OAAO,CAAA;IACb,QAAQ,CAAC,EAAE,kBAAkB,CAAA;IAC7B,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA;AA6JD,iEAAiE;AACjE,eAAO,MAAM,cAAc,EAAE,MAAM,EAEX,CAAA;AAExB,sCAAsC;AACtC,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS,CA0BxE;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD"}
|
|
@@ -244,6 +244,11 @@ function getMediaTypeConfig(type) {
|
|
|
244
244
|
language: "json",
|
|
245
245
|
preview: "json"
|
|
246
246
|
};
|
|
247
|
+
if (type.endsWith("+xml")) return {
|
|
248
|
+
extension: ".xml",
|
|
249
|
+
raw: true,
|
|
250
|
+
language: "xml"
|
|
251
|
+
};
|
|
247
252
|
}
|
|
248
253
|
/** Check if a media type that can be displayed as raw text */
|
|
249
254
|
function isTextMediaType(type) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media-types.js","names":[],"sources":["../../../../../src/v2/blocks/response-block/helpers/media-types.ts"],"sourcesContent":["import type { CodeMirrorLanguage } from '@scalar/use-codemirror'\n\nexport type MediaPreview = 'object' | 'image' | 'video' | 'audio' | 'json' | 'ndjson'\n\ntype MediaConfig = {\n preview?: MediaPreview\n alpha?: boolean\n raw?: boolean\n language?: CodeMirrorLanguage\n extension: string\n}\n\n/** Media Type (MIME Type) Definitions */\nconst mediaTypes: { [type: string]: MediaConfig | undefined } = {\n 'application/epub+zip': { extension: '.epub' },\n 'application/gzip': { extension: '.gz' },\n 'application/java-archive': { extension: '.jar' },\n 'application/javascript': { extension: '.js', raw: true },\n 'application/json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'application/ld+json': {\n extension: '.jsonld',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'application/problem+json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'application/vnd.api+json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'application/dns-json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n // Newline-delimited JSON is many JSON objects separated by newlines, not one\n // JSON document. The `ndjson` preview pretty-prints each line on its own, while\n // Raw keeps the exact wire format of one object per line.\n 'application/x-ndjson': {\n extension: '.ndjson',\n raw: true,\n language: 'json',\n preview: 'ndjson',\n },\n 'application/ndjson': {\n extension: '.ndjson',\n raw: true,\n language: 'json',\n preview: 'ndjson',\n },\n 'application/msword': { extension: '.doc' },\n 'application/octet-stream': { extension: '.bin' },\n 'application/ogg': { extension: '.ogx' },\n 'application/pdf': { extension: '.pdf', preview: 'object' },\n 'application/rtf': { extension: '.rtf', raw: true },\n 'application/vnd.amazon.ebook': { extension: '.azw' },\n 'application/vnd.apple.installer+xml': {\n extension: '.mpkg',\n raw: true,\n language: 'xml',\n },\n 'application/vnd.mozilla.xul+xml': {\n extension: '.xul',\n raw: true,\n language: 'xml',\n },\n 'application/vnd.ms-excel': { extension: '.xls' },\n 'application/vnd.ms-fontobject': { extension: '.eot' },\n 'application/vnd.ms-powerpoint': { extension: '.ppt' },\n 'application/vnd.oasis.opendocument.presentation': { extension: '.odp' },\n 'application/vnd.oasis.opendocument.spreadsheet': { extension: '.ods' },\n 'application/vnd.oasis.opendocument.text': { extension: '.odt' },\n 'application/vnd.openxmlformats-officedocument.presentationml.presentation': {\n extension: '.pptx',\n },\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {\n extension: '.xlsx',\n },\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': {\n extension: '.docx',\n },\n 'application/vnd.rar': { extension: '.rar' },\n 'application/vnd.visio': { extension: '.vsd' },\n 'application/x-7z-compressed': { extension: '.7z' },\n 'application/x-abiword': { extension: '.abw' },\n 'application/x-bzip': { extension: '.bz' },\n 'application/x-bzip2': { extension: '.bz2' },\n 'application/x-cdf': { extension: '.cda' },\n 'application/x-csh': { extension: '.csh' },\n 'application/x-freearc': { extension: '.arc' },\n 'application/x-httpd-php': { extension: '.php', raw: true },\n 'application/x-sh': { extension: '.sh', raw: true },\n 'application/x-tar': { extension: '.tar' },\n 'application/xhtml+xml': { extension: '.xhtml', raw: true, language: 'html' },\n 'application/xml': { extension: '.xml', raw: true, language: 'xml' },\n 'application/yaml': { extension: '.yaml', raw: true, language: 'yaml' },\n 'application/zip': { extension: '.zip' },\n 'audio/aac': { extension: '.aac' },\n 'audio/midi': { extension: '.midi' },\n 'audio/mpeg': { extension: '.mp3', preview: 'audio' },\n 'audio/ogg': { extension: '.oga' },\n 'audio/wav': { extension: '.wav' },\n 'audio/webm': { extension: '.weba' },\n 'font/otf': { extension: '.otf' },\n 'font/ttf': { extension: '.ttf' },\n 'font/woff': { extension: '.woff' },\n 'font/woff2': { extension: '.woff2' },\n 'image/apng': { extension: '.apng', preview: 'image', alpha: true },\n 'image/avif': { extension: '.avif', preview: 'image' },\n 'image/bmp': { extension: '.bmp', preview: 'image' },\n 'image/gif': { extension: '.gif', preview: 'image', alpha: true },\n 'image/jpeg': { extension: '.jpg', preview: 'image' },\n 'image/png': { extension: '.png', preview: 'image', alpha: true },\n 'image/svg+xml': {\n extension: '.svg',\n raw: true,\n language: 'xml',\n preview: 'image',\n alpha: true,\n },\n 'image/tiff': { extension: '.tiff' },\n 'image/vnd.microsoft.icon': { extension: '.ico', preview: 'image' },\n 'image/webp': { extension: '.webp', preview: 'image', alpha: true },\n 'text/calendar': { extension: '.ics', raw: true },\n 'text/css': { extension: '.css', raw: true, language: 'css' },\n 'text/csv': { extension: '.csv', raw: true },\n 'text/html': {\n extension: '.html',\n raw: true,\n language: 'html',\n preview: 'object',\n },\n 'text/javascript': { extension: '.js', raw: true },\n 'text/json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'text/plain': { extension: '.txt', raw: true },\n 'text/xml': { extension: '.xml', raw: true, language: 'xml' },\n 'text/yaml': { extension: '.yaml', raw: true, language: 'yaml' },\n 'video/3gpp': { extension: '.3gp' },\n 'audio/3gpp': { extension: '.3gp' },\n 'video/3gpp2': { extension: '.3g2' },\n 'audio/3gpp2': { extension: '.3g2' },\n 'video/mp2t': { extension: '.ts' },\n 'video/mp4': { extension: '.mp4', preview: 'video' },\n 'video/mpeg': { extension: '.mpeg' },\n 'video/ogg': { extension: '.ogv' },\n 'video/webm': { extension: '.webm', preview: 'video' },\n 'video/x-msvideo': { extension: '.avi' },\n}\n\n/** Media Types (MIME Types) that can be displayed as raw text */\nexport const textMediaTypes: string[] = Object.entries(mediaTypes)\n .filter(([, config]) => config?.raw)\n .map(([type]) => type)\n\n/** Get the config for a media type */\nexport function getMediaTypeConfig(type: string): MediaConfig | undefined {\n const config = mediaTypes[type]\n if (config) {\n return config\n }\n\n // Fallback for +json types\n if (type.endsWith('+json')) {\n return {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n }\n }\n\n return undefined\n}\n\n/** Check if a media type that can be displayed as raw text */\nexport function isTextMediaType(type: string): boolean {\n return !!getMediaTypeConfig(type)?.raw\n}\n"],"mappings":";;AAaA,IAAM,aAA0D;CAC9D,wBAAwB,EAAE,WAAW,QAAQ;CAC7C,oBAAoB,EAAE,WAAW,MAAM;CACvC,4BAA4B,EAAE,WAAW,OAAO;CAChD,0BAA0B;EAAE,WAAW;EAAO,KAAK;CAAK;CACxD,oBAAoB;EAClB,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CACA,uBAAuB;EACrB,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CACA,4BAA4B;EAC1B,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CACA,4BAA4B;EAC1B,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CACA,wBAAwB;EACtB,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CAIA,wBAAwB;EACtB,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CACA,sBAAsB;EACpB,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CACA,sBAAsB,EAAE,WAAW,OA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WAAW;EAAS,KAAK;EAAM,UAAU;CAAO;CAC/D,cAAc,EAAE,WAAW,OAAO;CAClC,cAAc,EAAE,WAAW,OAAO;CAClC,eAAe,EAAE,WAAW,OAAO;CACnC,eAAe,EAAE,WAAW,OAAO;CACnC,cAAc,EAAE,WAAW,MAAM;CACjC,aAAa;EAAE,WAAW;EAAQ,SAAS;CAAQ;CACnD,cAAc,EAAE,WAAW,QAAQ;CACnC,aAAa,EAAE,WAAW,OAAO;CACjC,cAAc;EAAE,WAAW;EAAS,SAAS;CAAQ;CACrD,mBAAmB,EAAE,WAAW,OAAO;AACzC;;AAGA,IAAa,iBAA2B,OAAO,QAAQ,UAAU,CAAC,CAC/D,QAAQ,GAAG,YAAY,QAAQ,GAAG,CAAC,CACnC,KAAK,CAAC,UAAU,IAAI;;AAGvB,SAAgB,mBAAmB,MAAuC;CACxE,MAAM,SAAS,WAAW;CAC1B,IAAI,QACF,OAAO;CAIT,IAAI,KAAK,SAAS,OAAO,GACvB,OAAO;EACL,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;AAIJ;;AAGA,SAAgB,gBAAgB,MAAuB;CACrD,OAAO,CAAC,CAAC,mBAAmB,IAAI,CAAC,EAAE;AACrC"}
|
|
1
|
+
{"version":3,"file":"media-types.js","names":[],"sources":["../../../../../src/v2/blocks/response-block/helpers/media-types.ts"],"sourcesContent":["import type { CodeMirrorLanguage } from '@scalar/use-codemirror'\n\nexport type MediaPreview = 'object' | 'image' | 'video' | 'audio' | 'json' | 'ndjson'\n\ntype MediaConfig = {\n preview?: MediaPreview\n alpha?: boolean\n raw?: boolean\n language?: CodeMirrorLanguage\n extension: string\n}\n\n/** Media Type (MIME Type) Definitions */\nconst mediaTypes: { [type: string]: MediaConfig | undefined } = {\n 'application/epub+zip': { extension: '.epub' },\n 'application/gzip': { extension: '.gz' },\n 'application/java-archive': { extension: '.jar' },\n 'application/javascript': { extension: '.js', raw: true },\n 'application/json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'application/ld+json': {\n extension: '.jsonld',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'application/problem+json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'application/vnd.api+json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'application/dns-json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n // Newline-delimited JSON is many JSON objects separated by newlines, not one\n // JSON document. The `ndjson` preview pretty-prints each line on its own, while\n // Raw keeps the exact wire format of one object per line.\n 'application/x-ndjson': {\n extension: '.ndjson',\n raw: true,\n language: 'json',\n preview: 'ndjson',\n },\n 'application/ndjson': {\n extension: '.ndjson',\n raw: true,\n language: 'json',\n preview: 'ndjson',\n },\n 'application/msword': { extension: '.doc' },\n 'application/octet-stream': { extension: '.bin' },\n 'application/ogg': { extension: '.ogx' },\n 'application/pdf': { extension: '.pdf', preview: 'object' },\n 'application/rtf': { extension: '.rtf', raw: true },\n 'application/vnd.amazon.ebook': { extension: '.azw' },\n 'application/vnd.apple.installer+xml': {\n extension: '.mpkg',\n raw: true,\n language: 'xml',\n },\n 'application/vnd.mozilla.xul+xml': {\n extension: '.xul',\n raw: true,\n language: 'xml',\n },\n 'application/vnd.ms-excel': { extension: '.xls' },\n 'application/vnd.ms-fontobject': { extension: '.eot' },\n 'application/vnd.ms-powerpoint': { extension: '.ppt' },\n 'application/vnd.oasis.opendocument.presentation': { extension: '.odp' },\n 'application/vnd.oasis.opendocument.spreadsheet': { extension: '.ods' },\n 'application/vnd.oasis.opendocument.text': { extension: '.odt' },\n 'application/vnd.openxmlformats-officedocument.presentationml.presentation': {\n extension: '.pptx',\n },\n 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': {\n extension: '.xlsx',\n },\n 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': {\n extension: '.docx',\n },\n 'application/vnd.rar': { extension: '.rar' },\n 'application/vnd.visio': { extension: '.vsd' },\n 'application/x-7z-compressed': { extension: '.7z' },\n 'application/x-abiword': { extension: '.abw' },\n 'application/x-bzip': { extension: '.bz' },\n 'application/x-bzip2': { extension: '.bz2' },\n 'application/x-cdf': { extension: '.cda' },\n 'application/x-csh': { extension: '.csh' },\n 'application/x-freearc': { extension: '.arc' },\n 'application/x-httpd-php': { extension: '.php', raw: true },\n 'application/x-sh': { extension: '.sh', raw: true },\n 'application/x-tar': { extension: '.tar' },\n 'application/xhtml+xml': { extension: '.xhtml', raw: true, language: 'html' },\n 'application/xml': { extension: '.xml', raw: true, language: 'xml' },\n 'application/yaml': { extension: '.yaml', raw: true, language: 'yaml' },\n 'application/zip': { extension: '.zip' },\n 'audio/aac': { extension: '.aac' },\n 'audio/midi': { extension: '.midi' },\n 'audio/mpeg': { extension: '.mp3', preview: 'audio' },\n 'audio/ogg': { extension: '.oga' },\n 'audio/wav': { extension: '.wav' },\n 'audio/webm': { extension: '.weba' },\n 'font/otf': { extension: '.otf' },\n 'font/ttf': { extension: '.ttf' },\n 'font/woff': { extension: '.woff' },\n 'font/woff2': { extension: '.woff2' },\n 'image/apng': { extension: '.apng', preview: 'image', alpha: true },\n 'image/avif': { extension: '.avif', preview: 'image' },\n 'image/bmp': { extension: '.bmp', preview: 'image' },\n 'image/gif': { extension: '.gif', preview: 'image', alpha: true },\n 'image/jpeg': { extension: '.jpg', preview: 'image' },\n 'image/png': { extension: '.png', preview: 'image', alpha: true },\n 'image/svg+xml': {\n extension: '.svg',\n raw: true,\n language: 'xml',\n preview: 'image',\n alpha: true,\n },\n 'image/tiff': { extension: '.tiff' },\n 'image/vnd.microsoft.icon': { extension: '.ico', preview: 'image' },\n 'image/webp': { extension: '.webp', preview: 'image', alpha: true },\n 'text/calendar': { extension: '.ics', raw: true },\n 'text/css': { extension: '.css', raw: true, language: 'css' },\n 'text/csv': { extension: '.csv', raw: true },\n 'text/html': {\n extension: '.html',\n raw: true,\n language: 'html',\n preview: 'object',\n },\n 'text/javascript': { extension: '.js', raw: true },\n 'text/json': {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n },\n 'text/plain': { extension: '.txt', raw: true },\n 'text/xml': { extension: '.xml', raw: true, language: 'xml' },\n 'text/yaml': { extension: '.yaml', raw: true, language: 'yaml' },\n 'video/3gpp': { extension: '.3gp' },\n 'audio/3gpp': { extension: '.3gp' },\n 'video/3gpp2': { extension: '.3g2' },\n 'audio/3gpp2': { extension: '.3g2' },\n 'video/mp2t': { extension: '.ts' },\n 'video/mp4': { extension: '.mp4', preview: 'video' },\n 'video/mpeg': { extension: '.mpeg' },\n 'video/ogg': { extension: '.ogv' },\n 'video/webm': { extension: '.webm', preview: 'video' },\n 'video/x-msvideo': { extension: '.avi' },\n}\n\n/** Media Types (MIME Types) that can be displayed as raw text */\nexport const textMediaTypes: string[] = Object.entries(mediaTypes)\n .filter(([, config]) => config?.raw)\n .map(([type]) => type)\n\n/** Get the config for a media type */\nexport function getMediaTypeConfig(type: string): MediaConfig | undefined {\n const config = mediaTypes[type]\n if (config) {\n return config\n }\n\n // Fallback for +json types\n if (type.endsWith('+json')) {\n return {\n extension: '.json',\n raw: true,\n language: 'json',\n preview: 'json',\n }\n }\n\n // Preserve specialized XML previews above, while treating other +xml types as text.\n if (type.endsWith('+xml')) {\n return {\n extension: '.xml',\n raw: true,\n language: 'xml',\n }\n }\n\n return undefined\n}\n\n/** Check if a media type that can be displayed as raw text */\nexport function isTextMediaType(type: string): boolean {\n return !!getMediaTypeConfig(type)?.raw\n}\n"],"mappings":";;AAaA,IAAM,aAA0D;CAC9D,wBAAwB,EAAE,WAAW,QAAQ;CAC7C,oBAAoB,EAAE,WAAW,MAAM;CACvC,4BAA4B,EAAE,WAAW,OAAO;CAChD,0BAA0B;EAAE,WAAW;EAAO,KAAK;CAAK;CACxD,oBAAoB;EAClB,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CACA,uBAAuB;EACrB,WAAW;EACX,KAAK;EACL,UAAU;EACV,SAAS;CACX;CACA,4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Selector.vue.script.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ScalarButton,\n type ScalarButton as ScalarButtonType,\n} from '@scalar/components/button'\nimport { ScalarComboboxMultiselect } from '@scalar/components/combobox'\nimport type { Icon } from '@scalar/components/icon'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { ScalarListboxCheckbox } from '@scalar/components/listbox'\nimport { useModal } from '@scalar/components/modal'\nimport { ScalarIconCaretDown, ScalarIconTrash } from '@scalar/icons'\nimport type { SelectedSecurity } from '@scalar/workspace-store/entities/auth'\nimport type {\n AuthMeta,\n WorkspaceEventBus,\n} from '@scalar/workspace-store/events'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n isAuthOptional,\n type MergedSecuritySchemes,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type {\n OpenApiDocument,\n SecurityRequirementObject,\n ServerObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { computed, ref, useId } from 'vue'\n\nimport DeleteRequestAuthModal from '@/v2/blocks/scalar-auth-selector-block/components/DeleteRequestAuthModal.vue'\nimport type { OAuth2Options } from '@/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue'\nimport {\n formatComplexScheme,\n formatScheme,\n getSecuritySchemeOptions,\n type SecuritySchemeOption,\n} from '@/v2/blocks/scalar-auth-selector-block/helpers/security-scheme'\nimport { CollapsibleSection } from '@/v2/components/layout'\n\nimport RequestAuthDataTable from './RequestAuthDataTable.vue'\n\nconst {\n environment,\n eventBus,\n createAnySecurityScheme = false,\n canDeleteSchemes = true,\n defaultOpen = true,\n isStatic = false,\n meta,\n proxyUrl,\n securityRequirements,\n securitySchemes,\n selectedSecurity,\n server,\n title,\n options,\n documentType,\n} = defineProps<{\n environment: XScalarEnvironment\n eventBus: WorkspaceEventBus\n /** Allows adding authentication which is not in the document */\n createAnySecurityScheme?: boolean\n /**\n * Whether schemes can be deleted from the selector. Enabled for the editable client, disabled in\n * the read-only reference where the schemes come from the document and cannot be removed.\n */\n canDeleteSchemes?: boolean\n /** Whether the authentication disclosure should start expanded */\n defaultOpen?: boolean\n /** Creates a static disclosure that cannot be collapsed */\n isStatic?: boolean\n meta: AuthMeta\n proxyUrl: string\n securityRequirements: OpenApiDocument['security']\n securitySchemes: MergedSecuritySchemes\n selectedSecurity: SelectedSecurity | undefined\n server: ServerObject | null\n title: string\n /** Any config options required for the OAuth2 flow */\n options?: OAuth2Options\n /** Type of the document the schemes belong to, used to label the missing-type warning */\n documentType?: 'openapi' | 'asyncapi'\n}>()\n\nconst titleId = useId()\nconst comboboxButtonRef = ref<typeof ScalarButtonType | null>(null)\nconst isDisclosureOpen = ref(false)\n\nconst deleteModal = useModal()\nconst schemeToDelete = ref<{\n label: string\n payload: SecurityRequirementObject\n} | null>(null)\n\n/**\n * Determines if authentication is required or optional\n *\n * Auth is optional when there is an empty security requirement and no complex requirements.\n * Complex requirements have multiple auth schemes combined (e.g., API key + OAuth).\n */\nconst authIndicator = computed<{ icon: Icon; text: string } | null>(() => {\n if (!securityRequirements?.length) {\n return null\n }\n\n const isOptional = isAuthOptional(securityRequirements)\n\n return {\n icon: isOptional ? 'Unlock' : 'Lock',\n text: isOptional ? 'Optional' : 'Required',\n }\n})\n\n/** All available auth scheme options for the dropdown */\nconst availableSchemeOptions = computed(() =>\n getSecuritySchemeOptions(\n securityRequirements ?? [],\n securitySchemes ?? {},\n selectedSecurity?.selectedSchemes ?? [],\n createAnySecurityScheme,\n ),\n)\n\n/** Currently active auth schemes selected for this operation or collection */\nconst activeSchemeOptions = computed<SecuritySchemeOption[]>(() => {\n const schemes = selectedSecurity?.selectedSchemes\n if (!schemes?.length) {\n return []\n }\n\n return schemes.flatMap((requirement) => {\n const schemeNames = Object.keys(requirement)\n\n if (schemeNames.length === 0) {\n return []\n }\n\n // Complex auth requirement with multiple schemes\n if (schemeNames.length > 1) {\n return formatComplexScheme(requirement)\n }\n\n // Simple auth requirement with single scheme\n const schemeName = schemeNames[0]\n if (!schemeName) {\n return []\n }\n\n const scheme = getResolvedRef(securitySchemes?.[schemeName])\n if (!scheme) {\n return []\n }\n\n return formatScheme({\n name: schemeName,\n value: requirement,\n })\n })\n})\n\n/**\n * Opens the combobox dropdown when clicking the auth indicator badge.\n * Prevents the disclosure from toggling if it is already open.\n */\nconst handleAuthIndicatorClick = (event: Event): void => {\n if (isDisclosureOpen.value) {\n event.stopPropagation()\n }\n comboboxButtonRef.value?.$el.click()\n}\n\n/**\n * Updates the selected auth schemes.\n * Separates existing schemes from newly created ones for the event payload.\n */\nconst handleSchemeSelection = (selected: SecuritySchemeOption[]): void => {\n const existingSchemes = selected\n .filter((option) => option.payload === undefined)\n .map((option) => unpackProxyObject(option.value, { depth: 2 }))\n\n const newSchemes = selected\n .filter((option) => option.payload !== undefined)\n .map((option) => ({\n name: option.label,\n scheme: option.payload!,\n }))\n\n eventBus.emit('auth:update:selected-security-schemes', {\n selectedRequirements: existingSchemes,\n newSchemes,\n meta,\n })\n}\n\n/** Shows the delete confirmation modal for the selected scheme */\nconst handleDeleteRequest = (option: {\n label: string\n value: SecurityRequirementObject\n}): void => {\n schemeToDelete.value = { label: option.label, payload: option.value }\n deleteModal.show()\n}\n\n/** Deletes the selected auth scheme after confirmation */\nconst handleDeleteConfirm = (): void => {\n if (!schemeToDelete.value) {\n return\n }\n\n eventBus.emit('auth:delete:security-scheme', {\n names: Object.keys(schemeToDelete.value.payload),\n })\n\n schemeToDelete.value = null\n deleteModal.hide()\n}\n\ndefineExpose({\n authIndicator,\n selectedSchemeOptions: activeSchemeOptions,\n schemeOptions: availableSchemeOptions,\n})\n</script>\n<template>\n <CollapsibleSection\n class=\"group/params relative\"\n :defaultOpen\n :isStatic=\"isStatic\"\n :itemCount=\"activeSchemeOptions.length\"\n @update:modelValue=\"(open) => (isDisclosureOpen = open)\">\n <template #title>\n <div\n :id=\"titleId\"\n class=\"inline-flex items-center gap-0.5 leading-[20px]\">\n <span>{{ title }}</span>\n\n <span\n v-if=\"authIndicator\"\n class=\"text-c-3 hover:bg-b-3 hover:text-c-1 -my-0.5 -mr-1 cursor-pointer rounded px-1 py-0.5 leading-[normal] font-normal\"\n :class=\"{ 'text-c-1': authIndicator.text === 'Required' }\"\n data-testid=\"auth-indicator\"\n @click=\"handleAuthIndicatorClick\">\n {{ authIndicator.text }}\n </span>\n </div>\n </template>\n\n <!-- Auth Dropdown (hidden when only one scheme is available) -->\n <template #actions>\n <ScalarComboboxMultiselect\n class=\"w-72 text-xs\"\n :modelValue=\"activeSchemeOptions\"\n multiple\n :options=\"availableSchemeOptions\"\n placement=\"bottom-end\"\n teleport\n @delete=\"handleDeleteRequest\"\n @update:modelValue=\"handleSchemeSelection\">\n <ScalarButton\n ref=\"comboboxButtonRef\"\n :aria-describedby=\"titleId\"\n class=\"group/combobox-button hover:text-c-1 text-c-2 flex h-fit w-full items-center gap-1 px-0.75 py-0.25 text-base font-normal\"\n variant=\"ghost\">\n <!-- Single auth scheme selected -->\n <template v-if=\"activeSchemeOptions.length === 1\">\n <span class=\"sr-only\">Selected Auth Type:</span>\n {{ activeSchemeOptions[0]?.label }}\n </template>\n\n <!-- Multiple auth schemes selected -->\n <template v-else-if=\"activeSchemeOptions.length > 1\">\n Multiple\n <span class=\"sr-only\">Auth Types Selected</span>\n </template>\n\n <!-- No auth schemes selected -->\n <template v-else>\n <span class=\"sr-only\">Select</span>\n Auth Type\n </template>\n\n <ScalarIconCaretDown\n class=\"size-3 shrink-0 transition-transform duration-100 group-aria-expanded/combobox-button:rotate-180\"\n weight=\"bold\" />\n </ScalarButton>\n\n <template #option=\"{ option, selected }\">\n <ScalarListboxCheckbox\n multiselect\n :selected=\"selected\" />\n <div class=\"min-w-0 flex-1 truncate\">\n {{ option.label }}\n </div>\n <ScalarIconButton\n v-if=\"option.isDeletable && canDeleteSchemes\"\n class=\"-m-0.5 shrink-0 p-0.5 opacity-0 group-hover/item:opacity-100\"\n :icon=\"ScalarIconTrash\"\n :label=\"`Delete ${option.label}`\"\n size=\"xs\"\n @click.stop=\"handleDeleteRequest(option)\" />\n </template>\n </ScalarComboboxMultiselect>\n </template>\n\n <!-- Auth Table -->\n <RequestAuthDataTable\n :activeAuthIndex=\"selectedSecurity?.selectedIndex ?? 0\"\n :documentType\n :environment\n :eventBus\n :isStatic\n :meta\n :options\n :proxyUrl\n :securitySchemes\n :selectedSchemeOptions=\"activeSchemeOptions\"\n :server />\n\n <!-- Delete Auth Modal -->\n <DeleteRequestAuthModal\n v-if=\"schemeToDelete\"\n :label=\"schemeToDelete.label\"\n :scheme=\"schemeToDelete\"\n :state=\"deleteModal\"\n @close=\"deleteModal.hide()\"\n @delete=\"handleDeleteConfirm\" />\n </CollapsibleSection>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqFA,MAAM,UAAU,MAAM;EACtB,MAAM,oBAAoB,IAAoC,IAAI;EAClE,MAAM,mBAAmB,IAAI,KAAK;EAElC,MAAM,cAAc,SAAS;EAC7B,MAAM,iBAAiB,IAGb,IAAI;;;;;;;EAQd,MAAM,gBAAgB,eAAoD;GACxE,IAAI,CAAC,QAAA,sBAAsB,QACzB,OAAO;GAGT,MAAM,aAAa,eAAe,QAAA,oBAAoB;GAEtD,OAAO;IACL,MAAM,aAAa,WAAW;IAC9B,MAAM,aAAa,aAAa;GAClC;EACF,CAAC;;EAGD,MAAM,yBAAyB,eAC7B,yBACE,QAAA,wBAAwB,CAAC,GACzB,QAAA,mBAAmB,CAAC,GACpB,QAAA,kBAAkB,mBAAmB,CAAC,GACtC,QAAA,uBACF,CACF;;EAGA,MAAM,sBAAsB,eAAuC;GACjE,MAAM,UAAU,QAAA,kBAAkB;GAClC,IAAI,CAAC,SAAS,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/blocks/scalar-auth-selector-block/components/AuthSelector.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport {\n ScalarButton,\n type ScalarButton as ScalarButtonType,\n} from '@scalar/components/button'\nimport { ScalarComboboxMultiselect } from '@scalar/components/combobox'\nimport type { Icon } from '@scalar/components/icon'\nimport { ScalarIconButton } from '@scalar/components/icon-button'\nimport { ScalarListboxCheckbox } from '@scalar/components/listbox'\nimport { useModal } from '@scalar/components/modal'\nimport { ScalarIconCaretDown, ScalarIconTrash } from '@scalar/icons'\nimport type { SelectedSecurity } from '@scalar/workspace-store/entities/auth'\nimport type {\n AuthMeta,\n WorkspaceEventBus,\n} from '@scalar/workspace-store/events'\nimport { getResolvedRef } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n isAuthOptional,\n type MergedSecuritySchemes,\n} from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type {\n OpenApiDocument,\n SecurityRequirementObject,\n ServerObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { computed, ref, useId } from 'vue'\n\nimport DeleteRequestAuthModal from '@/v2/blocks/scalar-auth-selector-block/components/DeleteRequestAuthModal.vue'\nimport type { OAuth2Options } from '@/v2/blocks/scalar-auth-selector-block/components/OAuth2.vue'\nimport {\n formatComplexScheme,\n formatScheme,\n getSecuritySchemeOptions,\n type SecuritySchemeOption,\n} from '@/v2/blocks/scalar-auth-selector-block/helpers/security-scheme'\nimport { CollapsibleSection } from '@/v2/components/layout'\n\nimport RequestAuthDataTable from './RequestAuthDataTable.vue'\n\nconst {\n environment,\n eventBus,\n createAnySecurityScheme = false,\n canDeleteSchemes = true,\n defaultOpen = true,\n isStatic = false,\n meta,\n proxyUrl,\n securityRequirements,\n securitySchemes,\n selectedSecurity,\n server,\n title,\n options,\n documentType,\n} = defineProps<{\n environment: XScalarEnvironment\n eventBus: WorkspaceEventBus\n /** Allows adding authentication which is not in the document */\n createAnySecurityScheme?: boolean\n /**\n * Whether schemes can be deleted from the selector. Enabled for the editable client, disabled in\n * the read-only reference where the schemes come from the document and cannot be removed.\n */\n canDeleteSchemes?: boolean\n /** Whether the authentication disclosure should start expanded */\n defaultOpen?: boolean\n /** Creates a static disclosure that cannot be collapsed */\n isStatic?: boolean\n meta: AuthMeta\n proxyUrl: string\n securityRequirements: OpenApiDocument['security']\n securitySchemes: MergedSecuritySchemes\n selectedSecurity: SelectedSecurity | undefined\n server: ServerObject | null\n title: string\n /** Any config options required for the OAuth2 flow */\n options?: OAuth2Options\n /** Type of the document the schemes belong to, used to label the missing-type warning */\n documentType?: 'openapi' | 'asyncapi'\n}>()\n\nconst titleId = useId()\nconst comboboxButtonRef = ref<typeof ScalarButtonType | null>(null)\nconst isDisclosureOpen = ref(false)\n\nconst deleteModal = useModal()\nconst schemeToDelete = ref<{\n label: string\n payload: SecurityRequirementObject\n} | null>(null)\n\n/**\n * Determines if authentication is required or optional\n *\n * Auth is optional when there is an empty security requirement and no complex requirements.\n * Complex requirements have multiple auth schemes combined (e.g., API key + OAuth).\n */\nconst authIndicator = computed<{ icon: Icon; text: string } | null>(() => {\n if (!securityRequirements?.length) {\n return null\n }\n\n const isOptional = isAuthOptional(securityRequirements)\n\n return {\n icon: isOptional ? 'Unlock' : 'Lock',\n text: isOptional ? 'Optional' : 'Required',\n }\n})\n\n/** All available auth scheme options for the dropdown */\nconst availableSchemeOptions = computed(() =>\n getSecuritySchemeOptions(\n securityRequirements ?? [],\n securitySchemes ?? {},\n selectedSecurity?.selectedSchemes ?? [],\n createAnySecurityScheme,\n ),\n)\n\n/** Currently active auth schemes selected for this operation or collection */\nconst activeSchemeOptions = computed<SecuritySchemeOption[]>(() => {\n const schemes = selectedSecurity?.selectedSchemes\n if (!schemes?.length) {\n return []\n }\n\n return schemes.flatMap((requirement) => {\n const schemeNames = Object.keys(requirement)\n\n if (schemeNames.length === 0) {\n return []\n }\n\n // Complex auth requirement with multiple schemes\n if (schemeNames.length > 1) {\n return formatComplexScheme(requirement)\n }\n\n // Simple auth requirement with single scheme\n const schemeName = schemeNames[0]\n if (!schemeName) {\n return []\n }\n\n const scheme = getResolvedRef(securitySchemes?.[schemeName])\n if (!scheme) {\n return []\n }\n\n return formatScheme({\n name: schemeName,\n value: requirement,\n })\n })\n})\n\n/**\n * Opens the combobox dropdown when clicking the auth indicator badge.\n * Prevents the disclosure from toggling if it is already open.\n */\nconst handleAuthIndicatorClick = (event: Event): void => {\n if (isDisclosureOpen.value) {\n event.stopPropagation()\n }\n comboboxButtonRef.value?.$el.click()\n}\n\n/**\n * Updates the selected auth schemes.\n * Separates existing schemes from newly created ones for the event payload.\n */\nconst handleSchemeSelection = (selected: SecuritySchemeOption[]): void => {\n const existingSchemes = selected\n .filter((option) => option.payload === undefined)\n .map((option) => unpackProxyObject(option.value, { depth: 2 }))\n\n const newSchemes = selected\n .filter((option) => option.payload !== undefined)\n .map((option) => ({\n name: option.label,\n scheme: option.payload!,\n }))\n\n eventBus.emit('auth:update:selected-security-schemes', {\n selectedRequirements: existingSchemes,\n newSchemes,\n meta,\n })\n}\n\n/** Shows the delete confirmation modal for the selected scheme */\nconst handleDeleteRequest = (option: {\n label: string\n value: SecurityRequirementObject\n}): void => {\n schemeToDelete.value = { label: option.label, payload: option.value }\n deleteModal.show()\n}\n\n/** Deletes the selected auth scheme after confirmation */\nconst handleDeleteConfirm = (): void => {\n if (!schemeToDelete.value) {\n return\n }\n\n eventBus.emit('auth:delete:security-scheme', {\n names: Object.keys(schemeToDelete.value.payload),\n })\n\n schemeToDelete.value = null\n deleteModal.hide()\n}\n\ndefineExpose({\n authIndicator,\n selectedSchemeOptions: activeSchemeOptions,\n schemeOptions: availableSchemeOptions,\n})\n</script>\n<template>\n <CollapsibleSection\n class=\"group/params relative\"\n :defaultOpen\n :isStatic=\"isStatic\"\n :itemCount=\"activeSchemeOptions.length\"\n @update:modelValue=\"(open) => (isDisclosureOpen = open)\">\n <template #title>\n <div\n :id=\"titleId\"\n class=\"inline-flex items-center gap-0.5 leading-[20px]\">\n <span>{{ title }}</span>\n\n <span\n v-if=\"authIndicator\"\n class=\"text-c-3 hover:bg-b-3 hover:text-c-1 -my-0.5 -mr-1 cursor-pointer rounded px-1 py-0.5 leading-[normal] font-normal\"\n :class=\"{ 'text-c-1': authIndicator.text === 'Required' }\"\n data-testid=\"auth-indicator\"\n @click=\"handleAuthIndicatorClick\">\n {{ authIndicator.text }}\n </span>\n </div>\n </template>\n\n <!-- Auth Dropdown (hidden when only one scheme is available) -->\n <template #actions>\n <ScalarComboboxMultiselect\n class=\"w-72 text-xs\"\n :modelValue=\"activeSchemeOptions\"\n multiple\n :options=\"availableSchemeOptions\"\n placement=\"bottom-end\"\n teleport\n @delete=\"handleDeleteRequest\"\n @update:modelValue=\"handleSchemeSelection\">\n <ScalarButton\n ref=\"comboboxButtonRef\"\n :aria-describedby=\"titleId\"\n class=\"group/combobox-button hover:text-c-1 text-c-2 flex h-fit w-full items-center gap-1 px-0.75 py-0.25 text-base font-normal\"\n variant=\"ghost\">\n <!-- Single auth scheme selected -->\n <template v-if=\"activeSchemeOptions.length === 1\">\n <span class=\"sr-only\">Selected Auth Type:</span>\n {{ activeSchemeOptions[0]?.label }}\n </template>\n\n <!-- Multiple auth schemes selected -->\n <template v-else-if=\"activeSchemeOptions.length > 1\">\n Multiple\n <span class=\"sr-only\">Auth Types Selected</span>\n </template>\n\n <!-- No auth schemes selected -->\n <template v-else>\n <span class=\"sr-only\">Select</span>\n Auth Type\n </template>\n\n <ScalarIconCaretDown\n class=\"size-3 shrink-0 transition-transform duration-100 group-aria-expanded/combobox-button:rotate-180\"\n weight=\"bold\" />\n </ScalarButton>\n\n <template #option=\"{ option, selected }\">\n <ScalarListboxCheckbox\n multiselect\n :selected=\"selected\" />\n <div class=\"min-w-0 flex-1 truncate\">\n {{ option.label }}\n </div>\n <ScalarIconButton\n v-if=\"option.isDeletable && canDeleteSchemes\"\n class=\"-m-0.5 shrink-0 p-0.5 opacity-0 group-hover/item:opacity-100\"\n :icon=\"ScalarIconTrash\"\n :label=\"`Delete ${option.label}`\"\n size=\"xs\"\n @click.stop=\"handleDeleteRequest(option)\" />\n </template>\n </ScalarComboboxMultiselect>\n </template>\n\n <!-- Auth Table -->\n <RequestAuthDataTable\n :activeAuthIndex=\"selectedSecurity?.selectedIndex ?? 0\"\n :documentType\n :environment\n :eventBus\n :isStatic\n :meta\n :options\n :proxyUrl\n :securitySchemes\n :selectedSchemeOptions=\"activeSchemeOptions\"\n :server />\n\n <!-- Delete Auth Modal -->\n <DeleteRequestAuthModal\n v-if=\"schemeToDelete\"\n :label=\"schemeToDelete.label\"\n :scheme=\"schemeToDelete\"\n :state=\"deleteModal\"\n @close=\"deleteModal.hide()\"\n @delete=\"handleDeleteConfirm\" />\n </CollapsibleSection>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAqFA,MAAM,UAAU,MAAM;EACtB,MAAM,oBAAoB,IAAoC,IAAI;EAClE,MAAM,mBAAmB,IAAI,KAAK;EAElC,MAAM,cAAc,SAAS;EAC7B,MAAM,iBAAiB,IAGb,IAAI;;;;;;;EAQd,MAAM,gBAAgB,eAAoD;GACxE,IAAI,CAAC,QAAA,sBAAsB,QACzB,OAAO;GAGT,MAAM,aAAa,eAAe,QAAA,oBAAoB;GAEtD,OAAO;IACL,MAAM,aAAa,WAAW;IAC9B,MAAM,aAAa,aAAa;GAClC;EACF,CAAC;;EAGD,MAAM,yBAAyB,eAC7B,yBACE,QAAA,wBAAwB,CAAC,GACzB,QAAA,mBAAmB,CAAC,GACpB,QAAA,kBAAkB,mBAAmB,CAAC,GACtC,QAAA,uBACF,CACF;;EAGA,MAAM,sBAAsB,eAAuC;GACjE,MAAM,UAAU,QAAA,kBAAkB;GAClC,IAAI,CAAC,SAAS,QACZ,OAAO,CAAC;GAGV,OAAO,QAAQ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ironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments';
|
|
3
|
+
import type { OAuth2Object } from '@scalar/workspace-store/schemas/v3.2/strict/security-scheme';
|
|
4
|
+
import type { CustomFetch } from '../../../../v2/blocks/operation-block/helpers/send-request.js';
|
|
5
|
+
type __VLS_Props = {
|
|
6
|
+
scheme: OAuth2Object;
|
|
7
|
+
name: string;
|
|
8
|
+
environment: XScalarEnvironment;
|
|
9
|
+
eventBus: WorkspaceEventBus;
|
|
10
|
+
proxyUrl: string;
|
|
11
|
+
customFetch?: CustomFetch;
|
|
12
|
+
};
|
|
13
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
|
+
declare const _default: typeof __VLS_export;
|
|
15
|
+
export default _default;
|
|
16
|
+
//# sourceMappingURL=OAuth2Metadata.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuth2Metadata.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue"],"names":[],"mappings":"AAgGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2EAA2E,CAAA;AACnH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,6DAA6D,CAAA;AAE/F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAOnF,KAAK,WAAW,GAAG;IACf,MAAM,EAAE,YAAY,CAAA;IACpB,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,kBAAkB,CAAA;IAC/B,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B,CAAC;AAiKJ,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import OAuth2Metadata_vue_vue_type_script_setup_true_lang_default from "./OAuth2Metadata.vue.script.js";
|
|
2
|
+
//#region src/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue
|
|
3
|
+
var OAuth2Metadata_default = OAuth2Metadata_vue_vue_type_script_setup_true_lang_default;
|
|
4
|
+
//#endregion
|
|
5
|
+
export { OAuth2Metadata_default as default };
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=OAuth2Metadata.vue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuth2Metadata.vue.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport { useLoadingState } from '@scalar/components/loading'\nimport { useToasts } from '@scalar/use-toasts'\nimport type { WorkspaceEventBus } from '@scalar/workspace-store/events'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type { OAuth2Object } from '@scalar/workspace-store/schemas/v3.2/strict/security-scheme'\n\nimport type { CustomFetch } from '@/v2/blocks/operation-block/helpers/send-request'\nimport { fetchOAuth2Metadata } from '@/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata'\nimport { oauth2MetadataToFlows } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows'\nimport { DataTableRow } from '@/v2/components/data-table'\n\nimport RequestAuthDataTableInput from './RequestAuthDataTableInput.vue'\n\nconst { scheme, name, environment, eventBus, proxyUrl, customFetch } =\n defineProps<{\n scheme: OAuth2Object\n name: string\n environment: XScalarEnvironment\n eventBus: WorkspaceEventBus\n proxyUrl: string\n customFetch?: CustomFetch\n }>()\nconst loader = useLoadingState()\nconst { toast } = useToasts()\n\nconst updateMetadataUrl = (oauth2MetadataUrl: string): void =>\n eventBus.emit('auth:update:security-scheme', {\n name,\n payload: { type: 'oauth2', oauth2MetadataUrl },\n })\n\n/** Apply metadata only to the scheme and URL that initiated the request. */\nconst fetchConfiguration = async (): Promise<void> => {\n const url = scheme.oauth2MetadataUrl\n const schemeName = name\n if (!url || loader.isLoading) {\n return\n }\n loader.start()\n const [error, metadata] = await fetchOAuth2Metadata(\n url,\n proxyUrl,\n customFetch,\n )\n await loader.clear()\n // Store updates can replace the proxy without changing the selected authorization server.\n if (name !== schemeName || scheme.oauth2MetadataUrl !== url) {\n return\n }\n if (error) {\n toast(error.message, 'error')\n return\n }\n eventBus.emit('auth:update:security-scheme', {\n name,\n payload: {\n type: 'oauth2',\n flows: oauth2MetadataToFlows(metadata, scheme.flows),\n },\n })\n}\n</script>\n\n<template>\n <DataTableRow>\n <RequestAuthDataTableInput\n :environment\n :modelValue=\"scheme.oauth2MetadataUrl ?? ''\"\n placeholder=\"https://example.com/.well-known/oauth-authorization-server\"\n @update:modelValue=\"updateMetadataUrl\">\n Metadata URL\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow\n v-if=\"scheme.oauth2MetadataUrl\"\n class=\"min-w-full\">\n <div class=\"flex h-8 w-full items-center justify-end border-t\">\n <ScalarButton\n class=\"mr-0.75 p-0 px-2 py-0.5\"\n :loader\n size=\"sm\"\n variant=\"outlined\"\n @click=\"fetchConfiguration\">\n Fetch Configuration\n </ScalarButton>\n </div>\n </DataTableRow>\n</template>\n"],"mappings":""}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import DataTableRow_default from "../../../components/data-table/DataTableRow.vue.js";
|
|
2
|
+
import RequestAuthDataTableInput_default from "./RequestAuthDataTableInput.vue.js";
|
|
3
|
+
import { fetchOAuth2Metadata } from "../helpers/fetch-oauth2-metadata.js";
|
|
4
|
+
import { oauth2MetadataToFlows } from "../helpers/oauth2-metadata-to-flows.js";
|
|
5
|
+
import { Fragment, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, openBlock, unref, withCtx } from "vue";
|
|
6
|
+
import { ScalarButton } from "@scalar/components/button";
|
|
7
|
+
import { useToasts } from "@scalar/use-toasts";
|
|
8
|
+
import { useLoadingState } from "@scalar/components/loading";
|
|
9
|
+
//#region src/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue?vue&type=script&setup=true&lang.ts
|
|
10
|
+
var _hoisted_1 = { class: "flex h-8 w-full items-center justify-end border-t" };
|
|
11
|
+
var OAuth2Metadata_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
12
|
+
__name: "OAuth2Metadata",
|
|
13
|
+
props: {
|
|
14
|
+
scheme: {},
|
|
15
|
+
name: {},
|
|
16
|
+
environment: {},
|
|
17
|
+
eventBus: {},
|
|
18
|
+
proxyUrl: {},
|
|
19
|
+
customFetch: {}
|
|
20
|
+
},
|
|
21
|
+
setup(__props) {
|
|
22
|
+
const loader = useLoadingState();
|
|
23
|
+
const { toast } = useToasts();
|
|
24
|
+
const updateMetadataUrl = (oauth2MetadataUrl) => __props.eventBus.emit("auth:update:security-scheme", {
|
|
25
|
+
name: __props.name,
|
|
26
|
+
payload: {
|
|
27
|
+
type: "oauth2",
|
|
28
|
+
oauth2MetadataUrl
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
/** Apply metadata only to the scheme and URL that initiated the request. */
|
|
32
|
+
const fetchConfiguration = async () => {
|
|
33
|
+
const url = __props.scheme.oauth2MetadataUrl;
|
|
34
|
+
const schemeName = __props.name;
|
|
35
|
+
if (!url || loader.isLoading) return;
|
|
36
|
+
loader.start();
|
|
37
|
+
const [error, metadata] = await fetchOAuth2Metadata(url, __props.proxyUrl, __props.customFetch);
|
|
38
|
+
await loader.clear();
|
|
39
|
+
if (__props.name !== schemeName || __props.scheme.oauth2MetadataUrl !== url) return;
|
|
40
|
+
if (error) {
|
|
41
|
+
toast(error.message, "error");
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
__props.eventBus.emit("auth:update:security-scheme", {
|
|
45
|
+
name: __props.name,
|
|
46
|
+
payload: {
|
|
47
|
+
type: "oauth2",
|
|
48
|
+
flows: oauth2MetadataToFlows(metadata, __props.scheme.flows)
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
return (_ctx, _cache) => {
|
|
53
|
+
return openBlock(), createElementBlock(Fragment, null, [createVNode(unref(DataTableRow_default), null, {
|
|
54
|
+
default: withCtx(() => [createVNode(RequestAuthDataTableInput_default, {
|
|
55
|
+
environment: __props.environment,
|
|
56
|
+
modelValue: __props.scheme.oauth2MetadataUrl ?? "",
|
|
57
|
+
placeholder: "https://example.com/.well-known/oauth-authorization-server",
|
|
58
|
+
"onUpdate:modelValue": updateMetadataUrl
|
|
59
|
+
}, {
|
|
60
|
+
default: withCtx(() => [..._cache[0] || (_cache[0] = [createTextVNode(" Metadata URL ", -1)])]),
|
|
61
|
+
_: 1
|
|
62
|
+
}, 8, ["environment", "modelValue"])]),
|
|
63
|
+
_: 1
|
|
64
|
+
}), __props.scheme.oauth2MetadataUrl ? (openBlock(), createBlock(unref(DataTableRow_default), {
|
|
65
|
+
key: 0,
|
|
66
|
+
class: "min-w-full"
|
|
67
|
+
}, {
|
|
68
|
+
default: withCtx(() => [createElementVNode("div", _hoisted_1, [createVNode(unref(ScalarButton), {
|
|
69
|
+
class: "mr-0.75 p-0 px-2 py-0.5",
|
|
70
|
+
loader: unref(loader),
|
|
71
|
+
size: "sm",
|
|
72
|
+
variant: "outlined",
|
|
73
|
+
onClick: fetchConfiguration
|
|
74
|
+
}, {
|
|
75
|
+
default: withCtx(() => [..._cache[1] || (_cache[1] = [createTextVNode(" Fetch Configuration ", -1)])]),
|
|
76
|
+
_: 1
|
|
77
|
+
}, 8, ["loader"])])]),
|
|
78
|
+
_: 1
|
|
79
|
+
})) : createCommentVNode("", true)], 64);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
//#endregion
|
|
84
|
+
export { OAuth2Metadata_vue_vue_type_script_setup_true_lang_default as default };
|
|
85
|
+
|
|
86
|
+
//# sourceMappingURL=OAuth2Metadata.vue.script.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"OAuth2Metadata.vue.script.js","names":[],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/OAuth2Metadata.vue"],"sourcesContent":["<script setup lang=\"ts\">\nimport { ScalarButton } from '@scalar/components/button'\nimport { useLoadingState } from '@scalar/components/loading'\nimport { useToasts } from '@scalar/use-toasts'\nimport type { WorkspaceEventBus } from '@scalar/workspace-store/events'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type { OAuth2Object } from '@scalar/workspace-store/schemas/v3.2/strict/security-scheme'\n\nimport type { CustomFetch } from '@/v2/blocks/operation-block/helpers/send-request'\nimport { fetchOAuth2Metadata } from '@/v2/blocks/scalar-auth-selector-block/helpers/fetch-oauth2-metadata'\nimport { oauth2MetadataToFlows } from '@/v2/blocks/scalar-auth-selector-block/helpers/oauth2-metadata-to-flows'\nimport { DataTableRow } from '@/v2/components/data-table'\n\nimport RequestAuthDataTableInput from './RequestAuthDataTableInput.vue'\n\nconst { scheme, name, environment, eventBus, proxyUrl, customFetch } =\n defineProps<{\n scheme: OAuth2Object\n name: string\n environment: XScalarEnvironment\n eventBus: WorkspaceEventBus\n proxyUrl: string\n customFetch?: CustomFetch\n }>()\nconst loader = useLoadingState()\nconst { toast } = useToasts()\n\nconst updateMetadataUrl = (oauth2MetadataUrl: string): void =>\n eventBus.emit('auth:update:security-scheme', {\n name,\n payload: { type: 'oauth2', oauth2MetadataUrl },\n })\n\n/** Apply metadata only to the scheme and URL that initiated the request. */\nconst fetchConfiguration = async (): Promise<void> => {\n const url = scheme.oauth2MetadataUrl\n const schemeName = name\n if (!url || loader.isLoading) {\n return\n }\n loader.start()\n const [error, metadata] = await fetchOAuth2Metadata(\n url,\n proxyUrl,\n customFetch,\n )\n await loader.clear()\n // Store updates can replace the proxy without changing the selected authorization server.\n if (name !== schemeName || scheme.oauth2MetadataUrl !== url) {\n return\n }\n if (error) {\n toast(error.message, 'error')\n return\n }\n eventBus.emit('auth:update:security-scheme', {\n name,\n payload: {\n type: 'oauth2',\n flows: oauth2MetadataToFlows(metadata, scheme.flows),\n },\n })\n}\n</script>\n\n<template>\n <DataTableRow>\n <RequestAuthDataTableInput\n :environment\n :modelValue=\"scheme.oauth2MetadataUrl ?? ''\"\n placeholder=\"https://example.com/.well-known/oauth-authorization-server\"\n @update:modelValue=\"updateMetadataUrl\">\n Metadata URL\n </RequestAuthDataTableInput>\n </DataTableRow>\n <DataTableRow\n v-if=\"scheme.oauth2MetadataUrl\"\n class=\"min-w-full\">\n <div class=\"flex h-8 w-full items-center justify-end border-t\">\n <ScalarButton\n class=\"mr-0.75 p-0 px-2 py-0.5\"\n :loader\n size=\"sm\"\n variant=\"outlined\"\n @click=\"fetchConfiguration\">\n Fetch Configuration\n </ScalarButton>\n </div>\n </DataTableRow>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;EAwBA,MAAM,SAAS,gBAAgB;EAC/B,MAAM,EAAE,UAAU,UAAU;EAE5B,MAAM,qBAAqB,sBACzB,QAAA,SAAS,KAAK,+BAA+B;GAC3C,MAAG,QAAA;GACH,SAAS;IAAE,MAAM;IAAU;GAAkB;EAC/C,CAAC;;EAGH,MAAM,qBAAqB,YAA2B;GACpD,MAAM,MAAM,QAAA,OAAO;GACnB,MAAM,aAAa,QAAA;GACnB,IAAI,CAAC,OAAO,OAAO,WACjB;GAEF,OAAO,MAAM;GACb,MAAM,CAAC,OAAO,YAAY,MAAM,oBAC9B,KACA,QAAA,UACA,QAAA,WACF;GACA,MAAM,OAAO,MAAM;GAEnB,IAAI,QAAA,SAAS,cAAc,QAAA,OAAO,sBAAsB,KACtD;GAEF,IAAI,OAAO;IACT,MAAM,MAAM,SAAS,OAAO;IAC5B;GACF;GACA,QAAA,SAAS,KAAK,+BAA+B;IAC3C,MAAG,QAAA;IACH,SAAS;KACP,MAAM;KACN,OAAO,sBAAsB,UAAU,QAAA,OAAO,KAAK;IACrD;GACF,CAAC;EACH;;2DAIE,YAQe,MAAA,oBAAA,GAAA,MAAA;2BADe,CAN5B,YAM4B,mCAAA;KALzB,aAAA,QAAA;KACA,YAAY,QAAA,OAAO,qBAAiB;KACrC,aAAY;KACX,uBAAmB;;4BAEtB,CAAA,GAAA,OAAA,OAAA,OAAA,KAAA,CAAA,gBAFyC,kBAEzC,EAAA,CAAA,EAAA,CAAA;;;;OAGM,QAAA,OAAO,qBAAA,UAAA,GADf,YAae,MAAA,oBAAA,GAAA;;IAXb,OAAM;;2BAUA,CATN,mBASM,OATN,YASM,CARJ,YAOe,MAAA,YAAA,GAAA;KANb,OAAM;KACL,QAAA,MAAA,MAAA;KACD,MAAK;KACL,SAAQ;KACP,SAAO;;4BAEV,CAAA,GAAA,OAAA,OAAA,OAAA,KAAA,CAAA,gBAF8B,yBAE9B,EAAA,CAAA,EAAA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestAuthTab.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RequestAuthTab.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/RequestAuthTab.vue"],"names":[],"mappings":"AA0rBA,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,gCAAgC,CAAA;AAEvC,OAAO,EAEL,KAAK,qBAAqB,EAG3B,MAAM,yCAAyC,CAAA;AAChD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2EAA2E,CAAA;AAEnH,OAAO,KAAK,EAEV,yBAAyB,EACzB,YAAY,EACb,MAAM,8DAA8D,CAAA;AAgBrE,OAAe,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAA;AAazD,KAAK,WAAW,GAAG;IACjB,wCAAwC;IACxC,WAAW,EAAE,kBAAkB,CAAA;IAC/B,yFAAyF;IACzF,QAAQ,EAAE,OAAO,CAAA;IACjB,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,+BAA+B;IAC/B,uBAAuB,EAAE,yBAAyB,CAAA;IAClD,oGAAoG;IACpG,eAAe,EAAE,qBAAqB,CAAA;IACtC,mCAAmC;IACnC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAA;IAC3B,2CAA2C;IAC3C,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,uDAAuD;IACvD,OAAO,CAAC,EAAE,aAAa,CAAA;IACvB,yFAAyF;IACzF,YAAY,CAAC,EAAE,SAAS,GAAG,UAAU,CAAA;CACtC,CAAC;AAwtCF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|