@open-loyalty/mcp-server 1.3.6 → 1.4.1

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 (42) hide show
  1. package/dist/instructions.d.ts +1 -1
  2. package/dist/instructions.js +18 -5
  3. package/dist/tools/achievement/index.js +10 -10
  4. package/dist/tools/achievement/schemas.js +16 -8
  5. package/dist/tools/reward/handlers.d.ts +3 -3
  6. package/dist/tools/reward/handlers.js +54 -8
  7. package/dist/tools/reward/index.d.ts +4 -8
  8. package/dist/tools/reward/index.js +13 -5
  9. package/dist/tools/reward/schemas.d.ts +3 -7
  10. package/dist/tools/reward/schemas.js +16 -8
  11. package/dist/tools/tierset.d.ts +1 -1
  12. package/dist/tools/tierset.js +49 -25
  13. package/dist/tools/transaction.js +5 -2
  14. package/dist/tools/wallet-type.js +27 -16
  15. package/dist/types/schemas/admin.d.ts +6 -6
  16. package/dist/types/schemas/role.d.ts +4 -4
  17. package/dist/types/schemas/wallet-type.js +7 -5
  18. package/package.json +1 -1
  19. package/dist/prompts/fan-engagement-setup.d.ts +0 -107
  20. package/dist/prompts/fan-engagement-setup.js +0 -492
  21. package/dist/tools/achievement.d.ts +0 -1017
  22. package/dist/tools/achievement.js +0 -354
  23. package/dist/tools/campaign.d.ts +0 -1800
  24. package/dist/tools/campaign.js +0 -737
  25. package/dist/tools/member.d.ts +0 -366
  26. package/dist/tools/member.js +0 -352
  27. package/dist/tools/reward.d.ts +0 -279
  28. package/dist/tools/reward.js +0 -361
  29. package/dist/tools/segment.d.ts +0 -816
  30. package/dist/tools/segment.js +0 -333
  31. package/dist/workflows/app-login-streak.d.ts +0 -39
  32. package/dist/workflows/app-login-streak.js +0 -298
  33. package/dist/workflows/early-arrival.d.ts +0 -33
  34. package/dist/workflows/early-arrival.js +0 -148
  35. package/dist/workflows/index.d.ts +0 -101
  36. package/dist/workflows/index.js +0 -208
  37. package/dist/workflows/match-attendance.d.ts +0 -45
  38. package/dist/workflows/match-attendance.js +0 -308
  39. package/dist/workflows/sportsbar-visit.d.ts +0 -41
  40. package/dist/workflows/sportsbar-visit.js +0 -284
  41. package/dist/workflows/vod-watching.d.ts +0 -43
  42. package/dist/workflows/vod-watching.js +0 -326
@@ -1,326 +0,0 @@
1
- /**
2
- * VOD Watching Workflow
3
- *
4
- * Creates a campaign to reward fans for watching video content,
5
- * with achievements for total watch time using attribute aggregation.
6
- */
7
- import { campaignCreate, campaignList } from "../tools/campaign/handlers.js";
8
- import { achievementCreate, achievementList } from "../tools/achievement.js";
9
- import { badgeList } from "../tools/badge.js";
10
- import { formatOLDate, DEFAULTS } from "../prompts/fan-engagement-setup.js";
11
- // ============================================================================
12
- // Workflow Implementation
13
- // ============================================================================
14
- /**
15
- * Execute the VOD watching workflow
16
- */
17
- export async function executeVodWatchingWorkflow(config = {}) {
18
- const result = {
19
- success: false,
20
- errors: [],
21
- summary: "",
22
- };
23
- // Merge with defaults
24
- const cfg = {
25
- trackBy: config.trackBy ?? DEFAULTS.vodWatching.trackBy,
26
- coinsPerUnit: config.coinsPerUnit ?? DEFAULTS.vodWatching.coinsPerUnit,
27
- unitSize: config.unitSize ?? DEFAULTS.vodWatching.unitSize,
28
- createAchievement: config.createAchievement ?? true,
29
- achievementTarget: config.achievementTarget ?? DEFAULTS.vodWatching.achievementMinutes,
30
- achievementBonus: config.achievementBonus ?? DEFAULTS.vodWatching.achievementBonus,
31
- badgeName: config.badgeName ?? "Content Enthusiast",
32
- seasonStart: config.seasonStart ?? DEFAULTS.seasonDates.start,
33
- seasonEnd: config.seasonEnd ?? DEFAULTS.seasonDates.end,
34
- };
35
- try {
36
- // Step 1: Create base VOD watching campaign
37
- const watchCampaignResult = await createWatchCampaign(cfg);
38
- if (watchCampaignResult.error) {
39
- result.errors.push(watchCampaignResult.error);
40
- }
41
- else {
42
- result.watchCampaignId = watchCampaignResult.campaignId;
43
- }
44
- // Step 2: Create achievement and bonus campaign if enabled
45
- if (cfg.createAchievement) {
46
- const badges = await getAvailableBadges();
47
- const achievementResult = await createWatchAchievement(cfg, badges);
48
- if (achievementResult.error) {
49
- result.errors.push(achievementResult.error);
50
- }
51
- else {
52
- result.achievementId = achievementResult.achievementId;
53
- // Create bonus campaign for achievement
54
- if (achievementResult.achievementId) {
55
- const bonusCampaignResult = await createAchievementBonusCampaign(achievementResult.achievementId, cfg);
56
- if (bonusCampaignResult.error) {
57
- result.errors.push(bonusCampaignResult.error);
58
- }
59
- else {
60
- result.bonusCampaignId = bonusCampaignResult.campaignId;
61
- }
62
- }
63
- }
64
- }
65
- // Step 3: Verify setup
66
- const verification = await verifySetup(result);
67
- if (verification.warnings.length > 0) {
68
- result.errors.push(...verification.warnings);
69
- }
70
- // Determine success
71
- result.success = result.watchCampaignId !== undefined && result.errors.length === 0;
72
- // Build summary
73
- result.summary = buildSummary(cfg, result);
74
- }
75
- catch (error) {
76
- result.errors.push(`Workflow error: ${error instanceof Error ? error.message : String(error)}`);
77
- }
78
- return result;
79
- }
80
- // ============================================================================
81
- // Helper Functions
82
- // ============================================================================
83
- async function createWatchCampaign(cfg) {
84
- try {
85
- const isMinutesBased = cfg.trackBy === "minutes";
86
- // For minutes-based tracking, we use an expression to calculate points
87
- // based on the minutes_watched attribute divided by unitSize
88
- const pointsRule = isMinutesBased
89
- ? {
90
- expression: `Math.floor(event.minutes_watched / ${cfg.unitSize}) * ${cfg.coinsPerUnit}`,
91
- }
92
- : {
93
- fixedValue: cfg.coinsPerUnit,
94
- };
95
- const description = isMinutesBased
96
- ? `Earn ${cfg.coinsPerUnit} coins for every ${cfg.unitSize} minutes of video watched`
97
- : `Earn ${cfg.coinsPerUnit} coins for each video viewed`;
98
- const response = await campaignCreate({
99
- type: "direct",
100
- trigger: "custom_event",
101
- event: "vod_watch",
102
- translations: {
103
- en: {
104
- name: "Video Content Reward",
105
- description,
106
- },
107
- },
108
- activity: {
109
- startsAt: formatOLDate(cfg.seasonStart),
110
- endsAt: formatOLDate(cfg.seasonEnd),
111
- },
112
- rules: [
113
- {
114
- name: "Award coins for watching content",
115
- effects: [
116
- {
117
- effect: "give_points",
118
- pointsRule,
119
- },
120
- ],
121
- },
122
- ],
123
- active: true,
124
- });
125
- return { campaignId: response.campaignId };
126
- }
127
- catch (error) {
128
- return {
129
- error: `Failed to create VOD watch campaign: ${error instanceof Error ? error.message : String(error)}`,
130
- };
131
- }
132
- }
133
- async function getAvailableBadges() {
134
- try {
135
- const response = await badgeList({});
136
- const badgeMap = new Map();
137
- for (const badge of response.badges) {
138
- if (badge.name && badge.badgeTypeId) {
139
- badgeMap.set(badge.name.toLowerCase(), badge.badgeTypeId);
140
- }
141
- }
142
- return badgeMap;
143
- }
144
- catch {
145
- return new Map();
146
- }
147
- }
148
- async function createWatchAchievement(cfg, badges) {
149
- try {
150
- const badgeTypeId = cfg.badgeName
151
- ? badges.get(cfg.badgeName.toLowerCase())
152
- : undefined;
153
- const isMinutesBased = cfg.trackBy === "minutes";
154
- const targetLabel = isMinutesBased ? "minutes" : "videos";
155
- /**
156
- * For attribute-sum achievements, we use aggregation rule "sum" with
157
- * the attribute to aggregate (e.g., "minutes_watched").
158
- * The periodGoal is the total to reach.
159
- */
160
- const achievementPayload = {
161
- translations: {
162
- en: {
163
- name: `Watch ${cfg.achievementTarget} ${targetLabel}`,
164
- description: isMinutesBased
165
- ? `Watch ${cfg.achievementTarget} total minutes of video content`
166
- : `Watch ${cfg.achievementTarget} videos`,
167
- },
168
- },
169
- active: true,
170
- activity: {
171
- startsAt: formatOLDate(cfg.seasonStart),
172
- endsAt: formatOLDate(cfg.seasonEnd),
173
- },
174
- rules: [
175
- {
176
- trigger: "custom_event",
177
- event: "vod_watch",
178
- completeRule: {
179
- periodGoal: cfg.achievementTarget,
180
- },
181
- // For minutes tracking, aggregate the minutes_watched attribute
182
- ...(isMinutesBased && {
183
- aggregation: {
184
- rule: "sum",
185
- },
186
- }),
187
- },
188
- ],
189
- };
190
- if (badgeTypeId) {
191
- achievementPayload.badgeTypeId = badgeTypeId;
192
- }
193
- const response = await achievementCreate(achievementPayload);
194
- return { achievementId: response.achievementId };
195
- }
196
- catch (error) {
197
- return {
198
- error: `Failed to create watch achievement: ${error instanceof Error ? error.message : String(error)}`,
199
- };
200
- }
201
- }
202
- async function createAchievementBonusCampaign(achievementId, cfg) {
203
- try {
204
- const targetLabel = cfg.trackBy === "minutes" ? "minutes" : "videos";
205
- const response = await campaignCreate({
206
- type: "direct",
207
- trigger: "achievement",
208
- translations: {
209
- en: {
210
- name: `Watch ${cfg.achievementTarget} ${targetLabel} Bonus`,
211
- description: `Bonus ${cfg.achievementBonus} coins for watching ${cfg.achievementTarget} ${targetLabel}`,
212
- },
213
- },
214
- activity: {
215
- startsAt: formatOLDate(cfg.seasonStart),
216
- endsAt: formatOLDate(cfg.seasonEnd),
217
- },
218
- rules: [
219
- {
220
- name: `Bonus for watching ${cfg.achievementTarget} ${targetLabel}`,
221
- effects: [
222
- {
223
- effect: "give_points",
224
- pointsRule: { fixedValue: cfg.achievementBonus },
225
- },
226
- ],
227
- conditions: [
228
- {
229
- operator: "is_equal",
230
- attribute: "achievement.achievementId",
231
- data: { value: achievementId },
232
- },
233
- ],
234
- },
235
- ],
236
- active: true,
237
- });
238
- return { campaignId: response.campaignId };
239
- }
240
- catch (error) {
241
- return {
242
- error: `Failed to create bonus campaign: ${error instanceof Error ? error.message : String(error)}`,
243
- };
244
- }
245
- }
246
- async function verifySetup(result) {
247
- const warnings = [];
248
- try {
249
- if (result.watchCampaignId) {
250
- const campaigns = await campaignList({ active: true });
251
- const found = campaigns.campaigns.some((c) => c.campaignId === result.watchCampaignId);
252
- if (!found) {
253
- warnings.push("Watch campaign created but not found in active campaigns list");
254
- }
255
- }
256
- if (result.achievementId) {
257
- const achievements = await achievementList({ active: true });
258
- const found = achievements.achievements.some((a) => a.achievementId === result.achievementId);
259
- if (!found) {
260
- warnings.push("Achievement created but not found in active achievements list");
261
- }
262
- }
263
- }
264
- catch (error) {
265
- warnings.push(`Verification error: ${error instanceof Error ? error.message : String(error)}`);
266
- }
267
- return { warnings };
268
- }
269
- function buildSummary(cfg, result) {
270
- const lines = [];
271
- const isMinutesBased = cfg.trackBy === "minutes";
272
- const targetLabel = isMinutesBased ? "minutes" : "videos";
273
- if (result.watchCampaignId) {
274
- lines.push(`VOD watching campaign created!`);
275
- lines.push(`\nTracking by: ${cfg.trackBy}`);
276
- if (isMinutesBased) {
277
- lines.push(`Reward: ${cfg.coinsPerUnit} coins per ${cfg.unitSize} minutes watched`);
278
- }
279
- else {
280
- lines.push(`Reward: ${cfg.coinsPerUnit} coins per video viewed`);
281
- }
282
- }
283
- if (result.achievementId) {
284
- lines.push(`\nAchievement: Watch ${cfg.achievementTarget} ${targetLabel}`);
285
- if (cfg.badgeName) {
286
- lines.push(`Badge: ${cfg.badgeName}`);
287
- }
288
- if (result.bonusCampaignId) {
289
- lines.push(`Completion bonus: ${cfg.achievementBonus} coins`);
290
- }
291
- }
292
- lines.push(`\nSeason: ${cfg.seasonStart} to ${cfg.seasonEnd}`);
293
- lines.push(`\nCustom event to trigger reward:`);
294
- lines.push(` Event: vod_watch`);
295
- if (isMinutesBased) {
296
- lines.push(` Required attribute: minutes_watched (number)`);
297
- lines.push(`\nExample event payload:`);
298
- lines.push(`{`);
299
- lines.push(` "event": "vod_watch",`);
300
- lines.push(` "attributes": {`);
301
- lines.push(` "minutes_watched": 15`);
302
- lines.push(` }`);
303
- lines.push(`}`);
304
- }
305
- else {
306
- lines.push(`\nExample event payload:`);
307
- lines.push(`{`);
308
- lines.push(` "event": "vod_watch"`);
309
- lines.push(`}`);
310
- }
311
- if (result.errors.length > 0) {
312
- lines.push(`\nWarnings/Errors:`);
313
- for (const error of result.errors) {
314
- lines.push(`- ${error}`);
315
- }
316
- }
317
- return lines.join("\n");
318
- }
319
- // ============================================================================
320
- // Exports
321
- // ============================================================================
322
- export const vodWatchingWorkflow = {
323
- id: "vod-watching",
324
- name: "VOD Watching Campaign",
325
- execute: executeVodWatchingWorkflow,
326
- };