@commercetools-frontend/mc-scripts 21.23.10 → 21.24.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 +120 -326
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +120 -326
- package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +116 -321
- package/dist/build-980cf2c9.cjs.prod.js +170 -0
- package/dist/build-c9601b07.esm.js +156 -0
- package/dist/build-e8a49b56.cjs.dev.js +170 -0
- package/dist/build-vite-b531d3d3.esm.js +118 -0
- package/dist/build-vite-c40a55c3.cjs.dev.js +129 -0
- package/dist/build-vite-d17432ec.cjs.prod.js +129 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +2 -2
- package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +2 -2
- package/dist/commercetools-frontend-mc-scripts.esm.js +2 -2
- package/dist/compile-html-41195e35.cjs.dev.js +49 -0
- package/dist/compile-html-5abd78aa.cjs.prod.js +49 -0
- package/dist/compile-html-f9de842c.esm.js +40 -0
- package/dist/config-sync-0ecc13b3.cjs.dev.js +783 -0
- package/dist/config-sync-4b1ddec3.esm.js +759 -0
- package/dist/config-sync-bb59a82d.cjs.prod.js +778 -0
- package/dist/{create-postcss-config-f65c7e31.cjs.dev.js → create-postcss-config-5cc679d5.cjs.dev.js} +9 -14
- package/dist/{create-postcss-config-06b2e5c2.esm.js → create-postcss-config-a0d4cffa.esm.js} +9 -13
- package/dist/{create-postcss-config-787d905f.cjs.prod.js → create-postcss-config-f94c07fd.cjs.prod.js} +9 -14
- package/dist/{create-webpack-config-for-development-fd365d6a.esm.js → create-webpack-config-for-development-95334073.esm.js} +21 -25
- package/dist/{create-webpack-config-for-development-d46ef148.cjs.dev.js → create-webpack-config-for-development-a53bab71.cjs.dev.js} +24 -28
- package/dist/{create-webpack-config-for-development-59faaed8.cjs.prod.js → create-webpack-config-for-development-c915ec0c.cjs.prod.js} +24 -28
- package/dist/{create-webpack-config-for-production-b28b3d33.esm.js → create-webpack-config-for-production-342485cd.esm.js} +18 -21
- package/dist/{create-webpack-config-for-production-1af3a454.cjs.prod.js → create-webpack-config-for-production-af6f3138.cjs.prod.js} +20 -23
- package/dist/{create-webpack-config-for-production-e12e3c30.cjs.dev.js → create-webpack-config-for-production-db45d9ab.cjs.dev.js} +20 -23
- package/dist/{user-agent-9a470e39.cjs.dev.js → credentials-storage-a37a8915.cjs.dev.js} +24 -24
- package/dist/{user-agent-6e8d0e0b.cjs.prod.js → credentials-storage-b803a804.cjs.prod.js} +24 -24
- package/dist/{user-agent-4b60934e.esm.js → credentials-storage-cb88e8fc.esm.js} +22 -22
- package/dist/declarations/src/deprecated-entry-points.d.ts +1 -1
- package/dist/login-35040a86.cjs.dev.js +93 -0
- package/dist/login-6e17747d.esm.js +84 -0
- package/dist/login-90736d7e.cjs.prod.js +93 -0
- package/dist/{package-a5454c97.esm.js → package-17f18481.esm.js} +17 -16
- package/dist/{package-e2d9b5e0.cjs.dev.js → package-c42dc2ac.cjs.dev.js} +17 -16
- package/dist/{package-808a31f1.cjs.prod.js → package-db15171f.cjs.prod.js} +17 -16
- package/dist/{paths-76b66e74.cjs.prod.js → paths-284c77fb.cjs.prod.js} +6 -8
- package/dist/{paths-ed23d5a1.esm.js → paths-55c5d5a2.esm.js} +6 -8
- package/dist/{paths-16823f56.cjs.dev.js → paths-db35ac0f.cjs.dev.js} +6 -8
- package/dist/serve-41077dad.cjs.prod.js +48 -0
- package/dist/serve-660e2ee0.esm.js +41 -0
- package/dist/serve-b8063204.cjs.dev.js +48 -0
- package/dist/start-0aa71e9a.esm.js +166 -0
- package/dist/start-2e7ec87c.cjs.dev.js +180 -0
- package/dist/start-c0ffe8d7.cjs.prod.js +180 -0
- package/dist/start-vite-324af14d.cjs.prod.js +119 -0
- package/dist/start-vite-7d10ae71.esm.js +107 -0
- package/dist/start-vite-8f03b0df.cjs.dev.js +119 -0
- package/dist/{vendors-to-transpile-367e0ba8.cjs.prod.js → vendors-to-transpile-04a49d40.cjs.prod.js} +1 -1
- package/dist/{vendors-to-transpile-b51af5d3.cjs.dev.js → vendors-to-transpile-6ab4ea06.cjs.dev.js} +1 -1
- package/dist/{vendors-to-transpile-68e03526.esm.js → vendors-to-transpile-7dc84a72.esm.js} +1 -1
- package/dist/vite-plugin-svgr-9a4e7f77.cjs.prod.js +79 -0
- package/dist/vite-plugin-svgr-f17db78a.esm.js +55 -0
- package/dist/vite-plugin-svgr-fdb37ccf.cjs.dev.js +79 -0
- package/package.json +17 -16
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -4
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -4
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -4
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +12 -13
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +12 -13
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +12 -13
- package/dist/build-0e6d74d1.esm.js +0 -209
- package/dist/build-9074fc85.cjs.dev.js +0 -224
- package/dist/build-ae132901.cjs.prod.js +0 -224
- package/dist/build-vite-482a21b8.cjs.dev.js +0 -151
- package/dist/build-vite-cc68e3bf.esm.js +0 -139
- package/dist/build-vite-f095b68d.cjs.prod.js +0 -151
- package/dist/compile-html-4361a0b3.esm.js +0 -77
- package/dist/compile-html-d6331c35.cjs.prod.js +0 -87
- package/dist/compile-html-d9e731aa.cjs.dev.js +0 -87
- package/dist/config-sync-2a9945bc.cjs.dev.js +0 -989
- package/dist/config-sync-43a80f60.cjs.prod.js +0 -984
- package/dist/config-sync-c6c4d1cf.esm.js +0 -964
- package/dist/login-7f1cc8d0.cjs.prod.js +0 -167
- package/dist/login-d21a49e8.esm.js +0 -157
- package/dist/login-ed827138.cjs.dev.js +0 -167
- package/dist/serve-12de323b.cjs.dev.js +0 -70
- package/dist/serve-784f4fcd.cjs.prod.js +0 -70
- package/dist/serve-d6b437b1.esm.js +0 -62
- package/dist/start-10a4d95a.esm.js +0 -194
- package/dist/start-d021fa98.cjs.prod.js +0 -209
- package/dist/start-eea524f2.cjs.dev.js +0 -209
- package/dist/start-vite-57ec5175.cjs.dev.js +0 -146
- package/dist/start-vite-94c2db8c.esm.js +0 -133
- package/dist/start-vite-fc0b15d3.cjs.prod.js +0 -146
- package/dist/vite-plugin-svgr-4205f2b5.cjs.dev.js +0 -110
- package/dist/vite-plugin-svgr-eb8524fa.esm.js +0 -85
- package/dist/vite-plugin-svgr-f3bbedbe.cjs.prod.js +0 -110
|
@@ -0,0 +1,759 @@
|
|
|
1
|
+
import _slicedToArray from '@babel/runtime-corejs3/helpers/esm/slicedToArray';
|
|
2
|
+
import _concatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/concat';
|
|
3
|
+
import _mapInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/map';
|
|
4
|
+
import _findInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/find';
|
|
5
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
6
|
+
import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
7
|
+
import chalk from 'chalk';
|
|
8
|
+
import omit from 'lodash/omit';
|
|
9
|
+
import prompts from 'prompts';
|
|
10
|
+
import { sanitizeSvg, processConfig } from '@commercetools-frontend/application-config';
|
|
11
|
+
import { C as CredentialsStorage, u as userAgent } from './credentials-storage-cb88e8fc.esm.js';
|
|
12
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
13
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
14
|
+
import _Object$getOwnPropertyDescriptors from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors';
|
|
15
|
+
import _Object$defineProperties from '@babel/runtime-corejs3/core-js-stable/object/define-properties';
|
|
16
|
+
import _Object$defineProperty from '@babel/runtime-corejs3/core-js-stable/object/define-property';
|
|
17
|
+
import _defineProperty from '@babel/runtime-corejs3/helpers/esm/defineProperty';
|
|
18
|
+
import _repeatInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/repeat';
|
|
19
|
+
import _Set from '@babel/runtime-corejs3/core-js-stable/set';
|
|
20
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
21
|
+
import _reduceInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/reduce';
|
|
22
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
23
|
+
import _someInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/some';
|
|
24
|
+
import { print } from 'graphql';
|
|
25
|
+
import { GraphQLClient, ClientError } from 'graphql-request';
|
|
26
|
+
import { GRAPHQL_TARGETS } from '@commercetools-frontend/constants';
|
|
27
|
+
import '@commercetools/http-user-agent';
|
|
28
|
+
import './package-17f18481.esm.js';
|
|
29
|
+
import '@babel/runtime-corejs3/helpers/classCallCheck';
|
|
30
|
+
import '@babel/runtime-corejs3/helpers/createClass';
|
|
31
|
+
import '@babel/runtime-corejs3/core-js-stable/date/now';
|
|
32
|
+
import 'fs';
|
|
33
|
+
import 'os';
|
|
34
|
+
import 'path';
|
|
35
|
+
|
|
36
|
+
function ownKeys$1(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
37
|
+
|
|
38
|
+
function _objectSpread$1(target) { for (var i = 1; i < arguments.length; i++) { var _context20, _context21; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context20 = ownKeys$1(Object(source), !0)).call(_context20, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context21 = ownKeys$1(Object(source))).call(_context21, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
39
|
+
// during tests the color used is appended before the string instead of coloring it.
|
|
40
|
+
|
|
41
|
+
const isTest = process.env.NODE_ENV === 'test';
|
|
42
|
+
|
|
43
|
+
const red = str => {
|
|
44
|
+
if (isTest) return "<color-red>".concat(str, "</color-red>");
|
|
45
|
+
return chalk.red(str);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const green = str => {
|
|
49
|
+
if (isTest) return "<color-green>".concat(str, "</color-green>");
|
|
50
|
+
return chalk.green(str);
|
|
51
|
+
}; // Two spaces are used for indentation.
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
const indent = indentLevel => {
|
|
55
|
+
var _context;
|
|
56
|
+
|
|
57
|
+
return _repeatInstanceProperty(_context = ' ').call(_context, indentLevel);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const getStringDiff = _ref => {
|
|
61
|
+
let previousValue = _ref.previousValue,
|
|
62
|
+
nextValue = _ref.nextValue,
|
|
63
|
+
label = _ref.label,
|
|
64
|
+
_ref$indentLevel = _ref.indentLevel,
|
|
65
|
+
indentLevel = _ref$indentLevel === void 0 ? 0 : _ref$indentLevel;
|
|
66
|
+
|
|
67
|
+
if (!previousValue && nextValue) {
|
|
68
|
+
var _context2, _context3;
|
|
69
|
+
|
|
70
|
+
return _concatInstanceProperty(_context2 = _concatInstanceProperty(_context3 = "".concat(indent(indentLevel))).call(_context3, label, " added: ")).call(_context2, green(nextValue));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (previousValue && !nextValue) {
|
|
74
|
+
var _context4, _context5;
|
|
75
|
+
|
|
76
|
+
return _concatInstanceProperty(_context4 = _concatInstanceProperty(_context5 = "".concat(indent(indentLevel))).call(_context5, label, " removed: ")).call(_context4, red(previousValue));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (previousValue && nextValue && previousValue !== nextValue) {
|
|
80
|
+
var _context6, _context7, _context8;
|
|
81
|
+
|
|
82
|
+
return _concatInstanceProperty(_context6 = _concatInstanceProperty(_context7 = _concatInstanceProperty(_context8 = "".concat(indent(indentLevel))).call(_context8, label, " changed: ")).call(_context7, red(previousValue), " => ")).call(_context6, green(nextValue));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return null;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
// NOTE: this assumes that the array values are scalar values (not objects).
|
|
89
|
+
const getArrayDiff = _ref2 => {
|
|
90
|
+
let previousValue = _ref2.previousValue,
|
|
91
|
+
nextValue = _ref2.nextValue,
|
|
92
|
+
label = _ref2.label,
|
|
93
|
+
_ref2$indentLevel = _ref2.indentLevel,
|
|
94
|
+
indentLevel = _ref2$indentLevel === void 0 ? 0 : _ref2$indentLevel;
|
|
95
|
+
const oldArraySet = new _Set(previousValue);
|
|
96
|
+
const arrayDiff = [];
|
|
97
|
+
nextValue === null || nextValue === void 0 ? void 0 : _forEachInstanceProperty(nextValue).call(nextValue, item => {
|
|
98
|
+
if (oldArraySet.has(item)) {
|
|
99
|
+
oldArraySet.delete(item);
|
|
100
|
+
} else {
|
|
101
|
+
arrayDiff.push(getStringDiff({
|
|
102
|
+
nextValue: item,
|
|
103
|
+
label,
|
|
104
|
+
indentLevel
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
_forEachInstanceProperty(oldArraySet).call(oldArraySet, item => {
|
|
110
|
+
arrayDiff.push(getStringDiff({
|
|
111
|
+
previousValue: item,
|
|
112
|
+
label,
|
|
113
|
+
indentLevel
|
|
114
|
+
}));
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return arrayDiff.join('\n');
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const getPermissionsDiff = _ref3 => {
|
|
121
|
+
var _context11;
|
|
122
|
+
|
|
123
|
+
let previousValue = _ref3.previousValue,
|
|
124
|
+
nextValue = _ref3.nextValue;
|
|
125
|
+
const permissionDiff = ['permissions changed'];
|
|
126
|
+
|
|
127
|
+
const mappedOldPermissions = _reduceInstanceProperty(previousValue).call(previousValue, (previousPermission, _ref4) => {
|
|
128
|
+
let name = _ref4.name,
|
|
129
|
+
oAuthScopes = _ref4.oAuthScopes;
|
|
130
|
+
return _objectSpread$1(_objectSpread$1({}, previousPermission), {}, {
|
|
131
|
+
[name]: oAuthScopes
|
|
132
|
+
});
|
|
133
|
+
}, {});
|
|
134
|
+
|
|
135
|
+
const indentLevel = 1;
|
|
136
|
+
|
|
137
|
+
_forEachInstanceProperty(nextValue).call(nextValue, newPermission => {
|
|
138
|
+
var _context9;
|
|
139
|
+
|
|
140
|
+
const currentDiff = [_concatInstanceProperty(_context9 = "".concat(indent(indentLevel), "\"")).call(_context9, newPermission.name, "\" changed")]; // if the permission name is not in the old config, it means it is a new addition.
|
|
141
|
+
|
|
142
|
+
if (!mappedOldPermissions[newPermission.name]) {
|
|
143
|
+
var _context10;
|
|
144
|
+
|
|
145
|
+
permissionDiff.push(_concatInstanceProperty(_context10 = "".concat(indent(indentLevel), "\"")).call(_context10, green(newPermission.name), "\" was added"));
|
|
146
|
+
} // if permission name is in the old config, now we check if there was a change
|
|
147
|
+
else {
|
|
148
|
+
currentDiff.push(getArrayDiff({
|
|
149
|
+
previousValue: mappedOldPermissions[newPermission.name],
|
|
150
|
+
nextValue: newPermission.oAuthScopes,
|
|
151
|
+
label: 'oauth scope',
|
|
152
|
+
indentLevel: 2
|
|
153
|
+
}));
|
|
154
|
+
delete mappedOldPermissions[newPermission.name];
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
_filterInstanceProperty(currentDiff).call(currentDiff, Boolean).length > 1 && permissionDiff.push(currentDiff.join('\n'));
|
|
158
|
+
}); // if there are old permissions left, it means they were deleted in the new Permissions.
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
_forEachInstanceProperty(_context11 = _Object$keys(mappedOldPermissions)).call(_context11, oldPermissionName => {
|
|
162
|
+
var _context12;
|
|
163
|
+
|
|
164
|
+
permissionDiff.push(_concatInstanceProperty(_context12 = "".concat(indent(indentLevel), "\"")).call(_context12, red(oldPermissionName), "\" was removed"));
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
if (permissionDiff.length > 1) return permissionDiff.join('\n');
|
|
168
|
+
return null;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const getLabelAllLocalesDiff = _ref5 => {
|
|
172
|
+
var _context16;
|
|
173
|
+
|
|
174
|
+
let _ref5$previousValue = _ref5.previousValue,
|
|
175
|
+
previousValue = _ref5$previousValue === void 0 ? [] : _ref5$previousValue,
|
|
176
|
+
_ref5$nextValue = _ref5.nextValue,
|
|
177
|
+
nextValue = _ref5$nextValue === void 0 ? [] : _ref5$nextValue,
|
|
178
|
+
_ref5$indentLevel = _ref5.indentLevel,
|
|
179
|
+
indentLevel = _ref5$indentLevel === void 0 ? 0 : _ref5$indentLevel;
|
|
180
|
+
const labelAllLocalesDiff = ["".concat(indent(indentLevel - 1), "labelAllLocales changed")];
|
|
181
|
+
|
|
182
|
+
const mappedOldLabelAllLocales = _reduceInstanceProperty(previousValue).call(previousValue, (previousLabelAllLocale, _ref6) => {
|
|
183
|
+
let locale = _ref6.locale,
|
|
184
|
+
value = _ref6.value;
|
|
185
|
+
return _objectSpread$1(_objectSpread$1({}, previousLabelAllLocale), {}, {
|
|
186
|
+
[locale]: value
|
|
187
|
+
});
|
|
188
|
+
}, {});
|
|
189
|
+
|
|
190
|
+
_forEachInstanceProperty(nextValue).call(nextValue, newLabelAllLocale => {
|
|
191
|
+
if (newLabelAllLocale.locale in mappedOldLabelAllLocales) {
|
|
192
|
+
const oldLocaleValue = mappedOldLabelAllLocales[newLabelAllLocale.locale];
|
|
193
|
+
|
|
194
|
+
if (oldLocaleValue !== newLabelAllLocale.value) {
|
|
195
|
+
var _context13, _context14, _context15;
|
|
196
|
+
|
|
197
|
+
labelAllLocalesDiff.push(_concatInstanceProperty(_context13 = _concatInstanceProperty(_context14 = _concatInstanceProperty(_context15 = "".concat(indent(indentLevel), "locale \"")).call(_context15, newLabelAllLocale.locale, "\" changed: ")).call(_context14, red(oldLocaleValue), " => ")).call(_context13, green(newLabelAllLocale.value)));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
delete mappedOldLabelAllLocales[newLabelAllLocale.locale];
|
|
201
|
+
} else {
|
|
202
|
+
const localeDiff = getStringDiff({
|
|
203
|
+
nextValue: newLabelAllLocale.locale,
|
|
204
|
+
label: 'locale',
|
|
205
|
+
indentLevel
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
if (localeDiff) {
|
|
209
|
+
labelAllLocalesDiff.push(localeDiff);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
_forEachInstanceProperty(_context16 = _Object$keys(mappedOldLabelAllLocales)).call(_context16, key => {
|
|
215
|
+
const localeDiff = getStringDiff({
|
|
216
|
+
previousValue: key,
|
|
217
|
+
label: 'locale',
|
|
218
|
+
indentLevel
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
if (localeDiff) {
|
|
222
|
+
labelAllLocalesDiff.push(localeDiff);
|
|
223
|
+
}
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
if (labelAllLocalesDiff.length > 1) return labelAllLocalesDiff.join('\n');
|
|
227
|
+
return null;
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const getMainMenuLinkDiff = _ref7 => {
|
|
231
|
+
let previousValue = _ref7.previousValue,
|
|
232
|
+
nextValue = _ref7.nextValue;
|
|
233
|
+
const mainMenuLinkDiff = ['mainMenuLink changed'];
|
|
234
|
+
const menuDiff = getStringDiff({
|
|
235
|
+
previousValue: previousValue.defaultLabel,
|
|
236
|
+
nextValue: nextValue.defaultLabel,
|
|
237
|
+
label: 'defaultLabel',
|
|
238
|
+
indentLevel: 1
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
if (menuDiff) {
|
|
242
|
+
mainMenuLinkDiff.push(menuDiff);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
const mainMenuLinkPermissionsDiff = getArrayDiff({
|
|
246
|
+
previousValue: previousValue.permissions,
|
|
247
|
+
nextValue: nextValue.permissions,
|
|
248
|
+
label: 'applied permission',
|
|
249
|
+
indentLevel: 2
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
if (mainMenuLinkPermissionsDiff.length > 0) {
|
|
253
|
+
mainMenuLinkDiff.push("".concat(indent(1), "permissions changed"));
|
|
254
|
+
mainMenuLinkDiff.push(mainMenuLinkPermissionsDiff);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
const menuLabelsDiff = getLabelAllLocalesDiff({
|
|
258
|
+
previousValue: previousValue.labelAllLocales,
|
|
259
|
+
nextValue: nextValue.labelAllLocales,
|
|
260
|
+
indentLevel: 2
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
if (menuLabelsDiff) {
|
|
264
|
+
mainMenuLinkDiff.push(menuLabelsDiff);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const filteredMainMenuLinkDiff = _filterInstanceProperty(mainMenuLinkDiff).call(mainMenuLinkDiff, Boolean);
|
|
268
|
+
|
|
269
|
+
if (filteredMainMenuLinkDiff.length > 1) return filteredMainMenuLinkDiff.join('\n');
|
|
270
|
+
return null;
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
const getSubmenuLinksDiff = _ref8 => {
|
|
274
|
+
var _context19;
|
|
275
|
+
|
|
276
|
+
let previousValue = _ref8.previousValue,
|
|
277
|
+
nextValue = _ref8.nextValue;
|
|
278
|
+
const submenuLinksDiff = ['submenuLink changed'];
|
|
279
|
+
|
|
280
|
+
const mappedSubmenuLinks = _reduceInstanceProperty(previousValue).call(previousValue, (previousSubmenuLink, currentSubmenuLink) => _objectSpread$1(_objectSpread$1({}, previousSubmenuLink), {}, {
|
|
281
|
+
[currentSubmenuLink.uriPath]: currentSubmenuLink
|
|
282
|
+
}), {});
|
|
283
|
+
|
|
284
|
+
_forEachInstanceProperty(nextValue).call(nextValue, newSubmenuLink => {
|
|
285
|
+
const oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
|
|
286
|
+
|
|
287
|
+
if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
|
|
288
|
+
var _context17, _context18;
|
|
289
|
+
|
|
290
|
+
const submenuLinkDiff = [_concatInstanceProperty(_context17 = "".concat(indent(1), "menu link \"")).call(_context17, newSubmenuLink.uriPath, "\" changed")];
|
|
291
|
+
|
|
292
|
+
_forEachInstanceProperty(_context18 = _Object$keys(mappedSubmenuLinks[newSubmenuLink.uriPath])).call(_context18, key => {
|
|
293
|
+
switch (key) {
|
|
294
|
+
case 'defaultLabel':
|
|
295
|
+
{
|
|
296
|
+
const labelDiff = getStringDiff({
|
|
297
|
+
previousValue: oldSubMenuLink.defaultLabel,
|
|
298
|
+
nextValue: newSubmenuLink.defaultLabel,
|
|
299
|
+
label: 'defaultLabel',
|
|
300
|
+
indentLevel: 2
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
if (labelDiff) {
|
|
304
|
+
submenuLinkDiff.push(labelDiff);
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
break;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
case 'permissions':
|
|
311
|
+
{
|
|
312
|
+
const submenuLinkPermissionsDiff = getArrayDiff({
|
|
313
|
+
previousValue: oldSubMenuLink.permissions,
|
|
314
|
+
nextValue: newSubmenuLink.permissions,
|
|
315
|
+
label: 'applied permission',
|
|
316
|
+
indentLevel: 3
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
if (submenuLinkPermissionsDiff.length > 0) {
|
|
320
|
+
submenuLinkDiff.push("".concat(indent(2), "permissions changed"));
|
|
321
|
+
submenuLinkDiff.push(submenuLinkPermissionsDiff);
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
case 'labelAllLocales':
|
|
328
|
+
{
|
|
329
|
+
const labelsDiff = getLabelAllLocalesDiff({
|
|
330
|
+
previousValue: oldSubMenuLink.labelAllLocales,
|
|
331
|
+
nextValue: newSubmenuLink.labelAllLocales,
|
|
332
|
+
indentLevel: 3
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
if (labelsDiff) {
|
|
336
|
+
submenuLinkDiff.push(labelsDiff);
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
break;
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
delete mappedSubmenuLinks[newSubmenuLink.uriPath];
|
|
345
|
+
|
|
346
|
+
const filteredSubmenuLinksDiff = _filterInstanceProperty(submenuLinkDiff).call(submenuLinkDiff, Boolean);
|
|
347
|
+
|
|
348
|
+
if (filteredSubmenuLinksDiff.length > 1) {
|
|
349
|
+
submenuLinksDiff.push(filteredSubmenuLinksDiff.join('\n'));
|
|
350
|
+
}
|
|
351
|
+
} else {
|
|
352
|
+
const linksDiff = getStringDiff({
|
|
353
|
+
nextValue: newSubmenuLink.uriPath,
|
|
354
|
+
label: 'menu link',
|
|
355
|
+
indentLevel: 1
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
if (linksDiff) {
|
|
359
|
+
submenuLinksDiff.push(linksDiff);
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
_forEachInstanceProperty(_context19 = _Object$keys(mappedSubmenuLinks)).call(_context19, key => {
|
|
365
|
+
const linksDiff = getStringDiff({
|
|
366
|
+
previousValue: key,
|
|
367
|
+
label: 'menu link',
|
|
368
|
+
indentLevel: 1
|
|
369
|
+
});
|
|
370
|
+
if (linksDiff) submenuLinksDiff.push(linksDiff);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
if (submenuLinksDiff.length > 1) return submenuLinksDiff.join('\n');
|
|
374
|
+
return null;
|
|
375
|
+
}; // Compute diff changes of the Custom Application config.
|
|
376
|
+
// NOTE: Only known keys are evaluated.
|
|
377
|
+
|
|
378
|
+
|
|
379
|
+
const getConfigDiff = (oldConfig, newConfig) => {
|
|
380
|
+
const diff = []; // Name
|
|
381
|
+
|
|
382
|
+
const nameDiff = getStringDiff({
|
|
383
|
+
previousValue: oldConfig.name,
|
|
384
|
+
nextValue: newConfig.name,
|
|
385
|
+
label: 'name'
|
|
386
|
+
});
|
|
387
|
+
|
|
388
|
+
if (nameDiff) {
|
|
389
|
+
diff.push(nameDiff);
|
|
390
|
+
} // Description
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
const descriptionDiff = getStringDiff({
|
|
394
|
+
previousValue: oldConfig.description,
|
|
395
|
+
nextValue: newConfig.description,
|
|
396
|
+
label: 'description'
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
if (descriptionDiff) {
|
|
400
|
+
diff.push(descriptionDiff);
|
|
401
|
+
} // URL
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
const urlDiff = getStringDiff({
|
|
405
|
+
previousValue: oldConfig.url,
|
|
406
|
+
nextValue: newConfig.url,
|
|
407
|
+
label: 'url'
|
|
408
|
+
});
|
|
409
|
+
|
|
410
|
+
if (urlDiff) {
|
|
411
|
+
diff.push(urlDiff);
|
|
412
|
+
} // Icon
|
|
413
|
+
|
|
414
|
+
|
|
415
|
+
const iconDiff = getStringDiff({
|
|
416
|
+
// This icon stored in the database has already been sanitized.
|
|
417
|
+
previousValue: oldConfig.icon,
|
|
418
|
+
// Sanitize the raw icon as-if it was stored in the database,
|
|
419
|
+
// to ensure the data can be safely compared.
|
|
420
|
+
nextValue: sanitizeSvg(newConfig.icon),
|
|
421
|
+
label: 'icon'
|
|
422
|
+
});
|
|
423
|
+
|
|
424
|
+
if (iconDiff) {
|
|
425
|
+
diff.push(iconDiff);
|
|
426
|
+
} // Permissions
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
const permissionsDiff = getPermissionsDiff({
|
|
430
|
+
previousValue: oldConfig.permissions,
|
|
431
|
+
nextValue: newConfig.permissions
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
if (permissionsDiff) {
|
|
435
|
+
diff.push(permissionsDiff);
|
|
436
|
+
} // Main menu link
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
const mainMenuDiff = getMainMenuLinkDiff({
|
|
440
|
+
previousValue: oldConfig.mainMenuLink,
|
|
441
|
+
nextValue: newConfig.mainMenuLink
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
if (mainMenuDiff) {
|
|
445
|
+
diff.push(mainMenuDiff);
|
|
446
|
+
} // Submenu links
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
const submenuDiff = getSubmenuLinksDiff({
|
|
450
|
+
previousValue: oldConfig.submenuLinks,
|
|
451
|
+
nextValue: newConfig.submenuLinks
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
if (submenuDiff) {
|
|
455
|
+
diff.push(submenuDiff);
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
return diff.join('\n');
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
462
|
+
|
|
463
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
464
|
+
var CreateCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "CreateCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "organizationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDraftDataInput" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "createCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "data" }, value: { kind: "Variable", name: { kind: "Name", value: "data" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 201, source: { body: "mutation CreateCustomApplicationFromCli(\n $organizationId: String!\n $data: CustomApplicationDraftDataInput!\n) {\n createCustomApplication(organizationId: $organizationId, data: $data) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
465
|
+
var FetchCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "entryPointUriPath" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationExtensionForCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "entryPointUriPath" }, value: { kind: "Variable", name: { kind: "Name", value: "entryPointUriPath" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "organizationId" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "application" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "entryPointUriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "description" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "url" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "icon" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "oAuthScopes" }, arguments: [], directives: [] }] } }, { kind: "Field", name: { kind: "Name", value: "mainMenuLink" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "defaultLabel" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }] } }, { kind: "Field", name: { kind: "Name", value: "submenuLinks" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "uriPath" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "defaultLabel" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "permissions" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "labelAllLocales" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "locale" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "value" }, arguments: [], directives: [] }] } }] } }] } }] } }] } }], loc: { start: 0, end: 647, source: { body: "query FetchCustomApplicationFromCli($entryPointUriPath: String!) {\n organizationExtensionForCustomApplication(\n entryPointUriPath: $entryPointUriPath\n ) {\n organizationId\n application {\n id\n entryPointUriPath\n name\n description\n url\n icon\n permissions {\n name\n oAuthScopes\n }\n mainMenuLink {\n defaultLabel\n permissions\n labelAllLocales {\n locale\n value\n }\n }\n submenuLinks {\n uriPath\n defaultLabel\n permissions\n labelAllLocales {\n locale\n value\n }\n }\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
466
|
+
var FetchMyOrganizationsFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "query", name: { kind: "Name", value: "FetchMyOrganizationsFromCli" }, variableDefinitions: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "myOrganizations" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "total" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "results" }, arguments: [], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }, { kind: "Field", name: { kind: "Name", value: "name" }, arguments: [], directives: [] }] } }] } }] } }], loc: { start: 0, end: 112, source: { body: "query FetchMyOrganizationsFromCli {\n myOrganizations {\n total\n results {\n id\n name\n }\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
467
|
+
var UpdateCustomApplicationFromCli = { kind: "Document", definitions: [{ kind: "OperationDefinition", operation: "mutation", name: { kind: "Name", value: "UpdateCustomApplicationFromCli" }, variableDefinitions: [{ kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "organizationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "String" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "data" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "CustomApplicationDraftDataInput" } } }, directives: [] }, { kind: "VariableDefinition", variable: { kind: "Variable", name: { kind: "Name", value: "applicationId" } }, type: { kind: "NonNullType", type: { kind: "NamedType", name: { kind: "Name", value: "ID" } } }, directives: [] }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "updateCustomApplication" }, arguments: [{ kind: "Argument", name: { kind: "Name", value: "organizationId" }, value: { kind: "Variable", name: { kind: "Name", value: "organizationId" } } }, { kind: "Argument", name: { kind: "Name", value: "data" }, value: { kind: "Variable", name: { kind: "Name", value: "data" } } }, { kind: "Argument", name: { kind: "Name", value: "applicationId" }, value: { kind: "Variable", name: { kind: "Name", value: "applicationId" } } }], directives: [], selectionSet: { kind: "SelectionSet", selections: [{ kind: "Field", name: { kind: "Name", value: "id" }, arguments: [], directives: [] }] } }] } }], loc: { start: 0, end: 268, source: { body: "mutation UpdateCustomApplicationFromCli(\n $organizationId: String!\n $data: CustomApplicationDraftDataInput!\n $applicationId: ID!\n) {\n updateCustomApplication(\n organizationId: $organizationId\n data: $data\n applicationId: $applicationId\n ) {\n id\n }\n}\n", name: "GraphQL request", locationOffset: { line: 1, column: 1 } } } };
|
|
468
|
+
const credentialsStorage$1 = new CredentialsStorage();
|
|
469
|
+
const client = new GraphQLClient('', // <-- Set on demand
|
|
470
|
+
{
|
|
471
|
+
headers: {
|
|
472
|
+
Accept: 'application/json',
|
|
473
|
+
'Content-Type': 'application/json',
|
|
474
|
+
'x-user-agent': userAgent
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
async function requestWithTokenRetry(document, requestOptions) {
|
|
479
|
+
let retryCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
480
|
+
const token = credentialsStorage$1.getToken(requestOptions.mcApiUrl);
|
|
481
|
+
client.setEndpoint("".concat(requestOptions.mcApiUrl, "/graphql"));
|
|
482
|
+
client.setHeaders(requestOptions.headers);
|
|
483
|
+
|
|
484
|
+
if (token) {
|
|
485
|
+
client.setHeader('x-mc-cli-access-token', token);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
try {
|
|
489
|
+
const result = await client.rawRequest(print(document), requestOptions.variables); // In case a new session token is returned from the server, save it.
|
|
490
|
+
|
|
491
|
+
const refreshedSessionToken = result.headers.get('x-refreshed-session-token');
|
|
492
|
+
|
|
493
|
+
if (refreshedSessionToken) {
|
|
494
|
+
console.log(chalk.green('Session token refreshed.'));
|
|
495
|
+
console.log();
|
|
496
|
+
const refreshedSessionTokenExpiresAt = result.headers.get('x-refreshed-session-token-expires-at'); // Store the updated access token.
|
|
497
|
+
|
|
498
|
+
credentialsStorage$1.setToken(requestOptions.mcApiUrl, {
|
|
499
|
+
token: refreshedSessionToken,
|
|
500
|
+
expiresAt: Number(refreshedSessionTokenExpiresAt)
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
return result.data;
|
|
505
|
+
} catch (error) {
|
|
506
|
+
if (error instanceof ClientError) {
|
|
507
|
+
// If it's an unauthorized error, retry the request to force the token to be refreshed.
|
|
508
|
+
if (retryCount === 0 && error.response.errors && error.response.errors.length > 0) {
|
|
509
|
+
var _context;
|
|
510
|
+
|
|
511
|
+
const isUnauthorizedError = _someInstanceProperty(_context = error.response.errors).call(_context, graphqlError => {
|
|
512
|
+
var _graphqlError$extensi;
|
|
513
|
+
|
|
514
|
+
return ((_graphqlError$extensi = graphqlError.extensions) === null || _graphqlError$extensi === void 0 ? void 0 : _graphqlError$extensi.code) === 'UNAUTHENTICATED';
|
|
515
|
+
});
|
|
516
|
+
|
|
517
|
+
if (isUnauthorizedError) {
|
|
518
|
+
console.log(chalk.yellow('Expired or invalid session token, attempting to retry the request with a refreshed token...'));
|
|
519
|
+
return requestWithTokenRetry(document, _objectSpread(_objectSpread({}, requestOptions), {}, {
|
|
520
|
+
headers: _objectSpread(_objectSpread({}, requestOptions.headers), {}, {
|
|
521
|
+
'X-Force-Token': 'true'
|
|
522
|
+
})
|
|
523
|
+
}), retryCount + 1);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
throw error;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
const fetchCustomApplication = async _ref => {
|
|
533
|
+
let mcApiUrl = _ref.mcApiUrl,
|
|
534
|
+
entryPointUriPath = _ref.entryPointUriPath;
|
|
535
|
+
const customAppData = await requestWithTokenRetry(FetchCustomApplicationFromCli, {
|
|
536
|
+
variables: {
|
|
537
|
+
entryPointUriPath
|
|
538
|
+
},
|
|
539
|
+
mcApiUrl,
|
|
540
|
+
headers: {
|
|
541
|
+
'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
return customAppData.organizationExtensionForCustomApplication;
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
const updateCustomApplication = async _ref2 => {
|
|
548
|
+
let mcApiUrl = _ref2.mcApiUrl,
|
|
549
|
+
applicationId = _ref2.applicationId,
|
|
550
|
+
organizationId = _ref2.organizationId,
|
|
551
|
+
data = _ref2.data;
|
|
552
|
+
const updatedCustomAppsData = await requestWithTokenRetry(UpdateCustomApplicationFromCli, {
|
|
553
|
+
variables: {
|
|
554
|
+
organizationId,
|
|
555
|
+
applicationId,
|
|
556
|
+
data
|
|
557
|
+
},
|
|
558
|
+
mcApiUrl,
|
|
559
|
+
headers: {
|
|
560
|
+
'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
|
|
561
|
+
}
|
|
562
|
+
});
|
|
563
|
+
return updatedCustomAppsData.updateCustomApplication;
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
const createCustomApplication = async _ref3 => {
|
|
567
|
+
let mcApiUrl = _ref3.mcApiUrl,
|
|
568
|
+
organizationId = _ref3.organizationId,
|
|
569
|
+
data = _ref3.data;
|
|
570
|
+
const createdCustomAppData = await requestWithTokenRetry(CreateCustomApplicationFromCli, {
|
|
571
|
+
variables: {
|
|
572
|
+
organizationId,
|
|
573
|
+
data
|
|
574
|
+
},
|
|
575
|
+
mcApiUrl,
|
|
576
|
+
headers: {
|
|
577
|
+
'x-graphql-target': GRAPHQL_TARGETS.SETTINGS_SERVICE
|
|
578
|
+
}
|
|
579
|
+
});
|
|
580
|
+
return createdCustomAppData.createCustomApplication;
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
const fetchUserOrganizations = async _ref4 => {
|
|
584
|
+
let mcApiUrl = _ref4.mcApiUrl;
|
|
585
|
+
const userOrganizations = await requestWithTokenRetry(FetchMyOrganizationsFromCli, {
|
|
586
|
+
mcApiUrl,
|
|
587
|
+
headers: {
|
|
588
|
+
'x-graphql-target': GRAPHQL_TARGETS.ADMINISTRATION_SERVICE
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
return userOrganizations.myOrganizations;
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
const credentialsStorage = new CredentialsStorage();
|
|
595
|
+
|
|
596
|
+
const getMcUrlLink = (mcApiUrl, organizationId, applicationId) => {
|
|
597
|
+
var _context, _context2;
|
|
598
|
+
|
|
599
|
+
const mcUrl = mcApiUrl.replace('mc-api', 'mc');
|
|
600
|
+
|
|
601
|
+
const customAppLink = _concatInstanceProperty(_context = _concatInstanceProperty(_context2 = "".concat(mcUrl, "/account/organizations/")).call(_context2, organizationId, "/custom-applications/owned/")).call(_context, applicationId);
|
|
602
|
+
|
|
603
|
+
return customAppLink;
|
|
604
|
+
};
|
|
605
|
+
|
|
606
|
+
async function run(options) {
|
|
607
|
+
var _context5;
|
|
608
|
+
|
|
609
|
+
const applicationConfig = processConfig();
|
|
610
|
+
const localCustomAppData = applicationConfig.data;
|
|
611
|
+
const mcApiUrl = applicationConfig.env.mcApiUrl;
|
|
612
|
+
console.log("Using Merchant Center environment \"".concat(chalk.green(mcApiUrl), "\"."));
|
|
613
|
+
console.log();
|
|
614
|
+
const isSessionValid = credentialsStorage.isSessionValid(mcApiUrl);
|
|
615
|
+
|
|
616
|
+
if (!isSessionValid) {
|
|
617
|
+
throw new Error("You don't have a valid session. Please, run the \"mc-scripts login\" command to authenticate yourself.");
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
const fetchedCustomApplication = await fetchCustomApplication({
|
|
621
|
+
mcApiUrl,
|
|
622
|
+
entryPointUriPath: localCustomAppData.entryPointUriPath
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
if (!fetchedCustomApplication) {
|
|
626
|
+
var _context4;
|
|
627
|
+
|
|
628
|
+
const userOrganizations = await fetchUserOrganizations({
|
|
629
|
+
mcApiUrl
|
|
630
|
+
});
|
|
631
|
+
let organizationId, organizationName;
|
|
632
|
+
|
|
633
|
+
if (userOrganizations.total === 0) {
|
|
634
|
+
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.");
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (userOrganizations.total === 1) {
|
|
638
|
+
const _userOrganizations$re = _slicedToArray(userOrganizations.results, 1),
|
|
639
|
+
organization = _userOrganizations$re[0];
|
|
640
|
+
|
|
641
|
+
organizationId = organization.id;
|
|
642
|
+
organizationName = organization.name;
|
|
643
|
+
} else {
|
|
644
|
+
var _context3;
|
|
645
|
+
|
|
646
|
+
const organizationChoices = _mapInstanceProperty(_context3 = userOrganizations.results).call(_context3, organization => ({
|
|
647
|
+
title: organization.name,
|
|
648
|
+
value: organization.id
|
|
649
|
+
}));
|
|
650
|
+
|
|
651
|
+
const _await$prompts = await prompts({
|
|
652
|
+
type: 'select',
|
|
653
|
+
name: 'organizationId',
|
|
654
|
+
message: 'Select an Organization',
|
|
655
|
+
choices: organizationChoices,
|
|
656
|
+
initial: 0
|
|
657
|
+
}),
|
|
658
|
+
selectedOrganizationId = _await$prompts.organizationId;
|
|
659
|
+
|
|
660
|
+
if (!selectedOrganizationId) {
|
|
661
|
+
throw new Error("No Organization selected, aborting.");
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
organizationId = selectedOrganizationId;
|
|
665
|
+
organizationName = _findInstanceProperty(organizationChoices).call(organizationChoices, _ref => {
|
|
666
|
+
let value = _ref.value;
|
|
667
|
+
return value === organizationId;
|
|
668
|
+
}).title;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
const _await$prompts2 = await prompts({
|
|
672
|
+
type: 'text',
|
|
673
|
+
name: 'confirmation',
|
|
674
|
+
message: _filterInstanceProperty(_context4 = ["You are about to create a new Custom Application in the \"".concat(chalk.green(organizationName), "\" organization. Are you sure you want to proceed?"), options.dryRun && chalk.gray('Using "--dry-run", no data will be created.')]).call(_context4, Boolean).join('\n'),
|
|
675
|
+
initial: 'yes'
|
|
676
|
+
}),
|
|
677
|
+
confirmation = _await$prompts2.confirmation;
|
|
678
|
+
|
|
679
|
+
if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
|
|
680
|
+
console.log(chalk.red('Aborted.'));
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
const data = omit(localCustomAppData, ['id']);
|
|
685
|
+
|
|
686
|
+
if (options.dryRun) {
|
|
687
|
+
console.log();
|
|
688
|
+
console.log("The following payload would be used to create a new Custom Application.");
|
|
689
|
+
console.log();
|
|
690
|
+
console.log(chalk.gray(_JSON$stringify(data, null, 2)));
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
const createdCustomApplication = await createCustomApplication({
|
|
695
|
+
mcApiUrl,
|
|
696
|
+
organizationId,
|
|
697
|
+
data
|
|
698
|
+
}); // This check is technically not necessary, as the `graphql-request` client
|
|
699
|
+
// throws an error in case of GraphQL errors.
|
|
700
|
+
// However, the generated TypeScript data related to the GraphQL query has the
|
|
701
|
+
// field typed as optional, thus having an extra check for type correctness.
|
|
702
|
+
|
|
703
|
+
if (!createdCustomApplication) {
|
|
704
|
+
throw new Error('Failed to create the Custom Application.');
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
const customAppLink = getMcUrlLink(mcApiUrl, organizationId, createdCustomApplication.id);
|
|
708
|
+
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: \"".concat(chalk.green(createdCustomApplication.id), "\".")));
|
|
709
|
+
console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk.gray(customAppLink), "\"."));
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
const customAppLink = getMcUrlLink(mcApiUrl, fetchedCustomApplication.organizationId, fetchedCustomApplication.application.id);
|
|
714
|
+
const configDiff = getConfigDiff(fetchedCustomApplication.application, localCustomAppData);
|
|
715
|
+
|
|
716
|
+
if (!configDiff) {
|
|
717
|
+
console.log(chalk.green("Custom Application up-to-date."));
|
|
718
|
+
console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk.gray(customAppLink), "\"."));
|
|
719
|
+
return;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
console.log('Changes detected:');
|
|
723
|
+
console.log(configDiff);
|
|
724
|
+
console.log();
|
|
725
|
+
|
|
726
|
+
const _await$prompts3 = await prompts({
|
|
727
|
+
type: 'text',
|
|
728
|
+
name: 'confirmation',
|
|
729
|
+
message: _filterInstanceProperty(_context5 = ["You are about to update the Custom Application \"".concat(chalk.green(localCustomAppData.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(_context5, Boolean).join('\n'),
|
|
730
|
+
initial: 'yes'
|
|
731
|
+
}),
|
|
732
|
+
confirmation = _await$prompts3.confirmation;
|
|
733
|
+
|
|
734
|
+
if (!confirmation || confirmation.toLowerCase().charAt(0) !== 'y') {
|
|
735
|
+
console.log(chalk.red('Aborted.'));
|
|
736
|
+
return;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
const data = omit(localCustomAppData, ['id']);
|
|
740
|
+
|
|
741
|
+
if (options.dryRun) {
|
|
742
|
+
console.log();
|
|
743
|
+
console.log("The following payload would be used to update the Custom Application \"".concat(chalk.green(data.entryPointUriPath), "\"."));
|
|
744
|
+
console.log();
|
|
745
|
+
console.log(chalk.gray(_JSON$stringify(data, null, 2)));
|
|
746
|
+
return;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
await updateCustomApplication({
|
|
750
|
+
mcApiUrl,
|
|
751
|
+
organizationId: fetchedCustomApplication.organizationId,
|
|
752
|
+
data: omit(localCustomAppData, ['id']),
|
|
753
|
+
applicationId: fetchedCustomApplication.application.id
|
|
754
|
+
});
|
|
755
|
+
console.log(chalk.green("Custom Application updated."));
|
|
756
|
+
console.log("You can inspect the Custom Application data in the Merchant Center at \"".concat(chalk.gray(customAppLink), "\"."));
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
export { run as default };
|