UNPKG

@memberjunction/actions-bizapps-lms

Version:

LMS system integration actions for MemberJunction

101 lines 4.21 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 generate an SSO login URL for a LearnWorlds user */ let SSOLoginAction = class SSOLoginAction extends LearnWorldsBaseAction { /** * Generates an SSO login URL for a LearnWorlds user. * Requires either Email or UserID to identify the user. */ async GenerateSSOUrl(params, contextUser) { this.SetCompanyContext(params.CompanyID); this.validateSSOParams(params); const body = this.buildSSORequestBody(params); const response = await this.makeLearnWorldsNonVersionedRequest('sso', 'POST', body, contextUser); return { LoginURL: response.url, LearnWorldsUserID: response.user_id, }; } /** * Validates that either Email or UserID is provided */ validateSSOParams(params) { if (!params.Email && !params.UserID) { throw new Error('Either Email or UserID is required for SSO login'); } } /** * Builds the SSO request body based on which identifier is provided */ buildSSORequestBody(params) { const body = {}; if (params.Email) { this.validateEmail(params.Email); body.email = params.Email; } else if (params.UserID) { body.user_id = params.UserID; } if (params.RedirectTo) { body.redirect_to = this.validateRedirectTo(params.RedirectTo); } return body; } /** * Framework entry point that delegates to the typed public method */ async InternalRunAction(params) { const { Params, ContextUser } = params; this.params = Params; try { const ssoParams = { CompanyID: this.getRequiredStringParam(Params, 'CompanyID'), Email: this.getOptionalStringParam(Params, 'Email'), UserID: this.getOptionalStringParam(Params, 'UserID'), RedirectTo: this.getOptionalStringParam(Params, 'RedirectTo'), }; const result = await this.GenerateSSOUrl(ssoParams, ContextUser); this.setOutputParam(Params, 'LoginURL', result.LoginURL); this.setOutputParam(Params, 'LearnWorldsUserID', result.LearnWorldsUserID); return this.buildSuccessResult(`SSO URL generated successfully`, Params); } catch (error) { const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred'; return this.buildErrorResult('ERROR', `Error generating SSO URL: ${errorMessage}`, Params); } } /** * Define the parameters this action expects */ get Params() { const baseParams = this.getCommonLMSParams(); const specificParams = [ { Name: 'Email', Type: 'Input', Value: null }, { Name: 'UserID', Type: 'Input', Value: null }, { Name: 'RedirectTo', Type: 'Input', Value: null }, { Name: 'LoginURL', Type: 'Output', Value: null }, { Name: 'LearnWorldsUserID', Type: 'Output', Value: null }, ]; return [...baseParams, ...specificParams]; } /** * Metadata about this action */ get Description() { return 'Generates an SSO login URL for a LearnWorlds user'; } }; SSOLoginAction = __decorate([ RegisterClass(BaseAction, 'SSOLoginAction') ], SSOLoginAction); export { SSOLoginAction }; //# sourceMappingURL=sso-login.action.js.map