@contello/uploader 8.14.0-next.1751836133

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.
@@ -0,0 +1,96 @@
1
+ import { Observable } from 'rxjs';
2
+
3
+ export declare class ContelloUploader {
4
+ private params;
5
+ constructor(params: ContelloUploaderParams);
6
+ upload(file: File, meta?: UploadAssetMetadata | undefined, options?: {
7
+ abort?: AbortSignal;
8
+ } | undefined): Observable<UploadAssetProgress | {
9
+ id: string;
10
+ }>;
11
+ }
12
+
13
+ export declare type ContelloUploaderParams = {
14
+ url: string;
15
+ project: string;
16
+ token: string;
17
+ transport?: 'http' | 'ws';
18
+ chunkSize?: number;
19
+ };
20
+
21
+ export declare type UploadAssetAnnotation = {
22
+ key: string;
23
+ value: string;
24
+ };
25
+
26
+ export declare type UploadAssetConvertTransformation = {
27
+ name: 'convert';
28
+ options: UploadAssetConvertTransformationJpegOptions | UploadAssetConvertTransformationPngOptions | UploadAssetConvertTransformationAvifOptions;
29
+ };
30
+
31
+ export declare type UploadAssetConvertTransformationAvifOptions = {
32
+ format: 'avif';
33
+ options: {
34
+ quality: number;
35
+ lossless: boolean;
36
+ };
37
+ };
38
+
39
+ export declare type UploadAssetConvertTransformationJpegOptions = {
40
+ format: 'jpeg';
41
+ options: {
42
+ quality: number;
43
+ interlace: boolean;
44
+ };
45
+ };
46
+
47
+ export declare type UploadAssetConvertTransformationPngOptions = {
48
+ format: 'png';
49
+ options: {
50
+ compressionLevel: number;
51
+ };
52
+ };
53
+
54
+ export declare type UploadAssetExtractTransformation = {
55
+ name: 'extract';
56
+ options: {
57
+ top: number;
58
+ left: number;
59
+ areaWidth: number;
60
+ areaHeight: number;
61
+ rotate?: 0 | 90 | 180 | 270 | undefined;
62
+ };
63
+ };
64
+
65
+ export declare type UploadAssetFitTransformation = {
66
+ name: 'fit';
67
+ options: {
68
+ width: number;
69
+ height: number;
70
+ };
71
+ };
72
+
73
+ export declare type UploadAssetImageMetadata = {
74
+ transformations: UploadAssetImageTransformation[];
75
+ };
76
+
77
+ export declare type UploadAssetImageTransformation = UploadAssetExtractTransformation | UploadAssetFitTransformation | UploadAssetConvertTransformation;
78
+
79
+ export declare type UploadAssetMetadata = {
80
+ annotations?: UploadAssetAnnotation[] | undefined;
81
+ createdAt?: string | undefined;
82
+ updatedAt?: string | undefined;
83
+ image?: UploadAssetImageMetadata | undefined;
84
+ retentionPolicy?: UploadAssetRetentionPolicy | undefined;
85
+ };
86
+
87
+ export declare type UploadAssetProgress = {
88
+ progress: number;
89
+ };
90
+
91
+ export declare enum UploadAssetRetentionPolicy {
92
+ retain = "retain",
93
+ deleteIfUnused = "deleteIfUnused"
94
+ }
95
+
96
+ export { }
package/dist/index.js ADDED
@@ -0,0 +1,445 @@
1
+ var z = /* @__PURE__ */ ((t) => (t.retain = "retain", t.deleteIfUnused = "deleteIfUnused", t))(z || {}), E = function(t, r) {
2
+ return E = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, n) {
3
+ e.__proto__ = n;
4
+ } || function(e, n) {
5
+ for (var o in n) Object.prototype.hasOwnProperty.call(n, o) && (e[o] = n[o]);
6
+ }, E(t, r);
7
+ };
8
+ function J(t, r) {
9
+ if (typeof r != "function" && r !== null)
10
+ throw new TypeError("Class extends value " + String(r) + " is not a constructor or null");
11
+ E(t, r);
12
+ function e() {
13
+ this.constructor = t;
14
+ }
15
+ t.prototype = r === null ? Object.create(r) : (e.prototype = r.prototype, new e());
16
+ }
17
+ function k(t) {
18
+ var r = typeof Symbol == "function" && Symbol.iterator, e = r && t[r], n = 0;
19
+ if (e) return e.call(t);
20
+ if (t && typeof t.length == "number") return {
21
+ next: function() {
22
+ return t && n >= t.length && (t = void 0), { value: t && t[n++], done: !t };
23
+ }
24
+ };
25
+ throw new TypeError(r ? "Object is not iterable." : "Symbol.iterator is not defined.");
26
+ }
27
+ function _(t, r) {
28
+ var e = typeof Symbol == "function" && t[Symbol.iterator];
29
+ if (!e) return t;
30
+ var n = e.call(t), o, i = [], u;
31
+ try {
32
+ for (; (r === void 0 || r-- > 0) && !(o = n.next()).done; ) i.push(o.value);
33
+ } catch (a) {
34
+ u = { error: a };
35
+ } finally {
36
+ try {
37
+ o && !o.done && (e = n.return) && e.call(n);
38
+ } finally {
39
+ if (u) throw u.error;
40
+ }
41
+ }
42
+ return i;
43
+ }
44
+ function x(t, r, e) {
45
+ if (e || arguments.length === 2) for (var n = 0, o = r.length, i; n < o; n++)
46
+ (i || !(n in r)) && (i || (i = Array.prototype.slice.call(r, 0, n)), i[n] = r[n]);
47
+ return t.concat(i || Array.prototype.slice.call(r));
48
+ }
49
+ function y(t) {
50
+ return typeof t == "function";
51
+ }
52
+ function B(t) {
53
+ var r = function(n) {
54
+ Error.call(n), n.stack = new Error().stack;
55
+ }, e = t(r);
56
+ return e.prototype = Object.create(Error.prototype), e.prototype.constructor = e, e;
57
+ }
58
+ var g = B(function(t) {
59
+ return function(e) {
60
+ t(this), this.message = e ? e.length + ` errors occurred during unsubscription:
61
+ ` + e.map(function(n, o) {
62
+ return o + 1 + ") " + n.toString();
63
+ }).join(`
64
+ `) : "", this.name = "UnsubscriptionError", this.errors = e;
65
+ };
66
+ });
67
+ function U(t, r) {
68
+ if (t) {
69
+ var e = t.indexOf(r);
70
+ 0 <= e && t.splice(e, 1);
71
+ }
72
+ }
73
+ var P = function() {
74
+ function t(r) {
75
+ this.initialTeardown = r, this.closed = !1, this._parentage = null, this._finalizers = null;
76
+ }
77
+ return t.prototype.unsubscribe = function() {
78
+ var r, e, n, o, i;
79
+ if (!this.closed) {
80
+ this.closed = !0;
81
+ var u = this._parentage;
82
+ if (u)
83
+ if (this._parentage = null, Array.isArray(u))
84
+ try {
85
+ for (var a = k(u), s = a.next(); !s.done; s = a.next()) {
86
+ var f = s.value;
87
+ f.remove(this);
88
+ }
89
+ } catch (l) {
90
+ r = { error: l };
91
+ } finally {
92
+ try {
93
+ s && !s.done && (e = a.return) && e.call(a);
94
+ } finally {
95
+ if (r) throw r.error;
96
+ }
97
+ }
98
+ else
99
+ u.remove(this);
100
+ var c = this.initialTeardown;
101
+ if (y(c))
102
+ try {
103
+ c();
104
+ } catch (l) {
105
+ i = l instanceof g ? l.errors : [l];
106
+ }
107
+ var p = this._finalizers;
108
+ if (p) {
109
+ this._finalizers = null;
110
+ try {
111
+ for (var d = k(p), h = d.next(); !h.done; h = d.next()) {
112
+ var b = h.value;
113
+ try {
114
+ j(b);
115
+ } catch (l) {
116
+ i = i ?? [], l instanceof g ? i = x(x([], _(i)), _(l.errors)) : i.push(l);
117
+ }
118
+ }
119
+ } catch (l) {
120
+ n = { error: l };
121
+ } finally {
122
+ try {
123
+ h && !h.done && (o = d.return) && o.call(d);
124
+ } finally {
125
+ if (n) throw n.error;
126
+ }
127
+ }
128
+ }
129
+ if (i)
130
+ throw new g(i);
131
+ }
132
+ }, t.prototype.add = function(r) {
133
+ var e;
134
+ if (r && r !== this)
135
+ if (this.closed)
136
+ j(r);
137
+ else {
138
+ if (r instanceof t) {
139
+ if (r.closed || r._hasParent(this))
140
+ return;
141
+ r._addParent(this);
142
+ }
143
+ (this._finalizers = (e = this._finalizers) !== null && e !== void 0 ? e : []).push(r);
144
+ }
145
+ }, t.prototype._hasParent = function(r) {
146
+ var e = this._parentage;
147
+ return e === r || Array.isArray(e) && e.includes(r);
148
+ }, t.prototype._addParent = function(r) {
149
+ var e = this._parentage;
150
+ this._parentage = Array.isArray(e) ? (e.push(r), e) : e ? [e, r] : r;
151
+ }, t.prototype._removeParent = function(r) {
152
+ var e = this._parentage;
153
+ e === r ? this._parentage = null : Array.isArray(e) && U(e, r);
154
+ }, t.prototype.remove = function(r) {
155
+ var e = this._finalizers;
156
+ e && U(e, r), r instanceof t && r._removeParent(this);
157
+ }, t.EMPTY = function() {
158
+ var r = new t();
159
+ return r.closed = !0, r;
160
+ }(), t;
161
+ }();
162
+ P.EMPTY;
163
+ function L(t) {
164
+ return t instanceof P || t && "closed" in t && y(t.remove) && y(t.add) && y(t.unsubscribe);
165
+ }
166
+ function j(t) {
167
+ y(t) ? t() : t.unsubscribe();
168
+ }
169
+ var H = {
170
+ Promise: void 0
171
+ }, M = {
172
+ setTimeout: function(t, r) {
173
+ for (var e = [], n = 2; n < arguments.length; n++)
174
+ e[n - 2] = arguments[n];
175
+ return setTimeout.apply(void 0, x([t, r], _(e)));
176
+ },
177
+ clearTimeout: function(t) {
178
+ return clearTimeout(t);
179
+ },
180
+ delegate: void 0
181
+ };
182
+ function C(t) {
183
+ M.setTimeout(function() {
184
+ throw t;
185
+ });
186
+ }
187
+ function R() {
188
+ }
189
+ function V(t) {
190
+ t();
191
+ }
192
+ var $ = function(t) {
193
+ J(r, t);
194
+ function r(e) {
195
+ var n = t.call(this) || this;
196
+ return n.isStopped = !1, e ? (n.destination = e, L(e) && e.add(n)) : n.destination = D, n;
197
+ }
198
+ return r.create = function(e, n, o) {
199
+ return new O(e, n, o);
200
+ }, r.prototype.next = function(e) {
201
+ this.isStopped || this._next(e);
202
+ }, r.prototype.error = function(e) {
203
+ this.isStopped || (this.isStopped = !0, this._error(e));
204
+ }, r.prototype.complete = function() {
205
+ this.isStopped || (this.isStopped = !0, this._complete());
206
+ }, r.prototype.unsubscribe = function() {
207
+ this.closed || (this.isStopped = !0, t.prototype.unsubscribe.call(this), this.destination = null);
208
+ }, r.prototype._next = function(e) {
209
+ this.destination.next(e);
210
+ }, r.prototype._error = function(e) {
211
+ try {
212
+ this.destination.error(e);
213
+ } finally {
214
+ this.unsubscribe();
215
+ }
216
+ }, r.prototype._complete = function() {
217
+ try {
218
+ this.destination.complete();
219
+ } finally {
220
+ this.unsubscribe();
221
+ }
222
+ }, r;
223
+ }(P), Y = function() {
224
+ function t(r) {
225
+ this.partialObserver = r;
226
+ }
227
+ return t.prototype.next = function(r) {
228
+ var e = this.partialObserver;
229
+ if (e.next)
230
+ try {
231
+ e.next(r);
232
+ } catch (n) {
233
+ m(n);
234
+ }
235
+ }, t.prototype.error = function(r) {
236
+ var e = this.partialObserver;
237
+ if (e.error)
238
+ try {
239
+ e.error(r);
240
+ } catch (n) {
241
+ m(n);
242
+ }
243
+ else
244
+ m(r);
245
+ }, t.prototype.complete = function() {
246
+ var r = this.partialObserver;
247
+ if (r.complete)
248
+ try {
249
+ r.complete();
250
+ } catch (e) {
251
+ m(e);
252
+ }
253
+ }, t;
254
+ }(), O = function(t) {
255
+ J(r, t);
256
+ function r(e, n, o) {
257
+ var i = t.call(this) || this, u;
258
+ return y(e) || !e ? u = {
259
+ next: e ?? void 0,
260
+ error: n ?? void 0,
261
+ complete: o ?? void 0
262
+ } : u = e, i.destination = new Y(u), i;
263
+ }
264
+ return r;
265
+ }($);
266
+ function m(t) {
267
+ C(t);
268
+ }
269
+ function q(t) {
270
+ throw t;
271
+ }
272
+ var D = {
273
+ closed: !0,
274
+ next: R,
275
+ error: q,
276
+ complete: R
277
+ }, X = function() {
278
+ return typeof Symbol == "function" && Symbol.observable || "@@observable";
279
+ }();
280
+ function N(t) {
281
+ return t;
282
+ }
283
+ function G(t) {
284
+ return t.length === 0 ? N : t.length === 1 ? t[0] : function(e) {
285
+ return t.reduce(function(n, o) {
286
+ return o(n);
287
+ }, e);
288
+ };
289
+ }
290
+ var I = function() {
291
+ function t(r) {
292
+ r && (this._subscribe = r);
293
+ }
294
+ return t.prototype.lift = function(r) {
295
+ var e = new t();
296
+ return e.source = this, e.operator = r, e;
297
+ }, t.prototype.subscribe = function(r, e, n) {
298
+ var o = this, i = Q(r) ? r : new O(r, e, n);
299
+ return V(function() {
300
+ var u = o, a = u.operator, s = u.source;
301
+ i.add(a ? a.call(i, s) : s ? o._subscribe(i) : o._trySubscribe(i));
302
+ }), i;
303
+ }, t.prototype._trySubscribe = function(r) {
304
+ try {
305
+ return this._subscribe(r);
306
+ } catch (e) {
307
+ r.error(e);
308
+ }
309
+ }, t.prototype.forEach = function(r, e) {
310
+ var n = this;
311
+ return e = F(e), new e(function(o, i) {
312
+ var u = new O({
313
+ next: function(a) {
314
+ try {
315
+ r(a);
316
+ } catch (s) {
317
+ i(s), u.unsubscribe();
318
+ }
319
+ },
320
+ error: i,
321
+ complete: o
322
+ });
323
+ n.subscribe(u);
324
+ });
325
+ }, t.prototype._subscribe = function(r) {
326
+ var e;
327
+ return (e = this.source) === null || e === void 0 ? void 0 : e.subscribe(r);
328
+ }, t.prototype[X] = function() {
329
+ return this;
330
+ }, t.prototype.pipe = function() {
331
+ for (var r = [], e = 0; e < arguments.length; e++)
332
+ r[e] = arguments[e];
333
+ return G(r)(this);
334
+ }, t.prototype.toPromise = function(r) {
335
+ var e = this;
336
+ return r = F(r), new r(function(n, o) {
337
+ var i;
338
+ e.subscribe(function(u) {
339
+ return i = u;
340
+ }, function(u) {
341
+ return o(u);
342
+ }, function() {
343
+ return n(i);
344
+ });
345
+ });
346
+ }, t.create = function(r) {
347
+ return new t(r);
348
+ }, t;
349
+ }();
350
+ function F(t) {
351
+ var r;
352
+ return (r = t ?? H.Promise) !== null && r !== void 0 ? r : Promise;
353
+ }
354
+ function K(t) {
355
+ return t && y(t.next) && y(t.error) && y(t.complete);
356
+ }
357
+ function Q(t) {
358
+ return t && t instanceof $ || K(t) && L(t);
359
+ }
360
+ function Z({ url: t, project: r, token: e, chunkSize: n }, o, i, u) {
361
+ const a = { ...i ?? {}, projectId: r };
362
+ return new I((s) => {
363
+ const f = new URL(t), c = new WebSocket(
364
+ `${f.protocol === "https:" ? "wss" : "ws"}://${f.host}/api/v1/assets/ws`,
365
+ "contello-file-upload-v1"
366
+ ), p = new FileReader();
367
+ let d = 0, h = !1, b = !1;
368
+ c.onopen = async () => {
369
+ const S = {
370
+ type: "init",
371
+ file: { name: o.name, type: o.type, size: o.size },
372
+ metadata: a,
373
+ token: e
374
+ };
375
+ c.send(JSON.stringify(S));
376
+ function A() {
377
+ const w = o.slice(d, d + n);
378
+ p.readAsArrayBuffer(w);
379
+ }
380
+ function T() {
381
+ p.abort(), c.send(JSON.stringify({ type: "done" }));
382
+ }
383
+ function W() {
384
+ b && A();
385
+ }
386
+ p.onload = () => {
387
+ c.readyState === WebSocket.OPEN ? p.result && p.result instanceof ArrayBuffer ? (c.send(p.result), d += p.result.byteLength, d < o.size ? A() : T()) : T() : (s.error(new Error("WebSocket is closed")), p.abort());
388
+ }, c.onmessage = (w) => {
389
+ const v = JSON.parse(w.data);
390
+ if (v.type === "ack") {
391
+ b = !0, W();
392
+ return;
393
+ }
394
+ if (v.type === "progress")
395
+ return s.next({ progress: v.bytesReceived / o.size * 100 });
396
+ if (v.type === "done")
397
+ return v.id ? (h = !0, s.next({ id: v.id }), s.complete()) : s.error(new Error("No asset id received")), c.close();
398
+ s.error(new Error("WebSocket message with unknown type " + JSON.stringify(v))), c.close();
399
+ };
400
+ }, c.onerror = (S) => s.error(S), c.onclose = () => {
401
+ h || s.error(new Error("Connection closed"));
402
+ };
403
+ const l = () => {
404
+ h || (p.abort(), c.close(), s.error(new Error("Upload aborted")));
405
+ };
406
+ return u?.abort?.addEventListener("abort", l), () => {
407
+ u?.abort?.removeEventListener("abort", l), c.close();
408
+ };
409
+ });
410
+ }
411
+ function rr({ url: t, project: r, token: e }, n, o, i) {
412
+ return new I((u) => {
413
+ const a = new FormData();
414
+ a.append("metadata", JSON.stringify({ ...o ?? {}, projectId: r })), a.append("file", n);
415
+ const s = new XMLHttpRequest();
416
+ return s.setRequestHeader("Authorization", `Bearer ${e}`), s.open("POST", `${t}/api/v1/assets`, !0), s.upload.onprogress = async (f) => {
417
+ f.lengthComputable && u.next({ progress: f.loaded / f.total * 100 });
418
+ }, s.onload = async () => {
419
+ if (s.status >= 200 && s.status < 300) {
420
+ const { id: f } = JSON.parse(s.responseText);
421
+ return u.next({ id: f }), u.complete();
422
+ }
423
+ u.error(new Error(`${s.status}: ${s.statusText}`));
424
+ }, s.onerror = (f) => u.error(f), s.send(a), i?.abort?.addEventListener("abort", () => s.abort()), () => s.abort();
425
+ });
426
+ }
427
+ class tr {
428
+ params;
429
+ constructor(r) {
430
+ this.params = {
431
+ url: r.url,
432
+ project: r.project,
433
+ token: r.token,
434
+ transport: r.transport || "ws",
435
+ chunkSize: r.chunkSize || 4 * 1024 * 1024
436
+ };
437
+ }
438
+ upload(r, e, n) {
439
+ return this.params.transport === "http" ? rr(this.params, r, e, n) : Z(this.params, r, e, n);
440
+ }
441
+ }
442
+ export {
443
+ tr as ContelloUploader,
444
+ z as UploadAssetRetentionPolicy
445
+ };
@@ -0,0 +1,3 @@
1
+ (function(v,m){typeof exports=="object"&&typeof module<"u"?m(exports):typeof define=="function"&&define.amd?define(["exports"],m):(v=typeof globalThis<"u"?globalThis:v||self,m(v.ContelloUploader={}))})(this,function(v){"use strict";var m=(e=>(e.retain="retain",e.deleteIfUnused="deleteIfUnused",e))(m||{}),w=function(e,r){return w=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,n){t.__proto__=n}||function(t,n){for(var o in n)Object.prototype.hasOwnProperty.call(n,o)&&(t[o]=n[o])},w(e,r)};function k(e,r){if(typeof r!="function"&&r!==null)throw new TypeError("Class extends value "+String(r)+" is not a constructor or null");w(e,r);function t(){this.constructor=e}e.prototype=r===null?Object.create(r):(t.prototype=r.prototype,new t)}function U(e){var r=typeof Symbol=="function"&&Symbol.iterator,t=r&&e[r],n=0;if(t)return t.call(e);if(e&&typeof e.length=="number")return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(r?"Object is not iterable.":"Symbol.iterator is not defined.")}function E(e,r){var t=typeof Symbol=="function"&&e[Symbol.iterator];if(!t)return e;var n=t.call(e),o,i=[],u;try{for(;(r===void 0||r-- >0)&&!(o=n.next()).done;)i.push(o.value)}catch(a){u={error:a}}finally{try{o&&!o.done&&(t=n.return)&&t.call(n)}finally{if(u)throw u.error}}return i}function O(e,r,t){if(t||arguments.length===2)for(var n=0,o=r.length,i;n<o;n++)(i||!(n in r))&&(i||(i=Array.prototype.slice.call(r,0,n)),i[n]=r[n]);return e.concat(i||Array.prototype.slice.call(r))}typeof SuppressedError=="function"&&SuppressedError;function d(e){return typeof e=="function"}function W(e){var r=function(n){Error.call(n),n.stack=new Error().stack},t=e(r);return t.prototype=Object.create(Error.prototype),t.prototype.constructor=t,t}var _=W(function(e){return function(t){e(this),this.message=t?t.length+` errors occurred during unsubscription:
2
+ `+t.map(function(n,o){return o+1+") "+n.toString()}).join(`
3
+ `):"",this.name="UnsubscriptionError",this.errors=t}});function j(e,r){if(e){var t=e.indexOf(r);0<=t&&e.splice(t,1)}}var x=function(){function e(r){this.initialTeardown=r,this.closed=!1,this._parentage=null,this._finalizers=null}return e.prototype.unsubscribe=function(){var r,t,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 a=U(u),s=a.next();!s.done;s=a.next()){var f=s.value;f.remove(this)}}catch(l){r={error:l}}finally{try{s&&!s.done&&(t=a.return)&&t.call(a)}finally{if(r)throw r.error}}else u.remove(this);var c=this.initialTeardown;if(d(c))try{c()}catch(l){i=l instanceof _?l.errors:[l]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var h=U(p),y=h.next();!y.done;y=h.next()){var g=y.value;try{F(g)}catch(l){i=i??[],l instanceof _?i=O(O([],E(i)),E(l.errors)):i.push(l)}}}catch(l){n={error:l}}finally{try{y&&!y.done&&(o=h.return)&&o.call(h)}finally{if(n)throw n.error}}}if(i)throw new _(i)}},e.prototype.add=function(r){var t;if(r&&r!==this)if(this.closed)F(r);else{if(r instanceof e){if(r.closed||r._hasParent(this))return;r._addParent(this)}(this._finalizers=(t=this._finalizers)!==null&&t!==void 0?t:[]).push(r)}},e.prototype._hasParent=function(r){var t=this._parentage;return t===r||Array.isArray(t)&&t.includes(r)},e.prototype._addParent=function(r){var t=this._parentage;this._parentage=Array.isArray(t)?(t.push(r),t):t?[t,r]:r},e.prototype._removeParent=function(r){var t=this._parentage;t===r?this._parentage=null:Array.isArray(t)&&j(t,r)},e.prototype.remove=function(r){var t=this._finalizers;t&&j(t,r),r instanceof e&&r._removeParent(this)},e.EMPTY=function(){var r=new e;return r.closed=!0,r}(),e}();x.EMPTY;function R(e){return e instanceof x||e&&"closed"in e&&d(e.remove)&&d(e.add)&&d(e.unsubscribe)}function F(e){d(e)?e():e.unsubscribe()}var z={Promise:void 0},B={setTimeout:function(e,r){for(var t=[],n=2;n<arguments.length;n++)t[n-2]=arguments[n];return setTimeout.apply(void 0,O([e,r],E(t)))},clearTimeout:function(e){return clearTimeout(e)},delegate:void 0};function H(e){B.setTimeout(function(){throw e})}function J(){}function V(e){e()}var L=function(e){k(r,e);function r(t){var n=e.call(this)||this;return n.isStopped=!1,t?(n.destination=t,R(t)&&t.add(n)):n.destination=D,n}return r.create=function(t,n,o){return new P(t,n,o)},r.prototype.next=function(t){this.isStopped||this._next(t)},r.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},r.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},r.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,e.prototype.unsubscribe.call(this),this.destination=null)},r.prototype._next=function(t){this.destination.next(t)},r.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},r.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},r}(x),Y=function(){function e(r){this.partialObserver=r}return e.prototype.next=function(r){var t=this.partialObserver;if(t.next)try{t.next(r)}catch(n){S(n)}},e.prototype.error=function(r){var t=this.partialObserver;if(t.error)try{t.error(r)}catch(n){S(n)}else S(r)},e.prototype.complete=function(){var r=this.partialObserver;if(r.complete)try{r.complete()}catch(t){S(t)}},e}(),P=function(e){k(r,e);function r(t,n,o){var i=e.call(this)||this,u;return d(t)||!t?u={next:t??void 0,error:n??void 0,complete:o??void 0}:u=t,i.destination=new Y(u),i}return r}(L);function S(e){H(e)}function q(e){throw e}var D={closed:!0,next:J,error:q,complete:J},X=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function N(e){return e}function G(e){return e.length===0?N:e.length===1?e[0]:function(t){return e.reduce(function(n,o){return o(n)},t)}}var $=function(){function e(r){r&&(this._subscribe=r)}return e.prototype.lift=function(r){var t=new e;return t.source=this,t.operator=r,t},e.prototype.subscribe=function(r,t,n){var o=this,i=Q(r)?r:new P(r,t,n);return V(function(){var u=o,a=u.operator,s=u.source;i.add(a?a.call(i,s):s?o._subscribe(i):o._trySubscribe(i))}),i},e.prototype._trySubscribe=function(r){try{return this._subscribe(r)}catch(t){r.error(t)}},e.prototype.forEach=function(r,t){var n=this;return t=C(t),new t(function(o,i){var u=new P({next:function(a){try{r(a)}catch(s){i(s),u.unsubscribe()}},error:i,complete:o});n.subscribe(u)})},e.prototype._subscribe=function(r){var t;return(t=this.source)===null||t===void 0?void 0:t.subscribe(r)},e.prototype[X]=function(){return this},e.prototype.pipe=function(){for(var r=[],t=0;t<arguments.length;t++)r[t]=arguments[t];return G(r)(this)},e.prototype.toPromise=function(r){var t=this;return r=C(r),new r(function(n,o){var i;t.subscribe(function(u){return i=u},function(u){return o(u)},function(){return n(i)})})},e.create=function(r){return new e(r)},e}();function C(e){var r;return(r=e??z.Promise)!==null&&r!==void 0?r:Promise}function K(e){return e&&d(e.next)&&d(e.error)&&d(e.complete)}function Q(e){return e&&e instanceof L||K(e)&&R(e)}function Z({url:e,project:r,token:t,chunkSize:n},o,i,u){const a={...i??{},projectId:r};return new $(s=>{const f=new URL(e),c=new WebSocket(`${f.protocol==="https:"?"wss":"ws"}://${f.host}/api/v1/assets/ws`,"contello-file-upload-v1"),p=new FileReader;let h=0,y=!1,g=!1;c.onopen=async()=>{const A={type:"init",file:{name:o.name,type:o.type,size:o.size},metadata:a,token:t};c.send(JSON.stringify(A));function I(){const T=o.slice(h,h+n);p.readAsArrayBuffer(T)}function M(){p.abort(),c.send(JSON.stringify({type:"done"}))}function tr(){g&&I()}p.onload=()=>{c.readyState===WebSocket.OPEN?p.result&&p.result instanceof ArrayBuffer?(c.send(p.result),h+=p.result.byteLength,h<o.size?I():M()):M():(s.error(new Error("WebSocket is closed")),p.abort())},c.onmessage=T=>{const b=JSON.parse(T.data);if(b.type==="ack"){g=!0,tr();return}if(b.type==="progress")return s.next({progress:b.bytesReceived/o.size*100});if(b.type==="done")return b.id?(y=!0,s.next({id:b.id}),s.complete()):s.error(new Error("No asset id received")),c.close();s.error(new Error("WebSocket message with unknown type "+JSON.stringify(b))),c.close()}},c.onerror=A=>s.error(A),c.onclose=()=>{y||s.error(new Error("Connection closed"))};const l=()=>{y||(p.abort(),c.close(),s.error(new Error("Upload aborted")))};return u?.abort?.addEventListener("abort",l),()=>{u?.abort?.removeEventListener("abort",l),c.close()}})}function rr({url:e,project:r,token:t},n,o,i){return new $(u=>{const a=new FormData;a.append("metadata",JSON.stringify({...o??{},projectId:r})),a.append("file",n);const s=new XMLHttpRequest;return s.setRequestHeader("Authorization",`Bearer ${t}`),s.open("POST",`${e}/api/v1/assets`,!0),s.upload.onprogress=async f=>{f.lengthComputable&&u.next({progress:f.loaded/f.total*100})},s.onload=async()=>{if(s.status>=200&&s.status<300){const{id:f}=JSON.parse(s.responseText);return u.next({id:f}),u.complete()}u.error(new Error(`${s.status}: ${s.statusText}`))},s.onerror=f=>u.error(f),s.send(a),i?.abort?.addEventListener("abort",()=>s.abort()),()=>s.abort()})}class er{params;constructor(r){this.params={url:r.url,project:r.project,token:r.token,transport:r.transport||"ws",chunkSize:r.chunkSize||4*1024*1024}}upload(r,t,n){return this.params.transport==="http"?rr(this.params,r,t,n):Z(this.params,r,t,n)}}v.ContelloUploader=er,v.UploadAssetRetentionPolicy=m,Object.defineProperty(v,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@contello/uploader",
3
+ "scripts": {
4
+ "start": "vite build --watch",
5
+ "build": "rm -rf dist/ && vite build",
6
+ "lint": "eslint . --report-unused-disable-directives --max-warnings 0",
7
+ "patch": "node ci/patcher.js"
8
+ },
9
+ "peerDependencies": {
10
+ "rxjs": ">=5.0.0"
11
+ },
12
+ "devDependencies": {
13
+ "rxjs": "^7.8.2",
14
+ "@types/node": "^24.0.10",
15
+ "@typescript-eslint/eslint-plugin": "^8.35.1",
16
+ "eslint": "^9.30.1",
17
+ "eslint-config-prettier": "^10.1.5",
18
+ "eslint-plugin-import": "^2.32.0",
19
+ "eslint-plugin-prettier": "^5.5.1",
20
+ "npm-run-all": "^4.1.5",
21
+ "typescript": "^5.8.3",
22
+ "typescript-eslint": "^8.35.1",
23
+ "graphql": "^16.11.0",
24
+ "graphql-ws": "^6.0.5",
25
+ "vite": "^7.0.2",
26
+ "vite-plugin-dts": "^4.5.4"
27
+ },
28
+ "author": "admin@entwico.com",
29
+ "license": "MIT",
30
+ "type": "module",
31
+ "files": [
32
+ "dist"
33
+ ],
34
+ "types": "./dist/index.d.ts",
35
+ "exports": {
36
+ ".": {
37
+ "import": "./dist/index.js",
38
+ "require": "./dist/index.umd.cjs"
39
+ }
40
+ },
41
+ "publishConfig": {
42
+ "access": "public",
43
+ "registry": "https://registry.npmjs.org"
44
+ },
45
+ "version": "8.14.0-next.1751836133"
46
+ }