@magda/typescript-common 1.2.1 → 2.0.0-alpha.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.
Files changed (84) hide show
  1. package/dist/OpaCompileResponseParser.d.ts +260 -36
  2. package/dist/OpaCompileResponseParser.js +697 -297
  3. package/dist/OpaCompileResponseParser.js.map +1 -1
  4. package/dist/SQLUtils.d.ts +70 -0
  5. package/dist/SQLUtils.js +263 -0
  6. package/dist/SQLUtils.js.map +1 -0
  7. package/dist/ServerError.d.ts +9 -0
  8. package/dist/ServerError.js +17 -0
  9. package/dist/ServerError.js.map +1 -0
  10. package/dist/authorization-api/authMiddleware.d.ts +60 -1
  11. package/dist/authorization-api/authMiddleware.js +155 -3
  12. package/dist/authorization-api/authMiddleware.js.map +1 -1
  13. package/dist/authorization-api/constants.d.ts +5 -0
  14. package/dist/authorization-api/constants.js +13 -0
  15. package/dist/authorization-api/constants.js.map +1 -0
  16. package/dist/authorization-api/model.d.ts +2 -7
  17. package/dist/express/getNoCacheHeaders.d.ts +6 -0
  18. package/dist/express/getNoCacheHeaders.js +9 -0
  19. package/dist/express/getNoCacheHeaders.js.map +1 -0
  20. package/dist/express/setResponseNoCache.d.ts +3 -0
  21. package/dist/express/setResponseNoCache.js +9 -0
  22. package/dist/express/setResponseNoCache.js.map +1 -0
  23. package/dist/generated/registry/api.d.ts +47 -2
  24. package/dist/generated/registry/api.js +197 -2
  25. package/dist/generated/registry/api.js.map +1 -1
  26. package/dist/getAbsoluteUrl.d.ts +3 -2
  27. package/dist/getAbsoluteUrl.js +2 -1
  28. package/dist/getAbsoluteUrl.js.map +1 -1
  29. package/dist/getStorageUrl.d.ts +34 -0
  30. package/dist/getStorageUrl.js +138 -0
  31. package/dist/getStorageUrl.js.map +1 -0
  32. package/dist/handleServerError.d.ts +2 -0
  33. package/dist/handleServerError.js +17 -0
  34. package/dist/handleServerError.js.map +1 -0
  35. package/dist/opa/AspectQuery.d.ts +71 -0
  36. package/dist/opa/AspectQuery.js +219 -0
  37. package/dist/opa/AspectQuery.js.map +1 -0
  38. package/dist/opa/AuthDecision.d.ts +51 -0
  39. package/dist/opa/AuthDecision.js +241 -0
  40. package/dist/opa/AuthDecision.js.map +1 -0
  41. package/dist/opa/AuthDecisionQueryClient.d.ts +23 -0
  42. package/dist/opa/AuthDecisionQueryClient.js +113 -0
  43. package/dist/opa/AuthDecisionQueryClient.js.map +1 -0
  44. package/dist/pgTypes.d.ts +1 -0
  45. package/dist/pgTypes.js +18 -0
  46. package/dist/pgTypes.js.map +1 -0
  47. package/dist/registry/AuthorizedRegistryClient.d.ts +1 -0
  48. package/dist/registry/AuthorizedRegistryClient.js +17 -0
  49. package/dist/registry/AuthorizedRegistryClient.js.map +1 -1
  50. package/dist/registry/RegistryClient.d.ts +11 -0
  51. package/dist/registry/RegistryClient.js +46 -0
  52. package/dist/registry/RegistryClient.js.map +1 -1
  53. package/dist/test/getAuthDecision.spec.js +2 -2
  54. package/dist/test/getAuthDecision.spec.js.map +1 -1
  55. package/dist/test/getStorageUrl.spec.d.ts +1 -0
  56. package/dist/test/getStorageUrl.spec.js +95 -0
  57. package/dist/test/getStorageUrl.spec.js.map +1 -0
  58. package/dist/test/sampleAuthDecisions/content.json +29 -0
  59. package/dist/test/sampleAuthDecisions/datasetPermissionWithOrgUnitConstraint.json +79 -0
  60. package/dist/test/sampleAuthDecisions/extraLargeResponse.json +2519 -0
  61. package/dist/test/sampleAuthDecisions/simple.json +29 -0
  62. package/dist/test/sampleAuthDecisions/singleTermAspectRef.json +39 -0
  63. package/dist/test/sampleAuthDecisions/unconditionalFalseSimple.json +6 -0
  64. package/dist/test/sampleAuthDecisions/unconditionalNotMacthed.json +6 -0
  65. package/dist/test/sampleAuthDecisions/unconditionalNotMacthedWithExtraRefs.json +6 -0
  66. package/dist/test/sampleAuthDecisions/unconditionalTrue.json +6 -0
  67. package/dist/test/sampleAuthDecisions/unconditionalTrueSimple.json +6 -0
  68. package/dist/test/sampleAuthDecisions/unconditionalTrueWithDefaultRule.json +6 -0
  69. package/dist/test/sampleAuthDecisions/withDefaultRule.json +6 -0
  70. package/dist/test/{sampleOpaResponse.json → sampleOpaResponses/content.json} +0 -0
  71. package/dist/test/sampleOpaResponses/datasetPermissionWithOrgUnitConstraint.json +341 -0
  72. package/dist/test/sampleOpaResponses/extraLargeResponse.json +104869 -0
  73. package/dist/test/{sampleOpaResponseSimple.json → sampleOpaResponses/simple.json} +0 -0
  74. package/dist/test/sampleOpaResponses/singleTermAspectRef.json +233 -0
  75. package/dist/test/sampleOpaResponses/unconditionalFalseSimple.json +3 -0
  76. package/dist/test/sampleOpaResponses/unconditionalNotMacthed.json +73 -0
  77. package/dist/test/sampleOpaResponses/unconditionalNotMacthedWithExtraRefs.json +155 -0
  78. package/dist/test/{sampleOpaResponseUnconditionalTrue.json → sampleOpaResponses/unconditionalTrue.json} +0 -0
  79. package/dist/test/sampleOpaResponses/unconditionalTrueSimple.json +48 -0
  80. package/dist/test/{sampleOpaResponseUnconditionalTrueWithDefaultRule.json → sampleOpaResponses/unconditionalTrueWithDefaultRule.json} +0 -0
  81. package/dist/test/{sampleOpaResponseWithDefaultRule.json → sampleOpaResponses/withDefaultRule.json} +0 -0
  82. package/dist/test/testOpaCompileResponseParser.spec.js +212 -20
  83. package/dist/test/testOpaCompileResponseParser.spec.js.map +1 -1
  84. package/package.json +9 -3
@@ -1,11 +1,24 @@
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");
20
+ const ServerError_1 = __importDefault(require("../ServerError"));
21
+ // deprecated middleware. To be removed after all code is secured with new model
9
22
  exports.mustBeLoggedIn = (jwtSecret) => function (req, res, next) {
10
23
  GetUserId_1.getUserIdHandling(req, res, jwtSecret, (userId) => {
11
24
  this.userId = userId;
@@ -14,11 +27,12 @@ exports.mustBeLoggedIn = (jwtSecret) => function (req, res, next) {
14
27
  };
15
28
  /**
16
29
  * Find the user making the request. Assign it to req passport style.
30
+ * !deprecated! should use middleware `getUserId` or `requireUserId` instead.
17
31
  */
18
- exports.getUser = (baseAuthUrl, jwtSecret) => (req, res, next) => {
32
+ exports.getUser = (baseAuthUrl, jwtSecret, actionUserId) => (req, res, next) => {
19
33
  GetUserId_1.getUserId(req, jwtSecret).caseOf({
20
34
  just: (userId) => {
21
- const apiClient = new ApiClient_1.default(baseAuthUrl, jwtSecret, userId);
35
+ const apiClient = new ApiClient_1.default(baseAuthUrl, jwtSecret, actionUserId ? actionUserId : constants_1.DEFAULT_ADMIN_USER_ID);
22
36
  apiClient
23
37
  .getUser(userId)
24
38
  .then((maybeUser) => {
@@ -35,6 +49,7 @@ exports.getUser = (baseAuthUrl, jwtSecret) => (req, res, next) => {
35
49
  nothing: next
36
50
  });
37
51
  };
52
+ // deprecated middleware. To be removed after all code is secured with new model
38
53
  exports.mustBeAdmin = (baseAuthUrl, jwtSecret) => {
39
54
  const getUserInstance = exports.getUser(baseAuthUrl, jwtSecret);
40
55
  return (req, res, next) => {
@@ -49,4 +64,141 @@ exports.mustBeAdmin = (baseAuthUrl, jwtSecret) => {
49
64
  });
50
65
  };
51
66
  };
67
+ /**
68
+ * Make auth decision based on auth decision request config.
69
+ * Depends on the config provided, either partial eval (conditional decision on a set of records/objects)
70
+ * Or unconditional decision for a single record / object will be returned via `res.locals.authDecision`.
71
+ *
72
+ * @export
73
+ * @param {AuthDecisionQueryClient} authDecisionClient
74
+ * @param {AuthDecisionReqConfig} config
75
+ * @return {*}
76
+ */
77
+ function withAuthDecision(authDecisionClient, config) {
78
+ return (req, res, next) => __awaiter(this, void 0, void 0, function* () {
79
+ try {
80
+ const jwtToken = req.get("X-Magda-Session");
81
+ const authDecision = yield authDecisionClient.getAuthDecision(config, jwtToken);
82
+ res.locals.authDecision = authDecision;
83
+ next();
84
+ }
85
+ catch (e) {
86
+ console.error(`withAuthDecision middleware error: ${e}`);
87
+ if (e instanceof ServerError_1.default) {
88
+ res.status(e.statusCode).send(e.message);
89
+ }
90
+ else {
91
+ res.status(500).send(`An error occurred while retrieving auth decision for the request: ${e}`);
92
+ }
93
+ }
94
+ });
95
+ }
96
+ exports.withAuthDecision = withAuthDecision;
97
+ /**
98
+ * Require unconditional auth decision based on auth decision request config.
99
+ * When making decision on a group of records/objects, this method makes sure
100
+ * the user has permission to all records/objects regardless individual record / object's attributes.
101
+ *
102
+ * @export
103
+ * @param {AuthDecisionQueryClient} authDecisionClient
104
+ * @param {AuthDecisionReqConfig} config
105
+ * @param {boolean} [requiredDecision=true]
106
+ * @return {*}
107
+ */
108
+ function requireUnconditionalAuthDecision(authDecisionClient, config, requiredDecision = true) {
109
+ return (req, res, next) => {
110
+ withAuthDecision(authDecisionClient, config)(req, res, () => {
111
+ const authDecision = res.locals.authDecision;
112
+ if ((authDecision === null || authDecision === void 0 ? void 0 : authDecision.hasResidualRules) === false &&
113
+ AuthDecision_1.isTrueEquivalent(authDecision === null || authDecision === void 0 ? void 0 : authDecision.result) == requiredDecision) {
114
+ return next();
115
+ }
116
+ else {
117
+ res.status(403).send(`you are not permitted to perform \`${config.operationUri}\` on required resources.`);
118
+ }
119
+ });
120
+ };
121
+ }
122
+ exports.requireUnconditionalAuthDecision = requireUnconditionalAuthDecision;
123
+ /**
124
+ * require permission based on input data provided.
125
+ * Different from withAuthDecision, its method always set `unknowns` = Nil i.e. it will always attempt to make unconditional decision.
126
+ * It's for make decision for one single record / object. For partial eval for a set of records / objects, please use `withAuthDecision` or `requireUnconditionalAuthDecision`
127
+ *
128
+ * @export
129
+ * @param {AuthDecisionQueryClient} authDecisionClient
130
+ * @param {string} operationUri
131
+ * @param {InputDataOrFuncType} [inputDataFunc] either a function that produce input data (auth decision context data) from `req` & `req` or a plain object
132
+ * @return {*}
133
+ */
134
+ function requirePermission(authDecisionClient, operationUri, inputDataOrFunc) {
135
+ return (req, res, next) => {
136
+ try {
137
+ const config = {
138
+ operationUri,
139
+ unknowns: []
140
+ };
141
+ if (inputDataOrFunc) {
142
+ if (typeof inputDataOrFunc === "function") {
143
+ config.input = inputDataOrFunc(req, res);
144
+ }
145
+ else {
146
+ config.input = inputDataOrFunc;
147
+ }
148
+ }
149
+ requireUnconditionalAuthDecision(authDecisionClient, config, true)(req, res, next);
150
+ }
151
+ catch (e) {
152
+ console.error(`requirePermission middleware error: ${e}`);
153
+ if (e instanceof ServerError_1.default) {
154
+ res.status(e.statusCode).send(e.message);
155
+ }
156
+ else {
157
+ res.status(500).send(`requirePermission middleware error: ${e}`);
158
+ }
159
+ }
160
+ };
161
+ }
162
+ exports.requirePermission = requirePermission;
163
+ /**
164
+ * Try to locate userId from JwtToken.
165
+ * If can't find JWT token, return undefined via `res.locals.userId`
166
+ *
167
+ * @export
168
+ * @param {Request} req
169
+ * @param {Response} res
170
+ * @param {() => void} next
171
+ */
172
+ function getUserId(jwtSecret) {
173
+ return (req, res, next) => {
174
+ GetUserId_1.getUserId(req, jwtSecret).caseOf({
175
+ just: (userId) => {
176
+ res.locals.userId = userId;
177
+ next();
178
+ },
179
+ nothing: () => {
180
+ res.locals.userId = undefined;
181
+ next();
182
+ }
183
+ });
184
+ };
185
+ }
186
+ exports.getUserId = getUserId;
187
+ /**
188
+ * get current user ID from JWT token
189
+ * If can't locate userId, response 403 error
190
+ *
191
+ * @export
192
+ * @param {Request} req
193
+ * @param {Response} res
194
+ * @param {() => void} next
195
+ */
196
+ exports.requireUserId = (jwtSecret) => (req, res, next) => getUserId(jwtSecret)(req, res, () => {
197
+ if (!res.locals.userId) {
198
+ res.status(403).send("Anonymous users access are not permitted: userId is required.");
199
+ }
200
+ else {
201
+ return next();
202
+ }
203
+ });
52
204
  //# sourceMappingURL=authMiddleware.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authMiddleware.js","sourceRoot":"","sources":["../../src/authorization-api/authMiddleware.ts"],"names":[],"mappings":";;;;;;AACA,oDAAoE;AACpE,4DAAoC;AAEvB,QAAA,cAAc,GAAG,CAAC,SAAiB,EAAE,EAAE,CAChD,UAAqB,GAAY,EAAE,GAAa,EAAE,IAAgB;IAC9D,6BAAiB,CAAC,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC,MAAc,EAAE,EAAE;QACtD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,EAAE,CAAC;IACX,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEN;;GAEG;AACU,QAAA,OAAO,GAAG,CAAC,WAAmB,EAAE,SAAiB,EAAE,EAAE,CAAC,CAC/D,GAAY,EACZ,GAAa,EACb,IAAgB,EAClB,EAAE;IACA,qBAAS,CAAC,GAAG,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC;QAC7B,IAAI,EAAE,CAAC,MAAM,EAAE,EAAE;YACb,MAAM,SAAS,GAAG,IAAI,mBAAS,CAAC,WAAW,EAAE,SAAS,EAAE,MAAM,CAAC,CAAC;YAChE,SAAS;iBACJ,OAAO,CAAC,MAAM,CAAC;iBACf,IAAI,CAAC,CAAC,SAAS,EAAE,EAAE;gBAChB,SAAS,CAAC,MAAM,CAAC;oBACb,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;wBACX,GAAG,CAAC,IAAI,mCAID,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,GAC1B,IAAI,CACV,CAAC;wBACF,IAAI,EAAE,CAAC;oBACX,CAAC;oBACD,OAAO,EAAE,IAAI;iBAChB,CAAC,CAAC;YACP,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,CAAC,CAAC;QAC7B,CAAC;QACD,OAAO,EAAE,IAAI;KAChB,CAAC,CAAC;AACP,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,CAAC,WAAmB,EAAE,SAAiB,EAAE,EAAE;IAClE,MAAM,eAAe,GAAG,eAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACxD,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAgB,EAAE,EAAE;QACrD,eAAe,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;YAC3B,IAAI,GAAG,CAAC,IAAI,IAAK,GAAG,CAAC,IAAY,CAAC,OAAO,EAAE;gBACvC,IAAI,EAAE,CAAC;aACV;iBAAM;gBACH,OAAO,CAAC,IAAI,CAAC,wCAAwC,CAAC,CAAC;gBACvD,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC;aAC3C;QACL,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;AACN,CAAC,CAAC"}
1
+ {"version":3,"file":"authMiddleware.js","sourceRoot":"","sources":["../../src/authorization-api/authMiddleware.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AACA,oDAG8B;AAC9B,4DAAoC;AAIpC,sDAAqE;AACrE,2CAAoD;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,CAAC,MAAM,EAAE;QACpB,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAChB,+DAA+D,CAClE,CAAC;KACL;SAAM;QACH,OAAO,IAAI,EAAE,CAAC;KACjB;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const ANONYMOUS_USERS_ROLE_ID = "00000000-0000-0001-0000-000000000000";
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,15 +85,10 @@ 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 DatasetAccessControlMetaData {
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
- orgUnitOwnerId?: string;
91
+ orgUnitId?: string;
97
92
  preAuthorisedPermissionIds?: string[];
98
93
  };
99
94
  }
@@ -0,0 +1,6 @@
1
+ declare const getNoCacheHeaders: () => {
2
+ "Cache-Control": string;
3
+ Expires: string;
4
+ "Last-Modified": string;
5
+ };
6
+ export default getNoCacheHeaders;
@@ -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,3 @@
1
+ import { Response } from "express";
2
+ declare const setResponseNoCache: (res: Response) => Response<any>;
3
+ export default setResponseNoCache;
@@ -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&#39;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&#39; aspectId &amp; 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&#39; aspectId &amp; 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
  *
@@ -449,6 +483,17 @@ export declare class RecordsApi {
449
483
  response: http.IncomingMessage;
450
484
  body: Record;
451
485
  }>;
486
+ /**
487
+ * Get a record in full by ID
488
+ * Get a record with all attached aspects data by the record ID.
489
+ * @param id ID of the record to be fetched.
490
+ * @param xMagdaTenantId 0
491
+ * @param xMagdaSession Magda internal session id
492
+ */
493
+ getByIdInFull(id: string, xMagdaTenantId: number, xMagdaSession?: string): Promise<{
494
+ response: http.IncomingMessage;
495
+ body: Record;
496
+ }>;
452
497
  /**
453
498
  * Get a summary record by ID
454
499
  * Gets a summary record, including all the aspect ids for which this record has data.
@@ -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&#39;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&#39; aspectId &amp; 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&#39; aspectId &amp; 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
  *
@@ -1305,6 +1443,63 @@ class RecordsApi {
1305
1443
  });
1306
1444
  });
1307
1445
  }
1446
+ /**
1447
+ * Get a record in full by ID
1448
+ * Get a record with all attached aspects data by the record ID.
1449
+ * @param id ID of the record to be fetched.
1450
+ * @param xMagdaTenantId 0
1451
+ * @param xMagdaSession Magda internal session id
1452
+ */
1453
+ getByIdInFull(id, xMagdaTenantId, xMagdaSession) {
1454
+ const localVarPath = this.basePath + '/records/inFull/{id}'
1455
+ .replace('{' + 'id' + '}', String(id));
1456
+ let queryParameters = {};
1457
+ let headerParams = Object.assign({}, this.defaultHeaders);
1458
+ let formParams = {};
1459
+ // verify required parameter 'id' is not null or undefined
1460
+ if (id === null || id === undefined) {
1461
+ throw new Error('Required parameter id was null or undefined when calling getByIdInFull.');
1462
+ }
1463
+ // verify required parameter 'xMagdaTenantId' is not null or undefined
1464
+ if (xMagdaTenantId === null || xMagdaTenantId === undefined) {
1465
+ throw new Error('Required parameter xMagdaTenantId was null or undefined when calling getByIdInFull.');
1466
+ }
1467
+ headerParams['X-Magda-Tenant-Id'] = xMagdaTenantId;
1468
+ headerParams['X-Magda-Session'] = xMagdaSession;
1469
+ let useFormData = false;
1470
+ let requestOptions = {
1471
+ method: 'GET',
1472
+ qs: queryParameters,
1473
+ headers: headerParams,
1474
+ uri: localVarPath,
1475
+ useQuerystring: this._useQuerystring,
1476
+ json: true,
1477
+ };
1478
+ this.authentications.default.applyToRequest(requestOptions);
1479
+ if (Object.keys(formParams).length) {
1480
+ if (useFormData) {
1481
+ requestOptions.formData = formParams;
1482
+ }
1483
+ else {
1484
+ requestOptions.form = formParams;
1485
+ }
1486
+ }
1487
+ return new Promise((resolve, reject) => {
1488
+ request(requestOptions, (error, response, body) => {
1489
+ if (error) {
1490
+ reject(error);
1491
+ }
1492
+ else {
1493
+ if (response.statusCode >= 200 && response.statusCode <= 299) {
1494
+ resolve({ response: response, body: body });
1495
+ }
1496
+ else {
1497
+ reject({ response: response, body: body });
1498
+ }
1499
+ }
1500
+ });
1501
+ });
1502
+ }
1308
1503
  /**
1309
1504
  * Get a summary record by ID
1310
1505
  * Gets a summary record, including all the aspect ids for which this record has data.