@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 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
- createdAt?: string | undefined;
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
- deleteIfUnused = "deleteIfUnused"
129
+ deleteIfNotUsed = "deleteIfNotUsed"
94
130
  }
95
131
 
96
132
  export { }
package/dist/index.js CHANGED
@@ -1,37 +1,37 @@
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) {
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
- }, E(t, r);
6
+ }, x(r, t);
7
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);
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 = t;
13
+ this.constructor = r;
14
14
  }
15
- t.prototype = r === null ? Object.create(r) : (e.prototype = r.prototype, new e());
15
+ r.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
16
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 {
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 t && n >= t.length && (t = void 0), { value: t && t[n++], done: !t };
22
+ return r && n >= r.length && (r = void 0), { value: r && r[n++], done: !r };
23
23
  }
24
24
  };
25
- throw new TypeError(r ? "Object is not iterable." : "Symbol.iterator is not defined.");
25
+ throw new TypeError(t ? "Object is not iterable." : "Symbol.iterator is not defined.");
26
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;
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 (; (r === void 0 || r-- > 0) && !(o = n.next()).done; ) i.push(o.value);
33
- } catch (a) {
34
- u = { error: a };
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 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));
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 y(t) {
50
- return typeof t == "function";
49
+ function d(r) {
50
+ return typeof r == "function";
51
51
  }
52
- function B(t) {
53
- var r = function(n) {
52
+ function B(r) {
53
+ var t = function(n) {
54
54
  Error.call(n), n.stack = new Error().stack;
55
- }, e = t(r);
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(t) {
58
+ var g = B(function(r) {
59
59
  return function(e) {
60
- t(this), this.message = e ? e.length + ` errors occurred during unsubscription:
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 U(t, r) {
68
- if (t) {
69
- var e = t.indexOf(r);
70
- 0 <= e && t.splice(e, 1);
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 P = function() {
74
- function t(r) {
75
- this.initialTeardown = r, this.closed = !1, this._parentage = null, this._finalizers = null;
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 t.prototype.unsubscribe = function() {
78
- var r, e, n, o, i;
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 a = k(u), s = a.next(); !s.done; s = a.next()) {
86
- var f = s.value;
87
- f.remove(this);
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 (l) {
90
- r = { error: l };
89
+ } catch (f) {
90
+ t = { error: f };
91
91
  } finally {
92
92
  try {
93
- s && !s.done && (e = a.return) && e.call(a);
93
+ s && !s.done && (e = c.return) && e.call(c);
94
94
  } finally {
95
- if (r) throw r.error;
95
+ if (t) throw t.error;
96
96
  }
97
97
  }
98
98
  else
99
99
  u.remove(this);
100
- var c = this.initialTeardown;
101
- if (y(c))
100
+ var a = this.initialTeardown;
101
+ if (d(a))
102
102
  try {
103
- c();
104
- } catch (l) {
105
- i = l instanceof g ? l.errors : [l];
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 d = k(p), h = d.next(); !h.done; h = d.next()) {
112
- var b = h.value;
111
+ for (var y = F(p), b = y.next(); !b.done; b = y.next()) {
112
+ var m = b.value;
113
113
  try {
114
- j(b);
115
- } catch (l) {
116
- i = i ?? [], l instanceof g ? i = x(x([], _(i)), _(l.errors)) : i.push(l);
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 (l) {
120
- n = { error: l };
119
+ } catch (f) {
120
+ n = { error: f };
121
121
  } finally {
122
122
  try {
123
- h && !h.done && (o = d.return) && o.call(d);
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
- }, t.prototype.add = function(r) {
132
+ }, r.prototype.add = function(t) {
133
133
  var e;
134
- if (r && r !== this)
134
+ if (t && t !== this)
135
135
  if (this.closed)
136
- j(r);
136
+ L(t);
137
137
  else {
138
- if (r instanceof t) {
139
- if (r.closed || r._hasParent(this))
138
+ if (t instanceof r) {
139
+ if (t.closed || t._hasParent(this))
140
140
  return;
141
- r._addParent(this);
141
+ t._addParent(this);
142
142
  }
143
- (this._finalizers = (e = this._finalizers) !== null && e !== void 0 ? e : []).push(r);
143
+ (this._finalizers = (e = this._finalizers) !== null && e !== void 0 ? e : []).push(t);
144
144
  }
145
- }, t.prototype._hasParent = function(r) {
145
+ }, r.prototype._hasParent = function(t) {
146
146
  var e = this._parentage;
147
- return e === r || Array.isArray(e) && e.includes(r);
148
- }, t.prototype._addParent = function(r) {
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(r), e) : e ? [e, r] : r;
151
- }, t.prototype._removeParent = function(r) {
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 === r ? this._parentage = null : Array.isArray(e) && U(e, r);
154
- }, t.prototype.remove = function(r) {
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 && 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;
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
- P.EMPTY;
163
- function L(t) {
164
- return t instanceof P || t && "closed" in t && y(t.remove) && y(t.add) && y(t.unsubscribe);
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 j(t) {
167
- y(t) ? t() : t.unsubscribe();
166
+ function L(r) {
167
+ d(r) ? r() : r.unsubscribe();
168
168
  }
169
- var H = {
169
+ var M = {
170
170
  Promise: void 0
171
- }, M = {
172
- setTimeout: function(t, r) {
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, x([t, r], _(e)));
175
+ return setTimeout.apply(void 0, _([r, t], O(e)));
176
176
  },
177
- clearTimeout: function(t) {
178
- return clearTimeout(t);
177
+ clearTimeout: function(r) {
178
+ return clearTimeout(r);
179
179
  },
180
180
  delegate: void 0
181
181
  };
182
- function C(t) {
183
- M.setTimeout(function() {
184
- throw t;
182
+ function q(r) {
183
+ V.setTimeout(function() {
184
+ throw r;
185
185
  });
186
186
  }
187
- function R() {
187
+ function W() {
188
188
  }
189
- function V(t) {
190
- t();
189
+ function Y(r) {
190
+ r();
191
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;
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 r.create = function(e, n, o) {
199
- return new O(e, n, o);
200
- }, r.prototype.next = function(e) {
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
- }, r.prototype.error = function(e) {
202
+ }, t.prototype.error = function(e) {
203
203
  this.isStopped || (this.isStopped = !0, this._error(e));
204
- }, r.prototype.complete = function() {
204
+ }, t.prototype.complete = function() {
205
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) {
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
- }, r.prototype._error = function(e) {
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
- }, r.prototype._complete = function() {
216
+ }, t.prototype._complete = function() {
217
217
  try {
218
218
  this.destination.complete();
219
219
  } finally {
220
220
  this.unsubscribe();
221
221
  }
222
- }, r;
223
- }(P), Y = function() {
224
- function t(r) {
225
- this.partialObserver = r;
222
+ }, t;
223
+ }(A), C = function() {
224
+ function r(t) {
225
+ this.partialObserver = t;
226
226
  }
227
- return t.prototype.next = function(r) {
227
+ return r.prototype.next = function(t) {
228
228
  var e = this.partialObserver;
229
229
  if (e.next)
230
230
  try {
231
- e.next(r);
231
+ e.next(t);
232
232
  } catch (n) {
233
- m(n);
233
+ S(n);
234
234
  }
235
- }, t.prototype.error = function(r) {
235
+ }, r.prototype.error = function(t) {
236
236
  var e = this.partialObserver;
237
237
  if (e.error)
238
238
  try {
239
- e.error(r);
239
+ e.error(t);
240
240
  } catch (n) {
241
- m(n);
241
+ S(n);
242
242
  }
243
243
  else
244
- m(r);
245
- }, t.prototype.complete = function() {
246
- var r = this.partialObserver;
247
- if (r.complete)
244
+ S(t);
245
+ }, r.prototype.complete = function() {
246
+ var t = this.partialObserver;
247
+ if (t.complete)
248
248
  try {
249
- r.complete();
249
+ t.complete();
250
250
  } catch (e) {
251
- m(e);
251
+ S(e);
252
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 = {
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 Y(u), i;
262
+ } : u = e, i.destination = new C(u), i;
263
263
  }
264
- return r;
265
- }($);
266
- function m(t) {
267
- C(t);
264
+ return t;
265
+ }(T);
266
+ function S(r) {
267
+ q(r);
268
268
  }
269
- function q(t) {
270
- throw t;
269
+ function D(r) {
270
+ throw r;
271
271
  }
272
- var D = {
272
+ var N = {
273
273
  closed: !0,
274
- next: R,
275
- error: q,
276
- complete: R
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 N(t) {
281
- return t;
280
+ function G(r) {
281
+ return r;
282
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) {
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 I = function() {
291
- function t(r) {
292
- r && (this._subscribe = r);
290
+ var $ = function() {
291
+ function r(t) {
292
+ t && (this._subscribe = t);
293
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));
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
- }, t.prototype._trySubscribe = function(r) {
303
+ }, r.prototype._trySubscribe = function(t) {
304
304
  try {
305
- return this._subscribe(r);
305
+ return this._subscribe(t);
306
306
  } catch (e) {
307
- r.error(e);
307
+ t.error(e);
308
308
  }
309
- }, t.prototype.forEach = function(r, e) {
309
+ }, r.prototype.forEach = function(t, e) {
310
310
  var n = this;
311
- return e = F(e), new e(function(o, i) {
312
- var u = new O({
313
- next: function(a) {
311
+ return e = z(e), new e(function(o, i) {
312
+ var u = new w({
313
+ next: function(c) {
314
314
  try {
315
- r(a);
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
- }, t.prototype._subscribe = function(r) {
325
+ }, r.prototype._subscribe = function(t) {
326
326
  var e;
327
- return (e = this.source) === null || e === void 0 ? void 0 : e.subscribe(r);
328
- }, t.prototype[X] = function() {
327
+ return (e = this.source) === null || e === void 0 ? void 0 : e.subscribe(t);
328
+ }, r.prototype[X] = function() {
329
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) {
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 r = F(r), new r(function(n, o) {
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
- }, t.create = function(r) {
347
- return new t(r);
348
- }, t;
346
+ }, r.create = function(t) {
347
+ return new r(t);
348
+ }, r;
349
349
  }();
350
- function F(t) {
351
- var r;
352
- return (r = t ?? H.Promise) !== null && r !== void 0 ? r : Promise;
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 K(t) {
355
- return t && y(t.next) && y(t.error) && y(t.complete);
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 Q(t) {
358
- return t && t instanceof $ || K(t) && L(t);
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 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`,
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 d = 0, h = !1, b = !1;
368
- c.onopen = async () => {
369
- const S = {
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
- file: { name: o.name, type: o.type, size: o.size },
372
- metadata: a,
452
+ metadata: {
453
+ ...c,
454
+ name: o.name,
455
+ mimeType: o.type,
456
+ size: o.size
457
+ },
373
458
  token: e
374
459
  };
375
- c.send(JSON.stringify(S));
376
- function A() {
377
- const w = o.slice(d, d + n);
378
- p.readAsArrayBuffer(w);
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 T() {
381
- p.abort(), c.send(JSON.stringify({ type: "done" }));
469
+ function U() {
470
+ p?.abort(), a.send(JSON.stringify({ type: "done" }));
382
471
  }
383
- function W() {
384
- b && A();
472
+ function H() {
473
+ m && k();
385
474
  }
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();
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 (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();
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
- }, c.onerror = (S) => s.error(S), c.onclose = () => {
401
- h || s.error(new Error("Connection closed"));
492
+ }, a.onerror = (E) => s.error(E), a.onclose = () => {
493
+ b || s.error(new Error("Connection closed"));
402
494
  };
403
- const l = () => {
404
- h || (p.abort(), c.close(), s.error(new Error("Upload aborted")));
495
+ const f = () => {
496
+ b || (p?.abort(), a.close(), s.error(new Error("Upload aborted")));
405
497
  };
406
- return u?.abort?.addEventListener("abort", l), () => {
407
- u?.abort?.removeEventListener("abort", l), c.close();
498
+ return u?.abort?.addEventListener("abort", f), () => {
499
+ u?.abort?.removeEventListener("abort", f), a.close();
408
500
  };
409
501
  });
410
502
  }
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);
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", `${t}/api/v1/assets`, !0), s.upload.onprogress = async (f) => {
417
- f.lengthComputable && u.next({ progress: f.loaded / f.total * 100 });
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: f } = JSON.parse(s.responseText);
421
- return u.next({ id: f }), u.complete();
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 = (f) => u.error(f), s.send(a), i?.abort?.addEventListener("abort", () => s.abort()), () => s.abort();
516
+ }, s.onerror = (l) => u.error(l), s.send(c), i?.abort?.addEventListener("abort", () => s.abort()), () => s.abort();
425
517
  });
426
518
  }
427
- class tr {
519
+ class ar {
428
520
  params;
429
- constructor(r) {
521
+ constructor(t) {
430
522
  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
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(r, e, n) {
439
- return this.params.transport === "http" ? rr(this.params, r, e, n) : Z(this.params, r, e, n);
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
- tr as ContelloUploader,
444
- z as UploadAssetRetentionPolicy
538
+ ar as ContelloUploader,
539
+ I as UploadAssetRetentionPolicy
445
540
  };
@@ -1,3 +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"})});
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
@@ -42,5 +42,5 @@
42
42
  "access": "public",
43
43
  "registry": "https://registry.npmjs.org"
44
44
  },
45
- "version": "8.16.0"
45
+ "version": "8.17.0-next.1753180901"
46
46
  }