@memberjunction/actions-bizapps-lms 2.55.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.
- package/.turbo/turbo-build.log +4 -0
- package/CHANGELOG.md +12 -0
- package/dist/base/base-lms.action.d.ts +77 -0
- package/dist/base/base-lms.action.d.ts.map +1 -0
- package/dist/base/base-lms.action.js +176 -0
- package/dist/base/base-lms.action.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -0
- package/dist/index.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts +125 -0
- package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-courses.action.js +436 -0
- package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +95 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.js +280 -0
- package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +151 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.js +417 -0
- package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/get-users.action.d.ts +53 -0
- package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/get-users.action.js +272 -0
- package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -0
- package/dist/providers/learnworlds/actions/index.d.ts +5 -0
- package/dist/providers/learnworlds/actions/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/actions/index.js +22 -0
- package/dist/providers/learnworlds/actions/index.js.map +1 -0
- package/dist/providers/learnworlds/index.d.ts +3 -0
- package/dist/providers/learnworlds/index.d.ts.map +1 -0
- package/dist/providers/learnworlds/index.js +21 -0
- package/dist/providers/learnworlds/index.js.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts +52 -0
- package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -0
- package/dist/providers/learnworlds/learnworlds-base.action.js +186 -0
- package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -0
- package/package.json +40 -0
- package/src/base/base-lms.action.ts +197 -0
- package/src/index.ts +5 -0
- package/src/providers/learnworlds/actions/get-courses.action.ts +592 -0
- package/src/providers/learnworlds/actions/get-user-details.action.ts +381 -0
- package/src/providers/learnworlds/actions/get-user-progress.action.ts +625 -0
- package/src/providers/learnworlds/actions/get-users.action.ts +319 -0
- package/src/providers/learnworlds/actions/index.ts +5 -0
- package/src/providers/learnworlds/index.ts +5 -0
- package/src/providers/learnworlds/learnworlds-base.action.ts +221 -0
- package/tsconfig.json +18 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { ActionParam } from '@memberjunction/actions-base';
|
|
2
|
+
import { BaseAction } from '@memberjunction/actions';
|
|
3
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
4
|
+
import { UserInfo } from '@memberjunction/core';
|
|
5
|
+
import { CompanyIntegrationEntity } from '@memberjunction/core-entities';
|
|
6
|
+
import { Metadata, RunView } from '@memberjunction/core';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Base class for all LMS-related actions.
|
|
10
|
+
* Provides common functionality and patterns for interacting with Learning Management Systems.
|
|
11
|
+
*/
|
|
12
|
+
@RegisterClass(BaseAction, 'BaseLMSAction')
|
|
13
|
+
export abstract class BaseLMSAction extends BaseAction {
|
|
14
|
+
/**
|
|
15
|
+
* The LMS provider this action is designed for (e.g., 'LearnWorlds', 'Moodle', etc.)
|
|
16
|
+
*/
|
|
17
|
+
protected abstract lmsProvider: string;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The integration name to look up in the Integration entity
|
|
21
|
+
*/
|
|
22
|
+
protected abstract integrationName: string;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Cached company integration for the current execution
|
|
26
|
+
*/
|
|
27
|
+
private _companyIntegration: CompanyIntegrationEntity | null = null;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Common LMS parameters that many actions will need
|
|
31
|
+
*/
|
|
32
|
+
protected getCommonLMSParams(): ActionParam[] {
|
|
33
|
+
return [
|
|
34
|
+
{
|
|
35
|
+
Name: 'CompanyID',
|
|
36
|
+
Type: 'Input',
|
|
37
|
+
Value: null
|
|
38
|
+
}
|
|
39
|
+
];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Gets the company integration record for the specified company and LMS
|
|
44
|
+
*/
|
|
45
|
+
protected async getCompanyIntegration(companyId: string, contextUser: UserInfo): Promise<CompanyIntegrationEntity> {
|
|
46
|
+
// Check cache first
|
|
47
|
+
if (this._companyIntegration && this._companyIntegration.CompanyID === companyId) {
|
|
48
|
+
return this._companyIntegration;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const rv = new RunView();
|
|
52
|
+
const result = await rv.RunView<CompanyIntegrationEntity>({
|
|
53
|
+
EntityName: 'Company Integrations',
|
|
54
|
+
ExtraFilter: `CompanyID = '${companyId}' AND Integration.Name = '${this.integrationName}'`,
|
|
55
|
+
ResultType: 'entity_object'
|
|
56
|
+
}, contextUser);
|
|
57
|
+
|
|
58
|
+
if (!result.Success) {
|
|
59
|
+
throw new Error(`Failed to retrieve company integration: ${result.ErrorMessage}`);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (!result.Results || result.Results.length === 0) {
|
|
63
|
+
throw new Error(`No ${this.integrationName} integration found for company ${companyId}. Please configure the integration first.`);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
this._companyIntegration = result.Results[0];
|
|
67
|
+
return this._companyIntegration;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Gets credentials from environment variables
|
|
72
|
+
* Format: BIZAPPS_{PROVIDER}_{COMPANY_ID}_{CREDENTIAL_TYPE}
|
|
73
|
+
* Example: BIZAPPS_LEARNWORLDS_12345_API_KEY
|
|
74
|
+
*/
|
|
75
|
+
protected getCredentialFromEnv(companyId: string, credentialType: string): string | undefined {
|
|
76
|
+
const envKey = `BIZAPPS_${this.lmsProvider.toUpperCase().replace(/\s+/g, '_')}_${companyId}_${credentialType.toUpperCase()}`;
|
|
77
|
+
return process.env[envKey];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Gets API credentials - first tries environment variables, then falls back to database
|
|
82
|
+
*/
|
|
83
|
+
protected async getAPICredentials(integration: CompanyIntegrationEntity): Promise<{ apiKey?: string; apiSecret?: string; accessToken?: string }> {
|
|
84
|
+
const companyId = integration.CompanyID;
|
|
85
|
+
|
|
86
|
+
// Try environment variables first
|
|
87
|
+
const envApiKey = this.getCredentialFromEnv(companyId, 'API_KEY');
|
|
88
|
+
const envApiSecret = this.getCredentialFromEnv(companyId, 'API_SECRET');
|
|
89
|
+
const envAccessToken = this.getCredentialFromEnv(companyId, 'ACCESS_TOKEN');
|
|
90
|
+
|
|
91
|
+
if (envApiKey || envAccessToken) {
|
|
92
|
+
return {
|
|
93
|
+
apiKey: envApiKey,
|
|
94
|
+
apiSecret: envApiSecret,
|
|
95
|
+
accessToken: envAccessToken
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Fall back to database (for backwards compatibility)
|
|
100
|
+
if (!integration.APIKey && !integration.AccessToken) {
|
|
101
|
+
throw new Error(`No API credentials found for ${this.integrationName} integration. Please set environment variables or configure in database.`);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
apiKey: integration.APIKey || undefined,
|
|
106
|
+
accessToken: integration.AccessToken || undefined
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Gets the base URL for API calls
|
|
112
|
+
*/
|
|
113
|
+
protected async getAPIBaseURL(integration: CompanyIntegrationEntity): Promise<string> {
|
|
114
|
+
// Check if custom URL is stored in the integration
|
|
115
|
+
if (integration.CustomAttribute1) {
|
|
116
|
+
return integration.CustomAttribute1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Return empty string - derived classes should override this
|
|
120
|
+
return '';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Helper to get parameter value with type safety
|
|
125
|
+
*/
|
|
126
|
+
protected getParamValue(params: ActionParam[], paramName: string): any {
|
|
127
|
+
const param = params.find(p => p.Name === paramName);
|
|
128
|
+
return param?.Value;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Standard date format for LMS systems (ISO 8601)
|
|
133
|
+
*/
|
|
134
|
+
protected formatLMSDate(date: Date): string {
|
|
135
|
+
return date.toISOString();
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Parse date from LMS format
|
|
140
|
+
*/
|
|
141
|
+
protected parseLMSDate(dateString: string): Date {
|
|
142
|
+
return new Date(dateString);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Calculate progress percentage
|
|
147
|
+
*/
|
|
148
|
+
protected calculateProgressPercentage(completed: number, total: number): number {
|
|
149
|
+
if (total === 0) return 0;
|
|
150
|
+
return Math.round((completed / total) * 100);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Format duration in seconds to human readable format
|
|
155
|
+
*/
|
|
156
|
+
protected formatDuration(seconds: number): string {
|
|
157
|
+
const hours = Math.floor(seconds / 3600);
|
|
158
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
159
|
+
const secs = seconds % 60;
|
|
160
|
+
|
|
161
|
+
if (hours > 0) {
|
|
162
|
+
return `${hours}h ${minutes}m ${secs}s`;
|
|
163
|
+
} else if (minutes > 0) {
|
|
164
|
+
return `${minutes}m ${secs}s`;
|
|
165
|
+
} else {
|
|
166
|
+
return `${secs}s`;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Helper to build consistent error messages for LMS operations
|
|
172
|
+
*/
|
|
173
|
+
protected buildLMSErrorMessage(operation: string, details: string, systemError?: any): string {
|
|
174
|
+
let message = `LMS operation failed: ${operation}. ${details}`;
|
|
175
|
+
if (systemError) {
|
|
176
|
+
message += ` System error: ${systemError.message || systemError}`;
|
|
177
|
+
}
|
|
178
|
+
return message;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Common enrollment status mapping
|
|
183
|
+
*/
|
|
184
|
+
protected mapEnrollmentStatus(status: string): 'active' | 'completed' | 'expired' | 'suspended' | 'unknown' {
|
|
185
|
+
const statusMap: Record<string, 'active' | 'completed' | 'expired' | 'suspended' | 'unknown'> = {
|
|
186
|
+
'active': 'active',
|
|
187
|
+
'completed': 'completed',
|
|
188
|
+
'finished': 'completed',
|
|
189
|
+
'expired': 'expired',
|
|
190
|
+
'suspended': 'suspended',
|
|
191
|
+
'paused': 'suspended',
|
|
192
|
+
'inactive': 'suspended'
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
return statusMap[status.toLowerCase()] || 'unknown';
|
|
196
|
+
}
|
|
197
|
+
}
|