@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,249 +2,305 @@ 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 { CreateUserParams, CreateUserResult, CreateUserDetails, CreateUserEnrollmentResult, CreateUserSummary, LWApiUser } from '../interfaces';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shape returned by the LearnWorlds POST /users endpoint
|
|
10
|
+
*/
|
|
11
|
+
interface LWCreateUserResponse {
|
|
12
|
+
id: string;
|
|
13
|
+
email: string;
|
|
14
|
+
username?: string;
|
|
15
|
+
first_name?: string;
|
|
16
|
+
last_name?: string;
|
|
17
|
+
role?: string;
|
|
18
|
+
is_active?: boolean;
|
|
19
|
+
tags?: string[];
|
|
20
|
+
custom_fields?: Record<string, unknown>;
|
|
21
|
+
created_at?: string;
|
|
22
|
+
login_url?: string;
|
|
23
|
+
reset_password_url?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Shape returned by the LearnWorlds POST /courses/{id}/enrollments endpoint
|
|
28
|
+
*/
|
|
29
|
+
interface LWEnrollmentResponse {
|
|
30
|
+
id?: string;
|
|
31
|
+
}
|
|
5
32
|
|
|
6
33
|
/**
|
|
7
34
|
* Action to create a new user in LearnWorlds
|
|
8
35
|
*/
|
|
9
36
|
@RegisterClass(BaseAction, 'CreateUserAction')
|
|
10
37
|
export class CreateUserAction extends LearnWorldsBaseAction {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
const username = this.getParamValue(Params, 'Username');
|
|
22
|
-
const password = this.getParamValue(Params, 'Password');
|
|
23
|
-
const firstName = this.getParamValue(Params, 'FirstName');
|
|
24
|
-
const lastName = this.getParamValue(Params, 'LastName');
|
|
25
|
-
const role = this.getParamValue(Params, 'Role') || 'student';
|
|
26
|
-
const isActive = this.getParamValue(Params, 'IsActive') !== false;
|
|
27
|
-
const sendWelcomeEmail = this.getParamValue(Params, 'SendWelcomeEmail') !== false;
|
|
28
|
-
const tags = this.getParamValue(Params, 'Tags');
|
|
29
|
-
const customFields = this.getParamValue(Params, 'CustomFields');
|
|
30
|
-
const enrollInCourses = this.getParamValue(Params, 'EnrollInCourses');
|
|
31
|
-
|
|
32
|
-
if (!email) {
|
|
33
|
-
return {
|
|
34
|
-
Success: false,
|
|
35
|
-
ResultCode: 'VALIDATION_ERROR',
|
|
36
|
-
Message: 'Email is required',
|
|
37
|
-
Params
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Prepare user data
|
|
42
|
-
const userData: any = {
|
|
43
|
-
email: email,
|
|
44
|
-
role: role,
|
|
45
|
-
is_active: isActive
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
// Add optional fields
|
|
49
|
-
if (username) userData.username = username;
|
|
50
|
-
if (password) userData.password = password;
|
|
51
|
-
if (firstName) userData.first_name = firstName;
|
|
52
|
-
if (lastName) userData.last_name = lastName;
|
|
53
|
-
if (sendWelcomeEmail !== undefined) userData.send_welcome_email = sendWelcomeEmail;
|
|
54
|
-
|
|
55
|
-
// Add tags if provided (expecting comma-separated string or array)
|
|
56
|
-
if (tags) {
|
|
57
|
-
userData.tags = Array.isArray(tags) ? tags : tags.split(',').map((t: string) => t.trim());
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// Add custom fields if provided
|
|
61
|
-
if (customFields) {
|
|
62
|
-
userData.custom_fields = customFields;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Create user
|
|
66
|
-
const newUser = await this.makeLearnWorldsRequest<any>(
|
|
67
|
-
'users',
|
|
68
|
-
'POST',
|
|
69
|
-
userData,
|
|
70
|
-
ContextUser
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
// Format user details
|
|
74
|
-
const userDetails = {
|
|
75
|
-
id: newUser.id,
|
|
76
|
-
email: newUser.email,
|
|
77
|
-
username: newUser.username,
|
|
78
|
-
firstName: newUser.first_name,
|
|
79
|
-
lastName: newUser.last_name,
|
|
80
|
-
fullName: `${newUser.first_name || ''} ${newUser.last_name || ''}`.trim(),
|
|
81
|
-
role: newUser.role,
|
|
82
|
-
status: newUser.is_active ? 'active' : 'inactive',
|
|
83
|
-
tags: newUser.tags || [],
|
|
84
|
-
customFields: newUser.custom_fields || {},
|
|
85
|
-
createdAt: newUser.created_at,
|
|
86
|
-
loginUrl: newUser.login_url,
|
|
87
|
-
resetPasswordUrl: newUser.reset_password_url
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
// Enroll in courses if requested
|
|
91
|
-
const enrollmentResults: any[] = [];
|
|
92
|
-
if (enrollInCourses && enrollInCourses.length > 0) {
|
|
93
|
-
const courseIds = Array.isArray(enrollInCourses) ? enrollInCourses : [enrollInCourses];
|
|
94
|
-
|
|
95
|
-
for (const courseId of courseIds) {
|
|
96
|
-
try {
|
|
97
|
-
const enrollData = await this.makeLearnWorldsRequest<any>(
|
|
98
|
-
`courses/${courseId}/enrollments`,
|
|
99
|
-
'POST',
|
|
100
|
-
{
|
|
101
|
-
user_id: newUser.id,
|
|
102
|
-
justification: 'Enrolled during user creation',
|
|
103
|
-
notify_user: false
|
|
104
|
-
},
|
|
105
|
-
ContextUser
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
enrollmentResults.push({
|
|
109
|
-
courseId: courseId,
|
|
110
|
-
success: true,
|
|
111
|
-
enrollmentId: enrollData.id
|
|
112
|
-
});
|
|
113
|
-
} catch (enrollError) {
|
|
114
|
-
enrollmentResults.push({
|
|
115
|
-
courseId: courseId,
|
|
116
|
-
success: false,
|
|
117
|
-
error: enrollError instanceof Error ? enrollError.message : 'Enrollment failed'
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Create summary
|
|
124
|
-
const summary = {
|
|
125
|
-
userId: userDetails.id,
|
|
126
|
-
email: userDetails.email,
|
|
127
|
-
username: userDetails.username,
|
|
128
|
-
fullName: userDetails.fullName,
|
|
129
|
-
role: userDetails.role,
|
|
130
|
-
status: userDetails.status,
|
|
131
|
-
welcomeEmailSent: sendWelcomeEmail,
|
|
132
|
-
coursesEnrolled: enrollmentResults.filter(r => r.success).length,
|
|
133
|
-
totalCoursesRequested: enrollmentResults.length,
|
|
134
|
-
loginUrl: userDetails.loginUrl
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
// Update output parameters
|
|
138
|
-
const outputParams = [...Params];
|
|
139
|
-
const userDetailsParam = outputParams.find(p => p.Name === 'UserDetails');
|
|
140
|
-
if (userDetailsParam) userDetailsParam.Value = userDetails;
|
|
141
|
-
const enrollmentResultsParam = outputParams.find(p => p.Name === 'EnrollmentResults');
|
|
142
|
-
if (enrollmentResultsParam) enrollmentResultsParam.Value = enrollmentResults;
|
|
143
|
-
const summaryParam = outputParams.find(p => p.Name === 'Summary');
|
|
144
|
-
if (summaryParam) summaryParam.Value = summary;
|
|
145
|
-
|
|
146
|
-
return {
|
|
147
|
-
Success: true,
|
|
148
|
-
ResultCode: 'SUCCESS',
|
|
149
|
-
Message: `Successfully created user ${userDetails.email}`,
|
|
150
|
-
Params: outputParams
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
} catch (error) {
|
|
154
|
-
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
155
|
-
return {
|
|
156
|
-
Success: false,
|
|
157
|
-
ResultCode: 'ERROR',
|
|
158
|
-
Message: `Error creating user: ${errorMessage}`,
|
|
159
|
-
Params
|
|
160
|
-
};
|
|
161
|
-
}
|
|
38
|
+
/**
|
|
39
|
+
* Typed public method for direct (non-framework) callers.
|
|
40
|
+
* Throws on failure instead of returning ActionResultSimple.
|
|
41
|
+
*/
|
|
42
|
+
public async CreateUser(params: CreateUserParams, contextUser: UserInfo): Promise<CreateUserResult> {
|
|
43
|
+
this.SetCompanyContext(params.CompanyID);
|
|
44
|
+
|
|
45
|
+
const email = params.Email;
|
|
46
|
+
if (!email) {
|
|
47
|
+
throw new Error('Email is required');
|
|
162
48
|
}
|
|
49
|
+
this.validateEmail(email);
|
|
50
|
+
|
|
51
|
+
const role = this.validateRole(params.Role || 'student');
|
|
52
|
+
const isActive = params.IsActive !== false;
|
|
53
|
+
const sendWelcomeEmail = params.SendWelcomeEmail !== false;
|
|
54
|
+
|
|
55
|
+
// Prepare user data
|
|
56
|
+
const userData: Record<string, unknown> = {
|
|
57
|
+
email: email,
|
|
58
|
+
role: role,
|
|
59
|
+
is_active: isActive,
|
|
60
|
+
};
|
|
163
61
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
},
|
|
175
|
-
{
|
|
176
|
-
Name: 'Username',
|
|
177
|
-
Type: 'Input',
|
|
178
|
-
Value: null
|
|
179
|
-
},
|
|
180
|
-
{
|
|
181
|
-
Name: 'Password',
|
|
182
|
-
Type: 'Input',
|
|
183
|
-
Value: null
|
|
184
|
-
},
|
|
185
|
-
{
|
|
186
|
-
Name: 'FirstName',
|
|
187
|
-
Type: 'Input',
|
|
188
|
-
Value: null
|
|
189
|
-
},
|
|
190
|
-
{
|
|
191
|
-
Name: 'LastName',
|
|
192
|
-
Type: 'Input',
|
|
193
|
-
Value: null
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
Name: 'Role',
|
|
197
|
-
Type: 'Input',
|
|
198
|
-
Value: 'student'
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
Name: 'IsActive',
|
|
202
|
-
Type: 'Input',
|
|
203
|
-
Value: true
|
|
204
|
-
},
|
|
205
|
-
{
|
|
206
|
-
Name: 'SendWelcomeEmail',
|
|
207
|
-
Type: 'Input',
|
|
208
|
-
Value: true
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
Name: 'Tags',
|
|
212
|
-
Type: 'Input',
|
|
213
|
-
Value: null
|
|
214
|
-
},
|
|
215
|
-
{
|
|
216
|
-
Name: 'CustomFields',
|
|
217
|
-
Type: 'Input',
|
|
218
|
-
Value: null
|
|
219
|
-
},
|
|
220
|
-
{
|
|
221
|
-
Name: 'EnrollInCourses',
|
|
222
|
-
Type: 'Input',
|
|
223
|
-
Value: null
|
|
224
|
-
},
|
|
225
|
-
{
|
|
226
|
-
Name: 'UserDetails',
|
|
227
|
-
Type: 'Output',
|
|
228
|
-
Value: null
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
Name: 'EnrollmentResults',
|
|
232
|
-
Type: 'Output',
|
|
233
|
-
Value: null
|
|
234
|
-
},
|
|
235
|
-
{
|
|
236
|
-
Name: 'Summary',
|
|
237
|
-
Type: 'Output',
|
|
238
|
-
Value: null
|
|
239
|
-
}
|
|
240
|
-
];
|
|
241
|
-
return [...baseParams, ...specificParams];
|
|
62
|
+
// Add optional fields
|
|
63
|
+
if (params.Username) userData.username = params.Username;
|
|
64
|
+
if (params.Password) userData.password = params.Password;
|
|
65
|
+
if (params.FirstName) userData.first_name = params.FirstName;
|
|
66
|
+
if (params.LastName) userData.last_name = params.LastName;
|
|
67
|
+
userData.send_welcome_email = sendWelcomeEmail;
|
|
68
|
+
|
|
69
|
+
// Add tags if provided (expecting comma-separated string or array)
|
|
70
|
+
if (params.Tags) {
|
|
71
|
+
userData.tags = Array.isArray(params.Tags) ? params.Tags : params.Tags.split(',').map((t: string) => t.trim());
|
|
242
72
|
}
|
|
243
73
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
public get Description(): string {
|
|
248
|
-
return 'Creates a new user in LearnWorlds with optional course enrollments and welcome email';
|
|
74
|
+
// Add custom fields if provided
|
|
75
|
+
if (params.CustomFields) {
|
|
76
|
+
userData.custom_fields = params.CustomFields;
|
|
249
77
|
}
|
|
250
|
-
|
|
78
|
+
|
|
79
|
+
// Create user
|
|
80
|
+
const newUser = await this.makeLearnWorldsRequest<LWCreateUserResponse>('users', 'POST', userData, contextUser);
|
|
81
|
+
|
|
82
|
+
// Format user details
|
|
83
|
+
const userDetails = this.buildUserDetails(newUser);
|
|
84
|
+
|
|
85
|
+
// Enroll in courses if requested
|
|
86
|
+
const enrollmentResults = await this.enrollInCourses(newUser.id, params.EnrollInCourses, contextUser);
|
|
87
|
+
|
|
88
|
+
// Create summary
|
|
89
|
+
const summary = this.buildSummary(userDetails, sendWelcomeEmail, enrollmentResults);
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
UserDetails: userDetails,
|
|
93
|
+
EnrollmentResults: enrollmentResults,
|
|
94
|
+
Summary: summary,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Framework entry point -- delegates to the typed public method.
|
|
100
|
+
*/
|
|
101
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
102
|
+
const { Params, ContextUser } = params;
|
|
103
|
+
this.params = Params;
|
|
104
|
+
|
|
105
|
+
try {
|
|
106
|
+
const typedParams = this.extractCreateUserParams(Params);
|
|
107
|
+
const result = await this.CreateUser(typedParams, ContextUser);
|
|
108
|
+
|
|
109
|
+
this.setOutputParam(Params, 'UserDetails', result.UserDetails);
|
|
110
|
+
this.setOutputParam(Params, 'EnrollmentResults', result.EnrollmentResults);
|
|
111
|
+
this.setOutputParam(Params, 'Summary', result.Summary);
|
|
112
|
+
|
|
113
|
+
return this.buildSuccessResult(`Successfully created user ${result.UserDetails.email}`, Params);
|
|
114
|
+
} catch (error) {
|
|
115
|
+
const msg = error instanceof Error ? error.message : 'Unknown error';
|
|
116
|
+
return this.buildErrorResult('ERROR', `Error creating user: ${msg}`, Params);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Extract typed params from the generic ActionParam array
|
|
122
|
+
*/
|
|
123
|
+
private extractCreateUserParams(params: ActionParam[]): CreateUserParams {
|
|
124
|
+
return {
|
|
125
|
+
CompanyID: this.getRequiredStringParam(params, 'CompanyID'),
|
|
126
|
+
Email: this.getRequiredStringParam(params, 'Email'),
|
|
127
|
+
Username: this.getOptionalStringParam(params, 'Username'),
|
|
128
|
+
Password: this.getOptionalStringParam(params, 'Password'),
|
|
129
|
+
FirstName: this.getOptionalStringParam(params, 'FirstName'),
|
|
130
|
+
LastName: this.getOptionalStringParam(params, 'LastName'),
|
|
131
|
+
Role: this.getOptionalStringParam(params, 'Role') || 'student',
|
|
132
|
+
IsActive: this.getOptionalBooleanParam(params, 'IsActive', undefined),
|
|
133
|
+
SendWelcomeEmail: this.getOptionalBooleanParam(params, 'SendWelcomeEmail', undefined),
|
|
134
|
+
Tags: this.getParamValue(params, 'Tags') as string | string[] | undefined,
|
|
135
|
+
CustomFields: this.getParamValue(params, 'CustomFields') as Record<string, unknown> | undefined,
|
|
136
|
+
EnrollInCourses: this.getParamValue(params, 'EnrollInCourses') as string | string[] | undefined,
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Map the raw LW create-user response to our typed details shape.
|
|
142
|
+
*/
|
|
143
|
+
private buildUserDetails(newUser: LWCreateUserResponse): CreateUserDetails {
|
|
144
|
+
return {
|
|
145
|
+
id: newUser.id,
|
|
146
|
+
email: newUser.email,
|
|
147
|
+
username: newUser.username,
|
|
148
|
+
firstName: newUser.first_name,
|
|
149
|
+
lastName: newUser.last_name,
|
|
150
|
+
fullName: `${newUser.first_name || ''} ${newUser.last_name || ''}`.trim(),
|
|
151
|
+
role: newUser.role || 'student',
|
|
152
|
+
status: newUser.is_active ? 'active' : 'inactive',
|
|
153
|
+
tags: newUser.tags || [],
|
|
154
|
+
customFields: newUser.custom_fields || {},
|
|
155
|
+
createdAt: newUser.created_at,
|
|
156
|
+
loginUrl: newUser.login_url,
|
|
157
|
+
resetPasswordUrl: newUser.reset_password_url,
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Enroll the newly created user in any requested courses.
|
|
163
|
+
*/
|
|
164
|
+
private async enrollInCourses(userId: string, enrollInCourses: string | string[] | undefined, contextUser: UserInfo): Promise<CreateUserEnrollmentResult[]> {
|
|
165
|
+
const enrollmentResults: CreateUserEnrollmentResult[] = [];
|
|
166
|
+
|
|
167
|
+
if (!enrollInCourses || (Array.isArray(enrollInCourses) && enrollInCourses.length === 0)) {
|
|
168
|
+
return enrollmentResults;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const courseIds = Array.isArray(enrollInCourses) ? enrollInCourses : [enrollInCourses];
|
|
172
|
+
|
|
173
|
+
for (const courseId of courseIds) {
|
|
174
|
+
try {
|
|
175
|
+
this.validatePathSegment(courseId, 'CourseID');
|
|
176
|
+
|
|
177
|
+
const enrollBody: Record<string, unknown> = {
|
|
178
|
+
user_id: userId,
|
|
179
|
+
justification: 'Enrolled during user creation',
|
|
180
|
+
notify_user: false,
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const enrollData = await this.makeLearnWorldsRequest<LWEnrollmentResponse>(`courses/${courseId}/enrollments`, 'POST', enrollBody, contextUser);
|
|
184
|
+
|
|
185
|
+
enrollmentResults.push({
|
|
186
|
+
courseId: courseId,
|
|
187
|
+
success: true,
|
|
188
|
+
enrollmentId: enrollData.id,
|
|
189
|
+
});
|
|
190
|
+
} catch (enrollError) {
|
|
191
|
+
enrollmentResults.push({
|
|
192
|
+
courseId: courseId,
|
|
193
|
+
success: false,
|
|
194
|
+
error: enrollError instanceof Error ? enrollError.message : 'Enrollment failed',
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return enrollmentResults;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Build the summary object from user details and enrollment results.
|
|
204
|
+
*/
|
|
205
|
+
private buildSummary(userDetails: CreateUserDetails, sendWelcomeEmail: boolean, enrollmentResults: CreateUserEnrollmentResult[]): CreateUserSummary {
|
|
206
|
+
return {
|
|
207
|
+
userId: userDetails.id,
|
|
208
|
+
email: userDetails.email,
|
|
209
|
+
username: userDetails.username,
|
|
210
|
+
fullName: userDetails.fullName,
|
|
211
|
+
role: userDetails.role,
|
|
212
|
+
status: userDetails.status,
|
|
213
|
+
welcomeEmailSent: sendWelcomeEmail,
|
|
214
|
+
coursesEnrolled: enrollmentResults.filter((r) => r.success).length,
|
|
215
|
+
totalCoursesRequested: enrollmentResults.length,
|
|
216
|
+
loginUrl: userDetails.loginUrl,
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Define the parameters this action expects
|
|
222
|
+
*/
|
|
223
|
+
public get Params(): ActionParam[] {
|
|
224
|
+
const baseParams = this.getCommonLMSParams();
|
|
225
|
+
const specificParams: ActionParam[] = [
|
|
226
|
+
{
|
|
227
|
+
Name: 'Email',
|
|
228
|
+
Type: 'Input',
|
|
229
|
+
Value: null,
|
|
230
|
+
},
|
|
231
|
+
{
|
|
232
|
+
Name: 'Username',
|
|
233
|
+
Type: 'Input',
|
|
234
|
+
Value: null,
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
Name: 'Password',
|
|
238
|
+
Type: 'Input',
|
|
239
|
+
Value: null,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
Name: 'FirstName',
|
|
243
|
+
Type: 'Input',
|
|
244
|
+
Value: null,
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
Name: 'LastName',
|
|
248
|
+
Type: 'Input',
|
|
249
|
+
Value: null,
|
|
250
|
+
},
|
|
251
|
+
{
|
|
252
|
+
Name: 'Role',
|
|
253
|
+
Type: 'Input',
|
|
254
|
+
Value: 'student',
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
Name: 'IsActive',
|
|
258
|
+
Type: 'Input',
|
|
259
|
+
Value: true,
|
|
260
|
+
},
|
|
261
|
+
{
|
|
262
|
+
Name: 'SendWelcomeEmail',
|
|
263
|
+
Type: 'Input',
|
|
264
|
+
Value: true,
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
Name: 'Tags',
|
|
268
|
+
Type: 'Input',
|
|
269
|
+
Value: null,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
Name: 'CustomFields',
|
|
273
|
+
Type: 'Input',
|
|
274
|
+
Value: null,
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
Name: 'EnrollInCourses',
|
|
278
|
+
Type: 'Input',
|
|
279
|
+
Value: null,
|
|
280
|
+
},
|
|
281
|
+
{
|
|
282
|
+
Name: 'UserDetails',
|
|
283
|
+
Type: 'Output',
|
|
284
|
+
Value: null,
|
|
285
|
+
},
|
|
286
|
+
{
|
|
287
|
+
Name: 'EnrollmentResults',
|
|
288
|
+
Type: 'Output',
|
|
289
|
+
Value: null,
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
Name: 'Summary',
|
|
293
|
+
Type: 'Output',
|
|
294
|
+
Value: null,
|
|
295
|
+
},
|
|
296
|
+
];
|
|
297
|
+
return [...baseParams, ...specificParams];
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Metadata about this action
|
|
302
|
+
*/
|
|
303
|
+
public get Description(): string {
|
|
304
|
+
return 'Creates a new user in LearnWorlds with optional course enrollments and welcome email';
|
|
305
|
+
}
|
|
306
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
2
|
+
import { LearnWorldsBaseAction } from '../learnworlds-base.action';
|
|
3
|
+
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
|
+
import { BaseAction } from '@memberjunction/actions';
|
|
5
|
+
import { UserInfo } from '@memberjunction/core';
|
|
6
|
+
import { TagParams, TagResult } from '../interfaces';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shape of the LearnWorlds tag operation API response
|
|
10
|
+
*/
|
|
11
|
+
interface LWApiTagResponse {
|
|
12
|
+
tags?: string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Action to detach tags from a LearnWorlds user
|
|
17
|
+
*/
|
|
18
|
+
@RegisterClass(BaseAction, 'DetachTagsAction')
|
|
19
|
+
export class DetachTagsAction extends LearnWorldsBaseAction {
|
|
20
|
+
/**
|
|
21
|
+
* Detaches one or more tags from a LearnWorlds user.
|
|
22
|
+
*/
|
|
23
|
+
public async DetachTags(params: TagParams, contextUser: UserInfo): Promise<TagResult> {
|
|
24
|
+
this.SetCompanyContext(params.CompanyID);
|
|
25
|
+
|
|
26
|
+
if (!params.UserID) {
|
|
27
|
+
throw new Error('UserID is required');
|
|
28
|
+
}
|
|
29
|
+
if (!params.Tags || params.Tags.length === 0) {
|
|
30
|
+
throw new Error('At least one tag is required');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.validatePathSegment(params.UserID, 'UserID');
|
|
34
|
+
|
|
35
|
+
const response = await this.makeLearnWorldsRequest<LWApiTagResponse>(`users/${params.UserID}/tags`, 'DELETE', { tags: params.Tags }, contextUser);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
Success: true,
|
|
39
|
+
UserID: params.UserID,
|
|
40
|
+
Tags: response.tags || params.Tags,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Framework entry point that delegates to the typed public method
|
|
46
|
+
*/
|
|
47
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
48
|
+
const { Params, ContextUser } = params;
|
|
49
|
+
this.params = Params;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const tagParams: TagParams = {
|
|
53
|
+
CompanyID: this.getRequiredStringParam(Params, 'CompanyID'),
|
|
54
|
+
UserID: this.getRequiredStringParam(Params, 'UserID'),
|
|
55
|
+
Tags: this.getOptionalStringArrayParam(Params, 'Tags') || [],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const result = await this.DetachTags(tagParams, ContextUser);
|
|
59
|
+
|
|
60
|
+
this.setOutputParam(Params, 'Success', result.Success);
|
|
61
|
+
this.setOutputParam(Params, 'ResultTags', result.Tags);
|
|
62
|
+
|
|
63
|
+
return this.buildSuccessResult(`Successfully detached ${result.Tags.length} tag(s) from user ${result.UserID}`, Params);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
66
|
+
return this.buildErrorResult('ERROR', `Error detaching tags: ${errorMessage}`, Params);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Define the parameters this action expects
|
|
72
|
+
*/
|
|
73
|
+
public get Params(): ActionParam[] {
|
|
74
|
+
const baseParams = this.getCommonLMSParams();
|
|
75
|
+
const specificParams: ActionParam[] = [
|
|
76
|
+
{ Name: 'UserID', Type: 'Input', Value: null },
|
|
77
|
+
{ Name: 'Tags', Type: 'Input', Value: null },
|
|
78
|
+
{ Name: 'Success', Type: 'Output', Value: null },
|
|
79
|
+
{ Name: 'ResultTags', Type: 'Output', Value: null },
|
|
80
|
+
];
|
|
81
|
+
return [...baseParams, ...specificParams];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Metadata about this action
|
|
86
|
+
*/
|
|
87
|
+
public get Description(): string {
|
|
88
|
+
return 'Detaches one or more tags from a LearnWorlds user';
|
|
89
|
+
}
|
|
90
|
+
}
|