@milaboratories/pl-deployments 1.8.0 → 1.8.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/index.mjs CHANGED
@@ -1,47 +1,48 @@
1
- var Y = Object.defineProperty;
2
- var Q = (n, e, r) => e in n ? Y(n, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : n[e] = r;
3
- var w = (n, e, r) => Q(n, typeof e != "symbol" ? e + "" : e, r);
4
- import { spawn as X } from "node:child_process";
5
- import { sleep as F, fileExists as y, assertNever as H, notEmpty as f, RetryablePromise as tt } from "@milaboratories/ts-helpers";
6
- import D from "node:fs";
7
- import m, { readFile as rt } from "node:fs/promises";
1
+ var X = Object.defineProperty;
2
+ var Y = (o, e, r) => e in o ? X(o, e, { enumerable: !0, configurable: !0, writable: !0, value: r }) : o[e] = r;
3
+ var w = (o, e, r) => Y(o, typeof e != "symbol" ? e + "" : e, r);
4
+ import { spawn as Q } from "node:child_process";
5
+ import { sleep as F, fileExists as v, assertNever as H, notEmpty as p, RetryablePromise as tt } from "@milaboratories/ts-helpers";
6
+ import O from "node:fs";
7
+ import g, { readFile as rt } from "node:fs/promises";
8
8
  import u from "upath";
9
9
  import { request as et } from "undici";
10
- import { Readable as it, Writable as ot } from "node:stream";
11
- import { text as nt } from "node:stream/consumers";
10
+ import { Readable as it, Writable as nt } from "node:stream";
11
+ import { text as ot } from "node:stream/consumers";
12
12
  import * as st from "tar";
13
13
  import at from "decompress";
14
+ import * as ct from "node:os";
14
15
  import A from "node:os";
15
- import ct, { Client as b } from "ssh2";
16
+ import lt, { Client as b } from "ssh2";
16
17
  import G from "node:net";
17
- import lt from "node:dns";
18
- import { randomBytes as k } from "node:crypto";
19
- import { generateSshPlConfigs as ht, getFreePort as $ } from "@milaboratories/pl-config";
20
- import { z as p } from "zod";
21
- function dt(n, e) {
22
- return n.info(`Running:
18
+ import ht from "node:dns";
19
+ import { randomBytes as D } from "node:crypto";
20
+ import { generateSshPlConfigs as dt, getFreePort as $ } from "@milaboratories/pl-config";
21
+ import { z as m } from "zod";
22
+ function ut(o, e) {
23
+ return o.info(`Running:
23
24
  cmd: ${JSON.stringify([e.cmd, ...e.args])}
24
- wd: ${e.opts.cwd}`), n.info(" spawning child process"), X(e.cmd, e.args, e.opts);
25
+ wd: ${e.opts.cwd}`), o.info(" spawning child process"), Q(e.cmd, e.args, e.opts);
25
26
  }
26
- async function x(n) {
27
+ async function x(o) {
27
28
  try {
28
- return process.kill(n, 0), !0;
29
+ return process.kill(o, 0), !0;
29
30
  } catch {
30
31
  return !1;
31
32
  }
32
33
  }
33
- function M(n) {
34
- return process.kill(n, "SIGINT");
34
+ function M(o) {
35
+ return process.kill(o, "SIGINT");
35
36
  }
36
- async function J(n, e) {
37
+ async function J(o, e) {
37
38
  let t = 0;
38
- for (; await x(n); )
39
+ for (; await x(o); )
39
40
  if (await F(100), t += 100, t > e)
40
41
  throw new Error(`The process did not stopped after ${e} ms.`);
41
42
  }
42
- const ut = ["linux", "macos", "windows"];
43
- function O(n) {
44
- switch (n.toLowerCase()) {
43
+ const wt = ["linux", "macos", "windows"];
44
+ function k(o) {
45
+ switch (o.toLowerCase()) {
45
46
  case "darwin":
46
47
  return "macos";
47
48
  case "linux":
@@ -50,13 +51,13 @@ function O(n) {
50
51
  return "windows";
51
52
  default:
52
53
  throw new Error(
53
- `operating system '${n}' is not currently supported by Platforma ecosystem. The list of OSes supported: ` + JSON.stringify(ut)
54
+ `operating system '${o}' is not currently supported by Platforma ecosystem. The list of OSes supported: ` + JSON.stringify(wt)
54
55
  );
55
56
  }
56
57
  }
57
- const wt = ["amd64", "arm64"];
58
- function P(n) {
59
- switch (n) {
58
+ const ft = ["amd64", "arm64"];
59
+ function P(o) {
60
+ switch (o) {
60
61
  case "aarch64":
61
62
  case "aarch64_be":
62
63
  case "arm64":
@@ -66,72 +67,72 @@ function P(n) {
66
67
  return "amd64";
67
68
  default:
68
69
  throw new Error(
69
- `processor architecture '${n}' is not currently supported by Platforma ecosystem. The list of architectures supported: ` + JSON.stringify(wt)
70
+ `processor architecture '${o}' is not currently supported by Platforma ecosystem. The list of architectures supported: ` + JSON.stringify(ft)
70
71
  );
71
72
  }
72
73
  }
73
- const ft = "https://cdn.platforma.bio/software", pt = "https://cdn-ga.pl-open.science/software";
74
- async function mt(n, e, r, t, i, o) {
75
- const s = L(r, t, e, P(i), O(o)), { archiveUrl: a, alternativeArchiveGAUrl: c, archivePath: l } = s;
74
+ const pt = "https://cdn.platforma.bio/software", mt = "https://cdn-ga.pl-open.science/software";
75
+ async function gt(o, e, r, t, i, n) {
76
+ const s = L(r, t, e, P(i), k(n)), { archiveUrl: a, alternativeArchiveGAUrl: c, archivePath: l } = s;
76
77
  try {
77
- await C(n, a, l), s.wasDownloadedFrom = a;
78
+ await C(o, a, l), s.wasDownloadedFrom = a;
78
79
  } catch {
79
- await C(n, c, l), s.wasDownloadedFrom = c;
80
+ await C(o, c, l), s.wasDownloadedFrom = c;
80
81
  }
81
82
  return s;
82
83
  }
83
- async function gt(n, e, r, t, i, o) {
84
- const s = L(r, t, e, P(i), O(o)), { archiveUrl: a, alternativeArchiveGAUrl: c, archivePath: l, archiveType: h, targetFolder: d } = s;
84
+ async function yt(o, e, r, t, i, n) {
85
+ const s = L(r, t, e, P(i), k(n)), { archiveUrl: a, alternativeArchiveGAUrl: c, archivePath: l, archiveType: h, targetFolder: d } = s;
85
86
  try {
86
- await C(n, a, l), s.wasDownloadedFrom = a;
87
+ await C(o, a, l), s.wasDownloadedFrom = a;
87
88
  } catch {
88
- await C(n, c, l), s.wasDownloadedFrom = c;
89
+ await C(o, c, l), s.wasDownloadedFrom = c;
89
90
  }
90
- return await vt(n, l, h, d), s;
91
+ return await $t(o, l, h, d), s;
91
92
  }
92
- function L(n, e, r, t, i) {
93
- const o = `${e}-${t}`, s = $t[i], a = `${o}.${s}`, c = `${ft}/${n}/${i}/${a}`, l = `${pt}/${n}/${i}/${a}`, h = u.join(r, a), d = u.join(r, o);
93
+ function L(o, e, r, t, i) {
94
+ const n = `${e}-${t}`, s = St[i], a = `${n}.${s}`, c = `${pt}/${o}/${i}/${a}`, l = `${mt}/${o}/${i}/${a}`, h = u.join(r, a), d = u.join(r, n);
94
95
  return {
95
96
  archiveUrl: c,
96
97
  alternativeArchiveGAUrl: l,
97
98
  archivePath: h,
98
99
  archiveType: s,
99
100
  targetFolder: d,
100
- baseName: o
101
+ baseName: n
101
102
  };
102
103
  }
103
- async function C(n, e, r) {
104
+ async function C(o, e, r) {
104
105
  const t = {};
105
106
  t.dstArchive = r;
106
107
  try {
107
- if (t.fileExisted = await y(r), t.fileExisted)
108
- return n.info(`Platforma Backend archive download skipped: '${r}' already exists`), t;
109
- await m.mkdir(u.dirname(r), { recursive: !0 }), t.dirnameCreated = !0, n.info(`Downloading archive:
108
+ if (t.fileExisted = await v(r), t.fileExisted)
109
+ return o.info(`Platforma Backend archive download skipped: '${r}' already exists`), t;
110
+ await g.mkdir(u.dirname(r), { recursive: !0 }), t.dirnameCreated = !0, o.info(`Downloading archive:
110
111
  URL: ${e}
111
112
  Save to: ${r}`);
112
- const { body: i, statusCode: o } = await et(e);
113
- if (t.statusCode = o, o != 200) {
114
- const s = await nt(i);
115
- throw t.errorMsg = `failed to download archive: ${o}, response: ${s.slice(0, 1e3)}`, n.error(t.errorMsg), new Error(t.errorMsg);
113
+ const { body: i, statusCode: n } = await et(e);
114
+ if (t.statusCode = n, n != 200) {
115
+ const s = await ot(i);
116
+ throw t.errorMsg = `failed to download archive: ${n}, response: ${s.slice(0, 1e3)}`, o.error(t.errorMsg), new Error(t.errorMsg);
116
117
  }
117
- return t.tmpPath = r + ".tmp", await it.toWeb(i).pipeTo(ot.toWeb(D.createWriteStream(t.tmpPath))), t.wroteTmp = !0, t.tmpExisted = await y(t.tmpPath), await m.rename(t.tmpPath, r), t.renamed = !0, t.newExisted = await y(r), t;
118
+ return t.tmpPath = r + ".tmp", await it.toWeb(i).pipeTo(nt.toWeb(O.createWriteStream(t.tmpPath))), t.wroteTmp = !0, t.tmpExisted = await v(t.tmpPath), await g.rename(t.tmpPath, r), t.renamed = !0, t.newExisted = await v(r), t;
118
119
  } catch (i) {
119
- const o = `downloadArchive: ${JSON.stringify(i)}, state: ${JSON.stringify(t)}`;
120
- throw n.error(o), new Error(o);
120
+ const n = `downloadArchive: ${JSON.stringify(i)}, state: ${JSON.stringify(t)}`;
121
+ throw o.error(n), new Error(n);
121
122
  }
122
123
  }
123
- const yt = ".ok";
124
- async function vt(n, e, r, t) {
125
- if (n.info("extracting archive..."), n.info(` archive path: '${e}'`), n.info(` target dir: '${t}'`), !await y(e)) {
126
- const o = `Platforma Backend binary archive not found at '${e}'`;
127
- throw n.error(o), new Error(o);
128
- }
129
- const i = u.join(t, yt);
130
- if (await y(i)) {
131
- n.info(`Platforma Backend binaries unpack skipped: '${t}' exists`);
124
+ const vt = ".ok";
125
+ async function $t(o, e, r, t) {
126
+ if (o.info("extracting archive..."), o.info(` archive path: '${e}'`), o.info(` target dir: '${t}'`), !await v(e)) {
127
+ const n = `Platforma Backend binary archive not found at '${e}'`;
128
+ throw o.error(n), new Error(n);
129
+ }
130
+ const i = u.join(t, vt);
131
+ if (await v(i)) {
132
+ o.info(`Platforma Backend binaries unpack skipped: '${t}' exists`);
132
133
  return;
133
134
  }
134
- switch (await y(t) && (n.info(`Removing previous incompletely unpacked folder: '${t}'`), await m.rm(t, { recursive: !0 })), n.info(` creating target dir '${t}'`), await m.mkdir(t, { recursive: !0 }), n.info(
135
+ switch (await v(t) && (o.info(`Removing previous incompletely unpacked folder: '${t}'`), await g.rm(t, { recursive: !0 })), o.info(` creating target dir '${t}'`), await g.mkdir(t, { recursive: !0 }), o.info(
135
136
  `Unpacking Platforma Backend archive:
136
137
  Archive: ${e}
137
138
  Target dir: ${t}`
@@ -149,97 +150,97 @@ async function vt(n, e, r, t) {
149
150
  default:
150
151
  H(r);
151
152
  }
152
- await m.writeFile(i, "ok"), n.info(" ... unpack done.");
153
+ await g.writeFile(i, "ok"), o.info(" ... unpack done.");
153
154
  }
154
- const $t = {
155
+ const St = {
155
156
  linux: "tgz",
156
157
  macos: "tgz",
157
158
  windows: "zip"
158
159
  };
159
160
  function R() {
160
- return "1.30.0";
161
+ return "1.31.3";
161
162
  }
162
- function St() {
163
+ function Pt() {
163
164
  return { type: "Download", version: R() };
164
165
  }
165
- async function Pt(n, e, r) {
166
+ async function Ct(o, e, r) {
166
167
  switch (r.type) {
167
168
  case "Download":
168
- const t = await gt(n, e, "pl", `pl-${r.version}`, A.arch(), A.platform());
169
- return u.join(t.baseName, "binaries", Ct[O(A.platform())]);
169
+ const t = await yt(o, e, "pl", `pl-${r.version}`, A.arch(), A.platform());
170
+ return u.join(t.baseName, "binaries", Et[k(A.platform())]);
170
171
  case "Local":
171
172
  return r.path;
172
173
  default:
173
174
  H(r);
174
175
  }
175
176
  }
176
- const Ct = {
177
+ const Et = {
177
178
  linux: "platforma",
178
179
  macos: "platforma",
179
180
  windows: "platforma.exe"
180
181
  };
181
- function W(n) {
182
- return u.join(n, "pl_pid");
182
+ function W(o) {
183
+ return u.join(o, "pl_pid");
183
184
  }
184
- async function Et(n) {
185
- if (!await y(n))
185
+ async function At(o) {
186
+ if (!await v(o))
186
187
  return;
187
- const e = await m.readFile(n);
188
+ const e = await g.readFile(o);
188
189
  return Number(e.toString());
189
190
  }
190
- async function At(n, e) {
191
- await m.writeFile(n, JSON.stringify(e));
191
+ async function bt(o, e) {
192
+ await g.writeFile(o, JSON.stringify(e));
192
193
  }
193
- function bt() {
194
+ function Ft() {
194
195
  return {};
195
196
  }
196
- function Ft(n, e, r) {
197
- return n[e] = r, r;
197
+ function Ot(o, e, r) {
198
+ return o[e] = r, r;
198
199
  }
199
- async function N(n, e) {
200
- const r = bt();
200
+ async function N(o, e) {
201
+ const r = Ft();
201
202
  try {
202
- return await e((i, o) => Ft(r, i, o), r);
203
+ return await e((i, n) => Ot(r, i, n), r);
203
204
  } catch (t) {
204
- throw n.error(`error ${t} while doing traced operation, state: ${JSON.stringify(r)}`), t;
205
+ throw o.error(`error ${t} while doing traced operation, state: ${JSON.stringify(r)}`), t;
205
206
  }
206
207
  }
207
208
  const Dt = "config-local.yaml";
208
- class kt {
209
- constructor(e, r, t, i, o, s, a, c) {
209
+ class xt {
210
+ constructor(e, r, t, i, n, s, a, c) {
210
211
  w(this, "instance");
211
212
  w(this, "pid");
212
213
  w(this, "nRuns", 0);
213
214
  w(this, "lastRunHistory", {});
214
215
  w(this, "wasStopped", !1);
215
- this.logger = e, this.workingDir = r, this.startOptions = t, this.initialStartHistory = i, this.onClose = o, this.onError = s, this.onCloseAndError = a, this.onCloseAndErrorNoStop = c;
216
+ this.logger = e, this.workingDir = r, this.startOptions = t, this.initialStartHistory = i, this.onClose = n, this.onError = s, this.onCloseAndError = a, this.onCloseAndErrorNoStop = c;
216
217
  }
217
218
  async start() {
218
219
  await N(this.logger, async (e, r) => {
219
220
  this.wasStopped = !1;
220
- const t = dt(this.logger, this.startOptions);
221
- t.on("error", (o) => {
221
+ const t = ut(this.logger, this.startOptions);
222
+ t.on("error", (n) => {
222
223
  this.logger.error(
223
- `error '${o}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`
224
+ `error '${n}', while running platforma, started opts: ${JSON.stringify(this.debugInfo())}`
224
225
  ), this.onError !== void 0 && this.onError(this), this.onCloseAndError !== void 0 && this.onCloseAndError(this), this.onCloseAndErrorNoStop !== void 0 && !this.wasStopped && this.onCloseAndErrorNoStop(this);
225
226
  }), t.on("close", () => {
226
227
  this.logger.warn(`platforma was closed, started opts: ${JSON.stringify(this.debugInfo())}`), this.onClose !== void 0 && this.onClose(this), this.onCloseAndError !== void 0 && this.onCloseAndError(this), this.onCloseAndErrorNoStop !== void 0 && !this.wasStopped && this.onCloseAndErrorNoStop(this);
227
228
  }), e("started", !0);
228
229
  const i = e("pidFile", W(this.workingDir));
229
- e("pid", f(t.pid)), e("pidWritten", await At(i, f(t.pid))), this.nRuns++, this.instance = t, this.pid = t.pid, this.lastRunHistory = r;
230
+ e("pid", p(t.pid)), e("pidWritten", await bt(i, p(t.pid))), this.nRuns++, this.instance = t, this.pid = t.pid, this.lastRunHistory = r;
230
231
  });
231
232
  }
232
233
  stop() {
233
- this.wasStopped = !0, M(f(this.pid));
234
+ this.wasStopped = !0, M(p(this.pid));
234
235
  }
235
236
  async waitStopped() {
236
- await J(f(this.pid), 15e3);
237
+ await J(p(this.pid), 15e3);
237
238
  }
238
239
  stopped() {
239
240
  return this.wasStopped;
240
241
  }
241
242
  async isAlive() {
242
- return await x(f(this.pid));
243
+ return await x(p(this.pid));
243
244
  }
244
245
  debugInfo() {
245
246
  return {
@@ -252,56 +253,75 @@ class kt {
252
253
  };
253
254
  }
254
255
  }
255
- async function mr(n, e) {
256
- const r = {
257
- plBinary: St(),
258
- spawnOptions: {},
259
- closeOld: !0,
260
- ...e
261
- };
262
- return await N(n, async (t, i) => {
263
- t("startOptions", { ...r, config: "too wordy" });
264
- const o = u.resolve(r.workingDir);
265
- r.closeOld && t("closeOld", await xt(n, o));
266
- const s = u.join(o, Dt);
267
- n.info(`writing configuration '${s}'...`), await m.writeFile(s, r.config);
268
- const a = u.join(o, "binaries"), c = await Pt(n, a, r.plBinary), h = {
269
- cmd: t("binaryPath", u.join("binaries", c)),
270
- args: ["--config", s],
271
- opts: {
272
- env: { ...process.env },
273
- cwd: o,
274
- stdio: ["pipe", "ignore", "inherit"],
275
- windowsHide: !0,
276
- // hide a terminal on Windows
277
- ...r.spawnOptions
278
- }
279
- };
280
- t("processOpts", {
281
- cmd: h.cmd,
282
- args: h.args,
283
- cwd: h.opts.cwd
256
+ async function vr(o, e) {
257
+ const r = Math.max(ct.cpus().length - 2, 1), t = Rt(e, r);
258
+ return await N(o, async (i, n) => {
259
+ i("startOptions", { ...t, config: "too wordy" });
260
+ const s = u.resolve(t.workingDir);
261
+ t.closeOld && i("closeOld", await kt(o, s));
262
+ const a = u.join(s, Dt);
263
+ o.info(`writing configuration '${a}'...`), await g.writeFile(a, t.config);
264
+ const c = u.join(s, "binaries"), l = await Ct(o, c, t.plBinary), h = i("binaryPath", u.join("binaries", l)), d = Nt(h, a, t, s, process.env);
265
+ i("processOpts", {
266
+ cmd: d.cmd,
267
+ args: d.args,
268
+ cwd: d.opts.cwd
284
269
  });
285
- const d = new kt(
270
+ const f = new xt(
271
+ o,
272
+ t.workingDir,
273
+ d,
286
274
  n,
287
- r.workingDir,
288
- h,
289
- i,
290
- r.onClose,
291
- r.onError,
292
- r.onCloseAndError,
293
- r.onCloseAndErrorNoStop
275
+ t.onClose,
276
+ t.onError,
277
+ t.onCloseAndError,
278
+ t.onCloseAndErrorNoStop
294
279
  );
295
- return await d.start(), d;
280
+ return await f.start(), f;
296
281
  });
297
282
  }
298
- async function xt(n, e) {
299
- return await N(n, async (r, t) => {
300
- const i = r("pidFilePath", W(e)), o = r("pid", await Et(i)), s = r("wasAlive", await x(o));
301
- return o !== void 0 && s && (r("stopped", M(o)), r("waitStopped", await J(o, 1e4))), t;
283
+ async function kt(o, e) {
284
+ return await N(o, async (r, t) => {
285
+ const i = r("pidFilePath", W(e)), n = r("pid", await At(i)), s = r("wasAlive", await x(n));
286
+ return n !== void 0 && s && (r("stopped", M(n)), r("waitStopped", await J(n, 1e4))), t;
302
287
  });
303
288
  }
304
- const Ot = {
289
+ function Rt(o, e) {
290
+ var i;
291
+ const r = {
292
+ plBinary: Pt(),
293
+ spawnOptions: {
294
+ env: {
295
+ GOMAXPROCS: String(e)
296
+ }
297
+ },
298
+ closeOld: !0
299
+ };
300
+ if ((i = o.spawnOptions) != null && i.env && (r.spawnOptions.env = { ...r.spawnOptions.env, ...o.spawnOptions.env }), o.spawnOptions) {
301
+ const n = { ...o.spawnOptions };
302
+ delete n.env, r.spawnOptions = { ...r.spawnOptions, ...n };
303
+ }
304
+ const t = { ...o };
305
+ return delete t.spawnOptions, { ...r, ...t };
306
+ }
307
+ function Nt(o, e, r, t, i) {
308
+ var a;
309
+ const n = {
310
+ cmd: o,
311
+ args: ["--config", e],
312
+ opts: {
313
+ env: { ...i },
314
+ cwd: t,
315
+ stdio: ["pipe", "ignore", "inherit"],
316
+ windowsHide: !0
317
+ // hide a terminal on Windows
318
+ }
319
+ };
320
+ (a = r.spawnOptions) != null && a.env && (n.opts.env = { ...n.opts.env, ...r.spawnOptions.env });
321
+ const s = { ...r.spawnOptions };
322
+ return delete s.env, n.opts = { ...n.opts, ...s }, n;
323
+ }
324
+ const Bt = {
305
325
  keepaliveInterval: 6e4,
306
326
  keepaliveCountMax: 10
307
327
  };
@@ -319,7 +339,7 @@ class B {
319
339
  */
320
340
  static async init(e, r) {
321
341
  const t = {
322
- ...Ot,
342
+ ...Bt,
323
343
  ...r
324
344
  }, i = new B(e, new b());
325
345
  return await i.connect(t), i;
@@ -341,7 +361,7 @@ class B {
341
361
  * @returns A promise that resolves when the connection is established or rejects on error.
342
362
  */
343
363
  async connect(e) {
344
- return this.config = e, await Rt(this.client, e);
364
+ return this.config = e, await Ut(this.client, e);
345
365
  }
346
366
  /**
347
367
  * Executes a command on the SSH server.
@@ -350,11 +370,11 @@ class B {
350
370
  */
351
371
  async exec(e) {
352
372
  return new Promise((r, t) => {
353
- this.client.exec(e, (i, o) => {
373
+ this.client.exec(e, (i, n) => {
354
374
  if (i)
355
375
  return t(new Error(`ssh.exec: ${e}: ${i}`));
356
376
  let s = "", a = "";
357
- o.on("close", (c) => {
377
+ n.on("close", (c) => {
358
378
  c === 0 ? r({ stdout: s, stderr: a }) : t(new Error(`Command ${e} exited with code ${c}, stdout: ${s}, stderr: ${a}`));
359
379
  }).on("data", (c) => {
360
380
  s += c.toString();
@@ -373,14 +393,14 @@ class B {
373
393
  static async getAuthTypes(e, r) {
374
394
  return new Promise((t) => {
375
395
  let i = "";
376
- const o = new b();
377
- o.on("ready", () => {
378
- o.end();
396
+ const n = new b();
397
+ n.on("ready", () => {
398
+ n.end();
379
399
  const s = this.extractAuthMethods(i);
380
400
  t(s.length === 0 ? ["publickey", "password"] : s);
381
- }), o.on("error", () => {
382
- o.end(), t(["publickey", "password"]);
383
- }), o.connect({
401
+ }), n.on("error", () => {
402
+ n.end(), t(["publickey", "password"]);
403
+ }), n.connect({
384
404
  host: e,
385
405
  port: r,
386
406
  username: (/* @__PURE__ */ new Date()).getTime().toString(),
@@ -408,38 +428,38 @@ class B {
408
428
  * @returns { server: net.Server } A promise resolving with the created server instance.
409
429
  */
410
430
  async forwardPort(e, r) {
411
- const t = `ssh.forward:${e.localPort}:${e.remotePort}.id_${k(1).toString("hex")}`;
431
+ const t = `ssh.forward:${e.localPort}:${e.remotePort}.id_${D(1).toString("hex")}`;
412
432
  r = r ?? this.config;
413
- const i = new tt((o) => new Promise((s, a) => {
433
+ const i = new tt((n) => new Promise((s, a) => {
414
434
  const c = new b();
415
435
  c.on("ready", () => {
416
436
  this.logger.info(`${t}.client.ready`), s(c);
417
437
  }), c.on("error", (l) => {
418
- this.logger.info(`${t}.client.error: ${l}`), o.reset(), a(l);
438
+ this.logger.info(`${t}.client.error: ${l}`), n.reset(), a(l);
419
439
  }), c.on("close", () => {
420
- this.logger.info(`${t}.client.closed`), o.reset();
440
+ this.logger.info(`${t}.client.closed`), n.reset();
421
441
  }), c.connect(r);
422
442
  }));
423
- return await i.ensure(), new Promise((o, s) => {
443
+ return await i.ensure(), new Promise((n, s) => {
424
444
  const a = G.createServer({ pauseOnConnect: !0 }, async (c) => {
425
- const l = `${t}.sock_${k(1).toString("hex")}`;
445
+ const l = `${t}.sock_${D(1).toString("hex")}`;
426
446
  let h;
427
447
  try {
428
448
  h = await i.ensure();
429
- } catch (v) {
430
- this.logger.info(`${l}.persistentClient.catch: ${v}`), c.end();
449
+ } catch (f) {
450
+ this.logger.info(`${l}.persistentClient.catch: ${f}`), c.end();
431
451
  return;
432
452
  }
433
453
  h.setNoDelay(!0), c.setNoDelay(!0);
434
454
  let d;
435
455
  try {
436
- d = await Nt(this.logger, h, "127.0.0.1", 0, "127.0.0.1", e.remotePort);
437
- } catch (v) {
438
- this.logger.error(`${l}.forwardOut.err: ${v}`), c.end();
456
+ d = await _t(this.logger, h, "127.0.0.1", 0, "127.0.0.1", e.remotePort);
457
+ } catch (f) {
458
+ this.logger.error(`${l}.forwardOut.err: ${f}`), c.end();
439
459
  return;
440
460
  }
441
- c.pipe(d), d.pipe(c), c.resume(), d.on("error", (v) => {
442
- this.logger.error(`${l}.stream.error: ${v}`), c.end(), d.end();
461
+ c.pipe(d), d.pipe(c), c.resume(), d.on("error", (f) => {
462
+ this.logger.error(`${l}.stream.error: ${f}`), c.end(), d.end();
443
463
  }), d.on("close", () => {
444
464
  c.end(), d.end();
445
465
  }), c.on("close", () => {
@@ -447,7 +467,7 @@ class B {
447
467
  });
448
468
  });
449
469
  a.listen(e.localPort, "127.0.0.1", () => {
450
- this.logger.info(`${t}.server: started listening`), this.forwardedServers.push(a), o({ server: a });
470
+ this.logger.info(`${t}.server: started listening`), this.forwardedServers.push(a), n({ server: a });
451
471
  }), a.on("error", (c) => {
452
472
  a.close(), s(new Error(`${t}.server: error: ${JSON.stringify(c)}`));
453
473
  }), a.on("close", () => {
@@ -472,7 +492,7 @@ class B {
472
492
  */
473
493
  static async checkHostAvailability(e) {
474
494
  return new Promise((r) => {
475
- lt.lookup(e, (t) => {
495
+ ht.lookup(e, (t) => {
476
496
  r(!t);
477
497
  });
478
498
  });
@@ -485,7 +505,7 @@ class B {
485
505
  static async isPassphraseRequiredForKey(e) {
486
506
  return new Promise((r, t) => {
487
507
  try {
488
- return ct.utils.parseKey(e) instanceof Error && r(!0), r(!1);
508
+ return lt.utils.parseKey(e) instanceof Error && r(!0), r(!1);
489
509
  } catch (i) {
490
510
  console.log("Error parsing privateKey"), t(new Error(`ssh.isPassphraseRequiredForKey: err ${i}`));
491
511
  }
@@ -499,13 +519,13 @@ class B {
499
519
  * @returns A promise resolving with `true` if the file was successfully uploaded.
500
520
  */
501
521
  async uploadFile(e, r) {
502
- return await this.withSftp(async (t) => new Promise((i, o) => {
522
+ return await this.withSftp(async (t) => new Promise((i, n) => {
503
523
  t.fastPut(e, r, (s) => {
504
524
  if (s) {
505
525
  const a = new Error(
506
526
  `ssh.uploadFile: err: ${s}, localPath: ${e}, remotePath: ${r}`
507
527
  );
508
- return o(a);
528
+ return n(a);
509
529
  }
510
530
  i(!0);
511
531
  });
@@ -513,13 +533,13 @@ class B {
513
533
  }
514
534
  async withSftp(e) {
515
535
  return new Promise((r, t) => {
516
- this.client.sftp((i, o) => {
536
+ this.client.sftp((i, n) => {
517
537
  if (i)
518
538
  return t(new Error(`ssh.withSftp: sftp err: ${i}`));
519
- e(o).then(r).catch((s) => {
539
+ e(n).then(r).catch((s) => {
520
540
  t(new Error(`ssh.withSftp.callback: err ${s}`));
521
541
  }).finally(() => {
522
- o == null || o.end();
542
+ n == null || n.end();
523
543
  });
524
544
  });
525
545
  });
@@ -528,10 +548,10 @@ class B {
528
548
  return this.withSftp(async (i) => this.writeFile(i, e, r, t));
529
549
  }
530
550
  async getForderStructure(e, r, t = { files: [], directories: [] }) {
531
- return new Promise((i, o) => {
551
+ return new Promise((i, n) => {
532
552
  e.readdir(r, async (s, a) => {
533
553
  if (s)
534
- return o(s);
554
+ return n(s);
535
555
  for (const c of a) {
536
556
  const l = `${r}/${c.filename}`;
537
557
  if (c.attrs.isDirectory()) {
@@ -539,7 +559,7 @@ class B {
539
559
  try {
540
560
  await this.getForderStructure(e, l, t);
541
561
  } catch (h) {
542
- return o(h instanceof Error ? h : new Error(String(h)));
562
+ return n(h instanceof Error ? h : new Error(String(h)));
543
563
  }
544
564
  } else
545
565
  t.files.push(l);
@@ -550,12 +570,12 @@ class B {
550
570
  }
551
571
  rmdir(e, r) {
552
572
  return new Promise((t, i) => {
553
- e.rmdir(r, (o) => o ? i(o) : t(!0));
573
+ e.rmdir(r, (n) => n ? i(n) : t(!0));
554
574
  });
555
575
  }
556
576
  unlink(e, r) {
557
577
  return new Promise((t, i) => {
558
- e.unlink(r, (o) => o ? i(o) : t(!0));
578
+ e.unlink(r, (n) => n ? i(n) : t(!0));
559
579
  });
560
580
  }
561
581
  async deleteFolder(e) {
@@ -565,7 +585,7 @@ class B {
565
585
  this.logger.info("ssh.deleteFolder list of files and directories"), this.logger.info(`ssh.deleteFolder list of files: ${t.files}`), this.logger.info(`ssh.deleteFolder list of directories: ${t.directories}`);
566
586
  for (const i of t.files)
567
587
  this.logger.info(`ssh.deleteFolder unlink file ${i}`), await this.unlink(r, i);
568
- t.directories.sort((i, o) => o.length - i.length);
588
+ t.directories.sort((i, n) => n.length - i.length);
569
589
  for (const i of t.directories)
570
590
  this.logger.info(`ssh.deleteFolder rmdir ${i}`), await this.rmdir(r, i);
571
591
  return await this.rmdir(r, e), !0;
@@ -578,32 +598,32 @@ class B {
578
598
  }
579
599
  async readFile(e) {
580
600
  return this.withSftp(async (r) => new Promise((t, i) => {
581
- r.readFile(e, (o, s) => {
582
- if (o)
583
- return i(new Error(`ssh.readFile: ${o}`));
601
+ r.readFile(e, (n, s) => {
602
+ if (n)
603
+ return i(new Error(`ssh.readFile: ${n}`));
584
604
  t(s.toString());
585
605
  });
586
606
  }));
587
607
  }
588
608
  async chmod(e, r) {
589
- return this.withSftp(async (t) => new Promise((i, o) => {
590
- t.chmod(e, r, (s) => s ? o(new Error(`ssh.chmod: ${s}, path: ${e}, mode: ${r}`)) : i(void 0));
609
+ return this.withSftp(async (t) => new Promise((i, n) => {
610
+ t.chmod(e, r, (s) => s ? n(new Error(`ssh.chmod: ${s}, path: ${e}, mode: ${r}`)) : i(void 0));
591
611
  }));
592
612
  }
593
613
  async checkFileExists(e) {
594
614
  return this.withSftp(async (r) => new Promise((t, i) => {
595
- r.stat(e, (o, s) => {
596
- if (o)
597
- return (o == null ? void 0 : o.code) === 2 ? t(!1) : i(new Error(`ssh.checkFileExists: err ${o}`));
615
+ r.stat(e, (n, s) => {
616
+ if (n)
617
+ return (n == null ? void 0 : n.code) === 2 ? t(!1) : i(new Error(`ssh.checkFileExists: err ${n}`));
598
618
  t(s.isFile());
599
619
  });
600
620
  }));
601
621
  }
602
622
  async checkPathExists(e) {
603
623
  return this.withSftp(async (r) => new Promise((t, i) => {
604
- r.stat(e, (o, s) => {
605
- if (o)
606
- return o.code === 2 ? t({ exists: !1, isFile: !1, isDirectory: !1 }) : i(new Error(`ssh.checkPathExists: ${o}`));
624
+ r.stat(e, (n, s) => {
625
+ if (n)
626
+ return n.code === 2 ? t({ exists: !1, isFile: !1, isDirectory: !1 }) : i(new Error(`ssh.checkPathExists: ${n}`));
607
627
  t({
608
628
  exists: !0,
609
629
  isFile: s.isFile(),
@@ -613,18 +633,18 @@ class B {
613
633
  }));
614
634
  }
615
635
  async writeFile(e, r, t, i = 432) {
616
- return new Promise((o, s) => {
636
+ return new Promise((n, s) => {
617
637
  e.writeFile(r, t, { mode: i }, (a) => {
618
638
  if (a)
619
639
  return s(new Error(`ssh.writeFile: err ${a}, remotePath: ${r}`));
620
- o(!0);
640
+ n(!0);
621
641
  });
622
642
  });
623
643
  }
624
644
  uploadFileUsingExistingSftp(e, r, t, i = 432) {
625
- return new Promise((o, s) => {
645
+ return new Promise((n, s) => {
626
646
  rt(r).then(async (a) => this.writeFile(e, t, a, i).then(() => {
627
- o(void 0);
647
+ n(void 0);
628
648
  }).catch((c) => {
629
649
  const l = `uploadFileUsingExistingSftp: ${c}`;
630
650
  this.logger.error(l), s(new Error(l));
@@ -632,17 +652,17 @@ class B {
632
652
  });
633
653
  }
634
654
  async __uploadDirectory(e, r, t, i = 432) {
635
- return new Promise((o, s) => {
636
- D.readdir(r, async (a, c) => {
655
+ return new Promise((n, s) => {
656
+ O.readdir(r, async (a, c) => {
637
657
  if (a)
638
658
  return s(new Error(`ssh.__uploadDir: err ${a}, localDir: ${r}, remoteDir: ${t}`));
639
659
  try {
640
660
  await this.__createRemoteDirectory(e, t);
641
661
  for (const l of c) {
642
662
  const h = u.join(r, l), d = `${t}/${l}`;
643
- D.lstatSync(h).isDirectory() ? await this.__uploadDirectory(e, h, d, i) : await this.uploadFileUsingExistingSftp(e, h, d, i);
663
+ O.lstatSync(h).isDirectory() ? await this.__uploadDirectory(e, h, d, i) : await this.uploadFileUsingExistingSftp(e, h, d, i);
644
664
  }
645
- o();
665
+ n();
646
666
  } catch (l) {
647
667
  const h = `ssh.__uploadDir: catched err ${l}`;
648
668
  this.logger.error(h), s(new Error(h));
@@ -657,12 +677,12 @@ class B {
657
677
  * @returns A promise that resolves when the directory and its contents are uploaded.
658
678
  */
659
679
  async uploadDirectory(e, r, t = 432) {
660
- return new Promise((i, o) => {
680
+ return new Promise((i, n) => {
661
681
  this.withSftp(async (s) => {
662
682
  try {
663
683
  await this.__uploadDirectory(s, e, r, t), i();
664
684
  } catch (a) {
665
- o(new Error(`ssh.uploadDirectory: ${a}`));
685
+ n(new Error(`ssh.uploadDirectory: ${a}`));
666
686
  }
667
687
  });
668
688
  });
@@ -675,12 +695,12 @@ class B {
675
695
  */
676
696
  __createRemoteDirectory(e, r) {
677
697
  return new Promise((t, i) => {
678
- const o = r.split("/");
698
+ const n = r.split("/");
679
699
  let s = "";
680
700
  const a = (c) => {
681
- if (c >= o.length)
701
+ if (c >= n.length)
682
702
  return t();
683
- s += `${o[c]}/`, e.stat(s, (l) => {
703
+ s += `${n[c]}/`, e.stat(s, (l) => {
684
704
  l ? e.mkdir(s, (h) => {
685
705
  if (h)
686
706
  return i(new Error(`ssh.__createRemDir: err ${h}, remotePath: ${r}`));
@@ -700,14 +720,14 @@ class B {
700
720
  ensureRemoteDirCreated(e, r = 493) {
701
721
  return this.withSftp(async (t) => {
702
722
  const i = e.split("/");
703
- let o = "";
723
+ let n = "";
704
724
  for (const s of i) {
705
- o += `${s}/`;
725
+ n += `${s}/`;
706
726
  try {
707
727
  await new Promise((a, c) => {
708
- t.stat(o, (l) => {
728
+ t.stat(n, (l) => {
709
729
  if (!l) return a();
710
- t.mkdir(o, { mode: r }, (h) => {
730
+ t.mkdir(n, { mode: r }, (h) => {
711
731
  if (h)
712
732
  return c(new Error(`ssh.createRemoteDir: err ${h}, remotePath: ${e}`));
713
733
  a();
@@ -715,7 +735,7 @@ class B {
715
735
  });
716
736
  });
717
737
  } catch (a) {
718
- throw console.error(`Failed to create directory: ${o}`, a), a;
738
+ throw console.error(`Failed to create directory: ${n}`, a), a;
719
739
  }
720
740
  }
721
741
  });
@@ -727,10 +747,10 @@ class B {
727
747
  * @returns A promise resolving with `true` if the file was successfully downloaded.
728
748
  */
729
749
  async downloadFile(e, r) {
730
- return this.withSftp(async (t) => new Promise((i, o) => {
750
+ return this.withSftp(async (t) => new Promise((i, n) => {
731
751
  t.fastGet(e, r, (s) => {
732
752
  if (s)
733
- return o(new Error(`ssh.downloadFile: err ${s}, remotePath: ${e}, localPath: ${r}`));
753
+ return n(new Error(`ssh.downloadFile: err ${s}, remotePath: ${e}, localPath: ${r}`));
734
754
  i(!0);
735
755
  });
736
756
  }));
@@ -742,69 +762,69 @@ class B {
742
762
  this.closeForwardedPorts(), this.client.end();
743
763
  }
744
764
  }
745
- async function Rt(n, e, r, t) {
746
- return new Promise((i, o) => {
747
- n.on("ready", () => {
748
- i(n);
749
- }), n.on("error", (s) => {
750
- o(new Error(`ssh.connect: ${s}`));
751
- }), n.on("close", () => {
752
- }), n.connect(e), n.setNoDelay(!0);
765
+ async function Ut(o, e, r, t) {
766
+ return new Promise((i, n) => {
767
+ o.on("ready", () => {
768
+ i(o);
769
+ }), o.on("error", (s) => {
770
+ n(new Error(`ssh.connect: ${s}`));
771
+ }), o.on("close", () => {
772
+ }), o.connect(e), o.setNoDelay(!0);
753
773
  });
754
774
  }
755
- async function Nt(n, e, r, t, i, o) {
775
+ async function _t(o, e, r, t, i, n) {
756
776
  return new Promise((s, a) => {
757
- e.forwardOut(r, t, i, o, (c, l) => c ? (n.error(`forwardOut.error: ${c}`), a(c)) : s(l));
777
+ e.forwardOut(r, t, i, n, (c, l) => c ? (o.error(`forwardOut.error: ${c}`), a(c)) : s(l));
758
778
  });
759
779
  }
760
- const Bt = "minio-2024-12-18T13-15-44Z", Ut = "supervisord-0.7.3", _t = "supervisord_0.7.3_Linux_64-bit";
761
- function g(n) {
762
- return u.join(n, ".platforma_ssh");
780
+ const Tt = "minio-2024-12-18T13-15-44Z", It = "supervisord-0.7.3", jt = "supervisord_0.7.3_Linux_64-bit";
781
+ function y(o) {
782
+ return u.join(o, ".platforma_ssh");
763
783
  }
764
- function E(n) {
765
- return u.join(g(n), "binaries");
784
+ function E(o) {
785
+ return u.join(y(o), "binaries");
766
786
  }
767
- function Tt(n, e) {
768
- return u.join(E(n), `pl-${R()}-${P(e)}`);
787
+ function Ht(o, e) {
788
+ return u.join(E(o), `pl-${R()}-${P(e)}`);
769
789
  }
770
- function V(n, e) {
771
- return u.join(Tt(n, e), "binaries");
790
+ function V(o, e) {
791
+ return u.join(Ht(o, e), "binaries");
772
792
  }
773
- function _(n, e) {
774
- return u.join(V(n, e), "platforma");
793
+ function _(o, e) {
794
+ return u.join(V(o, e), "platforma");
775
795
  }
776
- function It(n, e) {
777
- return u.join(V(n, e), "free-port");
796
+ function Gt(o, e) {
797
+ return u.join(V(o, e), "free-port");
778
798
  }
779
- function q(n, e) {
780
- return u.join(E(n), `minio-2024-12-18T13-15-44Z-${P(e)}`);
799
+ function q(o, e) {
800
+ return u.join(E(o), `minio-2024-12-18T13-15-44Z-${P(e)}`);
781
801
  }
782
- function jt(n, e) {
783
- return u.join(q(n, e), "minio");
802
+ function Mt(o, e) {
803
+ return u.join(q(o, e), "minio");
784
804
  }
785
- function Ht(n, e) {
786
- return u.join(E(n), `supervisord-0.7.3-${P(e)}`, _t);
805
+ function Jt(o, e) {
806
+ return u.join(E(o), `supervisord-0.7.3-${P(e)}`, jt);
787
807
  }
788
- function z(n, e) {
789
- return u.join(Ht(n, e), "supervisord");
808
+ function z(o, e) {
809
+ return u.join(Jt(o, e), "supervisord");
790
810
  }
791
- function K(n) {
792
- return u.join(g(n), "supervisor.conf");
811
+ function K(o) {
812
+ return u.join(y(o), "supervisor.conf");
793
813
  }
794
- function T(n) {
795
- return u.join(g(n), "connection.txt");
814
+ function T(o) {
815
+ return u.join(y(o), "connection.txt");
796
816
  }
797
- async function Gt(n, e, r) {
798
- const t = await U(n, e, r, "--daemon");
817
+ async function Lt(o, e, r) {
818
+ const t = await U(o, e, r, "--daemon");
799
819
  if (t.stderr)
800
820
  throw new Error(`Can not run ssh Platforma ${t.stderr}`);
801
821
  }
802
- async function Mt(n, e, r) {
803
- const t = await U(n, e, r, "ctl shutdown");
822
+ async function Wt(o, e, r) {
823
+ const t = await U(o, e, r, "ctl shutdown");
804
824
  if (t.stderr)
805
825
  throw new Error(`Can not stop ssh Platforma ${t.stderr}`);
806
826
  }
807
- async function Jt(n, e, r, t) {
827
+ async function Vt(o, e, r, t) {
808
828
  let i;
809
829
  try {
810
830
  i = await U(e, r, t, "ctl status");
@@ -812,17 +832,17 @@ async function Jt(n, e, r, t) {
812
832
  return { execError: String(c), allAlive: !1 };
813
833
  }
814
834
  if (i.stderr)
815
- return n.info(`supervisord ctl status: stderr occurred: ${i.stderr}, stdout: ${i.stdout}`), { rawResult: i, allAlive: !1 };
816
- const o = I(i.stdout, "platforma"), s = I(i.stdout, "minio"), a = {
835
+ return o.info(`supervisord ctl status: stderr occurred: ${i.stderr}, stdout: ${i.stdout}`), { rawResult: i, allAlive: !1 };
836
+ const n = I(i.stdout, "platforma"), s = I(i.stdout, "minio"), a = {
817
837
  rawResult: i,
818
- platforma: o,
838
+ platforma: n,
819
839
  minio: s,
820
- allAlive: o && s
840
+ allAlive: n && s
821
841
  };
822
- return a.allAlive || (a.minio || n.warn("Minio is not running on the server"), a.platforma || n.warn("Platforma is not running on the server")), a;
842
+ return a.allAlive || (a.minio || o.warn("Minio is not running on the server"), a.platforma || o.warn("Platforma is not running on the server")), a;
823
843
  }
824
- function Lt(n, e, r, t, i, o, s) {
825
- const a = Object.entries(e).map(([h, d]) => `${h}="${d}"`).join(","), c = k(16).toString("hex"), l = r;
844
+ function qt(o, e, r, t, i, n, s) {
845
+ const a = Object.entries(e).map(([h, d]) => `${h}="${d}"`).join(","), c = D(16).toString("hex"), l = r;
826
846
  return `
827
847
  [supervisord]
828
848
  logfile=${t}/supervisord.log
@@ -849,55 +869,55 @@ autorestart=true
849
869
  [program:minio]
850
870
  autostart=true
851
871
  environment=${a}
852
- command=${o} server ${n}
872
+ command=${n} server ${o}
853
873
  directory=${t}
854
874
  autorestart=true
855
875
  `;
856
876
  }
857
- async function U(n, e, r, t) {
858
- const i = z(e, r), o = K(e), s = `${i} --configuration ${o} ${t}`;
859
- return await n.exec(s);
877
+ async function U(o, e, r, t) {
878
+ const i = z(e, r), n = K(e), s = `${i} --configuration ${n} ${t}`;
879
+ return await o.exec(s);
860
880
  }
861
- function I(n, e) {
862
- return ((i) => i.replace(/\x1B\[[0-9;]*m/g, ""))(n).split(`
881
+ function I(o, e) {
882
+ return ((i) => i.replace(/\x1B\[[0-9;]*m/g, ""))(o).split(`
863
883
  `).some((i) => {
864
- const [o, s] = i.trim().split(/\s{2,}/);
865
- return o === e && s === "Running";
884
+ const [n, s] = i.trim().split(/\s{2,}/);
885
+ return n === e && s === "Running";
866
886
  });
867
887
  }
868
- const S = p.object({
869
- local: p.number(),
870
- remote: p.number()
871
- }), Wt = p.object({
888
+ const S = m.object({
889
+ local: m.number(),
890
+ remote: m.number()
891
+ }), zt = m.object({
872
892
  grpc: S,
873
893
  monitoring: S,
874
894
  debug: S,
875
895
  minioPort: S,
876
896
  minioConsolePort: S
877
- }), Vt = p.object({
878
- plUser: p.string(),
879
- plPassword: p.string(),
880
- ports: Wt,
897
+ }), Kt = m.object({
898
+ plUser: m.string(),
899
+ plPassword: m.string(),
900
+ ports: zt,
881
901
  // It's false by default because it was added later,
882
902
  // and in some deployments there won't be useGlobalAccess flag in the file.
883
- useGlobalAccess: p.boolean().default(!1),
903
+ useGlobalAccess: m.boolean().default(!1),
884
904
  // We added the field afterwards, the pl backend was this version.
885
- plVersion: p.string().default("1.18.3")
905
+ plVersion: m.string().default("1.18.3")
886
906
  });
887
- function qt(n, e, r, t, i) {
907
+ function Zt(o, e, r, t, i) {
888
908
  return {
889
- plUser: n,
909
+ plUser: o,
890
910
  plPassword: e,
891
911
  ports: r,
892
912
  useGlobalAccess: t,
893
913
  plVersion: i
894
914
  };
895
915
  }
896
- function zt(n) {
897
- return Vt.parse(JSON.parse(n));
916
+ function Xt(o) {
917
+ return Kt.parse(JSON.parse(o));
898
918
  }
899
- function Kt(n) {
900
- return JSON.stringify(n, void 0, 2);
919
+ function Yt(o) {
920
+ return JSON.stringify(o, void 0, 2);
901
921
  }
902
922
  const j = 2.28;
903
923
  class Z {
@@ -914,7 +934,7 @@ class Z {
914
934
  static async init(e, r) {
915
935
  try {
916
936
  const t = await B.init(e, r);
917
- return new Z(e, t, f(r.username));
937
+ return new Z(e, t, p(r.username));
918
938
  } catch (t) {
919
939
  throw e.error(`Connection error in SshClient.init: ${t}`), t;
920
940
  }
@@ -925,7 +945,7 @@ class Z {
925
945
  /** Provides an info if the platforma and minio are running along with the debug info. */
926
946
  async isAlive() {
927
947
  const e = await this.getArch(), r = await this.getUserHomeDirectory();
928
- return await Jt(this.logger, this.sshClient, r, e.arch);
948
+ return await Vt(this.logger, this.sshClient, r, e.arch);
929
949
  }
930
950
  /** Starts all the services on the server.
931
951
  * Idempotent semantic: we could call it several times. */
@@ -933,7 +953,7 @@ class Z {
933
953
  const e = await this.getArch(), r = await this.getUserHomeDirectory();
934
954
  try {
935
955
  if (!(await this.isAlive()).allAlive)
936
- return await Gt(this.sshClient, r, e.arch), await this.checkIsAliveWithInterval();
956
+ return await Lt(this.sshClient, r, e.arch), await this.checkIsAliveWithInterval();
937
957
  } catch (t) {
938
958
  const i = `SshPl.start: ${t}`;
939
959
  throw this.logger.error(i), new Error(i);
@@ -945,7 +965,7 @@ class Z {
945
965
  const e = await this.getArch(), r = await this.getUserHomeDirectory();
946
966
  try {
947
967
  if ((await this.isAlive()).allAlive)
948
- return await Mt(this.sshClient, r, e.arch), await this.checkIsAliveWithInterval(void 0, void 0, !1);
968
+ return await Wt(this.sshClient, r, e.arch), await this.checkIsAliveWithInterval(void 0, void 0, !1);
949
969
  } catch (t) {
950
970
  const i = `PlSsh.stop: ${t}`;
951
971
  throw this.logger.error(i), new Error(i);
@@ -958,7 +978,7 @@ class Z {
958
978
  /** Stops platforma and deletes its state. */
959
979
  async stopAndClean() {
960
980
  const e = await this.getUserHomeDirectory();
961
- this.logger.info("pl.reset: Stop Platforma on the server"), await this.stop(), this.logger.info(`pl.reset: Deleting Platforma workDir ${g(e)} on the server`), await this.sshClient.deleteFolder(g(e));
981
+ this.logger.info("pl.reset: Stop Platforma on the server"), await this.stop(), this.logger.info(`pl.reset: Deleting Platforma workDir ${y(e)} on the server`), await this.sshClient.deleteFolder(y(e));
962
982
  }
963
983
  /** Downloads binaries and untar them on the server,
964
984
  * generates all the configs, creates necessary dirs,
@@ -967,7 +987,7 @@ class Z {
967
987
  const r = { localWorkdir: e.localWorkdir }, { onProgress: t } = e;
968
988
  try {
969
989
  const i = {
970
- ...Zt,
990
+ ...Qt,
971
991
  ...e
972
992
  };
973
993
  if (r.plBinaryOps = i.plBinary, await (t == null ? void 0 : t("Detecting server architecture...")), r.arch = await this.getArch(), await (t == null ? void 0 : t("Server architecture detected.")), await (t == null ? void 0 : t("Fetching user home directory...")), r.remoteHome = await this.getUserHomeDirectory(), await (t == null ? void 0 : t("User home directory retrieved.")), await (t == null ? void 0 : t("Checking platform status...")), r.alive = await this.isAlive(), r.alive.allAlive && await (t == null ? void 0 : t("All required services are running.")), r.alive.allAlive) {
@@ -979,9 +999,9 @@ class Z {
979
999
  await (t == null ? void 0 : t("Stopping services...")), await this.stop();
980
1000
  }
981
1001
  await (t == null ? void 0 : t("Downloading and uploading required binaries..."));
982
- const o = await Yt(this.logger, this.sshClient);
983
- if (o < j)
984
- throw new Error(`glibc version ${o} is too old. Version ${j} or higher is required for Platforma.`);
1002
+ const n = await tr(this.logger, this.sshClient);
1003
+ if (n < j)
1004
+ throw new Error(`glibc version ${n} is too old. Version ${j} or higher is required for Platforma.`);
985
1005
  const s = await this.downloadBinariesAndUploadToTheServer(
986
1006
  i.localWorkdir,
987
1007
  i.plBinary,
@@ -991,9 +1011,9 @@ class Z {
991
1011
  if (await (t == null ? void 0 : t("All required binaries have been downloaded and uploaded.")), r.binPaths = { ...s, history: void 0 }, r.downloadedBinaries = s.history, r.ports = await this.fetchPorts(r.remoteHome, r.arch), !r.ports.debug.remote || !r.ports.grpc.remote || !r.ports.minioPort.remote || !r.ports.minioConsolePort.remote || !r.ports.monitoring.remote)
992
1012
  throw new Error("SshPl.platformaInit: remote ports are not defined");
993
1013
  await (t == null ? void 0 : t("Generating server configuration..."));
994
- const a = await ht({
1014
+ const a = await dt({
995
1015
  logger: this.logger,
996
- workingDir: g(r.remoteHome),
1016
+ workingDir: y(r.remoteHome),
997
1017
  portsMode: {
998
1018
  type: "customWithMinio",
999
1019
  ports: {
@@ -1007,7 +1027,7 @@ class Z {
1007
1027
  }
1008
1028
  },
1009
1029
  licenseMode: i.license,
1010
- useGlobalAccess: f(i.useGlobalAccess),
1030
+ useGlobalAccess: p(i.useGlobalAccess),
1011
1031
  plConfigPostprocessing: i.plConfigPostprocessing
1012
1032
  });
1013
1033
  r.generatedConfig = { ...a, filesToCreate: { skipped: "it is too wordy" } }, await (t == null ? void 0 : t("Server configuration generated.")), await (t == null ? void 0 : t("Generating folder structure..."));
@@ -1016,7 +1036,7 @@ class Z {
1016
1036
  for (const h of a.dirsToCreate)
1017
1037
  await this.sshClient.ensureRemoteDirCreated(h), this.logger.info(`Created directory ${h}`);
1018
1038
  await (t == null ? void 0 : t("Folder structure created.")), await (t == null ? void 0 : t("Writing supervisord configuration..."));
1019
- const c = Lt(
1039
+ const c = qt(
1020
1040
  a.minioConfig.storageDir,
1021
1041
  a.minioConfig.envs,
1022
1042
  await this.getFreePortForPlatformaOnServer(r.remoteHome, r.arch),
@@ -1026,24 +1046,24 @@ class Z {
1026
1046
  r.binPaths.downloadedPl
1027
1047
  );
1028
1048
  if (!await this.sshClient.writeFileOnTheServer(K(r.remoteHome), c))
1029
- throw new Error(`Can not write supervisord config on the server ${g(r.remoteHome)}`);
1030
- return await (t == null ? void 0 : t("Supervisord configuration written.")), await (t == null ? void 0 : t("Saving connection information...")), r.connectionInfo = qt(
1049
+ throw new Error(`Can not write supervisord config on the server ${y(r.remoteHome)}`);
1050
+ return await (t == null ? void 0 : t("Supervisord configuration written.")), await (t == null ? void 0 : t("Saving connection information...")), r.connectionInfo = Zt(
1031
1051
  a.plUser,
1032
1052
  a.plPassword,
1033
1053
  r.ports,
1034
- f(i.useGlobalAccess),
1054
+ p(i.useGlobalAccess),
1035
1055
  i.plBinary.version
1036
1056
  ), await this.sshClient.writeFileOnTheServer(
1037
1057
  T(r.remoteHome),
1038
- Kt(r.connectionInfo)
1058
+ Yt(r.connectionInfo)
1039
1059
  ), await (t == null ? void 0 : t("Connection information saved.")), await (t == null ? void 0 : t("Starting Platforma on the server...")), await this.start(), r.started = !0, this.initState = r, await (t == null ? void 0 : t("Platforma has been started successfully.")), r.connectionInfo;
1040
1060
  } catch (i) {
1041
- const o = `SshPl.platformaInit: ${i}, state: ${JSON.stringify(r)}`;
1042
- throw this.logger.error(o), new Error(o);
1061
+ const n = `SshPl.platformaInit: ${i}, state: ${JSON.stringify(r)}`;
1062
+ throw this.logger.error(n), new Error(n);
1043
1063
  }
1044
1064
  }
1045
1065
  async downloadBinariesAndUploadToTheServer(e, r, t, i) {
1046
- const o = [];
1066
+ const n = [];
1047
1067
  try {
1048
1068
  const s = await this.downloadAndUntar(
1049
1069
  e,
@@ -1052,29 +1072,29 @@ class Z {
1052
1072
  "pl",
1053
1073
  `pl-${r.version}`
1054
1074
  );
1055
- o.push(s);
1075
+ n.push(s);
1056
1076
  const a = await this.downloadAndUntar(
1057
1077
  e,
1058
1078
  t,
1059
1079
  i,
1060
1080
  "supervisord",
1061
- Ut
1081
+ It
1062
1082
  );
1063
- o.push(a);
1064
- const c = jt(t, i.arch), l = await this.downloadAndUntar(
1083
+ n.push(a);
1084
+ const c = Mt(t, i.arch), l = await this.downloadAndUntar(
1065
1085
  e,
1066
1086
  t,
1067
1087
  i,
1068
1088
  "minio",
1069
- Bt
1089
+ Tt
1070
1090
  );
1071
- return o.push(l), await this.sshClient.chmod(c, 488), {
1072
- history: o,
1091
+ return n.push(l), await this.sshClient.chmod(c, 488), {
1092
+ history: n,
1073
1093
  minioRelPath: c,
1074
1094
  downloadedPl: _(t, i.arch)
1075
1095
  };
1076
1096
  } catch (s) {
1077
- const a = `SshPl.downloadBinariesAndUploadToServer: ${s}, state: ${JSON.stringify(o)}`;
1097
+ const a = `SshPl.downloadBinariesAndUploadToServer: ${s}, state: ${JSON.stringify(n)}`;
1078
1098
  throw this.logger.error(a), s;
1079
1099
  }
1080
1100
  }
@@ -1084,18 +1104,18 @@ class Z {
1084
1104
  * For this reason, we extract all to the remote server.
1085
1105
  * It requires `tar` to be installed on the server
1086
1106
  * (it's not installed for Rocky Linux for example). */
1087
- async downloadAndUntar(e, r, t, i, o) {
1107
+ async downloadAndUntar(e, r, t, i, n) {
1088
1108
  const s = {};
1089
1109
  s.binBasePath = E(r), await this.sshClient.ensureRemoteDirCreated(s.binBasePath), s.binBasePathCreated = !0;
1090
1110
  let a = null;
1091
1111
  const c = 5;
1092
1112
  for (let h = 1; h <= c; h++)
1093
1113
  try {
1094
- a = await mt(
1114
+ a = await gt(
1095
1115
  this.logger,
1096
1116
  e,
1097
1117
  i,
1098
- o,
1118
+ n,
1099
1119
  t.arch,
1100
1120
  t.platform
1101
1121
  );
@@ -1104,7 +1124,7 @@ class Z {
1104
1124
  if (await F(300), h == c)
1105
1125
  throw new Error(`downloadAndUntar: ${c} attempts, last error: ${d}`);
1106
1126
  }
1107
- s.downloadResult = f(a), s.localArchivePath = u.resolve(s.downloadResult.archivePath), s.remoteDir = u.join(s.binBasePath, s.downloadResult.baseName), s.remoteArchivePath = s.remoteDir + ".tgz", await this.sshClient.ensureRemoteDirCreated(s.remoteDir), await this.sshClient.uploadFile(s.localArchivePath, s.remoteArchivePath), s.uploadDone = !0;
1127
+ s.downloadResult = p(a), s.localArchivePath = u.resolve(s.downloadResult.archivePath), s.remoteDir = u.join(s.binBasePath, s.downloadResult.baseName), s.remoteArchivePath = s.remoteDir + ".tgz", await this.sshClient.ensureRemoteDirCreated(s.remoteDir), await this.sshClient.uploadFile(s.localArchivePath, s.remoteArchivePath), s.uploadDone = !0;
1108
1128
  try {
1109
1129
  await this.sshClient.exec("hash tar");
1110
1130
  } catch {
@@ -1118,21 +1138,21 @@ class Z {
1118
1138
  return s.untarDone = !0, s;
1119
1139
  }
1120
1140
  async needDownload(e, r) {
1121
- const t = z(e, r.arch), i = q(e, r.arch), o = _(e, r.arch);
1122
- return !await this.sshClient.checkFileExists(o) || !await this.sshClient.checkFileExists(i) || !await this.sshClient.checkFileExists(t);
1141
+ const t = z(e, r.arch), i = q(e, r.arch), n = _(e, r.arch);
1142
+ return !await this.sshClient.checkFileExists(n) || !await this.sshClient.checkFileExists(i) || !await this.sshClient.checkFileExists(t);
1123
1143
  }
1124
1144
  async checkIsAliveWithInterval(e = 1e3, r = 15, t = !0) {
1125
1145
  const i = r * e;
1126
- let o = 0, s = await this.isAlive();
1146
+ let n = 0, s = await this.isAlive();
1127
1147
  for (; t ? !s.allAlive : s.allAlive; ) {
1128
- if (await F(e), o += e, o > i)
1148
+ if (await F(e), n += e, n > i)
1129
1149
  throw new Error(`isAliveWithInterval: The process did not ${t ? "started" : "stopped"} after ${i} ms. Live status: ${JSON.stringify(s)}`);
1130
1150
  s = await this.isAlive();
1131
1151
  }
1132
1152
  }
1133
1153
  async getUserCredentials(e) {
1134
1154
  const r = await this.sshClient.readFile(T(e));
1135
- return zt(r);
1155
+ return Xt(r);
1136
1156
  }
1137
1157
  async fetchPorts(e, r) {
1138
1158
  return {
@@ -1168,9 +1188,9 @@ class Z {
1168
1188
  });
1169
1189
  }
1170
1190
  async getFreePortForPlatformaOnServer(e, r) {
1171
- const t = It(e, r.arch), { stdout: i, stderr: o } = await this.sshClient.exec(`${t}`);
1172
- if (o)
1173
- throw new Error(`getFreePortForPlatformaOnServer: stderr is not empty: ${o}, stdout: ${i}`);
1191
+ const t = Gt(e, r.arch), { stdout: i, stderr: n } = await this.sshClient.exec(`${t}`);
1192
+ if (n)
1193
+ throw new Error(`getFreePortForPlatformaOnServer: stderr is not empty: ${n}, stdout: ${i}`);
1174
1194
  return +i;
1175
1195
  }
1176
1196
  async getArch() {
@@ -1193,42 +1213,44 @@ class Z {
1193
1213
  return e.trim();
1194
1214
  }
1195
1215
  }
1196
- const Zt = {
1216
+ const Qt = {
1197
1217
  useGlobalAccess: !1,
1198
1218
  plBinary: {
1199
1219
  type: "Download",
1200
1220
  version: R()
1201
1221
  }
1202
1222
  };
1203
- async function Yt(n, e) {
1223
+ async function tr(o, e) {
1204
1224
  try {
1205
1225
  const { stdout: r, stderr: t } = await e.exec("ldd --version | head -n 1");
1206
1226
  if (t)
1207
1227
  throw new Error(`Failed to check glibc version: ${t}`);
1208
- return Qt(r);
1228
+ return rr(r);
1209
1229
  } catch (r) {
1210
- throw n.error(`glibc version check failed: ${r}`), r;
1230
+ throw o.error(`glibc version check failed: ${r}`), r;
1211
1231
  }
1212
1232
  }
1213
- function Qt(n) {
1214
- const e = n.match(/\d+\.\d+/);
1233
+ function rr(o) {
1234
+ const e = o.match(/\d+\.\d+/);
1215
1235
  if (!e)
1216
- throw new Error(`Could not parse glibc version from: ${n}`);
1236
+ throw new Error(`Could not parse glibc version from: ${o}`);
1217
1237
  return parseFloat(e[0]);
1218
1238
  }
1219
1239
  export {
1220
- Vt as ConnectionInfo,
1240
+ Kt as ConnectionInfo,
1221
1241
  Dt as LocalConfigYaml,
1222
- kt as LocalPl,
1242
+ xt as LocalPl,
1223
1243
  S as PortPair,
1224
1244
  B as SshClient,
1225
1245
  Z as SshPl,
1226
- Wt as SshPlPorts,
1246
+ zt as SshPlPorts,
1227
1247
  R as getDefaultPlVersion,
1228
- mr as localPlatformaInit,
1229
- qt as newConnectionInfo,
1230
- zt as parseConnectionInfo,
1231
- Qt as parseGlibcVersion,
1232
- Kt as stringifyConnectionInfo
1248
+ vr as localPlatformaInit,
1249
+ Rt as mergeDefaultOps,
1250
+ Zt as newConnectionInfo,
1251
+ Xt as parseConnectionInfo,
1252
+ rr as parseGlibcVersion,
1253
+ Nt as plProcessOps,
1254
+ Yt as stringifyConnectionInfo
1233
1255
  };
1234
1256
  //# sourceMappingURL=index.mjs.map