@itwin/access-control-client 3.6.0 → 3.7.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/CHANGELOG.md +10 -2
- package/lib/cjs/subClients/BaseClient.d.ts +13 -6
- package/lib/cjs/subClients/BaseClient.d.ts.map +1 -1
- package/lib/cjs/subClients/BaseClient.js +26 -11
- package/lib/cjs/subClients/BaseClient.js.map +1 -1
- package/lib/esm/subClients/BaseClient.d.ts +13 -6
- package/lib/esm/subClients/BaseClient.d.ts.map +1 -1
- package/lib/esm/subClients/BaseClient.js +26 -11
- package/lib/esm/subClients/BaseClient.js.map +1 -1
- package/package.json +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
# Change Log - @itwin/access-control-client
|
|
2
2
|
|
|
3
|
-
<!-- This log was last generated on
|
|
3
|
+
<!-- This log was last generated on Thu, 02 Oct 2025 15:53:32 GMT and should not be manually modified. -->
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## 3.7.0
|
|
8
|
+
|
|
9
|
+
Thu, 02 Oct 2025 15:53:32 GMT
|
|
10
|
+
|
|
11
|
+
### Minor changes
|
|
12
|
+
|
|
13
|
+
- Refactor BaseClient to use fetch API and improve error handling; remove axios dependency ([commit](https://github.com/iTwin/access-control-client/commit/165fa8ae00423c7c375fad98286d83c6ce27d5c8))
|
|
14
|
+
|
|
7
15
|
## 3.6.0
|
|
8
16
|
|
|
9
|
-
Wed, 23 Jul 2025 13:27:
|
|
17
|
+
Wed, 23 Jul 2025 13:27:49 GMT
|
|
10
18
|
|
|
11
19
|
### Minor changes
|
|
12
20
|
|
|
@@ -2,15 +2,21 @@
|
|
|
2
2
|
* @module AccessControlClient
|
|
3
3
|
*/
|
|
4
4
|
import type { AccessToken } from "@itwin/core-bentley";
|
|
5
|
-
import type { Method } from "axios";
|
|
6
|
-
import type { AxiosRequestConfig } from "axios";
|
|
7
5
|
import type { AccessControlAPIResponse, AccessControlQueryArg } from "../accessControlTypes";
|
|
6
|
+
declare type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
7
|
+
interface RequestConfig {
|
|
8
|
+
method: Method;
|
|
9
|
+
url: string;
|
|
10
|
+
data?: any;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
validateStatus?: (status: number) => boolean;
|
|
13
|
+
}
|
|
8
14
|
export declare class BaseClient {
|
|
9
15
|
protected _baseUrl: string;
|
|
10
16
|
constructor(url?: string);
|
|
11
17
|
/**
|
|
12
18
|
* Sends a basic API request
|
|
13
|
-
* @param
|
|
19
|
+
* @param accessToken The client access token
|
|
14
20
|
* @param method The method type of the request (ex. GET, POST, DELETE, etc)
|
|
15
21
|
* @param url The url of the request
|
|
16
22
|
*/
|
|
@@ -19,11 +25,11 @@ export declare class BaseClient {
|
|
|
19
25
|
}): Promise<AccessControlAPIResponse<any>>;
|
|
20
26
|
/**
|
|
21
27
|
* Build the request methods, headers, and other options
|
|
22
|
-
* @param
|
|
28
|
+
* @param accessToken The client access token
|
|
23
29
|
*/
|
|
24
|
-
protected getRequestOptions(
|
|
30
|
+
protected getRequestOptions(accessToken: AccessToken, method: Method, url: string, data?: any, additionalHeaders?: {
|
|
25
31
|
[key: string]: string;
|
|
26
|
-
}):
|
|
32
|
+
}): RequestConfig;
|
|
27
33
|
/**
|
|
28
34
|
* Build a query to be appended to a URL
|
|
29
35
|
* @param queryArg Object container queryable properties
|
|
@@ -31,4 +37,5 @@ export declare class BaseClient {
|
|
|
31
37
|
*/
|
|
32
38
|
protected getQueryString(queryArg: AccessControlQueryArg): string;
|
|
33
39
|
}
|
|
40
|
+
export {};
|
|
34
41
|
//# sourceMappingURL=BaseClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../../src/subClients/BaseClient.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO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GAAG,MAAM,CAAA;KAAE,GAAG,aAAa;IAiB5J;;;;QAII;IACJ,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM;CAclE"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.BaseClient = void 0;
|
|
4
|
-
const axios_1 = require("axios");
|
|
5
4
|
class BaseClient {
|
|
6
5
|
constructor(url) {
|
|
7
6
|
this._baseUrl = "https://api.bentley.com/accesscontrol/itwins";
|
|
@@ -19,19 +18,36 @@ class BaseClient {
|
|
|
19
18
|
}
|
|
20
19
|
/**
|
|
21
20
|
* Sends a basic API request
|
|
22
|
-
* @param
|
|
21
|
+
* @param accessToken The client access token
|
|
23
22
|
* @param method The method type of the request (ex. GET, POST, DELETE, etc)
|
|
24
23
|
* @param url The url of the request
|
|
25
24
|
*/
|
|
26
25
|
async sendGenericAPIRequest(accessToken, method, url, data, property, additionalHeaders) {
|
|
27
26
|
const requestOptions = this.getRequestOptions(accessToken, method, url, data, additionalHeaders);
|
|
28
27
|
try {
|
|
29
|
-
const response = await (
|
|
28
|
+
const response = await fetch(requestOptions.url, {
|
|
29
|
+
method: requestOptions.method,
|
|
30
|
+
headers: requestOptions.headers,
|
|
31
|
+
body: requestOptions.data ? JSON.stringify(requestOptions.data) : undefined,
|
|
32
|
+
});
|
|
33
|
+
let responseData;
|
|
34
|
+
const contentType = response.headers.get("content-type");
|
|
35
|
+
if (contentType && contentType.includes("application/json")) {
|
|
36
|
+
responseData = await response.json();
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
responseData = await response.text();
|
|
40
|
+
}
|
|
41
|
+
// Convert Headers object to plain object for compatibility
|
|
42
|
+
const headers = {};
|
|
43
|
+
response.headers.forEach((value, key) => {
|
|
44
|
+
headers[key] = value;
|
|
45
|
+
});
|
|
30
46
|
return {
|
|
31
47
|
status: response.status,
|
|
32
|
-
data:
|
|
33
|
-
error:
|
|
34
|
-
headers
|
|
48
|
+
data: responseData?.error || responseData === "" ? undefined : property ? responseData[property] : responseData,
|
|
49
|
+
error: responseData?.error,
|
|
50
|
+
headers,
|
|
35
51
|
};
|
|
36
52
|
}
|
|
37
53
|
catch (err) {
|
|
@@ -47,15 +63,15 @@ class BaseClient {
|
|
|
47
63
|
}
|
|
48
64
|
/**
|
|
49
65
|
* Build the request methods, headers, and other options
|
|
50
|
-
* @param
|
|
66
|
+
* @param accessToken The client access token
|
|
51
67
|
*/
|
|
52
|
-
getRequestOptions(
|
|
68
|
+
getRequestOptions(accessToken, method, url, data, additionalHeaders) {
|
|
53
69
|
return {
|
|
54
70
|
method,
|
|
55
71
|
url,
|
|
56
72
|
data,
|
|
57
73
|
headers: {
|
|
58
|
-
"authorization":
|
|
74
|
+
"authorization": accessToken,
|
|
59
75
|
"content-type": "application/json",
|
|
60
76
|
"accept": "application/vnd.bentley.itwin-platform.v2+json",
|
|
61
77
|
...additionalHeaders,
|
|
@@ -79,8 +95,7 @@ class BaseClient {
|
|
|
79
95
|
queryString += `&$skip=${queryArg.skip}`;
|
|
80
96
|
}
|
|
81
97
|
// trim & from start of string
|
|
82
|
-
queryString.replace(/^&+/, "");
|
|
83
|
-
return queryString;
|
|
98
|
+
return queryString.replace(/^&+/, "");
|
|
84
99
|
}
|
|
85
100
|
}
|
|
86
101
|
exports.BaseClient = BaseClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseClient.js","sourceRoot":"","sources":["../../../src/subClients/BaseClient.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"BaseClient.js","sourceRoot":"","sources":["../../../src/subClients/BaseClient.ts"],"names":[],"mappings":";;;AAqBA,MAAa,UAAU;IAGrB,YAAmB,GAAY;QAFrB,aAAQ,GAAW,8CAA8C,CAAC;QAG1E,IAAI,GAAG,KAAK,SAAS,EAAE;YACrB,IAAI,CAAC,QAAQ,GAAG,GAAG,CAA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AAU,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC1C;QAED,8BAA8B;QAC9B,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC;CACF;AAhHD,gCAgHC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module AccessControlClient\r\n */\r\nimport type { AccessToken } from \"@itwin/core-bentley\";\r\nimport type { AccessControlAPIResponse, AccessControlQueryArg } from \"../accessControlTypes\";\r\n\r\n// Custom types to replace axios types\r\ntype Method = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\r\n\r\ninterface RequestConfig {\r\n method: Method;\r\n url: string;\r\n data?: any;\r\n headers?: Record<string, string>;\r\n validateStatus?: (status: number) => boolean;\r\n}\r\n\r\nexport class BaseClient {\r\n protected _baseUrl: string = \"https://api.bentley.com/accesscontrol/itwins\";\r\n\r\n public constructor(url?: string) {\r\n if (url !== undefined) {\r\n this._baseUrl = url;\r\n } else {\r\n const urlPrefix = process.env.IMJS_URL_PREFIX;\r\n if (urlPrefix) {\r\n const baseUrl = new URL(this._baseUrl);\r\n baseUrl.hostname = urlPrefix + baseUrl.hostname;\r\n this._baseUrl = baseUrl.href;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sends a basic API request\r\n * @param accessToken The client access token\r\n * @param method The method type of the request (ex. GET, POST, DELETE, etc)\r\n * @param url The url of the request\r\n */\r\n protected async sendGenericAPIRequest(\r\n accessToken: AccessToken,\r\n method: Method,\r\n url: string,\r\n data?: any,\r\n property?: string,\r\n additionalHeaders?: { [key: string]: string }\r\n ): Promise<AccessControlAPIResponse<any>> { // TODO: Change any response\r\n const requestOptions = this.getRequestOptions(accessToken, method, url, data, additionalHeaders);\r\n try {\r\n const response = await fetch(requestOptions.url, {\r\n method: requestOptions.method,\r\n headers: requestOptions.headers,\r\n body: requestOptions.data ? JSON.stringify(requestOptions.data) : undefined,\r\n });\r\n\r\n let responseData: any;\r\n const contentType = response.headers.get(\"content-type\");\r\n\r\n if (contentType && contentType.includes(\"application/json\")) {\r\n responseData = await response.json();\r\n } else {\r\n responseData = await response.text();\r\n }\r\n\r\n // Convert Headers object to plain object for compatibility\r\n const headers: Record<string, string> = {};\r\n response.headers.forEach((value, key) => {\r\n headers[key] = value;\r\n });\r\n\r\n return {\r\n status: response.status,\r\n data: responseData?.error || responseData === \"\" ? undefined : property ? responseData[property] : responseData,\r\n error: responseData?.error,\r\n headers,\r\n };\r\n } catch (err) {\r\n return {\r\n status: 500,\r\n error: {\r\n code: \"InternalServerError\",\r\n message:\r\n \"An internal exception happened while calling iTwins Service\",\r\n },\r\n headers: {},\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Build the request methods, headers, and other options\r\n * @param accessToken The client access token\r\n */\r\n protected getRequestOptions(accessToken: AccessToken, method: Method, url: string, data?: any, additionalHeaders?: { [key: string]: string }): RequestConfig {\r\n return {\r\n method,\r\n url,\r\n data,\r\n headers: {\r\n \"authorization\": accessToken,\r\n \"content-type\": \"application/json\",\r\n \"accept\": \"application/vnd.bentley.itwin-platform.v2+json\",\r\n ...additionalHeaders,\r\n },\r\n validateStatus(status: number) {\r\n return status < 500; // Resolve only if the status code is less than 500\r\n },\r\n };\r\n }\r\n\r\n /**\r\n * Build a query to be appended to a URL\r\n * @param queryArg Object container queryable properties\r\n * @returns query string with AccessControlQueryArg applied, which should be appended to a url\r\n */\r\n protected getQueryString(queryArg: AccessControlQueryArg): string {\r\n let queryString = \"\";\r\n\r\n if (queryArg.top) {\r\n queryString += `&$top=${queryArg.top}`;\r\n }\r\n\r\n if (queryArg.skip) {\r\n queryString += `&$skip=${queryArg.skip}`;\r\n }\r\n\r\n // trim & from start of string\r\n return queryString.replace(/^&+/, \"\");\r\n }\r\n}\r\n"]}
|
|
@@ -2,15 +2,21 @@
|
|
|
2
2
|
* @module AccessControlClient
|
|
3
3
|
*/
|
|
4
4
|
import type { AccessToken } from "@itwin/core-bentley";
|
|
5
|
-
import type { Method } from "axios";
|
|
6
|
-
import type { AxiosRequestConfig } from "axios";
|
|
7
5
|
import type { AccessControlAPIResponse, AccessControlQueryArg } from "../accessControlTypes";
|
|
6
|
+
declare type Method = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
7
|
+
interface RequestConfig {
|
|
8
|
+
method: Method;
|
|
9
|
+
url: string;
|
|
10
|
+
data?: any;
|
|
11
|
+
headers?: Record<string, string>;
|
|
12
|
+
validateStatus?: (status: number) => boolean;
|
|
13
|
+
}
|
|
8
14
|
export declare class BaseClient {
|
|
9
15
|
protected _baseUrl: string;
|
|
10
16
|
constructor(url?: string);
|
|
11
17
|
/**
|
|
12
18
|
* Sends a basic API request
|
|
13
|
-
* @param
|
|
19
|
+
* @param accessToken The client access token
|
|
14
20
|
* @param method The method type of the request (ex. GET, POST, DELETE, etc)
|
|
15
21
|
* @param url The url of the request
|
|
16
22
|
*/
|
|
@@ -19,11 +25,11 @@ export declare class BaseClient {
|
|
|
19
25
|
}): Promise<AccessControlAPIResponse<any>>;
|
|
20
26
|
/**
|
|
21
27
|
* Build the request methods, headers, and other options
|
|
22
|
-
* @param
|
|
28
|
+
* @param accessToken The client access token
|
|
23
29
|
*/
|
|
24
|
-
protected getRequestOptions(
|
|
30
|
+
protected getRequestOptions(accessToken: AccessToken, method: Method, url: string, data?: any, additionalHeaders?: {
|
|
25
31
|
[key: string]: string;
|
|
26
|
-
}):
|
|
32
|
+
}): RequestConfig;
|
|
27
33
|
/**
|
|
28
34
|
* Build a query to be appended to a URL
|
|
29
35
|
* @param queryArg Object container queryable properties
|
|
@@ -31,4 +37,5 @@ export declare class BaseClient {
|
|
|
31
37
|
*/
|
|
32
38
|
protected getQueryString(queryArg: AccessControlQueryArg): string;
|
|
33
39
|
}
|
|
40
|
+
export {};
|
|
34
41
|
//# sourceMappingURL=BaseClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../../src/subClients/BaseClient.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"BaseClient.d.ts","sourceRoot":"","sources":["../../../src/subClients/BaseClient.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,KAAK,EAAE,wBAAwB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAG7F,aAAK,MAAM,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE1D,UAAU,aAAa;IACrB,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC;CAC9C;AAED,qBAAa,UAAU;IACrB,SAAS,CAAC,QAAQ,EAAE,MAAM,CAAkD;gBAEzD,GAAG,CAAC,EAAE,MAAM;IAa/B;;;;;QAKI;cACY,qBAAqB,CACnC,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,IAAI,CAAC,EAAE,GAAG,EACV,QAAQ,CAAC,EAAE,MAAM,EACjB,iBAAiB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAC5C,OAAO,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC;IA2CzC;;;QAGI;IACJ,SAAS,CAAC,iBAAiB,CAAC,WAAW,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,iBAAiB,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,GAAG,aAAa;IAiB5J;;;;QAII;IACJ,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,qBAAqB,GAAG,MAAM;CAclE"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
export class BaseClient {
|
|
3
2
|
constructor(url) {
|
|
4
3
|
this._baseUrl = "https://api.bentley.com/accesscontrol/itwins";
|
|
@@ -16,19 +15,36 @@ export class BaseClient {
|
|
|
16
15
|
}
|
|
17
16
|
/**
|
|
18
17
|
* Sends a basic API request
|
|
19
|
-
* @param
|
|
18
|
+
* @param accessToken The client access token
|
|
20
19
|
* @param method The method type of the request (ex. GET, POST, DELETE, etc)
|
|
21
20
|
* @param url The url of the request
|
|
22
21
|
*/
|
|
23
22
|
async sendGenericAPIRequest(accessToken, method, url, data, property, additionalHeaders) {
|
|
24
23
|
const requestOptions = this.getRequestOptions(accessToken, method, url, data, additionalHeaders);
|
|
25
24
|
try {
|
|
26
|
-
const response = await
|
|
25
|
+
const response = await fetch(requestOptions.url, {
|
|
26
|
+
method: requestOptions.method,
|
|
27
|
+
headers: requestOptions.headers,
|
|
28
|
+
body: requestOptions.data ? JSON.stringify(requestOptions.data) : undefined,
|
|
29
|
+
});
|
|
30
|
+
let responseData;
|
|
31
|
+
const contentType = response.headers.get("content-type");
|
|
32
|
+
if (contentType && contentType.includes("application/json")) {
|
|
33
|
+
responseData = await response.json();
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
responseData = await response.text();
|
|
37
|
+
}
|
|
38
|
+
// Convert Headers object to plain object for compatibility
|
|
39
|
+
const headers = {};
|
|
40
|
+
response.headers.forEach((value, key) => {
|
|
41
|
+
headers[key] = value;
|
|
42
|
+
});
|
|
27
43
|
return {
|
|
28
44
|
status: response.status,
|
|
29
|
-
data:
|
|
30
|
-
error:
|
|
31
|
-
headers
|
|
45
|
+
data: responseData?.error || responseData === "" ? undefined : property ? responseData[property] : responseData,
|
|
46
|
+
error: responseData?.error,
|
|
47
|
+
headers,
|
|
32
48
|
};
|
|
33
49
|
}
|
|
34
50
|
catch (err) {
|
|
@@ -44,15 +60,15 @@ export class BaseClient {
|
|
|
44
60
|
}
|
|
45
61
|
/**
|
|
46
62
|
* Build the request methods, headers, and other options
|
|
47
|
-
* @param
|
|
63
|
+
* @param accessToken The client access token
|
|
48
64
|
*/
|
|
49
|
-
getRequestOptions(
|
|
65
|
+
getRequestOptions(accessToken, method, url, data, additionalHeaders) {
|
|
50
66
|
return {
|
|
51
67
|
method,
|
|
52
68
|
url,
|
|
53
69
|
data,
|
|
54
70
|
headers: {
|
|
55
|
-
"authorization":
|
|
71
|
+
"authorization": accessToken,
|
|
56
72
|
"content-type": "application/json",
|
|
57
73
|
"accept": "application/vnd.bentley.itwin-platform.v2+json",
|
|
58
74
|
...additionalHeaders,
|
|
@@ -76,8 +92,7 @@ export class BaseClient {
|
|
|
76
92
|
queryString += `&$skip=${queryArg.skip}`;
|
|
77
93
|
}
|
|
78
94
|
// trim & from start of string
|
|
79
|
-
queryString.replace(/^&+/, "");
|
|
80
|
-
return queryString;
|
|
95
|
+
return queryString.replace(/^&+/, "");
|
|
81
96
|
}
|
|
82
97
|
}
|
|
83
98
|
//# sourceMappingURL=BaseClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseClient.js","sourceRoot":"","sources":["../../../src/subClients/BaseClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BaseClient.js","sourceRoot":"","sources":["../../../src/subClients/BaseClient.ts"],"names":[],"mappings":"AAqBA,MAAM,OAAO,UAAU;IAGrB,YAAmB,GAAY;QAFrB,aAAQ,GAAW,8CAA8C,CAAC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GAAG,EAAE,CAAC;SACxC;QAED,IAAI,QAAQ,CAAC,IAAI,EAAE;YACjB,WAAW,IAAI,UAAU,QAAQ,CAAC,IAAI,EAAE,CAAC;SAC1C;QAED,8BAA8B;QAC9B,OAAO,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACxC,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n * See LICENSE.md in the project root for license terms and full copyright notice.\r\n *--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module AccessControlClient\r\n */\r\nimport type { AccessToken } from \"@itwin/core-bentley\";\r\nimport type { AccessControlAPIResponse, AccessControlQueryArg } from \"../accessControlTypes\";\r\n\r\n// Custom types to replace axios types\r\ntype Method = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\r\n\r\ninterface RequestConfig {\r\n method: Method;\r\n url: string;\r\n data?: any;\r\n headers?: Record<string, string>;\r\n validateStatus?: (status: number) => boolean;\r\n}\r\n\r\nexport class BaseClient {\r\n protected _baseUrl: string = \"https://api.bentley.com/accesscontrol/itwins\";\r\n\r\n public constructor(url?: string) {\r\n if (url !== undefined) {\r\n this._baseUrl = url;\r\n } else {\r\n const urlPrefix = process.env.IMJS_URL_PREFIX;\r\n if (urlPrefix) {\r\n const baseUrl = new URL(this._baseUrl);\r\n baseUrl.hostname = urlPrefix + baseUrl.hostname;\r\n this._baseUrl = baseUrl.href;\r\n }\r\n }\r\n }\r\n\r\n /**\r\n * Sends a basic API request\r\n * @param accessToken The client access token\r\n * @param method The method type of the request (ex. GET, POST, DELETE, etc)\r\n * @param url The url of the request\r\n */\r\n protected async sendGenericAPIRequest(\r\n accessToken: AccessToken,\r\n method: Method,\r\n url: string,\r\n data?: any,\r\n property?: string,\r\n additionalHeaders?: { [key: string]: string }\r\n ): Promise<AccessControlAPIResponse<any>> { // TODO: Change any response\r\n const requestOptions = this.getRequestOptions(accessToken, method, url, data, additionalHeaders);\r\n try {\r\n const response = await fetch(requestOptions.url, {\r\n method: requestOptions.method,\r\n headers: requestOptions.headers,\r\n body: requestOptions.data ? JSON.stringify(requestOptions.data) : undefined,\r\n });\r\n\r\n let responseData: any;\r\n const contentType = response.headers.get(\"content-type\");\r\n\r\n if (contentType && contentType.includes(\"application/json\")) {\r\n responseData = await response.json();\r\n } else {\r\n responseData = await response.text();\r\n }\r\n\r\n // Convert Headers object to plain object for compatibility\r\n const headers: Record<string, string> = {};\r\n response.headers.forEach((value, key) => {\r\n headers[key] = value;\r\n });\r\n\r\n return {\r\n status: response.status,\r\n data: responseData?.error || responseData === \"\" ? undefined : property ? responseData[property] : responseData,\r\n error: responseData?.error,\r\n headers,\r\n };\r\n } catch (err) {\r\n return {\r\n status: 500,\r\n error: {\r\n code: \"InternalServerError\",\r\n message:\r\n \"An internal exception happened while calling iTwins Service\",\r\n },\r\n headers: {},\r\n };\r\n }\r\n }\r\n\r\n /**\r\n * Build the request methods, headers, and other options\r\n * @param accessToken The client access token\r\n */\r\n protected getRequestOptions(accessToken: AccessToken, method: Method, url: string, data?: any, additionalHeaders?: { [key: string]: string }): RequestConfig {\r\n return {\r\n method,\r\n url,\r\n data,\r\n headers: {\r\n \"authorization\": accessToken,\r\n \"content-type\": \"application/json\",\r\n \"accept\": \"application/vnd.bentley.itwin-platform.v2+json\",\r\n ...additionalHeaders,\r\n },\r\n validateStatus(status: number) {\r\n return status < 500; // Resolve only if the status code is less than 500\r\n },\r\n };\r\n }\r\n\r\n /**\r\n * Build a query to be appended to a URL\r\n * @param queryArg Object container queryable properties\r\n * @returns query string with AccessControlQueryArg applied, which should be appended to a url\r\n */\r\n protected getQueryString(queryArg: AccessControlQueryArg): string {\r\n let queryString = \"\";\r\n\r\n if (queryArg.top) {\r\n queryString += `&$top=${queryArg.top}`;\r\n }\r\n\r\n if (queryArg.skip) {\r\n queryString += `&$skip=${queryArg.skip}`;\r\n }\r\n\r\n // trim & from start of string\r\n return queryString.replace(/^&+/, \"\");\r\n }\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@itwin/access-control-client",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Access control client for the iTwin platform",
|
|
5
5
|
"main": "lib/cjs/access-control-client.js",
|
|
6
6
|
"module": "lib/esm/access-control-client.js",
|
|
@@ -21,9 +21,6 @@
|
|
|
21
21
|
"version-bump": "beachball bump",
|
|
22
22
|
"publish-package": "beachball publish --yes"
|
|
23
23
|
},
|
|
24
|
-
"dependencies": {
|
|
25
|
-
"axios": "~1.11.0"
|
|
26
|
-
},
|
|
27
24
|
"devDependencies": {
|
|
28
25
|
"@itwin/build-tools": "^3.0.0",
|
|
29
26
|
"@itwin/certa": "^3.0.0",
|