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