@contractspec/example.learning-journey-quest-challenges 0.0.0-canary-20260113162409

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/package.json ADDED
@@ -0,0 +1,57 @@
1
+ {
2
+ "name": "@contractspec/example.learning-journey-quest-challenges",
3
+ "version": "0.0.0-canary-20260113162409",
4
+ "description": "Time-bound quest/challenge learning journey example.",
5
+ "type": "module",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": "./dist/index.js",
9
+ "./docs": "./dist/docs/index.js",
10
+ "./docs/quest-challenges.docblock": "./dist/docs/quest-challenges.docblock.js",
11
+ "./example": "./dist/example.js",
12
+ "./track": "./dist/track.js",
13
+ "./*": "./*"
14
+ },
15
+ "scripts": {
16
+ "publish:pkg": "bun publish --tolerate-republish --ignore-scripts --verbose",
17
+ "publish:pkg:canary": "bun publish:pkg --tag canary",
18
+ "build": "bun build:types && bun build:bundle",
19
+ "build:bundle": "tsdown",
20
+ "build:types": "tsc --noEmit",
21
+ "dev": "bun build:bundle --watch",
22
+ "clean": "rimraf dist .turbo",
23
+ "lint": "bun lint:fix",
24
+ "lint:fix": "eslint src --fix",
25
+ "lint:check": "eslint src",
26
+ "test": "bun test"
27
+ },
28
+ "dependencies": {
29
+ "@contractspec/module.learning-journey": "0.0.0-canary-20260113162409",
30
+ "@contractspec/lib.contracts": "0.0.0-canary-20260113162409"
31
+ },
32
+ "devDependencies": {
33
+ "@contractspec/tool.tsdown": "0.0.0-canary-20260113162409",
34
+ "@contractspec/tool.typescript": "0.0.0-canary-20260113162409",
35
+ "tsdown": "^0.19.0",
36
+ "typescript": "^5.9.3"
37
+ },
38
+ "publishConfig": {
39
+ "exports": {
40
+ ".": "./dist/index.js",
41
+ "./example": "./dist/example.js",
42
+ "./track": "./dist/track.js",
43
+ "./docs": "./dist/docs/index.js",
44
+ "./docs/quest-challenges.docblock": "./dist/docs/quest-challenges.docblock.js",
45
+ "./*": "./*"
46
+ },
47
+ "registry": "https://registry.npmjs.org/",
48
+ "access": "public"
49
+ },
50
+ "license": "MIT",
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "https://github.com/lssm-tech/contractspec.git",
54
+ "directory": "packages/examples/learning-journey-quest-challenges"
55
+ },
56
+ "homepage": "https://contractspec.io"
57
+ }
@@ -0,0 +1 @@
1
+ import './quest-challenges.docblock';
@@ -0,0 +1,36 @@
1
+ import type { DocBlock } from '@contractspec/lib.contracts/docs';
2
+ import { registerDocBlocks } from '@contractspec/lib.contracts/docs';
3
+
4
+ const questDocBlocks: DocBlock[] = [
5
+ {
6
+ id: 'docs.learning-journey.quest-challenges',
7
+ title: 'Learning Journey — Quest Challenges',
8
+ summary:
9
+ 'Time-bound challenge pattern (7-day money reset) with day unlocks and event-driven completion.',
10
+ kind: 'reference',
11
+ visibility: 'public',
12
+ route: '/docs/learning-journey/quest-challenges',
13
+ tags: ['learning', 'quest', 'challenge'],
14
+ body: `## Track
15
+ - **Key**: \`money_reset_7day\`
16
+ - **Duration**: 7 days, steps unlock day by day
17
+
18
+ ## Steps & Events
19
+ - Day 1 \`day1_map_accounts\` → event \`accounts.mapped\`
20
+ - Day 2 \`day2_categorize_transactions\` → event \`transactions.categorized\`
21
+ - Day 3 \`day3_define_goals\` → event \`goals.created\`
22
+ - Day 4 \`day4_setup_recurring_savings\` → event \`recurring_rule.created\`
23
+ - Day 5 \`day5_review_subscriptions\` → event \`subscription.flagged_or_cancelled\`
24
+ - Day 6 \`day6_plan_emergency\` → event \`emergency_plan.completed\`
25
+ - Day 7 \`day7_review_commit\` → event \`quest.review.completed\`
26
+
27
+ XP: 15 per day, completion bonus 30 if finished within duration. Optional recap via SRS after completion.
28
+
29
+ ## Usage
30
+ - Exported via \`@contractspec/example.learning-journey-quest-challenges/track\`.
31
+ - Step availability uses \`availability.unlockOnDay\` to gate days.
32
+ - Registry progression handles event matching and XP application.`,
33
+ },
34
+ ];
35
+
36
+ registerDocBlocks(questDocBlocks);
package/src/example.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { defineExample } from '@contractspec/lib.contracts';
2
+
3
+ const example = defineExample({
4
+ meta: {
5
+ key: 'learning-journey-quest-challenges',
6
+ version: '1.0.0',
7
+ title: 'Learning Journey — Quest Challenges',
8
+ description:
9
+ 'Quest/challenge pattern: multi-step goals with progress events, rewards, and streak hooks.',
10
+ kind: 'template',
11
+ visibility: 'public',
12
+ stability: 'experimental',
13
+ owners: ['@platform.core'],
14
+ tags: ['learning', 'quests', 'challenges'],
15
+ },
16
+ docs: {
17
+ rootDocId: 'docs.learning-journey.quest-challenges',
18
+ },
19
+ entrypoints: {
20
+ packageName: '@contractspec/example.learning-journey-quest-challenges',
21
+ docs: './docs',
22
+ },
23
+ surfaces: {
24
+ templates: true,
25
+ sandbox: { enabled: true, modes: ['playground', 'markdown'] },
26
+ studio: { enabled: true, installable: true },
27
+ mcp: { enabled: true },
28
+ },
29
+ });
30
+
31
+ export default example;
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './track';
2
+ export { default as example } from './example';
3
+ import './docs';
@@ -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];
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "@contractspec/tool.typescript/react-library.json",
3
+ "include": ["src"],
4
+ "exclude": ["node_modules"],
5
+ "compilerOptions": {
6
+ "rootDir": "src",
7
+ "outDir": "dist"
8
+ }
9
+ }