@citolab/qti-backend-firebase 0.0.3

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 (111) hide show
  1. package/LICENSE.md +674 -0
  2. package/dist/api/app-specific/base/application-specific-base.d.ts +45 -0
  3. package/dist/api/app-specific/base/application-specific-base.d.ts.map +1 -0
  4. package/dist/api/app-specific/base/application-specific-base.js +503 -0
  5. package/dist/api/app-specific/base/application-specific-base.js.map +1 -0
  6. package/dist/api/app-specific/base/cheerio-helper.d.ts +5 -0
  7. package/dist/api/app-specific/base/cheerio-helper.d.ts.map +1 -0
  8. package/dist/api/app-specific/base/cheerio-helper.js +16 -0
  9. package/dist/api/app-specific/base/cheerio-helper.js.map +1 -0
  10. package/dist/api/app-specific/baseImplementation.d.ts +6 -0
  11. package/dist/api/app-specific/baseImplementation.d.ts.map +1 -0
  12. package/dist/api/app-specific/baseImplementation.js +11 -0
  13. package/dist/api/app-specific/baseImplementation.js.map +1 -0
  14. package/dist/api/app-specific/index.d.ts +4 -0
  15. package/dist/api/app-specific/index.d.ts.map +1 -0
  16. package/dist/api/app-specific/index.js +4 -0
  17. package/dist/api/app-specific/index.js.map +1 -0
  18. package/dist/api/app-specific/interface/IApplicationSpecific.d.ts +31 -0
  19. package/dist/api/app-specific/interface/IApplicationSpecific.d.ts.map +1 -0
  20. package/dist/api/app-specific/interface/IApplicationSpecific.js +2 -0
  21. package/dist/api/app-specific/interface/IApplicationSpecific.js.map +1 -0
  22. package/dist/api/app-specific/specific.d.ts +1 -0
  23. package/dist/api/app-specific/specific.d.ts.map +1 -0
  24. package/dist/api/app-specific/specific.js +31 -0
  25. package/dist/api/app-specific/specific.js.map +1 -0
  26. package/dist/api/index.d.ts +3 -0
  27. package/dist/api/index.d.ts.map +1 -0
  28. package/dist/api/index.js +15 -0
  29. package/dist/api/index.js.map +1 -0
  30. package/dist/api/qti-data.d.ts +4 -0
  31. package/dist/api/qti-data.d.ts.map +1 -0
  32. package/dist/api/qti-data.js +622 -0
  33. package/dist/api/qti-data.js.map +1 -0
  34. package/dist/api/qti-resources.d.ts +4 -0
  35. package/dist/api/qti-resources.d.ts.map +1 -0
  36. package/dist/api/qti-resources.js +348 -0
  37. package/dist/api/qti-resources.js.map +1 -0
  38. package/dist/api/qti-teacher.d.ts +6 -0
  39. package/dist/api/qti-teacher.d.ts.map +1 -0
  40. package/dist/api/qti-teacher.js +807 -0
  41. package/dist/api/qti-teacher.js.map +1 -0
  42. package/dist/api/qti-tools.d.ts +3 -0
  43. package/dist/api/qti-tools.d.ts.map +1 -0
  44. package/dist/api/qti-tools.js +450 -0
  45. package/dist/api/qti-tools.js.map +1 -0
  46. package/dist/console.d.ts +2 -0
  47. package/dist/console.d.ts.map +1 -0
  48. package/dist/console.js +30 -0
  49. package/dist/console.js.map +1 -0
  50. package/dist/express-test.d.ts +2 -0
  51. package/dist/express-test.d.ts.map +1 -0
  52. package/dist/express-test.js +19 -0
  53. package/dist/express-test.js.map +1 -0
  54. package/dist/helpers/ci-bootstap.d.ts +4 -0
  55. package/dist/helpers/ci-bootstap.d.ts.map +1 -0
  56. package/dist/helpers/ci-bootstap.js +96 -0
  57. package/dist/helpers/ci-bootstap.js.map +1 -0
  58. package/dist/helpers/database.d.ts +110 -0
  59. package/dist/helpers/database.d.ts.map +1 -0
  60. package/dist/helpers/database.js +151 -0
  61. package/dist/helpers/database.js.map +1 -0
  62. package/dist/helpers/db.d.ts +3 -0
  63. package/dist/helpers/db.d.ts.map +1 -0
  64. package/dist/helpers/db.js +10 -0
  65. package/dist/helpers/db.js.map +1 -0
  66. package/dist/helpers/endpoint-helpers.d.ts +33 -0
  67. package/dist/helpers/endpoint-helpers.d.ts.map +1 -0
  68. package/dist/helpers/endpoint-helpers.js +149 -0
  69. package/dist/helpers/endpoint-helpers.js.map +1 -0
  70. package/dist/helpers/firebase.d.ts +7 -0
  71. package/dist/helpers/firebase.d.ts.map +1 -0
  72. package/dist/helpers/firebase.js +15 -0
  73. package/dist/helpers/firebase.js.map +1 -0
  74. package/dist/helpers/index.d.ts +11 -0
  75. package/dist/helpers/index.d.ts.map +1 -0
  76. package/dist/helpers/index.js +11 -0
  77. package/dist/helpers/index.js.map +1 -0
  78. package/dist/helpers/local-helpers.d.ts +2 -0
  79. package/dist/helpers/local-helpers.d.ts.map +1 -0
  80. package/dist/helpers/local-helpers.js +11 -0
  81. package/dist/helpers/local-helpers.js.map +1 -0
  82. package/dist/helpers/logic.d.ts +73 -0
  83. package/dist/helpers/logic.d.ts.map +1 -0
  84. package/dist/helpers/logic.js +759 -0
  85. package/dist/helpers/logic.js.map +1 -0
  86. package/dist/helpers/package-upload.d.ts +16 -0
  87. package/dist/helpers/package-upload.d.ts.map +1 -0
  88. package/dist/helpers/package-upload.js +160 -0
  89. package/dist/helpers/package-upload.js.map +1 -0
  90. package/dist/helpers/package.d.ts +32 -0
  91. package/dist/helpers/package.d.ts.map +1 -0
  92. package/dist/helpers/package.js +373 -0
  93. package/dist/helpers/package.js.map +1 -0
  94. package/dist/helpers/request-headers.d.ts +27 -0
  95. package/dist/helpers/request-headers.d.ts.map +1 -0
  96. package/dist/helpers/request-headers.js +144 -0
  97. package/dist/helpers/request-headers.js.map +1 -0
  98. package/dist/helpers/storage.d.ts +10 -0
  99. package/dist/helpers/storage.d.ts.map +1 -0
  100. package/dist/helpers/storage.js +132 -0
  101. package/dist/helpers/storage.js.map +1 -0
  102. package/dist/helpers/utils.d.ts +42 -0
  103. package/dist/helpers/utils.d.ts.map +1 -0
  104. package/dist/helpers/utils.js +228 -0
  105. package/dist/helpers/utils.js.map +1 -0
  106. package/dist/main.d.ts +2 -0
  107. package/dist/main.d.ts.map +1 -0
  108. package/dist/main.js +14 -0
  109. package/dist/main.js.map +1 -0
  110. package/package.json +101 -0
  111. package/readme.md +11 -0
@@ -0,0 +1,96 @@
1
+ export const CES = `
2
+ const postToParentWindows = (type, data) => {
3
+ window.top.postMessage(data ? { type, data } : { type }, '*');
4
+ let w = window.parent;
5
+ while (w) {
6
+ if (w !== window.top) {
7
+ w.postMessage({ type, data }, '*');
8
+ }
9
+ if (w !== w.parent) {
10
+ w = w.parent;
11
+ } else {
12
+ w = null;
13
+ }
14
+ }
15
+ };
16
+
17
+ window.CES = {
18
+ media: null,
19
+ response: null,
20
+ load: () => {
21
+ let resolveCount = 0;
22
+
23
+ const handleMessage = (event) => {
24
+ if (event.data.type === "mediaData") {
25
+ const media = event.data.data;
26
+ CES.media = media;
27
+ resolveCount++;
28
+ } else if (event.data.type === "responseData") {
29
+ const response = event.data.data;
30
+ if (response && Array.isArray(response) && response.length > 0) {
31
+ // state is stored in the first element of the array
32
+ CES.response = response[0];
33
+ // Wait a short moment to ensure CES.response is set
34
+ setTimeout(() => {
35
+ // Re-create the Controller instance if it exists
36
+ if (typeof Controller === 'function') {
37
+ console.log("Re-creating Controller instance");
38
+ ctrl = new Controller();
39
+ }
40
+ }, 50);
41
+ } else {
42
+ CES.response = response;
43
+ }
44
+ resolveCount++;
45
+ }
46
+ if (resolveCount === 2) {
47
+ //window.removeEventListener("message", handleMessage);
48
+ }
49
+ };
50
+ window.addEventListener("message", handleMessage);
51
+ postToParentWindows("getMedia");
52
+ postToParentWindows("getResponse");
53
+ },
54
+ setResponse: (data) => {
55
+ postToParentWindows("setResponse", data);
56
+ },
57
+ getResponse: () => {
58
+ return CES.response;
59
+ },
60
+ getMedia: () => {
61
+ return CES.media;
62
+ },
63
+ setStageHeight: () => {
64
+ postToParentWindows("setResponse");
65
+ },
66
+ };
67
+ `;
68
+ export const ciBootstrap = `
69
+ window.onload = async function () {
70
+ const handleMessage = event => {
71
+ if (event.data.type === 'mediaData') {
72
+ const media = event.data.data;
73
+ var n = document.createElement('iframe');
74
+ n.frameBorder = '0';
75
+ n.scrolling = 'no';
76
+ n.src = media[0];
77
+ document.body.appendChild(n);
78
+ window.removeEventListener('message', handleMessage);
79
+ }
80
+ };
81
+ window.addEventListener('message', handleMessage);
82
+ let w = window.parent;
83
+ while (w) {
84
+ w.postMessage({ type: 'getMedia' }, '*');
85
+ if (w !== w.parent) {
86
+ w = w.parent;
87
+ } else {
88
+ w = null;
89
+ }
90
+ }
91
+ };
92
+ `;
93
+ export const registerCES = `${CES}
94
+ CES.load();
95
+ ;`;
96
+ //# sourceMappingURL=ci-bootstap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ci-bootstap.js","sourceRoot":"","sources":["../../src/helpers/ci-bootstap.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,GAAG,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkElB,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;;;;;;;;;;CAwB1B,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,GAAG,GAAG;;EAE/B,CAAC"}
@@ -0,0 +1,110 @@
1
+ export declare class DATABASE {
2
+ appId?: string | undefined;
3
+ constructor(appId?: string | undefined);
4
+ get basePath(): string;
5
+ get APPLICATION(): {
6
+ COLLECTION: string;
7
+ DOC: () => string;
8
+ };
9
+ get FEEDBACK(): {
10
+ COLLECTION: () => string;
11
+ DOC: (feedbackId: string) => string;
12
+ };
13
+ get STATE(): {
14
+ COLLECTION: () => string;
15
+ DOC: (feedbackId: string) => string;
16
+ ACTION: {
17
+ DOC: (userId: string, dateId: string) => string;
18
+ };
19
+ };
20
+ get GROUP_DELIVERY(): {
21
+ COLLECTION: () => string;
22
+ DOC: (code: string) => string;
23
+ STUDENTS: {
24
+ COLLECTION: (code: string) => string;
25
+ DOC: (code: string, itemId: string) => string;
26
+ };
27
+ };
28
+ get PACKAGE(): {
29
+ COLLECTION: () => string;
30
+ DOC: (hash: string) => string;
31
+ };
32
+ get ASSESSMENT(): {
33
+ COLLECTION: () => string;
34
+ DOC: (assessmentId: string) => string;
35
+ };
36
+ get STUDENT(): {
37
+ COLLECTION: () => string;
38
+ DOC: (code: string) => string;
39
+ LOG: {
40
+ COLLECTION: (teacherId: string) => string;
41
+ DOC: (teacherId: string, dateId: string) => string;
42
+ };
43
+ SESSION: {
44
+ COLLECTION: (code: string) => string;
45
+ DOC: (code: string, sessionId: string) => string;
46
+ LOG: (code: string, sessionId: string, dateId: string) => string;
47
+ };
48
+ };
49
+ get EVENTLOG(): {
50
+ DOC: (identifier: string, timestamp: number) => string;
51
+ };
52
+ get STUDENT_USER_ID_MAPPING(): {
53
+ COLLECTION: () => string;
54
+ DOC: (userId: string) => string;
55
+ };
56
+ get REVIEWER(): {
57
+ COLLECTION: () => string;
58
+ LOG: {
59
+ COLLECTION: (teacherId: string) => string;
60
+ DOC: (teacherId: string, dateId: string) => string;
61
+ };
62
+ ASSESSMENT_ITEM_STATS: {
63
+ RESPONSES: {
64
+ COLLECTION: (teacherId: string, assessmentId: string, itemId: string) => string;
65
+ DOC: (teacherId: string, assessmentId: string, itemId: string, responseId: string) => string;
66
+ };
67
+ };
68
+ };
69
+ get TEACHER(): {
70
+ COLLECTION: () => string;
71
+ DOC: (teacherId: string) => string;
72
+ LOG: {
73
+ COLLECTION: (teacherId: string) => string;
74
+ DOC: (teacherId: string, dateId: string) => string;
75
+ };
76
+ ASSESSMENT_RESULTS: {
77
+ COLLECTION: (teacherId: string, assessmentId: string) => string;
78
+ DOC: (teacherId: string, assessmentId: string, code: string) => string;
79
+ };
80
+ ASSESSMENT_REPORTS: {
81
+ COLLECTION: (teacherId: string, assessmentId: string) => string;
82
+ DOC: (teacherId: string, assessmentId: string, code: string) => string;
83
+ };
84
+ ASSESSMENT_ITEM_STATS: {
85
+ RESPONSES: {
86
+ COLLECTION: (teacherId: string, assessmentId: string, itemId: string) => string;
87
+ DOC: (teacherId: string, assessmentId: string, itemId: string, responseId: string) => string;
88
+ };
89
+ };
90
+ STUDENTS: {
91
+ COLLECTION: (teacherId: string) => string;
92
+ DOC: (teacherId: string, studentId: string) => string;
93
+ SESSION: {
94
+ COLLECTION: (teacherId: string, studentId: string) => string;
95
+ DOC: (teacherId: string, studentId: string, sessionId: string) => string;
96
+ };
97
+ ITEM: {
98
+ COLLECTION: (teacherId: string, studentId: string) => string;
99
+ DOC: (teacherId: string, studentId: string, itemId: string) => string;
100
+ };
101
+ };
102
+ };
103
+ get AUTH(): {
104
+ COLLECTION: string;
105
+ DOC: (uid: string) => string;
106
+ APP_COLLECTION: (uid: string) => string;
107
+ CHECK_APP_RIGHTS: (uid: string, appId: string) => string;
108
+ };
109
+ }
110
+ //# sourceMappingURL=database.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.d.ts","sourceRoot":"","sources":["../../src/helpers/database.ts"],"names":[],"mappings":"AAEA,qBAAa,QAAQ;IACA,KAAK,CAAC,EAAE,MAAM;gBAAd,KAAK,CAAC,EAAE,MAAM,YAAA;IAEjC,IAAW,QAAQ,IAAI,MAAM,CAG5B;IAED,IAAI,WAAW;;;MAMd;IAED,IAAI,QAAQ;;0BAIU,MAAM;MAE3B;IAED,IAAI,KAAK;;0BAIa,MAAM;;0BAER,MAAM,UAAU,MAAM;;MAIzC;IAED,IAAI,cAAc;;oBAIF,MAAM;;+BAEG,MAAM;wBACb,MAAM,UAAU,MAAM;;MAIvC;IAED,IAAI,OAAO;;oBAIK,MAAM;MAErB;IACD,IAAI,UAAU;;4BAIU,MAAM;MAE7B;IAED,IAAI,OAAO;;oBAIK,MAAM;;oCAEQ,MAAM;6BACb,MAAM,UAAU,MAAM;;;+BAIpB,MAAM;wBACb,MAAM,aAAa,MAAM;wBAEzB,MAAM,aAAa,MAAM,UAAU,MAAM;;MAI1D;IAED,IAAI,QAAQ;0BAGU,MAAM,aAAa,MAAM;MAG9C;IAED,IAAI,uBAAuB;;sBAIT,MAAM;MAEvB;IAED,IAAI,QAAQ;;;oCAKkB,MAAM;6BACb,MAAM,UAAU,MAAM;;;;wCAMxB,MAAM,gBACH,MAAM,UACZ,MAAM;iCAIH,MAAM,gBACH,MAAM,UACZ,MAAM,cACF,MAAM;;;MAM3B;IACD,IAAI,OAAO;;yBAIU,MAAM;;oCAEG,MAAM;6BACb,MAAM,UAAU,MAAM;;;oCAKf,MAAM,gBAAgB,MAAM;6BAEnC,MAAM,gBAAgB,MAAM,QAAQ,MAAM;;;oCAInC,MAAM,gBAAgB,MAAM;6BAEnC,MAAM,gBAAgB,MAAM,QAAQ,MAAM;;;;wCAM5C,MAAM,gBACH,MAAM,UACZ,MAAM;iCAIH,MAAM,gBACH,MAAM,UACZ,MAAM,cACF,MAAM;;;;oCAME,MAAM;6BACb,MAAM,aAAa,MAAM;;wCAGhB,MAAM,aAAa,MAAM;iCAEhC,MAAM,aAAa,MAAM,aAAa,MAAM;;;wCAIrC,MAAM,aAAa,MAAM;iCAEhC,MAAM,aAAa,MAAM,UAAU,MAAM;;;MAKjE;IAED,IAAI,IAAI;;mBAGO,MAAM;8BACK,MAAM;gCACJ,MAAM,SAAS,MAAM;MAGhD;CACF"}
@@ -0,0 +1,151 @@
1
+ import { IsTrue } from "./utils";
2
+ export class DATABASE {
3
+ appId;
4
+ constructor(appId) {
5
+ this.appId = appId;
6
+ }
7
+ get basePath() {
8
+ const isSingleTenant = IsTrue(process.env["SINGLE_TENANT"]);
9
+ return !isSingleTenant && this.appId ? `application/${this.appId}` : "";
10
+ }
11
+ get APPLICATION() {
12
+ const basePath = this.basePath;
13
+ return {
14
+ COLLECTION: "application",
15
+ DOC: () => (this.appId ? `${basePath}` : "application/info"),
16
+ };
17
+ }
18
+ get FEEDBACK() {
19
+ const basePath = `${this.basePath}/feedback`;
20
+ return {
21
+ COLLECTION: () => basePath,
22
+ DOC: (feedbackId) => `${basePath}/${feedbackId}`,
23
+ };
24
+ }
25
+ get STATE() {
26
+ const basePath = `${this.basePath}/state`;
27
+ return {
28
+ COLLECTION: () => basePath,
29
+ DOC: (feedbackId) => `${basePath}/${feedbackId}`,
30
+ ACTION: {
31
+ DOC: (userId, dateId) => `${basePath}/${userId}/action/${dateId}`,
32
+ },
33
+ };
34
+ }
35
+ get GROUP_DELIVERY() {
36
+ const basePath = `${this.basePath}/groupDelivery`;
37
+ return {
38
+ COLLECTION: () => basePath,
39
+ DOC: (code) => `${basePath}/${code}`,
40
+ STUDENTS: {
41
+ COLLECTION: (code) => `${basePath}/${code}/students`,
42
+ DOC: (code, itemId) => `${basePath}/${code}/students/${itemId}`,
43
+ },
44
+ };
45
+ }
46
+ get PACKAGE() {
47
+ const basePath = `${this.basePath}/package`;
48
+ return {
49
+ COLLECTION: () => basePath,
50
+ DOC: (hash) => `${basePath}/${hash}`,
51
+ };
52
+ }
53
+ get ASSESSMENT() {
54
+ const basePath = `${this.basePath}/assessments`;
55
+ return {
56
+ COLLECTION: () => basePath,
57
+ DOC: (assessmentId) => `${basePath}/${assessmentId}`,
58
+ };
59
+ }
60
+ get STUDENT() {
61
+ const basePath = `${this.basePath}/students`;
62
+ return {
63
+ COLLECTION: () => basePath,
64
+ DOC: (code) => `${basePath}/${code}`,
65
+ LOG: {
66
+ COLLECTION: (teacherId) => `${basePath}/${teacherId}/log`,
67
+ DOC: (teacherId, dateId) => `${basePath}/${teacherId}/log/${dateId}`,
68
+ },
69
+ SESSION: {
70
+ COLLECTION: (code) => `${basePath}/${code}/sessions`,
71
+ DOC: (code, sessionId) => `${basePath}/${code}/sessions/${sessionId}`,
72
+ LOG: (code, sessionId, dateId) => `${basePath}/${code}/sessions/${sessionId}/log/${dateId}`,
73
+ },
74
+ };
75
+ }
76
+ get EVENTLOG() {
77
+ const basePath = `${this.basePath}/eventlog`;
78
+ return {
79
+ DOC: (identifier, timestamp) => `${basePath}$/eventlog/${identifier}/actions/${timestamp}`,
80
+ };
81
+ }
82
+ get STUDENT_USER_ID_MAPPING() {
83
+ const basePath = `${this.basePath}/studentUserIdCodeMapping`;
84
+ return {
85
+ COLLECTION: () => basePath,
86
+ DOC: (userId) => `${basePath}/${userId}`,
87
+ };
88
+ }
89
+ get REVIEWER() {
90
+ const basePath = `${this.basePath}/reviewer`;
91
+ return {
92
+ COLLECTION: () => basePath,
93
+ LOG: {
94
+ COLLECTION: (teacherId) => `${basePath}/${teacherId}/log`,
95
+ DOC: (teacherId, dateId) => `${basePath}/${teacherId}/log/${dateId}`,
96
+ },
97
+ ASSESSMENT_ITEM_STATS: {
98
+ RESPONSES: {
99
+ COLLECTION: (teacherId, assessmentId, itemId) => `${basePath}/${teacherId}/assessment/${assessmentId}/itemstats/${itemId}/responses`,
100
+ DOC: (teacherId, assessmentId, itemId, responseId) => `${basePath}/${teacherId}/assessment/${assessmentId}/itemstats/${itemId}/responses/${responseId}`,
101
+ },
102
+ },
103
+ };
104
+ }
105
+ get TEACHER() {
106
+ const basePath = `${this.basePath}/teacher`;
107
+ return {
108
+ COLLECTION: () => basePath,
109
+ DOC: (teacherId) => `${basePath}/${teacherId}`,
110
+ LOG: {
111
+ COLLECTION: (teacherId) => `${basePath}/${teacherId}/log`,
112
+ DOC: (teacherId, dateId) => `${basePath}/${teacherId}/log/${dateId}`,
113
+ },
114
+ ASSESSMENT_RESULTS: {
115
+ COLLECTION: (teacherId, assessmentId) => `${basePath}/${teacherId}/assessment/${assessmentId}/results`,
116
+ DOC: (teacherId, assessmentId, code) => `${basePath}/${teacherId}/assessment/${assessmentId}/results/${code}`,
117
+ },
118
+ ASSESSMENT_REPORTS: {
119
+ COLLECTION: (teacherId, assessmentId) => `${basePath}/${teacherId}/assessment/${assessmentId}/reports`,
120
+ DOC: (teacherId, assessmentId, code) => `${basePath}/${teacherId}/assessment/${assessmentId}/reports/${code}`,
121
+ },
122
+ ASSESSMENT_ITEM_STATS: {
123
+ RESPONSES: {
124
+ COLLECTION: (teacherId, assessmentId, itemId) => `${basePath}/${teacherId}/assessment/${assessmentId}/itemstats/${itemId}/responses`,
125
+ DOC: (teacherId, assessmentId, itemId, responseId) => `${basePath}/${teacherId}/assessment/${assessmentId}/itemstats/${itemId}/responses/${responseId}`,
126
+ },
127
+ },
128
+ STUDENTS: {
129
+ COLLECTION: (teacherId) => `${basePath}/${teacherId}/students`,
130
+ DOC: (teacherId, studentId) => `${basePath}/${teacherId}/students/${studentId}`,
131
+ SESSION: {
132
+ COLLECTION: (teacherId, studentId) => `${basePath}/${teacherId}/students/${studentId}/sessions`,
133
+ DOC: (teacherId, studentId, sessionId) => `${basePath}/${teacherId}/students/${studentId}/sessions/${sessionId}`,
134
+ },
135
+ ITEM: {
136
+ COLLECTION: (teacherId, studentId) => `${basePath}/${teacherId}/students/${studentId}/items`,
137
+ DOC: (teacherId, studentId, itemId) => `${basePath}/${teacherId}/students/${studentId}/items/${itemId}`,
138
+ },
139
+ },
140
+ };
141
+ }
142
+ get AUTH() {
143
+ return {
144
+ COLLECTION: "auth",
145
+ DOC: (uid) => `auth/${uid}`,
146
+ APP_COLLECTION: (uid) => `auth/${uid}/application`,
147
+ CHECK_APP_RIGHTS: (uid, appId) => `auth/${uid}/application/${appId.toLowerCase()}`,
148
+ };
149
+ }
150
+ }
151
+ //# sourceMappingURL=database.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database.js","sourceRoot":"","sources":["../../src/helpers/database.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,OAAO,QAAQ;IACA;IAAnB,YAAmB,KAAc;QAAd,UAAK,GAAL,KAAK,CAAS;IAAG,CAAC;IAErC,IAAW,QAAQ;QACjB,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC;QAC5D,OAAO,CAAC,cAAc,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,eAAe,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1E,CAAC;IAED,IAAI,WAAW;QACb,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;QAC/B,OAAO;YACL,UAAU,EAAE,aAAa;YACzB,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CA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E,EAAE,CAAC,GAAG,QAAQ,IAAI,SAAS,WAAW;gBACtE,GAAG,EAAE,CAAC,SAAiB,EAAE,SAAiB,EAAE,EAAE,CAC5C,GAAG,QAAQ,IAAI,SAAS,aAAa,SAAS,EAAE;gBAClD,OAAO,EAAE;oBACP,UAAU,EAAE,CAAC,SAAiB,EAAE,SAAiB,EAAE,EAAE,CACnD,GAAG,QAAQ,IAAI,SAAS,aAAa,SAAS,WAAW;oBAC3D,GAAG,EAAE,CAAC,SAAiB,EAAE,SAAiB,EAAE,SAAiB,EAAE,EAAE,CAC/D,GAAG,QAAQ,IAAI,SAAS,aAAa,SAAS,aAAa,SAAS,EAAE;iBACzE;gBACD,IAAI,EAAE;oBACJ,UAAU,EAAE,CAAC,SAAiB,EAAE,SAAiB,EAAE,EAAE,CACnD,GAAG,QAAQ,IAAI,SAAS,aAAa,SAAS,QAAQ;oBACxD,GAAG,EAAE,CAAC,SAAiB,EAAE,SAAiB,EAAE,MAAc,EAAE,EAAE,CAC5D,GAAG,QAAQ,IAAI,SAAS,aAAa,SAAS,UAAU,MAAM,EAAE;iBACnE;aACF;SACF,CAAC;IACJ,CAAC;IAED,IAAI,IAAI;QACN,OAAO;YACL,UAAU,EAAE,MAAM;YAClB,GAAG,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,QAAQ,GAAG,EAAE;YACnC,cAAc,EAAE,CAAC,GAAW,EAAE,EAAE,CAAC,QAAQ,GAAG,cAAc;YAC1D,gBAAgB,EAAE,CAAC,GAAW,EAAE,KAAa,EAAE,EAAE,CAC/C,QAAQ,GAAG,gBAAgB,KAAK,CAAC,WAAW,EAAE,EAAE;SACnD,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,3 @@
1
+ import { DATABASE } from './database';
2
+ export declare const getDatabase: (appId?: string) => DATABASE;
3
+ //# sourceMappingURL=db.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../../src/helpers/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAGtC,eAAO,MAAM,WAAW,GAAI,QAAQ,MAAM,aAMzC,CAAC"}
@@ -0,0 +1,10 @@
1
+ import { DATABASE } from './database';
2
+ import { IsTrue } from './utils';
3
+ export const getDatabase = (appId) => {
4
+ if (IsTrue(process.env.SINGLE_TENANT)) {
5
+ return new DATABASE();
6
+ }
7
+ const db = new DATABASE(!appId || appId === 'application' ? '' : appId);
8
+ return db;
9
+ };
10
+ //# sourceMappingURL=db.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"db.js","sourceRoot":"","sources":["../../src/helpers/db.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAc,EAAE,EAAE;IAC5C,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;QACtC,OAAO,IAAI,QAAQ,EAAE,CAAC;IACxB,CAAC;IACD,MAAM,EAAE,GAAG,IAAI,QAAQ,CAAC,CAAC,KAAK,IAAI,KAAK,KAAK,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACxE,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC"}
@@ -0,0 +1,33 @@
1
+ import multer from "multer";
2
+ import { Request, Response, NextFunction } from "express";
3
+ export interface AuthenticatedRequest extends Request {
4
+ user?: {
5
+ uid: string;
6
+ };
7
+ appId?: string;
8
+ file?: any;
9
+ }
10
+ export interface ErrorResponse {
11
+ error: string;
12
+ details?: any;
13
+ }
14
+ export interface SuccessResponse<T = any> {
15
+ success: boolean;
16
+ data?: T;
17
+ message?: string;
18
+ }
19
+ export declare const sendError: (res: Response, status: number, message: string, details?: any) => void;
20
+ export declare const sendSuccess: <T>(res: Response, data?: T, message?: string) => void;
21
+ export declare const requireAuth: (req: AuthenticatedRequest, res: Response, next: NextFunction) => Promise<void>;
22
+ export declare const handleValidationErrors: (req: Request, res: Response, next: NextFunction) => void;
23
+ export declare const createRateLimit: (windowMs: number, max: number) => import("express-rate-limit").RateLimitRequestHandler;
24
+ export declare const generalRateLimit: import("express-rate-limit").RateLimitRequestHandler;
25
+ export declare const heavyOperationLimit: import("express-rate-limit").RateLimitRequestHandler;
26
+ export declare const imageUploadConfig: multer.Multer;
27
+ export declare const zipUploadConfig: multer.Multer;
28
+ export declare const errorHandler: (err: Error, req: Request, res: Response, next: NextFunction) => void;
29
+ export declare const optionalAuth: (req: AuthenticatedRequest, res: Response, next: NextFunction) => Promise<void>;
30
+ export declare const validateAssessmentId: (assessmentId: string) => boolean;
31
+ export declare const validatePackageId: (packageId: string) => boolean;
32
+ export declare const validateApplicationId: (applicationId: string) => boolean;
33
+ //# sourceMappingURL=endpoint-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/endpoint-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAS1D,MAAM,WAAW,oBAAqB,SAAQ,OAAO;IACnD,IAAI,CAAC,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,GAAG,CAAC;CACZ;AAED,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,GAAG,CAAC;CACf;AAED,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG;IACtC,OAAO,EAAE,OAAO,CAAC;IACjB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAGD,eAAO,MAAM,SAAS,GACpB,KAAK,QAAQ,EACb,QAAQ,MAAM,EACd,SAAS,MAAM,EACf,UAAU,GAAG,KACZ,IAIF,CAAC;AAEF,eAAO,MAAM,WAAW,GAAI,CAAC,EAC3B,KAAK,QAAQ,EACb,OAAO,CAAC,EACR,UAAU,MAAM,KACf,IAKF,CAAC;AAEF,eAAO,MAAM,WAAW,GACtB,KAAK,oBAAoB,EACzB,KAAK,QAAQ,EACb,MAAM,YAAY,KACjB,OAAO,CAAC,IAAI,CAed,CAAC;AAGF,eAAO,MAAM,sBAAsB,GACjC,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,KACjB,IAOF,CAAC;AAGF,eAAO,MAAM,eAAe,GAAI,UAAU,MAAM,EAAE,KAAK,MAAM,yDAOzD,CAAC;AAGL,eAAO,MAAM,gBAAgB,sDAAuC,CAAC;AACrE,eAAO,MAAM,mBAAmB,sDAAsC,CAAC;AAGvE,eAAO,MAAM,iBAAiB,eAa5B,CAAC;AAEH,eAAO,MAAM,eAAe,eAa1B,CAAC;AAGH,eAAO,MAAM,YAAY,GACvB,KAAK,KAAK,EACV,KAAK,OAAO,EACZ,KAAK,QAAQ,EACb,MAAM,YAAY,KACjB,IAyBF,CAAC;AAEF,eAAO,MAAM,YAAY,GACvB,KAAK,oBAAoB,EACzB,KAAK,QAAQ,EACb,MAAM,YAAY,KACjB,OAAO,CAAC,IAAI,CAcd,CAAC;AAGF,eAAO,MAAM,oBAAoB,GAAI,cAAc,MAAM,KAAG,OAO3D,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,WAAW,MAAM,KAAG,OAOrD,CAAC;AAEF,eAAO,MAAM,qBAAqB,GAAI,eAAe,MAAM,KAAG,OAO7D,CAAC"}
@@ -0,0 +1,149 @@
1
+ import multer from "multer";
2
+ import rateLimit from "express-rate-limit";
3
+ import { authenticateStudent, getAppId, tryAuthenticateStudent, } from "./request-headers";
4
+ import { validationResult } from "express-validator";
5
+ // Middleware for standardized error responses
6
+ export const sendError = (res, status, message, details) => {
7
+ const errorResponse = { error: message };
8
+ if (details)
9
+ errorResponse.details = details;
10
+ res.status(status).json(errorResponse);
11
+ };
12
+ export const sendSuccess = (res, data, message) => {
13
+ const response = { success: true };
14
+ if (data !== undefined)
15
+ response.data = data;
16
+ if (message)
17
+ response.message = message;
18
+ res.json(response);
19
+ };
20
+ // Authentication middleware
21
+ export const requireAuth = async (req, res, next) => {
22
+ try {
23
+ const result = await authenticateStudent(req, res);
24
+ if (!result || result.handled) {
25
+ sendError(res, 401, "Authentication required");
26
+ return; // Just return void
27
+ }
28
+ req.user = result.user;
29
+ req.appId = getAppId(req);
30
+ next();
31
+ }
32
+ catch (error) {
33
+ console.error("Authentication error:", error);
34
+ sendError(res, 500, "Authentication failed");
35
+ return; // Just return void
36
+ }
37
+ };
38
+ // Validation middleware
39
+ export const handleValidationErrors = (req, res, next) => {
40
+ const errors = validationResult(req);
41
+ if (!errors.isEmpty()) {
42
+ sendError(res, 400, "Validation failed", errors.array());
43
+ return; // Just return void, don't return the response
44
+ }
45
+ next();
46
+ };
47
+ // Rate limiting middleware
48
+ export const createRateLimit = (windowMs, max) => rateLimit({
49
+ windowMs,
50
+ max,
51
+ message: { error: "Too many requests, please try again later" },
52
+ standardHeaders: true,
53
+ legacyHeaders: false,
54
+ });
55
+ // Rate limits
56
+ export const generalRateLimit = createRateLimit(15 * 60 * 1000, 100); // 100 requests per 15 minutes
57
+ export const heavyOperationLimit = createRateLimit(60 * 60 * 1000, 20); // 20 requests per hour for creating sessions
58
+ // File upload configuration for feedback
59
+ export const imageUploadConfig = multer({
60
+ storage: multer.memoryStorage(),
61
+ limits: {
62
+ fileSize: 5 * 1024 * 1024, // 5MB limit
63
+ files: 1,
64
+ },
65
+ fileFilter: (req, file, cb) => {
66
+ if (file.mimetype.startsWith("image/")) {
67
+ cb(null, true);
68
+ }
69
+ else {
70
+ cb(new Error("Only image files are allowed"));
71
+ }
72
+ },
73
+ });
74
+ export const zipUploadConfig = multer({
75
+ storage: multer.memoryStorage(),
76
+ limits: {
77
+ fileSize: 50 * 1024 * 1024, // 50MB limit
78
+ files: 1,
79
+ },
80
+ fileFilter: (req, file, cb) => {
81
+ if (file.mimetype === "application/zip") {
82
+ cb(null, true);
83
+ }
84
+ else {
85
+ cb(new Error("Only ZIP files are allowed"));
86
+ }
87
+ },
88
+ });
89
+ // Global error handler
90
+ export const errorHandler = (err, req, res, next) => {
91
+ console.error("Unhandled error:", err);
92
+ // Check if it's a multer error by checking the constructor name and properties
93
+ if (err.constructor.name === "MulterError") {
94
+ const multerError = err; // Type assertion since MulterError isn't exported
95
+ if (multerError.code === "LIMIT_FILE_SIZE") {
96
+ sendError(res, 400, "File too large (max 5MB)");
97
+ return;
98
+ }
99
+ if (multerError.code === "LIMIT_FILE_COUNT") {
100
+ sendError(res, 400, "Too many files");
101
+ return;
102
+ }
103
+ sendError(res, 400, "File upload error");
104
+ return;
105
+ }
106
+ if (err.message === "Only image files are allowed") {
107
+ sendError(res, 400, err.message);
108
+ return;
109
+ }
110
+ sendError(res, 500, "Internal server error");
111
+ return;
112
+ };
113
+ // Authentication middleware (optional authentication)
114
+ export const optionalAuth = async (req, res, next) => {
115
+ try {
116
+ const user = await tryAuthenticateStudent(req, res);
117
+ if (user) {
118
+ req.user = user;
119
+ }
120
+ req.appId = getAppId(req);
121
+ next();
122
+ }
123
+ catch (error) {
124
+ console.error("Optional authentication error:", error);
125
+ // Continue without authentication for optional auth
126
+ req.appId = getAppId(req);
127
+ next();
128
+ }
129
+ };
130
+ // Validation helpers
131
+ export const validateAssessmentId = (assessmentId) => {
132
+ return (typeof assessmentId === "string" &&
133
+ assessmentId.length > 0 &&
134
+ assessmentId.length <= 100 &&
135
+ /^[a-zA-Z0-9_-]+$/.test(assessmentId));
136
+ };
137
+ export const validatePackageId = (packageId) => {
138
+ return (typeof packageId === "string" &&
139
+ packageId.length > 0 &&
140
+ packageId.length <= 100 &&
141
+ /^[a-zA-Z0-9_-]+$/.test(packageId));
142
+ };
143
+ export const validateApplicationId = (applicationId) => {
144
+ return (typeof applicationId === "string" &&
145
+ applicationId.length > 0 &&
146
+ applicationId.length <= 100 &&
147
+ /^[a-zA-Z0-9_-]+$/.test(applicationId));
148
+ };
149
+ //# sourceMappingURL=endpoint-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"endpoint-helpers.js","sourceRoot":"","sources":["../../src/helpers/endpoint-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAE3C,OAAO,EACL,mBAAmB,EACnB,QAAQ,EACR,sBAAsB,GACvB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAoBrD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,GAAa,EACb,MAAc,EACd,OAAe,EACf,OAAa,EACP,EAAE;IACR,MAAM,aAAa,GAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACxD,IAAI,OAAO;QAAE,aAAa,CAAC,OAAO,GAAG,OAAO,CAAC;IAC7C,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CACzB,GAAa,EACb,IAAQ,EACR,OAAgB,EACV,EAAE;IACR,MAAM,QAAQ,GAAuB,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IACvD,IAAI,IAAI,KAAK,SAAS;QAAE,QAAQ,CAAC,IAAI,GAAG,IAAI,CAAC;IAC7C,IAAI,OAAO;QAAE,QAAQ,CAAC,OAAO,GAAG,OAAO,CAAC;IACxC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;AACrB,CAAC,CAAC;AACF,4BAA4B;AAC5B,MAAM,CA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orage from "firebase-admin/storage";
2
+ import * as firebaseAuth from "firebase-admin/auth";
3
+ import * as firebaseFirestore from "firebase-admin/firestore";
4
+ export declare const getFirestore: () => firebaseFirestore.Firestore;
5
+ export declare const getAuth: typeof firebaseAuth.getAuth;
6
+ export declare const getStorage: typeof firebaseStorage.getStorage;
7
+ //# sourceMappingURL=firebase.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebase.d.ts","sourceRoot":"","sources":["../../src/helpers/firebase.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,eAAe,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,iBAAiB,MAAM,0BAA0B,CAAC;AAG9D,eAAO,MAAM,YAAY,mCAKxB,CAAC;AACF,eAAO,MAAM,OAAO,6BAAuB,CAAC;AAC5C,eAAO,MAAM,UAAU,mCAA6B,CAAC"}
@@ -0,0 +1,15 @@
1
+ // somehow importing directly from firebase-admin fails locally
2
+ // this is a workaroud.
3
+ import * as firebaseStorage from "firebase-admin/storage";
4
+ import * as firebaseAuth from "firebase-admin/auth";
5
+ import * as firebaseFirestore from "firebase-admin/firestore";
6
+ let fs;
7
+ export const getFirestore = () => {
8
+ if (!fs) {
9
+ fs = firebaseFirestore.getFirestore();
10
+ }
11
+ return fs;
12
+ };
13
+ export const getAuth = firebaseAuth.getAuth;
14
+ export const getStorage = firebaseStorage.getStorage;
15
+ //# sourceMappingURL=firebase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"firebase.js","sourceRoot":"","sources":["../../src/helpers/firebase.ts"],"names":[],"mappings":"AAAA,+DAA+D;AAC/D,uBAAuB;AACvB,OAAO,KAAK,eAAe,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,YAAY,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,iBAAiB,MAAM,0BAA0B,CAAC;AAE9D,IAAI,EAA+B,CAAC;AACpC,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,EAAE;IAC/B,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,EAAE,GAAG,iBAAiB,CAAC,YAAY,EAAE,CAAC;IACxC,CAAC;IACD,OAAO,EAAE,CAAC;AACZ,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC;AAC5C,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAC,UAAU,CAAC"}
@@ -0,0 +1,11 @@
1
+ export * from "./utils";
2
+ export * from "./db";
3
+ export * from "./database";
4
+ export * from "./storage";
5
+ export * from "./package";
6
+ export * from "./local-helpers";
7
+ export * from "./firebase";
8
+ export * from "./logic";
9
+ export * from "./request-headers";
10
+ export * from "./endpoint-helpers";
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,MAAM,CAAC;AACrB,cAAc,YAAY,CAAC;AAC3B,cAAc,WAAW,CAAC;AAC1B,cAAc,WAAW,CAAC;AAC1B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,cAAc,SAAS,CAAC;AACxB,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC"}