@payware/mcp-server 1.1.1 → 1.3.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 (127) hide show
  1. package/.env.example +0 -0
  2. package/README.md +22 -16
  3. package/check-keys.js +0 -0
  4. package/keys/README.md +0 -0
  5. package/mcp-config.json +0 -0
  6. package/package.json +69 -66
  7. package/payware-mcp-config.json +0 -0
  8. package/src/auth/rsa-keys.js +0 -0
  9. package/src/auth/sandbox-setup.js +186 -186
  10. package/src/config/env.js +0 -0
  11. package/src/config/partner-types.js +0 -0
  12. package/src/core/auth/jwt-factory.js +4 -4
  13. package/src/core/auth/jwt-token.js +107 -66
  14. package/src/core/utils/json-serializer.js +5 -5
  15. package/src/core/utils/key-utils.js +0 -0
  16. package/src/index.js +0 -0
  17. package/src/isv/data/index.js +0 -0
  18. package/src/isv/deep-links/delete-product-link.js +0 -0
  19. package/src/isv/deep-links/delete-transaction-link.js +0 -0
  20. package/src/isv/deep-links/get-product-link.js +0 -0
  21. package/src/isv/deep-links/get-transaction-link.js +0 -0
  22. package/src/isv/deep-links/index.js +0 -0
  23. package/src/isv/index.js +29 -1
  24. package/src/isv/invitations/index.js +471 -0
  25. package/src/isv/oauth2/create-token-simple.js +0 -0
  26. package/src/isv/oauth2/get-token-info.js +0 -0
  27. package/src/isv/oauth2/obtain-token.js +19 -8
  28. package/src/isv/oauth2/token-helper.js +5 -2
  29. package/src/isv/poi/cancel-price.js +2 -10
  30. package/src/isv/poi/create.js +19 -0
  31. package/src/isv/poi/get-poi.js +2 -10
  32. package/src/isv/poi/get-qrcode.js +2 -10
  33. package/src/isv/poi/get-status.js +2 -10
  34. package/src/isv/poi/index.js +5 -0
  35. package/src/isv/poi/list-pois.js +2 -10
  36. package/src/isv/poi/set-price.js +217 -225
  37. package/src/isv/products/audios.js +0 -0
  38. package/src/isv/products/create-product.js +313 -313
  39. package/src/isv/products/delete-product.js +0 -0
  40. package/src/isv/products/get-product-image.js +0 -0
  41. package/src/isv/products/get-product.js +0 -0
  42. package/src/isv/products/index.js +0 -0
  43. package/src/isv/products/list-products.js +0 -0
  44. package/src/isv/products/schedules.js +0 -0
  45. package/src/isv/products/update-product.js +264 -264
  46. package/src/isv/reference/index.js +249 -0
  47. package/src/isv/shops/index.js +22 -0
  48. package/src/isv/transactions/cancel-transaction.js +43 -12
  49. package/src/isv/transactions/create-transaction.js +22 -6
  50. package/src/isv/transactions/get-status.js +18 -11
  51. package/src/isv/transactions/process-transaction.js +160 -42
  52. package/src/isv/transactions/simulate-callback.js +128 -109
  53. package/src/isv/transactions/transaction-history.js +86 -90
  54. package/src/isv/utils/auth.js +2 -2
  55. package/src/mcp-proxy.js +0 -0
  56. package/src/merchant/data/export-report.js +0 -0
  57. package/src/merchant/data/generate-report.js +19 -1
  58. package/src/merchant/data/get-export-list.js +0 -0
  59. package/src/merchant/data/get-report-requests.js +0 -0
  60. package/src/merchant/data/get-report-status.js +0 -0
  61. package/src/merchant/data/index.js +0 -0
  62. package/src/merchant/data/list-reports.js +0 -0
  63. package/src/merchant/deep-links/delete-product-link.js +0 -0
  64. package/src/merchant/deep-links/delete-transaction-link.js +0 -0
  65. package/src/merchant/deep-links/get-product-link.js +0 -0
  66. package/src/merchant/deep-links/get-transaction-link.js +0 -0
  67. package/src/merchant/deep-links/index.js +0 -0
  68. package/src/merchant/index.js +21 -1
  69. package/src/merchant/logs/index.js +366 -0
  70. package/src/merchant/products/audios.js +0 -0
  71. package/src/merchant/products/create-product.js +287 -287
  72. package/src/merchant/products/delete-product.js +0 -0
  73. package/src/merchant/products/get-product-image.js +0 -0
  74. package/src/merchant/products/get-product.js +0 -0
  75. package/src/merchant/products/index.js +0 -0
  76. package/src/merchant/products/list-products.js +0 -0
  77. package/src/merchant/products/schedules.js +0 -0
  78. package/src/merchant/products/update-product.js +281 -281
  79. package/src/merchant/shops/index.js +18 -0
  80. package/src/merchant/transactions/cancel-transaction.js +16 -19
  81. package/src/merchant/transactions/create-transaction.js +99 -19
  82. package/src/merchant/transactions/get-status.js +41 -12
  83. package/src/merchant/transactions/process-transaction.js +8 -16
  84. package/src/merchant/transactions/simulate-callback.js +68 -9
  85. package/src/merchant/transactions/transaction-history.js +275 -257
  86. package/src/payment-institution/data/index.js +0 -0
  87. package/src/payment-institution/deep-links/delete-transaction-link.js +0 -0
  88. package/src/payment-institution/deep-links/get-transaction-link.js +0 -0
  89. package/src/payment-institution/deep-links/index.js +0 -0
  90. package/src/payment-institution/index.js +0 -0
  91. package/src/payment-institution/transactions/create-pi-transaction.js +6 -14
  92. package/src/payment-institution/transactions/finalize-transaction.js +333 -340
  93. package/src/payment-institution/transactions/get-transaction-history.js +3 -11
  94. package/src/payment-institution/transactions/get-transaction-status.js +39 -12
  95. package/src/payment-institution/transactions/process-pi-transaction.js +5 -13
  96. package/src/payment-institution/transactions/simulate-pi-callback.js +49 -9
  97. package/src/payment-institution/transactions/soundbite-transaction.js +5 -13
  98. package/src/proxy-server.js +0 -0
  99. package/src/shared/api-errors.js +188 -0
  100. package/src/shared/auth-headers.js +62 -0
  101. package/src/shared/data/data-api.js +11 -10
  102. package/src/shared/deep-links/api.js +5 -4
  103. package/src/shared/index.js +0 -0
  104. package/src/shared/logs/logs-api.js +242 -0
  105. package/src/shared/poi/poi-create-api.js +419 -0
  106. package/src/shared/products/products-api.js +17 -16
  107. package/src/shared/shops/shops-api.js +155 -0
  108. package/src/tools/advanced-code-generator.js +2255 -2246
  109. package/src/utils/code-examples/common/auth-examples.js +1484 -1481
  110. package/src/utils/code-examples/common/helpers.js +7 -4
  111. package/src/utils/code-examples/common/utils-examples.js +0 -0
  112. package/src/utils/code-examples/frameworks/examples.js +4 -4
  113. package/src/utils/code-examples/index.js +0 -0
  114. package/src/utils/code-examples/isv/oauth2.js +458 -600
  115. package/src/utils/code-examples/isv/products.js +8 -8
  116. package/src/utils/code-examples/isv/transactions.js +815 -812
  117. package/src/utils/code-examples/merchant/products.js +0 -0
  118. package/src/utils/code-examples/merchant/transactions.js +9 -9
  119. package/src/utils/code-examples/payment-institution/transactions.js +0 -0
  120. package/src/utils/code-examples/shared/data.js +0 -0
  121. package/src/utils/code-examples/shared/deep-links.js +0 -0
  122. package/src/utils/code-examples/shared/soundbites.js +0 -0
  123. package/src/utils/code-examples.js +24 -24
  124. package/src/utils/format-request.js +3 -3
  125. package/src/utils/json-formatter.js +20 -20
  126. package/src/utils/server-info.js +0 -0
  127. package/MCP-SETUP.md +0 -190
@@ -0,0 +1,366 @@
1
+ /**
2
+ * Merchant Logs Tools - Premium Feature
3
+ * Tools for querying and downloading application logs.
4
+ * Requires Premium (PRM) plan subscription.
5
+ */
6
+
7
+ import {
8
+ queryLogs,
9
+ getLogStatus,
10
+ getLogDownloadUrl,
11
+ downloadLogs,
12
+ LOG_LEVELS
13
+ } from '../../shared/logs/logs-api.js';
14
+ import { getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
15
+
16
+ /**
17
+ * Query logs tool for merchants
18
+ */
19
+ export const queryLogsTool = {
20
+ name: "payware_logs_query",
21
+ description: "Query application logs with filters. Premium plan required. Returns paginated JSON log entries for debugging and monitoring your integration.",
22
+ inputSchema: {
23
+ type: "object",
24
+ properties: {
25
+ from: {
26
+ type: "string",
27
+ description: "Start timestamp in ISO 8601 format (e.g., '2024-01-15T00:00:00Z'). Defaults to 24 hours ago."
28
+ },
29
+ to: {
30
+ type: "string",
31
+ description: "End timestamp in ISO 8601 format (e.g., '2024-01-15T23:59:59Z'). Defaults to now."
32
+ },
33
+ level: {
34
+ type: "string",
35
+ enum: ["ERROR", "WARN", "INFO", "DEBUG"],
36
+ description: "Filter by log level. Use ERROR for errors only, WARN for warnings and above, etc."
37
+ },
38
+ logger: {
39
+ type: "string",
40
+ description: "Filter by logger name (partial match). E.g., 'TransactionController' to see transaction-related logs."
41
+ },
42
+ search: {
43
+ type: "string",
44
+ description: "Search text in log messages. Case-insensitive partial match."
45
+ },
46
+ limit: {
47
+ type: "number",
48
+ description: "Maximum records to return (default 1000, max 10000).",
49
+ default: 1000
50
+ },
51
+ cursor: {
52
+ type: "string",
53
+ description: "Pagination cursor from previous response for fetching next page."
54
+ },
55
+ partnerId: {
56
+ type: "string",
57
+ description: "Partner ID from payware dashboard. Uses PAYWARE_PARTNER_ID env var as default.",
58
+ default: getPartnerIdSafe()
59
+ },
60
+ privateKey: {
61
+ type: "string",
62
+ description: "RSA private key for authentication. Uses environment-specific private key as default."
63
+ }
64
+ },
65
+ required: []
66
+ },
67
+
68
+ async handler(args) {
69
+ const {
70
+ from,
71
+ to,
72
+ level,
73
+ logger,
74
+ search,
75
+ limit = 1000,
76
+ cursor,
77
+ partnerId = getPartnerIdSafe(),
78
+ privateKey = getPrivateKeySafe()
79
+ } = args;
80
+
81
+ if (!partnerId || !privateKey) {
82
+ throw new Error("Partner ID and private key are required. Set PAYWARE_PARTNER_ID and environment-specific private key variables or provide them as parameters.");
83
+ }
84
+
85
+ try {
86
+ const result = await queryLogs({
87
+ from,
88
+ to,
89
+ level,
90
+ logger,
91
+ search,
92
+ limit,
93
+ cursor,
94
+ partnerType: 'merchant',
95
+ partnerId,
96
+ privateKey
97
+ });
98
+
99
+ const data = result.data;
100
+ const entries = data.entries || [];
101
+ const hasMore = data.hasMore || false;
102
+ const nextCursor = data.nextCursor;
103
+
104
+ // Format log entries for display
105
+ let logsPreview = '';
106
+ if (entries.length > 0) {
107
+ const displayEntries = entries.slice(0, 10); // Show first 10
108
+ logsPreview = displayEntries.map(log => {
109
+ const timestamp = log['@timestamp'] || log.timestamp || 'N/A';
110
+ const logLevel = log.level || 'N/A';
111
+ const loggerName = log.logger_name || log.loggerName || 'N/A';
112
+ const message = log.message || 'N/A';
113
+ const shortMessage = message.length > 100 ? message.substring(0, 100) + '...' : message;
114
+ return `[${timestamp}] ${logLevel} ${loggerName}\n ${shortMessage}`;
115
+ }).join('\n\n');
116
+
117
+ if (entries.length > 10) {
118
+ logsPreview += `\n\n... and ${entries.length - 10} more entries`;
119
+ }
120
+ } else {
121
+ logsPreview = 'No log entries found matching the criteria.';
122
+ }
123
+
124
+ // Build filter summary
125
+ const filters = [];
126
+ if (from) filters.push(`from: ${from}`);
127
+ if (to) filters.push(`to: ${to}`);
128
+ if (level) filters.push(`level: ${level}`);
129
+ if (logger) filters.push(`logger: ${logger}`);
130
+ if (search) filters.push(`search: "${search}"`);
131
+ const filterSummary = filters.length > 0 ? filters.join(', ') : 'none (last 24 hours)';
132
+
133
+ return {
134
+ content: [{
135
+ type: "text",
136
+ text: `📋 **Log Query Results**
137
+
138
+ **Query Summary:**
139
+ - Total Entries: ${data.totalCount || entries.length}
140
+ - Returned: ${data.returnedCount || entries.length}
141
+ - Has More: ${hasMore ? 'Yes' : 'No'}
142
+ - Filters: ${filterSummary}
143
+
144
+ **Log Entries Preview:**
145
+ \`\`\`
146
+ ${logsPreview}
147
+ \`\`\`
148
+
149
+ ${hasMore ? `**Pagination:**
150
+ Use cursor \`${nextCursor}\` to fetch the next page of results.` : ''}
151
+
152
+ **Log Levels:**
153
+ - 🔴 **ERROR**: Application errors and exceptions
154
+ - 🟠 **WARN**: Warnings that may need attention
155
+ - 🟢 **INFO**: Informational messages
156
+ - 🔵 **DEBUG**: Detailed debugging information
157
+
158
+ **Tips:**
159
+ - Use \`level: "ERROR"\` to quickly find errors
160
+ - Use \`search\` to find specific transaction IDs or error messages
161
+ - Use \`logger\` filter to focus on specific components
162
+
163
+ ⚠️ **Note:** This is a Premium (PRM) plan feature.`
164
+ }]
165
+ };
166
+ } catch (error) {
167
+ throw new Error(`Failed to query logs: ${error.message}`);
168
+ }
169
+ }
170
+ };
171
+
172
+ /**
173
+ * Get log status tool for merchants
174
+ */
175
+ export const getLogStatusTool = {
176
+ name: "payware_logs_status",
177
+ description: "Get log availability and storage information. Premium plan required. Shows if logs are available, total size, and file count.",
178
+ inputSchema: {
179
+ type: "object",
180
+ properties: {
181
+ partnerId: {
182
+ type: "string",
183
+ description: "Partner ID from payware dashboard. Uses PAYWARE_PARTNER_ID env var as default.",
184
+ default: getPartnerIdSafe()
185
+ },
186
+ privateKey: {
187
+ type: "string",
188
+ description: "RSA private key for authentication. Uses environment-specific private key as default."
189
+ }
190
+ },
191
+ required: []
192
+ },
193
+
194
+ async handler(args) {
195
+ const {
196
+ partnerId = getPartnerIdSafe(),
197
+ privateKey = getPrivateKeySafe()
198
+ } = args;
199
+
200
+ if (!partnerId || !privateKey) {
201
+ throw new Error("Partner ID and private key are required. Set PAYWARE_PARTNER_ID and environment-specific private key variables or provide them as parameters.");
202
+ }
203
+
204
+ try {
205
+ const result = await getLogStatus({
206
+ partnerType: 'merchant',
207
+ partnerId,
208
+ privateKey
209
+ });
210
+
211
+ const data = result.data;
212
+
213
+ // Format file size
214
+ const formatSize = (bytes) => {
215
+ if (!bytes) return '0 B';
216
+ const units = ['B', 'KB', 'MB', 'GB'];
217
+ let unitIndex = 0;
218
+ let size = bytes;
219
+ while (size >= 1024 && unitIndex < units.length - 1) {
220
+ size /= 1024;
221
+ unitIndex++;
222
+ }
223
+ return `${size.toFixed(1)} ${units[unitIndex]}`;
224
+ };
225
+
226
+ return {
227
+ content: [{
228
+ type: "text",
229
+ text: `📊 **Log Status**
230
+
231
+ **Availability:**
232
+ - Partner ID: ${data.partnerId || partnerId}
233
+ - Logs Available: ${data.logsAvailable ? '✅ Yes' : '❌ No'}
234
+
235
+ **Storage Information:**
236
+ - Total Size: ${formatSize(data.totalSizeBytes)}
237
+ - File Count: ${data.fileCount || 0} files
238
+
239
+ **What You Can Do:**
240
+ ${data.logsAvailable ? `
241
+ 1. **Query logs** using \`payware_logs_query\` tool
242
+ - Filter by level, logger, search text, date range
243
+ - Paginate through results with cursor
244
+
245
+ 2. **Download logs** using \`payware_logs_download_url\` tool
246
+ - Get compressed archive of logs for offline analysis
247
+ ` : `
248
+ ⚠️ No logs are currently available. Logs are generated when API calls are made.
249
+ `}
250
+
251
+ ⚠️ **Note:** This is a Premium (PRM) plan feature.`
252
+ }]
253
+ };
254
+ } catch (error) {
255
+ throw new Error(`Failed to get log status: ${error.message}`);
256
+ }
257
+ }
258
+ };
259
+
260
+ /**
261
+ * Get log download URL tool for merchants
262
+ */
263
+ export const getLogDownloadUrlTool = {
264
+ name: "payware_logs_download_url",
265
+ description: "Get download URL for logs archive. Premium plan required. Returns URL for downloading logs as gzipped JSON file.",
266
+ inputSchema: {
267
+ type: "object",
268
+ properties: {
269
+ from: {
270
+ type: "string",
271
+ description: "Start timestamp in ISO 8601 format (e.g., '2024-01-15T00:00:00Z'). Defaults to 24 hours ago."
272
+ },
273
+ to: {
274
+ type: "string",
275
+ description: "End timestamp in ISO 8601 format (e.g., '2024-01-15T23:59:59Z'). Defaults to now."
276
+ },
277
+ partnerId: {
278
+ type: "string",
279
+ description: "Partner ID from payware dashboard. Uses PAYWARE_PARTNER_ID env var as default.",
280
+ default: getPartnerIdSafe()
281
+ },
282
+ privateKey: {
283
+ type: "string",
284
+ description: "RSA private key for authentication. Uses environment-specific private key as default."
285
+ }
286
+ },
287
+ required: []
288
+ },
289
+
290
+ async handler(args) {
291
+ const {
292
+ from,
293
+ to,
294
+ partnerId = getPartnerIdSafe(),
295
+ privateKey = getPrivateKeySafe()
296
+ } = args;
297
+
298
+ if (!partnerId || !privateKey) {
299
+ throw new Error("Partner ID and private key are required. Set PAYWARE_PARTNER_ID and environment-specific private key variables or provide them as parameters.");
300
+ }
301
+
302
+ try {
303
+ const result = await getLogDownloadUrl({
304
+ from,
305
+ to,
306
+ partnerType: 'merchant',
307
+ partnerId,
308
+ privateKey
309
+ });
310
+
311
+ const data = result.data;
312
+
313
+ return {
314
+ content: [{
315
+ type: "text",
316
+ text: `📥 **Log Download Information**
317
+
318
+ **Download URL:**
319
+ \`${data.downloadUrl}\`
320
+
321
+ **Parameters:**
322
+ - From: ${data.parameters.from}
323
+ - To: ${data.parameters.to}
324
+
325
+ **Important:**
326
+ ${data.note}
327
+
328
+ **File Format:**
329
+ - Content-Type: application/gzip
330
+ - Format: Gzipped newline-delimited JSON (NDJSON)
331
+ - Each line is a complete JSON log entry
332
+
333
+ **Usage Example (cURL):**
334
+ \`\`\`bash
335
+ curl -H "Authorization: Bearer YOUR_JWT_TOKEN" \\
336
+ -H "Api-Version: 1" \\
337
+ "${data.downloadUrl}" \\
338
+ -o logs.json.gz
339
+ \`\`\`
340
+
341
+ **Processing the Download:**
342
+ \`\`\`bash
343
+ # Decompress and view
344
+ gunzip -c logs.json.gz | head -10
345
+
346
+ # Parse with jq
347
+ gunzip -c logs.json.gz | jq '.level'
348
+ \`\`\`
349
+
350
+ ⚠️ **Note:** This is a Premium (PRM) plan feature.`
351
+ }]
352
+ };
353
+ } catch (error) {
354
+ throw new Error(`Failed to get download URL: ${error.message}`);
355
+ }
356
+ }
357
+ };
358
+
359
+ /**
360
+ * All merchant logs tools
361
+ */
362
+ export const merchantLogsTools = [
363
+ queryLogsTool,
364
+ getLogStatusTool,
365
+ getLogDownloadUrlTool
366
+ ];
File without changes