@hahnpro/hpc-api 1.0.2 → 2.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
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.
@@ -1,34 +1,43 @@
1
- export interface Asset {
1
+ export interface AssetType {
2
2
  id?: string;
3
3
  name: string;
4
- type: string | AssetType;
5
- type$name?: string;
4
+ tags?: string[];
5
+ allowedParents?: string[];
6
+ allowedParent$name?: string;
6
7
  readPermissions: string[];
7
8
  readWritePermissions: string[];
8
- tags?: string[];
9
- parent?: any | Asset;
10
- parent$name?: string;
11
- data?: any;
12
- attachments?: string[];
13
- image?: string;
9
+ supertype?: string;
10
+ supertype$name?: string;
11
+ typeSchema: any;
12
+ uiSchema: any;
14
13
  actions?: string[];
15
- notificationEndpoints?: string[];
16
14
  createdAt?: string;
17
15
  updatedAt?: string;
18
16
  }
19
- export interface AssetType {
17
+ export interface AssetParent {
20
18
  id?: string;
21
19
  name: string;
22
- tags?: string[];
23
- allowedParent?: string;
24
- allowedParent$name?: string;
20
+ type: string | AssetType;
25
21
  readPermissions: string[];
26
22
  readWritePermissions: string[];
27
- typeSchema: any;
28
- supertype?: string;
29
- supertype$name?: string;
30
- uiSchema: any;
23
+ parent?: any | Asset;
24
+ ancestors?: string[];
25
+ tags?: string[];
26
+ relations?: any[];
27
+ data?: any;
28
+ image?: string;
29
+ author?: string;
30
+ revision?: number;
31
+ }
32
+ export interface Asset extends AssetParent {
33
+ type$name?: string;
34
+ parent$name?: string;
35
+ attachments?: string[];
36
+ notificationEndpoints?: string[];
31
37
  actions?: string[];
38
+ }
39
+ export interface AssetRevision extends AssetParent {
40
+ originalId?: string;
32
41
  createdAt?: string;
33
42
  updatedAt?: string;
34
43
  }
@@ -1,5 +1,5 @@
1
1
  import FormData from 'form-data';
2
- import { Asset } from './asset.interface';
2
+ import { Asset, AssetRevision } from './asset.interface';
3
3
  import { Paginated, RequestParameter } from './data.interface';
4
4
  import { DataService } from './data.service';
5
5
  import { HttpClient } from './http.service';
@@ -7,4 +7,5 @@ export declare class AssetService extends DataService<Asset> {
7
7
  constructor(httpClient: HttpClient);
8
8
  addAttachment: (id: string, form: FormData) => Promise<Asset>;
9
9
  getChildren(assetId: string, params?: RequestParameter): Promise<Paginated<Asset[]>>;
10
+ findRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
10
11
  }
@@ -17,5 +17,8 @@ class AssetService extends data_service_1.DataService {
17
17
  getChildren(assetId, params = {}) {
18
18
  return this.getManyFiltered({ parent: assetId }, params);
19
19
  }
20
+ findRevisions(assetId) {
21
+ return this.httpClient.get(`${this.basePath}/${assetId}/revisions`);
22
+ }
20
23
  }
21
24
  exports.AssetService = AssetService;
@@ -9,9 +9,9 @@ export interface Endpoint {
9
9
  authToken: string;
10
10
  recipients?: string[];
11
11
  };
12
- notificationCheck: number;
13
- notificationCount: number;
14
- notificationPause: number;
12
+ notificationCheckInterval: number;
13
+ notificationPauseInterval: number;
14
+ nbOfNotificationsBetweenPauseInterval: number;
15
15
  readPermissions: string[];
16
16
  readWritePermissions: string[];
17
17
  }
@@ -23,3 +23,13 @@ export interface EndpointLog {
23
23
  group?: string;
24
24
  updatedAt?: string;
25
25
  }
26
+ export interface NotificationPayload {
27
+ subject: string;
28
+ message: string;
29
+ group?: string;
30
+ level?: string;
31
+ eventLink?: string;
32
+ assetId?: string;
33
+ assetName?: string;
34
+ assetLink?: string;
35
+ }
@@ -1,8 +1,8 @@
1
1
  import { HttpClient } from './http.service';
2
2
  import { DataService } from './data.service';
3
- import { Endpoint, EndpointLog } from './endpoint.interface';
3
+ import { Endpoint, NotificationPayload, EndpointLog } from './endpoint.interface';
4
4
  export declare class EndpointService extends DataService<Endpoint> {
5
5
  constructor(httpClient: HttpClient);
6
- sendNotification(endpointId: string, subject: string, message: string, group: string, eventLink?: string, assetLink?: string): Promise<void>;
6
+ sendNotification(endpointId: string, payload: NotificationPayload): Promise<void>;
7
7
  readLastLogByGroup(endpointId: string, group: string): Promise<EndpointLog>;
8
8
  }
@@ -6,9 +6,8 @@ class EndpointService extends data_service_1.DataService {
6
6
  constructor(httpClient) {
7
7
  super(httpClient, '/notification/endpoints');
8
8
  }
9
- sendNotification(endpointId, subject, message, group, eventLink, assetLink) {
10
- const body = Object.assign(Object.assign({ subject, message, group }, (eventLink && { eventLink })), (assetLink && { assetLink }));
11
- return this.httpClient.post(`${this.basePath}/${endpointId}`, body);
9
+ sendNotification(endpointId, payload) {
10
+ return this.httpClient.post(`${this.basePath}/${endpointId}`, payload);
12
11
  }
13
12
  readLastLogByGroup(endpointId, group) {
14
13
  return this.httpClient.get(`${this.basePath}/${endpointId}/logs/${group}/last`);
@@ -1,13 +1,17 @@
1
1
  import { API } from '../api';
2
- import { Asset } from '../asset.interface';
3
- import { Storage } from '../content.interface';
4
- import { TimeSeriesValue } from '../timeseries.interface';
2
+ import { Asset, AssetRevision, AssetType } from '../asset.interface';
3
+ import { Content } from '../content.interface';
4
+ import { Secret } from '../secret.interface';
5
+ import { TimeSeries, TimeSeriesValue } from '../timeseries.interface';
5
6
  import { AssetMockService } from './asset.mock.service';
6
7
  import { AssetTypesMockService } from './assetTypes.mock.service';
7
8
  import { ContentMockService } from './content.mock.service';
9
+ import { Endpoint } from '../endpoint.interface';
8
10
  import { EndpointMockService } from './endpoint.mock.service';
11
+ import { Event } from '../events.interface';
9
12
  import { EventsMockService } from './events.mock.service';
10
13
  import { SecretMockService } from './secret.mock.service';
14
+ import { Task } from '../task.interface';
11
15
  import { TimeseriesMockService } from './timeseries.mock.service';
12
16
  import { TaskMockService } from './task.mock.service';
13
17
  import { UserMockService } from './user.mock.service';
@@ -34,6 +38,7 @@ export declare class MockAPI implements API {
34
38
  userManager: UserMockService;
35
39
  constructor(initData: {
36
40
  assets?: AssetInit[];
41
+ revisions: AssetRevisionInit[];
37
42
  contents?: ContentInit[];
38
43
  endpoints?: EndpointInit[];
39
44
  secrets?: SecretInit[];
@@ -43,119 +48,27 @@ export declare class MockAPI implements API {
43
48
  users?: UserInit;
44
49
  });
45
50
  }
46
- export interface AssetInit {
47
- id: string;
48
- name: string;
49
- type: AssetTypeInit | string;
50
- type$name?: string;
51
- readPermissions?: string[];
52
- readWritePermissions?: string[];
53
- notificationEndpoints?: string[];
54
- tags?: string[];
55
- parent?: any | Asset;
56
- parent$name?: string;
57
- data?: any;
58
- actions?: string[];
59
- image?: string;
60
- attachments?: string[];
61
- createdAt?: string;
62
- updatedAt?: string;
63
- }
64
- export interface AssetTypeInit {
65
- id: string;
66
- name: string;
67
- allowedParent?: string;
68
- allowedParent$name?: string;
69
- readPermissions?: string[];
70
- readWritePermissions?: string[];
71
- typeSchema?: any;
72
- uiSchema?: any;
73
- supertype?: string;
74
- supertype$name?: string;
75
- actions?: string[];
76
- }
77
- export interface ContentInit {
78
- id: string;
79
- fileId?: string;
80
- filename: string;
51
+ export declare type Identity<T> = {
52
+ [P in keyof T]: T[P];
53
+ };
54
+ export declare type AtLeast<T, K extends keyof T> = Identity<Partial<T> & Pick<T, K>>;
55
+ export declare type Replace<T, K extends keyof T, TReplace> = Identity<Pick<T, Exclude<keyof T, K>> & {
56
+ [P in K]: TReplace;
57
+ }>;
58
+ export declare type AssetInit = Replace<AtLeast<Asset, 'id' | 'name' | 'type'>, 'type', AssetTypeInit | string>;
59
+ export declare type AssetRevisionInit = Replace<AtLeast<AssetRevision, 'id' | 'name' | 'type'>, 'type', AssetTypeInit | string>;
60
+ export declare type AssetTypeInit = AtLeast<AssetType, 'id' | 'name'>;
61
+ export declare type ContentInit = Identity<AtLeast<Content, 'id' | 'filename'> & {
81
62
  filePath?: string;
82
- mimetype?: string;
83
- size?: number;
84
- readPermissions?: string[];
85
- readWritePermissions?: string[];
86
- tags?: string[];
87
- assets?: string[];
88
- files?: Storage[];
89
- createdAt?: string;
90
- updatedAt?: string;
91
63
  data?: any;
92
- }
93
- export interface EndpointInit {
94
- id?: string;
95
- name: string;
96
- description?: string;
97
- status?: string;
98
- config?: {
99
- type: string;
100
- url?: string;
101
- authToken: string;
102
- recipients?: string[];
103
- };
104
- notificationCheck?: number;
105
- notificationCount?: number;
106
- notificationPause?: number;
107
- readPermissions?: string[];
108
- readWritePermissions?: string[];
109
- }
110
- export interface SecretInit {
111
- id?: string;
112
- name: string;
113
- key: string;
114
- readPermissions?: string[];
115
- readWritePermissions?: string[];
116
- }
117
- export interface TimeSeriesInit {
118
- id: string;
119
- name: string;
120
- assetRef?: string;
121
- assetRef$name?: string;
122
- assetTsId?: string;
123
- minDate?: Date;
124
- tsRef?: [string];
125
- metrics?: string[];
64
+ }>;
65
+ export declare type EndpointInit = AtLeast<Endpoint, 'name'>;
66
+ export declare type SecretInit = AtLeast<Secret, 'name' | 'key'>;
67
+ export declare type TimeSeriesInit = Identity<AtLeast<TimeSeries, 'id' | 'name'> & {
126
68
  values: TimeSeriesValue[];
127
- readPermissions?: string[];
128
- readWritePermissions?: string[];
129
- }
130
- export interface TaskInit {
131
- id?: string;
132
- name: string;
133
- readPermissions?: string[];
134
- readWritePermissions?: string[];
135
- assetRef?: string;
136
- assetRef$name?: string;
137
- subTasks?: string[];
138
- assignedTo: string[];
139
- status?: string;
140
- acceptedBy?: string;
141
- }
142
- export interface EventInit {
143
- id?: string;
144
- name: string;
145
- tags?: string[];
146
- readPermissions?: string[];
147
- readWritePermissions?: string[];
148
- assetRef?: string;
149
- assetRef$name?: string;
150
- alertRef?: string;
151
- alertRef$name?: string;
152
- tsRef?: string;
153
- tsRef$name?: string;
154
- eventRef?: string;
155
- cause?: string;
156
- level?: string;
157
- group?: string;
158
- }
69
+ }>;
70
+ export declare type TaskInit = AtLeast<Task, 'name' | 'assignedTo'>;
71
+ export declare type EventInit = AtLeast<Event, 'name'>;
159
72
  export interface UserInit {
160
73
  roles: string[];
161
74
  }
@@ -16,7 +16,7 @@ class MockAPI {
16
16
  this.httpClient = null;
17
17
  this.proxy = null;
18
18
  this.siDrive = null;
19
- const { assets = [], contents = [], endpoints = [], secrets = [], timeSeries = [], tasks = [], events = [], users } = initData;
19
+ const { assets = [], revisions = [], contents = [], endpoints = [], secrets = [], timeSeries = [], tasks = [], events = [], users, } = initData;
20
20
  const assetTypes = assets
21
21
  .map((v) => v.type)
22
22
  .map((v) => {
@@ -32,6 +32,7 @@ class MockAPI {
32
32
  };
33
33
  });
34
34
  const assets1 = assets.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
35
+ const revisions1 = revisions.map((v, index) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], type: assetTypes[index] })));
35
36
  const contents1 = contents.map((v) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [], size: 0, fileId: '', mimetype: v.mimetype || '' })));
36
37
  const contentData = contents.map((v) => {
37
38
  return v.data ? v.data : (0, fs_1.readFileSync)((0, path_1.join)(v.filePath, v.filename));
@@ -58,9 +59,9 @@ class MockAPI {
58
59
  description: value.description,
59
60
  status: value.status,
60
61
  config: value.config,
61
- notificationCheck: value.notificationCheck,
62
- notificationCount: value.notificationCount,
63
- notificationPause: value.notificationPause,
62
+ notificationCheckInterval: value.notificationCheckInterval,
63
+ notificationPauseInterval: value.notificationPauseInterval,
64
+ nbOfNotificationsBetweenPauseInterval: value.nbOfNotificationsBetweenPauseInterval,
64
65
  readPermissions: [],
65
66
  readWritePermissions: [],
66
67
  }));
@@ -70,7 +71,6 @@ class MockAPI {
70
71
  readPermissions: [],
71
72
  readWritePermissions: [],
72
73
  assetRef: v.assetRef,
73
- assetRef$name: v.assetRef$name,
74
74
  subTasks: [],
75
75
  assignedTo: v.assignedTo,
76
76
  status: v.status,
@@ -84,16 +84,14 @@ class MockAPI {
84
84
  assetRef: v.assetRef,
85
85
  assetRef$name: v.assetRef$name,
86
86
  alertRef: v.alertRef,
87
- alertRef$name: v.alertRef$name,
88
87
  tsRef: v.tsRef,
89
- tsRef$name: v.tsRef$name,
90
88
  tags: v.tags,
91
89
  cause: v.cause,
92
90
  level: v.level,
93
91
  group: v.group,
94
92
  }));
95
93
  const timeseriesValues = timeSeries.map((v) => v.values);
96
- this.assets = new asset_mock_service_1.AssetMockService(this, assets1);
94
+ this.assets = new asset_mock_service_1.AssetMockService(this, assets1, revisions1);
97
95
  this.contents = new content_mock_service_1.ContentMockService(contents1, contentData);
98
96
  this.endpoints = new endpoint_mock_service_1.EndpointMockService(endpoint1);
99
97
  this.secrets = new secret_mock_service_1.SecretMockService(secrets1);
@@ -1,12 +1,14 @@
1
1
  import FormData from 'form-data';
2
- import { Asset } from '../asset.interface';
2
+ import { Asset, AssetRevision } from '../asset.interface';
3
3
  import { AssetService } from '../asset.service';
4
4
  import { Paginated, RequestParameter } from '../data.interface';
5
5
  import { MockAPI } from './api.mock';
6
6
  import { DataMockService } from './data.mock.service';
7
7
  export declare class AssetMockService extends DataMockService<Asset> implements AssetService {
8
8
  private api;
9
- constructor(api: MockAPI, assets: Asset[]);
9
+ private revisions;
10
+ constructor(api: MockAPI, assets: Asset[], revisions: AssetRevision[]);
10
11
  addAttachment(id: string, form: FormData): Promise<Asset>;
11
12
  getChildren(assetId: string, params?: RequestParameter): Promise<Paginated<Asset[]>>;
13
+ findRevisions(assetId: string): Promise<Paginated<AssetRevision[]>>;
12
14
  }
@@ -3,10 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AssetMockService = void 0;
4
4
  const data_mock_service_1 = require("./data.mock.service");
5
5
  class AssetMockService extends data_mock_service_1.DataMockService {
6
- constructor(api, assets) {
6
+ constructor(api, assets, revisions) {
7
7
  super();
8
8
  this.api = api;
9
+ this.revisions = [];
9
10
  this.data = assets;
11
+ this.revisions = revisions;
10
12
  }
11
13
  async addAttachment(id, form) {
12
14
  const asset = this.data.find((v) => v.id === id);
@@ -17,5 +19,14 @@ class AssetMockService extends data_mock_service_1.DataMockService {
17
19
  getChildren(assetId, params = {}) {
18
20
  return this.getManyFiltered({ parent: assetId }, params);
19
21
  }
22
+ findRevisions(assetId) {
23
+ const newData = this.revisions.filter((revision) => revision.originalId === assetId);
24
+ const page = {
25
+ docs: newData,
26
+ limit: Number.MAX_SAFE_INTEGER,
27
+ total: newData.length,
28
+ };
29
+ return Promise.resolve(page);
30
+ }
20
31
  }
21
32
  exports.AssetMockService = AssetMockService;
@@ -1,9 +1,9 @@
1
- import { Endpoint } from '../endpoint.interface';
1
+ import { Endpoint, NotificationPayload } from '../endpoint.interface';
2
2
  import { EndpointService } from '../endpoint.service';
3
3
  import { DataMockService } from './data.mock.service';
4
4
  export declare class EndpointMockService extends DataMockService<Endpoint> implements EndpointService {
5
5
  constructor(endpoints: Endpoint[]);
6
- sendNotification(endpointId: string, subject: string, message: string, group: string, eventLink?: string, assetLink?: string): Promise<void>;
6
+ sendNotification(endpointId: string, payload: NotificationPayload): Promise<void>;
7
7
  readLastLogByGroup(endpointId: string, group: string): Promise<{
8
8
  id: string;
9
9
  endpoint: string;
@@ -7,7 +7,7 @@ class EndpointMockService extends data_mock_service_1.DataMockService {
7
7
  super();
8
8
  this.data = endpoints;
9
9
  }
10
- sendNotification(endpointId, subject, message, group, eventLink, assetLink) {
10
+ sendNotification(endpointId, payload) {
11
11
  return Promise.resolve();
12
12
  }
13
13
  readLastLogByGroup(endpointId, group) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/hpc-api",
3
- "version": "1.0.2",
3
+ "version": "2.1.0",
4
4
  "description": "Module for easy access to the HahnPRO API",
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",
@@ -24,7 +24,7 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "axios": "^0.23.0",
27
+ "axios": "^0.25.0",
28
28
  "form-data": "^4.0.0",
29
29
  "jwt-decode": "^3.1.2",
30
30
  "p-queue": "^6.6.2"