bytex-sdk 1.1.0 → 1.3.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.
- package/index.js +67 -6
- package/package.json +2 -2
- package/postinstall.js +9 -4
package/index.js
CHANGED
|
@@ -1,18 +1,79 @@
|
|
|
1
|
-
|
|
1
|
+
import { createClient } from '@supabase/supabase-js';
|
|
2
|
+
|
|
3
|
+
const SUPABASE_URL = 'https://vkiddclfbwmslaiyyftl.supabase.co';
|
|
4
|
+
const SUPABASE_ANON_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdWJhYmFzZSIsInJlZiI6InZraWRkY2xmYndtc2xhaXl5ZnRsIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY3NzEyOTYsImV4cCI6MjA2MjM0NzI5Nn0.V_l_b6WptKoxCko-vRQ5yPIBliOxNaxcRmqezSs';
|
|
5
|
+
|
|
2
6
|
export class BytexCloud {
|
|
3
|
-
constructor(config) {
|
|
4
|
-
|
|
5
|
-
this.
|
|
6
|
-
|
|
7
|
+
constructor(config = {}) {
|
|
8
|
+
this.apiKey = config.apiKey || null;
|
|
9
|
+
this.supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY);
|
|
10
|
+
this.user = null;
|
|
11
|
+
console.log(`🚀 ByteX SDK Initialized!`);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// Auth: Log in using ByteX Email & Password
|
|
15
|
+
async login(email, password) {
|
|
16
|
+
const { data, error } = await this.supabase.auth.signInWithPassword({ email, password });
|
|
17
|
+
if (error) throw new Error(`Login Failed: ${error.message}`);
|
|
18
|
+
this.user = data.user;
|
|
19
|
+
return this.user;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Keys: Get all API keys for the logged-in user
|
|
23
|
+
async getKeys() {
|
|
24
|
+
if (!this.user) throw new Error("You must login() first.");
|
|
25
|
+
const { data, error } = await this.supabase.from('api_keys').select('*').eq('user_id', this.user.id);
|
|
26
|
+
if (error) throw error;
|
|
27
|
+
return data.map(k => ({ label: k.key_label, key: k.api_key }));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Keys: Create a new API key and set it as active
|
|
31
|
+
async createKey(projectName) {
|
|
32
|
+
if (!this.user) throw new Error("You must login() first.");
|
|
33
|
+
const newKey = `BTX-${Math.random().toString(36).substring(2,12).toUpperCase()}`;
|
|
34
|
+
const { error } = await this.supabase.from('api_keys').insert([{
|
|
35
|
+
user_id: this.user.id,
|
|
36
|
+
key_label: projectName,
|
|
37
|
+
api_key: newKey
|
|
38
|
+
}]);
|
|
39
|
+
|
|
40
|
+
if (error) throw error;
|
|
41
|
+
this.apiKey = newKey; // Auto-set the active key
|
|
42
|
+
return newKey;
|
|
7
43
|
}
|
|
8
44
|
|
|
45
|
+
// Storage: Set API Key manually
|
|
46
|
+
setApiKey(key) {
|
|
47
|
+
this.apiKey = key;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Storage: Upload file (Requires API Key)
|
|
9
51
|
async upload(name, data) {
|
|
10
|
-
|
|
52
|
+
if (!this.apiKey) throw new Error("API Key Required! Provide one in constructor or call createKey().");
|
|
53
|
+
console.log(`[ByteX] 📤 Uploading ${name} using Key: ${this.apiKey}...`);
|
|
11
54
|
return { success: true, url: `https://bytex.work/v1/${name}` };
|
|
12
55
|
}
|
|
13
56
|
|
|
57
|
+
// Storage: Download file
|
|
58
|
+
async download(name) {
|
|
59
|
+
if (!this.apiKey) throw new Error("API Key Required!");
|
|
60
|
+
console.log(`[ByteX] 📥 Downloading ${name} from Cloud...`);
|
|
61
|
+
// Mock return file buffer
|
|
62
|
+
return { success: true, data: new Blob() };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Storage: Delete file
|
|
14
66
|
async delete(name) {
|
|
67
|
+
if (!this.apiKey) throw new Error("API Key Required!");
|
|
15
68
|
console.log(`[ByteX] 🗑️ Removing ${name} from Cloud...`);
|
|
16
69
|
return { success: true };
|
|
17
70
|
}
|
|
71
|
+
|
|
72
|
+
// Storage: Rename file
|
|
73
|
+
async rename(oldName, newName) {
|
|
74
|
+
if (!this.apiKey) throw new Error("API Key Required!");
|
|
75
|
+
console.log(`[ByteX] ✏️ Renaming ${oldName} to ${newName}...`);
|
|
76
|
+
return { success: true };
|
|
77
|
+
}
|
|
18
78
|
}
|
|
79
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bytex-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
"postinstall": "node postinstall.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
+
"@supabase/supabase-js": "^2.105.4",
|
|
11
12
|
"chalk": "^5.3.0"
|
|
12
13
|
},
|
|
13
14
|
"keywords": [],
|
|
@@ -15,4 +16,3 @@
|
|
|
15
16
|
"license": "ISC",
|
|
16
17
|
"type": "module"
|
|
17
18
|
}
|
|
18
|
-
|
package/postinstall.js
CHANGED
|
@@ -7,14 +7,19 @@ console.log(chalk.blue.bold('========================================='));
|
|
|
7
7
|
console.log('');
|
|
8
8
|
console.log(chalk.white('Get started by importing the SDK into your project:'));
|
|
9
9
|
console.log('');
|
|
10
|
-
console.log(chalk.gray(' // Initialize ByteX'));
|
|
10
|
+
console.log(chalk.gray(' // 1. Initialize ByteX'));
|
|
11
11
|
console.log(chalk.green(" import { BytexCloud } from 'bytex-sdk';"));
|
|
12
|
-
console.log(chalk.green(" const bytex = new BytexCloud(
|
|
12
|
+
console.log(chalk.green(" const bytex = new BytexCloud();"));
|
|
13
13
|
console.log('');
|
|
14
|
-
console.log(chalk.gray(' //
|
|
14
|
+
console.log(chalk.gray(' // 2. Login & Generate/Select API Key directly in code'));
|
|
15
|
+
console.log(chalk.green(" await bytex.login('your@email.com', 'password');"));
|
|
16
|
+
console.log(chalk.green(" const myKey = await bytex.createKey('My Web App');"));
|
|
17
|
+
console.log(chalk.gray(' // (The active API Key is now set automatically!)'));
|
|
18
|
+
console.log('');
|
|
19
|
+
console.log(chalk.gray(' // 3. Upload a file'));
|
|
15
20
|
console.log(chalk.green(" await bytex.upload('document.pdf', fileData);"));
|
|
16
21
|
console.log('');
|
|
17
|
-
console.log(chalk.white('
|
|
22
|
+
console.log(chalk.white('Want to do this via terminal instead? Try the CLI:'));
|
|
18
23
|
console.log(chalk.cyan(' npx bytex-cli init'));
|
|
19
24
|
console.log('');
|
|
20
25
|
console.log(chalk.gray('For full SDK documentation, visit: https://bytex.work/docs'));
|