@telestack/storage 1.2.0 → 1.3.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/README.md +83 -84
- package/dist/index.d.mts +597 -116
- package/dist/index.d.ts +597 -116
- package/dist/index.global.js +1 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -1,41 +1,26 @@
|
|
|
1
1
|
# TelestackStorage Web SDK
|
|
2
2
|
|
|
3
3
|
A powerful, fluent, and comprehensive client SDK for TelestackStorage.
|
|
4
|
-
Designed
|
|
4
|
+
Designed to be **fast, capable, and easy to use** for modern web storage workflows.
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## 🌊 Core Philosophy
|
|
7
|
+
TelestackStorage is an **S3-compatible storage gateway** with metadata, search, analytics, and realtime events.
|
|
8
|
+
|
|
9
|
+
## Features
|
|
7
10
|
|
|
8
11
|
- 🌊 **Fluent Directory & File References** (`storage.ref('path').child('video.mp4')`)
|
|
9
12
|
- 📈 **Observable Upload Tasks**: Built directly around progress observers, pausing, resuming, and canceling `uploadTask.on('state_changed', ...)`
|
|
10
|
-
- 🚀 **
|
|
11
|
-
- 🗂️ **Rich Querying**:
|
|
12
|
-
- 📦 **Mass Batch Operations**: Instantly delete, copy, or move multiple files
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
## 🚀 Standalone Installation (CDN)
|
|
19
|
-
|
|
20
|
-
You can use Telestack Storage as a completely standalone library directly in HTML:
|
|
21
|
-
|
|
22
|
-
```html
|
|
23
|
-
<script src="https://unpkg.com/@telestack/storage/dist/index.global.js"></script>
|
|
24
|
-
<script>
|
|
25
|
-
// The SDK is exposed globally as `TelestackStorageSetup.TelestackStorage`
|
|
26
|
-
const { TelestackStorage } = window.TelestackStorageSetup;
|
|
27
|
-
|
|
28
|
-
const storage = new TelestackStorage({
|
|
29
|
-
baseUrl: 'https://storage.yourdomain.com',
|
|
30
|
-
tenantId: 'your_tenant_id',
|
|
31
|
-
apiKey: 'your_api_key'
|
|
32
|
-
});
|
|
33
|
-
</script>
|
|
34
|
-
```
|
|
13
|
+
- 🚀 **Smart Upload Logic**: Uses standard uploads or resumable multipart uploads based on file size and runtime behavior.
|
|
14
|
+
- 🗂️ **Rich Querying**: Multi-criteria file searching using the fluent `query()` builder.
|
|
15
|
+
- 📦 **Mass Batch Operations**: Instantly delete, copy, or move multiple files in one asynchronous background request.
|
|
16
|
+
- 🌐 **Zero Dependencies**, fully browser native.
|
|
17
|
+
- 🧠 **Context-Aware Client**: Switch tenant/project/org defaults using `withContext(...)`.
|
|
18
|
+
- 🔐 **Auth Hot-Swap**: Rotate API keys or user JWTs without rebuilding client state via `withAuth(...)`.
|
|
19
|
+
- 🛡️ **Idempotent Provisioning**: `createBucketIfMissing(...)` prevents onboarding races.
|
|
35
20
|
|
|
36
21
|
---
|
|
37
22
|
|
|
38
|
-
## 📦
|
|
23
|
+
## 📦 Installation
|
|
39
24
|
|
|
40
25
|
```bash
|
|
41
26
|
npm install @telestack/storage
|
|
@@ -43,38 +28,78 @@ npm install @telestack/storage
|
|
|
43
28
|
|
|
44
29
|
---
|
|
45
30
|
|
|
46
|
-
##
|
|
47
|
-
|
|
48
|
-
### 1. Observable Uploads (Pause, Resume, Cancel)
|
|
31
|
+
## 🚀 Usage
|
|
49
32
|
|
|
50
|
-
|
|
33
|
+
### 1. Initialization
|
|
34
|
+
Initialize with your regional worker URL and tenant ID.
|
|
51
35
|
|
|
52
36
|
```typescript
|
|
53
37
|
import { TelestackStorage } from '@telestack/storage';
|
|
54
38
|
|
|
55
39
|
const storage = new TelestackStorage({
|
|
56
40
|
baseUrl: 'https://api.yourdomain.com',
|
|
57
|
-
tenantId: '
|
|
41
|
+
tenantId: 'your_tenant_id',
|
|
42
|
+
apiKey: 'your_api_key' // Optional
|
|
43
|
+
});
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### 2. Direct Bucket Creation (UI / Console)
|
|
47
|
+
Create a project bucket directly from your UI when the user signs up.
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const storage = new TelestackStorage({
|
|
51
|
+
baseUrl: 'https://api.yourdomain.com',
|
|
52
|
+
tenantId: 'project_123',
|
|
53
|
+
orgId: 'org_456',
|
|
54
|
+
apiKey: 'your_api_key'
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
const bucket = await storage.createBucket('project-bucket');
|
|
58
|
+
console.log('Created bucket ID:', bucket.bucketId);
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### 3. Multi-Tenant DX (Context + Auth in one line)
|
|
62
|
+
Use cloned clients for each workspace/user session while preserving the same API style.
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
const admin = new TelestackStorage({
|
|
66
|
+
baseUrl: 'https://api.yourdomain.com',
|
|
67
|
+
tenantId: 'tenant_root',
|
|
68
|
+
projectId: 'project_default',
|
|
69
|
+
orgId: 'org_default',
|
|
70
|
+
apiKey: 'admin_key'
|
|
58
71
|
});
|
|
59
72
|
|
|
60
|
-
const
|
|
61
|
-
|
|
73
|
+
const tenantClient = admin
|
|
74
|
+
.withContext({ tenantId: 'project_789', projectId: 'project_789', orgId: 'org_456' })
|
|
75
|
+
.withAuth({ token: userJwt, apiKey: null });
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### 4. Idempotent Bucket Provisioning (No Duplicate Errors)
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const result = await storage.createBucketIfMissing('project-bucket');
|
|
82
|
+
|
|
83
|
+
if (result.created) {
|
|
84
|
+
console.log('New bucket:', result.bucketId);
|
|
85
|
+
} else {
|
|
86
|
+
console.log('Bucket already exists for project:', result.projectId);
|
|
87
|
+
}
|
|
88
|
+
```
|
|
62
89
|
|
|
63
|
-
|
|
64
|
-
|
|
90
|
+
### 5. Observable Uploads (Pause, Resume, Cancel)
|
|
91
|
+
Works like familiar cloud-storage SDKs with resumable upload controls.
|
|
92
|
+
|
|
93
|
+
```typescript
|
|
94
|
+
const task = storage.ref('videos/concert.mp4').put(videoBlob);
|
|
95
|
+
|
|
96
|
+
task.on('state_changed',
|
|
65
97
|
(snapshot) => {
|
|
66
|
-
// Observers receive exact byte counts and state ('running', 'paused', etc.)
|
|
67
98
|
const progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
|
|
68
99
|
console.log(`Upload is ${progress}% done. State: ${snapshot.state}`);
|
|
69
100
|
},
|
|
70
|
-
(error) =>
|
|
71
|
-
|
|
72
|
-
},
|
|
73
|
-
() => {
|
|
74
|
-
console.log('Upload completed successfully!');
|
|
75
|
-
// Get the download URL directly from the ref
|
|
76
|
-
task.snapshot.task.ref.getDownloadUrl().then(url => console.log('File available at:', url));
|
|
77
|
-
}
|
|
101
|
+
(error) => console.error('Upload failed:', error),
|
|
102
|
+
() => console.log('Upload completed!')
|
|
78
103
|
);
|
|
79
104
|
|
|
80
105
|
// Control it!
|
|
@@ -83,50 +108,24 @@ task.resume();
|
|
|
83
108
|
task.cancel();
|
|
84
109
|
```
|
|
85
110
|
|
|
86
|
-
###
|
|
87
|
-
|
|
88
|
-
No more paginating basic lists manually to find a single file. Search by name or filter by metadata effortlessly:
|
|
111
|
+
### 6. Fluent Query Builder (Search & Filtering)
|
|
112
|
+
Search by name or filter by file extension effortlessly:
|
|
89
113
|
|
|
90
114
|
```typescript
|
|
91
115
|
const files = await storage.query()
|
|
92
|
-
.
|
|
93
|
-
.
|
|
116
|
+
.search('report')
|
|
117
|
+
.withExtension('pdf')
|
|
118
|
+
.minSize(1024 * 1024) // 1MB+
|
|
94
119
|
.limit(20)
|
|
95
120
|
.get();
|
|
96
121
|
```
|
|
97
122
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
Perform mass directory operations securely with a single API call (executed asynchronously on Cloudflare):
|
|
101
|
-
|
|
102
|
-
```typescript
|
|
103
|
-
// Delete multiple files instantly
|
|
104
|
-
await storage.batch()
|
|
105
|
-
.delete(['old/1.png', 'old/2.png'])
|
|
106
|
-
.run();
|
|
107
|
-
|
|
108
|
-
// Move/Rename hundreds of files effortlessly
|
|
109
|
-
await storage.batch()
|
|
110
|
-
.move(['docs/a.pdf', 'docs/b.pdf'], 'archive/')
|
|
111
|
-
.run();
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### 4. Enterprise Compliance Features
|
|
115
|
-
|
|
116
|
-
Storage versioning, tagging & immutable legal holds are built natively into the fluent refs:
|
|
117
|
-
|
|
118
|
-
```typescript
|
|
119
|
-
const docRef = storage.ref('critical-contracts/nda.pdf');
|
|
120
|
-
|
|
121
|
-
// Retrieve a previously overwritten historical version
|
|
122
|
-
const url = await docRef.getVersionUrl('v3_abc123');
|
|
123
|
+
---
|
|
123
124
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
]);
|
|
125
|
+
## 📊 Developer Perks
|
|
126
|
+
- **S3-compatible durability** with presigned URL workflows.
|
|
127
|
+
- **Resumable multipart uploads** for large files.
|
|
128
|
+
- **Auto-Sync**: Real-time SSE events across tabs/sessions.
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
```
|
|
130
|
+
---
|
|
131
|
+
*Verified production-ready for modern web storage workloads.*
|