bytex-sdk 2.0.0 → 5.0.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/README.md +30 -41
- package/package.json +17 -12
- package/{index.js → src/index.js} +30 -50
- package/postinstall.js +0 -26
package/README.md
CHANGED
|
@@ -1,56 +1,45 @@
|
|
|
1
|
-
# ByteX SDK
|
|
2
|
-
> The official SDK for the ByteX Cloud Ecosystem.
|
|
1
|
+
# ByteX Cloud SDK 🚀
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
The official SDK for the ByteX ecosystem, enabling developers to build professional "Super SaaS" products with 100% cloud sovereignty (BYOC).
|
|
5
4
|
|
|
6
|
-
##
|
|
7
|
-
- **
|
|
8
|
-
- **
|
|
9
|
-
- **
|
|
10
|
-
- **
|
|
11
|
-
- **Middleware System**: Intercept and optimize uploads (e.g., auto-convert to WebP).
|
|
12
|
-
- **Bulk Operations**: Download or export entire projects as ZIP.
|
|
5
|
+
## Features
|
|
6
|
+
- 🔐 **Secure Authentication**: Integrated with Supabase.
|
|
7
|
+
- 📦 **Data Persistence**: Upload and download streams directly to your own Cloud (HuggingFace).
|
|
8
|
+
- 🕵️♂️ **X-Ray Diagnostics**: Built-in network and infrastructure health checks.
|
|
9
|
+
- ⚡ **Lightweight**: Zero-config needed for most use cases.
|
|
13
10
|
|
|
14
|
-
##
|
|
11
|
+
## Installation
|
|
15
12
|
```bash
|
|
16
|
-
npm install bytex-sdk
|
|
13
|
+
npm install @bytex/cloud-sdk
|
|
17
14
|
```
|
|
18
15
|
|
|
19
|
-
##
|
|
16
|
+
## Quick Start
|
|
17
|
+
|
|
18
|
+
### Initialize
|
|
20
19
|
```javascript
|
|
21
|
-
import { BytexCloud } from 'bytex-sdk';
|
|
20
|
+
import { BytexCloud } from '@bytex/cloud-sdk';
|
|
21
|
+
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const bytex = new BytexCloud({
|
|
24
|
+
apiKey: 'YOUR_API_KEY',
|
|
25
|
+
workerUrl: 'https://api.bytex.work/',
|
|
26
|
+
storage: AsyncStorage // for React Native
|
|
27
27
|
});
|
|
28
|
-
|
|
29
|
-
// Upload a file
|
|
30
|
-
await bytex.upload('hello.txt', 'Hello World');
|
|
31
|
-
|
|
32
|
-
// Get a streaming URL
|
|
33
|
-
const streamUrl = bytex.stream('video.mp4');
|
|
34
|
-
|
|
35
|
-
// List files
|
|
36
|
-
const files = await bytex.listFiles();
|
|
37
|
-
console.log(files);
|
|
38
28
|
```
|
|
39
29
|
|
|
40
|
-
|
|
30
|
+
### Upload Data
|
|
41
31
|
```javascript
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// Automatically optimize images to WebP before upload
|
|
47
|
-
bytex.use(BytexMiddlewares.imageOptimizer(0.8));
|
|
48
|
-
|
|
49
|
-
await bytex.upload('photo.jpg', fileData); // Uploads as photo.webp
|
|
32
|
+
await bytex.uploadData('my_project', {
|
|
33
|
+
status: 'active',
|
|
34
|
+
users: 1000
|
|
35
|
+
});
|
|
50
36
|
```
|
|
51
37
|
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
### Infrastructure Health Check (X-Ray)
|
|
39
|
+
```javascript
|
|
40
|
+
const report = await bytex.xray();
|
|
41
|
+
console.log(report.checks);
|
|
42
|
+
```
|
|
54
43
|
|
|
55
|
-
##
|
|
56
|
-
|
|
44
|
+
## License
|
|
45
|
+
MIT © ByteX Guru
|
package/package.json
CHANGED
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bytex-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "",
|
|
5
|
-
"main": "index.js",
|
|
3
|
+
"version": "5.0.0",
|
|
4
|
+
"description": "The official ByteX Cloud SDK for BYOC (Bring Your Own Cloud) infrastructure management.",
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
"postinstall": "node postinstall.js"
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
8
|
},
|
|
9
|
+
"keywords": [
|
|
10
|
+
"bytex",
|
|
11
|
+
"cloud",
|
|
12
|
+
"saas",
|
|
13
|
+
"byoc",
|
|
14
|
+
"supabase",
|
|
15
|
+
"huggingface"
|
|
16
|
+
],
|
|
17
|
+
"author": "ByteX Guru",
|
|
18
|
+
"license": "MIT",
|
|
10
19
|
"dependencies": {
|
|
11
|
-
"@supabase/supabase-js": "^2.
|
|
12
|
-
"
|
|
13
|
-
}
|
|
14
|
-
"keywords": [],
|
|
15
|
-
"author": "",
|
|
16
|
-
"license": "ISC",
|
|
17
|
-
"type": "module"
|
|
20
|
+
"@supabase/supabase-js": "^2.39.0",
|
|
21
|
+
"react-native-url-polyfill": "^2.0.0"
|
|
22
|
+
}
|
|
18
23
|
}
|
|
@@ -21,23 +21,20 @@ export class BytexCloud {
|
|
|
21
21
|
supabaseConfig.auth.storage = config.storage;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
this.supabase = createClient(
|
|
24
|
+
this.supabase = createClient(SUPABASE_URL, SUPABASE_ANON_KEY, supabaseConfig);
|
|
25
25
|
this._listeners = {};
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
async _execute(fn, actionName) {
|
|
28
|
+
async _execute(fn, action) {
|
|
30
29
|
try {
|
|
31
30
|
return await fn();
|
|
32
31
|
} catch (e) {
|
|
33
|
-
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
throw new Error(`${actionName} failed: ${e.message}${advice}`);
|
|
32
|
+
const diag = await this.xray();
|
|
33
|
+
const advice = diag.advice.length > 0 ? `\n[X-RAY Advice]: ${diag.advice.join(' ')}` : '';
|
|
34
|
+
throw new Error(`${action} failed: ${e.message}${advice}`);
|
|
37
35
|
}
|
|
38
36
|
}
|
|
39
37
|
|
|
40
|
-
// --- CORE METHODS (ENHANCED WITH AUTO X-RAY) ---
|
|
41
38
|
async login(email, password) {
|
|
42
39
|
return this._execute(async () => {
|
|
43
40
|
const { data, error } = await this.supabase.auth.signInWithPassword({ email, password });
|
|
@@ -46,13 +43,25 @@ export class BytexCloud {
|
|
|
46
43
|
}, 'Login');
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
async
|
|
46
|
+
async uploadData(name, data) {
|
|
50
47
|
return this._execute(async () => {
|
|
51
48
|
this._requireKey();
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
49
|
+
const streamName = name.endsWith('.btx') ? name : `${name}.stream.btx`;
|
|
50
|
+
const url = `${this.workerUrl}?action=upload&key=${this.apiKey}&file=${encodeURIComponent(streamName)}`;
|
|
51
|
+
const { data: { session } } = await this.supabase.auth.getSession();
|
|
52
|
+
|
|
53
|
+
const payload = typeof data === 'string' ? data : JSON.stringify(data);
|
|
54
|
+
|
|
55
|
+
const res = await fetch(url, {
|
|
56
|
+
method: 'POST',
|
|
57
|
+
headers: {
|
|
58
|
+
'Authorization': `Bearer ${session?.access_token || ''}`,
|
|
59
|
+
'Content-Type': 'application/json'
|
|
60
|
+
},
|
|
61
|
+
body: payload
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
if (!res.ok) throw new Error(`Upload failed with status ${res.status}`);
|
|
56
65
|
return await res.json();
|
|
57
66
|
}, 'Upload');
|
|
58
67
|
}
|
|
@@ -63,59 +72,30 @@ export class BytexCloud {
|
|
|
63
72
|
const streamName = name.endsWith('.btx') ? name : `${name}.stream.btx`;
|
|
64
73
|
const url = `${this.workerUrl}?action=view&key=${this.apiKey}&file=${encodeURIComponent(streamName)}&_cb=${Date.now()}`;
|
|
65
74
|
const { data: { session } } = await this.supabase.auth.getSession();
|
|
66
|
-
const res = await fetch(url, {
|
|
75
|
+
const res = await fetch(url, {
|
|
76
|
+
headers: { 'Authorization': `Bearer ${session?.access_token || ''}` }
|
|
77
|
+
});
|
|
67
78
|
if (!res.ok) throw new Error(`Status ${res.status}`);
|
|
68
79
|
const text = await res.text();
|
|
69
80
|
try { return JSON.parse(text); } catch (e) { return text.split('\n').filter(Boolean).map(line => JSON.parse(line)); }
|
|
70
81
|
}, 'Download');
|
|
71
82
|
}
|
|
72
83
|
|
|
73
|
-
async delete(name) {
|
|
74
|
-
return this._execute(async () => {
|
|
75
|
-
this._requireKey();
|
|
76
|
-
const streamName = name.endsWith('.btx') ? name : `${name}.stream.btx`;
|
|
77
|
-
const { data: { session } } = await this.supabase.auth.getSession();
|
|
78
|
-
const res = await fetch(`${this.workerUrl}?action=delete&key=${this.apiKey}&file=${encodeURIComponent(streamName)}`, {
|
|
79
|
-
method: 'DELETE',
|
|
80
|
-
headers: { 'Authorization': `Bearer ${session?.access_token || ''}` }
|
|
81
|
-
});
|
|
82
|
-
if (!res.ok) throw new Error(`Status ${res.status}`);
|
|
83
|
-
return true;
|
|
84
|
-
}, 'Delete');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* ByteX X-RAY v2.5 (Self-Healing Diagnostic)
|
|
89
|
-
*/
|
|
90
84
|
async xray() {
|
|
91
|
-
const report = { timestamp: new Date().toISOString(),
|
|
85
|
+
const report = { timestamp: new Date().toISOString(), checks: {}, advice: [] };
|
|
92
86
|
const { data: { session } } = await this.supabase.auth.getSession();
|
|
93
87
|
|
|
94
|
-
// 1. Connectivity Check
|
|
95
|
-
const start = Date.now();
|
|
96
88
|
try {
|
|
97
89
|
const res = await fetch(`${this.workerUrl}?action=list&key=${this.apiKey}`);
|
|
98
90
|
report.checks.connectivity = res.ok ? 'OK' : 'ERROR';
|
|
99
|
-
report.latency = Date.now() - start;
|
|
100
91
|
} catch (e) {
|
|
101
92
|
report.checks.connectivity = 'OFFLINE';
|
|
102
|
-
report.advice.push('ByteX Cloud
|
|
93
|
+
report.advice.push('ByteX Cloud unreachable. Check internet connection.');
|
|
103
94
|
}
|
|
104
95
|
|
|
105
|
-
|
|
106
|
-
if (!
|
|
107
|
-
|
|
108
|
-
report.advice.push('No API Key detected. Please provide an apiKey in the constructor.');
|
|
109
|
-
} else { report.checks.api_key = 'OK'; }
|
|
110
|
-
|
|
111
|
-
// 3. Auth Check
|
|
112
|
-
report.checks.auth = session ? 'AUTHENTICATED' : 'GUEST';
|
|
113
|
-
if (!session) report.advice.push('User is not logged in. Some operations may fail.');
|
|
114
|
-
|
|
115
|
-
// 4. Platform Audit (Mobile/Web)
|
|
116
|
-
if (!this.config.storage && typeof navigator !== 'undefined') {
|
|
117
|
-
report.advice.push('Storage engine (AsyncStorage) is missing. Sessions will not persist.');
|
|
118
|
-
}
|
|
96
|
+
if (!this.apiKey) report.advice.push('API Key is missing.');
|
|
97
|
+
if (!session) report.advice.push('User is not logged in.');
|
|
98
|
+
if (!this.config.storage) report.advice.push('AsyncStorage engine is missing.');
|
|
119
99
|
|
|
120
100
|
return report;
|
|
121
101
|
}
|
package/postinstall.js
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import chalk from 'chalk';
|
|
2
|
-
|
|
3
|
-
console.log('');
|
|
4
|
-
console.log(chalk.blue.bold('========================================='));
|
|
5
|
-
console.log(chalk.cyan.bold(' 🚀 Successfully installed ByteX SDK!'));
|
|
6
|
-
console.log(chalk.blue.bold('========================================='));
|
|
7
|
-
console.log('');
|
|
8
|
-
console.log(chalk.white('Get started by importing the SDK into your project:'));
|
|
9
|
-
console.log('');
|
|
10
|
-
console.log(chalk.gray(' // 1. Initialize ByteX'));
|
|
11
|
-
console.log(chalk.green(" import { BytexCloud } from 'bytex-sdk';"));
|
|
12
|
-
console.log(chalk.green(" const bytex = new BytexCloud();"));
|
|
13
|
-
console.log('');
|
|
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'));
|
|
20
|
-
console.log(chalk.green(" await bytex.upload('document.pdf', fileData);"));
|
|
21
|
-
console.log('');
|
|
22
|
-
console.log(chalk.white('Want to do this via terminal instead? Try the CLI:'));
|
|
23
|
-
console.log(chalk.cyan(' npx bytex-cli init'));
|
|
24
|
-
console.log('');
|
|
25
|
-
console.log(chalk.gray('For full SDK documentation, visit: https://bytex.work/docs'));
|
|
26
|
-
console.log('');
|