@commercetools-frontend/sdk 21.23.10 → 21.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commercetools-frontend-sdk.cjs.dev.js +324 -356
- package/dist/commercetools-frontend-sdk.cjs.prod.js +284 -302
- package/dist/commercetools-frontend-sdk.esm.js +321 -353
- package/dist/declarations/src/components/sdk-get/sdk-get.d.ts +1 -1
- package/package.json +2 -2
- package/test-utils/dist/commercetools-frontend-sdk-test-utils.cjs.dev.js +20 -34
- package/test-utils/dist/commercetools-frontend-sdk-test-utils.cjs.prod.js +20 -34
- package/test-utils/dist/commercetools-frontend-sdk-test-utils.esm.js +20 -34
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="commercetools__sdk-client" />
|
|
2
|
+
import { Component } from 'react';
|
|
2
3
|
import type { SuccessResult, HttpErrorType } from '@commercetools/sdk-client';
|
|
3
4
|
import type { TSdkAction } from '../../types';
|
|
4
|
-
import { Component } from 'react';
|
|
5
5
|
type TSdkError = Error | HttpErrorType;
|
|
6
6
|
type TActionCreatorArgs = unknown[];
|
|
7
7
|
type State = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/sdk",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.24.1",
|
|
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.20.13",
|
|
25
25
|
"@babel/runtime-corejs3": "^7.20.13",
|
|
26
|
-
"@commercetools-frontend/constants": "21.
|
|
26
|
+
"@commercetools-frontend/constants": "21.24.1",
|
|
27
27
|
"@commercetools/api-request-builder": "6.0.0",
|
|
28
28
|
"@commercetools/http-user-agent": "3.0.0",
|
|
29
29
|
"@commercetools/sdk-client": "3.0.0",
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
6
5
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
7
6
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
8
7
|
var _findIndexInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find-index');
|
|
@@ -21,61 +20,48 @@ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInsta
|
|
|
21
20
|
var _spliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_spliceInstanceProperty);
|
|
22
21
|
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const serialize = data => {
|
|
24
|
+
const undefinedPlaceholder = uuid.v4();
|
|
25
|
+
const placeholderRegexp = new RegExp("\"".concat(undefinedPlaceholder, "\""), 'g');
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
return v === undefined ? undefinedPlaceholder : v;
|
|
30
|
-
};
|
|
27
|
+
const mapUndefinedValues = (_k, v) => v === undefined ? undefinedPlaceholder : v;
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
const withPlaceholders = _JSON$stringify__default["default"](data, mapUndefinedValues, 2);
|
|
33
30
|
|
|
34
31
|
return withPlaceholders.replace(placeholderRegexp, 'undefined');
|
|
35
32
|
};
|
|
36
33
|
|
|
37
|
-
|
|
34
|
+
const throwIfNoMocksArePassed = mocks => {
|
|
38
35
|
if (!mocks || !_Array$isArray__default["default"](mocks) || mocks.length === 0) {
|
|
39
36
|
throw new Error('Missing or invalid argument for `mocks`. Expected an array of mocked actions.');
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
return action.type === 'SDK';
|
|
45
|
-
};
|
|
40
|
+
const isSdkAction = action => action.type === 'SDK';
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
return mock.response !== undefined;
|
|
49
|
-
};
|
|
42
|
+
const isSdkMockSuccess = mock => mock.response !== undefined;
|
|
50
43
|
|
|
51
|
-
|
|
44
|
+
const createTestMiddleware = mocks => {
|
|
52
45
|
throwIfNoMocksArePassed(mocks); // We clone the mocks so we can keep the user-provided mocks around for
|
|
53
46
|
// the debugging message. The mocksStack gets mutated, while mocks
|
|
54
47
|
// should never be mutated.
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return function (next) {
|
|
60
|
-
return function (action) {
|
|
61
|
-
var _context;
|
|
49
|
+
const mocksStack = [...mocks];
|
|
50
|
+
return () => next => action => {
|
|
51
|
+
var _context;
|
|
62
52
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
if (!isSdkAction(action)) {
|
|
54
|
+
return next(action);
|
|
55
|
+
}
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
return fastEquals.deepEqual(item.action, action);
|
|
69
|
-
});
|
|
57
|
+
const index = _findIndexInstanceProperty__default["default"](mocksStack).call(mocksStack, item => fastEquals.deepEqual(item.action, action));
|
|
70
58
|
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
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)));
|
|
60
|
+
const mock = mocksStack[index]; // Mocks should only be used once, so we remove it from the stack.
|
|
73
61
|
|
|
74
|
-
|
|
62
|
+
_spliceInstanceProperty__default["default"](mocksStack).call(mocksStack, index, 1);
|
|
75
63
|
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
};
|
|
64
|
+
return isSdkMockSuccess(mock) ? _Promise__default["default"].resolve(mock.response) : _Promise__default["default"].reject(mock.error);
|
|
79
65
|
};
|
|
80
66
|
}; // eslint-disable-next-line import/prefer-default-export
|
|
81
67
|
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
6
5
|
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
7
6
|
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
8
7
|
var _findIndexInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find-index');
|
|
@@ -21,61 +20,48 @@ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInsta
|
|
|
21
20
|
var _spliceInstanceProperty__default = /*#__PURE__*/_interopDefault(_spliceInstanceProperty);
|
|
22
21
|
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
const serialize = data => {
|
|
24
|
+
const undefinedPlaceholder = uuid.v4();
|
|
25
|
+
const placeholderRegexp = new RegExp("\"".concat(undefinedPlaceholder, "\""), 'g');
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
return v === undefined ? undefinedPlaceholder : v;
|
|
30
|
-
};
|
|
27
|
+
const mapUndefinedValues = (_k, v) => v === undefined ? undefinedPlaceholder : v;
|
|
31
28
|
|
|
32
|
-
|
|
29
|
+
const withPlaceholders = _JSON$stringify__default["default"](data, mapUndefinedValues, 2);
|
|
33
30
|
|
|
34
31
|
return withPlaceholders.replace(placeholderRegexp, 'undefined');
|
|
35
32
|
};
|
|
36
33
|
|
|
37
|
-
|
|
34
|
+
const throwIfNoMocksArePassed = mocks => {
|
|
38
35
|
if (!mocks || !_Array$isArray__default["default"](mocks) || mocks.length === 0) {
|
|
39
36
|
throw new Error('Missing or invalid argument for `mocks`. Expected an array of mocked actions.');
|
|
40
37
|
}
|
|
41
38
|
};
|
|
42
39
|
|
|
43
|
-
|
|
44
|
-
return action.type === 'SDK';
|
|
45
|
-
};
|
|
40
|
+
const isSdkAction = action => action.type === 'SDK';
|
|
46
41
|
|
|
47
|
-
|
|
48
|
-
return mock.response !== undefined;
|
|
49
|
-
};
|
|
42
|
+
const isSdkMockSuccess = mock => mock.response !== undefined;
|
|
50
43
|
|
|
51
|
-
|
|
44
|
+
const createTestMiddleware = mocks => {
|
|
52
45
|
throwIfNoMocksArePassed(mocks); // We clone the mocks so we can keep the user-provided mocks around for
|
|
53
46
|
// the debugging message. The mocksStack gets mutated, while mocks
|
|
54
47
|
// should never be mutated.
|
|
55
48
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return function (next) {
|
|
60
|
-
return function (action) {
|
|
61
|
-
var _context;
|
|
49
|
+
const mocksStack = [...mocks];
|
|
50
|
+
return () => next => action => {
|
|
51
|
+
var _context;
|
|
62
52
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
53
|
+
if (!isSdkAction(action)) {
|
|
54
|
+
return next(action);
|
|
55
|
+
}
|
|
66
56
|
|
|
67
|
-
|
|
68
|
-
return fastEquals.deepEqual(item.action, action);
|
|
69
|
-
});
|
|
57
|
+
const index = _findIndexInstanceProperty__default["default"](mocksStack).call(mocksStack, item => fastEquals.deepEqual(item.action, action));
|
|
70
58
|
|
|
71
|
-
|
|
72
|
-
|
|
59
|
+
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)));
|
|
60
|
+
const mock = mocksStack[index]; // Mocks should only be used once, so we remove it from the stack.
|
|
73
61
|
|
|
74
|
-
|
|
62
|
+
_spliceInstanceProperty__default["default"](mocksStack).call(mocksStack, index, 1);
|
|
75
63
|
|
|
76
|
-
|
|
77
|
-
};
|
|
78
|
-
};
|
|
64
|
+
return isSdkMockSuccess(mock) ? _Promise__default["default"].resolve(mock.response) : _Promise__default["default"].reject(mock.error);
|
|
79
65
|
};
|
|
80
66
|
}; // eslint-disable-next-line import/prefer-default-export
|
|
81
67
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
|
|
2
1
|
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
3
2
|
import _Array$isArray from '@babel/runtime-corejs3/core-js-stable/array/is-array';
|
|
4
3
|
import _findIndexInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find-index';
|
|
@@ -8,61 +7,48 @@ import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
|
|
|
8
7
|
import { deepEqual } from 'fast-equals';
|
|
9
8
|
import { v4 } from 'uuid';
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const serialize = data => {
|
|
11
|
+
const undefinedPlaceholder = v4();
|
|
12
|
+
const placeholderRegexp = new RegExp("\"".concat(undefinedPlaceholder, "\""), 'g');
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
return v === undefined ? undefinedPlaceholder : v;
|
|
17
|
-
};
|
|
14
|
+
const mapUndefinedValues = (_k, v) => v === undefined ? undefinedPlaceholder : v;
|
|
18
15
|
|
|
19
|
-
|
|
16
|
+
const withPlaceholders = _JSON$stringify(data, mapUndefinedValues, 2);
|
|
20
17
|
|
|
21
18
|
return withPlaceholders.replace(placeholderRegexp, 'undefined');
|
|
22
19
|
};
|
|
23
20
|
|
|
24
|
-
|
|
21
|
+
const throwIfNoMocksArePassed = mocks => {
|
|
25
22
|
if (!mocks || !_Array$isArray(mocks) || mocks.length === 0) {
|
|
26
23
|
throw new Error('Missing or invalid argument for `mocks`. Expected an array of mocked actions.');
|
|
27
24
|
}
|
|
28
25
|
};
|
|
29
26
|
|
|
30
|
-
|
|
31
|
-
return action.type === 'SDK';
|
|
32
|
-
};
|
|
27
|
+
const isSdkAction = action => action.type === 'SDK';
|
|
33
28
|
|
|
34
|
-
|
|
35
|
-
return mock.response !== undefined;
|
|
36
|
-
};
|
|
29
|
+
const isSdkMockSuccess = mock => mock.response !== undefined;
|
|
37
30
|
|
|
38
|
-
|
|
31
|
+
const createTestMiddleware = mocks => {
|
|
39
32
|
throwIfNoMocksArePassed(mocks); // We clone the mocks so we can keep the user-provided mocks around for
|
|
40
33
|
// the debugging message. The mocksStack gets mutated, while mocks
|
|
41
34
|
// should never be mutated.
|
|
42
35
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return function (next) {
|
|
47
|
-
return function (action) {
|
|
48
|
-
var _context;
|
|
36
|
+
const mocksStack = [...mocks];
|
|
37
|
+
return () => next => action => {
|
|
38
|
+
var _context;
|
|
49
39
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
40
|
+
if (!isSdkAction(action)) {
|
|
41
|
+
return next(action);
|
|
42
|
+
}
|
|
53
43
|
|
|
54
|
-
|
|
55
|
-
return deepEqual(item.action, action);
|
|
56
|
-
});
|
|
44
|
+
const index = _findIndexInstanceProperty(mocksStack).call(mocksStack, item => deepEqual(item.action, action));
|
|
57
45
|
|
|
58
|
-
|
|
59
|
-
|
|
46
|
+
if (index === -1) throw new Error(_concatInstanceProperty(_context = "Could not find any more mocks for action ".concat(serialize(action), " in ")).call(_context, serialize(mocks)));
|
|
47
|
+
const mock = mocksStack[index]; // Mocks should only be used once, so we remove it from the stack.
|
|
60
48
|
|
|
61
|
-
|
|
49
|
+
_spliceInstanceProperty(mocksStack).call(mocksStack, index, 1);
|
|
62
50
|
|
|
63
|
-
|
|
64
|
-
};
|
|
65
|
-
};
|
|
51
|
+
return isSdkMockSuccess(mock) ? _Promise.resolve(mock.response) : _Promise.reject(mock.error);
|
|
66
52
|
};
|
|
67
53
|
}; // eslint-disable-next-line import/prefer-default-export
|
|
68
54
|
|