@universis/evaluations 1.0.2

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 (68) hide show
  1. package/.eslintignore +1 -0
  2. package/.eslintrc +34 -0
  3. package/.gitlab-ci.yml +22 -0
  4. package/LICENSE +163 -0
  5. package/README.md +38 -0
  6. package/babel.config.js +3 -0
  7. package/dist/EvaluationSchemaLoader.js +33 -0
  8. package/dist/EvaluationSchemaLoader.js.map +1 -0
  9. package/dist/EvaluationService.js +56 -0
  10. package/dist/EvaluationService.js.map +1 -0
  11. package/dist/config/models/AccessToken.json +76 -0
  12. package/dist/config/models/ClassInstructorEvaluationEvent.json +76 -0
  13. package/dist/config/models/CourseClassEvaluationEvent.json +57 -0
  14. package/dist/config/models/EvaluationAccessToken.json +101 -0
  15. package/dist/config/models/EvaluationDocument.json +72 -0
  16. package/dist/config/models/EvaluationEvent.json +50 -0
  17. package/dist/config/scope.access.json +11 -0
  18. package/dist/evaluationRouter.js +118 -0
  19. package/dist/evaluationRouter.js.map +1 -0
  20. package/dist/handlers/evaluation-key-handler.js +45 -0
  21. package/dist/handlers/evaluation-key-handler.js.map +1 -0
  22. package/dist/index.js +3 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/listeners/class-instructor-event-listener.js +27 -0
  25. package/dist/listeners/class-instructor-event-listener.js.map +1 -0
  26. package/dist/listeners/force-set-state-listener.js +47 -0
  27. package/dist/listeners/force-set-state-listener.js.map +1 -0
  28. package/dist/models/access-token-model.d.ts +37 -0
  29. package/dist/models/access-token-model.js +39 -0
  30. package/dist/models/access-token-model.js.map +1 -0
  31. package/dist/models/evaluation-access-token-model.d.ts +17 -0
  32. package/dist/models/evaluation-access-token-model.js +40 -0
  33. package/dist/models/evaluation-access-token-model.js.map +1 -0
  34. package/dist/models/evaluation-document-model.d.ts +13 -0
  35. package/dist/models/evaluation-document-model.js +150 -0
  36. package/dist/models/evaluation-document-model.js.map +1 -0
  37. package/dist/models/evaluation-event-model.d.ts +13 -0
  38. package/dist/models/evaluation-event-model.js +318 -0
  39. package/dist/models/evaluation-event-model.js.map +1 -0
  40. package/package.json +53 -0
  41. package/spec/CourseEvaluationSampleForm.json +1046 -0
  42. package/spec/EvaluationService.spec.js +9 -0
  43. package/spec/helpers/babel.js +1 -0
  44. package/spec/helpers/env.js +7 -0
  45. package/spec/helpers/reporter.js +11 -0
  46. package/spec/support/jasmine.json +13 -0
  47. package/src/EvaluationSchemaLoader.js +35 -0
  48. package/src/EvaluationService.js +57 -0
  49. package/src/config/models/AccessToken.json +76 -0
  50. package/src/config/models/ClassInstructorEvaluationEvent.json +76 -0
  51. package/src/config/models/CourseClassEvaluationEvent.json +57 -0
  52. package/src/config/models/EvaluationAccessToken.json +101 -0
  53. package/src/config/models/EvaluationDocument.json +72 -0
  54. package/src/config/models/EvaluationEvent.json +50 -0
  55. package/src/config/scope.access.json +11 -0
  56. package/src/evaluationRouter.js +117 -0
  57. package/src/handlers/evaluation-key-handler.js +45 -0
  58. package/src/index.js +2 -0
  59. package/src/listeners/class-instructor-event-listener.js +27 -0
  60. package/src/listeners/force-set-state-listener.js +46 -0
  61. package/src/models/access-token-model.d.ts +37 -0
  62. package/src/models/access-token-model.js +38 -0
  63. package/src/models/evaluation-access-token-model.d.ts +17 -0
  64. package/src/models/evaluation-access-token-model.js +39 -0
  65. package/src/models/evaluation-document-model.d.ts +13 -0
  66. package/src/models/evaluation-document-model.js +149 -0
  67. package/src/models/evaluation-event-model.d.ts +13 -0
  68. package/src/models/evaluation-event-model.js +317 -0
@@ -0,0 +1,101 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "http://schema.org/EvaluationAccessToken",
4
+ "name": "EvaluationAccessToken",
5
+ "description": "An access token provided for evaluating an object.",
6
+ "title": "EvaluationAccessToken",
7
+ "abstract": false,
8
+ "sealed": false,
9
+ "hidden": false,
10
+ "inherits": "AccessToken",
11
+ "version": "1.0",
12
+ "classPath": "./models/evaluation-access-token-model",
13
+ "fields": [
14
+ {
15
+ "@id": "http://schema.org/evaluationEvent",
16
+ "name": "evaluationEvent",
17
+ "title": "evaluationEvent",
18
+ "type": "EvaluationEvent",
19
+ "nullable": false
20
+ },
21
+ {
22
+ "@id": "https://themost.io/schemas/access_token",
23
+ "name": "access_token",
24
+ "title": "Access Token",
25
+ "description": "An access token is a string representing an authorization issued to the client.",
26
+ "type": "Text",
27
+ "nullable": false,
28
+ "primary": true,
29
+ "value": "javascript:return require('lodash').sampleSize('ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', 20).join('');"
30
+ },
31
+ {
32
+ "@id": "https://themost.io/schemas/scope",
33
+ "name": "scope",
34
+ "title": "Scope",
35
+ "description": "Scope is used to limit the authorization granted to the client by the resource owner.",
36
+ "type": "Text",
37
+ "readonly": true,
38
+ "value": "javascript:return 'evaluation';"
39
+ },
40
+ {
41
+ "@id": "https://themost.io/schemas/user_id",
42
+ "name": "user_id",
43
+ "title": "User",
44
+ "type": "Text",
45
+ "nullable": false,
46
+ "editable": false,
47
+ "value": "javascript:return 'anonymous';"
48
+ },
49
+ {
50
+ "@id": "https://themost.io/schemas/client_id",
51
+ "name": "client_id",
52
+ "title": "Client ID",
53
+ "description": "The authorization server issues the registered client a client identifier -- a unique string representing the registration information provided by the client.",
54
+ "type": "WebApplication",
55
+ "nullable": false,
56
+ "indexed": true,
57
+ "value": "javascript:return 'evaluation-center';",
58
+ "mapping": {
59
+ "associationType": "association",
60
+ "parentModel": "WebApplication",
61
+ "parentField": "alternateName",
62
+ "childModel": "EvaluationAccessToken",
63
+ "childField": "client_id"
64
+ }
65
+ },
66
+ {
67
+ "@id": "https://themost.io/schemas/expires",
68
+ "description": "The expiration date and time of this access token.",
69
+ "name": "expires",
70
+ "title": "Expires",
71
+ "type": "DateTime",
72
+ "nullable": true,
73
+ "value": "javascript:return require('moment')(new Date()).add(1, 'd').toDate();"
74
+ },
75
+ {
76
+ "@id": "https://themost.io/schemas/webApplication",
77
+ "name": "webApplication",
78
+ "title": "Web Application",
79
+ "type": "Text",
80
+ "nullable": true
81
+ }
82
+ ],
83
+ "constraints": [
84
+ ],
85
+ "privileges": [
86
+ {
87
+ "mask": 15,
88
+ "type": "global"
89
+ },
90
+ {
91
+ "mask": 15,
92
+ "type": "global",
93
+ "account": "Administrators"
94
+ }
95
+ ],
96
+ "eventListeners": [
97
+ {
98
+ "type": "./listeners/force-set-state-listener"
99
+ }
100
+ ]
101
+ }
@@ -0,0 +1,72 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "http://schema.org/EvaluationDocument",
4
+ "name": "EvaluationDocument",
5
+ "description": "Evaluation document",
6
+ "title": "EvaluationDocument",
7
+ "abstract": false,
8
+ "sealed": false,
9
+ "version": "1.0",
10
+ "inherits": "Attachment",
11
+ "classPath": "./models/evaluation-document-model",
12
+ "fields": [
13
+ {
14
+ "name": "documentNumber",
15
+ "title": "Document number",
16
+ "type": "Integer",
17
+ "value": "javascript:return this.newid();",
18
+ "nullable": false
19
+ },
20
+ {
21
+ "@id": "http://schema.org/evaluationType",
22
+ "name": "resultType",
23
+ "title": "Result Type",
24
+ "description": "A string which represents the data model where evaluation results will be stored.",
25
+ "type": "Text",
26
+ "value": "javascript:return 'Evaluation' + this.target.documentNumber;"
27
+ },
28
+ {
29
+ "name": "sameAs",
30
+ "title": "Same As",
31
+ "description": "URL of a reference Web page that unambiguously indicates the item's identity. E.g. the URL of the item's Wikipedia page, Freebase page, or official website.",
32
+ "type": "URL",
33
+ "nullable": true
34
+ },
35
+ {
36
+ "@id": "https://themost.io/schemas/version",
37
+ "name": "version",
38
+ "title": "Version",
39
+ "description": "The version of this item.",
40
+ "type": "Text",
41
+ "validation": {
42
+ "pattern": "^\\d+.\\d+.\\d+$"
43
+ }
44
+
45
+ }
46
+ ],
47
+ "constraints": [
48
+ {
49
+ "type": "unique",
50
+ "fields": [
51
+ "sameAs"
52
+ ]
53
+ }
54
+ ],
55
+ "privileges": [
56
+ {
57
+ "mask": 1,
58
+ "type": "global",
59
+ "account": "*"
60
+ },
61
+ {
62
+ "mask": 15,
63
+ "type": "global"
64
+ },
65
+ {
66
+ "mask": 15,
67
+ "type": "global",
68
+ "account": "Administrators"
69
+ }
70
+ ]
71
+ }
72
+
@@ -0,0 +1,50 @@
1
+ {
2
+ "$schema": "https://themost-framework.github.io/themost/models/2018/2/schema.json",
3
+ "@id": "http://schema.org/EvaluationEvent",
4
+ "name": "EvaluationEvent",
5
+ "title": "EvaluationEvents",
6
+ "abstract": false,
7
+ "sealed": false,
8
+ "inherits": "Event",
9
+ "version": "1.0",
10
+ "classPath": "./models/evaluation-event-model",
11
+ "fields": [
12
+ {
13
+ "name": "id",
14
+ "type": "Integer",
15
+ "primary": true,
16
+ "nullable": false
17
+ },
18
+ {
19
+ "@id": "http://schema.org/evaluationDocument",
20
+ "name": "evaluationDocument",
21
+ "title": "evaluationDocument",
22
+ "type": "EvaluationDocument",
23
+ "nullable": false
24
+ },
25
+ {
26
+ "name": "additionalType",
27
+ "title": "Additional Type",
28
+ "description": "An additional type for the item, typically used for adding more specific types from external vocabularies in microdata syntax. This is a relationship between something and a class that the thing is in. In RDFa syntax, it is better to use the native RDFa syntax - the 'typeof' attribute - for multiple types. Schema.org tools may have only weaker understanding of extra types, in particular those defined externally.",
29
+ "type": "Text",
30
+ "readonly": true,
31
+ "value": "javascript:return this.model.name;"
32
+ }
33
+ ],
34
+ "privileges": [
35
+ {
36
+ "mask": 15,
37
+ "type": "global"
38
+ },
39
+ {
40
+ "mask": 1,
41
+ "type": "global",
42
+ "account": "*"
43
+ },
44
+ {
45
+ "mask": 15,
46
+ "type": "global",
47
+ "account": "Administrators"
48
+ }
49
+ ]
50
+ }
@@ -0,0 +1,11 @@
1
+ [
2
+ {
3
+ "scope": [
4
+ "teachers"
5
+ ],
6
+ "resource": "/api/ClassInstructorEvaluationEvents/(\\d+)/Results",
7
+ "access": [
8
+ "read"
9
+ ]
10
+ }
11
+ ]
@@ -0,0 +1,118 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.evaluationRouter = evaluationRouter;var _express = _interopRequireDefault(require("express"));
2
+ var _evaluationKeyHandler = require("./handlers/evaluation-key-handler");
3
+ var _express2 = require("@themost/express");
4
+ var _i18n = _interopRequireDefault(require("i18n"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}
5
+
6
+
7
+ function evaluationRouter(app) {
8
+
9
+ const router = _express.default.Router();
10
+
11
+ router.use((req, res, next) => {
12
+ // create router context
13
+ const newContext = app.createContext();
14
+ /**
15
+ * try to find if request has already a data context
16
+ * @type {ExpressDataContext|*}
17
+ */
18
+ const interactiveContext = req.context;
19
+ // finalize already assigned context
20
+ if (interactiveContext) {
21
+ if (typeof interactiveContext.finalize === 'function') {
22
+ // finalize interactive context
23
+ return interactiveContext.finalize(() => {
24
+ // and assign new context
25
+ Object.defineProperty(req, 'context', {
26
+ enumerable: false,
27
+ configurable: true,
28
+ get: () => {
29
+ return newContext;
30
+ } });
31
+
32
+ // exit handler
33
+ return next();
34
+ });
35
+ }
36
+ }
37
+ // otherwise assign context
38
+ Object.defineProperty(req, 'context', {
39
+ enumerable: false,
40
+ configurable: true,
41
+ get: () => {
42
+ return newContext;
43
+ } });
44
+
45
+ // and exit handler
46
+ return next();
47
+ });
48
+ router.use((req, res, next) => {
49
+ // set context locale from request
50
+ req.context.locale = req.locale;
51
+ // set translation
52
+ req.context.translate = function () {
53
+ return _i18n.default.__.apply(req.context, Array.from(arguments));
54
+ };
55
+ return next();
56
+ });
57
+ // use this handler to finalize router context
58
+ // important note: context finalization is very important in order
59
+ // to close and finalize database connections, cache connections etc.
60
+ router.use((req, res, next) => {
61
+ req.on('end', () => {
62
+ //on end
63
+ if (req.context) {
64
+ //finalize data context
65
+ return req.context.finalize(() => {
66
+ //
67
+ });
68
+ }
69
+ });
70
+ return next();
71
+ });
72
+
73
+ router.use(async (req, res, next) => {
74
+ try {
75
+ await new _evaluationKeyHandler.EvaluationKeyHandler().beginRequestAsync(req, res);
76
+ return next();
77
+ } catch (err) {
78
+ return next(err);
79
+ }
80
+ });
81
+
82
+ router.get('/', (req, res, next) => {
83
+ // set entity set parameters
84
+ Object.assign(req.params, {
85
+ entitySetFunction: 'Current' });
86
+
87
+ return next();
88
+ }, (0, _express2.getEntitySetFunction)({
89
+ entitySet: 'EvaluationEvents' }));
90
+
91
+
92
+ router.get('/Form', (req, res, next) => {
93
+ // set entity set parameters
94
+ Object.assign(req.params, {
95
+ entitySetFunction: 'Current',
96
+ entityFunction: 'Form' });
97
+
98
+ return next();
99
+ }, (0, _express2.getEntitySetFunction)({
100
+ entitySet: 'EvaluationEvents' }));
101
+
102
+
103
+ router.post('/Evaluate', (req, res, next) => {
104
+ // set entity set parameters
105
+ Object.assign(req.params, {
106
+ entitySetFunction: 'Current',
107
+ entityAction: 'Evaluate' });
108
+
109
+ return next();
110
+ }, (0, _express2.postEntitySetFunction)({
111
+ entitySet: 'EvaluationEvents' }));
112
+
113
+
114
+
115
+
116
+ return router;
117
+ }
118
+ //# sourceMappingURL=evaluationRouter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/evaluationRouter.js"],"names":["evaluationRouter","app","router","express","Router","use","req","res","next","newContext","createContext","interactiveContext","context","finalize","Object","defineProperty","enumerable","configurable","get","locale","translate","i18n","__","apply","Array","from","arguments","on","EvaluationKeyHandler","beginRequestAsync","err","assign","params","entitySetFunction","entitySet","entityFunction","post","entityAction"],"mappings":"uHAAA;AACA;AACA;AACA,oD;;;AAGO,SAASA,gBAAT,CAA0BC,GAA1B,EAA+B;;AAElC,QAAMC,MAAM,GAAGC,iBAAQC,MAAR,EAAf;;AAEAF,EAAAA,MAAM,CAACG,GAAP,CAAW,CAACC,GAAD,EAAMC,GAAN,EAAWC,IAAX,KAAoB;AAC3B;AACA,UAAMC,UAAU,GAAGR,GAAG,CAACS,aAAJ,EAAnB;AACA;AACR;AACA;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IAAP,CAAY,WAAZ,EAAyB,CAAC9B,GAAD,EAAMC,GAAN,EAAWC,IAAX,KAAoB;AACzC;AACAM,IAAAA,MAAM,CAACiB,MAAP,CAAczB,GAAG,CAAC0B,MAAlB,EAA0B;AACtBC,MAAAA,iBAAiB,EAAG,SADE;AAEtBI,MAAAA,YAAY,EAAG,UAFO,EAA1B;;AAIA,WAAO7B,IAAI,EAAX;AACH,GAPD,EAOG,qCAAsB;AACrB0B,IAAAA,SAAS,EAAE,kBADU,EAAtB,CAPH;;;;;AAaA,SAAOhC,MAAP;AACH","sourcesContent":["import express from 'express';\nimport {EvaluationKeyHandler} from \"./handlers/evaluation-key-handler\";\nimport { getEntitySetFunction} from \"@themost/express\";\nimport i18n from \"i18n\";\nimport {postEntitySetFunction} from \"@themost/express\";\n\nexport function evaluationRouter(app) {\n\n const router = express.Router();\n\n router.use((req, res, next) => {\n // create router context\n const newContext = app.createContext();\n /**\n * try to find if request has already a data context\n * @type {ExpressDataContext|*}\n */\n const interactiveContext = req.context;\n // finalize already assigned context\n if (interactiveContext) {\n if (typeof interactiveContext.finalize === 'function') {\n // finalize interactive context\n return interactiveContext.finalize(() => {\n // and assign new context\n Object.defineProperty(req, 'context', {\n enumerable: false,\n configurable: true,\n get: () => {\n return newContext\n }\n });\n // exit handler\n return next();\n });\n }\n }\n // otherwise assign context\n Object.defineProperty(req, 'context', {\n enumerable: false,\n configurable: true,\n get: () => {\n return newContext\n }\n });\n // and exit handler\n return next();\n });\n router.use((req, res, next) => {\n // set context locale from request\n req.context.locale = req.locale;\n // set translation\n req.context.translate = function() {\n return i18n.__.apply(req.context, Array.from(arguments));\n };\n return next();\n });\n // use this handler to finalize router context\n // important note: context finalization is very important in order\n // to close and finalize database connections, cache connections etc.\n router.use((req, res, next) => {\n req.on('end', () => {\n //on end\n if (req.context) {\n //finalize data context\n return req.context.finalize( () => {\n //\n });\n }\n });\n return next();\n });\n\n router.use(async (req, res, next) => {\n try {\n await new EvaluationKeyHandler().beginRequestAsync(req, res);\n return next();\n } catch (err) {\n return next(err);\n }\n });\n\n router.get('/', (req, res, next) => {\n // set entity set parameters\n Object.assign(req.params, {\n entitySetFunction : 'Current'\n });\n return next();\n }, getEntitySetFunction({\n entitySet: 'EvaluationEvents'\n }));\n\n router.get('/Form', (req, res, next) => {\n // set entity set parameters\n Object.assign(req.params, {\n entitySetFunction : 'Current',\n entityFunction : 'Form'\n });\n return next();\n }, getEntitySetFunction({\n entitySet: 'EvaluationEvents'\n }));\n\n router.post('/Evaluate', (req, res, next) => {\n // set entity set parameters\n Object.assign(req.params, {\n entitySetFunction : 'Current',\n entityAction : 'Evaluate'\n });\n return next();\n }, postEntitySetFunction({\n entitySet: 'EvaluationEvents'\n }));\n\n\n\n return router;\n}\n"],"file":"evaluationRouter.js"}
@@ -0,0 +1,45 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.EvaluationKeyHandler = void 0;var _common = require("@themost/common");
2
+ const EvaluationAccessToken = require('../models/evaluation-access-token-model');
3
+
4
+ class EvaluationKeyHandler {
5
+ static createInstance() {
6
+ return new EvaluationKeyHandler();
7
+ }
8
+
9
+ beginRequest(req, res, callback) {
10
+ try {
11
+ if (Object.prototype.hasOwnProperty.call(req.headers, 'evaluation-key')) {
12
+ const evaluationKey = req.headers['evaluation-key'].replace(/-/ig, '');
13
+ return EvaluationAccessToken.inspect(req.context, evaluationKey).then((token) => {
14
+ if (token.active === false) {
15
+ return callback(new _common.HttpTokenExpiredError('Evaluation access token has been expired'));
16
+ }
17
+ req.context.user = req.context.user || {
18
+ name: 'anonymous',
19
+ authenticationType: 'Evaluation',
20
+ authenticationToken: token.access_token,
21
+ authenticationScope: token.scope };
22
+
23
+ return callback();
24
+ }).catch((err) => {
25
+ return callback(err);
26
+ });
27
+ }
28
+ return callback();
29
+ } catch (error) {
30
+ return callback(error);
31
+ }
32
+ }
33
+
34
+ beginRequestAsync(req, res) {
35
+ return new Promise((resolve, reject) => {
36
+ this.beginRequest(req, res, function (err) {
37
+ if (err) {
38
+ return reject(err);
39
+ }
40
+ return resolve(err);
41
+ });
42
+ });
43
+
44
+ }}exports.EvaluationKeyHandler = EvaluationKeyHandler;
45
+ //# sourceMappingURL=evaluation-key-handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/handlers/evaluation-key-handler.js"],"names":["EvaluationAccessToken","require","EvaluationKeyHandler","createInstance","beginRequest","req","res","callback","Object","prototype","hasOwnProperty","call","headers","evaluationKey","replace","inspect","context","then","token","active","HttpTokenExpiredError","user","name","authenticationType","authenticationToken","access_token","authenticationScope","scope","catch","err","error","beginRequestAsync","Promise","resolve","reject"],"mappings":"iHAAA;AACA,MAAMA,qBAAqB,GAAGC,OAAO,CAAC,yCAAD,CAArC;;AAEQ,MAAMC,oBAAN,CAA2B;AACV,SAAdC,cAAc,GAAG;AACpB,WAAO,IAAID,oBAAJ,EAAP;AACH;;AAEDE,EAAAA,YAAY,CAACC,GAAD,EAAMC,GAAN,EAAWC,QAAX,EAAqB;AAC7B,QAAI;AACA,UAAIC,MAAM,CAACC,SAAP,CAAiBC,cAAjB,CAAgCC,IAAhC,CAAqCN,GAAG,CAACO,OAAzC,EAAkD,gBAAlD,CAAJ,EAAyE;AACrE,cAAMC,aAAa,GAAGR,GAAG,CAACO,OAAJ,CAAY,gBAAZ,EAA8BE,OAA9B,CAAsC,KAAtC,EAA6C,EAA7C,CAAtB;AACA,eAAOd,qBAAqB,CAACe,OAAtB,CAA8BV,GAAG,CAACW,OAAlC,EAA2CH,aAA3C,EAA0DI,IAA1D,CAA+D,CAACC,KAAD,KAAW;AAC7E,cAAIA,KAAK,CAACC,MAAN,KAAiB,KAArB,EAA4B;AACxB,mBAAOZ,QAAQ,CAAC,IAAIa,6BAAJ,CAA0B,0CAA1B,CAAD,CAAf;AACH;AACDf,UAAAA,GAAG,CAACW,OAAJ,CAAYK,IAAZ,GAAmBhB,GAAG,CAACW,OAAJ,CAAYK,IAAZ,IAAoB;AACnCC,YAAAA,IAAI,EAAE,WAD6B;AAEnCC,YAAAA,kBAAkB,EAAE,YAFe;AAGnCC,YAAAA,mBAAmB,EAAEN,KAAK,CAACO,YAHQ;AAInCC,YAAAA,mBAAmB,EAAER,KAAK,CAACS,KAJQ,EAAvC;;AAMA,iBAAOpB,QAAQ,EAAf;AACH,SAXM,EAWJqB,KAXI,CAWE,CAACC,GAAD,KAAS;AACd,iBAAOtB,QAAQ,CAACsB,GAAD,CAAf;AACH,SAbM,CAAP;AAcH;AACD,aAAOtB,QAAQ,EAAf;AACH,KAnBD,CAmBE,OAAMuB,KAAN,EAAY;AACV,aAAOvB,QAAQ,CAACuB,KAAD,CAAf;AACH;AACJ;;AAEAC,EAAAA,iBAAiB,CAAC1B,GAAD,EAAMC,GAAN,EAAW;AACxB,WAAO,IAAI0B,OAAJ,CAAa,CAACC,OAAD,EAAUC,MAAV,KAAqB;AACtC,WAAK9B,YAAL,CAAmBC,GAAnB,EAAwBC,GAAxB,EAA6B,UAASuB,GAAT,EAAc;AACvC,YAAIA,GAAJ,EAAS;AACL,iBAAOK,MAAM,CAACL,GAAD,CAAb;AACH;AACD,eAAOI,OAAO,CAACJ,GAAD,CAAd;AACF,OALF;AAMF,KAPM,CAAP;;AASH,GAxC6B,C","sourcesContent":["import { HttpTokenExpiredError } from '@themost/common';\nconst EvaluationAccessToken = require('../models/evaluation-access-token-model');\n\n export class EvaluationKeyHandler {\n static createInstance() {\n return new EvaluationKeyHandler();\n }\n\n beginRequest(req, res, callback) {\n try {\n if (Object.prototype.hasOwnProperty.call(req.headers, 'evaluation-key')) {\n const evaluationKey = req.headers['evaluation-key'].replace(/-/ig, '');\n return EvaluationAccessToken.inspect(req.context, evaluationKey).then((token) => {\n if (token.active === false) {\n return callback(new HttpTokenExpiredError('Evaluation access token has been expired'))\n }\n req.context.user = req.context.user || {\n name: 'anonymous',\n authenticationType: 'Evaluation',\n authenticationToken: token.access_token,\n authenticationScope: token.scope\n };\n return callback();\n }).catch((err) => {\n return callback(err);\n });\n }\n return callback();\n } catch(error){\n return callback(error);\n }\n }\n\n beginRequestAsync(req, res) {\n return new Promise(((resolve, reject) => {\n this.beginRequest( req, res, function(err) {\n if (err) {\n return reject(err);\n }\n return resolve(err);\n });\n }));\n\n }\n}\n"],"file":"evaluation-key-handler.js"}
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", { value: true });var _EvaluationSchemaLoader = require("./EvaluationSchemaLoader");Object.keys(_EvaluationSchemaLoader).forEach(function (key) {if (key === "default" || key === "__esModule") return;if (key in exports && exports[key] === _EvaluationSchemaLoader[key]) return;Object.defineProperty(exports, key, { enumerable: true, get: function () {return _EvaluationSchemaLoader[key];} });});
2
+ var _EvaluationService = require("./EvaluationService");Object.keys(_EvaluationService).forEach(function (key) {if (key === "default" || key === "__esModule") return;if (key in exports && exports[key] === _EvaluationService[key]) return;Object.defineProperty(exports, key, { enumerable: true, get: function () {return _EvaluationService[key];} });});
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.js"],"names":[],"mappings":"2EAAA;AACA","sourcesContent":["export * from './EvaluationSchemaLoader';\nexport * from './EvaluationService';\n"],"file":"index.js"}
@@ -0,0 +1,27 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.beforeSave = beforeSave;var _data = require("@themost/data");
2
+ /**
3
+ *
4
+ * @param {DataEventArgs} event
5
+ */
6
+ async function beforeSaveAsync(event) {
7
+ // get organizer from courseClass
8
+ const context = event.model.context;
9
+ if (event.target.courseClassInstructor) {
10
+ const organizer = await context.model('CourseClassInstructor').
11
+ where('id').equal(event.target.courseClassInstructor).
12
+ select('courseClass/course/department').value();
13
+ event.target.organizer = organizer;
14
+ }
15
+ }
16
+ /**
17
+ * @param {DataEventArgs} event
18
+ * @param {Function} callback
19
+ */
20
+ function beforeSave(event, callback) {
21
+ beforeSaveAsync(event).then(() => {
22
+ return callback();
23
+ }).catch((err) => {
24
+ return callback(err);
25
+ });
26
+ }
27
+ //# sourceMappingURL=class-instructor-event-listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/listeners/class-instructor-event-listener.js"],"names":["beforeSaveAsync","event","context","model","target","courseClassInstructor","organizer","where","equal","select","value","beforeSave","callback","then","catch","err"],"mappings":"2GAAA;AACA;AACA;AACA;AACA;AACA,eAAeA,eAAf,CAA+BC,KAA/B,EAAsC;AAClC;AACA,QAAMC,OAAO,GAAGD,KAAK,CAACE,KAAN,CAAYD,OAA5B;AACA,MAAID,KAAK,CAACG,MAAN,CAAaC,qBAAjB,EAAwC;AACpC,UAAMC,SAAS,GAAG,MAAMJ,OAAO,CAACC,KAAR,CAAc,uBAAd;AACnBI,IAAAA,KADmB,CACb,IADa,EACPC,KADO,CACDP,KAAK,CAACG,MAAN,CAAaC,qBADZ;AAEnBI,IAAAA,MAFmB,CAEZ,+BAFY,EAEqBC,KAFrB,EAAxB;AAGAT,IAAAA,KAAK,CAACG,MAAN,CAAaE,SAAb,GAAyBA,SAAzB;AACH;AACJ;AACD;AACA;AACA;AACA;AACQ,SAASK,UAAT,CAAoBV,KAApB,EAA2BW,QAA3B,EAAqC;AACzCZ,EAAAA,eAAe,CAACC,KAAD,CAAf,CAAuBY,IAAvB,CAA4B,MAAM;AAC9B,WAAOD,QAAQ,EAAf;AACH,GAFD,EAEGE,KAFH,CAEU,CAAAC,GAAG,KAAI;AACb,WAAOH,QAAQ,CAACG,GAAD,CAAf;AACH,GAJD;AAKH","sourcesContent":["import { DataObjectState } from '@themost/data';\n/**\n * \n * @param {DataEventArgs} event \n */\nasync function beforeSaveAsync(event) {\n // get organizer from courseClass\n const context = event.model.context;\n if (event.target.courseClassInstructor) {\n const organizer = await context.model('CourseClassInstructor')\n .where('id').equal(event.target.courseClassInstructor)\n .select('courseClass/course/department').value();\n event.target.organizer = organizer;\n }\n}\n/**\n * @param {DataEventArgs} event\n * @param {Function} callback\n */\n export function beforeSave(event, callback) {\n beforeSaveAsync(event).then(() => {\n return callback()\n }).catch( err => {\n return callback(err);\n })\n}\n\n"],"file":"class-instructor-event-listener.js"}
@@ -0,0 +1,47 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.afterSave = afterSave;exports.beforeSave = beforeSave;
2
+ var _data = require("@themost/data"); // eslint-disable-next-line no-unused-vars
3
+ /**
4
+ *
5
+ * @param {DataEventArgs} event
6
+ */
7
+ async function beforeSaveAsync(event) {
8
+ if (event.state === _data.DataObjectState.Insert) {
9
+ Object.assign(event.target, {
10
+ $state: _data.DataObjectState.Insert });
11
+
12
+ }
13
+ }
14
+
15
+ /**
16
+ *
17
+ * @param {DataEventArgs} event
18
+ */
19
+ async function afterSaveAsync(event) {
20
+ if (event.state === _data.DataObjectState.Insert) {
21
+ delete event.target.$state;
22
+ }
23
+ }
24
+ /**
25
+ * @param {DataEventArgs} event
26
+ * @param {Function} callback
27
+ */
28
+ function beforeSave(event, callback) {
29
+ beforeSaveAsync(event).then(() => {
30
+ return callback();
31
+ }).catch((err) => {
32
+ return callback(err);
33
+ });
34
+ }
35
+
36
+ /**
37
+ * @param {DataEventArgs} event
38
+ * @param {Function} callback
39
+ */
40
+ function afterSave(event, callback) {
41
+ afterSaveAsync(event).then(() => {
42
+ return callback();
43
+ }).catch((err) => {
44
+ return callback(err);
45
+ });
46
+ }
47
+ //# sourceMappingURL=force-set-state-listener.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/listeners/force-set-state-listener.js"],"names":["beforeSaveAsync","event","state","DataObjectState","Insert","Object","assign","target","$state","afterSaveAsync","beforeSave","callback","then","catch","err","afterSave"],"mappings":";AACA,qC,CADA;AAEA;AACA;AACA;AACA;AACA,eAAeA,eAAf,CAA+BC,KAA/B,EAAsC;AAClC,MAAIA,KAAK,CAACC,KAAN,KAAgBC,sBAAgBC,MAApC,EAA4C;AACxCC,IAAAA,MAAM,CAACC,MAAP,CAAcL,KAAK,CAACM,MAApB,EAA4B;AACxBC,MAAAA,MAAM,EAAEL,sBAAgBC,MADA,EAA5B;;AAGH;AACJ;;AAED;AACA;AACA;AACA;AACC,eAAeK,cAAf,CAA8BR,KAA9B,EAAqC;AAClC,MAAIA,KAAK,CAACC,KAAN,KAAgBC,sBAAgBC,MAApC,EAA4C;AACxC,WAAOH,KAAK,CAACM,MAAN,CAAaC,MAApB;AACH;AACJ;AACD;AACA;AACA;AACA;AACQ,SAASE,UAAT,CAAoBT,KAApB,EAA2BU,QAA3B,EAAqC;AACzCX,EAAAA,eAAe,CAACC,KAAD,CAAf,CAAuBW,IAAvB,CAA4B,MAAM;AAC9B,WAAOD,QAAQ,EAAf;AACH,GAFD,EAEGE,KAFH,CAEU,CAAAC,GAAG,KAAI;AACb,WAAOH,QAAQ,CAACG,GAAD,CAAf;AACH,GAJD;AAKH;;AAED;AACA;AACA;AACA;AACQ,SAASC,SAAT,CAAmBd,KAAnB,EAA0BU,QAA1B,EAAoC;AACxCF,EAAAA,cAAc,CAACR,KAAD,CAAd,CAAsBW,IAAtB,CAA2B,MAAM;AAC7B,WAAOD,QAAQ,EAAf;AACH,GAFD,EAEGE,KAFH,CAEU,CAAAC,GAAG,KAAI;AACb,WAAOH,QAAQ,CAACG,GAAD,CAAf;AACH,GAJD;AAKH","sourcesContent":["// eslint-disable-next-line no-unused-vars\nimport { DataObjectState } from '@themost/data';\n/**\n * \n * @param {DataEventArgs} event \n */\nasync function beforeSaveAsync(event) {\n if (event.state === DataObjectState.Insert) {\n Object.assign(event.target, {\n $state: DataObjectState.Insert\n });\n }\n}\n\n/**\n * \n * @param {DataEventArgs} event \n */\n async function afterSaveAsync(event) {\n if (event.state === DataObjectState.Insert) {\n delete event.target.$state;\n }\n}\n/**\n * @param {DataEventArgs} event\n * @param {Function} callback\n */\n export function beforeSave(event, callback) {\n beforeSaveAsync(event).then(() => {\n return callback()\n }).catch( err => {\n return callback(err);\n })\n}\n\n/**\n * @param {DataEventArgs} event\n * @param {Function} callback\n */\n export function afterSave(event, callback) {\n afterSaveAsync(event).then(() => {\n return callback()\n }).catch( err => {\n return callback(err);\n })\n}"],"file":"force-set-state-listener.js"}
@@ -0,0 +1,37 @@
1
+ import {EdmMapping,EdmType} from '@themost/data/odata';
2
+
3
+ import {DataObject} from '@themost/data/data-object';
4
+ /**
5
+ * @class
6
+ */
7
+ declare class AccessToken extends DataObject {
8
+
9
+
10
+ /**
11
+ * @description An access token is a string representing an authorization issued to the client.
12
+ */
13
+ public access_token: string;
14
+
15
+ /**
16
+ * @description The authorization server issues the registered client a client identifier -- a unique string representing the registration information provided by the client.
17
+ */
18
+ public client_id: string;
19
+
20
+ /**
21
+ * @description The expiration date and time of this access token.
22
+ */
23
+ public expires?: Date;
24
+
25
+ /**
26
+ * @description Refresh tokens are issued to the client by the authorization server and are used to obtain a new access token when the current access token becomes invalid or expires.
27
+ */
28
+ public refresh_token?: string;
29
+
30
+ /**
31
+ * @description Scope is used to limit the authorization granted to the client by the resource owner.
32
+ */
33
+ public scope?: string;
34
+
35
+ }
36
+
37
+ export = AccessToken;
@@ -0,0 +1,39 @@
1
+ "use strict";var _data = require("@themost/data");var _dec, _class;let
2
+
3
+
4
+ AccessToken = (_dec = _data.EdmMapping.entityType('AccessToken'), _dec(_class = class AccessToken extends _data.DataObject {
5
+
6
+ constructor() {
7
+ super();
8
+ }
9
+
10
+ static async inspect(context, access_token) {
11
+ const token = await context.model('AccessToken').
12
+ where('access_token').equal(access_token).
13
+ silent().
14
+ getTypedItem();
15
+ if (token == null) {
16
+ return {
17
+ active: false };
18
+
19
+ }
20
+ return {
21
+ active: !token.isExpired(),
22
+ username: token.user_id,
23
+ client_id: token.client_id,
24
+ access_token: token.access_token,
25
+ refresh_token: token.refresh_token,
26
+ scope: token.scope };
27
+
28
+ }
29
+
30
+ isExpired() {
31
+ if (this.expires == null) {
32
+ return true;
33
+ }
34
+ return new Date(this.expires).getTime() < new Date().getTime();
35
+ }}) || _class);
36
+
37
+
38
+ module.exports = AccessToken;
39
+ //# sourceMappingURL=access-token-model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/models/access-token-model.js"],"names":["AccessToken","EdmMapping","entityType","DataObject","constructor","inspect","context","access_token","token","model","where","equal","silent","getTypedItem","active","isExpired","username","user_id","client_id","refresh_token","scope","expires","Date","getTime","module","exports"],"mappings":"aAAA,qC;;;AAGMA,W,WADLC,iBAAWC,UAAX,CAAsB,aAAtB,C,gBAAD,MACMF,WADN,SAC0BG,gBAD1B,CACqC;;AAEjCC,EAAAA,WAAW,GAAG;AACV;AACH;;AAEmB,eAAPC,OAAO,CAACC,OAAD,EAAUC,YAAV,EAAwB;AACxC,UAAMC,KAAK,GAAG,MAAMF,OAAO,CAACG,KAAR,CAAc,aAAd;AACjBC,IAAAA,KADiB,CACX,cADW,EACKC,KADL,CACWJ,YADX;AAEjBK,IAAAA,MAFiB;AAGjBC,IAAAA,YAHiB,EAApB;AAIA,QAAIL,KAAK,IAAI,IAAb,EAAmB;AACjB,aAAO;AACLM,QAAAA,MAAM,EAAE,KADH,EAAP;;AAGD;AACD,WAAO;AACLA,MAAAA,MAAM,EAAE,CAACN,KAAK,CAACO,SAAN,EADJ;AAELC,MAAAA,QAAQ,EAAER,KAAK,CAACS,OAFX;AAGLC,MAAAA,SAAS,EAAEV,KAAK,CAACU,SAHZ;AAILX,MAAAA,YAAY,EAAEC,KAAK,CAACD,YAJf;AAKLY,MAAAA,aAAa,EAAEX,KAAK,CAACW,aALhB;AAMLC,MAAAA,KAAK,EAAEZ,KAAK,CAACY,KANR,EAAP;;AAQD;;AAEDL,EAAAA,SAAS,GAAG;AACV,QAAI,KAAKM,OAAL,IAAgB,IAApB,EAA0B;AACxB,aAAO,IAAP;AACD;AACD,WAAQ,IAAIC,IAAJ,CAAS,KAAKD,OAAd,CAAD,CAAyBE,OAAzB,KAAsC,IAAID,IAAJ,EAAD,CAAaC,OAAb,EAA5C;AACD,GA/B8B,C;;;AAkCrCC,MAAM,CAACC,OAAP,GAAiBzB,WAAjB","sourcesContent":["import {DataObject, EdmMapping} from '@themost/data';\n\n@EdmMapping.entityType('AccessToken')\nclass AccessToken extends DataObject {\n\n constructor() {\n super();\n }\n\n static async inspect(context, access_token) {\n const token = await context.model('AccessToken')\n .where('access_token').equal(access_token)\n .silent()\n .getTypedItem();\n if (token == null) {\n return {\n active: false\n }\n }\n return {\n active: !token.isExpired(),\n username: token.user_id,\n client_id: token.client_id,\n access_token: token.access_token,\n refresh_token: token.refresh_token,\n scope: token.scope\n };\n }\n\n isExpired() {\n if (this.expires == null) {\n return true;\n }\n return (new Date(this.expires)).getTime() < (new Date()).getTime();\n }\n}\n\nmodule.exports = AccessToken;"],"file":"access-token-model.js"}
@@ -0,0 +1,17 @@
1
+ import AccessToken = require('./access-token-model');
2
+ /**
3
+ * @class
4
+ */
5
+ declare class EvaluationAccessToken extends AccessToken {
6
+
7
+
8
+ public evaluationEvent: any;
9
+
10
+ /**
11
+ * @description An access token is a string representing an authorization issued to the client.
12
+ */
13
+ public access_token: string;
14
+
15
+ }
16
+
17
+ export = EvaluationAccessToken;