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