@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
@@ -3,6 +3,7 @@ import { createJWTToken } from '../../core/auth/jwt-token.js';
3
3
  import { createJWTForPartner } from '../../core/auth/jwt-factory.js';
4
4
  import { createMinimizedJSON } from '../../core/utils/json-serializer.js';
5
5
  import { getSandboxUrl, getProductionUrl, getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
6
+ import { describeApiError } from '../api-errors.js';
6
7
 
7
8
  /**
8
9
  * Available report types from the Data API documentation
@@ -147,7 +148,7 @@ export async function generateReport({
147
148
  }
148
149
  };
149
150
  } catch (error) {
150
- throw new Error(`Failed to generate report: ${error.response?.data?.message || error.message}`);
151
+ throw describeApiError(error, 'generate report');
151
152
  }
152
153
  }
153
154
 
@@ -181,7 +182,7 @@ export async function getReportStatus({
181
182
  }
182
183
  };
183
184
  } catch (error) {
184
- throw new Error(`Failed to get report status: ${error.response?.data?.message || error.message}`);
185
+ throw describeApiError(error, 'get report status');
185
186
  }
186
187
  }
187
188
 
@@ -222,7 +223,7 @@ export async function exportReport({
222
223
  }
223
224
  };
224
225
  } catch (error) {
225
- throw new Error(`Failed to export report: ${error.response?.data?.message || error.message}`);
226
+ throw describeApiError(error, 'export report');
226
227
  }
227
228
  }
228
229
 
@@ -256,7 +257,7 @@ export async function getExportStatus({
256
257
  }
257
258
  };
258
259
  } catch (error) {
259
- throw new Error(`Failed to get export status: ${error.response?.data?.message || error.message}`);
260
+ throw describeApiError(error, 'get export status');
260
261
  }
261
262
  }
262
263
 
@@ -295,7 +296,7 @@ export async function downloadExport({
295
296
  }
296
297
  };
297
298
  } catch (error) {
298
- throw new Error(`Failed to download export: ${error.response?.data?.message || error.message}`);
299
+ throw describeApiError(error, 'download export');
299
300
  }
300
301
  }
301
302
 
@@ -331,7 +332,7 @@ export async function cancelReport({
331
332
  }
332
333
  };
333
334
  } catch (error) {
334
- throw new Error(`Failed to cancel report: ${error.response?.data?.message || error.message}`);
335
+ throw describeApiError(error, 'cancel report');
335
336
  }
336
337
  }
337
338
 
@@ -367,7 +368,7 @@ export async function cancelExport({
367
368
  }
368
369
  };
369
370
  } catch (error) {
370
- throw new Error(`Failed to cancel export: ${error.response?.data?.message || error.message}`);
371
+ throw describeApiError(error, 'cancel export');
371
372
  }
372
373
  }
373
374
 
@@ -396,7 +397,7 @@ export async function listReports({
396
397
  }
397
398
  };
398
399
  } catch (error) {
399
- throw new Error(`Failed to list reports: ${error.response?.data?.message || error.message}`);
400
+ throw describeApiError(error, 'list reports');
400
401
  }
401
402
  }
402
403
 
@@ -430,7 +431,7 @@ export async function getReportRequests({
430
431
  }
431
432
  };
432
433
  } catch (error) {
433
- throw new Error(`Failed to get report requests: ${error.response?.data?.message || error.message}`);
434
+ throw describeApiError(error, 'get report requests');
434
435
  }
435
436
  }
436
437
 
@@ -464,6 +465,6 @@ export async function getExportList({
464
465
  }
465
466
  };
466
467
  } catch (error) {
467
- throw new Error(`Failed to get export list: ${error.response?.data?.message || error.message}`);
468
+ throw describeApiError(error, 'get export list');
468
469
  }
469
470
  }
@@ -2,6 +2,7 @@ import axios from 'axios';
2
2
  import { createJWTToken } from '../../core/auth/jwt-token.js';
3
3
  import { createJWTForPartner } from '../../core/auth/jwt-factory.js';
4
4
  import { getProductionUrl } from '../../config/env.js';
5
+ import { describeApiError } from '../api-errors.js';
5
6
 
6
7
  /**
7
8
  * Create authentication headers based on partner type
@@ -84,7 +85,7 @@ export async function getTransactionDeepLink({
84
85
  }
85
86
  };
86
87
  } catch (error) {
87
- throw new Error(`Failed to get transaction deep link: ${error.response?.data?.message || error.message}`);
88
+ throw describeApiError(error, 'get transaction deep link');
88
89
  }
89
90
  }
90
91
 
@@ -127,7 +128,7 @@ export async function getProductDeepLink({
127
128
  }
128
129
  };
129
130
  } catch (error) {
130
- throw new Error(`Failed to get product deep link: ${error.response?.data?.message || error.message}`);
131
+ throw describeApiError(error, 'get product deep link');
131
132
  }
132
133
  }
133
134
 
@@ -166,7 +167,7 @@ export async function deleteTransactionDeepLink({
166
167
  }
167
168
  };
168
169
  } catch (error) {
169
- throw new Error(`Failed to delete transaction deep link: ${error.response?.data?.message || error.message}`);
170
+ throw describeApiError(error, 'delete transaction deep link');
170
171
  }
171
172
  }
172
173
 
@@ -209,6 +210,6 @@ export async function deleteProductDeepLink({
209
210
  }
210
211
  };
211
212
  } catch (error) {
212
- throw new Error(`Failed to delete product deep link: ${error.response?.data?.message || error.message}`);
213
+ throw describeApiError(error, 'delete product deep link');
213
214
  }
214
215
  }
File without changes
@@ -0,0 +1,242 @@
1
+ import axios from 'axios';
2
+ import { createJWTToken } from '../../core/auth/jwt-token.js';
3
+ import { createJWTForPartner } from '../../core/auth/jwt-factory.js';
4
+ import { getProductionUrl, getPartnerIdSafe, getPrivateKeySafe } from '../../config/env.js';
5
+ import { describeApiError } from '../api-errors.js';
6
+
7
+ /**
8
+ * Logs API - Premium Feature
9
+ * Provides access to application logs for debugging and monitoring.
10
+ * Requires Premium (PRM) plan subscription.
11
+ */
12
+
13
+ /**
14
+ * Available log levels for filtering
15
+ */
16
+ export const LOG_LEVELS = {
17
+ ERROR: 'ERROR',
18
+ WARN: 'WARN',
19
+ INFO: 'INFO',
20
+ DEBUG: 'DEBUG'
21
+ };
22
+
23
+ /**
24
+ * Create authentication headers for logs API
25
+ * @param {string} partnerType - merchant, isv, or payment_institution
26
+ * @param {Object} authParams - Authentication parameters
27
+ * @returns {Object} Headers for API request
28
+ */
29
+ async function createAuthHeaders(partnerType, authParams) {
30
+ const baseHeaders = {
31
+ 'Content-Type': 'application/json',
32
+ 'Api-Version': '1'
33
+ };
34
+
35
+ let tokenData;
36
+
37
+ switch (partnerType) {
38
+ case 'merchant':
39
+ case 'payment_institution':
40
+ // Standard JWT authentication
41
+ tokenData = createJWTToken(
42
+ authParams.partnerId,
43
+ authParams.privateKey,
44
+ authParams.requestBody
45
+ );
46
+ break;
47
+
48
+ case 'isv':
49
+ // ISV JWT with OAuth2
50
+ tokenData = await createJWTForPartner({
51
+ partnerId: authParams.isvPartnerId,
52
+ privateKey: authParams.privateKey,
53
+ merchantId: authParams.merchantPartnerId,
54
+ oauth2Token: authParams.oauth2Token,
55
+ requestBody: authParams.requestBody
56
+ });
57
+ break;
58
+
59
+ default:
60
+ throw new Error(`Unknown partner type: ${partnerType}`);
61
+ }
62
+
63
+ return {
64
+ ...baseHeaders,
65
+ 'Authorization': `Bearer ${tokenData.token}`
66
+ };
67
+ }
68
+
69
+ /**
70
+ * Handle 403 errors with Premium plan messaging
71
+ */
72
+ function handleLogsError(error, operation) {
73
+ if (error.response?.status === 403) {
74
+ throw new Error(
75
+ `Access denied: Logs API requires Premium (PRM) plan. ` +
76
+ `Please upgrade your subscription to access application logs. ` +
77
+ `Original error: ${error.response?.data?.message || 'Forbidden'}`
78
+ );
79
+ }
80
+ throw describeApiError(error, '${operation}');
81
+ }
82
+
83
+ /**
84
+ * Query logs with filters
85
+ * @param {Object} params - Query parameters
86
+ * @returns {Promise<Object>} Log query response
87
+ */
88
+ export async function queryLogs({
89
+ from,
90
+ to,
91
+ level,
92
+ logger,
93
+ search,
94
+ limit = 1000,
95
+ cursor,
96
+ partnerType,
97
+ ...authParams
98
+ }) {
99
+ const headers = await createAuthHeaders(partnerType, authParams);
100
+
101
+ // Build query parameters
102
+ const queryParams = new URLSearchParams();
103
+ if (from) queryParams.append('from', from);
104
+ if (to) queryParams.append('to', to);
105
+ if (level) queryParams.append('level', level);
106
+ if (logger) queryParams.append('logger', logger);
107
+ if (search) queryParams.append('search', search);
108
+ if (limit) queryParams.append('limit', limit.toString());
109
+ if (cursor) queryParams.append('cursor', cursor);
110
+
111
+ const queryString = queryParams.toString();
112
+ const url = `${getProductionUrl()}/logs${queryString ? '?' + queryString : ''}`;
113
+
114
+ try {
115
+ const response = await axios.get(url, { headers });
116
+
117
+ return {
118
+ success: true,
119
+ data: response.data,
120
+ requestInfo: {
121
+ url,
122
+ method: 'GET',
123
+ statusCode: response.status
124
+ }
125
+ };
126
+ } catch (error) {
127
+ handleLogsError(error, 'query logs');
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Get log status (availability and storage info)
133
+ * @param {Object} params - Authentication parameters
134
+ * @returns {Promise<Object>} Log status response
135
+ */
136
+ export async function getLogStatus({
137
+ partnerType,
138
+ ...authParams
139
+ }) {
140
+ const headers = await createAuthHeaders(partnerType, authParams);
141
+
142
+ try {
143
+ const response = await axios.get(
144
+ `${getProductionUrl()}/logs/status`,
145
+ { headers }
146
+ );
147
+
148
+ return {
149
+ success: true,
150
+ data: response.data,
151
+ requestInfo: {
152
+ url: `${getProductionUrl()}/logs/status`,
153
+ method: 'GET',
154
+ statusCode: response.status
155
+ }
156
+ };
157
+ } catch (error) {
158
+ handleLogsError(error, 'get log status');
159
+ }
160
+ }
161
+
162
+ /**
163
+ * Get download URL for logs archive
164
+ * @param {Object} params - Query parameters for date range
165
+ * @returns {Promise<Object>} Download URL information
166
+ */
167
+ export async function getLogDownloadUrl({
168
+ from,
169
+ to,
170
+ partnerType,
171
+ ...authParams
172
+ }) {
173
+ // Build query parameters for the download URL
174
+ const queryParams = new URLSearchParams();
175
+ if (from) queryParams.append('from', from);
176
+ if (to) queryParams.append('to', to);
177
+
178
+ const queryString = queryParams.toString();
179
+ const downloadUrl = `${getProductionUrl()}/logs/download${queryString ? '?' + queryString : ''}`;
180
+
181
+ // Note: The actual download requires authentication headers
182
+ // This returns the URL structure that would be used
183
+ return {
184
+ success: true,
185
+ data: {
186
+ downloadUrl,
187
+ note: 'Use this URL with proper JWT authentication headers to download logs as gzipped JSON',
188
+ parameters: {
189
+ from: from || 'default (24 hours ago)',
190
+ to: to || 'default (now)'
191
+ }
192
+ },
193
+ requestInfo: {
194
+ url: downloadUrl,
195
+ method: 'GET (with auth headers)'
196
+ }
197
+ };
198
+ }
199
+
200
+ /**
201
+ * Download logs as compressed archive
202
+ * @param {Object} params - Query parameters for date range
203
+ * @returns {Promise<Object>} Downloaded log data
204
+ */
205
+ export async function downloadLogs({
206
+ from,
207
+ to,
208
+ partnerType,
209
+ ...authParams
210
+ }) {
211
+ const headers = await createAuthHeaders(partnerType, authParams);
212
+
213
+ // Build query parameters
214
+ const queryParams = new URLSearchParams();
215
+ if (from) queryParams.append('from', from);
216
+ if (to) queryParams.append('to', to);
217
+
218
+ const queryString = queryParams.toString();
219
+ const url = `${getProductionUrl()}/logs/download${queryString ? '?' + queryString : ''}`;
220
+
221
+ try {
222
+ const response = await axios.get(url, {
223
+ headers,
224
+ responseType: 'arraybuffer'
225
+ });
226
+
227
+ return {
228
+ success: true,
229
+ data: response.data,
230
+ contentType: response.headers['content-type'],
231
+ contentDisposition: response.headers['content-disposition'],
232
+ contentLength: response.headers['content-length'],
233
+ requestInfo: {
234
+ url,
235
+ method: 'GET',
236
+ statusCode: response.status
237
+ }
238
+ };
239
+ } catch (error) {
240
+ handleLogsError(error, 'download logs');
241
+ }
242
+ }