@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.
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +1 -1
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +1 -1
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +1 -1
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +28 -14
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +28 -14
- package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +28 -14
- package/dist/{build-50f29fb0.cjs.prod.js → build-182a099c.cjs.prod.js} +7 -7
- package/dist/{build-0b4c6b04.esm.js → build-220a1658.esm.js} +7 -7
- package/dist/{build-1baf8a00.cjs.dev.js → build-519d246d.cjs.dev.js} +7 -7
- package/dist/{build-vite-e26f6c9f.cjs.dev.js → build-vite-837e7c94.cjs.dev.js} +64 -43
- package/dist/{build-vite-85211835.esm.js → build-vite-8cae71a0.esm.js} +61 -24
- package/dist/{build-vite-4a6c90c2.cjs.prod.js → build-vite-b007241b.cjs.prod.js} +64 -43
- 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/{compile-html-adfef598.esm.js → compile-html-025cd493.esm.js} +2 -4
- package/dist/{compile-html-b80f9651.cjs.prod.js → compile-html-50fd05ec.cjs.prod.js} +2 -5
- package/dist/{compile-html-8679f721.cjs.dev.js → compile-html-f4ac88cc.cjs.dev.js} +2 -5
- package/dist/config-sync-0b96d430.esm.js +255 -0
- package/dist/config-sync-b3072939.cjs.prod.js +265 -0
- package/dist/config-sync-ci-4a09aa00.cjs.prod.js +305 -0
- package/dist/config-sync-ci-85e3fec2.esm.js +294 -0
- package/dist/config-sync-ci-eadb8bfc.cjs.dev.js +305 -0
- package/dist/config-sync-f8fca39f.cjs.dev.js +265 -0
- package/dist/{config-sync-87ba9f28.cjs.prod.js → config-sync-helpers-11fc328f.cjs.prod.js} +193 -326
- package/dist/{config-sync-27ca0c93.cjs.dev.js → config-sync-helpers-dab59ed9.cjs.dev.js} +195 -328
- package/dist/{config-sync-ff4b1e5b.esm.js → config-sync-helpers-fe6ea729.esm.js} +186 -323
- package/dist/{create-postcss-config-34bab342.cjs.prod.js → create-postcss-config-56b74a34.cjs.prod.js} +1 -1
- package/dist/{create-postcss-config-0e833724.cjs.dev.js → create-postcss-config-78879a12.cjs.dev.js} +1 -1
- package/dist/{create-postcss-config-e6dfba3f.esm.js → create-postcss-config-95f9bf62.esm.js} +1 -1
- package/dist/{create-webpack-config-for-development-fe0945ce.cjs.prod.js → create-webpack-config-for-development-3eb1b365.cjs.prod.js} +7 -7
- package/dist/{create-webpack-config-for-development-2ac1d86f.cjs.dev.js → create-webpack-config-for-development-62b89920.cjs.dev.js} +7 -7
- package/dist/{create-webpack-config-for-development-be2722d6.esm.js → create-webpack-config-for-development-a28736fa.esm.js} +7 -7
- package/dist/{create-webpack-config-for-production-66c77849.esm.js → create-webpack-config-for-production-21ea561f.esm.js} +8 -8
- package/dist/{create-webpack-config-for-production-2200e554.cjs.prod.js → create-webpack-config-for-production-3b6599db.cjs.prod.js} +8 -8
- package/dist/{create-webpack-config-for-production-d2c41a9d.cjs.dev.js → create-webpack-config-for-production-e5ed8805.cjs.dev.js} +8 -8
- package/dist/{credentials-storage-381abf27.cjs.prod.js → credentials-storage-6d592cd6.cjs.prod.js} +21 -3
- package/dist/{credentials-storage-de220814.cjs.dev.js → credentials-storage-c4c5980e.cjs.dev.js} +21 -3
- package/dist/{credentials-storage-7285d7b4.esm.js → credentials-storage-fcc77fb6.esm.js} +21 -3
- package/dist/declarations/src/types.d.ts +4 -0
- package/dist/{deployment-previews-set-7f9fbfe5.esm.js → deployment-previews-set-7d49e7df.esm.js} +22 -27
- package/dist/{deployment-previews-set-3697be5e.cjs.dev.js → deployment-previews-set-8d6a1e99.cjs.dev.js} +22 -28
- package/dist/{deployment-previews-set-e92403f7.cjs.prod.js → deployment-previews-set-f8ce3db7.cjs.prod.js} +22 -28
- package/dist/{graphql-requests-bab5fcc3.cjs.dev.js → graphql-requests-b57fca4c.cjs.prod.js} +5 -8
- package/dist/{graphql-requests-d8bc2292.esm.js → graphql-requests-d2fa2ca7.esm.js} +6 -9
- package/dist/{graphql-requests-8ef89149.cjs.prod.js → graphql-requests-da194989.cjs.dev.js} +5 -8
- package/dist/{i18n-message-complilation-8aec9d1b.esm.js → i18n-message-complilation-21d3b0aa.esm.js} +1 -1
- package/dist/{i18n-message-complilation-3f80e8d6.cjs.dev.js → i18n-message-complilation-7311cb29.cjs.dev.js} +1 -1
- package/dist/{i18n-message-complilation-393d344a.cjs.prod.js → i18n-message-complilation-7762da61.cjs.prod.js} +1 -1
- package/dist/{login-5fd67aac.cjs.prod.js → login-9774c9cc.cjs.prod.js} +154 -38
- package/dist/login-abb38213.esm.js +337 -0
- package/dist/{login-9fac9eee.cjs.dev.js → login-f4550251.cjs.dev.js} +154 -38
- package/dist/{optimizations-ea21b802.cjs.prod.js → optimizations-7789145e.cjs.dev.js} +5 -8
- package/dist/{optimizations-ea71a24a.esm.js → optimizations-bf991634.esm.js} +5 -7
- package/dist/{optimizations-ebbeaf88.cjs.dev.js → optimizations-fb93514f.cjs.prod.js} +5 -8
- package/dist/{package-ff04bcf7.cjs.dev.js → package-0eebca1b.cjs.dev.js} +21 -11
- package/dist/{package-4bdd2ccf.esm.js → package-9e6910b8.esm.js} +21 -11
- package/dist/{package-428d5001.cjs.prod.js → package-b9298ce3.cjs.prod.js} +21 -11
- package/dist/{paths-7bf7e88e.esm.js → paths-39f22b8b.esm.js} +4 -9
- package/dist/{paths-af1a725a.cjs.prod.js → paths-7768b440.cjs.prod.js} +4 -10
- package/dist/{paths-ec3e3a7d.cjs.dev.js → paths-b76fc753.cjs.dev.js} +4 -10
- package/dist/{serve-04a03d5f.cjs.dev.js → serve-38456e1b.cjs.dev.js} +7 -6
- package/dist/{serve-fb1a0f5a.esm.js → serve-be1f9439.esm.js} +6 -6
- package/dist/{serve-2a863026.cjs.prod.js → serve-cc4a766d.cjs.prod.js} +7 -6
- package/dist/{start-643a55bb.esm.js → start-109f9462.esm.js} +8 -9
- package/dist/{start-47ea5e04.cjs.dev.js → start-7765f44c.cjs.dev.js} +8 -9
- package/dist/{start-84cdf12b.cjs.prod.js → start-e014127c.cjs.prod.js} +8 -9
- package/dist/{start-vite-eea72ba9.cjs.dev.js → start-vite-068e9f73.cjs.dev.js} +3 -4
- package/dist/{start-vite-d548c121.cjs.prod.js → start-vite-29078b3a.cjs.prod.js} +3 -4
- package/dist/{start-vite-d649d1f3.esm.js → start-vite-7d1161e8.esm.js} +3 -4
- package/dist/{vite-plugin-svgr-53ef97c7.cjs.dev.js → vite-plugin-svgr-4034a834.cjs.prod.js} +4 -4
- package/dist/{vite-plugin-svgr-5de1cad9.cjs.prod.js → vite-plugin-svgr-7d06f400.cjs.dev.js} +4 -4
- package/dist/{vite-plugin-svgr-22c8d518.esm.js → vite-plugin-svgr-de6ee7da.esm.js} +4 -4
- 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 +6 -6
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +6 -6
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +6 -6
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +1 -1
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +1 -1
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +1 -1
- 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-dab59ed9.cjs.dev.js');
|
|
9
|
+
var graphqlRequests = require('./graphql-requests-da194989.cjs.dev.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-c4c5980e.cjs.dev.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-0eebca1b.cjs.dev.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-eb86baca.cjs.dev.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,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-dab59ed9.cjs.dev.js');
|
|
11
|
+
var credentialsStorage$1 = require('./credentials-storage-c4c5980e.cjs.dev.js');
|
|
12
|
+
var graphqlRequests = require('./graphql-requests-da194989.cjs.dev.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-eb86baca.cjs.dev.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-0eebca1b.cjs.dev.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;
|