@optima-chat/dev-skills 0.7.13 → 0.7.14
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.
|
@@ -36,23 +36,34 @@ optima-generate-test-token [options]
|
|
|
36
36
|
### 基本使用
|
|
37
37
|
|
|
38
38
|
```bash
|
|
39
|
-
#
|
|
39
|
+
# CI 环境(默认)
|
|
40
40
|
optima-generate-test-token
|
|
41
41
|
|
|
42
|
-
#
|
|
43
|
-
optima-generate-test-token --env
|
|
42
|
+
# Stage 环境
|
|
43
|
+
optima-generate-test-token --env stage
|
|
44
|
+
|
|
45
|
+
# Prod 环境
|
|
46
|
+
optima-generate-test-token --env prod
|
|
44
47
|
|
|
45
48
|
# 自定义商户名称
|
|
46
|
-
optima-generate-test-token --business-name "我的测试店铺" --env
|
|
49
|
+
optima-generate-test-token --business-name "我的测试店铺" --env stage
|
|
47
50
|
|
|
48
51
|
# 完全自定义
|
|
49
52
|
optima-generate-test-token \
|
|
50
53
|
--email "test@example.com" \
|
|
51
54
|
--password "MyPassword123" \
|
|
52
55
|
--business-name "测试商店" \
|
|
53
|
-
--env
|
|
56
|
+
--env prod
|
|
54
57
|
```
|
|
55
58
|
|
|
59
|
+
### 环境说明
|
|
60
|
+
|
|
61
|
+
| 环境 | Auth URL | API URL |
|
|
62
|
+
|------|----------|---------|
|
|
63
|
+
| ci | `auth.optima.chat` | `api.optima.chat` |
|
|
64
|
+
| stage | `auth.stage.optima.onl` | `api.stage.optima.onl` |
|
|
65
|
+
| prod | `auth.optima.onl` | `api.optima.onl` |
|
|
66
|
+
|
|
56
67
|
### 使用生成的 Token
|
|
57
68
|
|
|
58
69
|
工具执行后会输出 token 文件路径,例如:`/tmp/optima-test-token-1763997011780.txt`
|
|
@@ -62,12 +73,12 @@ optima-generate-test-token \
|
|
|
62
73
|
```bash
|
|
63
74
|
# 查询商品列表
|
|
64
75
|
OPTIMA_TOKEN=$(cat /tmp/optima-test-token-xxx.txt) \
|
|
65
|
-
OPTIMA_ENV=
|
|
76
|
+
OPTIMA_ENV=ci \
|
|
66
77
|
commerce product list
|
|
67
78
|
|
|
68
79
|
# 创建商品
|
|
69
80
|
OPTIMA_TOKEN=$(cat /tmp/optima-test-token-xxx.txt) \
|
|
70
|
-
OPTIMA_ENV=
|
|
81
|
+
OPTIMA_ENV=ci \
|
|
71
82
|
commerce product create \
|
|
72
83
|
--title "测试商品" \
|
|
73
84
|
--description "这是一个测试商品" \
|
|
@@ -101,7 +112,7 @@ curl -H "Authorization: Bearer $(cat /tmp/optima-test-token-xxx.txt)" \
|
|
|
101
112
|
3. 使用 token 创建商品:
|
|
102
113
|
```bash
|
|
103
114
|
OPTIMA_TOKEN=$(cat /tmp/optima-test-token-xxx.txt) \
|
|
104
|
-
OPTIMA_ENV=
|
|
115
|
+
OPTIMA_ENV=ci \
|
|
105
116
|
commerce product create --title "测试商品" --price 99.99 --stock 100
|
|
106
117
|
```
|
|
107
118
|
|
|
@@ -115,7 +126,7 @@ curl -H "Authorization: Bearer $(cat /tmp/optima-test-token-xxx.txt)" \
|
|
|
115
126
|
3. 使用 token 查询订单:
|
|
116
127
|
```bash
|
|
117
128
|
OPTIMA_TOKEN=$(cat /tmp/optima-test-token-xxx.txt) \
|
|
118
|
-
OPTIMA_ENV=
|
|
129
|
+
OPTIMA_ENV=ci \
|
|
119
130
|
commerce order list
|
|
120
131
|
```
|
|
121
132
|
|
|
@@ -130,10 +141,10 @@ curl -H "Authorization: Bearer $(cat /tmp/optima-test-token-xxx.txt)" \
|
|
|
130
141
|
TOKEN_FILE=/tmp/optima-test-token-xxx.txt
|
|
131
142
|
|
|
132
143
|
# 创建多个商品
|
|
133
|
-
OPTIMA_TOKEN=$(cat $TOKEN_FILE) OPTIMA_ENV=
|
|
144
|
+
OPTIMA_TOKEN=$(cat $TOKEN_FILE) OPTIMA_ENV=ci \
|
|
134
145
|
commerce product create --title "商品A" --price 49.99 --stock 50
|
|
135
146
|
|
|
136
|
-
OPTIMA_TOKEN=$(cat $TOKEN_FILE) OPTIMA_ENV=
|
|
147
|
+
OPTIMA_TOKEN=$(cat $TOKEN_FILE) OPTIMA_ENV=ci \
|
|
137
148
|
commerce product create --title "商品B" --price 89.99 --stock 30
|
|
138
149
|
```
|
|
139
150
|
|
|
@@ -150,7 +161,7 @@ curl -H "Authorization: Bearer $(cat /tmp/optima-test-token-xxx.txt)" \
|
|
|
150
161
|
|
|
151
162
|
# 在环境变量中设置
|
|
152
163
|
export OPTIMA_TOKEN=$(cat $TOKEN_FILE)
|
|
153
|
-
export OPTIMA_ENV=
|
|
164
|
+
export OPTIMA_ENV=ci
|
|
154
165
|
|
|
155
166
|
# 运行测试
|
|
156
167
|
npm run test:api
|
|
@@ -179,7 +190,7 @@ curl -H "Authorization: Bearer $(cat /tmp/optima-test-token-xxx.txt)" \
|
|
|
179
190
|
TOKEN=$(cat /tmp/optima-test-token-1763997011780.txt)
|
|
180
191
|
|
|
181
192
|
# Use with commerce CLI:
|
|
182
|
-
OPTIMA_TOKEN=$(cat /tmp/optima-test-token-1763997011780.txt) OPTIMA_ENV=
|
|
193
|
+
OPTIMA_TOKEN=$(cat /tmp/optima-test-token-1763997011780.txt) OPTIMA_ENV=ci commerce product list
|
|
183
194
|
|
|
184
195
|
# Use in curl:
|
|
185
196
|
curl -H "Authorization: Bearer $(cat /tmp/optima-test-token-1763997011780.txt)" https://api.optima.chat/api/products
|
|
@@ -196,7 +207,7 @@ curl -H "Authorization: Bearer $(cat /tmp/optima-test-token-xxx.txt)" \
|
|
|
196
207
|
|
|
197
208
|
使用 commerce CLI 时**必须**设置环境变量:
|
|
198
209
|
```bash
|
|
199
|
-
OPTIMA_ENV=
|
|
210
|
+
OPTIMA_ENV=ci # 必需,指定环境 (ci/stage/prod)
|
|
200
211
|
OPTIMA_TOKEN=$(cat /tmp/optima-test-token-xxx.txt) # 必需,读取 token
|
|
201
212
|
```
|
|
202
213
|
|
|
@@ -212,13 +223,17 @@ OPTIMA_TOKEN=$(cat /tmp/optima-test-token-xxx.txt) # 必需,读取 token
|
|
|
212
223
|
- 系统重启后可能被清理
|
|
213
224
|
- 建议在使用完成后手动删除敏感文件
|
|
214
225
|
|
|
215
|
-
###
|
|
226
|
+
### 支持的环境
|
|
227
|
+
|
|
228
|
+
工具支持三个环境,使用 `--env` 参数指定:
|
|
229
|
+
|
|
230
|
+
| 环境 | Auth API | Commerce API |
|
|
231
|
+
|------|----------|--------------|
|
|
232
|
+
| ci (默认) | `https://auth.optima.chat` | `https://api.optima.chat` |
|
|
233
|
+
| stage | `https://auth.stage.optima.onl` | `https://api.stage.optima.onl` |
|
|
234
|
+
| prod | `https://auth.optima.onl` | `https://api.optima.onl` |
|
|
216
235
|
|
|
217
|
-
|
|
218
|
-
- API 地址:
|
|
219
|
-
- Auth: `https://auth.optima.chat`
|
|
220
|
-
- Commerce: `https://api.optima.chat`
|
|
221
|
-
- **不能用于** production 或 stage 环境
|
|
236
|
+
⚠️ **注意**:Prod 环境创建的账户会出现在生产系统中,请谨慎使用。
|
|
222
237
|
|
|
223
238
|
## 💡 最佳实践
|
|
224
239
|
|
|
@@ -241,8 +256,8 @@ OPTIMA_TOKEN=$(cat "$TOKEN_FILE")
|
|
|
241
256
|
export TOKEN_FILE=/tmp/optima-test-token-1763997011780.txt
|
|
242
257
|
|
|
243
258
|
# 后续使用
|
|
244
|
-
OPTIMA_TOKEN=$(cat $TOKEN_FILE) OPTIMA_ENV=
|
|
245
|
-
OPTIMA_TOKEN=$(cat $TOKEN_FILE) OPTIMA_ENV=
|
|
259
|
+
OPTIMA_TOKEN=$(cat $TOKEN_FILE) OPTIMA_ENV=ci commerce product list
|
|
260
|
+
OPTIMA_TOKEN=$(cat $TOKEN_FILE) OPTIMA_ENV=ci commerce order list
|
|
246
261
|
```
|
|
247
262
|
|
|
248
263
|
### 3. 自定义账户信息(可选)
|
|
@@ -275,7 +290,7 @@ rm /tmp/optima-test-token-*.txt
|
|
|
275
290
|
|
|
276
291
|
**解决方案**:
|
|
277
292
|
- Token 已过期(15分钟),重新生成
|
|
278
|
-
- 环境变量设置错误,检查 `OPTIMA_ENV=
|
|
293
|
+
- 环境变量设置错误,检查 `OPTIMA_ENV=ci`
|
|
279
294
|
- Token 文件路径错误,检查文件是否存在
|
|
280
295
|
|
|
281
296
|
### 问题 2:Merchant profile 未设置
|
|
@@ -24,7 +24,7 @@ interface MerchantSetupResponse {
|
|
|
24
24
|
user_id: string;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
type Environment = '
|
|
27
|
+
type Environment = 'ci' | 'stage' | 'prod';
|
|
28
28
|
|
|
29
29
|
interface EnvironmentConfig {
|
|
30
30
|
authUrl: string;
|
|
@@ -34,17 +34,23 @@ interface EnvironmentConfig {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
const ENV_CONFIG: Record<Environment, EnvironmentConfig> = {
|
|
37
|
-
|
|
37
|
+
ci: {
|
|
38
38
|
authUrl: 'https://auth.optima.chat',
|
|
39
39
|
apiUrl: 'https://api.optima.chat',
|
|
40
40
|
clientId: 'dev-skill-cli-he7fjmsp',
|
|
41
|
-
envName: '
|
|
41
|
+
envName: 'ci'
|
|
42
42
|
},
|
|
43
|
-
|
|
44
|
-
authUrl: 'https://auth.optima.
|
|
45
|
-
apiUrl: 'https://api.optima.
|
|
46
|
-
clientId: '
|
|
47
|
-
envName: '
|
|
43
|
+
stage: {
|
|
44
|
+
authUrl: 'https://auth.stage.optima.onl',
|
|
45
|
+
apiUrl: 'https://api.stage.optima.onl',
|
|
46
|
+
clientId: 'commerce-cli-stage-ihbbwplz',
|
|
47
|
+
envName: 'stage'
|
|
48
|
+
},
|
|
49
|
+
prod: {
|
|
50
|
+
authUrl: 'https://auth.optima.onl',
|
|
51
|
+
apiUrl: 'https://api.optima.onl',
|
|
52
|
+
clientId: 'commerce-cli-ecs-pro-i2r5of1h',
|
|
53
|
+
envName: 'prod'
|
|
48
54
|
}
|
|
49
55
|
};
|
|
50
56
|
|
|
@@ -166,7 +172,7 @@ async function main() {
|
|
|
166
172
|
let businessName = defaultBusinessName;
|
|
167
173
|
let phone: string | undefined;
|
|
168
174
|
let address: string | undefined;
|
|
169
|
-
let environment: Environment = '
|
|
175
|
+
let environment: Environment = 'ci';
|
|
170
176
|
|
|
171
177
|
// 解析命令行参数
|
|
172
178
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -184,15 +190,15 @@ async function main() {
|
|
|
184
190
|
address = args[++i];
|
|
185
191
|
} else if (arg === '--env' && args[i + 1]) {
|
|
186
192
|
const envArg = args[++i];
|
|
187
|
-
if (envArg === '
|
|
193
|
+
if (envArg === 'ci' || envArg === 'stage' || envArg === 'prod') {
|
|
188
194
|
environment = envArg;
|
|
189
195
|
} else {
|
|
190
|
-
console.error(`❌ Invalid environment: ${envArg}. Must be '
|
|
196
|
+
console.error(`❌ Invalid environment: ${envArg}. Must be 'ci', 'stage', or 'prod'.`);
|
|
191
197
|
process.exit(1);
|
|
192
198
|
}
|
|
193
199
|
} else if (arg === '--help' || arg === '-h') {
|
|
194
200
|
console.log(`
|
|
195
|
-
Usage: generate-test-token [options]
|
|
201
|
+
Usage: optima-generate-test-token [options]
|
|
196
202
|
|
|
197
203
|
Options:
|
|
198
204
|
--email <email> User email (default: auto-generated)
|
|
@@ -200,14 +206,19 @@ Options:
|
|
|
200
206
|
--business-name <name> Merchant business name (default: auto-generated)
|
|
201
207
|
--phone <phone> Merchant phone number (optional)
|
|
202
208
|
--address <address> Merchant address (optional)
|
|
203
|
-
--env <environment> Environment:
|
|
209
|
+
--env <environment> Environment: ci (default), stage, or prod
|
|
204
210
|
--help, -h Show this help message
|
|
205
211
|
|
|
212
|
+
Environments:
|
|
213
|
+
ci CI 环境 (auth.optima.chat, api.optima.chat)
|
|
214
|
+
stage Stage 环境 (auth.stage.optima.onl, api.stage.optima.onl)
|
|
215
|
+
prod Prod 环境 (auth.optima.onl, api.optima.onl)
|
|
216
|
+
|
|
206
217
|
Example:
|
|
207
|
-
generate-test-token
|
|
208
|
-
generate-test-token --env
|
|
209
|
-
generate-test-token --
|
|
210
|
-
generate-test-token --
|
|
218
|
+
optima-generate-test-token
|
|
219
|
+
optima-generate-test-token --env stage
|
|
220
|
+
optima-generate-test-token --env prod
|
|
221
|
+
optima-generate-test-token --business-name "My Test Shop" --env stage
|
|
211
222
|
`);
|
|
212
223
|
process.exit(0);
|
|
213
224
|
}
|
|
@@ -38,17 +38,23 @@ const fs = __importStar(require("fs"));
|
|
|
38
38
|
const os = __importStar(require("os"));
|
|
39
39
|
const path = __importStar(require("path"));
|
|
40
40
|
const ENV_CONFIG = {
|
|
41
|
-
|
|
41
|
+
ci: {
|
|
42
42
|
authUrl: 'https://auth.optima.chat',
|
|
43
43
|
apiUrl: 'https://api.optima.chat',
|
|
44
44
|
clientId: 'dev-skill-cli-he7fjmsp',
|
|
45
|
-
envName: '
|
|
45
|
+
envName: 'ci'
|
|
46
46
|
},
|
|
47
|
-
|
|
48
|
-
authUrl: 'https://auth.optima.
|
|
49
|
-
apiUrl: 'https://api.optima.
|
|
50
|
-
clientId: '
|
|
51
|
-
envName: '
|
|
47
|
+
stage: {
|
|
48
|
+
authUrl: 'https://auth.stage.optima.onl',
|
|
49
|
+
apiUrl: 'https://api.stage.optima.onl',
|
|
50
|
+
clientId: 'commerce-cli-stage-ihbbwplz',
|
|
51
|
+
envName: 'stage'
|
|
52
|
+
},
|
|
53
|
+
prod: {
|
|
54
|
+
authUrl: 'https://auth.optima.onl',
|
|
55
|
+
apiUrl: 'https://api.optima.onl',
|
|
56
|
+
clientId: 'commerce-cli-ecs-pro-i2r5of1h',
|
|
57
|
+
envName: 'prod'
|
|
52
58
|
}
|
|
53
59
|
};
|
|
54
60
|
async function httpRequest(url, options = {}) {
|
|
@@ -149,7 +155,7 @@ async function main() {
|
|
|
149
155
|
let businessName = defaultBusinessName;
|
|
150
156
|
let phone;
|
|
151
157
|
let address;
|
|
152
|
-
let environment = '
|
|
158
|
+
let environment = 'ci';
|
|
153
159
|
// 解析命令行参数
|
|
154
160
|
for (let i = 0; i < args.length; i++) {
|
|
155
161
|
const arg = args[i];
|
|
@@ -170,17 +176,17 @@ async function main() {
|
|
|
170
176
|
}
|
|
171
177
|
else if (arg === '--env' && args[i + 1]) {
|
|
172
178
|
const envArg = args[++i];
|
|
173
|
-
if (envArg === '
|
|
179
|
+
if (envArg === 'ci' || envArg === 'stage' || envArg === 'prod') {
|
|
174
180
|
environment = envArg;
|
|
175
181
|
}
|
|
176
182
|
else {
|
|
177
|
-
console.error(`❌ Invalid environment: ${envArg}. Must be '
|
|
183
|
+
console.error(`❌ Invalid environment: ${envArg}. Must be 'ci', 'stage', or 'prod'.`);
|
|
178
184
|
process.exit(1);
|
|
179
185
|
}
|
|
180
186
|
}
|
|
181
187
|
else if (arg === '--help' || arg === '-h') {
|
|
182
188
|
console.log(`
|
|
183
|
-
Usage: generate-test-token [options]
|
|
189
|
+
Usage: optima-generate-test-token [options]
|
|
184
190
|
|
|
185
191
|
Options:
|
|
186
192
|
--email <email> User email (default: auto-generated)
|
|
@@ -188,14 +194,19 @@ Options:
|
|
|
188
194
|
--business-name <name> Merchant business name (default: auto-generated)
|
|
189
195
|
--phone <phone> Merchant phone number (optional)
|
|
190
196
|
--address <address> Merchant address (optional)
|
|
191
|
-
--env <environment> Environment:
|
|
197
|
+
--env <environment> Environment: ci (default), stage, or prod
|
|
192
198
|
--help, -h Show this help message
|
|
193
199
|
|
|
200
|
+
Environments:
|
|
201
|
+
ci CI 环境 (auth.optima.chat, api.optima.chat)
|
|
202
|
+
stage Stage 环境 (auth.stage.optima.onl, api.stage.optima.onl)
|
|
203
|
+
prod Prod 环境 (auth.optima.onl, api.optima.onl)
|
|
204
|
+
|
|
194
205
|
Example:
|
|
195
|
-
generate-test-token
|
|
196
|
-
generate-test-token --env
|
|
197
|
-
generate-test-token --
|
|
198
|
-
generate-test-token --
|
|
206
|
+
optima-generate-test-token
|
|
207
|
+
optima-generate-test-token --env stage
|
|
208
|
+
optima-generate-test-token --env prod
|
|
209
|
+
optima-generate-test-token --business-name "My Test Shop" --env stage
|
|
199
210
|
`);
|
|
200
211
|
process.exit(0);
|
|
201
212
|
}
|