@payware/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 (106) hide show
  1. package/.env.example +92 -0
  2. package/MCP-SETUP.md +190 -0
  3. package/README.md +483 -0
  4. package/check-keys.js +52 -0
  5. package/keys/README.md +112 -0
  6. package/mcp-config.json +9 -0
  7. package/package.json +66 -0
  8. package/payware-mcp-config.json +12 -0
  9. package/src/auth/rsa-keys.js +82 -0
  10. package/src/auth/sandbox-setup.js +187 -0
  11. package/src/config/env.js +229 -0
  12. package/src/config/partner-types.js +143 -0
  13. package/src/core/auth/jwt-factory.js +182 -0
  14. package/src/core/auth/jwt-token.js +735 -0
  15. package/src/core/utils/json-serializer.js +100 -0
  16. package/src/core/utils/key-utils.js +133 -0
  17. package/src/index.js +237 -0
  18. package/src/isv/data/index.js +291 -0
  19. package/src/isv/deep-links/delete-product-link.js +154 -0
  20. package/src/isv/deep-links/delete-transaction-link.js +154 -0
  21. package/src/isv/deep-links/get-product-link.js +167 -0
  22. package/src/isv/deep-links/get-transaction-link.js +167 -0
  23. package/src/isv/deep-links/index.js +23 -0
  24. package/src/isv/index.js +103 -0
  25. package/src/isv/oauth2/create-token-simple.js +46 -0
  26. package/src/isv/oauth2/get-token-info.js +157 -0
  27. package/src/isv/oauth2/obtain-token.js +189 -0
  28. package/src/isv/oauth2/token-helper.js +151 -0
  29. package/src/isv/products/audios.js +470 -0
  30. package/src/isv/products/create-product.js +314 -0
  31. package/src/isv/products/delete-product.js +119 -0
  32. package/src/isv/products/get-product-image.js +247 -0
  33. package/src/isv/products/get-product.js +168 -0
  34. package/src/isv/products/index.js +65 -0
  35. package/src/isv/products/list-products.js +136 -0
  36. package/src/isv/products/schedules.js +522 -0
  37. package/src/isv/products/update-product.js +265 -0
  38. package/src/isv/transactions/cancel-transaction.js +129 -0
  39. package/src/isv/transactions/create-transaction.js +361 -0
  40. package/src/isv/transactions/get-status.js +217 -0
  41. package/src/isv/transactions/process-transaction.js +145 -0
  42. package/src/isv/transactions/simulate-callback.js +146 -0
  43. package/src/isv/transactions/transaction-history.js +186 -0
  44. package/src/isv/utils/auth.js +159 -0
  45. package/src/mcp-proxy.js +150 -0
  46. package/src/merchant/data/export-report.js +108 -0
  47. package/src/merchant/data/generate-report.js +151 -0
  48. package/src/merchant/data/get-report-status.js +120 -0
  49. package/src/merchant/data/index.js +351 -0
  50. package/src/merchant/deep-links/delete-product-link.js +121 -0
  51. package/src/merchant/deep-links/delete-transaction-link.js +121 -0
  52. package/src/merchant/deep-links/get-product-link.js +134 -0
  53. package/src/merchant/deep-links/get-transaction-link.js +134 -0
  54. package/src/merchant/deep-links/index.js +23 -0
  55. package/src/merchant/index.js +92 -0
  56. package/src/merchant/products/audios.js +606 -0
  57. package/src/merchant/products/create-product.js +288 -0
  58. package/src/merchant/products/delete-product.js +111 -0
  59. package/src/merchant/products/get-product-image.js +252 -0
  60. package/src/merchant/products/get-product.js +144 -0
  61. package/src/merchant/products/index.js +65 -0
  62. package/src/merchant/products/list-products.js +112 -0
  63. package/src/merchant/products/schedules.js +646 -0
  64. package/src/merchant/products/update-product.js +282 -0
  65. package/src/merchant/transactions/cancel-transaction.js +241 -0
  66. package/src/merchant/transactions/create-transaction.js +482 -0
  67. package/src/merchant/transactions/get-status.js +196 -0
  68. package/src/merchant/transactions/process-transaction.js +349 -0
  69. package/src/merchant/transactions/simulate-callback.js +246 -0
  70. package/src/merchant/transactions/transaction-history.js +258 -0
  71. package/src/payment-institution/data/index.js +280 -0
  72. package/src/payment-institution/deep-links/delete-transaction-link.js +128 -0
  73. package/src/payment-institution/deep-links/get-transaction-link.js +141 -0
  74. package/src/payment-institution/deep-links/index.js +17 -0
  75. package/src/payment-institution/index.js +92 -0
  76. package/src/payment-institution/transactions/create-pi-transaction.js +484 -0
  77. package/src/payment-institution/transactions/finalize-transaction.js +340 -0
  78. package/src/payment-institution/transactions/get-transaction-history.js +269 -0
  79. package/src/payment-institution/transactions/get-transaction-status.js +234 -0
  80. package/src/payment-institution/transactions/process-pi-transaction.js +421 -0
  81. package/src/payment-institution/transactions/simulate-pi-callback.js +326 -0
  82. package/src/payment-institution/transactions/soundbite-transaction.js +269 -0
  83. package/src/proxy-server.js +205 -0
  84. package/src/shared/data/data-api.js +372 -0
  85. package/src/shared/deep-links/api.js +214 -0
  86. package/src/shared/index.js +44 -0
  87. package/src/shared/products/products-api.js +872 -0
  88. package/src/tools/advanced-code-generator.js +2247 -0
  89. package/src/utils/code-examples/common/auth-examples.js +1482 -0
  90. package/src/utils/code-examples/common/helpers.js +416 -0
  91. package/src/utils/code-examples/common/utils-examples.js +591 -0
  92. package/src/utils/code-examples/frameworks/examples.js +859 -0
  93. package/src/utils/code-examples/index.js +441 -0
  94. package/src/utils/code-examples/isv/oauth2.js +600 -0
  95. package/src/utils/code-examples/isv/products.js +666 -0
  96. package/src/utils/code-examples/isv/transactions.js +813 -0
  97. package/src/utils/code-examples/merchant/products.js +497 -0
  98. package/src/utils/code-examples/merchant/transactions.js +623 -0
  99. package/src/utils/code-examples/payment-institution/transactions.js +388 -0
  100. package/src/utils/code-examples/shared/data.js +607 -0
  101. package/src/utils/code-examples/shared/deep-links.js +662 -0
  102. package/src/utils/code-examples/shared/soundbites.js +808 -0
  103. package/src/utils/code-examples.js +646 -0
  104. package/src/utils/format-request.js +363 -0
  105. package/src/utils/json-formatter.js +249 -0
  106. package/src/utils/server-info.js +132 -0
@@ -0,0 +1,607 @@
1
+ /**
2
+ * Data operations examples (shared across all partner types)
3
+ */
4
+
5
+ import { ExampleGenerator, CommonTemplates } from '../common/helpers.js';
6
+
7
+ /**
8
+ * Data operations available to all partner types
9
+ */
10
+ export const DataOperations = {
11
+ generate_report: {
12
+ description: 'Generate a data report',
13
+ endpoint: '/data/reports',
14
+ method: 'POST',
15
+ sampleBody: {
16
+ reportType: 'TRANSACTION_SUMMARY',
17
+ dateRange: {
18
+ startDate: '2024-01-01T00:00:00Z',
19
+ endDate: '2024-12-31T23:59:59Z'
20
+ },
21
+ filters: {
22
+ status: ['COMPLETED', 'CANCELLED'],
23
+ currency: 'EUR',
24
+ minAmount: '1.00',
25
+ maxAmount: '1000.00'
26
+ },
27
+ format: 'JSON',
28
+ includeDetails: true
29
+ }
30
+ },
31
+
32
+ get_report_status: {
33
+ description: 'Get status of a generated report',
34
+ endpoint: '/data/reports/{id}',
35
+ method: 'GET',
36
+ sampleBody: null
37
+ },
38
+
39
+ export_report: {
40
+ description: 'Export report data in specified format',
41
+ endpoint: '/data/exports',
42
+ method: 'POST',
43
+ sampleBody: {
44
+ reportId: 'rpt_example_123',
45
+ format: 'CSV',
46
+ exportOptions: {
47
+ compression: 'gzip',
48
+ includeHeaders: true,
49
+ delimiter: ',',
50
+ encoding: 'UTF-8'
51
+ }
52
+ }
53
+ },
54
+
55
+ download_export: {
56
+ description: 'Download exported report file',
57
+ endpoint: '/data/exports/{id}',
58
+ method: 'GET',
59
+ sampleBody: null,
60
+ responseType: 'file'
61
+ },
62
+
63
+ cancel_report: {
64
+ description: 'Cancel a running report generation',
65
+ endpoint: '/data/reports/{id}',
66
+ method: 'DELETE',
67
+ sampleBody: {
68
+ reason: 'User cancelled operation'
69
+ }
70
+ },
71
+
72
+ list_reports: {
73
+ description: 'List all reports for partner',
74
+ endpoint: '/data/reports',
75
+ method: 'GET',
76
+ sampleBody: null,
77
+ queryParams: {
78
+ limit: 20,
79
+ offset: 0,
80
+ status: 'COMPLETED',
81
+ reportType: 'TRANSACTION_SUMMARY'
82
+ }
83
+ },
84
+
85
+ get_analytics_summary: {
86
+ description: 'Get analytics summary for partner',
87
+ endpoint: '/data/analytics/summary',
88
+ method: 'GET',
89
+ sampleBody: null,
90
+ queryParams: {
91
+ period: '30d',
92
+ metrics: 'transactions,revenue,fees',
93
+ granularity: 'daily'
94
+ }
95
+ },
96
+
97
+ create_custom_report: {
98
+ description: 'Create custom report with specific parameters',
99
+ endpoint: '/data/reports/custom',
100
+ method: 'POST',
101
+ sampleBody: {
102
+ name: 'Monthly Transaction Report',
103
+ description: 'Custom monthly transaction analysis',
104
+ query: {
105
+ aggregations: [
106
+ {
107
+ field: 'amount',
108
+ operation: 'SUM',
109
+ groupBy: 'currency'
110
+ },
111
+ {
112
+ field: 'transactionId',
113
+ operation: 'COUNT',
114
+ groupBy: 'status'
115
+ }
116
+ ],
117
+ filters: {
118
+ dateField: 'createdAt',
119
+ conditions: [
120
+ {
121
+ field: 'status',
122
+ operator: 'IN',
123
+ values: ['COMPLETED', 'PENDING']
124
+ }
125
+ ]
126
+ }
127
+ },
128
+ schedule: {
129
+ frequency: 'MONTHLY',
130
+ dayOfMonth: 1,
131
+ timezone: 'Europe/Berlin'
132
+ }
133
+ }
134
+ }
135
+ };
136
+
137
+ /**
138
+ * Python Data Operations Generator
139
+ */
140
+ export class PythonDataGenerator extends ExampleGenerator {
141
+ constructor() {
142
+ super('python');
143
+ }
144
+
145
+ getOperationTemplate(operation, partnerType, params = {}) {
146
+ const opConfig = DataOperations[operation];
147
+ if (!opConfig) {
148
+ throw new Error(`Unknown operation: ${operation}`);
149
+ }
150
+
151
+ const {
152
+ reportId = 'rpt_example_123',
153
+ exportId = 'exp_example_456',
154
+ ...otherParams
155
+ } = params;
156
+
157
+ let endpoint = opConfig.endpoint;
158
+ if (endpoint.includes('{id}')) {
159
+ const id = operation.includes('export') ? exportId : reportId;
160
+ endpoint = endpoint.replace('{id}', id);
161
+ }
162
+
163
+ const functionName = `${operation}_example`;
164
+
165
+ return `def ${functionName}(${this.getFunctionParams(operation, reportId, exportId)}, use_sandbox=True):
166
+ """${opConfig.description}"""
167
+
168
+ try:
169
+ # Get API configuration
170
+ base_url = get_api_base_url(use_sandbox)
171
+ endpoint = '${endpoint}'
172
+ url = f"{base_url}{endpoint}"
173
+
174
+ ${this.getQueryParamsSection(operation, opConfig)}
175
+ ${this.getRequestBodySection(operation, opConfig, reportId)}
176
+
177
+ # Create JWT token
178
+ token, body_string = create_jwt_token(request_body, use_sandbox)
179
+ headers = get_api_headers(token)
180
+
181
+ ${this.getSpecialHandling(operation, opConfig)}
182
+
183
+ ${this.getRequestSection(opConfig.method, opConfig.responseType)}
184
+
185
+ ${this.getResponseHandling(operation, opConfig)}
186
+
187
+ except requests.exceptions.RequestException as e:
188
+ print(f"Request error: {str(e)}")
189
+ return None
190
+ except Exception as e:
191
+ print(f"Unexpected error: {str(e)}")
192
+ return None
193
+
194
+ # Example usage
195
+ if __name__ == "__main__":
196
+ print("Data Operations Example")
197
+
198
+ # ${opConfig.description}
199
+ result = ${functionName}()
200
+
201
+ if result:
202
+ print("Data operation completed successfully")
203
+ ${this.getUsageExample(operation)}
204
+ else:
205
+ print("Data operation failed")`;
206
+ }
207
+
208
+ getFunctionParams(operation, reportId, exportId) {
209
+ const params = [];
210
+
211
+ if (operation.includes('report') && operation !== 'generate_report' && operation !== 'list_reports') {
212
+ params.push(`report_id='${reportId}'`);
213
+ }
214
+ if (operation.includes('export') && operation !== 'export_report') {
215
+ params.push(`export_id='${exportId}'`);
216
+ }
217
+
218
+ return params.join(', ');
219
+ }
220
+
221
+ getQueryParamsSection(operation, opConfig) {
222
+ if (!opConfig.queryParams) {
223
+ return '';
224
+ }
225
+
226
+ const paramsStr = Object.entries(opConfig.queryParams)
227
+ .map(([key, value]) => ` '${key}': ${typeof value === 'string' ? `'${value}'` : value}`)
228
+ .join(',\n');
229
+
230
+ return `# Add query parameters
231
+ params = {
232
+ ${paramsStr}
233
+ }
234
+ if params:
235
+ url += '?' + '&'.join([f"{k}={v}" for k, v in params.items()])`;
236
+ }
237
+
238
+ getRequestBodySection(operation, opConfig, reportId) {
239
+ if (!opConfig.sampleBody) {
240
+ return '# No request body needed for this operation\n request_body = None';
241
+ }
242
+
243
+ let body = { ...opConfig.sampleBody };
244
+
245
+ // Replace placeholder values
246
+ if (body.reportId) {
247
+ body.reportId = reportId;
248
+ }
249
+
250
+ const bodyStr = JSON.stringify(body, null, 8).replace(/^/gm, ' ');
251
+ return `# Prepare request body
252
+ request_body = ${bodyStr}`;
253
+ }
254
+
255
+ getSpecialHandling(operation, opConfig) {
256
+ if (operation === 'download_export') {
257
+ return `# Set headers for file download
258
+ headers['Accept'] = 'application/octet-stream'`;
259
+ }
260
+ return '';
261
+ }
262
+
263
+ getRequestSection(method, responseType) {
264
+ if (method === 'GET') {
265
+ if (responseType === 'file') {
266
+ return `response = requests.get(url, headers=headers, stream=True)`;
267
+ }
268
+ return 'response = requests.get(url, headers=headers)';
269
+ } else if (method === 'DELETE') {
270
+ return 'response = requests.delete(url, headers=headers, data=body_string if request_body else None)';
271
+ } else {
272
+ return `response = requests.${method.toLowerCase()}(
273
+ url,
274
+ headers=headers,
275
+ data=body_string if request_body else None
276
+ )`;
277
+ }
278
+ }
279
+
280
+ getResponseHandling(operation, opConfig) {
281
+ if (opConfig.responseType === 'file') {
282
+ return `if response.status_code == 200:
283
+ # Handle file download
284
+ filename = f"export_{export_id}.{opConfig.format.lower() if opConfig.format else 'dat'}"
285
+
286
+ with open(filename, 'wb') as f:
287
+ for chunk in response.iter_content(chunk_size=8192):
288
+ f.write(chunk)
289
+
290
+ print(f"File downloaded successfully: {filename}")
291
+ return filename
292
+ else:
293
+ error_msg = f"Download failed with status {response.status_code}: {response.text}"
294
+ print(error_msg)
295
+ return None`;
296
+ } else {
297
+ return `if response.status_code == 200:
298
+ result = response.json()
299
+ print(f"${opConfig.description} successful:")
300
+ print(json.dumps(result, indent=2))
301
+ return result
302
+ else:
303
+ error_msg = f"Request failed with status {response.status_code}: {response.text}"
304
+ print(error_msg)
305
+ return None`;
306
+ }
307
+ }
308
+
309
+ getUsageExample(operation) {
310
+ const examples = {
311
+ generate_report: `# Store report ID for status checking
312
+ if 'reportId' in result:
313
+ report_id = result['reportId']
314
+ print(f"Report generation started: {report_id}")
315
+ print("Use get_report_status_example(report_id) to check progress")`,
316
+
317
+ get_report_status: `# Check if report is ready
318
+ status = result.get('status')
319
+ if status == 'COMPLETED':
320
+ print("Report is ready for download")
321
+ elif status == 'PROCESSING':
322
+ print("Report is still being generated")
323
+ elif status == 'FAILED':
324
+ print(f"Report generation failed: {result.get('error')}")`,
325
+
326
+ export_report: `# Start export process
327
+ if 'exportId' in result:
328
+ export_id = result['exportId']
329
+ print(f"Export started: {export_id}")
330
+ print("Use download_export_example(export_id) when ready")`,
331
+
332
+ get_analytics_summary: `# Display analytics summary
333
+ metrics = result.get('metrics', {})
334
+ for metric, value in metrics.items():
335
+ print(f"- {metric}: {value}")
336
+
337
+ trends = result.get('trends', {})
338
+ if trends:
339
+ print("\\nTrends:")
340
+ for period, data in trends.items():
341
+ print(f"- {period}: {data}")`
342
+ };
343
+
344
+ return examples[operation] || '# Process data result as needed';
345
+ }
346
+ }
347
+
348
+ /**
349
+ * Node.js Data Operations Generator
350
+ */
351
+ export class NodeJSDataGenerator extends ExampleGenerator {
352
+ constructor() {
353
+ super('nodejs');
354
+ }
355
+
356
+ getOperationTemplate(operation, partnerType, params = {}) {
357
+ const opConfig = DataOperations[operation];
358
+ if (!opConfig) {
359
+ throw new Error(`Unknown operation: ${operation}`);
360
+ }
361
+
362
+ const {
363
+ reportId = 'rpt_example_123',
364
+ exportId = 'exp_example_456',
365
+ ...otherParams
366
+ } = params;
367
+
368
+ let endpoint = opConfig.endpoint;
369
+ if (endpoint.includes('{id}')) {
370
+ const id = operation.includes('export') ? exportId : reportId;
371
+ endpoint = endpoint.replace('{id}', id);
372
+ }
373
+
374
+ const functionName = `${operation}Example`;
375
+
376
+ return `async function ${functionName}(${this.getFunctionParams(operation, reportId, exportId)}, useSandbox = true) {
377
+ /**
378
+ * ${opConfig.description}
379
+ */
380
+
381
+ try {
382
+ // Get API configuration
383
+ const baseUrl = getAPIBaseURL(useSandbox);
384
+ const endpoint = '${endpoint}';
385
+ let url = \`\${baseUrl}\${endpoint}\`;
386
+
387
+ ${this.getQueryParamsSection(operation, opConfig)}
388
+ ${this.getRequestBodySection(operation, opConfig, reportId)}
389
+
390
+ // Create JWT token
391
+ const { token, bodyString } = createJWTToken(requestBody, useSandbox);
392
+ const headers = getAPIHeaders(token);
393
+
394
+ ${this.getSpecialHandling(operation, opConfig)}
395
+
396
+ ${this.getRequestSection(opConfig.method, opConfig.responseType)}
397
+
398
+ ${this.getResponseHandling(operation, opConfig)}
399
+
400
+ } catch (error) {
401
+ if (error.response) {
402
+ console.error(\`API Error: \${error.response.status} - \${error.response.data}\`);
403
+ } else {
404
+ console.error('Request Error:', error.message);
405
+ }
406
+ return null;
407
+ }
408
+ }
409
+
410
+ // Example usage
411
+ async function main() {
412
+ console.log('Data Operations Example');
413
+
414
+ try {
415
+ const result = await ${functionName}();
416
+
417
+ if (result) {
418
+ console.log('Data operation completed successfully');
419
+ ${this.getUsageExample(operation)}
420
+ } else {
421
+ console.log('Data operation failed');
422
+ }
423
+
424
+ } catch (error) {
425
+ console.error('Data operation error:', error.message);
426
+ }
427
+ }
428
+
429
+ // Run example if this file is executed directly
430
+ if (require.main === module) {
431
+ main().catch(console.error);
432
+ }`;
433
+ }
434
+
435
+ getFunctionParams(operation, reportId, exportId) {
436
+ const params = [];
437
+
438
+ if (operation.includes('report') && operation !== 'generate_report' && operation !== 'list_reports') {
439
+ params.push(`reportId = '${reportId}'`);
440
+ }
441
+ if (operation.includes('export') && operation !== 'export_report') {
442
+ params.push(`exportId = '${exportId}'`);
443
+ }
444
+
445
+ return params.join(', ');
446
+ }
447
+
448
+ getQueryParamsSection(operation, opConfig) {
449
+ if (!opConfig.queryParams) {
450
+ return '';
451
+ }
452
+
453
+ const paramsStr = JSON.stringify(opConfig.queryParams, null, 4).replace(/^/gm, ' ');
454
+ return `// Add query parameters
455
+ const queryParams = ${paramsStr};
456
+ const searchParams = new URLSearchParams(queryParams);
457
+ url += \`?\${searchParams.toString()}\`;`;
458
+ }
459
+
460
+ getRequestBodySection(operation, opConfig, reportId) {
461
+ if (!opConfig.sampleBody) {
462
+ return '// No request body needed for this operation\n const requestBody = null;';
463
+ }
464
+
465
+ let body = { ...opConfig.sampleBody };
466
+
467
+ // Replace placeholder values
468
+ if (body.reportId) {
469
+ body.reportId = reportId;
470
+ }
471
+
472
+ const bodyStr = JSON.stringify(body, null, 4).replace(/^/gm, ' ');
473
+ return `// Prepare request body
474
+ const requestBody = ${bodyStr};`;
475
+ }
476
+
477
+ getSpecialHandling(operation, opConfig) {
478
+ if (operation === 'download_export') {
479
+ return `// Set headers for file download
480
+ headers['Accept'] = 'application/octet-stream';`;
481
+ }
482
+ return '';
483
+ }
484
+
485
+ getRequestSection(method, responseType) {
486
+ if (method === 'GET') {
487
+ if (responseType === 'file') {
488
+ return `const response = await axios.get(url, {
489
+ headers,
490
+ responseType: 'stream'
491
+ });`;
492
+ }
493
+ return 'const response = await axios.get(url, { headers });';
494
+ } else if (method === 'DELETE') {
495
+ return `const response = await axios.delete(url, {
496
+ headers,
497
+ data: bodyString || undefined
498
+ });`;
499
+ } else {
500
+ return `const response = await axios.${method.toLowerCase()}(
501
+ url,
502
+ bodyString || undefined,
503
+ { headers }
504
+ );`;
505
+ }
506
+ }
507
+
508
+ getResponseHandling(operation, opConfig) {
509
+ if (opConfig.responseType === 'file') {
510
+ return `if (response.status === 200) {
511
+ // Handle file download
512
+ const fs = require('fs');
513
+ const filename = \`export_\${exportId}.\${opConfig.format?.toLowerCase() || 'dat'}\`;
514
+
515
+ const writer = fs.createWriteStream(filename);
516
+ response.data.pipe(writer);
517
+
518
+ return new Promise((resolve, reject) => {
519
+ writer.on('finish', () => {
520
+ console.log(\`File downloaded successfully: \${filename}\`);
521
+ resolve(filename);
522
+ });
523
+ writer.on('error', reject);
524
+ });
525
+ } else {
526
+ console.error(\`Download failed with status \${response.status}: \${response.statusText}\`);
527
+ return null;
528
+ }`;
529
+ } else {
530
+ return `if (response.status === 200) {
531
+ const result = response.data;
532
+ console.log('${opConfig.description} successful:');
533
+ console.log(JSON.stringify(result, null, 2));
534
+ return result;
535
+ } else {
536
+ console.error(\`Request failed with status \${response.status}: \${response.statusText}\`);
537
+ return null;
538
+ }`;
539
+ }
540
+ }
541
+
542
+ getUsageExample(operation) {
543
+ const examples = {
544
+ generate_report: `// Store report ID for status checking
545
+ if (result.reportId) {
546
+ const reportId = result.reportId;
547
+ console.log(\`Report generation started: \${reportId}\`);
548
+ console.log('Use getReportStatusExample(reportId) to check progress');
549
+ }`,
550
+
551
+ get_report_status: `// Check if report is ready
552
+ const status = result.status;
553
+ if (status === 'COMPLETED') {
554
+ console.log('Report is ready for download');
555
+ } else if (status === 'PROCESSING') {
556
+ console.log('Report is still being generated');
557
+ } else if (status === 'FAILED') {
558
+ console.log(\`Report generation failed: \${result.error}\`);
559
+ }`,
560
+
561
+ export_report: `// Start export process
562
+ if (result.exportId) {
563
+ const exportId = result.exportId;
564
+ console.log(\`Export started: \${exportId}\`);
565
+ console.log('Use downloadExportExample(exportId) when ready');
566
+ }`,
567
+
568
+ get_analytics_summary: `// Display analytics summary
569
+ const metrics = result.metrics || {};
570
+ Object.entries(metrics).forEach(([metric, value]) => {
571
+ console.log(\`- \${metric}: \${value}\`);
572
+ });
573
+
574
+ const trends = result.trends || {};
575
+ if (Object.keys(trends).length > 0) {
576
+ console.log('\\nTrends:');
577
+ Object.entries(trends).forEach(([period, data]) => {
578
+ console.log(\`- \${period}:\`, data);
579
+ });
580
+ }`
581
+ };
582
+
583
+ return examples[operation] || '// Process data result as needed';
584
+ }
585
+ }
586
+
587
+ /**
588
+ * Export all generators
589
+ */
590
+ export const DataGenerators = {
591
+ python: PythonDataGenerator,
592
+ nodejs: NodeJSDataGenerator,
593
+ javascript: NodeJSDataGenerator
594
+ };
595
+
596
+ /**
597
+ * Generate data operation example
598
+ */
599
+ export function generateDataExample(operation, language = 'python', partnerType = 'merchant', options = {}) {
600
+ const GeneratorClass = DataGenerators[language];
601
+ if (!GeneratorClass) {
602
+ throw new Error(`Unsupported language: ${language}`);
603
+ }
604
+
605
+ const generator = new GeneratorClass();
606
+ return generator.generateExample(operation, partnerType, options);
607
+ }