@commercetools-frontend/application-shell-connectors 22.8.4 → 22.10.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-application-shell-connectors.cjs.dev.js +618 -36
- package/dist/commercetools-frontend-application-shell-connectors.cjs.prod.js +612 -36
- package/dist/commercetools-frontend-application-shell-connectors.esm.js +590 -37
- package/dist/declarations/src/apollo-links/error-link.d.ts +2 -0
- package/dist/declarations/src/apollo-links/header-link.d.ts +3 -0
- package/dist/declarations/src/apollo-links/index.d.ts +4 -0
- package/dist/declarations/src/apollo-links/token-retry-link.d.ts +3 -0
- package/dist/declarations/src/apollo-links/utils.d.ts +10 -0
- package/dist/declarations/src/configure-apollo.d.ts +7 -0
- package/dist/declarations/src/export-types.d.ts +9 -0
- package/dist/declarations/src/hooks/apollo-hooks/apollo-hooks.d.ts +12 -0
- package/dist/declarations/src/hooks/apollo-hooks/index.d.ts +1 -0
- package/dist/declarations/src/index.d.ts +6 -1
- package/dist/declarations/src/types/generated/settings.d.ts +223 -29
- package/dist/declarations/src/utils/apollo-client-runtime-cache.d.ts +4 -0
- package/dist/declarations/src/utils/apollo-context.d.ts +15 -0
- package/dist/declarations/src/utils/get-correlation-id/get-correlation-id.d.ts +3 -0
- package/dist/declarations/src/utils/get-correlation-id/index.d.ts +1 -0
- package/dist/declarations/src/utils/http-client.d.ts +31 -0
- package/dist/declarations/src/utils/index.d.ts +7 -0
- package/dist/declarations/src/utils/logger.d.ts +10 -0
- package/dist/declarations/src/utils/oidc-storage.d.ts +11 -0
- package/dist/declarations/src/utils/select-project-key-from-url/index.d.ts +1 -0
- package/dist/declarations/src/utils/select-project-key-from-url/select-project-key-from-url.d.ts +1 -0
- package/dist/declarations/src/utils/select-team-id-from-storage/index.d.ts +1 -0
- package/dist/declarations/src/utils/select-team-id-from-storage/select-team-id-from-storage.d.ts +1 -0
- package/dist/declarations/src/utils/select-user-id/index.d.ts +1 -0
- package/dist/declarations/src/utils/select-user-id/select-user-id.d.ts +1 -0
- package/package.json +13 -4
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
6
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
7
5
|
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
8
6
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
9
7
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
@@ -17,6 +15,8 @@ require('prop-types');
|
|
|
17
15
|
var react = require('react');
|
|
18
16
|
var moment = require('moment-timezone');
|
|
19
17
|
var sentry = require('@commercetools-frontend/sentry');
|
|
18
|
+
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
19
|
+
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
20
20
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
21
21
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
22
22
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
@@ -25,11 +25,32 @@ var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
|
25
25
|
var react$1 = require('@apollo/client/react');
|
|
26
26
|
require('tiny-warning');
|
|
27
27
|
var constants = require('@commercetools-frontend/constants');
|
|
28
|
+
var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
|
|
29
|
+
var client = require('@apollo/client');
|
|
30
|
+
var loggerLink = require('apollo-link-logger');
|
|
31
|
+
var error = require('@apollo/client/link/error');
|
|
32
|
+
var history = require('@commercetools-frontend/browser-history');
|
|
33
|
+
var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
|
|
34
|
+
var _Array$isArray = require('@babel/runtime-corejs3/core-js-stable/array/is-array');
|
|
35
|
+
var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
|
|
36
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
37
|
+
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
38
|
+
var createHttpUserAgent = require('@commercetools/http-user-agent');
|
|
39
|
+
var omitEmpty = require('omit-empty-es');
|
|
40
|
+
var uuid = require('uuid');
|
|
41
|
+
var _Reflect$construct = require('@babel/runtime-corejs3/core-js-stable/reflect/construct');
|
|
42
|
+
var _createClass = require('@babel/runtime-corejs3/helpers/createClass');
|
|
43
|
+
var _classCallCheck = require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
44
|
+
var _assertThisInitialized = require('@babel/runtime-corejs3/helpers/assertThisInitialized');
|
|
45
|
+
var _inherits = require('@babel/runtime-corejs3/helpers/inherits');
|
|
46
|
+
var _possibleConstructorReturn = require('@babel/runtime-corejs3/helpers/possibleConstructorReturn');
|
|
47
|
+
var _getPrototypeOf = require('@babel/runtime-corejs3/helpers/getPrototypeOf');
|
|
48
|
+
var _wrapNativeSuper = require('@babel/runtime-corejs3/helpers/wrapNativeSuper');
|
|
49
|
+
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
50
|
+
var retry = require('@apollo/client/link/retry');
|
|
28
51
|
|
|
29
52
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
30
53
|
|
|
31
|
-
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
32
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
33
54
|
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
34
55
|
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
35
56
|
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
@@ -39,12 +60,37 @@ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_O
|
|
|
39
60
|
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
40
61
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
41
62
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
63
|
+
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
64
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
42
65
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
43
66
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
44
67
|
var _valuesInstanceProperty__default = /*#__PURE__*/_interopDefault(_valuesInstanceProperty);
|
|
68
|
+
var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
|
|
69
|
+
var loggerLink__default = /*#__PURE__*/_interopDefault(loggerLink);
|
|
70
|
+
var history__default = /*#__PURE__*/_interopDefault(history);
|
|
71
|
+
var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
|
|
72
|
+
var _Array$isArray__default = /*#__PURE__*/_interopDefault(_Array$isArray);
|
|
73
|
+
var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
|
|
74
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
75
|
+
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
76
|
+
var createHttpUserAgent__default = /*#__PURE__*/_interopDefault(createHttpUserAgent);
|
|
77
|
+
var omitEmpty__default = /*#__PURE__*/_interopDefault(omitEmpty);
|
|
78
|
+
var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construct);
|
|
79
|
+
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
45
80
|
|
|
46
81
|
// NOTE: This string will be replaced on build time with the package version.
|
|
47
|
-
var version = "22.
|
|
82
|
+
var version = "22.10.0";
|
|
83
|
+
|
|
84
|
+
// From https://github.com/acdlite/recompose/blob/master/src/packages/recompose/getDisplayName.js
|
|
85
|
+
const getDisplayName = Component => {
|
|
86
|
+
if (typeof Component === 'string') {
|
|
87
|
+
return Component;
|
|
88
|
+
}
|
|
89
|
+
if (!Component) {
|
|
90
|
+
return undefined;
|
|
91
|
+
}
|
|
92
|
+
return Component.displayName || Component.name || 'Component';
|
|
93
|
+
};
|
|
48
94
|
|
|
49
95
|
const mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
50
96
|
const mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
|
|
@@ -78,19 +124,8 @@ function getMcApiUrl() {
|
|
|
78
124
|
return environment.mcApiUrl;
|
|
79
125
|
}
|
|
80
126
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (typeof Component === 'string') {
|
|
84
|
-
return Component;
|
|
85
|
-
}
|
|
86
|
-
if (!Component) {
|
|
87
|
-
return undefined;
|
|
88
|
-
}
|
|
89
|
-
return Component.displayName || Component.name || 'Component';
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
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; }
|
|
93
|
-
function _objectSpread$2(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$2(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$2(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
127
|
+
function ownKeys$6(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; }
|
|
128
|
+
function _objectSpread$6(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$6(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$6(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
94
129
|
// Menu visibilities
|
|
95
130
|
|
|
96
131
|
// Permissions
|
|
@@ -123,7 +158,7 @@ const normalizeAllAppliedPermissions = allAppliedPermissions => {
|
|
|
123
158
|
}
|
|
124
159
|
return _reduceInstanceProperty__default["default"](allAppliedPermissions).call(allAppliedPermissions, (transformedAllApplied, allApplied) => {
|
|
125
160
|
if (!allApplied) return transformedAllApplied;
|
|
126
|
-
return _objectSpread$
|
|
161
|
+
return _objectSpread$6(_objectSpread$6({}, transformedAllApplied), {}, {
|
|
127
162
|
[allApplied.name]: allApplied.value
|
|
128
163
|
});
|
|
129
164
|
}, {});
|
|
@@ -134,7 +169,7 @@ const normalizeAllAppliedMenuVisibilities = allAppliedMenuVisibilities => {
|
|
|
134
169
|
}
|
|
135
170
|
return _reduceInstanceProperty__default["default"](allAppliedMenuVisibilities).call(allAppliedMenuVisibilities, (transformedAllApplied, allApplied) => {
|
|
136
171
|
if (!allApplied) return transformedAllApplied;
|
|
137
|
-
return _objectSpread$
|
|
172
|
+
return _objectSpread$6(_objectSpread$6({}, transformedAllApplied), {}, {
|
|
138
173
|
[allApplied.name]: allApplied.value
|
|
139
174
|
});
|
|
140
175
|
}, {});
|
|
@@ -146,8 +181,8 @@ const normalizeAllAppliedActionRights = allAppliedActionRights => {
|
|
|
146
181
|
return _reduceInstanceProperty__default["default"](allAppliedActionRights).call(allAppliedActionRights, (transformedAllApplied, allApplied) => {
|
|
147
182
|
if (!allApplied) return transformedAllApplied;
|
|
148
183
|
const previousAllAppliedGroup = transformedAllApplied[allApplied.group];
|
|
149
|
-
return _objectSpread$
|
|
150
|
-
[allApplied.group]: _objectSpread$
|
|
184
|
+
return _objectSpread$6(_objectSpread$6({}, transformedAllApplied), {}, {
|
|
185
|
+
[allApplied.group]: _objectSpread$6(_objectSpread$6({}, previousAllAppliedGroup), {}, {
|
|
151
186
|
[allApplied.name]: allApplied.value
|
|
152
187
|
})
|
|
153
188
|
});
|
|
@@ -158,7 +193,7 @@ const normalizeAppliedDataFencesForStoresByResourceType = dataFences => {
|
|
|
158
193
|
const groupedByResourceType = _reduceInstanceProperty__default["default"](dataFences).call(dataFences, (previousGroupsOfSameType, appliedDataFence) => {
|
|
159
194
|
if (!appliedDataFence) return previousGroupsOfSameType;
|
|
160
195
|
const previousGroup = previousGroupsOfSameType[appliedDataFence.group];
|
|
161
|
-
return _objectSpread$
|
|
196
|
+
return _objectSpread$6(_objectSpread$6({}, previousGroupsOfSameType), {}, {
|
|
162
197
|
[appliedDataFence.group]: [...(previousGroup || []), appliedDataFence]
|
|
163
198
|
});
|
|
164
199
|
}, {});
|
|
@@ -170,13 +205,13 @@ const normalizeAppliedDataFencesForStoresByResourceType = dataFences => {
|
|
|
170
205
|
const dataFenceByName = nextDataFenceValues[dataFence.name] || {
|
|
171
206
|
values: []
|
|
172
207
|
};
|
|
173
|
-
return _objectSpread$
|
|
174
|
-
[dataFence.name]: _objectSpread$
|
|
208
|
+
return _objectSpread$6(_objectSpread$6({}, nextDataFenceValues), {}, {
|
|
209
|
+
[dataFence.name]: _objectSpread$6(_objectSpread$6({}, dataFenceByName), {}, {
|
|
175
210
|
values: [..._valuesInstanceProperty__default["default"](dataFenceByName), dataFence.value]
|
|
176
211
|
})
|
|
177
212
|
});
|
|
178
213
|
}, {});
|
|
179
|
-
return _objectSpread$
|
|
214
|
+
return _objectSpread$6(_objectSpread$6({}, previousGroupedByResourceType), {}, {
|
|
180
215
|
[resourceType]: groupByDataFenceName
|
|
181
216
|
});
|
|
182
217
|
}, {});
|
|
@@ -220,19 +255,19 @@ const normalizeAllAppliedDataFences = allAppliedDataFences => {
|
|
|
220
255
|
const groupedByType = _reduceInstanceProperty__default["default"](allAppliedDataFences).call(allAppliedDataFences, (previousGroupsOfSameType, appliedDataFence) => {
|
|
221
256
|
if (!appliedDataFence) return previousGroupsOfSameType;
|
|
222
257
|
const previousGroup = previousGroupsOfSameType[appliedDataFence.type];
|
|
223
|
-
return _objectSpread$
|
|
258
|
+
return _objectSpread$6(_objectSpread$6({}, previousGroupsOfSameType), {}, {
|
|
224
259
|
[appliedDataFence.type]: [...(previousGroup || []), appliedDataFence]
|
|
225
260
|
});
|
|
226
261
|
}, {});
|
|
227
|
-
const normalizedDataFences = _objectSpread$
|
|
262
|
+
const normalizedDataFences = _objectSpread$6({}, 'store' in groupedByType ? {
|
|
228
263
|
store: normalizeAppliedDataFencesForStoresByResourceType(groupedByType.store)
|
|
229
264
|
} : {});
|
|
230
265
|
if (_Object$keys__default["default"](normalizedDataFences).length > 0) return normalizedDataFences;
|
|
231
266
|
return null;
|
|
232
267
|
};
|
|
233
268
|
|
|
234
|
-
function ownKeys$
|
|
235
|
-
function _objectSpread$
|
|
269
|
+
function ownKeys$5(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; }
|
|
270
|
+
function _objectSpread$5(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$5(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$5(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
236
271
|
const Context$2 = /*#__PURE__*/react.createContext({});
|
|
237
272
|
const defaultTimeZone = moment__default["default"].tz.guess() || 'Etc/UTC';
|
|
238
273
|
|
|
@@ -266,7 +301,7 @@ const mapUserToApplicationContextUser = user => {
|
|
|
266
301
|
}
|
|
267
302
|
});
|
|
268
303
|
}
|
|
269
|
-
applicationContextUser.idTokenUserInfo = _objectSpread$
|
|
304
|
+
applicationContextUser.idTokenUserInfo = _objectSpread$5(_objectSpread$5({}, user.idTokenUserInfo), {}, {
|
|
270
305
|
additionalClaims
|
|
271
306
|
});
|
|
272
307
|
}
|
|
@@ -274,7 +309,7 @@ const mapUserToApplicationContextUser = user => {
|
|
|
274
309
|
};
|
|
275
310
|
|
|
276
311
|
// Adjust certain fields which depend e.g. on the origin
|
|
277
|
-
const mapEnvironmentToApplicationContextEnvironment = (environment, origin) => _objectSpread$
|
|
312
|
+
const mapEnvironmentToApplicationContextEnvironment = (environment, origin) => _objectSpread$5(_objectSpread$5({}, environment), {}, {
|
|
278
313
|
// NOTE: The `mcApiUrl` depends on `servedByProxy`
|
|
279
314
|
mcApiUrl: getMcApiUrl(environment, origin)
|
|
280
315
|
});
|
|
@@ -329,7 +364,7 @@ function withApplicationContext(mapApplicationContextToProps) {
|
|
|
329
364
|
const mappedProps = mapApplicationContextToProps ? mapApplicationContextToProps(applicationContext) : {
|
|
330
365
|
applicationContext
|
|
331
366
|
};
|
|
332
|
-
return jsxRuntime.jsx(Component, _objectSpread$
|
|
367
|
+
return jsxRuntime.jsx(Component, _objectSpread$5(_objectSpread$5({}, props), mappedProps));
|
|
333
368
|
}
|
|
334
369
|
});
|
|
335
370
|
WrappedComponent.displayName = "withApplicationContext(".concat(getDisplayName(Component), ")");
|
|
@@ -388,8 +423,8 @@ function useCustomViewContextHook(selector) {
|
|
|
388
423
|
// See related issue: https://github.com/babel/babel/issues/8361
|
|
389
424
|
const useCustomViewContext = useCustomViewContextHook;
|
|
390
425
|
|
|
391
|
-
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; }
|
|
392
|
-
function _objectSpread(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(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(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
426
|
+
function ownKeys$4(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; }
|
|
427
|
+
function _objectSpread$4(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$4(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$4(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
393
428
|
var FetchProjectExtensionImageRegex = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchProjectExtensionImageRegex" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "projectExtension" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "imageRegex" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "thumb" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "FragmentSpread", name: { kind: "Name", value: "ImageRegex" }, directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "small" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "FragmentSpread", name: { kind: "Name", value: "ImageRegex" }, directives: [] }] } }] } }] } }] } }, { kind: "FragmentDefinition", name: { kind: "Name", value: "ImageRegex" }, typeCondition: { kind: "NamedType", name: { kind: "Name", value: "ImageRegexOptions" } }, directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "flag" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "search" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "replace" }, arguments: [], directives: [] }] } }], loc: { start: 0, end: 256, source: { body: "query FetchProjectExtensionImageRegex {\n projectExtension {\n id\n imageRegex {\n thumb {\n ...ImageRegex\n }\n small {\n ...ImageRegex\n }\n }\n }\n}\nfragment ImageRegex on ImageRegexOptions {\n flag\n search\n replace\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
394
429
|
const useWarning = (condition, message) => {
|
|
395
430
|
react.useEffect(() => {
|
|
@@ -443,7 +478,7 @@ function withProjectExtensionImageRegex() {
|
|
|
443
478
|
useWarning();
|
|
444
479
|
const imageregexContext = useProjectExtensionImageRegex();
|
|
445
480
|
return jsxRuntime.jsx(GetProjectExtensionImageRegex, {
|
|
446
|
-
render: () => jsxRuntime.jsx(Component, _objectSpread(_objectSpread({}, props), {}, {
|
|
481
|
+
render: () => jsxRuntime.jsx(Component, _objectSpread$4(_objectSpread$4({}, props), {}, {
|
|
447
482
|
[propKey]: imageregexContext
|
|
448
483
|
}))
|
|
449
484
|
});
|
|
@@ -453,19 +488,560 @@ function withProjectExtensionImageRegex() {
|
|
|
453
488
|
};
|
|
454
489
|
}
|
|
455
490
|
|
|
491
|
+
function ownKeys$3(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; }
|
|
492
|
+
function _objectSpread$3(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$3(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$3(Object(t))).call(_context3, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
493
|
+
const getSkipTokenRetry = context => {
|
|
494
|
+
const skipTokenRetry = Boolean(context.skipTokenRetry);
|
|
495
|
+
return skipTokenRetry;
|
|
496
|
+
};
|
|
497
|
+
const forwardTokenRetryHeader = headers => _objectSpread$3(_objectSpread$3({}, headers), {}, {
|
|
498
|
+
[constants.SUPPORTED_HEADERS.X_TOKEN_RETRY]: 'true'
|
|
499
|
+
});
|
|
500
|
+
|
|
501
|
+
// This link retries requests to the CTP API that have been rejected
|
|
502
|
+
// because of an invalid/expired oauth token.
|
|
503
|
+
// To do so, we resend the request with the header "X-Force-Token: true"
|
|
504
|
+
// so that the MC BE can issue a new token.
|
|
505
|
+
// NOTE: the retry is not meant to work for the MC access token.
|
|
506
|
+
const getDoesGraphQLTargetSupportTokenRetry = context => {
|
|
507
|
+
var _context$headers, _context$headers2, _context;
|
|
508
|
+
const graphQLTarget = ((_context$headers = context.headers) === null || _context$headers === void 0 ? void 0 : _context$headers[constants.SUPPORTED_HEADERS.X_GRAPHQL_TARGET]) || ((_context$headers2 = context.headers) === null || _context$headers2 === void 0 ? void 0 : _context$headers2[constants.SUPPORTED_HEADERS.X_GRAPHQL_TARGET.toLowerCase()]);
|
|
509
|
+
return Boolean(graphQLTarget && _includesInstanceProperty__default["default"](_context = [constants.GRAPHQL_TARGETS.COMMERCETOOLS_PLATFORM, constants.GRAPHQL_TARGETS.ADMINISTRATION_SERVICE, constants.GRAPHQL_TARGETS.SETTINGS_SERVICE, constants.GRAPHQL_TARGETS.MERCHANT_CENTER_BACKEND]).call(_context, graphQLTarget));
|
|
510
|
+
};
|
|
511
|
+
const isHttpError = error => error.statusCode !== undefined || error.statusCode !== undefined;
|
|
512
|
+
const isGraphQLError = error => _Array$isArray__default["default"](error) && _someInstanceProperty__default["default"](error).call(error, err => err.message !== undefined || err.extensions !== undefined);
|
|
513
|
+
|
|
514
|
+
// Checks response from GraphQL in order to scan 401 errors and redirect the
|
|
515
|
+
// user to the login page resetting the store and showing the proper message
|
|
516
|
+
const errorLink = error.onError(_ref => {
|
|
517
|
+
let graphQLErrors = _ref.graphQLErrors,
|
|
518
|
+
networkError = _ref.networkError,
|
|
519
|
+
operation = _ref.operation,
|
|
520
|
+
forward = _ref.forward;
|
|
521
|
+
if (networkError && isHttpError(networkError) && networkError.statusCode === constants.STATUS_CODES.UNAUTHORIZED) {
|
|
522
|
+
history__default["default"].push("/logout?reason=".concat(constants.LOGOUT_REASONS.UNAUTHORIZED));
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
// In case of graphql errors, we want to retry unauthenticated requests by
|
|
527
|
+
// forcing our API to fetch a new token, using the `X-Force-Token` header.
|
|
528
|
+
// https://www.apollographql.com/docs/link/links/error/#retrying-failed-requests
|
|
529
|
+
// We need to do this as the `token-retry-link` only works for network errors.
|
|
530
|
+
// https://www.apollographql.com/docs/link/links/retry/
|
|
531
|
+
if (graphQLErrors && isGraphQLError(graphQLErrors)) {
|
|
532
|
+
const context = operation.getContext();
|
|
533
|
+
for (const err of graphQLErrors) {
|
|
534
|
+
var _err$extensions;
|
|
535
|
+
const isNonAuthenticatedViaExtensionCode = (err === null || err === void 0 || (_err$extensions = err.extensions) === null || _err$extensions === void 0 ? void 0 : _err$extensions.code) === 'UNAUTHENTICATED';
|
|
536
|
+
/**
|
|
537
|
+
* NOTE:
|
|
538
|
+
* Not not all GraphQL APIs expose an `extensions` field in
|
|
539
|
+
* each error. For those we have to use the `message`
|
|
540
|
+
* property until they introduced support for the `extensions`
|
|
541
|
+
* field.
|
|
542
|
+
*/
|
|
543
|
+
const isNonAuthenticatedViaCode = (err === null || err === void 0 ? void 0 : err.message) === 'invalid_token';
|
|
544
|
+
if ((isNonAuthenticatedViaExtensionCode || isNonAuthenticatedViaCode) && getDoesGraphQLTargetSupportTokenRetry(context) && !getSkipTokenRetry(context)) {
|
|
545
|
+
operation.setContext(_ref2 => {
|
|
546
|
+
let headers = _ref2.headers;
|
|
547
|
+
return {
|
|
548
|
+
headers: forwardTokenRetryHeader(headers)
|
|
549
|
+
};
|
|
550
|
+
});
|
|
551
|
+
// retry the request, returning the new observable
|
|
552
|
+
return forward(operation);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
return;
|
|
557
|
+
});
|
|
558
|
+
|
|
559
|
+
// Attempt to load the `teamId` from sessionStorage
|
|
560
|
+
function selectTeamIdFromStorage() {
|
|
561
|
+
var _window$app$__DEVELOP;
|
|
562
|
+
return window.sessionStorage.getItem(constants.STORAGE_KEYS.ACTIVE_TEAM_ID) || ((_window$app$__DEVELOP = window.app.__DEVELOPMENT__) === null || _window$app$__DEVELOP === void 0 || (_window$app$__DEVELOP = _window$app$__DEVELOP.oidc) === null || _window$app$__DEVELOP === void 0 ? void 0 : _window$app$__DEVELOP.teamId);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const staticUrlPathsInPositionOfProjectKey = ['login', 'logout', 'account'];
|
|
566
|
+
|
|
567
|
+
// Attempt to extract the `:projectKey` from the URL.
|
|
568
|
+
// If the value matches one of the values in the list above,
|
|
569
|
+
// return `undefined` as we're not within a project context.
|
|
570
|
+
function selectProjectKeyFromUrl() {
|
|
571
|
+
let locationPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.location.pathname;
|
|
572
|
+
let possibleProjectKey = '';
|
|
573
|
+
const pathParts = locationPath.split('/');
|
|
574
|
+
if (pathParts[1] === 'custom-views') {
|
|
575
|
+
// Custom Views paths: /custom-views/:customViewId/projects/:projectKey
|
|
576
|
+
possibleProjectKey = pathParts[4];
|
|
577
|
+
} else {
|
|
578
|
+
// Application paths: /:projectKey/:applicationId
|
|
579
|
+
possibleProjectKey = pathParts[1];
|
|
580
|
+
}
|
|
581
|
+
return _includesInstanceProperty__default["default"](staticUrlPathsInPositionOfProjectKey).call(staticUrlPathsInPositionOfProjectKey, possibleProjectKey) ? undefined : possibleProjectKey;
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// Keep an in-memory reference to the apollo client that would be initialized
|
|
585
|
+
// by the application. This is useful to retrieve on runtime the reference
|
|
586
|
+
// to the apollo client in other static modules.
|
|
587
|
+
let cachedApolloClient;
|
|
588
|
+
const setCachedApolloClient = apolloClient => {
|
|
589
|
+
cachedApolloClient = apolloClient;
|
|
590
|
+
};
|
|
591
|
+
const getCachedApolloClient = () => cachedApolloClient;
|
|
592
|
+
|
|
593
|
+
var FetchUserId = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchUserId" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", alias: { kind: "Name", value: "user" }, name: { kind: "Name", value: "me" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 46, source: { body: "query FetchUserId {\n user: me {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
594
|
+
function selectUserId() {
|
|
595
|
+
const apolloClient = getCachedApolloClient();
|
|
596
|
+
if (!apolloClient) {
|
|
597
|
+
return null;
|
|
598
|
+
}
|
|
599
|
+
try {
|
|
600
|
+
const queryResult = apolloClient.readQuery({
|
|
601
|
+
query: FetchUserId
|
|
602
|
+
});
|
|
603
|
+
if (queryResult && queryResult.user) {
|
|
604
|
+
return queryResult.user.id;
|
|
605
|
+
}
|
|
606
|
+
} catch (e) {
|
|
607
|
+
return null;
|
|
608
|
+
}
|
|
609
|
+
return null;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
const VALID_ID_PART_FORMAT = /^[\w-/]+$/;
|
|
613
|
+
const skipMalformedPart = part => part && VALID_ID_PART_FORMAT.test(part);
|
|
614
|
+
function getCorrelationId() {
|
|
615
|
+
var _context;
|
|
616
|
+
let _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
617
|
+
userId = _ref.userId;
|
|
618
|
+
return _filterInstanceProperty__default["default"](_context = ['mc', selectProjectKeyFromUrl(), userId, uuid.v4()]).call(_context, skipMalformedPart).join('/');
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
const createApolloContextForProxyForwardTo = proxyForwardTocontext => ({
|
|
622
|
+
// Send the request to the forward-to endpoint.
|
|
623
|
+
uri: "".concat(getMcApiUrl(), "/proxy/forward-to"),
|
|
624
|
+
// Custom properties to be used by the "header-link".
|
|
625
|
+
forwardToConfig: proxyForwardTocontext,
|
|
626
|
+
skipGraphQlTargetCheck: true
|
|
627
|
+
});
|
|
628
|
+
|
|
629
|
+
/* eslint-disable no-console */
|
|
630
|
+
|
|
631
|
+
const isLoggerEnabled = () => {
|
|
632
|
+
if (process.env.DEBUG === 'true') return true;
|
|
633
|
+
const queryParams = new _URL__default["default"](window.location.href);
|
|
634
|
+
if (queryParams.searchParams.get('debug') === 'true') return true;
|
|
635
|
+
return false;
|
|
636
|
+
};
|
|
637
|
+
const logger = {
|
|
638
|
+
groupCollapsed: function () {
|
|
639
|
+
return isLoggerEnabled() && console.groupCollapsed(...arguments);
|
|
640
|
+
},
|
|
641
|
+
groupEnd: () => isLoggerEnabled() && console.groupEnd(),
|
|
642
|
+
info: function () {
|
|
643
|
+
return isLoggerEnabled() && console.info(...arguments);
|
|
644
|
+
},
|
|
645
|
+
log: function () {
|
|
646
|
+
return isLoggerEnabled() && console.log(...arguments);
|
|
647
|
+
},
|
|
648
|
+
error: function () {
|
|
649
|
+
return isLoggerEnabled() && console.error(...arguments);
|
|
650
|
+
},
|
|
651
|
+
warn: function () {
|
|
652
|
+
return isLoggerEnabled() && console.warn(...arguments);
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
|
|
656
|
+
const getSessionToken = () => window.sessionStorage.getItem(constants.STORAGE_KEYS.SESSION_TOKEN);
|
|
657
|
+
const setActiveSession = sessionToken => {
|
|
658
|
+
if (!sessionToken) return;
|
|
659
|
+
window.sessionStorage.setItem(constants.STORAGE_KEYS.SESSION_TOKEN, sessionToken !== null && sessionToken !== void 0 ? sessionToken : '');
|
|
660
|
+
window.localStorage.setItem(constants.STORAGE_KEYS.LOGIN_STRATEGY, constants.LOGIN_STRATEGY_OIDC);
|
|
661
|
+
// Remove flag for original workflow
|
|
662
|
+
window.localStorage.removeItem(constants.STORAGE_KEYS.IS_AUTHENTICATED);
|
|
663
|
+
};
|
|
664
|
+
const clearSession = () => {
|
|
665
|
+
window.sessionStorage.removeItem(constants.STORAGE_KEYS.SESSION_TOKEN);
|
|
666
|
+
window.sessionStorage.removeItem(constants.STORAGE_KEYS.SESSION_SCOPE);
|
|
667
|
+
window.sessionStorage.removeItem(constants.STORAGE_KEYS.IS_AUTHENTICATED);
|
|
668
|
+
};
|
|
669
|
+
const getActiveProjectKey = () => window.localStorage.getItem(constants.STORAGE_KEYS.ACTIVE_PROJECT_KEY);
|
|
670
|
+
const removeActiveProjectKey = () => {
|
|
671
|
+
window.localStorage.removeItem(constants.STORAGE_KEYS.ACTIVE_PROJECT_KEY);
|
|
672
|
+
};
|
|
673
|
+
const setActiveProjectKey = projectKey => {
|
|
674
|
+
window.localStorage.setItem(constants.STORAGE_KEYS.ACTIVE_PROJECT_KEY, projectKey);
|
|
675
|
+
};
|
|
676
|
+
const getSessionScope = () => window.sessionStorage.getItem(constants.STORAGE_KEYS.SESSION_SCOPE);
|
|
677
|
+
const setSessionScope = scope => {
|
|
678
|
+
window.sessionStorage.setItem(constants.STORAGE_KEYS.SESSION_SCOPE, scope);
|
|
679
|
+
};
|
|
680
|
+
const getSessionState = stateId => {
|
|
681
|
+
var _context;
|
|
682
|
+
const sessionStateKey = _concatInstanceProperty__default["default"](_context = "".concat(constants.STORAGE_KEYS.NONCE, "_")).call(_context, stateId);
|
|
683
|
+
const unparsedSessionState = window.sessionStorage.getItem(sessionStateKey);
|
|
684
|
+
if (unparsedSessionState) {
|
|
685
|
+
try {
|
|
686
|
+
const parsedSessionState = JSON.parse(unparsedSessionState);
|
|
687
|
+
window.sessionStorage.removeItem(sessionStateKey);
|
|
688
|
+
return parsedSessionState;
|
|
689
|
+
} catch (error) {
|
|
690
|
+
window.sessionStorage.removeItem(sessionStateKey);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
return null;
|
|
694
|
+
};
|
|
695
|
+
const setSessionState = (stateId, state) => {
|
|
696
|
+
var _context3;
|
|
697
|
+
const sessionStateKey = _concatInstanceProperty__default["default"](_context3 = "".concat(constants.STORAGE_KEYS.NONCE, "_")).call(_context3, stateId);
|
|
698
|
+
window.sessionStorage.setItem(sessionStateKey, _JSON$stringify__default["default"](state));
|
|
699
|
+
};
|
|
700
|
+
|
|
701
|
+
var oidcStorage = /*#__PURE__*/Object.freeze({
|
|
702
|
+
__proto__: null,
|
|
703
|
+
getSessionToken: getSessionToken,
|
|
704
|
+
setActiveSession: setActiveSession,
|
|
705
|
+
clearSession: clearSession,
|
|
706
|
+
getSessionState: getSessionState,
|
|
707
|
+
setSessionState: setSessionState,
|
|
708
|
+
getActiveProjectKey: getActiveProjectKey,
|
|
709
|
+
setActiveProjectKey: setActiveProjectKey,
|
|
710
|
+
removeActiveProjectKey: removeActiveProjectKey,
|
|
711
|
+
getSessionScope: getSessionScope,
|
|
712
|
+
setSessionScope: setSessionScope
|
|
713
|
+
});
|
|
714
|
+
|
|
715
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = _Reflect$construct__default["default"](Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
716
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !_Reflect$construct__default["default"]) return false; if (_Reflect$construct__default["default"].sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
717
|
+
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; }
|
|
718
|
+
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var _context3, _context4; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context3 = ownKeys$2(Object(t), !0)).call(_context3, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context4 = ownKeys$2(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
719
|
+
const defaultUserAgent = createHttpUserAgent__default["default"]({
|
|
720
|
+
name: 'unknown-http-client',
|
|
721
|
+
libraryName: window.app.applicationName
|
|
722
|
+
});
|
|
723
|
+
const defaultForwardToVersion = 'v2';
|
|
724
|
+
const defaultForwardToAudiencePolicy = 'forward-url-full-path';
|
|
725
|
+
function buildApiUrl(endpoint) {
|
|
726
|
+
var _context;
|
|
727
|
+
const apiUrl = getMcApiUrl().replace(/\/$/, '');
|
|
728
|
+
return _concatInstanceProperty__default["default"](_context = "".concat(apiUrl)).call(_context, endpoint);
|
|
729
|
+
}
|
|
730
|
+
const getAppliedForwardToHeaders = forwardToConfig => {
|
|
731
|
+
var _context2, _forwardToConfig$head, _forwardToConfig$vers, _forwardToConfig$audi;
|
|
732
|
+
if (!forwardToConfig) {
|
|
733
|
+
return {};
|
|
734
|
+
}
|
|
735
|
+
if (!forwardToConfig.uri) {
|
|
736
|
+
throw new Error("Missing required \"uri\" option.");
|
|
737
|
+
}
|
|
738
|
+
const exchangeTokenClaims = [];
|
|
739
|
+
if (forwardToConfig.includeUserPermissions) {
|
|
740
|
+
exchangeTokenClaims.push('permissions');
|
|
741
|
+
}
|
|
742
|
+
return _objectSpread$2(_objectSpread$2({}, _reduceInstanceProperty__default["default"](_context2 = _Object$entries__default["default"]((_forwardToConfig$head = forwardToConfig.headers) !== null && _forwardToConfig$head !== void 0 ? _forwardToConfig$head : {})).call(_context2, (customForwardHeaders, _ref) => {
|
|
743
|
+
let _ref2 = _slicedToArray(_ref, 2),
|
|
744
|
+
headerName = _ref2[0],
|
|
745
|
+
headerValue = _ref2[1];
|
|
746
|
+
return _objectSpread$2(_objectSpread$2({}, customForwardHeaders), {}, {
|
|
747
|
+
// Prefix headers so that the MC API can allow and forward them.
|
|
748
|
+
["x-forward-header-".concat(headerName)]: headerValue
|
|
749
|
+
});
|
|
750
|
+
}, {})), {}, {
|
|
751
|
+
[constants.SUPPORTED_HEADERS.ACCEPT_VERSION]: (_forwardToConfig$vers = forwardToConfig.version) !== null && _forwardToConfig$vers !== void 0 ? _forwardToConfig$vers : defaultForwardToVersion,
|
|
752
|
+
[constants.SUPPORTED_HEADERS.X_FORWARD_TO]: forwardToConfig.uri,
|
|
753
|
+
[constants.SUPPORTED_HEADERS.X_FORWARD_TO_AUDIENCE_POLICY]: (_forwardToConfig$audi = forwardToConfig.audiencePolicy) !== null && _forwardToConfig$audi !== void 0 ? _forwardToConfig$audi : defaultForwardToAudiencePolicy,
|
|
754
|
+
[constants.SUPPORTED_HEADERS.X_FORWARD_TO_CLAIMS]: exchangeTokenClaims.join(' ')
|
|
755
|
+
});
|
|
756
|
+
};
|
|
757
|
+
function createHttpClientOptions() {
|
|
758
|
+
var _config$projectKey;
|
|
759
|
+
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
760
|
+
const sessionToken = getSessionToken();
|
|
761
|
+
const projectKey = (_config$projectKey = config.projectKey) !== null && _config$projectKey !== void 0 ? _config$projectKey : selectProjectKeyFromUrl();
|
|
762
|
+
const userId = selectUserId();
|
|
763
|
+
const userAgent = (config === null || config === void 0 ? void 0 : config.userAgent) || defaultUserAgent;
|
|
764
|
+
return {
|
|
765
|
+
credentials: 'include',
|
|
766
|
+
headers: omitEmpty__default["default"](_objectSpread$2(_objectSpread$2({}, config.headers), {}, {
|
|
767
|
+
// Required headers
|
|
768
|
+
[constants.SUPPORTED_HEADERS.ACCEPT]: 'application/json',
|
|
769
|
+
[constants.SUPPORTED_HEADERS.AUTHORIZATION]: sessionToken ? "Bearer ".concat(sessionToken) : undefined,
|
|
770
|
+
[constants.SUPPORTED_HEADERS.X_APPLICATION_ID]: window.app.applicationIdentifier,
|
|
771
|
+
[constants.SUPPORTED_HEADERS.X_CUSTOM_VIEW_ID]: window.app.customViewId,
|
|
772
|
+
[constants.SUPPORTED_HEADERS.X_CORRELATION_ID]: getCorrelationId({
|
|
773
|
+
userId
|
|
774
|
+
}),
|
|
775
|
+
[constants.SUPPORTED_HEADERS.X_PROJECT_KEY]: projectKey,
|
|
776
|
+
[constants.SUPPORTED_HEADERS.X_USER_AGENT]: userAgent
|
|
777
|
+
}, getAppliedForwardToHeaders(config.forwardToConfig)))
|
|
778
|
+
};
|
|
779
|
+
}
|
|
780
|
+
let RenewTokenError = /*#__PURE__*/function (_Error) {
|
|
781
|
+
_inherits(RenewTokenError, _Error);
|
|
782
|
+
var _super = _createSuper(RenewTokenError);
|
|
783
|
+
function RenewTokenError(message) {
|
|
784
|
+
var _this;
|
|
785
|
+
_classCallCheck(this, RenewTokenError);
|
|
786
|
+
_this = _super.call(this, message);
|
|
787
|
+
_Object$defineProperty__default["default"](_assertThisInitialized(_this), 'name', {
|
|
788
|
+
value: 'RenewTokenError'
|
|
789
|
+
});
|
|
790
|
+
return _this;
|
|
791
|
+
}
|
|
792
|
+
return _createClass(RenewTokenError);
|
|
793
|
+
}( /*#__PURE__*/_wrapNativeSuper(Error));
|
|
794
|
+
async function executeHttpClientRequest(fetcher) {
|
|
795
|
+
let config = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
796
|
+
// Wrapper function to be called again (once) on retry.
|
|
797
|
+
async function sendRequest() {
|
|
798
|
+
let _ref3 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
799
|
+
shouldRenewToken = _ref3.shouldRenewToken;
|
|
800
|
+
const requestOptions = createHttpClientOptions(config);
|
|
801
|
+
const response = await fetcher(_objectSpread$2(_objectSpread$2({}, requestOptions), {}, {
|
|
802
|
+
headers: omitEmpty__default["default"](_objectSpread$2(_objectSpread$2({}, requestOptions.headers), {}, {
|
|
803
|
+
// Passing this header forces a token renewal.
|
|
804
|
+
[constants.SUPPORTED_HEADERS.X_TOKEN_RETRY]: shouldRenewToken
|
|
805
|
+
}))
|
|
806
|
+
}));
|
|
807
|
+
if (response.statusCode === constants.STATUS_CODES.UNAUTHORIZED) {
|
|
808
|
+
throw new RenewTokenError("Unauthorized response, attempting retry.");
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// In case a new session token is returned from the server, save it.
|
|
812
|
+
const refreshedSessionToken = response.getHeader('x-refreshed-session-token');
|
|
813
|
+
if (refreshedSessionToken) {
|
|
814
|
+
setActiveSession(refreshedSessionToken);
|
|
815
|
+
}
|
|
816
|
+
return response.data;
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
// Attempt to send the request.
|
|
820
|
+
return sendRequest().catch(error => {
|
|
821
|
+
if (error instanceof RenewTokenError) {
|
|
822
|
+
// Retry the request and ask to renew the token.
|
|
823
|
+
return sendRequest({
|
|
824
|
+
shouldRenewToken: true
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
throw error;
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
function ownKeys$1(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; }
|
|
832
|
+
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var _context4, _context5; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context4 = ownKeys$1(Object(t), !0)).call(_context4, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context5 = ownKeys$1(Object(t))).call(_context5, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
833
|
+
const userAgent = createHttpUserAgent__default["default"]({
|
|
834
|
+
name: 'apollo-client',
|
|
835
|
+
// version: apolloVersion,
|
|
836
|
+
libraryName: [window.app.applicationName, 'application-shell'].join('/'),
|
|
837
|
+
libraryVersion: version,
|
|
838
|
+
contactUrl: 'https://git.io/fjuyC',
|
|
839
|
+
// points to the appkit repo issues
|
|
840
|
+
contactEmail: 'support@commercetools.com'
|
|
841
|
+
});
|
|
842
|
+
const isKnownGraphQlTarget = target => {
|
|
843
|
+
var _context;
|
|
844
|
+
return target ? _includesInstanceProperty__default["default"](_context = _Object$values__default["default"](constants.GRAPHQL_TARGETS)).call(_context, target) : false;
|
|
845
|
+
};
|
|
846
|
+
const extractSessionTokenFromResponse = context => {
|
|
847
|
+
var _context$response, _context$restResponse;
|
|
848
|
+
const refreshedSessionToken = (_context$response = context.response) === null || _context$response === void 0 || (_context$response = _context$response.headers) === null || _context$response === void 0 ? void 0 : _context$response.get('x-refreshed-session-token');
|
|
849
|
+
if (refreshedSessionToken) {
|
|
850
|
+
return refreshedSessionToken !== null && refreshedSessionToken !== void 0 ? refreshedSessionToken : null;
|
|
851
|
+
}
|
|
852
|
+
const restResponseWithRefreshTokenHeader = (_context$restResponse = context.restResponses) === null || _context$restResponse === void 0 ? void 0 : _findInstanceProperty__default["default"](_context$restResponse).call(_context$restResponse, response => {
|
|
853
|
+
var _response$headers;
|
|
854
|
+
return (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.has('x-refreshed-session-token');
|
|
855
|
+
});
|
|
856
|
+
if (restResponseWithRefreshTokenHeader) {
|
|
857
|
+
var _restResponseWithRefr;
|
|
858
|
+
return (_restResponseWithRefr = restResponseWithRefreshTokenHeader.headers.get('x-refreshed-session-token')) !== null && _restResponseWithRefr !== void 0 ? _restResponseWithRefr : null;
|
|
859
|
+
}
|
|
860
|
+
return null;
|
|
861
|
+
};
|
|
862
|
+
|
|
863
|
+
/* eslint-disable import/prefer-default-export */
|
|
864
|
+
// Use a middleware to update the request headers with the correct params.
|
|
865
|
+
const headerLink = new client.ApolloLink((operation, forward) => {
|
|
866
|
+
var _context2, _context3;
|
|
867
|
+
const apolloContext = operation.getContext();
|
|
868
|
+
const variables = operation.variables;
|
|
869
|
+
const graphQlTarget = apolloContext.target || variables.target;
|
|
870
|
+
if (!apolloContext.skipGraphQlTargetCheck && !isKnownGraphQlTarget(graphQlTarget)) throw new Error(_concatInstanceProperty__default["default"](_context2 = "GraphQL target \"".concat(graphQlTarget, "\" is missing (or is not supported) in operation \"")).call(_context2, operation.operationName, "\""));
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* NOTE:
|
|
874
|
+
* The project key is read from the url in a project related application context.
|
|
875
|
+
* This holds for most applications like `application-categories`, `application-discounts` etc.
|
|
876
|
+
* However, the `application-account` does not run with the project key being part of the url.
|
|
877
|
+
* As a result we allow passing the project key as a variable on the operation allowing
|
|
878
|
+
* it to be the fallback.
|
|
879
|
+
*/
|
|
880
|
+
const projectKey = apolloContext.projectKey || variables.projectKey || selectProjectKeyFromUrl();
|
|
881
|
+
const teamId = apolloContext.teamId || variables.teamId || selectTeamIdFromStorage();
|
|
882
|
+
const featureFlag = apolloContext.featureFlag || variables.featureFlag;
|
|
883
|
+
operation.setContext(createHttpClientOptions({
|
|
884
|
+
userAgent,
|
|
885
|
+
headers: omitEmpty__default["default"](_objectSpread$1(_objectSpread$1({}, apolloContext.headers), {}, {
|
|
886
|
+
// Required headers for GraphQL API.
|
|
887
|
+
[constants.SUPPORTED_HEADERS.X_GRAPHQL_TARGET]: graphQlTarget,
|
|
888
|
+
// For logging/debugging purposes.
|
|
889
|
+
[constants.SUPPORTED_HEADERS.X_GRAPHQL_OPERATION_NAME]: operation.operationName,
|
|
890
|
+
// Experimental features, use with caution.
|
|
891
|
+
[constants.SUPPORTED_HEADERS.X_TEAM_ID]: teamId,
|
|
892
|
+
[constants.SUPPORTED_HEADERS.X_FEATURE_FLAG]: featureFlag
|
|
893
|
+
})),
|
|
894
|
+
forwardToConfig: apolloContext.forwardToConfig,
|
|
895
|
+
projectKey
|
|
896
|
+
}));
|
|
897
|
+
return _mapInstanceProperty__default["default"](_context3 = forward(operation)).call(_context3, response => {
|
|
898
|
+
const context = operation.getContext();
|
|
899
|
+
const refreshedSessionToken = extractSessionTokenFromResponse(context);
|
|
900
|
+
if (refreshedSessionToken) {
|
|
901
|
+
setActiveSession(refreshedSessionToken);
|
|
902
|
+
}
|
|
903
|
+
return response;
|
|
904
|
+
});
|
|
905
|
+
});
|
|
906
|
+
|
|
907
|
+
const tokenRetryLink = new retry.RetryLink({
|
|
908
|
+
attempts: (count, operation, error) => {
|
|
909
|
+
const context = operation.getContext();
|
|
910
|
+
if ((error === null || error === void 0 ? void 0 : error.statusCode) === constants.STATUS_CODES.UNAUTHORIZED && count === 1 && getDoesGraphQLTargetSupportTokenRetry(context) && !getSkipTokenRetry(context)) {
|
|
911
|
+
operation.setContext(_ref => {
|
|
912
|
+
let headers = _ref.headers;
|
|
913
|
+
return {
|
|
914
|
+
headers: forwardTokenRetryHeader(headers)
|
|
915
|
+
};
|
|
916
|
+
});
|
|
917
|
+
return true;
|
|
918
|
+
}
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
});
|
|
922
|
+
|
|
923
|
+
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; }
|
|
924
|
+
function _objectSpread(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(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(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
925
|
+
const httpLink = client.createHttpLink({
|
|
926
|
+
uri: "".concat(getMcApiUrl(), "/graphql"),
|
|
927
|
+
fetch
|
|
928
|
+
});
|
|
929
|
+
const createApolloLink = function () {
|
|
930
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
931
|
+
return (
|
|
932
|
+
// The order of links is IMPORTANT!
|
|
933
|
+
// In the request-phase they are executed top to bottom.
|
|
934
|
+
// In the response/phase they are executed bottom to top.
|
|
935
|
+
// The `httpLink` is terminating so it must be last, while `tokenRetryLink` and `errorLink`
|
|
936
|
+
// wrap the links the their right.
|
|
937
|
+
client.from([headerLink,
|
|
938
|
+
// See https://www.apollographql.com/docs/react/api/link/apollo-link-rest/#link-order
|
|
939
|
+
// State & context links should happen before (to the left of) `restLink`.
|
|
940
|
+
...(options.restLink ? [options.restLink] : []),
|
|
941
|
+
// Must be before `tokenRetryLink`.
|
|
942
|
+
errorLink,
|
|
943
|
+
// Avoid logging queries in test environment
|
|
944
|
+
...(isLoggerEnabled() ? [loggerLink__default["default"]] : []),
|
|
945
|
+
// Must be after `errorLink`.
|
|
946
|
+
tokenRetryLink,
|
|
947
|
+
// Must be last.
|
|
948
|
+
httpLink])
|
|
949
|
+
);
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
// This custom merge function allows to merge two arrays of objects.
|
|
953
|
+
// The incoming list is what we need to update to, but we still need
|
|
954
|
+
// to ensure that existing cache elements are not removed but updated.
|
|
955
|
+
// This is usually the case when elements get removed.
|
|
956
|
+
const mergeArraysObjects = function () {
|
|
957
|
+
let existing = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
958
|
+
let incoming = arguments.length > 1 ? arguments[1] : undefined;
|
|
959
|
+
let _ref = arguments.length > 2 ? arguments[2] : undefined,
|
|
960
|
+
mergeObjects = _ref.mergeObjects;
|
|
961
|
+
return _reduceInstanceProperty__default["default"](incoming).call(incoming, (mergedElements, elem) => {
|
|
962
|
+
const existingElem = _findInstanceProperty__default["default"](existing).call(existing, el => el.__ref === elem.__ref);
|
|
963
|
+
if (existingElem) {
|
|
964
|
+
const updatedElem = mergeObjects(existingElem, elem);
|
|
965
|
+
if (updatedElem) {
|
|
966
|
+
return [...mergedElements, updatedElem];
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
return [...mergedElements, elem];
|
|
970
|
+
}, []);
|
|
971
|
+
};
|
|
972
|
+
const createApolloClient = function () {
|
|
973
|
+
var _options$cache, _customCacheConfig$ty;
|
|
974
|
+
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
975
|
+
const customCacheConfig = (_options$cache = options === null || options === void 0 ? void 0 : options.cache) !== null && _options$cache !== void 0 ? _options$cache : {};
|
|
976
|
+
return new client.ApolloClient({
|
|
977
|
+
link: createApolloLink(options),
|
|
978
|
+
// https://www.apollographql.com/docs/react/caching/cache-configuration/
|
|
979
|
+
cache: new client.InMemoryCache(_objectSpread(_objectSpread({}, customCacheConfig), {}, {
|
|
980
|
+
// https://www.apollographql.com/docs/react/caching/cache-configuration/#generating-unique-identifiers
|
|
981
|
+
typePolicies: _objectSpread({
|
|
982
|
+
// CTP types with `key` as identifier
|
|
983
|
+
Project: {
|
|
984
|
+
keyFields: ['key']
|
|
985
|
+
},
|
|
986
|
+
Store: {
|
|
987
|
+
keyFields: ['key']
|
|
988
|
+
},
|
|
989
|
+
// Internal apps menu links representations
|
|
990
|
+
ApplicationsMenu: {
|
|
991
|
+
fields: {
|
|
992
|
+
appBar: {
|
|
993
|
+
merge: mergeArraysObjects
|
|
994
|
+
},
|
|
995
|
+
navBar: {
|
|
996
|
+
merge: mergeArraysObjects
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
}, (_customCacheConfig$ty = customCacheConfig.typePolicies) !== null && _customCacheConfig$ty !== void 0 ? _customCacheConfig$ty : {})
|
|
1001
|
+
}))
|
|
1002
|
+
});
|
|
1003
|
+
};
|
|
1004
|
+
|
|
1005
|
+
function useMcQuery(query, options) {
|
|
1006
|
+
return react$1.useQuery(query, options);
|
|
1007
|
+
}
|
|
1008
|
+
function useMcLazyQuery(query, options) {
|
|
1009
|
+
return react$1.useLazyQuery(query, options);
|
|
1010
|
+
}
|
|
1011
|
+
function useMcMutation(mutation, options) {
|
|
1012
|
+
return react$1.useMutation(mutation, options);
|
|
1013
|
+
}
|
|
1014
|
+
|
|
456
1015
|
exports.ApplicationContext = ApplicationContext;
|
|
457
1016
|
exports.ApplicationContextProvider = ApplicationContextProvider;
|
|
458
1017
|
exports.Context = Context$2;
|
|
459
1018
|
exports.CustomViewContextProvider = CustomViewContextProvider;
|
|
460
1019
|
exports.GetProjectExtensionImageRegex = GetProjectExtensionImageRegex;
|
|
461
1020
|
exports.ProjectExtensionProviderForImageRegex = ProjectExtensionProviderForImageRegex;
|
|
1021
|
+
exports.buildApiUrl = buildApiUrl;
|
|
1022
|
+
exports.createApolloClient = createApolloClient;
|
|
1023
|
+
exports.createApolloContextForProxyForwardTo = createApolloContextForProxyForwardTo;
|
|
1024
|
+
exports.createHttpClientOptions = createHttpClientOptions;
|
|
1025
|
+
exports.executeHttpClientRequest = executeHttpClientRequest;
|
|
1026
|
+
exports.getCachedApolloClient = getCachedApolloClient;
|
|
1027
|
+
exports.getCorrelationId = getCorrelationId;
|
|
462
1028
|
exports.getMcApiUrl = getMcApiUrl;
|
|
1029
|
+
exports.isLoggerEnabled = isLoggerEnabled;
|
|
1030
|
+
exports.logger = logger;
|
|
463
1031
|
exports.normalizeAllAppliedActionRights = normalizeAllAppliedActionRights;
|
|
464
1032
|
exports.normalizeAllAppliedDataFences = normalizeAllAppliedDataFences;
|
|
465
1033
|
exports.normalizeAllAppliedMenuVisibilities = normalizeAllAppliedMenuVisibilities;
|
|
466
1034
|
exports.normalizeAllAppliedPermissions = normalizeAllAppliedPermissions;
|
|
1035
|
+
exports.oidcStorage = oidcStorage;
|
|
1036
|
+
exports.selectProjectKeyFromUrl = selectProjectKeyFromUrl;
|
|
1037
|
+
exports.selectTeamIdFromStorage = selectTeamIdFromStorage;
|
|
1038
|
+
exports.selectUserId = selectUserId;
|
|
1039
|
+
exports.setCachedApolloClient = setCachedApolloClient;
|
|
467
1040
|
exports.useApplicationContext = useApplicationContext;
|
|
468
1041
|
exports.useCustomViewContext = useCustomViewContext;
|
|
1042
|
+
exports.useMcLazyQuery = useMcLazyQuery;
|
|
1043
|
+
exports.useMcMutation = useMcMutation;
|
|
1044
|
+
exports.useMcQuery = useMcQuery;
|
|
469
1045
|
exports.useProjectExtensionImageRegex = useProjectExtensionImageRegex;
|
|
470
1046
|
exports.version = version;
|
|
471
1047
|
exports.withApplicationContext = withApplicationContext;
|