@northflank/js-client 0.9.3-beta.1 → 0.9.3-beta.2
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/cjs/api-client.d.ts +9 -3852
- package/dist/cjs/api-client.js +60 -59
- package/dist/esm/api-client.d.ts +9 -3852
- package/dist/esm/api-client.js +48 -47
- package/package.json +1 -1
package/dist/esm/api-client.js
CHANGED
|
@@ -158,21 +158,21 @@ return[2,(s.address=u.sent(),s.port=o.internalPort,s)]}})})},t.prototype.consist
|
|
|
158
158
|
return[4,ta.load({header:"Northflank Proxy"})];case 1:return t=r.sent(),e(t),[4,t.backup({suffix:".backup-pre-northflank"})];case 2:r.sent(),r.label=3;case 3:return r.trys.push([3,5,,7]),[4,Uo(5)(function(){return W(n,void 0,void 0,function(){return $(this,function(e){switch(e.label){case 0:return[4,t.write({writeMode:"atomic"})];case 1:return e.sent(),[2]}})})})];case 4:return r.sent(),[3,7];case 5:return r.sent(),[4,Uo(5)(function(){return W(n,void 0,void 0,function(){return $(this,function(e){switch(e.label){case 0:return[4,t.write({writeMode:"standard"})];case 1:return e.sent(),[2]}})})})];case 6:return r.sent(),[3,7];case 7:return[2]}})})})];case 1:return n.sent(),[2]}})})},t.prototype.stopProjectForwarding=function(e){return W(this,void 0,void 0,function(){var t=this;return $(this,function(n){switch(n.label){case 0:return[4,Promise.all(this.connections.filter(function(t){return t.forwardingContext.projectId===e.projectId}).map(function(e){return t.stopForwarding(e)}))];case 1:
|
|
159
159
|
return n.sent(),[2]}})})},t.prototype.stopServiceForwarding=function(e){return W(this,void 0,void 0,function(){var t=this;return $(this,function(n){switch(n.label){case 0:return[4,Promise.all(this.connections.filter(function(t){return"service"===t.forwardingContext.type&&t.forwardingContext.projectId===e.projectId&&t.forwardingContext.id===e.serviceId}).map(function(e){return t.stopForwarding(e)}))];case 1:return n.sent(),[2]}})})},t.prototype.stopAddonForwarding=function(e){return W(this,void 0,void 0,function(){var t=this;return $(this,function(n){switch(n.label){case 0:return[4,Promise.all(this.connections.filter(function(t){return"addon"===t.forwardingContext.type&&t.forwardingContext.projectId===e.projectId&&t.forwardingContext.id===e.addonId}).map(function(e){return t.stopForwarding(e)}))];case 1:return n.sent(),[2]}})})},t.prototype.stop=function(){return W(this,void 0,void 0,function(){var e=this;return $(this,function(t){switch(t.label){case 0:
|
|
160
160
|
return[4,Promise.all(this.connections.map(function(t){return W(e,void 0,void 0,function(){return $(this,function(e){return[2,this.stopForwarding(t)]})})}))];case 1:return t.sent(),[2]}})})},t}(t),ui=function(e){function t(t,n,r,a,i,d,p){void 0===i&&(i=new o.PassThrough),void 0===d&&(d=new o.PassThrough),void 0===p&&(p=new o.PassThrough);var l=e.call(this)||this;return l.baseUrl=t,l.execConfig=n,l.token=r,l.agent=a,l.stdOut=i,l.stdErr=d,l.stdIn=p,l.waitForCommandResult=function(){return W(l,void 0,void 0,function(){return $(this,function(e){switch(e.label){case 0:if(void 0===this.currentCommand)throw new Error("No command is running");return[4,this.currentCommand];case 1:return[2,e.sent()]}})})},l.sendInputToCurrentCommand=function(e){return W(l,void 0,void 0,function(){var t;return $(this,function(n){if(void 0===this.currentCommand||void 0===this.duplex)throw new Error("No command is running");return null===(t=this.duplex)||void 0===t||t.write(this.constructPayloadPacket(e)),[2]})})},
|
|
161
|
-
l.resizeTerminal=function(e){return W(l,void 0,void 0,function(){var t;return $(this,function(n){if(void 0===this.currentCommand||void 0===this.duplex)throw new Error("No command is running, can't resize terminal");return null===(t=this.duplex)||void 0===t||t.write(JSON.stringify({type:"resize",data:{ttyRows:null==e?void 0:e.rows,ttyColumns:null==e?void 0:e.columns}})),[2]})})},l.constructPayloadPacket=function(e){
|
|
162
|
-
return"
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
new Error("Command execution failed: ".concat(a instanceof Error?a.message:String(a)));case 4:return[2]}})})},e.prototype.shellSession=function(e,t){return W(this,void 0,void 0,function(){var n,r;return $(this,function(o){switch(o.label){case 0:return this.assertStartedWithNodejs(),n=this.getCommandRunner(e),r=new Promise(function(e,r){n.once("auth-success",function(n){var r;null==t||t(null!==(r=null==n?void 0:n.context)&&void 0!==r?r:{}),e()}),n.once("error",function(e){r(new Error("Shell session failed: ".concat(e.message||e)))});var o=setTimeout(function(){r(new Error("Shell session timed out waiting for auth-success"))},3e4);n.once("auth-success",function(){return clearTimeout(o)})}),n.start(),[4,r];case 1:return o.sent(),[2,n]}})})},e.prototype.getCommandRunner=function(e){var t=this.contextProvider.getCurrentBaseUrl(!0),n=this.contextProvider.getCurrentToken();if(!n)throw Error("API token not found");var r=e.execLocationHint,o=e.execLocationOverride
|
|
175
|
-
shell:"none"},e),n,this.http2Session({execLocationOverride:o})):r?new mi(J({shell:"none"},e),n,this.http2Session({execLocationHint:r})):new ui(t,e,n,this.agent)},e}(),hi=Object.defineProperty,fi="object"==typeof process&&process?process:{stdout:null,stderr:null
|
|
161
|
+
l.resizeTerminal=function(e){return W(l,void 0,void 0,function(){var t;return $(this,function(n){if(void 0===this.currentCommand||void 0===this.duplex)throw new Error("No command is running, can't resize terminal");return null===(t=this.duplex)||void 0===t||t.write(JSON.stringify({type:"resize",data:{ttyRows:null==e?void 0:e.rows,ttyColumns:null==e?void 0:e.columns}})),[2]})})},l.constructPayloadPacket=function(e){return JSON.stringify({type:"payload",data:e.toString()})},l.stdInEndPacket=JSON.stringify({type:"stdInEnd"}),l}return z(t,e),Object.defineProperty(t.prototype,"execEndpoint",{get:function(){var e=this.execConfig,t=e.entityId,n=e.entityType,r=e.projectId,o=e.teamId,a=void 0!==o?"teams/".concat(o,"/"):"",i="".concat(this.baseUrl,"/v1/command-exec/").concat(a,"projects/").concat(r,"/");return"".concat(i).concat(function(){switch(n){case"service":return"services/".concat(t);case"job":return"jobs/".concat(t);case"addon":return"addons/".concat(t);case"build":
|
|
162
|
+
return"builds/".concat(t);default:throw new Error("Unexpected Northflank entity type received in command exec endpoint generation: ".concat(n))}}())},enumerable:!1,configurable:!0}),t.prototype.start=function(){return W(this,void 0,void 0,function(){var e=this;return $(this,function(t){if(void 0!==this.currentCommand)throw new Error("Command is already running");return this.currentCommand=new Promise(function(t,n){var r,o,a;if(void 0===e.remote){var i,d=!1,p=function(t){d?e.listenerCount("error")>0&&e.emit("error",new Error(t)):(d=!0,e.listenerCount("error")>0&&e.emit("error",new Error(t)),e.reset(),n(new Error(t)))};try{var l=e.execEndpoint.replace("https:","wss:").replace("http:","ws:");e.remote=new ii(l,{agent:e.agent}),e.remote.on("error",function(e){p("WebSocket error: ".concat(e.message))}),e.remote.on("close",function(e,t){[1e3,1005].includes(e)||d||p("WebSocket closed unexpectedly: ".concat(e," ").concat(t||"(no reason)"))}),e.duplex=ti(e.remote)}catch(e){
|
|
163
|
+
return void p("Failed to establish connection to command execution proxy: ".concat(e.message))}e.stdIn.on("data",function(t){var n;(null===(n=e.duplex)||void 0===n?void 0:n.writable)&&e.duplex.write(e.constructPayloadPacket(t))}),e.stdIn.on("end",function(){var t;(null===(t=e.duplex)||void 0===t?void 0:t.writable)&&e.duplex.write(e.stdInEndPacket)});null===(r=e.duplex)||void 0===r||r.on("data",function(t){var n,r,o,a,d;try{var l=JSON.parse(t.toString());switch(null==l?void 0:l.type){case"init":var s=l.data;"successful"!==s.auth?p("Command initialization failed: ".concat(null!==(n=null==s?void 0:s.message)&&void 0!==n?n:"Reason unknown")):e.emit("auth-success",s);break;case"completion":i=l.data,e.emit("command-result",i),null===(r=e.duplex)||void 0===r||r.end(),e.stdOut.end(),e.stdErr.end(),e.stdIn.end();break;case"stdOut":e.emit("std-out-data",l.data),e.stdOut.write(l.data,null===(o=e.execConfig)||void 0===o?void 0:o.encoding);break;case"stdErr":e.emit("std-err-data",l.data),
|
|
164
|
+
e.stdErr.write(l.data,null===(a=e.execConfig)||void 0===a?void 0:a.encoding);break;case"error":p((null===(d=l.data)||void 0===d?void 0:d.message)||"Unknown error");break;default:var u="unable to parse message: ".concat(JSON.stringify(l));p(u)}}catch(e){p("Failed to parse message: ".concat(e.message))}}),null===(o=e.duplex)||void 0===o||o.on("end",function(){i?d||(d=!0,e.emit("command-completed"),e.reset(),t(i)):d||p("Connection closed before receiving command result")}),null===(a=e.duplex)||void 0===a||a.on("error",function(e){p("Duplex stream error: ".concat(e.message))}),e.initialAuth(),e.emit("command-started")}else n(Error("Command is already running"))}),[2,this.currentCommand]})})},t.prototype.initialAuth=function(){var e,t=this.execConfig,n=t.command,r=t.containerName,o=t.instanceName,a=t.shell,i=t.user,d=this.execConfig,p=d.group,l=d.encoding,s=d.tty,u=d.ttyColumns,m=d.ttyRows,c={type:"init",data:{auth:{type:"apiToken",apiToken:this.token},context:{instanceName:o,
|
|
165
|
+
containerName:r,command:n,shell:a,user:i,group:p,encoding:l,tty:s,ttyColumns:u,ttyRows:m}}};null===(e=this.duplex)||void 0===e||e.write(JSON.stringify(c))},t.prototype.reset=function(){var e;this.remote=void 0,this.currentCommand=void 0,null===(e=this.duplex)||void 0===e||e.destroy(),this.duplex=void 0},t}(t),mi=function(e){function t(t,n,r,a,i,d){void 0===a&&(a=new o.PassThrough),void 0===i&&(i=new o.PassThrough),void 0===d&&(d=new o.PassThrough);var p=e.call(this)||this;return p.execConfig=t,p.token=n,p.session=r,p.stdOut=a,p.stdErr=i,p.stdIn=d,p.waitForCommandResult=function(){return W(p,void 0,void 0,function(){return $(this,function(e){switch(e.label){case 0:if(void 0===this.currentCommand)throw new Error("No command is running");return[4,this.currentCommand];case 1:return[2,e.sent()]}})})},p.sendInputToCurrentCommand=function(e){return W(p,void 0,void 0,function(){var t;return $(this,function(n){
|
|
166
|
+
if(void 0===this.currentCommand||void 0===this.clientStream)throw new Error("No command is running");return null===(t=this.clientStream)||void 0===t||t.write(this.constructPayloadPacket(e)),[2]})})},p.resizeTerminal=function(e){return W(p,void 0,void 0,function(){var t,n;return $(this,function(r){if(void 0===this.currentCommand||void 0===this.clientStream)throw new Error("No command is running, can't resize terminal");return t={type:"resize",data:{ttyRows:null==e?void 0:e.rows,ttyColumns:null==e?void 0:e.columns}},null===(n=this.clientStream)||void 0===n||n.write("".concat(JSON.stringify(t),"\n")),[2]})})},p.getHashingKey=function(){var e;return p.execConfig.entityId+(null!==(e=p.execConfig.instanceName)&&void 0!==e?e:"na")},p.constructPayloadPacket=function(e){return"".concat(JSON.stringify({type:"payload",data:e.toString()}),"\n")},p.stdInEndPacket="".concat(JSON.stringify({type:"stdInEnd"}),"\n"),p}return z(t,e),t.prototype.start=function(){return W(this,void 0,void 0,function(){
|
|
167
|
+
var e=this;return $(this,function(t){if(void 0!==this.currentCommand)throw new Error("Command is already running");return this.currentCommand=new Promise(function(t,n){var r,o,a;if(void 0===e.clientStream){var i,d=!1,p=function(t){d?e.listenerCount("error")>0&&e.emit("error",new Error(t)):(d=!0,e.listenerCount("error")>0&&e.emit("error",new Error(t)),e.reset(),n(new Error(t)))};try{var l=e.session.request({":method":"POST",":path":"/exec","content-type":"application/x-ndjson","x-target-key":e.getHashingKey()});e.clientStream=l,l.on("error",function(e){p("session error: ".concat(e.message))})}catch(e){return void p("Failed to establish connection to command execution proxy: ".concat(e.message))}e.stdIn.on("data",function(t){var n;(null===(n=e.clientStream)||void 0===n?void 0:n.writable)&&e.clientStream.write(e.constructPayloadPacket(t))}),e.stdIn.on("end",function(){var t;(null===(t=e.clientStream)||void 0===t?void 0:t.writable)&&e.clientStream.write(e.stdInEndPacket)})
|
|
168
|
+
;var s=function(t){var n,r,o,a,d;switch(null==t?void 0:t.type){case"init":var l=t.data;"successful"!==l.auth?p("Command initialization failed: ".concat(null!==(n=null==l?void 0:l.message)&&void 0!==n?n:"Reason unknown")):e.emit("auth-success",l);break;case"completion":i=t.data,e.emit("command-result",i),null===(r=e.clientStream)||void 0===r||r.end(),e.stdOut.end(),e.stdErr.end(),e.stdIn.end();break;case"stdOut":e.emit("std-out-data",t.data),e.stdOut.write(t.data,null===(o=e.execConfig)||void 0===o?void 0:o.encoding);break;case"stdErr":e.emit("std-err-data",t.data),e.stdErr.write(t.data,null===(a=e.execConfig)||void 0===a?void 0:a.encoding);break;case"error":p((null===(d=t.data)||void 0===d?void 0:d.message)||"Unknown error");break;default:var s="Unknown frame type: ".concat(String(null==t?void 0:t.type),"; message: ").concat(JSON.stringify(t));p(s)}},u="";null===(r=e.clientStream)||void 0===r||r.on("data",function(e){var t,n=(u+=e.toString()).split("\n")
|
|
169
|
+
;u=null!==(t=n.pop())&&void 0!==t?t:"";for(var r=0,o=n;r<o.length;r++){var a=o[r];if(a)try{var i=JSON.parse(a);s(i)}catch(e){return void p("Failed to parse message: ".concat(e.message))}}}),null===(o=e.clientStream)||void 0===o||o.on("end",function(){i?d||(d=!0,e.emit("command-completed"),e.reset(),t(i)):d||p("Connection closed before receiving command result")}),null===(a=e.clientStream)||void 0===a||a.on("error",function(e){p("Duplex stream error: ".concat(e.message))}),e.initialAuth(),e.emit("command-started")}else n(Error("Command is already running"))}),[2,this.currentCommand]})})},t.prototype.entityIdField=function(){var e=this.execConfig,t=e.entityType,n=e.entityId;switch(t){case"service":return{serviceId:n};case"job":return{jobId:n};case"addon":return{addonId:n};case"build":return{buildId:n}}},t.prototype.initialAuth=function(){
|
|
170
|
+
var e,t=this.execConfig,n=t.command,r=t.containerName,o=t.instanceName,a=t.shell,i=t.user,d=this.execConfig,p=d.group,l=d.encoding,s=d.tty,u=d.ttyColumns,m=d.ttyRows,c={type:"init",data:{auth:{type:"apiToken",apiToken:this.token},context:J(J({projectId:this.execConfig.projectId},this.entityIdField()),{instanceName:o,containerName:r,command:n,shell:a,user:i,group:p,encoding:l,tty:s,ttyColumns:u,ttyRows:m})}};null===(e=this.clientStream)||void 0===e||e.write("".concat(JSON.stringify(c),"\n"))},t.prototype.reset=function(){var e;this.currentCommand=void 0,null===(e=this.clientStream)||void 0===e||e.destroy(),this.clientStream=void 0},t}(t),ci=["us","eu","asia"],vi=function(){function e(e,t,n){var r=this;this.contextProvider=e,this.agent=t,this.sessionRegistry={},this.assertStartedWithNodejs=function(){if(!Ro)throw new Error("Command exec only possible when started with nodejs")},null==n||n.forEach(function(e){r.http2Session({execLocationHint:e})})}
|
|
171
|
+
return e.prototype.http2Session=function(e){var t,n=this,r=function(){if(e.execLocationHint){var t=e.execLocationHint;if(!ci.includes(t))throw new Error("execLocationHint (".concat(t,") not valid. Must be one of [").concat(ci.join(","),"]."));var r=n.contextProvider.getCurrentBaseUrl(!0);return o=t,r.replace(/\/\/api\./,"//api-exec-".concat(o,"."))}if(e.execLocationOverride)return e.execLocationOverride;var o;throw new Error("Invalid exec location"+JSON.stringify(e))}();if(null===(t=this.sessionRegistry)||void 0===t?void 0:t[r])return this.sessionRegistry[r];var o="".concat(r,"/exec"),a=A(o);return this.sessionRegistry[r]=a,a},e.prototype.execServiceCommand=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){return n=e.serviceId,r=e.projectId,o=e.teamId,a=J({teamId:o,projectId:r,entityId:n,entityType:"service"},t),[2,this.execCommand(a)]})})},e.prototype.execServiceSession=function(e,t,n){return W(this,void 0,void 0,function(){var r,o,a,i
|
|
172
|
+
;return $(this,function(d){switch(d.label){case 0:return r=e.serviceId,o=e.projectId,a=e.teamId,i=J({teamId:a,projectId:o,entityId:r,entityType:"service"},t),[4,this.shellSession(i,n)];case 1:return[2,d.sent()]}})})},e.prototype.execJobCommand=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){return n=e.jobId,r=e.projectId,o=e.teamId,a=J({teamId:o,projectId:r,entityId:n,entityType:"job"},t),[2,this.execCommand(a)]})})},e.prototype.execJobSession=function(e,t,n){return W(this,void 0,void 0,function(){var r,o,a,i;return $(this,function(d){switch(d.label){case 0:return r=e.jobId,o=e.projectId,a=e.teamId,i=J({teamId:a,projectId:o,entityId:r,entityType:"job"},t),[4,this.shellSession(i,n)];case 1:return[2,d.sent()]}})})},e.prototype.execAddonCommand=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){return n=e.addonId,r=e.projectId,o=e.teamId,a=J({teamId:o,projectId:r,entityId:n,entityType:"addon"},t),
|
|
173
|
+
[2,this.execCommand(a)]})})},e.prototype.execAddonSession=function(e,t,n){return W(this,void 0,void 0,function(){var r,o,a,i;return $(this,function(d){switch(d.label){case 0:return r=e.addonId,o=e.projectId,a=e.teamId,i=J({teamId:a,projectId:o,entityId:r,entityType:"addon"},t),[4,this.shellSession(i,n)];case 1:return[2,d.sent()]}})})},e.prototype.execCommand=function(e){return W(this,void 0,void 0,function(){var t,n,r,o,a;return $(this,function(i){switch(i.label){case 0:this.assertStartedWithNodejs(),t=this.getCommandRunner(J({shell:"none"},e)),n=new Do,r=new Do,i.label=1;case 1:return i.trys.push([1,3,,4]),t.stdOut.pipe(n),t.stdErr.pipe(r),o=new Promise(function(e,n){t.once("error",function(e){n(new Error("".concat(e.message||e)))})}),[4,Promise.race([t.start(),o])];case 2:return[2,{commandResult:i.sent(),stdOut:n.getContentsAsString(),stdErr:r.getContentsAsString()}];case 3:throw a=i.sent(),t.stdOut.unpipe(n),t.stdErr.unpipe(r),
|
|
174
|
+
new Error("Command execution failed: ".concat(a instanceof Error?a.message:String(a)));case 4:return[2]}})})},e.prototype.shellSession=function(e,t){return W(this,void 0,void 0,function(){var n,r;return $(this,function(o){switch(o.label){case 0:return this.assertStartedWithNodejs(),n=this.getCommandRunner(e),r=new Promise(function(e,r){n.once("auth-success",function(n){var r;null==t||t(null!==(r=null==n?void 0:n.context)&&void 0!==r?r:{}),e()}),n.once("error",function(e){r(new Error("Shell session failed: ".concat(e.message||e)))});var o=setTimeout(function(){r(new Error("Shell session timed out waiting for auth-success"))},3e4);n.once("auth-success",function(){return clearTimeout(o)})}),n.start().catch(function(){}),[4,r];case 1:return o.sent(),[2,n]}})})},e.prototype.getCommandRunner=function(e){var t=this.contextProvider.getCurrentBaseUrl(!0),n=this.contextProvider.getCurrentToken();if(!n)throw Error("API token not found");var r=e.execLocationHint,o=e.execLocationOverride
|
|
175
|
+
;return o?new mi(J({shell:"none"},e),n,this.http2Session({execLocationOverride:o})):r?new mi(J({shell:"none"},e),n,this.http2Session({execLocationHint:r})):new ui(t,e,n,this.agent)},e}(),hi=Object.defineProperty,fi="object"==typeof process&&process?process:{stdout:null,stderr:null
|
|
176
176
|
},Ii=e=>!!e&&"object"==typeof e&&(e instanceof td||e instanceof a||wi(e)||gi(e)),wi=e=>!!e&&"object"==typeof e&&e instanceof k&&"function"==typeof e.pipe&&e.pipe!==a.Writable.prototype.pipe,gi=e=>!!e&&"object"==typeof e&&e instanceof k&&"function"==typeof e.write&&"function"==typeof e.end,bi=Symbol("EOF"),yi=Symbol("maybeEmitEnd"),Ri=Symbol("emittedEnd"),ji=Symbol("emittingEnd"),Ui=Symbol("emittedError"),Ci=Symbol("closed"),Ei=Symbol("read"),_i=Symbol("flush"),Si=Symbol("flushChunk"),Ni=Symbol("encoding"),Ai=Symbol("decoder"),ki=Symbol("flowing"),Pi=Symbol("paused"),Ti=Symbol("resume"),Di=Symbol("buffer"),Oi=Symbol("pipes"),xi=Symbol("bufferLength"),Li=Symbol("bufferPush"),qi=Symbol("bufferShift"),Bi=Symbol("objectMode"),Vi=Symbol("destroyed"),Fi=Symbol("error"),Mi=Symbol("emitData"),Gi=Symbol("emitEnd"),zi=Symbol("emitEnd2"),Ji=Symbol("async"),Wi=Symbol("abort"),$i=Symbol("aborted"),Hi=Symbol("signal"),Zi=Symbol("dataListeners"),Yi=Symbol("discarded"),Ki=e=>Promise.resolve().then(e),Xi=e=>e(),Qi=class{
|
|
177
177
|
src;dest;opts;ondrain;constructor(e,t,n){this.src=e,this.dest=t,this.opts=n,this.ondrain=()=>e[Ti](),this.dest.on("drain",this.ondrain)}unpipe(){this.dest.removeListener("drain",this.ondrain)}proxyErrors(e){}end(){this.unpipe(),this.opts.end&&this.dest.end()}},ed=class extends Qi{unpipe(){this.src.removeListener("error",this.proxyErrors),super.unpipe()}constructor(e,t,n){super(e,t,n),this.proxyErrors=e=>this.dest.emit("error",e),e.on("error",this.proxyErrors)}},td=class extends k{[ki]=!1;[Pi]=!1;[Oi]=[];[Di]=[];[Bi];[Ni];[Ji];[Ai];[bi]=!1;[Ri]=!1;[ji]=!1;[Ci]=!1;[Ui]=null;[xi]=0;[Vi]=!1;[Hi];[$i]=!1;[Zi]=0;[Yi]=!1;writable=!0;readable=!0;constructor(...e){let t=e[0]||{};if(super(),t.objectMode&&"string"==typeof t.encoding)throw new TypeError("Encoding and objectMode may not be used together");t.objectMode?(this[Bi]=!0,this[Ni]=null):(e=>!e.objectMode&&!!e.encoding&&"buffer"!==e.encoding)(t)?(this[Ni]=t.encoding,this[Bi]=!1):(this[Bi]=!1,this[Ni]=null),this[Ji]=!!t.async,
|
|
178
178
|
this[Ai]=this[Ni]?new P(this[Ni]):null,t&&!0===t.debugExposeBuffer&&Object.defineProperty(this,"buffer",{get:()=>this[Di]}),t&&!0===t.debugExposePipes&&Object.defineProperty(this,"pipes",{get:()=>this[Oi]});let{signal:n}=t;n&&(this[Hi]=n,n.aborted?this[Wi]():n.addEventListener("abort",()=>this[Wi]()))}get bufferLength(){return this[xi]}get encoding(){return this[Ni]}set encoding(e){throw new Error("Encoding must be set at instantiation time")}setEncoding(e){throw new Error("Encoding must be set at instantiation time")}get objectMode(){return this[Bi]}set objectMode(e){throw new Error("objectMode must be set at instantiation time")}get async(){return this[Ji]}set async(e){this[Ji]=this[Ji]||!!e}[Wi](){this[$i]=!0,this.emit("abort",this[Hi]?.reason),this.destroy(this[Hi]?.reason)}get aborted(){return this[$i]}set aborted(e){}write(e,t,n){if(this[$i])return!1;if(this[bi])throw new Error("write after end")
|
|
@@ -264,38 +264,39 @@ q.open(e.file,a,i)):d||!p?o(d):void q.fstat(p,(a,i)=>{if(a)return q.close(p,()=>
|
|
|
264
264
|
"undefined"!=typeof process&&(process.env&&process.env.IGNORE_TEST_WIN32||"win32"===process.platform)){const e=e=>/^\\\\\?\\/.test(e)||/["<>|\u0000-\u001F]+/u.test(e)?e:e.replace(/\\/g,"/");I.convert=e;const t=/^[a-z]:\//i;I.isNotRelative=e=>t.test(e)||w(e)}return Lu}(),Mu=ur(Fu);!function(e){e.DIRECTORY_UPLOAD="directory-upload",e.FILE_UPLOAD="file-upload",e.DIRECTORY_DOWNLOAD="directory-download",e.FILE_DOWNLOAD="file-download"}(Vu||(Vu={}));var Gu,zu=function(){function e(e,t){var n=this;if(this.exec=e,this.parameters=t,this.defaultEncoding="base64",this.getFileIgnoreFilter=function(e){if(void 0!==e){var t=Mu({allowRelativePaths:!0}).add(e);return function(e){return!t.ignores(e)}}},this.getTarTransformFn=function(e,t){return function(n){n.path=n.path.replace(e,t)}},this.ensureDirRemote=function(e){return W(n,void 0,void 0,function(){var t,n,r;return $(this,function(o){switch(o.label){case 0:return t=["mkdir","-p",e],[4,this.runCommand(t)];case 1:if(n=o.sent(),
|
|
265
265
|
"Success"!==(null===(r=null==n?void 0:n.commandResult)||void 0===r?void 0:r.status))throw new Error("Failed creating remote directory.");return[2]}})})},this.ensureTarCmd=function(){return W(n,void 0,void 0,function(){var e,t,n;return $(this,function(r){switch(r.label){case 0:return e=["tar","--version"],[4,this.runCommand(e)];case 1:if(t=r.sent(),"Success"!==(null===(n=null==t?void 0:t.commandResult)||void 0===n?void 0:n.status))throw new Error("Tar command not found on remote container. Required for file copy.");return[2]}})})},this.pathExistsRemote=function(e){return W(n,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=["test","-e",e],[4,this.runCommand(t)];case 1:return[2,0===n.sent().commandResult.exitCode]}})})},this.checkIsDirRemote=function(e){return W(n,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=["test","-d",e],[4,this.runCommand(t)];case 1:return[2,0===n.sent().commandResult.exitCode]}})})},
|
|
266
266
|
this.checkIsFileRemote=function(e){return W(n,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return t=["test","-e",e],[4,this.runCommand(t)];case 1:return[2,0===n.sent().commandResult.exitCode]}})})},this.runCommand=function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r];return W(n,H([e],t,!0),void 0,function(e,t){var n,r,o,a,i,d,p,l,s,u,m,c;return void 0===t&&(t="none"),$(this,function(v){switch(v.label){case 0:return r=(n=this).exec,o=n.parameters,a=o.teamId,i=o.projectId,d=o.resourceId,p=o.resourceType,l=o.containerName,s=o.instanceName,u=o.execLocationHint,m={command:e,shell:t,containerName:l,instanceName:s,execLocationHint:u},"service"!==p?[3,2]:[4,r.execServiceCommand({teamId:a,projectId:i,serviceId:d},m)];case 1:return c=v.sent(),[3,4];case 2:return[4,r.execJobCommand({teamId:a,projectId:i,jobId:d},m)];case 3:c=v.sent(),v.label=4;case 4:return[2,c]}})})},this.runSession=function(e){return W(n,void 0,void 0,function(){
|
|
267
|
-
var t,n,r,o,a,i,d,p,l,s,u;return $(this,function(
|
|
268
|
-
;return r=b.lstatSync(e).isFile(),o=r?y.dirname(e):e,a=r?y.basename(e):".",i=r&&void 0!==t&&""!==y.extname(t),d=i?y.dirname(t):null!=t?t:o,p=void 0!==t?y.basename(t):a,l=Ns({gzip
|
|
269
|
-
targetDirectory:d}]}})})},e.prototype.uploadStream=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a,
|
|
270
|
-
case 0:return(r=void 0===e)?[3,2]:[4,this.pathExistsRemote(e)];case 1:r=!I.sent(),I.label=2;case 2:if(r)throw new Error("Remote path '".concat(e,"' does not exists but is required for downloads."));return[4,this.checkIsDirRemote(e)];case 3:return o=I.sent(),a=o?e:y.dirname(e),i=o?".":y.basename(e),d=void 0!==t&&""!==y.extname(t),p=!o&&d?y.basename(t):i,(l=void 0!==t?d?y.dirname(t):t:".")&&b.mkdirSync(l,{recursive:!0}),s=Po(null!=n?n:[]).map(function(e){return"--exclude=".concat(e)}),u=H(H(["tar","-zcf","-"],["--no-same-owner"],!0),s,!0),m=H(H([],u,!0),["-C",a,i],!1),[4,this.runSession(m)];case 4:
|
|
271
|
-
;return o?[2,{type:Vu.DIRECTORY_DOWNLOAD,sourceDirectory:a,targetDirectory:l}]:[2,{type:Vu.FILE_DOWNLOAD,sourceDirectory:a,sourceFile:i,targetDirectory:l,targetFile:p}]}})})},e.prototype.downloadStream=function(e){return W(this,void 0,void 0,function(){var t,n,r,o;return $(this,function(a){switch(a.label){case 0:return[4,this.checkIsFileRemote(e)];case 1:if(!a.sent())throw new Error("Remote path '".concat(e,"' must be a file."));return t=y.dirname(e),[4,this.ensureTarCmd()];case 2:return a.sent(),[4,this.ensureDirRemote(t)];case 3:return a.sent(),n=["cat",e],[4,this.runSession(n)];case 4:
|
|
272
|
-
|
|
273
|
-
return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.serviceId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,resourceType:"service"},[4,
|
|
274
|
-
|
|
275
|
-
containerName:t.containerName,execLocationHint:t.execLocationHint})),o=H(H([],null!==(a=t.ignoreList)&&void 0!==a?a:[],!0),this.stdIgnoreList,!0),n){case"download":return[3,1];case"upload":return[3,3]}return[3,5];case 1:return[4,r.downloadFiles(t.remotePath,t.localPath,o)];case 2:case 4:return[2,i.sent()];case 3:return[4,r.uploadFiles(t.localPath,t.remotePath,o)];case 5:return[2]}})})},e}(),Wu=function(e){function t(t){var n=this.constructor,r=e.call(this,t.message)||this;r.name="NorthflankApiCallError",r.message=t.message,r.status=t.status,r.id=t.id,r.details=t.details;var o=n.prototype
|
|
276
|
-
a.stop=function(){return W(a,void 0,void 0,function(){var e;return $(this,function(t){if(void 0===this.logSession)throw new Error("No command is running");return null===(e=this.remote)||void 0===e||e.close(),[2]})})},a}return z(t,e),t.getLogsEndpoint=function(e){
|
|
277
|
-
void 0!==
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
var e=JSON.parse(b.readFileSync(y.join(y.dirname(u(import.meta.url)),"../../package.json")).toString());$u=null==e?void 0:e.version}catch(e){$u=void 0}return $u},Xu=function(){function e(e,t){var n=this;this.opts=t,this.call=function(e){return W(n,void 0,void 0,function(){return $(this,function(t){return[2,this.executeCall(e)]})})},this.contextProvider=e}return e.prototype.getDefaultHeaders=function(){
|
|
281
|
-
|
|
282
|
-
;return t.method="get",t.body=function(){},t}return z(t,e),t}(Xu),em=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.all=function(e){return W(t,void 0,void 0,function(){return $(this,function(t){return[2,new am(this,e).getAll()]})})},t.call=function(n){return W(t,void 0,void 0,function(){var t,r=this;return $(this,function(o){switch(o.label){case 0:
|
|
283
|
-
|
|
284
|
-
var e,t,
|
|
285
|
-
rawResponse:null===(i=e[0])||void 0===i?void 0:i.rawResponse}]}})})},e}(),im=function(e){return new Promise(function(t){setTimeout(function(){t()},e)})},dm=function(e,t,n,r){return void 0===t&&(t={}),void 0===n&&(n=3),void 0===r&&(r=500),new Promise(function(o,a){var i=function(n){return jo(e,t).then(function(e){o(e)}).catch(function(e){return W(void 0,void 0,void 0,function(){
|
|
286
|
-
return
|
|
287
|
-
}),"
|
|
288
|
-
|
|
289
|
-
teamId:t.teamId},[2,this.logTail(r,null!=n?n:{},"
|
|
290
|
-
entityId:t.addonId,projectId:t.projectId},o={backupId:t.backupId,restoreId:t.restoreId},[2,this.logTail(r,J(J({},n),o),"addonRestore")]})})},this.logTail=function(e,t,r){return W(n,void 0,void 0,function(){var n,o,a,i,d,p;return $(this,function(l){if(n=e.entityId,o=e.projectId,a=e.teamId,i=J({queryType:"tail",teamId:a,projectId:o,entityId:n,entityType:r},t),this.assertStartedWithNodejs(),
|
|
291
|
-
var t=e.teamId,n=e.projectId,r=e.entityId,o=e.entityType,a=e.deploymentId,i=e.runId,d=e.buildId,p=e.isBuild,l=e.queryType,s=e.metricTypes,u=e.startTime,m=e.endTime,c=e.duration,v=e.containerName,h=e.timestamp,f=void 0!==t?"teams/".concat(t,"/"):"",I="/v1/".concat(f,"projects/").concat(n,"/");var w=new URLSearchParams;return w.append("queryType",l),void 0!==u&&w.append("startTime",u.toISOString()),
|
|
292
|
-
throw new Error("Unexpected Northflank entity type received in metrics endpoint generation: ".concat(o))}}(),"?").concat(w.toString())},t.body=function(){},t}return z(t,e),t}(Qu),um=function(e){return{metadata:e.metadata,data:e.data.map(function(e){return{value:e.value,ts:new Date(e.ts)}})}};!function(e){e.Cpu="cpu",e.Memory="memory",e.NetworkIngress="networkIngress",e.NetworkEgress="networkEgress",
|
|
293
|
-
|
|
294
|
-
o=t.projectId,a=t.teamId,i={entityId:r,projectId:o,teamId:a},[2,this.metricsSingle(i,null!=n?n:{},"
|
|
295
|
-
return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.
|
|
296
|
-
queryType:"range"}),[2,this.getMetrics(i)]})})},this.getMetrics=function(e){return W(t,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return[4,new sm(this.contextProvider,{}).call(e)];case 1:return(t=n.sent()).error?[2,t]:[2,J(J({},t),{data:Object.fromEntries(Object.entries(t.data).map(function(e){var t=e[0],n=e[1];return[t,J(J({},n),{values:n.values.map(um)})]}))})]}})})}
|
|
297
|
-
|
|
298
|
-
|
|
267
|
+
var t,n,r,o,a,i,d,p,l,s,u,m;return $(this,function(c){switch(c.label){case 0:return n=(t=this).exec,r=t.parameters,o=r.teamId,a=r.projectId,i=r.resourceId,d=r.resourceType,p=r.containerName,l=r.instanceName,s=r.execLocationHint,u={command:e,shell:"none",tty:!1,encoding:this.defaultEncoding,containerName:p,instanceName:l,execLocationHint:s},"service"!==d?[3,2]:[4,n.execServiceSession({teamId:o,projectId:a,serviceId:i},u)];case 1:return m=c.sent(),[3,4];case 2:return[4,n.execJobSession({teamId:o,projectId:a,jobId:i},u)];case 3:m=c.sent(),c.label=4;case 4:return[2,m]}})})},!["service","job"].includes(t.resourceType))throw new Error("Invalid resource type: ".concat(t.resourceType,", only 'service' and 'job' supported"))}return e.prototype.uploadFiles=function(e,t,n){return W(this,void 0,void 0,function(){var r,o,a,i,d,p,l,s,u,m,c,v;return $(this,function(h){switch(h.label){case 0:
|
|
268
|
+
if(void 0===e||!b.existsSync(e))throw new Error("Local path '".concat(e,"' does not exists but is required for uploads."));return r=b.lstatSync(e).isFile(),o=r?y.dirname(e):e,a=r?y.basename(e):".",i=r&&void 0!==t&&""!==y.extname(t),d=i?y.dirname(t):null!=t?t:o,p=void 0!==t?y.basename(t):a,l=Ns({gzip:{encoding:this.defaultEncoding},cwd:o,filter:this.getFileIgnoreFilter(n),preservePaths:!0,onWriteEntry:i?this.getTarTransformFn(a,p):void 0},Po(a)),[4,this.ensureTarCmd()];case 1:return h.sent(),[4,this.ensureDirRemote(d)];case 2:return h.sent(),s=H(H(["tar","-xzvf","-"],["--no-same-owner"],!0),["-C",d],!1),[4,this.runSession(s)];case 3:return u=h.sent(),m=new Do,c=new Do,u.stdErr.pipe(m),u.stdOut.pipe(c),l.pipe(u.stdIn),[4,u.waitForCommandResult()];case 4:if("Success"!==(null==(v=h.sent())?void 0:v.status))throw new Error("Failed to upload file to container: ".concat(null==v?void 0:v.message,", error details: ").concat(m.getContentsAsString(),"; ").concat(c.getContentsAsString()))
|
|
269
|
+
;return r?[2,{type:Vu.FILE_UPLOAD,sourceDirectory:o,sourceFile:a,targetDirectory:d,targetFile:p}]:[2,{type:Vu.DIRECTORY_UPLOAD,sourceDirectory:o,targetDirectory:d}]}})})},e.prototype.uploadStream=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a,p,l,s;return $(this,function(u){switch(u.label){case 0:return n=function(e){var t=new i({transform:function(e,t,n){this.push(e.toString("base64")),n()}}),n="string"==typeof e,r=Buffer.isBuffer(e);return n||r?d.from(e).pipe(t):e.pipe(t)},r=y.dirname(t),[4,this.ensureTarCmd()];case 1:return u.sent(),[4,this.ensureDirRemote(r)];case 2:return u.sent(),o=["tee",t],[4,this.runSession(o)];case 3:return a=u.sent(),p=new Do,l=new Do,a.stdErr.pipe(p),a.stdOut.pipe(l),n(e).pipe(a.stdIn),[4,a.waitForCommandResult()];case 4:return s=u.sent(),[4,this.runCommand(["cat",t])];case 5:if(u.sent(),
|
|
270
|
+
"Success"!==(null==s?void 0:s.status))throw new Error("Failed to upload file to container: ".concat(null==s?void 0:s.message,", error details: ").concat(p.getContentsAsString(),"; ").concat(l.getContentsAsString()));return[2]}})})},e.prototype.downloadFiles=function(e,t,n){return W(this,void 0,void 0,function(){var r,o,a,i,d,p,l,s,u,m,c,v,h,f;return $(this,function(I){switch(I.label){case 0:return(r=void 0===e)?[3,2]:[4,this.pathExistsRemote(e)];case 1:r=!I.sent(),I.label=2;case 2:if(r)throw new Error("Remote path '".concat(e,"' does not exists but is required for downloads."));return[4,this.checkIsDirRemote(e)];case 3:return o=I.sent(),a=o?e:y.dirname(e),i=o?".":y.basename(e),d=void 0!==t&&""!==y.extname(t),p=!o&&d?y.basename(t):i,(l=void 0!==t?d?y.dirname(t):t:".")&&b.mkdirSync(l,{recursive:!0}),s=Po(null!=n?n:[]).map(function(e){return"--exclude=".concat(e)}),u=H(H(["tar","-zcf","-"],["--no-same-owner"],!0),s,!0),m=H(H([],u,!0),["-C",a,i],!1),[4,this.runSession(m)];case 4:
|
|
271
|
+
return c=I.sent(),v=Pu({cwd:l,gzip:{encoding:this.defaultEncoding},onReadEntry:p?this.getTarTransformFn(i,p):void 0}),h=new Do,c.stdErr.pipe(h),c.stdOut.pipe(v),[4,c.waitForCommandResult()];case 5:if("Success"!==(null==(f=I.sent())?void 0:f.status))throw new Error("Failed to download file from container: ".concat(null==f?void 0:f.message,", error details: ").concat(h.getContentsAsString()));return o?[2,{type:Vu.DIRECTORY_DOWNLOAD,sourceDirectory:a,targetDirectory:l}]:[2,{type:Vu.FILE_DOWNLOAD,sourceDirectory:a,sourceFile:i,targetDirectory:l,targetFile:p}]}})})},e.prototype.downloadStream=function(e){return W(this,void 0,void 0,function(){var t,n,r,o;return $(this,function(a){switch(a.label){case 0:return[4,this.checkIsFileRemote(e)];case 1:if(!a.sent())throw new Error("Remote path '".concat(e,"' must be a file."));return t=y.dirname(e),[4,this.ensureTarCmd()];case 2:return a.sent(),[4,this.ensureDirRemote(t)];case 3:return a.sent(),n=["cat",e],[4,this.runSession(n)];case 4:
|
|
272
|
+
return r=a.sent(),o=new Do,r.stdErr.pipe(o),[2,{fileStream:r.stdOut,completionPromise:r.waitForCommandResult().then(function(e){return 0===e.exitCode})}]}})})},e}(),Ju=function(){function e(e,t){this.exec=e,this.stdIgnoreList=["*.*~"],t&&(this.stdIgnoreList=t)}return e.prototype.downloadServiceFiles=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.serviceId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,resourceType:"service"},[4,this.copy(a,t,"download")];case 1:return[2,i.sent()]}})})},e.prototype.downloadServiceFileStream=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.serviceId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,resourceType:"service"},[4,new zu(this.exec,J(J({},a),{instanceName:t.instanceName,containerName:t.containerName})).downloadStream(t.remotePath)];case 1:return[2,i.sent()]}})})},
|
|
273
|
+
e.prototype.uploadServiceFiles=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.serviceId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,resourceType:"service"},[4,this.copy(a,t,"upload")];case 1:return[2,i.sent()]}})})},e.prototype.uploadServiceFileStream=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.serviceId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,resourceType:"service"},[4,new zu(this.exec,J(J({},a),{instanceName:t.instanceName,containerName:t.containerName})).uploadStream(t.source,t.remotePath)];case 1:return[2,i.sent()]}})})},e.prototype.downloadJobFiles=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.jobId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,resourceType:"job"},
|
|
274
|
+
[4,this.copy(a,t,"download")];case 1:return[2,i.sent()]}})})},e.prototype.downloadJobFileStream=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.jobId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,resourceType:"job"},[4,new zu(this.exec,J(J({},a),{instanceName:t.instanceName,containerName:t.containerName})).downloadStream(t.remotePath)];case 1:return[2,i.sent()]}})})},e.prototype.uploadJobFiles=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.jobId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,resourceType:"job"},[4,this.copy(a,t,"upload")];case 1:return[2,i.sent()]}})})},e.prototype.uploadJobFileStream=function(e,t){return W(this,void 0,void 0,function(){var n,r,o,a;return $(this,function(i){switch(i.label){case 0:return n=e.jobId,r=e.projectId,o=e.teamId,a={teamId:o,projectId:r,resourceId:n,
|
|
275
|
+
resourceType:"job"},[4,new zu(this.exec,J(J({},a),{instanceName:t.instanceName,containerName:t.containerName})).uploadStream(t.source,t.remotePath)];case 1:return[2,i.sent()]}})})},e.prototype.copy=function(e,t,n){return W(this,void 0,void 0,function(){var r,o,a;return $(this,function(i){switch(i.label){case 0:switch(r=new zu(this.exec,J(J({},e),{instanceName:t.instanceName,containerName:t.containerName,execLocationHint:t.execLocationHint})),o=H(H([],null!==(a=t.ignoreList)&&void 0!==a?a:[],!0),this.stdIgnoreList,!0),n){case"download":return[3,1];case"upload":return[3,3]}return[3,5];case 1:return[4,r.downloadFiles(t.remotePath,t.localPath,o)];case 2:case 4:return[2,i.sent()];case 3:return[4,r.uploadFiles(t.localPath,t.remotePath,o)];case 5:return[2]}})})},e}(),Wu=function(e){function t(t){var n=this.constructor,r=e.call(this,t.message)||this;r.name="NorthflankApiCallError",r.message=t.message,r.status=t.status,r.id=t.id,r.details=t.details;var o=n.prototype
|
|
276
|
+
;return Object.setPrototypeOf?Object.setPrototypeOf(r,o):r.__proto__=o,r}return z(t,e),t}(Error);!function(e){e.CDN="cdn",e.Mesh="mesh",e.Ingress="ingress",e.Runtime="runtime"}(Gu||(Gu={}));var $u,Hu,Zu=function(e){return{containerId:e.containerId,log:e.log,ts:new Date(e.ts)}},Yu=function(e){function t(t,n,r,o){var a=e.call(this)||this;return a.baseUrl=t,a.logsConfig=n,a.token=r,a.agent=o,a.stop=function(){return W(a,void 0,void 0,function(){var e;return $(this,function(t){if(void 0===this.logSession)throw new Error("No command is running");return null===(e=this.remote)||void 0===e||e.close(),[2]})})},a}return z(t,e),t.getLogsEndpoint=function(e){
|
|
277
|
+
var t=e.containerName,n=e.types,r=e.entityId,o=e.entityType,a=e.buildId,i=e.runId,d=e.backupId,p=e.restoreId,l=e.deploymentId,s=e.isBuild,u=e.lineLimit,m=e.teamId,c=e.projectId,v=e.queryType,h=e.startTime,f=e.endTime,I=e.duration,w=e.direction,g=e.textIncludes,b=e.textNotIncludes,y=e.regexIncludes,R=e.regexNotIncludes,j=void 0!==m?"teams/".concat(m,"/"):"",U="/v1/".concat(j,"projects/").concat(c,"/"),C=new URLSearchParams;return C.append("queryType",v),void 0!==h&&C.append("startTime",h.toISOString()),void 0!==f&&C.append("endTime",f.toISOString()),void 0!==u&&C.append("lineLimit",u.toString()),void 0!==t&&C.append("containerName",t),void 0!==l&&C.append("deploymentId",l),void 0!==i&&C.append("runId",i),void 0!==a&&C.append("buildId",a),void 0!==g&&C.append("textIncludes",g),void 0!==b&&C.append("textNotIncludes",b),void 0!==y&&C.append("regexIncludes",y),void 0!==R&&C.append("regexNotIncludes",R),void 0!==w&&C.append("direction",w),void 0!==I&&C.append("duration",I.toString()),
|
|
278
|
+
void 0!==n&&n.forEach(function(e){return C.append("type",e)}),"".concat(U).concat(function(){var e=s?"/build-logs":"/logs";switch(o){case"service":return"services/".concat(r).concat(e);case"job":return"jobs/".concat(r).concat(e);case"addon":return"addons/".concat(r).concat(e);case"addonBackup":return"addons/".concat(r,"/backups/").concat(d).concat(e);case"addonRestore":return"addons/".concat(r,"/backups/").concat(d,"/restores/").concat(p).concat(e);default:throw new Error("Unexpected Northflank entity type received in logs endpoint generation: ".concat(o))}}(),"?").concat(C.toString())},Object.defineProperty(t.prototype,"logsEndpoint",{get:function(){return"".concat(this.baseUrl).concat(t.getLogsEndpoint(this.logsConfig))},enumerable:!1,configurable:!0}),t.prototype.start=function(){return W(this,void 0,void 0,function(){var e=this;return $(this,function(t){switch(t.label){case 0:if(void 0!==this.logSession)throw new Error("Command is already running")
|
|
279
|
+
;return this.logSession=new Promise(function(t,n){var r,o,a,i;void 0!==e.remote&&n(Error("Command is already running"));var d=e.logsEndpoint.replace("https:","wss:").replace("http:","ws:");e.remote=new ii(d,{agent:e.agent}),null===(r=e.remote)||void 0===r||r.on("message",function(t){var n,r,o=JSON.parse(t.toString());switch(null==o?void 0:o.type){case"init":var a=o.data;"successful"!==a.auth&&p("Log tail initialization failed: ".concat(null!==(n=null==a?void 0:a.message)&&void 0!==n?n:"Reason unknown"));break;case"log-lines":var i=o.data;e.emit("logs-received",i.map(Zu));break;case"error":p(null===(r=o.data)||void 0===r?void 0:r.message);break;default:var d="unable to parse message: ".concat(JSON.stringify(o));p(d)}}),null===(o=e.remote)||void 0===o||o.on("close",function(){e.emit("close"),e.reset(),t()}),null===(a=e.remote)||void 0===a||a.on("open",function(){e.emit("open")}),null===(i=e.remote)||void 0===i||i.on("error",function(n){e.emit("error",n),e.reset(),t()});var p=function(t){
|
|
280
|
+
e.emit("error",{message:t}),e.reset(),n(new Error(t))}}),[4,new Promise(function(t){var n;e.remote.on("open",function(){return t()}),null===(n=e.remote)||void 0===n||n.on("error",function(){t()})})];case 1:return t.sent(),this.initialAuth(),[2,this.logSession]}})})},t.prototype.initialAuth=function(){var e,t={type:"init",data:{auth:{type:"apiToken",apiToken:this.token}}};null===(e=this.remote)||void 0===e||e.send(JSON.stringify(t))},t.prototype.reset=function(){this.remote=void 0,this.logSession=void 0},t}(t),Ku=function(){if(void 0!==$u)return $u;if(Ro)try{var e=JSON.parse(b.readFileSync(y.join(y.dirname(u(import.meta.url)),"../../package.json")).toString());$u=null==e?void 0:e.version}catch(e){$u=void 0}return $u},Xu=function(){function e(e,t){var n=this;this.opts=t,this.call=function(e){return W(n,void 0,void 0,function(){return $(this,function(t){return[2,this.executeCall(e)]})})},this.contextProvider=e}return e.prototype.getDefaultHeaders=function(){
|
|
281
|
+
var e,t=this.contextProvider.getCurrentToken(),n=(null===(e=this.opts)||void 0===e?void 0:e.customUserAgent)?" (".concat(this.opts.customUserAgent,")"):"";return{Authorization:this.withAuth?"Bearer ".concat(t):void 0,"Content-Type":"application/json","User-Agent":"northflank-js-client/".concat(Ku()).concat(n)}},e.prototype.executeCall=function(e){return W(this,void 0,void 0,function(){var t,n,r,o,a,i,d,p,l,s,u,m,c,v=this;return $(this,function(h){switch(h.label){case 0:if(t=this.method,n=this.opts.agent,r={method:t,headers:this.getDefaultHeaders(),agent:n},!(o=null===(c=this.contextProvider)||void 0===c?void 0:c.getCurrentBaseUrl()))throw new Error("Api client context not correctly initialized, please provide a url to the context.");return a="".concat(o).concat(this.endpointUrl(e)),i=this.body(e),d=J(J({url:a},r),{body:i}),[4,dm(a,J(J({},r),{body:i}))];case 1:return[4,(p=h.sent()).text()];case 2:return l=h.sent(),s=function(){if(200!==p.status){
|
|
282
|
+
var e=null==u?void 0:u.error,t=(null==e?void 0:e.message)||"",n={status:p.status,message:t,id:null==e?void 0:e.id,details:null==e?void 0:e.details};if(v.opts.throwErrorOnHttpErrorCode)throw new Wu(n);return n}},u=function(){try{return JSON.parse(l)}catch(e){throw Error("Failed reading api request result: \n\tStatus: ".concat(p.statusText," (").concat(p.status,")\n\tMessage: ").concat(l))}}(),m=s(),[2,{data:null==u?void 0:u.data,rawResponse:p,request:d,error:m,pagination:null==u?void 0:u.pagination}]}})})},e}(),Qu=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.method="get",t.body=function(){},t}return z(t,e),t}(Xu),em=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.all=function(e){return W(t,void 0,void 0,function(){return $(this,function(t){return[2,new am(this,e).getAll()]})})},t.call=function(n){return W(t,void 0,void 0,function(){var t,r=this;return $(this,function(o){switch(o.label){case 0:
|
|
283
|
+
return[4,e.prototype.executeCall.call(this,n)];case 1:return t=o.sent(),[2,J(J({},t),{pagination:J(J({},t.pagination),{getNextPage:function(){return W(r,void 0,void 0,function(){var e,r,o,a,i,d,p,l=this;return $(this,function(s){return void 0===(null===(d=t.pagination)||void 0===d?void 0:d.cursor)?(e=Object.keys(t.data),r=1===e.length?((i={})[e[0]]=[],i):{},o=J(J({},t),{pagination:J(J({},t.pagination),{count:0}),data:r}),[2,(a=function(e){return J(J({},e),{pagination:J(J({},e.pagination),{getNextPage:function(){return W(l,void 0,void 0,function(){return $(this,function(t){return[2,a(e)]})})}})})})(o)]):[2,new am(this,n,null===(p=t.pagination)||void 0===p?void 0:p.cursor).getNext()]})})}})})]}})})},t}return z(t,e),t}(Qu),tm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.method="post",t}return z(t,e),t}(Xu),nm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.method="delete",t}return z(t,e),t}(Xu),rm=function(e){function t(){
|
|
284
|
+
var t=null!==e&&e.apply(this,arguments)||this;return t.method="put",t}return z(t,e),t}(Xu),om=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.method="patch",t}return z(t,e),t}(Xu),am=function(){function e(e,t,n){void 0===n&&(n=null);var r=this;this.endpoint=e,this.opts=t,this._currentOffset=0,this.hasNext=function(){return void 0!==r.cursor},this.cursor=n}return Object.defineProperty(e.prototype,"currentOffset",{get:function(){return this._currentOffset},enumerable:!1,configurable:!0}),e.prototype.getNext=function(){return W(this,void 0,void 0,function(){var e,t,n,r,o,a,i,d,p;return $(this,function(l){switch(l.label){case 0:return[4,this.endpoint.call(J(J({},this.opts),{options:J(J({},null===(i=this.opts)||void 0===i?void 0:i.options),{cursor:null!==(d=this.cursor)&&void 0!==d?d:void 0})}))];case 1:return e=l.sent(),t=e.data,n=e.request,r=e.error,o=e.pagination,a=e.rawResponse,this.cursor=null==o?void 0:o.cursor,
|
|
285
|
+
this._currentOffset+=null!==(p=null==o?void 0:o.count)&&void 0!==p?p:0,[2,{data:t,request:n,error:r,pagination:o,rawResponse:a}]}})})},e.prototype.getAll=function(){return W(this,void 0,void 0,function(){var e,t,n,r,o,a,i;return $(this,function(d){switch(d.label){case 0:e=[],d.label=1;case 1:return this.hasNext()?[4,this.getNext()]:[3,3];case 2:return(t=d.sent()).error?[2,t]:(e.push(t),[3,1]);case 3:return r=e.flatMap(function(e){var t=Object.keys(e.data);return 1===t.length?(n=t[0],e.data[t[0]]):e.data}),[2,{data:void 0===n?r:(o={},o[n]=r,o),request:null===(a=e[0])||void 0===a?void 0:a.request,rawResponse:null===(i=e[0])||void 0===i?void 0:i.rawResponse}]}})})},e}(),im=function(e){return new Promise(function(t){setTimeout(function(){t()},e)})},dm=function(e,t,n,r){return void 0===t&&(t={}),void 0===n&&(n=3),void 0===r&&(r=500),new Promise(function(o,a){var i=function(n){return jo(e,t).then(function(e){o(e)}).catch(function(e){return W(void 0,void 0,void 0,function(){
|
|
286
|
+
return $(this,function(t){switch(t.label){case 0:return n>0?[4,im(r)]:[3,2];case 1:return t.sent(),[2,i(n-1)];case 2:return[2,a(e)]}})})})};return i(n)})},pm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.description="Fetch log lines over a specific time span",t.withAuth=!0,t.requiredPermissions="Account > Service | Job | Addon > General > Read",t.endpointUrl=function(e){return Yu.getLogsEndpoint(e)},t.body=function(){},t}return z(t,e),t}(Qu),lm=function(e,t){void 0===t&&(t={});var n=this;this.contextProvider=e,this.clientOpts=t,this.getServiceLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r;return $(this,function(o){return t=e.parameters,n=e.options,r={entityId:t.serviceId,projectId:t.projectId,teamId:t.teamId},[2,this.logRange(r,null!=n?n:{},"service")]})})},this.getServiceBuildLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.projectId,o=t.serviceId,
|
|
287
|
+
a=t.teamId,i={entityId:o,projectId:r,teamId:a},[2,this.logRange(i,J(J({},n),{isBuild:!0}),"service")]})})},this.getJobLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r;return $(this,function(o){return t=e.parameters,n=e.options,r={entityId:t.jobId,projectId:t.projectId,teamId:t.teamId},[2,this.logRange(r,null!=n?n:{},"job")]})})},this.getJobBuildLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.projectId,o=t.jobId,a=t.teamId,i={entityId:o,projectId:r,teamId:a},[2,this.logRange(i,J(J({},n),{isBuild:!0}),"job")]})})},this.getAddonLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r;return $(this,function(o){return t=e.parameters,n=e.options,r={entityId:t.addonId,projectId:t.projectId},[2,this.logRange(r,null!=n?n:{},"addon")]})})},this.getAddonBackupLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r;return $(this,function(o){return t=e.parameters,n=e.options,r={
|
|
288
|
+
entityId:t.addonId,projectId:t.projectId,teamId:t.teamId},[2,this.logRange(r,J(J({},n),{backupId:t.backupId}),"addonBackup")]})})},this.getAddonRestoresLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r,o,a,i,d;return $(this,function(p){return t=e.parameters,n=e.options,r=t.teamId,o=t.projectId,a=t.addonId,i={entityId:a,projectId:o,teamId:r},d={backupId:t.backupId,restoreId:t.restoreId},[2,this.logRange(i,J(J({},n),d),"addonRestore")]})})},this.logRange=function(e,t,r){return W(n,void 0,void 0,function(){var n,o,a,i,d,p;return $(this,function(l){switch(l.label){case 0:return n=e.entityId,o=e.projectId,a=e.teamId,i=J(J({teamId:a,projectId:o,entityId:n,entityType:r},t),{queryType:"range"}),[4,new pm(this.contextProvider,this.clientOpts).call(i)];case 1:return(d=l.sent()).error?[2,d]:[2,J(J({},d),{data:null===(p=null==d?void 0:d.data)||void 0===p?void 0:p.map(Zu)})]}})})},this.tailServiceLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r;return $(this,function(o){
|
|
289
|
+
return t=e.parameters,n=e.options,r={entityId:t.serviceId,projectId:t.projectId,teamId:t.teamId},[2,this.logTail(r,null!=n?n:{},"service")]})})},this.tailServiceBuildLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.serviceId,o=t.projectId,a=t.teamId,i={entityId:r,projectId:o,teamId:a},[2,this.logTail(i,J(J({},n),{isBuild:!0}),"service")]})})},this.tailJobLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r;return $(this,function(o){return t=e.parameters,n=e.options,r={entityId:t.jobId,projectId:t.projectId,teamId:t.teamId},[2,this.logTail(r,null!=n?n:{},"job")]})})},this.tailJobBuildLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r,o,a;return $(this,function(i){return t=e.parameters,n=e.options,r=t.projectId,o=t.jobId,a={entityId:o,projectId:r,teamId:t.teamId},[2,this.logTail(a,J(J({},n),{isBuild:!0}),"job")]})})},this.tailAddonLogs=function(e){return W(n,void 0,void 0,function(){
|
|
290
|
+
var t,n,r;return $(this,function(o){return t=e.parameters,n=e.options,r={entityId:t.addonId,projectId:t.projectId,teamId:t.teamId},[2,this.logTail(r,null!=n?n:{},"addon")]})})},this.tailAddonBackupLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r;return $(this,function(o){return t=e.parameters,n=e.options,r={entityId:t.addonId,projectId:t.projectId,teamId:t.teamId},[2,this.logTail(r,J(J({},n),{backupId:t.backupId}),"addonBackup")]})})},this.tailAddonRestoresLogs=function(e){return W(n,void 0,void 0,function(){var t,n,r,o;return $(this,function(a){return t=e.parameters,n=e.options,r={entityId:t.addonId,projectId:t.projectId},o={backupId:t.backupId,restoreId:t.restoreId},[2,this.logTail(r,J(J({},n),o),"addonRestore")]})})},this.logTail=function(e,t,r){return W(n,void 0,void 0,function(){var n,o,a,i,d,p;return $(this,function(l){if(n=e.entityId,o=e.projectId,a=e.teamId,i=J({queryType:"tail",teamId:a,projectId:o,entityId:n,entityType:r},t),this.assertStartedWithNodejs(),
|
|
291
|
+
d=this.contextProvider.getCurrentBaseUrl(!0),!(p=this.contextProvider.getCurrentToken()))throw new Error("API token not found");return[2,new Yu(d,i,p,this.clientOpts.agent)]})})},this.assertStartedWithNodejs=function(){if(!Ro)throw new Error("Command exec only possible when started with nodejs")}},sm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.description="Fetch metrics entries over a specific time span",t.withAuth=!0,t.requiredPermissions="Account > Service | Job | Addon > General > Read",t.endpointUrl=function(e){var t=e.teamId,n=e.projectId,r=e.entityId,o=e.entityType,a=e.deploymentId,i=e.runId,d=e.buildId,p=e.isBuild,l=e.queryType,s=e.metricTypes,u=e.startTime,m=e.endTime,c=e.duration,v=e.containerName,h=e.timestamp,f=void 0!==t?"teams/".concat(t,"/"):"",I="/v1/".concat(f,"projects/").concat(n,"/");var w=new URLSearchParams;return w.append("queryType",l),void 0!==u&&w.append("startTime",u.toISOString()),
|
|
292
|
+
void 0!==m&&w.append("endTime",m.toISOString()),void 0!==v&&w.append("containerName",v),void 0!==a&&w.append("deploymentId",a),void 0!==i&&w.append("runId",i),void 0!==d&&w.append("buildId",d),void 0!==h&&w.append("timestamp",h.toISOString()),void 0!==c&&w.append("duration",c.toString()),void 0!==s&&s.forEach(function(e){return w.append("metricTypes",e)}),"".concat(I).concat(function(){var e=p?"/build-metrics":"/metrics";switch(o){case"service":return"services/".concat(r).concat(e);case"job":return"jobs/".concat(r).concat(e);case"addon":return"addons/".concat(r).concat(e);default:throw new Error("Unexpected Northflank entity type received in metrics endpoint generation: ".concat(o))}}(),"?").concat(w.toString())},t.body=function(){},t}return z(t,e),t}(Qu),um=function(e){return{metadata:e.metadata,data:e.data.map(function(e){return{value:e.value,ts:new Date(e.ts)}})}};!function(e){e.Cpu="cpu",e.Memory="memory",e.NetworkIngress="networkIngress",e.NetworkEgress="networkEgress",
|
|
293
|
+
e.TcpConnectionOpen="tcpConnectionsOpen",e.PvcUsage="diskUsage",e.Requests="requests",e.Http4xxResponses="http4xxResponses",e.Http5xxResponses="http5xxResponses",e.Bandwidth="bandwidth",e.BandwidthVolume="bandwidthVolume"}(Hu||(Hu={}));var mm=function(e){var t=this;this.contextProvider=e,this.getServiceMetrics=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.serviceId,o=t.projectId,a=t.teamId,i={teamId:a,entityId:r,projectId:o},[2,this.metricsSingle(i,null!=n?n:{},"service")]})})},this.getServiceBuildMetrics=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.serviceId,o=t.projectId,a=t.teamId,i={entityId:r,projectId:o,teamId:a},[2,this.metricsSingle(i,J(J({},n),{isBuild:!0}),"service")]})})},this.getJobMetrics=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,
|
|
294
|
+
r=t.jobId,o=t.projectId,a=t.teamId,i={entityId:r,projectId:o,teamId:a},[2,this.metricsSingle(i,null!=n?n:{},"job")]})})},this.getJobBuildMetrics=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.jobId,o=t.projectId,a=t.teamId,i={entityId:r,projectId:o,teamId:a},[2,this.metricsSingle(i,J(J({},n),{isBuild:!0}),"job")]})})},this.getAddonMetrics=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.addonId,o=t.projectId,a=t.teamId,i={entityId:r,projectId:o,teamId:a},[2,this.metricsSingle(i,null!=n?n:{},"addon")]})})},this.metricsSingle=function(e,n,r){return W(t,void 0,void 0,function(){var t,o,a,i;return $(this,function(d){return t=e.entityId,o=e.projectId,a=e.teamId,i=J(J({teamId:a,projectId:o,entityId:t,entityType:r},n),{queryType:"single"}),[2,this.getMetrics(i)]})})},this.getServiceMetricsRange=function(e){
|
|
295
|
+
return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.serviceId,o=t.projectId,a=t.teamId,i={entityId:r,projectId:o,teamId:a},[2,this.metricsRange(i,null!=n?n:{},"service")]})})},this.getServiceBuildMetricsRange=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.projectId,o=t.serviceId,a=t.teamId,i={entityId:o,projectId:r,teamId:a},[2,this.metricsRange(i,J(J({},n),{isBuild:!0}),"service")]})})},this.getJobMetricsRange=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.projectId,o=t.jobId,a=t.teamId,i={entityId:o,projectId:r,teamId:a},[2,this.metricsRange(i,null!=n?n:{},"job")]})})},this.getJobBuildMetricsRange=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.projectId,o=t.jobId,a=t.teamId,i={
|
|
296
|
+
entityId:o,projectId:r,teamId:a},[2,this.metricsRange(i,J(J({},n),{isBuild:!0}),"job")]})})},this.getAddonMetricsRange=function(e){return W(t,void 0,void 0,function(){var t,n,r,o,a,i;return $(this,function(d){return t=e.parameters,n=e.options,r=t.projectId,o=t.addonId,a=t.teamId,i={entityId:o,projectId:r,teamId:a},[2,this.metricsRange(i,null!=n?n:{},"addon")]})})},this.metricsRange=function(e,n,r){return W(t,void 0,void 0,function(){var t,o,a,i;return $(this,function(d){return t=e.entityId,o=e.projectId,a=e.teamId,i=J(J({teamId:a,projectId:o,entityId:t,entityType:r},n),{queryType:"range"}),[2,this.getMetrics(i)]})})},this.getMetrics=function(e){return W(t,void 0,void 0,function(){var t;return $(this,function(n){switch(n.label){case 0:return[4,new sm(this.contextProvider,{}).call(e)];case 1:return(t=n.sent()).error?[2,t]:[2,J(J({},t),{data:Object.fromEntries(Object.entries(t.data).map(function(e){var t=e[0],n=e[1];return[t,J(J({},n),{values:n.values.map(um)})]}))})]}})})}
|
|
297
|
+
},cm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.description="Gets information about the available addon types",t.withAuth=!0,t.requiredPermissions="undefined",t.endpointUrl=function(e){return"/v1/addon-types"},t.body=function(){},t}return z(t,e),t}(Qu),vm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.description="Lists the backup destinations saved to this account. Does not display secrets.",t.withAuth=!0,t.requiredPermissions="Account > BackupDestinations > General > Read",t.endpointUrl=function(e){var t,n,r;[].forEach(function(t){var n;if(void 0===(null===(n=null==e?void 0:e.parameters)||void 0===n?void 0:n[t]))throw new Error("Required argument not set: '".concat(t,"'"))}),
|
|
298
|
+
r=(null==e?void 0:e.parameters)&&"teamId"in(null==e?void 0:e.parameters)&&void 0!==(null===(t=null==e?void 0:e.parameters)||void 0===t?void 0:t.teamId)?"/v1/teams/".concat(encodeURIComponent(e.parameters.teamId),"/backup-destinations"):"/v1/backup-destinations";var o=Object.entries(null!==(n=null==e?void 0:e.options)&&void 0!==n?n:{}).filter(function(e){return void 0!==e[1]}),a=o.length>0?"?".concat(o.map(function(e){return"".concat(e[0],"=").concat(e[1])}).join("&")):"";return"".concat(r).concat(a)},t.body=function(){},t}return z(t,e),t}(em),hm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.description="Adds a new backup destination to this account.",t.withAuth=!0,t.requiredPermissions="Account > BackupDestinations > General > Create",t.endpointUrl=function(e){var t;return[].forEach(function(t){var n;if(void 0===(null===(n=null==e?void 0:e.parameters)||void 0===n?void 0:n[t]))throw new Error("Required argument not set: '".concat(t,"'"))}),
|
|
299
|
+
(null==e?void 0:e.parameters)&&"teamId"in(null==e?void 0:e.parameters)&&void 0!==(null===(t=null==e?void 0:e.parameters)||void 0===t?void 0:t.teamId)?"/v1/teams/".concat(encodeURIComponent(e.parameters.teamId),"/backup-destinations"):"/v1/backup-destinations"},t.body=function(e){return JSON.stringify(e.data)},t}return z(t,e),t}(tm),fm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.description="View a backup destination, including secrets.",t.withAuth=!0,t.requiredPermissions="Account > BackupDestinations > General > Read",t.endpointUrl=function(e){var t,n,r,o;if([].forEach(function(t){var n;if(void 0===(null===(n=null==e?void 0:e.parameters)||void 0===n?void 0:n[t]))throw new Error("Required argument not set: '".concat(t,"'"))}),
|
|
299
300
|
(null==e?void 0:e.parameters)&&"teamId"in(null==e?void 0:e.parameters)&&void 0!==(null===(t=null==e?void 0:e.parameters)||void 0===t?void 0:t.teamId)&&(null==e?void 0:e.parameters)&&"backupDestinationId"in(null==e?void 0:e.parameters)&&void 0!==(null===(n=null==e?void 0:e.parameters)||void 0===n?void 0:n.backupDestinationId))o="/v1/teams/".concat(encodeURIComponent(e.parameters.teamId),"/backup-destinations/").concat(encodeURIComponent(e.parameters.backupDestinationId));else{if(!(null==e?void 0:e.parameters)||!("backupDestinationId"in(null==e?void 0:e.parameters))||void 0===(null===(r=null==e?void 0:e.parameters)||void 0===r?void 0:r.backupDestinationId))throw new Error("No matching endpoint URL found for provided parameters");o="/v1/backup-destinations/".concat(encodeURIComponent(e.parameters.backupDestinationId))}return o},t.body=function(){},t}return z(t,e),t}(Qu),Im=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this
|
|
300
301
|
;return t.description="Updates a backup destination.",t.withAuth=!0,t.requiredPermissions="Account > BackupDestinations > General > Update",t.endpointUrl=function(e){var t,n,r,o;if([].forEach(function(t){var n;if(void 0===(null===(n=null==e?void 0:e.parameters)||void 0===n?void 0:n[t]))throw new Error("Required argument not set: '".concat(t,"'"))}),(null==e?void 0:e.parameters)&&"teamId"in(null==e?void 0:e.parameters)&&void 0!==(null===(t=null==e?void 0:e.parameters)||void 0===t?void 0:t.teamId)&&(null==e?void 0:e.parameters)&&"backupDestinationId"in(null==e?void 0:e.parameters)&&void 0!==(null===(n=null==e?void 0:e.parameters)||void 0===n?void 0:n.backupDestinationId))o="/v1/teams/".concat(encodeURIComponent(e.parameters.teamId),"/backup-destinations/").concat(encodeURIComponent(e.parameters.backupDestinationId));else{
|
|
301
302
|
if(!(null==e?void 0:e.parameters)||!("backupDestinationId"in(null==e?void 0:e.parameters))||void 0===(null===(r=null==e?void 0:e.parameters)||void 0===r?void 0:r.backupDestinationId))throw new Error("No matching endpoint URL found for provided parameters");o="/v1/backup-destinations/".concat(encodeURIComponent(e.parameters.backupDestinationId))}return o},t.body=function(e){return JSON.stringify(e.data)},t}return z(t,e),t}(om),wm=function(e){function t(){var t=null!==e&&e.apply(this,arguments)||this;return t.description="Delete a backup destination.",t.withAuth=!0,t.requiredPermissions="Account > BackupDestinations > General > Delete",t.endpointUrl=function(e){var t,n,r,o;if([].forEach(function(t){var n;if(void 0===(null===(n=null==e?void 0:e.parameters)||void 0===n?void 0:n[t]))throw new Error("Required argument not set: '".concat(t,"'"))}),
|