@commercetools-frontend/sdk 21.9.0 → 21.12.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.
@@ -30,6 +30,8 @@ var apiRequestBuilder = require('@commercetools/api-request-builder');
30
30
  var constants = require('@commercetools-frontend/constants');
31
31
  var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
32
32
  var qss = require('qss');
33
+ var _globalThis = require('@babel/runtime-corejs3/core-js/global-this');
34
+ var buffer = require('buffer');
33
35
  var sdkClient = require('@commercetools/sdk-client');
34
36
  var sdkMiddlewareHttp = require('@commercetools/sdk-middleware-http');
35
37
  var sdkMiddlewareCorrelationId = require('@commercetools/sdk-middleware-correlation-id');
@@ -51,6 +53,7 @@ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defin
51
53
  var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
52
54
  var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
53
55
  var _URL__default = /*#__PURE__*/_interopDefault(_URL);
56
+ var _globalThis__default = /*#__PURE__*/_interopDefault(_globalThis);
54
57
  var createHttpUserAgent__default = /*#__PURE__*/_interopDefault(createHttpUserAgent);
55
58
 
56
59
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -324,7 +327,7 @@ var index = /*#__PURE__*/Object.freeze({
324
327
  });
325
328
 
326
329
  // NOTE: This string will be replaced on build time with the package version.
327
- var version = "21.9.0";
330
+ var version = "21.12.0";
328
331
 
329
332
  /* eslint-disable no-console */
330
333
  var isLoggerEnabled = function isLoggerEnabled() {
@@ -407,47 +410,38 @@ var logRequest = function logRequest(_ref) {
407
410
  if (error) logger.log('%cerror', "color: red; font-weight: bold;", error);
408
411
  logger.groupEnd();
409
412
  };
413
+ var mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
414
+ var mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
410
415
 
411
- var removeMcPrefix = function removeMcPrefix(host) {
412
- return host.replace(/^mc(-(\d){4,})?\.(.*)$/, '$3');
413
- };
414
- /**
415
- * NOTE:
416
- * Given the Merchant Center or Custom Application runs behind the proxy
417
- * then the `mcApiUrl` should be build using the origin on the window.
418
- *
419
- * This allows the Merchant Center (or any Custom Appliction) to automatically
420
- * use an `mcApiUrl` which matches the respective url of the deployment.
421
- *
422
- * This is particularily useful with the new and old hostnames for the Merchant Center.
423
- * When using the origin, it will be made sure that the authorization cookie will
424
- * always be sent as the appropriate API url is used.
425
- *
426
- * 1. MC: mc.commercetools.com with API: mc-api.europe-west1.gcp.commercetools.com
427
- * -> Will not work as urls differ
428
- * 2. MC: mc.europe-west1.gcp.commercetools.com with API: mc-api.commercetools.com
429
- * -> Will not work as urls differ
430
- *
431
- * Using the origin ensures that urls always match the the cookie is sent. Otherwise,
432
- * the application shell will rightfully redirect to the logout page.
433
- */
416
+ var getMcOriginTld = function getMcOriginTld(host) {
417
+ if (host.match(mcPreviewHostnameRegex)) {
418
+ return host.replace(mcPreviewHostnameRegex, '$1');
419
+ }
434
420
 
421
+ return host.replace(mcHostnameRegex, '$3');
422
+ };
435
423
 
436
424
  var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(actualWindow) {
437
425
  var _context2;
438
426
 
439
427
  var url = new _URL__default["default"](actualWindow.origin);
440
- var originTld = removeMcPrefix(url.host);
428
+ var originTld = getMcOriginTld(url.host);
441
429
  return _concatInstanceProperty__default["default"](_context2 = "".concat(url.protocol, "//mc-api.")).call(_context2, originTld);
442
430
  };
443
431
 
444
- var isEnvironmentConfigurationEnabled = function isEnvironmentConfigurationEnabled(environmentConfiguration) {
445
- return environmentConfiguration === true || environmentConfiguration === 'true';
432
+ var parseAsBoolean = function parseAsBoolean(value) {
433
+ return value === true || value === 'true';
446
434
  };
447
435
 
448
436
  function getMcApiUrl() {
449
437
  var actualWindow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
450
- var isServedByProxy = isEnvironmentConfigurationEnabled(actualWindow.app.servedByProxy);
438
+ var isServedByProxy = parseAsBoolean(actualWindow.app.servedByProxy);
439
+ /**
440
+ * Prefer using the origin URL for the MC API based on the origin value
441
+ * of the browser's `window.location`.
442
+ * This ensures that the application always uses the correct URL associated
443
+ * with that environment, instead of relying on the config value.
444
+ */
451
445
 
452
446
  if (isServedByProxy) {
453
447
  return getMcApiUrlFromOrigin(actualWindow);
@@ -459,6 +453,8 @@ function getMcApiUrl() {
459
453
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
460
454
 
461
455
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
456
+
457
+ _globalThis__default["default"].Buffer = buffer.Buffer;
462
458
  var userAgent = createHttpUserAgent__default["default"]({
463
459
  name: '@commercetools/sdk-client',
464
460
  libraryName: [window.app.applicationName, 'sdk'].join('/'),
@@ -30,6 +30,8 @@ var apiRequestBuilder = require('@commercetools/api-request-builder');
30
30
  var constants = require('@commercetools-frontend/constants');
31
31
  var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
32
32
  require('qss');
33
+ var _globalThis = require('@babel/runtime-corejs3/core-js/global-this');
34
+ var buffer = require('buffer');
33
35
  var sdkClient = require('@commercetools/sdk-client');
34
36
  var sdkMiddlewareHttp = require('@commercetools/sdk-middleware-http');
35
37
  var sdkMiddlewareCorrelationId = require('@commercetools/sdk-middleware-correlation-id');
@@ -50,6 +52,7 @@ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defin
50
52
  var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
51
53
  var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
52
54
  var _URL__default = /*#__PURE__*/_interopDefault(_URL);
55
+ var _globalThis__default = /*#__PURE__*/_interopDefault(_globalThis);
53
56
  var createHttpUserAgent__default = /*#__PURE__*/_interopDefault(createHttpUserAgent);
54
57
 
55
58
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
@@ -315,48 +318,40 @@ var index = /*#__PURE__*/Object.freeze({
315
318
  });
316
319
 
317
320
  // NOTE: This string will be replaced on build time with the package version.
318
- var version = "21.9.0";
321
+ var version = "21.12.0";
319
322
 
320
- var removeMcPrefix = function removeMcPrefix(host) {
321
- return host.replace(/^mc(-(\d){4,})?\.(.*)$/, '$3');
322
- };
323
- /**
324
- * NOTE:
325
- * Given the Merchant Center or Custom Application runs behind the proxy
326
- * then the `mcApiUrl` should be build using the origin on the window.
327
- *
328
- * This allows the Merchant Center (or any Custom Appliction) to automatically
329
- * use an `mcApiUrl` which matches the respective url of the deployment.
330
- *
331
- * This is particularily useful with the new and old hostnames for the Merchant Center.
332
- * When using the origin, it will be made sure that the authorization cookie will
333
- * always be sent as the appropriate API url is used.
334
- *
335
- * 1. MC: mc.commercetools.com with API: mc-api.europe-west1.gcp.commercetools.com
336
- * -> Will not work as urls differ
337
- * 2. MC: mc.europe-west1.gcp.commercetools.com with API: mc-api.commercetools.com
338
- * -> Will not work as urls differ
339
- *
340
- * Using the origin ensures that urls always match the the cookie is sent. Otherwise,
341
- * the application shell will rightfully redirect to the logout page.
342
- */
323
+ var mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
324
+ var mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
343
325
 
326
+ var getMcOriginTld = function getMcOriginTld(host) {
327
+ if (host.match(mcPreviewHostnameRegex)) {
328
+ return host.replace(mcPreviewHostnameRegex, '$1');
329
+ }
330
+
331
+ return host.replace(mcHostnameRegex, '$3');
332
+ };
344
333
 
345
334
  var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(actualWindow) {
346
335
  var _context2;
347
336
 
348
337
  var url = new _URL__default["default"](actualWindow.origin);
349
- var originTld = removeMcPrefix(url.host);
338
+ var originTld = getMcOriginTld(url.host);
350
339
  return _concatInstanceProperty__default["default"](_context2 = "".concat(url.protocol, "//mc-api.")).call(_context2, originTld);
351
340
  };
352
341
 
353
- var isEnvironmentConfigurationEnabled = function isEnvironmentConfigurationEnabled(environmentConfiguration) {
354
- return environmentConfiguration === true || environmentConfiguration === 'true';
342
+ var parseAsBoolean = function parseAsBoolean(value) {
343
+ return value === true || value === 'true';
355
344
  };
356
345
 
357
346
  function getMcApiUrl() {
358
347
  var actualWindow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
359
- var isServedByProxy = isEnvironmentConfigurationEnabled(actualWindow.app.servedByProxy);
348
+ var isServedByProxy = parseAsBoolean(actualWindow.app.servedByProxy);
349
+ /**
350
+ * Prefer using the origin URL for the MC API based on the origin value
351
+ * of the browser's `window.location`.
352
+ * This ensures that the application always uses the correct URL associated
353
+ * with that environment, instead of relying on the config value.
354
+ */
360
355
 
361
356
  if (isServedByProxy) {
362
357
  return getMcApiUrlFromOrigin(actualWindow);
@@ -368,6 +363,8 @@ function getMcApiUrl() {
368
363
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
369
364
 
370
365
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
366
+
367
+ _globalThis__default["default"].Buffer = buffer.Buffer;
371
368
  var userAgent = createHttpUserAgent__default["default"]({
372
369
  name: '@commercetools/sdk-client',
373
370
  libraryName: [window.app.applicationName, 'sdk'].join('/'),
@@ -26,6 +26,8 @@ import { createRequestBuilder } from '@commercetools/api-request-builder';
26
26
  import { SHOW_LOADING, STATUS_CODES, HIDE_LOADING } from '@commercetools-frontend/constants';
27
27
  import _URL from '@babel/runtime-corejs3/core-js-stable/url';
28
28
  import { decode } from 'qss';
29
+ import _globalThis from '@babel/runtime-corejs3/core-js/global-this';
30
+ import { Buffer } from 'buffer';
29
31
  import { createClient as createClient$1 } from '@commercetools/sdk-client';
30
32
  import { createHttpMiddleware } from '@commercetools/sdk-middleware-http';
31
33
  import { createCorrelationIdMiddleware as createCorrelationIdMiddleware$1 } from '@commercetools/sdk-middleware-correlation-id';
@@ -302,7 +304,7 @@ var index = /*#__PURE__*/Object.freeze({
302
304
  });
303
305
 
304
306
  // NOTE: This string will be replaced on build time with the package version.
305
- var version = "21.9.0";
307
+ var version = "21.12.0";
306
308
 
307
309
  /* eslint-disable no-console */
308
310
  var isLoggerEnabled = function isLoggerEnabled() {
@@ -385,47 +387,38 @@ var logRequest = function logRequest(_ref) {
385
387
  if (error) logger.log('%cerror', "color: red; font-weight: bold;", error);
386
388
  logger.groupEnd();
387
389
  };
390
+ var mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
391
+ var mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
388
392
 
389
- var removeMcPrefix = function removeMcPrefix(host) {
390
- return host.replace(/^mc(-(\d){4,})?\.(.*)$/, '$3');
391
- };
392
- /**
393
- * NOTE:
394
- * Given the Merchant Center or Custom Application runs behind the proxy
395
- * then the `mcApiUrl` should be build using the origin on the window.
396
- *
397
- * This allows the Merchant Center (or any Custom Appliction) to automatically
398
- * use an `mcApiUrl` which matches the respective url of the deployment.
399
- *
400
- * This is particularily useful with the new and old hostnames for the Merchant Center.
401
- * When using the origin, it will be made sure that the authorization cookie will
402
- * always be sent as the appropriate API url is used.
403
- *
404
- * 1. MC: mc.commercetools.com with API: mc-api.europe-west1.gcp.commercetools.com
405
- * -> Will not work as urls differ
406
- * 2. MC: mc.europe-west1.gcp.commercetools.com with API: mc-api.commercetools.com
407
- * -> Will not work as urls differ
408
- *
409
- * Using the origin ensures that urls always match the the cookie is sent. Otherwise,
410
- * the application shell will rightfully redirect to the logout page.
411
- */
393
+ var getMcOriginTld = function getMcOriginTld(host) {
394
+ if (host.match(mcPreviewHostnameRegex)) {
395
+ return host.replace(mcPreviewHostnameRegex, '$1');
396
+ }
412
397
 
398
+ return host.replace(mcHostnameRegex, '$3');
399
+ };
413
400
 
414
401
  var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(actualWindow) {
415
402
  var _context2;
416
403
 
417
404
  var url = new _URL(actualWindow.origin);
418
- var originTld = removeMcPrefix(url.host);
405
+ var originTld = getMcOriginTld(url.host);
419
406
  return _concatInstanceProperty(_context2 = "".concat(url.protocol, "//mc-api.")).call(_context2, originTld);
420
407
  };
421
408
 
422
- var isEnvironmentConfigurationEnabled = function isEnvironmentConfigurationEnabled(environmentConfiguration) {
423
- return environmentConfiguration === true || environmentConfiguration === 'true';
409
+ var parseAsBoolean = function parseAsBoolean(value) {
410
+ return value === true || value === 'true';
424
411
  };
425
412
 
426
413
  function getMcApiUrl() {
427
414
  var actualWindow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
428
- var isServedByProxy = isEnvironmentConfigurationEnabled(actualWindow.app.servedByProxy);
415
+ var isServedByProxy = parseAsBoolean(actualWindow.app.servedByProxy);
416
+ /**
417
+ * Prefer using the origin URL for the MC API based on the origin value
418
+ * of the browser's `window.location`.
419
+ * This ensures that the application always uses the correct URL associated
420
+ * with that environment, instead of relying on the config value.
421
+ */
429
422
 
430
423
  if (isServedByProxy) {
431
424
  return getMcApiUrlFromOrigin(actualWindow);
@@ -437,6 +430,8 @@ function getMcApiUrl() {
437
430
  function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
438
431
 
439
432
  function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
433
+
434
+ _globalThis.Buffer = Buffer;
440
435
  var userAgent = createHttpUserAgent({
441
436
  name: '@commercetools/sdk-client',
442
437
  libraryName: [window.app.applicationName, 'sdk'].join('/'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/sdk",
3
- "version": "21.9.0",
3
+ "version": "21.12.0",
4
4
  "description": "Tools for declarative fetching",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@babel/runtime": "^7.18.6",
25
25
  "@babel/runtime-corejs3": "^7.18.6",
26
- "@commercetools-frontend/constants": "21.9.0",
26
+ "@commercetools-frontend/constants": "21.12.0",
27
27
  "@commercetools/api-request-builder": "5.6.3",
28
28
  "@commercetools/http-user-agent": "2.1.2",
29
29
  "@commercetools/sdk-client": "2.1.2",
@@ -33,6 +33,7 @@
33
33
  "@types/prop-types": "^15.7.5",
34
34
  "@types/react": "^17.0.47",
35
35
  "@types/react-redux": "^7.1.24",
36
+ "buffer": "6.0.3",
36
37
  "fast-equals": "2.0.4",
37
38
  "prop-types": "15.8.1",
38
39
  "qss": "2.0.3",