@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,15 +1,3 @@
|
|
|
1
|
-
import _Reflect$construct from '@babel/runtime-corejs3/core-js-stable/reflect/construct';
|
|
2
|
-
import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
|
|
3
|
-
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
4
|
-
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
5
|
-
import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
6
|
-
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
7
|
-
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
8
|
-
import _pt from 'prop-types';
|
|
9
|
-
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
10
|
-
import { Component } from 'react';
|
|
11
|
-
import { connect, useDispatch } from 'react-redux';
|
|
12
|
-
import { deepEqual } from 'fast-equals';
|
|
13
1
|
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
14
2
|
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
15
3
|
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
@@ -23,28 +11,154 @@ import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
|
23
11
|
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
24
12
|
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
25
13
|
import omitEmpty from 'omit-empty-es';
|
|
14
|
+
import _Reflect$construct from '@babel/runtime-corejs3/core-js-stable/reflect/construct';
|
|
15
|
+
import _classCallCheck from '@babel/runtime-corejs3/helpers/esm/classCallCheck';
|
|
16
|
+
import _createClass from '@babel/runtime-corejs3/helpers/esm/createClass';
|
|
17
|
+
import _inherits from '@babel/runtime-corejs3/helpers/esm/inherits';
|
|
18
|
+
import _possibleConstructorReturn from '@babel/runtime-corejs3/helpers/esm/possibleConstructorReturn';
|
|
19
|
+
import _getPrototypeOf from '@babel/runtime-corejs3/helpers/esm/getPrototypeOf';
|
|
20
|
+
import _pt from 'prop-types';
|
|
21
|
+
import { Component } from 'react';
|
|
22
|
+
import { deepEqual } from 'fast-equals';
|
|
23
|
+
import { connect, useDispatch } from 'react-redux';
|
|
24
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
26
25
|
import { createRequestBuilder } from '@commercetools/api-request-builder';
|
|
27
26
|
import { SHOW_LOADING, STATUS_CODES, HIDE_LOADING } from '@commercetools-frontend/constants';
|
|
28
27
|
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
|
29
28
|
import { decode } from 'qss';
|
|
30
29
|
import _globalThis from '@babel/runtime-corejs3/core-js/global-this';
|
|
31
30
|
import { Buffer } from 'buffer';
|
|
31
|
+
import createHttpUserAgent from '@commercetools/http-user-agent';
|
|
32
32
|
import { createClient as createClient$1 } from '@commercetools/sdk-client';
|
|
33
|
-
import { createHttpMiddleware } from '@commercetools/sdk-middleware-http';
|
|
34
33
|
import { createCorrelationIdMiddleware as createCorrelationIdMiddleware$1 } from '@commercetools/sdk-middleware-correlation-id';
|
|
35
|
-
import
|
|
34
|
+
import { createHttpMiddleware } from '@commercetools/sdk-middleware-http';
|
|
35
|
+
|
|
36
|
+
function ownKeys$3(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
+
|
|
38
|
+
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys$3(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys$3(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
39
|
+
function get(payload) {
|
|
40
|
+
return {
|
|
41
|
+
type: 'SDK',
|
|
42
|
+
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
43
|
+
method: 'GET'
|
|
44
|
+
})
|
|
45
|
+
};
|
|
46
|
+
} // contrary to the other methods this does not bear the exact name of the HTTP-verb
|
|
47
|
+
// because `delete` is a reserved keyword in ECMAScript
|
|
48
|
+
|
|
49
|
+
function del(payload) {
|
|
50
|
+
return {
|
|
51
|
+
type: 'SDK',
|
|
52
|
+
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
53
|
+
method: 'DELETE'
|
|
54
|
+
})
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function head(payload) {
|
|
58
|
+
return {
|
|
59
|
+
type: 'SDK',
|
|
60
|
+
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
61
|
+
method: 'HEAD'
|
|
62
|
+
})
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
function post(payload) {
|
|
66
|
+
return {
|
|
67
|
+
type: 'SDK',
|
|
68
|
+
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
69
|
+
method: 'POST'
|
|
70
|
+
})
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const enhancePayloadForForwardToProxy = payload => {
|
|
75
|
+
var _payload$headers, _context;
|
|
76
|
+
|
|
77
|
+
const headers = (_payload$headers = payload.headers) !== null && _payload$headers !== void 0 ? _payload$headers : {};
|
|
78
|
+
const exchangeTokenClaims = [];
|
|
79
|
+
|
|
80
|
+
if (payload.includeUserPermissions) {
|
|
81
|
+
exchangeTokenClaims.push('permissions');
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
uri: '/proxy/forward-to',
|
|
86
|
+
mcApiProxyTarget: undefined,
|
|
87
|
+
headers: omitEmpty(_objectSpread$3(_objectSpread$3({}, _reduceInstanceProperty(_context = _Object$entries(headers)).call(_context, (customForwardHeaders, _ref) => {
|
|
88
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
89
|
+
headerName = _ref2[0],
|
|
90
|
+
headerValue = _ref2[1];
|
|
91
|
+
|
|
92
|
+
return _objectSpread$3(_objectSpread$3({}, customForwardHeaders), {}, {
|
|
93
|
+
// Prefix headers so that the MC API can allow and forward them.
|
|
94
|
+
["x-forward-header-".concat(headerName)]: headerValue
|
|
95
|
+
});
|
|
96
|
+
}, {})), {}, {
|
|
97
|
+
'Accept-version': 'v2',
|
|
98
|
+
'X-Forward-To': payload.uri,
|
|
99
|
+
'X-Forward-To-Audience-Policy': payload.audiencePolicy || 'forward-url-full-path',
|
|
100
|
+
'X-Forward-To-Claims': exchangeTokenClaims.join(' ')
|
|
101
|
+
}))
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const forwardTo = {
|
|
106
|
+
get(payload) {
|
|
107
|
+
return {
|
|
108
|
+
type: 'SDK',
|
|
109
|
+
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
110
|
+
method: 'GET'
|
|
111
|
+
}, enhancePayloadForForwardToProxy(payload))
|
|
112
|
+
};
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
del(payload) {
|
|
116
|
+
return {
|
|
117
|
+
type: 'SDK',
|
|
118
|
+
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
119
|
+
method: 'DELETE'
|
|
120
|
+
}, enhancePayloadForForwardToProxy(payload))
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
head(payload) {
|
|
125
|
+
return {
|
|
126
|
+
type: 'SDK',
|
|
127
|
+
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
128
|
+
method: 'HEAD'
|
|
129
|
+
}, enhancePayloadForForwardToProxy(payload))
|
|
130
|
+
};
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
post(payload) {
|
|
134
|
+
return {
|
|
135
|
+
type: 'SDK',
|
|
136
|
+
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
137
|
+
method: 'POST'
|
|
138
|
+
}, enhancePayloadForForwardToProxy(payload))
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
145
|
+
__proto__: null,
|
|
146
|
+
get: get,
|
|
147
|
+
del: del,
|
|
148
|
+
head: head,
|
|
149
|
+
post: post,
|
|
150
|
+
forwardTo: forwardTo
|
|
151
|
+
});
|
|
36
152
|
|
|
37
153
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
38
154
|
|
|
39
155
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct) return false; if (_Reflect$construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
40
|
-
|
|
156
|
+
let SdkGet = /*#__PURE__*/function (_Component) {
|
|
41
157
|
_inherits(SdkGet, _Component);
|
|
42
158
|
|
|
43
159
|
var _super = _createSuper(SdkGet);
|
|
44
160
|
|
|
45
161
|
function SdkGet() {
|
|
46
|
-
var _context;
|
|
47
|
-
|
|
48
162
|
var _this;
|
|
49
163
|
|
|
50
164
|
_classCallCheck(this, SdkGet);
|
|
@@ -53,7 +167,7 @@ var SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
53
167
|
args[_key] = arguments[_key];
|
|
54
168
|
}
|
|
55
169
|
|
|
56
|
-
_this = _super.call
|
|
170
|
+
_this = _super.call(this, ...args);
|
|
57
171
|
_this.state = {
|
|
58
172
|
// We want the component to have a loading state by default, so we
|
|
59
173
|
// keep track of whether the first request has completed.
|
|
@@ -66,16 +180,14 @@ var SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
66
180
|
};
|
|
67
181
|
_this.isComponentMounted = false;
|
|
68
182
|
|
|
69
|
-
_this.changeRequestsInFlight =
|
|
70
|
-
if (_this.isComponentMounted) _this.setState(
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
};
|
|
74
|
-
});
|
|
183
|
+
_this.changeRequestsInFlight = delta => {
|
|
184
|
+
if (_this.isComponentMounted) _this.setState(prevState => ({
|
|
185
|
+
requestsInFlight: prevState.requestsInFlight + delta
|
|
186
|
+
}));
|
|
75
187
|
};
|
|
76
188
|
|
|
77
|
-
_this.fetch =
|
|
78
|
-
|
|
189
|
+
_this.fetch = _ref => {
|
|
190
|
+
let dispatch = _ref.dispatch,
|
|
79
191
|
actionCreator = _ref.actionCreator,
|
|
80
192
|
actionCreatorArgs = _ref.actionCreatorArgs,
|
|
81
193
|
onSuccess = _ref.onSuccess,
|
|
@@ -83,35 +195,33 @@ var SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
83
195
|
|
|
84
196
|
_this.changeRequestsInFlight(1);
|
|
85
197
|
|
|
86
|
-
return dispatch(actionCreator
|
|
198
|
+
return dispatch(actionCreator(...actionCreatorArgs)).then(result => {
|
|
87
199
|
_this.changeRequestsInFlight(-1);
|
|
88
200
|
|
|
89
201
|
if (_this.isComponentMounted) _this.setState({
|
|
90
202
|
error: undefined,
|
|
91
|
-
result
|
|
203
|
+
result
|
|
92
204
|
});
|
|
93
205
|
if (onSuccess) onSuccess(result);
|
|
94
206
|
return result;
|
|
95
|
-
},
|
|
207
|
+
}, error => {
|
|
96
208
|
_this.changeRequestsInFlight(-1);
|
|
97
209
|
|
|
98
210
|
if (_this.isComponentMounted) _this.setState({
|
|
99
|
-
error
|
|
211
|
+
error,
|
|
100
212
|
result: undefined
|
|
101
213
|
});
|
|
102
214
|
if (onError) onError(error);else SdkGet.errorHandler(error);
|
|
103
215
|
});
|
|
104
216
|
};
|
|
105
217
|
|
|
106
|
-
_this.refresh =
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
});
|
|
114
|
-
};
|
|
218
|
+
_this.refresh = () => _this.fetch({
|
|
219
|
+
dispatch: _this.props.dispatch,
|
|
220
|
+
actionCreator: _this.props.actionCreator,
|
|
221
|
+
actionCreatorArgs: _this.props.actionCreatorArgs,
|
|
222
|
+
onSuccess: _this.props.onSuccess,
|
|
223
|
+
onError: _this.props.onError
|
|
224
|
+
});
|
|
115
225
|
|
|
116
226
|
return _this;
|
|
117
227
|
}
|
|
@@ -119,8 +229,6 @@ var SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
119
229
|
_createClass(SdkGet, [{
|
|
120
230
|
key: "componentDidMount",
|
|
121
231
|
value: function componentDidMount() {
|
|
122
|
-
var _this2 = this;
|
|
123
|
-
|
|
124
232
|
this.isComponentMounted = true;
|
|
125
233
|
this.fetch({
|
|
126
234
|
dispatch: this.props.dispatch,
|
|
@@ -128,13 +236,13 @@ var SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
128
236
|
actionCreatorArgs: this.props.actionCreatorArgs,
|
|
129
237
|
onSuccess: this.props.onSuccess,
|
|
130
238
|
onError: this.props.onError
|
|
131
|
-
}).then(
|
|
132
|
-
if (
|
|
239
|
+
}).then(result => {
|
|
240
|
+
if (this.isComponentMounted) this.setState({
|
|
133
241
|
isWaitingForCompletionOfFirstRequest: false
|
|
134
242
|
});
|
|
135
243
|
return result;
|
|
136
|
-
},
|
|
137
|
-
if (
|
|
244
|
+
}, error => {
|
|
245
|
+
if (this.isComponentMounted) this.setState({
|
|
138
246
|
isWaitingForCompletionOfFirstRequest: false
|
|
139
247
|
});
|
|
140
248
|
throw error;
|
|
@@ -172,15 +280,13 @@ var SdkGet = /*#__PURE__*/function (_Component) {
|
|
|
172
280
|
}(Component);
|
|
173
281
|
SdkGet.displayName = 'SdkGet';
|
|
174
282
|
|
|
175
|
-
SdkGet.errorHandler =
|
|
283
|
+
SdkGet.errorHandler = error => {
|
|
176
284
|
throw error;
|
|
177
285
|
};
|
|
178
286
|
|
|
179
287
|
SdkGet.defaultProps = {
|
|
180
288
|
actionCreatorArgs: [],
|
|
181
|
-
shouldRefetch:
|
|
182
|
-
return !deepEqual(prevArgs, nextArgs);
|
|
183
|
-
}
|
|
289
|
+
shouldRefetch: (prevArgs, nextArgs) => !deepEqual(prevArgs, nextArgs)
|
|
184
290
|
};
|
|
185
291
|
SdkGet.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
186
292
|
dispatch: _pt.func.isRequired,
|
|
@@ -192,172 +298,48 @@ SdkGet.propTypes = process.env.NODE_ENV !== "production" ? {
|
|
|
192
298
|
render: _pt.func.isRequired
|
|
193
299
|
} : {};
|
|
194
300
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
};
|
|
199
|
-
};
|
|
301
|
+
const mapDispatchToProps = dispatch => ({
|
|
302
|
+
dispatch
|
|
303
|
+
});
|
|
200
304
|
|
|
201
305
|
var SdkGet$1 = connect(null, mapDispatchToProps)(SdkGet);
|
|
202
306
|
|
|
203
|
-
function ownKeys$3(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
204
|
-
|
|
205
|
-
function _objectSpread$3(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys$3(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys$3(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
206
|
-
function get(payload) {
|
|
207
|
-
return {
|
|
208
|
-
type: 'SDK',
|
|
209
|
-
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
210
|
-
method: 'GET'
|
|
211
|
-
})
|
|
212
|
-
};
|
|
213
|
-
} // contrary to the other methods this does not bear the exact name of the HTTP-verb
|
|
214
|
-
// because `delete` is a reserved keyword in ECMAScript
|
|
215
|
-
|
|
216
|
-
function del(payload) {
|
|
217
|
-
return {
|
|
218
|
-
type: 'SDK',
|
|
219
|
-
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
220
|
-
method: 'DELETE'
|
|
221
|
-
})
|
|
222
|
-
};
|
|
223
|
-
}
|
|
224
|
-
function head(payload) {
|
|
225
|
-
return {
|
|
226
|
-
type: 'SDK',
|
|
227
|
-
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
228
|
-
method: 'HEAD'
|
|
229
|
-
})
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
function post(payload) {
|
|
233
|
-
return {
|
|
234
|
-
type: 'SDK',
|
|
235
|
-
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
236
|
-
method: 'POST'
|
|
237
|
-
})
|
|
238
|
-
};
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
var enhancePayloadForForwardToProxy = function enhancePayloadForForwardToProxy(payload) {
|
|
242
|
-
var _payload$headers, _context;
|
|
243
|
-
|
|
244
|
-
var headers = (_payload$headers = payload.headers) !== null && _payload$headers !== void 0 ? _payload$headers : {};
|
|
245
|
-
var exchangeTokenClaims = [];
|
|
246
|
-
|
|
247
|
-
if (payload.includeUserPermissions) {
|
|
248
|
-
exchangeTokenClaims.push('permissions');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
return {
|
|
252
|
-
uri: '/proxy/forward-to',
|
|
253
|
-
mcApiProxyTarget: undefined,
|
|
254
|
-
headers: omitEmpty(_objectSpread$3(_objectSpread$3({}, _reduceInstanceProperty(_context = _Object$entries(headers)).call(_context, function (customForwardHeaders, _ref) {
|
|
255
|
-
var _ref2 = _slicedToArray(_ref, 2),
|
|
256
|
-
headerName = _ref2[0],
|
|
257
|
-
headerValue = _ref2[1];
|
|
258
|
-
|
|
259
|
-
return _objectSpread$3(_objectSpread$3({}, customForwardHeaders), {}, _defineProperty({}, "x-forward-header-".concat(headerName), headerValue));
|
|
260
|
-
}, {})), {}, {
|
|
261
|
-
'Accept-version': 'v2',
|
|
262
|
-
'X-Forward-To': payload.uri,
|
|
263
|
-
'X-Forward-To-Audience-Policy': payload.audiencePolicy || 'forward-url-full-path',
|
|
264
|
-
'X-Forward-To-Claims': exchangeTokenClaims.join(' ')
|
|
265
|
-
}))
|
|
266
|
-
};
|
|
267
|
-
};
|
|
268
|
-
|
|
269
|
-
var forwardTo = {
|
|
270
|
-
get: function get(payload) {
|
|
271
|
-
return {
|
|
272
|
-
type: 'SDK',
|
|
273
|
-
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
274
|
-
method: 'GET'
|
|
275
|
-
}, enhancePayloadForForwardToProxy(payload))
|
|
276
|
-
};
|
|
277
|
-
},
|
|
278
|
-
del: function del(payload) {
|
|
279
|
-
return {
|
|
280
|
-
type: 'SDK',
|
|
281
|
-
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
282
|
-
method: 'DELETE'
|
|
283
|
-
}, enhancePayloadForForwardToProxy(payload))
|
|
284
|
-
};
|
|
285
|
-
},
|
|
286
|
-
head: function head(payload) {
|
|
287
|
-
return {
|
|
288
|
-
type: 'SDK',
|
|
289
|
-
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
290
|
-
method: 'HEAD'
|
|
291
|
-
}, enhancePayloadForForwardToProxy(payload))
|
|
292
|
-
};
|
|
293
|
-
},
|
|
294
|
-
post: function post(payload) {
|
|
295
|
-
return {
|
|
296
|
-
type: 'SDK',
|
|
297
|
-
payload: _objectSpread$3(_objectSpread$3({}, payload), {}, {
|
|
298
|
-
method: 'POST'
|
|
299
|
-
}, enhancePayloadForForwardToProxy(payload))
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
305
|
-
__proto__: null,
|
|
306
|
-
get: get,
|
|
307
|
-
del: del,
|
|
308
|
-
head: head,
|
|
309
|
-
post: post,
|
|
310
|
-
forwardTo: forwardTo
|
|
311
|
-
});
|
|
312
|
-
|
|
313
307
|
// NOTE: This string will be replaced on build time with the package version.
|
|
314
|
-
var version = "21.
|
|
308
|
+
var version = "21.24.1";
|
|
315
309
|
|
|
316
310
|
/* eslint-disable no-console */
|
|
317
|
-
|
|
311
|
+
const isLoggerEnabled = () => {
|
|
318
312
|
if (process.env.DEBUG === 'true') return true;
|
|
319
313
|
if (process.env.NODE_ENV === 'development') return true;
|
|
320
|
-
|
|
314
|
+
const queryParams = new _URL(window.location.href);
|
|
321
315
|
if (process.env.NODE_ENV === 'production' && queryParams.searchParams.get('debug') === 'true') return true;
|
|
322
316
|
return false;
|
|
323
317
|
};
|
|
324
318
|
|
|
325
|
-
|
|
326
|
-
groupCollapsed: function
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
return isLoggerEnabled() && (_console = console).groupCollapsed.apply(_console, arguments);
|
|
330
|
-
},
|
|
331
|
-
groupEnd: function groupEnd() {
|
|
332
|
-
return isLoggerEnabled() && console.groupEnd();
|
|
319
|
+
const logger = {
|
|
320
|
+
groupCollapsed: function () {
|
|
321
|
+
return isLoggerEnabled() && console.groupCollapsed(...arguments);
|
|
333
322
|
},
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
return isLoggerEnabled() && (_console2 = console).info.apply(_console2, arguments);
|
|
323
|
+
groupEnd: () => isLoggerEnabled() && console.groupEnd(),
|
|
324
|
+
info: function () {
|
|
325
|
+
return isLoggerEnabled() && console.info(...arguments);
|
|
338
326
|
},
|
|
339
|
-
log: function
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
return isLoggerEnabled() && (_console3 = console).log.apply(_console3, arguments);
|
|
327
|
+
log: function () {
|
|
328
|
+
return isLoggerEnabled() && console.log(...arguments);
|
|
343
329
|
},
|
|
344
|
-
error: function
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
return isLoggerEnabled() && (_console4 = console).error.apply(_console4, arguments);
|
|
330
|
+
error: function () {
|
|
331
|
+
return isLoggerEnabled() && console.error(...arguments);
|
|
348
332
|
},
|
|
349
|
-
warn: function
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
return isLoggerEnabled() && (_console5 = console).warn.apply(_console5, arguments);
|
|
333
|
+
warn: function () {
|
|
334
|
+
return isLoggerEnabled() && console.warn(...arguments);
|
|
353
335
|
}
|
|
354
336
|
};
|
|
355
337
|
|
|
356
338
|
function ownKeys$2(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
357
339
|
|
|
358
340
|
function _objectSpread$2(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys$2(Object(source), !0)).call(_context3, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys$2(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
359
|
-
|
|
360
|
-
|
|
341
|
+
const parseUri = uri => {
|
|
342
|
+
const parser = document.createElement('a');
|
|
361
343
|
parser.href = uri;
|
|
362
344
|
return {
|
|
363
345
|
pathname: parser.pathname,
|
|
@@ -365,21 +347,19 @@ var parseUri = function parseUri(uri) {
|
|
|
365
347
|
};
|
|
366
348
|
};
|
|
367
349
|
|
|
368
|
-
|
|
369
|
-
return action.payload.method === 'POST';
|
|
370
|
-
};
|
|
350
|
+
const isPostAction = action => action.payload.method === 'POST';
|
|
371
351
|
|
|
372
|
-
|
|
352
|
+
const logRequest = _ref => {
|
|
373
353
|
var _context;
|
|
374
354
|
|
|
375
|
-
|
|
355
|
+
let method = _ref.method,
|
|
376
356
|
request = _ref.request,
|
|
377
357
|
response = _ref.response,
|
|
378
358
|
error = _ref.error,
|
|
379
359
|
action = _ref.action;
|
|
380
|
-
|
|
360
|
+
const uriParts = parseUri(request.uri);
|
|
381
361
|
|
|
382
|
-
|
|
362
|
+
const groupName = _concatInstanceProperty(_context = "%c".concat(method, " %c")).call(_context, uriParts.pathname);
|
|
383
363
|
|
|
384
364
|
logger.groupCollapsed(groupName, "color: ".concat(error ? 'red' : 'black', "; font-weight: bold;"), 'color: gray; font-weight: lighter;');
|
|
385
365
|
logger.log('%caction', 'color: cadetblue; font-weight: bold;', action);
|
|
@@ -394,10 +374,10 @@ var logRequest = function logRequest(_ref) {
|
|
|
394
374
|
if (error) logger.log('%cerror', "color: red; font-weight: bold;", error);
|
|
395
375
|
logger.groupEnd();
|
|
396
376
|
};
|
|
397
|
-
|
|
398
|
-
|
|
377
|
+
const mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
378
|
+
const mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
|
|
399
379
|
|
|
400
|
-
|
|
380
|
+
const getMcOriginTld = host => {
|
|
401
381
|
if (host.match(mcPreviewHostnameRegex)) {
|
|
402
382
|
return host.replace(mcPreviewHostnameRegex, '$1');
|
|
403
383
|
}
|
|
@@ -405,21 +385,19 @@ var getMcOriginTld = function getMcOriginTld(host) {
|
|
|
405
385
|
return host.replace(mcHostnameRegex, '$3');
|
|
406
386
|
};
|
|
407
387
|
|
|
408
|
-
|
|
388
|
+
const getMcApiUrlFromOrigin = actualWindow => {
|
|
409
389
|
var _context2;
|
|
410
390
|
|
|
411
|
-
|
|
412
|
-
|
|
391
|
+
const url = new _URL(actualWindow.origin);
|
|
392
|
+
const originTld = getMcOriginTld(url.host);
|
|
413
393
|
return _concatInstanceProperty(_context2 = "".concat(url.protocol, "//mc-api.")).call(_context2, originTld);
|
|
414
394
|
};
|
|
415
395
|
|
|
416
|
-
|
|
417
|
-
return value === true || value === 'true';
|
|
418
|
-
};
|
|
396
|
+
const parseAsBoolean = value => value === true || value === 'true';
|
|
419
397
|
|
|
420
398
|
function getMcApiUrl() {
|
|
421
|
-
|
|
422
|
-
|
|
399
|
+
let actualWindow = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window;
|
|
400
|
+
const isServedByProxy = parseAsBoolean(actualWindow.app.servedByProxy);
|
|
423
401
|
/**
|
|
424
402
|
* Prefer using the origin URL for the MC API based on the origin value
|
|
425
403
|
* of the browser's `window.location`.
|
|
@@ -439,7 +417,7 @@ function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys(object); if
|
|
|
439
417
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
440
418
|
|
|
441
419
|
_globalThis.Buffer = Buffer;
|
|
442
|
-
|
|
420
|
+
const userAgent = createHttpUserAgent({
|
|
443
421
|
name: '@commercetools/sdk-client',
|
|
444
422
|
libraryName: [window.app.applicationName, 'sdk'].join('/'),
|
|
445
423
|
libraryVersion: version,
|
|
@@ -448,39 +426,37 @@ var userAgent = createHttpUserAgent({
|
|
|
448
426
|
contactEmail: 'mc@commercetools.com'
|
|
449
427
|
});
|
|
450
428
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
});
|
|
429
|
+
const customUserAgentMiddleware = next => (request, response) => {
|
|
430
|
+
const requestWithCustomUserAgent = _objectSpread$1(_objectSpread$1({}, request), {}, {
|
|
431
|
+
headers: _objectSpread$1(_objectSpread$1({}, request.headers), {}, {
|
|
432
|
+
'X-User-Agent': userAgent
|
|
433
|
+
})
|
|
434
|
+
});
|
|
458
435
|
|
|
459
|
-
|
|
460
|
-
};
|
|
436
|
+
next(requestWithCustomUserAgent, response);
|
|
461
437
|
}; // NOTE we should not use these directly but rather have them passed in from
|
|
462
438
|
// the application
|
|
463
439
|
|
|
464
440
|
|
|
465
|
-
|
|
441
|
+
const httpMiddleware = createHttpMiddleware({
|
|
466
442
|
host: getMcApiUrl(),
|
|
467
443
|
includeResponseHeaders: true,
|
|
468
444
|
credentialsMode: 'include',
|
|
469
|
-
fetch
|
|
445
|
+
fetch
|
|
470
446
|
});
|
|
471
447
|
|
|
472
|
-
|
|
473
|
-
|
|
448
|
+
const createCorrelationIdMiddleware = _ref => {
|
|
449
|
+
let getCorrelationId = _ref.getCorrelationId;
|
|
474
450
|
return createCorrelationIdMiddleware$1({
|
|
475
451
|
generate: getCorrelationId
|
|
476
452
|
});
|
|
477
453
|
};
|
|
478
454
|
|
|
479
|
-
|
|
480
|
-
|
|
455
|
+
const createClient = _ref2 => {
|
|
456
|
+
let getCorrelationId = _ref2.getCorrelationId;
|
|
481
457
|
return createClient$1({
|
|
482
458
|
middlewares: [createCorrelationIdMiddleware({
|
|
483
|
-
getCorrelationId
|
|
459
|
+
getCorrelationId
|
|
484
460
|
}), customUserAgentMiddleware, httpMiddleware]
|
|
485
461
|
});
|
|
486
462
|
};
|
|
@@ -489,14 +465,12 @@ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (
|
|
|
489
465
|
|
|
490
466
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context4, _context5; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context4 = ownKeys(Object(source), !0)).call(_context4, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context5 = ownKeys(Object(source))).call(_context5, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
491
467
|
|
|
492
|
-
|
|
493
|
-
return actionPayload.uri !== undefined;
|
|
494
|
-
}; // https://github.com/commercetools/nodejs/blob/master/packages/api-request-builder/src/default-services.js#L200:L200
|
|
468
|
+
const isSdkActionForUri = actionPayload => actionPayload.uri !== undefined; // https://github.com/commercetools/nodejs/blob/master/packages/api-request-builder/src/default-services.js#L200:L200
|
|
495
469
|
|
|
496
470
|
|
|
497
|
-
|
|
471
|
+
const ORDER_EDIT_SERVICE = 'orderEdits';
|
|
498
472
|
|
|
499
|
-
|
|
473
|
+
const actionToUri = (action, projectKey) => {
|
|
500
474
|
var _action$payload$optio;
|
|
501
475
|
|
|
502
476
|
if (isSdkActionForUri(action.payload)) return action.payload.uri; // Validate that `projectKey` exists
|
|
@@ -507,13 +481,13 @@ var actionToUri = function actionToUri(action, projectKey) {
|
|
|
507
481
|
throw new Error(_concatInstanceProperty(_context = "Expected projectKey to be defined for action service \"".concat(action.payload.service, "\" (method \"")).call(_context, action.payload.method, "\")"));
|
|
508
482
|
}
|
|
509
483
|
|
|
510
|
-
|
|
511
|
-
projectKey
|
|
484
|
+
const requestBuilder = createRequestBuilder({
|
|
485
|
+
projectKey
|
|
512
486
|
}); // NOTE it's weird that we have to access this from the request builder.
|
|
513
487
|
// Shouldn't it just be a part of the object we parse?
|
|
514
488
|
// NOTE shouldn't requestBuilder be called requestUriBuilder instead?
|
|
515
489
|
|
|
516
|
-
|
|
490
|
+
const service = requestBuilder[action.payload.service];
|
|
517
491
|
if (action.payload.options) service.parse(action.payload.options);
|
|
518
492
|
return service.build({
|
|
519
493
|
// given `service=orderEdits` and given `applyOrderEditTo`, we build an apply endpoint
|
|
@@ -526,135 +500,129 @@ var actionToUri = function actionToUri(action, projectKey) {
|
|
|
526
500
|
}; // Force TS cast of generic action to TNotificationAction
|
|
527
501
|
|
|
528
502
|
|
|
529
|
-
|
|
530
|
-
return action.type === 'SDK';
|
|
531
|
-
};
|
|
503
|
+
const isSdkAction = action => action.type === 'SDK';
|
|
532
504
|
|
|
533
|
-
|
|
534
|
-
return error.statusCode !== undefined;
|
|
535
|
-
};
|
|
505
|
+
const isSdkError = error => error.statusCode !== undefined;
|
|
536
506
|
|
|
537
507
|
function createSdkMiddleware(_ref) {
|
|
538
|
-
|
|
508
|
+
let getCorrelationId = _ref.getCorrelationId,
|
|
539
509
|
getProjectKey = _ref.getProjectKey,
|
|
540
510
|
getAdditionalHeaders = _ref.getAdditionalHeaders;
|
|
541
|
-
|
|
542
|
-
getCorrelationId
|
|
511
|
+
const client = createClient({
|
|
512
|
+
getCorrelationId
|
|
543
513
|
});
|
|
544
514
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
return
|
|
548
|
-
|
|
549
|
-
|
|
515
|
+
const middleware = _ref2 => {
|
|
516
|
+
let dispatch = _ref2.dispatch;
|
|
517
|
+
return next => action => {
|
|
518
|
+
var _context2, _context3;
|
|
519
|
+
|
|
520
|
+
if (!isSdkAction(action)) {
|
|
521
|
+
return next(action);
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
const projectKey = getProjectKey();
|
|
525
|
+
|
|
526
|
+
const uri = _filterInstanceProperty(_context2 = [action.payload.mcApiProxyTarget && "/proxy/".concat(action.payload.mcApiProxyTarget), actionToUri(action, projectKey)]).call(_context2, Boolean).join(''); // This `requestName` is never really used.
|
|
527
|
+
//
|
|
528
|
+
// We keep track of requests which are in progress in the `loading` state of
|
|
529
|
+
// the application. The `loading` state is an array of strings
|
|
530
|
+
// (which are correlation Ids, action types or request names).
|
|
531
|
+
// This is just done so that debugging is easier.
|
|
532
|
+
//
|
|
533
|
+
// It's easier to debug
|
|
534
|
+
// loading: ['PRODUCTS_FETCHED', 'sdk.fetch(/product-projection-search)']
|
|
535
|
+
// than to debug
|
|
536
|
+
// loading: 2
|
|
537
|
+
|
|
538
|
+
|
|
539
|
+
const requestName = _concatInstanceProperty(_context3 = "sdk.".concat(action.payload.method.toLowerCase(), "(")).call(_context3, uri, ")"); // NOTE here the middleware is aware of the application
|
|
540
|
+
// Instead we should probably convert to a middleware factory
|
|
541
|
+
// and provide hooks for `onFetch`, `onResult` and `onError
|
|
542
|
+
|
|
543
|
+
|
|
544
|
+
dispatch({
|
|
545
|
+
type: SHOW_LOADING,
|
|
546
|
+
payload: requestName
|
|
547
|
+
}); // NOTE the promise returned by the client resolves to a custom format
|
|
548
|
+
// it will contain { statusCode, headers, body }
|
|
549
|
+
// NOTE This retry logic could be moved to an sdk client middleware,
|
|
550
|
+
// but the client's middleware system is not capable of that right now
|
|
551
|
+
// https://github.com/commercetools/merchant-center-frontend/pull/3304
|
|
552
|
+
// https://github.com/commercetools/nodejs/issues/390
|
|
553
|
+
|
|
554
|
+
const sendRequest = function () {
|
|
555
|
+
let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
556
|
+
shouldRenewToken = _ref3.shouldRenewToken;
|
|
557
|
+
|
|
558
|
+
const additionalHeaders = getAdditionalHeaders();
|
|
559
|
+
|
|
560
|
+
const headers = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
561
|
+
Accept: 'application/json'
|
|
562
|
+
}, action.payload.headers || {}), shouldRenewToken ? {
|
|
563
|
+
'X-Force-Token': 'true'
|
|
564
|
+
} : {}), projectKey && {
|
|
565
|
+
'X-Project-Key': projectKey
|
|
566
|
+
}), additionalHeaders !== null && additionalHeaders !== void 0 ? additionalHeaders : {});
|
|
567
|
+
|
|
568
|
+
const body = action.payload.method === 'POST' ? action.payload.payload : undefined;
|
|
569
|
+
return client.execute({
|
|
570
|
+
uri,
|
|
571
|
+
method: action.payload.method,
|
|
572
|
+
headers,
|
|
573
|
+
body
|
|
574
|
+
}).then(result => {
|
|
575
|
+
if (process.env.NODE_ENV === 'development') logRequest({
|
|
576
|
+
method: action.payload.method,
|
|
577
|
+
request: {
|
|
578
|
+
headers,
|
|
579
|
+
uri
|
|
580
|
+
},
|
|
581
|
+
response: result.body,
|
|
582
|
+
action
|
|
583
|
+
});
|
|
584
|
+
return result;
|
|
585
|
+
}, error => {
|
|
586
|
+
if (process.env.NODE_ENV === 'development') logRequest({
|
|
587
|
+
method: action.payload.method,
|
|
588
|
+
request: {
|
|
589
|
+
headers,
|
|
590
|
+
uri
|
|
591
|
+
},
|
|
592
|
+
error,
|
|
593
|
+
action
|
|
594
|
+
});
|
|
595
|
+
throw error;
|
|
596
|
+
});
|
|
597
|
+
};
|
|
550
598
|
|
|
551
|
-
|
|
552
|
-
|
|
599
|
+
return sendRequest().catch(error => {
|
|
600
|
+
// in case of 401 error, try again with a new token
|
|
601
|
+
// https://github.com/commercetools/merchant-center-backend/blob/master/docs/AUTHENTICATION.md#problems-due-to-oauth-token-caching
|
|
602
|
+
if (isSdkError(error) && error.statusCode === STATUS_CODES.UNAUTHORIZED) {
|
|
603
|
+
return sendRequest({
|
|
604
|
+
shouldRenewToken: true
|
|
605
|
+
});
|
|
553
606
|
}
|
|
554
607
|
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
var uri = _filterInstanceProperty(_context2 = [action.payload.mcApiProxyTarget && "/proxy/".concat(action.payload.mcApiProxyTarget), actionToUri(action, projectKey)]).call(_context2, Boolean).join(''); // This `requestName` is never really used.
|
|
558
|
-
//
|
|
559
|
-
// We keep track of requests which are in progress in the `loading` state of
|
|
560
|
-
// the application. The `loading` state is an array of strings
|
|
561
|
-
// (which are correlation Ids, action types or request names).
|
|
562
|
-
// This is just done so that debugging is easier.
|
|
563
|
-
//
|
|
564
|
-
// It's easier to debug
|
|
565
|
-
// loading: ['PRODUCTS_FETCHED', 'sdk.fetch(/product-projection-search)']
|
|
566
|
-
// than to debug
|
|
567
|
-
// loading: 2
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
var requestName = _concatInstanceProperty(_context3 = "sdk.".concat(action.payload.method.toLowerCase(), "(")).call(_context3, uri, ")"); // NOTE here the middleware is aware of the application
|
|
571
|
-
// Instead we should probably convert to a middleware factory
|
|
572
|
-
// and provide hooks for `onFetch`, `onResult` and `onError
|
|
573
|
-
|
|
574
|
-
|
|
608
|
+
throw error;
|
|
609
|
+
}).then(result => {
|
|
575
610
|
dispatch({
|
|
576
|
-
type:
|
|
611
|
+
type: HIDE_LOADING,
|
|
577
612
|
payload: requestName
|
|
578
|
-
}); //
|
|
579
|
-
//
|
|
580
|
-
//
|
|
581
|
-
//
|
|
582
|
-
// https://github.com/commercetools/merchant-center-frontend/pull/3304
|
|
583
|
-
// https://github.com/commercetools/nodejs/issues/390
|
|
584
|
-
|
|
585
|
-
var sendRequest = function sendRequest() {
|
|
586
|
-
var _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
587
|
-
shouldRenewToken = _ref3.shouldRenewToken;
|
|
588
|
-
|
|
589
|
-
var additionalHeaders = getAdditionalHeaders();
|
|
590
|
-
|
|
591
|
-
var headers = _objectSpread(_objectSpread(_objectSpread(_objectSpread({
|
|
592
|
-
Accept: 'application/json'
|
|
593
|
-
}, action.payload.headers || {}), shouldRenewToken ? {
|
|
594
|
-
'X-Force-Token': 'true'
|
|
595
|
-
} : {}), projectKey && {
|
|
596
|
-
'X-Project-Key': projectKey
|
|
597
|
-
}), additionalHeaders !== null && additionalHeaders !== void 0 ? additionalHeaders : {});
|
|
598
|
-
|
|
599
|
-
var body = action.payload.method === 'POST' ? action.payload.payload : undefined;
|
|
600
|
-
return client.execute({
|
|
601
|
-
uri: uri,
|
|
602
|
-
method: action.payload.method,
|
|
603
|
-
headers: headers,
|
|
604
|
-
body: body
|
|
605
|
-
}).then(function (result) {
|
|
606
|
-
if (process.env.NODE_ENV === 'development') logRequest({
|
|
607
|
-
method: action.payload.method,
|
|
608
|
-
request: {
|
|
609
|
-
headers: headers,
|
|
610
|
-
uri: uri
|
|
611
|
-
},
|
|
612
|
-
response: result.body,
|
|
613
|
-
action: action
|
|
614
|
-
});
|
|
615
|
-
return result;
|
|
616
|
-
}, function (error) {
|
|
617
|
-
if (process.env.NODE_ENV === 'development') logRequest({
|
|
618
|
-
method: action.payload.method,
|
|
619
|
-
request: {
|
|
620
|
-
headers: headers,
|
|
621
|
-
uri: uri
|
|
622
|
-
},
|
|
623
|
-
error: error,
|
|
624
|
-
action: action
|
|
625
|
-
});
|
|
626
|
-
throw error;
|
|
627
|
-
});
|
|
628
|
-
};
|
|
629
|
-
|
|
630
|
-
return sendRequest().catch(function (error) {
|
|
631
|
-
// in case of 401 error, try again with a new token
|
|
632
|
-
// https://github.com/commercetools/merchant-center-backend/blob/master/docs/AUTHENTICATION.md#problems-due-to-oauth-token-caching
|
|
633
|
-
if (isSdkError(error) && error.statusCode === STATUS_CODES.UNAUTHORIZED) {
|
|
634
|
-
return sendRequest({
|
|
635
|
-
shouldRenewToken: true
|
|
636
|
-
});
|
|
637
|
-
}
|
|
613
|
+
}); // The promise returned by "fetch" will reject when the request fails,
|
|
614
|
+
// but only in certain cases. See "Checking that the fetch was successful"
|
|
615
|
+
// in https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
|
|
616
|
+
// The SDK already handles this case for us.
|
|
638
617
|
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
}); // The promise returned by "fetch" will reject when the request fails,
|
|
645
|
-
// but only in certain cases. See "Checking that the fetch was successful"
|
|
646
|
-
// in https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch
|
|
647
|
-
// The SDK already handles this case for us.
|
|
648
|
-
|
|
649
|
-
return result.body;
|
|
650
|
-
}, function (error) {
|
|
651
|
-
dispatch({
|
|
652
|
-
type: HIDE_LOADING,
|
|
653
|
-
payload: requestName
|
|
654
|
-
});
|
|
655
|
-
throw error;
|
|
618
|
+
return result.body;
|
|
619
|
+
}, error => {
|
|
620
|
+
dispatch({
|
|
621
|
+
type: HIDE_LOADING,
|
|
622
|
+
payload: requestName
|
|
656
623
|
});
|
|
657
|
-
|
|
624
|
+
throw error;
|
|
625
|
+
});
|
|
658
626
|
};
|
|
659
627
|
};
|
|
660
628
|
|
|
@@ -664,11 +632,11 @@ function createSdkMiddleware(_ref) {
|
|
|
664
632
|
// Wraps `dispatch` and cast the return type to a Promise, as the middleware
|
|
665
633
|
// returns a Promise.
|
|
666
634
|
function useAsyncDispatch() {
|
|
667
|
-
|
|
635
|
+
const dispatch = useDispatch();
|
|
668
636
|
return dispatch;
|
|
669
637
|
}
|
|
670
638
|
|
|
671
|
-
|
|
639
|
+
const Sdk = {
|
|
672
640
|
Get: SdkGet$1
|
|
673
641
|
};
|
|
674
642
|
|