@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,214 @@
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 } from '../../config/env.js';
5
+
6
+ /**
7
+ * Create authentication headers based on partner type
8
+ * @param {string} partnerType - merchant, isv, or payment_institution
9
+ * @param {Object} authParams - Authentication parameters
10
+ * @returns {Object} Headers for API request
11
+ */
12
+ async function createAuthHeaders(partnerType, authParams) {
13
+ const baseHeaders = {
14
+ 'Content-Type': 'application/json',
15
+ 'Api-Version': '1'
16
+ };
17
+
18
+ let tokenData;
19
+
20
+ switch (partnerType) {
21
+ case 'merchant':
22
+ case 'payment_institution':
23
+ // Standard JWT authentication
24
+ tokenData = createJWTToken(
25
+ authParams.partnerId,
26
+ authParams.privateKey,
27
+ authParams.requestBody || ''
28
+ );
29
+ break;
30
+
31
+ case 'isv':
32
+ // ISV JWT with OAuth2 - note the parameter mapping
33
+ tokenData = await createJWTForPartner({
34
+ partnerId: authParams.isvPartnerId,
35
+ privateKey: authParams.privateKey,
36
+ merchantId: authParams.merchantPartnerId, // Map merchantPartnerId to merchantId
37
+ oauth2Token: authParams.oauth2Token,
38
+ requestBody: authParams.requestBody || ''
39
+ });
40
+ break;
41
+
42
+ default:
43
+ throw new Error(`Unknown partner type: ${partnerType}`);
44
+ }
45
+
46
+ return {
47
+ ...baseHeaders,
48
+ 'Authorization': `Bearer ${tokenData.token}`
49
+ };
50
+ }
51
+
52
+ /**
53
+ * Get deep link for a transaction
54
+ * @param {Object} params - Parameters
55
+ * @param {string} params.transactionId - Transaction ID
56
+ * @param {string} params.partnerType - Partner type (merchant, isv, payment_institution)
57
+ * @param {Object} params.authParams - Authentication parameters
58
+ * @returns {Object} Deep link response
59
+ */
60
+ export async function getTransactionDeepLink({
61
+ transactionId,
62
+ partnerType,
63
+ ...authParams
64
+ }) {
65
+ if (!transactionId) {
66
+ throw new Error('transactionId is required');
67
+ }
68
+
69
+ const headers = await createAuthHeaders(partnerType, authParams);
70
+
71
+ try {
72
+ const response = await axios.get(
73
+ `${getProductionUrl()}/transactions/${transactionId}/link`,
74
+ { headers }
75
+ );
76
+
77
+ return {
78
+ success: true,
79
+ data: response.data,
80
+ requestInfo: {
81
+ url: `${getProductionUrl()}/transactions/${transactionId}/link`,
82
+ method: 'GET',
83
+ statusCode: response.status
84
+ }
85
+ };
86
+ } catch (error) {
87
+ throw new Error(`Failed to get transaction deep link: ${error.response?.data?.message || error.message}`);
88
+ }
89
+ }
90
+
91
+ /**
92
+ * Get deep link for a product
93
+ * @param {Object} params - Parameters
94
+ * @param {string} params.productId - Product ID
95
+ * @param {string} params.partnerType - Partner type (merchant, isv)
96
+ * @param {Object} params.authParams - Authentication parameters
97
+ * @returns {Object} Deep link response
98
+ */
99
+ export async function getProductDeepLink({
100
+ productId,
101
+ partnerType,
102
+ ...authParams
103
+ }) {
104
+ if (!productId) {
105
+ throw new Error('productId is required');
106
+ }
107
+
108
+ if (partnerType === 'payment_institution') {
109
+ throw new Error('Payment institutions do not manage products');
110
+ }
111
+
112
+ const headers = await createAuthHeaders(partnerType, authParams);
113
+
114
+ try {
115
+ const response = await axios.get(
116
+ `${getProductionUrl()}/products/${productId}/link`,
117
+ { headers }
118
+ );
119
+
120
+ return {
121
+ success: true,
122
+ data: response.data,
123
+ requestInfo: {
124
+ url: `${getProductionUrl()}/products/${productId}/link`,
125
+ method: 'GET',
126
+ statusCode: response.status
127
+ }
128
+ };
129
+ } catch (error) {
130
+ throw new Error(`Failed to get product deep link: ${error.response?.data?.message || error.message}`);
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Delete deep link for a transaction
136
+ * @param {Object} params - Parameters
137
+ * @param {string} params.transactionId - Transaction ID
138
+ * @param {string} params.partnerType - Partner type (merchant, isv, payment_institution)
139
+ * @param {Object} params.authParams - Authentication parameters
140
+ * @returns {Object} Delete response
141
+ */
142
+ export async function deleteTransactionDeepLink({
143
+ transactionId,
144
+ partnerType,
145
+ ...authParams
146
+ }) {
147
+ if (!transactionId) {
148
+ throw new Error('transactionId is required');
149
+ }
150
+
151
+ const headers = await createAuthHeaders(partnerType, authParams);
152
+
153
+ try {
154
+ const response = await axios.delete(
155
+ `${getProductionUrl()}/transactions/${transactionId}/link`,
156
+ { headers }
157
+ );
158
+
159
+ return {
160
+ success: true,
161
+ data: response.data,
162
+ requestInfo: {
163
+ url: `${getProductionUrl()}/transactions/${transactionId}/link`,
164
+ method: 'DELETE',
165
+ statusCode: response.status
166
+ }
167
+ };
168
+ } catch (error) {
169
+ throw new Error(`Failed to delete transaction deep link: ${error.response?.data?.message || error.message}`);
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Delete deep link for a product
175
+ * @param {Object} params - Parameters
176
+ * @param {string} params.productId - Product ID
177
+ * @param {string} params.partnerType - Partner type (merchant, isv)
178
+ * @param {Object} params.authParams - Authentication parameters
179
+ * @returns {Object} Delete response
180
+ */
181
+ export async function deleteProductDeepLink({
182
+ productId,
183
+ partnerType,
184
+ ...authParams
185
+ }) {
186
+ if (!productId) {
187
+ throw new Error('productId is required');
188
+ }
189
+
190
+ if (partnerType === 'payment_institution') {
191
+ throw new Error('Payment institutions do not manage products');
192
+ }
193
+
194
+ const headers = await createAuthHeaders(partnerType, authParams);
195
+
196
+ try {
197
+ const response = await axios.delete(
198
+ `${getProductionUrl()}/products/${productId}/link`,
199
+ { headers }
200
+ );
201
+
202
+ return {
203
+ success: true,
204
+ data: response.data,
205
+ requestInfo: {
206
+ url: `${getProductionUrl()}/products/${productId}/link`,
207
+ method: 'DELETE',
208
+ statusCode: response.status
209
+ }
210
+ };
211
+ } catch (error) {
212
+ throw new Error(`Failed to delete product deep link: ${error.response?.data?.message || error.message}`);
213
+ }
214
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Shared tools registry
3
+ * Tools available to all partner types
4
+ */
5
+
6
+ // Import utility tools that remain shared
7
+ import { generateCodeExampleTool, generateDocumentationTool } from '../tools/advanced-code-generator.js';
8
+ import { formatRequestTool } from '../utils/format-request.js';
9
+ import { getServerInfoTool } from '../utils/server-info.js';
10
+ import { formatJSONDeterministicTool } from '../utils/json-formatter.js';
11
+
12
+ // Import auth tools that remain shared
13
+ import { generateRSAKeysTool } from '../auth/rsa-keys.js';
14
+ import { createJWTTokenTool, validateJWTTokenTool, testJWTTokenTool } from '../core/auth/jwt-token.js';
15
+ import { setupSandboxAuthTool } from '../auth/sandbox-setup.js';
16
+
17
+ /**
18
+ * Tools shared across all partner types
19
+ */
20
+ export const sharedTools = [
21
+ // Authentication tools
22
+ generateRSAKeysTool,
23
+ createJWTTokenTool,
24
+ validateJWTTokenTool,
25
+ testJWTTokenTool,
26
+ setupSandboxAuthTool,
27
+
28
+ // Code generation tools
29
+ generateCodeExampleTool,
30
+ generateDocumentationTool,
31
+
32
+ // Utility tools
33
+ formatRequestTool,
34
+ getServerInfoTool,
35
+ formatJSONDeterministicTool
36
+ ];
37
+
38
+ /**
39
+ * Get shared tools with proper naming
40
+ * @returns {Array} Array of shared tools
41
+ */
42
+ export function getSharedTools() {
43
+ return sharedTools;
44
+ }