@kontent-ai/delivery-sdk 15.0.0 → 15.1.1

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.
@@ -4411,7 +4411,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
4411
4411
  exports.sdkInfo = void 0;
4412
4412
  exports.sdkInfo = {
4413
4413
  host: 'npmjs.com',
4414
- version: '15.0.0',
4414
+ version: '15.1.1',
4415
4415
  name: '@kontent-ai/delivery-sdk'
4416
4416
  };
4417
4417
 
@@ -7297,7 +7297,11 @@ const getBodyLength = async (body) => {
7297
7297
  }
7298
7298
 
7299
7299
  if(_utils_js__WEBPACK_IMPORTED_MODULE_1__["default"].isSpecCompliantForm(body)) {
7300
- return (await new Request(body).arrayBuffer()).byteLength;
7300
+ const _request = new Request(_platform_index_js__WEBPACK_IMPORTED_MODULE_0__["default"].origin, {
7301
+ method: 'POST',
7302
+ body,
7303
+ });
7304
+ return (await _request.arrayBuffer()).byteLength;
7301
7305
  }
7302
7306
 
7303
7307
  if(_utils_js__WEBPACK_IMPORTED_MODULE_1__["default"].isArrayBufferView(body) || _utils_js__WEBPACK_IMPORTED_MODULE_1__["default"].isArrayBuffer(body)) {
@@ -7337,18 +7341,13 @@ const resolveBodyLength = async (headers, body) => {
7337
7341
 
7338
7342
  responseType = responseType ? (responseType + '').toLowerCase() : 'text';
7339
7343
 
7340
- let [composedSignal, stopTimeout] = (signal || cancelToken || timeout) ?
7341
- (0,_helpers_composeSignals_js__WEBPACK_IMPORTED_MODULE_4__["default"])([signal, cancelToken], timeout) : [];
7342
-
7343
- let finished, request;
7344
+ let composedSignal = (0,_helpers_composeSignals_js__WEBPACK_IMPORTED_MODULE_4__["default"])([signal, cancelToken && cancelToken.toAbortSignal()], timeout);
7344
7345
 
7345
- const onFinish = () => {
7346
- !finished && setTimeout(() => {
7347
- composedSignal && composedSignal.unsubscribe();
7348
- });
7346
+ let request;
7349
7347
 
7350
- finished = true;
7351
- }
7348
+ const unsubscribe = composedSignal && composedSignal.unsubscribe && (() => {
7349
+ composedSignal.unsubscribe();
7350
+ });
7352
7351
 
7353
7352
  let requestContentLength;
7354
7353
 
@@ -7375,7 +7374,7 @@ const resolveBodyLength = async (headers, body) => {
7375
7374
  (0,_helpers_progressEventReducer_js__WEBPACK_IMPORTED_MODULE_5__.progressEventReducer)((0,_helpers_progressEventReducer_js__WEBPACK_IMPORTED_MODULE_5__.asyncDecorator)(onUploadProgress))
7376
7375
  );
7377
7376
 
7378
- data = (0,_helpers_trackStream_js__WEBPACK_IMPORTED_MODULE_6__.trackStream)(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush, encodeText);
7377
+ data = (0,_helpers_trackStream_js__WEBPACK_IMPORTED_MODULE_6__.trackStream)(_request.body, DEFAULT_CHUNK_SIZE, onProgress, flush);
7379
7378
  }
7380
7379
  }
7381
7380
 
@@ -7383,6 +7382,9 @@ const resolveBodyLength = async (headers, body) => {
7383
7382
  withCredentials = withCredentials ? 'include' : 'omit';
7384
7383
  }
7385
7384
 
7385
+ // Cloudflare Workers throws when credentials are defined
7386
+ // see https://github.com/cloudflare/workerd/issues/902
7387
+ const isCredentialsSupported = "credentials" in Request.prototype;
7386
7388
  request = new Request(url, {
7387
7389
  ...fetchOptions,
7388
7390
  signal: composedSignal,
@@ -7390,14 +7392,14 @@ const resolveBodyLength = async (headers, body) => {
7390
7392
  headers: headers.normalize().toJSON(),
7391
7393
  body: data,
7392
7394
  duplex: "half",
7393
- credentials: withCredentials
7395
+ credentials: isCredentialsSupported ? withCredentials : undefined
7394
7396
  });
7395
7397
 
7396
7398
  let response = await fetch(request);
7397
7399
 
7398
7400
  const isStreamResponse = supportsResponseStream && (responseType === 'stream' || responseType === 'response');
7399
7401
 
7400
- if (supportsResponseStream && (onDownloadProgress || isStreamResponse)) {
7402
+ if (supportsResponseStream && (onDownloadProgress || (isStreamResponse && unsubscribe))) {
7401
7403
  const options = {};
7402
7404
 
7403
7405
  ['status', 'statusText', 'headers'].forEach(prop => {
@@ -7414,8 +7416,8 @@ const resolveBodyLength = async (headers, body) => {
7414
7416
  response = new Response(
7415
7417
  (0,_helpers_trackStream_js__WEBPACK_IMPORTED_MODULE_6__.trackStream)(response.body, DEFAULT_CHUNK_SIZE, onProgress, () => {
7416
7418
  flush && flush();
7417
- isStreamResponse && onFinish();
7418
- }, encodeText),
7419
+ unsubscribe && unsubscribe();
7420
+ }),
7419
7421
  options
7420
7422
  );
7421
7423
  }
@@ -7424,9 +7426,7 @@ const resolveBodyLength = async (headers, body) => {
7424
7426
 
7425
7427
  let responseData = await resolvers[_utils_js__WEBPACK_IMPORTED_MODULE_1__["default"].findKey(resolvers, responseType) || 'text'](response, config);
7426
7428
 
7427
- !isStreamResponse && onFinish();
7428
-
7429
- stopTimeout && stopTimeout();
7429
+ !isStreamResponse && unsubscribe && unsubscribe();
7430
7430
 
7431
7431
  return await new Promise((resolve, reject) => {
7432
7432
  (0,_core_settle_js__WEBPACK_IMPORTED_MODULE_7__["default"])(resolve, reject, {
@@ -7439,7 +7439,7 @@ const resolveBodyLength = async (headers, body) => {
7439
7439
  })
7440
7440
  })
7441
7441
  } catch (err) {
7442
- onFinish();
7442
+ unsubscribe && unsubscribe();
7443
7443
 
7444
7444
  if (err && err.name === 'TypeError' && /fetch/i.test(err.message)) {
7445
7445
  throw Object.assign(
@@ -7915,6 +7915,20 @@ class CancelToken {
7915
7915
  }
7916
7916
  }
7917
7917
 
7918
+ toAbortSignal() {
7919
+ const controller = new AbortController();
7920
+
7921
+ const abort = (err) => {
7922
+ controller.abort(err);
7923
+ };
7924
+
7925
+ this.subscribe(abort);
7926
+
7927
+ controller.signal.unsubscribe = () => this.unsubscribe(abort);
7928
+
7929
+ return controller.signal;
7930
+ }
7931
+
7918
7932
  /**
7919
7933
  * Returns an object that contains a new `CancelToken` and a function that, when called,
7920
7934
  * cancels the `CancelToken`.
@@ -8286,7 +8300,10 @@ function AxiosError(message, code, config, request, response) {
8286
8300
  code && (this.code = code);
8287
8301
  config && (this.config = config);
8288
8302
  request && (this.request = request);
8289
- response && (this.response = response);
8303
+ if (response) {
8304
+ this.response = response;
8305
+ this.status = response.status ? response.status : null;
8306
+ }
8290
8307
  }
8291
8308
 
8292
8309
  _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].inherits(AxiosError, Error, {
@@ -8306,7 +8323,7 @@ _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].inherits(AxiosError, Error, {
8306
8323
  // Axios
8307
8324
  config: _utils_js__WEBPACK_IMPORTED_MODULE_0__["default"].toJSONObject(this.config),
8308
8325
  code: this.code,
8309
- status: this.response && this.response.status ? this.response.status : null
8326
+ status: this.status
8310
8327
  };
8311
8328
  }
8312
8329
  });
@@ -9325,7 +9342,7 @@ __webpack_require__.r(__webpack_exports__);
9325
9342
  /* harmony export */ __webpack_require__.d(__webpack_exports__, {
9326
9343
  /* harmony export */ VERSION: () => (/* binding */ VERSION)
9327
9344
  /* harmony export */ });
9328
- const VERSION = "1.7.4";
9345
+ const VERSION = "1.7.7";
9329
9346
 
9330
9347
  /***/ }),
9331
9348
 
@@ -9628,49 +9645,52 @@ __webpack_require__.r(__webpack_exports__);
9628
9645
  /* harmony export */ });
9629
9646
  /* harmony import */ var _cancel_CanceledError_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../cancel/CanceledError.js */ "./node_modules/axios/lib/cancel/CanceledError.js");
9630
9647
  /* harmony import */ var _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../core/AxiosError.js */ "./node_modules/axios/lib/core/AxiosError.js");
9648
+ /* harmony import */ var _utils_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ../utils.js */ "./node_modules/axios/lib/utils.js");
9649
+
9631
9650
 
9632
9651
 
9633
9652
 
9634
9653
  const composeSignals = (signals, timeout) => {
9635
- let controller = new AbortController();
9654
+ const {length} = (signals = signals ? signals.filter(Boolean) : []);
9636
9655
 
9637
- let aborted;
9656
+ if (timeout || length) {
9657
+ let controller = new AbortController();
9638
9658
 
9639
- const onabort = function (cancel) {
9640
- if (!aborted) {
9641
- aborted = true;
9642
- unsubscribe();
9643
- const err = cancel instanceof Error ? cancel : this.reason;
9644
- controller.abort(err instanceof _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_0__["default"] ? err : new _cancel_CanceledError_js__WEBPACK_IMPORTED_MODULE_1__["default"](err instanceof Error ? err.message : err));
9645
- }
9646
- }
9659
+ let aborted;
9647
9660
 
9648
- let timer = timeout && setTimeout(() => {
9649
- onabort(new _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_0__["default"](`timeout ${timeout} of ms exceeded`, _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_0__["default"].ETIMEDOUT))
9650
- }, timeout)
9661
+ const onabort = function (reason) {
9662
+ if (!aborted) {
9663
+ aborted = true;
9664
+ unsubscribe();
9665
+ const err = reason instanceof Error ? reason : this.reason;
9666
+ controller.abort(err instanceof _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_0__["default"] ? err : new _cancel_CanceledError_js__WEBPACK_IMPORTED_MODULE_1__["default"](err instanceof Error ? err.message : err));
9667
+ }
9668
+ }
9651
9669
 
9652
- const unsubscribe = () => {
9653
- if (signals) {
9654
- timer && clearTimeout(timer);
9670
+ let timer = timeout && setTimeout(() => {
9655
9671
  timer = null;
9656
- signals.forEach(signal => {
9657
- signal &&
9658
- (signal.removeEventListener ? signal.removeEventListener('abort', onabort) : signal.unsubscribe(onabort));
9659
- });
9660
- signals = null;
9672
+ onabort(new _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_0__["default"](`timeout ${timeout} of ms exceeded`, _core_AxiosError_js__WEBPACK_IMPORTED_MODULE_0__["default"].ETIMEDOUT))
9673
+ }, timeout)
9674
+
9675
+ const unsubscribe = () => {
9676
+ if (signals) {
9677
+ timer && clearTimeout(timer);
9678
+ timer = null;
9679
+ signals.forEach(signal => {
9680
+ signal.unsubscribe ? signal.unsubscribe(onabort) : signal.removeEventListener('abort', onabort);
9681
+ });
9682
+ signals = null;
9683
+ }
9661
9684
  }
9662
- }
9663
9685
 
9664
- signals.forEach((signal) => signal && signal.addEventListener && signal.addEventListener('abort', onabort));
9686
+ signals.forEach((signal) => signal.addEventListener('abort', onabort));
9665
9687
 
9666
- const {signal} = controller;
9688
+ const {signal} = controller;
9667
9689
 
9668
- signal.unsubscribe = unsubscribe;
9690
+ signal.unsubscribe = () => _utils_js__WEBPACK_IMPORTED_MODULE_2__["default"].asap(unsubscribe);
9669
9691
 
9670
- return [signal, () => {
9671
- timer && clearTimeout(timer);
9672
- timer = null;
9673
- }];
9692
+ return signal;
9693
+ }
9674
9694
  }
9675
9695
 
9676
9696
  /* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = (composeSignals);
@@ -9926,7 +9946,7 @@ __webpack_require__.r(__webpack_exports__);
9926
9946
  // Standard browser envs have full support of the APIs needed to test
9927
9947
  // whether the request URL is of the same origin as current location.
9928
9948
  (function standardBrowserEnv() {
9929
- const msie = /(msie|trident)/i.test(navigator.userAgent);
9949
+ const msie = _platform_index_js__WEBPACK_IMPORTED_MODULE_0__["default"].navigator && /(msie|trident)/i.test(_platform_index_js__WEBPACK_IMPORTED_MODULE_0__["default"].navigator.userAgent);
9930
9950
  const urlParsingNode = document.createElement('a');
9931
9951
  let originURL;
9932
9952
 
@@ -10706,14 +10726,34 @@ const streamChunk = function* (chunk, chunkSize) {
10706
10726
  }
10707
10727
  }
10708
10728
 
10709
- const readBytes = async function* (iterable, chunkSize, encode) {
10710
- for await (const chunk of iterable) {
10711
- yield* streamChunk(ArrayBuffer.isView(chunk) ? chunk : (await encode(String(chunk))), chunkSize);
10729
+ const readBytes = async function* (iterable, chunkSize) {
10730
+ for await (const chunk of readStream(iterable)) {
10731
+ yield* streamChunk(chunk, chunkSize);
10732
+ }
10733
+ }
10734
+
10735
+ const readStream = async function* (stream) {
10736
+ if (stream[Symbol.asyncIterator]) {
10737
+ yield* stream;
10738
+ return;
10739
+ }
10740
+
10741
+ const reader = stream.getReader();
10742
+ try {
10743
+ for (;;) {
10744
+ const {done, value} = await reader.read();
10745
+ if (done) {
10746
+ break;
10747
+ }
10748
+ yield value;
10749
+ }
10750
+ } finally {
10751
+ await reader.cancel();
10712
10752
  }
10713
10753
  }
10714
10754
 
10715
- const trackStream = (stream, chunkSize, onProgress, onFinish, encode) => {
10716
- const iterator = readBytes(stream, chunkSize, encode);
10755
+ const trackStream = (stream, chunkSize, onProgress, onFinish) => {
10756
+ const iterator = readBytes(stream, chunkSize);
10717
10757
 
10718
10758
  let bytes = 0;
10719
10759
  let done;
@@ -10959,10 +10999,13 @@ __webpack_require__.r(__webpack_exports__);
10959
10999
  /* harmony export */ hasBrowserEnv: () => (/* binding */ hasBrowserEnv),
10960
11000
  /* harmony export */ hasStandardBrowserEnv: () => (/* binding */ hasStandardBrowserEnv),
10961
11001
  /* harmony export */ hasStandardBrowserWebWorkerEnv: () => (/* binding */ hasStandardBrowserWebWorkerEnv),
11002
+ /* harmony export */ navigator: () => (/* binding */ _navigator),
10962
11003
  /* harmony export */ origin: () => (/* binding */ origin)
10963
11004
  /* harmony export */ });
10964
11005
  const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'undefined';
10965
11006
 
11007
+ const _navigator = typeof navigator === 'object' && navigator || undefined;
11008
+
10966
11009
  /**
10967
11010
  * Determine if we're running in a standard browser environment
10968
11011
  *
@@ -10980,10 +11023,8 @@ const hasBrowserEnv = typeof window !== 'undefined' && typeof document !== 'unde
10980
11023
  *
10981
11024
  * @returns {boolean}
10982
11025
  */
10983
- const hasStandardBrowserEnv = (
10984
- (product) => {
10985
- return hasBrowserEnv && ['ReactNative', 'NativeScript', 'NS'].indexOf(product) < 0
10986
- })(typeof navigator !== 'undefined' && navigator.product);
11026
+ const hasStandardBrowserEnv = hasBrowserEnv &&
11027
+ (!_navigator || ['ReactNative', 'NativeScript', 'NS'].indexOf(_navigator.product) < 0);
10987
11028
 
10988
11029
  /**
10989
11030
  * Determine if we're running in a standard browser webWorker environment