@kapeta/local-cluster-service 0.20.4 → 0.21.0

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 (54) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/cjs/src/assetManager.js +5 -6
  3. package/dist/cjs/src/clusterService.js +2 -2
  4. package/dist/cjs/src/codeGeneratorManager.js +2 -2
  5. package/dist/cjs/src/config/routes.js +13 -2
  6. package/dist/cjs/src/configManager.js +10 -10
  7. package/dist/cjs/src/definitionsManager.js +2 -3
  8. package/dist/cjs/src/instanceManager.js +18 -15
  9. package/dist/cjs/src/middleware/kapeta.js +3 -3
  10. package/dist/cjs/src/networkManager.js +6 -6
  11. package/dist/cjs/src/operatorManager.js +3 -3
  12. package/dist/cjs/src/repositoryManager.js +2 -2
  13. package/dist/cjs/src/serviceManager.d.ts +1 -0
  14. package/dist/cjs/src/serviceManager.js +9 -9
  15. package/dist/cjs/src/socketManager.js +3 -3
  16. package/dist/cjs/src/utils/BlockInstanceRunner.js +32 -14
  17. package/dist/cjs/src/utils/utils.d.ts +0 -1
  18. package/dist/cjs/src/utils/utils.js +1 -13
  19. package/dist/cjs/test/proxy/types/rest.test.js +16 -17
  20. package/dist/esm/src/assetManager.js +5 -6
  21. package/dist/esm/src/clusterService.js +2 -2
  22. package/dist/esm/src/codeGeneratorManager.js +2 -2
  23. package/dist/esm/src/config/routes.js +13 -2
  24. package/dist/esm/src/configManager.js +10 -10
  25. package/dist/esm/src/definitionsManager.js +2 -3
  26. package/dist/esm/src/instanceManager.js +18 -15
  27. package/dist/esm/src/middleware/kapeta.js +3 -3
  28. package/dist/esm/src/networkManager.js +6 -6
  29. package/dist/esm/src/operatorManager.js +3 -3
  30. package/dist/esm/src/repositoryManager.js +2 -2
  31. package/dist/esm/src/serviceManager.d.ts +1 -0
  32. package/dist/esm/src/serviceManager.js +9 -9
  33. package/dist/esm/src/socketManager.js +3 -3
  34. package/dist/esm/src/utils/BlockInstanceRunner.js +32 -14
  35. package/dist/esm/src/utils/utils.d.ts +0 -1
  36. package/dist/esm/src/utils/utils.js +1 -13
  37. package/dist/esm/test/proxy/types/rest.test.js +16 -17
  38. package/package.json +1 -1
  39. package/src/assetManager.ts +1 -2
  40. package/src/clusterService.ts +1 -1
  41. package/src/codeGeneratorManager.ts +1 -1
  42. package/src/config/routes.ts +17 -6
  43. package/src/configManager.ts +2 -2
  44. package/src/definitionsManager.ts +1 -2
  45. package/src/instanceManager.ts +8 -3
  46. package/src/middleware/kapeta.ts +1 -2
  47. package/src/networkManager.ts +1 -1
  48. package/src/operatorManager.ts +3 -3
  49. package/src/repositoryManager.ts +1 -1
  50. package/src/serviceManager.ts +2 -2
  51. package/src/socketManager.ts +1 -1
  52. package/src/utils/BlockInstanceRunner.ts +65 -30
  53. package/src/utils/utils.ts +0 -13
  54. package/test/proxy/types/rest.test.ts +22 -22
@@ -34,12 +34,19 @@ async function getProvider(uri) {
34
34
  return (0, nodejs_utils_1.parseKapetaUri)(ref).id === uri.id;
35
35
  });
36
36
  }
37
- function getProviderPorts(assetVersion) {
38
- return (assetVersion.definition?.spec?.providers
37
+ function getProviderPorts(assetVersion, providerVersion) {
38
+ const out = assetVersion.definition?.spec?.providers
39
39
  ?.map((provider) => {
40
40
  return provider.spec?.port?.type;
41
41
  })
42
- .filter((t) => !!t) ?? []);
42
+ .filter((t) => !!t) ?? [];
43
+ if (out.length === 0) {
44
+ if (providerVersion.definition.spec?.defaultPort?.type) {
45
+ return [providerVersion.definition.spec?.defaultPort?.type];
46
+ }
47
+ return [serviceManager_1.DEFAULT_PORT_TYPE];
48
+ }
49
+ return out;
43
50
  }
44
51
  class BlockInstanceRunner {
45
52
  _systemId;
@@ -49,7 +56,7 @@ class BlockInstanceRunner {
49
56
  * @type {string}
50
57
  * @private
51
58
  */
52
- this._systemId = (0, utils_1.normalizeKapetaUri)(systemId);
59
+ this._systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
53
60
  }
54
61
  /**
55
62
  * Start a block
@@ -92,7 +99,7 @@ class BlockInstanceRunner {
92
99
  }
93
100
  else {
94
101
  //We need a port type to know how to connect to the block consistently
95
- const portTypes = getProviderPorts(assetVersion);
102
+ const portTypes = getProviderPorts(assetVersion, providerVersion);
96
103
  if (blockUri.version === 'local') {
97
104
  processInfo = await this._startLocalProcess(blockInstance, blockUri, env, assetVersion);
98
105
  }
@@ -117,14 +124,19 @@ class BlockInstanceRunner {
117
124
  if (!assetVersion.definition.spec?.target?.kind) {
118
125
  throw new Error('Missing target kind in block definition');
119
126
  }
120
- const kindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.spec?.target?.kind);
121
- const targetVersion = await getProvider(kindUri);
127
+ const kindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.kind);
128
+ const providerVersion = await getProvider(kindUri);
129
+ if (!providerVersion) {
130
+ throw new Error(`Block type not found: ${kindUri.id}`);
131
+ }
132
+ const targetKindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.spec?.target?.kind);
133
+ const targetVersion = await getProvider(targetKindUri);
122
134
  if (!targetVersion) {
123
- throw new Error(`Target not found: ${kindUri.id}`);
135
+ throw new Error(`Target not found: ${targetKindUri.id}`);
124
136
  }
125
137
  const localContainer = targetVersion.definition.spec.local;
126
138
  if (!localContainer) {
127
- throw new Error(`Missing local container information from target: ${kindUri.id}`);
139
+ throw new Error(`Missing local container information from target: ${targetKindUri.id}`);
128
140
  }
129
141
  const dockerImage = localContainer.image;
130
142
  if (!dockerImage) {
@@ -141,7 +153,7 @@ class BlockInstanceRunner {
141
153
  delete localContainer.HostConfig;
142
154
  delete localContainer.Labels;
143
155
  delete localContainer.Env;
144
- const { PortBindings, ExposedPorts, addonEnv } = await this.getDockerPortBindings(blockInstance, assetVersion);
156
+ const { PortBindings, ExposedPorts, addonEnv } = await this.getDockerPortBindings(blockInstance, assetVersion, providerVersion);
145
157
  let HealthCheck = undefined;
146
158
  if (localContainer.healthcheck) {
147
159
  HealthCheck = containerManager_1.containerManager.toDockerHealth({ cmd: localContainer.healthcheck });
@@ -194,7 +206,12 @@ class BlockInstanceRunner {
194
206
  if (!dockerImage) {
195
207
  throw new Error(`Missing docker image information: ${JSON.stringify(versionInfo?.artifact?.details)}`);
196
208
  }
197
- const { PortBindings, ExposedPorts, addonEnv } = await this.getDockerPortBindings(blockInstance, assetVersion);
209
+ const kindUri = (0, nodejs_utils_1.parseKapetaUri)(assetVersion.definition.kind);
210
+ const providerVersion = await getProvider(kindUri);
211
+ if (!providerVersion) {
212
+ throw new Error(`Block type not found: ${kindUri.id}`);
213
+ }
214
+ const { PortBindings, ExposedPorts, addonEnv } = await this.getDockerPortBindings(blockInstance, assetVersion, providerVersion);
198
215
  const containerName = (0, utils_1.getBlockInstanceContainerName)(this._systemId, blockInstance.id);
199
216
  // For windows we need to default to root
200
217
  const innerHome = process.platform === 'win32' ? '/root/.kapeta' : local_cluster_config_1.default.getKapetaBasedir();
@@ -252,7 +269,8 @@ class BlockInstanceRunner {
252
269
  const PortBindings = {};
253
270
  let HealthCheck = undefined;
254
271
  let Mounts = [];
255
- const promises = Object.entries(spec.local.ports).map(async ([portType, value]) => {
272
+ const localPorts = spec.local.ports;
273
+ const promises = Object.entries(localPorts).map(async ([portType, value]) => {
256
274
  const dockerPort = `${value.port}/${value.type}`;
257
275
  ExposedPorts[dockerPort] = {};
258
276
  addonEnv[`KAPETA_LOCAL_SERVER_PORT_${portType.toUpperCase()}`] = value.port;
@@ -315,12 +333,12 @@ class BlockInstanceRunner {
315
333
  }
316
334
  return out;
317
335
  }
318
- async getDockerPortBindings(blockInstance, assetVersion) {
336
+ async getDockerPortBindings(blockInstance, assetVersion, providerVersion) {
319
337
  const bindHost = (0, utils_1.getBindHost)();
320
338
  const ExposedPorts = {};
321
339
  const addonEnv = {};
322
340
  const PortBindings = {};
323
- const portTypes = getProviderPorts(assetVersion);
341
+ const portTypes = getProviderPorts(assetVersion, providerVersion);
324
342
  let port = 80;
325
343
  const promises = portTypes.map(async (portType) => {
326
344
  const publicPort = await serviceManager_1.serviceManager.ensureServicePort(this._systemId, blockInstance.id, portType);
@@ -1,7 +1,6 @@
1
1
  import { EntityList } from '@kapeta/schemas';
2
2
  import { AnyMap } from '../types';
3
3
  export declare function getBlockInstanceContainerName(systemId: string, instanceId: string): string;
4
- export declare function normalizeKapetaUri(uri: string): string;
5
4
  export declare function readYML(path: string): any;
6
5
  export declare function isWindows(): boolean;
7
6
  export declare function isMac(): boolean;
@@ -3,27 +3,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getResolvedConfiguration = exports.getBindHost = exports.isLinux = exports.isMac = exports.isWindows = exports.readYML = exports.normalizeKapetaUri = exports.getBlockInstanceContainerName = void 0;
6
+ exports.getResolvedConfiguration = exports.getBindHost = exports.isLinux = exports.isMac = exports.isWindows = exports.readYML = exports.getBlockInstanceContainerName = void 0;
7
7
  const node_fs_1 = __importDefault(require("node:fs"));
8
8
  const yaml_1 = __importDefault(require("yaml"));
9
- const nodejs_utils_1 = require("@kapeta/nodejs-utils");
10
9
  const md5_1 = __importDefault(require("md5"));
11
10
  const lodash_1 = __importDefault(require("lodash"));
12
11
  function getBlockInstanceContainerName(systemId, instanceId) {
13
12
  return `kapeta-block-instance-${(0, md5_1.default)(systemId + instanceId)}`;
14
13
  }
15
14
  exports.getBlockInstanceContainerName = getBlockInstanceContainerName;
16
- function normalizeKapetaUri(uri) {
17
- if (!uri) {
18
- return '';
19
- }
20
- const uriObj = (0, nodejs_utils_1.parseKapetaUri)(uri);
21
- if (!uriObj.version) {
22
- return `kapeta://${(0, nodejs_utils_1.parseKapetaUri)(uri).fullName}`;
23
- }
24
- return `kapeta://${(0, nodejs_utils_1.parseKapetaUri)(uri).id}`;
25
- }
26
- exports.normalizeKapetaUri = normalizeKapetaUri;
27
15
  function readYML(path) {
28
16
  const rawYaml = node_fs_1.default.readFileSync(path);
29
17
  try {
@@ -4,42 +4,41 @@ const rest_1 = require("../../../src/proxy/types/rest");
4
4
  describe('getRestMethodId', () => {
5
5
  it('should match @Query in url', () => {
6
6
  const restResource = new TestResource();
7
- const restMethodId = (0, rest_1.getRestMethodId)(restResource, "POST", "/names?name=Ib");
7
+ const restMethodId = (0, rest_1.getRestMethodId)(restResource, 'POST', '/names?name=Ib');
8
8
  expect(restMethodId).toBeDefined();
9
9
  });
10
10
  });
11
11
  class TestResource {
12
- kind = "";
12
+ kind = '';
13
13
  metadata = new TestResourceMetaData();
14
14
  get spec() {
15
15
  return {
16
16
  methods: [
17
17
  {
18
18
  responseType: {
19
- ref: "Name[]"
19
+ ref: 'Name[]',
20
20
  },
21
- method: "GET",
22
- path: "/names",
23
- arguments: {}
21
+ method: 'GET',
22
+ path: '/names',
23
+ arguments: {},
24
24
  },
25
25
  {
26
26
  responseType: {
27
- ref: "Name"
27
+ ref: 'Name',
28
28
  },
29
- method: "POST",
30
- path: "/names",
29
+ method: 'POST',
30
+ path: '/names',
31
31
  arguments: {
32
32
  name: {
33
- type: "string",
34
- transport: "QUERY"
35
- }
36
- }
37
- }
38
- ]
33
+ type: 'string',
34
+ transport: 'QUERY',
35
+ },
36
+ },
37
+ },
38
+ ],
39
39
  };
40
40
  }
41
- ;
42
41
  }
43
42
  class TestResourceMetaData {
44
- name = "";
43
+ name = '';
45
44
  }
@@ -13,7 +13,6 @@ const nodejs_utils_1 = require("@kapeta/nodejs-utils");
13
13
  const repositoryManager_1 = require("./repositoryManager");
14
14
  const nodejs_registry_utils_1 = require("@kapeta/nodejs-registry-utils");
15
15
  const definitionsManager_1 = require("./definitionsManager");
16
- const utils_1 = require("./utils/utils");
17
16
  const taskManager_1 = require("./taskManager");
18
17
  const cacheManager_1 = require("./cacheManager");
19
18
  const node_uuid_1 = __importDefault(require("node-uuid"));
@@ -85,7 +84,7 @@ class AssetManager {
85
84
  return instance;
86
85
  }
87
86
  async getAsset(ref, noCache = false, autoFetch = true) {
88
- ref = (0, utils_1.normalizeKapetaUri)(ref);
87
+ ref = (0, nodejs_utils_1.normalizeKapetaUri)(ref);
89
88
  const cacheKey = toKey(ref);
90
89
  if (!noCache && cacheManager_1.cacheManager.has(cacheKey)) {
91
90
  return cacheManager_1.cacheManager.get(cacheKey);
@@ -117,7 +116,7 @@ class AssetManager {
117
116
  await fs_extra_1.default.writeFile(path, yaml_1.default.stringify(yaml));
118
117
  const asset = await this.importFile(path);
119
118
  asset.forEach((a) => {
120
- const ref = (0, utils_1.normalizeKapetaUri)(a.ref);
119
+ const ref = (0, nodejs_utils_1.normalizeKapetaUri)(a.ref);
121
120
  const key = toKey(ref);
122
121
  cacheManager_1.cacheManager.set(key, a, CACHE_TTL);
123
122
  });
@@ -128,7 +127,7 @@ class AssetManager {
128
127
  return asset;
129
128
  }
130
129
  async updateAsset(ref, yaml, sourceOfChange = 'filesystem') {
131
- ref = (0, utils_1.normalizeKapetaUri)(ref);
130
+ ref = (0, nodejs_utils_1.normalizeKapetaUri)(ref);
132
131
  const asset = await this.getAsset(ref, true, false);
133
132
  if (!asset) {
134
133
  throw new Error('Attempted to update unknown asset: ' + ref);
@@ -157,7 +156,7 @@ class AssetManager {
157
156
  const assetInfos = yaml_1.default.parseAllDocuments(content.toString()).map((doc) => doc.toJSON());
158
157
  await nodejs_registry_utils_1.Actions.link(new progressListener_1.ProgressListener(), node_path_1.default.dirname(filePath));
159
158
  const version = 'local';
160
- const refs = assetInfos.map((assetInfo) => (0, utils_1.normalizeKapetaUri)(`kapeta://${assetInfo.metadata.name}:${version}`));
159
+ const refs = assetInfos.map((assetInfo) => (0, nodejs_utils_1.normalizeKapetaUri)(`kapeta://${assetInfo.metadata.name}:${version}`));
161
160
  refs.forEach((ref) => {
162
161
  const key = toKey(ref);
163
162
  cacheManager_1.cacheManager.remove(key);
@@ -189,7 +188,7 @@ class AssetManager {
189
188
  return await repositoryManager_1.repositoryManager.ensureAsset(uri.handle, uri.name, uri.version, false);
190
189
  }
191
190
  async maybeGenerateCode(ref, ymlPath, block) {
192
- ref = (0, utils_1.normalizeKapetaUri)(ref);
191
+ ref = (0, nodejs_utils_1.normalizeKapetaUri)(ref);
193
192
  if (await codeGeneratorManager_1.codeGeneratorManager.canGenerateCode(block)) {
194
193
  const assetTitle = block.metadata.title ? block.metadata.title : (0, nodejs_utils_1.parseKapetaUri)(block.metadata.name).name;
195
194
  const taskId = `codegen:${node_uuid_1.default.v4()}`;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.clusterService = void 0;
4
- const utils_1 = require("./utils/utils");
4
+ const nodejs_utils_1 = require("@kapeta/nodejs-utils");
5
5
  const net = require('net');
6
6
  const DEFAULT_SERVER_PORT = 35100;
7
7
  const DEFAULT_START_PORT = 40000;
@@ -109,7 +109,7 @@ class ClusterService {
109
109
  * @return {string}
110
110
  */
111
111
  getProxyPath(systemId, consumerInstanceId, consumerResourceName, portType) {
112
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
112
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
113
113
  return `/proxy/${encodeURIComponent(systemId)}/${encodeURIComponent(consumerInstanceId)}/${encodeURIComponent(consumerResourceName)}/${encodeURIComponent(portType)}/`;
114
114
  }
115
115
  }
@@ -8,7 +8,7 @@ const path_1 = __importDefault(require("path"));
8
8
  const codegen_1 = require("@kapeta/codegen");
9
9
  const definitionsManager_1 = require("./definitionsManager");
10
10
  const assetManager_1 = require("./assetManager");
11
- const utils_1 = require("./utils/utils");
11
+ const nodejs_utils_1 = require("@kapeta/nodejs-utils");
12
12
  const repositoryManager_1 = require("./repositoryManager");
13
13
  const TARGET_KIND = 'core/language-target';
14
14
  const BLOCK_TYPE_KIND = 'core/block-type';
@@ -67,7 +67,7 @@ class CodeGeneratorManager {
67
67
  //Not all block types have targets
68
68
  return;
69
69
  }
70
- const targetRef = (0, utils_1.normalizeKapetaUri)(yamlContent.spec.target?.kind);
70
+ const targetRef = (0, nodejs_utils_1.normalizeKapetaUri)(yamlContent.spec.target?.kind);
71
71
  // Automatically downloads target if not available
72
72
  const targetAsset = await assetManager_1.assetManager.getAsset(targetRef);
73
73
  if (!targetAsset) {
@@ -111,8 +111,19 @@ router.get('/identity', async (req, res) => {
111
111
  * already called the endpoint the same port is returned.
112
112
  */
113
113
  router.get('/provides/:type', async (req, res) => {
114
- //Get service port
115
- res.send('' + (await serviceManager_1.serviceManager.ensureServicePort(req.kapeta.systemId, req.kapeta.instanceId, req.params.type)));
114
+ if (req.kapeta.environment === 'docker' && ['web', 'rest'].includes(req.params.type)) {
115
+ // Happens when starting a local container with no providers.
116
+ res.send('80');
117
+ return;
118
+ }
119
+ try {
120
+ const port = await serviceManager_1.serviceManager.ensureServicePort(req.kapeta.systemId, req.kapeta.instanceId, req.params.type);
121
+ res.send('' + port);
122
+ }
123
+ catch (err) {
124
+ console.warn('Failed to resolve service port: ' + req.params.type, err);
125
+ res.status(400).send({ error: err.message });
126
+ }
116
127
  });
117
128
  /**
118
129
  * Used by services to get info for consumed operator resource.
@@ -12,19 +12,19 @@ class ConfigManager {
12
12
  this._config = storageService_1.storageService.section('config');
13
13
  }
14
14
  _forSystem(systemId) {
15
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
15
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
16
16
  if (!this._config[systemId]) {
17
17
  this._config[systemId] = {};
18
18
  }
19
19
  return this._config[systemId];
20
20
  }
21
21
  setConfigForSystem(systemId, config) {
22
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
22
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
23
23
  const systemConfig = config || {};
24
24
  storageService_1.storageService.put('config', systemId, systemConfig);
25
25
  }
26
26
  getConfigForSystem(systemId) {
27
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
27
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
28
28
  return this._forSystem(systemId);
29
29
  }
30
30
  async getConfigForBlockInstance(systemId, instanceId) {
@@ -37,13 +37,13 @@ class ConfigManager {
37
37
  return (0, utils_1.getResolvedConfiguration)(blockAsset.data.spec.configuration, instanceConfig, blockInstance.defaultConfiguration);
38
38
  }
39
39
  setConfigForSection(systemId, sectionId, config) {
40
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
40
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
41
41
  let systemConfig = this._forSystem(systemId);
42
42
  systemConfig[sectionId] = config || {};
43
43
  storageService_1.storageService.put('config', systemId, systemConfig);
44
44
  }
45
45
  getConfigForSection(systemId, sectionId) {
46
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
46
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
47
47
  const systemConfig = this._forSystem(systemId);
48
48
  if (!systemConfig[sectionId]) {
49
49
  systemConfig[sectionId] = {};
@@ -67,9 +67,9 @@ class ConfigManager {
67
67
  * @returns {Promise<{systemId:string,instanceId:string}>}
68
68
  */
69
69
  async resolveIdentity(blockRef, systemId) {
70
- blockRef = (0, utils_1.normalizeKapetaUri)(blockRef);
70
+ blockRef = (0, nodejs_utils_1.normalizeKapetaUri)(blockRef);
71
71
  if (systemId) {
72
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
72
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
73
73
  }
74
74
  const planAssets = await assetManager_1.assetManager.getPlans();
75
75
  const blockUri = (0, nodejs_utils_1.parseKapetaUri)(blockRef);
@@ -86,7 +86,7 @@ class ConfigManager {
86
86
  const refUri = (0, nodejs_utils_1.parseKapetaUri)(blockInstance.block.ref);
87
87
  if (refUri.equals(blockUri)) {
88
88
  matchingIdentities.push({
89
- systemId: (0, utils_1.normalizeKapetaUri)(planAsset.ref),
89
+ systemId: (0, nodejs_utils_1.normalizeKapetaUri)(planAsset.ref),
90
90
  instanceId: blockInstance.id,
91
91
  });
92
92
  }
@@ -107,8 +107,8 @@ class ConfigManager {
107
107
  return matchingIdentities[0];
108
108
  }
109
109
  async verifyIdentity(blockRef, systemId, instanceId) {
110
- blockRef = (0, utils_1.normalizeKapetaUri)(blockRef);
111
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
110
+ blockRef = (0, nodejs_utils_1.normalizeKapetaUri)(blockRef);
111
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
112
112
  const planAssets = await assetManager_1.assetManager.getPlans();
113
113
  const systemUri = systemId ? (0, nodejs_utils_1.parseKapetaUri)(systemId) : null;
114
114
  const blockUri = (0, nodejs_utils_1.parseKapetaUri)(blockRef);
@@ -9,7 +9,6 @@ const nodejs_utils_1 = require("@kapeta/nodejs-utils");
9
9
  const cacheManager_1 = require("./cacheManager");
10
10
  const nodejs_api_client_1 = require("@kapeta/nodejs-api-client");
11
11
  const fs_extra_1 = __importDefault(require("fs-extra"));
12
- const utils_1 = require("./utils/utils");
13
12
  const yaml_1 = __importDefault(require("yaml"));
14
13
  const nodejs_registry_utils_1 = require("@kapeta/nodejs-registry-utils");
15
14
  const progressListener_1 = require("./progressListener");
@@ -66,12 +65,12 @@ class DefinitionsManager {
66
65
  const blockUri = (0, nodejs_utils_1.parseKapetaUri)(b.block.ref);
67
66
  if (blockUri.version === 'local') {
68
67
  blockRefs.add(blockUri.id);
69
- b.block.ref = (0, utils_1.normalizeKapetaUri)(`${profile.handle}/${blockUri.name}:local`);
68
+ b.block.ref = (0, nodejs_utils_1.normalizeKapetaUri)(`${profile.handle}/${blockUri.name}:local`);
70
69
  }
71
70
  });
72
71
  // Rewrite all blocks that are referenced by the sample plan
73
72
  const rewrittenBlocks = Array.from(blockRefs)
74
- .map((ref) => definitions.find((d) => (0, utils_1.normalizeKapetaUri)(d.definition.metadata.name + ':' + d.version) === (0, utils_1.normalizeKapetaUri)(ref)))
73
+ .map((ref) => definitions.find((d) => (0, nodejs_utils_1.normalizeKapetaUri)(d.definition.metadata.name + ':' + d.version) === (0, nodejs_utils_1.normalizeKapetaUri)(ref)))
75
74
  .filter((d) => d !== undefined)
76
75
  .map((d) => applyHandleChange(d, profile.handle));
77
76
  // Persist the rewritten assets
@@ -51,7 +51,7 @@ class InstanceManager {
51
51
  if (!this._instances) {
52
52
  return [];
53
53
  }
54
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
54
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
55
55
  const planInfo = await definitionsManager_1.definitionsManager.getDefinition(systemId);
56
56
  if (!planInfo) {
57
57
  return [];
@@ -64,11 +64,11 @@ class InstanceManager {
64
64
  return this._instances.filter((instance) => instance.systemId === systemId && instanceIds.includes(instance.instanceId));
65
65
  }
66
66
  getInstance(systemId, instanceId) {
67
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
67
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
68
68
  return this._instances.find((i) => i.systemId === systemId && i.instanceId === instanceId);
69
69
  }
70
70
  async exclusive(systemId, instanceId, fn) {
71
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
71
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
72
72
  const key = `${systemId}/${instanceId}`;
73
73
  //console.log(`Acquiring lock for ${key}`, this.instanceLocks.isBusy(key));
74
74
  const result = await this.instanceLocks.acquire(key, fn);
@@ -105,9 +105,9 @@ class InstanceManager {
105
105
  return [];
106
106
  }
107
107
  async saveInternalInstance(instance) {
108
- instance.systemId = (0, utils_1.normalizeKapetaUri)(instance.systemId);
108
+ instance.systemId = (0, nodejs_utils_1.normalizeKapetaUri)(instance.systemId);
109
109
  if (instance.ref) {
110
- instance.ref = (0, utils_1.normalizeKapetaUri)(instance.ref);
110
+ instance.ref = (0, nodejs_utils_1.normalizeKapetaUri)(instance.ref);
111
111
  }
112
112
  //Get target address
113
113
  let address = await serviceManager_1.serviceManager.getProviderAddress(instance.systemId, instance.instanceId, instance.portType ?? DEFAULT_HEALTH_PORT_TYPE);
@@ -135,7 +135,7 @@ class InstanceManager {
135
135
  */
136
136
  async registerInstanceFromSDK(systemId, instanceId, info) {
137
137
  return this.exclusive(systemId, instanceId, async () => {
138
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
138
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
139
139
  let instance = this.getInstance(systemId, instanceId);
140
140
  //Get target address
141
141
  const address = await serviceManager_1.serviceManager.getProviderAddress(systemId, instanceId, info.portType ?? DEFAULT_HEALTH_PORT_TYPE);
@@ -167,6 +167,9 @@ class InstanceManager {
167
167
  if (healthUrl) {
168
168
  instance.health = healthUrl;
169
169
  }
170
+ if (info.portType) {
171
+ instance.portType = info.portType;
172
+ }
170
173
  socketManager_1.socketManager.emitSystemEvent(systemId, socketManager_1.EVENT_STATUS_CHANGED, instance);
171
174
  }
172
175
  else {
@@ -202,7 +205,7 @@ class InstanceManager {
202
205
  }
203
206
  markAsStopped(systemId, instanceId) {
204
207
  return this.exclusive(systemId, instanceId, async () => {
205
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
208
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
206
209
  const instance = lodash_1.default.find(this._instances, { systemId, instanceId });
207
210
  if (instance && instance.owner === types_1.InstanceOwner.EXTERNAL && instance.status !== types_1.InstanceStatus.STOPPED) {
208
211
  instance.status = types_1.InstanceStatus.STOPPED;
@@ -214,7 +217,7 @@ class InstanceManager {
214
217
  });
215
218
  }
216
219
  async startAllForPlan(systemId) {
217
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
220
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
218
221
  const plan = await assetManager_1.assetManager.getPlan(systemId, true);
219
222
  if (!plan) {
220
223
  throw new Error(`Plan not found: ${systemId}`);
@@ -254,7 +257,7 @@ class InstanceManager {
254
257
  }
255
258
  async stopInner(systemId, instanceId, changeDesired = false) {
256
259
  return this.exclusive(systemId, instanceId, async () => {
257
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
260
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
258
261
  const instance = this.getInstance(systemId, instanceId);
259
262
  if (!instance) {
260
263
  return;
@@ -308,7 +311,7 @@ class InstanceManager {
308
311
  });
309
312
  }
310
313
  stopAllForPlan(systemId) {
311
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
314
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
312
315
  const instancesForPlan = this._instances.filter((instance) => instance.systemId === systemId);
313
316
  return taskManager_1.taskManager.add(`plan:stop:${systemId}`, async () => {
314
317
  return this.stopInstances(instancesForPlan);
@@ -318,9 +321,9 @@ class InstanceManager {
318
321
  }
319
322
  async start(systemId, instanceId) {
320
323
  return this.exclusive(systemId, instanceId, async () => {
321
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
324
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
322
325
  const blockInstance = await assetManager_1.assetManager.getBlockInstance(systemId, instanceId);
323
- const blockRef = (0, utils_1.normalizeKapetaUri)(blockInstance.block.ref);
326
+ const blockRef = (0, nodejs_utils_1.normalizeKapetaUri)(blockInstance.block.ref);
324
327
  const blockAsset = await assetManager_1.assetManager.getAsset(blockRef, true);
325
328
  if (!blockAsset) {
326
329
  throw new Error('Block not found: ' + blockRef);
@@ -436,7 +439,7 @@ class InstanceManager {
436
439
  * We do it this way to not cause the user to wait for the instance to start again
437
440
  */
438
441
  async prepareForRestart(systemId, instanceId) {
439
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
442
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
440
443
  await this.stopInner(systemId, instanceId);
441
444
  }
442
445
  async stopAll() {
@@ -468,9 +471,9 @@ class InstanceManager {
468
471
  if (!instance.systemId) {
469
472
  return;
470
473
  }
471
- instance.systemId = (0, utils_1.normalizeKapetaUri)(instance.systemId);
474
+ instance.systemId = (0, nodejs_utils_1.normalizeKapetaUri)(instance.systemId);
472
475
  if (instance.ref) {
473
- instance.ref = (0, utils_1.normalizeKapetaUri)(instance.ref);
476
+ instance.ref = (0, nodejs_utils_1.normalizeKapetaUri)(instance.ref);
474
477
  }
475
478
  if (instance.desiredStatus === types_1.DesiredInstanceStatus.RUN) {
476
479
  // Check if the plan still exists and the instance is still in the plan
@@ -1,17 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.kapetaHeaders = void 0;
4
- const utils_1 = require("../utils/utils");
4
+ const nodejs_utils_1 = require("@kapeta/nodejs-utils");
5
5
  function kapetaHeaders(req, res, next) {
6
6
  let blockRef = req.headers['x-kapeta-block'];
7
7
  let systemId = req.headers['x-kapeta-system'];
8
8
  let instanceId = req.headers['x-kapeta-instance'];
9
9
  let environment = req.headers['x-kapeta-environment'];
10
10
  if (blockRef) {
11
- blockRef = (0, utils_1.normalizeKapetaUri)(blockRef);
11
+ blockRef = (0, nodejs_utils_1.normalizeKapetaUri)(blockRef);
12
12
  }
13
13
  if (systemId) {
14
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
14
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
15
15
  }
16
16
  req.kapeta = {
17
17
  blockRef,
@@ -5,7 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.networkManager = void 0;
7
7
  const node_uuid_1 = __importDefault(require("node-uuid"));
8
- const utils_1 = require("./utils/utils");
8
+ const nodejs_utils_1 = require("@kapeta/nodejs-utils");
9
9
  class NetworkManager {
10
10
  _connections;
11
11
  _sources;
@@ -24,7 +24,7 @@ class NetworkManager {
24
24
  this._targets = {};
25
25
  }
26
26
  _ensureSystem(systemId) {
27
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
27
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
28
28
  if (!this._connections[systemId]) {
29
29
  this._connections[systemId] = {};
30
30
  }
@@ -36,7 +36,7 @@ class NetworkManager {
36
36
  }
37
37
  }
38
38
  _ensureConnection(systemId, connectionId) {
39
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
39
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
40
40
  this._ensureSystem(systemId);
41
41
  if (!this._connections[systemId][connectionId]) {
42
42
  this._connections[systemId][connectionId] = [];
@@ -44,7 +44,7 @@ class NetworkManager {
44
44
  return this._connections[systemId][connectionId];
45
45
  }
46
46
  _ensureSource(systemId, sourceBlockInstanceId) {
47
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
47
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
48
48
  this._ensureSystem(systemId);
49
49
  if (!this._sources[systemId][sourceBlockInstanceId]) {
50
50
  this._sources[systemId][sourceBlockInstanceId] = [];
@@ -52,7 +52,7 @@ class NetworkManager {
52
52
  return this._sources[systemId][sourceBlockInstanceId];
53
53
  }
54
54
  _ensureTarget(systemId, targetBlockInstanceId) {
55
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
55
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
56
56
  this._ensureSystem(systemId);
57
57
  if (!this._targets[systemId][targetBlockInstanceId]) {
58
58
  this._targets[systemId][targetBlockInstanceId] = [];
@@ -60,7 +60,7 @@ class NetworkManager {
60
60
  return this._targets[systemId][targetBlockInstanceId];
61
61
  }
62
62
  addRequest(systemId, connection, request, consumerMethodId, providerMethodId) {
63
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
63
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
64
64
  const traffic = new Traffic(connection, request, consumerMethodId, providerMethodId);
65
65
  this._ensureConnection(systemId, traffic.connectionId).push(traffic);
66
66
  this._ensureSource(systemId, connection.provider.blockId).push(traffic);
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.operatorManager = exports.KIND_OPERATOR = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const md5_1 = __importDefault(require("md5"));
9
- const nodejs_utils_1 = require("@kapeta/nodejs-utils");
10
9
  const serviceManager_1 = require("./serviceManager");
11
10
  const storageService_1 = require("./storageService");
12
11
  const containerManager_1 = require("./containerManager");
13
12
  const fs_extra_1 = __importDefault(require("fs-extra"));
14
13
  const definitionsManager_1 = require("./definitionsManager");
15
14
  const utils_1 = require("./utils/utils");
15
+ const nodejs_utils_1 = require("@kapeta/nodejs-utils");
16
16
  const lodash_1 = __importDefault(require("lodash"));
17
17
  const async_lock_1 = __importDefault(require("async-lock"));
18
18
  const taskManager_1 = require("./taskManager");
@@ -69,7 +69,7 @@ class OperatorManager {
69
69
  * Get information about a specific consumed resource
70
70
  */
71
71
  async getConsumerResourceInfo(systemId, fromServiceId, resourceType, portType, name, environment) {
72
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
72
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
73
73
  const plans = await definitionsManager_1.definitionsManager.getDefinitions(KIND_PLAN);
74
74
  const planUri = (0, nodejs_utils_1.parseKapetaUri)(systemId);
75
75
  const currentPlan = plans.find((plan) => plan.definition.metadata.name === planUri.fullName && plan.version === planUri.version);
@@ -117,7 +117,7 @@ class OperatorManager {
117
117
  * @return {Promise<ContainerInfo>}
118
118
  */
119
119
  async ensureResource(systemId, resourceType, version) {
120
- systemId = (0, utils_1.normalizeKapetaUri)(systemId);
120
+ systemId = (0, nodejs_utils_1.normalizeKapetaUri)(systemId);
121
121
  const key = `${systemId}#${resourceType}:${version}`;
122
122
  return await this.operatorLock.acquire(key, async () => {
123
123
  const operator = await this.getOperator(resourceType, version);