@liangshanli/mcp-server-project-standards 3.0.2 → 5.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/README.md +62 -1
- package/README.zh-CN.md +62 -1
- package/bin/cli.js +1 -1
- package/package.json +1 -1
- package/src/server-final.js +102 -9
- package/src/utils/api_common.js +3 -3
- package/src/utils/api_config.js +22 -22
- package/src/utils/api_debug.js +45 -45
- package/src/utils/api_execute.js +26 -26
- package/src/utils/api_login.js +24 -24
- package/src/utils/database_standards.js +9 -9
- package/src/utils/generate_cursorrules.js +172 -0
- package/src/utils/get_api_standards.js +17 -17
- package/src/utils/get_development_standards.js +9 -9
- package/src/utils/get_project_info.js +7 -7
- package/src/utils/get_project_structure.js +13 -13
- package/src/utils/list_directory.js +85 -0
package/src/utils/api_debug.js
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
const { getAllowedMethods, loadApiConfig, saveApiConfig, detectContentType } = require('./api_common');
|
|
2
2
|
const https = require('https');
|
|
3
3
|
|
|
4
|
-
//
|
|
4
|
+
// Create an agent for HTTPS requests that skips certificate verification
|
|
5
5
|
const httpsAgent = new https.Agent({
|
|
6
6
|
rejectUnauthorized: false
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* API
|
|
10
|
+
* API Debug Tool - Direct API request execution
|
|
11
11
|
*
|
|
12
|
-
*
|
|
13
|
-
* 1. JSON
|
|
14
|
-
* 2.
|
|
15
|
-
* 3.
|
|
12
|
+
* Supported body formats:
|
|
13
|
+
* 1. JSON object: {"username": "admin", "password": "123456"}
|
|
14
|
+
* 2. Form data: "username=admin&password=123456"
|
|
15
|
+
* 3. Plain text: "Hello World"
|
|
16
16
|
* 4. XML: "<user><name>John</name><email>john@example.com</email></user>"
|
|
17
17
|
* 5. HTML: "<html><body>Content</body></html>"
|
|
18
18
|
*
|
|
19
|
-
*
|
|
20
|
-
* - JSON
|
|
21
|
-
* -
|
|
19
|
+
* Auto content-type detection:
|
|
20
|
+
* - JSON object → application/json
|
|
21
|
+
* - Form data → application/x-www-form-urlencoded
|
|
22
22
|
* - XML → application/xml
|
|
23
23
|
* - HTML → text/html
|
|
24
|
-
* -
|
|
24
|
+
* - Plain text → text/plain
|
|
25
25
|
*
|
|
26
|
-
* @param {Object} params -
|
|
27
|
-
* @param {string} params.url -
|
|
28
|
-
* @param {string} params.method - HTTP
|
|
29
|
-
* @param {Object} params.headers -
|
|
30
|
-
* @param {Object} params.query -
|
|
31
|
-
* @param {*} params.body -
|
|
32
|
-
* @param {string} params.contentType -
|
|
33
|
-
* @param {Object} config -
|
|
34
|
-
* @param {Function} saveConfig -
|
|
35
|
-
* @returns {Object} API
|
|
26
|
+
* @param {Object} params - Parameters
|
|
27
|
+
* @param {string} params.url - API URL to execute (required)
|
|
28
|
+
* @param {string} params.method - HTTP method (optional, default GET)
|
|
29
|
+
* @param {Object} params.headers - Additional request headers (optional)
|
|
30
|
+
* @param {Object} params.query - Query parameters (optional)
|
|
31
|
+
* @param {*} params.body - Request body (optional, supports multiple formats)
|
|
32
|
+
* @param {string} params.contentType - Content-Type (optional, will be auto-detected)
|
|
33
|
+
* @param {Object} config - Server configuration
|
|
34
|
+
* @param {Function} saveConfig - Save configuration function
|
|
35
|
+
* @returns {Object} API debug result
|
|
36
36
|
*/
|
|
37
37
|
async function api_debug(params, config, saveConfig) {
|
|
38
38
|
const { url, method = 'GET', headers = {}, query, body, contentType } = params || {};
|
|
@@ -77,10 +77,10 @@ async function api_debug(params, config, saveConfig) {
|
|
|
77
77
|
}
|
|
78
78
|
|
|
79
79
|
try {
|
|
80
|
-
//
|
|
80
|
+
// Load current configuration
|
|
81
81
|
const apiDebugConfig = loadApiConfig();
|
|
82
82
|
|
|
83
|
-
//
|
|
83
|
+
// Verify if the request method is allowed
|
|
84
84
|
const allowedMethods = getAllowedMethods();
|
|
85
85
|
const requestMethod = method.toUpperCase();
|
|
86
86
|
|
|
@@ -88,7 +88,7 @@ async function api_debug(params, config, saveConfig) {
|
|
|
88
88
|
throw new Error(`Method ${requestMethod} is not allowed. Allowed methods: ${allowedMethods.join(', ')}`);
|
|
89
89
|
}
|
|
90
90
|
|
|
91
|
-
//
|
|
91
|
+
// Build full URL
|
|
92
92
|
let fullUrl;
|
|
93
93
|
if (url.startsWith('http://') || url.startsWith('https://')) {
|
|
94
94
|
fullUrl = url;
|
|
@@ -97,23 +97,23 @@ async function api_debug(params, config, saveConfig) {
|
|
|
97
97
|
fullUrl = baseUrl + url;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
//
|
|
100
|
+
// Merge request headers
|
|
101
101
|
const finalHeaders = {
|
|
102
102
|
...apiDebugConfig.headers,
|
|
103
103
|
...headers
|
|
104
104
|
};
|
|
105
105
|
|
|
106
|
-
//
|
|
106
|
+
// Process request body
|
|
107
107
|
let requestBody = null;
|
|
108
108
|
if (body && (requestMethod === 'POST' || requestMethod === 'PUT' || requestMethod === 'PATCH')) {
|
|
109
109
|
if (typeof body === 'string') {
|
|
110
|
-
//
|
|
110
|
+
// Check if it starts with { but cannot be parsed as a JSON object
|
|
111
111
|
if (body.trim().startsWith('{')) {
|
|
112
112
|
try {
|
|
113
113
|
JSON.parse(body);
|
|
114
|
-
//
|
|
114
|
+
// If can parse successfully, continue normal processing
|
|
115
115
|
} catch (parseError) {
|
|
116
|
-
//
|
|
116
|
+
// Cannot parse as JSON, give suggestions
|
|
117
117
|
return {
|
|
118
118
|
contentType: "text",
|
|
119
119
|
content: [
|
|
@@ -146,21 +146,21 @@ async function api_debug(params, config, saveConfig) {
|
|
|
146
146
|
}
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
-
//
|
|
149
|
+
// Check if Content-Type is specified
|
|
150
150
|
if (contentType) {
|
|
151
151
|
finalHeaders['Content-Type'] = contentType;
|
|
152
152
|
requestBody = body;
|
|
153
153
|
} else {
|
|
154
|
-
//
|
|
154
|
+
// Auto-detect Content-Type
|
|
155
155
|
const detectedType = detectContentType(body);
|
|
156
156
|
finalHeaders['Content-Type'] = detectedType;
|
|
157
157
|
requestBody = body;
|
|
158
158
|
}
|
|
159
159
|
} else if (typeof body === 'object') {
|
|
160
|
-
//
|
|
160
|
+
// Check if Content-Type is specified
|
|
161
161
|
if (contentType) {
|
|
162
162
|
if (contentType === 'application/x-www-form-urlencoded') {
|
|
163
|
-
//
|
|
163
|
+
// Convert to URL encoded format
|
|
164
164
|
const formData = new URLSearchParams();
|
|
165
165
|
Object.entries(body).forEach(([key, value]) => {
|
|
166
166
|
if (value !== null && value !== undefined) {
|
|
@@ -170,19 +170,19 @@ async function api_debug(params, config, saveConfig) {
|
|
|
170
170
|
finalHeaders['Content-Type'] = 'application/x-www-form-urlencoded';
|
|
171
171
|
requestBody = formData.toString();
|
|
172
172
|
} else {
|
|
173
|
-
//
|
|
173
|
+
// Other specified types, serialize directly
|
|
174
174
|
finalHeaders['Content-Type'] = contentType;
|
|
175
175
|
requestBody = JSON.stringify(body);
|
|
176
176
|
}
|
|
177
177
|
} else {
|
|
178
|
-
//
|
|
178
|
+
// Auto-detect: objects default to JSON format
|
|
179
179
|
finalHeaders['Content-Type'] = 'application/json';
|
|
180
180
|
requestBody = JSON.stringify(body);
|
|
181
181
|
}
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
-
//
|
|
185
|
+
// Process query parameters
|
|
186
186
|
let queryString = '';
|
|
187
187
|
if (query && Object.keys(query).length > 0) {
|
|
188
188
|
const queryParams = new URLSearchParams();
|
|
@@ -202,21 +202,21 @@ async function api_debug(params, config, saveConfig) {
|
|
|
202
202
|
let error = null;
|
|
203
203
|
|
|
204
204
|
try {
|
|
205
|
-
//
|
|
205
|
+
// Execute request
|
|
206
206
|
const fetchOptions = {
|
|
207
207
|
method: requestMethod,
|
|
208
208
|
headers: finalHeaders,
|
|
209
209
|
body: requestBody
|
|
210
210
|
};
|
|
211
211
|
|
|
212
|
-
//
|
|
212
|
+
// Add agent to HTTPS requests to skip certificate verification
|
|
213
213
|
if (finalRequestUrl.startsWith('https')) {
|
|
214
214
|
fetchOptions.agent = httpsAgent;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
response = await fetch(finalRequestUrl, fetchOptions);
|
|
218
218
|
|
|
219
|
-
//
|
|
219
|
+
// Get response data
|
|
220
220
|
const responseContentType = response.headers.get('content-type');
|
|
221
221
|
|
|
222
222
|
if (responseContentType && responseContentType.includes('application/json')) {
|
|
@@ -225,7 +225,7 @@ async function api_debug(params, config, saveConfig) {
|
|
|
225
225
|
responseData = await response.text();
|
|
226
226
|
}
|
|
227
227
|
|
|
228
|
-
//
|
|
228
|
+
// Determine if the request was successful (HTTP status code 200-299)
|
|
229
229
|
const isHttpSuccess = response.status >= 200 && response.status < 300;
|
|
230
230
|
success = isHttpSuccess;
|
|
231
231
|
|
|
@@ -235,20 +235,20 @@ async function api_debug(params, config, saveConfig) {
|
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
if (success && response) {
|
|
238
|
-
//
|
|
238
|
+
// Automatically add interface to the configuration list
|
|
239
239
|
try {
|
|
240
240
|
const apiConfig = loadApiConfig();
|
|
241
241
|
if (!apiConfig.list) {
|
|
242
242
|
apiConfig.list = [];
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
//
|
|
245
|
+
// Check if the same interface already exists
|
|
246
246
|
const existingApiIndex = apiConfig.list.findIndex(api =>
|
|
247
247
|
api.url === url && api.method === requestMethod
|
|
248
248
|
);
|
|
249
249
|
|
|
250
250
|
if (existingApiIndex === -1) {
|
|
251
|
-
//
|
|
251
|
+
// If it doesn't exist, add to the list
|
|
252
252
|
const newApi = {
|
|
253
253
|
url: url,
|
|
254
254
|
method: requestMethod,
|
|
@@ -281,7 +281,7 @@ async function api_debug(params, config, saveConfig) {
|
|
|
281
281
|
timestamp: new Date().toISOString()
|
|
282
282
|
};
|
|
283
283
|
} else {
|
|
284
|
-
//
|
|
284
|
+
// If it already exists, update the interface information
|
|
285
285
|
apiConfig.list[existingApiIndex] = {
|
|
286
286
|
...apiConfig.list[existingApiIndex],
|
|
287
287
|
url: url,
|
|
@@ -313,7 +313,7 @@ async function api_debug(params, config, saveConfig) {
|
|
|
313
313
|
};
|
|
314
314
|
}
|
|
315
315
|
} catch (saveError) {
|
|
316
|
-
//
|
|
316
|
+
// If saving fails, still return a success response
|
|
317
317
|
console.error('Failed to save API to list:', saveError.message);
|
|
318
318
|
return {
|
|
319
319
|
success: true,
|
|
@@ -334,7 +334,7 @@ async function api_debug(params, config, saveConfig) {
|
|
|
334
334
|
};
|
|
335
335
|
}
|
|
336
336
|
} else {
|
|
337
|
-
//
|
|
337
|
+
// Return response data even on failure
|
|
338
338
|
return {
|
|
339
339
|
success: false,
|
|
340
340
|
message: `Failed to execute API: ${url}`,
|
package/src/utils/api_execute.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
const { loadApiConfig, getAllowedMethods } = require('./api_common');
|
|
2
2
|
const https = require('https');
|
|
3
3
|
|
|
4
|
-
//
|
|
4
|
+
// Create an agent for HTTPS requests that skips certificate verification
|
|
5
5
|
const httpsAgent = new https.Agent({
|
|
6
6
|
rejectUnauthorized: false
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* API
|
|
11
|
-
* @param {Object} params -
|
|
12
|
-
* @param {number} params.index - API
|
|
13
|
-
* @param {Object} params.overrides -
|
|
14
|
-
* @param {string} params.overrides.url -
|
|
15
|
-
* @param {string} params.overrides.method -
|
|
16
|
-
* @param {Object} params.overrides.headers -
|
|
17
|
-
* @param {Object} params.overrides.query -
|
|
18
|
-
* @param {*} params.overrides.body -
|
|
19
|
-
* @param {string} params.overrides.contentType -
|
|
20
|
-
* @param {Object} config -
|
|
21
|
-
* @param {Function} saveConfig -
|
|
22
|
-
* @returns {Object} API
|
|
10
|
+
* API Execute Tool - Execute configured APIs by index
|
|
11
|
+
* @param {Object} params - Parameters
|
|
12
|
+
* @param {number} params.index - API index (required)
|
|
13
|
+
* @param {Object} params.overrides - Override parameters (optional)
|
|
14
|
+
* @param {string} params.overrides.url - Override URL
|
|
15
|
+
* @param {string} params.overrides.method - Override HTTP method
|
|
16
|
+
* @param {Object} params.overrides.headers - Override request headers
|
|
17
|
+
* @param {Object} params.overrides.query - Override query parameters
|
|
18
|
+
* @param {*} params.overrides.body - Override request body
|
|
19
|
+
* @param {string} params.overrides.contentType - Override content type
|
|
20
|
+
* @param {Object} config - Server configuration
|
|
21
|
+
* @param {Function} saveConfig - Save configuration function
|
|
22
|
+
* @returns {Object} API execution result
|
|
23
23
|
*/
|
|
24
24
|
async function api_execute(params, config, saveConfig) {
|
|
25
25
|
const { index, overrides = {} } = params || {};
|
|
@@ -29,7 +29,7 @@ async function api_execute(params, config, saveConfig) {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
try {
|
|
32
|
-
//
|
|
32
|
+
// Load API configuration
|
|
33
33
|
const apiDebugConfig = loadApiConfig();
|
|
34
34
|
|
|
35
35
|
if (!apiDebugConfig.list || !Array.isArray(apiDebugConfig.list)) {
|
|
@@ -40,10 +40,10 @@ async function api_execute(params, config, saveConfig) {
|
|
|
40
40
|
throw new Error(`API index ${index} is out of range. Available APIs: 0-${apiDebugConfig.list.length - 1}`);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
-
//
|
|
43
|
+
// Get API configuration
|
|
44
44
|
const apiConfig = apiDebugConfig.list[index];
|
|
45
45
|
|
|
46
|
-
//
|
|
46
|
+
// Merge configuration and override parameters
|
|
47
47
|
const finalConfig = {
|
|
48
48
|
url: overrides.url || apiConfig.url,
|
|
49
49
|
method: overrides.method || apiConfig.method || 'GET',
|
|
@@ -53,13 +53,13 @@ async function api_execute(params, config, saveConfig) {
|
|
|
53
53
|
contentType: overrides.contentType || apiConfig.contentType
|
|
54
54
|
};
|
|
55
55
|
|
|
56
|
-
//
|
|
56
|
+
// Verify HTTP method
|
|
57
57
|
const allowedMethods = getAllowedMethods();
|
|
58
58
|
if (!allowedMethods.includes(finalConfig.method.toUpperCase())) {
|
|
59
59
|
throw new Error(`HTTP method '${finalConfig.method}' is not allowed. Allowed methods: ${allowedMethods.join(', ')}`);
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
//
|
|
62
|
+
// Build full URL
|
|
63
63
|
let fullUrl;
|
|
64
64
|
if (finalConfig.url.startsWith('http://') || finalConfig.url.startsWith('https://')) {
|
|
65
65
|
fullUrl = finalConfig.url;
|
|
@@ -67,19 +67,19 @@ async function api_execute(params, config, saveConfig) {
|
|
|
67
67
|
fullUrl = apiDebugConfig.baseUrl + finalConfig.url;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
//
|
|
70
|
+
// Add query parameters
|
|
71
71
|
if (finalConfig.query && Object.keys(finalConfig.query).length > 0) {
|
|
72
72
|
const queryString = new URLSearchParams(finalConfig.query).toString();
|
|
73
73
|
fullUrl += (fullUrl.includes('?') ? '&' : '?') + queryString;
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
//
|
|
76
|
+
// Prepare request options
|
|
77
77
|
const requestOptions = {
|
|
78
78
|
method: finalConfig.method.toUpperCase(),
|
|
79
79
|
headers: finalConfig.headers
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
-
//
|
|
82
|
+
// Process request body
|
|
83
83
|
if (finalConfig.body && ['POST', 'PUT', 'PATCH'].includes(finalConfig.method.toUpperCase())) {
|
|
84
84
|
if (typeof finalConfig.body === 'object') {
|
|
85
85
|
requestOptions.body = JSON.stringify(finalConfig.body);
|
|
@@ -94,21 +94,21 @@ async function api_execute(params, config, saveConfig) {
|
|
|
94
94
|
}
|
|
95
95
|
}
|
|
96
96
|
|
|
97
|
-
//
|
|
97
|
+
// Execute request
|
|
98
98
|
const startTime = Date.now();
|
|
99
99
|
let response;
|
|
100
100
|
let responseData;
|
|
101
101
|
let error = null;
|
|
102
102
|
|
|
103
103
|
try {
|
|
104
|
-
//
|
|
104
|
+
// Add agent to HTTPS requests to skip certificate verification
|
|
105
105
|
if (fullUrl.startsWith('https')) {
|
|
106
106
|
requestOptions.agent = httpsAgent;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
response = await fetch(fullUrl, requestOptions);
|
|
110
110
|
|
|
111
|
-
//
|
|
111
|
+
// Process response
|
|
112
112
|
const contentType = response.headers.get('content-type') || '';
|
|
113
113
|
|
|
114
114
|
if (contentType.includes('application/json')) {
|
|
@@ -123,7 +123,7 @@ async function api_execute(params, config, saveConfig) {
|
|
|
123
123
|
|
|
124
124
|
const endTime = Date.now();
|
|
125
125
|
|
|
126
|
-
//
|
|
126
|
+
// Determine if the request was successful (HTTP status code 200-299)
|
|
127
127
|
const isHttpSuccess = response.status >= 200 && response.status < 300;
|
|
128
128
|
const success = isHttpSuccess;
|
|
129
129
|
|
package/src/utils/api_login.js
CHANGED
|
@@ -1,32 +1,32 @@
|
|
|
1
1
|
const { getLoginUrl, getLoginMethod, getLoginBody, loadApiConfig, saveApiConfig } = require('./api_common');
|
|
2
2
|
const https = require('https');
|
|
3
3
|
|
|
4
|
-
//
|
|
4
|
+
// Create an agent for HTTPS requests that skips certificate verification
|
|
5
5
|
const httpsAgent = new https.Agent({
|
|
6
6
|
rejectUnauthorized: false
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
|
-
* API
|
|
11
|
-
* @param {Object} params -
|
|
12
|
-
* @param {string} params.baseUrl -
|
|
13
|
-
* @param {Object} config -
|
|
14
|
-
* @param {Function} saveConfig -
|
|
15
|
-
* @returns {Object}
|
|
10
|
+
* API Login Tool - Execute login request directly (Get login info from environment variables)
|
|
11
|
+
* @param {Object} params - Parameters
|
|
12
|
+
* @param {string} params.baseUrl - Base URL (optional, overrides baseUrl in configuration)
|
|
13
|
+
* @param {Object} config - Server configuration
|
|
14
|
+
* @param {Function} saveConfig - Save configuration function
|
|
15
|
+
* @returns {Object} Login result
|
|
16
16
|
*/
|
|
17
17
|
async function api_login(params, config, saveConfig) {
|
|
18
18
|
const { baseUrl } = params || {};
|
|
19
19
|
|
|
20
20
|
try {
|
|
21
|
-
//
|
|
21
|
+
// Load current configuration
|
|
22
22
|
const apiDebugConfig = loadApiConfig();
|
|
23
23
|
|
|
24
|
-
//
|
|
24
|
+
// Use passed baseUrl or baseUrl from configuration
|
|
25
25
|
const finalBaseUrl = baseUrl || apiDebugConfig.baseUrl || '';
|
|
26
26
|
const loginUrl = getLoginUrl();
|
|
27
27
|
const loginMethod = getLoginMethod();
|
|
28
28
|
|
|
29
|
-
//
|
|
29
|
+
// Build full login URL
|
|
30
30
|
let fullLoginUrl;
|
|
31
31
|
if (loginUrl.startsWith('http://') || loginUrl.startsWith('https://')) {
|
|
32
32
|
fullLoginUrl = loginUrl;
|
|
@@ -34,29 +34,29 @@ async function api_login(params, config, saveConfig) {
|
|
|
34
34
|
fullLoginUrl = finalBaseUrl + loginUrl;
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
//
|
|
37
|
+
// Get login request body from environment variables
|
|
38
38
|
const loginBodyRaw = getLoginBody();
|
|
39
39
|
let loginBody;
|
|
40
40
|
|
|
41
|
-
//
|
|
41
|
+
// Process request body in different formats
|
|
42
42
|
if (typeof loginBodyRaw === 'string') {
|
|
43
|
-
//
|
|
43
|
+
// If it's a string, use it directly
|
|
44
44
|
loginBody = loginBodyRaw;
|
|
45
45
|
} else if (typeof loginBodyRaw === 'object') {
|
|
46
|
-
//
|
|
46
|
+
// If it's an object, convert to JSON string
|
|
47
47
|
loginBody = JSON.stringify(loginBodyRaw);
|
|
48
48
|
} else {
|
|
49
|
-
//
|
|
49
|
+
// Otherwise, use default format
|
|
50
50
|
loginBody = '{"username":"","password":""}';
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
//
|
|
53
|
+
// Prepare request headers
|
|
54
54
|
const headers = {
|
|
55
55
|
...apiDebugConfig.headers,
|
|
56
56
|
'Content-Type': 'application/json'
|
|
57
57
|
};
|
|
58
58
|
|
|
59
|
-
//
|
|
59
|
+
// Execute login request
|
|
60
60
|
let response;
|
|
61
61
|
let responseData;
|
|
62
62
|
let success = true;
|
|
@@ -69,14 +69,14 @@ async function api_login(params, config, saveConfig) {
|
|
|
69
69
|
body: loginBody
|
|
70
70
|
};
|
|
71
71
|
|
|
72
|
-
//
|
|
72
|
+
// Add agent to HTTPS requests to skip certificate verification
|
|
73
73
|
if (fullLoginUrl.startsWith('https')) {
|
|
74
74
|
fetchOptions.agent = httpsAgent;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
response = await fetch(fullLoginUrl, fetchOptions);
|
|
78
78
|
|
|
79
|
-
//
|
|
79
|
+
// Get response data
|
|
80
80
|
const contentType = response.headers.get('content-type');
|
|
81
81
|
|
|
82
82
|
if (contentType && contentType.includes('application/json')) {
|
|
@@ -85,17 +85,17 @@ async function api_login(params, config, saveConfig) {
|
|
|
85
85
|
responseData = await response.text();
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
//
|
|
88
|
+
// Determine if login was successful
|
|
89
89
|
const isHttpSuccess = response.status >= 200 && response.status < 300;
|
|
90
90
|
success = isHttpSuccess;
|
|
91
91
|
|
|
92
92
|
if (success) {
|
|
93
|
-
//
|
|
93
|
+
// Login successful, try to extract token and update common headers
|
|
94
94
|
let token = null;
|
|
95
95
|
|
|
96
|
-
//
|
|
96
|
+
// Try to extract token from response
|
|
97
97
|
if (responseData && typeof responseData === 'object') {
|
|
98
|
-
//
|
|
98
|
+
// Common token field names
|
|
99
99
|
const tokenFields = ['token', 'access_token', 'accessToken', 'authToken', 'jwt'];
|
|
100
100
|
for (const field of tokenFields) {
|
|
101
101
|
if (responseData[field]) {
|
|
@@ -105,7 +105,7 @@ async function api_login(params, config, saveConfig) {
|
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
|
|
108
|
-
//
|
|
108
|
+
// If token is found, automatically update Authorization header
|
|
109
109
|
if (token) {
|
|
110
110
|
apiDebugConfig.headers = {
|
|
111
111
|
...apiDebugConfig.headers,
|
|
@@ -21,7 +21,7 @@ async function database_standards(params, config, saveConfig) {
|
|
|
21
21
|
|
|
22
22
|
if (action === 'get') {
|
|
23
23
|
try {
|
|
24
|
-
//
|
|
24
|
+
// Get standards from database_standards field in config file, use default if not present
|
|
25
25
|
const databaseStandards = config?.database_standards || [
|
|
26
26
|
'Use meaningful table names with descriptive prefixes',
|
|
27
27
|
'Use snake_case for table and column names',
|
|
@@ -69,23 +69,23 @@ async function database_standards(params, config, saveConfig) {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
try {
|
|
72
|
-
//
|
|
72
|
+
// Update configuration
|
|
73
73
|
if (!config.database_standards) {
|
|
74
74
|
config.database_standards = [];
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
//
|
|
77
|
+
// Handle merging logic for array types
|
|
78
78
|
if (!forceOverwrite) {
|
|
79
|
-
//
|
|
79
|
+
// Merge array instead of overwrite if forceOverwrite is false
|
|
80
80
|
const existingArray = config.database_standards;
|
|
81
81
|
const newArray = [...new Set([...existingArray, ...standards])];
|
|
82
82
|
config.database_standards = newArray;
|
|
83
83
|
} else {
|
|
84
|
-
//
|
|
84
|
+
// Overwrite directly
|
|
85
85
|
config.database_standards = standards;
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
-
//
|
|
88
|
+
// Save configuration
|
|
89
89
|
const saved = saveConfig(config);
|
|
90
90
|
if (!saved) {
|
|
91
91
|
throw new Error('Failed to save configuration');
|
|
@@ -111,17 +111,17 @@ async function database_standards(params, config, saveConfig) {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
try {
|
|
114
|
-
//
|
|
114
|
+
// Ensure config.database_standards exists
|
|
115
115
|
if (!config.database_standards) {
|
|
116
116
|
config.database_standards = [];
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
//
|
|
119
|
+
// Find and delete specified standard
|
|
120
120
|
const standardIndex = config.database_standards.indexOf(standard);
|
|
121
121
|
if (standardIndex !== -1) {
|
|
122
122
|
config.database_standards.splice(standardIndex, 1);
|
|
123
123
|
|
|
124
|
-
//
|
|
124
|
+
// Save configuration
|
|
125
125
|
const saved = saveConfig(config);
|
|
126
126
|
if (!saved) {
|
|
127
127
|
throw new Error('Failed to save configuration');
|