@commercetools-frontend/application-shell-connectors 22.30.2 → 22.31.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 +45 -62
- package/dist/commercetools-frontend-application-shell-connectors.cjs.prod.js +42 -58
- package/dist/commercetools-frontend-application-shell-connectors.esm.js +45 -61
- package/dist/declarations/src/components/application-context/application-context.d.ts +10 -0
- package/dist/declarations/src/components/application-context/normalizers.d.ts +18 -0
- package/dist/declarations/src/types/generated/mc.d.ts +5 -0
- package/dist/declarations/src/types/generated/settings.d.ts +22 -0
- package/dist/declarations/src/utils/http-client.d.ts +76 -0
- package/package.json +5 -5
|
@@ -16,7 +16,6 @@ var react = require('react');
|
|
|
16
16
|
var moment = require('moment-timezone');
|
|
17
17
|
var sentry = require('@commercetools-frontend/sentry');
|
|
18
18
|
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
19
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
20
19
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
21
20
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
22
21
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
@@ -62,7 +61,6 @@ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defin
|
|
|
62
61
|
var _pt__default = /*#__PURE__*/_interopDefault(_pt);
|
|
63
62
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
64
63
|
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
65
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
66
64
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
67
65
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
68
66
|
var _valuesInstanceProperty__default = /*#__PURE__*/_interopDefault(_valuesInstanceProperty);
|
|
@@ -81,7 +79,7 @@ var _Reflect$construct__default = /*#__PURE__*/_interopDefault(_Reflect$construc
|
|
|
81
79
|
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
82
80
|
|
|
83
81
|
// NOTE: This string will be replaced on build time with the package version.
|
|
84
|
-
var version = "22.
|
|
82
|
+
var version = "22.31.0";
|
|
85
83
|
|
|
86
84
|
// From https://github.com/acdlite/recompose/blob/master/src/packages/recompose/getDisplayName.js
|
|
87
85
|
const getDisplayName = Component => {
|
|
@@ -103,10 +101,9 @@ const getMcOriginTld = host => {
|
|
|
103
101
|
return host.replace(mcHostnameRegex, '$3');
|
|
104
102
|
};
|
|
105
103
|
const getMcApiUrlFromOrigin = origin => {
|
|
106
|
-
var _context;
|
|
107
104
|
const url = new _URL__default["default"](origin);
|
|
108
105
|
const originTld = getMcOriginTld(url.host);
|
|
109
|
-
return
|
|
106
|
+
return `${url.protocol}//mc-api.${originTld}`;
|
|
110
107
|
};
|
|
111
108
|
const parseAsBoolean = value => value === true || value === 'true';
|
|
112
109
|
function getMcApiUrl() {
|
|
@@ -338,9 +335,9 @@ const createApplicationContext = (environment, user, project, projectDataLocale)
|
|
|
338
335
|
environment: mapEnvironmentToApplicationContextEnvironment(environment),
|
|
339
336
|
user: mapUserToApplicationContextUser(user),
|
|
340
337
|
project: mapProjectToApplicationContextProject(project),
|
|
341
|
-
permissions: normalizeAllAppliedPermissions(project
|
|
342
|
-
actionRights: normalizeAllAppliedActionRights(project
|
|
343
|
-
dataFences: normalizeAllAppliedDataFences(project
|
|
338
|
+
permissions: normalizeAllAppliedPermissions(project?.allAppliedPermissions),
|
|
339
|
+
actionRights: normalizeAllAppliedActionRights(project?.allAppliedActionRights),
|
|
340
|
+
dataFences: normalizeAllAppliedDataFences(project?.allAppliedDataFences),
|
|
344
341
|
dataLocale: projectDataLocale || null
|
|
345
342
|
});
|
|
346
343
|
const ApplicationContextProvider = props => jsxRuntime.jsx(Context$2.Provider, {
|
|
@@ -376,7 +373,7 @@ function withApplicationContext(mapApplicationContextToProps) {
|
|
|
376
373
|
return jsxRuntime.jsx(Component, _objectSpread$6(_objectSpread$6({}, props), mappedProps));
|
|
377
374
|
}
|
|
378
375
|
});
|
|
379
|
-
WrappedComponent.displayName =
|
|
376
|
+
WrappedComponent.displayName = `withApplicationContext(${getDisplayName(Component)})`;
|
|
380
377
|
return WrappedComponent;
|
|
381
378
|
};
|
|
382
379
|
}
|
|
@@ -485,7 +482,7 @@ ProjectExtensionProviderForImageRegex.propTypes = process.env.NODE_ENV !== "prod
|
|
|
485
482
|
} : {};
|
|
486
483
|
ProjectExtensionProviderForImageRegex.displayName = 'ProjectExtensionProviderForImageRegex';
|
|
487
484
|
const GetProjectExtensionImageRegex = props => {
|
|
488
|
-
useWarning(false,
|
|
485
|
+
useWarning(false, `@commercetools-frontend/application-shell-connectors: It is not recommended to use the 'GetProjectExtensionImageRegex' anymore. Please use the 'useProjectExtensionImageRegex' hook instead.`);
|
|
489
486
|
return jsxRuntime.jsx(Context.Consumer, {
|
|
490
487
|
children: imageRegexContext => props.render(imageRegexContext)
|
|
491
488
|
});
|
|
@@ -498,7 +495,7 @@ function withProjectExtensionImageRegex() {
|
|
|
498
495
|
let propKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'imageRegexData';
|
|
499
496
|
return Component => {
|
|
500
497
|
const WrappedComponent = props => {
|
|
501
|
-
useWarning(false,
|
|
498
|
+
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.`);
|
|
502
499
|
const imageregexContext = useProjectExtensionImageRegex();
|
|
503
500
|
return jsxRuntime.jsx(GetProjectExtensionImageRegex, {
|
|
504
501
|
render: () => jsxRuntime.jsx(Component, _objectSpread$4(_objectSpread$4({}, props), {}, {
|
|
@@ -506,7 +503,7 @@ function withProjectExtensionImageRegex() {
|
|
|
506
503
|
}))
|
|
507
504
|
});
|
|
508
505
|
};
|
|
509
|
-
WrappedComponent.displayName =
|
|
506
|
+
WrappedComponent.displayName = `withProjectExtensionImageRegex(${getDisplayName(Component)})`;
|
|
510
507
|
return WrappedComponent;
|
|
511
508
|
};
|
|
512
509
|
}
|
|
@@ -527,8 +524,8 @@ const forwardTokenRetryHeader = headers => _objectSpread$3(_objectSpread$3({}, h
|
|
|
527
524
|
// so that the MC BE can issue a new token.
|
|
528
525
|
// NOTE: the retry is not meant to work for the MC access token.
|
|
529
526
|
const getDoesGraphQLTargetSupportTokenRetry = context => {
|
|
530
|
-
var _context
|
|
531
|
-
const graphQLTarget =
|
|
527
|
+
var _context;
|
|
528
|
+
const graphQLTarget = context.headers?.[constants.SUPPORTED_HEADERS.X_GRAPHQL_TARGET] || context.headers?.[constants.SUPPORTED_HEADERS.X_GRAPHQL_TARGET.toLowerCase()];
|
|
532
529
|
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));
|
|
533
530
|
};
|
|
534
531
|
const isHttpError = error => error.statusCode !== undefined || error.statusCode !== undefined;
|
|
@@ -542,7 +539,7 @@ const errorLink = error.onError(_ref => {
|
|
|
542
539
|
operation = _ref.operation,
|
|
543
540
|
forward = _ref.forward;
|
|
544
541
|
if (networkError && isHttpError(networkError) && networkError.statusCode === constants.STATUS_CODES.UNAUTHORIZED) {
|
|
545
|
-
history__default["default"].push(
|
|
542
|
+
history__default["default"].push(`/logout?reason=${constants.LOGOUT_REASONS.UNAUTHORIZED}`);
|
|
546
543
|
return;
|
|
547
544
|
}
|
|
548
545
|
|
|
@@ -554,8 +551,7 @@ const errorLink = error.onError(_ref => {
|
|
|
554
551
|
if (graphQLErrors && isGraphQLError(graphQLErrors)) {
|
|
555
552
|
const context = operation.getContext();
|
|
556
553
|
for (const err of graphQLErrors) {
|
|
557
|
-
|
|
558
|
-
const isNonAuthenticatedViaExtensionCode = (err === null || err === void 0 || (_err$extensions = err.extensions) === null || _err$extensions === void 0 ? void 0 : _err$extensions.code) === 'UNAUTHENTICATED';
|
|
554
|
+
const isNonAuthenticatedViaExtensionCode = err?.extensions?.code === 'UNAUTHENTICATED';
|
|
559
555
|
/**
|
|
560
556
|
* NOTE:
|
|
561
557
|
* Not not all GraphQL APIs expose an `extensions` field in
|
|
@@ -563,7 +559,7 @@ const errorLink = error.onError(_ref => {
|
|
|
563
559
|
* property until they introduced support for the `extensions`
|
|
564
560
|
* field.
|
|
565
561
|
*/
|
|
566
|
-
const isNonAuthenticatedViaCode =
|
|
562
|
+
const isNonAuthenticatedViaCode = err?.message === 'invalid_token';
|
|
567
563
|
if ((isNonAuthenticatedViaExtensionCode || isNonAuthenticatedViaCode) && getDoesGraphQLTargetSupportTokenRetry(context) && !getSkipTokenRetry(context)) {
|
|
568
564
|
operation.setContext(_ref2 => {
|
|
569
565
|
let headers = _ref2.headers;
|
|
@@ -581,8 +577,7 @@ const errorLink = error.onError(_ref => {
|
|
|
581
577
|
|
|
582
578
|
// Attempt to load the `teamId` from sessionStorage
|
|
583
579
|
function selectTeamIdFromStorage() {
|
|
584
|
-
|
|
585
|
-
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);
|
|
580
|
+
return window.sessionStorage.getItem(constants.STORAGE_KEYS.ACTIVE_TEAM_ID) || window.app.__DEVELOPMENT__?.oidc?.teamId;
|
|
586
581
|
}
|
|
587
582
|
|
|
588
583
|
const staticUrlPathsInPositionOfProjectKey = ['login', 'logout', 'account'];
|
|
@@ -643,7 +638,7 @@ function getCorrelationId() {
|
|
|
643
638
|
|
|
644
639
|
const createApolloContextForProxyForwardTo = proxyForwardTocontext => ({
|
|
645
640
|
// Send the request to the forward-to endpoint.
|
|
646
|
-
uri:
|
|
641
|
+
uri: `${getMcApiUrl()}/proxy/forward-to`,
|
|
647
642
|
// Custom properties to be used by the "header-link".
|
|
648
643
|
forwardToConfig: proxyForwardTocontext,
|
|
649
644
|
skipGraphQlTargetCheck: true
|
|
@@ -680,7 +675,7 @@ const logger = {
|
|
|
680
675
|
const getSessionToken = () => window.sessionStorage.getItem(constants.STORAGE_KEYS.SESSION_TOKEN);
|
|
681
676
|
const setActiveSession = sessionToken => {
|
|
682
677
|
if (!sessionToken) return;
|
|
683
|
-
window.sessionStorage.setItem(constants.STORAGE_KEYS.SESSION_TOKEN, sessionToken
|
|
678
|
+
window.sessionStorage.setItem(constants.STORAGE_KEYS.SESSION_TOKEN, sessionToken ?? '');
|
|
684
679
|
window.localStorage.setItem(constants.STORAGE_KEYS.LOGIN_STRATEGY, constants.LOGIN_STRATEGY_OIDC);
|
|
685
680
|
// Remove flag for original workflow
|
|
686
681
|
window.localStorage.removeItem(constants.STORAGE_KEYS.IS_AUTHENTICATED);
|
|
@@ -702,8 +697,7 @@ const setSessionScope = scope => {
|
|
|
702
697
|
window.sessionStorage.setItem(constants.STORAGE_KEYS.SESSION_SCOPE, scope);
|
|
703
698
|
};
|
|
704
699
|
const getSessionState = stateId => {
|
|
705
|
-
|
|
706
|
-
const sessionStateKey = _concatInstanceProperty__default["default"](_context = "".concat(constants.STORAGE_KEYS.NONCE, "_")).call(_context, stateId);
|
|
700
|
+
const sessionStateKey = `${constants.STORAGE_KEYS.NONCE}_${stateId}`;
|
|
707
701
|
const unparsedSessionState = window.sessionStorage.getItem(sessionStateKey);
|
|
708
702
|
if (unparsedSessionState) {
|
|
709
703
|
try {
|
|
@@ -711,22 +705,19 @@ const getSessionState = stateId => {
|
|
|
711
705
|
return parsedSessionState;
|
|
712
706
|
} catch (error) {
|
|
713
707
|
if (process.env.NODE_ENV !== 'production') {
|
|
714
|
-
var _context2;
|
|
715
708
|
// eslint-disable-next-line no-console
|
|
716
|
-
console.warn(
|
|
709
|
+
console.warn(`Cannot parse session state for "${sessionStateKey}".\n${unparsedSessionState}`);
|
|
717
710
|
}
|
|
718
711
|
}
|
|
719
712
|
}
|
|
720
713
|
return null;
|
|
721
714
|
};
|
|
722
715
|
const setSessionState = (stateId, state) => {
|
|
723
|
-
|
|
724
|
-
const sessionStateKey = _concatInstanceProperty__default["default"](_context3 = "".concat(constants.STORAGE_KEYS.NONCE, "_")).call(_context3, stateId);
|
|
716
|
+
const sessionStateKey = `${constants.STORAGE_KEYS.NONCE}_${stateId}`;
|
|
725
717
|
window.sessionStorage.setItem(sessionStateKey, _JSON$stringify__default["default"](state));
|
|
726
718
|
};
|
|
727
719
|
const removeSessionState = stateId => {
|
|
728
|
-
|
|
729
|
-
const sessionStateKey = _concatInstanceProperty__default["default"](_context4 = "".concat(constants.STORAGE_KEYS.NONCE, "_")).call(_context4, stateId);
|
|
720
|
+
const sessionStateKey = `${constants.STORAGE_KEYS.NONCE}_${stateId}`;
|
|
730
721
|
window.sessionStorage.removeItem(sessionStateKey);
|
|
731
722
|
};
|
|
732
723
|
|
|
@@ -748,7 +739,7 @@ var oidcStorage = /*#__PURE__*/Object.freeze({
|
|
|
748
739
|
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); }; }
|
|
749
740
|
function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(_Reflect$construct__default["default"](Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function () { return !!t; })(); }
|
|
750
741
|
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; }
|
|
751
|
-
function _objectSpread$2(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
742
|
+
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; }
|
|
752
743
|
const defaultUserAgent = createHttpUserAgent__default["default"]({
|
|
753
744
|
name: 'unknown-http-client',
|
|
754
745
|
libraryName: typeof window !== 'undefined' ? window.app.applicationName : 'unknown-application-name'
|
|
@@ -756,50 +747,48 @@ const defaultUserAgent = createHttpUserAgent__default["default"]({
|
|
|
756
747
|
const defaultForwardToVersion = 'v2';
|
|
757
748
|
const defaultForwardToAudiencePolicy = 'forward-url-full-path';
|
|
758
749
|
function buildApiUrl(endpoint) {
|
|
759
|
-
var _context;
|
|
760
750
|
const apiUrl = getMcApiUrl().replace(/\/$/, '');
|
|
761
|
-
return
|
|
751
|
+
return `${apiUrl}${endpoint}`;
|
|
762
752
|
}
|
|
763
753
|
const getAppliedForwardToHeaders = forwardToConfig => {
|
|
764
|
-
var
|
|
754
|
+
var _context;
|
|
765
755
|
if (!forwardToConfig) {
|
|
766
756
|
return {};
|
|
767
757
|
}
|
|
768
758
|
if (!forwardToConfig.uri) {
|
|
769
|
-
throw new Error(
|
|
759
|
+
throw new Error(`Missing required "uri" option.`);
|
|
770
760
|
}
|
|
771
761
|
const exchangeTokenClaims = [];
|
|
772
762
|
if (forwardToConfig.includeUserPermissions) {
|
|
773
763
|
exchangeTokenClaims.push('permissions');
|
|
774
764
|
}
|
|
775
|
-
return _objectSpread$2(_objectSpread$2({}, _reduceInstanceProperty__default["default"](
|
|
765
|
+
return _objectSpread$2(_objectSpread$2({}, _reduceInstanceProperty__default["default"](_context = _Object$entries__default["default"](forwardToConfig.headers ?? {})).call(_context, (customForwardHeaders, _ref) => {
|
|
776
766
|
let _ref2 = _slicedToArray(_ref, 2),
|
|
777
767
|
headerName = _ref2[0],
|
|
778
768
|
headerValue = _ref2[1];
|
|
779
769
|
return _objectSpread$2(_objectSpread$2({}, customForwardHeaders), {}, {
|
|
780
770
|
// Prefix headers so that the MC API can allow and forward them.
|
|
781
|
-
[
|
|
771
|
+
[`x-forward-header-${headerName}`]: headerValue
|
|
782
772
|
});
|
|
783
773
|
}, {})), {}, {
|
|
784
|
-
[constants.SUPPORTED_HEADERS.ACCEPT_VERSION]:
|
|
774
|
+
[constants.SUPPORTED_HEADERS.ACCEPT_VERSION]: forwardToConfig.version ?? defaultForwardToVersion,
|
|
785
775
|
[constants.SUPPORTED_HEADERS.X_FORWARD_TO]: forwardToConfig.uri,
|
|
786
|
-
[constants.SUPPORTED_HEADERS.X_FORWARD_TO_AUDIENCE_POLICY]:
|
|
776
|
+
[constants.SUPPORTED_HEADERS.X_FORWARD_TO_AUDIENCE_POLICY]: forwardToConfig.audiencePolicy ?? defaultForwardToAudiencePolicy,
|
|
787
777
|
[constants.SUPPORTED_HEADERS.X_FORWARD_TO_CLAIMS]: exchangeTokenClaims.join(' ')
|
|
788
778
|
});
|
|
789
779
|
};
|
|
790
780
|
function createHttpClientOptions() {
|
|
791
|
-
var _config$projectKey;
|
|
792
781
|
let config = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
793
782
|
const sessionToken = getSessionToken();
|
|
794
|
-
const projectKey =
|
|
783
|
+
const projectKey = config.projectKey ?? selectProjectKeyFromUrl();
|
|
795
784
|
const userId = selectUserId();
|
|
796
|
-
const userAgent =
|
|
785
|
+
const userAgent = config?.userAgent || defaultUserAgent;
|
|
797
786
|
return {
|
|
798
787
|
credentials: 'include',
|
|
799
788
|
headers: omitEmpty__default["default"](_objectSpread$2(_objectSpread$2({}, config.headers), {}, {
|
|
800
789
|
// Required headers
|
|
801
790
|
[constants.SUPPORTED_HEADERS.ACCEPT]: 'application/json',
|
|
802
|
-
[constants.SUPPORTED_HEADERS.AUTHORIZATION]: sessionToken ?
|
|
791
|
+
[constants.SUPPORTED_HEADERS.AUTHORIZATION]: sessionToken ? `Bearer ${sessionToken}` : undefined,
|
|
803
792
|
[constants.SUPPORTED_HEADERS.X_APPLICATION_ID]: window.app.applicationIdentifier,
|
|
804
793
|
[constants.SUPPORTED_HEADERS.X_CUSTOM_VIEW_ID]: window.app.customViewId,
|
|
805
794
|
[constants.SUPPORTED_HEADERS.X_CORRELATION_ID]: getCorrelationId({
|
|
@@ -838,7 +827,7 @@ async function executeHttpClientRequest(fetcher) {
|
|
|
838
827
|
}))
|
|
839
828
|
}));
|
|
840
829
|
if (response.statusCode === constants.STATUS_CODES.UNAUTHORIZED) {
|
|
841
|
-
throw new RenewTokenError(
|
|
830
|
+
throw new RenewTokenError(`Unauthorized response, attempting retry.`);
|
|
842
831
|
}
|
|
843
832
|
|
|
844
833
|
// In case a new session token is returned from the server, save it.
|
|
@@ -862,7 +851,7 @@ async function executeHttpClientRequest(fetcher) {
|
|
|
862
851
|
}
|
|
863
852
|
|
|
864
853
|
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; }
|
|
865
|
-
function _objectSpread$1(e) { for (var r = 1; r < arguments.length; r++) { var
|
|
854
|
+
function _objectSpread$1(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$1(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$1(Object(t))).call(_context4, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
866
855
|
const userAgent = createHttpUserAgent__default["default"]({
|
|
867
856
|
name: 'apollo-client',
|
|
868
857
|
// version: apolloVersion,
|
|
@@ -877,18 +866,13 @@ const isKnownGraphQlTarget = target => {
|
|
|
877
866
|
return target ? _includesInstanceProperty__default["default"](_context = _Object$values__default["default"](constants.GRAPHQL_TARGETS)).call(_context, target) : false;
|
|
878
867
|
};
|
|
879
868
|
const extractSessionTokenFromResponse = context => {
|
|
880
|
-
|
|
881
|
-
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');
|
|
869
|
+
const refreshedSessionToken = context.response?.headers?.get('x-refreshed-session-token');
|
|
882
870
|
if (refreshedSessionToken) {
|
|
883
|
-
return refreshedSessionToken
|
|
871
|
+
return refreshedSessionToken ?? null;
|
|
884
872
|
}
|
|
885
|
-
const restResponseWithRefreshTokenHeader =
|
|
886
|
-
var _response$headers;
|
|
887
|
-
return (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.has('x-refreshed-session-token');
|
|
888
|
-
});
|
|
873
|
+
const restResponseWithRefreshTokenHeader = context.restResponses?.find(response => response.headers?.has('x-refreshed-session-token'));
|
|
889
874
|
if (restResponseWithRefreshTokenHeader) {
|
|
890
|
-
|
|
891
|
-
return (_restResponseWithRefr = restResponseWithRefreshTokenHeader.headers.get('x-refreshed-session-token')) !== null && _restResponseWithRefr !== void 0 ? _restResponseWithRefr : null;
|
|
875
|
+
return restResponseWithRefreshTokenHeader.headers.get('x-refreshed-session-token') ?? null;
|
|
892
876
|
}
|
|
893
877
|
return null;
|
|
894
878
|
};
|
|
@@ -896,11 +880,11 @@ const extractSessionTokenFromResponse = context => {
|
|
|
896
880
|
/* eslint-disable import/prefer-default-export */
|
|
897
881
|
// Use a middleware to update the request headers with the correct params.
|
|
898
882
|
const headerLink = new client.ApolloLink((operation, forward) => {
|
|
899
|
-
var _context2
|
|
883
|
+
var _context2;
|
|
900
884
|
const apolloContext = operation.getContext();
|
|
901
885
|
const variables = operation.variables;
|
|
902
886
|
const graphQlTarget = apolloContext.target || variables.target;
|
|
903
|
-
if (!apolloContext.skipGraphQlTargetCheck && !isKnownGraphQlTarget(graphQlTarget)) throw new Error(
|
|
887
|
+
if (!apolloContext.skipGraphQlTargetCheck && !isKnownGraphQlTarget(graphQlTarget)) throw new Error(`GraphQL target "${graphQlTarget}" is missing (or is not supported) in operation "${operation.operationName}"`);
|
|
904
888
|
|
|
905
889
|
/**
|
|
906
890
|
* NOTE:
|
|
@@ -927,7 +911,7 @@ const headerLink = new client.ApolloLink((operation, forward) => {
|
|
|
927
911
|
forwardToConfig: apolloContext.forwardToConfig,
|
|
928
912
|
projectKey
|
|
929
913
|
}));
|
|
930
|
-
return _mapInstanceProperty__default["default"](
|
|
914
|
+
return _mapInstanceProperty__default["default"](_context2 = forward(operation)).call(_context2, response => {
|
|
931
915
|
const context = operation.getContext();
|
|
932
916
|
const refreshedSessionToken = extractSessionTokenFromResponse(context);
|
|
933
917
|
if (refreshedSessionToken) {
|
|
@@ -940,7 +924,7 @@ const headerLink = new client.ApolloLink((operation, forward) => {
|
|
|
940
924
|
const tokenRetryLink = new retry.RetryLink({
|
|
941
925
|
attempts: (count, operation, error) => {
|
|
942
926
|
const context = operation.getContext();
|
|
943
|
-
if (
|
|
927
|
+
if (error?.statusCode === constants.STATUS_CODES.UNAUTHORIZED && count === 1 && getDoesGraphQLTargetSupportTokenRetry(context) && !getSkipTokenRetry(context)) {
|
|
944
928
|
operation.setContext(_ref => {
|
|
945
929
|
let headers = _ref.headers;
|
|
946
930
|
return {
|
|
@@ -958,7 +942,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _co
|
|
|
958
942
|
const createApolloLink = function () {
|
|
959
943
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
960
944
|
const httpLink = client.createHttpLink({
|
|
961
|
-
uri:
|
|
945
|
+
uri: `${getMcApiUrl()}/graphql`,
|
|
962
946
|
fetch
|
|
963
947
|
});
|
|
964
948
|
|
|
@@ -1002,9 +986,8 @@ const mergeArraysObjects = function () {
|
|
|
1002
986
|
}, []);
|
|
1003
987
|
};
|
|
1004
988
|
const createApolloClient = function () {
|
|
1005
|
-
var _options$cache, _customCacheConfig$ty;
|
|
1006
989
|
let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
1007
|
-
const customCacheConfig =
|
|
990
|
+
const customCacheConfig = options?.cache ?? {};
|
|
1008
991
|
return new client.ApolloClient({
|
|
1009
992
|
link: createApolloLink(options),
|
|
1010
993
|
// https://www.apollographql.com/docs/react/caching/cache-configuration/
|
|
@@ -1043,7 +1026,7 @@ const createApolloClient = function () {
|
|
|
1043
1026
|
}
|
|
1044
1027
|
}
|
|
1045
1028
|
}
|
|
1046
|
-
},
|
|
1029
|
+
}, customCacheConfig.typePolicies ?? {})
|
|
1047
1030
|
}))
|
|
1048
1031
|
});
|
|
1049
1032
|
};
|