@commercetools-frontend/mc-scripts 0.0.0-CRAFT-1791-20251006162610
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +7 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.d.ts +2 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +7 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.js +7 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +7 -0
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +5 -0
- package/application-runtime/package.json +4 -0
- package/bin/cli.js +8 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.d.ts +2 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +199 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.js +7 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +199 -0
- package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +184 -0
- package/cli/package.json +4 -0
- package/config/create-webpack-config-for-development.js +8 -0
- package/config/create-webpack-config-for-production.js +8 -0
- package/config/vendors-to-transpile.js +6 -0
- package/dist/build-2a0a18bd.esm.js +155 -0
- package/dist/build-521f3f9f.cjs.prod.js +169 -0
- package/dist/build-988fc0f7.cjs.dev.js +169 -0
- package/dist/build-vite-16b1a575.cjs.dev.js +238 -0
- package/dist/build-vite-59e1f185.esm.js +208 -0
- package/dist/build-vite-5d317720.cjs.prod.js +238 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.d.ts +2 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +29 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.js +7 -0
- package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +29 -0
- package/dist/commercetools-frontend-mc-scripts.esm.js +21 -0
- package/dist/compile-html-025cd493.esm.js +34 -0
- package/dist/compile-html-50fd05ec.cjs.prod.js +42 -0
- package/dist/compile-html-f4ac88cc.cjs.dev.js +42 -0
- package/dist/config-sync-70a16916.cjs.dev.js +852 -0
- package/dist/config-sync-72c20d80.cjs.prod.js +846 -0
- package/dist/config-sync-bc895390.esm.js +830 -0
- package/dist/create-postcss-config-cb7be312.cjs.dev.js +81 -0
- package/dist/create-postcss-config-dde0ccf1.esm.js +75 -0
- package/dist/create-postcss-config-edca0c33.cjs.prod.js +81 -0
- package/dist/create-webpack-config-for-development-1aed1cc0.cjs.prod.js +465 -0
- package/dist/create-webpack-config-for-development-a95f3634.esm.js +440 -0
- package/dist/create-webpack-config-for-development-d003697b.cjs.dev.js +465 -0
- package/dist/create-webpack-config-for-production-15fbe7db.cjs.dev.js +523 -0
- package/dist/create-webpack-config-for-production-764c482f.cjs.prod.js +523 -0
- package/dist/create-webpack-config-for-production-9f42c336.esm.js +493 -0
- package/dist/credentials-storage-66c1e51f.cjs.prod.js +95 -0
- package/dist/credentials-storage-d001f726.esm.js +83 -0
- package/dist/credentials-storage-e7884d17.cjs.dev.js +95 -0
- package/dist/declarations/src/application-runtime.d.ts +1 -0
- package/dist/declarations/src/cli.d.ts +4 -0
- package/dist/declarations/src/config/create-postcss-config.d.ts +4 -0
- package/dist/declarations/src/config/create-webpack-config-for-development.d.ts +10 -0
- package/dist/declarations/src/config/create-webpack-config-for-production.d.ts +10 -0
- package/dist/declarations/src/config/vendors-to-transpile.d.ts +2 -0
- package/dist/declarations/src/deprecated-entry-points.d.ts +7 -0
- package/dist/declarations/src/index.d.ts +3 -0
- package/dist/declarations/src/postcss.d.ts +1 -0
- package/dist/declarations/src/types.d.ts +94 -0
- package/dist/declarations/src/version.d.ts +2 -0
- package/dist/declarations/src/webpack-loaders/i18n-message-compilation-loader.d.ts +3 -0
- package/dist/declarations/src/webpack.d.ts +2 -0
- package/dist/deployment-previews-set-17e8ed48.cjs.prod.js +202 -0
- package/dist/deployment-previews-set-3648972f.esm.js +191 -0
- package/dist/deployment-previews-set-37aef990.cjs.dev.js +202 -0
- package/dist/does-file-exist-32618334.esm.js +12 -0
- package/dist/does-file-exist-be53305d.cjs.prod.js +18 -0
- package/dist/does-file-exist-eb86baca.cjs.dev.js +18 -0
- package/dist/graphql-requests-6a47ad5b.esm.js +247 -0
- package/dist/graphql-requests-779b867b.cjs.dev.js +270 -0
- package/dist/graphql-requests-8086eba7.cjs.prod.js +270 -0
- package/dist/has-jsx-runtime-aa5d21ee.cjs.dev.js +15 -0
- package/dist/has-jsx-runtime-c3202df5.cjs.prod.js +15 -0
- package/dist/has-jsx-runtime-e3ecb09b.esm.js +13 -0
- package/dist/i18n-message-complilation-21d3b0aa.esm.js +15 -0
- package/dist/i18n-message-complilation-7311cb29.cjs.dev.js +23 -0
- package/dist/i18n-message-complilation-7762da61.cjs.prod.js +23 -0
- package/dist/login-0a728449.esm.js +229 -0
- package/dist/login-817a5a26.cjs.dev.js +270 -0
- package/dist/login-85c25393.cjs.prod.js +270 -0
- package/dist/optimizations-7789145e.cjs.dev.js +85 -0
- package/dist/optimizations-bf991634.esm.js +67 -0
- package/dist/optimizations-fb93514f.cjs.prod.js +85 -0
- package/dist/package-7e170dc4.cjs.dev.js +160 -0
- package/dist/package-940b0a2a.cjs.prod.js +160 -0
- package/dist/package-99e547a7.esm.js +158 -0
- package/dist/paths-39f22b8b.esm.js +36 -0
- package/dist/paths-7768b440.cjs.prod.js +44 -0
- package/dist/paths-b76fc753.cjs.dev.js +44 -0
- package/dist/serve-1036c2de.esm.js +55 -0
- package/dist/serve-50d33f0b.cjs.dev.js +64 -0
- package/dist/serve-8a506da6.cjs.prod.js +64 -0
- package/dist/start-1d677ad8.cjs.dev.js +177 -0
- package/dist/start-2a7ae03d.esm.js +164 -0
- package/dist/start-f56cb5f7.cjs.prod.js +177 -0
- package/dist/start-vite-068e9f73.cjs.dev.js +128 -0
- package/dist/start-vite-29078b3a.cjs.prod.js +128 -0
- package/dist/start-vite-7d1161e8.esm.js +116 -0
- package/dist/vendors-to-transpile-04a49d40.cjs.prod.js +5 -0
- package/dist/vendors-to-transpile-6ab4ea06.cjs.dev.js +5 -0
- package/dist/vendors-to-transpile-7dc84a72.esm.js +3 -0
- package/dist/vite-plugin-svgr-4034a834.cjs.prod.js +151 -0
- package/dist/vite-plugin-svgr-7d06f400.cjs.dev.js +151 -0
- package/dist/vite-plugin-svgr-de6ee7da.esm.js +125 -0
- package/package.json +156 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.d.ts +2 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +12 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.js +7 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +12 -0
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +4 -0
- package/postcss/package.json +4 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.d.ts +2 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +57 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.js +7 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +57 -0
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +48 -0
- package/webpack/package.json +4 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.d.ts +3 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +30 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.js +7 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +30 -0
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +26 -0
- package/webpack-loaders/i18n-message-compilation-loader/package.json +4 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function hasJsxRuntime() {
|
|
4
|
+
if (process.env.ENABLE_NEW_JSX_TRANSFORM !== 'true') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
require.resolve('react/jsx-runtime');
|
|
9
|
+
return true;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.hasJsxRuntime = hasJsxRuntime;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function hasJsxRuntime() {
|
|
4
|
+
if (process.env.ENABLE_NEW_JSX_TRANSFORM !== 'true') {
|
|
5
|
+
return false;
|
|
6
|
+
}
|
|
7
|
+
try {
|
|
8
|
+
require.resolve('react/jsx-runtime');
|
|
9
|
+
return true;
|
|
10
|
+
} catch (e) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
exports.hasJsxRuntime = hasJsxRuntime;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import _Object$values from '@babel/runtime-corejs3/core-js-stable/object/values';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
|
|
4
|
+
function getI18nMessageFormat(source) {
|
|
5
|
+
const messageContents = JSON.parse(source);
|
|
6
|
+
const firstValue = _Object$values(messageContents)[0];
|
|
7
|
+
return typeof firstValue === 'string' ? 'simple' : 'transifex';
|
|
8
|
+
}
|
|
9
|
+
function handleMessageCompilationError(fileIdentifier, error, warnFunction) {
|
|
10
|
+
if (!process.env.CI) {
|
|
11
|
+
warnFunction(new Error(`[i18n message compilation] Message compilation on ${fileIdentifier} has failed.\n` + `Consider setting the environmental variable ${chalk.yellow('DISABLE_I18N_MESSAGE_COMPILATION')} to true to disable the message loader or resolve the issues on the messages file.\n` + `${error instanceof Error ? `Error: ${error.message}` : ''}`));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { getI18nMessageFormat as g, handleMessageCompilationError as h };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
4
|
+
var chalk = require('chalk');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
7
|
+
|
|
8
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
9
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
10
|
+
|
|
11
|
+
function getI18nMessageFormat(source) {
|
|
12
|
+
const messageContents = JSON.parse(source);
|
|
13
|
+
const firstValue = _Object$values__default["default"](messageContents)[0];
|
|
14
|
+
return typeof firstValue === 'string' ? 'simple' : 'transifex';
|
|
15
|
+
}
|
|
16
|
+
function handleMessageCompilationError(fileIdentifier, error, warnFunction) {
|
|
17
|
+
if (!process.env.CI) {
|
|
18
|
+
warnFunction(new Error(`[i18n message compilation] Message compilation on ${fileIdentifier} has failed.\n` + `Consider setting the environmental variable ${chalk__default["default"].yellow('DISABLE_I18N_MESSAGE_COMPILATION')} to true to disable the message loader or resolve the issues on the messages file.\n` + `${error instanceof Error ? `Error: ${error.message}` : ''}`));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.getI18nMessageFormat = getI18nMessageFormat;
|
|
23
|
+
exports.handleMessageCompilationError = handleMessageCompilationError;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _Object$values = require('@babel/runtime-corejs3/core-js-stable/object/values');
|
|
4
|
+
var chalk = require('chalk');
|
|
5
|
+
|
|
6
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
7
|
+
|
|
8
|
+
var _Object$values__default = /*#__PURE__*/_interopDefault(_Object$values);
|
|
9
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
10
|
+
|
|
11
|
+
function getI18nMessageFormat(source) {
|
|
12
|
+
const messageContents = JSON.parse(source);
|
|
13
|
+
const firstValue = _Object$values__default["default"](messageContents)[0];
|
|
14
|
+
return typeof firstValue === 'string' ? 'simple' : 'transifex';
|
|
15
|
+
}
|
|
16
|
+
function handleMessageCompilationError(fileIdentifier, error, warnFunction) {
|
|
17
|
+
if (!process.env.CI) {
|
|
18
|
+
warnFunction(new Error(`[i18n message compilation] Message compilation on ${fileIdentifier} has failed.\n` + `Consider setting the environmental variable ${chalk__default["default"].yellow('DISABLE_I18N_MESSAGE_COMPILATION')} to true to disable the message loader or resolve the issues on the messages file.\n` + `${error instanceof Error ? `Error: ${error.message}` : ''}`));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.getI18nMessageFormat = getI18nMessageFormat;
|
|
23
|
+
exports.handleMessageCompilationError = handleMessageCompilationError;
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import _Promise from '@babel/runtime-corejs3/core-js-stable/promise';
|
|
2
|
+
import _URL from '@babel/runtime-corejs3/core-js-stable/url';
|
|
3
|
+
import crypto from 'node:crypto';
|
|
4
|
+
import process, { exit } from 'node:process';
|
|
5
|
+
import chalk from 'chalk';
|
|
6
|
+
import prompts from 'prompts';
|
|
7
|
+
import { processConfig } from '@commercetools-frontend/application-config';
|
|
8
|
+
import { p as pkgJson } from './package-99e547a7.esm.js';
|
|
9
|
+
import _Object$keys from '@babel/runtime-corejs3/core-js-stable/object/keys';
|
|
10
|
+
import _Object$getOwnPropertySymbols from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols';
|
|
11
|
+
import _filterInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/filter';
|
|
12
|
+
import _Object$getOwnPropertyDescriptor from '@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor';
|
|
13
|
+
import _forEachInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/for-each';
|
|
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 _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
|
|
19
|
+
import fetch from 'node-fetch';
|
|
20
|
+
import { u as userAgent, C as CredentialsStorage } from './credentials-storage-d001f726.esm.js';
|
|
21
|
+
import http from 'node:http';
|
|
22
|
+
import jwtDecode from 'jwt-decode';
|
|
23
|
+
import '@commercetools/http-user-agent';
|
|
24
|
+
import '@babel/runtime-corejs3/helpers/classCallCheck';
|
|
25
|
+
import '@babel/runtime-corejs3/helpers/createClass';
|
|
26
|
+
import '@babel/runtime-corejs3/core-js-stable/date/now';
|
|
27
|
+
import 'node:fs';
|
|
28
|
+
import 'node:os';
|
|
29
|
+
import 'node:path';
|
|
30
|
+
import './does-file-exist-32618334.esm.js';
|
|
31
|
+
|
|
32
|
+
function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
33
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
34
|
+
const getAuthToken = async (mcApiUrl, payload, headers) => {
|
|
35
|
+
const response = await fetch(`${mcApiUrl}/tokens/cli`, {
|
|
36
|
+
method: 'POST',
|
|
37
|
+
headers: _objectSpread({
|
|
38
|
+
Accept: 'application/json',
|
|
39
|
+
'Content-Type': 'application/json',
|
|
40
|
+
'x-user-agent': userAgent
|
|
41
|
+
}, headers),
|
|
42
|
+
body: _JSON$stringify(payload)
|
|
43
|
+
});
|
|
44
|
+
if (!response.ok) {
|
|
45
|
+
const text = await response.text();
|
|
46
|
+
let parsed;
|
|
47
|
+
try {
|
|
48
|
+
parsed = JSON.parse(text);
|
|
49
|
+
} catch (error) {}
|
|
50
|
+
const errorMessage = parsed ? parsed.message : text;
|
|
51
|
+
throw new Error(errorMessage);
|
|
52
|
+
}
|
|
53
|
+
const authToken = await response.json();
|
|
54
|
+
return authToken;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
function createAuthCallbackServer(options) {
|
|
58
|
+
const server = http.createServer(async (request, response) => {
|
|
59
|
+
try {
|
|
60
|
+
if (request.url?.includes(`/${options.clientIdentifier}/oidc/callback`)) {
|
|
61
|
+
const incomingUrl = new _URL(request.url, 'http://localhost');
|
|
62
|
+
const sessionToken = incomingUrl.searchParams.get('sessionToken');
|
|
63
|
+
const requestedState = incomingUrl.searchParams.get('state');
|
|
64
|
+
if (!sessionToken) {
|
|
65
|
+
throw new Error('Invalid authentication flow (missing sessionToken)');
|
|
66
|
+
}
|
|
67
|
+
const decodedSessionToken = jwtDecode(sessionToken);
|
|
68
|
+
if (decodedSessionToken?.nonce !== options.nonce) {
|
|
69
|
+
throw new Error('Invalid authentication flow (nonce mismatch)');
|
|
70
|
+
}
|
|
71
|
+
if (requestedState !== options.state) {
|
|
72
|
+
throw new Error('Invalid authentication flow (state mismatch)');
|
|
73
|
+
}
|
|
74
|
+
options.onSuccess({
|
|
75
|
+
token: sessionToken,
|
|
76
|
+
expiresAt: decodedSessionToken.exp
|
|
77
|
+
});
|
|
78
|
+
response.setHeader('content-type', 'text/html');
|
|
79
|
+
response.end('Success!');
|
|
80
|
+
server.close(() => {
|
|
81
|
+
exit();
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
} catch (error) {
|
|
85
|
+
response.setHeader('content-type', 'text/html');
|
|
86
|
+
if (error instanceof Error) {
|
|
87
|
+
console.error(error.message);
|
|
88
|
+
response.end(error.message);
|
|
89
|
+
} else {
|
|
90
|
+
console.error(error);
|
|
91
|
+
response.end(`Invalid authentication flow.`);
|
|
92
|
+
}
|
|
93
|
+
server.close(() => {
|
|
94
|
+
exit();
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
return server;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const credentialsStorage = new CredentialsStorage();
|
|
102
|
+
const port = 3001;
|
|
103
|
+
const clientIdentifier = `mc-scripts-${pkgJson.version}`;
|
|
104
|
+
const isServerError = error => {
|
|
105
|
+
return error instanceof Error && 'code' in error;
|
|
106
|
+
};
|
|
107
|
+
const startServer = server => new _Promise((resolve, reject) => {
|
|
108
|
+
server.listen(port, 'localhost').on('listening', resolve).on('error', error => {
|
|
109
|
+
if (isServerError(error) && error.code === 'EADDRINUSE') {
|
|
110
|
+
return reject(new Error(`The address "localhost:${port}" is already in use. Are you running a Merchant Center application in other process? Please stop that and try again.`, {
|
|
111
|
+
cause: error
|
|
112
|
+
}));
|
|
113
|
+
}
|
|
114
|
+
return reject(new Error('Problem starting server', {
|
|
115
|
+
cause: error
|
|
116
|
+
}));
|
|
117
|
+
}).on('close', () => {
|
|
118
|
+
process.exit();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
const resolveMcApiUrl = async () => {
|
|
122
|
+
// We first check whether the user has set the MC_API_URL environment variable
|
|
123
|
+
if (process.env.MC_API_URL) {
|
|
124
|
+
return process.env.MC_API_URL;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// In the future we might want to support this value as a command line parameter
|
|
128
|
+
|
|
129
|
+
// If not, we parse the Custom Application configuration and check if it's defined over there
|
|
130
|
+
const applicationConfig = await processConfig();
|
|
131
|
+
const mcApiUrl = applicationConfig.env.mcApiUrl;
|
|
132
|
+
return mcApiUrl;
|
|
133
|
+
};
|
|
134
|
+
const resolveProjectKey = async () => {
|
|
135
|
+
// We first check whether the user has set the CTP_PROJECT_KEY environment variable
|
|
136
|
+
if (process.env.CTP_PROJECT_KEY) {
|
|
137
|
+
return process.env.CTP_PROJECT_KEY;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// In the future we might want to support this value as a command line parameter
|
|
141
|
+
|
|
142
|
+
try {
|
|
143
|
+
const applicationConfig = await processConfig();
|
|
144
|
+
// @ts-expect-error - We know that the initialProjectKey is defined in the development environment
|
|
145
|
+
return applicationConfig.env.development.initialProjectKey;
|
|
146
|
+
} catch (error) {
|
|
147
|
+
// It's ok if there's not application config file or if it does not contain the initialProjectKey
|
|
148
|
+
return null;
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const generateRandomHash = function () {
|
|
152
|
+
let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 16;
|
|
153
|
+
return crypto.randomBytes(length).toString('hex');
|
|
154
|
+
};
|
|
155
|
+
async function run() {
|
|
156
|
+
const shouldUseExperimentalIdentityAuthFlow = process.env.ENABLE_EXPERIMENTAL_IDENTITY_AUTH_FLOW === 'true';
|
|
157
|
+
const mcApiUrl = await resolveMcApiUrl();
|
|
158
|
+
if (!mcApiUrl) {
|
|
159
|
+
throw new Error('No Merchant Center API environment URL found. Aborting.');
|
|
160
|
+
}
|
|
161
|
+
console.log(`Using Merchant Center environment "${chalk.green(mcApiUrl)}".`);
|
|
162
|
+
console.log();
|
|
163
|
+
if (credentialsStorage.isSessionValid(mcApiUrl)) {
|
|
164
|
+
console.log(`You already have a valid session.`);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (shouldUseExperimentalIdentityAuthFlow) {
|
|
168
|
+
const open = await import('open');
|
|
169
|
+
const projectKey = await resolveProjectKey();
|
|
170
|
+
const state = generateRandomHash();
|
|
171
|
+
const nonce = generateRandomHash();
|
|
172
|
+
const scopes = ['openid'];
|
|
173
|
+
if (projectKey) {
|
|
174
|
+
scopes.push(`project_key:${projectKey}`);
|
|
175
|
+
scopes.push('view:view_project_settings');
|
|
176
|
+
scopes.push('view:view_products');
|
|
177
|
+
}
|
|
178
|
+
const authUrl = new _URL('/login/authorize', mcApiUrl);
|
|
179
|
+
authUrl.searchParams.set('response_type', 'id_token');
|
|
180
|
+
authUrl.searchParams.set('response_mode', 'query');
|
|
181
|
+
authUrl.searchParams.set('client_id', `__local:${clientIdentifier}`);
|
|
182
|
+
authUrl.searchParams.set('scope', scopes.join(' '));
|
|
183
|
+
authUrl.searchParams.set('state', state);
|
|
184
|
+
authUrl.searchParams.set('nonce', nonce);
|
|
185
|
+
const server = createAuthCallbackServer({
|
|
186
|
+
clientIdentifier,
|
|
187
|
+
state,
|
|
188
|
+
nonce,
|
|
189
|
+
onSuccess: tokenContext => {
|
|
190
|
+
credentialsStorage.setToken(mcApiUrl, tokenContext);
|
|
191
|
+
console.log();
|
|
192
|
+
console.log(chalk.green(`Login successful.`));
|
|
193
|
+
console.log();
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
await startServer(server);
|
|
197
|
+
console.log(`Initiating the OIDC authentication flow, opening the login page in your browser...`);
|
|
198
|
+
console.log(` ${authUrl}`);
|
|
199
|
+
console.log();
|
|
200
|
+
await open.default(authUrl.toString());
|
|
201
|
+
console.log('Waiting for the OIDC authentication to complete...');
|
|
202
|
+
} else {
|
|
203
|
+
console.log(`Enter the login credentials:`);
|
|
204
|
+
const _await$prompts = await prompts({
|
|
205
|
+
type: 'text',
|
|
206
|
+
name: 'email',
|
|
207
|
+
message: 'Email'
|
|
208
|
+
}),
|
|
209
|
+
email = _await$prompts.email;
|
|
210
|
+
const _await$prompts2 = await prompts({
|
|
211
|
+
type: 'invisible',
|
|
212
|
+
name: 'password',
|
|
213
|
+
message: 'Password (hidden)'
|
|
214
|
+
}),
|
|
215
|
+
password = _await$prompts2.password;
|
|
216
|
+
if (!email || !password) {
|
|
217
|
+
throw new Error(`Missing email or password values. Aborting.`);
|
|
218
|
+
}
|
|
219
|
+
const credentials = await getAuthToken(mcApiUrl, {
|
|
220
|
+
email,
|
|
221
|
+
password
|
|
222
|
+
});
|
|
223
|
+
credentialsStorage.setToken(mcApiUrl, credentials);
|
|
224
|
+
console.log(chalk.green(`Login successful.`));
|
|
225
|
+
console.log();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export { run as default };
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
4
|
+
var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
|
|
5
|
+
var crypto = require('node:crypto');
|
|
6
|
+
var process = require('node:process');
|
|
7
|
+
var chalk = require('chalk');
|
|
8
|
+
var prompts = require('prompts');
|
|
9
|
+
var applicationConfig = require('@commercetools-frontend/application-config');
|
|
10
|
+
var _package = require('./package-7e170dc4.cjs.dev.js');
|
|
11
|
+
var _Object$keys = require('@babel/runtime-corejs3/core-js-stable/object/keys');
|
|
12
|
+
var _Object$getOwnPropertySymbols = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols');
|
|
13
|
+
var _filterInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/filter');
|
|
14
|
+
var _Object$getOwnPropertyDescriptor = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor');
|
|
15
|
+
var _forEachInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/for-each');
|
|
16
|
+
var _Object$getOwnPropertyDescriptors = require('@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors');
|
|
17
|
+
var _Object$defineProperties = require('@babel/runtime-corejs3/core-js-stable/object/define-properties');
|
|
18
|
+
var _Object$defineProperty = require('@babel/runtime-corejs3/core-js-stable/object/define-property');
|
|
19
|
+
var _defineProperty = require('@babel/runtime-corejs3/helpers/defineProperty');
|
|
20
|
+
var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
21
|
+
var fetch = require('node-fetch');
|
|
22
|
+
var credentialsStorage$1 = require('./credentials-storage-e7884d17.cjs.dev.js');
|
|
23
|
+
var http = require('node:http');
|
|
24
|
+
var jwtDecode = require('jwt-decode');
|
|
25
|
+
require('@commercetools/http-user-agent');
|
|
26
|
+
require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
27
|
+
require('@babel/runtime-corejs3/helpers/createClass');
|
|
28
|
+
require('@babel/runtime-corejs3/core-js-stable/date/now');
|
|
29
|
+
require('node:fs');
|
|
30
|
+
require('node:os');
|
|
31
|
+
require('node:path');
|
|
32
|
+
require('./does-file-exist-eb86baca.cjs.dev.js');
|
|
33
|
+
|
|
34
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
35
|
+
|
|
36
|
+
function _interopNamespace(e) {
|
|
37
|
+
if (e && e.__esModule) return e;
|
|
38
|
+
var n = Object.create(null);
|
|
39
|
+
if (e) {
|
|
40
|
+
Object.keys(e).forEach(function (k) {
|
|
41
|
+
if (k !== 'default') {
|
|
42
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
43
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function () { return e[k]; }
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
n["default"] = e;
|
|
51
|
+
return Object.freeze(n);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
55
|
+
var _URL__default = /*#__PURE__*/_interopDefault(_URL);
|
|
56
|
+
var crypto__default = /*#__PURE__*/_interopDefault(crypto);
|
|
57
|
+
var process__default = /*#__PURE__*/_interopDefault(process);
|
|
58
|
+
var chalk__default = /*#__PURE__*/_interopDefault(chalk);
|
|
59
|
+
var prompts__default = /*#__PURE__*/_interopDefault(prompts);
|
|
60
|
+
var _Object$keys__default = /*#__PURE__*/_interopDefault(_Object$keys);
|
|
61
|
+
var _Object$getOwnPropertySymbols__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertySymbols);
|
|
62
|
+
var _filterInstanceProperty__default = /*#__PURE__*/_interopDefault(_filterInstanceProperty);
|
|
63
|
+
var _Object$getOwnPropertyDescriptor__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptor);
|
|
64
|
+
var _forEachInstanceProperty__default = /*#__PURE__*/_interopDefault(_forEachInstanceProperty);
|
|
65
|
+
var _Object$getOwnPropertyDescriptors__default = /*#__PURE__*/_interopDefault(_Object$getOwnPropertyDescriptors);
|
|
66
|
+
var _Object$defineProperties__default = /*#__PURE__*/_interopDefault(_Object$defineProperties);
|
|
67
|
+
var _Object$defineProperty__default = /*#__PURE__*/_interopDefault(_Object$defineProperty);
|
|
68
|
+
var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
|
|
69
|
+
var fetch__default = /*#__PURE__*/_interopDefault(fetch);
|
|
70
|
+
var http__default = /*#__PURE__*/_interopDefault(http);
|
|
71
|
+
var jwtDecode__default = /*#__PURE__*/_interopDefault(jwtDecode);
|
|
72
|
+
|
|
73
|
+
function ownKeys(e, r) { var t = _Object$keys__default["default"](e); if (_Object$getOwnPropertySymbols__default["default"]) { var o = _Object$getOwnPropertySymbols__default["default"](e); r && (o = _filterInstanceProperty__default["default"](o).call(o, function (r) { return _Object$getOwnPropertyDescriptor__default["default"](e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
74
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context, _context2; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty__default["default"](_context = ownKeys(Object(t), !0)).call(_context, function (r) { _defineProperty(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors__default["default"] ? _Object$defineProperties__default["default"](e, _Object$getOwnPropertyDescriptors__default["default"](t)) : _forEachInstanceProperty__default["default"](_context2 = ownKeys(Object(t))).call(_context2, function (r) { _Object$defineProperty__default["default"](e, r, _Object$getOwnPropertyDescriptor__default["default"](t, r)); }); } return e; }
|
|
75
|
+
const getAuthToken = async (mcApiUrl, payload, headers) => {
|
|
76
|
+
const response = await fetch__default["default"](`${mcApiUrl}/tokens/cli`, {
|
|
77
|
+
method: 'POST',
|
|
78
|
+
headers: _objectSpread({
|
|
79
|
+
Accept: 'application/json',
|
|
80
|
+
'Content-Type': 'application/json',
|
|
81
|
+
'x-user-agent': credentialsStorage$1.userAgent
|
|
82
|
+
}, headers),
|
|
83
|
+
body: _JSON$stringify__default["default"](payload)
|
|
84
|
+
});
|
|
85
|
+
if (!response.ok) {
|
|
86
|
+
const text = await response.text();
|
|
87
|
+
let parsed;
|
|
88
|
+
try {
|
|
89
|
+
parsed = JSON.parse(text);
|
|
90
|
+
} catch (error) {}
|
|
91
|
+
const errorMessage = parsed ? parsed.message : text;
|
|
92
|
+
throw new Error(errorMessage);
|
|
93
|
+
}
|
|
94
|
+
const authToken = await response.json();
|
|
95
|
+
return authToken;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function createAuthCallbackServer(options) {
|
|
99
|
+
const server = http__default["default"].createServer(async (request, response) => {
|
|
100
|
+
try {
|
|
101
|
+
if (request.url?.includes(`/${options.clientIdentifier}/oidc/callback`)) {
|
|
102
|
+
const incomingUrl = new _URL__default["default"](request.url, 'http://localhost');
|
|
103
|
+
const sessionToken = incomingUrl.searchParams.get('sessionToken');
|
|
104
|
+
const requestedState = incomingUrl.searchParams.get('state');
|
|
105
|
+
if (!sessionToken) {
|
|
106
|
+
throw new Error('Invalid authentication flow (missing sessionToken)');
|
|
107
|
+
}
|
|
108
|
+
const decodedSessionToken = jwtDecode__default["default"](sessionToken);
|
|
109
|
+
if (decodedSessionToken?.nonce !== options.nonce) {
|
|
110
|
+
throw new Error('Invalid authentication flow (nonce mismatch)');
|
|
111
|
+
}
|
|
112
|
+
if (requestedState !== options.state) {
|
|
113
|
+
throw new Error('Invalid authentication flow (state mismatch)');
|
|
114
|
+
}
|
|
115
|
+
options.onSuccess({
|
|
116
|
+
token: sessionToken,
|
|
117
|
+
expiresAt: decodedSessionToken.exp
|
|
118
|
+
});
|
|
119
|
+
response.setHeader('content-type', 'text/html');
|
|
120
|
+
response.end('Success!');
|
|
121
|
+
server.close(() => {
|
|
122
|
+
process.exit();
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
} catch (error) {
|
|
126
|
+
response.setHeader('content-type', 'text/html');
|
|
127
|
+
if (error instanceof Error) {
|
|
128
|
+
console.error(error.message);
|
|
129
|
+
response.end(error.message);
|
|
130
|
+
} else {
|
|
131
|
+
console.error(error);
|
|
132
|
+
response.end(`Invalid authentication flow.`);
|
|
133
|
+
}
|
|
134
|
+
server.close(() => {
|
|
135
|
+
process.exit();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
return server;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
|
|
143
|
+
const port = 3001;
|
|
144
|
+
const clientIdentifier = `mc-scripts-${_package.pkgJson.version}`;
|
|
145
|
+
const isServerError = error => {
|
|
146
|
+
return error instanceof Error && 'code' in error;
|
|
147
|
+
};
|
|
148
|
+
const startServer = server => new _Promise__default["default"]((resolve, reject) => {
|
|
149
|
+
server.listen(port, 'localhost').on('listening', resolve).on('error', error => {
|
|
150
|
+
if (isServerError(error) && error.code === 'EADDRINUSE') {
|
|
151
|
+
return reject(new Error(`The address "localhost:${port}" is already in use. Are you running a Merchant Center application in other process? Please stop that and try again.`, {
|
|
152
|
+
cause: error
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
return reject(new Error('Problem starting server', {
|
|
156
|
+
cause: error
|
|
157
|
+
}));
|
|
158
|
+
}).on('close', () => {
|
|
159
|
+
process__default["default"].exit();
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
const resolveMcApiUrl = async () => {
|
|
163
|
+
// We first check whether the user has set the MC_API_URL environment variable
|
|
164
|
+
if (process__default["default"].env.MC_API_URL) {
|
|
165
|
+
return process__default["default"].env.MC_API_URL;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// In the future we might want to support this value as a command line parameter
|
|
169
|
+
|
|
170
|
+
// If not, we parse the Custom Application configuration and check if it's defined over there
|
|
171
|
+
const applicationConfig$1 = await applicationConfig.processConfig();
|
|
172
|
+
const mcApiUrl = applicationConfig$1.env.mcApiUrl;
|
|
173
|
+
return mcApiUrl;
|
|
174
|
+
};
|
|
175
|
+
const resolveProjectKey = async () => {
|
|
176
|
+
// We first check whether the user has set the CTP_PROJECT_KEY environment variable
|
|
177
|
+
if (process__default["default"].env.CTP_PROJECT_KEY) {
|
|
178
|
+
return process__default["default"].env.CTP_PROJECT_KEY;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// In the future we might want to support this value as a command line parameter
|
|
182
|
+
|
|
183
|
+
try {
|
|
184
|
+
const applicationConfig$1 = await applicationConfig.processConfig();
|
|
185
|
+
// @ts-expect-error - We know that the initialProjectKey is defined in the development environment
|
|
186
|
+
return applicationConfig$1.env.development.initialProjectKey;
|
|
187
|
+
} catch (error) {
|
|
188
|
+
// It's ok if there's not application config file or if it does not contain the initialProjectKey
|
|
189
|
+
return null;
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
const generateRandomHash = function () {
|
|
193
|
+
let length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 16;
|
|
194
|
+
return crypto__default["default"].randomBytes(length).toString('hex');
|
|
195
|
+
};
|
|
196
|
+
async function run() {
|
|
197
|
+
const shouldUseExperimentalIdentityAuthFlow = process__default["default"].env.ENABLE_EXPERIMENTAL_IDENTITY_AUTH_FLOW === 'true';
|
|
198
|
+
const mcApiUrl = await resolveMcApiUrl();
|
|
199
|
+
if (!mcApiUrl) {
|
|
200
|
+
throw new Error('No Merchant Center API environment URL found. Aborting.');
|
|
201
|
+
}
|
|
202
|
+
console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
|
|
203
|
+
console.log();
|
|
204
|
+
if (credentialsStorage.isSessionValid(mcApiUrl)) {
|
|
205
|
+
console.log(`You already have a valid session.`);
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (shouldUseExperimentalIdentityAuthFlow) {
|
|
209
|
+
const open = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('open')); });
|
|
210
|
+
const projectKey = await resolveProjectKey();
|
|
211
|
+
const state = generateRandomHash();
|
|
212
|
+
const nonce = generateRandomHash();
|
|
213
|
+
const scopes = ['openid'];
|
|
214
|
+
if (projectKey) {
|
|
215
|
+
scopes.push(`project_key:${projectKey}`);
|
|
216
|
+
scopes.push('view:view_project_settings');
|
|
217
|
+
scopes.push('view:view_products');
|
|
218
|
+
}
|
|
219
|
+
const authUrl = new _URL__default["default"]('/login/authorize', mcApiUrl);
|
|
220
|
+
authUrl.searchParams.set('response_type', 'id_token');
|
|
221
|
+
authUrl.searchParams.set('response_mode', 'query');
|
|
222
|
+
authUrl.searchParams.set('client_id', `__local:${clientIdentifier}`);
|
|
223
|
+
authUrl.searchParams.set('scope', scopes.join(' '));
|
|
224
|
+
authUrl.searchParams.set('state', state);
|
|
225
|
+
authUrl.searchParams.set('nonce', nonce);
|
|
226
|
+
const server = createAuthCallbackServer({
|
|
227
|
+
clientIdentifier,
|
|
228
|
+
state,
|
|
229
|
+
nonce,
|
|
230
|
+
onSuccess: tokenContext => {
|
|
231
|
+
credentialsStorage.setToken(mcApiUrl, tokenContext);
|
|
232
|
+
console.log();
|
|
233
|
+
console.log(chalk__default["default"].green(`Login successful.`));
|
|
234
|
+
console.log();
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
await startServer(server);
|
|
238
|
+
console.log(`Initiating the OIDC authentication flow, opening the login page in your browser...`);
|
|
239
|
+
console.log(` ${authUrl}`);
|
|
240
|
+
console.log();
|
|
241
|
+
await open.default(authUrl.toString());
|
|
242
|
+
console.log('Waiting for the OIDC authentication to complete...');
|
|
243
|
+
} else {
|
|
244
|
+
console.log(`Enter the login credentials:`);
|
|
245
|
+
const _await$prompts = await prompts__default["default"]({
|
|
246
|
+
type: 'text',
|
|
247
|
+
name: 'email',
|
|
248
|
+
message: 'Email'
|
|
249
|
+
}),
|
|
250
|
+
email = _await$prompts.email;
|
|
251
|
+
const _await$prompts2 = await prompts__default["default"]({
|
|
252
|
+
type: 'invisible',
|
|
253
|
+
name: 'password',
|
|
254
|
+
message: 'Password (hidden)'
|
|
255
|
+
}),
|
|
256
|
+
password = _await$prompts2.password;
|
|
257
|
+
if (!email || !password) {
|
|
258
|
+
throw new Error(`Missing email or password values. Aborting.`);
|
|
259
|
+
}
|
|
260
|
+
const credentials = await getAuthToken(mcApiUrl, {
|
|
261
|
+
email,
|
|
262
|
+
password
|
|
263
|
+
});
|
|
264
|
+
credentialsStorage.setToken(mcApiUrl, credentials);
|
|
265
|
+
console.log(chalk__default["default"].green(`Login successful.`));
|
|
266
|
+
console.log();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
exports["default"] = run;
|