@signskart/uploader 1.0.0 → 1.0.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 +179 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
# @signskart/uploader
|
|
2
|
+
|
|
3
|
+
Production-grade Upload Manager SDK by Signskart.
|
|
4
|
+
|
|
5
|
+
Features:
|
|
6
|
+
|
|
7
|
+
- 🚀 Upload queue
|
|
8
|
+
- 🔁 Retry logic with exponential backoff
|
|
9
|
+
- 📊 Real-time progress tracking
|
|
10
|
+
- ❌ Cancel uploads
|
|
11
|
+
- ⚡ Concurrency control
|
|
12
|
+
- ☁ Multi-provider support (S3, Cloudinary)
|
|
13
|
+
- 🧠 Fully typed (TypeScript)
|
|
14
|
+
- 🌍 Works with React, Vue, Next.js, Vite
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 📦 Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install @signskart/uploader
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
or
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
yarn add @signskart/uploader
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
# 🚀 Quick Start
|
|
33
|
+
|
|
34
|
+
## Using Amazon S3 (Presigned Upload)
|
|
35
|
+
|
|
36
|
+
```ts
|
|
37
|
+
import { UploadManager, S3Uploader } from '@signskart/uploader';
|
|
38
|
+
|
|
39
|
+
const uploader = new S3Uploader({
|
|
40
|
+
apiBaseUrl: 'https://api.yourbackend.com',
|
|
41
|
+
publicUrl: 'https://cdn.yoursite.com'
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const manager = new UploadManager(uploader, 2); // concurrency = 2
|
|
45
|
+
|
|
46
|
+
const task = manager.add({
|
|
47
|
+
file,
|
|
48
|
+
folder: 'designs'
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
task.events.subscribe((state) => {
|
|
52
|
+
console.log(state.progress, state.status);
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Using Cloudinary
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
import { UploadManager, CloudinaryUploader } from '@signskart/uploader';
|
|
62
|
+
|
|
63
|
+
const uploader = new CloudinaryUploader({
|
|
64
|
+
cloudName: 'your-cloud-name',
|
|
65
|
+
uploadPreset: 'unsigned-preset'
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
const manager = new UploadManager(uploader);
|
|
69
|
+
|
|
70
|
+
const task = manager.add({
|
|
71
|
+
file,
|
|
72
|
+
folder: 'designs'
|
|
73
|
+
});
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
---
|
|
77
|
+
|
|
78
|
+
# 🧠 API Reference
|
|
79
|
+
|
|
80
|
+
## UploadManager
|
|
81
|
+
|
|
82
|
+
```ts
|
|
83
|
+
new UploadManager(uploader, concurrency?)
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
### Parameters:
|
|
87
|
+
|
|
88
|
+
| Parameter | Type | Default |
|
|
89
|
+
|-----------|------|----------|
|
|
90
|
+
| uploader | BaseUploader | required |
|
|
91
|
+
| concurrency | number | 3 |
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
## UploadTask
|
|
96
|
+
|
|
97
|
+
Returned from:
|
|
98
|
+
|
|
99
|
+
```ts
|
|
100
|
+
const task = manager.add(options);
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Properties:
|
|
104
|
+
|
|
105
|
+
- `task.state`
|
|
106
|
+
- `task.events.subscribe()`
|
|
107
|
+
|
|
108
|
+
### Methods:
|
|
109
|
+
|
|
110
|
+
```ts
|
|
111
|
+
task.start()
|
|
112
|
+
task.cancel()
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Upload Options
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
{
|
|
121
|
+
file: File;
|
|
122
|
+
folder: string;
|
|
123
|
+
fileName?: string;
|
|
124
|
+
metadata?: Record<string, any>;
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
# 🔁 Retry Logic
|
|
131
|
+
|
|
132
|
+
- Automatic retry
|
|
133
|
+
- Exponential backoff
|
|
134
|
+
- Default max retries: 2
|
|
135
|
+
|
|
136
|
+
---
|
|
137
|
+
|
|
138
|
+
# ❌ Cancel Upload
|
|
139
|
+
|
|
140
|
+
```ts
|
|
141
|
+
task.cancel();
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
---
|
|
145
|
+
|
|
146
|
+
# 📊 Listen to Progress
|
|
147
|
+
|
|
148
|
+
```ts
|
|
149
|
+
task.events.subscribe((state) => {
|
|
150
|
+
console.log(state.progress);
|
|
151
|
+
});
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
---
|
|
155
|
+
|
|
156
|
+
# 🏗 Example React Usage
|
|
157
|
+
|
|
158
|
+
```tsx
|
|
159
|
+
const handleUpload = (file: File) => {
|
|
160
|
+
const task = manager.add({ file, folder: 'uploads' });
|
|
161
|
+
|
|
162
|
+
task.events.subscribe((state) => {
|
|
163
|
+
setProgress(state.progress);
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
---
|
|
169
|
+
|
|
170
|
+
# 🛠 Requirements
|
|
171
|
+
|
|
172
|
+
- Modern browser (AbortController support)
|
|
173
|
+
- Backend endpoint for S3 presign (if using S3)
|
|
174
|
+
|
|
175
|
+
---
|
|
176
|
+
|
|
177
|
+
# 📜 License
|
|
178
|
+
|
|
179
|
+
MIT © Signskart
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@signskart/uploader",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Production-grade upload manager SDK with queue, progress tracking, retry logic, and multi-provider support (S3, Cloudinary).",
|
|
5
5
|
"author": "Signskart",
|
|
6
6
|
"license": "MIT",
|
|
@@ -35,4 +35,4 @@
|
|
|
35
35
|
"tsup": "^8.0.0",
|
|
36
36
|
"typescript": "^5.0.0"
|
|
37
37
|
}
|
|
38
|
-
}
|
|
38
|
+
}
|