@commercetools-frontend/mc-scripts 25.0.0 → 25.2.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 (84) hide show
  1. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +1 -1
  2. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +1 -1
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +1 -1
  4. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +28 -14
  5. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +28 -14
  6. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +28 -14
  7. package/dist/{build-50f29fb0.cjs.prod.js → build-182a099c.cjs.prod.js} +7 -7
  8. package/dist/{build-0b4c6b04.esm.js → build-220a1658.esm.js} +7 -7
  9. package/dist/{build-1baf8a00.cjs.dev.js → build-519d246d.cjs.dev.js} +7 -7
  10. package/dist/{build-vite-e26f6c9f.cjs.dev.js → build-vite-837e7c94.cjs.dev.js} +64 -43
  11. package/dist/{build-vite-85211835.esm.js → build-vite-8cae71a0.esm.js} +61 -24
  12. package/dist/{build-vite-4a6c90c2.cjs.prod.js → build-vite-b007241b.cjs.prod.js} +64 -43
  13. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +1 -1
  14. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +1 -1
  15. package/dist/commercetools-frontend-mc-scripts.esm.js +1 -1
  16. package/dist/{compile-html-adfef598.esm.js → compile-html-025cd493.esm.js} +2 -4
  17. package/dist/{compile-html-b80f9651.cjs.prod.js → compile-html-50fd05ec.cjs.prod.js} +2 -5
  18. package/dist/{compile-html-8679f721.cjs.dev.js → compile-html-f4ac88cc.cjs.dev.js} +2 -5
  19. package/dist/config-sync-0b96d430.esm.js +255 -0
  20. package/dist/config-sync-b3072939.cjs.prod.js +265 -0
  21. package/dist/config-sync-ci-4a09aa00.cjs.prod.js +305 -0
  22. package/dist/config-sync-ci-85e3fec2.esm.js +294 -0
  23. package/dist/config-sync-ci-eadb8bfc.cjs.dev.js +305 -0
  24. package/dist/config-sync-f8fca39f.cjs.dev.js +265 -0
  25. package/dist/{config-sync-87ba9f28.cjs.prod.js → config-sync-helpers-11fc328f.cjs.prod.js} +193 -326
  26. package/dist/{config-sync-27ca0c93.cjs.dev.js → config-sync-helpers-dab59ed9.cjs.dev.js} +195 -328
  27. package/dist/{config-sync-ff4b1e5b.esm.js → config-sync-helpers-fe6ea729.esm.js} +186 -323
  28. package/dist/{create-postcss-config-34bab342.cjs.prod.js → create-postcss-config-56b74a34.cjs.prod.js} +1 -1
  29. package/dist/{create-postcss-config-0e833724.cjs.dev.js → create-postcss-config-78879a12.cjs.dev.js} +1 -1
  30. package/dist/{create-postcss-config-e6dfba3f.esm.js → create-postcss-config-95f9bf62.esm.js} +1 -1
  31. package/dist/{create-webpack-config-for-development-fe0945ce.cjs.prod.js → create-webpack-config-for-development-3eb1b365.cjs.prod.js} +7 -7
  32. package/dist/{create-webpack-config-for-development-2ac1d86f.cjs.dev.js → create-webpack-config-for-development-62b89920.cjs.dev.js} +7 -7
  33. package/dist/{create-webpack-config-for-development-be2722d6.esm.js → create-webpack-config-for-development-a28736fa.esm.js} +7 -7
  34. package/dist/{create-webpack-config-for-production-66c77849.esm.js → create-webpack-config-for-production-21ea561f.esm.js} +8 -8
  35. package/dist/{create-webpack-config-for-production-2200e554.cjs.prod.js → create-webpack-config-for-production-3b6599db.cjs.prod.js} +8 -8
  36. package/dist/{create-webpack-config-for-production-d2c41a9d.cjs.dev.js → create-webpack-config-for-production-e5ed8805.cjs.dev.js} +8 -8
  37. package/dist/{credentials-storage-381abf27.cjs.prod.js → credentials-storage-6d592cd6.cjs.prod.js} +21 -3
  38. package/dist/{credentials-storage-de220814.cjs.dev.js → credentials-storage-c4c5980e.cjs.dev.js} +21 -3
  39. package/dist/{credentials-storage-7285d7b4.esm.js → credentials-storage-fcc77fb6.esm.js} +21 -3
  40. package/dist/declarations/src/types.d.ts +4 -0
  41. package/dist/{deployment-previews-set-7f9fbfe5.esm.js → deployment-previews-set-7d49e7df.esm.js} +22 -27
  42. package/dist/{deployment-previews-set-3697be5e.cjs.dev.js → deployment-previews-set-8d6a1e99.cjs.dev.js} +22 -28
  43. package/dist/{deployment-previews-set-e92403f7.cjs.prod.js → deployment-previews-set-f8ce3db7.cjs.prod.js} +22 -28
  44. package/dist/{graphql-requests-bab5fcc3.cjs.dev.js → graphql-requests-b57fca4c.cjs.prod.js} +5 -8
  45. package/dist/{graphql-requests-d8bc2292.esm.js → graphql-requests-d2fa2ca7.esm.js} +6 -9
  46. package/dist/{graphql-requests-8ef89149.cjs.prod.js → graphql-requests-da194989.cjs.dev.js} +5 -8
  47. package/dist/{i18n-message-complilation-8aec9d1b.esm.js → i18n-message-complilation-21d3b0aa.esm.js} +1 -1
  48. package/dist/{i18n-message-complilation-3f80e8d6.cjs.dev.js → i18n-message-complilation-7311cb29.cjs.dev.js} +1 -1
  49. package/dist/{i18n-message-complilation-393d344a.cjs.prod.js → i18n-message-complilation-7762da61.cjs.prod.js} +1 -1
  50. package/dist/{login-5fd67aac.cjs.prod.js → login-9774c9cc.cjs.prod.js} +154 -38
  51. package/dist/login-abb38213.esm.js +337 -0
  52. package/dist/{login-9fac9eee.cjs.dev.js → login-f4550251.cjs.dev.js} +154 -38
  53. package/dist/{optimizations-ea21b802.cjs.prod.js → optimizations-7789145e.cjs.dev.js} +5 -8
  54. package/dist/{optimizations-ea71a24a.esm.js → optimizations-bf991634.esm.js} +5 -7
  55. package/dist/{optimizations-ebbeaf88.cjs.dev.js → optimizations-fb93514f.cjs.prod.js} +5 -8
  56. package/dist/{package-ff04bcf7.cjs.dev.js → package-0eebca1b.cjs.dev.js} +21 -11
  57. package/dist/{package-4bdd2ccf.esm.js → package-9e6910b8.esm.js} +21 -11
  58. package/dist/{package-428d5001.cjs.prod.js → package-b9298ce3.cjs.prod.js} +21 -11
  59. package/dist/{paths-7bf7e88e.esm.js → paths-39f22b8b.esm.js} +4 -9
  60. package/dist/{paths-af1a725a.cjs.prod.js → paths-7768b440.cjs.prod.js} +4 -10
  61. package/dist/{paths-ec3e3a7d.cjs.dev.js → paths-b76fc753.cjs.dev.js} +4 -10
  62. package/dist/{serve-04a03d5f.cjs.dev.js → serve-38456e1b.cjs.dev.js} +7 -6
  63. package/dist/{serve-fb1a0f5a.esm.js → serve-be1f9439.esm.js} +6 -6
  64. package/dist/{serve-2a863026.cjs.prod.js → serve-cc4a766d.cjs.prod.js} +7 -6
  65. package/dist/{start-643a55bb.esm.js → start-109f9462.esm.js} +8 -9
  66. package/dist/{start-47ea5e04.cjs.dev.js → start-7765f44c.cjs.dev.js} +8 -9
  67. package/dist/{start-84cdf12b.cjs.prod.js → start-e014127c.cjs.prod.js} +8 -9
  68. package/dist/{start-vite-eea72ba9.cjs.dev.js → start-vite-068e9f73.cjs.dev.js} +3 -4
  69. package/dist/{start-vite-d548c121.cjs.prod.js → start-vite-29078b3a.cjs.prod.js} +3 -4
  70. package/dist/{start-vite-d649d1f3.esm.js → start-vite-7d1161e8.esm.js} +3 -4
  71. package/dist/{vite-plugin-svgr-53ef97c7.cjs.dev.js → vite-plugin-svgr-4034a834.cjs.prod.js} +4 -4
  72. package/dist/{vite-plugin-svgr-5de1cad9.cjs.prod.js → vite-plugin-svgr-7d06f400.cjs.dev.js} +4 -4
  73. package/dist/{vite-plugin-svgr-22c8d518.esm.js → vite-plugin-svgr-de6ee7da.esm.js} +4 -4
  74. package/package.json +21 -11
  75. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -2
  76. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -2
  77. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -2
  78. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +6 -6
  79. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +6 -6
  80. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +6 -6
  81. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +1 -1
  82. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +1 -1
  83. package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +1 -1
  84. package/dist/login-9ee43381.esm.js +0 -223
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
4
3
  var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
5
4
  var fs = require('fs');
6
5
  var chalk = require('chalk');
7
6
  var mcHtmlTemplate = require('@commercetools-frontend/mc-html-template');
8
- var paths = require('./paths-af1a725a.cjs.prod.js');
7
+ var paths = require('./paths-7768b440.cjs.prod.js');
9
8
  require('@babel/runtime-corejs3/core-js-stable/instance/find');
10
9
  require('path');
11
10
  require('./does-file-exist-be53305d.cjs.prod.js');
@@ -13,7 +12,6 @@ require('node:fs');
13
12
 
14
13
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
15
14
 
16
- var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
17
15
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
18
16
  var fs__default = /*#__PURE__*/_interopDefault(fs);
19
17
  var chalk__default = /*#__PURE__*/_interopDefault(chalk);
@@ -33,8 +31,7 @@ async function run(options) {
33
31
  const transformerFn = require(transformerPath);
34
32
  transformerFn(compiled);
35
33
  } catch (error) {
36
- var _context;
37
- throw new Error(_concatInstanceProperty__default["default"](_context = "Could not load transformer module \"".concat(options.transformer, "\"\n")).call(_context, error instanceof Error ? error.stack : ''));
34
+ throw new Error(`Could not load transformer module "${options.transformer}"\n${error instanceof Error ? error.stack : ''}`);
38
35
  }
39
36
  } else if (options.printSecurityHeaders) {
40
37
  console.log(_JSON$stringify__default["default"](compiled.headers));
@@ -1,11 +1,10 @@
1
1
  'use strict';
2
2
 
3
- var _concatInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/concat');
4
3
  var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
5
4
  var fs = require('fs');
6
5
  var chalk = require('chalk');
7
6
  var mcHtmlTemplate = require('@commercetools-frontend/mc-html-template');
8
- var paths = require('./paths-ec3e3a7d.cjs.dev.js');
7
+ var paths = require('./paths-b76fc753.cjs.dev.js');
9
8
  require('@babel/runtime-corejs3/core-js-stable/instance/find');
10
9
  require('path');
11
10
  require('./does-file-exist-eb86baca.cjs.dev.js');
@@ -13,7 +12,6 @@ require('node:fs');
13
12
 
14
13
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
15
14
 
16
- var _concatInstanceProperty__default = /*#__PURE__*/_interopDefault(_concatInstanceProperty);
17
15
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
18
16
  var fs__default = /*#__PURE__*/_interopDefault(fs);
19
17
  var chalk__default = /*#__PURE__*/_interopDefault(chalk);
@@ -33,8 +31,7 @@ async function run(options) {
33
31
  const transformerFn = require(transformerPath);
34
32
  transformerFn(compiled);
35
33
  } catch (error) {
36
- var _context;
37
- throw new Error(_concatInstanceProperty__default["default"](_context = "Could not load transformer module \"".concat(options.transformer, "\"\n")).call(_context, error instanceof Error ? error.stack : ''));
34
+ throw new Error(`Could not load transformer module "${options.transformer}"\n${error instanceof Error ? error.stack : ''}`);
38
35
  }
39
36
  } else if (options.printSecurityHeaders) {
40
37
  console.log(_JSON$stringify__default["default"](compiled.headers));
@@ -0,0 +1,255 @@
1
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
2
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
3
+ import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
4
+ import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
5
+ import chalk from 'chalk';
6
+ import prompts from 'prompts';
7
+ import { processConfig } from '@commercetools-frontend/application-config';
8
+ import { i as isCustomViewData, c as checkCustomApplicationStatus, p as performCreateCustomApplication, a as performUpdateCustomApplication, b as checkCustomViewStatus, d as performCreateCustomView, e as performUpdateCustomView } from './config-sync-helpers-fe6ea729.esm.js';
9
+ import { C as CredentialsStorage } from './credentials-storage-fcc77fb6.esm.js';
10
+ import { f as fetchUserOrganizations } from './graphql-requests-d2fa2ca7.esm.js';
11
+ import '@babel/runtime-corejs3/core-js-stable/json/stringify';
12
+ import 'lodash/omit';
13
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
14
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
15
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
16
+ import '@babel/runtime-corejs3/core-js-stable/object/define-properties';
17
+ import '@babel/runtime-corejs3/core-js-stable/object/define-property';
18
+ import '@babel/runtime-corejs3/helpers/defineProperty';
19
+ import '@babel/runtime-corejs3/core-js-stable/instance/repeat';
20
+ import '@babel/runtime-corejs3/core-js-stable/set';
21
+ import '@babel/runtime-corejs3/core-js-stable/instance/for-each';
22
+ import '@babel/runtime-corejs3/core-js-stable/instance/bind';
23
+ import '@babel/runtime-corejs3/core-js-stable/instance/reduce';
24
+ import '@babel/runtime-corejs3/core-js-stable/object/keys';
25
+ import '@babel/runtime-corejs3/helpers/classCallCheck';
26
+ import '@babel/runtime-corejs3/helpers/createClass';
27
+ import '@babel/runtime-corejs3/core-js-stable/date/now';
28
+ import 'node:fs';
29
+ import 'node:os';
30
+ import 'node:path';
31
+ import './does-file-exist-32618334.esm.js';
32
+ import '@babel/runtime-corejs3/core-js-stable/instance/some';
33
+ import 'graphql';
34
+ import 'graphql-request';
35
+ import '@commercetools-frontend/constants';
36
+ import '@commercetools/http-user-agent';
37
+ import './package-9e6910b8.esm.js';
38
+
39
+ const credentialsStorage = new CredentialsStorage();
40
+ async function promptForOrganization(_ref) {
41
+ var _context;
42
+ let mcApiUrl = _ref.mcApiUrl,
43
+ applicationIdentifier = _ref.applicationIdentifier,
44
+ customViewId = _ref.customViewId,
45
+ entityType = _ref.entityType;
46
+ const userOrganizations = await fetchUserOrganizations({
47
+ mcApiUrl,
48
+ applicationIdentifier,
49
+ customViewId
50
+ });
51
+ if (userOrganizations.total === 0) {
52
+ 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 ${entityType} to be configured to.`);
53
+ }
54
+ if (userOrganizations.total === 1) {
55
+ const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
56
+ organization = _userOrganizations$re[0];
57
+ return {
58
+ id: organization.id,
59
+ name: organization.name
60
+ };
61
+ }
62
+ const organizationChoices = _mapInstanceProperty(_context = userOrganizations.results).call(_context, organization => ({
63
+ title: organization.name,
64
+ value: organization.id
65
+ }));
66
+ const _await$prompts = await prompts({
67
+ type: 'select',
68
+ name: 'organizationId',
69
+ message: 'Select an Organization',
70
+ choices: organizationChoices,
71
+ initial: 0
72
+ }),
73
+ selectedOrganizationId = _await$prompts.organizationId;
74
+ if (!selectedOrganizationId) {
75
+ throw new Error(`No Organization selected, aborting.`);
76
+ }
77
+ const organizationName = _findInstanceProperty(organizationChoices).call(organizationChoices, _ref2 => {
78
+ let value = _ref2.value;
79
+ return value === selectedOrganizationId;
80
+ }).title;
81
+ return {
82
+ id: selectedOrganizationId,
83
+ name: organizationName
84
+ };
85
+ }
86
+ async function confirmAction(_ref3) {
87
+ var _context2;
88
+ let message = _ref3.message,
89
+ dryRun = _ref3.dryRun,
90
+ dryRunMessage = _ref3.dryRunMessage;
91
+ const _await$prompts2 = await prompts({
92
+ type: 'text',
93
+ name: 'confirmation',
94
+ message: _filterInstanceProperty(_context2 = [message, dryRun && chalk.gray(dryRunMessage)]).call(_context2, Boolean).join('\n'),
95
+ initial: 'yes'
96
+ }),
97
+ confirmation = _await$prompts2.confirmation;
98
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
99
+ console.log(chalk.red('Aborted.'));
100
+ return false;
101
+ }
102
+ return true;
103
+ }
104
+ async function createOrUpdateCustomApplication(_ref4) {
105
+ let mcApiUrl = _ref4.mcApiUrl,
106
+ localCustomEntityData = _ref4.localCustomEntityData,
107
+ applicationIdentifier = _ref4.applicationIdentifier,
108
+ options = _ref4.options;
109
+ const status = await checkCustomApplicationStatus({
110
+ mcApiUrl,
111
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
112
+ applicationIdentifier,
113
+ localCustomEntityData
114
+ });
115
+ if (!status.exists) {
116
+ // Create new Custom Application
117
+ const organization = await promptForOrganization({
118
+ mcApiUrl,
119
+ applicationIdentifier,
120
+ entityType: 'Custom Application'
121
+ });
122
+ const confirmed = await confirmAction({
123
+ message: `You are about to create a new Custom Application in the "${chalk.green(organization.name)}" organization. Are you sure you want to proceed?`,
124
+ dryRun: options.dryRun,
125
+ dryRunMessage: 'Using "--dry-run", no data will be created.'
126
+ });
127
+ if (!confirmed) return;
128
+ await performCreateCustomApplication({
129
+ mcApiUrl,
130
+ organizationId: organization.id,
131
+ organizationName: organization.name,
132
+ localCustomEntityData,
133
+ applicationIdentifier,
134
+ dryRun: options.dryRun
135
+ });
136
+ return;
137
+ }
138
+
139
+ // Check for changes
140
+ if (!status.configDiff) {
141
+ console.log(chalk.green(`Custom Application up-to-date.`));
142
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk.gray(status.link)}".`);
143
+ return;
144
+ }
145
+ console.log('Changes detected:');
146
+ console.log(status.configDiff);
147
+ console.log();
148
+ const confirmed = await confirmAction({
149
+ message: `You are about to update the Custom Application "${chalk.green(localCustomEntityData.entryPointUriPath)}" with the changes above. Are you sure you want to proceed?`,
150
+ dryRun: options.dryRun,
151
+ dryRunMessage: 'Using "--dry-run", no data will be updated.'
152
+ });
153
+ if (!confirmed) return;
154
+ await performUpdateCustomApplication({
155
+ mcApiUrl,
156
+ organizationId: status.organizationId,
157
+ applicationId: status.applicationId,
158
+ localCustomEntityData,
159
+ applicationIdentifier,
160
+ dryRun: options.dryRun
161
+ });
162
+ }
163
+ async function createOrUpdateCustomView(_ref5) {
164
+ let mcApiUrl = _ref5.mcApiUrl,
165
+ localCustomEntityData = _ref5.localCustomEntityData,
166
+ customViewId = _ref5.customViewId,
167
+ options = _ref5.options,
168
+ applicationIdentifier = _ref5.applicationIdentifier;
169
+ const status = await checkCustomViewStatus({
170
+ mcApiUrl,
171
+ customViewId,
172
+ applicationIdentifier,
173
+ localCustomEntityData
174
+ });
175
+ if (!status.exists) {
176
+ // Create new Custom View
177
+ const organization = await promptForOrganization({
178
+ mcApiUrl,
179
+ applicationIdentifier,
180
+ customViewId,
181
+ entityType: 'Custom View'
182
+ });
183
+ const confirmed = await confirmAction({
184
+ message: `You are about to create a new Custom View in the "${chalk.green(organization.name)}" organization. Are you sure you want to proceed?`,
185
+ dryRun: options.dryRun,
186
+ dryRunMessage: 'Using "--dry-run", no data will be created.'
187
+ });
188
+ if (!confirmed) return;
189
+ await performCreateCustomView({
190
+ mcApiUrl,
191
+ organizationId: organization.id,
192
+ organizationName: organization.name,
193
+ localCustomEntityData,
194
+ applicationIdentifier,
195
+ dryRun: options.dryRun
196
+ });
197
+ return;
198
+ }
199
+
200
+ // Check for changes
201
+ if (!status.configDiff) {
202
+ console.log(chalk.green(`Custom View up-to-date.`));
203
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk.gray(status.link)}".`);
204
+ return;
205
+ }
206
+ console.log('Changes detected:');
207
+ console.log(status.configDiff);
208
+ console.log();
209
+ const confirmed = await confirmAction({
210
+ message: `You are about to update the Custom View "${chalk.green(localCustomEntityData.defaultLabel)}" with the changes above. Are you sure you want to proceed?`,
211
+ dryRun: options.dryRun,
212
+ dryRunMessage: 'Using "--dry-run", no data will be updated.'
213
+ });
214
+ if (!confirmed) return;
215
+ await performUpdateCustomView({
216
+ mcApiUrl,
217
+ organizationId: status.organizationId,
218
+ customViewId: status.customViewId,
219
+ localCustomEntityData,
220
+ applicationIdentifier,
221
+ dryRun: options.dryRun
222
+ });
223
+ }
224
+ async function run(options) {
225
+ const applicationConfig = await processConfig();
226
+ const localCustomEntityData = applicationConfig.data;
227
+ const _applicationConfig$en = applicationConfig.env,
228
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
229
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier,
230
+ customViewId = _applicationConfig$en.customViewId;
231
+ console.log(`Using Merchant Center environment "${chalk.green(mcApiUrl)}".`);
232
+ console.log();
233
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
234
+ if (!isSessionValid) {
235
+ throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
236
+ }
237
+ if (isCustomViewData(localCustomEntityData)) {
238
+ await createOrUpdateCustomView({
239
+ mcApiUrl,
240
+ localCustomEntityData,
241
+ applicationIdentifier,
242
+ customViewId: customViewId || localCustomEntityData.id,
243
+ options
244
+ });
245
+ } else {
246
+ await createOrUpdateCustomApplication({
247
+ mcApiUrl,
248
+ localCustomEntityData,
249
+ applicationIdentifier,
250
+ options
251
+ });
252
+ }
253
+ }
254
+
255
+ export { run as default };
@@ -0,0 +1,265 @@
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 chalk = require('chalk');
8
+ var prompts = require('prompts');
9
+ var applicationConfig = require('@commercetools-frontend/application-config');
10
+ var configSyncHelpers = require('./config-sync-helpers-11fc328f.cjs.prod.js');
11
+ var credentialsStorage$1 = require('./credentials-storage-6d592cd6.cjs.prod.js');
12
+ var graphqlRequests = require('./graphql-requests-b57fca4c.cjs.prod.js');
13
+ require('@babel/runtime-corejs3/core-js-stable/json/stringify');
14
+ require('lodash/omit');
15
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
16
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
17
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
18
+ require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
19
+ require('@babel/runtime-corejs3/core-js-stable/object/define-property');
20
+ require('@babel/runtime-corejs3/helpers/defineProperty');
21
+ require('@babel/runtime-corejs3/core-js-stable/instance/repeat');
22
+ require('@babel/runtime-corejs3/core-js-stable/set');
23
+ require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
24
+ require('@babel/runtime-corejs3/core-js-stable/instance/bind');
25
+ require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
26
+ require('@babel/runtime-corejs3/core-js-stable/object/keys');
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('node:fs');
31
+ require('node:os');
32
+ require('node:path');
33
+ require('./does-file-exist-be53305d.cjs.prod.js');
34
+ require('@babel/runtime-corejs3/core-js-stable/instance/some');
35
+ require('graphql');
36
+ require('graphql-request');
37
+ require('@commercetools-frontend/constants');
38
+ require('@commercetools/http-user-agent');
39
+ require('./package-b9298ce3.cjs.prod.js');
40
+
41
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
42
+
43
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
44
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
45
+ var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
46
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
47
+ var prompts__default = /*#__PURE__*/_interopDefault(prompts);
48
+
49
+ const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
50
+ async function promptForOrganization(_ref) {
51
+ var _context;
52
+ let mcApiUrl = _ref.mcApiUrl,
53
+ applicationIdentifier = _ref.applicationIdentifier,
54
+ customViewId = _ref.customViewId,
55
+ entityType = _ref.entityType;
56
+ const userOrganizations = await graphqlRequests.fetchUserOrganizations({
57
+ mcApiUrl,
58
+ applicationIdentifier,
59
+ customViewId
60
+ });
61
+ if (userOrganizations.total === 0) {
62
+ 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 ${entityType} to be configured to.`);
63
+ }
64
+ if (userOrganizations.total === 1) {
65
+ const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
66
+ organization = _userOrganizations$re[0];
67
+ return {
68
+ id: organization.id,
69
+ name: organization.name
70
+ };
71
+ }
72
+ const organizationChoices = _mapInstanceProperty__default["default"](_context = userOrganizations.results).call(_context, organization => ({
73
+ title: organization.name,
74
+ value: organization.id
75
+ }));
76
+ const _await$prompts = await prompts__default["default"]({
77
+ type: 'select',
78
+ name: 'organizationId',
79
+ message: 'Select an Organization',
80
+ choices: organizationChoices,
81
+ initial: 0
82
+ }),
83
+ selectedOrganizationId = _await$prompts.organizationId;
84
+ if (!selectedOrganizationId) {
85
+ throw new Error(`No Organization selected, aborting.`);
86
+ }
87
+ const organizationName = _findInstanceProperty__default["default"](organizationChoices).call(organizationChoices, _ref2 => {
88
+ let value = _ref2.value;
89
+ return value === selectedOrganizationId;
90
+ }).title;
91
+ return {
92
+ id: selectedOrganizationId,
93
+ name: organizationName
94
+ };
95
+ }
96
+ async function confirmAction(_ref3) {
97
+ var _context2;
98
+ let message = _ref3.message,
99
+ dryRun = _ref3.dryRun,
100
+ dryRunMessage = _ref3.dryRunMessage;
101
+ const _await$prompts2 = await prompts__default["default"]({
102
+ type: 'text',
103
+ name: 'confirmation',
104
+ message: _filterInstanceProperty__default["default"](_context2 = [message, dryRun && chalk__default["default"].gray(dryRunMessage)]).call(_context2, Boolean).join('\n'),
105
+ initial: 'yes'
106
+ }),
107
+ confirmation = _await$prompts2.confirmation;
108
+ if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
109
+ console.log(chalk__default["default"].red('Aborted.'));
110
+ return false;
111
+ }
112
+ return true;
113
+ }
114
+ async function createOrUpdateCustomApplication(_ref4) {
115
+ let mcApiUrl = _ref4.mcApiUrl,
116
+ localCustomEntityData = _ref4.localCustomEntityData,
117
+ applicationIdentifier = _ref4.applicationIdentifier,
118
+ options = _ref4.options;
119
+ const status = await configSyncHelpers.checkCustomApplicationStatus({
120
+ mcApiUrl,
121
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
122
+ applicationIdentifier,
123
+ localCustomEntityData
124
+ });
125
+ if (!status.exists) {
126
+ // Create new Custom Application
127
+ const organization = await promptForOrganization({
128
+ mcApiUrl,
129
+ applicationIdentifier,
130
+ entityType: 'Custom Application'
131
+ });
132
+ const confirmed = await confirmAction({
133
+ message: `You are about to create a new Custom Application in the "${chalk__default["default"].green(organization.name)}" organization. Are you sure you want to proceed?`,
134
+ dryRun: options.dryRun,
135
+ dryRunMessage: 'Using "--dry-run", no data will be created.'
136
+ });
137
+ if (!confirmed) return;
138
+ await configSyncHelpers.performCreateCustomApplication({
139
+ mcApiUrl,
140
+ organizationId: organization.id,
141
+ organizationName: organization.name,
142
+ localCustomEntityData,
143
+ applicationIdentifier,
144
+ dryRun: options.dryRun
145
+ });
146
+ return;
147
+ }
148
+
149
+ // Check for changes
150
+ if (!status.configDiff) {
151
+ console.log(chalk__default["default"].green(`Custom Application up-to-date.`));
152
+ console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk__default["default"].gray(status.link)}".`);
153
+ return;
154
+ }
155
+ console.log('Changes detected:');
156
+ console.log(status.configDiff);
157
+ console.log();
158
+ const confirmed = await confirmAction({
159
+ message: `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?`,
160
+ dryRun: options.dryRun,
161
+ dryRunMessage: 'Using "--dry-run", no data will be updated.'
162
+ });
163
+ if (!confirmed) return;
164
+ await configSyncHelpers.performUpdateCustomApplication({
165
+ mcApiUrl,
166
+ organizationId: status.organizationId,
167
+ applicationId: status.applicationId,
168
+ localCustomEntityData,
169
+ applicationIdentifier,
170
+ dryRun: options.dryRun
171
+ });
172
+ }
173
+ async function createOrUpdateCustomView(_ref5) {
174
+ let mcApiUrl = _ref5.mcApiUrl,
175
+ localCustomEntityData = _ref5.localCustomEntityData,
176
+ customViewId = _ref5.customViewId,
177
+ options = _ref5.options,
178
+ applicationIdentifier = _ref5.applicationIdentifier;
179
+ const status = await configSyncHelpers.checkCustomViewStatus({
180
+ mcApiUrl,
181
+ customViewId,
182
+ applicationIdentifier,
183
+ localCustomEntityData
184
+ });
185
+ if (!status.exists) {
186
+ // Create new Custom View
187
+ const organization = await promptForOrganization({
188
+ mcApiUrl,
189
+ applicationIdentifier,
190
+ customViewId,
191
+ entityType: 'Custom View'
192
+ });
193
+ const confirmed = await confirmAction({
194
+ message: `You are about to create a new Custom View in the "${chalk__default["default"].green(organization.name)}" organization. Are you sure you want to proceed?`,
195
+ dryRun: options.dryRun,
196
+ dryRunMessage: 'Using "--dry-run", no data will be created.'
197
+ });
198
+ if (!confirmed) return;
199
+ await configSyncHelpers.performCreateCustomView({
200
+ mcApiUrl,
201
+ organizationId: organization.id,
202
+ organizationName: organization.name,
203
+ localCustomEntityData,
204
+ applicationIdentifier,
205
+ dryRun: options.dryRun
206
+ });
207
+ return;
208
+ }
209
+
210
+ // Check for changes
211
+ if (!status.configDiff) {
212
+ console.log(chalk__default["default"].green(`Custom View up-to-date.`));
213
+ console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk__default["default"].gray(status.link)}".`);
214
+ return;
215
+ }
216
+ console.log('Changes detected:');
217
+ console.log(status.configDiff);
218
+ console.log();
219
+ const confirmed = await confirmAction({
220
+ message: `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?`,
221
+ dryRun: options.dryRun,
222
+ dryRunMessage: 'Using "--dry-run", no data will be updated.'
223
+ });
224
+ if (!confirmed) return;
225
+ await configSyncHelpers.performUpdateCustomView({
226
+ mcApiUrl,
227
+ organizationId: status.organizationId,
228
+ customViewId: status.customViewId,
229
+ localCustomEntityData,
230
+ applicationIdentifier,
231
+ dryRun: options.dryRun
232
+ });
233
+ }
234
+ async function run(options) {
235
+ const applicationConfig$1 = await applicationConfig.processConfig();
236
+ const localCustomEntityData = applicationConfig$1.data;
237
+ const _applicationConfig$en = applicationConfig$1.env,
238
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
239
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier,
240
+ customViewId = _applicationConfig$en.customViewId;
241
+ console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
242
+ console.log();
243
+ const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
244
+ if (!isSessionValid) {
245
+ throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
246
+ }
247
+ if (configSyncHelpers.isCustomViewData(localCustomEntityData)) {
248
+ await createOrUpdateCustomView({
249
+ mcApiUrl,
250
+ localCustomEntityData,
251
+ applicationIdentifier,
252
+ customViewId: customViewId || localCustomEntityData.id,
253
+ options
254
+ });
255
+ } else {
256
+ await createOrUpdateCustomApplication({
257
+ mcApiUrl,
258
+ localCustomEntityData,
259
+ applicationIdentifier,
260
+ options
261
+ });
262
+ }
263
+ }
264
+
265
+ exports["default"] = run;