@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
|
@@ -3,6 +3,8 @@ import { BaseLMSAction } from '../../base/base-lms.action';
|
|
|
3
3
|
import { UserInfo } from '@memberjunction/core';
|
|
4
4
|
import { MJCompanyIntegrationEntity } from '@memberjunction/core-entities';
|
|
5
5
|
import { BaseAction } from '@memberjunction/actions';
|
|
6
|
+
import { ActionParam } from '@memberjunction/actions-base';
|
|
7
|
+
import { LWApiEnrollmentStatus, LWApiProgressData, LWApiUser, LearnWorldsUser, LearnWorldsPaginatedResponse } from './interfaces';
|
|
6
8
|
|
|
7
9
|
/**
|
|
8
10
|
* Base class for all LearnWorlds LMS actions.
|
|
@@ -10,213 +12,469 @@ import { BaseAction } from '@memberjunction/actions';
|
|
|
10
12
|
*/
|
|
11
13
|
@RegisterClass(BaseAction, 'LearnWorldsBaseAction')
|
|
12
14
|
export abstract class LearnWorldsBaseAction extends BaseLMSAction {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
221
|
-
|
|
222
|
-
|
|
15
|
+
protected lmsProvider = 'LearnWorlds';
|
|
16
|
+
protected integrationName = 'LearnWorlds';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* LearnWorlds API version
|
|
20
|
+
*/
|
|
21
|
+
protected apiVersion = 'v2';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Concurrency limit for parallel API calls to avoid overwhelming the API.
|
|
25
|
+
*/
|
|
26
|
+
protected static readonly CONCURRENCY_LIMIT = 5;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Allowed user roles in LearnWorlds.
|
|
30
|
+
*/
|
|
31
|
+
protected static readonly ALLOWED_ROLES: readonly string[] = ['student', 'observer', 'instructor'] as const;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Maximum number of items per page supported by the LearnWorlds API
|
|
35
|
+
*/
|
|
36
|
+
protected static readonly LW_MAX_PAGE_SIZE = 100;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Current action parameters (set by the framework or by SetCompanyContext)
|
|
40
|
+
*/
|
|
41
|
+
protected params: ActionParam[] = [];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Tracks the number of actual HTTP requests made since last reset.
|
|
45
|
+
* Useful for callers that need accurate API call counts (e.g., bulk data).
|
|
46
|
+
*/
|
|
47
|
+
protected apiCallCount = 0;
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Public accessor for the running API call count.
|
|
51
|
+
*/
|
|
52
|
+
public get ApiCallCount(): number {
|
|
53
|
+
return this.apiCallCount;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Set the company context for direct (non-framework) calls.
|
|
58
|
+
* This populates `this.params` so that `makeLearnWorldsRequest` can find the CompanyID.
|
|
59
|
+
*/
|
|
60
|
+
public SetCompanyContext(companyId: string): void {
|
|
61
|
+
this.params = [{ Name: 'CompanyID', Type: 'Input', Value: companyId }];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Makes an authenticated request to LearnWorlds API.
|
|
66
|
+
* The body parameter accepts any object that will be JSON-serialized.
|
|
67
|
+
*/
|
|
68
|
+
protected async makeLearnWorldsRequest<T = Record<string, unknown>>(
|
|
69
|
+
endpoint: string,
|
|
70
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET',
|
|
71
|
+
body?: object | null,
|
|
72
|
+
contextUser?: UserInfo,
|
|
73
|
+
): Promise<T> {
|
|
74
|
+
if (!contextUser) {
|
|
75
|
+
throw new Error('Context user is required for LearnWorlds API calls');
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const { fullUrl, headers } = await this.buildRequestConfig(contextUser);
|
|
79
|
+
const requestUrl = `${fullUrl}/${endpoint}`;
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
this.apiCallCount++;
|
|
83
|
+
const response = await fetch(requestUrl, {
|
|
84
|
+
method,
|
|
85
|
+
headers,
|
|
86
|
+
body: body ? JSON.stringify(body) : undefined,
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
if (!response.ok) {
|
|
90
|
+
throw new Error(await this.buildErrorMessage(response));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (await response.json()) as T;
|
|
94
|
+
} catch (error) {
|
|
95
|
+
if (error instanceof Error) {
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
throw new Error(`LearnWorlds API request failed: ${error}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Resolves integration credentials and builds the base URL and headers.
|
|
104
|
+
*/
|
|
105
|
+
private async buildRequestConfig(contextUser: UserInfo): Promise<{ fullUrl: string; headers: Record<string, string> }> {
|
|
106
|
+
const companyId = this.getParamValue(this.params, 'CompanyID') as string | undefined;
|
|
107
|
+
if (!companyId) {
|
|
108
|
+
throw new Error('CompanyID parameter is required');
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const integration = await this.getCompanyIntegration(companyId, contextUser);
|
|
112
|
+
const credentials = await this.getAPICredentials(integration);
|
|
113
|
+
|
|
114
|
+
if (!credentials.apiKey) {
|
|
115
|
+
throw new Error('API Key is required for LearnWorlds integration');
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const schoolDomain = integration.ExternalSystemID || this.getCredentialFromEnv(companyId, 'SCHOOL_DOMAIN');
|
|
119
|
+
if (!schoolDomain) {
|
|
120
|
+
throw new Error('School domain not found. Set in CompanyIntegration.ExternalSystemID or environment variable');
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
this.validateSchoolDomain(schoolDomain);
|
|
124
|
+
|
|
125
|
+
return {
|
|
126
|
+
fullUrl: `https://${schoolDomain}/api/${this.apiVersion}`,
|
|
127
|
+
headers: {
|
|
128
|
+
Authorization: `Bearer ${credentials.apiKey}`,
|
|
129
|
+
Accept: 'application/json',
|
|
130
|
+
'Content-Type': 'application/json',
|
|
131
|
+
'Lw-Client': 'MemberJunction',
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Parses error details from a non-OK API response.
|
|
138
|
+
*/
|
|
139
|
+
private async buildErrorMessage(response: Response): Promise<string> {
|
|
140
|
+
const errorText = await response.text();
|
|
141
|
+
let errorMessage = `LearnWorlds API error: ${response.status} ${response.statusText}`;
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
const errorJson = JSON.parse(errorText) as { error?: { message?: string }; message?: string };
|
|
145
|
+
if (errorJson.error) {
|
|
146
|
+
errorMessage = `LearnWorlds API error: ${errorJson.error.message || String(errorJson.error)}`;
|
|
147
|
+
} else if (errorJson.message) {
|
|
148
|
+
errorMessage = `LearnWorlds API error: ${errorJson.message}`;
|
|
149
|
+
}
|
|
150
|
+
} catch {
|
|
151
|
+
errorMessage += ` - ${errorText}`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
return errorMessage;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Makes a paginated request to LearnWorlds API
|
|
159
|
+
*/
|
|
160
|
+
protected async makeLearnWorldsPaginatedRequest<T = Record<string, unknown>>(
|
|
161
|
+
endpoint: string,
|
|
162
|
+
queryParams: Record<string, string | number | boolean> = {},
|
|
163
|
+
contextUser?: UserInfo,
|
|
164
|
+
): Promise<T[]> {
|
|
165
|
+
const results: T[] = [];
|
|
166
|
+
let page = 1;
|
|
167
|
+
let hasMore = true;
|
|
168
|
+
const limit = (queryParams.limit as number) || LearnWorldsBaseAction.LW_MAX_PAGE_SIZE;
|
|
169
|
+
|
|
170
|
+
while (hasMore) {
|
|
171
|
+
const paginatedParams: Record<string, string> = {};
|
|
172
|
+
for (const [key, val] of Object.entries(queryParams)) {
|
|
173
|
+
paginatedParams[key] = String(val);
|
|
174
|
+
}
|
|
175
|
+
paginatedParams.page = page.toString();
|
|
176
|
+
paginatedParams.limit = limit.toString();
|
|
177
|
+
|
|
178
|
+
const qs = new URLSearchParams(paginatedParams);
|
|
179
|
+
|
|
180
|
+
const response = await this.makeLearnWorldsRequest<LearnWorldsPaginatedResponse<T>>(`${endpoint}?${qs}`, 'GET', undefined, contextUser);
|
|
181
|
+
|
|
182
|
+
if (response.data && Array.isArray(response.data)) {
|
|
183
|
+
results.push(...response.data);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Check if there are more pages
|
|
187
|
+
if (response.meta && response.meta.page < response.meta.totalPages) {
|
|
188
|
+
page++;
|
|
189
|
+
} else {
|
|
190
|
+
hasMore = false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// Respect max results if specified
|
|
194
|
+
const maxResults = this.getParamValue(this.params, 'MaxResults') as number | undefined;
|
|
195
|
+
if (maxResults && results.length >= maxResults) {
|
|
196
|
+
return results.slice(0, maxResults);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return results;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Convert LearnWorlds date format to Date object
|
|
205
|
+
*/
|
|
206
|
+
protected parseLearnWorldsDate(dateString: string | number): Date {
|
|
207
|
+
// LearnWorlds sometimes returns timestamps as seconds since epoch
|
|
208
|
+
if (typeof dateString === 'number') {
|
|
209
|
+
return new Date(dateString * 1000);
|
|
210
|
+
}
|
|
211
|
+
return new Date(dateString);
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Format date for LearnWorlds API (ISO 8601)
|
|
216
|
+
*/
|
|
217
|
+
protected formatLearnWorldsDate(date: Date): string {
|
|
218
|
+
return date.toISOString();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Map LearnWorlds user status to standard status
|
|
223
|
+
*/
|
|
224
|
+
protected mapUserStatus(status: string): 'active' | 'inactive' | 'suspended' {
|
|
225
|
+
const statusMap: Record<string, 'active' | 'inactive' | 'suspended'> = {
|
|
226
|
+
active: 'active',
|
|
227
|
+
inactive: 'inactive',
|
|
228
|
+
suspended: 'suspended',
|
|
229
|
+
blocked: 'suspended',
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
return statusMap[status.toLowerCase()] || 'inactive';
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Map LearnWorlds enrollment status
|
|
237
|
+
*/
|
|
238
|
+
protected mapLearnWorldsEnrollmentStatus(enrollment: LWApiEnrollmentStatus): 'active' | 'completed' | 'expired' | 'suspended' {
|
|
239
|
+
if (enrollment.completed) {
|
|
240
|
+
return 'completed';
|
|
241
|
+
}
|
|
242
|
+
if (enrollment.expired) {
|
|
243
|
+
return 'expired';
|
|
244
|
+
}
|
|
245
|
+
if (enrollment.suspended || !enrollment.active) {
|
|
246
|
+
return 'suspended';
|
|
247
|
+
}
|
|
248
|
+
return 'active';
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Calculate progress from LearnWorlds data
|
|
253
|
+
*/
|
|
254
|
+
protected calculateProgress(progressData: LWApiProgressData): {
|
|
255
|
+
percentage: number;
|
|
256
|
+
completedUnits: number;
|
|
257
|
+
totalUnits: number;
|
|
258
|
+
timeSpent: number;
|
|
259
|
+
} {
|
|
260
|
+
return {
|
|
261
|
+
percentage: progressData.percentage || 0,
|
|
262
|
+
completedUnits: progressData.completed_units || 0,
|
|
263
|
+
totalUnits: progressData.total_units || 0,
|
|
264
|
+
timeSpent: progressData.time_spent || 0,
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Safely parses a date string to ISO format.
|
|
270
|
+
* Returns undefined if the input is falsy or produces an invalid date.
|
|
271
|
+
*/
|
|
272
|
+
protected safeParseDateToISO(dateString: string | undefined): string | undefined {
|
|
273
|
+
if (!dateString) return undefined;
|
|
274
|
+
const parsed = new Date(dateString);
|
|
275
|
+
if (isNaN(parsed.getTime())) {
|
|
276
|
+
console.warn(`Invalid date string "${dateString}" — skipping date filter`);
|
|
277
|
+
return undefined;
|
|
278
|
+
}
|
|
279
|
+
return parsed.toISOString();
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
// ----------------------------------------------------------------
|
|
283
|
+
// Validation helpers
|
|
284
|
+
// ----------------------------------------------------------------
|
|
285
|
+
|
|
286
|
+
/**
|
|
287
|
+
* Validates that a value is safe to use as a URL path segment.
|
|
288
|
+
* Rejects values containing path traversal or URL manipulation characters.
|
|
289
|
+
*/
|
|
290
|
+
protected validatePathSegment(value: string, paramName: string): string {
|
|
291
|
+
if (value.length === 0) {
|
|
292
|
+
throw new Error(`${paramName} must not be empty`);
|
|
293
|
+
}
|
|
294
|
+
if (/[\/\\?#@%]|\.\./.test(value)) {
|
|
295
|
+
throw new Error(`Invalid ${paramName}: contains forbidden characters`);
|
|
296
|
+
}
|
|
297
|
+
return value;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Validates that a school domain is safe to use in URL construction.
|
|
302
|
+
* Must look like a hostname (alphanumeric + hyphens + dots).
|
|
303
|
+
*/
|
|
304
|
+
private validateSchoolDomain(domain: string): string {
|
|
305
|
+
if (/[\/\\?#@\s]/.test(domain)) {
|
|
306
|
+
throw new Error('Invalid school domain: contains URL-unsafe characters');
|
|
307
|
+
}
|
|
308
|
+
if (!/^[a-zA-Z0-9]([a-zA-Z0-9.-]*[a-zA-Z0-9])?$/.test(domain)) {
|
|
309
|
+
throw new Error('Invalid school domain format');
|
|
310
|
+
}
|
|
311
|
+
return domain;
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Validates that a role is in the allowed set.
|
|
316
|
+
*/
|
|
317
|
+
protected validateRole(role: string): string {
|
|
318
|
+
const normalizedRole = role.toLowerCase();
|
|
319
|
+
if (!LearnWorldsBaseAction.ALLOWED_ROLES.includes(normalizedRole)) {
|
|
320
|
+
throw new Error(`Invalid role '${role}'. Allowed roles: ${LearnWorldsBaseAction.ALLOWED_ROLES.join(', ')}`);
|
|
321
|
+
}
|
|
322
|
+
return normalizedRole;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/**
|
|
326
|
+
* Validates that a string is a plausible email address.
|
|
327
|
+
*/
|
|
328
|
+
protected validateEmail(email: string, paramName: string = 'Email'): string {
|
|
329
|
+
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
330
|
+
if (!emailRegex.test(email)) {
|
|
331
|
+
throw new Error(`Invalid ${paramName} format: '${email}'`);
|
|
332
|
+
}
|
|
333
|
+
return email;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Validates that a redirect URL is either a relative path or an absolute URL
|
|
338
|
+
* that belongs to the LearnWorlds school domain and uses http(s).
|
|
339
|
+
*/
|
|
340
|
+
protected validateRedirectTo(redirectTo: string, schoolDomain?: string): string {
|
|
341
|
+
// Allow relative paths
|
|
342
|
+
if (redirectTo.startsWith('/')) {
|
|
343
|
+
return redirectTo;
|
|
344
|
+
}
|
|
345
|
+
// If absolute URL, parse and check against school domain
|
|
346
|
+
let url: URL;
|
|
347
|
+
try {
|
|
348
|
+
url = new URL(redirectTo);
|
|
349
|
+
} catch {
|
|
350
|
+
throw new Error('RedirectTo is not a valid URL or relative path');
|
|
351
|
+
}
|
|
352
|
+
// Block dangerous protocols
|
|
353
|
+
if (!['http:', 'https:'].includes(url.protocol)) {
|
|
354
|
+
throw new Error('RedirectTo must use http or https protocol');
|
|
355
|
+
}
|
|
356
|
+
if (schoolDomain && !url.hostname.endsWith('.learnworlds.com') && url.hostname !== schoolDomain) {
|
|
357
|
+
throw new Error('RedirectTo must be a relative path or a LearnWorlds domain URL');
|
|
358
|
+
}
|
|
359
|
+
return redirectTo;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// ----------------------------------------------------------------
|
|
363
|
+
// Batch concurrency helper
|
|
364
|
+
// ----------------------------------------------------------------
|
|
365
|
+
|
|
366
|
+
/**
|
|
367
|
+
* Processes items in batches with controlled concurrency.
|
|
368
|
+
* Prevents unbounded parallel API calls from overwhelming the target API.
|
|
369
|
+
*/
|
|
370
|
+
protected async processInBatches<TItem, TResult>(
|
|
371
|
+
items: TItem[],
|
|
372
|
+
processFn: (item: TItem) => Promise<TResult>,
|
|
373
|
+
batchSize: number = LearnWorldsBaseAction.CONCURRENCY_LIMIT,
|
|
374
|
+
): Promise<TResult[]> {
|
|
375
|
+
const results: TResult[] = [];
|
|
376
|
+
for (let i = 0; i < items.length; i += batchSize) {
|
|
377
|
+
const batch = items.slice(i, i + batchSize);
|
|
378
|
+
const batchResults = await Promise.all(batch.map(processFn));
|
|
379
|
+
results.push(...batchResults);
|
|
380
|
+
}
|
|
381
|
+
return results;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
// ----------------------------------------------------------------
|
|
385
|
+
// Parameter extraction helpers
|
|
386
|
+
// ----------------------------------------------------------------
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Gets a required string parameter, throwing if missing or empty.
|
|
390
|
+
*/
|
|
391
|
+
protected getRequiredStringParam(params: ActionParam[], name: string): string {
|
|
392
|
+
const value = this.getParamValue(params, name);
|
|
393
|
+
if (typeof value !== 'string' || !value) {
|
|
394
|
+
throw new Error(`Required string parameter '${name}' is missing or invalid`);
|
|
395
|
+
}
|
|
396
|
+
return value;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/**
|
|
400
|
+
* Gets an optional string parameter.
|
|
401
|
+
*/
|
|
402
|
+
protected getOptionalStringParam(params: ActionParam[], name: string): string | undefined {
|
|
403
|
+
const value = this.getParamValue(params, name);
|
|
404
|
+
if (value === undefined || value === null) return undefined;
|
|
405
|
+
return typeof value === 'string' ? value : String(value);
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Gets an optional boolean parameter with a default value.
|
|
410
|
+
* When defaultValue is undefined, returns undefined if the parameter is missing.
|
|
411
|
+
*/
|
|
412
|
+
protected getOptionalBooleanParam(params: ActionParam[], name: string, defaultValue: boolean): boolean;
|
|
413
|
+
protected getOptionalBooleanParam(params: ActionParam[], name: string, defaultValue: boolean | undefined): boolean | undefined;
|
|
414
|
+
protected getOptionalBooleanParam(params: ActionParam[], name: string, defaultValue: boolean | undefined): boolean | undefined {
|
|
415
|
+
const value = this.getParamValue(params, name);
|
|
416
|
+
if (value === undefined || value === null) return defaultValue;
|
|
417
|
+
if (typeof value === 'boolean') return value;
|
|
418
|
+
const strVal = String(value).toLowerCase();
|
|
419
|
+
if (strVal === 'true' || strVal === '1') return true;
|
|
420
|
+
if (strVal === 'false' || strVal === '0') return false;
|
|
421
|
+
return defaultValue;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Gets an optional number parameter with a default value.
|
|
426
|
+
* When defaultValue is undefined, returns undefined if the parameter is missing.
|
|
427
|
+
*/
|
|
428
|
+
protected getOptionalNumberParam(params: ActionParam[], name: string, defaultValue: number): number;
|
|
429
|
+
protected getOptionalNumberParam(params: ActionParam[], name: string, defaultValue: number | undefined): number | undefined;
|
|
430
|
+
protected getOptionalNumberParam(params: ActionParam[], name: string, defaultValue: number | undefined): number | undefined {
|
|
431
|
+
const value = this.getParamValue(params, name);
|
|
432
|
+
if (value === undefined || value === null) return defaultValue;
|
|
433
|
+
const parsed = Number(value);
|
|
434
|
+
return isNaN(parsed) ? defaultValue : parsed;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Gets an optional string array parameter.
|
|
439
|
+
*/
|
|
440
|
+
protected getOptionalStringArrayParam(params: ActionParam[], name: string): string[] | undefined {
|
|
441
|
+
const value = this.getParamValue(params, name);
|
|
442
|
+
if (value === undefined || value === null) return undefined;
|
|
443
|
+
if (Array.isArray(value)) return value.map(String);
|
|
444
|
+
return undefined;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* Shared utility: find a LearnWorlds user by email.
|
|
449
|
+
* Returns the user if found, null if not found (empty results).
|
|
450
|
+
* Re-throws errors for network failures, auth errors, rate limiting, etc.
|
|
451
|
+
*/
|
|
452
|
+
public async FindUserByEmail(email: string, contextUser: UserInfo): Promise<LearnWorldsUser | null> {
|
|
453
|
+
const response = await this.makeLearnWorldsPaginatedRequest<LWApiUser>('users', { search: email, limit: 5 }, contextUser);
|
|
454
|
+
|
|
455
|
+
const match = response.find((u) => u.email.toLowerCase() === email.toLowerCase());
|
|
456
|
+
if (!match) return null;
|
|
457
|
+
|
|
458
|
+
return this.mapLWApiUserToLearnWorldsUser(match);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Maps a raw LW API user to the normalized LearnWorldsUser shape.
|
|
463
|
+
*/
|
|
464
|
+
private mapLWApiUserToLearnWorldsUser(user: LWApiUser): LearnWorldsUser {
|
|
465
|
+
return {
|
|
466
|
+
id: user.id || user._id || '',
|
|
467
|
+
email: user.email,
|
|
468
|
+
username: user.username || user.email,
|
|
469
|
+
firstName: user.first_name,
|
|
470
|
+
lastName: user.last_name,
|
|
471
|
+
fullName: user.full_name || `${user.first_name || ''} ${user.last_name || ''}`.trim(),
|
|
472
|
+
status: this.mapUserStatus(user.status || 'active'),
|
|
473
|
+
role: user.role || 'student',
|
|
474
|
+
createdAt: this.parseLearnWorldsDate(user.created || user.created_at || ''),
|
|
475
|
+
lastLoginAt: user.last_login ? this.parseLearnWorldsDate(user.last_login) : undefined,
|
|
476
|
+
tags: user.tags || [],
|
|
477
|
+
customFields: user.custom_fields || {},
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
}
|