@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
@@ -0,0 +1,305 @@
1
+ 'use strict';
2
+
3
+ var _slicedToArray = require('@babel/runtime-corejs3/helpers/slicedToArray');
4
+ var _findInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/find');
5
+ var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
6
+ var chalk = require('chalk');
7
+ var applicationConfig = require('@commercetools-frontend/application-config');
8
+ var configSyncHelpers = require('./config-sync-helpers-11fc328f.cjs.prod.js');
9
+ var graphqlRequests = require('./graphql-requests-b57fca4c.cjs.prod.js');
10
+ var _Date$now = require('@babel/runtime-corejs3/core-js-stable/date/now');
11
+ var _includesInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/includes');
12
+ var jwtDecode = require('jwt-decode');
13
+ var credentialsStorage = require('./credentials-storage-6d592cd6.cjs.prod.js');
14
+ require('@babel/runtime-corejs3/core-js-stable/json/stringify');
15
+ require('lodash/omit');
16
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
17
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
18
+ require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
19
+ require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
20
+ require('@babel/runtime-corejs3/core-js-stable/object/define-property');
21
+ require('@babel/runtime-corejs3/helpers/defineProperty');
22
+ require('@babel/runtime-corejs3/core-js-stable/instance/repeat');
23
+ require('@babel/runtime-corejs3/core-js-stable/set');
24
+ require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
25
+ require('@babel/runtime-corejs3/core-js-stable/instance/bind');
26
+ require('@babel/runtime-corejs3/core-js-stable/instance/reduce');
27
+ require('@babel/runtime-corejs3/core-js-stable/instance/filter');
28
+ require('@babel/runtime-corejs3/core-js-stable/object/keys');
29
+ require('@babel/runtime-corejs3/core-js-stable/instance/some');
30
+ require('graphql');
31
+ require('graphql-request');
32
+ require('@commercetools-frontend/constants');
33
+ require('@commercetools/http-user-agent');
34
+ require('./package-b9298ce3.cjs.prod.js');
35
+ require('@babel/runtime-corejs3/helpers/classCallCheck');
36
+ require('@babel/runtime-corejs3/helpers/createClass');
37
+ require('node:fs');
38
+ require('node:os');
39
+ require('node:path');
40
+ require('./does-file-exist-be53305d.cjs.prod.js');
41
+
42
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
43
+
44
+ var _findInstanceProperty__default = /*#__PURE__*/_interopDefault(_findInstanceProperty);
45
+ var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
46
+ var chalk__default = /*#__PURE__*/_interopDefault(chalk);
47
+ var _Date$now__default = /*#__PURE__*/_interopDefault(_Date$now);
48
+ var _includesInstanceProperty__default = /*#__PURE__*/_interopDefault(_includesInstanceProperty);
49
+ var jwtDecode__default = /*#__PURE__*/_interopDefault(jwtDecode);
50
+
51
+ /**
52
+ * Environment variable names for CI authentication
53
+ */
54
+ const ENV_VARS$1 = {
55
+ TOKEN: 'MC_ACCESS_TOKEN'
56
+ };
57
+ /**
58
+ * Authenticates for CI environments using environment variables.
59
+ * Supports two authentication methods:
60
+ * 1. MC_ACCESS_TOKEN - Pre-existing session token
61
+ * 2. Existing session from previous mc-scripts login
62
+ */
63
+ async function authenticateForCI(_ref) {
64
+ let mcApiUrl = _ref.mcApiUrl;
65
+ const credentialsStorage$1 = new credentialsStorage.CredentialsStorage();
66
+
67
+ // Option 1: Use pre-existing token from environment
68
+ const envToken = process.env[ENV_VARS$1.TOKEN];
69
+ if (envToken) {
70
+ try {
71
+ const decodedToken = jwtDecode__default["default"](envToken);
72
+ const now = Math.floor(_Date$now__default["default"]() / 1000);
73
+ if (decodedToken.exp <= now) {
74
+ throw new Error('The provided MC_ACCESS_TOKEN has expired');
75
+ }
76
+ // Store the token for subsequent requests
77
+ credentialsStorage$1.setToken(mcApiUrl, {
78
+ token: envToken,
79
+ expiresAt: decodedToken.exp
80
+ });
81
+ return {
82
+ token: envToken,
83
+ expiresAt: decodedToken.exp
84
+ };
85
+ } catch (error) {
86
+ var _context;
87
+ if (error instanceof Error && _includesInstanceProperty__default["default"](_context = error.message).call(_context, 'expired')) {
88
+ throw error;
89
+ }
90
+ throw new Error('The provided MC_ACCESS_TOKEN is invalid');
91
+ }
92
+ }
93
+
94
+ // Option 2: Check if there's already a valid session (from previous mc-scripts login)
95
+ if (credentialsStorage$1.isSessionValid(mcApiUrl)) {
96
+ const token = credentialsStorage$1.getToken(mcApiUrl);
97
+ if (token) {
98
+ const decodedToken = jwtDecode__default["default"](token);
99
+ return {
100
+ token,
101
+ expiresAt: decodedToken.exp
102
+ };
103
+ }
104
+ }
105
+ throw new Error(`No valid authentication found for CI mode. Please provide one of:\n` + ` - ${ENV_VARS$1.TOKEN}: A valid MC session token\n` + ` - Run "mc-scripts login --headless" with IDENTITY_EMAIL and IDENTITY_PASSWORD\n` + ` - Run "mc-scripts login" interactively to create a session`);
106
+ }
107
+
108
+ /**
109
+ * Environment variable names for CI configuration
110
+ */
111
+ const ENV_VARS = {
112
+ ORGANIZATION_ID: 'CT_ORGANIZATION_ID',
113
+ ORGANIZATION_NAME: 'CT_ORGANIZATION_NAME'
114
+ };
115
+ async function resolveOrganization(_ref) {
116
+ var _context3;
117
+ let mcApiUrl = _ref.mcApiUrl,
118
+ applicationIdentifier = _ref.applicationIdentifier,
119
+ customViewId = _ref.customViewId;
120
+ const userOrganizations = await graphqlRequests.fetchUserOrganizations({
121
+ mcApiUrl,
122
+ applicationIdentifier,
123
+ customViewId
124
+ });
125
+ if (userOrganizations.total === 0) {
126
+ throw new Error(`No organizations found. Please ensure you are an admin of at least one Organization.`);
127
+ }
128
+
129
+ // Check if organization was provided via environment variables
130
+ const organizationId = process.env[ENV_VARS.ORGANIZATION_ID];
131
+ const organizationName = process.env[ENV_VARS.ORGANIZATION_NAME];
132
+ if (organizationId) {
133
+ var _context;
134
+ const matchingOrg = _findInstanceProperty__default["default"](_context = userOrganizations.results).call(_context, org => org.id === organizationId);
135
+ if (!matchingOrg) {
136
+ throw new Error(`Organization with ID "${organizationId}" (from ${ENV_VARS.ORGANIZATION_ID}) not found or you don't have admin access to it.`);
137
+ }
138
+ return {
139
+ id: matchingOrg.id,
140
+ name: matchingOrg.name
141
+ };
142
+ }
143
+ if (organizationName) {
144
+ var _context2;
145
+ const matchingOrg = _findInstanceProperty__default["default"](_context2 = userOrganizations.results).call(_context2, org => org.name === organizationName);
146
+ if (!matchingOrg) {
147
+ throw new Error(`Organization with name "${organizationName}" (from ${ENV_VARS.ORGANIZATION_NAME}) not found or you don't have admin access to it.`);
148
+ }
149
+ return {
150
+ id: matchingOrg.id,
151
+ name: matchingOrg.name
152
+ };
153
+ }
154
+
155
+ // If only one organization, use it automatically
156
+ if (userOrganizations.total === 1) {
157
+ const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
158
+ organization = _userOrganizations$re[0];
159
+ console.log(`Using organization "${chalk__default["default"].green(organization.name)}" (only one available).`);
160
+ return {
161
+ id: organization.id,
162
+ name: organization.name
163
+ };
164
+ }
165
+
166
+ // Multiple organizations and none specified - error in CI mode
167
+ const orgNames = _mapInstanceProperty__default["default"](_context3 = userOrganizations.results).call(_context3, org => ` - "${org.name}" (ID: ${org.id})`).join('\n');
168
+ throw new Error(`Multiple organizations found. Please specify one using ${ENV_VARS.ORGANIZATION_ID} or ${ENV_VARS.ORGANIZATION_NAME} environment variable:\n${orgNames}`);
169
+ }
170
+ async function handleCustomApplication(_ref2) {
171
+ let mcApiUrl = _ref2.mcApiUrl,
172
+ localCustomEntityData = _ref2.localCustomEntityData,
173
+ applicationIdentifier = _ref2.applicationIdentifier,
174
+ dryRun = _ref2.dryRun;
175
+ const status = await configSyncHelpers.checkCustomApplicationStatus({
176
+ mcApiUrl,
177
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
178
+ applicationIdentifier,
179
+ localCustomEntityData
180
+ });
181
+ if (!status.exists) {
182
+ // Create new Custom Application
183
+ const organization = await resolveOrganization({
184
+ mcApiUrl,
185
+ applicationIdentifier
186
+ });
187
+ await configSyncHelpers.performCreateCustomApplication({
188
+ mcApiUrl,
189
+ organizationId: organization.id,
190
+ organizationName: organization.name,
191
+ localCustomEntityData,
192
+ applicationIdentifier,
193
+ dryRun
194
+ });
195
+ return;
196
+ }
197
+
198
+ // Check for changes
199
+ if (!status.configDiff) {
200
+ console.log(chalk__default["default"].green('Custom Application is up-to-date.'));
201
+ console.log(`URL: ${chalk__default["default"].gray(status.link)}`);
202
+ return;
203
+ }
204
+ console.log('Changes detected:');
205
+ console.log(status.configDiff);
206
+ console.log();
207
+ await configSyncHelpers.performUpdateCustomApplication({
208
+ mcApiUrl,
209
+ organizationId: status.organizationId,
210
+ applicationId: status.applicationId,
211
+ localCustomEntityData,
212
+ applicationIdentifier,
213
+ dryRun
214
+ });
215
+ }
216
+ async function handleCustomView(_ref3) {
217
+ let mcApiUrl = _ref3.mcApiUrl,
218
+ localCustomEntityData = _ref3.localCustomEntityData,
219
+ customViewId = _ref3.customViewId,
220
+ applicationIdentifier = _ref3.applicationIdentifier,
221
+ dryRun = _ref3.dryRun;
222
+ const status = await configSyncHelpers.checkCustomViewStatus({
223
+ mcApiUrl,
224
+ customViewId,
225
+ applicationIdentifier,
226
+ localCustomEntityData
227
+ });
228
+ if (!status.exists) {
229
+ // Create new Custom View
230
+ const organization = await resolveOrganization({
231
+ mcApiUrl,
232
+ applicationIdentifier,
233
+ customViewId
234
+ });
235
+ await configSyncHelpers.performCreateCustomView({
236
+ mcApiUrl,
237
+ organizationId: organization.id,
238
+ organizationName: organization.name,
239
+ localCustomEntityData,
240
+ applicationIdentifier,
241
+ dryRun
242
+ });
243
+ return;
244
+ }
245
+
246
+ // Check for changes
247
+ if (!status.configDiff) {
248
+ console.log(chalk__default["default"].green('Custom View is up-to-date.'));
249
+ console.log(`URL: ${chalk__default["default"].gray(status.link)}`);
250
+ return;
251
+ }
252
+ console.log('Changes detected:');
253
+ console.log(status.configDiff);
254
+ console.log();
255
+ await configSyncHelpers.performUpdateCustomView({
256
+ mcApiUrl,
257
+ organizationId: status.organizationId,
258
+ customViewId: status.customViewId,
259
+ localCustomEntityData,
260
+ applicationIdentifier,
261
+ dryRun
262
+ });
263
+ }
264
+ async function run(options) {
265
+ const applicationConfig$1 = await applicationConfig.processConfig();
266
+ const localCustomEntityData = applicationConfig$1.data;
267
+ const _applicationConfig$en = applicationConfig$1.env,
268
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
269
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier,
270
+ customViewId = _applicationConfig$en.customViewId;
271
+ console.log(`Environment: ${chalk__default["default"].green(mcApiUrl)}`);
272
+
273
+ // Authenticate for CI
274
+ console.log('Authenticating...');
275
+ try {
276
+ await authenticateForCI({
277
+ mcApiUrl
278
+ });
279
+ console.log(chalk__default["default"].green('Authentication successful.'));
280
+ } catch (error) {
281
+ if (error instanceof Error) {
282
+ throw new Error(`Authentication failed: ${error.message}`);
283
+ }
284
+ throw error;
285
+ }
286
+ console.log();
287
+ if (configSyncHelpers.isCustomViewData(localCustomEntityData)) {
288
+ await handleCustomView({
289
+ mcApiUrl,
290
+ localCustomEntityData,
291
+ customViewId: customViewId || localCustomEntityData.id,
292
+ applicationIdentifier,
293
+ dryRun: options.dryRun
294
+ });
295
+ } else {
296
+ await handleCustomApplication({
297
+ mcApiUrl,
298
+ localCustomEntityData,
299
+ applicationIdentifier,
300
+ dryRun: options.dryRun
301
+ });
302
+ }
303
+ }
304
+
305
+ exports["default"] = run;
@@ -0,0 +1,294 @@
1
+ import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
2
+ import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
3
+ import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
4
+ import chalk from 'chalk';
5
+ import { processConfig } from '@commercetools-frontend/application-config';
6
+ 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';
7
+ import { f as fetchUserOrganizations } from './graphql-requests-d2fa2ca7.esm.js';
8
+ import _Date$now from '@babel/runtime-corejs3/core-js-stable/date/now';
9
+ import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
10
+ import jwtDecode from 'jwt-decode';
11
+ import { C as CredentialsStorage } from './credentials-storage-fcc77fb6.esm.js';
12
+ import '@babel/runtime-corejs3/core-js-stable/json/stringify';
13
+ import 'lodash/omit';
14
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
15
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
16
+ import '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
17
+ import '@babel/runtime-corejs3/core-js-stable/object/define-properties';
18
+ import '@babel/runtime-corejs3/core-js-stable/object/define-property';
19
+ import '@babel/runtime-corejs3/helpers/defineProperty';
20
+ import '@babel/runtime-corejs3/core-js-stable/instance/repeat';
21
+ import '@babel/runtime-corejs3/core-js-stable/set';
22
+ import '@babel/runtime-corejs3/core-js-stable/instance/for-each';
23
+ import '@babel/runtime-corejs3/core-js-stable/instance/bind';
24
+ import '@babel/runtime-corejs3/core-js-stable/instance/reduce';
25
+ import '@babel/runtime-corejs3/core-js-stable/instance/filter';
26
+ import '@babel/runtime-corejs3/core-js-stable/object/keys';
27
+ import '@babel/runtime-corejs3/core-js-stable/instance/some';
28
+ import 'graphql';
29
+ import 'graphql-request';
30
+ import '@commercetools-frontend/constants';
31
+ import '@commercetools/http-user-agent';
32
+ import './package-9e6910b8.esm.js';
33
+ import '@babel/runtime-corejs3/helpers/classCallCheck';
34
+ import '@babel/runtime-corejs3/helpers/createClass';
35
+ import 'node:fs';
36
+ import 'node:os';
37
+ import 'node:path';
38
+ import './does-file-exist-32618334.esm.js';
39
+
40
+ /**
41
+ * Environment variable names for CI authentication
42
+ */
43
+ const ENV_VARS$1 = {
44
+ TOKEN: 'MC_ACCESS_TOKEN'
45
+ };
46
+ /**
47
+ * Authenticates for CI environments using environment variables.
48
+ * Supports two authentication methods:
49
+ * 1. MC_ACCESS_TOKEN - Pre-existing session token
50
+ * 2. Existing session from previous mc-scripts login
51
+ */
52
+ async function authenticateForCI(_ref) {
53
+ let mcApiUrl = _ref.mcApiUrl;
54
+ const credentialsStorage = new CredentialsStorage();
55
+
56
+ // Option 1: Use pre-existing token from environment
57
+ const envToken = process.env[ENV_VARS$1.TOKEN];
58
+ if (envToken) {
59
+ try {
60
+ const decodedToken = jwtDecode(envToken);
61
+ const now = Math.floor(_Date$now() / 1000);
62
+ if (decodedToken.exp <= now) {
63
+ throw new Error('The provided MC_ACCESS_TOKEN has expired');
64
+ }
65
+ // Store the token for subsequent requests
66
+ credentialsStorage.setToken(mcApiUrl, {
67
+ token: envToken,
68
+ expiresAt: decodedToken.exp
69
+ });
70
+ return {
71
+ token: envToken,
72
+ expiresAt: decodedToken.exp
73
+ };
74
+ } catch (error) {
75
+ var _context;
76
+ if (error instanceof Error && _includesInstanceProperty(_context = error.message).call(_context, 'expired')) {
77
+ throw error;
78
+ }
79
+ throw new Error('The provided MC_ACCESS_TOKEN is invalid');
80
+ }
81
+ }
82
+
83
+ // Option 2: Check if there's already a valid session (from previous mc-scripts login)
84
+ if (credentialsStorage.isSessionValid(mcApiUrl)) {
85
+ const token = credentialsStorage.getToken(mcApiUrl);
86
+ if (token) {
87
+ const decodedToken = jwtDecode(token);
88
+ return {
89
+ token,
90
+ expiresAt: decodedToken.exp
91
+ };
92
+ }
93
+ }
94
+ throw new Error(`No valid authentication found for CI mode. Please provide one of:\n` + ` - ${ENV_VARS$1.TOKEN}: A valid MC session token\n` + ` - Run "mc-scripts login --headless" with IDENTITY_EMAIL and IDENTITY_PASSWORD\n` + ` - Run "mc-scripts login" interactively to create a session`);
95
+ }
96
+
97
+ /**
98
+ * Environment variable names for CI configuration
99
+ */
100
+ const ENV_VARS = {
101
+ ORGANIZATION_ID: 'CT_ORGANIZATION_ID',
102
+ ORGANIZATION_NAME: 'CT_ORGANIZATION_NAME'
103
+ };
104
+ async function resolveOrganization(_ref) {
105
+ var _context3;
106
+ let mcApiUrl = _ref.mcApiUrl,
107
+ applicationIdentifier = _ref.applicationIdentifier,
108
+ customViewId = _ref.customViewId;
109
+ const userOrganizations = await fetchUserOrganizations({
110
+ mcApiUrl,
111
+ applicationIdentifier,
112
+ customViewId
113
+ });
114
+ if (userOrganizations.total === 0) {
115
+ throw new Error(`No organizations found. Please ensure you are an admin of at least one Organization.`);
116
+ }
117
+
118
+ // Check if organization was provided via environment variables
119
+ const organizationId = process.env[ENV_VARS.ORGANIZATION_ID];
120
+ const organizationName = process.env[ENV_VARS.ORGANIZATION_NAME];
121
+ if (organizationId) {
122
+ var _context;
123
+ const matchingOrg = _findInstanceProperty(_context = userOrganizations.results).call(_context, org => org.id === organizationId);
124
+ if (!matchingOrg) {
125
+ throw new Error(`Organization with ID "${organizationId}" (from ${ENV_VARS.ORGANIZATION_ID}) not found or you don't have admin access to it.`);
126
+ }
127
+ return {
128
+ id: matchingOrg.id,
129
+ name: matchingOrg.name
130
+ };
131
+ }
132
+ if (organizationName) {
133
+ var _context2;
134
+ const matchingOrg = _findInstanceProperty(_context2 = userOrganizations.results).call(_context2, org => org.name === organizationName);
135
+ if (!matchingOrg) {
136
+ throw new Error(`Organization with name "${organizationName}" (from ${ENV_VARS.ORGANIZATION_NAME}) not found or you don't have admin access to it.`);
137
+ }
138
+ return {
139
+ id: matchingOrg.id,
140
+ name: matchingOrg.name
141
+ };
142
+ }
143
+
144
+ // If only one organization, use it automatically
145
+ if (userOrganizations.total === 1) {
146
+ const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
147
+ organization = _userOrganizations$re[0];
148
+ console.log(`Using organization "${chalk.green(organization.name)}" (only one available).`);
149
+ return {
150
+ id: organization.id,
151
+ name: organization.name
152
+ };
153
+ }
154
+
155
+ // Multiple organizations and none specified - error in CI mode
156
+ const orgNames = _mapInstanceProperty(_context3 = userOrganizations.results).call(_context3, org => ` - "${org.name}" (ID: ${org.id})`).join('\n');
157
+ throw new Error(`Multiple organizations found. Please specify one using ${ENV_VARS.ORGANIZATION_ID} or ${ENV_VARS.ORGANIZATION_NAME} environment variable:\n${orgNames}`);
158
+ }
159
+ async function handleCustomApplication(_ref2) {
160
+ let mcApiUrl = _ref2.mcApiUrl,
161
+ localCustomEntityData = _ref2.localCustomEntityData,
162
+ applicationIdentifier = _ref2.applicationIdentifier,
163
+ dryRun = _ref2.dryRun;
164
+ const status = await checkCustomApplicationStatus({
165
+ mcApiUrl,
166
+ entryPointUriPath: localCustomEntityData.entryPointUriPath,
167
+ applicationIdentifier,
168
+ localCustomEntityData
169
+ });
170
+ if (!status.exists) {
171
+ // Create new Custom Application
172
+ const organization = await resolveOrganization({
173
+ mcApiUrl,
174
+ applicationIdentifier
175
+ });
176
+ await performCreateCustomApplication({
177
+ mcApiUrl,
178
+ organizationId: organization.id,
179
+ organizationName: organization.name,
180
+ localCustomEntityData,
181
+ applicationIdentifier,
182
+ dryRun
183
+ });
184
+ return;
185
+ }
186
+
187
+ // Check for changes
188
+ if (!status.configDiff) {
189
+ console.log(chalk.green('Custom Application is up-to-date.'));
190
+ console.log(`URL: ${chalk.gray(status.link)}`);
191
+ return;
192
+ }
193
+ console.log('Changes detected:');
194
+ console.log(status.configDiff);
195
+ console.log();
196
+ await performUpdateCustomApplication({
197
+ mcApiUrl,
198
+ organizationId: status.organizationId,
199
+ applicationId: status.applicationId,
200
+ localCustomEntityData,
201
+ applicationIdentifier,
202
+ dryRun
203
+ });
204
+ }
205
+ async function handleCustomView(_ref3) {
206
+ let mcApiUrl = _ref3.mcApiUrl,
207
+ localCustomEntityData = _ref3.localCustomEntityData,
208
+ customViewId = _ref3.customViewId,
209
+ applicationIdentifier = _ref3.applicationIdentifier,
210
+ dryRun = _ref3.dryRun;
211
+ const status = await checkCustomViewStatus({
212
+ mcApiUrl,
213
+ customViewId,
214
+ applicationIdentifier,
215
+ localCustomEntityData
216
+ });
217
+ if (!status.exists) {
218
+ // Create new Custom View
219
+ const organization = await resolveOrganization({
220
+ mcApiUrl,
221
+ applicationIdentifier,
222
+ customViewId
223
+ });
224
+ await performCreateCustomView({
225
+ mcApiUrl,
226
+ organizationId: organization.id,
227
+ organizationName: organization.name,
228
+ localCustomEntityData,
229
+ applicationIdentifier,
230
+ dryRun
231
+ });
232
+ return;
233
+ }
234
+
235
+ // Check for changes
236
+ if (!status.configDiff) {
237
+ console.log(chalk.green('Custom View is up-to-date.'));
238
+ console.log(`URL: ${chalk.gray(status.link)}`);
239
+ return;
240
+ }
241
+ console.log('Changes detected:');
242
+ console.log(status.configDiff);
243
+ console.log();
244
+ await performUpdateCustomView({
245
+ mcApiUrl,
246
+ organizationId: status.organizationId,
247
+ customViewId: status.customViewId,
248
+ localCustomEntityData,
249
+ applicationIdentifier,
250
+ dryRun
251
+ });
252
+ }
253
+ async function run(options) {
254
+ const applicationConfig = await processConfig();
255
+ const localCustomEntityData = applicationConfig.data;
256
+ const _applicationConfig$en = applicationConfig.env,
257
+ mcApiUrl = _applicationConfig$en.mcApiUrl,
258
+ applicationIdentifier = _applicationConfig$en.applicationIdentifier,
259
+ customViewId = _applicationConfig$en.customViewId;
260
+ console.log(`Environment: ${chalk.green(mcApiUrl)}`);
261
+
262
+ // Authenticate for CI
263
+ console.log('Authenticating...');
264
+ try {
265
+ await authenticateForCI({
266
+ mcApiUrl
267
+ });
268
+ console.log(chalk.green('Authentication successful.'));
269
+ } catch (error) {
270
+ if (error instanceof Error) {
271
+ throw new Error(`Authentication failed: ${error.message}`);
272
+ }
273
+ throw error;
274
+ }
275
+ console.log();
276
+ if (isCustomViewData(localCustomEntityData)) {
277
+ await handleCustomView({
278
+ mcApiUrl,
279
+ localCustomEntityData,
280
+ customViewId: customViewId || localCustomEntityData.id,
281
+ applicationIdentifier,
282
+ dryRun: options.dryRun
283
+ });
284
+ } else {
285
+ await handleCustomApplication({
286
+ mcApiUrl,
287
+ localCustomEntityData,
288
+ applicationIdentifier,
289
+ dryRun: options.dryRun
290
+ });
291
+ }
292
+ }
293
+
294
+ export { run as default };