@memberjunction/actions-bizapps-lms 5.3.0 → 5.4.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 +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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ActionParam } from '@memberjunction/actions-base';
|
|
1
|
+
import { ActionParam, ActionResultSimple } from '@memberjunction/actions-base';
|
|
2
2
|
import { BaseAction } from '@memberjunction/actions';
|
|
3
3
|
import { RegisterClass } from '@memberjunction/global';
|
|
4
4
|
import { UserInfo } from '@memberjunction/core';
|
|
@@ -11,187 +11,250 @@ import { Metadata, RunView } from '@memberjunction/core';
|
|
|
11
11
|
*/
|
|
12
12
|
@RegisterClass(BaseAction, 'BaseLMSAction')
|
|
13
13
|
export abstract class BaseLMSAction extends BaseAction {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
}
|
|
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: MJCompanyIntegrationEntity | null = null;
|
|
41
28
|
|
|
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
|
-
this._companyIntegration = result.Results[0];
|
|
67
|
-
return this._companyIntegration;
|
|
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
|
+
* Validates that a string is a valid UUID format to prevent SQL injection.
|
|
44
|
+
*/
|
|
45
|
+
private static readonly uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Validates that an integration name contains only safe characters (alphanumeric, spaces, hyphens, underscores).
|
|
49
|
+
*/
|
|
50
|
+
private validateIntegrationName(name: string): string {
|
|
51
|
+
if (!/^[a-zA-Z0-9 _-]+$/.test(name)) {
|
|
52
|
+
throw new Error('Invalid integration name: contains forbidden characters');
|
|
68
53
|
}
|
|
54
|
+
return name;
|
|
55
|
+
}
|
|
69
56
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return process.env[envKey];
|
|
57
|
+
/**
|
|
58
|
+
* Gets the company integration record for the specified company and LMS
|
|
59
|
+
*/
|
|
60
|
+
protected async getCompanyIntegration(companyId: string, contextUser: UserInfo): Promise<MJCompanyIntegrationEntity> {
|
|
61
|
+
// Validate companyId format to prevent SQL injection
|
|
62
|
+
if (!BaseLMSAction.uuidRegex.test(companyId)) {
|
|
63
|
+
throw new Error('CompanyID must be a valid UUID');
|
|
78
64
|
}
|
|
79
65
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
};
|
|
66
|
+
// Validate integration name before SQL interpolation
|
|
67
|
+
const safeIntegrationName = this.validateIntegrationName(this.integrationName);
|
|
68
|
+
|
|
69
|
+
// Check cache first
|
|
70
|
+
if (this._companyIntegration && this._companyIntegration.CompanyID === companyId) {
|
|
71
|
+
return this._companyIntegration;
|
|
108
72
|
}
|
|
109
73
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
74
|
+
const rv = new RunView();
|
|
75
|
+
const result = await rv.RunView<MJCompanyIntegrationEntity>(
|
|
76
|
+
{
|
|
77
|
+
EntityName: 'MJ: Company Integrations',
|
|
78
|
+
ExtraFilter: `CompanyID = '${companyId}' AND Integration.Name = '${safeIntegrationName}'`,
|
|
79
|
+
ResultType: 'entity_object',
|
|
80
|
+
},
|
|
81
|
+
contextUser,
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
if (!result.Success) {
|
|
85
|
+
throw new Error(`Failed to retrieve company integration: ${result.ErrorMessage}`);
|
|
121
86
|
}
|
|
122
87
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
*/
|
|
126
|
-
protected getParamValue(params: ActionParam[], paramName: string): any {
|
|
127
|
-
const param = params.find(p => p.Name === paramName);
|
|
128
|
-
return param?.Value;
|
|
88
|
+
if (!result.Results || result.Results.length === 0) {
|
|
89
|
+
throw new Error(`No ${this.integrationName} integration found for company ${companyId}. Please configure the integration first.`);
|
|
129
90
|
}
|
|
130
91
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
92
|
+
this._companyIntegration = result.Results[0];
|
|
93
|
+
return this._companyIntegration;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Gets credentials from environment variables
|
|
98
|
+
* Format: BIZAPPS_{PROVIDER}_{COMPANY_ID}_{CREDENTIAL_TYPE}
|
|
99
|
+
* Example: BIZAPPS_LEARNWORLDS_12345_API_KEY
|
|
100
|
+
*/
|
|
101
|
+
protected getCredentialFromEnv(companyId: string, credentialType: string): string | undefined {
|
|
102
|
+
const envKey = `BIZAPPS_${this.lmsProvider.toUpperCase().replace(/\s+/g, '_')}_${companyId}_${credentialType.toUpperCase()}`;
|
|
103
|
+
return process.env[envKey];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Gets API credentials - first tries environment variables, then falls back to database
|
|
108
|
+
*/
|
|
109
|
+
protected async getAPICredentials(integration: MJCompanyIntegrationEntity): Promise<{ apiKey?: string; apiSecret?: string; accessToken?: string }> {
|
|
110
|
+
const companyId = integration.CompanyID;
|
|
111
|
+
|
|
112
|
+
// Try environment variables first
|
|
113
|
+
const envApiKey = this.getCredentialFromEnv(companyId, 'API_KEY');
|
|
114
|
+
const envApiSecret = this.getCredentialFromEnv(companyId, 'API_SECRET');
|
|
115
|
+
const envAccessToken = this.getCredentialFromEnv(companyId, 'ACCESS_TOKEN');
|
|
116
|
+
|
|
117
|
+
if (envApiKey || envAccessToken) {
|
|
118
|
+
return {
|
|
119
|
+
apiKey: envApiKey,
|
|
120
|
+
apiSecret: envApiSecret,
|
|
121
|
+
accessToken: envAccessToken,
|
|
122
|
+
};
|
|
136
123
|
}
|
|
137
124
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
protected parseLMSDate(dateString: string): Date {
|
|
142
|
-
return new Date(dateString);
|
|
125
|
+
// Fall back to database (for backwards compatibility)
|
|
126
|
+
if (!integration.APIKey && !integration.AccessToken) {
|
|
127
|
+
throw new Error(`No API credentials found for ${this.integrationName} integration. Please set environment variables or configure in database.`);
|
|
143
128
|
}
|
|
144
129
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
130
|
+
return {
|
|
131
|
+
apiKey: integration.APIKey || undefined,
|
|
132
|
+
accessToken: integration.AccessToken || undefined,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Gets the base URL for API calls
|
|
138
|
+
*/
|
|
139
|
+
protected async getAPIBaseURL(integration: MJCompanyIntegrationEntity): Promise<string> {
|
|
140
|
+
// Check if custom URL is stored in the integration
|
|
141
|
+
if (integration.CustomAttribute1) {
|
|
142
|
+
return integration.CustomAttribute1;
|
|
151
143
|
}
|
|
152
144
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
145
|
+
// Return empty string - derived classes should override this
|
|
146
|
+
return '';
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Helper to get parameter value from an ActionParam array
|
|
151
|
+
*/
|
|
152
|
+
protected getParamValue(params: ActionParam[], paramName: string): unknown {
|
|
153
|
+
const param = params.find((p) => p.Name === paramName);
|
|
154
|
+
return param?.Value;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Standard date format for LMS systems (ISO 8601)
|
|
159
|
+
*/
|
|
160
|
+
protected formatLMSDate(date: Date): string {
|
|
161
|
+
return date.toISOString();
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Parse date from LMS format
|
|
166
|
+
*/
|
|
167
|
+
protected parseLMSDate(dateString: string): Date {
|
|
168
|
+
return new Date(dateString);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Calculate progress percentage
|
|
173
|
+
*/
|
|
174
|
+
protected calculateProgressPercentage(completed: number, total: number): number {
|
|
175
|
+
if (total === 0) return 0;
|
|
176
|
+
return Math.round((completed / total) * 100);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Format duration in seconds to human readable format
|
|
181
|
+
*/
|
|
182
|
+
protected formatDuration(seconds: number): string {
|
|
183
|
+
const hours = Math.floor(seconds / 3600);
|
|
184
|
+
const minutes = Math.floor((seconds % 3600) / 60);
|
|
185
|
+
const secs = seconds % 60;
|
|
186
|
+
|
|
187
|
+
if (hours > 0) {
|
|
188
|
+
return `${hours}h ${minutes}m ${secs}s`;
|
|
189
|
+
} else if (minutes > 0) {
|
|
190
|
+
return `${minutes}m ${secs}s`;
|
|
191
|
+
} else {
|
|
192
|
+
return `${secs}s`;
|
|
168
193
|
}
|
|
194
|
+
}
|
|
169
195
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
return message;
|
|
196
|
+
/**
|
|
197
|
+
* Helper to build consistent error messages for LMS operations
|
|
198
|
+
*/
|
|
199
|
+
protected buildLMSErrorMessage(operation: string, details: string, systemError?: Error | string | { message?: string }): string {
|
|
200
|
+
let message = `LMS operation failed: ${operation}. ${details}`;
|
|
201
|
+
if (systemError) {
|
|
202
|
+
const errorMsg = typeof systemError === 'string' ? systemError : (systemError as { message?: string }).message || String(systemError);
|
|
203
|
+
message += ` System error: ${errorMsg}`;
|
|
179
204
|
}
|
|
205
|
+
return message;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Common enrollment status mapping
|
|
210
|
+
*/
|
|
211
|
+
protected mapEnrollmentStatus(status: string): 'active' | 'completed' | 'expired' | 'suspended' | 'unknown' {
|
|
212
|
+
const statusMap: Record<string, 'active' | 'completed' | 'expired' | 'suspended' | 'unknown'> = {
|
|
213
|
+
active: 'active',
|
|
214
|
+
completed: 'completed',
|
|
215
|
+
finished: 'completed',
|
|
216
|
+
expired: 'expired',
|
|
217
|
+
suspended: 'suspended',
|
|
218
|
+
paused: 'suspended',
|
|
219
|
+
inactive: 'suspended',
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
return statusMap[status.toLowerCase()] || 'unknown';
|
|
223
|
+
}
|
|
180
224
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
'suspended': 'suspended',
|
|
191
|
-
'paused': 'suspended',
|
|
192
|
-
'inactive': 'suspended'
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
return statusMap[status.toLowerCase()] || 'unknown';
|
|
225
|
+
/**
|
|
226
|
+
* Helper to set an output parameter, creating it if it doesn't exist
|
|
227
|
+
*/
|
|
228
|
+
protected setOutputParam(params: ActionParam[], name: string, value: unknown): void {
|
|
229
|
+
const existing = params.find((p) => p.Name === name);
|
|
230
|
+
if (existing) {
|
|
231
|
+
existing.Value = value;
|
|
232
|
+
} else {
|
|
233
|
+
params.push({ Name: name, Type: 'Output', Value: value });
|
|
196
234
|
}
|
|
197
|
-
}
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/**
|
|
238
|
+
* Build a standard success ActionResultSimple
|
|
239
|
+
*/
|
|
240
|
+
protected buildSuccessResult(message: string, params?: ActionParam[]): ActionResultSimple {
|
|
241
|
+
return {
|
|
242
|
+
Success: true,
|
|
243
|
+
ResultCode: 'SUCCESS',
|
|
244
|
+
Message: message,
|
|
245
|
+
...(params ? { Params: params } : {}),
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Build a standard error ActionResultSimple
|
|
251
|
+
*/
|
|
252
|
+
protected buildErrorResult(code: string, message: string, params?: ActionParam[]): ActionResultSimple {
|
|
253
|
+
return {
|
|
254
|
+
Success: false,
|
|
255
|
+
ResultCode: code,
|
|
256
|
+
Message: message,
|
|
257
|
+
...(params ? { Params: params } : {}),
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
2
|
+
import { LearnWorldsBaseAction } from '../learnworlds-base.action';
|
|
3
|
+
import { ActionParam, ActionResultSimple, RunActionParams } from '@memberjunction/actions-base';
|
|
4
|
+
import { BaseAction } from '@memberjunction/actions';
|
|
5
|
+
import { UserInfo } from '@memberjunction/core';
|
|
6
|
+
import { TagParams, TagResult } from '../interfaces';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Shape of the LearnWorlds tag operation API response
|
|
10
|
+
*/
|
|
11
|
+
interface LWApiTagResponse {
|
|
12
|
+
tags?: string[];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Action to attach tags to a LearnWorlds user
|
|
17
|
+
*/
|
|
18
|
+
@RegisterClass(BaseAction, 'AttachTagsAction')
|
|
19
|
+
export class AttachTagsAction extends LearnWorldsBaseAction {
|
|
20
|
+
/**
|
|
21
|
+
* Attaches one or more tags to a LearnWorlds user.
|
|
22
|
+
*/
|
|
23
|
+
public async AttachTags(params: TagParams, contextUser: UserInfo): Promise<TagResult> {
|
|
24
|
+
this.SetCompanyContext(params.CompanyID);
|
|
25
|
+
|
|
26
|
+
if (!params.UserID) {
|
|
27
|
+
throw new Error('UserID is required');
|
|
28
|
+
}
|
|
29
|
+
if (!params.Tags || params.Tags.length === 0) {
|
|
30
|
+
throw new Error('At least one tag is required');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
this.validatePathSegment(params.UserID, 'UserID');
|
|
34
|
+
|
|
35
|
+
const response = await this.makeLearnWorldsRequest<LWApiTagResponse>(`users/${params.UserID}/tags`, 'POST', { tags: params.Tags }, contextUser);
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
Success: true,
|
|
39
|
+
UserID: params.UserID,
|
|
40
|
+
Tags: response.tags || params.Tags,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Framework entry point that delegates to the typed public method
|
|
46
|
+
*/
|
|
47
|
+
protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
|
|
48
|
+
const { Params, ContextUser } = params;
|
|
49
|
+
this.params = Params;
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
const tagParams: TagParams = {
|
|
53
|
+
CompanyID: this.getRequiredStringParam(Params, 'CompanyID'),
|
|
54
|
+
UserID: this.getRequiredStringParam(Params, 'UserID'),
|
|
55
|
+
Tags: this.getOptionalStringArrayParam(Params, 'Tags') || [],
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const result = await this.AttachTags(tagParams, ContextUser);
|
|
59
|
+
|
|
60
|
+
this.setOutputParam(Params, 'Success', result.Success);
|
|
61
|
+
this.setOutputParam(Params, 'ResultTags', result.Tags);
|
|
62
|
+
|
|
63
|
+
return this.buildSuccessResult(`Successfully attached ${result.Tags.length} tag(s) to user ${result.UserID}`, Params);
|
|
64
|
+
} catch (error) {
|
|
65
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
|
66
|
+
return this.buildErrorResult('ERROR', `Error attaching tags: ${errorMessage}`, Params);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Define the parameters this action expects
|
|
72
|
+
*/
|
|
73
|
+
public get Params(): ActionParam[] {
|
|
74
|
+
const baseParams = this.getCommonLMSParams();
|
|
75
|
+
const specificParams: ActionParam[] = [
|
|
76
|
+
{ Name: 'UserID', Type: 'Input', Value: null },
|
|
77
|
+
{ Name: 'Tags', Type: 'Input', Value: null },
|
|
78
|
+
{ Name: 'Success', Type: 'Output', Value: null },
|
|
79
|
+
{ Name: 'ResultTags', Type: 'Output', Value: null },
|
|
80
|
+
];
|
|
81
|
+
return [...baseParams, ...specificParams];
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Metadata about this action
|
|
86
|
+
*/
|
|
87
|
+
public get Description(): string {
|
|
88
|
+
return 'Attaches one or more tags to a LearnWorlds user';
|
|
89
|
+
}
|
|
90
|
+
}
|