@memberjunction/actions-bizapps-lms 5.3.0 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +1 -1
- package/CHANGELOG.md +26 -0
- package/LEARNWORLDS_SIDECAR_PLAN.md +845 -0
- package/dist/base/base-lms.action.d.ts +26 -4
- package/dist/base/base-lms.action.d.ts.map +1 -1
- package/dist/base/base-lms.action.js +73 -17
- package/dist/base/base-lms.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/attach-tags.action.d.ts +26 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.js +79 -0
- package/dist/providers/learnworlds/actions/attach-tags.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/create-user.action.d.ts +24 -1
- package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/create-user.action.js +166 -142
- package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/detach-tags.action.d.ts +26 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.js +79 -0
- package/dist/providers/learnworlds/actions/detach-tags.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +31 -3
- package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/enroll-user.action.js +179 -125
- package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts +79 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.js +359 -0
- package/dist/providers/learnworlds/actions/get-bulk-data.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.d.ts +34 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.js +107 -0
- package/dist/providers/learnworlds/actions/get-bundles.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +33 -2
- package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-certificates.action.js +311 -244
- package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +14 -14
- package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js +234 -226
- package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +42 -6
- package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-course-details.action.js +182 -148
- package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts +29 -82
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-courses.action.js +188 -207
- package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +22 -2
- package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js +316 -294
- package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +23 -59
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-details.action.js +113 -114
- package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +43 -5
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +191 -147
- package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +21 -92
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-user-progress.action.js +145 -166
- package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.d.ts +14 -28
- package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/get-users.action.js +122 -143
- package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/index.d.ts +7 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/index.js +7 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -1
- package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts +53 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.js +236 -0
- package/dist/providers/learnworlds/actions/onboard-learner.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/sso-login.action.d.ts +35 -0
- package/dist/providers/learnworlds/actions/sso-login.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/sso-login.action.js +101 -0
- package/dist/providers/learnworlds/actions/sso-login.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +12 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/actions/update-user-progress.action.js +167 -210
- package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -1
- package/dist/providers/learnworlds/actions/update-user.action.d.ts +39 -0
- package/dist/providers/learnworlds/actions/update-user.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/update-user.action.js +168 -0
- package/dist/providers/learnworlds/actions/update-user.action.js.map +1 -0
- package/dist/providers/learnworlds/index.d.ts +1 -0
- package/dist/providers/learnworlds/index.d.ts.map +1 -1
- package/dist/providers/learnworlds/index.js +2 -0
- package/dist/providers/learnworlds/index.js.map +1 -1
- package/dist/providers/learnworlds/interfaces/bundle.types.d.ts +16 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/bundle.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.d.ts +66 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/certificate.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/common.types.d.ts +221 -0
- package/dist/providers/learnworlds/interfaces/common.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/common.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/common.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/course.types.d.ts +393 -0
- package/dist/providers/learnworlds/interfaces/course.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/course.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/course.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts +165 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/enrollment.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/index.d.ts +12 -0
- package/dist/providers/learnworlds/interfaces/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/index.js +13 -0
- package/dist/providers/learnworlds/interfaces/index.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts +39 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/onboarding.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.d.ts +108 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/quiz.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/sso.types.d.ts +18 -0
- package/dist/providers/learnworlds/interfaces/sso.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/sso.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/sso.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/sync.types.d.ts +44 -0
- package/dist/providers/learnworlds/interfaces/sync.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/sync.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/sync.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/tag.types.d.ts +17 -0
- package/dist/providers/learnworlds/interfaces/tag.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/tag.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/tag.types.js.map +1 -0
- package/dist/providers/learnworlds/interfaces/user.types.d.ts +198 -0
- package/dist/providers/learnworlds/interfaces/user.types.d.ts.map +1 -0
- package/dist/providers/learnworlds/interfaces/user.types.js +2 -0
- package/dist/providers/learnworlds/interfaces/user.types.js.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts +111 -7
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
- package/dist/providers/learnworlds/learnworlds-base.action.js +293 -56
- package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
- package/package.json +8 -7
- package/src/__tests__/attach-tags.action.test.ts +137 -0
- package/src/__tests__/create-user.action.test.ts +311 -0
- package/src/__tests__/detach-tags.action.test.ts +136 -0
- package/src/__tests__/enroll-user.action.test.ts +283 -0
- package/src/__tests__/get-bulk-data.action.test.ts +649 -0
- package/src/__tests__/get-bundles.action.test.ts +215 -0
- package/src/__tests__/lms.test.ts +275 -184
- package/src/__tests__/onboard-learner.action.test.ts +455 -0
- package/src/__tests__/sso-login.action.test.ts +256 -0
- package/src/__tests__/update-user.action.test.ts +350 -0
- package/src/base/base-lms.action.ts +226 -163
- package/src/providers/learnworlds/actions/attach-tags.action.ts +90 -0
- package/src/providers/learnworlds/actions/create-user.action.ts +291 -235
- package/src/providers/learnworlds/actions/detach-tags.action.ts +90 -0
- package/src/providers/learnworlds/actions/enroll-user.action.ts +326 -220
- package/src/providers/learnworlds/actions/get-bulk-data.action.ts +438 -0
- package/src/providers/learnworlds/actions/get-bundles.action.ts +139 -0
- package/src/providers/learnworlds/actions/get-certificates.action.ts +499 -309
- package/src/providers/learnworlds/actions/get-course-analytics.action.ts +470 -337
- package/src/providers/learnworlds/actions/get-course-details.action.ts +395 -249
- package/src/providers/learnworlds/actions/get-courses.action.ts +508 -565
- package/src/providers/learnworlds/actions/get-quiz-results.action.ts +606 -381
- package/src/providers/learnworlds/actions/get-user-details.action.ts +335 -349
- package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +328 -228
- package/src/providers/learnworlds/actions/get-user-progress.action.ts +522 -571
- package/src/providers/learnworlds/actions/get-users.action.ts +231 -282
- package/src/providers/learnworlds/actions/index.ts +8 -1
- package/src/providers/learnworlds/actions/onboard-learner.action.ts +286 -0
- package/src/providers/learnworlds/actions/sso-login.action.ts +116 -0
- package/src/providers/learnworlds/actions/update-user-progress.action.ts +301 -263
- package/src/providers/learnworlds/actions/update-user.action.ts +181 -0
- package/src/providers/learnworlds/index.ts +4 -1
- package/src/providers/learnworlds/interfaces/bundle.types.ts +17 -0
- package/src/providers/learnworlds/interfaces/certificate.types.ts +69 -0
- package/src/providers/learnworlds/interfaces/common.types.ts +233 -0
- package/src/providers/learnworlds/interfaces/course.types.ts +411 -0
- package/src/providers/learnworlds/interfaces/enrollment.types.ts +176 -0
- package/src/providers/learnworlds/interfaces/index.ts +12 -0
- package/src/providers/learnworlds/interfaces/onboarding.types.ts +41 -0
- package/src/providers/learnworlds/interfaces/quiz.types.ts +118 -0
- package/src/providers/learnworlds/interfaces/sso.types.ts +19 -0
- package/src/providers/learnworlds/interfaces/sync.types.ts +46 -0
- package/src/providers/learnworlds/interfaces/tag.types.ts +18 -0
- package/src/providers/learnworlds/interfaces/user.types.ts +204 -0
- package/src/providers/learnworlds/learnworlds-base.action.ts +468 -210
- package/tsconfig.json +1 -1
- package/dist/__tests__/lms.test.d.ts +0 -2
- package/dist/__tests__/lms.test.d.ts.map +0 -1
- package/dist/__tests__/lms.test.js +0 -232
- package/dist/__tests__/lms.test.js.map +0 -1
|
@@ -2,277 +2,315 @@ import { RegisterClass } from '@memberjunction/global';
|
|
|
2
2
|
import { LearnWorldsBaseAction } from '../learnworlds-base.action';
|
|
3
3
|
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
4
|
import { BaseAction } from '@memberjunction/actions';
|
|
5
|
+
import { UserInfo } from '@memberjunction/core';
|
|
6
|
+
import { UpdateUserProgressParams, UpdateUserProgressResult, ProgressDetails, ProgressUpdateSummary, ProgressUpdateResult } from '../interfaces';
|
|
7
|
+
|
|
8
|
+
// ----------------------------------------------------------------
|
|
9
|
+
// File-local interfaces for raw LearnWorlds API shapes
|
|
10
|
+
// ----------------------------------------------------------------
|
|
11
|
+
|
|
12
|
+
/** Shape returned by the enrollment / progress GET endpoints */
|
|
13
|
+
interface LWEnrollmentProgress {
|
|
14
|
+
progress_percentage?: number;
|
|
15
|
+
completed_units?: number;
|
|
16
|
+
total_units?: number;
|
|
17
|
+
total_time_spent?: number;
|
|
18
|
+
last_accessed_at?: string;
|
|
19
|
+
completed?: boolean;
|
|
20
|
+
completed_at?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Request body sent to the lesson-level progress PUT endpoint */
|
|
24
|
+
interface LWLessonProgressRequest {
|
|
25
|
+
completed: boolean;
|
|
26
|
+
progress_percentage?: number;
|
|
27
|
+
time_spent?: number;
|
|
28
|
+
score?: number;
|
|
29
|
+
notes?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Request body sent to the course-level progress PUT endpoint */
|
|
33
|
+
interface LWCourseProgressRequest {
|
|
34
|
+
progress_percentage?: number;
|
|
35
|
+
completed?: boolean;
|
|
36
|
+
total_time_spent?: number;
|
|
37
|
+
}
|
|
38
|
+
|
|
5
39
|
|
|
6
40
|
/**
|
|
7
41
|
* Action to update a user's course progress in LearnWorlds
|
|
8
42
|
*/
|
|
9
43
|
@RegisterClass(BaseAction, 'UpdateUserProgressAction')
|
|
10
44
|
export class UpdateUserProgressAction extends LearnWorldsBaseAction {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
const progressDetails = {
|
|
151
|
-
userId: userId,
|
|
152
|
-
courseId: courseId,
|
|
153
|
-
lessonId: lessonId,
|
|
154
|
-
previousProgress: {
|
|
155
|
-
percentage: currentEnrollment.progress_percentage || 0,
|
|
156
|
-
completedUnits: currentEnrollment.completed_units || 0,
|
|
157
|
-
totalTimeSpent: currentEnrollment.total_time_spent || 0
|
|
158
|
-
},
|
|
159
|
-
updatedProgress: {
|
|
160
|
-
percentage: updatedProgress.progress_percentage || 0,
|
|
161
|
-
completedUnits: updatedProgress.completed_units || 0,
|
|
162
|
-
totalUnits: updatedProgress.total_units || 0,
|
|
163
|
-
totalTimeSpent: updatedProgress.total_time_spent || 0,
|
|
164
|
-
totalTimeSpentText: this.formatDuration(updatedProgress.total_time_spent || 0),
|
|
165
|
-
lastAccessedAt: updatedProgress.last_accessed_at || new Date().toISOString(),
|
|
166
|
-
completed: updatedProgress.completed || false,
|
|
167
|
-
completedAt: updatedProgress.completed_at
|
|
168
|
-
},
|
|
169
|
-
updateType: lessonId ? 'lesson' : 'course',
|
|
170
|
-
updateResult: updateResult
|
|
171
|
-
};
|
|
172
|
-
|
|
173
|
-
// Create summary
|
|
174
|
-
const summary = {
|
|
175
|
-
userId: userId,
|
|
176
|
-
courseId: courseId,
|
|
177
|
-
lessonId: lessonId,
|
|
178
|
-
progressIncreased: (updatedProgress.progress_percentage || 0) > (currentEnrollment.progress_percentage || 0),
|
|
179
|
-
previousPercentage: currentEnrollment.progress_percentage || 0,
|
|
180
|
-
newPercentage: updatedProgress.progress_percentage || 0,
|
|
181
|
-
timeAdded: timeSpent || 0,
|
|
182
|
-
totalTimeSpent: updatedProgress.total_time_spent || 0,
|
|
183
|
-
isCompleted: updatedProgress.completed || false,
|
|
184
|
-
updateType: progressDetails.updateType
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
// Update output parameters
|
|
188
|
-
const outputParams = [...Params];
|
|
189
|
-
const progressDetailsParam = outputParams.find(p => p.Name === 'ProgressDetails');
|
|
190
|
-
if (progressDetailsParam) progressDetailsParam.Value = progressDetails;
|
|
191
|
-
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
192
|
-
if (summaryParam) summaryParam.Value = summary;
|
|
193
|
-
|
|
194
|
-
return {
|
|
195
|
-
Success: true,
|
|
196
|
-
ResultCode: 'SUCCESS',
|
|
197
|
-
Message: `Successfully updated ${progressDetails.updateType} progress`,
|
|
198
|
-
Params: outputParams
|
|
199
|
-
};
|
|
200
|
-
|
|
201
|
-
} catch (error) {
|
|
202
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
203
|
-
return {
|
|
204
|
-
Success: false,
|
|
205
|
-
ResultCode: 'ERROR',
|
|
206
|
-
Message: `Error updating progress: ${errorMessage}`,
|
|
207
|
-
Params
|
|
208
|
-
};
|
|
209
|
-
}
|
|
45
|
+
// ----------------------------------------------------------------
|
|
46
|
+
// Typed public method – can be called directly from code
|
|
47
|
+
// ----------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Update user progress for a course or lesson.
|
|
51
|
+
* Throws on any error.
|
|
52
|
+
*/
|
|
53
|
+
public async UpdateProgress(params: UpdateUserProgressParams, contextUser: UserInfo): Promise<UpdateUserProgressResult> {
|
|
54
|
+
this.SetCompanyContext(params.CompanyID);
|
|
55
|
+
|
|
56
|
+
const { UserID, CourseID, LessonID, ProgressPercentage, Completed, TimeSpent, Score, Notes } = params;
|
|
57
|
+
|
|
58
|
+
// Validate required fields
|
|
59
|
+
if (!UserID) {
|
|
60
|
+
throw new Error('UserID is required');
|
|
61
|
+
}
|
|
62
|
+
if (!CourseID) {
|
|
63
|
+
throw new Error('CourseID is required');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this.validatePathSegment(UserID, 'UserID');
|
|
67
|
+
this.validatePathSegment(CourseID, 'CourseID');
|
|
68
|
+
if (LessonID) {
|
|
69
|
+
this.validatePathSegment(LessonID, 'LessonID');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (ProgressPercentage !== undefined && (ProgressPercentage < 0 || ProgressPercentage > 100)) {
|
|
73
|
+
throw new Error('ProgressPercentage must be between 0 and 100');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// Get current enrollment first
|
|
77
|
+
const currentEnrollment = await this.fetchCurrentEnrollment(UserID, CourseID, contextUser);
|
|
78
|
+
|
|
79
|
+
const updateResult: ProgressUpdateResult = {};
|
|
80
|
+
|
|
81
|
+
// Update lesson progress if lessonId is provided
|
|
82
|
+
if (LessonID) {
|
|
83
|
+
updateResult.lessonProgress = await this.updateLessonProgress(
|
|
84
|
+
UserID,
|
|
85
|
+
CourseID,
|
|
86
|
+
LessonID,
|
|
87
|
+
{ Completed, ProgressPercentage, TimeSpent, Score, Notes },
|
|
88
|
+
contextUser,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Update overall course progress if progressPercentage is provided at course level
|
|
93
|
+
if (ProgressPercentage !== undefined && !LessonID) {
|
|
94
|
+
updateResult.courseProgress = await this.updateCourseProgress(
|
|
95
|
+
UserID,
|
|
96
|
+
CourseID,
|
|
97
|
+
currentEnrollment,
|
|
98
|
+
{ Completed, ProgressPercentage, TimeSpent },
|
|
99
|
+
contextUser,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Get updated enrollment details
|
|
104
|
+
const updatedProgress = await this.fetchUpdatedEnrollment(UserID, CourseID, currentEnrollment, contextUser);
|
|
105
|
+
|
|
106
|
+
// Build typed result
|
|
107
|
+
const updateType: 'lesson' | 'course' = LessonID ? 'lesson' : 'course';
|
|
108
|
+
|
|
109
|
+
const progressDetails = this.buildProgressDetails(UserID, CourseID, LessonID, currentEnrollment, updatedProgress, updateType, updateResult);
|
|
110
|
+
|
|
111
|
+
const summary = this.buildProgressSummary(UserID, CourseID, LessonID, currentEnrollment, updatedProgress, TimeSpent, updateType);
|
|
112
|
+
|
|
113
|
+
return { ProgressDetails: progressDetails, Summary: summary };
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ----------------------------------------------------------------
|
|
117
|
+
// Framework wrapper – thin delegation to the public method
|
|
118
|
+
// ----------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
121
|
+
const { Params, ContextUser } = params;
|
|
122
|
+
this.params = Params;
|
|
123
|
+
|
|
124
|
+
try {
|
|
125
|
+
const typedParams = this.extractUpdateProgressParams(Params);
|
|
126
|
+
const result = await this.UpdateProgress(typedParams, ContextUser);
|
|
127
|
+
|
|
128
|
+
this.setOutputParam(Params, 'ProgressDetails', result.ProgressDetails);
|
|
129
|
+
this.setOutputParam(Params, 'Summary', result.Summary);
|
|
130
|
+
|
|
131
|
+
return this.buildSuccessResult(`Successfully updated ${result.ProgressDetails.updateType} progress`, Params);
|
|
132
|
+
} catch (error) {
|
|
133
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
134
|
+
return this.buildErrorResult('ERROR', `Error updating progress: ${msg}`, Params);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ----------------------------------------------------------------
|
|
139
|
+
// Private helpers
|
|
140
|
+
// ----------------------------------------------------------------
|
|
141
|
+
|
|
142
|
+
private extractUpdateProgressParams(params: ActionParam[]): UpdateUserProgressParams {
|
|
143
|
+
return {
|
|
144
|
+
CompanyID: this.getRequiredStringParam(params, 'CompanyID'),
|
|
145
|
+
UserID: this.getRequiredStringParam(params, 'UserID'),
|
|
146
|
+
CourseID: this.getRequiredStringParam(params, 'CourseID'),
|
|
147
|
+
LessonID: this.getOptionalStringParam(params, 'LessonID'),
|
|
148
|
+
ProgressPercentage: this.getOptionalNumberParam(params, 'ProgressPercentage', undefined),
|
|
149
|
+
Completed: this.getOptionalBooleanParam(params, 'Completed', undefined),
|
|
150
|
+
TimeSpent: this.getOptionalNumberParam(params, 'TimeSpent', undefined),
|
|
151
|
+
Score: this.getOptionalNumberParam(params, 'Score', undefined),
|
|
152
|
+
Notes: this.getOptionalStringParam(params, 'Notes'),
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
private async fetchCurrentEnrollment(userId: string, courseId: string, contextUser: UserInfo): Promise<LWEnrollmentProgress> {
|
|
157
|
+
try {
|
|
158
|
+
return await this.makeLearnWorldsRequest<LWEnrollmentProgress>(`users/${userId}/enrollments/${courseId}`, 'GET', undefined, contextUser);
|
|
159
|
+
} catch {
|
|
160
|
+
throw new Error('User is not enrolled in this course');
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
private async updateLessonProgress(
|
|
165
|
+
userId: string,
|
|
166
|
+
courseId: string,
|
|
167
|
+
lessonId: string,
|
|
168
|
+
data: { Completed?: boolean; ProgressPercentage?: number; TimeSpent?: number; Score?: number; Notes?: string },
|
|
169
|
+
contextUser: UserInfo,
|
|
170
|
+
): Promise<Record<string, unknown>> {
|
|
171
|
+
const body: LWLessonProgressRequest = {
|
|
172
|
+
completed: data.Completed !== undefined ? data.Completed : false,
|
|
173
|
+
progress_percentage: data.ProgressPercentage,
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
if (data.TimeSpent !== undefined) {
|
|
177
|
+
body.time_spent = data.TimeSpent;
|
|
178
|
+
}
|
|
179
|
+
if (data.Score !== undefined) {
|
|
180
|
+
body.score = data.Score;
|
|
181
|
+
}
|
|
182
|
+
if (data.Notes) {
|
|
183
|
+
body.notes = data.Notes;
|
|
210
184
|
}
|
|
211
185
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
Value: null
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
Name: 'Completed',
|
|
240
|
-
Type: 'Input',
|
|
241
|
-
Value: null
|
|
242
|
-
},
|
|
243
|
-
{
|
|
244
|
-
Name: 'TimeSpent',
|
|
245
|
-
Type: 'Input',
|
|
246
|
-
Value: null
|
|
247
|
-
},
|
|
248
|
-
{
|
|
249
|
-
Name: 'Score',
|
|
250
|
-
Type: 'Input',
|
|
251
|
-
Value: null
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
Name: 'Notes',
|
|
255
|
-
Type: 'Input',
|
|
256
|
-
Value: null
|
|
257
|
-
},
|
|
258
|
-
{
|
|
259
|
-
Name: 'ProgressDetails',
|
|
260
|
-
Type: 'Output',
|
|
261
|
-
Value: null
|
|
262
|
-
},
|
|
263
|
-
{
|
|
264
|
-
Name: 'Summary',
|
|
265
|
-
Type: 'Output',
|
|
266
|
-
Value: null
|
|
267
|
-
}
|
|
268
|
-
];
|
|
269
|
-
return [...baseParams, ...specificParams];
|
|
186
|
+
return await this.makeLearnWorldsRequest<Record<string, unknown>>(
|
|
187
|
+
`users/${userId}/courses/${courseId}/lessons/${lessonId}/progress`,
|
|
188
|
+
'PUT',
|
|
189
|
+
body,
|
|
190
|
+
contextUser,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private async updateCourseProgress(
|
|
195
|
+
userId: string,
|
|
196
|
+
courseId: string,
|
|
197
|
+
currentEnrollment: LWEnrollmentProgress,
|
|
198
|
+
data: { Completed?: boolean; ProgressPercentage?: number; TimeSpent?: number },
|
|
199
|
+
contextUser: UserInfo,
|
|
200
|
+
): Promise<Record<string, unknown>> {
|
|
201
|
+
const body: LWCourseProgressRequest = {
|
|
202
|
+
progress_percentage: data.ProgressPercentage,
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
if (data.Completed !== undefined) {
|
|
206
|
+
body.completed = data.Completed;
|
|
207
|
+
}
|
|
208
|
+
if (data.TimeSpent !== undefined) {
|
|
209
|
+
body.total_time_spent = (currentEnrollment.total_time_spent || 0) + data.TimeSpent;
|
|
270
210
|
}
|
|
271
211
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
212
|
+
return await this.makeLearnWorldsRequest<Record<string, unknown>>(
|
|
213
|
+
`users/${userId}/enrollments/${courseId}/progress`,
|
|
214
|
+
'PUT',
|
|
215
|
+
body,
|
|
216
|
+
contextUser,
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
private async fetchUpdatedEnrollment(userId: string, courseId: string, fallback: LWEnrollmentProgress, contextUser: UserInfo): Promise<LWEnrollmentProgress> {
|
|
221
|
+
try {
|
|
222
|
+
return await this.makeLearnWorldsRequest<LWEnrollmentProgress>(`users/${userId}/enrollments/${courseId}`, 'GET', undefined, contextUser);
|
|
223
|
+
} catch (error) {
|
|
224
|
+
// If we can't get updated details, use previous enrollment
|
|
225
|
+
console.warn('Failed to get updated enrollment details:', error);
|
|
226
|
+
return fallback;
|
|
277
227
|
}
|
|
278
|
-
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
private buildProgressDetails(
|
|
231
|
+
userId: string,
|
|
232
|
+
courseId: string,
|
|
233
|
+
lessonId: string | undefined,
|
|
234
|
+
currentEnrollment: LWEnrollmentProgress,
|
|
235
|
+
updatedProgress: LWEnrollmentProgress,
|
|
236
|
+
updateType: 'lesson' | 'course',
|
|
237
|
+
updateResult: ProgressUpdateResult,
|
|
238
|
+
): ProgressDetails {
|
|
239
|
+
return {
|
|
240
|
+
userId,
|
|
241
|
+
courseId,
|
|
242
|
+
lessonId,
|
|
243
|
+
previousProgress: {
|
|
244
|
+
percentage: currentEnrollment.progress_percentage || 0,
|
|
245
|
+
completedUnits: currentEnrollment.completed_units || 0,
|
|
246
|
+
totalTimeSpent: currentEnrollment.total_time_spent || 0,
|
|
247
|
+
},
|
|
248
|
+
updatedProgress: {
|
|
249
|
+
percentage: updatedProgress.progress_percentage || 0,
|
|
250
|
+
completedUnits: updatedProgress.completed_units || 0,
|
|
251
|
+
totalUnits: updatedProgress.total_units || 0,
|
|
252
|
+
totalTimeSpent: updatedProgress.total_time_spent || 0,
|
|
253
|
+
totalTimeSpentText: this.formatDuration(updatedProgress.total_time_spent || 0),
|
|
254
|
+
lastAccessedAt: updatedProgress.last_accessed_at || new Date().toISOString(),
|
|
255
|
+
completed: updatedProgress.completed || false,
|
|
256
|
+
completedAt: updatedProgress.completed_at,
|
|
257
|
+
},
|
|
258
|
+
updateType,
|
|
259
|
+
updateResult,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private buildProgressSummary(
|
|
264
|
+
userId: string,
|
|
265
|
+
courseId: string,
|
|
266
|
+
lessonId: string | undefined,
|
|
267
|
+
currentEnrollment: LWEnrollmentProgress,
|
|
268
|
+
updatedProgress: LWEnrollmentProgress,
|
|
269
|
+
timeSpent: number | undefined,
|
|
270
|
+
updateType: 'lesson' | 'course',
|
|
271
|
+
): ProgressUpdateSummary {
|
|
272
|
+
return {
|
|
273
|
+
userId,
|
|
274
|
+
courseId,
|
|
275
|
+
lessonId,
|
|
276
|
+
progressIncreased: (updatedProgress.progress_percentage || 0) > (currentEnrollment.progress_percentage || 0),
|
|
277
|
+
previousPercentage: currentEnrollment.progress_percentage || 0,
|
|
278
|
+
newPercentage: updatedProgress.progress_percentage || 0,
|
|
279
|
+
timeAdded: timeSpent || 0,
|
|
280
|
+
totalTimeSpent: updatedProgress.total_time_spent || 0,
|
|
281
|
+
isCompleted: updatedProgress.completed || false,
|
|
282
|
+
updateType,
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
// ----------------------------------------------------------------
|
|
287
|
+
// Params & Description metadata
|
|
288
|
+
// ----------------------------------------------------------------
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Define the parameters this action expects
|
|
292
|
+
*/
|
|
293
|
+
public get Params(): ActionParam[] {
|
|
294
|
+
const baseParams = this.getCommonLMSParams();
|
|
295
|
+
const specificParams: ActionParam[] = [
|
|
296
|
+
{ Name: 'UserID', Type: 'Input', Value: null },
|
|
297
|
+
{ Name: 'CourseID', Type: 'Input', Value: null },
|
|
298
|
+
{ Name: 'LessonID', Type: 'Input', Value: null },
|
|
299
|
+
{ Name: 'ProgressPercentage', Type: 'Input', Value: null },
|
|
300
|
+
{ Name: 'Completed', Type: 'Input', Value: null },
|
|
301
|
+
{ Name: 'TimeSpent', Type: 'Input', Value: null },
|
|
302
|
+
{ Name: 'Score', Type: 'Input', Value: null },
|
|
303
|
+
{ Name: 'Notes', Type: 'Input', Value: null },
|
|
304
|
+
{ Name: 'ProgressDetails', Type: 'Output', Value: null },
|
|
305
|
+
{ Name: 'Summary', Type: 'Output', Value: null },
|
|
306
|
+
];
|
|
307
|
+
return [...baseParams, ...specificParams];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* Metadata about this action
|
|
312
|
+
*/
|
|
313
|
+
public get Description(): string {
|
|
314
|
+
return "Updates a user's progress for a course or specific lesson in LearnWorlds";
|
|
315
|
+
}
|
|
316
|
+
}
|