@commercetools-frontend/application-shell-connectors 21.9.0 → 21.12.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 +49 -47
- package/dist/commercetools-frontend-application-shell-connectors.cjs.prod.js +49 -47
- package/dist/commercetools-frontend-application-shell-connectors.esm.js +47 -46
- package/dist/declarations/src/components/application-context/application-context.d.ts +1 -1
- package/dist/declarations/src/index.d.ts +1 -0
- package/dist/declarations/src/utils/get-mc-api-url/get-mc-api-url.d.ts +1 -3
- package/package.json +3 -3
|
@@ -2,6 +2,8 @@
|
|
|
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');
|
|
5
7
|
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
6
8
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
7
9
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
@@ -17,10 +19,8 @@ var moment = require('moment-timezone');
|
|
|
17
19
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
18
20
|
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
19
21
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
20
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
21
22
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
22
23
|
var _valuesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/values');
|
|
23
|
-
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
24
24
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
25
25
|
var warning = require('tiny-warning');
|
|
26
26
|
var react$1 = require('@apollo/client/react');
|
|
@@ -29,6 +29,8 @@ var sentry = require('@commercetools-frontend/sentry');
|
|
|
29
29
|
|
|
30
30
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
31
31
|
|
|
32
|
+
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
33
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
32
34
|
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
33
35
|
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
34
36
|
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
@@ -40,14 +42,53 @@ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defin
|
|
|
40
42
|
var _pt__default = /*#__PURE__*/_interopDefault(_pt);
|
|
41
43
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
42
44
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
43
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
44
45
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
45
46
|
var _valuesInstanceProperty__default = /*#__PURE__*/_interopDefault(_valuesInstanceProperty);
|
|
46
|
-
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
47
47
|
var warning__default = /*#__PURE__*/_interopDefault(warning);
|
|
48
48
|
|
|
49
49
|
// NOTE: This string will be replaced on build time with the package version.
|
|
50
|
-
var version = "21.
|
|
50
|
+
var version = "21.12.0";
|
|
51
|
+
|
|
52
|
+
var mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
53
|
+
var mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
|
|
54
|
+
|
|
55
|
+
var getMcOriginTld = function getMcOriginTld(host) {
|
|
56
|
+
if (host.match(mcPreviewHostnameRegex)) {
|
|
57
|
+
return host.replace(mcPreviewHostnameRegex, '$1');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return host.replace(mcHostnameRegex, '$3');
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(origin) {
|
|
64
|
+
var _context;
|
|
65
|
+
|
|
66
|
+
var url = new _URL__default["default"](origin);
|
|
67
|
+
var originTld = getMcOriginTld(url.host);
|
|
68
|
+
return _concatInstanceProperty__default["default"](_context = "".concat(url.protocol, "//mc-api.")).call(_context, originTld);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
var parseAsBoolean = function parseAsBoolean(value) {
|
|
72
|
+
return value === true || value === 'true';
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function getMcApiUrl() {
|
|
76
|
+
var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.app;
|
|
77
|
+
var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.origin;
|
|
78
|
+
var isServedByProxy = parseAsBoolean(environment.servedByProxy);
|
|
79
|
+
/**
|
|
80
|
+
* Prefer using the origin URL for the MC API based on the origin value
|
|
81
|
+
* of the browser's `window.location`.
|
|
82
|
+
* This ensures that the application always uses the correct URL associated
|
|
83
|
+
* with that environment, instead of relying on the config value.
|
|
84
|
+
*/
|
|
85
|
+
|
|
86
|
+
if (isServedByProxy) {
|
|
87
|
+
return getMcApiUrlFromOrigin(origin);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return environment.mcApiUrl;
|
|
91
|
+
}
|
|
51
92
|
|
|
52
93
|
// From https://github.com/acdlite/recompose/blob/master/src/packages/recompose/getDisplayName.js
|
|
53
94
|
var getDisplayName = function getDisplayName(Component) {
|
|
@@ -202,45 +243,6 @@ var normalizeAllAppliedDataFences = function normalizeAllAppliedDataFences(allAp
|
|
|
202
243
|
return null;
|
|
203
244
|
};
|
|
204
245
|
|
|
205
|
-
var removeMcPrefix = function removeMcPrefix(host) {
|
|
206
|
-
return host.replace(/^mc(-(\d){4,})?\.(.*)$/, '$3');
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* NOTE:
|
|
210
|
-
* Given the Merchant Center or Custom Application runs behind the proxy
|
|
211
|
-
* then the `mcApiUrl` should be build using the origin on the window.
|
|
212
|
-
*
|
|
213
|
-
* This allows the Merchant Center (or any Custom Appliction) to automatically
|
|
214
|
-
* use an `mcApiUrl` which matches the respective url of the deployment.
|
|
215
|
-
*
|
|
216
|
-
* This is particularily useful with the new and old hostnames for the Merchant Center.
|
|
217
|
-
* When using the origin, it will be made sure that the authorization cookie will
|
|
218
|
-
* always be sent as the appropriate API url is used.
|
|
219
|
-
*
|
|
220
|
-
* 1. MC: mc.commercetools.com with API: mc-api.europe-west1.gcp.commercetools.com
|
|
221
|
-
* -> Will not work as urls differ
|
|
222
|
-
* 2. MC: mc.europe-west1.gcp.commercetools.com with API: mc-api.commercetools.com
|
|
223
|
-
* -> Will not work as urls differ
|
|
224
|
-
*
|
|
225
|
-
* Using the origin ensures that urls always match with the cookie sent. Otherwise,
|
|
226
|
-
* the application shell will rightfully redirect to the logout page.
|
|
227
|
-
*/
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(partialWindow) {
|
|
231
|
-
var _context;
|
|
232
|
-
|
|
233
|
-
var url = new _URL__default["default"](partialWindow.origin);
|
|
234
|
-
var originTld = removeMcPrefix(url.host);
|
|
235
|
-
return _concatInstanceProperty__default["default"](_context = "".concat(url.protocol, "//mc-api.")).call(_context, originTld);
|
|
236
|
-
};
|
|
237
|
-
|
|
238
|
-
function getMcApiUrl(environment, partialWindow) {
|
|
239
|
-
var isServedByProxy = environment.servedByProxy;
|
|
240
|
-
if (isServedByProxy && partialWindow.origin) return getMcApiUrlFromOrigin(partialWindow);
|
|
241
|
-
return environment.mcApiUrl;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
246
|
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
245
247
|
|
|
246
248
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
@@ -264,11 +266,10 @@ var mapUserToApplicationContextUser = function mapUserToApplicationContextUser(u
|
|
|
264
266
|
};
|
|
265
267
|
}; // Adjust certain fields which depend e.g. on the origin
|
|
266
268
|
|
|
267
|
-
var mapEnvironmentToApplicationContextEnvironment = function mapEnvironmentToApplicationContextEnvironment(environment) {
|
|
268
|
-
var partialWindow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
|
|
269
|
+
var mapEnvironmentToApplicationContextEnvironment = function mapEnvironmentToApplicationContextEnvironment(environment, origin) {
|
|
269
270
|
return _objectSpread$1(_objectSpread$1({}, environment), {}, {
|
|
270
271
|
// NOTE: The `mcApiUrl` depends on `servedByProxy`
|
|
271
|
-
mcApiUrl: getMcApiUrl(environment,
|
|
272
|
+
mcApiUrl: getMcApiUrl(environment, origin)
|
|
272
273
|
});
|
|
273
274
|
}; // Expose only certain fields as some of them are only meant to
|
|
274
275
|
// be used internally in the AppShell
|
|
@@ -456,6 +457,7 @@ exports.ApplicationContextProvider = ApplicationContextProvider;
|
|
|
456
457
|
exports.Context = Context$1;
|
|
457
458
|
exports.GetProjectExtensionImageRegex = GetProjectExtensionImageRegex;
|
|
458
459
|
exports.ProjectExtensionProviderForImageRegex = ProjectExtensionProviderForImageRegex;
|
|
460
|
+
exports.getMcApiUrl = getMcApiUrl;
|
|
459
461
|
exports.normalizeAllAppliedActionRights = normalizeAllAppliedActionRights;
|
|
460
462
|
exports.normalizeAllAppliedDataFences = normalizeAllAppliedDataFences;
|
|
461
463
|
exports.normalizeAllAppliedMenuVisibilities = normalizeAllAppliedMenuVisibilities;
|
|
@@ -2,6 +2,8 @@
|
|
|
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');
|
|
5
7
|
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
6
8
|
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
7
9
|
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
@@ -17,10 +19,8 @@ var moment = require('moment-timezone');
|
|
|
17
19
|
var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
|
|
18
20
|
var _toConsumableArray = require('@babel/runtime-corejs3/helpers/toConsumableArray');
|
|
19
21
|
var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
|
|
20
|
-
var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
|
|
21
22
|
var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
|
|
22
23
|
var _valuesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/values');
|
|
23
|
-
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
24
24
|
var jsxRuntime = require('@emotion/react/jsx-runtime');
|
|
25
25
|
require('tiny-warning');
|
|
26
26
|
var react$1 = require('@apollo/client/react');
|
|
@@ -29,6 +29,8 @@ var sentry = require('@commercetools-frontend/sentry');
|
|
|
29
29
|
|
|
30
30
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
31
31
|
|
|
32
|
+
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
33
|
+
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
32
34
|
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
33
35
|
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
34
36
|
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
@@ -39,13 +41,52 @@ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$def
|
|
|
39
41
|
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
40
42
|
var moment__default = /*#__PURE__*/_interopDefault(moment);
|
|
41
43
|
var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
|
|
42
|
-
var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
|
|
43
44
|
var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
|
|
44
45
|
var _valuesInstanceProperty__default = /*#__PURE__*/_interopDefault(_valuesInstanceProperty);
|
|
45
|
-
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
46
46
|
|
|
47
47
|
// NOTE: This string will be replaced on build time with the package version.
|
|
48
|
-
var version = "21.
|
|
48
|
+
var version = "21.12.0";
|
|
49
|
+
|
|
50
|
+
var mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
51
|
+
var mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
|
|
52
|
+
|
|
53
|
+
var getMcOriginTld = function getMcOriginTld(host) {
|
|
54
|
+
if (host.match(mcPreviewHostnameRegex)) {
|
|
55
|
+
return host.replace(mcPreviewHostnameRegex, '$1');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return host.replace(mcHostnameRegex, '$3');
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(origin) {
|
|
62
|
+
var _context;
|
|
63
|
+
|
|
64
|
+
var url = new _URL__default["default"](origin);
|
|
65
|
+
var originTld = getMcOriginTld(url.host);
|
|
66
|
+
return _concatInstanceProperty__default["default"](_context = "".concat(url.protocol, "//mc-api.")).call(_context, originTld);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
var parseAsBoolean = function parseAsBoolean(value) {
|
|
70
|
+
return value === true || value === 'true';
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
function getMcApiUrl() {
|
|
74
|
+
var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.app;
|
|
75
|
+
var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.origin;
|
|
76
|
+
var isServedByProxy = parseAsBoolean(environment.servedByProxy);
|
|
77
|
+
/**
|
|
78
|
+
* Prefer using the origin URL for the MC API based on the origin value
|
|
79
|
+
* of the browser's `window.location`.
|
|
80
|
+
* This ensures that the application always uses the correct URL associated
|
|
81
|
+
* with that environment, instead of relying on the config value.
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
if (isServedByProxy) {
|
|
85
|
+
return getMcApiUrlFromOrigin(origin);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return environment.mcApiUrl;
|
|
89
|
+
}
|
|
49
90
|
|
|
50
91
|
// From https://github.com/acdlite/recompose/blob/master/src/packages/recompose/getDisplayName.js
|
|
51
92
|
var getDisplayName = function getDisplayName(Component) {
|
|
@@ -200,45 +241,6 @@ var normalizeAllAppliedDataFences = function normalizeAllAppliedDataFences(allAp
|
|
|
200
241
|
return null;
|
|
201
242
|
};
|
|
202
243
|
|
|
203
|
-
var removeMcPrefix = function removeMcPrefix(host) {
|
|
204
|
-
return host.replace(/^mc(-(\d){4,})?\.(.*)$/, '$3');
|
|
205
|
-
};
|
|
206
|
-
/**
|
|
207
|
-
* NOTE:
|
|
208
|
-
* Given the Merchant Center or Custom Application runs behind the proxy
|
|
209
|
-
* then the `mcApiUrl` should be build using the origin on the window.
|
|
210
|
-
*
|
|
211
|
-
* This allows the Merchant Center (or any Custom Appliction) to automatically
|
|
212
|
-
* use an `mcApiUrl` which matches the respective url of the deployment.
|
|
213
|
-
*
|
|
214
|
-
* This is particularily useful with the new and old hostnames for the Merchant Center.
|
|
215
|
-
* When using the origin, it will be made sure that the authorization cookie will
|
|
216
|
-
* always be sent as the appropriate API url is used.
|
|
217
|
-
*
|
|
218
|
-
* 1. MC: mc.commercetools.com with API: mc-api.europe-west1.gcp.commercetools.com
|
|
219
|
-
* -> Will not work as urls differ
|
|
220
|
-
* 2. MC: mc.europe-west1.gcp.commercetools.com with API: mc-api.commercetools.com
|
|
221
|
-
* -> Will not work as urls differ
|
|
222
|
-
*
|
|
223
|
-
* Using the origin ensures that urls always match with the cookie sent. Otherwise,
|
|
224
|
-
* the application shell will rightfully redirect to the logout page.
|
|
225
|
-
*/
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(partialWindow) {
|
|
229
|
-
var _context;
|
|
230
|
-
|
|
231
|
-
var url = new _URL__default["default"](partialWindow.origin);
|
|
232
|
-
var originTld = removeMcPrefix(url.host);
|
|
233
|
-
return _concatInstanceProperty__default["default"](_context = "".concat(url.protocol, "//mc-api.")).call(_context, originTld);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
function getMcApiUrl(environment, partialWindow) {
|
|
237
|
-
var isServedByProxy = environment.servedByProxy;
|
|
238
|
-
if (isServedByProxy && partialWindow.origin) return getMcApiUrlFromOrigin(partialWindow);
|
|
239
|
-
return environment.mcApiUrl;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
244
|
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
243
245
|
|
|
244
246
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
|
|
@@ -262,11 +264,10 @@ var mapUserToApplicationContextUser = function mapUserToApplicationContextUser(u
|
|
|
262
264
|
};
|
|
263
265
|
}; // Adjust certain fields which depend e.g. on the origin
|
|
264
266
|
|
|
265
|
-
var mapEnvironmentToApplicationContextEnvironment = function mapEnvironmentToApplicationContextEnvironment(environment) {
|
|
266
|
-
var partialWindow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
|
|
267
|
+
var mapEnvironmentToApplicationContextEnvironment = function mapEnvironmentToApplicationContextEnvironment(environment, origin) {
|
|
267
268
|
return _objectSpread$1(_objectSpread$1({}, environment), {}, {
|
|
268
269
|
// NOTE: The `mcApiUrl` depends on `servedByProxy`
|
|
269
|
-
mcApiUrl: getMcApiUrl(environment,
|
|
270
|
+
mcApiUrl: getMcApiUrl(environment, origin)
|
|
270
271
|
});
|
|
271
272
|
}; // Expose only certain fields as some of them are only meant to
|
|
272
273
|
// be used internally in the AppShell
|
|
@@ -443,6 +444,7 @@ exports.ApplicationContextProvider = ApplicationContextProvider;
|
|
|
443
444
|
exports.Context = Context$1;
|
|
444
445
|
exports.GetProjectExtensionImageRegex = GetProjectExtensionImageRegex;
|
|
445
446
|
exports.ProjectExtensionProviderForImageRegex = ProjectExtensionProviderForImageRegex;
|
|
447
|
+
exports.getMcApiUrl = getMcApiUrl;
|
|
446
448
|
exports.normalizeAllAppliedActionRights = normalizeAllAppliedActionRights;
|
|
447
449
|
exports.normalizeAllAppliedDataFences = normalizeAllAppliedDataFences;
|
|
448
450
|
exports.normalizeAllAppliedMenuVisibilities = normalizeAllAppliedMenuVisibilities;
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
|
2
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
1
3
|
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
2
4
|
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
3
5
|
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
@@ -13,10 +15,8 @@ import moment from 'moment-timezone';
|
|
|
13
15
|
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
14
16
|
import _toConsumableArray from '@babel/runtime-corejs3/helpers/esm/toConsumableArray';
|
|
15
17
|
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
16
|
-
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
17
18
|
import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
|
|
18
19
|
import _valuesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/values';
|
|
19
|
-
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
|
20
20
|
import { jsx } from '@emotion/react/jsx-runtime';
|
|
21
21
|
import warning from 'tiny-warning';
|
|
22
22
|
import { useQuery } from '@apollo/client/react';
|
|
@@ -24,7 +24,48 @@ import { GRAPHQL_TARGETS } from '@commercetools-frontend/constants';
|
|
|
24
24
|
import { reportErrorToSentry } from '@commercetools-frontend/sentry';
|
|
25
25
|
|
|
26
26
|
// NOTE: This string will be replaced on build time with the package version.
|
|
27
|
-
var version = "21.
|
|
27
|
+
var version = "21.12.0";
|
|
28
|
+
|
|
29
|
+
var mcHostnameRegex = /^mc(-(\d){4,})?\.(.*)$/;
|
|
30
|
+
var mcPreviewHostnameRegex = /^.*\.mc-preview\.(.*)$/;
|
|
31
|
+
|
|
32
|
+
var getMcOriginTld = function getMcOriginTld(host) {
|
|
33
|
+
if (host.match(mcPreviewHostnameRegex)) {
|
|
34
|
+
return host.replace(mcPreviewHostnameRegex, '$1');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return host.replace(mcHostnameRegex, '$3');
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(origin) {
|
|
41
|
+
var _context;
|
|
42
|
+
|
|
43
|
+
var url = new _URL(origin);
|
|
44
|
+
var originTld = getMcOriginTld(url.host);
|
|
45
|
+
return _concatInstanceProperty(_context = "".concat(url.protocol, "//mc-api.")).call(_context, originTld);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
var parseAsBoolean = function parseAsBoolean(value) {
|
|
49
|
+
return value === true || value === 'true';
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
function getMcApiUrl() {
|
|
53
|
+
var environment = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : window.app;
|
|
54
|
+
var origin = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window.origin;
|
|
55
|
+
var isServedByProxy = parseAsBoolean(environment.servedByProxy);
|
|
56
|
+
/**
|
|
57
|
+
* Prefer using the origin URL for the MC API based on the origin value
|
|
58
|
+
* of the browser's `window.location`.
|
|
59
|
+
* This ensures that the application always uses the correct URL associated
|
|
60
|
+
* with that environment, instead of relying on the config value.
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
if (isServedByProxy) {
|
|
64
|
+
return getMcApiUrlFromOrigin(origin);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return environment.mcApiUrl;
|
|
68
|
+
}
|
|
28
69
|
|
|
29
70
|
// From https://github.com/acdlite/recompose/blob/master/src/packages/recompose/getDisplayName.js
|
|
30
71
|
var getDisplayName = function getDisplayName(Component) {
|
|
@@ -179,45 +220,6 @@ var normalizeAllAppliedDataFences = function normalizeAllAppliedDataFences(allAp
|
|
|
179
220
|
return null;
|
|
180
221
|
};
|
|
181
222
|
|
|
182
|
-
var removeMcPrefix = function removeMcPrefix(host) {
|
|
183
|
-
return host.replace(/^mc(-(\d){4,})?\.(.*)$/, '$3');
|
|
184
|
-
};
|
|
185
|
-
/**
|
|
186
|
-
* NOTE:
|
|
187
|
-
* Given the Merchant Center or Custom Application runs behind the proxy
|
|
188
|
-
* then the `mcApiUrl` should be build using the origin on the window.
|
|
189
|
-
*
|
|
190
|
-
* This allows the Merchant Center (or any Custom Appliction) to automatically
|
|
191
|
-
* use an `mcApiUrl` which matches the respective url of the deployment.
|
|
192
|
-
*
|
|
193
|
-
* This is particularily useful with the new and old hostnames for the Merchant Center.
|
|
194
|
-
* When using the origin, it will be made sure that the authorization cookie will
|
|
195
|
-
* always be sent as the appropriate API url is used.
|
|
196
|
-
*
|
|
197
|
-
* 1. MC: mc.commercetools.com with API: mc-api.europe-west1.gcp.commercetools.com
|
|
198
|
-
* -> Will not work as urls differ
|
|
199
|
-
* 2. MC: mc.europe-west1.gcp.commercetools.com with API: mc-api.commercetools.com
|
|
200
|
-
* -> Will not work as urls differ
|
|
201
|
-
*
|
|
202
|
-
* Using the origin ensures that urls always match with the cookie sent. Otherwise,
|
|
203
|
-
* the application shell will rightfully redirect to the logout page.
|
|
204
|
-
*/
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
var getMcApiUrlFromOrigin = function getMcApiUrlFromOrigin(partialWindow) {
|
|
208
|
-
var _context;
|
|
209
|
-
|
|
210
|
-
var url = new _URL(partialWindow.origin);
|
|
211
|
-
var originTld = removeMcPrefix(url.host);
|
|
212
|
-
return _concatInstanceProperty(_context = "".concat(url.protocol, "//mc-api.")).call(_context, originTld);
|
|
213
|
-
};
|
|
214
|
-
|
|
215
|
-
function getMcApiUrl(environment, partialWindow) {
|
|
216
|
-
var isServedByProxy = environment.servedByProxy;
|
|
217
|
-
if (isServedByProxy && partialWindow.origin) return getMcApiUrlFromOrigin(partialWindow);
|
|
218
|
-
return environment.mcApiUrl;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
223
|
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
222
224
|
|
|
223
225
|
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys$1(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys$1(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
@@ -241,11 +243,10 @@ var mapUserToApplicationContextUser = function mapUserToApplicationContextUser(u
|
|
|
241
243
|
};
|
|
242
244
|
}; // Adjust certain fields which depend e.g. on the origin
|
|
243
245
|
|
|
244
|
-
var mapEnvironmentToApplicationContextEnvironment = function mapEnvironmentToApplicationContextEnvironment(environment) {
|
|
245
|
-
var partialWindow = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : window;
|
|
246
|
+
var mapEnvironmentToApplicationContextEnvironment = function mapEnvironmentToApplicationContextEnvironment(environment, origin) {
|
|
246
247
|
return _objectSpread$1(_objectSpread$1({}, environment), {}, {
|
|
247
248
|
// NOTE: The `mcApiUrl` depends on `servedByProxy`
|
|
248
|
-
mcApiUrl: getMcApiUrl(environment,
|
|
249
|
+
mcApiUrl: getMcApiUrl(environment, origin)
|
|
249
250
|
});
|
|
250
251
|
}; // Expose only certain fields as some of them are only meant to
|
|
251
252
|
// be used internally in the AppShell
|
|
@@ -428,4 +429,4 @@ function withProjectExtensionImageRegex() {
|
|
|
428
429
|
};
|
|
429
430
|
} // Exports
|
|
430
431
|
|
|
431
|
-
export { ApplicationContext, ApplicationContextProvider, Context$1 as Context, GetProjectExtensionImageRegex, ProjectExtensionProviderForImageRegex, normalizeAllAppliedActionRights, normalizeAllAppliedDataFences, normalizeAllAppliedMenuVisibilities, normalizeAllAppliedPermissions, useApplicationContext, useProjectExtensionImageRegex, version, withApplicationContext, withProjectExtensionImageRegex };
|
|
432
|
+
export { ApplicationContext, ApplicationContextProvider, Context$1 as Context, GetProjectExtensionImageRegex, ProjectExtensionProviderForImageRegex, getMcApiUrl, normalizeAllAppliedActionRights, normalizeAllAppliedDataFences, normalizeAllAppliedMenuVisibilities, normalizeAllAppliedPermissions, useApplicationContext, useProjectExtensionImageRegex, version, withApplicationContext, withProjectExtensionImageRegex };
|
|
@@ -72,7 +72,7 @@ export declare const mapEnvironmentToApplicationContextEnvironment: <AdditionalE
|
|
|
72
72
|
oidc?: import("@commercetools-frontend/constants").ApplicationOidcForDevelopmentConfig | undefined;
|
|
73
73
|
menuLinks?: import("@commercetools-frontend/constants").ApplicationMenuLinksForDevelopmentConfig | undefined;
|
|
74
74
|
} | undefined;
|
|
75
|
-
},
|
|
75
|
+
}, origin?: string) => AdditionalEnvironmentProperties & {
|
|
76
76
|
mcApiUrl: string;
|
|
77
77
|
applicationId: string;
|
|
78
78
|
applicationName: string;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as version } from './version';
|
|
2
2
|
export * from './export-types';
|
|
3
|
+
export { default as getMcApiUrl } from './utils/get-mc-api-url';
|
|
3
4
|
export { Context, ApplicationContext, ApplicationContextProvider, withApplicationContext, useApplicationContext, normalizeAllAppliedActionRights, normalizeAllAppliedDataFences, normalizeAllAppliedMenuVisibilities, normalizeAllAppliedPermissions, } from './components/application-context';
|
|
4
5
|
export { GetProjectExtensionImageRegex, ProjectExtensionProviderForImageRegex, withProjectExtensionImageRegex, useProjectExtensionImageRegex, } from './components/project-extension-image-regex';
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { ApplicationWindow } from '@commercetools-frontend/constants';
|
|
2
|
-
declare
|
|
3
|
-
declare type TPartialWindow = Pick<Window, 'origin'>;
|
|
4
|
-
declare function getMcApiUrl(environment: TApplicationContextEnvironment, partialWindow: TPartialWindow): string;
|
|
2
|
+
declare function getMcApiUrl(environment?: ApplicationWindow['app'], origin?: string): string;
|
|
5
3
|
export default getMcApiUrl;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@commercetools-frontend/application-shell-connectors",
|
|
3
|
-
"version": "21.
|
|
3
|
+
"version": "21.12.0",
|
|
4
4
|
"description": "Contains complementary tools for @commercetools-frontend/application-shell",
|
|
5
5
|
"bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
|
|
6
6
|
"repository": {
|
|
@@ -23,8 +23,8 @@
|
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@babel/runtime": "^7.18.6",
|
|
25
25
|
"@babel/runtime-corejs3": "^7.18.6",
|
|
26
|
-
"@commercetools-frontend/constants": "21.
|
|
27
|
-
"@commercetools-frontend/sentry": "21.
|
|
26
|
+
"@commercetools-frontend/constants": "21.12.0",
|
|
27
|
+
"@commercetools-frontend/sentry": "21.12.0",
|
|
28
28
|
"@emotion/react": "11.9.3",
|
|
29
29
|
"@types/lodash": "^4.14.182",
|
|
30
30
|
"@types/prop-types": "^15.7.5",
|