@open-loyalty/mcp-server 1.0.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.
Files changed (99) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +654 -0
  3. package/dist/client/http.d.ts +8 -0
  4. package/dist/client/http.js +69 -0
  5. package/dist/config.d.ts +17 -0
  6. package/dist/config.js +40 -0
  7. package/dist/index.d.ts +2 -0
  8. package/dist/index.js +20 -0
  9. package/dist/server.d.ts +4 -0
  10. package/dist/server.js +334 -0
  11. package/dist/tools/achievement.d.ts +983 -0
  12. package/dist/tools/achievement.js +311 -0
  13. package/dist/tools/admin.d.ts +153 -0
  14. package/dist/tools/admin.js +193 -0
  15. package/dist/tools/analytics.d.ts +162 -0
  16. package/dist/tools/analytics.js +245 -0
  17. package/dist/tools/apikey.d.ts +72 -0
  18. package/dist/tools/apikey.js +78 -0
  19. package/dist/tools/audit.d.ts +107 -0
  20. package/dist/tools/audit.js +90 -0
  21. package/dist/tools/badge.d.ts +135 -0
  22. package/dist/tools/badge.js +165 -0
  23. package/dist/tools/campaign.d.ts +1775 -0
  24. package/dist/tools/campaign.js +724 -0
  25. package/dist/tools/export.d.ts +110 -0
  26. package/dist/tools/export.js +147 -0
  27. package/dist/tools/import.d.ts +110 -0
  28. package/dist/tools/import.js +126 -0
  29. package/dist/tools/index.d.ts +22 -0
  30. package/dist/tools/index.js +527 -0
  31. package/dist/tools/member.d.ts +345 -0
  32. package/dist/tools/member.js +358 -0
  33. package/dist/tools/member.test.d.ts +1 -0
  34. package/dist/tools/member.test.js +213 -0
  35. package/dist/tools/points.d.ts +188 -0
  36. package/dist/tools/points.js +306 -0
  37. package/dist/tools/points.test.d.ts +1 -0
  38. package/dist/tools/points.test.js +292 -0
  39. package/dist/tools/reward.d.ts +261 -0
  40. package/dist/tools/reward.js +371 -0
  41. package/dist/tools/reward.test.d.ts +1 -0
  42. package/dist/tools/reward.test.js +240 -0
  43. package/dist/tools/role.d.ts +161 -0
  44. package/dist/tools/role.js +160 -0
  45. package/dist/tools/segment.d.ts +797 -0
  46. package/dist/tools/segment.js +299 -0
  47. package/dist/tools/store.d.ts +101 -0
  48. package/dist/tools/store.js +117 -0
  49. package/dist/tools/tierset.d.ts +288 -0
  50. package/dist/tools/tierset.js +244 -0
  51. package/dist/tools/transaction.d.ts +357 -0
  52. package/dist/tools/transaction.js +242 -0
  53. package/dist/tools/transaction.test.d.ts +1 -0
  54. package/dist/tools/transaction.test.js +235 -0
  55. package/dist/tools/wallet-type.d.ts +32 -0
  56. package/dist/tools/wallet-type.js +58 -0
  57. package/dist/tools/webhook.d.ts +179 -0
  58. package/dist/tools/webhook.js +171 -0
  59. package/dist/types/schemas/achievement.d.ts +1116 -0
  60. package/dist/types/schemas/achievement.js +172 -0
  61. package/dist/types/schemas/admin.d.ts +263 -0
  62. package/dist/types/schemas/admin.js +99 -0
  63. package/dist/types/schemas/analytics.d.ts +542 -0
  64. package/dist/types/schemas/analytics.js +130 -0
  65. package/dist/types/schemas/badge.d.ts +131 -0
  66. package/dist/types/schemas/badge.js +48 -0
  67. package/dist/types/schemas/campaign.d.ts +2005 -0
  68. package/dist/types/schemas/campaign.js +189 -0
  69. package/dist/types/schemas/common.d.ts +52 -0
  70. package/dist/types/schemas/common.js +26 -0
  71. package/dist/types/schemas/export.d.ts +127 -0
  72. package/dist/types/schemas/export.js +43 -0
  73. package/dist/types/schemas/import.d.ts +344 -0
  74. package/dist/types/schemas/import.js +68 -0
  75. package/dist/types/schemas/member.d.ts +443 -0
  76. package/dist/types/schemas/member.js +92 -0
  77. package/dist/types/schemas/points.d.ts +188 -0
  78. package/dist/types/schemas/points.js +54 -0
  79. package/dist/types/schemas/reward.d.ts +278 -0
  80. package/dist/types/schemas/reward.js +69 -0
  81. package/dist/types/schemas/role.d.ts +260 -0
  82. package/dist/types/schemas/role.js +75 -0
  83. package/dist/types/schemas/segment.d.ts +592 -0
  84. package/dist/types/schemas/segment.js +114 -0
  85. package/dist/types/schemas/tierset.d.ts +552 -0
  86. package/dist/types/schemas/tierset.js +87 -0
  87. package/dist/types/schemas/transaction.d.ts +1022 -0
  88. package/dist/types/schemas/transaction.js +63 -0
  89. package/dist/types/schemas/wallet-type.d.ts +99 -0
  90. package/dist/types/schemas/wallet-type.js +17 -0
  91. package/dist/types/schemas/webhook.d.ts +195 -0
  92. package/dist/types/schemas/webhook.js +39 -0
  93. package/dist/utils/cursor.d.ts +84 -0
  94. package/dist/utils/cursor.js +117 -0
  95. package/dist/utils/errors.d.ts +12 -0
  96. package/dist/utils/errors.js +69 -0
  97. package/dist/utils/pagination.d.ts +39 -0
  98. package/dist/utils/pagination.js +77 -0
  99. package/package.json +65 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Open Loyalty
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,654 @@
1
+ # Open Loyalty MCP Server
2
+
3
+ MCP (Model Context Protocol) server for interacting with Open Loyalty API. This server enables AI agents like Claude to manage loyalty programs, members, points, rewards, and transactions.
4
+
5
+ ## Prerequisites
6
+
7
+ - Node.js 18 or later
8
+ - An Open Loyalty account with API access
9
+
10
+ ## Installation
11
+
12
+ ### Via npm (Recommended)
13
+
14
+ ```bash
15
+ npm install -g @openloyalty/mcp-server
16
+ ```
17
+
18
+ Or use directly with npx (no installation required):
19
+
20
+ ```bash
21
+ npx @openloyalty/mcp-server
22
+ ```
23
+
24
+ ### From Source
25
+
26
+ ```bash
27
+ git clone https://github.com/openloyalty/mcp-server.git
28
+ cd mcp-server
29
+ npm install
30
+ npm run build
31
+ ```
32
+
33
+ ## Configuration
34
+
35
+ The server requires the following environment variables:
36
+
37
+ | Variable | Description |
38
+ |----------|-------------|
39
+ | `OPENLOYALTY_API_URL` | Your Open Loyalty API URL (e.g., `https://api.openloyalty.io`) |
40
+ | `OPENLOYALTY_API_TOKEN` | Your API authentication token |
41
+ | `OPENLOYALTY_DEFAULT_STORE_CODE` | Default store code (e.g., `default`) |
42
+
43
+ For local development, create a `.env` file based on `.env.example`:
44
+
45
+ ```bash
46
+ cp .env.example .env
47
+ ```
48
+
49
+ ## Claude Desktop Configuration
50
+
51
+ Add this to your Claude Desktop configuration file:
52
+ - **macOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
53
+ - **Windows**: `%APPDATA%\Claude\claude_desktop_config.json`
54
+
55
+ ### Using npx (Recommended)
56
+
57
+ ```json
58
+ {
59
+ "mcpServers": {
60
+ "openloyalty": {
61
+ "command": "npx",
62
+ "args": ["-y", "@openloyalty/mcp-server"],
63
+ "env": {
64
+ "OPENLOYALTY_API_URL": "https://your-instance.openloyalty.io",
65
+ "OPENLOYALTY_API_TOKEN": "your-api-token",
66
+ "OPENLOYALTY_DEFAULT_STORE_CODE": "default"
67
+ }
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ ### Using Global Installation
74
+
75
+ ```json
76
+ {
77
+ "mcpServers": {
78
+ "openloyalty": {
79
+ "command": "openloyalty-mcp",
80
+ "env": {
81
+ "OPENLOYALTY_API_URL": "https://your-instance.openloyalty.io",
82
+ "OPENLOYALTY_API_TOKEN": "your-api-token",
83
+ "OPENLOYALTY_DEFAULT_STORE_CODE": "default"
84
+ }
85
+ }
86
+ }
87
+ }
88
+ ```
89
+
90
+ ### Using Local Build
91
+
92
+ ```json
93
+ {
94
+ "mcpServers": {
95
+ "openloyalty": {
96
+ "command": "node",
97
+ "args": ["/path/to/mcp-server/dist/index.js"],
98
+ "env": {
99
+ "OPENLOYALTY_API_URL": "https://your-instance.openloyalty.io",
100
+ "OPENLOYALTY_API_TOKEN": "your-api-token",
101
+ "OPENLOYALTY_DEFAULT_STORE_CODE": "default"
102
+ }
103
+ }
104
+ }
105
+ }
106
+ ```
107
+
108
+ ## Development
109
+
110
+ ```bash
111
+ # Run in development mode
112
+ npm run dev
113
+
114
+ # Build for production
115
+ npm run build
116
+
117
+ # Run tests
118
+ npm test
119
+
120
+ # Type checking
121
+ npm run typecheck
122
+ ```
123
+
124
+ ## Available Tools (112 total)
125
+
126
+ ### Wallet Types (2 tools)
127
+ - `openloyalty_wallet_type_list` - List all wallet types (point currencies)
128
+ - `openloyalty_wallet_type_get` - Get details for a specific wallet type
129
+
130
+ ### Tier Sets (6 tools)
131
+ - `openloyalty_tierset_list` - List all tier sets
132
+ - `openloyalty_tierset_create` - Create a new tier set
133
+ - `openloyalty_tierset_get` - Get tier set details with condition IDs
134
+ - `openloyalty_tierset_update` - Update tier set metadata
135
+ - `openloyalty_tierset_update_tiers` - Define tier thresholds
136
+ - `openloyalty_tierset_get_tiers` - Get all tiers in a tier set
137
+
138
+ ### Members (10 tools)
139
+ - `openloyalty_member_create` - Register a new loyalty program member
140
+ - `openloyalty_member_get` - Get member details including profile, points balance, and tier status
141
+ - `openloyalty_member_list` - Search and list members with optional filters
142
+ - `openloyalty_member_update` - Update member profile fields
143
+ - `openloyalty_member_activate` - Activate a deactivated member
144
+ - `openloyalty_member_deactivate` - Deactivate an active member
145
+ - `openloyalty_member_delete` - Permanently remove member (GDPR compliance)
146
+ - `openloyalty_member_get_tier_progress` - Get tier progression status
147
+ - `openloyalty_member_assign_tier` - Manually assign tier to member
148
+ - `openloyalty_member_remove_manual_tier` - Remove manual tier assignment
149
+
150
+ ### Points (6 tools)
151
+ - `openloyalty_points_add` - Add points to member wallet (with optional expiration/lock)
152
+ - `openloyalty_points_spend` - Deduct points from member wallet
153
+ - `openloyalty_points_transfer` - Transfer points between members (P2P)
154
+ - `openloyalty_points_get_balance` - Get member points balance breakdown
155
+ - `openloyalty_points_get_history` - Get points transaction history
156
+ - `openloyalty_points_get_histogram` - Get points histogram for visualization
157
+
158
+ ### Rewards (9 tools)
159
+ - `openloyalty_reward_list` - List available rewards
160
+ - `openloyalty_reward_create` - Create a new reward
161
+ - `openloyalty_reward_get` - Get reward details
162
+ - `openloyalty_reward_update` - Update reward configuration
163
+ - `openloyalty_reward_activate` - Activate a reward
164
+ - `openloyalty_reward_deactivate` - Deactivate a reward
165
+ - `openloyalty_reward_buy` - Purchase reward for member (deducts points)
166
+ - `openloyalty_reward_redeem` - Mark coupon as used
167
+ - `openloyalty_reward_category_list` - List reward categories
168
+
169
+ ### Transactions (4 tools)
170
+ - `openloyalty_transaction_create` - Record a purchase transaction
171
+ - `openloyalty_transaction_get` - Get transaction details
172
+ - `openloyalty_transaction_list` - List transactions with filters
173
+ - `openloyalty_transaction_assign_member` - Assign unmatched transaction to member
174
+
175
+ ### Campaigns (12 tools)
176
+ - `openloyalty_campaign_list` - List all campaigns with optional filters
177
+ - `openloyalty_campaign_create` - Create campaign to automate engagement
178
+ - `openloyalty_campaign_get` - Get full campaign configuration
179
+ - `openloyalty_campaign_update` - Update campaign (full replacement)
180
+ - `openloyalty_campaign_patch` - Patch campaign (active/displayOrder only)
181
+ - `openloyalty_campaign_delete` - Permanently delete a campaign
182
+ - `openloyalty_campaign_simulate` - Preview campaign effects without executing
183
+ - `openloyalty_campaign_generate_codes` - Generate redemption codes
184
+ - `openloyalty_campaign_list_codes` - List redemption codes
185
+ - `openloyalty_campaign_get_available` - Get campaigns available for member
186
+ - `openloyalty_campaign_get_visible` - Get campaigns visible to member
187
+ - `openloyalty_campaign_get_leaderboard` - Get campaign leaderboard
188
+
189
+ ### Segments (9 tools)
190
+ - `openloyalty_segment_list` - List customer segments
191
+ - `openloyalty_segment_create` - Create segment to group members
192
+ - `openloyalty_segment_get` - Get segment details with criteria
193
+ - `openloyalty_segment_update` - Update segment configuration
194
+ - `openloyalty_segment_delete` - Permanently delete a segment
195
+ - `openloyalty_segment_get_members` - Get members matching segment
196
+ - `openloyalty_segment_activate` - Activate a segment
197
+ - `openloyalty_segment_deactivate` - Deactivate a segment
198
+ - `openloyalty_segment_get_resources` - Get resources associated with segment
199
+
200
+ ### Achievements (7 tools)
201
+ - `openloyalty_achievement_list` - List achievements
202
+ - `openloyalty_achievement_create` - Create achievement for gamification
203
+ - `openloyalty_achievement_get` - Get achievement details
204
+ - `openloyalty_achievement_update` - Update achievement (full replacement)
205
+ - `openloyalty_achievement_patch` - Patch achievement (active/displayOrder)
206
+ - `openloyalty_achievement_get_member_progress` - Get member's progress on achievement
207
+ - `openloyalty_achievement_list_member_achievements` - List member's achievements
208
+
209
+ ### Badges (4 tools)
210
+ - `openloyalty_badge_list` - List badge types
211
+ - `openloyalty_badge_get` - Get badge type details
212
+ - `openloyalty_badge_update` - Update badge type configuration
213
+ - `openloyalty_badge_get_member_badges` - Get badges earned by member
214
+
215
+ ### Analytics (9 tools)
216
+ - `openloyalty_analytics_tiers` - Get tier distribution with member counts
217
+ - `openloyalty_analytics_members` - Get member statistics (new, active, inactive)
218
+ - `openloyalty_analytics_points` - Get points statistics (issued, spent, expired)
219
+ - `openloyalty_analytics_transactions` - Get transaction statistics
220
+ - `openloyalty_analytics_referrals` - Get referral program statistics
221
+ - `openloyalty_analytics_campaigns` - Get campaign performance metrics
222
+ - `openloyalty_analytics_dashboard` - Get dashboard overview metrics
223
+ - `openloyalty_analytics_units` - Get wallet-specific metrics
224
+ - `openloyalty_analytics_campaign_detail` - Get detailed campaign analytics
225
+
226
+ ### Admin Users (6 tools)
227
+ - `openloyalty_admin_list` - List admin users
228
+ - `openloyalty_admin_create` - Create admin user
229
+ - `openloyalty_admin_get` - Get admin user details
230
+ - `openloyalty_admin_update` - Update admin user profile
231
+ - `openloyalty_admin_change_password` - Change admin password
232
+ - `openloyalty_admin_get_permissions` - Get admin permissions
233
+
234
+ ### Roles/ACL (6 tools)
235
+ - `openloyalty_role_list` - List roles
236
+ - `openloyalty_role_create` - Create role with permissions
237
+ - `openloyalty_role_get` - Get role details
238
+ - `openloyalty_role_update` - Update role
239
+ - `openloyalty_role_delete` - Delete role
240
+ - `openloyalty_acl_get_resources` - Get available ACL resources and actions
241
+
242
+ ### API Keys (3 tools)
243
+ - `openloyalty_apikey_create` - Create API key (token shown once!)
244
+ - `openloyalty_apikey_list` - List API keys for admin
245
+ - `openloyalty_apikey_delete` - Delete API key
246
+
247
+ ### Audit Logs (2 tools)
248
+ - `openloyalty_audit_list` - List audit log entries
249
+ - `openloyalty_audit_export` - Export audit logs
250
+
251
+ ### Stores (4 tools)
252
+ - `openloyalty_store_list` - List stores
253
+ - `openloyalty_store_create` - Create store for multi-tenancy
254
+ - `openloyalty_store_get` - Get store details
255
+ - `openloyalty_store_update` - Update store configuration
256
+
257
+ ### Webhooks (6 tools)
258
+ - `openloyalty_webhook_list` - List webhook subscriptions
259
+ - `openloyalty_webhook_create` - Create webhook subscription for event notifications
260
+ - `openloyalty_webhook_get` - Get webhook subscription details
261
+ - `openloyalty_webhook_update` - Update webhook subscription
262
+ - `openloyalty_webhook_delete` - Delete webhook subscription
263
+ - `openloyalty_webhook_events` - List available webhook event types
264
+
265
+ ### Import (3 tools)
266
+ - `openloyalty_import_create` - Create bulk import from CSV
267
+ - `openloyalty_import_list` - List imports with status
268
+ - `openloyalty_import_get` - Get import details and item statuses
269
+
270
+ ### Export (4 tools)
271
+ - `openloyalty_export_create` - Create data export (async)
272
+ - `openloyalty_export_list` - List exports with status
273
+ - `openloyalty_export_get` - Get export status and details
274
+ - `openloyalty_export_download` - Download export CSV (when status='done')
275
+
276
+ ## Example Workflows
277
+
278
+ ### 1. Create 3-Tier Loyalty Program
279
+
280
+ ```
281
+ openloyalty_wallet_type_list
282
+ openloyalty_tierset_create({ name: "VIP Program", conditions: [{ attribute: "activeUnits", walletType: "points" }] })
283
+ openloyalty_tierset_get({ tierSetId: "..." })
284
+ openloyalty_tierset_update_tiers({
285
+ tierSetId: "...",
286
+ tiers: [
287
+ { name: "Bronze", conditions: [{ conditionId: "xxx", value: 400 }] },
288
+ { name: "Silver", conditions: [{ conditionId: "xxx", value: 800 }] },
289
+ { name: "Gold", conditions: [{ conditionId: "xxx", value: 1200 }] }
290
+ ]
291
+ })
292
+ ```
293
+
294
+ ### 2. Full Member Lifecycle
295
+
296
+ ```
297
+ // Register member
298
+ openloyalty_member_create({ email: "john@example.com", firstName: "John", lastName: "Doe" })
299
+
300
+ // Add welcome bonus
301
+ openloyalty_points_add({ memberId: "...", points: 100, comment: "Welcome bonus" })
302
+
303
+ // Record purchase (auto-earns points via campaigns)
304
+ openloyalty_transaction_create({
305
+ header: { documentNumber: "INV-001", purchasedAt: "2024-01-15T10:00:00Z" },
306
+ items: [{ sku: "PROD-1", name: "Widget", grossValue: 99.99, category: "Electronics" }],
307
+ customerData: { email: "john@example.com" }
308
+ })
309
+
310
+ // Check tier progress
311
+ openloyalty_member_get_tier_progress({ memberId: "..." })
312
+ ```
313
+
314
+ ### 3. Reward Redemption Flow
315
+
316
+ ```
317
+ // List available rewards
318
+ openloyalty_reward_list({ active: true })
319
+
320
+ // Check member balance
321
+ openloyalty_points_get_balance({ memberId: "..." })
322
+
323
+ // Purchase reward (deducts points, returns coupon code)
324
+ openloyalty_reward_buy({ rewardId: "...", memberId: "..." })
325
+
326
+ // Later: mark coupon as used
327
+ openloyalty_reward_redeem({ memberId: "...", couponCode: "COUP-ABC123" })
328
+ ```
329
+
330
+ ### 4. Assign Unmatched Transaction
331
+
332
+ ```
333
+ // Find unmatched transactions
334
+ openloyalty_transaction_list({ matched: false })
335
+
336
+ // Assign to member (triggers point campaigns)
337
+ openloyalty_transaction_assign_member({ documentNumber: "INV-999", loyaltyCardNumber: "CARD-123" })
338
+ ```
339
+
340
+ ### 5. Create Double Points Campaign for Gold Tier
341
+
342
+ ```
343
+ // First, find the Gold tier level ID
344
+ openloyalty_tierset_get_tiers({ tierSetId: "..." })
345
+
346
+ // Create a segment targeting Gold tier members
347
+ openloyalty_segment_create({
348
+ name: "Gold Members",
349
+ parts: [{
350
+ criteria: [{
351
+ type: "tier",
352
+ tierIds: ["gold-level-id"]
353
+ }]
354
+ }]
355
+ })
356
+
357
+ // Create campaign with double points effect
358
+ openloyalty_campaign_create({
359
+ type: "direct",
360
+ trigger: "transaction",
361
+ translations: { en: { name: "Double Points for Gold", description: "Gold members earn 2x points" } },
362
+ activity: { startsAt: "2024-01-01T00:00:00Z" },
363
+ rules: [{
364
+ name: "Double points",
365
+ effects: [{
366
+ effect: "give_points",
367
+ pointsRule: { multiplier: 2 }
368
+ }]
369
+ }],
370
+ audience: {
371
+ target: "segment",
372
+ segments: ["segment-id"]
373
+ },
374
+ active: true
375
+ })
376
+
377
+ // Test the campaign before it triggers
378
+ openloyalty_campaign_simulate({
379
+ trigger: "transaction",
380
+ transaction: { grossValue: 100 },
381
+ customer: { email: "gold-member@example.com" }
382
+ })
383
+ ```
384
+
385
+ ### 6. Create VIP Segment Based on Transaction Count
386
+
387
+ ```
388
+ // Create segment for members with 10+ transactions
389
+ openloyalty_segment_create({
390
+ name: "VIP Customers",
391
+ description: "Members with 10 or more purchases",
392
+ parts: [{
393
+ criteria: [{
394
+ type: "transaction_count",
395
+ min: 10
396
+ }]
397
+ }],
398
+ active: true
399
+ })
400
+
401
+ // Check segment membership
402
+ openloyalty_segment_get_members({ segmentId: "..." })
403
+
404
+ // Use for campaign targeting
405
+ openloyalty_campaign_create({
406
+ type: "direct",
407
+ trigger: "transaction",
408
+ translations: { en: { name: "VIP Bonus" } },
409
+ activity: { startsAt: "2024-01-01T00:00:00Z" },
410
+ rules: [{
411
+ name: "VIP Bonus Points",
412
+ effects: [{ effect: "give_points", pointsRule: { value: 50 } }]
413
+ }],
414
+ audience: { target: "segment", segments: ["vip-segment-id"] },
415
+ active: true
416
+ })
417
+ ```
418
+
419
+ ### 7. Create Purchase Achievement with Badge
420
+
421
+ ```
422
+ // Create an achievement for making 5 purchases
423
+ openloyalty_achievement_create({
424
+ translations: { en: { name: "Frequent Shopper", description: "Make 5 purchases" } },
425
+ rules: [{
426
+ trigger: "transaction",
427
+ completeRule: {
428
+ periodGoal: 5,
429
+ period: { type: "forever" }
430
+ }
431
+ }],
432
+ badgeTypeId: "shopper-badge-id",
433
+ active: true
434
+ })
435
+
436
+ // Check member progress
437
+ openloyalty_achievement_get_member_progress({ memberId: "...", achievementId: "..." })
438
+
439
+ // List all member achievements and badges
440
+ openloyalty_achievement_list_member_achievements({ memberId: "..." })
441
+ openloyalty_badge_get_member_badges({ memberId: "..." })
442
+ ```
443
+
444
+ ### 8. Segment Logic: OR vs AND
445
+
446
+ ```
447
+ // Parts use OR logic - member matches if ANY part matches
448
+ // Criteria within parts use AND logic - must match ALL criteria in that part
449
+
450
+ // Example: (Gold tier AND 1000+ points) OR (10+ transactions)
451
+ openloyalty_segment_create({
452
+ name: "High Value Members",
453
+ parts: [
454
+ {
455
+ // Part 1: Gold tier with high balance
456
+ criteria: [
457
+ { type: "tier", tierIds: ["gold-level-id"] },
458
+ { type: "points_balance", min: 1000 }
459
+ ]
460
+ },
461
+ {
462
+ // Part 2: Frequent shoppers (OR with Part 1)
463
+ criteria: [
464
+ { type: "transaction_count", min: 10 }
465
+ ]
466
+ }
467
+ ]
468
+ })
469
+ ```
470
+
471
+ ### 9. Create Read-Only Analyst Role
472
+
473
+ ```
474
+ // Discover available ACL resources and actions
475
+ openloyalty_acl_get_resources()
476
+
477
+ // Create a role with VIEW-only permissions
478
+ openloyalty_role_create({
479
+ name: "Analyst",
480
+ permissions: [
481
+ { resource: "ANALYTICS", access: "VIEW" },
482
+ { resource: "MEMBER", access: "VIEW" },
483
+ { resource: "TRANSACTION", access: "VIEW" },
484
+ { resource: "CAMPAIGN", access: "VIEW" }
485
+ ]
486
+ })
487
+
488
+ // Create admin with analyst role
489
+ openloyalty_admin_create({
490
+ email: "analyst@company.com",
491
+ password: "SecurePass123!",
492
+ firstName: "Data",
493
+ lastName: "Analyst",
494
+ roles: ["analyst-role-id"]
495
+ })
496
+ ```
497
+
498
+ ### 10. Generate API Key for Integration
499
+
500
+ ```
501
+ // Get admin to create API key for
502
+ openloyalty_admin_list({ email: "integration@company.com" })
503
+
504
+ // Create API key - CRITICAL: Save the token immediately!
505
+ openloyalty_apikey_create({
506
+ adminId: "admin-uuid",
507
+ name: "CRM Integration Key",
508
+ expirationDate: "2025-12-31"
509
+ })
510
+ // Response includes token that is ONLY shown once
511
+
512
+ // List API keys (tokens not shown)
513
+ openloyalty_apikey_list({ adminId: "admin-uuid" })
514
+ ```
515
+
516
+ ### 11. Analyze Program Performance
517
+
518
+ ```
519
+ // Get high-level dashboard metrics
520
+ openloyalty_analytics_dashboard()
521
+
522
+ // Analyze tier distribution
523
+ openloyalty_analytics_tiers({ dateFrom: "2024-01-01", dateTo: "2024-12-31" })
524
+
525
+ // Check points economy
526
+ openloyalty_analytics_points({ dateFrom: "2024-01-01", dateTo: "2024-12-31" })
527
+
528
+ // Analyze specific campaign
529
+ openloyalty_analytics_campaign_detail({ campaignId: "campaign-uuid" })
530
+
531
+ // Get wallet-specific metrics
532
+ openloyalty_analytics_units({ walletTypeCode: "points" })
533
+ ```
534
+
535
+ ### 12. Audit User Actions
536
+
537
+ ```
538
+ // List recent audit entries
539
+ openloyalty_audit_list({ perPage: 50 })
540
+
541
+ // Filter by specific user
542
+ openloyalty_audit_list({ username: "admin@company.com" })
543
+
544
+ // Filter by entity type and date range
545
+ openloyalty_audit_list({
546
+ entityType: "MEMBER",
547
+ dateFrom: "2024-01-01",
548
+ dateTo: "2024-01-31"
549
+ })
550
+
551
+ // Export audit logs for compliance
552
+ openloyalty_audit_export({
553
+ dateFrom: "2024-01-01",
554
+ dateTo: "2024-12-31"
555
+ })
556
+ ```
557
+
558
+ ### 13. Multi-Tenant Store Setup
559
+
560
+ ```
561
+ // Create a new store for a region
562
+ openloyalty_store_create({
563
+ code: "EU",
564
+ name: "European Store",
565
+ currency: "EUR",
566
+ active: true
567
+ })
568
+
569
+ // List all stores
570
+ openloyalty_store_list()
571
+
572
+ // Use storeCode in subsequent operations
573
+ openloyalty_member_create({
574
+ email: "customer@eu.example.com",
575
+ firstName: "Jean",
576
+ lastName: "Dupont",
577
+ storeCode: "EU"
578
+ })
579
+ ```
580
+
581
+ ### 14. Subscribe to Member Events for CRM Sync
582
+
583
+ ```
584
+ // Discover available event types
585
+ openloyalty_webhook_events()
586
+
587
+ // Subscribe to member creation events
588
+ openloyalty_webhook_create({
589
+ eventName: "member.created",
590
+ url: "https://crm.example.com/webhooks/loyalty",
591
+ headers: [
592
+ { headerName: "Authorization", headerValue: "Bearer crm-token" }
593
+ ]
594
+ })
595
+
596
+ // List current subscriptions
597
+ openloyalty_webhook_list()
598
+
599
+ // Update subscription URL
600
+ openloyalty_webhook_update({
601
+ webhookSubscriptionId: "...",
602
+ url: "https://crm-v2.example.com/webhooks/loyalty"
603
+ })
604
+ ```
605
+
606
+ ### 15. Bulk Import Members from CSV
607
+
608
+ ```
609
+ // Create import with CSV content
610
+ openloyalty_import_create({
611
+ type: "member",
612
+ fileContent: "email,firstName,lastName\njohn@example.com,John,Doe\njane@example.com,Jane,Smith",
613
+ fileName: "members.csv"
614
+ })
615
+
616
+ // Poll import status
617
+ openloyalty_import_list({ type: "member" })
618
+
619
+ // Check individual item statuses
620
+ openloyalty_import_get({ importId: "..." })
621
+ ```
622
+
623
+ ### 16. Export Campaign Codes and Download
624
+
625
+ ```
626
+ // Create export for campaign codes
627
+ openloyalty_export_create({
628
+ type: "campaignCode",
629
+ filters: { campaignId: "campaign-uuid" }
630
+ })
631
+
632
+ // Poll until status is 'done'
633
+ openloyalty_export_get({ exportId: "..." })
634
+
635
+ // Download the CSV file
636
+ openloyalty_export_download({ exportId: "..." })
637
+ ```
638
+
639
+ ### 17. Bulk Add Points via Import
640
+
641
+ ```
642
+ // Create import for adding points to multiple members
643
+ openloyalty_import_create({
644
+ type: "unitTransferAdding",
645
+ fileContent: "loyaltyCardNumber,points,comment\nCARD-001,500,Promotion bonus\nCARD-002,500,Promotion bonus"
646
+ })
647
+
648
+ // Check import progress
649
+ openloyalty_import_get({ importId: "..." })
650
+ ```
651
+
652
+ ## License
653
+
654
+ MIT
@@ -0,0 +1,8 @@
1
+ import { AxiosInstance } from "axios";
2
+ export declare function resetHttpClient(): void;
3
+ export declare function getAxiosInstance(): AxiosInstance;
4
+ export declare function apiGet<T>(url: string): Promise<T>;
5
+ export declare function apiPost<T>(url: string, data?: unknown): Promise<T>;
6
+ export declare function apiPut<T>(url: string, data?: unknown): Promise<T>;
7
+ export declare function apiDelete<T>(url: string): Promise<T>;
8
+ export declare function apiPatch<T>(url: string, data?: unknown): Promise<T>;