@ignos/api-client 20260602.144.1 → 20260605.146.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/lib/AuthorizedApiBase.d.ts +8 -1
- package/lib/AuthorizedApiBase.js +13 -6
- package/lib/ignosportal-api.d.ts +102 -91
- package/lib/ignosportal-api.js +45 -6
- package/package.json +1 -1
- package/src/AuthorizedApiBase.ts +24 -8
- package/src/ignosportal-api.ts +149 -98
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
export interface IAccessTokenProvider {
|
|
2
2
|
getAccessToken: () => Promise<string>;
|
|
3
3
|
}
|
|
4
|
+
export interface ITenantIdProvider {
|
|
5
|
+
getTenantId: () => string | null;
|
|
6
|
+
}
|
|
7
|
+
export interface IApiClientConfig {
|
|
8
|
+
accessTokenProvider: IAccessTokenProvider;
|
|
9
|
+
tenantIdProvider: ITenantIdProvider;
|
|
10
|
+
}
|
|
4
11
|
export declare class AuthorizedApiBase {
|
|
5
12
|
private readonly config;
|
|
6
|
-
protected constructor(config:
|
|
13
|
+
protected constructor(config: IApiClientConfig);
|
|
7
14
|
protected transformOptions: (options: any) => Promise<any>;
|
|
8
15
|
protected jsonParseReviver: (_: any, value: any) => any;
|
|
9
16
|
}
|
package/lib/AuthorizedApiBase.js
CHANGED
|
@@ -3,18 +3,25 @@ export class AuthorizedApiBase {
|
|
|
3
3
|
this.transformOptions = async (options) => {
|
|
4
4
|
options.headers = {
|
|
5
5
|
...options.headers,
|
|
6
|
-
Authorization: "Bearer " + (await this.config.getAccessToken()),
|
|
6
|
+
Authorization: "Bearer " + (await this.config.accessTokenProvider.getAccessToken()),
|
|
7
7
|
};
|
|
8
|
+
const tenantId = this.config.tenantIdProvider.getTenantId();
|
|
9
|
+
if (tenantId)
|
|
10
|
+
options.headers["x-tenantid"] = tenantId;
|
|
8
11
|
return options;
|
|
9
12
|
};
|
|
10
13
|
this.jsonParseReviver = (_, value) => {
|
|
11
14
|
// Matches starts with "2025-12-09T13:19:39"
|
|
12
15
|
// Will also match "2025-12-09T13:19:39.4576289+00:00"
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (typeof value !== "string")
|
|
17
|
+
return value;
|
|
18
|
+
const regex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/;
|
|
19
|
+
if (!regex.test(value))
|
|
20
|
+
return value;
|
|
21
|
+
const date = new Date(value);
|
|
22
|
+
// Prevent values like "2025-12-09T13:19:39.4576289+00:00 bla bla bla" from being parsed as Date
|
|
23
|
+
// (values not starting with an ISO date-time are already filtered out by the regex above)
|
|
24
|
+
return isNaN(date.getTime()) ? value : date;
|
|
18
25
|
};
|
|
19
26
|
this.config = config;
|
|
20
27
|
}
|