@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.
- 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 +361 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +361 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +345 -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-5357ad26.cjs.prod.js +224 -0
- package/dist/build-9b6d7eee.cjs.dev.js +224 -0
- package/dist/build-c483e87f.esm.js +209 -0
- package/dist/build-vite-3b82522e.cjs.dev.js +151 -0
- package/dist/build-vite-93abdc95.esm.js +139 -0
- package/dist/build-vite-b7cd993a.cjs.prod.js +151 -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-4361a0b3.esm.js +77 -0
- package/dist/compile-html-d6331c35.cjs.prod.js +87 -0
- package/dist/compile-html-d9e731aa.cjs.dev.js +87 -0
- package/dist/config-sync-6b31d972.esm.js +840 -0
- package/dist/config-sync-a478bc0f.cjs.dev.js +864 -0
- package/dist/config-sync-f07734e4.cjs.prod.js +859 -0
- package/{build/config/create-postcss-config.js → dist/create-postcss-config-04243dea.esm.js} +27 -25
- package/dist/create-postcss-config-760e2dc5.cjs.dev.js +90 -0
- package/dist/create-postcss-config-ddc3abee.cjs.prod.js +90 -0
- package/dist/create-webpack-config-for-development-76fdab59.cjs.prod.js +419 -0
- package/{build/config/create-webpack-config-for-development.js → dist/create-webpack-config-for-development-d93ae4b2.esm.js} +94 -57
- package/dist/create-webpack-config-for-development-dfd1c174.cjs.dev.js +419 -0
- package/{build/config/create-webpack-config-for-production.js → dist/create-webpack-config-for-production-9290479a.esm.js} +120 -54
- package/dist/create-webpack-config-for-production-bc8c1f37.cjs.dev.js +469 -0
- package/dist/create-webpack-config-for-production-d652ad1a.cjs.prod.js +469 -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/moment-locales.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 +2485 -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/vite-plugins/vite-plugin-custom-application.d.ts +4 -0
- package/dist/declarations/src/vite-plugins/vite-plugin-dynamic-base-assets-globals.d.ts +3 -0
- package/dist/declarations/src/vite-plugins/vite-plugin-svgr.d.ts +3 -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-7b7ae27e.esm.js +155 -0
- package/dist/login-b13f26e7.cjs.dev.js +165 -0
- package/dist/login-c11fb977.cjs.prod.js +165 -0
- package/dist/package-4b4fcf02.cjs.prod.js +139 -0
- package/dist/package-4c3e3fb7.cjs.dev.js +139 -0
- package/dist/package-8e6305bd.esm.js +137 -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-1b7dad90.cjs.prod.js +209 -0
- package/dist/start-45ca01f2.cjs.dev.js +209 -0
- package/dist/start-600d06a3.esm.js +194 -0
- package/dist/start-vite-22de08dc.cjs.dev.js +151 -0
- package/dist/start-vite-dc046cba.esm.js +138 -0
- package/dist/start-vite-fe13330b.cjs.prod.js +151 -0
- package/dist/user-agent-5f8ec93d.cjs.prod.js +106 -0
- package/dist/user-agent-ca628320.esm.js +94 -0
- package/dist/user-agent-ee57c98a.cjs.dev.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/dist/vite-plugin-svgr-4205f2b5.cjs.dev.js +110 -0
- package/dist/vite-plugin-svgr-eb8524fa.esm.js +85 -0
- package/dist/vite-plugin-svgr-f3bbedbe.cjs.prod.js +110 -0
- package/package.json +56 -50
- 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/commands/start.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/* eslint-disable no-console,global-require,import/no-dynamic-require */
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
|
|
6
|
-
const webpack = require('webpack');
|
|
7
|
-
|
|
8
|
-
const WebpackDevServer = require('webpack-dev-server');
|
|
9
|
-
|
|
10
|
-
const chalk = require('react-dev-utils/chalk');
|
|
11
|
-
|
|
12
|
-
const clearConsole = require('react-dev-utils/clearConsole');
|
|
13
|
-
|
|
14
|
-
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
|
15
|
-
|
|
16
|
-
const {
|
|
17
|
-
choosePort,
|
|
18
|
-
createCompiler,
|
|
19
|
-
prepareUrls
|
|
20
|
-
} = require('react-dev-utils/WebpackDevServerUtils');
|
|
21
|
-
|
|
22
|
-
const openBrowser = require('react-dev-utils/openBrowser');
|
|
23
|
-
|
|
24
|
-
const paths = require('../config/paths');
|
|
25
|
-
|
|
26
|
-
const createDevServerConfig = require('../config/webpack-dev-server.config');
|
|
27
|
-
|
|
28
|
-
const createWebpackConfigForDevelopment = require('../config/create-webpack-config-for-development');
|
|
29
|
-
|
|
30
|
-
const useYarn = fs.existsSync(paths.yarnLockFile);
|
|
31
|
-
const isInteractive = process.stdout.isTTY; // Whether or not `react-refresh` is enabled, `react-refresh` is not 100% stable at this time,
|
|
32
|
-
// which is why it's disabled by default.
|
|
33
|
-
|
|
34
|
-
const hasWebpackConfig = fs.existsSync(paths.appWebpackConfig); // Warn and crash if required files are missing
|
|
35
|
-
|
|
36
|
-
if (!checkRequiredFiles([])) {
|
|
37
|
-
process.exit(1);
|
|
38
|
-
} // Tools like Cloud9 rely on this.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const DEFAULT_PORT = parseInt(process.env.HTTP_PORT, 10) || 3001;
|
|
42
|
-
const HOST = process.env.HOST || '0.0.0.0'; // We attempt to use the default port but if it is busy, we offer the user to
|
|
43
|
-
// run on a different port. `detect()` Promise resolves to the next free port.
|
|
44
|
-
|
|
45
|
-
choosePort(HOST, DEFAULT_PORT).then(port => {
|
|
46
|
-
if (port == null) {
|
|
47
|
-
// We have not found a port.
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
|
52
|
-
|
|
53
|
-
const appName = require(paths.appPackageJson).name;
|
|
54
|
-
|
|
55
|
-
const urls = prepareUrls(protocol, HOST, port); // Get webpack config
|
|
56
|
-
|
|
57
|
-
const config = hasWebpackConfig ? require(paths.appWebpackConfig) : createWebpackConfigForDevelopment();
|
|
58
|
-
const devSocket = {
|
|
59
|
-
warnings: warnings => // eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
60
|
-
devServer.sockWrite(devServer.sockets, 'warnings', warnings),
|
|
61
|
-
errors: errors => // eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
62
|
-
devServer.sockWrite(devServer.sockets, 'errors', errors)
|
|
63
|
-
}; // Create a webpack compiler that is configured with custom messages.
|
|
64
|
-
|
|
65
|
-
const compiler = createCompiler({
|
|
66
|
-
appName,
|
|
67
|
-
config,
|
|
68
|
-
devSocket,
|
|
69
|
-
urls,
|
|
70
|
-
useYarn,
|
|
71
|
-
webpack
|
|
72
|
-
}); // Serve webpack assets generated by the compiler over a web sever.
|
|
73
|
-
|
|
74
|
-
const serverConfig = createDevServerConfig({
|
|
75
|
-
port,
|
|
76
|
-
publicPath: config.output.publicPath
|
|
77
|
-
});
|
|
78
|
-
const devServer = new WebpackDevServer(serverConfig, compiler); // Launch WebpackDevServer.
|
|
79
|
-
|
|
80
|
-
devServer.startCallback(() => {
|
|
81
|
-
if (isInteractive) {
|
|
82
|
-
clearConsole();
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
console.log(chalk.cyan('Starting the development server...\n'));
|
|
86
|
-
openBrowser(urls.localUrlForBrowser);
|
|
87
|
-
});
|
|
88
|
-
['SIGINT', 'SIGTERM'].forEach(sig => {
|
|
89
|
-
process.on(sig, () => {
|
|
90
|
-
devServer.close();
|
|
91
|
-
process.exit();
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
if (process.env.CI !== 'true') {
|
|
96
|
-
// Gracefully exit when stdin ends
|
|
97
|
-
process.stdin.on('end', function () {
|
|
98
|
-
devServer.close();
|
|
99
|
-
process.exit();
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
}).catch(err => {
|
|
103
|
-
if (err && err.message) {
|
|
104
|
-
console.error(err.message);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
process.exit(1);
|
|
108
|
-
});
|
package/build/config/paths.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fs = require('fs');
|
|
4
|
-
|
|
5
|
-
const path = require('path');
|
|
6
|
-
|
|
7
|
-
const moduleFileExtensions = ['js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx']; // Make sure any symlinks in the project folder are resolved:
|
|
8
|
-
// https://github.com/facebook/create-react-app/issues/637
|
|
9
|
-
|
|
10
|
-
const appDirectory = fs.realpathSync(process.cwd());
|
|
11
|
-
|
|
12
|
-
const resolveApp = relativePath => path.resolve(appDirectory, relativePath); // Resolve file paths in the order given
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const resolveModule = (resolveFn, filePath) => {
|
|
16
|
-
const extension = moduleFileExtensions.find(extension => fs.existsSync(resolveFn(`${filePath}.${extension}`)));
|
|
17
|
-
|
|
18
|
-
if (extension) {
|
|
19
|
-
return resolveFn(`${filePath}.${extension}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return resolveFn(`${filePath}.js`);
|
|
23
|
-
}; // Resolve the absolute path of the caller location. This is necessary
|
|
24
|
-
// to point to files within that folder.
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const paths = {
|
|
28
|
-
appPackageJson: resolveApp('package.json'),
|
|
29
|
-
appBuild: resolveApp('public'),
|
|
30
|
-
appIndexHtmlTemplate: resolveApp('public/index.html.template'),
|
|
31
|
-
appIndexHtml: resolveApp('public/index.html'),
|
|
32
|
-
appWebpackConfig: resolveModule(resolveApp, `webpack.config.${process.env.NODE_ENV === 'production' ? 'prod' : 'dev'}`),
|
|
33
|
-
yarnLockFile: resolveApp('yarn.lock'),
|
|
34
|
-
appRoot: resolveApp('.'),
|
|
35
|
-
entryPoint: resolveModule(resolveApp, 'src/index'),
|
|
36
|
-
sourceFolders: [resolveApp('src')]
|
|
37
|
-
};
|
|
38
|
-
module.exports = paths;
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
processConfig
|
|
5
|
-
} = require('@commercetools-frontend/application-config');
|
|
6
|
-
|
|
7
|
-
const {
|
|
8
|
-
processHeaders
|
|
9
|
-
} = require('@commercetools-frontend/mc-html-template');
|
|
10
|
-
|
|
11
|
-
const {
|
|
12
|
-
createMcDevAuthenticationMiddleware
|
|
13
|
-
} = require('@commercetools-frontend/mc-dev-authentication');
|
|
14
|
-
|
|
15
|
-
const applicationConfig = processConfig();
|
|
16
|
-
const compiledHeaders = processHeaders(applicationConfig);
|
|
17
|
-
const host = process.env.HOST || '0.0.0.0'; // We support configuring the sockjs pathname during development.
|
|
18
|
-
// These settings let a developer run multiple simultaneous projects.
|
|
19
|
-
// They are used as the connection `hostname`, `pathname` and `port`
|
|
20
|
-
// in webpackHotDevClient. They are used as the `sockHost`, `sockPath`
|
|
21
|
-
// and `sockPort` options in webpack-dev-server.
|
|
22
|
-
|
|
23
|
-
const sockHost = process.env.WDS_SOCKET_HOST;
|
|
24
|
-
const sockPath = process.env.WDS_SOCKET_PATH; // default: '/ws'
|
|
25
|
-
|
|
26
|
-
const sockPort = process.env.WDS_SOCKET_PORT;
|
|
27
|
-
|
|
28
|
-
module.exports = ({
|
|
29
|
-
port,
|
|
30
|
-
publicPath
|
|
31
|
-
}) => ({
|
|
32
|
-
client: {
|
|
33
|
-
overlay: false,
|
|
34
|
-
webSocketURL: {
|
|
35
|
-
hostname: sockHost,
|
|
36
|
-
pathname: sockPath,
|
|
37
|
-
port: sockPort
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
// Enable gzip compression of generated files.
|
|
41
|
-
compress: true,
|
|
42
|
-
devMiddleware: {
|
|
43
|
-
// It is important to tell WebpackDevServer to use the same "publicPath" path as
|
|
44
|
-
// we specified in the webpack config. When homepage is '.', default to serving
|
|
45
|
-
// from the root.
|
|
46
|
-
publicPath
|
|
47
|
-
},
|
|
48
|
-
headers: compiledHeaders,
|
|
49
|
-
historyApiFallback: {
|
|
50
|
-
// Paths with dots should still use the history fallback.
|
|
51
|
-
// See https://github.com/facebookincubator/create-react-app/issues/387.
|
|
52
|
-
disableDotRule: true,
|
|
53
|
-
index: publicPath
|
|
54
|
-
},
|
|
55
|
-
host,
|
|
56
|
-
hot: true,
|
|
57
|
-
https: false,
|
|
58
|
-
port,
|
|
59
|
-
|
|
60
|
-
setupMiddlewares(middlewares, devServer) {
|
|
61
|
-
if (!devServer) {
|
|
62
|
-
throw new Error('webpack-dev-server is not defined');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
devServer.app.use(createMcDevAuthenticationMiddleware(applicationConfig));
|
|
66
|
-
return middlewares;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
});
|
package/build/index.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const createWebpackConfigForDevelopment = require('./config/create-webpack-config-for-development');
|
|
4
|
-
|
|
5
|
-
const createWebpackConfigForProduction = require('./config/create-webpack-config-for-production');
|
|
6
|
-
|
|
7
|
-
const vendorsToCompile = require('./config/vendors-to-transpile');
|
|
8
|
-
|
|
9
|
-
const createPostcssConfig = require('./config/create-postcss-config');
|
|
10
|
-
|
|
11
|
-
module.exports = {
|
|
12
|
-
createWebpackConfigForDevelopment,
|
|
13
|
-
createWebpackConfigForProduction,
|
|
14
|
-
vendorsToCompile,
|
|
15
|
-
createPostcssConfig
|
|
16
|
-
};
|
package/build/utils/auth.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
const fetch = require('node-fetch');
|
|
4
|
-
|
|
5
|
-
const userAgent = require('./user-agent');
|
|
6
|
-
|
|
7
|
-
const getAuthToken = async (mcApiUrl, payload) => {
|
|
8
|
-
const response = await fetch(`${mcApiUrl}/tokens/cli`, {
|
|
9
|
-
method: 'POST',
|
|
10
|
-
headers: {
|
|
11
|
-
Accept: 'application/json',
|
|
12
|
-
'Content-Type': 'application/json',
|
|
13
|
-
'x-user-agent': userAgent
|
|
14
|
-
},
|
|
15
|
-
body: JSON.stringify(payload)
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
if (!response.ok) {
|
|
19
|
-
const text = await response.text();
|
|
20
|
-
let parsed;
|
|
21
|
-
|
|
22
|
-
try {
|
|
23
|
-
parsed = JSON.parse(text);
|
|
24
|
-
} catch (error) {}
|
|
25
|
-
|
|
26
|
-
const errorMessage = parsed ? parsed.message : text;
|
|
27
|
-
throw new Error(errorMessage);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const authToken = await response.json();
|
|
31
|
-
return authToken;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
exports.getAuthToken = getAuthToken;
|
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
|
-
}
|