@commercetools-frontend/mc-html-template 22.38.0 → 22.38.2

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.
@@ -12,6 +12,7 @@ var _Object$assign = require('@babel/runtime-corejs3/core-js-stable/object/assig
12
12
  var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
13
13
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
14
14
  var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
15
+ var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
15
16
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
16
17
  var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
17
18
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
@@ -34,6 +35,7 @@ var _Object$assign__default = /*#__PURE__*/_interopDefault(_Object$assign);
34
35
  var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
35
36
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
36
37
  var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
38
+ var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
37
39
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
38
40
  var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
39
41
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
@@ -70,11 +72,12 @@ const htmlScripts$1 = {
70
72
  "publicPath": "window.__dynamicImportHandler__=function(n){return window.app.cdnUrl.replace(/\\/$/,\"\")+\"/\"+n.replace(/^(\\.\\/)?/,\"\")},window.__dynamicImportPreload__=function(n){return n.map(n=>window.app.cdnUrl.replace(/\\/$/,\"\")+\"/\"+n)};"
71
73
  };
72
74
  const toArray = value => _Array$isArray__default["default"](value) ? value : [value];
73
- const mergeDirectives = function () {
75
+ const parseCSPDirectives = function () {
76
+ var _context2;
74
77
  for (var _len = arguments.length, directives = new Array(_len), _key = 0; _key < _len; _key++) {
75
78
  directives[_key] = arguments[_key];
76
79
  }
77
- return _reduceInstanceProperty__default["default"](directives).call(directives, (mergedDirectives, directive) => {
80
+ const mergedDirectives = _reduceInstanceProperty__default["default"](directives).call(directives, (mergedDirectives, directive) => {
78
81
  var _context;
79
82
  return _Object$assign__default["default"](mergedDirectives, _reduceInstanceProperty__default["default"](_context = _Object$keys__default["default"](directive)).call(_context, (mergedDirectiveValues, directiveKey) => {
80
83
  const existingDirectiveValue = mergedDirectives[directiveKey];
@@ -83,26 +86,27 @@ const mergeDirectives = function () {
83
86
  });
84
87
  }, {}));
85
88
  }, {});
86
- };
87
- const toHeaderString = function () {
88
- var _context2;
89
- let directives = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
90
- return _mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](directives)).call(_context2, _ref => {
89
+ return _mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](mergedDirectives)).call(_context2, _ref => {
91
90
  let _ref2 = _slicedToArray(_ref, 2),
92
91
  directive = _ref2[0],
93
92
  value = _ref2[1];
94
93
  return `${directive} ${_Array$isArray__default["default"](value) ? value.join(' ') : value}`;
95
94
  }).join('; ');
96
95
  };
97
- const toStructuredHeaderString = function () {
96
+ const parsePermissionsPolicyDirectives = (defaultValue, customDirectives) => {
98
97
  var _context3;
99
- let directives = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
100
- return _mapInstanceProperty__default["default"](_context3 = _Object$entries__default["default"](directives)).call(_context3, _ref3 => {
101
- let _ref4 = _slicedToArray(_ref3, 2),
102
- directive = _ref4[0],
103
- value = _ref4[1];
104
- return `${directive}=${_Array$isArray__default["default"](value) ? value.join(' ') : value}`;
105
- }).join(', ');
98
+ const mergedDirectives = _mapInstanceProperty__default["default"](_context3 = defaultValue.split(',')).call(_context3, directive => {
99
+ const _directive$trim$split = _trimInstanceProperty__default["default"](directive).call(directive).split('='),
100
+ _directive$trim$split2 = _slicedToArray(_directive$trim$split, 2),
101
+ directiveName = _directive$trim$split2[0],
102
+ directiveValue = _directive$trim$split2[1];
103
+ const overrideDirectiveValue = customDirectives[directiveName];
104
+ if (overrideDirectiveValue) {
105
+ return [directiveName, overrideDirectiveValue].join('=');
106
+ }
107
+ return [directiveName, directiveValue].join('=');
108
+ });
109
+ return mergedDirectives.join(', ');
106
110
  };
107
111
  const processHeaders = applicationConfig => {
108
112
  var _context4, _context5, _context6;
@@ -120,7 +124,7 @@ const processHeaders = applicationConfig => {
120
124
  * Content Security Policy (CSP)
121
125
  * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
122
126
  */
123
- const cspDirectives = _Object$assign__default["default"]({
127
+ const defaultCSPDirectives = _Object$assign__default["default"]({
124
128
  'default-src': "'none'",
125
129
  'script-src': _concatInstanceProperty__default["default"](_context4 = ["'self'"]).call(_context4, isMcDevEnv ?
126
130
  // Allow webpack to load source maps on runtime when errors occur
@@ -154,15 +158,12 @@ const processHeaders = applicationConfig => {
154
158
  // - `require-sri-for style script` (at the moment not possible because
155
159
  // Intercom scripts are apparently not meant for this)
156
160
  );
157
-
158
- // Recursively merge the directives
159
- const mergedCsp = mergeDirectives(cspDirectives, applicationConfig.headers?.csp ?? {});
160
161
  return _objectSpread(_objectSpread({}, constants.HTTP_SECURITY_HEADERS), {}, {
161
162
  // The `Content-Security-Policy` header is always generated
162
163
  // based on the Merchant Center customization config.
163
- 'Content-Security-Policy': toHeaderString(mergedCsp)
164
+ [constants.HTTP_SECURITY_HEADER_KEYS['Content-Security-Policy']]: parseCSPDirectives(defaultCSPDirectives, applicationConfig.headers?.csp ?? {})
164
165
  }, applicationConfig.headers?.permissionsPolicies ? {
165
- 'Permissions-Policy': toStructuredHeaderString(applicationConfig.headers.permissionsPolicies)
166
+ [constants.HTTP_SECURITY_HEADER_KEYS['Permissions-Policy']]: parsePermissionsPolicyDirectives(constants.HTTP_SECURITY_HEADERS['Permissions-Policy'], applicationConfig.headers.permissionsPolicies ?? {})
166
167
  } : {});
167
168
  };
168
169
 
@@ -12,6 +12,7 @@ var _Object$assign = require('@babel/runtime-corejs3/core-js-stable/object/assig
12
12
  var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
13
13
  var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
14
14
  var _Object$entries = require('@babel/runtime-corejs3/core-js-stable/object/entries');
15
+ var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
15
16
  var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
16
17
  var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
17
18
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
@@ -34,6 +35,7 @@ var _Object$assign__default = /*#__PURE__*/_interopDefault(_Object$assign);
34
35
  var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
35
36
  var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
36
37
  var _Object$entries__default = /*#__PURE__*/_interopDefault(_Object$entries);
38
+ var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
37
39
  var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
38
40
  var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
39
41
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
@@ -70,11 +72,12 @@ const htmlScripts$1 = {
70
72
  "publicPath": "window.__dynamicImportHandler__=function(n){return window.app.cdnUrl.replace(/\\/$/,\"\")+\"/\"+n.replace(/^(\\.\\/)?/,\"\")},window.__dynamicImportPreload__=function(n){return n.map(n=>window.app.cdnUrl.replace(/\\/$/,\"\")+\"/\"+n)};"
71
73
  };
72
74
  const toArray = value => _Array$isArray__default["default"](value) ? value : [value];
73
- const mergeDirectives = function () {
75
+ const parseCSPDirectives = function () {
76
+ var _context2;
74
77
  for (var _len = arguments.length, directives = new Array(_len), _key = 0; _key < _len; _key++) {
75
78
  directives[_key] = arguments[_key];
76
79
  }
77
- return _reduceInstanceProperty__default["default"](directives).call(directives, (mergedDirectives, directive) => {
80
+ const mergedDirectives = _reduceInstanceProperty__default["default"](directives).call(directives, (mergedDirectives, directive) => {
78
81
  var _context;
79
82
  return _Object$assign__default["default"](mergedDirectives, _reduceInstanceProperty__default["default"](_context = _Object$keys__default["default"](directive)).call(_context, (mergedDirectiveValues, directiveKey) => {
80
83
  const existingDirectiveValue = mergedDirectives[directiveKey];
@@ -83,26 +86,27 @@ const mergeDirectives = function () {
83
86
  });
84
87
  }, {}));
85
88
  }, {});
86
- };
87
- const toHeaderString = function () {
88
- var _context2;
89
- let directives = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
90
- return _mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](directives)).call(_context2, _ref => {
89
+ return _mapInstanceProperty__default["default"](_context2 = _Object$entries__default["default"](mergedDirectives)).call(_context2, _ref => {
91
90
  let _ref2 = _slicedToArray(_ref, 2),
92
91
  directive = _ref2[0],
93
92
  value = _ref2[1];
94
93
  return `${directive} ${_Array$isArray__default["default"](value) ? value.join(' ') : value}`;
95
94
  }).join('; ');
96
95
  };
97
- const toStructuredHeaderString = function () {
96
+ const parsePermissionsPolicyDirectives = (defaultValue, customDirectives) => {
98
97
  var _context3;
99
- let directives = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
100
- return _mapInstanceProperty__default["default"](_context3 = _Object$entries__default["default"](directives)).call(_context3, _ref3 => {
101
- let _ref4 = _slicedToArray(_ref3, 2),
102
- directive = _ref4[0],
103
- value = _ref4[1];
104
- return `${directive}=${_Array$isArray__default["default"](value) ? value.join(' ') : value}`;
105
- }).join(', ');
98
+ const mergedDirectives = _mapInstanceProperty__default["default"](_context3 = defaultValue.split(',')).call(_context3, directive => {
99
+ const _directive$trim$split = _trimInstanceProperty__default["default"](directive).call(directive).split('='),
100
+ _directive$trim$split2 = _slicedToArray(_directive$trim$split, 2),
101
+ directiveName = _directive$trim$split2[0],
102
+ directiveValue = _directive$trim$split2[1];
103
+ const overrideDirectiveValue = customDirectives[directiveName];
104
+ if (overrideDirectiveValue) {
105
+ return [directiveName, overrideDirectiveValue].join('=');
106
+ }
107
+ return [directiveName, directiveValue].join('=');
108
+ });
109
+ return mergedDirectives.join(', ');
106
110
  };
107
111
  const processHeaders = applicationConfig => {
108
112
  var _context4, _context5, _context6;
@@ -120,7 +124,7 @@ const processHeaders = applicationConfig => {
120
124
  * Content Security Policy (CSP)
121
125
  * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
122
126
  */
123
- const cspDirectives = _Object$assign__default["default"]({
127
+ const defaultCSPDirectives = _Object$assign__default["default"]({
124
128
  'default-src': "'none'",
125
129
  'script-src': _concatInstanceProperty__default["default"](_context4 = ["'self'"]).call(_context4, isMcDevEnv ?
126
130
  // Allow webpack to load source maps on runtime when errors occur
@@ -154,15 +158,12 @@ const processHeaders = applicationConfig => {
154
158
  // - `require-sri-for style script` (at the moment not possible because
155
159
  // Intercom scripts are apparently not meant for this)
156
160
  );
157
-
158
- // Recursively merge the directives
159
- const mergedCsp = mergeDirectives(cspDirectives, applicationConfig.headers?.csp ?? {});
160
161
  return _objectSpread(_objectSpread({}, constants.HTTP_SECURITY_HEADERS), {}, {
161
162
  // The `Content-Security-Policy` header is always generated
162
163
  // based on the Merchant Center customization config.
163
- 'Content-Security-Policy': toHeaderString(mergedCsp)
164
+ [constants.HTTP_SECURITY_HEADER_KEYS['Content-Security-Policy']]: parseCSPDirectives(defaultCSPDirectives, applicationConfig.headers?.csp ?? {})
164
165
  }, applicationConfig.headers?.permissionsPolicies ? {
165
- 'Permissions-Policy': toStructuredHeaderString(applicationConfig.headers.permissionsPolicies)
166
+ [constants.HTTP_SECURITY_HEADER_KEYS['Permissions-Policy']]: parsePermissionsPolicyDirectives(constants.HTTP_SECURITY_HEADERS['Permissions-Policy'], applicationConfig.headers.permissionsPolicies ?? {})
166
167
  } : {});
167
168
  };
168
169
 
@@ -8,6 +8,7 @@ import _Object$assign from '@babel/runtime-corejs3/core-js-stable/object/assign'
8
8
  import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
9
9
  import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
10
10
  import _Object$entries from '@babel/runtime-corejs3/core-js-stable/object/entries';
11
+ import _trimInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/trim';
11
12
  import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
12
13
  import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
13
14
  import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
@@ -16,7 +17,7 @@ import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/inst
16
17
  import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
17
18
  import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
18
19
  import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
19
- import { HTTP_SECURITY_HEADERS } from '@commercetools-frontend/constants';
20
+ import { HTTP_SECURITY_HEADER_KEYS, HTTP_SECURITY_HEADERS } from '@commercetools-frontend/constants';
20
21
  import crypto from 'crypto';
21
22
  import serialize from 'serialize-javascript';
22
23
  export { g as generateTemplate } from './generate-template-31dee161.esm.js';
@@ -46,11 +47,12 @@ const htmlScripts$1 = {
46
47
  "publicPath": "window.__dynamicImportHandler__=function(n){return window.app.cdnUrl.replace(/\\/$/,\"\")+\"/\"+n.replace(/^(\\.\\/)?/,\"\")},window.__dynamicImportPreload__=function(n){return n.map(n=>window.app.cdnUrl.replace(/\\/$/,\"\")+\"/\"+n)};"
47
48
  };
48
49
  const toArray = value => _Array$isArray(value) ? value : [value];
49
- const mergeDirectives = function () {
50
+ const parseCSPDirectives = function () {
51
+ var _context2;
50
52
  for (var _len = arguments.length, directives = new Array(_len), _key = 0; _key < _len; _key++) {
51
53
  directives[_key] = arguments[_key];
52
54
  }
53
- return _reduceInstanceProperty(directives).call(directives, (mergedDirectives, directive) => {
55
+ const mergedDirectives = _reduceInstanceProperty(directives).call(directives, (mergedDirectives, directive) => {
54
56
  var _context;
55
57
  return _Object$assign(mergedDirectives, _reduceInstanceProperty(_context = _Object$keys(directive)).call(_context, (mergedDirectiveValues, directiveKey) => {
56
58
  const existingDirectiveValue = mergedDirectives[directiveKey];
@@ -59,26 +61,27 @@ const mergeDirectives = function () {
59
61
  });
60
62
  }, {}));
61
63
  }, {});
62
- };
63
- const toHeaderString = function () {
64
- var _context2;
65
- let directives = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
66
- return _mapInstanceProperty(_context2 = _Object$entries(directives)).call(_context2, _ref => {
64
+ return _mapInstanceProperty(_context2 = _Object$entries(mergedDirectives)).call(_context2, _ref => {
67
65
  let _ref2 = _slicedToArray(_ref, 2),
68
66
  directive = _ref2[0],
69
67
  value = _ref2[1];
70
68
  return `${directive} ${_Array$isArray(value) ? value.join(' ') : value}`;
71
69
  }).join('; ');
72
70
  };
73
- const toStructuredHeaderString = function () {
71
+ const parsePermissionsPolicyDirectives = (defaultValue, customDirectives) => {
74
72
  var _context3;
75
- let directives = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
76
- return _mapInstanceProperty(_context3 = _Object$entries(directives)).call(_context3, _ref3 => {
77
- let _ref4 = _slicedToArray(_ref3, 2),
78
- directive = _ref4[0],
79
- value = _ref4[1];
80
- return `${directive}=${_Array$isArray(value) ? value.join(' ') : value}`;
81
- }).join(', ');
73
+ const mergedDirectives = _mapInstanceProperty(_context3 = defaultValue.split(',')).call(_context3, directive => {
74
+ const _directive$trim$split = _trimInstanceProperty(directive).call(directive).split('='),
75
+ _directive$trim$split2 = _slicedToArray(_directive$trim$split, 2),
76
+ directiveName = _directive$trim$split2[0],
77
+ directiveValue = _directive$trim$split2[1];
78
+ const overrideDirectiveValue = customDirectives[directiveName];
79
+ if (overrideDirectiveValue) {
80
+ return [directiveName, overrideDirectiveValue].join('=');
81
+ }
82
+ return [directiveName, directiveValue].join('=');
83
+ });
84
+ return mergedDirectives.join(', ');
82
85
  };
83
86
  const processHeaders = applicationConfig => {
84
87
  var _context4, _context5, _context6;
@@ -96,7 +99,7 @@ const processHeaders = applicationConfig => {
96
99
  * Content Security Policy (CSP)
97
100
  * https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy
98
101
  */
99
- const cspDirectives = _Object$assign({
102
+ const defaultCSPDirectives = _Object$assign({
100
103
  'default-src': "'none'",
101
104
  'script-src': _concatInstanceProperty(_context4 = ["'self'"]).call(_context4, isMcDevEnv ?
102
105
  // Allow webpack to load source maps on runtime when errors occur
@@ -130,15 +133,12 @@ const processHeaders = applicationConfig => {
130
133
  // - `require-sri-for style script` (at the moment not possible because
131
134
  // Intercom scripts are apparently not meant for this)
132
135
  );
133
-
134
- // Recursively merge the directives
135
- const mergedCsp = mergeDirectives(cspDirectives, applicationConfig.headers?.csp ?? {});
136
136
  return _objectSpread(_objectSpread({}, HTTP_SECURITY_HEADERS), {}, {
137
137
  // The `Content-Security-Policy` header is always generated
138
138
  // based on the Merchant Center customization config.
139
- 'Content-Security-Policy': toHeaderString(mergedCsp)
139
+ [HTTP_SECURITY_HEADER_KEYS['Content-Security-Policy']]: parseCSPDirectives(defaultCSPDirectives, applicationConfig.headers?.csp ?? {})
140
140
  }, applicationConfig.headers?.permissionsPolicies ? {
141
- 'Permissions-Policy': toStructuredHeaderString(applicationConfig.headers.permissionsPolicies)
141
+ [HTTP_SECURITY_HEADER_KEYS['Permissions-Policy']]: parsePermissionsPolicyDirectives(HTTP_SECURITY_HEADERS['Permissions-Policy'], applicationConfig.headers.permissionsPolicies ?? {})
142
142
  } : {});
143
143
  };
144
144
 
@@ -1,3 +1,4 @@
1
1
  import type { ApplicationRuntimeConfig } from '@commercetools-frontend/application-config';
2
- declare const processHeaders: (applicationConfig: ApplicationRuntimeConfig) => Record<string, string | undefined>;
2
+ import { type THttpSecurityHeaders } from '@commercetools-frontend/constants';
3
+ declare const processHeaders: (applicationConfig: ApplicationRuntimeConfig) => Record<THttpSecurityHeaders, string | undefined>;
3
4
  export default processHeaders;
@@ -1,7 +1,8 @@
1
1
  import type { ApplicationRuntimeConfig } from '@commercetools-frontend/application-config';
2
+ import type { THttpSecurityHeaders } from '@commercetools-frontend/constants';
2
3
  type TReplaceHtmlPlaceholdersOptions = {
3
4
  env: ApplicationRuntimeConfig['env'];
4
- headers: Record<string, string | undefined>;
5
+ headers?: Record<THttpSecurityHeaders, string | undefined>;
5
6
  };
6
7
  declare const replaceHtmlPlaceholders: (indexHtmlContent: string, options: TReplaceHtmlPlaceholdersOptions) => string;
7
8
  export default replaceHtmlPlaceholders;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@commercetools-frontend/mc-html-template",
3
- "version": "22.38.0",
3
+ "version": "22.38.2",
4
4
  "description": "Everything related to render the index.html for a MC application",
5
5
  "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
6
  "repository": {
@@ -38,8 +38,8 @@
38
38
  "dependencies": {
39
39
  "@babel/runtime": "^7.22.15",
40
40
  "@babel/runtime-corejs3": "^7.22.15",
41
- "@commercetools-frontend/application-config": "22.38.0",
42
- "@commercetools-frontend/constants": "22.38.0",
41
+ "@commercetools-frontend/application-config": "22.38.2",
42
+ "@commercetools-frontend/constants": "22.38.2",
43
43
  "serialize-javascript": "6.0.2",
44
44
  "uglify-js": "3.18.0",
45
45
  "uglifycss": "0.0.29"