@magda/typescript-common 2.3.2 → 3.0.0-alpha.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/AspectBuilder.d.ts +1 -1
- package/dist/AspectBuilder.js +1 -2
- package/dist/AspectCreationFailure.js +3 -4
- package/dist/AspectCreationFailure.js.map +1 -1
- package/dist/AsyncPage.js +59 -79
- package/dist/AsyncPage.js.map +1 -1
- package/dist/BaseApiClient.d.ts +3 -3
- package/dist/BaseApiClient.js +20 -13
- package/dist/BaseApiClient.js.map +1 -1
- package/dist/ConnectionResult.d.ts +2 -2
- package/dist/ConnectionResult.js +17 -22
- package/dist/ConnectionResult.js.map +1 -1
- package/dist/ConnectorRecordId.d.ts +1 -1
- package/dist/ConnectorRecordId.js +9 -13
- package/dist/ConnectorRecordId.js.map +1 -1
- package/dist/IndexerApiClient.d.ts +1 -1
- package/dist/IndexerApiClient.js +13 -32
- package/dist/IndexerApiClient.js.map +1 -1
- package/dist/JsonConnector.d.ts +9 -9
- package/dist/JsonConnector.js +163 -206
- package/dist/JsonConnector.js.map +1 -1
- package/dist/JsonTransformer.d.ts +3 -3
- package/dist/JsonTransformer.js +71 -75
- package/dist/JsonTransformer.js.map +1 -1
- package/dist/OpaCompileResponseParser.d.ts +4 -4
- package/dist/OpaCompileResponseParser.js +278 -211
- package/dist/OpaCompileResponseParser.js.map +1 -1
- package/dist/RecordCreationFailure.d.ts +1 -1
- package/dist/RecordCreationFailure.js +4 -4
- package/dist/RecordCreationFailure.js.map +1 -1
- package/dist/SQLUtils.d.ts +3 -3
- package/dist/SQLUtils.js +139 -195
- package/dist/SQLUtils.js.map +1 -1
- package/dist/ServerError.js +2 -4
- package/dist/ServerError.js.map +1 -1
- package/dist/Try.js +20 -35
- package/dist/Try.js.map +1 -1
- package/dist/addTrailingSlash.js +1 -4
- package/dist/addTrailingSlash.js.map +1 -1
- package/dist/appendUrlSegments.js +3 -8
- package/dist/appendUrlSegments.js.map +1 -1
- package/dist/authorization-api/AccessControlError.d.ts +1 -1
- package/dist/authorization-api/AccessControlError.js +2 -8
- package/dist/authorization-api/AccessControlError.js.map +1 -1
- package/dist/authorization-api/ApiClient.d.ts +3 -3
- package/dist/authorization-api/ApiClient.js +211 -272
- package/dist/authorization-api/ApiClient.js.map +1 -1
- package/dist/authorization-api/AuthError.d.ts +1 -1
- package/dist/authorization-api/AuthError.js +2 -8
- package/dist/authorization-api/AuthError.js.map +1 -1
- package/dist/authorization-api/GenericError.js +2 -4
- package/dist/authorization-api/GenericError.js.map +1 -1
- package/dist/authorization-api/authMiddleware.d.ts +3 -3
- package/dist/authorization-api/authMiddleware.js +19 -40
- package/dist/authorization-api/authMiddleware.js.map +1 -1
- package/dist/authorization-api/constants.js +9 -12
- package/dist/authorization-api/constants.js.map +1 -1
- package/dist/authorization-api/model.d.ts +8 -8
- package/dist/authorization-api/model.js +1 -2
- package/dist/coerceJson.js +1 -3
- package/dist/coerceJson.js.map +1 -1
- package/dist/createNoCacheFetchOptions.d.ts +1 -1
- package/dist/createNoCacheFetchOptions.js +4 -7
- package/dist/createNoCacheFetchOptions.js.map +1 -1
- package/dist/createServiceError.d.ts +1 -1
- package/dist/createServiceError.js +4 -9
- package/dist/createServiceError.js.map +1 -1
- package/dist/delay.js +1 -3
- package/dist/delay.js.map +1 -1
- package/dist/express/getNoCacheHeaders.js +1 -3
- package/dist/express/getNoCacheHeaders.js.map +1 -1
- package/dist/express/setResponseNoCache.d.ts +1 -1
- package/dist/express/setResponseNoCache.js +3 -8
- package/dist/express/setResponseNoCache.js.map +1 -1
- package/dist/express/status.d.ts +14 -15
- package/dist/express/status.js +135 -126
- package/dist/express/status.js.map +1 -1
- package/dist/fetchRequest.d.ts +6 -6
- package/dist/fetchRequest.js +36 -51
- package/dist/fetchRequest.js.map +1 -1
- package/dist/formatServiceError.js +1 -4
- package/dist/formatServiceError.js.map +1 -1
- package/dist/generated/registry/api.d.ts +4 -4
- package/dist/generated/registry/api.js +197 -102
- package/dist/generated/registry/api.js.map +1 -1
- package/dist/getAbsoluteUrl.js +8 -11
- package/dist/getAbsoluteUrl.js.map +1 -1
- package/dist/getBasePathFromUrl.js +3 -9
- package/dist/getBasePathFromUrl.js.map +1 -1
- package/dist/getBoolValWithDefault.js +1 -3
- package/dist/getBoolValWithDefault.js.map +1 -1
- package/dist/getRequest.js +9 -26
- package/dist/getRequest.js.map +1 -1
- package/dist/getRequestNoCache.js +4 -21
- package/dist/getRequestNoCache.js.map +1 -1
- package/dist/getStorageUrl.js +13 -23
- package/dist/getStorageUrl.js.map +1 -1
- package/dist/handleServerError.js +3 -9
- package/dist/handleServerError.js.map +1 -1
- package/dist/markdownToHtml.js +5 -11
- package/dist/markdownToHtml.js.map +1 -1
- package/dist/opa/AspectQuery.js +55 -79
- package/dist/opa/AspectQuery.js.map +1 -1
- package/dist/opa/AuthDecision.d.ts +2 -2
- package/dist/opa/AuthDecision.js +52 -69
- package/dist/opa/AuthDecision.js.map +1 -1
- package/dist/opa/AuthDecisionQueryClient.d.ts +2 -2
- package/dist/opa/AuthDecisionQueryClient.js +75 -102
- package/dist/opa/AuthDecisionQueryClient.js.map +1 -1
- package/dist/pgTypes.js +4 -9
- package/dist/pgTypes.js.map +1 -1
- package/dist/registry/AuthorizedRegistryClient.d.ts +4 -4
- package/dist/registry/AuthorizedRegistryClient.js +52 -92
- package/dist/registry/AuthorizedRegistryClient.js.map +1 -1
- package/dist/registry/RegistryClient.d.ts +2 -2
- package/dist/registry/RegistryClient.js +60 -76
- package/dist/registry/RegistryClient.js.map +1 -1
- package/dist/registry/TenantConsts.js +3 -6
- package/dist/registry/TenantConsts.js.map +1 -1
- package/dist/registry/model.js +1 -2
- package/dist/registry-manual/api.d.ts +1 -1
- package/dist/registry-manual/api.js +18 -7
- package/dist/registry-manual/api.js.map +1 -1
- package/dist/request.d.ts +2 -2
- package/dist/request.js +4 -9
- package/dist/request.js.map +1 -1
- package/dist/retry.d.ts +1 -1
- package/dist/retry.js +3 -9
- package/dist/retry.js.map +1 -1
- package/dist/retryBackoff.js +3 -9
- package/dist/retryBackoff.js.map +1 -1
- package/dist/runLater.js +1 -4
- package/dist/runLater.js.map +1 -1
- package/dist/session/GetUserId.d.ts +2 -2
- package/dist/session/GetUserId.js +10 -16
- package/dist/session/GetUserId.js.map +1 -1
- package/dist/session/GetUserSession.d.ts +1 -1
- package/dist/session/GetUserSession.js +6 -10
- package/dist/session/GetUserSession.js.map +1 -1
- package/dist/session/addJwtSecretFromEnvVar.js +1 -4
- package/dist/session/addJwtSecretFromEnvVar.js.map +1 -1
- package/dist/session/buildJwt.d.ts +1 -1
- package/dist/session/buildJwt.js +2 -5
- package/dist/session/buildJwt.js.map +1 -1
- package/dist/session/buildJwtFromReq.d.ts +2 -0
- package/dist/session/buildJwtFromReq.js +4 -0
- package/dist/session/buildJwtFromReq.js.map +1 -0
- package/dist/session/cookieUtils.d.ts +2 -13
- package/dist/session/cookieUtils.js +8 -9
- package/dist/session/cookieUtils.js.map +1 -1
- package/dist/session/destroySession.js +18 -33
- package/dist/session/destroySession.js.map +1 -1
- package/dist/session/getSessionId.js +5 -11
- package/dist/session/getSessionId.js.map +1 -1
- package/dist/tenant-api/AuthorizedTenantClient.d.ts +1 -1
- package/dist/tenant-api/AuthorizedTenantClient.js +22 -36
- package/dist/tenant-api/AuthorizedTenantClient.js.map +1 -1
- package/dist/tenant-api/Tenant.js +13 -5
- package/dist/tenant-api/Tenant.js.map +1 -1
- package/dist/test/JsonConnector.spec.js +56 -61
- package/dist/test/JsonConnector.spec.js.map +1 -1
- package/dist/test/JsonTransformer.spec.js +15 -19
- package/dist/test/JsonTransformer.spec.js.map +1 -1
- package/dist/test/arbitraries.d.ts +21 -21
- package/dist/test/arbitraries.js +85 -99
- package/dist/test/arbitraries.js.map +1 -1
- package/dist/test/aspect-templates/organization-details.d.ts +1 -4
- package/dist/test/aspect-templates/organization-details.js +1 -1
- package/dist/test/aspect-templates/organization-details.js.map +1 -1
- package/dist/test/buildApiClient.spec.js +81 -107
- package/dist/test/buildApiClient.spec.js.map +1 -1
- package/dist/test/buildAuthorizedTenantClient.spec.js +25 -40
- package/dist/test/buildAuthorizedTenantClient.spec.js.map +1 -1
- package/dist/test/connectors/MockExpressServer.js +9 -23
- package/dist/test/connectors/MockExpressServer.js.map +1 -1
- package/dist/test/connectors/MockRegistry.d.ts +1 -1
- package/dist/test/connectors/MockRegistry.js +11 -18
- package/dist/test/connectors/MockRegistry.js.map +1 -1
- package/dist/test/connectors/runConnectorTest.js +33 -55
- package/dist/test/connectors/runConnectorTest.js.map +1 -1
- package/dist/test/createMockAuthDecisionQueryClient.d.ts +4 -4
- package/dist/test/createMockAuthDecisionQueryClient.js +4 -9
- package/dist/test/createMockAuthDecisionQueryClient.js.map +1 -1
- package/dist/test/db/getTestDBConfig.js +1 -3
- package/dist/test/db/getTestDBConfig.js.map +1 -1
- package/dist/test/db/runMigrationSql.js +37 -58
- package/dist/test/db/runMigrationSql.js.map +1 -1
- package/dist/test/express/status.spec.js +81 -72
- package/dist/test/express/status.spec.js.map +1 -1
- package/dist/test/fakeArgv.js +6 -5
- package/dist/test/fakeArgv.js.map +1 -1
- package/dist/test/getBasePathFromUrl.spec.js +5 -10
- package/dist/test/getBasePathFromUrl.spec.js.map +1 -1
- package/dist/test/getStorageUrl.spec.js +22 -46
- package/dist/test/getStorageUrl.spec.js.map +1 -1
- package/dist/test/mockAuthApiHost.js +26 -28
- package/dist/test/mockAuthApiHost.js.map +1 -1
- package/dist/test/mockAuthorization.js +4 -10
- package/dist/test/mockAuthorization.js.map +1 -1
- package/dist/test/mockTenantDataStore.d.ts +1 -1
- package/dist/test/mockTenantDataStore.js +3 -5
- package/dist/test/mockTenantDataStore.js.map +1 -1
- package/dist/test/mockUserDataStore.d.ts +1 -1
- package/dist/test/mockUserDataStore.js +4 -6
- package/dist/test/mockUserDataStore.js.map +1 -1
- package/dist/test/registry/buildAuthorizedClient.spec.js +65 -87
- package/dist/test/registry/buildAuthorizedClient.spec.js.map +1 -1
- package/dist/test/session/buildJwt.spec.js +15 -19
- package/dist/test/session/buildJwt.spec.js.map +1 -1
- package/dist/test/session/buildJwtForRegistryEsriOpaGroupsAndOwnerTest.spec.js +6 -11
- package/dist/test/session/buildJwtForRegistryEsriOpaGroupsAndOwnerTest.spec.js.map +1 -1
- package/dist/test/session/buildJwtForRegistryEsriOpaGroupsTest.spec.js +6 -11
- package/dist/test/session/buildJwtForRegistryEsriOpaGroupsTest.spec.js.map +1 -1
- package/dist/test/session/buildJwtForRegistryEsriOpaOwnerTest.spec.js +6 -11
- package/dist/test/session/buildJwtForRegistryEsriOpaOwnerTest.spec.js.map +1 -1
- package/dist/test/testAsyncPage.spec.js +84 -105
- package/dist/test/testAsyncPage.spec.js.map +1 -1
- package/dist/test/testOpaCompileResponseParser.spec.js +192 -196
- package/dist/test/testOpaCompileResponseParser.spec.js.map +1 -1
- package/dist/test/util.js +1 -5
- package/dist/test/util.js.map +1 -1
- package/dist/unknown2Error.d.ts +2 -0
- package/dist/unknown2Error.js +3 -0
- package/dist/unknown2Error.js.map +1 -0
- package/dist/util/arrayToMaybe.d.ts +1 -1
- package/dist/util/arrayToMaybe.js +3 -6
- package/dist/util/arrayToMaybe.js.map +1 -1
- package/dist/util/cleanOrgTitle.js +1 -4
- package/dist/util/cleanOrgTitle.js.map +1 -1
- package/dist/util/escapeRegExp.js +1 -3
- package/dist/util/escapeRegExp.js.map +1 -1
- package/dist/util/getMinikubeIP.js +3 -9
- package/dist/util/getMinikubeIP.js.map +1 -1
- package/dist/util/isArray.js +1 -3
- package/dist/util/isArray.js.map +1 -1
- package/dist/util/isUuid.js +1 -3
- package/dist/util/isUuid.js.map +1 -1
- package/dist/util/unionToThrowable.d.ts +1 -1
- package/dist/util/unionToThrowable.js +3 -9
- package/dist/util/unionToThrowable.js.map +1 -1
- package/dist/utilityTypes.d.ts +1 -1
- package/dist/utilityTypes.js +1 -2
- package/package.json +44 -26
- package/dist/test/jsverify.d.ts +0 -2
- package/dist/test/jsverify.js +0 -8
- package/dist/test/jsverify.js.map +0 -1
|
@@ -1,35 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
|
|
16
|
-
const tsmonad_1 = require("tsmonad");
|
|
17
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
18
|
-
const buildJwt_1 = __importDefault(require("../session/buildJwt"));
|
|
19
|
-
const addTrailingSlash_1 = __importDefault(require("../addTrailingSlash"));
|
|
20
|
-
const urijs_1 = __importDefault(require("urijs"));
|
|
21
|
-
const ServerError_1 = __importDefault(require("../ServerError"));
|
|
22
|
-
const isUuid_1 = __importDefault(require("../util/isUuid"));
|
|
23
|
-
class ApiClient {
|
|
1
|
+
import fetch from "cross-fetch";
|
|
2
|
+
import { Maybe } from "@magda/tsmonad";
|
|
3
|
+
import lodash from "lodash";
|
|
4
|
+
import buildJwt from "../session/buildJwt.js";
|
|
5
|
+
import addTrailingSlash from "../addTrailingSlash.js";
|
|
6
|
+
import urijs from "urijs";
|
|
7
|
+
import ServerError from "../ServerError.js";
|
|
8
|
+
import isUuid from "../util/isUuid.js";
|
|
9
|
+
export default class ApiClient {
|
|
10
|
+
jwt = null;
|
|
11
|
+
requestInitOption = null;
|
|
12
|
+
baseUrl = "";
|
|
24
13
|
constructor(
|
|
25
14
|
// e.g. http://authorization-api/v0
|
|
26
15
|
baseUrl, jwtSecret = null, userId = null) {
|
|
27
|
-
this.
|
|
28
|
-
this.requestInitOption = null;
|
|
29
|
-
this.baseUrl = "";
|
|
30
|
-
this.baseUrl = addTrailingSlash_1.default(baseUrl);
|
|
16
|
+
this.baseUrl = addTrailingSlash(baseUrl);
|
|
31
17
|
if (jwtSecret && userId) {
|
|
32
|
-
this.jwt =
|
|
18
|
+
this.jwt = buildJwt(jwtSecret, userId);
|
|
33
19
|
}
|
|
34
20
|
if (this.jwt) {
|
|
35
21
|
this.requestInitOption = {
|
|
@@ -41,8 +27,8 @@ class ApiClient {
|
|
|
41
27
|
}
|
|
42
28
|
getMergeRequestInitOption(extraOptions = null) {
|
|
43
29
|
let defaultContentTypeCfg = {};
|
|
44
|
-
if (
|
|
45
|
-
(!
|
|
30
|
+
if (extraOptions?.body &&
|
|
31
|
+
(!extraOptions?.headers ||
|
|
46
32
|
(typeof extraOptions.headers === "object" &&
|
|
47
33
|
Object.keys(extraOptions.headers)
|
|
48
34
|
.map((key) => key.toLowerCase())
|
|
@@ -53,18 +39,16 @@ class ApiClient {
|
|
|
53
39
|
}
|
|
54
40
|
};
|
|
55
41
|
}
|
|
56
|
-
return
|
|
42
|
+
return lodash.merge({}, this.requestInitOption, extraOptions, defaultContentTypeCfg);
|
|
57
43
|
}
|
|
58
|
-
processJsonResponse(res) {
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
});
|
|
44
|
+
async processJsonResponse(res) {
|
|
45
|
+
if (res.status >= 200 && res.status < 300) {
|
|
46
|
+
return (await res.json());
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const responseText = await res.text();
|
|
50
|
+
throw new ServerError(`Error: ${res.statusText}. ${responseText.replace(/<(.|\n)*?>/g, "")}`, res.status);
|
|
51
|
+
}
|
|
68
52
|
}
|
|
69
53
|
/**
|
|
70
54
|
* Get the data of a user.
|
|
@@ -73,10 +57,8 @@ class ApiClient {
|
|
|
73
57
|
* @returns {Promise<Maybe<User>>}
|
|
74
58
|
* @memberof ApiClient
|
|
75
59
|
*/
|
|
76
|
-
getUser(userId) {
|
|
77
|
-
return
|
|
78
|
-
return yield this.handleGetResult(isomorphic_fetch_1.default(`${this.baseUrl}public/users/${userId}`, this.getMergeRequestInitOption()));
|
|
79
|
-
});
|
|
60
|
+
async getUser(userId) {
|
|
61
|
+
return await this.handleGetResult(fetch(`${this.baseUrl}public/users/${userId}`, this.getMergeRequestInitOption()));
|
|
80
62
|
}
|
|
81
63
|
/**
|
|
82
64
|
* Lookup user by source (identity provider) & sourceId (identity ID)
|
|
@@ -86,29 +68,27 @@ class ApiClient {
|
|
|
86
68
|
* @returns {Promise<Maybe<User>>}
|
|
87
69
|
* @memberof ApiClient
|
|
88
70
|
*/
|
|
89
|
-
lookupUser(source, sourceId) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
limit: 1
|
|
101
|
-
});
|
|
102
|
-
const res = yield isomorphic_fetch_1.default(uri.toString(), this.getMergeRequestInitOption());
|
|
103
|
-
if (!res.ok) {
|
|
104
|
-
throw new ServerError_1.default(yield res.text(), res.status);
|
|
105
|
-
}
|
|
106
|
-
const data = yield res.json();
|
|
107
|
-
if (!(data === null || data === void 0 ? void 0 : data.length)) {
|
|
108
|
-
return tsmonad_1.Maybe.nothing();
|
|
109
|
-
}
|
|
110
|
-
return tsmonad_1.Maybe.just(data[0]);
|
|
71
|
+
async lookupUser(source, sourceId) {
|
|
72
|
+
if (!source) {
|
|
73
|
+
throw new ServerError("source cannot be empty!", 400);
|
|
74
|
+
}
|
|
75
|
+
if (!sourceId) {
|
|
76
|
+
throw new ServerError("sourceId cannot be empty!", 400);
|
|
77
|
+
}
|
|
78
|
+
const uri = urijs(`${this.baseUrl}public/users`).search({
|
|
79
|
+
source,
|
|
80
|
+
sourceId,
|
|
81
|
+
limit: 1
|
|
111
82
|
});
|
|
83
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption());
|
|
84
|
+
if (!res.ok) {
|
|
85
|
+
throw new ServerError(await res.text(), res.status);
|
|
86
|
+
}
|
|
87
|
+
const data = await res.json();
|
|
88
|
+
if (!data?.length) {
|
|
89
|
+
return Maybe.nothing();
|
|
90
|
+
}
|
|
91
|
+
return Maybe.just(data[0]);
|
|
112
92
|
}
|
|
113
93
|
/**
|
|
114
94
|
* create a user
|
|
@@ -117,27 +97,25 @@ class ApiClient {
|
|
|
117
97
|
* @returns {Promise<UserRecord>}
|
|
118
98
|
* @memberof ApiClient
|
|
119
99
|
*/
|
|
120
|
-
createUser(user) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
throw new Error(`Encountered error ${res.status}: ${yield res.text()} when creating new user to ${this.baseUrl}public/users`);
|
|
132
|
-
}
|
|
133
|
-
const resData = yield res.json();
|
|
134
|
-
return resData;
|
|
135
|
-
}
|
|
136
|
-
catch (e) {
|
|
137
|
-
console.error(e);
|
|
138
|
-
throw e;
|
|
100
|
+
async createUser(user) {
|
|
101
|
+
try {
|
|
102
|
+
const res = await fetch(`${this.baseUrl}public/users`, this.getMergeRequestInitOption({
|
|
103
|
+
method: "POST",
|
|
104
|
+
headers: {
|
|
105
|
+
"Content-Type": "application/json"
|
|
106
|
+
},
|
|
107
|
+
body: JSON.stringify(user)
|
|
108
|
+
}));
|
|
109
|
+
if (res.status >= 400) {
|
|
110
|
+
throw new Error(`Encountered error ${res.status}: ${await res.text()} when creating new user to ${this.baseUrl}public/users`);
|
|
139
111
|
}
|
|
140
|
-
|
|
112
|
+
const resData = await res.json();
|
|
113
|
+
return resData;
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
console.error(e);
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
141
119
|
}
|
|
142
120
|
/**
|
|
143
121
|
* Add Roles to a user.
|
|
@@ -148,17 +126,15 @@ class ApiClient {
|
|
|
148
126
|
* @returns {Promise<string[]>}
|
|
149
127
|
* @memberof ApiClient
|
|
150
128
|
*/
|
|
151
|
-
addUserRoles(userId, roleIds) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return yield this.processJsonResponse(res);
|
|
161
|
-
});
|
|
129
|
+
async addUserRoles(userId, roleIds) {
|
|
130
|
+
const res = await fetch(`${this.baseUrl}public/users/${userId}/roles`, this.getMergeRequestInitOption({
|
|
131
|
+
method: "POST",
|
|
132
|
+
headers: {
|
|
133
|
+
"Content-Type": "application/json"
|
|
134
|
+
},
|
|
135
|
+
body: JSON.stringify(roleIds)
|
|
136
|
+
}));
|
|
137
|
+
return await this.processJsonResponse(res);
|
|
162
138
|
}
|
|
163
139
|
/**
|
|
164
140
|
* Remove a list roles from a user.
|
|
@@ -168,17 +144,15 @@ class ApiClient {
|
|
|
168
144
|
* @returns {Promise<void>}
|
|
169
145
|
* @memberof ApiClient
|
|
170
146
|
*/
|
|
171
|
-
deleteUserRoles(userId, roleIds) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
yield this.processJsonResponse(res);
|
|
181
|
-
});
|
|
147
|
+
async deleteUserRoles(userId, roleIds) {
|
|
148
|
+
const res = await fetch(`${this.baseUrl}public/user/${userId}/roles`, this.getMergeRequestInitOption({
|
|
149
|
+
method: "DELETE",
|
|
150
|
+
headers: {
|
|
151
|
+
"Content-Type": "application/json"
|
|
152
|
+
},
|
|
153
|
+
body: JSON.stringify(roleIds)
|
|
154
|
+
}));
|
|
155
|
+
await this.processJsonResponse(res);
|
|
182
156
|
}
|
|
183
157
|
/**
|
|
184
158
|
* Get all roles of a user
|
|
@@ -187,11 +161,9 @@ class ApiClient {
|
|
|
187
161
|
* @returns {Promise<Role[]>}
|
|
188
162
|
* @memberof ApiClient
|
|
189
163
|
*/
|
|
190
|
-
getUserRoles(userId) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return yield this.processJsonResponse(res);
|
|
194
|
-
});
|
|
164
|
+
async getUserRoles(userId) {
|
|
165
|
+
const res = await fetch(`${this.baseUrl}public/users/${userId}/roles`, this.getMergeRequestInitOption());
|
|
166
|
+
return await this.processJsonResponse(res);
|
|
195
167
|
}
|
|
196
168
|
/**
|
|
197
169
|
* Get all permissions of a user
|
|
@@ -200,11 +172,9 @@ class ApiClient {
|
|
|
200
172
|
* @returns {Promise<Permission[]>}
|
|
201
173
|
* @memberof ApiClient
|
|
202
174
|
*/
|
|
203
|
-
getUserPermissions(userId) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
return yield this.processJsonResponse(res);
|
|
207
|
-
});
|
|
175
|
+
async getUserPermissions(userId) {
|
|
176
|
+
const res = await fetch(`${this.baseUrl}public/users/${userId}/permissions`, this.getMergeRequestInitOption());
|
|
177
|
+
return await this.processJsonResponse(res);
|
|
208
178
|
}
|
|
209
179
|
/**
|
|
210
180
|
* Get all permissions of a role
|
|
@@ -213,11 +183,9 @@ class ApiClient {
|
|
|
213
183
|
* @returns {Promise<Permission[]>}
|
|
214
184
|
* @memberof ApiClient
|
|
215
185
|
*/
|
|
216
|
-
getRolePermissions(roleId) {
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return yield this.processJsonResponse(res);
|
|
220
|
-
});
|
|
186
|
+
async getRolePermissions(roleId) {
|
|
187
|
+
const res = await fetch(`${this.baseUrl}public/roles/${roleId}/permissions`, this.getMergeRequestInitOption());
|
|
188
|
+
return await this.processJsonResponse(res);
|
|
221
189
|
}
|
|
222
190
|
/**
|
|
223
191
|
* List OrgUnits at certain org tree level.
|
|
@@ -229,18 +197,16 @@ class ApiClient {
|
|
|
229
197
|
* @returns {Promise<OrgUnit[]>}
|
|
230
198
|
* @memberof ApiClient
|
|
231
199
|
*/
|
|
232
|
-
getOrgUnitsByLevel(orgLevel, relationshipOrgUnitId) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return yield this.processJsonResponse(res);
|
|
243
|
-
});
|
|
200
|
+
async getOrgUnitsByLevel(orgLevel, relationshipOrgUnitId) {
|
|
201
|
+
const uri = urijs(`${this.baseUrl}public/orgunits/bylevel`).segmentCoded(`${orgLevel}`);
|
|
202
|
+
const queries = {};
|
|
203
|
+
if (relationshipOrgUnitId) {
|
|
204
|
+
queries["relationshipOrgUnitId"] = relationshipOrgUnitId;
|
|
205
|
+
}
|
|
206
|
+
const res = await fetch(Object.keys(queries).length
|
|
207
|
+
? uri.search(queries).toString()
|
|
208
|
+
: uri.toString(), this.getMergeRequestInitOption());
|
|
209
|
+
return await this.processJsonResponse(res);
|
|
244
210
|
}
|
|
245
211
|
/**
|
|
246
212
|
* Get orgunits by name
|
|
@@ -251,19 +217,17 @@ class ApiClient {
|
|
|
251
217
|
* @returns {Promise<OrgUnit[]>}
|
|
252
218
|
* @memberof ApiClient
|
|
253
219
|
*/
|
|
254
|
-
getOrgUnitsByName(nodeName, leafNodesOnly = false, relationshipOrgUnitId) {
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return yield this.processJsonResponse(res);
|
|
266
|
-
});
|
|
220
|
+
async getOrgUnitsByName(nodeName, leafNodesOnly = false, relationshipOrgUnitId) {
|
|
221
|
+
const uri = urijs(`${this.baseUrl}public/orgunits`);
|
|
222
|
+
const queries = {
|
|
223
|
+
nodeName,
|
|
224
|
+
leafNodesOnly
|
|
225
|
+
};
|
|
226
|
+
if (relationshipOrgUnitId) {
|
|
227
|
+
queries["relationshipOrgUnitId"] = relationshipOrgUnitId;
|
|
228
|
+
}
|
|
229
|
+
const res = await fetch(uri.search(queries).toString(), this.getMergeRequestInitOption());
|
|
230
|
+
return await this.processJsonResponse(res);
|
|
267
231
|
}
|
|
268
232
|
/**
|
|
269
233
|
* Gets the root organisation unit (top of the tree).
|
|
@@ -271,11 +235,9 @@ class ApiClient {
|
|
|
271
235
|
* @returns {Promise<OrgUnit>}
|
|
272
236
|
* @memberof ApiClient
|
|
273
237
|
*/
|
|
274
|
-
getRootOrgUnit() {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
return yield this.processJsonResponse(res);
|
|
278
|
-
});
|
|
238
|
+
async getRootOrgUnit() {
|
|
239
|
+
const res = await fetch(`${this.baseUrl}public/orgunits/root`, this.getMergeRequestInitOption());
|
|
240
|
+
return await this.processJsonResponse(res);
|
|
279
241
|
}
|
|
280
242
|
/**
|
|
281
243
|
* Gets the details of the node with its id.
|
|
@@ -284,12 +246,10 @@ class ApiClient {
|
|
|
284
246
|
* @returns {Promise<OrgUnit>}
|
|
285
247
|
* @memberof ApiClient
|
|
286
248
|
*/
|
|
287
|
-
getOrgUnitById(nodeId) {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
return yield this.processJsonResponse(res);
|
|
292
|
-
});
|
|
249
|
+
async getOrgUnitById(nodeId) {
|
|
250
|
+
const uri = urijs(`${this.baseUrl}public/orgunits`).segmentCoded(nodeId);
|
|
251
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption());
|
|
252
|
+
return await this.processJsonResponse(res);
|
|
293
253
|
}
|
|
294
254
|
/**
|
|
295
255
|
* Gets all the children immediately below the requested node. If the node doesn't exist, returns an empty list.
|
|
@@ -298,15 +258,13 @@ class ApiClient {
|
|
|
298
258
|
* @returns {Promise<OrgUnit[]>}
|
|
299
259
|
* @memberof ApiClient
|
|
300
260
|
*/
|
|
301
|
-
getImmediateOrgUnitChildren(nodeId) {
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
return yield this.processJsonResponse(res);
|
|
309
|
-
});
|
|
261
|
+
async getImmediateOrgUnitChildren(nodeId) {
|
|
262
|
+
const uri = urijs(`${this.baseUrl}public/orgunits`)
|
|
263
|
+
.segmentCoded(nodeId)
|
|
264
|
+
.segmentCoded("children")
|
|
265
|
+
.segmentCoded("immediate");
|
|
266
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption());
|
|
267
|
+
return await this.processJsonResponse(res);
|
|
310
268
|
}
|
|
311
269
|
/**
|
|
312
270
|
* Gets all the children below the requested node recursively. If node doesn't exist, returns an empty list.
|
|
@@ -315,118 +273,99 @@ class ApiClient {
|
|
|
315
273
|
* @returns {Promise<OrgUnit[]>}
|
|
316
274
|
* @memberof ApiClient
|
|
317
275
|
*/
|
|
318
|
-
getAllOrgUnitChildren(nodeId) {
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return yield this.processJsonResponse(res);
|
|
326
|
-
});
|
|
276
|
+
async getAllOrgUnitChildren(nodeId) {
|
|
277
|
+
const uri = urijs(`${this.baseUrl}public/orgunits`)
|
|
278
|
+
.segmentCoded(nodeId)
|
|
279
|
+
.segmentCoded("children")
|
|
280
|
+
.segmentCoded("all");
|
|
281
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption());
|
|
282
|
+
return await this.processJsonResponse(res);
|
|
327
283
|
}
|
|
328
|
-
createOrgNode(parentNodeId, node) {
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return yield this.processJsonResponse(res);
|
|
338
|
-
});
|
|
284
|
+
async createOrgNode(parentNodeId, node) {
|
|
285
|
+
const uri = urijs(`${this.baseUrl}public/orgunits`)
|
|
286
|
+
.segmentCoded(parentNodeId)
|
|
287
|
+
.segmentCoded("insert");
|
|
288
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption({
|
|
289
|
+
method: "post",
|
|
290
|
+
body: JSON.stringify(node)
|
|
291
|
+
}));
|
|
292
|
+
return await this.processJsonResponse(res);
|
|
339
293
|
}
|
|
340
|
-
createRole(name, desc) {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
return yield this.processJsonResponse(res);
|
|
351
|
-
});
|
|
294
|
+
async createRole(name, desc) {
|
|
295
|
+
const uri = urijs(`${this.baseUrl}public/roles`);
|
|
296
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption({
|
|
297
|
+
method: "post",
|
|
298
|
+
body: JSON.stringify({
|
|
299
|
+
name,
|
|
300
|
+
description: desc ? desc : ""
|
|
301
|
+
})
|
|
302
|
+
}));
|
|
303
|
+
return await this.processJsonResponse(res);
|
|
352
304
|
}
|
|
353
|
-
createRolePermission(roleId, permissionData) {
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
return yield this.processJsonResponse(res);
|
|
364
|
-
});
|
|
305
|
+
async createRolePermission(roleId, permissionData) {
|
|
306
|
+
if (!isUuid(roleId)) {
|
|
307
|
+
throw new ServerError(`roleId: ${roleId} is not a valid UUID.`);
|
|
308
|
+
}
|
|
309
|
+
const uri = urijs(`${this.baseUrl}public/roles/${encodeURIComponent(roleId)}/permissions`);
|
|
310
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption({
|
|
311
|
+
method: "post",
|
|
312
|
+
body: JSON.stringify(permissionData)
|
|
313
|
+
}));
|
|
314
|
+
return await this.processJsonResponse(res);
|
|
365
315
|
}
|
|
366
|
-
createPermission(permissionData) {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
return yield this.processJsonResponse(res);
|
|
374
|
-
});
|
|
316
|
+
async createPermission(permissionData) {
|
|
317
|
+
const uri = urijs(`${this.baseUrl}public/permissions`);
|
|
318
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption({
|
|
319
|
+
method: "post",
|
|
320
|
+
body: JSON.stringify(permissionData)
|
|
321
|
+
}));
|
|
322
|
+
return await this.processJsonResponse(res);
|
|
375
323
|
}
|
|
376
|
-
updatePermission(id, permissionData) {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
return yield this.processJsonResponse(res);
|
|
387
|
-
});
|
|
324
|
+
async updatePermission(id, permissionData) {
|
|
325
|
+
if (!permissionData || !Object.keys(permissionData).length) {
|
|
326
|
+
throw new Error("Empty data supplied to update permission!");
|
|
327
|
+
}
|
|
328
|
+
const uri = urijs(`${this.baseUrl}public/permissions/${encodeURIComponent(id)}`);
|
|
329
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption({
|
|
330
|
+
method: "put",
|
|
331
|
+
body: JSON.stringify(permissionData)
|
|
332
|
+
}));
|
|
333
|
+
return await this.processJsonResponse(res);
|
|
388
334
|
}
|
|
389
|
-
getOperationByUri(opUri) {
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return yield this.processJsonResponse(res);
|
|
394
|
-
});
|
|
335
|
+
async getOperationByUri(opUri) {
|
|
336
|
+
const uri = urijs(`${this.baseUrl}public/operations/byUri/${opUri}`);
|
|
337
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption());
|
|
338
|
+
return await this.processJsonResponse(res);
|
|
395
339
|
}
|
|
396
|
-
getResourceByUri(resUri) {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
return yield this.processJsonResponse(res);
|
|
401
|
-
});
|
|
340
|
+
async getResourceByUri(resUri) {
|
|
341
|
+
const uri = urijs(`${this.baseUrl}public/resources/byUri/${resUri}`);
|
|
342
|
+
const res = await fetch(uri.toString(), this.getMergeRequestInitOption());
|
|
343
|
+
return await this.processJsonResponse(res);
|
|
402
344
|
}
|
|
403
|
-
handleGetResult(promise) {
|
|
404
|
-
return
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
throw e;
|
|
427
|
-
});
|
|
345
|
+
async handleGetResult(promise) {
|
|
346
|
+
return promise
|
|
347
|
+
.then((res) => {
|
|
348
|
+
if (res.status === 404) {
|
|
349
|
+
return Promise.resolve(Maybe.nothing());
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
return res
|
|
353
|
+
.text()
|
|
354
|
+
.then((resText) => {
|
|
355
|
+
try {
|
|
356
|
+
return JSON.parse(resText);
|
|
357
|
+
}
|
|
358
|
+
catch (e) {
|
|
359
|
+
throw new Error(resText);
|
|
360
|
+
}
|
|
361
|
+
})
|
|
362
|
+
.then((user) => Maybe.just(user));
|
|
363
|
+
}
|
|
364
|
+
})
|
|
365
|
+
.catch((e) => {
|
|
366
|
+
console.error(e);
|
|
367
|
+
throw e;
|
|
428
368
|
});
|
|
429
369
|
}
|
|
430
370
|
}
|
|
431
|
-
exports.default = ApiClient;
|
|
432
371
|
//# sourceMappingURL=ApiClient.js.map
|