@hahnpro/hpc-api 6.0.0 → 2024.4.0-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 (178) hide show
  1. package/package.json +8 -24
  2. package/src/index.d.ts +20 -0
  3. package/src/index.js +20 -0
  4. package/{dist → src/lib}/Queue.js +2 -7
  5. package/src/lib/api-base.js +6 -0
  6. package/src/lib/api.js +60 -0
  7. package/src/lib/asset.interface.js +1 -0
  8. package/{dist → src/lib}/asset.service.js +21 -17
  9. package/src/lib/assettypes.service.js +24 -0
  10. package/{dist → src/lib}/content.interface.js +2 -5
  11. package/src/lib/content.service.js +49 -0
  12. package/src/lib/data.interface.js +3 -0
  13. package/{dist → src/lib}/data.service.js +18 -11
  14. package/src/lib/endpoint.interface.js +1 -0
  15. package/{dist → src/lib}/endpoint.service.d.ts +2 -2
  16. package/{dist → src/lib}/endpoint.service.js +2 -6
  17. package/src/lib/events.interface.js +1 -0
  18. package/src/lib/events.service.js +9 -0
  19. package/src/lib/flow-deployment.interface.js +1 -0
  20. package/src/lib/flow-deployment.service.js +68 -0
  21. package/src/lib/flow-function.interface.js +1 -0
  22. package/{dist → src/lib}/flow-function.service.js +3 -6
  23. package/src/lib/flow-module.interface.js +1 -0
  24. package/{dist → src/lib}/flow-module.service.js +8 -7
  25. package/src/lib/flow.interface.js +1 -0
  26. package/{dist → src/lib}/flow.service.js +15 -20
  27. package/src/lib/http.service.js +179 -0
  28. package/src/lib/label.interface.js +1 -0
  29. package/{dist → src/lib}/label.service.js +2 -6
  30. package/src/lib/mock/api-base.mock.js +7 -0
  31. package/src/lib/mock/api.mock.js +199 -0
  32. package/{dist → src/lib}/mock/asset.mock.service.js +30 -41
  33. package/{dist → src/lib}/mock/assetTypes.mock.service.js +19 -27
  34. package/{dist → src/lib}/mock/content.mock.service.js +21 -24
  35. package/src/lib/mock/data.mock.service.js +93 -0
  36. package/{dist → src/lib}/mock/endpoint.mock.service.js +2 -6
  37. package/src/lib/mock/events.mock.service.js +10 -0
  38. package/src/lib/mock/flow-deployment.mock.service.js +118 -0
  39. package/{dist → src/lib}/mock/flow-functions.mock.service.js +12 -21
  40. package/src/lib/mock/flow-modules.mock.service.js +20 -0
  41. package/src/lib/mock/flow.mock.service.js +81 -0
  42. package/src/lib/mock/index.js +11 -0
  43. package/src/lib/mock/label.mock.service.js +13 -0
  44. package/src/lib/mock/notification.mock.service.js +7 -0
  45. package/src/lib/mock/secret.mock.service.js +28 -0
  46. package/src/lib/mock/task.mock.service.js +32 -0
  47. package/{dist → src/lib}/mock/timeseries.mock.service.js +40 -49
  48. package/{dist → src/lib}/mock/trash.mock.service.js +8 -15
  49. package/src/lib/mock/user.mock.service.js +10 -0
  50. package/{dist → src/lib}/mock/vault.mock.service.js +2 -6
  51. package/src/lib/notification.interface.js +1 -0
  52. package/src/lib/notification.service.js +6 -0
  53. package/{dist → src/lib}/proxy.service.js +1 -5
  54. package/src/lib/resource.interface.js +1 -0
  55. package/src/lib/schema.interface.js +1 -0
  56. package/src/lib/secret.interface.js +1 -0
  57. package/src/lib/secret.service.js +15 -0
  58. package/src/lib/storage.interface.js +1 -0
  59. package/src/lib/task.interface.js +1 -0
  60. package/src/lib/task.service.js +19 -0
  61. package/src/lib/timeseries.interface.js +1 -0
  62. package/src/lib/timeseries.service.js +92 -0
  63. package/{dist → src/lib}/token-set.js +3 -7
  64. package/{dist → src/lib}/trash.service.js +2 -6
  65. package/src/lib/user-settings.interface.js +1 -0
  66. package/src/lib/user.service.js +26 -0
  67. package/src/lib/vault.interface.js +1 -0
  68. package/src/lib/vault.service.js +10 -0
  69. package/LICENSE +0 -21
  70. package/dist/api-base.js +0 -10
  71. package/dist/api.js +0 -62
  72. package/dist/asset.interface.js +0 -2
  73. package/dist/assettypes.service.js +0 -28
  74. package/dist/content.service.js +0 -50
  75. package/dist/data.interface.js +0 -6
  76. package/dist/endpoint.interface.js +0 -2
  77. package/dist/events.interface.js +0 -2
  78. package/dist/events.service.js +0 -13
  79. package/dist/flow-deployment.interface.js +0 -2
  80. package/dist/flow-deployment.service.js +0 -74
  81. package/dist/flow-function.interface.js +0 -2
  82. package/dist/flow-module.interface.js +0 -2
  83. package/dist/flow.interface.js +0 -2
  84. package/dist/http.service.js +0 -182
  85. package/dist/index.d.ts +0 -20
  86. package/dist/index.js +0 -23
  87. package/dist/label.interface.js +0 -2
  88. package/dist/mock/api-base.mock.js +0 -11
  89. package/dist/mock/api.mock.js +0 -128
  90. package/dist/mock/data.mock.service.js +0 -96
  91. package/dist/mock/events.mock.service.js +0 -14
  92. package/dist/mock/flow-deployment.mock.service.js +0 -142
  93. package/dist/mock/flow-modules.mock.service.js +0 -27
  94. package/dist/mock/flow.mock.service.js +0 -93
  95. package/dist/mock/index.js +0 -14
  96. package/dist/mock/label.mock.service.js +0 -17
  97. package/dist/mock/notification.mock.service.js +0 -11
  98. package/dist/mock/secret.mock.service.js +0 -31
  99. package/dist/mock/task.mock.service.js +0 -37
  100. package/dist/mock/user.mock.service.js +0 -14
  101. package/dist/notification.interface.js +0 -2
  102. package/dist/notification.service.js +0 -10
  103. package/dist/resource.interface.js +0 -2
  104. package/dist/schema.interface.js +0 -2
  105. package/dist/secret.interface.js +0 -2
  106. package/dist/secret.service.js +0 -19
  107. package/dist/storage.interface.js +0 -2
  108. package/dist/task.interface.js +0 -2
  109. package/dist/task.service.js +0 -22
  110. package/dist/timeseries.interface.js +0 -2
  111. package/dist/timeseries.service.js +0 -56
  112. package/dist/user-settings.interface.js +0 -2
  113. package/dist/user.service.js +0 -33
  114. package/dist/vault.interface.js +0 -2
  115. package/dist/vault.service.js +0 -14
  116. package/{dist → src/lib}/Queue.d.ts +0 -0
  117. package/{dist → src/lib}/api-base.d.ts +0 -0
  118. package/{dist → src/lib}/api.d.ts +6 -6
  119. package/{dist → src/lib}/asset.interface.d.ts +0 -0
  120. package/{dist → src/lib}/asset.service.d.ts +0 -0
  121. package/{dist → src/lib}/assettypes.service.d.ts +0 -0
  122. package/{dist → src/lib}/content.interface.d.ts +0 -0
  123. package/{dist → src/lib}/content.service.d.ts +1 -1
  124. package/{dist → src/lib}/data.interface.d.ts +0 -0
  125. package/{dist → src/lib}/data.service.d.ts +0 -0
  126. package/{dist → src/lib}/endpoint.interface.d.ts +0 -0
  127. package/{dist → src/lib}/events.interface.d.ts +0 -0
  128. package/{dist → src/lib}/events.service.d.ts +0 -0
  129. package/{dist → src/lib}/flow-deployment.interface.d.ts +1 -1
  130. package/{dist → src/lib}/flow-deployment.service.d.ts +0 -0
  131. package/{dist → src/lib}/flow-function.interface.d.ts +0 -0
  132. package/{dist → src/lib}/flow-function.service.d.ts +1 -1
  133. package/{dist → src/lib}/flow-module.interface.d.ts +0 -0
  134. package/{dist → src/lib}/flow-module.service.d.ts +1 -1
  135. package/{dist → src/lib}/flow.interface.d.ts +1 -1
  136. package/{dist → src/lib}/flow.service.d.ts +1 -1
  137. package/{dist → src/lib}/http.service.d.ts +0 -0
  138. package/{dist → src/lib}/label.interface.d.ts +0 -0
  139. package/{dist → src/lib}/label.service.d.ts +0 -0
  140. package/{dist → src/lib}/mock/api-base.mock.d.ts +0 -0
  141. package/{dist → src/lib}/mock/api.mock.d.ts +18 -18
  142. package/{dist → src/lib}/mock/asset.mock.service.d.ts +1 -1
  143. package/{dist → src/lib}/mock/assetTypes.mock.service.d.ts +0 -0
  144. package/{dist → src/lib}/mock/content.mock.service.d.ts +1 -1
  145. package/{dist → src/lib}/mock/data.mock.service.d.ts +0 -0
  146. package/{dist → src/lib}/mock/endpoint.mock.service.d.ts +0 -0
  147. package/{dist → src/lib}/mock/events.mock.service.d.ts +0 -0
  148. package/{dist → src/lib}/mock/flow-deployment.mock.service.d.ts +2 -2
  149. package/{dist → src/lib}/mock/flow-functions.mock.service.d.ts +1 -1
  150. package/{dist → src/lib}/mock/flow-modules.mock.service.d.ts +2 -2
  151. package/{dist → src/lib}/mock/flow.mock.service.d.ts +1 -1
  152. package/{dist → src/lib}/mock/index.d.ts +0 -0
  153. package/{dist → src/lib}/mock/label.mock.service.d.ts +1 -1
  154. package/{dist → src/lib}/mock/notification.mock.service.d.ts +1 -1
  155. package/{dist → src/lib}/mock/secret.mock.service.d.ts +1 -1
  156. package/{dist → src/lib}/mock/task.mock.service.d.ts +0 -0
  157. package/{dist → src/lib}/mock/timeseries.mock.service.d.ts +0 -0
  158. package/{dist → src/lib}/mock/trash.mock.service.d.ts +1 -1
  159. package/{dist → src/lib}/mock/user.mock.service.d.ts +0 -0
  160. package/{dist → src/lib}/mock/vault.mock.service.d.ts +1 -1
  161. package/{dist → src/lib}/notification.interface.d.ts +0 -0
  162. package/{dist → src/lib}/notification.service.d.ts +1 -1
  163. package/{dist → src/lib}/proxy.service.d.ts +0 -0
  164. package/{dist → src/lib}/resource.interface.d.ts +0 -0
  165. package/{dist → src/lib}/schema.interface.d.ts +0 -0
  166. package/{dist → src/lib}/secret.interface.d.ts +0 -0
  167. package/{dist → src/lib}/secret.service.d.ts +0 -0
  168. package/{dist → src/lib}/storage.interface.d.ts +0 -0
  169. package/{dist → src/lib}/task.interface.d.ts +0 -0
  170. package/{dist → src/lib}/task.service.d.ts +0 -0
  171. package/{dist → src/lib}/timeseries.interface.d.ts +0 -0
  172. package/{dist → src/lib}/timeseries.service.d.ts +0 -0
  173. package/{dist → src/lib}/token-set.d.ts +0 -0
  174. package/{dist → src/lib}/trash.service.d.ts +0 -0
  175. package/{dist → src/lib}/user-settings.interface.d.ts +0 -0
  176. package/{dist → src/lib}/user.service.d.ts +0 -0
  177. package/{dist → src/lib}/vault.interface.d.ts +0 -0
  178. package/{dist → src/lib}/vault.service.d.ts +1 -1
@@ -1,24 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeseriesMockService = void 0;
4
- const tslib_1 = require("tslib");
5
- const ts_mixer_1 = require("ts-mixer");
6
- const api_base_mock_1 = require("./api-base.mock");
7
- const data_mock_service_1 = require("./data.mock.service");
8
- const trash_mock_service_1 = require("./trash.mock.service");
9
- let BaseService = class BaseService extends api_base_mock_1.APIBaseMock {
1
+ import { __decorate } from "tslib";
2
+ import { mix } from 'ts-mixer';
3
+ import { APIBaseMock } from './api-base.mock';
4
+ import { DataMockService } from './data.mock.service';
5
+ import { TrashMockService } from './trash.mock.service';
6
+ let BaseService = class BaseService extends APIBaseMock {
10
7
  };
11
- BaseService = tslib_1.__decorate([
12
- (0, ts_mixer_1.mix)(data_mock_service_1.DataMockService, trash_mock_service_1.TrashMockService)
8
+ BaseService = __decorate([
9
+ mix(DataMockService, TrashMockService)
13
10
  ], BaseService);
14
- class TimeseriesMockService extends BaseService {
11
+ export class TimeseriesMockService extends BaseService {
15
12
  constructor(timeseries, timeseriesValues) {
16
- const data = timeseries.map((value, index) => (Object.assign(Object.assign({}, value), { data: timeseriesValues[index] })));
13
+ const data = timeseries.map((value, index) => ({ ...value, data: timeseriesValues[index] }));
17
14
  super(data);
18
15
  }
19
16
  deleteOne(tsmId, force = false) {
20
17
  const tsm = this.data.find((v) => v.id === tsmId);
21
- if (!(tsm === null || tsm === void 0 ? void 0 : tsm.deletedAt) && !force) {
18
+ if (!tsm?.deletedAt && !force) {
19
+ // put tsm in paper bin by setting deletedAt prop
22
20
  tsm.deletedAt = new Date().toISOString();
23
21
  return Promise.resolve(tsm);
24
22
  }
@@ -32,7 +30,7 @@ class TimeseriesMockService extends BaseService {
32
30
  const ts = this.data.find((v) => v.assetRef === assetId);
33
31
  const data = Object.entries(values).map(([timestamp, value]) => {
34
32
  if (value !== null && typeof value === 'object') {
35
- return Object.assign({ timestamp }, value);
33
+ return { timestamp, ...value };
36
34
  }
37
35
  else {
38
36
  return { timestamp, value };
@@ -63,7 +61,7 @@ class TimeseriesMockService extends BaseService {
63
61
  for (const [tsName, values] of Object.entries(timeSeries)) {
64
62
  const data = Object.entries(values).map(([timestamp, value]) => {
65
63
  if (value !== null && typeof value === 'object') {
66
- return Object.assign({ timestamp }, value);
64
+ return { timestamp, ...value };
67
65
  }
68
66
  else {
69
67
  return { timestamp, value };
@@ -92,20 +90,19 @@ class TimeseriesMockService extends BaseService {
92
90
  }
93
91
  return Promise.resolve(psr);
94
92
  }
95
- addValue(id, value) {
96
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
97
- const ts = yield this.getOne(id, {});
98
- for (const [timestamp, v] of Object.entries(value)) {
99
- if (v !== null && typeof v === 'object') {
100
- ts.data.push(Object.assign({ timestamp }, v));
101
- }
102
- else {
103
- ts.data.push({ timestamp: parseInt(timestamp, 10), value: v });
104
- }
93
+ async addValue(id, value) {
94
+ const ts = await this.getOne(id, {});
95
+ for (const [timestamp, v] of Object.entries(value)) {
96
+ if (v !== null && typeof v === 'object') {
97
+ ts.data.push({ timestamp, ...v });
105
98
  }
106
- });
99
+ else {
100
+ ts.data.push({ timestamp: parseInt(timestamp, 10), value: v });
101
+ }
102
+ }
107
103
  }
108
104
  getManyByAsset(assetId, names) {
105
+ // get timeseries where assetRef is assetId
109
106
  const page = { docs: [], limit: 10, total: 0 };
110
107
  for (const datum of this.data) {
111
108
  if (datum.assetRef === assetId) {
@@ -118,30 +115,24 @@ class TimeseriesMockService extends BaseService {
118
115
  page.total = page.docs.length;
119
116
  return Promise.resolve(page);
120
117
  }
121
- getMostRecentValue(id, before) {
122
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
123
- const ts = yield this.getOne(id, {});
124
- for (const datum of ts.data) {
125
- if (datum.timestamp < before.valueOf()) {
126
- return datum;
127
- }
118
+ async getMostRecentValue(id, before) {
119
+ const ts = await this.getOne(id, {});
120
+ for (const datum of ts.data) {
121
+ if (datum.timestamp < before.valueOf()) {
122
+ return datum;
128
123
  }
129
- });
124
+ }
125
+ return null;
130
126
  }
131
- getValues(id, from, limit, group) {
132
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
133
- let timeSeriesValues = yield this.getValuesOfPeriod(id, from, new Date().valueOf(), group);
134
- if (limit) {
135
- timeSeriesValues = timeSeriesValues.slice(0, limit);
136
- }
137
- return timeSeriesValues;
138
- });
127
+ async getValues(id, from, limit, group) {
128
+ let timeSeriesValues = await this.getValuesOfPeriod(id, from, new Date().valueOf(), group);
129
+ if (limit) {
130
+ timeSeriesValues = timeSeriesValues.slice(0, limit);
131
+ }
132
+ return timeSeriesValues;
139
133
  }
140
- getValuesOfPeriod(id, from, to, group) {
141
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
142
- const ts = yield this.getOne(id, {});
143
- return ts.data.filter((v) => v.timestamp < to && v.timestamp > from);
144
- });
134
+ async getValuesOfPeriod(id, from, to, group) {
135
+ const ts = await this.getOne(id, {});
136
+ return ts.data.filter((v) => v.timestamp < to && v.timestamp > from);
145
137
  }
146
138
  }
147
- exports.TimeseriesMockService = TimeseriesMockService;
@@ -1,9 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrashMockService = void 0;
4
- const tslib_1 = require("tslib");
5
- const trash_service_1 = require("../trash.service");
6
- class TrashMockService extends trash_service_1.TrashService {
1
+ import { TrashService } from '../trash.service';
2
+ export class TrashMockService extends TrashService {
7
3
  constructor() {
8
4
  super(null, null);
9
5
  this.data = [];
@@ -20,14 +16,12 @@ class TrashMockService extends trash_service_1.TrashService {
20
16
  delete deleted['deletedAt'];
21
17
  return Promise.resolve(deleted);
22
18
  }
23
- emptyTrash(offset) {
24
- return tslib_1.__awaiter(this, void 0, void 0, function* () {
25
- const dateOffsSeconds = Math.round(new Date().getTime() / 1000) - offset;
26
- const date = new Date(dateOffsSeconds * 1000);
27
- const trashIds = this.data.filter((v) => new Date(v['deletedAt']) < date).map((v) => v.id);
28
- this.data = this.data.filter((item) => !trashIds.includes(item.id));
29
- return Promise.resolve({ acknowledged: true, deletedCount: trashIds.length });
30
- });
19
+ async emptyTrash(offset) {
20
+ const dateOffsSeconds = Math.round(new Date().getTime() / 1000) - offset;
21
+ const date = new Date(dateOffsSeconds * 1000);
22
+ const trashIds = this.data.filter((v) => new Date(v['deletedAt']) < date).map((v) => v.id);
23
+ this.data = this.data.filter((item) => !trashIds.includes(item.id));
24
+ return Promise.resolve({ acknowledged: true, deletedCount: trashIds.length });
31
25
  }
32
26
  getTrash(params) {
33
27
  const page = this.getItems(params, true);
@@ -43,4 +37,3 @@ class TrashMockService extends trash_service_1.TrashService {
43
37
  return page;
44
38
  }
45
39
  }
46
- exports.TrashMockService = TrashMockService;
@@ -0,0 +1,10 @@
1
+ import { UserService } from '../user.service';
2
+ export class UserMockService extends UserService {
3
+ constructor(users) {
4
+ super(null);
5
+ this.users = users;
6
+ }
7
+ getCurrentUserRoles() {
8
+ return Promise.resolve(this.users.roles);
9
+ }
10
+ }
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VaultMockService = void 0;
4
- const data_mock_service_1 = require("./data.mock.service");
5
- class VaultMockService extends data_mock_service_1.DataMockService {
1
+ import { DataMockService } from './data.mock.service';
2
+ export class VaultMockService extends DataMockService {
6
3
  constructor(secrets) {
7
4
  super();
8
5
  this.data = secrets;
@@ -15,4 +12,3 @@ class VaultMockService extends data_mock_service_1.DataMockService {
15
12
  return Promise.resolve(vaultSecret.secret);
16
13
  }
17
14
  }
18
- exports.VaultMockService = VaultMockService;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ import { DataService } from './data.service';
2
+ export class NotificationService extends DataService {
3
+ constructor(httpClient) {
4
+ super(httpClient, '/notifications');
5
+ }
6
+ }
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ProxyService = void 0;
4
- class ProxyService {
1
+ export class ProxyService {
5
2
  constructor(httpClient) {
6
3
  this.httpClient = httpClient;
7
4
  this.delete = (proxyId, path, config) => this.httpClient.delete(this.url(proxyId, path), config);
@@ -14,4 +11,3 @@ class ProxyService {
14
11
  return `/proxy/${proxyId}${path}`;
15
12
  }
16
13
  }
17
- exports.ProxyService = ProxyService;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,15 @@
1
+ import { __decorate } from "tslib";
2
+ import { mix } from 'ts-mixer';
3
+ import { APIBase } from './api-base';
4
+ import { DataService } from './data.service';
5
+ import { TrashService } from './trash.service';
6
+ let BaseService = class BaseService extends APIBase {
7
+ };
8
+ BaseService = __decorate([
9
+ mix(DataService, TrashService)
10
+ ], BaseService);
11
+ export class SecretService extends BaseService {
12
+ constructor(httpClient) {
13
+ super(httpClient, '/secrets');
14
+ }
15
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,19 @@
1
+ import { __decorate } from "tslib";
2
+ import { mix } from 'ts-mixer';
3
+ import { APIBase } from './api-base';
4
+ import { DataService } from './data.service';
5
+ import { TrashService } from './trash.service';
6
+ let BaseService = class BaseService extends APIBase {
7
+ };
8
+ BaseService = __decorate([
9
+ mix(DataService, TrashService)
10
+ ], BaseService);
11
+ export class TaskService extends BaseService {
12
+ constructor(httpClient) {
13
+ super(httpClient, '/tasks');
14
+ }
15
+ // we may not need this method (already have the addOne method from DataService)
16
+ createTaskAttachedToAsset(dto, options = {}) {
17
+ return this.httpClient.post(this.basePath, dto, options);
18
+ }
19
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,92 @@
1
+ import { __decorate } from "tslib";
2
+ import { mix } from 'ts-mixer';
3
+ import { APIBase } from './api-base';
4
+ import { DataService } from './data.service';
5
+ import { TrashService } from './trash.service';
6
+ let BaseService = class BaseService extends APIBase {
7
+ };
8
+ BaseService = __decorate([
9
+ mix(DataService, TrashService)
10
+ ], BaseService);
11
+ export class TimeSeriesService extends BaseService {
12
+ constructor(httpClient) {
13
+ super(httpClient, '/tsm');
14
+ }
15
+ addValue(id, value, options = {}) {
16
+ return this.httpClient.post(`${this.basePath}/${id}`, value, options);
17
+ }
18
+ /**
19
+ * Adds time series values to an asset by the name of the time series.
20
+ * If the time series does not exist, it is created.
21
+ * @param assetId - The ID of the asset to which the time series values are added.
22
+ * @param name - The name of the time series.
23
+ * @param readPermissions - an array of permissions that allow the user to read the time series.
24
+ * @param readWritePermissions - an array of permissions that allow the user to read and write the time series.
25
+ * @param values - The time series values are specified as an object with the following structure:
26
+ * {
27
+ * [timestamp: string]: any, // The timestamp and value pairs
28
+ * ...
29
+ * }
30
+ * @param options
31
+ * @returns a promise that resolves to the time series that was added.
32
+ */
33
+ addAssetTimeSeriesValues(assetId, name, readPermissions, readWritePermissions, values, options = {}) {
34
+ const dto = {
35
+ name,
36
+ readPermissions,
37
+ readWritePermissions,
38
+ values,
39
+ };
40
+ return this.httpClient.post(`${this.basePath}/assets/${assetId}`, dto, options);
41
+ }
42
+ /**
43
+ * Adds multiple time series values to an asset by the name of the time series.
44
+ * If the time series does not exist, it is created.
45
+ * If the operation is successful, the value property contains the time series that was added.
46
+ * If the operation fails, the reason property contains the error that caused the operation to fail.
47
+ * @param assetId - The ID of the asset to which the time series values are added.
48
+ * @param readPermissions - an array of permissions that allow the user to read the time series.
49
+ * @param readWritePermissions - an array of permissions that allow the user to read and write the time series.
50
+ * @param timeSeries - The time series values are specified as an object with the following structure:
51
+ * {
52
+ * [timeSeriesName: string]: { // The name of the time series
53
+ * [timestamp: string]: any, // The timestamp and value pairs
54
+ * ...
55
+ * },
56
+ * ...
57
+ * }
58
+ * @param options
59
+ * @returns a promise that resolves to an array of objects containing the results of the operation.
60
+ * Each object has the following structure:
61
+ * {
62
+ * status: "fulfilled" | "rejected",
63
+ * value?: TimeSeries,
64
+ * reason?: Error,
65
+ * }
66
+ */
67
+ addManyAssetTimeSeriesValues(assetId, readPermissions, readWritePermissions, timeSeries, options = {}) {
68
+ const dtos = Object.entries(timeSeries).map(([name, values]) => ({
69
+ name,
70
+ readPermissions,
71
+ readWritePermissions,
72
+ values,
73
+ }));
74
+ return this.httpClient.post(`${this.basePath}/assets/${assetId}/bulk`, dtos, options);
75
+ }
76
+ getMostRecentValue(id, before, options = {}) {
77
+ const params = before ? { before: before.toISOString() } : {};
78
+ return this.httpClient.get(`${this.basePath}/${id}/recent`, { params, ...options });
79
+ }
80
+ getValues(id, from, limit, group, options = {}) {
81
+ const params = { limit, group };
82
+ return this.httpClient.get(`${this.basePath}/${id}/${from}`, { params, ...options });
83
+ }
84
+ getValuesOfPeriod(id, from, to, group, options = {}) {
85
+ const params = { group };
86
+ return this.httpClient.get(`${this.basePath}/${id}/${from}/${to}`, { params, ...options });
87
+ }
88
+ getManyByAsset(assetId, names, options = {}) {
89
+ const params = Array.isArray(names) ? { names: names.join() } : {};
90
+ return this.httpClient.get(`${this.basePath}/asset/${assetId}`, { params, ...options });
91
+ }
92
+ }
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TokenSet = void 0;
4
- const TOKEN_EXPIRATION_BUFFER = 20;
5
- class TokenSet {
1
+ const TOKEN_EXPIRATION_BUFFER = 20; // 20 seconds
2
+ export class TokenSet {
6
3
  constructor(access_token, expires_in, provided = false) {
7
4
  this._accessToken = access_token;
8
5
  this._expiresAt = Math.floor(Date.now() / 1000) + Number(expires_in);
@@ -21,7 +18,6 @@ class TokenSet {
21
18
  return this._provided;
22
19
  }
23
20
  isExpired() {
24
- return this.expiresIn <= (this.provided ? 0 : TOKEN_EXPIRATION_BUFFER);
21
+ return this.expiresIn <= (this.provided ? 0 : TOKEN_EXPIRATION_BUFFER); // Use the entire time of provided token to avoid throwing 'expired' error early
25
22
  }
26
23
  }
27
- exports.TokenSet = TokenSet;
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TrashService = void 0;
4
- const api_base_1 = require("./api-base");
5
- class TrashService extends api_base_1.APIBase {
1
+ import { APIBase } from './api-base';
2
+ export class TrashService extends APIBase {
6
3
  trashRestoreAll() {
7
4
  return this.httpClient.put(`${this.basePath}/trash/restore`, {});
8
5
  }
@@ -18,4 +15,3 @@ class TrashService extends api_base_1.APIBase {
18
15
  return this.httpClient.get(`${this.basePath}/trash`, { params });
19
16
  }
20
17
  }
21
- exports.TrashService = TrashService;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,26 @@
1
+ import { jwtDecode } from 'jwt-decode';
2
+ export class UserService {
3
+ constructor(httpClient) {
4
+ this.httpClient = httpClient;
5
+ this.basePath = '/user';
6
+ }
7
+ async getCurrentUserRoles() {
8
+ try {
9
+ const token = await this.httpClient.getAccessToken();
10
+ const decode = jwtDecode(token);
11
+ return decode.realm_access.roles;
12
+ }
13
+ catch (err) {
14
+ return null;
15
+ }
16
+ }
17
+ getUserSettings(options = {}) {
18
+ return this.httpClient.get(this.basePath, options);
19
+ }
20
+ updateUserSettings(settings, options = {}) {
21
+ return this.httpClient.put(this.basePath, settings, options);
22
+ }
23
+ deleteUserSettings(options = {}) {
24
+ return this.httpClient.delete(this.basePath, options);
25
+ }
26
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,10 @@
1
+ import { DataService } from './data.service';
2
+ export class VaultService extends DataService {
3
+ constructor(httpClient) {
4
+ super(httpClient, '/vault/secrets');
5
+ }
6
+ getSecret(name, version, options = {}) {
7
+ const params = version ? { version } : {};
8
+ return this.httpClient.get(`${this.basePath}/${name}/secret`, { params, ...options });
9
+ }
10
+ }
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2021 Hahn PRO
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/dist/api-base.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.APIBase = void 0;
4
- class APIBase {
5
- constructor(httpClient, basePath) {
6
- this.httpClient = httpClient;
7
- this.basePath = basePath;
8
- }
9
- }
10
- exports.APIBase = APIBase;
package/dist/api.js DELETED
@@ -1,62 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.API = void 0;
4
- const asset_service_1 = require("./asset.service");
5
- const assettypes_service_1 = require("./assettypes.service");
6
- const content_service_1 = require("./content.service");
7
- const endpoint_service_1 = require("./endpoint.service");
8
- const events_service_1 = require("./events.service");
9
- const http_service_1 = require("./http.service");
10
- const proxy_service_1 = require("./proxy.service");
11
- const secret_service_1 = require("./secret.service");
12
- const task_service_1 = require("./task.service");
13
- const timeseries_service_1 = require("./timeseries.service");
14
- const user_service_1 = require("./user.service");
15
- const flow_service_1 = require("./flow.service");
16
- const flow_function_service_1 = require("./flow-function.service");
17
- const flow_module_service_1 = require("./flow-module.service");
18
- const flow_deployment_service_1 = require("./flow-deployment.service");
19
- const label_service_1 = require("./label.service");
20
- const vault_service_1 = require("./vault.service");
21
- const notification_service_1 = require("./notification.service");
22
- class API {
23
- constructor(httpClient, context) {
24
- this.httpClient = httpClient;
25
- if (!httpClient) {
26
- const normalizePath = (value = '', defaultValue = '') => value.replace(/(?:^\/+)|(?:\/+$)/g, '') || defaultValue;
27
- let apiBaseUrl = process.env.API_BASE_URL || 'https://testing.hahnpro.com';
28
- if (!apiBaseUrl.startsWith('https') && !apiBaseUrl.startsWith('http')) {
29
- console.info('no protocol specified - using HTTPS');
30
- apiBaseUrl = `https://${apiBaseUrl}`;
31
- }
32
- const apiUrl = apiBaseUrl + '/' + normalizePath(process.env.API_BASE_PATH, 'api');
33
- const authBaseUrl = process.env.AUTH_BASE_URL || apiBaseUrl;
34
- const authUrl = authBaseUrl + '/' + normalizePath(process.env.AUTH_BASE_PATH, 'auth');
35
- const realm = process.env.AUTH_REALM || 'hpc';
36
- const client = process.env.API_USER || 'flow-executor-service';
37
- const secret = process.env.AUTH_SECRET;
38
- if (!secret) {
39
- throw new Error('"API_BASE_URL", "API_USER", "AUTH_REALM" and "AUTH_SECRET" environment variables must be set');
40
- }
41
- this.httpClient = new http_service_1.HttpClient(apiUrl, authUrl, realm, client, secret, context === null || context === void 0 ? void 0 : context.tokenSubject);
42
- }
43
- this.assets = new asset_service_1.AssetService(this.httpClient);
44
- this.assetTypes = new assettypes_service_1.AssetTypesService(this.httpClient);
45
- this.contents = new content_service_1.ContentService(this.httpClient);
46
- this.endpoints = new endpoint_service_1.EndpointService(this.httpClient);
47
- this.events = new events_service_1.EventsService(this.httpClient);
48
- this.flows = new flow_service_1.FlowService(this.httpClient);
49
- this.flowDeployments = new flow_deployment_service_1.FlowDeploymentService(this.httpClient);
50
- this.flowFunctions = new flow_function_service_1.FlowFunctionService(this.httpClient);
51
- this.flowModules = new flow_module_service_1.FlowModuleService(this.httpClient);
52
- this.labels = new label_service_1.LabelService(this.httpClient);
53
- this.proxy = new proxy_service_1.ProxyService(this.httpClient);
54
- this.secrets = new secret_service_1.SecretService(this.httpClient);
55
- this.tasks = new task_service_1.TaskService(this.httpClient);
56
- this.timeSeries = new timeseries_service_1.TimeSeriesService(this.httpClient);
57
- this.users = new user_service_1.UserService(this.httpClient);
58
- this.vault = new vault_service_1.VaultService(this.httpClient);
59
- this.notifications = new notification_service_1.NotificationService(this.httpClient);
60
- }
61
- }
62
- exports.API = API;
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssetTypesService = void 0;
4
- const tslib_1 = require("tslib");
5
- const ts_mixer_1 = require("ts-mixer");
6
- const api_base_1 = require("./api-base");
7
- const data_service_1 = require("./data.service");
8
- const trash_service_1 = require("./trash.service");
9
- let BaseService = class BaseService extends api_base_1.APIBase {
10
- };
11
- BaseService = tslib_1.__decorate([
12
- (0, ts_mixer_1.mix)(data_service_1.DataService, trash_service_1.TrashService)
13
- ], BaseService);
14
- class AssetTypesService extends BaseService {
15
- constructor(httpClient) {
16
- super(httpClient, '/assettypes');
17
- }
18
- getRevisions(id, options = {}) {
19
- return this.httpClient.get(`${this.basePath}/${id}/revisions`, options);
20
- }
21
- rollback(id, revisionId, options = {}) {
22
- return this.httpClient.put(`${this.basePath}/${id}/rollback`, { revisionId }, options);
23
- }
24
- deleteRevision(id, revisionId, options = {}) {
25
- return this.httpClient.delete(`${this.basePath}/${id}/revisions/${revisionId}`, options);
26
- }
27
- }
28
- exports.AssetTypesService = AssetTypesService;
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentService = void 0;
4
- const tslib_1 = require("tslib");
5
- const ts_mixer_1 = require("ts-mixer");
6
- const api_base_1 = require("./api-base");
7
- const content_interface_1 = require("./content.interface");
8
- const data_service_1 = require("./data.service");
9
- const trash_service_1 = require("./trash.service");
10
- let BaseService = class BaseService extends api_base_1.APIBase {
11
- };
12
- BaseService = tslib_1.__decorate([
13
- (0, ts_mixer_1.mix)(data_service_1.DataService, trash_service_1.TrashService)
14
- ], BaseService);
15
- class ContentService extends BaseService {
16
- constructor(httpClient) {
17
- super(httpClient, '/contents');
18
- this.upload = (form, options = {}) => {
19
- const headers = Object.assign({}, form.getHeaders());
20
- return this.httpClient.post(`${this.basePath}`, form, Object.assign({ headers, maxBodyLength: Infinity, maxContentLength: Infinity }, options));
21
- };
22
- }
23
- download(id_1, second_1) {
24
- return tslib_1.__awaiter(this, arguments, void 0, function* (id, second, options = {}) {
25
- let returnType;
26
- if (typeof second === 'boolean' || second == null) {
27
- returnType = second ? content_interface_1.ReturnType.ARRAYBUFFER : content_interface_1.ReturnType.BLOB;
28
- }
29
- else {
30
- returnType = second;
31
- }
32
- const url = `${this.basePath}/${id}/download`;
33
- switch (returnType) {
34
- case content_interface_1.ReturnType.TEXT:
35
- return this.httpClient.get(url, Object.assign({ responseType: 'text' }, options));
36
- case content_interface_1.ReturnType.JSON:
37
- return this.httpClient.get(url, Object.assign({ responseType: 'json' }, options));
38
- case content_interface_1.ReturnType.NODEBUFFER:
39
- return Buffer.from(new Uint8Array(yield this.httpClient.get(url, Object.assign({ responseType: 'arraybuffer' }, options))));
40
- case content_interface_1.ReturnType.BLOB:
41
- return this.httpClient.get(url, Object.assign({ responseType: 'blob' }, options));
42
- case content_interface_1.ReturnType.ARRAYBUFFER:
43
- return this.httpClient.get(url, Object.assign({ responseType: 'arraybuffer' }, options));
44
- case content_interface_1.ReturnType.NODESTREAM:
45
- return this.httpClient.get(url, Object.assign({ responseType: 'stream' }, options));
46
- }
47
- });
48
- }
49
- }
50
- exports.ContentService = ContentService;
@@ -1,6 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.instanceOfTimePeriod = instanceOfTimePeriod;
4
- function instanceOfTimePeriod(object) {
5
- return 'from' in object && 'to' in object;
6
- }