@magda/typescript-common 1.2.0-rc.0 → 2.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/OpaCompileResponseParser.d.ts +147 -34
- package/dist/OpaCompileResponseParser.js +479 -293
- package/dist/OpaCompileResponseParser.js.map +1 -1
- package/dist/SQLUtils.d.ts +70 -0
- package/dist/SQLUtils.js +263 -0
- package/dist/SQLUtils.js.map +1 -0
- package/dist/ServerError.d.ts +9 -0
- package/dist/ServerError.js +17 -0
- package/dist/ServerError.js.map +1 -0
- package/dist/authorization-api/authMiddleware.d.ts +59 -1
- package/dist/authorization-api/authMiddleware.js +146 -3
- package/dist/authorization-api/authMiddleware.js.map +1 -1
- package/dist/authorization-api/constants.d.ts +5 -0
- package/dist/authorization-api/constants.js +13 -0
- package/dist/authorization-api/constants.js.map +1 -0
- package/dist/authorization-api/model.d.ts +1 -6
- package/dist/express/getNoCacheHeaders.d.ts +6 -0
- package/dist/express/getNoCacheHeaders.js +9 -0
- package/dist/express/getNoCacheHeaders.js.map +1 -0
- package/dist/express/setResponseNoCache.d.ts +3 -0
- package/dist/express/setResponseNoCache.js +9 -0
- package/dist/express/setResponseNoCache.js.map +1 -0
- package/dist/generated/registry/api.d.ts +36 -2
- package/dist/generated/registry/api.js +140 -2
- package/dist/generated/registry/api.js.map +1 -1
- package/dist/getAbsoluteUrl.d.ts +3 -2
- package/dist/getAbsoluteUrl.js +2 -1
- package/dist/getAbsoluteUrl.js.map +1 -1
- package/dist/opa/AspectQuery.d.ts +71 -0
- package/dist/opa/AspectQuery.js +216 -0
- package/dist/opa/AspectQuery.js.map +1 -0
- package/dist/opa/AuthDecision.d.ts +51 -0
- package/dist/opa/AuthDecision.js +241 -0
- package/dist/opa/AuthDecision.js.map +1 -0
- package/dist/opa/AuthDecisionQueryClient.d.ts +23 -0
- package/dist/opa/AuthDecisionQueryClient.js +110 -0
- package/dist/opa/AuthDecisionQueryClient.js.map +1 -0
- package/dist/pgTypes.d.ts +1 -0
- package/dist/pgTypes.js +18 -0
- package/dist/pgTypes.js.map +1 -0
- package/dist/registry/AuthorizedRegistryClient.d.ts +1 -0
- package/dist/registry/AuthorizedRegistryClient.js +17 -0
- package/dist/registry/AuthorizedRegistryClient.js.map +1 -1
- package/dist/registry/RegistryClient.d.ts +10 -0
- package/dist/registry/RegistryClient.js +32 -0
- package/dist/registry/RegistryClient.js.map +1 -1
- package/dist/test/getAuthDecision.spec.js +2 -2
- package/dist/test/getAuthDecision.spec.js.map +1 -1
- package/dist/test/sampleAuthDecisions/content.json +29 -0
- package/dist/test/sampleAuthDecisions/datasetPermissionWithOrgUnitConstraint.json +79 -0
- package/dist/test/sampleAuthDecisions/simple.json +29 -0
- package/dist/test/sampleAuthDecisions/singleTermAspectRef.json +39 -0
- package/dist/test/sampleAuthDecisions/unconditionalFalseSimple.json +6 -0
- package/dist/test/sampleAuthDecisions/unconditionalNotMacthed.json +6 -0
- package/dist/test/sampleAuthDecisions/unconditionalNotMacthedWithExtraRefs.json +6 -0
- package/dist/test/sampleAuthDecisions/unconditionalTrue.json +6 -0
- package/dist/test/sampleAuthDecisions/unconditionalTrueSimple.json +6 -0
- package/dist/test/sampleAuthDecisions/unconditionalTrueWithDefaultRule.json +6 -0
- package/dist/test/sampleAuthDecisions/withDefaultRule.json +6 -0
- package/dist/test/{sampleOpaResponse.json → sampleOpaResponses/content.json} +0 -0
- package/dist/test/sampleOpaResponses/datasetPermissionWithOrgUnitConstraint.json +341 -0
- package/dist/test/{sampleOpaResponseSimple.json → sampleOpaResponses/simple.json} +0 -0
- package/dist/test/sampleOpaResponses/singleTermAspectRef.json +233 -0
- package/dist/test/sampleOpaResponses/unconditionalFalseSimple.json +3 -0
- package/dist/test/sampleOpaResponses/unconditionalNotMacthed.json +73 -0
- package/dist/test/sampleOpaResponses/unconditionalNotMacthedWithExtraRefs.json +155 -0
- package/dist/test/{sampleOpaResponseUnconditionalTrue.json → sampleOpaResponses/unconditionalTrue.json} +0 -0
- package/dist/test/sampleOpaResponses/unconditionalTrueSimple.json +48 -0
- package/dist/test/{sampleOpaResponseUnconditionalTrueWithDefaultRule.json → sampleOpaResponses/unconditionalTrueWithDefaultRule.json} +0 -0
- package/dist/test/{sampleOpaResponseWithDefaultRule.json → sampleOpaResponses/withDefaultRule.json} +0 -0
- package/dist/test/testOpaCompileResponseParser.spec.js +195 -20
- package/dist/test/testOpaCompileResponseParser.spec.js.map +1 -1
- package/package.json +7 -3
|
@@ -1,11 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
2
11
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
13
|
};
|
|
5
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.mustBeAdmin = exports.getUser = exports.mustBeLoggedIn = void 0;
|
|
15
|
+
exports.requireUserId = exports.getUserId = exports.requirePermission = exports.requireUnconditionalAuthDecision = exports.withAuthDecision = exports.mustBeAdmin = exports.getUser = exports.mustBeLoggedIn = void 0;
|
|
7
16
|
const GetUserId_1 = require("../session/GetUserId");
|
|
8
17
|
const ApiClient_1 = __importDefault(require("./ApiClient"));
|
|
18
|
+
const AuthDecision_1 = require("../opa/AuthDecision");
|
|
19
|
+
const constants_1 = require("./constants");
|
|
9
20
|
exports.mustBeLoggedIn = (jwtSecret) => function (req, res, next) {
|
|
10
21
|
GetUserId_1.getUserIdHandling(req, res, jwtSecret, (userId) => {
|
|
11
22
|
this.userId = userId;
|
|
@@ -15,10 +26,10 @@ exports.mustBeLoggedIn = (jwtSecret) => function (req, res, next) {
|
|
|
15
26
|
/**
|
|
16
27
|
* Find the user making the request. Assign it to req passport style.
|
|
17
28
|
*/
|
|
18
|
-
exports.getUser = (baseAuthUrl, jwtSecret) => (req, res, next) => {
|
|
29
|
+
exports.getUser = (baseAuthUrl, jwtSecret, actionUserId) => (req, res, next) => {
|
|
19
30
|
GetUserId_1.getUserId(req, jwtSecret).caseOf({
|
|
20
31
|
just: (userId) => {
|
|
21
|
-
const apiClient = new ApiClient_1.default(baseAuthUrl, jwtSecret,
|
|
32
|
+
const apiClient = new ApiClient_1.default(baseAuthUrl, jwtSecret, actionUserId ? actionUserId : constants_1.DEFAULT_ADMIN_USER_ID);
|
|
22
33
|
apiClient
|
|
23
34
|
.getUser(userId)
|
|
24
35
|
.then((maybeUser) => {
|
|
@@ -49,4 +60,136 @@ exports.mustBeAdmin = (baseAuthUrl, jwtSecret) => {
|
|
|
49
60
|
});
|
|
50
61
|
};
|
|
51
62
|
};
|
|
63
|
+
/**
|
|
64
|
+
* Make auth decision based on auth decision request config.
|
|
65
|
+
* Depends on the config provided, either partial eval (conditional decision on a set of records/objects)
|
|
66
|
+
* Or unconditional decision for a single record / object will be returned via `res.locals.authDecision`.
|
|
67
|
+
*
|
|
68
|
+
* @export
|
|
69
|
+
* @param {AuthDecisionQueryClient} authDecisionClient
|
|
70
|
+
* @param {AuthDecisionReqConfig} config
|
|
71
|
+
* @return {*}
|
|
72
|
+
*/
|
|
73
|
+
function withAuthDecision(authDecisionClient, config) {
|
|
74
|
+
return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
try {
|
|
76
|
+
const jwtToken = req.get("X-Magda-Session");
|
|
77
|
+
const authDecision = yield authDecisionClient.getAuthDecision(config, jwtToken);
|
|
78
|
+
res.locals.authDecision = authDecision;
|
|
79
|
+
next();
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
console.error(`Failed to get auth decision: ${e}`);
|
|
83
|
+
res.status(500).send("An error occurred while retrieving auth decision for the request.");
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.withAuthDecision = withAuthDecision;
|
|
88
|
+
/**
|
|
89
|
+
* Require unconditional auth decision based on auth decision request config.
|
|
90
|
+
* When making decision on a group of records/objects, this method makes sure
|
|
91
|
+
* the user has permission to all records/objects regardless individual record / object's attributes.
|
|
92
|
+
*
|
|
93
|
+
* @export
|
|
94
|
+
* @param {AuthDecisionQueryClient} authDecisionClient
|
|
95
|
+
* @param {AuthDecisionReqConfig} config
|
|
96
|
+
* @param {boolean} [requiredDecision=true]
|
|
97
|
+
* @return {*}
|
|
98
|
+
*/
|
|
99
|
+
function requireUnconditionalAuthDecision(authDecisionClient, config, requiredDecision = true) {
|
|
100
|
+
return (req, res, next) => {
|
|
101
|
+
withAuthDecision(authDecisionClient, config)(req, res, () => {
|
|
102
|
+
const authDecision = res.locals.authDecision;
|
|
103
|
+
if ((authDecision === null || authDecision === void 0 ? void 0 : authDecision.hasResidualRules) === false &&
|
|
104
|
+
AuthDecision_1.isTrueEquivalent(authDecision === null || authDecision === void 0 ? void 0 : authDecision.result) == requiredDecision) {
|
|
105
|
+
return next();
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
res.status(403).send(`you are not permitted to perform \`${config.operationUri}\` on required resources.`);
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
exports.requireUnconditionalAuthDecision = requireUnconditionalAuthDecision;
|
|
114
|
+
/**
|
|
115
|
+
* require permission based on input data provided.
|
|
116
|
+
* Different from withAuthDecision, its method always set `unknowns` = Nil i.e. it will always attempt to make unconditional decision.
|
|
117
|
+
* It's for make decision for one single record / object. For partial eval for a set of records / objects, please use `withAuthDecision` or `requireUnconditionalAuthDecision`
|
|
118
|
+
*
|
|
119
|
+
* @export
|
|
120
|
+
* @param {AuthDecisionQueryClient} authDecisionClient
|
|
121
|
+
* @param {string} operationUri
|
|
122
|
+
* @param {(req: Request, res: Response) => { [key: string]: any }} [inputDataFunc]
|
|
123
|
+
* @return {*}
|
|
124
|
+
*/
|
|
125
|
+
function requirePermission(authDecisionClient, operationUri, inputDataFunc) {
|
|
126
|
+
return (req, res, next) => {
|
|
127
|
+
const config = {
|
|
128
|
+
operationUri,
|
|
129
|
+
unknowns: []
|
|
130
|
+
};
|
|
131
|
+
if (inputDataFunc) {
|
|
132
|
+
config.input = inputDataFunc(req, res);
|
|
133
|
+
}
|
|
134
|
+
withAuthDecision(authDecisionClient, config)(req, res, () => {
|
|
135
|
+
const authDecision = res.locals.authDecision;
|
|
136
|
+
if (authDecision === null || authDecision === void 0 ? void 0 : authDecision.hasResidualRules) {
|
|
137
|
+
console.warn(`Failed to make unconditional auth decision for operation '${operationUri}'.
|
|
138
|
+
"Input: ${config === null || config === void 0 ? void 0 : config.input}. `);
|
|
139
|
+
res.status(403).send(`you are not permitted to perform '${operationUri}': no unconditional decision can be made.`);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
if (AuthDecision_1.isTrueEquivalent(authDecision === null || authDecision === void 0 ? void 0 : authDecision.result)) {
|
|
143
|
+
return next();
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
res.status(403).send(`you are not permitted to perform \`${config.operationUri}\` on required resources.`);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
exports.requirePermission = requirePermission;
|
|
153
|
+
/**
|
|
154
|
+
* Try to locate userId from JwtToken.
|
|
155
|
+
* If can't find JWT token, return undefined via `res.locals.userId`
|
|
156
|
+
*
|
|
157
|
+
* @export
|
|
158
|
+
* @param {Request} req
|
|
159
|
+
* @param {Response} res
|
|
160
|
+
* @param {() => void} next
|
|
161
|
+
*/
|
|
162
|
+
function getUserId(req, res, next) {
|
|
163
|
+
GetUserId_1.getUserId(req, req.get("X-Magda-Session")).caseOf({
|
|
164
|
+
just: (userId) => {
|
|
165
|
+
res.locals.userId = userId;
|
|
166
|
+
next();
|
|
167
|
+
},
|
|
168
|
+
nothing: () => {
|
|
169
|
+
res.locals.userId = undefined;
|
|
170
|
+
next();
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
exports.getUserId = getUserId;
|
|
175
|
+
/**
|
|
176
|
+
* get current user ID from JWT token
|
|
177
|
+
* If can't locate userId, response 403 error
|
|
178
|
+
*
|
|
179
|
+
* @export
|
|
180
|
+
* @param {Request} req
|
|
181
|
+
* @param {Response} res
|
|
182
|
+
* @param {() => void} next
|
|
183
|
+
*/
|
|
184
|
+
function requireUserId(req, res, next) {
|
|
185
|
+
getUserId(req, res, () => {
|
|
186
|
+
if (!res.locals.userId) {
|
|
187
|
+
res.status(403).send("Anonymous users access are not permitted: userId is required.");
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
return next();
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
exports.requireUserId = requireUserId;
|
|
52
195
|
//# sourceMappingURL=authMiddleware.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"authMiddleware.js","sourceRoot":"","sources":["../../src/authorization-api/authMiddleware.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"authMiddleware.js","sourceRoot":"","sources":["../../src/authorization-api/authMiddleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,oDAG8B;AAC9B,4DAAoC;AAIpC,sDAAqE;AACrE,2CAAoD;AAEvC,QAAA,cAAc,GAAG,CAAC,SAAiB,EAAE,EAAE,CAChD,UAAqB,GAAY,EAAE,GAAa,EAAE,IAAgB;IAC9D,6BAAiB,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
|
|
2
|
+
export declare const AUTHENTICATED_USERS_ROLE_ID = "00000000-0000-0002-0000-000000000000";
|
|
3
|
+
export declare const ADMIN_USERS_ROLE_ID = "00000000-0000-0003-0000-000000000000";
|
|
4
|
+
export declare const DEFAULT_ADMIN_USER_ID = "00000000-0000-4000-8000-000000000000";
|
|
5
|
+
export declare const SYSTEM_ROLES: string[];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SYSTEM_ROLES = exports.DEFAULT_ADMIN_USER_ID = exports.ADMIN_USERS_ROLE_ID = exports.AUTHENTICATED_USERS_ROLE_ID = exports.ANONYMOUS_USERS_ROLE_ID = void 0;
|
|
4
|
+
exports.ANONYMOUS_USERS_ROLE_ID = "00000000-0000-0001-0000-000000000000";
|
|
5
|
+
exports.AUTHENTICATED_USERS_ROLE_ID = "00000000-0000-0002-0000-000000000000";
|
|
6
|
+
exports.ADMIN_USERS_ROLE_ID = "00000000-0000-0003-0000-000000000000";
|
|
7
|
+
exports.DEFAULT_ADMIN_USER_ID = "00000000-0000-4000-8000-000000000000";
|
|
8
|
+
exports.SYSTEM_ROLES = [
|
|
9
|
+
exports.ANONYMOUS_USERS_ROLE_ID,
|
|
10
|
+
exports.AUTHENTICATED_USERS_ROLE_ID,
|
|
11
|
+
exports.ADMIN_USERS_ROLE_ID
|
|
12
|
+
];
|
|
13
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/authorization-api/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,uBAAuB,GAAG,sCAAsC,CAAC;AACjE,QAAA,2BAA2B,GACpC,sCAAsC,CAAC;AAC9B,QAAA,mBAAmB,GAAG,sCAAsC,CAAC;AAC7D,QAAA,qBAAqB,GAAG,sCAAsC,CAAC;AAE/D,QAAA,YAAY,GAAG;IACxB,+BAAuB;IACvB,mCAA2B;IAC3B,2BAAmB;CACtB,CAAC"}
|
|
@@ -85,12 +85,7 @@ export interface UserToken {
|
|
|
85
85
|
* You only need this when you try to figure out user characteristic (unknown) via Known information of a dataset.
|
|
86
86
|
* i.e. set `input.user` to unknown then calculate residual rules via partial evaluation.
|
|
87
87
|
*/
|
|
88
|
-
export interface
|
|
89
|
-
/**
|
|
90
|
-
* We do allow "archived" as defined in `publishing.schema.json`
|
|
91
|
-
* But we probably should avoid using it as there is no story behinds it.
|
|
92
|
-
*/
|
|
93
|
-
publishingState: "draft" | "published" | "archived";
|
|
88
|
+
export interface AccessControlMetaData {
|
|
94
89
|
accessControl?: {
|
|
95
90
|
ownerId?: string;
|
|
96
91
|
orgUnitOwnerId?: string;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const getNoCacheHeaders = () => ({
|
|
4
|
+
"Cache-Control": "max-age=0, no-cache, must-revalidate, proxy-revalidate",
|
|
5
|
+
Expires: "Thu, 01 Jan 1970 00:00:00 GMT",
|
|
6
|
+
"Last-Modified": new Date().toUTCString()
|
|
7
|
+
});
|
|
8
|
+
exports.default = getNoCacheHeaders;
|
|
9
|
+
//# sourceMappingURL=getNoCacheHeaders.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNoCacheHeaders.js","sourceRoot":"","sources":["../../src/express/getNoCacheHeaders.ts"],"names":[],"mappings":";;AAAA,MAAM,iBAAiB,GAAG,GAAG,EAAE,CAAC,CAAC;IAC7B,eAAe,EAAE,wDAAwD;IACzE,OAAO,EAAE,+BAA+B;IACxC,eAAe,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;CAC5C,CAAC,CAAC;AAEH,kBAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const getNoCacheHeaders_1 = __importDefault(require("./getNoCacheHeaders"));
|
|
7
|
+
const setResponseNoCache = (res) => res.set(getNoCacheHeaders_1.default());
|
|
8
|
+
exports.default = setResponseNoCache;
|
|
9
|
+
//# sourceMappingURL=setResponseNoCache.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setResponseNoCache.js","sourceRoot":"","sources":["../../src/express/setResponseNoCache.ts"],"names":[],"mappings":";;;;;AACA,4EAAoD;AAEpD,MAAM,kBAAkB,GAAG,CAAC,GAAa,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,2BAAiB,EAAE,CAAC,CAAC;AAE3E,kBAAe,kBAAkB,CAAC"}
|
|
@@ -143,6 +143,11 @@ export declare class WebHook {
|
|
|
143
143
|
'retryCount': number;
|
|
144
144
|
'isRunning': any;
|
|
145
145
|
'isProcessing': any;
|
|
146
|
+
'ownerId': string;
|
|
147
|
+
'creatorId': string;
|
|
148
|
+
'editorId': string;
|
|
149
|
+
'createTime': Date;
|
|
150
|
+
'editTime': Date;
|
|
146
151
|
}
|
|
147
152
|
/**
|
|
148
153
|
* Asynchronously acknowledges receipt of a web hook notification.
|
|
@@ -230,8 +235,9 @@ export declare class AspectDefinitionsApi {
|
|
|
230
235
|
* Get a list of all aspects
|
|
231
236
|
*
|
|
232
237
|
* @param xMagdaTenantId 0
|
|
238
|
+
* @param xMagdaSession Magda internal session id
|
|
233
239
|
*/
|
|
234
|
-
getAll(xMagdaTenantId: number): Promise<{
|
|
240
|
+
getAll(xMagdaTenantId: number, xMagdaSession?: string): Promise<{
|
|
235
241
|
response: http.IncomingMessage;
|
|
236
242
|
body: Array<AspectDefinition>;
|
|
237
243
|
}>;
|
|
@@ -240,8 +246,9 @@ export declare class AspectDefinitionsApi {
|
|
|
240
246
|
*
|
|
241
247
|
* @param xMagdaTenantId 0
|
|
242
248
|
* @param id ID of the aspect to be fetched.
|
|
249
|
+
* @param xMagdaSession Magda internal session id
|
|
243
250
|
*/
|
|
244
|
-
getById(xMagdaTenantId: number, id: string): Promise<{
|
|
251
|
+
getById(xMagdaTenantId: number, id: string, xMagdaSession?: string): Promise<{
|
|
245
252
|
response: http.IncomingMessage;
|
|
246
253
|
body: AspectDefinition;
|
|
247
254
|
}>;
|
|
@@ -292,6 +299,33 @@ export declare class RecordAspectsApi {
|
|
|
292
299
|
response: http.IncomingMessage;
|
|
293
300
|
body: DeleteResult;
|
|
294
301
|
}>;
|
|
302
|
+
/**
|
|
303
|
+
* Get a list of a record's aspects
|
|
304
|
+
*
|
|
305
|
+
* @param xMagdaTenantId 0
|
|
306
|
+
* @param recordId ID of the record for which to fetch aspects.
|
|
307
|
+
* @param keyword Specify the keyword to search in the all aspects' aspectId & data fields.
|
|
308
|
+
* @param aspectIdOnly When set to true, will respond only an array contains aspect id only.
|
|
309
|
+
* @param start The index of the first record to retrieve.
|
|
310
|
+
* @param limit The maximum number of records to receive.
|
|
311
|
+
* @param xMagdaSession Magda internal session id
|
|
312
|
+
*/
|
|
313
|
+
getAspects(xMagdaTenantId: number, recordId: string, keyword?: string, aspectIdOnly?: boolean, start?: number, limit?: number, xMagdaSession?: string): Promise<{
|
|
314
|
+
response: http.IncomingMessage;
|
|
315
|
+
body: Array<any>;
|
|
316
|
+
}>;
|
|
317
|
+
/**
|
|
318
|
+
* Get the number of aspects that a record has
|
|
319
|
+
*
|
|
320
|
+
* @param xMagdaTenantId 0
|
|
321
|
+
* @param recordId ID of the record for which to fetch an aspect.
|
|
322
|
+
* @param keyword Specify the keyword to search in the all aspects' aspectId & data fields.
|
|
323
|
+
* @param xMagdaSession Magda internal session id
|
|
324
|
+
*/
|
|
325
|
+
getAspectsCount(xMagdaTenantId: number, recordId: string, keyword?: string, xMagdaSession?: string): Promise<{
|
|
326
|
+
response: http.IncomingMessage;
|
|
327
|
+
body: CountResponse;
|
|
328
|
+
}>;
|
|
295
329
|
/**
|
|
296
330
|
* Get a record aspect by ID
|
|
297
331
|
*
|
|
@@ -214,8 +214,9 @@ class AspectDefinitionsApi {
|
|
|
214
214
|
* Get a list of all aspects
|
|
215
215
|
*
|
|
216
216
|
* @param xMagdaTenantId 0
|
|
217
|
+
* @param xMagdaSession Magda internal session id
|
|
217
218
|
*/
|
|
218
|
-
getAll(xMagdaTenantId) {
|
|
219
|
+
getAll(xMagdaTenantId, xMagdaSession) {
|
|
219
220
|
const localVarPath = this.basePath + '/aspects';
|
|
220
221
|
let queryParameters = {};
|
|
221
222
|
let headerParams = Object.assign({}, this.defaultHeaders);
|
|
@@ -225,6 +226,7 @@ class AspectDefinitionsApi {
|
|
|
225
226
|
throw new Error('Required parameter xMagdaTenantId was null or undefined when calling getAll.');
|
|
226
227
|
}
|
|
227
228
|
headerParams['X-Magda-Tenant-Id'] = xMagdaTenantId;
|
|
229
|
+
headerParams['X-Magda-Session'] = xMagdaSession;
|
|
228
230
|
let useFormData = false;
|
|
229
231
|
let requestOptions = {
|
|
230
232
|
method: 'GET',
|
|
@@ -264,8 +266,9 @@ class AspectDefinitionsApi {
|
|
|
264
266
|
*
|
|
265
267
|
* @param xMagdaTenantId 0
|
|
266
268
|
* @param id ID of the aspect to be fetched.
|
|
269
|
+
* @param xMagdaSession Magda internal session id
|
|
267
270
|
*/
|
|
268
|
-
getById(xMagdaTenantId, id) {
|
|
271
|
+
getById(xMagdaTenantId, id, xMagdaSession) {
|
|
269
272
|
const localVarPath = this.basePath + '/aspects/{id}'
|
|
270
273
|
.replace('{' + 'id' + '}', String(id));
|
|
271
274
|
let queryParameters = {};
|
|
@@ -280,6 +283,7 @@ class AspectDefinitionsApi {
|
|
|
280
283
|
throw new Error('Required parameter id was null or undefined when calling getById.');
|
|
281
284
|
}
|
|
282
285
|
headerParams['X-Magda-Tenant-Id'] = xMagdaTenantId;
|
|
286
|
+
headerParams['X-Magda-Session'] = xMagdaSession;
|
|
283
287
|
let useFormData = false;
|
|
284
288
|
let requestOptions = {
|
|
285
289
|
method: 'GET',
|
|
@@ -545,6 +549,140 @@ class RecordAspectsApi {
|
|
|
545
549
|
});
|
|
546
550
|
});
|
|
547
551
|
}
|
|
552
|
+
/**
|
|
553
|
+
* Get a list of a record's aspects
|
|
554
|
+
*
|
|
555
|
+
* @param xMagdaTenantId 0
|
|
556
|
+
* @param recordId ID of the record for which to fetch aspects.
|
|
557
|
+
* @param keyword Specify the keyword to search in the all aspects' aspectId & data fields.
|
|
558
|
+
* @param aspectIdOnly When set to true, will respond only an array contains aspect id only.
|
|
559
|
+
* @param start The index of the first record to retrieve.
|
|
560
|
+
* @param limit The maximum number of records to receive.
|
|
561
|
+
* @param xMagdaSession Magda internal session id
|
|
562
|
+
*/
|
|
563
|
+
getAspects(xMagdaTenantId, recordId, keyword, aspectIdOnly, start, limit, xMagdaSession) {
|
|
564
|
+
const localVarPath = this.basePath + '/records/{recordId}/aspects'
|
|
565
|
+
.replace('{' + 'recordId' + '}', String(recordId));
|
|
566
|
+
let queryParameters = {};
|
|
567
|
+
let headerParams = Object.assign({}, this.defaultHeaders);
|
|
568
|
+
let formParams = {};
|
|
569
|
+
// verify required parameter 'xMagdaTenantId' is not null or undefined
|
|
570
|
+
if (xMagdaTenantId === null || xMagdaTenantId === undefined) {
|
|
571
|
+
throw new Error('Required parameter xMagdaTenantId was null or undefined when calling getAspects.');
|
|
572
|
+
}
|
|
573
|
+
// verify required parameter 'recordId' is not null or undefined
|
|
574
|
+
if (recordId === null || recordId === undefined) {
|
|
575
|
+
throw new Error('Required parameter recordId was null or undefined when calling getAspects.');
|
|
576
|
+
}
|
|
577
|
+
if (keyword !== undefined) {
|
|
578
|
+
queryParameters['keyword'] = keyword;
|
|
579
|
+
}
|
|
580
|
+
if (aspectIdOnly !== undefined) {
|
|
581
|
+
queryParameters['aspectIdOnly'] = aspectIdOnly;
|
|
582
|
+
}
|
|
583
|
+
if (start !== undefined) {
|
|
584
|
+
queryParameters['start'] = start;
|
|
585
|
+
}
|
|
586
|
+
if (limit !== undefined) {
|
|
587
|
+
queryParameters['limit'] = limit;
|
|
588
|
+
}
|
|
589
|
+
headerParams['X-Magda-Tenant-Id'] = xMagdaTenantId;
|
|
590
|
+
headerParams['X-Magda-Session'] = xMagdaSession;
|
|
591
|
+
let useFormData = false;
|
|
592
|
+
let requestOptions = {
|
|
593
|
+
method: 'GET',
|
|
594
|
+
qs: queryParameters,
|
|
595
|
+
headers: headerParams,
|
|
596
|
+
uri: localVarPath,
|
|
597
|
+
useQuerystring: this._useQuerystring,
|
|
598
|
+
json: true,
|
|
599
|
+
};
|
|
600
|
+
this.authentications.default.applyToRequest(requestOptions);
|
|
601
|
+
if (Object.keys(formParams).length) {
|
|
602
|
+
if (useFormData) {
|
|
603
|
+
requestOptions.formData = formParams;
|
|
604
|
+
}
|
|
605
|
+
else {
|
|
606
|
+
requestOptions.form = formParams;
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
return new Promise((resolve, reject) => {
|
|
610
|
+
request(requestOptions, (error, response, body) => {
|
|
611
|
+
if (error) {
|
|
612
|
+
reject(error);
|
|
613
|
+
}
|
|
614
|
+
else {
|
|
615
|
+
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
|
616
|
+
resolve({ response: response, body: body });
|
|
617
|
+
}
|
|
618
|
+
else {
|
|
619
|
+
reject({ response: response, body: body });
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Get the number of aspects that a record has
|
|
627
|
+
*
|
|
628
|
+
* @param xMagdaTenantId 0
|
|
629
|
+
* @param recordId ID of the record for which to fetch an aspect.
|
|
630
|
+
* @param keyword Specify the keyword to search in the all aspects' aspectId & data fields.
|
|
631
|
+
* @param xMagdaSession Magda internal session id
|
|
632
|
+
*/
|
|
633
|
+
getAspectsCount(xMagdaTenantId, recordId, keyword, xMagdaSession) {
|
|
634
|
+
const localVarPath = this.basePath + '/records/{recordId}/aspects/count'
|
|
635
|
+
.replace('{' + 'recordId' + '}', String(recordId));
|
|
636
|
+
let queryParameters = {};
|
|
637
|
+
let headerParams = Object.assign({}, this.defaultHeaders);
|
|
638
|
+
let formParams = {};
|
|
639
|
+
// verify required parameter 'xMagdaTenantId' is not null or undefined
|
|
640
|
+
if (xMagdaTenantId === null || xMagdaTenantId === undefined) {
|
|
641
|
+
throw new Error('Required parameter xMagdaTenantId was null or undefined when calling getAspectsCount.');
|
|
642
|
+
}
|
|
643
|
+
// verify required parameter 'recordId' is not null or undefined
|
|
644
|
+
if (recordId === null || recordId === undefined) {
|
|
645
|
+
throw new Error('Required parameter recordId was null or undefined when calling getAspectsCount.');
|
|
646
|
+
}
|
|
647
|
+
if (keyword !== undefined) {
|
|
648
|
+
queryParameters['keyword'] = keyword;
|
|
649
|
+
}
|
|
650
|
+
headerParams['X-Magda-Tenant-Id'] = xMagdaTenantId;
|
|
651
|
+
headerParams['X-Magda-Session'] = xMagdaSession;
|
|
652
|
+
let useFormData = false;
|
|
653
|
+
let requestOptions = {
|
|
654
|
+
method: 'GET',
|
|
655
|
+
qs: queryParameters,
|
|
656
|
+
headers: headerParams,
|
|
657
|
+
uri: localVarPath,
|
|
658
|
+
useQuerystring: this._useQuerystring,
|
|
659
|
+
json: true,
|
|
660
|
+
};
|
|
661
|
+
this.authentications.default.applyToRequest(requestOptions);
|
|
662
|
+
if (Object.keys(formParams).length) {
|
|
663
|
+
if (useFormData) {
|
|
664
|
+
requestOptions.formData = formParams;
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
requestOptions.form = formParams;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
return new Promise((resolve, reject) => {
|
|
671
|
+
request(requestOptions, (error, response, body) => {
|
|
672
|
+
if (error) {
|
|
673
|
+
reject(error);
|
|
674
|
+
}
|
|
675
|
+
else {
|
|
676
|
+
if (response.statusCode >= 200 && response.statusCode <= 299) {
|
|
677
|
+
resolve({ response: response, body: body });
|
|
678
|
+
}
|
|
679
|
+
else {
|
|
680
|
+
reject({ response: response, body: body });
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
});
|
|
684
|
+
});
|
|
685
|
+
}
|
|
548
686
|
/**
|
|
549
687
|
* Get a record aspect by ID
|
|
550
688
|
*
|