@redocly/reference-docs 2.45.8 → 2.45.9

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.
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Console=void 0;var tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),informed_1=require("informed"),mobx_react_1=require("mobx-react"),swagger_client_1=(0,tslib_1.__importDefault)(require("swagger-client")),react_1=require("react"),utils_1=require("../../utils"),redoc_lib_1=require("../../redoc-lib"),RenderHook_1=require("../../redoc-lib/src/components/RenderHook"),Labels_1=require("../../redoc-lib/src/services/Labels"),Panel_1=require("../Panel"),OAuth2_1=require("../../services/OAuth2"),helper_1=require("../common/FileUpload/helper"),OperationParameters_1=require("../OperationParameters"),hooks_1=require("../../hooks"),events_1=require("../../events"),utils_2=require("../../services/utils"),utils_3=require("./utils"),AuthPanel_1=require("./AuthPanel"),ConsoleBadges_1=require("./ConsoleBadges"),RequestBody_1=require("./RequestBody"),ResponsePanel_1=require("./ResponsePanel"),ActionPanel_1=require("./ActionPanel"),ServersDropdown_1=require("./ServersDropdown"),TryItPanel_1=require("./TryItPanel"),styled_1=require("./styled");function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}var flexColumn={flex:1,display:"flex",flexDirection:"column"},Console=function(e){function t(t){var r=e.call(this,t)||this;return Object.defineProperty(r,"formApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"setFormApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.formApi=e;var t=e.getState(),s=t.values,i=(0,tslib_1.__rest)(t,["values"]);setTimeout((function(){var e=(0,tslib_1.__assign)((0,tslib_1.__assign)({},i),{values:(0,tslib_1.__assign)((0,tslib_1.__assign)({},s),{query:(0,utils_3.unescapeQueryParams)(s.query||{}),path:(0,utils_3.unescapeQueryParams)(s.path||{})})});r.setState({form:e})}),0)}}),Object.defineProperty(r,"handleValueChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=(0,tslib_1.__assign)((0,tslib_1.__assign)({},e),{query:(0,utils_3.unescapeQueryParams)(e.query||{}),path:(0,utils_3.unescapeQueryParams)(e.path||{})});r.setState((function(e){return{form:(0,tslib_1.__assign)((0,tslib_1.__assign)({},e.form),{values:t})}}),(function(){(0,utils_3.updateStorage)(r.state.form),r.props.operation.setRequestValues(e)}))}}),Object.defineProperty(r,"handleTabChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({activeTab:e})}}),Object.defineProperty(r,"handleServerChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({server:e}),r.props.operation.setActiveServer(e)}}),Object.defineProperty(r,"handleExecute",{enumerable:!0,configurable:!0,writable:!0,value:function(){return(0,tslib_1.__awaiter)(r,void 0,void 0,(function(){var e,t,r,s,i,o,n,a,l,u,_,d,c,p,h,v,m,b,y,g,f,x,j,P,q,S,A,C,k,w,I,O,T,R,B,H,F,V,D,E,U,N,L,W=this;return(0,tslib_1.__generator)(this,(function(z){switch(z.label){case 0:if(e=this.props,t=e.store,r=e.operation,s=e.onResponse,null===(R=this.formApi)||void 0===R||R.submitForm(),((null===(B=this.formApi)||void 0===B?void 0:B.getState())||this.state.form).invalid)return this.setState({shaking:!0}),setTimeout((function(){return W.setState({shaking:!1})}),1e3),null===(F=null===(H=null==t?void 0:t.options.events)||void 0===H?void 0:H.tryItSent)||void 0===F||F.call(H,{eventType:events_1.AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"ValidationFailed",operationId:r.operationId,operationPath:r.path,operationHttpVerb:r.httpVerb,operationSummary:r.description}),[2];if(i=((null===(V=this.formApi)||void 0===V?void 0:V.getState())||this.state.form).values,o=this.props.operation,n=o.servers,a=o.requestBody,l=a&&a.content&&a.content.active&&a.content.active.name||"",u=i.body,/json/.test(l))try{u=JSON.parse(u)}catch(e){console.error(e)}if(this.setState({loading:!0}),_=this.state.resolvedRawSpec,d=(r.httpVerb||"").toLowerCase(),!n)throw console.error("Servers are not specified in your OpenAPI file. You can't use Try It Out console without specifying servers. If you use OpenAPI 2, make sure you configured host and basepath"),new Error("Servers are not specified");c=n.find((function(e){return W.state.server.url.endsWith(e.url.endsWith("/")?e.url.substring(0,e.url.length-1):e.url)})),p=Date.now(),v=i.auth,!(0,utils_2.isEmptyObject)(i.auth)&&i.auth?(m=Object.keys(i.auth)[0],b=(0,utils_1.unescapeFormId)(m),h=(0,tslib_1.__assign)((0,tslib_1.__assign)({},_),{components:(0,tslib_1.__assign)((0,tslib_1.__assign)({},null==_?void 0:_.components),{securitySchemes:(0,tslib_1.__assign)((0,tslib_1.__assign)({},null==_?void 0:_.components.securitySchemes),(w={},w[b]=(0,tslib_1.__assign)((0,tslib_1.__assign)({},null==_?void 0:_.components.securitySchemes[b]),{type:"openIdConnect"===(null==_?void 0:_.components.securitySchemes[b].type)?"oauth2":null==_?void 0:_.components.securitySchemes[b].type}),w))})}),y="cookie"===(null==_?void 0:_.components.securitySchemes[b].in)?"Cookie":b,g="cookie"===(null==_?void 0:_.components.securitySchemes[b].in)?(null==_?void 0:_.components.securitySchemes[b].name)+"="+v[m]:v[m],v=(0,tslib_1.__assign)((0,tslib_1.__assign)({},v),((I={})[y]=g,I))):h=(0,tslib_1.__assign)({},_),h.servers=n,(f=t.options.corsProxyUrl)&&n.length&&(h.servers=n.map((function(e){return(0,tslib_1.__assign)((0,tslib_1.__assign)({},e),{url:f+normalizeUrlProtocol(e.url)})})),h.paths=(0,tslib_1.__assign)((0,tslib_1.__assign)({},h.paths),((O={})[r.path]=(0,tslib_1.__assign)((0,tslib_1.__assign)({},h.paths[r.path]),((T={})[d]=(0,tslib_1.__assign)((0,tslib_1.__assign)({},h.paths[r.path][d]),{servers:void 0}),T.servers=void 0,T)),O))),(x=(null===(E=null===(D=null==a?void 0:a.content)||void 0===D?void 0:D.active)||void 0===E?void 0:E.name)||null)&&u&&(0,helper_1.isFileUploadMime)(x)&&(j=Object.values(u),u=j.length>1?j:j[0]),P={server:f?f+normalizeUrlProtocol(c.url):c.url,serverVariables:this.state.server.variables,spec:h,pathName:r.path,method:r.httpVerb,parameters:(0,tslib_1.__assign)((0,tslib_1.__assign)((0,tslib_1.__assign)((0,tslib_1.__assign)({},i.path),i.query),i.header),i.cookie),securities:{authorized:v},requestBody:u,requestContentType:x,responseContentType:(null===(U=i.header)||void 0===U?void 0:U.Accept)||null,requestInterceptor:(0,utils_3.makeRequestInterceptor)(t.options,r,v,i)},z.label=1;case 1:return z.trys.push([1,5,8,9]),[4,swagger_client_1.default.execute(P)];case 2:return q=z.sent(),(S=null==q?void 0:q.data)instanceof Blob?((0,helper_1.isFileUploadMime)(S.type)&&(q.fileInfo={rawData:S,fileName:(0,utils_3.getFileNameFromHeaders)(q.headers)}),A=q,[4,S.text()]):[3,4];case 3:A.data=z.sent(),z.label=4;case 4:return null==s||s({request:P,response:q}),this.setState({response:q,error:void 0}),[3,9];case 5:return(C=z.sent())&&C.response&&C.response.data instanceof Blob?(k=C.response,[4,C.response.data.text()]):[3,7];case 6:k.data=z.sent(),null==s||s({request:P,response:C.response}),z.label=7;case 7:return this.setState({response:void 0,error:C}),[3,9];case 8:return this.setState({loading:!1,activeTab:1,time:Date.now()-p}),null===(L=null===(N=null==t?void 0:t.options.events)||void 0===N?void 0:N.tryItSent)||void 0===L||L.call(N,{eventType:events_1.AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"Sent",operationId:r.operationId,operationPath:r.path,operationHttpVerb:r.httpVerb,operationSummary:r.description}),[7];case 9:return[2]}}))}))}}),r.state={form:{values:{path:(0,utils_3.getParameters)(t.operation.parameters,"path"),cookie:(0,utils_3.getParameters)(t.operation.parameters,"cookie"),header:(0,utils_3.getParameters)(t.operation.parameters,"header"),query:(0,utils_3.getParameters)(t.operation.parameters,"query")}},shaking:!1,loading:!1,activeTab:0,server:{}},r}return(0,tslib_1.__extends)(t,e),Object.defineProperty(t.prototype,"componentDidMount",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e;return(0,tslib_1.__awaiter)(this,void 0,void 0,(function(){var t,r,s,i;return(0,tslib_1.__generator)(this,(function(o){switch(o.label){case 0:return t=this.props,r=t.store,s=t.operation,[4,r.dereferenceSpecForTryIt(s)];case 1:return i=o.sent(),this.setState({resolvedRawSpec:i}),null===(e=this.formApi)||void 0===e||e.setValues({}),[2]}}))}))}}),Object.defineProperty(t.prototype,"componentDidUpdate",{enumerable:!1,configurable:!0,writable:!0,value:function(e){e.operation!==this.props.operation&&this.setState({response:void 0,error:void 0,activeTab:0})}}),Object.defineProperty(t.prototype,"render",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.props,t=e.operation,r=e.className,s=e.rootElement,i=this.state,o=i.shaking,n=i.activeTab,a=i.form,l=i.response,u=i.loading,_=i.error,d=!(!l&&!_);return(0,jsx_runtime_1.jsxs)(ConsoleWrapHook,(0,tslib_1.__assign)({shaking:o,className:r,rootElement:s},{children:[(0,jsx_runtime_1.jsxs)(Panel_1.CodeHeader,{children:[(0,jsx_runtime_1.jsx)(ConsoleBadges_1.ConsoleBadges,{active:n,hasResponse:d,onChange:this.handleTabChange},void 0),this.props.onClose&&(0,jsx_runtime_1.jsx)(styled_1.CloseButton,(0,tslib_1.__assign)({onClick:this.props.onClose},{children:" ✕ "}),void 0)]},void 0),(0,jsx_runtime_1.jsx)(styled_1.ConsoleBody,(0,tslib_1.__assign)({hidden:0!==n,"data-cy":"console-request-body"},{children:this.renderRequest()}),void 0),(0,jsx_runtime_1.jsx)(styled_1.ConsoleBody,(0,tslib_1.__assign)({hidden:1!==n,"data-cy":"console-response-body"},{children:this.renderResponse()}),void 0),(0,jsx_runtime_1.jsx)(ActionPanel_1.ActionPanel,{hasResponse:d,params:a.values,operation:t,loading:u,execute:this.handleExecute},void 0)]}),void 0)}}),Object.defineProperty(t.prototype,"renderRequest",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e,t=this.props,r=t.operation,s=t.store,i=t.properties,o=t.securityDefaults,n=this.state,a=n.form,l=n.resolvedRawSpec,u=n.server,_=a.errors||{},d=_.path||_.cookie||_.header||_.query,c=l&&redoc_lib_1.JsonPointer.get(l,r.pointer),p=a.values&&a.values.auth&&Object.keys(a.values.auth)[0];p&&a.values.auth[p]||(p=void 0),!p||void 0===a.values.auth[p].token&&void 0===a.values.auth[p].client_id&&void 0===a.values.auth[p].client_secret||a.values.auth[p].token&&a.values.auth[p].token.access_token||(p=void 0),p&&null!=a.values.auth[p].username&&(a.values.auth[p].username&&a.values.auth[p].password||(p=void 0));var h=r.parameters||[],v=null===(e=null==s?void 0:s.options.hooks)||void 0===e?void 0:e.ReplaceTryItSecurityPanel;return!l&&(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:"Loading..."},void 0)||(0,jsx_runtime_1.jsxs)(informed_1.Form,(0,tslib_1.__assign)({onValueChange:this.handleValueChange,getApi:this.setFormApi,style:(0,tslib_1.__assign)((0,tslib_1.__assign)({},flexColumn),{margin:0})},{children:[(0,jsx_runtime_1.jsx)(ServersDropdown_1.ServersDropdown,{operation:r,onChange:this.handleServerChange},void 0),(0,jsx_runtime_1.jsxs)(Panel_1.Accordion,(0,tslib_1.__assign)({initialActiveIdx:r.security.length&&p?1:0},{children:[r.security.length&&this.formApi&&(0,jsx_runtime_1.jsx)(TryItPanel_1.TryItPanel,(0,tslib_1.__assign)({header:(0,Labels_1.l)("tryItAuth"),"data-cy":"security-trigger",renderChildrenHidden:!0,error:!p&&!!_.auth,success:!!p},{children:v?(0,jsx_runtime_1.jsx)(AuthPanelHook,(0,tslib_1.__assign)({field:"auth",validate:AuthPanel_1.requiredValidator},{children:function(e){return(0,jsx_runtime_1.jsx)(RenderHook_1.RenderHook,{Hook:v,props:{server:u,operation:r,onChange:e,OAuth2:OAuth2_1.OAuth2}},void 0)}}),void 0):(0,jsx_runtime_1.jsx)(AuthPanel_1.AuthPanel,{formApi:this.formApi,form:a,operation:r,activeServer:u.url,authCorsProxyUrl:s.options.authCorsProxyUrl,securityDefaults:o},void 0)}),void 0)||null,r.requestBody&&this.formApi&&(0,jsx_runtime_1.jsx)(TryItPanel_1.TryItPanel,(0,tslib_1.__assign)({header:(0,Labels_1.l)("tryItBody"),"data-cy":"body-trigger",renderChildrenHidden:!0,error:!!_.body},{children:(0,jsx_runtime_1.jsx)(RequestBody_1.RequestBody,{validate:allowBodyErrors,formApi:this.formApi,body:r.requestBody,id:r.id,resolvedBody:null==c?void 0:c.requestBody,properties:i},void 0)}),void 0)||null,h.length&&(0,jsx_runtime_1.jsx)(TryItPanel_1.TryItPanel,(0,tslib_1.__assign)({header:(0,Labels_1.l)("tryItParameters"),"data-cy":"parameters-trigger",error:d,renderChildrenHidden:!0},{children:(0,jsx_runtime_1.jsx)(OperationParameters_1.OperationParameters,{operation:r,values:a.values,errors:a.errors||{}},void 0)}),void 0)||null]}),void 0)]}),void 0)}}),Object.defineProperty(t.prototype,"renderResponse",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.state,t=e.response,r=e.error,s=e.time;return(0,jsx_runtime_1.jsx)(ResponsePanel_1.ResponsePanel,{response:t,error:r,time:s},void 0)}}),t=(0,tslib_1.__decorate)([mobx_react_1.observer],t)}(react_1.Component);function allowBodyErrors(){}function ConsoleWrapHook(e){var t=e.shaking,r=e.className,s=e.children,i=e.rootElement,o=(0,hooks_1.useDimensions)(i)[0];return(0,jsx_runtime_1.jsx)(styled_1.ConsoleWrap,(0,tslib_1.__assign)({shaking:t,className:r,"data-cy":"console",fullWidth:null==o?void 0:o.width},{children:s}),void 0)}function AuthPanelHook(e){var t=(0,informed_1.useField)((0,tslib_1.__assign)({},e)),r=t.fieldApi,s=t.render,i=t.userProps,o=r.setValue,n=i.children;return s((0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:n(o)},void 0))}exports.Console=Console;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Console=void 0;var tslib_1=require("tslib"),jsx_runtime_1=require("react/jsx-runtime"),informed_1=require("informed"),mobx_react_1=require("mobx-react"),swagger_client_1=(0,tslib_1.__importDefault)(require("swagger-client")),react_1=require("react"),utils_1=require("../../utils"),redoc_lib_1=require("../../redoc-lib"),RenderHook_1=require("../../redoc-lib/src/components/RenderHook"),Labels_1=require("../../redoc-lib/src/services/Labels"),Panel_1=require("../Panel"),OAuth2_1=require("../../services/OAuth2"),helper_1=require("../common/FileUpload/helper"),OperationParameters_1=require("../OperationParameters"),hooks_1=require("../../hooks"),events_1=require("../../events"),utils_2=require("../../services/utils"),utils_3=require("./utils"),AuthPanel_1=require("./AuthPanel"),ConsoleBadges_1=require("./ConsoleBadges"),RequestBody_1=require("./RequestBody"),ResponsePanel_1=require("./ResponsePanel"),ActionPanel_1=require("./ActionPanel"),ServersDropdown_1=require("./ServersDropdown"),TryItPanel_1=require("./TryItPanel"),styled_1=require("./styled");function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}var flexColumn={flex:1,display:"flex",flexDirection:"column"},Console=function(e){function t(t){var r=e.call(this,t)||this;return Object.defineProperty(r,"formApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(r,"setFormApi",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.formApi=e;var t=e.getState(),s=t.values,i=(0,tslib_1.__rest)(t,["values"]);setTimeout((function(){var e=(0,tslib_1.__assign)((0,tslib_1.__assign)({},i),{values:(0,tslib_1.__assign)((0,tslib_1.__assign)({},s),{query:(0,utils_3.unescapeQueryParams)(s.query||{}),path:(0,utils_3.unescapeQueryParams)(s.path||{})})});r.setState({form:e})}),0)}}),Object.defineProperty(r,"handleValueChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){var t=(0,tslib_1.__assign)((0,tslib_1.__assign)({},e),{query:(0,utils_3.unescapeQueryParams)(e.query||{}),path:(0,utils_3.unescapeQueryParams)(e.path||{})});r.setState((function(e){return{form:(0,tslib_1.__assign)((0,tslib_1.__assign)({},e.form),{values:t})}}),(function(){(0,utils_3.updateStorage)(r.state.form),r.props.operation.setRequestValues(e)}))}}),Object.defineProperty(r,"handleTabChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({activeTab:e})}}),Object.defineProperty(r,"handleServerChange",{enumerable:!0,configurable:!0,writable:!0,value:function(e){r.setState({server:e}),r.props.operation.setActiveServer(e)}}),Object.defineProperty(r,"handleExecute",{enumerable:!0,configurable:!0,writable:!0,value:function(){return(0,tslib_1.__awaiter)(r,void 0,void 0,(function(){var e,t,r,s,i,o,n,a,l,u,_,d,c,p,h,v,m,b,y,g,f,x,j,P,q,S,A,C,k,w,I,O,T,R,B,H,D,F,V,E,U,N,L,W=this;return(0,tslib_1.__generator)(this,(function(z){switch(z.label){case 0:if(e=this.props,t=e.store,r=e.operation,s=e.onResponse,null===(R=this.formApi)||void 0===R||R.submitForm(),((null===(B=this.formApi)||void 0===B?void 0:B.getState())||this.state.form).invalid)return this.setState({shaking:!0}),setTimeout((function(){return W.setState({shaking:!1})}),1e3),null===(D=null===(H=null==t?void 0:t.options.events)||void 0===H?void 0:H.tryItSent)||void 0===D||D.call(H,{eventType:events_1.AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"ValidationFailed",operationId:r.operationId,operationPath:r.path,operationHttpVerb:r.httpVerb,operationSummary:r.description}),[2];if(i=((null===(F=this.formApi)||void 0===F?void 0:F.getState())||this.state.form).values,o=this.props.operation,n=o.servers,a=o.requestBody,l=a&&a.content&&a.content.active&&a.content.active.name||"",u=i.body,/json/.test(l))try{u=JSON.parse(u)}catch(e){console.error(e)}if(this.setState({loading:!0}),_=this.state.resolvedRawSpec,d=(r.httpVerb||"").toLowerCase(),!n)throw console.error("Servers are not specified in your OpenAPI file. You can't use Try It Out console without specifying servers. If you use OpenAPI 2, make sure you configured host and basepath"),new Error("Servers are not specified");c=n.find((function(e){return W.state.server.url.endsWith(e.url.endsWith("/")?e.url.substring(0,e.url.length-1):e.url)})),p=Date.now(),v=i.auth,!(0,utils_2.isEmptyObject)(i.auth)&&i.auth?(m=Object.keys(i.auth)[0],b=(0,utils_1.unescapeFormId)(m),h=(0,tslib_1.__assign)((0,tslib_1.__assign)({},_),{components:(0,tslib_1.__assign)((0,tslib_1.__assign)({},null==_?void 0:_.components),{securitySchemes:(0,tslib_1.__assign)((0,tslib_1.__assign)({},null==_?void 0:_.components.securitySchemes),(w={},w[b]=(0,tslib_1.__assign)((0,tslib_1.__assign)({},null==_?void 0:_.components.securitySchemes[b]),{type:"openIdConnect"===(null==_?void 0:_.components.securitySchemes[b].type)?"oauth2":null==_?void 0:_.components.securitySchemes[b].type}),w))})}),y="cookie"===(null==_?void 0:_.components.securitySchemes[b].in)?"Cookie":b,g="cookie"===(null==_?void 0:_.components.securitySchemes[b].in)?(null==_?void 0:_.components.securitySchemes[b].name)+"="+v[m]:v[m],v=(0,tslib_1.__assign)((0,tslib_1.__assign)({},v),((I={})[y]=g,I))):h=(0,tslib_1.__assign)({},_),h.servers=n,(f=t.options.corsProxyUrl)&&n.length&&(h.servers=n.map((function(e){return(0,tslib_1.__assign)((0,tslib_1.__assign)({},e),{url:f+normalizeUrlProtocol(e.url)})})),h.paths=(0,tslib_1.__assign)((0,tslib_1.__assign)({},h.paths),((O={})[r.path]=(0,tslib_1.__assign)((0,tslib_1.__assign)({},h.paths[r.path]),((T={})[d]=(0,tslib_1.__assign)((0,tslib_1.__assign)({},h.paths[r.path][d]),{servers:void 0}),T.servers=void 0,T)),O))),(x=(null===(E=null===(V=null==a?void 0:a.content)||void 0===V?void 0:V.active)||void 0===E?void 0:E.name)||null)&&u&&(0,helper_1.isFileUploadMime)(x)&&(j=Object.values(u),u=j.length>1?j:j[0]),P={server:f?f+normalizeUrlProtocol(c.url):c.url,serverVariables:this.state.server.variables,spec:h,pathName:r.path,method:r.httpVerb,parameters:(0,tslib_1.__assign)((0,tslib_1.__assign)((0,tslib_1.__assign)((0,tslib_1.__assign)({},i.path),(0,utils_3.decodeKeysDeep)(i.query)),i.header),i.cookie),securities:{authorized:v},requestBody:u,requestContentType:x,responseContentType:(null===(U=i.header)||void 0===U?void 0:U.Accept)||null,requestInterceptor:(0,utils_3.makeRequestInterceptor)(t.options,r,v,i)},z.label=1;case 1:return z.trys.push([1,5,8,9]),[4,swagger_client_1.default.execute(P)];case 2:return q=z.sent(),(S=null==q?void 0:q.data)instanceof Blob?((0,helper_1.isFileUploadMime)(S.type)&&(q.fileInfo={rawData:S,fileName:(0,utils_3.getFileNameFromHeaders)(q.headers)}),A=q,[4,S.text()]):[3,4];case 3:A.data=z.sent(),z.label=4;case 4:return null==s||s({request:P,response:q}),this.setState({response:q,error:void 0}),[3,9];case 5:return(C=z.sent())&&C.response&&C.response.data instanceof Blob?(k=C.response,[4,C.response.data.text()]):[3,7];case 6:k.data=z.sent(),null==s||s({request:P,response:C.response}),z.label=7;case 7:return this.setState({response:void 0,error:C}),[3,9];case 8:return this.setState({loading:!1,activeTab:1,time:Date.now()-p}),null===(L=null===(N=null==t?void 0:t.options.events)||void 0===N?void 0:N.tryItSent)||void 0===L||L.call(N,{eventType:events_1.AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"Sent",operationId:r.operationId,operationPath:r.path,operationHttpVerb:r.httpVerb,operationSummary:r.description}),[7];case 9:return[2]}}))}))}}),r.state={form:{values:{path:(0,utils_3.getParameters)(t.operation.parameters,"path"),cookie:(0,utils_3.getParameters)(t.operation.parameters,"cookie"),header:(0,utils_3.getParameters)(t.operation.parameters,"header"),query:(0,utils_3.getParameters)(t.operation.parameters,"query")}},shaking:!1,loading:!1,activeTab:0,server:{}},r}return(0,tslib_1.__extends)(t,e),Object.defineProperty(t.prototype,"componentDidMount",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e;return(0,tslib_1.__awaiter)(this,void 0,void 0,(function(){var t,r,s,i;return(0,tslib_1.__generator)(this,(function(o){switch(o.label){case 0:return t=this.props,r=t.store,s=t.operation,[4,r.dereferenceSpecForTryIt(s)];case 1:return i=o.sent(),this.setState({resolvedRawSpec:i}),null===(e=this.formApi)||void 0===e||e.setValues({}),[2]}}))}))}}),Object.defineProperty(t.prototype,"componentDidUpdate",{enumerable:!1,configurable:!0,writable:!0,value:function(e){e.operation!==this.props.operation&&this.setState({response:void 0,error:void 0,activeTab:0})}}),Object.defineProperty(t.prototype,"render",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.props,t=e.operation,r=e.className,s=e.rootElement,i=this.state,o=i.shaking,n=i.activeTab,a=i.form,l=i.response,u=i.loading,_=i.error,d=!(!l&&!_);return(0,jsx_runtime_1.jsxs)(ConsoleWrapHook,(0,tslib_1.__assign)({shaking:o,className:r,rootElement:s},{children:[(0,jsx_runtime_1.jsxs)(Panel_1.CodeHeader,{children:[(0,jsx_runtime_1.jsx)(ConsoleBadges_1.ConsoleBadges,{active:n,hasResponse:d,onChange:this.handleTabChange},void 0),this.props.onClose&&(0,jsx_runtime_1.jsx)(styled_1.CloseButton,(0,tslib_1.__assign)({onClick:this.props.onClose},{children:" ✕ "}),void 0)]},void 0),(0,jsx_runtime_1.jsx)(styled_1.ConsoleBody,(0,tslib_1.__assign)({hidden:0!==n,"data-cy":"console-request-body"},{children:this.renderRequest()}),void 0),(0,jsx_runtime_1.jsx)(styled_1.ConsoleBody,(0,tslib_1.__assign)({hidden:1!==n,"data-cy":"console-response-body"},{children:this.renderResponse()}),void 0),(0,jsx_runtime_1.jsx)(ActionPanel_1.ActionPanel,{hasResponse:d,params:a.values,operation:t,loading:u,execute:this.handleExecute},void 0)]}),void 0)}}),Object.defineProperty(t.prototype,"renderRequest",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e,t=this.props,r=t.operation,s=t.store,i=t.properties,o=t.securityDefaults,n=this.state,a=n.form,l=n.resolvedRawSpec,u=n.server,_=a.errors||{},d=_.path||_.cookie||_.header||_.query,c=l&&redoc_lib_1.JsonPointer.get(l,r.pointer),p=a.values&&a.values.auth&&Object.keys(a.values.auth)[0];p&&a.values.auth[p]||(p=void 0),!p||void 0===a.values.auth[p].token&&void 0===a.values.auth[p].client_id&&void 0===a.values.auth[p].client_secret||a.values.auth[p].token&&a.values.auth[p].token.access_token||(p=void 0),p&&null!=a.values.auth[p].username&&(a.values.auth[p].username&&a.values.auth[p].password||(p=void 0));var h=r.parameters||[],v=null===(e=null==s?void 0:s.options.hooks)||void 0===e?void 0:e.ReplaceTryItSecurityPanel;return!l&&(0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:"Loading..."},void 0)||(0,jsx_runtime_1.jsxs)(informed_1.Form,(0,tslib_1.__assign)({onValueChange:this.handleValueChange,getApi:this.setFormApi,style:(0,tslib_1.__assign)((0,tslib_1.__assign)({},flexColumn),{margin:0})},{children:[(0,jsx_runtime_1.jsx)(ServersDropdown_1.ServersDropdown,{operation:r,onChange:this.handleServerChange},void 0),(0,jsx_runtime_1.jsxs)(Panel_1.Accordion,(0,tslib_1.__assign)({initialActiveIdx:r.security.length&&p?1:0},{children:[r.security.length&&this.formApi&&(0,jsx_runtime_1.jsx)(TryItPanel_1.TryItPanel,(0,tslib_1.__assign)({header:(0,Labels_1.l)("tryItAuth"),"data-cy":"security-trigger",renderChildrenHidden:!0,error:!p&&!!_.auth,success:!!p},{children:v?(0,jsx_runtime_1.jsx)(AuthPanelHook,(0,tslib_1.__assign)({field:"auth",validate:AuthPanel_1.requiredValidator},{children:function(e){return(0,jsx_runtime_1.jsx)(RenderHook_1.RenderHook,{Hook:v,props:{server:u,operation:r,onChange:e,OAuth2:OAuth2_1.OAuth2}},void 0)}}),void 0):(0,jsx_runtime_1.jsx)(AuthPanel_1.AuthPanel,{formApi:this.formApi,form:a,operation:r,activeServer:u.url,authCorsProxyUrl:s.options.authCorsProxyUrl,securityDefaults:o},void 0)}),void 0)||null,r.requestBody&&this.formApi&&(0,jsx_runtime_1.jsx)(TryItPanel_1.TryItPanel,(0,tslib_1.__assign)({header:(0,Labels_1.l)("tryItBody"),"data-cy":"body-trigger",renderChildrenHidden:!0,error:!!_.body},{children:(0,jsx_runtime_1.jsx)(RequestBody_1.RequestBody,{validate:allowBodyErrors,formApi:this.formApi,body:r.requestBody,id:r.id,resolvedBody:null==c?void 0:c.requestBody,properties:i},void 0)}),void 0)||null,h.length&&(0,jsx_runtime_1.jsx)(TryItPanel_1.TryItPanel,(0,tslib_1.__assign)({header:(0,Labels_1.l)("tryItParameters"),"data-cy":"parameters-trigger",error:d,renderChildrenHidden:!0},{children:(0,jsx_runtime_1.jsx)(OperationParameters_1.OperationParameters,{operation:r,values:a.values,errors:a.errors||{}},void 0)}),void 0)||null]}),void 0)]}),void 0)}}),Object.defineProperty(t.prototype,"renderResponse",{enumerable:!1,configurable:!0,writable:!0,value:function(){var e=this.state,t=e.response,r=e.error,s=e.time;return(0,jsx_runtime_1.jsx)(ResponsePanel_1.ResponsePanel,{response:t,error:r,time:s},void 0)}}),t=(0,tslib_1.__decorate)([mobx_react_1.observer],t)}(react_1.Component);function allowBodyErrors(){}function ConsoleWrapHook(e){var t=e.shaking,r=e.className,s=e.children,i=e.rootElement,o=(0,hooks_1.useDimensions)(i)[0];return(0,jsx_runtime_1.jsx)(styled_1.ConsoleWrap,(0,tslib_1.__assign)({shaking:t,className:r,"data-cy":"console",fullWidth:null==o?void 0:o.width},{children:s}),void 0)}function AuthPanelHook(e){var t=(0,informed_1.useField)((0,tslib_1.__assign)({},e)),r=t.fieldApi,s=t.render,i=t.userProps,o=r.setValue,n=i.children;return s((0,jsx_runtime_1.jsx)(jsx_runtime_1.Fragment,{children:n(o)},void 0))}exports.Console=Console;
2
2
  //# sourceMappingURL=Console.js.map
@@ -24,3 +24,4 @@ export declare function encodeSample(sample: ExampleModel, properties: RequestBo
24
24
  export declare const getStorageExampleKey: (operationId: string, activeMimeType: string, activeExample?: string | false | undefined, examples?: {
25
25
  [name: string]: ExampleModel;
26
26
  } | undefined) => string;
27
+ export declare const decodeKeysDeep: (obj: Record<string, any>) => Record<string, any>;
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getStorageExampleKey=exports.encodeSample=exports.getOAuth2TokenEndpointAuthHeader=exports.validateTokenEndpointMethod=exports.makeRequestInterceptor=exports.getFileNameFromHeaders=exports.unescapeQueryParams=exports.updateVariablesStorage=exports.getDefaultOrStoredVariables=exports.expandDefaultServerVariables=exports.expandVariables=exports.getInitialServerWithVariables=exports.getServerWithVariables=exports.getParameters=exports.updateStorage=exports.normalizeUrlProtocol=void 0;var tslib_1=require("tslib"),deepmerge_1=(0,tslib_1.__importDefault)(require("deepmerge")),types_1=require("../../types"),utils_1=require("../../services/utils"),utils_2=require("../../utils");function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}function updateStorage(e){if(e.values.auth)for(var r=0,t=Object.keys(e.values.auth);r<t.length;r++){var a=t[r],i=e.values.auth[a];(0,utils_2.setSecurityDetails)(a,i)}updateParameterStorage(e)}function updateParameterStorage(e){for(var r,t=0,a=["path","query","header","cookie"];t<a.length;t++){var i=a[t];if(null===(r=e.values)||void 0===r?void 0:r[i])for(var o=0,n=Object.keys(e.values[i]);o<n.length;o++){var s=n[o];(0,utils_2.setParameterValue)(i,s,e.values[i][s])}}}exports.normalizeUrlProtocol=normalizeUrlProtocol,exports.updateStorage=updateStorage;var getParameters=function(e,r){return e.filter((function(e){return e.in===r})).reduce((function(e,r){var t=r.in,a=r.name;return e[a]=(0,utils_2.getParameterValue)(t||"",a),e}),{})};exports.getParameters=getParameters;var pathTemplateRegExp=/(?:{)(.*?)(?:})/g;function getServerWithVariables(e,r){void 0===r&&(r=0);var t=e[r],a=getDefaultOrStoredVariables(t);return(0,tslib_1.__assign)((0,tslib_1.__assign)({},t),{variables:a})}function getInitialServerWithVariables(e){var r=(0,utils_2.fromSessionStorage)("serverUrl"),t=e.find((function(e){return e.url===r}))||e[0],a=getDefaultOrStoredVariables(t);return(0,tslib_1.__assign)((0,tslib_1.__assign)({},t),{variables:a})}function expandVariables(e,r){return void 0===r&&(r={}),e.replace(pathTemplateRegExp,(function(e,t){return r[t]||e}))}function expandDefaultServerVariables(e,r){return void 0===r&&(r={}),e.replace(pathTemplateRegExp,(function(e,t){return r[t]&&r[t].default||e}))}function getDefaultOrStoredVariables(e){if(!(null==e?void 0:e.variables))return{};var r=(0,utils_2.fromSessionStorage)("variables"),t=r&&JSON.parse(r)||{},a={};return Object.entries(e.variables||{}).forEach((function(e){var r=e[0],i=e[1];a[r]=t[r]||i.default||""})),a}function updateVariablesStorage(e,r){var t,a=(0,utils_2.fromSessionStorage)("variables"),i=a&&JSON.parse(a)||{};(0,utils_2.toSessionStorage)("variables",JSON.stringify((0,tslib_1.__assign)((0,tslib_1.__assign)({},i),((t={})[e]=r,t))))}function unescapeQueryParams(e){return Object.entries(e).reduce((function(e,r){var t=r[0],a=r[1];return e[(0,utils_2.unescapeFormId)(t)]=a,e}),{})}function getFileNameFromHeaders(e){for(var r="filename=",t=0,a=Object.entries(e);t<a.length;t++){var i=a[t],o=i[0],n=i[1];if("content-disposition"===o.toLowerCase()){var s=n.split(";").find((function(e){return e.trim().startsWith(r)}));if(s)return s.split(r)[1]}}return""}exports.getServerWithVariables=getServerWithVariables,exports.getInitialServerWithVariables=getInitialServerWithVariables,exports.expandVariables=expandVariables,exports.expandDefaultServerVariables=expandDefaultServerVariables,exports.getDefaultOrStoredVariables=getDefaultOrStoredVariables,exports.updateVariablesStorage=updateVariablesStorage,exports.unescapeQueryParams=unescapeQueryParams,exports.getFileNameFromHeaders=getFileNameFromHeaders;var makeRequestInterceptor=function(e,r,t,a){var i=e.requestInterceptor,o=e.sendXUserAgentInTryIt,n=e.disableTryItRequestUrlEncoding;return function(e){var s,l,u,d,p,v;n&&(e=(0,tslib_1.__assign)((0,tslib_1.__assign)({},e),{url:decodeURIComponent(e.url)})),o&&(e.headers["X-User-Agent"]="Redocly Try it API console");var c=(null===(l=null===(s=null==r?void 0:r.requestValues)||void 0===s?void 0:s.header)||void 0===l?void 0:l.authorization)||(null===(d=null===(u=null==r?void 0:r.requestValues)||void 0===u?void 0:u.header)||void 0===d?void 0:d.Authorization)||(null===(p=null==a?void 0:a.header)||void 0===p?void 0:p.Authorization)||(null===(v=null==a?void 0:a.header)||void 0===v?void 0:v.authorization);return!(null==t?void 0:t.Authorization)&&c&&(e.headers.Authorization=c),(null==t?void 0:t.Cookie)&&(e.headers["X-Redocly-Cookie"]=t.Cookie),i?i(e,r):e}};exports.makeRequestInterceptor=makeRequestInterceptor;var validateTokenEndpointMethod=function(e){if(!e)return!0;var r=Array.isArray(e)?e:[e];return!(r.length&&!r.includes("none")&&!r.includes("client_secret_basic"))};exports.validateTokenEndpointMethod=validateTokenEndpointMethod;var getOAuth2TokenEndpointAuthHeader=function(e){var r=e.authMethod,t=e.clientId,a=e.clientSecret;return"client_secret_basic"===r||Array.isArray(r)&&r.includes("client_secret_basic")?{Authorization:"Basic "+btoa(t+":"+a)}:{}};function encodeSample(e,r){if(!e)return"";if(e.mime===types_1.MediaTypes.URL_ENCODED)return e.value;var t=e.value,a=r?(0,deepmerge_1.default)(t,r,{arrayMerge:utils_1.arrayMergeStrategy}):t;return JSON.stringify(a,null,2)}exports.getOAuth2TokenEndpointAuthHeader=getOAuth2TokenEndpointAuthHeader,exports.encodeSample=encodeSample;var getStorageExampleKey=function(e,r,t,a){var i=e+"_"+r;return t&&a&&Object.keys(a).includes(t)&&(i+="_"+t),i};exports.getStorageExampleKey=getStorageExampleKey;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.decodeKeysDeep=exports.getStorageExampleKey=exports.encodeSample=exports.getOAuth2TokenEndpointAuthHeader=exports.validateTokenEndpointMethod=exports.makeRequestInterceptor=exports.getFileNameFromHeaders=exports.unescapeQueryParams=exports.updateVariablesStorage=exports.getDefaultOrStoredVariables=exports.expandDefaultServerVariables=exports.expandVariables=exports.getInitialServerWithVariables=exports.getServerWithVariables=exports.getParameters=exports.updateStorage=exports.normalizeUrlProtocol=void 0;var tslib_1=require("tslib"),deepmerge_1=(0,tslib_1.__importDefault)(require("deepmerge")),types_1=require("../../types"),utils_1=require("../../services/utils"),utils_2=require("../../utils");function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}function updateStorage(e){if(e.values.auth)for(var r=0,t=Object.keys(e.values.auth);r<t.length;r++){var a=t[r],i=e.values.auth[a];(0,utils_2.setSecurityDetails)(a,i)}updateParameterStorage(e)}function updateParameterStorage(e){for(var r,t=0,a=["path","query","header","cookie"];t<a.length;t++){var i=a[t];if(null===(r=e.values)||void 0===r?void 0:r[i])for(var o=0,n=Object.keys(e.values[i]);o<n.length;o++){var s=n[o];(0,utils_2.setParameterValue)(i,s,e.values[i][s])}}}exports.normalizeUrlProtocol=normalizeUrlProtocol,exports.updateStorage=updateStorage;var getParameters=function(e,r){return e.filter((function(e){return e.in===r})).reduce((function(e,r){var t=r.in,a=r.name;return e[a]=(0,utils_2.getParameterValue)(t||"",a),e}),{})};exports.getParameters=getParameters;var pathTemplateRegExp=/(?:{)(.*?)(?:})/g;function getServerWithVariables(e,r){void 0===r&&(r=0);var t=e[r],a=getDefaultOrStoredVariables(t);return(0,tslib_1.__assign)((0,tslib_1.__assign)({},t),{variables:a})}function getInitialServerWithVariables(e){var r=(0,utils_2.fromSessionStorage)("serverUrl"),t=e.find((function(e){return e.url===r}))||e[0],a=getDefaultOrStoredVariables(t);return(0,tslib_1.__assign)((0,tslib_1.__assign)({},t),{variables:a})}function expandVariables(e,r){return void 0===r&&(r={}),e.replace(pathTemplateRegExp,(function(e,t){return r[t]||e}))}function expandDefaultServerVariables(e,r){return void 0===r&&(r={}),e.replace(pathTemplateRegExp,(function(e,t){return r[t]&&r[t].default||e}))}function getDefaultOrStoredVariables(e){if(!(null==e?void 0:e.variables))return{};var r=(0,utils_2.fromSessionStorage)("variables"),t=r&&JSON.parse(r)||{},a={};return Object.entries(e.variables||{}).forEach((function(e){var r=e[0],i=e[1];a[r]=t[r]||i.default||""})),a}function updateVariablesStorage(e,r){var t,a=(0,utils_2.fromSessionStorage)("variables"),i=a&&JSON.parse(a)||{};(0,utils_2.toSessionStorage)("variables",JSON.stringify((0,tslib_1.__assign)((0,tslib_1.__assign)({},i),((t={})[e]=r,t))))}function unescapeQueryParams(e){return Object.entries(e).reduce((function(e,r){var t=r[0],a=r[1];return e[(0,utils_2.unescapeFormId)(t)]=a,e}),{})}function getFileNameFromHeaders(e){for(var r="filename=",t=0,a=Object.entries(e);t<a.length;t++){var i=a[t],o=i[0],n=i[1];if("content-disposition"===o.toLowerCase()){var s=n.split(";").find((function(e){return e.trim().startsWith(r)}));if(s)return s.split(r)[1]}}return""}exports.getServerWithVariables=getServerWithVariables,exports.getInitialServerWithVariables=getInitialServerWithVariables,exports.expandVariables=expandVariables,exports.expandDefaultServerVariables=expandDefaultServerVariables,exports.getDefaultOrStoredVariables=getDefaultOrStoredVariables,exports.updateVariablesStorage=updateVariablesStorage,exports.unescapeQueryParams=unescapeQueryParams,exports.getFileNameFromHeaders=getFileNameFromHeaders;var makeRequestInterceptor=function(e,r,t,a){var i=e.requestInterceptor,o=e.sendXUserAgentInTryIt,n=e.disableTryItRequestUrlEncoding;return function(e){var s,l,u,d,p,c;n&&(e=(0,tslib_1.__assign)((0,tslib_1.__assign)({},e),{url:decodeURIComponent(e.url)})),o&&(e.headers["X-User-Agent"]="Redocly Try it API console");var v=(null===(l=null===(s=null==r?void 0:r.requestValues)||void 0===s?void 0:s.header)||void 0===l?void 0:l.authorization)||(null===(d=null===(u=null==r?void 0:r.requestValues)||void 0===u?void 0:u.header)||void 0===d?void 0:d.Authorization)||(null===(p=null==a?void 0:a.header)||void 0===p?void 0:p.Authorization)||(null===(c=null==a?void 0:a.header)||void 0===c?void 0:c.authorization);return!(null==t?void 0:t.Authorization)&&v&&(e.headers.Authorization=v),(null==t?void 0:t.Cookie)&&(e.headers["X-Redocly-Cookie"]=t.Cookie),i?i(e,r):e}};exports.makeRequestInterceptor=makeRequestInterceptor;var validateTokenEndpointMethod=function(e){if(!e)return!0;var r=Array.isArray(e)?e:[e];return!(r.length&&!r.includes("none")&&!r.includes("client_secret_basic"))};exports.validateTokenEndpointMethod=validateTokenEndpointMethod;var getOAuth2TokenEndpointAuthHeader=function(e){var r=e.authMethod,t=e.clientId,a=e.clientSecret;return"client_secret_basic"===r||Array.isArray(r)&&r.includes("client_secret_basic")?{Authorization:"Basic "+btoa(t+":"+a)}:{}};function encodeSample(e,r){if(!e)return"";if(e.mime===types_1.MediaTypes.URL_ENCODED)return e.value;var t=e.value,a=r?(0,deepmerge_1.default)(t,r,{arrayMerge:utils_1.arrayMergeStrategy}):t;return JSON.stringify(a,null,2)}exports.getOAuth2TokenEndpointAuthHeader=getOAuth2TokenEndpointAuthHeader,exports.encodeSample=encodeSample;var getStorageExampleKey=function(e,r,t,a){var i=e+"_"+r;return t&&a&&Object.keys(a).includes(t)&&(i+="_"+t),i};exports.getStorageExampleKey=getStorageExampleKey;var decodeKeysDeep=function(e){if(Array.isArray(e))return e.map((function(e){return(0,exports.decodeKeysDeep)(e)}));if(null!==e&&"object"==typeof e){var r={};for(var t in e){if(Object.prototype.hasOwnProperty.call(e,t))r[decodeURIComponent(t)]=(0,exports.decodeKeysDeep)(e[t])}return r}return e};exports.decodeKeysDeep=decodeKeysDeep;
2
2
  //# sourceMappingURL=utils.js.map
package/lib/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getJsUrl=exports.getWindowReferenceOptions=exports.dottedString=exports.joinStringFactory=exports.get=exports.getSecurityDetailsOptions=exports.getSecurityDetails=exports.setSecurityDetailsVariants=exports.setSecurityDetails=exports.unescapeFormId=exports.escapeFormId=exports.fromLocalStorage=exports.toLocalStorage=exports.getParameterValue=exports.setParameterValue=exports.fromSessionStorage=exports.toSessionStorage=exports.debounce=exports.setGlobalStore=exports.getGlobalStore=void 0;var _store,utils_1=require("./redoc-lib/src/utils"),getGlobalStore=function(){return _store};exports.getGlobalStore=getGlobalStore;var setGlobalStore=function(e){return _store=e};function debounce(e,t,r){var o,s=0;return function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];s++,o?clearTimeout(o):r&&e.apply(void 0,n),o=setTimeout((function(){s>1&&e.apply(void 0,n),s=0,o=null}),t)}}function toSessionStorage(e,t){utils_1.IS_BROWSER&&window.sessionStorage.setItem("redoc."+e,t)}function fromSessionStorage(e){return utils_1.IS_BROWSER&&window.sessionStorage.getItem("redoc."+e)||""}function setParameterValue(e,t,r){toSessionStorage(e+"."+t,JSON.stringify(r))}function getParameterValue(e,t){try{return JSON.parse(fromSessionStorage(e+"."+t))}catch(e){return null}}function toLocalStorage(e,t){window.localStorage.setItem("redoc."+e,t)}function fromLocalStorage(e){return utils_1.IS_BROWSER&&window.localStorage.getItem("redoc."+e)||""}function escapeFormId(e){return e.replace(/[.[\]]/g,(function(e){return{".":"%2e","[":"%5b","]":"%5d"}[e]||""}))}function unescapeFormId(e){return e.replace(/%2e|%5b|%5d/g,(function(e){return{"%2e":".","%5b":"[","%5d":"]"}[e]||""}))}function setSecurityDetails(e,t){e=escapeFormId(e),"string"==typeof t?toSessionStorage("auth."+e,t):t&&(toSessionStorage("auth."+e+".password",t.password||""),toSessionStorage("auth."+e+".username",t.username||""),toSessionStorage("auth."+e+".token",t.token&&JSON.stringify(t.token)||""),toSessionStorage("auth."+e+".client_id",t.client_id||""),toSessionStorage("auth."+e+".client_secret",t.client_secret||""),toSessionStorage("auth."+e+".scopes",t.scopes&&JSON.stringify(t.scopes)||""))}function setSecurityDetailsVariants(e,t){toSessionStorage("auth."+(e=escapeFormId(e))+".variants",JSON.stringify(t))}function getSecurityDetails(e){var t=fromSessionStorage("auth."+(e=escapeFormId(e))),r=fromSessionStorage("auth."+e+".token");return{raw:t,password:fromSessionStorage("auth."+e+".password"),username:fromSessionStorage("auth."+e+".username"),token:r&&JSON.parse(r)||null,client_id:fromSessionStorage("auth."+e+".client_id"),client_secret:fromSessionStorage("auth."+e+".client_secret"),scopes:fromSessionStorage("auth."+e+".scopes")}}function getSecurityDetailsOptions(e,t){var r=fromSessionStorage("auth."+(e=escapeFormId(e))+".variants");if(!r)return null;var o=JSON.parse(r);return o&&Array.isArray(o)?o.map((function(e){return e.details?""===t&&e.details&&"string"==typeof e.details?{label:e.label,value:e.details}:"object"==typeof e.details?{label:e.label,value:e.details[t]}:null:null})).filter(notNull):null}function notNull(e){return null!==e}function get(e,t,r){return void 0===e&&(e={}),"string"==typeof t&&(t=t.split(".")),t.reduce((function(e,t){return e&&e[t]?e[t]:r}),e)}function joinStringFactory(e){return function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];return t.filter(Boolean).join(e)}}function getWindowReferenceOptions(e){var t;return utils_1.IS_BROWSER?null===(t=null===window||void 0===window?void 0:window.REFERENCE_DOCS_OPTIONS)||void 0===t?void 0:t[e]:null}function getJsUrl(){var e;if(!utils_1.IS_BROWSER)return"";var t=+new Date+Math.random();try{return document.currentScript&&(document.currentScript.async||document.currentScript.defer)||document.write('<script id="dummy'+t+'"><\/script>'),(null===(e=document.getElementById("dummy"+t))||void 0===e?void 0:e.previousSibling).src}catch(e){return""}}exports.setGlobalStore=setGlobalStore,exports.debounce=debounce,exports.toSessionStorage=toSessionStorage,exports.fromSessionStorage=fromSessionStorage,exports.setParameterValue=setParameterValue,exports.getParameterValue=getParameterValue,exports.toLocalStorage=toLocalStorage,exports.fromLocalStorage=fromLocalStorage,exports.escapeFormId=escapeFormId,exports.unescapeFormId=unescapeFormId,exports.setSecurityDetails=setSecurityDetails,exports.setSecurityDetailsVariants=setSecurityDetailsVariants,exports.getSecurityDetails=getSecurityDetails,exports.getSecurityDetailsOptions=getSecurityDetailsOptions,exports.get=get,exports.joinStringFactory=joinStringFactory,exports.dottedString=joinStringFactory("."),exports.getWindowReferenceOptions=getWindowReferenceOptions,exports.getJsUrl=getJsUrl;
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.getJsUrl=exports.getWindowReferenceOptions=exports.dottedString=exports.joinStringFactory=exports.get=exports.getSecurityDetailsOptions=exports.getSecurityDetails=exports.setSecurityDetailsVariants=exports.setSecurityDetails=exports.unescapeFormId=exports.escapeFormId=exports.fromLocalStorage=exports.toLocalStorage=exports.getParameterValue=exports.setParameterValue=exports.fromSessionStorage=exports.toSessionStorage=exports.debounce=exports.setGlobalStore=exports.getGlobalStore=void 0;var _store,utils_1=require("./redoc-lib/src/utils"),getGlobalStore=function(){return _store};exports.getGlobalStore=getGlobalStore;var setGlobalStore=function(e){return _store=e};function debounce(e,t,o){var r,s=0;return function(){for(var n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];s++,r?clearTimeout(r):o&&e.apply(void 0,n),r=setTimeout((function(){s>1&&e.apply(void 0,n),s=0,r=null}),t)}}function toSessionStorage(e,t){utils_1.IS_BROWSER&&window.sessionStorage.setItem("redoc."+e,t)}function fromSessionStorage(e){return utils_1.IS_BROWSER&&window.sessionStorage.getItem("redoc."+e)||""}function setParameterValue(e,t,o){toSessionStorage(e+"."+t,JSON.stringify(o))}function getParameterValue(e,t){try{return JSON.parse(fromSessionStorage(e+"."+t)||fromSessionStorage(e+"."+decodeURIComponent(t)))}catch(e){return null}}function toLocalStorage(e,t){window.localStorage.setItem("redoc."+e,t)}function fromLocalStorage(e){return utils_1.IS_BROWSER&&window.localStorage.getItem("redoc."+e)||""}function escapeFormId(e){return e.replace(/[.[\]]/g,(function(e){return{".":"%2e","[":"%5b","]":"%5d"}[e]||""}))}function unescapeFormId(e){return e.replace(/%2e|%5b|%5d/g,(function(e){return{"%2e":".","%5b":"[","%5d":"]"}[e]||""}))}function setSecurityDetails(e,t){e=escapeFormId(e),"string"==typeof t?toSessionStorage("auth."+e,t):t&&(toSessionStorage("auth."+e+".password",t.password||""),toSessionStorage("auth."+e+".username",t.username||""),toSessionStorage("auth."+e+".token",t.token&&JSON.stringify(t.token)||""),toSessionStorage("auth."+e+".client_id",t.client_id||""),toSessionStorage("auth."+e+".client_secret",t.client_secret||""),toSessionStorage("auth."+e+".scopes",t.scopes&&JSON.stringify(t.scopes)||""))}function setSecurityDetailsVariants(e,t){toSessionStorage("auth."+(e=escapeFormId(e))+".variants",JSON.stringify(t))}function getSecurityDetails(e){var t=fromSessionStorage("auth."+(e=escapeFormId(e))),o=fromSessionStorage("auth."+e+".token");return{raw:t,password:fromSessionStorage("auth."+e+".password"),username:fromSessionStorage("auth."+e+".username"),token:o&&JSON.parse(o)||null,client_id:fromSessionStorage("auth."+e+".client_id"),client_secret:fromSessionStorage("auth."+e+".client_secret"),scopes:fromSessionStorage("auth."+e+".scopes")}}function getSecurityDetailsOptions(e,t){var o=fromSessionStorage("auth."+(e=escapeFormId(e))+".variants");if(!o)return null;var r=JSON.parse(o);return r&&Array.isArray(r)?r.map((function(e){return e.details?""===t&&e.details&&"string"==typeof e.details?{label:e.label,value:e.details}:"object"==typeof e.details?{label:e.label,value:e.details[t]}:null:null})).filter(notNull):null}function notNull(e){return null!==e}function get(e,t,o){return void 0===e&&(e={}),"string"==typeof t&&(t=t.split(".")),t.reduce((function(e,t){return e&&e[t]?e[t]:o}),e)}function joinStringFactory(e){return function(){for(var t=[],o=0;o<arguments.length;o++)t[o]=arguments[o];return t.filter(Boolean).join(e)}}function getWindowReferenceOptions(e){var t;return utils_1.IS_BROWSER?null===(t=null===window||void 0===window?void 0:window.REFERENCE_DOCS_OPTIONS)||void 0===t?void 0:t[e]:null}function getJsUrl(){var e;if(!utils_1.IS_BROWSER)return"";var t=+new Date+Math.random();try{return document.currentScript&&(document.currentScript.async||document.currentScript.defer)||document.write('<script id="dummy'+t+'"><\/script>'),(null===(e=document.getElementById("dummy"+t))||void 0===e?void 0:e.previousSibling).src}catch(e){return""}}exports.setGlobalStore=setGlobalStore,exports.debounce=debounce,exports.toSessionStorage=toSessionStorage,exports.fromSessionStorage=fromSessionStorage,exports.setParameterValue=setParameterValue,exports.getParameterValue=getParameterValue,exports.toLocalStorage=toLocalStorage,exports.fromLocalStorage=fromLocalStorage,exports.escapeFormId=escapeFormId,exports.unescapeFormId=unescapeFormId,exports.setSecurityDetails=setSecurityDetails,exports.setSecurityDetailsVariants=setSecurityDetailsVariants,exports.getSecurityDetails=getSecurityDetails,exports.getSecurityDetailsOptions=getSecurityDetailsOptions,exports.get=get,exports.joinStringFactory=joinStringFactory,exports.dottedString=joinStringFactory("."),exports.getWindowReferenceOptions=getWindowReferenceOptions,exports.getJsUrl=getJsUrl;
2
2
  //# sourceMappingURL=utils.js.map
@@ -1,2 +1,2 @@
1
- import{__decorate,__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{Form,useField}from"informed";import{observer}from"mobx-react";import Swagger from"swagger-client";import{Component}from"react";import{unescapeFormId}from"../../utils";import{JsonPointer}from"../../redoc-lib";import{RenderHook}from"../../redoc-lib/src/components/RenderHook";import{l}from"../../redoc-lib/src/services/Labels";import{CodeHeader,Accordion}from"../Panel";import{OAuth2}from"../../services/OAuth2";import{isFileUploadMime}from"../common/FileUpload/helper";import{OperationParameters}from"../OperationParameters";import{useDimensions}from"../../hooks";import{AnalyticsEventType}from"../../events";import{isEmptyObject}from"../../services/utils";import{getFileNameFromHeaders,getParameters,makeRequestInterceptor,unescapeQueryParams,updateStorage}from"./utils";import{AuthPanel,requiredValidator}from"./AuthPanel";import{ConsoleBadges}from"./ConsoleBadges";import{RequestBody}from"./RequestBody";import{ResponsePanel}from"./ResponsePanel";import{ActionPanel}from"./ActionPanel";import{ServersDropdown}from"./ServersDropdown";import{TryItPanel}from"./TryItPanel";import{CloseButton,ConsoleBody,ConsoleWrap}from"./styled";function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}const flexColumn={flex:1,display:"flex",flexDirection:"column"};let Console=class extends Component{constructor(e){super(e),Object.defineProperty(this,"formApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setFormApi",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.formApi=e;const t=e.getState(),{values:o}=t,s=__rest(t,["values"]);setTimeout((()=>{const e=Object.assign(Object.assign({},s),{values:Object.assign(Object.assign({},o),{query:unescapeQueryParams(o.query||{}),path:unescapeQueryParams(o.path||{})})});this.setState({form:e})}),0)}}),Object.defineProperty(this,"handleValueChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=Object.assign(Object.assign({},e),{query:unescapeQueryParams(e.query||{}),path:unescapeQueryParams(e.path||{})});this.setState((e=>({form:Object.assign(Object.assign({},e.form),{values:t})})),(()=>{updateStorage(this.state.form),this.props.operation.setRequestValues(e)}))}}),Object.defineProperty(this,"handleTabChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({activeTab:e})}}),Object.defineProperty(this,"handleServerChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({server:e}),this.props.operation.setActiveServer(e)}}),Object.defineProperty(this,"handleExecute",{enumerable:!0,configurable:!0,writable:!0,value:async()=>{var e,t,o,s,r,a,i,n,l,c;const{store:d,operation:p,onResponse:u}=this.props;null===(e=this.formApi)||void 0===e||e.submitForm();const{invalid:h}=(null===(t=this.formApi)||void 0===t?void 0:t.getState())||this.state.form;if(h)return this.setState({shaking:!0}),setTimeout((()=>this.setState({shaking:!1})),1e3),void(null===(s=null===(o=null==d?void 0:d.options.events)||void 0===o?void 0:o.tryItSent)||void 0===s||s.call(o,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"ValidationFailed",operationId:p.operationId,operationPath:p.path,operationHttpVerb:p.httpVerb,operationSummary:p.description}));const{values:m}=(null===(r=this.formApi)||void 0===r?void 0:r.getState())||this.state.form,{servers:v,requestBody:g}=this.props.operation,y=g&&g.content&&g.content.active&&g.content.active.name||"";let b=m.body;if(/json/.test(y))try{b=JSON.parse(b)}catch(e){console.error(e)}this.setState({loading:!0});const f=this.state.resolvedRawSpec,j=(p.httpVerb||"").toLowerCase();if(!v)throw console.error("Servers are not specified in your OpenAPI file. You can't use Try It Out console without specifying servers. If you use OpenAPI 2, make sure you configured host and basepath"),new Error("Servers are not specified");const O=v.find((e=>this.state.server.url.endsWith(e.url.endsWith("/")?e.url.substring(0,e.url.length-1):e.url))),P=Date.now();let S,x=m.auth;if(!isEmptyObject(m.auth)&&m.auth){const e=Object.keys(m.auth)[0],t=unescapeFormId(e);S=Object.assign(Object.assign({},f),{components:Object.assign(Object.assign({},null==f?void 0:f.components),{securitySchemes:Object.assign(Object.assign({},null==f?void 0:f.components.securitySchemes),{[t]:Object.assign(Object.assign({},null==f?void 0:f.components.securitySchemes[t]),{type:"openIdConnect"===(null==f?void 0:f.components.securitySchemes[t].type)?"oauth2":null==f?void 0:f.components.securitySchemes[t].type})})})});const o="cookie"===(null==f?void 0:f.components.securitySchemes[t].in)?"Cookie":t,s="cookie"===(null==f?void 0:f.components.securitySchemes[t].in)?`${null==f?void 0:f.components.securitySchemes[t].name}=${x[e]}`:x[e];x=Object.assign(Object.assign({},x),{[o]:s})}else S=Object.assign({},f);S.servers=v;const C=d.options.corsProxyUrl;C&&v.length&&(S.servers=v.map((e=>Object.assign(Object.assign({},e),{url:C+normalizeUrlProtocol(e.url)}))),S.paths=Object.assign(Object.assign({},S.paths),{[p.path]:Object.assign(Object.assign({},S.paths[p.path]),{[j]:Object.assign(Object.assign({},S.paths[p.path][j]),{servers:void 0}),servers:void 0})}));const _=(null===(i=null===(a=null==g?void 0:g.content)||void 0===a?void 0:a.active)||void 0===i?void 0:i.name)||null;if(_&&b&&isFileUploadMime(_)){const e=Object.values(b);b=e.length>1?e:e[0]}const A={server:C?C+normalizeUrlProtocol(O.url):O.url,serverVariables:this.state.server.variables,spec:S,pathName:p.path,method:p.httpVerb,parameters:Object.assign(Object.assign(Object.assign(Object.assign({},m.path),m.query),m.header),m.cookie),securities:{authorized:x},requestBody:b,requestContentType:_,responseContentType:(null===(n=m.header)||void 0===n?void 0:n.Accept)||null,requestInterceptor:makeRequestInterceptor(d.options,p,x,m)};try{const e=await Swagger.execute(A),t=null==e?void 0:e.data;t instanceof Blob&&(isFileUploadMime(t.type)&&(e.fileInfo={rawData:t,fileName:getFileNameFromHeaders(e.headers)}),e.data=await t.text()),null==u||u({request:A,response:e}),this.setState({response:e,error:void 0})}catch(e){e&&e.response&&e.response.data instanceof Blob&&(e.response.data=await e.response.data.text(),null==u||u({request:A,response:e.response})),this.setState({response:void 0,error:e})}finally{this.setState({loading:!1,activeTab:1,time:Date.now()-P}),null===(c=null===(l=null==d?void 0:d.options.events)||void 0===l?void 0:l.tryItSent)||void 0===c||c.call(l,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"Sent",operationId:p.operationId,operationPath:p.path,operationHttpVerb:p.httpVerb,operationSummary:p.description})}}}),this.state={form:{values:{path:getParameters(e.operation.parameters,"path"),cookie:getParameters(e.operation.parameters,"cookie"),header:getParameters(e.operation.parameters,"header"),query:getParameters(e.operation.parameters,"query")}},shaking:!1,loading:!1,activeTab:0,server:{}}}async componentDidMount(){var e;const{store:t,operation:o}=this.props,s=await t.dereferenceSpecForTryIt(o);this.setState({resolvedRawSpec:s}),null===(e=this.formApi)||void 0===e||e.setValues({})}componentDidUpdate(e){e.operation!==this.props.operation&&this.setState({response:void 0,error:void 0,activeTab:0})}render(){const{operation:e,className:t,rootElement:o}=this.props,{shaking:s,activeTab:r,form:a,response:i,loading:n,error:l}=this.state,c=!(!i&&!l);return _jsxs(ConsoleWrapHook,Object.assign({shaking:s,className:t,rootElement:o},{children:[_jsxs(CodeHeader,{children:[_jsx(ConsoleBadges,{active:r,hasResponse:c,onChange:this.handleTabChange},void 0),this.props.onClose&&_jsx(CloseButton,Object.assign({onClick:this.props.onClose},{children:" ✕ "}),void 0)]},void 0),_jsx(ConsoleBody,Object.assign({hidden:0!==r,"data-cy":"console-request-body"},{children:this.renderRequest()}),void 0),_jsx(ConsoleBody,Object.assign({hidden:1!==r,"data-cy":"console-response-body"},{children:this.renderResponse()}),void 0),_jsx(ActionPanel,{hasResponse:c,params:a.values,operation:e,loading:n,execute:this.handleExecute},void 0)]}),void 0)}renderRequest(){var e;const{operation:t,store:o,properties:s,securityDefaults:r}=this.props,{form:a,resolvedRawSpec:i,server:n}=this.state,c=a.errors||{},d=c.path||c.cookie||c.header||c.query,p=i&&JsonPointer.get(i,t.pointer);let u=a.values&&a.values.auth&&Object.keys(a.values.auth)[0];u&&a.values.auth[u]||(u=void 0),!u||void 0===a.values.auth[u].token&&void 0===a.values.auth[u].client_id&&void 0===a.values.auth[u].client_secret||a.values.auth[u].token&&a.values.auth[u].token.access_token||(u=void 0),u&&null!=a.values.auth[u].username&&(a.values.auth[u].username&&a.values.auth[u].password||(u=void 0));const h=t.parameters||[],m=null===(e=null==o?void 0:o.options.hooks)||void 0===e?void 0:e.ReplaceTryItSecurityPanel;return!i&&_jsx(_Fragment,{children:"Loading..."},void 0)||_jsxs(Form,Object.assign({onValueChange:this.handleValueChange,getApi:this.setFormApi,style:Object.assign(Object.assign({},flexColumn),{margin:0})},{children:[_jsx(ServersDropdown,{operation:t,onChange:this.handleServerChange},void 0),_jsxs(Accordion,Object.assign({initialActiveIdx:t.security.length&&u?1:0},{children:[t.security.length&&this.formApi&&_jsx(TryItPanel,Object.assign({header:l("tryItAuth"),"data-cy":"security-trigger",renderChildrenHidden:!0,error:!u&&!!c.auth,success:!!u},{children:m?_jsx(AuthPanelHook,Object.assign({field:"auth",validate:requiredValidator},{children:e=>_jsx(RenderHook,{Hook:m,props:{server:n,operation:t,onChange:e,OAuth2:OAuth2}},void 0)}),void 0):_jsx(AuthPanel,{formApi:this.formApi,form:a,operation:t,activeServer:n.url,authCorsProxyUrl:o.options.authCorsProxyUrl,securityDefaults:r},void 0)}),void 0)||null,t.requestBody&&this.formApi&&_jsx(TryItPanel,Object.assign({header:l("tryItBody"),"data-cy":"body-trigger",renderChildrenHidden:!0,error:!!c.body},{children:_jsx(RequestBody,{validate:allowBodyErrors,formApi:this.formApi,body:t.requestBody,id:t.id,resolvedBody:null==p?void 0:p.requestBody,properties:s},void 0)}),void 0)||null,h.length&&_jsx(TryItPanel,Object.assign({header:l("tryItParameters"),"data-cy":"parameters-trigger",error:d,renderChildrenHidden:!0},{children:_jsx(OperationParameters,{operation:t,values:a.values,errors:a.errors||{}},void 0)}),void 0)||null]}),void 0)]}),void 0)}renderResponse(){const{response:e,error:t,time:o}=this.state;return _jsx(ResponsePanel,{response:e,error:t,time:o},void 0)}};Console=__decorate([observer],Console);export{Console};function allowBodyErrors(){}function ConsoleWrapHook(e){const{shaking:t,className:o,children:s,rootElement:r}=e,[a]=useDimensions(r);return _jsx(ConsoleWrap,Object.assign({shaking:t,className:o,"data-cy":"console",fullWidth:null==a?void 0:a.width},{children:s}),void 0)}function AuthPanelHook(e){const{fieldApi:t,render:o,userProps:s}=useField(Object.assign({},e)),{setValue:r}=t,{children:a}=s;return o(_jsx(_Fragment,{children:a(r)},void 0))}
1
+ import{__decorate,__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{Form,useField}from"informed";import{observer}from"mobx-react";import Swagger from"swagger-client";import{Component}from"react";import{unescapeFormId}from"../../utils";import{JsonPointer}from"../../redoc-lib";import{RenderHook}from"../../redoc-lib/src/components/RenderHook";import{l}from"../../redoc-lib/src/services/Labels";import{CodeHeader,Accordion}from"../Panel";import{OAuth2}from"../../services/OAuth2";import{isFileUploadMime}from"../common/FileUpload/helper";import{OperationParameters}from"../OperationParameters";import{useDimensions}from"../../hooks";import{AnalyticsEventType}from"../../events";import{isEmptyObject}from"../../services/utils";import{getFileNameFromHeaders,getParameters,makeRequestInterceptor,unescapeQueryParams,updateStorage,decodeKeysDeep}from"./utils";import{AuthPanel,requiredValidator}from"./AuthPanel";import{ConsoleBadges}from"./ConsoleBadges";import{RequestBody}from"./RequestBody";import{ResponsePanel}from"./ResponsePanel";import{ActionPanel}from"./ActionPanel";import{ServersDropdown}from"./ServersDropdown";import{TryItPanel}from"./TryItPanel";import{CloseButton,ConsoleBody,ConsoleWrap}from"./styled";function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}const flexColumn={flex:1,display:"flex",flexDirection:"column"};let Console=class extends Component{constructor(e){super(e),Object.defineProperty(this,"formApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setFormApi",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.formApi=e;const t=e.getState(),{values:o}=t,s=__rest(t,["values"]);setTimeout((()=>{const e=Object.assign(Object.assign({},s),{values:Object.assign(Object.assign({},o),{query:unescapeQueryParams(o.query||{}),path:unescapeQueryParams(o.path||{})})});this.setState({form:e})}),0)}}),Object.defineProperty(this,"handleValueChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=Object.assign(Object.assign({},e),{query:unescapeQueryParams(e.query||{}),path:unescapeQueryParams(e.path||{})});this.setState((e=>({form:Object.assign(Object.assign({},e.form),{values:t})})),(()=>{updateStorage(this.state.form),this.props.operation.setRequestValues(e)}))}}),Object.defineProperty(this,"handleTabChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({activeTab:e})}}),Object.defineProperty(this,"handleServerChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({server:e}),this.props.operation.setActiveServer(e)}}),Object.defineProperty(this,"handleExecute",{enumerable:!0,configurable:!0,writable:!0,value:async()=>{var e,t,o,s,r,a,i,n,l,c;const{store:d,operation:p,onResponse:u}=this.props;null===(e=this.formApi)||void 0===e||e.submitForm();const{invalid:h}=(null===(t=this.formApi)||void 0===t?void 0:t.getState())||this.state.form;if(h)return this.setState({shaking:!0}),setTimeout((()=>this.setState({shaking:!1})),1e3),void(null===(s=null===(o=null==d?void 0:d.options.events)||void 0===o?void 0:o.tryItSent)||void 0===s||s.call(o,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"ValidationFailed",operationId:p.operationId,operationPath:p.path,operationHttpVerb:p.httpVerb,operationSummary:p.description}));const{values:m}=(null===(r=this.formApi)||void 0===r?void 0:r.getState())||this.state.form,{servers:v,requestBody:g}=this.props.operation,y=g&&g.content&&g.content.active&&g.content.active.name||"";let b=m.body;if(/json/.test(y))try{b=JSON.parse(b)}catch(e){console.error(e)}this.setState({loading:!0});const f=this.state.resolvedRawSpec,j=(p.httpVerb||"").toLowerCase();if(!v)throw console.error("Servers are not specified in your OpenAPI file. You can't use Try It Out console without specifying servers. If you use OpenAPI 2, make sure you configured host and basepath"),new Error("Servers are not specified");const O=v.find((e=>this.state.server.url.endsWith(e.url.endsWith("/")?e.url.substring(0,e.url.length-1):e.url))),P=Date.now();let S,x=m.auth;if(!isEmptyObject(m.auth)&&m.auth){const e=Object.keys(m.auth)[0],t=unescapeFormId(e);S=Object.assign(Object.assign({},f),{components:Object.assign(Object.assign({},null==f?void 0:f.components),{securitySchemes:Object.assign(Object.assign({},null==f?void 0:f.components.securitySchemes),{[t]:Object.assign(Object.assign({},null==f?void 0:f.components.securitySchemes[t]),{type:"openIdConnect"===(null==f?void 0:f.components.securitySchemes[t].type)?"oauth2":null==f?void 0:f.components.securitySchemes[t].type})})})});const o="cookie"===(null==f?void 0:f.components.securitySchemes[t].in)?"Cookie":t,s="cookie"===(null==f?void 0:f.components.securitySchemes[t].in)?`${null==f?void 0:f.components.securitySchemes[t].name}=${x[e]}`:x[e];x=Object.assign(Object.assign({},x),{[o]:s})}else S=Object.assign({},f);S.servers=v;const C=d.options.corsProxyUrl;C&&v.length&&(S.servers=v.map((e=>Object.assign(Object.assign({},e),{url:C+normalizeUrlProtocol(e.url)}))),S.paths=Object.assign(Object.assign({},S.paths),{[p.path]:Object.assign(Object.assign({},S.paths[p.path]),{[j]:Object.assign(Object.assign({},S.paths[p.path][j]),{servers:void 0}),servers:void 0})}));const _=(null===(i=null===(a=null==g?void 0:g.content)||void 0===a?void 0:a.active)||void 0===i?void 0:i.name)||null;if(_&&b&&isFileUploadMime(_)){const e=Object.values(b);b=e.length>1?e:e[0]}const A={server:C?C+normalizeUrlProtocol(O.url):O.url,serverVariables:this.state.server.variables,spec:S,pathName:p.path,method:p.httpVerb,parameters:Object.assign(Object.assign(Object.assign(Object.assign({},m.path),decodeKeysDeep(m.query)),m.header),m.cookie),securities:{authorized:x},requestBody:b,requestContentType:_,responseContentType:(null===(n=m.header)||void 0===n?void 0:n.Accept)||null,requestInterceptor:makeRequestInterceptor(d.options,p,x,m)};try{const e=await Swagger.execute(A),t=null==e?void 0:e.data;t instanceof Blob&&(isFileUploadMime(t.type)&&(e.fileInfo={rawData:t,fileName:getFileNameFromHeaders(e.headers)}),e.data=await t.text()),null==u||u({request:A,response:e}),this.setState({response:e,error:void 0})}catch(e){e&&e.response&&e.response.data instanceof Blob&&(e.response.data=await e.response.data.text(),null==u||u({request:A,response:e.response})),this.setState({response:void 0,error:e})}finally{this.setState({loading:!1,activeTab:1,time:Date.now()-P}),null===(c=null===(l=null==d?void 0:d.options.events)||void 0===l?void 0:l.tryItSent)||void 0===c||c.call(l,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"Sent",operationId:p.operationId,operationPath:p.path,operationHttpVerb:p.httpVerb,operationSummary:p.description})}}}),this.state={form:{values:{path:getParameters(e.operation.parameters,"path"),cookie:getParameters(e.operation.parameters,"cookie"),header:getParameters(e.operation.parameters,"header"),query:getParameters(e.operation.parameters,"query")}},shaking:!1,loading:!1,activeTab:0,server:{}}}async componentDidMount(){var e;const{store:t,operation:o}=this.props,s=await t.dereferenceSpecForTryIt(o);this.setState({resolvedRawSpec:s}),null===(e=this.formApi)||void 0===e||e.setValues({})}componentDidUpdate(e){e.operation!==this.props.operation&&this.setState({response:void 0,error:void 0,activeTab:0})}render(){const{operation:e,className:t,rootElement:o}=this.props,{shaking:s,activeTab:r,form:a,response:i,loading:n,error:l}=this.state,c=!(!i&&!l);return _jsxs(ConsoleWrapHook,Object.assign({shaking:s,className:t,rootElement:o},{children:[_jsxs(CodeHeader,{children:[_jsx(ConsoleBadges,{active:r,hasResponse:c,onChange:this.handleTabChange},void 0),this.props.onClose&&_jsx(CloseButton,Object.assign({onClick:this.props.onClose},{children:" ✕ "}),void 0)]},void 0),_jsx(ConsoleBody,Object.assign({hidden:0!==r,"data-cy":"console-request-body"},{children:this.renderRequest()}),void 0),_jsx(ConsoleBody,Object.assign({hidden:1!==r,"data-cy":"console-response-body"},{children:this.renderResponse()}),void 0),_jsx(ActionPanel,{hasResponse:c,params:a.values,operation:e,loading:n,execute:this.handleExecute},void 0)]}),void 0)}renderRequest(){var e;const{operation:t,store:o,properties:s,securityDefaults:r}=this.props,{form:a,resolvedRawSpec:i,server:n}=this.state,c=a.errors||{},d=c.path||c.cookie||c.header||c.query,p=i&&JsonPointer.get(i,t.pointer);let u=a.values&&a.values.auth&&Object.keys(a.values.auth)[0];u&&a.values.auth[u]||(u=void 0),!u||void 0===a.values.auth[u].token&&void 0===a.values.auth[u].client_id&&void 0===a.values.auth[u].client_secret||a.values.auth[u].token&&a.values.auth[u].token.access_token||(u=void 0),u&&null!=a.values.auth[u].username&&(a.values.auth[u].username&&a.values.auth[u].password||(u=void 0));const h=t.parameters||[],m=null===(e=null==o?void 0:o.options.hooks)||void 0===e?void 0:e.ReplaceTryItSecurityPanel;return!i&&_jsx(_Fragment,{children:"Loading..."},void 0)||_jsxs(Form,Object.assign({onValueChange:this.handleValueChange,getApi:this.setFormApi,style:Object.assign(Object.assign({},flexColumn),{margin:0})},{children:[_jsx(ServersDropdown,{operation:t,onChange:this.handleServerChange},void 0),_jsxs(Accordion,Object.assign({initialActiveIdx:t.security.length&&u?1:0},{children:[t.security.length&&this.formApi&&_jsx(TryItPanel,Object.assign({header:l("tryItAuth"),"data-cy":"security-trigger",renderChildrenHidden:!0,error:!u&&!!c.auth,success:!!u},{children:m?_jsx(AuthPanelHook,Object.assign({field:"auth",validate:requiredValidator},{children:e=>_jsx(RenderHook,{Hook:m,props:{server:n,operation:t,onChange:e,OAuth2:OAuth2}},void 0)}),void 0):_jsx(AuthPanel,{formApi:this.formApi,form:a,operation:t,activeServer:n.url,authCorsProxyUrl:o.options.authCorsProxyUrl,securityDefaults:r},void 0)}),void 0)||null,t.requestBody&&this.formApi&&_jsx(TryItPanel,Object.assign({header:l("tryItBody"),"data-cy":"body-trigger",renderChildrenHidden:!0,error:!!c.body},{children:_jsx(RequestBody,{validate:allowBodyErrors,formApi:this.formApi,body:t.requestBody,id:t.id,resolvedBody:null==p?void 0:p.requestBody,properties:s},void 0)}),void 0)||null,h.length&&_jsx(TryItPanel,Object.assign({header:l("tryItParameters"),"data-cy":"parameters-trigger",error:d,renderChildrenHidden:!0},{children:_jsx(OperationParameters,{operation:t,values:a.values,errors:a.errors||{}},void 0)}),void 0)||null]}),void 0)]}),void 0)}renderResponse(){const{response:e,error:t,time:o}=this.state;return _jsx(ResponsePanel,{response:e,error:t,time:o},void 0)}};Console=__decorate([observer],Console);export{Console};function allowBodyErrors(){}function ConsoleWrapHook(e){const{shaking:t,className:o,children:s,rootElement:r}=e,[a]=useDimensions(r);return _jsx(ConsoleWrap,Object.assign({shaking:t,className:o,"data-cy":"console",fullWidth:null==a?void 0:a.width},{children:s}),void 0)}function AuthPanelHook(e){const{fieldApi:t,render:o,userProps:s}=useField(Object.assign({},e)),{setValue:r}=t,{children:a}=s;return o(_jsx(_Fragment,{children:a(r)},void 0))}
2
2
  //# sourceMappingURL=Console.js.map
@@ -24,3 +24,4 @@ export declare function encodeSample(sample: ExampleModel, properties: RequestBo
24
24
  export declare const getStorageExampleKey: (operationId: string, activeMimeType: string, activeExample?: string | false | undefined, examples?: {
25
25
  [name: string]: ExampleModel;
26
26
  } | undefined) => string;
27
+ export declare const decodeKeysDeep: (obj: Record<string, any>) => Record<string, any>;
@@ -1,2 +1,2 @@
1
- import merge from"deepmerge";import{MediaTypes}from"../../types";import{arrayMergeStrategy}from"../../services/utils";import{fromSessionStorage,getParameterValue,setParameterValue,setSecurityDetails,toSessionStorage,unescapeFormId}from"../../utils";export function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}export function updateStorage(e){if(e.values.auth)for(const t of Object.keys(e.values.auth)){const r=e.values.auth[t];setSecurityDetails(t,r)}updateParameterStorage(e)}function updateParameterStorage(e){var t;for(const r of["path","query","header","cookie"])if(null===(t=e.values)||void 0===t?void 0:t[r])for(const t of Object.keys(e.values[r]))setParameterValue(r,t,e.values[r][t])}export const getParameters=(e,t)=>e.filter((e=>e.in===t)).reduce(((e,t)=>{const{in:r,name:a}=t;return e[a]=getParameterValue(r||"",a),e}),{});const pathTemplateRegExp=/(?:{)(.*?)(?:})/g;export function getServerWithVariables(e,t=0){const r=e[t],a=getDefaultOrStoredVariables(r);return Object.assign(Object.assign({},r),{variables:a})}export function getInitialServerWithVariables(e){const t=fromSessionStorage("serverUrl"),r=e.find((e=>e.url===t))||e[0],a=getDefaultOrStoredVariables(r);return Object.assign(Object.assign({},r),{variables:a})}export function expandVariables(e,t={}){return e.replace(pathTemplateRegExp,((e,r)=>t[r]||e))}export function expandDefaultServerVariables(e,t={}){return e.replace(pathTemplateRegExp,((e,r)=>t[r]&&t[r].default||e))}export function getDefaultOrStoredVariables(e){if(!(null==e?void 0:e.variables))return{};const t=fromSessionStorage("variables"),r=t&&JSON.parse(t)||{},a={};return Object.entries(e.variables||{}).forEach((([e,t])=>{a[e]=r[e]||t.default||""})),a}export function updateVariablesStorage(e,t){const r=fromSessionStorage("variables"),a=r&&JSON.parse(r)||{};toSessionStorage("variables",JSON.stringify(Object.assign(Object.assign({},a),{[e]:t})))}export function unescapeQueryParams(e){return Object.entries(e).reduce(((e,[t,r])=>(e[unescapeFormId(t)]=r,e)),{})}export function getFileNameFromHeaders(e){const t="filename=";for(const[r,a]of Object.entries(e))if("content-disposition"===r.toLowerCase()){const e=a.split(";").find((e=>e.trim().startsWith(t)));if(e)return e.split(t)[1]}return""}export const makeRequestInterceptor=({requestInterceptor:e,sendXUserAgentInTryIt:t,disableTryItRequestUrlEncoding:r},a,o,i)=>n=>{var s,l,u,c,d,p;r&&(n=Object.assign(Object.assign({},n),{url:decodeURIComponent(n.url)})),t&&(n.headers["X-User-Agent"]="Redocly Try it API console");const f=(null===(l=null===(s=null==a?void 0:a.requestValues)||void 0===s?void 0:s.header)||void 0===l?void 0:l.authorization)||(null===(c=null===(u=null==a?void 0:a.requestValues)||void 0===u?void 0:u.header)||void 0===c?void 0:c.Authorization)||(null===(d=null==i?void 0:i.header)||void 0===d?void 0:d.Authorization)||(null===(p=null==i?void 0:i.header)||void 0===p?void 0:p.authorization);return!(null==o?void 0:o.Authorization)&&f&&(n.headers.Authorization=f),(null==o?void 0:o.Cookie)&&(n.headers["X-Redocly-Cookie"]=o.Cookie),e?e(n,a):n};export const validateTokenEndpointMethod=e=>{if(!e)return!0;const t=Array.isArray(e)?e:[e];return!(t.length&&!t.includes("none")&&!t.includes("client_secret_basic"))};export const getOAuth2TokenEndpointAuthHeader=({authMethod:e,clientId:t,clientSecret:r})=>"client_secret_basic"===e||Array.isArray(e)&&e.includes("client_secret_basic")?{Authorization:`Basic ${btoa(t+":"+r)}`}:{};export function encodeSample(e,t){if(!e)return"";if(e.mime===MediaTypes.URL_ENCODED)return e.value;const r=e.value,a=t?merge(r,t,{arrayMerge:arrayMergeStrategy}):r;return JSON.stringify(a,null,2)}export const getStorageExampleKey=(e,t,r,a)=>{let o=e+"_"+t;return r&&a&&Object.keys(a).includes(r)&&(o+="_"+r),o};
1
+ import merge from"deepmerge";import{MediaTypes}from"../../types";import{arrayMergeStrategy}from"../../services/utils";import{fromSessionStorage,getParameterValue,setParameterValue,setSecurityDetails,toSessionStorage,unescapeFormId}from"../../utils";export function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}export function updateStorage(e){if(e.values.auth)for(const t of Object.keys(e.values.auth)){const r=e.values.auth[t];setSecurityDetails(t,r)}updateParameterStorage(e)}function updateParameterStorage(e){var t;for(const r of["path","query","header","cookie"])if(null===(t=e.values)||void 0===t?void 0:t[r])for(const t of Object.keys(e.values[r]))setParameterValue(r,t,e.values[r][t])}export const getParameters=(e,t)=>e.filter((e=>e.in===t)).reduce(((e,t)=>{const{in:r,name:o}=t;return e[o]=getParameterValue(r||"",o),e}),{});const pathTemplateRegExp=/(?:{)(.*?)(?:})/g;export function getServerWithVariables(e,t=0){const r=e[t],o=getDefaultOrStoredVariables(r);return Object.assign(Object.assign({},r),{variables:o})}export function getInitialServerWithVariables(e){const t=fromSessionStorage("serverUrl"),r=e.find((e=>e.url===t))||e[0],o=getDefaultOrStoredVariables(r);return Object.assign(Object.assign({},r),{variables:o})}export function expandVariables(e,t={}){return e.replace(pathTemplateRegExp,((e,r)=>t[r]||e))}export function expandDefaultServerVariables(e,t={}){return e.replace(pathTemplateRegExp,((e,r)=>t[r]&&t[r].default||e))}export function getDefaultOrStoredVariables(e){if(!(null==e?void 0:e.variables))return{};const t=fromSessionStorage("variables"),r=t&&JSON.parse(t)||{},o={};return Object.entries(e.variables||{}).forEach((([e,t])=>{o[e]=r[e]||t.default||""})),o}export function updateVariablesStorage(e,t){const r=fromSessionStorage("variables"),o=r&&JSON.parse(r)||{};toSessionStorage("variables",JSON.stringify(Object.assign(Object.assign({},o),{[e]:t})))}export function unescapeQueryParams(e){return Object.entries(e).reduce(((e,[t,r])=>(e[unescapeFormId(t)]=r,e)),{})}export function getFileNameFromHeaders(e){const t="filename=";for(const[r,o]of Object.entries(e))if("content-disposition"===r.toLowerCase()){const e=o.split(";").find((e=>e.trim().startsWith(t)));if(e)return e.split(t)[1]}return""}export const makeRequestInterceptor=({requestInterceptor:e,sendXUserAgentInTryIt:t,disableTryItRequestUrlEncoding:r},o,a,n)=>i=>{var s,l,u,c,d,p;r&&(i=Object.assign(Object.assign({},i),{url:decodeURIComponent(i.url)})),t&&(i.headers["X-User-Agent"]="Redocly Try it API console");const f=(null===(l=null===(s=null==o?void 0:o.requestValues)||void 0===s?void 0:s.header)||void 0===l?void 0:l.authorization)||(null===(c=null===(u=null==o?void 0:o.requestValues)||void 0===u?void 0:u.header)||void 0===c?void 0:c.Authorization)||(null===(d=null==n?void 0:n.header)||void 0===d?void 0:d.Authorization)||(null===(p=null==n?void 0:n.header)||void 0===p?void 0:p.authorization);return!(null==a?void 0:a.Authorization)&&f&&(i.headers.Authorization=f),(null==a?void 0:a.Cookie)&&(i.headers["X-Redocly-Cookie"]=a.Cookie),e?e(i,o):i};export const validateTokenEndpointMethod=e=>{if(!e)return!0;const t=Array.isArray(e)?e:[e];return!(t.length&&!t.includes("none")&&!t.includes("client_secret_basic"))};export const getOAuth2TokenEndpointAuthHeader=({authMethod:e,clientId:t,clientSecret:r})=>"client_secret_basic"===e||Array.isArray(e)&&e.includes("client_secret_basic")?{Authorization:`Basic ${btoa(t+":"+r)}`}:{};export function encodeSample(e,t){if(!e)return"";if(e.mime===MediaTypes.URL_ENCODED)return e.value;const r=e.value,o=t?merge(r,t,{arrayMerge:arrayMergeStrategy}):r;return JSON.stringify(o,null,2)}export const getStorageExampleKey=(e,t,r,o)=>{let a=e+"_"+t;return r&&o&&Object.keys(o).includes(r)&&(a+="_"+r),a};export const decodeKeysDeep=e=>{if(Array.isArray(e))return e.map((e=>decodeKeysDeep(e)));if(null!==e&&"object"==typeof e){const t={};for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)){t[decodeURIComponent(r)]=decodeKeysDeep(e[r])}return t}return e};
2
2
  //# sourceMappingURL=utils.js.map
@@ -1,2 +1,2 @@
1
- import{IS_BROWSER}from"./redoc-lib/src/utils";let _store;export const getGlobalStore=()=>_store;export const setGlobalStore=e=>_store=e;export function debounce(e,t,o){let r,n=0;return function(...s){n++,r?clearTimeout(r):o&&e(...s),r=setTimeout((function(){n>1&&e(...s),n=0,r=null}),t)}}export function toSessionStorage(e,t){IS_BROWSER&&window.sessionStorage.setItem("redoc."+e,t)}export function fromSessionStorage(e){return IS_BROWSER&&window.sessionStorage.getItem("redoc."+e)||""}export function setParameterValue(e,t,o){toSessionStorage(`${e}.${t}`,JSON.stringify(o))}export function getParameterValue(e,t){try{return JSON.parse(fromSessionStorage(`${e}.${t}`))}catch(e){return null}}export function toLocalStorage(e,t){window.localStorage.setItem("redoc."+e,t)}export function fromLocalStorage(e){return IS_BROWSER&&window.localStorage.getItem("redoc."+e)||""}export function escapeFormId(e){return e.replace(/[.[\]]/g,(e=>({".":"%2e","[":"%5b","]":"%5d"}[e]||"")))}export function unescapeFormId(e){return e.replace(/%2e|%5b|%5d/g,(e=>({"%2e":".","%5b":"[","%5d":"]"}[e]||"")))}export function setSecurityDetails(e,t){e=escapeFormId(e),"string"==typeof t?toSessionStorage("auth."+e,t):t&&(toSessionStorage(`auth.${e}.password`,t.password||""),toSessionStorage(`auth.${e}.username`,t.username||""),toSessionStorage(`auth.${e}.token`,t.token&&JSON.stringify(t.token)||""),toSessionStorage(`auth.${e}.client_id`,t.client_id||""),toSessionStorage(`auth.${e}.client_secret`,t.client_secret||""),toSessionStorage(`auth.${e}.scopes`,t.scopes&&JSON.stringify(t.scopes)||""))}export function setSecurityDetailsVariants(e,t){toSessionStorage(`auth.${e=escapeFormId(e)}.variants`,JSON.stringify(t))}export function getSecurityDetails(e){const t=fromSessionStorage(`auth.${e=escapeFormId(e)}`),o=fromSessionStorage(`auth.${e}.token`);return{raw:t,password:fromSessionStorage(`auth.${e}.password`),username:fromSessionStorage(`auth.${e}.username`),token:o&&JSON.parse(o)||null,client_id:fromSessionStorage(`auth.${e}.client_id`),client_secret:fromSessionStorage(`auth.${e}.client_secret`),scopes:fromSessionStorage(`auth.${e}.scopes`)}}export function getSecurityDetailsOptions(e,t){const o=fromSessionStorage(`auth.${e=escapeFormId(e)}.variants`);if(!o)return null;const r=JSON.parse(o);return r&&Array.isArray(r)?r.map((e=>e.details?""===t&&e.details&&"string"==typeof e.details?{label:e.label,value:e.details}:"object"==typeof e.details?{label:e.label,value:e.details[t]}:null:null)).filter(notNull):null}function notNull(e){return null!==e}export function get(e={},t,o){return"string"==typeof t&&(t=t.split(".")),t.reduce(((e,t)=>e&&e[t]?e[t]:o),e)}export function joinStringFactory(e){return(...t)=>t.filter(Boolean).join(e)}export const dottedString=joinStringFactory(".");export function getWindowReferenceOptions(e){var t;return IS_BROWSER?null===(t=null===window||void 0===window?void 0:window.REFERENCE_DOCS_OPTIONS)||void 0===t?void 0:t[e]:null}export function getJsUrl(){var e;if(!IS_BROWSER)return"";const t=+new Date+Math.random();try{return document.currentScript&&(document.currentScript.async||document.currentScript.defer)||document.write(`<script id="dummy${t}"><\/script>`),(null===(e=document.getElementById("dummy"+t))||void 0===e?void 0:e.previousSibling).src}catch(e){return""}}
1
+ import{IS_BROWSER}from"./redoc-lib/src/utils";let _store;export const getGlobalStore=()=>_store;export const setGlobalStore=e=>_store=e;export function debounce(e,t,o){let r,n=0;return function(...s){n++,r?clearTimeout(r):o&&e(...s),r=setTimeout((function(){n>1&&e(...s),n=0,r=null}),t)}}export function toSessionStorage(e,t){IS_BROWSER&&window.sessionStorage.setItem("redoc."+e,t)}export function fromSessionStorage(e){return IS_BROWSER&&window.sessionStorage.getItem("redoc."+e)||""}export function setParameterValue(e,t,o){toSessionStorage(`${e}.${t}`,JSON.stringify(o))}export function getParameterValue(e,t){try{return JSON.parse(fromSessionStorage(`${e}.${t}`)||fromSessionStorage(`${e}.${decodeURIComponent(t)}`))}catch(e){return null}}export function toLocalStorage(e,t){window.localStorage.setItem("redoc."+e,t)}export function fromLocalStorage(e){return IS_BROWSER&&window.localStorage.getItem("redoc."+e)||""}export function escapeFormId(e){return e.replace(/[.[\]]/g,(e=>({".":"%2e","[":"%5b","]":"%5d"}[e]||"")))}export function unescapeFormId(e){return e.replace(/%2e|%5b|%5d/g,(e=>({"%2e":".","%5b":"[","%5d":"]"}[e]||"")))}export function setSecurityDetails(e,t){e=escapeFormId(e),"string"==typeof t?toSessionStorage("auth."+e,t):t&&(toSessionStorage(`auth.${e}.password`,t.password||""),toSessionStorage(`auth.${e}.username`,t.username||""),toSessionStorage(`auth.${e}.token`,t.token&&JSON.stringify(t.token)||""),toSessionStorage(`auth.${e}.client_id`,t.client_id||""),toSessionStorage(`auth.${e}.client_secret`,t.client_secret||""),toSessionStorage(`auth.${e}.scopes`,t.scopes&&JSON.stringify(t.scopes)||""))}export function setSecurityDetailsVariants(e,t){toSessionStorage(`auth.${e=escapeFormId(e)}.variants`,JSON.stringify(t))}export function getSecurityDetails(e){const t=fromSessionStorage(`auth.${e=escapeFormId(e)}`),o=fromSessionStorage(`auth.${e}.token`);return{raw:t,password:fromSessionStorage(`auth.${e}.password`),username:fromSessionStorage(`auth.${e}.username`),token:o&&JSON.parse(o)||null,client_id:fromSessionStorage(`auth.${e}.client_id`),client_secret:fromSessionStorage(`auth.${e}.client_secret`),scopes:fromSessionStorage(`auth.${e}.scopes`)}}export function getSecurityDetailsOptions(e,t){const o=fromSessionStorage(`auth.${e=escapeFormId(e)}.variants`);if(!o)return null;const r=JSON.parse(o);return r&&Array.isArray(r)?r.map((e=>e.details?""===t&&e.details&&"string"==typeof e.details?{label:e.label,value:e.details}:"object"==typeof e.details?{label:e.label,value:e.details[t]}:null:null)).filter(notNull):null}function notNull(e){return null!==e}export function get(e={},t,o){return"string"==typeof t&&(t=t.split(".")),t.reduce(((e,t)=>e&&e[t]?e[t]:o),e)}export function joinStringFactory(e){return(...t)=>t.filter(Boolean).join(e)}export const dottedString=joinStringFactory(".");export function getWindowReferenceOptions(e){var t;return IS_BROWSER?null===(t=null===window||void 0===window?void 0:window.REFERENCE_DOCS_OPTIONS)||void 0===t?void 0:t[e]:null}export function getJsUrl(){var e;if(!IS_BROWSER)return"";const t=+new Date+Math.random();try{return document.currentScript&&(document.currentScript.async||document.currentScript.defer)||document.write(`<script id="dummy${t}"><\/script>`),(null===(e=document.getElementById("dummy"+t))||void 0===e?void 0:e.previousSibling).src}catch(e){return""}}
2
2
  //# sourceMappingURL=utils.js.map
@@ -1,2 +1,2 @@
1
- import{__decorate,__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{Form,useField}from"informed";import{observer}from"mobx-react";import Swagger from"swagger-client";import{Component}from"react";import{unescapeFormId}from"../../utils";import{JsonPointer}from"../../redoc-lib";import{RenderHook}from"../../redoc-lib/src/components/RenderHook";import{l}from"../../redoc-lib/src/services/Labels";import{CodeHeader,Accordion}from"../Panel";import{OAuth2}from"../../services/OAuth2";import{isFileUploadMime}from"../common/FileUpload/helper";import{OperationParameters}from"../OperationParameters";import{useDimensions}from"../../hooks";import{AnalyticsEventType}from"../../events";import{isEmptyObject}from"../../services/utils";import{getFileNameFromHeaders,getParameters,makeRequestInterceptor,unescapeQueryParams,updateStorage}from"./utils";import{AuthPanel,requiredValidator}from"./AuthPanel";import{ConsoleBadges}from"./ConsoleBadges";import{RequestBody}from"./RequestBody";import{ResponsePanel}from"./ResponsePanel";import{ActionPanel}from"./ActionPanel";import{ServersDropdown}from"./ServersDropdown";import{TryItPanel}from"./TryItPanel";import{CloseButton,ConsoleBody,ConsoleWrap}from"./styled";function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}const flexColumn={flex:1,display:"flex",flexDirection:"column"};let Console=class extends Component{constructor(e){super(e),Object.defineProperty(this,"formApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setFormApi",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.formApi=e;const t=e.getState(),{values:o}=t,s=__rest(t,["values"]);setTimeout((()=>{const e=Object.assign(Object.assign({},s),{values:Object.assign(Object.assign({},o),{query:unescapeQueryParams(o.query||{}),path:unescapeQueryParams(o.path||{})})});this.setState({form:e})}),0)}}),Object.defineProperty(this,"handleValueChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=Object.assign(Object.assign({},e),{query:unescapeQueryParams(e.query||{}),path:unescapeQueryParams(e.path||{})});this.setState((e=>({form:Object.assign(Object.assign({},e.form),{values:t})})),(()=>{updateStorage(this.state.form),this.props.operation.setRequestValues(e)}))}}),Object.defineProperty(this,"handleTabChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({activeTab:e})}}),Object.defineProperty(this,"handleServerChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({server:e}),this.props.operation.setActiveServer(e)}}),Object.defineProperty(this,"handleExecute",{enumerable:!0,configurable:!0,writable:!0,value:async()=>{var e,t,o,s,r,a,i,n,l,c;const{store:d,operation:p,onResponse:u}=this.props;null===(e=this.formApi)||void 0===e||e.submitForm();const{invalid:h}=(null===(t=this.formApi)||void 0===t?void 0:t.getState())||this.state.form;if(h)return this.setState({shaking:!0}),setTimeout((()=>this.setState({shaking:!1})),1e3),void(null===(s=null===(o=null==d?void 0:d.options.events)||void 0===o?void 0:o.tryItSent)||void 0===s||s.call(o,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"ValidationFailed",operationId:p.operationId,operationPath:p.path,operationHttpVerb:p.httpVerb,operationSummary:p.description}));const{values:m}=(null===(r=this.formApi)||void 0===r?void 0:r.getState())||this.state.form,{servers:v,requestBody:g}=this.props.operation,y=g&&g.content&&g.content.active&&g.content.active.name||"";let b=m.body;if(/json/.test(y))try{b=JSON.parse(b)}catch(e){console.error(e)}this.setState({loading:!0});const f=this.state.resolvedRawSpec,j=(p.httpVerb||"").toLowerCase();if(!v)throw console.error("Servers are not specified in your OpenAPI file. You can't use Try It Out console without specifying servers. If you use OpenAPI 2, make sure you configured host and basepath"),new Error("Servers are not specified");const O=v.find((e=>this.state.server.url.endsWith(e.url.endsWith("/")?e.url.substring(0,e.url.length-1):e.url))),P=Date.now();let S,x=m.auth;if(!isEmptyObject(m.auth)&&m.auth){const e=Object.keys(m.auth)[0],t=unescapeFormId(e);S=Object.assign(Object.assign({},f),{components:Object.assign(Object.assign({},null==f?void 0:f.components),{securitySchemes:Object.assign(Object.assign({},null==f?void 0:f.components.securitySchemes),{[t]:Object.assign(Object.assign({},null==f?void 0:f.components.securitySchemes[t]),{type:"openIdConnect"===(null==f?void 0:f.components.securitySchemes[t].type)?"oauth2":null==f?void 0:f.components.securitySchemes[t].type})})})});const o="cookie"===(null==f?void 0:f.components.securitySchemes[t].in)?"Cookie":t,s="cookie"===(null==f?void 0:f.components.securitySchemes[t].in)?`${null==f?void 0:f.components.securitySchemes[t].name}=${x[e]}`:x[e];x=Object.assign(Object.assign({},x),{[o]:s})}else S=Object.assign({},f);S.servers=v;const C=d.options.corsProxyUrl;C&&v.length&&(S.servers=v.map((e=>Object.assign(Object.assign({},e),{url:C+normalizeUrlProtocol(e.url)}))),S.paths=Object.assign(Object.assign({},S.paths),{[p.path]:Object.assign(Object.assign({},S.paths[p.path]),{[j]:Object.assign(Object.assign({},S.paths[p.path][j]),{servers:void 0}),servers:void 0})}));const _=(null===(i=null===(a=null==g?void 0:g.content)||void 0===a?void 0:a.active)||void 0===i?void 0:i.name)||null;if(_&&b&&isFileUploadMime(_)){const e=Object.values(b);b=e.length>1?e:e[0]}const A={server:C?C+normalizeUrlProtocol(O.url):O.url,serverVariables:this.state.server.variables,spec:S,pathName:p.path,method:p.httpVerb,parameters:Object.assign(Object.assign(Object.assign(Object.assign({},m.path),m.query),m.header),m.cookie),securities:{authorized:x},requestBody:b,requestContentType:_,responseContentType:(null===(n=m.header)||void 0===n?void 0:n.Accept)||null,requestInterceptor:makeRequestInterceptor(d.options,p,x,m)};try{const e=await Swagger.execute(A),t=null==e?void 0:e.data;t instanceof Blob&&(isFileUploadMime(t.type)&&(e.fileInfo={rawData:t,fileName:getFileNameFromHeaders(e.headers)}),e.data=await t.text()),null==u||u({request:A,response:e}),this.setState({response:e,error:void 0})}catch(e){e&&e.response&&e.response.data instanceof Blob&&(e.response.data=await e.response.data.text(),null==u||u({request:A,response:e.response})),this.setState({response:void 0,error:e})}finally{this.setState({loading:!1,activeTab:1,time:Date.now()-P}),null===(c=null===(l=null==d?void 0:d.options.events)||void 0===l?void 0:l.tryItSent)||void 0===c||c.call(l,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"Sent",operationId:p.operationId,operationPath:p.path,operationHttpVerb:p.httpVerb,operationSummary:p.description})}}}),this.state={form:{values:{path:getParameters(e.operation.parameters,"path"),cookie:getParameters(e.operation.parameters,"cookie"),header:getParameters(e.operation.parameters,"header"),query:getParameters(e.operation.parameters,"query")}},shaking:!1,loading:!1,activeTab:0,server:{}}}async componentDidMount(){var e;const{store:t,operation:o}=this.props,s=await t.dereferenceSpecForTryIt(o);this.setState({resolvedRawSpec:s}),null===(e=this.formApi)||void 0===e||e.setValues({})}componentDidUpdate(e){e.operation!==this.props.operation&&this.setState({response:void 0,error:void 0,activeTab:0})}render(){const{operation:e,className:t,rootElement:o}=this.props,{shaking:s,activeTab:r,form:a,response:i,loading:n,error:l}=this.state,c=!(!i&&!l);return _jsxs(ConsoleWrapHook,Object.assign({shaking:s,className:t,rootElement:o},{children:[_jsxs(CodeHeader,{children:[_jsx(ConsoleBadges,{active:r,hasResponse:c,onChange:this.handleTabChange},void 0),this.props.onClose&&_jsx(CloseButton,Object.assign({onClick:this.props.onClose},{children:" ✕ "}),void 0)]},void 0),_jsx(ConsoleBody,Object.assign({hidden:0!==r,"data-cy":"console-request-body"},{children:this.renderRequest()}),void 0),_jsx(ConsoleBody,Object.assign({hidden:1!==r,"data-cy":"console-response-body"},{children:this.renderResponse()}),void 0),_jsx(ActionPanel,{hasResponse:c,params:a.values,operation:e,loading:n,execute:this.handleExecute},void 0)]}),void 0)}renderRequest(){var e;const{operation:t,store:o,properties:s,securityDefaults:r}=this.props,{form:a,resolvedRawSpec:i,server:n}=this.state,c=a.errors||{},d=c.path||c.cookie||c.header||c.query,p=i&&JsonPointer.get(i,t.pointer);let u=a.values&&a.values.auth&&Object.keys(a.values.auth)[0];u&&a.values.auth[u]||(u=void 0),!u||void 0===a.values.auth[u].token&&void 0===a.values.auth[u].client_id&&void 0===a.values.auth[u].client_secret||a.values.auth[u].token&&a.values.auth[u].token.access_token||(u=void 0),u&&null!=a.values.auth[u].username&&(a.values.auth[u].username&&a.values.auth[u].password||(u=void 0));const h=t.parameters||[],m=null===(e=null==o?void 0:o.options.hooks)||void 0===e?void 0:e.ReplaceTryItSecurityPanel;return!i&&_jsx(_Fragment,{children:"Loading..."},void 0)||_jsxs(Form,Object.assign({onValueChange:this.handleValueChange,getApi:this.setFormApi,style:Object.assign(Object.assign({},flexColumn),{margin:0})},{children:[_jsx(ServersDropdown,{operation:t,onChange:this.handleServerChange},void 0),_jsxs(Accordion,Object.assign({initialActiveIdx:t.security.length&&u?1:0},{children:[t.security.length&&this.formApi&&_jsx(TryItPanel,Object.assign({header:l("tryItAuth"),"data-cy":"security-trigger",renderChildrenHidden:!0,error:!u&&!!c.auth,success:!!u},{children:m?_jsx(AuthPanelHook,Object.assign({field:"auth",validate:requiredValidator},{children:e=>_jsx(RenderHook,{Hook:m,props:{server:n,operation:t,onChange:e,OAuth2:OAuth2}},void 0)}),void 0):_jsx(AuthPanel,{formApi:this.formApi,form:a,operation:t,activeServer:n.url,authCorsProxyUrl:o.options.authCorsProxyUrl,securityDefaults:r},void 0)}),void 0)||null,t.requestBody&&this.formApi&&_jsx(TryItPanel,Object.assign({header:l("tryItBody"),"data-cy":"body-trigger",renderChildrenHidden:!0,error:!!c.body},{children:_jsx(RequestBody,{validate:allowBodyErrors,formApi:this.formApi,body:t.requestBody,id:t.id,resolvedBody:null==p?void 0:p.requestBody,properties:s},void 0)}),void 0)||null,h.length&&_jsx(TryItPanel,Object.assign({header:l("tryItParameters"),"data-cy":"parameters-trigger",error:d,renderChildrenHidden:!0},{children:_jsx(OperationParameters,{operation:t,values:a.values,errors:a.errors||{}},void 0)}),void 0)||null]}),void 0)]}),void 0)}renderResponse(){const{response:e,error:t,time:o}=this.state;return _jsx(ResponsePanel,{response:e,error:t,time:o},void 0)}};Console=__decorate([observer],Console);export{Console};function allowBodyErrors(){}function ConsoleWrapHook(e){const{shaking:t,className:o,children:s,rootElement:r}=e,[a]=useDimensions(r);return _jsx(ConsoleWrap,Object.assign({shaking:t,className:o,"data-cy":"console",fullWidth:null==a?void 0:a.width},{children:s}),void 0)}function AuthPanelHook(e){const{fieldApi:t,render:o,userProps:s}=useField(Object.assign({},e)),{setValue:r}=t,{children:a}=s;return o(_jsx(_Fragment,{children:a(r)},void 0))}
1
+ import{__decorate,__rest}from"tslib";import{jsx as _jsx,jsxs as _jsxs,Fragment as _Fragment}from"react/jsx-runtime";import{Form,useField}from"informed";import{observer}from"mobx-react";import Swagger from"swagger-client";import{Component}from"react";import{unescapeFormId}from"../../utils";import{JsonPointer}from"../../redoc-lib";import{RenderHook}from"../../redoc-lib/src/components/RenderHook";import{l}from"../../redoc-lib/src/services/Labels";import{CodeHeader,Accordion}from"../Panel";import{OAuth2}from"../../services/OAuth2";import{isFileUploadMime}from"../common/FileUpload/helper";import{OperationParameters}from"../OperationParameters";import{useDimensions}from"../../hooks";import{AnalyticsEventType}from"../../events";import{isEmptyObject}from"../../services/utils";import{getFileNameFromHeaders,getParameters,makeRequestInterceptor,unescapeQueryParams,updateStorage,decodeKeysDeep}from"./utils";import{AuthPanel,requiredValidator}from"./AuthPanel";import{ConsoleBadges}from"./ConsoleBadges";import{RequestBody}from"./RequestBody";import{ResponsePanel}from"./ResponsePanel";import{ActionPanel}from"./ActionPanel";import{ServersDropdown}from"./ServersDropdown";import{TryItPanel}from"./TryItPanel";import{CloseButton,ConsoleBody,ConsoleWrap}from"./styled";function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}const flexColumn={flex:1,display:"flex",flexDirection:"column"};let Console=class extends Component{constructor(e){super(e),Object.defineProperty(this,"formApi",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"setFormApi",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.formApi=e;const t=e.getState(),{values:o}=t,s=__rest(t,["values"]);setTimeout((()=>{const e=Object.assign(Object.assign({},s),{values:Object.assign(Object.assign({},o),{query:unescapeQueryParams(o.query||{}),path:unescapeQueryParams(o.path||{})})});this.setState({form:e})}),0)}}),Object.defineProperty(this,"handleValueChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{const t=Object.assign(Object.assign({},e),{query:unescapeQueryParams(e.query||{}),path:unescapeQueryParams(e.path||{})});this.setState((e=>({form:Object.assign(Object.assign({},e.form),{values:t})})),(()=>{updateStorage(this.state.form),this.props.operation.setRequestValues(e)}))}}),Object.defineProperty(this,"handleTabChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({activeTab:e})}}),Object.defineProperty(this,"handleServerChange",{enumerable:!0,configurable:!0,writable:!0,value:e=>{this.setState({server:e}),this.props.operation.setActiveServer(e)}}),Object.defineProperty(this,"handleExecute",{enumerable:!0,configurable:!0,writable:!0,value:async()=>{var e,t,o,s,r,a,i,n,l,c;const{store:d,operation:p,onResponse:u}=this.props;null===(e=this.formApi)||void 0===e||e.submitForm();const{invalid:h}=(null===(t=this.formApi)||void 0===t?void 0:t.getState())||this.state.form;if(h)return this.setState({shaking:!0}),setTimeout((()=>this.setState({shaking:!1})),1e3),void(null===(s=null===(o=null==d?void 0:d.options.events)||void 0===o?void 0:o.tryItSent)||void 0===s||s.call(o,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"ValidationFailed",operationId:p.operationId,operationPath:p.path,operationHttpVerb:p.httpVerb,operationSummary:p.description}));const{values:m}=(null===(r=this.formApi)||void 0===r?void 0:r.getState())||this.state.form,{servers:v,requestBody:g}=this.props.operation,y=g&&g.content&&g.content.active&&g.content.active.name||"";let b=m.body;if(/json/.test(y))try{b=JSON.parse(b)}catch(e){console.error(e)}this.setState({loading:!0});const f=this.state.resolvedRawSpec,j=(p.httpVerb||"").toLowerCase();if(!v)throw console.error("Servers are not specified in your OpenAPI file. You can't use Try It Out console without specifying servers. If you use OpenAPI 2, make sure you configured host and basepath"),new Error("Servers are not specified");const O=v.find((e=>this.state.server.url.endsWith(e.url.endsWith("/")?e.url.substring(0,e.url.length-1):e.url))),P=Date.now();let S,x=m.auth;if(!isEmptyObject(m.auth)&&m.auth){const e=Object.keys(m.auth)[0],t=unescapeFormId(e);S=Object.assign(Object.assign({},f),{components:Object.assign(Object.assign({},null==f?void 0:f.components),{securitySchemes:Object.assign(Object.assign({},null==f?void 0:f.components.securitySchemes),{[t]:Object.assign(Object.assign({},null==f?void 0:f.components.securitySchemes[t]),{type:"openIdConnect"===(null==f?void 0:f.components.securitySchemes[t].type)?"oauth2":null==f?void 0:f.components.securitySchemes[t].type})})})});const o="cookie"===(null==f?void 0:f.components.securitySchemes[t].in)?"Cookie":t,s="cookie"===(null==f?void 0:f.components.securitySchemes[t].in)?`${null==f?void 0:f.components.securitySchemes[t].name}=${x[e]}`:x[e];x=Object.assign(Object.assign({},x),{[o]:s})}else S=Object.assign({},f);S.servers=v;const C=d.options.corsProxyUrl;C&&v.length&&(S.servers=v.map((e=>Object.assign(Object.assign({},e),{url:C+normalizeUrlProtocol(e.url)}))),S.paths=Object.assign(Object.assign({},S.paths),{[p.path]:Object.assign(Object.assign({},S.paths[p.path]),{[j]:Object.assign(Object.assign({},S.paths[p.path][j]),{servers:void 0}),servers:void 0})}));const _=(null===(i=null===(a=null==g?void 0:g.content)||void 0===a?void 0:a.active)||void 0===i?void 0:i.name)||null;if(_&&b&&isFileUploadMime(_)){const e=Object.values(b);b=e.length>1?e:e[0]}const A={server:C?C+normalizeUrlProtocol(O.url):O.url,serverVariables:this.state.server.variables,spec:S,pathName:p.path,method:p.httpVerb,parameters:Object.assign(Object.assign(Object.assign(Object.assign({},m.path),decodeKeysDeep(m.query)),m.header),m.cookie),securities:{authorized:x},requestBody:b,requestContentType:_,responseContentType:(null===(n=m.header)||void 0===n?void 0:n.Accept)||null,requestInterceptor:makeRequestInterceptor(d.options,p,x,m)};try{const e=await Swagger.execute(A),t=null==e?void 0:e.data;t instanceof Blob&&(isFileUploadMime(t.type)&&(e.fileInfo={rawData:t,fileName:getFileNameFromHeaders(e.headers)}),e.data=await t.text()),null==u||u({request:A,response:e}),this.setState({response:e,error:void 0})}catch(e){e&&e.response&&e.response.data instanceof Blob&&(e.response.data=await e.response.data.text(),null==u||u({request:A,response:e.response})),this.setState({response:void 0,error:e})}finally{this.setState({loading:!1,activeTab:1,time:Date.now()-P}),null===(c=null===(l=null==d?void 0:d.options.events)||void 0===l?void 0:l.tryItSent)||void 0===c||c.call(l,{eventType:AnalyticsEventType.TryItSent,resource:"Redocly_OperationTryIt",action:"Sent",operationId:p.operationId,operationPath:p.path,operationHttpVerb:p.httpVerb,operationSummary:p.description})}}}),this.state={form:{values:{path:getParameters(e.operation.parameters,"path"),cookie:getParameters(e.operation.parameters,"cookie"),header:getParameters(e.operation.parameters,"header"),query:getParameters(e.operation.parameters,"query")}},shaking:!1,loading:!1,activeTab:0,server:{}}}async componentDidMount(){var e;const{store:t,operation:o}=this.props,s=await t.dereferenceSpecForTryIt(o);this.setState({resolvedRawSpec:s}),null===(e=this.formApi)||void 0===e||e.setValues({})}componentDidUpdate(e){e.operation!==this.props.operation&&this.setState({response:void 0,error:void 0,activeTab:0})}render(){const{operation:e,className:t,rootElement:o}=this.props,{shaking:s,activeTab:r,form:a,response:i,loading:n,error:l}=this.state,c=!(!i&&!l);return _jsxs(ConsoleWrapHook,Object.assign({shaking:s,className:t,rootElement:o},{children:[_jsxs(CodeHeader,{children:[_jsx(ConsoleBadges,{active:r,hasResponse:c,onChange:this.handleTabChange},void 0),this.props.onClose&&_jsx(CloseButton,Object.assign({onClick:this.props.onClose},{children:" ✕ "}),void 0)]},void 0),_jsx(ConsoleBody,Object.assign({hidden:0!==r,"data-cy":"console-request-body"},{children:this.renderRequest()}),void 0),_jsx(ConsoleBody,Object.assign({hidden:1!==r,"data-cy":"console-response-body"},{children:this.renderResponse()}),void 0),_jsx(ActionPanel,{hasResponse:c,params:a.values,operation:e,loading:n,execute:this.handleExecute},void 0)]}),void 0)}renderRequest(){var e;const{operation:t,store:o,properties:s,securityDefaults:r}=this.props,{form:a,resolvedRawSpec:i,server:n}=this.state,c=a.errors||{},d=c.path||c.cookie||c.header||c.query,p=i&&JsonPointer.get(i,t.pointer);let u=a.values&&a.values.auth&&Object.keys(a.values.auth)[0];u&&a.values.auth[u]||(u=void 0),!u||void 0===a.values.auth[u].token&&void 0===a.values.auth[u].client_id&&void 0===a.values.auth[u].client_secret||a.values.auth[u].token&&a.values.auth[u].token.access_token||(u=void 0),u&&null!=a.values.auth[u].username&&(a.values.auth[u].username&&a.values.auth[u].password||(u=void 0));const h=t.parameters||[],m=null===(e=null==o?void 0:o.options.hooks)||void 0===e?void 0:e.ReplaceTryItSecurityPanel;return!i&&_jsx(_Fragment,{children:"Loading..."},void 0)||_jsxs(Form,Object.assign({onValueChange:this.handleValueChange,getApi:this.setFormApi,style:Object.assign(Object.assign({},flexColumn),{margin:0})},{children:[_jsx(ServersDropdown,{operation:t,onChange:this.handleServerChange},void 0),_jsxs(Accordion,Object.assign({initialActiveIdx:t.security.length&&u?1:0},{children:[t.security.length&&this.formApi&&_jsx(TryItPanel,Object.assign({header:l("tryItAuth"),"data-cy":"security-trigger",renderChildrenHidden:!0,error:!u&&!!c.auth,success:!!u},{children:m?_jsx(AuthPanelHook,Object.assign({field:"auth",validate:requiredValidator},{children:e=>_jsx(RenderHook,{Hook:m,props:{server:n,operation:t,onChange:e,OAuth2:OAuth2}},void 0)}),void 0):_jsx(AuthPanel,{formApi:this.formApi,form:a,operation:t,activeServer:n.url,authCorsProxyUrl:o.options.authCorsProxyUrl,securityDefaults:r},void 0)}),void 0)||null,t.requestBody&&this.formApi&&_jsx(TryItPanel,Object.assign({header:l("tryItBody"),"data-cy":"body-trigger",renderChildrenHidden:!0,error:!!c.body},{children:_jsx(RequestBody,{validate:allowBodyErrors,formApi:this.formApi,body:t.requestBody,id:t.id,resolvedBody:null==p?void 0:p.requestBody,properties:s},void 0)}),void 0)||null,h.length&&_jsx(TryItPanel,Object.assign({header:l("tryItParameters"),"data-cy":"parameters-trigger",error:d,renderChildrenHidden:!0},{children:_jsx(OperationParameters,{operation:t,values:a.values,errors:a.errors||{}},void 0)}),void 0)||null]}),void 0)]}),void 0)}renderResponse(){const{response:e,error:t,time:o}=this.state;return _jsx(ResponsePanel,{response:e,error:t,time:o},void 0)}};Console=__decorate([observer],Console);export{Console};function allowBodyErrors(){}function ConsoleWrapHook(e){const{shaking:t,className:o,children:s,rootElement:r}=e,[a]=useDimensions(r);return _jsx(ConsoleWrap,Object.assign({shaking:t,className:o,"data-cy":"console",fullWidth:null==a?void 0:a.width},{children:s}),void 0)}function AuthPanelHook(e){const{fieldApi:t,render:o,userProps:s}=useField(Object.assign({},e)),{setValue:r}=t,{children:a}=s;return o(_jsx(_Fragment,{children:a(r)},void 0))}
2
2
  //# sourceMappingURL=Console.js.map
@@ -24,3 +24,4 @@ export declare function encodeSample(sample: ExampleModel, properties: RequestBo
24
24
  export declare const getStorageExampleKey: (operationId: string, activeMimeType: string, activeExample?: string | false | undefined, examples?: {
25
25
  [name: string]: ExampleModel;
26
26
  } | undefined) => string;
27
+ export declare const decodeKeysDeep: (obj: Record<string, any>) => Record<string, any>;
@@ -1,2 +1,2 @@
1
- import merge from"deepmerge";import{MediaTypes}from"../../types";import{arrayMergeStrategy}from"../../services/utils";import{fromSessionStorage,getParameterValue,setParameterValue,setSecurityDetails,toSessionStorage,unescapeFormId}from"../../utils";export function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}export function updateStorage(e){if(e.values.auth)for(const t of Object.keys(e.values.auth)){const r=e.values.auth[t];setSecurityDetails(t,r)}updateParameterStorage(e)}function updateParameterStorage(e){var t;for(const r of["path","query","header","cookie"])if(null===(t=e.values)||void 0===t?void 0:t[r])for(const t of Object.keys(e.values[r]))setParameterValue(r,t,e.values[r][t])}export const getParameters=(e,t)=>e.filter((e=>e.in===t)).reduce(((e,t)=>{const{in:r,name:a}=t;return e[a]=getParameterValue(r||"",a),e}),{});const pathTemplateRegExp=/(?:{)(.*?)(?:})/g;export function getServerWithVariables(e,t=0){const r=e[t],a=getDefaultOrStoredVariables(r);return Object.assign(Object.assign({},r),{variables:a})}export function getInitialServerWithVariables(e){const t=fromSessionStorage("serverUrl"),r=e.find((e=>e.url===t))||e[0],a=getDefaultOrStoredVariables(r);return Object.assign(Object.assign({},r),{variables:a})}export function expandVariables(e,t={}){return e.replace(pathTemplateRegExp,((e,r)=>t[r]||e))}export function expandDefaultServerVariables(e,t={}){return e.replace(pathTemplateRegExp,((e,r)=>t[r]&&t[r].default||e))}export function getDefaultOrStoredVariables(e){if(!(null==e?void 0:e.variables))return{};const t=fromSessionStorage("variables"),r=t&&JSON.parse(t)||{},a={};return Object.entries(e.variables||{}).forEach((([e,t])=>{a[e]=r[e]||t.default||""})),a}export function updateVariablesStorage(e,t){const r=fromSessionStorage("variables"),a=r&&JSON.parse(r)||{};toSessionStorage("variables",JSON.stringify(Object.assign(Object.assign({},a),{[e]:t})))}export function unescapeQueryParams(e){return Object.entries(e).reduce(((e,[t,r])=>(e[unescapeFormId(t)]=r,e)),{})}export function getFileNameFromHeaders(e){const t="filename=";for(const[r,a]of Object.entries(e))if("content-disposition"===r.toLowerCase()){const e=a.split(";").find((e=>e.trim().startsWith(t)));if(e)return e.split(t)[1]}return""}export const makeRequestInterceptor=({requestInterceptor:e,sendXUserAgentInTryIt:t,disableTryItRequestUrlEncoding:r},a,o,i)=>n=>{var s,l,u,c,d,p;r&&(n=Object.assign(Object.assign({},n),{url:decodeURIComponent(n.url)})),t&&(n.headers["X-User-Agent"]="Redocly Try it API console");const f=(null===(l=null===(s=null==a?void 0:a.requestValues)||void 0===s?void 0:s.header)||void 0===l?void 0:l.authorization)||(null===(c=null===(u=null==a?void 0:a.requestValues)||void 0===u?void 0:u.header)||void 0===c?void 0:c.Authorization)||(null===(d=null==i?void 0:i.header)||void 0===d?void 0:d.Authorization)||(null===(p=null==i?void 0:i.header)||void 0===p?void 0:p.authorization);return!(null==o?void 0:o.Authorization)&&f&&(n.headers.Authorization=f),(null==o?void 0:o.Cookie)&&(n.headers["X-Redocly-Cookie"]=o.Cookie),e?e(n,a):n};export const validateTokenEndpointMethod=e=>{if(!e)return!0;const t=Array.isArray(e)?e:[e];return!(t.length&&!t.includes("none")&&!t.includes("client_secret_basic"))};export const getOAuth2TokenEndpointAuthHeader=({authMethod:e,clientId:t,clientSecret:r})=>"client_secret_basic"===e||Array.isArray(e)&&e.includes("client_secret_basic")?{Authorization:`Basic ${btoa(t+":"+r)}`}:{};export function encodeSample(e,t){if(!e)return"";if(e.mime===MediaTypes.URL_ENCODED)return e.value;const r=e.value,a=t?merge(r,t,{arrayMerge:arrayMergeStrategy}):r;return JSON.stringify(a,null,2)}export const getStorageExampleKey=(e,t,r,a)=>{let o=e+"_"+t;return r&&a&&Object.keys(a).includes(r)&&(o+="_"+r),o};
1
+ import merge from"deepmerge";import{MediaTypes}from"../../types";import{arrayMergeStrategy}from"../../services/utils";import{fromSessionStorage,getParameterValue,setParameterValue,setSecurityDetails,toSessionStorage,unescapeFormId}from"../../utils";export function normalizeUrlProtocol(e){return e.startsWith("//")?"https:"+e:e}export function updateStorage(e){if(e.values.auth)for(const t of Object.keys(e.values.auth)){const r=e.values.auth[t];setSecurityDetails(t,r)}updateParameterStorage(e)}function updateParameterStorage(e){var t;for(const r of["path","query","header","cookie"])if(null===(t=e.values)||void 0===t?void 0:t[r])for(const t of Object.keys(e.values[r]))setParameterValue(r,t,e.values[r][t])}export const getParameters=(e,t)=>e.filter((e=>e.in===t)).reduce(((e,t)=>{const{in:r,name:o}=t;return e[o]=getParameterValue(r||"",o),e}),{});const pathTemplateRegExp=/(?:{)(.*?)(?:})/g;export function getServerWithVariables(e,t=0){const r=e[t],o=getDefaultOrStoredVariables(r);return Object.assign(Object.assign({},r),{variables:o})}export function getInitialServerWithVariables(e){const t=fromSessionStorage("serverUrl"),r=e.find((e=>e.url===t))||e[0],o=getDefaultOrStoredVariables(r);return Object.assign(Object.assign({},r),{variables:o})}export function expandVariables(e,t={}){return e.replace(pathTemplateRegExp,((e,r)=>t[r]||e))}export function expandDefaultServerVariables(e,t={}){return e.replace(pathTemplateRegExp,((e,r)=>t[r]&&t[r].default||e))}export function getDefaultOrStoredVariables(e){if(!(null==e?void 0:e.variables))return{};const t=fromSessionStorage("variables"),r=t&&JSON.parse(t)||{},o={};return Object.entries(e.variables||{}).forEach((([e,t])=>{o[e]=r[e]||t.default||""})),o}export function updateVariablesStorage(e,t){const r=fromSessionStorage("variables"),o=r&&JSON.parse(r)||{};toSessionStorage("variables",JSON.stringify(Object.assign(Object.assign({},o),{[e]:t})))}export function unescapeQueryParams(e){return Object.entries(e).reduce(((e,[t,r])=>(e[unescapeFormId(t)]=r,e)),{})}export function getFileNameFromHeaders(e){const t="filename=";for(const[r,o]of Object.entries(e))if("content-disposition"===r.toLowerCase()){const e=o.split(";").find((e=>e.trim().startsWith(t)));if(e)return e.split(t)[1]}return""}export const makeRequestInterceptor=({requestInterceptor:e,sendXUserAgentInTryIt:t,disableTryItRequestUrlEncoding:r},o,a,n)=>i=>{var s,l,u,c,d,p;r&&(i=Object.assign(Object.assign({},i),{url:decodeURIComponent(i.url)})),t&&(i.headers["X-User-Agent"]="Redocly Try it API console");const f=(null===(l=null===(s=null==o?void 0:o.requestValues)||void 0===s?void 0:s.header)||void 0===l?void 0:l.authorization)||(null===(c=null===(u=null==o?void 0:o.requestValues)||void 0===u?void 0:u.header)||void 0===c?void 0:c.Authorization)||(null===(d=null==n?void 0:n.header)||void 0===d?void 0:d.Authorization)||(null===(p=null==n?void 0:n.header)||void 0===p?void 0:p.authorization);return!(null==a?void 0:a.Authorization)&&f&&(i.headers.Authorization=f),(null==a?void 0:a.Cookie)&&(i.headers["X-Redocly-Cookie"]=a.Cookie),e?e(i,o):i};export const validateTokenEndpointMethod=e=>{if(!e)return!0;const t=Array.isArray(e)?e:[e];return!(t.length&&!t.includes("none")&&!t.includes("client_secret_basic"))};export const getOAuth2TokenEndpointAuthHeader=({authMethod:e,clientId:t,clientSecret:r})=>"client_secret_basic"===e||Array.isArray(e)&&e.includes("client_secret_basic")?{Authorization:`Basic ${btoa(t+":"+r)}`}:{};export function encodeSample(e,t){if(!e)return"";if(e.mime===MediaTypes.URL_ENCODED)return e.value;const r=e.value,o=t?merge(r,t,{arrayMerge:arrayMergeStrategy}):r;return JSON.stringify(o,null,2)}export const getStorageExampleKey=(e,t,r,o)=>{let a=e+"_"+t;return r&&o&&Object.keys(o).includes(r)&&(a+="_"+r),a};export const decodeKeysDeep=e=>{if(Array.isArray(e))return e.map((e=>decodeKeysDeep(e)));if(null!==e&&"object"==typeof e){const t={};for(const r in e)if(Object.prototype.hasOwnProperty.call(e,r)){t[decodeURIComponent(r)]=decodeKeysDeep(e[r])}return t}return e};
2
2
  //# sourceMappingURL=utils.js.map
package/lib-esm/utils.js CHANGED
@@ -1,2 +1,2 @@
1
- import{IS_BROWSER}from"./redoc-lib/src/utils";let _store;export const getGlobalStore=()=>_store;export const setGlobalStore=e=>_store=e;export function debounce(e,t,o){let r,n=0;return function(...s){n++,r?clearTimeout(r):o&&e(...s),r=setTimeout((function(){n>1&&e(...s),n=0,r=null}),t)}}export function toSessionStorage(e,t){IS_BROWSER&&window.sessionStorage.setItem("redoc."+e,t)}export function fromSessionStorage(e){return IS_BROWSER&&window.sessionStorage.getItem("redoc."+e)||""}export function setParameterValue(e,t,o){toSessionStorage(`${e}.${t}`,JSON.stringify(o))}export function getParameterValue(e,t){try{return JSON.parse(fromSessionStorage(`${e}.${t}`))}catch(e){return null}}export function toLocalStorage(e,t){window.localStorage.setItem("redoc."+e,t)}export function fromLocalStorage(e){return IS_BROWSER&&window.localStorage.getItem("redoc."+e)||""}export function escapeFormId(e){return e.replace(/[.[\]]/g,(e=>({".":"%2e","[":"%5b","]":"%5d"}[e]||"")))}export function unescapeFormId(e){return e.replace(/%2e|%5b|%5d/g,(e=>({"%2e":".","%5b":"[","%5d":"]"}[e]||"")))}export function setSecurityDetails(e,t){e=escapeFormId(e),"string"==typeof t?toSessionStorage("auth."+e,t):t&&(toSessionStorage(`auth.${e}.password`,t.password||""),toSessionStorage(`auth.${e}.username`,t.username||""),toSessionStorage(`auth.${e}.token`,t.token&&JSON.stringify(t.token)||""),toSessionStorage(`auth.${e}.client_id`,t.client_id||""),toSessionStorage(`auth.${e}.client_secret`,t.client_secret||""),toSessionStorage(`auth.${e}.scopes`,t.scopes&&JSON.stringify(t.scopes)||""))}export function setSecurityDetailsVariants(e,t){toSessionStorage(`auth.${e=escapeFormId(e)}.variants`,JSON.stringify(t))}export function getSecurityDetails(e){const t=fromSessionStorage(`auth.${e=escapeFormId(e)}`),o=fromSessionStorage(`auth.${e}.token`);return{raw:t,password:fromSessionStorage(`auth.${e}.password`),username:fromSessionStorage(`auth.${e}.username`),token:o&&JSON.parse(o)||null,client_id:fromSessionStorage(`auth.${e}.client_id`),client_secret:fromSessionStorage(`auth.${e}.client_secret`),scopes:fromSessionStorage(`auth.${e}.scopes`)}}export function getSecurityDetailsOptions(e,t){const o=fromSessionStorage(`auth.${e=escapeFormId(e)}.variants`);if(!o)return null;const r=JSON.parse(o);return r&&Array.isArray(r)?r.map((e=>e.details?""===t&&e.details&&"string"==typeof e.details?{label:e.label,value:e.details}:"object"==typeof e.details?{label:e.label,value:e.details[t]}:null:null)).filter(notNull):null}function notNull(e){return null!==e}export function get(e={},t,o){return"string"==typeof t&&(t=t.split(".")),t.reduce(((e,t)=>e&&e[t]?e[t]:o),e)}export function joinStringFactory(e){return(...t)=>t.filter(Boolean).join(e)}export const dottedString=joinStringFactory(".");export function getWindowReferenceOptions(e){var t;return IS_BROWSER?null===(t=null===window||void 0===window?void 0:window.REFERENCE_DOCS_OPTIONS)||void 0===t?void 0:t[e]:null}export function getJsUrl(){var e;if(!IS_BROWSER)return"";const t=+new Date+Math.random();try{return document.currentScript&&(document.currentScript.async||document.currentScript.defer)||document.write(`<script id="dummy${t}"><\/script>`),(null===(e=document.getElementById("dummy"+t))||void 0===e?void 0:e.previousSibling).src}catch(e){return""}}
1
+ import{IS_BROWSER}from"./redoc-lib/src/utils";let _store;export const getGlobalStore=()=>_store;export const setGlobalStore=e=>_store=e;export function debounce(e,t,o){let r,n=0;return function(...s){n++,r?clearTimeout(r):o&&e(...s),r=setTimeout((function(){n>1&&e(...s),n=0,r=null}),t)}}export function toSessionStorage(e,t){IS_BROWSER&&window.sessionStorage.setItem("redoc."+e,t)}export function fromSessionStorage(e){return IS_BROWSER&&window.sessionStorage.getItem("redoc."+e)||""}export function setParameterValue(e,t,o){toSessionStorage(`${e}.${t}`,JSON.stringify(o))}export function getParameterValue(e,t){try{return JSON.parse(fromSessionStorage(`${e}.${t}`)||fromSessionStorage(`${e}.${decodeURIComponent(t)}`))}catch(e){return null}}export function toLocalStorage(e,t){window.localStorage.setItem("redoc."+e,t)}export function fromLocalStorage(e){return IS_BROWSER&&window.localStorage.getItem("redoc."+e)||""}export function escapeFormId(e){return e.replace(/[.[\]]/g,(e=>({".":"%2e","[":"%5b","]":"%5d"}[e]||"")))}export function unescapeFormId(e){return e.replace(/%2e|%5b|%5d/g,(e=>({"%2e":".","%5b":"[","%5d":"]"}[e]||"")))}export function setSecurityDetails(e,t){e=escapeFormId(e),"string"==typeof t?toSessionStorage("auth."+e,t):t&&(toSessionStorage(`auth.${e}.password`,t.password||""),toSessionStorage(`auth.${e}.username`,t.username||""),toSessionStorage(`auth.${e}.token`,t.token&&JSON.stringify(t.token)||""),toSessionStorage(`auth.${e}.client_id`,t.client_id||""),toSessionStorage(`auth.${e}.client_secret`,t.client_secret||""),toSessionStorage(`auth.${e}.scopes`,t.scopes&&JSON.stringify(t.scopes)||""))}export function setSecurityDetailsVariants(e,t){toSessionStorage(`auth.${e=escapeFormId(e)}.variants`,JSON.stringify(t))}export function getSecurityDetails(e){const t=fromSessionStorage(`auth.${e=escapeFormId(e)}`),o=fromSessionStorage(`auth.${e}.token`);return{raw:t,password:fromSessionStorage(`auth.${e}.password`),username:fromSessionStorage(`auth.${e}.username`),token:o&&JSON.parse(o)||null,client_id:fromSessionStorage(`auth.${e}.client_id`),client_secret:fromSessionStorage(`auth.${e}.client_secret`),scopes:fromSessionStorage(`auth.${e}.scopes`)}}export function getSecurityDetailsOptions(e,t){const o=fromSessionStorage(`auth.${e=escapeFormId(e)}.variants`);if(!o)return null;const r=JSON.parse(o);return r&&Array.isArray(r)?r.map((e=>e.details?""===t&&e.details&&"string"==typeof e.details?{label:e.label,value:e.details}:"object"==typeof e.details?{label:e.label,value:e.details[t]}:null:null)).filter(notNull):null}function notNull(e){return null!==e}export function get(e={},t,o){return"string"==typeof t&&(t=t.split(".")),t.reduce(((e,t)=>e&&e[t]?e[t]:o),e)}export function joinStringFactory(e){return(...t)=>t.filter(Boolean).join(e)}export const dottedString=joinStringFactory(".");export function getWindowReferenceOptions(e){var t;return IS_BROWSER?null===(t=null===window||void 0===window?void 0:window.REFERENCE_DOCS_OPTIONS)||void 0===t?void 0:t[e]:null}export function getJsUrl(){var e;if(!IS_BROWSER)return"";const t=+new Date+Math.random();try{return document.currentScript&&(document.currentScript.async||document.currentScript.defer)||document.write(`<script id="dummy${t}"><\/script>`),(null===(e=document.getElementById("dummy"+t))||void 0===e?void 0:e.previousSibling).src}catch(e){return""}}
2
2
  //# sourceMappingURL=utils.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@redocly/reference-docs",
3
- "version": "2.45.8",
3
+ "version": "2.45.9",
4
4
  "description": "Redocly Reference Docs",
5
5
  "main": "lib/index.js",
6
6
  "module": "lib-esm/index.js",
@@ -48,7 +48,7 @@
48
48
  "stickyfill": "^1.1.1",
49
49
  "stringify-object": "^3.3.0",
50
50
  "styled-components": "^4.1.1 || ^5.1.1 || ^6.0.5",
51
- "swagger-client": "^3.13.3",
51
+ "swagger-client": "^3.35.0",
52
52
  "swagger2openapi": "^7.0.8",
53
53
  "tslib": "^2.2.0",
54
54
  "url-template": "^2.0.8",