@northflank/cli 0.7.8 → 0.8.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1,912 @@
1
- 'use strict';var a6p=['deleteWarningPrompt','retry','value','851049KvQcRn','stringify','__importDefault','fileName','Yes,\x20send','example','find','askGeneric','sent','toString','SAVE','contextProvider','ops','__esModule','pathVars','askForSecret','\x20type?','toUpperCase','prototype','boolean','domains','Choose\x20the\x20project\x20to\x20use:','isFinite','Choose\x20the\x20','startedAt','writeFileSync','createdAt','EDIT','getQuestionString','__spreadArray','description','addEntry','secret','askForDomain','blue','includes','green','yml','projects','for\x20this\x20','success','addon:\x20\x27','minimum','job','askArrayEntry','choices','jobs','slice','number','tokenPrompt','askForResource','length','greenBright','password','./api-helpers','./utils','must\x20be\x20a\x20number,\x20is\x20','isValidJSON','41179PVSCcL','defineProperty','blueBright','__generator','trys','\x20Example:\x20','maxLength','backups','No\x20','__importStar','message','556658JtcEFn','editor','domain','js-yaml','InquirerHelper','No\x20builds\x20found','minLength','throw','writable','getCurrentProjectName','registryCredentials','pattern','\x20to\x20use:','apply','No,\x20but\x20save\x20as\x20file','Something\x20unexpected\x20happened.','split','call',',\x20supported\x20types:\x20[json|yaml|yml]','editedResult','Please\x20confirm\x20following\x20configuration:\x0a','9oZgGUm','\x20characters,\x20is\x20','properties','ABORT','askForProjectScopedResource','confirmationPrompt','getPathString','test','safeLoad','No,\x20repeat','rawObject','REPEAT','Writing\x20configuration\x20failed:\x20','must\x20be\x20a\x20valid\x20non-empty\x20json\x20string','oneOf','\x20(full\x20domain:\x20','must\x20be\x20shorter\x20than\x20or\x20equal\x20to\x20','concat','What\x20do\x20you\x20want\x20to\x20use\x20as','choice','bold','YES','volumes','isObject','Context\x20name\x20already\x20exists.','1ilkQtr','\x20(completedAt:\x20','default','No,\x20abort','WARNING:\x20You\x20are\x20about\x20to\x20delete\x20','1GVTcrf','runs','fullName','2669yWOWzg','bgGrey','filter','askForBuild','resultCache','Enter\x20the\x20','subdomain','map','label','has','input','retrievePayloadViaInteractiveCli','askForCredentials','maximum','string','loginPrompt','push','job\x20runs','askForAddon','integer','askForVolume','propToType','Choose\x20the\x20login\x20token:','assign','pop','askForSubdomain','isNaN','must\x20be\x20longer\x20than\x20or\x20equal\x20to\x20','askForJob','values','isBoolean','__awaiter','join','warning','editPayload','isUndefined','token','getType','items','object','completedAt','next','575699mGSHSL','1196505KcJKNg','isEmpty','get','yaml','secrets','1dJqvPm','job:\x20\x27','function','list','\x20(startedAt:\x20','Do\x20you\x20want\x20to\x20add','create','addon','configurable','confirm','whiteBright','service','1128081nPJrbn','safeDump','type','override','project:\x20\x27','Default\x20project\x20in\x20context\x20not\x20set\x20and\x20no\x20argument\x20provided.','getOwnPropertyDescriptor','data','found','trim','builds','tmpCmdPath','Aborted.','name','apiClient','return','set','fetchResourceList','max','validate','json','Choose\x20the\x20name\x20of\x20the\x20new\x20local\x20context:','then','reset','5yMoSDa','askForService','getInnerType','grey','ask','Should\x20it\x20be','subdomains','lodash','a\x20Northflank\x20resource','cmdPath','hasOwnProperty','services','confirmation','credentials','saveFile','\x20characters','don\x27t\x20change','must\x20be\x20bigger\x20than\x20or\x20equal\x20to\x20','prompt'];var a6h=a6Y;(function(p,Y){var i=a6Y;while(!![]){try{var f=parseInt(i(0x156))+-parseInt(i(0x167))+-parseInt(i(0x10a))*-parseInt(i(0x12b))+parseInt(i(0x123))*-parseInt(i(0xf5))+parseInt(i(0x128))*parseInt(i(0x195))+parseInt(i(0x17f))*-parseInt(i(0xea))+parseInt(i(0x155))*parseInt(i(0x15b));if(f===Y)break;else p['push'](p['shift']());}catch(Z){p['push'](p['shift']());}}}(a6p,0xb8ba0));function a6Y(p,Y){p=p-0xd9;var f=a6p[p];return f;}var __assign=this&&this['__assign']||function(){var T=a6Y;return __assign=Object[T(0x142)]||function(Y){var V=T;for(var f,Z=0x1,o=arguments['length'];Z<o;Z++){f=arguments[Z];for(var L in f)if(Object[V(0x1a7)][V(0x189)]['call'](f,L))Y[L]=f[L];}return Y;},__assign[T(0x102)](this,arguments);},__createBinding=this&&this['__createBinding']||(Object[a6h(0x161)]?function(p,Y,f,Z){var K=a6h;if(Z===undefined)Z=f;var t=Object[K(0x16d)](Y,f);(!t||(K(0x158)in t?!Y[K(0x1a2)]:t[K(0xfd)]||t[K(0x163)]))&&(t={'enumerable':!![],'get':function(){return Y[f];}}),Object[K(0xeb)](p,Z,t);}:function(p,Y,f,Z){if(Z===undefined)Z=f;p[Z]=Y[f];}),__setModuleDefault=this&&this['__setModuleDefault']||(Object[a6h(0x161)]?function(p,Y){Object['defineProperty'](p,'default',{'enumerable':!![],'value':Y});}:function(p,Y){p['default']=Y;}),__importStar=this&&this[a6h(0xf3)]||function(p){var j=a6h;if(p&&p[j(0x1a2)])return p;var Y={};if(p!=null){for(var f in p)if(f!=='default'&&Object[j(0x1a7)]['hasOwnProperty'][j(0x106)](p,f))__createBinding(Y,p,f);}return __setModuleDefault(Y,p),Y;},__awaiter=this&&this[a6h(0x14a)]||function(p,Y,f,Z){function o(t){return t instanceof f?t:new f(function(L){L(t);});}return new(f||(f=Promise))(function(t,L){var O=a6Y;function A(a){try{R(Z['next'](a));}catch(n){L(n);}}function g(a){var E=a6Y;try{R(Z[E(0xfc)](a));}catch(n){L(n);}}function R(a){var I=a6Y;a['done']?t(a[I(0x194)]):o(a['value'])[I(0x17d)](A,g);}R((Z=Z[O(0x102)](p,Y||[]))[O(0x154)]());});},__generator=this&&this[a6h(0xed)]||function(p,Y){var v=a6h,Z={'label':0x0,'sent':function(){if(A[0x0]&0x1)throw A[0x1];return A[0x1];},'trys':[],'ops':[]},o,L,A,R;return R={'next':a(0x0),'throw':a(0x1),'return':a(0x2)},typeof Symbol===v(0x15d)&&(R[Symbol['iterator']]=function(){return this;}),R;function a(U){return function(u){return n([U,u]);};}function n(U){var P=v;if(o)throw new TypeError('Generator\x20is\x20already\x20executing.');while(Z)try{if(o=0x1,L&&(A=U[0x0]&0x2?L[P(0x176)]:U[0x0]?L[P(0xfc)]||((A=L[P(0x176)])&&A[P(0x106)](L),0x0):L[P(0x154)])&&!(A=A['call'](L,U[0x1]))['done'])return A;if(L=0x0,A)U=[U[0x0]&0x2,A[P(0x194)]];switch(U[0x0]){case 0x0:case 0x1:A=U;break;case 0x4:Z[P(0x133)]++;return{'value':U[0x1],'done':![]};case 0x5:Z[P(0x133)]++,L=U[0x1],U=[0x0];continue;case 0x7:U=Z[P(0x1a1)][P(0x143)](),Z[P(0xee)][P(0x143)]();continue;default:if(!(A=Z[P(0xee)],A=A[P(0xe3)]>0x0&&A[A[P(0xe3)]-0x1])&&(U[0x0]===0x6||U[0x0]===0x2)){Z=0x0;continue;}if(U[0x0]===0x3&&(!A||U[0x1]>A[0x0]&&U[0x1]<A[0x3])){Z[P(0x133)]=U[0x1];break;}if(U[0x0]===0x6&&Z[P(0x133)]<A[0x1]){Z[P(0x133)]=A[0x1],A=U;break;}if(A&&Z[P(0x133)]<A[0x2]){Z[P(0x133)]=A[0x2],Z['ops']['push'](U);break;}if(A[0x2])Z[P(0x1a1)]['pop']();Z[P(0xee)][P(0x143)]();continue;}U=Y[P(0x106)](p,Z);}catch(u){U=[0x6,u],L=0x0;}finally{o=A=0x0;}if(U[0x0]&0x5)throw U[0x1];return{'value':U[0x0]?U[0x1]:void 0x0,'done':!![]};}},__spreadArray=this&&this[a6h(0x1b2)]||function(p,Y,f){var H=a6h;if(f||arguments[H(0xe3)]===0x2)for(var Z=0x0,o=Y[H(0xe3)],t;Z<o;Z++){if(t||!(Z in Y)){if(!t)t=Array[H(0x1a7)][H(0xdf)][H(0x106)](Y,0x0,Z);t[Z]=Y[Z];}}return p[H(0x11b)](t||Array[H(0x1a7)][H(0xdf)][H(0x106)](Y));},__importDefault=this&&this[a6h(0x197)]||function(p){var e=a6h;return p&&p[e(0x1a2)]?p:{'default':p};};Object['defineProperty'](exports,a6h(0x1a2),{'value':!![]}),exports['InquirerHelper']=void 0x0;var _=__importStar(require(a6h(0x186))),chalk_1=__importDefault(require('chalk')),fs=__importStar(require('fs')),utils_1=require(a6h(0xe7)),api_helpers_1=require(a6h(0xe6)),inquirer=require('inquirer'),yaml=require(a6h(0xf8)),ConfirmChoices;(function(p){var m=a6h;p['YES']=m(0x199),p[m(0x115)]=m(0x113),p[m(0x1b0)]='No,\x20edit',p['SAVE']=m(0x103),p[m(0x10d)]=m(0x126);}(ConfirmChoices||(ConfirmChoices={})));var InquirerHelper=function(){var pw=a6h;function p(Y){var b=a6Y,f=this;this[b(0x175)]=Y,this[b(0x14d)]=function(Z){return __awaiter(f,void 0x0,void 0x0,function(){var o;return __generator(this,function(t){var N=a6Y;switch(t[N(0x133)]){case 0x0:return[0x4,inquirer[N(0x191)]([{'type':N(0xf6),'name':N(0x108),'message':'Go\x20to\x20editor','default':yaml[N(0x168)](Z)}])];case 0x1:o=t['sent']()['editedResult'];return[0x2,yaml[N(0x112)](o)];}});});},this[b(0x18d)]=function(Z){return __awaiter(f,void 0x0,void 0x0,function(){function o(){return __awaiter(this,void 0x0,void 0x0,function(){return __generator(this,function(g){var c=a6Y;return[0x2,inquirer[c(0x191)]([{'type':c(0x135),'name':'fileName','message':'Provide\x20a\x20file\x20path\x20to\x20write\x20the\x20configuration\x20to\x20(<name>.[json|yaml|yml])','validate':function(R){var G=c;return new RegExp('.*\x5c.(json|yaml|yml)$')[G(0x111)](R)?!![]:t(R);}}])];});});}var t,L,A;return __generator(this,function(g){var s=a6Y;switch(g[s(0x133)]){case 0x0:t=function(R){var k=s;return'Unexpected\x20file\x20type:\x20'[k(0x11b)](R,k(0x107));};return[0x4,o()];case 0x1:L=g[s(0x19d)]()[s(0x198)],A=L[s(0x19e)]()[s(0x105)]('.')[s(0x143)]();try{switch(A){case s(0x17b):(0x0,utils_1[s(0x1bd)])('Configuration\x20file\x20written\x20to\x20'['concat'](L));return[0x2,fs[s(0x1ae)](L,JSON[s(0x196)](Z,null,'\x20\x20'))];case s(0x159):case s(0x1ba):(0x0,utils_1[s(0x1bd)])('Configuration\x20file\x20written\x20to\x20'[s(0x11b)](L));return[0x2,fs[s(0x1ae)](L,yaml[s(0x168)](Z))];default:(0x0,utils_1[s(0x14c)])(t(A));}}catch(R){(0x0,utils_1[s(0x14c)])(s(0x116)[s(0x11b)](R[s(0xf4)]));}return[0x2,undefined];}});});},this[b(0x12d)]=function(Z,o){return function(t){var S=a6Y,L=typeof t===S(0x139)?t[S(0x170)]():t;if(Z===S(0xe0)&&Number[S(0x145)](L))return'';return o===![]&&L===S(0x18f)?'':L;};},this[b(0x17a)]=function(Z,o){return function(t){var M=a6Y,L=[];if(t===''||t==='don\x27t\x20change'){if(o!==![])L['push']('this\x20option\x20is\x20required,\x20please\x20answer');else return!![];}Z[M(0x169)]==='string'&&!_[M(0x14e)](Z['pattern'])&&L[M(0x13b)](new RegExp(Z[M(0x100)])[M(0x111)](t)?!![]:'doesn\x27t\x20match\x20pattern\x20\x27'[M(0x11b)](Z[M(0x100)],'\x27'));Z[M(0x169)]===M(0x139)&&!_[M(0x14e)](Z[M(0xfb)])&&L[M(0x13b)](t[M(0xe3)]>=Z['minLength']?!![]:M(0x146)[M(0x11b)](Z[M(0xfb)],M(0x10b))[M(0x11b)](t['length'],'\x20characters'));Z[M(0x169)]===M(0x139)&&!_['isUndefined'](Z[M(0xf0)])&&L[M(0x13b)](t[M(0xe3)]<=Z[M(0xf0)]?!![]:M(0x11a)[M(0x11b)](Z['maxLength'],M(0x10b))[M(0x11b)](t[M(0xe3)],M(0x18e)));Z['type']==='integer'&&!_[M(0x1ab)](Number(t))&&L[M(0x13b)](M(0xe8)[M(0x11b)](t));Z[M(0x169)]===M(0x13e)&&!_[M(0x14e)](Z['minimum'])&&L[M(0x13b)](t>=Z[M(0xda)]?!![]:M(0x190)['concat'](Z[M(0xda)]));Z[M(0x169)]===M(0x13e)&&!_[M(0x14e)](Z['maximum'])&&L[M(0x13b)](t<=Z['maximum']?!![]:'must\x20be\x20smaller\x20than\x20or\x20equal\x20to\x20'['concat'](Z[M(0x138)]));if(Z[M(0x169)]===M(0x114)){var A=(0x0,utils_1['isValidJSON'])(t);L[M(0x13b)](A===![]||_[M(0x157)](A)?M(0x117):!![]);}var g=L[M(0x12d)](function(a){return a!==!![];}),R=(Z===null||Z===void 0x0?void 0x0:Z['example'])?'\x0a'[M(0x11b)](chalk_1[M(0x125)]['red']('>>'),M(0xef))[M(0x11b)](chalk_1[M(0x125)][M(0x165)](JSON['stringify'](Z[M(0x19a)]))):'';return g[M(0xe3)]>0x0?g['join'](chalk_1['default']['underline']('\x20and\x20it\x20'))+R:!![];};},this[b(0x110)]=function(Z,o,t){var W=b,L=Z[Z['length']-0x1];function A(){var r=a6Y;return Z[r(0xdf)](0x0,-0x1)['map'](function(a){var y=r;return a['charAt'](0x0)[y(0x1a6)]()+a['slice'](0x1);})[r(0x14b)]('>');}var g=Z[W(0xe3)]>0x1?''[W(0x11b)](chalk_1[W(0x125)][W(0x12c)][W(0x165)](A()),':\x20'):'',R=t?'\x20('[W(0x11b)](chalk_1[W(0x125)][W(0x1b7)](t),')'):'';return chalk_1[W(0x125)][W(0x17e)](''[W(0x11b)](g)[W(0x11b)](o,'\x20')[W(0x11b)](chalk_1['default'][W(0x11e)][W(0xe4)](L))[W(0x11b)](R,'?'));},this['askForResource']=function(Z,o,t){return __awaiter(f,void 0x0,void 0x0,function(){var L,A;return __generator(this,function(g){var F=a6Y;switch(g[F(0x133)]){case 0x0:if(o[F(0xe3)]<0x1){L=t?F(0x1bc)['concat'](t):F(0x16f);throw new Error(F(0xf2)['concat'](Z,'\x20')[F(0x11b)](L,'.'));}A=F(0x1ac)[F(0x11b)](Z,F(0x101));return[0x4,inquirer[F(0x191)]([{'type':F(0x15e),'name':F(0x174),'message':A,'choices':o}])];case 0x1:return[0x2,g[F(0x19d)]()['name']];}});});},this[b(0x19c)]=function(Z,o){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var t,L,A;return __generator(this,function(g){var D=a6Y;switch(g[D(0x133)]){case 0x0:t=''[D(0x11b)](o?'('['concat'](chalk_1[D(0x125)][D(0x1b7)](o),')\x20'):''),L=D(0x130)[D(0x11b)](chalk_1[D(0x125)][D(0x1b9)](Z),'\x20')[D(0x11b)](t,'to\x20use:'),A=this[D(0x17a)]({'type':D(0x139),'required':!![]});return[0x4,inquirer[D(0x191)]([{'type':D(0x135),'name':D(0x174),'message':L,'validate':A}])];case 0x1:return[0x2,g['sent']()[D(0x174)]];}});});};},this[b(0x180)]=function(Z){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var o,t=this;return __generator(this,function(L){var l=a6Y;return o=function(A){return __awaiter(t,void 0x0,void 0x0,function(){return __generator(this,function(g){var z=a6Y;switch(g['label']){case 0x0:return[0x4,this[z(0x175)]['list']['services']({'parameters':{'projectId':A},'options':{'per_page':0x64}})];case 0x1:return[0x2,g[z(0x19d)]()['data'][z(0x18a)][z(0x132)](function(R){return R['id'];})];}});});},[0x2,this[l(0x10e)]('service',o,Z)];});});};},this[b(0x147)]=function(Z){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var o,t=this;return __generator(this,function(L){var J=a6Y;return o=function(A){return __awaiter(t,void 0x0,void 0x0,function(){return __generator(this,function(g){var q=a6Y;switch(g[q(0x133)]){case 0x0:return[0x4,this[q(0x175)]['list']['jobs']({'parameters':{'projectId':A},'options':{'per_page':0x64}})];case 0x1:return[0x2,g[q(0x19d)]()[q(0x16e)][q(0xde)]['map'](function(R){return R['id'];})];}});});},[0x2,this[J(0x10e)](J(0xdb),o,Z)];});});};},this['askForJobRun']=function(Z,o){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var t,L=this;return __generator(this,function(A){var X=a6Y;return t=function(g){return __awaiter(L,void 0x0,void 0x0,function(){return __generator(this,function(R){var d=a6Y;switch(R['label']){case 0x0:return[0x4,this['apiClient'][d(0x158)][d(0xdb)][d(0x129)]({'parameters':{'projectId':g,'jobId':Z},'options':{'per_page':0x64}})];case 0x1:return[0x2,R['sent']()[d(0x16e)][d(0x129)]['map'](function(a){var x=d;return''[x(0x11b)](a['id'],x(0x15f))[x(0x11b)](a[x(0x1ad)],')');})];}});});},[0x2,this[X(0x10e)](X(0x13c),t,o,X(0x15c)['concat'](Z,'\x27'))['then'](function(g){var p0=X;return g[p0(0x105)]('\x20')[0x0];})];});});};},this[b(0x12e)]=function(Z,o,t){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var L,L,A=this;return __generator(this,function(g){var p3=a6Y;if(t!==undefined)return L=function(R){return __awaiter(A,void 0x0,void 0x0,function(){return __generator(this,function(a){var p1=a6Y;switch(a[p1(0x133)]){case 0x0:return[0x4,this[p1(0x175)][p1(0x158)][p1(0xdb)]['builds']({'parameters':{'projectId':R,'jobId':t},'options':{'per_page':0x64}})];case 0x1:return[0x2,a[p1(0x19d)]()[p1(0x16e)][p1(0x171)]['map'](function(n){var p2=p1;return''[p2(0x11b)](n['id'],p2(0x15f))[p2(0x11b)](n[p2(0x1af)],')');})];}});});},[0x2,this[p3(0x10e)]('job\x20builds',L,Z,p3(0x15c)['concat'](t,'\x27'))[p3(0x17d)](function(R){var p4=p3;return R[p4(0x105)]('\x20')[0x0];})];if(o!==undefined)return L=function(R){return __awaiter(A,void 0x0,void 0x0,function(){return __generator(this,function(a){var p5=a6Y;switch(a['label']){case 0x0:return[0x4,this[p5(0x175)][p5(0x158)][p5(0x166)]['builds']({'parameters':{'projectId':R,'serviceId':o},'options':{'per_page':0x64}})];case 0x1:return[0x2,a[p5(0x19d)]()['data'][p5(0x171)][p5(0x132)](function(n){var p6=p5;return''[p6(0x11b)](n['id'],p6(0x15f))[p6(0x11b)](n[p6(0x1af)],')');})];}});});},[0x2,this[p3(0x10e)]('job\x20build',L,Z,'service:\x20\x27'[p3(0x11b)](t,'\x27'))[p3(0x17d)](function(R){var p7=p3;return R[p7(0x105)]('\x20')[0x0];})];throw new Error(p3(0xfa));});});};},this[b(0x13d)]=function(Z){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var o,t=this;return __generator(this,function(L){var p9=a6Y;return o=function(A){return __awaiter(t,void 0x0,void 0x0,function(){return __generator(this,function(g){var p8=a6Y;switch(g[p8(0x133)]){case 0x0:return[0x4,this['apiClient']['list']['addons']({'parameters':{'projectId':A},'options':{'per_page':0x64}})];case 0x1:return[0x2,g['sent']()[p8(0x16e)]['addons']['map'](function(R){return R['id'];})];}});});},[0x2,this[p9(0x10e)](p9(0x162),o,Z)];});});};},this['askForAddonBackup']=function(Z,o){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var t,L=this;return __generator(this,function(A){var pf=a6Y;return t=function(g){return __awaiter(L,void 0x0,void 0x0,function(){return __generator(this,function(R){var pp=a6Y;switch(R['label']){case 0x0:return[0x4,this[pp(0x175)][pp(0x158)][pp(0x162)][pp(0xf1)]({'parameters':{'projectId':g,'addonId':o},'options':{'per_page':0x64}})];case 0x1:return[0x2,R[pp(0x19d)]()[pp(0x16e)][pp(0xf1)][pp(0x132)](function(a){var pY=pp;return''['concat'](a['id'],pY(0x124))['concat'](a[pY(0x153)]||'not\x20completed',')');})];}});});},[0x2,this[pf(0x10e)](pf(0xf1),t,Z,pf(0xd9)['concat'](o,'\x27'))[pf(0x17d)](function(g){var pZ=pf;return g[pZ(0x105)]('\x20')[0x0];})];});});};},this[b(0x13f)]=function(Z){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var o,t=this;return __generator(this,function(L){var pt=a6Y;return o=function(A){return __awaiter(t,void 0x0,void 0x0,function(){return __generator(this,function(g){var po=a6Y;switch(g[po(0x133)]){case 0x0:return[0x4,this['apiClient']['list'][po(0x120)]({'parameters':{'projectId':A}})];case 0x1:return[0x2,g[po(0x19d)]()[po(0x16e)][po(0x132)](function(R){return R['id'];})];}});});},[0x2,this[pt(0x10e)]('volume',o,Z)];});});};},this[b(0x1a4)]=function(Z){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var o,t=this;return __generator(this,function(L){var pA=a6Y;return o=function(A){return __awaiter(t,void 0x0,void 0x0,function(){return __generator(this,function(g){var pL=a6Y;switch(g['label']){case 0x0:return[0x4,this['apiClient']['list']['secrets']({'parameters':{'projectId':A},'options':{'per_page':0x64}})];case 0x1:return[0x2,g[pL(0x19d)]()['data'][pL(0x15a)]['map'](function(R){return R['id'];})];}});});},[0x2,this[pA(0x10e)](pA(0x1b5),o,Z)];});});};},this[b(0x144)]=function(Z){return function(){return __awaiter(f,void 0x0,void 0x0,function(){var o,t,L;return __generator(this,function(A){var pg=a6Y;switch(A[pg(0x133)]){case 0x0:return[0x4,this[pg(0x175)][pg(0x158)][pg(0xf7)]({'parameters':{'domain':Z}})];case 0x1:o=A['sent'](),t=o[pg(0x16e)][pg(0x185)]['map'](function(g){var pR=pg;return''[pR(0x11b)](g[pR(0x174)],pR(0x119))['concat'](g[pR(0x12a)],')');}),L='domain\x20('['concat'](Z,')');return[0x2,this[pg(0xe2)](pg(0x131),t,L)['then'](function(g){var pa=pg;return g[pa(0x105)]('\x20')[0x0];})];}});});};},this[b(0x192)]=function(Z){return __awaiter(f,void 0x0,void 0x0,function(){return __generator(this,function(o){var pn=a6Y;switch(o['label']){case 0x0:return[0x4,inquirer[pn(0x191)]([{'type':pn(0x164),'name':pn(0x18b),'message':chalk_1[pn(0x125)]['yellowBright'](pn(0x127)[pn(0x11b)](Z||pn(0x187),'.\x20This\x20is\x20irreversible.\x20Please\x20confirm!')),'default':![]}])];case 0x1:return[0x2,o[pn(0x19d)]()[pn(0x18b)]];}});});},this[b(0x13a)]=function(Z,o){return __awaiter(f,void 0x0,void 0x0,function(){var t,L=this;return __generator(this,function(A){var pU=a6Y;switch(A[pU(0x133)]){case 0x0:if(!_[pU(0x14e)](Z[pU(0x174)]))return[0x3,0x3];if(!(o['length']<=0x0))return[0x3,0x1];_[pU(0x177)](Z,pU(0x174),pU(0x125));return[0x3,0x3];case 0x1:return[0x4,(0x0,utils_1[pU(0x193)])(0xa)(function(){return __awaiter(L,void 0x0,void 0x0,function(){var g,R;return __generator(this,function(a){var pu=a6Y;switch(a[pu(0x133)]){case 0x0:return[0x4,inquirer['prompt']([{'type':'input','name':pu(0x174),'message':pu(0x17c),'default':'main-context'}])];case 0x1:g=a[pu(0x19d)]()['name'];if(!(!Z[pu(0x16a)]&&o[pu(0x19b)](function(n){return n['name']===g;})))return[0x3,0x3];return[0x4,inquirer[pu(0x191)]([{'type':pu(0x164),'name':'c','message':'Context\x20with\x20name\x20\x27'[pu(0x11b)](g,'\x27\x20already\x20exists.\x20Do\x20you\x20want\x20to\x20override\x20this\x20context\x20(y)\x20or\x20enter\x20a\x20new\x20name\x20(N)?'),'default':![]}])];case 0x2:R=a[pu(0x19d)]()['c'];if(R===![])throw new Error(pu(0x122));_[pu(0x177)](Z,pu(0x16a),!![]),a[pu(0x133)]=0x3;case 0x3:_[pu(0x177)](Z,pu(0x174),g);return[0x2];}});});})];case 0x2:A[pU(0x19d)](),A['label']=0x3;case 0x3:if(!_[pU(0x14e)](Z[pU(0x14f)]))return[0x3,0x5];return[0x4,this[pU(0xe1)]()];case 0x4:t=A[pU(0x19d)](),_[pU(0x177)](Z,'token',t),A['label']=0x5;case 0x5:return[0x2,Z];}});});},this[b(0xe1)]=function(){return __awaiter(f,void 0x0,void 0x0,function(){var Z;return __generator(this,function(o){var pQ=a6Y;switch(o['label']){case 0x0:return[0x4,inquirer['prompt']([{'type':pQ(0xe5),'name':pQ(0x14f),'mask':'*','message':pQ(0x141)}])];case 0x1:Z=o[pQ(0x19d)]()['token'];return[0x2,Z];}});});};}return p[pw(0x1a7)]['confirmationPrompt']=function(Y,f){return __awaiter(this,void 0x0,void 0x0,function(){var Z,o,t,L,A,g;return __generator(this,function(R){var pB=a6Y;switch(R[pB(0x133)]){case 0x0:Z=yaml[pB(0x168)](Y),o=_[pB(0x179)](Z[pB(0x105)]('\x0a')[pB(0x132)](function(a){var pC=pB;return a[pC(0xe3)];})),t=chalk_1[pB(0x125)][pB(0x182)](''[pB(0x11b)]('-'['repeat'](o),'\x0a'));return[0x4,inquirer[pB(0x191)]([{'type':pB(0x15e),'name':pB(0x164),'message':''['concat'](chalk_1[pB(0x125)]['bold']['green'](pB(0x109)))['concat'](t)[pB(0x11b)](chalk_1['default'][pB(0xec)](Z))[pB(0x11b)](t),'choices':Object[pB(0x148)](ConfirmChoices)}])];case 0x1:L=R[pB(0x19d)]()[pB(0x164)],A=L;switch(A){case ConfirmChoices[pB(0x11f)]:return[0x3,0x2];case ConfirmChoices['ABORT']:return[0x3,0x3];case ConfirmChoices[pB(0x115)]:return[0x3,0x4];case ConfirmChoices[pB(0x1b0)]:return[0x3,0x5];case ConfirmChoices[pB(0x19f)]:return[0x3,0x7];}return[0x3,0x9];case 0x2:return[0x2,Y];case 0x3:throw new Error(pB(0x173));case 0x4:return[0x2,this[pB(0x136)](f)];case 0x5:g=this[pB(0x10f)];return[0x4,this['editPayload'](Y)];case 0x6:return[0x2,g['apply'](this,[R['sent'](),f])];case 0x7:return[0x4,this[pB(0x18d)](Y)];case 0x8:R[pB(0x19d)]();return[0x2,this[pB(0x10f)](Y,f)];case 0x9:throw new Error(pB(0x104));}});});},p[pw(0x1a7)][pw(0x136)]=function(Y,f){return __awaiter(this,void 0x0,void 0x0,function(){var Z;return __generator(this,function(o){var pi=a6Y;switch(o[pi(0x133)]){case 0x0:if((f===null||f===void 0x0?void 0x0:f['resultCache'])!==undefined)this[pi(0x12f)]=f===null||f===void 0x0?void 0x0:f[pi(0x12f)];this[pi(0x172)]=f===null||f===void 0x0?void 0x0:f[pi(0x188)],Z={};return[0x4,this[pi(0x140)]([],Y['opt']['body'],Z)];case 0x1:o[pi(0x19d)](),this[pi(0x12f)]=Z;return[0x4,this[pi(0x10f)](Z,Y)];case 0x2:return[0x2,o['sent']()];}});});},p[pw(0x1a7)][pw(0x140)]=function(Y,f,Z,o){return __awaiter(this,void 0x0,void 0x0,function(){var t,L,A;return __generator(this,function(g){var pT=a6Y;switch(g[pT(0x133)]){case 0x0:if(!(f[pT(0x118)]&&!_[pT(0x134)](f,pT(0x10c))))return[0x3,0x6];if(!(f[pT(0x118)][pT(0xe3)]>0x1))return[0x3,0x3];return[0x4,inquirer[pT(0x191)]([{'type':pT(0x15e),'name':pT(0x11d),'message':'What\x27s\x20the\x20'['concat'](Y[Y[pT(0xe3)]-0x1]||'',pT(0x1a5)),'choices':f['oneOf']['map'](function(R){var pV=pT;return R[pV(0x1b3)];})}])];case 0x1:L=g[pT(0x19d)]()[pT(0x11d)];return[0x4,this[pT(0x150)](Y,f['oneOf'][pT(0x19b)](function(R){var ph=pT;return R[ph(0x1b3)]===L;}),Z,o)];case 0x2:t=g[pT(0x19d)]();return[0x3,0x5];case 0x3:A=f[pT(0x118)][0x0],_[pT(0x177)](A,'description',f[pT(0x1b3)]);return[0x4,this[pT(0x150)](Y,A,Z,o)];case 0x4:t=g[pT(0x19d)](),g[pT(0x133)]=0x5;case 0x5:t={};return[0x3,0x8];case 0x6:return[0x4,this['getType'](Y,f,Z,o)];case 0x7:t=g[pT(0x19d)](),g['label']=0x8;case 0x8:return[0x2,t];}});});},p[pw(0x1a7)]['getInnerType']=function(Y,f,Z,o){var t;return __awaiter(this,void 0x0,void 0x0,function(){var L,A,g,R,a,n,U;return __generator(this,function(u){var pK=a6Y;switch(u[pK(0x133)]){case 0x0:if(!(o===![]))return[0x3,0x2];return[0x4,inquirer['prompt']([{'type':'confirm','name':pK(0x1b4),'message':this['getPathString'](f,'Do\x20you\x20want\x20to\x20add',Y===null||Y===void 0x0?void 0x0:Y[pK(0x1b3)]),'default':![]}])];case 0x1:L=u[pK(0x19d)]()[pK(0x1b4)];if(!L)return[0x2,Z];u[pK(0x133)]=0x2;case 0x2:A=Object['keys']((t=Y===null||Y===void 0x0?void 0x0:Y['properties'])!==null&&t!==void 0x0?t:[]),g=Y['required']||[];if(!(A[pK(0xe3)]>0x0))return[0x3,0x7];R=0x0,a=A,u[pK(0x133)]=0x3;case 0x3:if(!(R<a[pK(0xe3)]))return[0x3,0x6];n=a[R],U=f[pK(0x11b)](n);if(f[pK(0xe3)]>0x0&&!_[pK(0x134)](Z,f[pK(0x14b)]('.')))_[pK(0x177)](Z,f[pK(0x14b)]('.'),{});return[0x4,this[pK(0x140)](U,Y[pK(0x10c)][n],Z,g[pK(0x1b8)](n))];case 0x4:u[pK(0x19d)](),u[pK(0x133)]=0x5;case 0x5:R++;return[0x3,0x3];case 0x6:return[0x3,0x9];case 0x7:return[0x4,this[pK(0x150)](f,__assign(__assign({},Y),{'type':pK(0x114)}),Z,o)];case 0x8:u[pK(0x19d)](),u['label']=0x9;case 0x9:return[0x2,Z];}});});},p[pw(0x1a7)]['askArrayEntry']=function(Y,f,Z,o){return __awaiter(this,void 0x0,void 0x0,function(){var t,L;return __generator(this,function(A){var pj=a6Y;switch(A[pj(0x133)]){case 0x0:if(f&&Z)return[0x2,!![]];t=f?pj(0x160):'Do\x20you\x20want\x20to\x20add\x20more';return[0x4,inquirer['prompt']([{'type':pj(0x164),'name':pj(0x1b4),'message':this[pj(0x110)](Y,t,f?o:undefined),'default':![]}])];case 0x1:L=A[pj(0x19d)]()[pj(0x1b4)];return[0x2,L];}});});},p[pw(0x1a7)][pw(0x150)]=function(Y,f,Z,o){return __awaiter(this,void 0x0,void 0x0,function(){var t,L,A,g,R,a,n;return __generator(this,function(U){var pE=a6Y;switch(U['label']){case 0x0:L=Y[pE(0x14b)]('.'),A=f===null||f===void 0x0?void 0x0:f['type'];switch(A){case'array':return[0x3,0x1];case pE(0x152):return[0x3,0x6];case'rawObject':return[0x3,0x8];case pE(0x139):return[0x3,0xa];case pE(0x1a8):return[0x3,0xa];case pE(0x13e):return[0x3,0xa];}return[0x3,0xa];case 0x1:g=!![],U['label']=0x2;case 0x2:return[0x4,this[pE(0xdc)](Y,g,o,f===null||f===void 0x0?void 0x0:f[pE(0x1b3)])];case 0x3:if(!U[pE(0x19d)]())return[0x3,0x5];R=_[pE(0x158)](Z,L),_['unset'](Z,L);return[0x4,this['getType'](Y,f[pE(0x151)],Z)];case 0x4:U['sent'](),a=_[pE(0x158)](Z,L);!_['isArray'](R)?_[pE(0x177)](Z,L,[a]):(R[pE(0x13b)](a),_[pE(0x177)](Z,L,R));g=![];return[0x3,0x2];case 0x5:return[0x2,t||[]];case 0x6:return[0x4,this[pE(0x181)](f,Y,Z,o)];case 0x7:t=U[pE(0x19d)]();return[0x2,t];case 0x8:n=utils_1[pE(0xe9)];return[0x4,this[pE(0x183)](Y,f,o)];case 0x9:t=n[pE(0x102)](void 0x0,[U[pE(0x19d)]()])||undefined;return[0x3,0xc];case 0xa:return[0x4,this['ask'](Y,f,o,Z)];case 0xb:t=U[pE(0x19d)]();return[0x3,0xc];case 0xc:!_['isUndefined'](t)&&_[pE(0x177)](Z,L,t);return[0x2,t];}});});},p[pw(0x1a7)]['ask']=function(Y,f,Z,o){var t;return __awaiter(this,void 0x0,void 0x0,function(){var L,A,g,R,a,n,U,u,Q,w,B;return __generator(this,function(C){var pI=a6Y;switch(C[pI(0x133)]){case 0x0:L=Y[Y[pI(0xe3)]-0x1];return[0x4,(0x0,api_helpers_1[pI(0x178)])(L,this['apiClient'],this[pI(0x172)],o,this[pI(0x1a3)],Y)];case 0x1:A=C[pI(0x19d)](),g=A['defaultValue'],R=g===void 0x0?(t=f===null||f===void 0x0?void 0x0:f[pI(0x19a)])!==null&&t!==void 0x0?t:f===null||f===void 0x0?void 0x0:f[pI(0x125)]:g,a=A[pI(0xdd)],n=a===void 0x0?f===null||f===void 0x0?void 0x0:f['enum']:a,U='input';if(!_['isUndefined'](n))U=pI(0x15e);else{if((f===null||f===void 0x0?void 0x0:f[pI(0x169)])===pI(0x1a8))U='confirm';else{if((f===null||f===void 0x0?void 0x0:f['type'])===pI(0x13e))U='number';else(f===null||f===void 0x0?void 0x0:f[pI(0x169)])===pI(0x114)&&(U=pI(0xf6));}}u=Z!==![]?!_[pI(0x121)](R)?R:JSON[pI(0x196)](R):_[pI(0x149)](R)?R:pI(0x18f);if(n)u=u[pI(0x19e)]();_['has'](this['resultCache'],Y[pI(0x14b)]('.'))&&(u=this['resultCache'][Y['join']('.')]);Q=n&&Z===![]?__spreadArray(__spreadArray([],n,!![]),[pI(0x18f)],![]):n,w={'type':U,'name':'id','message':this[pI(0x1b1)](Y,f),'choices':Q,'default':u,'filter':this[pI(0x12d)](U,Z),'validate':this[pI(0x17a)](f,Z)};return[0x4,inquirer[pI(0x191)]([w])];case 0x2:B=C[pI(0x19d)]()['id'];return[0x2,B===pI(0x18f)||B===''?undefined:B];}});});},p[pw(0x1a7)][pw(0x1b1)]=function(Y,f){var pO=pw,Z=(f===null||f===void 0x0?void 0x0:f[pO(0x169)])!==pO(0x1a8)?pO(0x11c):pO(0x184);return this[pO(0x110)](Y,Z,f===null||f===void 0x0?void 0x0:f[pO(0x1b3)]);},p[pw(0x1a7)]['askForProject']=function(){return __awaiter(this,void 0x0,void 0x0,function(){var Y,f;return __generator(this,function(Z){var pv=a6Y;switch(Z[pv(0x133)]){case 0x0:return[0x4,this[pv(0x175)][pv(0x15e)][pv(0x1bb)]({})];case 0x1:Y=Z[pv(0x19d)](),f=Y[pv(0x16e)][pv(0x1bb)][pv(0x132)](function(o){return o['id'];});if(f[pv(0xe3)]<0x1)throw new Error('No\x20projects\x20in\x20current\x20context');return[0x4,inquirer[pv(0x191)]([{'type':'list','name':pv(0x174),'message':pv(0x1aa),'choices':f}])];case 0x2:return[0x2,Z[pv(0x19d)]()[pv(0x174)]];}});});},p[pw(0x1a7)]['askForProjectScopedResource']=function(Y,f,Z,o){return __awaiter(this,void 0x0,void 0x0,function(){var t,L;return __generator(this,function(A){var pP=a6Y;switch(A['label']){case 0x0:t=Z||this[pP(0x175)][pP(0x1a0)][pP(0xfe)]();if(_[pP(0x14e)](t))throw new Error(pP(0x16c));return[0x4,f(t)];case 0x1:L=A[pP(0x19d)]();return[0x4,this['askForResource'](Y,L,''[pP(0x11b)](o?''[pP(0x11b)](o,'\x20in\x20'):'',pP(0x16b))[pP(0x11b)](t,'\x27'))];case 0x2:return[0x2,A['sent']()];}});});},p[pw(0x1a7)][pw(0x1b6)]=function(){return __awaiter(this,void 0x0,void 0x0,function(){var Y,f;return __generator(this,function(Z){var pH=a6Y;switch(Z[pH(0x133)]){case 0x0:return[0x4,this[pH(0x175)][pH(0x15e)][pH(0x1a9)]({})];case 0x1:Y=Z[pH(0x19d)](),f=Y[pH(0x16e)][pH(0x1a9)][pH(0x132)](function(o){var pe=pH;return o[pe(0x174)];});return[0x2,this['askForResource'](pH(0xf7),f)];}});});},p[pw(0x1a7)][pw(0x137)]=function(){return __awaiter(this,void 0x0,void 0x0,function(){var Y,f;return __generator(this,function(Z){var pm=a6Y;switch(Z[pm(0x133)]){case 0x0:return[0x4,this[pm(0x175)][pm(0x15e)][pm(0xff)]({})];case 0x1:Y=Z[pm(0x19d)](),f=Y[pm(0x16e)][pm(0x18c)][pm(0x132)](function(o){return o['id'];});return[0x2,this[pm(0xe2)](pm(0x18c),f)];}});});},p['prototype']['setPathVars']=function(Y){var pb=pw;this[pb(0x1a3)]=Y;},p;}();exports[a6h(0xf9)]=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 utils_1 = require("./utils");
91
+ var api_helpers_1 = require("./api-helpers");
92
+ var inquirer = require('inquirer');
93
+ var yaml = require('js-yaml');
94
+ var ConfirmChoices;
95
+ (function (ConfirmChoices) {
96
+ ConfirmChoices["YES"] = "Yes, send";
97
+ ConfirmChoices["REPEAT"] = "No, repeat";
98
+ ConfirmChoices["EDIT"] = "No, edit";
99
+ ConfirmChoices["SAVE"] = "No, but save as file";
100
+ ConfirmChoices["ABORT"] = "No, abort";
101
+ })(ConfirmChoices || (ConfirmChoices = {}));
102
+ var InquirerHelper = /** @class */ (function () {
103
+ function InquirerHelper(apiClient) {
104
+ var _this = this;
105
+ this.apiClient = apiClient;
106
+ this.editPayload = function (result) { return __awaiter(_this, void 0, void 0, function () {
107
+ var editedResult;
108
+ return __generator(this, function (_a) {
109
+ switch (_a.label) {
110
+ case 0: return [4 /*yield*/, inquirer.prompt([
111
+ {
112
+ type: 'editor',
113
+ name: 'editedResult',
114
+ message: 'Go to editor',
115
+ default: yaml.safeDump(result),
116
+ },
117
+ ])];
118
+ case 1:
119
+ editedResult = (_a.sent()).editedResult;
120
+ return [2 /*return*/, yaml.safeLoad(editedResult)];
121
+ }
122
+ });
123
+ }); };
124
+ this.saveFile = function (result) { return __awaiter(_this, void 0, void 0, function () {
125
+ function prompFileName() {
126
+ return __awaiter(this, void 0, void 0, function () {
127
+ return __generator(this, function (_a) {
128
+ return [2 /*return*/, inquirer.prompt([
129
+ {
130
+ type: 'input',
131
+ name: 'fileName',
132
+ message: 'Provide a file path to write the configuration to (<name>.[json|yaml|yml])',
133
+ validate: function (input) {
134
+ return new RegExp('.*\\.(json|yaml|yml)$').test(input) ? true : fileTypeWarning(input);
135
+ },
136
+ },
137
+ ])];
138
+ });
139
+ });
140
+ }
141
+ var fileTypeWarning, filePath, fileEnding;
142
+ return __generator(this, function (_a) {
143
+ switch (_a.label) {
144
+ case 0:
145
+ fileTypeWarning = function (fileEnding) {
146
+ return "Unexpected file type: ".concat(fileEnding, ", supported types: [json|yaml|yml]");
147
+ };
148
+ return [4 /*yield*/, prompFileName()];
149
+ case 1:
150
+ filePath = (_a.sent()).fileName;
151
+ fileEnding = filePath.toString().split('.').pop();
152
+ try {
153
+ switch (fileEnding) {
154
+ case 'json':
155
+ (0, utils_1.success)("Configuration file written to ".concat(filePath));
156
+ return [2 /*return*/, fs.writeFileSync(filePath, JSON.stringify(result, null, ' '))];
157
+ case 'yaml':
158
+ case 'yml':
159
+ (0, utils_1.success)("Configuration file written to ".concat(filePath));
160
+ return [2 /*return*/, fs.writeFileSync(filePath, yaml.safeDump(result))];
161
+ default:
162
+ (0, utils_1.warning)(fileTypeWarning(fileEnding));
163
+ }
164
+ }
165
+ catch (e) {
166
+ (0, utils_1.warning)("Writing configuration failed: ".concat(e.message));
167
+ }
168
+ return [2 /*return*/, undefined];
169
+ }
170
+ });
171
+ }); };
172
+ this.filter = function (type, required) { return function (input) {
173
+ var sanitisedInput = typeof input === 'string' ? input.trim() : input;
174
+ if (type === 'number' && Number.isNaN(sanitisedInput))
175
+ return '';
176
+ return required === false && sanitisedInput === "don't change" ? '' : sanitisedInput;
177
+ }; };
178
+ this.validate = function (prop, required) { return function (input) {
179
+ var valid = [];
180
+ if (input === '' || input === "don't change") {
181
+ if (required !== false) {
182
+ valid.push("this option is required, please answer");
183
+ }
184
+ else {
185
+ return true;
186
+ }
187
+ }
188
+ if (prop.type === 'string' && !_.isUndefined(prop.pattern)) {
189
+ valid.push(new RegExp(prop.pattern).test(input) ? true : "doesn't match pattern '".concat(prop.pattern, "'"));
190
+ }
191
+ if (prop.type === 'string' && !_.isUndefined(prop.minLength)) {
192
+ valid.push(input.length >= prop.minLength
193
+ ? true
194
+ : "must be longer than or equal to ".concat(prop.minLength, " characters, is ").concat(input.length, " characters"));
195
+ }
196
+ if (prop.type === 'string' && !_.isUndefined(prop.maxLength)) {
197
+ valid.push(input.length <= prop.maxLength
198
+ ? true
199
+ : "must be shorter than or equal to ".concat(prop.maxLength, " characters, is ").concat(input.length, " characters"));
200
+ }
201
+ if (prop.type === 'integer' && !_.isFinite(Number(input))) {
202
+ valid.push("must be a number, is ".concat(input));
203
+ }
204
+ if (prop.type === 'integer' && !_.isUndefined(prop.minimum)) {
205
+ valid.push(input >= prop.minimum ? true : "must be bigger than or equal to ".concat(prop.minimum));
206
+ }
207
+ if (prop.type === 'integer' && !_.isUndefined(prop.maximum)) {
208
+ valid.push(input <= prop.maximum ? true : "must be smaller than or equal to ".concat(prop.maximum));
209
+ }
210
+ if (prop.type === 'rawObject') {
211
+ var asJson = (0, utils_1.isValidJSON)(input);
212
+ valid.push(asJson === false || _.isEmpty(asJson) ? "must be a valid non-empty json string" : true);
213
+ }
214
+ var errors = valid.filter(function (e) { return e !== true; });
215
+ var example = (prop === null || prop === void 0 ? void 0 : prop.example)
216
+ ? "\n".concat(chalk_1.default.red('>>'), " Example: ").concat(chalk_1.default.whiteBright(JSON.stringify(prop.example)))
217
+ : '';
218
+ return errors.length > 0 ? errors.join(chalk_1.default.underline(' and it ')) + example : true;
219
+ }; };
220
+ this.getPathString = function (propPath, question, description) {
221
+ var current = propPath[propPath.length - 1];
222
+ function stringifyPath() {
223
+ return propPath
224
+ .slice(0, -1)
225
+ .map(function (p) { return p.charAt(0).toUpperCase() + p.slice(1); })
226
+ .join('>');
227
+ }
228
+ var path = propPath.length > 1 ? "".concat(chalk_1.default.bgGrey.whiteBright(stringifyPath()), ": ") : '';
229
+ var descr = description ? " (".concat(chalk_1.default.blue(description), ")") : '';
230
+ return chalk_1.default.reset("".concat(path).concat(question, " ").concat(chalk_1.default.bold.greenBright(current)).concat(descr, "?"));
231
+ };
232
+ this.askForResource = function (resourceName, resourceNames, scopedBy) { return __awaiter(_this, void 0, void 0, function () {
233
+ var scope, message;
234
+ return __generator(this, function (_a) {
235
+ switch (_a.label) {
236
+ case 0:
237
+ if (resourceNames.length < 1) {
238
+ scope = scopedBy ? "for this ".concat(scopedBy) : 'found';
239
+ throw new Error("No ".concat(resourceName, " ").concat(scope, "."));
240
+ }
241
+ message = "Choose the ".concat(resourceName, " to use:");
242
+ return [4 /*yield*/, inquirer.prompt([{ type: 'list', name: 'name', message: message, choices: resourceNames }])];
243
+ case 1: return [2 /*return*/, (_a.sent()).name];
244
+ }
245
+ });
246
+ }); };
247
+ this.askGeneric = function (resourceName, description) { return function () { return __awaiter(_this, void 0, void 0, function () {
248
+ var descrMsg, message, validate;
249
+ return __generator(this, function (_a) {
250
+ switch (_a.label) {
251
+ case 0:
252
+ descrMsg = "".concat(description ? "(".concat(chalk_1.default.blue(description), ") ") : '');
253
+ message = "Enter the ".concat(chalk_1.default.green(resourceName), " ").concat(descrMsg, "to use:");
254
+ validate = this.validate({ type: 'string', required: true });
255
+ return [4 /*yield*/, inquirer.prompt([{ type: 'input', name: 'name', message: message, validate: validate }])];
256
+ case 1: return [2 /*return*/, (_a.sent()).name];
257
+ }
258
+ });
259
+ }); }; };
260
+ this.askForService = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
261
+ var apiCall;
262
+ var _this = this;
263
+ return __generator(this, function (_a) {
264
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
265
+ return __generator(this, function (_a) {
266
+ switch (_a.label) {
267
+ case 0: return [4 /*yield*/, this.apiClient.list.services({
268
+ parameters: { projectId: projectName },
269
+ options: { per_page: 100 },
270
+ })];
271
+ case 1: return [2 /*return*/, (_a.sent()).data.services.map(function (svc) { return svc.id; })];
272
+ }
273
+ });
274
+ }); };
275
+ return [2 /*return*/, this.askForProjectScopedResource('service', apiCall, project)];
276
+ });
277
+ }); }; };
278
+ this.askForJob = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
279
+ var apiCall;
280
+ var _this = this;
281
+ return __generator(this, function (_a) {
282
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
283
+ return __generator(this, function (_a) {
284
+ switch (_a.label) {
285
+ case 0: return [4 /*yield*/, this.apiClient.list.jobs({
286
+ parameters: { projectId: projectName },
287
+ options: { per_page: 100 },
288
+ })];
289
+ case 1: return [2 /*return*/, (_a.sent()).data.jobs.map(function (job) { return job.id; })];
290
+ }
291
+ });
292
+ }); };
293
+ return [2 /*return*/, this.askForProjectScopedResource('job', apiCall, project)];
294
+ });
295
+ }); }; };
296
+ this.askForJobRun = function (jobName, project) { return function () { return __awaiter(_this, void 0, void 0, function () {
297
+ var apiCall;
298
+ var _this = this;
299
+ return __generator(this, function (_a) {
300
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
301
+ return __generator(this, function (_a) {
302
+ switch (_a.label) {
303
+ case 0: return [4 /*yield*/, this.apiClient.get.job.runs({
304
+ parameters: { projectId: projectName, jobId: jobName },
305
+ options: { per_page: 100 },
306
+ })];
307
+ case 1: return [2 /*return*/, (_a.sent()).data.runs.map(function (job) { return "".concat(job.id, " (startedAt: ").concat(job.startedAt, ")"); })];
308
+ }
309
+ });
310
+ }); };
311
+ return [2 /*return*/, this.askForProjectScopedResource('job runs', apiCall, project, "job: '".concat(jobName, "'")).then(function (j) { return j.split(' ')[0]; })];
312
+ });
313
+ }); }; };
314
+ this.askForBuild = function (project, serviceId, jobId) { return function () { return __awaiter(_this, void 0, void 0, function () {
315
+ var apiCall, apiCall;
316
+ var _this = this;
317
+ return __generator(this, function (_a) {
318
+ if (jobId !== undefined) {
319
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
320
+ return __generator(this, function (_a) {
321
+ switch (_a.label) {
322
+ case 0: return [4 /*yield*/, this.apiClient.get.job.builds({
323
+ parameters: { projectId: projectName, jobId: jobId },
324
+ options: { per_page: 100 },
325
+ })];
326
+ case 1: return [2 /*return*/, (_a.sent()).data.builds.map(function (build) { return "".concat(build.id, " (startedAt: ").concat(build.createdAt, ")"); })];
327
+ }
328
+ });
329
+ }); };
330
+ return [2 /*return*/, this.askForProjectScopedResource('job builds', apiCall, project, "job: '".concat(jobId, "'")).then(function (j) { return j.split(' ')[0]; })];
331
+ }
332
+ if (serviceId !== undefined) {
333
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
334
+ return __generator(this, function (_a) {
335
+ switch (_a.label) {
336
+ case 0: return [4 /*yield*/, this.apiClient.get.service.builds({
337
+ parameters: { projectId: projectName, serviceId: serviceId },
338
+ options: { per_page: 100 },
339
+ })];
340
+ case 1: return [2 /*return*/, (_a.sent()).data.builds.map(function (build) { return "".concat(build.id, " (startedAt: ").concat(build.createdAt, ")"); })];
341
+ }
342
+ });
343
+ }); };
344
+ return [2 /*return*/, this.askForProjectScopedResource('job build', apiCall, project, "service: '".concat(jobId, "'")).then(function (j) { return j.split(' ')[0]; })];
345
+ }
346
+ throw new Error('No builds found');
347
+ });
348
+ }); }; };
349
+ this.askForAddon = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
350
+ var apiCall;
351
+ var _this = this;
352
+ return __generator(this, function (_a) {
353
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
354
+ return __generator(this, function (_a) {
355
+ switch (_a.label) {
356
+ case 0: return [4 /*yield*/, this.apiClient.list.addons({
357
+ parameters: { projectId: projectName },
358
+ options: { per_page: 100 },
359
+ })];
360
+ case 1: return [2 /*return*/, (_a.sent()).data.addons.map(function (svc) { return svc.id; })];
361
+ }
362
+ });
363
+ }); };
364
+ return [2 /*return*/, this.askForProjectScopedResource('addon', apiCall, project)];
365
+ });
366
+ }); }; };
367
+ this.askForAddonBackup = function (project, addon) { return function () { return __awaiter(_this, void 0, void 0, function () {
368
+ var apiCall;
369
+ var _this = this;
370
+ return __generator(this, function (_a) {
371
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
372
+ return __generator(this, function (_a) {
373
+ switch (_a.label) {
374
+ case 0: return [4 /*yield*/, this.apiClient.get.addon.backups({
375
+ parameters: {
376
+ projectId: projectName,
377
+ addonId: addon,
378
+ },
379
+ options: { per_page: 100 },
380
+ })];
381
+ case 1: return [2 /*return*/, (_a.sent()).data.backups.map(function (job) { return "".concat(job.id, " (completedAt: ").concat(job.completedAt || 'not completed', ")"); })];
382
+ }
383
+ });
384
+ }); };
385
+ return [2 /*return*/, this.askForProjectScopedResource('backups', apiCall, project, "addon: '".concat(addon, "'")).then(function (j) { return j.split(' ')[0]; })];
386
+ });
387
+ }); }; };
388
+ this.askForVolume = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
389
+ var apiCall;
390
+ var _this = this;
391
+ return __generator(this, function (_a) {
392
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
393
+ return __generator(this, function (_a) {
394
+ switch (_a.label) {
395
+ case 0: return [4 /*yield*/, this.apiClient.list.volumes({ parameters: { projectId: projectName } })];
396
+ case 1: return [2 /*return*/, (_a.sent()).data.map(function (vol) { return vol.id; })];
397
+ }
398
+ });
399
+ }); };
400
+ return [2 /*return*/, this.askForProjectScopedResource('volume', apiCall, project)];
401
+ });
402
+ }); }; };
403
+ this.askForSecret = function (project) { return function () { return __awaiter(_this, void 0, void 0, function () {
404
+ var apiCall;
405
+ var _this = this;
406
+ return __generator(this, function (_a) {
407
+ apiCall = function (projectName) { return __awaiter(_this, void 0, void 0, function () {
408
+ return __generator(this, function (_a) {
409
+ switch (_a.label) {
410
+ case 0: return [4 /*yield*/, this.apiClient.list.secrets({
411
+ parameters: { projectId: projectName },
412
+ options: { per_page: 100 },
413
+ })];
414
+ case 1: return [2 /*return*/, (_a.sent()).data.secrets.map(function (svc) { return svc.id; })];
415
+ }
416
+ });
417
+ }); };
418
+ return [2 /*return*/, this.askForProjectScopedResource('secret', apiCall, project)];
419
+ });
420
+ }); }; };
421
+ this.askForSubdomain = function (domain) { return function () { return __awaiter(_this, void 0, void 0, function () {
422
+ var getDomainResponse, subdomains, scopedBy;
423
+ return __generator(this, function (_a) {
424
+ switch (_a.label) {
425
+ case 0: return [4 /*yield*/, this.apiClient.get.domain({
426
+ parameters: { domain: domain },
427
+ })];
428
+ case 1:
429
+ getDomainResponse = _a.sent();
430
+ subdomains = getDomainResponse.data.subdomains.map(function (d) { return "".concat(d.name, " (full domain: ").concat(d.fullName, ")"); });
431
+ scopedBy = "domain (".concat(domain, ")");
432
+ return [2 /*return*/, this.askForResource('subdomain', subdomains, scopedBy).then(function (j) { return j.split(' ')[0]; })];
433
+ }
434
+ });
435
+ }); }; };
436
+ this.deleteWarningPrompt = function (resourceString) { return __awaiter(_this, void 0, void 0, function () {
437
+ return __generator(this, function (_a) {
438
+ switch (_a.label) {
439
+ case 0: return [4 /*yield*/, inquirer.prompt([
440
+ {
441
+ type: 'confirm',
442
+ name: 'confirmation',
443
+ message: chalk_1.default.yellowBright("WARNING: You are about to delete ".concat(resourceString || 'a Northflank resource', ". This is irreversible. Please confirm!")),
444
+ default: false,
445
+ },
446
+ ])];
447
+ case 1: return [2 /*return*/, (_a.sent()).confirmation];
448
+ }
449
+ });
450
+ }); };
451
+ this.loginPrompt = function (options, existingContexts) { return __awaiter(_this, void 0, void 0, function () {
452
+ var token;
453
+ var _this = this;
454
+ return __generator(this, function (_a) {
455
+ switch (_a.label) {
456
+ case 0:
457
+ if (!_.isUndefined(options.name)) return [3 /*break*/, 3];
458
+ if (!(existingContexts.length <= 0)) return [3 /*break*/, 1];
459
+ _.set(options, 'name', 'default');
460
+ return [3 /*break*/, 3];
461
+ case 1: return [4 /*yield*/, (0, utils_1.retry)(10)(function () { return __awaiter(_this, void 0, void 0, function () {
462
+ var name, c;
463
+ return __generator(this, function (_a) {
464
+ switch (_a.label) {
465
+ case 0: return [4 /*yield*/, inquirer.prompt([
466
+ {
467
+ type: 'input',
468
+ name: 'name',
469
+ message: 'Choose the name of the new local context:',
470
+ default: 'main-context',
471
+ },
472
+ ])];
473
+ case 1:
474
+ name = (_a.sent()).name;
475
+ if (!(!options.override && existingContexts.find(function (ctx) { return ctx.name === name; }))) return [3 /*break*/, 3];
476
+ return [4 /*yield*/, inquirer.prompt([
477
+ {
478
+ type: 'confirm',
479
+ name: 'c',
480
+ message: "Context with name '".concat(name, "' already exists. Do you want to override this context (y) or enter a new name (N)?"),
481
+ default: false,
482
+ },
483
+ ])];
484
+ case 2:
485
+ c = (_a.sent()).c;
486
+ if (c === false)
487
+ throw new Error('Context name already exists.');
488
+ _.set(options, 'override', true);
489
+ _a.label = 3;
490
+ case 3:
491
+ _.set(options, 'name', name);
492
+ return [2 /*return*/];
493
+ }
494
+ });
495
+ }); })];
496
+ case 2:
497
+ _a.sent();
498
+ _a.label = 3;
499
+ case 3:
500
+ if (!_.isUndefined(options.token)) return [3 /*break*/, 5];
501
+ return [4 /*yield*/, this.tokenPrompt()];
502
+ case 4:
503
+ token = _a.sent();
504
+ _.set(options, 'token', token);
505
+ _a.label = 5;
506
+ case 5: return [2 /*return*/, options];
507
+ }
508
+ });
509
+ }); };
510
+ this.tokenPrompt = function () { return __awaiter(_this, void 0, void 0, function () {
511
+ var token;
512
+ return __generator(this, function (_a) {
513
+ switch (_a.label) {
514
+ case 0: return [4 /*yield*/, inquirer.prompt([
515
+ {
516
+ type: 'password',
517
+ name: 'token',
518
+ mask: '*',
519
+ message: 'Choose the login token:',
520
+ },
521
+ ])];
522
+ case 1:
523
+ token = (_a.sent()).token;
524
+ return [2 /*return*/, token];
525
+ }
526
+ });
527
+ }); };
528
+ }
529
+ InquirerHelper.prototype.confirmationPrompt = function (result, defaultOpt) {
530
+ return __awaiter(this, void 0, void 0, function () {
531
+ var resultDump, length, divider, confirm, _a, _b;
532
+ return __generator(this, function (_c) {
533
+ switch (_c.label) {
534
+ case 0:
535
+ resultDump = yaml.safeDump(result);
536
+ length = _.max(resultDump.split('\n').map(function (l) { return l.length; }));
537
+ divider = chalk_1.default.grey("".concat('-'.repeat(length), "\n"));
538
+ return [4 /*yield*/, inquirer.prompt([
539
+ {
540
+ type: 'list',
541
+ name: 'confirm',
542
+ message: "".concat(chalk_1.default.bold.green('Please confirm following configuration:\n')).concat(divider).concat(chalk_1.default.blueBright(resultDump)).concat(divider),
543
+ choices: Object.values(ConfirmChoices),
544
+ },
545
+ ])];
546
+ case 1:
547
+ confirm = (_c.sent()).confirm;
548
+ _a = confirm;
549
+ switch (_a) {
550
+ case ConfirmChoices.YES: return [3 /*break*/, 2];
551
+ case ConfirmChoices.ABORT: return [3 /*break*/, 3];
552
+ case ConfirmChoices.REPEAT: return [3 /*break*/, 4];
553
+ case ConfirmChoices.EDIT: return [3 /*break*/, 5];
554
+ case ConfirmChoices.SAVE: return [3 /*break*/, 7];
555
+ }
556
+ return [3 /*break*/, 9];
557
+ case 2: return [2 /*return*/, result];
558
+ case 3: throw new Error('Aborted.');
559
+ case 4: return [2 /*return*/, this.retrievePayloadViaInteractiveCli(defaultOpt)];
560
+ case 5:
561
+ _b = this.confirmationPrompt;
562
+ return [4 /*yield*/, this.editPayload(result)];
563
+ case 6: return [2 /*return*/, _b.apply(this, [_c.sent(), defaultOpt])];
564
+ case 7: return [4 /*yield*/, this.saveFile(result)];
565
+ case 8:
566
+ _c.sent();
567
+ return [2 /*return*/, this.confirmationPrompt(result, defaultOpt)];
568
+ case 9: throw new Error('Something unexpected happened.');
569
+ }
570
+ });
571
+ });
572
+ };
573
+ InquirerHelper.prototype.retrievePayloadViaInteractiveCli = function (defaultOpt, ctx) {
574
+ return __awaiter(this, void 0, void 0, function () {
575
+ var result;
576
+ return __generator(this, function (_a) {
577
+ switch (_a.label) {
578
+ case 0:
579
+ if ((ctx === null || ctx === void 0 ? void 0 : ctx.resultCache) !== undefined)
580
+ this.resultCache = ctx === null || ctx === void 0 ? void 0 : ctx.resultCache;
581
+ this.tmpCmdPath = ctx === null || ctx === void 0 ? void 0 : ctx.cmdPath;
582
+ result = {};
583
+ return [4 /*yield*/, this.propToType([], defaultOpt.opt.body, result)];
584
+ case 1:
585
+ _a.sent();
586
+ this.resultCache = result;
587
+ return [4 /*yield*/, this.confirmationPrompt(result, defaultOpt)];
588
+ case 2: return [2 /*return*/, _a.sent()];
589
+ }
590
+ });
591
+ });
592
+ };
593
+ InquirerHelper.prototype.propToType = function (propPath, prop, obj, required) {
594
+ return __awaiter(this, void 0, void 0, function () {
595
+ var type, choice_1, oneOfProp;
596
+ return __generator(this, function (_a) {
597
+ switch (_a.label) {
598
+ case 0:
599
+ if (!(prop.oneOf && !_.has(prop, 'properties'))) return [3 /*break*/, 6];
600
+ if (!(prop.oneOf.length > 1)) return [3 /*break*/, 3];
601
+ return [4 /*yield*/, inquirer.prompt([
602
+ {
603
+ type: 'list',
604
+ name: 'choice',
605
+ message: "What's the ".concat(propPath[propPath.length - 1] || '', " type?"),
606
+ choices: prop.oneOf.map(function (p) { return p.description; }),
607
+ },
608
+ ])];
609
+ case 1:
610
+ choice_1 = (_a.sent()).choice;
611
+ return [4 /*yield*/, this.getType(propPath, prop.oneOf.find(function (p) { return p.description === choice_1; }), obj, required)];
612
+ case 2:
613
+ type = _a.sent();
614
+ return [3 /*break*/, 5];
615
+ case 3:
616
+ oneOfProp = prop.oneOf[0];
617
+ _.set(oneOfProp, 'description', prop.description);
618
+ return [4 /*yield*/, this.getType(propPath, oneOfProp, obj, required)];
619
+ case 4:
620
+ type = _a.sent();
621
+ _a.label = 5;
622
+ case 5:
623
+ type = {};
624
+ return [3 /*break*/, 8];
625
+ case 6: return [4 /*yield*/, this.getType(propPath, prop, obj, required)];
626
+ case 7:
627
+ type = _a.sent();
628
+ _a.label = 8;
629
+ case 8: return [2 /*return*/, type];
630
+ }
631
+ });
632
+ });
633
+ };
634
+ InquirerHelper.prototype.getInnerType = function (prop, path, obj, required) {
635
+ var _a;
636
+ return __awaiter(this, void 0, void 0, function () {
637
+ var addEntry, propertyKeys, requiredProps, _i, propertyKeys_1, propNameInner, innerPath;
638
+ return __generator(this, function (_b) {
639
+ switch (_b.label) {
640
+ case 0:
641
+ if (!(required === false)) return [3 /*break*/, 2];
642
+ return [4 /*yield*/, inquirer.prompt([
643
+ {
644
+ type: 'confirm',
645
+ name: 'addEntry',
646
+ message: this.getPathString(path, "Do you want to add", prop === null || prop === void 0 ? void 0 : prop.description),
647
+ default: false,
648
+ },
649
+ ])];
650
+ case 1:
651
+ addEntry = (_b.sent()).addEntry;
652
+ if (!addEntry)
653
+ return [2 /*return*/, obj];
654
+ _b.label = 2;
655
+ case 2:
656
+ propertyKeys = Object.keys((_a = prop === null || prop === void 0 ? void 0 : prop.properties) !== null && _a !== void 0 ? _a : []);
657
+ requiredProps = prop.required || [];
658
+ if (!(propertyKeys.length > 0)) return [3 /*break*/, 7];
659
+ _i = 0, propertyKeys_1 = propertyKeys;
660
+ _b.label = 3;
661
+ case 3:
662
+ if (!(_i < propertyKeys_1.length)) return [3 /*break*/, 6];
663
+ propNameInner = propertyKeys_1[_i];
664
+ innerPath = path.concat(propNameInner);
665
+ // innerPath.concat(propNameInner);
666
+ // eslint-disable-next-line no-await-in-loop
667
+ if (path.length > 0 && !_.has(obj, path.join('.')))
668
+ _.set(obj, path.join('.'), {});
669
+ return [4 /*yield*/, this.propToType(innerPath, prop.properties[propNameInner], obj, requiredProps.includes(propNameInner))];
670
+ case 4:
671
+ _b.sent();
672
+ _b.label = 5;
673
+ case 5:
674
+ _i++;
675
+ return [3 /*break*/, 3];
676
+ case 6: return [3 /*break*/, 9];
677
+ case 7: return [4 /*yield*/, this.getType(path, __assign(__assign({}, prop), { type: 'rawObject' }), obj, required)];
678
+ case 8:
679
+ _b.sent();
680
+ _b.label = 9;
681
+ case 9: return [2 /*return*/, obj];
682
+ }
683
+ });
684
+ });
685
+ };
686
+ InquirerHelper.prototype.askArrayEntry = function (propPath, firstTime, required, description) {
687
+ return __awaiter(this, void 0, void 0, function () {
688
+ var message, addEntry;
689
+ return __generator(this, function (_a) {
690
+ switch (_a.label) {
691
+ case 0:
692
+ if (firstTime && required) {
693
+ return [2 /*return*/, true];
694
+ }
695
+ message = firstTime ? "Do you want to add" : "Do you want to add more";
696
+ return [4 /*yield*/, inquirer.prompt([
697
+ {
698
+ type: 'confirm',
699
+ name: 'addEntry',
700
+ message: this.getPathString(propPath, message, firstTime ? description : undefined),
701
+ default: false,
702
+ },
703
+ ])];
704
+ case 1:
705
+ addEntry = (_a.sent()).addEntry;
706
+ return [2 /*return*/, addEntry];
707
+ }
708
+ });
709
+ });
710
+ };
711
+ InquirerHelper.prototype.getType = function (propPath, prop, obj, required) {
712
+ return __awaiter(this, void 0, void 0, function () {
713
+ var result, path, _a, firstTime, current, newEntry, _b;
714
+ return __generator(this, function (_c) {
715
+ switch (_c.label) {
716
+ case 0:
717
+ path = propPath.join('.');
718
+ _a = prop === null || prop === void 0 ? void 0 : prop.type;
719
+ switch (_a) {
720
+ case 'array': return [3 /*break*/, 1];
721
+ case 'object': return [3 /*break*/, 6];
722
+ case 'rawObject': return [3 /*break*/, 8];
723
+ case 'string': return [3 /*break*/, 10];
724
+ case 'boolean': return [3 /*break*/, 10];
725
+ case 'integer': return [3 /*break*/, 10];
726
+ }
727
+ return [3 /*break*/, 10];
728
+ case 1:
729
+ firstTime = true;
730
+ _c.label = 2;
731
+ case 2: return [4 /*yield*/, this.askArrayEntry(propPath, firstTime, required, prop === null || prop === void 0 ? void 0 : prop.description)];
732
+ case 3:
733
+ if (!_c.sent()) return [3 /*break*/, 5];
734
+ current = _.get(obj, path);
735
+ _.unset(obj, path);
736
+ return [4 /*yield*/, this.getType(propPath, prop.items, obj)];
737
+ case 4:
738
+ _c.sent();
739
+ newEntry = _.get(obj, path);
740
+ if (!_.isArray(current)) {
741
+ _.set(obj, path, [newEntry]);
742
+ }
743
+ else {
744
+ current.push(newEntry);
745
+ _.set(obj, path, current);
746
+ }
747
+ firstTime = false;
748
+ return [3 /*break*/, 2];
749
+ case 5:
750
+ // @ts-ignore
751
+ return [2 /*return*/, result || []];
752
+ case 6: return [4 /*yield*/, this.getInnerType(prop, propPath, obj, required)];
753
+ case 7:
754
+ result = _c.sent();
755
+ return [2 /*return*/, result];
756
+ case 8:
757
+ _b = utils_1.isValidJSON;
758
+ return [4 /*yield*/, this.ask(propPath, prop, required)];
759
+ case 9:
760
+ result = _b.apply(void 0, [_c.sent()]) || undefined;
761
+ return [3 /*break*/, 12];
762
+ case 10: return [4 /*yield*/, this.ask(propPath, prop, required, obj)];
763
+ case 11:
764
+ result = _c.sent();
765
+ return [3 /*break*/, 12];
766
+ case 12:
767
+ if (!_.isUndefined(result)) {
768
+ _.set(obj, path, result);
769
+ }
770
+ return [2 /*return*/, result];
771
+ }
772
+ });
773
+ });
774
+ };
775
+ InquirerHelper.prototype.ask = function (propPath, prop, required, currentObj) {
776
+ var _a;
777
+ return __awaiter(this, void 0, void 0, function () {
778
+ var parentPropertyPath, _b, _c, defaultValue, _d, choices, type, defaultStr, requiredAdjustedChoices, questionConfig, result;
779
+ return __generator(this, function (_e) {
780
+ switch (_e.label) {
781
+ case 0:
782
+ parentPropertyPath = propPath[propPath.length - 1];
783
+ return [4 /*yield*/, (0, api_helpers_1.fetchResourceList)(parentPropertyPath, this.apiClient, this.tmpCmdPath, currentObj, this.pathVars, propPath)];
784
+ case 1:
785
+ _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;
786
+ type = 'input';
787
+ if (!_.isUndefined(choices)) {
788
+ type = 'list';
789
+ }
790
+ else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'boolean') {
791
+ type = 'confirm';
792
+ }
793
+ else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'integer') {
794
+ type = 'number';
795
+ }
796
+ else if ((prop === null || prop === void 0 ? void 0 : prop.type) === 'rawObject') {
797
+ type = 'editor';
798
+ }
799
+ defaultStr =
800
+ // eslint-disable-next-line no-nested-ternary
801
+ required !== false
802
+ ? !_.isObject(defaultValue)
803
+ ? defaultValue
804
+ : JSON.stringify(defaultValue)
805
+ : _.isBoolean(defaultValue)
806
+ ? defaultValue
807
+ : "don't change";
808
+ if (choices)
809
+ defaultStr = defaultStr.toString();
810
+ if (_.has(this.resultCache, propPath.join('.'))) {
811
+ defaultStr = this.resultCache[propPath.join('.')];
812
+ }
813
+ requiredAdjustedChoices = choices && required === false ? __spreadArray(__spreadArray([], choices, true), ["don't change"], false) : choices;
814
+ questionConfig = {
815
+ type: type,
816
+ name: 'id',
817
+ message: this.getQuestionString(propPath, prop),
818
+ choices: requiredAdjustedChoices,
819
+ default: defaultStr,
820
+ filter: this.filter(type, required),
821
+ validate: this.validate(prop, required),
822
+ };
823
+ return [4 /*yield*/, inquirer.prompt([questionConfig])];
824
+ case 2:
825
+ result = (_e.sent()).id;
826
+ return [2 /*return*/, result === "don't change" || result === '' ? undefined : result];
827
+ }
828
+ });
829
+ });
830
+ };
831
+ InquirerHelper.prototype.getQuestionString = function (propPath, prop) {
832
+ var question = (prop === null || prop === void 0 ? void 0 : prop.type) !== 'boolean' ? "What do you want to use as" : 'Should it be';
833
+ return this.getPathString(propPath, question, prop === null || prop === void 0 ? void 0 : prop.description);
834
+ };
835
+ InquirerHelper.prototype.askForProject = function () {
836
+ return __awaiter(this, void 0, void 0, function () {
837
+ var projects, projectNames;
838
+ return __generator(this, function (_a) {
839
+ switch (_a.label) {
840
+ case 0: return [4 /*yield*/, this.apiClient.list.projects({})];
841
+ case 1:
842
+ projects = _a.sent();
843
+ projectNames = projects.data.projects.map(function (prj) { return prj.id; });
844
+ if (projectNames.length < 1) {
845
+ throw new Error("No projects in current context");
846
+ }
847
+ return [4 /*yield*/, inquirer.prompt([
848
+ {
849
+ type: 'list',
850
+ name: 'name',
851
+ message: "Choose the project to use:",
852
+ choices: projectNames,
853
+ },
854
+ ])];
855
+ case 2: return [2 /*return*/, (_a.sent()).name];
856
+ }
857
+ });
858
+ });
859
+ };
860
+ InquirerHelper.prototype.askForProjectScopedResource = function (resourceName, apiCall, project, subScope) {
861
+ return __awaiter(this, void 0, void 0, function () {
862
+ var projectName, resourceNames;
863
+ return __generator(this, function (_a) {
864
+ switch (_a.label) {
865
+ case 0:
866
+ projectName = project || this.apiClient.contextProvider.getCurrentProjectName();
867
+ if (_.isUndefined(projectName)) {
868
+ throw new Error('Default project in context not set and no argument provided.');
869
+ }
870
+ return [4 /*yield*/, apiCall(projectName)];
871
+ case 1:
872
+ resourceNames = _a.sent();
873
+ return [4 /*yield*/, this.askForResource(resourceName, resourceNames, "".concat(subScope ? "".concat(subScope, " in ") : '', "project: '").concat(projectName, "'"))];
874
+ case 2: return [2 /*return*/, _a.sent()];
875
+ }
876
+ });
877
+ });
878
+ };
879
+ InquirerHelper.prototype.askForDomain = function () {
880
+ return __awaiter(this, void 0, void 0, function () {
881
+ var listDomainsResponse, domains;
882
+ return __generator(this, function (_a) {
883
+ switch (_a.label) {
884
+ case 0: return [4 /*yield*/, this.apiClient.list.domains({})];
885
+ case 1:
886
+ listDomainsResponse = _a.sent();
887
+ domains = listDomainsResponse.data.domains.map(function (d) { return d.name; });
888
+ return [2 /*return*/, this.askForResource('domain', domains)];
889
+ }
890
+ });
891
+ });
892
+ };
893
+ InquirerHelper.prototype.askForCredentials = function () {
894
+ return __awaiter(this, void 0, void 0, function () {
895
+ var listCredentialsResponse, credentials;
896
+ return __generator(this, function (_a) {
897
+ switch (_a.label) {
898
+ case 0: return [4 /*yield*/, this.apiClient.list.registryCredentials({})];
899
+ case 1:
900
+ listCredentialsResponse = _a.sent();
901
+ credentials = listCredentialsResponse.data.credentials.map(function (d) { return d.id; });
902
+ return [2 /*return*/, this.askForResource('credentials', credentials)];
903
+ }
904
+ });
905
+ });
906
+ };
907
+ InquirerHelper.prototype.setPathVars = function (opt) {
908
+ this.pathVars = opt;
909
+ };
910
+ return InquirerHelper;
911
+ }());
912
+ exports.InquirerHelper = InquirerHelper;