@contello/uploader 8.16.0-next.1753095146 → 8.16.0-next.1753102198

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
@@ -108,11 +108,16 @@ export declare type UploadAssetImageMetadata = {
108
108
  export declare type UploadAssetImageTransformation = UploadAssetExtractTransformation | UploadAssetFitTransformation | UploadAssetConvertTransformation;
109
109
 
110
110
  export declare type UploadAssetMetadata = {
111
+ name?: string | undefined;
112
+ mimeType?: string | undefined;
113
+ size?: number | undefined;
111
114
  annotations?: UploadAssetAnnotation[] | undefined;
112
- createdAt?: string | undefined;
113
- updatedAt?: string | undefined;
115
+ collectionRefs?: string[] | undefined;
114
116
  image?: UploadAssetImageMetadata | undefined;
115
117
  retentionPolicy?: UploadAssetRetentionPolicy | undefined;
118
+ generatePreview?: boolean | undefined;
119
+ createdAt?: string | undefined;
120
+ updatedAt?: string | undefined;
116
121
  };
117
122
 
118
123
  export declare type UploadAssetProgress = {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- var H = /* @__PURE__ */ ((r) => (r.retain = "retain", r.deleteIfUnused = "deleteIfUnused", r))(H || {}), x = function(r, t) {
1
+ var I = /* @__PURE__ */ ((r) => (r.retain = "retain", r.deleteIfUnused = "deleteIfUnused", r))(I || {}), x = function(r, t) {
2
2
  return x = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(e, n) {
3
3
  e.__proto__ = n;
4
4
  } || function(e, n) {
@@ -14,7 +14,7 @@ function P(r, t) {
14
14
  }
15
15
  r.prototype = t === null ? Object.create(t) : (e.prototype = t.prototype, new e());
16
16
  }
17
- function R(r) {
17
+ function F(r) {
18
18
  var t = typeof Symbol == "function" && Symbol.iterator, e = t && r[t], n = 0;
19
19
  if (e) return e.call(r);
20
20
  if (r && typeof r.length == "number") return {
@@ -82,7 +82,7 @@ var A = function() {
82
82
  if (u)
83
83
  if (this._parentage = null, Array.isArray(u))
84
84
  try {
85
- for (var c = R(u), s = c.next(); !s.done; s = c.next()) {
85
+ for (var c = F(u), s = c.next(); !s.done; s = c.next()) {
86
86
  var l = s.value;
87
87
  l.remove(this);
88
88
  }
@@ -108,7 +108,7 @@ var A = function() {
108
108
  if (p) {
109
109
  this._finalizers = null;
110
110
  try {
111
- for (var y = R(p), b = y.next(); !b.done; b = y.next()) {
111
+ for (var y = F(p), b = y.next(); !b.done; b = y.next()) {
112
112
  var m = b.value;
113
113
  try {
114
114
  L(m);
@@ -160,7 +160,7 @@ var A = function() {
160
160
  }(), r;
161
161
  }();
162
162
  A.EMPTY;
163
- function I(r) {
163
+ function J(r) {
164
164
  return r instanceof A || r && "closed" in r && d(r.remove) && d(r.add) && d(r.unsubscribe);
165
165
  }
166
166
  function L(r) {
@@ -193,7 +193,7 @@ var T = function(r) {
193
193
  P(t, r);
194
194
  function t(e) {
195
195
  var n = r.call(this) || this;
196
- return n.isStopped = !1, e ? (n.destination = e, I(e) && e.add(n)) : n.destination = X, n;
196
+ return n.isStopped = !1, e ? (n.destination = e, J(e) && e.add(n)) : n.destination = X, n;
197
197
  }
198
198
  return t.create = function(e, n, o) {
199
199
  return new w(e, n, o);
@@ -287,7 +287,7 @@ function N(r) {
287
287
  }, e);
288
288
  };
289
289
  }
290
- var J = function() {
290
+ var $ = function() {
291
291
  function r(t) {
292
292
  t && (this._subscribe = t);
293
293
  }
@@ -355,7 +355,7 @@ function Q(r) {
355
355
  return r && d(r.next) && d(r.error) && d(r.complete);
356
356
  }
357
357
  function Z(r) {
358
- return r && r instanceof T || Q(r) && I(r);
358
+ return r && r instanceof T || Q(r) && J(r);
359
359
  }
360
360
  function rr(r) {
361
361
  return d(r?.lift);
@@ -439,8 +439,8 @@ function sr(r, t) {
439
439
  });
440
440
  }
441
441
  function ur({ url: r, project: t, token: e, chunkSize: n }, o, i, u) {
442
- const c = { ...i ?? {}, projectId: t };
443
- return new J((s) => {
442
+ const c = { ...i ?? {}, projectRef: t };
443
+ return new $((s) => {
444
444
  const l = new URL(r), a = new WebSocket(
445
445
  `${l.protocol === "https:" ? "wss" : "ws"}://${l.host}/api/v1/assets/ws`,
446
446
  "contello-file-upload-v1"
@@ -449,15 +449,19 @@ function ur({ url: r, project: t, token: e, chunkSize: n }, o, i, u) {
449
449
  a.onopen = async () => {
450
450
  const E = {
451
451
  type: "init",
452
- file: { name: o.name, type: o.type, size: o.size },
453
- metadata: c,
452
+ metadata: {
453
+ ...c,
454
+ name: o.name,
455
+ mimeType: o.type,
456
+ size: o.size
457
+ },
454
458
  token: e
455
459
  };
456
460
  a.send(JSON.stringify(E));
457
461
  function k() {
458
462
  const v = o.slice(y, y + n);
459
463
  p ? p.readAsArrayBuffer(v) : v.arrayBuffer().then((h) => {
460
- F(h);
464
+ R(h);
461
465
  }).catch((h) => {
462
466
  s.error(h);
463
467
  });
@@ -465,18 +469,18 @@ function ur({ url: r, project: t, token: e, chunkSize: n }, o, i, u) {
465
469
  function U() {
466
470
  p?.abort(), a.send(JSON.stringify({ type: "done" }));
467
471
  }
468
- function $() {
472
+ function H() {
469
473
  m && k();
470
474
  }
471
- function F(v) {
475
+ function R(v) {
472
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());
473
477
  }
474
478
  p && (p.onload = () => {
475
- p.result && p.result instanceof ArrayBuffer ? F(p.result) : U();
479
+ p.result && p.result instanceof ArrayBuffer ? R(p.result) : U();
476
480
  }), a.onmessage = (v) => {
477
481
  const h = JSON.parse(v.data);
478
482
  if (h.type === "ack") {
479
- m = !0, $();
483
+ m = !0, H();
480
484
  return;
481
485
  }
482
486
  if (h.type === "progress")
@@ -497,9 +501,9 @@ function ur({ url: r, project: t, token: e, chunkSize: n }, o, i, u) {
497
501
  });
498
502
  }
499
503
  function cr({ url: r, project: t, token: e }, n, o, i) {
500
- return new J((u) => {
504
+ return new $((u) => {
501
505
  const c = new FormData();
502
- c.append("metadata", JSON.stringify({ ...o ?? {}, projectId: t })), c.append("file", n);
506
+ c.append("metadata", JSON.stringify({ ...o ?? {}, projectRef: t })), c.append("file", n);
503
507
  const s = new XMLHttpRequest();
504
508
  return s.setRequestHeader("Authorization", `Bearer ${e}`), s.open("POST", `${r}/api/v1/assets`, !0), s.upload.onprogress = async (l) => {
505
509
  l.lengthComputable && u.next({ progress: l.loaded / l.total * 100 });
@@ -532,5 +536,5 @@ class ar {
532
536
  }
533
537
  export {
534
538
  ar as ContelloUploader,
535
- H as UploadAssetRetentionPolicy
539
+ I as UploadAssetRetentionPolicy
536
540
  };
@@ -1,3 +1,3 @@
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.deleteIfUnused="deleteIfUnused",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 j(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 h(r){return typeof r=="function"}function F(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 A=F(function(r){return function(e){r(this),this.message=e?e.length+` errors occurred during unsubscription:
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.deleteIfUnused="deleteIfUnused",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
2
  `+e.map(function(n,o){return o+1+") "+n.toString()}).join(`
3
- `):"",this.name="UnsubscriptionError",this.errors=e}});function R(r,t){if(r){var e=r.indexOf(t);0<=e&&r.splice(e,1)}}var T=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=j(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(h(a))try{a()}catch(f){i=f instanceof A?f.errors:[f]}var p=this._finalizers;if(p){this._finalizers=null;try{for(var y=j(p),b=y.next();!b.done;b=y.next()){var E=b.value;try{W(E)}catch(f){i=i??[],f instanceof A?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 A(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)&&R(e,t)},r.prototype.remove=function(t){var e=this._finalizers;e&&R(e,t),t instanceof r&&t._removeParent(this)},r.EMPTY=function(){var t=new r;return t.closed=!0,t}(),r}();T.EMPTY;function L(r){return r instanceof T||r&&"closed"in r&&h(r.remove)&&h(r.add)&&h(r.unsubscribe)}function W(r){h(r)?r():r.unsubscribe()}var C={Promise:void 0},H={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){H.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=X,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}(T),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 h(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 X={closed:!0,next:z,error:D,complete:z},G=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function K(r){return r}function N(r){return r.length===0?K: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=I(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[G]=function(){return this},r.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return N(t)(this)},r.prototype.toPromise=function(t){var e=this;return t=I(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 I(r){var t;return(t=r??C.Promise)!==null&&t!==void 0?t:Promise}function Q(r){return r&&h(r.next)&&h(r.error)&&h(r.complete)}function Z(r){return r&&r instanceof U||Q(r)&&L(r)}function rr(r){return h(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=F(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??{},projectId: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",file:{name:o.name,type:o.type,size:o.size},metadata:c,token:e};a.send(JSON.stringify(k));function J(){const m=o.slice(y,y+n);p?p.readAsArrayBuffer(m):m.arrayBuffer().then(d=>{M(d)}).catch(d=>{s.error(d)})}function $(){p?.abort(),a.send(JSON.stringify({type:"done"}))}function lr(){E&&J()}function M(m){a.readyState===WebSocket.OPEN?(a.send(m),y+=m.byteLength,y<o.size?J():$()):(s.error(new Error("WebSocket is closed")),p?.abort())}p&&(p.onload=()=>{p.result&&p.result instanceof ArrayBuffer?M(p.result):$()}),a.onmessage=m=>{const d=JSON.parse(m.data);if(d.type==="ack"){E=!0,lr();return}if(d.type==="progress")return s.next({progress:d.bytesReceived/o.size*100});if(d.type==="done")return d.id?(b=!0,s.next({id:d.id}),s.complete()):s.error(new Error("No asset id received")),a.close();s.error(new Error("WebSocket message with unknown type "+JSON.stringify(d))),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??{},projectId: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"})});
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=X,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 X={closed:!0,next:z,error:D,complete:z},G=function(){return typeof Symbol=="function"&&Symbol.observable||"@@observable"}();function K(r){return r}function N(r){return r.length===0?K: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[G]=function(){return this},r.prototype.pipe=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return N(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-next.1753095146"
45
+ "version": "8.16.0-next.1753102198"
46
46
  }