apiconnect-explorer
Version:
- [Getting Started](#getting-started) - [Configuration](#configuration) * [Required](#required) * [Optional](#optional) - [Usage in React](#usage-in-react) - [Usage outside of React](#usage-outside-of-react) - [Detailed description of options](#detail
1 lines • 6.24 kB
JavaScript
function a(b){"@babel/helpers - typeof";return a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(a){return typeof a}:function(a){return a&&"function"==typeof Symbol&&a.constructor===Symbol&&a!==Symbol.prototype?"symbol":typeof a},a(b)}function b(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function c(a){for(var c,e=1;e<arguments.length;e++)c=null==arguments[e]?{}:arguments[e],e%2?b(Object(c),!0).forEach(function(b){d(a,b,c[b])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(c)):b(Object(c)).forEach(function(b){Object.defineProperty(a,b,Object.getOwnPropertyDescriptor(c,b))});return a}function d(a,b,c){return(b=f(b))in a?Object.defineProperty(a,b,{value:c,enumerable:!0,configurable:!0,writable:!0}):a[b]=c,a}function f(b){var c=g(b,"string");return"symbol"==a(c)?c:c+""}function g(b,c){if("object"!=a(b)||!b)return b;var d=b[Symbol.toPrimitive];if(void 0!==d){var e=d.call(b,c||"default");if("object"!=a(e))return e;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===c?String:Number)(b)}function h(a,b){return m(a)||l(a,b)||j(a,b)||i()}function i(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function j(b,c){if(b){if("string"==typeof b)return k(b,c);var a={}.toString.call(b).slice(8,-1);return"Object"===a&&b.constructor&&(a=b.constructor.name),"Map"===a||"Set"===a?Array.from(b):"Arguments"===a||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(a)?k(b,c):void 0}}function k(b,c){(null==c||c>b.length)&&(c=b.length);for(var d=0,f=Array(c);d<c;d++)f[d]=b[d];return f}function l(b,c){var d=null==b?null:"undefined"!=typeof Symbol&&b[Symbol.iterator]||b["@@iterator"];if(null!=d){var g,h,j,k,l=[],a=!0,m=!1;try{if(j=(d=d.call(b)).next,0===c){if(Object(d)!==d)return;a=!1}else for(;!(a=(g=j.call(d)).done)&&(l.push(g.value),l.length!==c);a=!0);}catch(a){m=!0,h=a}finally{try{if(!a&&null!=d["return"]&&(k=d["return"](),Object(k)!==k))return}finally{if(m)throw h}}return l}}function m(a){if(Array.isArray(a))return a}import n,{useEffect as o,useState as p}from"react";import{Loading as q,Select as r,SelectItem as s,useTheme as t}from"@carbon/react";import{GraphiQLExplorer as u}from"stepzen-graphiql";import{findFirstAppWithAccess as v}from"./../utils/common.js";import{useApi as w}from"../contexts/ApiHandler/index.tsx";function x(a){var b,d=a.api,e=a.apps,f=w(),g=f.apiHandler,i=p(""),j=h(i,2),k=j[0],l=j[1],m=p([]),x=h(m,2),y=x[0],z=x[1],A=p({userCredentials:{username:null,password:null},identification:{clientID:null,clientSecret:"",redirectUri:null,externalApiKeys:{}},flags:{},scopes:[],authToken:{code:"",access_token:""}}),B=h(A,2),C=B[0],D=B[1],E=t();console.log("theme ",E.theme);o(function(){if(d){var a=g.getEndpoints(d,{});if(z(a),0<(null===a||void 0===a?void 0:a.length)){var b,f=g.buildFullUrl(a[0].url,"/graphql");l(f);var h=null===(b=d.paths)||void 0===b||null===(b=b["/graphql"])||void 0===b?void 0:b.post,i=null;if(!C.identification.clientID&&e&&0<e.length&&e[0].credentials&&0<e[0].credentials.length){var j,k=v(e);i=k?null===(j=k.credentials)||void 0===j?void 0:j[0]:e[0].credentials[0]}var m=g.getSecurityConfig(d,h,null,f);m&&D(function(a){var b;return c(c({},a),{},{identification:c(c({},a.identification),{},{clientID:(null===(b=i)||void 0===b?void 0:b.client_id)||""}),flags:m.flags||{}})})}}},[d,g,e]);var F={endpoint:k,showExplorerHeader:!1,headers:function(a){var b,c=a.flags,d={};return d["Content-Type"]="application/json",d.Accept="application/json",c.requiresBasicAuth&&(d.Authorization="not_supported"),c.requiresOauth&&null!==(b=c.authToken)&&void 0!==b&&b.access_token&&(d.Authorization="not_supported"),c.requiresHttpBearerToken&&(d.Authorization="not_supported"),c.requiresDigestAuth&&(d.Authorization="not_supported"),c.requiresHobaAuth&&(d.Authorization="not_supported"),c.requiresMutualAuth&&(d.Authorization="not_supported"),c.requiresNegotiateAuth&&(d.Authorization="not_supported"),c.requiresVapidAuth&&(d.Authorization="not_supported"),c.requiresScramShaAuth&&(d.Authorization="not_supported"),c.requiresClientId&&"header"===c.clientIdLocation&&(c.clientIdName?d[c.clientIdName]=a.identification.clientID:d["X-IBM-Client-Id"]=a.identification.clientID),c.requiresClientSecret&&"header"===c.clientSecretLocation&&(c.clientSecretName?d[c.clientSecretName]=a.identification.clientSecret:d["X-IBM-Client-Secret"]=a.identification.clientSecret),d}(C),theme:E?E.theme:"white"};return n.createElement("div",null,n.createElement("div",{className:"graphql-endpoint-selector"},n.createElement("div",null,n.createElement("div",{className:"graphql-endpoint-label"},"Endpoint"),n.createElement("div",null,y&&0<y.length?n.createElement(r,{id:"graphql-endpoint-selector",onChange:function(a){var b,f=a.target.value,h=g.buildFullUrl(f,"/graphql");l(h);var i=null===(b=d.paths)||void 0===b||null===(b=b["/graphql"])||void 0===b?void 0:b.post,j=null;if(!C.identification.clientID&&e&&0<e.length&&e[0].credentials&&0<e[0].credentials.length){var k,m=v(e);j=m?null===(k=m.credentials)||void 0===k?void 0:k[0]:e[0].credentials[0]}var n=g.getSecurityConfig(d,i,null,h);n&&D(function(a){var b;return c(c({},a),{},{identification:c(c({},a.identification),{},{clientID:(null===(b=j)||void 0===b?void 0:b.client_id)||""}),flags:n.flags||{}})})},defaultValue:(null===(b=y[0])||void 0===b?void 0:b.url)||"",hideLabel:!0,size:"sm","data-testid":"graphql-endpoint-selector",style:{width:"100%"}},y.map(function(a,b){var c=a.types?"".concat(a.types,": "):"",d="".concat(c).concat(a.url,"/graphql");return n.createElement(s,{key:a.url||"endpoint-".concat(b),value:a.url||"",text:d||"Endpoint ".concat(b+1),"data-testid":"graphql-endpoint-option"})})):n.createElement("div",null,"No endpoints available")),n.createElement("div",{style:{height:"2rem"}}))),k?n.createElement(u,{key:"graphql-explorer-".concat(k),config:F}):n.createElement(q,{small:!0,"data-testid":"loading-graphiql-explorer"}))}x.displayName="TestGraphQL";export default x;