@commercetools-frontend/mc-scripts 27.9.1 → 27.9.3
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/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.dev.js +1 -1
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.cjs.prod.js +1 -1
- package/application-runtime/dist/commercetools-frontend-mc-scripts-application-runtime.esm.js +1 -1
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.dev.js +16 -15
- package/cli/dist/commercetools-frontend-mc-scripts-cli.cjs.prod.js +16 -15
- package/cli/dist/commercetools-frontend-mc-scripts-cli.esm.js +16 -15
- package/dist/{build-b9cbc1d1.cjs.dev.js → build-0e40ae4b.cjs.dev.js} +8 -8
- package/dist/{build-cdeab3a8.cjs.prod.js → build-30150f3a.cjs.prod.js} +8 -8
- package/dist/{build-5a0c84e7.esm.js → build-d34f0880.esm.js} +8 -8
- package/dist/{build-vite-ce3c4fb6.esm.js → build-vite-2ea8a241.esm.js} +14 -16
- package/dist/{build-vite-aa0e7242.cjs.prod.js → build-vite-377f721f.cjs.prod.js} +14 -16
- package/dist/{build-vite-0e8f3463.cjs.dev.js → build-vite-e4eeb1a3.cjs.dev.js} +14 -16
- package/dist/commercetools-frontend-mc-scripts.cjs.dev.js +1 -1
- package/dist/commercetools-frontend-mc-scripts.cjs.prod.js +1 -1
- package/dist/commercetools-frontend-mc-scripts.esm.js +1 -1
- package/dist/{compile-html-adfef598.esm.js → compile-html-025cd493.esm.js} +2 -4
- package/dist/{compile-html-b80f9651.cjs.prod.js → compile-html-50fd05ec.cjs.prod.js} +2 -5
- package/dist/{compile-html-8679f721.cjs.dev.js → compile-html-f4ac88cc.cjs.dev.js} +2 -5
- package/dist/{config-sync-7031a7de.esm.js → config-sync-2d02ffa8.esm.js} +17 -17
- package/dist/{config-sync-2b56a941.cjs.dev.js → config-sync-9bb37ec5.cjs.dev.js} +17 -17
- package/dist/{config-sync-41bc7f5e.cjs.prod.js → config-sync-a16795bc.cjs.prod.js} +17 -17
- package/dist/{config-sync-ci-6d12f2f3.cjs.dev.js → config-sync-ci-7f4935ea.cjs.dev.js} +19 -25
- package/dist/{config-sync-ci-1866c188.esm.js → config-sync-ci-b3ea139f.esm.js} +19 -24
- package/dist/{config-sync-ci-ea943de9.cjs.prod.js → config-sync-ci-bfd6918d.cjs.prod.js} +19 -25
- package/dist/{config-sync-helpers-36985f8c.cjs.dev.js → config-sync-helpers-1bd93aad.cjs.dev.js} +48 -57
- package/dist/{config-sync-helpers-79ccaaad.cjs.prod.js → config-sync-helpers-5a1b172b.cjs.prod.js} +46 -55
- package/dist/{config-sync-helpers-875ef4a4.esm.js → config-sync-helpers-9439de91.esm.js} +47 -56
- package/dist/{create-postcss-config-13cb1cb8.cjs.dev.js → create-postcss-config-24861798.cjs.dev.js} +1 -1
- package/dist/{create-postcss-config-390e8a52.esm.js → create-postcss-config-3b68ddee.esm.js} +1 -1
- package/dist/{create-postcss-config-1eeb3d9d.cjs.prod.js → create-postcss-config-9acd005d.cjs.prod.js} +1 -1
- package/dist/{create-webpack-config-for-development-dd95f3d5.esm.js → create-webpack-config-for-development-7787fa87.esm.js} +7 -7
- package/dist/{create-webpack-config-for-development-9a3a3a93.cjs.dev.js → create-webpack-config-for-development-ac4d9b95.cjs.dev.js} +7 -7
- package/dist/{create-webpack-config-for-development-6608b4e4.cjs.prod.js → create-webpack-config-for-development-ba55541a.cjs.prod.js} +7 -7
- package/dist/{create-webpack-config-for-production-29b34b8c.cjs.dev.js → create-webpack-config-for-production-4f0c062f.cjs.dev.js} +8 -8
- package/dist/{create-webpack-config-for-production-31bb3d24.esm.js → create-webpack-config-for-production-6f78b27b.esm.js} +8 -8
- package/dist/{create-webpack-config-for-production-2e6e5036.cjs.prod.js → create-webpack-config-for-production-b054a984.cjs.prod.js} +8 -8
- package/dist/{credentials-storage-bfaa78f0.esm.js → credentials-storage-67deadc3.esm.js} +1 -1
- package/dist/{credentials-storage-60a63c81.cjs.prod.js → credentials-storage-ea1c16dc.cjs.prod.js} +1 -1
- package/dist/{credentials-storage-1826f1a2.cjs.dev.js → credentials-storage-fd195144.cjs.dev.js} +1 -1
- package/dist/{deployment-previews-set-bebd7a04.cjs.prod.js → deployment-previews-set-370f5bce.cjs.prod.js} +22 -28
- package/dist/{deployment-previews-set-410cecf1.esm.js → deployment-previews-set-6ce467f3.esm.js} +22 -27
- package/dist/{deployment-previews-set-a04efad3.cjs.dev.js → deployment-previews-set-fa6468e1.cjs.dev.js} +22 -28
- package/dist/{graphql-requests-c491206a.esm.js → graphql-requests-0e55505c.esm.js} +5 -8
- package/dist/{graphql-requests-1ea68584.cjs.dev.js → graphql-requests-6e742563.cjs.prod.js} +5 -8
- package/dist/{graphql-requests-98b1b779.cjs.prod.js → graphql-requests-af3ea6c9.cjs.dev.js} +5 -8
- package/dist/{i18n-message-complilation-8aec9d1b.esm.js → i18n-message-complilation-21d3b0aa.esm.js} +1 -1
- package/dist/{i18n-message-complilation-3f80e8d6.cjs.dev.js → i18n-message-complilation-7311cb29.cjs.dev.js} +1 -1
- package/dist/{i18n-message-complilation-393d344a.cjs.prod.js → i18n-message-complilation-7762da61.cjs.prod.js} +1 -1
- package/dist/{login-cd99208a.cjs.dev.js → login-8b1925fa.cjs.dev.js} +58 -37
- package/dist/{login-a99d14e6.cjs.prod.js → login-93faaa9c.cjs.prod.js} +58 -37
- package/dist/{login-b935aede.esm.js → login-d6b9b61b.esm.js} +57 -36
- package/dist/{optimizations-1b3f8157.esm.js → optimizations-54382f7b.esm.js} +5 -7
- package/dist/{optimizations-09a6638c.cjs.prod.js → optimizations-56be74d6.cjs.dev.js} +5 -8
- package/dist/{optimizations-640ffcac.cjs.dev.js → optimizations-da5a0cfa.cjs.prod.js} +5 -8
- package/dist/{package-98adb0d5.cjs.dev.js → package-2a97179c.cjs.prod.js} +1 -1
- package/dist/{package-90af7dfe.cjs.prod.js → package-42b38ba8.cjs.dev.js} +1 -1
- package/dist/{package-15124b28.esm.js → package-76b6a39c.esm.js} +1 -1
- package/dist/{paths-7bf7e88e.esm.js → paths-39f22b8b.esm.js} +4 -9
- package/dist/{paths-af1a725a.cjs.prod.js → paths-7768b440.cjs.prod.js} +4 -10
- package/dist/{paths-ec3e3a7d.cjs.dev.js → paths-b76fc753.cjs.dev.js} +4 -10
- package/dist/{serve-ddf30b4c.esm.js → serve-22475fec.esm.js} +13 -13
- package/dist/{serve-87ef7d4f.cjs.prod.js → serve-3837602d.cjs.prod.js} +14 -13
- package/dist/{serve-760fc169.cjs.dev.js → serve-b1c12985.cjs.dev.js} +14 -13
- package/dist/{start-a0945fde.cjs.dev.js → start-bf7fee92.cjs.dev.js} +9 -10
- package/dist/{start-08895b5f.esm.js → start-d66f7fa7.esm.js} +9 -10
- package/dist/{start-d9bd5dfb.cjs.prod.js → start-e2f64f34.cjs.prod.js} +9 -10
- package/dist/{start-vite-745d3123.esm.js → start-vite-4b0df191.esm.js} +4 -5
- package/dist/{start-vite-10e49e5c.cjs.dev.js → start-vite-698c9e82.cjs.dev.js} +4 -5
- package/dist/{start-vite-00514c35.cjs.prod.js → start-vite-dd8a1e26.cjs.prod.js} +4 -5
- package/dist/{try-load-nimbus-plugins-526dccbd.esm.js → try-load-nimbus-plugins-2f528d8f.esm.js} +1 -1
- package/dist/{try-load-nimbus-plugins-59c3a594.cjs.prod.js → try-load-nimbus-plugins-a713d7d3.cjs.prod.js} +1 -1
- package/dist/{try-load-nimbus-plugins-06ce5d83.cjs.dev.js → try-load-nimbus-plugins-d502a5fe.cjs.dev.js} +1 -1
- package/dist/{vite-plugin-svgr-5de1cad9.cjs.prod.js → vite-plugin-svgr-4034a834.cjs.prod.js} +4 -4
- package/dist/{vite-plugin-svgr-53ef97c7.cjs.dev.js → vite-plugin-svgr-7d06f400.cjs.dev.js} +4 -4
- package/dist/{vite-plugin-svgr-22c8d518.esm.js → vite-plugin-svgr-de6ee7da.esm.js} +4 -4
- package/package.json +10 -10
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.dev.js +2 -2
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.cjs.prod.js +2 -2
- package/postcss/dist/commercetools-frontend-mc-scripts-postcss.esm.js +2 -2
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.dev.js +7 -7
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.cjs.prod.js +7 -7
- package/webpack/dist/commercetools-frontend-mc-scripts-webpack.esm.js +7 -7
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.dev.js +1 -1
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.cjs.prod.js +1 -1
- package/webpack-loaders/i18n-message-compilation-loader/dist/commercetools-frontend-mc-scripts-webpack-loaders-i18n-message-compilation-loader.esm.js +1 -1
|
@@ -14,9 +14,9 @@ var chalk = require('chalk');
|
|
|
14
14
|
var graphql = require('graphql');
|
|
15
15
|
var graphqlRequest = require('graphql-request');
|
|
16
16
|
var constants = require('@commercetools-frontend/constants');
|
|
17
|
-
var credentialsStorage$1 = require('./credentials-storage-
|
|
17
|
+
var credentialsStorage$1 = require('./credentials-storage-ea1c16dc.cjs.prod.js');
|
|
18
18
|
var createHttpUserAgent = require('@commercetools/http-user-agent');
|
|
19
|
-
var _package = require('./package-
|
|
19
|
+
var _package = require('./package-2a97179c.cjs.prod.js');
|
|
20
20
|
|
|
21
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
22
22
|
|
|
@@ -57,9 +57,9 @@ async function requestWithTokenRetry(document, requestOptions) {
|
|
|
57
57
|
let retryCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
58
58
|
const token = credentialsStorage.getToken(requestOptions.mcApiUrl);
|
|
59
59
|
const tokenHeader = {
|
|
60
|
-
[constants.SUPPORTED_HEADERS.AUTHORIZATION]:
|
|
60
|
+
[constants.SUPPORTED_HEADERS.AUTHORIZATION]: `Bearer ${token}`
|
|
61
61
|
};
|
|
62
|
-
const client = new graphqlRequest.GraphQLClient(
|
|
62
|
+
const client = new graphqlRequest.GraphQLClient(`${requestOptions.mcApiUrl}/graphql`, {
|
|
63
63
|
headers: _objectSpread(_objectSpread({
|
|
64
64
|
Accept: 'application/json',
|
|
65
65
|
'Content-Type': 'application/json',
|
|
@@ -87,10 +87,7 @@ async function requestWithTokenRetry(document, requestOptions) {
|
|
|
87
87
|
// If it's an unauthorized error, retry the request to force the token to be refreshed.
|
|
88
88
|
if (retryCount === 0 && error.response.errors && error.response.errors.length > 0) {
|
|
89
89
|
var _context;
|
|
90
|
-
const isUnauthorizedError = _someInstanceProperty__default["default"](_context = error.response.errors).call(_context, graphqlError =>
|
|
91
|
-
var _graphqlError$extensi;
|
|
92
|
-
return ((_graphqlError$extensi = graphqlError.extensions) === null || _graphqlError$extensi === void 0 ? void 0 : _graphqlError$extensi.code) === 'UNAUTHENTICATED';
|
|
93
|
-
});
|
|
90
|
+
const isUnauthorizedError = _someInstanceProperty__default["default"](_context = error.response.errors).call(_context, graphqlError => graphqlError.extensions?.code === 'UNAUTHENTICATED');
|
|
94
91
|
if (isUnauthorizedError) {
|
|
95
92
|
console.log(chalk__default["default"].yellow('Expired or invalid session token, attempting to retry the request with a refreshed token...'));
|
|
96
93
|
return requestWithTokenRetry(document, _objectSpread(_objectSpread({}, requestOptions), {}, {
|
|
@@ -14,9 +14,9 @@ var chalk = require('chalk');
|
|
|
14
14
|
var graphql = require('graphql');
|
|
15
15
|
var graphqlRequest = require('graphql-request');
|
|
16
16
|
var constants = require('@commercetools-frontend/constants');
|
|
17
|
-
var credentialsStorage$1 = require('./credentials-storage-
|
|
17
|
+
var credentialsStorage$1 = require('./credentials-storage-fd195144.cjs.dev.js');
|
|
18
18
|
var createHttpUserAgent = require('@commercetools/http-user-agent');
|
|
19
|
-
var _package = require('./package-
|
|
19
|
+
var _package = require('./package-42b38ba8.cjs.dev.js');
|
|
20
20
|
|
|
21
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
|
|
22
22
|
|
|
@@ -57,9 +57,9 @@ async function requestWithTokenRetry(document, requestOptions) {
|
|
|
57
57
|
let retryCount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
58
58
|
const token = credentialsStorage.getToken(requestOptions.mcApiUrl);
|
|
59
59
|
const tokenHeader = {
|
|
60
|
-
[constants.SUPPORTED_HEADERS.AUTHORIZATION]:
|
|
60
|
+
[constants.SUPPORTED_HEADERS.AUTHORIZATION]: `Bearer ${token}`
|
|
61
61
|
};
|
|
62
|
-
const client = new graphqlRequest.GraphQLClient(
|
|
62
|
+
const client = new graphqlRequest.GraphQLClient(`${requestOptions.mcApiUrl}/graphql`, {
|
|
63
63
|
headers: _objectSpread(_objectSpread({
|
|
64
64
|
Accept: 'application/json',
|
|
65
65
|
'Content-Type': 'application/json',
|
|
@@ -87,10 +87,7 @@ async function requestWithTokenRetry(document, requestOptions) {
|
|
|
87
87
|
// If it's an unauthorized error, retry the request to force the token to be refreshed.
|
|
88
88
|
if (retryCount === 0 && error.response.errors && error.response.errors.length > 0) {
|
|
89
89
|
var _context;
|
|
90
|
-
const isUnauthorizedError = _someInstanceProperty__default["default"](_context = error.response.errors).call(_context, graphqlError =>
|
|
91
|
-
var _graphqlError$extensi;
|
|
92
|
-
return ((_graphqlError$extensi = graphqlError.extensions) === null || _graphqlError$extensi === void 0 ? void 0 : _graphqlError$extensi.code) === 'UNAUTHENTICATED';
|
|
93
|
-
});
|
|
90
|
+
const isUnauthorizedError = _someInstanceProperty__default["default"](_context = error.response.errors).call(_context, graphqlError => graphqlError.extensions?.code === 'UNAUTHENTICATED');
|
|
94
91
|
if (isUnauthorizedError) {
|
|
95
92
|
console.log(chalk__default["default"].yellow('Expired or invalid session token, attempting to retry the request with a refreshed token...'));
|
|
96
93
|
return requestWithTokenRetry(document, _objectSpread(_objectSpread({}, requestOptions), {}, {
|
package/dist/{i18n-message-complilation-8aec9d1b.esm.js → i18n-message-complilation-21d3b0aa.esm.js}
RENAMED
|
@@ -8,7 +8,7 @@ function getI18nMessageFormat(source) {
|
|
|
8
8
|
}
|
|
9
9
|
function handleMessageCompilationError(fileIdentifier, error, warnFunction) {
|
|
10
10
|
if (!process.env.CI) {
|
|
11
|
-
warnFunction(new Error(
|
|
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
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
@@ -15,7 +15,7 @@ function getI18nMessageFormat(source) {
|
|
|
15
15
|
}
|
|
16
16
|
function handleMessageCompilationError(fileIdentifier, error, warnFunction) {
|
|
17
17
|
if (!process.env.CI) {
|
|
18
|
-
warnFunction(new Error(
|
|
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
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -15,7 +15,7 @@ function getI18nMessageFormat(source) {
|
|
|
15
15
|
}
|
|
16
16
|
function handleMessageCompilationError(fileIdentifier, error, warnFunction) {
|
|
17
17
|
if (!process.env.CI) {
|
|
18
|
-
warnFunction(new Error(
|
|
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
19
|
}
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
4
4
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
5
5
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
6
|
-
var
|
|
6
|
+
var _bindInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/bind');
|
|
7
7
|
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
8
8
|
var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
|
|
9
9
|
var _setTimeout = require('@babel/runtime-corejs3/core-js-stable/set-timeout');
|
|
@@ -15,10 +15,10 @@ var crypto = require('node:crypto');
|
|
|
15
15
|
var process = require('node:process');
|
|
16
16
|
var chalk = require('chalk');
|
|
17
17
|
var applicationConfig = require('@commercetools-frontend/application-config');
|
|
18
|
-
var _package = require('./package-
|
|
18
|
+
var _package = require('./package-42b38ba8.cjs.dev.js');
|
|
19
19
|
var http = require('node:http');
|
|
20
20
|
var jwtDecode = require('jwt-decode');
|
|
21
|
-
var credentialsStorage$1 = require('./credentials-storage-
|
|
21
|
+
var credentialsStorage$1 = require('./credentials-storage-fd195144.cjs.dev.js');
|
|
22
22
|
require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
23
23
|
require('@babel/runtime-corejs3/helpers/createClass');
|
|
24
24
|
require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
@@ -50,7 +50,7 @@ function _interopNamespace(e) {
|
|
|
50
50
|
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
51
51
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
52
52
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
53
|
-
var
|
|
53
|
+
var _bindInstanceProperty__default = /*#__PURE__*/_interopDefault(_bindInstanceProperty);
|
|
54
54
|
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
55
55
|
var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
|
|
56
56
|
var _setTimeout__default = /*#__PURE__*/_interopDefault(_setTimeout);
|
|
@@ -66,8 +66,8 @@ var http__default = /*#__PURE__*/_interopDefault(http);
|
|
|
66
66
|
function createAuthCallbackServer(options) {
|
|
67
67
|
const server = http__default["default"].createServer(async (request, response) => {
|
|
68
68
|
try {
|
|
69
|
-
var
|
|
70
|
-
if ((
|
|
69
|
+
var _context, _context2;
|
|
70
|
+
if (((_context = request.url) == null ? void 0 : _bindInstanceProperty__default["default"](_context2 = Function.call).call(_context2, _includesInstanceProperty__default["default"](_context), _context))?.(`/${options.clientIdentifier}/oidc/callback`)) {
|
|
71
71
|
const incomingUrl = new _URL__default["default"](request.url, 'http://localhost');
|
|
72
72
|
const sessionToken = incomingUrl.searchParams.get('sessionToken');
|
|
73
73
|
const requestedState = incomingUrl.searchParams.get('state');
|
|
@@ -75,7 +75,7 @@ function createAuthCallbackServer(options) {
|
|
|
75
75
|
throw new Error('Invalid authentication flow (missing sessionToken)');
|
|
76
76
|
}
|
|
77
77
|
const decodedSessionToken = jwtDecode.jwtDecode(sessionToken);
|
|
78
|
-
if (
|
|
78
|
+
if (decodedSessionToken?.nonce !== options.nonce) {
|
|
79
79
|
throw new Error('Invalid authentication flow (nonce mismatch)');
|
|
80
80
|
}
|
|
81
81
|
if (requestedState !== options.state) {
|
|
@@ -98,7 +98,7 @@ function createAuthCallbackServer(options) {
|
|
|
98
98
|
response.end(error.message);
|
|
99
99
|
} else {
|
|
100
100
|
console.error(error);
|
|
101
|
-
response.end(
|
|
101
|
+
response.end(`Invalid authentication flow.`);
|
|
102
102
|
}
|
|
103
103
|
server.close(() => {
|
|
104
104
|
process.exit();
|
|
@@ -110,14 +110,14 @@ function createAuthCallbackServer(options) {
|
|
|
110
110
|
|
|
111
111
|
const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
|
|
112
112
|
const port = 3001;
|
|
113
|
-
const clientIdentifier =
|
|
113
|
+
const clientIdentifier = `mc-scripts-${_package.pkgJson.version}`;
|
|
114
114
|
const isServerError = error => {
|
|
115
115
|
return error instanceof Error && 'code' in error;
|
|
116
116
|
};
|
|
117
117
|
const startServer = server => new _Promise__default["default"]((resolve, reject) => {
|
|
118
118
|
server.listen(port, 'localhost').on('listening', resolve).on('error', error => {
|
|
119
119
|
if (isServerError(error) && error.code === 'EADDRINUSE') {
|
|
120
|
-
return reject(new Error(
|
|
120
|
+
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.`, {
|
|
121
121
|
cause: error
|
|
122
122
|
}));
|
|
123
123
|
}
|
|
@@ -153,9 +153,8 @@ const resolveProjectKey = async options => {
|
|
|
153
153
|
return process__default["default"].env.CTP_PROJECT_KEY;
|
|
154
154
|
}
|
|
155
155
|
try {
|
|
156
|
-
var _applicationConfig$en;
|
|
157
156
|
const applicationConfig$1 = await applicationConfig.processConfig();
|
|
158
|
-
return
|
|
157
|
+
return applicationConfig$1.env.__DEVELOPMENT__?.oidc?.initialProjectKey;
|
|
159
158
|
} catch (error) {
|
|
160
159
|
// It's ok if there's not application config file or if it does not contain the initialProjectKey
|
|
161
160
|
return;
|
|
@@ -164,10 +163,10 @@ const resolveProjectKey = async options => {
|
|
|
164
163
|
const mapOAuthScopesToClaims = scopes => {
|
|
165
164
|
return _mapInstanceProperty__default["default"](scopes).call(scopes, scope => {
|
|
166
165
|
if (_startsWithInstanceProperty__default["default"](scope).call(scope, 'view_')) {
|
|
167
|
-
return
|
|
166
|
+
return `view:${scope}`;
|
|
168
167
|
}
|
|
169
168
|
if (_startsWithInstanceProperty__default["default"](scope).call(scope, 'manage_')) {
|
|
170
|
-
return
|
|
169
|
+
return `manage:${scope}`;
|
|
171
170
|
}
|
|
172
171
|
return scope;
|
|
173
172
|
});
|
|
@@ -175,12 +174,10 @@ const mapOAuthScopesToClaims = scopes => {
|
|
|
175
174
|
const mapAdditionalOAuthScopesToClaims = (name, scopes) => {
|
|
176
175
|
return _mapInstanceProperty__default["default"](scopes).call(scopes, scope => {
|
|
177
176
|
if (_startsWithInstanceProperty__default["default"](scope).call(scope, 'view_')) {
|
|
178
|
-
|
|
179
|
-
return _concatInstanceProperty__default["default"](_context = "view/".concat(name, ":")).call(_context, scope);
|
|
177
|
+
return `view/${name}:${scope}`;
|
|
180
178
|
}
|
|
181
179
|
if (_startsWithInstanceProperty__default["default"](scope).call(scope, 'manage_')) {
|
|
182
|
-
|
|
183
|
-
return _concatInstanceProperty__default["default"](_context2 = "manage/".concat(name, ":")).call(_context2, scope);
|
|
180
|
+
return `manage/${name}:${scope}`;
|
|
184
181
|
}
|
|
185
182
|
return scope;
|
|
186
183
|
});
|
|
@@ -192,15 +189,15 @@ const resolveOAuthScopes = async options => {
|
|
|
192
189
|
|
|
193
190
|
// We first check whether the user has set the CTP_OAUTH_SCOPES environment variable
|
|
194
191
|
if (process__default["default"].env.CTP_OAUTH_SCOPES) {
|
|
195
|
-
var
|
|
196
|
-
return mapOAuthScopesToClaims((
|
|
192
|
+
var _context, _context2;
|
|
193
|
+
return mapOAuthScopesToClaims(((_context = process__default["default"].env.CTP_OAUTH_SCOPES?.split(',')) == null ? void 0 : _bindInstanceProperty__default["default"](_context2 = Function.call).call(_context2, _mapInstanceProperty__default["default"](_context), _context))?.(scope => _trimInstanceProperty__default["default"](scope).call(scope)) ?? []);
|
|
197
194
|
}
|
|
198
195
|
try {
|
|
199
|
-
var
|
|
196
|
+
var _context3, _context4, _context5, _context6;
|
|
200
197
|
const applicationConfig$1 = await applicationConfig.processConfig();
|
|
201
|
-
const configuredOAuthScopes =
|
|
202
|
-
const configuredAdditionalOAuthScopes =
|
|
203
|
-
return [...mapOAuthScopesToClaims(
|
|
198
|
+
const configuredOAuthScopes = applicationConfig$1.env.__DEVELOPMENT__?.oidc?.oAuthScopes;
|
|
199
|
+
const configuredAdditionalOAuthScopes = applicationConfig$1.env.__DEVELOPMENT__?.oidc?.additionalOAuthScopes;
|
|
200
|
+
return [...mapOAuthScopesToClaims(configuredOAuthScopes?.view ?? []), ...mapOAuthScopesToClaims(configuredOAuthScopes?.manage ?? []), ...(((_context3 = configuredAdditionalOAuthScopes) == null ? void 0 : _bindInstanceProperty__default["default"](_context4 = Function.call).call(_context4, _flatMapInstanceProperty__default["default"](_context3), _context3))?.(scope => mapAdditionalOAuthScopesToClaims(scope.name, scope.view)) ?? []), ...(((_context5 = configuredAdditionalOAuthScopes) == null ? void 0 : _bindInstanceProperty__default["default"](_context6 = Function.call).call(_context6, _flatMapInstanceProperty__default["default"](_context5), _context5))?.(scope => mapAdditionalOAuthScopesToClaims(scope.name, scope.manage)) ?? [])];
|
|
204
201
|
} catch (error) {
|
|
205
202
|
// It's ok if there's not application config file or if it does not contain the initialProjectKey
|
|
206
203
|
return [];
|
|
@@ -224,7 +221,7 @@ async function runHeadlessLogin(authUrl) {
|
|
|
224
221
|
let puppeteer;
|
|
225
222
|
try {
|
|
226
223
|
puppeteer = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('puppeteer')); });
|
|
227
|
-
} catch
|
|
224
|
+
} catch {
|
|
228
225
|
throw new Error('Puppeteer is required for headless login. Install it with: npm install puppeteer');
|
|
229
226
|
}
|
|
230
227
|
const browser = await puppeteer.default.launch({
|
|
@@ -245,9 +242,17 @@ async function runHeadlessLogin(authUrl) {
|
|
|
245
242
|
// Dismiss cookie banner if present
|
|
246
243
|
// Note: Using string-based evaluate to avoid bundler transforming Array.from
|
|
247
244
|
try {
|
|
248
|
-
await page.evaluate(
|
|
245
|
+
await page.evaluate(`
|
|
246
|
+
(function() {
|
|
247
|
+
var buttons = Array.from(document.querySelectorAll('button'));
|
|
248
|
+
var acceptBtn = buttons.find(function(btn) {
|
|
249
|
+
return btn.textContent && btn.textContent.includes('Accept all cookies');
|
|
250
|
+
});
|
|
251
|
+
if (acceptBtn) acceptBtn.click();
|
|
252
|
+
})()
|
|
253
|
+
`);
|
|
249
254
|
await new _Promise__default["default"](resolve => _setTimeout__default["default"](resolve, 500));
|
|
250
|
-
} catch
|
|
255
|
+
} catch {
|
|
251
256
|
// Cookie banner not found or already dismissed
|
|
252
257
|
}
|
|
253
258
|
|
|
@@ -256,7 +261,15 @@ async function runHeadlessLogin(authUrl) {
|
|
|
256
261
|
await new _Promise__default["default"](resolve => _setTimeout__default["default"](resolve, 500));
|
|
257
262
|
|
|
258
263
|
// Click "Next" button
|
|
259
|
-
await page.evaluate(
|
|
264
|
+
await page.evaluate(`
|
|
265
|
+
(function() {
|
|
266
|
+
var buttons = Array.from(document.querySelectorAll('button'));
|
|
267
|
+
var nextBtn = buttons.find(function(btn) {
|
|
268
|
+
return btn.textContent && btn.textContent.toLowerCase().includes('next');
|
|
269
|
+
});
|
|
270
|
+
if (nextBtn) nextBtn.click();
|
|
271
|
+
})()
|
|
272
|
+
`);
|
|
260
273
|
|
|
261
274
|
// Wait for password field
|
|
262
275
|
await page.waitForSelector('input[name="password"]', {
|
|
@@ -269,7 +282,15 @@ async function runHeadlessLogin(authUrl) {
|
|
|
269
282
|
await new _Promise__default["default"](resolve => _setTimeout__default["default"](resolve, 500));
|
|
270
283
|
|
|
271
284
|
// Click "Submit" button
|
|
272
|
-
await page.evaluate(
|
|
285
|
+
await page.evaluate(`
|
|
286
|
+
(function() {
|
|
287
|
+
var buttons = Array.from(document.querySelectorAll('button'));
|
|
288
|
+
var submitBtn = buttons.find(function(btn) {
|
|
289
|
+
return btn.textContent && btn.textContent.toLowerCase().includes('submit');
|
|
290
|
+
});
|
|
291
|
+
if (submitBtn) submitBtn.click();
|
|
292
|
+
})()
|
|
293
|
+
`);
|
|
273
294
|
|
|
274
295
|
// Wait for the callback to be processed (the server will close and exit)
|
|
275
296
|
// We just need to keep the browser alive until the redirect happens
|
|
@@ -301,17 +322,17 @@ async function run(options) {
|
|
|
301
322
|
if (!mcApiUrl) {
|
|
302
323
|
throw new Error('No Merchant Center API URL found. Aborting.');
|
|
303
324
|
}
|
|
304
|
-
console.log(
|
|
325
|
+
console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
|
|
305
326
|
console.log();
|
|
306
327
|
if (!options.force && credentialsStorage.isSessionValid(mcApiUrl)) {
|
|
307
|
-
console.log(
|
|
328
|
+
console.log(`You already have a valid session.`);
|
|
308
329
|
return;
|
|
309
330
|
}
|
|
310
331
|
const projectKey = await resolveProjectKey(options);
|
|
311
332
|
const oauthScopes = await resolveOAuthScopes(options);
|
|
312
333
|
const scopes = ['openid'];
|
|
313
334
|
if (projectKey) {
|
|
314
|
-
scopes.push(
|
|
335
|
+
scopes.push(`project_key:${projectKey}`);
|
|
315
336
|
_forEachInstanceProperty__default["default"](oauthScopes).call(oauthScopes, scope => {
|
|
316
337
|
scopes.push(scope);
|
|
317
338
|
});
|
|
@@ -321,7 +342,7 @@ async function run(options) {
|
|
|
321
342
|
const authUrl = new _URL__default["default"]('/login/authorize', mcApiUrl);
|
|
322
343
|
authUrl.searchParams.set('response_type', 'id_token');
|
|
323
344
|
authUrl.searchParams.set('response_mode', 'query');
|
|
324
|
-
authUrl.searchParams.set('client_id',
|
|
345
|
+
authUrl.searchParams.set('client_id', `__local:${clientIdentifier}`);
|
|
325
346
|
authUrl.searchParams.set('scope', scopes.join(' '));
|
|
326
347
|
authUrl.searchParams.set('state', state);
|
|
327
348
|
authUrl.searchParams.set('nonce', nonce);
|
|
@@ -332,18 +353,18 @@ async function run(options) {
|
|
|
332
353
|
onSuccess: tokenContext => {
|
|
333
354
|
credentialsStorage.setToken(mcApiUrl, tokenContext);
|
|
334
355
|
console.log();
|
|
335
|
-
console.log(chalk__default["default"].green(
|
|
356
|
+
console.log(chalk__default["default"].green(`Login successful.`));
|
|
336
357
|
console.log();
|
|
337
358
|
}
|
|
338
359
|
});
|
|
339
360
|
await startServer(server);
|
|
340
361
|
if (options.headless) {
|
|
341
|
-
console.log(
|
|
362
|
+
console.log(`Initiating headless authentication flow using Puppeteer...`);
|
|
342
363
|
console.log();
|
|
343
364
|
await runHeadlessLogin(authUrl);
|
|
344
365
|
} else {
|
|
345
|
-
console.log(
|
|
346
|
-
console.log(
|
|
366
|
+
console.log(`Initiating the OIDC authentication flow, opening the login page in your browser...`);
|
|
367
|
+
console.log(` ${authUrl}`);
|
|
347
368
|
console.log();
|
|
348
369
|
const open = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('open')); });
|
|
349
370
|
await open.default(authUrl.toString());
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _Promise = require('@babel/runtime-corejs3/core-js-stable/promise');
|
|
4
4
|
var _mapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/map');
|
|
5
5
|
var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
|
|
6
|
-
var
|
|
6
|
+
var _bindInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/bind');
|
|
7
7
|
var _trimInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/trim');
|
|
8
8
|
var _flatMapInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/flat-map');
|
|
9
9
|
var _setTimeout = require('@babel/runtime-corejs3/core-js-stable/set-timeout');
|
|
@@ -15,10 +15,10 @@ var crypto = require('node:crypto');
|
|
|
15
15
|
var process = require('node:process');
|
|
16
16
|
var chalk = require('chalk');
|
|
17
17
|
var applicationConfig = require('@commercetools-frontend/application-config');
|
|
18
|
-
var _package = require('./package-
|
|
18
|
+
var _package = require('./package-2a97179c.cjs.prod.js');
|
|
19
19
|
var http = require('node:http');
|
|
20
20
|
var jwtDecode = require('jwt-decode');
|
|
21
|
-
var credentialsStorage$1 = require('./credentials-storage-
|
|
21
|
+
var credentialsStorage$1 = require('./credentials-storage-ea1c16dc.cjs.prod.js');
|
|
22
22
|
require('@babel/runtime-corejs3/helpers/classCallCheck');
|
|
23
23
|
require('@babel/runtime-corejs3/helpers/createClass');
|
|
24
24
|
require('@babel/runtime-corejs3/core-js-stable/json/stringify');
|
|
@@ -50,7 +50,7 @@ function _interopNamespace(e) {
|
|
|
50
50
|
var _Promise__default = /*#__PURE__*/_interopDefault(_Promise);
|
|
51
51
|
var _mapInstanceProperty__default = /*#__PURE__*/_interopDefault(_mapInstanceProperty);
|
|
52
52
|
var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
|
|
53
|
-
var
|
|
53
|
+
var _bindInstanceProperty__default = /*#__PURE__*/_interopDefault(_bindInstanceProperty);
|
|
54
54
|
var _trimInstanceProperty__default = /*#__PURE__*/_interopDefault(_trimInstanceProperty);
|
|
55
55
|
var _flatMapInstanceProperty__default = /*#__PURE__*/_interopDefault(_flatMapInstanceProperty);
|
|
56
56
|
var _setTimeout__default = /*#__PURE__*/_interopDefault(_setTimeout);
|
|
@@ -66,8 +66,8 @@ var http__default = /*#__PURE__*/_interopDefault(http);
|
|
|
66
66
|
function createAuthCallbackServer(options) {
|
|
67
67
|
const server = http__default["default"].createServer(async (request, response) => {
|
|
68
68
|
try {
|
|
69
|
-
var
|
|
70
|
-
if ((
|
|
69
|
+
var _context, _context2;
|
|
70
|
+
if (((_context = request.url) == null ? void 0 : _bindInstanceProperty__default["default"](_context2 = Function.call).call(_context2, _includesInstanceProperty__default["default"](_context), _context))?.(`/${options.clientIdentifier}/oidc/callback`)) {
|
|
71
71
|
const incomingUrl = new _URL__default["default"](request.url, 'http://localhost');
|
|
72
72
|
const sessionToken = incomingUrl.searchParams.get('sessionToken');
|
|
73
73
|
const requestedState = incomingUrl.searchParams.get('state');
|
|
@@ -75,7 +75,7 @@ function createAuthCallbackServer(options) {
|
|
|
75
75
|
throw new Error('Invalid authentication flow (missing sessionToken)');
|
|
76
76
|
}
|
|
77
77
|
const decodedSessionToken = jwtDecode.jwtDecode(sessionToken);
|
|
78
|
-
if (
|
|
78
|
+
if (decodedSessionToken?.nonce !== options.nonce) {
|
|
79
79
|
throw new Error('Invalid authentication flow (nonce mismatch)');
|
|
80
80
|
}
|
|
81
81
|
if (requestedState !== options.state) {
|
|
@@ -98,7 +98,7 @@ function createAuthCallbackServer(options) {
|
|
|
98
98
|
response.end(error.message);
|
|
99
99
|
} else {
|
|
100
100
|
console.error(error);
|
|
101
|
-
response.end(
|
|
101
|
+
response.end(`Invalid authentication flow.`);
|
|
102
102
|
}
|
|
103
103
|
server.close(() => {
|
|
104
104
|
process.exit();
|
|
@@ -110,14 +110,14 @@ function createAuthCallbackServer(options) {
|
|
|
110
110
|
|
|
111
111
|
const credentialsStorage = new credentialsStorage$1.CredentialsStorage();
|
|
112
112
|
const port = 3001;
|
|
113
|
-
const clientIdentifier =
|
|
113
|
+
const clientIdentifier = `mc-scripts-${_package.pkgJson.version}`;
|
|
114
114
|
const isServerError = error => {
|
|
115
115
|
return error instanceof Error && 'code' in error;
|
|
116
116
|
};
|
|
117
117
|
const startServer = server => new _Promise__default["default"]((resolve, reject) => {
|
|
118
118
|
server.listen(port, 'localhost').on('listening', resolve).on('error', error => {
|
|
119
119
|
if (isServerError(error) && error.code === 'EADDRINUSE') {
|
|
120
|
-
return reject(new Error(
|
|
120
|
+
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.`, {
|
|
121
121
|
cause: error
|
|
122
122
|
}));
|
|
123
123
|
}
|
|
@@ -153,9 +153,8 @@ const resolveProjectKey = async options => {
|
|
|
153
153
|
return process__default["default"].env.CTP_PROJECT_KEY;
|
|
154
154
|
}
|
|
155
155
|
try {
|
|
156
|
-
var _applicationConfig$en;
|
|
157
156
|
const applicationConfig$1 = await applicationConfig.processConfig();
|
|
158
|
-
return
|
|
157
|
+
return applicationConfig$1.env.__DEVELOPMENT__?.oidc?.initialProjectKey;
|
|
159
158
|
} catch (error) {
|
|
160
159
|
// It's ok if there's not application config file or if it does not contain the initialProjectKey
|
|
161
160
|
return;
|
|
@@ -164,10 +163,10 @@ const resolveProjectKey = async options => {
|
|
|
164
163
|
const mapOAuthScopesToClaims = scopes => {
|
|
165
164
|
return _mapInstanceProperty__default["default"](scopes).call(scopes, scope => {
|
|
166
165
|
if (_startsWithInstanceProperty__default["default"](scope).call(scope, 'view_')) {
|
|
167
|
-
return
|
|
166
|
+
return `view:${scope}`;
|
|
168
167
|
}
|
|
169
168
|
if (_startsWithInstanceProperty__default["default"](scope).call(scope, 'manage_')) {
|
|
170
|
-
return
|
|
169
|
+
return `manage:${scope}`;
|
|
171
170
|
}
|
|
172
171
|
return scope;
|
|
173
172
|
});
|
|
@@ -175,12 +174,10 @@ const mapOAuthScopesToClaims = scopes => {
|
|
|
175
174
|
const mapAdditionalOAuthScopesToClaims = (name, scopes) => {
|
|
176
175
|
return _mapInstanceProperty__default["default"](scopes).call(scopes, scope => {
|
|
177
176
|
if (_startsWithInstanceProperty__default["default"](scope).call(scope, 'view_')) {
|
|
178
|
-
|
|
179
|
-
return _concatInstanceProperty__default["default"](_context = "view/".concat(name, ":")).call(_context, scope);
|
|
177
|
+
return `view/${name}:${scope}`;
|
|
180
178
|
}
|
|
181
179
|
if (_startsWithInstanceProperty__default["default"](scope).call(scope, 'manage_')) {
|
|
182
|
-
|
|
183
|
-
return _concatInstanceProperty__default["default"](_context2 = "manage/".concat(name, ":")).call(_context2, scope);
|
|
180
|
+
return `manage/${name}:${scope}`;
|
|
184
181
|
}
|
|
185
182
|
return scope;
|
|
186
183
|
});
|
|
@@ -192,15 +189,15 @@ const resolveOAuthScopes = async options => {
|
|
|
192
189
|
|
|
193
190
|
// We first check whether the user has set the CTP_OAUTH_SCOPES environment variable
|
|
194
191
|
if (process__default["default"].env.CTP_OAUTH_SCOPES) {
|
|
195
|
-
var
|
|
196
|
-
return mapOAuthScopesToClaims((
|
|
192
|
+
var _context, _context2;
|
|
193
|
+
return mapOAuthScopesToClaims(((_context = process__default["default"].env.CTP_OAUTH_SCOPES?.split(',')) == null ? void 0 : _bindInstanceProperty__default["default"](_context2 = Function.call).call(_context2, _mapInstanceProperty__default["default"](_context), _context))?.(scope => _trimInstanceProperty__default["default"](scope).call(scope)) ?? []);
|
|
197
194
|
}
|
|
198
195
|
try {
|
|
199
|
-
var
|
|
196
|
+
var _context3, _context4, _context5, _context6;
|
|
200
197
|
const applicationConfig$1 = await applicationConfig.processConfig();
|
|
201
|
-
const configuredOAuthScopes =
|
|
202
|
-
const configuredAdditionalOAuthScopes =
|
|
203
|
-
return [...mapOAuthScopesToClaims(
|
|
198
|
+
const configuredOAuthScopes = applicationConfig$1.env.__DEVELOPMENT__?.oidc?.oAuthScopes;
|
|
199
|
+
const configuredAdditionalOAuthScopes = applicationConfig$1.env.__DEVELOPMENT__?.oidc?.additionalOAuthScopes;
|
|
200
|
+
return [...mapOAuthScopesToClaims(configuredOAuthScopes?.view ?? []), ...mapOAuthScopesToClaims(configuredOAuthScopes?.manage ?? []), ...(((_context3 = configuredAdditionalOAuthScopes) == null ? void 0 : _bindInstanceProperty__default["default"](_context4 = Function.call).call(_context4, _flatMapInstanceProperty__default["default"](_context3), _context3))?.(scope => mapAdditionalOAuthScopesToClaims(scope.name, scope.view)) ?? []), ...(((_context5 = configuredAdditionalOAuthScopes) == null ? void 0 : _bindInstanceProperty__default["default"](_context6 = Function.call).call(_context6, _flatMapInstanceProperty__default["default"](_context5), _context5))?.(scope => mapAdditionalOAuthScopesToClaims(scope.name, scope.manage)) ?? [])];
|
|
204
201
|
} catch (error) {
|
|
205
202
|
// It's ok if there's not application config file or if it does not contain the initialProjectKey
|
|
206
203
|
return [];
|
|
@@ -224,7 +221,7 @@ async function runHeadlessLogin(authUrl) {
|
|
|
224
221
|
let puppeteer;
|
|
225
222
|
try {
|
|
226
223
|
puppeteer = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('puppeteer')); });
|
|
227
|
-
} catch
|
|
224
|
+
} catch {
|
|
228
225
|
throw new Error('Puppeteer is required for headless login. Install it with: npm install puppeteer');
|
|
229
226
|
}
|
|
230
227
|
const browser = await puppeteer.default.launch({
|
|
@@ -245,9 +242,17 @@ async function runHeadlessLogin(authUrl) {
|
|
|
245
242
|
// Dismiss cookie banner if present
|
|
246
243
|
// Note: Using string-based evaluate to avoid bundler transforming Array.from
|
|
247
244
|
try {
|
|
248
|
-
await page.evaluate(
|
|
245
|
+
await page.evaluate(`
|
|
246
|
+
(function() {
|
|
247
|
+
var buttons = Array.from(document.querySelectorAll('button'));
|
|
248
|
+
var acceptBtn = buttons.find(function(btn) {
|
|
249
|
+
return btn.textContent && btn.textContent.includes('Accept all cookies');
|
|
250
|
+
});
|
|
251
|
+
if (acceptBtn) acceptBtn.click();
|
|
252
|
+
})()
|
|
253
|
+
`);
|
|
249
254
|
await new _Promise__default["default"](resolve => _setTimeout__default["default"](resolve, 500));
|
|
250
|
-
} catch
|
|
255
|
+
} catch {
|
|
251
256
|
// Cookie banner not found or already dismissed
|
|
252
257
|
}
|
|
253
258
|
|
|
@@ -256,7 +261,15 @@ async function runHeadlessLogin(authUrl) {
|
|
|
256
261
|
await new _Promise__default["default"](resolve => _setTimeout__default["default"](resolve, 500));
|
|
257
262
|
|
|
258
263
|
// Click "Next" button
|
|
259
|
-
await page.evaluate(
|
|
264
|
+
await page.evaluate(`
|
|
265
|
+
(function() {
|
|
266
|
+
var buttons = Array.from(document.querySelectorAll('button'));
|
|
267
|
+
var nextBtn = buttons.find(function(btn) {
|
|
268
|
+
return btn.textContent && btn.textContent.toLowerCase().includes('next');
|
|
269
|
+
});
|
|
270
|
+
if (nextBtn) nextBtn.click();
|
|
271
|
+
})()
|
|
272
|
+
`);
|
|
260
273
|
|
|
261
274
|
// Wait for password field
|
|
262
275
|
await page.waitForSelector('input[name="password"]', {
|
|
@@ -269,7 +282,15 @@ async function runHeadlessLogin(authUrl) {
|
|
|
269
282
|
await new _Promise__default["default"](resolve => _setTimeout__default["default"](resolve, 500));
|
|
270
283
|
|
|
271
284
|
// Click "Submit" button
|
|
272
|
-
await page.evaluate(
|
|
285
|
+
await page.evaluate(`
|
|
286
|
+
(function() {
|
|
287
|
+
var buttons = Array.from(document.querySelectorAll('button'));
|
|
288
|
+
var submitBtn = buttons.find(function(btn) {
|
|
289
|
+
return btn.textContent && btn.textContent.toLowerCase().includes('submit');
|
|
290
|
+
});
|
|
291
|
+
if (submitBtn) submitBtn.click();
|
|
292
|
+
})()
|
|
293
|
+
`);
|
|
273
294
|
|
|
274
295
|
// Wait for the callback to be processed (the server will close and exit)
|
|
275
296
|
// We just need to keep the browser alive until the redirect happens
|
|
@@ -301,17 +322,17 @@ async function run(options) {
|
|
|
301
322
|
if (!mcApiUrl) {
|
|
302
323
|
throw new Error('No Merchant Center API URL found. Aborting.');
|
|
303
324
|
}
|
|
304
|
-
console.log(
|
|
325
|
+
console.log(`Using Merchant Center environment "${chalk__default["default"].green(mcApiUrl)}".`);
|
|
305
326
|
console.log();
|
|
306
327
|
if (!options.force && credentialsStorage.isSessionValid(mcApiUrl)) {
|
|
307
|
-
console.log(
|
|
328
|
+
console.log(`You already have a valid session.`);
|
|
308
329
|
return;
|
|
309
330
|
}
|
|
310
331
|
const projectKey = await resolveProjectKey(options);
|
|
311
332
|
const oauthScopes = await resolveOAuthScopes(options);
|
|
312
333
|
const scopes = ['openid'];
|
|
313
334
|
if (projectKey) {
|
|
314
|
-
scopes.push(
|
|
335
|
+
scopes.push(`project_key:${projectKey}`);
|
|
315
336
|
_forEachInstanceProperty__default["default"](oauthScopes).call(oauthScopes, scope => {
|
|
316
337
|
scopes.push(scope);
|
|
317
338
|
});
|
|
@@ -321,7 +342,7 @@ async function run(options) {
|
|
|
321
342
|
const authUrl = new _URL__default["default"]('/login/authorize', mcApiUrl);
|
|
322
343
|
authUrl.searchParams.set('response_type', 'id_token');
|
|
323
344
|
authUrl.searchParams.set('response_mode', 'query');
|
|
324
|
-
authUrl.searchParams.set('client_id',
|
|
345
|
+
authUrl.searchParams.set('client_id', `__local:${clientIdentifier}`);
|
|
325
346
|
authUrl.searchParams.set('scope', scopes.join(' '));
|
|
326
347
|
authUrl.searchParams.set('state', state);
|
|
327
348
|
authUrl.searchParams.set('nonce', nonce);
|
|
@@ -332,18 +353,18 @@ async function run(options) {
|
|
|
332
353
|
onSuccess: tokenContext => {
|
|
333
354
|
credentialsStorage.setToken(mcApiUrl, tokenContext);
|
|
334
355
|
console.log();
|
|
335
|
-
console.log(chalk__default["default"].green(
|
|
356
|
+
console.log(chalk__default["default"].green(`Login successful.`));
|
|
336
357
|
console.log();
|
|
337
358
|
}
|
|
338
359
|
});
|
|
339
360
|
await startServer(server);
|
|
340
361
|
if (options.headless) {
|
|
341
|
-
console.log(
|
|
362
|
+
console.log(`Initiating headless authentication flow using Puppeteer...`);
|
|
342
363
|
console.log();
|
|
343
364
|
await runHeadlessLogin(authUrl);
|
|
344
365
|
} else {
|
|
345
|
-
console.log(
|
|
346
|
-
console.log(
|
|
366
|
+
console.log(`Initiating the OIDC authentication flow, opening the login page in your browser...`);
|
|
367
|
+
console.log(` ${authUrl}`);
|
|
347
368
|
console.log();
|
|
348
369
|
const open = await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('open')); });
|
|
349
370
|
await open.default(authUrl.toString());
|