@open-loyalty/mcp-server 1.1.0 → 1.3.3

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 (112) hide show
  1. package/README.md +180 -177
  2. package/dist/auth/provider.js +2 -14
  3. package/dist/auth/storage.js +22 -0
  4. package/dist/client/http.js +10 -0
  5. package/dist/config.d.ts +0 -13
  6. package/dist/config.js +0 -14
  7. package/dist/http.js +35 -3
  8. package/dist/instructions.d.ts +5 -0
  9. package/dist/instructions.js +440 -0
  10. package/dist/prompts/fan-engagement-setup.d.ts +107 -0
  11. package/dist/prompts/fan-engagement-setup.js +492 -0
  12. package/dist/server.d.ts +1 -1
  13. package/dist/server.js +60 -273
  14. package/dist/tools/achievement/handlers.d.ts +117 -0
  15. package/dist/tools/achievement/handlers.js +161 -0
  16. package/dist/tools/achievement/index.d.ts +479 -0
  17. package/dist/tools/achievement/index.js +74 -0
  18. package/dist/tools/achievement/schemas.d.ts +433 -0
  19. package/dist/tools/achievement/schemas.js +142 -0
  20. package/dist/tools/achievement.d.ts +141 -121
  21. package/dist/tools/achievement.js +60 -24
  22. package/dist/tools/admin.d.ts +6 -6
  23. package/dist/tools/admin.js +12 -12
  24. package/dist/tools/analytics.d.ts +11 -11
  25. package/dist/tools/analytics.js +30 -29
  26. package/dist/tools/apikey.d.ts +3 -3
  27. package/dist/tools/apikey.js +6 -6
  28. package/dist/tools/audit.d.ts +2 -2
  29. package/dist/tools/audit.js +4 -4
  30. package/dist/tools/badge.d.ts +6 -6
  31. package/dist/tools/badge.js +23 -18
  32. package/dist/tools/campaign/handlers.d.ts +42 -0
  33. package/dist/tools/campaign/handlers.js +223 -0
  34. package/dist/tools/campaign/index.d.ts +783 -0
  35. package/dist/tools/campaign/index.js +117 -0
  36. package/dist/tools/campaign/member-handlers.d.ts +60 -0
  37. package/dist/tools/campaign/member-handlers.js +159 -0
  38. package/dist/tools/campaign/schemas.d.ts +704 -0
  39. package/dist/tools/campaign/schemas.js +259 -0
  40. package/dist/tools/campaign/types.d.ts +161 -0
  41. package/dist/tools/campaign/types.js +2 -0
  42. package/dist/tools/custom-event.d.ts +315 -0
  43. package/dist/tools/custom-event.js +270 -0
  44. package/dist/tools/export.d.ts +4 -4
  45. package/dist/tools/export.js +12 -12
  46. package/dist/tools/import.d.ts +3 -3
  47. package/dist/tools/import.js +23 -15
  48. package/dist/tools/index.js +13 -5
  49. package/dist/tools/member/handlers.d.ts +111 -0
  50. package/dist/tools/member/handlers.js +206 -0
  51. package/dist/tools/member/index.d.ts +169 -0
  52. package/dist/tools/member/index.js +92 -0
  53. package/dist/tools/member/schemas.d.ts +89 -0
  54. package/dist/tools/member/schemas.js +65 -0
  55. package/dist/tools/points.d.ts +7 -6
  56. package/dist/tools/points.js +21 -20
  57. package/dist/tools/referral/handlers.d.ts +47 -0
  58. package/dist/tools/referral/handlers.js +115 -0
  59. package/dist/tools/referral/index.d.ts +44 -0
  60. package/dist/tools/referral/index.js +44 -0
  61. package/dist/tools/referral/schemas.d.ts +34 -0
  62. package/dist/tools/referral/schemas.js +52 -0
  63. package/dist/tools/reward/handlers.d.ts +110 -0
  64. package/dist/tools/reward/handlers.js +289 -0
  65. package/dist/tools/reward/index.d.ts +177 -0
  66. package/dist/tools/reward/index.js +93 -0
  67. package/dist/tools/reward/schemas.d.ts +116 -0
  68. package/dist/tools/reward/schemas.js +92 -0
  69. package/dist/tools/role.d.ts +6 -6
  70. package/dist/tools/role.js +12 -12
  71. package/dist/tools/segment/handlers.d.ts +87 -0
  72. package/dist/tools/segment/handlers.js +174 -0
  73. package/dist/tools/segment/index.d.ts +395 -0
  74. package/dist/tools/segment/index.js +88 -0
  75. package/dist/tools/segment/schemas.d.ts +337 -0
  76. package/dist/tools/segment/schemas.js +79 -0
  77. package/dist/tools/segment.d.ts +10 -10
  78. package/dist/tools/segment.js +55 -31
  79. package/dist/tools/store.d.ts +4 -4
  80. package/dist/tools/store.js +8 -8
  81. package/dist/tools/tierset.d.ts +10 -10
  82. package/dist/tools/tierset.js +69 -37
  83. package/dist/tools/transaction.d.ts +4 -4
  84. package/dist/tools/transaction.js +12 -12
  85. package/dist/tools/wallet-type.d.ts +221 -16
  86. package/dist/tools/wallet-type.js +248 -17
  87. package/dist/tools/webhook.d.ts +6 -6
  88. package/dist/tools/webhook.js +90 -31
  89. package/dist/types/schemas/achievement.d.ts +18 -18
  90. package/dist/types/schemas/campaign.d.ts +64 -184
  91. package/dist/types/schemas/campaign.js +2 -7
  92. package/dist/types/schemas/common.d.ts +5 -0
  93. package/dist/types/schemas/common.js +5 -0
  94. package/dist/types/schemas/member.d.ts +2 -2
  95. package/dist/types/schemas/reward.d.ts +94 -18
  96. package/dist/types/schemas/reward.js +8 -3
  97. package/dist/types/schemas/wallet-type.d.ts +306 -8
  98. package/dist/types/schemas/wallet-type.js +82 -1
  99. package/dist/utils/errors.js +32 -5
  100. package/dist/workflows/app-login-streak.d.ts +39 -0
  101. package/dist/workflows/app-login-streak.js +298 -0
  102. package/dist/workflows/early-arrival.d.ts +33 -0
  103. package/dist/workflows/early-arrival.js +148 -0
  104. package/dist/workflows/index.d.ts +101 -0
  105. package/dist/workflows/index.js +208 -0
  106. package/dist/workflows/match-attendance.d.ts +45 -0
  107. package/dist/workflows/match-attendance.js +308 -0
  108. package/dist/workflows/sportsbar-visit.d.ts +41 -0
  109. package/dist/workflows/sportsbar-visit.js +284 -0
  110. package/dist/workflows/vod-watching.d.ts +43 -0
  111. package/dist/workflows/vod-watching.js +326 -0
  112. package/package.json +8 -2
@@ -0,0 +1,440 @@
1
+ /**
2
+ * MCP Server Instructions - provides context and guidance for AI agents
3
+ * using the Open Loyalty MCP server.
4
+ */
5
+ export const SERVER_INSTRUCTIONS = `
6
+ Open Loyalty MCP Server - Complete Loyalty Program Management
7
+
8
+ ## Domain Model
9
+
10
+ Member (loyalty program participant)
11
+ └── Points (wallet balance, transfers)
12
+ └── Tier (current level: Bronze, Silver, Gold)
13
+ └── Transactions (purchase history)
14
+ └── Rewards (redeemed coupons)
15
+ └── Achievements (gamification progress)
16
+ └── Badges (visual rewards from achievements)
17
+
18
+ TierSet (loyalty program structure)
19
+ └── Conditions (criteria: activeUnits, totalSpending)
20
+ └── Tiers (levels with thresholds)
21
+
22
+ WalletType (points currency configuration)
23
+
24
+ Reward (redeemable items)
25
+ └── Categories (reward groupings)
26
+
27
+ Campaign (automated points/rewards rules)
28
+ └── Type (earning, spending, custom, instant_reward)
29
+ └── Trigger (transaction, custom_event, points_transfer)
30
+ └── Rules (SKU, category, transaction amount conditions)
31
+ └── Effects (give_points, multiply_points, percentage_discount)
32
+ └── Targeting (segments, tiers for audience)
33
+
34
+ Segment (member audience grouping)
35
+ └── Parts (groups of criteria - OR logic between parts)
36
+ └── Criteria (conditions - AND logic within part)
37
+ Types: transaction_count (working; requires min+max). Other types may be rejected by the API.
38
+
39
+ Achievement (gamification goals)
40
+ └── Trigger (transaction, custom_event, points_transfer, reward_redemption, referral, achievement, tier_change, profile_update)
41
+ └── CompleteRule (periodGoal, period type, unique counting)
42
+ └── Badge (visual reward when completed)
43
+
44
+ Badge (visual recognition)
45
+ └── Linked to achievements via badgeTypeId
46
+ └── Auto-created when referenced by achievement
47
+
48
+ ## Key Workflows
49
+
50
+ ### 1. Create 3-tier Loyalty Program:
51
+ RECOMMENDED WORKFLOW:
52
+ 1. wallet_type_list → Get wallet code (usually "default")
53
+ 2. tierset_list → Check if tier set already exists
54
+ 3. IF EXISTS: tierset_get → Get conditionId from existing tier set
55
+ ELSE: tierset_create → Create new, then tierset_get to get conditionId
56
+ 4. tierset_update_tiers → Define tier thresholds using conditionId
57
+ 5. tierset_get_tiers → Verify tiers created correctly
58
+
59
+ GOTCHA - Valid tier condition attributes:
60
+ - activeUnits (current spendable balance)
61
+ - totalEarnedUnits (lifetime points - NOT 'earnedUnits'!)
62
+ - totalSpending (lifetime spend amount)
63
+ - monthsSinceJoiningProgram (tenure in months)
64
+ - cumulatedEarnedUnits (similar to totalEarnedUnits)
65
+
66
+ COMMON MISTAKE: Using 'earnedUnits' will fail - use 'totalEarnedUnits' for lifetime points.
67
+
68
+ ### 2. Register and Reward Member:
69
+ member_create → points_add (welcome bonus) → member_get (verify)
70
+
71
+ ### 3. Record Purchase and Earn Points:
72
+ transaction_create (with customerData) → triggers campaigns → points auto-added
73
+
74
+ ### 4. Redeem Reward:
75
+ reward_list → reward_buy (deducts points) → reward_redeem (mark coupon used)
76
+
77
+ ### 5. Assign Unmatched Transaction:
78
+ transaction_list (matched=false) → transaction_assign_member → points earned
79
+
80
+ ### 6. Check Member Tier Progress:
81
+ member_get_tier_progress → shows current tier, next tier, progress %
82
+
83
+ ### 7. Double Points for VIP Members:
84
+ segment_create (with transaction_count criteria) → campaign_create (targeting that segment with give_points effect and pointsRule: "transaction.grossValue * 2")
85
+
86
+ ### 8. Purchase Achievement with Badge:
87
+ badge_list (find or note badgeTypeId) → achievement_create (type+trigger+aggregation+period required, badgeTypeId)
88
+
89
+ ### 9. Create Targeted Promotion:
90
+ segment_create (define audience) → campaign_create (type: earning, target: segment, segmentIds: [segmentId])
91
+
92
+ ### 10. Track Member Gamification:
93
+ achievement_list_member_achievements → badge_get_member_badges → achievement_get_member_progress
94
+
95
+ ## Discovery Paths:
96
+ - Members: member_list → member_get → points_get_balance
97
+ - Tiers: tierset_list → tierset_get → tierset_get_tiers
98
+ - Rewards: reward_category_list → reward_list → reward_get
99
+ - Transactions: transaction_list → transaction_get
100
+ - Campaigns: campaign_list → campaign_get → campaign_simulate
101
+ - Segments: segment_list → segment_get → segment_get_members → campaign_create (audience targeting)
102
+ - Achievements: achievement_list → badge_list → achievement_create (with badge)
103
+ - Member Gamification: achievement_list_member_achievements → badge_get_member_badges
104
+
105
+ ## Important Patterns:
106
+ - TIER SETUP: conditionId REQUIRED for tier thresholds
107
+ 1. tierset_create returns conditions but you need the id from tierset_get
108
+ 2. The conditionId is in tierset_get response: conditions[].id (this IS the conditionId)
109
+ 3. Use this conditionId in tierset_update_tiers for each tier's threshold
110
+ - TIER ATTRIBUTES: Use 'totalEarnedUnits' (NOT 'earnedUnits') for lifetime points
111
+ - walletType uses CODE (e.g., 'default'), not UUID
112
+ - Points operations: check balance with points_get_balance before spending
113
+ - Reward flow: reward_buy returns couponCode, use reward_redeem to mark used
114
+ - Transactions auto-match to members via customerData (email, phone, loyaltyCardNumber)
115
+
116
+ ### Pagination:
117
+ - Traditional pagination: use page + perPage params
118
+ - Cursor pagination: provide cursor from previous response for efficient deep pagination
119
+ - Cursor-enabled tools: member_list, transaction_list, points_get_history
120
+ - First scroll request: cursor="" (empty string)
121
+ - Subsequent requests: use cursor value from previous response
122
+ - When cursor provided, page param is ignored
123
+
124
+ ### Campaign Patterns:
125
+ - Campaign types: direct (standard), referral (referral programs)
126
+ - Triggers: transaction (purchase), custom_event, time, achievement, etc.
127
+ - Effects: give_points, give_reward, deduct_unit
128
+ - Target campaigns to segments or tiers using audience.target: "segment" and audience.segments array
129
+ - campaign_create requires activity.startsAt, rules[].name, and effects[].effect (use key effect, not type). pointsRule is a STRING expression.
130
+
131
+ ### Points Expression (pointsRule):
132
+ pointsRule is a STRING expression, not an object. Examples:
133
+ - Fixed: "100"
134
+ - Per dollar: "transaction.grossValue * 10"
135
+ - Category-based: "transaction.category('electronics').grossValue * 5"
136
+ - Capped: "(transaction.grossValue * 2 >= 100) ? 100 : transaction.grossValue * 2"
137
+ - Rounded: "round_up(0.1 * transaction.grossValue)"
138
+
139
+ ### Segment Patterns:
140
+ - Parts use OR logic (member matches ANY part)
141
+ - Criteria within a part use AND logic (member must match ALL criteria in that part)
142
+ - Common criteria: transaction_count (working; requires min+max). Other criteria may be rejected by the API.
143
+
144
+ ### Achievement Patterns:
145
+ - Triggers: transaction, custom_event, points_transfer, reward_redemption, referral, achievement, tier_change, profile_update
146
+ - periodGoal sets the target (e.g., 5 purchases, 1000 points spent)
147
+ - period.type defines timeframe: day, week, month, year, last_day, calendarDays, calendarWeeks, calendarMonths, calendarYears
148
+ - aggregation.type defines counting method: quantity (count events only)
149
+ - Link to badge via badgeTypeId - badge auto-created if doesn't exist
150
+ - uniqueAttribute for counting distinct values (e.g., unique products)
151
+
152
+ ### Achievement Period Types:
153
+ - "day": Count all-time when consecutive=1
154
+ - "week": Count per week (use consecutive=1 for all-time weekly tracking)
155
+ - "month": Count per month
156
+ - "year": Count per year
157
+ - "last_day": Rolling window of N days (e.g., value: 7 for last 7 days)
158
+ - "calendarDays": Reset daily at midnight
159
+ - "calendarWeeks": Reset weekly (Monday)
160
+ - "calendarMonths": Reset monthly (1st of month)
161
+ - "calendarYears": Reset yearly (January 1st)
162
+
163
+ ### Streak Achievement Example (7-day login streak):
164
+ {
165
+ "rules": [{
166
+ "trigger": "custom_event",
167
+ "event": "app_login",
168
+ "type": "direct",
169
+ "aggregation": {"type": "quantity"},
170
+ "completeRule": {
171
+ "periodGoal": 1,
172
+ "period": {"type": "last_day", "value": 7, "consecutive": 1}
173
+ },
174
+ "limit": {
175
+ "interval": {"type": "calendarDays", "value": 1},
176
+ "value": 1
177
+ }
178
+ }]
179
+ }
180
+
181
+ ### Custom Event Workflows:
182
+
183
+ #### Create Custom Event Campaign:
184
+ 1. custom_event_schema_list → Check if event type exists
185
+ 2. custom_event_schema_create (if needed) → Define event type and fields
186
+ 3. campaign_create with trigger: "custom_event", event: "{event_type}"
187
+ 4. Send events via custom_event_send to trigger campaign
188
+
189
+ #### Create Achievement with Custom Event:
190
+ 1. custom_event_schema_create → Define event (e.g., "location_visit")
191
+ 2. achievement_create with:
192
+ - rules[].trigger: "custom_event"
193
+ - rules[].event: "{event_type}"
194
+ - rules[].type: "direct"
195
+ - rules[].aggregation.type: "quantity"
196
+ - rules[].completeRule.periodGoal: {count}
197
+ - rules[].completeRule.period: { type: "day", consecutive: 1 } (all-time)
198
+
199
+ #### Create Campaign Triggered by Achievement:
200
+ 1. achievement_create → Get achievementId from response
201
+ 2. campaign_create with:
202
+ - trigger: "achievement"
203
+ - achievementId: "{achievement_id}"
204
+ - rules with effects (give_points, give_reward)
205
+
206
+ ### Condition Operators (for campaigns/achievements):
207
+ - is_equal, is_not_equal
208
+ - gte, gt, lte, lt
209
+ - is_between, is_not_between
210
+ - is_time_between
211
+ - is_day_of_week, is_day_of_month
212
+ - contains, not_contains
213
+ - starts_with, ends_with
214
+ - one_of, not_one_of
215
+ - expression (for custom logic)
216
+
217
+ ## Common Campaign Patterns (Industry-Agnostic)
218
+
219
+ These patterns work for any loyalty program - retail, QSR, aviation, fan engagement, hospitality, etc.
220
+
221
+ ### Pattern 1: Count Events Toward Goal (Achievements)
222
+ Use case: Track member actions (visits, purchases, logins, check-ins) toward a milestone.
223
+ 1. custom_event_schema_create → Define your action type (e.g., "store_visit", "app_login")
224
+ 2. achievement_create with:
225
+ - trigger: "custom_event"
226
+ - event: "{your_event_code}"
227
+ - aggregation: { type: "quantity" }
228
+ - completeRule: { periodGoal: {count}, period: { type: "day", consecutive: 1 } }
229
+ 3. custom_event_send to log each action
230
+
231
+ ### Pattern 2: Points Per Action (Instant Rewards)
232
+ Use case: Award instant points for each qualifying action.
233
+ 1. custom_event_schema_create (if not using transaction)
234
+ 2. campaign_create with:
235
+ - trigger: "custom_event" (or "transaction")
236
+ - event: "{event_code}" (for custom events)
237
+ - rules: [{ effects: [{ effect: "give_points", pointsRule: "50" }] }]
238
+
239
+ ### Pattern 3: Conditional Rewards (Bonus Conditions)
240
+ Use case: Award points only when a condition is met (e.g., early arrival, large purchase).
241
+ Use ternary expressions in pointsRule instead of conditions array:
242
+ - pointsRule: "event.body.minutes_before >= 60 ? 25 : 0"
243
+ - pointsRule: "transaction.grossValue >= 100 ? 50 : 0"
244
+
245
+ ### Pattern 4: Execution Limits (Anti-Fraud)
246
+ Use case: Limit rewards to prevent abuse (once per day, once per week).
247
+ Campaign limits structure:
248
+ {
249
+ "limits": {
250
+ "executionsPerMember": {
251
+ "value": 1,
252
+ "interval": { "type": "calendarDays", "value": 1 }
253
+ }
254
+ }
255
+ }
256
+ Note: Use "calendarDays" (not "days"), "calendarWeeks", "calendarMonths", "calendarYears".
257
+ Omit interval entirely for lifetime/forever limit.
258
+
259
+ ### Pattern 5: Achievement-Triggered Bonus
260
+ Use case: Award bonus points/rewards when member completes an achievement.
261
+ 1. achievement_create → Get achievementId from response
262
+ 2. campaign_create with:
263
+ - trigger: "achievement"
264
+ - achievementId: "{achievement_id}"
265
+ - rules with give_points or give_reward effect
266
+
267
+ ### Pattern 6: Tiered Milestones
268
+ Use case: Multiple achievement levels (bronze/silver/gold, 5/10/25 visits).
269
+ Create multiple achievements with increasing periodGoal values,
270
+ each linked to a different bonus campaign with increasing rewards.
271
+
272
+ ### Pattern 7: Time-Limited Promotion
273
+ Use case: Seasonal or promotional campaigns.
274
+ {
275
+ "activity": {
276
+ "startsAt": "2026-01-01 00:00+00:00",
277
+ "endsAt": "2026-03-31 23:59+00:00"
278
+ }
279
+ }
280
+
281
+ ### Pattern 8: Streak Tracking
282
+ Use case: Reward consecutive daily/weekly actions (login streaks, workout streaks).
283
+ Achievement with:
284
+ - completeRule.period: { type: "last_day", value: 7 } (rolling 7-day window)
285
+ - limit: { value: 1, interval: { type: "calendarDays", value: 1 } } (max 1 per day)
286
+
287
+ ## Phase 3: Analytics, Admin, Roles & Stores
288
+
289
+ ### Domain Model (Extended)
290
+
291
+ Admin (system user)
292
+ └── Roles (permission sets)
293
+ └── Permissions (resource + access level)
294
+ └── API Keys (programmatic access)
295
+
296
+ Store (multi-tenant container)
297
+ └── Members, Campaigns, Rewards (isolated per store)
298
+
299
+ Audit Log (compliance tracking)
300
+ └── eventType, entityType, entityId, username, timestamp
301
+
302
+ ### Analytics Workflows:
303
+
304
+ #### 11. Get Program Overview:
305
+ analytics_dashboard → analytics_tiers → analytics_members
306
+
307
+ #### 12. Analyze Points Economy:
308
+ analytics_points → analytics_units (per wallet) → points_get_histogram
309
+
310
+ #### 13. Measure Campaign Performance:
311
+ analytics_campaigns → analytics_campaign_detail (specific campaign)
312
+
313
+ #### 14. Track Transactions:
314
+ analytics_transactions → transaction_list (details)
315
+
316
+ ### Aggregation Queries (Top Spenders, Purchase Analysis):
317
+
318
+ IMPORTANT: For queries like "top 5 spenders in July 2025", use this approach:
319
+
320
+ #### 15. Find Top Spenders by Date Range:
321
+ 1. transaction_list(purchasedAtFrom, purchasedAtTo, perPage=50, cursor='') - returns customerId with each transaction
322
+ 2. Use cursor pagination to fetch ALL pages - even if there are 1000+ transactions
323
+ 3. Aggregate grossValue by customerId in your code
324
+ 4. Sort by total spent, take top N
325
+ 5. member_get for each top spender to get names/details
326
+
327
+ CRITICAL - DO NOT TRY TO BE SMART OR OPTIMIZE:
328
+ - ALWAYS iterate through ALL pages using cursor pagination - this is the ONLY correct approach
329
+ - DO NOT skip pages or try to sample data - you will get inaccurate results
330
+ - DO NOT use transaction_get individually - transaction_list already includes customerId
331
+ - DO NOT try to find "smarter" analytics endpoints - they don't exist for per-customer aggregation
332
+ - Large datasets (1000+ transactions) are normal - just keep paginating until cursor is empty
333
+ - Start with cursor='' (empty string), use returned cursor for next request, repeat until done
334
+
335
+ Example: Top 5 spenders July 2025
336
+ - First request: transaction_list(purchasedAtFrom: "2025-07-01", purchasedAtTo: "2025-07-31", perPage: 50, cursor: "")
337
+ - Each result includes: transactionId, grossValue, customerId, purchasedAt
338
+ - Keep fetching with returned cursor until response has no cursor or empty transactions
339
+ - Even if there are 1500 transactions (30 pages), iterate through ALL of them
340
+ - Group by customerId, sum grossValue, sort descending, take 5
341
+
342
+ ### Admin & Security Workflows:
343
+
344
+ #### 15. Create Admin with Limited Role:
345
+ acl_get_resources → role_create → admin_create (with roleId)
346
+
347
+ #### 16. Generate API Key for Integration:
348
+ admin_get → apikey_create → SAVE TOKEN IMMEDIATELY (shown once!)
349
+
350
+ #### 17. Audit User Actions:
351
+ audit_list (filter by username/entity) → audit_export (compliance report)
352
+
353
+ ### Store Multi-Tenancy:
354
+
355
+ #### 18. Create New Store:
356
+ store_create → configure campaigns/tiers → member_create (with storeCode)
357
+
358
+ ### Analytics Query Patterns:
359
+ - All analytics tools support dateFrom/dateTo ISO date filters
360
+ - analytics_dashboard: high-level program metrics
361
+ - analytics_units: wallet-specific metrics (requires walletTypeCode)
362
+ - analytics_campaign_detail: detailed metrics for single campaign
363
+
364
+ ### Admin → Role → Permission Model:
365
+ ┌─────────┐ ┌──────┐ ┌────────────┐
366
+ │ Admin │────▶│ Role │────▶│ Permission │
367
+ └─────────┘ └──────┘ └────────────┘
368
+ │ │
369
+ │ resource + access
370
+ │ (VIEW, MODIFY, etc.)
371
+
372
+ ┌─────────┐
373
+ │ API Key │
374
+ └─────────┘
375
+
376
+ ### Store Multi-Tenancy:
377
+ - Each store is isolated: members, campaigns, rewards, transactions
378
+ - storeCode parameter routes requests to correct tenant
379
+ - Default store used when storeCode omitted
380
+ - IMPORTANT: Do NOT pass storeCode parameter unless the user explicitly asks to work with a different store. The configured default store should always be used unless the user requests otherwise.
381
+
382
+ ## Phase 4: Webhooks, Import & Export
383
+
384
+ ### Domain Model (Extended)
385
+
386
+ Webhook Subscription (event notification)
387
+ └── eventName (event to subscribe to)
388
+ └── url (callback endpoint)
389
+ └── headers (custom HTTP headers)
390
+
391
+ Import (bulk data upload)
392
+ └── type: member, groupValue, segmentMembers, unitTransferAdding, etc.
393
+ └── status: pending, processing, succeed, failed
394
+ └── items (individual row results)
395
+
396
+ Export (bulk data download)
397
+ └── type: campaignCode, member, memberTier, memberSegment, rewardFulfillment
398
+ └── status: pending, done, failed, error
399
+ └── CSV file (when status='done')
400
+
401
+ ### Webhook Workflows:
402
+
403
+ #### 19. Subscribe to Member Events for CRM Sync:
404
+ webhook_events → webhook_create (eventName: 'member.created', url: 'https://crm.example.com/webhook')
405
+
406
+ #### 20. List and Manage Subscriptions:
407
+ webhook_list → webhook_get → webhook_update or webhook_delete
408
+
409
+ ### Import Workflows:
410
+
411
+ #### 21. Bulk Import Members from CSV:
412
+ import_create (type: 'member', fileContent: CSV data) → import_list → import_get (check status)
413
+
414
+ #### 22. Bulk Add Points to Members:
415
+ import_create (type: 'unitTransferAdding', fileContent: CSV) → poll import_get until complete
416
+
417
+ ### Export Workflows:
418
+
419
+ #### 23. Export Campaign Codes:
420
+ export_create (type: 'campaignCode', filters: { campaignId }) → poll export_get (until status='done') → export_download
421
+
422
+ #### 24. Export Member Data:
423
+ export_create (type: 'member') → export_get → export_download (returns CSV)
424
+
425
+ ### Webhook Patterns:
426
+ - Use webhook_events to discover available event types before subscribing
427
+ - API uses wrapper: { webhookSubscription: { eventName, url, headers? } }
428
+ - Common events: member.created, member.updated, transaction.created, reward.purchased
429
+
430
+ ### Import Patterns:
431
+ - Import is async: create returns importId, poll status with import_get
432
+ - CSV format required - provide plain text, not base64
433
+ - Types: member, groupValue, segmentMembers, unitTransferAdding, unitTransferSpending, transaction, campaignCode, rewardCoupon
434
+
435
+ ### Export Patterns:
436
+ - Export is async: create returns exportId, poll status until 'done'
437
+ - API body wrapper varies by type: { campaignCode: { filters... } }
438
+ - Only call export_download when status='done'
439
+ - Types: campaignCode, member, memberTier, memberSegment, rewardFulfillment
440
+ `;
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Fan Engagement Setup Prompts
3
+ *
4
+ * MCP prompt templates for guided campaign setup.
5
+ * These define conversational flows and default values for AI agents
6
+ * to help program admins create fan engagement campaigns.
7
+ */
8
+ export interface WorkflowQuestion {
9
+ id: string;
10
+ question: string;
11
+ type: "number" | "boolean" | "string" | "select";
12
+ default?: unknown;
13
+ options?: string[];
14
+ validation?: (value: unknown) => boolean;
15
+ hint?: string;
16
+ }
17
+ export interface WorkflowStep {
18
+ id: string;
19
+ action: string;
20
+ tool: string;
21
+ description: string;
22
+ }
23
+ export interface WorkflowDefinition {
24
+ id: string;
25
+ name: string;
26
+ description: string;
27
+ triggerPhrases: string[];
28
+ questions: WorkflowQuestion[];
29
+ steps: WorkflowStep[];
30
+ }
31
+ export declare const DEFAULTS: {
32
+ readonly matchAttendance: {
33
+ readonly coinsPerMatch: 50;
34
+ readonly milestones: number[];
35
+ readonly milestoneBonuses: Record<string | number, number>;
36
+ readonly limitPerDay: 1;
37
+ readonly badges: Record<string | number, string>;
38
+ };
39
+ readonly earlyArrival: {
40
+ readonly minutesBefore: 60;
41
+ readonly coinsPerArrival: 25;
42
+ readonly limitPerMatch: 1;
43
+ };
44
+ readonly sportsbarVisit: {
45
+ readonly coinsPerVisit: 50;
46
+ readonly visitMilestone: 5;
47
+ readonly milestoneBonus: 500;
48
+ readonly limitPerDay: 1;
49
+ };
50
+ readonly vodWatching: {
51
+ readonly trackBy: "views" | "minutes";
52
+ readonly coinsPerUnit: 10;
53
+ readonly unitSize: 10;
54
+ readonly achievementMinutes: 300;
55
+ readonly achievementBonus: 200;
56
+ };
57
+ readonly appLoginStreak: {
58
+ readonly coinsPerLogin: 5;
59
+ readonly streakDays: 7;
60
+ readonly streakBonus: 50;
61
+ readonly limitPerDay: 1;
62
+ };
63
+ readonly seasonDates: {
64
+ readonly start: string;
65
+ readonly end: string;
66
+ };
67
+ };
68
+ export declare const MATCH_ATTENDANCE_WORKFLOW: WorkflowDefinition;
69
+ export declare const EARLY_ARRIVAL_WORKFLOW: WorkflowDefinition;
70
+ export declare const SPORTSBAR_VISIT_WORKFLOW: WorkflowDefinition;
71
+ export declare const VOD_WATCHING_WORKFLOW: WorkflowDefinition;
72
+ export declare const APP_LOGIN_STREAK_WORKFLOW: WorkflowDefinition;
73
+ export declare const ALL_WORKFLOWS: WorkflowDefinition[];
74
+ /**
75
+ * Find matching workflow based on user input
76
+ */
77
+ export declare function findMatchingWorkflow(userInput: string): WorkflowDefinition | undefined;
78
+ /**
79
+ * Get workflow by ID
80
+ */
81
+ export declare function getWorkflowById(id: string): WorkflowDefinition | undefined;
82
+ /**
83
+ * Parse comma-separated values to array
84
+ */
85
+ export declare function parseCommaSeparated(value: string): string[];
86
+ /**
87
+ * Parse milestones (handles both numbers and percentages like "80%")
88
+ */
89
+ export declare function parseMilestones(value: string): (number | string)[];
90
+ /**
91
+ * Format ISO date for Open Loyalty (YYYY-MM-DD HH:mm+TZ)
92
+ */
93
+ export declare function formatOLDate(date: string | Date): string;
94
+ export declare const AGENT_PROMPTS: {
95
+ /**
96
+ * System prompt for fan engagement setup
97
+ */
98
+ systemPrompt: string;
99
+ /**
100
+ * Workflow completion template
101
+ */
102
+ completionTemplate: (results: {
103
+ campaignIds: string[];
104
+ achievementIds: string[];
105
+ summary: string;
106
+ }) => string;
107
+ };