@contello/uploader 8.16.0 → 8.17.0-next.1753180901
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/dist/index.d.ts +39 -3
- package/dist/index.js +340 -245
- package/dist/index.umd.cjs +3 -3
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,20 +1,51 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* ContelloUploader is a class for uploading files to a Contello server.
|
|
5
|
+
* It supports both WebSocket and HTTP transports.
|
|
6
|
+
*/
|
|
3
7
|
export declare class ContelloUploader {
|
|
4
8
|
private params;
|
|
5
9
|
constructor(params: ContelloUploaderParams);
|
|
6
10
|
upload(file: File, meta?: UploadAssetMetadata | undefined, options?: {
|
|
7
11
|
abort?: AbortSignal;
|
|
12
|
+
} | undefined): Promise<{
|
|
13
|
+
id: string;
|
|
14
|
+
}>;
|
|
15
|
+
uploadWithEvents(file: File, meta?: UploadAssetMetadata | undefined, options?: {
|
|
16
|
+
abort?: AbortSignal;
|
|
8
17
|
} | undefined): Observable<UploadAssetProgress | {
|
|
9
18
|
id: string;
|
|
10
19
|
}>;
|
|
11
20
|
}
|
|
12
21
|
|
|
13
22
|
export declare type ContelloUploaderParams = {
|
|
23
|
+
/**
|
|
24
|
+
* Base URL of the Contello server.
|
|
25
|
+
* Example: 'https://example.com'
|
|
26
|
+
*/
|
|
14
27
|
url: string;
|
|
28
|
+
/**
|
|
29
|
+
* Project identifier for the Contello project.
|
|
30
|
+
* Example: 'myProjectId'
|
|
31
|
+
*/
|
|
15
32
|
project: string;
|
|
33
|
+
/**
|
|
34
|
+
* Authentication token for the Contello API.
|
|
35
|
+
* Example: 'app-a123b456c7890d123456789'
|
|
36
|
+
*/
|
|
16
37
|
token: string;
|
|
38
|
+
/**
|
|
39
|
+
* Transport protocol to use for uploading files.
|
|
40
|
+
* 'http' uses XMLHttpRequest, 'ws' uses WebSocket.
|
|
41
|
+
* @default 'ws'
|
|
42
|
+
*/
|
|
17
43
|
transport?: 'http' | 'ws';
|
|
44
|
+
/**
|
|
45
|
+
* Size of each chunk in bytes when uploading files.
|
|
46
|
+
* Default is 4MB.
|
|
47
|
+
* @default 4_194_304
|
|
48
|
+
*/
|
|
18
49
|
chunkSize?: number;
|
|
19
50
|
};
|
|
20
51
|
|
|
@@ -77,11 +108,16 @@ export declare type UploadAssetImageMetadata = {
|
|
|
77
108
|
export declare type UploadAssetImageTransformation = UploadAssetExtractTransformation | UploadAssetFitTransformation | UploadAssetConvertTransformation;
|
|
78
109
|
|
|
79
110
|
export declare type UploadAssetMetadata = {
|
|
111
|
+
name?: string | undefined;
|
|
112
|
+
mimeType?: string | undefined;
|
|
113
|
+
size?: number | undefined;
|
|
80
114
|
annotations?: UploadAssetAnnotation[] | undefined;
|
|
81
|
-
|
|
82
|
-
updatedAt?: string | undefined;
|
|
115
|
+
collectionRefs?: string[] | undefined;
|
|
83
116
|
image?: UploadAssetImageMetadata | undefined;
|
|
84
117
|
retentionPolicy?: UploadAssetRetentionPolicy | undefined;
|
|
118
|
+
generatePreview?: boolean | undefined;
|
|
119
|
+
createdAt?: string | undefined;
|
|
120
|
+
updatedAt?: string | undefined;
|
|
85
121
|
};
|
|
86
122
|
|
|
87
123
|
export declare type UploadAssetProgress = {
|
|
@@ -90,7 +126,7 @@ export declare type UploadAssetProgress = {
|
|
|
90
126
|
|
|
91
127
|
export declare enum UploadAssetRetentionPolicy {
|
|
92
128
|
retain = "retain",
|
|
93
|
-
|
|
129
|
+
deleteIfNotUsed = "deleteIfNotUsed"
|
|
94
130
|
}
|
|
95
131
|
|
|
96
132
|
export { }
|
package/dist/index.js
CHANGED
|
@@ -1,37 +1,37 @@
|
|
|
1
|
-
var
|
|
2
|
-
return
|
|
1
|
+
var I = /* @__PURE__ */ ((r) => (r.retain = "retain", r.deleteIfNotUsed = "deleteIfNotUsed", r))(I || {}), x = function(r, t) {
|
|
2
|
+
return x = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, n) {
|
|
3
3
|
e.__proto__ = n;
|
|
4
4
|
} || function(e, n) {
|
|
5
5
|
for (var o in n) Object.prototype.hasOwnProperty.call(n, o) && (e[o] = n[o]);
|
|
6
|
-
},
|
|
6
|
+
}, x(r, t);
|
|
7
7
|
};
|
|
8
|
-
function
|
|
9
|
-
if (typeof
|
|
10
|
-
throw new TypeError("Class extends value " + String(
|
|
11
|
-
|
|
8
|
+
function P(r, t) {
|
|
9
|
+
if (typeof t != "function" && t !== null)
|
|
10
|
+
throw new TypeError("Class extends value " + String(t) + " is not a constructor or null");
|
|
11
|
+
x(r, t);
|
|
12
12
|
function e() {
|
|
13
|
-
this.constructor =
|
|
13
|
+
this.constructor = r;
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
r.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
|
|
16
16
|
}
|
|
17
|
-
function
|
|
18
|
-
var
|
|
19
|
-
if (e) return e.call(
|
|
20
|
-
if (
|
|
17
|
+
function F(r) {
|
|
18
|
+
var t = typeof Symbol == "function" && Symbol.iterator, e = t && r[t], n = 0;
|
|
19
|
+
if (e) return e.call(r);
|
|
20
|
+
if (r && typeof r.length == "number") return {
|
|
21
21
|
next: function() {
|
|
22
|
-
return
|
|
22
|
+
return r && n >= r.length && (r = void 0), { value: r && r[n++], done: !r };
|
|
23
23
|
}
|
|
24
24
|
};
|
|
25
|
-
throw new TypeError(
|
|
25
|
+
throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
26
26
|
}
|
|
27
|
-
function
|
|
28
|
-
var e = typeof Symbol == "function" &&
|
|
29
|
-
if (!e) return
|
|
30
|
-
var n = e.call(
|
|
27
|
+
function O(r, t) {
|
|
28
|
+
var e = typeof Symbol == "function" && r[Symbol.iterator];
|
|
29
|
+
if (!e) return r;
|
|
30
|
+
var n = e.call(r), o, i = [], u;
|
|
31
31
|
try {
|
|
32
|
-
for (; (
|
|
33
|
-
} catch (
|
|
34
|
-
u = { error:
|
|
32
|
+
for (; (t === void 0 || t-- > 0) && !(o = n.next()).done; ) i.push(o.value);
|
|
33
|
+
} catch (c) {
|
|
34
|
+
u = { error: c };
|
|
35
35
|
} finally {
|
|
36
36
|
try {
|
|
37
37
|
o && !o.done && (e = n.return) && e.call(n);
|
|
@@ -41,86 +41,86 @@ function _(t, r) {
|
|
|
41
41
|
}
|
|
42
42
|
return i;
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
if (e || arguments.length === 2) for (var n = 0, o =
|
|
46
|
-
(i || !(n in
|
|
47
|
-
return
|
|
44
|
+
function _(r, t, e) {
|
|
45
|
+
if (e || arguments.length === 2) for (var n = 0, o = t.length, i; n < o; n++)
|
|
46
|
+
(i || !(n in t)) && (i || (i = Array.prototype.slice.call(t, 0, n)), i[n] = t[n]);
|
|
47
|
+
return r.concat(i || Array.prototype.slice.call(t));
|
|
48
48
|
}
|
|
49
|
-
function
|
|
50
|
-
return typeof
|
|
49
|
+
function d(r) {
|
|
50
|
+
return typeof r == "function";
|
|
51
51
|
}
|
|
52
|
-
function B(
|
|
53
|
-
var
|
|
52
|
+
function B(r) {
|
|
53
|
+
var t = function(n) {
|
|
54
54
|
Error.call(n), n.stack = new Error().stack;
|
|
55
|
-
}, e = t
|
|
55
|
+
}, e = r(t);
|
|
56
56
|
return e.prototype = Object.create(Error.prototype), e.prototype.constructor = e, e;
|
|
57
57
|
}
|
|
58
|
-
var g = B(function(
|
|
58
|
+
var g = B(function(r) {
|
|
59
59
|
return function(e) {
|
|
60
|
-
|
|
60
|
+
r(this), this.message = e ? e.length + ` errors occurred during unsubscription:
|
|
61
61
|
` + e.map(function(n, o) {
|
|
62
62
|
return o + 1 + ") " + n.toString();
|
|
63
63
|
}).join(`
|
|
64
64
|
`) : "", this.name = "UnsubscriptionError", this.errors = e;
|
|
65
65
|
};
|
|
66
66
|
});
|
|
67
|
-
function
|
|
68
|
-
if (
|
|
69
|
-
var e =
|
|
70
|
-
0 <= e &&
|
|
67
|
+
function j(r, t) {
|
|
68
|
+
if (r) {
|
|
69
|
+
var e = r.indexOf(t);
|
|
70
|
+
0 <= e && r.splice(e, 1);
|
|
71
71
|
}
|
|
72
72
|
}
|
|
73
|
-
var
|
|
74
|
-
function t
|
|
75
|
-
this.initialTeardown =
|
|
73
|
+
var A = function() {
|
|
74
|
+
function r(t) {
|
|
75
|
+
this.initialTeardown = t, this.closed = !1, this._parentage = null, this._finalizers = null;
|
|
76
76
|
}
|
|
77
|
-
return
|
|
78
|
-
var
|
|
77
|
+
return r.prototype.unsubscribe = function() {
|
|
78
|
+
var t, e, n, o, i;
|
|
79
79
|
if (!this.closed) {
|
|
80
80
|
this.closed = !0;
|
|
81
81
|
var u = this._parentage;
|
|
82
82
|
if (u)
|
|
83
83
|
if (this._parentage = null, Array.isArray(u))
|
|
84
84
|
try {
|
|
85
|
-
for (var
|
|
86
|
-
var
|
|
87
|
-
|
|
85
|
+
for (var c = F(u), s = c.next(); !s.done; s = c.next()) {
|
|
86
|
+
var l = s.value;
|
|
87
|
+
l.remove(this);
|
|
88
88
|
}
|
|
89
|
-
} catch (
|
|
90
|
-
|
|
89
|
+
} catch (f) {
|
|
90
|
+
t = { error: f };
|
|
91
91
|
} finally {
|
|
92
92
|
try {
|
|
93
|
-
s && !s.done && (e =
|
|
93
|
+
s && !s.done && (e = c.return) && e.call(c);
|
|
94
94
|
} finally {
|
|
95
|
-
if (
|
|
95
|
+
if (t) throw t.error;
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
else
|
|
99
99
|
u.remove(this);
|
|
100
|
-
var
|
|
101
|
-
if (
|
|
100
|
+
var a = this.initialTeardown;
|
|
101
|
+
if (d(a))
|
|
102
102
|
try {
|
|
103
|
-
|
|
104
|
-
} catch (
|
|
105
|
-
i =
|
|
103
|
+
a();
|
|
104
|
+
} catch (f) {
|
|
105
|
+
i = f instanceof g ? f.errors : [f];
|
|
106
106
|
}
|
|
107
107
|
var p = this._finalizers;
|
|
108
108
|
if (p) {
|
|
109
109
|
this._finalizers = null;
|
|
110
110
|
try {
|
|
111
|
-
for (var
|
|
112
|
-
var
|
|
111
|
+
for (var y = F(p), b = y.next(); !b.done; b = y.next()) {
|
|
112
|
+
var m = b.value;
|
|
113
113
|
try {
|
|
114
|
-
|
|
115
|
-
} catch (
|
|
116
|
-
i = i ?? [],
|
|
114
|
+
L(m);
|
|
115
|
+
} catch (f) {
|
|
116
|
+
i = i ?? [], f instanceof g ? i = _(_([], O(i)), O(f.errors)) : i.push(f);
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
} catch (
|
|
120
|
-
n = { error:
|
|
119
|
+
} catch (f) {
|
|
120
|
+
n = { error: f };
|
|
121
121
|
} finally {
|
|
122
122
|
try {
|
|
123
|
-
|
|
123
|
+
b && !b.done && (o = y.return) && o.call(y);
|
|
124
124
|
} finally {
|
|
125
125
|
if (n) throw n.error;
|
|
126
126
|
}
|
|
@@ -129,190 +129,190 @@ var P = function() {
|
|
|
129
129
|
if (i)
|
|
130
130
|
throw new g(i);
|
|
131
131
|
}
|
|
132
|
-
},
|
|
132
|
+
}, r.prototype.add = function(t) {
|
|
133
133
|
var e;
|
|
134
|
-
if (
|
|
134
|
+
if (t && t !== this)
|
|
135
135
|
if (this.closed)
|
|
136
|
-
|
|
136
|
+
L(t);
|
|
137
137
|
else {
|
|
138
|
-
if (
|
|
139
|
-
if (
|
|
138
|
+
if (t instanceof r) {
|
|
139
|
+
if (t.closed || t._hasParent(this))
|
|
140
140
|
return;
|
|
141
|
-
|
|
141
|
+
t._addParent(this);
|
|
142
142
|
}
|
|
143
|
-
(this._finalizers = (e = this._finalizers) !== null && e !== void 0 ? e : []).push(
|
|
143
|
+
(this._finalizers = (e = this._finalizers) !== null && e !== void 0 ? e : []).push(t);
|
|
144
144
|
}
|
|
145
|
-
},
|
|
145
|
+
}, r.prototype._hasParent = function(t) {
|
|
146
146
|
var e = this._parentage;
|
|
147
|
-
return e ===
|
|
148
|
-
},
|
|
147
|
+
return e === t || Array.isArray(e) && e.includes(t);
|
|
148
|
+
}, r.prototype._addParent = function(t) {
|
|
149
149
|
var e = this._parentage;
|
|
150
|
-
this._parentage = Array.isArray(e) ? (e.push(
|
|
151
|
-
},
|
|
150
|
+
this._parentage = Array.isArray(e) ? (e.push(t), e) : e ? [e, t] : t;
|
|
151
|
+
}, r.prototype._removeParent = function(t) {
|
|
152
152
|
var e = this._parentage;
|
|
153
|
-
e ===
|
|
154
|
-
},
|
|
153
|
+
e === t ? this._parentage = null : Array.isArray(e) && j(e, t);
|
|
154
|
+
}, r.prototype.remove = function(t) {
|
|
155
155
|
var e = this._finalizers;
|
|
156
|
-
e &&
|
|
157
|
-
},
|
|
158
|
-
var
|
|
159
|
-
return
|
|
160
|
-
}(),
|
|
156
|
+
e && j(e, t), t instanceof r && t._removeParent(this);
|
|
157
|
+
}, r.EMPTY = function() {
|
|
158
|
+
var t = new r();
|
|
159
|
+
return t.closed = !0, t;
|
|
160
|
+
}(), r;
|
|
161
161
|
}();
|
|
162
|
-
|
|
163
|
-
function
|
|
164
|
-
return
|
|
162
|
+
A.EMPTY;
|
|
163
|
+
function J(r) {
|
|
164
|
+
return r instanceof A || r && "closed" in r && d(r.remove) && d(r.add) && d(r.unsubscribe);
|
|
165
165
|
}
|
|
166
|
-
function
|
|
167
|
-
|
|
166
|
+
function L(r) {
|
|
167
|
+
d(r) ? r() : r.unsubscribe();
|
|
168
168
|
}
|
|
169
|
-
var
|
|
169
|
+
var M = {
|
|
170
170
|
Promise: void 0
|
|
171
|
-
},
|
|
172
|
-
setTimeout: function(
|
|
171
|
+
}, V = {
|
|
172
|
+
setTimeout: function(r, t) {
|
|
173
173
|
for (var e = [], n = 2; n < arguments.length; n++)
|
|
174
174
|
e[n - 2] = arguments[n];
|
|
175
|
-
return setTimeout.apply(void 0,
|
|
175
|
+
return setTimeout.apply(void 0, _([r, t], O(e)));
|
|
176
176
|
},
|
|
177
|
-
clearTimeout: function(
|
|
178
|
-
return clearTimeout(
|
|
177
|
+
clearTimeout: function(r) {
|
|
178
|
+
return clearTimeout(r);
|
|
179
179
|
},
|
|
180
180
|
delegate: void 0
|
|
181
181
|
};
|
|
182
|
-
function
|
|
183
|
-
|
|
184
|
-
throw
|
|
182
|
+
function q(r) {
|
|
183
|
+
V.setTimeout(function() {
|
|
184
|
+
throw r;
|
|
185
185
|
});
|
|
186
186
|
}
|
|
187
|
-
function
|
|
187
|
+
function W() {
|
|
188
188
|
}
|
|
189
|
-
function
|
|
190
|
-
|
|
189
|
+
function Y(r) {
|
|
190
|
+
r();
|
|
191
191
|
}
|
|
192
|
-
var
|
|
193
|
-
|
|
194
|
-
function
|
|
195
|
-
var n =
|
|
196
|
-
return n.isStopped = !1, e ? (n.destination = e,
|
|
192
|
+
var T = function(r) {
|
|
193
|
+
P(t, r);
|
|
194
|
+
function t(e) {
|
|
195
|
+
var n = r.call(this) || this;
|
|
196
|
+
return n.isStopped = !1, e ? (n.destination = e, J(e) && e.add(n)) : n.destination = N, n;
|
|
197
197
|
}
|
|
198
|
-
return
|
|
199
|
-
return new
|
|
200
|
-
},
|
|
198
|
+
return t.create = function(e, n, o) {
|
|
199
|
+
return new w(e, n, o);
|
|
200
|
+
}, t.prototype.next = function(e) {
|
|
201
201
|
this.isStopped || this._next(e);
|
|
202
|
-
},
|
|
202
|
+
}, t.prototype.error = function(e) {
|
|
203
203
|
this.isStopped || (this.isStopped = !0, this._error(e));
|
|
204
|
-
},
|
|
204
|
+
}, t.prototype.complete = function() {
|
|
205
205
|
this.isStopped || (this.isStopped = !0, this._complete());
|
|
206
|
-
},
|
|
207
|
-
this.closed || (this.isStopped = !0,
|
|
208
|
-
},
|
|
206
|
+
}, t.prototype.unsubscribe = function() {
|
|
207
|
+
this.closed || (this.isStopped = !0, r.prototype.unsubscribe.call(this), this.destination = null);
|
|
208
|
+
}, t.prototype._next = function(e) {
|
|
209
209
|
this.destination.next(e);
|
|
210
|
-
},
|
|
210
|
+
}, t.prototype._error = function(e) {
|
|
211
211
|
try {
|
|
212
212
|
this.destination.error(e);
|
|
213
213
|
} finally {
|
|
214
214
|
this.unsubscribe();
|
|
215
215
|
}
|
|
216
|
-
},
|
|
216
|
+
}, t.prototype._complete = function() {
|
|
217
217
|
try {
|
|
218
218
|
this.destination.complete();
|
|
219
219
|
} finally {
|
|
220
220
|
this.unsubscribe();
|
|
221
221
|
}
|
|
222
|
-
},
|
|
223
|
-
}(
|
|
224
|
-
function t
|
|
225
|
-
this.partialObserver =
|
|
222
|
+
}, t;
|
|
223
|
+
}(A), C = function() {
|
|
224
|
+
function r(t) {
|
|
225
|
+
this.partialObserver = t;
|
|
226
226
|
}
|
|
227
|
-
return
|
|
227
|
+
return r.prototype.next = function(t) {
|
|
228
228
|
var e = this.partialObserver;
|
|
229
229
|
if (e.next)
|
|
230
230
|
try {
|
|
231
|
-
e.next(
|
|
231
|
+
e.next(t);
|
|
232
232
|
} catch (n) {
|
|
233
|
-
|
|
233
|
+
S(n);
|
|
234
234
|
}
|
|
235
|
-
},
|
|
235
|
+
}, r.prototype.error = function(t) {
|
|
236
236
|
var e = this.partialObserver;
|
|
237
237
|
if (e.error)
|
|
238
238
|
try {
|
|
239
|
-
e.error(
|
|
239
|
+
e.error(t);
|
|
240
240
|
} catch (n) {
|
|
241
|
-
|
|
241
|
+
S(n);
|
|
242
242
|
}
|
|
243
243
|
else
|
|
244
|
-
|
|
245
|
-
},
|
|
246
|
-
var
|
|
247
|
-
if (
|
|
244
|
+
S(t);
|
|
245
|
+
}, r.prototype.complete = function() {
|
|
246
|
+
var t = this.partialObserver;
|
|
247
|
+
if (t.complete)
|
|
248
248
|
try {
|
|
249
|
-
|
|
249
|
+
t.complete();
|
|
250
250
|
} catch (e) {
|
|
251
|
-
|
|
251
|
+
S(e);
|
|
252
252
|
}
|
|
253
|
-
},
|
|
254
|
-
}(),
|
|
255
|
-
|
|
256
|
-
function
|
|
257
|
-
var i =
|
|
258
|
-
return
|
|
253
|
+
}, r;
|
|
254
|
+
}(), w = function(r) {
|
|
255
|
+
P(t, r);
|
|
256
|
+
function t(e, n, o) {
|
|
257
|
+
var i = r.call(this) || this, u;
|
|
258
|
+
return d(e) || !e ? u = {
|
|
259
259
|
next: e ?? void 0,
|
|
260
260
|
error: n ?? void 0,
|
|
261
261
|
complete: o ?? void 0
|
|
262
|
-
} : u = e, i.destination = new
|
|
262
|
+
} : u = e, i.destination = new C(u), i;
|
|
263
263
|
}
|
|
264
|
-
return
|
|
265
|
-
}(
|
|
266
|
-
function
|
|
267
|
-
|
|
264
|
+
return t;
|
|
265
|
+
}(T);
|
|
266
|
+
function S(r) {
|
|
267
|
+
q(r);
|
|
268
268
|
}
|
|
269
|
-
function
|
|
270
|
-
throw
|
|
269
|
+
function D(r) {
|
|
270
|
+
throw r;
|
|
271
271
|
}
|
|
272
|
-
var
|
|
272
|
+
var N = {
|
|
273
273
|
closed: !0,
|
|
274
|
-
next:
|
|
275
|
-
error:
|
|
276
|
-
complete:
|
|
274
|
+
next: W,
|
|
275
|
+
error: D,
|
|
276
|
+
complete: W
|
|
277
277
|
}, X = function() {
|
|
278
278
|
return typeof Symbol == "function" && Symbol.observable || "@@observable";
|
|
279
279
|
}();
|
|
280
|
-
function
|
|
281
|
-
return
|
|
280
|
+
function G(r) {
|
|
281
|
+
return r;
|
|
282
282
|
}
|
|
283
|
-
function
|
|
284
|
-
return
|
|
285
|
-
return
|
|
283
|
+
function K(r) {
|
|
284
|
+
return r.length === 0 ? G : r.length === 1 ? r[0] : function(e) {
|
|
285
|
+
return r.reduce(function(n, o) {
|
|
286
286
|
return o(n);
|
|
287
287
|
}, e);
|
|
288
288
|
};
|
|
289
289
|
}
|
|
290
|
-
var
|
|
291
|
-
function t
|
|
292
|
-
|
|
290
|
+
var $ = function() {
|
|
291
|
+
function r(t) {
|
|
292
|
+
t && (this._subscribe = t);
|
|
293
293
|
}
|
|
294
|
-
return
|
|
295
|
-
var e = new
|
|
296
|
-
return e.source = this, e.operator =
|
|
297
|
-
},
|
|
298
|
-
var o = this, i =
|
|
299
|
-
return
|
|
300
|
-
var u = o,
|
|
301
|
-
i.add(
|
|
294
|
+
return r.prototype.lift = function(t) {
|
|
295
|
+
var e = new r();
|
|
296
|
+
return e.source = this, e.operator = t, e;
|
|
297
|
+
}, r.prototype.subscribe = function(t, e, n) {
|
|
298
|
+
var o = this, i = Z(t) ? t : new w(t, e, n);
|
|
299
|
+
return Y(function() {
|
|
300
|
+
var u = o, c = u.operator, s = u.source;
|
|
301
|
+
i.add(c ? c.call(i, s) : s ? o._subscribe(i) : o._trySubscribe(i));
|
|
302
302
|
}), i;
|
|
303
|
-
},
|
|
303
|
+
}, r.prototype._trySubscribe = function(t) {
|
|
304
304
|
try {
|
|
305
|
-
return this._subscribe(
|
|
305
|
+
return this._subscribe(t);
|
|
306
306
|
} catch (e) {
|
|
307
|
-
|
|
307
|
+
t.error(e);
|
|
308
308
|
}
|
|
309
|
-
},
|
|
309
|
+
}, r.prototype.forEach = function(t, e) {
|
|
310
310
|
var n = this;
|
|
311
|
-
return e =
|
|
312
|
-
var u = new
|
|
313
|
-
next: function(
|
|
311
|
+
return e = z(e), new e(function(o, i) {
|
|
312
|
+
var u = new w({
|
|
313
|
+
next: function(c) {
|
|
314
314
|
try {
|
|
315
|
-
|
|
315
|
+
t(c);
|
|
316
316
|
} catch (s) {
|
|
317
317
|
i(s), u.unsubscribe();
|
|
318
318
|
}
|
|
@@ -322,18 +322,18 @@ var I = function() {
|
|
|
322
322
|
});
|
|
323
323
|
n.subscribe(u);
|
|
324
324
|
});
|
|
325
|
-
},
|
|
325
|
+
}, r.prototype._subscribe = function(t) {
|
|
326
326
|
var e;
|
|
327
|
-
return (e = this.source) === null || e === void 0 ? void 0 : e.subscribe(
|
|
328
|
-
},
|
|
327
|
+
return (e = this.source) === null || e === void 0 ? void 0 : e.subscribe(t);
|
|
328
|
+
}, r.prototype[X] = function() {
|
|
329
329
|
return this;
|
|
330
|
-
},
|
|
331
|
-
for (var
|
|
332
|
-
|
|
333
|
-
return
|
|
334
|
-
},
|
|
330
|
+
}, r.prototype.pipe = function() {
|
|
331
|
+
for (var t = [], e = 0; e < arguments.length; e++)
|
|
332
|
+
t[e] = arguments[e];
|
|
333
|
+
return K(t)(this);
|
|
334
|
+
}, r.prototype.toPromise = function(t) {
|
|
335
335
|
var e = this;
|
|
336
|
-
return
|
|
336
|
+
return t = z(t), new t(function(n, o) {
|
|
337
337
|
var i;
|
|
338
338
|
e.subscribe(function(u) {
|
|
339
339
|
return i = u;
|
|
@@ -343,103 +343,198 @@ var I = function() {
|
|
|
343
343
|
return n(i);
|
|
344
344
|
});
|
|
345
345
|
});
|
|
346
|
-
},
|
|
347
|
-
return new t
|
|
348
|
-
},
|
|
346
|
+
}, r.create = function(t) {
|
|
347
|
+
return new r(t);
|
|
348
|
+
}, r;
|
|
349
349
|
}();
|
|
350
|
-
function
|
|
351
|
-
var
|
|
352
|
-
return (
|
|
350
|
+
function z(r) {
|
|
351
|
+
var t;
|
|
352
|
+
return (t = r ?? M.Promise) !== null && t !== void 0 ? t : Promise;
|
|
353
|
+
}
|
|
354
|
+
function Q(r) {
|
|
355
|
+
return r && d(r.next) && d(r.error) && d(r.complete);
|
|
356
|
+
}
|
|
357
|
+
function Z(r) {
|
|
358
|
+
return r && r instanceof T || Q(r) && J(r);
|
|
359
|
+
}
|
|
360
|
+
function rr(r) {
|
|
361
|
+
return d(r?.lift);
|
|
362
|
+
}
|
|
363
|
+
function tr(r) {
|
|
364
|
+
return function(t) {
|
|
365
|
+
if (rr(t))
|
|
366
|
+
return t.lift(function(e) {
|
|
367
|
+
try {
|
|
368
|
+
return r(e, this);
|
|
369
|
+
} catch (n) {
|
|
370
|
+
this.error(n);
|
|
371
|
+
}
|
|
372
|
+
});
|
|
373
|
+
throw new TypeError("Unable to lift unknown Observable type");
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
function er(r, t, e, n, o) {
|
|
377
|
+
return new nr(r, t, e, n, o);
|
|
353
378
|
}
|
|
354
|
-
function
|
|
355
|
-
|
|
379
|
+
var nr = function(r) {
|
|
380
|
+
P(t, r);
|
|
381
|
+
function t(e, n, o, i, u, c) {
|
|
382
|
+
var s = r.call(this, e) || this;
|
|
383
|
+
return s.onFinalize = u, s.shouldUnsubscribe = c, s._next = n ? function(l) {
|
|
384
|
+
try {
|
|
385
|
+
n(l);
|
|
386
|
+
} catch (a) {
|
|
387
|
+
e.error(a);
|
|
388
|
+
}
|
|
389
|
+
} : r.prototype._next, s._error = i ? function(l) {
|
|
390
|
+
try {
|
|
391
|
+
i(l);
|
|
392
|
+
} catch (a) {
|
|
393
|
+
e.error(a);
|
|
394
|
+
} finally {
|
|
395
|
+
this.unsubscribe();
|
|
396
|
+
}
|
|
397
|
+
} : r.prototype._error, s._complete = o ? function() {
|
|
398
|
+
try {
|
|
399
|
+
o();
|
|
400
|
+
} catch (l) {
|
|
401
|
+
e.error(l);
|
|
402
|
+
} finally {
|
|
403
|
+
this.unsubscribe();
|
|
404
|
+
}
|
|
405
|
+
} : r.prototype._complete, s;
|
|
406
|
+
}
|
|
407
|
+
return t.prototype.unsubscribe = function() {
|
|
408
|
+
var e;
|
|
409
|
+
if (!this.shouldUnsubscribe || this.shouldUnsubscribe()) {
|
|
410
|
+
var n = this.closed;
|
|
411
|
+
r.prototype.unsubscribe.call(this), !n && ((e = this.onFinalize) === null || e === void 0 || e.call(this));
|
|
412
|
+
}
|
|
413
|
+
}, t;
|
|
414
|
+
}(T), or = B(function(r) {
|
|
415
|
+
return function() {
|
|
416
|
+
r(this), this.name = "EmptyError", this.message = "no elements in sequence";
|
|
417
|
+
};
|
|
418
|
+
});
|
|
419
|
+
function ir(r, t) {
|
|
420
|
+
return new Promise(function(e, n) {
|
|
421
|
+
var o = new w({
|
|
422
|
+
next: function(i) {
|
|
423
|
+
e(i), o.unsubscribe();
|
|
424
|
+
},
|
|
425
|
+
error: n,
|
|
426
|
+
complete: function() {
|
|
427
|
+
n(new or());
|
|
428
|
+
}
|
|
429
|
+
});
|
|
430
|
+
r.subscribe(o);
|
|
431
|
+
});
|
|
356
432
|
}
|
|
357
|
-
function
|
|
358
|
-
return
|
|
433
|
+
function sr(r, t) {
|
|
434
|
+
return tr(function(e, n) {
|
|
435
|
+
var o = 0;
|
|
436
|
+
e.subscribe(er(n, function(i) {
|
|
437
|
+
return r.call(t, i, o++) && n.next(i);
|
|
438
|
+
}));
|
|
439
|
+
});
|
|
359
440
|
}
|
|
360
|
-
function
|
|
361
|
-
const
|
|
362
|
-
return new
|
|
363
|
-
const
|
|
364
|
-
`${
|
|
441
|
+
function ur({ url: r, project: t, token: e, chunkSize: n }, o, i, u) {
|
|
442
|
+
const c = { ...i ?? {}, projectRef: t };
|
|
443
|
+
return new $((s) => {
|
|
444
|
+
const l = new URL(r), a = new WebSocket(
|
|
445
|
+
`${l.protocol === "https:" ? "wss" : "ws"}://${l.host}/api/v1/assets/ws`,
|
|
365
446
|
"contello-file-upload-v1"
|
|
366
|
-
), p = new FileReader();
|
|
367
|
-
let
|
|
368
|
-
|
|
369
|
-
const
|
|
447
|
+
), p = typeof FileReader < "u" ? new FileReader() : null;
|
|
448
|
+
let y = 0, b = !1, m = !1;
|
|
449
|
+
a.onopen = async () => {
|
|
450
|
+
const E = {
|
|
370
451
|
type: "init",
|
|
371
|
-
|
|
372
|
-
|
|
452
|
+
metadata: {
|
|
453
|
+
...c,
|
|
454
|
+
name: o.name,
|
|
455
|
+
mimeType: o.type,
|
|
456
|
+
size: o.size
|
|
457
|
+
},
|
|
373
458
|
token: e
|
|
374
459
|
};
|
|
375
|
-
|
|
376
|
-
function
|
|
377
|
-
const
|
|
378
|
-
p.readAsArrayBuffer(
|
|
460
|
+
a.send(JSON.stringify(E));
|
|
461
|
+
function k() {
|
|
462
|
+
const v = o.slice(y, y + n);
|
|
463
|
+
p ? p.readAsArrayBuffer(v) : v.arrayBuffer().then((h) => {
|
|
464
|
+
R(h);
|
|
465
|
+
}).catch((h) => {
|
|
466
|
+
s.error(h);
|
|
467
|
+
});
|
|
379
468
|
}
|
|
380
|
-
function
|
|
381
|
-
p
|
|
469
|
+
function U() {
|
|
470
|
+
p?.abort(), a.send(JSON.stringify({ type: "done" }));
|
|
382
471
|
}
|
|
383
|
-
function
|
|
384
|
-
|
|
472
|
+
function H() {
|
|
473
|
+
m && k();
|
|
385
474
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
475
|
+
function R(v) {
|
|
476
|
+
a.readyState === WebSocket.OPEN ? (a.send(v), y += v.byteLength, y < o.size ? k() : U()) : (s.error(new Error("WebSocket is closed")), p?.abort());
|
|
477
|
+
}
|
|
478
|
+
p && (p.onload = () => {
|
|
479
|
+
p.result && p.result instanceof ArrayBuffer ? R(p.result) : U();
|
|
480
|
+
}), a.onmessage = (v) => {
|
|
481
|
+
const h = JSON.parse(v.data);
|
|
482
|
+
if (h.type === "ack") {
|
|
483
|
+
m = !0, H();
|
|
392
484
|
return;
|
|
393
485
|
}
|
|
394
|
-
if (
|
|
395
|
-
return s.next({ progress:
|
|
396
|
-
if (
|
|
397
|
-
return
|
|
398
|
-
s.error(new Error("WebSocket message with unknown type " + JSON.stringify(
|
|
486
|
+
if (h.type === "progress")
|
|
487
|
+
return s.next({ progress: h.bytesReceived / o.size * 100 });
|
|
488
|
+
if (h.type === "done")
|
|
489
|
+
return h.id ? (b = !0, s.next({ id: h.id }), s.complete()) : s.error(new Error("No asset id received")), a.close();
|
|
490
|
+
s.error(new Error("WebSocket message with unknown type " + JSON.stringify(h))), a.close();
|
|
399
491
|
};
|
|
400
|
-
},
|
|
401
|
-
|
|
492
|
+
}, a.onerror = (E) => s.error(E), a.onclose = () => {
|
|
493
|
+
b || s.error(new Error("Connection closed"));
|
|
402
494
|
};
|
|
403
|
-
const
|
|
404
|
-
|
|
495
|
+
const f = () => {
|
|
496
|
+
b || (p?.abort(), a.close(), s.error(new Error("Upload aborted")));
|
|
405
497
|
};
|
|
406
|
-
return u?.abort?.addEventListener("abort",
|
|
407
|
-
u?.abort?.removeEventListener("abort",
|
|
498
|
+
return u?.abort?.addEventListener("abort", f), () => {
|
|
499
|
+
u?.abort?.removeEventListener("abort", f), a.close();
|
|
408
500
|
};
|
|
409
501
|
});
|
|
410
502
|
}
|
|
411
|
-
function
|
|
412
|
-
return new
|
|
413
|
-
const
|
|
414
|
-
|
|
503
|
+
function cr({ url: r, project: t, token: e }, n, o, i) {
|
|
504
|
+
return new $((u) => {
|
|
505
|
+
const c = new FormData();
|
|
506
|
+
c.append("metadata", JSON.stringify({ ...o ?? {}, projectRef: t })), c.append("file", n);
|
|
415
507
|
const s = new XMLHttpRequest();
|
|
416
|
-
return s.setRequestHeader("Authorization", `Bearer ${e}`), s.open("POST", `${
|
|
417
|
-
|
|
508
|
+
return s.setRequestHeader("Authorization", `Bearer ${e}`), s.open("POST", `${r}/api/v1/assets`, !0), s.upload.onprogress = async (l) => {
|
|
509
|
+
l.lengthComputable && u.next({ progress: l.loaded / l.total * 100 });
|
|
418
510
|
}, s.onload = async () => {
|
|
419
511
|
if (s.status >= 200 && s.status < 300) {
|
|
420
|
-
const { id:
|
|
421
|
-
return u.next({ id:
|
|
512
|
+
const { id: l } = JSON.parse(s.responseText);
|
|
513
|
+
return u.next({ id: l }), u.complete();
|
|
422
514
|
}
|
|
423
515
|
u.error(new Error(`${s.status}: ${s.statusText}`));
|
|
424
|
-
}, s.onerror = (
|
|
516
|
+
}, s.onerror = (l) => u.error(l), s.send(c), i?.abort?.addEventListener("abort", () => s.abort()), () => s.abort();
|
|
425
517
|
});
|
|
426
518
|
}
|
|
427
|
-
class
|
|
519
|
+
class ar {
|
|
428
520
|
params;
|
|
429
|
-
constructor(
|
|
521
|
+
constructor(t) {
|
|
430
522
|
this.params = {
|
|
431
|
-
url:
|
|
432
|
-
project:
|
|
433
|
-
token:
|
|
434
|
-
transport:
|
|
435
|
-
chunkSize:
|
|
523
|
+
url: t.url,
|
|
524
|
+
project: t.project,
|
|
525
|
+
token: t.token,
|
|
526
|
+
transport: t.transport || "ws",
|
|
527
|
+
chunkSize: t.chunkSize || 4 * 1024 * 1024
|
|
436
528
|
};
|
|
437
529
|
}
|
|
438
|
-
upload(
|
|
439
|
-
return this.
|
|
530
|
+
async upload(t, e, n) {
|
|
531
|
+
return ir(this.uploadWithEvents(t, e, n).pipe(sr((o) => "id" in o)));
|
|
532
|
+
}
|
|
533
|
+
uploadWithEvents(t, e, n) {
|
|
534
|
+
return this.params.transport === "http" ? cr(this.params, t, e, n) : ur(this.params, t, e, n);
|
|
440
535
|
}
|
|
441
536
|
}
|
|
442
537
|
export {
|
|
443
|
-
|
|
444
|
-
|
|
538
|
+
ar as ContelloUploader,
|
|
539
|
+
I as UploadAssetRetentionPolicy
|
|
445
540
|
};
|
package/dist/index.umd.cjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
(function(v,
|
|
2
|
-
`+
|
|
3
|
-
`):"",this.name="UnsubscriptionError",this.errors=
|
|
1
|
+
(function(v,S){typeof exports=="object"&&typeof module<"u"?S(exports):typeof define=="function"&&define.amd?define(["exports"],S):(v=typeof globalThis<"u"?globalThis:v||self,S(v.ContelloUploader={}))})(this,function(v){"use strict";var S=(r=>(r.retain="retain",r.deleteIfNotUsed="deleteIfNotUsed",r))(S||{}),O=function(r,t){return O=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o])},O(r,t)};function x(r,t){if(typeof t!="function"&&t!==null)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");O(r,t);function e(){this.constructor=r}r.prototype=t===null?Object.create(t):(e.prototype=t.prototype,new e)}function R(r){var t=typeof Symbol=="function"&&Symbol.iterator,e=t&&r[t],n=0;if(e)return e.call(r);if(r&&typeof r.length=="number")return{next:function(){return r&&n>=r.length&&(r=void 0),{value:r&&r[n++],done:!r}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}function _(r,t){var e=typeof Symbol=="function"&&r[Symbol.iterator];if(!e)return r;var n=e.call(r),o,i=[],u;try{for(;(t===void 0||t-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(c){u={error:c}}finally{try{o&&!o.done&&(e=n.return)&&e.call(n)}finally{if(u)throw u.error}}return i}function P(r,t,e){if(e||arguments.length===2)for(var n=0,o=t.length,i;n<o;n++)(i||!(n in t))&&(i||(i=Array.prototype.slice.call(t,0,n)),i[n]=t[n]);return r.concat(i||Array.prototype.slice.call(t))}typeof SuppressedError=="function"&&SuppressedError;function d(r){return typeof r=="function"}function j(r){var t=function(n){Error.call(n),n.stack=new Error().stack},e=r(t);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var T=j(function(r){return function(e){r(this),this.message=e?e.length+` errors occurred during unsubscription:
|
|
2
|
+
`+e.map(function(n,o){return o+1+") "+n.toString()}).join(`
|
|
3
|
+
`):"",this.name="UnsubscriptionError",this.errors=e}});function F(r,t){if(r){var e=r.indexOf(t);0<=e&&r.splice(e,1)}}var A=function(){function r(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}return r.prototype.unsubscribe=function(){var t,e,n,o,i;if(!this.closed){this.closed=!0;var u=this._parentage;if(u)if(this._parentage=null,Array.isArray(u))try{for(var c=R(u),s=c.next();!s.done;s=c.next()){var l=s.value;l.remove(this)}}catch(f){t={error:f}}finally{try{s&&!s.done&&(e=c.return)&&e.call(c)}finally{if(t)throw t.error}}else u.remove(this);var a=this.initialTeardown;if(d(a))try{a()}catch(f){i=f instanceof T?f.errors:[f]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var y=R(p),b=y.next();!b.done;b=y.next()){var E=b.value;try{W(E)}catch(f){i=i??[],f instanceof T?i=P(P([],_(i)),_(f.errors)):i.push(f)}}}catch(f){n={error:f}}finally{try{b&&!b.done&&(o=y.return)&&o.call(y)}finally{if(n)throw n.error}}}if(i)throw new T(i)}},r.prototype.add=function(t){var e;if(t&&t!==this)if(this.closed)W(t);else{if(t instanceof r){if(t.closed||t._hasParent(this))return;t._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(t)}},r.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},r.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},r.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&F(e,t)},r.prototype.remove=function(t){var e=this._finalizers;e&&F(e,t),t instanceof r&&t._removeParent(this)},r.EMPTY=function(){var t=new r;return t.closed=!0,t}(),r}();A.EMPTY;function L(r){return r instanceof A||r&&"closed"in r&&d(r.remove)&&d(r.add)&&d(r.unsubscribe)}function W(r){d(r)?r():r.unsubscribe()}var H={Promise:void 0},I={setTimeout:function(r,t){for(var e=[],n=2;n<arguments.length;n++)e[n-2]=arguments[n];return setTimeout.apply(void 0,P([r,t],_(e)))},clearTimeout:function(r){return clearTimeout(r)},delegate:void 0};function V(r){I.setTimeout(function(){throw r})}function z(){}function q(r){r()}var U=function(r){x(t,r);function t(e){var n=r.call(this)||this;return n.isStopped=!1,e?(n.destination=e,L(e)&&e.add(n)):n.destination=N,n}return t.create=function(e,n,o){return new w(e,n,o)},t.prototype.next=function(e){this.isStopped||this._next(e)},t.prototype.error=function(e){this.isStopped||(this.isStopped=!0,this._error(e))},t.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},t.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,r.prototype.unsubscribe.call(this),this.destination=null)},t.prototype._next=function(e){this.destination.next(e)},t.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},t.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},t}(A),Y=function(){function r(t){this.partialObserver=t}return r.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(n){g(n)}},r.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(n){g(n)}else g(t)},r.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(e){g(e)}},r}(),w=function(r){x(t,r);function t(e,n,o){var i=r.call(this)||this,u;return d(e)||!e?u={next:e??void 0,error:n??void 0,complete:o??void 0}:u=e,i.destination=new Y(u),i}return t}(U);function g(r){V(r)}function D(r){throw r}var N={closed:!0,next:z,error:D,complete:z},X=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function G(r){return r}function K(r){return r.length===0?G:r.length===1?r[0]:function(e){return r.reduce(function(n,o){return o(n)},e)}}var B=function(){function r(t){t&&(this._subscribe=t)}return r.prototype.lift=function(t){var e=new r;return e.source=this,e.operator=t,e},r.prototype.subscribe=function(t,e,n){var o=this,i=Z(t)?t:new w(t,e,n);return q(function(){var u=o,c=u.operator,s=u.source;i.add(c?c.call(i,s):s?o._subscribe(i):o._trySubscribe(i))}),i},r.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},r.prototype.forEach=function(t,e){var n=this;return e=J(e),new e(function(o,i){var u=new w({next:function(c){try{t(c)}catch(s){i(s),u.unsubscribe()}},error:i,complete:o});n.subscribe(u)})},r.prototype._subscribe=function(t){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(t)},r.prototype[X]=function(){return this},r.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return K(t)(this)},r.prototype.toPromise=function(t){var e=this;return t=J(t),new t(function(n,o){var i;e.subscribe(function(u){return i=u},function(u){return o(u)},function(){return n(i)})})},r.create=function(t){return new r(t)},r}();function J(r){var t;return(t=r??H.Promise)!==null&&t!==void 0?t:Promise}function Q(r){return r&&d(r.next)&&d(r.error)&&d(r.complete)}function Z(r){return r&&r instanceof U||Q(r)&&L(r)}function rr(r){return d(r?.lift)}function tr(r){return function(t){if(rr(t))return t.lift(function(e){try{return r(e,this)}catch(n){this.error(n)}});throw new TypeError("Unable to lift unknown Observable type")}}function er(r,t,e,n,o){return new nr(r,t,e,n,o)}var nr=function(r){x(t,r);function t(e,n,o,i,u,c){var s=r.call(this,e)||this;return s.onFinalize=u,s.shouldUnsubscribe=c,s._next=n?function(l){try{n(l)}catch(a){e.error(a)}}:r.prototype._next,s._error=i?function(l){try{i(l)}catch(a){e.error(a)}finally{this.unsubscribe()}}:r.prototype._error,s._complete=o?function(){try{o()}catch(l){e.error(l)}finally{this.unsubscribe()}}:r.prototype._complete,s}return t.prototype.unsubscribe=function(){var e;if(!this.shouldUnsubscribe||this.shouldUnsubscribe()){var n=this.closed;r.prototype.unsubscribe.call(this),!n&&((e=this.onFinalize)===null||e===void 0||e.call(this))}},t}(U),or=j(function(r){return function(){r(this),this.name="EmptyError",this.message="no elements in sequence"}});function ir(r,t){return new Promise(function(e,n){var o=new w({next:function(i){e(i),o.unsubscribe()},error:n,complete:function(){n(new or)}});r.subscribe(o)})}function sr(r,t){return tr(function(e,n){var o=0;e.subscribe(er(n,function(i){return r.call(t,i,o++)&&n.next(i)}))})}function ur({url:r,project:t,token:e,chunkSize:n},o,i,u){const c={...i??{},projectRef:t};return new B(s=>{const l=new URL(r),a=new WebSocket(`${l.protocol==="https:"?"wss":"ws"}://${l.host}/api/v1/assets/ws`,"contello-file-upload-v1"),p=typeof FileReader<"u"?new FileReader:null;let y=0,b=!1,E=!1;a.onopen=async()=>{const k={type:"init",metadata:{...c,name:o.name,mimeType:o.type,size:o.size},token:e};a.send(JSON.stringify(k));function $(){const m=o.slice(y,y+n);p?p.readAsArrayBuffer(m):m.arrayBuffer().then(h=>{C(h)}).catch(h=>{s.error(h)})}function M(){p?.abort(),a.send(JSON.stringify({type:"done"}))}function lr(){E&&$()}function C(m){a.readyState===WebSocket.OPEN?(a.send(m),y+=m.byteLength,y<o.size?$():M()):(s.error(new Error("WebSocket is closed")),p?.abort())}p&&(p.onload=()=>{p.result&&p.result instanceof ArrayBuffer?C(p.result):M()}),a.onmessage=m=>{const h=JSON.parse(m.data);if(h.type==="ack"){E=!0,lr();return}if(h.type==="progress")return s.next({progress:h.bytesReceived/o.size*100});if(h.type==="done")return h.id?(b=!0,s.next({id:h.id}),s.complete()):s.error(new Error("No asset id received")),a.close();s.error(new Error("WebSocket message with unknown type "+JSON.stringify(h))),a.close()}},a.onerror=k=>s.error(k),a.onclose=()=>{b||s.error(new Error("Connection closed"))};const f=()=>{b||(p?.abort(),a.close(),s.error(new Error("Upload aborted")))};return u?.abort?.addEventListener("abort",f),()=>{u?.abort?.removeEventListener("abort",f),a.close()}})}function cr({url:r,project:t,token:e},n,o,i){return new B(u=>{const c=new FormData;c.append("metadata",JSON.stringify({...o??{},projectRef:t})),c.append("file",n);const s=new XMLHttpRequest;return s.setRequestHeader("Authorization",`Bearer ${e}`),s.open("POST",`${r}/api/v1/assets`,!0),s.upload.onprogress=async l=>{l.lengthComputable&&u.next({progress:l.loaded/l.total*100})},s.onload=async()=>{if(s.status>=200&&s.status<300){const{id:l}=JSON.parse(s.responseText);return u.next({id:l}),u.complete()}u.error(new Error(`${s.status}: ${s.statusText}`))},s.onerror=l=>u.error(l),s.send(c),i?.abort?.addEventListener("abort",()=>s.abort()),()=>s.abort()})}class ar{params;constructor(t){this.params={url:t.url,project:t.project,token:t.token,transport:t.transport||"ws",chunkSize:t.chunkSize||4*1024*1024}}async upload(t,e,n){return ir(this.uploadWithEvents(t,e,n).pipe(sr(o=>"id"in o)))}uploadWithEvents(t,e,n){return this.params.transport==="http"?cr(this.params,t,e,n):ur(this.params,t,e,n)}}v.ContelloUploader=ar,v.UploadAssetRetentionPolicy=S,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED