@bytescale/sdk 3.0.0-alpha.18 → 3.0.0-alpha.19
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/browser/cjs/main.js +152 -147
- package/dist/node/cjs/main.js +90 -85
- package/dist/node/esm/main.mjs +90 -85
- package/dist/types/private/model/AuthManagerInterface.d.ts +14 -5
- package/dist/types/private/model/AuthSession.d.ts +2 -2
- package/dist/types/public/browser/AuthManagerBrowser.d.ts +10 -6
- package/dist/types/public/node/AuthManagerNode.d.ts +8 -3
- package/dist/types/public/shared/generated/runtime.d.ts +7 -5
- package/dist/worker/cjs/main.js +90 -85
- package/dist/worker/esm/main.mjs +90 -85
- package/package.json +1 -1
package/dist/node/cjs/main.js
CHANGED
|
@@ -507,6 +507,9 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
507
507
|
this.config = config;
|
|
508
508
|
BytescaleApiClientConfigUtils.validate(config);
|
|
509
509
|
}
|
|
510
|
+
/**
|
|
511
|
+
* Returns a successful response (2**) else throws an error.
|
|
512
|
+
*/
|
|
510
513
|
runtime_createClass(BaseAPI, [{
|
|
511
514
|
key: "request",
|
|
512
515
|
value: function request(context, initOverrides, baseUrlOverride) {
|
|
@@ -525,64 +528,9 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
525
528
|
return runtime_await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_a = nonDefaultBasePaths[baseUrlOverride]) !== null && _a !== void 0 ? _a : baseUrlOverride), function (_ref) {
|
|
526
529
|
var url = _ref.url,
|
|
527
530
|
init = _ref.init;
|
|
528
|
-
return
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
return Promise.reject(e);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
/**
|
|
535
|
-
* Returns a successful response (2**) else throws an error.
|
|
536
|
-
*/
|
|
537
|
-
}, {
|
|
538
|
-
key: "doFetch",
|
|
539
|
-
value: function doFetch(url, init, isBytescaleApi) {
|
|
540
|
-
try {
|
|
541
|
-
var _exit3 = false;
|
|
542
|
-
var _this4 = this;
|
|
543
|
-
var _a, _b;
|
|
544
|
-
var response;
|
|
545
|
-
return runtime_continue(_catch(function () {
|
|
546
|
-
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
|
|
547
|
-
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
548
|
-
//
|
|
549
|
-
// "fetch requests that use the POST method are also automatically cached."
|
|
550
|
-
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
551
|
-
//
|
|
552
|
-
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
553
|
-
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
554
|
-
cache: "no-store"
|
|
555
|
-
})), function (_BytescaleApiClientCo) {
|
|
556
|
-
response = _BytescaleApiClientCo;
|
|
557
|
-
});
|
|
558
|
-
}, function (e) {
|
|
559
|
-
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
|
|
560
|
-
// HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
|
|
561
|
-
throw new Error(isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
|
|
562
|
-
}), function (_result) {
|
|
563
|
-
var _exit2 = false;
|
|
564
|
-
if (_exit3) return _result;
|
|
565
|
-
return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
|
|
566
|
-
if (isBytescaleApi) {
|
|
567
|
-
var jsonError = undefined;
|
|
568
|
-
return runtime_continue(_catch(function () {
|
|
569
|
-
return runtime_await(response.json(), function (_response$json) {
|
|
570
|
-
jsonError = _response$json;
|
|
571
|
-
});
|
|
572
|
-
}, runtime_empty), function () {
|
|
573
|
-
if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
|
|
574
|
-
throw new BytescaleApiError(jsonError);
|
|
575
|
-
}
|
|
576
|
-
// HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
|
|
577
|
-
// this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
|
|
578
|
-
// this error will appear from any intermediary service failure.
|
|
579
|
-
throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
|
|
580
|
-
});
|
|
581
|
-
}
|
|
582
|
-
}, function (_result2) {
|
|
583
|
-
if (_exit2) return _result2;
|
|
584
|
-
throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
|
|
585
|
-
});
|
|
531
|
+
return BaseAPI.fetch(url, init, Object.assign(Object.assign({}, _this2.config), {
|
|
532
|
+
isBytescaleApi: true
|
|
533
|
+
}));
|
|
586
534
|
});
|
|
587
535
|
} catch (e) {
|
|
588
536
|
return Promise.reject(e);
|
|
@@ -605,15 +553,15 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
605
553
|
key: "createFetchParams",
|
|
606
554
|
value: function createFetchParams(context, initOverrides, baseUrlOverride) {
|
|
607
555
|
try {
|
|
608
|
-
var
|
|
609
|
-
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(
|
|
556
|
+
var _this4 = this;
|
|
557
|
+
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this4.config)) + context.path;
|
|
610
558
|
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
611
559
|
// only add the querystring to the URL if there are query parameters.
|
|
612
560
|
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
613
561
|
// do not handle correctly sometimes.
|
|
614
562
|
url += "?" + querystring(context.query);
|
|
615
563
|
}
|
|
616
|
-
var configHeaders =
|
|
564
|
+
var configHeaders = _this4.config.headers;
|
|
617
565
|
var _Object$assign3 = Object.assign({}, context.headers);
|
|
618
566
|
return runtime_await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
|
|
619
567
|
var headers = Object.assign(_Object$assign3, _configHeaders);
|
|
@@ -647,6 +595,59 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
647
595
|
return Promise.reject(e);
|
|
648
596
|
}
|
|
649
597
|
}
|
|
598
|
+
}], [{
|
|
599
|
+
key: "fetch",
|
|
600
|
+
value: function fetch(url, init, config) {
|
|
601
|
+
try {
|
|
602
|
+
var _exit3 = false;
|
|
603
|
+
var _a, _b;
|
|
604
|
+
var response;
|
|
605
|
+
return runtime_continue(_catch(function () {
|
|
606
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(config)(url, Object.assign(Object.assign({}, init), {
|
|
607
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
608
|
+
//
|
|
609
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
610
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
611
|
+
//
|
|
612
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
613
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
614
|
+
cache: "no-store"
|
|
615
|
+
})), function (_BytescaleApiClientCo) {
|
|
616
|
+
response = _BytescaleApiClientCo;
|
|
617
|
+
});
|
|
618
|
+
}, function (e) {
|
|
619
|
+
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
|
|
620
|
+
// HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
|
|
621
|
+
throw new Error(config.isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
|
|
622
|
+
}), function (_result) {
|
|
623
|
+
var _exit2 = false;
|
|
624
|
+
if (_exit3) return _result;
|
|
625
|
+
return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
|
|
626
|
+
if (config.isBytescaleApi) {
|
|
627
|
+
var jsonError = undefined;
|
|
628
|
+
return runtime_continue(_catch(function () {
|
|
629
|
+
return runtime_await(response.json(), function (_response$json) {
|
|
630
|
+
jsonError = _response$json;
|
|
631
|
+
});
|
|
632
|
+
}, runtime_empty), function () {
|
|
633
|
+
if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
|
|
634
|
+
throw new BytescaleApiError(jsonError);
|
|
635
|
+
}
|
|
636
|
+
// HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
|
|
637
|
+
// this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
|
|
638
|
+
// this error will appear from any intermediary service failure.
|
|
639
|
+
throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
|
|
640
|
+
});
|
|
641
|
+
}
|
|
642
|
+
}, function (_result2) {
|
|
643
|
+
if (_exit2) return _result2;
|
|
644
|
+
throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
} catch (e) {
|
|
648
|
+
return Promise.reject(e);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
650
651
|
}]);
|
|
651
652
|
return BaseAPI;
|
|
652
653
|
}();
|
|
@@ -654,11 +655,11 @@ var CancelledError = /*#__PURE__*/function (_Error) {
|
|
|
654
655
|
_inherits(CancelledError, _Error);
|
|
655
656
|
var _super = _createSuper(CancelledError);
|
|
656
657
|
function CancelledError() {
|
|
657
|
-
var
|
|
658
|
+
var _this5;
|
|
658
659
|
runtime_classCallCheck(this, CancelledError);
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
return
|
|
660
|
+
_this5 = _super.call(this, "Operation cancelled by caller.");
|
|
661
|
+
_this5.name = "CancelledError";
|
|
662
|
+
return _this5;
|
|
662
663
|
}
|
|
663
664
|
return runtime_createClass(CancelledError);
|
|
664
665
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
@@ -666,13 +667,13 @@ var BytescaleApiError = /*#__PURE__*/function (_Error2) {
|
|
|
666
667
|
_inherits(BytescaleApiError, _Error2);
|
|
667
668
|
var _super2 = _createSuper(BytescaleApiError);
|
|
668
669
|
function BytescaleApiError(response) {
|
|
669
|
-
var
|
|
670
|
+
var _this6;
|
|
670
671
|
runtime_classCallCheck(this, BytescaleApiError);
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
return
|
|
672
|
+
_this6 = _super2.call(this, response.error.message);
|
|
673
|
+
_this6.name = "BytescaleApiError";
|
|
674
|
+
_this6.errorCode = response.error.code;
|
|
675
|
+
_this6.details = response.error.details;
|
|
676
|
+
return _this6;
|
|
676
677
|
}
|
|
677
678
|
return runtime_createClass(BytescaleApiError);
|
|
678
679
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
@@ -698,8 +699,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
|
|
|
698
699
|
key: "value",
|
|
699
700
|
value: function value() {
|
|
700
701
|
try {
|
|
701
|
-
var
|
|
702
|
-
return runtime_await(
|
|
702
|
+
var _this8 = this;
|
|
703
|
+
return runtime_await(_this8.raw.json());
|
|
703
704
|
} catch (e) {
|
|
704
705
|
return Promise.reject(e);
|
|
705
706
|
}
|
|
@@ -740,8 +741,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
740
741
|
key: "text",
|
|
741
742
|
value: function text() {
|
|
742
743
|
try {
|
|
743
|
-
var
|
|
744
|
-
return runtime_await(
|
|
744
|
+
var _this10 = this;
|
|
745
|
+
return runtime_await(_this10.raw.text());
|
|
745
746
|
} catch (e) {
|
|
746
747
|
return Promise.reject(e);
|
|
747
748
|
}
|
|
@@ -750,8 +751,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
750
751
|
key: "blob",
|
|
751
752
|
value: function blob() {
|
|
752
753
|
try {
|
|
753
|
-
var
|
|
754
|
-
return runtime_await(
|
|
754
|
+
var _this12 = this;
|
|
755
|
+
return runtime_await(_this12.raw.blob());
|
|
755
756
|
} catch (e) {
|
|
756
757
|
return Promise.reject(e);
|
|
757
758
|
}
|
|
@@ -760,8 +761,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
760
761
|
key: "json",
|
|
761
762
|
value: function json() {
|
|
762
763
|
try {
|
|
763
|
-
var
|
|
764
|
-
return runtime_await(
|
|
764
|
+
var _this14 = this;
|
|
765
|
+
return runtime_await(_this14.raw.json());
|
|
765
766
|
} catch (e) {
|
|
766
767
|
return Promise.reject(e);
|
|
767
768
|
}
|
|
@@ -2999,13 +3000,13 @@ function AuthManagerNode_createClass(Constructor, protoProps, staticProps) { if
|
|
|
2999
3000
|
function AuthManagerNode_toPropertyKey(arg) { var key = AuthManagerNode_toPrimitive(arg, "string"); return AuthManagerNode_typeof(key) === "symbol" ? key : String(key); }
|
|
3000
3001
|
function AuthManagerNode_toPrimitive(input, hint) { if (AuthManagerNode_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthManagerNode_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
3001
3002
|
|
|
3002
|
-
var
|
|
3003
|
-
function
|
|
3004
|
-
AuthManagerNode_classCallCheck(this,
|
|
3003
|
+
var AuthManagerImpl = /*#__PURE__*/function () {
|
|
3004
|
+
function AuthManagerImpl() {
|
|
3005
|
+
AuthManagerNode_classCallCheck(this, AuthManagerImpl);
|
|
3005
3006
|
}
|
|
3006
|
-
AuthManagerNode_createClass(
|
|
3007
|
+
AuthManagerNode_createClass(AuthManagerImpl, [{
|
|
3007
3008
|
key: "beginAuthSession",
|
|
3008
|
-
value: function beginAuthSession(
|
|
3009
|
+
value: function beginAuthSession(_params) {
|
|
3009
3010
|
try {
|
|
3010
3011
|
throw EnvChecker.methodRequiresBrowser("beginAuthSession");
|
|
3011
3012
|
} catch (e) {
|
|
@@ -3027,8 +3028,12 @@ var AuthManager = /*#__PURE__*/function () {
|
|
|
3027
3028
|
return false;
|
|
3028
3029
|
}
|
|
3029
3030
|
}]);
|
|
3030
|
-
return
|
|
3031
|
+
return AuthManagerImpl;
|
|
3031
3032
|
}();
|
|
3033
|
+
/**
|
|
3034
|
+
* Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
|
|
3035
|
+
*/
|
|
3036
|
+
var AuthManager = new AuthManagerImpl();
|
|
3032
3037
|
;// CONCATENATED MODULE: ./src/public/node/index.ts
|
|
3033
3038
|
|
|
3034
3039
|
|
package/dist/node/esm/main.mjs
CHANGED
|
@@ -494,6 +494,9 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
494
494
|
this.config = config;
|
|
495
495
|
BytescaleApiClientConfigUtils.validate(config);
|
|
496
496
|
}
|
|
497
|
+
/**
|
|
498
|
+
* Returns a successful response (2**) else throws an error.
|
|
499
|
+
*/
|
|
497
500
|
runtime_createClass(BaseAPI, [{
|
|
498
501
|
key: "request",
|
|
499
502
|
value: function request(context, initOverrides, baseUrlOverride) {
|
|
@@ -512,64 +515,9 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
512
515
|
return runtime_await(_this2.createFetchParams(context, initOverrides, baseUrlOverride === undefined ? undefined : (_a = nonDefaultBasePaths[baseUrlOverride]) !== null && _a !== void 0 ? _a : baseUrlOverride), function (_ref) {
|
|
513
516
|
var url = _ref.url,
|
|
514
517
|
init = _ref.init;
|
|
515
|
-
return
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
return Promise.reject(e);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
/**
|
|
522
|
-
* Returns a successful response (2**) else throws an error.
|
|
523
|
-
*/
|
|
524
|
-
}, {
|
|
525
|
-
key: "doFetch",
|
|
526
|
-
value: function doFetch(url, init, isBytescaleApi) {
|
|
527
|
-
try {
|
|
528
|
-
var _exit3 = false;
|
|
529
|
-
var _this4 = this;
|
|
530
|
-
var _a, _b;
|
|
531
|
-
var response;
|
|
532
|
-
return runtime_continue(_catch(function () {
|
|
533
|
-
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(_this4.config)(url, Object.assign(Object.assign({}, init), {
|
|
534
|
-
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
535
|
-
//
|
|
536
|
-
// "fetch requests that use the POST method are also automatically cached."
|
|
537
|
-
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
538
|
-
//
|
|
539
|
-
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
540
|
-
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
541
|
-
cache: "no-store"
|
|
542
|
-
})), function (_BytescaleApiClientCo) {
|
|
543
|
-
response = _BytescaleApiClientCo;
|
|
544
|
-
});
|
|
545
|
-
}, function (e) {
|
|
546
|
-
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
|
|
547
|
-
// HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
|
|
548
|
-
throw new Error(isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
|
|
549
|
-
}), function (_result) {
|
|
550
|
-
var _exit2 = false;
|
|
551
|
-
if (_exit3) return _result;
|
|
552
|
-
return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
|
|
553
|
-
if (isBytescaleApi) {
|
|
554
|
-
var jsonError = undefined;
|
|
555
|
-
return runtime_continue(_catch(function () {
|
|
556
|
-
return runtime_await(response.json(), function (_response$json) {
|
|
557
|
-
jsonError = _response$json;
|
|
558
|
-
});
|
|
559
|
-
}, runtime_empty), function () {
|
|
560
|
-
if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
|
|
561
|
-
throw new BytescaleApiError(jsonError);
|
|
562
|
-
}
|
|
563
|
-
// HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
|
|
564
|
-
// this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
|
|
565
|
-
// this error will appear from any intermediary service failure.
|
|
566
|
-
throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
|
|
567
|
-
});
|
|
568
|
-
}
|
|
569
|
-
}, function (_result2) {
|
|
570
|
-
if (_exit2) return _result2;
|
|
571
|
-
throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
|
|
572
|
-
});
|
|
518
|
+
return BaseAPI.fetch(url, init, Object.assign(Object.assign({}, _this2.config), {
|
|
519
|
+
isBytescaleApi: true
|
|
520
|
+
}));
|
|
573
521
|
});
|
|
574
522
|
} catch (e) {
|
|
575
523
|
return Promise.reject(e);
|
|
@@ -592,15 +540,15 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
592
540
|
key: "createFetchParams",
|
|
593
541
|
value: function createFetchParams(context, initOverrides, baseUrlOverride) {
|
|
594
542
|
try {
|
|
595
|
-
var
|
|
596
|
-
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(
|
|
543
|
+
var _this4 = this;
|
|
544
|
+
var url = (baseUrlOverride !== null && baseUrlOverride !== void 0 ? baseUrlOverride : BytescaleApiClientConfigUtils.getApiUrl(_this4.config)) + context.path;
|
|
597
545
|
if (context.query !== undefined && Object.keys(context.query).length !== 0) {
|
|
598
546
|
// only add the querystring to the URL if there are query parameters.
|
|
599
547
|
// this is done to avoid urls ending with a "?" character which buggy webservers
|
|
600
548
|
// do not handle correctly sometimes.
|
|
601
549
|
url += "?" + querystring(context.query);
|
|
602
550
|
}
|
|
603
|
-
var configHeaders =
|
|
551
|
+
var configHeaders = _this4.config.headers;
|
|
604
552
|
var _Object$assign3 = Object.assign({}, context.headers);
|
|
605
553
|
return runtime_await(configHeaders === undefined ? {} : configHeaders(), function (_configHeaders) {
|
|
606
554
|
var headers = Object.assign(_Object$assign3, _configHeaders);
|
|
@@ -634,6 +582,59 @@ var BaseAPI = /*#__PURE__*/function () {
|
|
|
634
582
|
return Promise.reject(e);
|
|
635
583
|
}
|
|
636
584
|
}
|
|
585
|
+
}], [{
|
|
586
|
+
key: "fetch",
|
|
587
|
+
value: function fetch(url, init, config) {
|
|
588
|
+
try {
|
|
589
|
+
var _exit3 = false;
|
|
590
|
+
var _a, _b;
|
|
591
|
+
var response;
|
|
592
|
+
return runtime_continue(_catch(function () {
|
|
593
|
+
return runtime_await(BytescaleApiClientConfigUtils.getFetchApi(config)(url, Object.assign(Object.assign({}, init), {
|
|
594
|
+
// This is specifically added to cater for Next.js's Fetch implementation, which caches POST requests...
|
|
595
|
+
//
|
|
596
|
+
// "fetch requests that use the POST method are also automatically cached."
|
|
597
|
+
// - https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#caching-data
|
|
598
|
+
//
|
|
599
|
+
// However, this is probably a good idea, even for all GET requests, as if the user is refreshing a JWT
|
|
600
|
+
// or downloading a file via 'FileApi.downloadFile', then they'll likely want the latest.
|
|
601
|
+
cache: "no-store"
|
|
602
|
+
})), function (_BytescaleApiClientCo) {
|
|
603
|
+
response = _BytescaleApiClientCo;
|
|
604
|
+
});
|
|
605
|
+
}, function (e) {
|
|
606
|
+
// Network-level errors, CORS errors, or HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies).
|
|
607
|
+
// HTTP-level errors from external services (e.g. AWS or the user's own proxy) will appear as CORS errors as their response headers won't include the appropriate CORS values.
|
|
608
|
+
throw new Error(config.isBytescaleApi ? "Unable to resolve the Bytescale API: ".concat(e.message, " If the problem persists, and your network connection is OK, then please contact support@bytescale.com and provide: (a) time of failed request in UTC (b) screenshot of failed network response header + body (c) screenshot of failed network request header + body (d) browser and OS version.") : "Unable to resolve URL (".concat(url, "): ").concat(e.message));
|
|
609
|
+
}), function (_result) {
|
|
610
|
+
var _exit2 = false;
|
|
611
|
+
if (_exit3) return _result;
|
|
612
|
+
return response.status >= 200 && response.status < 300 ? response : _invoke(function () {
|
|
613
|
+
if (config.isBytescaleApi) {
|
|
614
|
+
var jsonError = undefined;
|
|
615
|
+
return runtime_continue(_catch(function () {
|
|
616
|
+
return runtime_await(response.json(), function (_response$json) {
|
|
617
|
+
jsonError = _response$json;
|
|
618
|
+
});
|
|
619
|
+
}, runtime_empty), function () {
|
|
620
|
+
if (typeof ((_a = jsonError === null || jsonError === void 0 ? void 0 : jsonError.error) === null || _a === void 0 ? void 0 : _a.code) === "string") {
|
|
621
|
+
throw new BytescaleApiError(jsonError);
|
|
622
|
+
}
|
|
623
|
+
// HTTP-level errors from intermediary services (e.g. AWS or the user's own infrastructure/proxies). On the browser,
|
|
624
|
+
// this error is unlikely to be triggered since these errors will masqurade as CORS errors (see above) but in Node.js
|
|
625
|
+
// this error will appear from any intermediary service failure.
|
|
626
|
+
throw new Error("Unable to connect to the Bytescale API (".concat(response.status, "): please try again."));
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
}, function (_result2) {
|
|
630
|
+
if (_exit2) return _result2;
|
|
631
|
+
throw new Error("Failure status code (".concat(response.status, ") received for request: ").concat((_b = init.method) !== null && _b !== void 0 ? _b : "GET", " ").concat(url));
|
|
632
|
+
});
|
|
633
|
+
});
|
|
634
|
+
} catch (e) {
|
|
635
|
+
return Promise.reject(e);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
637
638
|
}]);
|
|
638
639
|
return BaseAPI;
|
|
639
640
|
}();
|
|
@@ -641,11 +642,11 @@ var CancelledError = /*#__PURE__*/function (_Error) {
|
|
|
641
642
|
_inherits(CancelledError, _Error);
|
|
642
643
|
var _super = _createSuper(CancelledError);
|
|
643
644
|
function CancelledError() {
|
|
644
|
-
var
|
|
645
|
+
var _this5;
|
|
645
646
|
runtime_classCallCheck(this, CancelledError);
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
return
|
|
647
|
+
_this5 = _super.call(this, "Operation cancelled by caller.");
|
|
648
|
+
_this5.name = "CancelledError";
|
|
649
|
+
return _this5;
|
|
649
650
|
}
|
|
650
651
|
return runtime_createClass(CancelledError);
|
|
651
652
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
@@ -653,13 +654,13 @@ var BytescaleApiError = /*#__PURE__*/function (_Error2) {
|
|
|
653
654
|
_inherits(BytescaleApiError, _Error2);
|
|
654
655
|
var _super2 = _createSuper(BytescaleApiError);
|
|
655
656
|
function BytescaleApiError(response) {
|
|
656
|
-
var
|
|
657
|
+
var _this6;
|
|
657
658
|
runtime_classCallCheck(this, BytescaleApiError);
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
return
|
|
659
|
+
_this6 = _super2.call(this, response.error.message);
|
|
660
|
+
_this6.name = "BytescaleApiError";
|
|
661
|
+
_this6.errorCode = response.error.code;
|
|
662
|
+
_this6.details = response.error.details;
|
|
663
|
+
return _this6;
|
|
663
664
|
}
|
|
664
665
|
return runtime_createClass(BytescaleApiError);
|
|
665
666
|
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
@@ -685,8 +686,8 @@ var JSONApiResponse = /*#__PURE__*/function () {
|
|
|
685
686
|
key: "value",
|
|
686
687
|
value: function value() {
|
|
687
688
|
try {
|
|
688
|
-
var
|
|
689
|
-
return runtime_await(
|
|
689
|
+
var _this8 = this;
|
|
690
|
+
return runtime_await(_this8.raw.json());
|
|
690
691
|
} catch (e) {
|
|
691
692
|
return Promise.reject(e);
|
|
692
693
|
}
|
|
@@ -727,8 +728,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
727
728
|
key: "text",
|
|
728
729
|
value: function text() {
|
|
729
730
|
try {
|
|
730
|
-
var
|
|
731
|
-
return runtime_await(
|
|
731
|
+
var _this10 = this;
|
|
732
|
+
return runtime_await(_this10.raw.text());
|
|
732
733
|
} catch (e) {
|
|
733
734
|
return Promise.reject(e);
|
|
734
735
|
}
|
|
@@ -737,8 +738,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
737
738
|
key: "blob",
|
|
738
739
|
value: function blob() {
|
|
739
740
|
try {
|
|
740
|
-
var
|
|
741
|
-
return runtime_await(
|
|
741
|
+
var _this12 = this;
|
|
742
|
+
return runtime_await(_this12.raw.blob());
|
|
742
743
|
} catch (e) {
|
|
743
744
|
return Promise.reject(e);
|
|
744
745
|
}
|
|
@@ -747,8 +748,8 @@ var BinaryResult = /*#__PURE__*/function () {
|
|
|
747
748
|
key: "json",
|
|
748
749
|
value: function json() {
|
|
749
750
|
try {
|
|
750
|
-
var
|
|
751
|
-
return runtime_await(
|
|
751
|
+
var _this14 = this;
|
|
752
|
+
return runtime_await(_this14.raw.json());
|
|
752
753
|
} catch (e) {
|
|
753
754
|
return Promise.reject(e);
|
|
754
755
|
}
|
|
@@ -2990,13 +2991,13 @@ function AuthManagerNode_createClass(Constructor, protoProps, staticProps) { if
|
|
|
2990
2991
|
function AuthManagerNode_toPropertyKey(arg) { var key = AuthManagerNode_toPrimitive(arg, "string"); return AuthManagerNode_typeof(key) === "symbol" ? key : String(key); }
|
|
2991
2992
|
function AuthManagerNode_toPrimitive(input, hint) { if (AuthManagerNode_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (AuthManagerNode_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
2992
2993
|
|
|
2993
|
-
var
|
|
2994
|
-
function
|
|
2995
|
-
AuthManagerNode_classCallCheck(this,
|
|
2994
|
+
var AuthManagerImpl = /*#__PURE__*/function () {
|
|
2995
|
+
function AuthManagerImpl() {
|
|
2996
|
+
AuthManagerNode_classCallCheck(this, AuthManagerImpl);
|
|
2996
2997
|
}
|
|
2997
|
-
AuthManagerNode_createClass(
|
|
2998
|
+
AuthManagerNode_createClass(AuthManagerImpl, [{
|
|
2998
2999
|
key: "beginAuthSession",
|
|
2999
|
-
value: function beginAuthSession(
|
|
3000
|
+
value: function beginAuthSession(_params) {
|
|
3000
3001
|
try {
|
|
3001
3002
|
throw EnvChecker.methodRequiresBrowser("beginAuthSession");
|
|
3002
3003
|
} catch (e) {
|
|
@@ -3018,8 +3019,12 @@ var AuthManager = /*#__PURE__*/function () {
|
|
|
3018
3019
|
return false;
|
|
3019
3020
|
}
|
|
3020
3021
|
}]);
|
|
3021
|
-
return
|
|
3022
|
+
return AuthManagerImpl;
|
|
3022
3023
|
}();
|
|
3024
|
+
/**
|
|
3025
|
+
* Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
|
|
3026
|
+
*/
|
|
3027
|
+
var AuthManager = new AuthManagerImpl();
|
|
3023
3028
|
;// CONCATENATED MODULE: ./src/public/node/index.ts
|
|
3024
3029
|
|
|
3025
3030
|
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
import { BytescaleApiClientConfig } from "../../public/shared";
|
|
2
|
+
export interface BeginAuthSessionParams extends Pick<BytescaleApiClientConfig, "fetchApi" | "cdnUrl" | "apiKey"> {
|
|
3
|
+
/**
|
|
4
|
+
* Headers to send to your backend API.
|
|
5
|
+
*
|
|
6
|
+
* IMPORTANT: do not call 'AuthManager.beginAuthSession' or 'AuthManager.endAuthSession' inside this callback, as this will cause a deadlock.
|
|
7
|
+
*/
|
|
8
|
+
authHeaders: () => Promise<Record<string, string>>;
|
|
9
|
+
/**
|
|
10
|
+
* The fully-qualified URL for your backend API's auth endpoint.
|
|
11
|
+
*/
|
|
12
|
+
authUrl: string;
|
|
13
|
+
}
|
|
1
14
|
export interface AuthManagerInterface {
|
|
2
15
|
/**
|
|
3
16
|
* Begins an authenticated Bytescale API and Bytescale CDN session.
|
|
@@ -21,12 +34,8 @@ export interface AuthManagerInterface {
|
|
|
21
34
|
* 2) The JWT will be saved to a cookie scoped to the Bytescale CDN. This allows the user to view private files via the URL in the browser, including <img> elements on the page that reference private images, etc.
|
|
22
35
|
*
|
|
23
36
|
* 3) The JWT will also be added as a request header via 'authorization-token' to all Bytescale API requests made via this SDK. This allows the user to upload private files and perform administrative operations permitted by the JWT, such as deleting files, etc.
|
|
24
|
-
*
|
|
25
|
-
* @param authUrl The fully-qualified URL for your backend API's auth endpoint.
|
|
26
|
-
* @param authHeaders Headers to send to your backend API.
|
|
27
|
-
* IMPORTANT: do not call '*AuthSession' inside this callback, as this will cause a deadlock.
|
|
28
37
|
*/
|
|
29
|
-
beginAuthSession: (
|
|
38
|
+
beginAuthSession: (params: BeginAuthSessionParams) => Promise<void>;
|
|
30
39
|
/**
|
|
31
40
|
* Ends an authenticated Bytescale API and Bytescale CDN session.
|
|
32
41
|
*
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { BeginAuthSessionParams } from "./AuthManagerInterface";
|
|
1
2
|
export interface AuthSession {
|
|
2
3
|
accessToken: string | undefined;
|
|
3
4
|
accessTokenRefreshHandle: number | undefined;
|
|
4
|
-
authHeaders: () => Promise<Record<string, string>>;
|
|
5
|
-
authUrl: string;
|
|
6
5
|
isActive: boolean;
|
|
6
|
+
params: BeginAuthSessionParams;
|
|
7
7
|
}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { AuthManagerInterface } from "../../private/model/AuthManagerInterface";
|
|
2
|
-
|
|
3
|
-
export declare class AuthManager extends BaseAPI implements AuthManagerInterface {
|
|
4
|
-
private readonly accessTokenUrl;
|
|
1
|
+
import { AuthManagerInterface, BeginAuthSessionParams } from "../../private/model/AuthManagerInterface";
|
|
2
|
+
declare class AuthManagerImpl implements AuthManagerInterface {
|
|
5
3
|
private readonly authSessionMutex;
|
|
6
4
|
private readonly contentType;
|
|
7
5
|
private readonly contentTypeJson;
|
|
@@ -10,12 +8,18 @@ export declare class AuthManager extends BaseAPI implements AuthManagerInterface
|
|
|
10
8
|
private readonly maxJwtTtlSeconds;
|
|
11
9
|
private readonly retryAuthAfterErrorSeconds;
|
|
12
10
|
private readonly refreshBeforeExpirySeconds;
|
|
13
|
-
constructor(
|
|
11
|
+
constructor();
|
|
14
12
|
isAuthSessionActive(): boolean;
|
|
15
|
-
beginAuthSession(
|
|
13
|
+
beginAuthSession(params: BeginAuthSessionParams): Promise<void>;
|
|
16
14
|
endAuthSession(): Promise<void>;
|
|
17
15
|
private refreshAccessToken;
|
|
16
|
+
private getAccessTokenUrl;
|
|
18
17
|
private deleteAccessToken;
|
|
19
18
|
private setAccessToken;
|
|
20
19
|
private getAccessToken;
|
|
21
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
|
|
23
|
+
*/
|
|
24
|
+
export declare const AuthManager: AuthManagerImpl;
|
|
25
|
+
export {};
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
import { AuthManagerInterface } from "../../private/model/AuthManagerInterface";
|
|
2
|
-
|
|
3
|
-
beginAuthSession(
|
|
1
|
+
import { AuthManagerInterface, BeginAuthSessionParams } from "../../private/model/AuthManagerInterface";
|
|
2
|
+
declare class AuthManagerImpl implements AuthManagerInterface {
|
|
3
|
+
beginAuthSession(_params: BeginAuthSessionParams): Promise<void>;
|
|
4
4
|
endAuthSession(): Promise<void>;
|
|
5
5
|
isAuthSessionActive(): boolean;
|
|
6
6
|
}
|
|
7
|
+
/**
|
|
8
|
+
* Alternative way of implementing a static class (i.e. all methods static). We do this so we can use a interface on the class (interfaces can't define static methods).
|
|
9
|
+
*/
|
|
10
|
+
export declare const AuthManager: AuthManagerImpl;
|
|
11
|
+
export {};
|
|
@@ -45,9 +45,9 @@ export declare class BytescaleApiClientConfigUtils {
|
|
|
45
45
|
private static readonly specialApiKeyAccountId;
|
|
46
46
|
private static readonly accountIdLength;
|
|
47
47
|
static getApiUrl(config: BytescaleApiClientConfig): string;
|
|
48
|
-
static getCdnUrl(config: BytescaleApiClientConfig): string;
|
|
49
|
-
static getFetchApi(config: BytescaleApiClientConfig): FetchAPI;
|
|
50
|
-
static getAccountId(config: BytescaleApiClientConfig): string;
|
|
48
|
+
static getCdnUrl(config: Pick<BytescaleApiClientConfig, "cdnUrl">): string;
|
|
49
|
+
static getFetchApi(config: Pick<BytescaleApiClientConfig, "fetchApi">): FetchAPI;
|
|
50
|
+
static getAccountId(config: Pick<BytescaleApiClientConfig, "apiKey">): string;
|
|
51
51
|
static validate(config: BytescaleApiClientConfig): void;
|
|
52
52
|
}
|
|
53
53
|
/**
|
|
@@ -56,11 +56,13 @@ export declare class BytescaleApiClientConfigUtils {
|
|
|
56
56
|
export declare class BaseAPI {
|
|
57
57
|
protected readonly config: BytescaleApiClientConfig;
|
|
58
58
|
constructor(config: BytescaleApiClientConfig);
|
|
59
|
-
protected request(context: RequestOpts, initOverrides: RequestInit | InitOverrideFunction | undefined, baseUrlOverride: string | undefined): Promise<Response>;
|
|
60
59
|
/**
|
|
61
60
|
* Returns a successful response (2**) else throws an error.
|
|
62
61
|
*/
|
|
63
|
-
|
|
62
|
+
static fetch(url: string, init: RequestInit, config: Pick<BytescaleApiClientConfig, "fetchApi"> & {
|
|
63
|
+
isBytescaleApi: boolean;
|
|
64
|
+
}): Promise<Response>;
|
|
65
|
+
protected request(context: RequestOpts, initOverrides: RequestInit | InitOverrideFunction | undefined, baseUrlOverride: string | undefined): Promise<Response>;
|
|
64
66
|
protected encodeParam(paramName: string, paramValue: string): string;
|
|
65
67
|
private createFetchParams;
|
|
66
68
|
}
|