@bytescale/sdk 3.27.0 → 3.29.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.
@@ -44,6 +44,7 @@ __lib_require__.d(__lib_exports__, {
44
44
  "BinaryResult": function() { return /* reexport */ BinaryResult; },
45
45
  "BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
46
46
  "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
47
+ "BytescaleGenericError": function() { return /* reexport */ BytescaleGenericError; },
47
48
  "CancelledError": function() { return /* reexport */ CancelledError; },
48
49
  "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
49
50
  "FileApi": function() { return /* reexport */ FileApi; },
@@ -55,6 +56,7 @@ __lib_require__.d(__lib_exports__, {
55
56
  "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
56
57
  "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
57
58
  "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
59
+ "encodeBytescaleQuerystringKVP": function() { return /* reexport */ encodeBytescaleQuerystringKVP; },
58
60
  "querystring": function() { return /* reexport */ querystring; }
59
61
  });
60
62
 
@@ -549,8 +551,10 @@ var BaseAPI = /*#__PURE__*/function () {
549
551
  }
550
552
  // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
551
553
  // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
552
- // this error will appear from any intermediary service failure.
553
- throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
554
+ // this error will appear from any intermediary service failure. Also occurs when calling ProcessFile for an
555
+ // asynchronous media job, where the transformation is initiated using the primary artifact: in this instance,
556
+ // a 404 JSON response is returned containing the transformation job until it completes.
557
+ throw new BytescaleGenericError(response, errorText, errorJson);
554
558
  });
555
559
  }
556
560
  }, function (_result2) {
@@ -577,18 +581,39 @@ var CancelledError = /*#__PURE__*/function (_Error) {
577
581
  }
578
582
  return runtime_createClass(CancelledError);
579
583
  }( /*#__PURE__*/_wrapNativeSuper(Error));
580
- var BytescaleApiError = /*#__PURE__*/function (_Error2) {
581
- _inherits(BytescaleApiError, _Error2);
582
- var _super2 = _createSuper(BytescaleApiError);
583
- function BytescaleApiError(response) {
584
+ /**
585
+ * Thrown when the Bytescale API cannot be reached or when an error is returned that cannot be parsed as a JSON error response.
586
+ */
587
+ var BytescaleGenericError = /*#__PURE__*/function (_Error2) {
588
+ _inherits(BytescaleGenericError, _Error2);
589
+ var _super2 = _createSuper(BytescaleGenericError);
590
+ function BytescaleGenericError(response, responseText, responseJson) {
584
591
  var _this6;
585
- runtime_classCallCheck(this, BytescaleApiError);
586
- _this6 = _super2.call(this, response.error.message);
587
- _this6.name = "BytescaleApiError";
588
- _this6.errorCode = response.error.code;
589
- _this6.details = response.error.details;
592
+ runtime_classCallCheck(this, BytescaleGenericError);
593
+ _this6 = _super2.call(this, "Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
594
+ _this6.response = response;
595
+ _this6.responseText = responseText;
596
+ _this6.responseJson = responseJson;
597
+ _this6.name = "BytescaleGenericError";
590
598
  return _this6;
591
599
  }
600
+ return runtime_createClass(BytescaleGenericError);
601
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
602
+ /**
603
+ * Thrown when the Bytescale API returns a JSON error response.
604
+ */
605
+ var BytescaleApiError = /*#__PURE__*/function (_Error3) {
606
+ _inherits(BytescaleApiError, _Error3);
607
+ var _super3 = _createSuper(BytescaleApiError);
608
+ function BytescaleApiError(response) {
609
+ var _this7;
610
+ runtime_classCallCheck(this, BytescaleApiError);
611
+ _this7 = _super3.call(this, response.error.message);
612
+ _this7.name = "BytescaleApiError";
613
+ _this7.errorCode = response.error.code;
614
+ _this7.details = response.error.details;
615
+ return _this7;
616
+ }
592
617
  return runtime_createClass(BytescaleApiError);
593
618
  }( /*#__PURE__*/_wrapNativeSuper(Error));
594
619
  function querystring(params) {
@@ -603,7 +628,20 @@ function querystringSingleKey(key, value) {
603
628
  // Matches 'array' or 'object' (which we want).
604
629
  return querystring(value);
605
630
  }
606
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
631
+ return encodeBytescaleQuerystringKVP(key, String(value));
632
+ }
633
+ /**
634
+ * Handles artifacts specially as these must use "/" instead of "%2F" in order for relative paths within the artifact's
635
+ * contents to work (assumes user has replaced "?" with "!"). For example, M3U8 artifacts that contain relative URLs to
636
+ * other M3U8s and/or media segments will only work if the user replaces "?" with "!" in the URL _and_ the artifact
637
+ * query param value has been written using "/" instead of "%2F", as this then means the URLs become relative to the
638
+ * artifact, as opposed to the file path.
639
+ */
640
+ function encodeBytescaleQuerystringKVP(key, value) {
641
+ if (key === "a" || key === "artifact") {
642
+ return "".concat(key, "=").concat(encodeURIComponent(value).replace(/%2F/g, "/"));
643
+ }
644
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
607
645
  }
608
646
  var JSONApiResponse = /*#__PURE__*/function () {
609
647
  function JSONApiResponse(raw) {
@@ -614,8 +652,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
614
652
  key: "value",
615
653
  value: function value() {
616
654
  try {
617
- var _this8 = this;
618
- return runtime_await(_this8.raw.json());
655
+ var _this9 = this;
656
+ return runtime_await(_this9.raw.json());
619
657
  } catch (e) {
620
658
  return Promise.reject(e);
621
659
  }
@@ -656,8 +694,8 @@ var BinaryResult = /*#__PURE__*/function () {
656
694
  key: "text",
657
695
  value: function text() {
658
696
  try {
659
- var _this10 = this;
660
- return runtime_await(_this10.raw.text());
697
+ var _this11 = this;
698
+ return runtime_await(_this11.raw.text());
661
699
  } catch (e) {
662
700
  return Promise.reject(e);
663
701
  }
@@ -666,8 +704,8 @@ var BinaryResult = /*#__PURE__*/function () {
666
704
  key: "blob",
667
705
  value: function blob() {
668
706
  try {
669
- var _this12 = this;
670
- return runtime_await(_this12.raw.blob());
707
+ var _this13 = this;
708
+ return runtime_await(_this13.raw.blob());
671
709
  } catch (e) {
672
710
  return Promise.reject(e);
673
711
  }
@@ -676,8 +714,8 @@ var BinaryResult = /*#__PURE__*/function () {
676
714
  key: "json",
677
715
  value: function json() {
678
716
  try {
679
- var _this14 = this;
680
- return runtime_await(_this14.raw.json());
717
+ var _this15 = this;
718
+ return runtime_await(_this15.raw.json());
681
719
  } catch (e) {
682
720
  return Promise.reject(e);
683
721
  }
@@ -1732,7 +1770,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1732
1770
  var _ref4 = _slicedToArray(_ref3, 2),
1733
1771
  key = _ref4[0],
1734
1772
  value = _ref4[1];
1735
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1773
+ return encodeBytescaleQuerystringKVP(key, value);
1736
1774
  }).join("&"));
1737
1775
  }
1738
1776
  }]);
@@ -29,6 +29,7 @@ __lib_require__.d(__lib_exports__, {
29
29
  "BinaryResult": function() { return /* reexport */ BinaryResult; },
30
30
  "BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
31
31
  "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
32
+ "BytescaleGenericError": function() { return /* reexport */ BytescaleGenericError; },
32
33
  "CancelledError": function() { return /* reexport */ CancelledError; },
33
34
  "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
34
35
  "FileApi": function() { return /* reexport */ FileApi; },
@@ -40,6 +41,7 @@ __lib_require__.d(__lib_exports__, {
40
41
  "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
41
42
  "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
42
43
  "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
44
+ "encodeBytescaleQuerystringKVP": function() { return /* reexport */ encodeBytescaleQuerystringKVP; },
43
45
  "querystring": function() { return /* reexport */ querystring; }
44
46
  });
45
47
 
@@ -534,8 +536,10 @@ var BaseAPI = /*#__PURE__*/function () {
534
536
  }
535
537
  // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
536
538
  // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
537
- // this error will appear from any intermediary service failure.
538
- throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
539
+ // this error will appear from any intermediary service failure. Also occurs when calling ProcessFile for an
540
+ // asynchronous media job, where the transformation is initiated using the primary artifact: in this instance,
541
+ // a 404 JSON response is returned containing the transformation job until it completes.
542
+ throw new BytescaleGenericError(response, errorText, errorJson);
539
543
  });
540
544
  }
541
545
  }, function (_result2) {
@@ -562,18 +566,39 @@ var CancelledError = /*#__PURE__*/function (_Error) {
562
566
  }
563
567
  return runtime_createClass(CancelledError);
564
568
  }( /*#__PURE__*/_wrapNativeSuper(Error));
565
- var BytescaleApiError = /*#__PURE__*/function (_Error2) {
566
- _inherits(BytescaleApiError, _Error2);
567
- var _super2 = _createSuper(BytescaleApiError);
568
- function BytescaleApiError(response) {
569
+ /**
570
+ * Thrown when the Bytescale API cannot be reached or when an error is returned that cannot be parsed as a JSON error response.
571
+ */
572
+ var BytescaleGenericError = /*#__PURE__*/function (_Error2) {
573
+ _inherits(BytescaleGenericError, _Error2);
574
+ var _super2 = _createSuper(BytescaleGenericError);
575
+ function BytescaleGenericError(response, responseText, responseJson) {
569
576
  var _this6;
570
- runtime_classCallCheck(this, BytescaleApiError);
571
- _this6 = _super2.call(this, response.error.message);
572
- _this6.name = "BytescaleApiError";
573
- _this6.errorCode = response.error.code;
574
- _this6.details = response.error.details;
577
+ runtime_classCallCheck(this, BytescaleGenericError);
578
+ _this6 = _super2.call(this, "Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
579
+ _this6.response = response;
580
+ _this6.responseText = responseText;
581
+ _this6.responseJson = responseJson;
582
+ _this6.name = "BytescaleGenericError";
575
583
  return _this6;
576
584
  }
585
+ return runtime_createClass(BytescaleGenericError);
586
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
587
+ /**
588
+ * Thrown when the Bytescale API returns a JSON error response.
589
+ */
590
+ var BytescaleApiError = /*#__PURE__*/function (_Error3) {
591
+ _inherits(BytescaleApiError, _Error3);
592
+ var _super3 = _createSuper(BytescaleApiError);
593
+ function BytescaleApiError(response) {
594
+ var _this7;
595
+ runtime_classCallCheck(this, BytescaleApiError);
596
+ _this7 = _super3.call(this, response.error.message);
597
+ _this7.name = "BytescaleApiError";
598
+ _this7.errorCode = response.error.code;
599
+ _this7.details = response.error.details;
600
+ return _this7;
601
+ }
577
602
  return runtime_createClass(BytescaleApiError);
578
603
  }( /*#__PURE__*/_wrapNativeSuper(Error));
579
604
  function querystring(params) {
@@ -588,7 +613,20 @@ function querystringSingleKey(key, value) {
588
613
  // Matches 'array' or 'object' (which we want).
589
614
  return querystring(value);
590
615
  }
591
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
616
+ return encodeBytescaleQuerystringKVP(key, String(value));
617
+ }
618
+ /**
619
+ * Handles artifacts specially as these must use "/" instead of "%2F" in order for relative paths within the artifact's
620
+ * contents to work (assumes user has replaced "?" with "!"). For example, M3U8 artifacts that contain relative URLs to
621
+ * other M3U8s and/or media segments will only work if the user replaces "?" with "!" in the URL _and_ the artifact
622
+ * query param value has been written using "/" instead of "%2F", as this then means the URLs become relative to the
623
+ * artifact, as opposed to the file path.
624
+ */
625
+ function encodeBytescaleQuerystringKVP(key, value) {
626
+ if (key === "a" || key === "artifact") {
627
+ return "".concat(key, "=").concat(encodeURIComponent(value).replace(/%2F/g, "/"));
628
+ }
629
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
592
630
  }
593
631
  var JSONApiResponse = /*#__PURE__*/function () {
594
632
  function JSONApiResponse(raw) {
@@ -599,8 +637,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
599
637
  key: "value",
600
638
  value: function value() {
601
639
  try {
602
- var _this8 = this;
603
- return runtime_await(_this8.raw.json());
640
+ var _this9 = this;
641
+ return runtime_await(_this9.raw.json());
604
642
  } catch (e) {
605
643
  return Promise.reject(e);
606
644
  }
@@ -641,8 +679,8 @@ var BinaryResult = /*#__PURE__*/function () {
641
679
  key: "text",
642
680
  value: function text() {
643
681
  try {
644
- var _this10 = this;
645
- return runtime_await(_this10.raw.text());
682
+ var _this11 = this;
683
+ return runtime_await(_this11.raw.text());
646
684
  } catch (e) {
647
685
  return Promise.reject(e);
648
686
  }
@@ -651,8 +689,8 @@ var BinaryResult = /*#__PURE__*/function () {
651
689
  key: "blob",
652
690
  value: function blob() {
653
691
  try {
654
- var _this12 = this;
655
- return runtime_await(_this12.raw.blob());
692
+ var _this13 = this;
693
+ return runtime_await(_this13.raw.blob());
656
694
  } catch (e) {
657
695
  return Promise.reject(e);
658
696
  }
@@ -661,8 +699,8 @@ var BinaryResult = /*#__PURE__*/function () {
661
699
  key: "json",
662
700
  value: function json() {
663
701
  try {
664
- var _this14 = this;
665
- return runtime_await(_this14.raw.json());
702
+ var _this15 = this;
703
+ return runtime_await(_this15.raw.json());
666
704
  } catch (e) {
667
705
  return Promise.reject(e);
668
706
  }
@@ -1717,7 +1755,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1717
1755
  var _ref4 = _slicedToArray(_ref3, 2),
1718
1756
  key = _ref4[0],
1719
1757
  value = _ref4[1];
1720
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1758
+ return encodeBytescaleQuerystringKVP(key, value);
1721
1759
  }).join("&"));
1722
1760
  }
1723
1761
  }]);
@@ -2956,6 +2994,7 @@ var __lib_exports__BaseAPI = __lib_exports__.BaseAPI;
2956
2994
  var __lib_exports__BinaryResult = __lib_exports__.BinaryResult;
2957
2995
  var __lib_exports__BytescaleApiClientConfigUtils = __lib_exports__.BytescaleApiClientConfigUtils;
2958
2996
  var __lib_exports__BytescaleApiError = __lib_exports__.BytescaleApiError;
2997
+ var __lib_exports__BytescaleGenericError = __lib_exports__.BytescaleGenericError;
2959
2998
  var __lib_exports__CancelledError = __lib_exports__.CancelledError;
2960
2999
  var __lib_exports__CommonTypesNoOp = __lib_exports__.CommonTypesNoOp;
2961
3000
  var __lib_exports__FileApi = __lib_exports__.FileApi;
@@ -2967,5 +3006,6 @@ var __lib_exports__UploadManager = __lib_exports__.UploadManager;
2967
3006
  var __lib_exports__UrlBuilder = __lib_exports__.UrlBuilder;
2968
3007
  var __lib_exports__UrlBuilderTypesNoOp = __lib_exports__.UrlBuilderTypesNoOp;
2969
3008
  var __lib_exports__VoidApiResponse = __lib_exports__.VoidApiResponse;
3009
+ var __lib_exports__encodeBytescaleQuerystringKVP = __lib_exports__.encodeBytescaleQuerystringKVP;
2970
3010
  var __lib_exports__querystring = __lib_exports__.querystring;
2971
- export { __lib_exports__AuthManager as AuthManager, __lib_exports__BaseAPI as BaseAPI, __lib_exports__BinaryResult as BinaryResult, __lib_exports__BytescaleApiClientConfigUtils as BytescaleApiClientConfigUtils, __lib_exports__BytescaleApiError as BytescaleApiError, __lib_exports__CancelledError as CancelledError, __lib_exports__CommonTypesNoOp as CommonTypesNoOp, __lib_exports__FileApi as FileApi, __lib_exports__FolderApi as FolderApi, __lib_exports__JSONApiResponse as JSONApiResponse, __lib_exports__JobApi as JobApi, __lib_exports__UploadApi as UploadApi, __lib_exports__UploadManager as UploadManager, __lib_exports__UrlBuilder as UrlBuilder, __lib_exports__UrlBuilderTypesNoOp as UrlBuilderTypesNoOp, __lib_exports__VoidApiResponse as VoidApiResponse, __lib_exports__querystring as querystring };
3011
+ export { __lib_exports__AuthManager as AuthManager, __lib_exports__BaseAPI as BaseAPI, __lib_exports__BinaryResult as BinaryResult, __lib_exports__BytescaleApiClientConfigUtils as BytescaleApiClientConfigUtils, __lib_exports__BytescaleApiError as BytescaleApiError, __lib_exports__BytescaleGenericError as BytescaleGenericError, __lib_exports__CancelledError as CancelledError, __lib_exports__CommonTypesNoOp as CommonTypesNoOp, __lib_exports__FileApi as FileApi, __lib_exports__FolderApi as FolderApi, __lib_exports__JSONApiResponse as JSONApiResponse, __lib_exports__JobApi as JobApi, __lib_exports__UploadApi as UploadApi, __lib_exports__UploadManager as UploadManager, __lib_exports__UrlBuilder as UrlBuilder, __lib_exports__UrlBuilderTypesNoOp as UrlBuilderTypesNoOp, __lib_exports__VoidApiResponse as VoidApiResponse, __lib_exports__encodeBytescaleQuerystringKVP as encodeBytescaleQuerystringKVP, __lib_exports__querystring as querystring };
@@ -44,6 +44,7 @@ __lib_require__.d(__lib_exports__, {
44
44
  "BinaryResult": function() { return /* reexport */ BinaryResult; },
45
45
  "BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
46
46
  "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
47
+ "BytescaleGenericError": function() { return /* reexport */ BytescaleGenericError; },
47
48
  "CancelledError": function() { return /* reexport */ CancelledError; },
48
49
  "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
49
50
  "FileApi": function() { return /* reexport */ FileApi; },
@@ -55,6 +56,7 @@ __lib_require__.d(__lib_exports__, {
55
56
  "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
56
57
  "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
57
58
  "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
59
+ "encodeBytescaleQuerystringKVP": function() { return /* reexport */ encodeBytescaleQuerystringKVP; },
58
60
  "querystring": function() { return /* reexport */ querystring; }
59
61
  });
60
62
 
@@ -549,8 +551,10 @@ var BaseAPI = /*#__PURE__*/function () {
549
551
  }
550
552
  // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
551
553
  // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
552
- // this error will appear from any intermediary service failure.
553
- throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
554
+ // this error will appear from any intermediary service failure. Also occurs when calling ProcessFile for an
555
+ // asynchronous media job, where the transformation is initiated using the primary artifact: in this instance,
556
+ // a 404 JSON response is returned containing the transformation job until it completes.
557
+ throw new BytescaleGenericError(response, errorText, errorJson);
554
558
  });
555
559
  }
556
560
  }, function (_result2) {
@@ -577,18 +581,39 @@ var CancelledError = /*#__PURE__*/function (_Error) {
577
581
  }
578
582
  return runtime_createClass(CancelledError);
579
583
  }( /*#__PURE__*/_wrapNativeSuper(Error));
580
- var BytescaleApiError = /*#__PURE__*/function (_Error2) {
581
- _inherits(BytescaleApiError, _Error2);
582
- var _super2 = _createSuper(BytescaleApiError);
583
- function BytescaleApiError(response) {
584
+ /**
585
+ * Thrown when the Bytescale API cannot be reached or when an error is returned that cannot be parsed as a JSON error response.
586
+ */
587
+ var BytescaleGenericError = /*#__PURE__*/function (_Error2) {
588
+ _inherits(BytescaleGenericError, _Error2);
589
+ var _super2 = _createSuper(BytescaleGenericError);
590
+ function BytescaleGenericError(response, responseText, responseJson) {
584
591
  var _this6;
585
- runtime_classCallCheck(this, BytescaleApiError);
586
- _this6 = _super2.call(this, response.error.message);
587
- _this6.name = "BytescaleApiError";
588
- _this6.errorCode = response.error.code;
589
- _this6.details = response.error.details;
592
+ runtime_classCallCheck(this, BytescaleGenericError);
593
+ _this6 = _super2.call(this, "Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
594
+ _this6.response = response;
595
+ _this6.responseText = responseText;
596
+ _this6.responseJson = responseJson;
597
+ _this6.name = "BytescaleGenericError";
590
598
  return _this6;
591
599
  }
600
+ return runtime_createClass(BytescaleGenericError);
601
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
602
+ /**
603
+ * Thrown when the Bytescale API returns a JSON error response.
604
+ */
605
+ var BytescaleApiError = /*#__PURE__*/function (_Error3) {
606
+ _inherits(BytescaleApiError, _Error3);
607
+ var _super3 = _createSuper(BytescaleApiError);
608
+ function BytescaleApiError(response) {
609
+ var _this7;
610
+ runtime_classCallCheck(this, BytescaleApiError);
611
+ _this7 = _super3.call(this, response.error.message);
612
+ _this7.name = "BytescaleApiError";
613
+ _this7.errorCode = response.error.code;
614
+ _this7.details = response.error.details;
615
+ return _this7;
616
+ }
592
617
  return runtime_createClass(BytescaleApiError);
593
618
  }( /*#__PURE__*/_wrapNativeSuper(Error));
594
619
  function querystring(params) {
@@ -603,7 +628,20 @@ function querystringSingleKey(key, value) {
603
628
  // Matches 'array' or 'object' (which we want).
604
629
  return querystring(value);
605
630
  }
606
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
631
+ return encodeBytescaleQuerystringKVP(key, String(value));
632
+ }
633
+ /**
634
+ * Handles artifacts specially as these must use "/" instead of "%2F" in order for relative paths within the artifact's
635
+ * contents to work (assumes user has replaced "?" with "!"). For example, M3U8 artifacts that contain relative URLs to
636
+ * other M3U8s and/or media segments will only work if the user replaces "?" with "!" in the URL _and_ the artifact
637
+ * query param value has been written using "/" instead of "%2F", as this then means the URLs become relative to the
638
+ * artifact, as opposed to the file path.
639
+ */
640
+ function encodeBytescaleQuerystringKVP(key, value) {
641
+ if (key === "a" || key === "artifact") {
642
+ return "".concat(key, "=").concat(encodeURIComponent(value).replace(/%2F/g, "/"));
643
+ }
644
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
607
645
  }
608
646
  var JSONApiResponse = /*#__PURE__*/function () {
609
647
  function JSONApiResponse(raw) {
@@ -614,8 +652,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
614
652
  key: "value",
615
653
  value: function value() {
616
654
  try {
617
- var _this8 = this;
618
- return runtime_await(_this8.raw.json());
655
+ var _this9 = this;
656
+ return runtime_await(_this9.raw.json());
619
657
  } catch (e) {
620
658
  return Promise.reject(e);
621
659
  }
@@ -656,8 +694,8 @@ var BinaryResult = /*#__PURE__*/function () {
656
694
  key: "text",
657
695
  value: function text() {
658
696
  try {
659
- var _this10 = this;
660
- return runtime_await(_this10.raw.text());
697
+ var _this11 = this;
698
+ return runtime_await(_this11.raw.text());
661
699
  } catch (e) {
662
700
  return Promise.reject(e);
663
701
  }
@@ -666,8 +704,8 @@ var BinaryResult = /*#__PURE__*/function () {
666
704
  key: "blob",
667
705
  value: function blob() {
668
706
  try {
669
- var _this12 = this;
670
- return runtime_await(_this12.raw.blob());
707
+ var _this13 = this;
708
+ return runtime_await(_this13.raw.blob());
671
709
  } catch (e) {
672
710
  return Promise.reject(e);
673
711
  }
@@ -676,8 +714,8 @@ var BinaryResult = /*#__PURE__*/function () {
676
714
  key: "json",
677
715
  value: function json() {
678
716
  try {
679
- var _this14 = this;
680
- return runtime_await(_this14.raw.json());
717
+ var _this15 = this;
718
+ return runtime_await(_this15.raw.json());
681
719
  } catch (e) {
682
720
  return Promise.reject(e);
683
721
  }
@@ -1732,7 +1770,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1732
1770
  var _ref4 = _slicedToArray(_ref3, 2),
1733
1771
  key = _ref4[0],
1734
1772
  value = _ref4[1];
1735
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1773
+ return encodeBytescaleQuerystringKVP(key, value);
1736
1774
  }).join("&"));
1737
1775
  }
1738
1776
  }]);
@@ -31,6 +31,7 @@ __lib_require__.d(__lib_exports__, {
31
31
  "BinaryResult": function() { return /* reexport */ BinaryResult; },
32
32
  "BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
33
33
  "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
34
+ "BytescaleGenericError": function() { return /* reexport */ BytescaleGenericError; },
34
35
  "CancelledError": function() { return /* reexport */ CancelledError; },
35
36
  "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
36
37
  "FileApi": function() { return /* reexport */ FileApi; },
@@ -42,6 +43,7 @@ __lib_require__.d(__lib_exports__, {
42
43
  "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
43
44
  "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
44
45
  "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
46
+ "encodeBytescaleQuerystringKVP": function() { return /* reexport */ encodeBytescaleQuerystringKVP; },
45
47
  "querystring": function() { return /* reexport */ querystring; }
46
48
  });
47
49
 
@@ -536,8 +538,10 @@ var BaseAPI = /*#__PURE__*/function () {
536
538
  }
537
539
  // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
538
540
  // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
539
- // this error will appear from any intermediary service failure.
540
- throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
541
+ // this error will appear from any intermediary service failure. Also occurs when calling ProcessFile for an
542
+ // asynchronous media job, where the transformation is initiated using the primary artifact: in this instance,
543
+ // a 404 JSON response is returned containing the transformation job until it completes.
544
+ throw new BytescaleGenericError(response, errorText, errorJson);
541
545
  });
542
546
  }
543
547
  }, function (_result2) {
@@ -564,18 +568,39 @@ var CancelledError = /*#__PURE__*/function (_Error) {
564
568
  }
565
569
  return runtime_createClass(CancelledError);
566
570
  }( /*#__PURE__*/_wrapNativeSuper(Error));
567
- var BytescaleApiError = /*#__PURE__*/function (_Error2) {
568
- _inherits(BytescaleApiError, _Error2);
569
- var _super2 = _createSuper(BytescaleApiError);
570
- function BytescaleApiError(response) {
571
+ /**
572
+ * Thrown when the Bytescale API cannot be reached or when an error is returned that cannot be parsed as a JSON error response.
573
+ */
574
+ var BytescaleGenericError = /*#__PURE__*/function (_Error2) {
575
+ _inherits(BytescaleGenericError, _Error2);
576
+ var _super2 = _createSuper(BytescaleGenericError);
577
+ function BytescaleGenericError(response, responseText, responseJson) {
571
578
  var _this6;
572
- runtime_classCallCheck(this, BytescaleApiError);
573
- _this6 = _super2.call(this, response.error.message);
574
- _this6.name = "BytescaleApiError";
575
- _this6.errorCode = response.error.code;
576
- _this6.details = response.error.details;
579
+ runtime_classCallCheck(this, BytescaleGenericError);
580
+ _this6 = _super2.call(this, "Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
581
+ _this6.response = response;
582
+ _this6.responseText = responseText;
583
+ _this6.responseJson = responseJson;
584
+ _this6.name = "BytescaleGenericError";
577
585
  return _this6;
578
586
  }
587
+ return runtime_createClass(BytescaleGenericError);
588
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
589
+ /**
590
+ * Thrown when the Bytescale API returns a JSON error response.
591
+ */
592
+ var BytescaleApiError = /*#__PURE__*/function (_Error3) {
593
+ _inherits(BytescaleApiError, _Error3);
594
+ var _super3 = _createSuper(BytescaleApiError);
595
+ function BytescaleApiError(response) {
596
+ var _this7;
597
+ runtime_classCallCheck(this, BytescaleApiError);
598
+ _this7 = _super3.call(this, response.error.message);
599
+ _this7.name = "BytescaleApiError";
600
+ _this7.errorCode = response.error.code;
601
+ _this7.details = response.error.details;
602
+ return _this7;
603
+ }
579
604
  return runtime_createClass(BytescaleApiError);
580
605
  }( /*#__PURE__*/_wrapNativeSuper(Error));
581
606
  function querystring(params) {
@@ -590,7 +615,20 @@ function querystringSingleKey(key, value) {
590
615
  // Matches 'array' or 'object' (which we want).
591
616
  return querystring(value);
592
617
  }
593
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
618
+ return encodeBytescaleQuerystringKVP(key, String(value));
619
+ }
620
+ /**
621
+ * Handles artifacts specially as these must use "/" instead of "%2F" in order for relative paths within the artifact's
622
+ * contents to work (assumes user has replaced "?" with "!"). For example, M3U8 artifacts that contain relative URLs to
623
+ * other M3U8s and/or media segments will only work if the user replaces "?" with "!" in the URL _and_ the artifact
624
+ * query param value has been written using "/" instead of "%2F", as this then means the URLs become relative to the
625
+ * artifact, as opposed to the file path.
626
+ */
627
+ function encodeBytescaleQuerystringKVP(key, value) {
628
+ if (key === "a" || key === "artifact") {
629
+ return "".concat(key, "=").concat(encodeURIComponent(value).replace(/%2F/g, "/"));
630
+ }
631
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
594
632
  }
595
633
  var JSONApiResponse = /*#__PURE__*/function () {
596
634
  function JSONApiResponse(raw) {
@@ -601,8 +639,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
601
639
  key: "value",
602
640
  value: function value() {
603
641
  try {
604
- var _this8 = this;
605
- return runtime_await(_this8.raw.json());
642
+ var _this9 = this;
643
+ return runtime_await(_this9.raw.json());
606
644
  } catch (e) {
607
645
  return Promise.reject(e);
608
646
  }
@@ -643,8 +681,8 @@ var BinaryResult = /*#__PURE__*/function () {
643
681
  key: "text",
644
682
  value: function text() {
645
683
  try {
646
- var _this10 = this;
647
- return runtime_await(_this10.raw.text());
684
+ var _this11 = this;
685
+ return runtime_await(_this11.raw.text());
648
686
  } catch (e) {
649
687
  return Promise.reject(e);
650
688
  }
@@ -653,8 +691,8 @@ var BinaryResult = /*#__PURE__*/function () {
653
691
  key: "blob",
654
692
  value: function blob() {
655
693
  try {
656
- var _this12 = this;
657
- return runtime_await(_this12.raw.blob());
694
+ var _this13 = this;
695
+ return runtime_await(_this13.raw.blob());
658
696
  } catch (e) {
659
697
  return Promise.reject(e);
660
698
  }
@@ -663,8 +701,8 @@ var BinaryResult = /*#__PURE__*/function () {
663
701
  key: "json",
664
702
  value: function json() {
665
703
  try {
666
- var _this14 = this;
667
- return runtime_await(_this14.raw.json());
704
+ var _this15 = this;
705
+ return runtime_await(_this15.raw.json());
668
706
  } catch (e) {
669
707
  return Promise.reject(e);
670
708
  }
@@ -1719,7 +1757,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1719
1757
  var _ref4 = _slicedToArray(_ref3, 2),
1720
1758
  key = _ref4[0],
1721
1759
  value = _ref4[1];
1722
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1760
+ return encodeBytescaleQuerystringKVP(key, value);
1723
1761
  }).join("&"));
1724
1762
  }
1725
1763
  }]);
@@ -2974,6 +3012,7 @@ var __lib_exports__BaseAPI = __lib_exports__.BaseAPI;
2974
3012
  var __lib_exports__BinaryResult = __lib_exports__.BinaryResult;
2975
3013
  var __lib_exports__BytescaleApiClientConfigUtils = __lib_exports__.BytescaleApiClientConfigUtils;
2976
3014
  var __lib_exports__BytescaleApiError = __lib_exports__.BytescaleApiError;
3015
+ var __lib_exports__BytescaleGenericError = __lib_exports__.BytescaleGenericError;
2977
3016
  var __lib_exports__CancelledError = __lib_exports__.CancelledError;
2978
3017
  var __lib_exports__CommonTypesNoOp = __lib_exports__.CommonTypesNoOp;
2979
3018
  var __lib_exports__FileApi = __lib_exports__.FileApi;
@@ -2985,5 +3024,6 @@ var __lib_exports__UploadManager = __lib_exports__.UploadManager;
2985
3024
  var __lib_exports__UrlBuilder = __lib_exports__.UrlBuilder;
2986
3025
  var __lib_exports__UrlBuilderTypesNoOp = __lib_exports__.UrlBuilderTypesNoOp;
2987
3026
  var __lib_exports__VoidApiResponse = __lib_exports__.VoidApiResponse;
3027
+ var __lib_exports__encodeBytescaleQuerystringKVP = __lib_exports__.encodeBytescaleQuerystringKVP;
2988
3028
  var __lib_exports__querystring = __lib_exports__.querystring;
2989
- export { __lib_exports__AuthManager as AuthManager, __lib_exports__BaseAPI as BaseAPI, __lib_exports__BinaryResult as BinaryResult, __lib_exports__BytescaleApiClientConfigUtils as BytescaleApiClientConfigUtils, __lib_exports__BytescaleApiError as BytescaleApiError, __lib_exports__CancelledError as CancelledError, __lib_exports__CommonTypesNoOp as CommonTypesNoOp, __lib_exports__FileApi as FileApi, __lib_exports__FolderApi as FolderApi, __lib_exports__JSONApiResponse as JSONApiResponse, __lib_exports__JobApi as JobApi, __lib_exports__UploadApi as UploadApi, __lib_exports__UploadManager as UploadManager, __lib_exports__UrlBuilder as UrlBuilder, __lib_exports__UrlBuilderTypesNoOp as UrlBuilderTypesNoOp, __lib_exports__VoidApiResponse as VoidApiResponse, __lib_exports__querystring as querystring };
3029
+ export { __lib_exports__AuthManager as AuthManager, __lib_exports__BaseAPI as BaseAPI, __lib_exports__BinaryResult as BinaryResult, __lib_exports__BytescaleApiClientConfigUtils as BytescaleApiClientConfigUtils, __lib_exports__BytescaleApiError as BytescaleApiError, __lib_exports__BytescaleGenericError as BytescaleGenericError, __lib_exports__CancelledError as CancelledError, __lib_exports__CommonTypesNoOp as CommonTypesNoOp, __lib_exports__FileApi as FileApi, __lib_exports__FolderApi as FolderApi, __lib_exports__JSONApiResponse as JSONApiResponse, __lib_exports__JobApi as JobApi, __lib_exports__UploadApi as UploadApi, __lib_exports__UploadManager as UploadManager, __lib_exports__UrlBuilder as UrlBuilder, __lib_exports__UrlBuilderTypesNoOp as UrlBuilderTypesNoOp, __lib_exports__VoidApiResponse as VoidApiResponse, __lib_exports__encodeBytescaleQuerystringKVP as encodeBytescaleQuerystringKVP, __lib_exports__querystring as querystring };
@@ -74,6 +74,19 @@ export declare class CancelledError extends Error {
74
74
  name: "CancelledError";
75
75
  constructor();
76
76
  }
77
+ /**
78
+ * Thrown when the Bytescale API cannot be reached or when an error is returned that cannot be parsed as a JSON error response.
79
+ */
80
+ export declare class BytescaleGenericError extends Error {
81
+ readonly response: Response;
82
+ readonly responseText: string | undefined;
83
+ readonly responseJson: object | undefined;
84
+ name: "BytescaleGenericError";
85
+ constructor(response: Response, responseText: string | undefined, responseJson: object | undefined);
86
+ }
87
+ /**
88
+ * Thrown when the Bytescale API returns a JSON error response.
89
+ */
77
90
  export declare class BytescaleApiError extends Error {
78
91
  name: "BytescaleApiError";
79
92
  readonly errorCode: string;
@@ -107,6 +120,14 @@ export interface RequestOpts {
107
120
  body?: HTTPBody;
108
121
  }
109
122
  export declare function querystring(params: HTTPQuery): string;
123
+ /**
124
+ * Handles artifacts specially as these must use "/" instead of "%2F" in order for relative paths within the artifact's
125
+ * contents to work (assumes user has replaced "?" with "!"). For example, M3U8 artifacts that contain relative URLs to
126
+ * other M3U8s and/or media segments will only work if the user replaces "?" with "!" in the URL _and_ the artifact
127
+ * query param value has been written using "/" instead of "%2F", as this then means the URLs become relative to the
128
+ * artifact, as opposed to the file path.
129
+ */
130
+ export declare function encodeBytescaleQuerystringKVP(key: string, value: string): string;
110
131
  export interface ApiResponse<T> {
111
132
  raw: Response;
112
133
  value(): Promise<T>;
@@ -44,6 +44,7 @@ __lib_require__.d(__lib_exports__, {
44
44
  "BinaryResult": function() { return /* reexport */ BinaryResult; },
45
45
  "BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
46
46
  "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
47
+ "BytescaleGenericError": function() { return /* reexport */ BytescaleGenericError; },
47
48
  "CancelledError": function() { return /* reexport */ CancelledError; },
48
49
  "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
49
50
  "FileApi": function() { return /* reexport */ FileApi; },
@@ -55,6 +56,7 @@ __lib_require__.d(__lib_exports__, {
55
56
  "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
56
57
  "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
57
58
  "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
59
+ "encodeBytescaleQuerystringKVP": function() { return /* reexport */ encodeBytescaleQuerystringKVP; },
58
60
  "querystring": function() { return /* reexport */ querystring; }
59
61
  });
60
62
 
@@ -549,8 +551,10 @@ var BaseAPI = /*#__PURE__*/function () {
549
551
  }
550
552
  // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
551
553
  // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
552
- // this error will appear from any intermediary service failure.
553
- throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
554
+ // this error will appear from any intermediary service failure. Also occurs when calling ProcessFile for an
555
+ // asynchronous media job, where the transformation is initiated using the primary artifact: in this instance,
556
+ // a 404 JSON response is returned containing the transformation job until it completes.
557
+ throw new BytescaleGenericError(response, errorText, errorJson);
554
558
  });
555
559
  }
556
560
  }, function (_result2) {
@@ -577,18 +581,39 @@ var CancelledError = /*#__PURE__*/function (_Error) {
577
581
  }
578
582
  return runtime_createClass(CancelledError);
579
583
  }( /*#__PURE__*/_wrapNativeSuper(Error));
580
- var BytescaleApiError = /*#__PURE__*/function (_Error2) {
581
- _inherits(BytescaleApiError, _Error2);
582
- var _super2 = _createSuper(BytescaleApiError);
583
- function BytescaleApiError(response) {
584
+ /**
585
+ * Thrown when the Bytescale API cannot be reached or when an error is returned that cannot be parsed as a JSON error response.
586
+ */
587
+ var BytescaleGenericError = /*#__PURE__*/function (_Error2) {
588
+ _inherits(BytescaleGenericError, _Error2);
589
+ var _super2 = _createSuper(BytescaleGenericError);
590
+ function BytescaleGenericError(response, responseText, responseJson) {
584
591
  var _this6;
585
- runtime_classCallCheck(this, BytescaleApiError);
586
- _this6 = _super2.call(this, response.error.message);
587
- _this6.name = "BytescaleApiError";
588
- _this6.errorCode = response.error.code;
589
- _this6.details = response.error.details;
592
+ runtime_classCallCheck(this, BytescaleGenericError);
593
+ _this6 = _super2.call(this, "Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
594
+ _this6.response = response;
595
+ _this6.responseText = responseText;
596
+ _this6.responseJson = responseJson;
597
+ _this6.name = "BytescaleGenericError";
590
598
  return _this6;
591
599
  }
600
+ return runtime_createClass(BytescaleGenericError);
601
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
602
+ /**
603
+ * Thrown when the Bytescale API returns a JSON error response.
604
+ */
605
+ var BytescaleApiError = /*#__PURE__*/function (_Error3) {
606
+ _inherits(BytescaleApiError, _Error3);
607
+ var _super3 = _createSuper(BytescaleApiError);
608
+ function BytescaleApiError(response) {
609
+ var _this7;
610
+ runtime_classCallCheck(this, BytescaleApiError);
611
+ _this7 = _super3.call(this, response.error.message);
612
+ _this7.name = "BytescaleApiError";
613
+ _this7.errorCode = response.error.code;
614
+ _this7.details = response.error.details;
615
+ return _this7;
616
+ }
592
617
  return runtime_createClass(BytescaleApiError);
593
618
  }( /*#__PURE__*/_wrapNativeSuper(Error));
594
619
  function querystring(params) {
@@ -603,7 +628,20 @@ function querystringSingleKey(key, value) {
603
628
  // Matches 'array' or 'object' (which we want).
604
629
  return querystring(value);
605
630
  }
606
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
631
+ return encodeBytescaleQuerystringKVP(key, String(value));
632
+ }
633
+ /**
634
+ * Handles artifacts specially as these must use "/" instead of "%2F" in order for relative paths within the artifact's
635
+ * contents to work (assumes user has replaced "?" with "!"). For example, M3U8 artifacts that contain relative URLs to
636
+ * other M3U8s and/or media segments will only work if the user replaces "?" with "!" in the URL _and_ the artifact
637
+ * query param value has been written using "/" instead of "%2F", as this then means the URLs become relative to the
638
+ * artifact, as opposed to the file path.
639
+ */
640
+ function encodeBytescaleQuerystringKVP(key, value) {
641
+ if (key === "a" || key === "artifact") {
642
+ return "".concat(key, "=").concat(encodeURIComponent(value).replace(/%2F/g, "/"));
643
+ }
644
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
607
645
  }
608
646
  var JSONApiResponse = /*#__PURE__*/function () {
609
647
  function JSONApiResponse(raw) {
@@ -614,8 +652,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
614
652
  key: "value",
615
653
  value: function value() {
616
654
  try {
617
- var _this8 = this;
618
- return runtime_await(_this8.raw.json());
655
+ var _this9 = this;
656
+ return runtime_await(_this9.raw.json());
619
657
  } catch (e) {
620
658
  return Promise.reject(e);
621
659
  }
@@ -656,8 +694,8 @@ var BinaryResult = /*#__PURE__*/function () {
656
694
  key: "text",
657
695
  value: function text() {
658
696
  try {
659
- var _this10 = this;
660
- return runtime_await(_this10.raw.text());
697
+ var _this11 = this;
698
+ return runtime_await(_this11.raw.text());
661
699
  } catch (e) {
662
700
  return Promise.reject(e);
663
701
  }
@@ -666,8 +704,8 @@ var BinaryResult = /*#__PURE__*/function () {
666
704
  key: "blob",
667
705
  value: function blob() {
668
706
  try {
669
- var _this12 = this;
670
- return runtime_await(_this12.raw.blob());
707
+ var _this13 = this;
708
+ return runtime_await(_this13.raw.blob());
671
709
  } catch (e) {
672
710
  return Promise.reject(e);
673
711
  }
@@ -676,8 +714,8 @@ var BinaryResult = /*#__PURE__*/function () {
676
714
  key: "json",
677
715
  value: function json() {
678
716
  try {
679
- var _this14 = this;
680
- return runtime_await(_this14.raw.json());
717
+ var _this15 = this;
718
+ return runtime_await(_this15.raw.json());
681
719
  } catch (e) {
682
720
  return Promise.reject(e);
683
721
  }
@@ -1732,7 +1770,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1732
1770
  var _ref4 = _slicedToArray(_ref3, 2),
1733
1771
  key = _ref4[0],
1734
1772
  value = _ref4[1];
1735
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1773
+ return encodeBytescaleQuerystringKVP(key, value);
1736
1774
  }).join("&"));
1737
1775
  }
1738
1776
  }]);
@@ -29,6 +29,7 @@ __lib_require__.d(__lib_exports__, {
29
29
  "BinaryResult": function() { return /* reexport */ BinaryResult; },
30
30
  "BytescaleApiClientConfigUtils": function() { return /* reexport */ BytescaleApiClientConfigUtils; },
31
31
  "BytescaleApiError": function() { return /* reexport */ BytescaleApiError; },
32
+ "BytescaleGenericError": function() { return /* reexport */ BytescaleGenericError; },
32
33
  "CancelledError": function() { return /* reexport */ CancelledError; },
33
34
  "CommonTypesNoOp": function() { return /* reexport */ CommonTypesNoOp; },
34
35
  "FileApi": function() { return /* reexport */ FileApi; },
@@ -40,6 +41,7 @@ __lib_require__.d(__lib_exports__, {
40
41
  "UrlBuilder": function() { return /* reexport */ UrlBuilder; },
41
42
  "UrlBuilderTypesNoOp": function() { return /* reexport */ UrlBuilderTypesNoOp; },
42
43
  "VoidApiResponse": function() { return /* reexport */ VoidApiResponse; },
44
+ "encodeBytescaleQuerystringKVP": function() { return /* reexport */ encodeBytescaleQuerystringKVP; },
43
45
  "querystring": function() { return /* reexport */ querystring; }
44
46
  });
45
47
 
@@ -534,8 +536,10 @@ var BaseAPI = /*#__PURE__*/function () {
534
536
  }
535
537
  // HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
536
538
  // this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
537
- // this error will appear from any intermediary service failure.
538
- throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
539
+ // this error will appear from any intermediary service failure. Also occurs when calling ProcessFile for an
540
+ // asynchronous media job, where the transformation is initiated using the primary artifact: in this instance,
541
+ // a 404 JSON response is returned containing the transformation job until it completes.
542
+ throw new BytescaleGenericError(response, errorText, errorJson);
539
543
  });
540
544
  }
541
545
  }, function (_result2) {
@@ -562,18 +566,39 @@ var CancelledError = /*#__PURE__*/function (_Error) {
562
566
  }
563
567
  return runtime_createClass(CancelledError);
564
568
  }( /*#__PURE__*/_wrapNativeSuper(Error));
565
- var BytescaleApiError = /*#__PURE__*/function (_Error2) {
566
- _inherits(BytescaleApiError, _Error2);
567
- var _super2 = _createSuper(BytescaleApiError);
568
- function BytescaleApiError(response) {
569
+ /**
570
+ * Thrown when the Bytescale API cannot be reached or when an error is returned that cannot be parsed as a JSON error response.
571
+ */
572
+ var BytescaleGenericError = /*#__PURE__*/function (_Error2) {
573
+ _inherits(BytescaleGenericError, _Error2);
574
+ var _super2 = _createSuper(BytescaleGenericError);
575
+ function BytescaleGenericError(response, responseText, responseJson) {
569
576
  var _this6;
570
- runtime_classCallCheck(this, BytescaleApiError);
571
- _this6 = _super2.call(this, response.error.message);
572
- _this6.name = "BytescaleApiError";
573
- _this6.errorCode = response.error.code;
574
- _this6.details = response.error.details;
577
+ runtime_classCallCheck(this, BytescaleGenericError);
578
+ _this6 = _super2.call(this, "Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
579
+ _this6.response = response;
580
+ _this6.responseText = responseText;
581
+ _this6.responseJson = responseJson;
582
+ _this6.name = "BytescaleGenericError";
575
583
  return _this6;
576
584
  }
585
+ return runtime_createClass(BytescaleGenericError);
586
+ }( /*#__PURE__*/_wrapNativeSuper(Error));
587
+ /**
588
+ * Thrown when the Bytescale API returns a JSON error response.
589
+ */
590
+ var BytescaleApiError = /*#__PURE__*/function (_Error3) {
591
+ _inherits(BytescaleApiError, _Error3);
592
+ var _super3 = _createSuper(BytescaleApiError);
593
+ function BytescaleApiError(response) {
594
+ var _this7;
595
+ runtime_classCallCheck(this, BytescaleApiError);
596
+ _this7 = _super3.call(this, response.error.message);
597
+ _this7.name = "BytescaleApiError";
598
+ _this7.errorCode = response.error.code;
599
+ _this7.details = response.error.details;
600
+ return _this7;
601
+ }
577
602
  return runtime_createClass(BytescaleApiError);
578
603
  }( /*#__PURE__*/_wrapNativeSuper(Error));
579
604
  function querystring(params) {
@@ -588,7 +613,20 @@ function querystringSingleKey(key, value) {
588
613
  // Matches 'array' or 'object' (which we want).
589
614
  return querystring(value);
590
615
  }
591
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(String(value)));
616
+ return encodeBytescaleQuerystringKVP(key, String(value));
617
+ }
618
+ /**
619
+ * Handles artifacts specially as these must use "/" instead of "%2F" in order for relative paths within the artifact's
620
+ * contents to work (assumes user has replaced "?" with "!"). For example, M3U8 artifacts that contain relative URLs to
621
+ * other M3U8s and/or media segments will only work if the user replaces "?" with "!" in the URL _and_ the artifact
622
+ * query param value has been written using "/" instead of "%2F", as this then means the URLs become relative to the
623
+ * artifact, as opposed to the file path.
624
+ */
625
+ function encodeBytescaleQuerystringKVP(key, value) {
626
+ if (key === "a" || key === "artifact") {
627
+ return "".concat(key, "=").concat(encodeURIComponent(value).replace(/%2F/g, "/"));
628
+ }
629
+ return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
592
630
  }
593
631
  var JSONApiResponse = /*#__PURE__*/function () {
594
632
  function JSONApiResponse(raw) {
@@ -599,8 +637,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
599
637
  key: "value",
600
638
  value: function value() {
601
639
  try {
602
- var _this8 = this;
603
- return runtime_await(_this8.raw.json());
640
+ var _this9 = this;
641
+ return runtime_await(_this9.raw.json());
604
642
  } catch (e) {
605
643
  return Promise.reject(e);
606
644
  }
@@ -641,8 +679,8 @@ var BinaryResult = /*#__PURE__*/function () {
641
679
  key: "text",
642
680
  value: function text() {
643
681
  try {
644
- var _this10 = this;
645
- return runtime_await(_this10.raw.text());
682
+ var _this11 = this;
683
+ return runtime_await(_this11.raw.text());
646
684
  } catch (e) {
647
685
  return Promise.reject(e);
648
686
  }
@@ -651,8 +689,8 @@ var BinaryResult = /*#__PURE__*/function () {
651
689
  key: "blob",
652
690
  value: function blob() {
653
691
  try {
654
- var _this12 = this;
655
- return runtime_await(_this12.raw.blob());
692
+ var _this13 = this;
693
+ return runtime_await(_this13.raw.blob());
656
694
  } catch (e) {
657
695
  return Promise.reject(e);
658
696
  }
@@ -661,8 +699,8 @@ var BinaryResult = /*#__PURE__*/function () {
661
699
  key: "json",
662
700
  value: function json() {
663
701
  try {
664
- var _this14 = this;
665
- return runtime_await(_this14.raw.json());
702
+ var _this15 = this;
703
+ return runtime_await(_this15.raw.json());
666
704
  } catch (e) {
667
705
  return Promise.reject(e);
668
706
  }
@@ -1717,7 +1755,7 @@ var UrlBuilder = /*#__PURE__*/function () {
1717
1755
  var _ref4 = _slicedToArray(_ref3, 2),
1718
1756
  key = _ref4[0],
1719
1757
  value = _ref4[1];
1720
- return "".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
1758
+ return encodeBytescaleQuerystringKVP(key, value);
1721
1759
  }).join("&"));
1722
1760
  }
1723
1761
  }]);
@@ -2499,6 +2537,7 @@ var __lib_exports__BaseAPI = __lib_exports__.BaseAPI;
2499
2537
  var __lib_exports__BinaryResult = __lib_exports__.BinaryResult;
2500
2538
  var __lib_exports__BytescaleApiClientConfigUtils = __lib_exports__.BytescaleApiClientConfigUtils;
2501
2539
  var __lib_exports__BytescaleApiError = __lib_exports__.BytescaleApiError;
2540
+ var __lib_exports__BytescaleGenericError = __lib_exports__.BytescaleGenericError;
2502
2541
  var __lib_exports__CancelledError = __lib_exports__.CancelledError;
2503
2542
  var __lib_exports__CommonTypesNoOp = __lib_exports__.CommonTypesNoOp;
2504
2543
  var __lib_exports__FileApi = __lib_exports__.FileApi;
@@ -2510,5 +2549,6 @@ var __lib_exports__UploadManager = __lib_exports__.UploadManager;
2510
2549
  var __lib_exports__UrlBuilder = __lib_exports__.UrlBuilder;
2511
2550
  var __lib_exports__UrlBuilderTypesNoOp = __lib_exports__.UrlBuilderTypesNoOp;
2512
2551
  var __lib_exports__VoidApiResponse = __lib_exports__.VoidApiResponse;
2552
+ var __lib_exports__encodeBytescaleQuerystringKVP = __lib_exports__.encodeBytescaleQuerystringKVP;
2513
2553
  var __lib_exports__querystring = __lib_exports__.querystring;
2514
- export { __lib_exports__AuthManager as AuthManager, __lib_exports__BaseAPI as BaseAPI, __lib_exports__BinaryResult as BinaryResult, __lib_exports__BytescaleApiClientConfigUtils as BytescaleApiClientConfigUtils, __lib_exports__BytescaleApiError as BytescaleApiError, __lib_exports__CancelledError as CancelledError, __lib_exports__CommonTypesNoOp as CommonTypesNoOp, __lib_exports__FileApi as FileApi, __lib_exports__FolderApi as FolderApi, __lib_exports__JSONApiResponse as JSONApiResponse, __lib_exports__JobApi as JobApi, __lib_exports__UploadApi as UploadApi, __lib_exports__UploadManager as UploadManager, __lib_exports__UrlBuilder as UrlBuilder, __lib_exports__UrlBuilderTypesNoOp as UrlBuilderTypesNoOp, __lib_exports__VoidApiResponse as VoidApiResponse, __lib_exports__querystring as querystring };
2554
+ export { __lib_exports__AuthManager as AuthManager, __lib_exports__BaseAPI as BaseAPI, __lib_exports__BinaryResult as BinaryResult, __lib_exports__BytescaleApiClientConfigUtils as BytescaleApiClientConfigUtils, __lib_exports__BytescaleApiError as BytescaleApiError, __lib_exports__BytescaleGenericError as BytescaleGenericError, __lib_exports__CancelledError as CancelledError, __lib_exports__CommonTypesNoOp as CommonTypesNoOp, __lib_exports__FileApi as FileApi, __lib_exports__FolderApi as FolderApi, __lib_exports__JSONApiResponse as JSONApiResponse, __lib_exports__JobApi as JobApi, __lib_exports__UploadApi as UploadApi, __lib_exports__UploadManager as UploadManager, __lib_exports__UrlBuilder as UrlBuilder, __lib_exports__UrlBuilderTypesNoOp as UrlBuilderTypesNoOp, __lib_exports__VoidApiResponse as VoidApiResponse, __lib_exports__encodeBytescaleQuerystringKVP as encodeBytescaleQuerystringKVP, __lib_exports__querystring as querystring };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytescale/sdk",
3
- "version": "3.27.0",
3
+ "version": "3.29.0",
4
4
  "description": "Bytescale JavaScript SDK",
5
5
  "author": "Bytescale <hello@bytescale.com> (https://www.bytescale.com)",
6
6
  "license": "MIT",
@@ -49,7 +49,7 @@ describe("UrlBuilder", () => {
49
49
  filePath: "/example.jpg",
50
50
  options: { transformation: "preset", transformationPreset: "thumbnail", artifact: "/foo" }
51
51
  });
52
- const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?artifact=%2Ffoo";
52
+ const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?artifact=/foo";
53
53
  expect(actual).toEqual(expected);
54
54
  });
55
55
 
@@ -59,7 +59,7 @@ describe("UrlBuilder", () => {
59
59
  filePath: "/example.jpg",
60
60
  options: { transformation: "preset", transformationPreset: "thumbnail", artifact: "/foo" }
61
61
  });
62
- const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?artifact=%2Ffoo";
62
+ const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?artifact=/foo";
63
63
  expect(actual).toEqual(expected);
64
64
  });
65
65
 
@@ -74,7 +74,7 @@ describe("UrlBuilder", () => {
74
74
  cachePermanently: false
75
75
  }
76
76
  });
77
- const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?cache_perm=false&artifact=%2Ffoo";
77
+ const expected = "https://upcdn.io/1234abc/thumbnail/example.jpg?cache_perm=false&artifact=/foo";
78
78
  expect(actual).toEqual(expected);
79
79
  });
80
80
 
@@ -121,7 +121,7 @@ describe("UrlBuilder", () => {
121
121
  auth: true
122
122
  }
123
123
  });
124
- const expected = "https://upcdn.io/1234abc/image/example.jpg?w=42&h=50&version=50&cache_perm=auto&artifact=%2Ffoo";
124
+ const expected = "https://upcdn.io/1234abc/image/example.jpg?w=42&h=50&version=50&cache_perm=auto&artifact=/foo";
125
125
  expect(actual).toEqual(expected);
126
126
  });
127
127