@memberjunction/actions-bizapps-lms 5.7.0 → 5.9.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 (49) hide show
  1. package/.env.integration.example +28 -0
  2. package/.turbo/turbo-build.log +1 -1
  3. package/CHANGELOG.md +24 -0
  4. package/dist/base/base-lms.action.d.ts.map +1 -1
  5. package/dist/base/base-lms.action.js +10 -3
  6. package/dist/base/base-lms.action.js.map +1 -1
  7. package/dist/providers/learnworlds/actions/attach-tags.action.js +1 -1
  8. package/dist/providers/learnworlds/actions/attach-tags.action.js.map +1 -1
  9. package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
  10. package/dist/providers/learnworlds/actions/create-user.action.js +6 -5
  11. package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
  12. package/dist/providers/learnworlds/actions/detach-tags.action.js +1 -1
  13. package/dist/providers/learnworlds/actions/detach-tags.action.js.map +1 -1
  14. package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +1 -1
  15. package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -1
  16. package/dist/providers/learnworlds/actions/enroll-user.action.js +11 -34
  17. package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -1
  18. package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -1
  19. package/dist/providers/learnworlds/actions/get-course-details.action.js +50 -34
  20. package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
  21. package/dist/providers/learnworlds/actions/get-user-details.action.js +1 -1
  22. package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
  23. package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +1 -1
  24. package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -1
  25. package/dist/providers/learnworlds/actions/get-users.action.js +1 -1
  26. package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
  27. package/dist/providers/learnworlds/actions/sso-login.action.js +1 -1
  28. package/dist/providers/learnworlds/actions/sso-login.action.js.map +1 -1
  29. package/dist/providers/learnworlds/learnworlds-base.action.d.ts +5 -1
  30. package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
  31. package/dist/providers/learnworlds/learnworlds-base.action.js +42 -9
  32. package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
  33. package/package.json +10 -8
  34. package/src/__tests__/create-user.action.test.ts +12 -1
  35. package/src/__tests__/enroll-user.action.test.ts +7 -7
  36. package/src/__tests__/integration.test.ts +510 -0
  37. package/src/__tests__/lms.test.ts +17 -3
  38. package/src/__tests__/sso-login.action.test.ts +7 -7
  39. package/src/base/base-lms.action.ts +9 -3
  40. package/src/providers/learnworlds/actions/attach-tags.action.ts +1 -1
  41. package/src/providers/learnworlds/actions/create-user.action.ts +6 -4
  42. package/src/providers/learnworlds/actions/detach-tags.action.ts +1 -1
  43. package/src/providers/learnworlds/actions/enroll-user.action.ts +9 -39
  44. package/src/providers/learnworlds/actions/get-course-details.action.ts +63 -51
  45. package/src/providers/learnworlds/actions/get-user-details.action.ts +1 -1
  46. package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +1 -1
  47. package/src/providers/learnworlds/actions/get-users.action.ts +1 -1
  48. package/src/providers/learnworlds/actions/sso-login.action.ts +1 -1
  49. package/src/providers/learnworlds/learnworlds-base.action.ts +55 -10
@@ -60,7 +60,7 @@ export class CreateUserAction extends LearnWorldsBaseAction {
60
60
  };
61
61
 
62
62
  // Add optional fields
63
- if (params.Username) userData.username = params.Username;
63
+ userData.username = params.Username || email;
64
64
  if (params.Password) userData.password = params.Password;
65
65
  if (params.FirstName) userData.first_name = params.FirstName;
66
66
  if (params.LastName) userData.last_name = params.LastName;
@@ -175,12 +175,14 @@ export class CreateUserAction extends LearnWorldsBaseAction {
175
175
  this.validatePathSegment(courseId, 'CourseID');
176
176
 
177
177
  const enrollBody: Record<string, unknown> = {
178
- user_id: userId,
178
+ productId: courseId,
179
+ productType: 'course',
179
180
  justification: 'Enrolled during user creation',
180
- notify_user: false,
181
+ price: 0,
182
+ send_enrollment_email: false,
181
183
  };
182
184
 
183
- const enrollData = await this.makeLearnWorldsRequest<LWEnrollmentResponse>(`courses/${courseId}/enrollments`, 'POST', enrollBody, contextUser);
185
+ const enrollData = await this.makeLearnWorldsRequest<LWEnrollmentResponse>(`users/${userId}/enrollment`, 'POST', enrollBody, contextUser);
184
186
 
185
187
  enrollmentResults.push({
186
188
  courseId: courseId,
@@ -32,7 +32,7 @@ export class DetachTagsAction extends LearnWorldsBaseAction {
32
32
 
33
33
  this.validatePathSegment(params.UserID, 'UserID');
34
34
 
35
- const response = await this.makeLearnWorldsRequest<LWApiTagResponse>(`users/${params.UserID}/tags`, 'DELETE', { tags: params.Tags }, contextUser);
35
+ const response = await this.makeLearnWorldsRequest<LWApiTagResponse>(`users/${params.UserID}/tags`, 'PUT', { tags: params.Tags, action: 'detach' }, contextUser);
36
36
 
37
37
  return {
38
38
  Success: true,
@@ -87,8 +87,6 @@ export class EnrollUserAction extends LearnWorldsBaseAction {
87
87
  price,
88
88
  justification,
89
89
  notifyUser,
90
- params.StartDate,
91
- params.ExpiryDate,
92
90
  );
93
91
 
94
92
  // Create enrollment
@@ -167,7 +165,7 @@ export class EnrollUserAction extends LearnWorldsBaseAction {
167
165
  }
168
166
 
169
167
  /**
170
- * Build the endpoint and body based on product type (course vs bundle).
168
+ * Build the endpoint and body for enrollment (unified endpoint per LW v2 API).
171
169
  */
172
170
  private buildEnrollmentRequest(
173
171
  userId: string,
@@ -176,44 +174,16 @@ export class EnrollUserAction extends LearnWorldsBaseAction {
176
174
  price: number,
177
175
  justification: string,
178
176
  notifyUser: boolean,
179
- startDate?: string,
180
- expiryDate?: string,
181
177
  ): { endpoint: string; enrollmentData: Record<string, unknown> } {
182
- if (productType === 'bundle') {
183
- // Bundles use the generic enrollments endpoint with product_type
184
- return {
185
- endpoint: 'enrollments',
186
- enrollmentData: {
187
- product_id: courseId,
188
- product_type: 'bundle',
189
- user_id: userId,
190
- price: price,
191
- justification: justification,
192
- notify_user: notifyUser,
193
- ...(startDate ? { starts_at: new Date(startDate).toISOString() } : {}),
194
- ...(expiryDate ? { expires_at: new Date(expiryDate).toISOString() } : {}),
195
- },
196
- };
197
- }
198
-
199
- // Courses use the per-course enrollment endpoint
200
- const enrollmentData: Record<string, unknown> = {
201
- user_id: userId,
202
- justification: justification,
203
- price: price,
204
- notify_user: notifyUser,
205
- };
206
-
207
- if (startDate) {
208
- enrollmentData.starts_at = new Date(startDate).toISOString();
209
- }
210
- if (expiryDate) {
211
- enrollmentData.expires_at = new Date(expiryDate).toISOString();
212
- }
213
-
214
178
  return {
215
- endpoint: `courses/${courseId}/enrollments`,
216
- enrollmentData,
179
+ endpoint: `users/${userId}/enrollment`,
180
+ enrollmentData: {
181
+ productId: courseId,
182
+ productType,
183
+ justification,
184
+ price,
185
+ send_enrollment_email: notifyUser,
186
+ },
217
187
  };
218
188
  }
219
189
 
@@ -15,23 +15,19 @@ import {
15
15
  } from '../interfaces';
16
16
 
17
17
  /**
18
- * Raw API shape for a course response from LearnWorlds
18
+ * Raw API shape returned by the LearnWorlds GET /v2/courses/{id} endpoint.
19
+ * The v2 API returns the course object directly (no wrapper).
19
20
  */
20
- interface LWApiCourseResponse {
21
- success?: boolean;
22
- data?: LWApiCourseData;
23
- message?: string;
24
- }
25
-
26
21
  interface LWApiCourseData {
27
22
  id: string;
28
23
  title: string;
29
24
  slug?: string;
30
- description?: string;
25
+ description?: string | null;
31
26
  short_description?: string;
32
- status?: string;
33
- price?: number;
27
+ access?: string;
34
28
  original_price?: number;
29
+ discount_price?: number;
30
+ final_price?: number;
35
31
  currency?: string;
36
32
  level?: string;
37
33
  language?: string;
@@ -41,21 +37,26 @@ interface LWApiCourseData {
41
37
  total_ratings?: number;
42
38
  tags?: string[];
43
39
  categories?: string[];
40
+ courseImage?: string | null;
44
41
  image_url?: string;
45
42
  video_url?: string;
46
43
  certificate_enabled?: boolean;
44
+ created?: number;
45
+ modified?: number;
47
46
  created_at?: string;
48
47
  updated_at?: string;
49
48
  published_at?: string;
49
+ label?: string | null;
50
+ expires?: number | null;
51
+ expiresType?: string;
52
+ author?: { name?: string; image?: string | null } | null;
50
53
  }
51
54
 
52
55
  /**
53
56
  * Raw API shape for sections/modules response
54
57
  */
55
58
  interface LWApiSectionsResponse {
56
- success?: boolean;
57
59
  data?: LWApiModuleData[] | { data: LWApiModuleData[] };
58
- message?: string;
59
60
  }
60
61
 
61
62
  interface LWApiModuleData {
@@ -86,9 +87,7 @@ interface LWApiLessonData {
86
87
  * Raw API shape for instructors response
87
88
  */
88
89
  interface LWApiInstructorsResponse {
89
- success?: boolean;
90
90
  data?: LWApiInstructorData[] | { data: LWApiInstructorData[] };
91
- message?: string;
92
91
  }
93
92
 
94
93
  interface LWApiInstructorData {
@@ -154,14 +153,13 @@ export class GetLearnWorldsCourseDetailsAction extends LearnWorldsBaseAction {
154
153
  }
155
154
  this.validatePathSegment(courseId, 'CourseID');
156
155
 
157
- // Get course details
158
- const courseResponse = await this.makeLearnWorldsRequest<LWApiCourseResponse>(`/courses/${courseId}`, 'GET', null, contextUser);
156
+ // Get course details — LW v2 API returns the course object directly
157
+ const course = await this.makeLearnWorldsRequest<LWApiCourseData>(`courses/${courseId}`, 'GET', undefined, contextUser);
159
158
 
160
- if (!courseResponse.success || !courseResponse.data) {
161
- throw new Error(courseResponse.message || 'Failed to retrieve course details');
159
+ if (!course || !course.id) {
160
+ throw new Error('Failed to retrieve course details');
162
161
  }
163
162
 
164
- const course = courseResponse.data;
165
163
  const courseDetails = this.buildCourseDetails(course);
166
164
 
167
165
  if (includeModules) {
@@ -226,10 +224,10 @@ export class GetLearnWorldsCourseDetailsAction extends LearnWorldsBaseAction {
226
224
  id: course.id,
227
225
  title: course.title,
228
226
  slug: course.slug,
229
- description: course.description,
227
+ description: course.description || undefined,
230
228
  shortDescription: course.short_description,
231
- status: course.status || 'published',
232
- price: course.price || 0,
229
+ status: course.access || 'published',
230
+ price: course.final_price ?? course.original_price ?? 0,
233
231
  originalPrice: course.original_price,
234
232
  currency: course.currency || 'USD',
235
233
  level: course.level || 'all',
@@ -241,11 +239,11 @@ export class GetLearnWorldsCourseDetailsAction extends LearnWorldsBaseAction {
241
239
  totalRatings: course.total_ratings || 0,
242
240
  tags: course.tags || [],
243
241
  categories: course.categories || [],
244
- imageUrl: course.image_url,
242
+ imageUrl: course.courseImage || course.image_url || undefined,
245
243
  videoUrl: course.video_url,
246
244
  certificateEnabled: course.certificate_enabled || false,
247
- createdAt: course.created_at,
248
- updatedAt: course.updated_at,
245
+ createdAt: course.created ? String(course.created) : course.created_at,
246
+ updatedAt: course.modified ? String(course.modified) : course.updated_at,
249
247
  publishedAt: course.published_at,
250
248
  };
251
249
  }
@@ -254,14 +252,20 @@ export class GetLearnWorldsCourseDetailsAction extends LearnWorldsBaseAction {
254
252
  * Fetch and attach modules/curriculum to course details
255
253
  */
256
254
  private async attachModules(courseId: string, courseDetails: CourseDetailsData, contextUser: UserInfo): Promise<void> {
257
- const modulesResponse = await this.makeLearnWorldsRequest<LWApiSectionsResponse>(`/courses/${courseId}/sections`, 'GET', null, contextUser);
258
-
259
- if (modulesResponse.success && modulesResponse.data) {
260
- const rawModules = Array.isArray(modulesResponse.data) ? modulesResponse.data : (modulesResponse.data as { data: LWApiModuleData[] }).data || [];
261
-
262
- courseDetails.modules = this.formatModules(rawModules);
263
- courseDetails.totalModules = courseDetails.modules.length;
264
- courseDetails.totalLessons = courseDetails.modules.reduce((sum, mod) => sum + (mod.lessons?.length || 0), 0);
255
+ try {
256
+ const modulesResponse = await this.makeLearnWorldsRequest<LWApiSectionsResponse>(`courses/${courseId}/sections`, 'GET', undefined, contextUser);
257
+
258
+ const rawModules = modulesResponse.data
259
+ ? (Array.isArray(modulesResponse.data) ? modulesResponse.data : (modulesResponse.data as { data: LWApiModuleData[] }).data || [])
260
+ : [];
261
+
262
+ if (rawModules.length > 0) {
263
+ courseDetails.modules = this.formatModules(rawModules);
264
+ courseDetails.totalModules = courseDetails.modules.length;
265
+ courseDetails.totalLessons = courseDetails.modules.reduce((sum, mod) => sum + (mod.lessons?.length || 0), 0);
266
+ }
267
+ } catch {
268
+ // Sections endpoint might not be available for this course type
265
269
  }
266
270
  }
267
271
 
@@ -269,14 +273,18 @@ export class GetLearnWorldsCourseDetailsAction extends LearnWorldsBaseAction {
269
273
  * Fetch and attach instructors to course details
270
274
  */
271
275
  private async attachInstructors(courseId: string, courseDetails: CourseDetailsData, contextUser: UserInfo): Promise<void> {
272
- const instructorsResponse = await this.makeLearnWorldsRequest<LWApiInstructorsResponse>(`/courses/${courseId}/instructors`, 'GET', null, contextUser);
276
+ try {
277
+ const instructorsResponse = await this.makeLearnWorldsRequest<LWApiInstructorsResponse>(`courses/${courseId}/instructors`, 'GET', undefined, contextUser);
273
278
 
274
- if (instructorsResponse.success && instructorsResponse.data) {
275
- const rawInstructors = Array.isArray(instructorsResponse.data)
276
- ? instructorsResponse.data
277
- : (instructorsResponse.data as { data: LWApiInstructorData[] }).data || [];
279
+ const rawInstructors = instructorsResponse.data
280
+ ? (Array.isArray(instructorsResponse.data) ? instructorsResponse.data : (instructorsResponse.data as { data: LWApiInstructorData[] }).data || [])
281
+ : [];
278
282
 
279
- courseDetails.instructors = this.formatInstructors(rawInstructors);
283
+ if (rawInstructors.length > 0) {
284
+ courseDetails.instructors = this.formatInstructors(rawInstructors);
285
+ }
286
+ } catch {
287
+ // Instructors endpoint might not be available
280
288
  }
281
289
  }
282
290
 
@@ -284,18 +292,22 @@ export class GetLearnWorldsCourseDetailsAction extends LearnWorldsBaseAction {
284
292
  * Fetch and attach stats to course details
285
293
  */
286
294
  private async attachStats(courseId: string, courseDetails: CourseDetailsData, contextUser: UserInfo): Promise<void> {
287
- const statsResponse = await this.makeLearnWorldsRequest<LWApiStatsResponse>(`/courses/${courseId}/stats`, 'GET', null, contextUser);
288
-
289
- if (statsResponse.success && statsResponse.data) {
290
- const statsData = statsResponse.data;
291
- courseDetails.stats = {
292
- totalEnrollments: statsData.total_enrollments || courseDetails.totalEnrollments,
293
- activeStudents: statsData.active_students || 0,
294
- completionRate: statsData.completion_rate || 0,
295
- averageProgressPercentage: statsData.average_progress || 0,
296
- averageTimeToComplete: statsData.average_time_to_complete,
297
- totalRevenue: statsData.total_revenue || 0,
298
- } satisfies CourseStats;
295
+ try {
296
+ const statsResponse = await this.makeLearnWorldsRequest<LWApiStatsResponse>(`courses/${courseId}/stats`, 'GET', undefined, contextUser);
297
+
298
+ if (statsResponse.data) {
299
+ const statsData = statsResponse.data;
300
+ courseDetails.stats = {
301
+ totalEnrollments: statsData.total_enrollments || courseDetails.totalEnrollments,
302
+ activeStudents: statsData.active_students || 0,
303
+ completionRate: statsData.completion_rate || 0,
304
+ averageProgressPercentage: statsData.average_progress || 0,
305
+ averageTimeToComplete: statsData.average_time_to_complete,
306
+ totalRevenue: statsData.total_revenue || 0,
307
+ } satisfies CourseStats;
308
+ }
309
+ } catch {
310
+ // Stats endpoint might not be available for all plan types
299
311
  }
300
312
  }
301
313
 
@@ -209,7 +209,7 @@ export class GetLearnWorldsUserDetailsAction extends LearnWorldsBaseAction {
209
209
  * Fetch and attach enrollment data to userDetails.
210
210
  */
211
211
  private async loadEnrollments(userDetails: LearnWorldsUserDetailsFull, userId: string, contextUser: UserInfo): Promise<void> {
212
- const enrollmentsResponse = await this.makeLearnWorldsRequest<LWEnrollmentsListResponse>(`users/${userId}/enrollments`, 'GET', undefined, contextUser);
212
+ const enrollmentsResponse = await this.makeLearnWorldsRequest<LWEnrollmentsListResponse>(`users/${userId}/courses`, 'GET', undefined, contextUser);
213
213
 
214
214
  if (enrollmentsResponse.data) {
215
215
  userDetails.enrollments = enrollmentsResponse.data.map((e) => this.mapEnrollment(e));
@@ -82,7 +82,7 @@ export class GetUserEnrollmentsAction extends LearnWorldsBaseAction {
82
82
 
83
83
  const queryParams = this.buildEnrollmentQueryParams(status, includeExpired, sortBy, sortOrder, maxResults);
84
84
 
85
- const enrollmentsData = await this.makeLearnWorldsPaginatedRequest<LWApiEnrollmentData>(`users/${userId}/enrollments`, queryParams, contextUser);
85
+ const enrollmentsData = await this.makeLearnWorldsPaginatedRequest<LWApiEnrollmentData>(`users/${userId}/courses`, queryParams, contextUser, maxResults);
86
86
 
87
87
  const enrollments = enrollmentsData || [];
88
88
  const formattedEnrollments = await this.formatEnrollments(enrollments, includeCourseDetails, contextUser);
@@ -61,7 +61,7 @@ export class GetLearnWorldsUsersAction extends LearnWorldsBaseAction {
61
61
  queryParams.limit = Math.min(maxResults, 100); // LearnWorlds max is usually 100
62
62
 
63
63
  // Make the API request
64
- const users = await this.makeLearnWorldsPaginatedRequest<LWApiUser>('users', queryParams, contextUser);
64
+ const users = await this.makeLearnWorldsPaginatedRequest<LWApiUser>('users', queryParams, contextUser, maxResults);
65
65
 
66
66
  // Map to our interface
67
67
  const mappedUsers: LearnWorldsUser[] = users.map((user) => this.mapLearnWorldsUser(user));
@@ -28,7 +28,7 @@ export class SSOLoginAction extends LearnWorldsBaseAction {
28
28
  this.validateSSOParams(params);
29
29
 
30
30
  const body = this.buildSSORequestBody(params);
31
- const response = await this.makeLearnWorldsRequest<LWApiSSOResponse>('sso', 'POST', body, contextUser);
31
+ const response = await this.makeLearnWorldsNonVersionedRequest<LWApiSSOResponse>('sso', 'POST', body, contextUser);
32
32
 
33
33
  return {
34
34
  LoginURL: response.url,
@@ -102,7 +102,7 @@ export abstract class LearnWorldsBaseAction extends BaseLMSAction {
102
102
  /**
103
103
  * Resolves integration credentials and builds the base URL and headers.
104
104
  */
105
- private async buildRequestConfig(contextUser: UserInfo): Promise<{ fullUrl: string; headers: Record<string, string> }> {
105
+ private async buildRequestConfig(contextUser: UserInfo): Promise<{ fullUrl: string; nonVersionedUrl: string; headers: Record<string, string> }> {
106
106
  const companyId = this.getParamValue(this.params, 'CompanyID') as string | undefined;
107
107
  if (!companyId) {
108
108
  throw new Error('CompanyID parameter is required');
@@ -122,17 +122,58 @@ export abstract class LearnWorldsBaseAction extends BaseLMSAction {
122
122
 
123
123
  this.validateSchoolDomain(schoolDomain);
124
124
 
125
+ const lwClient = this.getCredentialFromEnv(companyId, 'CLIENT_ID') || schoolDomain;
126
+ const nonVersionedUrl = `https://${schoolDomain}/admin/api`;
127
+
125
128
  return {
126
- fullUrl: `https://${schoolDomain}/api/${this.apiVersion}`,
129
+ fullUrl: `${nonVersionedUrl}/${this.apiVersion}`,
130
+ nonVersionedUrl,
127
131
  headers: {
128
132
  Authorization: `Bearer ${credentials.apiKey}`,
129
133
  Accept: 'application/json',
130
134
  'Content-Type': 'application/json',
131
- 'Lw-Client': 'MemberJunction',
135
+ 'Lw-Client': lwClient,
132
136
  },
133
137
  };
134
138
  }
135
139
 
140
+ /**
141
+ * Makes an authenticated request to a non-versioned LearnWorlds API endpoint (e.g. /admin/api/sso).
142
+ */
143
+ protected async makeLearnWorldsNonVersionedRequest<T = Record<string, unknown>>(
144
+ endpoint: string,
145
+ method: 'GET' | 'POST' | 'PUT' | 'DELETE' = 'GET',
146
+ body?: object | null,
147
+ contextUser?: UserInfo,
148
+ ): Promise<T> {
149
+ if (!contextUser) {
150
+ throw new Error('Context user is required for LearnWorlds API calls');
151
+ }
152
+
153
+ const { nonVersionedUrl, headers } = await this.buildRequestConfig(contextUser);
154
+ const requestUrl = `${nonVersionedUrl}/${endpoint}`;
155
+
156
+ try {
157
+ this.apiCallCount++;
158
+ const response = await fetch(requestUrl, {
159
+ method,
160
+ headers,
161
+ body: body ? JSON.stringify(body) : undefined,
162
+ });
163
+
164
+ if (!response.ok) {
165
+ throw new Error(await this.buildErrorMessage(response));
166
+ }
167
+
168
+ return (await response.json()) as T;
169
+ } catch (error) {
170
+ if (error instanceof Error) {
171
+ throw error;
172
+ }
173
+ throw new Error(`LearnWorlds API request failed: ${error}`);
174
+ }
175
+ }
176
+
136
177
  /**
137
178
  * Parses error details from a non-OK API response.
138
179
  */
@@ -161,11 +202,13 @@ export abstract class LearnWorldsBaseAction extends BaseLMSAction {
161
202
  endpoint: string,
162
203
  queryParams: Record<string, string | number | boolean> = {},
163
204
  contextUser?: UserInfo,
205
+ maxResults?: number,
164
206
  ): Promise<T[]> {
165
207
  const results: T[] = [];
166
208
  let page = 1;
167
209
  let hasMore = true;
168
210
  const limit = (queryParams.limit as number) || LearnWorldsBaseAction.LW_MAX_PAGE_SIZE;
211
+ const effectiveMax = maxResults ?? (this.getParamValue(this.params, 'MaxResults') as number | undefined);
169
212
 
170
213
  while (hasMore) {
171
214
  const paginatedParams: Record<string, string> = {};
@@ -190,10 +233,9 @@ export abstract class LearnWorldsBaseAction extends BaseLMSAction {
190
233
  hasMore = false;
191
234
  }
192
235
 
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);
236
+ // Respect max results
237
+ if (effectiveMax && results.length >= effectiveMax) {
238
+ return results.slice(0, effectiveMax);
197
239
  }
198
240
  }
199
241
 
@@ -450,9 +492,12 @@ export abstract class LearnWorldsBaseAction extends BaseLMSAction {
450
492
  * Re-throws errors for network failures, auth errors, rate limiting, etc.
451
493
  */
452
494
  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());
495
+ const qs = new URLSearchParams({ search: email, limit: '50' });
496
+ const response = await this.makeLearnWorldsRequest<LearnWorldsPaginatedResponse<LWApiUser>>(
497
+ `users?${qs}`, 'GET', undefined, contextUser,
498
+ );
499
+ const users = (response.data && Array.isArray(response.data)) ? response.data : [];
500
+ const match = users.find((u) => u.email.toLowerCase() === email.toLowerCase());
456
501
  if (!match) return null;
457
502
 
458
503
  return this.mapLWApiUserToLearnWorldsUser(match);