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.96 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)}Object.defineProperty(exports,"__esModule",{value:!0}),exports["default"]=void 0;var b=i(require("react")),c=require("@carbon/react"),d=require("@carbon/react/icons"),e=require("react-i18next"),f=h(require("../utils/invoker")),g=require("../utils/error-message-handler");function h(a){return a&&a.__esModule?a:{default:a}}function i(b,c){if("function"==typeof WeakMap)var d=new WeakMap,g=new WeakMap;return(i=function(b,c){if(!c&&b&&b.__esModule)return b;var e,h,j={__proto__:null,default:b};if(null===b||"object"!=a(b)&&"function"!=typeof b)return j;if(e=c?g:d){if(e.has(b))return e.get(b);e.set(b,j)}for(var f in b)"default"!=f&&{}.hasOwnProperty.call(b,f)&&((h=(e=Object.defineProperty)&&Object.getOwnPropertyDescriptor(b,f))&&(h.get||h.set)?e(j,f,h):j[f]=b[f]);return j})(b,c)}function j(){function b(a,b,f,g){var h=b&&b.prototype instanceof d?b:d,c=Object.create(h.prototype);return k(c,"_invoke",function(a,b,g){function h(a,b){for(k=a,s=b,e=0;!w&&t&&!c&&e<v.length;e++){var c,f=v[e],g=p.p,h=f[2];3<a?(c=h===b)&&(s=f[(k=f[4])?5:(k=3,3)],f[4]=f[5]=m):f[0]<=g&&((c=2>a&&g<f[1])?(k=0,p.v=b,p.n=f[1]):g<h&&(c=3>a||f[0]>b||b>h)&&(f[4]=a,f[5]=b,p.n=h,k=0))}if(c||1<a)return q;throw w=!0,b}var j,k,s,t=0,v=g||[],w=!1,p={p:0,n:0,v:m,a:h,f:h.bind(m,4),d:function c(a,b){return j=a,k=0,s=m,p.n=b,q}};return function(c,d,f){if(1<t)throw TypeError("Generator is already running");for(w&&1===d&&h(d,f),k=d,s=f;(e=2>k?m:s)||!w;){j||(k?3>k?(1<k&&(p.n=-1),h(k,s)):p.n=s:p.v=s);try{if(t=2,j){if(k||(c="next"),e=j[c]){if(!(e=e.call(j,s)))throw TypeError("iterator result is not an object");if(!e.done)return e;s=e.value,2>k&&(k=0)}else 1===k&&(e=j["return"])&&e.call(j),2>k&&(s=TypeError("The iterator does not provide a '"+c+"' method"),k=1);j=m}else if((e=(w=0>p.n)?s:a.call(b,p))!==q)break}catch(a){j=m,k=1,s=a}finally{t=1}}return{value:e,done:w}}}(a,f,g),!0),c}function d(){}function g(){}function h(){}function i(a){return Object.setPrototypeOf?Object.setPrototypeOf(a,h):(a.__proto__=h,k(a,n,"GeneratorFunction")),a.prototype=Object.create(c),a}var m,e,f="function"==typeof Symbol?Symbol:{},l=f.iterator||"@@iterator",n=f.toStringTag||"@@toStringTag",q={};e=Object.getPrototypeOf;var a=[][l]?e(e([][l]())):(k(e={},l,function(){return this}),e),c=h.prototype=d.prototype=Object.create(a);return g.prototype=h,k(c,"constructor",h),k(h,"constructor",g),g.displayName="GeneratorFunction",k(h,n,"GeneratorFunction"),k(c),k(c,n,"Generator"),k(c,l,function(){return this}),k(c,"toString",function(){return"[object Generator]"}),(j=function a(){return{w:b,m:i}})()}function k(a,b,c,d){var f=Object.defineProperty;try{f({},"",{})}catch(a){f=0}k=function e(a,b,c,d){function g(b,c){k(a,b,function(a){return this._invoke(b,c,a)})}b?f?f(a,b,{value:c,enumerable:!d,configurable:!d,writable:!d}):a[b]=c:(g("next",0),g("throw",1),g("return",2))},k(a,b,c,d)}function l(b,d,f,e,g,h,a){try{var c=b[h](a),i=c.value}catch(a){return void f(a)}c.done?d(i):Promise.resolve(i).then(e,g)}function m(b){return function(){var c=this,d=arguments;return new Promise(function(e,f){function g(a){l(i,e,f,g,h,"next",a)}function h(a){l(i,e,f,g,h,"throw",a)}var i=b.apply(c,d);g(void 0)})}}function n(a,b){return t(a)||s(a,b)||p(a,b)||o()}function o(){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 p(b,c){if(b){if("string"==typeof b)return q(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)?q(b,c):void 0}}function q(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 s(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 t(a){if(Array.isArray(a))return a}function u(a){var h=a.config,i=a.onChange,k=(0,b.useState)({access_token:""}),l=n(k,2),o=l[0],p=l[1],q=(0,b.useState)({}),r=n(q,2),s=r[0],u=r[1],v=(0,b.useState)(!1),w=n(v,2),x=w[0],y=w[1],z=(0,b.useMemo)(function(){return new f["default"]},[]),A=(0,e.useTranslation)(),B=A.t;(0,b.useEffect)(function(){o.access_token||p({access_token:""})},[o.access_token]);var t=function(){var a=m(j().m(function b(a){var c,d,e,f;return j().w(function(a){for(;1;)switch(a.p=a.n){case 0:if(c={access_token:""},"https:"!==window.location.protocol||0===h.flags.selectedTokenUrl.lastIndexOf(window.location.protocol)){a.n=1;break}return p(c),u((0,g.getMixedContentMessage)(B)),a.a(2);case 1:if("implicit"!==h.flags.oauthFlow){a.n=2;break}z.authorize(h.flags,h.identification.clientID,h.scopes,h.identification.redirectUri),a.n=7;break;case 2:return a.p=2,a.n=3,z.getToken(h.flags,h.authToken,h.identification.clientID,h.identification.clientSecret,h.scopes,h.identification.redirectUri,h.userCredentials.username,h.userCredentials.password);case 3:d=a.v,u({}),Object.keys(d).forEach(function(a){c[a]=d[a]}),a.n=6;break;case 4:return a.p=4,e=a.v,f=u,a.n=5,(0,g.getOauthErrorMessage)(e,B);case 5:f(a.v);case 6:return a.p=6,p(c),i&&"function"==typeof i&&i(c),a.f(6);case 7:return a.a(2)}},b,null,[[2,4,6,7]])}));return function c(b){return a.apply(this,arguments)}}(),C=function b(a){var c={};c.access_token=a.target.value,p(c),i&&"function"==typeof i&&i(c)},D="";return h.removeFields&&(D="accessCode"===h.flags.oauthFlow||"authorizationCode"===h.flags.oauthFlow?B("explorer_help_access_code"):B("explorer_help_implicit")),b["default"].createElement(b["default"].Fragment,null,b["default"].createElement("div",{className:"getToken"},!h.removeFields&&b["default"].createElement(c.Button,{className:"getTokenButton",onClick:t},B("explorer_get_token")),b["default"].createElement(c.TextInput,{className:"tokenField",labelText:B("explorer_access_token"),type:x?"text":"password",id:"tokenField",value:o.access_token,onChange:C,helperText:D}),b["default"].createElement(c.Button,{hasIconOnly:!0,className:"togglePassword",kind:"ghost",iconDescription:x?"Hide access token":"Show access token",renderIcon:x?d.ViewOff:d.View,onClick:function a(){y(!x)}})),s&&s.highlightedText&&b["default"].createElement("div",{className:"authError"},b["default"].createElement("pre",null,b["default"].createElement("code",{className:"boundedSection hljs oauthError",dangerouslySetInnerHTML:s.highlightedText}))))}var v=exports["default"]=u;