@commercetools-frontend/mc-scripts 21.7.0 → 21.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -42
  3. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +1 -0
  4. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
  5. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
  6. package/{build/config/application-runtime.js → application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js} +2 -2
  7. package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
  8. package/application-runtime/package.json +4 -0
  9. package/bin/cli.js +1 -1
  10. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +1 -0
  11. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +361 -0
  12. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
  13. package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +361 -0
  14. package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +345 -0
  15. package/cli/package.json +4 -0
  16. package/config/create-webpack-config-for-development.js +7 -1
  17. package/config/create-webpack-config-for-production.js +7 -1
  18. package/config/vendors-to-transpile.js +5 -1
  19. package/dist/build-5357ad26.cjs.prod.js +224 -0
  20. package/dist/build-9b6d7eee.cjs.dev.js +224 -0
  21. package/dist/build-c483e87f.esm.js +209 -0
  22. package/dist/build-vite-3b82522e.cjs.dev.js +151 -0
  23. package/dist/build-vite-93abdc95.esm.js +139 -0
  24. package/dist/build-vite-b7cd993a.cjs.prod.js +151 -0
  25. package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +1 -0
  26. package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +30 -0
  27. package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
  28. package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +30 -0
  29. package/dist/commercetools-frontend-mc-scripts.esm.js +22 -0
  30. package/dist/compile-html-4361a0b3.esm.js +77 -0
  31. package/dist/compile-html-d6331c35.cjs.prod.js +87 -0
  32. package/dist/compile-html-d9e731aa.cjs.dev.js +87 -0
  33. package/dist/config-sync-6b31d972.esm.js +840 -0
  34. package/dist/config-sync-a478bc0f.cjs.dev.js +864 -0
  35. package/dist/config-sync-f07734e4.cjs.prod.js +859 -0
  36. package/{build/config/create-postcss-config.js → dist/create-postcss-config-04243dea.esm.js} +27 -25
  37. package/dist/create-postcss-config-760e2dc5.cjs.dev.js +90 -0
  38. package/dist/create-postcss-config-ddc3abee.cjs.prod.js +90 -0
  39. package/dist/create-webpack-config-for-development-76fdab59.cjs.prod.js +419 -0
  40. package/{build/config/create-webpack-config-for-development.js → dist/create-webpack-config-for-development-d93ae4b2.esm.js} +94 -57
  41. package/dist/create-webpack-config-for-development-dfd1c174.cjs.dev.js +419 -0
  42. package/{build/config/create-webpack-config-for-production.js → dist/create-webpack-config-for-production-9290479a.esm.js} +120 -54
  43. package/dist/create-webpack-config-for-production-bc8c1f37.cjs.dev.js +469 -0
  44. package/dist/create-webpack-config-for-production-d652ad1a.cjs.prod.js +469 -0
  45. package/dist/declarations/src/application-runtime.d.ts +1 -0
  46. package/dist/declarations/src/cli.d.ts +4 -0
  47. package/dist/declarations/src/commands/build-vite.d.ts +2 -0
  48. package/dist/declarations/src/commands/build.d.ts +2 -0
  49. package/dist/declarations/src/commands/compile-html.d.ts +3 -0
  50. package/dist/declarations/src/commands/config-sync.d.ts +3 -0
  51. package/dist/declarations/src/commands/login.d.ts +2 -0
  52. package/dist/declarations/src/commands/serve.d.ts +2 -0
  53. package/dist/declarations/src/commands/start-vite.d.ts +2 -0
  54. package/dist/declarations/src/commands/start.d.ts +2 -0
  55. package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
  56. package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
  57. package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
  58. package/dist/declarations/src/config/has-jsx-runtime.d.ts +2 -0
  59. package/dist/declarations/src/config/moment-locales.d.ts +2 -0
  60. package/dist/declarations/src/config/paths.d.ts +12 -0
  61. package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
  62. package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
  63. package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
  64. package/dist/declarations/src/generated/core.d.ts +710 -0
  65. package/dist/declarations/src/generated/settings.d.ts +2485 -0
  66. package/dist/declarations/src/index.d.ts +3 -0
  67. package/dist/declarations/src/postcss.d.ts +1 -0
  68. package/dist/declarations/src/types.d.ts +82 -0
  69. package/dist/declarations/src/utils/auth.d.ts +6 -0
  70. package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
  71. package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
  72. package/dist/declarations/src/utils/graphql-requests.d.ts +80 -0
  73. package/dist/declarations/src/utils/user-agent.d.ts +2 -0
  74. package/dist/declarations/src/version.d.ts +2 -0
  75. package/dist/declarations/src/vite-plugins/vite-plugin-custom-application.d.ts +4 -0
  76. package/dist/declarations/src/vite-plugins/vite-plugin-dynamic-base-assets-globals.d.ts +3 -0
  77. package/dist/declarations/src/vite-plugins/vite-plugin-svgr.d.ts +3 -0
  78. package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
  79. package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
  80. package/dist/declarations/src/webpack.d.ts +2 -0
  81. package/dist/has-jsx-runtime-0b03b72e.cjs.prod.js +17 -0
  82. package/dist/has-jsx-runtime-3d4bb633.cjs.dev.js +17 -0
  83. package/{build/config/has-jsx-runtime.js → dist/has-jsx-runtime-8314226e.esm.js} +1 -3
  84. package/dist/login-7b7ae27e.esm.js +155 -0
  85. package/dist/login-b13f26e7.cjs.dev.js +165 -0
  86. package/dist/login-c11fb977.cjs.prod.js +165 -0
  87. package/dist/package-4b4fcf02.cjs.prod.js +139 -0
  88. package/dist/package-4c3e3fb7.cjs.dev.js +139 -0
  89. package/dist/package-8e6305bd.esm.js +137 -0
  90. package/dist/paths-16823f56.cjs.dev.js +55 -0
  91. package/dist/paths-76b66e74.cjs.prod.js +55 -0
  92. package/dist/paths-ed23d5a1.esm.js +46 -0
  93. package/dist/serve-12de323b.cjs.dev.js +70 -0
  94. package/dist/serve-784f4fcd.cjs.prod.js +70 -0
  95. package/dist/serve-d6b437b1.esm.js +62 -0
  96. package/dist/start-1b7dad90.cjs.prod.js +209 -0
  97. package/dist/start-45ca01f2.cjs.dev.js +209 -0
  98. package/dist/start-600d06a3.esm.js +194 -0
  99. package/dist/start-vite-22de08dc.cjs.dev.js +151 -0
  100. package/dist/start-vite-dc046cba.esm.js +138 -0
  101. package/dist/start-vite-fe13330b.cjs.prod.js +151 -0
  102. package/dist/user-agent-5f8ec93d.cjs.prod.js +106 -0
  103. package/dist/user-agent-ca628320.esm.js +94 -0
  104. package/dist/user-agent-ee57c98a.cjs.dev.js +106 -0
  105. package/dist/vendors-to-transpile-367e0ba8.cjs.prod.js +5 -0
  106. package/dist/vendors-to-transpile-68e03526.esm.js +3 -0
  107. package/dist/vendors-to-transpile-b51af5d3.cjs.dev.js +5 -0
  108. package/dist/vite-plugin-svgr-4205f2b5.cjs.dev.js +110 -0
  109. package/dist/vite-plugin-svgr-eb8524fa.esm.js +85 -0
  110. package/dist/vite-plugin-svgr-f3bbedbe.cjs.prod.js +110 -0
  111. package/package.json +56 -50
  112. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +1 -0
  113. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +14 -0
  114. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
  115. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +14 -0
  116. package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +6 -0
  117. package/postcss/package.json +4 -0
  118. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +1 -0
  119. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +51 -0
  120. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
  121. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +51 -0
  122. package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +42 -0
  123. package/webpack/package.json +4 -0
  124. package/build/bin/cli.js +0 -264
  125. package/build/commands/build-vite.js +0 -91
  126. package/build/commands/build.js +0 -140
  127. package/build/commands/compile-html.js +0 -53
  128. package/build/commands/config-sync.js +0 -176
  129. package/build/commands/login.js +0 -60
  130. package/build/commands/serve.js +0 -37
  131. package/build/commands/start-vite.js +0 -138
  132. package/build/commands/start.js +0 -108
  133. package/build/config/paths.js +0 -38
  134. package/build/config/vendors-to-transpile.js +0 -3
  135. package/build/config/webpack-dev-server.config.js +0 -69
  136. package/build/index.js +0 -16
  137. package/build/utils/auth.js +0 -34
  138. package/build/utils/auth.spec.js +0 -61
  139. package/build/utils/create-custom-application.settings.graphql +0 -8
  140. package/build/utils/credentials-storage.js +0 -72
  141. package/build/utils/credentials-storage.spec.js +0 -69
  142. package/build/utils/fetch-custom-application.settings.graphql +0 -36
  143. package/build/utils/fetch-user-organizations.core.graphql +0 -9
  144. package/build/utils/get-config-diff.js +0 -308
  145. package/build/utils/get-config-diff.spec.js +0 -285
  146. package/build/utils/graphql-requests.js +0 -105
  147. package/build/utils/graphql-requests.spec.js +0 -159
  148. package/build/utils/require-graphql.js +0 -15
  149. package/build/utils/update-custom-application.settings.graphql +0 -13
  150. package/build/utils/user-agent.js +0 -15
  151. package/build/webpack-plugins/final-stats-writer-plugin.js +0 -50
  152. package/build/webpack-plugins/local-html-webpack-plugin.js +0 -38
@@ -1,308 +0,0 @@
1
- "use strict";
2
-
3
- const chalk = require('chalk'); // Since not all terminal supports colors, to make things more consistent for testing purposes,
4
- // during tests the color used is appended before the string instead of coloring it.
5
-
6
-
7
- const isTest = process.env.NODE_ENV === 'test';
8
-
9
- const red = str => {
10
- if (isTest) return `<color-red>${str}</color-red>`;
11
- return chalk.red(str);
12
- };
13
-
14
- const green = str => {
15
- if (isTest) return `<color-green>${str}</color-green>`;
16
- return chalk.green(str);
17
- }; // Two spaces are used for indentation.
18
-
19
-
20
- const indent = indentLevel => ' '.repeat(indentLevel);
21
-
22
- const getStringDiff = ({
23
- previousValue,
24
- nextValue,
25
- label,
26
- indentLevel = 0
27
- }) => {
28
- if (!previousValue && nextValue) {
29
- return `${indent(indentLevel)}${label} added: ${green(nextValue)}`;
30
- }
31
-
32
- if (previousValue && !nextValue) {
33
- return `${indent(indentLevel)}${label} removed: ${red(previousValue)}`;
34
- }
35
-
36
- if (previousValue && nextValue && previousValue !== nextValue) {
37
- return `${indent(indentLevel)}${label} changed: ${red(previousValue)} => ${green(nextValue)}`;
38
- }
39
-
40
- return null;
41
- }; // NOTE: this assumes that the array values are scalar values (not objects).
42
-
43
-
44
- const getArrayDiff = ({
45
- previousValue,
46
- nextValue,
47
- label,
48
- indentLevel = 0
49
- }) => {
50
- const oldArraySet = new Set(previousValue);
51
- const arrayDiff = [];
52
- nextValue === null || nextValue === void 0 ? void 0 : nextValue.forEach(item => {
53
- if (oldArraySet.has(item)) {
54
- oldArraySet.delete(item);
55
- } else {
56
- arrayDiff.push(getStringDiff({
57
- nextValue: item,
58
- label,
59
- indentLevel
60
- }));
61
- }
62
- });
63
- oldArraySet.forEach(item => {
64
- arrayDiff.push(getStringDiff({
65
- previousValue: item,
66
- label,
67
- indentLevel
68
- }));
69
- });
70
- return arrayDiff.join('\n');
71
- };
72
-
73
- const getPermissionsDiff = ({
74
- previousValue,
75
- nextValue
76
- }) => {
77
- const permissionDiff = ['permissions changed'];
78
- const mappedOldPermissions = previousValue.reduce((previousPermission, {
79
- name,
80
- oAuthScopes
81
- }) => ({ ...previousPermission,
82
- [name]: oAuthScopes
83
- }), {});
84
- const indentLevel = 1;
85
- nextValue.forEach(newPermission => {
86
- const currentDiff = [`${indent(indentLevel)}"${newPermission.name}" changed`]; // if the permission name is not in the old config, it means it is a new addition.
87
-
88
- if (!mappedOldPermissions[newPermission.name]) {
89
- permissionDiff.push(`${indent(indentLevel)}"${green(newPermission.name)}" was added`);
90
- } // if permission name is in the old config, now we check if there was a change
91
- else {
92
- currentDiff.push(getArrayDiff({
93
- previousValue: mappedOldPermissions[newPermission.name],
94
- nextValue: newPermission.oAuthScopes,
95
- label: 'oauth scope',
96
- indentLevel: 2
97
- }));
98
- delete mappedOldPermissions[newPermission.name];
99
- }
100
-
101
- currentDiff.filter(Boolean).length > 1 && permissionDiff.push(currentDiff.join('\n'));
102
- }); // if there are old permissions left, it means they were deleted in the new Permissions.
103
-
104
- Object.keys(mappedOldPermissions).forEach(oldPermissionName => {
105
- permissionDiff.push(`${indent(indentLevel)}"${red(oldPermissionName)}" was removed`);
106
- });
107
- if (permissionDiff.length > 1) return permissionDiff.join('\n');
108
- };
109
-
110
- const getLabelAllLocalesDiff = ({
111
- previousValue,
112
- nextValue,
113
- indentLevel = 0
114
- }) => {
115
- const labelAllLocalesDiff = [`${indent(indentLevel - 1)}labelAllLocales changed`];
116
- const mappedOldLabelAllLocales = (previousValue === null || previousValue === void 0 ? void 0 : previousValue.reduce((previousLabelAllLocale, {
117
- locale,
118
- value
119
- }) => ({ ...previousLabelAllLocale,
120
- [locale]: value
121
- }), {})) ?? {};
122
- nextValue === null || nextValue === void 0 ? void 0 : nextValue.forEach(newLabelAllLocale => {
123
- if (newLabelAllLocale.locale in mappedOldLabelAllLocales) {
124
- const oldLocaleValue = mappedOldLabelAllLocales[newLabelAllLocale.locale];
125
-
126
- if (oldLocaleValue !== newLabelAllLocale.value) {
127
- labelAllLocalesDiff.push(`${indent(indentLevel)}locale "${newLabelAllLocale.locale}" changed: ${red(oldLocaleValue)} => ${green(newLabelAllLocale.value)}`);
128
- }
129
-
130
- delete mappedOldLabelAllLocales[newLabelAllLocale.locale];
131
- } else {
132
- labelAllLocalesDiff.push(getStringDiff({
133
- nextValue: newLabelAllLocale.locale,
134
- label: 'locale',
135
- indentLevel
136
- }));
137
- }
138
- });
139
- Object.keys(mappedOldLabelAllLocales).forEach(key => {
140
- labelAllLocalesDiff.push(getStringDiff({
141
- previousValue: key,
142
- label: 'locale',
143
- indentLevel
144
- }));
145
- });
146
- if (labelAllLocalesDiff.length > 1) return labelAllLocalesDiff.join('\n');
147
- };
148
-
149
- const getMainMenuLinkDiff = ({
150
- previousValue,
151
- nextValue
152
- }) => {
153
- const mainMenuLinkDiff = ['mainMenuLink changed'];
154
- mainMenuLinkDiff.push(getStringDiff({
155
- previousValue: previousValue.defaultLabel,
156
- nextValue: nextValue.defaultLabel,
157
- label: 'defaultLabel',
158
- indentLevel: 1
159
- }));
160
- const mainMenuLinkPermissionsDiff = getArrayDiff({
161
- previousValue: previousValue.permissions,
162
- nextValue: nextValue.permissions,
163
- label: 'applied permission',
164
- indentLevel: 2
165
- });
166
-
167
- if (mainMenuLinkPermissionsDiff.length > 0) {
168
- mainMenuLinkDiff.push(`${indent(1)}permissions changed`);
169
- mainMenuLinkDiff.push(mainMenuLinkPermissionsDiff);
170
- }
171
-
172
- mainMenuLinkDiff.push(getLabelAllLocalesDiff({
173
- previousValue: previousValue.labelAllLocales,
174
- nextValue: nextValue.labelAllLocales,
175
- indentLevel: 2
176
- }));
177
- const filteredMainMenuLinkDiff = mainMenuLinkDiff.filter(Boolean);
178
- if (filteredMainMenuLinkDiff.length > 1) return filteredMainMenuLinkDiff.join('\n');
179
- };
180
-
181
- const getSubmenuLinksDiff = ({
182
- previousValue,
183
- nextValue
184
- }) => {
185
- const submenuLinksDiff = ['submenuLink changed'];
186
- const mappedSubmenuLinks = previousValue.reduce((previousSubmenuLink, currentSubmenuLink) => ({ ...previousSubmenuLink,
187
- [currentSubmenuLink.uriPath]: currentSubmenuLink
188
- }), {});
189
- nextValue.forEach(newSubmenuLink => {
190
- const oldSubMenuLink = mappedSubmenuLinks[newSubmenuLink.uriPath];
191
-
192
- if (newSubmenuLink.uriPath in mappedSubmenuLinks) {
193
- const submenuLinkDiff = [`${indent(1)}menu link "${newSubmenuLink.uriPath}" changed`];
194
- Object.keys(mappedSubmenuLinks[newSubmenuLink.uriPath]).forEach(key => {
195
- switch (key) {
196
- case 'defaultLabel':
197
- {
198
- submenuLinkDiff.push(getStringDiff({
199
- previousValue: oldSubMenuLink.defaultLabel,
200
- nextValue: newSubmenuLink.defaultLabel,
201
- label: 'defaultLabel',
202
- indentLevel: 2
203
- }));
204
- break;
205
- }
206
-
207
- case 'permissions':
208
- {
209
- const submenuLinkPermissionsDiff = getArrayDiff({
210
- previousValue: oldSubMenuLink.permissions,
211
- nextValue: newSubmenuLink.permissions,
212
- label: 'applied permission',
213
- indentLevel: 3
214
- });
215
-
216
- if (submenuLinkPermissionsDiff.length > 0) {
217
- submenuLinkDiff.push(`${indent(2)}permissions changed`);
218
- submenuLinkDiff.push(submenuLinkPermissionsDiff);
219
- }
220
-
221
- break;
222
- }
223
-
224
- case 'labelAllLocales':
225
- {
226
- submenuLinkDiff.push(getLabelAllLocalesDiff({
227
- previousValue: oldSubMenuLink.labelAllLocales,
228
- nextValue: newSubmenuLink.labelAllLocales,
229
- indentLevel: 3
230
- }));
231
- break;
232
- }
233
-
234
- default:
235
- break;
236
- }
237
- });
238
- delete mappedSubmenuLinks[newSubmenuLink.uriPath];
239
- const filteredSubmenuLinksDiff = submenuLinkDiff.filter(Boolean);
240
-
241
- if (filteredSubmenuLinksDiff.length > 1) {
242
- submenuLinksDiff.push(filteredSubmenuLinksDiff.join('\n'));
243
- }
244
- } else {
245
- submenuLinksDiff.push(getStringDiff({
246
- nextValue: newSubmenuLink.uriPath,
247
- label: 'menu link',
248
- indentLevel: 1
249
- }));
250
- }
251
- });
252
- Object.keys(mappedSubmenuLinks).forEach(key => {
253
- submenuLinksDiff.push(getStringDiff({
254
- previousValue: key,
255
- label: 'menu link',
256
- indentLevel: 1
257
- }));
258
- });
259
- if (submenuLinksDiff.length > 1) return submenuLinksDiff.join('\n');
260
- }; // Compute diff changes of the Custom Application config.
261
- // NOTE: Only known keys are evaluated.
262
-
263
-
264
- const getConfigDiff = (oldConfig, newConfig) => {
265
- const diff = []; // Name
266
-
267
- diff.push(getStringDiff({
268
- previousValue: oldConfig.name,
269
- nextValue: newConfig.name,
270
- label: 'name'
271
- })); // Description
272
-
273
- diff.push(getStringDiff({
274
- previousValue: oldConfig.description,
275
- nextValue: newConfig.description,
276
- label: 'description'
277
- })); // URL
278
-
279
- diff.push(getStringDiff({
280
- previousValue: oldConfig.url,
281
- nextValue: newConfig.url,
282
- label: 'url'
283
- })); // Icon
284
-
285
- diff.push(getStringDiff({
286
- previousValue: oldConfig.icon,
287
- nextValue: newConfig.icon,
288
- label: 'icon'
289
- })); // Permissions
290
-
291
- diff.push(getPermissionsDiff({
292
- previousValue: oldConfig.permissions,
293
- nextValue: newConfig.permissions
294
- })); // Main menu link
295
-
296
- diff.push(getMainMenuLinkDiff({
297
- previousValue: oldConfig.mainMenuLink,
298
- nextValue: newConfig.mainMenuLink
299
- })); // Submenu links
300
-
301
- diff.push(getSubmenuLinksDiff({
302
- previousValue: oldConfig.submenuLinks,
303
- nextValue: newConfig.submenuLinks
304
- }));
305
- return diff.filter(Boolean).join('\n');
306
- };
307
-
308
- module.exports = getConfigDiff;
@@ -1,285 +0,0 @@
1
- "use strict";
2
-
3
- const getConfigDiff = require('./get-config-diff');
4
-
5
- const createTestConfig = customConfig => ({
6
- entryPointUriPath: 'my-test-app',
7
- name: 'test name',
8
- description: 'test description',
9
- url: 'https://test.com',
10
- icon: '<svg><path fill="#000000"></path></svg>',
11
- permissions: [],
12
- mainMenuLink: {},
13
- submenuLinks: [],
14
- ...customConfig
15
- });
16
-
17
- describe('when there are no changes', () => {
18
- it('should display no diff', () => {
19
- expect(getConfigDiff(createTestConfig(), createTestConfig())).toBe('');
20
- });
21
- });
22
- describe('when there are changes', () => {
23
- it('should display diff if "name", "description", "icon", "url" changed', () => {
24
- const newConfig = createTestConfig({
25
- name: 'updated test name',
26
- description: 'updated description',
27
- url: 'https://updated-test.com',
28
- icon: '<svg><path fill="#ffffff"></path></svg>'
29
- });
30
- expect(getConfigDiff(createTestConfig(), newConfig)).toMatchInlineSnapshot(`
31
- "name changed: <color-red>test name</color-red> => <color-green>updated test name</color-green>
32
- description changed: <color-red>test description</color-red> => <color-green>updated description</color-green>
33
- url changed: <color-red>https://test.com</color-red> => <color-green>https://updated-test.com</color-green>
34
- icon changed: <color-red><svg><path fill=\\"#000000\\"></path></svg></color-red> => <color-green><svg><path fill=\\"#ffffff\\"></path></svg></color-green>"
35
- `);
36
- });
37
- it('should display diff if "description" is removed', () => {
38
- const newConfig = createTestConfig({
39
- description: undefined
40
- });
41
- expect(getConfigDiff(createTestConfig(), newConfig)).toMatchInlineSnapshot(`"description removed: <color-red>test description</color-red>"`);
42
- });
43
- it('should display diff for "permissions"', () => {
44
- const oldConfig = createTestConfig({
45
- permissions: [{
46
- oAuthScopes: ['manage_product'],
47
- name: 'manageMyTestApp'
48
- }, {
49
- oAuthScopes: ['view_products', 'view_customers'],
50
- name: 'viewMyTestApp'
51
- }]
52
- });
53
- const newConfig = createTestConfig({
54
- permissions: [{
55
- oAuthScopes: ['manage_customer'],
56
- name: 'manageMyTestApp'
57
- }, {
58
- oAuthScopes: ['view_products', 'view_customers', 'view_orders'],
59
- name: 'viewMyTestApp'
60
- }]
61
- });
62
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
63
- "permissions changed
64
- \\"manageMyTestApp\\" changed
65
- oauth scope added: <color-green>manage_customer</color-green>
66
- oauth scope removed: <color-red>manage_product</color-red>
67
- \\"viewMyTestApp\\" changed
68
- oauth scope added: <color-green>view_orders</color-green>"
69
- `);
70
- });
71
- describe('for "mainMenuLink"', () => {
72
- it('should display diff for "mainMenuLink" when assigning new permissions', () => {
73
- const oldConfig = createTestConfig({
74
- mainMenuLink: {
75
- defaultLabel: 'Avengers',
76
- permissions: [],
77
- labelAllLocales: []
78
- }
79
- });
80
- const newConfig = createTestConfig({
81
- mainMenuLink: {
82
- defaultLabel: 'Avengers',
83
- permissions: ['ViewMyTestApp'],
84
- labelAllLocales: []
85
- }
86
- });
87
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
88
- "mainMenuLink changed
89
- permissions changed
90
- applied permission added: <color-green>ViewMyTestApp</color-green>"
91
- `);
92
- });
93
- it('should display diff for "mainMenuLink" when removing permissions', () => {
94
- const oldConfig = createTestConfig({
95
- mainMenuLink: {
96
- defaultLabel: 'Avengers',
97
- permissions: ['ViewMyTestApp'],
98
- labelAllLocales: []
99
- }
100
- });
101
- const newConfig = createTestConfig({
102
- mainMenuLink: {
103
- defaultLabel: 'Avengers',
104
- permissions: [],
105
- labelAllLocales: []
106
- }
107
- });
108
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
109
- "mainMenuLink changed
110
- permissions changed
111
- applied permission removed: <color-red>ViewMyTestApp</color-red>"
112
- `);
113
- });
114
- it('should display diff for "mainMenuLink" when assigning new labels', () => {
115
- const oldConfig = createTestConfig({
116
- mainMenuLink: {
117
- defaultLabel: 'Avengers',
118
- permissions: [],
119
- labelAllLocales: []
120
- }
121
- });
122
- const newConfig = createTestConfig({
123
- mainMenuLink: {
124
- defaultLabel: 'Avengers',
125
- permissions: [],
126
- labelAllLocales: [{
127
- locale: 'de',
128
- value: 'Die Avengers'
129
- }]
130
- }
131
- });
132
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
133
- "mainMenuLink changed
134
- labelAllLocales changed
135
- locale added: <color-green>de</color-green>"
136
- `);
137
- });
138
- it('should display diff for "mainMenuLink" when removing labels', () => {
139
- const oldConfig = createTestConfig({
140
- mainMenuLink: {
141
- defaultLabel: 'Avengers',
142
- permissions: [],
143
- labelAllLocales: [{
144
- locale: 'de',
145
- value: 'Die Avengers'
146
- }]
147
- }
148
- });
149
- const newConfig = createTestConfig({
150
- mainMenuLink: {
151
- defaultLabel: 'Avengers',
152
- permissions: [],
153
- labelAllLocales: []
154
- }
155
- });
156
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
157
- "mainMenuLink changed
158
- labelAllLocales changed
159
- locale removed: <color-red>de</color-red>"
160
- `);
161
- });
162
- it('should display multiple diff for changes of existing "mainMenuLink"', () => {
163
- const oldConfig = createTestConfig({
164
- mainMenuLink: {
165
- defaultLabel: 'Avengers',
166
- permissions: ['ViewMyTestApp'],
167
- labelAllLocales: [{
168
- locale: 'de',
169
- value: 'Die Avengers'
170
- }, {
171
- locale: 'en',
172
- value: 'The Avengers'
173
- }]
174
- }
175
- });
176
- const newConfig = createTestConfig({
177
- mainMenuLink: {
178
- defaultLabel: 'Justice League',
179
- permissions: ['ManageMyTestApp'],
180
- labelAllLocales: [{
181
- locale: 'de',
182
- value: 'Die Justice League'
183
- }, {
184
- locale: 'it',
185
- value: 'La Justice League'
186
- }]
187
- }
188
- });
189
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
190
- "mainMenuLink changed
191
- defaultLabel changed: <color-red>Avengers</color-red> => <color-green>Justice League</color-green>
192
- permissions changed
193
- applied permission added: <color-green>ManageMyTestApp</color-green>
194
- applied permission removed: <color-red>ViewMyTestApp</color-red>
195
- labelAllLocales changed
196
- locale \\"de\\" changed: <color-red>Die Avengers</color-red> => <color-green>Die Justice League</color-green>
197
- locale added: <color-green>it</color-green>
198
- locale removed: <color-red>en</color-red>"
199
- `);
200
- });
201
- });
202
- describe('for "submenuLinks"', () => {
203
- it('should display diff for "submenuLinks" when adding a new menu link', () => {
204
- const oldConfig = createTestConfig({
205
- submenuLinks: []
206
- });
207
- const newConfig = createTestConfig({
208
- submenuLinks: [{
209
- uriPath: 'my-test-app/new',
210
- defaultLabel: 'New Avenger',
211
- permissions: ['ManageMyTestApp'],
212
- labelAllLocales: [{
213
- locale: 'de',
214
- value: 'Neu Avenger'
215
- }]
216
- }]
217
- });
218
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
219
- "submenuLink changed
220
- menu link added: <color-green>my-test-app/new</color-green>"
221
- `);
222
- });
223
- it('should display diff for "submenuLinks" when removing a menu link', () => {
224
- const oldConfig = createTestConfig({
225
- submenuLinks: [{
226
- uriPath: 'my-test-app/new',
227
- defaultLabel: 'New Avenger',
228
- permissions: ['ManageMyTestApp'],
229
- labelAllLocales: [{
230
- locale: 'de',
231
- value: 'Neu Avenger'
232
- }]
233
- }]
234
- });
235
- const newConfig = createTestConfig({
236
- submenuLinks: []
237
- });
238
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
239
- "submenuLink changed
240
- menu link removed: <color-red>my-test-app/new</color-red>"
241
- `);
242
- });
243
- it('should display multiple diff for changes of existing "submenuLinks"', () => {
244
- const oldConfig = createTestConfig({
245
- submenuLinks: [{
246
- uriPath: 'my-test-app/new',
247
- defaultLabel: 'New Avenger',
248
- permissions: ['ManageMyTestApp'],
249
- labelAllLocales: [{
250
- locale: 'de',
251
- value: 'Neu Avenger'
252
- }, {
253
- locale: 'en',
254
- value: 'Add Avenger'
255
- }]
256
- }]
257
- });
258
- const newConfig = createTestConfig({
259
- submenuLinks: [{
260
- uriPath: 'my-test-app/new',
261
- defaultLabel: 'Add Avenger',
262
- permissions: [],
263
- labelAllLocales: [{
264
- locale: 'de',
265
- value: 'Avenger hinzufügen'
266
- }, {
267
- locale: 'it',
268
- value: 'Nuovo Avenger'
269
- }]
270
- }]
271
- });
272
- expect(getConfigDiff(oldConfig, newConfig)).toMatchInlineSnapshot(`
273
- "submenuLink changed
274
- menu link \\"my-test-app/new\\" changed
275
- defaultLabel changed: <color-red>New Avenger</color-red> => <color-green>Add Avenger</color-green>
276
- permissions changed
277
- applied permission removed: <color-red>ManageMyTestApp</color-red>
278
- labelAllLocales changed
279
- locale \\"de\\" changed: <color-red>Neu Avenger</color-red> => <color-green>Avenger hinzufügen</color-green>
280
- locale added: <color-green>it</color-green>
281
- locale removed: <color-red>en</color-red>"
282
- `);
283
- });
284
- });
285
- });
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- const {
4
- GraphQLClient
5
- } = require('graphql-request');
6
-
7
- const {
8
- GRAPHQL_TARGETS
9
- } = require('@commercetools-frontend/constants');
10
-
11
- const userAgent = require('./user-agent');
12
-
13
- const requireGraphqlHelper = require('./require-graphql');
14
-
15
- const requireGraphql = requireGraphqlHelper(__dirname);
16
- const FetchCustomApplicationFromCli = requireGraphql('./fetch-custom-application.settings.graphql');
17
- const UpdateCustomApplicationFromCli = requireGraphql('./update-custom-application.settings.graphql');
18
- const CreateCustomApplicationFromCli = requireGraphql('./create-custom-application.settings.graphql');
19
- const FetchMyOrganizationsFromCli = requireGraphql('./fetch-user-organizations.core.graphql');
20
-
21
- const graphQLClient = (uri, token, target = GRAPHQL_TARGETS.SETTINGS_SERVICE) => new GraphQLClient(`${uri}/graphql`, {
22
- headers: {
23
- Accept: 'application/json',
24
- 'Content-Type': 'application/json',
25
- 'x-graphql-target': target,
26
- 'x-mc-cli-access-token': token,
27
- 'x-user-agent': userAgent
28
- }
29
- });
30
-
31
- const fetchCustomApplication = async ({
32
- mcApiUrl,
33
- token,
34
- entryPointUriPath
35
- }) => {
36
- const variables = {
37
- entryPointUriPath
38
- };
39
-
40
- try {
41
- const customAppData = await graphQLClient(mcApiUrl, token).request(FetchCustomApplicationFromCli, variables);
42
- return customAppData.organizationExtensionForCustomApplication;
43
- } catch (error) {
44
- throw new Error(error.response.message);
45
- }
46
- };
47
-
48
- const updateCustomApplication = async ({
49
- mcApiUrl,
50
- token,
51
- applicationId,
52
- organizationId,
53
- data
54
- }) => {
55
- const variables = {
56
- organizationId,
57
- applicationId,
58
- data
59
- };
60
-
61
- try {
62
- const updatedCustomAppsData = await graphQLClient(mcApiUrl, token).request(UpdateCustomApplicationFromCli, variables);
63
- return updatedCustomAppsData.updateCustomApplication;
64
- } catch (error) {
65
- throw new Error(error.response.message);
66
- }
67
- };
68
-
69
- const createCustomApplication = async ({
70
- mcApiUrl,
71
- token,
72
- organizationId,
73
- data
74
- }) => {
75
- const variables = {
76
- organizationId,
77
- data
78
- };
79
-
80
- try {
81
- const createdCustomAppData = await graphQLClient(mcApiUrl, token).request(CreateCustomApplicationFromCli, variables);
82
- return createdCustomAppData.createCustomApplication;
83
- } catch (error) {
84
- throw new Error(error.response.message);
85
- }
86
- };
87
-
88
- const fetchUserOrganizations = async ({
89
- mcApiUrl,
90
- token
91
- }) => {
92
- try {
93
- const userOrganizations = await graphQLClient(mcApiUrl, token, GRAPHQL_TARGETS.ADMINISTRATION_SERVICE).request(FetchMyOrganizationsFromCli);
94
- return userOrganizations.myOrganizations;
95
- } catch (error) {
96
- throw new Error(error.response.message);
97
- }
98
- };
99
-
100
- module.exports = {
101
- fetchCustomApplication,
102
- updateCustomApplication,
103
- createCustomApplication,
104
- fetchUserOrganizations
105
- };