@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,845 @@
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-3cea94ea.cjs.dev.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-733aac06.cjs.dev.js');
25
+ require('@commercetools/http-user-agent');
26
+ require('./package-436331e6.cjs.dev.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-eb86baca.cjs.dev.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
+
63
+ // Since not all terminal supports colors, to make things more consistent for testing purposes,
64
+ // during tests the color used is appended before the string instead of coloring it.
65
+ const isTest = process.env.NODE_ENV === 'test';
66
+ const red = str => {
67
+ if (isTest) return `<color-red>${str}</color-red>`;
68
+ return chalk__default["default"].red(str);
69
+ };
70
+ const green = str => {
71
+ if (isTest) return `<color-green>${str}</color-green>`;
72
+ return chalk__default["default"].green(str);
73
+ };
74
+
75
+ // Two spaces are used for indentation.
76
+ const indent = indentLevel => {
77
+ var _context;
78
+ return _repeatInstanceProperty__default["default"](_context = ' ').call(_context, indentLevel);
79
+ };
80
+ const getStringDiff = _ref => {
81
+ let previousValue = _ref.previousValue,
82
+ nextValue = _ref.nextValue,
83
+ label = _ref.label,
84
+ _ref$indentLevel = _ref.indentLevel,
85
+ indentLevel = _ref$indentLevel === void 0 ? 0 : _ref$indentLevel;
86
+ if (!previousValue && nextValue) {
87
+ return `${indent(indentLevel)}${label} added: ${green(nextValue)}`;
88
+ }
89
+ if (previousValue && !nextValue) {
90
+ return `${indent(indentLevel)}${label} removed: ${red(previousValue)}`;
91
+ }
92
+ if (previousValue && nextValue && previousValue !== nextValue) {
93
+ return `${indent(indentLevel)}${label} changed: ${red(previousValue)} => ${green(nextValue)}`;
94
+ }
95
+ return null;
96
+ };
97
+ // NOTE: this assumes that the array values are scalar values (not objects).
98
+ const getArrayDiff = _ref2 => {
99
+ let previousValue = _ref2.previousValue,
100
+ nextValue = _ref2.nextValue,
101
+ label = _ref2.label,
102
+ _ref2$indentLevel = _ref2.indentLevel,
103
+ indentLevel = _ref2$indentLevel === void 0 ? 0 : _ref2$indentLevel;
104
+ const oldArraySet = new _Set__default["default"](previousValue);
105
+ const arrayDiff = [];
106
+ nextValue?.forEach(item => {
107
+ if (oldArraySet.has(item)) {
108
+ oldArraySet.delete(item);
109
+ } else {
110
+ arrayDiff.push(getStringDiff({
111
+ nextValue: item,
112
+ label,
113
+ indentLevel
114
+ }));
115
+ }
116
+ });
117
+ _forEachInstanceProperty__default["default"](oldArraySet).call(oldArraySet, item => {
118
+ arrayDiff.push(getStringDiff({
119
+ previousValue: item,
120
+ label,
121
+ indentLevel
122
+ }));
123
+ });
124
+ return arrayDiff.join('\n');
125
+ };
126
+ const getPermissionsDiff = _ref3 => {
127
+ var _context2;
128
+ let previousValue = _ref3.previousValue,
129
+ nextValue = _ref3.nextValue;
130
+ const permissionDiff = ['permissions changed'];
131
+ const mappedOldPermissions = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousPermission, _ref4) => {
132
+ let name = _ref4.name,
133
+ oAuthScopes = _ref4.oAuthScopes;
134
+ return _objectSpread(_objectSpread({}, previousPermission), {}, {
135
+ [name]: oAuthScopes
136
+ });
137
+ }, {});
138
+ const indentLevel = 1;
139
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newPermission => {
140
+ const currentDiff = [`${indent(indentLevel)}"${newPermission.name}" changed`];
141
+ // if the permission name is not in the old config, it means it is a new addition.
142
+ if (!mappedOldPermissions[newPermission.name]) {
143
+ permissionDiff.push(`${indent(indentLevel)}"${green(newPermission.name)}" was added`);
144
+ }
145
+
146
+ // if permission name is in the old config, now we check if there was a change
147
+ else {
148
+ currentDiff.push(getArrayDiff({
149
+ previousValue: mappedOldPermissions[newPermission.name],
150
+ nextValue: newPermission.oAuthScopes,
151
+ label: 'oauth scope',
152
+ indentLevel: 2
153
+ }));
154
+ delete mappedOldPermissions[newPermission.name];
155
+ }
156
+ _filterInstanceProperty__default["default"](currentDiff).call(currentDiff, Boolean).length > 1 && permissionDiff.push(currentDiff.join('\n'));
157
+ });
158
+
159
+ // if there are old permissions left, it means they were deleted in the new Permissions.
160
+ _forEachInstanceProperty__default["default"](_context2 = _Object$keys__default["default"](mappedOldPermissions)).call(_context2, oldPermissionName => {
161
+ permissionDiff.push(`${indent(indentLevel)}"${red(oldPermissionName)}" was removed`);
162
+ });
163
+ if (permissionDiff.length > 1) return permissionDiff.join('\n');
164
+ return null;
165
+ };
166
+ const getLabelAllLocalesDiff = _ref5 => {
167
+ var _context3;
168
+ let _ref5$previousValue = _ref5.previousValue,
169
+ previousValue = _ref5$previousValue === void 0 ? [] : _ref5$previousValue,
170
+ _ref5$nextValue = _ref5.nextValue,
171
+ nextValue = _ref5$nextValue === void 0 ? [] : _ref5$nextValue,
172
+ _ref5$indentLevel = _ref5.indentLevel,
173
+ indentLevel = _ref5$indentLevel === void 0 ? 0 : _ref5$indentLevel;
174
+ const labelAllLocalesDiff = [`${indent(indentLevel - 1)}labelAllLocales changed`];
175
+ const mappedOldLabelAllLocales = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousLabelAllLocale, _ref6) => {
176
+ let locale = _ref6.locale,
177
+ value = _ref6.value;
178
+ return _objectSpread(_objectSpread({}, previousLabelAllLocale), {}, {
179
+ [locale]: value
180
+ });
181
+ }, {});
182
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newLabelAllLocale => {
183
+ if (newLabelAllLocale.locale in mappedOldLabelAllLocales) {
184
+ const oldLocaleValue = mappedOldLabelAllLocales[newLabelAllLocale.locale];
185
+ if (oldLocaleValue !== newLabelAllLocale.value) {
186
+ labelAllLocalesDiff.push(`${indent(indentLevel)}locale "${newLabelAllLocale.locale}" changed: ${red(oldLocaleValue)} => ${green(newLabelAllLocale.value)}`);
187
+ }
188
+ delete mappedOldLabelAllLocales[newLabelAllLocale.locale];
189
+ } else {
190
+ const localeDiff = getStringDiff({
191
+ nextValue: newLabelAllLocale.locale,
192
+ label: 'locale',
193
+ indentLevel
194
+ });
195
+ if (localeDiff) {
196
+ labelAllLocalesDiff.push(localeDiff);
197
+ }
198
+ }
199
+ });
200
+ _forEachInstanceProperty__default["default"](_context3 = _Object$keys__default["default"](mappedOldLabelAllLocales)).call(_context3, key => {
201
+ const localeDiff = getStringDiff({
202
+ previousValue: key,
203
+ label: 'locale',
204
+ indentLevel
205
+ });
206
+ if (localeDiff) {
207
+ labelAllLocalesDiff.push(localeDiff);
208
+ }
209
+ });
210
+ if (labelAllLocalesDiff.length > 1) return labelAllLocalesDiff.join('\n');
211
+ return null;
212
+ };
213
+ const getTypeSettingsDiff = _ref7 => {
214
+ var _context4;
215
+ let previousValue = _ref7.previousValue,
216
+ nextValue = _ref7.nextValue;
217
+ const nonNullablePreviousValue = previousValue || {};
218
+ const nonNullableNextValue = nextValue || {};
219
+ const indentLevel = 1;
220
+ const typeSettingsDiff = [`${indent(indentLevel - 1)}type settings changed`];
221
+ _forEachInstanceProperty__default["default"](_context4 = _Object$keys__default["default"](nonNullablePreviousValue)).call(_context4, key => {
222
+ const typeSettingDiff = getStringDiff({
223
+ previousValue: nonNullablePreviousValue[key],
224
+ nextValue: nonNullableNextValue[key],
225
+ label: key,
226
+ indentLevel
227
+ });
228
+ if (typeSettingDiff) {
229
+ typeSettingsDiff.push(typeSettingDiff);
230
+ }
231
+ });
232
+ if (typeSettingsDiff.length > 1) return typeSettingsDiff.join('\n');
233
+ return null;
234
+ };
235
+ const getLocatorsDiff = _ref8 => {
236
+ let previousValue = _ref8.previousValue,
237
+ nextValue = _ref8.nextValue;
238
+ const diff = [];
239
+ const locatorsDiff = getArrayDiff({
240
+ previousValue: previousValue,
241
+ nextValue: nextValue,
242
+ label: 'locators',
243
+ indentLevel: 1
244
+ });
245
+ if (locatorsDiff) {
246
+ diff.push('locators changed');
247
+ diff.push(locatorsDiff);
248
+ }
249
+ return diff.join('\n');
250
+ };
251
+ const getMainMenuLinkDiff = _ref9 => {
252
+ let previousValue = _ref9.previousValue,
253
+ nextValue = _ref9.nextValue;
254
+ const mainMenuLinkDiff = ['mainMenuLink changed'];
255
+ const menuDiff = getStringDiff({
256
+ previousValue: previousValue.defaultLabel,
257
+ nextValue: nextValue.defaultLabel,
258
+ label: 'defaultLabel',
259
+ indentLevel: 1
260
+ });
261
+ if (menuDiff) {
262
+ mainMenuLinkDiff.push(menuDiff);
263
+ }
264
+ const mainMenuLinkPermissionsDiff = getArrayDiff({
265
+ previousValue: previousValue.permissions,
266
+ nextValue: nextValue.permissions,
267
+ label: 'applied permission',
268
+ indentLevel: 2
269
+ });
270
+ if (mainMenuLinkPermissionsDiff.length > 0) {
271
+ mainMenuLinkDiff.push(`${indent(1)}permissions changed`);
272
+ mainMenuLinkDiff.push(mainMenuLinkPermissionsDiff);
273
+ }
274
+ const menuLabelsDiff = getLabelAllLocalesDiff({
275
+ previousValue: previousValue.labelAllLocales,
276
+ nextValue: nextValue.labelAllLocales,
277
+ indentLevel: 2
278
+ });
279
+ if (menuLabelsDiff) {
280
+ mainMenuLinkDiff.push(menuLabelsDiff);
281
+ }
282
+ const filteredMainMenuLinkDiff = _filterInstanceProperty__default["default"](mainMenuLinkDiff).call(mainMenuLinkDiff, Boolean);
283
+ if (filteredMainMenuLinkDiff.length > 1) return filteredMainMenuLinkDiff.join('\n');
284
+ return null;
285
+ };
286
+ const getSubmenuLinksDiff = _ref10 => {
287
+ var _context6;
288
+ let previousValue = _ref10.previousValue,
289
+ nextValue = _ref10.nextValue;
290
+ const submenuLinksDiff = ['submenuLink changed'];
291
+ const mappedSubmenuLinks = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousSubmenuLink, currentSubmenuLink) => _objectSpread(_objectSpread({}, previousSubmenuLink), {}, {
292
+ [currentSubmenuLink.uriPath]: currentSubmenuLink
293
+ }), {});
294
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newSubmenuLink => {
295
+ const oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
296
+ if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
297
+ var _context5;
298
+ const submenuLinkDiff = [`${indent(1)}menu link "${newSubmenuLink.uriPath}" changed`];
299
+ _forEachInstanceProperty__default["default"](_context5 = _Object$keys__default["default"](mappedSubmenuLinks[newSubmenuLink.uriPath])).call(_context5, key => {
300
+ switch (key) {
301
+ case 'defaultLabel':
302
+ {
303
+ const labelDiff = getStringDiff({
304
+ previousValue: oldSubMenuLink.defaultLabel,
305
+ nextValue: newSubmenuLink.defaultLabel,
306
+ label: 'defaultLabel',
307
+ indentLevel: 2
308
+ });
309
+ if (labelDiff) {
310
+ submenuLinkDiff.push(labelDiff);
311
+ }
312
+ break;
313
+ }
314
+ case 'permissions':
315
+ {
316
+ const submenuLinkPermissionsDiff = getArrayDiff({
317
+ previousValue: oldSubMenuLink.permissions,
318
+ nextValue: newSubmenuLink.permissions,
319
+ label: 'applied permission',
320
+ indentLevel: 3
321
+ });
322
+ if (submenuLinkPermissionsDiff.length > 0) {
323
+ submenuLinkDiff.push(`${indent(2)}permissions changed`);
324
+ submenuLinkDiff.push(submenuLinkPermissionsDiff);
325
+ }
326
+ break;
327
+ }
328
+ case 'labelAllLocales':
329
+ {
330
+ const labelsDiff = getLabelAllLocalesDiff({
331
+ previousValue: oldSubMenuLink.labelAllLocales,
332
+ nextValue: newSubmenuLink.labelAllLocales,
333
+ indentLevel: 3
334
+ });
335
+ if (labelsDiff) {
336
+ submenuLinkDiff.push(labelsDiff);
337
+ }
338
+ break;
339
+ }
340
+ }
341
+ });
342
+ delete mappedSubmenuLinks[newSubmenuLink.uriPath];
343
+ const filteredSubmenuLinksDiff = _filterInstanceProperty__default["default"](submenuLinkDiff).call(submenuLinkDiff, Boolean);
344
+ if (filteredSubmenuLinksDiff.length > 1) {
345
+ submenuLinksDiff.push(filteredSubmenuLinksDiff.join('\n'));
346
+ }
347
+ } else {
348
+ const linksDiff = getStringDiff({
349
+ nextValue: newSubmenuLink.uriPath,
350
+ label: 'menu link',
351
+ indentLevel: 1
352
+ });
353
+ if (linksDiff) {
354
+ submenuLinksDiff.push(linksDiff);
355
+ }
356
+ }
357
+ });
358
+ _forEachInstanceProperty__default["default"](_context6 = _Object$keys__default["default"](mappedSubmenuLinks)).call(_context6, key => {
359
+ const linksDiff = getStringDiff({
360
+ previousValue: key,
361
+ label: 'menu link',
362
+ indentLevel: 1
363
+ });
364
+ if (linksDiff) submenuLinksDiff.push(linksDiff);
365
+ });
366
+ if (submenuLinksDiff.length > 1) return submenuLinksDiff.join('\n');
367
+ return null;
368
+ };
369
+
370
+ // Compute diff changes of the Custom Application config.
371
+ // NOTE: Only known keys are evaluated.
372
+ const getCustomApplicationConfigDiff = (oldConfig, newConfig) => {
373
+ const diff = [];
374
+
375
+ // Name
376
+ const nameDiff = getStringDiff({
377
+ previousValue: oldConfig.name,
378
+ nextValue: newConfig.name,
379
+ label: 'name'
380
+ });
381
+ if (nameDiff) {
382
+ diff.push(nameDiff);
383
+ }
384
+
385
+ // Description
386
+ const descriptionDiff = getStringDiff({
387
+ previousValue: oldConfig.description,
388
+ nextValue: newConfig.description,
389
+ label: 'description'
390
+ });
391
+ if (descriptionDiff) {
392
+ diff.push(descriptionDiff);
393
+ }
394
+
395
+ // URL
396
+ const urlDiff = getStringDiff({
397
+ previousValue: oldConfig.url,
398
+ nextValue: newConfig.url,
399
+ label: 'url'
400
+ });
401
+ if (urlDiff) {
402
+ diff.push(urlDiff);
403
+ }
404
+
405
+ // Icon
406
+ const iconDiff = getStringDiff({
407
+ // This icon stored in the database has already been sanitized.
408
+ previousValue: oldConfig.icon,
409
+ // Sanitize the raw icon as-if it was stored in the database,
410
+ // to ensure the data can be safely compared.
411
+ nextValue: applicationConfig.sanitizeSvg(newConfig.icon),
412
+ label: 'icon'
413
+ });
414
+ if (iconDiff) {
415
+ diff.push(iconDiff);
416
+ }
417
+
418
+ // Permissions
419
+ const permissionsDiff = getPermissionsDiff({
420
+ previousValue: oldConfig.permissions,
421
+ nextValue: newConfig.permissions
422
+ });
423
+ if (permissionsDiff) {
424
+ diff.push(permissionsDiff);
425
+ }
426
+
427
+ // Main menu link
428
+ const mainMenuDiff = getMainMenuLinkDiff({
429
+ previousValue: oldConfig.mainMenuLink,
430
+ nextValue: newConfig.mainMenuLink
431
+ });
432
+ if (mainMenuDiff) {
433
+ diff.push(mainMenuDiff);
434
+ }
435
+
436
+ // Submenu links
437
+ const submenuDiff = getSubmenuLinksDiff({
438
+ previousValue: oldConfig.submenuLinks,
439
+ nextValue: newConfig.submenuLinks
440
+ });
441
+ if (submenuDiff) {
442
+ diff.push(submenuDiff);
443
+ }
444
+ return diff.join('\n');
445
+ };
446
+
447
+ // Compute diff changes of the Custom View config.
448
+ // NOTE: Only known keys are evaluated.
449
+ const getCustomViewConfigDiff = (oldConfig, newConfig) => {
450
+ const diff = [];
451
+
452
+ // Default Label
453
+ const defaultLabelDiff = getStringDiff({
454
+ previousValue: oldConfig.defaultLabel,
455
+ nextValue: newConfig.defaultLabel,
456
+ label: 'defaultLabel'
457
+ });
458
+ if (defaultLabelDiff) {
459
+ diff.push(defaultLabelDiff);
460
+ }
461
+
462
+ // Description
463
+ const descriptionDiff = getStringDiff({
464
+ previousValue: oldConfig.description,
465
+ nextValue: newConfig.description,
466
+ label: 'description'
467
+ });
468
+ if (descriptionDiff) {
469
+ diff.push(descriptionDiff);
470
+ }
471
+
472
+ // URL
473
+ const urlDiff = getStringDiff({
474
+ previousValue: oldConfig.url,
475
+ nextValue: newConfig.url,
476
+ label: 'url'
477
+ });
478
+ if (urlDiff) {
479
+ diff.push(urlDiff);
480
+ }
481
+
482
+ // Type
483
+ const typeDiff = getStringDiff({
484
+ previousValue: oldConfig.type,
485
+ nextValue: newConfig.type,
486
+ label: 'type'
487
+ });
488
+ if (typeDiff) {
489
+ diff.push(typeDiff);
490
+ }
491
+
492
+ // Permissions
493
+ const permissionsDiff = getPermissionsDiff({
494
+ previousValue: oldConfig.permissions,
495
+ nextValue: newConfig.permissions
496
+ });
497
+ if (permissionsDiff) {
498
+ diff.push(permissionsDiff);
499
+ }
500
+
501
+ // Label All Locales
502
+ const labelsDiff = getLabelAllLocalesDiff({
503
+ previousValue: oldConfig.labelAllLocales,
504
+ nextValue: newConfig.labelAllLocales,
505
+ indentLevel: 1
506
+ });
507
+ if (labelsDiff) {
508
+ diff.push(labelsDiff);
509
+ }
510
+
511
+ // Type settings
512
+ const typeSettingsDiff = getTypeSettingsDiff({
513
+ previousValue: oldConfig.typeSettings,
514
+ nextValue: newConfig.typeSettings
515
+ });
516
+ if (typeSettingsDiff) {
517
+ diff.push(typeSettingsDiff);
518
+ }
519
+
520
+ // Locators
521
+ const locatorsDiff = getLocatorsDiff({
522
+ previousValue: oldConfig.locators,
523
+ nextValue: newConfig.locators
524
+ });
525
+ if (locatorsDiff) {
526
+ diff.push(locatorsDiff);
527
+ }
528
+ return diff.join('\n');
529
+ };
530
+
531
+ const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
532
+ const getMcUrlLink = _ref => {
533
+ let mcApiUrl = _ref.mcApiUrl,
534
+ organizationId = _ref.organizationId,
535
+ customEntityId = _ref.customEntityId,
536
+ isCustomView = _ref.isCustomView;
537
+ const mcUrl = mcApiUrl.replace('mc-api', 'mc');
538
+ const customEntityLink = `${mcUrl}/account/organizations/${organizationId}/custom-${isCustomView ? 'views' : 'applications'}/owned/${customEntityId}`;
539
+ return customEntityLink;
540
+ };
541
+ const isCustomViewData = data => data.entryPointUriPath === undefined;
542
+ async function createOrUpdateCustomApplication(_ref2) {
543
+ var _context3;
544
+ let mcApiUrl = _ref2.mcApiUrl,
545
+ localCustomEntityData = _ref2.localCustomEntityData,
546
+ applicationIdentifier = _ref2.applicationIdentifier,
547
+ options = _ref2.options;
548
+ const fetchedCustomApplication = await graphqlRequests.fetchCustomApplication({
549
+ mcApiUrl,
550
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
551
+ applicationIdentifier
552
+ });
553
+ if (!fetchedCustomApplication) {
554
+ var _context2;
555
+ const userOrganizations = await graphqlRequests.fetchUserOrganizations({
556
+ mcApiUrl,
557
+ applicationIdentifier
558
+ });
559
+ let organizationId, organizationName;
560
+ if (userOrganizations.total === 0) {
561
+ 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.`);
562
+ }
563
+ if (userOrganizations.total === 1) {
564
+ const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
565
+ organization = _userOrganizations$re[0];
566
+ organizationId = organization.id;
567
+ organizationName = organization.name;
568
+ } else {
569
+ var _context;
570
+ const organizationChoices = _mapInstanceProperty__default["default"](_context = userOrganizations.results).call(_context, organization => ({
571
+ title: organization.name,
572
+ value: organization.id
573
+ }));
574
+ const _await$prompts = await prompts__default["default"]({
575
+ type: 'select',
576
+ name: 'organizationId',
577
+ message: 'Select an Organization',
578
+ choices: organizationChoices,
579
+ initial: 0
580
+ }),
581
+ selectedOrganizationId = _await$prompts.organizationId;
582
+ if (!selectedOrganizationId) {
583
+ throw new Error(`No Organization selected, aborting.`);
584
+ }
585
+ organizationId = selectedOrganizationId;
586
+ organizationName = _findInstanceProperty__default["default"](organizationChoices).call(organizationChoices, _ref3 => {
587
+ let value = _ref3.value;
588
+ return value === organizationId;
589
+ }).title;
590
+ }
591
+ const _await$prompts2 = await prompts__default["default"]({
592
+ type: 'text',
593
+ name: 'confirmation',
594
+ 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'),
595
+ initial: 'yes'
596
+ }),
597
+ confirmation = _await$prompts2.confirmation;
598
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
599
+ console.log(chalk__default["default"].red('Aborted.'));
600
+ return;
601
+ }
602
+ const data = omit__default["default"](localCustomEntityData, ['id']);
603
+ if (options.dryRun) {
604
+ console.log();
605
+ console.log(`The following payload would be used to create a new Custom Application.`);
606
+ console.log();
607
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
608
+ return;
609
+ }
610
+ const createdCustomApplication = await graphqlRequests.createCustomApplication({
611
+ mcApiUrl,
612
+ organizationId,
613
+ data,
614
+ applicationIdentifier
615
+ });
616
+
617
+ // This check is technically not necessary, as the `graphql-request` client
618
+ // throws an error in case of GraphQL errors.
619
+ // However, the generated TypeScript data related to the GraphQL query has the
620
+ // field typed as optional, thus having an extra check for type correctness.
621
+ if (!createdCustomApplication) {
622
+ throw new Error('Failed to create the Custom Application.');
623
+ }
624
+ const customAppLink = getMcUrlLink({
625
+ mcApiUrl,
626
+ organizationId,
627
+ customEntityId: createdCustomApplication.id
628
+ });
629
+ 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)}".`));
630
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk__default["default"].gray(customAppLink)}".`);
631
+ return;
632
+ }
633
+ const customAppLink = getMcUrlLink({
634
+ mcApiUrl,
635
+ organizationId: fetchedCustomApplication.organizationId,
636
+ customEntityId: fetchedCustomApplication.application.id
637
+ });
638
+ const configDiff = getCustomApplicationConfigDiff(fetchedCustomApplication.application, localCustomEntityData);
639
+ if (!configDiff) {
640
+ console.log(chalk__default["default"].green(`Custom Application up-to-date.`));
641
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk__default["default"].gray(customAppLink)}".`);
642
+ return;
643
+ }
644
+ console.log('Changes detected:');
645
+ console.log(configDiff);
646
+ console.log();
647
+ const _await$prompts3 = await prompts__default["default"]({
648
+ type: 'text',
649
+ name: 'confirmation',
650
+ 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'),
651
+ initial: 'yes'
652
+ }),
653
+ confirmation = _await$prompts3.confirmation;
654
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
655
+ console.log(chalk__default["default"].red('Aborted.'));
656
+ return;
657
+ }
658
+ const data = omit__default["default"](localCustomEntityData, ['id']);
659
+ if (options.dryRun) {
660
+ console.log();
661
+ console.log(`The following payload would be used to update the Custom Application "${chalk__default["default"].green(data.entryPointUriPath)}".`);
662
+ console.log();
663
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
664
+ return;
665
+ }
666
+ await graphqlRequests.updateCustomApplication({
667
+ mcApiUrl,
668
+ organizationId: fetchedCustomApplication.organizationId,
669
+ data: omit__default["default"](localCustomEntityData, ['id']),
670
+ applicationId: fetchedCustomApplication.application.id,
671
+ applicationIdentifier
672
+ });
673
+ console.log(chalk__default["default"].green(`Custom Application updated.`));
674
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk__default["default"].gray(customAppLink)}".`);
675
+ }
676
+ async function createOrUpdateCustomView(_ref4) {
677
+ var _context6;
678
+ let mcApiUrl = _ref4.mcApiUrl,
679
+ localCustomEntityData = _ref4.localCustomEntityData,
680
+ customViewId = _ref4.customViewId,
681
+ options = _ref4.options,
682
+ applicationIdentifier = _ref4.applicationIdentifier;
683
+ const fetchedCustomView = await graphqlRequests.fetchCustomView({
684
+ mcApiUrl,
685
+ customViewId,
686
+ applicationIdentifier
687
+ });
688
+ if (!fetchedCustomView) {
689
+ var _context5;
690
+ const userOrganizations = await graphqlRequests.fetchUserOrganizations({
691
+ mcApiUrl,
692
+ customViewId,
693
+ applicationIdentifier
694
+ });
695
+ let organizationId, organizationName;
696
+ if (userOrganizations.total === 0) {
697
+ 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.`);
698
+ }
699
+ if (userOrganizations.total === 1) {
700
+ const _userOrganizations$re2 = _slicedToArray(userOrganizations.results, 1),
701
+ organization = _userOrganizations$re2[0];
702
+ organizationId = organization.id;
703
+ organizationName = organization.name;
704
+ } else {
705
+ var _context4;
706
+ const organizationChoices = _mapInstanceProperty__default["default"](_context4 = userOrganizations.results).call(_context4, organization => ({
707
+ title: organization.name,
708
+ value: organization.id
709
+ }));
710
+ const _await$prompts4 = await prompts__default["default"]({
711
+ type: 'select',
712
+ name: 'organizationId',
713
+ message: 'Select an Organization',
714
+ choices: organizationChoices,
715
+ initial: 0
716
+ }),
717
+ selectedOrganizationId = _await$prompts4.organizationId;
718
+ if (!selectedOrganizationId) {
719
+ throw new Error(`No Organization selected, aborting.`);
720
+ }
721
+ organizationId = selectedOrganizationId;
722
+ organizationName = _findInstanceProperty__default["default"](organizationChoices).call(organizationChoices, _ref5 => {
723
+ let value = _ref5.value;
724
+ return value === organizationId;
725
+ }).title;
726
+ }
727
+ const _await$prompts5 = await prompts__default["default"]({
728
+ type: 'text',
729
+ name: 'confirmation',
730
+ 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'),
731
+ initial: 'yes'
732
+ }),
733
+ confirmation = _await$prompts5.confirmation;
734
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
735
+ console.log(chalk__default["default"].red('Aborted.'));
736
+ return;
737
+ }
738
+ const data = omit__default["default"](localCustomEntityData, ['id']);
739
+ if (options.dryRun) {
740
+ console.log();
741
+ console.log(`The following payload would be used to create a new Custom View.`);
742
+ console.log();
743
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
744
+ return;
745
+ }
746
+ const createdCustomView = await graphqlRequests.createCustomView({
747
+ mcApiUrl,
748
+ organizationId,
749
+ data,
750
+ applicationIdentifier
751
+ });
752
+
753
+ // This check is technically not necessary, as the `graphql-request` client
754
+ // throws an error in case of GraphQL errors.
755
+ // However, the generated TypeScript data related to the GraphQL query has the
756
+ // field typed as optional, thus having an extra check for type correctness.
757
+ if (!createdCustomView) {
758
+ throw new Error('Failed to create the Custom View.');
759
+ }
760
+ const customViewLink = getMcUrlLink({
761
+ mcApiUrl,
762
+ organizationId,
763
+ customEntityId: createdCustomView.id,
764
+ isCustomView: true
765
+ });
766
+ 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)}".`));
767
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk__default["default"].gray(customViewLink)}".`);
768
+ return;
769
+ }
770
+ const customViewLink = getMcUrlLink({
771
+ mcApiUrl,
772
+ organizationId: fetchedCustomView.organizationId,
773
+ customEntityId: fetchedCustomView?.customView?.id || '',
774
+ isCustomView: true
775
+ });
776
+ const configDiff = getCustomViewConfigDiff(fetchedCustomView.customView, localCustomEntityData);
777
+ if (!configDiff) {
778
+ console.log(chalk__default["default"].green(`Custom View up-to-date.`));
779
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk__default["default"].gray(customViewLink)}".`);
780
+ return;
781
+ }
782
+ console.log('Changes detected:');
783
+ console.log(configDiff);
784
+ console.log();
785
+ const _await$prompts6 = await prompts__default["default"]({
786
+ type: 'text',
787
+ name: 'confirmation',
788
+ 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'),
789
+ initial: 'yes'
790
+ }),
791
+ confirmation = _await$prompts6.confirmation;
792
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
793
+ console.log(chalk__default["default"].red('Aborted.'));
794
+ return;
795
+ }
796
+ const data = omit__default["default"](localCustomEntityData, ['id']);
797
+ if (options.dryRun) {
798
+ console.log();
799
+ console.log(`The following payload would be used to update the Custom View "${chalk__default["default"].green(data.defaultLabel)}".`);
800
+ console.log();
801
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
802
+ return;
803
+ }
804
+ await graphqlRequests.updateCustomView({
805
+ mcApiUrl,
806
+ organizationId: fetchedCustomView.organizationId,
807
+ data: omit__default["default"](localCustomEntityData, ['id']),
808
+ customViewId: fetchedCustomView?.customView?.id || '',
809
+ applicationIdentifier
810
+ });
811
+ console.log(chalk__default["default"].green(`Custom View updated.`));
812
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk__default["default"].gray(customViewLink)}".`);
813
+ }
814
+ async function run(options) {
815
+ const applicationConfig$1 = applicationConfig.processConfig();
816
+ const localCustomEntityData = applicationConfig$1.data;
817
+ const _applicationConfig$en = applicationConfig$1.env,
818
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
819
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier,
820
+ customViewId = _applicationConfig$en.customViewId;
821
+ console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
822
+ console.log();
823
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
824
+ if (!isSessionValid) {
825
+ throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
826
+ }
827
+ if (isCustomViewData(localCustomEntityData)) {
828
+ createOrUpdateCustomView({
829
+ mcApiUrl,
830
+ localCustomEntityData,
831
+ applicationIdentifier,
832
+ customViewId: customViewId || localCustomEntityData.id,
833
+ options
834
+ });
835
+ } else {
836
+ createOrUpdateCustomApplication({
837
+ mcApiUrl,
838
+ localCustomEntityData,
839
+ applicationIdentifier,
840
+ options
841
+ });
842
+ }
843
+ }
844
+
845
+ exports["default"] = run;