@commercetools-frontend/mc-scripts 25.1.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 (56) hide show
  1. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +20 -7
  2. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +20 -7
  3. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +20 -7
  4. package/dist/{build-ec10df64.cjs.prod.js → build-182a099c.cjs.prod.js} +3 -3
  5. package/dist/{build-dbcd0936.esm.js → build-220a1658.esm.js} +3 -3
  6. package/dist/{build-0a5986d1.cjs.dev.js → build-519d246d.cjs.dev.js} +3 -3
  7. package/dist/{build-vite-16b1a575.cjs.dev.js → build-vite-837e7c94.cjs.dev.js} +56 -34
  8. package/dist/{build-vite-59e1f185.esm.js → build-vite-8cae71a0.esm.js} +53 -15
  9. package/dist/{build-vite-5d317720.cjs.prod.js → build-vite-b007241b.cjs.prod.js} +56 -34
  10. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +1 -1
  11. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +1 -1
  12. package/dist/commercetools-frontend-mc-scripts.esm.js +1 -1
  13. package/dist/config-sync-0b96d430.esm.js +255 -0
  14. package/dist/config-sync-b3072939.cjs.prod.js +265 -0
  15. package/dist/config-sync-ci-4a09aa00.cjs.prod.js +305 -0
  16. package/dist/config-sync-ci-85e3fec2.esm.js +294 -0
  17. package/dist/config-sync-ci-eadb8bfc.cjs.dev.js +305 -0
  18. package/dist/config-sync-f8fca39f.cjs.dev.js +265 -0
  19. package/dist/{config-sync-ce05c66c.cjs.prod.js → config-sync-helpers-11fc328f.cjs.prod.js} +162 -287
  20. package/dist/{config-sync-dbb43993.cjs.dev.js → config-sync-helpers-dab59ed9.cjs.dev.js} +162 -287
  21. package/dist/{config-sync-e7f53a98.esm.js → config-sync-helpers-fe6ea729.esm.js} +154 -283
  22. package/dist/{create-postcss-config-91c09596.cjs.prod.js → create-postcss-config-56b74a34.cjs.prod.js} +1 -1
  23. package/dist/{create-postcss-config-381b636b.cjs.dev.js → create-postcss-config-78879a12.cjs.dev.js} +1 -1
  24. package/dist/{create-postcss-config-0a86560d.esm.js → create-postcss-config-95f9bf62.esm.js} +1 -1
  25. package/dist/{create-webpack-config-for-development-37677a49.cjs.prod.js → create-webpack-config-for-development-3eb1b365.cjs.prod.js} +2 -2
  26. package/dist/{create-webpack-config-for-development-488742b2.cjs.dev.js → create-webpack-config-for-development-62b89920.cjs.dev.js} +2 -2
  27. package/dist/{create-webpack-config-for-development-df3f7f7f.esm.js → create-webpack-config-for-development-a28736fa.esm.js} +2 -2
  28. package/dist/{create-webpack-config-for-production-e22f78d2.esm.js → create-webpack-config-for-production-21ea561f.esm.js} +2 -2
  29. package/dist/{create-webpack-config-for-production-aad64e2a.cjs.prod.js → create-webpack-config-for-production-3b6599db.cjs.prod.js} +2 -2
  30. package/dist/{create-webpack-config-for-production-46d817cc.cjs.dev.js → create-webpack-config-for-production-e5ed8805.cjs.dev.js} +2 -2
  31. package/dist/{credentials-storage-0b89aa0e.cjs.prod.js → credentials-storage-6d592cd6.cjs.prod.js} +20 -2
  32. package/dist/{credentials-storage-cbb5c559.cjs.dev.js → credentials-storage-c4c5980e.cjs.dev.js} +20 -2
  33. package/dist/{credentials-storage-4464313c.esm.js → credentials-storage-fcc77fb6.esm.js} +20 -2
  34. package/dist/declarations/src/types.d.ts +4 -0
  35. package/dist/{deployment-previews-set-bbef95d2.esm.js → deployment-previews-set-7d49e7df.esm.js} +3 -3
  36. package/dist/{deployment-previews-set-4edd48db.cjs.dev.js → deployment-previews-set-8d6a1e99.cjs.dev.js} +3 -3
  37. package/dist/{deployment-previews-set-636fb1a3.cjs.prod.js → deployment-previews-set-f8ce3db7.cjs.prod.js} +3 -3
  38. package/dist/{graphql-requests-0a6eeb3a.cjs.prod.js → graphql-requests-b57fca4c.cjs.prod.js} +2 -2
  39. package/dist/{graphql-requests-14074b2b.esm.js → graphql-requests-d2fa2ca7.esm.js} +3 -3
  40. package/dist/{graphql-requests-23f7ddb1.cjs.dev.js → graphql-requests-da194989.cjs.dev.js} +2 -2
  41. package/dist/{login-54ebae96.cjs.prod.js → login-9774c9cc.cjs.prod.js} +130 -11
  42. package/dist/{login-1b222f33.esm.js → login-abb38213.esm.js} +127 -10
  43. package/dist/{login-a6fd5fbf.cjs.dev.js → login-f4550251.cjs.dev.js} +130 -11
  44. package/dist/{package-e1f7242c.cjs.prod.js → package-0eebca1b.cjs.dev.js} +20 -10
  45. package/dist/{package-a34835d9.esm.js → package-9e6910b8.esm.js} +20 -10
  46. package/dist/{package-d8b1f4c0.cjs.dev.js → package-b9298ce3.cjs.prod.js} +20 -10
  47. package/dist/{start-890895df.esm.js → start-109f9462.esm.js} +3 -3
  48. package/dist/{start-37ec4a7e.cjs.dev.js → start-7765f44c.cjs.dev.js} +3 -3
  49. package/dist/{start-0be8a294.cjs.prod.js → start-e014127c.cjs.prod.js} +3 -3
  50. package/package.json +20 -10
  51. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -2
  52. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -2
  53. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -2
  54. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +4 -4
  55. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +4 -4
  56. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +4 -4
@@ -3,10 +3,10 @@
3
3
  var _parseInt = require('@babel/runtime-corejs3/core-js-stable/parse-int');
4
4
  var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
5
5
  var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
6
- var path = require('path');
6
+ var path$1 = require('path');
7
7
  var pluginGraphql = require('@rollup/plugin-graphql');
8
8
  var pluginReact = require('@vitejs/plugin-react');
9
- var fs = require('fs-extra');
9
+ var fs$1 = require('fs-extra');
10
10
  var rollupPluginVisualizer = require('rollup-plugin-visualizer');
11
11
  var vite = require('vite');
12
12
  var viteBundleAnalyzer = require('vite-bundle-analyzer');
@@ -17,6 +17,9 @@ var paths = require('./paths-7768b440.cjs.prod.js');
17
17
  var cliLib = require('@formatjs/cli-lib');
18
18
  var pluginutils = require('@rollup/pluginutils');
19
19
  var i18nMessageComplilation = require('./i18n-message-complilation-7762da61.cjs.prod.js');
20
+ var fs = require('node:fs');
21
+ var path = require('node:path');
22
+ var glob = require('glob');
20
23
  var vitePluginSvgr = require('./vite-plugin-svgr-4034a834.cjs.prod.js');
21
24
  require('@babel/runtime-corejs3/helpers/defineProperty');
22
25
  require('@babel/runtime-corejs3/helpers/slicedToArray');
@@ -34,38 +37,21 @@ require('chalk');
34
37
  require('@babel/runtime-corejs3/core-js-stable/instance/find');
35
38
  require('fs');
36
39
  require('./does-file-exist-be53305d.cjs.prod.js');
37
- require('node:fs');
38
40
  require('@babel/runtime-corejs3/core-js-stable/object/values');
39
41
  require('crypto');
40
42
  require('@babel/runtime-corejs3/core-js/instance/match-all');
41
43
 
42
44
  function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
43
45
 
44
- function _interopNamespace(e) {
45
- if (e && e.__esModule) return e;
46
- var n = Object.create(null);
47
- if (e) {
48
- Object.keys(e).forEach(function (k) {
49
- if (k !== 'default') {
50
- var d = Object.getOwnPropertyDescriptor(e, k);
51
- Object.defineProperty(n, k, d.get ? d : {
52
- enumerable: true,
53
- get: function () { return e[k]; }
54
- });
55
- }
56
- });
57
- }
58
- n["default"] = e;
59
- return Object.freeze(n);
60
- }
61
-
62
46
  var _parseInt__default = /*#__PURE__*/_interopDefault(_parseInt);
63
47
  var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
64
48
  var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
65
- var path__default = /*#__PURE__*/_interopDefault(path);
49
+ var path__default$1 = /*#__PURE__*/_interopDefault(path$1);
66
50
  var pluginGraphql__default = /*#__PURE__*/_interopDefault(pluginGraphql);
67
51
  var pluginReact__default = /*#__PURE__*/_interopDefault(pluginReact);
52
+ var fs__default$1 = /*#__PURE__*/_interopDefault(fs$1);
68
53
  var fs__default = /*#__PURE__*/_interopDefault(fs);
54
+ var path__default = /*#__PURE__*/_interopDefault(path);
69
55
 
70
56
  // Type guard to help with filtering arrays for nullish elements.
71
57
  function nonNullable(value) {
@@ -121,25 +107,62 @@ function vitePluginI18nMessageCompilation() {
121
107
  };
122
108
  }
123
109
 
110
+ /**
111
+ * A simple Vite plugin to clean up files matching glob patterns after build.
112
+ * Replaces `vite-plugin-post-cleanup` to avoid the `inflight` vulnerability
113
+ * in its transitive dependencies.
114
+ */
115
+ function pluginPostCleanup(options) {
116
+ return {
117
+ name: 'vite-plugin-post-cleanup',
118
+ apply: 'build',
119
+ closeBundle() {
120
+ const outputDir = options.outputDir,
121
+ patterns = options.patterns,
122
+ verbose = options.verbose;
123
+ let totalFilesDeleted = 0;
124
+ for (const pattern of patterns) {
125
+ const files = glob.globSync(pattern, {
126
+ cwd: outputDir
127
+ });
128
+ for (const file of files) {
129
+ const filePath = path__default["default"].join(outputDir, file);
130
+ try {
131
+ fs__default["default"].unlinkSync(filePath);
132
+ totalFilesDeleted++;
133
+ if (verbose) {
134
+ console.log(`[post-cleanup] Deleted: ${file}`);
135
+ }
136
+ } catch (error) {
137
+ console.warn(`[post-cleanup] Failed to delete ${file}:`, error);
138
+ }
139
+ }
140
+ }
141
+ if (verbose && patterns.length > 0 && totalFilesDeleted === 0) {
142
+ console.log('[post-cleanup] No files matched the patterns');
143
+ }
144
+ }
145
+ };
146
+ }
147
+
124
148
  async function run() {
125
149
  var _context;
126
- const CleanBuild = (await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('vite-plugin-clean-build')); })).default;
127
150
  const DEFAULT_PORT = _parseInt__default["default"](String(process.env.HTTP_PORT), 10) || 3001;
128
151
 
129
152
  // Ensure the `/public` folder exists.
130
- fs__default["default"].mkdirSync(paths.paths.appBuild, {
153
+ fs__default$1["default"].mkdirSync(paths.paths.appBuild, {
131
154
  recursive: true
132
155
  });
133
156
 
134
157
  // Generate `index.html` (template).
135
- const appEntryPoint = path__default["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
158
+ const appEntryPoint = path__default$1["default"].relative(paths.paths.appRoot, paths.paths.entryPoint);
136
159
  const html = mcHtmlTemplate.generateTemplate({
137
160
  // Define the module entry point (path relative from the `/public` folder).
138
161
  // NOTE: that this is different from the development configuration.
139
162
  scriptImports: [`<script type="module" src="/${appEntryPoint}" defer></script>`]
140
163
  });
141
164
  // Write `index.html` (template) into the `/public` folder.
142
- fs__default["default"].writeFileSync(paths.paths.appIndexHtml, html, {
165
+ fs__default$1["default"].writeFileSync(paths.paths.appIndexHtml, html, {
143
166
  encoding: 'utf8'
144
167
  });
145
168
  const appDependencies = require(paths.paths.appPackageJson).dependencies;
@@ -201,12 +224,11 @@ async function run() {
201
224
  // Enable pre-parse default `formatjs` messages into AST.
202
225
  // TODO: make it a CLI option when Vite support becomes stable.
203
226
  process.env.ENABLE_I18N_AST === 'true'
204
- }] : undefined]).call(_context, nonNullable)
227
+ }] : undefined, process.env.ENABLE_BABEL_REACT_COMPILER === 'true' ? 'babel-plugin-react-compiler' : undefined]).call(_context, nonNullable)
205
228
  }
206
229
  }),
207
- // cleanbuild is needed to remove large svg assets
208
- // that are not used after the build.
209
- CleanBuild({
230
+ // Clean up large SVG assets that are not used after the build.
231
+ pluginPostCleanup({
210
232
  outputDir: paths.paths.appBuild,
211
233
  patterns: ['*.react-*.svg'],
212
234
  verbose: true // logs the files that are removed
@@ -220,17 +242,17 @@ async function run() {
220
242
  });
221
243
 
222
244
  // Rename `/public/public/index.html` to `/public/index.html.template`
223
- fs__default["default"].renameSync(
245
+ fs__default$1["default"].renameSync(
224
246
  // Because of our custom entry point path (`/public/index.html`),
225
247
  // Vite will write the `index.html` to `/public/public/index.html`.
226
248
  // We need to move this file to the `/public` folder and rename it
227
249
  // to `index.html.template` (as expected by the `compile-html` command).
228
- path__default["default"].join(paths.paths.appBuild, 'public/index.html'), paths.paths.appIndexHtmlTemplate);
250
+ path__default$1["default"].join(paths.paths.appBuild, 'public/index.html'), paths.paths.appIndexHtmlTemplate);
229
251
  // Clean up nested folder
230
- fs__default["default"].rmdirSync(path__default["default"].join(paths.paths.appBuild, 'public'));
252
+ fs__default$1["default"].rmdirSync(path__default$1["default"].join(paths.paths.appBuild, 'public'));
231
253
 
232
254
  // Copy public assets
233
- fs__default["default"].copySync(path__default["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
255
+ fs__default$1["default"].copySync(path__default$1["default"].join(assets.packageLocation, 'html-page'), paths.paths.appBuild, {
234
256
  dereference: true
235
257
  });
236
258
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var vendorsToTranspile = require('./vendors-to-transpile-6ab4ea06.cjs.dev.js');
6
6
 
7
7
  // NOTE: This string will be replaced on build time with the package version.
8
- var version = "25.1.0";
8
+ var version = "25.2.0";
9
9
 
10
10
  // These exports are deprecated.
11
11
 
@@ -5,7 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var vendorsToTranspile = require('./vendors-to-transpile-04a49d40.cjs.prod.js');
6
6
 
7
7
  // NOTE: This string will be replaced on build time with the package version.
8
- var version = "25.1.0";
8
+ var version = "25.2.0";
9
9
 
10
10
  // These exports are deprecated.
11
11
 
@@ -1,7 +1,7 @@
1
1
  export { v as vendorsToTranspile } from './vendors-to-transpile-7dc84a72.esm.js';
2
2
 
3
3
  // NOTE: This string will be replaced on build time with the package version.
4
- var version = "25.1.0";
4
+ var version = "25.2.0";
5
5
 
6
6
  // These exports are deprecated.
7
7
 
@@ -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 };