@commercetools-frontend/sdk 24.11.0 → 24.13.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.
- package/dist/commercetools-frontend-sdk.cjs.dev.js +28 -21
- package/dist/commercetools-frontend-sdk.cjs.prod.js +21 -15
- package/dist/commercetools-frontend-sdk.esm.js +27 -21
- package/package.json +2 -2
- package/test-utils/dist/commercetools-frontend-sdk-test-utils.cjs.dev.js +5 -2
- package/test-utils/dist/commercetools-frontend-sdk-test-utils.cjs.prod.js +5 -2
- package/test-utils/dist/commercetools-frontend-sdk-test-utils.esm.js +4 -2
|
@@ -24,6 +24,7 @@ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
|
24
24
|
var react = require('react');
|
|
25
25
|
var fastEquals = require('fast-equals');
|
|
26
26
|
var reactRedux = require('react-redux');
|
|
27
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
27
28
|
var apiRequestBuilder = require('@commercetools/api-request-builder');
|
|
28
29
|
var constants = require('@commercetools-frontend/constants');
|
|
29
30
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
@@ -49,6 +50,7 @@ var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInsta
|
|
|
49
50
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
50
51
|
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
51
52
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
53
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
52
54
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
53
55
|
var _globalThis__default = /*#__PURE__*/_interopDefault(_globalThis);
|
|
54
56
|
var createHttpUserAgent__default = /*#__PURE__*/_interopDefault(createHttpUserAgent);
|
|
@@ -92,8 +94,8 @@ function post(payload) {
|
|
|
92
94
|
};
|
|
93
95
|
}
|
|
94
96
|
const enhancePayloadForForwardToProxy = payload => {
|
|
95
|
-
var _context;
|
|
96
|
-
const headers = payload.headers
|
|
97
|
+
var _payload$headers, _context;
|
|
98
|
+
const headers = (_payload$headers = payload.headers) !== null && _payload$headers !== void 0 ? _payload$headers : {};
|
|
97
99
|
const exchangeTokenClaims = [];
|
|
98
100
|
if (payload.includeUserPermissions) {
|
|
99
101
|
exchangeTokenClaims.push('permissions');
|
|
@@ -107,7 +109,7 @@ const enhancePayloadForForwardToProxy = payload => {
|
|
|
107
109
|
headerValue = _ref2[1];
|
|
108
110
|
return _objectSpread$3(_objectSpread$3({}, customForwardHeaders), {}, {
|
|
109
111
|
// Prefix headers so that the MC API can allow and forward them.
|
|
110
|
-
[
|
|
112
|
+
["x-forward-header-".concat(headerName)]: headerValue
|
|
111
113
|
});
|
|
112
114
|
}, {})), {}, {
|
|
113
115
|
'Accept-version': 'v2',
|
|
@@ -198,7 +200,7 @@ let SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
198
200
|
onSuccess = _ref.onSuccess,
|
|
199
201
|
onError = _ref.onError;
|
|
200
202
|
_this.changeRequestsInFlight(1);
|
|
201
|
-
return dispatch(actionCreator(...(actionCreatorArgs
|
|
203
|
+
return dispatch(actionCreator(...(actionCreatorArgs !== null && actionCreatorArgs !== void 0 ? actionCreatorArgs : defaultProps.actionCreatorArgs))).then(result => {
|
|
202
204
|
_this.changeRequestsInFlight(-1);
|
|
203
205
|
if (_this.isComponentMounted) _this.setState({
|
|
204
206
|
error: undefined,
|
|
@@ -250,8 +252,9 @@ let SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
250
252
|
}, {
|
|
251
253
|
key: "componentDidUpdate",
|
|
252
254
|
value: function componentDidUpdate(prevProps) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
+
var _this$props$shouldRef, _prevProps$actionCrea, _this$props$actionCre;
|
|
256
|
+
const shouldRefetch = (_this$props$shouldRef = this.props.shouldRefetch) !== null && _this$props$shouldRef !== void 0 ? _this$props$shouldRef : defaultProps.shouldRefetch;
|
|
257
|
+
if (shouldRefetch((_prevProps$actionCrea = prevProps.actionCreatorArgs) !== null && _prevProps$actionCrea !== void 0 ? _prevProps$actionCrea : defaultProps.actionCreatorArgs, (_this$props$actionCre = this.props.actionCreatorArgs) !== null && _this$props$actionCre !== void 0 ? _this$props$actionCre : defaultProps.actionCreatorArgs)) {
|
|
255
258
|
this.fetch({
|
|
256
259
|
dispatch: this.props.dispatch,
|
|
257
260
|
actionCreator: this.props.actionCreator,
|
|
@@ -288,7 +291,7 @@ const mapDispatchToProps = dispatch => ({
|
|
|
288
291
|
var SdkGet$1 = reactRedux.connect(null, mapDispatchToProps)(SdkGet);
|
|
289
292
|
|
|
290
293
|
// NOTE: This string will be replaced on build time with the package version.
|
|
291
|
-
var version = "24.
|
|
294
|
+
var version = "24.13.0";
|
|
292
295
|
|
|
293
296
|
/* eslint-disable no-console */
|
|
294
297
|
|
|
@@ -319,7 +322,7 @@ const logger = {
|
|
|
319
322
|
};
|
|
320
323
|
|
|
321
324
|
function ownKeys$2(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
322
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
325
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$2(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$2(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
323
326
|
const parseUri = uri => {
|
|
324
327
|
const parser = document.createElement('a');
|
|
325
328
|
parser.href = uri;
|
|
@@ -330,24 +333,25 @@ const parseUri = uri => {
|
|
|
330
333
|
};
|
|
331
334
|
const isPostAction = action => action.payload.method === 'POST';
|
|
332
335
|
const logRequest = _ref => {
|
|
336
|
+
var _context;
|
|
333
337
|
let method = _ref.method,
|
|
334
338
|
request = _ref.request,
|
|
335
339
|
response = _ref.response,
|
|
336
340
|
error = _ref.error,
|
|
337
341
|
action = _ref.action;
|
|
338
342
|
const uriParts = parseUri(request.uri);
|
|
339
|
-
const groupName =
|
|
340
|
-
logger.groupCollapsed(groupName,
|
|
343
|
+
const groupName = _concatInstanceProperty__default["default"](_context = "%c".concat(method, " %c")).call(_context, uriParts.pathname);
|
|
344
|
+
logger.groupCollapsed(groupName, "color: ".concat(error ? 'red' : 'black', "; font-weight: bold;"), 'color: gray; font-weight: lighter;');
|
|
341
345
|
logger.log('%caction', 'color: cadetblue; font-weight: bold;', action);
|
|
342
|
-
logger.log('%crequest',
|
|
346
|
+
logger.log('%crequest', "color: cornflowerblue; font-weight: bold;", _objectSpread$2({
|
|
343
347
|
headers: request.headers,
|
|
344
348
|
uri: request.uri,
|
|
345
349
|
params: uriParts.search
|
|
346
350
|
}, isPostAction(action) ? {
|
|
347
351
|
body: action.payload.payload
|
|
348
352
|
} : {}));
|
|
349
|
-
if (response) logger.log('%cresponse',
|
|
350
|
-
if (error) logger.log('%cerror',
|
|
353
|
+
if (response) logger.log('%cresponse', "color: green; font-weight: bold;", response);
|
|
354
|
+
if (error) logger.log('%cerror', "color: red; font-weight: bold;", error);
|
|
351
355
|
logger.groupEnd();
|
|
352
356
|
};
|
|
353
357
|
const mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
@@ -359,9 +363,10 @@ const getMcOriginTld = host => {
|
|
|
359
363
|
return host.replace(mcHostnameRegex, '$3');
|
|
360
364
|
};
|
|
361
365
|
const getMcApiUrlFromOrigin = actualWindow => {
|
|
366
|
+
var _context2;
|
|
362
367
|
const url = new _URL__default["default"](actualWindow.origin);
|
|
363
368
|
const originTld = getMcOriginTld(url.host);
|
|
364
|
-
return
|
|
369
|
+
return _concatInstanceProperty__default["default"](_context2 = "".concat(url.protocol, "//mc-api.")).call(_context2, originTld);
|
|
365
370
|
};
|
|
366
371
|
const parseAsBoolean = value => value === true || value === 'true';
|
|
367
372
|
function getMcApiUrl() {
|
|
@@ -426,17 +431,19 @@ const createClient = _ref2 => {
|
|
|
426
431
|
};
|
|
427
432
|
|
|
428
433
|
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
429
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
434
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(t), !0)).call(_context4, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(t))).call(_context5, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
430
435
|
const isSdkActionForUri = actionPayload => actionPayload.uri !== undefined;
|
|
431
436
|
|
|
432
437
|
// https://github.com/commercetools/nodejs/blob/master/packages/api-request-builder/src/default-services.js#L200:L200
|
|
433
438
|
const ORDER_EDIT_SERVICE = 'orderEdits';
|
|
434
439
|
const actionToUri = (action, projectKey) => {
|
|
440
|
+
var _action$payload$optio;
|
|
435
441
|
if (isSdkActionForUri(action.payload)) return action.payload.uri;
|
|
436
442
|
|
|
437
443
|
// Validate that `projectKey` exists
|
|
438
444
|
if (!projectKey) {
|
|
439
|
-
|
|
445
|
+
var _context;
|
|
446
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "Expected projectKey to be defined for action service \"".concat(action.payload.service, "\" (method \"")).call(_context, action.payload.method, "\")"));
|
|
440
447
|
}
|
|
441
448
|
const requestBuilder = apiRequestBuilder.createRequestBuilder({
|
|
442
449
|
projectKey
|
|
@@ -450,7 +457,7 @@ const actionToUri = (action, projectKey) => {
|
|
|
450
457
|
// given `service=orderEdits` and given `applyOrderEditTo`, we build an apply endpoint
|
|
451
458
|
// given `service=orderEdits` and no `applyOrderEditTo`, we build an update endpoint
|
|
452
459
|
// https://docs.commercetools.com/api/projects/order-edits
|
|
453
|
-
applyOrderEdit: action.payload.service === ORDER_EDIT_SERVICE && typeof action.payload.options
|
|
460
|
+
applyOrderEdit: action.payload.service === ORDER_EDIT_SERVICE && typeof ((_action$payload$optio = action.payload.options) === null || _action$payload$optio === void 0 ? void 0 : _action$payload$optio.applyOrderEditTo) === 'string',
|
|
454
461
|
// at this stage, the `projectKey` should be available already.
|
|
455
462
|
withProjectKey: true
|
|
456
463
|
});
|
|
@@ -469,12 +476,12 @@ function createSdkMiddleware(_ref) {
|
|
|
469
476
|
const middleware = _ref2 => {
|
|
470
477
|
let dispatch = _ref2.dispatch;
|
|
471
478
|
return next => action => {
|
|
472
|
-
var
|
|
479
|
+
var _context2, _context3;
|
|
473
480
|
if (!isSdkAction(action)) {
|
|
474
481
|
return next(action);
|
|
475
482
|
}
|
|
476
483
|
const projectKey = getProjectKey();
|
|
477
|
-
const uri = _filterInstanceProperty__default["default"](
|
|
484
|
+
const uri = _filterInstanceProperty__default["default"](_context2 = [action.payload.mcApiProxyTarget && "/proxy/".concat(action.payload.mcApiProxyTarget), actionToUri(action, projectKey)]).call(_context2, Boolean).join('');
|
|
478
485
|
|
|
479
486
|
// This `requestName` is never really used.
|
|
480
487
|
//
|
|
@@ -487,7 +494,7 @@ function createSdkMiddleware(_ref) {
|
|
|
487
494
|
// loading: ['PRODUCTS_FETCHED', 'sdk.fetch(/product-projection-search)']
|
|
488
495
|
// than to debug
|
|
489
496
|
// loading: 2
|
|
490
|
-
const requestName =
|
|
497
|
+
const requestName = _concatInstanceProperty__default["default"](_context3 = "sdk.".concat(action.payload.method.toLowerCase(), "(")).call(_context3, uri, ")");
|
|
491
498
|
|
|
492
499
|
// NOTE here the middleware is aware of the application
|
|
493
500
|
// Instead we should probably convert to a middleware factory
|
|
@@ -513,7 +520,7 @@ function createSdkMiddleware(_ref) {
|
|
|
513
520
|
'X-Force-Token': 'true'
|
|
514
521
|
} : {}), projectKey && {
|
|
515
522
|
'X-Project-Key': projectKey
|
|
516
|
-
}), additionalHeaders
|
|
523
|
+
}), additionalHeaders !== null && additionalHeaders !== void 0 ? additionalHeaders : {});
|
|
517
524
|
const body = action.payload.method === 'POST' ? action.payload.payload : undefined;
|
|
518
525
|
return client.execute({
|
|
519
526
|
uri,
|
|
@@ -24,6 +24,7 @@ var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
|
24
24
|
var react = require('react');
|
|
25
25
|
var fastEquals = require('fast-equals');
|
|
26
26
|
var reactRedux = require('react-redux');
|
|
27
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
27
28
|
var apiRequestBuilder = require('@commercetools/api-request-builder');
|
|
28
29
|
var constants = require('@commercetools-frontend/constants');
|
|
29
30
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
@@ -49,6 +50,7 @@ var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInsta
|
|
|
49
50
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
50
51
|
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
51
52
|
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
53
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
52
54
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
53
55
|
var _globalThis__default = /*#__PURE__*/_interopDefault(_globalThis);
|
|
54
56
|
var createHttpUserAgent__default = /*#__PURE__*/_interopDefault(createHttpUserAgent);
|
|
@@ -92,8 +94,8 @@ function post(payload) {
|
|
|
92
94
|
};
|
|
93
95
|
}
|
|
94
96
|
const enhancePayloadForForwardToProxy = payload => {
|
|
95
|
-
var _context;
|
|
96
|
-
const headers = payload.headers
|
|
97
|
+
var _payload$headers, _context;
|
|
98
|
+
const headers = (_payload$headers = payload.headers) !== null && _payload$headers !== void 0 ? _payload$headers : {};
|
|
97
99
|
const exchangeTokenClaims = [];
|
|
98
100
|
if (payload.includeUserPermissions) {
|
|
99
101
|
exchangeTokenClaims.push('permissions');
|
|
@@ -107,7 +109,7 @@ const enhancePayloadForForwardToProxy = payload => {
|
|
|
107
109
|
headerValue = _ref2[1];
|
|
108
110
|
return _objectSpread$2(_objectSpread$2({}, customForwardHeaders), {}, {
|
|
109
111
|
// Prefix headers so that the MC API can allow and forward them.
|
|
110
|
-
[
|
|
112
|
+
["x-forward-header-".concat(headerName)]: headerValue
|
|
111
113
|
});
|
|
112
114
|
}, {})), {}, {
|
|
113
115
|
'Accept-version': 'v2',
|
|
@@ -198,7 +200,7 @@ let SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
198
200
|
onSuccess = _ref.onSuccess,
|
|
199
201
|
onError = _ref.onError;
|
|
200
202
|
_this.changeRequestsInFlight(1);
|
|
201
|
-
return dispatch(actionCreator(...(actionCreatorArgs
|
|
203
|
+
return dispatch(actionCreator(...(actionCreatorArgs !== null && actionCreatorArgs !== void 0 ? actionCreatorArgs : defaultProps.actionCreatorArgs))).then(result => {
|
|
202
204
|
_this.changeRequestsInFlight(-1);
|
|
203
205
|
if (_this.isComponentMounted) _this.setState({
|
|
204
206
|
error: undefined,
|
|
@@ -250,8 +252,9 @@ let SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
250
252
|
}, {
|
|
251
253
|
key: "componentDidUpdate",
|
|
252
254
|
value: function componentDidUpdate(prevProps) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
+
var _this$props$shouldRef, _prevProps$actionCrea, _this$props$actionCre;
|
|
256
|
+
const shouldRefetch = (_this$props$shouldRef = this.props.shouldRefetch) !== null && _this$props$shouldRef !== void 0 ? _this$props$shouldRef : defaultProps.shouldRefetch;
|
|
257
|
+
if (shouldRefetch((_prevProps$actionCrea = prevProps.actionCreatorArgs) !== null && _prevProps$actionCrea !== void 0 ? _prevProps$actionCrea : defaultProps.actionCreatorArgs, (_this$props$actionCre = this.props.actionCreatorArgs) !== null && _this$props$actionCre !== void 0 ? _this$props$actionCre : defaultProps.actionCreatorArgs)) {
|
|
255
258
|
this.fetch({
|
|
256
259
|
dispatch: this.props.dispatch,
|
|
257
260
|
actionCreator: this.props.actionCreator,
|
|
@@ -288,7 +291,7 @@ const mapDispatchToProps = dispatch => ({
|
|
|
288
291
|
var SdkGet$1 = reactRedux.connect(null, mapDispatchToProps)(SdkGet);
|
|
289
292
|
|
|
290
293
|
// NOTE: This string will be replaced on build time with the package version.
|
|
291
|
-
var version = "24.
|
|
294
|
+
var version = "24.13.0";
|
|
292
295
|
|
|
293
296
|
const mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
294
297
|
const mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
|
|
@@ -299,9 +302,10 @@ const getMcOriginTld = host => {
|
|
|
299
302
|
return host.replace(mcHostnameRegex, '$3');
|
|
300
303
|
};
|
|
301
304
|
const getMcApiUrlFromOrigin = actualWindow => {
|
|
305
|
+
var _context2;
|
|
302
306
|
const url = new _URL__default["default"](actualWindow.origin);
|
|
303
307
|
const originTld = getMcOriginTld(url.host);
|
|
304
|
-
return
|
|
308
|
+
return _concatInstanceProperty__default["default"](_context2 = "".concat(url.protocol, "//mc-api.")).call(_context2, originTld);
|
|
305
309
|
};
|
|
306
310
|
const parseAsBoolean = value => value === true || value === 'true';
|
|
307
311
|
function getMcApiUrl() {
|
|
@@ -366,17 +370,19 @@ const createClient = _ref2 => {
|
|
|
366
370
|
};
|
|
367
371
|
|
|
368
372
|
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
369
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
373
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys(Object(t), !0)).call(_context4, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys(Object(t))).call(_context5, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
370
374
|
const isSdkActionForUri = actionPayload => actionPayload.uri !== undefined;
|
|
371
375
|
|
|
372
376
|
// https://github.com/commercetools/nodejs/blob/master/packages/api-request-builder/src/default-services.js#L200:L200
|
|
373
377
|
const ORDER_EDIT_SERVICE = 'orderEdits';
|
|
374
378
|
const actionToUri = (action, projectKey) => {
|
|
379
|
+
var _action$payload$optio;
|
|
375
380
|
if (isSdkActionForUri(action.payload)) return action.payload.uri;
|
|
376
381
|
|
|
377
382
|
// Validate that `projectKey` exists
|
|
378
383
|
if (!projectKey) {
|
|
379
|
-
|
|
384
|
+
var _context;
|
|
385
|
+
throw new Error(_concatInstanceProperty__default["default"](_context = "Expected projectKey to be defined for action service \"".concat(action.payload.service, "\" (method \"")).call(_context, action.payload.method, "\")"));
|
|
380
386
|
}
|
|
381
387
|
const requestBuilder = apiRequestBuilder.createRequestBuilder({
|
|
382
388
|
projectKey
|
|
@@ -390,7 +396,7 @@ const actionToUri = (action, projectKey) => {
|
|
|
390
396
|
// given `service=orderEdits` and given `applyOrderEditTo`, we build an apply endpoint
|
|
391
397
|
// given `service=orderEdits` and no `applyOrderEditTo`, we build an update endpoint
|
|
392
398
|
// https://docs.commercetools.com/api/projects/order-edits
|
|
393
|
-
applyOrderEdit: action.payload.service === ORDER_EDIT_SERVICE && typeof action.payload.options
|
|
399
|
+
applyOrderEdit: action.payload.service === ORDER_EDIT_SERVICE && typeof ((_action$payload$optio = action.payload.options) === null || _action$payload$optio === void 0 ? void 0 : _action$payload$optio.applyOrderEditTo) === 'string',
|
|
394
400
|
// at this stage, the `projectKey` should be available already.
|
|
395
401
|
withProjectKey: true
|
|
396
402
|
});
|
|
@@ -409,12 +415,12 @@ function createSdkMiddleware(_ref) {
|
|
|
409
415
|
const middleware = _ref2 => {
|
|
410
416
|
let dispatch = _ref2.dispatch;
|
|
411
417
|
return next => action => {
|
|
412
|
-
var
|
|
418
|
+
var _context2, _context3;
|
|
413
419
|
if (!isSdkAction(action)) {
|
|
414
420
|
return next(action);
|
|
415
421
|
}
|
|
416
422
|
const projectKey = getProjectKey();
|
|
417
|
-
const uri = _filterInstanceProperty__default["default"](
|
|
423
|
+
const uri = _filterInstanceProperty__default["default"](_context2 = [action.payload.mcApiProxyTarget && "/proxy/".concat(action.payload.mcApiProxyTarget), actionToUri(action, projectKey)]).call(_context2, Boolean).join('');
|
|
418
424
|
|
|
419
425
|
// This `requestName` is never really used.
|
|
420
426
|
//
|
|
@@ -427,7 +433,7 @@ function createSdkMiddleware(_ref) {
|
|
|
427
433
|
// loading: ['PRODUCTS_FETCHED', 'sdk.fetch(/product-projection-search)']
|
|
428
434
|
// than to debug
|
|
429
435
|
// loading: 2
|
|
430
|
-
const requestName =
|
|
436
|
+
const requestName = _concatInstanceProperty__default["default"](_context3 = "sdk.".concat(action.payload.method.toLowerCase(), "(")).call(_context3, uri, ")");
|
|
431
437
|
|
|
432
438
|
// NOTE here the middleware is aware of the application
|
|
433
439
|
// Instead we should probably convert to a middleware factory
|
|
@@ -453,7 +459,7 @@ function createSdkMiddleware(_ref) {
|
|
|
453
459
|
'X-Force-Token': 'true'
|
|
454
460
|
} : {}), projectKey && {
|
|
455
461
|
'X-Project-Key': projectKey
|
|
456
|
-
}), additionalHeaders
|
|
462
|
+
}), additionalHeaders !== null && additionalHeaders !== void 0 ? additionalHeaders : {});
|
|
457
463
|
const body = action.payload.method === 'POST' ? action.payload.payload : undefined;
|
|
458
464
|
return client.execute({
|
|
459
465
|
uri,
|
|
@@ -20,6 +20,7 @@ import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
|
20
20
|
import { Component } from 'react';
|
|
21
21
|
import { deepEqual } from 'fast-equals';
|
|
22
22
|
import { connect, useDispatch } from 'react-redux';
|
|
23
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
23
24
|
import { createRequestBuilder } from '@commercetools/api-request-builder';
|
|
24
25
|
import { SHOW_LOADING, STATUS_CODES, HIDE_LOADING } from '@commercetools-frontend/constants';
|
|
25
26
|
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
|
@@ -70,8 +71,8 @@ function post(payload) {
|
|
|
70
71
|
};
|
|
71
72
|
}
|
|
72
73
|
const enhancePayloadForForwardToProxy = payload => {
|
|
73
|
-
var _context;
|
|
74
|
-
const headers = payload.headers
|
|
74
|
+
var _payload$headers, _context;
|
|
75
|
+
const headers = (_payload$headers = payload.headers) !== null && _payload$headers !== void 0 ? _payload$headers : {};
|
|
75
76
|
const exchangeTokenClaims = [];
|
|
76
77
|
if (payload.includeUserPermissions) {
|
|
77
78
|
exchangeTokenClaims.push('permissions');
|
|
@@ -85,7 +86,7 @@ const enhancePayloadForForwardToProxy = payload => {
|
|
|
85
86
|
headerValue = _ref2[1];
|
|
86
87
|
return _objectSpread$3(_objectSpread$3({}, customForwardHeaders), {}, {
|
|
87
88
|
// Prefix headers so that the MC API can allow and forward them.
|
|
88
|
-
[
|
|
89
|
+
["x-forward-header-".concat(headerName)]: headerValue
|
|
89
90
|
});
|
|
90
91
|
}, {})), {}, {
|
|
91
92
|
'Accept-version': 'v2',
|
|
@@ -176,7 +177,7 @@ let SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
176
177
|
onSuccess = _ref.onSuccess,
|
|
177
178
|
onError = _ref.onError;
|
|
178
179
|
_this.changeRequestsInFlight(1);
|
|
179
|
-
return dispatch(actionCreator(...(actionCreatorArgs
|
|
180
|
+
return dispatch(actionCreator(...(actionCreatorArgs !== null && actionCreatorArgs !== void 0 ? actionCreatorArgs : defaultProps.actionCreatorArgs))).then(result => {
|
|
180
181
|
_this.changeRequestsInFlight(-1);
|
|
181
182
|
if (_this.isComponentMounted) _this.setState({
|
|
182
183
|
error: undefined,
|
|
@@ -228,8 +229,9 @@ let SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
228
229
|
}, {
|
|
229
230
|
key: "componentDidUpdate",
|
|
230
231
|
value: function componentDidUpdate(prevProps) {
|
|
231
|
-
|
|
232
|
-
|
|
232
|
+
var _this$props$shouldRef, _prevProps$actionCrea, _this$props$actionCre;
|
|
233
|
+
const shouldRefetch = (_this$props$shouldRef = this.props.shouldRefetch) !== null && _this$props$shouldRef !== void 0 ? _this$props$shouldRef : defaultProps.shouldRefetch;
|
|
234
|
+
if (shouldRefetch((_prevProps$actionCrea = prevProps.actionCreatorArgs) !== null && _prevProps$actionCrea !== void 0 ? _prevProps$actionCrea : defaultProps.actionCreatorArgs, (_this$props$actionCre = this.props.actionCreatorArgs) !== null && _this$props$actionCre !== void 0 ? _this$props$actionCre : defaultProps.actionCreatorArgs)) {
|
|
233
235
|
this.fetch({
|
|
234
236
|
dispatch: this.props.dispatch,
|
|
235
237
|
actionCreator: this.props.actionCreator,
|
|
@@ -266,7 +268,7 @@ const mapDispatchToProps = dispatch => ({
|
|
|
266
268
|
var SdkGet$1 = connect(null, mapDispatchToProps)(SdkGet);
|
|
267
269
|
|
|
268
270
|
// NOTE: This string will be replaced on build time with the package version.
|
|
269
|
-
var version = "24.
|
|
271
|
+
var version = "24.13.0";
|
|
270
272
|
|
|
271
273
|
/* eslint-disable no-console */
|
|
272
274
|
|
|
@@ -297,7 +299,7 @@ const logger = {
|
|
|
297
299
|
};
|
|
298
300
|
|
|
299
301
|
function ownKeys$2(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
300
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
302
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context3 = ownKeys$2(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context4 = ownKeys$2(Object(t))).call(_context4, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
301
303
|
const parseUri = uri => {
|
|
302
304
|
const parser = document.createElement('a');
|
|
303
305
|
parser.href = uri;
|
|
@@ -308,24 +310,25 @@ const parseUri = uri => {
|
|
|
308
310
|
};
|
|
309
311
|
const isPostAction = action => action.payload.method === 'POST';
|
|
310
312
|
const logRequest = _ref => {
|
|
313
|
+
var _context;
|
|
311
314
|
let method = _ref.method,
|
|
312
315
|
request = _ref.request,
|
|
313
316
|
response = _ref.response,
|
|
314
317
|
error = _ref.error,
|
|
315
318
|
action = _ref.action;
|
|
316
319
|
const uriParts = parseUri(request.uri);
|
|
317
|
-
const groupName =
|
|
318
|
-
logger.groupCollapsed(groupName,
|
|
320
|
+
const groupName = _concatInstanceProperty(_context = "%c".concat(method, " %c")).call(_context, uriParts.pathname);
|
|
321
|
+
logger.groupCollapsed(groupName, "color: ".concat(error ? 'red' : 'black', "; font-weight: bold;"), 'color: gray; font-weight: lighter;');
|
|
319
322
|
logger.log('%caction', 'color: cadetblue; font-weight: bold;', action);
|
|
320
|
-
logger.log('%crequest',
|
|
323
|
+
logger.log('%crequest', "color: cornflowerblue; font-weight: bold;", _objectSpread$2({
|
|
321
324
|
headers: request.headers,
|
|
322
325
|
uri: request.uri,
|
|
323
326
|
params: uriParts.search
|
|
324
327
|
}, isPostAction(action) ? {
|
|
325
328
|
body: action.payload.payload
|
|
326
329
|
} : {}));
|
|
327
|
-
if (response) logger.log('%cresponse',
|
|
328
|
-
if (error) logger.log('%cerror',
|
|
330
|
+
if (response) logger.log('%cresponse', "color: green; font-weight: bold;", response);
|
|
331
|
+
if (error) logger.log('%cerror', "color: red; font-weight: bold;", error);
|
|
329
332
|
logger.groupEnd();
|
|
330
333
|
};
|
|
331
334
|
const mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
@@ -337,9 +340,10 @@ const getMcOriginTld = host => {
|
|
|
337
340
|
return host.replace(mcHostnameRegex, '$3');
|
|
338
341
|
};
|
|
339
342
|
const getMcApiUrlFromOrigin = actualWindow => {
|
|
343
|
+
var _context2;
|
|
340
344
|
const url = new _URL(actualWindow.origin);
|
|
341
345
|
const originTld = getMcOriginTld(url.host);
|
|
342
|
-
return
|
|
346
|
+
return _concatInstanceProperty(_context2 = "".concat(url.protocol, "//mc-api.")).call(_context2, originTld);
|
|
343
347
|
};
|
|
344
348
|
const parseAsBoolean = value => value === true || value === 'true';
|
|
345
349
|
function getMcApiUrl() {
|
|
@@ -404,17 +408,19 @@ const createClient = _ref2 => {
|
|
|
404
408
|
};
|
|
405
409
|
|
|
406
410
|
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
407
|
-
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
411
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context4 = ownKeys(Object(t), !0)).call(_context4, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context5 = ownKeys(Object(t))).call(_context5, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
408
412
|
const isSdkActionForUri = actionPayload => actionPayload.uri !== undefined;
|
|
409
413
|
|
|
410
414
|
// https://github.com/commercetools/nodejs/blob/master/packages/api-request-builder/src/default-services.js#L200:L200
|
|
411
415
|
const ORDER_EDIT_SERVICE = 'orderEdits';
|
|
412
416
|
const actionToUri = (action, projectKey) => {
|
|
417
|
+
var _action$payload$optio;
|
|
413
418
|
if (isSdkActionForUri(action.payload)) return action.payload.uri;
|
|
414
419
|
|
|
415
420
|
// Validate that `projectKey` exists
|
|
416
421
|
if (!projectKey) {
|
|
417
|
-
|
|
422
|
+
var _context;
|
|
423
|
+
throw new Error(_concatInstanceProperty(_context = "Expected projectKey to be defined for action service \"".concat(action.payload.service, "\" (method \"")).call(_context, action.payload.method, "\")"));
|
|
418
424
|
}
|
|
419
425
|
const requestBuilder = createRequestBuilder({
|
|
420
426
|
projectKey
|
|
@@ -428,7 +434,7 @@ const actionToUri = (action, projectKey) => {
|
|
|
428
434
|
// given `service=orderEdits` and given `applyOrderEditTo`, we build an apply endpoint
|
|
429
435
|
// given `service=orderEdits` and no `applyOrderEditTo`, we build an update endpoint
|
|
430
436
|
// https://docs.commercetools.com/api/projects/order-edits
|
|
431
|
-
applyOrderEdit: action.payload.service === ORDER_EDIT_SERVICE && typeof action.payload.options
|
|
437
|
+
applyOrderEdit: action.payload.service === ORDER_EDIT_SERVICE && typeof ((_action$payload$optio = action.payload.options) === null || _action$payload$optio === void 0 ? void 0 : _action$payload$optio.applyOrderEditTo) === 'string',
|
|
432
438
|
// at this stage, the `projectKey` should be available already.
|
|
433
439
|
withProjectKey: true
|
|
434
440
|
});
|
|
@@ -447,12 +453,12 @@ function createSdkMiddleware(_ref) {
|
|
|
447
453
|
const middleware = _ref2 => {
|
|
448
454
|
let dispatch = _ref2.dispatch;
|
|
449
455
|
return next => action => {
|
|
450
|
-
var
|
|
456
|
+
var _context2, _context3;
|
|
451
457
|
if (!isSdkAction(action)) {
|
|
452
458
|
return next(action);
|
|
453
459
|
}
|
|
454
460
|
const projectKey = getProjectKey();
|
|
455
|
-
const uri = _filterInstanceProperty(
|
|
461
|
+
const uri = _filterInstanceProperty(_context2 = [action.payload.mcApiProxyTarget && "/proxy/".concat(action.payload.mcApiProxyTarget), actionToUri(action, projectKey)]).call(_context2, Boolean).join('');
|
|
456
462
|
|
|
457
463
|
// This `requestName` is never really used.
|
|
458
464
|
//
|
|
@@ -465,7 +471,7 @@ function createSdkMiddleware(_ref) {
|
|
|
465
471
|
// loading: ['PRODUCTS_FETCHED', 'sdk.fetch(/product-projection-search)']
|
|
466
472
|
// than to debug
|
|
467
473
|
// loading: 2
|
|
468
|
-
const requestName =
|
|
474
|
+
const requestName = _concatInstanceProperty(_context3 = "sdk.".concat(action.payload.method.toLowerCase(), "(")).call(_context3, uri, ")");
|
|
469
475
|
|
|
470
476
|
// NOTE here the middleware is aware of the application
|
|
471
477
|
// Instead we should probably convert to a middleware factory
|
|
@@ -491,7 +497,7 @@ function createSdkMiddleware(_ref) {
|
|
|
491
497
|
'X-Force-Token': 'true'
|
|
492
498
|
} : {}), projectKey && {
|
|
493
499
|
'X-Project-Key': projectKey
|
|
494
|
-
}), additionalHeaders
|
|
500
|
+
}), additionalHeaders !== null && additionalHeaders !== void 0 ? additionalHeaders : {});
|
|
495
501
|
const body = action.payload.method === 'POST' ? action.payload.payload : undefined;
|
|
496
502
|
return client.execute({
|
|
497
503
|
uri,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/sdk",
|
|
3
|
-
"version": "24.
|
|
3
|
+
"version": "24.13.0",
|
|
4
4
|
"description": "Tools for declarative fetching",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@babel/runtime": "^7.22.15",
|
|
39
39
|
"@babel/runtime-corejs3": "^7.22.15",
|
|
40
|
-
"@commercetools-frontend/constants": "24.
|
|
40
|
+
"@commercetools-frontend/constants": "24.13.0",
|
|
41
41
|
"@commercetools/api-request-builder": "6.0.0",
|
|
42
42
|
"@commercetools/http-user-agent": "3.0.0",
|
|
43
43
|
"@commercetools/sdk-client": "3.0.0",
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
6
6
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
7
7
|
var _findIndexInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find-index');
|
|
8
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
8
9
|
var _spliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/splice');
|
|
9
10
|
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
10
11
|
var fastEquals = require('fast-equals');
|
|
@@ -15,6 +16,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
15
16
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
16
17
|
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
17
18
|
var _findIndexInstanceProperty__default = /*#__PURE__*/_interopDefault(_findIndexInstanceProperty);
|
|
19
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
18
20
|
var _spliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_spliceInstanceProperty);
|
|
19
21
|
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
20
22
|
|
|
@@ -27,7 +29,7 @@ var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
|
27
29
|
|
|
28
30
|
const serialize = data => {
|
|
29
31
|
const undefinedPlaceholder = uuid.v4();
|
|
30
|
-
const placeholderRegexp = new RegExp(
|
|
32
|
+
const placeholderRegexp = new RegExp("\"".concat(undefinedPlaceholder, "\""), 'g');
|
|
31
33
|
const mapUndefinedValues = (_k, v) => v === undefined ? undefinedPlaceholder : v;
|
|
32
34
|
const withPlaceholders = _JSON$stringify__default["default"](data, mapUndefinedValues, 2);
|
|
33
35
|
return withPlaceholders.replace(placeholderRegexp, 'undefined');
|
|
@@ -47,11 +49,12 @@ const createTestMiddleware = mocks => {
|
|
|
47
49
|
// should never be mutated.
|
|
48
50
|
const mocksStack = [...mocks];
|
|
49
51
|
return () => next => action => {
|
|
52
|
+
var _context;
|
|
50
53
|
if (!isSdkAction(action)) {
|
|
51
54
|
return next(action);
|
|
52
55
|
}
|
|
53
56
|
const index = _findIndexInstanceProperty__default["default"](mocksStack).call(mocksStack, item => fastEquals.deepEqual(item.action, action));
|
|
54
|
-
if (index === -1) throw new Error(
|
|
57
|
+
if (index === -1) throw new Error(_concatInstanceProperty__default["default"](_context = "Could not find any more mocks for action ".concat(serialize(action), " in ")).call(_context, serialize(mocks)));
|
|
55
58
|
const mock = mocksStack[index];
|
|
56
59
|
|
|
57
60
|
// Mocks should only be used once, so we remove it from the stack.
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
6
6
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
7
7
|
var _findIndexInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find-index');
|
|
8
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
8
9
|
var _spliceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/splice');
|
|
9
10
|
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
10
11
|
var fastEquals = require('fast-equals');
|
|
@@ -15,6 +16,7 @@ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e };
|
|
|
15
16
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
16
17
|
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
17
18
|
var _findIndexInstanceProperty__default = /*#__PURE__*/_interopDefault(_findIndexInstanceProperty);
|
|
19
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
18
20
|
var _spliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_spliceInstanceProperty);
|
|
19
21
|
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
20
22
|
|
|
@@ -27,7 +29,7 @@ var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
|
27
29
|
|
|
28
30
|
const serialize = data => {
|
|
29
31
|
const undefinedPlaceholder = uuid.v4();
|
|
30
|
-
const placeholderRegexp = new RegExp(
|
|
32
|
+
const placeholderRegexp = new RegExp("\"".concat(undefinedPlaceholder, "\""), 'g');
|
|
31
33
|
const mapUndefinedValues = (_k, v) => v === undefined ? undefinedPlaceholder : v;
|
|
32
34
|
const withPlaceholders = _JSON$stringify__default["default"](data, mapUndefinedValues, 2);
|
|
33
35
|
return withPlaceholders.replace(placeholderRegexp, 'undefined');
|
|
@@ -47,11 +49,12 @@ const createTestMiddleware = mocks => {
|
|
|
47
49
|
// should never be mutated.
|
|
48
50
|
const mocksStack = [...mocks];
|
|
49
51
|
return () => next => action => {
|
|
52
|
+
var _context;
|
|
50
53
|
if (!isSdkAction(action)) {
|
|
51
54
|
return next(action);
|
|
52
55
|
}
|
|
53
56
|
const index = _findIndexInstanceProperty__default["default"](mocksStack).call(mocksStack, item => fastEquals.deepEqual(item.action, action));
|
|
54
|
-
if (index === -1) throw new Error(
|
|
57
|
+
if (index === -1) throw new Error(_concatInstanceProperty__default["default"](_context = "Could not find any more mocks for action ".concat(serialize(action), " in ")).call(_context, serialize(mocks)));
|
|
55
58
|
const mock = mocksStack[index];
|
|
56
59
|
|
|
57
60
|
// Mocks should only be used once, so we remove it from the stack.
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
2
2
|
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
3
3
|
import _findIndexInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find-index';
|
|
4
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
4
5
|
import _spliceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/splice';
|
|
5
6
|
import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
|
|
6
7
|
import { deepEqual } from 'fast-equals';
|
|
@@ -15,7 +16,7 @@ import { v4 } from 'uuid';
|
|
|
15
16
|
|
|
16
17
|
const serialize = data => {
|
|
17
18
|
const undefinedPlaceholder = v4();
|
|
18
|
-
const placeholderRegexp = new RegExp(
|
|
19
|
+
const placeholderRegexp = new RegExp("\"".concat(undefinedPlaceholder, "\""), 'g');
|
|
19
20
|
const mapUndefinedValues = (_k, v) => v === undefined ? undefinedPlaceholder : v;
|
|
20
21
|
const withPlaceholders = _JSON$stringify(data, mapUndefinedValues, 2);
|
|
21
22
|
return withPlaceholders.replace(placeholderRegexp, 'undefined');
|
|
@@ -35,11 +36,12 @@ const createTestMiddleware = mocks => {
|
|
|
35
36
|
// should never be mutated.
|
|
36
37
|
const mocksStack = [...mocks];
|
|
37
38
|
return () => next => action => {
|
|
39
|
+
var _context;
|
|
38
40
|
if (!isSdkAction(action)) {
|
|
39
41
|
return next(action);
|
|
40
42
|
}
|
|
41
43
|
const index = _findIndexInstanceProperty(mocksStack).call(mocksStack, item => deepEqual(item.action, action));
|
|
42
|
-
if (index === -1) throw new Error(
|
|
44
|
+
if (index === -1) throw new Error(_concatInstanceProperty(_context = "Could not find any more mocks for action ".concat(serialize(action), " in ")).call(_context, serialize(mocks)));
|
|
43
45
|
const mock = mocksStack[index];
|
|
44
46
|
|
|
45
47
|
// Mocks should only be used once, so we remove it from the stack.
|