@commercetools-frontend/mc-scripts 21.23.10 → 21.24.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +120 -326
  2. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +120 -326
  3. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +116 -321
  4. package/dist/build-980cf2c9.cjs.prod.js +170 -0
  5. package/dist/build-c9601b07.esm.js +156 -0
  6. package/dist/build-e8a49b56.cjs.dev.js +170 -0
  7. package/dist/build-vite-b531d3d3.esm.js +118 -0
  8. package/dist/build-vite-c40a55c3.cjs.dev.js +129 -0
  9. package/dist/build-vite-d17432ec.cjs.prod.js +129 -0
  10. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +2 -2
  11. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +2 -2
  12. package/dist/commercetools-frontend-mc-scripts.esm.js +2 -2
  13. package/dist/compile-html-41195e35.cjs.dev.js +49 -0
  14. package/dist/compile-html-5abd78aa.cjs.prod.js +49 -0
  15. package/dist/compile-html-f9de842c.esm.js +40 -0
  16. package/dist/config-sync-0ecc13b3.cjs.dev.js +783 -0
  17. package/dist/config-sync-4b1ddec3.esm.js +759 -0
  18. package/dist/config-sync-bb59a82d.cjs.prod.js +778 -0
  19. package/dist/{create-postcss-config-f65c7e31.cjs.dev.js → create-postcss-config-5cc679d5.cjs.dev.js} +9 -14
  20. package/dist/{create-postcss-config-06b2e5c2.esm.js → create-postcss-config-a0d4cffa.esm.js} +9 -13
  21. package/dist/{create-postcss-config-787d905f.cjs.prod.js → create-postcss-config-f94c07fd.cjs.prod.js} +9 -14
  22. package/dist/{create-webpack-config-for-development-fd365d6a.esm.js → create-webpack-config-for-development-95334073.esm.js} +21 -25
  23. package/dist/{create-webpack-config-for-development-d46ef148.cjs.dev.js → create-webpack-config-for-development-a53bab71.cjs.dev.js} +24 -28
  24. package/dist/{create-webpack-config-for-development-59faaed8.cjs.prod.js → create-webpack-config-for-development-c915ec0c.cjs.prod.js} +24 -28
  25. package/dist/{create-webpack-config-for-production-b28b3d33.esm.js → create-webpack-config-for-production-342485cd.esm.js} +18 -21
  26. package/dist/{create-webpack-config-for-production-1af3a454.cjs.prod.js → create-webpack-config-for-production-af6f3138.cjs.prod.js} +20 -23
  27. package/dist/{create-webpack-config-for-production-e12e3c30.cjs.dev.js → create-webpack-config-for-production-db45d9ab.cjs.dev.js} +20 -23
  28. package/dist/{user-agent-9a470e39.cjs.dev.js → credentials-storage-a37a8915.cjs.dev.js} +24 -24
  29. package/dist/{user-agent-6e8d0e0b.cjs.prod.js → credentials-storage-b803a804.cjs.prod.js} +24 -24
  30. package/dist/{user-agent-4b60934e.esm.js → credentials-storage-cb88e8fc.esm.js} +22 -22
  31. package/dist/declarations/src/deprecated-entry-points.d.ts +1 -1
  32. package/dist/login-35040a86.cjs.dev.js +93 -0
  33. package/dist/login-6e17747d.esm.js +84 -0
  34. package/dist/login-90736d7e.cjs.prod.js +93 -0
  35. package/dist/{package-a5454c97.esm.js → package-17f18481.esm.js} +17 -16
  36. package/dist/{package-e2d9b5e0.cjs.dev.js → package-c42dc2ac.cjs.dev.js} +17 -16
  37. package/dist/{package-808a31f1.cjs.prod.js → package-db15171f.cjs.prod.js} +17 -16
  38. package/dist/{paths-76b66e74.cjs.prod.js → paths-284c77fb.cjs.prod.js} +6 -8
  39. package/dist/{paths-ed23d5a1.esm.js → paths-55c5d5a2.esm.js} +6 -8
  40. package/dist/{paths-16823f56.cjs.dev.js → paths-db35ac0f.cjs.dev.js} +6 -8
  41. package/dist/serve-41077dad.cjs.prod.js +48 -0
  42. package/dist/serve-660e2ee0.esm.js +41 -0
  43. package/dist/serve-b8063204.cjs.dev.js +48 -0
  44. package/dist/start-0aa71e9a.esm.js +166 -0
  45. package/dist/start-2e7ec87c.cjs.dev.js +180 -0
  46. package/dist/start-c0ffe8d7.cjs.prod.js +180 -0
  47. package/dist/start-vite-324af14d.cjs.prod.js +119 -0
  48. package/dist/start-vite-7d10ae71.esm.js +107 -0
  49. package/dist/start-vite-8f03b0df.cjs.dev.js +119 -0
  50. package/dist/{vendors-to-transpile-367e0ba8.cjs.prod.js → vendors-to-transpile-04a49d40.cjs.prod.js} +1 -1
  51. package/dist/{vendors-to-transpile-b51af5d3.cjs.dev.js → vendors-to-transpile-6ab4ea06.cjs.dev.js} +1 -1
  52. package/dist/{vendors-to-transpile-68e03526.esm.js → vendors-to-transpile-7dc84a72.esm.js} +1 -1
  53. package/dist/vite-plugin-svgr-9a4e7f77.cjs.prod.js +79 -0
  54. package/dist/vite-plugin-svgr-f17db78a.esm.js +55 -0
  55. package/dist/vite-plugin-svgr-fdb37ccf.cjs.dev.js +79 -0
  56. package/package.json +17 -16
  57. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -4
  58. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -4
  59. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -4
  60. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +12 -13
  61. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +12 -13
  62. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +12 -13
  63. package/dist/build-0e6d74d1.esm.js +0 -209
  64. package/dist/build-9074fc85.cjs.dev.js +0 -224
  65. package/dist/build-ae132901.cjs.prod.js +0 -224
  66. package/dist/build-vite-482a21b8.cjs.dev.js +0 -151
  67. package/dist/build-vite-cc68e3bf.esm.js +0 -139
  68. package/dist/build-vite-f095b68d.cjs.prod.js +0 -151
  69. package/dist/compile-html-4361a0b3.esm.js +0 -77
  70. package/dist/compile-html-d6331c35.cjs.prod.js +0 -87
  71. package/dist/compile-html-d9e731aa.cjs.dev.js +0 -87
  72. package/dist/config-sync-2a9945bc.cjs.dev.js +0 -989
  73. package/dist/config-sync-43a80f60.cjs.prod.js +0 -984
  74. package/dist/config-sync-c6c4d1cf.esm.js +0 -964
  75. package/dist/login-7f1cc8d0.cjs.prod.js +0 -167
  76. package/dist/login-d21a49e8.esm.js +0 -157
  77. package/dist/login-ed827138.cjs.dev.js +0 -167
  78. package/dist/serve-12de323b.cjs.dev.js +0 -70
  79. package/dist/serve-784f4fcd.cjs.prod.js +0 -70
  80. package/dist/serve-d6b437b1.esm.js +0 -62
  81. package/dist/start-10a4d95a.esm.js +0 -194
  82. package/dist/start-d021fa98.cjs.prod.js +0 -209
  83. package/dist/start-eea524f2.cjs.dev.js +0 -209
  84. package/dist/start-vite-57ec5175.cjs.dev.js +0 -146
  85. package/dist/start-vite-94c2db8c.esm.js +0 -133
  86. package/dist/start-vite-fc0b15d3.cjs.prod.js +0 -146
  87. package/dist/vite-plugin-svgr-4205f2b5.cjs.dev.js +0 -110
  88. package/dist/vite-plugin-svgr-eb8524fa.esm.js +0 -85
  89. package/dist/vite-plugin-svgr-f3bbedbe.cjs.prod.js +0 -110
@@ -0,0 +1,783 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
4
+ var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
5
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
6
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
7
+ var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
8
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
9
+ var chalk = require('chalk');
10
+ var omit = require('lodash/omit');
11
+ var prompts = require('prompts');
12
+ var applicationConfig = require('@commercetools-frontend/application-config');
13
+ var credentialsStorage$2 = require('./credentials-storage-a37a8915.cjs.dev.js');
14
+ var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
15
+ var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
16
+ var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
17
+ var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
18
+ var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
19
+ var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
20
+ var _repeatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/repeat');
21
+ var _Set = require('@babel/runtime-corejs3/core-js-stable/set');
22
+ var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
23
+ var _reduceInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
24
+ var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
25
+ var _someInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/some');
26
+ var graphql = require('graphql');
27
+ var graphqlRequest = require('graphql-request');
28
+ var constants = require('@commercetools-frontend/constants');
29
+ require('@commercetools/http-user-agent');
30
+ require('./package-c42dc2ac.cjs.dev.js');
31
+ require('@babel/runtime-corejs3/helpers/classCallCheck');
32
+ require('@babel/runtime-corejs3/helpers/createClass');
33
+ require('@babel/runtime-corejs3/core-js-stable/date/now');
34
+ require('fs');
35
+ require('os');
36
+ require('path');
37
+
38
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
39
+
40
+ var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
41
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
42
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
43
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
44
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
45
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
46
+ var omit__default = /*#__PURE__*/_interopDefault(omit);
47
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
48
+ var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
49
+ var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
50
+ var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
51
+ var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
52
+ var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
53
+ var _repeatInstanceProperty__default = /*#__PURE__*/_interopDefault(_repeatInstanceProperty);
54
+ var _Set__default = /*#__PURE__*/_interopDefault(_Set);
55
+ var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
56
+ var _reduceInstanceProperty__default = /*#__PURE__*/_interopDefault(_reduceInstanceProperty);
57
+ var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
58
+ var _someInstanceProperty__default = /*#__PURE__*/_interopDefault(_someInstanceProperty);
59
+
60
+ function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
61
+
62
+ function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context20, _context21; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context20 = ownKeys$1(Object(source), !0)).call(_context20, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context21 = ownKeys$1(Object(source))).call(_context21, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
63
+ // during tests the color used is appended before the string instead of coloring it.
64
+
65
+ const isTest = process.env.NODE_ENV === 'test';
66
+
67
+ const red = str => {
68
+ if (isTest) return "<color-red>".concat(str, "</color-red>");
69
+ return chalk__default["default"].red(str);
70
+ };
71
+
72
+ const green = str => {
73
+ if (isTest) return "<color-green>".concat(str, "</color-green>");
74
+ return chalk__default["default"].green(str);
75
+ }; // Two spaces are used for indentation.
76
+
77
+
78
+ const indent = indentLevel => {
79
+ var _context;
80
+
81
+ return _repeatInstanceProperty__default["default"](_context = ' ').call(_context, indentLevel);
82
+ };
83
+
84
+ const getStringDiff = _ref => {
85
+ let previousValue = _ref.previousValue,
86
+ nextValue = _ref.nextValue,
87
+ label = _ref.label,
88
+ _ref$indentLevel = _ref.indentLevel,
89
+ indentLevel = _ref$indentLevel === void 0 ? 0 : _ref$indentLevel;
90
+
91
+ if (!previousValue && nextValue) {
92
+ var _context2, _context3;
93
+
94
+ return _concatInstanceProperty__default["default"](_context2 = _concatInstanceProperty__default["default"](_context3 = "".concat(indent(indentLevel))).call(_context3, label, " added: ")).call(_context2, green(nextValue));
95
+ }
96
+
97
+ if (previousValue && !nextValue) {
98
+ var _context4, _context5;
99
+
100
+ return _concatInstanceProperty__default["default"](_context4 = _concatInstanceProperty__default["default"](_context5 = "".concat(indent(indentLevel))).call(_context5, label, " removed: ")).call(_context4, red(previousValue));
101
+ }
102
+
103
+ if (previousValue && nextValue && previousValue !== nextValue) {
104
+ var _context6, _context7, _context8;
105
+
106
+ return _concatInstanceProperty__default["default"](_context6 = _concatInstanceProperty__default["default"](_context7 = _concatInstanceProperty__default["default"](_context8 = "".concat(indent(indentLevel))).call(_context8, label, " changed: ")).call(_context7, red(previousValue), " => ")).call(_context6, green(nextValue));
107
+ }
108
+
109
+ return null;
110
+ };
111
+
112
+ // NOTE: this assumes that the array values are scalar values (not objects).
113
+ const getArrayDiff = _ref2 => {
114
+ let previousValue = _ref2.previousValue,
115
+ nextValue = _ref2.nextValue,
116
+ label = _ref2.label,
117
+ _ref2$indentLevel = _ref2.indentLevel,
118
+ indentLevel = _ref2$indentLevel === void 0 ? 0 : _ref2$indentLevel;
119
+ const oldArraySet = new _Set__default["default"](previousValue);
120
+ const arrayDiff = [];
121
+ nextValue === null || nextValue === void 0 ? void 0 : _forEachInstanceProperty__default["default"](nextValue).call(nextValue, item => {
122
+ if (oldArraySet.has(item)) {
123
+ oldArraySet.delete(item);
124
+ } else {
125
+ arrayDiff.push(getStringDiff({
126
+ nextValue: item,
127
+ label,
128
+ indentLevel
129
+ }));
130
+ }
131
+ });
132
+
133
+ _forEachInstanceProperty__default["default"](oldArraySet).call(oldArraySet, item => {
134
+ arrayDiff.push(getStringDiff({
135
+ previousValue: item,
136
+ label,
137
+ indentLevel
138
+ }));
139
+ });
140
+
141
+ return arrayDiff.join('\n');
142
+ };
143
+
144
+ const getPermissionsDiff = _ref3 => {
145
+ var _context11;
146
+
147
+ let previousValue = _ref3.previousValue,
148
+ nextValue = _ref3.nextValue;
149
+ const permissionDiff = ['permissions changed'];
150
+
151
+ const mappedOldPermissions = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousPermission, _ref4) => {
152
+ let name = _ref4.name,
153
+ oAuthScopes = _ref4.oAuthScopes;
154
+ return _objectSpread$1(_objectSpread$1({}, previousPermission), {}, {
155
+ [name]: oAuthScopes
156
+ });
157
+ }, {});
158
+
159
+ const indentLevel = 1;
160
+
161
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newPermission => {
162
+ var _context9;
163
+
164
+ const currentDiff = [_concatInstanceProperty__default["default"](_context9 = "".concat(indent(indentLevel), "\"")).call(_context9, newPermission.name, "\" changed")]; // if the permission name is not in the old config, it means it is a new addition.
165
+
166
+ if (!mappedOldPermissions[newPermission.name]) {
167
+ var _context10;
168
+
169
+ permissionDiff.push(_concatInstanceProperty__default["default"](_context10 = "".concat(indent(indentLevel), "\"")).call(_context10, green(newPermission.name), "\" was added"));
170
+ } // if permission name is in the old config, now we check if there was a change
171
+ else {
172
+ currentDiff.push(getArrayDiff({
173
+ previousValue: mappedOldPermissions[newPermission.name],
174
+ nextValue: newPermission.oAuthScopes,
175
+ label: 'oauth scope',
176
+ indentLevel: 2
177
+ }));
178
+ delete mappedOldPermissions[newPermission.name];
179
+ }
180
+
181
+ _filterInstanceProperty__default["default"](currentDiff).call(currentDiff, Boolean).length > 1 && permissionDiff.push(currentDiff.join('\n'));
182
+ }); // if there are old permissions left, it means they were deleted in the new Permissions.
183
+
184
+
185
+ _forEachInstanceProperty__default["default"](_context11 = _Object$keys__default["default"](mappedOldPermissions)).call(_context11, oldPermissionName => {
186
+ var _context12;
187
+
188
+ permissionDiff.push(_concatInstanceProperty__default["default"](_context12 = "".concat(indent(indentLevel), "\"")).call(_context12, red(oldPermissionName), "\" was removed"));
189
+ });
190
+
191
+ if (permissionDiff.length > 1) return permissionDiff.join('\n');
192
+ return null;
193
+ };
194
+
195
+ const getLabelAllLocalesDiff = _ref5 => {
196
+ var _context16;
197
+
198
+ let _ref5$previousValue = _ref5.previousValue,
199
+ previousValue = _ref5$previousValue === void 0 ? [] : _ref5$previousValue,
200
+ _ref5$nextValue = _ref5.nextValue,
201
+ nextValue = _ref5$nextValue === void 0 ? [] : _ref5$nextValue,
202
+ _ref5$indentLevel = _ref5.indentLevel,
203
+ indentLevel = _ref5$indentLevel === void 0 ? 0 : _ref5$indentLevel;
204
+ const labelAllLocalesDiff = ["".concat(indent(indentLevel - 1), "labelAllLocales changed")];
205
+
206
+ const mappedOldLabelAllLocales = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousLabelAllLocale, _ref6) => {
207
+ let locale = _ref6.locale,
208
+ value = _ref6.value;
209
+ return _objectSpread$1(_objectSpread$1({}, previousLabelAllLocale), {}, {
210
+ [locale]: value
211
+ });
212
+ }, {});
213
+
214
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newLabelAllLocale => {
215
+ if (newLabelAllLocale.locale in mappedOldLabelAllLocales) {
216
+ const oldLocaleValue = mappedOldLabelAllLocales[newLabelAllLocale.locale];
217
+
218
+ if (oldLocaleValue !== newLabelAllLocale.value) {
219
+ var _context13, _context14, _context15;
220
+
221
+ labelAllLocalesDiff.push(_concatInstanceProperty__default["default"](_context13 = _concatInstanceProperty__default["default"](_context14 = _concatInstanceProperty__default["default"](_context15 = "".concat(indent(indentLevel), "locale \"")).call(_context15, newLabelAllLocale.locale, "\" changed: ")).call(_context14, red(oldLocaleValue), " => ")).call(_context13, green(newLabelAllLocale.value)));
222
+ }
223
+
224
+ delete mappedOldLabelAllLocales[newLabelAllLocale.locale];
225
+ } else {
226
+ const localeDiff = getStringDiff({
227
+ nextValue: newLabelAllLocale.locale,
228
+ label: 'locale',
229
+ indentLevel
230
+ });
231
+
232
+ if (localeDiff) {
233
+ labelAllLocalesDiff.push(localeDiff);
234
+ }
235
+ }
236
+ });
237
+
238
+ _forEachInstanceProperty__default["default"](_context16 = _Object$keys__default["default"](mappedOldLabelAllLocales)).call(_context16, key => {
239
+ const localeDiff = getStringDiff({
240
+ previousValue: key,
241
+ label: 'locale',
242
+ indentLevel
243
+ });
244
+
245
+ if (localeDiff) {
246
+ labelAllLocalesDiff.push(localeDiff);
247
+ }
248
+ });
249
+
250
+ if (labelAllLocalesDiff.length > 1) return labelAllLocalesDiff.join('\n');
251
+ return null;
252
+ };
253
+
254
+ const getMainMenuLinkDiff = _ref7 => {
255
+ let previousValue = _ref7.previousValue,
256
+ nextValue = _ref7.nextValue;
257
+ const mainMenuLinkDiff = ['mainMenuLink changed'];
258
+ const menuDiff = getStringDiff({
259
+ previousValue: previousValue.defaultLabel,
260
+ nextValue: nextValue.defaultLabel,
261
+ label: 'defaultLabel',
262
+ indentLevel: 1
263
+ });
264
+
265
+ if (menuDiff) {
266
+ mainMenuLinkDiff.push(menuDiff);
267
+ }
268
+
269
+ const mainMenuLinkPermissionsDiff = getArrayDiff({
270
+ previousValue: previousValue.permissions,
271
+ nextValue: nextValue.permissions,
272
+ label: 'applied permission',
273
+ indentLevel: 2
274
+ });
275
+
276
+ if (mainMenuLinkPermissionsDiff.length > 0) {
277
+ mainMenuLinkDiff.push("".concat(indent(1), "permissions changed"));
278
+ mainMenuLinkDiff.push(mainMenuLinkPermissionsDiff);
279
+ }
280
+
281
+ const menuLabelsDiff = getLabelAllLocalesDiff({
282
+ previousValue: previousValue.labelAllLocales,
283
+ nextValue: nextValue.labelAllLocales,
284
+ indentLevel: 2
285
+ });
286
+
287
+ if (menuLabelsDiff) {
288
+ mainMenuLinkDiff.push(menuLabelsDiff);
289
+ }
290
+
291
+ const filteredMainMenuLinkDiff = _filterInstanceProperty__default["default"](mainMenuLinkDiff).call(mainMenuLinkDiff, Boolean);
292
+
293
+ if (filteredMainMenuLinkDiff.length > 1) return filteredMainMenuLinkDiff.join('\n');
294
+ return null;
295
+ };
296
+
297
+ const getSubmenuLinksDiff = _ref8 => {
298
+ var _context19;
299
+
300
+ let previousValue = _ref8.previousValue,
301
+ nextValue = _ref8.nextValue;
302
+ const submenuLinksDiff = ['submenuLink changed'];
303
+
304
+ const mappedSubmenuLinks = _reduceInstanceProperty__default["default"](previousValue).call(previousValue, (previousSubmenuLink, currentSubmenuLink) => _objectSpread$1(_objectSpread$1({}, previousSubmenuLink), {}, {
305
+ [currentSubmenuLink.uriPath]: currentSubmenuLink
306
+ }), {});
307
+
308
+ _forEachInstanceProperty__default["default"](nextValue).call(nextValue, newSubmenuLink => {
309
+ const oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
310
+
311
+ if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
312
+ var _context17, _context18;
313
+
314
+ const submenuLinkDiff = [_concatInstanceProperty__default["default"](_context17 = "".concat(indent(1), "menu link \"")).call(_context17, newSubmenuLink.uriPath, "\" changed")];
315
+
316
+ _forEachInstanceProperty__default["default"](_context18 = _Object$keys__default["default"](mappedSubmenuLinks[newSubmenuLink.uriPath])).call(_context18, key => {
317
+ switch (key) {
318
+ case 'defaultLabel':
319
+ {
320
+ const labelDiff = getStringDiff({
321
+ previousValue: oldSubMenuLink.defaultLabel,
322
+ nextValue: newSubmenuLink.defaultLabel,
323
+ label: 'defaultLabel',
324
+ indentLevel: 2
325
+ });
326
+
327
+ if (labelDiff) {
328
+ submenuLinkDiff.push(labelDiff);
329
+ }
330
+
331
+ break;
332
+ }
333
+
334
+ case 'permissions':
335
+ {
336
+ const submenuLinkPermissionsDiff = getArrayDiff({
337
+ previousValue: oldSubMenuLink.permissions,
338
+ nextValue: newSubmenuLink.permissions,
339
+ label: 'applied permission',
340
+ indentLevel: 3
341
+ });
342
+
343
+ if (submenuLinkPermissionsDiff.length > 0) {
344
+ submenuLinkDiff.push("".concat(indent(2), "permissions changed"));
345
+ submenuLinkDiff.push(submenuLinkPermissionsDiff);
346
+ }
347
+
348
+ break;
349
+ }
350
+
351
+ case 'labelAllLocales':
352
+ {
353
+ const labelsDiff = getLabelAllLocalesDiff({
354
+ previousValue: oldSubMenuLink.labelAllLocales,
355
+ nextValue: newSubmenuLink.labelAllLocales,
356
+ indentLevel: 3
357
+ });
358
+
359
+ if (labelsDiff) {
360
+ submenuLinkDiff.push(labelsDiff);
361
+ }
362
+
363
+ break;
364
+ }
365
+ }
366
+ });
367
+
368
+ delete mappedSubmenuLinks[newSubmenuLink.uriPath];
369
+
370
+ const filteredSubmenuLinksDiff = _filterInstanceProperty__default["default"](submenuLinkDiff).call(submenuLinkDiff, Boolean);
371
+
372
+ if (filteredSubmenuLinksDiff.length > 1) {
373
+ submenuLinksDiff.push(filteredSubmenuLinksDiff.join('\n'));
374
+ }
375
+ } else {
376
+ const linksDiff = getStringDiff({
377
+ nextValue: newSubmenuLink.uriPath,
378
+ label: 'menu link',
379
+ indentLevel: 1
380
+ });
381
+
382
+ if (linksDiff) {
383
+ submenuLinksDiff.push(linksDiff);
384
+ }
385
+ }
386
+ });
387
+
388
+ _forEachInstanceProperty__default["default"](_context19 = _Object$keys__default["default"](mappedSubmenuLinks)).call(_context19, key => {
389
+ const linksDiff = getStringDiff({
390
+ previousValue: key,
391
+ label: 'menu link',
392
+ indentLevel: 1
393
+ });
394
+ if (linksDiff) submenuLinksDiff.push(linksDiff);
395
+ });
396
+
397
+ if (submenuLinksDiff.length > 1) return submenuLinksDiff.join('\n');
398
+ return null;
399
+ }; // Compute diff changes of the Custom Application config.
400
+ // NOTE: Only known keys are evaluated.
401
+
402
+
403
+ const getConfigDiff = (oldConfig, newConfig) => {
404
+ const diff = []; // Name
405
+
406
+ const nameDiff = getStringDiff({
407
+ previousValue: oldConfig.name,
408
+ nextValue: newConfig.name,
409
+ label: 'name'
410
+ });
411
+
412
+ if (nameDiff) {
413
+ diff.push(nameDiff);
414
+ } // Description
415
+
416
+
417
+ const descriptionDiff = getStringDiff({
418
+ previousValue: oldConfig.description,
419
+ nextValue: newConfig.description,
420
+ label: 'description'
421
+ });
422
+
423
+ if (descriptionDiff) {
424
+ diff.push(descriptionDiff);
425
+ } // URL
426
+
427
+
428
+ const urlDiff = getStringDiff({
429
+ previousValue: oldConfig.url,
430
+ nextValue: newConfig.url,
431
+ label: 'url'
432
+ });
433
+
434
+ if (urlDiff) {
435
+ diff.push(urlDiff);
436
+ } // Icon
437
+
438
+
439
+ const iconDiff = getStringDiff({
440
+ // This icon stored in the database has already been sanitized.
441
+ previousValue: oldConfig.icon,
442
+ // Sanitize the raw icon as-if it was stored in the database,
443
+ // to ensure the data can be safely compared.
444
+ nextValue: applicationConfig.sanitizeSvg(newConfig.icon),
445
+ label: 'icon'
446
+ });
447
+
448
+ if (iconDiff) {
449
+ diff.push(iconDiff);
450
+ } // Permissions
451
+
452
+
453
+ const permissionsDiff = getPermissionsDiff({
454
+ previousValue: oldConfig.permissions,
455
+ nextValue: newConfig.permissions
456
+ });
457
+
458
+ if (permissionsDiff) {
459
+ diff.push(permissionsDiff);
460
+ } // Main menu link
461
+
462
+
463
+ const mainMenuDiff = getMainMenuLinkDiff({
464
+ previousValue: oldConfig.mainMenuLink,
465
+ nextValue: newConfig.mainMenuLink
466
+ });
467
+
468
+ if (mainMenuDiff) {
469
+ diff.push(mainMenuDiff);
470
+ } // Submenu links
471
+
472
+
473
+ const submenuDiff = getSubmenuLinksDiff({
474
+ previousValue: oldConfig.submenuLinks,
475
+ nextValue: newConfig.submenuLinks
476
+ });
477
+
478
+ if (submenuDiff) {
479
+ diff.push(submenuDiff);
480
+ }
481
+
482
+ return diff.join('\n');
483
+ };
484
+
485
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys__default["default"](object); if (_Object$getOwnPropertySymbols__default["default"]) { var symbols = _Object$getOwnPropertySymbols__default["default"](object); enumerableOnly && (symbols = _filterInstanceProperty__default["default"](symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor__default["default"](object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
486
+
487
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](target, _Object$getOwnPropertyDescriptors__default["default"](source)) : _forEachInstanceProperty__default["default"](_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty__default["default"](target, key, _Object$getOwnPropertyDescriptor__default["default"](source, key)); }); } return target; }
488
+ var CreateCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "CreateCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "organizationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDraftDataInput" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "createCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "data" }, value: { kind: "Variable", name: { kind: "Name", value: "data" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 201, source: { body: "mutation CreateCustomApplicationFromCli(\n $organizationId: String!\n $data: CustomApplicationDraftDataInput!\n) {\n createCustomApplication(organizationId: $organizationId, data: $data) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
489
+ var FetchCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "entryPointUriPath" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationExtensionForCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "entryPointUriPath" }, value: { kind: "Variable", name: { kind: "Name", value: "entryPointUriPath" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationId" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "application" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "entryPointUriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "description" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "oAuthScopes" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "mainMenuLink" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "defaultLabel" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "submenuLinks" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "defaultLabel" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }], loc: { start: 0, end: 647, source: { body: "query FetchCustomApplicationFromCli($entryPointUriPath: String!) {\n organizationExtensionForCustomApplication(\n entryPointUriPath: $entryPointUriPath\n ) {\n organizationId\n application {\n id\n entryPointUriPath\n name\n description\n url\n icon\n permissions {\n name\n oAuthScopes\n }\n mainMenuLink {\n defaultLabel\n permissions\n labelAllLocales {\n locale\n value\n }\n }\n submenuLinks {\n uriPath\n defaultLabel\n permissions\n labelAllLocales {\n locale\n value\n }\n }\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
490
+ var FetchMyOrganizationsFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchMyOrganizationsFromCli" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "myOrganizations" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "total" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "results" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 112, source: { body: "query FetchMyOrganizationsFromCli {\n myOrganizations {\n total\n results {\n id\n name\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
491
+ var UpdateCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "UpdateCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "organizationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDraftDataInput" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "applicationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "ID" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "updateCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "data" }, value: { kind: "Variable", name: { kind: "Name", value: "data" } } }, { kind: "Argument", name: { kind: "Name", value: "applicationId" }, value: { kind: "Variable", name: { kind: "Name", value: "applicationId" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 268, source: { body: "mutation UpdateCustomApplicationFromCli(\n $organizationId: String!\n $data: CustomApplicationDraftDataInput!\n $applicationId: ID!\n) {\n updateCustomApplication(\n organizationId: $organizationId\n data: $data\n applicationId: $applicationId\n ) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
492
+ const credentialsStorage$1 = new credentialsStorage$2.CredentialsStorage();
493
+ const client = new graphqlRequest.GraphQLClient('', // <-- Set on demand
494
+ {
495
+ headers: {
496
+ Accept: 'application/json',
497
+ 'Content-Type': 'application/json',
498
+ 'x-user-agent': credentialsStorage$2.userAgent
499
+ }
500
+ });
501
+
502
+ async function requestWithTokenRetry(document, requestOptions) {
503
+ let retryCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
504
+ const token = credentialsStorage$1.getToken(requestOptions.mcApiUrl);
505
+ client.setEndpoint("".concat(requestOptions.mcApiUrl, "/graphql"));
506
+ client.setHeaders(requestOptions.headers);
507
+
508
+ if (token) {
509
+ client.setHeader('x-mc-cli-access-token', token);
510
+ }
511
+
512
+ try {
513
+ const result = await client.rawRequest(graphql.print(document), requestOptions.variables); // In case a new session token is returned from the server, save it.
514
+
515
+ const refreshedSessionToken = result.headers.get('x-refreshed-session-token');
516
+
517
+ if (refreshedSessionToken) {
518
+ console.log(chalk__default["default"].green('Session token refreshed.'));
519
+ console.log();
520
+ const refreshedSessionTokenExpiresAt = result.headers.get('x-refreshed-session-token-expires-at'); // Store the updated access token.
521
+
522
+ credentialsStorage$1.setToken(requestOptions.mcApiUrl, {
523
+ token: refreshedSessionToken,
524
+ expiresAt: Number(refreshedSessionTokenExpiresAt)
525
+ });
526
+ }
527
+
528
+ return result.data;
529
+ } catch (error) {
530
+ if (error instanceof graphqlRequest.ClientError) {
531
+ // If it's an unauthorized error, retry the request to force the token to be refreshed.
532
+ if (retryCount === 0 && error.response.errors && error.response.errors.length > 0) {
533
+ var _context;
534
+
535
+ const isUnauthorizedError = _someInstanceProperty__default["default"](_context = error.response.errors).call(_context, graphqlError => {
536
+ var _graphqlError$extensi;
537
+
538
+ return ((_graphqlError$extensi = graphqlError.extensions) === null || _graphqlError$extensi === void 0 ? void 0 : _graphqlError$extensi.code) === 'UNAUTHENTICATED';
539
+ });
540
+
541
+ if (isUnauthorizedError) {
542
+ console.log(chalk__default["default"].yellow('Expired or invalid session token, attempting to retry the request with a refreshed token...'));
543
+ return requestWithTokenRetry(document, _objectSpread(_objectSpread({}, requestOptions), {}, {
544
+ headers: _objectSpread(_objectSpread({}, requestOptions.headers), {}, {
545
+ 'X-Force-Token': 'true'
546
+ })
547
+ }), retryCount + 1);
548
+ }
549
+ }
550
+ }
551
+
552
+ throw error;
553
+ }
554
+ }
555
+
556
+ const fetchCustomApplication = async _ref => {
557
+ let mcApiUrl = _ref.mcApiUrl,
558
+ entryPointUriPath = _ref.entryPointUriPath;
559
+ const customAppData = await requestWithTokenRetry(FetchCustomApplicationFromCli, {
560
+ variables: {
561
+ entryPointUriPath
562
+ },
563
+ mcApiUrl,
564
+ headers: {
565
+ 'x-graphql-target': constants.GRAPHQL_TARGETS.SETTINGS_SERVICE
566
+ }
567
+ });
568
+ return customAppData.organizationExtensionForCustomApplication;
569
+ };
570
+
571
+ const updateCustomApplication = async _ref2 => {
572
+ let mcApiUrl = _ref2.mcApiUrl,
573
+ applicationId = _ref2.applicationId,
574
+ organizationId = _ref2.organizationId,
575
+ data = _ref2.data;
576
+ const updatedCustomAppsData = await requestWithTokenRetry(UpdateCustomApplicationFromCli, {
577
+ variables: {
578
+ organizationId,
579
+ applicationId,
580
+ data
581
+ },
582
+ mcApiUrl,
583
+ headers: {
584
+ 'x-graphql-target': constants.GRAPHQL_TARGETS.SETTINGS_SERVICE
585
+ }
586
+ });
587
+ return updatedCustomAppsData.updateCustomApplication;
588
+ };
589
+
590
+ const createCustomApplication = async _ref3 => {
591
+ let mcApiUrl = _ref3.mcApiUrl,
592
+ organizationId = _ref3.organizationId,
593
+ data = _ref3.data;
594
+ const createdCustomAppData = await requestWithTokenRetry(CreateCustomApplicationFromCli, {
595
+ variables: {
596
+ organizationId,
597
+ data
598
+ },
599
+ mcApiUrl,
600
+ headers: {
601
+ 'x-graphql-target': constants.GRAPHQL_TARGETS.SETTINGS_SERVICE
602
+ }
603
+ });
604
+ return createdCustomAppData.createCustomApplication;
605
+ };
606
+
607
+ const fetchUserOrganizations = async _ref4 => {
608
+ let mcApiUrl = _ref4.mcApiUrl;
609
+ const userOrganizations = await requestWithTokenRetry(FetchMyOrganizationsFromCli, {
610
+ mcApiUrl,
611
+ headers: {
612
+ 'x-graphql-target': constants.GRAPHQL_TARGETS.ADMINISTRATION_SERVICE
613
+ }
614
+ });
615
+ return userOrganizations.myOrganizations;
616
+ };
617
+
618
+ const credentialsStorage = new credentialsStorage$2.CredentialsStorage();
619
+
620
+ const getMcUrlLink = (mcApiUrl, organizationId, applicationId) => {
621
+ var _context, _context2;
622
+
623
+ const mcUrl = mcApiUrl.replace('mc-api', 'mc');
624
+
625
+ const customAppLink = _concatInstanceProperty__default["default"](_context = _concatInstanceProperty__default["default"](_context2 = "".concat(mcUrl, "/account/organizations/")).call(_context2, organizationId, "/custom-applications/owned/")).call(_context, applicationId);
626
+
627
+ return customAppLink;
628
+ };
629
+
630
+ async function run(options) {
631
+ var _context5;
632
+
633
+ const applicationConfig$1 = applicationConfig.processConfig();
634
+ const localCustomAppData = applicationConfig$1.data;
635
+ const mcApiUrl = applicationConfig$1.env.mcApiUrl;
636
+ console.log("Using Merchant Center environment \"".concat(chalk__default["default"].green(mcApiUrl), "\"."));
637
+ console.log();
638
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
639
+
640
+ if (!isSessionValid) {
641
+ throw new Error("You don't have a valid session. Please, run the \"mc-scripts login\" command to authenticate yourself.");
642
+ }
643
+
644
+ const fetchedCustomApplication = await fetchCustomApplication({
645
+ mcApiUrl,
646
+ entryPointUriPath: localCustomAppData.entryPointUriPath
647
+ });
648
+
649
+ if (!fetchedCustomApplication) {
650
+ var _context4;
651
+
652
+ const userOrganizations = await fetchUserOrganizations({
653
+ mcApiUrl
654
+ });
655
+ let organizationId, organizationName;
656
+
657
+ if (userOrganizations.total === 0) {
658
+ 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.");
659
+ }
660
+
661
+ if (userOrganizations.total === 1) {
662
+ const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
663
+ organization = _userOrganizations$re[0];
664
+
665
+ organizationId = organization.id;
666
+ organizationName = organization.name;
667
+ } else {
668
+ var _context3;
669
+
670
+ const organizationChoices = _mapInstanceProperty__default["default"](_context3 = userOrganizations.results).call(_context3, organization => ({
671
+ title: organization.name,
672
+ value: organization.id
673
+ }));
674
+
675
+ const _await$prompts = await prompts__default["default"]({
676
+ type: 'select',
677
+ name: 'organizationId',
678
+ message: 'Select an Organization',
679
+ choices: organizationChoices,
680
+ initial: 0
681
+ }),
682
+ selectedOrganizationId = _await$prompts.organizationId;
683
+
684
+ if (!selectedOrganizationId) {
685
+ throw new Error("No Organization selected, aborting.");
686
+ }
687
+
688
+ organizationId = selectedOrganizationId;
689
+ organizationName = _findInstanceProperty__default["default"](organizationChoices).call(organizationChoices, _ref => {
690
+ let value = _ref.value;
691
+ return value === organizationId;
692
+ }).title;
693
+ }
694
+
695
+ const _await$prompts2 = await prompts__default["default"]({
696
+ type: 'text',
697
+ name: 'confirmation',
698
+ message: _filterInstanceProperty__default["default"](_context4 = ["You are about to create a new Custom Application in the \"".concat(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(_context4, Boolean).join('\n'),
699
+ initial: 'yes'
700
+ }),
701
+ confirmation = _await$prompts2.confirmation;
702
+
703
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
704
+ console.log(chalk__default["default"].red('Aborted.'));
705
+ return;
706
+ }
707
+
708
+ const data = omit__default["default"](localCustomAppData, ['id']);
709
+
710
+ if (options.dryRun) {
711
+ console.log();
712
+ console.log("The following payload would be used to create a new Custom Application.");
713
+ console.log();
714
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
715
+ return;
716
+ }
717
+
718
+ const createdCustomApplication = await createCustomApplication({
719
+ mcApiUrl,
720
+ organizationId,
721
+ data
722
+ }); // This check is technically not necessary, as the `graphql-request` client
723
+ // throws an error in case of GraphQL errors.
724
+ // However, the generated TypeScript data related to the GraphQL query has the
725
+ // field typed as optional, thus having an extra check for type correctness.
726
+
727
+ if (!createdCustomApplication) {
728
+ throw new Error('Failed to create the Custom Application.');
729
+ }
730
+
731
+ const customAppLink = getMcUrlLink(mcApiUrl, organizationId, createdCustomApplication.id);
732
+ 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: \"".concat(chalk__default["default"].green(createdCustomApplication.id), "\".")));
733
+ console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk__default["default"].gray(customAppLink), "\"."));
734
+ return;
735
+ }
736
+
737
+ const customAppLink = getMcUrlLink(mcApiUrl, fetchedCustomApplication.organizationId, fetchedCustomApplication.application.id);
738
+ const configDiff = getConfigDiff(fetchedCustomApplication.application, localCustomAppData);
739
+
740
+ if (!configDiff) {
741
+ console.log(chalk__default["default"].green("Custom Application up-to-date."));
742
+ console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk__default["default"].gray(customAppLink), "\"."));
743
+ return;
744
+ }
745
+
746
+ console.log('Changes detected:');
747
+ console.log(configDiff);
748
+ console.log();
749
+
750
+ const _await$prompts3 = await prompts__default["default"]({
751
+ type: 'text',
752
+ name: 'confirmation',
753
+ message: _filterInstanceProperty__default["default"](_context5 = ["You are about to update the Custom Application \"".concat(chalk__default["default"].green(localCustomAppData.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(_context5, Boolean).join('\n'),
754
+ initial: 'yes'
755
+ }),
756
+ confirmation = _await$prompts3.confirmation;
757
+
758
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
759
+ console.log(chalk__default["default"].red('Aborted.'));
760
+ return;
761
+ }
762
+
763
+ const data = omit__default["default"](localCustomAppData, ['id']);
764
+
765
+ if (options.dryRun) {
766
+ console.log();
767
+ console.log("The following payload would be used to update the Custom Application \"".concat(chalk__default["default"].green(data.entryPointUriPath), "\"."));
768
+ console.log();
769
+ console.log(chalk__default["default"].gray(_JSON$stringify__default["default"](data, null, 2)));
770
+ return;
771
+ }
772
+
773
+ await updateCustomApplication({
774
+ mcApiUrl,
775
+ organizationId: fetchedCustomApplication.organizationId,
776
+ data: omit__default["default"](localCustomAppData, ['id']),
777
+ applicationId: fetchedCustomApplication.application.id
778
+ });
779
+ console.log(chalk__default["default"].green("Custom Application updated."));
780
+ console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk__default["default"].gray(customAppLink), "\"."));
781
+ }
782
+
783
+ exports["default"] = run;