@stoplight/elements-core 7.12.3 → 7.13.0

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/index.js CHANGED
@@ -21,9 +21,9 @@ var jotai = require('jotai');
21
21
  var URI = require('urijs');
22
22
  var mosaicCodeViewer = require('@stoplight/mosaic-code-viewer');
23
23
  var httpsnippetLite = require('httpsnippet-lite');
24
- var flatten = require('lodash/flatten.js');
25
24
  var capitalize = require('lodash/capitalize.js');
26
25
  var filter = require('lodash/filter.js');
26
+ var flatten = require('lodash/flatten.js');
27
27
  var nanoid = require('nanoid');
28
28
  var curry = require('lodash/curry.js');
29
29
  var omit = require('lodash/omit.js');
@@ -80,9 +80,9 @@ var isPlainObject__default = /*#__PURE__*/_interopDefaultLegacy(isPlainObject);
80
80
  var isObject__default = /*#__PURE__*/_interopDefaultLegacy(isObject);
81
81
  var cn__default = /*#__PURE__*/_interopDefaultLegacy(cn);
82
82
  var URI__default = /*#__PURE__*/_interopDefaultLegacy(URI);
83
- var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
84
83
  var capitalize__default = /*#__PURE__*/_interopDefaultLegacy(capitalize);
85
84
  var filter__default = /*#__PURE__*/_interopDefaultLegacy(filter);
85
+ var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten);
86
86
  var curry__default = /*#__PURE__*/_interopDefaultLegacy(curry);
87
87
  var omit__default = /*#__PURE__*/_interopDefaultLegacy(omit);
88
88
  var keyBy__default = /*#__PURE__*/_interopDefaultLegacy(keyBy);
@@ -933,15 +933,34 @@ function getReadableSecurityName(securityScheme, includeKey = false) {
933
933
  case 'mutualTLS':
934
934
  name = 'Mutual TLS';
935
935
  break;
936
+ case undefined:
937
+ name = 'None';
938
+ break;
936
939
  }
937
940
  return includeKey ? `${name} (${securityScheme.key})` : name;
938
941
  }
942
+ function getReadableSecurityNames(securitySchemes, includeKey = false) {
943
+ if (securitySchemes.length === 0)
944
+ return 'None';
945
+ let name = '';
946
+ for (let i = 0; i < securitySchemes.length; i++) {
947
+ if (i > 0)
948
+ name += ' & ';
949
+ name += getReadableSecurityName(securitySchemes[i], shouldIncludeKey(securitySchemes, securitySchemes[i].type));
950
+ }
951
+ return includeKey ? `${name} (${securitySchemes[0].key})` : name;
952
+ }
939
953
  const isOAuth2ImplicitFlow = (maybeFlow) => isObject__default["default"](maybeFlow) && 'authorizationUrl' in maybeFlow && !('tokenUrl' in maybeFlow);
940
954
  const isOauth2AuthorizationCodeFlow = (maybeFlow) => isObject__default["default"](maybeFlow) && 'authorizationUrl' in maybeFlow && 'tokenUrl' in maybeFlow;
941
955
  const isOauth2ClientCredentialsOrPasswordFlow = (maybeFlow) => isObject__default["default"](maybeFlow) && !('authorizationUrl' in maybeFlow) && 'tokenUrl' in maybeFlow;
942
956
  function shouldIncludeKey(schemes, type) {
943
957
  return filter__default["default"](schemes, { type }).length > 1;
944
- }
958
+ }
959
+ const shouldAddKey = (auth, operationSecuritySchemes) => {
960
+ if (auth.length !== 1)
961
+ return false;
962
+ return shouldIncludeKey(flatten__default["default"](operationSecuritySchemes.filter(scheme => scheme.length === 1)), auth[0].type);
963
+ };
945
964
 
946
965
  const useUniqueId = (prefix = 'id_') => React__namespace.useRef(`${prefix}${nanoid.nanoid(8)}`).current;
947
966
 
@@ -955,16 +974,73 @@ const AuthTokenInput = ({ type, name, value, onChange }) => {
955
974
  };
956
975
 
957
976
  const APIKeyAuth = ({ scheme, onChange, value }) => {
958
- return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid" },
977
+ return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid", "data-test": "auth-try-it-row" },
959
978
  React__namespace.createElement(AuthTokenInput, { type: "apiKey", name: scheme.name, value: value, onChange: onChange })));
960
979
  };
961
980
 
981
+ const caseInsensitivelyEquals = curry__default["default"]((a, b) => a.toUpperCase() === b.toUpperCase());
982
+ function slugify(name) {
983
+ return name
984
+ .replace(/\/|{|}|\s/g, '-')
985
+ .replace(/-{2,}/, '-')
986
+ .replace(/^-/, '')
987
+ .replace(/-$/, '');
988
+ }
989
+
990
+ const isApiKeySecurityScheme = (maybeIApiKey) => isObject__default["default"](maybeIApiKey) && maybeIApiKey.type === 'apiKey';
991
+ const isOAuth2SecurityScheme = (maybeIOAuth2) => isObject__default["default"](maybeIOAuth2) && maybeIOAuth2.type === 'oauth2';
992
+ const isBasicSecurityScheme = (maybeIBasic) => isObject__default["default"](maybeIBasic) && maybeIBasic.type === 'http' && maybeIBasic.scheme === 'basic';
993
+ const isBearerSecurityScheme = (maybeIBearer) => isObject__default["default"](maybeIBearer) && maybeIBearer.type === 'http' && maybeIBearer.scheme === 'bearer';
994
+ const isDigestSecurityScheme = (maybeIBearer) => isObject__default["default"](maybeIBearer) && maybeIBearer.type === 'http' && maybeIBearer.scheme === 'digest';
995
+ function filterOutAuthorizationParams(queryParams, securitySchemes = []) {
996
+ const flattenedSecuritySchemes = flatten__default["default"](securitySchemes);
997
+ const securitySchemeNames = getSecuritySchemeNames(flattenedSecuritySchemes);
998
+ return queryParams.filter(queryParam => !securitySchemeNames.some(caseInsensitivelyEquals(queryParam.name)));
999
+ }
1000
+ const getSecuritySchemeNames = (securitySchemes) => securitySchemes.flatMap(scheme => {
1001
+ if (isApiKeySecurityScheme(scheme)) {
1002
+ return scheme.name;
1003
+ }
1004
+ if (isOAuth2SecurityScheme(scheme)) {
1005
+ return 'Authorization';
1006
+ }
1007
+ return [];
1008
+ });
1009
+ const securitySchemeValuesAtom = persistAtom('TryIt_securitySchemeValues', jotai.atom({}));
1010
+ const usePersistedSecuritySchemeWithValues = () => {
1011
+ const [currentScheme, setCurrentScheme] = React__default["default"].useState();
1012
+ const [securitySchemeValues, setSecuritySchemeValues] = jotai.useAtom(securitySchemeValuesAtom);
1013
+ const setPersistedAuthenticationSettings = (securitySchemeWithValues) => {
1014
+ if (securitySchemeWithValues) {
1015
+ const key = securitySchemeWithValues.scheme.key;
1016
+ const value = securitySchemeWithValues.authValue;
1017
+ if (value !== undefined) {
1018
+ setSecuritySchemeValues(Object.assign(Object.assign({}, securitySchemeValues), { [key]: value }));
1019
+ }
1020
+ }
1021
+ };
1022
+ const schemeWithPersistedValue = React__default["default"].useMemo(() => {
1023
+ if (!currentScheme)
1024
+ return undefined;
1025
+ return currentScheme.map(scheme => {
1026
+ return {
1027
+ scheme: scheme.scheme,
1028
+ authValue: securitySchemeValues[scheme.scheme.key],
1029
+ };
1030
+ });
1031
+ }, [currentScheme, securitySchemeValues]);
1032
+ return [schemeWithPersistedValue, setPersistedAuthenticationSettings, setCurrentScheme];
1033
+ };
1034
+ const createUndefinedValuedSchemes = (schemes) => {
1035
+ return schemes.map(scheme => ({ scheme, authValue: undefined }));
1036
+ };
1037
+
962
1038
  const BasicAuth = ({ onChange, value }) => {
963
1039
  const [username = '', password = ''] = decode(value).split(':');
964
1040
  const onCredentialsChange = (username, password) => {
965
1041
  onChange(encode(`${username}:${password}`));
966
1042
  };
967
- return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid" },
1043
+ return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid", "data-test": "auth-try-it-row" },
968
1044
  React__namespace.createElement("div", null, "Username"),
969
1045
  React__namespace.createElement(mosaic.Text, { mx: 3 }, ":"),
970
1046
  React__namespace.createElement(mosaic.Flex, { flex: 1 },
@@ -987,7 +1063,7 @@ function decode(encoded) {
987
1063
  }
988
1064
 
989
1065
  const BearerAuth = ({ value, onChange }) => {
990
- return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid" },
1066
+ return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid", "data-test": "auth-try-it-row" },
991
1067
  React__namespace.createElement(AuthTokenInput, { type: "http", name: "Token", value: value, onChange: onChange })));
992
1068
  };
993
1069
 
@@ -1002,63 +1078,78 @@ const digestPlaceholder = `Digest username="User Name",
1002
1078
  opaque="5ccc069c403ebaf9f0171e9517f40e41"
1003
1079
  `;
1004
1080
  const DigestAuth = ({ onChange, value }) => {
1005
- return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid" },
1081
+ return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid", "data-test": "auth-try-it-row" },
1006
1082
  React__namespace.createElement("div", null, "Authorization"),
1007
1083
  React__namespace.createElement(mosaic.Text, { mx: 3 }, ":"),
1008
1084
  React__namespace.createElement("textarea", { className: "sl-relative sl-z-10 sl-w-full sl-text-base sl-bg-canvas-100 sl-p-1 sl-pr-2.5 sl-pl-2.5 sl-rounded sl-border-transparent hover:sl-border-input focus:sl-border-primary sl-border", "aria-label": "Authorization", placeholder: digestPlaceholder, value: value, onChange: e => onChange(e.currentTarget.value), rows: 9 })));
1009
1085
  };
1010
1086
 
1011
1087
  const OAuth2Auth = ({ value, onChange }) => {
1012
- return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid" },
1088
+ return (React__namespace.createElement(mosaic.Panel.Content, { className: "ParameterGrid", "data-test": "auth-try-it-row" },
1013
1089
  React__namespace.createElement(AuthTokenInput, { type: "oauth2", name: "Token", value: value, onChange: onChange })));
1014
1090
  };
1015
1091
 
1016
- function getSupportedSecurityScheme(value, supportedSecuritySchemes) {
1017
- var _a;
1018
- if (value && supportedSecuritySchemes.some(s => value.scheme.id === s.id)) {
1019
- return [value.scheme, (_a = value.authValue) !== null && _a !== void 0 ? _a : ''];
1092
+ const checkViableCurrentAuth = (current, operationSecuritySchemes) => {
1093
+ if (current === undefined)
1094
+ return false;
1095
+ const flattened = operationSecuritySchemes.flat(1);
1096
+ for (const element of current) {
1097
+ if (!flattened.some(flat => flat.id === element.scheme.id))
1098
+ return false;
1020
1099
  }
1021
- return [supportedSecuritySchemes[0], ''];
1022
- }
1023
- const TryItAuth = ({ operationSecurityScheme: operationAuth, onChange, value }) => {
1024
- const operationSecurityArray = flatten__default["default"](operationAuth);
1025
- const filteredSecurityItems = operationSecurityArray.filter(scheme => securitySchemeKeys.includes(scheme === null || scheme === void 0 ? void 0 : scheme.type));
1026
- const [securityScheme, authValue] = getSupportedSecurityScheme(value, filteredSecurityItems);
1027
- const menuName = securityScheme ? getReadableSecurityName(securityScheme) : 'Security Scheme';
1028
- const handleChange = (authValue) => {
1029
- onChange(securityScheme && { scheme: securityScheme, authValue: authValue });
1100
+ return true;
1101
+ };
1102
+ const createMenuChild = (name, currentItemName, onPress) => {
1103
+ return {
1104
+ id: `security-scheme-${name}`,
1105
+ title: name,
1106
+ isChecked: name === currentItemName,
1107
+ onPress,
1108
+ };
1109
+ };
1110
+ const TryItAuth = ({ operationSecuritySchemes, operationAuthValue, setOperationAuthValue, setCurrentScheme, }) => {
1111
+ const filteredSecurityItems = operationSecuritySchemes.filter(auth => auth.length === 0 || auth.every(scheme => securitySchemeKeys.includes(scheme.type)));
1112
+ const menuName = operationAuthValue
1113
+ ? getReadableSecurityNames(operationAuthValue.map(auth => auth.scheme))
1114
+ : 'Security Scheme';
1115
+ const currentName = operationAuthValue
1116
+ ? getReadableSecurityNames(operationAuthValue.map(auth => auth.scheme), shouldAddKey(operationAuthValue.map(auth => auth.scheme), operationSecuritySchemes))
1117
+ : undefined;
1118
+ const handleChange = (scheme, authValue) => {
1119
+ setOperationAuthValue({ scheme, authValue });
1030
1120
  };
1031
1121
  React__namespace.useEffect(() => {
1032
- handleChange();
1033
- }, []);
1122
+ if (checkViableCurrentAuth(operationAuthValue, operationSecuritySchemes) === false) {
1123
+ setCurrentScheme(createUndefinedValuedSchemes(operationSecuritySchemes[0]));
1124
+ }
1125
+ });
1034
1126
  const menuItems = React__namespace.useMemo(() => {
1035
1127
  const items = [
1036
1128
  {
1037
1129
  type: 'group',
1038
1130
  title: 'Security Schemes',
1039
- children: filteredSecurityItems.map(auth => ({
1040
- id: `security-scheme-${auth.key}`,
1041
- title: getReadableSecurityName(auth, shouldIncludeKey(filteredSecurityItems, auth.type)),
1042
- isChecked: auth.key === (securityScheme === null || securityScheme === void 0 ? void 0 : securityScheme.key),
1043
- onPress: () => {
1044
- onChange({ scheme: auth, authValue: undefined });
1045
- },
1046
- })),
1131
+ children: filteredSecurityItems.map(auth => createMenuChild(getReadableSecurityNames(auth, shouldAddKey(auth, operationSecuritySchemes)), currentName, () => setCurrentScheme(createUndefinedValuedSchemes(auth)))),
1047
1132
  },
1048
1133
  ];
1049
1134
  return items;
1050
- }, [filteredSecurityItems, onChange, securityScheme]);
1135
+ }, [currentName, filteredSecurityItems, operationSecuritySchemes, setCurrentScheme]);
1051
1136
  if (filteredSecurityItems.length === 0)
1052
1137
  return null;
1053
- return (React__namespace.createElement(mosaic.Panel, { defaultIsOpen: true },
1138
+ return (React__namespace.createElement(mosaic.Panel, { defaultIsOpen: true, "data-test": "try-it-auth" },
1054
1139
  React__namespace.createElement(mosaic.Panel.Titlebar, { rightComponent: filteredSecurityItems.length > 1 && (React__namespace.createElement(mosaic.Menu, { "aria-label": "security-schemes", items: menuItems, closeOnPress: true, renderTrigger: ({ isOpen }) => (React__namespace.createElement(mosaic.Button, { appearance: "minimal", size: "sm", iconRight: ['fas', 'sort'], active: isOpen }, menuName)) })) }, "Auth"),
1055
- React__namespace.createElement(SecuritySchemeComponent, { scheme: securityScheme, onChange: handleChange, value: authValue })));
1140
+ operationAuthValue && operationAuthValue.length > 0 ? (operationAuthValue.map(scheme => {
1141
+ var _a;
1142
+ return (React__namespace.createElement(SecuritySchemeComponent, { key: scheme.scheme.key, scheme: scheme.scheme, onChange: (authValue) => handleChange(scheme.scheme, authValue), value: (_a = scheme.authValue) !== null && _a !== void 0 ? _a : '' }));
1143
+ })) : (React__namespace.createElement(OptionalMessageContainer, null))));
1056
1144
  };
1057
1145
  const GenericMessageContainer = ({ scheme }) => {
1058
- return React__namespace.createElement(mosaic.Panel.Content, null,
1146
+ return React__namespace.createElement(mosaic.Panel.Content, { "data-test": "auth-try-it-row" },
1059
1147
  "Coming Soon: ",
1060
1148
  getReadableSecurityName(scheme));
1061
1149
  };
1150
+ const OptionalMessageContainer = () => {
1151
+ return React__namespace.createElement(mosaic.Panel.Content, null, "No auth selected");
1152
+ };
1062
1153
  const SecuritySchemeComponent = (_a) => {
1063
1154
  var { scheme } = _a, rest = tslib.__rest(_a, ["scheme"]);
1064
1155
  switch (scheme.type) {
@@ -1083,59 +1174,6 @@ const SecuritySchemeComponent = (_a) => {
1083
1174
  };
1084
1175
  const securitySchemeKeys = ['apiKey', 'http', 'oauth2', 'openIdConnect'];
1085
1176
 
1086
- const caseInsensitivelyEquals = curry__default["default"]((a, b) => a.toUpperCase() === b.toUpperCase());
1087
- function slugify(name) {
1088
- return name
1089
- .replace(/\/|{|}|\s/g, '-')
1090
- .replace(/-{2,}/, '-')
1091
- .replace(/^-/, '')
1092
- .replace(/-$/, '');
1093
- }
1094
-
1095
- const isApiKeySecurityScheme = (maybeIApiKey) => isObject__default["default"](maybeIApiKey) && maybeIApiKey.type === 'apiKey';
1096
- const isOAuth2SecurityScheme = (maybeIOAuth2) => isObject__default["default"](maybeIOAuth2) && maybeIOAuth2.type === 'oauth2';
1097
- const isBasicSecurityScheme = (maybeIBasic) => isObject__default["default"](maybeIBasic) && maybeIBasic.type === 'http' && maybeIBasic.scheme === 'basic';
1098
- const isBearerSecurityScheme = (maybeIBearer) => isObject__default["default"](maybeIBearer) && maybeIBearer.type === 'http' && maybeIBearer.scheme === 'bearer';
1099
- const isDigestSecurityScheme = (maybeIBearer) => isObject__default["default"](maybeIBearer) && maybeIBearer.type === 'http' && maybeIBearer.scheme === 'digest';
1100
- function filterOutAuthorizationParams(queryParams, securitySchemes = []) {
1101
- const flattenedSecuritySchemes = flatten__default["default"](securitySchemes);
1102
- const securitySchemeNames = getSecuritySchemeNames(flattenedSecuritySchemes);
1103
- return queryParams.filter(queryParam => !securitySchemeNames.some(caseInsensitivelyEquals(queryParam.name)));
1104
- }
1105
- const getSecuritySchemeNames = (securitySchemes) => securitySchemes.flatMap(scheme => {
1106
- if (isApiKeySecurityScheme(scheme)) {
1107
- return scheme.name;
1108
- }
1109
- if (isOAuth2SecurityScheme(scheme)) {
1110
- return 'Authorization';
1111
- }
1112
- return [];
1113
- });
1114
- const securitySchemeValuesAtom = persistAtom('TryIt_securitySchemeValues', jotai.atom({}));
1115
- const usePersistedSecuritySchemeWithValues = () => {
1116
- const [currentScheme, setCurrentScheme] = React__default["default"].useState();
1117
- const [securitySchemeValues, setSecuritySchemeValues] = jotai.useAtom(securitySchemeValuesAtom);
1118
- const setPersistedAuthenticationSettings = (securitySchemeWithValues) => {
1119
- setCurrentScheme(securitySchemeWithValues);
1120
- if (securitySchemeWithValues) {
1121
- const key = securitySchemeWithValues.scheme.key;
1122
- const value = securitySchemeWithValues.authValue;
1123
- if (value !== undefined) {
1124
- setSecuritySchemeValues(Object.assign(Object.assign({}, securitySchemeValues), { [key]: value }));
1125
- }
1126
- }
1127
- };
1128
- const persistedSecuritySchemeValue = currentScheme && securitySchemeValues[currentScheme.scheme.key];
1129
- const schemeWithPersistedValue = React__default["default"].useMemo(() => {
1130
- if (!currentScheme)
1131
- return undefined;
1132
- if (currentScheme.authValue)
1133
- return currentScheme;
1134
- return Object.assign(Object.assign({}, currentScheme), { authValue: persistedSecuritySchemeValue });
1135
- }, [currentScheme, persistedSecuritySchemeValue]);
1136
- return [schemeWithPersistedValue, setPersistedAuthenticationSettings];
1137
- };
1138
-
1139
1177
  const FileUploadParameterEditor = ({ parameter, value, onChange }) => {
1140
1178
  var _a;
1141
1179
  const parameterDisplayName = `${parameter.name}${parameter.required ? '*' : ''}`;
@@ -1620,50 +1658,52 @@ function buildFetchRequest({ httpOperation, mediaTypeContent, bodyInput, paramet
1620
1658
  ];
1621
1659
  });
1622
1660
  }
1623
- const runAuthRequestEhancements = (auth, queryParams, headers) => {
1624
- var _a, _b, _c, _d, _e;
1625
- if (!auth)
1661
+ const runAuthRequestEhancements = (auths, queryParams, headers) => {
1662
+ if (!auths)
1626
1663
  return [queryParams, headers];
1627
1664
  const newQueryParams = [...queryParams];
1628
1665
  const newHeaders = [...headers];
1629
- if (isApiKeySecurityScheme(auth.scheme)) {
1630
- if (auth.scheme.in === 'query') {
1631
- newQueryParams.push({
1632
- name: auth.scheme.name,
1633
- value: (_a = auth.authValue) !== null && _a !== void 0 ? _a : '',
1666
+ auths.forEach(auth => {
1667
+ var _a, _b, _c, _d, _e;
1668
+ if (isApiKeySecurityScheme(auth.scheme)) {
1669
+ if (auth.scheme.in === 'query') {
1670
+ newQueryParams.push({
1671
+ name: auth.scheme.name,
1672
+ value: (_a = auth.authValue) !== null && _a !== void 0 ? _a : '',
1673
+ });
1674
+ }
1675
+ if (auth.scheme.in === 'header') {
1676
+ newHeaders.push({
1677
+ name: auth.scheme.name,
1678
+ value: (_b = auth.authValue) !== null && _b !== void 0 ? _b : '',
1679
+ });
1680
+ }
1681
+ }
1682
+ if (isOAuth2SecurityScheme(auth.scheme)) {
1683
+ newHeaders.push({
1684
+ name: 'Authorization',
1685
+ value: (_c = auth.authValue) !== null && _c !== void 0 ? _c : '',
1634
1686
  });
1635
1687
  }
1636
- if (auth.scheme.in === 'header') {
1688
+ if (isBearerSecurityScheme(auth.scheme)) {
1637
1689
  newHeaders.push({
1638
- name: auth.scheme.name,
1639
- value: (_b = auth.authValue) !== null && _b !== void 0 ? _b : '',
1690
+ name: 'Authorization',
1691
+ value: `Bearer ${auth.authValue}`,
1640
1692
  });
1641
1693
  }
1642
- }
1643
- if (isOAuth2SecurityScheme(auth.scheme)) {
1644
- newHeaders.push({
1645
- name: 'Authorization',
1646
- value: (_c = auth.authValue) !== null && _c !== void 0 ? _c : '',
1647
- });
1648
- }
1649
- if (isBearerSecurityScheme(auth.scheme)) {
1650
- newHeaders.push({
1651
- name: 'Authorization',
1652
- value: `Bearer ${auth.authValue}`,
1653
- });
1654
- }
1655
- if (isDigestSecurityScheme(auth.scheme)) {
1656
- newHeaders.push({
1657
- name: 'Authorization',
1658
- value: (_e = (_d = auth.authValue) === null || _d === void 0 ? void 0 : _d.replace(/\s\s+/g, ' ').trim()) !== null && _e !== void 0 ? _e : '',
1659
- });
1660
- }
1661
- if (isBasicSecurityScheme(auth.scheme)) {
1662
- newHeaders.push({
1663
- name: 'Authorization',
1664
- value: `Basic ${auth.authValue}`,
1665
- });
1666
- }
1694
+ if (isDigestSecurityScheme(auth.scheme)) {
1695
+ newHeaders.push({
1696
+ name: 'Authorization',
1697
+ value: (_e = (_d = auth.authValue) === null || _d === void 0 ? void 0 : _d.replace(/\s\s+/g, ' ').trim()) !== null && _e !== void 0 ? _e : '',
1698
+ });
1699
+ }
1700
+ if (isBasicSecurityScheme(auth.scheme)) {
1701
+ newHeaders.push({
1702
+ name: 'Authorization',
1703
+ value: `Basic ${auth.authValue}`,
1704
+ });
1705
+ }
1706
+ });
1667
1707
  return [newQueryParams, newHeaders];
1668
1708
  };
1669
1709
  function buildHarRequest({ httpOperation, bodyInput, parameterValues, serverVariableValues, mediaTypeContent, auth, mockData, chosenServer, corsProxy, }) {
@@ -2043,9 +2083,9 @@ const VariableEditor = ({ variable, value, onChange }) => {
2043
2083
  };
2044
2084
 
2045
2085
  const ServerVariables = ({ variables, values, onChangeValue }) => {
2046
- return (React__namespace.createElement(mosaic.Panel, { defaultIsOpen: true },
2086
+ return (React__namespace.createElement(mosaic.Panel, { defaultIsOpen: true, "data-test": "server-vars-try-it" },
2047
2087
  React__namespace.createElement(mosaic.Panel.Titlebar, null, "Server Variables"),
2048
- React__namespace.createElement(mosaic.Panel.Content, { className: "sl-overflow-y-auto ParameterGrid ServerVariablesContent" }, variables.map(variable => (React__namespace.createElement(VariableEditor, { key: variable.name, variable: variable, value: values[variable.name], onChange: (value) => {
2088
+ React__namespace.createElement(mosaic.Panel.Content, { className: "sl-overflow-y-auto ParameterGrid ServerVariablesContent" }, variables.map(variable => (React__namespace.createElement(VariableEditor, { key: variable.name, "data-test": "server-vars-try-it-row", variable: variable, value: values[variable.name], onChange: (value) => {
2049
2089
  const actualValue = String(value);
2050
2090
  onChangeValue(variable.enum || actualValue !== '' ? 'set' : 'unset', variable.name, actualValue);
2051
2091
  } }))))));
@@ -2053,7 +2093,7 @@ const ServerVariables = ({ variables, values, onChangeValue }) => {
2053
2093
 
2054
2094
  const defaultServers = [];
2055
2095
  const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embeddedInMd = false, tryItCredentialsPolicy, corsProxy, }) => {
2056
- var _a, _b, _c, _d, _e, _f, _g;
2096
+ var _a, _b, _c, _d, _e, _f;
2057
2097
  TryIt.displayName = 'TryIt';
2058
2098
  const isDark = mosaic.useThemeIsDark();
2059
2099
  const [response, setResponse] = React__namespace.useState();
@@ -2065,7 +2105,7 @@ const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embe
2065
2105
  const [mockingOptions, setMockingOptions] = useMockingOptions();
2066
2106
  const [bodyParameterValues, setBodyParameterValues, isAllowedEmptyValues, setAllowedEmptyValues, formDataState] = useBodyParameterState(mediaTypeContent);
2067
2107
  const [textRequestBody, setTextRequestBody] = useTextRequestBodyState(mediaTypeContent);
2068
- const [operationAuthValue, setOperationAuthValue] = usePersistedSecuritySchemeWithValues();
2108
+ const [operationAuthValue, setOperationAuthValue, setCurrentScheme] = usePersistedSecuritySchemeWithValues();
2069
2109
  const servers = React__namespace.useMemo(() => {
2070
2110
  return getServersToDisplay(httpOperation.servers || defaultServers, mockUrl, false);
2071
2111
  }, [httpOperation.servers, mockUrl]);
@@ -2173,10 +2213,10 @@ const TryIt = ({ httpOperation, mockUrl, onRequestChange, requestBodyIndex, embe
2173
2213
  });
2174
2214
  const isOnlySendButton = !((_d = httpOperation.security) === null || _d === void 0 ? void 0 : _d.length) && !allParameters.length && !formDataState.isFormDataBody && !mediaTypeContent;
2175
2215
  const tryItPanelContents = (React__namespace.createElement(React__namespace.Fragment, null,
2176
- ((_e = httpOperation.security) === null || _e === void 0 ? void 0 : _e.length) ? (React__namespace.createElement(TryItAuth, { onChange: setOperationAuthValue, operationSecurityScheme: (_f = httpOperation.security) !== null && _f !== void 0 ? _f : [], value: operationAuthValue })) : null,
2216
+ ((_e = httpOperation.security) === null || _e === void 0 ? void 0 : _e.length) ? (React__namespace.createElement(TryItAuth, { operationSecuritySchemes: httpOperation.security, operationAuthValue: operationAuthValue, setOperationAuthValue: setOperationAuthValue, setCurrentScheme: setCurrentScheme })) : null,
2177
2217
  serverVariables.length > 0 && (React__namespace.createElement(ServerVariables, { variables: serverVariables, values: serverVariableValues, onChangeValue: updateServerVariableValue })),
2178
2218
  allParameters.length > 0 && (React__namespace.createElement(OperationParameters, { parameters: allParameters, values: parameterValuesWithDefaults, onChangeValue: updateParameterValue, validate: validateParameters })),
2179
- formDataState.isFormDataBody ? (React__namespace.createElement(FormDataBody, { specification: formDataState.bodySpecification, values: bodyParameterValues, onChangeValues: setBodyParameterValues, onChangeParameterAllow: setAllowedEmptyValues, isAllowedEmptyValues: isAllowedEmptyValues })) : mediaTypeContent ? (React__namespace.createElement(RequestBody, { examples: (_g = mediaTypeContent.examples) !== null && _g !== void 0 ? _g : [], requestBody: textRequestBody, onChange: setTextRequestBody })) : null,
2219
+ formDataState.isFormDataBody ? (React__namespace.createElement(FormDataBody, { specification: formDataState.bodySpecification, values: bodyParameterValues, onChangeValues: setBodyParameterValues, onChangeParameterAllow: setAllowedEmptyValues, isAllowedEmptyValues: isAllowedEmptyValues })) : mediaTypeContent ? (React__namespace.createElement(RequestBody, { examples: (_f = mediaTypeContent.examples) !== null && _f !== void 0 ? _f : [], requestBody: textRequestBody, onChange: setTextRequestBody })) : null,
2180
2220
  React__namespace.createElement(mosaic.Panel.Content, { className: "SendButtonHolder", mt: 4, pt: !isOnlySendButton && !embeddedInMd ? 0 : undefined },
2181
2221
  React__namespace.createElement(mosaic.HStack, { alignItems: "center", spacing: 2 },
2182
2222
  React__namespace.createElement(mosaic.Button, { appearance: "primary", loading: loading, disabled: loading, onPress: handleSendRequest, size: "sm" }, "Send API Request"),
@@ -2459,7 +2499,7 @@ const Request = ({ operation: { request, request: { path: pathParams = [], heade
2459
2499
  if (!request || typeof request !== 'object')
2460
2500
  return null;
2461
2501
  const bodyIsEmpty = isBodyEmpty(body);
2462
- const securitySchemes = flatten__default["default"](security);
2502
+ const securitySchemes = security !== null && security !== void 0 ? security : [];
2463
2503
  const hasRequestData = Boolean(securitySchemes.length ||
2464
2504
  pathParams.length ||
2465
2505
  queryParams.length ||
@@ -2487,19 +2527,25 @@ const Request = ({ operation: { request, request: { path: pathParams = [], heade
2487
2527
  };
2488
2528
  Request.displayName = 'HttpOperation.Request';
2489
2529
  const schemeExpandedState = utils.atomWithStorage('HttpOperation_security_expanded', {});
2490
- const SecurityPanel = ({ scheme, includeKey }) => {
2530
+ const SecurityPanel = ({ schemes, includeKey }) => {
2491
2531
  const [expandedState, setExpanded] = jotai.useAtom(schemeExpandedState);
2492
- return (React__namespace.createElement(SubSectionPanel, { title: `Security: ${getReadableSecurityName(scheme, includeKey)}`, defaultIsOpen: !!expandedState[scheme.key], onChange: isOpen => setExpanded(Object.assign(Object.assign({}, expandedState), { [scheme.key]: isOpen })) },
2493
- React__namespace.createElement(MarkdownViewer, { style: { fontSize: 12 }, markdown: `${scheme.description || ''}\n\n` + getDefaultDescription(scheme) })));
2532
+ const { nodeHasChanged } = useOptionsCtx();
2533
+ const collection = schemes.length > 1;
2534
+ return (React__namespace.createElement(SubSectionPanel, { title: `Security: ${getReadableSecurityNames(schemes, includeKey)}`, defaultIsOpen: !!expandedState[getReadableSecurityNames(schemes)], onChange: isOpen => setExpanded(Object.assign(Object.assign({}, expandedState), { [getReadableSecurityNames(schemes)]: isOpen })) },
2535
+ React__namespace.createElement(mosaic.Box, { m: -2 }, schemes.map(scheme => {
2536
+ var _a;
2537
+ return (React__namespace.createElement(mosaic.Box, { key: scheme.key, p: 2, m: 2, border: true },
2538
+ collection && (React__namespace.createElement(MarkdownViewer, { style: { fontWeight: 'bold', fontSize: 12, marginBottom: 10 }, markdown: getReadableSecurityName(scheme, shouldIncludeKey(schemes, scheme.type)) })),
2539
+ React__namespace.createElement(MarkdownViewer, { style: { fontSize: 12 }, markdown: `${(_a = scheme.description) !== null && _a !== void 0 ? _a : ''}\n\n` + getDefaultDescription(scheme) }),
2540
+ React__namespace.createElement(mosaic.NodeAnnotation, { change: nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId: scheme.id }) })));
2541
+ }))));
2494
2542
  };
2495
2543
  const SecuritySchemes$1 = ({ schemes }) => {
2496
- const { nodeHasChanged } = useOptionsCtx();
2497
2544
  if (!schemes.length) {
2498
2545
  return null;
2499
2546
  }
2500
- return (React__namespace.createElement(mosaic.VStack, { spacing: 3 }, schemes.map((scheme, i) => (React__namespace.createElement(mosaic.Box, { pos: "relative", key: i },
2501
- React__namespace.createElement(SecurityPanel, { scheme: scheme, includeKey: shouldIncludeKey(schemes, scheme.type) }),
2502
- React__namespace.createElement(mosaic.NodeAnnotation, { change: nodeHasChanged === null || nodeHasChanged === void 0 ? void 0 : nodeHasChanged({ nodeId: scheme.id }) }))))));
2547
+ return (React__namespace.createElement(mosaic.VStack, { spacing: 3 }, schemes.map((scheme, i) => (React__namespace.createElement(mosaic.Box, { pos: "relative", key: i, p: 0, "data-test": "security-row" },
2548
+ React__namespace.createElement(SecurityPanel, { schemes: scheme, includeKey: shouldAddKey(scheme, schemes) }))))));
2503
2549
  };
2504
2550
 
2505
2551
  const Responses = ({ responses: unsortedResponses, onStatusCodeChange, onMediaTypeChange, isCompact, }) => {
@@ -2689,7 +2735,7 @@ const ExportButton = ({ original, bundled }) => {
2689
2735
  };
2690
2736
 
2691
2737
  const SecuritySchemes = ({ schemes, defaultScheme, defaultCollapsed = false, }) => {
2692
- return (React__default["default"].createElement(mosaic.Panel, { rounded: true, isCollapsible: defaultCollapsed },
2738
+ return (React__default["default"].createElement(mosaic.Panel, { rounded: true, isCollapsible: defaultCollapsed, "data-test": "security-row" },
2693
2739
  React__default["default"].createElement(mosaic.Panel.Titlebar, { bg: "canvas-300" },
2694
2740
  React__default["default"].createElement(mosaic.Box, { as: "span", role: "heading" }, "Security")),
2695
2741
  React__default["default"].createElement(mosaic.Panel.Content, { p: 0 }, sortBy__default["default"](schemes, 'type').map((scheme, i) => (React__default["default"].createElement(SecurityScheme, { key: i, scheme: scheme, defaultIsOpen: defaultScheme ? scheme.key === defaultScheme : i === 0, isCollapsible: schemes.length > 1, showSchemeKey: shouldIncludeKey(schemes, scheme.type) }))))));
@@ -2715,7 +2761,7 @@ const ServerInfo = ({ servers, mockUrl }) => {
2715
2761
  return null;
2716
2762
  }
2717
2763
  return (React__namespace.createElement(mosaic.InvertTheme, null,
2718
- React__namespace.createElement(mosaic.Panel, { rounded: true, isCollapsible: false, className: "BaseURLContent", w: "full" },
2764
+ React__namespace.createElement(mosaic.Panel, { rounded: true, isCollapsible: false, className: "BaseURLContent", w: "full", "data-test": "servers" },
2719
2765
  React__namespace.createElement(mosaic.Panel.Titlebar, { whitespace: "nowrap" }, "API Base URL"),
2720
2766
  React__namespace.createElement(mosaic.Panel.Content, { w: "full", className: "sl-flex sl-flex-col" },
2721
2767
  React__namespace.createElement(mosaic.VStack, { spacing: 1, divider: true }, serversToDisplay.map((server, index) => (React__namespace.createElement(ServerUrl, Object.assign({}, server, { defaultIsOpen: index === firstServerVariableIndex, hasAnyServerVariables: firstServerVariableIndex !== -1, key: server.id })))))))));
@@ -2731,7 +2777,7 @@ const ServerUrl = ({ id, description, url, variables, hasAnyServerVariables, def
2731
2777
  e.stopPropagation();
2732
2778
  onCopy();
2733
2779
  }, [onCopy]);
2734
- return (React__namespace.createElement(mosaic.Panel, { isCollapsible: !!variablesSchema, defaultIsOpen: defaultIsOpen, w: "full" },
2780
+ return (React__namespace.createElement(mosaic.Panel, { isCollapsible: !!variablesSchema, defaultIsOpen: defaultIsOpen, w: "full", "data-test": "server-row" },
2735
2781
  React__namespace.createElement(mosaic.Panel.Titlebar, { whitespace: "nowrap" },
2736
2782
  React__namespace.createElement(mosaic.Text, { pl: titlePaddingLeft, pr: 2, fontWeight: "bold" },
2737
2783
  description,
@@ -2823,8 +2869,8 @@ const HttpServiceComponent = React__namespace.memo(({ data: unresolvedData, loca
2823
2869
  pathname && (layoutOptions === null || layoutOptions === void 0 ? void 0 : layoutOptions.showPoweredByLink) && (React__namespace.createElement(PoweredByLink, { source: (_a = data.name) !== null && _a !== void 0 ? _a : 'no-title', pathname: pathname, packageType: "elements", layout: "stacked" })),
2824
2870
  React__namespace.createElement(mosaic.VStack, { spacing: 6 },
2825
2871
  React__namespace.createElement(ServerInfo, { servers: (_b = data.servers) !== null && _b !== void 0 ? _b : [], mockUrl: mocking.mockUrl }),
2826
- React__namespace.createElement(mosaic.Box, null, ((_c = data.securitySchemes) === null || _c === void 0 ? void 0 : _c.length) ? (React__namespace.createElement(SecuritySchemes, { schemes: data.securitySchemes, defaultScheme: query.get('security') || undefined })) : null),
2827
- React__namespace.createElement(mosaic.Box, null, (((_d = data.contact) === null || _d === void 0 ? void 0 : _d.email) || data.license || data.termsOfService) && (React__namespace.createElement(AdditionalInfo, { id: data.id, contact: data.contact, license: data.license, termsOfService: data.termsOfService })))),
2872
+ React__namespace.createElement(mosaic.Box, { "data-test": "security" }, ((_c = data.securitySchemes) === null || _c === void 0 ? void 0 : _c.length) ? (React__namespace.createElement(SecuritySchemes, { schemes: data.securitySchemes, defaultScheme: query.get('security') || undefined })) : null),
2873
+ React__namespace.createElement(mosaic.Box, { "data-test": "additional-info" }, (((_d = data.contact) === null || _d === void 0 ? void 0 : _d.email) || data.license || data.termsOfService) && (React__namespace.createElement(AdditionalInfo, { id: data.id, contact: data.contact, license: data.license, termsOfService: data.termsOfService })))),
2828
2874
  data.description && (React__namespace.createElement(mosaic.Box, { pos: "relative" },
2829
2875
  React__namespace.createElement(MarkdownViewer, { className: "sl-my-5", markdown: data.description }),
2830
2876
  React__namespace.createElement(mosaic.NodeAnnotation, { change: descriptionChanged })))));