@commercetools-frontend/mc-scripts 25.1.0 → 26.0.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.
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +20 -7
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +20 -7
- package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +20 -7
- package/dist/{build-0a5986d1.cjs.dev.js → build-201624d0.cjs.dev.js} +4 -4
- package/dist/{build-dbcd0936.esm.js → build-607506eb.esm.js} +4 -4
- package/dist/{build-ec10df64.cjs.prod.js → build-c3b700bd.cjs.prod.js} +4 -4
- package/dist/{build-vite-16b1a575.cjs.dev.js → build-vite-837e7c94.cjs.dev.js} +56 -34
- package/dist/{build-vite-59e1f185.esm.js → build-vite-8cae71a0.esm.js} +53 -15
- package/dist/{build-vite-5d317720.cjs.prod.js → build-vite-b007241b.cjs.prod.js} +56 -34
- package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +1 -1
- package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +1 -1
- package/dist/commercetools-frontend-mc-scripts.esm.js +1 -1
- package/dist/config-sync-32b19a2a.cjs.dev.js +265 -0
- package/dist/config-sync-57743d92.esm.js +255 -0
- package/dist/config-sync-c3fb301b.cjs.prod.js +265 -0
- package/dist/config-sync-ci-2823fd2e.cjs.prod.js +305 -0
- package/dist/config-sync-ci-8a073525.cjs.dev.js +305 -0
- package/dist/config-sync-ci-fb0d5c7e.esm.js +294 -0
- package/dist/{config-sync-e7f53a98.esm.js → config-sync-helpers-17f05f8f.esm.js} +154 -283
- package/dist/{config-sync-ce05c66c.cjs.prod.js → config-sync-helpers-2239c279.cjs.prod.js} +162 -287
- package/dist/{config-sync-dbb43993.cjs.dev.js → config-sync-helpers-9bd96619.cjs.dev.js} +162 -287
- package/dist/{create-postcss-config-0a86560d.esm.js → create-postcss-config-6c26f1d5.esm.js} +1 -1
- package/dist/{create-postcss-config-381b636b.cjs.dev.js → create-postcss-config-73d94525.cjs.dev.js} +1 -1
- package/dist/{create-postcss-config-91c09596.cjs.prod.js → create-postcss-config-929430f6.cjs.prod.js} +1 -1
- package/dist/{create-webpack-config-for-development-488742b2.cjs.dev.js → create-webpack-config-for-development-3a6f3fac.cjs.dev.js} +2 -2
- package/dist/{create-webpack-config-for-development-37677a49.cjs.prod.js → create-webpack-config-for-development-4749aed7.cjs.prod.js} +2 -2
- package/dist/{create-webpack-config-for-development-df3f7f7f.esm.js → create-webpack-config-for-development-fb17e299.esm.js} +2 -2
- package/dist/{create-webpack-config-for-production-e22f78d2.esm.js → create-webpack-config-for-production-23f194fc.esm.js} +14 -14
- package/dist/{create-webpack-config-for-production-46d817cc.cjs.dev.js → create-webpack-config-for-production-b836a125.cjs.dev.js} +15 -15
- package/dist/{create-webpack-config-for-production-aad64e2a.cjs.prod.js → create-webpack-config-for-production-ee70e601.cjs.prod.js} +15 -15
- package/dist/{credentials-storage-0b89aa0e.cjs.prod.js → credentials-storage-6d592cd6.cjs.prod.js} +20 -2
- package/dist/{credentials-storage-cbb5c559.cjs.dev.js → credentials-storage-c4c5980e.cjs.dev.js} +20 -2
- package/dist/{credentials-storage-4464313c.esm.js → credentials-storage-fcc77fb6.esm.js} +20 -2
- package/dist/declarations/src/types.d.ts +4 -0
- package/dist/{deployment-previews-set-636fb1a3.cjs.prod.js → deployment-previews-set-46172936.cjs.prod.js} +3 -3
- package/dist/{deployment-previews-set-4edd48db.cjs.dev.js → deployment-previews-set-50752e76.cjs.dev.js} +3 -3
- package/dist/{deployment-previews-set-bbef95d2.esm.js → deployment-previews-set-e2c508a2.esm.js} +3 -3
- package/dist/{graphql-requests-23f7ddb1.cjs.dev.js → graphql-requests-79116775.cjs.dev.js} +2 -2
- package/dist/{graphql-requests-0a6eeb3a.cjs.prod.js → graphql-requests-9d9289e2.cjs.prod.js} +2 -2
- package/dist/{graphql-requests-14074b2b.esm.js → graphql-requests-c56947a9.esm.js} +3 -3
- package/dist/{login-a6fd5fbf.cjs.dev.js → login-2ae319b6.cjs.dev.js} +130 -11
- package/dist/{login-1b222f33.esm.js → login-66cf38b8.esm.js} +127 -10
- package/dist/{login-54ebae96.cjs.prod.js → login-fc126950.cjs.prod.js} +130 -11
- package/dist/{package-a34835d9.esm.js → package-0974229d.esm.js} +21 -11
- package/dist/{package-e1f7242c.cjs.prod.js → package-8d902e4f.cjs.dev.js} +21 -11
- package/dist/{package-d8b1f4c0.cjs.dev.js → package-f3555da1.cjs.prod.js} +21 -11
- package/dist/{start-0be8a294.cjs.prod.js → start-6233d44d.cjs.prod.js} +3 -3
- package/dist/{start-890895df.esm.js → start-6406e20a.esm.js} +3 -3
- package/dist/{start-37ec4a7e.cjs.dev.js → start-94c67c51.cjs.dev.js} +3 -3
- package/package.json +21 -11
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -2
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -2
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -2
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +4 -4
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +4 -4
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +4 -4
|
@@ -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-17f05f8f.esm.js';
|
|
7
|
+
import { f as fetchUserOrganizations } from './graphql-requests-c56947a9.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-0974229d.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 };
|