@commercetools-frontend/mc-scripts 0.0.0-CRAFT-1791-20251006162610
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/LICENSE +21 -0
- package/README.md +7 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +2 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +7 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
- package/application-runtime/package.json +4 -0
- package/bin/cli.js +8 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +2 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +199 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +199 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +184 -0
- package/cli/package.json +4 -0
- package/config/create-webpack-config-for-development.js +8 -0
- package/config/create-webpack-config-for-production.js +8 -0
- package/config/vendors-to-transpile.js +6 -0
- package/dist/build-2a0a18bd.esm.js +155 -0
- package/dist/build-521f3f9f.cjs.prod.js +169 -0
- package/dist/build-988fc0f7.cjs.dev.js +169 -0
- package/dist/build-vite-16b1a575.cjs.dev.js +238 -0
- package/dist/build-vite-59e1f185.esm.js +208 -0
- package/dist/build-vite-5d317720.cjs.prod.js +238 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +2 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +29 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +29 -0
- package/dist/commercetools-frontend-mc-scripts.esm.js +21 -0
- package/dist/compile-html-025cd493.esm.js +34 -0
- package/dist/compile-html-50fd05ec.cjs.prod.js +42 -0
- package/dist/compile-html-f4ac88cc.cjs.dev.js +42 -0
- package/dist/config-sync-70a16916.cjs.dev.js +852 -0
- package/dist/config-sync-72c20d80.cjs.prod.js +846 -0
- package/dist/config-sync-bc895390.esm.js +830 -0
- package/dist/create-postcss-config-cb7be312.cjs.dev.js +81 -0
- package/dist/create-postcss-config-dde0ccf1.esm.js +75 -0
- package/dist/create-postcss-config-edca0c33.cjs.prod.js +81 -0
- package/dist/create-webpack-config-for-development-1aed1cc0.cjs.prod.js +465 -0
- package/dist/create-webpack-config-for-development-a95f3634.esm.js +440 -0
- package/dist/create-webpack-config-for-development-d003697b.cjs.dev.js +465 -0
- package/dist/create-webpack-config-for-production-15fbe7db.cjs.dev.js +523 -0
- package/dist/create-webpack-config-for-production-764c482f.cjs.prod.js +523 -0
- package/dist/create-webpack-config-for-production-9f42c336.esm.js +493 -0
- package/dist/credentials-storage-66c1e51f.cjs.prod.js +95 -0
- package/dist/credentials-storage-d001f726.esm.js +83 -0
- package/dist/credentials-storage-e7884d17.cjs.dev.js +95 -0
- package/dist/declarations/src/application-runtime.d.ts +1 -0
- package/dist/declarations/src/cli.d.ts +4 -0
- package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
- package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
- package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
- package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
- package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
- package/dist/declarations/src/index.d.ts +3 -0
- package/dist/declarations/src/postcss.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +94 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/dist/declarations/src/webpack-loaders/i18n-message-compilation-loader.d.ts +3 -0
- package/dist/declarations/src/webpack.d.ts +2 -0
- package/dist/deployment-previews-set-17e8ed48.cjs.prod.js +202 -0
- package/dist/deployment-previews-set-3648972f.esm.js +191 -0
- package/dist/deployment-previews-set-37aef990.cjs.dev.js +202 -0
- package/dist/does-file-exist-32618334.esm.js +12 -0
- package/dist/does-file-exist-be53305d.cjs.prod.js +18 -0
- package/dist/does-file-exist-eb86baca.cjs.dev.js +18 -0
- package/dist/graphql-requests-6a47ad5b.esm.js +247 -0
- package/dist/graphql-requests-779b867b.cjs.dev.js +270 -0
- package/dist/graphql-requests-8086eba7.cjs.prod.js +270 -0
- package/dist/has-jsx-runtime-aa5d21ee.cjs.dev.js +15 -0
- package/dist/has-jsx-runtime-c3202df5.cjs.prod.js +15 -0
- package/dist/has-jsx-runtime-e3ecb09b.esm.js +13 -0
- package/dist/i18n-message-complilation-21d3b0aa.esm.js +15 -0
- package/dist/i18n-message-complilation-7311cb29.cjs.dev.js +23 -0
- package/dist/i18n-message-complilation-7762da61.cjs.prod.js +23 -0
- package/dist/login-0a728449.esm.js +229 -0
- package/dist/login-817a5a26.cjs.dev.js +270 -0
- package/dist/login-85c25393.cjs.prod.js +270 -0
- package/dist/optimizations-7789145e.cjs.dev.js +85 -0
- package/dist/optimizations-bf991634.esm.js +67 -0
- package/dist/optimizations-fb93514f.cjs.prod.js +85 -0
- package/dist/package-7e170dc4.cjs.dev.js +160 -0
- package/dist/package-940b0a2a.cjs.prod.js +160 -0
- package/dist/package-99e547a7.esm.js +158 -0
- package/dist/paths-39f22b8b.esm.js +36 -0
- package/dist/paths-7768b440.cjs.prod.js +44 -0
- package/dist/paths-b76fc753.cjs.dev.js +44 -0
- package/dist/serve-1036c2de.esm.js +55 -0
- package/dist/serve-50d33f0b.cjs.dev.js +64 -0
- package/dist/serve-8a506da6.cjs.prod.js +64 -0
- package/dist/start-1d677ad8.cjs.dev.js +177 -0
- package/dist/start-2a7ae03d.esm.js +164 -0
- package/dist/start-f56cb5f7.cjs.prod.js +177 -0
- package/dist/start-vite-068e9f73.cjs.dev.js +128 -0
- package/dist/start-vite-29078b3a.cjs.prod.js +128 -0
- package/dist/start-vite-7d1161e8.esm.js +116 -0
- package/dist/vendors-to-transpile-04a49d40.cjs.prod.js +5 -0
- package/dist/vendors-to-transpile-6ab4ea06.cjs.dev.js +5 -0
- package/dist/vendors-to-transpile-7dc84a72.esm.js +3 -0
- package/dist/vite-plugin-svgr-4034a834.cjs.prod.js +151 -0
- package/dist/vite-plugin-svgr-7d06f400.cjs.dev.js +151 -0
- package/dist/vite-plugin-svgr-de6ee7da.esm.js +125 -0
- package/package.json +156 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +2 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +12 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +12 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +4 -0
- package/postcss/package.json +4 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +2 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +57 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +57 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +48 -0
- package/webpack/package.json +4 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts +3 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +30 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.js +7 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +30 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +26 -0
- package/webpack-loaders/i18n-message-compilation-loader/package.json +4 -0
|
@@ -0,0 +1,830 @@
|
|
|
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 _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import omit from 'lodash/omit';
|
|
8
|
+
import prompts from 'prompts';
|
|
9
|
+
import { sanitizeSvg, processConfig } from '@commercetools-frontend/application-config';
|
|
10
|
+
import { C as CredentialsStorage } from './credentials-storage-d001f726.esm.js';
|
|
11
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
12
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
13
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
14
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
15
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
16
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
17
|
+
import _repeatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/repeat';
|
|
18
|
+
import _Set from '@babel/runtime-corejs3/core-js-stable/set';
|
|
19
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
20
|
+
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
21
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
22
|
+
import { f as fetchCustomApplication, a as fetchUserOrganizations, c as createCustomApplication, u as updateCustomApplication, b as fetchCustomView, d as createCustomView, e as updateCustomView } from './graphql-requests-6a47ad5b.esm.js';
|
|
23
|
+
import '@commercetools/http-user-agent';
|
|
24
|
+
import './package-99e547a7.esm.js';
|
|
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
|
+
|
|
37
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
38
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context7, _context8; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context7 = ownKeys(Object(t), !0)).call(_context7, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context8 = ownKeys(Object(t))).call(_context8, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
39
|
+
|
|
40
|
+
// Since not all terminal supports colors, to make things more consistent for testing purposes,
|
|
41
|
+
// during tests the color used is appended before the string instead of coloring it.
|
|
42
|
+
const isTest = process.env.NODE_ENV === 'test';
|
|
43
|
+
const red = str => {
|
|
44
|
+
if (isTest) return `<color-red>${str}</color-red>`;
|
|
45
|
+
return chalk.red(str);
|
|
46
|
+
};
|
|
47
|
+
const green = str => {
|
|
48
|
+
if (isTest) return `<color-green>${str}</color-green>`;
|
|
49
|
+
return chalk.green(str);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// Two spaces are used for indentation.
|
|
53
|
+
const indent = indentLevel => {
|
|
54
|
+
var _context;
|
|
55
|
+
return _repeatInstanceProperty(_context = ' ').call(_context, indentLevel);
|
|
56
|
+
};
|
|
57
|
+
const getStringDiff = _ref => {
|
|
58
|
+
let previousValue = _ref.previousValue,
|
|
59
|
+
nextValue = _ref.nextValue,
|
|
60
|
+
label = _ref.label,
|
|
61
|
+
_ref$indentLevel = _ref.indentLevel,
|
|
62
|
+
indentLevel = _ref$indentLevel === void 0 ? 0 : _ref$indentLevel;
|
|
63
|
+
if (!previousValue && nextValue) {
|
|
64
|
+
return `${indent(indentLevel)}${label} added: ${green(nextValue)}`;
|
|
65
|
+
}
|
|
66
|
+
if (previousValue && !nextValue) {
|
|
67
|
+
return `${indent(indentLevel)}${label} removed: ${red(previousValue)}`;
|
|
68
|
+
}
|
|
69
|
+
if (previousValue && nextValue && previousValue !== nextValue) {
|
|
70
|
+
return `${indent(indentLevel)}${label} changed: ${red(previousValue)} => ${green(nextValue)}`;
|
|
71
|
+
}
|
|
72
|
+
return null;
|
|
73
|
+
};
|
|
74
|
+
// NOTE: this assumes that the array values are scalar values (not objects).
|
|
75
|
+
const getArrayDiff = _ref2 => {
|
|
76
|
+
let previousValue = _ref2.previousValue,
|
|
77
|
+
nextValue = _ref2.nextValue,
|
|
78
|
+
label = _ref2.label,
|
|
79
|
+
_ref2$indentLevel = _ref2.indentLevel,
|
|
80
|
+
indentLevel = _ref2$indentLevel === void 0 ? 0 : _ref2$indentLevel;
|
|
81
|
+
const oldArraySet = new _Set(previousValue);
|
|
82
|
+
const arrayDiff = [];
|
|
83
|
+
nextValue?.forEach(item => {
|
|
84
|
+
if (oldArraySet.has(item)) {
|
|
85
|
+
oldArraySet.delete(item);
|
|
86
|
+
} else {
|
|
87
|
+
arrayDiff.push(getStringDiff({
|
|
88
|
+
nextValue: item,
|
|
89
|
+
label,
|
|
90
|
+
indentLevel
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
_forEachInstanceProperty(oldArraySet).call(oldArraySet, item => {
|
|
95
|
+
arrayDiff.push(getStringDiff({
|
|
96
|
+
previousValue: item,
|
|
97
|
+
label,
|
|
98
|
+
indentLevel
|
|
99
|
+
}));
|
|
100
|
+
});
|
|
101
|
+
return arrayDiff.join('\n');
|
|
102
|
+
};
|
|
103
|
+
const getPermissionsDiff = _ref3 => {
|
|
104
|
+
var _context2;
|
|
105
|
+
let previousValue = _ref3.previousValue,
|
|
106
|
+
nextValue = _ref3.nextValue;
|
|
107
|
+
const permissionDiff = ['permissions changed'];
|
|
108
|
+
const mappedOldPermissions = _reduceInstanceProperty(previousValue).call(previousValue, (previousPermission, _ref4) => {
|
|
109
|
+
let name = _ref4.name,
|
|
110
|
+
oAuthScopes = _ref4.oAuthScopes;
|
|
111
|
+
return _objectSpread(_objectSpread({}, previousPermission), {}, {
|
|
112
|
+
[name]: oAuthScopes
|
|
113
|
+
});
|
|
114
|
+
}, {});
|
|
115
|
+
const indentLevel = 1;
|
|
116
|
+
_forEachInstanceProperty(nextValue).call(nextValue, newPermission => {
|
|
117
|
+
const currentDiff = [`${indent(indentLevel)}"${newPermission.name}" changed`];
|
|
118
|
+
// if the permission name is not in the old config, it means it is a new addition.
|
|
119
|
+
if (!mappedOldPermissions[newPermission.name]) {
|
|
120
|
+
permissionDiff.push(`${indent(indentLevel)}"${green(newPermission.name)}" was added`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// if permission name is in the old config, now we check if there was a change
|
|
124
|
+
else {
|
|
125
|
+
currentDiff.push(getArrayDiff({
|
|
126
|
+
previousValue: mappedOldPermissions[newPermission.name],
|
|
127
|
+
nextValue: newPermission.oAuthScopes,
|
|
128
|
+
label: 'oauth scope',
|
|
129
|
+
indentLevel: 2
|
|
130
|
+
}));
|
|
131
|
+
delete mappedOldPermissions[newPermission.name];
|
|
132
|
+
}
|
|
133
|
+
_filterInstanceProperty(currentDiff).call(currentDiff, Boolean).length > 1 && permissionDiff.push(currentDiff.join('\n'));
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// if there are old permissions left, it means they were deleted in the new Permissions.
|
|
137
|
+
_forEachInstanceProperty(_context2 = _Object$keys(mappedOldPermissions)).call(_context2, oldPermissionName => {
|
|
138
|
+
permissionDiff.push(`${indent(indentLevel)}"${red(oldPermissionName)}" was removed`);
|
|
139
|
+
});
|
|
140
|
+
if (permissionDiff.length > 1) return permissionDiff.join('\n');
|
|
141
|
+
return null;
|
|
142
|
+
};
|
|
143
|
+
const getLabelAllLocalesDiff = _ref5 => {
|
|
144
|
+
var _context3;
|
|
145
|
+
let _ref5$previousValue = _ref5.previousValue,
|
|
146
|
+
previousValue = _ref5$previousValue === void 0 ? [] : _ref5$previousValue,
|
|
147
|
+
_ref5$nextValue = _ref5.nextValue,
|
|
148
|
+
nextValue = _ref5$nextValue === void 0 ? [] : _ref5$nextValue,
|
|
149
|
+
_ref5$indentLevel = _ref5.indentLevel,
|
|
150
|
+
indentLevel = _ref5$indentLevel === void 0 ? 0 : _ref5$indentLevel;
|
|
151
|
+
const labelAllLocalesDiff = [`${indent(indentLevel - 1)}labelAllLocales changed`];
|
|
152
|
+
const mappedOldLabelAllLocales = _reduceInstanceProperty(previousValue).call(previousValue, (previousLabelAllLocale, _ref6) => {
|
|
153
|
+
let locale = _ref6.locale,
|
|
154
|
+
value = _ref6.value;
|
|
155
|
+
return _objectSpread(_objectSpread({}, previousLabelAllLocale), {}, {
|
|
156
|
+
[locale]: value
|
|
157
|
+
});
|
|
158
|
+
}, {});
|
|
159
|
+
_forEachInstanceProperty(nextValue).call(nextValue, newLabelAllLocale => {
|
|
160
|
+
if (newLabelAllLocale.locale in mappedOldLabelAllLocales) {
|
|
161
|
+
const oldLocaleValue = mappedOldLabelAllLocales[newLabelAllLocale.locale];
|
|
162
|
+
if (oldLocaleValue !== newLabelAllLocale.value) {
|
|
163
|
+
labelAllLocalesDiff.push(`${indent(indentLevel)}locale "${newLabelAllLocale.locale}" changed: ${red(oldLocaleValue)} => ${green(newLabelAllLocale.value)}`);
|
|
164
|
+
}
|
|
165
|
+
delete mappedOldLabelAllLocales[newLabelAllLocale.locale];
|
|
166
|
+
} else {
|
|
167
|
+
const localeDiff = getStringDiff({
|
|
168
|
+
nextValue: newLabelAllLocale.locale,
|
|
169
|
+
label: 'locale',
|
|
170
|
+
indentLevel
|
|
171
|
+
});
|
|
172
|
+
if (localeDiff) {
|
|
173
|
+
labelAllLocalesDiff.push(localeDiff);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
_forEachInstanceProperty(_context3 = _Object$keys(mappedOldLabelAllLocales)).call(_context3, key => {
|
|
178
|
+
const localeDiff = getStringDiff({
|
|
179
|
+
previousValue: key,
|
|
180
|
+
label: 'locale',
|
|
181
|
+
indentLevel
|
|
182
|
+
});
|
|
183
|
+
if (localeDiff) {
|
|
184
|
+
labelAllLocalesDiff.push(localeDiff);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
if (labelAllLocalesDiff.length > 1) return labelAllLocalesDiff.join('\n');
|
|
188
|
+
return null;
|
|
189
|
+
};
|
|
190
|
+
const getTypeSettingsDiff = _ref7 => {
|
|
191
|
+
var _context4;
|
|
192
|
+
let previousValue = _ref7.previousValue,
|
|
193
|
+
nextValue = _ref7.nextValue;
|
|
194
|
+
const nonNullablePreviousValue = previousValue || {};
|
|
195
|
+
const nonNullableNextValue = nextValue || {};
|
|
196
|
+
const indentLevel = 1;
|
|
197
|
+
const typeSettingsDiff = [`${indent(indentLevel - 1)}type settings changed`];
|
|
198
|
+
_forEachInstanceProperty(_context4 = _Object$keys(nonNullablePreviousValue)).call(_context4, key => {
|
|
199
|
+
const typeSettingDiff = getStringDiff({
|
|
200
|
+
previousValue: nonNullablePreviousValue[key],
|
|
201
|
+
nextValue: nonNullableNextValue[key],
|
|
202
|
+
label: key,
|
|
203
|
+
indentLevel
|
|
204
|
+
});
|
|
205
|
+
if (typeSettingDiff) {
|
|
206
|
+
typeSettingsDiff.push(typeSettingDiff);
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
if (typeSettingsDiff.length > 1) return typeSettingsDiff.join('\n');
|
|
210
|
+
return null;
|
|
211
|
+
};
|
|
212
|
+
const getLocatorsDiff = _ref8 => {
|
|
213
|
+
let previousValue = _ref8.previousValue,
|
|
214
|
+
nextValue = _ref8.nextValue;
|
|
215
|
+
const diff = [];
|
|
216
|
+
const locatorsDiff = getArrayDiff({
|
|
217
|
+
previousValue: previousValue,
|
|
218
|
+
nextValue: nextValue,
|
|
219
|
+
label: 'locators',
|
|
220
|
+
indentLevel: 1
|
|
221
|
+
});
|
|
222
|
+
if (locatorsDiff) {
|
|
223
|
+
diff.push('locators changed');
|
|
224
|
+
diff.push(locatorsDiff);
|
|
225
|
+
}
|
|
226
|
+
return diff.join('\n');
|
|
227
|
+
};
|
|
228
|
+
const getMainMenuLinkDiff = _ref9 => {
|
|
229
|
+
let previousValue = _ref9.previousValue,
|
|
230
|
+
nextValue = _ref9.nextValue;
|
|
231
|
+
const mainMenuLinkDiff = ['mainMenuLink changed'];
|
|
232
|
+
const menuDiff = getStringDiff({
|
|
233
|
+
previousValue: previousValue.defaultLabel,
|
|
234
|
+
nextValue: nextValue.defaultLabel,
|
|
235
|
+
label: 'defaultLabel',
|
|
236
|
+
indentLevel: 1
|
|
237
|
+
});
|
|
238
|
+
if (menuDiff) {
|
|
239
|
+
mainMenuLinkDiff.push(menuDiff);
|
|
240
|
+
}
|
|
241
|
+
const mainMenuLinkPermissionsDiff = getArrayDiff({
|
|
242
|
+
previousValue: previousValue.permissions,
|
|
243
|
+
nextValue: nextValue.permissions,
|
|
244
|
+
label: 'applied permission',
|
|
245
|
+
indentLevel: 2
|
|
246
|
+
});
|
|
247
|
+
if (mainMenuLinkPermissionsDiff.length > 0) {
|
|
248
|
+
mainMenuLinkDiff.push(`${indent(1)}permissions changed`);
|
|
249
|
+
mainMenuLinkDiff.push(mainMenuLinkPermissionsDiff);
|
|
250
|
+
}
|
|
251
|
+
const menuLabelsDiff = getLabelAllLocalesDiff({
|
|
252
|
+
previousValue: previousValue.labelAllLocales,
|
|
253
|
+
nextValue: nextValue.labelAllLocales,
|
|
254
|
+
indentLevel: 2
|
|
255
|
+
});
|
|
256
|
+
if (menuLabelsDiff) {
|
|
257
|
+
mainMenuLinkDiff.push(menuLabelsDiff);
|
|
258
|
+
}
|
|
259
|
+
const filteredMainMenuLinkDiff = _filterInstanceProperty(mainMenuLinkDiff).call(mainMenuLinkDiff, Boolean);
|
|
260
|
+
if (filteredMainMenuLinkDiff.length > 1) return filteredMainMenuLinkDiff.join('\n');
|
|
261
|
+
return null;
|
|
262
|
+
};
|
|
263
|
+
const getSubmenuLinksDiff = _ref0 => {
|
|
264
|
+
var _context6;
|
|
265
|
+
let previousValue = _ref0.previousValue,
|
|
266
|
+
nextValue = _ref0.nextValue;
|
|
267
|
+
const submenuLinksDiff = ['submenuLink changed'];
|
|
268
|
+
const mappedSubmenuLinks = _reduceInstanceProperty(previousValue).call(previousValue, (previousSubmenuLink, currentSubmenuLink) => _objectSpread(_objectSpread({}, previousSubmenuLink), {}, {
|
|
269
|
+
[currentSubmenuLink.uriPath]: currentSubmenuLink
|
|
270
|
+
}), {});
|
|
271
|
+
const getOrder = value => _mapInstanceProperty(value).call(value, link => link.uriPath).join(', ');
|
|
272
|
+
const previousOrder = getOrder(previousValue);
|
|
273
|
+
const newOrder = getOrder(nextValue);
|
|
274
|
+
if (previousOrder !== newOrder) {
|
|
275
|
+
submenuLinksDiff.push(`${indent(1)}submenu order changed`);
|
|
276
|
+
submenuLinksDiff.push(`${indent(2)}previous order: [${previousOrder}]`);
|
|
277
|
+
submenuLinksDiff.push(`${indent(2)}new order: [${newOrder}]`);
|
|
278
|
+
}
|
|
279
|
+
_forEachInstanceProperty(nextValue).call(nextValue, newSubmenuLink => {
|
|
280
|
+
const oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
|
|
281
|
+
if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
|
|
282
|
+
var _context5;
|
|
283
|
+
const submenuLinkDiff = [`${indent(1)}menu link "${newSubmenuLink.uriPath}" changed`];
|
|
284
|
+
_forEachInstanceProperty(_context5 = _Object$keys(mappedSubmenuLinks[newSubmenuLink.uriPath])).call(_context5, key => {
|
|
285
|
+
switch (key) {
|
|
286
|
+
case 'defaultLabel':
|
|
287
|
+
{
|
|
288
|
+
const labelDiff = getStringDiff({
|
|
289
|
+
previousValue: oldSubMenuLink.defaultLabel,
|
|
290
|
+
nextValue: newSubmenuLink.defaultLabel,
|
|
291
|
+
label: 'defaultLabel',
|
|
292
|
+
indentLevel: 2
|
|
293
|
+
});
|
|
294
|
+
if (labelDiff) {
|
|
295
|
+
submenuLinkDiff.push(labelDiff);
|
|
296
|
+
}
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
case 'permissions':
|
|
300
|
+
{
|
|
301
|
+
const submenuLinkPermissionsDiff = getArrayDiff({
|
|
302
|
+
previousValue: oldSubMenuLink.permissions,
|
|
303
|
+
nextValue: newSubmenuLink.permissions,
|
|
304
|
+
label: 'applied permission',
|
|
305
|
+
indentLevel: 3
|
|
306
|
+
});
|
|
307
|
+
if (submenuLinkPermissionsDiff.length > 0) {
|
|
308
|
+
submenuLinkDiff.push(`${indent(2)}permissions changed`);
|
|
309
|
+
submenuLinkDiff.push(submenuLinkPermissionsDiff);
|
|
310
|
+
}
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
case 'labelAllLocales':
|
|
314
|
+
{
|
|
315
|
+
const labelsDiff = getLabelAllLocalesDiff({
|
|
316
|
+
previousValue: oldSubMenuLink.labelAllLocales,
|
|
317
|
+
nextValue: newSubmenuLink.labelAllLocales,
|
|
318
|
+
indentLevel: 3
|
|
319
|
+
});
|
|
320
|
+
if (labelsDiff) {
|
|
321
|
+
submenuLinkDiff.push(labelsDiff);
|
|
322
|
+
}
|
|
323
|
+
break;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
});
|
|
327
|
+
delete mappedSubmenuLinks[newSubmenuLink.uriPath];
|
|
328
|
+
const filteredSubmenuLinksDiff = _filterInstanceProperty(submenuLinkDiff).call(submenuLinkDiff, Boolean);
|
|
329
|
+
if (filteredSubmenuLinksDiff.length > 1) {
|
|
330
|
+
submenuLinksDiff.push(filteredSubmenuLinksDiff.join('\n'));
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
const linksDiff = getStringDiff({
|
|
334
|
+
nextValue: newSubmenuLink.uriPath,
|
|
335
|
+
label: 'menu link',
|
|
336
|
+
indentLevel: 1
|
|
337
|
+
});
|
|
338
|
+
if (linksDiff) {
|
|
339
|
+
submenuLinksDiff.push(linksDiff);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
_forEachInstanceProperty(_context6 = _Object$keys(mappedSubmenuLinks)).call(_context6, key => {
|
|
344
|
+
const linksDiff = getStringDiff({
|
|
345
|
+
previousValue: key,
|
|
346
|
+
label: 'menu link',
|
|
347
|
+
indentLevel: 1
|
|
348
|
+
});
|
|
349
|
+
if (linksDiff) submenuLinksDiff.push(linksDiff);
|
|
350
|
+
});
|
|
351
|
+
if (submenuLinksDiff.length > 1) return submenuLinksDiff.join('\n');
|
|
352
|
+
return null;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
// Compute diff changes of the Custom Application config.
|
|
356
|
+
// NOTE: Only known keys are evaluated.
|
|
357
|
+
const getCustomApplicationConfigDiff = (oldConfig, newConfig) => {
|
|
358
|
+
const diff = [];
|
|
359
|
+
|
|
360
|
+
// Name
|
|
361
|
+
const nameDiff = getStringDiff({
|
|
362
|
+
previousValue: oldConfig.name,
|
|
363
|
+
nextValue: newConfig.name,
|
|
364
|
+
label: 'name'
|
|
365
|
+
});
|
|
366
|
+
if (nameDiff) {
|
|
367
|
+
diff.push(nameDiff);
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// Description
|
|
371
|
+
const descriptionDiff = getStringDiff({
|
|
372
|
+
previousValue: oldConfig.description,
|
|
373
|
+
nextValue: newConfig.description,
|
|
374
|
+
label: 'description'
|
|
375
|
+
});
|
|
376
|
+
if (descriptionDiff) {
|
|
377
|
+
diff.push(descriptionDiff);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// URL
|
|
381
|
+
const urlDiff = getStringDiff({
|
|
382
|
+
previousValue: oldConfig.url,
|
|
383
|
+
nextValue: newConfig.url,
|
|
384
|
+
label: 'url'
|
|
385
|
+
});
|
|
386
|
+
if (urlDiff) {
|
|
387
|
+
diff.push(urlDiff);
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
// Icon
|
|
391
|
+
const iconDiff = getStringDiff({
|
|
392
|
+
// This icon stored in the database has already been sanitized.
|
|
393
|
+
previousValue: oldConfig.icon,
|
|
394
|
+
// Sanitize the raw icon as-if it was stored in the database,
|
|
395
|
+
// to ensure the data can be safely compared.
|
|
396
|
+
nextValue: sanitizeSvg(newConfig.icon),
|
|
397
|
+
label: 'icon'
|
|
398
|
+
});
|
|
399
|
+
if (iconDiff) {
|
|
400
|
+
diff.push(iconDiff);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// Permissions
|
|
404
|
+
const permissionsDiff = getPermissionsDiff({
|
|
405
|
+
previousValue: oldConfig.permissions,
|
|
406
|
+
nextValue: newConfig.permissions
|
|
407
|
+
});
|
|
408
|
+
if (permissionsDiff) {
|
|
409
|
+
diff.push(permissionsDiff);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// Main menu link
|
|
413
|
+
const mainMenuDiff = getMainMenuLinkDiff({
|
|
414
|
+
previousValue: oldConfig.mainMenuLink,
|
|
415
|
+
nextValue: newConfig.mainMenuLink
|
|
416
|
+
});
|
|
417
|
+
if (mainMenuDiff) {
|
|
418
|
+
diff.push(mainMenuDiff);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Submenu links
|
|
422
|
+
const submenuDiff = getSubmenuLinksDiff({
|
|
423
|
+
previousValue: oldConfig.submenuLinks,
|
|
424
|
+
nextValue: newConfig.submenuLinks
|
|
425
|
+
});
|
|
426
|
+
if (submenuDiff) {
|
|
427
|
+
diff.push(submenuDiff);
|
|
428
|
+
}
|
|
429
|
+
return diff.join('\n');
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
// Compute diff changes of the Custom View config.
|
|
433
|
+
// NOTE: Only known keys are evaluated.
|
|
434
|
+
const getCustomViewConfigDiff = (oldConfig, newConfig) => {
|
|
435
|
+
const diff = [];
|
|
436
|
+
|
|
437
|
+
// Default Label
|
|
438
|
+
const defaultLabelDiff = getStringDiff({
|
|
439
|
+
previousValue: oldConfig.defaultLabel,
|
|
440
|
+
nextValue: newConfig.defaultLabel,
|
|
441
|
+
label: 'defaultLabel'
|
|
442
|
+
});
|
|
443
|
+
if (defaultLabelDiff) {
|
|
444
|
+
diff.push(defaultLabelDiff);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// Description
|
|
448
|
+
const descriptionDiff = getStringDiff({
|
|
449
|
+
previousValue: oldConfig.description,
|
|
450
|
+
nextValue: newConfig.description,
|
|
451
|
+
label: 'description'
|
|
452
|
+
});
|
|
453
|
+
if (descriptionDiff) {
|
|
454
|
+
diff.push(descriptionDiff);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
// URL
|
|
458
|
+
const urlDiff = getStringDiff({
|
|
459
|
+
previousValue: oldConfig.url,
|
|
460
|
+
nextValue: newConfig.url,
|
|
461
|
+
label: 'url'
|
|
462
|
+
});
|
|
463
|
+
if (urlDiff) {
|
|
464
|
+
diff.push(urlDiff);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Type
|
|
468
|
+
const typeDiff = getStringDiff({
|
|
469
|
+
previousValue: oldConfig.type,
|
|
470
|
+
nextValue: newConfig.type,
|
|
471
|
+
label: 'type'
|
|
472
|
+
});
|
|
473
|
+
if (typeDiff) {
|
|
474
|
+
diff.push(typeDiff);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// Permissions
|
|
478
|
+
const permissionsDiff = getPermissionsDiff({
|
|
479
|
+
previousValue: oldConfig.permissions,
|
|
480
|
+
nextValue: newConfig.permissions
|
|
481
|
+
});
|
|
482
|
+
if (permissionsDiff) {
|
|
483
|
+
diff.push(permissionsDiff);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
// Label All Locales
|
|
487
|
+
const labelsDiff = getLabelAllLocalesDiff({
|
|
488
|
+
previousValue: oldConfig.labelAllLocales,
|
|
489
|
+
nextValue: newConfig.labelAllLocales,
|
|
490
|
+
indentLevel: 1
|
|
491
|
+
});
|
|
492
|
+
if (labelsDiff) {
|
|
493
|
+
diff.push(labelsDiff);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// Type settings
|
|
497
|
+
const typeSettingsDiff = getTypeSettingsDiff({
|
|
498
|
+
previousValue: oldConfig.typeSettings,
|
|
499
|
+
nextValue: newConfig.typeSettings
|
|
500
|
+
});
|
|
501
|
+
if (typeSettingsDiff) {
|
|
502
|
+
diff.push(typeSettingsDiff);
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
// Locators
|
|
506
|
+
const locatorsDiff = getLocatorsDiff({
|
|
507
|
+
previousValue: oldConfig.locators,
|
|
508
|
+
nextValue: newConfig.locators
|
|
509
|
+
});
|
|
510
|
+
if (locatorsDiff) {
|
|
511
|
+
diff.push(locatorsDiff);
|
|
512
|
+
}
|
|
513
|
+
return diff.join('\n');
|
|
514
|
+
};
|
|
515
|
+
|
|
516
|
+
const credentialsStorage = new CredentialsStorage();
|
|
517
|
+
const getMcUrlLink = _ref => {
|
|
518
|
+
let mcApiUrl = _ref.mcApiUrl,
|
|
519
|
+
organizationId = _ref.organizationId,
|
|
520
|
+
customEntityId = _ref.customEntityId,
|
|
521
|
+
isCustomView = _ref.isCustomView;
|
|
522
|
+
const mcUrl = mcApiUrl.replace('mc-api', 'mc');
|
|
523
|
+
const customEntityLink = `${mcUrl}/account/organizations/${organizationId}/custom-${isCustomView ? 'views' : 'applications'}/owned/${customEntityId}`;
|
|
524
|
+
return customEntityLink;
|
|
525
|
+
};
|
|
526
|
+
const isCustomViewData = data => data.entryPointUriPath === undefined;
|
|
527
|
+
async function createOrUpdateCustomApplication(_ref2) {
|
|
528
|
+
var _context3;
|
|
529
|
+
let mcApiUrl = _ref2.mcApiUrl,
|
|
530
|
+
localCustomEntityData = _ref2.localCustomEntityData,
|
|
531
|
+
applicationIdentifier = _ref2.applicationIdentifier,
|
|
532
|
+
options = _ref2.options;
|
|
533
|
+
const fetchedCustomApplication = await fetchCustomApplication({
|
|
534
|
+
mcApiUrl,
|
|
535
|
+
entryPointUriPath: localCustomEntityData.entryPointUriPath,
|
|
536
|
+
applicationIdentifier
|
|
537
|
+
});
|
|
538
|
+
if (!fetchedCustomApplication) {
|
|
539
|
+
var _context2;
|
|
540
|
+
const userOrganizations = await fetchUserOrganizations({
|
|
541
|
+
mcApiUrl,
|
|
542
|
+
applicationIdentifier
|
|
543
|
+
});
|
|
544
|
+
let organizationId, organizationName;
|
|
545
|
+
if (userOrganizations.total === 0) {
|
|
546
|
+
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 Custom Application to be configured to.`);
|
|
547
|
+
}
|
|
548
|
+
if (userOrganizations.total === 1) {
|
|
549
|
+
const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
|
|
550
|
+
organization = _userOrganizations$re[0];
|
|
551
|
+
organizationId = organization.id;
|
|
552
|
+
organizationName = organization.name;
|
|
553
|
+
} else {
|
|
554
|
+
var _context;
|
|
555
|
+
const organizationChoices = _mapInstanceProperty(_context = userOrganizations.results).call(_context, organization => ({
|
|
556
|
+
title: organization.name,
|
|
557
|
+
value: organization.id
|
|
558
|
+
}));
|
|
559
|
+
const _await$prompts = await prompts({
|
|
560
|
+
type: 'select',
|
|
561
|
+
name: 'organizationId',
|
|
562
|
+
message: 'Select an Organization',
|
|
563
|
+
choices: organizationChoices,
|
|
564
|
+
initial: 0
|
|
565
|
+
}),
|
|
566
|
+
selectedOrganizationId = _await$prompts.organizationId;
|
|
567
|
+
if (!selectedOrganizationId) {
|
|
568
|
+
throw new Error(`No Organization selected, aborting.`);
|
|
569
|
+
}
|
|
570
|
+
organizationId = selectedOrganizationId;
|
|
571
|
+
organizationName = _findInstanceProperty(organizationChoices).call(organizationChoices, _ref3 => {
|
|
572
|
+
let value = _ref3.value;
|
|
573
|
+
return value === organizationId;
|
|
574
|
+
}).title;
|
|
575
|
+
}
|
|
576
|
+
const _await$prompts2 = await prompts({
|
|
577
|
+
type: 'text',
|
|
578
|
+
name: 'confirmation',
|
|
579
|
+
message: _filterInstanceProperty(_context2 = [`You are about to create a new Custom Application in the "${chalk.green(organizationName)}" organization. Are you sure you want to proceed?`, options.dryRun && chalk.gray('Using "--dry-run", no data will be created.')]).call(_context2, Boolean).join('\n'),
|
|
580
|
+
initial: 'yes'
|
|
581
|
+
}),
|
|
582
|
+
confirmation = _await$prompts2.confirmation;
|
|
583
|
+
if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
|
|
584
|
+
console.log(chalk.red('Aborted.'));
|
|
585
|
+
return;
|
|
586
|
+
}
|
|
587
|
+
const data = omit(localCustomEntityData, ['id']);
|
|
588
|
+
if (options.dryRun) {
|
|
589
|
+
console.log();
|
|
590
|
+
console.log(`The following payload would be used to create a new Custom Application.`);
|
|
591
|
+
console.log();
|
|
592
|
+
console.log(chalk.gray(_JSON$stringify(data, null, 2)));
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
const createdCustomApplication = await createCustomApplication({
|
|
596
|
+
mcApiUrl,
|
|
597
|
+
organizationId,
|
|
598
|
+
data,
|
|
599
|
+
applicationIdentifier
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
// This check is technically not necessary, as the `graphql-request` client
|
|
603
|
+
// throws an error in case of GraphQL errors.
|
|
604
|
+
// However, the generated TypeScript data related to the GraphQL query has the
|
|
605
|
+
// field typed as optional, thus having an extra check for type correctness.
|
|
606
|
+
if (!createdCustomApplication) {
|
|
607
|
+
throw new Error('Failed to create the Custom Application.');
|
|
608
|
+
}
|
|
609
|
+
const customAppLink = getMcUrlLink({
|
|
610
|
+
mcApiUrl,
|
|
611
|
+
organizationId,
|
|
612
|
+
customEntityId: createdCustomApplication.id
|
|
613
|
+
});
|
|
614
|
+
console.log(chalk.green(`Custom Application created.\nPlease update the "env.production.applicationId" field in your local Custom Application config file with the following value: "${chalk.green(createdCustomApplication.id)}".`));
|
|
615
|
+
console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk.gray(customAppLink)}".`);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const customAppLink = getMcUrlLink({
|
|
619
|
+
mcApiUrl,
|
|
620
|
+
organizationId: fetchedCustomApplication.organizationId,
|
|
621
|
+
customEntityId: fetchedCustomApplication.application.id
|
|
622
|
+
});
|
|
623
|
+
const configDiff = getCustomApplicationConfigDiff(fetchedCustomApplication.application, localCustomEntityData);
|
|
624
|
+
if (!configDiff) {
|
|
625
|
+
console.log(chalk.green(`Custom Application up-to-date.`));
|
|
626
|
+
console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk.gray(customAppLink)}".`);
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
console.log('Changes detected:');
|
|
630
|
+
console.log(configDiff);
|
|
631
|
+
console.log();
|
|
632
|
+
const _await$prompts3 = await prompts({
|
|
633
|
+
type: 'text',
|
|
634
|
+
name: 'confirmation',
|
|
635
|
+
message: _filterInstanceProperty(_context3 = [`You are about to update the Custom Application "${chalk.green(localCustomEntityData.entryPointUriPath)}" with the changes above. Are you sure you want to proceed?`, options.dryRun && chalk.gray('Using "--dry-run", no data will be updated.')]).call(_context3, Boolean).join('\n'),
|
|
636
|
+
initial: 'yes'
|
|
637
|
+
}),
|
|
638
|
+
confirmation = _await$prompts3.confirmation;
|
|
639
|
+
if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
|
|
640
|
+
console.log(chalk.red('Aborted.'));
|
|
641
|
+
return;
|
|
642
|
+
}
|
|
643
|
+
const data = omit(localCustomEntityData, ['id']);
|
|
644
|
+
if (options.dryRun) {
|
|
645
|
+
console.log();
|
|
646
|
+
console.log(`The following payload would be used to update the Custom Application "${chalk.green(data.entryPointUriPath)}".`);
|
|
647
|
+
console.log();
|
|
648
|
+
console.log(chalk.gray(_JSON$stringify(data, null, 2)));
|
|
649
|
+
return;
|
|
650
|
+
}
|
|
651
|
+
await updateCustomApplication({
|
|
652
|
+
mcApiUrl,
|
|
653
|
+
organizationId: fetchedCustomApplication.organizationId,
|
|
654
|
+
data: omit(localCustomEntityData, ['id']),
|
|
655
|
+
applicationId: fetchedCustomApplication.application.id,
|
|
656
|
+
applicationIdentifier
|
|
657
|
+
});
|
|
658
|
+
console.log(chalk.green(`Custom Application updated.`));
|
|
659
|
+
console.log(`You can inspect the Custom Application data in the Merchant Center at "${chalk.gray(customAppLink)}".`);
|
|
660
|
+
}
|
|
661
|
+
async function createOrUpdateCustomView(_ref4) {
|
|
662
|
+
var _context6;
|
|
663
|
+
let mcApiUrl = _ref4.mcApiUrl,
|
|
664
|
+
localCustomEntityData = _ref4.localCustomEntityData,
|
|
665
|
+
customViewId = _ref4.customViewId,
|
|
666
|
+
options = _ref4.options,
|
|
667
|
+
applicationIdentifier = _ref4.applicationIdentifier;
|
|
668
|
+
const fetchedCustomView = await fetchCustomView({
|
|
669
|
+
mcApiUrl,
|
|
670
|
+
customViewId,
|
|
671
|
+
applicationIdentifier
|
|
672
|
+
});
|
|
673
|
+
if (!fetchedCustomView) {
|
|
674
|
+
var _context5;
|
|
675
|
+
const userOrganizations = await fetchUserOrganizations({
|
|
676
|
+
mcApiUrl,
|
|
677
|
+
customViewId,
|
|
678
|
+
applicationIdentifier
|
|
679
|
+
});
|
|
680
|
+
let organizationId, organizationName;
|
|
681
|
+
if (userOrganizations.total === 0) {
|
|
682
|
+
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 Custom View to be configured to.`);
|
|
683
|
+
}
|
|
684
|
+
if (userOrganizations.total === 1) {
|
|
685
|
+
const _userOrganizations$re2 = _slicedToArray(userOrganizations.results, 1),
|
|
686
|
+
organization = _userOrganizations$re2[0];
|
|
687
|
+
organizationId = organization.id;
|
|
688
|
+
organizationName = organization.name;
|
|
689
|
+
} else {
|
|
690
|
+
var _context4;
|
|
691
|
+
const organizationChoices = _mapInstanceProperty(_context4 = userOrganizations.results).call(_context4, organization => ({
|
|
692
|
+
title: organization.name,
|
|
693
|
+
value: organization.id
|
|
694
|
+
}));
|
|
695
|
+
const _await$prompts4 = await prompts({
|
|
696
|
+
type: 'select',
|
|
697
|
+
name: 'organizationId',
|
|
698
|
+
message: 'Select an Organization',
|
|
699
|
+
choices: organizationChoices,
|
|
700
|
+
initial: 0
|
|
701
|
+
}),
|
|
702
|
+
selectedOrganizationId = _await$prompts4.organizationId;
|
|
703
|
+
if (!selectedOrganizationId) {
|
|
704
|
+
throw new Error(`No Organization selected, aborting.`);
|
|
705
|
+
}
|
|
706
|
+
organizationId = selectedOrganizationId;
|
|
707
|
+
organizationName = _findInstanceProperty(organizationChoices).call(organizationChoices, _ref5 => {
|
|
708
|
+
let value = _ref5.value;
|
|
709
|
+
return value === organizationId;
|
|
710
|
+
}).title;
|
|
711
|
+
}
|
|
712
|
+
const _await$prompts5 = await prompts({
|
|
713
|
+
type: 'text',
|
|
714
|
+
name: 'confirmation',
|
|
715
|
+
message: _filterInstanceProperty(_context5 = [`You are about to create a new Custom View in the "${chalk.green(organizationName)}" organization. Are you sure you want to proceed?`, options.dryRun && chalk.gray('Using "--dry-run", no data will be created.')]).call(_context5, Boolean).join('\n'),
|
|
716
|
+
initial: 'yes'
|
|
717
|
+
}),
|
|
718
|
+
confirmation = _await$prompts5.confirmation;
|
|
719
|
+
if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
|
|
720
|
+
console.log(chalk.red('Aborted.'));
|
|
721
|
+
return;
|
|
722
|
+
}
|
|
723
|
+
const data = omit(localCustomEntityData, ['id']);
|
|
724
|
+
if (options.dryRun) {
|
|
725
|
+
console.log();
|
|
726
|
+
console.log(`The following payload would be used to create a new Custom View.`);
|
|
727
|
+
console.log();
|
|
728
|
+
console.log(chalk.gray(_JSON$stringify(data, null, 2)));
|
|
729
|
+
return;
|
|
730
|
+
}
|
|
731
|
+
const createdCustomView = await createCustomView({
|
|
732
|
+
mcApiUrl,
|
|
733
|
+
organizationId,
|
|
734
|
+
data,
|
|
735
|
+
applicationIdentifier
|
|
736
|
+
});
|
|
737
|
+
|
|
738
|
+
// This check is technically not necessary, as the `graphql-request` client
|
|
739
|
+
// throws an error in case of GraphQL errors.
|
|
740
|
+
// However, the generated TypeScript data related to the GraphQL query has the
|
|
741
|
+
// field typed as optional, thus having an extra check for type correctness.
|
|
742
|
+
if (!createdCustomView) {
|
|
743
|
+
throw new Error('Failed to create the Custom View.');
|
|
744
|
+
}
|
|
745
|
+
const customViewLink = getMcUrlLink({
|
|
746
|
+
mcApiUrl,
|
|
747
|
+
organizationId,
|
|
748
|
+
customEntityId: createdCustomView.id,
|
|
749
|
+
isCustomView: true
|
|
750
|
+
});
|
|
751
|
+
console.log(chalk.green(`Custom View created.\nPlease update the "env.production.customViewId" field in your local Custom View config file with the following value: "${chalk.green(createdCustomView.id)}".`));
|
|
752
|
+
console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk.gray(customViewLink)}".`);
|
|
753
|
+
return;
|
|
754
|
+
}
|
|
755
|
+
const customViewLink = getMcUrlLink({
|
|
756
|
+
mcApiUrl,
|
|
757
|
+
organizationId: fetchedCustomView.organizationId,
|
|
758
|
+
customEntityId: fetchedCustomView?.customView?.id || '',
|
|
759
|
+
isCustomView: true
|
|
760
|
+
});
|
|
761
|
+
const configDiff = getCustomViewConfigDiff(fetchedCustomView.customView, localCustomEntityData);
|
|
762
|
+
if (!configDiff) {
|
|
763
|
+
console.log(chalk.green(`Custom View up-to-date.`));
|
|
764
|
+
console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk.gray(customViewLink)}".`);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
console.log('Changes detected:');
|
|
768
|
+
console.log(configDiff);
|
|
769
|
+
console.log();
|
|
770
|
+
const _await$prompts6 = await prompts({
|
|
771
|
+
type: 'text',
|
|
772
|
+
name: 'confirmation',
|
|
773
|
+
message: _filterInstanceProperty(_context6 = [`You are about to update the Custom View "${chalk.green(localCustomEntityData.defaultLabel)}" with the changes above. Are you sure you want to proceed?`, options.dryRun && chalk.gray('Using "--dry-run", no data will be updated.')]).call(_context6, Boolean).join('\n'),
|
|
774
|
+
initial: 'yes'
|
|
775
|
+
}),
|
|
776
|
+
confirmation = _await$prompts6.confirmation;
|
|
777
|
+
if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
|
|
778
|
+
console.log(chalk.red('Aborted.'));
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
const data = omit(localCustomEntityData, ['id']);
|
|
782
|
+
if (options.dryRun) {
|
|
783
|
+
console.log();
|
|
784
|
+
console.log(`The following payload would be used to update the Custom View "${chalk.green(data.defaultLabel)}".`);
|
|
785
|
+
console.log();
|
|
786
|
+
console.log(chalk.gray(_JSON$stringify(data, null, 2)));
|
|
787
|
+
return;
|
|
788
|
+
}
|
|
789
|
+
await updateCustomView({
|
|
790
|
+
mcApiUrl,
|
|
791
|
+
organizationId: fetchedCustomView.organizationId,
|
|
792
|
+
data: omit(localCustomEntityData, ['id']),
|
|
793
|
+
customViewId: fetchedCustomView?.customView?.id || '',
|
|
794
|
+
applicationIdentifier
|
|
795
|
+
});
|
|
796
|
+
console.log(chalk.green(`Custom View updated.`));
|
|
797
|
+
console.log(`You can inspect the Custom View data in the Merchant Center at "${chalk.gray(customViewLink)}".`);
|
|
798
|
+
}
|
|
799
|
+
async function run(options) {
|
|
800
|
+
const applicationConfig = await processConfig();
|
|
801
|
+
const localCustomEntityData = applicationConfig.data;
|
|
802
|
+
const _applicationConfig$en = applicationConfig.env,
|
|
803
|
+
mcApiUrl = _applicationConfig$en.mcApiUrl,
|
|
804
|
+
applicationIdentifier = _applicationConfig$en.applicationIdentifier,
|
|
805
|
+
customViewId = _applicationConfig$en.customViewId;
|
|
806
|
+
console.log(`Using Merchant Center environment "${chalk.green(mcApiUrl)}".`);
|
|
807
|
+
console.log();
|
|
808
|
+
const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
|
|
809
|
+
if (!isSessionValid) {
|
|
810
|
+
throw new Error(`You don't have a valid session. Please, run the "mc-scripts login" command to authenticate yourself.`);
|
|
811
|
+
}
|
|
812
|
+
if (isCustomViewData(localCustomEntityData)) {
|
|
813
|
+
createOrUpdateCustomView({
|
|
814
|
+
mcApiUrl,
|
|
815
|
+
localCustomEntityData,
|
|
816
|
+
applicationIdentifier,
|
|
817
|
+
customViewId: customViewId || localCustomEntityData.id,
|
|
818
|
+
options
|
|
819
|
+
});
|
|
820
|
+
} else {
|
|
821
|
+
createOrUpdateCustomApplication({
|
|
822
|
+
mcApiUrl,
|
|
823
|
+
localCustomEntityData,
|
|
824
|
+
applicationIdentifier,
|
|
825
|
+
options
|
|
826
|
+
});
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
|
|
830
|
+
export { run as default };
|