@kapeta/local-cluster-service 0.28.1 → 0.29.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ # [0.29.0](https://github.com/kapetacom/local-cluster-service/compare/v0.28.1...v0.29.0) (2023-12-12)
2
+
3
+
4
+ ### Features
5
+
6
+ * Treat web, http and rest port types the same during port allocation ([#101](https://github.com/kapetacom/local-cluster-service/issues/101)) ([bd9f845](https://github.com/kapetacom/local-cluster-service/commit/bd9f8455ff05e273b900dcd1705aa67423f91d72))
7
+
1
8
  ## [0.28.1](https://github.com/kapetacom/local-cluster-service/compare/v0.28.0...v0.28.1) (2023-12-12)
2
9
 
3
10
 
@@ -115,7 +115,7 @@ router.get('/identity', async (req, res) => {
115
115
  * already called the endpoint the same port is returned.
116
116
  */
117
117
  router.get('/provides/:type', async (req, res) => {
118
- if (req.kapeta.environment === 'docker' && ['web', 'rest'].includes(req.params.type)) {
118
+ if (req.kapeta.environment === 'docker' && serviceManager_1.HTTP_PORTS.includes(req.params.type)) {
119
119
  // Happens when starting a local container with no providers.
120
120
  res.send('80');
121
121
  return;
@@ -21,7 +21,7 @@ const router = (0, express_promise_router_1.default)();
21
21
  */
22
22
  const TYPE_HANDLERS = {
23
23
  rest: rest_1.proxyRestRequest,
24
- web: web_1.proxyWebRequest,
24
+ http: web_1.proxyHttpRequest,
25
25
  };
26
26
  function getResource(resources, resourceName) {
27
27
  return resources.find((resource) => {
@@ -31,10 +31,10 @@ function getResource(resources, resourceName) {
31
31
  router.use('/:systemId/:consumerInstanceId/:consumerResourceName', stringBody_1.stringBody);
32
32
  router.all('/:systemId/:consumerInstanceId/:consumerResourceName/:type/*', async (req, res) => {
33
33
  try {
34
- const typeHandler = TYPE_HANDLERS[req.params.type.toLowerCase()];
34
+ let typeHandler = TYPE_HANDLERS[req.params.type.toLowerCase()];
35
35
  if (!typeHandler) {
36
- res.status(401).send({ error: 'Unknown connection type: ' + req.params.type });
37
- return;
36
+ // Default to http
37
+ typeHandler = TYPE_HANDLERS['http'];
38
38
  }
39
39
  const plan = await assetManager_1.assetManager.getPlan(req.params.systemId);
40
40
  // We can find the connection by the consumer information alone since
@@ -5,4 +5,4 @@
5
5
  import { Response } from 'express';
6
6
  import { ProxyRequestInfo } from '../../types';
7
7
  import { StringBodyRequest } from '../../middleware/stringBody';
8
- export declare function proxyWebRequest(req: StringBodyRequest, res: Response, opts: ProxyRequestInfo): void;
8
+ export declare function proxyHttpRequest(req: StringBodyRequest, res: Response, opts: ProxyRequestInfo): void;
@@ -7,12 +7,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.proxyWebRequest = void 0;
10
+ exports.proxyHttpRequest = void 0;
11
11
  const request_1 = __importDefault(require("request"));
12
12
  const lodash_1 = __importDefault(require("lodash"));
13
13
  const networkManager_1 = require("../../networkManager");
14
14
  const socketManager_1 = require("../../socketManager");
15
- function proxyWebRequest(req, res, opts) {
15
+ function proxyHttpRequest(req, res, opts) {
16
16
  const requestHeaders = lodash_1.default.clone(req.headers);
17
17
  delete requestHeaders['content-length'];
18
18
  delete requestHeaders['content-encoding'];
@@ -54,4 +54,4 @@ function proxyWebRequest(req, res, opts) {
54
54
  //We need to pipe the proxy response to the client response to handle sockets and event streams
55
55
  proxyReq.pipe(res);
56
56
  }
57
- exports.proxyWebRequest = proxyWebRequest;
57
+ exports.proxyHttpRequest = proxyHttpRequest;
@@ -3,7 +3,8 @@
3
3
  * SPDX-License-Identifier: BUSL-1.1
4
4
  */
5
5
  import { EnvironmentType } from './types';
6
- export declare const DEFAULT_PORT_TYPE = "rest";
6
+ export declare const DEFAULT_PORT_TYPE = "http";
7
+ export declare const HTTP_PORTS: string[];
7
8
  declare class ServiceManager {
8
9
  private _systems;
9
10
  constructor();
@@ -7,12 +7,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.serviceManager = exports.DEFAULT_PORT_TYPE = void 0;
10
+ exports.serviceManager = exports.HTTP_PORTS = exports.DEFAULT_PORT_TYPE = void 0;
11
11
  const lodash_1 = __importDefault(require("lodash"));
12
12
  const clusterService_1 = require("./clusterService");
13
13
  const storageService_1 = require("./storageService");
14
14
  const nodejs_utils_1 = require("@kapeta/nodejs-utils");
15
- exports.DEFAULT_PORT_TYPE = 'rest';
15
+ exports.DEFAULT_PORT_TYPE = 'http';
16
+ exports.HTTP_PORTS = ['web', 'http', 'rest'];
16
17
  class ServiceManager {
17
18
  _systems;
18
19
  constructor() {
@@ -64,6 +65,9 @@ class ServiceManager {
64
65
  if (!portType) {
65
66
  portType = exports.DEFAULT_PORT_TYPE;
66
67
  }
68
+ if (exports.HTTP_PORTS.includes(portType)) {
69
+ portType = 'http';
70
+ }
67
71
  const service = this._ensureService(systemId, blockInstanceId);
68
72
  if (!service[portType]) {
69
73
  const port = await clusterService_1.clusterService.getNextAvailablePort();
@@ -115,7 +115,7 @@ router.get('/identity', async (req, res) => {
115
115
  * already called the endpoint the same port is returned.
116
116
  */
117
117
  router.get('/provides/:type', async (req, res) => {
118
- if (req.kapeta.environment === 'docker' && ['web', 'rest'].includes(req.params.type)) {
118
+ if (req.kapeta.environment === 'docker' && serviceManager_1.HTTP_PORTS.includes(req.params.type)) {
119
119
  // Happens when starting a local container with no providers.
120
120
  res.send('80');
121
121
  return;
@@ -21,7 +21,7 @@ const router = (0, express_promise_router_1.default)();
21
21
  */
22
22
  const TYPE_HANDLERS = {
23
23
  rest: rest_1.proxyRestRequest,
24
- web: web_1.proxyWebRequest,
24
+ http: web_1.proxyHttpRequest,
25
25
  };
26
26
  function getResource(resources, resourceName) {
27
27
  return resources.find((resource) => {
@@ -31,10 +31,10 @@ function getResource(resources, resourceName) {
31
31
  router.use('/:systemId/:consumerInstanceId/:consumerResourceName', stringBody_1.stringBody);
32
32
  router.all('/:systemId/:consumerInstanceId/:consumerResourceName/:type/*', async (req, res) => {
33
33
  try {
34
- const typeHandler = TYPE_HANDLERS[req.params.type.toLowerCase()];
34
+ let typeHandler = TYPE_HANDLERS[req.params.type.toLowerCase()];
35
35
  if (!typeHandler) {
36
- res.status(401).send({ error: 'Unknown connection type: ' + req.params.type });
37
- return;
36
+ // Default to http
37
+ typeHandler = TYPE_HANDLERS['http'];
38
38
  }
39
39
  const plan = await assetManager_1.assetManager.getPlan(req.params.systemId);
40
40
  // We can find the connection by the consumer information alone since
@@ -5,4 +5,4 @@
5
5
  import { Response } from 'express';
6
6
  import { ProxyRequestInfo } from '../../types';
7
7
  import { StringBodyRequest } from '../../middleware/stringBody';
8
- export declare function proxyWebRequest(req: StringBodyRequest, res: Response, opts: ProxyRequestInfo): void;
8
+ export declare function proxyHttpRequest(req: StringBodyRequest, res: Response, opts: ProxyRequestInfo): void;
@@ -7,12 +7,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.proxyWebRequest = void 0;
10
+ exports.proxyHttpRequest = void 0;
11
11
  const request_1 = __importDefault(require("request"));
12
12
  const lodash_1 = __importDefault(require("lodash"));
13
13
  const networkManager_1 = require("../../networkManager");
14
14
  const socketManager_1 = require("../../socketManager");
15
- function proxyWebRequest(req, res, opts) {
15
+ function proxyHttpRequest(req, res, opts) {
16
16
  const requestHeaders = lodash_1.default.clone(req.headers);
17
17
  delete requestHeaders['content-length'];
18
18
  delete requestHeaders['content-encoding'];
@@ -54,4 +54,4 @@ function proxyWebRequest(req, res, opts) {
54
54
  //We need to pipe the proxy response to the client response to handle sockets and event streams
55
55
  proxyReq.pipe(res);
56
56
  }
57
- exports.proxyWebRequest = proxyWebRequest;
57
+ exports.proxyHttpRequest = proxyHttpRequest;
@@ -3,7 +3,8 @@
3
3
  * SPDX-License-Identifier: BUSL-1.1
4
4
  */
5
5
  import { EnvironmentType } from './types';
6
- export declare const DEFAULT_PORT_TYPE = "rest";
6
+ export declare const DEFAULT_PORT_TYPE = "http";
7
+ export declare const HTTP_PORTS: string[];
7
8
  declare class ServiceManager {
8
9
  private _systems;
9
10
  constructor();
@@ -7,12 +7,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
7
7
  return (mod && mod.__esModule) ? mod : { "default": mod };
8
8
  };
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.serviceManager = exports.DEFAULT_PORT_TYPE = void 0;
10
+ exports.serviceManager = exports.HTTP_PORTS = exports.DEFAULT_PORT_TYPE = void 0;
11
11
  const lodash_1 = __importDefault(require("lodash"));
12
12
  const clusterService_1 = require("./clusterService");
13
13
  const storageService_1 = require("./storageService");
14
14
  const nodejs_utils_1 = require("@kapeta/nodejs-utils");
15
- exports.DEFAULT_PORT_TYPE = 'rest';
15
+ exports.DEFAULT_PORT_TYPE = 'http';
16
+ exports.HTTP_PORTS = ['web', 'http', 'rest'];
16
17
  class ServiceManager {
17
18
  _systems;
18
19
  constructor() {
@@ -64,6 +65,9 @@ class ServiceManager {
64
65
  if (!portType) {
65
66
  portType = exports.DEFAULT_PORT_TYPE;
66
67
  }
68
+ if (exports.HTTP_PORTS.includes(portType)) {
69
+ portType = 'http';
70
+ }
67
71
  const service = this._ensureService(systemId, blockInstanceId);
68
72
  if (!service[portType]) {
69
73
  const port = await clusterService_1.clusterService.getNextAvailablePort();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapeta/local-cluster-service",
3
- "version": "0.28.1",
3
+ "version": "0.29.0",
4
4
  "description": "Manages configuration, ports and service discovery for locally running Kapeta systems",
5
5
  "type": "commonjs",
6
6
  "exports": {
@@ -5,7 +5,7 @@
5
5
 
6
6
  import Router from 'express-promise-router';
7
7
  import { configManager, SYSTEM_ID } from '../configManager';
8
- import { serviceManager } from '../serviceManager';
8
+ import { HTTP_PORTS, serviceManager } from '../serviceManager';
9
9
  import { operatorManager } from '../operatorManager';
10
10
  import { instanceManager } from '../instanceManager';
11
11
  import { corsHandler } from '../middleware/cors';
@@ -125,7 +125,7 @@ router.get('/identity', async (req: KapetaRequest, res) => {
125
125
  * already called the endpoint the same port is returned.
126
126
  */
127
127
  router.get('/provides/:type', async (req: KapetaRequest, res) => {
128
- if (req.kapeta!.environment === 'docker' && ['web', 'rest'].includes(req.params.type)) {
128
+ if (req.kapeta!.environment === 'docker' && HTTP_PORTS.includes(req.params.type)) {
129
129
  // Happens when starting a local container with no providers.
130
130
  res.send('80');
131
131
  return;
@@ -7,7 +7,7 @@ import Router from 'express-promise-router';
7
7
  import { Request, Response } from 'express';
8
8
  import { Resource } from '@kapeta/schemas';
9
9
  import { proxyRestRequest } from './types/rest';
10
- import { proxyWebRequest } from './types/web';
10
+ import { proxyHttpRequest } from './types/web';
11
11
  import { ProxyRequestHandler } from '../types';
12
12
  import { stringBody, StringBodyRequest } from '../middleware/stringBody';
13
13
  import { serviceManager } from '../serviceManager';
@@ -22,7 +22,7 @@ const router = Router();
22
22
  */
23
23
  const TYPE_HANDLERS: { [p: string]: ProxyRequestHandler } = {
24
24
  rest: proxyRestRequest,
25
- web: proxyWebRequest,
25
+ http: proxyHttpRequest,
26
26
  };
27
27
 
28
28
  function getResource(resources: Resource[], resourceName: string) {
@@ -37,10 +37,10 @@ router.all(
37
37
  '/:systemId/:consumerInstanceId/:consumerResourceName/:type/*',
38
38
  async (req: StringBodyRequest, res: Response) => {
39
39
  try {
40
- const typeHandler = TYPE_HANDLERS[req.params.type.toLowerCase()];
40
+ let typeHandler = TYPE_HANDLERS[req.params.type.toLowerCase()];
41
41
  if (!typeHandler) {
42
- res.status(401).send({ error: 'Unknown connection type: ' + req.params.type });
43
- return;
42
+ // Default to http
43
+ typeHandler = TYPE_HANDLERS['http'];
44
44
  }
45
45
 
46
46
  const plan = await assetManager.getPlan(req.params.systemId);
@@ -11,7 +11,7 @@ import { Request, Response } from 'express';
11
11
  import { ProxyRequestInfo, SimpleRequest, StringMap } from '../../types';
12
12
  import { StringBodyRequest } from '../../middleware/stringBody';
13
13
 
14
- export function proxyWebRequest(req: StringBodyRequest, res: Response, opts: ProxyRequestInfo) {
14
+ export function proxyHttpRequest(req: StringBodyRequest, res: Response, opts: ProxyRequestInfo) {
15
15
  const requestHeaders = _.clone(req.headers);
16
16
 
17
17
  delete requestHeaders['content-length'];
@@ -9,7 +9,9 @@ import { storageService } from './storageService';
9
9
  import { EnvironmentType } from './types';
10
10
  import { normalizeKapetaUri } from '@kapeta/nodejs-utils';
11
11
 
12
- export const DEFAULT_PORT_TYPE = 'rest';
12
+ export const DEFAULT_PORT_TYPE = 'http';
13
+
14
+ export const HTTP_PORTS = ['web', 'http', 'rest'];
13
15
 
14
16
  class ServiceManager {
15
17
  private _systems: any;
@@ -73,6 +75,10 @@ class ServiceManager {
73
75
  portType = DEFAULT_PORT_TYPE;
74
76
  }
75
77
 
78
+ if (HTTP_PORTS.includes(portType)) {
79
+ portType = 'http';
80
+ }
81
+
76
82
  const service = this._ensureService(systemId, blockInstanceId);
77
83
 
78
84
  if (!service[portType]) {