@privateaim/core-kit 0.8.21 → 0.8.23

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 (52) hide show
  1. package/CHANGELOG.md +43 -0
  2. package/dist/domains/analysis/constants.d.ts +5 -41
  3. package/dist/domains/analysis/constants.d.ts.map +1 -1
  4. package/dist/domains/analysis/entity.d.ts +30 -6
  5. package/dist/domains/analysis/entity.d.ts.map +1 -1
  6. package/dist/domains/analysis/error.d.ts +5 -1
  7. package/dist/domains/analysis/error.d.ts.map +1 -1
  8. package/dist/domains/analysis/helpers/builder.d.ts +16 -0
  9. package/dist/domains/analysis/helpers/builder.d.ts.map +1 -0
  10. package/dist/domains/analysis/helpers/configurator.d.ts +16 -0
  11. package/dist/domains/analysis/helpers/configurator.d.ts.map +1 -0
  12. package/dist/domains/analysis/helpers/distributor.d.ts +16 -0
  13. package/dist/domains/analysis/helpers/distributor.d.ts.map +1 -0
  14. package/dist/domains/analysis/helpers/index.d.ts +4 -0
  15. package/dist/domains/analysis/helpers/index.d.ts.map +1 -0
  16. package/dist/domains/analysis-bucket/entity.d.ts +3 -3
  17. package/dist/domains/analysis-bucket/entity.d.ts.map +1 -1
  18. package/dist/domains/analysis-bucket-file/entity.d.ts +7 -5
  19. package/dist/domains/analysis-bucket-file/entity.d.ts.map +1 -1
  20. package/dist/domains/analysis-node/constants.d.ts +0 -9
  21. package/dist/domains/analysis-node/constants.d.ts.map +1 -1
  22. package/dist/domains/analysis-node/entity.d.ts +4 -2
  23. package/dist/domains/analysis-node/entity.d.ts.map +1 -1
  24. package/dist/domains/analysis-permission/entity.d.ts +2 -2
  25. package/dist/domains/analysis-permission/entity.d.ts.map +1 -1
  26. package/dist/domains/master-image/entity.d.ts +3 -0
  27. package/dist/domains/master-image/entity.d.ts.map +1 -1
  28. package/dist/domains/node/entity.d.ts +5 -1
  29. package/dist/domains/node/entity.d.ts.map +1 -1
  30. package/dist/index.mjs +126 -192
  31. package/dist/index.mjs.map +1 -1
  32. package/package.json +11 -12
  33. package/rollup.config.mjs +1 -6
  34. package/src/domains/analysis/constants.ts +4 -63
  35. package/src/domains/analysis/entity.ts +42 -11
  36. package/src/domains/analysis/error.ts +15 -1
  37. package/src/domains/analysis/helpers/builder.ts +61 -0
  38. package/src/domains/analysis/helpers/configurator.ts +68 -0
  39. package/src/domains/analysis/helpers/distributor.ts +40 -0
  40. package/src/domains/analysis/helpers/index.ts +10 -0
  41. package/src/domains/analysis-bucket/entity.ts +7 -5
  42. package/src/domains/analysis-bucket-file/entity.ts +11 -5
  43. package/src/domains/analysis-node/constants.ts +0 -15
  44. package/src/domains/analysis-node/entity.ts +5 -2
  45. package/src/domains/analysis-permission/entity.ts +2 -2
  46. package/src/domains/master-image/entity.ts +5 -0
  47. package/src/domains/node/entity.ts +6 -1
  48. package/dist/domains/analysis/helpers.d.ts +0 -15
  49. package/dist/domains/analysis/helpers.d.ts.map +0 -1
  50. package/dist/index.cjs +0 -599
  51. package/dist/index.cjs.map +0 -1
  52. package/src/domains/analysis/helpers.ts +0 -163
@@ -5,72 +5,13 @@
5
5
  * view the LICENSE file that was distributed with this source code.
6
6
  */
7
7
 
8
- export enum AnalysisBuildStatus {
9
- STARTING = 'starting', // ui trigger
10
- STARTED = 'started', // tb trigger
11
-
12
- STOPPING = 'stopping', // ui trigger
13
- STOPPED = 'stopped', // tb trigger
14
-
15
- FINISHED = 'finished', // tb trigger
16
- FAILED = 'failed', // tb trigger
17
- }
18
-
19
- // -------------------------------------------------------------------------
20
-
21
- export enum AnalysisConfigurationStatus {
22
- NODES = 'nodes',
23
- MASTER_IMAGE = 'masterImage',
24
- FILES = 'files',
25
- FINISHED = 'finished',
26
- }
27
-
28
- // -------------------------------------------------------------------------
29
-
30
- export enum AnalysisRunStatus {
31
- STARTING = 'starting',
32
- STARTED = 'started',
33
-
34
- RUNNING = 'running',
35
-
36
- STOPPING = 'stopping',
37
- STOPPED = 'stopped',
38
-
39
- FINISHED = 'finished',
40
- FAILED = 'failed',
41
- }
42
-
43
- // -------------------------------------------------------------------------
44
-
45
- export enum AnalysisResultStatus {
46
- STARTED = 'started',
47
-
48
- DOWNLOADING = 'downloading',
49
- DOWNLOADED = 'downloaded',
50
-
51
- PROCESSING = 'extracting',
52
- PROCESSED = 'extracted',
53
-
54
- FINISHED = 'finished',
55
- FAILED = 'failed',
56
- }
57
-
58
- // -------------------------------------------------------------------------
59
-
60
- export enum AnalysisAPICommand {
61
- SPIN_UP = 'spinUp',
62
- TEAR_DOWN = 'tearDown',
63
-
8
+ export enum AnalysisCommand {
64
9
  BUILD_START = 'buildStart',
65
- BUILD_STOP = 'buildStop',
66
- BUILD_STATUS = 'buildStatus',
10
+ BUILD_CHECK = 'buildCheck',
67
11
 
68
12
  CONFIGURATION_LOCK = 'configurationLock',
69
13
  CONFIGURATION_UNLOCK = 'configurationUnlock',
70
- }
71
-
72
- // -------------------------------------------------------------------------
73
14
 
74
- export enum AnalysisContainerPath {
75
- CODE = '/opt/code/',
15
+ DISTRIBUTION_START = 'distributionStart',
16
+ DISTRIBUTION_CHECK = 'distributionCheck',
76
17
  }
@@ -6,12 +6,9 @@
6
6
  */
7
7
 
8
8
  import type { Realm, User } from '@authup/core-kit';
9
+ import type { ProcessStatus } from '@privateaim/kit';
9
10
  import type { MasterImage, MasterImageCommandArgument } from '../master-image';
10
11
  import type { Project } from '../project';
11
- import type {
12
- AnalysisBuildStatus,
13
- AnalysisRunStatus,
14
- } from './constants';
15
12
  import type { Registry } from '../registry';
16
13
 
17
14
  export interface Analysis {
@@ -21,8 +18,18 @@ export interface Analysis {
21
18
 
22
19
  description: string | null;
23
20
 
21
+ // ------------------------------------------------------------------
22
+
23
+ /**
24
+ * Amount of nodes assigned to the analysis.
25
+ */
24
26
  nodes: number;
25
27
 
28
+ /**
29
+ * Amount of nodes which approved the analysis.
30
+ */
31
+ nodes_approved: number;
32
+
26
33
  // ------------------------------------------------------------------
27
34
 
28
35
  configuration_locked: boolean;
@@ -54,23 +61,47 @@ export interface Analysis {
54
61
 
55
62
  // ------------------------------------------------------------------
56
63
 
57
- build_status: AnalysisBuildStatus | null;
64
+ build_status: `${ProcessStatus}` | null;
58
65
 
59
- // ------------------------------------------------------------------
66
+ /**
67
+ * Define if the node constraints are satisfied for the build process.
68
+ */
69
+ build_nodes_valid: boolean;
60
70
 
61
71
  /**
62
- * todo: add distribution_status
72
+ * Percentage for building image
63
73
  */
74
+ build_progress: number | null;
75
+
76
+ /**
77
+ * Hash for build process.
78
+ */
79
+ build_hash: string | null;
80
+
81
+ /**
82
+ * Operating system
83
+ */
84
+ build_os: string | null;
64
85
 
65
- // ------------------------------------------------------------------
66
86
  /**
67
- * todo: rename to execution_status
87
+ * Size in bytes
68
88
  */
69
- run_status: AnalysisRunStatus | null;
89
+ build_size: number | null;
90
+
91
+ // ------------------------------------------------------------------
92
+
93
+ distribution_status: `${ProcessStatus}` | null;
70
94
 
71
95
  /**
72
- * todo: add execution_progress
96
+ * Percentage for distributing image
73
97
  */
98
+ distribution_progress: number | null;
99
+
100
+ // ------------------------------------------------------------------
101
+
102
+ execution_status: `${ProcessStatus}` | null;
103
+
104
+ execution_progress: number | null;
74
105
 
75
106
  // ------------------------------------------------------------------
76
107
 
@@ -5,7 +5,13 @@
5
5
  * view the LICENSE file that was distributed with this source code.
6
6
  */
7
7
 
8
- export class AnalysisError extends Error {
8
+ import { HubError } from '@privateaim/kit';
9
+
10
+ export class AnalysisError extends HubError {
11
+ static notFound() {
12
+ return new AnalysisError('The Analysis could not be found.');
13
+ }
14
+
9
15
  static defaultNodeRequired() {
10
16
  return new AnalysisError('At least one default node must be selected.');
11
17
  }
@@ -14,6 +20,10 @@ export class AnalysisError extends Error {
14
20
  return new AnalysisError('An aggregator node node must be selected.');
15
21
  }
16
22
 
23
+ static nodesApprovalRequired() {
24
+ return new AnalysisError('All assigned nodes have to approve the analysis.');
25
+ }
26
+
17
27
  static entrypointRequired() {
18
28
  return new AnalysisError('An entrypoint must be selected.');
19
29
  }
@@ -26,6 +36,10 @@ export class AnalysisError extends Error {
26
36
  return new AnalysisError('The analysis configuration is locked.');
27
37
  }
28
38
 
39
+ static configurationNotLocked() {
40
+ return new AnalysisError('The analysis configuration is not locked.');
41
+ }
42
+
29
43
  static buildInitialized() {
30
44
  return new AnalysisError('The analysis build process has already been initialized.');
31
45
  }
@@ -0,0 +1,61 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { ProcessStatus } from '@privateaim/kit';
9
+ import type { Analysis } from '../entity';
10
+ import { AnalysisError } from '../error';
11
+
12
+ export class AnalysisBuilderCommandChecker {
13
+ /**
14
+ * Verify if the build start process can be triggered.
15
+ *
16
+ * @param entity
17
+ */
18
+ static canStart(entity: Analysis) {
19
+ if (!entity.configuration_locked) {
20
+ throw AnalysisError.configurationNotLocked();
21
+ }
22
+
23
+ if (!entity.build_nodes_valid) {
24
+ throw AnalysisError.nodesApprovalRequired();
25
+ }
26
+
27
+ if (!entity.build_status) {
28
+ return;
29
+ }
30
+
31
+ if (
32
+ entity.build_status === ProcessStatus.FAILED ||
33
+ entity.build_status === ProcessStatus.STOPPED
34
+ ) {
35
+ return;
36
+ }
37
+
38
+ throw new AnalysisError('The analysis build can not be started.');
39
+ }
40
+
41
+ /**
42
+ * Check if the build check process can be triggered.
43
+ *
44
+ * @param entity
45
+ */
46
+ static canCheck(entity: Analysis) {
47
+ if (!entity.configuration_locked) {
48
+ throw new AnalysisError('The analysis configuration must be locked before checking the build status.');
49
+ }
50
+
51
+ if (!entity.build_status) {
52
+ throw new AnalysisError('The analysis build process has not been initialized.');
53
+ }
54
+
55
+ if (entity.build_status === ProcessStatus.FINISHED) {
56
+ throw new AnalysisError('The analysis build process has already been successfully completed.');
57
+ }
58
+
59
+ // todo: check time
60
+ }
61
+ }
@@ -0,0 +1,68 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { ProcessStatus } from '@privateaim/kit';
9
+ import type { Analysis } from '../entity';
10
+ import { AnalysisError } from '../error';
11
+
12
+ export class AnalysisConfiguratorCommandChecker {
13
+ /**
14
+ * Check if the analysis configuration can be locked.
15
+ *
16
+ * @param entity
17
+ */
18
+ static canLock(entity: Analysis) : void {
19
+ if (entity.configuration_locked) {
20
+ throw AnalysisError.configurationLocked();
21
+ }
22
+
23
+ if (entity.build_status) {
24
+ throw AnalysisError.buildInitialized();
25
+ }
26
+
27
+ if (!entity.configuration_node_default_valid) {
28
+ throw AnalysisError.defaultNodeRequired();
29
+ }
30
+
31
+ if (!entity.configuration_node_aggregator_valid) {
32
+ throw AnalysisError.aggregatorNodeRequired();
33
+ }
34
+
35
+ if (!entity.configuration_entrypoint_valid) {
36
+ throw AnalysisError.entrypointRequired();
37
+ }
38
+
39
+ if (!entity.configuration_image_valid) {
40
+ throw AnalysisError.imageAssignmentRequired();
41
+ }
42
+ }
43
+
44
+ /**
45
+ * Check if the analysis configuration can be unlocked.
46
+ *
47
+ * @param entity
48
+ */
49
+ static canUnlock(entity: Analysis): void {
50
+ if (!entity.configuration_locked) {
51
+ throw new AnalysisError('The analysis configuration is already unlocked.');
52
+ }
53
+
54
+ if (!entity.distribution_status) {
55
+ return;
56
+ }
57
+
58
+ if (
59
+ entity.build_status === ProcessStatus.FAILED ||
60
+ entity.build_status === ProcessStatus.STOPPED ||
61
+ entity.build_status === ProcessStatus.STOPPING
62
+ ) {
63
+ return;
64
+ }
65
+
66
+ throw new AnalysisError('The analysis configuration can not be unlocked.');
67
+ }
68
+ }
@@ -0,0 +1,40 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { ProcessStatus } from '@privateaim/kit';
9
+ import type { Analysis } from '../entity';
10
+ import { AnalysisError } from '../error';
11
+
12
+ export class AnalysisDistributorCommandChecker {
13
+ /**
14
+ * Check if the distribution start process can be triggered.
15
+ *
16
+ * @param entity
17
+ */
18
+ static canStart(entity: Analysis) {
19
+ if (!entity.build_status || entity.build_status !== ProcessStatus.FINISHED) {
20
+ throw new AnalysisError('The analysis is not built yet.');
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Check if the distribution check process can be triggered.
26
+ *
27
+ * @param entity
28
+ */
29
+ static canCheck(entity: Analysis) {
30
+ if (!entity.build_status) {
31
+ throw new AnalysisError('The analysis build process has not been initialized.');
32
+ }
33
+
34
+ if (entity.build_status !== ProcessStatus.FINISHED) {
35
+ throw new AnalysisError('The analysis build process has not been finished.');
36
+ }
37
+
38
+ // todo: check time
39
+ }
40
+ }
@@ -0,0 +1,10 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './builder';
9
+ export * from './configurator';
10
+ export * from './distributor';
@@ -14,13 +14,9 @@ export interface AnalysisBucket {
14
14
 
15
15
  type: `${AnalysisBucketType}`;
16
16
 
17
- external_id: string | null;
18
-
19
17
  // ------------------------------------------------------------------
20
18
 
21
- created_at: Date;
22
-
23
- updated_at: Date;
19
+ bucket_id: string;
24
20
 
25
21
  // ------------------------------------------------------------------
26
22
 
@@ -31,4 +27,10 @@ export interface AnalysisBucket {
31
27
  // ------------------------------------------------------------------
32
28
 
33
29
  realm_id: Realm['id'];
30
+
31
+ // ------------------------------------------------------------------
32
+
33
+ created_at: Date;
34
+
35
+ updated_at: Date;
34
36
  }
@@ -5,14 +5,16 @@
5
5
  * view the LICENSE file that was distributed with this source code.
6
6
  */
7
7
 
8
- import type { Realm, Robot, User } from '@authup/core-kit';
8
+ import type {
9
+ Client, Realm, Robot, User,
10
+ } from '@authup/core-kit';
9
11
  import type { AnalysisBucket } from '../analysis-bucket';
10
12
  import type { Analysis } from '../analysis';
11
13
 
12
14
  export interface AnalysisBucketFile {
13
15
  id: string;
14
16
 
15
- name: string;
17
+ path: string;
16
18
 
17
19
  root: boolean;
18
20
 
@@ -24,13 +26,15 @@ export interface AnalysisBucketFile {
24
26
 
25
27
  // ------------------------------------------------------------------
26
28
 
27
- external_id: string;
29
+ bucket_id: string;
30
+
31
+ bucket_file_id: string;
28
32
 
29
33
  // ------------------------------------------------------------------
30
34
 
31
- bucket_id: AnalysisBucket['id'];
35
+ analysis_bucket_id: AnalysisBucket['id'];
32
36
 
33
- bucket: AnalysisBucket;
37
+ analysis_bucket: AnalysisBucket;
34
38
 
35
39
  // ------------------------------------------------------------------
36
40
 
@@ -42,6 +46,8 @@ export interface AnalysisBucketFile {
42
46
 
43
47
  realm_id: Realm['id'];
44
48
 
49
+ client_id: Client['id'] | null;
50
+
45
51
  user_id: User['id'] | null;
46
52
 
47
53
  robot_id: Robot['id'] | null;
@@ -14,18 +14,3 @@ export enum AnalysisNodeApprovalStatus {
14
14
  REJECTED = 'rejected',
15
15
  APPROVED = 'approved',
16
16
  }
17
-
18
- // -------------------------------------------------------------------------
19
-
20
- export enum AnalysisNodeRunStatus {
21
- STARTING = 'starting',
22
- STARTED = 'started',
23
-
24
- STOPPING = 'stopping',
25
- STOPPED = 'stopped',
26
-
27
- RUNNING = 'running',
28
- FINISHED = 'finished',
29
-
30
- FAILED = 'failed',
31
- }
@@ -6,9 +6,10 @@
6
6
  */
7
7
 
8
8
  import type { Realm } from '@authup/core-kit';
9
+ import type { ProcessStatus } from '@privateaim/kit';
9
10
  import type { Node } from '../node';
10
11
  import type { Analysis } from '../analysis';
11
- import type { AnalysisNodeApprovalStatus, AnalysisNodeRunStatus } from './constants';
12
+ import type { AnalysisNodeApprovalStatus } from './constants';
12
13
 
13
14
  export interface AnalysisNode {
14
15
  id: string;
@@ -19,7 +20,9 @@ export interface AnalysisNode {
19
20
 
20
21
  // ------------------------------------------------------------------
21
22
 
22
- run_status: AnalysisNodeRunStatus | null;
23
+ execution_status: ProcessStatus | null;
24
+
25
+ execution_progress: number | null;
23
26
 
24
27
  // ------------------------------------------------------------------
25
28
 
@@ -25,7 +25,7 @@ export interface AnalysisPermission extends PermissionRelation {
25
25
 
26
26
  // ------------------------------------------------------------------
27
27
 
28
- created_at: Date | string;
28
+ created_at: string;
29
29
 
30
- updated_at: Date | string;
30
+ updated_at: string;
31
31
  }
@@ -5,11 +5,16 @@
5
5
  * view the LICENSE file that was distributed with this source code.
6
6
  */
7
7
 
8
+ import type { ProcessStatus } from '@privateaim/kit';
8
9
  import type { MasterImageCommandArgument } from './types';
9
10
 
10
11
  export interface MasterImage {
11
12
  id: string;
12
13
 
14
+ build_status: `${ProcessStatus}` | null;
15
+
16
+ build_progress: number | null;
17
+
13
18
  path: string | null;
14
19
 
15
20
  virtual_path: string;
@@ -5,7 +5,7 @@
5
5
  * view the LICENSE file that was distributed with this source code.
6
6
  */
7
7
 
8
- import type { Realm, Robot } from '@authup/core-kit';
8
+ import type { Client, Realm, Robot } from '@authup/core-kit';
9
9
  import type { RegistryProject } from '../registry-project';
10
10
  import type { Registry } from '../registry';
11
11
  import type { NodeType } from './constants';
@@ -37,6 +37,11 @@ export interface Node {
37
37
 
38
38
  // ------------------------------------------------------------------
39
39
 
40
+ client_id: Client['id'] | null;
41
+
42
+ /**
43
+ * @deprecated
44
+ */
40
45
  robot_id: Robot['id'] | null;
41
46
 
42
47
  // ------------------------------------------------------------------
@@ -1,15 +0,0 @@
1
- import { AnalysisAPICommand } from './constants';
2
- import type { Analysis } from './entity';
3
- type CanResult = {
4
- success: boolean;
5
- message: string;
6
- };
7
- /**
8
- * Check if an analysis can be build based on analysis attributes (build_status, configuration_locked, ...)
9
- *
10
- * @param entity
11
- * @param command
12
- */
13
- export declare function isAnalysisAPICommandExecutable(entity: Analysis, command: `${AnalysisAPICommand}`): CanResult;
14
- export {};
15
- //# sourceMappingURL=helpers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/domains/analysis/helpers.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,kBAAkB,EAAuB,MAAM,aAAa,CAAC;AACtE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAGzC,KAAK,SAAS,GAAG;IACb,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC1C,MAAM,EAAE,QAAQ,EAChB,OAAO,EAAE,GAAG,kBAAkB,EAAE,GAChC,SAAS,CAyIZ"}