@hahnpro/hpc-api 3.7.0 → 3.8.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/dist/api.d.ts CHANGED
@@ -16,6 +16,7 @@ import { FlowModuleService } from './flow-module.service';
16
16
  import { FlowDeploymentService } from './flow-deployment.service';
17
17
  import { LabelService } from './label.service';
18
18
  import { VaultService } from './vault.service';
19
+ import { NotificationService } from './notification.service';
19
20
  export declare class API {
20
21
  httpClient: HttpClient;
21
22
  assets: AssetService;
@@ -34,6 +35,7 @@ export declare class API {
34
35
  timeSeries: TimeSeriesService;
35
36
  users: UserService;
36
37
  vault: VaultService;
38
+ notifications: NotificationService;
37
39
  /**
38
40
  * @deprecated use "assets" instead
39
41
  */
package/dist/api.js CHANGED
@@ -19,6 +19,7 @@ const flow_module_service_1 = require("./flow-module.service");
19
19
  const flow_deployment_service_1 = require("./flow-deployment.service");
20
20
  const label_service_1 = require("./label.service");
21
21
  const vault_service_1 = require("./vault.service");
22
+ const notification_service_1 = require("./notification.service");
22
23
  class API {
23
24
  constructor() {
24
25
  const normalizePath = (value = '', defaultValue = '') => value.replace(/(?:^\/+)|(?:\/+$)/g, '') || defaultValue;
@@ -53,6 +54,7 @@ class API {
53
54
  this.timeSeries = new timeseries_service_1.TimeSeriesService(this.httpClient);
54
55
  this.users = new user_service_1.UserService(this.httpClient);
55
56
  this.vault = new vault_service_1.VaultService(this.httpClient);
57
+ this.notifications = new notification_service_1.NotificationService(this.httpClient);
56
58
  this.assetManager = this.assets;
57
59
  this.contentManager = this.contents;
58
60
  this.endpointManager = this.endpoints;
@@ -30,7 +30,7 @@ export declare class HttpClient {
30
30
  addEventSource(url: string, listener: (event: MessageEvent) => void, errorListener?: (event: MessageEvent) => void): Promise<any>;
31
31
  destroyEventSource(id: string): void;
32
32
  destroyAllEventSources(): void;
33
- getAccessToken: () => Promise<string>;
33
+ getAccessToken: (forceRefresh?: boolean) => Promise<string>;
34
34
  private validateIssuer;
35
35
  private discoverIssuer;
36
36
  private requestAccessToken;
@@ -9,7 +9,6 @@ const jose_1 = require("jose");
9
9
  const Queue_1 = require("./Queue");
10
10
  const token_set_1 = require("./token-set");
11
11
  const querystring_1 = require("querystring");
12
- const TOKEN_EXPIRATION_BUFFER = 30;
13
12
  class HttpClient {
14
13
  constructor(baseURL, authBaseURL, realm, clientId, clientSecret) {
15
14
  this.baseURL = baseURL;
@@ -34,11 +33,11 @@ class HttpClient {
34
33
  .catch(reject);
35
34
  }));
36
35
  };
37
- this.getAccessToken = async () => {
38
- if (!this.tokenSet || this.tokenSet.expired() || this.tokenSet.expiresAt < Date.now() / 1000 + TOKEN_EXPIRATION_BUFFER) {
36
+ this.getAccessToken = async (forceRefresh = false) => {
37
+ if (forceRefresh || !this.tokenSet || this.tokenSet.isExpired()) {
39
38
  return this.requestAccessToken();
40
39
  }
41
- return this.tokenSet.access_token;
40
+ return this.tokenSet.accessToken;
42
41
  };
43
42
  this.axiosInstance = axios_1.default.create({ baseURL, timeout: 60000 });
44
43
  this.authAxiosInstance = axios_1.default.create({ baseURL: authBaseURL || baseURL, timeout: 10000 });
package/dist/index.d.ts CHANGED
@@ -17,4 +17,5 @@ export * from './flow.interface';
17
17
  export * from './resource.interface';
18
18
  export * from './schema.interface';
19
19
  export * from './vault.interface';
20
+ export * from './notification.interface';
20
21
  export * as SiDrive from './sidriveiq.interface';
package/dist/index.js CHANGED
@@ -21,4 +21,5 @@ tslib_1.__exportStar(require("./flow.interface"), exports);
21
21
  tslib_1.__exportStar(require("./resource.interface"), exports);
22
22
  tslib_1.__exportStar(require("./schema.interface"), exports);
23
23
  tslib_1.__exportStar(require("./vault.interface"), exports);
24
+ tslib_1.__exportStar(require("./notification.interface"), exports);
24
25
  exports.SiDrive = tslib_1.__importStar(require("./sidriveiq.interface"));
@@ -28,6 +28,8 @@ import { LabelMockService } from './label.mock.service';
28
28
  import { Label } from '../label.interface';
29
29
  import { VaultSecret } from '../vault.interface';
30
30
  import { VaultMockService } from './vault.mock.service';
31
+ import { Notification } from '../notification.interface';
32
+ import { NotificationMockService } from './notification.mock.service';
31
33
  export declare class MockAPI implements API {
32
34
  httpClient: any;
33
35
  assets: AssetMockService;
@@ -46,6 +48,7 @@ export declare class MockAPI implements API {
46
48
  timeSeries: TimeseriesMockService;
47
49
  users: UserMockService;
48
50
  vault: VaultMockService;
51
+ notifications: NotificationMockService;
49
52
  assetManager: AssetMockService;
50
53
  contentManager: ContentMockService;
51
54
  endpointManager: EndpointMockService;
@@ -74,6 +77,7 @@ export declare class MockAPI implements API {
74
77
  diagrams?: FlowDiagramInit[];
75
78
  labels?: LabelInit[];
76
79
  vault?: VaultSecretInit[];
80
+ notifications?: NotificationInit[];
77
81
  });
78
82
  }
79
83
  export type Identity<T> = {
@@ -109,6 +113,7 @@ export type ArtifactInit = AtLeast<Artifact & {
109
113
  export type FlowDiagramInit = AtLeast<FlowDiagram, 'id' | 'flow'>;
110
114
  export type LabelInit = AtLeast<Label, 'id' | 'name'>;
111
115
  export type VaultSecretInit = AtLeast<VaultSecret, 'name' | 'secret'>;
116
+ export type NotificationInit = AtLeast<Notification, 'id' | 'name' | 'userId' | 'notificationType'>;
112
117
  export interface UserInit {
113
118
  roles: string[];
114
119
  }
@@ -18,12 +18,13 @@ const flow_modules_mock_service_1 = require("./flow-modules.mock.service");
18
18
  const crypto_1 = require("crypto");
19
19
  const label_mock_service_1 = require("./label.mock.service");
20
20
  const vault_mock_service_1 = require("./vault.mock.service");
21
+ const notification_mock_service_1 = require("./notification.mock.service");
21
22
  class MockAPI {
22
23
  constructor(initData) {
23
24
  this.httpClient = null;
24
25
  this.proxy = null;
25
26
  this.siDrive = null;
26
- const { assets = [], assetRevisions = [], contents = [], endpoints = [], secrets = [], timeSeries = [], tasks = [], events = [], users, flows = [], flowRevisions = [], deployments = [], functions = [], functionRevisions = [], modules = [], diagrams = [], labels = [], vault = [], } = initData;
27
+ const { assets = [], assetRevisions = [], contents = [], endpoints = [], secrets = [], timeSeries = [], tasks = [], events = [], users, flows = [], flowRevisions = [], deployments = [], functions = [], functionRevisions = [], modules = [], diagrams = [], labels = [], vault = [], notifications = [], } = initData;
27
28
  const assetTypes = assets
28
29
  .map((v) => v.type)
29
30
  .map((v) => {
@@ -113,6 +114,7 @@ class MockAPI {
113
114
  });
114
115
  const labels1 = labels.map((label) => (Object.assign(Object.assign({}, label), { color: '', description: '', readPermissions: [], readWritePermissions: [] })));
115
116
  const vaultSecrets1 = vault.map((v) => (Object.assign(Object.assign({}, v), { readPermissions: [], readWritePermissions: [] })));
117
+ const notifications1 = notifications.map((n) => (Object.assign(Object.assign({}, n), { link: '', description: '', read: false })));
116
118
  this.assets = new asset_mock_service_1.AssetMockService(this, assets1, assetRevisions1);
117
119
  this.contents = new content_mock_service_1.ContentMockService(contents1, contentData);
118
120
  this.endpoints = new endpoint_mock_service_1.EndpointMockService(endpoint1);
@@ -127,6 +129,7 @@ class MockAPI {
127
129
  this.flowModules = new flow_modules_mock_service_1.FlowModulesMockService(modules1);
128
130
  this.labels = new label_mock_service_1.LabelMockService(labels1);
129
131
  this.vault = new vault_mock_service_1.VaultMockService(vaultSecrets1);
132
+ this.notifications = new notification_mock_service_1.NotificationMockService(notifications1);
130
133
  this.assetManager = this.assets;
131
134
  this.contentManager = this.contents;
132
135
  this.endpointManager = this.endpoints;
@@ -8,3 +8,4 @@ export * from './timeseries.mock.service';
8
8
  export * from './task.mock.service';
9
9
  export * from './events.mock.service';
10
10
  export * from './vault.mock.service';
11
+ export * from './notification.mock.service';
@@ -11,3 +11,4 @@ tslib_1.__exportStar(require("./timeseries.mock.service"), exports);
11
11
  tslib_1.__exportStar(require("./task.mock.service"), exports);
12
12
  tslib_1.__exportStar(require("./events.mock.service"), exports);
13
13
  tslib_1.__exportStar(require("./vault.mock.service"), exports);
14
+ tslib_1.__exportStar(require("./notification.mock.service"), exports);
@@ -0,0 +1,6 @@
1
+ import { DataMockService } from './data.mock.service';
2
+ import { Notification } from '../notification.interface';
3
+ import { NotificationService } from '../notification.service';
4
+ export declare class NotificationMockService extends DataMockService<Notification> implements NotificationService {
5
+ constructor(notifications: Notification[]);
6
+ }
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotificationMockService = void 0;
4
+ const data_mock_service_1 = require("./data.mock.service");
5
+ class NotificationMockService extends data_mock_service_1.DataMockService {
6
+ constructor(notifications) {
7
+ super();
8
+ this.data = notifications;
9
+ }
10
+ }
11
+ exports.NotificationMockService = NotificationMockService;
@@ -0,0 +1,10 @@
1
+ export type NotificationType = 'INFO' | 'WARNING' | 'CRITICAL';
2
+ export interface Notification {
3
+ id?: string;
4
+ name: string;
5
+ description: string;
6
+ userId: string;
7
+ read?: boolean;
8
+ link: string;
9
+ notificationType: NotificationType;
10
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,6 @@
1
+ import { DataService } from './data.service';
2
+ import { Notification } from './notification.interface';
3
+ import { HttpClient } from './http.service';
4
+ export declare class NotificationService extends DataService<Notification> {
5
+ constructor(httpClient: HttpClient);
6
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NotificationService = void 0;
4
+ const data_service_1 = require("./data.service");
5
+ class NotificationService extends data_service_1.DataService {
6
+ constructor(httpClient) {
7
+ super(httpClient, '/notifications');
8
+ }
9
+ }
10
+ exports.NotificationService = NotificationService;
@@ -1,8 +1,9 @@
1
1
  export declare class TokenSet {
2
- expiresAt: number;
3
- access_token: string;
2
+ private readonly _accessToken;
3
+ private readonly _expiresAt;
4
4
  constructor(access_token: string, expires_in: number);
5
- set expires_in(value: number);
6
- get expires_in(): number;
7
- expired(): boolean;
5
+ get accessToken(): string;
6
+ get expiresAt(): number;
7
+ get expiresIn(): number;
8
+ isExpired(): boolean;
8
9
  }
package/dist/token-set.js CHANGED
@@ -1,19 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TokenSet = void 0;
4
+ const TOKEN_EXPIRATION_BUFFER = 20;
4
5
  class TokenSet {
5
6
  constructor(access_token, expires_in) {
6
- this.expires_in = expires_in;
7
- this.access_token = access_token;
7
+ this._accessToken = access_token;
8
+ this._expiresAt = Math.floor(Date.now() / 1000) + Number(expires_in);
8
9
  }
9
- set expires_in(value) {
10
- this.expiresAt = Date.now() + Number(value);
10
+ get accessToken() {
11
+ return this._accessToken;
11
12
  }
12
- get expires_in() {
13
- return Math.max(this.expiresAt - Date.now(), 0);
13
+ get expiresAt() {
14
+ return this._expiresAt;
14
15
  }
15
- expired() {
16
- return this.expires_in === 0;
16
+ get expiresIn() {
17
+ return Math.max(this.expiresAt - Math.ceil(Date.now() / 1000), 0);
18
+ }
19
+ isExpired() {
20
+ return this.expiresIn <= TOKEN_EXPIRATION_BUFFER;
17
21
  }
18
22
  }
19
23
  exports.TokenSet = TokenSet;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/hpc-api",
3
- "version": "3.7.0",
3
+ "version": "3.8.0",
4
4
  "description": "Module for easy access to the HahnPRO API",
5
5
  "license": "MIT",
6
6
  "author": {
@@ -24,10 +24,10 @@
24
24
  "access": "public"
25
25
  },
26
26
  "dependencies": {
27
- "axios": "~1.3.3",
27
+ "axios": "~1.3.5",
28
28
  "eventsource": "^2.0.2",
29
29
  "form-data": "^4.0.0",
30
- "jose": "^4.12.0",
30
+ "jose": "^4.13.1",
31
31
  "jwt-decode": "^3.1.2",
32
32
  "p-queue": "^6.6.2",
33
33
  "ts-mixer": "^6.0.3",
@@ -35,7 +35,7 @@
35
35
  },
36
36
  "devDependencies": {
37
37
  "@types/eventsource": "1.1.10",
38
- "axios-mock-adapter": "^1.21.2"
38
+ "axios-mock-adapter": "^1.21.4"
39
39
  },
40
40
  "engines": {
41
41
  "node": ">=v14.13"