@commercetools-frontend/mc-scripts 21.7.0 → 21.8.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/LICENSE +1 -1
- package/README.md +1 -42
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +1 -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/{build/config/application-runtime.js → application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js} +2 -2
- 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 +1 -1
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +1 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +354 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +354 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +338 -0
- package/cli/package.json +4 -0
- package/config/create-webpack-config-for-development.js +7 -1
- package/config/create-webpack-config-for-production.js +7 -1
- package/config/vendors-to-transpile.js +5 -1
- package/dist/build-8582b673.esm.js +209 -0
- package/dist/build-9395925a.cjs.prod.js +224 -0
- package/dist/build-97278377.cjs.dev.js +224 -0
- package/dist/build-vite-6c987a60.cjs.dev.js +109 -0
- package/dist/build-vite-76d44332.cjs.prod.js +109 -0
- package/dist/build-vite-a9602b19.esm.js +97 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +1 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +30 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +30 -0
- package/dist/commercetools-frontend-mc-scripts.esm.js +22 -0
- package/dist/compile-html-0c588a89.cjs.dev.js +93 -0
- package/dist/compile-html-4832f8c5.esm.js +83 -0
- package/dist/compile-html-7654b5e6.cjs.prod.js +93 -0
- package/dist/config-sync-20bc05e8.esm.js +868 -0
- package/dist/config-sync-62824317.cjs.prod.js +887 -0
- package/dist/config-sync-d52e73f6.cjs.dev.js +892 -0
- package/dist/create-postcss-config-4cbe10ab.cjs.dev.js +90 -0
- package/dist/create-postcss-config-8ea16440.cjs.prod.js +90 -0
- package/{build/config/create-postcss-config.js → dist/create-postcss-config-c1aa3525.esm.js} +27 -25
- package/{build/config/create-webpack-config-for-development.js → dist/create-webpack-config-for-development-8a8b84d6.esm.js} +92 -56
- package/dist/create-webpack-config-for-development-a5e73092.cjs.prod.js +418 -0
- package/dist/create-webpack-config-for-development-e2735e02.cjs.dev.js +418 -0
- package/dist/create-webpack-config-for-production-4e7b56c0.cjs.prod.js +468 -0
- package/{build/config/create-webpack-config-for-production.js → dist/create-webpack-config-for-production-7dc669e5.esm.js} +117 -52
- package/dist/create-webpack-config-for-production-d9bf281c.cjs.dev.js +468 -0
- package/dist/declarations/src/application-runtime.d.ts +1 -0
- package/dist/declarations/src/cli.d.ts +4 -0
- package/dist/declarations/src/commands/build-vite.d.ts +2 -0
- package/dist/declarations/src/commands/build.d.ts +2 -0
- package/dist/declarations/src/commands/compile-html.d.ts +3 -0
- package/dist/declarations/src/commands/config-sync.d.ts +3 -0
- package/dist/declarations/src/commands/login.d.ts +2 -0
- package/dist/declarations/src/commands/serve.d.ts +2 -0
- package/dist/declarations/src/commands/start-vite.d.ts +2 -0
- package/dist/declarations/src/commands/start.d.ts +2 -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/has-jsx-runtime.d.ts +2 -0
- package/dist/declarations/src/config/paths.d.ts +12 -0
- package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
- package/dist/declarations/src/config/webpack-dev-server.config.d.ts +6 -0
- package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
- package/dist/declarations/src/generated/core.d.ts +710 -0
- package/dist/declarations/src/generated/settings.d.ts +2383 -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 +82 -0
- package/dist/declarations/src/utils/auth.d.ts +6 -0
- package/dist/declarations/src/utils/credentials-storage.d.ts +11 -0
- package/dist/declarations/src/utils/get-config-diff.d.ts +3 -0
- package/dist/declarations/src/utils/graphql-requests.d.ts +80 -0
- package/dist/declarations/src/utils/user-agent.d.ts +2 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/dist/declarations/src/webpack-plugins/final-stats-writer-plugin.d.ts +12 -0
- package/dist/declarations/src/webpack-plugins/local-html-webpack-plugin.d.ts +5 -0
- package/dist/declarations/src/webpack.d.ts +2 -0
- package/dist/has-jsx-runtime-0b03b72e.cjs.prod.js +17 -0
- package/dist/has-jsx-runtime-3d4bb633.cjs.dev.js +17 -0
- package/{build/config/has-jsx-runtime.js → dist/has-jsx-runtime-8314226e.esm.js} +1 -3
- package/dist/login-706ccc9a.cjs.prod.js +165 -0
- package/dist/login-779552b7.cjs.dev.js +165 -0
- package/dist/login-7d94659e.esm.js +155 -0
- package/dist/package-a98de907.esm.js +133 -0
- package/dist/package-aaf61bf0.cjs.dev.js +135 -0
- package/dist/package-b5c040f3.cjs.prod.js +135 -0
- package/dist/paths-16823f56.cjs.dev.js +55 -0
- package/dist/paths-76b66e74.cjs.prod.js +55 -0
- package/dist/paths-ed23d5a1.esm.js +46 -0
- package/dist/serve-12de323b.cjs.dev.js +70 -0
- package/dist/serve-784f4fcd.cjs.prod.js +70 -0
- package/dist/serve-d6b437b1.esm.js +62 -0
- package/dist/start-2b953ab0.cjs.dev.js +209 -0
- package/dist/start-e3ccd672.cjs.prod.js +209 -0
- package/dist/start-e924bd5d.esm.js +194 -0
- package/dist/start-vite-737bacca.cjs.dev.js +149 -0
- package/dist/start-vite-b0f58ae4.cjs.prod.js +149 -0
- package/dist/start-vite-ec5d40b5.esm.js +136 -0
- package/dist/user-agent-5da1830b.cjs.dev.js +106 -0
- package/dist/user-agent-8044acd6.esm.js +94 -0
- package/dist/user-agent-d18809af.cjs.prod.js +106 -0
- package/dist/vendors-to-transpile-367e0ba8.cjs.prod.js +5 -0
- package/dist/vendors-to-transpile-68e03526.esm.js +3 -0
- package/dist/vendors-to-transpile-b51af5d3.cjs.dev.js +5 -0
- package/package.json +41 -39
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +1 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +14 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +14 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +6 -0
- package/postcss/package.json +4 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +1 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +51 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +51 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +42 -0
- package/webpack/package.json +4 -0
- package/build/bin/cli.js +0 -264
- package/build/commands/build-vite.js +0 -91
- package/build/commands/build.js +0 -140
- package/build/commands/compile-html.js +0 -53
- package/build/commands/config-sync.js +0 -176
- package/build/commands/login.js +0 -60
- package/build/commands/serve.js +0 -37
- package/build/commands/start-vite.js +0 -138
- package/build/commands/start.js +0 -108
- package/build/config/paths.js +0 -38
- package/build/config/vendors-to-transpile.js +0 -3
- package/build/config/webpack-dev-server.config.js +0 -69
- package/build/index.js +0 -16
- package/build/utils/auth.js +0 -34
- package/build/utils/auth.spec.js +0 -61
- package/build/utils/create-custom-application.settings.graphql +0 -8
- package/build/utils/credentials-storage.js +0 -72
- package/build/utils/credentials-storage.spec.js +0 -69
- package/build/utils/fetch-custom-application.settings.graphql +0 -36
- package/build/utils/fetch-user-organizations.core.graphql +0 -9
- package/build/utils/get-config-diff.js +0 -308
- package/build/utils/get-config-diff.spec.js +0 -285
- package/build/utils/graphql-requests.js +0 -105
- package/build/utils/graphql-requests.spec.js +0 -159
- package/build/utils/require-graphql.js +0 -15
- package/build/utils/update-custom-application.settings.graphql +0 -13
- package/build/utils/user-agent.js +0 -15
- package/build/webpack-plugins/final-stats-writer-plugin.js +0 -50
- package/build/webpack-plugins/local-html-webpack-plugin.js +0 -38
package/build/utils/auth.spec.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
rest
|
|
5
|
-
} = require('msw');
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
setupServer
|
|
9
|
-
} = require('msw/node');
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
getAuthToken
|
|
13
|
-
} = require('./auth');
|
|
14
|
-
|
|
15
|
-
const mockServer = setupServer();
|
|
16
|
-
afterEach(() => {
|
|
17
|
-
mockServer.resetHandlers();
|
|
18
|
-
});
|
|
19
|
-
beforeAll(() => mockServer.listen({
|
|
20
|
-
onUnhandledRequest: 'error'
|
|
21
|
-
}));
|
|
22
|
-
afterAll(() => mockServer.close());
|
|
23
|
-
const mcApiUrl = 'https://mc-api.europe-west1.gcp.commercetools.com';
|
|
24
|
-
describe('when login details are correct', () => {
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
mockServer.use(rest.post(`${mcApiUrl}/tokens/cli`, (req, res, ctx) => {
|
|
27
|
-
return res(ctx.status(200), ctx.json({
|
|
28
|
-
token: 'hello-world',
|
|
29
|
-
expiresAt: Math.floor(Date.now() / 1000) + 60 * 60 * 36 // 1,5 days
|
|
30
|
-
|
|
31
|
-
}));
|
|
32
|
-
}));
|
|
33
|
-
});
|
|
34
|
-
it('should match returned credentials', async () => {
|
|
35
|
-
const sessionData = await getAuthToken(mcApiUrl, {
|
|
36
|
-
email: 'user@email.com',
|
|
37
|
-
password: 'secret'
|
|
38
|
-
});
|
|
39
|
-
expect(sessionData).toEqual({
|
|
40
|
-
token: 'hello-world',
|
|
41
|
-
expiresAt: expect.any(Number)
|
|
42
|
-
});
|
|
43
|
-
expect(sessionData.expiresAt).toBeGreaterThan(Math.floor(Date.now() / 1000));
|
|
44
|
-
expect(sessionData.expiresAt).toBeLessThanOrEqual(Math.floor(Date.now() / 1000) + 60 * 60 * 36);
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
describe('when login details are incorrect', () => {
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
mockServer.use(rest.post(`${mcApiUrl}/tokens/cli`, (req, res, ctx) => {
|
|
50
|
-
return res(ctx.status(400), ctx.json({
|
|
51
|
-
message: 'Invalid email or password'
|
|
52
|
-
}));
|
|
53
|
-
}));
|
|
54
|
-
});
|
|
55
|
-
it('should throw error', async () => {
|
|
56
|
-
await expect(async () => await getAuthToken(mcApiUrl, {
|
|
57
|
-
email: 'user@email.com',
|
|
58
|
-
password: 'secret'
|
|
59
|
-
})).rejects.toThrow('Invalid email or password');
|
|
60
|
-
});
|
|
61
|
-
});
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
|
|
7
|
-
const homedir = require('os').homedir();
|
|
8
|
-
|
|
9
|
-
const credentialsFolderPath = path.join(homedir, `.commercetools`);
|
|
10
|
-
const credentialsFilePath = path.join(credentialsFolderPath, 'mc-credentials.json');
|
|
11
|
-
|
|
12
|
-
class CredentialsStorage {
|
|
13
|
-
static location = credentialsFilePath;
|
|
14
|
-
|
|
15
|
-
constructor() {
|
|
16
|
-
// Ensure the credentials file is present
|
|
17
|
-
if (!fs.existsSync(credentialsFilePath)) {
|
|
18
|
-
fs.mkdirSync(credentialsFolderPath, {
|
|
19
|
-
recursive: true
|
|
20
|
-
}); // Initialize with an empty object
|
|
21
|
-
|
|
22
|
-
this._writeCredentials({});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
_writeCredentials(credentials) {
|
|
27
|
-
fs.writeFileSync(credentialsFilePath, JSON.stringify(credentials, null, 2), {
|
|
28
|
-
encoding: 'utf8'
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
_loadCredentials() {
|
|
33
|
-
const data = fs.readFileSync(credentialsFilePath, {
|
|
34
|
-
encoding: 'utf8'
|
|
35
|
-
});
|
|
36
|
-
return JSON.parse(data);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getToken(environmentKey) {
|
|
40
|
-
const allCredentials = this._loadCredentials();
|
|
41
|
-
|
|
42
|
-
if (!this.isSessionValid(environmentKey)) {
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return allCredentials[environmentKey].token;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
setToken(environmentKey, credentials) {
|
|
50
|
-
const allCredentials = this._loadCredentials();
|
|
51
|
-
|
|
52
|
-
allCredentials[environmentKey] = credentials;
|
|
53
|
-
|
|
54
|
-
this._writeCredentials(allCredentials);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
isSessionValid(environmentKey) {
|
|
58
|
-
const allCredentials = this._loadCredentials();
|
|
59
|
-
|
|
60
|
-
const credentials = allCredentials[environmentKey];
|
|
61
|
-
|
|
62
|
-
if (!credentials) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const now = Math.floor(Date.now() / 1000);
|
|
67
|
-
return now < credentials.expiresAt;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
module.exports = CredentialsStorage;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const mock = require('mock-fs');
|
|
4
|
-
|
|
5
|
-
const CredentialsStorage = require('./credentials-storage');
|
|
6
|
-
|
|
7
|
-
afterEach(() => {
|
|
8
|
-
mock.restore();
|
|
9
|
-
});
|
|
10
|
-
const mcApiUrl = 'https://mc-api.europe-west1.gcp.commercetools.com';
|
|
11
|
-
describe('when session is valid', () => {
|
|
12
|
-
let credentialsStorage;
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
mock({
|
|
15
|
-
[CredentialsStorage.location]: JSON.stringify({
|
|
16
|
-
[mcApiUrl]: {
|
|
17
|
-
token: 'hello-world',
|
|
18
|
-
expiresAt: Math.floor(Date.now() / 1000) + 60 * 60 * 36
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
});
|
|
22
|
-
credentialsStorage = new CredentialsStorage();
|
|
23
|
-
});
|
|
24
|
-
it('should load credentials and update token', () => {
|
|
25
|
-
expect(credentialsStorage.getToken(mcApiUrl)).toBe('hello-world');
|
|
26
|
-
expect(credentialsStorage.isSessionValid(mcApiUrl)).toBe(true);
|
|
27
|
-
const newSessionData = {
|
|
28
|
-
token: 'fizz-buzz',
|
|
29
|
-
expiresAt: Math.floor(Date.now() / 1000) + 60 * 60 * 36
|
|
30
|
-
};
|
|
31
|
-
credentialsStorage.setToken(mcApiUrl, newSessionData);
|
|
32
|
-
expect(credentialsStorage.getToken(mcApiUrl)).toBe('fizz-buzz');
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
describe('when session is expired', () => {
|
|
36
|
-
let credentialsStorage;
|
|
37
|
-
beforeEach(() => {
|
|
38
|
-
mock({
|
|
39
|
-
[CredentialsStorage.location]: JSON.stringify({
|
|
40
|
-
[mcApiUrl]: {
|
|
41
|
-
token: 'hello-world',
|
|
42
|
-
expiresAt: Math.floor(Date.now() / 1000) - 1
|
|
43
|
-
}
|
|
44
|
-
})
|
|
45
|
-
});
|
|
46
|
-
credentialsStorage = new CredentialsStorage();
|
|
47
|
-
});
|
|
48
|
-
it('should not load credentials', () => {
|
|
49
|
-
expect(credentialsStorage.isSessionValid(mcApiUrl)).toBe(false);
|
|
50
|
-
expect(credentialsStorage.getToken(mcApiUrl)).toBe(null);
|
|
51
|
-
});
|
|
52
|
-
});
|
|
53
|
-
describe('when credentials file is missing', () => {
|
|
54
|
-
let credentialsStorage;
|
|
55
|
-
beforeEach(() => {
|
|
56
|
-
mock({});
|
|
57
|
-
credentialsStorage = new CredentialsStorage();
|
|
58
|
-
});
|
|
59
|
-
it('should not load credentials and update token', () => {
|
|
60
|
-
expect(credentialsStorage.getToken(mcApiUrl)).toBe(null);
|
|
61
|
-
expect(credentialsStorage.isSessionValid(mcApiUrl)).toBe(false);
|
|
62
|
-
const newSessionData = {
|
|
63
|
-
token: 'fizz-buzz',
|
|
64
|
-
expiresAt: Math.floor(Date.now() / 1000) + 60 * 60 * 36
|
|
65
|
-
};
|
|
66
|
-
credentialsStorage.setToken(mcApiUrl, newSessionData);
|
|
67
|
-
expect(credentialsStorage.getToken(mcApiUrl)).toBe('fizz-buzz');
|
|
68
|
-
});
|
|
69
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
query FetchCustomApplicationFromCli($entryPointUriPath: String!) {
|
|
2
|
-
organizationExtensionForCustomApplication(
|
|
3
|
-
entryPointUriPath: $entryPointUriPath
|
|
4
|
-
) {
|
|
5
|
-
organizationId
|
|
6
|
-
application {
|
|
7
|
-
id
|
|
8
|
-
entryPointUriPath
|
|
9
|
-
name
|
|
10
|
-
description
|
|
11
|
-
url
|
|
12
|
-
icon
|
|
13
|
-
permissions {
|
|
14
|
-
name
|
|
15
|
-
oAuthScopes
|
|
16
|
-
}
|
|
17
|
-
mainMenuLink {
|
|
18
|
-
defaultLabel
|
|
19
|
-
permissions
|
|
20
|
-
labelAllLocales {
|
|
21
|
-
locale
|
|
22
|
-
value
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
submenuLinks {
|
|
26
|
-
uriPath
|
|
27
|
-
defaultLabel
|
|
28
|
-
permissions
|
|
29
|
-
labelAllLocales {
|
|
30
|
-
locale
|
|
31
|
-
value
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -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;
|