spaps 0.2.7 โ 0.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.
- package/bin/spaps.js +82 -0
- package/package.json +1 -1
- package/src/ai-helper.js +273 -0
package/bin/spaps.js
CHANGED
|
@@ -15,6 +15,7 @@ const fs = require('fs');
|
|
|
15
15
|
const { handleError } = require('../src/error-handler');
|
|
16
16
|
const { showInteractiveHelp, showQuickHelp } = require('../src/help-system');
|
|
17
17
|
const { showInteractiveDocs, showQuickReference, searchDocs } = require('../src/docs-system');
|
|
18
|
+
const { getQuickStartInstructions, getServerStatus, runQuickTest } = require('../src/ai-helper');
|
|
18
19
|
|
|
19
20
|
const version = require('../package.json').version;
|
|
20
21
|
|
|
@@ -93,6 +94,87 @@ program
|
|
|
93
94
|
}
|
|
94
95
|
});
|
|
95
96
|
|
|
97
|
+
// Quickstart command - For AI agents
|
|
98
|
+
program
|
|
99
|
+
.command('quickstart')
|
|
100
|
+
.description('Get quick start instructions (for AI agents)')
|
|
101
|
+
.option('-p, --port <port>', 'Port to check', '3300')
|
|
102
|
+
.option('--json', 'Output in JSON format')
|
|
103
|
+
.action(async (options) => {
|
|
104
|
+
const instructions = getQuickStartInstructions(options.port);
|
|
105
|
+
|
|
106
|
+
if (options.json === true) {
|
|
107
|
+
console.log(JSON.stringify(instructions, null, 2));
|
|
108
|
+
process.exit(0);
|
|
109
|
+
} else {
|
|
110
|
+
console.log(chalk.yellow('\n๐ SPAPS Quick Start Instructions\n'));
|
|
111
|
+
console.log('1. Install SDK: npm install spaps-sdk');
|
|
112
|
+
console.log('2. Create test file with the code above');
|
|
113
|
+
console.log('3. Run: node test-spaps.js');
|
|
114
|
+
console.log('\nFor JSON output: npx spaps quickstart --json');
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
// Status command - Check if server is running
|
|
119
|
+
program
|
|
120
|
+
.command('status')
|
|
121
|
+
.description('Check if SPAPS server is running')
|
|
122
|
+
.option('-p, --port <port>', 'Port to check', '3300')
|
|
123
|
+
.option('--json', 'Output in JSON format')
|
|
124
|
+
.action(async (options) => {
|
|
125
|
+
const status = await getServerStatus(options.port);
|
|
126
|
+
|
|
127
|
+
if (options.json) {
|
|
128
|
+
console.log(JSON.stringify(status));
|
|
129
|
+
} else {
|
|
130
|
+
if (status.running) {
|
|
131
|
+
console.log(chalk.green(`โ
SPAPS is running on port ${options.port}`));
|
|
132
|
+
console.log(chalk.blue(` URL: ${status.url}`));
|
|
133
|
+
console.log(chalk.blue(` Docs: ${status.docs}`));
|
|
134
|
+
} else {
|
|
135
|
+
console.log(chalk.red(`โ SPAPS is not running on port ${options.port}`));
|
|
136
|
+
console.log(chalk.yellow(` Start with: ${status.start_command}`));
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// Test command - Run quick tests
|
|
142
|
+
program
|
|
143
|
+
.command('test')
|
|
144
|
+
.description('Run quick tests to verify SPAPS is working')
|
|
145
|
+
.option('-p, --port <port>', 'Port to test', '3300')
|
|
146
|
+
.option('--json', 'Output in JSON format')
|
|
147
|
+
.action(async (options) => {
|
|
148
|
+
const results = await runQuickTest(options.port);
|
|
149
|
+
|
|
150
|
+
if (options.json) {
|
|
151
|
+
console.log(JSON.stringify(results, null, 2));
|
|
152
|
+
} else {
|
|
153
|
+
console.log(chalk.yellow('\n๐งช Running SPAPS Tests...\n'));
|
|
154
|
+
|
|
155
|
+
results.results.forEach(result => {
|
|
156
|
+
const icon = result.success ? 'โ
' : 'โ';
|
|
157
|
+
console.log(`${icon} ${result.test}`);
|
|
158
|
+
if (!result.success && result.fix) {
|
|
159
|
+
console.log(chalk.yellow(` Fix: ${result.fix}`));
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
console.log();
|
|
164
|
+
console.log(results.success ?
|
|
165
|
+
chalk.green(`โจ ${results.summary}`) :
|
|
166
|
+
chalk.red(`โ ๏ธ ${results.summary}`)
|
|
167
|
+
);
|
|
168
|
+
|
|
169
|
+
if (results.next_steps) {
|
|
170
|
+
console.log('\nNext steps:');
|
|
171
|
+
results.next_steps.forEach(step => {
|
|
172
|
+
console.log(` โข ${step}`);
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
|
|
96
178
|
// Init command - Initialize SPAPS in existing project
|
|
97
179
|
program
|
|
98
180
|
.command('init')
|
package/package.json
CHANGED
package/src/ai-helper.js
ADDED
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPAPS AI Agent Helper
|
|
3
|
+
* Provides AI-friendly outputs and quick commands
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const chalk = require('chalk');
|
|
7
|
+
|
|
8
|
+
function getQuickStartInstructions(port = 3300) {
|
|
9
|
+
return {
|
|
10
|
+
success: true,
|
|
11
|
+
instructions: {
|
|
12
|
+
step1: {
|
|
13
|
+
description: "Install SDK",
|
|
14
|
+
command: "npm install spaps-sdk",
|
|
15
|
+
verify: "npm list spaps-sdk"
|
|
16
|
+
},
|
|
17
|
+
step2: {
|
|
18
|
+
description: "Create test file",
|
|
19
|
+
filename: "test-spaps.js",
|
|
20
|
+
content: `const { SPAPSClient } = require('spaps-sdk');
|
|
21
|
+
|
|
22
|
+
async function test() {
|
|
23
|
+
const spaps = new SPAPSClient({
|
|
24
|
+
apiUrl: 'http://localhost:${port}'
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
// Test login
|
|
28
|
+
const { data } = await spaps.login('test@example.com', 'password');
|
|
29
|
+
console.log('โ
Login successful:', data.user.email);
|
|
30
|
+
|
|
31
|
+
// Test authenticated request
|
|
32
|
+
const user = await spaps.getUser();
|
|
33
|
+
console.log('โ
Got user:', user.data.email);
|
|
34
|
+
|
|
35
|
+
return { success: true, user: user.data };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
test().then(console.log).catch(console.error);`
|
|
39
|
+
},
|
|
40
|
+
step3: {
|
|
41
|
+
description: "Run test",
|
|
42
|
+
command: "node test-spaps.js",
|
|
43
|
+
expected_output: {
|
|
44
|
+
success: true,
|
|
45
|
+
user: {
|
|
46
|
+
id: "local-user-123",
|
|
47
|
+
email: "test@example.com"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
endpoints: [
|
|
53
|
+
{
|
|
54
|
+
method: "POST",
|
|
55
|
+
path: "/api/auth/login",
|
|
56
|
+
body: { email: "string", password: "string" },
|
|
57
|
+
response: { access_token: "string", refresh_token: "string", user: "object" }
|
|
58
|
+
},
|
|
59
|
+
{
|
|
60
|
+
method: "POST",
|
|
61
|
+
path: "/api/auth/register",
|
|
62
|
+
body: { email: "string", password: "string" },
|
|
63
|
+
response: { access_token: "string", refresh_token: "string", user: "object" }
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
method: "GET",
|
|
67
|
+
path: "/api/auth/user",
|
|
68
|
+
headers: { Authorization: "Bearer TOKEN" },
|
|
69
|
+
response: { id: "string", email: "string", role: "string" }
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
method: "POST",
|
|
73
|
+
path: "/api/stripe/create-checkout-session",
|
|
74
|
+
body: { price_id: "string", success_url: "string" },
|
|
75
|
+
response: { sessionId: "string", url: "string" }
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
method: "GET",
|
|
79
|
+
path: "/api/usage/balance",
|
|
80
|
+
headers: { Authorization: "Bearer TOKEN" },
|
|
81
|
+
response: { balance: "number", currency: "string" }
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
test_commands: {
|
|
85
|
+
health_check: `curl http://localhost:${port}/health`,
|
|
86
|
+
login: `curl -X POST http://localhost:${port}/api/auth/login -H "Content-Type: application/json" -d '{"email":"test@example.com","password":"password"}'`,
|
|
87
|
+
with_sdk: `node -e "const {SPAPSClient}=require('spaps-sdk');const s=new SPAPSClient();s.login('test@example.com','password').then(r=>console.log(JSON.stringify(r.data))).catch(console.error)"`
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function getServerStatus(port = 3300) {
|
|
93
|
+
const http = require('http');
|
|
94
|
+
|
|
95
|
+
return new Promise((resolve) => {
|
|
96
|
+
const options = {
|
|
97
|
+
hostname: 'localhost',
|
|
98
|
+
port: port,
|
|
99
|
+
path: '/health',
|
|
100
|
+
method: 'GET',
|
|
101
|
+
timeout: 1000
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const req = http.request(options, (res) => {
|
|
105
|
+
let data = '';
|
|
106
|
+
res.on('data', chunk => data += chunk);
|
|
107
|
+
res.on('end', () => {
|
|
108
|
+
try {
|
|
109
|
+
const parsed = JSON.parse(data);
|
|
110
|
+
resolve({
|
|
111
|
+
running: true,
|
|
112
|
+
port: port,
|
|
113
|
+
health: parsed,
|
|
114
|
+
url: `http://localhost:${port}`,
|
|
115
|
+
docs: `http://localhost:${port}/docs`
|
|
116
|
+
});
|
|
117
|
+
} catch {
|
|
118
|
+
resolve({ running: true, port: port, error: 'Invalid response' });
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
req.on('error', () => {
|
|
124
|
+
resolve({
|
|
125
|
+
running: false,
|
|
126
|
+
port: port,
|
|
127
|
+
message: 'Server not running',
|
|
128
|
+
start_command: `npx spaps local --port ${port}`
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
req.on('timeout', () => {
|
|
133
|
+
req.destroy();
|
|
134
|
+
resolve({
|
|
135
|
+
running: false,
|
|
136
|
+
port: port,
|
|
137
|
+
message: 'Server timeout',
|
|
138
|
+
start_command: `npx spaps local --port ${port}`
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
req.end();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
async function runQuickTest(port = 3300) {
|
|
147
|
+
const results = [];
|
|
148
|
+
|
|
149
|
+
// Check server
|
|
150
|
+
const status = await getServerStatus(port);
|
|
151
|
+
results.push({
|
|
152
|
+
test: 'server_status',
|
|
153
|
+
success: status.running,
|
|
154
|
+
details: status
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (!status.running) {
|
|
158
|
+
return {
|
|
159
|
+
success: false,
|
|
160
|
+
message: 'Server not running',
|
|
161
|
+
fix: `npx spaps local --port ${port}`,
|
|
162
|
+
results
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Try HTTP request
|
|
167
|
+
try {
|
|
168
|
+
const http = require('http');
|
|
169
|
+
const loginResult = await new Promise((resolve, reject) => {
|
|
170
|
+
const postData = JSON.stringify({
|
|
171
|
+
email: 'test@example.com',
|
|
172
|
+
password: 'password'
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
const options = {
|
|
176
|
+
hostname: 'localhost',
|
|
177
|
+
port: port,
|
|
178
|
+
path: '/api/auth/login',
|
|
179
|
+
method: 'POST',
|
|
180
|
+
headers: {
|
|
181
|
+
'Content-Type': 'application/json',
|
|
182
|
+
'Content-Length': Buffer.byteLength(postData)
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const req = http.request(options, (res) => {
|
|
187
|
+
let data = '';
|
|
188
|
+
res.on('data', chunk => data += chunk);
|
|
189
|
+
res.on('end', () => {
|
|
190
|
+
try {
|
|
191
|
+
resolve(JSON.parse(data));
|
|
192
|
+
} catch {
|
|
193
|
+
reject(new Error('Invalid JSON response'));
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
req.on('error', reject);
|
|
199
|
+
req.write(postData);
|
|
200
|
+
req.end();
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
results.push({
|
|
204
|
+
test: 'login_endpoint',
|
|
205
|
+
success: true,
|
|
206
|
+
response: loginResult
|
|
207
|
+
});
|
|
208
|
+
} catch (error) {
|
|
209
|
+
results.push({
|
|
210
|
+
test: 'login_endpoint',
|
|
211
|
+
success: false,
|
|
212
|
+
error: error.message
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Check SDK availability
|
|
217
|
+
try {
|
|
218
|
+
require.resolve('spaps-sdk');
|
|
219
|
+
results.push({
|
|
220
|
+
test: 'sdk_installed',
|
|
221
|
+
success: true,
|
|
222
|
+
message: 'spaps-sdk is installed'
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// Try SDK login
|
|
226
|
+
try {
|
|
227
|
+
const { SPAPSClient } = require('spaps-sdk');
|
|
228
|
+
const spaps = new SPAPSClient({ apiUrl: `http://localhost:${port}` });
|
|
229
|
+
const { data } = await spaps.login('test@example.com', 'password');
|
|
230
|
+
|
|
231
|
+
results.push({
|
|
232
|
+
test: 'sdk_login',
|
|
233
|
+
success: true,
|
|
234
|
+
user: data.user
|
|
235
|
+
});
|
|
236
|
+
} catch (error) {
|
|
237
|
+
results.push({
|
|
238
|
+
test: 'sdk_login',
|
|
239
|
+
success: false,
|
|
240
|
+
error: error.message
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
} catch {
|
|
244
|
+
results.push({
|
|
245
|
+
test: 'sdk_installed',
|
|
246
|
+
success: false,
|
|
247
|
+
message: 'spaps-sdk not installed',
|
|
248
|
+
fix: 'npm install spaps-sdk'
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
const allSuccess = results.every(r => r.success);
|
|
253
|
+
|
|
254
|
+
return {
|
|
255
|
+
success: allSuccess,
|
|
256
|
+
summary: `${results.filter(r => r.success).length}/${results.length} tests passed`,
|
|
257
|
+
results,
|
|
258
|
+
next_steps: allSuccess ? [
|
|
259
|
+
'Server is running and SDK is working',
|
|
260
|
+
'You can now use SPAPS in your application',
|
|
261
|
+
'See docs at http://localhost:' + port + '/docs'
|
|
262
|
+
] : [
|
|
263
|
+
'Fix the failing tests above',
|
|
264
|
+
'Run: npx spaps test --json to retry'
|
|
265
|
+
]
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
module.exports = {
|
|
270
|
+
getQuickStartInstructions,
|
|
271
|
+
getServerStatus,
|
|
272
|
+
runQuickTest
|
|
273
|
+
};
|