@commercetools-frontend/mc-dev-authentication 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) commercetools GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @commercetools-frontend/mc-dev-authentication
2
+
3
+ <p align="center">
4
+ <a href="https://www.npmjs.com/package/@commercetools-frontend/mc-dev-authentication"><img src="https://badgen.net/npm/v/@commercetools-frontend/mc-dev-authentication" alt="Latest release (latest dist-tag)" /></a> <a href="https://www.npmjs.com/package/@commercetools-frontend/mc-dev-authentication"><img src="https://badgen.net/npm/v/@commercetools-frontend/mc-dev-authentication/next" alt="Latest release (next dist-tag)" /></a> <a href="https://bundlephobia.com/result?p=@commercetools-frontend/mc-dev-authentication"><img src="https://badgen.net/bundlephobia/minzip/@commercetools-frontend/mc-dev-authentication" alt="Minified + GZipped size" /></a> <a href="https://github.com/commercetools/merchant-center-application-kit/blob/main/LICENSE"><img src="https://badgen.net/github/license/commercetools/merchant-center-application-kit" alt="GitHub license" /></a>
5
+ </p>
6
+
7
+ Authentication views when running webpack-dev-server in development mode.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ $ npm install --save @commercetools-frontend/mc-dev-authentication
13
+ ```
@@ -0,0 +1,2 @@
1
+ export * from "./declarations/src/index.js";
2
+ //# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY29tbWVyY2V0b29scy1mcm9udGVuZC1tYy1kZXYtYXV0aGVudGljYXRpb24uY2pzLmQudHMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuL2RlY2xhcmF0aW9ucy9zcmMvaW5kZXguZC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
6
+ var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
7
+ var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
10
+
11
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
12
+ var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
13
+ var _URL__default = /*#__PURE__*/_interopDefault(_URL);
14
+
15
+ const trimTrailingSlash = value => value.replace(/\/$/, '');
16
+ function createMcDevAuthenticationMiddleware(applicationConfig) {
17
+ const isDevAuthenticationMiddlewareDisabled = String(applicationConfig.env.disableAuthRoutesOfDevServer) === 'true' || applicationConfig.env.servedByProxy;
18
+ return (request, response, next) => {
19
+ // This endpoint is meant to be used in Cypress tests to ensure
20
+ // that the primary origin is set to localhost.
21
+ if (request.originalUrl === '/api/health') {
22
+ response.statusCode = 200;
23
+ if (request.headers.accept === 'application/json') {
24
+ response.setHeader('Content-Type', 'application/json');
25
+ response.end(_JSON$stringify__default["default"]({
26
+ healthy: true
27
+ }));
28
+ } else {
29
+ response.setHeader('Content-Type', 'text/html');
30
+ response.end(`healthy = true`);
31
+ }
32
+ return;
33
+ }
34
+ if (request.originalUrl === '/api/graphql') {
35
+ response.statusCode = 404;
36
+ response.setHeader('Content-Type', 'application/json');
37
+ response.end(_JSON$stringify__default["default"]({
38
+ message: `This GraphQL endpoint is only available in production in the [Merchant Center Proxy Router](https://docs.commercetools.com/merchant-center-customizations/concepts/merchant-center-proxy-router). Please check that you are not calling this endpoint in development mode.`
39
+ }));
40
+ return;
41
+ }
42
+ if (applicationConfig.env.__DEVELOPMENT__?.oidc?.authorizeUrl) {
43
+ var _context;
44
+ // Handle login page for OIDC workflow when developing against a local MC API.
45
+ if (_startsWithInstanceProperty__default["default"](_context = applicationConfig.env.__DEVELOPMENT__.oidc.authorizeUrl).call(_context, 'http://localhost')) {
46
+ if (request.originalUrl?.startsWith('/login/authorize')) {
47
+ if (!isDevAuthenticationMiddlewareDisabled) {
48
+ // Redirect to the MC API to initiate the authorize flow.
49
+ const redirectTo = new _URL__default["default"](request.originalUrl, trimTrailingSlash(applicationConfig.env.mcApiUrl));
50
+ response.writeHead(301, {
51
+ Location: redirectTo.toString()
52
+ }).end();
53
+ return;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ next();
59
+ };
60
+ }
61
+
62
+ const transformerLocal = () => {
63
+ // noop
64
+ };
65
+
66
+ exports.createMcDevAuthenticationMiddleware = createMcDevAuthenticationMiddleware;
67
+ exports.transformerLocal = transformerLocal;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ if (process.env.NODE_ENV === "production") {
4
+ module.exports = require("./commercetools-frontend-mc-dev-authentication.cjs.prod.js");
5
+ } else {
6
+ module.exports = require("./commercetools-frontend-mc-dev-authentication.cjs.dev.js");
7
+ }
@@ -0,0 +1,67 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _JSON$stringify = require('@babel/runtime-corejs3/core-js-stable/json/stringify');
6
+ var _startsWithInstanceProperty = require('@babel/runtime-corejs3/core-js-stable/instance/starts-with');
7
+ var _URL = require('@babel/runtime-corejs3/core-js-stable/url');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { 'default': e }; }
10
+
11
+ var _JSON$stringify__default = /*#__PURE__*/_interopDefault(_JSON$stringify);
12
+ var _startsWithInstanceProperty__default = /*#__PURE__*/_interopDefault(_startsWithInstanceProperty);
13
+ var _URL__default = /*#__PURE__*/_interopDefault(_URL);
14
+
15
+ const trimTrailingSlash = value => value.replace(/\/$/, '');
16
+ function createMcDevAuthenticationMiddleware(applicationConfig) {
17
+ const isDevAuthenticationMiddlewareDisabled = String(applicationConfig.env.disableAuthRoutesOfDevServer) === 'true' || applicationConfig.env.servedByProxy;
18
+ return (request, response, next) => {
19
+ // This endpoint is meant to be used in Cypress tests to ensure
20
+ // that the primary origin is set to localhost.
21
+ if (request.originalUrl === '/api/health') {
22
+ response.statusCode = 200;
23
+ if (request.headers.accept === 'application/json') {
24
+ response.setHeader('Content-Type', 'application/json');
25
+ response.end(_JSON$stringify__default["default"]({
26
+ healthy: true
27
+ }));
28
+ } else {
29
+ response.setHeader('Content-Type', 'text/html');
30
+ response.end(`healthy = true`);
31
+ }
32
+ return;
33
+ }
34
+ if (request.originalUrl === '/api/graphql') {
35
+ response.statusCode = 404;
36
+ response.setHeader('Content-Type', 'application/json');
37
+ response.end(_JSON$stringify__default["default"]({
38
+ message: `This GraphQL endpoint is only available in production in the [Merchant Center Proxy Router](https://docs.commercetools.com/merchant-center-customizations/concepts/merchant-center-proxy-router). Please check that you are not calling this endpoint in development mode.`
39
+ }));
40
+ return;
41
+ }
42
+ if (applicationConfig.env.__DEVELOPMENT__?.oidc?.authorizeUrl) {
43
+ var _context;
44
+ // Handle login page for OIDC workflow when developing against a local MC API.
45
+ if (_startsWithInstanceProperty__default["default"](_context = applicationConfig.env.__DEVELOPMENT__.oidc.authorizeUrl).call(_context, 'http://localhost')) {
46
+ if (request.originalUrl?.startsWith('/login/authorize')) {
47
+ if (!isDevAuthenticationMiddlewareDisabled) {
48
+ // Redirect to the MC API to initiate the authorize flow.
49
+ const redirectTo = new _URL__default["default"](request.originalUrl, trimTrailingSlash(applicationConfig.env.mcApiUrl));
50
+ response.writeHead(301, {
51
+ Location: redirectTo.toString()
52
+ }).end();
53
+ return;
54
+ }
55
+ }
56
+ }
57
+ }
58
+ next();
59
+ };
60
+ }
61
+
62
+ const transformerLocal = () => {
63
+ // noop
64
+ };
65
+
66
+ exports.createMcDevAuthenticationMiddleware = createMcDevAuthenticationMiddleware;
67
+ exports.transformerLocal = transformerLocal;
@@ -0,0 +1,56 @@
1
+ import _JSON$stringify from '@babel/runtime-corejs3/core-js-stable/json/stringify';
2
+ import _startsWithInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/starts-with';
3
+ import _URL from '@babel/runtime-corejs3/core-js-stable/url';
4
+
5
+ const trimTrailingSlash = value => value.replace(/\/$/, '');
6
+ function createMcDevAuthenticationMiddleware(applicationConfig) {
7
+ const isDevAuthenticationMiddlewareDisabled = String(applicationConfig.env.disableAuthRoutesOfDevServer) === 'true' || applicationConfig.env.servedByProxy;
8
+ return (request, response, next) => {
9
+ // This endpoint is meant to be used in Cypress tests to ensure
10
+ // that the primary origin is set to localhost.
11
+ if (request.originalUrl === '/api/health') {
12
+ response.statusCode = 200;
13
+ if (request.headers.accept === 'application/json') {
14
+ response.setHeader('Content-Type', 'application/json');
15
+ response.end(_JSON$stringify({
16
+ healthy: true
17
+ }));
18
+ } else {
19
+ response.setHeader('Content-Type', 'text/html');
20
+ response.end(`healthy = true`);
21
+ }
22
+ return;
23
+ }
24
+ if (request.originalUrl === '/api/graphql') {
25
+ response.statusCode = 404;
26
+ response.setHeader('Content-Type', 'application/json');
27
+ response.end(_JSON$stringify({
28
+ message: `This GraphQL endpoint is only available in production in the [Merchant Center Proxy Router](https://docs.commercetools.com/merchant-center-customizations/concepts/merchant-center-proxy-router). Please check that you are not calling this endpoint in development mode.`
29
+ }));
30
+ return;
31
+ }
32
+ if (applicationConfig.env.__DEVELOPMENT__?.oidc?.authorizeUrl) {
33
+ var _context;
34
+ // Handle login page for OIDC workflow when developing against a local MC API.
35
+ if (_startsWithInstanceProperty(_context = applicationConfig.env.__DEVELOPMENT__.oidc.authorizeUrl).call(_context, 'http://localhost')) {
36
+ if (request.originalUrl?.startsWith('/login/authorize')) {
37
+ if (!isDevAuthenticationMiddlewareDisabled) {
38
+ // Redirect to the MC API to initiate the authorize flow.
39
+ const redirectTo = new _URL(request.originalUrl, trimTrailingSlash(applicationConfig.env.mcApiUrl));
40
+ response.writeHead(301, {
41
+ Location: redirectTo.toString()
42
+ }).end();
43
+ return;
44
+ }
45
+ }
46
+ }
47
+ }
48
+ next();
49
+ };
50
+ }
51
+
52
+ const transformerLocal = () => {
53
+ // noop
54
+ };
55
+
56
+ export { createMcDevAuthenticationMiddleware, transformerLocal };
@@ -0,0 +1,5 @@
1
+ import type { ServerResponse } from 'node:http';
2
+ import type { IncomingMessage, NextFunction } from 'connect';
3
+ import type { TCustomApplicationRuntimeConfig } from "./types.js";
4
+ declare function createMcDevAuthenticationMiddleware(applicationConfig: TCustomApplicationRuntimeConfig): (request: IncomingMessage, response: ServerResponse, next: NextFunction) => void;
5
+ export default createMcDevAuthenticationMiddleware;
@@ -0,0 +1,2 @@
1
+ export { default as createMcDevAuthenticationMiddleware } from "./create-mc-dev-authentication-middleware.js";
2
+ export { default as transformerLocal } from "./transformer-local.js";
@@ -0,0 +1,2 @@
1
+ declare const transformerLocal: () => void;
2
+ export default transformerLocal;
@@ -0,0 +1,4 @@
1
+ import type { ApplicationRuntimeConfig } from '@commercetools-frontend/application-config';
2
+ export type TCustomApplicationRuntimeConfig = ApplicationRuntimeConfig<{
3
+ disableAuthRoutesOfDevServer?: boolean;
4
+ }>;
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "@commercetools-frontend/mc-dev-authentication",
3
+ "version": "0.0.0-CRAFT-1791-20251006162610",
4
+ "description": "Authentication views when running webpack-dev-server in development mode",
5
+ "bugs": "https://github.com/commercetools/merchant-center-application-kit/issues",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/commercetools/merchant-center-application-kit.git",
9
+ "directory": "packages/mc-dev-authentication"
10
+ },
11
+ "homepage": "https://docs.commercetools.com/merchant-center-customizations",
12
+ "keywords": [
13
+ "javascript",
14
+ "frontend",
15
+ "react",
16
+ "toolkit"
17
+ ],
18
+ "license": "MIT",
19
+ "publishConfig": {
20
+ "access": "public"
21
+ },
22
+ "main": "dist/commercetools-frontend-mc-dev-authentication.cjs.js",
23
+ "module": "dist/commercetools-frontend-mc-dev-authentication.esm.js",
24
+ "files": [
25
+ "dist",
26
+ "transformer-local.js",
27
+ "package.json",
28
+ "LICENSE",
29
+ "README.md"
30
+ ],
31
+ "dependencies": {
32
+ "@babel/runtime": "^7.22.15",
33
+ "@babel/runtime-corejs3": "^7.22.15"
34
+ },
35
+ "devDependencies": {
36
+ "@tsconfig/node22": "^22.0.0",
37
+ "@types/connect": "^3.4.36",
38
+ "connect": "^3.7.0",
39
+ "@commercetools-frontend/application-config": "0.0.0-CRAFT-1791-20251006162610"
40
+ },
41
+ "engines": {
42
+ "node": "18.x || 20.x || >=22.0.0"
43
+ }
44
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * This file is expected to be included in the package as it's referenced for the `--transformer` option
3
+ * in the `compile-html` command.
4
+ *
5
+ * @example
6
+ * ```
7
+ * mc-scripts compile-html --transformer @commercetools-frontend/mc-dev-authentication/transformer-local.js
8
+ * ```
9
+ */
10
+
11
+ const { transformerLocal } = require('.');
12
+ module.exports = transformerLocal;