@scalar/api-client 3.24.0 → 3.25.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 +16 -0
- package/dist/style.css +50 -42
- package/dist/v2/blocks/request-block/RequestBlock.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBody.vue.d.ts +2 -2
- 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_vue_type_script_setup_true_lang.js +40 -4
- package/dist/v2/blocks/request-block/components/RequestBody.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue.d.ts +3 -1
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue_vue_type_script_setup_true_lang.js +20 -5
- package/dist/v2/blocks/request-block/components/RequestBodyForm.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue.d.ts +15 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue.d.ts.map +1 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue.js +7 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue.js.map +1 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue_vue_type_script_setup_true_lang.js +156 -0
- package/dist/v2/blocks/request-block/components/RequestBodyMultipart.vue_vue_type_script_setup_true_lang.js.map +1 -0
- package/dist/v2/blocks/request-block/components/RequestTable.vue.d.ts +2 -0
- package/dist/v2/blocks/request-block/components/RequestTable.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue.js +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTable.vue_vue_type_script_setup_true_lang.js +6 -0
- package/dist/v2/blocks/request-block/components/RequestTable.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.d.ts +4 -0
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue.js.map +1 -1
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue_vue_type_script_setup_true_lang.js +10 -3
- package/dist/v2/blocks/request-block/components/RequestTableRow.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.d.ts +2 -2
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js +8 -4
- package/dist/v2/blocks/request-block/helpers/get-form-body-rows.js.map +1 -1
- package/dist/v2/blocks/request-block/helpers/multipart-body.d.ts +18 -0
- package/dist/v2/blocks/request-block/helpers/multipart-body.d.ts.map +1 -0
- package/dist/v2/blocks/request-block/helpers/multipart-body.js +80 -0
- package/dist/v2/blocks/request-block/helpers/multipart-body.js.map +1 -0
- package/dist/v2/blocks/request-block/helpers/structured-body-codec.d.ts.map +1 -1
- package/dist/v2/blocks/request-block/helpers/structured-body-codec.js +2 -1
- package/dist/v2/blocks/request-block/helpers/structured-body-codec.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/AuthSelector.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.d.ts +2 -2
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue_vue_type_script_setup_true_lang.js +2 -0
- package/dist/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue_vue_type_script_setup_true_lang.js.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.d.ts.map +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js +1 -1
- package/dist/v2/blocks/scalar-auth-selector-block/helpers/security-scheme.js.map +1 -1
- package/dist/v2/constants.js +1 -1
- package/dist/v2/features/localization/locales/ar.d.ts +3 -0
- package/dist/v2/features/localization/locales/ar.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/ar.js +3 -0
- package/dist/v2/features/localization/locales/ar.js.map +1 -1
- package/dist/v2/features/localization/locales/de.d.ts +3 -0
- package/dist/v2/features/localization/locales/de.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/de.js +3 -0
- package/dist/v2/features/localization/locales/de.js.map +1 -1
- package/dist/v2/features/localization/locales/es.d.ts +3 -0
- package/dist/v2/features/localization/locales/es.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/es.js +3 -0
- package/dist/v2/features/localization/locales/es.js.map +1 -1
- package/dist/v2/features/localization/locales/fr.d.ts +3 -0
- package/dist/v2/features/localization/locales/fr.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/fr.js +3 -0
- package/dist/v2/features/localization/locales/fr.js.map +1 -1
- package/dist/v2/features/localization/locales/pt.d.ts +3 -0
- package/dist/v2/features/localization/locales/pt.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/pt.js +3 -0
- package/dist/v2/features/localization/locales/pt.js.map +1 -1
- package/dist/v2/features/localization/locales/ru.d.ts +3 -0
- package/dist/v2/features/localization/locales/ru.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/ru.js +3 -0
- package/dist/v2/features/localization/locales/ru.js.map +1 -1
- package/dist/v2/features/localization/locales/zh-cn.d.ts +3 -0
- package/dist/v2/features/localization/locales/zh-cn.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/zh-cn.js +3 -0
- package/dist/v2/features/localization/locales/zh-cn.js.map +1 -1
- package/dist/v2/features/localization/locales/zh-tw.d.ts +3 -0
- package/dist/v2/features/localization/locales/zh-tw.d.ts.map +1 -1
- package/dist/v2/features/localization/locales/zh-tw.js +3 -0
- package/dist/v2/features/localization/locales/zh-tw.js.map +1 -1
- package/dist/v2/features/localization/translations.d.ts +3 -0
- package/dist/v2/features/localization/translations.d.ts.map +1 -1
- package/dist/v2/features/localization/translations.js +3 -0
- package/dist/v2/features/localization/translations.js.map +1 -1
- package/dist/vue-styles.css +4 -4
- package/package.json +15 -18
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RequestTableRow.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","DataTableRow","_normalizeClass","_withCtx","_createVNode","DataTableCheckbox","DataTableCell","CodeInputLite","DataTableInputSelect","_createCommentVNode","RequestTableTooltip","_createElementBlock","_Fragment","_createElementVNode","_toDisplayString"],"sources":["../../../../../src/v2/blocks/request-block/components/RequestTableRow.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 { ScalarIconGlobe, ScalarIconTrash } from '@scalar/icons'\nimport type { ApiReferenceEvents } from '@scalar/workspace-store/events'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type {\n ParameterObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { computed, ref, useTemplateRef, watch } from 'vue'\n\nimport { getFileName } from '@/v2/blocks/request-block/helpers/files'\nimport { validateParameter } from '@/v2/blocks/request-block/helpers/validate-parameter'\nimport { CodeInputLite } from '@/v2/components/code-input'\nimport {\n DataTableCell,\n DataTableCheckbox,\n DataTableInputSelect,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport RequestTableTooltip from './RequestTableTooltip.vue'\n\nconst {\n data,\n environment,\n hasCheckboxDisabled,\n deferKeyUpdates,\n invalidParams,\n showUploadButton,\n} = defineProps<{\n data: TableRow\n /** Keep key edits local until blur when the row identity depends on its name. */\n deferKeyUpdates?: boolean\n hasCheckboxDisabled?: boolean\n invalidParams?: Set<string>\n label?: string\n environment: XScalarEnvironment\n showUploadButton?: boolean\n}>()\n\nconst emit = defineEmits<{\n (e: 'upsertRow', payload: TableRowUpsertPayload): void\n (e: 'deleteRow'): void\n (e: 'uploadFile'): void\n (e: 'removeFile'): void\n (e: 'navigate', route: NonNullable<TableRow['globalRoute']>): void\n /** Select a value for a grouped global cookie preset. */\n (e: 'selectPreset', value: string): void\n}>()\n\nconst { translate } = useLocalization()\n\nconst valueInput = useTemplateRef('valueInput')\ndefineExpose({ focusValue: (): void => valueInput.value?.focus() })\n\nexport type TableRow = {\n /** The parameter or field name/key */\n name: string\n /** The parameter value, can be a string, file, or null */\n value: string | File | null\n /** Optional description for the parameter */\n description?: string\n /** Optional route for global parameters (e.g., cookies shared across workspace) */\n globalRoute?: ApiReferenceEvents['ui:navigate']\n /** Whether the parameter is disabled/inactive */\n isDisabled?: boolean\n /** Whether an optional parameter is disabled because it has no explicit x-disabled value */\n isDisabledByDefault?: boolean\n /** OpenAPI schema object with type, validation rules, examples, etc. */\n schema?: SchemaObject\n /** Preserve array values even while their JSON text is temporarily invalid. */\n isArray?: boolean\n /** Text representation used by array enum controls. */\n arrayEncoding?: 'json' | 'comma-separated'\n /** Whether the parameter is required */\n isRequired?: boolean\n /**\n * Whether the parameter is readonly and can not be modifies directly\n * User can still override the parameter which is going to show up with the linethrough style\n */\n isReadonly?: boolean\n /** Whether the parameter is overridden later on */\n isOverridden?: boolean\n /** Track the original parameter so we can update it */\n originalParameter?: ParameterObject\n /** Path to a value inside the original parameter example for expanded object parameters */\n sourceParameterValuePath?: string[]\n /**\n * Selectable values for a grouped global cookie preset. When set, the value cell renders a\n * dropdown to switch between predefined values (for example a `Culture` cookie with `PL`/`EN`)\n * instead of an editable input.\n */\n presetOptions?: string[]\n}\n\nexport type TableRowUpsertPayload = {\n name: string\n value: string | File\n isDisabled: boolean\n shouldRenameExpandedRow?: boolean\n}\n\n/**\n * Track local state for the row\n *\n * Now this is required because of the way we get default values from the schema.\n * If we have a default value in data.value, then we update isDisabled to true. We lose the default value since now\n * we have an example where value: ''. This is why we need to track the local state and update all of the params at the\n * same time.\n */\nconst name = ref<string>(data.name ?? '')\nconst value = ref<string | File>(unpackProxyObject(data.value) ?? '')\nconst isDisabled = ref<boolean>(data.isDisabled ?? false)\n\n// Keep the above state synced with the data prop\nwatch(\n () => data.name,\n (newName) => {\n // Do not overwrite a valid local name with an empty incoming prop — this\n // can happen when the placeholder row (appended by displayData) is briefly\n // mapped onto this component instance before Vue re-keys the list.\n if (!newName && name.value && !deferKeyUpdates) {\n return\n }\n name.value = newName ?? ''\n },\n)\nwatch(\n () => data.value,\n (newValue) => (value.value = unpackProxyObject(newValue) ?? ''),\n)\nwatch(\n () => data.isDisabled,\n (newIsDisabled) => (isDisabled.value = newIsDisabled ?? false),\n)\n\n/** Check if the value is a File instance */\nconst isFile = computed(() => value.value instanceof File)\n\n/** Display value handles File instances and shows filename instead */\nconst displayValue = computed(\n () =>\n (isFile.value\n ? getFileName(value.value as File)\n : (value.value as string)) ?? '',\n)\n\nconst defaultValue = computed(() => data.schema?.default as string)\n\n/** See if we can extract enum values from the schema */\nconst enumValue = computed<unknown[]>(() => {\n if (!data.schema) {\n return []\n }\n\n // Grab the enum from the schema\n if (data.schema.enum) {\n return data.schema.enum.map((item) => String(item))\n }\n\n // Grab the enum from the items schema\n if ('items' in data.schema) {\n const resolved = resolve.schema(data.schema.items)\n if (resolved?.enum) {\n return data.arrayEncoding === 'json'\n ? resolved.enum\n : resolved.enum.map((item) => String(item))\n }\n }\n\n return []\n})\n\nconst typeValue = computed(() =>\n data.schema && 'type' in data.schema ? data.schema.type : undefined,\n)\n\nconst validationResult = computed(() =>\n validateParameter(data.schema, value.value),\n)\n\n/** Handle row updates while preserving existing properties */\nconst handleUpdateRow = (\n payload: Partial<{ name: string; value: string; isDisabled: boolean }>,\n options: { shouldRenameExpandedRow?: boolean; commitKey?: boolean } = {},\n): void => {\n // Update our local state\n if (payload.name !== undefined) {\n name.value = payload.name\n }\n if (payload.value !== undefined) {\n value.value = payload.value\n\n // Optional parameters start unchecked, but entering a value expresses intent to send it.\n // Explicit x-disabled values stay unchanged so a deliberate opt-out is preserved.\n if (data.isDisabledByDefault) {\n isDisabled.value = false\n }\n }\n\n // Is disabled should only be updated when explicitly provided in the payload\n if (payload.isDisabled !== undefined) {\n isDisabled.value = payload.isDisabled\n }\n\n if (\n payload.name !== undefined &&\n (deferKeyUpdates || data.sourceParameterValuePath) &&\n !options.shouldRenameExpandedRow &&\n !options.commitKey\n ) {\n return\n }\n\n // Emit all of the local state\n emit('upsertRow', {\n name: name.value,\n value: value.value,\n isDisabled: isDisabled.value,\n ...(options.shouldRenameExpandedRow\n ? { shouldRenameExpandedRow: true }\n : {}),\n })\n}\n\n/**\n * Commit a key edit when the input loses focus. Body and expanded-object rows defer their rename to blur (see\n * handleUpdateRow), so we only emit when the key actually changed. Focusing and blurring the field\n * without typing should not re-emit the row or silently reset its disabled state. The current\n * disabled state is passed through so a renamed row keeps it.\n */\nconst handleKeyBlur = (newName: string): void => {\n if (newName === data.name) {\n return\n }\n // Do not emit an update that would blank the parameter name — this can fire\n // when CodeInputLite blurs before it has rendered its initial value.\n if (!newName && data.name && (!deferKeyUpdates || name.value !== '')) {\n return\n }\n\n handleUpdateRow(\n { name: newName, isDisabled: isDisabled.value },\n {\n shouldRenameExpandedRow: Boolean(data.sourceParameterValuePath),\n commitKey: true,\n },\n )\n}\n\n/** Save a pending body key before the send shortcut reaches the request handler. */\nconst handleKeydown = (event: KeyboardEvent): void => {\n if (\n deferKeyUpdates &&\n event.key === 'Enter' &&\n (event.metaKey || event.ctrlKey)\n ) {\n handleKeyBlur(name.value)\n }\n}\n</script>\n\n<template>\n <DataTableRow\n :id=\"data.name\"\n :class=\"{\n alert: validationResult.ok === false,\n error: validationResult.ok === false && invalidParams?.has(data.name),\n }\">\n <DataTableCheckbox\n :ariaLabel=\"\n translate('apiClient.requestTableRow.include', {\n name: data.name || translate('apiClient.requestTableRow.row'),\n })\n \"\n class=\"!border-r\"\n :disabled=\"hasCheckboxDisabled ?? false\"\n :modelValue=\"!isDisabled\"\n @update:modelValue=\"(v) => handleUpdateRow({ isDisabled: !v })\" />\n\n <!-- Name -->\n <DataTableCell>\n <CodeInputLite\n :aria-label=\"\n translate('apiClient.requestTableRow.keyLabel', { name: label ?? '' })\n \"\n :disabled=\"data.isReadonly\"\n :environment=\"environment\"\n :modelValue=\"name\"\n :placeholder=\"translate('apiClient.requestTableRow.key')\"\n :required=\"Boolean(data.isRequired)\"\n @blur=\"(v) => handleKeyBlur(v)\"\n @keydown.capture=\"handleKeydown\"\n @navigate=\"(route) => emit('navigate', route)\"\n @update:modelValue=\"(v) => handleUpdateRow({ name: v })\" />\n </DataTableCell>\n\n <!-- Value -->\n <DataTableCell>\n <!-- Preset switcher for grouped global cookies that share a name -->\n <DataTableInputSelect\n v-if=\"data.presetOptions?.length\"\n :canAddCustomValue=\"false\"\n :modelValue=\"displayValue\"\n :value=\"data.presetOptions\"\n @update:modelValue=\"(v) => emit('selectPreset', v)\" />\n <CodeInputLite\n v-else\n ref=\"valueInput\"\n :aria-label=\"\n translate('apiClient.requestTableRow.valueLabel', {\n name: label ?? '',\n })\n \"\n :arrayEncoding=\"data.arrayEncoding\"\n class=\"pr-6 group-hover:pr-10 group-has-[.code-input-lite__editor:focus]:pr-10\"\n :default=\"defaultValue\"\n :disabled=\"data.isReadonly\"\n :enum=\"enumValue\"\n :environment=\"environment\"\n :examples=\"\n data.schema?.examples?.map((example) => String(example)) ?? []\n \"\n :linethrough=\"data.isOverridden\"\n :modelValue=\"displayValue\"\n :placeholder=\"translate('apiClient.requestTableRow.value')\"\n :type=\"typeValue\"\n withFakeData\n @navigate=\"(route) => emit('navigate', route)\"\n @update:modelValue=\"(v) => handleUpdateRow({ value: v })\">\n <template #icon>\n <ScalarButton\n v-if=\"\n Boolean(data.name || value) &&\n !data.isRequired &&\n data.isReadonly !== true\n \"\n :aria-label=\"\n translate('apiClient.requestTableRow.deleteRow', {\n name: data.name || translate('apiClient.requestTableRow.row'),\n })\n \"\n class=\"text-c-2 hover:text-c-1 hover:bg-b-2 z-context -mr-0.5 hidden h-fit rounded p-1 group-hover:flex group-has-[.code-input-lite__editor:focus]:flex\"\n size=\"sm\"\n variant=\"ghost\"\n @click=\"emit('deleteRow')\">\n <ScalarIconTrash class=\"size-3.5\" />\n </ScalarButton>\n\n <ScalarIconButton\n v-if=\"data.globalRoute !== undefined\"\n class=\"text-c-2 hover:text-c-1 hover:bg-b-2 z-context -mr-0.5 h-fit\"\n :icon=\"ScalarIconGlobe\"\n :label=\"translate('apiClient.requestTableRow.globalCookieHint')\"\n size=\"xs\"\n tooltip=\"top\"\n variant=\"ghost\"\n @click=\"emit('navigate', data.globalRoute)\" />\n\n <RequestTableTooltip\n v-if=\"data.isReadonly\"\n :description=\"translate('apiClient.requestTableRow.readOnlyHint')\"\n :value=\"null\" />\n <RequestTableTooltip\n v-else-if=\"data.schema\"\n :description=\"data.description\"\n :schema=\"data.schema\"\n :value />\n </template>\n </CodeInputLite>\n </DataTableCell>\n\n <!-- File upload -->\n <DataTableCell\n v-if=\"showUploadButton\"\n class=\"group/upload flex items-center justify-center whitespace-nowrap\">\n <template v-if=\"isFile\">\n <div\n class=\"text-c-2 flex w-full max-w-[100%] items-center justify-center overflow-hidden p-1\">\n <span\n class=\"truncate\"\n :title=\"displayValue\"\n >{{ displayValue }}</span\n >\n </div>\n <button\n class=\"bg-b-2 mt-1 block rounded p-0.5 text-center text-xs font-medium md:pointer-events-none md:absolute md:inset-x-1 md:top-1/2 md:mt-0 md:-translate-y-1/2 md:opacity-0 md:group-hover/upload:pointer-events-auto md:group-hover/upload:opacity-100\"\n type=\"button\"\n @click=\"emit('removeFile')\">\n {{ translate('apiClient.requestTableRow.delete') }}\n </button>\n </template>\n <template v-else>\n <div class=\"p-0.5\">\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 h-fit border-0 py-px shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"emit('uploadFile')\">\n <span>{{ translate('apiClient.requestTableRow.selectFile') }}</span>\n <ScalarIcon\n class=\"ml-1\"\n icon=\"Upload\"\n size=\"xs\"\n thickness=\"2.5\" />\n </ScalarButton>\n </div>\n </template>\n </DataTableCell>\n </DataTableRow>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA8CA,MAAM,OAAO;EAUb,MAAM,EAAE,cAAc,gBAAgB;EAEtC,MAAM,aAAa,eAAe,YAAY;EAC9C,SAAa,EAAE,kBAAwB,WAAW,OAAO,MAAM,EAAE,CAAC;EAyDlE,MAAM,OAAO,IAAY,QAAA,KAAK,QAAQ,EAAE;EACxC,MAAM,QAAQ,IAAmB,kBAAkB,QAAA,KAAK,KAAK,KAAK,EAAE;EACpE,MAAM,aAAa,IAAa,QAAA,KAAK,cAAc,KAAK;EAGxD,YACQ,QAAA,KAAK,OACV,YAAY;GAIX,IAAI,CAAC,WAAW,KAAK,SAAS,CAAC,QAAA,iBAC7B;GAEF,KAAK,QAAQ,WAAW;EAC1B,CACF;EACA,YACQ,QAAA,KAAK,QACV,aAAc,MAAM,QAAQ,kBAAkB,QAAQ,KAAK,EAC9D;EACA,YACQ,QAAA,KAAK,aACV,kBAAmB,WAAW,QAAQ,iBAAiB,KAC1D;;EAGA,MAAM,SAAS,eAAe,MAAM,iBAAiB,IAAI;;EA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,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,KAAI,YAAA;MACT,GAAAC,gBAAAd,MAAA,SAAA,CAAS,CAAA,kCAAA,CAAA,GAAA,CAAA,C,WAIdF,UAAA,GAAAa,mBAaM,OAbN,YAaM,CAZJP,YAWeJ,MAAA,YAAA,GAAA;OAVb,OAAM;OACN,MAAK;OACL,SAAQ;OACP,SAAK,OAAA,QAAA,OAAA,OAAA,WAAE,KAAI,YAAA;;OACZ,SAAAG,cAAoE,CAApEU,mBAAoE,QAAA,MAAAC,gBAA3Dd,MAAA,SAAA,CAAS,CAAA,sCAAA,CAAA,GAAA,CAAA,GAClBI,YAIoBJ,MAAA,UAAA,GAAA;QAHlB,OAAM;QACN,MAAK;QACL,MAAK;QACL,WAAU"}
|
|
1
|
+
{"version":3,"file":"RequestTableRow.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","DataTableRow","_normalizeClass","_withCtx","_createVNode","DataTableCheckbox","DataTableCell","CodeInputLite","DataTableInputSelect","_createCommentVNode","RequestTableTooltip","_createElementBlock","_Fragment","_createElementVNode","_toDisplayString"],"sources":["../../../../../src/v2/blocks/request-block/components/RequestTableRow.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 { ScalarIconGlobe, ScalarIconTrash } from '@scalar/icons'\nimport type { ApiReferenceEvents } from '@scalar/workspace-store/events'\nimport { isFileSchema } from '@scalar/workspace-store/helpers/is-file-schema'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\nimport type {\n ParameterObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { computed, ref, useTemplateRef, watch } from 'vue'\n\nimport { getFileName } from '@/v2/blocks/request-block/helpers/files'\nimport { validateParameter } from '@/v2/blocks/request-block/helpers/validate-parameter'\nimport { CodeInputLite } from '@/v2/components/code-input'\nimport {\n DataTableCell,\n DataTableCheckbox,\n DataTableInputSelect,\n DataTableRow,\n} from '@/v2/components/data-table'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport RequestTableTooltip from './RequestTableTooltip.vue'\n\nconst {\n data,\n environment,\n hasCheckboxDisabled,\n deferKeyUpdates,\n invalidParams,\n showUploadButton,\n allowUnknownFileUploads = true,\n} = defineProps<{\n data: TableRow\n /** Keep key edits local until blur when the row identity depends on its name. */\n deferKeyUpdates?: boolean\n hasCheckboxDisabled?: boolean\n invalidParams?: Set<string>\n label?: string\n environment: XScalarEnvironment\n showUploadButton?: boolean\n /** Unknown fields remain editable as files only in free-form multipart requests. */\n allowUnknownFileUploads?: boolean\n}>()\n\nconst emit = defineEmits<{\n (e: 'upsertRow', payload: TableRowUpsertPayload): void\n (e: 'deleteRow'): void\n (e: 'uploadFile'): void\n (e: 'removeFile'): void\n (e: 'navigate', route: NonNullable<TableRow['globalRoute']>): void\n /** Select a value for a grouped global cookie preset. */\n (e: 'selectPreset', value: string): void\n}>()\n\nconst { translate } = useLocalization()\n\nconst valueInput = useTemplateRef('valueInput')\ndefineExpose({ focusValue: (): void => valueInput.value?.focus() })\n\nexport type TableRow = {\n /** The parameter or field name/key */\n name: string\n /** The parameter value, can be a string, file, or null */\n value: string | File | null\n /** Optional description for the parameter */\n description?: string\n /** Optional route for global parameters (e.g., cookies shared across workspace) */\n globalRoute?: ApiReferenceEvents['ui:navigate']\n /** Whether the parameter is disabled/inactive */\n isDisabled?: boolean\n /** Whether an optional parameter is disabled because it has no explicit x-disabled value */\n isDisabledByDefault?: boolean\n /** OpenAPI schema object with type, validation rules, examples, etc. */\n schema?: SchemaObject\n /** Explicit media type for this multipart field. */\n contentType?: string\n /** Preserve array values even while their JSON text is temporarily invalid. */\n isArray?: boolean\n /** Text representation used by array enum controls. */\n arrayEncoding?: 'json' | 'comma-separated'\n /** Whether the parameter is required */\n isRequired?: boolean\n /**\n * Whether the parameter is readonly and can not be modifies directly\n * User can still override the parameter which is going to show up with the linethrough style\n */\n isReadonly?: boolean\n /** Whether the parameter is overridden later on */\n isOverridden?: boolean\n /** Track the original parameter so we can update it */\n originalParameter?: ParameterObject\n /** Path to a value inside the original parameter example for expanded object parameters */\n sourceParameterValuePath?: string[]\n /**\n * Selectable values for a grouped global cookie preset. When set, the value cell renders a\n * dropdown to switch between predefined values (for example a `Culture` cookie with `PL`/`EN`)\n * instead of an editable input.\n */\n presetOptions?: string[]\n}\n\nexport type TableRowUpsertPayload = {\n name: string\n value: string | File\n isDisabled: boolean\n shouldRenameExpandedRow?: boolean\n}\n\n/**\n * Track local state for the row\n *\n * Now this is required because of the way we get default values from the schema.\n * If we have a default value in data.value, then we update isDisabled to true. We lose the default value since now\n * we have an example where value: ''. This is why we need to track the local state and update all of the params at the\n * same time.\n */\nconst name = ref<string>(data.name ?? '')\nconst value = ref<string | File>(unpackProxyObject(data.value) ?? '')\nconst isDisabled = ref<boolean>(data.isDisabled ?? false)\n\n// Keep the above state synced with the data prop\nwatch(\n () => data.name,\n (newName) => {\n // Do not overwrite a valid local name with an empty incoming prop — this\n // can happen when the placeholder row (appended by displayData) is briefly\n // mapped onto this component instance before Vue re-keys the list.\n if (!newName && name.value && !deferKeyUpdates) {\n return\n }\n name.value = newName ?? ''\n },\n)\nwatch(\n () => data.value,\n (newValue) => (value.value = unpackProxyObject(newValue) ?? ''),\n)\nwatch(\n () => data.isDisabled,\n (newIsDisabled) => (isDisabled.value = newIsDisabled ?? false),\n)\n\n/** Check if the value is a File instance */\nconst isFile = computed(() => value.value instanceof File)\n\n/** Whether this row’s schema accepts a file part. */\nconst canUploadFile = computed<boolean>(() =>\n data.schema\n ? isFileSchema(data.schema, true, data.contentType)\n : allowUnknownFileUploads,\n)\n\n/** Display value handles File instances and shows filename instead */\nconst displayValue = computed(\n () =>\n (isFile.value\n ? getFileName(value.value as File)\n : (value.value as string)) ?? '',\n)\n\nconst defaultValue = computed(() => data.schema?.default as string)\n\n/** See if we can extract enum values from the schema */\nconst enumValue = computed<unknown[]>(() => {\n if (!data.schema) {\n return []\n }\n\n // Grab the enum from the schema\n if (data.schema.enum) {\n return data.schema.enum.map((item) => String(item))\n }\n\n // Grab the enum from the items schema\n if ('items' in data.schema) {\n const resolved = resolve.schema(data.schema.items)\n if (resolved?.enum) {\n return data.arrayEncoding === 'json'\n ? resolved.enum\n : resolved.enum.map((item) => String(item))\n }\n }\n\n return []\n})\n\nconst typeValue = computed(() =>\n data.schema && 'type' in data.schema ? data.schema.type : undefined,\n)\n\nconst validationResult = computed(() =>\n validateParameter(data.schema, value.value),\n)\n\n/** Handle row updates while preserving existing properties */\nconst handleUpdateRow = (\n payload: Partial<{ name: string; value: string; isDisabled: boolean }>,\n options: { shouldRenameExpandedRow?: boolean; commitKey?: boolean } = {},\n): void => {\n // Update our local state\n if (payload.name !== undefined) {\n name.value = payload.name\n }\n if (payload.value !== undefined) {\n value.value = payload.value\n\n // Optional parameters start unchecked, but entering a value expresses intent to send it.\n // Explicit x-disabled values stay unchanged so a deliberate opt-out is preserved.\n if (data.isDisabledByDefault) {\n isDisabled.value = false\n }\n }\n\n // Is disabled should only be updated when explicitly provided in the payload\n if (payload.isDisabled !== undefined) {\n isDisabled.value = payload.isDisabled\n }\n\n if (\n payload.name !== undefined &&\n (deferKeyUpdates || data.sourceParameterValuePath) &&\n !options.shouldRenameExpandedRow &&\n !options.commitKey\n ) {\n return\n }\n\n // Emit all of the local state\n emit('upsertRow', {\n name: name.value,\n value: value.value,\n isDisabled: isDisabled.value,\n ...(options.shouldRenameExpandedRow\n ? { shouldRenameExpandedRow: true }\n : {}),\n })\n}\n\n/**\n * Commit a key edit when the input loses focus. Body and expanded-object rows defer their rename to blur (see\n * handleUpdateRow), so we only emit when the key actually changed. Focusing and blurring the field\n * without typing should not re-emit the row or silently reset its disabled state. The current\n * disabled state is passed through so a renamed row keeps it.\n */\nconst handleKeyBlur = (newName: string): void => {\n if (newName === data.name) {\n return\n }\n // Do not emit an update that would blank the parameter name — this can fire\n // when CodeInputLite blurs before it has rendered its initial value.\n if (!newName && data.name && (!deferKeyUpdates || name.value !== '')) {\n return\n }\n\n handleUpdateRow(\n { name: newName, isDisabled: isDisabled.value },\n {\n shouldRenameExpandedRow: Boolean(data.sourceParameterValuePath),\n commitKey: true,\n },\n )\n}\n\n/** Save a pending body key before the send shortcut reaches the request handler. */\nconst handleKeydown = (event: KeyboardEvent): void => {\n if (\n deferKeyUpdates &&\n event.key === 'Enter' &&\n (event.metaKey || event.ctrlKey)\n ) {\n handleKeyBlur(name.value)\n }\n}\n</script>\n\n<template>\n <DataTableRow\n :id=\"data.name\"\n :class=\"{\n alert: validationResult.ok === false,\n error: validationResult.ok === false && invalidParams?.has(data.name),\n }\">\n <DataTableCheckbox\n :ariaLabel=\"\n translate('apiClient.requestTableRow.include', {\n name: data.name || translate('apiClient.requestTableRow.row'),\n })\n \"\n class=\"!border-r\"\n :disabled=\"hasCheckboxDisabled ?? false\"\n :modelValue=\"!isDisabled\"\n @update:modelValue=\"(v) => handleUpdateRow({ isDisabled: !v })\" />\n\n <!-- Name -->\n <DataTableCell>\n <CodeInputLite\n :aria-label=\"\n translate('apiClient.requestTableRow.keyLabel', { name: label ?? '' })\n \"\n :disabled=\"data.isReadonly\"\n :environment=\"environment\"\n :modelValue=\"name\"\n :placeholder=\"translate('apiClient.requestTableRow.key')\"\n :required=\"Boolean(data.isRequired)\"\n @blur=\"(v) => handleKeyBlur(v)\"\n @keydown.capture=\"handleKeydown\"\n @navigate=\"(route) => emit('navigate', route)\"\n @update:modelValue=\"(v) => handleUpdateRow({ name: v })\" />\n </DataTableCell>\n\n <!-- Value -->\n <DataTableCell>\n <!-- Preset switcher for grouped global cookies that share a name -->\n <DataTableInputSelect\n v-if=\"data.presetOptions?.length\"\n :canAddCustomValue=\"false\"\n :modelValue=\"displayValue\"\n :value=\"data.presetOptions\"\n @update:modelValue=\"(v) => emit('selectPreset', v)\" />\n <CodeInputLite\n v-else\n ref=\"valueInput\"\n :aria-label=\"\n translate('apiClient.requestTableRow.valueLabel', {\n name: label ?? '',\n })\n \"\n :arrayEncoding=\"data.arrayEncoding\"\n class=\"pr-6 group-hover:pr-10 group-has-[.code-input-lite__editor:focus]:pr-10\"\n :default=\"defaultValue\"\n :disabled=\"data.isReadonly\"\n :enum=\"enumValue\"\n :environment=\"environment\"\n :examples=\"\n data.schema?.examples?.map((example) => String(example)) ?? []\n \"\n :linethrough=\"data.isOverridden\"\n :modelValue=\"displayValue\"\n :placeholder=\"translate('apiClient.requestTableRow.value')\"\n :type=\"typeValue\"\n withFakeData\n @navigate=\"(route) => emit('navigate', route)\"\n @update:modelValue=\"(v) => handleUpdateRow({ value: v })\">\n <template #icon>\n <ScalarButton\n v-if=\"\n Boolean(data.name || value) &&\n !data.isRequired &&\n data.isReadonly !== true\n \"\n :aria-label=\"\n translate('apiClient.requestTableRow.deleteRow', {\n name: data.name || translate('apiClient.requestTableRow.row'),\n })\n \"\n class=\"text-c-2 hover:text-c-1 hover:bg-b-2 z-context -mr-0.5 hidden h-fit rounded p-1 group-hover:flex group-has-[.code-input-lite__editor:focus]:flex\"\n size=\"sm\"\n variant=\"ghost\"\n @click=\"emit('deleteRow')\">\n <ScalarIconTrash class=\"size-3.5\" />\n </ScalarButton>\n\n <ScalarIconButton\n v-if=\"data.globalRoute !== undefined\"\n class=\"text-c-2 hover:text-c-1 hover:bg-b-2 z-context -mr-0.5 h-fit\"\n :icon=\"ScalarIconGlobe\"\n :label=\"translate('apiClient.requestTableRow.globalCookieHint')\"\n size=\"xs\"\n tooltip=\"top\"\n variant=\"ghost\"\n @click=\"emit('navigate', data.globalRoute)\" />\n\n <RequestTableTooltip\n v-if=\"data.isReadonly\"\n :description=\"translate('apiClient.requestTableRow.readOnlyHint')\"\n :value=\"null\" />\n <RequestTableTooltip\n v-else-if=\"data.schema\"\n :description=\"data.description\"\n :schema=\"data.schema\"\n :value />\n </template>\n </CodeInputLite>\n </DataTableCell>\n\n <!-- File upload -->\n <DataTableCell\n v-if=\"showUploadButton\"\n class=\"group/upload flex items-center justify-center whitespace-nowrap\">\n <template v-if=\"isFile\">\n <div\n class=\"text-c-2 flex w-full max-w-[100%] items-center justify-center overflow-hidden p-1\">\n <span\n class=\"truncate\"\n :title=\"displayValue\"\n >{{ displayValue }}</span\n >\n </div>\n <button\n class=\"bg-b-2 mt-1 block rounded p-0.5 text-center text-xs font-medium md:pointer-events-none md:absolute md:inset-x-1 md:top-1/2 md:mt-0 md:-translate-y-1/2 md:opacity-0 md:group-hover/upload:pointer-events-auto md:group-hover/upload:opacity-100\"\n type=\"button\"\n @click=\"emit('removeFile')\">\n {{ translate('apiClient.requestTableRow.delete') }}\n </button>\n </template>\n <template v-else-if=\"canUploadFile\">\n <div class=\"p-0.5\">\n <ScalarButton\n class=\"bg-b-2 hover:bg-b-3 text-c-2 h-fit border-0 py-px shadow-none\"\n size=\"sm\"\n variant=\"outlined\"\n @click=\"emit('uploadFile')\">\n <span>{{ translate('apiClient.requestTableRow.selectFile') }}</span>\n <ScalarIcon\n class=\"ml-1\"\n icon=\"Upload\"\n size=\"xs\"\n thickness=\"2.5\" />\n </ScalarButton>\n </div>\n </template>\n </DataTableCell>\n </DataTableRow>\n</template>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkDA,MAAM,OAAO;EAUb,MAAM,EAAE,cAAc,gBAAgB;EAEtC,MAAM,aAAa,eAAe,YAAY;EAC9C,SAAa,EAAE,kBAAwB,WAAW,OAAO,MAAM,EAAE,CAAC;EA2DlE,MAAM,OAAO,IAAY,QAAA,KAAK,QAAQ,EAAE;EACxC,MAAM,QAAQ,IAAmB,kBAAkB,QAAA,KAAK,KAAK,KAAK,EAAE;EACpE,MAAM,aAAa,IAAa,QAAA,KAAK,cAAc,KAAK;E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AAa,QAAA,KAAK;SAClB,QAAQ,QAAA,KAAK;SACb,OAAA,MAAA;;;;;;;;;;;;;;;;;;;;;;;KAOD,QAAA,oBADRZ,UAAA,GAAAC,YAmCgBC,MAAAM,qBAAA,GAAA;;MAjCd,OAAM;;MACN,SAAAH,cAeW,CAfK,OAAA,SAAhBL,UAAA,GAAAa,mBAeWC,UAAA,EAAA,KAAA,EAAA,GAAA,CAdTC,mBAOM,OAPN,YAOM,CALJA,mBAIC,QAAA;OAHC,OAAM;OACL,OAAO,aAAA;MACJ,GAAAC,gBAAA,aAAA,KAAY,GAAA,GAAA,UAAA,C,IAGpBD,mBAKS,UAAA;OAJP,OAAM;OACN,MAAK;OACJ,SAAK,OAAA,OAAA,OAAA,MAAA,WAAE,KAAI,YAAA;MACT,GAAAC,gBAAAd,MAAA,SAAA,CAAS,CAAA,kCAAA,CAAA,GAAA,CAAA,C,UAGK,cAAA,SACnBF,UAAA,GAAAa,mBAaM,OAbN,YAaM,CAZJP,YAWeJ,MAAA,YAAA,GAAA;OAVb,OAAM;OACN,MAAK;OACL,SAAQ;OACP,SAAK,OAAA,QAAA,OAAA,OAAA,WAAE,KAAI,YAAA;;OACZ,SAAAG,cAAoE,CAApEU,mBAAoE,QAAA,MAAAC,gBAA3Dd,MAAA,SAAA,CAAS,CAAA,sCAAA,CAAA,GAAA,CAAA,GAClBI,YAIoBJ,MAAA,UAAA,GAAA;QAHlB,OAAM;QACN,MAAK;QACL,MAAK;QACL,WAAU"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ExampleObject, SchemaObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
1
|
+
import type { ExampleObject, MediaTypeObject, SchemaObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
2
2
|
import type { TableRow } from '../components/RequestTableRow.vue.js';
|
|
3
3
|
export declare const stringifyValue: (value: unknown) => string;
|
|
4
4
|
export type LeafRow = {
|
|
@@ -32,5 +32,5 @@ export declare const collectExampleRows: (example: unknown, schema: SchemaObject
|
|
|
32
32
|
/** Restore array values after text editing without parsing ordinary string fields. */
|
|
33
33
|
export declare const getFormBodyValue: (row: TableRow) => string | File | unknown[] | undefined;
|
|
34
34
|
/** Build the table rows for the form data, optionally enriched with schema (e.g. enum) per property */
|
|
35
|
-
export declare const getFormBodyRows: (example: ExampleObject | undefined | null, contentType: string, formBodySchema?: SchemaObject, compositionSelection?: Record<string, number
|
|
35
|
+
export declare const getFormBodyRows: (example: ExampleObject | undefined | null, contentType: string, formBodySchema?: SchemaObject, compositionSelection?: Record<string, number>, encoding?: MediaTypeObject["encoding"]) => TableRow[];
|
|
36
36
|
//# sourceMappingURL=get-form-body-rows.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-form-body-rows.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/request-block/helpers/get-form-body-rows.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"get-form-body-rows.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/request-block/helpers/get-form-body-rows.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EACf,YAAY,EACb,MAAM,8DAA8D,CAAA;AAGrE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0DAA0D,CAAA;AAExF,eAAO,MAAM,cAAc,GAAI,OAAO,OAAO,WAQ5C,CAAA;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,MAAM,EAAE,YAAY,GAAG,SAAS,CAAA;IAChC,UAAU,EAAE,OAAO,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,GAChC,QAAQ,YAAY,EACpB,aAAY,MAAM,EAAO,EACzB,wBAAqB,EACrB,oBAAoB,MAAM,KACzB,OAAO,EA6BT,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAC7B,SAAS,OAAO,EAChB,QAAQ,YAAY,GAAG,SAAS,EAChC,aAAY,MAAM,EAAO,KACxB;IAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,EAqCpC,CAAA;AAED,sFAAsF;AACtF,eAAO,MAAM,gBAAgB,GAAI,KAAK,QAAQ,KAAG,MAAM,GAAG,IAAI,GAAG,OAAO,EAAE,GAAG,SAG5E,CAAA;AAED,uGAAuG;AACvG,eAAO,MAAM,eAAe,GAC1B,SAAS,aAAa,GAAG,SAAS,GAAG,IAAI,EACzC,aAAa,MAAM,EACnB,iBAAiB,YAAY,EAC7B,uBAAuB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC7C,WAAW,eAAe,CAAC,UAAU,CAAC,KACrC,QAAQ,EA8JV,CAAA"}
|
|
@@ -79,11 +79,14 @@ var getFormBodyValue = (row) => {
|
|
|
79
79
|
return Array.isArray(value) ? value : row.value ?? void 0;
|
|
80
80
|
};
|
|
81
81
|
/** Build the table rows for the form data, optionally enriched with schema (e.g. enum) per property */
|
|
82
|
-
var getFormBodyRows = (example, contentType, formBodySchema, compositionSelection) => {
|
|
82
|
+
var getFormBodyRows = (example, contentType, formBodySchema, compositionSelection, encoding) => {
|
|
83
83
|
const value = example?.dataValue !== void 0 ? example.dataValue : example?.value;
|
|
84
84
|
if (!value || contentType !== "multipart/form-data" && contentType !== "application/x-www-form-urlencoded") return [];
|
|
85
85
|
const resolvedBodySchema = resolveFormSchema(formBodySchema, compositionSelection);
|
|
86
|
-
const schemaWithProperties = resolvedBodySchema && isObjectSchema(resolvedBodySchema)
|
|
86
|
+
const schemaWithProperties = resolvedBodySchema && (isObjectSchema(resolvedBodySchema) || "properties" in resolvedBodySchema || "additionalProperties" in resolvedBodySchema) ? {
|
|
87
|
+
...resolvedBodySchema,
|
|
88
|
+
type: "object"
|
|
89
|
+
} : void 0;
|
|
87
90
|
const isComposed = Boolean(schemaWithProperties?.allOf || schemaWithProperties?.oneOf || schemaWithProperties?.anyOf);
|
|
88
91
|
const requiredSet = schemaWithProperties ? new Set(schemaWithProperties.required ?? []) : void 0;
|
|
89
92
|
const leafByDottedName = /* @__PURE__ */ new Map();
|
|
@@ -92,11 +95,12 @@ var getFormBodyRows = (example, contentType, formBodySchema, compositionSelectio
|
|
|
92
95
|
const row = {
|
|
93
96
|
name,
|
|
94
97
|
value,
|
|
95
|
-
isDisabled: isDisabled ?? false
|
|
98
|
+
isDisabled: isDisabled ?? false,
|
|
99
|
+
...encoding?.[name]?.contentType ? { contentType: encoding[name].contentType } : {}
|
|
96
100
|
};
|
|
97
101
|
if (!schemaWithProperties || !name) return row;
|
|
98
102
|
const leaf = leafByDottedName.get(name);
|
|
99
|
-
const propSchema = leaf?.schema ?? resolveSchemaWithAnnotations(schemaWithProperties.properties?.[name]);
|
|
103
|
+
const propSchema = leaf?.schema ?? resolveSchemaWithAnnotations(schemaWithProperties.properties?.[name] ?? (typeof schemaWithProperties.additionalProperties === "object" ? schemaWithProperties.additionalProperties : schemaWithProperties.additionalProperties === false ? void 0 : { __scalar_: "" }));
|
|
100
104
|
row.schema = propSchema;
|
|
101
105
|
row.description = leaf?.description ?? propSchema?.description;
|
|
102
106
|
row.isRequired = leaf?.isRequired ?? requiredSet?.has(name) ?? false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-form-body-rows.js","names":[],"sources":["../../../../../src/v2/blocks/request-block/helpers/get-form-body-rows.ts"],"sourcesContent":["import { isObject } from '@scalar/helpers/object/is-object'\nimport { objectEntries } from '@scalar/helpers/object/object-entries'\nimport { resolveFormSchema } from '@scalar/workspace-store/helpers/resolve-form-schema'\nimport { resolveSchemaWithAnnotations } from '@scalar/workspace-store/helpers/resolve-schema-with-annotations'\nimport { coerceLeafValueToSchemaType } from '@scalar/workspace-store/request-example'\nimport type { ExampleObject, SchemaObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { isObjectSchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\n\nimport type { TableRow } from '@/v2/blocks/request-block/components/RequestTableRow.vue'\n\nexport const stringifyValue = (value: unknown) => {\n if (value instanceof File) {\n return value.name\n }\n if (typeof value === 'object' && value !== null) {\n return JSON.stringify(value)\n }\n return String(value)\n}\n\nexport type LeafRow = {\n path: string[]\n schema: SchemaObject | undefined\n isRequired: boolean\n description?: string\n}\n\n/**\n * Walk a (possibly nested) object schema and collect one entry per leaf property.\n *\n * A \"leaf\" is any property whose resolved schema is not an `{ type: 'object' }` schema\n * with named `properties` — i.e. primitives, arrays, files, and `additionalProperties`\n * placeholders all stop the recursion. Object properties recurse, so the widget example\n * (`file` + `props.{name,description,created_at}`) yields four leaves.\n */\nexport const collectLeafProperties = (\n schema: SchemaObject,\n parentPath: string[] = [],\n parentRequired = true,\n parentDescription?: string,\n): LeafRow[] => {\n // Nothing to walk if this is not an object schema or has no declared properties.\n if (!isObjectSchema(schema) || !schema.properties) {\n return []\n }\n\n // `required` is a list of property names on *this* schema, so build it once per level.\n const requiredSet = new Set(schema.required ?? [])\n const leaves: LeafRow[] = []\n\n for (const [key, rawChildSchema] of objectEntries(schema.properties)) {\n const childSchema = resolveSchemaWithAnnotations(rawChildSchema)\n const path = [...parentPath, String(key)]\n\n // A leaf is only required when *every* ancestor was also required — a non-required\n // parent makes the whole subtree optional regardless of inner `required` lists.\n const isRequired = parentRequired && requiredSet.has(String(key))\n\n // Nested objects with named properties recurse so each leaf gets its own row;\n // everything else (primitives, arrays, files, additionalProperties placeholders)\n // is treated as a leaf and stops the descent.\n if (childSchema && isObjectSchema(childSchema) && childSchema.properties) {\n leaves.push(...collectLeafProperties(childSchema, path, isRequired, childSchema.description ?? parentDescription))\n } else {\n leaves.push({ path, schema: childSchema, isRequired, description: childSchema?.description ?? parentDescription })\n }\n }\n\n return leaves\n}\n\n/**\n * Walk a schema + example together and collect one row per leaf, including example-only\n * keys that the schema does not declare. Schema-declared properties come first in schema\n * order; extras present in the example follow in example order at each level.\n *\n * Unlike `collectLeafProperties` (which is schema-only and feeds the dotted-name index),\n * this walker drives what the user actually sees in the form: a row for every leaf the\n * example contains, even when the schema is partial or out of date.\n */\nexport const collectExampleRows = (\n example: unknown,\n schema: SchemaObject | undefined,\n parentPath: string[] = [],\n): { path: string[]; value: unknown }[] => {\n const rows: { path: string[]; value: unknown }[] = []\n const exampleEntries = isObject(example) ? objectEntries(example) : []\n const exampleByKey = new Map<string, unknown>(exampleEntries.map(([key, value]) => [String(key), value]))\n const declaredKeys = new Set<string>()\n const schemaProperties = schema && isObjectSchema(schema) ? (schema.properties ?? {}) : {}\n\n // Schema-declared properties first, in schema order. Nested object schemas recurse so\n // each leaf gets its own row; otherwise the schema-declared key is a leaf and uses the\n // matching example value (or `undefined` when the example does not provide one).\n for (const [key, rawChildSchema] of objectEntries(schemaProperties)) {\n const keyStr = String(key)\n declaredKeys.add(keyStr)\n const childSchema = resolveSchemaWithAnnotations(rawChildSchema)\n const path = [...parentPath, keyStr]\n const exampleSubvalue = exampleByKey.get(keyStr)\n\n if (childSchema && isObjectSchema(childSchema) && childSchema.properties) {\n rows.push(...collectExampleRows(exampleSubvalue, childSchema, path))\n } else {\n rows.push({ path, value: exampleSubvalue })\n }\n }\n\n // Example-only properties at this level (preserve example order). Their inner shape is\n // not descended into — without a schema saying \"this is a nested object\" we have no\n // signal to flatten, so an object value becomes a single JSON-stringified row, matching\n // the schema-less fallback below.\n for (const [key, value] of exampleEntries) {\n const keyStr = String(key)\n if (declaredKeys.has(keyStr)) {\n continue\n }\n rows.push({ path: [...parentPath, keyStr], value })\n }\n\n return rows\n}\n\n/** Restore array values after text editing without parsing ordinary string fields. */\nexport const getFormBodyValue = (row: TableRow): string | File | unknown[] | undefined => {\n const value = coerceLeafValueToSchemaType(row.value, row.isArray ? { type: 'array' } : row.schema)\n return Array.isArray(value) ? value : (row.value ?? undefined)\n}\n\n/** Build the table rows for the form data, optionally enriched with schema (e.g. enum) per property */\nexport const getFormBodyRows = (\n example: ExampleObject | undefined | null,\n contentType: string,\n formBodySchema?: SchemaObject,\n compositionSelection?: Record<string, number>,\n): TableRow[] => {\n // Forms use structured data even when the raw example also supplies wire text.\n const value = example?.dataValue !== undefined ? example.dataValue : example?.value\n // We only need the rows for formData\n if (!value || (contentType !== 'multipart/form-data' && contentType !== 'application/x-www-form-urlencoded')) {\n return []\n }\n\n // Get all the schema properties if the schema is an object schema\n const resolvedBodySchema = resolveFormSchema(formBodySchema, compositionSelection)\n const schemaWithProperties = resolvedBodySchema && isObjectSchema(resolvedBodySchema) ? resolvedBodySchema : undefined\n // The request builder preserves composed fields because members can make them required.\n // Keep those fields checked so the initial form matches the body that will be sent.\n const isComposed = Boolean(schemaWithProperties?.allOf || schemaWithProperties?.oneOf || schemaWithProperties?.anyOf)\n const requiredSet = schemaWithProperties ? new Set(schemaWithProperties.required ?? []) : undefined\n\n // Pre-compute the leaf-by-dotted-name index up front so both the array and the\n // schema-driven branches can pull each row's leaf schema and required flag without\n // re-walking the schema. Without this, edited rows lose the per-leaf `Required`\n // badge because a top-level `properties[name]` lookup misses dotted names.\n const leafByDottedName = new Map<string, LeafRow>()\n if (schemaWithProperties) {\n for (const leaf of collectLeafProperties(schemaWithProperties)) {\n leafByDottedName.set(leaf.path.join('.'), leaf)\n }\n }\n\n const mapRow = ({\n name,\n value,\n isDisabled,\n }: {\n name: string\n value: string | File\n isDisabled?: boolean\n }): TableRow => {\n const row: TableRow = { name, value, isDisabled: isDisabled ?? false }\n if (!schemaWithProperties || !name) {\n return row\n }\n // Prefer the pre-resolved leaf (handles dotted names like `props.name`); fall back\n // to a top-level property lookup so user-added rows keep working.\n const leaf = leafByDottedName.get(name)\n const propSchema = leaf?.schema ?? resolveSchemaWithAnnotations(schemaWithProperties.properties?.[name])\n row.schema = propSchema\n row.description = leaf?.description ?? propSchema?.description\n row.isRequired = leaf?.isRequired ?? requiredSet?.has(name) ?? false\n\n // Top-level optional properties default to disabled (unchecked), matching how optional\n // parameters behave. Scoped to top-level declared properties on purpose: the send side\n // (`build-request-body`) only drops top-level optional keys, so auto-disabling a nested\n // leaf (e.g. `props.name`) would leave it unchecked yet still transmitted. `Object.hasOwn`\n // (not `in`) keeps example-only keys named like `Object.prototype` members enabled. An\n // explicit `isDisabled` (from a stored form-row array) always wins.\n if (\n isDisabled === undefined &&\n !isComposed &&\n schemaWithProperties.properties &&\n Object.hasOwn(schemaWithProperties.properties, name)\n ) {\n row.isDisabled = !row.isRequired\n // Mark the row as disabled by default (no explicit `isDisabled` was stored) so typing a\n // value auto-enables it in `RequestTableRow`, matching how optional parameters behave. An\n // explicit `isDisabled` from a stored form-row array skips this branch and keeps winning.\n row.isDisabledByDefault = row.isDisabled\n }\n return row\n }\n\n const mapValue = (name: string, value: unknown, isDisabled?: boolean, isArray?: boolean): TableRow[] => {\n // Uploaded files must never pass through JSON.stringify, which discards their bytes.\n if (\n contentType === 'multipart/form-data' &&\n Array.isArray(value) &&\n value.length > 0 &&\n value.every((item) => item instanceof File)\n ) {\n return value.map((file) => mapRow({ name, value: file, isDisabled }))\n }\n const row = mapRow({\n name,\n value: value instanceof File || value == null ? (value ?? '') : stringifyValue(value),\n isDisabled,\n })\n if (contentType === 'multipart/form-data' && (Array.isArray(value) || isArray)) {\n // Example-only arrays also need their type to survive a form-table round trip.\n row.isArray = true\n }\n return [row]\n }\n\n // We have form data stored as an array\n if (Array.isArray(value)) {\n return value.flatMap((exampleValue) => {\n if (isObject(exampleValue)) {\n const name = String(exampleValue.name)\n const rows =\n contentType === 'multipart/form-data'\n ? mapValue(name, exampleValue.value, Boolean(exampleValue.isDisabled), exampleValue.isArray === true)\n : [\n mapRow({\n name,\n value: exampleValue.value instanceof File ? exampleValue.value : String(exampleValue.value),\n isDisabled: Boolean(exampleValue.isDisabled),\n }),\n ]\n // An untouched optional row stays eligible for auto-enabling after another row is edited.\n return rows.map((row) =>\n row.isDisabled && exampleValue.isDisabledByDefault === true ? { ...row, isDisabledByDefault: true } : row,\n )\n }\n return { name: '', value: exampleValue, isDisabled: false }\n })\n }\n\n // Schema-driven path: when the form body schema describes nested objects, emit one row\n // per leaf so users can edit individual fields. The dotted name (`props.name`) is folded\n // back into a single JSON multipart part by `build-request-body.ts` before the request is\n // sent. Gated to `multipart/form-data` because urlencoded has no regrouping step on send,\n // so dotted leaves would otherwise reach the wire as separate `props.name`-style fields.\n //\n // We walk the example alongside the schema so example-only properties (top-level extras\n // or undeclared keys inside a nested object) are still visible and editable instead of\n // being silently dropped to whatever the schema happens to declare.\n if (contentType === 'multipart/form-data' && schemaWithProperties && typeof value === 'object') {\n return collectExampleRows(value, schemaWithProperties).flatMap(({ path, value }) => mapValue(path.join('.'), value))\n }\n\n // We got an object try to convert it to an array of rows\n if (typeof value === 'object' && value) {\n return objectEntries(value).flatMap(([key, value]) =>\n contentType === 'multipart/form-data'\n ? mapValue(String(key), value)\n : mapRow({ name: String(key), value: stringifyValue(value) }),\n )\n }\n\n return []\n}\n"],"mappings":";;;;;;;AAUA,IAAa,kBAAkB,UAAmB;CAChD,IAAI,iBAAiB,MACnB,OAAO,MAAM;CAEf,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO,KAAK,UAAU,KAAK;CAE7B,OAAO,OAAO,KAAK;AACrB;;;;;;;;;AAiBA,IAAa,yBACX,QACA,aAAuB,CAAC,GACxB,iBAAiB,MACjB,sBACc;CAEd,IAAI,CAAC,eAAe,MAAM,KAAK,CAAC,OAAO,YACrC,OAAO,CAAC;CAIV,MAAM,cAAc,IAAI,IAAI,OAAO,YAAY,CAAC,CAAC;CACjD,MAAM,SAAoB,CAAC;CAE3B,KAAK,MAAM,CAAC,KAAK,mBAAmB,cAAc,OAAO,UAAU,GAAG;EACpE,MAAM,cAAc,6BAA6B,cAAc;EAC/D,MAAM,OAAO,CAAC,GAAG,YAAY,OAAO,GAAG,CAAC;EAIxC,MAAM,aAAa,kBAAkB,YAAY,IAAI,OAAO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,gBAAgB,wBACZ,SAAS,OAAO,GAAG,GAAG,KAAK,IAC3B,OAAO;EAAE,MAAM,OAAO,GAAG;EAAG,OAAO,eAAe,KAAK;CAAE,CAAC,CAChE;CAGF,OAAO,CAAC;AACV"}
|
|
1
|
+
{"version":3,"file":"get-form-body-rows.js","names":[],"sources":["../../../../../src/v2/blocks/request-block/helpers/get-form-body-rows.ts"],"sourcesContent":["import { isObject } from '@scalar/helpers/object/is-object'\nimport { objectEntries } from '@scalar/helpers/object/object-entries'\nimport { resolveFormSchema } from '@scalar/workspace-store/helpers/resolve-form-schema'\nimport { resolveSchemaWithAnnotations } from '@scalar/workspace-store/helpers/resolve-schema-with-annotations'\nimport { coerceLeafValueToSchemaType } from '@scalar/workspace-store/request-example'\nimport type {\n ExampleObject,\n MediaTypeObject,\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'\n\nimport type { TableRow } from '@/v2/blocks/request-block/components/RequestTableRow.vue'\n\nexport const stringifyValue = (value: unknown) => {\n if (value instanceof File) {\n return value.name\n }\n if (typeof value === 'object' && value !== null) {\n return JSON.stringify(value)\n }\n return String(value)\n}\n\nexport type LeafRow = {\n path: string[]\n schema: SchemaObject | undefined\n isRequired: boolean\n description?: string\n}\n\n/**\n * Walk a (possibly nested) object schema and collect one entry per leaf property.\n *\n * A \"leaf\" is any property whose resolved schema is not an `{ type: 'object' }` schema\n * with named `properties` — i.e. primitives, arrays, files, and `additionalProperties`\n * placeholders all stop the recursion. Object properties recurse, so the widget example\n * (`file` + `props.{name,description,created_at}`) yields four leaves.\n */\nexport const collectLeafProperties = (\n schema: SchemaObject,\n parentPath: string[] = [],\n parentRequired = true,\n parentDescription?: string,\n): LeafRow[] => {\n // Nothing to walk if this is not an object schema or has no declared properties.\n if (!isObjectSchema(schema) || !schema.properties) {\n return []\n }\n\n // `required` is a list of property names on *this* schema, so build it once per level.\n const requiredSet = new Set(schema.required ?? [])\n const leaves: LeafRow[] = []\n\n for (const [key, rawChildSchema] of objectEntries(schema.properties)) {\n const childSchema = resolveSchemaWithAnnotations(rawChildSchema)\n const path = [...parentPath, String(key)]\n\n // A leaf is only required when *every* ancestor was also required — a non-required\n // parent makes the whole subtree optional regardless of inner `required` lists.\n const isRequired = parentRequired && requiredSet.has(String(key))\n\n // Nested objects with named properties recurse so each leaf gets its own row;\n // everything else (primitives, arrays, files, additionalProperties placeholders)\n // is treated as a leaf and stops the descent.\n if (childSchema && isObjectSchema(childSchema) && childSchema.properties) {\n leaves.push(...collectLeafProperties(childSchema, path, isRequired, childSchema.description ?? parentDescription))\n } else {\n leaves.push({ path, schema: childSchema, isRequired, description: childSchema?.description ?? parentDescription })\n }\n }\n\n return leaves\n}\n\n/**\n * Walk a schema + example together and collect one row per leaf, including example-only\n * keys that the schema does not declare. Schema-declared properties come first in schema\n * order; extras present in the example follow in example order at each level.\n *\n * Unlike `collectLeafProperties` (which is schema-only and feeds the dotted-name index),\n * this walker drives what the user actually sees in the form: a row for every leaf the\n * example contains, even when the schema is partial or out of date.\n */\nexport const collectExampleRows = (\n example: unknown,\n schema: SchemaObject | undefined,\n parentPath: string[] = [],\n): { path: string[]; value: unknown }[] => {\n const rows: { path: string[]; value: unknown }[] = []\n const exampleEntries = isObject(example) ? objectEntries(example) : []\n const exampleByKey = new Map<string, unknown>(exampleEntries.map(([key, value]) => [String(key), value]))\n const declaredKeys = new Set<string>()\n const schemaProperties = schema && isObjectSchema(schema) ? (schema.properties ?? {}) : {}\n\n // Schema-declared properties first, in schema order. Nested object schemas recurse so\n // each leaf gets its own row; otherwise the schema-declared key is a leaf and uses the\n // matching example value (or `undefined` when the example does not provide one).\n for (const [key, rawChildSchema] of objectEntries(schemaProperties)) {\n const keyStr = String(key)\n declaredKeys.add(keyStr)\n const childSchema = resolveSchemaWithAnnotations(rawChildSchema)\n const path = [...parentPath, keyStr]\n const exampleSubvalue = exampleByKey.get(keyStr)\n\n if (childSchema && isObjectSchema(childSchema) && childSchema.properties) {\n rows.push(...collectExampleRows(exampleSubvalue, childSchema, path))\n } else {\n rows.push({ path, value: exampleSubvalue })\n }\n }\n\n // Example-only properties at this level (preserve example order). Their inner shape is\n // not descended into — without a schema saying \"this is a nested object\" we have no\n // signal to flatten, so an object value becomes a single JSON-stringified row, matching\n // the schema-less fallback below.\n for (const [key, value] of exampleEntries) {\n const keyStr = String(key)\n if (declaredKeys.has(keyStr)) {\n continue\n }\n rows.push({ path: [...parentPath, keyStr], value })\n }\n\n return rows\n}\n\n/** Restore array values after text editing without parsing ordinary string fields. */\nexport const getFormBodyValue = (row: TableRow): string | File | unknown[] | undefined => {\n const value = coerceLeafValueToSchemaType(row.value, row.isArray ? { type: 'array' } : row.schema)\n return Array.isArray(value) ? value : (row.value ?? undefined)\n}\n\n/** Build the table rows for the form data, optionally enriched with schema (e.g. enum) per property */\nexport const getFormBodyRows = (\n example: ExampleObject | undefined | null,\n contentType: string,\n formBodySchema?: SchemaObject,\n compositionSelection?: Record<string, number>,\n encoding?: MediaTypeObject['encoding'],\n): TableRow[] => {\n // Forms use structured data even when the raw example also supplies wire text.\n const value = example?.dataValue !== undefined ? example.dataValue : example?.value\n // We only need the rows for formData\n if (!value || (contentType !== 'multipart/form-data' && contentType !== 'application/x-www-form-urlencoded')) {\n return []\n }\n\n // Get all the schema properties if the schema is an object schema\n const resolvedBodySchema = resolveFormSchema(formBodySchema, compositionSelection)\n const schemaWithProperties =\n resolvedBodySchema &&\n (isObjectSchema(resolvedBodySchema) ||\n 'properties' in resolvedBodySchema ||\n 'additionalProperties' in resolvedBodySchema)\n ? { ...resolvedBodySchema, type: 'object' as const }\n : undefined\n // The request builder preserves composed fields because members can make them required.\n // Keep those fields checked so the initial form matches the body that will be sent.\n const isComposed = Boolean(schemaWithProperties?.allOf || schemaWithProperties?.oneOf || schemaWithProperties?.anyOf)\n const requiredSet = schemaWithProperties ? new Set(schemaWithProperties.required ?? []) : undefined\n\n // Pre-compute the leaf-by-dotted-name index up front so both the array and the\n // schema-driven branches can pull each row's leaf schema and required flag without\n // re-walking the schema. Without this, edited rows lose the per-leaf `Required`\n // badge because a top-level `properties[name]` lookup misses dotted names.\n const leafByDottedName = new Map<string, LeafRow>()\n if (schemaWithProperties) {\n for (const leaf of collectLeafProperties(schemaWithProperties)) {\n leafByDottedName.set(leaf.path.join('.'), leaf)\n }\n }\n\n const mapRow = ({\n name,\n value,\n isDisabled,\n }: {\n name: string\n value: string | File\n isDisabled?: boolean\n }): TableRow => {\n const row: TableRow = {\n name,\n value,\n isDisabled: isDisabled ?? false,\n ...(encoding?.[name]?.contentType ? { contentType: encoding[name].contentType } : {}),\n }\n if (!schemaWithProperties || !name) {\n return row\n }\n // Prefer the pre-resolved leaf (handles dotted names like `props.name`); fall back\n // to a top-level property lookup so user-added rows keep working.\n const leaf = leafByDottedName.get(name)\n const propSchema =\n leaf?.schema ??\n resolveSchemaWithAnnotations(\n schemaWithProperties.properties?.[name] ??\n (typeof schemaWithProperties.additionalProperties === 'object'\n ? schemaWithProperties.additionalProperties\n : schemaWithProperties.additionalProperties === false\n ? undefined\n : { __scalar_: '' }),\n )\n row.schema = propSchema\n row.description = leaf?.description ?? propSchema?.description\n row.isRequired = leaf?.isRequired ?? requiredSet?.has(name) ?? false\n\n // Top-level optional properties default to disabled (unchecked), matching how optional\n // parameters behave. Scoped to top-level declared properties on purpose: the send side\n // (`build-request-body`) only drops top-level optional keys, so auto-disabling a nested\n // leaf (e.g. `props.name`) would leave it unchecked yet still transmitted. `Object.hasOwn`\n // (not `in`) keeps example-only keys named like `Object.prototype` members enabled. An\n // explicit `isDisabled` (from a stored form-row array) always wins.\n if (\n isDisabled === undefined &&\n !isComposed &&\n schemaWithProperties.properties &&\n Object.hasOwn(schemaWithProperties.properties, name)\n ) {\n row.isDisabled = !row.isRequired\n // Mark the row as disabled by default (no explicit `isDisabled` was stored) so typing a\n // value auto-enables it in `RequestTableRow`, matching how optional parameters behave. An\n // explicit `isDisabled` from a stored form-row array skips this branch and keeps winning.\n row.isDisabledByDefault = row.isDisabled\n }\n return row\n }\n\n const mapValue = (name: string, value: unknown, isDisabled?: boolean, isArray?: boolean): TableRow[] => {\n // Uploaded files must never pass through JSON.stringify, which discards their bytes.\n if (\n contentType === 'multipart/form-data' &&\n Array.isArray(value) &&\n value.length > 0 &&\n value.every((item) => item instanceof File)\n ) {\n return value.map((file) => mapRow({ name, value: file, isDisabled }))\n }\n const row = mapRow({\n name,\n value: value instanceof File || value == null ? (value ?? '') : stringifyValue(value),\n isDisabled,\n })\n if (contentType === 'multipart/form-data' && (Array.isArray(value) || isArray)) {\n // Example-only arrays also need their type to survive a form-table round trip.\n row.isArray = true\n }\n return [row]\n }\n\n // We have form data stored as an array\n if (Array.isArray(value)) {\n return value.flatMap((exampleValue) => {\n if (isObject(exampleValue)) {\n const name = String(exampleValue.name)\n const rows =\n contentType === 'multipart/form-data'\n ? mapValue(name, exampleValue.value, Boolean(exampleValue.isDisabled), exampleValue.isArray === true)\n : [\n mapRow({\n name,\n value: exampleValue.value instanceof File ? exampleValue.value : String(exampleValue.value),\n isDisabled: Boolean(exampleValue.isDisabled),\n }),\n ]\n // An untouched optional row stays eligible for auto-enabling after another row is edited.\n return rows.map((row) =>\n row.isDisabled && exampleValue.isDisabledByDefault === true ? { ...row, isDisabledByDefault: true } : row,\n )\n }\n return { name: '', value: exampleValue, isDisabled: false }\n })\n }\n\n // Schema-driven path: when the form body schema describes nested objects, emit one row\n // per leaf so users can edit individual fields. The dotted name (`props.name`) is folded\n // back into a single JSON multipart part by `build-request-body.ts` before the request is\n // sent. Gated to `multipart/form-data` because urlencoded has no regrouping step on send,\n // so dotted leaves would otherwise reach the wire as separate `props.name`-style fields.\n //\n // We walk the example alongside the schema so example-only properties (top-level extras\n // or undeclared keys inside a nested object) are still visible and editable instead of\n // being silently dropped to whatever the schema happens to declare.\n if (contentType === 'multipart/form-data' && schemaWithProperties && typeof value === 'object') {\n return collectExampleRows(value, schemaWithProperties).flatMap(({ path, value }) => mapValue(path.join('.'), value))\n }\n\n // We got an object try to convert it to an array of rows\n if (typeof value === 'object' && value) {\n return objectEntries(value).flatMap(([key, value]) =>\n contentType === 'multipart/form-data'\n ? mapValue(String(key), value)\n : mapRow({ name: String(key), value: stringifyValue(value) }),\n )\n }\n\n return []\n}\n"],"mappings":";;;;;;;AAcA,IAAa,kBAAkB,UAAmB;CAChD,IAAI,iBAAiB,MACnB,OAAO,MAAM;CAEf,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,OAAO,KAAK,UAAU,KAAK;CAE7B,OAAO,OAAO,KAAK;AACrB;;;;;;;;;AAiBA,IAAa,yBACX,QACA,aAAuB,CAAC,GACxB,iBAAiB,MACjB,sBACc;CAEd,IAAI,CAAC,eAAe,MAAM,KAAK,CAAC,OAAO,YACrC,OAAO,CAAC;CAIV,MAAM,cAAc,IAAI,IAAI,OAAO,YAAY,CAAC,CAAC;CACjD,MAAM,SAAoB,CAAC;CAE3B,KAAK,MAAM,CAAC,KAAK,mBAAmB,cAAc,OAAO,UAAU,GAAG;EACpE,MAAM,cAAc,6BAA6B,cAAc;EAC/D,MAAM,OAAO,CAAC,GAAG,YAAY,OAAO,GAAG,CAAC;EAIxC,MAAM,aAAa,kBAAkB,YAAY,IAAI,OAAO,GAAG,CAAC;EAKhE,IAAI,eAAe,eAAe,WAAW,KAAK,YAAY,YAC5D,OAAO,KAAK,GAAG,sBAAsB,aAAa,MAAM,YAAY,YAAY,eAAe,iBAAiB,CAAC;OAEjH,OAAO,KAAK;GAAE;GAAM,QAAQ;GAAa;GAAY,aAAa,aAAa,eAAe;EAAkB,CAAC;CAErH;CAEA,OAAO;AACT;;;;;;;;;;AAWA,IAAa,sBACX,SACA,QACA,aAAuB,CAAC,MACiB;CACzC,MAAM,OAA6C,CAAC;CACpD,MAAM,iBAAiB,SAAS,OAAO,IAAI,cAAc,OAAO,IAAI,CAAC;CACrE,MAAM,eAAe,IAAI,IAAqB,eAAe,KAAK,C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|
+
import type { ExampleObject, MediaTypeObject, SchemaObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
2
|
+
/** Keep structured parts and File objects intact until the existing multipart serializer runs. */
|
|
3
|
+
export type MultipartBodyValue = unknown[] | Record<string, unknown>;
|
|
4
|
+
/** One editable leaf part; paths retain positions and literal property names. */
|
|
5
|
+
export type MultipartBodyPart = {
|
|
6
|
+
path: (string | number)[];
|
|
7
|
+
value: unknown;
|
|
8
|
+
schema?: SchemaObject;
|
|
9
|
+
contentType?: string;
|
|
10
|
+
canUpload: boolean;
|
|
11
|
+
};
|
|
12
|
+
/** Raw wire examples stay in the raw editor, while JSON arrays/objects can expose individual parts. */
|
|
13
|
+
export declare const parseMultipartBody: (example: ExampleObject | null | undefined) => MultipartBodyValue | undefined;
|
|
14
|
+
/** Match the serializer's positional and named layouts without flattening JSON parts into form fields. */
|
|
15
|
+
export declare const getMultipartBodyParts: (value: MultipartBodyValue, media: MediaTypeObject, compositionSelection?: Record<string, number>) => MultipartBodyPart[];
|
|
16
|
+
/** Copy only the edited path so uploading a file never serializes sibling File objects or mutates the example. */
|
|
17
|
+
export declare const updateMultipartBodyPart: (body: MultipartBodyValue, path: (string | number)[], value: unknown) => MultipartBodyValue;
|
|
18
|
+
//# sourceMappingURL=multipart-body.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart-body.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/request-block/helpers/multipart-body.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAEV,aAAa,EACb,eAAe,EACf,YAAY,EACb,MAAM,8DAA8D,CAAA;AAGrE,kGAAkG;AAClG,MAAM,MAAM,kBAAkB,GAAG,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;AAEpE,iFAAiF;AACjF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,IAAI,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAA;IACzB,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,CAAC,EAAE,YAAY,CAAA;IACrB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,SAAS,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,uGAAuG;AACvG,eAAO,MAAM,kBAAkB,GAAI,SAAS,aAAa,GAAG,IAAI,GAAG,SAAS,KAAG,kBAAkB,GAAG,SAYnG,CAAA;AAED,0GAA0G;AAC1G,eAAO,MAAM,qBAAqB,GAChC,OAAO,kBAAkB,EACzB,OAAO,eAAe,EACtB,uBAAuB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAC5C,iBAAiB,EA8EnB,CAAA;AAED,kHAAkH;AAClH,eAAO,MAAM,uBAAuB,GAClC,MAAM,kBAAkB,EACxB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,EACzB,OAAO,OAAO,KACb,kBAkBF,CAAA"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { MAX_MULTIPART_NESTING, getMultipartItemSchema } from "@scalar/workspace-store/request-example";
|
|
2
|
+
import { parseMimeType } from "@scalar/helpers/http/mime-type";
|
|
3
|
+
import { unpackProxyShallow } from "@scalar/workspace-store/helpers/unpack-proxy";
|
|
4
|
+
import { isObject } from "@scalar/helpers/object/is-object";
|
|
5
|
+
import { getExampleValue } from "@scalar/workspace-store/helpers/get-example-value";
|
|
6
|
+
import { isArraySchema } from "@scalar/workspace-store/schemas/v3.2/strict/type-guards";
|
|
7
|
+
import { isFileSchema } from "@scalar/workspace-store/helpers/is-file-schema";
|
|
8
|
+
import { resolveFormSchema } from "@scalar/workspace-store/helpers/resolve-form-schema";
|
|
9
|
+
//#region src/v2/blocks/request-block/helpers/multipart-body.ts
|
|
10
|
+
/** Raw wire examples stay in the raw editor, while JSON arrays/objects can expose individual parts. */
|
|
11
|
+
var parseMultipartBody = (example) => {
|
|
12
|
+
const selected = getExampleValue(example ?? void 0);
|
|
13
|
+
if (!selected || selected.source === "serialized") return;
|
|
14
|
+
try {
|
|
15
|
+
const value = typeof selected.value === "string" ? JSON.parse(selected.value) : unpackProxyShallow(selected.value);
|
|
16
|
+
return Array.isArray(value) || isObject(value) ? value : void 0;
|
|
17
|
+
} catch {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
/** Match the serializer's positional and named layouts without flattening JSON parts into form fields. */
|
|
22
|
+
var getMultipartBodyParts = (value, media, compositionSelection) => {
|
|
23
|
+
const walk = (body, encoding, schema, path, schemaPath, nesting = 0) => {
|
|
24
|
+
const part = (partValue, rawSchema, partEncoding, partPath, partSchemaPath) => {
|
|
25
|
+
const partSchema = resolveFormSchema(rawSchema, compositionSelection, partSchemaPath);
|
|
26
|
+
if (nesting + 1 < MAX_MULTIPART_NESTING && parseMimeType(partEncoding?.contentType).type === "multipart" && (Array.isArray(partValue) || isObject(partValue))) return walk(partValue, partEncoding ?? {}, partSchema, partPath, partSchemaPath, nesting + 1);
|
|
27
|
+
return [{
|
|
28
|
+
path: partPath,
|
|
29
|
+
value: unpackProxyShallow(partValue),
|
|
30
|
+
schema: partSchema,
|
|
31
|
+
contentType: partEncoding?.contentType,
|
|
32
|
+
canUpload: partSchema === void 0 || !isArraySchema(partSchema) && isFileSchema(partSchema, true, partEncoding?.contentType)
|
|
33
|
+
}];
|
|
34
|
+
};
|
|
35
|
+
if (Array.isArray(body)) return (body.length === 0 && path.length > 0 && !(schema && "maxItems" in schema && schema.maxItems === 0) ? [""] : body).flatMap((item, index) => part(item, getMultipartItemSchema(schema, index, encoding.itemSchema), index < (encoding.prefixEncoding?.length ?? 0) ? encoding.prefixEncoding?.[index] : encoding.itemEncoding, [...path, index], schema && "prefixItems" in schema && schema.prefixItems?.[index] ? [
|
|
36
|
+
...schemaPath,
|
|
37
|
+
"prefixItems",
|
|
38
|
+
String(index)
|
|
39
|
+
] : [...schemaPath, "items"]));
|
|
40
|
+
return Object.entries(body).flatMap(([name, item]) => {
|
|
41
|
+
const properties = schema && "properties" in schema ? schema.properties : void 0;
|
|
42
|
+
const additional = schema && "additionalProperties" in schema ? schema.additionalProperties : void 0;
|
|
43
|
+
const propertySchema = resolveFormSchema(properties?.[name] ?? (typeof additional === "object" ? additional : void 0), compositionSelection, [...schemaPath, name]);
|
|
44
|
+
return Array.isArray(item) ? (item.length || propertySchema && "maxItems" in propertySchema && propertySchema.maxItems === 0 ? item : [""]).flatMap((entry, index) => part(entry, getMultipartItemSchema(propertySchema, index), encoding.encoding?.[name], [
|
|
45
|
+
...path,
|
|
46
|
+
name,
|
|
47
|
+
index
|
|
48
|
+
], propertySchema && "prefixItems" in propertySchema && propertySchema.prefixItems?.[index] ? [
|
|
49
|
+
...schemaPath,
|
|
50
|
+
name,
|
|
51
|
+
"prefixItems",
|
|
52
|
+
String(index)
|
|
53
|
+
] : [
|
|
54
|
+
...schemaPath,
|
|
55
|
+
name,
|
|
56
|
+
"items"
|
|
57
|
+
])) : part(item, propertySchema, encoding.encoding?.[name], [...path, name], [...schemaPath, name]);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
return walk(value, media, resolveFormSchema(media.schema, compositionSelection), [], ["requestBody"]);
|
|
61
|
+
};
|
|
62
|
+
/** Copy only the edited path so uploading a file never serializes sibling File objects or mutates the example. */
|
|
63
|
+
var updateMultipartBodyPart = (body, path, value) => {
|
|
64
|
+
const update = (current, remaining) => {
|
|
65
|
+
const [key, ...rest] = remaining;
|
|
66
|
+
if (key === void 0) return value;
|
|
67
|
+
if (Array.isArray(current) && typeof key === "number") return key === current.length ? [...current, update(void 0, rest)] : current.map((item, index) => index === key ? update(item, rest) : item);
|
|
68
|
+
if (isObject(current) && Object.hasOwn(current, key)) return {
|
|
69
|
+
...current,
|
|
70
|
+
[key]: update(current[key], rest)
|
|
71
|
+
};
|
|
72
|
+
return current;
|
|
73
|
+
};
|
|
74
|
+
const result = update(body, path);
|
|
75
|
+
return Array.isArray(result) || isObject(result) ? result : body;
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
export { getMultipartBodyParts, parseMultipartBody, updateMultipartBodyPart };
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=multipart-body.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multipart-body.js","names":[],"sources":["../../../../../src/v2/blocks/request-block/helpers/multipart-body.ts"],"sourcesContent":["import { parseMimeType } from '@scalar/helpers/http/mime-type'\nimport { isObject } from '@scalar/helpers/object/is-object'\nimport { getExampleValue } from '@scalar/workspace-store/helpers/get-example-value'\nimport { isFileSchema } from '@scalar/workspace-store/helpers/is-file-schema'\nimport { resolveFormSchema } from '@scalar/workspace-store/helpers/resolve-form-schema'\nimport { unpackProxyShallow } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport { MAX_MULTIPART_NESTING, getMultipartItemSchema } from '@scalar/workspace-store/request-example'\nimport type {\n EncodingObject,\n ExampleObject,\n MediaTypeObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { isArraySchema } from '@scalar/workspace-store/schemas/v3.2/strict/type-guards'\n\n/** Keep structured parts and File objects intact until the existing multipart serializer runs. */\nexport type MultipartBodyValue = unknown[] | Record<string, unknown>\n\n/** One editable leaf part; paths retain positions and literal property names. */\nexport type MultipartBodyPart = {\n path: (string | number)[]\n value: unknown\n schema?: SchemaObject\n contentType?: string\n canUpload: boolean\n}\n\n/** Raw wire examples stay in the raw editor, while JSON arrays/objects can expose individual parts. */\nexport const parseMultipartBody = (example: ExampleObject | null | undefined): MultipartBodyValue | undefined => {\n const selected = getExampleValue(example ?? undefined)\n if (!selected || selected.source === 'serialized') {\n return undefined\n }\n try {\n const value: unknown =\n typeof selected.value === 'string' ? JSON.parse(selected.value) : unpackProxyShallow(selected.value)\n return Array.isArray(value) || isObject(value) ? value : undefined\n } catch {\n return undefined\n }\n}\n\n/** Match the serializer's positional and named layouts without flattening JSON parts into form fields. */\nexport const getMultipartBodyParts = (\n value: MultipartBodyValue,\n media: MediaTypeObject,\n compositionSelection?: Record<string, number>,\n): MultipartBodyPart[] => {\n const walk = (\n body: MultipartBodyValue,\n encoding: Pick<MediaTypeObject, 'encoding' | 'prefixEncoding' | 'itemEncoding' | 'itemSchema'>,\n schema: SchemaObject | undefined,\n path: (string | number)[],\n schemaPath: string[],\n nesting = 0,\n ): MultipartBodyPart[] => {\n const part = (\n partValue: unknown,\n rawSchema: SchemaObject | undefined,\n partEncoding: EncodingObject | undefined,\n partPath: (string | number)[],\n partSchemaPath: string[],\n ): MultipartBodyPart[] => {\n const partSchema = resolveFormSchema(rawSchema, compositionSelection, partSchemaPath)\n if (\n nesting + 1 < MAX_MULTIPART_NESTING &&\n parseMimeType(partEncoding?.contentType).type === 'multipart' &&\n (Array.isArray(partValue) || isObject(partValue))\n ) {\n return walk(partValue, partEncoding ?? {}, partSchema, partPath, partSchemaPath, nesting + 1)\n }\n return [\n {\n path: partPath,\n value: unpackProxyShallow(partValue),\n schema: partSchema,\n contentType: partEncoding?.contentType,\n canUpload:\n partSchema === undefined ||\n (!isArraySchema(partSchema) && isFileSchema(partSchema, true, partEncoding?.contentType)),\n },\n ]\n }\n if (Array.isArray(body)) {\n const items =\n body.length === 0 && path.length > 0 && !(schema && 'maxItems' in schema && schema.maxItems === 0) ? [''] : body\n return items.flatMap((item, index) =>\n part(\n item,\n getMultipartItemSchema(schema, index, encoding.itemSchema),\n index < (encoding.prefixEncoding?.length ?? 0) ? encoding.prefixEncoding?.[index] : encoding.itemEncoding,\n [...path, index],\n schema && 'prefixItems' in schema && schema.prefixItems?.[index]\n ? [...schemaPath, 'prefixItems', String(index)]\n : [...schemaPath, 'items'],\n ),\n )\n }\n return Object.entries(body).flatMap(([name, item]) => {\n const properties = schema && 'properties' in schema ? schema.properties : undefined\n const additional = schema && 'additionalProperties' in schema ? schema.additionalProperties : undefined\n const propertySchema = resolveFormSchema(\n properties?.[name] ?? (typeof additional === 'object' ? additional : undefined),\n compositionSelection,\n [...schemaPath, name],\n )\n return Array.isArray(item)\n ? (item.length || (propertySchema && 'maxItems' in propertySchema && propertySchema.maxItems === 0)\n ? item\n : ['']\n ).flatMap((entry, index) =>\n part(\n entry,\n getMultipartItemSchema(propertySchema, index),\n encoding.encoding?.[name],\n [...path, name, index],\n propertySchema && 'prefixItems' in propertySchema && propertySchema.prefixItems?.[index]\n ? [...schemaPath, name, 'prefixItems', String(index)]\n : [...schemaPath, name, 'items'],\n ),\n )\n : part(item, propertySchema, encoding.encoding?.[name], [...path, name], [...schemaPath, name])\n })\n }\n return walk(value, media, resolveFormSchema(media.schema, compositionSelection), [], ['requestBody'])\n}\n\n/** Copy only the edited path so uploading a file never serializes sibling File objects or mutates the example. */\nexport const updateMultipartBodyPart = (\n body: MultipartBodyValue,\n path: (string | number)[],\n value: unknown,\n): MultipartBodyValue => {\n const update = (current: unknown, remaining: (string | number)[]): unknown => {\n const [key, ...rest] = remaining\n if (key === undefined) {\n return value\n }\n if (Array.isArray(current) && typeof key === 'number') {\n return key === current.length\n ? [...current, update(undefined, rest)]\n : current.map((item, index) => (index === key ? update(item, rest) : item))\n }\n if (isObject(current) && Object.hasOwn(current, key)) {\n return { ...current, [key]: update(current[key], rest) }\n }\n return current\n }\n const result = update(body, path)\n return Array.isArray(result) || isObject(result) ? result : body\n}\n"],"mappings":";;;;;;;;;;AA4BA,IAAa,sBAAsB,YAA8E;CAC/G,MAAM,WAAW,gBAAgB,WAAW,KAAA,CAAS;CACrD,IAAI,CAAC,YAAY,SAAS,WAAW,cACnC;CAEF,IAAI;EACF,MAAM,QACJ,OAAO,SAAS,UAAU,WAAW,KAAK,MAAM,SAAS,KAAK,IAAI,mBAAmB,SAAS,KAAK;EACrG,OAAO,MAAM,QAAQ,KAAK,KAAK,SAAS,KAAK,IAAI,QAAQ,KAAA;CAC3D,QAAQ;EACN;CACF;AACF;;AAGA,IAAa,yBACX,OACA,OACA,yBACwB;CACxB,MAAM,QACJ,MACA,UACA,QACA,MACA,YACA,UAAU,MACc;EACxB,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/blocks/request-block/helpers/structured-body-codec.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"structured-body-codec.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/request-block/helpers/structured-body-codec.ts"],"names":[],"mappings":"AAIA,+EAA+E;AAC/E,KAAK,mBAAmB,GAAG;IACzB,uEAAuE;IACvE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;IACzB,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAA;IAChC,SAAS,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;CACtC,CAAA;AAgBD;;;;GAIG;AACH,eAAO,MAAM,sBAAsB,GAAI,aAAa,MAAM,KAAG,mBAAmB,GAAG,SAUlF,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { parseMimeType } from "@scalar/helpers/http/mime-type";
|
|
2
|
+
import { YAML_MAX_ALIAS_COUNT } from "@scalar/helpers/general/yaml-max-alias-count";
|
|
2
3
|
import { parse, stringify } from "yaml";
|
|
3
4
|
//#region src/v2/blocks/request-block/helpers/structured-body-codec.ts
|
|
4
5
|
var jsonCodec = {
|
|
@@ -8,7 +9,7 @@ var jsonCodec = {
|
|
|
8
9
|
};
|
|
9
10
|
var yamlCodec = {
|
|
10
11
|
language: "yaml",
|
|
11
|
-
parse: (text) => parse(text),
|
|
12
|
+
parse: (text) => parse(text, { maxAliasCount: YAML_MAX_ALIAS_COUNT }),
|
|
12
13
|
stringify: (value) => stringify(value)
|
|
13
14
|
};
|
|
14
15
|
var YAML_ESSENCES = /* @__PURE__ */ new Set([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"structured-body-codec.js","names":["parseYaml","stringifyYaml"],"sources":["../../../../../src/v2/blocks/request-block/helpers/structured-body-codec.ts"],"sourcesContent":["import { parseMimeType } from '@scalar/helpers/http/mime-type'\nimport { parse as parseYaml, stringify as stringifyYaml } from 'yaml'\n\n/** Parse/serialize pair for a structured (form-editable) body content type. */\ntype StructuredBodyCodec = {\n /** Language for the raw code editor, doubles as the codec family id */\n language: 'json' | 'yaml'\n parse: (text: string) => unknown\n stringify: (value: unknown) => string\n}\n\nconst jsonCodec: StructuredBodyCodec = {\n language: 'json',\n parse: (text) => JSON.parse(text),\n stringify: (value) => JSON.stringify(value, null, 2),\n}\n\nconst yamlCodec: StructuredBodyCodec = {\n language: 'yaml',\n parse: (text) => parseYaml(text),\n stringify: (value) => stringifyYaml(value),\n}\n\nconst YAML_ESSENCES = new Set(['application/yaml', 'application/x-yaml', 'text/yaml', 'text/x-yaml'])\n\n/**\n * Return the codec for content types whose body is a structured document we can edit as\n * a form (JSON and YAML families, including `+json` / `+yaml` vendor suffixes), or\n * `undefined` for everything else (multipart and urlencoded keep their own form editor).\n */\nexport const getStructuredBodyCodec = (contentType: string): StructuredBodyCodec | undefined => {\n const essence = parseMimeType(contentType).essence\n\n if (essence === 'application/json' || essence.endsWith('+json')) {\n return jsonCodec\n }\n if (YAML_ESSENCES.has(essence) || essence.endsWith('+yaml')) {\n return yamlCodec\n }\n return undefined\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"structured-body-codec.js","names":["parseYaml","stringifyYaml"],"sources":["../../../../../src/v2/blocks/request-block/helpers/structured-body-codec.ts"],"sourcesContent":["import { YAML_MAX_ALIAS_COUNT } from '@scalar/helpers/general/yaml-max-alias-count'\nimport { parseMimeType } from '@scalar/helpers/http/mime-type'\nimport { parse as parseYaml, stringify as stringifyYaml } from 'yaml'\n\n/** Parse/serialize pair for a structured (form-editable) body content type. */\ntype StructuredBodyCodec = {\n /** Language for the raw code editor, doubles as the codec family id */\n language: 'json' | 'yaml'\n parse: (text: string) => unknown\n stringify: (value: unknown) => string\n}\n\nconst jsonCodec: StructuredBodyCodec = {\n language: 'json',\n parse: (text) => JSON.parse(text),\n stringify: (value) => JSON.stringify(value, null, 2),\n}\n\nconst yamlCodec: StructuredBodyCodec = {\n language: 'yaml',\n parse: (text) => parseYaml(text, { maxAliasCount: YAML_MAX_ALIAS_COUNT }),\n stringify: (value) => stringifyYaml(value),\n}\n\nconst YAML_ESSENCES = new Set(['application/yaml', 'application/x-yaml', 'text/yaml', 'text/x-yaml'])\n\n/**\n * Return the codec for content types whose body is a structured document we can edit as\n * a form (JSON and YAML families, including `+json` / `+yaml` vendor suffixes), or\n * `undefined` for everything else (multipart and urlencoded keep their own form editor).\n */\nexport const getStructuredBodyCodec = (contentType: string): StructuredBodyCodec | undefined => {\n const essence = parseMimeType(contentType).essence\n\n if (essence === 'application/json' || essence.endsWith('+json')) {\n return jsonCodec\n }\n if (YAML_ESSENCES.has(essence) || essence.endsWith('+yaml')) {\n return yamlCodec\n }\n return undefined\n}\n"],"mappings":";;;;AAYA,IAAM,YAAiC;CACrC,UAAU;CACV,QAAQ,SAAS,KAAK,MAAM,IAAI;CAChC,YAAY,UAAU,KAAK,UAAU,OAAO,MAAM,CAAC;AACrD;AAEA,IAAM,YAAiC;CACrC,UAAU;CACV,QAAQ,SAASA,MAAU,MAAM,EAAE,eAAe,qBAAqB,CAAC;CACxE,YAAY,UAAUC,UAAc,KAAK;AAC3C;AAEA,IAAM,gCAAgB,IAAI,IAAI;CAAC;CAAoB;CAAsB;CAAa;AAAa,CAAC;;;;;;AAOpG,IAAa,0BAA0B,gBAAyD;CAC9F,MAAM,UAAU,cAAc,WAAW,CAAC,CAAC;CAE3C,IAAI,YAAY,sBAAsB,QAAQ,SAAS,OAAO,GAC5D,OAAO;CAET,IAAI,cAAc,IAAI,OAAO,KAAK,QAAQ,SAAS,OAAO,GACxD,OAAO;AAGX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AuthSelector.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","CollapsibleSection","_createSlots","_withCtx","_createElementVNode","_toDisplayString","_createElementBlock","_normalizeClass","_createCommentVNode","_createVNode","RequestAuthDataTable","DeleteRequestAuthModal","_withModifiers","_Fragment","_createTextVNode"],"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'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport RequestAuthDataTable from './RequestAuthDataTable.vue'\n\nconst {\n environment,\n eventBus,\n createAnySecurityScheme = false,\n allowedSecuritySchemes,\n canDeleteSchemes = true,\n defaultOpen = true,\n heading = true,\n hideSingleRequiredScheme = false,\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 /** Limits visible schemes without changing request authentication. */\n allowedSecuritySchemes?: string[]\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 /**\n * Whether the title belongs in the document outline. The client renders the\n * selector as one section of a request, so it is a heading there. A surface\n * that only offers the schemes as a card of controls, such as the reference,\n * turns it off and the card is named as a group instead.\n */\n heading?: boolean\n /** Hides a sole active required choice in the reference while preserving client controls. */\n hideSingleRequiredScheme?: 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 { translate, translations } = useLocalization()\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\n ? translate('apiClient.authSelector.optional')\n : translate('apiClient.authSelector.required'),\n }\n})\n\n/** Excluded schemes must also stay out of secondary forms such as OAuth acquisition. */\nconst visibleSecuritySchemes = computed<MergedSecuritySchemes>(() =>\n allowedSecuritySchemes\n ? Object.fromEntries(\n Object.entries(securitySchemes).filter(([name]) =>\n allowedSecuritySchemes.includes(name),\n ),\n )\n : securitySchemes,\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 translations.value.apiClient,\n allowedSecuritySchemes,\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 (\n schemeNames.length === 0 ||\n (allowedSecuritySchemes &&\n schemeNames.some((name) => !allowedSecuritySchemes.includes(name)))\n ) {\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/** Preserve store indexes when the allowlist hides earlier saved selections. */\nconst visibleSchemeIndexes = computed<number[]>(() =>\n activeSchemeOptions.value.map(\n (option) =>\n selectedSecurity?.selectedSchemes.findIndex(\n (requirement) => formatComplexScheme(requirement).id === option.id,\n ) ?? -1,\n ),\n)\nconst visibleActiveIndex = computed<number>(() =>\n visibleSchemeIndexes.value.indexOf(selectedSecurity?.selectedIndex ?? 0),\n)\n\n/** Keep selection available whenever it can change auth or recover an empty saved selection. */\nconst showSchemeSelector = computed<boolean>(() => {\n if (\n !hideSingleRequiredScheme ||\n createAnySecurityScheme ||\n securityRequirements?.length !== 1 ||\n Object.keys(securityRequirements[0] ?? {}).length === 0\n ) {\n return true\n }\n\n const schemeOptions = availableSchemeOptions.value.flatMap((option) =>\n 'options' in option ? option.options : [option],\n )\n\n return (\n schemeOptions.length !== 1 ||\n activeSchemeOptions.value.length !== 1 ||\n activeSchemeOptions.value[0]?.id !== schemeOptions[0]?.id\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 (!showSchemeSelector.value) {\n return\n }\n\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 :heading\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 -my-0.5 -mr-1 rounded px-1 py-0.5 leading-[normal] font-normal\"\n :class=\"{\n 'text-c-1': authIndicator.icon === 'Lock',\n 'hover:bg-b-3 hover:text-c-1 cursor-pointer': showSchemeSelector,\n }\"\n data-testid=\"auth-indicator\"\n @click=\"handleAuthIndicatorClick\">\n {{ authIndicator.text }}\n </span>\n </div>\n </template>\n\n <!-- The client keeps its selection and deletion controls. -->\n <template\n v-if=\"showSchemeSelector\"\n #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 {{\n translate('apiClient.authSelector.selectedType', {\n type: activeSchemeOptions[0]?.label ?? '',\n })\n }}\n </template>\n\n <!-- Multiple auth schemes selected -->\n <template v-else-if=\"activeSchemeOptions.length > 1\">\n {{ translate('apiClient.authSelector.multipleTypes') }}\n </template>\n\n <!-- No auth schemes selected -->\n <template v-else>\n {{ translate('apiClient.authSelector.selectType') }}\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=\"\n translate('apiClient.authSelector.deleteScheme', {\n name: option.label,\n })\n \"\n size=\"xs\"\n @click.stop=\"handleDeleteRequest(option)\" />\n </template>\n </ScalarComboboxMultiselect>\n </template>\n\n <!-- Auth Table -->\n <RequestAuthDataTable\n :activeAuthIndex=\"visibleActiveIndex\"\n :documentType\n :environment\n :eventBus\n :isStatic\n :meta\n :options\n :proxyUrl\n :securitySchemes=\"visibleSecuritySchemes\"\n :selectedSchemeIndexes=\"visibleSchemeIndexes\"\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoGA,MAAM,EAAE,WAAW,iBAAiB,gBAAgB;EAEpD,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,aACF,UAAU,iCAAiC,IAC3C,UAAU,iCAAiC;GACjD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MAAA,qBAAA,GAAA;OADvB,aAAA;OACW;;MACbI,mBAEM,OAFN,YAEMC,gBADD,OAAO,KAAK,GAAA,CAAA;MAGT,OAAO,eAAe,QAAA,oBAD9BP,UAAA,GAAAC,YAU8CC,MAAA,gBAAA,GAAA;;OAR5C,OAAM;OACL,MAAMA,MAAA,eAAA;OACN,OAAsBA,MAAA,SAAA,CAAS,CAAA,uCAAA,EAAgE,MAAA,OAAO,M;OAKvG,MAAK;OACJ,SAAKY,eAAA,WAAO,oBAAoB,MAAM,GAAA,CAAA,MAAA,CAAA;;;;;;;KA9C3C,SAAAT,cA2Be,CA3BfM,YA2BeT,MAAA,YAAA,GAAA;MA1BT,SAAA;MAAJ,KAAI;MACH,oBAAkBA,MAAA,OAAA;MACnB,OAAM;MACN,SAAQ;;MAER,SAAAG,cAMW,CANK,oBAAA,MAAoB,WAAM,KAA1CL,UAAA,GAAAQ,mBAMWO,UAAA,EAAA,KAAA,EAAA,GAAA,CAJPC,gBAAAT,gBAAAL,MAAA,SAAA,CAAS,CAAA,uCAAA,EAAgE,MAAA,oBAAA,MAAmB,EAAA,EAAK,SAAK,G,iBAOrF,oBAAA,MAAoB,SAAM,KAA/CF,UAAA,GAAAQ,mBAEWO,UAAA,EAAA,KAAA,EAAA,GAAA,CADNC,gBAAAT,gBAAAL,MAAA,SAAA,CAAS,CAAA,sCAAA,CAAA,GAAA,CAAA,C,WAIdF,UAAA,GAAAQ,mBAEWO,UAAA,EAAA,KAAA,EAAA,GAAA,CADNC,gBAAAT,gBAAAL,MAAA,SAAA,CAAS,CAAA,mCAAA,CAAA,GAAA,CAAA,C,SAGdS,YAEkBT,MAAA,mBAAA,GAAA;OADhB,OAAM;OACN,QAAO"}
|
|
1
|
+
{"version":3,"file":"AuthSelector.vue_vue_type_script_setup_true_lang.js","names":["_openBlock","_createBlock","_unref","CollapsibleSection","_createSlots","_withCtx","_createElementVNode","_toDisplayString","_createElementBlock","_normalizeClass","_createCommentVNode","_createVNode","RequestAuthDataTable","DeleteRequestAuthModal","_withModifiers","_Fragment","_createTextVNode"],"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'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport RequestAuthDataTable from './RequestAuthDataTable.vue'\n\nconst {\n environment,\n eventBus,\n createAnySecurityScheme = false,\n allowedSecuritySchemes,\n canDeleteSchemes = true,\n defaultOpen = true,\n heading = true,\n hideSingleRequiredScheme = false,\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 /** Limits visible schemes without changing request authentication. */\n allowedSecuritySchemes?: string[]\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 /**\n * Whether the title belongs in the document outline. The client renders the\n * selector as one section of a request, so it is a heading there. A surface\n * that only offers the schemes as a card of controls, such as the reference,\n * turns it off and the card is named as a group instead.\n */\n heading?: boolean\n /** Hides a sole active required choice in the reference while preserving client controls. */\n hideSingleRequiredScheme?: 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 { translate, translations } = useLocalization()\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\n ? translate('apiClient.authSelector.optional')\n : translate('apiClient.authSelector.required'),\n }\n})\n\n/** Excluded schemes must also stay out of secondary forms such as OAuth acquisition. */\nconst visibleSecuritySchemes = computed<MergedSecuritySchemes>(() =>\n allowedSecuritySchemes\n ? Object.fromEntries(\n Object.entries(securitySchemes).filter(([name]) =>\n allowedSecuritySchemes.includes(name),\n ),\n )\n : securitySchemes,\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 translations.value.apiClient,\n allowedSecuritySchemes,\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 (\n schemeNames.length === 0 ||\n (allowedSecuritySchemes &&\n schemeNames.some((name) => !allowedSecuritySchemes.includes(name)))\n ) {\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/** Preserve store indexes when the allowlist hides earlier saved selections. */\nconst visibleSchemeIndexes = computed<number[]>(() =>\n activeSchemeOptions.value.map(\n (option) =>\n selectedSecurity?.selectedSchemes.findIndex(\n (requirement) => formatComplexScheme(requirement).id === option.id,\n ) ?? -1,\n ),\n)\nconst visibleActiveIndex = computed<number>(() =>\n visibleSchemeIndexes.value.indexOf(selectedSecurity?.selectedIndex ?? 0),\n)\n\n/** Keep selection available whenever it can change auth or recover an empty saved selection. */\nconst showSchemeSelector = computed<boolean>(() => {\n if (\n !hideSingleRequiredScheme ||\n createAnySecurityScheme ||\n securityRequirements?.length !== 1 ||\n Object.keys(securityRequirements[0] ?? {}).length === 0\n ) {\n return true\n }\n\n const schemeOptions = availableSchemeOptions.value.flatMap((option) =>\n 'options' in option ? option.options : [option],\n )\n\n return (\n schemeOptions.length !== 1 ||\n activeSchemeOptions.value.length !== 1 ||\n activeSchemeOptions.value[0]?.id !== schemeOptions[0]?.id\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 (!showSchemeSelector.value) {\n return\n }\n\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 :heading\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 -my-0.5 -mr-1 rounded px-1 py-0.5 leading-[normal] font-normal\"\n :class=\"{\n 'text-c-1': authIndicator.icon === 'Lock',\n 'hover:bg-b-3 hover:text-c-1 cursor-pointer': showSchemeSelector,\n }\"\n data-testid=\"auth-indicator\"\n @click=\"handleAuthIndicatorClick\">\n {{ authIndicator.text }}\n </span>\n </div>\n </template>\n\n <!-- The client keeps its selection and deletion controls. -->\n <template\n v-if=\"showSchemeSelector\"\n #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 {{\n translate('apiClient.authSelector.selectedType', {\n type: activeSchemeOptions[0]?.label ?? '',\n })\n }}\n </template>\n\n <!-- Multiple auth schemes selected -->\n <template v-else-if=\"activeSchemeOptions.length > 1\">\n {{ translate('apiClient.authSelector.multipleTypes') }}\n </template>\n\n <!-- No auth schemes selected -->\n <template v-else>\n {{ translate('apiClient.authSelector.selectType') }}\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=\"\n translate('apiClient.authSelector.deleteScheme', {\n name: option.label,\n })\n \"\n size=\"xs\"\n @click.stop=\"handleDeleteRequest(option)\" />\n </template>\n </ScalarComboboxMultiselect>\n </template>\n\n <!-- Auth Table -->\n <RequestAuthDataTable\n :activeAuthIndex=\"visibleActiveIndex\"\n :documentType\n :environment\n :eventBus\n :isStatic\n :meta\n :options\n :proxyUrl\n :securitySchemes=\"visibleSecuritySchemes\"\n :selectedSchemeIndexes=\"visibleSchemeIndexes\"\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAoGA,MAAM,EAAE,WAAW,iBAAiB,gBAAgB;EAEpD,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,aACF,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/request-example';
|
|
2
3
|
import type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments';
|
|
3
|
-
import { type OpenIdConnectObject } from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document';
|
|
4
4
|
import type { CustomFetch } from '../../operation-block/helpers/send-request.js';
|
|
5
5
|
type __VLS_Props = {
|
|
6
6
|
/** Current environment configuration */
|
|
@@ -14,7 +14,7 @@ type __VLS_Props = {
|
|
|
14
14
|
/** Proxy URL */
|
|
15
15
|
proxyUrl: string;
|
|
16
16
|
/** OpenID Connect scheme */
|
|
17
|
-
scheme:
|
|
17
|
+
scheme: OpenIdConnectObjectSecret;
|
|
18
18
|
/** Optional fetch override (IPC-backed on desktop) used for discovery requests */
|
|
19
19
|
customFetch?: CustomFetch;
|
|
20
20
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenIDConnect.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenIDConnect.vue.d.ts","sourceRoot":"","sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.vue"],"names":[],"mappings":"AAmIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAA;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAA;AACxF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2EAA2E,CAAA;AAEnH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kDAAkD,CAAA;AAQnF,KAAK,WAAW,GAAG;IACjB,wCAAwC;IACxC,WAAW,EAAE,kBAAkB,CAAA;IAC/B,2CAA2C;IAC3C,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,kCAAkC;IAClC,oBAAoB,EAAE,MAAM,MAAM,GAAG,KAAK,CAAA;IAC1C,kCAAkC;IAClC,IAAI,EAAE,MAAM,CAAA;IACZ,gBAAgB;IAChB,QAAQ,EAAE,MAAM,CAAA;IAChB,4BAA4B;IAC5B,MAAM,EAAE,yBAAyB,CAAA;IACjC,kFAAkF;IAClF,WAAW,CAAC,EAAE,WAAW,CAAA;CAC1B,CAAC;AAgMF,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenIDConnect.vue.js","names":["_sfc_main"],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.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 {
|
|
1
|
+
{"version":3,"file":"OpenIDConnect.vue.js","names":["_sfc_main"],"sources":["../../../../../src/v2/blocks/scalar-auth-selector-block/components/OpenIDConnect.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 { OpenIdConnectObjectSecret } from '@scalar/workspace-store/request-example'\nimport type { XScalarEnvironment } from '@scalar/workspace-store/schemas/extensions/document/x-scalar-environments'\n\nimport type { CustomFetch } from '@/v2/blocks/operation-block/helpers/send-request'\nimport { fetchOpenIDConnectDiscovery } from '@/v2/blocks/scalar-auth-selector-block/helpers/fetch-openid-connect-discovery'\nimport { openIDDiscoveryToFlows } from '@/v2/blocks/scalar-auth-selector-block/helpers/openid-discovery-to-flows'\nimport { DataTableRow } from '@/v2/components/data-table'\nimport { useLocalization } from '@/v2/features/localization'\n\nimport RequestAuthDataTableInput from './RequestAuthDataTableInput.vue'\n\nconst {\n environment,\n eventBus,\n getStaticBorderClass,\n name,\n scheme,\n proxyUrl,\n customFetch,\n} = defineProps<{\n /** Current environment configuration */\n environment: XScalarEnvironment\n /** Event bus for authentication updates */\n eventBus: WorkspaceEventBus\n /** Get the static border class */\n getStaticBorderClass: () => string | false\n /** Name of the security scheme */\n name: string\n /** Proxy URL */\n proxyUrl: string\n /** OpenID Connect scheme */\n scheme: OpenIdConnectObjectSecret\n /** Optional fetch override (IPC-backed on desktop) used for discovery requests */\n customFetch?: CustomFetch\n}>()\n\nconst { translate } = useLocalization()\n\nconst loader = useLoadingState()\nconst { toast } = useToasts()\n\n/**\n * Fetches the OpenID Connect discovery document and triggers authorization\n */\nconst handleOpenIdConnect = async (): Promise<void> => {\n if (loader.isLoading || !scheme.openIdConnectUrl) {\n return\n }\n\n loader.start()\n const [error, _discovery] = await fetchOpenIDConnectDiscovery(\n scheme.openIdConnectUrl,\n proxyUrl,\n customFetch,\n )\n await loader.clear()\n\n // Toast for error\n if (error) {\n console.error(error)\n toast(\n error?.message ??\n translate('apiClient.openIdConnect.failedToFetchConfiguration'),\n 'error',\n )\n return\n }\n\n /** Set the newly discovered params in the secret store */\n const openIdConnect = openIDDiscoveryToFlows(_discovery)\n // Seed PKCE once so later user edits keep precedence over the configured default.\n const configuredPkce =\n scheme.configuredFlows?.authorizationCode?.['x-usePkce']\n if (openIdConnect.authorizationCode && configuredPkce !== undefined) {\n openIdConnect.authorizationCode['x-usePkce'] = configuredPkce\n }\n eventBus.emit('auth:update:security-scheme-secrets', {\n payload: openIdConnect,\n name,\n overwrite: true,\n })\n}\n\nconst handleUpdateOpenIdConnectUrl = (value: string): void =>\n eventBus.emit('auth:update:security-scheme', {\n payload: {\n type: 'openIdConnect',\n openIdConnectUrl: value,\n },\n name,\n })\n</script>\n\n<template>\n <DataTableRow>\n <RequestAuthDataTableInput\n :containerClass=\"getStaticBorderClass()\"\n :environment\n :modelValue=\"scheme.openIdConnectUrl\"\n placeholder=\"https://example.com/.well-known/openid-configuration\"\n required\n @update:modelValue=\"handleUpdateOpenIdConnectUrl\">\n {{ translate('apiClient.openIdConnect.discoveryUrl') }}\n </RequestAuthDataTableInput>\n </DataTableRow>\n\n <DataTableRow 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 :disabled=\"!scheme.openIdConnectUrl\"\n :loader\n size=\"sm\"\n variant=\"outlined\"\n @click=\"handleOpenIdConnect\">\n {{ translate('apiClient.openIdConnect.fetchConfiguration') }}\n </ScalarButton>\n </div>\n </DataTableRow>\n</template>\n"],"mappings":""}
|
|
@@ -39,6 +39,8 @@ var OpenIDConnect_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ de
|
|
|
39
39
|
}
|
|
40
40
|
/** Set the newly discovered params in the secret store */
|
|
41
41
|
const openIdConnect = openIDDiscoveryToFlows(_discovery);
|
|
42
|
+
const configuredPkce = __props.scheme.configuredFlows?.authorizationCode?.["x-usePkce"];
|
|
43
|
+
if (openIdConnect.authorizationCode && configuredPkce !== void 0) openIdConnect.authorizationCode["x-usePkce"] = configuredPkce;
|
|
42
44
|
__props.eventBus.emit("auth:update:security-scheme-secrets", {
|
|
43
45
|
payload: openIdConnect,
|
|
44
46
|
name: __props.name,
|