@optima-chat/bi-cli 0.2.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.
Files changed (44) hide show
  1. package/dist/commands/analytics.d.ts +3 -0
  2. package/dist/commands/analytics.d.ts.map +1 -0
  3. package/dist/commands/analytics.js +228 -0
  4. package/dist/commands/analytics.js.map +1 -0
  5. package/dist/commands/auth.d.ts +3 -0
  6. package/dist/commands/auth.d.ts.map +1 -0
  7. package/dist/commands/auth.js +214 -0
  8. package/dist/commands/auth.js.map +1 -0
  9. package/dist/commands/product.d.ts +3 -0
  10. package/dist/commands/product.d.ts.map +1 -0
  11. package/dist/commands/product.js +199 -0
  12. package/dist/commands/product.js.map +1 -0
  13. package/dist/commands/sales.d.ts +3 -0
  14. package/dist/commands/sales.d.ts.map +1 -0
  15. package/dist/commands/sales.js +85 -0
  16. package/dist/commands/sales.js.map +1 -0
  17. package/dist/commands/trends.d.ts +3 -0
  18. package/dist/commands/trends.d.ts.map +1 -0
  19. package/dist/commands/trends.js +224 -0
  20. package/dist/commands/trends.js.map +1 -0
  21. package/dist/config/index.d.ts +21 -0
  22. package/dist/config/index.d.ts.map +1 -0
  23. package/dist/config/index.js +39 -0
  24. package/dist/config/index.js.map +1 -0
  25. package/dist/index.d.ts +3 -0
  26. package/dist/index.d.ts.map +1 -0
  27. package/dist/index.js +52 -0
  28. package/dist/index.js.map +1 -0
  29. package/dist/utils/output.d.ts +11 -0
  30. package/dist/utils/output.d.ts.map +1 -0
  31. package/dist/utils/output.js +45 -0
  32. package/dist/utils/output.js.map +1 -0
  33. package/package.json +39 -0
  34. package/src/commands/analytics.ts +352 -0
  35. package/src/commands/auth.ts +277 -0
  36. package/src/commands/product.ts +327 -0
  37. package/src/commands/sales.ts +125 -0
  38. package/src/commands/trends.ts +355 -0
  39. package/src/config/index.ts +50 -0
  40. package/src/index.ts +64 -0
  41. package/src/utils/output.ts +52 -0
  42. package/test-auth.js +63 -0
  43. package/test-sales.js +45 -0
  44. package/tsconfig.json +13 -0
package/test-auth.js ADDED
@@ -0,0 +1,63 @@
1
+ #!/usr/bin/env node
2
+
3
+ const axios = require('axios');
4
+
5
+ async function testAuthEndpoints() {
6
+ console.log('🧪 Testing OAuth Device Flow endpoints\n');
7
+
8
+ try {
9
+ // Step 1: Test device authorization
10
+ console.log('1ļøāƒ£ Testing device authorization endpoint...');
11
+ const deviceRes = await axios.post(
12
+ 'https://auth.optima.chat/api/v1/oauth/device/authorize',
13
+ { client_id: 'bi-cli-aqkutatj' }
14
+ );
15
+
16
+ console.log('āœ… Device authorization successful!');
17
+ console.log(' Device Code:', deviceRes.data.device_code.substring(0, 20) + '...');
18
+ console.log(' User Code:', deviceRes.data.user_code);
19
+ console.log(' Verification URI:', deviceRes.data.verification_uri);
20
+ console.log(' Expires in:', deviceRes.data.expires_in, 'seconds');
21
+ console.log(' Polling interval:', deviceRes.data.interval, 'seconds');
22
+
23
+ // Step 2: Test token endpoint (will fail with authorization_pending, which is expected)
24
+ console.log('\n2ļøāƒ£ Testing token endpoint (expecting authorization_pending)...');
25
+ try {
26
+ const params = new URLSearchParams({
27
+ grant_type: 'urn:ietf:params:oauth:grant-type:device_code',
28
+ client_id: 'bi-cli-aqkutatj',
29
+ device_code: deviceRes.data.device_code,
30
+ });
31
+
32
+ await axios.post(
33
+ 'https://auth.optima.chat/api/v1/oauth/device/token',
34
+ params,
35
+ { headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }
36
+ );
37
+ console.log('āš ļø Unexpected success (user may have authorized)');
38
+ } catch (err) {
39
+ if (err.response?.data?.error === 'authorization_pending') {
40
+ console.log('āœ… Token endpoint working correctly (authorization_pending)');
41
+ } else {
42
+ console.log('āŒ Unexpected error:', err.response?.data || err.message);
43
+ }
44
+ }
45
+
46
+ console.log('\nāœ… All OAuth endpoints are correctly configured!');
47
+ console.log('\nšŸ“‹ Summary:');
48
+ console.log(' Auth Service: https://auth.optima.chat');
49
+ console.log(' Client ID: bi-cli-aqkutatj');
50
+ console.log(' Device Authorize: /api/v1/oauth/device/authorize');
51
+ console.log(' Token: /api/v1/oauth/device/token');
52
+ console.log('\nšŸ’” To test full login flow, run: npm run dev -- auth login');
53
+ } catch (err) {
54
+ console.error('āŒ Error:', err.message);
55
+ if (err.response) {
56
+ console.error(' Status:', err.response.status);
57
+ console.error(' Data:', err.response.data);
58
+ }
59
+ process.exit(1);
60
+ }
61
+ }
62
+
63
+ testAuthEndpoints();
package/test-sales.js ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+
3
+ const axios = require('axios');
4
+
5
+ async function testSales() {
6
+ try {
7
+ console.log('🧪 Testing sales API...\n');
8
+
9
+ const response = await axios.get('http://localhost:3001/api/v1/sales', {
10
+ params: { days: 7 },
11
+ headers: {
12
+ Authorization: 'Bearer test-token-no-validation',
13
+ },
14
+ });
15
+
16
+ const { summary, daily } = response.data.data;
17
+
18
+ console.log('šŸ“Š Sales Summary\n');
19
+ console.log(` Total Revenue: Ā„${summary.total_revenue.toFixed(2)}`);
20
+ console.log(` Total Orders: ${summary.total_orders}`);
21
+ console.log(` Avg Order Value: Ā„${summary.avg_order_value.toFixed(2)}`);
22
+ console.log(` Unique Customers: ${summary.unique_customers}`);
23
+
24
+ console.log('\nšŸ“… Daily Breakdown (showing first 3 days)\n');
25
+ daily.slice(0, 3).forEach((day) => {
26
+ console.log(` ${day.date}: Ā„${day.total_revenue.toFixed(2)} (${day.order_count} orders)`);
27
+ });
28
+
29
+ console.log(`\nāœ“ Cached: ${response.data.meta.cached}`);
30
+ if (response.data.meta.query_time_ms) {
31
+ console.log(`āœ“ Query Time: ${response.data.meta.query_time_ms}ms`);
32
+ }
33
+
34
+ console.log('\nāœ… Sales command logic works correctly!');
35
+ } catch (err) {
36
+ console.error('āŒ Error:', err.message);
37
+ if (err.response) {
38
+ console.error('Response status:', err.response.status);
39
+ console.error('Response data:', err.response.data);
40
+ }
41
+ process.exit(1);
42
+ }
43
+ }
44
+
45
+ testSales();
package/tsconfig.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./dist",
5
+ "rootDir": "./src",
6
+ "resolveJsonModule": true,
7
+ "module": "ES2022",
8
+ "moduleResolution": "bundler",
9
+ "allowSyntheticDefaultImports": true
10
+ },
11
+ "include": ["src/**/*"],
12
+ "exclude": ["node_modules", "dist"]
13
+ }