@contractspec/example.learning-journey-registry 1.57.0 → 1.58.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 +52 -55
- package/.turbo/turbo-prebuild.log +1 -0
- package/CHANGELOG.md +23 -0
- package/dist/api-types.d.ts +33 -37
- package/dist/api-types.d.ts.map +1 -1
- package/dist/api-types.js +1 -0
- package/dist/api.d.ts +7 -11
- package/dist/api.d.ts.map +1 -1
- package/dist/api.js +261 -161
- package/dist/api.test.d.ts +2 -0
- package/dist/api.test.d.ts.map +1 -0
- package/dist/browser/api-types.js +0 -0
- package/dist/browser/api.js +270 -0
- package/dist/browser/docs/index.js +33 -0
- package/dist/browser/docs/learning-journey-registry.docblock.js +33 -0
- package/dist/browser/example.js +32 -0
- package/dist/browser/index.js +540 -0
- package/dist/browser/learning-journey-registry.feature.js +45 -0
- package/dist/browser/presentations/index.js +67 -0
- package/dist/browser/progress-store.js +34 -0
- package/dist/browser/tracks.js +52 -0
- package/dist/browser/ui/LearningMiniApp.js +133 -0
- package/dist/browser/ui/index.js +133 -0
- package/dist/docs/index.d.ts +2 -1
- package/dist/docs/index.d.ts.map +1 -0
- package/dist/docs/index.js +34 -1
- package/dist/docs/learning-journey-registry.docblock.d.ts +2 -1
- package/dist/docs/learning-journey-registry.docblock.d.ts.map +1 -0
- package/dist/docs/learning-journey-registry.docblock.js +18 -22
- package/dist/example.d.ts +2 -6
- package/dist/example.d.ts.map +1 -1
- package/dist/example.js +31 -39
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +541 -10
- package/dist/learning-journey-registry.feature.d.ts +1 -6
- package/dist/learning-journey-registry.feature.d.ts.map +1 -1
- package/dist/learning-journey-registry.feature.js +44 -73
- package/dist/node/api-types.js +0 -0
- package/dist/node/api.js +270 -0
- package/dist/node/docs/index.js +33 -0
- package/dist/node/docs/learning-journey-registry.docblock.js +33 -0
- package/dist/node/example.js +32 -0
- package/dist/node/index.js +540 -0
- package/dist/node/learning-journey-registry.feature.js +45 -0
- package/dist/node/presentations/index.js +67 -0
- package/dist/node/progress-store.js +34 -0
- package/dist/node/tracks.js +52 -0
- package/dist/node/ui/LearningMiniApp.js +133 -0
- package/dist/node/ui/index.js +133 -0
- package/dist/presentations/index.d.ts +4 -9
- package/dist/presentations/index.d.ts.map +1 -1
- package/dist/presentations/index.js +63 -66
- package/dist/progress-store.d.ts +6 -10
- package/dist/progress-store.d.ts.map +1 -1
- package/dist/progress-store.js +33 -29
- package/dist/tracks.d.ts +33 -36
- package/dist/tracks.d.ts.map +1 -1
- package/dist/tracks.js +44 -39
- package/dist/ui/LearningMiniApp.d.ts +8 -16
- package/dist/ui/LearningMiniApp.d.ts.map +1 -1
- package/dist/ui/LearningMiniApp.js +123 -69
- package/dist/ui/index.d.ts +2 -2
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +134 -3
- package/package.json +143 -48
- package/tsdown.config.js +1 -2
- package/.turbo/turbo-build$colon$bundle.log +0 -55
- package/dist/api.js.map +0 -1
- package/dist/docs/learning-journey-registry.docblock.js.map +0 -1
- package/dist/example.js.map +0 -1
- package/dist/learning-journey-registry.feature.js.map +0 -1
- package/dist/presentations/index.js.map +0 -1
- package/dist/progress-store.js.map +0 -1
- package/dist/tracks.js.map +0 -1
- package/dist/ui/LearningMiniApp.js.map +0 -1
- package/tsconfig.tsbuildinfo +0 -1
package/dist/api.js
CHANGED
|
@@ -1,171 +1,271 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
// @bun
|
|
2
|
+
// src/tracks.ts
|
|
3
|
+
import { crmLearningTracks } from "@contractspec/example.learning-journey-crm-onboarding/track";
|
|
4
|
+
import { drillTracks } from "@contractspec/example.learning-journey-duo-drills/track";
|
|
5
|
+
import { ambientCoachTracks } from "@contractspec/example.learning-journey-ambient-coach/track";
|
|
6
|
+
import { questTracks } from "@contractspec/example.learning-journey-quest-challenges/track";
|
|
7
|
+
import { platformLearningTracks } from "@contractspec/example.learning-journey-platform-tour/track";
|
|
8
|
+
import { studioLearningTracks } from "@contractspec/example.learning-journey-studio-onboarding/track";
|
|
9
|
+
var mapStep = (step) => ({
|
|
10
|
+
id: step.id,
|
|
11
|
+
title: step.title,
|
|
12
|
+
description: step.description,
|
|
13
|
+
completionEvent: step.completion.eventName,
|
|
14
|
+
completionCondition: step.completion,
|
|
15
|
+
xpReward: step.xpReward,
|
|
16
|
+
isRequired: step.isRequired,
|
|
17
|
+
canSkip: step.canSkip,
|
|
18
|
+
actionUrl: step.actionUrl,
|
|
19
|
+
actionLabel: step.actionLabel,
|
|
20
|
+
availability: step.availability,
|
|
21
|
+
metadata: step.metadata
|
|
22
|
+
});
|
|
23
|
+
var mapTrackSpecToDto = (track) => ({
|
|
24
|
+
id: track.id,
|
|
25
|
+
name: track.name,
|
|
26
|
+
description: track.description,
|
|
27
|
+
productId: track.productId,
|
|
28
|
+
targetUserSegment: track.targetUserSegment,
|
|
29
|
+
targetRole: track.targetRole,
|
|
30
|
+
totalXp: track.totalXp,
|
|
31
|
+
streakRule: track.streakRule,
|
|
32
|
+
completionRewards: track.completionRewards,
|
|
33
|
+
steps: track.steps.map(mapStep),
|
|
34
|
+
metadata: track.metadata
|
|
35
|
+
});
|
|
36
|
+
var learningJourneyTracks = [
|
|
37
|
+
...studioLearningTracks,
|
|
38
|
+
...platformLearningTracks,
|
|
39
|
+
...crmLearningTracks,
|
|
40
|
+
...drillTracks,
|
|
41
|
+
...ambientCoachTracks,
|
|
42
|
+
...questTracks
|
|
43
|
+
];
|
|
44
|
+
var onboardingTrackCatalog = learningJourneyTracks.map(mapTrackSpecToDto);
|
|
45
|
+
// src/progress-store.ts
|
|
46
|
+
var progressStore = new Map;
|
|
47
|
+
var getTrackResolver = (tracks) => (trackId) => tracks.find((t) => t.id === trackId);
|
|
48
|
+
var getLearnerTracks = (learnerId) => {
|
|
49
|
+
const existing = progressStore.get(learnerId);
|
|
50
|
+
if (existing)
|
|
51
|
+
return existing;
|
|
52
|
+
const map = new Map;
|
|
53
|
+
progressStore.set(learnerId, map);
|
|
54
|
+
return map;
|
|
55
|
+
};
|
|
56
|
+
var initProgress = (learnerId, track) => ({
|
|
57
|
+
learnerId,
|
|
58
|
+
trackId: track.id,
|
|
59
|
+
progress: 0,
|
|
60
|
+
isCompleted: false,
|
|
61
|
+
xpEarned: 0,
|
|
62
|
+
steps: track.steps.map((step) => ({
|
|
63
|
+
id: step.id,
|
|
64
|
+
status: "PENDING",
|
|
65
|
+
xpEarned: 0,
|
|
66
|
+
occurrences: 0,
|
|
67
|
+
masteryCount: 0
|
|
68
|
+
})),
|
|
69
|
+
startedAt: undefined,
|
|
70
|
+
completedAt: undefined,
|
|
71
|
+
lastActivityAt: undefined
|
|
72
|
+
});
|
|
3
73
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
74
|
+
// src/api.ts
|
|
75
|
+
var getTrack = getTrackResolver(learningJourneyTracks);
|
|
76
|
+
var matchesFilter = (filter, payload) => {
|
|
77
|
+
if (!filter)
|
|
78
|
+
return true;
|
|
79
|
+
if (!payload)
|
|
80
|
+
return false;
|
|
81
|
+
return Object.entries(filter).every(([key, value]) => payload[key] === value);
|
|
10
82
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
83
|
+
var matchesBaseEvent = (condition, event) => {
|
|
84
|
+
if (condition.eventName !== event.name)
|
|
85
|
+
return false;
|
|
86
|
+
if (condition.eventVersion !== undefined && event.version !== undefined) {
|
|
87
|
+
if (condition.eventVersion !== event.version)
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
if (condition.sourceModule && event.sourceModule && condition.sourceModule !== event.sourceModule) {
|
|
91
|
+
return false;
|
|
92
|
+
}
|
|
93
|
+
return matchesFilter(condition.payloadFilter, event.payload);
|
|
18
94
|
};
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
95
|
+
var matchesCondition = (condition, event, step, trackStartedAt) => {
|
|
96
|
+
if (condition.kind === "count") {
|
|
97
|
+
if (!matchesBaseEvent(condition, event))
|
|
98
|
+
return { matched: false };
|
|
99
|
+
const occurrences = (step.occurrences ?? 0) + 1;
|
|
100
|
+
const within = condition.withinHours === undefined || Boolean(trackStartedAt && event.occurredAt && (event.occurredAt.getTime() - trackStartedAt.getTime()) / (1000 * 60 * 60) <= condition.withinHours);
|
|
101
|
+
return { matched: within && occurrences >= condition.atLeast, occurrences };
|
|
102
|
+
}
|
|
103
|
+
if (condition.kind === "time_window") {
|
|
104
|
+
if (!matchesBaseEvent(condition, event))
|
|
105
|
+
return { matched: false };
|
|
106
|
+
if (condition.withinHoursOfStart !== undefined && trackStartedAt && event.occurredAt) {
|
|
107
|
+
const hoursSinceStart = (event.occurredAt.getTime() - trackStartedAt.getTime()) / (1000 * 60 * 60);
|
|
108
|
+
if (hoursSinceStart > condition.withinHoursOfStart) {
|
|
109
|
+
return { matched: false };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return { matched: true };
|
|
113
|
+
}
|
|
114
|
+
if (condition.kind === "srs_mastery") {
|
|
115
|
+
if (event.name !== condition.eventName)
|
|
116
|
+
return { matched: false };
|
|
117
|
+
const payload = event.payload;
|
|
118
|
+
if (!matchesFilter(condition.payloadFilter, payload)) {
|
|
119
|
+
return { matched: false };
|
|
120
|
+
}
|
|
121
|
+
const skillKey = condition.skillIdField ?? "skillId";
|
|
122
|
+
const masteryKey = condition.masteryField ?? "mastery";
|
|
123
|
+
const skillId = payload?.[skillKey];
|
|
124
|
+
const masteryValue = payload?.[masteryKey];
|
|
125
|
+
if (skillId === undefined || masteryValue === undefined) {
|
|
126
|
+
return { matched: false };
|
|
127
|
+
}
|
|
128
|
+
if (typeof masteryValue !== "number")
|
|
129
|
+
return { matched: false };
|
|
130
|
+
if (masteryValue < condition.minimumMastery)
|
|
131
|
+
return { matched: false };
|
|
132
|
+
const masteryCount = (step.masteryCount ?? 0) + 1;
|
|
133
|
+
const required = condition.requiredCount ?? 1;
|
|
134
|
+
return { matched: masteryCount >= required, masteryCount };
|
|
135
|
+
}
|
|
136
|
+
return { matched: matchesBaseEvent(condition, event) };
|
|
53
137
|
};
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
138
|
+
var getAvailability = (availability, startedAt) => {
|
|
139
|
+
if (!availability || !startedAt)
|
|
140
|
+
return {};
|
|
141
|
+
const baseTime = startedAt.getTime();
|
|
142
|
+
let unlockTime = baseTime;
|
|
143
|
+
if (availability.unlockOnDay !== undefined) {
|
|
144
|
+
unlockTime = baseTime + (availability.unlockOnDay - 1) * 24 * 60 * 60 * 1000;
|
|
145
|
+
}
|
|
146
|
+
if (availability.unlockAfterHours !== undefined) {
|
|
147
|
+
unlockTime = baseTime + availability.unlockAfterHours * 60 * 60 * 1000;
|
|
148
|
+
}
|
|
149
|
+
const availableAt = new Date(unlockTime);
|
|
150
|
+
const dueAt = availability.dueWithinHours !== undefined ? new Date(availableAt.getTime() + availability.dueWithinHours * 60 * 60 * 1000) : undefined;
|
|
151
|
+
return { availableAt, dueAt };
|
|
65
152
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
153
|
+
var computeProgressPercent = (steps) => {
|
|
154
|
+
const total = steps.length || 1;
|
|
155
|
+
const done = steps.filter((s) => s.status === "COMPLETED").length;
|
|
156
|
+
return Math.round(done / total * 100);
|
|
70
157
|
};
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
158
|
+
var applyTrackCompletionBonuses = (track, progress) => {
|
|
159
|
+
if (progress.isCompleted)
|
|
160
|
+
return progress;
|
|
161
|
+
const completedAt = new Date;
|
|
162
|
+
const startedAt = progress.startedAt ?? completedAt;
|
|
163
|
+
const hoursElapsed = (completedAt.getTime() - startedAt.getTime()) / (1000 * 60 * 60);
|
|
164
|
+
let xpEarned = progress.xpEarned;
|
|
165
|
+
const { completionRewards, streakRule } = track;
|
|
166
|
+
if (completionRewards?.xpBonus) {
|
|
167
|
+
xpEarned += completionRewards.xpBonus;
|
|
168
|
+
}
|
|
169
|
+
if (streakRule?.hoursWindow !== undefined && hoursElapsed <= streakRule.hoursWindow && streakRule.bonusXp) {
|
|
170
|
+
xpEarned += streakRule.bonusXp;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
...progress,
|
|
174
|
+
xpEarned,
|
|
175
|
+
isCompleted: true,
|
|
176
|
+
completedAt,
|
|
177
|
+
lastActivityAt: completedAt
|
|
178
|
+
};
|
|
87
179
|
};
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
180
|
+
var listTracks = (learnerId) => {
|
|
181
|
+
const progressMap = learnerId ? getLearnerTracks(learnerId) : undefined;
|
|
182
|
+
const progress = learnerId && progressMap ? Array.from(progressMap.values()) : [];
|
|
183
|
+
return {
|
|
184
|
+
tracks: learningJourneyTracks,
|
|
185
|
+
progress
|
|
186
|
+
};
|
|
94
187
|
};
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
188
|
+
var getProgress = (trackId, learnerId) => {
|
|
189
|
+
const track = getTrack(trackId);
|
|
190
|
+
if (!track)
|
|
191
|
+
return;
|
|
192
|
+
const map = getLearnerTracks(learnerId);
|
|
193
|
+
const existing = map.get(trackId) ?? initProgress(learnerId, track);
|
|
194
|
+
map.set(trackId, existing);
|
|
195
|
+
return existing;
|
|
102
196
|
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
197
|
+
var recordEvent = (event) => {
|
|
198
|
+
const targets = event.trackId !== undefined ? learningJourneyTracks.filter((t) => t.id === event.trackId) : learningJourneyTracks;
|
|
199
|
+
const updated = [];
|
|
200
|
+
const eventTime = event.occurredAt ?? new Date;
|
|
201
|
+
for (const track of targets) {
|
|
202
|
+
const map = getLearnerTracks(event.learnerId);
|
|
203
|
+
const current = map.get(track.id) ?? initProgress(event.learnerId, track);
|
|
204
|
+
const startedAt = current.startedAt ?? eventTime;
|
|
205
|
+
let changed = current.startedAt === undefined;
|
|
206
|
+
const steps = current.steps.map((step) => {
|
|
207
|
+
if (step.status === "COMPLETED")
|
|
208
|
+
return step;
|
|
209
|
+
const spec = track.steps.find((s) => s.id === step.id);
|
|
210
|
+
if (!spec)
|
|
211
|
+
return step;
|
|
212
|
+
const { availableAt, dueAt } = getAvailability(spec.availability, startedAt);
|
|
213
|
+
if (availableAt && eventTime < availableAt) {
|
|
214
|
+
return { ...step, availableAt, dueAt };
|
|
215
|
+
}
|
|
216
|
+
if (dueAt && eventTime > dueAt) {
|
|
217
|
+
return { ...step, availableAt, dueAt };
|
|
218
|
+
}
|
|
219
|
+
const result = matchesCondition(spec.completion, event, step, startedAt);
|
|
220
|
+
if (result.matched) {
|
|
221
|
+
changed = true;
|
|
222
|
+
return {
|
|
223
|
+
...step,
|
|
224
|
+
status: "COMPLETED",
|
|
225
|
+
xpEarned: spec.xpReward ?? 0,
|
|
226
|
+
completedAt: eventTime,
|
|
227
|
+
triggeringEvent: event.name,
|
|
228
|
+
eventPayload: event.payload,
|
|
229
|
+
occurrences: result.occurrences ?? step.occurrences,
|
|
230
|
+
masteryCount: result.masteryCount ?? step.masteryCount,
|
|
231
|
+
availableAt,
|
|
232
|
+
dueAt
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
if (result.occurrences !== undefined || result.masteryCount !== undefined) {
|
|
236
|
+
changed = true;
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
...step,
|
|
240
|
+
occurrences: result.occurrences ?? step.occurrences,
|
|
241
|
+
masteryCount: result.masteryCount ?? step.masteryCount,
|
|
242
|
+
availableAt,
|
|
243
|
+
dueAt
|
|
244
|
+
};
|
|
245
|
+
});
|
|
246
|
+
if (!changed) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
const xpEarned = steps.reduce((sum, s) => sum + s.xpEarned, 0) + (track.totalXp ?? 0);
|
|
250
|
+
let progress = {
|
|
251
|
+
...current,
|
|
252
|
+
steps,
|
|
253
|
+
xpEarned,
|
|
254
|
+
startedAt,
|
|
255
|
+
lastActivityAt: eventTime,
|
|
256
|
+
progress: computeProgressPercent(steps)
|
|
257
|
+
};
|
|
258
|
+
const allDone = steps.every((s) => s.status === "COMPLETED");
|
|
259
|
+
if (allDone) {
|
|
260
|
+
progress = applyTrackCompletionBonuses(track, progress);
|
|
261
|
+
}
|
|
262
|
+
map.set(track.id, progress);
|
|
263
|
+
updated.push(progress);
|
|
264
|
+
}
|
|
265
|
+
return updated;
|
|
266
|
+
};
|
|
267
|
+
export {
|
|
268
|
+
recordEvent,
|
|
269
|
+
listTracks,
|
|
270
|
+
getProgress
|
|
167
271
|
};
|
|
168
|
-
|
|
169
|
-
//#endregion
|
|
170
|
-
export { getProgress, listTracks, recordEvent };
|
|
171
|
-
//# sourceMappingURL=api.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.test.d.ts","sourceRoot":"","sources":["../src/api.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|