@memberjunction/actions-bizapps-lms 5.3.1 → 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.
Files changed (194) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +16 -0
  3. package/LEARNWORLDS_SIDECAR_PLAN.md +845 -0
  4. package/dist/base/base-lms.action.d.ts +26 -4
  5. package/dist/base/base-lms.action.d.ts.map +1 -1
  6. package/dist/base/base-lms.action.js +73 -17
  7. package/dist/base/base-lms.action.js.map +1 -1
  8. package/dist/providers/learnworlds/actions/attach-tags.action.d.ts +26 -0
  9. package/dist/providers/learnworlds/actions/attach-tags.action.d.ts.map +1 -0
  10. package/dist/providers/learnworlds/actions/attach-tags.action.js +79 -0
  11. package/dist/providers/learnworlds/actions/attach-tags.action.js.map +1 -0
  12. package/dist/providers/learnworlds/actions/create-user.action.d.ts +24 -1
  13. package/dist/providers/learnworlds/actions/create-user.action.d.ts.map +1 -1
  14. package/dist/providers/learnworlds/actions/create-user.action.js +166 -142
  15. package/dist/providers/learnworlds/actions/create-user.action.js.map +1 -1
  16. package/dist/providers/learnworlds/actions/detach-tags.action.d.ts +26 -0
  17. package/dist/providers/learnworlds/actions/detach-tags.action.d.ts.map +1 -0
  18. package/dist/providers/learnworlds/actions/detach-tags.action.js +79 -0
  19. package/dist/providers/learnworlds/actions/detach-tags.action.js.map +1 -0
  20. package/dist/providers/learnworlds/actions/enroll-user.action.d.ts +31 -3
  21. package/dist/providers/learnworlds/actions/enroll-user.action.d.ts.map +1 -1
  22. package/dist/providers/learnworlds/actions/enroll-user.action.js +179 -125
  23. package/dist/providers/learnworlds/actions/enroll-user.action.js.map +1 -1
  24. package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts +79 -0
  25. package/dist/providers/learnworlds/actions/get-bulk-data.action.d.ts.map +1 -0
  26. package/dist/providers/learnworlds/actions/get-bulk-data.action.js +359 -0
  27. package/dist/providers/learnworlds/actions/get-bulk-data.action.js.map +1 -0
  28. package/dist/providers/learnworlds/actions/get-bundles.action.d.ts +34 -0
  29. package/dist/providers/learnworlds/actions/get-bundles.action.d.ts.map +1 -0
  30. package/dist/providers/learnworlds/actions/get-bundles.action.js +107 -0
  31. package/dist/providers/learnworlds/actions/get-bundles.action.js.map +1 -0
  32. package/dist/providers/learnworlds/actions/get-certificates.action.d.ts +33 -2
  33. package/dist/providers/learnworlds/actions/get-certificates.action.d.ts.map +1 -1
  34. package/dist/providers/learnworlds/actions/get-certificates.action.js +311 -244
  35. package/dist/providers/learnworlds/actions/get-certificates.action.js.map +1 -1
  36. package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts +14 -14
  37. package/dist/providers/learnworlds/actions/get-course-analytics.action.d.ts.map +1 -1
  38. package/dist/providers/learnworlds/actions/get-course-analytics.action.js +234 -226
  39. package/dist/providers/learnworlds/actions/get-course-analytics.action.js.map +1 -1
  40. package/dist/providers/learnworlds/actions/get-course-details.action.d.ts +42 -6
  41. package/dist/providers/learnworlds/actions/get-course-details.action.d.ts.map +1 -1
  42. package/dist/providers/learnworlds/actions/get-course-details.action.js +182 -148
  43. package/dist/providers/learnworlds/actions/get-course-details.action.js.map +1 -1
  44. package/dist/providers/learnworlds/actions/get-courses.action.d.ts +29 -82
  45. package/dist/providers/learnworlds/actions/get-courses.action.d.ts.map +1 -1
  46. package/dist/providers/learnworlds/actions/get-courses.action.js +188 -207
  47. package/dist/providers/learnworlds/actions/get-courses.action.js.map +1 -1
  48. package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts +22 -2
  49. package/dist/providers/learnworlds/actions/get-quiz-results.action.d.ts.map +1 -1
  50. package/dist/providers/learnworlds/actions/get-quiz-results.action.js +316 -294
  51. package/dist/providers/learnworlds/actions/get-quiz-results.action.js.map +1 -1
  52. package/dist/providers/learnworlds/actions/get-user-details.action.d.ts +23 -59
  53. package/dist/providers/learnworlds/actions/get-user-details.action.d.ts.map +1 -1
  54. package/dist/providers/learnworlds/actions/get-user-details.action.js +113 -114
  55. package/dist/providers/learnworlds/actions/get-user-details.action.js.map +1 -1
  56. package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts +43 -5
  57. package/dist/providers/learnworlds/actions/get-user-enrollments.action.d.ts.map +1 -1
  58. package/dist/providers/learnworlds/actions/get-user-enrollments.action.js +191 -147
  59. package/dist/providers/learnworlds/actions/get-user-enrollments.action.js.map +1 -1
  60. package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts +21 -92
  61. package/dist/providers/learnworlds/actions/get-user-progress.action.d.ts.map +1 -1
  62. package/dist/providers/learnworlds/actions/get-user-progress.action.js +145 -166
  63. package/dist/providers/learnworlds/actions/get-user-progress.action.js.map +1 -1
  64. package/dist/providers/learnworlds/actions/get-users.action.d.ts +14 -28
  65. package/dist/providers/learnworlds/actions/get-users.action.d.ts.map +1 -1
  66. package/dist/providers/learnworlds/actions/get-users.action.js +122 -143
  67. package/dist/providers/learnworlds/actions/get-users.action.js.map +1 -1
  68. package/dist/providers/learnworlds/actions/index.d.ts +7 -0
  69. package/dist/providers/learnworlds/actions/index.d.ts.map +1 -1
  70. package/dist/providers/learnworlds/actions/index.js +7 -0
  71. package/dist/providers/learnworlds/actions/index.js.map +1 -1
  72. package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts +53 -0
  73. package/dist/providers/learnworlds/actions/onboard-learner.action.d.ts.map +1 -0
  74. package/dist/providers/learnworlds/actions/onboard-learner.action.js +236 -0
  75. package/dist/providers/learnworlds/actions/onboard-learner.action.js.map +1 -0
  76. package/dist/providers/learnworlds/actions/sso-login.action.d.ts +35 -0
  77. package/dist/providers/learnworlds/actions/sso-login.action.d.ts.map +1 -0
  78. package/dist/providers/learnworlds/actions/sso-login.action.js +101 -0
  79. package/dist/providers/learnworlds/actions/sso-login.action.js.map +1 -0
  80. package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts +12 -1
  81. package/dist/providers/learnworlds/actions/update-user-progress.action.d.ts.map +1 -1
  82. package/dist/providers/learnworlds/actions/update-user-progress.action.js +167 -210
  83. package/dist/providers/learnworlds/actions/update-user-progress.action.js.map +1 -1
  84. package/dist/providers/learnworlds/actions/update-user.action.d.ts +39 -0
  85. package/dist/providers/learnworlds/actions/update-user.action.d.ts.map +1 -0
  86. package/dist/providers/learnworlds/actions/update-user.action.js +168 -0
  87. package/dist/providers/learnworlds/actions/update-user.action.js.map +1 -0
  88. package/dist/providers/learnworlds/index.d.ts +1 -0
  89. package/dist/providers/learnworlds/index.d.ts.map +1 -1
  90. package/dist/providers/learnworlds/index.js +2 -0
  91. package/dist/providers/learnworlds/index.js.map +1 -1
  92. package/dist/providers/learnworlds/interfaces/bundle.types.d.ts +16 -0
  93. package/dist/providers/learnworlds/interfaces/bundle.types.d.ts.map +1 -0
  94. package/dist/providers/learnworlds/interfaces/bundle.types.js +2 -0
  95. package/dist/providers/learnworlds/interfaces/bundle.types.js.map +1 -0
  96. package/dist/providers/learnworlds/interfaces/certificate.types.d.ts +66 -0
  97. package/dist/providers/learnworlds/interfaces/certificate.types.d.ts.map +1 -0
  98. package/dist/providers/learnworlds/interfaces/certificate.types.js +2 -0
  99. package/dist/providers/learnworlds/interfaces/certificate.types.js.map +1 -0
  100. package/dist/providers/learnworlds/interfaces/common.types.d.ts +221 -0
  101. package/dist/providers/learnworlds/interfaces/common.types.d.ts.map +1 -0
  102. package/dist/providers/learnworlds/interfaces/common.types.js +2 -0
  103. package/dist/providers/learnworlds/interfaces/common.types.js.map +1 -0
  104. package/dist/providers/learnworlds/interfaces/course.types.d.ts +393 -0
  105. package/dist/providers/learnworlds/interfaces/course.types.d.ts.map +1 -0
  106. package/dist/providers/learnworlds/interfaces/course.types.js +2 -0
  107. package/dist/providers/learnworlds/interfaces/course.types.js.map +1 -0
  108. package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts +165 -0
  109. package/dist/providers/learnworlds/interfaces/enrollment.types.d.ts.map +1 -0
  110. package/dist/providers/learnworlds/interfaces/enrollment.types.js +2 -0
  111. package/dist/providers/learnworlds/interfaces/enrollment.types.js.map +1 -0
  112. package/dist/providers/learnworlds/interfaces/index.d.ts +12 -0
  113. package/dist/providers/learnworlds/interfaces/index.d.ts.map +1 -0
  114. package/dist/providers/learnworlds/interfaces/index.js +13 -0
  115. package/dist/providers/learnworlds/interfaces/index.js.map +1 -0
  116. package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts +39 -0
  117. package/dist/providers/learnworlds/interfaces/onboarding.types.d.ts.map +1 -0
  118. package/dist/providers/learnworlds/interfaces/onboarding.types.js +2 -0
  119. package/dist/providers/learnworlds/interfaces/onboarding.types.js.map +1 -0
  120. package/dist/providers/learnworlds/interfaces/quiz.types.d.ts +108 -0
  121. package/dist/providers/learnworlds/interfaces/quiz.types.d.ts.map +1 -0
  122. package/dist/providers/learnworlds/interfaces/quiz.types.js +2 -0
  123. package/dist/providers/learnworlds/interfaces/quiz.types.js.map +1 -0
  124. package/dist/providers/learnworlds/interfaces/sso.types.d.ts +18 -0
  125. package/dist/providers/learnworlds/interfaces/sso.types.d.ts.map +1 -0
  126. package/dist/providers/learnworlds/interfaces/sso.types.js +2 -0
  127. package/dist/providers/learnworlds/interfaces/sso.types.js.map +1 -0
  128. package/dist/providers/learnworlds/interfaces/sync.types.d.ts +44 -0
  129. package/dist/providers/learnworlds/interfaces/sync.types.d.ts.map +1 -0
  130. package/dist/providers/learnworlds/interfaces/sync.types.js +2 -0
  131. package/dist/providers/learnworlds/interfaces/sync.types.js.map +1 -0
  132. package/dist/providers/learnworlds/interfaces/tag.types.d.ts +17 -0
  133. package/dist/providers/learnworlds/interfaces/tag.types.d.ts.map +1 -0
  134. package/dist/providers/learnworlds/interfaces/tag.types.js +2 -0
  135. package/dist/providers/learnworlds/interfaces/tag.types.js.map +1 -0
  136. package/dist/providers/learnworlds/interfaces/user.types.d.ts +198 -0
  137. package/dist/providers/learnworlds/interfaces/user.types.d.ts.map +1 -0
  138. package/dist/providers/learnworlds/interfaces/user.types.js +2 -0
  139. package/dist/providers/learnworlds/interfaces/user.types.js.map +1 -0
  140. package/dist/providers/learnworlds/learnworlds-base.action.d.ts +111 -7
  141. package/dist/providers/learnworlds/learnworlds-base.action.d.ts.map +1 -1
  142. package/dist/providers/learnworlds/learnworlds-base.action.js +293 -56
  143. package/dist/providers/learnworlds/learnworlds-base.action.js.map +1 -1
  144. package/package.json +8 -7
  145. package/src/__tests__/attach-tags.action.test.ts +137 -0
  146. package/src/__tests__/create-user.action.test.ts +311 -0
  147. package/src/__tests__/detach-tags.action.test.ts +136 -0
  148. package/src/__tests__/enroll-user.action.test.ts +283 -0
  149. package/src/__tests__/get-bulk-data.action.test.ts +649 -0
  150. package/src/__tests__/get-bundles.action.test.ts +215 -0
  151. package/src/__tests__/lms.test.ts +275 -184
  152. package/src/__tests__/onboard-learner.action.test.ts +455 -0
  153. package/src/__tests__/sso-login.action.test.ts +256 -0
  154. package/src/__tests__/update-user.action.test.ts +350 -0
  155. package/src/base/base-lms.action.ts +226 -163
  156. package/src/providers/learnworlds/actions/attach-tags.action.ts +90 -0
  157. package/src/providers/learnworlds/actions/create-user.action.ts +291 -235
  158. package/src/providers/learnworlds/actions/detach-tags.action.ts +90 -0
  159. package/src/providers/learnworlds/actions/enroll-user.action.ts +326 -220
  160. package/src/providers/learnworlds/actions/get-bulk-data.action.ts +438 -0
  161. package/src/providers/learnworlds/actions/get-bundles.action.ts +139 -0
  162. package/src/providers/learnworlds/actions/get-certificates.action.ts +499 -309
  163. package/src/providers/learnworlds/actions/get-course-analytics.action.ts +470 -337
  164. package/src/providers/learnworlds/actions/get-course-details.action.ts +395 -249
  165. package/src/providers/learnworlds/actions/get-courses.action.ts +508 -565
  166. package/src/providers/learnworlds/actions/get-quiz-results.action.ts +606 -381
  167. package/src/providers/learnworlds/actions/get-user-details.action.ts +335 -349
  168. package/src/providers/learnworlds/actions/get-user-enrollments.action.ts +328 -228
  169. package/src/providers/learnworlds/actions/get-user-progress.action.ts +522 -571
  170. package/src/providers/learnworlds/actions/get-users.action.ts +231 -282
  171. package/src/providers/learnworlds/actions/index.ts +8 -1
  172. package/src/providers/learnworlds/actions/onboard-learner.action.ts +286 -0
  173. package/src/providers/learnworlds/actions/sso-login.action.ts +116 -0
  174. package/src/providers/learnworlds/actions/update-user-progress.action.ts +301 -263
  175. package/src/providers/learnworlds/actions/update-user.action.ts +181 -0
  176. package/src/providers/learnworlds/index.ts +4 -1
  177. package/src/providers/learnworlds/interfaces/bundle.types.ts +17 -0
  178. package/src/providers/learnworlds/interfaces/certificate.types.ts +69 -0
  179. package/src/providers/learnworlds/interfaces/common.types.ts +233 -0
  180. package/src/providers/learnworlds/interfaces/course.types.ts +411 -0
  181. package/src/providers/learnworlds/interfaces/enrollment.types.ts +176 -0
  182. package/src/providers/learnworlds/interfaces/index.ts +12 -0
  183. package/src/providers/learnworlds/interfaces/onboarding.types.ts +41 -0
  184. package/src/providers/learnworlds/interfaces/quiz.types.ts +118 -0
  185. package/src/providers/learnworlds/interfaces/sso.types.ts +19 -0
  186. package/src/providers/learnworlds/interfaces/sync.types.ts +46 -0
  187. package/src/providers/learnworlds/interfaces/tag.types.ts +18 -0
  188. package/src/providers/learnworlds/interfaces/user.types.ts +204 -0
  189. package/src/providers/learnworlds/learnworlds-base.action.ts +468 -210
  190. package/tsconfig.json +1 -1
  191. package/dist/__tests__/lms.test.d.ts +0 -2
  192. package/dist/__tests__/lms.test.d.ts.map +0 -1
  193. package/dist/__tests__/lms.test.js +0 -232
  194. package/dist/__tests__/lms.test.js.map +0 -1
@@ -0,0 +1,845 @@
1
+ # LearnWorlds Sidecar Integration Plan
2
+
3
+ ## Executive Summary
4
+
5
+ This document details the plan for building a "sidecar" integration with LearnWorlds (LW) where MemberJunction (MJ) owns the checkout and authentication flow, and LearnWorlds serves as the course delivery platform. The two primary objectives are:
6
+
7
+ 1. **Onboarding Flow**: Stripe checkout → Auth0 account creation → LW user provisioning + enrollment → immediate redirect into LW (no password-reset email)
8
+ 2. **Data Retrieval Actions**: Actions that pull learner progress, enrollment status, certificates, and other data from LW — consumers handle their own DB storage, scheduling, and mapping
9
+
10
+ ---
11
+
12
+ ## Part 1: Onboarding Flow
13
+
14
+ ### 1.1 End-to-End User Journey
15
+
16
+ ```
17
+ ┌─────────────────────────────────────────────────────────────────────────┐
18
+ │ USER JOURNEY │
19
+ │ │
20
+ │ 1. User lands on signup/purchase page │
21
+ │ 2. Stripe Checkout form collects payment + email │
22
+ │ 3. Stripe payment succeeds │
23
+ │ 4. Same page transitions to Auth0 login widget (inline, not redirect) │
24
+ │ └─ If user already has Auth0 account → they log in │
25
+ │ └─ If new user → they create Auth0 account (email prefilled) │
26
+ │ 5. Auth0 callback returns to our app with auth token │
27
+ │ 6. Our app calls backend "Onboard Learner" action │
28
+ │ └─ Backend creates user in LW (if not exists) │
29
+ │ └─ Backend enrolls user in purchased course(s)/bundle(s) │
30
+ │ └─ Backend generates SSO login URL from LW │
31
+ │ 7. User is immediately redirected to LW school (auto-logged in) │
32
+ │ │
33
+ └─────────────────────────────────────────────────────────────────────────┘
34
+ ```
35
+
36
+ ### 1.2 Why This Flow (vs. Password Reset Email)
37
+
38
+ The password-reset-email approach has several problems:
39
+ - **Friction**: User has to check email, click link, set password, then log in — multiple steps where they can drop off
40
+ - **Deliverability**: Emails can land in spam, be delayed, or get blocked by corporate filters
41
+ - **Timing**: User just paid and is motivated NOW — making them wait kills momentum
42
+ - **Clunkiness**: LW's password-reset flow is designed for forgotten-password scenarios, not onboarding
43
+
44
+ The Auth0 widget approach solves all of these:
45
+ - **Immediate access**: User creates account and is redirected to LW in one smooth flow
46
+ - **Auth0 is already our IdP**: We use Auth0 for SSO with LW, so the infrastructure exists
47
+ - **Binding is clean**: Auth0 account ↔ Stripe transaction ↔ LW user are all linked by email
48
+ - **No LW auth dependency**: We never rely on LW's own authentication — Auth0 is the single source of truth
49
+
50
+ ### 1.3 Architecture Decision: Action with Strongly-Typed Class Composition
51
+
52
+ The onboarding orchestration is built as an **Action** that directly instantiates other action classes and calls their **strongly-typed public methods** (not via the Action execution interface). This gives us:
53
+
54
+ - **Agent/workflow discoverability**: It's a registered Action, so agents can find and invoke it, and it can be scheduled
55
+ - **Type safety**: Direct class instantiation with typed method signatures, not serialized params
56
+ - **Code reuse**: The individual action classes (CreateUser, EnrollUser, SSO) are both standalone Actions AND reusable building blocks
57
+ - **No rule violation**: We're not calling actions through the Action interface — we're using classes directly
58
+
59
+ **The refactor pattern** applied to all existing and new action classes:
60
+
61
+ ```typescript
62
+ // Each action class exposes a strongly-typed public method
63
+ // alongside the InternalRunAction entry point
64
+
65
+ class CreateUserAction extends LearnWorldsBaseAction {
66
+ /** Strongly-typed, directly callable by other code */
67
+ public async CreateUser(params: CreateUserParams, contextUser: UserInfo): Promise<CreateUserResult> {
68
+ // Core logic with typed params and result
69
+ }
70
+
71
+ /** Action framework entry point — maps untyped params to typed method */
72
+ protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
73
+ const typed = this.extractParams(params.Params);
74
+ const result = await this.CreateUser(typed, params.ContextUser);
75
+ return this.mapToActionResult(result);
76
+ }
77
+ }
78
+
79
+ // Onboarding action instantiates classes directly and calls typed methods
80
+ class OnboardLearnerAction extends LearnWorldsBaseAction {
81
+ public async OnboardLearner(params: OnboardLearnerParams, contextUser: UserInfo): Promise<OnboardResult> {
82
+ const createAction = new CreateUserAction();
83
+ const lwUser = await createAction.CreateUser({ Email: params.Email, ... }, contextUser);
84
+
85
+ const enrollAction = new EnrollUserAction();
86
+ await enrollAction.EnrollUser({ UserId: lwUser.Id, ... }, contextUser);
87
+
88
+ const ssoAction = new SSOLoginAction();
89
+ const ssoResult = await ssoAction.GenerateSSOUrl({ Email: params.Email, ... }, contextUser);
90
+
91
+ return { LoginURL: ssoResult.Url, ... };
92
+ }
93
+
94
+ protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
95
+ const typed = this.extractParams(params.Params);
96
+ const result = await this.OnboardLearner(typed, params.ContextUser);
97
+ return this.mapToActionResult(result);
98
+ }
99
+ }
100
+ ```
101
+
102
+ ### 1.4 Detailed Onboarding Flow — Technical Sequence
103
+
104
+ ```
105
+ Frontend (Angular Element Widget) Backend (MJAPI) External Services
106
+ ───────────────────────────────── ─────────────── ─────────────────
107
+
108
+ 1. Embedded Angular Element shows
109
+ Stripe Checkout form
110
+ ─── Stripe.js ───────────────────────────────────────────────────── Stripe
111
+ Payment succeeds
112
+ Stripe returns payment_intent.id
113
+ and customer email
114
+
115
+ 2. Widget seamlessly transitions to
116
+ Auth0 login/signup (inline, same widget)
117
+ (email prefilled from Stripe)
118
+ ─── Auth0 SDK ──────────────────────────────────────────────────── Auth0
119
+ User logs in OR creates account
120
+ Auth0 returns ID token + user info
121
+
122
+ 3. Widget calls backend
123
+ POST /api/onboard-learner
124
+ {
125
+ email,
126
+ firstName, lastName,
127
+ courseIds[], ← caller provides LW course/bundle IDs
128
+ bundleIds[], ← optional LW bundle IDs
129
+ redirectTo
130
+ }
131
+ 4. Create/find LW user
132
+ ─── LW API ─────────────────── LearnWorlds
133
+ POST /v2/users (if new)
134
+ GET /v2/users?email= (if exists)
135
+
136
+ 5. Enroll in course(s) and/or bundle(s)
137
+ ─── LW API ─────────────────── LearnWorlds
138
+ POST /v2/enrollments (product_type: course|bundle)
139
+
140
+ 6. Generate SSO login URL
141
+ ─── LW API ─────────────────── LearnWorlds
142
+ POST /v2/sso
143
+ { email, redirect_to: course_url }
144
+ Returns: { url, user_id }
145
+
146
+ 7. Return SSO URL to frontend
147
+
148
+ 8. window.location.href = ssoUrl
149
+ User lands in LW, auto-logged in,
150
+ on the course they purchased
151
+ ```
152
+
153
+ ### 1.5 Course/Bundle Mapping — Consumer Responsibility
154
+
155
+ The onboarding action accepts LW course IDs and/or LW bundle IDs directly. **The mapping from a Stripe product/purchase to specific LW course/bundle IDs is the consumer's responsibility**, not this package's.
156
+
157
+ - The action's `CourseIds` and `BundleIds` input parameters take LW-native identifiers
158
+ - Each MJ instance consumer (e.g., BC CDP) maintains their own mapping logic
159
+ - This keeps the LMS package generic and reusable across different deployments
160
+ - LearnWorlds bundles ARE a real API concept — the enrollment endpoint (`POST /v2/enrollments`) accepts `product_type: "course"` or `product_type: "bundle"` (bundles map to "Learning Programs" in LW's new platform version)
161
+
162
+ ### 1.6 New Components to Build
163
+
164
+ #### 1.6.1 SSO Login Action (`sso-login.action.ts`)
165
+
166
+ **LW API Endpoint**: `POST /v2/sso`
167
+
168
+ ```typescript
169
+ // Strongly-typed public method
170
+ public async GenerateSSOUrl(params: SSOLoginParams, contextUser: UserInfo): Promise<SSOLoginResult> { ... }
171
+
172
+ // Types
173
+ interface SSOLoginParams {
174
+ CompanyID: string;
175
+ Email?: string; // Use email OR UserID
176
+ UserID?: string;
177
+ RedirectTo?: string; // URL to land on after login
178
+ }
179
+
180
+ interface SSOLoginResult {
181
+ LoginURL: string;
182
+ LearnWorldsUserID: string;
183
+ }
184
+ ```
185
+
186
+ #### 1.6.2 Update User Action (`update-user.action.ts`)
187
+
188
+ **LW API Endpoint**: `PUT /v2/users/{userId}`
189
+
190
+ ```typescript
191
+ public async UpdateUser(params: UpdateUserParams, contextUser: UserInfo): Promise<UpdateUserResult> { ... }
192
+
193
+ interface UpdateUserParams {
194
+ CompanyID: string;
195
+ UserID: string; // LW user ID
196
+ Email?: string;
197
+ FirstName?: string;
198
+ LastName?: string;
199
+ Username?: string;
200
+ Role?: string;
201
+ IsActive?: boolean;
202
+ Tags?: string[];
203
+ CustomFields?: Record<string, string>;
204
+ }
205
+ ```
206
+
207
+ #### 1.6.3 Tag Management Actions
208
+
209
+ **LW API Endpoints**: `POST /v2/users/{userId}/tags`, `DELETE /v2/users/{userId}/tags`
210
+
211
+ ```typescript
212
+ public async AttachTags(params: TagParams, contextUser: UserInfo): Promise<TagResult> { ... }
213
+ public async DetachTags(params: TagParams, contextUser: UserInfo): Promise<TagResult> { ... }
214
+
215
+ interface TagParams {
216
+ CompanyID: string;
217
+ UserID: string;
218
+ Tags: string[];
219
+ }
220
+ ```
221
+
222
+ #### 1.6.4 Onboard Learner Action (`onboard-learner.action.ts`)
223
+
224
+ The orchestration action — callable by agents, schedulable, AND used directly by the REST endpoint:
225
+
226
+ ```typescript
227
+ @RegisterClass(BaseAction, 'OnboardLearnerAction')
228
+ export class OnboardLearnerAction extends LearnWorldsBaseAction {
229
+ /**
230
+ * Strongly-typed onboarding method:
231
+ * 1. Find or create LW user
232
+ * 2. Enroll in purchased courses/bundles
233
+ * 3. Generate SSO login URL
234
+ */
235
+ public async OnboardLearner(
236
+ params: OnboardLearnerParams,
237
+ contextUser: UserInfo
238
+ ): Promise<OnboardLearnerResult> {
239
+ // Instantiate action classes directly
240
+ const createUserAction = new CreateUserAction();
241
+ const enrollAction = new EnrollUserAction();
242
+ const ssoAction = new SSOLoginAction();
243
+
244
+ // Step 1: Find or create user
245
+ let lwUser: CreateUserResult;
246
+ const existingUser = await this.findUserByEmail(params.Email, contextUser);
247
+ if (existingUser) {
248
+ lwUser = existingUser;
249
+ } else {
250
+ lwUser = await createUserAction.CreateUser({
251
+ CompanyID: params.CompanyID,
252
+ Email: params.Email,
253
+ FirstName: params.FirstName,
254
+ LastName: params.LastName,
255
+ SendWelcomeEmail: false // We handle auth via Auth0
256
+ }, contextUser);
257
+ }
258
+
259
+ // Step 2: Enroll in courses
260
+ const enrollments = [];
261
+ for (const courseId of (params.CourseIds || [])) {
262
+ const enrollment = await enrollAction.EnrollUser({
263
+ CompanyID: params.CompanyID,
264
+ UserId: lwUser.UserId,
265
+ CourseId: courseId,
266
+ ProductType: 'course'
267
+ }, contextUser);
268
+ enrollments.push(enrollment);
269
+ }
270
+
271
+ // Step 2b: Enroll in bundles
272
+ for (const bundleId of (params.BundleIds || [])) {
273
+ const enrollment = await enrollAction.EnrollUser({
274
+ CompanyID: params.CompanyID,
275
+ UserId: lwUser.UserId,
276
+ CourseId: bundleId,
277
+ ProductType: 'bundle'
278
+ }, contextUser);
279
+ enrollments.push(enrollment);
280
+ }
281
+
282
+ // Step 3: Generate SSO URL
283
+ const ssoResult = await ssoAction.GenerateSSOUrl({
284
+ CompanyID: params.CompanyID,
285
+ Email: params.Email,
286
+ RedirectTo: params.RedirectTo
287
+ }, contextUser);
288
+
289
+ return {
290
+ Success: true,
291
+ LoginURL: ssoResult.LoginURL,
292
+ LearnWorldsUserId: lwUser.UserId,
293
+ Enrollments: enrollments
294
+ };
295
+ }
296
+
297
+ /** Action framework entry point */
298
+ protected async InternalRunAction(params: RunActionParams): Promise<ActionResultSimple> {
299
+ const typed = this.extractOnboardParams(params.Params);
300
+ const result = await this.OnboardLearner(typed, params.ContextUser);
301
+ return this.mapToActionResult(result);
302
+ }
303
+ }
304
+ ```
305
+
306
+ #### 1.6.5 Typed Interfaces (Exported for Consumers)
307
+
308
+ ```typescript
309
+ // Published in package exports for TypeScript consumers
310
+
311
+ export interface OnboardLearnerParams {
312
+ CompanyID: string;
313
+ Email: string;
314
+ FirstName?: string;
315
+ LastName?: string;
316
+ CourseIds?: string[]; // LW course IDs
317
+ BundleIds?: string[]; // LW bundle IDs (Learning Programs)
318
+ RedirectTo?: string; // Where to land in LW after login
319
+ }
320
+
321
+ export interface OnboardLearnerResult {
322
+ Success: boolean;
323
+ LoginURL: string;
324
+ LearnWorldsUserId: string;
325
+ Enrollments: EnrollmentResult[];
326
+ ErrorMessage?: string;
327
+ }
328
+ ```
329
+
330
+ #### 1.6.6 REST Endpoint for Frontend Widget
331
+
332
+ ```typescript
333
+ // Custom REST endpoint in MJAPI for the Angular Element widget to call
334
+ // POST /api/onboard-learner
335
+ app.post('/api/onboard-learner', authenticateJWT, async (req, res) => {
336
+ const { courseIds, bundleIds, redirectTo } = req.body;
337
+ const contextUser = req.user; // From Auth0 JWT
338
+
339
+ const action = new OnboardLearnerAction();
340
+ const result = await action.OnboardLearner({
341
+ CompanyID: resolveCompanyId(contextUser),
342
+ Email: contextUser.Email,
343
+ FirstName: contextUser.FirstName,
344
+ LastName: contextUser.LastName,
345
+ CourseIds: courseIds,
346
+ BundleIds: bundleIds,
347
+ RedirectTo: redirectTo
348
+ }, contextUser);
349
+
350
+ res.json({
351
+ success: result.Success,
352
+ loginUrl: result.LoginURL,
353
+ enrollments: result.Enrollments
354
+ });
355
+ });
356
+ ```
357
+
358
+ ### 1.7 Frontend: Angular Element Checkout Widget
359
+
360
+ The checkout experience is built as a **custom Angular Element** (Web Component) that can be dropped into any website. It seamlessly transitions from Stripe checkout to Auth0 login within the same widget — no page redirects, no jarring context switches.
361
+
362
+ This is a separate deliverable built by consumers (e.g., BC CDP) but the LMS package provides the backend actions it calls. The widget would:
363
+
364
+ 1. **Step 1 — Stripe**: Embed Stripe Elements form for payment collection
365
+ 2. **Step 2 — Auth0**: On payment success, transition to inline Auth0 login/signup (email prefilled from Stripe)
366
+ 3. **Step 3 — Onboard**: After Auth0 login, call `POST /api/onboard-learner` with course/bundle IDs
367
+ 4. **Step 4 — Redirect**: On success, `window.location.href = loginUrl` to send user to LW
368
+
369
+ ### 1.8 Edge Cases and Error Handling
370
+
371
+ | Scenario | Handling |
372
+ |----------|----------|
373
+ | **User already exists in LW** | `findUserByEmail` finds them; skip creation, proceed to enrollment + SSO |
374
+ | **User already enrolled** | LW API returns enrollment details; skip re-enrollment, proceed to SSO |
375
+ | **LW user creation fails** | Return error with details; payment is still valid (can retry) |
376
+ | **SSO URL generation fails** | Fall back to LW's `login_url` from user creation response |
377
+ | **Auth0 account exists but LW doesn't** | Normal flow — create LW user, enroll, generate SSO |
378
+ | **User closes browser after Stripe, before Auth0** | Payment exists but no LW user; consumer handles reconciliation |
379
+ | **LW API rate limiting** | Exponential backoff retry in `makeLearnWorldsRequest`; surface error if exhausted |
380
+
381
+ ---
382
+
383
+ ## Part 2: Data Retrieval Actions
384
+
385
+ ### 2.1 Design Philosophy
386
+
387
+ The LMS package provides **actions that retrieve data from LearnWorlds and return strongly-typed JSON payloads**. The package does NOT:
388
+ - Define database entities for storing LW data
389
+ - Handle scheduling of sync jobs
390
+ - Map LW data to local database schemas
391
+
392
+ These are all **consumer responsibilities**. Each MJ instance (e.g., BC CDP) decides:
393
+ - Which data to pull and how often
394
+ - What local tables/entities to store it in
395
+ - How to schedule the sync (via MJ's ScheduledJob infrastructure)
396
+ - How to map LW data structures to their own schemas
397
+
398
+ ### 2.2 What the Package Provides
399
+
400
+ #### Existing Retrieval Actions (Already Built)
401
+ - `GetLearnWorldsUsersAction` — list/search users with filters
402
+ - `GetLearnWorldsUserDetailsAction` — comprehensive user profile
403
+ - `GetLearnWorldsUserProgressAction` — learning progress across courses
404
+ - `GetLearnWorldsCoursesAction` — course catalog
405
+ - `GetLearnWorldsCourseDetailsAction` — full course info with curriculum
406
+ - `GetLearnWorldsUserEnrollmentsAction` — user's enrollments with progress
407
+ - `GetCourseAnalyticsAction` — course performance analytics
408
+ - `GetQuizResultsAction` — quiz/assessment results
409
+ - `GetCertificatesAction` — earned certificates
410
+
411
+ #### New Retrieval Action
412
+ - `GetLearnWorldsBundlesAction` — list bundles/learning programs (`GET /v2/bundles`)
413
+
414
+ #### Exported TypeScript Interfaces for Consumers
415
+
416
+ The package exports strongly-typed interfaces that consumers can use when processing action results in TypeScript:
417
+
418
+ ```typescript
419
+ // Consumers import these for type-safe processing of action output
420
+ export interface LearnWorldsUser {
421
+ Id: string;
422
+ Email: string;
423
+ Username: string;
424
+ FirstName: string;
425
+ LastName: string;
426
+ Status: 'active' | 'inactive' | 'suspended';
427
+ Role: 'student' | 'instructor' | 'admin';
428
+ Tags: string[];
429
+ CustomFields: Record<string, string>;
430
+ CreatedAt: string;
431
+ LastLoginAt: string;
432
+ LastActivityAt: string;
433
+ TotalCertificates: number;
434
+ Points: number;
435
+ }
436
+
437
+ export interface LearnWorldsEnrollment {
438
+ Id: string;
439
+ CourseId: string;
440
+ UserId: string;
441
+ Status: 'active' | 'completed' | 'expired' | 'suspended';
442
+ EnrolledAt: string;
443
+ CompletedAt: string | null;
444
+ ProgressPercentage: number;
445
+ CompletedLessons: number;
446
+ TotalLessons: number;
447
+ TotalTimeSpent: number;
448
+ Grade: number | null;
449
+ CertificateEligible: boolean;
450
+ CertificateIssuedAt: string | null;
451
+ }
452
+
453
+ export interface LearnWorldsCourse {
454
+ Id: string;
455
+ Title: string;
456
+ Description: string;
457
+ Status: 'draft' | 'published' | 'archived';
458
+ Price: number;
459
+ Currency: string;
460
+ IsFree: boolean;
461
+ Duration: number;
462
+ TotalEnrollments: number;
463
+ CertificateEnabled: boolean;
464
+ }
465
+
466
+ export interface LearnWorldsBundle {
467
+ Id: string;
468
+ Title: string;
469
+ Description: string;
470
+ Price: number;
471
+ Currency: string;
472
+ CourseIds: string[];
473
+ Status: string;
474
+ }
475
+
476
+ export interface LearnWorldsCourseProgress {
477
+ UserId: string;
478
+ CourseId: string;
479
+ ProgressPercentage: number;
480
+ CompletedLessons: number;
481
+ TotalLessons: number;
482
+ CompletedUnits: number;
483
+ TotalUnits: number;
484
+ TotalTimeSpent: number;
485
+ QuizScoreAverage: number | null;
486
+ LastAccessedAt: string;
487
+ }
488
+
489
+ export interface LearnWorldsCertificate {
490
+ Id: string;
491
+ UserId: string;
492
+ CourseId: string;
493
+ IssuedAt: string;
494
+ ExpiresAt: string | null;
495
+ CertificateURL: string;
496
+ VerificationCode: string;
497
+ VerificationURL: string;
498
+ }
499
+
500
+ // Sync result types for consumers building sync services
501
+ export interface LearnWorldsSyncPayload {
502
+ Users: LearnWorldsUser[];
503
+ Courses: LearnWorldsCourse[];
504
+ Bundles: LearnWorldsBundle[];
505
+ Enrollments: LearnWorldsEnrollment[];
506
+ Progress: LearnWorldsCourseProgress[];
507
+ Certificates: LearnWorldsCertificate[];
508
+ SyncTimestamp: string;
509
+ TotalApiCalls: number;
510
+ Errors: SyncError[];
511
+ }
512
+
513
+ export interface SyncError {
514
+ Entity: string;
515
+ EntityId: string;
516
+ ErrorMessage: string;
517
+ Timestamp: string;
518
+ }
519
+ ```
520
+
521
+ ### 2.3 Consumer-Side Sync Pattern (Example for BC CDP)
522
+
523
+ The consumer (e.g., BC CDP) would build their own sync infrastructure using the LMS package:
524
+
525
+ ```typescript
526
+ // Example consumer-side sync service (NOT in the LMS package)
527
+ import {
528
+ GetLearnWorldsUsersAction,
529
+ GetLearnWorldsUserEnrollmentsAction,
530
+ LearnWorldsUser,
531
+ LearnWorldsEnrollment
532
+ } from '@memberjunction/actions-bizapps-lms';
533
+
534
+ class BCLearnerSyncService {
535
+ async syncFromLearnWorlds() {
536
+ // Use the typed public methods directly
537
+ const getUsersAction = new GetLearnWorldsUsersAction();
538
+ const users = await getUsersAction.GetUsers({
539
+ CompanyID: myCompanyId,
540
+ MaxResults: 1000
541
+ }, contextUser);
542
+
543
+ // Map to local DB entities (consumer's schema)
544
+ for (const lwUser of users.Users) {
545
+ await this.upsertLocalLearnerRecord(lwUser);
546
+ }
547
+ }
548
+ }
549
+ ```
550
+
551
+ The consumer would then schedule this via MJ's `ScheduledJob` infrastructure.
552
+
553
+ ### 2.4 Bulk Data Retrieval Action (New)
554
+
555
+ For consumers who want to pull everything in one call:
556
+
557
+ ```typescript
558
+ @RegisterClass(BaseAction, 'GetLearnWorldsBulkDataAction')
559
+ export class GetLearnWorldsBulkDataAction extends LearnWorldsBaseAction {
560
+ /**
561
+ * Pulls all data types from LW in a single call.
562
+ * Returns a LearnWorldsSyncPayload with all entities.
563
+ * Consumer decides what to do with the data.
564
+ */
565
+ public async GetBulkData(
566
+ params: BulkDataParams,
567
+ contextUser: UserInfo
568
+ ): Promise<LearnWorldsSyncPayload> {
569
+ // Orchestrate all retrieval actions
570
+ const getUsersAction = new GetLearnWorldsUsersAction();
571
+ const getCoursesAction = new GetLearnWorldsCoursesAction();
572
+ // ... etc
573
+
574
+ const users = await getUsersAction.GetUsers({ ... }, contextUser);
575
+ const courses = await getCoursesAction.GetCourses({ ... }, contextUser);
576
+ // ...
577
+
578
+ return {
579
+ Users: users,
580
+ Courses: courses,
581
+ // ...
582
+ SyncTimestamp: new Date().toISOString(),
583
+ TotalApiCalls: totalCalls,
584
+ Errors: errors
585
+ };
586
+ }
587
+ }
588
+ ```
589
+
590
+ ---
591
+
592
+ ## Part 3: Stripe Integration in Core MJ (Separate Workstream)
593
+
594
+ ### 3.1 Current State
595
+
596
+ There is **no Stripe SDK or integration** anywhere in MJ today. The Accounting BizApps package covers Business Central and QuickBooks, but not Stripe.
597
+
598
+ ### 3.2 Two-Part Stripe Integration
599
+
600
+ Stripe is ubiquitous enough to warrant a core MJ integration with both server-side actions (non-visual) and a client-side Angular widget (visual).
601
+
602
+ #### Server-Side: `@memberjunction/actions-bizapps-payments` (new BizApps package)
603
+
604
+ Non-visual integration — actions that agents, workflows, and scheduled jobs can call:
605
+
606
+ ```
607
+ packages/Actions/BizApps/Payments/
608
+ ├── src/
609
+ │ ├── base/
610
+ │ │ └── base-payment.action.ts # Shared payment provider patterns
611
+ │ ├── providers/
612
+ │ │ └── stripe/
613
+ │ │ ├── stripe-base.action.ts # Stripe API auth, common utilities
614
+ │ │ └── actions/
615
+ │ │ ├── verify-payment.action.ts # Verify payment_intent status
616
+ │ │ ├── create-checkout-session.action.ts # Create Stripe Checkout session
617
+ │ │ ├── get-customer.action.ts # Get customer details
618
+ │ │ ├── get-payment-intent.action.ts # Get payment intent details
619
+ │ │ ├── list-subscriptions.action.ts # List customer subscriptions
620
+ │ │ ├── create-payment-link.action.ts # Generate payment links
621
+ │ │ └── list-invoices.action.ts # List customer invoices
622
+ │ ├── interfaces/
623
+ │ │ └── stripe.types.ts # Exported typed interfaces
624
+ │ └── index.ts
625
+ ├── package.json # Depends on `stripe` npm package
626
+ ```
627
+
628
+ Same pattern as LMS — each action exposes a strongly-typed public method alongside `InternalRunAction`. Extensible for future payment providers (PayPal, Square, etc.) via the base class.
629
+
630
+ #### Client-Side: `@memberjunction/ng-stripe` (new Angular/Generic package)
631
+
632
+ Visual integration — an Angular wrapper widget for Stripe Elements:
633
+
634
+ ```
635
+ packages/Angular/Generic/stripe/
636
+ ├── src/lib/
637
+ │ ├── components/
638
+ │ │ ├── stripe-payment-form/ # Wraps Stripe Elements (card, payment)
639
+ │ │ ├── stripe-checkout-button/ # One-click checkout button
640
+ │ │ └── stripe-payment-status/ # Payment confirmation display
641
+ │ ├── services/
642
+ │ │ ├── stripe-config.service.ts # Publishable key management
643
+ │ │ └── stripe-elements.service.ts # Stripe.js SDK lifecycle
644
+ │ ├── types/
645
+ │ │ └── stripe-widget.types.ts
646
+ │ └── module.ts # StripeModule for NgModule consumers
647
+ ├── package.json # Depends on `@stripe/stripe-js`
648
+ ```
649
+
650
+ The widget provides:
651
+ - Drop-in `<mj-stripe-payment-form>` component for embedding in any Angular app or Angular Element
652
+ - Event emitters: `(paymentSuccess)`, `(paymentError)`, `(paymentProcessing)`
653
+ - Configurable via `@Input()` properties: amount, currency, publishable key, payment method types
654
+ - Handles Stripe.js SDK loading and lifecycle
655
+ - Can be combined with auth widgets in a checkout flow
656
+
657
+ ### 3.3 Scope for This Project
658
+
659
+ For the LW sidecar integration, the onboarding action does NOT need Stripe payment verification. The flow is:
660
+ 1. Frontend handles Stripe checkout (via `@memberjunction/ng-stripe` widget or consumer's own Stripe integration)
661
+ 2. Frontend handles Auth0 login
662
+ 3. Frontend calls onboard-learner with LW course/bundle IDs
663
+ 4. Backend only talks to LW — no Stripe server-side calls needed
664
+
665
+ If Stripe server-side verification is desired as an extra safety layer (verifying the payment_intent is actually paid before provisioning), that would be part of the Payments BizApps package and called from the consumer's REST endpoint, not from the LMS package itself.
666
+
667
+ ---
668
+
669
+ ## Part 3b: Generic Auth Widget in Core MJ (Separate Workstream)
670
+
671
+ ### Current State
672
+
673
+ The existing auth integration lives at `packages/Angular/Explorer/auth-services/` and is **tightly coupled to the Explorer app**. It provides Auth0 authentication via `MJAuth0Provider` but is not reusable outside Explorer.
674
+
675
+ ### Recommendation: Generic Auth Package Under `Angular/Generic`
676
+
677
+ Build a provider-agnostic auth widget under `packages/Angular/Generic/` that:
678
+ - Provides embeddable login/signup UI components
679
+ - Supports multiple auth providers (Auth0 initially, extensible to others)
680
+ - Can be used in Angular Elements (Web Components) for embedding in external sites
681
+ - Can be consumed by Explorer (replacing or wrapping the current Explorer-specific auth)
682
+
683
+ #### Proposed Structure
684
+
685
+ ```
686
+ packages/Angular/Generic/auth/
687
+ ├── src/lib/
688
+ │ ├── components/
689
+ │ │ ├── auth-login-widget/ # Embeddable login/signup form
690
+ │ │ ├── auth-status-indicator/ # Shows logged-in state
691
+ │ │ └── auth-profile-menu/ # User profile dropdown
692
+ │ ├── providers/
693
+ │ │ ├── auth-provider.base.ts # Abstract base for auth providers
694
+ │ │ ├── auth0/
695
+ │ │ │ └── auth0-provider.service.ts # Auth0 implementation
696
+ │ │ └── index.ts
697
+ │ ├── services/
698
+ │ │ ├── auth-config.service.ts # Configuration management
699
+ │ │ └── auth-state.service.ts # Observable auth state
700
+ │ ├── types/
701
+ │ │ └── auth.types.ts
702
+ │ └── module.ts # GenericAuthModule
703
+ ├── package.json
704
+ ```
705
+
706
+ #### Key Design Goals
707
+
708
+ - **Provider-agnostic**: The widget components work with any auth provider that implements the base interface
709
+ - **Embeddable**: Works in Angular Elements (Web Components) for embedding in marketing sites, checkout pages, etc.
710
+ - **Email prefill**: The login widget accepts an `email` input to prefill from a prior step (e.g., Stripe checkout)
711
+ - **Event-driven**: Emits `(loginSuccess)`, `(loginError)`, `(signupSuccess)` events
712
+ - **Explorer-compatible**: Explorer's auth can migrate to use this generic package, reducing duplication
713
+
714
+ #### Relationship to the LW Sidecar Checkout Widget
715
+
716
+ The consumer's Angular Element checkout widget (e.g., BC CDP) would compose:
717
+ 1. `<mj-stripe-payment-form>` from `@memberjunction/ng-stripe`
718
+ 2. `<mj-auth-login-widget>` from `@memberjunction/ng-auth` (with email prefilled from Stripe)
719
+ 3. Custom checkout logic that calls the onboarding REST endpoint
720
+ 4. Redirect to LW on success
721
+
722
+ This gives maximum reusability — both widgets are useful independently and together.
723
+
724
+ ---
725
+
726
+ ## Part 4: Implementation Plan
727
+
728
+ ### Phase 1: Refactor Existing Actions + Build New Actions
729
+
730
+ Refactor existing action classes to expose strongly-typed public methods, and build the new actions:
731
+
732
+ | # | Item | File | Details |
733
+ |---|------|------|---------|
734
+ | 1 | Refactor `CreateUserAction` | `create-user.action.ts` | Extract `CreateUser(params, contextUser)` public method |
735
+ | 2 | Refactor `EnrollUserAction` | `enroll-user.action.ts` | Extract `EnrollUser(params, contextUser)` public method; add bundle support via `product_type` |
736
+ | 3 | Refactor all other existing actions | Various | Same pattern: typed public method + thin InternalRunAction |
737
+ | 4 | **NEW**: SSO Login action | `sso-login.action.ts` | `POST /v2/sso` — `GenerateSSOUrl()` |
738
+ | 5 | **NEW**: Update User action | `update-user.action.ts` | `PUT /v2/users/{id}` — `UpdateUser()` |
739
+ | 6 | **NEW**: Attach Tags action | `attach-tags.action.ts` | `POST /v2/users/{id}/tags` — `AttachTags()` |
740
+ | 7 | **NEW**: Detach Tags action | `detach-tags.action.ts` | `DELETE /v2/users/{id}/tags` — `DetachTags()` |
741
+ | 8 | **NEW**: Get Bundles action | `get-bundles.action.ts` | `GET /v2/bundles` — `GetBundles()` |
742
+ | 9 | Export typed interfaces | `interfaces/` | All strongly-typed param/result interfaces |
743
+ | 10 | Action metadata | `.bizapps-actions.json` | Metadata entries for new actions |
744
+ | 11 | Unit tests | `__tests__/` | Tests for all new and refactored actions |
745
+
746
+ ### Phase 2: Onboarding Action
747
+
748
+ | # | Item | Details |
749
+ |---|------|---------|
750
+ | 1 | `OnboardLearnerAction` | Orchestration action with typed `OnboardLearner()` method |
751
+ | 2 | `findUserByEmail` utility | Shared method in base class for user lookup |
752
+ | 3 | Action metadata | Entry in `.bizapps-actions.json` |
753
+ | 4 | Unit tests | Mock LW API calls, test full flow + edge cases |
754
+
755
+ ### Phase 3: Bulk Data Retrieval Action
756
+
757
+ | # | Item | Details |
758
+ |---|------|---------|
759
+ | 1 | `GetLearnWorldsBulkDataAction` | Orchestrates all retrieval actions, returns `LearnWorldsSyncPayload` |
760
+ | 2 | Concurrency control | Limit parallel API calls to avoid LW rate limiting |
761
+ | 3 | Error collection | Partial failures logged in `Errors` array, doesn't abort entire sync |
762
+ | 4 | Action metadata | Entry in `.bizapps-actions.json` |
763
+ | 5 | Unit tests | Mock all sub-action calls, verify payload assembly |
764
+
765
+ ### Phase 4: Frontend (Consumer-Built, Not in LMS Package)
766
+
767
+ The Angular Element checkout widget is built by the consumer (BC CDP). The LMS package provides:
768
+ - Backend actions the widget calls
769
+ - TypeScript interfaces the widget can use
770
+ - REST endpoint pattern (documented, consumer implements in their MJAPI instance)
771
+
772
+ ---
773
+
774
+ ## Part 5: Package Structure
775
+
776
+ ```
777
+ packages/Actions/BizApps/LMS/
778
+ ├── src/
779
+ │ ├── base/
780
+ │ │ └── base-lms.action.ts (existing, unchanged)
781
+ │ ├── providers/
782
+ │ │ └── learnworlds/
783
+ │ │ ├── learnworlds-base.action.ts (existing, unchanged)
784
+ │ │ ├── actions/
785
+ │ │ │ ├── create-user.action.ts (REFACTOR: add typed public method)
786
+ │ │ │ ├── enroll-user.action.ts (REFACTOR: add typed public method + bundle support)
787
+ │ │ │ ├── get-users.action.ts (REFACTOR: add typed public method)
788
+ │ │ │ ├── get-user-details.action.ts (REFACTOR: add typed public method)
789
+ │ │ │ ├── get-user-progress.action.ts (REFACTOR: add typed public method)
790
+ │ │ │ ├── get-user-enrollments.action.ts (REFACTOR: add typed public method)
791
+ │ │ │ ├── get-courses.action.ts (REFACTOR: add typed public method)
792
+ │ │ │ ├── get-course-details.action.ts (REFACTOR: add typed public method)
793
+ │ │ │ ├── get-course-analytics.action.ts (REFACTOR: add typed public method)
794
+ │ │ │ ├── get-quiz-results.action.ts (REFACTOR: add typed public method)
795
+ │ │ │ ├── get-certificates.action.ts (REFACTOR: add typed public method)
796
+ │ │ │ ├── update-user-progress.action.ts (REFACTOR: add typed public method)
797
+ │ │ │ ├── sso-login.action.ts ← NEW
798
+ │ │ │ ├── update-user.action.ts ← NEW
799
+ │ │ │ ├── attach-tags.action.ts ← NEW
800
+ │ │ │ ├── detach-tags.action.ts ← NEW
801
+ │ │ │ ├── get-bundles.action.ts ← NEW
802
+ │ │ │ ├── onboard-learner.action.ts ← NEW (orchestration)
803
+ │ │ │ ├── get-bulk-data.action.ts ← NEW (bulk retrieval)
804
+ │ │ │ └── index.ts (update exports)
805
+ │ │ └── interfaces/
806
+ │ │ ├── user.types.ts ← NEW (or refactored from inline)
807
+ │ │ ├── course.types.ts ← NEW
808
+ │ │ ├── enrollment.types.ts ← NEW
809
+ │ │ ├── onboarding.types.ts ← NEW
810
+ │ │ ├── sync.types.ts ← NEW
811
+ │ │ └── index.ts ← NEW
812
+ │ └── index.ts (update exports)
813
+ ├── src/__tests__/
814
+ │ ├── sso-login.action.test.ts ← NEW
815
+ │ ├── update-user.action.test.ts ← NEW
816
+ │ ├── onboard-learner.action.test.ts ← NEW
817
+ │ ├── get-bulk-data.action.test.ts ← NEW
818
+ │ └── ...
819
+ └── package.json (no new deps needed — Stripe is consumer-side)
820
+ ```
821
+
822
+ ### No New Dependencies
823
+
824
+ The LMS package does NOT need Stripe as a dependency. Stripe handling happens:
825
+ - **Client-side**: In the Angular Element widget (consumer-built) via `@stripe/stripe-js`
826
+ - **Server-side** (if needed): In a future `@memberjunction/actions-bizapps-payments` package
827
+
828
+ ---
829
+
830
+ ## Part 6: Resolved Questions
831
+
832
+ | # | Question | Decision |
833
+ |---|----------|----------|
834
+ | 1 | **Course-to-product mapping** | Consumer's responsibility. The onboarding action accepts LW course IDs and bundle IDs directly. Each MJ instance maintains its own mapping (e.g., BC CDP has its own mapping table). |
835
+ | 2 | **Auth0 widget placement** | Inline within a custom Angular Element widget. The widget transitions seamlessly from Stripe to Auth0 within the same embedded component — no redirects. |
836
+ | 3 | **Data sync approach** | Actions return JSON payloads with typed interfaces. Consumers handle their own DB storage, scheduling, and mapping. The package exports `LearnWorldsSyncPayload` and related interfaces for TypeScript consumers. |
837
+ | 4 | **Stripe integration** | Not in the LMS package. A future `@memberjunction/actions-bizapps-payments` package is recommended for core MJ. For now, Stripe is handled client-side in the Angular Element widget. |
838
+ | 5 | **SSO plan level** | Confirmed — high-end LW plan with SSO API access. |
839
+ | 6 | **Multi-course purchases** | Supported. `OnboardLearner` accepts arrays of `CourseIds` and `BundleIds`. Bundles are a real LW API concept (`product_type: "bundle"` in the enrollment endpoint). |
840
+
841
+ ## Part 7: Open Items
842
+
843
+ 1. **LW API rate limits** — Need to verify LW's rate limits. The bulk data retrieval could generate many API calls. May need to add configurable concurrency limits.
844
+ 2. **LW bundle enrollment API** — Need to verify the exact endpoint and parameters for bundle enrollment. The enrollment endpoint may use `POST /v2/enrollments` with `product_type: "bundle"` or a separate path.
845
+ 3. **Webhook support (future)** — Not in initial scope. If consumers need real-time sync, LW webhooks can be added later as a separate enhancement.