@memberjunction/actions-bizapps-lms 5.3.1 → 5.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,233 +2,339 @@ 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 { EnrollUserParams, EnrollUserResult, EnrollUserSummary, LearnWorldsEnrollment } from '../interfaces';
|
|
5
7
|
|
|
6
8
|
/**
|
|
7
|
-
*
|
|
9
|
+
* Shape returned by the LearnWorlds enrollment endpoint
|
|
10
|
+
*/
|
|
11
|
+
interface LWEnrollmentResponse {
|
|
12
|
+
success?: boolean;
|
|
13
|
+
message?: string;
|
|
14
|
+
data?: {
|
|
15
|
+
id?: string;
|
|
16
|
+
user_id?: string;
|
|
17
|
+
course_id?: string;
|
|
18
|
+
enrolled_at?: string;
|
|
19
|
+
created_at?: string;
|
|
20
|
+
starts_at?: string;
|
|
21
|
+
expires_at?: string;
|
|
22
|
+
status?: string;
|
|
23
|
+
price?: number;
|
|
24
|
+
progress_percentage?: number;
|
|
25
|
+
completed_units?: number;
|
|
26
|
+
total_units?: number;
|
|
27
|
+
last_accessed_at?: string;
|
|
28
|
+
certificate_eligible?: boolean;
|
|
29
|
+
certificate_issued_at?: string;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Shape returned by the LearnWorlds GET /courses/{id} endpoint (partial)
|
|
35
|
+
*/
|
|
36
|
+
interface LWCourseResponse {
|
|
37
|
+
success?: boolean;
|
|
38
|
+
data?: {
|
|
39
|
+
title?: string;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Shape returned by the LearnWorlds GET /users/{id} endpoint (partial)
|
|
45
|
+
*/
|
|
46
|
+
interface LWUserLookupResponse {
|
|
47
|
+
success?: boolean;
|
|
48
|
+
data?: {
|
|
49
|
+
email?: string;
|
|
50
|
+
username?: string;
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Action to enroll a user in a LearnWorlds course or bundle
|
|
8
56
|
*/
|
|
9
57
|
@RegisterClass(BaseAction, 'EnrollUserAction')
|
|
10
58
|
export class EnrollUserAction 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
|
-
// Get course and user details for summary
|
|
103
|
-
let courseTitle = 'Unknown Course';
|
|
104
|
-
let userName = 'Unknown User';
|
|
105
|
-
|
|
106
|
-
// Try to get course details
|
|
107
|
-
const courseResponse = await this.makeLearnWorldsRequest(
|
|
108
|
-
`/courses/${courseId}`,
|
|
109
|
-
'GET',
|
|
110
|
-
null,
|
|
111
|
-
ContextUser
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
if (courseResponse.success && courseResponse.data) {
|
|
115
|
-
courseTitle = courseResponse.data.title || courseTitle;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// Try to get user details
|
|
119
|
-
const userResponse = await this.makeLearnWorldsRequest(
|
|
120
|
-
`/users/${userId}`,
|
|
121
|
-
'GET',
|
|
122
|
-
null,
|
|
123
|
-
ContextUser
|
|
124
|
-
);
|
|
125
|
-
|
|
126
|
-
if (userResponse.success && userResponse.data) {
|
|
127
|
-
const user = userResponse.data;
|
|
128
|
-
userName = user.email || user.username || userName;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Create summary
|
|
132
|
-
const summary = {
|
|
133
|
-
enrollmentId: enrollmentDetails.id,
|
|
134
|
-
userId: userId,
|
|
135
|
-
userName: userName,
|
|
136
|
-
courseId: courseId,
|
|
137
|
-
courseTitle: courseTitle,
|
|
138
|
-
enrolledAt: enrollmentDetails.enrolledAt,
|
|
139
|
-
status: enrollmentDetails.status,
|
|
140
|
-
price: enrollmentDetails.price,
|
|
141
|
-
notificationSent: notifyUser
|
|
142
|
-
};
|
|
143
|
-
|
|
144
|
-
// Update output parameters
|
|
145
|
-
const outputParams = [...Params];
|
|
146
|
-
const enrollmentDetailsParam = outputParams.find(p => p.Name === 'EnrollmentDetails');
|
|
147
|
-
if (enrollmentDetailsParam) {
|
|
148
|
-
enrollmentDetailsParam.Value = enrollmentDetails;
|
|
149
|
-
}
|
|
150
|
-
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
151
|
-
if (summaryParam) {
|
|
152
|
-
summaryParam.Value = summary;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return {
|
|
156
|
-
Success: true,
|
|
157
|
-
ResultCode: 'SUCCESS',
|
|
158
|
-
Message: `Successfully enrolled user ${userName} in course ${courseTitle}`,
|
|
159
|
-
Params: outputParams
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
} catch (error) {
|
|
163
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
164
|
-
return {
|
|
165
|
-
Success: false,
|
|
166
|
-
ResultCode: 'EXECUTION_ERROR',
|
|
167
|
-
Message: `Error enrolling user: ${errorMessage}`,
|
|
168
|
-
Params
|
|
169
|
-
};
|
|
170
|
-
}
|
|
59
|
+
/**
|
|
60
|
+
* Typed public method for direct (non-framework) callers.
|
|
61
|
+
* Supports both course and bundle enrollment via ProductType.
|
|
62
|
+
* Throws on failure.
|
|
63
|
+
*/
|
|
64
|
+
public async EnrollUser(params: EnrollUserParams, contextUser: UserInfo): Promise<EnrollUserResult> {
|
|
65
|
+
this.SetCompanyContext(params.CompanyID);
|
|
66
|
+
|
|
67
|
+
if (!params.UserID) {
|
|
68
|
+
throw new Error('UserID is required');
|
|
69
|
+
}
|
|
70
|
+
if (!params.CourseID) {
|
|
71
|
+
throw new Error('CourseID is required');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.validatePathSegment(params.UserID, 'UserID');
|
|
75
|
+
this.validatePathSegment(params.CourseID, 'CourseID');
|
|
76
|
+
|
|
77
|
+
const price = params.Price ?? 0;
|
|
78
|
+
const justification = params.Justification || 'API Enrollment';
|
|
79
|
+
const notifyUser = params.NotifyUser !== false;
|
|
80
|
+
const productType = params.ProductType || 'course';
|
|
81
|
+
|
|
82
|
+
// Build enrollment body and choose endpoint based on product type
|
|
83
|
+
const { endpoint, enrollmentData } = this.buildEnrollmentRequest(
|
|
84
|
+
params.UserID,
|
|
85
|
+
params.CourseID,
|
|
86
|
+
productType,
|
|
87
|
+
price,
|
|
88
|
+
justification,
|
|
89
|
+
notifyUser,
|
|
90
|
+
params.StartDate,
|
|
91
|
+
params.ExpiryDate,
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
// Create enrollment
|
|
95
|
+
const enrollmentResponse = await this.makeLearnWorldsRequest<LWEnrollmentResponse>(endpoint, 'POST', enrollmentData, contextUser);
|
|
96
|
+
|
|
97
|
+
if (enrollmentResponse.success === false) {
|
|
98
|
+
throw new Error(enrollmentResponse.message || 'Failed to enroll user');
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const enrollment = enrollmentResponse.data;
|
|
102
|
+
|
|
103
|
+
// Format enrollment details
|
|
104
|
+
const enrollmentDetails = this.buildEnrollmentDetails(enrollment, params.UserID, params.CourseID, price);
|
|
105
|
+
|
|
106
|
+
// Fetch course title and user name in parallel for the summary
|
|
107
|
+
const [courseTitle, userName] = await Promise.all([
|
|
108
|
+
this.fetchCourseTitle(params.CourseID, contextUser),
|
|
109
|
+
this.fetchUserName(params.UserID, contextUser),
|
|
110
|
+
]);
|
|
111
|
+
|
|
112
|
+
// Create summary
|
|
113
|
+
const summary: EnrollUserSummary = {
|
|
114
|
+
enrollmentId: enrollmentDetails.id,
|
|
115
|
+
userId: params.UserID,
|
|
116
|
+
userName: userName,
|
|
117
|
+
courseId: params.CourseID,
|
|
118
|
+
courseTitle: courseTitle,
|
|
119
|
+
enrolledAt: enrollmentDetails.enrolledAt,
|
|
120
|
+
status: enrollmentDetails.status,
|
|
121
|
+
price: enrollmentDetails.price,
|
|
122
|
+
notificationSent: notifyUser,
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
EnrollmentDetails: enrollmentDetails,
|
|
127
|
+
Summary: summary,
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Framework entry point -- delegates to the typed public method.
|
|
133
|
+
*/
|
|
134
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
135
|
+
const { Params, ContextUser } = params;
|
|
136
|
+
this.params = Params;
|
|
137
|
+
|
|
138
|
+
try {
|
|
139
|
+
const typedParams = this.extractEnrollUserParams(Params);
|
|
140
|
+
const result = await this.EnrollUser(typedParams, ContextUser);
|
|
141
|
+
|
|
142
|
+
this.setOutputParam(Params, 'EnrollmentDetails', result.EnrollmentDetails);
|
|
143
|
+
this.setOutputParam(Params, 'Summary', result.Summary);
|
|
144
|
+
|
|
145
|
+
return this.buildSuccessResult(`Successfully enrolled user ${result.Summary.userName} in course ${result.Summary.courseTitle}`, Params);
|
|
146
|
+
} catch (error) {
|
|
147
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
148
|
+
return this.buildErrorResult('ERROR', `Error enrolling user: ${msg}`, Params);
|
|
171
149
|
}
|
|
150
|
+
}
|
|
172
151
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
},
|
|
219
|
-
{
|
|
220
|
-
Name: 'Summary',
|
|
221
|
-
Type: 'Output',
|
|
222
|
-
Value: null
|
|
223
|
-
}
|
|
224
|
-
];
|
|
225
|
-
return [...baseParams, ...specificParams];
|
|
152
|
+
/**
|
|
153
|
+
* Extract typed params from the generic ActionParam array
|
|
154
|
+
*/
|
|
155
|
+
private extractEnrollUserParams(params: ActionParam[]): EnrollUserParams {
|
|
156
|
+
return {
|
|
157
|
+
CompanyID: this.getRequiredStringParam(params, 'CompanyID'),
|
|
158
|
+
UserID: this.getRequiredStringParam(params, 'UserID'),
|
|
159
|
+
CourseID: this.getRequiredStringParam(params, 'CourseID'),
|
|
160
|
+
ProductType: (this.getOptionalStringParam(params, 'ProductType') || 'course') as 'course' | 'bundle',
|
|
161
|
+
Price: this.getOptionalNumberParam(params, 'Price', 0),
|
|
162
|
+
Justification: this.getOptionalStringParam(params, 'Justification') || 'API Enrollment',
|
|
163
|
+
NotifyUser: this.getOptionalBooleanParam(params, 'NotifyUser', true),
|
|
164
|
+
StartDate: this.getOptionalStringParam(params, 'StartDate'),
|
|
165
|
+
ExpiryDate: this.getOptionalStringParam(params, 'ExpiryDate'),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Build the endpoint and body based on product type (course vs bundle).
|
|
171
|
+
*/
|
|
172
|
+
private buildEnrollmentRequest(
|
|
173
|
+
userId: string,
|
|
174
|
+
courseId: string,
|
|
175
|
+
productType: 'course' | 'bundle',
|
|
176
|
+
price: number,
|
|
177
|
+
justification: string,
|
|
178
|
+
notifyUser: boolean,
|
|
179
|
+
startDate?: string,
|
|
180
|
+
expiryDate?: string,
|
|
181
|
+
): { endpoint: string; enrollmentData: Record<string, unknown> } {
|
|
182
|
+
if (productType === 'bundle') {
|
|
183
|
+
// Bundles use the generic enrollments endpoint with product_type
|
|
184
|
+
return {
|
|
185
|
+
endpoint: 'enrollments',
|
|
186
|
+
enrollmentData: {
|
|
187
|
+
product_id: courseId,
|
|
188
|
+
product_type: 'bundle',
|
|
189
|
+
user_id: userId,
|
|
190
|
+
price: price,
|
|
191
|
+
justification: justification,
|
|
192
|
+
notify_user: notifyUser,
|
|
193
|
+
...(startDate ? { starts_at: new Date(startDate).toISOString() } : {}),
|
|
194
|
+
...(expiryDate ? { expires_at: new Date(expiryDate).toISOString() } : {}),
|
|
195
|
+
},
|
|
196
|
+
};
|
|
226
197
|
}
|
|
227
198
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
199
|
+
// Courses use the per-course enrollment endpoint
|
|
200
|
+
const enrollmentData: Record<string, unknown> = {
|
|
201
|
+
user_id: userId,
|
|
202
|
+
justification: justification,
|
|
203
|
+
price: price,
|
|
204
|
+
notify_user: notifyUser,
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
if (startDate) {
|
|
208
|
+
enrollmentData.starts_at = new Date(startDate).toISOString();
|
|
233
209
|
}
|
|
234
|
-
|
|
210
|
+
if (expiryDate) {
|
|
211
|
+
enrollmentData.expires_at = new Date(expiryDate).toISOString();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
endpoint: `courses/${courseId}/enrollments`,
|
|
216
|
+
enrollmentData,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Map the raw enrollment response data to our typed LearnWorldsEnrollment shape.
|
|
222
|
+
*/
|
|
223
|
+
private buildEnrollmentDetails(enrollment: LWEnrollmentResponse['data'] | undefined, userId: string, courseId: string, price: number): LearnWorldsEnrollment {
|
|
224
|
+
return {
|
|
225
|
+
id: enrollment?.id || '',
|
|
226
|
+
userId: enrollment?.user_id || userId,
|
|
227
|
+
courseId: enrollment?.course_id || courseId,
|
|
228
|
+
enrolledAt: enrollment?.enrolled_at || enrollment?.created_at || new Date().toISOString(),
|
|
229
|
+
startsAt: enrollment?.starts_at,
|
|
230
|
+
expiresAt: enrollment?.expires_at,
|
|
231
|
+
status: enrollment?.status || 'active',
|
|
232
|
+
price: enrollment?.price ?? price,
|
|
233
|
+
progress: {
|
|
234
|
+
percentage: enrollment?.progress_percentage || 0,
|
|
235
|
+
completedUnits: enrollment?.completed_units || 0,
|
|
236
|
+
totalUnits: enrollment?.total_units || 0,
|
|
237
|
+
lastAccessedAt: enrollment?.last_accessed_at,
|
|
238
|
+
},
|
|
239
|
+
certificateEligible: enrollment?.certificate_eligible || false,
|
|
240
|
+
certificateIssuedAt: enrollment?.certificate_issued_at,
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Try to fetch the course title for the summary. Falls back to a default.
|
|
246
|
+
*/
|
|
247
|
+
private async fetchCourseTitle(courseId: string, contextUser: UserInfo): Promise<string> {
|
|
248
|
+
try {
|
|
249
|
+
const courseResponse = await this.makeLearnWorldsRequest<LWCourseResponse>(`courses/${courseId}`, 'GET', null, contextUser);
|
|
250
|
+
if (courseResponse.success !== false && courseResponse.data) {
|
|
251
|
+
return courseResponse.data.title || 'Unknown Course';
|
|
252
|
+
}
|
|
253
|
+
} catch (error) {
|
|
254
|
+
console.warn(`Failed to fetch course title for ${courseId}:`, error instanceof Error ? error.message : error);
|
|
255
|
+
}
|
|
256
|
+
return 'Unknown Course';
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Try to fetch the user display name for the summary. Falls back to a default.
|
|
261
|
+
*/
|
|
262
|
+
private async fetchUserName(userId: string, contextUser: UserInfo): Promise<string> {
|
|
263
|
+
try {
|
|
264
|
+
const userResponse = await this.makeLearnWorldsRequest<LWUserLookupResponse>(`users/${userId}`, 'GET', null, contextUser);
|
|
265
|
+
if (userResponse.success !== false && userResponse.data) {
|
|
266
|
+
return userResponse.data.email || userResponse.data.username || 'Unknown User';
|
|
267
|
+
}
|
|
268
|
+
} catch (error) {
|
|
269
|
+
console.warn(`Failed to fetch user name for ${userId}:`, error instanceof Error ? error.message : error);
|
|
270
|
+
}
|
|
271
|
+
return 'Unknown User';
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Define the parameters this action expects
|
|
276
|
+
*/
|
|
277
|
+
public get Params(): ActionParam[] {
|
|
278
|
+
const baseParams = this.getCommonLMSParams();
|
|
279
|
+
const specificParams: ActionParam[] = [
|
|
280
|
+
{
|
|
281
|
+
Name: 'UserID',
|
|
282
|
+
Type: 'Input',
|
|
283
|
+
Value: null,
|
|
284
|
+
},
|
|
285
|
+
{
|
|
286
|
+
Name: 'CourseID',
|
|
287
|
+
Type: 'Input',
|
|
288
|
+
Value: null,
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
Name: 'ProductType',
|
|
292
|
+
Type: 'Input',
|
|
293
|
+
Value: 'course',
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
Name: 'Price',
|
|
297
|
+
Type: 'Input',
|
|
298
|
+
Value: 0,
|
|
299
|
+
},
|
|
300
|
+
{
|
|
301
|
+
Name: 'Justification',
|
|
302
|
+
Type: 'Input',
|
|
303
|
+
Value: 'API Enrollment',
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
Name: 'NotifyUser',
|
|
307
|
+
Type: 'Input',
|
|
308
|
+
Value: true,
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
Name: 'StartDate',
|
|
312
|
+
Type: 'Input',
|
|
313
|
+
Value: null,
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
Name: 'ExpiryDate',
|
|
317
|
+
Type: 'Input',
|
|
318
|
+
Value: null,
|
|
319
|
+
},
|
|
320
|
+
{
|
|
321
|
+
Name: 'EnrollmentDetails',
|
|
322
|
+
Type: 'Output',
|
|
323
|
+
Value: null,
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
Name: 'Summary',
|
|
327
|
+
Type: 'Output',
|
|
328
|
+
Value: null,
|
|
329
|
+
},
|
|
330
|
+
];
|
|
331
|
+
return [...baseParams, ...specificParams];
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Metadata about this action
|
|
336
|
+
*/
|
|
337
|
+
public get Description(): string {
|
|
338
|
+
return 'Enrolls a user in a LearnWorlds course or bundle with optional pricing and notification settings';
|
|
339
|
+
}
|
|
340
|
+
}
|