@platforma-sdk/bootstrap 2.0.1 → 2.0.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.d.ts CHANGED
@@ -1,19 +1,19 @@
1
- import { default as Stop } from './commands/stop';
2
- import { default as Reset } from './commands/reset';
3
- import { default as Start } from './commands/start';
4
- import { default as Docker } from './commands/start/docker';
5
- import { default as S3 } from './commands/start/docker/s3';
6
- import { default as Local } from './commands/start/local';
7
- import { default as LocalS3 } from './commands/start/local/s3';
8
- import { default as CreateBlock } from './commands/create-block';
1
+ import { default as Cmd0 } from './commands/create-block';
2
+ import { default as Cmd1 } from './commands/reset';
3
+ import { default as Cmd2 } from './commands/start';
4
+ import { default as Cmd3 } from './commands/stop';
5
+ import { default as Cmd4 } from './commands/start/docker';
6
+ import { default as Cmd5 } from './commands/start/local';
7
+ import { default as Cmd6 } from './commands/start/docker/s3';
8
+ import { default as Cmd7 } from './commands/start/local/s3';
9
9
  export declare const COMMANDS: {
10
- stop: typeof Stop;
11
- start: typeof Start;
12
- reset: typeof Reset;
13
- 'create-block': typeof CreateBlock;
14
- 'start docker': typeof Docker;
15
- 'start local': typeof Local;
16
- 'start docker s3': typeof S3;
17
- 'start local s3': typeof LocalS3;
10
+ 'create-block': typeof Cmd0;
11
+ reset: typeof Cmd1;
12
+ start: typeof Cmd2;
13
+ stop: typeof Cmd3;
14
+ 'start:docker': typeof Cmd4;
15
+ 'start:local': typeof Cmd5;
16
+ 'start:docker:s3': typeof Cmd6;
17
+ 'start:local:s3': typeof Cmd7;
18
18
  };
19
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,KAAK,MAAM,kBAAkB,CAAC;AAErC,OAAO,KAAK,MAAM,kBAAkB,CAAC;AACrC,OAAO,MAAM,MAAM,yBAAyB,CAAC;AAC7C,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAC5C,OAAO,KAAK,MAAM,wBAAwB,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAE/D,OAAO,WAAW,MAAM,yBAAyB,CAAC;AAGlD,eAAO,MAAM,QAAQ;;;;;;;;;CASpB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,IAAI,MAAM,kBAAkB,CAAC;AACpC,OAAO,IAAI,MAAM,iBAAiB,CAAC;AACnC,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,IAAI,MAAM,wBAAwB,CAAC;AAC1C,OAAO,IAAI,MAAM,4BAA4B,CAAC;AAC9C,OAAO,IAAI,MAAM,2BAA2B,CAAC;AAG7C,eAAO,MAAM,QAAQ;;;;;;;;;CASpB,CAAC"}
package/dist/index.js CHANGED
@@ -1,13 +1,21 @@
1
- "use strict";var Xe=Object.defineProperty;var Ze=(a,e,r)=>e in a?Xe(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var y=(a,e,r)=>Ze(a,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@oclif/core"),$=require("node:child_process"),xe=require("yaml"),l=require("node:fs"),_=require("node:os"),f=require("node:path"),W=require("winston"),er=require("node:crypto"),K=require("readline-sync"),rr=require("node:https"),tr=require("tar"),ar=require("node:stream"),z=require("zod"),sr=require("decompress");function ir(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const r in a)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(a,r);Object.defineProperty(e,r,t.get?t:{enumerable:!0,get:()=>a[r]})}}return e.default=a,Object.freeze(e)}const cr=ir(tr);function Be(...a){return f.resolve(__dirname,"..",...a)}function O(...a){return Be("assets",...a)}function nr(){return l.readdirSync(O()).filter(e=>e.startsWith("compose-")&&e.endsWith(".yaml")).map(e=>O(e))}function Ge(...a){return l.readFileSync(Be(...a))}var te;function V(){return te||(te=JSON.parse(Ge("package.json").toString())),te}function ae(a){return a||(a=V()["pl-version"]),`quay.io/milaboratories/platforma:${a}`}function lr(a){return K.question(`${a} [y/N] `).toLowerCase()==="y"}function J(a){throw new Error("this should never happen")}function F(a="debug"){return W.createLogger({level:a,format:W.format.combine(W.format.printf(({level:e,message:r})=>{const t=" ".repeat(e.length+2),s=r.split(`
1
+ "use strict";var Xe=Object.defineProperty;var Ze=(a,e,r)=>e in a?Xe(a,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):a[e]=r;var y=(a,e,r)=>Ze(a,typeof e!="symbol"?e+"":e,r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("@oclif/core"),_=require("node:os"),l=require("node:fs"),f=require("node:path"),$=require("node:child_process"),W=require("winston"),er=require("node:crypto"),K=require("readline-sync"),rr=require("node:stream"),z=require("zod"),tr=require("decompress"),xe=require("yaml"),ar=require("node:https"),sr=require("tar");function ir(a){const e=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(a){for(const r in a)if(r!=="default"){const t=Object.getOwnPropertyDescriptor(a,r);Object.defineProperty(e,r,t.get?t:{enumerable:!0,get:()=>a[r]})}}return e.default=a,Object.freeze(e)}const cr=ir(sr),F={"log-level":d.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"],required:!1})},Be={image:d.Flags.string({description:"use custom docker image to run platforma"})},V={version:d.Flags.string({description:"use custom platforma release (official docker image or binary package)"})},Q={license:d.Flags.string({description:'pass a license code. The license can be got from "https://licensing.milaboratories.com".'}),"license-file":d.Flags.file({exists:!0,description:"specify a path to the file with a license. The license can be got from 'https://licensing.milaboratories.com'."})},X={"grpc-port":d.Flags.integer({description:"port for Platforma Backend gRPC API. Default is 6345",env:"PLATFORMA_GRPC_PORT"}),"grpc-listen":d.Flags.string({description:"full listen addr for Platforma Backend gRPC API. Default is 127.0.0.1:6345",env:"PLATFORMA_GRPC_LISTEN"}),"monitoring-port":d.Flags.integer({description:"port for Platforma Backend monitoring API. Default is 9090",env:"PLATFORMA_MONITORING_PORT"}),"monitoring-listen":d.Flags.string({description:"full listen addr for Platforma Backend monitoring API. Default is 127.0.0.1:9090",env:"PLATFORMA_MONITORING_LISTEN"}),"debug-port":d.Flags.integer({description:"port for Platforma Backend debug API. Default is 9091",env:"PLATFORMA_DEBUG_PORT"}),"debug-listen":d.Flags.string({description:"full listen addr for Platforma Backend debug API. Default is 127.0.0.1:9091",env:"PLATFORMA_DEBUG_LISTEN"})},nr={"s3-address-port":d.Flags.integer({description:"port that S3 will listen, default is 9000",default:9e3,env:"PLATFORMA_S3_PORT"}),"s3-console-address-port":d.Flags.integer({description:"port that a console of S3 will listen, default is 9001",default:9001,env:"PLATFORMA_S3_CONSOLE_PORT"})},Z={storage:d.Flags.string({description:"specify path on host to be used as storage for all Platforma Backend data"})},Ge={"pl-log-file":d.Flags.file({description:"specify path for Platforma Backend log file"})},Ue={"pl-workdir":d.Flags.file({description:"specify working directory for Platforma Backend process"})},je={"pl-binary":d.Flags.file({description:"start given Platforma Backend binary instead of automatically downloaded version"})},We={"pl-sources":d.Flags.file({description:"path to pl repository root: build Platforma Backend from sources and start the resulting binary"})},qe={config:d.Flags.string({description:"use custom Platforma Backend config"})};d.Flags.file({description:"specify path on host to be used as 'primary' storage"});const ue={"storage-work":d.Flags.file({description:"specify path on host to be used as 'work' storage"})};d.Flags.file({description:"specify path on host to be used as 'library' storage"});const fe={"storage-primary":d.Flags.string({description:`specify 'primary' storage destination URL.
2
+ file:/path/to/dir for directory on local FS
3
+ s3://<bucket>/?region=<name> for real AWS bucket
4
+ s3e://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via http
5
+ s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},he={"storage-library":d.Flags.string({description:`specify 'library' storage destination URL.
6
+ file:/path/to/dir for directory on local FS
7
+ s3://<bucket>/?region=<name> for real AWS bucket
8
+ s3e://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via http
9
+ s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},lr={"auth-enabled":d.Flags.boolean({description:"enable authorization"})},or={"auth-htpasswd-file":d.Flags.file({description:"path to .htpasswd file with Platforma users (static user DB auth source)"})},dr={"auth-ldap-server":d.Flags.string({description:"address of LDAP server to use for auth in Platforma (auth source)"})},gr={"auth-ldap-default-dn":d.Flags.string({description:"DN to use when checking user with LDAP bind operation: e.g. cn=%u,ou=users,dc=example,dc=com"})},ee={...lr,...or,...dr,...gr};function ur(a){return K.question(`${a} [y/N] `).toLowerCase()==="y"}function J(a){throw new Error("this should never happen")}function T(a="debug"){return W.createLogger({level:a,format:W.format.combine(W.format.printf(({level:e,message:r})=>{const t=" ".repeat(e.length+2),s=r.split(`
2
10
  `).map((c,n)=>n===0?c:t+c).join(`
3
- `);return`${(c=>W.format.colorize().colorize(c,c))(e)}: ${s}`})),transports:[new W.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function or(a){return er.randomBytes(Math.ceil(a/2)).toString("hex").slice(0,a)}function dr(a){return a.startsWith("~")?f.join(_.homedir(),a.slice(1)):a}function Y(a){l.existsSync(a)||l.mkdirSync(a,{recursive:!0})}function gr(a){try{if(_.platform()!=="win32")return $.execSync(`ps -p ${a} -o comm=`,{encoding:"utf8"}).trim();const e=`wmic process where processid=${a} get Caption`,r=$.execSync(e,{encoding:"utf8"}).split(`
4
- `);return r.length<=1?"":r[1].trim()}catch{return""}}const E=class E{constructor(e){y(this,"state",{lastRun:void 0,isActive:!1});y(this,"filePath");y(this,"dirPath");e=e??f.resolve(_.homedir(),".config","pl-bootstrap");const r=f.join(e,"state.json");this.dirPath=e,this.filePath=r,l.existsSync(e)||l.mkdirSync(e,{recursive:!0}),l.existsSync(r)&&(this.state=JSON.parse(Ge(r).toString()))}static getInstance(){return E.instance||(E.instance=new E),E.instance}path(...e){return f.join(this.dirPath,...e)}data(...e){return this.path("data",...e)}binaries(...e){return this.path("binaries",...e)}writeState(){l.writeFileSync(this.filePath,JSON.stringify(this.state))}get isActive(){var e,r;return this.state.isActive?this.state.isActive:(r=(e=this.state.lastRun)==null?void 0:e.process)!=null&&r.pid?this.isValidPID:!1}get isValidPID(){var r,t;if(!((t=(r=this.state.lastRun)==null?void 0:r.process)!=null&&t.pid))return!1;const e=gr(this.state.lastRun.process.pid);return e==="platforma"||e.endsWith("/platforma")||e.endsWith("\\platforma")}set isActive(e){this.state.isActive=e,this.writeState()}get lastRun(){return this.state.lastRun}set lastRun(e){this.state.lastRun=e,this.writeState()}};y(E,"instance");let se=E;const o=se.getInstance();function Me(a,e,r,t){var s;return o.lastRun={...o.lastRun,mode:"docker",cmd:"docker",args:e,workdir:r.cwd,envs:r.env,docker:{...(s=o.lastRun)==null?void 0:s.docker,...t}},Ue(a,"docker",e,r)}function ur(a,e,r,t,s){var c;o.lastRun={...o.lastRun,mode:"process",cmd:e,args:r,workdir:t.cwd,envs:t.env,process:{...(c=o.lastRun)==null?void 0:c.process,...s}};const i=hr(a,e,r,t);return o.lastRun.process={...o.lastRun.process,pid:i.pid},i}function fr(a,e){if(!o.lastRun)throw new Error("no previous run info found: this is the first run after package installation");return e={cwd:o.lastRun.workdir,env:{...o.lastRun.envs,...e.env},...e},Ue(a,o.lastRun.cmd,o.lastRun.args,e)}function hr(a,e,r,t){a.debug(`Running:
11
+ `);return`${(c=>W.format.colorize().colorize(c,c))(e)}: ${s}`})),transports:[new W.transports.Console({stderrLevels:["error","warn","info","debug"],handleExceptions:!0})]})}function fr(a){return er.randomBytes(Math.ceil(a/2)).toString("hex").slice(0,a)}function hr(a){return a.startsWith("~")?f.join(_.homedir(),a.slice(1)):a}function Y(a){l.existsSync(a)||l.mkdirSync(a,{recursive:!0})}function mr(a){try{if(_.platform()!=="win32")return $.execSync(`ps -p ${a} -o comm=`,{encoding:"utf8"}).trim();const e=`wmic process where processid=${a} get Caption`,r=$.execSync(e,{encoding:"utf8"}).split(`
12
+ `);return r.length<=1?"":r[1].trim()}catch{return""}}const yr=z.z.object({npmOrgName:z.z.string().min(1),orgName:z.z.string().min(1),blockName:z.z.string().min(1)});async function Pr(a){const e=br(),r=f.join(process.cwd(),e.blockName);a.info("Downloading boilerplate code..."),await vr("https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip","platforma-block-boilerplate-main",r),a.info("Replace everything in the template with provided options..."),wr(r,/pl-open\/my-org.block-boilerplate/g,`${e.npmOrgName}/${e.orgName}.${e.blockName}`)}function br(){let a=K.question('Write an organization name for npm. Default is "pl-open": ');a===""&&(a="pl-open");const e=K.question('Write an organization name, e.g. "my-org": '),r=K.question('Write a name of the block, e.g. "hello-world": ');return yr.parse({npmOrgName:a,orgName:e,blockName:r})}async function vr(a,e,r){const s=await(await fetch(a)).blob(),i=l.mkdtempSync(f.join(_.tmpdir(),"create-repo")),c=f.join(i,"packed-repo.zip"),n=rr.Writable.toWeb(l.createWriteStream(c));await s.stream().pipeTo(n);const m=f.join(i,"unpacked-repo");l.mkdirSync(m),await tr(c,m),l.cpSync(f.join(m,e),r,{recursive:!0})}function wr(a,e,r){kr(a).forEach(t=>Sr(t,e,r))}function kr(a){return l.readdirSync(a,{withFileTypes:!0,recursive:!0}).filter(r=>r.isFile()).map(r=>f.join(r.parentPath,r.name))}function Sr(a,e,r){const s=l.readFileSync(a).toString().replaceAll(e,r);l.writeFileSync(a,s)}const I=class I extends d.Command{async run(){const{flags:e}=await this.parse(I),r=T(e["log-level"]);await Pr(r)}};y(I,"description","Helps to create a new block by downloading a block's template."),y(I,"examples",["<%= name %>"]),y(I,"flags",{...F});let se=I;function Je(...a){return f.resolve(__dirname,"..",...a)}function O(...a){return Je("assets",...a)}function Ar(){return l.readdirSync(O()).filter(e=>e.startsWith("compose-")&&e.endsWith(".yaml")).map(e=>O(e))}function He(...a){return l.readFileSync(Je(...a))}var te;function re(){return te||(te=JSON.parse(He("package.json").toString())),te}function ae(a){return a||(a=re()["pl-version"]),`quay.io/milaboratories/platforma:${a}`}const E=class E{constructor(e){y(this,"state",{lastRun:void 0,isActive:!1});y(this,"filePath");y(this,"dirPath");e=e??f.resolve(_.homedir(),".config","pl-bootstrap");const r=f.join(e,"state.json");this.dirPath=e,this.filePath=r,l.existsSync(e)||l.mkdirSync(e,{recursive:!0}),l.existsSync(r)&&(this.state=JSON.parse(He(r).toString()))}static getInstance(){return E.instance||(E.instance=new E),E.instance}path(...e){return f.join(this.dirPath,...e)}data(...e){return this.path("data",...e)}binaries(...e){return this.path("binaries",...e)}writeState(){l.writeFileSync(this.filePath,JSON.stringify(this.state))}get isActive(){var e,r;return this.state.isActive?this.state.isActive:(r=(e=this.state.lastRun)==null?void 0:e.process)!=null&&r.pid?this.isValidPID:!1}get isValidPID(){var r,t;if(!((t=(r=this.state.lastRun)==null?void 0:r.process)!=null&&t.pid))return!1;const e=mr(this.state.lastRun.process.pid);return e==="platforma"||e.endsWith("/platforma")||e.endsWith("\\platforma")}set isActive(e){this.state.isActive=e,this.writeState()}get lastRun(){return this.state.lastRun}set lastRun(e){this.state.lastRun=e,this.writeState()}};y(E,"instance");let ie=E;const o=ie.getInstance();function Me(a,e,r,t){var s;return o.lastRun={...o.lastRun,mode:"docker",cmd:"docker",args:e,workdir:r.cwd,envs:r.env,docker:{...(s=o.lastRun)==null?void 0:s.docker,...t}},ze(a,"docker",e,r)}function Lr(a,e,r,t,s){var c;o.lastRun={...o.lastRun,mode:"process",cmd:e,args:r,workdir:t.cwd,envs:t.env,process:{...(c=o.lastRun)==null?void 0:c.process,...s}};const i=_r(a,e,r,t);return o.lastRun.process={...o.lastRun.process,pid:i.pid},i}function Rr(a,e){if(!o.lastRun)throw new Error("no previous run info found: this is the first run after package installation");return e={cwd:o.lastRun.workdir,env:{...o.lastRun.envs,...e.env},...e},ze(a,o.lastRun.cmd,o.lastRun.args,e)}function _r(a,e,r,t){a.debug(`Running:
5
13
  env: ${JSON.stringify(t.env)}
6
14
  cmd: ${JSON.stringify([e,...r])}
7
- wd: ${t.cwd}`),t.env={...process.env,...t.env},a.debug(" spawning child process");const s=$.spawn(e,r,t);var i=!1;const c=()=>{s.kill("SIGINT"),i=!0};return a.debug(" setting up signal handler"),process.on("SIGINT",c),s.on("close",n=>{process.removeListener("SIGINT",c),i&&process.exit(n)}),s}function Ue(a,e,r,t){return a.debug(`Running:
15
+ wd: ${t.cwd}`),t.env={...process.env,...t.env},a.debug(" spawning child process");const s=$.spawn(e,r,t);var i=!1;const c=()=>{s.kill("SIGINT"),i=!0};return a.debug(" setting up signal handler"),process.on("SIGINT",c),s.on("close",n=>{process.removeListener("SIGINT",c),i&&process.exit(n)}),s}function ze(a,e,r,t){return a.debug(`Running:
8
16
  env: ${JSON.stringify(t.env)}
9
17
  cmd: ${JSON.stringify([e,...r])}
10
- wd: ${t.cwd}`),t.env={...process.env,...t.env},$.spawnSync(e,r,t)}function mr(a){return{id:a,type:"S3",indexCachePeriod:"0s",endpoint:"",region:"",presignEndpoint:"",bucketName:"",createBucket:!1,forcePathStyle:!1,key:"",secret:"",keyPrefix:"",accessPrefixes:[],uploadKeyPrefix:""}}function je(a){return{id:a,type:"FS",indexCachePeriod:"0s",rootPath:""}}function N(a,e,r){a=dr(a);const t=new URL(a,`file:${e}`);switch(t.protocol){case"s3:":var c=t.hostname,s=t.searchParams.get("region");return{...r,type:"S3",bucketName:c,region:s};case"s3e:":var i=t.pathname.split("/").slice(1),c=i[0],n=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`http://${t.host}/`,bucketName:c,keyPrefix:n,region:t.searchParams.get("region"),key:t.username?`static:${t.username}`:"",secret:t.password?`static:${t.password}`:""};case"s3es:":var i=t.pathname.split("/").slice(1),c=i[0],n=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`https://${t.host}/`,bucketName:c,keyPrefix:n,region:t.searchParams.get("region"),key:t.username?`static:${t.username}`:"",secret:t.password?`static:${t.password}`:""};case"file:":return{type:"FS",rootPath:t.pathname};default:throw new Error(`storage protocol '${t.protocol}' is not supported`)}}function yr(a,e){var g,b,w,S,L,k,p,j,A,me,ye,Pe,be,ve,we,ke,Se,Ae,Le,Re,_e,pe,Oe,$e,Fe,Te,Ee,De,Ne,Ie;const r=(e==null?void 0:e.localRoot)??o.data("local-custom"),t={level:((g=e==null?void 0:e.log)==null?void 0:g.level)??"info",path:((b=e==null?void 0:e.log)==null?void 0:b.path)??`${r}/platforma.log`},s={listen:((w=e==null?void 0:e.grpc)==null?void 0:w.listen)??"localhost:6345",tls:{enable:H((L=(S=e==null?void 0:e.grpc)==null?void 0:S.tls)==null?void 0:L.enable,!1),clientAuthMode:((p=(k=e==null?void 0:e.grpc)==null?void 0:k.tls)==null?void 0:p.clientAuthMode)??"NoAuth",certFile:((A=(j=e==null?void 0:e.grpc)==null?void 0:j.tls)==null?void 0:A.certFile)??`${r}/certs/tls.cert`,keyFile:((ye=(me=e==null?void 0:e.grpc)==null?void 0:me.tls)==null?void 0:ye.keyFile)??`${r}/certs/tls.key`,...(Pe=e==null?void 0:e.grpc)==null?void 0:Pe.tls}},i={auth:{enabled:((ve=(be=e==null?void 0:e.core)==null?void 0:be.auth)==null?void 0:ve.enabled)??!1,drivers:((ke=(we=e==null?void 0:e.core)==null?void 0:we.auth)==null?void 0:ke.drivers)??[{driver:"jwt",key:a},{driver:"htpasswd",path:`${r}/users.htpasswd`}]},db:{path:`${r}/db`}},c=Ce("main",`${r}/storages/main`,"main-bucket",(Se=e==null?void 0:e.storages)==null?void 0:Se.primary);var n;switch((Le=(Ae=e==null?void 0:e.storages)==null?void 0:Ae.work)==null?void 0:Le.type){case void 0:case"FS":n=je("work"),n.rootPath=((_e=(Re=e==null?void 0:e.storages)==null?void 0:Re.work)==null?void 0:_e.rootPath)??`${r}/storages/work`,n.indexCachePeriod=((Oe=(pe=e==null?void 0:e.storages)==null?void 0:pe.work)==null?void 0:Oe.indexCachePeriod)??"1m";break;default:throw new Error("work storage MUST have 'FS' type as it is used for working directories management")}const h=Ce("library",`${r}/storages/library`,"library-bucket",($e=e==null?void 0:e.storages)==null?void 0:$e.library),u={enabled:H((Fe=e==null?void 0:e.monitoring)==null?void 0:Fe.enabled,!0),listen:((Te=e==null?void 0:e.monitoring)==null?void 0:Te.listen)??"127.0.0.1:9090"},v={enabled:H((Ee=e==null?void 0:e.debug)==null?void 0:Ee.enabled,!0),listen:((De=e==null?void 0:e.debug)==null?void 0:De.listen)??"127.0.0.1:9091"},P={value:((Ne=e==null?void 0:e.license)==null?void 0:Ne.value)??"",file:((Ie=e==null?void 0:e.license)==null?void 0:Ie.file)??""};return{localRoot:r,license:P,log:t,grpc:s,core:i,monitoring:u,debug:v,storages:{primary:c,work:n,library:h},hacks:{libraryDownloadable:!0}}}function Ce(a,e,r,t){var s;switch(t==null?void 0:t.type){case void 0:case"FS":s=je(a),s.rootPath=(t==null?void 0:t.rootPath)??e;break;case"S3":s=mr(a),s.endpoint=(t==null?void 0:t.endpoint)??"http://localhost:9000",s.presignEndpoint=(t==null?void 0:t.presignEndpoint)??"http://localhost:9000",s.bucketName=(t==null?void 0:t.bucketName)??r,s.createBucket=H(t==null?void 0:t.createBucket,!0),s.forcePathStyle=H(t==null?void 0:t.forcePathStyle,!0),s.key=(t==null?void 0:t.key)??"",s.secret=(t==null?void 0:t.secret)??"",s.keyPrefix=(t==null?void 0:t.keyPrefix)??"",s.accessPrefixes=(t==null?void 0:t.accessPrefixes)??[""],s.uploadKeyPrefix=(t==null?void 0:t.uploadKeyPrefix)??"";break;default:throw J(),new Error("unknown storage type")}return s}function Pr(a){const e=a.monitoring.enabled?"":" disabled",r=a.debug.enabled?"":" disabled",t=a.hacks.libraryDownloadable?"true":"false";var s=a.license.value;return a.license.file!=""&&(s=l.readFileSync(a.license.file).toString().trimEnd()),`
18
+ wd: ${t.cwd}`),t.env={...process.env,...t.env},$.spawnSync(e,r,t)}function pr(a){return{id:a,type:"S3",indexCachePeriod:"0s",endpoint:"",region:"",presignEndpoint:"",bucketName:"",createBucket:!1,forcePathStyle:!1,key:"",secret:"",keyPrefix:"",accessPrefixes:[],uploadKeyPrefix:""}}function Ye(a){return{id:a,type:"FS",indexCachePeriod:"0s",rootPath:""}}function N(a,e,r){a=hr(a);const t=new URL(a,`file:${e}`);switch(t.protocol){case"s3:":var c=t.hostname,s=t.searchParams.get("region");return{...r,type:"S3",bucketName:c,region:s};case"s3e:":var i=t.pathname.split("/").slice(1),c=i[0],n=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`http://${t.host}/`,bucketName:c,keyPrefix:n,region:t.searchParams.get("region"),key:t.username?`static:${t.username}`:"",secret:t.password?`static:${t.password}`:""};case"s3es:":var i=t.pathname.split("/").slice(1),c=i[0],n=i.length>1?i[1]:"";return{...r,type:"S3",endpoint:`https://${t.host}/`,bucketName:c,keyPrefix:n,region:t.searchParams.get("region"),key:t.username?`static:${t.username}`:"",secret:t.password?`static:${t.password}`:""};case"file:":return{type:"FS",rootPath:t.pathname};default:throw new Error(`storage protocol '${t.protocol}' is not supported`)}}function Or(a,e){var g,b,w,S,L,k,p,j,A,me,ye,Pe,be,ve,we,ke,Se,Ae,Le,Re,_e,pe,Oe,$e,Fe,Te,Ee,De,Ne,Ie;const r=(e==null?void 0:e.localRoot)??o.data("local-custom"),t={level:((g=e==null?void 0:e.log)==null?void 0:g.level)??"info",path:((b=e==null?void 0:e.log)==null?void 0:b.path)??`${r}/platforma.log`},s={listen:((w=e==null?void 0:e.grpc)==null?void 0:w.listen)??"localhost:6345",tls:{enable:H((L=(S=e==null?void 0:e.grpc)==null?void 0:S.tls)==null?void 0:L.enable,!1),clientAuthMode:((p=(k=e==null?void 0:e.grpc)==null?void 0:k.tls)==null?void 0:p.clientAuthMode)??"NoAuth",certFile:((A=(j=e==null?void 0:e.grpc)==null?void 0:j.tls)==null?void 0:A.certFile)??`${r}/certs/tls.cert`,keyFile:((ye=(me=e==null?void 0:e.grpc)==null?void 0:me.tls)==null?void 0:ye.keyFile)??`${r}/certs/tls.key`,...(Pe=e==null?void 0:e.grpc)==null?void 0:Pe.tls}},i={auth:{enabled:((ve=(be=e==null?void 0:e.core)==null?void 0:be.auth)==null?void 0:ve.enabled)??!1,drivers:((ke=(we=e==null?void 0:e.core)==null?void 0:we.auth)==null?void 0:ke.drivers)??[{driver:"jwt",key:a},{driver:"htpasswd",path:`${r}/users.htpasswd`}]},db:{path:`${r}/db`}},c=Ce("main",`${r}/storages/main`,"main-bucket",(Se=e==null?void 0:e.storages)==null?void 0:Se.primary);var n;switch((Le=(Ae=e==null?void 0:e.storages)==null?void 0:Ae.work)==null?void 0:Le.type){case void 0:case"FS":n=Ye("work"),n.rootPath=((_e=(Re=e==null?void 0:e.storages)==null?void 0:Re.work)==null?void 0:_e.rootPath)??`${r}/storages/work`,n.indexCachePeriod=((Oe=(pe=e==null?void 0:e.storages)==null?void 0:pe.work)==null?void 0:Oe.indexCachePeriod)??"1m";break;default:throw new Error("work storage MUST have 'FS' type as it is used for working directories management")}const h=Ce("library",`${r}/storages/library`,"library-bucket",($e=e==null?void 0:e.storages)==null?void 0:$e.library),u={enabled:H((Fe=e==null?void 0:e.monitoring)==null?void 0:Fe.enabled,!0),listen:((Te=e==null?void 0:e.monitoring)==null?void 0:Te.listen)??"127.0.0.1:9090"},v={enabled:H((Ee=e==null?void 0:e.debug)==null?void 0:Ee.enabled,!0),listen:((De=e==null?void 0:e.debug)==null?void 0:De.listen)??"127.0.0.1:9091"},P={value:((Ne=e==null?void 0:e.license)==null?void 0:Ne.value)??"",file:((Ie=e==null?void 0:e.license)==null?void 0:Ie.file)??""};return{localRoot:r,license:P,log:t,grpc:s,core:i,monitoring:u,debug:v,storages:{primary:c,work:n,library:h},hacks:{libraryDownloadable:!0}}}function Ce(a,e,r,t){var s;switch(t==null?void 0:t.type){case void 0:case"FS":s=Ye(a),s.rootPath=(t==null?void 0:t.rootPath)??e;break;case"S3":s=pr(a),s.endpoint=(t==null?void 0:t.endpoint)??"http://localhost:9000",s.presignEndpoint=(t==null?void 0:t.presignEndpoint)??"http://localhost:9000",s.bucketName=(t==null?void 0:t.bucketName)??r,s.createBucket=H(t==null?void 0:t.createBucket,!0),s.forcePathStyle=H(t==null?void 0:t.forcePathStyle,!0),s.key=(t==null?void 0:t.key)??"",s.secret=(t==null?void 0:t.secret)??"",s.keyPrefix=(t==null?void 0:t.keyPrefix)??"",s.accessPrefixes=(t==null?void 0:t.accessPrefixes)??[""],s.uploadKeyPrefix=(t==null?void 0:t.uploadKeyPrefix)??"";break;default:throw J(),new Error("unknown storage type")}return s}function $r(a){const e=a.monitoring.enabled?"":" disabled",r=a.debug.enabled?"":" disabled",t=a.hacks.libraryDownloadable?"true":"false";var s=a.license.value;return a.license.file!=""&&(s=l.readFileSync(a.license.file).toString().trimEnd()),`
11
19
  license:
12
20
  value: '${a.license.value}'
13
21
  file: '${a.license.file}'
@@ -76,12 +84,12 @@ controllers:
76
84
  packagesRoot: '${a.localRoot}/packages'
77
85
 
78
86
  workflows: {}
79
- `}function H(a,e){return a===void 0?e:a}const br=["linux","macos","windows"];function vr(a){const e=_.platform();switch(e){case"darwin":return"macos";case"linux":return"linux";case"win32":return"windows";default:throw new Error(`operating system '${e}' is not currently supported by Platforma ecosystem. The list of OSes supported: `+JSON.stringify(br))}}const wr=["amd64","arm64"];function We(a){const e=_.arch();switch(e){case"arm64":return"arm64";case"x64":return"amd64";default:throw new Error(`processor architecture '${e}' is not currently supported by Platforma ecosystem. The list of architectures supported: `+JSON.stringify(wr))}}function kr(a,e){const r=(e==null?void 0:e.version)??V()["pl-version"],t=(e==null?void 0:e.showProgress)??process.stdout.isTTY,s=`pl-${r}-${We()}.tgz`,i=(e==null?void 0:e.downloadURL)??`https://cdn.platforma.bio/software/pl/${vr()}/${s}`,c=(e==null?void 0:e.saveTo)??o.binaries(s);if(l.existsSync(c))return a.info(`Platforma Backend archive download skipped: '${c}' already exists`),Promise.resolve(c);l.mkdirSync(f.dirname(c),{recursive:!0}),a.info(`Downloading Platforma Backend archive:
87
+ `}function H(a,e){return a===void 0?e:a}const Fr=["linux","macos","windows"];function Tr(a){const e=_.platform();switch(e){case"darwin":return"macos";case"linux":return"linux";case"win32":return"windows";default:throw new Error(`operating system '${e}' is not currently supported by Platforma ecosystem. The list of OSes supported: `+JSON.stringify(Fr))}}const Er=["amd64","arm64"];function Ke(a){const e=_.arch();switch(e){case"arm64":return"arm64";case"x64":return"amd64";default:throw new Error(`processor architecture '${e}' is not currently supported by Platforma ecosystem. The list of architectures supported: `+JSON.stringify(Er))}}function Dr(a,e){const r=(e==null?void 0:e.version)??re()["pl-version"],t=(e==null?void 0:e.showProgress)??process.stdout.isTTY,s=`pl-${r}-${Ke()}.tgz`,i=(e==null?void 0:e.downloadURL)??`https://cdn.platforma.bio/software/pl/${Tr()}/${s}`,c=(e==null?void 0:e.saveTo)??o.binaries(s);if(l.existsSync(c))return a.info(`Platforma Backend archive download skipped: '${c}' already exists`),Promise.resolve(c);l.mkdirSync(f.dirname(c),{recursive:!0}),a.info(`Downloading Platforma Backend archive:
80
88
  URL: ${i}
81
- Save to: ${c}`);const n=rr.get(i);return new Promise((m,h)=>{n.on("response",u=>{if(!u.statusCode){const b=new Error("failed to download archive: no HTTP status code in response from server");n.destroy(),h(b);return}if(u.statusCode!==200){const b=new Error(`failed to download archive: ${u.statusCode} ${u.statusMessage}`);n.destroy(),h(b);return}const v=parseInt(u.headers["content-length"]||"0",10);let P=0;const g=l.createWriteStream(c);u.pipe(g),u.on("data",b=>{P+=b.length;const w=P/v*100;t&&process.stdout.write(` downloading: ${w.toFixed(2)}%\r`)}),u.on("error",b=>{l.unlinkSync(c),a.error(`Failed to download Platforma Binary: ${b.message}`),n.destroy(),h(b)}),g.on("finish",()=>{g.close(),a.info(" ... download done."),n.destroy(),m(c)})})})}function Sr(a,e){a.debug("extracting archive...");const r=(e==null?void 0:e.version)??V()["pl-version"];a.debug(` version: '${r}'`);const t=`${Je({version:r})}.tgz`,s=(e==null?void 0:e.archivePath)??o.binaries(t);a.debug(` archive path: '${s}'`);const i=(e==null?void 0:e.extractTo)??Lr(s);if(a.debug(` target dir: '${i}'`),l.existsSync(i))return a.info(`Platforma Backend binaries unpack skipped: '${i}' exists`),i;if(!l.existsSync(s)){const c=`Platforma Backend binary archive not found at '${s}'`;throw a.error(c),new Error(c)}return l.existsSync(i)||(a.debug(` creating target dir '${i}'`),l.mkdirSync(i,{recursive:!0})),a.info(`Unpacking Platforma Backend archive:
89
+ Save to: ${c}`);const n=ar.get(i);return new Promise((m,h)=>{n.on("response",u=>{if(!u.statusCode){const b=new Error("failed to download archive: no HTTP status code in response from server");n.destroy(),h(b);return}if(u.statusCode!==200){const b=new Error(`failed to download archive: ${u.statusCode} ${u.statusMessage}`);n.destroy(),h(b);return}const v=parseInt(u.headers["content-length"]||"0",10);let P=0;const g=l.createWriteStream(c);u.pipe(g),u.on("data",b=>{P+=b.length;const w=P/v*100;t&&process.stdout.write(` downloading: ${w.toFixed(2)}%\r`)}),u.on("error",b=>{l.unlinkSync(c),a.error(`Failed to download Platforma Binary: ${b.message}`),n.destroy(),h(b)}),g.on("finish",()=>{g.close(),a.info(" ... download done."),n.destroy(),m(c)})})})}function Nr(a,e){a.debug("extracting archive...");const r=(e==null?void 0:e.version)??re()["pl-version"];a.debug(` version: '${r}'`);const t=`${Qe({version:r})}.tgz`,s=(e==null?void 0:e.archivePath)??o.binaries(t);a.debug(` archive path: '${s}'`);const i=(e==null?void 0:e.extractTo)??xr(s);if(a.debug(` target dir: '${i}'`),l.existsSync(i))return a.info(`Platforma Backend binaries unpack skipped: '${i}' exists`),i;if(!l.existsSync(s)){const c=`Platforma Backend binary archive not found at '${s}'`;throw a.error(c),new Error(c)}return l.existsSync(i)||(a.debug(` creating target dir '${i}'`),l.mkdirSync(i,{recursive:!0})),a.info(`Unpacking Platforma Backend archive:
82
90
  Archive: ${s}
83
- Target dir: ${i}`),cr.x({file:s,cwd:i,gzip:!0,sync:!0}),a.info(" ... unpack done."),i}function qe(a,e){return kr(a,e).then(r=>Sr(a,{archivePath:r}))}function Je(a){return`pl-${(a==null?void 0:a.version)??V()["pl-version"]}-${We()}`}function Ar(a,...e){return o.binaries(Je({version:a}),...e)}function Lr(a){const e=a.lastIndexOf(".");return e===-1?a:a.slice(0,e)}class D{constructor(e){this.logger=e}startLast(){const e=fr(this.logger,{stdio:"inherit"});q(e,"failed to bring back Platforma Backend in the last started configuration")}startLocal(e){var m,h,u,v,P,g,b,w,S,L;const r=(e==null?void 0:e.binaryPath)??Ar(e==null?void 0:e.version,"binaries","platforma");var t=e==null?void 0:e.configPath;const s=(e==null?void 0:e.workdir)??(t?process.cwd():o.path());e!=null&&e.primaryURL&&(e.configOptions={...e.configOptions,storages:{...(m=e.configOptions)==null?void 0:m.storages,primary:N(e.primaryURL,s,(u=(h=e.configOptions)==null?void 0:h.storages)==null?void 0:u.primary)}}),e!=null&&e.libraryURL&&(e.configOptions={...e.configOptions,storages:{...(v=e.configOptions)==null?void 0:v.storages,library:N(e.libraryURL,s,(g=(P=e.configOptions)==null?void 0:P.storages)==null?void 0:g.library)}});const i=yr(this.getLastJwt(),e==null?void 0:e.configOptions);this.logger.debug(" checking license..."),this.checkLicense((w=(b=e==null?void 0:e.configOptions)==null?void 0:b.license)==null?void 0:w.value,(L=(S=e==null?void 0:e.configOptions)==null?void 0:S.license)==null?void 0:L.file);const c=[`${i.localRoot}/packages`,`${i.localRoot}/packages-local`,`${i.localRoot}/blocks-local`];i.storages.primary.type==="FS"&&c.push(i.storages.primary.rootPath),i.storages.library.type==="FS"&&(c.push(i.storages.library.rootPath),i.hacks.libraryDownloadable=!1),i.storages.work.type==="FS"&&c.push(i.storages.work.rootPath),this.logger.debug(" creating pl state directories...");for(const k of c)l.existsSync(k)||(this.logger.debug(` '${k}'`),l.mkdirSync(k,{recursive:!0}));for(const k of i.core.auth.drivers)k.driver==="htpasswd"&&(l.existsSync(k.path)||(this.logger.debug(` installing default 'users.htpasswd' to ${k.path}...`),l.copyFileSync(O("users.htpasswd"),k.path)));t||(t=f.join(i.localRoot,"config.yaml"),this.logger.debug(` rendering configuration '${t}'...`),l.writeFileSync(t,Pr(i)));const n=this.renderRunInfo({configPath:t,dbPath:i.core.db.path,apiAddr:i.grpc.listen,logPath:i.log.path,primary:i.storages.primary,work:i.storages.work,library:i.storages.library});return this.logger.info(`Starting platforma:
84
- ${n}`),ur(this.logger,r,["-config",t],{cwd:s,stdio:"inherit"},{storagePath:i.localRoot})}startLocalS3(e){var s;this.logger.debug("starting platforma in 'local s3' mode...");const r=(e==null?void 0:e.minioPort)??9e3,t=(s=e==null?void 0:e.configOptions)==null?void 0:s.localRoot;return this.startMinio({minioPort:r,minioConsolePort:e==null?void 0:e.minioConsolePort,storage:t?f.join(t,"minio"):void 0}),this.startLocal({...e,primaryURL:(e==null?void 0:e.primaryURL)??`s3e://testuser:testpassword@localhost:${r}/main-bucket/?region=no-region`,libraryURL:(e==null?void 0:e.libraryURL)??`s3e://testuser:testpassword@localhost:${r}/library-bucket/?region=no-region`})}startMinio(e){this.logger.debug(" starting minio...");var r=O("compose-backend.yaml");const t=e!=null&&e.version?`:${e.version}`:"";this.logger.debug(` minio version: ${t}`);const s=(e==null?void 0:e.image)??`quay.io/minio/minio${t}`;this.logger.debug(` minio image: ${s}`);const i=(e==null?void 0:e.storage)??o.data("minio");Y(i);const c=o.data("stub");Y(c);const n=(e==null?void 0:e.minioPort)??9e3,m=(e==null?void 0:e.minioConsolePort)??9001,h={MINIO_IMAGE:s,MINIO_STORAGE:f.resolve(i),MINIO_PORT:n.toString(),MINIO_CONSOLE_PORT:m.toString(),PL_DATA_DB_ROOT:c,PL_DATA_PRIMARY_ROOT:c,PL_DATA_LIBRARY_ROOT:c,PL_DATA_WORKDIR_ROOT:c,PL_DATA_PACKAGE_ROOT:c,PL_IMAGE:"scratch"};this.logger.debug(" spawning child 'docker' process...");const u=$.spawnSync("docker",["compose",`--file=${r}`,"up","--detach","--remove-orphans","--pull=missing","minio"],{env:{...process.env,...h},stdio:"inherit"});q(u,"failed to start MinIO service in docker")}buildPlatforma(e){const r=f.resolve(e.repoRoot,"cmd","platforma"),t=e.binPath??f.join(_.tmpdir(),"platforma-local-build");this.logger.info("Building Platforma Backend binary from sources"),this.logger.info(` sources path: ${e.repoRoot}`),this.logger.info(` binary path: ${t}`);const s=$.spawnSync("go",["build","-o",t,"."],{cwd:r,stdio:"inherit"});return q(s,"failed to build platforma binary from sources using 'go build' command"),t}startDockerS3(e,r){const t=O("compose-backend.yaml"),s=(r==null?void 0:r.image)??ae(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=S=>f.join(e,S),c=S=>{const L=i(S);return Y(L),L},n=i("platforma.log");l.existsSync(n)||(l.mkdirSync(f.dirname(n),{recursive:!0}),l.writeFileSync(n,""));const m=N("s3e://testuser:testpassword@minio:9000/main-bucket");if(m.type!=="S3")throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");m.presignEndpoint="http://localhost:9000";const h=N("s3e://testuser:testpassword@minio:9000/library-bucket");if(h.type!=="S3")throw new Error(`${h.type} storage type is not supported for library storage`);h.presignEndpoint="http://localhost:9000";const u=c("db"),v=c("work"),P=i("users.htpasswd");l.existsSync(P)||l.copyFileSync(O("users.htpasswd"),P);const g={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:P,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:(r==null?void 0:r.logLevel)??"info",PL_LOG_FILE:n,PL_DATA_DB_ROOT:u,PL_DATA_PRIMARY_ROOT:c("primary"),PL_DATA_LIBRARY_ROOT:c("library"),PL_DATA_WORKDIR_ROOT:v,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",m),...this.configureDockerStorage("library",h)};if(r!=null&&r.grpcAddr&&(g.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(g.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(g.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(g.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(g.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(g.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(g.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const S of r.auth.drivers)S.driver==="htpasswd"&&(g.PL_AUTH_HTPASSWD_PATH=f.resolve(S.path),S.path="/etc/platforma/users.htpasswd");g.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}const b=Me(this.logger,["compose",`--file=${t}`,"up","--detach","--remove-orphans","--pull=missing","minio","backend"],{env:g,stdio:"inherit"},{plImage:s,composePath:t});q(b,"failed to start Platforma Backend in Docker"),o.isActive=!0;const w=this.renderRunInfo({apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:n,primary:m,work:{type:"FS",rootPath:v},library:h,dbPath:u});this.logger.info(`Started platforma:
91
+ Target dir: ${i}`),cr.x({file:s,cwd:i,gzip:!0,sync:!0}),a.info(" ... unpack done."),i}function Ve(a,e){return Dr(a,e).then(r=>Nr(a,{archivePath:r}))}function Qe(a){return`pl-${(a==null?void 0:a.version)??re()["pl-version"]}-${Ke()}`}function Ir(a,...e){return o.binaries(Qe({version:a}),...e)}function xr(a){const e=a.lastIndexOf(".");return e===-1?a:a.slice(0,e)}class D{constructor(e){this.logger=e}startLast(){const e=Rr(this.logger,{stdio:"inherit"});q(e,"failed to bring back Platforma Backend in the last started configuration")}startLocal(e){var m,h,u,v,P,g,b,w,S,L;const r=(e==null?void 0:e.binaryPath)??Ir(e==null?void 0:e.version,"binaries","platforma");var t=e==null?void 0:e.configPath;const s=(e==null?void 0:e.workdir)??(t?process.cwd():o.path());e!=null&&e.primaryURL&&(e.configOptions={...e.configOptions,storages:{...(m=e.configOptions)==null?void 0:m.storages,primary:N(e.primaryURL,s,(u=(h=e.configOptions)==null?void 0:h.storages)==null?void 0:u.primary)}}),e!=null&&e.libraryURL&&(e.configOptions={...e.configOptions,storages:{...(v=e.configOptions)==null?void 0:v.storages,library:N(e.libraryURL,s,(g=(P=e.configOptions)==null?void 0:P.storages)==null?void 0:g.library)}});const i=Or(this.getLastJwt(),e==null?void 0:e.configOptions);this.logger.debug(" checking license..."),this.checkLicense((w=(b=e==null?void 0:e.configOptions)==null?void 0:b.license)==null?void 0:w.value,(L=(S=e==null?void 0:e.configOptions)==null?void 0:S.license)==null?void 0:L.file);const c=[`${i.localRoot}/packages`,`${i.localRoot}/packages-local`,`${i.localRoot}/blocks-local`];i.storages.primary.type==="FS"&&c.push(i.storages.primary.rootPath),i.storages.library.type==="FS"&&(c.push(i.storages.library.rootPath),i.hacks.libraryDownloadable=!1),i.storages.work.type==="FS"&&c.push(i.storages.work.rootPath),this.logger.debug(" creating pl state directories...");for(const k of c)l.existsSync(k)||(this.logger.debug(` '${k}'`),l.mkdirSync(k,{recursive:!0}));for(const k of i.core.auth.drivers)k.driver==="htpasswd"&&(l.existsSync(k.path)||(this.logger.debug(` installing default 'users.htpasswd' to ${k.path}...`),l.copyFileSync(O("users.htpasswd"),k.path)));t||(t=f.join(i.localRoot,"config.yaml"),this.logger.debug(` rendering configuration '${t}'...`),l.writeFileSync(t,$r(i)));const n=this.renderRunInfo({configPath:t,dbPath:i.core.db.path,apiAddr:i.grpc.listen,logPath:i.log.path,primary:i.storages.primary,work:i.storages.work,library:i.storages.library});return this.logger.info(`Starting platforma:
92
+ ${n}`),Lr(this.logger,r,["-config",t],{cwd:s,stdio:"inherit"},{storagePath:i.localRoot})}startLocalS3(e){var s;this.logger.debug("starting platforma in 'local s3' mode...");const r=(e==null?void 0:e.minioPort)??9e3,t=(s=e==null?void 0:e.configOptions)==null?void 0:s.localRoot;return this.startMinio({minioPort:r,minioConsolePort:e==null?void 0:e.minioConsolePort,storage:t?f.join(t,"minio"):void 0}),this.startLocal({...e,primaryURL:(e==null?void 0:e.primaryURL)??`s3e://testuser:testpassword@localhost:${r}/main-bucket/?region=no-region`,libraryURL:(e==null?void 0:e.libraryURL)??`s3e://testuser:testpassword@localhost:${r}/library-bucket/?region=no-region`})}startMinio(e){this.logger.debug(" starting minio...");var r=O("compose-backend.yaml");const t=e!=null&&e.version?`:${e.version}`:"";this.logger.debug(` minio version: ${t}`);const s=(e==null?void 0:e.image)??`quay.io/minio/minio${t}`;this.logger.debug(` minio image: ${s}`);const i=(e==null?void 0:e.storage)??o.data("minio");Y(i);const c=o.data("stub");Y(c);const n=(e==null?void 0:e.minioPort)??9e3,m=(e==null?void 0:e.minioConsolePort)??9001,h={MINIO_IMAGE:s,MINIO_STORAGE:f.resolve(i),MINIO_PORT:n.toString(),MINIO_CONSOLE_PORT:m.toString(),PL_DATA_DB_ROOT:c,PL_DATA_PRIMARY_ROOT:c,PL_DATA_LIBRARY_ROOT:c,PL_DATA_WORKDIR_ROOT:c,PL_DATA_PACKAGE_ROOT:c,PL_IMAGE:"scratch"};this.logger.debug(" spawning child 'docker' process...");const u=$.spawnSync("docker",["compose",`--file=${r}`,"up","--detach","--remove-orphans","--pull=missing","minio"],{env:{...process.env,...h},stdio:"inherit"});q(u,"failed to start MinIO service in docker")}buildPlatforma(e){const r=f.resolve(e.repoRoot,"cmd","platforma"),t=e.binPath??f.join(_.tmpdir(),"platforma-local-build");this.logger.info("Building Platforma Backend binary from sources"),this.logger.info(` sources path: ${e.repoRoot}`),this.logger.info(` binary path: ${t}`);const s=$.spawnSync("go",["build","-o",t,"."],{cwd:r,stdio:"inherit"});return q(s,"failed to build platforma binary from sources using 'go build' command"),t}startDockerS3(e,r){const t=O("compose-backend.yaml"),s=(r==null?void 0:r.image)??ae(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=S=>f.join(e,S),c=S=>{const L=i(S);return Y(L),L},n=i("platforma.log");l.existsSync(n)||(l.mkdirSync(f.dirname(n),{recursive:!0}),l.writeFileSync(n,""));const m=N("s3e://testuser:testpassword@minio:9000/main-bucket");if(m.type!=="S3")throw new Error("primary storage must have 'S3' type in 'docker s3' configuration");m.presignEndpoint="http://localhost:9000";const h=N("s3e://testuser:testpassword@minio:9000/library-bucket");if(h.type!=="S3")throw new Error(`${h.type} storage type is not supported for library storage`);h.presignEndpoint="http://localhost:9000";const u=c("db"),v=c("work"),P=i("users.htpasswd");l.existsSync(P)||l.copyFileSync(O("users.htpasswd"),P);const g={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:P,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:(r==null?void 0:r.logLevel)??"info",PL_LOG_FILE:n,PL_DATA_DB_ROOT:u,PL_DATA_PRIMARY_ROOT:c("primary"),PL_DATA_LIBRARY_ROOT:c("library"),PL_DATA_WORKDIR_ROOT:v,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",m),...this.configureDockerStorage("library",h)};if(r!=null&&r.grpcAddr&&(g.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(g.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(g.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(g.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(g.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(g.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(g.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const S of r.auth.drivers)S.driver==="htpasswd"&&(g.PL_AUTH_HTPASSWD_PATH=f.resolve(S.path),S.path="/etc/platforma/users.htpasswd");g.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}const b=Me(this.logger,["compose",`--file=${t}`,"up","--detach","--remove-orphans","--pull=missing","minio","backend"],{env:g,stdio:"inherit"},{plImage:s,composePath:t});q(b,"failed to start Platforma Backend in Docker"),o.isActive=!0;const w=this.renderRunInfo({apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:n,primary:m,work:{type:"FS",rootPath:v},library:h,dbPath:u});this.logger.info(`Started platforma:
85
93
  ${w}`)}startDocker(e,r){var t=O("compose-backend.yaml");const s=(r==null?void 0:r.image)??ae(r==null?void 0:r.version);this.checkLicense(r==null?void 0:r.license,r==null?void 0:r.licenseFile);const i=k=>f.join(e,k),c=k=>{const p=i(k);return Y(p),p},n=i("platforma.log");l.existsSync(n)||(l.mkdirSync(f.dirname(n),{recursive:!0}),l.writeFileSync(n,""));const m=c("db"),h=c("primary"),u=c("library"),v=c("work"),P=i("users.htpasswd");l.existsSync(P)||l.copyFileSync(O("users.htpasswd"),P);const g=N((r==null?void 0:r.primaryStorageURL)??`file:${h}`,"."),b=N((r==null?void 0:r.libraryStorageURL)??`file:${u}`,"."),w={MINIO_IMAGE:"quay.io/minio/minio",MINIO_STORAGE:c("minio"),PL_IMAGE:s,PL_AUTH_HTPASSWD_PATH:P,PL_LICENSE:r==null?void 0:r.license,PL_LICENSE_FILE:r==null?void 0:r.licenseFile,PL_LOG_LEVEL:"info",PL_LOG_FILE:n,PL_DATA_DB_ROOT:m,PL_DATA_PRIMARY_ROOT:h,PL_DATA_LIBRARY_ROOT:u,PL_DATA_WORKDIR_ROOT:v,PL_DATA_PACKAGE_ROOT:c("packages"),...this.configureDockerStorage("primary",g),...this.configureDockerStorage("library",b)};if(r!=null&&r.grpcAddr&&(w.PL_GRPC_ADDR=r.grpcAddr),r!=null&&r.grpcPort&&(w.PL_GRPC_PORT=r.grpcPort.toString()),r!=null&&r.monitoringAddr&&(w.PL_MONITORING_ADDR=r.monitoringAddr),r!=null&&r.monitoringPort&&(w.PL_MONITORING_PORT=r.monitoringPort.toString()),r!=null&&r.debugAddr&&(w.PL_DEBUG_ADDR=r.debugAddr),r!=null&&r.debugPort&&(w.PL_DEBUG_PORT=r.debugPort.toString()),r!=null&&r.auth&&(r.auth.enabled&&(w.PL_AUTH_ENABLED="true"),r.auth.drivers)){for(const k of r.auth.drivers)k.driver==="htpasswd"&&(w.PL_AUTH_HTPASSWD_PATH=f.resolve(k.path),k.path="/etc/platforma/users.htpasswd");w.PL_AUTH_DRIVERS=JSON.stringify(r.auth.drivers)}const S=Me(this.logger,["compose",`--file=${t}`,"up","--detach","--remove-orphans","--pull=missing","backend"],{env:w,stdio:"inherit"},{plImage:s,composePath:t,primaryPath:h,workPath:v,libraryPath:u});q(S,"failed to start Platforma Backend in Docker"),o.isActive=!0;const L=this.renderRunInfo({apiPort:r==null?void 0:r.grpcPort,apiAddr:r==null?void 0:r.grpcAddr,logPath:n,primary:g,work:{type:"FS",rootPath:v},library:b,dbPath:m});this.logger.info(`Started platforma:
86
94
  ${L}`)}stop(){if(!o.isActive){console.log("no running service detected");return}const e=o.lastRun;switch(e.mode){case"docker":const r=$.spawnSync("docker",["compose","--file",e.docker.composePath,"down"],{env:{...process.env,...e.envs},stdio:"inherit"});o.isActive=!1,r.status!==0&&process.exit(r.status);return;case"process":o.isValidPID&&process.kill(e.process.pid),o.isActive=!1;return;default:J(e.mode)}}cleanup(){var n,m,h,u,v,P,g,b,w,S,L,k,p,j;const e=["last command run cache ('pl-service start' shorthand will stop working until next full start command call)","'platforma' docker compose service containers and volumes"],r=o.data(),t=[r];if((m=(n=o.lastRun)==null?void 0:n.docker)!=null&&m.primaryPath){const A=(u=(h=o.lastRun)==null?void 0:h.docker)==null?void 0:u.primaryPath;A.startsWith(r)||t.push(A)}if((P=(v=o.lastRun)==null?void 0:v.docker)!=null&&P.workPath){const A=(b=(g=o.lastRun)==null?void 0:g.docker)==null?void 0:b.workPath;A.startsWith(r)||t.push(A)}if((S=(w=o.lastRun)==null?void 0:w.process)!=null&&S.storagePath){const A=(k=(L=o.lastRun)==null?void 0:L.process)==null?void 0:k.storagePath;A.startsWith(r)||t.push(A)}const s=t.length>0?` - storages (you'll loose all projects and calculation results stored in service instances):
87
95
  - ${t.join(`
@@ -91,9 +99,9 @@ Things to be removed:
91
99
  - ${e.join(`
92
100
  - `)}
93
101
  ${s}
94
- `;if(this.logger.warn(i),!lr("Are you sure?")){this.logger.info("Reset action was canceled");return}const c=new Set(nr());(j=(p=o.lastRun)==null?void 0:p.docker)!=null&&j.composePath&&c.add(o.lastRun.docker.composePath);for(const A of c)this.logger.info(`Destroying docker compose '${A}'`),this.destroyDocker(A,ae());for(const A of t)this.logger.info(`Destroying '${A}'`),l.rmSync(A,{recursive:!0,force:!0});this.logger.info(`Destroying state dir '${o.path()}'`),l.rmSync(o.path(),{recursive:!0,force:!0}),this.logger.info(`
102
+ `;if(this.logger.warn(i),!ur("Are you sure?")){this.logger.info("Reset action was canceled");return}const c=new Set(Ar());(j=(p=o.lastRun)==null?void 0:p.docker)!=null&&j.composePath&&c.add(o.lastRun.docker.composePath);for(const A of c)this.logger.info(`Destroying docker compose '${A}'`),this.destroyDocker(A,ae());for(const A of t)this.logger.info(`Destroying '${A}'`),l.rmSync(A,{recursive:!0,force:!0});this.logger.info(`Destroying state dir '${o.path()}'`),l.rmSync(o.path(),{recursive:!0,force:!0}),this.logger.info(`
95
103
  If you want to remove all downloaded platforma binaries, delete '${o.binaries()}' dir manually
96
- `)}mergeLicenseEnvs(e){e.license===void 0&&((process.env.MI_LICENSE??"")!=""?e.license=process.env.MI_LICENSE:(process.env.PL_LICENSE??"")!=""&&(e.license=process.env.PL_LICENSE)),e["license-file"]===void 0&&e.license===void 0&&((process.env.MI_LICENSE_FILE??"")!=""?e["license-file"]=process.env.MI_LICENSE_FILE:(process.env.PL_LICENSE_FILE??"")!=""?e["license-file"]=process.env.PL_LICENSE_FILE:l.existsSync(f.resolve(_.homedir(),".pl.license"))&&(e["license-file"]=f.resolve(_.homedir(),".pl.license")))}initAuthDriversList(e,r){var t=[];if(e["auth-htpasswd-file"]&&t.push({driver:"htpasswd",path:f.resolve(r,e["auth-htpasswd-file"])}),!!e["auth-ldap-server"]!=!!e["auth-ldap-default-dn"])throw new Error("LDAP auth settings require both 'server' and 'default DN' options to be set");if(e["auth-ldap-server"]&&t.push({driver:"ldap",serverUrl:e["auth-ldap-server"],defaultDN:e["auth-ldap-default-dn"]}),t.length!==0)return[{driver:"jwt",key:this.getLastJwt()},...t]}getLastJwt(){const e=o.path("auth.jwt"),r="utf-8";let t="";try{t=l.readFileSync(e,{encoding:r})}catch{}return t==""&&(t=or(64),l.writeFileSync(e,t,{encoding:r})),t}destroyDocker(e,r){const t=o.data("stub"),s=$.spawnSync("docker",["compose","--file",e,"down","--volumes","--remove-orphans"],{env:{...process.env,PL_IMAGE:"scratch",PL_DATA_DB_ROOT:t,PL_DATA_PRIMARY_ROOT:t,PL_DATA_LIBRARY_ROOT:t,PL_DATA_WORKDIR_ROOT:t,PL_DATA_PACKAGE_ROOT:t,MINIO_IMAGE:"scratch",MINIO_STORAGE:t},stdio:"inherit"});s.status!==0&&process.exit(s.status)}checkLicense(e,r){if(!(e!==void 0&&e!="")&&!(r!==void 0&&r!=""))throw this.logger.error(`A license for Platforma Backend must be set.
104
+ `)}mergeLicenseEnvs(e){e.license===void 0&&((process.env.MI_LICENSE??"")!=""?e.license=process.env.MI_LICENSE:(process.env.PL_LICENSE??"")!=""&&(e.license=process.env.PL_LICENSE)),e["license-file"]===void 0&&e.license===void 0&&((process.env.MI_LICENSE_FILE??"")!=""?e["license-file"]=process.env.MI_LICENSE_FILE:(process.env.PL_LICENSE_FILE??"")!=""?e["license-file"]=process.env.PL_LICENSE_FILE:l.existsSync(f.resolve(_.homedir(),".pl.license"))&&(e["license-file"]=f.resolve(_.homedir(),".pl.license")))}initAuthDriversList(e,r){var t=[];if(e["auth-htpasswd-file"]&&t.push({driver:"htpasswd",path:f.resolve(r,e["auth-htpasswd-file"])}),!!e["auth-ldap-server"]!=!!e["auth-ldap-default-dn"])throw new Error("LDAP auth settings require both 'server' and 'default DN' options to be set");if(e["auth-ldap-server"]&&t.push({driver:"ldap",serverUrl:e["auth-ldap-server"],defaultDN:e["auth-ldap-default-dn"]}),t.length!==0)return[{driver:"jwt",key:this.getLastJwt()},...t]}getLastJwt(){const e=o.path("auth.jwt"),r="utf-8";let t="";try{t=l.readFileSync(e,{encoding:r})}catch{}return t==""&&(t=fr(64),l.writeFileSync(e,t,{encoding:r})),t}destroyDocker(e,r){const t=o.data("stub"),s=$.spawnSync("docker",["compose","--file",e,"down","--volumes","--remove-orphans"],{env:{...process.env,PL_IMAGE:"scratch",PL_DATA_DB_ROOT:t,PL_DATA_PRIMARY_ROOT:t,PL_DATA_LIBRARY_ROOT:t,PL_DATA_WORKDIR_ROOT:t,PL_DATA_PACKAGE_ROOT:t,MINIO_IMAGE:"scratch",MINIO_STORAGE:t},stdio:"inherit"});s.status!==0&&process.exit(s.status)}checkLicense(e,r){if(!(e!==void 0&&e!="")&&!(r!==void 0&&r!=""))throw this.logger.error(`A license for Platforma Backend must be set.
97
105
 
98
106
  You can provide the license directly using the '--license' flag
99
107
  or use the '--license-file' flag if the license is stored in a file.
@@ -104,13 +112,5 @@ The license file can also be set with the variables 'MI_LICENSE_FILE' or 'PL_LIC
104
112
  or stored in '$HOME/.pl.license'.
105
113
 
106
114
  You can obtain the license from "https://licensing.milaboratories.com".`),new Error("The license was not provided.")}configureDockerStorage(e,r){const t={},s=r.type;switch(e=e.toUpperCase(),s){case"S3":return t[`PL_DATA_${e}_TYPE`]="S3",t[`PL_DATA_${e}_S3_BUCKET`]=r.bucketName,r.endpoint&&(t[`PL_DATA_${e}_S3_ENDPOINT`]=r.endpoint),r.presignEndpoint&&(t[`PL_DATA_${e}_S3_PRESIGN_ENDPOINT`]=r.presignEndpoint),r.region&&(t[`PL_DATA_${e}_S3_REGION`]=r.region),r.key&&(t[`PL_DATA_${e}_S3_KEY`]=r.key),r.secret&&(t[`PL_DATA_${e}_S3_SECRET`]=r.secret),t;case"FS":return t[`PL_DATA_${e}_TYPE`]="FS",t;default:J()}return{}}renderRunInfo(e,r=10){var n,m;const t=[],s=h=>h.padStart(r," ");switch(e.configPath&&t.push(`${s("config")}: ${e.configPath}`),e.apiAddr?t.push(`${s("API")}: ${e.apiAddr}`):e.apiPort?t.push(`${s("API")}: 127.0.0.1:${e.apiPort.toString()}`):t.push(`${s("API")}: 127.0.0.1:6345`),e.logPath&&t.push(`${s("log")}: ${e.logPath}`),(n=e.primary)==null?void 0:n.type){case void 0:break;case"FS":t.push(`${s("primary")}: ${e.primary.rootPath}`);break;case"S3":t.push(`${s("primary")}: S3 at '${e.primary.endpoint??"AWS"}', bucket '${e.primary.bucketName}', prefix: '${e.primary.keyPrefix??""}'`);break;default:J()}switch((m=e.library)==null?void 0:m.type){case void 0:break;case"FS":t.push(`${s("library")}: ${e.library.rootPath}`);break;case"S3":t.push(`${s("library")}: S3 at '${e.library.endpoint??"AWS"}', bucket '${e.library.bucketName}', prefix: '${e.library.keyPrefix??""}'`);break;default:J()}return e.work&&t.push(`${s("workdirs")}: ${e.work.rootPath}`),e.dbPath&&t.push(`${s("db")}: ${e.dbPath}`),t.join(`
107
- `)}readComposeFile(e){const r=l.readFileSync(e);return xe.parse(r.toString())}writeComposeFile(e,r){l.writeFileSync(e,xe.stringify(r))}}function q(a,e){if(a.error)throw a.error;const r=e??"failed to run command";if(a.status!==0)throw new Error(`${r}, process exited with code '${a.status}'`)}const T={"log-level":d.Flags.string({description:"logging level",default:"info",options:["error","warn","info","debug"],required:!1})},He={image:d.Flags.string({description:"use custom docker image to run platforma"})},Q={version:d.Flags.string({description:"use custom platforma release (official docker image or binary package)"})},X={license:d.Flags.string({description:'pass a license code. The license can be got from "https://licensing.milaboratories.com".'}),"license-file":d.Flags.file({exists:!0,description:"specify a path to the file with a license. The license can be got from 'https://licensing.milaboratories.com'."})},Z={"grpc-port":d.Flags.integer({description:"port for Platforma Backend gRPC API. Default is 6345",env:"PLATFORMA_GRPC_PORT"}),"grpc-listen":d.Flags.string({description:"full listen addr for Platforma Backend gRPC API. Default is 127.0.0.1:6345",env:"PLATFORMA_GRPC_LISTEN"}),"monitoring-port":d.Flags.integer({description:"port for Platforma Backend monitoring API. Default is 9090",env:"PLATFORMA_MONITORING_PORT"}),"monitoring-listen":d.Flags.string({description:"full listen addr for Platforma Backend monitoring API. Default is 127.0.0.1:9090",env:"PLATFORMA_MONITORING_LISTEN"}),"debug-port":d.Flags.integer({description:"port for Platforma Backend debug API. Default is 9091",env:"PLATFORMA_DEBUG_PORT"}),"debug-listen":d.Flags.string({description:"full listen addr for Platforma Backend debug API. Default is 127.0.0.1:9091",env:"PLATFORMA_DEBUG_LISTEN"})},Rr={"s3-address-port":d.Flags.integer({description:"port that S3 will listen, default is 9000",default:9e3,env:"PLATFORMA_S3_PORT"}),"s3-console-address-port":d.Flags.integer({description:"port that a console of S3 will listen, default is 9001",default:9001,env:"PLATFORMA_S3_CONSOLE_PORT"})},ee={storage:d.Flags.string({description:"specify path on host to be used as storage for all Platforma Backend data"})},ze={"pl-log-file":d.Flags.file({description:"specify path for Platforma Backend log file"})},Ye={"pl-workdir":d.Flags.file({description:"specify working directory for Platforma Backend process"})},Ke={"pl-binary":d.Flags.file({description:"start given Platforma Backend binary instead of automatically downloaded version"})},Ve={"pl-sources":d.Flags.file({description:"path to pl repository root: build Platforma Backend from sources and start the resulting binary"})},Qe={config:d.Flags.string({description:"use custom Platforma Backend config"})};d.Flags.file({description:"specify path on host to be used as 'primary' storage"});const ue={"storage-work":d.Flags.file({description:"specify path on host to be used as 'work' storage"})};d.Flags.file({description:"specify path on host to be used as 'library' storage"});const fe={"storage-primary":d.Flags.string({description:`specify 'primary' storage destination URL.
108
- file:/path/to/dir for directory on local FS
109
- s3://<bucket>/?region=<name> for real AWS bucket
110
- s3e://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via http
111
- s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},he={"storage-library":d.Flags.string({description:`specify 'library' storage destination URL.
112
- file:/path/to/dir for directory on local FS
113
- s3://<bucket>/?region=<name> for real AWS bucket
114
- s3e://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via http
115
- s3es://<endpoint>/<bucket>/?region=<name> for bucket behind custom endpoint via https`})},_r={"auth-enabled":d.Flags.boolean({description:"enable authorization"})},pr={"auth-htpasswd-file":d.Flags.file({description:"path to .htpasswd file with Platforma users (static user DB auth source)"})},Or={"auth-ldap-server":d.Flags.string({description:"address of LDAP server to use for auth in Platforma (auth source)"})},$r={"auth-ldap-default-dn":d.Flags.string({description:"DN to use when checking user with LDAP bind operation: e.g. cn=%u,ou=users,dc=example,dc=com"})},re={..._r,...pr,...Or,...$r},I=class I extends d.Command{async run(){const{flags:e}=await this.parse(I),r=F(e["log-level"]);new D(r).stop()}};y(I,"description","Stop platforma service"),y(I,"examples",["<%= config.bin %> <%= command.id %>"]),y(I,"flags",{...T});let ie=I;const x=class x extends d.Command{async run(){const{flags:e}=await this.parse(x),r=F(e["log-level"]);new D(r).cleanup()}};y(x,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),y(x,"examples",["<%= config.bin %> <%= command.id %>"]),y(x,"flags",{...T});let ce=x;const M=class M extends d.Command{async run(){const{flags:e}=await this.parse(M),r=F(e["log-level"]);new D(r).startLast()}};y(M,"description","Start last run service configuraiton"),y(M,"examples",["<%= config.bin %> <%= command.id %>"]),y(M,"flags",{...T});let ne=M;const C=class C extends d.Command{async run(){const{flags:e}=await this.parse(C),r=F(e["log-level"]),t=new D(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,c=e.storage?f.join(".",e.storage):o.data("docker");t.startDocker(c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]})}};y(C,"description","Run platforma backend service with 'FS' primary storage type"),y(C,"examples",["<%= config.bin %> <%= command.id %>"]),y(C,"flags",{...T,...Z,...He,...Q,...re,...X,...ee,...fe,...ue,...he});let le=C;var R;let Fr=(R=class extends d.Command{async run(){const{flags:e}=await this.parse(R),r=F(e["log-level"]),t=new D(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,c=e.storage?f.join(".",e.storage):o.data("docker-s3");t.startDockerS3(c,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]})}},y(R,"description","Run platforma backend service with 'S3' primary storage type"),y(R,"examples",["<%= config.bin %> <%= command.id %>"]),y(R,"flags",{...T,...Z,...He,...Q,...ee,...X,...re}),R);const B=class B extends d.Command{async run(){const{flags:e}=await this.parse(B),r=F(e["log-level"]),t=new D(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?f.join(s,e.storage):o.data("local"),c=e["pl-log-file"]?f.join(s,e["pl-log-file"]):void 0,n=t.initAuthDriversList(e,s),m=e["auth-enabled"]??n!==void 0;var h=e["pl-binary"];e["pl-sources"]&&(h=t.buildPlatforma({repoRoot:e["pl-sources"]}));var u="127.0.0.1:6345";e["grpc-listen"]?u=e["grpc-listen"]:e["grpc-port"]&&(u=`127.0.0.1:${e["grpc-port"]}`);var v="127.0.0.1:9090";e["monitoring-listen"]?v=e["monitoring-listen"]:e["monitoring-port"]&&(v=`127.0.0.1:${e["monitoring-port"]}`);var P="127.0.0.1:9091";e["debug-listen"]?P=e["debug-listen"]:e["debug-port"]&&(P=`127.0.0.1:${e["debug-port"]}`);const g={binaryPath:h,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:u},monitoring:{listen:v},debug:{listen:P},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:m,drivers:n}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};g.binaryPath?t.startLocal(g):qe(r,{version:e.version}).then(()=>t.startLocal(g)).catch(function(b){r.error(b.message)})}};y(B,"description","Run Platforma Backend service as local process on current host (no docker container)"),y(B,"examples",["<%= config.bin %> <%= command.id %>"]),y(B,"flags",{...T,...Q,...Z,...Ke,...Ve,...Qe,...X,...ee,...fe,...ue,...he,...ze,...Ye,...re});let oe=B;const G=class G extends d.Command{async run(){const{flags:e}=await this.parse(G),r=F(e["log-level"]),t=new D(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?f.join(s,e.storage):o.data("local-s3"),c=e["pl-log-file"]?f.join(s,e["pl-log-file"]):void 0,n=t.initAuthDriversList(e,s),m=e["auth-enabled"]??n!==void 0;var h=e["pl-binary"];e["pl-sources"]&&(h=t.buildPlatforma({repoRoot:e["pl-sources"]}));var u="127.0.0.1:6345";e["grpc-listen"]?u=e["grpc-listen"]:e["grpc-port"]&&(u=`127.0.0.1:${e["grpc-port"]}`);var v="127.0.0.1:9090";e["monitoring-listen"]?v=e["monitoring-listen"]:e["monitoring-port"]&&(v=`127.0.0.1:${e["monitoring-port"]}`);var P="127.0.0.1:9091";e["debug-listen"]?P=e["debug-listen"]:e["debug-port"]&&(P=`127.0.0.1:${e["debug-port"]}`);const g={binaryPath:h,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-address-port"],minioConsolePort:e["s3-console-address-port"],configOptions:{grpc:{listen:u},monitoring:{listen:v},debug:{listen:P},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:m,drivers:n}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};g.binaryPath?t.startLocalS3(g):qe(r,{version:e.version}).then(()=>t.startLocalS3(g)).catch(function(b){r.error(b.message)})}};y(G,"description","Run Platforma Backend service as local process on current host (no docker container)"),y(G,"examples",["<%= config.bin %> <%= command.id %>"]),y(G,"flags",{...T,...Q,...Z,...Rr,...Ke,...Ve,...Qe,...X,...ee,...fe,...ue,...he,...ze,...Ye,...re});let de=G;const Tr=z.z.object({npmOrgName:z.z.string().min(1),orgName:z.z.string().min(1),blockName:z.z.string().min(1)});async function Er(a){const e=Dr(),r=f.join(process.cwd(),e.blockName);a.info("Downloading boilerplate code..."),await Nr("https://github.com/milaboratory/platforma-block-boilerplate/archive/refs/heads/main.zip","platforma-block-boilerplate-main",r),a.info("Replace everything in the template with provided options..."),Ir(r,/pl-open\/my-org.block-boilerplate/g,`${e.npmOrgName}/${e.orgName}.${e.blockName}`)}function Dr(){let a=K.question('Write an organization name for npm. Default is "pl-open": ');a===""&&(a="pl-open");const e=K.question('Write an organization name, e.g. "my-org": '),r=K.question('Write a name of the block, e.g. "hello-world": ');return Tr.parse({npmOrgName:a,orgName:e,blockName:r})}async function Nr(a,e,r){const s=await(await fetch(a)).blob(),i=l.mkdtempSync(f.join(_.tmpdir(),"create-repo")),c=f.join(i,"packed-repo.zip"),n=ar.Writable.toWeb(l.createWriteStream(c));await s.stream().pipeTo(n);const m=f.join(i,"unpacked-repo");l.mkdirSync(m),await sr(c,m),l.cpSync(f.join(m,e),r,{recursive:!0})}function Ir(a,e,r){xr(a).forEach(t=>Mr(t,e,r))}function xr(a){return l.readdirSync(a,{withFileTypes:!0,recursive:!0}).filter(r=>r.isFile()).map(r=>f.join(r.parentPath,r.name))}function Mr(a,e,r){const s=l.readFileSync(a).toString().replaceAll(e,r);l.writeFileSync(a,s)}const U=class U extends d.Command{async run(){const{flags:e}=await this.parse(U),r=F(e["log-level"]);await Er(r)}};y(U,"description","Helps to create a new block by downloading a block's template."),y(U,"examples",["<%= name %>"]),y(U,"flags",{...T});let ge=U;const Cr={stop:ie,start:ne,reset:ce,"create-block":ge,"start docker":le,"start local":oe,"start docker s3":Fr,"start local s3":de};exports.COMMANDS=Cr;
115
+ `)}readComposeFile(e){const r=l.readFileSync(e);return xe.parse(r.toString())}writeComposeFile(e,r){l.writeFileSync(e,xe.stringify(r))}}function q(a,e){if(a.error)throw a.error;const r=e??"failed to run command";if(a.status!==0)throw new Error(`${r}, process exited with code '${a.status}'`)}const x=class x extends d.Command{async run(){const{flags:e}=await this.parse(x),r=T(e["log-level"]);new D(r).cleanup()}};y(x,"description","Clear service state (forget last run command, destroy docker services, volumes and so on)"),y(x,"examples",["<%= config.bin %> <%= command.id %>"]),y(x,"flags",{...F});let ce=x;const M=class M extends d.Command{async run(){const{flags:e}=await this.parse(M),r=T(e["log-level"]);new D(r).startLast()}};y(M,"description","Start last run service configuraiton"),y(M,"examples",["<%= config.bin %> <%= command.id %>"]),y(M,"flags",{...F});let ne=M;const C=class C extends d.Command{async run(){const{flags:e}=await this.parse(C),r=T(e["log-level"]);new D(r).stop()}};y(C,"description","Stop platforma service"),y(C,"examples",["<%= config.bin %> <%= command.id %>"]),y(C,"flags",{...F});let le=C;const B=class B extends d.Command{async run(){const{flags:e}=await this.parse(B),r=T(e["log-level"]),t=new D(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,c=e.storage?f.join(".",e.storage):o.data("docker");t.startDocker(c,{primaryStorageURL:e["storage-primary"],workStoragePath:e["storage-work"],libraryStorageURL:e["storage-library"],image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]})}};y(B,"description","Run platforma backend service with 'FS' primary storage type"),y(B,"examples",["<%= config.bin %> <%= command.id %>"]),y(B,"flags",{...F,...X,...Be,...V,...ee,...Q,...Z,...fe,...ue,...he});let oe=B;const G=class G extends d.Command{async run(){const{flags:e}=await this.parse(G),r=T(e["log-level"]),t=new D(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?f.join(s,e.storage):o.data("local"),c=e["pl-log-file"]?f.join(s,e["pl-log-file"]):void 0,n=t.initAuthDriversList(e,s),m=e["auth-enabled"]??n!==void 0;var h=e["pl-binary"];e["pl-sources"]&&(h=t.buildPlatforma({repoRoot:e["pl-sources"]}));var u="127.0.0.1:6345";e["grpc-listen"]?u=e["grpc-listen"]:e["grpc-port"]&&(u=`127.0.0.1:${e["grpc-port"]}`);var v="127.0.0.1:9090";e["monitoring-listen"]?v=e["monitoring-listen"]:e["monitoring-port"]&&(v=`127.0.0.1:${e["monitoring-port"]}`);var P="127.0.0.1:9091";e["debug-listen"]?P=e["debug-listen"]:e["debug-port"]&&(P=`127.0.0.1:${e["debug-port"]}`);const g={binaryPath:h,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],configOptions:{grpc:{listen:u},monitoring:{listen:v},debug:{listen:P},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:m,drivers:n}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};g.binaryPath?t.startLocal(g):Ve(r,{version:e.version}).then(()=>t.startLocal(g)).catch(function(b){r.error(b.message)})}};y(G,"description","Run Platforma Backend service as local process on current host (no docker container)"),y(G,"examples",["<%= config.bin %> <%= command.id %>"]),y(G,"flags",{...F,...V,...X,...je,...We,...qe,...Q,...Z,...fe,...ue,...he,...Ge,...Ue,...ee});let de=G;var R;let Mr=(R=class extends d.Command{async run(){const{flags:e}=await this.parse(R),r=T(e["log-level"]),t=new D(r);t.mergeLicenseEnvs(e);const s=e["auth-enabled"],i=s?{enabled:s,drivers:t.initAuthDriversList(e,".")}:void 0,c=e.storage?f.join(".",e.storage):o.data("docker-s3");t.startDockerS3(c,{image:e.image,version:e.version,license:e.license,licenseFile:e["license-file"],auth:i,grpcAddr:e["grpc-listen"],grpcPort:e["grpc-port"],monitoringAddr:e["monitoring-listen"],monitoringPort:e["monitoring-port"],debugAddr:e["debug-listen"],debugPort:e["debug-port"]})}},y(R,"description","Run platforma backend service with 'S3' primary storage type"),y(R,"examples",["<%= config.bin %> <%= command.id %>"]),y(R,"flags",{...F,...X,...Be,...V,...Z,...Q,...ee}),R);const U=class U extends d.Command{async run(){const{flags:e}=await this.parse(U),r=T(e["log-level"]),t=new D(r);t.mergeLicenseEnvs(e);const s=e["pl-workdir"]??".",i=e.storage?f.join(s,e.storage):o.data("local-s3"),c=e["pl-log-file"]?f.join(s,e["pl-log-file"]):void 0,n=t.initAuthDriversList(e,s),m=e["auth-enabled"]??n!==void 0;var h=e["pl-binary"];e["pl-sources"]&&(h=t.buildPlatforma({repoRoot:e["pl-sources"]}));var u="127.0.0.1:6345";e["grpc-listen"]?u=e["grpc-listen"]:e["grpc-port"]&&(u=`127.0.0.1:${e["grpc-port"]}`);var v="127.0.0.1:9090";e["monitoring-listen"]?v=e["monitoring-listen"]:e["monitoring-port"]&&(v=`127.0.0.1:${e["monitoring-port"]}`);var P="127.0.0.1:9091";e["debug-listen"]?P=e["debug-listen"]:e["debug-port"]&&(P=`127.0.0.1:${e["debug-port"]}`);const g={binaryPath:h,version:e.version,configPath:e.config,workdir:e["pl-workdir"],primaryURL:e["storage-primary"],libraryURL:e["storage-library"],minioPort:e["s3-address-port"],minioConsolePort:e["s3-console-address-port"],configOptions:{grpc:{listen:u},monitoring:{listen:v},debug:{listen:P},license:{value:e.license,file:e["license-file"]},log:{path:c},localRoot:i,core:{auth:{enabled:m,drivers:n}},storages:{work:{type:"FS",rootPath:e["storage-work"]}}}};g.binaryPath?t.startLocalS3(g):Ve(r,{version:e.version}).then(()=>t.startLocalS3(g)).catch(function(b){r.error(b.message)})}};y(U,"description","Run Platforma Backend service as local process on current host (no docker container)"),y(U,"examples",["<%= config.bin %> <%= command.id %>"]),y(U,"flags",{...F,...V,...X,...nr,...je,...We,...qe,...Q,...Z,...fe,...ue,...he,...Ge,...Ue,...ee});let ge=U;const Cr={"create-block":se,reset:ce,start:ne,stop:le,"start:docker":oe,"start:local":de,"start:docker:s3":Mr,"start:local:s3":ge};exports.COMMANDS=Cr;
116
116
  //# sourceMappingURL=index.js.map