bruce-models 5.6.9 → 5.7.0

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.
@@ -566,6 +566,12 @@
566
566
  formData.append(key, params.formData[key]);
567
567
  }
568
568
  }
569
+ /**
570
+ * If we support the legacy request and need it for progress, then we diverge there.
571
+ */
572
+ if (window && window["XMLHttpRequest"] && params.onProgress) {
573
+ return legacyUpload(url, params.headers, formData, params.onProgress, params.abortSignal);
574
+ }
569
575
  const res = yield fetch(url, {
570
576
  headers: params.headers,
571
577
  method: "POST",
@@ -576,6 +582,52 @@
576
582
  });
577
583
  }
578
584
  }
585
+ /**
586
+ * Performs a legacy upload with XMLHttpRequest.
587
+ * Unfortunately, this is needed to track progress when it's supported.
588
+ * Fetch doesn't have this capability.
589
+ * @param url
590
+ * @param params
591
+ */
592
+ function legacyUpload(url, headers, formData, onProgress, abortSignal) {
593
+ return new Promise((resolve, reject) => {
594
+ const xhr = new window["XMLHttpRequest"]();
595
+ xhr.open("POST", url, true);
596
+ // Set custom headers.
597
+ if (headers) {
598
+ Object.keys(headers).forEach((key) => {
599
+ let value = headers[key];
600
+ if (!value) {
601
+ value = "";
602
+ }
603
+ xhr.setRequestHeader(key, value);
604
+ });
605
+ }
606
+ // Progress event.
607
+ xhr.upload.onprogress = (event) => {
608
+ if (onProgress && event.lengthComputable) {
609
+ onProgress(event);
610
+ }
611
+ };
612
+ // Success and error handling.
613
+ xhr.onload = () => {
614
+ if (xhr.status >= 200 && xhr.status < 300) {
615
+ resolve(JSON.parse(xhr.responseText));
616
+ }
617
+ else {
618
+ reject(new Error(`Failed to upload: ${xhr.status} ${xhr.statusText}`));
619
+ }
620
+ };
621
+ xhr.onerror = () => reject(new Error("Network error occurred during file upload."));
622
+ if (abortSignal) {
623
+ abortSignal.addEventListener("abort", () => {
624
+ xhr.abort();
625
+ reject(new Error("Upload aborted."));
626
+ });
627
+ }
628
+ xhr.send(formData);
629
+ });
630
+ }
579
631
 
580
632
  (function (MessageBroker) {
581
633
  let EAction;
@@ -14908,7 +14960,7 @@
14908
14960
  })(exports.Scenario || (exports.Scenario = {}));
14909
14961
 
14910
14962
  // This is updated with the package.json version on build.
14911
- const VERSION = "5.6.9";
14963
+ const VERSION = "5.7.0";
14912
14964
 
14913
14965
  exports.VERSION = VERSION;
14914
14966
  exports.AbstractApi = AbstractApi;