@optima-chat/bi-cli 0.3.3 → 0.3.5
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/dist/commands/analytics.d.ts.map +1 -1
- package/dist/commands/analytics.js +89 -14
- package/dist/commands/analytics.js.map +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +14 -6
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/product.d.ts.map +1 -1
- package/dist/commands/product.js +77 -13
- package/dist/commands/product.js.map +1 -1
- package/dist/commands/sales.d.ts.map +1 -1
- package/dist/commands/sales.js +24 -4
- package/dist/commands/sales.js.map +1 -1
- package/dist/commands/traffic.d.ts +3 -0
- package/dist/commands/traffic.d.ts.map +1 -0
- package/dist/commands/traffic.js +331 -0
- package/dist/commands/traffic.js.map +1 -0
- package/dist/commands/trends.d.ts.map +1 -1
- package/dist/commands/trends.js +80 -13
- package/dist/commands/trends.js.map +1 -1
- package/dist/index.js +22 -9
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/commands/analytics.ts +98 -17
- package/src/commands/auth.ts +18 -6
- package/src/commands/product.ts +87 -13
- package/src/commands/sales.ts +28 -4
- package/src/commands/traffic.ts +454 -0
- package/src/commands/trends.ts +90 -13
- package/src/index.ts +25 -9
|
@@ -0,0 +1,454 @@
|
|
|
1
|
+
import { Command } from 'commander';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { getConfig } from '../config/index.js';
|
|
4
|
+
import { outputJson, outputPretty, error, OutputFormat } from '../utils/output.js';
|
|
5
|
+
|
|
6
|
+
interface TrafficOverview {
|
|
7
|
+
period: {
|
|
8
|
+
start: string;
|
|
9
|
+
end: string;
|
|
10
|
+
days: number;
|
|
11
|
+
};
|
|
12
|
+
summary: {
|
|
13
|
+
page_views: number;
|
|
14
|
+
unique_visitors: number;
|
|
15
|
+
sessions: number;
|
|
16
|
+
avg_session_duration: number;
|
|
17
|
+
bounce_rate: number;
|
|
18
|
+
};
|
|
19
|
+
comparison: {
|
|
20
|
+
page_views_change: number;
|
|
21
|
+
unique_visitors_change: number;
|
|
22
|
+
sessions_change: number;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface TrafficSource {
|
|
27
|
+
source: string;
|
|
28
|
+
medium: string;
|
|
29
|
+
visitors: number;
|
|
30
|
+
page_views: number;
|
|
31
|
+
percentage: number;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface FunnelStep {
|
|
35
|
+
step: string;
|
|
36
|
+
count: number;
|
|
37
|
+
rate: number;
|
|
38
|
+
conversion: number;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
interface SearchItem {
|
|
42
|
+
query: string;
|
|
43
|
+
count: number;
|
|
44
|
+
unique_searchers: number;
|
|
45
|
+
avg_results: number;
|
|
46
|
+
click_rate: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface PageItem {
|
|
50
|
+
path: string;
|
|
51
|
+
page_views: number;
|
|
52
|
+
unique_visitors: number;
|
|
53
|
+
sessions: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function formatPercent(value: number): string {
|
|
57
|
+
return `${(value * 100).toFixed(1)}%`;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function formatChange(value: number): string {
|
|
61
|
+
const sign = value >= 0 ? '+' : '';
|
|
62
|
+
return `${sign}${(value * 100).toFixed(1)}%`;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function formatDuration(seconds: number): string {
|
|
66
|
+
const mins = Math.floor(seconds / 60);
|
|
67
|
+
const secs = seconds % 60;
|
|
68
|
+
return mins > 0 ? `${mins}m ${secs}s` : `${secs}s`;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function createTrafficCommand(): Command {
|
|
72
|
+
const traffic = new Command('traffic').description(
|
|
73
|
+
`Traffic analytics.
|
|
74
|
+
|
|
75
|
+
Analyze website visits, traffic sources, conversion funnels, search keywords.`
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
// traffic overview
|
|
79
|
+
traffic
|
|
80
|
+
.command('overview')
|
|
81
|
+
.description(
|
|
82
|
+
`Traffic overview.
|
|
83
|
+
|
|
84
|
+
Get page views, unique visitors, sessions, and comparison with previous period.
|
|
85
|
+
|
|
86
|
+
Returns JSON:
|
|
87
|
+
{
|
|
88
|
+
"period": { "start": "2024-01-01", "end": "2024-01-30", "days": 30 },
|
|
89
|
+
"summary": {
|
|
90
|
+
"page_views": 10000,
|
|
91
|
+
"unique_visitors": 3000,
|
|
92
|
+
"sessions": 5000,
|
|
93
|
+
"avg_session_duration": 180, // seconds
|
|
94
|
+
"bounce_rate": 0.35 // 35%
|
|
95
|
+
},
|
|
96
|
+
"comparison": {
|
|
97
|
+
"page_views_change": 0.15, // +15%
|
|
98
|
+
"unique_visitors_change": 0.10
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
Examples:
|
|
103
|
+
bi-cli traffic overview # Last 30 days, all pages
|
|
104
|
+
bi-cli traffic overview --days 7 # Last 7 days
|
|
105
|
+
bi-cli traffic overview --product <uuid> # Filter by product`
|
|
106
|
+
)
|
|
107
|
+
.option('--days <number>', 'Number of days (range: 1-365, default: 30)', '30')
|
|
108
|
+
.option('--product <id>', 'Filter by product ID (UUID format)')
|
|
109
|
+
.option('--pretty', 'Output as table (default: JSON)')
|
|
110
|
+
.action(async (options) => {
|
|
111
|
+
const cfg = getConfig();
|
|
112
|
+
|
|
113
|
+
if (!cfg.accessToken) {
|
|
114
|
+
error('Not logged in. Run: bi-cli auth login');
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const days = parseInt(options.days, 10);
|
|
119
|
+
if (isNaN(days) || days < 1 || days > 365) {
|
|
120
|
+
error('Days must be between 1 and 365');
|
|
121
|
+
process.exit(1);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const format = options.pretty ? OutputFormat.PRETTY : OutputFormat.JSON;
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
const response = await axios.get<TrafficOverview>(
|
|
128
|
+
`${cfg.backendUrl}/api/v1/analytics/traffic/overview`,
|
|
129
|
+
{
|
|
130
|
+
params: { days, product_id: options.product },
|
|
131
|
+
headers: { Authorization: `Bearer ${cfg.accessToken}` },
|
|
132
|
+
}
|
|
133
|
+
);
|
|
134
|
+
|
|
135
|
+
const data = response.data;
|
|
136
|
+
|
|
137
|
+
if (format === OutputFormat.JSON) {
|
|
138
|
+
outputJson(data);
|
|
139
|
+
} else {
|
|
140
|
+
console.log('\n📊 Traffic Overview\n');
|
|
141
|
+
console.log(
|
|
142
|
+
`Period: ${data.period.start} to ${data.period.end} (${data.period.days} days)\n`
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
outputPretty({
|
|
146
|
+
'Page Views': `${data.summary.page_views.toLocaleString()} (${formatChange(data.comparison.page_views_change)})`,
|
|
147
|
+
'Unique Visitors': `${data.summary.unique_visitors.toLocaleString()} (${formatChange(data.comparison.unique_visitors_change)})`,
|
|
148
|
+
Sessions: `${data.summary.sessions.toLocaleString()} (${formatChange(data.comparison.sessions_change)})`,
|
|
149
|
+
'Avg Session Duration': formatDuration(data.summary.avg_session_duration),
|
|
150
|
+
'Bounce Rate': formatPercent(data.summary.bounce_rate),
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
} catch (err: unknown) {
|
|
154
|
+
handleError(err);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
// traffic sources
|
|
159
|
+
traffic
|
|
160
|
+
.command('sources')
|
|
161
|
+
.description(
|
|
162
|
+
`Traffic source analysis.
|
|
163
|
+
|
|
164
|
+
Analyze visitor sources (Google, WeChat, direct, etc.).
|
|
165
|
+
|
|
166
|
+
Returns JSON:
|
|
167
|
+
{
|
|
168
|
+
"sources": [
|
|
169
|
+
{
|
|
170
|
+
"source": "google",
|
|
171
|
+
"medium": "organic",
|
|
172
|
+
"visitors": 1000,
|
|
173
|
+
"page_views": 3000,
|
|
174
|
+
"percentage": 0.35 // 35%
|
|
175
|
+
}
|
|
176
|
+
]
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
Use case: Evaluate channel effectiveness, optimize marketing spend.`
|
|
180
|
+
)
|
|
181
|
+
.option('--days <number>', 'Number of days (default: 30)', '30')
|
|
182
|
+
.option('--limit <number>', 'Number of results (default: 10)', '10')
|
|
183
|
+
.option('--pretty', 'Output as table (default: JSON)')
|
|
184
|
+
.action(async (options) => {
|
|
185
|
+
const cfg = getConfig();
|
|
186
|
+
|
|
187
|
+
if (!cfg.accessToken) {
|
|
188
|
+
error('Not logged in. Run: bi-cli auth login');
|
|
189
|
+
process.exit(1);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
const days = parseInt(options.days, 10);
|
|
193
|
+
const limit = parseInt(options.limit, 10);
|
|
194
|
+
const format = options.pretty ? OutputFormat.PRETTY : OutputFormat.JSON;
|
|
195
|
+
|
|
196
|
+
try {
|
|
197
|
+
const response = await axios.get<{ sources: TrafficSource[] }>(
|
|
198
|
+
`${cfg.backendUrl}/api/v1/analytics/traffic/sources`,
|
|
199
|
+
{
|
|
200
|
+
params: { days, limit },
|
|
201
|
+
headers: { Authorization: `Bearer ${cfg.accessToken}` },
|
|
202
|
+
}
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
const { sources } = response.data;
|
|
206
|
+
|
|
207
|
+
if (format === OutputFormat.JSON) {
|
|
208
|
+
outputJson(response.data);
|
|
209
|
+
} else {
|
|
210
|
+
console.log('\n🔗 Traffic Sources\n');
|
|
211
|
+
outputPretty(
|
|
212
|
+
sources.map((s) => ({
|
|
213
|
+
Source: s.source,
|
|
214
|
+
Medium: s.medium,
|
|
215
|
+
Visitors: s.visitors.toLocaleString(),
|
|
216
|
+
'Page Views': s.page_views.toLocaleString(),
|
|
217
|
+
Share: formatPercent(s.percentage),
|
|
218
|
+
})),
|
|
219
|
+
['Source', 'Medium', 'Visitors', 'Page Views', 'Share']
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
} catch (err: unknown) {
|
|
223
|
+
handleError(err);
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
// traffic funnel
|
|
228
|
+
traffic
|
|
229
|
+
.command('funnel')
|
|
230
|
+
.description(
|
|
231
|
+
`Conversion funnel analysis.
|
|
232
|
+
|
|
233
|
+
Analyze user journey from visit to purchase:
|
|
234
|
+
Visit → View Product → Add to Cart → Checkout → Purchase
|
|
235
|
+
|
|
236
|
+
Returns JSON:
|
|
237
|
+
{
|
|
238
|
+
"funnel": [
|
|
239
|
+
{ "step": "page_view", "count": 10000, "rate": 1.0, "conversion": 1.0 },
|
|
240
|
+
{ "step": "product_view", "count": 5000, "rate": 0.5, "conversion": 0.5 },
|
|
241
|
+
{ "step": "add_to_cart", "count": 1000, "rate": 0.1, "conversion": 0.2 },
|
|
242
|
+
{ "step": "checkout", "count": 500, "rate": 0.05, "conversion": 0.5 },
|
|
243
|
+
{ "step": "purchase", "count": 300, "rate": 0.03, "conversion": 0.6 }
|
|
244
|
+
]
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
Note: rate = ratio from start, conversion = conversion from previous step.`
|
|
248
|
+
)
|
|
249
|
+
.option('--days <number>', 'Number of days (default: 30)', '30')
|
|
250
|
+
.option('--product <id>', 'Filter by product ID (UUID format)')
|
|
251
|
+
.option('--pretty', 'Output as table (default: JSON)')
|
|
252
|
+
.action(async (options) => {
|
|
253
|
+
const cfg = getConfig();
|
|
254
|
+
|
|
255
|
+
if (!cfg.accessToken) {
|
|
256
|
+
error('Not logged in. Run: bi-cli auth login');
|
|
257
|
+
process.exit(1);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const days = parseInt(options.days, 10);
|
|
261
|
+
const format = options.pretty ? OutputFormat.PRETTY : OutputFormat.JSON;
|
|
262
|
+
|
|
263
|
+
try {
|
|
264
|
+
const response = await axios.get<{ funnel: FunnelStep[] }>(
|
|
265
|
+
`${cfg.backendUrl}/api/v1/analytics/traffic/funnel`,
|
|
266
|
+
{
|
|
267
|
+
params: { days, product_id: options.product },
|
|
268
|
+
headers: { Authorization: `Bearer ${cfg.accessToken}` },
|
|
269
|
+
}
|
|
270
|
+
);
|
|
271
|
+
|
|
272
|
+
const { funnel } = response.data;
|
|
273
|
+
|
|
274
|
+
if (format === OutputFormat.JSON) {
|
|
275
|
+
outputJson(response.data);
|
|
276
|
+
} else {
|
|
277
|
+
console.log('\n🔻 Conversion Funnel\n');
|
|
278
|
+
outputPretty(
|
|
279
|
+
funnel.map((f) => ({
|
|
280
|
+
Step: f.step.replace(/_/g, ' '),
|
|
281
|
+
Users: f.count.toLocaleString(),
|
|
282
|
+
'From Start': formatPercent(f.rate),
|
|
283
|
+
Conversion: formatPercent(f.conversion),
|
|
284
|
+
})),
|
|
285
|
+
['Step', 'Users', 'From Start', 'Conversion']
|
|
286
|
+
);
|
|
287
|
+
}
|
|
288
|
+
} catch (err: unknown) {
|
|
289
|
+
handleError(err);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
// traffic search
|
|
294
|
+
traffic
|
|
295
|
+
.command('search')
|
|
296
|
+
.description(
|
|
297
|
+
`Site search analytics.
|
|
298
|
+
|
|
299
|
+
Analyze search keywords, result counts, and click-through rates.
|
|
300
|
+
|
|
301
|
+
Returns JSON:
|
|
302
|
+
{
|
|
303
|
+
"searches": [
|
|
304
|
+
{ "query": "dress", "count": 500, "avg_results": 25, "click_rate": 0.65 }
|
|
305
|
+
],
|
|
306
|
+
"zero_results": [
|
|
307
|
+
{ "query": "nonexistent product", "count": 10 }
|
|
308
|
+
]
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
Use case: Optimize product titles, add missing products, improve search.`
|
|
312
|
+
)
|
|
313
|
+
.option('--days <number>', 'Number of days (default: 30)', '30')
|
|
314
|
+
.option('--limit <number>', 'Number of results (default: 20)', '20')
|
|
315
|
+
.option('--zero-results', 'Show only zero-result queries')
|
|
316
|
+
.option('--pretty', 'Output as table (default: JSON)')
|
|
317
|
+
.action(async (options) => {
|
|
318
|
+
const cfg = getConfig();
|
|
319
|
+
|
|
320
|
+
if (!cfg.accessToken) {
|
|
321
|
+
error('Not logged in. Run: bi-cli auth login');
|
|
322
|
+
process.exit(1);
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
const days = parseInt(options.days, 10);
|
|
326
|
+
const limit = parseInt(options.limit, 10);
|
|
327
|
+
const format = options.pretty ? OutputFormat.PRETTY : OutputFormat.JSON;
|
|
328
|
+
|
|
329
|
+
try {
|
|
330
|
+
const response = await axios.get<{
|
|
331
|
+
searches: SearchItem[];
|
|
332
|
+
zero_results: { query: string; count: number }[];
|
|
333
|
+
}>(`${cfg.backendUrl}/api/v1/analytics/traffic/search`, {
|
|
334
|
+
params: { days, limit, zero_results: options.zeroResults },
|
|
335
|
+
headers: { Authorization: `Bearer ${cfg.accessToken}` },
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
const { searches, zero_results } = response.data;
|
|
339
|
+
|
|
340
|
+
if (format === OutputFormat.JSON) {
|
|
341
|
+
outputJson(response.data);
|
|
342
|
+
} else {
|
|
343
|
+
console.log('\n🔍 Top Searches\n');
|
|
344
|
+
outputPretty(
|
|
345
|
+
searches.map((s) => ({
|
|
346
|
+
Query: s.query,
|
|
347
|
+
Searches: s.count.toLocaleString(),
|
|
348
|
+
'Avg Results': s.avg_results,
|
|
349
|
+
'Click Rate': formatPercent(s.click_rate),
|
|
350
|
+
})),
|
|
351
|
+
['Query', 'Searches', 'Avg Results', 'Click Rate']
|
|
352
|
+
);
|
|
353
|
+
|
|
354
|
+
if (zero_results.length > 0) {
|
|
355
|
+
console.log('\n❌ Zero Results Queries\n');
|
|
356
|
+
outputPretty(
|
|
357
|
+
zero_results.map((z) => ({
|
|
358
|
+
Query: z.query,
|
|
359
|
+
Count: z.count.toLocaleString(),
|
|
360
|
+
})),
|
|
361
|
+
['Query', 'Count']
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
} catch (err: unknown) {
|
|
366
|
+
handleError(err);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// traffic pages
|
|
371
|
+
traffic
|
|
372
|
+
.command('pages')
|
|
373
|
+
.description(
|
|
374
|
+
`Top pages analysis.
|
|
375
|
+
|
|
376
|
+
View most popular pages sorted by page views.
|
|
377
|
+
|
|
378
|
+
Returns JSON:
|
|
379
|
+
{
|
|
380
|
+
"pages": [
|
|
381
|
+
{
|
|
382
|
+
"path": "/products/xxx",
|
|
383
|
+
"page_views": 5000,
|
|
384
|
+
"unique_visitors": 2000,
|
|
385
|
+
"sessions": 3000
|
|
386
|
+
}
|
|
387
|
+
]
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
Use case: Understand browsing patterns, optimize popular page experience.`
|
|
391
|
+
)
|
|
392
|
+
.option('--days <number>', 'Number of days (default: 30)', '30')
|
|
393
|
+
.option('--limit <number>', 'Number of results (default: 20)', '20')
|
|
394
|
+
.option('--pretty', 'Output as table (default: JSON)')
|
|
395
|
+
.action(async (options) => {
|
|
396
|
+
const cfg = getConfig();
|
|
397
|
+
|
|
398
|
+
if (!cfg.accessToken) {
|
|
399
|
+
error('Not logged in. Run: bi-cli auth login');
|
|
400
|
+
process.exit(1);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const days = parseInt(options.days, 10);
|
|
404
|
+
const limit = parseInt(options.limit, 10);
|
|
405
|
+
const format = options.pretty ? OutputFormat.PRETTY : OutputFormat.JSON;
|
|
406
|
+
|
|
407
|
+
try {
|
|
408
|
+
const response = await axios.get<{ pages: PageItem[] }>(
|
|
409
|
+
`${cfg.backendUrl}/api/v1/analytics/traffic/pages`,
|
|
410
|
+
{
|
|
411
|
+
params: { days, limit },
|
|
412
|
+
headers: { Authorization: `Bearer ${cfg.accessToken}` },
|
|
413
|
+
}
|
|
414
|
+
);
|
|
415
|
+
|
|
416
|
+
const { pages } = response.data;
|
|
417
|
+
|
|
418
|
+
if (format === OutputFormat.JSON) {
|
|
419
|
+
outputJson(response.data);
|
|
420
|
+
} else {
|
|
421
|
+
console.log('\n📄 Top Pages\n');
|
|
422
|
+
outputPretty(
|
|
423
|
+
pages.map((p) => ({
|
|
424
|
+
Path: p.path.length > 40 ? p.path.substring(0, 37) + '...' : p.path,
|
|
425
|
+
'Page Views': p.page_views.toLocaleString(),
|
|
426
|
+
Visitors: p.unique_visitors.toLocaleString(),
|
|
427
|
+
Sessions: p.sessions.toLocaleString(),
|
|
428
|
+
})),
|
|
429
|
+
['Path', 'Page Views', 'Visitors', 'Sessions']
|
|
430
|
+
);
|
|
431
|
+
}
|
|
432
|
+
} catch (err: unknown) {
|
|
433
|
+
handleError(err);
|
|
434
|
+
}
|
|
435
|
+
});
|
|
436
|
+
|
|
437
|
+
return traffic;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
function handleError(err: unknown): never {
|
|
441
|
+
const axiosError = err as {
|
|
442
|
+
response?: { status?: number; data?: { error?: string } };
|
|
443
|
+
};
|
|
444
|
+
const errorObj = err as Error;
|
|
445
|
+
|
|
446
|
+
if (axiosError.response?.status === 401) {
|
|
447
|
+
error('Authentication failed. Please login again: bi-cli auth login');
|
|
448
|
+
} else if (axiosError.response?.data?.error) {
|
|
449
|
+
error(`Error: ${axiosError.response.data.error}`);
|
|
450
|
+
} else {
|
|
451
|
+
error(`Request failed: ${errorObj.message || 'Unknown error'}`);
|
|
452
|
+
}
|
|
453
|
+
process.exit(1);
|
|
454
|
+
}
|
package/src/commands/trends.ts
CHANGED
|
@@ -78,15 +78,39 @@ interface ForecastResponse {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
export function createTrendsCommand(): Command {
|
|
81
|
-
const trends = new Command('trends').description(
|
|
81
|
+
const trends = new Command('trends').description(
|
|
82
|
+
`Trend analytics.
|
|
83
|
+
|
|
84
|
+
Analyze revenue trends, order heatmaps, seasonality, and forecasts.`
|
|
85
|
+
);
|
|
82
86
|
|
|
83
87
|
// trends revenue
|
|
84
88
|
trends
|
|
85
89
|
.command('revenue')
|
|
86
|
-
.description(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
.description(
|
|
91
|
+
`Revenue trend analysis.
|
|
92
|
+
|
|
93
|
+
View revenue over time with hourly/daily/weekly aggregation and 7-day moving average.
|
|
94
|
+
|
|
95
|
+
Returns JSON:
|
|
96
|
+
{
|
|
97
|
+
"statistics": {
|
|
98
|
+
"total_revenue": number,
|
|
99
|
+
"avg_revenue": number,
|
|
100
|
+
"trend_direction": "up" | "down" | "stable"
|
|
101
|
+
},
|
|
102
|
+
"trend": [
|
|
103
|
+
{ "period": "2024-01-01", "revenue": 1000, "orders": 50, "moving_avg_7": 950 }
|
|
104
|
+
]
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
Examples:
|
|
108
|
+
bi-cli trends revenue # Last 30 days, daily
|
|
109
|
+
bi-cli trends revenue --days 7 --granularity hourly # Last 7 days, hourly`
|
|
110
|
+
)
|
|
111
|
+
.option('--days <number>', 'Number of days (default: 30)', '30')
|
|
112
|
+
.option('--granularity <type>', 'Time granularity: hourly | daily | weekly', 'daily')
|
|
113
|
+
.option('--pretty', 'Output as table')
|
|
90
114
|
.action(async (options) => {
|
|
91
115
|
const cfg = getConfig();
|
|
92
116
|
if (!cfg.accessToken) {
|
|
@@ -152,9 +176,25 @@ export function createTrendsCommand(): Command {
|
|
|
152
176
|
// trends heatmap
|
|
153
177
|
trends
|
|
154
178
|
.command('heatmap')
|
|
155
|
-
.description(
|
|
156
|
-
|
|
157
|
-
|
|
179
|
+
.description(
|
|
180
|
+
`Orders heatmap by day and hour.
|
|
181
|
+
|
|
182
|
+
Analyze order distribution by day of week and hour to find peak times.
|
|
183
|
+
|
|
184
|
+
Returns JSON:
|
|
185
|
+
{
|
|
186
|
+
"heatmap": [
|
|
187
|
+
{ "day": "Monday", "hours": [ { "hour": 10, "orders": 15, "revenue": 500 }, ... ] }
|
|
188
|
+
],
|
|
189
|
+
"peak_times": [
|
|
190
|
+
{ "day": "Saturday", "hour": "14:00-15:00", "orders": 25 }
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
Use case: Optimize marketing timing, schedule customer service staff.`
|
|
195
|
+
)
|
|
196
|
+
.option('--days <number>', 'Number of days (default: 30)', '30')
|
|
197
|
+
.option('--pretty', 'Output as table')
|
|
158
198
|
.action(async (options) => {
|
|
159
199
|
const cfg = getConfig();
|
|
160
200
|
if (!cfg.accessToken) {
|
|
@@ -221,8 +261,26 @@ export function createTrendsCommand(): Command {
|
|
|
221
261
|
// trends seasonality
|
|
222
262
|
trends
|
|
223
263
|
.command('seasonality')
|
|
224
|
-
.description(
|
|
225
|
-
|
|
264
|
+
.description(
|
|
265
|
+
`Monthly/seasonal pattern analysis.
|
|
266
|
+
|
|
267
|
+
Analyze sales by month to identify peak and low seasons.
|
|
268
|
+
|
|
269
|
+
Returns JSON:
|
|
270
|
+
{
|
|
271
|
+
"monthly_pattern": [
|
|
272
|
+
{ "month": 1, "month_name": "January", "revenue": 50000, "orders": 500, "index": 120 }
|
|
273
|
+
],
|
|
274
|
+
"insights": {
|
|
275
|
+
"peak_months": ["December", "November"],
|
|
276
|
+
"low_months": ["February"],
|
|
277
|
+
"avg_monthly_revenue": 45000
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
Note: index is percentage relative to average (>100 = above average).`
|
|
282
|
+
)
|
|
283
|
+
.option('--pretty', 'Output as table')
|
|
226
284
|
.action(async (options) => {
|
|
227
285
|
const cfg = getConfig();
|
|
228
286
|
if (!cfg.accessToken) {
|
|
@@ -277,9 +335,28 @@ export function createTrendsCommand(): Command {
|
|
|
277
335
|
// trends forecast
|
|
278
336
|
trends
|
|
279
337
|
.command('forecast')
|
|
280
|
-
.description(
|
|
281
|
-
|
|
282
|
-
|
|
338
|
+
.description(
|
|
339
|
+
`Revenue forecast.
|
|
340
|
+
|
|
341
|
+
Predict future revenue based on historical data, considering trends and day-of-week patterns.
|
|
342
|
+
|
|
343
|
+
Returns JSON:
|
|
344
|
+
{
|
|
345
|
+
"trend": { "direction": "up", "daily_change": 50.5 },
|
|
346
|
+
"forecast": [
|
|
347
|
+
{ "date": "2024-01-15", "day_of_week": "Monday", "predicted_revenue": 5000, "confidence": "medium" }
|
|
348
|
+
],
|
|
349
|
+
"disclaimer": "For reference only..."
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
Note: Forecast based on simple linear model, for reference only.
|
|
353
|
+
|
|
354
|
+
Examples:
|
|
355
|
+
bi-cli trends forecast # Forecast next 7 days
|
|
356
|
+
bi-cli trends forecast --days 14 # Forecast next 14 days`
|
|
357
|
+
)
|
|
358
|
+
.option('--days <number>', 'Days to forecast (default: 7)', '7')
|
|
359
|
+
.option('--pretty', 'Output as table')
|
|
283
360
|
.action(async (options) => {
|
|
284
361
|
const cfg = getConfig();
|
|
285
362
|
if (!cfg.accessToken) {
|
package/src/index.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { createSalesCommand } from './commands/sales.js';
|
|
|
9
9
|
import { createProductCommand } from './commands/product.js';
|
|
10
10
|
import { createTrendsCommand } from './commands/trends.js';
|
|
11
11
|
import { createAnalyticsCommand } from './commands/analytics.js';
|
|
12
|
+
import { createTrafficCommand } from './commands/traffic.js';
|
|
12
13
|
|
|
13
14
|
// Read version from package.json
|
|
14
15
|
const __filename = fileURLToPath(import.meta.url);
|
|
@@ -19,7 +20,19 @@ const program = new Command();
|
|
|
19
20
|
|
|
20
21
|
program
|
|
21
22
|
.name('bi-cli')
|
|
22
|
-
.description(
|
|
23
|
+
.description(
|
|
24
|
+
`Optima BI CLI - E-commerce business intelligence tool for LLM agents.
|
|
25
|
+
|
|
26
|
+
IMPORTANT: Run 'bi-cli auth login' first to authenticate before using other commands.
|
|
27
|
+
|
|
28
|
+
Output: All commands output JSON by default (for programmatic parsing). Use --pretty for human-readable tables.
|
|
29
|
+
|
|
30
|
+
Common use cases:
|
|
31
|
+
- Get sales data → bi-cli sales get --days 7
|
|
32
|
+
- Top selling products → bi-cli product best-sellers --limit 10
|
|
33
|
+
- Revenue trends → bi-cli trends revenue --days 30
|
|
34
|
+
- Compare periods → bi-cli analytics compare --days 7`
|
|
35
|
+
)
|
|
23
36
|
.version(pkg.version);
|
|
24
37
|
|
|
25
38
|
// Auth commands
|
|
@@ -37,36 +50,39 @@ program.addCommand(createTrendsCommand());
|
|
|
37
50
|
// Analytics commands
|
|
38
51
|
program.addCommand(createAnalyticsCommand());
|
|
39
52
|
|
|
53
|
+
// Traffic commands
|
|
54
|
+
program.addCommand(createTrafficCommand());
|
|
55
|
+
|
|
40
56
|
// Config commands (placeholder)
|
|
41
57
|
program
|
|
42
58
|
.command('config')
|
|
43
|
-
.description('
|
|
59
|
+
.description('[NOT IMPLEMENTED] Configuration management')
|
|
44
60
|
.action(() => {
|
|
45
|
-
console.log('
|
|
61
|
+
console.log('This feature is not yet implemented');
|
|
46
62
|
});
|
|
47
63
|
|
|
48
64
|
// Customer commands (placeholder)
|
|
49
65
|
program
|
|
50
66
|
.command('customer')
|
|
51
|
-
.description('Customer analytics')
|
|
67
|
+
.description('[NOT IMPLEMENTED] Customer analytics')
|
|
52
68
|
.action(() => {
|
|
53
|
-
console.log('
|
|
69
|
+
console.log('This feature is not yet implemented');
|
|
54
70
|
});
|
|
55
71
|
|
|
56
72
|
// Inventory commands (placeholder)
|
|
57
73
|
program
|
|
58
74
|
.command('inventory')
|
|
59
|
-
.description('Inventory analytics')
|
|
75
|
+
.description('[NOT IMPLEMENTED] Inventory analytics')
|
|
60
76
|
.action(() => {
|
|
61
|
-
console.log('
|
|
77
|
+
console.log('This feature is not yet implemented');
|
|
62
78
|
});
|
|
63
79
|
|
|
64
80
|
// Platform commands (admin only - placeholder)
|
|
65
81
|
program
|
|
66
82
|
.command('platform')
|
|
67
|
-
.description('Platform analytics (admin only)')
|
|
83
|
+
.description('[NOT IMPLEMENTED] Platform analytics (admin only)')
|
|
68
84
|
.action(() => {
|
|
69
|
-
console.log('
|
|
85
|
+
console.log('This feature is not yet implemented');
|
|
70
86
|
});
|
|
71
87
|
|
|
72
88
|
program.parse();
|