@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
package/lib/ignosportal-api.js
CHANGED
|
@@ -10,18 +10,25 @@ export class AuthorizedApiBase {
|
|
|
10
10
|
this.transformOptions = async (options) => {
|
|
11
11
|
options.headers = {
|
|
12
12
|
...options.headers,
|
|
13
|
-
Authorization: "Bearer " + (await this.config.getAccessToken()),
|
|
13
|
+
Authorization: "Bearer " + (await this.config.accessTokenProvider.getAccessToken()),
|
|
14
14
|
};
|
|
15
|
+
const tenantId = this.config.tenantIdProvider.getTenantId();
|
|
16
|
+
if (tenantId)
|
|
17
|
+
options.headers["x-tenantid"] = tenantId;
|
|
15
18
|
return options;
|
|
16
19
|
};
|
|
17
20
|
this.jsonParseReviver = (_, value) => {
|
|
18
21
|
// Matches starts with "2025-12-09T13:19:39"
|
|
19
22
|
// Will also match "2025-12-09T13:19:39.4576289+00:00"
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
if (typeof value !== "string")
|
|
24
|
+
return value;
|
|
25
|
+
const regex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/;
|
|
26
|
+
if (!regex.test(value))
|
|
27
|
+
return value;
|
|
28
|
+
const date = new Date(value);
|
|
29
|
+
// Prevent values like "2025-12-09T13:19:39.4576289+00:00 bla bla bla" from being parsed as Date
|
|
30
|
+
// (values not starting with an ISO date-time are already filtered out by the regex above)
|
|
31
|
+
return isNaN(date.getTime()) ? value : date;
|
|
25
32
|
};
|
|
26
33
|
this.config = config;
|
|
27
34
|
}
|
|
@@ -8932,6 +8939,38 @@ export class MeasuringToolsClient extends AuthorizedApiBase {
|
|
|
8932
8939
|
}
|
|
8933
8940
|
return Promise.resolve(null);
|
|
8934
8941
|
}
|
|
8942
|
+
seedTypesAndSubTypes() {
|
|
8943
|
+
let url_ = this.baseUrl + "/measuringtools/types/seed";
|
|
8944
|
+
url_ = url_.replace(/[?&]$/, "");
|
|
8945
|
+
let options_ = {
|
|
8946
|
+
method: "POST",
|
|
8947
|
+
headers: {}
|
|
8948
|
+
};
|
|
8949
|
+
return this.transformOptions(options_).then(transformedOptions_ => {
|
|
8950
|
+
return this.http.fetch(url_, transformedOptions_);
|
|
8951
|
+
}).then((_response) => {
|
|
8952
|
+
return this.processSeedTypesAndSubTypes(_response);
|
|
8953
|
+
});
|
|
8954
|
+
}
|
|
8955
|
+
processSeedTypesAndSubTypes(response) {
|
|
8956
|
+
const status = response.status;
|
|
8957
|
+
let _headers = {};
|
|
8958
|
+
if (response.headers && response.headers.forEach) {
|
|
8959
|
+
response.headers.forEach((v, k) => _headers[k] = v);
|
|
8960
|
+
}
|
|
8961
|
+
;
|
|
8962
|
+
if (status === 204) {
|
|
8963
|
+
return response.text().then((_responseText) => {
|
|
8964
|
+
return;
|
|
8965
|
+
});
|
|
8966
|
+
}
|
|
8967
|
+
else if (status !== 200 && status !== 204) {
|
|
8968
|
+
return response.text().then((_responseText) => {
|
|
8969
|
+
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
|
|
8970
|
+
});
|
|
8971
|
+
}
|
|
8972
|
+
return Promise.resolve(null);
|
|
8973
|
+
}
|
|
8935
8974
|
listMeasuringUnits() {
|
|
8936
8975
|
let url_ = this.baseUrl + "/measuringtools/units";
|
|
8937
8976
|
url_ = url_.replace(/[?&]$/, "");
|
package/package.json
CHANGED
package/src/AuthorizedApiBase.ts
CHANGED
|
@@ -2,30 +2,46 @@ export interface IAccessTokenProvider {
|
|
|
2
2
|
getAccessToken: () => Promise<string>;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
+
export interface ITenantIdProvider {
|
|
6
|
+
getTenantId: () => string | null;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface IApiClientConfig {
|
|
10
|
+
accessTokenProvider: IAccessTokenProvider;
|
|
11
|
+
tenantIdProvider: ITenantIdProvider;
|
|
12
|
+
}
|
|
13
|
+
|
|
5
14
|
export class AuthorizedApiBase {
|
|
6
|
-
private readonly config:
|
|
15
|
+
private readonly config: IApiClientConfig;
|
|
7
16
|
|
|
8
|
-
protected constructor(config:
|
|
17
|
+
protected constructor(config: IApiClientConfig) {
|
|
9
18
|
this.config = config;
|
|
10
19
|
}
|
|
11
20
|
|
|
12
21
|
protected transformOptions = async (options: any): Promise<any> => {
|
|
13
22
|
options.headers = {
|
|
14
23
|
...options.headers,
|
|
15
|
-
Authorization: "Bearer " + (await this.config.getAccessToken()),
|
|
24
|
+
Authorization: "Bearer " + (await this.config.accessTokenProvider.getAccessToken()),
|
|
16
25
|
};
|
|
26
|
+
|
|
27
|
+
const tenantId = this.config.tenantIdProvider.getTenantId();
|
|
28
|
+
if (tenantId) options.headers["x-tenantid"] = tenantId;
|
|
29
|
+
|
|
17
30
|
return options;
|
|
18
31
|
};
|
|
19
32
|
|
|
20
33
|
protected jsonParseReviver = (_: any, value: any) => {
|
|
21
34
|
// Matches starts with "2025-12-09T13:19:39"
|
|
22
35
|
// Will also match "2025-12-09T13:19:39.4576289+00:00"
|
|
23
|
-
|
|
36
|
+
if (typeof value !== "string") return value;
|
|
37
|
+
|
|
38
|
+
const regex = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})/;
|
|
39
|
+
if (!regex.test(value)) return value;
|
|
24
40
|
|
|
25
|
-
|
|
26
|
-
return new Date(value);
|
|
27
|
-
}
|
|
41
|
+
const date = new Date(value);
|
|
28
42
|
|
|
29
|
-
|
|
43
|
+
// Prevent values like "2025-12-09T13:19:39.4576289+00:00 bla bla bla" from being parsed as Date
|
|
44
|
+
// (values not starting with an ISO date-time are already filtered out by the regex above)
|
|
45
|
+
return isNaN(date.getTime()) ? value : date;
|
|
30
46
|
};
|
|
31
47
|
}
|