@memberjunction/actions-bizapps-lms 5.3.1 → 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.
Files changed (194) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +16 -0
  3. package/LEARNWORLDS_SIDECAR_PLAN.md +845 -0
  4. package/dist/base/base-lms.action.d.ts +26 -4
  5. package/dist/base/base-lms.action.d.ts.map +1 -1
  6. package/dist/base/base-lms.action.js +73 -17
  7. package/dist/base/base-lms.action.js.map +1 -1
  8. package/dist/providers/learnworlds/actions/attach-tags.action.d.ts +26 -0
  9. package/dist/providers/learnworlds/actions/attach-tags.action.d.ts.map +1 -0
  10. package/dist/providers/learnworlds/actions/attach-tags.action.js +79 -0
  11. package/dist/providers/learnworlds/actions/attach-tags.action.js.map +1 -0
  12. package/dist/providers/learnworlds/actions/create-user.action.d.ts +24 -1
  13. package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
  14. package/dist/providers/learnworlds/actions/create-user.action.js +166 -142
  15. package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
  16. package/dist/providers/learnworlds/actions/detach-tags.action.d.ts +26 -0
  17. package/dist/providers/learnworlds/actions/detach-tags.action.d.ts.map +1 -0
  18. package/dist/providers/learnworlds/actions/detach-tags.action.js +79 -0
  19. package/dist/providers/learnworlds/actions/detach-tags.action.js.map +1 -0
  20. package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +31 -3
  21. package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -1
  22. package/dist/providers/learnworlds/actions/enroll-user.action.js +179 -125
  23. package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -1
  24. package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts +79 -0
  25. package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts.map +1 -0
  26. package/dist/providers/learnworlds/actions/get-bulk-data.action.js +359 -0
  27. package/dist/providers/learnworlds/actions/get-bulk-data.action.js.map +1 -0
  28. package/dist/providers/learnworlds/actions/get-bundles.action.d.ts +34 -0
  29. package/dist/providers/learnworlds/actions/get-bundles.action.d.ts.map +1 -0
  30. package/dist/providers/learnworlds/actions/get-bundles.action.js +107 -0
  31. package/dist/providers/learnworlds/actions/get-bundles.action.js.map +1 -0
  32. package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +33 -2
  33. package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -1
  34. package/dist/providers/learnworlds/actions/get-certificates.action.js +311 -244
  35. package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -1
  36. package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +14 -14
  37. package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -1
  38. package/dist/providers/learnworlds/actions/get-course-analytics.action.js +234 -226
  39. package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -1
  40. package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +42 -6
  41. package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -1
  42. package/dist/providers/learnworlds/actions/get-course-details.action.js +182 -148
  43. package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
  44. package/dist/providers/learnworlds/actions/get-courses.action.d.ts +29 -82
  45. package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -1
  46. package/dist/providers/learnworlds/actions/get-courses.action.js +188 -207
  47. package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -1
  48. package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +22 -2
  49. package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -1
  50. package/dist/providers/learnworlds/actions/get-quiz-results.action.js +316 -294
  51. package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -1
  52. package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +23 -59
  53. package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -1
  54. package/dist/providers/learnworlds/actions/get-user-details.action.js +113 -114
  55. package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
  56. package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +43 -5
  57. package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -1
  58. package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +191 -147
  59. package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -1
  60. package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +21 -92
  61. package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -1
  62. package/dist/providers/learnworlds/actions/get-user-progress.action.js +145 -166
  63. package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -1
  64. package/dist/providers/learnworlds/actions/get-users.action.d.ts +14 -28
  65. package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -1
  66. package/dist/providers/learnworlds/actions/get-users.action.js +122 -143
  67. package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
  68. package/dist/providers/learnworlds/actions/index.d.ts +7 -0
  69. package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
  70. package/dist/providers/learnworlds/actions/index.js +7 -0
  71. package/dist/providers/learnworlds/actions/index.js.map +1 -1
  72. package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts +53 -0
  73. package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts.map +1 -0
  74. package/dist/providers/learnworlds/actions/onboard-learner.action.js +236 -0
  75. package/dist/providers/learnworlds/actions/onboard-learner.action.js.map +1 -0
  76. package/dist/providers/learnworlds/actions/sso-login.action.d.ts +35 -0
  77. package/dist/providers/learnworlds/actions/sso-login.action.d.ts.map +1 -0
  78. package/dist/providers/learnworlds/actions/sso-login.action.js +101 -0
  79. package/dist/providers/learnworlds/actions/sso-login.action.js.map +1 -0
  80. package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +12 -1
  81. package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -1
  82. package/dist/providers/learnworlds/actions/update-user-progress.action.js +167 -210
  83. package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -1
  84. package/dist/providers/learnworlds/actions/update-user.action.d.ts +39 -0
  85. package/dist/providers/learnworlds/actions/update-user.action.d.ts.map +1 -0
  86. package/dist/providers/learnworlds/actions/update-user.action.js +168 -0
  87. package/dist/providers/learnworlds/actions/update-user.action.js.map +1 -0
  88. package/dist/providers/learnworlds/index.d.ts +1 -0
  89. package/dist/providers/learnworlds/index.d.ts.map +1 -1
  90. package/dist/providers/learnworlds/index.js +2 -0
  91. package/dist/providers/learnworlds/index.js.map +1 -1
  92. package/dist/providers/learnworlds/interfaces/bundle.types.d.ts +16 -0
  93. package/dist/providers/learnworlds/interfaces/bundle.types.d.ts.map +1 -0
  94. package/dist/providers/learnworlds/interfaces/bundle.types.js +2 -0
  95. package/dist/providers/learnworlds/interfaces/bundle.types.js.map +1 -0
  96. package/dist/providers/learnworlds/interfaces/certificate.types.d.ts +66 -0
  97. package/dist/providers/learnworlds/interfaces/certificate.types.d.ts.map +1 -0
  98. package/dist/providers/learnworlds/interfaces/certificate.types.js +2 -0
  99. package/dist/providers/learnworlds/interfaces/certificate.types.js.map +1 -0
  100. package/dist/providers/learnworlds/interfaces/common.types.d.ts +221 -0
  101. package/dist/providers/learnworlds/interfaces/common.types.d.ts.map +1 -0
  102. package/dist/providers/learnworlds/interfaces/common.types.js +2 -0
  103. package/dist/providers/learnworlds/interfaces/common.types.js.map +1 -0
  104. package/dist/providers/learnworlds/interfaces/course.types.d.ts +393 -0
  105. package/dist/providers/learnworlds/interfaces/course.types.d.ts.map +1 -0
  106. package/dist/providers/learnworlds/interfaces/course.types.js +2 -0
  107. package/dist/providers/learnworlds/interfaces/course.types.js.map +1 -0
  108. package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts +165 -0
  109. package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts.map +1 -0
  110. package/dist/providers/learnworlds/interfaces/enrollment.types.js +2 -0
  111. package/dist/providers/learnworlds/interfaces/enrollment.types.js.map +1 -0
  112. package/dist/providers/learnworlds/interfaces/index.d.ts +12 -0
  113. package/dist/providers/learnworlds/interfaces/index.d.ts.map +1 -0
  114. package/dist/providers/learnworlds/interfaces/index.js +13 -0
  115. package/dist/providers/learnworlds/interfaces/index.js.map +1 -0
  116. package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts +39 -0
  117. package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts.map +1 -0
  118. package/dist/providers/learnworlds/interfaces/onboarding.types.js +2 -0
  119. package/dist/providers/learnworlds/interfaces/onboarding.types.js.map +1 -0
  120. package/dist/providers/learnworlds/interfaces/quiz.types.d.ts +108 -0
  121. package/dist/providers/learnworlds/interfaces/quiz.types.d.ts.map +1 -0
  122. package/dist/providers/learnworlds/interfaces/quiz.types.js +2 -0
  123. package/dist/providers/learnworlds/interfaces/quiz.types.js.map +1 -0
  124. package/dist/providers/learnworlds/interfaces/sso.types.d.ts +18 -0
  125. package/dist/providers/learnworlds/interfaces/sso.types.d.ts.map +1 -0
  126. package/dist/providers/learnworlds/interfaces/sso.types.js +2 -0
  127. package/dist/providers/learnworlds/interfaces/sso.types.js.map +1 -0
  128. package/dist/providers/learnworlds/interfaces/sync.types.d.ts +44 -0
  129. package/dist/providers/learnworlds/interfaces/sync.types.d.ts.map +1 -0
  130. package/dist/providers/learnworlds/interfaces/sync.types.js +2 -0
  131. package/dist/providers/learnworlds/interfaces/sync.types.js.map +1 -0
  132. package/dist/providers/learnworlds/interfaces/tag.types.d.ts +17 -0
  133. package/dist/providers/learnworlds/interfaces/tag.types.d.ts.map +1 -0
  134. package/dist/providers/learnworlds/interfaces/tag.types.js +2 -0
  135. package/dist/providers/learnworlds/interfaces/tag.types.js.map +1 -0
  136. package/dist/providers/learnworlds/interfaces/user.types.d.ts +198 -0
  137. package/dist/providers/learnworlds/interfaces/user.types.d.ts.map +1 -0
  138. package/dist/providers/learnworlds/interfaces/user.types.js +2 -0
  139. package/dist/providers/learnworlds/interfaces/user.types.js.map +1 -0
  140. package/dist/providers/learnworlds/learnworlds-base.action.d.ts +111 -7
  141. package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
  142. package/dist/providers/learnworlds/learnworlds-base.action.js +293 -56
  143. package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
  144. package/package.json +8 -7
  145. package/src/__tests__/attach-tags.action.test.ts +137 -0
  146. package/src/__tests__/create-user.action.test.ts +311 -0
  147. package/src/__tests__/detach-tags.action.test.ts +136 -0
  148. package/src/__tests__/enroll-user.action.test.ts +283 -0
  149. package/src/__tests__/get-bulk-data.action.test.ts +649 -0
  150. package/src/__tests__/get-bundles.action.test.ts +215 -0
  151. package/src/__tests__/lms.test.ts +275 -184
  152. package/src/__tests__/onboard-learner.action.test.ts +455 -0
  153. package/src/__tests__/sso-login.action.test.ts +256 -0
  154. package/src/__tests__/update-user.action.test.ts +350 -0
  155. package/src/base/base-lms.action.ts +226 -163
  156. package/src/providers/learnworlds/actions/attach-tags.action.ts +90 -0
  157. package/src/providers/learnworlds/actions/create-user.action.ts +291 -235
  158. package/src/providers/learnworlds/actions/detach-tags.action.ts +90 -0
  159. package/src/providers/learnworlds/actions/enroll-user.action.ts +326 -220
  160. package/src/providers/learnworlds/actions/get-bulk-data.action.ts +438 -0
  161. package/src/providers/learnworlds/actions/get-bundles.action.ts +139 -0
  162. package/src/providers/learnworlds/actions/get-certificates.action.ts +499 -309
  163. package/src/providers/learnworlds/actions/get-course-analytics.action.ts +470 -337
  164. package/src/providers/learnworlds/actions/get-course-details.action.ts +395 -249
  165. package/src/providers/learnworlds/actions/get-courses.action.ts +508 -565
  166. package/src/providers/learnworlds/actions/get-quiz-results.action.ts +606 -381
  167. package/src/providers/learnworlds/actions/get-user-details.action.ts +335 -349
  168. package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +328 -228
  169. package/src/providers/learnworlds/actions/get-user-progress.action.ts +522 -571
  170. package/src/providers/learnworlds/actions/get-users.action.ts +231 -282
  171. package/src/providers/learnworlds/actions/index.ts +8 -1
  172. package/src/providers/learnworlds/actions/onboard-learner.action.ts +286 -0
  173. package/src/providers/learnworlds/actions/sso-login.action.ts +116 -0
  174. package/src/providers/learnworlds/actions/update-user-progress.action.ts +301 -263
  175. package/src/providers/learnworlds/actions/update-user.action.ts +181 -0
  176. package/src/providers/learnworlds/index.ts +4 -1
  177. package/src/providers/learnworlds/interfaces/bundle.types.ts +17 -0
  178. package/src/providers/learnworlds/interfaces/certificate.types.ts +69 -0
  179. package/src/providers/learnworlds/interfaces/common.types.ts +233 -0
  180. package/src/providers/learnworlds/interfaces/course.types.ts +411 -0
  181. package/src/providers/learnworlds/interfaces/enrollment.types.ts +176 -0
  182. package/src/providers/learnworlds/interfaces/index.ts +12 -0
  183. package/src/providers/learnworlds/interfaces/onboarding.types.ts +41 -0
  184. package/src/providers/learnworlds/interfaces/quiz.types.ts +118 -0
  185. package/src/providers/learnworlds/interfaces/sso.types.ts +19 -0
  186. package/src/providers/learnworlds/interfaces/sync.types.ts +46 -0
  187. package/src/providers/learnworlds/interfaces/tag.types.ts +18 -0
  188. package/src/providers/learnworlds/interfaces/user.types.ts +204 -0
  189. package/src/providers/learnworlds/learnworlds-base.action.ts +468 -210
  190. package/tsconfig.json +1 -1
  191. package/dist/__tests__/lms.test.d.ts +0 -2
  192. package/dist/__tests__/lms.test.d.ts.map +0 -1
  193. package/dist/__tests__/lms.test.js +0 -232
  194. package/dist/__tests__/lms.test.js.map +0 -1
@@ -2,319 +2,268 @@ 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
-
6
- /**
7
- * Interface for a LearnWorlds user
8
- */
9
- export interface LearnWorldsUser {
10
- id: string;
11
- email: string;
12
- username: string;
13
- firstName?: string;
14
- lastName?: string;
15
- fullName?: string;
16
- status: 'active' | 'inactive' | 'suspended';
17
- role: string;
18
- createdAt: Date;
19
- lastLoginAt?: Date;
20
- tags?: string[];
21
- customFields?: Record<string, any>;
22
- totalCourses?: number;
23
- completedCourses?: number;
24
- inProgressCourses?: number;
25
- totalTimeSpent?: number;
26
- avatarUrl?: string;
27
- bio?: string;
28
- location?: string;
29
- timezone?: string;
30
- }
5
+ import { UserInfo } from '@memberjunction/core';
6
+ import { GetUsersParams, GetUsersResult, UsersSummary, LearnWorldsUser, LWApiUser } from '../interfaces';
31
7
 
32
8
  /**
33
9
  * Action to retrieve users from LearnWorlds LMS
34
10
  */
35
11
  @RegisterClass(BaseAction, 'GetLearnWorldsUsersAction')
36
12
  export class GetLearnWorldsUsersAction extends LearnWorldsBaseAction {
37
-
38
- /**
39
- * Description of the action
40
- */
41
- public get Description(): string {
42
- return 'Retrieves users (students, instructors, admins) from LearnWorlds LMS with filtering and search options';
43
- }
13
+ /**
14
+ * Description of the action
15
+ */
16
+ public get Description(): string {
17
+ return 'Retrieves users (students, instructors, admins) from LearnWorlds LMS with filtering and search options';
18
+ }
44
19
 
45
- /**
46
- * Main execution method
47
- */
48
- protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
49
- try {
50
- const contextUser = params.ContextUser;
51
- if (!contextUser) {
52
- return {
53
- Success: false,
54
- ResultCode: 'ERROR',
55
- Message: 'Context user is required for LearnWorlds API calls'
56
- };
57
- }
20
+ /**
21
+ * Typed public method for direct (non-framework) callers.
22
+ * Throws on failure.
23
+ */
24
+ public async GetUsers(params: GetUsersParams, contextUser: UserInfo): Promise<GetUsersResult> {
25
+ this.SetCompanyContext(params.CompanyID);
58
26
 
59
- // Store params for base class methods
60
- this.params = params.Params;
27
+ // Build query parameters
28
+ const queryParams: Record<string, string | number | boolean> = {};
61
29
 
62
- // Build query parameters
63
- const queryParams: Record<string, any> = {};
64
-
65
- // Search filter
66
- const searchText = this.getParamValue(params.Params, 'SearchText');
67
- if (searchText) {
68
- queryParams.search = searchText;
69
- }
30
+ if (params.SearchText) {
31
+ queryParams.search = params.SearchText;
32
+ }
33
+ if (params.Role) {
34
+ queryParams.role = params.Role;
35
+ }
36
+ if (params.Status) {
37
+ queryParams.status = params.Status;
38
+ }
39
+ if (params.Tags) {
40
+ queryParams.tags = params.Tags;
41
+ }
42
+ if (params.CreatedAfter) {
43
+ queryParams.created_after = this.formatLearnWorldsDate(new Date(params.CreatedAfter));
44
+ }
45
+ if (params.CreatedBefore) {
46
+ queryParams.created_before = this.formatLearnWorldsDate(new Date(params.CreatedBefore));
47
+ }
70
48
 
71
- // Role filter
72
- const role = this.getParamValue(params.Params, 'Role');
73
- if (role) {
74
- queryParams.role = role;
75
- }
49
+ // Sorting
50
+ const sortBy = params.SortBy || 'created';
51
+ const sortOrder = params.SortOrder || 'desc';
52
+ queryParams.sort = `${sortOrder === 'asc' ? '' : '-'}${sortBy}`;
76
53
 
77
- // Status filter
78
- const status = this.getParamValue(params.Params, 'Status');
79
- if (status) {
80
- queryParams.status = status;
81
- }
54
+ // Include course stats
55
+ if (params.IncludeCourseStats) {
56
+ queryParams.include = 'course_stats';
57
+ }
82
58
 
83
- // Tag filter
84
- const tags = this.getParamValue(params.Params, 'Tags');
85
- if (tags) {
86
- queryParams.tags = tags;
87
- }
59
+ // Limit for pagination
60
+ const maxResults = params.MaxResults || 100;
61
+ queryParams.limit = Math.min(maxResults, 100); // LearnWorlds max is usually 100
88
62
 
89
- // Date filters
90
- const createdAfter = this.getParamValue(params.Params, 'CreatedAfter');
91
- if (createdAfter) {
92
- queryParams.created_after = this.formatLearnWorldsDate(new Date(createdAfter));
93
- }
63
+ // Make the API request
64
+ const users = await this.makeLearnWorldsPaginatedRequest<LWApiUser>('users', queryParams, contextUser);
94
65
 
95
- const createdBefore = this.getParamValue(params.Params, 'CreatedBefore');
96
- if (createdBefore) {
97
- queryParams.created_before = this.formatLearnWorldsDate(new Date(createdBefore));
98
- }
66
+ // Map to our interface
67
+ const mappedUsers: LearnWorldsUser[] = users.map((user) => this.mapLearnWorldsUser(user));
99
68
 
100
- // Sorting
101
- const sortBy = this.getParamValue(params.Params, 'SortBy') || 'created';
102
- const sortOrder = this.getParamValue(params.Params, 'SortOrder') || 'desc';
103
- queryParams.sort = `${sortOrder === 'asc' ? '' : '-'}${sortBy}`;
69
+ // Calculate summary
70
+ const summary = this.calculateUserSummary(mappedUsers);
104
71
 
105
- // Include course stats
106
- const includeCourseStats = this.getParamValue(params.Params, 'IncludeCourseStats');
107
- if (includeCourseStats) {
108
- queryParams.include = 'course_stats';
109
- }
72
+ return {
73
+ Users: mappedUsers,
74
+ TotalCount: mappedUsers.length,
75
+ Summary: summary,
76
+ };
77
+ }
110
78
 
111
- // Limit for pagination
112
- const maxResults = this.getParamValue(params.Params, 'MaxResults') || 100;
113
- queryParams.limit = Math.min(maxResults, 100); // LearnWorlds max is usually 100
79
+ /**
80
+ * Framework entry point -- delegates to the typed public method.
81
+ */
82
+ protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
83
+ const { Params, ContextUser } = params;
84
+ this.params = Params;
114
85
 
115
- // Make the API request
116
- const users = await this.makeLearnWorldsPaginatedRequest<any>(
117
- 'users',
118
- queryParams,
119
- contextUser
120
- );
86
+ try {
87
+ if (!ContextUser) {
88
+ return this.buildErrorResult('ERROR', 'Context user is required for LearnWorlds API calls', Params);
89
+ }
121
90
 
122
- // Map to our interface
123
- const mappedUsers: LearnWorldsUser[] = users.map(user => this.mapLearnWorldsUser(user));
91
+ const typedParams = this.extractGetUsersParams(Params);
92
+ const result = await this.GetUsers(typedParams, ContextUser);
124
93
 
125
- // Calculate summary
126
- const summary = this.calculateUserSummary(mappedUsers);
94
+ this.setOutputParam(Params, 'Users', result.Users);
95
+ this.setOutputParam(Params, 'TotalCount', result.TotalCount);
96
+ this.setOutputParam(Params, 'Summary', result.Summary);
127
97
 
128
- // Create output parameters
129
- if (!params.Params.find(p => p.Name === 'Users')) {
130
- params.Params.push({
131
- Name: 'Users',
132
- Type: 'Output',
133
- Value: mappedUsers
134
- });
135
- } else {
136
- params.Params.find(p => p.Name === 'Users')!.Value = mappedUsers;
137
- }
98
+ return this.buildSuccessResult(`Successfully retrieved ${result.TotalCount} users from LearnWorlds`, Params);
99
+ } catch (error) {
100
+ const msg = error instanceof Error ? error.message : 'Unknown error occurred';
101
+ return this.buildErrorResult('ERROR', msg, Params);
102
+ }
103
+ }
138
104
 
139
- if (!params.Params.find(p => p.Name === 'TotalCount')) {
140
- params.Params.push({
141
- Name: 'TotalCount',
142
- Type: 'Output',
143
- Value: mappedUsers.length
144
- });
145
- } else {
146
- params.Params.find(p => p.Name === 'TotalCount')!.Value = mappedUsers.length;
147
- }
105
+ /**
106
+ * Extract typed params from the generic ActionParam array
107
+ */
108
+ private extractGetUsersParams(params: ActionParam[]): GetUsersParams {
109
+ return {
110
+ CompanyID: this.getRequiredStringParam(params, 'CompanyID'),
111
+ SearchText: this.getOptionalStringParam(params, 'SearchText'),
112
+ Role: this.getOptionalStringParam(params, 'Role'),
113
+ Status: this.getOptionalStringParam(params, 'Status'),
114
+ Tags: this.getOptionalStringParam(params, 'Tags'),
115
+ CreatedAfter: this.getOptionalStringParam(params, 'CreatedAfter'),
116
+ CreatedBefore: this.getOptionalStringParam(params, 'CreatedBefore'),
117
+ SortBy: this.getOptionalStringParam(params, 'SortBy') || 'created',
118
+ SortOrder: (this.getOptionalStringParam(params, 'SortOrder') || 'desc') as 'asc' | 'desc',
119
+ IncludeCourseStats: this.getOptionalBooleanParam(params, 'IncludeCourseStats', false),
120
+ MaxResults: this.getOptionalNumberParam(params, 'MaxResults', LearnWorldsBaseAction.LW_MAX_PAGE_SIZE),
121
+ };
122
+ }
148
123
 
149
- if (!params.Params.find(p => p.Name === 'Summary')) {
150
- params.Params.push({
151
- Name: 'Summary',
152
- Type: 'Output',
153
- Value: summary
154
- });
155
- } else {
156
- params.Params.find(p => p.Name === 'Summary')!.Value = summary;
157
- }
124
+ /**
125
+ * Map a raw LearnWorlds API user to our typed interface
126
+ */
127
+ private mapLearnWorldsUser(lwUser: LWApiUser): LearnWorldsUser {
128
+ return {
129
+ id: lwUser.id || lwUser._id || '',
130
+ email: lwUser.email,
131
+ username: lwUser.username || lwUser.email,
132
+ firstName: lwUser.first_name,
133
+ lastName: lwUser.last_name,
134
+ fullName: lwUser.full_name || `${lwUser.first_name || ''} ${lwUser.last_name || ''}`.trim(),
135
+ status: this.mapUserStatus(lwUser.status || 'active'),
136
+ role: lwUser.role || 'student',
137
+ createdAt: this.parseLearnWorldsDate(lwUser.created || lwUser.created_at || ''),
138
+ lastLoginAt: lwUser.last_login ? this.parseLearnWorldsDate(lwUser.last_login) : undefined,
139
+ tags: lwUser.tags || [],
140
+ customFields: lwUser.custom_fields || {},
141
+ totalCourses: lwUser.course_stats?.total || 0,
142
+ completedCourses: lwUser.course_stats?.completed || 0,
143
+ inProgressCourses: lwUser.course_stats?.in_progress || 0,
144
+ totalTimeSpent: lwUser.course_stats?.total_time_spent || 0,
145
+ avatarUrl: lwUser.avatar_url,
146
+ bio: lwUser.bio,
147
+ location: lwUser.location,
148
+ timezone: lwUser.timezone,
149
+ };
150
+ }
158
151
 
159
- return {
160
- Success: true,
161
- ResultCode: 'SUCCESS',
162
- Message: `Successfully retrieved ${mappedUsers.length} users from LearnWorlds`
163
- };
152
+ /**
153
+ * Calculate summary statistics from the mapped user list
154
+ */
155
+ private calculateUserSummary(users: LearnWorldsUser[]): UsersSummary {
156
+ const usersByRole: Record<string, number> = {};
157
+ let totalTimeSpent = 0;
164
158
 
165
- } catch (error) {
166
- const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
167
- return {
168
- Success: false,
169
- ResultCode: 'ERROR',
170
- Message: errorMessage
171
- };
172
- }
173
- }
159
+ users.forEach((user) => {
160
+ usersByRole[user.role] = (usersByRole[user.role] || 0) + 1;
161
+ totalTimeSpent += user.totalTimeSpent || 0;
162
+ });
174
163
 
175
- /**
176
- * Map LearnWorlds user data to our interface
177
- */
178
- private mapLearnWorldsUser(lwUser: any): LearnWorldsUser {
179
- return {
180
- id: lwUser.id || lwUser._id,
181
- email: lwUser.email,
182
- username: lwUser.username || lwUser.email,
183
- firstName: lwUser.first_name,
184
- lastName: lwUser.last_name,
185
- fullName: lwUser.full_name || `${lwUser.first_name || ''} ${lwUser.last_name || ''}`.trim(),
186
- status: this.mapUserStatus(lwUser.status || 'active'),
187
- role: lwUser.role || 'student',
188
- createdAt: this.parseLearnWorldsDate(lwUser.created || lwUser.created_at),
189
- lastLoginAt: lwUser.last_login ? this.parseLearnWorldsDate(lwUser.last_login) : undefined,
190
- tags: lwUser.tags || [],
191
- customFields: lwUser.custom_fields || {},
192
- totalCourses: lwUser.course_stats?.total || 0,
193
- completedCourses: lwUser.course_stats?.completed || 0,
194
- inProgressCourses: lwUser.course_stats?.in_progress || 0,
195
- totalTimeSpent: lwUser.course_stats?.total_time_spent || 0,
196
- avatarUrl: lwUser.avatar_url,
197
- bio: lwUser.bio,
198
- location: lwUser.location,
199
- timezone: lwUser.timezone
200
- };
164
+ let averageCoursesPerUser = 0;
165
+ if (users.length > 0) {
166
+ const totalCourses = users.reduce((sum, u) => sum + (u.totalCourses || 0), 0);
167
+ averageCoursesPerUser = totalCourses / users.length;
201
168
  }
202
169
 
203
- /**
204
- * Calculate summary statistics
205
- */
206
- private calculateUserSummary(users: LearnWorldsUser[]): any {
207
- const summary = {
208
- totalUsers: users.length,
209
- activeUsers: users.filter(u => u.status === 'active').length,
210
- inactiveUsers: users.filter(u => u.status === 'inactive').length,
211
- suspendedUsers: users.filter(u => u.status === 'suspended').length,
212
- usersByRole: {} as Record<string, number>,
213
- averageCoursesPerUser: 0,
214
- totalTimeSpent: 0,
215
- mostActiveUsers: [] as any[],
216
- recentSignups: [] as any[]
217
- };
170
+ // Find most active users (by completed courses)
171
+ const mostActiveUsers: Array<{ id: string; name: string; completedCourses?: number }> = users
172
+ .filter((u) => u.completedCourses && u.completedCourses > 0)
173
+ .sort((a, b) => (b.completedCourses || 0) - (a.completedCourses || 0))
174
+ .slice(0, 5)
175
+ .map((u) => ({
176
+ id: u.id,
177
+ name: u.fullName || u.email,
178
+ completedCourses: u.completedCourses,
179
+ }));
218
180
 
219
- // Count by role
220
- users.forEach(user => {
221
- summary.usersByRole[user.role] = (summary.usersByRole[user.role] || 0) + 1;
222
- summary.totalTimeSpent += user.totalTimeSpent || 0;
223
- });
181
+ // Find recent signups (last 30 days)
182
+ const thirtyDaysAgo = new Date();
183
+ thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
224
184
 
225
- // Calculate averages
226
- if (users.length > 0) {
227
- const totalCourses = users.reduce((sum, u) => sum + (u.totalCourses || 0), 0);
228
- summary.averageCoursesPerUser = totalCourses / users.length;
229
- }
185
+ const recentSignups: Array<{ id: string; name: string; signupDate: Date }> = users
186
+ .filter((u) => u.createdAt > thirtyDaysAgo)
187
+ .sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
188
+ .slice(0, 10)
189
+ .map((u) => ({
190
+ id: u.id,
191
+ name: u.fullName || u.email,
192
+ signupDate: u.createdAt,
193
+ }));
230
194
 
231
- // Find most active users (by completed courses)
232
- summary.mostActiveUsers = users
233
- .filter(u => u.completedCourses && u.completedCourses > 0)
234
- .sort((a, b) => (b.completedCourses || 0) - (a.completedCourses || 0))
235
- .slice(0, 5)
236
- .map(u => ({
237
- id: u.id,
238
- name: u.fullName || u.email,
239
- completedCourses: u.completedCourses
240
- }));
195
+ return {
196
+ totalUsers: users.length,
197
+ activeUsers: users.filter((u) => u.status === 'active').length,
198
+ inactiveUsers: users.filter((u) => u.status === 'inactive').length,
199
+ suspendedUsers: users.filter((u) => u.status === 'suspended').length,
200
+ usersByRole,
201
+ averageCoursesPerUser,
202
+ totalTimeSpent,
203
+ mostActiveUsers,
204
+ recentSignups,
205
+ };
206
+ }
241
207
 
242
- // Find recent signups (last 30 days)
243
- const thirtyDaysAgo = new Date();
244
- thirtyDaysAgo.setDate(thirtyDaysAgo.getDate() - 30);
245
-
246
- summary.recentSignups = users
247
- .filter(u => u.createdAt > thirtyDaysAgo)
248
- .sort((a, b) => b.createdAt.getTime() - a.createdAt.getTime())
249
- .slice(0, 10)
250
- .map(u => ({
251
- id: u.id,
252
- name: u.fullName || u.email,
253
- signupDate: u.createdAt
254
- }));
208
+ /**
209
+ * Define the parameters for this action
210
+ */
211
+ public get Params(): ActionParam[] {
212
+ const baseParams = this.getCommonLMSParams();
255
213
 
256
- return summary;
257
- }
258
-
259
- /**
260
- * Define the parameters for this action
261
- */
262
- public get Params(): ActionParam[] {
263
- const baseParams = this.getCommonLMSParams();
264
-
265
- const specificParams: ActionParam[] = [
266
- {
267
- Name: 'SearchText',
268
- Type: 'Input',
269
- Value: null
270
- },
271
- {
272
- Name: 'Role',
273
- Type: 'Input',
274
- Value: null
275
- },
276
- {
277
- Name: 'Status',
278
- Type: 'Input',
279
- Value: null
280
- },
281
- {
282
- Name: 'Tags',
283
- Type: 'Input',
284
- Value: null
285
- },
286
- {
287
- Name: 'CreatedAfter',
288
- Type: 'Input',
289
- Value: null
290
- },
291
- {
292
- Name: 'CreatedBefore',
293
- Type: 'Input',
294
- Value: null
295
- },
296
- {
297
- Name: 'SortBy',
298
- Type: 'Input',
299
- Value: 'created'
300
- },
301
- {
302
- Name: 'SortOrder',
303
- Type: 'Input',
304
- Value: 'desc'
305
- },
306
- {
307
- Name: 'IncludeCourseStats',
308
- Type: 'Input',
309
- Value: true
310
- },
311
- {
312
- Name: 'MaxResults',
313
- Type: 'Input',
314
- Value: 100
315
- }
316
- ];
214
+ const specificParams: ActionParam[] = [
215
+ {
216
+ Name: 'SearchText',
217
+ Type: 'Input',
218
+ Value: null,
219
+ },
220
+ {
221
+ Name: 'Role',
222
+ Type: 'Input',
223
+ Value: null,
224
+ },
225
+ {
226
+ Name: 'Status',
227
+ Type: 'Input',
228
+ Value: null,
229
+ },
230
+ {
231
+ Name: 'Tags',
232
+ Type: 'Input',
233
+ Value: null,
234
+ },
235
+ {
236
+ Name: 'CreatedAfter',
237
+ Type: 'Input',
238
+ Value: null,
239
+ },
240
+ {
241
+ Name: 'CreatedBefore',
242
+ Type: 'Input',
243
+ Value: null,
244
+ },
245
+ {
246
+ Name: 'SortBy',
247
+ Type: 'Input',
248
+ Value: 'created',
249
+ },
250
+ {
251
+ Name: 'SortOrder',
252
+ Type: 'Input',
253
+ Value: 'desc',
254
+ },
255
+ {
256
+ Name: 'IncludeCourseStats',
257
+ Type: 'Input',
258
+ Value: true,
259
+ },
260
+ {
261
+ Name: 'MaxResults',
262
+ Type: 'Input',
263
+ Value: 100,
264
+ },
265
+ ];
317
266
 
318
- return [...baseParams, ...specificParams];
319
- }
320
- }
267
+ return [...baseParams, ...specificParams];
268
+ }
269
+ }
@@ -10,4 +10,11 @@ export * from './get-course-analytics.action';
10
10
  export * from './create-user.action';
11
11
  export * from './update-user-progress.action';
12
12
  export * from './get-certificates.action';
13
- export * from './get-quiz-results.action';
13
+ export * from './get-quiz-results.action';
14
+ export * from './sso-login.action';
15
+ export * from './update-user.action';
16
+ export * from './attach-tags.action';
17
+ export * from './detach-tags.action';
18
+ export * from './get-bundles.action';
19
+ export * from './onboard-learner.action';
20
+ export * from './get-bulk-data.action';