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