@contractspec/example.learning-journey-quest-challenges 1.44.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$colon$bundle.log +25 -0
- package/.turbo/turbo-build.log +26 -0
- package/CHANGELOG.md +178 -0
- package/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/docs/index.d.ts +1 -0
- package/dist/docs/index.js +1 -0
- package/dist/docs/quest-challenges.docblock.d.ts +1 -0
- package/dist/docs/quest-challenges.docblock.js +38 -0
- package/dist/docs/quest-challenges.docblock.js.map +1 -0
- package/dist/example.d.ts +33 -0
- package/dist/example.d.ts.map +1 -0
- package/dist/example.js +35 -0
- package/dist/example.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +5 -0
- package/dist/track.d.ts +8 -0
- package/dist/track.d.ts.map +1 -0
- package/dist/track.js +36 -0
- package/dist/track.js.map +1 -0
- package/example.ts +1 -0
- package/package.json +60 -0
- package/src/docs/index.ts +1 -0
- package/src/docs/quest-challenges.docblock.ts +36 -0
- package/src/example.ts +24 -0
- package/src/index.ts +3 -0
- package/src/track.test.ts +52 -0
- package/src/track.ts +76 -0
- package/tsconfig.json +9 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/tsdown.config.js +17 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { describe, expect, it } from 'bun:test';
|
|
2
|
+
|
|
3
|
+
import { moneyResetQuestTrack } from './track';
|
|
4
|
+
|
|
5
|
+
const addDays = (date: Date, days: number) =>
|
|
6
|
+
new Date(date.getTime() + days * 24 * 60 * 60 * 1000);
|
|
7
|
+
|
|
8
|
+
type StepStatus = 'PENDING' | 'COMPLETED';
|
|
9
|
+
|
|
10
|
+
describe('quest challenges track', () => {
|
|
11
|
+
it('unlocks by day and completes within window', () => {
|
|
12
|
+
const start = new Date('2024-01-01T09:00:00Z');
|
|
13
|
+
const events = [
|
|
14
|
+
{ name: 'accounts.mapped', dayOffset: 0 },
|
|
15
|
+
{ name: 'transactions.categorized', dayOffset: 1 },
|
|
16
|
+
{ name: 'goals.created', dayOffset: 2 },
|
|
17
|
+
{ name: 'recurring_rule.created', dayOffset: 3 },
|
|
18
|
+
{ name: 'subscription.flagged_or_cancelled', dayOffset: 4 },
|
|
19
|
+
{ name: 'emergency_plan.completed', dayOffset: 5 },
|
|
20
|
+
{ name: 'quest.review.completed', dayOffset: 6 },
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const progress = moneyResetQuestTrack.steps.map((step) => ({
|
|
24
|
+
id: step.id,
|
|
25
|
+
status: 'PENDING' as StepStatus,
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
events.forEach((evt) => {
|
|
29
|
+
const now = addDays(start, evt.dayOffset);
|
|
30
|
+
moneyResetQuestTrack.steps.forEach((spec, idx) => {
|
|
31
|
+
const step = progress[idx];
|
|
32
|
+
if (!step || step.status === 'COMPLETED') return;
|
|
33
|
+
const availableAt =
|
|
34
|
+
spec.availability?.unlockOnDay !== undefined
|
|
35
|
+
? addDays(start, spec.availability.unlockOnDay - 1)
|
|
36
|
+
: start;
|
|
37
|
+
if (now < availableAt) return;
|
|
38
|
+
const within =
|
|
39
|
+
spec.completion.kind === 'time_window' &&
|
|
40
|
+
spec.completion.withinHoursOfStart !== undefined
|
|
41
|
+
? (now.getTime() - start.getTime()) / (1000 * 60 * 60) <=
|
|
42
|
+
spec.completion.withinHoursOfStart
|
|
43
|
+
: true;
|
|
44
|
+
if (!within) return;
|
|
45
|
+
if (spec.completion.eventName !== evt.name) return;
|
|
46
|
+
step.status = 'COMPLETED';
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
expect(progress.every((s) => s.status === 'COMPLETED')).toBeTrue();
|
|
51
|
+
});
|
|
52
|
+
});
|
package/src/track.ts
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { LearningJourneyTrackSpec } from '@contractspec/module.learning-journey/track-spec';
|
|
2
|
+
|
|
3
|
+
const dayStep = (
|
|
4
|
+
id: string,
|
|
5
|
+
day: number,
|
|
6
|
+
eventName: string,
|
|
7
|
+
description: string
|
|
8
|
+
): LearningJourneyTrackSpec['steps'][number] => ({
|
|
9
|
+
id,
|
|
10
|
+
title: `Day ${day}`,
|
|
11
|
+
description,
|
|
12
|
+
availability: { unlockOnDay: day },
|
|
13
|
+
completion: {
|
|
14
|
+
kind: 'time_window',
|
|
15
|
+
eventName,
|
|
16
|
+
withinHoursOfStart: (day + 1) * 24, // allow grace through next day
|
|
17
|
+
},
|
|
18
|
+
xpReward: 15,
|
|
19
|
+
metadata: { day },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const moneyResetQuestTrack: LearningJourneyTrackSpec = {
|
|
23
|
+
id: 'money_reset_7day',
|
|
24
|
+
name: '7-day Money Reset',
|
|
25
|
+
description:
|
|
26
|
+
'Time-bound quest to reset personal finances over a focused week.',
|
|
27
|
+
targetUserSegment: 'money_user',
|
|
28
|
+
totalXp: 105,
|
|
29
|
+
completionRewards: { xpBonus: 30 },
|
|
30
|
+
steps: [
|
|
31
|
+
dayStep(
|
|
32
|
+
'day1_map_accounts',
|
|
33
|
+
1,
|
|
34
|
+
'accounts.mapped',
|
|
35
|
+
'Map bank and card accounts.'
|
|
36
|
+
),
|
|
37
|
+
dayStep(
|
|
38
|
+
'day2_categorize_transactions',
|
|
39
|
+
2,
|
|
40
|
+
'transactions.categorized',
|
|
41
|
+
'Categorize recent transactions.'
|
|
42
|
+
),
|
|
43
|
+
dayStep(
|
|
44
|
+
'day3_define_goals',
|
|
45
|
+
3,
|
|
46
|
+
'goals.created',
|
|
47
|
+
'Define at least one savings goal.'
|
|
48
|
+
),
|
|
49
|
+
dayStep(
|
|
50
|
+
'day4_setup_recurring_savings',
|
|
51
|
+
4,
|
|
52
|
+
'recurring_rule.created',
|
|
53
|
+
'Set a recurring savings rule.'
|
|
54
|
+
),
|
|
55
|
+
dayStep(
|
|
56
|
+
'day5_review_subscriptions',
|
|
57
|
+
5,
|
|
58
|
+
'subscription.flagged_or_cancelled',
|
|
59
|
+
'Review subscriptions and flag or cancel wasteful ones.'
|
|
60
|
+
),
|
|
61
|
+
dayStep(
|
|
62
|
+
'day6_plan_emergency',
|
|
63
|
+
6,
|
|
64
|
+
'emergency_plan.completed',
|
|
65
|
+
'Draft an emergency plan and target buffer.'
|
|
66
|
+
),
|
|
67
|
+
dayStep(
|
|
68
|
+
'day7_review_commit',
|
|
69
|
+
7,
|
|
70
|
+
'quest.review.completed',
|
|
71
|
+
'Review week outcomes and commit to the next month.'
|
|
72
|
+
),
|
|
73
|
+
],
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const questTracks: LearningJourneyTrackSpec[] = [moneyResetQuestTrack];
|