@milaboratories/pl-middle-layer 1.37.4 → 1.37.5

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.
Files changed (35) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.d.ts.map +1 -1
  3. package/dist/index.js +40 -14
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +1747 -1468
  6. package/dist/index.mjs.map +1 -1
  7. package/dist/mutator/context_export.d.ts +2 -2
  8. package/dist/mutator/context_export.d.ts.map +1 -1
  9. package/dist/mutator/template/render_template.d.ts +2 -2
  10. package/dist/mutator/template/render_template.d.ts.map +1 -1
  11. package/dist/network_check/network_check.d.ts +40 -0
  12. package/dist/network_check/network_check.d.ts.map +1 -0
  13. package/dist/network_check/network_check.test.d.ts.map +1 -0
  14. package/dist/network_check/pings.d.ts +32 -0
  15. package/dist/network_check/pings.d.ts.map +1 -0
  16. package/dist/network_check/template.d.ts +33 -0
  17. package/dist/network_check/template.d.ts.map +1 -0
  18. package/dist/network_check/template.test.d.ts +2 -0
  19. package/dist/network_check/template.test.d.ts.map +1 -0
  20. package/dist/network_check/test_utils.d.ts +6 -0
  21. package/dist/network_check/test_utils.d.ts.map +1 -0
  22. package/package.json +10 -10
  23. package/src/index.ts +1 -1
  24. package/src/mutator/template/render_template.ts +2 -2
  25. package/src/{network_check.test.ts → network_check/network_check.test.ts} +3 -3
  26. package/src/network_check/network_check.ts +369 -0
  27. package/src/network_check/pings.ts +154 -0
  28. package/src/network_check/template.test.ts +83 -0
  29. package/src/network_check/template.ts +330 -0
  30. package/src/network_check/test_utils.ts +9 -0
  31. package/dist/network_check.d.ts +0 -29
  32. package/dist/network_check.d.ts.map +0 -1
  33. package/dist/network_check.test.d.ts.map +0 -1
  34. package/src/network_check.ts +0 -329
  35. /package/dist/{network_check.test.d.ts → network_check/network_check.test.d.ts} +0 -0
@@ -1,9 +1,9 @@
1
- import { AnyRef, PlTransaction } from '@milaboratories/pl-client';
1
+ import { AnyRef, PlTransaction, FieldRef } from '@milaboratories/pl-client';
2
2
  import { TemplateSpecPrepared } from '../model/template_spec';
3
3
  export type TemplateEnvelop = {
4
4
  spec: TemplateSpecPrepared;
5
5
  hash: string;
6
6
  };
7
7
  export declare function getPreparedExportTemplateEnvelope(): Promise<TemplateEnvelop>;
8
- export declare function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef): AnyRef;
8
+ export declare function exportContext(tx: PlTransaction, exportTpl: AnyRef, ctx: AnyRef): FieldRef;
9
9
  //# sourceMappingURL=context_export.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"context_export.d.ts","sourceRoot":"","sources":["../../src/mutator/context_export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAWnE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAI3E,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,eAAe,CAAC,CAUlF;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,UAE9E"}
1
+ {"version":3,"file":"context_export.d.ts","sourceRoot":"","sources":["../../src/mutator/context_export.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAGvE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAWnE,MAAM,MAAM,eAAe,GAAG;IAAE,IAAI,EAAE,oBAAoB,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAI3E,wBAAsB,iCAAiC,IAAI,OAAO,CAAC,eAAe,CAAC,CAUlF;AAED,wBAAgB,aAAa,CAAC,EAAE,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gDAE9E"}
@@ -1,4 +1,4 @@
1
- import { AnyRef, PlTransaction, Pl } from '@milaboratories/pl-client';
1
+ import { AnyRef, FieldRef, PlTransaction, Pl } from '@milaboratories/pl-client';
2
2
  /**
3
3
  * Creates render template operation, for a given remplate and inputs.
4
4
  *
@@ -8,5 +8,5 @@ import { AnyRef, PlTransaction, Pl } from '@milaboratories/pl-client';
8
8
  * @param inputs map of inputs pointing to other resources or fields
9
9
  * @param outputNames names of the outputs to collect and return from this method
10
10
  */
11
- export declare function createRenderTemplate<O extends string>(tx: PlTransaction, tpl: AnyRef, ephemeral: boolean, inputs: Pl.PlRecord, outputNames: O[]): Record<O, AnyRef>;
11
+ export declare function createRenderTemplate<O extends string>(tx: PlTransaction, tpl: AnyRef, ephemeral: boolean, inputs: Pl.PlRecord, outputNames: O[]): Record<O, FieldRef>;
12
12
  //# sourceMappingURL=render_template.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"render_template.d.ts","sourceRoot":"","sources":["../../../src/mutator/template/render_template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACvE,OAAO,EAAS,EAAE,EAAE,MAAM,2BAA2B,CAAC;AAYtD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,EAAE,EAAE,aAAa,EACjB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,EAAE,CAAC,QAAQ,EACnB,WAAW,EAAE,CAAC,EAAE,GACf,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,CAYnB"}
1
+ {"version":3,"file":"render_template.d.ts","sourceRoot":"","sources":["../../../src/mutator/template/render_template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAS,EAAE,EAAE,MAAM,2BAA2B,CAAC;AAYtD;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,EACnD,EAAE,EAAE,aAAa,EACjB,GAAG,EAAE,MAAM,EACX,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,EAAE,CAAC,QAAQ,EACnB,WAAW,EAAE,CAAC,EAAE,GACf,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,CAYrB"}
@@ -0,0 +1,40 @@
1
+ import { PlClientConfig, PlClient } from '@milaboratories/pl-client';
2
+ import { MiLogger } from '@milaboratories/ts-helpers';
3
+ import { ClientDownload, ClientUpload, LsDriver } from '@milaboratories/pl-drivers';
4
+ import { Dispatcher } from 'undici';
5
+ export interface CheckNetworkOpts {
6
+ /** Platforma Backend pings options. */
7
+ pingCheckDurationMs: number;
8
+ pingTimeoutMs: number;
9
+ maxPingsPerSecond: number;
10
+ /** An options for CDN and block registry. */
11
+ httpTimeoutMs: number;
12
+ /** Block registry pings options. */
13
+ blockRegistryDurationMs: number;
14
+ maxRegistryChecksPerSecond: number;
15
+ blockRegistryUrl: string;
16
+ blockGARegistryUrl: string;
17
+ blockOverviewPath: string;
18
+ blockUiPath: string;
19
+ /** CDN for auto-update pings options. */
20
+ autoUpdateCdnDurationMs: number;
21
+ maxAutoUpdateCdnChecksPerSecond: number;
22
+ autoUpdateCdnUrl: string;
23
+ bodyLimit: number;
24
+ }
25
+ /** Checks connectivity to Platforma Backend, to block registry
26
+ * and to auto-update CDN,
27
+ * and generates a string report. */
28
+ export declare function checkNetwork(plCredentials: string, plUser: string | undefined, plPassword: string | undefined, optsOverrides?: Partial<CheckNetworkOpts>): Promise<string>;
29
+ export declare function initNetworkCheck(plCredentials: string, plUser: string | undefined, plPassword: string | undefined, optsOverrides?: Partial<CheckNetworkOpts>): Promise<{
30
+ logger: MiLogger;
31
+ plConfig: PlClientConfig;
32
+ client: PlClient;
33
+ downloadClient: ClientDownload;
34
+ uploadBlobClient: ClientUpload;
35
+ lsDriver: LsDriver;
36
+ httpClient: Dispatcher;
37
+ ops: CheckNetworkOpts;
38
+ terminate: () => Promise<void>;
39
+ }>;
40
+ //# sourceMappingURL=network_check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network_check.d.ts","sourceRoot":"","sources":["../../src/network_check/network_check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACjF,OAAO,EAAE,QAAQ,EAA8C,MAAM,2BAA2B,CAAC;AACjG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAG3D,OAAO,KAAK,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC/E,OAAO,EAAE,QAAQ,EAAgD,MAAM,4BAA4B,CAAC;AAGpG,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAsBzC,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,mBAAmB,EAAE,MAAM,CAAC;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,iBAAiB,EAAE,MAAM,CAAC;IAE1B,6CAA6C;IAC7C,aAAa,EAAE,MAAM,CAAC;IAEtB,oCAAoC;IACpC,uBAAuB,EAAE,MAAM,CAAC;IAChC,0BAA0B,EAAE,MAAM,CAAC;IACnC,gBAAgB,EAAE,MAAM,CAAC;IACzB,kBAAkB,EAAE,MAAM,CAAC;IAC3B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,CAAC;IAEpB,yCAAyC;IACzC,uBAAuB,EAAE,MAAM,CAAC;IAChC,+BAA+B,EAAE,MAAM,CAAC;IACxC,gBAAgB,EAAE,MAAM,CAAC;IAEzB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;oCAEoC;AACpC,wBAAsB,YAAY,CAChC,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,aAAa,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAC5C,OAAO,CAAC,MAAM,CAAC,CA6DjB;AAED,wBAAsB,gBAAgB,CACpC,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,MAAM,GAAG,SAAS,EAC1B,UAAU,EAAE,MAAM,GAAG,SAAS,EAC9B,aAAa,GAAE,OAAO,CAAC,gBAAgB,CAAM,GAC5C,OAAO,CAAC;IACP,MAAM,EAAE,QAAQ,CAAC;IACjB,QAAQ,EAAE,cAAc,CAAC;IACzB,MAAM,EAAE,QAAQ,CAAC;IACjB,cAAc,EAAE,cAAc,CAAC;IAC/B,gBAAgB,EAAE,YAAY,CAAC;IAC/B,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,UAAU,CAAC;IACvB,GAAG,EAAE,gBAAgB,CAAC;IACtB,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC,CAAC,CA2FH"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"network_check.test.d.ts","sourceRoot":"","sources":["../../src/network_check/network_check.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,32 @@
1
+ import { ValueOrError } from '@milaboratories/ts-helpers';
2
+ import { Dispatcher } from 'undici';
3
+ import { CheckNetworkOpts } from './network_check';
4
+ import { PlClientConfig } from '@milaboratories/pl-client';
5
+ /** A report about one concrete ping to the service. */
6
+ export interface NetworkReport<T> {
7
+ elapsedMs: number;
8
+ response: ValueOrError<T>;
9
+ }
10
+ export type HttpNetworkReport = NetworkReport<{
11
+ statusCode: number;
12
+ beginningOfBody: string;
13
+ }>;
14
+ export declare function backendPings(ops: CheckNetworkOpts, plConfig: PlClientConfig): Promise<NetworkReport<string>[]>;
15
+ export declare function blockRegistryOverviewPings(ops: CheckNetworkOpts, httpClient: Dispatcher): Promise<HttpNetworkReport[]>;
16
+ export declare function blockGARegistryOverviewPings(ops: CheckNetworkOpts, httpClient: Dispatcher): Promise<HttpNetworkReport[]>;
17
+ export declare function blockRegistryUiPings(ops: CheckNetworkOpts, httpClient: Dispatcher): Promise<HttpNetworkReport[]>;
18
+ export declare function blockGARegistryUiPings(ops: CheckNetworkOpts, httpClient: Dispatcher): Promise<HttpNetworkReport[]>;
19
+ export declare function autoUpdateCdnPings(ops: CheckNetworkOpts, httpClient: Dispatcher): Promise<HttpNetworkReport[]>;
20
+ /** Executes a body several times per second up to the given duration,
21
+ * and returns results and elapsed time for every result. */
22
+ export declare function recordPings<T>(pingCheckDurationMs: number, maxPingsPerSecond: number, body: () => Promise<T>): Promise<NetworkReport<T>[]>;
23
+ export declare function requestUrl(url: string | URL, ops: CheckNetworkOpts, httpClient: Dispatcher): Promise<{
24
+ statusCode: number;
25
+ beginningOfBody: string;
26
+ }>;
27
+ export declare function elapsed(startMs: number): number;
28
+ export declare function reportToString<T>(report: NetworkReport<T>[]): {
29
+ ok: boolean;
30
+ details: string;
31
+ };
32
+ //# sourceMappingURL=pings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pings.d.ts","sourceRoot":"","sources":["../../src/network_check/pings.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACxD,OAAO,EAA2B,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEzF,uDAAuD;AACvD,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;CAC3B;AAED,MAAM,MAAM,iBAAiB,GAAG,aAAa,CAAC;IAC5C,UAAU,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a,CAAC,CAAC,CAAC,EAAE,GAAG;IAC7D,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB,CAiBA"}
@@ -0,0 +1,33 @@
1
+ import { PlClient } from '@milaboratories/pl-client';
2
+ import { ClientDownload, LsDriver, ClientUpload } from '@milaboratories/pl-drivers';
3
+ import { MiLogger } from '@milaboratories/ts-helpers';
4
+ import { ResourceInfo } from '@milaboratories/pl-tree';
5
+ export interface TemplateReport {
6
+ ok: boolean;
7
+ message: string;
8
+ }
9
+ /** Uploads `hello-world` template and checks the output is correct. */
10
+ export declare function uploadTemplate(logger: MiLogger, pl: PlClient, name: string): Promise<TemplateReport>;
11
+ export declare function runUploadTemplate(logger: MiLogger, pl: PlClient, name: string): Promise<string>;
12
+ /** Uploads a file to the backend and checks the output is a Blob resource. */
13
+ export declare function uploadFile(logger: MiLogger, lsDriver: LsDriver, uploadClient: ClientUpload, pl: PlClient, filePath: string): Promise<TemplateReport>;
14
+ export declare function runUploadFile(logger: MiLogger, lsDriver: LsDriver, uploadClient: ClientUpload, pl: PlClient, filePath: string): Promise<ResourceInfo>;
15
+ /** Uploads a file to the backend and then tries to download it back. */
16
+ export declare function downloadFile(logger: MiLogger, pl: PlClient, lsDriver: LsDriver, uploadClient: ClientUpload, downloadClient: ClientDownload, filePath: string, fileContent: string): Promise<TemplateReport>;
17
+ export declare function runDownloadFile(logger: MiLogger, pl: PlClient, lsDriver: LsDriver, uploadClient: ClientUpload, downloadClient: ClientDownload, filePath: string): Promise<string>;
18
+ /** Runs Go's hello-world binary. */
19
+ export declare function softwareCheck(pl: PlClient): Promise<TemplateReport>;
20
+ export declare function runSoftware(pl: PlClient): Promise<string>;
21
+ /** Runs Python hello-world. */
22
+ export declare function pythonSoftware(pl: PlClient, name: string): Promise<TemplateReport>;
23
+ export declare function runPythonSoftware(pl: PlClient, name: string): Promise<string>;
24
+ /** Creates a big temporary file with random content. */
25
+ export declare function createBigTempFile(): Promise<{
26
+ filePath: string;
27
+ }>;
28
+ /** Creates a temporarly file we could use for uploading and downloading. */
29
+ export declare function createTempFile(): Promise<{
30
+ filePath: string;
31
+ fileContent: string;
32
+ }>;
33
+ //# sourceMappingURL=template.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../src/network_check/template.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAqB,QAAQ,EAAgB,MAAM,2BAA2B,CAAC;AAM3F,OAAO,KAAK,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC3E,OAAO,EAA0C,KAAK,YAAY,EAAE,MAAM,4BAA4B,CAAC;AACvG,OAAO,EAAY,KAAK,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAO5D,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,OAAO,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,uEAAuE;AACvE,wBAAsB,cAAc,CAAC,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,CAAC,CAW1G;AAED,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,QAAQ,EAChB,EAAE,EAAE,QAAQ,EACZ,IAAI,EAAE,MAAM,GACX,OAAO,CAAC,MAAM,CAAC,CAgBjB;AAED,8EAA8E;AAC9E,wBAAsB,UAAU,CAC9B,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,QAAQ,EACZ,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,cAAc,CAAC,CAYzB;AAED,wBAAsB,aAAa,CACjC,MAAM,EAAE,QAAQ,EAChB,QAAQ,EAAE,QAAQ,EAClB,YAAY,EAAE,YAAY,EAC1B,EAAE,EAAE,QAAQ,EACZ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.d.ts","sourceRoot":"","sources":["../../src/network_check/template.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,6 @@
1
+ export declare function testCredentials(): {
2
+ plEndpoint: string;
3
+ plUser: string | undefined;
4
+ plPassword: string | undefined;
5
+ };
6
+ //# sourceMappingURL=test_utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test_utils.d.ts","sourceRoot":"","sources":["../../src/network_check/test_utils.ts"],"names":[],"mappings":"AAAA,wBAAgB,eAAe;;;;EAQ9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@milaboratories/pl-middle-layer",
3
- "version": "1.37.4",
3
+ "version": "1.37.5",
4
4
  "description": "Pl Middle Layer",
5
5
  "engines": {
6
6
  "node": ">=20.16.0"
@@ -33,21 +33,21 @@
33
33
  "zod": "~3.23.8",
34
34
  "remeda": "^2.21.2",
35
35
  "@milaboratories/pl-http": "^1.1.2",
36
- "@milaboratories/resolve-helper": "^1.1.0",
37
- "@milaboratories/pl-drivers": "^1.5.50",
38
36
  "@milaboratories/computable": "^2.4.7",
39
37
  "@platforma-sdk/block-tools": "^2.5.44",
40
38
  "@milaboratories/pl-client": "^2.9.0",
41
- "@milaboratories/pl-model-common": "^1.14.0",
39
+ "@milaboratories/pl-drivers": "^1.5.51",
42
40
  "@milaboratories/pl-model-middle-layer": "^1.7.29",
41
+ "@milaboratories/pl-model-common": "^1.14.0",
43
42
  "@milaboratories/pl-model-backend": "^1.1.0",
43
+ "@milaboratories/resolve-helper": "^1.1.0",
44
44
  "@platforma-sdk/model": "^1.30.3",
45
- "@milaboratories/ts-helpers": "^1.2.0",
46
45
  "@milaboratories/pl-tree": "^1.6.0",
46
+ "@milaboratories/ts-helpers": "^1.2.0",
47
+ "@platforma-sdk/workflow-tengo": "4.2.1",
47
48
  "@milaboratories/pl-config": "^1.4.9",
48
- "@platforma-sdk/workflow-tengo": "4.2.0",
49
- "@milaboratories/pl-deployments": "^2.1.2",
50
- "@milaboratories/pl-errors": "^1.0.9"
49
+ "@milaboratories/pl-errors": "^1.0.9",
50
+ "@milaboratories/pl-deployments": "^2.1.2"
51
51
  },
52
52
  "devDependencies": {
53
53
  "semver": "^7.6.3",
@@ -60,8 +60,8 @@
60
60
  "jest": "^29.7.0",
61
61
  "@jest/globals": "^29.7.0",
62
62
  "ts-jest": "^29.2.6",
63
- "@milaboratories/eslint-config": "^1.0.4",
64
- "@milaboratories/platforma-build-configs": "1.0.3"
63
+ "@milaboratories/platforma-build-configs": "1.0.3",
64
+ "@milaboratories/eslint-config": "^1.0.4"
65
65
  },
66
66
  "scripts": {
67
67
  "type-check": "tsc --noEmit --composite false",
package/src/index.ts CHANGED
@@ -6,7 +6,7 @@ export * from './block_registry';
6
6
  export * from './middle_layer';
7
7
  export * from './model';
8
8
 
9
- export * from './network_check';
9
+ export * from './network_check/network_check';
10
10
 
11
11
  // explicitly override ProjectListEntry from SDK
12
12
  export { type ProjectListEntry } from './model';
@@ -1,4 +1,4 @@
1
- import type { AnyRef, PlTransaction } from '@milaboratories/pl-client';
1
+ import type { AnyRef, FieldRef, PlTransaction } from '@milaboratories/pl-client';
2
2
  import { field, Pl } from '@milaboratories/pl-client';
3
3
  import type { ResourceType } from '@platforma-sdk/model';
4
4
 
@@ -26,7 +26,7 @@ export function createRenderTemplate<O extends string>(
26
26
  ephemeral: boolean,
27
27
  inputs: Pl.PlRecord,
28
28
  outputNames: O[],
29
- ): Record<O, AnyRef> {
29
+ ): Record<O, FieldRef> {
30
30
  if (outputNames.length === 0) throw new Error('Zero output names provided');
31
31
  const rId = ephemeral ? tx.createEphemeral(EphRenderTemplate) : tx.createStruct(RenderTemplate);
32
32
 
@@ -1,10 +1,10 @@
1
1
  import { checkNetwork } from './network_check';
2
+ import { testCredentials } from './test_utils';
2
3
 
3
4
  // it's too long, enable only when you need to see the report.
4
5
  test.skip('should return network connectivity report for a platform endpoint set in PL_ADDRESS env', async () => {
5
- expect(process.env.PL_ADDRESS).not.toBeUndefined();
6
+ const { plEndpoint, plUser, plPassword } = testCredentials();
6
7
 
7
- const plEndpoint = process.env.PL_ADDRESS!;
8
- const report = await checkNetwork(plEndpoint);
8
+ const report = await checkNetwork(plEndpoint, plUser, plPassword);
9
9
  console.log(report);
10
10
  }, 80000);
@@ -0,0 +1,369 @@
1
+ /** A utility to check network problems and gather statistics.
2
+ * It's useful when we cannot connect to the server of a company
3
+ * because of security reasons,
4
+ * but they can send us and their DevOps team this report.
5
+ *
6
+ * What we check:
7
+ * - pings to backend
8
+ * - block registry for block overview and ui.
9
+ * - autoupdate CDN.
10
+ * - upload workflow to backend (workflow part via our API).
11
+ * - the desktop could do multipart upload.
12
+ * - the desktop could download files from S3.
13
+ * - backend could download software and run it.
14
+ * - backend could run python software.
15
+ * TODO:
16
+ * - try to get something from backend's library storage.
17
+ *
18
+ * We don't check backend access to S3 storage, it is checked on the start of backend.
19
+ */
20
+
21
+ import type { AuthInformation, PlClientConfig } from '@milaboratories/pl-client';
22
+ import { PlClient, UnauthenticatedPlClient, plAddressToConfig } from '@milaboratories/pl-client';
23
+ import type { MiLogger } from '@milaboratories/ts-helpers';
24
+ import { ConsoleLoggerAdapter, HmacSha256Signer } from '@milaboratories/ts-helpers';
25
+ import { channel } from 'node:diagnostics_channel';
26
+ import type { ClientDownload, ClientUpload } from '@milaboratories/pl-drivers';
27
+ import { LsDriver, createDownloadClient, createUploadBlobClient } from '@milaboratories/pl-drivers';
28
+ import type { HttpNetworkReport, NetworkReport } from './pings';
29
+ import { autoUpdateCdnPings, backendPings, blockGARegistryOverviewPings, blockGARegistryUiPings, blockRegistryOverviewPings, blockRegistryUiPings, reportToString } from './pings';
30
+ import type { Dispatcher } from 'undici';
31
+ import type { TemplateReport } from './template';
32
+ import { uploadTemplate, uploadFile, downloadFile, createTempFile, pythonSoftware, softwareCheck, createBigTempFile } from './template';
33
+
34
+ /** All reports we need to collect. */
35
+ interface NetworkReports {
36
+ plPings: NetworkReport<string>[];
37
+
38
+ blockRegistryOverviewChecks: HttpNetworkReport[];
39
+ blockGARegistryOverviewChecks: HttpNetworkReport[];
40
+ blockRegistryUiChecks: HttpNetworkReport[];
41
+ blockGARegistryUiChecks: HttpNetworkReport[];
42
+
43
+ autoUpdateCdnChecks: HttpNetworkReport[];
44
+
45
+ uploadTemplateCheck: TemplateReport;
46
+ uploadFileCheck: TemplateReport;
47
+ downloadFileCheck: TemplateReport;
48
+ softwareCheck: TemplateReport;
49
+ pythonSoftwareCheck: TemplateReport;
50
+ }
51
+
52
+ export interface CheckNetworkOpts {
53
+ /** Platforma Backend pings options. */
54
+ pingCheckDurationMs: number;
55
+ pingTimeoutMs: number;
56
+ maxPingsPerSecond: number;
57
+
58
+ /** An options for CDN and block registry. */
59
+ httpTimeoutMs: number;
60
+
61
+ /** Block registry pings options. */
62
+ blockRegistryDurationMs: number;
63
+ maxRegistryChecksPerSecond: number;
64
+ blockRegistryUrl: string;
65
+ blockGARegistryUrl: string;
66
+ blockOverviewPath: string;
67
+ blockUiPath: string;
68
+
69
+ /** CDN for auto-update pings options. */
70
+ autoUpdateCdnDurationMs: number;
71
+ maxAutoUpdateCdnChecksPerSecond: number;
72
+ autoUpdateCdnUrl: string;
73
+
74
+ bodyLimit: number;
75
+ }
76
+
77
+ /** Checks connectivity to Platforma Backend, to block registry
78
+ * and to auto-update CDN,
79
+ * and generates a string report. */
80
+ export async function checkNetwork(
81
+ plCredentials: string,
82
+ plUser: string | undefined,
83
+ plPassword: string | undefined,
84
+ optsOverrides: Partial<CheckNetworkOpts> = {},
85
+ ): Promise<string> {
86
+ const undiciLogs: any[] = [];
87
+ // Subscribe to all Undici diagnostic events
88
+ undiciEvents.forEach((event) => {
89
+ const diagnosticChannel = channel(event);
90
+ diagnosticChannel.subscribe((message: any) => {
91
+ const timestamp = new Date().toISOString();
92
+ const data = { ...message };
93
+ if (data?.response?.headers) {
94
+ data.response = { ...data.response };
95
+ data.response.headers = data.response.headers.slice();
96
+ data.response.headers = data.response.headers.map((h: any) => h.toString());
97
+ }
98
+
99
+ // we try to upload big files, don't include the buffer in the report.
100
+ if (data?.request?.body) {
101
+ data.request = { ...data.request };
102
+ data.request.body = `too big`;
103
+ }
104
+
105
+ undiciLogs.push(
106
+ JSON.stringify({
107
+ timestamp,
108
+ event,
109
+ data,
110
+ }),
111
+ );
112
+ });
113
+ });
114
+
115
+ const {
116
+ logger,
117
+ plConfig,
118
+ client,
119
+ downloadClient,
120
+ uploadBlobClient,
121
+ lsDriver,
122
+ httpClient,
123
+ ops,
124
+ } = await initNetworkCheck(plCredentials, plUser, plPassword, optsOverrides);
125
+
126
+ const { filePath: filePathToDownload, fileContent: fileContentToDownload } = await createTempFile();
127
+ const { filePath: filePathToUpload } = await createBigTempFile();
128
+
129
+ const report: NetworkReports = {
130
+ plPings: await backendPings(ops, plConfig),
131
+ blockRegistryOverviewChecks: await blockRegistryOverviewPings(ops, httpClient),
132
+ blockGARegistryOverviewChecks: await blockGARegistryOverviewPings(ops, httpClient),
133
+ blockRegistryUiChecks: await blockRegistryUiPings(ops, httpClient),
134
+ blockGARegistryUiChecks: await blockGARegistryUiPings(ops, httpClient),
135
+
136
+ autoUpdateCdnChecks: await autoUpdateCdnPings(ops, httpClient),
137
+
138
+ uploadTemplateCheck: await uploadTemplate(logger, client, 'Jack'),
139
+ uploadFileCheck: await uploadFile(logger, lsDriver, uploadBlobClient, client, filePathToUpload),
140
+ downloadFileCheck: await downloadFile(logger, client, lsDriver, uploadBlobClient, downloadClient, filePathToDownload, fileContentToDownload),
141
+ softwareCheck: await softwareCheck(client),
142
+ pythonSoftwareCheck: await pythonSoftware(client, 'Jack'),
143
+ };
144
+
145
+ return reportsToString(report, plCredentials, ops, undiciLogs);
146
+ }
147
+
148
+ export async function initNetworkCheck(
149
+ plCredentials: string,
150
+ plUser: string | undefined,
151
+ plPassword: string | undefined,
152
+ optsOverrides: Partial<CheckNetworkOpts> = {},
153
+ ): Promise<{
154
+ logger: MiLogger;
155
+ plConfig: PlClientConfig;
156
+ client: PlClient;
157
+ downloadClient: ClientDownload;
158
+ uploadBlobClient: ClientUpload;
159
+ lsDriver: LsDriver;
160
+ httpClient: Dispatcher;
161
+ ops: CheckNetworkOpts;
162
+ terminate: () => Promise<void>;
163
+ }> {
164
+ const ops: CheckNetworkOpts = {
165
+ pingCheckDurationMs: 10000,
166
+ pingTimeoutMs: 3000,
167
+ maxPingsPerSecond: 50,
168
+
169
+ httpTimeoutMs: 3000,
170
+
171
+ blockRegistryDurationMs: 3000,
172
+ maxRegistryChecksPerSecond: 1,
173
+
174
+ blockRegistryUrl: 'https://blocks.pl-open.science',
175
+ blockGARegistryUrl: 'https://blocks-ga.pl-open.science',
176
+ blockOverviewPath: 'v2/overview.json',
177
+ blockUiPath: 'v2/milaboratories/samples-and-data/1.7.0/ui.tgz',
178
+
179
+ autoUpdateCdnDurationMs: 5000,
180
+ maxAutoUpdateCdnChecksPerSecond: 1,
181
+ autoUpdateCdnUrl:
182
+ 'https://cdn.platforma.bio/software/platforma-desktop-v2/windows/amd64/latest.yml',
183
+
184
+ bodyLimit: 300,
185
+
186
+ ...optsOverrides,
187
+ };
188
+
189
+ const plConfig = plAddressToConfig(plCredentials, {
190
+ defaultRequestTimeout: ops.pingTimeoutMs,
191
+ });
192
+
193
+ // exposing alternative root for fields not to interfere with
194
+ // projects of the user.
195
+ plConfig.alternativeRoot = `check_network_${Date.now()}`;
196
+
197
+ const uaClient = new UnauthenticatedPlClient(plConfig);
198
+
199
+ let auth: AuthInformation = {};
200
+ if (plUser && plPassword) {
201
+ auth = await uaClient.login(plUser, plPassword);
202
+ }
203
+
204
+ const client = await PlClient.init(plCredentials, { authInformation: auth });
205
+
206
+ const httpClient = uaClient.ll.httpDispatcher;
207
+ const logger = new ConsoleLoggerAdapter();
208
+
209
+ // FIXME: do we need to get an actual secret?
210
+ const signer = new HmacSha256Signer('localSecret');
211
+
212
+ // We could initialize middle-layer here, but for now it seems like an overkill.
213
+ // Here's the code to do it:
214
+ //
215
+ // const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'platforma-network-check-'));
216
+ // const ml = await MiddleLayer.init(client, tmpDir, {
217
+ // logger,
218
+ // localSecret: '',
219
+ // localProjections: [],
220
+ // openFileDialogCallback: () => Promise.resolve([]),
221
+ // preferredUpdateChannel: 'stable',
222
+ // });
223
+
224
+ const downloadClient = createDownloadClient(logger, client, []);
225
+ const uploadBlobClient = createUploadBlobClient(client, logger);
226
+
227
+ const lsDriver = await LsDriver.init(
228
+ logger,
229
+ client,
230
+ signer,
231
+ [],
232
+ () => Promise.resolve([]),
233
+ [],
234
+ );
235
+
236
+ const terminate = async () => {
237
+ downloadClient.close();
238
+ uploadBlobClient.close();
239
+ await httpClient.close();
240
+ await client.close();
241
+ };
242
+
243
+ return {
244
+ logger,
245
+ plConfig,
246
+ client,
247
+ downloadClient,
248
+ uploadBlobClient,
249
+ lsDriver,
250
+ httpClient,
251
+ ops,
252
+ terminate,
253
+ };
254
+ }
255
+
256
+ function reportsToString(
257
+ report: NetworkReports,
258
+ plEndpoint: string,
259
+ opts: CheckNetworkOpts,
260
+ undiciLogs: any[],
261
+ ): string {
262
+ const successPings = report.plPings.filter((p) => p.response.ok);
263
+ const failedPings = report.plPings.filter((p) => !p.response.ok);
264
+ const successPingsBodies = [
265
+ ...new Set(successPings.map((p) => JSON.stringify((p.response as any).value))),
266
+ ];
267
+
268
+ const pings = reportToString(report.plPings);
269
+ const blockRegistryOverview = reportToString(report.blockRegistryOverviewChecks);
270
+ const blockGARegistryOverview = reportToString(report.blockGARegistryOverviewChecks);
271
+ const blockRegistryUi = reportToString(report.blockRegistryUiChecks);
272
+ const blockGARegistryUi = reportToString(report.blockGARegistryUiChecks);
273
+ const autoUpdateCdn = reportToString(report.autoUpdateCdnChecks);
274
+
275
+ const summary = (ok: boolean) => ok ? 'OK' : 'FAILED';
276
+
277
+ return `
278
+ Network report:
279
+ pl endpoint: ${plEndpoint};
280
+
281
+ summary:
282
+ ${summary(pings.ok)} pings to Platforma Backend
283
+ ${summary(blockRegistryOverview.ok)} block registry overview
284
+ ${summary(blockGARegistryOverview.ok)} block ga registry overview
285
+ ${summary(blockRegistryUi.ok)} block registry ui
286
+ ${summary(blockGARegistryUi.ok)} block ga registry ui
287
+ ${summary(autoUpdateCdn.ok)} auto-update CDN
288
+ ${summary(report.uploadTemplateCheck.ok)} upload template
289
+ ${summary(report.uploadFileCheck.ok)} upload file
290
+ ${summary(report.downloadFileCheck.ok)} download file
291
+ ${summary(report.softwareCheck.ok)} software check
292
+ ${summary(report.pythonSoftwareCheck.ok)} python software check
293
+
294
+ details:
295
+ options: ${JSON.stringify(opts, null, 2)}.
296
+
297
+ Upload template response: ${report.uploadTemplateCheck.message}
298
+
299
+ Upload file response: ${report.uploadFileCheck.message}
300
+
301
+ Download file response: ${report.downloadFileCheck.message}
302
+
303
+ Software check response: ${report.softwareCheck.message}
304
+ Python software check response: ${report.pythonSoftwareCheck.message}
305
+ Platforma pings: ${pings.details}
306
+
307
+ Block registry overview responses: ${blockRegistryOverview.details}
308
+
309
+ Block ga registry overview responses: ${blockGARegistryOverview.details}
310
+
311
+ Block registry ui responses: ${blockRegistryUi.details}
312
+
313
+ Block ga registry ui responses: ${blockGARegistryUi.details}
314
+
315
+ Auto-update CDN responses: ${autoUpdateCdn.details}
316
+
317
+ dumps:
318
+ Block registry overview dumps:
319
+ ${JSON.stringify(report.blockRegistryOverviewChecks, null, 2)}
320
+
321
+ Block ga registry overview dumps:
322
+ ${JSON.stringify(report.blockGARegistryOverviewChecks, null, 2)}
323
+
324
+ Block registry ui dumps:
325
+ ${JSON.stringify(report.blockRegistryUiChecks, null, 2)}
326
+
327
+ Block ga registry ui dumps:
328
+ ${JSON.stringify(report.blockGARegistryUiChecks, null, 2)}
329
+
330
+ Auto-update CDN dumps:
331
+ ${JSON.stringify(report.autoUpdateCdnChecks, null, 2)}
332
+
333
+ Platforma pings error dumps:
334
+ ${JSON.stringify(failedPings, null, 2)}
335
+
336
+ Platforma pings success dump examples:
337
+ ${JSON.stringify(successPingsBodies, null, 2)}
338
+
339
+ Undici logs:
340
+ ${undiciLogs.join('\n')}
341
+ `;
342
+ }
343
+
344
+ // List of Undici diagnostic channels
345
+ const undiciEvents: string[] = [
346
+ 'undici:request:create', // When a new request is created
347
+ 'undici:request:bodySent', // When the request body is sent
348
+ 'undici:request:headers', // When request headers are sent
349
+ 'undici:request:error', // When a request encounters an error
350
+ 'undici:request:trailers', // When a response completes.
351
+
352
+ 'undici:client:sendHeaders',
353
+ 'undici:client:beforeConnect',
354
+ 'undici:client:connected',
355
+ 'undici:client:connectError',
356
+
357
+ 'undici:socket:close', // When a socket is closed
358
+ 'undici:socket:connect', // When a socket connects
359
+ 'undici:socket:error', // When a socket encounters an error
360
+
361
+ 'undici:pool:request', // When a request is added to the pool
362
+ 'undici:pool:connect', // When a pool creates a new connection
363
+ 'undici:pool:disconnect', // When a pool connection is closed
364
+ 'undici:pool:destroy', // When a pool is destroyed
365
+ 'undici:dispatcher:request', // When a dispatcher processes a request
366
+ 'undici:dispatcher:connect', // When a dispatcher connects
367
+ 'undici:dispatcher:disconnect', // When a dispatcher disconnects
368
+ 'undici:dispatcher:retry', // When a dispatcher retries a request
369
+ ];