@northflank/cli 0.8.0 → 0.8.3-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-helpers.js +273 -1
- package/dist/cli.js +630 -1
- package/dist/command-overview.js +93 -1
- package/dist/console-format-helpers.js +113 -1
- package/dist/context/contextCommands.js +522 -1
- package/dist/defaults.js +10238 -1
- package/dist/exec/index.js +262 -1
- package/dist/inquirer-helper.js +1049 -1
- package/dist/login/browser-login.js +204 -0
- package/dist/pagination/inquirer-pagination-prompt.js +156 -0
- package/dist/port-forward/index.js +271 -1
- package/dist/utils.js +201 -1
- package/package.json +10 -5
package/dist/inquirer-helper.js
CHANGED
|
@@ -1 +1,1049 @@
|
|
|
1
|
-
'use strict';var a7J=['underline','maximum','\x20(full\x20domain:\x20','values','create','repeat','services','\x20to\x20use:','safeDump','validate','Do\x20you\x20want\x20to\x20add','askForSecret','to\x20use:','addon:\x20\x27','example','fileName','askForSubdomain','next','getPathString','don\x27t\x20change','job\x20runs','string','subdomains','10151KuiRPM','propToType','oneOf','83ScJQys','Something\x20unexpected\x20happened.','retrievePayloadViaInteractiveCli','defaultValue','backups','this\x20option\x20is\x20required,\x20please\x20answer','writable','313025VyaoOF','Should\x20it\x20be','Provide\x20a\x20file\x20path\x20to\x20write\x20the\x20configuration\x20to\x20(<name>.[json|yaml|yml])','domain\x20(','190696cubkIM','data','found','\x20characters,\x20is\x20','Yes,\x20send','minLength','integer','Do\x20you\x20want\x20to\x20add\x20more','yellowBright','green','has','subdomain','Context\x20name\x20already\x20exists.','Configuration\x20file\x20written\x20to\x20','editPayload','runs','askForAddon','defineProperty','message','body','editedResult','map','required','askGeneric','pattern','function','credentials','charAt','doesn\x27t\x20match\x20pattern\x20\x27','done','fullName','Default\x20project\x20in\x20context\x20not\x20set\x20and\x20no\x20argument\x20provided.','addon','1LwKUhD','Choose\x20the\x20project\x20to\x20use:','includes','must\x20be\x20longer\x20than\x20or\x20equal\x20to\x20','default','must\x20be\x20smaller\x20than\x20or\x20equal\x20to\x20','askForAddonBackup','registryCredentials','confirm','number','ask','795643TmUNUM','What\x27s\x20the\x20','trys','yml','setPathVars','Unexpected\x20file\x20type:\x20','No\x20builds\x20found','\x20type?','domain','431376LjUWGE','job','apply','toString','type','boolean','No,\x20repeat','Generator\x20is\x20already\x20executing.','list','confirmationPrompt','__spreadArray','inquirer','createdAt','test','service:\x20\x27','yaml','editor','a\x20Northflank\x20resource','sent','No,\x20edit','askForCredentials','then','password','unset','__createBinding','js-yaml','enum','label','Go\x20to\x20editor','throw','length','projects','isEmpty','stringify','EDIT','No\x20','Choose\x20the\x20name\x20of\x20the\x20new\x20local\x20context:','Choose\x20the\x20login\x20token:','667449fhHIZa','pop','keys','getQuestionString','service','get','.*\x5c.(json|yaml|yml)$','__esModule','secret','No,\x20abort','WARNING:\x20You\x20are\x20about\x20to\x20delete\x20','startedAt','\x20characters','Context\x20with\x20name\x20\x27','chalk','askForJobRun','\x20(completedAt:\x20','must\x20be\x20a\x20number,\x20is\x20','maxLength','filter','YES','askForProjectScopedResource','job\x20builds','name','choice','\x20and\x20it\x20','tokenPrompt','SAVE','ops','InquirerHelper','askForJob','prototype','confirmation','assign','deleteWarningPrompt','askForBuild','return','__importStar','addons','resultCache','getType','2302oUTBOr','not\x20completed','pathVars','\x20in\x20','lodash','bold','REPEAT','.\x20This\x20is\x20irreversible.\x20Please\x20confirm!','isUndefined','writeFileSync','isBoolean','2AaTegv','join','jobs','input','minimum','job:\x20\x27','slice','builds','79vjxAIs','__importDefault','concat','getOwnPropertyDescriptor','isObject','apiClient','grey','must\x20be\x20shorter\x20than\x20or\x20equal\x20to\x20','override','tmpCmdPath','hasOwnProperty','\x20(startedAt:\x20','addEntry','prompt','properties','split','isFinite','secrets','whiteBright','success','Please\x20confirm\x20following\x20configuration:\x0a','warning','must\x20be\x20a\x20valid\x20non-empty\x20json\x20string','find','red','\x20Example:\x20','for\x20this\x20','askForVolume','configurable','rawObject','max','items','set','token','iterator','project:\x20\x27','getCurrentProjectName','description','askArrayEntry','volume','value','loginPrompt','job\x20build','saveFile','call','isValidJSON','domains','push','askForResource','array'];var a7l=a7o;(function(J,o){var O=a7o;while(!![]){try{var T=parseInt(O(0x22e))*-parseInt(O(0x19f))+parseInt(O(0x1d6))*parseInt(O(0x1cb))+-parseInt(O(0x205))+parseInt(O(0x1df))+-parseInt(O(0x1a6))+-parseInt(O(0x19c))*-parseInt(O(0x241))+parseInt(O(0x239))*-parseInt(O(0x1aa));if(T===o)break;else J['push'](J['shift']());}catch(n){J['push'](J['shift']());}}}(a7J,0x74370));var __assign=this&&this['__assign']||function(){var W=a7o;return __assign=Object[W(0x226)]||function(J){var K=W;for(var o,T=0x1,k=arguments[K(0x1fd)];T<k;T++){o=arguments[T];for(var v in o)if(Object[K(0x224)]['hasOwnProperty'][K(0x26d)](o,v))J[v]=o[v];}return J;},__assign[W(0x1e1)](this,arguments);},__createBinding=this&&this[a7l(0x1f7)]||(Object[a7l(0x277)]?function(J,T,n,v){var F=a7l;if(v===undefined)v=n;var c=Object[F(0x244)](T,n);(!c||(F(0x20a)in c?!T[F(0x20c)]:c[F(0x1a5)]||c[F(0x25d)]))&&(c={'enumerable':!![],'get':function(){return T[n];}}),Object[F(0x1bb)](J,v,c);}:function(J,T,n,v){if(v===undefined)v=n;J[v]=T[n];}),__setModuleDefault=this&&this['__setModuleDefault']||(Object[a7l(0x277)]?function(J,T){var R=a7l;Object['defineProperty'](J,R(0x1cf),{'enumerable':!![],'value':T});}:function(J,T){J['default']=T;}),__importStar=this&&this[a7l(0x22a)]||function(J){var b=a7l;if(J&&J['__esModule'])return J;var o={};if(J!=null){for(var T in J)if(T!==b(0x1cf)&&Object['prototype'][b(0x24b)]['call'](J,T))__createBinding(o,J,T);}return __setModuleDefault(o,J),o;},__awaiter=this&&this['__awaiter']||function(J,o,T,n){function k(v){return v instanceof T?v:new T(function(c){c(v);});}return new(T||(T=Promise))(function(v,c){var I=a7o;function B(s){var p=a7o;try{G(n[p(0x196)](s));}catch(Y){c(Y);}}function L(s){var i=a7o;try{G(n[i(0x1fc)](s));}catch(Y){c(Y);}}function G(s){var w=a7o;s['done']?v(s['value']):k(s[w(0x269)])[w(0x1f4)](B,L);}G((n=n[I(0x1e1)](J,o||[]))[I(0x196)]());});},__generator=this&&this['__generator']||function(J,o){var u=a7l,T={'label':0x0,'sent':function(){if(v[0x0]&0x1)throw v[0x1];return v[0x1];},'trys':[],'ops':[]},n,k,v,c;return c={'next':B(0x0),'throw':B(0x1),'return':B(0x2)},typeof Symbol===u(0x1c3)&&(c[Symbol[u(0x263)]]=function(){return this;}),c;function B(G){return function(s){return L([G,s]);};}function L(G){var Z=u;if(n)throw new TypeError(Z(0x1e6));while(T)try{if(n=0x1,k&&(v=G[0x0]&0x2?k[Z(0x229)]:G[0x0]?k['throw']||((v=k[Z(0x229)])&&v['call'](k),0x0):k[Z(0x196)])&&!(v=v[Z(0x26d)](k,G[0x1]))[Z(0x1c7)])return v;if(k=0x0,v)G=[G[0x0]&0x2,v[Z(0x269)]];switch(G[0x0]){case 0x0:case 0x1:v=G;break;case 0x4:T[Z(0x1fa)]++;return{'value':G[0x1],'done':![]};case 0x5:T[Z(0x1fa)]++,k=G[0x1],G=[0x0];continue;case 0x7:G=T['ops'][Z(0x206)](),T[Z(0x1d8)]['pop']();continue;default:if(!(v=T[Z(0x1d8)],v=v[Z(0x1fd)]>0x0&&v[v[Z(0x1fd)]-0x1])&&(G[0x0]===0x6||G[0x0]===0x2)){T=0x0;continue;}if(G[0x0]===0x3&&(!v||G[0x1]>v[0x0]&&G[0x1]<v[0x3])){T[Z(0x1fa)]=G[0x1];break;}if(G[0x0]===0x6&&T['label']<v[0x1]){T['label']=v[0x1],v=G;break;}if(v&&T['label']<v[0x2]){T[Z(0x1fa)]=v[0x2],T[Z(0x221)][Z(0x270)](G);break;}if(v[0x2])T['ops'][Z(0x206)]();T['trys']['pop']();continue;}G=o[Z(0x26d)](J,T);}catch(s){G=[0x6,s],k=0x0;}finally{n=v=0x0;}if(G[0x0]&0x5)throw G[0x1];return{'value':G[0x0]?G[0x1]:void 0x0,'done':!![]};}},__spreadArray=this&&this[a7l(0x1e9)]||function(J,o,T){var N=a7l;if(T||arguments[N(0x1fd)]===0x2)for(var n=0x0,k=o[N(0x1fd)],v;n<k;n++){if(v||!(n in o)){if(!v)v=Array[N(0x224)]['slice'][N(0x26d)](o,0x0,n);v[n]=o[n];}}return J[N(0x243)](v||Array['prototype'][N(0x23f)][N(0x26d)](o));},__importDefault=this&&this[a7l(0x242)]||function(J){var S=a7l;return J&&J[S(0x20c)]?J:{'default':J};};Object[a7l(0x1bb)](exports,a7l(0x20c),{'value':!![]}),exports[a7l(0x222)]=void 0x0;var _=__importStar(require(a7l(0x232))),chalk_1=__importDefault(require(a7l(0x213))),fs=__importStar(require('fs')),utils_1=require('./utils'),api_helpers_1=require('./api-helpers'),inquirer=require(a7l(0x1ea)),yaml=require(a7l(0x1f8)),ConfirmChoices;(function(J){var D=a7l;J['YES']=D(0x1ae),J[D(0x234)]=D(0x1e5),J['EDIT']=D(0x1f2),J[D(0x220)]='No,\x20but\x20save\x20as\x20file',J['ABORT']=D(0x20e);}(ConfirmChoices||(ConfirmChoices={})));var InquirerHelper=function(){var JM=a7l;function J(o){var H=a7o,T=this;this[H(0x246)]=o,this[H(0x1b8)]=function(n){return __awaiter(T,void 0x0,void 0x0,function(){var k;return __generator(this,function(v){var y=a7o;switch(v[y(0x1fa)]){case 0x0:return[0x4,inquirer['prompt']([{'type':y(0x1ef),'name':'editedResult','message':y(0x1fb),'default':yaml[y(0x18d)](n)}])];case 0x1:k=v[y(0x1f1)]()[y(0x1be)];return[0x2,yaml['safeLoad'](k)];}});});},this['saveFile']=function(n){return __awaiter(T,void 0x0,void 0x0,function(){function k(){return __awaiter(this,void 0x0,void 0x0,function(){return __generator(this,function(L){var h=a7o;return[0x2,inquirer[h(0x24e)]([{'type':h(0x23c),'name':h(0x194),'message':h(0x1a8),'validate':function(G){var t=h;return new RegExp(t(0x20b))[t(0x1ec)](G)?!![]:v(G);}}])];});});}var v,c,B;return __generator(this,function(L){var x=a7o;switch(L[x(0x1fa)]){case 0x0:v=function(G){var V=x;return V(0x1db)[V(0x243)](G,',\x20supported\x20types:\x20[json|yaml|yml]');};return[0x4,k()];case 0x1:c=L[x(0x1f1)]()[x(0x194)],B=c[x(0x1e2)]()['split']('.')[x(0x206)]();try{switch(B){case'json':(0x0,utils_1[x(0x254)])('Configuration\x20file\x20written\x20to\x20'[x(0x243)](c));return[0x2,fs[x(0x237)](c,JSON[x(0x200)](n,null,'\x20\x20'))];case x(0x1ee):case x(0x1d9):(0x0,utils_1['success'])(x(0x1b7)[x(0x243)](c));return[0x2,fs[x(0x237)](c,yaml['safeDump'](n))];default:(0x0,utils_1['warning'])(v(B));}}catch(G){(0x0,utils_1[x(0x256)])('Writing\x20configuration\x20failed:\x20'[x(0x243)](G[x(0x1bc)]));}return[0x2,undefined];}});});},this[H(0x218)]=function(n,k){return function(v){var d=a7o,c=typeof v===d(0x19a)?v['trim']():v;if(n==='number'&&Number['isNaN'](c))return'';return k===![]&&c===d(0x198)?'':c;};},this['validate']=function(n,k){return function(v){var j=a7o,c=[];if(v===''||v===j(0x198)){if(k!==![])c[j(0x270)](j(0x1a4));else return!![];}n[j(0x1e3)]==='string'&&!_[j(0x236)](n['pattern'])&&c['push'](new RegExp(n[j(0x1c2)])['test'](v)?!![]:j(0x1c6)['concat'](n[j(0x1c2)],'\x27'));n['type']===j(0x19a)&&!_[j(0x236)](n[j(0x1af)])&&c[j(0x270)](v[j(0x1fd)]>=n[j(0x1af)]?!![]:j(0x1ce)[j(0x243)](n[j(0x1af)],j(0x1ad))[j(0x243)](v[j(0x1fd)],j(0x211)));n['type']===j(0x19a)&&!_[j(0x236)](n[j(0x217)])&&c[j(0x270)](v['length']<=n[j(0x217)]?!![]:j(0x248)['concat'](n[j(0x217)],j(0x1ad))[j(0x243)](v['length'],j(0x211)));n['type']===j(0x1b0)&&!_[j(0x251)](Number(v))&&c['push'](j(0x216)[j(0x243)](v));n['type']===j(0x1b0)&&!_['isUndefined'](n[j(0x23d)])&&c['push'](v>=n['minimum']?!![]:'must\x20be\x20bigger\x20than\x20or\x20equal\x20to\x20'[j(0x243)](n['minimum']));n[j(0x1e3)]===j(0x1b0)&&!_[j(0x236)](n[j(0x274)])&&c[j(0x270)](v<=n[j(0x274)]?!![]:j(0x1d0)['concat'](n[j(0x274)]));if(n['type']===j(0x25e)){var B=(0x0,utils_1[j(0x26e)])(v);c[j(0x270)](B===![]||_[j(0x1ff)](B)?j(0x257):!![]);}var L=c[j(0x218)](function(s){return s!==!![];}),G=(n===null||n===void 0x0?void 0x0:n['example'])?'\x0a'[j(0x243)](chalk_1[j(0x1cf)][j(0x259)]('>>'),j(0x25a))['concat'](chalk_1['default'][j(0x253)](JSON[j(0x200)](n[j(0x193)]))):'';return L['length']>0x0?L[j(0x23a)](chalk_1[j(0x1cf)][j(0x273)](j(0x21e)))+G:!![];};},this['getPathString']=function(n,k,v){var U=H,c=n[n[U(0x1fd)]-0x1];function B(){var e=U;return n[e(0x23f)](0x0,-0x1)[e(0x1bf)](function(s){var Q=e;return s[Q(0x1c5)](0x0)['toUpperCase']()+s[Q(0x23f)](0x1);})['join']('>');}var L=n[U(0x1fd)]>0x1?''[U(0x243)](chalk_1[U(0x1cf)]['bgGrey'][U(0x253)](B()),':\x20'):'',G=v?'\x20('[U(0x243)](chalk_1['default']['blue'](v),')'):'';return chalk_1[U(0x1cf)]['reset'](''['concat'](L)[U(0x243)](k,'\x20')[U(0x243)](chalk_1['default'][U(0x233)]['greenBright'](c))[U(0x243)](G,'?'));},this[H(0x271)]=function(n,k,v){return __awaiter(T,void 0x0,void 0x0,function(){var c,B;return __generator(this,function(L){var z=a7o;switch(L[z(0x1fa)]){case 0x0:if(k[z(0x1fd)]<0x1){c=v?z(0x25b)[z(0x243)](v):z(0x1ac);throw new Error(z(0x202)[z(0x243)](n,'\x20')['concat'](c,'.'));}B='Choose\x20the\x20'[z(0x243)](n,z(0x18c));return[0x4,inquirer['prompt']([{'type':z(0x1e7),'name':'name','message':B,'choices':k}])];case 0x1:return[0x2,L[z(0x1f1)]()[z(0x21c)]];}});});},this[H(0x1c1)]=function(n,k){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var v,c,B;return __generator(this,function(L){var q=a7o;switch(L[q(0x1fa)]){case 0x0:v=''[q(0x243)](k?'('[q(0x243)](chalk_1[q(0x1cf)]['blue'](k),')\x20'):''),c='Enter\x20the\x20'[q(0x243)](chalk_1['default'][q(0x1b3)](n),'\x20')[q(0x243)](v,q(0x191)),B=this[q(0x18e)]({'type':q(0x19a),'required':!![]});return[0x4,inquirer[q(0x24e)]([{'type':q(0x23c),'name':q(0x21c),'message':c,'validate':B}])];case 0x1:return[0x2,L['sent']()['name']];}});});};},this['askForService']=function(n){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var k,v=this;return __generator(this,function(c){var A=a7o;return k=function(B){return __awaiter(v,void 0x0,void 0x0,function(){return __generator(this,function(L){var X=a7o;switch(L[X(0x1fa)]){case 0x0:return[0x4,this[X(0x246)][X(0x1e7)][X(0x279)]({'parameters':{'projectId':B},'options':{'per_page':0x64}})];case 0x1:return[0x2,L['sent']()[X(0x1ab)][X(0x279)][X(0x1bf)](function(G){return G['id'];})];}});});},[0x2,this['askForProjectScopedResource'](A(0x209),k,n)];});});};},this[H(0x223)]=function(n){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var k,v=this;return __generator(this,function(c){var m=a7o;return k=function(B){return __awaiter(v,void 0x0,void 0x0,function(){return __generator(this,function(L){var r=a7o;switch(L['label']){case 0x0:return[0x4,this[r(0x246)][r(0x1e7)][r(0x23b)]({'parameters':{'projectId':B},'options':{'per_page':0x64}})];case 0x1:return[0x2,L[r(0x1f1)]()['data'][r(0x23b)][r(0x1bf)](function(G){return G['id'];})];}});});},[0x2,this[m(0x21a)](m(0x1e0),k,n)];});});};},this[H(0x214)]=function(n,k){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var v,c=this;return __generator(this,function(B){var J1=a7o;return v=function(L){return __awaiter(c,void 0x0,void 0x0,function(){return __generator(this,function(G){var a=a7o;switch(G[a(0x1fa)]){case 0x0:return[0x4,this[a(0x246)][a(0x20a)][a(0x1e0)][a(0x1b9)]({'parameters':{'projectId':L,'jobId':n},'options':{'per_page':0x64}})];case 0x1:return[0x2,G[a(0x1f1)]()[a(0x1ab)][a(0x1b9)]['map'](function(s){var J0=a;return''[J0(0x243)](s['id'],J0(0x24c))[J0(0x243)](s[J0(0x210)],')');})];}});});},[0x2,this['askForProjectScopedResource'](J1(0x199),v,k,J1(0x23e)[J1(0x243)](n,'\x27'))[J1(0x1f4)](function(L){var J2=J1;return L[J2(0x250)]('\x20')[0x0];})];});});};},this[H(0x228)]=function(n,k,v){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var c,c,B=this;return __generator(this,function(L){var J5=a7o;if(v!==undefined)return c=function(G){return __awaiter(B,void 0x0,void 0x0,function(){return __generator(this,function(s){var J3=a7o;switch(s[J3(0x1fa)]){case 0x0:return[0x4,this[J3(0x246)][J3(0x20a)][J3(0x1e0)][J3(0x240)]({'parameters':{'projectId':G,'jobId':v},'options':{'per_page':0x64}})];case 0x1:return[0x2,s[J3(0x1f1)]()[J3(0x1ab)]['builds'][J3(0x1bf)](function(Y){var J4=J3;return''['concat'](Y['id'],J4(0x24c))['concat'](Y[J4(0x1eb)],')');})];}});});},[0x2,this[J5(0x21a)](J5(0x21b),c,n,J5(0x23e)[J5(0x243)](v,'\x27'))[J5(0x1f4)](function(G){var J6=J5;return G[J6(0x250)]('\x20')[0x0];})];if(k!==undefined)return c=function(G){return __awaiter(B,void 0x0,void 0x0,function(){return __generator(this,function(s){var J7=a7o;switch(s['label']){case 0x0:return[0x4,this[J7(0x246)]['get'][J7(0x209)][J7(0x240)]({'parameters':{'projectId':G,'serviceId':k},'options':{'per_page':0x64}})];case 0x1:return[0x2,s[J7(0x1f1)]()[J7(0x1ab)][J7(0x240)][J7(0x1bf)](function(Y){var J8=J7;return''[J8(0x243)](Y['id'],J8(0x24c))[J8(0x243)](Y[J8(0x1eb)],')');})];}});});},[0x2,this[J5(0x21a)](J5(0x26b),c,n,J5(0x1ed)[J5(0x243)](v,'\x27'))[J5(0x1f4)](function(G){var J9=J5;return G[J9(0x250)]('\x20')[0x0];})];throw new Error(J5(0x1dc));});});};},this[H(0x1ba)]=function(n){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var k,v=this;return __generator(this,function(c){var Jo=a7o;return k=function(B){return __awaiter(v,void 0x0,void 0x0,function(){return __generator(this,function(L){var JJ=a7o;switch(L[JJ(0x1fa)]){case 0x0:return[0x4,this[JJ(0x246)][JJ(0x1e7)][JJ(0x22b)]({'parameters':{'projectId':B},'options':{'per_page':0x64}})];case 0x1:return[0x2,L[JJ(0x1f1)]()[JJ(0x1ab)][JJ(0x22b)][JJ(0x1bf)](function(G){return G['id'];})];}});});},[0x2,this[Jo(0x21a)](Jo(0x1ca),k,n)];});});};},this[H(0x1d1)]=function(n,k){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var v,c=this;return __generator(this,function(B){var Jk=a7o;return v=function(L){return __awaiter(c,void 0x0,void 0x0,function(){return __generator(this,function(G){var JT=a7o;switch(G[JT(0x1fa)]){case 0x0:return[0x4,this['apiClient']['get'][JT(0x1ca)][JT(0x1a3)]({'parameters':{'projectId':L,'addonId':k},'options':{'per_page':0x64}})];case 0x1:return[0x2,G[JT(0x1f1)]()['data'][JT(0x1a3)][JT(0x1bf)](function(s){var Jn=JT;return''[Jn(0x243)](s['id'],Jn(0x215))['concat'](s['completedAt']||Jn(0x22f),')');})];}});});},[0x2,this[Jk(0x21a)](Jk(0x1a3),v,n,Jk(0x192)['concat'](k,'\x27'))[Jk(0x1f4)](function(L){return L['split']('\x20')[0x0];})];});});};},this[H(0x25c)]=function(n){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var k,v=this;return __generator(this,function(c){var Jc=a7o;return k=function(B){return __awaiter(v,void 0x0,void 0x0,function(){return __generator(this,function(L){var Jv=a7o;switch(L[Jv(0x1fa)]){case 0x0:return[0x4,this['apiClient'][Jv(0x1e7)]['volumes']({'parameters':{'projectId':B}})];case 0x1:return[0x2,L[Jv(0x1f1)]()['data'][Jv(0x1bf)](function(G){return G['id'];})];}});});},[0x2,this['askForProjectScopedResource'](Jc(0x268),k,n)];});});};},this[H(0x190)]=function(n){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var k,v=this;return __generator(this,function(c){var JL=a7o;return k=function(B){return __awaiter(v,void 0x0,void 0x0,function(){return __generator(this,function(L){var JB=a7o;switch(L[JB(0x1fa)]){case 0x0:return[0x4,this[JB(0x246)][JB(0x1e7)][JB(0x252)]({'parameters':{'projectId':B},'options':{'per_page':0x64}})];case 0x1:return[0x2,L[JB(0x1f1)]()[JB(0x1ab)]['secrets'][JB(0x1bf)](function(G){return G['id'];})];}});});},[0x2,this[JL(0x21a)](JL(0x20d),k,n)];});});};},this[H(0x195)]=function(n){return function(){return __awaiter(T,void 0x0,void 0x0,function(){var k,v,c;return __generator(this,function(B){var JG=a7o;switch(B['label']){case 0x0:return[0x4,this[JG(0x246)][JG(0x20a)][JG(0x1de)]({'parameters':{'domain':n}})];case 0x1:k=B[JG(0x1f1)](),v=k['data'][JG(0x19b)]['map'](function(L){var Js=JG;return''[Js(0x243)](L[Js(0x21c)],Js(0x275))['concat'](L[Js(0x1c8)],')');}),c=JG(0x1a9)[JG(0x243)](n,')');return[0x2,this['askForResource'](JG(0x1b5),v,c)['then'](function(L){var JY=JG;return L[JY(0x250)]('\x20')[0x0];})];}});});};},this[H(0x227)]=function(n){return __awaiter(T,void 0x0,void 0x0,function(){return __generator(this,function(k){var JP=a7o;switch(k['label']){case 0x0:return[0x4,inquirer[JP(0x24e)]([{'type':JP(0x1d3),'name':JP(0x225),'message':chalk_1[JP(0x1cf)][JP(0x1b2)](JP(0x20f)['concat'](n||JP(0x1f0),JP(0x235))),'default':![]}])];case 0x1:return[0x2,k['sent']()[JP(0x225)]];}});});},this[H(0x26a)]=function(n,k){return __awaiter(T,void 0x0,void 0x0,function(){var v,c=this;return __generator(this,function(B){var Jg=a7o;switch(B[Jg(0x1fa)]){case 0x0:if(!_[Jg(0x236)](n[Jg(0x21c)]))return[0x3,0x3];if(!(k[Jg(0x1fd)]<=0x0))return[0x3,0x1];_['set'](n,Jg(0x21c),Jg(0x1cf));return[0x3,0x3];case 0x1:return[0x4,(0x0,utils_1['retry'])(0xa)(function(){return __awaiter(c,void 0x0,void 0x0,function(){var L,G;return __generator(this,function(s){var Jf=a7o;switch(s['label']){case 0x0:return[0x4,inquirer['prompt']([{'type':'input','name':Jf(0x21c),'message':Jf(0x203),'default':'main-context'}])];case 0x1:L=s[Jf(0x1f1)]()['name'];if(!(!n['override']&&k['find'](function(Y){var JC=Jf;return Y[JC(0x21c)]===L;})))return[0x3,0x3];return[0x4,inquirer[Jf(0x24e)]([{'type':Jf(0x1d3),'name':'c','message':Jf(0x212)[Jf(0x243)](L,'\x27\x20already\x20exists.\x20Do\x20you\x20want\x20to\x20override\x20this\x20context\x20(y)\x20or\x20enter\x20a\x20new\x20name\x20(N)?'),'default':![]}])];case 0x2:G=s['sent']()['c'];if(G===![])throw new Error(Jf(0x1b6));_[Jf(0x261)](n,Jf(0x249),!![]),s['label']=0x3;case 0x3:_[Jf(0x261)](n,'name',L);return[0x2];}});});})];case 0x2:B[Jg(0x1f1)](),B[Jg(0x1fa)]=0x3;case 0x3:if(!_['isUndefined'](n['token']))return[0x3,0x5];return[0x4,this['tokenPrompt']()];case 0x4:v=B[Jg(0x1f1)](),_[Jg(0x261)](n,Jg(0x262),v),B['label']=0x5;case 0x5:return[0x2,n];}});});},this[H(0x21f)]=function(){return __awaiter(T,void 0x0,void 0x0,function(){var n;return __generator(this,function(k){var JE=a7o;switch(k[JE(0x1fa)]){case 0x0:return[0x4,inquirer['prompt']([{'type':JE(0x1f5),'name':JE(0x262),'mask':'*','message':JE(0x204)}])];case 0x1:n=k[JE(0x1f1)]()[JE(0x262)];return[0x2,n];}});});};}return J[JM(0x224)][JM(0x1e8)]=function(o,T){return __awaiter(this,void 0x0,void 0x0,function(){var n,k,v,c,B,L;return __generator(this,function(G){var JO=a7o;switch(G['label']){case 0x0:n=yaml[JO(0x18d)](o),k=_[JO(0x25f)](n['split']('\x0a')['map'](function(s){var JW=JO;return s[JW(0x1fd)];})),v=chalk_1[JO(0x1cf)][JO(0x247)](''[JO(0x243)]('-'[JO(0x278)](k),'\x0a'));return[0x4,inquirer[JO(0x24e)]([{'type':'list','name':'confirm','message':''[JO(0x243)](chalk_1[JO(0x1cf)][JO(0x233)][JO(0x1b3)](JO(0x255)))[JO(0x243)](v)['concat'](chalk_1[JO(0x1cf)]['blueBright'](n))['concat'](v),'choices':Object[JO(0x276)](ConfirmChoices)}])];case 0x1:c=G[JO(0x1f1)]()[JO(0x1d3)],B=c;switch(B){case ConfirmChoices[JO(0x219)]:return[0x3,0x2];case ConfirmChoices['ABORT']:return[0x3,0x3];case ConfirmChoices[JO(0x234)]:return[0x3,0x4];case ConfirmChoices[JO(0x201)]:return[0x3,0x5];case ConfirmChoices['SAVE']:return[0x3,0x7];}return[0x3,0x9];case 0x2:return[0x2,o];case 0x3:throw new Error('Aborted.');case 0x4:return[0x2,this[JO(0x1a1)](T)];case 0x5:L=this[JO(0x1e8)];return[0x4,this[JO(0x1b8)](o)];case 0x6:return[0x2,L[JO(0x1e1)](this,[G[JO(0x1f1)](),T])];case 0x7:return[0x4,this[JO(0x26c)](o)];case 0x8:G[JO(0x1f1)]();return[0x2,this[JO(0x1e8)](o,T)];case 0x9:throw new Error(JO(0x1a0));}});});},J[JM(0x224)]['retrievePayloadViaInteractiveCli']=function(o,T){return __awaiter(this,void 0x0,void 0x0,function(){var n;return __generator(this,function(k){var JK=a7o;switch(k[JK(0x1fa)]){case 0x0:if((T===null||T===void 0x0?void 0x0:T[JK(0x22c)])!==undefined)this[JK(0x22c)]=T===null||T===void 0x0?void 0x0:T[JK(0x22c)];this[JK(0x24a)]=T===null||T===void 0x0?void 0x0:T['cmdPath'],n={};return[0x4,this[JK(0x19d)]([],o['opt'][JK(0x1bd)],n)];case 0x1:k[JK(0x1f1)](),this[JK(0x22c)]=n;return[0x4,this[JK(0x1e8)](n,o)];case 0x2:return[0x2,k[JK(0x1f1)]()];}});});},J['prototype']['propToType']=function(o,T,n,k){return __awaiter(this,void 0x0,void 0x0,function(){var v,c,B;return __generator(this,function(L){var Jl=a7o;switch(L[Jl(0x1fa)]){case 0x0:if(!(T[Jl(0x19e)]&&!_[Jl(0x1b4)](T,Jl(0x24f))))return[0x3,0x6];if(!(T[Jl(0x19e)][Jl(0x1fd)]>0x1))return[0x3,0x3];return[0x4,inquirer[Jl(0x24e)]([{'type':Jl(0x1e7),'name':Jl(0x21d),'message':Jl(0x1d7)['concat'](o[o[Jl(0x1fd)]-0x1]||'',Jl(0x1dd)),'choices':T[Jl(0x19e)][Jl(0x1bf)](function(G){return G['description'];})}])];case 0x1:c=L[Jl(0x1f1)]()[Jl(0x21d)];return[0x4,this['getType'](o,T[Jl(0x19e)][Jl(0x258)](function(G){var JF=Jl;return G[JF(0x266)]===c;}),n,k)];case 0x2:v=L[Jl(0x1f1)]();return[0x3,0x5];case 0x3:B=T[Jl(0x19e)][0x0],_[Jl(0x261)](B,'description',T['description']);return[0x4,this[Jl(0x22d)](o,B,n,k)];case 0x4:v=L['sent'](),L['label']=0x5;case 0x5:v={};return[0x3,0x8];case 0x6:return[0x4,this[Jl(0x22d)](o,T,n,k)];case 0x7:v=L[Jl(0x1f1)](),L[Jl(0x1fa)]=0x8;case 0x8:return[0x2,v];}});});},J[JM(0x224)]['getInnerType']=function(o,T,n,k){var v;return __awaiter(this,void 0x0,void 0x0,function(){var c,B,L,G,s,Y,P;return __generator(this,function(g){var JR=a7o;switch(g[JR(0x1fa)]){case 0x0:if(!(k===![]))return[0x3,0x2];return[0x4,inquirer['prompt']([{'type':JR(0x1d3),'name':JR(0x24d),'message':this[JR(0x197)](T,JR(0x18f),o===null||o===void 0x0?void 0x0:o[JR(0x266)]),'default':![]}])];case 0x1:c=g[JR(0x1f1)]()['addEntry'];if(!c)return[0x2,n];g[JR(0x1fa)]=0x2;case 0x2:B=Object[JR(0x207)]((v=o===null||o===void 0x0?void 0x0:o[JR(0x24f)])!==null&&v!==void 0x0?v:[]),L=o[JR(0x1c0)]||[];if(!(B[JR(0x1fd)]>0x0))return[0x3,0x7];G=0x0,s=B,g[JR(0x1fa)]=0x3;case 0x3:if(!(G<s['length']))return[0x3,0x6];Y=s[G],P=T[JR(0x243)](Y);if(T[JR(0x1fd)]>0x0&&!_[JR(0x1b4)](n,T[JR(0x23a)]('.')))_['set'](n,T[JR(0x23a)]('.'),{});return[0x4,this[JR(0x19d)](P,o['properties'][Y],n,L[JR(0x1cd)](Y))];case 0x4:g[JR(0x1f1)](),g[JR(0x1fa)]=0x5;case 0x5:G++;return[0x3,0x3];case 0x6:return[0x3,0x9];case 0x7:return[0x4,this[JR(0x22d)](T,__assign(__assign({},o),{'type':JR(0x25e)}),n,k)];case 0x8:g['sent'](),g[JR(0x1fa)]=0x9;case 0x9:return[0x2,n];}});});},J[JM(0x224)][JM(0x267)]=function(o,T,n,k){return __awaiter(this,void 0x0,void 0x0,function(){var v,c;return __generator(this,function(B){var Jb=a7o;switch(B[Jb(0x1fa)]){case 0x0:if(T&&n)return[0x2,!![]];v=T?Jb(0x18f):Jb(0x1b1);return[0x4,inquirer[Jb(0x24e)]([{'type':'confirm','name':Jb(0x24d),'message':this[Jb(0x197)](o,v,T?k:undefined),'default':![]}])];case 0x1:c=B[Jb(0x1f1)]()['addEntry'];return[0x2,c];}});});},J[JM(0x224)][JM(0x22d)]=function(o,T,n,k){return __awaiter(this,void 0x0,void 0x0,function(){var v,c,B,L,G,s,Y;return __generator(this,function(P){var Jp=a7o;switch(P[Jp(0x1fa)]){case 0x0:c=o['join']('.'),B=T===null||T===void 0x0?void 0x0:T[Jp(0x1e3)];switch(B){case Jp(0x272):return[0x3,0x1];case'object':return[0x3,0x6];case Jp(0x25e):return[0x3,0x8];case Jp(0x19a):return[0x3,0xa];case Jp(0x1e4):return[0x3,0xa];case Jp(0x1b0):return[0x3,0xa];}return[0x3,0xa];case 0x1:L=!![],P[Jp(0x1fa)]=0x2;case 0x2:return[0x4,this['askArrayEntry'](o,L,k,T===null||T===void 0x0?void 0x0:T['description'])];case 0x3:if(!P[Jp(0x1f1)]())return[0x3,0x5];G=_[Jp(0x20a)](n,c),_[Jp(0x1f6)](n,c);return[0x4,this[Jp(0x22d)](o,T[Jp(0x260)],n)];case 0x4:P['sent'](),s=_[Jp(0x20a)](n,c);!_['isArray'](G)?_[Jp(0x261)](n,c,[s]):(G[Jp(0x270)](s),_['set'](n,c,G));L=![];return[0x3,0x2];case 0x5:return[0x2,v||[]];case 0x6:return[0x4,this['getInnerType'](T,o,n,k)];case 0x7:v=P[Jp(0x1f1)]();return[0x2,v];case 0x8:Y=utils_1[Jp(0x26e)];return[0x4,this['ask'](o,T,k)];case 0x9:v=Y[Jp(0x1e1)](void 0x0,[P[Jp(0x1f1)]()])||undefined;return[0x3,0xc];case 0xa:return[0x4,this[Jp(0x1d5)](o,T,k,n)];case 0xb:v=P[Jp(0x1f1)]();return[0x3,0xc];case 0xc:!_['isUndefined'](v)&&_['set'](n,c,v);return[0x2,v];}});});},J[JM(0x224)]['ask']=function(o,T,n,k){var v;return __awaiter(this,void 0x0,void 0x0,function(){var c,B,L,G,s,Y,P,g,f,C,E;return __generator(this,function(M){var Ji=a7o;switch(M[Ji(0x1fa)]){case 0x0:c=o[o['length']-0x1];return[0x4,(0x0,api_helpers_1['fetchResourceList'])(c,this['apiClient'],this[Ji(0x24a)],k,this[Ji(0x230)],o)];case 0x1:B=M['sent'](),L=B[Ji(0x1a2)],G=L===void 0x0?(v=T===null||T===void 0x0?void 0x0:T[Ji(0x193)])!==null&&v!==void 0x0?v:T===null||T===void 0x0?void 0x0:T[Ji(0x1cf)]:L,s=B['choices'],Y=s===void 0x0?T===null||T===void 0x0?void 0x0:T[Ji(0x1f9)]:s,P=Ji(0x23c);if(!_[Ji(0x236)](Y))P=Ji(0x1e7);else{if((T===null||T===void 0x0?void 0x0:T['type'])===Ji(0x1e4))P=Ji(0x1d3);else{if((T===null||T===void 0x0?void 0x0:T[Ji(0x1e3)])==='integer')P=Ji(0x1d4);else(T===null||T===void 0x0?void 0x0:T[Ji(0x1e3)])===Ji(0x25e)&&(P=Ji(0x1ef));}}g=n!==![]?!_[Ji(0x245)](G)?G:JSON[Ji(0x200)](G):_[Ji(0x238)](G)?G:'don\x27t\x20change';if(Y)g=g['toString']();_[Ji(0x1b4)](this[Ji(0x22c)],o['join']('.'))&&(g=this[Ji(0x22c)][o[Ji(0x23a)]('.')]);f=Y&&n===![]?__spreadArray(__spreadArray([],Y,!![]),[Ji(0x198)],![]):Y,C={'type':P,'name':'id','message':this[Ji(0x208)](o,T),'choices':f,'default':g,'filter':this[Ji(0x218)](P,n),'validate':this[Ji(0x18e)](T,n)};return[0x4,inquirer[Ji(0x24e)]([C])];case 0x2:E=M['sent']()['id'];return[0x2,E==='don\x27t\x20change'||E===''?undefined:E];}});});},J[JM(0x224)][JM(0x208)]=function(o,T){var Jw=JM,n=(T===null||T===void 0x0?void 0x0:T[Jw(0x1e3)])!==Jw(0x1e4)?'What\x20do\x20you\x20want\x20to\x20use\x20as':Jw(0x1a7);return this[Jw(0x197)](o,n,T===null||T===void 0x0?void 0x0:T[Jw(0x266)]);},J[JM(0x224)]['askForProject']=function(){return __awaiter(this,void 0x0,void 0x0,function(){var o,T;return __generator(this,function(n){var JI=a7o;switch(n[JI(0x1fa)]){case 0x0:return[0x4,this[JI(0x246)][JI(0x1e7)]['projects']({})];case 0x1:o=n[JI(0x1f1)](),T=o[JI(0x1ab)][JI(0x1fe)]['map'](function(k){return k['id'];});if(T['length']<0x1)throw new Error('No\x20projects\x20in\x20current\x20context');return[0x4,inquirer[JI(0x24e)]([{'type':JI(0x1e7),'name':JI(0x21c),'message':JI(0x1cc),'choices':T}])];case 0x2:return[0x2,n[JI(0x1f1)]()[JI(0x21c)]];}});});},J[JM(0x224)][JM(0x21a)]=function(o,T,n,k){return __awaiter(this,void 0x0,void 0x0,function(){var v,c;return __generator(this,function(B){var Ju=a7o;switch(B[Ju(0x1fa)]){case 0x0:v=n||this[Ju(0x246)]['contextProvider'][Ju(0x265)]();if(_[Ju(0x236)](v))throw new Error(Ju(0x1c9));return[0x4,T(v)];case 0x1:c=B[Ju(0x1f1)]();return[0x4,this[Ju(0x271)](o,c,''['concat'](k?''[Ju(0x243)](k,Ju(0x231)):'',Ju(0x264))[Ju(0x243)](v,'\x27'))];case 0x2:return[0x2,B[Ju(0x1f1)]()];}});});},J[JM(0x224)]['askForDomain']=function(){return __awaiter(this,void 0x0,void 0x0,function(){var o,T;return __generator(this,function(n){var JZ=a7o;switch(n[JZ(0x1fa)]){case 0x0:return[0x4,this[JZ(0x246)][JZ(0x1e7)][JZ(0x26f)]({})];case 0x1:o=n[JZ(0x1f1)](),T=o[JZ(0x1ab)][JZ(0x26f)][JZ(0x1bf)](function(k){var JN=JZ;return k[JN(0x21c)];});return[0x2,this[JZ(0x271)](JZ(0x1de),T)];}});});},J['prototype'][JM(0x1f3)]=function(){return __awaiter(this,void 0x0,void 0x0,function(){var o,T;return __generator(this,function(n){var JS=a7o;switch(n[JS(0x1fa)]){case 0x0:return[0x4,this['apiClient'][JS(0x1e7)][JS(0x1d2)]({})];case 0x1:o=n[JS(0x1f1)](),T=o['data'][JS(0x1c4)][JS(0x1bf)](function(k){return k['id'];});return[0x2,this[JS(0x271)](JS(0x1c4),T)];}});});},J[JM(0x224)][JM(0x1da)]=function(o){this['pathVars']=o;},J;}();function a7o(J,o){J=J-0x18c;var T=a7J[J];return T;}exports[a7l(0x222)]=InquirerHelper;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
14
|
+
if (k2 === undefined) k2 = k;
|
|
15
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
16
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
17
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
18
|
+
}
|
|
19
|
+
Object.defineProperty(o, k2, desc);
|
|
20
|
+
}) : (function(o, m, k, k2) {
|
|
21
|
+
if (k2 === undefined) k2 = k;
|
|
22
|
+
o[k2] = m[k];
|
|
23
|
+
}));
|
|
24
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
25
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
26
|
+
}) : function(o, v) {
|
|
27
|
+
o["default"] = v;
|
|
28
|
+
});
|
|
29
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
37
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
38
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
39
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
40
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
41
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
42
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
46
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
47
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
48
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
49
|
+
function step(op) {
|
|
50
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
51
|
+
while (_) try {
|
|
52
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
53
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
54
|
+
switch (op[0]) {
|
|
55
|
+
case 0: case 1: t = op; break;
|
|
56
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
57
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
58
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
59
|
+
default:
|
|
60
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
61
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
62
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
63
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
64
|
+
if (t[2]) _.ops.pop();
|
|
65
|
+
_.trys.pop(); continue;
|
|
66
|
+
}
|
|
67
|
+
op = body.call(thisArg, _);
|
|
68
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
69
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
73
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
74
|
+
if (ar || !(i in from)) {
|
|
75
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
76
|
+
ar[i] = from[i];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
80
|
+
};
|
|
81
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
82
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
83
|
+
};
|
|
84
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
85
|
+
exports.InquirerHelper = void 0;
|
|
86
|
+
/* eslint-disable no-await-in-loop */
|
|
87
|
+
var _ = __importStar(require("lodash"));
|
|
88
|
+
var chalk_1 = __importDefault(require("chalk"));
|
|
89
|
+
var fs = __importStar(require("fs"));
|
|
90
|
+
var inquirer_1 = __importDefault(require("inquirer"));
|
|
91
|
+
var inquirer_search_list_1 = __importDefault(require("inquirer-search-list"));
|
|
92
|
+
var utils_1 = require("./utils");
|
|
93
|
+
var api_helpers_1 = require("./api-helpers");
|
|
94
|
+
var inquirer_pagination_prompt_1 = require("./pagination/inquirer-pagination-prompt");
|
|
95
|
+
var yaml = require('js-yaml');
|
|
96
|
+
var ConfirmChoices;
|
|
97
|
+
(function (ConfirmChoices) {
|
|
98
|
+
ConfirmChoices["YES"] = "Yes, send";
|
|
99
|
+
ConfirmChoices["REPEAT"] = "No, repeat";
|
|
100
|
+
ConfirmChoices["EDIT"] = "No, edit";
|
|
101
|
+
ConfirmChoices["SAVE"] = "No, but save as file";
|
|
102
|
+
ConfirmChoices["ABORT"] = "No, abort";
|
|
103
|
+
})(ConfirmChoices || (ConfirmChoices = {}));
|
|
104
|
+
var InquirerHelper = /** @class */ (function () {
|
|
105
|
+
function InquirerHelper(apiClient) {
|
|
106
|
+
var _this = this;
|
|
107
|
+
this.apiClient = apiClient;
|
|
108
|
+
this.defaultPaginationPageSize = 50;
|
|
109
|
+
this.editPayload = function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
110
|
+
var editedResult;
|
|
111
|
+
return __generator(this, function (_a) {
|
|
112
|
+
switch (_a.label) {
|
|
113
|
+
case 0: return [4 /*yield*/, inquirer_1.default.prompt([
|
|
114
|
+
{
|
|
115
|
+
type: 'editor',
|
|
116
|
+
name: 'editedResult',
|
|
117
|
+
message: 'Go to editor',
|
|
118
|
+
default: yaml.safeDump(result),
|
|
119
|
+
},
|
|
120
|
+
])];
|
|
121
|
+
case 1:
|
|
122
|
+
editedResult = (_a.sent()).editedResult;
|
|
123
|
+
return [2 /*return*/, yaml.safeLoad(editedResult)];
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}); };
|
|
127
|
+
this.saveFile = function (result) { return __awaiter(_this, void 0, void 0, function () {
|
|
128
|
+
function prompFileName() {
|
|
129
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
130
|
+
return __generator(this, function (_a) {
|
|
131
|
+
return [2 /*return*/, inquirer_1.default.prompt([
|
|
132
|
+
{
|
|
133
|
+
type: 'input',
|
|
134
|
+
name: 'fileName',
|
|
135
|
+
message: 'Provide a file path to write the configuration to (<name>.[json|yaml|yml])',
|
|
136
|
+
validate: function (input) {
|
|
137
|
+
return new RegExp('.*\\.(json|yaml|yml)$').test(input) ? true : fileTypeWarning(input);
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
])];
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
var fileTypeWarning, filePath, fileEnding;
|
|
145
|
+
return __generator(this, function (_a) {
|
|
146
|
+
switch (_a.label) {
|
|
147
|
+
case 0:
|
|
148
|
+
fileTypeWarning = function (fileEnding) {
|
|
149
|
+
return "Unexpected file type: ".concat(fileEnding, ", supported types: [json|yaml|yml]");
|
|
150
|
+
};
|
|
151
|
+
return [4 /*yield*/, prompFileName()];
|
|
152
|
+
case 1:
|
|
153
|
+
filePath = (_a.sent()).fileName;
|
|
154
|
+
fileEnding = filePath.toString().split('.').pop();
|
|
155
|
+
try {
|
|
156
|
+
switch (fileEnding) {
|
|
157
|
+
case 'json':
|
|
158
|
+
(0, utils_1.success)("Configuration file written to ".concat(filePath));
|
|
159
|
+
return [2 /*return*/, fs.writeFileSync(filePath, JSON.stringify(result, null, ' '))];
|
|
160
|
+
case 'yaml':
|
|
161
|
+
case 'yml':
|
|
162
|
+
(0, utils_1.success)("Configuration file written to ".concat(filePath));
|
|
163
|
+
return [2 /*return*/, fs.writeFileSync(filePath, yaml.safeDump(result))];
|
|
164
|
+
default:
|
|
165
|
+
(0, utils_1.warning)(fileTypeWarning(fileEnding));
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
catch (e) {
|
|
169
|
+
(0, utils_1.warning)("Writing configuration failed: ".concat(e.message));
|
|
170
|
+
}
|
|
171
|
+
return [2 /*return*/, undefined];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}); };
|
|
175
|
+
this.filter = function (type, required) { return function (input) {
|
|
176
|
+
var sanitisedInput = typeof input === 'string' ? input.trim() : input;
|
|
177
|
+
return required === false && sanitisedInput === "don't change" ? '' : sanitisedInput;
|
|
178
|
+
}; };
|
|
179
|
+
this.validate = function (prop, required, actuallyNumber) { return function (input) {
|
|
180
|
+
var valid = [];
|
|
181
|
+
if (input === '' || input === "don't change") {
|
|
182
|
+
if (required !== false) {
|
|
183
|
+
valid.push("this option is required, please answer");
|
|
184
|
+
}
|
|
185
|
+
else {
|
|
186
|
+
return true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
if (prop.type === 'string' && !_.isUndefined(prop.pattern)) {
|
|
190
|
+
valid.push(new RegExp(prop.pattern).test(input) ? true : "doesn't match pattern '".concat(prop.pattern, "'"));
|
|
191
|
+
}
|
|
192
|
+
if (prop.type === 'string' && !_.isUndefined(prop.minLength)) {
|
|
193
|
+
valid.push(input.length >= prop.minLength
|
|
194
|
+
? true
|
|
195
|
+
: "must be longer than or equal to ".concat(prop.minLength, " characters, is ").concat(input.length, " characters"));
|
|
196
|
+
}
|
|
197
|
+
if (prop.type === 'string' && !_.isUndefined(prop.maxLength)) {
|
|
198
|
+
valid.push(input.length <= prop.maxLength
|
|
199
|
+
? true
|
|
200
|
+
: "must be shorter than or equal to ".concat(prop.maxLength, " characters, is ").concat(input.length, " characters"));
|
|
201
|
+
}
|
|
202
|
+
if (actuallyNumber && Number.isNaN(parseInt(input, 10))) {
|
|
203
|
+
valid.push("must be a number, is ".concat(input));
|
|
204
|
+
}
|
|
205
|
+
if (prop.type === 'integer' && !_.isUndefined(prop.minimum)) {
|
|
206
|
+
valid.push(input >= prop.minimum ? true : "must be bigger than or equal to ".concat(prop.minimum));
|
|
207
|
+
}
|
|
208
|
+
if (prop.type === 'integer' && !_.isUndefined(prop.maximum)) {
|
|
209
|
+
valid.push(input <= prop.maximum ? true : "must be smaller than or equal to ".concat(prop.maximum));
|
|
210
|
+
}
|
|
211
|
+
if (prop.type === 'rawObject') {
|
|
212
|
+
var asJson = (0, utils_1.isValidJSON)(input);
|
|
213
|
+
valid.push(asJson === false || _.isEmpty(asJson) ? "must be a valid non-empty json string" : true);
|
|
214
|
+
}
|
|
215
|
+
var errors = valid.filter(function (e) { return e !== true; });
|
|
216
|
+
var example = (prop === null || prop === void 0 ? void 0 : prop.example)
|
|
217
|
+
? "\n".concat(chalk_1.default.red('>>'), " Example: ").concat(chalk_1.default.whiteBright(JSON.stringify(prop.example)))
|
|
218
|
+
: '';
|
|
219
|
+
return errors.length > 0 ? errors.join(chalk_1.default.underline(' and it ')) + example : true;
|
|
220
|
+
}; };
|
|
221
|
+
this.getPathString = function (propPath, question, description) {
|
|
222
|
+
var current = propPath[propPath.length - 1];
|
|
223
|
+
function stringifyPath() {
|
|
224
|
+
return propPath
|
|
225
|
+
.slice(0, -1)
|
|
226
|
+
.map(function (p) { return p.charAt(0).toUpperCase() + p.slice(1); })
|
|
227
|
+
.join('>');
|
|
228
|
+
}
|
|
229
|
+
var path = propPath.length > 1 ? "".concat(chalk_1.default.bgGrey.whiteBright(stringifyPath()), ": ") : '';
|
|
230
|
+
var descr = description ? " (".concat(chalk_1.default.blue(description), ")") : '';
|
|
231
|
+
return chalk_1.default.reset("".concat(path).concat(question, " ").concat(chalk_1.default.bold.greenBright(current)).concat(descr, "?"));
|
|
232
|
+
};
|
|
233
|
+
this.askForResource = function (resourceName, resourceNames, scopedBy) { return __awaiter(_this, void 0, void 0, function () {
|
|
234
|
+
var scope, message, type;
|
|
235
|
+
return __generator(this, function (_a) {
|
|
236
|
+
switch (_a.label) {
|
|
237
|
+
case 0:
|
|
238
|
+
if (resourceNames.length < 1) {
|
|
239
|
+
scope = scopedBy ? "for this ".concat(scopedBy) : 'found';
|
|
240
|
+
throw new Error("No ".concat(resourceName, " ").concat(scope, "."));
|
|
241
|
+
}
|
|
242
|
+
message = "Choose the ".concat(resourceName, " to use:");
|
|
243
|
+
type = resourceNames.length > 4 ? 'search-list' : 'list';
|
|
244
|
+
return [4 /*yield*/, inquirer_1.default.prompt([{ type: type, name: 'name', message: message, choices: resourceNames }])];
|
|
245
|
+
case 1: return [2 /*return*/, (_a.sent()).name];
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}); };
|
|
249
|
+
this.askForResourcePaginated = function (resourceName, resourceFetcher, scopedBy) { return __awaiter(_this, void 0, void 0, function () {
|
|
250
|
+
var _a, elements, nextCursor, scope, message, loadNextPage, type;
|
|
251
|
+
var _this = this;
|
|
252
|
+
return __generator(this, function (_b) {
|
|
253
|
+
switch (_b.label) {
|
|
254
|
+
case 0: return [4 /*yield*/, resourceFetcher()];
|
|
255
|
+
case 1:
|
|
256
|
+
_a = _b.sent(), elements = _a.elements, nextCursor = _a.nextCursor;
|
|
257
|
+
if (elements.length < 1) {
|
|
258
|
+
scope = scopedBy ? "for this ".concat(scopedBy) : 'found';
|
|
259
|
+
throw new Error("No ".concat(resourceName, " ").concat(scope, "."));
|
|
260
|
+
}
|
|
261
|
+
message = "Choose the ".concat(resourceName, " to use:");
|
|
262
|
+
if (!(nextCursor !== undefined)) return [3 /*break*/, 3];
|
|
263
|
+
loadNextPage = function (_a) {
|
|
264
|
+
var nextPageCursor = _a.nextPageCursor;
|
|
265
|
+
return __awaiter(_this, void 0, void 0, function () {
|
|
266
|
+
var nextPage;
|
|
267
|
+
return __generator(this, function (_b) {
|
|
268
|
+
switch (_b.label) {
|
|
269
|
+
case 0: return [4 /*yield*/, resourceFetcher(nextPageCursor)];
|
|
270
|
+
case 1:
|
|
271
|
+
nextPage = _b.sent();
|
|
272
|
+
return [2 /*return*/, { elements: nextPage.elements, nextPageCursor: nextPage.nextCursor }];
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
278
|
+
{
|
|
279
|
+
type: 'pagination-prompt',
|
|
280
|
+
name: 'name',
|
|
281
|
+
message: message,
|
|
282
|
+
choices: elements,
|
|
283
|
+
nextPageCursor: nextCursor,
|
|
284
|
+
loadMore: loadNextPage,
|
|
285
|
+
},
|
|
286
|
+
])];
|
|
287
|
+
case 2: return [2 /*return*/, (_b.sent()).name];
|
|
288
|
+
case 3:
|
|
289
|
+
type = elements.length > 4 ? 'search-list' : 'list';
|
|
290
|
+
return [4 /*yield*/, inquirer_1.default.prompt([{ type: type, name: 'name', message: message, choices: elements }])];
|
|
291
|
+
case 4: return [2 /*return*/, (_b.sent()).name];
|
|
292
|
+
}
|
|
293
|
+
});
|
|
294
|
+
}); };
|
|
295
|
+
this.askGeneric = function (resourceName, description) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
296
|
+
var descrMsg, message, validate;
|
|
297
|
+
return __generator(this, function (_a) {
|
|
298
|
+
switch (_a.label) {
|
|
299
|
+
case 0:
|
|
300
|
+
descrMsg = "".concat(description ? "(".concat(chalk_1.default.blue(description), ") ") : '');
|
|
301
|
+
message = "Enter the ".concat(chalk_1.default.green(resourceName), " ").concat(descrMsg, "to use:");
|
|
302
|
+
validate = this.validate({ type: 'string', required: true });
|
|
303
|
+
return [4 /*yield*/, inquirer_1.default.prompt([{ type: 'input', name: 'name', message: message, validate: validate }])];
|
|
304
|
+
case 1: return [2 /*return*/, (_a.sent()).name];
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
}); }; };
|
|
308
|
+
this.askConfirm = function (message) { return __awaiter(_this, void 0, void 0, function () {
|
|
309
|
+
return __generator(this, function (_a) {
|
|
310
|
+
switch (_a.label) {
|
|
311
|
+
case 0: return [4 /*yield*/, inquirer_1.default.prompt([{ type: 'confirm', name: 'name', message: message, default: true }])];
|
|
312
|
+
case 1: return [2 /*return*/, (_a.sent())
|
|
313
|
+
.name];
|
|
314
|
+
}
|
|
315
|
+
});
|
|
316
|
+
}); };
|
|
317
|
+
this.askForService = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
318
|
+
var apiCall;
|
|
319
|
+
var _this = this;
|
|
320
|
+
return __generator(this, function (_a) {
|
|
321
|
+
apiCall = function (projectName) { return function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
322
|
+
var listServicesResponse, elements;
|
|
323
|
+
var _a;
|
|
324
|
+
return __generator(this, function (_b) {
|
|
325
|
+
switch (_b.label) {
|
|
326
|
+
case 0: return [4 /*yield*/, this.apiClient.list.services({
|
|
327
|
+
parameters: { projectId: projectName },
|
|
328
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
329
|
+
})];
|
|
330
|
+
case 1:
|
|
331
|
+
listServicesResponse = _b.sent();
|
|
332
|
+
elements = listServicesResponse.data.services.map(function (svc) { return svc.id; });
|
|
333
|
+
return [2 /*return*/, { elements: elements, nextCursor: (_a = listServicesResponse.pagination) === null || _a === void 0 ? void 0 : _a.cursor }];
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}); }; };
|
|
337
|
+
return [2 /*return*/, this.askForProjectScopedResourcePaginated('service', apiCall, project)];
|
|
338
|
+
});
|
|
339
|
+
}); }; };
|
|
340
|
+
this.askForJob = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
341
|
+
var apiCall;
|
|
342
|
+
var _this = this;
|
|
343
|
+
return __generator(this, function (_a) {
|
|
344
|
+
apiCall = function (projectName) { return function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
345
|
+
var listJobsResponse, elements;
|
|
346
|
+
var _a;
|
|
347
|
+
return __generator(this, function (_b) {
|
|
348
|
+
switch (_b.label) {
|
|
349
|
+
case 0: return [4 /*yield*/, this.apiClient.list.jobs({
|
|
350
|
+
parameters: { projectId: projectName },
|
|
351
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
352
|
+
})];
|
|
353
|
+
case 1:
|
|
354
|
+
listJobsResponse = _b.sent();
|
|
355
|
+
elements = listJobsResponse.data.jobs.map(function (job) { return job.id; });
|
|
356
|
+
return [2 /*return*/, { elements: elements, nextCursor: (_a = listJobsResponse.pagination) === null || _a === void 0 ? void 0 : _a.cursor }];
|
|
357
|
+
}
|
|
358
|
+
});
|
|
359
|
+
}); }; };
|
|
360
|
+
return [2 /*return*/, this.askForProjectScopedResourcePaginated('job', apiCall, project)];
|
|
361
|
+
});
|
|
362
|
+
}); }; };
|
|
363
|
+
this.askForJobRun = function (jobName, project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
364
|
+
var apiCall;
|
|
365
|
+
var _this = this;
|
|
366
|
+
return __generator(this, function (_a) {
|
|
367
|
+
apiCall = function (projectName) { return function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
368
|
+
var listJobRunsResponse, elements;
|
|
369
|
+
var _a;
|
|
370
|
+
return __generator(this, function (_b) {
|
|
371
|
+
switch (_b.label) {
|
|
372
|
+
case 0: return [4 /*yield*/, this.apiClient.get.job.runs({
|
|
373
|
+
parameters: { projectId: projectName, jobId: jobName },
|
|
374
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
375
|
+
})];
|
|
376
|
+
case 1:
|
|
377
|
+
listJobRunsResponse = _b.sent();
|
|
378
|
+
elements = listJobRunsResponse.data.runs.map(function (job) { return "".concat(job.id, " (startedAt: ").concat(job.startedAt, ")"); });
|
|
379
|
+
return [2 /*return*/, { elements: elements, nextCursor: (_a = listJobRunsResponse.pagination) === null || _a === void 0 ? void 0 : _a.cursor }];
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
}); }; };
|
|
383
|
+
return [2 /*return*/, this.askForProjectScopedResourcePaginated('job runs', apiCall, project, "job: '".concat(jobName, "'")).then(function (j) { return j.split(' ')[0]; })];
|
|
384
|
+
});
|
|
385
|
+
}); }; };
|
|
386
|
+
this.askForBuild = function (project, serviceId, jobId) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
387
|
+
var apiCall, apiCall;
|
|
388
|
+
var _this = this;
|
|
389
|
+
return __generator(this, function (_a) {
|
|
390
|
+
if (jobId !== undefined) {
|
|
391
|
+
apiCall = function (projectName) { return function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
392
|
+
var listBuildsResponse;
|
|
393
|
+
var _a;
|
|
394
|
+
return __generator(this, function (_b) {
|
|
395
|
+
switch (_b.label) {
|
|
396
|
+
case 0: return [4 /*yield*/, this.apiClient.get.job.builds({
|
|
397
|
+
parameters: { projectId: projectName, jobId: jobId },
|
|
398
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
399
|
+
})];
|
|
400
|
+
case 1:
|
|
401
|
+
listBuildsResponse = _b.sent();
|
|
402
|
+
return [2 /*return*/, {
|
|
403
|
+
elements: listBuildsResponse.data.builds.map(function (build) { return "".concat(build.id, " (startedAt: ").concat(build.createdAt, ")"); }),
|
|
404
|
+
nextCursor: (_a = listBuildsResponse.pagination) === null || _a === void 0 ? void 0 : _a.cursor,
|
|
405
|
+
}];
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}); }; };
|
|
409
|
+
return [2 /*return*/, this.askForProjectScopedResourcePaginated('job builds', apiCall, project, "job: '".concat(jobId, "'")).then(function (j) { return j.split(' ')[0]; })];
|
|
410
|
+
}
|
|
411
|
+
if (serviceId !== undefined) {
|
|
412
|
+
apiCall = function (projectName) { return function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
413
|
+
var listBuildsResponse;
|
|
414
|
+
var _a;
|
|
415
|
+
return __generator(this, function (_b) {
|
|
416
|
+
switch (_b.label) {
|
|
417
|
+
case 0: return [4 /*yield*/, this.apiClient.get.service.builds({
|
|
418
|
+
parameters: { projectId: projectName, serviceId: serviceId },
|
|
419
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
420
|
+
})];
|
|
421
|
+
case 1:
|
|
422
|
+
listBuildsResponse = _b.sent();
|
|
423
|
+
return [2 /*return*/, {
|
|
424
|
+
elements: listBuildsResponse.data.builds.map(function (build) { return "".concat(build.id, " (startedAt: ").concat(build.createdAt, ")"); }),
|
|
425
|
+
nextCursor: (_a = listBuildsResponse.pagination) === null || _a === void 0 ? void 0 : _a.cursor,
|
|
426
|
+
}];
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
}); }; };
|
|
430
|
+
return [2 /*return*/, this.askForProjectScopedResourcePaginated('job build', apiCall, project, "service: '".concat(jobId, "'")).then(function (j) { return j.split(' ')[0]; })];
|
|
431
|
+
}
|
|
432
|
+
throw new Error('No builds found');
|
|
433
|
+
});
|
|
434
|
+
}); }; };
|
|
435
|
+
this.askForAddon = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
436
|
+
var apiCall;
|
|
437
|
+
var _this = this;
|
|
438
|
+
return __generator(this, function (_a) {
|
|
439
|
+
apiCall = function (projectName) { return function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
440
|
+
var listAddonsResponse;
|
|
441
|
+
var _a;
|
|
442
|
+
return __generator(this, function (_b) {
|
|
443
|
+
switch (_b.label) {
|
|
444
|
+
case 0: return [4 /*yield*/, this.apiClient.list.addons({
|
|
445
|
+
parameters: { projectId: projectName },
|
|
446
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
447
|
+
})];
|
|
448
|
+
case 1:
|
|
449
|
+
listAddonsResponse = _b.sent();
|
|
450
|
+
return [2 /*return*/, {
|
|
451
|
+
elements: listAddonsResponse.data.addons.map(function (svc) { return svc.id; }),
|
|
452
|
+
nextCursor: (_a = listAddonsResponse.pagination) === null || _a === void 0 ? void 0 : _a.cursor,
|
|
453
|
+
}];
|
|
454
|
+
}
|
|
455
|
+
});
|
|
456
|
+
}); }; };
|
|
457
|
+
return [2 /*return*/, this.askForProjectScopedResourcePaginated('addon', apiCall, project)];
|
|
458
|
+
});
|
|
459
|
+
}); }; };
|
|
460
|
+
this.askForAddonBackup = function (project, addon) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
461
|
+
var apiCall;
|
|
462
|
+
var _this = this;
|
|
463
|
+
return __generator(this, function (_a) {
|
|
464
|
+
apiCall = function (projectName) { return function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
465
|
+
var listAddonsBackupResponse;
|
|
466
|
+
var _a;
|
|
467
|
+
return __generator(this, function (_b) {
|
|
468
|
+
switch (_b.label) {
|
|
469
|
+
case 0: return [4 /*yield*/, this.apiClient.get.addon.backups({
|
|
470
|
+
parameters: {
|
|
471
|
+
projectId: projectName,
|
|
472
|
+
addonId: addon,
|
|
473
|
+
},
|
|
474
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
475
|
+
})];
|
|
476
|
+
case 1:
|
|
477
|
+
listAddonsBackupResponse = _b.sent();
|
|
478
|
+
return [2 /*return*/, {
|
|
479
|
+
elements: listAddonsBackupResponse.data.backups.map(function (job) { return "".concat(job.id, " (completedAt: ").concat(job.completedAt || 'not completed', ")"); }),
|
|
480
|
+
nextCursor: (_a = listAddonsBackupResponse.pagination) === null || _a === void 0 ? void 0 : _a.cursor,
|
|
481
|
+
}];
|
|
482
|
+
}
|
|
483
|
+
});
|
|
484
|
+
}); }; };
|
|
485
|
+
return [2 /*return*/, this.askForProjectScopedResourcePaginated('backups', apiCall, project, "addon: '".concat(addon, "'")).then(function (j) { return j.split(' ')[0]; })];
|
|
486
|
+
});
|
|
487
|
+
}); }; };
|
|
488
|
+
this.askForVolume = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
489
|
+
var apiCall;
|
|
490
|
+
var _this = this;
|
|
491
|
+
return __generator(this, function (_a) {
|
|
492
|
+
apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
|
|
493
|
+
return __generator(this, function (_a) {
|
|
494
|
+
switch (_a.label) {
|
|
495
|
+
case 0: return [4 /*yield*/, this.apiClient.list.volumes({ parameters: { projectId: projectName } })];
|
|
496
|
+
case 1: return [2 /*return*/, (_a.sent()).data.map(function (vol) { return vol.id; })];
|
|
497
|
+
}
|
|
498
|
+
});
|
|
499
|
+
}); };
|
|
500
|
+
return [2 /*return*/, this.askForProjectScopedResource('volume', apiCall, project)];
|
|
501
|
+
});
|
|
502
|
+
}); }; };
|
|
503
|
+
this.askForSecret = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
504
|
+
var apiCall;
|
|
505
|
+
var _this = this;
|
|
506
|
+
return __generator(this, function (_a) {
|
|
507
|
+
apiCall = function (projectName) { return function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
508
|
+
var listSecretsResponse;
|
|
509
|
+
var _a;
|
|
510
|
+
return __generator(this, function (_b) {
|
|
511
|
+
switch (_b.label) {
|
|
512
|
+
case 0: return [4 /*yield*/, this.apiClient.list.secrets({
|
|
513
|
+
parameters: { projectId: projectName },
|
|
514
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
515
|
+
})];
|
|
516
|
+
case 1:
|
|
517
|
+
listSecretsResponse = _b.sent();
|
|
518
|
+
return [2 /*return*/, {
|
|
519
|
+
elements: listSecretsResponse.data.secrets.map(function (svc) { return svc.id; }),
|
|
520
|
+
nextCursor: (_a = listSecretsResponse.pagination) === null || _a === void 0 ? void 0 : _a.cursor,
|
|
521
|
+
}];
|
|
522
|
+
}
|
|
523
|
+
});
|
|
524
|
+
}); }; };
|
|
525
|
+
return [2 /*return*/, this.askForProjectScopedResourcePaginated('secret', apiCall, project)];
|
|
526
|
+
});
|
|
527
|
+
}); }; };
|
|
528
|
+
this.askForSubdomain = function (domain) { return function () { return __awaiter(_this, void 0, void 0, function () {
|
|
529
|
+
var getDomainResponse, subdomains, scopedBy;
|
|
530
|
+
return __generator(this, function (_a) {
|
|
531
|
+
switch (_a.label) {
|
|
532
|
+
case 0: return [4 /*yield*/, this.apiClient.get.domain({
|
|
533
|
+
parameters: { domain: domain },
|
|
534
|
+
})];
|
|
535
|
+
case 1:
|
|
536
|
+
getDomainResponse = _a.sent();
|
|
537
|
+
subdomains = getDomainResponse.data.subdomains.map(function (d) { return "".concat(d.name, " (full domain: ").concat(d.fullName, ")"); });
|
|
538
|
+
scopedBy = "domain (".concat(domain, ")");
|
|
539
|
+
return [2 /*return*/, this.askForResource('subdomain', subdomains, scopedBy).then(function (j) { return j.split(' ')[0]; })];
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
}); }; };
|
|
543
|
+
this.deleteWarningPrompt = function (resourceString) { return __awaiter(_this, void 0, void 0, function () {
|
|
544
|
+
return __generator(this, function (_a) {
|
|
545
|
+
switch (_a.label) {
|
|
546
|
+
case 0: return [4 /*yield*/, inquirer_1.default.prompt([
|
|
547
|
+
{
|
|
548
|
+
type: 'confirm',
|
|
549
|
+
name: 'confirmation',
|
|
550
|
+
message: chalk_1.default.yellowBright("WARNING: You are about to delete ".concat(resourceString || 'a Northflank resource', ". This is irreversible. Please confirm!")),
|
|
551
|
+
default: false,
|
|
552
|
+
},
|
|
553
|
+
])];
|
|
554
|
+
case 1: return [2 /*return*/, (_a.sent()).confirmation];
|
|
555
|
+
}
|
|
556
|
+
});
|
|
557
|
+
}); };
|
|
558
|
+
this.loginPrompt = function (options, existingContexts) { return __awaiter(_this, void 0, void 0, function () {
|
|
559
|
+
var token;
|
|
560
|
+
var _this = this;
|
|
561
|
+
return __generator(this, function (_a) {
|
|
562
|
+
switch (_a.label) {
|
|
563
|
+
case 0:
|
|
564
|
+
if (!_.isUndefined(options.name)) return [3 /*break*/, 3];
|
|
565
|
+
if (!(existingContexts.length <= 0)) return [3 /*break*/, 1];
|
|
566
|
+
_.set(options, 'name', 'default');
|
|
567
|
+
return [3 /*break*/, 3];
|
|
568
|
+
case 1: return [4 /*yield*/, (0, utils_1.retry)(10)(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
569
|
+
var name, c;
|
|
570
|
+
return __generator(this, function (_a) {
|
|
571
|
+
switch (_a.label) {
|
|
572
|
+
case 0: return [4 /*yield*/, inquirer_1.default.prompt([
|
|
573
|
+
{
|
|
574
|
+
type: 'input',
|
|
575
|
+
name: 'name',
|
|
576
|
+
message: 'Choose the name of the new local context:',
|
|
577
|
+
default: 'main-context',
|
|
578
|
+
},
|
|
579
|
+
])];
|
|
580
|
+
case 1:
|
|
581
|
+
name = (_a.sent()).name;
|
|
582
|
+
if (!(!options.override && existingContexts.find(function (ctx) { return ctx.name === name; }))) return [3 /*break*/, 3];
|
|
583
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
584
|
+
{
|
|
585
|
+
type: 'confirm',
|
|
586
|
+
name: 'c',
|
|
587
|
+
message: "Context with name '".concat(name, "' already exists. Do you want to override this context (y) or enter a new name (N)?"),
|
|
588
|
+
default: false,
|
|
589
|
+
},
|
|
590
|
+
])];
|
|
591
|
+
case 2:
|
|
592
|
+
c = (_a.sent()).c;
|
|
593
|
+
if (c === false)
|
|
594
|
+
throw new Error('Context name already exists.');
|
|
595
|
+
_.set(options, 'override', true);
|
|
596
|
+
_a.label = 3;
|
|
597
|
+
case 3:
|
|
598
|
+
_.set(options, 'name', name);
|
|
599
|
+
return [2 /*return*/];
|
|
600
|
+
}
|
|
601
|
+
});
|
|
602
|
+
}); })];
|
|
603
|
+
case 2:
|
|
604
|
+
_a.sent();
|
|
605
|
+
_a.label = 3;
|
|
606
|
+
case 3:
|
|
607
|
+
if (!_.isUndefined(options.token)) return [3 /*break*/, 5];
|
|
608
|
+
return [4 /*yield*/, this.tokenPrompt()];
|
|
609
|
+
case 4:
|
|
610
|
+
token = _a.sent();
|
|
611
|
+
_.set(options, 'token', token);
|
|
612
|
+
_a.label = 5;
|
|
613
|
+
case 5: return [2 /*return*/, options];
|
|
614
|
+
}
|
|
615
|
+
});
|
|
616
|
+
}); };
|
|
617
|
+
this.tokenPrompt = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
618
|
+
var token;
|
|
619
|
+
return __generator(this, function (_a) {
|
|
620
|
+
switch (_a.label) {
|
|
621
|
+
case 0: return [4 /*yield*/, inquirer_1.default.prompt([
|
|
622
|
+
{
|
|
623
|
+
type: 'password',
|
|
624
|
+
name: 'token',
|
|
625
|
+
mask: '*',
|
|
626
|
+
message: 'Choose the login token:',
|
|
627
|
+
},
|
|
628
|
+
])];
|
|
629
|
+
case 1:
|
|
630
|
+
token = (_a.sent()).token;
|
|
631
|
+
return [2 /*return*/, token];
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
}); };
|
|
635
|
+
inquirer_1.default.registerPrompt('search-list', inquirer_search_list_1.default);
|
|
636
|
+
inquirer_1.default.registerPrompt('pagination-prompt', inquirer_pagination_prompt_1.DynamicReloadPaginationPrompt);
|
|
637
|
+
}
|
|
638
|
+
InquirerHelper.prototype.confirmationPrompt = function (result, defaultOpt) {
|
|
639
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
640
|
+
var resultDump, length, divider, confirm, _a, _b;
|
|
641
|
+
return __generator(this, function (_c) {
|
|
642
|
+
switch (_c.label) {
|
|
643
|
+
case 0:
|
|
644
|
+
resultDump = yaml.safeDump(result);
|
|
645
|
+
length = _.max(resultDump.split('\n').map(function (l) { return l.length; }));
|
|
646
|
+
divider = chalk_1.default.grey("".concat('-'.repeat(length), "\n"));
|
|
647
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
648
|
+
{
|
|
649
|
+
type: 'list',
|
|
650
|
+
name: 'confirm',
|
|
651
|
+
message: "".concat(chalk_1.default.bold.green('Please confirm following configuration:\n')).concat(divider).concat(chalk_1.default.blueBright(resultDump)).concat(divider),
|
|
652
|
+
choices: Object.values(ConfirmChoices),
|
|
653
|
+
},
|
|
654
|
+
])];
|
|
655
|
+
case 1:
|
|
656
|
+
confirm = (_c.sent()).confirm;
|
|
657
|
+
_a = confirm;
|
|
658
|
+
switch (_a) {
|
|
659
|
+
case ConfirmChoices.YES: return [3 /*break*/, 2];
|
|
660
|
+
case ConfirmChoices.ABORT: return [3 /*break*/, 3];
|
|
661
|
+
case ConfirmChoices.REPEAT: return [3 /*break*/, 4];
|
|
662
|
+
case ConfirmChoices.EDIT: return [3 /*break*/, 5];
|
|
663
|
+
case ConfirmChoices.SAVE: return [3 /*break*/, 7];
|
|
664
|
+
}
|
|
665
|
+
return [3 /*break*/, 9];
|
|
666
|
+
case 2: return [2 /*return*/, result];
|
|
667
|
+
case 3: throw new Error('Aborted.');
|
|
668
|
+
case 4: return [2 /*return*/, this.retrievePayloadViaInteractiveCli(defaultOpt)];
|
|
669
|
+
case 5:
|
|
670
|
+
_b = this.confirmationPrompt;
|
|
671
|
+
return [4 /*yield*/, this.editPayload(result)];
|
|
672
|
+
case 6: return [2 /*return*/, _b.apply(this, [_c.sent(), defaultOpt])];
|
|
673
|
+
case 7: return [4 /*yield*/, this.saveFile(result)];
|
|
674
|
+
case 8:
|
|
675
|
+
_c.sent();
|
|
676
|
+
return [2 /*return*/, this.confirmationPrompt(result, defaultOpt)];
|
|
677
|
+
case 9: throw new Error('Something unexpected happened.');
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
});
|
|
681
|
+
};
|
|
682
|
+
InquirerHelper.prototype.retrievePayloadViaInteractiveCli = function (defaultOpt, ctx) {
|
|
683
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
684
|
+
var result;
|
|
685
|
+
return __generator(this, function (_a) {
|
|
686
|
+
switch (_a.label) {
|
|
687
|
+
case 0:
|
|
688
|
+
if ((ctx === null || ctx === void 0 ? void 0 : ctx.resultCache) !== undefined)
|
|
689
|
+
this.resultCache = ctx === null || ctx === void 0 ? void 0 : ctx.resultCache;
|
|
690
|
+
this.tmpCmdPath = ctx === null || ctx === void 0 ? void 0 : ctx.cmdPath;
|
|
691
|
+
result = {};
|
|
692
|
+
return [4 /*yield*/, this.propToType([], defaultOpt.opt.body, result)];
|
|
693
|
+
case 1:
|
|
694
|
+
_a.sent();
|
|
695
|
+
this.resultCache = result;
|
|
696
|
+
return [4 /*yield*/, this.confirmationPrompt(result, defaultOpt)];
|
|
697
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
698
|
+
}
|
|
699
|
+
});
|
|
700
|
+
});
|
|
701
|
+
};
|
|
702
|
+
InquirerHelper.prototype.propToType = function (propPath, prop, obj, required) {
|
|
703
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
704
|
+
var type, choice_1, oneOfProp;
|
|
705
|
+
return __generator(this, function (_a) {
|
|
706
|
+
switch (_a.label) {
|
|
707
|
+
case 0:
|
|
708
|
+
if (!(prop.oneOf && !_.has(prop, 'properties'))) return [3 /*break*/, 6];
|
|
709
|
+
if (!(prop.oneOf.length > 1)) return [3 /*break*/, 3];
|
|
710
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
711
|
+
{
|
|
712
|
+
type: 'list',
|
|
713
|
+
name: 'choice',
|
|
714
|
+
message: "What's the ".concat(propPath[propPath.length - 1] || '', " type?"),
|
|
715
|
+
choices: prop.oneOf.map(function (p) { return p.description; }),
|
|
716
|
+
},
|
|
717
|
+
])];
|
|
718
|
+
case 1:
|
|
719
|
+
choice_1 = (_a.sent()).choice;
|
|
720
|
+
return [4 /*yield*/, this.getType(propPath, prop.oneOf.find(function (p) { return p.description === choice_1; }), obj, required)];
|
|
721
|
+
case 2:
|
|
722
|
+
type = _a.sent();
|
|
723
|
+
return [3 /*break*/, 5];
|
|
724
|
+
case 3:
|
|
725
|
+
oneOfProp = prop.oneOf[0];
|
|
726
|
+
_.set(oneOfProp, 'description', prop.description);
|
|
727
|
+
return [4 /*yield*/, this.getType(propPath, oneOfProp, obj, required)];
|
|
728
|
+
case 4:
|
|
729
|
+
type = _a.sent();
|
|
730
|
+
_a.label = 5;
|
|
731
|
+
case 5:
|
|
732
|
+
type = {};
|
|
733
|
+
return [3 /*break*/, 8];
|
|
734
|
+
case 6: return [4 /*yield*/, this.getType(propPath, prop, obj, required)];
|
|
735
|
+
case 7:
|
|
736
|
+
type = _a.sent();
|
|
737
|
+
_a.label = 8;
|
|
738
|
+
case 8: return [2 /*return*/, type];
|
|
739
|
+
}
|
|
740
|
+
});
|
|
741
|
+
});
|
|
742
|
+
};
|
|
743
|
+
InquirerHelper.prototype.getInnerType = function (prop, path, obj, required) {
|
|
744
|
+
var _a;
|
|
745
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
746
|
+
var addEntry, propertyKeys, requiredProps, _i, propertyKeys_1, propNameInner, innerPath;
|
|
747
|
+
return __generator(this, function (_b) {
|
|
748
|
+
switch (_b.label) {
|
|
749
|
+
case 0:
|
|
750
|
+
if (!(required === false)) return [3 /*break*/, 2];
|
|
751
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
752
|
+
{
|
|
753
|
+
type: 'confirm',
|
|
754
|
+
name: 'addEntry',
|
|
755
|
+
message: this.getPathString(path, "Do you want to add", prop === null || prop === void 0 ? void 0 : prop.description),
|
|
756
|
+
default: false,
|
|
757
|
+
},
|
|
758
|
+
])];
|
|
759
|
+
case 1:
|
|
760
|
+
addEntry = (_b.sent()).addEntry;
|
|
761
|
+
if (!addEntry)
|
|
762
|
+
return [2 /*return*/, obj];
|
|
763
|
+
_b.label = 2;
|
|
764
|
+
case 2:
|
|
765
|
+
propertyKeys = Object.keys((_a = prop === null || prop === void 0 ? void 0 : prop.properties) !== null && _a !== void 0 ? _a : []);
|
|
766
|
+
requiredProps = prop.required || [];
|
|
767
|
+
if (!(propertyKeys.length > 0)) return [3 /*break*/, 7];
|
|
768
|
+
_i = 0, propertyKeys_1 = propertyKeys;
|
|
769
|
+
_b.label = 3;
|
|
770
|
+
case 3:
|
|
771
|
+
if (!(_i < propertyKeys_1.length)) return [3 /*break*/, 6];
|
|
772
|
+
propNameInner = propertyKeys_1[_i];
|
|
773
|
+
innerPath = path.concat(propNameInner);
|
|
774
|
+
// innerPath.concat(propNameInner);
|
|
775
|
+
// eslint-disable-next-line no-await-in-loop
|
|
776
|
+
if (path.length > 0 && !_.has(obj, path.join('.')))
|
|
777
|
+
_.set(obj, path.join('.'), {});
|
|
778
|
+
return [4 /*yield*/, this.propToType(innerPath, prop.properties[propNameInner], obj, requiredProps.includes(propNameInner))];
|
|
779
|
+
case 4:
|
|
780
|
+
_b.sent();
|
|
781
|
+
_b.label = 5;
|
|
782
|
+
case 5:
|
|
783
|
+
_i++;
|
|
784
|
+
return [3 /*break*/, 3];
|
|
785
|
+
case 6: return [3 /*break*/, 9];
|
|
786
|
+
case 7: return [4 /*yield*/, this.getType(path, __assign(__assign({}, prop), { type: 'rawObject' }), obj, required)];
|
|
787
|
+
case 8:
|
|
788
|
+
_b.sent();
|
|
789
|
+
_b.label = 9;
|
|
790
|
+
case 9: return [2 /*return*/, obj];
|
|
791
|
+
}
|
|
792
|
+
});
|
|
793
|
+
});
|
|
794
|
+
};
|
|
795
|
+
InquirerHelper.prototype.askArrayEntry = function (propPath, firstTime, required, description) {
|
|
796
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
797
|
+
var message, addEntry;
|
|
798
|
+
return __generator(this, function (_a) {
|
|
799
|
+
switch (_a.label) {
|
|
800
|
+
case 0:
|
|
801
|
+
if (firstTime && required) {
|
|
802
|
+
return [2 /*return*/, true];
|
|
803
|
+
}
|
|
804
|
+
message = firstTime ? "Do you want to add" : "Do you want to add more";
|
|
805
|
+
return [4 /*yield*/, inquirer_1.default.prompt([
|
|
806
|
+
{
|
|
807
|
+
type: 'confirm',
|
|
808
|
+
name: 'addEntry',
|
|
809
|
+
message: this.getPathString(propPath, message, firstTime ? description : undefined),
|
|
810
|
+
default: false,
|
|
811
|
+
},
|
|
812
|
+
])];
|
|
813
|
+
case 1:
|
|
814
|
+
addEntry = (_a.sent()).addEntry;
|
|
815
|
+
return [2 /*return*/, addEntry];
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
});
|
|
819
|
+
};
|
|
820
|
+
InquirerHelper.prototype.getType = function (propPath, prop, obj, required) {
|
|
821
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
822
|
+
var result, path, _a, firstTime, current, newEntry, _b;
|
|
823
|
+
return __generator(this, function (_c) {
|
|
824
|
+
switch (_c.label) {
|
|
825
|
+
case 0:
|
|
826
|
+
path = propPath.join('.');
|
|
827
|
+
_a = prop === null || prop === void 0 ? void 0 : prop.type;
|
|
828
|
+
switch (_a) {
|
|
829
|
+
case 'array': return [3 /*break*/, 1];
|
|
830
|
+
case 'object': return [3 /*break*/, 6];
|
|
831
|
+
case 'rawObject': return [3 /*break*/, 8];
|
|
832
|
+
case 'string': return [3 /*break*/, 10];
|
|
833
|
+
case 'boolean': return [3 /*break*/, 10];
|
|
834
|
+
case 'integer': return [3 /*break*/, 10];
|
|
835
|
+
}
|
|
836
|
+
return [3 /*break*/, 10];
|
|
837
|
+
case 1:
|
|
838
|
+
firstTime = true;
|
|
839
|
+
_c.label = 2;
|
|
840
|
+
case 2: return [4 /*yield*/, this.askArrayEntry(propPath, firstTime, required, prop === null || prop === void 0 ? void 0 : prop.description)];
|
|
841
|
+
case 3:
|
|
842
|
+
if (!_c.sent()) return [3 /*break*/, 5];
|
|
843
|
+
current = _.get(obj, path);
|
|
844
|
+
_.unset(obj, path);
|
|
845
|
+
return [4 /*yield*/, this.getType(propPath, prop.items, obj)];
|
|
846
|
+
case 4:
|
|
847
|
+
_c.sent();
|
|
848
|
+
newEntry = _.get(obj, path);
|
|
849
|
+
if (!_.isArray(current)) {
|
|
850
|
+
_.set(obj, path, [newEntry]);
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
current.push(newEntry);
|
|
854
|
+
_.set(obj, path, current);
|
|
855
|
+
}
|
|
856
|
+
firstTime = false;
|
|
857
|
+
return [3 /*break*/, 2];
|
|
858
|
+
case 5:
|
|
859
|
+
// @ts-ignore
|
|
860
|
+
return [2 /*return*/, result || []];
|
|
861
|
+
case 6: return [4 /*yield*/, this.getInnerType(prop, propPath, obj, required)];
|
|
862
|
+
case 7:
|
|
863
|
+
result = _c.sent();
|
|
864
|
+
return [2 /*return*/, result];
|
|
865
|
+
case 8:
|
|
866
|
+
_b = utils_1.isValidJSON;
|
|
867
|
+
return [4 /*yield*/, this.ask(propPath, prop, required)];
|
|
868
|
+
case 9:
|
|
869
|
+
result = _b.apply(void 0, [_c.sent()]) || undefined;
|
|
870
|
+
return [3 /*break*/, 12];
|
|
871
|
+
case 10: return [4 /*yield*/, this.ask(propPath, prop, required, obj)];
|
|
872
|
+
case 11:
|
|
873
|
+
result = _c.sent();
|
|
874
|
+
return [3 /*break*/, 12];
|
|
875
|
+
case 12:
|
|
876
|
+
if (!_.isUndefined(result)) {
|
|
877
|
+
_.set(obj, path, result);
|
|
878
|
+
}
|
|
879
|
+
return [2 /*return*/, result];
|
|
880
|
+
}
|
|
881
|
+
});
|
|
882
|
+
});
|
|
883
|
+
};
|
|
884
|
+
InquirerHelper.prototype.ask = function (propPath, prop, required, currentObj) {
|
|
885
|
+
var _a;
|
|
886
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
887
|
+
var parentPropertyPath, _b, _c, defaultValue, _d, choices, pagination, type, defaultStr, requiredAdjustedChoices, actuallyNumber, questionConfig, result;
|
|
888
|
+
return __generator(this, function (_e) {
|
|
889
|
+
switch (_e.label) {
|
|
890
|
+
case 0:
|
|
891
|
+
parentPropertyPath = propPath[propPath.length - 1];
|
|
892
|
+
return [4 /*yield*/, (0, api_helpers_1.fetchResourceList)(parentPropertyPath, this.apiClient, this.tmpCmdPath, currentObj, this.pathVars, propPath)];
|
|
893
|
+
case 1:
|
|
894
|
+
_b = _e.sent(), _c = _b.defaultValue, defaultValue = _c === void 0 ? (_a = prop === null || prop === void 0 ? void 0 : prop.example) !== null && _a !== void 0 ? _a : prop === null || prop === void 0 ? void 0 : prop.default : _c, _d = _b.choices, choices = _d === void 0 ? prop === null || prop === void 0 ? void 0 : prop.enum : _d, pagination = _b.pagination;
|
|
895
|
+
type = 'input';
|
|
896
|
+
if (!_.isUndefined(choices) && choices.length > 0) {
|
|
897
|
+
if (pagination !== undefined && pagination.nextPageCursor !== undefined) {
|
|
898
|
+
type = 'pagination-prompt';
|
|
899
|
+
}
|
|
900
|
+
else if (choices.length > 4 && typeof choices[0] === 'string') {
|
|
901
|
+
type = 'search-list';
|
|
902
|
+
}
|
|
903
|
+
else {
|
|
904
|
+
type = 'list';
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'boolean') {
|
|
908
|
+
type = 'confirm';
|
|
909
|
+
}
|
|
910
|
+
else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'integer') {
|
|
911
|
+
type = 'input'; // There is a bug with numbers which causes the input to be not cleared correctly on invalid input (https://github.com/SBoudrias/Inquirer.js/issues/866#issuecomment-626265477)
|
|
912
|
+
}
|
|
913
|
+
else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'rawObject') {
|
|
914
|
+
type = 'editor';
|
|
915
|
+
}
|
|
916
|
+
defaultStr =
|
|
917
|
+
// eslint-disable-next-line no-nested-ternary
|
|
918
|
+
required !== false
|
|
919
|
+
? !_.isObject(defaultValue)
|
|
920
|
+
? defaultValue
|
|
921
|
+
: JSON.stringify(defaultValue)
|
|
922
|
+
: _.isBoolean(defaultValue)
|
|
923
|
+
? defaultValue
|
|
924
|
+
: "don't change";
|
|
925
|
+
if (choices)
|
|
926
|
+
defaultStr = defaultStr.toString();
|
|
927
|
+
if (_.has(this.resultCache, propPath.join('.'))) {
|
|
928
|
+
defaultStr = this.resultCache[propPath.join('.')];
|
|
929
|
+
}
|
|
930
|
+
requiredAdjustedChoices = choices && required === false ? __spreadArray(__spreadArray([], choices, true), ["don't change"], false) : choices;
|
|
931
|
+
actuallyNumber = (prop === null || prop === void 0 ? void 0 : prop.type) === 'integer';
|
|
932
|
+
questionConfig = __assign({ type: type, name: 'id', message: this.getQuestionString(propPath, prop), choices: requiredAdjustedChoices, default: defaultStr, filter: this.filter(type, required), validate: this.validate(prop, required, actuallyNumber) }, pagination);
|
|
933
|
+
return [4 /*yield*/, inquirer_1.default.prompt([questionConfig])];
|
|
934
|
+
case 2:
|
|
935
|
+
result = (_e.sent()).id;
|
|
936
|
+
if (result === "don't change" || result === '')
|
|
937
|
+
return [2 /*return*/, undefined];
|
|
938
|
+
if (actuallyNumber) {
|
|
939
|
+
return [2 /*return*/, parseInt(result, 10)];
|
|
940
|
+
}
|
|
941
|
+
return [2 /*return*/, result];
|
|
942
|
+
}
|
|
943
|
+
});
|
|
944
|
+
});
|
|
945
|
+
};
|
|
946
|
+
InquirerHelper.prototype.getQuestionString = function (propPath, prop) {
|
|
947
|
+
var question = (prop === null || prop === void 0 ? void 0 : prop.type) !== 'boolean' ? "What do you want to use as" : 'Should it be';
|
|
948
|
+
return this.getPathString(propPath, question, prop === null || prop === void 0 ? void 0 : prop.description);
|
|
949
|
+
};
|
|
950
|
+
InquirerHelper.prototype.askForProject = function () {
|
|
951
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
952
|
+
var apiCall;
|
|
953
|
+
var _this = this;
|
|
954
|
+
return __generator(this, function (_a) {
|
|
955
|
+
switch (_a.label) {
|
|
956
|
+
case 0:
|
|
957
|
+
apiCall = function (currentCursor) { return __awaiter(_this, void 0, void 0, function () {
|
|
958
|
+
var projects, elements;
|
|
959
|
+
var _a;
|
|
960
|
+
return __generator(this, function (_b) {
|
|
961
|
+
switch (_b.label) {
|
|
962
|
+
case 0: return [4 /*yield*/, this.apiClient.list.projects({
|
|
963
|
+
options: { per_page: this.defaultPaginationPageSize, cursor: currentCursor },
|
|
964
|
+
})];
|
|
965
|
+
case 1:
|
|
966
|
+
projects = _b.sent();
|
|
967
|
+
elements = projects.data.projects.map(function (prj) { return prj.id; });
|
|
968
|
+
return [2 /*return*/, { elements: elements, nextCursor: (_a = projects.pagination) === null || _a === void 0 ? void 0 : _a.cursor }];
|
|
969
|
+
}
|
|
970
|
+
});
|
|
971
|
+
}); };
|
|
972
|
+
return [4 /*yield*/, this.askForResourcePaginated('project', apiCall)];
|
|
973
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
974
|
+
}
|
|
975
|
+
});
|
|
976
|
+
});
|
|
977
|
+
};
|
|
978
|
+
InquirerHelper.prototype.askForProjectScopedResource = function (resourceName, apiCall, project, subScope) {
|
|
979
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
980
|
+
var projectName, resourceNames;
|
|
981
|
+
return __generator(this, function (_a) {
|
|
982
|
+
switch (_a.label) {
|
|
983
|
+
case 0:
|
|
984
|
+
projectName = project || this.apiClient.contextProvider.getCurrentProjectName();
|
|
985
|
+
if (_.isUndefined(projectName)) {
|
|
986
|
+
throw new Error('Default project in context not set and no argument provided.');
|
|
987
|
+
}
|
|
988
|
+
return [4 /*yield*/, apiCall(projectName)];
|
|
989
|
+
case 1:
|
|
990
|
+
resourceNames = _a.sent();
|
|
991
|
+
return [4 /*yield*/, this.askForResource(resourceName, resourceNames, "".concat(subScope ? "".concat(subScope, " in ") : '', "project: '").concat(projectName, "'"))];
|
|
992
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
993
|
+
}
|
|
994
|
+
});
|
|
995
|
+
});
|
|
996
|
+
};
|
|
997
|
+
InquirerHelper.prototype.askForProjectScopedResourcePaginated = function (resourceName, apiCall, project, subScope) {
|
|
998
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
999
|
+
var projectName, resourceFetcher;
|
|
1000
|
+
return __generator(this, function (_a) {
|
|
1001
|
+
switch (_a.label) {
|
|
1002
|
+
case 0:
|
|
1003
|
+
projectName = project || this.apiClient.contextProvider.getCurrentProjectName();
|
|
1004
|
+
if (_.isUndefined(projectName)) {
|
|
1005
|
+
throw new Error('Default project in context not set and no argument provided.');
|
|
1006
|
+
}
|
|
1007
|
+
return [4 /*yield*/, apiCall(projectName)];
|
|
1008
|
+
case 1:
|
|
1009
|
+
resourceFetcher = _a.sent();
|
|
1010
|
+
return [4 /*yield*/, this.askForResourcePaginated(resourceName, resourceFetcher, "".concat(subScope ? "".concat(subScope, " in ") : '', "project: '").concat(projectName, "'"))];
|
|
1011
|
+
case 2: return [2 /*return*/, _a.sent()];
|
|
1012
|
+
}
|
|
1013
|
+
});
|
|
1014
|
+
});
|
|
1015
|
+
};
|
|
1016
|
+
InquirerHelper.prototype.askForDomain = function () {
|
|
1017
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1018
|
+
var listDomainsResponse, domains;
|
|
1019
|
+
return __generator(this, function (_a) {
|
|
1020
|
+
switch (_a.label) {
|
|
1021
|
+
case 0: return [4 /*yield*/, this.apiClient.list.domains({})];
|
|
1022
|
+
case 1:
|
|
1023
|
+
listDomainsResponse = _a.sent();
|
|
1024
|
+
domains = listDomainsResponse.data.domains.map(function (d) { return d.name; });
|
|
1025
|
+
return [2 /*return*/, this.askForResource('domain', domains)];
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
});
|
|
1029
|
+
};
|
|
1030
|
+
InquirerHelper.prototype.askForCredentials = function () {
|
|
1031
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1032
|
+
var listCredentialsResponse, credentials;
|
|
1033
|
+
return __generator(this, function (_a) {
|
|
1034
|
+
switch (_a.label) {
|
|
1035
|
+
case 0: return [4 /*yield*/, this.apiClient.list.registryCredentials({})];
|
|
1036
|
+
case 1:
|
|
1037
|
+
listCredentialsResponse = _a.sent();
|
|
1038
|
+
credentials = listCredentialsResponse.data.credentials.map(function (d) { return d.id; });
|
|
1039
|
+
return [2 /*return*/, this.askForResource('credentials', credentials)];
|
|
1040
|
+
}
|
|
1041
|
+
});
|
|
1042
|
+
});
|
|
1043
|
+
};
|
|
1044
|
+
InquirerHelper.prototype.setPathVars = function (opt) {
|
|
1045
|
+
this.pathVars = opt;
|
|
1046
|
+
};
|
|
1047
|
+
return InquirerHelper;
|
|
1048
|
+
}());
|
|
1049
|
+
exports.InquirerHelper = InquirerHelper;
|