omnibiofex 2.8.0 → 2.8.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omnibiofex",
3
- "version": "2.8.0",
3
+ "version": "2.8.1",
4
4
  "description": "OmniBioFex X - The Autonomous Research Terminal for AI-powered research missions",
5
5
  "main": "bin/obx",
6
6
  "bin": {
@@ -2,6 +2,21 @@ const chalk = require('chalk');
2
2
  const open = require('open');
3
3
  const { getAuthToken, isAuthenticated } = require('../auth');
4
4
  const { PremiumSpinner, sleep } = require('../utils/display');
5
+ const { initializeApp } = require('firebase/app');
6
+ const { getAuth } = require('firebase/auth');
7
+ const { getFirestore, collection, query, where, getDocs } = require('firebase/firestore');
8
+
9
+ const firebaseConfig = {
10
+ apiKey: "AIzaSyDlgXId4pLlYqm-MDuhfz3dLH24KBRHkw8",
11
+ authDomain: "omnibiofex-x.firebaseapp.com",
12
+ projectId: "omnibiofex-x",
13
+ storageBucket: "omnibiofex-x.firebasestorage.app",
14
+ messagingSenderId: "292246591666",
15
+ appId: "1:292246591666:web:a182851585e4b0f79511ab"
16
+ };
17
+
18
+ const app = initializeApp(firebaseConfig);
19
+ const db = getFirestore(app);
5
20
 
6
21
  async function credits() {
7
22
  if (!isAuthenticated()) {
@@ -59,30 +74,82 @@ async function usage() {
59
74
  return;
60
75
  }
61
76
 
62
- console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
63
- console.log(chalk.white.bold('📊 USAGE STATISTICS'));
64
- console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
77
+ const spinner = new PremiumSpinner('Fetching usage statistics');
78
+ spinner.start();
79
+
80
+ try {
81
+ const auth = getAuth(app);
82
+ const user = auth.currentUser;
83
+
84
+ if (!user) {
85
+ spinner.fail('Not authenticated');
86
+ console.error(chalk.red('Please run: obx login'));
87
+ return;
88
+ }
89
+
90
+ // Fetch ALL missions (real data)
91
+ const allMissionsQuery = query(
92
+ collection(db, 'missions'),
93
+ where('uid', '==', user.uid)
94
+ );
95
+
96
+ const allMissionsSnapshot = await getDocs(allMissionsQuery);
97
+ const allMissions = [];
98
+
99
+ allMissionsSnapshot.forEach((docSnap) => {
100
+ allMissions.push({
101
+ id: docSnap.id,
102
+ ...docSnap.data()
103
+ });
104
+ });
105
+
106
+ // Calculate real statistics
107
+ const totalMissions = allMissions.length;
108
+ const completedMissions = allMissions.filter(m => m.status === 'completed').length;
109
+ const activeMissions = allMissions.filter(m => m.status === 'running' || m.status === 'pending').length;
110
+ const publishedMissions = allMissions.filter(m => m.isPublished === true).length;
111
+ const totalRCCSpent = allMissions.reduce((sum, m) => sum + (m.rccCost || 0), 0);
112
+
113
+ // Fetch published missions for earnings
114
+ const publishedQuery = query(
115
+ collection(db, 'missions'),
116
+ where('uid', '==', user.uid),
117
+ where('isPublished', '==', true)
118
+ );
119
+
120
+ const publishedSnapshot = await getDocs(publishedQuery);
121
+ const publishedMissionsData = [];
122
+
123
+ publishedSnapshot.forEach((docSnap) => {
124
+ publishedMissionsData.push({
125
+ id: docSnap.id,
126
+ ...docSnap.data()
127
+ });
128
+ });
129
+
130
+ const totalViews = publishedMissionsData.reduce((sum, m) => sum + (m.views || 0), 0);
131
+ const totalEarnings = publishedMissionsData.reduce((sum, m) => sum + (m.earnings || 0), 0);
132
+
133
+ spinner.succeed('Usage statistics loaded');
134
+
135
+ console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
136
+ console.log(chalk.white.bold('📊 USAGE STATISTICS'));
137
+ console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
65
138
 
66
- // Simulated usage data
67
- const usageData = {
68
- totalMissions: 15,
69
- completedMissions: 12,
70
- activeMissions: 3,
71
- totalRCCSpent: 1250,
72
- publishedResearch: 8,
73
- totalViews: 56800,
74
- totalEarnings: 2840
75
- };
76
-
77
- console.log(chalk.white(` 🎯 Total Missions: ${chalk.green(usageData.totalMissions)}`));
78
- console.log(chalk.white(` ✅ Completed: ${chalk.green(usageData.completedMissions)}`));
79
- console.log(chalk.white(` ⏳ Active: ${chalk.yellow(usageData.activeMissions)}`));
80
- console.log(chalk.white(` ⛽ RCC Spent: ${chalk.green(usageData.totalRCCSpent.toLocaleString())}`));
81
- console.log(chalk.white(` 📤 Published: ${chalk.green(usageData.publishedResearch)}`));
82
- console.log(chalk.white(` 👁 Total Views: ${chalk.green(usageData.totalViews.toLocaleString())}`));
83
- console.log(chalk.white(` 💰 Total Earnings: ${chalk.green('₹' + usageData.totalEarnings.toLocaleString())}`));
84
-
85
- console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════\n'));
139
+ console.log(chalk.white(` 🎯 Total Missions: ${chalk.green(totalMissions)}`));
140
+ console.log(chalk.white(` Completed: ${chalk.green(completedMissions)}`));
141
+ console.log(chalk.white(` ⏳ Active: ${chalk.yellow(activeMissions)}`));
142
+ console.log(chalk.white(` ⛽ RCC Spent: ${chalk.green(totalRCCSpent.toLocaleString())}`));
143
+ console.log(chalk.white(` 📤 Published: ${chalk.green(publishedMissions)}`));
144
+ console.log(chalk.white(` 👁 Total Views: ${chalk.green(totalViews.toLocaleString())}`));
145
+ console.log(chalk.white(` 💰 Total Earnings: ${chalk.green('₹' + totalEarnings.toLocaleString())}`));
146
+
147
+ console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════\n'));
148
+
149
+ } catch (error) {
150
+ spinner.fail('Failed to fetch usage statistics');
151
+ console.error(chalk.red(error.message));
152
+ }
86
153
  }
87
154
 
88
155
  async function buy() {
@@ -1,6 +1,21 @@
1
1
  const chalk = require('chalk');
2
- const { isAuthenticated } = require('../auth');
2
+ const { getAuthToken, isAuthenticated } = require('../auth');
3
3
  const { PremiumSpinner, sleep } = require('../utils/display');
4
+ const { initializeApp } = require('firebase/app');
5
+ const { getAuth } = require('firebase/auth');
6
+ const { getFirestore, collection, query, where, orderBy, limit, getDocs } = require('firebase/firestore');
7
+
8
+ const firebaseConfig = {
9
+ apiKey: "AIzaSyDlgXId4pLlYqm-MDuhfz3dLH24KBRHkw8",
10
+ authDomain: "omnibiofex-x.firebaseapp.com",
11
+ projectId: "omnibiofex-x",
12
+ storageBucket: "omnibiofex-x.firebasestorage.app",
13
+ messagingSenderId: "292246591666",
14
+ appId: "1:292246591666:web:a182851585e4b0f79511ab"
15
+ };
16
+
17
+ const app = initializeApp(firebaseConfig);
18
+ const db = getFirestore(app);
4
19
 
5
20
  async function earnings() {
6
21
  if (!isAuthenticated()) {
@@ -10,75 +25,123 @@ async function earnings() {
10
25
 
11
26
  const spinner = new PremiumSpinner('Fetching your earnings data');
12
27
  spinner.start();
13
- await sleep(800);
14
- spinner.succeed('Earnings data loaded');
15
-
16
- console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
17
- console.log(chalk.white.bold('💰 EARNINGS DASHBOARD'));
18
- console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
19
-
20
- // Simulated earnings data
21
- const earningsData = {
22
- totalEarnings: 2840,
23
- thisMonth: 840,
24
- lastMonth: 1200,
25
- pending: 420,
26
- totalViews: 56800,
27
- thisMonthViews: 14200,
28
- publishedResearch: 12,
29
- averagePerView: 0.05,
30
- revenueShare: 80,
31
- nextPayout: '2026-08-01',
32
- payoutMethod: 'Bank Transfer'
33
- };
34
-
35
- console.log(chalk.white.bold('📊 OVERVIEW'));
36
- console.log(chalk.gray('─'.repeat(60)));
37
- console.log(chalk.white(`\n 💰 Total Earnings: ${chalk.green('₹' + earningsData.totalEarnings.toLocaleString())}`));
38
- console.log(chalk.white(` 📅 This Month: ${chalk.green('₹' + earningsData.thisMonth.toLocaleString())}`));
39
- console.log(chalk.white(` 📅 Last Month: ${chalk.gray('₹' + earningsData.lastMonth.toLocaleString())}`));
40
- console.log(chalk.white(` ⏳ Pending Payout: ${chalk.yellow('₹' + earningsData.pending.toLocaleString())}`));
41
-
42
- console.log(chalk.white.bold('\n\n📈 TRAFFIC METRICS'));
43
- console.log(chalk.gray(''.repeat(60)));
44
- console.log(chalk.white(`\n 👁 Total Views: ${chalk.green(earningsData.totalViews.toLocaleString())}`));
45
- console.log(chalk.white(` 👁 This Month: ${chalk.green(earningsData.thisMonthViews.toLocaleString())}`));
46
- console.log(chalk.white(` 📄 Published Research: ${chalk.green(earningsData.publishedResearch)}`));
47
- console.log(chalk.white(` 💵 Average Per View: ${chalk.green('₹' + earningsData.averagePerView)}`));
48
-
49
- console.log(chalk.white.bold('\n\n💳 PAYOUT DETAILS'));
50
- console.log(chalk.gray('─'.repeat(60)));
51
- console.log(chalk.white(`\n 📊 Revenue Share: ${chalk.green(earningsData.revenueShare + '%')}`));
52
- console.log(chalk.white(` 📅 Next Payout: ${chalk.green(earningsData.nextPayout)}`));
53
- console.log(chalk.white(` 💳 Payout Method: ${chalk.green(earningsData.payoutMethod)}`));
54
-
55
- console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
56
- console.log(chalk.white.bold('📊 MONTHLY BREAKDOWN'));
57
- console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
58
-
59
- const monthlyData = [
60
- { month: 'July 2026', earnings: 840, views: 14200, research: 3 },
61
- { month: 'June 2026', earnings: 1200, views: 21000, research: 4 },
62
- { month: 'May 2026', earnings: 800, views: 15600, research: 3 },
63
- { month: 'April 2026', earnings: 0, views: 6000, research: 2 }
64
- ];
65
-
66
- monthlyData.forEach(m => {
67
- console.log(chalk.white(`\n 📅 ${chalk.hex('#F24E1E')(m.month)}`));
68
- console.log(chalk.white(` 💰 Earnings: ${chalk.green('₹' + m.earnings.toLocaleString())}`));
69
- console.log(chalk.white(` 👁 Views: ${chalk.gray(m.views.toLocaleString())}`));
70
- console.log(chalk.white(` 📄 Research: ${chalk.gray(m.research)}`));
71
- });
72
-
73
- console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════\n'));
74
-
75
- console.log(chalk.white.bold('💡 TIPS TO INCREASE EARNINGS'));
76
- console.log(chalk.gray(''.repeat(60)));
77
- console.log(chalk.white('\n ✓ Publish more research to increase views'));
78
- console.log(chalk.white(' Share your research on social media'));
79
- console.log(chalk.white(' Use relevant tags for better discoverability'));
80
- console.log(chalk.white(' Create high-quality, comprehensive research'));
81
- console.log(chalk.white(' Update research regularly with new findings\n'));
28
+
29
+ try {
30
+ const auth = getAuth(app);
31
+ const user = auth.currentUser;
32
+
33
+ if (!user) {
34
+ spinner.fail('Not authenticated');
35
+ console.error(chalk.red('Please run: obx login'));
36
+ return;
37
+ }
38
+
39
+ // Fetch real published missions with earnings data
40
+ const publishedQuery = query(
41
+ collection(db, 'missions'),
42
+ where('uid', '==', user.uid),
43
+ where('isPublished', '==', true),
44
+ orderBy('publishedAt', 'desc'),
45
+ limit(100)
46
+ );
47
+
48
+ const querySnapshot = await getDocs(publishedQuery);
49
+ const publishedMissions = [];
50
+
51
+ querySnapshot.forEach((docSnap) => {
52
+ publishedMissions.push({
53
+ id: docSnap.id,
54
+ ...docSnap.data()
55
+ });
56
+ });
57
+
58
+ spinner.succeed('Earnings data loaded');
59
+
60
+ // Calculate real earnings from actual data
61
+ const totalViews = publishedMissions.reduce((sum, m) => sum + (m.views || 0), 0);
62
+ const totalDownloads = publishedMissions.reduce((sum, m) => sum + (m.downloads || 0), 0);
63
+ const totalCitations = publishedMissions.reduce((sum, m) => sum + (m.citations || 0), 0);
64
+ const totalEarnings = publishedMissions.reduce((sum, m) => sum + (m.earnings || 0), 0);
65
+
66
+ // Calculate monthly breakdown
67
+ const now = new Date();
68
+ const thisMonth = now.getMonth();
69
+ const thisYear = now.getFullYear();
70
+ const lastMonth = thisMonth === 0 ? 11 : thisMonth - 1;
71
+ const lastMonthYear = thisMonth === 0 ? thisYear - 1 : thisYear;
72
+
73
+ const thisMonthMissions = publishedMissions.filter(m => {
74
+ const publishedDate = m.publishedAt?.toDate?.();
75
+ return publishedDate && publishedDate.getMonth() === thisMonth && publishedDate.getFullYear() === thisYear;
76
+ });
77
+
78
+ const lastMonthMissions = publishedMissions.filter(m => {
79
+ const publishedDate = m.publishedAt?.toDate?.();
80
+ return publishedDate && publishedDate.getMonth() === lastMonth && publishedDate.getFullYear() === lastMonthYear;
81
+ });
82
+
83
+ const thisMonthEarnings = thisMonthMissions.reduce((sum, m) => sum + (m.earnings || 0), 0);
84
+ const thisMonthViews = thisMonthMissions.reduce((sum, m) => sum + (m.views || 0), 0);
85
+ const lastMonthEarnings = lastMonthMissions.reduce((sum, m) => sum + (m.earnings || 0), 0);
86
+
87
+ console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
88
+ console.log(chalk.white.bold('💰 EARNINGS DASHBOARD'));
89
+ console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
90
+
91
+ console.log(chalk.white.bold('📊 OVERVIEW'));
92
+ console.log(chalk.gray(''.repeat(60)));
93
+ console.log(chalk.white(`\n 💰 Total Earnings: ${chalk.green('₹' + totalEarnings.toLocaleString())}`));
94
+ console.log(chalk.white(` 📅 This Month: ${chalk.green('₹' + thisMonthEarnings.toLocaleString())}`));
95
+ console.log(chalk.white(` 📅 Last Month: ${chalk.gray('₹' + lastMonthEarnings.toLocaleString())}`));
96
+ console.log(chalk.white(` 📄 Published Research: ${chalk.green(publishedMissions.length)}`));
97
+
98
+ console.log(chalk.white.bold('\n\n📈 TRAFFIC METRICS'));
99
+ console.log(chalk.gray('─'.repeat(60)));
100
+ console.log(chalk.white(`\n 👁 Total Views: ${chalk.green(totalViews.toLocaleString())}`));
101
+ console.log(chalk.white(` 👁 This Month: ${chalk.green(thisMonthViews.toLocaleString())}`));
102
+ console.log(chalk.white(` 💾 Total Downloads: ${chalk.green(totalDownloads.toLocaleString())}`));
103
+ console.log(chalk.white(` 📚 Total Citations: ${chalk.green(totalCitations.toLocaleString())}`));
104
+
105
+ if (totalViews > 0) {
106
+ const averagePerView = totalEarnings / totalViews;
107
+ console.log(chalk.white(` 💵 Average Per View: ${chalk.green('₹' + averagePerView.toFixed(3))}`));
108
+ }
109
+
110
+ console.log(chalk.white.bold('\n\n💳 PAYOUT DETAILS'));
111
+ console.log(chalk.gray('─'.repeat(60)));
112
+ console.log(chalk.white(`\n 📊 Revenue Share: ${chalk.green('80%')}`));
113
+ console.log(chalk.white(` 📅 Next Payout: ${chalk.green('1st of next month')}`));
114
+ console.log(chalk.white(` 💳 Payout Method: ${chalk.green('Bank Transfer / UPI')}`));
115
+
116
+ if (publishedMissions.length > 0) {
117
+ console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
118
+ console.log(chalk.white.bold('📊 YOUR PUBLISHED RESEARCH'));
119
+ console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
120
+
121
+ publishedMissions.slice(0, 10).forEach((m, i) => {
122
+ const publishedDate = m.publishedAt?.toDate?.().toLocaleDateString() || 'N/A';
123
+ console.log(chalk.white(`\n ${i + 1}. ${chalk.hex('#F24E1E')(m.id)}`));
124
+ console.log(chalk.white(` Topic: ${(m.message || 'No topic').substring(0, 50)}${(m.message?.length || 0) > 50 ? '...' : ''}`));
125
+ console.log(chalk.white(` 👁 Views: ${chalk.green((m.views || 0).toLocaleString())}`));
126
+ console.log(chalk.white(` 💰 Earnings: ${chalk.green('₹' + (m.earnings || 0).toLocaleString())}`));
127
+ console.log(chalk.gray(` 📅 Published: ${publishedDate}`));
128
+ });
129
+ }
130
+
131
+ console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════\n'));
132
+
133
+ console.log(chalk.white.bold('💡 TIPS TO INCREASE EARNINGS'));
134
+ console.log(chalk.gray('─'.repeat(60)));
135
+ console.log(chalk.white('\n ✓ Publish more research to increase views'));
136
+ console.log(chalk.white(' ✓ Share your research on social media'));
137
+ console.log(chalk.white(' ✓ Use relevant tags for better discoverability'));
138
+ console.log(chalk.white(' ✓ Create high-quality, comprehensive research'));
139
+ console.log(chalk.white(' ✓ Update research regularly with new findings\n'));
140
+
141
+ } catch (error) {
142
+ spinner.fail('Failed to fetch earnings data');
143
+ console.error(chalk.red(error.message));
144
+ }
82
145
  }
83
146
 
84
147
  module.exports = { earnings };
@@ -1,8 +1,22 @@
1
1
  const chalk = require('chalk');
2
2
  const inquirer = require('inquirer');
3
- const { getAuthToken } = require('../auth');
4
- const { isAuthenticated } = require('../auth');
3
+ const { getAuthToken, isAuthenticated } = require('../auth');
5
4
  const { PremiumSpinner, sleep } = require('../utils/display');
5
+ const { initializeApp } = require('firebase/app');
6
+ const { getAuth } = require('firebase/auth');
7
+ const { getFirestore, collection, query, where, orderBy, limit, getDocs, doc, updateDoc } = require('firebase/firestore');
8
+
9
+ const firebaseConfig = {
10
+ apiKey: "AIzaSyDlgXId4pLlYqm-MDuhfz3dLH24KBRHkw8",
11
+ authDomain: "omnibiofex-x.firebaseapp.com",
12
+ projectId: "omnibiofex-x",
13
+ storageBucket: "omnibiofex-x.firebasestorage.app",
14
+ messagingSenderId: "292246591666",
15
+ appId: "1:292246591666:web:a182851585e4b0f79511ab"
16
+ };
17
+
18
+ const app = initializeApp(firebaseConfig);
19
+ const db = getFirestore(app);
6
20
 
7
21
  async function publish(missionId) {
8
22
  if (!isAuthenticated()) {
@@ -14,56 +28,84 @@ async function publish(missionId) {
14
28
  console.log(chalk.white.bold('📤 PUBLISH RESEARCH'));
15
29
  console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
16
30
 
17
- // If no mission ID provided, show recent missions
31
+ const token = await getAuthToken();
32
+
33
+ // If no mission ID provided, fetch real missions from Firestore
18
34
  if (!missionId) {
19
- console.log(chalk.gray('Usage: obx publish <mission-id>'));
20
- console.log(chalk.gray('Example: obx publish mission_atlas_123\n'));
35
+ console.log(chalk.gray('Fetching your completed missions...\n'));
21
36
 
22
- const { action } = await inquirer.prompt([
23
- {
24
- type: 'list',
25
- name: 'action',
26
- message: 'What would you like to do?',
27
- choices: [
28
- { name: '📋 View my recent missions', value: 'view' },
29
- { name: '🔍 Search for a specific mission', value: 'search' },
30
- { name: '❌ Cancel', value: 'cancel' }
31
- ]
37
+ const spinner = new PremiumSpinner('Loading missions from database');
38
+ spinner.start();
39
+
40
+ try {
41
+ // Get authenticated user
42
+ const auth = getAuth(app);
43
+ const user = auth.currentUser;
44
+
45
+ if (!user) {
46
+ spinner.fail('Not authenticated');
47
+ console.error(chalk.red('Please run: obx login'));
48
+ return;
32
49
  }
33
- ]);
34
50
 
35
- if (action === 'cancel') return;
36
-
37
- if (action === 'view') {
38
- console.log(chalk.yellow('\n📋 Recent Missions (Last 10):'));
39
- console.log(chalk.gray(''.repeat(60)));
51
+ // Fetch real completed missions from Firestore
52
+ const missionsQuery = query(
53
+ collection(db, 'missions'),
54
+ where('uid', '==', user.uid),
55
+ where('status', '==', 'completed'),
56
+ where('isPublished', '==', false),
57
+ orderBy('createdAt', 'desc'),
58
+ limit(10)
59
+ );
60
+
61
+ const querySnapshot = await getDocs(missionsQuery);
62
+ const missions = [];
40
63
 
41
- // Simulated recent missions
42
- const missions = [
43
- { id: 'mission_atlas_123', title: 'Quantum Battery Optimization', status: 'completed', date: '2026-07-01' },
44
- { id: 'mission_helix_456', title: 'CRISPR Gene Editing Analysis', status: 'completed', date: '2026-06-28' },
45
- { id: 'mission_nova_789', title: 'Neural Interface Research', status: 'completed', date: '2026-06-25' },
46
- { id: 'mission_orion_101', title: 'Sustainable Energy Materials', status: 'completed', date: '2026-06-22' },
47
- { id: 'mission_phoenix_202', title: 'AI Ethics Framework', status: 'completed', date: '2026-06-20' }
48
- ];
64
+ querySnapshot.forEach((docSnap) => {
65
+ missions.push({
66
+ id: docSnap.id,
67
+ ...docSnap.data()
68
+ });
69
+ });
70
+
71
+ spinner.succeed(`Found ${missions.length} unpublished missions`);
72
+
73
+ if (missions.length === 0) {
74
+ console.log(chalk.yellow('\n⚠️ No unpublished missions found.'));
75
+ console.log(chalk.gray('Create a mission first: obx mission create\n'));
76
+ return;
77
+ }
49
78
 
79
+ console.log(chalk.white('\n📋 Your Unpublished Missions:'));
80
+ console.log(chalk.gray('─'.repeat(60)));
81
+
50
82
  missions.forEach((m, i) => {
83
+ const date = m.createdAt?.toDate?.().toLocaleDateString() || 'N/A';
51
84
  console.log(chalk.white(`\n${i + 1}. ${chalk.hex('#F24E1E')(m.id)}`));
52
- console.log(chalk.white(` Title: ${m.title}`));
53
- console.log(chalk.green(` Status: ${m.status}`));
54
- console.log(chalk.gray(` Date: ${m.date}`));
85
+ console.log(chalk.white(` Topic: ${(m.message || 'No topic').substring(0, 60)}${(m.message?.length || 0) > 60 ? '...' : ''}`));
86
+ console.log(chalk.green(` Type: ${m.taskType || 'Research'}`));
87
+ console.log(chalk.gray(` Date: ${date}`));
88
+ console.log(chalk.gray(` RCC Cost: ${m.rccCost || 0}`));
55
89
  });
56
90
 
57
- const { selectedMission } = await inquirer.prompt([
91
+ const { selectedIndex } = await inquirer.prompt([
58
92
  {
59
- type: 'input',
60
- name: 'selectedMission',
61
- message: '\nEnter mission ID to publish:',
62
- validate: (input) => input.length > 0 || 'Mission ID is required'
93
+ type: 'list',
94
+ name: 'selectedIndex',
95
+ message: '\nSelect mission to publish:',
96
+ choices: missions.map((m, i) => ({
97
+ name: `${i + 1}. ${m.id} - ${(m.message || 'No topic').substring(0, 50)}`,
98
+ value: i
99
+ }))
63
100
  }
64
101
  ]);
65
102
 
66
- missionId = selectedMission;
103
+ missionId = missions[selectedIndex].id;
104
+
105
+ } catch (error) {
106
+ spinner.fail('Failed to load missions');
107
+ console.error(chalk.red(error.message));
108
+ return;
67
109
  }
68
110
  }
69
111
 
@@ -72,70 +114,81 @@ async function publish(missionId) {
72
114
  spinner.start();
73
115
  await sleep(500);
74
116
 
75
- spinner.update('Generating SEO-optimized page');
76
- await sleep(500);
77
-
78
- spinner.update('Adding metadata and tags');
79
- await sleep(400);
80
-
81
- spinner.update('Submitting to Google for indexing');
82
- await sleep(600);
83
-
84
- spinner.update('Enabling revenue tracking');
85
- await sleep(400);
86
-
87
- spinner.succeed('Research published successfully!');
117
+ try {
118
+ spinner.update('Fetching mission data');
119
+ const missionRef = doc(db, 'missions', missionId);
120
+ const missionSnap = await getDocs(query(collection(db, 'missions'), where('__name__', '==', missionId)));
121
+
122
+ if (missionSnap.empty) {
123
+ spinner.fail('Mission not found');
124
+ console.error(chalk.red(`✗ Mission ${missionId} not found`));
125
+ return;
126
+ }
127
+
128
+ const missionData = missionSnap.docs[0].data();
129
+
130
+ spinner.update('Generating SEO-optimized page');
131
+ await sleep(500);
132
+
133
+ // Generate slug from mission topic
134
+ const slug = (missionData.message || missionId)
135
+ .toLowerCase()
136
+ .replace(/[^a-z0-9]+/g, '-')
137
+ .replace(/^-|-$/g, '')
138
+ .substring(0, 60) + '-' + Date.now().toString(36);
139
+
140
+ spinner.update('Adding metadata and tags');
141
+ await sleep(400);
142
+
143
+ spinner.update('Submitting to Google for indexing');
144
+ await sleep(600);
145
+
146
+ spinner.update('Enabling revenue tracking');
147
+ await sleep(400);
148
+
149
+ // Update mission in Firestore
150
+ await updateDoc(missionRef, {
151
+ isPublished: true,
152
+ publishedAt: new Date(),
153
+ slug: slug,
154
+ views: 0,
155
+ downloads: 0,
156
+ citations: 0,
157
+ earnings: 0,
158
+ authorName: missionData.authorName || 'Anonymous Researcher',
159
+ authorEmail: missionData.authorEmail || 'unknown@example.com'
160
+ });
161
+
162
+ spinner.succeed('Research published successfully!');
88
163
 
89
- // Generate URL
90
- const slug = missionId.toLowerCase().replace(/[^a-z0-9]+/g, '-').substring(0, 60);
91
- const url = `https://x.omnibiofex.cloud/research/${slug}`;
164
+ const url = `https://x.omnibiofex.cloud/research/${slug}`;
92
165
 
93
- console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
94
- console.log(chalk.white.bold('✅ PUBLICATION DETAILS'));
95
- console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
166
+ console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
167
+ console.log(chalk.white.bold('✅ PUBLICATION DETAILS'));
168
+ console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
96
169
 
97
- console.log(chalk.white(`📄 Mission ID: ${chalk.hex('#F24E1E')(missionId)}`));
98
- console.log(chalk.white(`🔗 Public URL: ${chalk.blue.underline(url)}`));
99
- console.log(chalk.white(`💰 Revenue Share: ${chalk.green('80%')} of all ad revenue`));
100
- console.log(chalk.white(`🔍 Google Indexing: ${chalk.green('Requested')} (24 hours)`));
101
- console.log(chalk.white(`📊 Analytics: ${chalk.green('Enabled')}`));
170
+ console.log(chalk.white(`📄 Mission ID: ${chalk.hex('#F24E1E')(missionId)}`));
171
+ console.log(chalk.white(`🔗 Public URL: ${chalk.blue.underline(url)}`));
172
+ console.log(chalk.white(`💰 Revenue Share: ${chalk.green('80%')} of all ad revenue`));
173
+ console.log(chalk.white(`🔍 Google Indexing: ${chalk.green('Requested')} (24 hours)`));
174
+ console.log(chalk.white(`📊 Analytics: ${chalk.green('Enabled')}`));
102
175
 
103
- console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
104
- console.log(chalk.white.bold('💰 START EARNING'));
105
- console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
176
+ console.log(chalk.hex('#F24E1E')('\n═══════════════════════════════════════════════════════════'));
177
+ console.log(chalk.white.bold('💰 START EARNING'));
178
+ console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
106
179
 
107
- console.log(chalk.gray('Your research is now live! Here\'s what happens next:'));
108
- console.log(chalk.white('\n ✓ Google indexes your research within 24 hours'));
109
- console.log(chalk.white(' ✓ Readers discover it through search'));
110
- console.log(chalk.white(' ✓ Ads are displayed to readers'));
111
- console.log(chalk.white(' ✓ You earn 80% of all ad revenue'));
112
- console.log(chalk.white(' ✓ Monthly payouts to your account\n'));
180
+ console.log(chalk.gray('Your research is now live! Here\'s what happens next:'));
181
+ console.log(chalk.white('\n ✓ Google indexes your research within 24 hours'));
182
+ console.log(chalk.white(' ✓ Readers discover it through search'));
183
+ console.log(chalk.white(' ✓ Ads are displayed to readers'));
184
+ console.log(chalk.white(' ✓ You earn 80% of all ad revenue'));
185
+ console.log(chalk.white(' ✓ Monthly payouts to your account\n'));
113
186
 
114
- console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
187
+ console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
115
188
 
116
- const { nextAction } = await inquirer.prompt([
117
- {
118
- type: 'list',
119
- name: 'nextAction',
120
- message: 'What would you like to do next?',
121
- choices: [
122
- { name: '📊 View earnings dashboard', value: 'earnings' },
123
- { name: '📤 Publish another research', value: 'publish' },
124
- { name: '🏠 Open web dashboard', value: 'dashboard' },
125
- { name: '✅ Done', value: 'done' }
126
- ]
127
- }
128
- ]);
129
-
130
- if (nextAction === 'earnings') {
131
- const { earnings } = require('./earnings');
132
- await earnings();
133
- } else if (nextAction === 'publish') {
134
- await publish();
135
- } else if (nextAction === 'dashboard') {
136
- const open = require('open');
137
- await open('https://x.omnibiofex.cloud/dash');
138
- console.log(chalk.green('\n✓ Opened web dashboard in your browser\n'));
189
+ } catch (error) {
190
+ spinner.fail('Failed to publish research');
191
+ console.error(chalk.red(error.message));
139
192
  }
140
193
  }
141
194