@hahnpro/flow-sdk 5.0.0-0 → 5.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 (98) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/FlowApplication.d.ts +53 -14
  4. package/dist/FlowApplication.js +266 -85
  5. package/dist/FlowElement.d.ts +12 -4
  6. package/dist/FlowElement.js +47 -48
  7. package/dist/FlowEvent.d.ts +7 -1
  8. package/dist/FlowEvent.js +5 -5
  9. package/dist/FlowLogger.d.ts +9 -6
  10. package/dist/FlowLogger.js +17 -18
  11. package/dist/FlowModule.d.ts +1 -1
  12. package/dist/FlowModule.js +3 -3
  13. package/dist/RpcClient.d.ts +5 -3
  14. package/dist/RpcClient.js +23 -9
  15. package/dist/TestModule.js +6 -6
  16. package/dist/amqp.d.ts +14 -0
  17. package/dist/amqp.js +13 -0
  18. package/dist/extra-validators.js +15 -8
  19. package/dist/flow.interface.d.ts +7 -1
  20. package/dist/flow.interface.js +7 -0
  21. package/dist/index.d.ts +2 -1
  22. package/dist/index.js +2 -1
  23. package/dist/rpc_server.py +89 -77
  24. package/dist/unit-decorators.d.ts +39 -0
  25. package/dist/unit-decorators.js +157 -0
  26. package/dist/unit-utils.d.ts +8 -0
  27. package/dist/unit-utils.js +144 -0
  28. package/dist/units.d.ts +31 -0
  29. package/dist/units.js +570 -0
  30. package/dist/utils.d.ts +5 -1
  31. package/dist/utils.js +40 -7
  32. package/package.json +35 -33
  33. package/dist/api/Queue.d.ts +0 -15
  34. package/dist/api/Queue.js +0 -25
  35. package/dist/api/api.d.ts +0 -22
  36. package/dist/api/api.interface.d.ts +0 -14
  37. package/dist/api/api.interface.js +0 -2
  38. package/dist/api/api.js +0 -38
  39. package/dist/api/asset.interface.d.ts +0 -45
  40. package/dist/api/asset.interface.js +0 -2
  41. package/dist/api/asset.service.d.ts +0 -8
  42. package/dist/api/asset.service.js +0 -18
  43. package/dist/api/content.interface.d.ts +0 -33
  44. package/dist/api/content.interface.js +0 -2
  45. package/dist/api/content.service.d.ts +0 -9
  46. package/dist/api/content.service.js +0 -22
  47. package/dist/api/data.interface.d.ts +0 -29
  48. package/dist/api/data.interface.js +0 -2
  49. package/dist/api/data.service.d.ts +0 -15
  50. package/dist/api/data.service.js +0 -50
  51. package/dist/api/endpoint.interface.d.ts +0 -18
  52. package/dist/api/endpoint.interface.js +0 -2
  53. package/dist/api/endpoint.service.d.ts +0 -7
  54. package/dist/api/endpoint.service.js +0 -14
  55. package/dist/api/http.service.d.ts +0 -29
  56. package/dist/api/http.service.js +0 -96
  57. package/dist/api/index.d.ts +0 -11
  58. package/dist/api/index.js +0 -15
  59. package/dist/api/mock/api.mock.d.ts +0 -102
  60. package/dist/api/mock/api.mock.js +0 -81
  61. package/dist/api/mock/asset.mock.service.d.ts +0 -9
  62. package/dist/api/mock/asset.mock.service.js +0 -18
  63. package/dist/api/mock/content.mock.service.d.ts +0 -9
  64. package/dist/api/mock/content.mock.service.js +0 -21
  65. package/dist/api/mock/data.mock.service.d.ts +0 -11
  66. package/dist/api/mock/data.mock.service.js +0 -53
  67. package/dist/api/mock/endpoint.mock.service.d.ts +0 -10
  68. package/dist/api/mock/endpoint.mock.service.js +0 -15
  69. package/dist/api/mock/index.d.ts +0 -7
  70. package/dist/api/mock/index.js +0 -10
  71. package/dist/api/mock/secret.mock.service.d.ts +0 -5
  72. package/dist/api/mock/secret.mock.service.js +0 -11
  73. package/dist/api/mock/task.mock.service.d.ts +0 -8
  74. package/dist/api/mock/task.mock.service.js +0 -16
  75. package/dist/api/mock/timeseries.mock.service.d.ts +0 -18
  76. package/dist/api/mock/timeseries.mock.service.js +0 -70
  77. package/dist/api/mock/user.mock.service.d.ts +0 -7
  78. package/dist/api/mock/user.mock.service.js +0 -12
  79. package/dist/api/secret.interface.d.ts +0 -9
  80. package/dist/api/secret.interface.js +0 -2
  81. package/dist/api/secret.service.d.ts +0 -6
  82. package/dist/api/secret.service.js +0 -10
  83. package/dist/api/sidriveiq.interface.d.ts +0 -104
  84. package/dist/api/sidriveiq.interface.js +0 -2
  85. package/dist/api/sidriveiq.service.d.ts +0 -31
  86. package/dist/api/sidriveiq.service.js +0 -97
  87. package/dist/api/task.interface.d.ts +0 -26
  88. package/dist/api/task.interface.js +0 -2
  89. package/dist/api/task.service.d.ts +0 -7
  90. package/dist/api/task.service.js +0 -13
  91. package/dist/api/timeseries.interface.d.ts +0 -51
  92. package/dist/api/timeseries.interface.js +0 -2
  93. package/dist/api/timeseries.service.d.ts +0 -17
  94. package/dist/api/timeseries.service.js +0 -38
  95. package/dist/api/user.interface.d.ts +0 -3
  96. package/dist/api/user.interface.js +0 -2
  97. package/dist/api/user.service.d.ts +0 -7
  98. package/dist/api/user.service.js +0 -21
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/flow-sdk",
3
- "version": "5.0.0-0",
3
+ "version": "5.0.0",
4
4
  "description": "SDK for building Flow Modules",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "repository": {
11
11
  "type": "git",
12
- "url": "git@gitlab.com:hahnpro/flow.git"
12
+ "url": "git@github.com:hahnprojects/flow.git"
13
13
  },
14
14
  "directories": {
15
15
  "lib": "lib",
@@ -23,41 +23,43 @@
23
23
  "publishConfig": {
24
24
  "access": "public"
25
25
  },
26
- "scripts": {
27
- "build": "../../node_modules/.bin/tsc -p tsconfig.lib.json",
28
- "postbuild": "../../node_modules/.bin/copyfiles -u 1 lib/*.py dist",
29
- "prepublishOnly": "yarn build"
30
- },
31
26
  "dependencies": {
32
- "@golevelup/nestjs-rabbitmq": "^1.16.0",
33
- "amqp-connection-manager": "^3.2.1",
34
- "amqplib": "^0.6.0",
35
- "axios": "^0.21.1",
36
- "class-transformer": "0.3.1",
37
- "class-validator": "~0.12.2",
38
- "cloudevents": "^4.0.0",
39
- "eventemitter3": "^4.0.7",
40
- "form-data": "^3.0.0",
41
- "jwt-decode": "^3.1.2",
42
- "lodash": "^4.17.20",
43
- "object-sizeof": "^1.6.1",
44
- "p-queue": "^6.6.2",
45
- "python-shell": "^2.0.3",
46
- "querystring": "^0.2.0",
27
+ "amqp-connection-manager": "^4.1.14",
28
+ "amqplib": "^0.10.3",
29
+ "class-transformer": "0.5.1",
30
+ "class-validator": "~0.14.0",
31
+ "cloudevents": "^8.0.0",
32
+ "lodash": "^4.17.21",
33
+ "object-sizeof": "~2.6.3",
34
+ "python-shell": "^3.0.1",
47
35
  "reflect-metadata": "^0.1.13",
48
- "rxjs": "^6.6.2",
49
- "string-interp": "^0.3.6"
36
+ "rxjs": "^7.8.1",
37
+ "string-interp": "^0.3.6",
38
+ "@hahnpro/hpc-api": "5.0.0"
50
39
  },
51
40
  "devDependencies": {
52
- "@types/amqp-connection-manager": "^2.0.10",
53
- "@types/amqplib": "^0.5.17",
54
- "@types/jest": "^26.0.20",
55
- "@types/lodash": "^4.14.168",
56
- "@types/node": "14.14.20",
57
- "jest": "^26.6.3",
58
- "typescript": "^4.1.3"
41
+ "@types/amqplib": "^0.10.3",
42
+ "@types/jest": "^29.5.7",
43
+ "@types/lodash": "^4.14.200",
44
+ "@types/node": "^20.8.10",
45
+ "class-validator-jsonschema": "^5.0.0",
46
+ "jest": "^29.7.0",
47
+ "typescript": "^5.2.2"
48
+ },
49
+ "peerDependencies": {
50
+ "axios": "1.x",
51
+ "class-transformer": "^0.5.1",
52
+ "class-validator": "^0.14.0",
53
+ "lodash": "4.x",
54
+ "python-shell": "3.x"
59
55
  },
60
56
  "engines": {
61
- "node": ">=14"
57
+ "node": ">=v18"
58
+ },
59
+ "scripts": {
60
+ "build": "../../node_modules/.bin/tsc -p tsconfig.lib.json",
61
+ "build:nocomments": "../../node_modules/.bin/tsc -p tsconfig.nocomments.json",
62
+ "postbuild": "../../node_modules/.bin/copyfiles -u 1 lib/*.py dist",
63
+ "lint": "eslint '*/**/*.{js,ts}'"
62
64
  }
63
- }
65
+ }
@@ -1,15 +0,0 @@
1
- import PQueue from 'p-queue';
2
- export declare class Queue extends PQueue {
3
- private peak;
4
- private total;
5
- constructor(options?: QueueOptions);
6
- getStats(): {
7
- peak: number;
8
- pending: number;
9
- size: number;
10
- total: number;
11
- };
12
- }
13
- export interface QueueOptions {
14
- concurrent?: number;
15
- }
package/dist/api/Queue.js DELETED
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Queue = void 0;
4
- const tslib_1 = require("tslib");
5
- const p_queue_1 = tslib_1.__importDefault(require("p-queue"));
6
- class Queue extends p_queue_1.default {
7
- constructor(options = { concurrent: 1 }) {
8
- super({ concurrency: options.concurrent || 1 });
9
- this.peak = 0;
10
- this.total = 0;
11
- this.on('active', () => {
12
- this.total++;
13
- this.peak = Math.max(this.peak, this.size);
14
- });
15
- }
16
- getStats() {
17
- return {
18
- peak: this.peak,
19
- pending: this.pending,
20
- size: this.size,
21
- total: this.total,
22
- };
23
- }
24
- }
25
- exports.Queue = Queue;
package/dist/api/api.d.ts DELETED
@@ -1,22 +0,0 @@
1
- import { APIInterface } from './api.interface';
2
- import { AssetInterface } from './asset.interface';
3
- import { ContentInterface } from './content.interface';
4
- import { EndpointInterface } from './endpoint.interface';
5
- import { HttpClient } from './http.service';
6
- import { SecretInterface } from './secret.interface';
7
- import { SiDriveIqService } from './sidriveiq.service';
8
- import { TimeseriesInterface } from './timeseries.interface';
9
- import { TaskInterface } from './task.interface';
10
- import { UserService } from './user.service';
11
- export declare class API implements APIInterface {
12
- httpClient: HttpClient;
13
- assetManager: AssetInterface;
14
- contentManager: ContentInterface;
15
- endpointManager: EndpointInterface;
16
- secretsManager: SecretInterface;
17
- siDrive: SiDriveIqService;
18
- timeSeriesManager: TimeseriesInterface;
19
- taskManager: TaskInterface;
20
- userManager: UserService;
21
- constructor();
22
- }
@@ -1,14 +0,0 @@
1
- import { AssetInterface } from './asset.interface';
2
- import { ContentInterface } from './content.interface';
3
- import { SecretInterface } from './secret.interface';
4
- import { TimeseriesInterface } from './timeseries.interface';
5
- import { TaskInterface } from './task.interface';
6
- import { UserInterface } from './user.interface';
7
- export interface APIInterface {
8
- assetManager: AssetInterface;
9
- contentManager: ContentInterface;
10
- secretsManager: SecretInterface;
11
- timeSeriesManager: TimeseriesInterface;
12
- taskManager: TaskInterface;
13
- userManager: UserInterface;
14
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
package/dist/api/api.js DELETED
@@ -1,38 +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 content_service_1 = require("./content.service");
6
- const endpoint_service_1 = require("./endpoint.service");
7
- const http_service_1 = require("./http.service");
8
- const secret_service_1 = require("./secret.service");
9
- const sidriveiq_service_1 = require("./sidriveiq.service");
10
- const timeseries_service_1 = require("./timeseries.service");
11
- const task_service_1 = require("./task.service");
12
- const user_service_1 = require("./user.service");
13
- class API {
14
- constructor() {
15
- let apiBaseUrl = process.env.API_BASE_URL || 'https://testing.hahnpro.com';
16
- if (!apiBaseUrl.startsWith('https') && !apiBaseUrl.startsWith('http')) {
17
- console.info('no protocol specified - using HTTPS');
18
- apiBaseUrl = `https://${apiBaseUrl}`;
19
- }
20
- const authBaseUrl = process.env.AUTH_BASE_URL || apiBaseUrl;
21
- const realm = process.env.AUTH_REALM || 'hpc';
22
- const client = process.env.API_USER || 'flow-executor-service';
23
- const secret = process.env.AUTH_SECRET;
24
- if (!secret) {
25
- throw new Error('"API_BASE_URL", "API_USER", "AUTH_REALM" and "AUTH_SECRET" environment variables must be set');
26
- }
27
- this.httpClient = new http_service_1.HttpClient(apiBaseUrl, authBaseUrl, realm, client, secret);
28
- this.assetManager = new asset_service_1.AssetService(this.httpClient);
29
- this.contentManager = new content_service_1.ContentService(this.httpClient);
30
- this.endpointManager = new endpoint_service_1.EndpointService(this.httpClient);
31
- this.secretsManager = new secret_service_1.SecretService(this.httpClient);
32
- this.siDrive = new sidriveiq_service_1.SiDriveIqService(this.httpClient);
33
- this.timeSeriesManager = new timeseries_service_1.TimeSeriesService(this.httpClient);
34
- this.taskManager = new task_service_1.TaskService(this.httpClient);
35
- this.userManager = new user_service_1.UserService(this.httpClient);
36
- }
37
- }
38
- exports.API = API;
@@ -1,45 +0,0 @@
1
- import FormData from 'form-data';
2
- import { DataInterface } from './data.interface';
3
- export interface Asset {
4
- id?: string;
5
- name: string;
6
- type: string | AssetType;
7
- readPermissions: string[];
8
- readWritePermissions: string[];
9
- tags?: string[];
10
- parent?: any | Asset;
11
- data?: any;
12
- attachments?: string[];
13
- createdAt?: string;
14
- updatedAt?: string;
15
- }
16
- export interface AssetType {
17
- id?: string;
18
- name: string;
19
- allowedParent?: string;
20
- readPermissions: string[];
21
- readWritePermissions: string[];
22
- typeSchema: any;
23
- uiSchema: any;
24
- }
25
- export interface Attachment {
26
- id?: string;
27
- filename: string;
28
- metadata: {
29
- mimetype: string;
30
- };
31
- }
32
- export interface Action {
33
- id?: string;
34
- name?: string;
35
- description?: string;
36
- type?: string;
37
- method?: string;
38
- authToken?: string;
39
- isAuthFromAsset?: boolean;
40
- url?: string;
41
- data?: string;
42
- }
43
- export interface AssetInterface extends DataInterface<Asset> {
44
- addAttachment(id: string, form: FormData): Promise<Asset>;
45
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,8 +0,0 @@
1
- import FormData from 'form-data';
2
- import { Asset, AssetInterface } from './asset.interface';
3
- import { DataService } from './data.service';
4
- import { HttpClient } from './http.service';
5
- export declare class AssetService extends DataService<Asset> implements AssetInterface {
6
- constructor(httpClient: HttpClient);
7
- addAttachment: (id: string, form: FormData) => Promise<Asset>;
8
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AssetService = void 0;
4
- const data_service_1 = require("./data.service");
5
- class AssetService extends data_service_1.DataService {
6
- constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_ASSET_URL || 'api/assets');
8
- this.addAttachment = (id, form) => {
9
- const headers = Object.assign({}, form.getHeaders());
10
- return this.httpClient.post(`${this.basePath}/${id}/attachment`, form, {
11
- headers,
12
- maxBodyLength: Infinity,
13
- maxContentLength: Infinity,
14
- });
15
- };
16
- }
17
- }
18
- exports.AssetService = AssetService;
@@ -1,33 +0,0 @@
1
- import FormData from 'form-data';
2
- import { DataInterface } from './data.interface';
3
- declare type FileType = 'original' | 'preview-sm' | 'preview-md' | 'preview-lg';
4
- declare type StorageProvider = 's3' | 'mongo';
5
- export interface Storage {
6
- id: string;
7
- filename: string;
8
- mimetype: string;
9
- size: number;
10
- createdAt: string;
11
- provider?: StorageProvider;
12
- type?: FileType;
13
- md5?: string;
14
- }
15
- export interface Content {
16
- id?: string;
17
- fileId: string;
18
- filename: string;
19
- mimetype: string;
20
- size: number;
21
- readPermissions: string[];
22
- readWritePermissions: string[];
23
- tags?: string[];
24
- assets?: string[];
25
- files?: Storage[];
26
- createdAt?: string;
27
- updatedAt?: string;
28
- }
29
- export interface ContentInterface extends DataInterface<Content> {
30
- upload(form: FormData): Promise<Content>;
31
- download(id: string, raw?: boolean): Promise<Blob | ArrayBuffer>;
32
- }
33
- export {};
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,9 +0,0 @@
1
- import FormData from 'form-data';
2
- import { Content, ContentInterface } from './content.interface';
3
- import { DataService } from './data.service';
4
- import { HttpClient } from './http.service';
5
- export declare class ContentService extends DataService<Content> implements ContentInterface {
6
- constructor(httpClient: HttpClient);
7
- upload: (form: FormData) => Promise<Content>;
8
- download: (id: string, raw?: boolean) => Promise<Blob | ArrayBuffer>;
9
- }
@@ -1,22 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ContentService = void 0;
4
- const data_service_1 = require("./data.service");
5
- class ContentService extends data_service_1.DataService {
6
- constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_CONTENT_URL || 'api/contents');
8
- this.upload = (form) => {
9
- const headers = Object.assign({}, form.getHeaders());
10
- return this.httpClient.post(`${this.basePath}`, form, { headers, maxBodyLength: Infinity, maxContentLength: Infinity });
11
- };
12
- this.download = (id, raw = false) => {
13
- if (raw) {
14
- return this.httpClient.get(`${this.basePath}/${id}/download`, { responseType: 'arraybuffer' });
15
- }
16
- else {
17
- return this.httpClient.get(`${this.basePath}/${id}/download`, { responseType: 'blob' });
18
- }
19
- };
20
- }
21
- }
22
- exports.ContentService = ContentService;
@@ -1,29 +0,0 @@
1
- export interface Paginated<T> {
2
- docs: T;
3
- total: number;
4
- limit: number;
5
- page?: number;
6
- pages?: number;
7
- offset?: number;
8
- }
9
- export interface RequestParameter {
10
- filter?: string;
11
- limit?: number;
12
- page?: number;
13
- populate?: string;
14
- sort?: string;
15
- }
16
- export interface Filter {
17
- tags?: string[];
18
- type?: string;
19
- parent?: string;
20
- }
21
- export interface DataInterface<T> {
22
- addOne(dto: any): Promise<T>;
23
- addMany(dto: any[]): Promise<T[]>;
24
- getOne(id: string, options?: any): Promise<T>;
25
- getMany(params?: RequestParameter, parentId?: string): Promise<Paginated<T[]>>;
26
- getManyFiltered(filter: Filter, params?: RequestParameter, parentId?: string): Promise<Paginated<T[]>>;
27
- updateOne(id: string, dto: any): Promise<T>;
28
- deleteOne(id: string): Promise<any>;
29
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,15 +0,0 @@
1
- import { DataInterface, Filter, Paginated, RequestParameter } from './data.interface';
2
- import { HttpClient } from './http.service';
3
- export declare class DataService<T> implements DataInterface<T> {
4
- protected readonly httpClient: HttpClient;
5
- protected readonly basePath: any;
6
- constructor(httpClient: HttpClient, basePath: any);
7
- addOne(dto: any): Promise<T>;
8
- addMany(dto: any[]): Promise<T[]>;
9
- getOne(id: string, options?: any): Promise<T>;
10
- getMany(params?: RequestParameter, parentId?: string): Promise<Paginated<T[]>>;
11
- getManyFiltered(filter: Filter, params?: RequestParameter, parentId?: string): Promise<Paginated<T[]>>;
12
- updateOne(id: string, dto: any): Promise<T>;
13
- deleteOne(id: string): Promise<any>;
14
- protected getFilterString(filter: Filter): string;
15
- }
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataService = void 0;
4
- class DataService {
5
- constructor(httpClient, basePath) {
6
- this.httpClient = httpClient;
7
- this.basePath = basePath;
8
- }
9
- addOne(dto) {
10
- return this.httpClient.post(this.basePath, dto);
11
- }
12
- addMany(dto) {
13
- return this.httpClient.post(`${this.basePath}/many`, dto);
14
- }
15
- getOne(id, options = {}) {
16
- const params = options.populate ? { populate: options.populate } : {};
17
- return this.httpClient.get(`${this.basePath}/${id}`, { params });
18
- }
19
- getMany(params = {}, parentId) {
20
- params.limit = params.limit || 0;
21
- params.page = params.page || 1;
22
- parentId = parentId ? '/' + parentId : '';
23
- return this.httpClient.get(`${this.basePath}${parentId}`, { params });
24
- }
25
- getManyFiltered(filter, params = {}, parentId) {
26
- params.filter = this.getFilterString(filter);
27
- return this.getMany(params, parentId);
28
- }
29
- updateOne(id, dto) {
30
- return this.httpClient.put(`${this.basePath}/${id}`, dto);
31
- }
32
- deleteOne(id) {
33
- return this.httpClient.delete(`${this.basePath}/${id}`);
34
- }
35
- getFilterString(filter) {
36
- const { parent, tags, type } = filter;
37
- const filters = [];
38
- if (tags) {
39
- filters.push('tags=@' + tags.join());
40
- }
41
- if (type) {
42
- filters.push('type==' + type);
43
- }
44
- if (parent) {
45
- filters.push('parent==' + parent);
46
- }
47
- return filters.join(';');
48
- }
49
- }
50
- exports.DataService = DataService;
@@ -1,18 +0,0 @@
1
- import { DataInterface } from './data.interface';
2
- export interface Endpoint {
3
- id?: string;
4
- name: string;
5
- description?: string;
6
- status: string;
7
- config: {
8
- type: string;
9
- url?: string;
10
- authToken: string;
11
- recipients?: string[];
12
- };
13
- readPermissions: string[];
14
- readWritePermissions: string[];
15
- }
16
- export interface EndpointInterface extends DataInterface<Endpoint> {
17
- sendNotification(endpointId: string, subject: string, message: string): any;
18
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,7 +0,0 @@
1
- import { HttpClient } from './http.service';
2
- import { DataService } from './data.service';
3
- import { Endpoint, EndpointInterface } from './endpoint.interface';
4
- export declare class EndpointService extends DataService<Endpoint> implements EndpointInterface {
5
- constructor(httpClient: HttpClient);
6
- sendNotification(endpointId: string, subject: string, message: string): Promise<void>;
7
- }
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.EndpointService = void 0;
4
- const data_service_1 = require("./data.service");
5
- class EndpointService extends data_service_1.DataService {
6
- constructor(httpClient) {
7
- super(httpClient, process.env.DEBUG_ENDPOINT_URL || 'api/notification/endpoints');
8
- }
9
- sendNotification(endpointId, subject, message) {
10
- const body = { subject, message };
11
- return this.httpClient.post(`${this.basePath}/${endpointId}`, body);
12
- }
13
- }
14
- exports.EndpointService = EndpointService;
@@ -1,29 +0,0 @@
1
- import { AxiosRequestConfig } from 'axios';
2
- export declare class HttpClient {
3
- private readonly apiBaseUrl;
4
- private readonly authBaseUrl;
5
- private readonly realm;
6
- private readonly client;
7
- private readonly secret;
8
- private readonly axiosInstance;
9
- private readonly authAxiosInstance;
10
- private readonly requestQueue;
11
- private accessToken;
12
- private accessTokenExpiration;
13
- constructor(apiBaseUrl: string, authBaseUrl: string, realm: string, client: string, secret: string);
14
- clone: (newApiBaseUrl?: string) => HttpClient;
15
- getQueueStats: () => {
16
- peak: number;
17
- pending: number;
18
- size: number;
19
- total: number;
20
- };
21
- delete: <T>(url: string, config?: AxiosRequestConfig) => Promise<T>;
22
- get: <T>(url: string, config?: AxiosRequestConfig) => Promise<T>;
23
- post: <T>(url: string, data: any, config?: AxiosRequestConfig) => Promise<T>;
24
- put: <T>(url: string, data: any, config?: AxiosRequestConfig) => Promise<T>;
25
- private request;
26
- getAccessToken: () => Promise<string>;
27
- private isTokenValid;
28
- private getToken;
29
- }
@@ -1,96 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HttpClient = void 0;
4
- const tslib_1 = require("tslib");
5
- const axios_1 = tslib_1.__importDefault(require("axios"));
6
- const querystring_1 = tslib_1.__importDefault(require("querystring"));
7
- const Queue_1 = require("./Queue");
8
- class HttpClient {
9
- constructor(apiBaseUrl, authBaseUrl, realm, client, secret) {
10
- this.apiBaseUrl = apiBaseUrl;
11
- this.authBaseUrl = authBaseUrl;
12
- this.realm = realm;
13
- this.client = client;
14
- this.secret = secret;
15
- this.accessTokenExpiration = 0;
16
- this.clone = (newApiBaseUrl = this.apiBaseUrl) => new HttpClient(newApiBaseUrl, this.authBaseUrl, this.realm, this.client, this.secret);
17
- this.getQueueStats = () => this.requestQueue && this.requestQueue.getStats();
18
- this.delete = (url, config) => this.request('DELETE', url, config);
19
- this.get = (url, config) => this.request('GET', url, config);
20
- this.post = (url, data, config) => this.request('POST', url, config, data);
21
- this.put = (url, data, config) => this.request('PUT', url, config, data);
22
- this.request = (method, url, config, data) => {
23
- return this.requestQueue.add(() => new Promise((resolve, reject) => {
24
- this.axiosInstance
25
- .request(Object.assign(Object.assign({}, config), { method, url, data }))
26
- .then((response) => resolve(response.data))
27
- .catch((err) => reject(err));
28
- }));
29
- };
30
- this.getAccessToken = () => {
31
- return new Promise((resolve, reject) => {
32
- if (this.isTokenValid()) {
33
- resolve(this.accessToken);
34
- }
35
- else {
36
- this.requestQueue.pause();
37
- this.getToken()
38
- .then((t) => {
39
- this.requestQueue.start();
40
- resolve(t);
41
- })
42
- .catch((e) => reject(e));
43
- }
44
- });
45
- };
46
- this.isTokenValid = () => {
47
- if (this.accessToken && this.accessTokenExpiration) {
48
- const buffer = 5000;
49
- return Date.now() + buffer < this.accessTokenExpiration;
50
- }
51
- return false;
52
- };
53
- this.getToken = async () => {
54
- return new Promise((resolve, reject) => {
55
- const params = {
56
- grant_type: 'client_credentials',
57
- client_id: this.client,
58
- client_secret: this.secret,
59
- };
60
- const headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
61
- this.authAxiosInstance
62
- .post(`/auth/realms/${this.realm}/protocol/openid-connect/token`, querystring_1.default.stringify(params), { headers })
63
- .then((res) => {
64
- if (res && res.data && res.data.access_token && res.data.expires_in) {
65
- this.accessToken = res.data.access_token;
66
- this.accessTokenExpiration = Date.now() + res.data.expires_in * 1000;
67
- resolve(res.data.access_token);
68
- }
69
- else {
70
- reject(new Error('Invalid format for access token received'));
71
- }
72
- })
73
- .catch((err) => reject(err));
74
- });
75
- };
76
- authBaseUrl = authBaseUrl || apiBaseUrl;
77
- this.axiosInstance = axios_1.default.create({ baseURL: apiBaseUrl, timeout: 60000 });
78
- this.authAxiosInstance = axios_1.default.create({ baseURL: authBaseUrl, timeout: 10000 });
79
- this.requestQueue = new Queue_1.Queue({ concurrent: 1 });
80
- this.requestQueue.pause();
81
- this.getAccessToken()
82
- .then(() => this.requestQueue.start())
83
- .catch((err) => console.error(err));
84
- this.axiosInstance.interceptors.request.use(async (config = {}) => {
85
- try {
86
- config.headers = config.headers || {};
87
- config.headers.Authorization = `Bearer ${await this.getAccessToken()}`;
88
- return config;
89
- }
90
- catch (err) {
91
- Promise.reject(err);
92
- }
93
- }, (error) => Promise.reject(error));
94
- }
95
- }
96
- exports.HttpClient = HttpClient;
@@ -1,11 +0,0 @@
1
- export * from './api';
2
- export * from './asset.interface';
3
- export * from './content.interface';
4
- export * from './data.interface';
5
- export * from './data.service';
6
- export * from './endpoint.interface';
7
- export * from './secret.interface';
8
- export * from './timeseries.interface';
9
- export * from './task.interface';
10
- export * from './mock';
11
- export * as SiDrive from './sidriveiq.interface';