@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.
- package/.env.example +92 -0
- package/MCP-SETUP.md +190 -0
- package/README.md +483 -0
- package/check-keys.js +52 -0
- package/keys/README.md +112 -0
- package/mcp-config.json +9 -0
- package/package.json +66 -0
- package/payware-mcp-config.json +12 -0
- package/src/auth/rsa-keys.js +82 -0
- package/src/auth/sandbox-setup.js +187 -0
- package/src/config/env.js +229 -0
- package/src/config/partner-types.js +143 -0
- package/src/core/auth/jwt-factory.js +182 -0
- package/src/core/auth/jwt-token.js +735 -0
- package/src/core/utils/json-serializer.js +100 -0
- package/src/core/utils/key-utils.js +133 -0
- package/src/index.js +237 -0
- package/src/isv/data/index.js +291 -0
- package/src/isv/deep-links/delete-product-link.js +154 -0
- package/src/isv/deep-links/delete-transaction-link.js +154 -0
- package/src/isv/deep-links/get-product-link.js +167 -0
- package/src/isv/deep-links/get-transaction-link.js +167 -0
- package/src/isv/deep-links/index.js +23 -0
- package/src/isv/index.js +103 -0
- package/src/isv/oauth2/create-token-simple.js +46 -0
- package/src/isv/oauth2/get-token-info.js +157 -0
- package/src/isv/oauth2/obtain-token.js +189 -0
- package/src/isv/oauth2/token-helper.js +151 -0
- package/src/isv/products/audios.js +470 -0
- package/src/isv/products/create-product.js +314 -0
- package/src/isv/products/delete-product.js +119 -0
- package/src/isv/products/get-product-image.js +247 -0
- package/src/isv/products/get-product.js +168 -0
- package/src/isv/products/index.js +65 -0
- package/src/isv/products/list-products.js +136 -0
- package/src/isv/products/schedules.js +522 -0
- package/src/isv/products/update-product.js +265 -0
- package/src/isv/transactions/cancel-transaction.js +129 -0
- package/src/isv/transactions/create-transaction.js +361 -0
- package/src/isv/transactions/get-status.js +217 -0
- package/src/isv/transactions/process-transaction.js +145 -0
- package/src/isv/transactions/simulate-callback.js +146 -0
- package/src/isv/transactions/transaction-history.js +186 -0
- package/src/isv/utils/auth.js +159 -0
- package/src/mcp-proxy.js +150 -0
- package/src/merchant/data/export-report.js +108 -0
- package/src/merchant/data/generate-report.js +151 -0
- package/src/merchant/data/get-report-status.js +120 -0
- package/src/merchant/data/index.js +351 -0
- package/src/merchant/deep-links/delete-product-link.js +121 -0
- package/src/merchant/deep-links/delete-transaction-link.js +121 -0
- package/src/merchant/deep-links/get-product-link.js +134 -0
- package/src/merchant/deep-links/get-transaction-link.js +134 -0
- package/src/merchant/deep-links/index.js +23 -0
- package/src/merchant/index.js +92 -0
- package/src/merchant/products/audios.js +606 -0
- package/src/merchant/products/create-product.js +288 -0
- package/src/merchant/products/delete-product.js +111 -0
- package/src/merchant/products/get-product-image.js +252 -0
- package/src/merchant/products/get-product.js +144 -0
- package/src/merchant/products/index.js +65 -0
- package/src/merchant/products/list-products.js +112 -0
- package/src/merchant/products/schedules.js +646 -0
- package/src/merchant/products/update-product.js +282 -0
- package/src/merchant/transactions/cancel-transaction.js +241 -0
- package/src/merchant/transactions/create-transaction.js +482 -0
- package/src/merchant/transactions/get-status.js +196 -0
- package/src/merchant/transactions/process-transaction.js +349 -0
- package/src/merchant/transactions/simulate-callback.js +246 -0
- package/src/merchant/transactions/transaction-history.js +258 -0
- package/src/payment-institution/data/index.js +280 -0
- package/src/payment-institution/deep-links/delete-transaction-link.js +128 -0
- package/src/payment-institution/deep-links/get-transaction-link.js +141 -0
- package/src/payment-institution/deep-links/index.js +17 -0
- package/src/payment-institution/index.js +92 -0
- package/src/payment-institution/transactions/create-pi-transaction.js +484 -0
- package/src/payment-institution/transactions/finalize-transaction.js +340 -0
- package/src/payment-institution/transactions/get-transaction-history.js +269 -0
- package/src/payment-institution/transactions/get-transaction-status.js +234 -0
- package/src/payment-institution/transactions/process-pi-transaction.js +421 -0
- package/src/payment-institution/transactions/simulate-pi-callback.js +326 -0
- package/src/payment-institution/transactions/soundbite-transaction.js +269 -0
- package/src/proxy-server.js +205 -0
- package/src/shared/data/data-api.js +372 -0
- package/src/shared/deep-links/api.js +214 -0
- package/src/shared/index.js +44 -0
- package/src/shared/products/products-api.js +872 -0
- package/src/tools/advanced-code-generator.js +2247 -0
- package/src/utils/code-examples/common/auth-examples.js +1482 -0
- package/src/utils/code-examples/common/helpers.js +416 -0
- package/src/utils/code-examples/common/utils-examples.js +591 -0
- package/src/utils/code-examples/frameworks/examples.js +859 -0
- package/src/utils/code-examples/index.js +441 -0
- package/src/utils/code-examples/isv/oauth2.js +600 -0
- package/src/utils/code-examples/isv/products.js +666 -0
- package/src/utils/code-examples/isv/transactions.js +813 -0
- package/src/utils/code-examples/merchant/products.js +497 -0
- package/src/utils/code-examples/merchant/transactions.js +623 -0
- package/src/utils/code-examples/payment-institution/transactions.js +388 -0
- package/src/utils/code-examples/shared/data.js +607 -0
- package/src/utils/code-examples/shared/deep-links.js +662 -0
- package/src/utils/code-examples/shared/soundbites.js +808 -0
- package/src/utils/code-examples.js +646 -0
- package/src/utils/format-request.js +363 -0
- package/src/utils/json-formatter.js +249 -0
- package/src/utils/server-info.js +132 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Common helper functions for code example generation
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Base class for all code example generators
|
|
7
|
+
*/
|
|
8
|
+
export class ExampleGenerator {
|
|
9
|
+
constructor(language, framework = 'none') {
|
|
10
|
+
this.language = language;
|
|
11
|
+
this.framework = framework;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Generate a complete code example
|
|
16
|
+
* @param {string} operation - The operation to generate example for
|
|
17
|
+
* @param {string} partnerType - Partner type (merchant, isv, payment_institution)
|
|
18
|
+
* @param {Object} options - Generation options
|
|
19
|
+
* @returns {string} Generated code example
|
|
20
|
+
*/
|
|
21
|
+
generateExample(operation, partnerType, options = {}) {
|
|
22
|
+
const {
|
|
23
|
+
includeComments = true,
|
|
24
|
+
includeErrorHandling = true,
|
|
25
|
+
includeTests = false,
|
|
26
|
+
includeEnvironmentSetup = true,
|
|
27
|
+
...params
|
|
28
|
+
} = options;
|
|
29
|
+
|
|
30
|
+
const sections = [];
|
|
31
|
+
|
|
32
|
+
if (includeEnvironmentSetup) {
|
|
33
|
+
sections.push(this.generateEnvironmentSetup(partnerType));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
sections.push(this.generateDependencies(operation));
|
|
37
|
+
sections.push(this.generateAuthSetup(partnerType));
|
|
38
|
+
sections.push(this.generateMainOperation(operation, partnerType, params));
|
|
39
|
+
|
|
40
|
+
if (includeErrorHandling) {
|
|
41
|
+
sections.push(this.generateErrorHandling());
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (includeTests) {
|
|
45
|
+
sections.push(this.generateTests(operation, partnerType));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return sections.filter(Boolean).join('\n\n');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Generate environment setup section
|
|
53
|
+
*/
|
|
54
|
+
generateEnvironmentSetup(partnerType) {
|
|
55
|
+
return this.getEnvironmentTemplate(partnerType);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Generate dependencies section
|
|
60
|
+
*/
|
|
61
|
+
generateDependencies(operation) {
|
|
62
|
+
return this.getDependenciesTemplate(operation);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Generate authentication setup
|
|
67
|
+
*/
|
|
68
|
+
generateAuthSetup(partnerType) {
|
|
69
|
+
return this.getAuthTemplate(partnerType);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Generate main operation code
|
|
74
|
+
*/
|
|
75
|
+
generateMainOperation(operation, partnerType, params) {
|
|
76
|
+
return this.getOperationTemplate(operation, partnerType, params);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Generate error handling code
|
|
81
|
+
*/
|
|
82
|
+
generateErrorHandling() {
|
|
83
|
+
return this.getErrorHandlingTemplate();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Generate test code
|
|
88
|
+
*/
|
|
89
|
+
generateTests(operation, partnerType) {
|
|
90
|
+
return this.getTestTemplate(operation, partnerType);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Abstract methods to be implemented by language-specific generators
|
|
94
|
+
getEnvironmentTemplate(partnerType) { throw new Error('Not implemented'); }
|
|
95
|
+
getDependenciesTemplate(operation) { throw new Error('Not implemented'); }
|
|
96
|
+
getAuthTemplate(partnerType) { throw new Error('Not implemented'); }
|
|
97
|
+
getOperationTemplate(operation, partnerType, params) { throw new Error('Not implemented'); }
|
|
98
|
+
getErrorHandlingTemplate() { throw new Error('Not implemented'); }
|
|
99
|
+
getTestTemplate(operation, partnerType) { throw new Error('Not implemented'); }
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Common templates and utilities
|
|
104
|
+
*/
|
|
105
|
+
export const CommonTemplates = {
|
|
106
|
+
/**
|
|
107
|
+
* Get environment variables template for partner type
|
|
108
|
+
*/
|
|
109
|
+
getEnvironmentVariables(partnerType) {
|
|
110
|
+
const common = {
|
|
111
|
+
PAYWARE_PARTNER_TYPE: partnerType,
|
|
112
|
+
PAYWARE_PARTNER_ID: 'YOUR_PARTNER_ID',
|
|
113
|
+
PAYWARE_SANDBOX_PRIVATE_KEY_PATH: `keys/sandbox-${partnerType}-private-key.pem`,
|
|
114
|
+
PAYWARE_PRODUCTION_PRIVATE_KEY_PATH: `keys/production-${partnerType}-private-key.pem`,
|
|
115
|
+
PAYWARE_SANDBOX_URL: 'https://sandbox.payware.eu/api',
|
|
116
|
+
PAYWARE_PRODUCTION_URL: 'https://api.payware.eu/api'
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
if (partnerType === 'isv') {
|
|
120
|
+
return {
|
|
121
|
+
...common,
|
|
122
|
+
PAYWARE_OAUTH_CLIENT_ID: 'YOUR_OAUTH_CLIENT_ID',
|
|
123
|
+
PAYWARE_OAUTH_CLIENT_SECRET: 'YOUR_OAUTH_CLIENT_SECRET',
|
|
124
|
+
PAYWARE_DEFAULT_MERCHANT_ID: 'TARGET_MERCHANT_ID'
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return common;
|
|
129
|
+
},
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Get API endpoints for operations
|
|
133
|
+
*/
|
|
134
|
+
getApiEndpoint(operation, partnerType) {
|
|
135
|
+
const endpoints = {
|
|
136
|
+
// Transaction endpoints
|
|
137
|
+
create_transaction: '/transactions',
|
|
138
|
+
get_transaction_status: '/transactions/{id}',
|
|
139
|
+
cancel_transaction: '/transactions/{id}',
|
|
140
|
+
process_transaction: '/transactions/{id}',
|
|
141
|
+
get_transaction_history: '/transactions/{id}/history',
|
|
142
|
+
simulate_callback: '/transactions/{id}/callback',
|
|
143
|
+
|
|
144
|
+
// Product endpoints
|
|
145
|
+
create_product: '/products',
|
|
146
|
+
get_product: '/products/{id}',
|
|
147
|
+
update_product: '/products/{id}',
|
|
148
|
+
delete_product: '/products/{id}',
|
|
149
|
+
list_products: '/products',
|
|
150
|
+
get_product_image: '/products/{id}/image',
|
|
151
|
+
|
|
152
|
+
// Schedule endpoints
|
|
153
|
+
create_schedule: '/products/{id}/schedules',
|
|
154
|
+
get_schedule: '/products/{id}/schedules/{scheduleId}',
|
|
155
|
+
update_schedule: '/products/{id}/schedules/{scheduleId}',
|
|
156
|
+
delete_schedule: '/products/{id}/schedules/{scheduleId}',
|
|
157
|
+
list_schedules: '/products/{id}/schedules',
|
|
158
|
+
|
|
159
|
+
// Audio endpoints
|
|
160
|
+
register_audio: '/products/{id}/audios/upload',
|
|
161
|
+
get_audio: '/products/{id}/audios/{audioId}',
|
|
162
|
+
update_audio: '/products/{id}/audios/{audioId}',
|
|
163
|
+
delete_audio: '/products/{id}/audios/{audioId}',
|
|
164
|
+
list_audios: '/products/{id}/audios',
|
|
165
|
+
|
|
166
|
+
// Data endpoints
|
|
167
|
+
generate_report: '/data/reports',
|
|
168
|
+
get_report_status: '/data/reports/{id}',
|
|
169
|
+
export_report: '/data/exports',
|
|
170
|
+
download_export: '/data/exports/{id}',
|
|
171
|
+
cancel_report: '/data/reports/{id}',
|
|
172
|
+
|
|
173
|
+
// Deep link endpoints
|
|
174
|
+
get_transaction_link: '/deeplinks/transactions/{id}',
|
|
175
|
+
get_product_link: '/deeplinks/products/{id}',
|
|
176
|
+
delete_transaction_link: '/deeplinks/transactions/{id}',
|
|
177
|
+
delete_product_link: '/deeplinks/products/{id}',
|
|
178
|
+
|
|
179
|
+
// OAuth2 endpoints (ISV only)
|
|
180
|
+
obtain_token: '/oauth2/token',
|
|
181
|
+
get_token_info: '/oauth2/token/info',
|
|
182
|
+
create_token_simple: '/oauth2/token/simple',
|
|
183
|
+
|
|
184
|
+
// Payment Institution specific
|
|
185
|
+
create_pi_transaction: '/transactions',
|
|
186
|
+
process_pi_transaction: '/transactions/{id}',
|
|
187
|
+
finalize_transaction: '/transactions/{id}/finalize',
|
|
188
|
+
get_pi_transaction_status: '/transactions/{id}',
|
|
189
|
+
get_pi_transaction_history: '/transactions/{id}/history',
|
|
190
|
+
soundbite_transaction: '/transactions',
|
|
191
|
+
simulate_pi_callback: '/transactions/{id}/callback'
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
return endpoints[operation] || '/unknown-endpoint';
|
|
195
|
+
},
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Get HTTP method for operation
|
|
199
|
+
*/
|
|
200
|
+
getHttpMethod(operation) {
|
|
201
|
+
const methods = {
|
|
202
|
+
// GET operations
|
|
203
|
+
get_transaction_status: 'GET',
|
|
204
|
+
get_transaction_history: 'GET',
|
|
205
|
+
get_product: 'GET',
|
|
206
|
+
list_products: 'GET',
|
|
207
|
+
get_product_image: 'GET',
|
|
208
|
+
get_schedule: 'GET',
|
|
209
|
+
list_schedules: 'GET',
|
|
210
|
+
get_audio: 'GET',
|
|
211
|
+
list_audios: 'GET',
|
|
212
|
+
get_report_status: 'GET',
|
|
213
|
+
download_export: 'GET',
|
|
214
|
+
get_transaction_link: 'GET',
|
|
215
|
+
get_product_link: 'GET',
|
|
216
|
+
get_token_info: 'GET',
|
|
217
|
+
get_pi_transaction_status: 'GET',
|
|
218
|
+
get_pi_transaction_history: 'GET',
|
|
219
|
+
|
|
220
|
+
// POST operations
|
|
221
|
+
create_transaction: 'POST',
|
|
222
|
+
process_transaction: 'POST',
|
|
223
|
+
simulate_callback: 'POST',
|
|
224
|
+
create_product: 'POST',
|
|
225
|
+
create_schedule: 'POST',
|
|
226
|
+
register_audio: 'POST',
|
|
227
|
+
generate_report: 'POST',
|
|
228
|
+
export_report: 'POST',
|
|
229
|
+
obtain_token: 'POST',
|
|
230
|
+
create_token_simple: 'POST',
|
|
231
|
+
create_pi_transaction: 'POST',
|
|
232
|
+
process_pi_transaction: 'POST',
|
|
233
|
+
finalize_transaction: 'POST',
|
|
234
|
+
soundbite_transaction: 'POST',
|
|
235
|
+
simulate_pi_callback: 'POST',
|
|
236
|
+
|
|
237
|
+
// PATCH operations
|
|
238
|
+
cancel_transaction: 'PATCH',
|
|
239
|
+
update_product: 'PATCH',
|
|
240
|
+
update_schedule: 'PATCH',
|
|
241
|
+
update_audio: 'PATCH',
|
|
242
|
+
|
|
243
|
+
// DELETE operations
|
|
244
|
+
delete_product: 'DELETE',
|
|
245
|
+
delete_schedule: 'DELETE',
|
|
246
|
+
delete_audio: 'DELETE',
|
|
247
|
+
cancel_report: 'DELETE',
|
|
248
|
+
delete_transaction_link: 'DELETE',
|
|
249
|
+
delete_product_link: 'DELETE'
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
return methods[operation] || 'POST';
|
|
253
|
+
},
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Get sample request body for operation
|
|
257
|
+
*/
|
|
258
|
+
getSampleRequestBody(operation, partnerType, params = {}) {
|
|
259
|
+
const {
|
|
260
|
+
amount = '10.00',
|
|
261
|
+
currency = 'EUR',
|
|
262
|
+
reasonL1 = 'Test transaction',
|
|
263
|
+
reasonL2 = '',
|
|
264
|
+
transactionType = 'PLAIN',
|
|
265
|
+
productName = 'Test Product',
|
|
266
|
+
productPrice = '25.00'
|
|
267
|
+
} = params;
|
|
268
|
+
|
|
269
|
+
const bodies = {
|
|
270
|
+
create_transaction: {
|
|
271
|
+
trData: {
|
|
272
|
+
amount,
|
|
273
|
+
currency,
|
|
274
|
+
reasonL1,
|
|
275
|
+
...(reasonL2 && { reasonL2 })
|
|
276
|
+
},
|
|
277
|
+
trOptions: {
|
|
278
|
+
type: transactionType,
|
|
279
|
+
timeToLive: 120
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
cancel_transaction: {
|
|
284
|
+
status: 'CANCELLED',
|
|
285
|
+
statusMessage: 'Cancelled by user request'
|
|
286
|
+
},
|
|
287
|
+
|
|
288
|
+
process_transaction: partnerType === 'merchant' ? {
|
|
289
|
+
account: 'MERCHANT_ACCOUNT',
|
|
290
|
+
friendlyName: 'Merchant Name'
|
|
291
|
+
} : {
|
|
292
|
+
account: 'PI_ACCOUNT',
|
|
293
|
+
friendlyName: 'Payment Institution Name',
|
|
294
|
+
trData: {
|
|
295
|
+
amount,
|
|
296
|
+
currency,
|
|
297
|
+
reasonL1
|
|
298
|
+
}
|
|
299
|
+
},
|
|
300
|
+
|
|
301
|
+
create_product: {
|
|
302
|
+
name: productName,
|
|
303
|
+
shortDescription: 'Short description of the product',
|
|
304
|
+
prData: {
|
|
305
|
+
type: 'ITEM',
|
|
306
|
+
regularPrice: productPrice,
|
|
307
|
+
currency,
|
|
308
|
+
timeToLive: 86400
|
|
309
|
+
},
|
|
310
|
+
prOptions: {
|
|
311
|
+
imageUrl: 'https://example.com/product-image.jpg'
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
|
|
315
|
+
create_pi_transaction: {
|
|
316
|
+
trData: {
|
|
317
|
+
amount,
|
|
318
|
+
currency,
|
|
319
|
+
reasonL1,
|
|
320
|
+
...(reasonL2 && { reasonL2 })
|
|
321
|
+
},
|
|
322
|
+
trOptions: {
|
|
323
|
+
type: transactionType,
|
|
324
|
+
timeToLive: 120
|
|
325
|
+
}
|
|
326
|
+
},
|
|
327
|
+
|
|
328
|
+
finalize_transaction: {
|
|
329
|
+
status: 'CONFIRMED',
|
|
330
|
+
amount,
|
|
331
|
+
currency
|
|
332
|
+
},
|
|
333
|
+
|
|
334
|
+
obtain_token: {
|
|
335
|
+
grant_type: 'client_credentials',
|
|
336
|
+
client_id: 'YOUR_CLIENT_ID',
|
|
337
|
+
client_secret: 'YOUR_CLIENT_SECRET',
|
|
338
|
+
scope: 'transactions:create transactions:read'
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
return bodies[operation] || {};
|
|
343
|
+
}
|
|
344
|
+
};
|
|
345
|
+
|
|
346
|
+
/**
|
|
347
|
+
* Utility functions for code generation
|
|
348
|
+
*/
|
|
349
|
+
export const CodeUtils = {
|
|
350
|
+
/**
|
|
351
|
+
* Format parameter for different languages
|
|
352
|
+
*/
|
|
353
|
+
formatParameter(value, language) {
|
|
354
|
+
if (typeof value === 'string') {
|
|
355
|
+
switch (language) {
|
|
356
|
+
case 'python':
|
|
357
|
+
return `'${value}'`;
|
|
358
|
+
case 'javascript':
|
|
359
|
+
case 'nodejs':
|
|
360
|
+
return `'${value}'`;
|
|
361
|
+
case 'php':
|
|
362
|
+
return `'${value}'`;
|
|
363
|
+
case 'java':
|
|
364
|
+
return `"${value}"`;
|
|
365
|
+
case 'csharp':
|
|
366
|
+
return `"${value}"`;
|
|
367
|
+
case 'go':
|
|
368
|
+
return `"${value}"`;
|
|
369
|
+
case 'ruby':
|
|
370
|
+
return `'${value}'`;
|
|
371
|
+
default:
|
|
372
|
+
return `"${value}"`;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return value;
|
|
376
|
+
},
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* Generate variable name for different languages
|
|
380
|
+
*/
|
|
381
|
+
formatVariableName(name, language) {
|
|
382
|
+
switch (language) {
|
|
383
|
+
case 'python':
|
|
384
|
+
return name.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
385
|
+
case 'java':
|
|
386
|
+
case 'csharp':
|
|
387
|
+
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
388
|
+
case 'go':
|
|
389
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
390
|
+
default:
|
|
391
|
+
return name;
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
|
|
395
|
+
/**
|
|
396
|
+
* Generate function name for different languages
|
|
397
|
+
*/
|
|
398
|
+
formatFunctionName(name, language) {
|
|
399
|
+
switch (language) {
|
|
400
|
+
case 'python':
|
|
401
|
+
return name.replace(/([A-Z])/g, '_$1').toLowerCase();
|
|
402
|
+
case 'java':
|
|
403
|
+
case 'javascript':
|
|
404
|
+
case 'nodejs':
|
|
405
|
+
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
406
|
+
case 'csharp':
|
|
407
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
408
|
+
case 'go':
|
|
409
|
+
return name.charAt(0).toUpperCase() + name.slice(1);
|
|
410
|
+
case 'php':
|
|
411
|
+
return name.charAt(0).toLowerCase() + name.slice(1);
|
|
412
|
+
default:
|
|
413
|
+
return name;
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
};
|