@commercetools-frontend/mc-scripts 0.0.0-FEC-157-preview-releases-20241126230331

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.
Files changed (156) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +7 -0
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +2 -0
  4. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts.map +1 -0
  5. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
  6. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
  7. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +7 -0
  8. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
  9. package/application-runtime/package.json +4 -0
  10. package/bin/cli.js +8 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +2 -0
  12. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts.map +1 -0
  13. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +211 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
  15. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +211 -0
  16. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +196 -0
  17. package/cli/package.json +4 -0
  18. package/config/create-webpack-config-for-development.js +8 -0
  19. package/config/create-webpack-config-for-production.js +8 -0
  20. package/config/vendors-to-transpile.js +6 -0
  21. package/dist/build-99744dae.cjs.prod.js +166 -0
  22. package/dist/build-a93715aa.esm.js +152 -0
  23. package/dist/build-f56ce7ec.cjs.dev.js +166 -0
  24. package/dist/build-vite-000f0a2d.cjs.prod.js +193 -0
  25. package/dist/build-vite-722f0dcf.esm.js +182 -0
  26. package/dist/build-vite-838c8e01.cjs.dev.js +193 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +2 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts.map +1 -0
  29. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +29 -0
  30. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  31. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +29 -0
  32. package/dist/commercetools-frontend-mc-scripts.esm.js +21 -0
  33. package/dist/compile-html-025cd493.esm.js +34 -0
  34. package/dist/compile-html-50fd05ec.cjs.prod.js +42 -0
  35. package/dist/compile-html-f4ac88cc.cjs.dev.js +42 -0
  36. package/dist/config-sync-2ff62f08.cjs.dev.js +845 -0
  37. package/dist/config-sync-b57f79e2.cjs.prod.js +839 -0
  38. package/dist/config-sync-cda7662e.esm.js +823 -0
  39. package/dist/create-postcss-config-2f709335.esm.js +75 -0
  40. package/dist/create-postcss-config-3b540c7c.cjs.prod.js +81 -0
  41. package/dist/create-postcss-config-5962fa01.cjs.dev.js +81 -0
  42. package/dist/create-webpack-config-for-development-7d9e4dc4.cjs.prod.js +463 -0
  43. package/dist/create-webpack-config-for-development-86baace3.esm.js +438 -0
  44. package/dist/create-webpack-config-for-development-b379913b.cjs.dev.js +463 -0
  45. package/dist/create-webpack-config-for-production-3a40f56b.cjs.dev.js +518 -0
  46. package/dist/create-webpack-config-for-production-5ec9d0e2.cjs.prod.js +518 -0
  47. package/dist/create-webpack-config-for-production-b6ee3116.esm.js +488 -0
  48. package/dist/credentials-storage-3cea94ea.cjs.dev.js +95 -0
  49. package/dist/credentials-storage-b13e1406.esm.js +83 -0
  50. package/dist/credentials-storage-dc849808.cjs.prod.js +95 -0
  51. package/dist/declarations/src/application-runtime.d.ts +1 -0
  52. package/dist/declarations/src/cli.d.ts +4 -0
  53. package/dist/declarations/src/commands/build-vite.d.ts +2 -0
  54. package/dist/declarations/src/commands/build.d.ts +2 -0
  55. package/dist/declarations/src/commands/compile-html.d.ts +3 -0
  56. package/dist/declarations/src/commands/config-sync.d.ts +3 -0
  57. package/dist/declarations/src/commands/deployment-previews-set.d.ts +3 -0
  58. package/dist/declarations/src/commands/login.d.ts +2 -0
  59. package/dist/declarations/src/commands/serve.d.ts +2 -0
  60. package/dist/declarations/src/commands/start-vite.d.ts +2 -0
  61. package/dist/declarations/src/commands/start.d.ts +2 -0
  62. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  63. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  64. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  65. package/dist/declarations/src/config/has-jsx-runtime.d.ts +2 -0
  66. package/dist/declarations/src/config/moment-locales.d.ts +2 -0
  67. package/dist/declarations/src/config/optimizations.d.ts +2 -0
  68. package/dist/declarations/src/config/paths.d.ts +12 -0
  69. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  70. package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
  71. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  72. package/dist/declarations/src/generated/core.d.ts +739 -0
  73. package/dist/declarations/src/generated/settings.d.ts +2116 -0
  74. package/dist/declarations/src/index.d.ts +3 -0
  75. package/dist/declarations/src/postcss.d.ts +1 -0
  76. package/dist/declarations/src/types.d.ts +87 -0
  77. package/dist/declarations/src/utils/auth.d.ts +6 -0
  78. package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
  79. package/dist/declarations/src/utils/does-file-exist.d.ts +2 -0
  80. package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
  81. package/dist/declarations/src/utils/graphql-requests.d.ts +172 -0
  82. package/dist/declarations/src/utils/i18n-message-complilation.d.ts +4 -0
  83. package/dist/declarations/src/utils/user-agent.d.ts +2 -0
  84. package/dist/declarations/src/version.d.ts +2 -0
  85. package/dist/declarations/src/vite-plugins/vite-plugin-dynamic-base-assets-globals.d.ts +3 -0
  86. package/dist/declarations/src/vite-plugins/vite-plugin-i18n-message-compilation.d.ts +3 -0
  87. package/dist/declarations/src/vite-plugins/vite-plugin-merchant-center-customization.d.ts +4 -0
  88. package/dist/declarations/src/vite-plugins/vite-plugin-svgr.d.ts +3 -0
  89. package/dist/declarations/src/webpack-loaders/i18n-message-compilation-loader.d.ts +3 -0
  90. package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
  91. package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
  92. package/dist/declarations/src/webpack.d.ts +2 -0
  93. package/dist/deployment-previews-set-173d8491.cjs.dev.js +203 -0
  94. package/dist/deployment-previews-set-923f79de.esm.js +192 -0
  95. package/dist/deployment-previews-set-f451242a.cjs.prod.js +203 -0
  96. package/dist/does-file-exist-32618334.esm.js +12 -0
  97. package/dist/does-file-exist-be53305d.cjs.prod.js +18 -0
  98. package/dist/does-file-exist-eb86baca.cjs.dev.js +18 -0
  99. package/dist/graphql-requests-0e427050.esm.js +243 -0
  100. package/dist/graphql-requests-733aac06.cjs.dev.js +266 -0
  101. package/dist/graphql-requests-db54706e.cjs.prod.js +266 -0
  102. package/dist/has-jsx-runtime-aa5d21ee.cjs.dev.js +15 -0
  103. package/dist/has-jsx-runtime-c3202df5.cjs.prod.js +15 -0
  104. package/dist/has-jsx-runtime-e3ecb09b.esm.js +13 -0
  105. package/dist/i18n-message-complilation-21d3b0aa.esm.js +15 -0
  106. package/dist/i18n-message-complilation-7311cb29.cjs.dev.js +23 -0
  107. package/dist/i18n-message-complilation-7762da61.cjs.prod.js +23 -0
  108. package/dist/login-35f578e3.esm.js +86 -0
  109. package/dist/login-65c78b83.cjs.dev.js +103 -0
  110. package/dist/login-c616d769.cjs.prod.js +103 -0
  111. package/dist/optimizations-7789145e.cjs.dev.js +85 -0
  112. package/dist/optimizations-bf991634.esm.js +67 -0
  113. package/dist/optimizations-fb93514f.cjs.prod.js +85 -0
  114. package/dist/package-436331e6.cjs.dev.js +151 -0
  115. package/dist/package-a7096308.cjs.prod.js +151 -0
  116. package/dist/package-b2f2b4e5.esm.js +149 -0
  117. package/dist/paths-39f22b8b.esm.js +36 -0
  118. package/dist/paths-7768b440.cjs.prod.js +44 -0
  119. package/dist/paths-b76fc753.cjs.dev.js +44 -0
  120. package/dist/serve-5666b16a.cjs.prod.js +48 -0
  121. package/dist/serve-6a951584.esm.js +41 -0
  122. package/dist/serve-f898c45e.cjs.dev.js +48 -0
  123. package/dist/start-4e79e08f.esm.js +164 -0
  124. package/dist/start-569eb0f9.cjs.dev.js +177 -0
  125. package/dist/start-b0765c9a.cjs.prod.js +177 -0
  126. package/dist/start-vite-45bfc42f.esm.js +110 -0
  127. package/dist/start-vite-a68e1b9f.cjs.prod.js +122 -0
  128. package/dist/start-vite-a787f80d.cjs.dev.js +122 -0
  129. package/dist/vendors-to-transpile-04a49d40.cjs.prod.js +5 -0
  130. package/dist/vendors-to-transpile-6ab4ea06.cjs.dev.js +5 -0
  131. package/dist/vendors-to-transpile-7dc84a72.esm.js +3 -0
  132. package/dist/vite-plugin-svgr-069f402d.esm.js +83 -0
  133. package/dist/vite-plugin-svgr-7fb42bbf.cjs.dev.js +108 -0
  134. package/dist/vite-plugin-svgr-b080c510.cjs.prod.js +108 -0
  135. package/package.json +147 -0
  136. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +2 -0
  137. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts.map +1 -0
  138. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +12 -0
  139. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  140. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +12 -0
  141. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +4 -0
  142. package/postcss/package.json +4 -0
  143. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +2 -0
  144. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts.map +1 -0
  145. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +57 -0
  146. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  147. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +57 -0
  148. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +48 -0
  149. package/webpack/package.json +4 -0
  150. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts +3 -0
  151. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts.map +1 -0
  152. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +30 -0
  153. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.js +7 -0
  154. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +30 -0
  155. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +26 -0
  156. package/webpack-loaders/i18n-message-compilation-loader/package.json +4 -0
@@ -0,0 +1,839 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
4
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
5
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
6
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
7
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
8
+ var chalk = require('chalk');
9
+ var omit = require('lodash/omit');
10
+ var prompts = require('prompts');
11
+ var applicationConfig = require('@commercetools-frontend/application-config');
12
+ var credentialsStorage$1 = require('./credentials-storage-dc849808.cjs.prod.js');
13
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
14
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
15
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
16
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
17
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
18
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
19
+ var _repeatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/repeat');
20
+ var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
21
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
22
+ var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
23
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
24
+ var graphqlRequests = require('./graphql-requests-db54706e.cjs.prod.js');
25
+ require('@commercetools/http-user-agent');
26
+ require('./package-a7096308.cjs.prod.js');
27
+ require('@babel/runtime-corejs3/helpers/classCallCheck');
28
+ require('@babel/runtime-corejs3/helpers/createClass');
29
+ require('@babel/runtime-corejs3/core-js-stable/date/now');
30
+ require('fs');
31
+ require('os');
32
+ require('path');
33
+ require('./does-file-exist-be53305d.cjs.prod.js');
34
+ require('node:fs');
35
+ require('@babel/runtime-corejs3/core-js-stable/instance/some');
36
+ require('graphql');
37
+ require('graphql-request');
38
+ require('@commercetools-frontend/constants');
39
+
40
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
41
+
42
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
43
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
44
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
45
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
46
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
47
+ var omit__default = /*#__PURE__*/_interopDefault(omit);
48
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
49
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
50
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
51
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
52
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
53
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
54
+ var _repeatInstanceProperty__default = /*#__PURE__*/_interopDefault(_repeatInstanceProperty);
55
+ var _Set__default = /*#__PURE__*/_interopDefault(_Set);
56
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
57
+ var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
58
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
59
+
60
+ function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
61
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context7, _context8; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context7 = ownKeys(Object(t), !0)).call(_context7, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context8 = ownKeys(Object(t))).call(_context8, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
62
+ const red = str => {
63
+ return chalk__default["default"].red(str);
64
+ };
65
+ const green = str => {
66
+ return chalk__default["default"].green(str);
67
+ };
68
+
69
+ // Two spaces are used for indentation.
70
+ const indent = indentLevel => {
71
+ var _context;
72
+ return _repeatInstanceProperty__default["default"](_context = ' ').call(_context, indentLevel);
73
+ };
74
+ const getStringDiff = _ref => {
75
+ let previousValue = _ref.previousValue,
76
+ nextValue = _ref.nextValue,
77
+ label = _ref.label,
78
+ _ref$indentLevel = _ref.indentLevel,
79
+ indentLevel = _ref$indentLevel === void 0 ? 0 : _ref$indentLevel;
80
+ if (!previousValue && nextValue) {
81
+ return `${indent(indentLevel)}${label} added: ${green(nextValue)}`;
82
+ }
83
+ if (previousValue && !nextValue) {
84
+ return `${indent(indentLevel)}${label} removed: ${red(previousValue)}`;
85
+ }
86
+ if (previousValue && nextValue && previousValue !== nextValue) {
87
+ return `${indent(indentLevel)}${label} changed: ${red(previousValue)} => ${green(nextValue)}`;
88
+ }
89
+ return null;
90
+ };
91
+ // NOTE: this assumes that the array values are scalar values (not objects).
92
+ const getArrayDiff = _ref2 => {
93
+ let previousValue = _ref2.previousValue,
94
+ nextValue = _ref2.nextValue,
95
+ label = _ref2.label,
96
+ _ref2$indentLevel = _ref2.indentLevel,
97
+ indentLevel = _ref2$indentLevel === void 0 ? 0 : _ref2$indentLevel;
98
+ const oldArraySet = new _Set__default["default"](previousValue);
99
+ const arrayDiff = [];
100
+ nextValue?.forEach(item => {
101
+ if (oldArraySet.has(item)) {
102
+ oldArraySet.delete(item);
103
+ } else {
104
+ arrayDiff.push(getStringDiff({
105
+ nextValue: item,
106
+ label,
107
+ indentLevel
108
+ }));
109
+ }
110
+ });
111
+ _forEachInstanceProperty__default["default"](oldArraySet).call(oldArraySet, item => {
112
+ arrayDiff.push(getStringDiff({
113
+ previousValue: item,
114
+ label,
115
+ indentLevel
116
+ }));
117
+ });
118
+ return arrayDiff.join('\n');
119
+ };
120
+ const getPermissionsDiff = _ref3 => {
121
+ var _context2;
122
+ let previousValue = _ref3.previousValue,
123
+ nextValue = _ref3.nextValue;
124
+ const permissionDiff = ['permissions changed'];
125
+ const mappedOldPermissions = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousPermission, _ref4) => {
126
+ let name = _ref4.name,
127
+ oAuthScopes = _ref4.oAuthScopes;
128
+ return _objectSpread(_objectSpread({}, previousPermission), {}, {
129
+ [name]: oAuthScopes
130
+ });
131
+ }, {});
132
+ const indentLevel = 1;
133
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newPermission => {
134
+ const currentDiff = [`${indent(indentLevel)}"${newPermission.name}" changed`];
135
+ // if the permission name is not in the old config, it means it is a new addition.
136
+ if (!mappedOldPermissions[newPermission.name]) {
137
+ permissionDiff.push(`${indent(indentLevel)}"${green(newPermission.name)}" was added`);
138
+ }
139
+
140
+ // if permission name is in the old config, now we check if there was a change
141
+ else {
142
+ currentDiff.push(getArrayDiff({
143
+ previousValue: mappedOldPermissions[newPermission.name],
144
+ nextValue: newPermission.oAuthScopes,
145
+ label: 'oauth scope',
146
+ indentLevel: 2
147
+ }));
148
+ delete mappedOldPermissions[newPermission.name];
149
+ }
150
+ _filterInstanceProperty__default["default"](currentDiff).call(currentDiff, Boolean).length > 1 && permissionDiff.push(currentDiff.join('\n'));
151
+ });
152
+
153
+ // if there are old permissions left, it means they were deleted in the new Permissions.
154
+ _forEachInstanceProperty__default["default"](_context2 = _Object$keys__default["default"](mappedOldPermissions)).call(_context2, oldPermissionName => {
155
+ permissionDiff.push(`${indent(indentLevel)}"${red(oldPermissionName)}" was removed`);
156
+ });
157
+ if (permissionDiff.length > 1) return permissionDiff.join('\n');
158
+ return null;
159
+ };
160
+ const getLabelAllLocalesDiff = _ref5 => {
161
+ var _context3;
162
+ let _ref5$previousValue = _ref5.previousValue,
163
+ previousValue = _ref5$previousValue === void 0 ? [] : _ref5$previousValue,
164
+ _ref5$nextValue = _ref5.nextValue,
165
+ nextValue = _ref5$nextValue === void 0 ? [] : _ref5$nextValue,
166
+ _ref5$indentLevel = _ref5.indentLevel,
167
+ indentLevel = _ref5$indentLevel === void 0 ? 0 : _ref5$indentLevel;
168
+ const labelAllLocalesDiff = [`${indent(indentLevel - 1)}labelAllLocales changed`];
169
+ const mappedOldLabelAllLocales = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousLabelAllLocale, _ref6) => {
170
+ let locale = _ref6.locale,
171
+ value = _ref6.value;
172
+ return _objectSpread(_objectSpread({}, previousLabelAllLocale), {}, {
173
+ [locale]: value
174
+ });
175
+ }, {});
176
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newLabelAllLocale => {
177
+ if (newLabelAllLocale.locale in mappedOldLabelAllLocales) {
178
+ const oldLocaleValue = mappedOldLabelAllLocales[newLabelAllLocale.locale];
179
+ if (oldLocaleValue !== newLabelAllLocale.value) {
180
+ labelAllLocalesDiff.push(`${indent(indentLevel)}locale "${newLabelAllLocale.locale}" changed: ${red(oldLocaleValue)} => ${green(newLabelAllLocale.value)}`);
181
+ }
182
+ delete mappedOldLabelAllLocales[newLabelAllLocale.locale];
183
+ } else {
184
+ const localeDiff = getStringDiff({
185
+ nextValue: newLabelAllLocale.locale,
186
+ label: 'locale',
187
+ indentLevel
188
+ });
189
+ if (localeDiff) {
190
+ labelAllLocalesDiff.push(localeDiff);
191
+ }
192
+ }
193
+ });
194
+ _forEachInstanceProperty__default["default"](_context3 = _Object$keys__default["default"](mappedOldLabelAllLocales)).call(_context3, key => {
195
+ const localeDiff = getStringDiff({
196
+ previousValue: key,
197
+ label: 'locale',
198
+ indentLevel
199
+ });
200
+ if (localeDiff) {
201
+ labelAllLocalesDiff.push(localeDiff);
202
+ }
203
+ });
204
+ if (labelAllLocalesDiff.length > 1) return labelAllLocalesDiff.join('\n');
205
+ return null;
206
+ };
207
+ const getTypeSettingsDiff = _ref7 => {
208
+ var _context4;
209
+ let previousValue = _ref7.previousValue,
210
+ nextValue = _ref7.nextValue;
211
+ const nonNullablePreviousValue = previousValue || {};
212
+ const nonNullableNextValue = nextValue || {};
213
+ const indentLevel = 1;
214
+ const typeSettingsDiff = [`${indent(indentLevel - 1)}type settings changed`];
215
+ _forEachInstanceProperty__default["default"](_context4 = _Object$keys__default["default"](nonNullablePreviousValue)).call(_context4, key => {
216
+ const typeSettingDiff = getStringDiff({
217
+ previousValue: nonNullablePreviousValue[key],
218
+ nextValue: nonNullableNextValue[key],
219
+ label: key,
220
+ indentLevel
221
+ });
222
+ if (typeSettingDiff) {
223
+ typeSettingsDiff.push(typeSettingDiff);
224
+ }
225
+ });
226
+ if (typeSettingsDiff.length > 1) return typeSettingsDiff.join('\n');
227
+ return null;
228
+ };
229
+ const getLocatorsDiff = _ref8 => {
230
+ let previousValue = _ref8.previousValue,
231
+ nextValue = _ref8.nextValue;
232
+ const diff = [];
233
+ const locatorsDiff = getArrayDiff({
234
+ previousValue: previousValue,
235
+ nextValue: nextValue,
236
+ label: 'locators',
237
+ indentLevel: 1
238
+ });
239
+ if (locatorsDiff) {
240
+ diff.push('locators changed');
241
+ diff.push(locatorsDiff);
242
+ }
243
+ return diff.join('\n');
244
+ };
245
+ const getMainMenuLinkDiff = _ref9 => {
246
+ let previousValue = _ref9.previousValue,
247
+ nextValue = _ref9.nextValue;
248
+ const mainMenuLinkDiff = ['mainMenuLink changed'];
249
+ const menuDiff = getStringDiff({
250
+ previousValue: previousValue.defaultLabel,
251
+ nextValue: nextValue.defaultLabel,
252
+ label: 'defaultLabel',
253
+ indentLevel: 1
254
+ });
255
+ if (menuDiff) {
256
+ mainMenuLinkDiff.push(menuDiff);
257
+ }
258
+ const mainMenuLinkPermissionsDiff = getArrayDiff({
259
+ previousValue: previousValue.permissions,
260
+ nextValue: nextValue.permissions,
261
+ label: 'applied permission',
262
+ indentLevel: 2
263
+ });
264
+ if (mainMenuLinkPermissionsDiff.length > 0) {
265
+ mainMenuLinkDiff.push(`${indent(1)}permissions changed`);
266
+ mainMenuLinkDiff.push(mainMenuLinkPermissionsDiff);
267
+ }
268
+ const menuLabelsDiff = getLabelAllLocalesDiff({
269
+ previousValue: previousValue.labelAllLocales,
270
+ nextValue: nextValue.labelAllLocales,
271
+ indentLevel: 2
272
+ });
273
+ if (menuLabelsDiff) {
274
+ mainMenuLinkDiff.push(menuLabelsDiff);
275
+ }
276
+ const filteredMainMenuLinkDiff = _filterInstanceProperty__default["default"](mainMenuLinkDiff).call(mainMenuLinkDiff, Boolean);
277
+ if (filteredMainMenuLinkDiff.length > 1) return filteredMainMenuLinkDiff.join('\n');
278
+ return null;
279
+ };
280
+ const getSubmenuLinksDiff = _ref10 => {
281
+ var _context6;
282
+ let previousValue = _ref10.previousValue,
283
+ nextValue = _ref10.nextValue;
284
+ const submenuLinksDiff = ['submenuLink changed'];
285
+ const mappedSubmenuLinks = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousSubmenuLink, currentSubmenuLink) => _objectSpread(_objectSpread({}, previousSubmenuLink), {}, {
286
+ [currentSubmenuLink.uriPath]: currentSubmenuLink
287
+ }), {});
288
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newSubmenuLink => {
289
+ const oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
290
+ if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
291
+ var _context5;
292
+ const submenuLinkDiff = [`${indent(1)}menu link "${newSubmenuLink.uriPath}" changed`];
293
+ _forEachInstanceProperty__default["default"](_context5 = _Object$keys__default["default"](mappedSubmenuLinks[newSubmenuLink.uriPath])).call(_context5, key => {
294
+ switch (key) {
295
+ case 'defaultLabel':
296
+ {
297
+ const labelDiff = getStringDiff({
298
+ previousValue: oldSubMenuLink.defaultLabel,
299
+ nextValue: newSubmenuLink.defaultLabel,
300
+ label: 'defaultLabel',
301
+ indentLevel: 2
302
+ });
303
+ if (labelDiff) {
304
+ submenuLinkDiff.push(labelDiff);
305
+ }
306
+ break;
307
+ }
308
+ case 'permissions':
309
+ {
310
+ const submenuLinkPermissionsDiff = getArrayDiff({
311
+ previousValue: oldSubMenuLink.permissions,
312
+ nextValue: newSubmenuLink.permissions,
313
+ label: 'applied permission',
314
+ indentLevel: 3
315
+ });
316
+ if (submenuLinkPermissionsDiff.length > 0) {
317
+ submenuLinkDiff.push(`${indent(2)}permissions changed`);
318
+ submenuLinkDiff.push(submenuLinkPermissionsDiff);
319
+ }
320
+ break;
321
+ }
322
+ case 'labelAllLocales':
323
+ {
324
+ const labelsDiff = getLabelAllLocalesDiff({
325
+ previousValue: oldSubMenuLink.labelAllLocales,
326
+ nextValue: newSubmenuLink.labelAllLocales,
327
+ indentLevel: 3
328
+ });
329
+ if (labelsDiff) {
330
+ submenuLinkDiff.push(labelsDiff);
331
+ }
332
+ break;
333
+ }
334
+ }
335
+ });
336
+ delete mappedSubmenuLinks[newSubmenuLink.uriPath];
337
+ const filteredSubmenuLinksDiff = _filterInstanceProperty__default["default"](submenuLinkDiff).call(submenuLinkDiff, Boolean);
338
+ if (filteredSubmenuLinksDiff.length > 1) {
339
+ submenuLinksDiff.push(filteredSubmenuLinksDiff.join('\n'));
340
+ }
341
+ } else {
342
+ const linksDiff = getStringDiff({
343
+ nextValue: newSubmenuLink.uriPath,
344
+ label: 'menu link',
345
+ indentLevel: 1
346
+ });
347
+ if (linksDiff) {
348
+ submenuLinksDiff.push(linksDiff);
349
+ }
350
+ }
351
+ });
352
+ _forEachInstanceProperty__default["default"](_context6 = _Object$keys__default["default"](mappedSubmenuLinks)).call(_context6, key => {
353
+ const linksDiff = getStringDiff({
354
+ previousValue: key,
355
+ label: 'menu link',
356
+ indentLevel: 1
357
+ });
358
+ if (linksDiff) submenuLinksDiff.push(linksDiff);
359
+ });
360
+ if (submenuLinksDiff.length > 1) return submenuLinksDiff.join('\n');
361
+ return null;
362
+ };
363
+
364
+ // Compute diff changes of the Custom Application config.
365
+ // NOTE: Only known keys are evaluated.
366
+ const getCustomApplicationConfigDiff = (oldConfig, newConfig) => {
367
+ const diff = [];
368
+
369
+ // Name
370
+ const nameDiff = getStringDiff({
371
+ previousValue: oldConfig.name,
372
+ nextValue: newConfig.name,
373
+ label: 'name'
374
+ });
375
+ if (nameDiff) {
376
+ diff.push(nameDiff);
377
+ }
378
+
379
+ // Description
380
+ const descriptionDiff = getStringDiff({
381
+ previousValue: oldConfig.description,
382
+ nextValue: newConfig.description,
383
+ label: 'description'
384
+ });
385
+ if (descriptionDiff) {
386
+ diff.push(descriptionDiff);
387
+ }
388
+
389
+ // URL
390
+ const urlDiff = getStringDiff({
391
+ previousValue: oldConfig.url,
392
+ nextValue: newConfig.url,
393
+ label: 'url'
394
+ });
395
+ if (urlDiff) {
396
+ diff.push(urlDiff);
397
+ }
398
+
399
+ // Icon
400
+ const iconDiff = getStringDiff({
401
+ // This icon stored in the database has already been sanitized.
402
+ previousValue: oldConfig.icon,
403
+ // Sanitize the raw icon as-if it was stored in the database,
404
+ // to ensure the data can be safely compared.
405
+ nextValue: applicationConfig.sanitizeSvg(newConfig.icon),
406
+ label: 'icon'
407
+ });
408
+ if (iconDiff) {
409
+ diff.push(iconDiff);
410
+ }
411
+
412
+ // Permissions
413
+ const permissionsDiff = getPermissionsDiff({
414
+ previousValue: oldConfig.permissions,
415
+ nextValue: newConfig.permissions
416
+ });
417
+ if (permissionsDiff) {
418
+ diff.push(permissionsDiff);
419
+ }
420
+
421
+ // Main menu link
422
+ const mainMenuDiff = getMainMenuLinkDiff({
423
+ previousValue: oldConfig.mainMenuLink,
424
+ nextValue: newConfig.mainMenuLink
425
+ });
426
+ if (mainMenuDiff) {
427
+ diff.push(mainMenuDiff);
428
+ }
429
+
430
+ // Submenu links
431
+ const submenuDiff = getSubmenuLinksDiff({
432
+ previousValue: oldConfig.submenuLinks,
433
+ nextValue: newConfig.submenuLinks
434
+ });
435
+ if (submenuDiff) {
436
+ diff.push(submenuDiff);
437
+ }
438
+ return diff.join('\n');
439
+ };
440
+
441
+ // Compute diff changes of the Custom View config.
442
+ // NOTE: Only known keys are evaluated.
443
+ const getCustomViewConfigDiff = (oldConfig, newConfig) => {
444
+ const diff = [];
445
+
446
+ // Default Label
447
+ const defaultLabelDiff = getStringDiff({
448
+ previousValue: oldConfig.defaultLabel,
449
+ nextValue: newConfig.defaultLabel,
450
+ label: 'defaultLabel'
451
+ });
452
+ if (defaultLabelDiff) {
453
+ diff.push(defaultLabelDiff);
454
+ }
455
+
456
+ // Description
457
+ const descriptionDiff = getStringDiff({
458
+ previousValue: oldConfig.description,
459
+ nextValue: newConfig.description,
460
+ label: 'description'
461
+ });
462
+ if (descriptionDiff) {
463
+ diff.push(descriptionDiff);
464
+ }
465
+
466
+ // URL
467
+ const urlDiff = getStringDiff({
468
+ previousValue: oldConfig.url,
469
+ nextValue: newConfig.url,
470
+ label: 'url'
471
+ });
472
+ if (urlDiff) {
473
+ diff.push(urlDiff);
474
+ }
475
+
476
+ // Type
477
+ const typeDiff = getStringDiff({
478
+ previousValue: oldConfig.type,
479
+ nextValue: newConfig.type,
480
+ label: 'type'
481
+ });
482
+ if (typeDiff) {
483
+ diff.push(typeDiff);
484
+ }
485
+
486
+ // Permissions
487
+ const permissionsDiff = getPermissionsDiff({
488
+ previousValue: oldConfig.permissions,
489
+ nextValue: newConfig.permissions
490
+ });
491
+ if (permissionsDiff) {
492
+ diff.push(permissionsDiff);
493
+ }
494
+
495
+ // Label All Locales
496
+ const labelsDiff = getLabelAllLocalesDiff({
497
+ previousValue: oldConfig.labelAllLocales,
498
+ nextValue: newConfig.labelAllLocales,
499
+ indentLevel: 1
500
+ });
501
+ if (labelsDiff) {
502
+ diff.push(labelsDiff);
503
+ }
504
+
505
+ // Type settings
506
+ const typeSettingsDiff = getTypeSettingsDiff({
507
+ previousValue: oldConfig.typeSettings,
508
+ nextValue: newConfig.typeSettings
509
+ });
510
+ if (typeSettingsDiff) {
511
+ diff.push(typeSettingsDiff);
512
+ }
513
+
514
+ // Locators
515
+ const locatorsDiff = getLocatorsDiff({
516
+ previousValue: oldConfig.locators,
517
+ nextValue: newConfig.locators
518
+ });
519
+ if (locatorsDiff) {
520
+ diff.push(locatorsDiff);
521
+ }
522
+ return diff.join('\n');
523
+ };
524
+
525
+ const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
526
+ const getMcUrlLink = _ref => {
527
+ let mcApiUrl = _ref.mcApiUrl,
528
+ organizationId = _ref.organizationId,
529
+ customEntityId = _ref.customEntityId,
530
+ isCustomView = _ref.isCustomView;
531
+ const mcUrl = mcApiUrl.replace('mc-api', 'mc');
532
+ const customEntityLink = `${mcUrl}/account/organizations/${organizationId}/custom-${isCustomView ? 'views' : 'applications'}/owned/${customEntityId}`;
533
+ return customEntityLink;
534
+ };
535
+ const isCustomViewData = data => data.entryPointUriPath === undefined;
536
+ async function createOrUpdateCustomApplication(_ref2) {
537
+ var _context3;
538
+ let mcApiUrl = _ref2.mcApiUrl,
539
+ localCustomEntityData = _ref2.localCustomEntityData,
540
+ applicationIdentifier = _ref2.applicationIdentifier,
541
+ options = _ref2.options;
542
+ const fetchedCustomApplication = await graphqlRequests.fetchCustomApplication({
543
+ mcApiUrl,
544
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
545
+ applicationIdentifier
546
+ });
547
+ if (!fetchedCustomApplication) {
548
+ var _context2;
549
+ const userOrganizations = await graphqlRequests.fetchUserOrganizations({
550
+ mcApiUrl,
551
+ applicationIdentifier
552
+ });
553
+ let organizationId, organizationName;
554
+ if (userOrganizations.total === 0) {
555
+ throw new Error(`It seems you are not an admin of any Organization. Please make sure to be part of the Administrators team of the Organization you want the Custom Application to be configured to.`);
556
+ }
557
+ if (userOrganizations.total === 1) {
558
+ const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
559
+ organization = _userOrganizations$re[0];
560
+ organizationId = organization.id;
561
+ organizationName = organization.name;
562
+ } else {
563
+ var _context;
564
+ const organizationChoices = _mapInstanceProperty__default["default"](_context = userOrganizations.results).call(_context, organization => ({
565
+ title: organization.name,
566
+ value: organization.id
567
+ }));
568
+ const _await$prompts = await prompts__default["default"]({
569
+ type: 'select',
570
+ name: 'organizationId',
571
+ message: 'Select an Organization',
572
+ choices: organizationChoices,
573
+ initial: 0
574
+ }),
575
+ selectedOrganizationId = _await$prompts.organizationId;
576
+ if (!selectedOrganizationId) {
577
+ throw new Error(`No Organization selected, aborting.`);
578
+ }
579
+ organizationId = selectedOrganizationId;
580
+ organizationName = _findInstanceProperty__default["default"](organizationChoices).call(organizationChoices, _ref3 => {
581
+ let value = _ref3.value;
582
+ return value === organizationId;
583
+ }).title;
584
+ }
585
+ const _await$prompts2 = await prompts__default["default"]({
586
+ type: 'text',
587
+ name: 'confirmation',
588
+ message: _filterInstanceProperty__default["default"](_context2 = [`You are about to create a new Custom Application in the "${chalk__default["default"].green(organizationName)}" organization. Are you sure you want to proceed?`, options.dryRun && chalk__default["default"].gray('Using "--dry-run", no data will be created.')]).call(_context2, Boolean).join('\n'),
589
+ initial: 'yes'
590
+ }),
591
+ confirmation = _await$prompts2.confirmation;
592
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
593
+ console.log(chalk__default["default"].red('Aborted.'));
594
+ return;
595
+ }
596
+ const data = omit__default["default"](localCustomEntityData, ['id']);
597
+ if (options.dryRun) {
598
+ console.log();
599
+ console.log(`The following payload would be used to create a new Custom Application.`);
600
+ console.log();
601
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
602
+ return;
603
+ }
604
+ const createdCustomApplication = await graphqlRequests.createCustomApplication({
605
+ mcApiUrl,
606
+ organizationId,
607
+ data,
608
+ applicationIdentifier
609
+ });
610
+
611
+ // This check is technically not necessary, as the `graphql-request` client
612
+ // throws an error in case of GraphQL errors.
613
+ // However, the generated TypeScript data related to the GraphQL query has the
614
+ // field typed as optional, thus having an extra check for type correctness.
615
+ if (!createdCustomApplication) {
616
+ throw new Error('Failed to create the Custom Application.');
617
+ }
618
+ const customAppLink = getMcUrlLink({
619
+ mcApiUrl,
620
+ organizationId,
621
+ customEntityId: createdCustomApplication.id
622
+ });
623
+ console.log(chalk__default["default"].green(`Custom Application created.\nPlease update the "env.production.applicationId" field in your local Custom Application config file with the following value: "${chalk__default["default"].green(createdCustomApplication.id)}".`));
624
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk__default["default"].gray(customAppLink)}".`);
625
+ return;
626
+ }
627
+ const customAppLink = getMcUrlLink({
628
+ mcApiUrl,
629
+ organizationId: fetchedCustomApplication.organizationId,
630
+ customEntityId: fetchedCustomApplication.application.id
631
+ });
632
+ const configDiff = getCustomApplicationConfigDiff(fetchedCustomApplication.application, localCustomEntityData);
633
+ if (!configDiff) {
634
+ console.log(chalk__default["default"].green(`Custom Application up-to-date.`));
635
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk__default["default"].gray(customAppLink)}".`);
636
+ return;
637
+ }
638
+ console.log('Changes detected:');
639
+ console.log(configDiff);
640
+ console.log();
641
+ const _await$prompts3 = await prompts__default["default"]({
642
+ type: 'text',
643
+ name: 'confirmation',
644
+ message: _filterInstanceProperty__default["default"](_context3 = [`You are about to update the Custom Application "${chalk__default["default"].green(localCustomEntityData.entryPointUriPath)}" with the changes above. Are you sure you want to proceed?`, options.dryRun && chalk__default["default"].gray('Using "--dry-run", no data will be updated.')]).call(_context3, Boolean).join('\n'),
645
+ initial: 'yes'
646
+ }),
647
+ confirmation = _await$prompts3.confirmation;
648
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
649
+ console.log(chalk__default["default"].red('Aborted.'));
650
+ return;
651
+ }
652
+ const data = omit__default["default"](localCustomEntityData, ['id']);
653
+ if (options.dryRun) {
654
+ console.log();
655
+ console.log(`The following payload would be used to update the Custom Application "${chalk__default["default"].green(data.entryPointUriPath)}".`);
656
+ console.log();
657
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
658
+ return;
659
+ }
660
+ await graphqlRequests.updateCustomApplication({
661
+ mcApiUrl,
662
+ organizationId: fetchedCustomApplication.organizationId,
663
+ data: omit__default["default"](localCustomEntityData, ['id']),
664
+ applicationId: fetchedCustomApplication.application.id,
665
+ applicationIdentifier
666
+ });
667
+ console.log(chalk__default["default"].green(`Custom Application updated.`));
668
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk__default["default"].gray(customAppLink)}".`);
669
+ }
670
+ async function createOrUpdateCustomView(_ref4) {
671
+ var _context6;
672
+ let mcApiUrl = _ref4.mcApiUrl,
673
+ localCustomEntityData = _ref4.localCustomEntityData,
674
+ customViewId = _ref4.customViewId,
675
+ options = _ref4.options,
676
+ applicationIdentifier = _ref4.applicationIdentifier;
677
+ const fetchedCustomView = await graphqlRequests.fetchCustomView({
678
+ mcApiUrl,
679
+ customViewId,
680
+ applicationIdentifier
681
+ });
682
+ if (!fetchedCustomView) {
683
+ var _context5;
684
+ const userOrganizations = await graphqlRequests.fetchUserOrganizations({
685
+ mcApiUrl,
686
+ customViewId,
687
+ applicationIdentifier
688
+ });
689
+ let organizationId, organizationName;
690
+ if (userOrganizations.total === 0) {
691
+ throw new Error(`It seems you are not an admin of any Organization. Please make sure to be part of the Administrators team of the Organization you want the Custom View to be configured to.`);
692
+ }
693
+ if (userOrganizations.total === 1) {
694
+ const _userOrganizations$re2 = _slicedToArray(userOrganizations.results, 1),
695
+ organization = _userOrganizations$re2[0];
696
+ organizationId = organization.id;
697
+ organizationName = organization.name;
698
+ } else {
699
+ var _context4;
700
+ const organizationChoices = _mapInstanceProperty__default["default"](_context4 = userOrganizations.results).call(_context4, organization => ({
701
+ title: organization.name,
702
+ value: organization.id
703
+ }));
704
+ const _await$prompts4 = await prompts__default["default"]({
705
+ type: 'select',
706
+ name: 'organizationId',
707
+ message: 'Select an Organization',
708
+ choices: organizationChoices,
709
+ initial: 0
710
+ }),
711
+ selectedOrganizationId = _await$prompts4.organizationId;
712
+ if (!selectedOrganizationId) {
713
+ throw new Error(`No Organization selected, aborting.`);
714
+ }
715
+ organizationId = selectedOrganizationId;
716
+ organizationName = _findInstanceProperty__default["default"](organizationChoices).call(organizationChoices, _ref5 => {
717
+ let value = _ref5.value;
718
+ return value === organizationId;
719
+ }).title;
720
+ }
721
+ const _await$prompts5 = await prompts__default["default"]({
722
+ type: 'text',
723
+ name: 'confirmation',
724
+ message: _filterInstanceProperty__default["default"](_context5 = [`You are about to create a new Custom View in the "${chalk__default["default"].green(organizationName)}" organization. Are you sure you want to proceed?`, options.dryRun && chalk__default["default"].gray('Using "--dry-run", no data will be created.')]).call(_context5, Boolean).join('\n'),
725
+ initial: 'yes'
726
+ }),
727
+ confirmation = _await$prompts5.confirmation;
728
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
729
+ console.log(chalk__default["default"].red('Aborted.'));
730
+ return;
731
+ }
732
+ const data = omit__default["default"](localCustomEntityData, ['id']);
733
+ if (options.dryRun) {
734
+ console.log();
735
+ console.log(`The following payload would be used to create a new Custom View.`);
736
+ console.log();
737
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
738
+ return;
739
+ }
740
+ const createdCustomView = await graphqlRequests.createCustomView({
741
+ mcApiUrl,
742
+ organizationId,
743
+ data,
744
+ applicationIdentifier
745
+ });
746
+
747
+ // This check is technically not necessary, as the `graphql-request` client
748
+ // throws an error in case of GraphQL errors.
749
+ // However, the generated TypeScript data related to the GraphQL query has the
750
+ // field typed as optional, thus having an extra check for type correctness.
751
+ if (!createdCustomView) {
752
+ throw new Error('Failed to create the Custom View.');
753
+ }
754
+ const customViewLink = getMcUrlLink({
755
+ mcApiUrl,
756
+ organizationId,
757
+ customEntityId: createdCustomView.id,
758
+ isCustomView: true
759
+ });
760
+ console.log(chalk__default["default"].green(`Custom View created.\nPlease update the "env.production.customViewId" field in your local Custom View config file with the following value: "${chalk__default["default"].green(createdCustomView.id)}".`));
761
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk__default["default"].gray(customViewLink)}".`);
762
+ return;
763
+ }
764
+ const customViewLink = getMcUrlLink({
765
+ mcApiUrl,
766
+ organizationId: fetchedCustomView.organizationId,
767
+ customEntityId: fetchedCustomView?.customView?.id || '',
768
+ isCustomView: true
769
+ });
770
+ const configDiff = getCustomViewConfigDiff(fetchedCustomView.customView, localCustomEntityData);
771
+ if (!configDiff) {
772
+ console.log(chalk__default["default"].green(`Custom View up-to-date.`));
773
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk__default["default"].gray(customViewLink)}".`);
774
+ return;
775
+ }
776
+ console.log('Changes detected:');
777
+ console.log(configDiff);
778
+ console.log();
779
+ const _await$prompts6 = await prompts__default["default"]({
780
+ type: 'text',
781
+ name: 'confirmation',
782
+ message: _filterInstanceProperty__default["default"](_context6 = [`You are about to update the Custom View "${chalk__default["default"].green(localCustomEntityData.defaultLabel)}" with the changes above. Are you sure you want to proceed?`, options.dryRun && chalk__default["default"].gray('Using "--dry-run", no data will be updated.')]).call(_context6, Boolean).join('\n'),
783
+ initial: 'yes'
784
+ }),
785
+ confirmation = _await$prompts6.confirmation;
786
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
787
+ console.log(chalk__default["default"].red('Aborted.'));
788
+ return;
789
+ }
790
+ const data = omit__default["default"](localCustomEntityData, ['id']);
791
+ if (options.dryRun) {
792
+ console.log();
793
+ console.log(`The following payload would be used to update the Custom View "${chalk__default["default"].green(data.defaultLabel)}".`);
794
+ console.log();
795
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
796
+ return;
797
+ }
798
+ await graphqlRequests.updateCustomView({
799
+ mcApiUrl,
800
+ organizationId: fetchedCustomView.organizationId,
801
+ data: omit__default["default"](localCustomEntityData, ['id']),
802
+ customViewId: fetchedCustomView?.customView?.id || '',
803
+ applicationIdentifier
804
+ });
805
+ console.log(chalk__default["default"].green(`Custom View updated.`));
806
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk__default["default"].gray(customViewLink)}".`);
807
+ }
808
+ async function run(options) {
809
+ const applicationConfig$1 = applicationConfig.processConfig();
810
+ const localCustomEntityData = applicationConfig$1.data;
811
+ const _applicationConfig$en = applicationConfig$1.env,
812
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
813
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier,
814
+ customViewId = _applicationConfig$en.customViewId;
815
+ console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
816
+ console.log();
817
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
818
+ if (!isSessionValid) {
819
+ throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
820
+ }
821
+ if (isCustomViewData(localCustomEntityData)) {
822
+ createOrUpdateCustomView({
823
+ mcApiUrl,
824
+ localCustomEntityData,
825
+ applicationIdentifier,
826
+ customViewId: customViewId || localCustomEntityData.id,
827
+ options
828
+ });
829
+ } else {
830
+ createOrUpdateCustomApplication({
831
+ mcApiUrl,
832
+ localCustomEntityData,
833
+ applicationIdentifier,
834
+ options
835
+ });
836
+ }
837
+ }
838
+
839
+ exports["default"] = run;