@hahnpro/hpc-api 2025.4.0 → 2025.4.1-beta.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hahnpro/hpc-api",
3
- "version": "2025.4.0",
3
+ "version": "2025.4.1-beta.1",
4
4
  "description": "Module for easy access to the HahnPRO Cloud API",
5
5
  "license": "MIT",
6
6
  "author": {
package/src/lib/api.d.ts CHANGED
@@ -27,5 +27,6 @@ export declare class API {
27
27
  notificationRules: NotificationRuleService;
28
28
  constructor(httpClient?: HttpClientService, context?: {
29
29
  tokenSubject?: string;
30
+ activeOrg?: string;
30
31
  });
31
32
  }
package/src/lib/api.js CHANGED
@@ -23,7 +23,15 @@ class API {
23
23
  if (!secret) {
24
24
  throw new Error('"API_BASE_URL", "API_USER", "AUTH_REALM" and "AUTH_SECRET" environment variables must be set');
25
25
  }
26
- this.httpClient = new services_1.HttpClientService(apiUrl, authUrl, realm, client, secret, context?.tokenSubject);
26
+ this.httpClient = new services_1.HttpClientService({
27
+ baseURL: apiUrl,
28
+ authBaseURL: authUrl,
29
+ realm,
30
+ clientId: client,
31
+ clientSecret: secret,
32
+ tokenSubject: context?.tokenSubject,
33
+ activeOrg: context?.activeOrg,
34
+ });
27
35
  }
28
36
  this.ai = new services_1.AiService(this.httpClient);
29
37
  this.alerts = new services_1.AlertService(this.httpClient);
@@ -5,6 +5,15 @@ import { Observable, Subject } from 'rxjs';
5
5
  import { Config, Issuer, TokenOption } from '../interfaces';
6
6
  import { Queue } from '../queue';
7
7
  import { TokenSet } from '../token-set';
8
+ export interface HttpClientConfig {
9
+ baseURL: string;
10
+ authBaseURL?: string;
11
+ realm: string;
12
+ clientId: string;
13
+ clientSecret: string;
14
+ tokenSubject?: string;
15
+ activeOrg?: string;
16
+ }
8
17
  export declare class HttpClientService {
9
18
  protected readonly baseURL: string;
10
19
  protected readonly authBaseURL: string;
@@ -12,6 +21,7 @@ export declare class HttpClientService {
12
21
  protected readonly clientId: string;
13
22
  protected readonly clientSecret: string;
14
23
  protected readonly tokenSubject?: string;
24
+ protected readonly activeOrg?: string;
15
25
  protected readonly axiosInstance: AxiosInstance;
16
26
  protected readonly authAxiosInstance: AxiosInstance;
17
27
  protected readonly requestQueue: Queue;
@@ -23,7 +33,8 @@ export declare class HttpClientService {
23
33
  listener: (event: MessageEvent) => void;
24
34
  errListener: (event: MessageEvent) => void;
25
35
  }>;
26
- constructor(baseURL: string, authBaseURL: string, realm: string, clientId: string, clientSecret: string, tokenSubject?: string);
36
+ constructor(config: HttpClientConfig);
37
+ constructor(baseURL: string, authBaseURL: string, realm: string, clientId: string, clientSecret: string, tokenSubject?: string, activeOrg?: string);
27
38
  getQueueStats: () => {
28
39
  peak: number;
29
40
  pending: number;
@@ -10,13 +10,7 @@ const rxjs_1 = require("rxjs");
10
10
  const queue_1 = require("../queue");
11
11
  const token_set_1 = require("../token-set");
12
12
  class HttpClientService {
13
- constructor(baseURL, authBaseURL, realm, clientId, clientSecret, tokenSubject) {
14
- this.baseURL = baseURL;
15
- this.authBaseURL = authBaseURL;
16
- this.realm = realm;
17
- this.clientId = clientId;
18
- this.clientSecret = clientSecret;
19
- this.tokenSubject = tokenSubject;
13
+ constructor(configOrBaseURL, authBaseURL, realm, clientId, clientSecret, tokenSubject, activeOrg) {
20
14
  this.discoveredIssuers = new Map();
21
15
  this.eventSourcesMap = new Map();
22
16
  this.getQueueStats = () => this.requestQueue?.getStats();
@@ -31,6 +25,9 @@ class HttpClientService {
31
25
  tokenP
32
26
  .then((token) => {
33
27
  const headers = { Authorization: `Bearer ${token}`, ...config.headers };
28
+ if (this.activeOrg) {
29
+ headers['active-org-id'] = this.activeOrg;
30
+ }
34
31
  return this.axiosInstance.request({ ...config, headers, method, url, data });
35
32
  })
36
33
  .then((response) => resolve(response.data))
@@ -59,8 +56,32 @@ class HttpClientService {
59
56
  return accessToken;
60
57
  }
61
58
  };
62
- this.axiosInstance = axios_1.default.create({ baseURL, timeout: 60000 });
63
- this.authAxiosInstance = axios_1.default.create({ baseURL: authBaseURL || baseURL, timeout: 10000 });
59
+ // Handle single config object overload
60
+ if (typeof configOrBaseURL === 'object') {
61
+ const config = configOrBaseURL;
62
+ this.baseURL = config.baseURL;
63
+ this.authBaseURL = config.authBaseURL || config.baseURL;
64
+ this.realm = config.realm;
65
+ this.clientId = config.clientId;
66
+ this.clientSecret = config.clientSecret;
67
+ this.tokenSubject = config.tokenSubject;
68
+ this.activeOrg = config.activeOrg;
69
+ }
70
+ else {
71
+ // Handle individual parameters overload
72
+ if (!authBaseURL || !realm || !clientId || !clientSecret) {
73
+ throw new Error('Missing required parameters for HttpClientService constructor');
74
+ }
75
+ this.baseURL = configOrBaseURL;
76
+ this.authBaseURL = authBaseURL;
77
+ this.realm = realm;
78
+ this.clientId = clientId;
79
+ this.clientSecret = clientSecret;
80
+ this.tokenSubject = tokenSubject;
81
+ this.activeOrg = activeOrg;
82
+ }
83
+ this.axiosInstance = axios_1.default.create({ baseURL: this.baseURL, timeout: 60000 });
84
+ this.authAxiosInstance = axios_1.default.create({ baseURL: this.authBaseURL, timeout: 10000 });
64
85
  this.requestQueue = new queue_1.Queue({ concurrency: 1, timeout: 70000, throwOnTimeout: true });
65
86
  }
66
87
  getSseObservable(path, onmessage) {
@@ -106,13 +127,19 @@ class HttpClientService {
106
127
  };
107
128
  const token = options.token ? options.token : await this.getAccessToken();
108
129
  const es = new eventsource_1.EventSource(`${this.baseURL}${url}`, {
109
- fetch: (input, init) => fetch(input, {
110
- ...init,
111
- headers: {
130
+ fetch: (input, init) => {
131
+ const headers = {
112
132
  ...init.headers,
113
133
  Authorization: 'Bearer ' + token,
114
- },
115
- }),
134
+ };
135
+ if (this.activeOrg) {
136
+ headers['active-org-id'] = this.activeOrg;
137
+ }
138
+ return fetch(input, {
139
+ ...init,
140
+ headers,
141
+ });
142
+ },
116
143
  });
117
144
  es.addEventListener('message', listener);
118
145
  es.addEventListener('error', errListener);