UNPKG

@memberjunction/actions-bizapps-lms

Version:

LMS system integration actions for MemberJunction

107 lines 4.76 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import { RegisterClass } from '@memberjunction/global'; import { LearnWorldsBaseAction } from '../learnworlds-base.action.js'; import { BaseAction } from '@memberjunction/actions'; /** * Action to retrieve bundles from LearnWorlds */ let GetBundlesAction = class GetBundlesAction extends LearnWorldsBaseAction { /** * Retrieves bundles from LearnWorlds with optional search filtering. */ async GetBundles(params, contextUser) { this.SetCompanyContext(params.CompanyID); const queryParams = this.buildBundleQueryParams(params); const rawBundles = await this.makeLearnWorldsPaginatedRequest('bundles', queryParams, contextUser); const bundles = rawBundles.map((b) => this.mapApiBundle(b)); return { Bundles: bundles, TotalCount: bundles.length, }; } /** * Builds query parameters for the bundles API request */ buildBundleQueryParams(params) { const queryParams = {}; if (params.SearchText) { queryParams.search = params.SearchText; } if (params.MaxResults) { queryParams.limit = Math.min(params.MaxResults, 100); } return queryParams; } /** * Maps a raw LearnWorlds API bundle to the standard LearnWorldsBundle interface */ mapApiBundle(raw) { const createdRaw = raw.created || raw.created_at || ''; const updatedRaw = raw.updated || raw.updated_at || ''; return { id: raw.id || raw._id || '', title: raw.title || '', description: raw.description, price: raw.price, currency: raw.currency, courses: raw.courses || [], isActive: raw.is_active !== false, createdAt: createdRaw ? this.parseLearnWorldsDate(createdRaw).toISOString() : '', updatedAt: updatedRaw ? this.parseLearnWorldsDate(updatedRaw).toISOString() : '', thumbnailUrl: raw.thumbnail_url || raw.image, totalCourses: raw.total_courses || (raw.courses ? raw.courses.length : 0), totalEnrollments: raw.total_enrollments || raw.students_count || 0, }; } /** * Framework entry point that delegates to the typed public method */ async InternalRunAction(params) { const { Params, ContextUser } = params; this.params = Params; try { const bundleParams = { CompanyID: this.getRequiredStringParam(Params, 'CompanyID'), SearchText: this.getOptionalStringParam(Params, 'SearchText'), MaxResults: this.getOptionalNumberParam(Params, 'MaxResults', LearnWorldsBaseAction.LW_MAX_PAGE_SIZE), }; const result = await this.GetBundles(bundleParams, ContextUser); this.setOutputParam(Params, 'Bundles', result.Bundles); this.setOutputParam(Params, 'TotalCount', result.TotalCount); return this.buildSuccessResult(`Successfully retrieved ${result.TotalCount} bundle(s) from LearnWorlds`, Params); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; return this.buildErrorResult('ERROR', `Error retrieving bundles: ${errorMessage}`, Params); } } /** * Define the parameters this action expects */ get Params() { const baseParams = this.getCommonLMSParams(); const specificParams = [ { Name: 'SearchText', Type: 'Input', Value: null }, { Name: 'MaxResults', Type: 'Input', Value: null }, { Name: 'Bundles', Type: 'Output', Value: null }, { Name: 'TotalCount', Type: 'Output', Value: null }, ]; return [...baseParams, ...specificParams]; } /** * Metadata about this action */ get Description() { return 'Retrieves course bundles from LearnWorlds with optional search filtering'; } }; GetBundlesAction = __decorate([ RegisterClass(BaseAction, 'GetBundlesAction') ], GetBundlesAction); export { GetBundlesAction }; //# sourceMappingURL=get-bundles.action.js.map