-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsetup.mjs
More file actions
387 lines (333 loc) ยท 18.4 KB
/
Copy pathsetup.mjs
File metadata and controls
387 lines (333 loc) ยท 18.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
/**
* ็ตๅ้พ่พ โ ้ฆๆฌก้
็ฝฎๅๅฏผ v2.0
* ็จๆณ๏ผnode setup.mjs
*
* ๅผๅฏผ้กบๅบ๏ผไปไธๅกๅฐๆๆฏ๏ผ็ฑๆต
ๅ
ฅๆทฑ๏ผ๏ผ
* Step 1 โ ไธๅกๆจกๅผ๏ผๅฝๅ
/ ่ทจๅข / ไธค่
๏ผ
* Step 2 โ ้ๅฎๆธ ้๏ผไพๆฎ Step 1 ่ฟๆปค้้กน๏ผ
* Step 3 โ ๅๅ็ฑปๅ๏ผๅฝฑๅๆๆก/็ฉๆต/SEO ็ญ็ฅ๏ผ
* Step 4 โ ไผๅ
่งฃๅณไปไน๏ผๅณๅฎ Cron ๅฏ็จ้กบๅบ + Dashboard ๅ
ฅๅฃ๏ผ
* Step 5 โ ๅฎกๆน่งๅ๏ผๅชไบ้ซ้ฃ้ฉๆไฝ้่ฆไบบๅทฅ็กฎ่ฎค + Telegram ้็ฅ้
็ฝฎ๏ผ
* Step 6 โ ้
็ฝฎ API๏ผไป
้
็ฝฎ Step 2 ้ไธญ็ๆธ ้๏ผ
*/
import { writeFileSync, readFileSync, existsSync } from 'fs';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { createInterface } from 'readline';
import { createServer } from 'http';
import { exec } from 'child_process';
const __dirname = dirname(fileURLToPath(import.meta.url));
const CONFIG_PATH = join(__dirname, 'config.json');
const CALLBACK_PORT = 3457;
const CALLBACK_PATH = '/callback';
const SHOPIFY_SCOPES = [
'read_orders', 'write_orders',
'read_products', 'write_products',
'read_inventory', 'write_inventory',
'read_customers',
'read_price_rules', 'write_price_rules',
'read_discounts', 'write_discounts'
].join(',');
const rl = createInterface({ input: process.stdin, output: process.stdout });
const ask = (q) => new Promise(r => rl.question(q, r));
function hr() { console.log('\n' + 'โ'.repeat(50) + '\n'); }
function openBrowser(url) {
const cmd = process.platform === 'win32' ? `start "" "${url}"`
: process.platform === 'darwin' ? `open "${url}"`
: `xdg-open "${url}"`;
exec(cmd);
}
// โโโ ๅ้ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function singleSelect(prompt, options) {
console.log(prompt);
options.forEach((o, i) => console.log(` ${i + 1}. ${o.label}`));
while (true) {
const ans = (await ask('\n่ฏท่พๅ
ฅ็ผๅท๏ผ')).trim();
const idx = parseInt(ans) - 1;
if (idx >= 0 && idx < options.length) return options[idx];
console.log(' โ ๆ ๆ้้กน๏ผ่ฏท้ๆฐ่พๅ
ฅ');
}
}
// โโโ ๅค้ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function multiSelect(prompt, options, minSelect = 1) {
console.log(prompt);
options.forEach((o, i) => console.log(` ${i + 1}. ${o.label}`));
console.log('\n ๅค้็จ้ๅทๅ้๏ผๅฆ๏ผ1,3');
while (true) {
const ans = (await ask('่ฏท่พๅ
ฅ็ผๅท๏ผ')).trim();
const indices = ans.split(',').map(s => parseInt(s.trim()) - 1);
const valid = indices.filter(i => i >= 0 && i < options.length);
const unique = [...new Set(valid)];
if (unique.length >= minSelect) return unique.map(i => options[i]);
console.log(` โ ่ฏท่ณๅฐ้ๆฉ ${minSelect} ้กน`);
}
}
// โโโ Shopify OAuth โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function shopifyOAuth(clientId, clientSecret, shopDomain) {
return new Promise((resolve, reject) => {
const server = createServer(async (req, res) => {
const url = new URL(req.url, `http://localhost:${CALLBACK_PORT}`);
if (url.pathname !== CALLBACK_PATH) { res.end('Not found'); return; }
const code = url.searchParams.get('code');
const shop = url.searchParams.get('shop');
const state = url.searchParams.get('state');
if (!code) { res.writeHead(400); res.end('Missing code'); return; }
if (state !== 'ecomclaw-setup') { res.writeHead(400); res.end('Invalid state'); return; }
try {
const tokenRes = await fetch(`https://${shop}/admin/oauth/access_token`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ client_id: clientId, client_secret: clientSecret, code })
});
const tokenData = await tokenRes.json();
if (!tokenData.access_token) throw new Error(JSON.stringify(tokenData));
res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
res.end(`<html><body style="font-family:sans-serif;text-align:center;padding:60px;background:#0f0f17;color:#fff">
<div style="font-size:60px">๐ฆ</div>
<h2 style="color:#4ade80;margin:16px 0">ๆๆๆๅ๏ผ</h2>
<p style="color:#888">ๅฏไปฅๅ
ณ้ญๆญค้กต้ขไบใ</p>
</body></html>`);
server.close();
resolve(tokenData.access_token);
} catch (err) {
res.writeHead(500); res.end(`Error: ${err.message}`);
server.close();
reject(err);
}
});
server.listen(CALLBACK_PORT, () => {
console.log(`\n โ
ๆฌๅฐๅ่ฐๆๅกๅจๅทฒๅฏๅจ๏ผport ${CALLBACK_PORT}๏ผ`);
const redirectUri = `http://localhost:${CALLBACK_PORT}${CALLBACK_PATH}`;
const authUrl = `https://${shopDomain}/admin/oauth/authorize?client_id=${clientId}&scope=${SHOPIFY_SCOPES}&redirect_uri=${encodeURIComponent(redirectUri)}&state=ecomclaw-setup&grant_options[]=offline`;
console.log('\n ๐ ๆญฃๅจๆๅผๆต่งๅจๅฎๆๆๆ...');
console.log(' ๅฆๆช่ชๅจๆๅผ๏ผ่ฏทๆๅจ่ฎฟ้ฎ๏ผ');
console.log(` ${authUrl}\n`);
openBrowser(authUrl);
});
server.on('error', reject);
setTimeout(() => { server.close(); reject(new Error('ๆๆ่ถ
ๆถ๏ผ2ๅ้๏ผ๏ผ่ฏท้่ฏ')); }, 120000);
});
}
// โโโ ไธปๆต็จ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
async function main() {
console.log('\n๐ฆ ็ตๅ้พ่พ โ ้ฆๆฌก้
็ฝฎๅๅฏผ\n');
console.log(' ๆไผ้ฎไฝ 6 ไธช้ฎ้ข๏ผๅธฎไฝ ๅฎๅถๆ้ๅ็้
็ฝฎใ');
console.log(' ๆดไธช่ฟ็จ็บฆ้ 5 ๅ้ใ\n');
// ๅทฒๆ config ๆถ่ฏข้ฎๆฏๅฆ้ๆฐ้
็ฝฎ
if (existsSync(CONFIG_PATH)) {
const ans = (await ask('โ ๏ธ ๆฃๆตๅฐๅทฒๆ config.json๏ผๆฏๅฆ้ๆฐ้
็ฝฎ๏ผ(y/N) ')).trim();
if (ans.toLowerCase() !== 'y') {
console.log('\n่ทณ่ฟ๏ผ้ช่ฏ็ฐๆ้
็ฝฎ...');
rl.close();
const { testConnection } = await import('./connectors/shopify.js');
const result = await testConnection();
console.log(result.ok ? `โ
่ฟๆฅๆญฃๅธธ๏ผๅบ้บ๏ผ${result.shop_name}` : `โ ่ฟๆฅๅคฑ่ดฅ๏ผ${result.error}`);
return;
}
}
const config = {};
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Step 1 โ ไธๅกๆจกๅผ
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
hr();
console.log('ใStep 1 / 6ใไธๅกๆจกๅผ\n');
const modeChoice = await singleSelect('ๆจ็ไธป่ฆไธๅกๆนๅๆฏ๏ผ', [
{ label: 'ๅฝๅ
็ตๅ โ ้ขๅๅฝๅ
ไนฐๅฎถ๏ผไบบๆฐๅธ็ป็ฎ', value: 'domestic' },
{ label: '่ทจๅขๅบๆตท โ ้ขๅๆตทๅคไนฐๅฎถ๏ผๅคๅธ็ป็ฎ', value: 'crossborder' },
{ label: 'ๅฝๅ
+่ทจๅข โ ไธค่
้ฝๆ', value: 'both' },
]);
config.business = { mode: modeChoice.value };
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Step 2 โ ้ๅฎๆธ ้๏ผไพไธๅกๆจกๅผ่ฟๆปค้้กน๏ผ
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
hr();
console.log('ใStep 2 / 6ใ้ๅฎๆธ ้\n');
// ๆไธๅกๆจกๅผๅฑ็คบไธๅๆธ ้
const allChannels = [
{ label: 'Shopify โ ็ฌ็ซ็ซ๏ผๆฏๆๅฝๅ
+่ทจๅข', value: 'shopify', modes: ['domestic', 'crossborder', 'both'] },
{ label: 'WooCommerce โ WordPress ็ฌ็ซ็ซ', value: 'woocommerce', modes: ['domestic', 'crossborder', 'both'] },
{ label: 'ๆ่ต โ ๅฝๅ
็งๅ/ๅพฎไฟกๅฐ็จๅบ', value: 'youzan', modes: ['domestic', 'both'] },
].filter(c => c.modes.includes(config.business.mode));
const channelChoices = await multiSelect(
'ๆจ็ฎๅๅจๅชไบๅนณๅฐ้ๅฎ๏ผ๏ผ่ณๅฐ้ 1 ไธช๏ผ',
allChannels
);
config.business.channels = channelChoices.map(c => c.value);
// ่ฎฐๅฝไธปๅนณๅฐ๏ผ็ฌฌไธไธช้็๏ผ
config.business.primaryChannel = config.business.channels[0];
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Step 3 โ ๅๅ็ฑปๅ
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
hr();
console.log('ใStep 3 / 6ใๅๅ็ฑปๅ\n');
console.log(' ๏ผๅฝฑๅๆๆก้ฃๆ ผใ็ฉๆต้
็ฝฎใSEO ๅ
ณ้ฎ่ฏ็ญ็ฅ๏ผ\n');
const categoryChoices = await multiSelect(
'ๆจไธป่ฆๅไปไน็ฑปๅ็ๅๅ๏ผ๏ผๅฏๅค้๏ผ',
[
{ label: 'ๆ่ฃ
/ ้ๅธฝ / ้
้ฅฐ', value: 'fashion' },
{ label: '็พๅฆ / ๆค่ค / ไธชๆค', value: 'beauty' },
{ label: 'ๆฐ็ / ๅฎถ็ต / ้
ไปถ', value: 'electronics' },
{ label: 'ๅฎถๅฑ
/ ๅฎถ่ฃ
/ ๅฎถ็บบ', value: 'home' },
{ label: '้ฃๅ / ไฟๅฅ / ่ฅๅ
ปๅ', value: 'food' },
{ label: 'ๆทๅค / ่ฟๅจ / ๅฅ่บซ', value: 'sports' },
{ label: 'ๆฏๅฉด / ็ฉๅ
ท / ๅฟ็ซฅ', value: 'baby' },
{ label: 'ๅ
ถไป', value: 'other' },
]
);
config.business.categories = categoryChoices.map(c => c.value);
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Step 4 โ ไผๅ
่งฃๅณไปไน
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
hr();
console.log('ใStep 4 / 6ใไผๅ
็ฎๆ \n');
console.log(' ๏ผๅณๅฎๅฏๅจๅ Dashboard ๅ
ฅๅฃ + ๅชไบ Cron ไผๅ
ๆฟๆดป๏ผ\n');
const priorityChoice = await singleSelect(
'ๆจๆๆณๅ
่งฃๅณ็้ฎ้ขๆฏ๏ผ',
[
{ label: '๐ ้ๅ้ท่พพ โ ่ถๅฟๆๆใๅฉๆถฆๆต็ฎใ็ซๅ็ๆงใ็ๆฌพๅ็ฐ', value: 'selection' },
{ label: '๐ช ๅบ้บ่ฟ่ฅ โ ๅๅไธๆฐใ่ฎขๅๅค็ใๅบๅญ่ฐๅบฆใไฟ้ๅฎไปท', value: 'store' },
{ label: '๐ฃ ๅ
ๅฎน็คพๅช โ ่ฏ่ฎบ่ฟ่ฅใFAQๆฒๆทใๅฐ็บขไนฆ/ๆ้ณ/TikTokๆๆก', value: 'community' },
{ label: '๐ ๆฐๆฎๅ่ฐ โ ๆฅๆฅๅจๆฅๆๆฅใ็ป่ฅๆดๅฏใ้ฎ้ข่ฏๆญใๆน่ฟๅปบ่ฎฎ', value: 'analytics' },
]
);
config.business.priority = priorityChoice.value;
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Step 5 โ ๅฎกๆน่งๅ
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
hr();
console.log('ใStep 5 / 6ใๅฎกๆน่งๅ\n');
console.log(' ้ซ้ฃ้ฉๆไฝๆง่กๅ๏ผ็ณป็ปไผๅ Telegram ๆถๆฏ่ฎฉๆจ็นๆ้ฎ็กฎ่ฎคใ\n');
// 5a โ ๅชไบๆไฝ้่ฆๅฎกๆน
const approvalChoices = await multiSelect(
'ไปฅไธๆไฝ๏ผๅชไบ้่ฆไบบๅทฅๅฎกๆน๏ผ๏ผๅฏๅค้๏ผ็ดๆฅๅ่ฝฆ้้ป่ฎค๏ผ\n ้ป่ฎคๅทฒๅพ้๏ผ1,2,3,7',
[
{ label: '้ๆฌพ ๐ด ้ซ้ฃ้ฉ๏ผๆจ่ๅฟ
้๏ผ', value: 'refund' },
{ label: 'ๅๆถ่ฎขๅ ๐ด ้ซ้ฃ้ฉ๏ผๆจ่ๅฟ
้๏ผ', value: 'cancel' },
{ label: 'ๆน้ๆนไปท ๐ด ้ซ้ฃ้ฉ๏ผๆจ่ๅฟ
้๏ผ', value: 'bulk_price' },
{ label: 'ๅ่ดง ๐ก ไธญ้ฃ้ฉ', value: 'fulfill' },
{ label: '่กฅๅ ๐ข ไฝ้ฃ้ฉ', value: 'resend' },
{ label: 'ๅๅปบๆๆฃ็ ๐ก ไธญ้ฃ้ฉ', value: 'discount_create' },
{ label: 'ๅ ้คๆๆฃ็ ๐ด ้ซ้ฃ้ฉ๏ผๆจ่ๅฟ
้๏ผ', value: 'discount_delete' },
]
);
// 5b โ ้ๆฌพ้้ข้ๅผ
console.log('');
const thresholdRaw = (await ask(' ้ๆฌพๅฎกๆน้้ข้ๅผ๏ผไฝไบๆญค้้ขไธ้ๅฎกๆน๏ผๅกซ 0 ๅๅ
จ้จๅฎกๆน๏ผ๏ผ')).trim();
const refundThreshold = parseFloat(thresholdRaw) || 0;
// 5c โ Telegram Chat ID
console.log('');
const chatIdRaw = (await ask(' Telegram Chat ID๏ผๅฎกๆน้็ฅๅๅพๆญค ID๏ผ้ป่ฎค 2074812988๏ผ๏ผ')).trim();
const chatId = chatIdRaw || '2074812988';
// 5d โ ๅบๅญ้ข่ญฆ้ๅผ
const stockRaw = (await ask(' ๅบๅญ้ข่ญฆ้ๅผ๏ผไฝไบๆญคๆฐ้่งฆๅๅ่ญฆ๏ผ้ป่ฎค 10๏ผ๏ผ')).trim();
const lowStockThreshold = parseInt(stockRaw) || 10;
config.approval = {
require: approvalChoices.map(c => c.value),
refund_threshold: refundThreshold,
telegram_chat_id: chatId,
};
config.notifications = { telegram_chat_id: chatId };
config.alerts = {
low_stock_threshold: lowStockThreshold,
order_poll_interval_minutes: 15,
};
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// Step 6 โ ้
็ฝฎ API๏ผไป
้
็ฝฎ Step 2 ้ไธญ็ๆธ ้๏ผ
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
hr();
console.log('ใStep 6 / 6ใ้
็ฝฎ API\n');
console.log(` ๆจ้ๆฉไบไปฅไธๆธ ้๏ผ${config.business.channels.join('ใ')}`);
console.log(' ไพๆฌกๅฎๆๅๅนณๅฐๆๆใ\n');
// โโ Shopify โโ
if (config.business.channels.includes('shopify')) {
console.log('โโ Shopify ๆๆ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
console.log('ๅ็ฝฎๆญฅ้ชค๏ผๅจ dev.shopify.com ็ App ่ฎพ็ฝฎ้๏ผ');
console.log(`ๆไปฅไธๅฐๅๅ ๅ
ฅใๅ
่ฎธ็้ๅฎๅ URLใ๏ผ`);
console.log(` http://localhost:${CALLBACK_PORT}${CALLBACK_PATH}\n`);
const domain = (await ask(' ๅบ้บๅๅ๏ผๅฆ my-shop.myshopify.com๏ผ๏ผ')).trim();
const clientId = (await ask(' Client ID๏ผ')).trim();
const secret = (await ask(' Client Secret๏ผ')).trim();
console.log('\n ๆญฃๅจๅฏๅจ OAuth ๆๆๆต็จ...');
const accessToken = await shopifyOAuth(clientId, secret, domain);
console.log(' โ
Shopify ๆๆๆๅ\n');
config.shopify = {
shop_domain: domain,
access_token: accessToken,
client_id: clientId,
client_secret: secret,
api_version: '2026-01',
};
}
// โโ WooCommerce โโ
if (config.business.channels.includes('woocommerce')) {
console.log('\nโโ WooCommerce ๆๆ โโโโโโโโโโโโโโโโโโโโโโโโโ');
console.log(' ๅจ WordPress ๅๅฐ โ WooCommerce โ ่ฎพ็ฝฎ โ ้ซ็บง โ REST API');
console.log(' ็ๆไธไธชใ่ฏปๅใๆ้็ API Key\n');
const wcUrl = (await ask(' ๅบ้บๅฐๅ๏ผๅฆ https://mystore.com๏ผ๏ผ')).trim().replace(/\/$/, '');
const wcKey = (await ask(' Consumer Key๏ผck_...๏ผ๏ผ')).trim();
const wcSecret = (await ask(' Consumer Secret๏ผcs_...๏ผ๏ผ')).trim();
config.woocommerce = {
store_url: wcUrl,
consumer_key: wcKey,
consumer_secret: wcSecret,
api_version: 'wc/v3',
};
console.log(' โ
WooCommerce ้
็ฝฎๅทฒไฟๅญ\n');
}
// โโ ๆ่ต โโ
if (config.business.channels.includes('youzan')) {
console.log('\nโโ ๆ่ตๆๆ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ');
console.log(' ๆ่ตๅผๆพๅนณๅฐ โ ๅบ็จ็ฎก็ โ ่ทๅ Access Token\n');
const yzToken = (await ask(' Access Token๏ผ')).trim();
const yzKdtId = (await ask(' ๅบ้บ KDT ID๏ผๆ่ตๅๅฐ โ ๅบ้บ่ฎพ็ฝฎ๏ผ๏ผ')).trim();
config.youzan = {
access_token: yzToken,
kdt_id: yzKdtId,
};
console.log(' โ
ๆ่ต้
็ฝฎๅทฒไฟๅญ\n');
}
config.report = {
daily_report_hour: 8,
timezone: 'Asia/Shanghai',
};
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
// ๅๅ
ฅ config.json
// โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
writeFileSync(CONFIG_PATH, JSON.stringify(config, null, 2), 'utf8');
hr();
console.log('๐ ้
็ฝฎๅฎๆ๏ผ\n');
console.log(' ไธๅกๆจกๅผ๏ผ' + { domestic: 'ๅฝๅ
็ตๅ', crossborder: '่ทจๅขๅบๆตท', both: 'ๅฝๅ
+่ทจๅข' }[config.business.mode]);
console.log(' ้ๅฎๆธ ้๏ผ' + config.business.channels.join('ใ'));
console.log(' ๅๅ็ฑปๅ๏ผ' + config.business.categories.join('ใ'));
console.log(' ไผๅ
็ฎๆ ๏ผ' + { selection:'๐ ้ๅ้ท่พพ', store:'๐ช ๅบ้บ่ฟ่ฅ', community:'๐ฃ ๅ
ๅฎน็คพๅช', analytics:'๐ ๆฐๆฎๅ่ฐ' }[config.business.priority]);
console.log(' ๅฎกๆนๆไฝ๏ผ' + (config.approval.require.length ? config.approval.require.join('ใ') : 'ๅ
จ้จไธ้่ฆ'));
console.log(' ้็ฅ ID๏ผ' + chatId);
console.log(' ๅบๅญ้ข่ญฆ๏ผ< ' + lowStockThreshold);
// ้ช่ฏไธปๅนณๅฐ่ฟๆฅ
if (config.business.channels.includes('shopify')) {
console.log('\n ๆญฃๅจ้ช่ฏ Shopify ่ฟๆฅ...');
const { testConnection } = await import('./connectors/shopify.js');
const result = await testConnection();
if (result.ok) {
console.log(` โ
Shopify ่ฟๆฅๆญฃๅธธ๏ผ${result.shop_name}๏ผ${result.currency}๏ผ`);
} else {
console.log(` โ ๏ธ Shopify ่ฟๆฅ้ช่ฏๅคฑ่ดฅ๏ผ${result.error}`);
console.log(' ๅฏ็จๅ่ฟ่ก node scripts/connect-test.mjs ้่ฏ');
}
}
console.log('\n ไธไธๆญฅ๏ผ');
const nextStepMap = {
selection: 'node modules/selection/index.mjs --help',
store: 'node modules/store/index.mjs --help',
community: 'node modules/community/index.mjs --help',
analytics: 'node scripts/daily-report.mjs',
};
console.log(` ${nextStepMap[config.business.priority]}`);
console.log('\n Dashboard๏ผnode scripts/dashboard-server.mjs โ http://localhost:3458\n');
rl.close();
}
main().catch(err => {
console.error('\nโ ๅๅงๅๅคฑ่ดฅ๏ผ', err.message);
rl.close();
process.exit(1);
});