omnibiofex 2.8.1 → 2.8.2

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.1",
3
+ "version": "2.8.2",
4
4
  "description": "OmniBioFex X - The Autonomous Research Terminal for AI-powered research missions",
5
5
  "main": "bin/obx",
6
6
  "bin": {
package/src/auth.js CHANGED
@@ -3,22 +3,19 @@ const { URL } = require('url');
3
3
  const axios = require('axios');
4
4
  const chalk = require('chalk');
5
5
  const inquirer = require('inquirer');
6
- const { initializeApp } = require('firebase/app');
7
- const { getAuth, sendSignInLinkToEmail } = require('firebase/auth');
8
- const config = require('./config');
9
-
10
- const firebaseConfig = {
11
- apiKey: "AIzaSyDlgXId4pLlYqm-MDuhfz3dLH24KBRHkw8",
12
- authDomain: "omnibiofex-x.firebaseapp.com",
13
- projectId: "omnibiofex-x",
14
- storageBucket: "omnibiofex-x.firebasestorage.app",
15
- messagingSenderId: "292246591666",
16
- appId: "1:292246591666:web:a182851585e4b0f79511ab",
17
- measurementId: "G-RLQH7BDNHB"
18
- };
19
-
20
- const app = initializeApp(firebaseConfig);
21
- const auth = getAuth(app);
6
+ const Conf = require('conf');
7
+ const { sendSignInLinkToEmail } = require('firebase/auth');
8
+ const { app, auth, db } = require('./firebase');
9
+
10
+ // Use the shared auth instance
11
+ const config = new Conf({
12
+ projectName: 'omnibiofex',
13
+ schema: {
14
+ token: { type: 'string' },
15
+ refreshToken: { type: 'string' },
16
+ expiresAt: { type: 'number' }
17
+ }
18
+ });
22
19
 
23
20
  const LOCAL_PORT = 8765;
24
21
  const CALLBACK_PATH = '/auth/callback';
@@ -157,12 +154,10 @@ function startLocalServer() {
157
154
  console.log('Local server received request:', req.url);
158
155
 
159
156
  if (url.pathname === CALLBACK_PATH) {
160
- // 🔥 FIX: Properly decode URL parameters
161
157
  let token = url.searchParams.get('token');
162
158
  let refreshToken = url.searchParams.get('refreshToken');
163
159
  const error = url.searchParams.get('error');
164
160
 
165
- // 🔥 FIX: Replace spaces with + (URL decoding issue)
166
161
  if (token && token.includes(' ')) {
167
162
  console.log(chalk.yellow('⚠️ Token contains spaces, fixing...'));
168
163
  token = token.replace(/ /g, '+');
@@ -177,7 +172,6 @@ function startLocalServer() {
177
172
  console.log('Token length:', token.length);
178
173
  console.log('Token starts with:', token.substring(0, 20));
179
174
 
180
- // 🔥 Validate token format
181
175
  if (!token.startsWith('eyJ')) {
182
176
  console.error('✗ Invalid token format');
183
177
  res.writeHead(400, { 'Content-Type': 'text/html' });
@@ -279,8 +273,10 @@ async function refreshAuthToken() {
279
273
  try {
280
274
  console.log(chalk.gray('🔄 Refreshing authentication token...'));
281
275
 
276
+ const apiKey = app.options.apiKey; // Get API key from the shared Firebase app
277
+
282
278
  const response = await axios.post(
283
- `https://securetoken.googleapis.com/v1/token?key=${firebaseConfig.apiKey}`,
279
+ `https://securetoken.googleapis.com/v1/token?key=${apiKey}`,
284
280
  new URLSearchParams({
285
281
  grant_type: 'refresh_token',
286
282
  refresh_token: refreshToken
@@ -294,7 +290,6 @@ async function refreshAuthToken() {
294
290
 
295
291
  const { id_token, refresh_token, expires_in } = response.data;
296
292
 
297
- // 🔥 Validate new token
298
293
  if (!id_token || !id_token.startsWith('eyJ')) {
299
294
  throw new Error('Invalid token received from refresh endpoint');
300
295
  }
@@ -347,7 +342,6 @@ async function getAuthToken() {
347
342
  process.exit(1);
348
343
  }
349
344
 
350
- // 🔥 Validate token before returning
351
345
  if (!token.startsWith('eyJ')) {
352
346
  console.error(chalk.red('Stored token is corrupted. Please login again.'));
353
347
  config.delete('authToken');
@@ -1,22 +1,9 @@
1
1
  const chalk = require('chalk');
2
2
  const open = require('open');
3
3
  const { getAuthToken, isAuthenticated } = require('../auth');
4
+ const { db, auth } = require('../firebase');
4
5
  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);
6
+ const { collection, query, where, getDocs } = require('firebase/firestore');
20
7
 
21
8
  async function credits() {
22
9
  if (!isAuthenticated()) {
@@ -78,7 +65,6 @@ async function usage() {
78
65
  spinner.start();
79
66
 
80
67
  try {
81
- const auth = getAuth(app);
82
68
  const user = auth.currentUser;
83
69
 
84
70
  if (!user) {
@@ -1,21 +1,8 @@
1
1
  const chalk = require('chalk');
2
2
  const { getAuthToken, isAuthenticated } = require('../auth');
3
+ const { db, auth } = require('../firebase');
3
4
  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);
5
+ const { collection, query, where, orderBy, limit, getDocs } = require('firebase/firestore');
19
6
 
20
7
  async function earnings() {
21
8
  if (!isAuthenticated()) {
@@ -27,7 +14,6 @@ async function earnings() {
27
14
  spinner.start();
28
15
 
29
16
  try {
30
- const auth = getAuth(app);
31
17
  const user = auth.currentUser;
32
18
 
33
19
  if (!user) {
@@ -1,22 +1,9 @@
1
1
  const chalk = require('chalk');
2
2
  const inquirer = require('inquirer');
3
3
  const { getAuthToken, isAuthenticated } = require('../auth');
4
+ const { db, auth } = require('../firebase');
4
5
  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
+ const { collection, query, where, orderBy, limit, getDocs, doc, updateDoc } = require('firebase/firestore');
20
7
 
21
8
  async function publish(missionId) {
22
9
  if (!isAuthenticated()) {
@@ -28,8 +15,6 @@ async function publish(missionId) {
28
15
  console.log(chalk.white.bold('📤 PUBLISH RESEARCH'));
29
16
  console.log(chalk.hex('#F24E1E')('═══════════════════════════════════════════════════════════\n'));
30
17
 
31
- const token = await getAuthToken();
32
-
33
18
  // If no mission ID provided, fetch real missions from Firestore
34
19
  if (!missionId) {
35
20
  console.log(chalk.gray('Fetching your completed missions...\n'));
@@ -38,8 +23,6 @@ async function publish(missionId) {
38
23
  spinner.start();
39
24
 
40
25
  try {
41
- // Get authenticated user
42
- const auth = getAuth(app);
43
26
  const user = auth.currentUser;
44
27
 
45
28
  if (!user) {
@@ -117,6 +100,8 @@ async function publish(missionId) {
117
100
  try {
118
101
  spinner.update('Fetching mission data');
119
102
  const missionRef = doc(db, 'missions', missionId);
103
+
104
+ // Get the mission document
120
105
  const missionSnap = await getDocs(query(collection(db, 'missions'), where('__name__', '==', missionId)));
121
106
 
122
107
  if (missionSnap.empty) {
@@ -0,0 +1,25 @@
1
+ const { initializeApp, getApps } = require('firebase/app');
2
+ const { getAuth } = require('firebase/auth');
3
+ const { getFirestore } = require('firebase/firestore');
4
+
5
+ const firebaseConfig = {
6
+ apiKey: "AIzaSyDlgXId4pLlYqm-MDuhfz3dLH24KBRHkw8",
7
+ authDomain: "omnibiofex-x.firebaseapp.com",
8
+ projectId: "omnibiofex-x",
9
+ storageBucket: "omnibiofex-x.firebasestorage.app",
10
+ messagingSenderId: "292246591666",
11
+ appId: "1:292246591666:web:a182851585e4b0f79511ab"
12
+ };
13
+
14
+ // Initialize Firebase only once
15
+ let app;
16
+ if (getApps().length === 0) {
17
+ app = initializeApp(firebaseConfig);
18
+ } else {
19
+ app = getApps()[0];
20
+ }
21
+
22
+ const auth = getAuth(app);
23
+ const db = getFirestore(app);
24
+
25
+ module.exports = { app, auth, db };