@hahnpro/hpc-api 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/api.js CHANGED
@@ -15,19 +15,22 @@ const timeseries_service_1 = require("./timeseries.service");
15
15
  const user_service_1 = require("./user.service");
16
16
  class API {
17
17
  constructor() {
18
+ const normalizePath = (value = '', defaultValue = '') => value.replace(/^\/+|\/+$/g, '') || defaultValue;
18
19
  let apiBaseUrl = process.env.API_BASE_URL || 'https://testing.hahnpro.com';
19
20
  if (!apiBaseUrl.startsWith('https') && !apiBaseUrl.startsWith('http')) {
20
21
  console.info('no protocol specified - using HTTPS');
21
22
  apiBaseUrl = `https://${apiBaseUrl}`;
22
23
  }
24
+ const apiUrl = apiBaseUrl + '/' + normalizePath(process.env.API_BASE_PATH, 'api');
23
25
  const authBaseUrl = process.env.AUTH_BASE_URL || apiBaseUrl;
26
+ const authUrl = authBaseUrl + '/' + normalizePath(process.env.AUTH_BASE_PATH, 'auth');
24
27
  const realm = process.env.AUTH_REALM || 'hpc';
25
28
  const client = process.env.API_USER || 'flow-executor-service';
26
29
  const secret = process.env.AUTH_SECRET;
27
30
  if (!secret) {
28
31
  throw new Error('"API_BASE_URL", "API_USER", "AUTH_REALM" and "AUTH_SECRET" environment variables must be set');
29
32
  }
30
- this.httpClient = new http_service_1.HttpClient(apiBaseUrl, authBaseUrl, realm, client, secret);
33
+ this.httpClient = new http_service_1.HttpClient(apiUrl, authUrl, realm, client, secret);
31
34
  this.assets = new asset_service_1.AssetService(this.httpClient);
32
35
  this.assetTypes = new assettypes_service_1.AssetTypesService(this.httpClient);
33
36
  this.contents = new content_service_1.ContentService(this.httpClient);
@@ -4,7 +4,7 @@ exports.AssetService = void 0;
4
4
  const data_service_1 = require("./data.service");
5
5
  class AssetService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_ASSET_URL || 'api/assets');
7
+ super(httpClient, '/assets');
8
8
  this.addAttachment = (id, form) => {
9
9
  const headers = Object.assign({}, form.getHeaders());
10
10
  return this.httpClient.post(`${this.basePath}/${id}/attachment`, form, {
@@ -4,7 +4,7 @@ exports.AssetTypesService = void 0;
4
4
  const data_service_1 = require("./data.service");
5
5
  class AssetTypesService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
- super(httpClient, 'api/assettypes');
7
+ super(httpClient, '/assettypes');
8
8
  }
9
9
  }
10
10
  exports.AssetTypesService = AssetTypesService;
@@ -5,7 +5,7 @@ const content_interface_1 = require("./content.interface");
5
5
  const data_service_1 = require("./data.service");
6
6
  class ContentService extends data_service_1.DataService {
7
7
  constructor(httpClient) {
8
- super(httpClient, process.env.DEBUG_CONTENT_URL || 'api/contents');
8
+ super(httpClient, '/contents');
9
9
  this.upload = (form) => {
10
10
  const headers = Object.assign({}, form.getHeaders());
11
11
  return this.httpClient.post(`${this.basePath}`, form, { headers, maxBodyLength: Infinity, maxContentLength: Infinity });
@@ -4,7 +4,7 @@ exports.EndpointService = void 0;
4
4
  const data_service_1 = require("./data.service");
5
5
  class EndpointService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_ENDPOINT_URL || 'api/notification/endpoints');
7
+ super(httpClient, '/notification/endpoints');
8
8
  }
9
9
  sendNotification(endpointId, subject, message, group, eventLink, assetLink) {
10
10
  const body = Object.assign(Object.assign({ subject, message, group }, (eventLink && { eventLink })), (assetLink && { assetLink }));
@@ -4,7 +4,7 @@ exports.EventsService = void 0;
4
4
  const data_service_1 = require("./data.service");
5
5
  class EventsService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_EVENTS_URL || 'api/events');
7
+ super(httpClient, '/events');
8
8
  }
9
9
  getLastEventByAssetAndGroup(assetId, group) {
10
10
  return this.httpClient.get(`${this.basePath}/last/${assetId}/${group}`);
@@ -8,7 +8,7 @@ export declare class HttpClient {
8
8
  private readonly requestQueue;
9
9
  private accessToken;
10
10
  private accessTokenExpiration;
11
- constructor(apiBaseUrl: string, authBaseUrl: string, realm: string, client: string, secret: string);
11
+ constructor(baseURL: string, authbaseURL: string, realm: string, client: string, secret: string);
12
12
  getQueueStats: () => {
13
13
  peak: number;
14
14
  pending: number;
@@ -6,7 +6,7 @@ const axios_1 = (0, tslib_1.__importDefault)(require("axios"));
6
6
  const Queue_1 = require("./Queue");
7
7
  const EXPIRATION_BUFFER = 30 * 1000;
8
8
  class HttpClient {
9
- constructor(apiBaseUrl, authBaseUrl, realm, client, secret) {
9
+ constructor(baseURL, authbaseURL, realm, client, secret) {
10
10
  this.realm = realm;
11
11
  this.client = client;
12
12
  this.secret = secret;
@@ -50,7 +50,7 @@ class HttpClient {
50
50
  ]);
51
51
  const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
52
52
  this.authAxiosInstance
53
- .post(`/auth/realms/${this.realm}/protocol/openid-connect/token`, params.toString(), { headers })
53
+ .post(`/realms/${this.realm}/protocol/openid-connect/token`, params.toString(), { headers })
54
54
  .then((res) => {
55
55
  var _a;
56
56
  if (((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.access_token) && res.data.expires_in) {
@@ -65,9 +65,8 @@ class HttpClient {
65
65
  .catch(reject);
66
66
  });
67
67
  };
68
- authBaseUrl = authBaseUrl || apiBaseUrl;
69
- this.axiosInstance = axios_1.default.create({ baseURL: apiBaseUrl, timeout: 60000 });
70
- this.authAxiosInstance = axios_1.default.create({ baseURL: authBaseUrl, timeout: 10000 });
68
+ this.axiosInstance = axios_1.default.create({ baseURL, timeout: 60000 });
69
+ this.authAxiosInstance = axios_1.default.create({ baseURL: authbaseURL || baseURL, timeout: 10000 });
71
70
  this.requestQueue = new Queue_1.Queue({ concurrency: 1, timeout: 70000, throwOnTimeout: true });
72
71
  }
73
72
  }
@@ -11,7 +11,7 @@ class ProxyService {
11
11
  }
12
12
  url(proxyId, path = '/') {
13
13
  path = path.startsWith('/') ? path : `/${path}`;
14
- return `api/${proxyId}${path}`;
14
+ return `/proxy/${proxyId}${path}`;
15
15
  }
16
16
  }
17
17
  exports.ProxyService = ProxyService;
@@ -4,7 +4,7 @@ exports.SecretService = void 0;
4
4
  const data_service_1 = require("./data.service");
5
5
  class SecretService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_SECRET_URL || '/api/secrets');
7
+ super(httpClient, '/secrets');
8
8
  }
9
9
  }
10
10
  exports.SecretService = SecretService;
@@ -4,7 +4,7 @@ exports.SiDriveIqService = void 0;
4
4
  class SiDriveIqService {
5
5
  constructor(httpClient) {
6
6
  this.httpClient = httpClient;
7
- this.basePath = 'api/sidrive/api/v0';
7
+ this.basePath = '/proxy/sidrive/api/v0';
8
8
  }
9
9
  getAssets(params = {}) {
10
10
  return this.httpClient.get(`${this.basePath}/assets`, { params });
@@ -4,7 +4,7 @@ exports.TaskService = void 0;
4
4
  const data_service_1 = require("./data.service");
5
5
  class TaskService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_TSK_URL || 'api/tasks');
7
+ super(httpClient, '/tasks');
8
8
  }
9
9
  createTaskAttachedToAsset(dto) {
10
10
  return this.httpClient.post(this.basePath, dto);
@@ -4,7 +4,7 @@ exports.TimeSeriesService = void 0;
4
4
  const data_service_1 = require("./data.service");
5
5
  class TimeSeriesService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_TSM_URL || 'api/tsm');
7
+ super(httpClient, '/tsm');
8
8
  }
9
9
  addValue(id, value) {
10
10
  return this.httpClient.post(`${this.basePath}/${id}`, value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/hpc-api",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Module for easy access to the HahnPRO API",
5
5
  "license": "MIT",
6
6
  "author": {