@eventcatalog/core 3.44.1 → 3.44.2
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/dist/analytics/analytics.cjs +1 -1
- package/dist/analytics/analytics.js +2 -2
- package/dist/analytics/log-build.cjs +1 -1
- package/dist/analytics/log-build.js +3 -3
- package/dist/{chunk-DKKPJ3QM.js → chunk-BLJ5FRR3.js} +1 -1
- package/dist/{chunk-L26L4Y5J.js → chunk-IU3D7JRW.js} +1 -1
- package/dist/{chunk-MFLSPCEA.js → chunk-LIIOK6SZ.js} +1 -1
- package/dist/{chunk-3UVY6YHH.js → chunk-RUACTEJR.js} +1 -1
- package/dist/{chunk-EPDZMVQ3.js → chunk-THDZCUFV.js} +1 -1
- package/dist/constants.cjs +1 -1
- package/dist/constants.js +1 -1
- package/dist/eventcatalog.cjs +1 -1
- package/dist/eventcatalog.js +5 -5
- package/dist/generate.cjs +1 -1
- package/dist/generate.js +3 -3
- package/dist/utils/cli-logger.cjs +1 -1
- package/dist/utils/cli-logger.js +2 -2
- package/eventcatalog/src/components/EnvironmentDropdown.test.ts +64 -0
- package/eventcatalog/src/components/EnvironmentDropdown.tsx +45 -13
- package/package.json +1 -1
|
@@ -140,7 +140,7 @@ var verifyRequiredFieldsAreInCatalogConfigFile = async (projectDirectory) => {
|
|
|
140
140
|
var import_os = __toESM(require("os"), 1);
|
|
141
141
|
|
|
142
142
|
// package.json
|
|
143
|
-
var version = "3.44.
|
|
143
|
+
var version = "3.44.2";
|
|
144
144
|
|
|
145
145
|
// src/constants.ts
|
|
146
146
|
var VERSION = version;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
log_build_default
|
|
3
|
-
} from "../chunk-
|
|
4
|
-
import "../chunk-
|
|
3
|
+
} from "../chunk-BLJ5FRR3.js";
|
|
4
|
+
import "../chunk-LIIOK6SZ.js";
|
|
5
5
|
import "../chunk-DAOXTQVS.js";
|
|
6
|
-
import "../chunk-
|
|
6
|
+
import "../chunk-THDZCUFV.js";
|
|
7
7
|
import "../chunk-6QENHZZP.js";
|
|
8
8
|
export {
|
|
9
9
|
log_build_default as default
|
package/dist/constants.cjs
CHANGED
package/dist/constants.js
CHANGED
package/dist/eventcatalog.cjs
CHANGED
|
@@ -144,7 +144,7 @@ var verifyRequiredFieldsAreInCatalogConfigFile = async (projectDirectory) => {
|
|
|
144
144
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
145
145
|
|
|
146
146
|
// package.json
|
|
147
|
-
var version = "3.44.
|
|
147
|
+
var version = "3.44.2";
|
|
148
148
|
|
|
149
149
|
// src/constants.ts
|
|
150
150
|
var VERSION = version;
|
package/dist/eventcatalog.js
CHANGED
|
@@ -13,8 +13,8 @@ import {
|
|
|
13
13
|
} from "./chunk-3H2RT3CM.js";
|
|
14
14
|
import {
|
|
15
15
|
log_build_default
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
16
|
+
} from "./chunk-BLJ5FRR3.js";
|
|
17
|
+
import "./chunk-LIIOK6SZ.js";
|
|
18
18
|
import "./chunk-DAOXTQVS.js";
|
|
19
19
|
import {
|
|
20
20
|
catalogToAstro
|
|
@@ -28,13 +28,13 @@ import {
|
|
|
28
28
|
} from "./chunk-B7HCX5HM.js";
|
|
29
29
|
import {
|
|
30
30
|
generate
|
|
31
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-RUACTEJR.js";
|
|
32
32
|
import {
|
|
33
33
|
logger
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-IU3D7JRW.js";
|
|
35
35
|
import {
|
|
36
36
|
VERSION
|
|
37
|
-
} from "./chunk-
|
|
37
|
+
} from "./chunk-THDZCUFV.js";
|
|
38
38
|
import {
|
|
39
39
|
getEventCatalogConfigFile,
|
|
40
40
|
verifyRequiredFieldsAreInCatalogConfigFile
|
package/dist/generate.cjs
CHANGED
|
@@ -108,7 +108,7 @@ var getEventCatalogConfigFile = async (projectDirectory) => {
|
|
|
108
108
|
var import_picocolors = __toESM(require("picocolors"), 1);
|
|
109
109
|
|
|
110
110
|
// package.json
|
|
111
|
-
var version = "3.44.
|
|
111
|
+
var version = "3.44.2";
|
|
112
112
|
|
|
113
113
|
// src/constants.ts
|
|
114
114
|
var VERSION = version;
|
package/dist/generate.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
generate
|
|
3
|
-
} from "./chunk-
|
|
4
|
-
import "./chunk-
|
|
5
|
-
import "./chunk-
|
|
3
|
+
} from "./chunk-RUACTEJR.js";
|
|
4
|
+
import "./chunk-IU3D7JRW.js";
|
|
5
|
+
import "./chunk-THDZCUFV.js";
|
|
6
6
|
import "./chunk-6QENHZZP.js";
|
|
7
7
|
export {
|
|
8
8
|
generate
|
package/dist/utils/cli-logger.js
CHANGED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { buildEnvironmentUrl, findCurrentEnvironment } from './EnvironmentDropdown';
|
|
3
|
+
|
|
4
|
+
const environments = [
|
|
5
|
+
{
|
|
6
|
+
name: 'Development',
|
|
7
|
+
url: 'https://example.com/event-catalog/dev',
|
|
8
|
+
shortName: 'Dev',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'UAT',
|
|
12
|
+
url: 'https://example.com/event-catalog/uat',
|
|
13
|
+
shortName: 'UAT',
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
name: 'Production',
|
|
17
|
+
url: 'https://example.com/event-catalog/prod',
|
|
18
|
+
shortName: 'Prod',
|
|
19
|
+
},
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
describe('EnvironmentDropdown', () => {
|
|
23
|
+
it('finds the current environment when environments share an origin but use different base paths', () => {
|
|
24
|
+
expect(findCurrentEnvironment(environments, 'https://example.com/event-catalog/uat/services/foo')?.name).toBe('UAT');
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('builds environment urls by replacing the current environment base path', () => {
|
|
28
|
+
expect(
|
|
29
|
+
buildEnvironmentUrl(
|
|
30
|
+
'https://example.com/event-catalog/prod',
|
|
31
|
+
'https://example.com/event-catalog/uat/services/foo',
|
|
32
|
+
'https://example.com/event-catalog/uat'
|
|
33
|
+
)
|
|
34
|
+
).toBe('https://example.com/event-catalog/prod/services/foo');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('preserves search params and hashes when switching environments', () => {
|
|
38
|
+
expect(
|
|
39
|
+
buildEnvironmentUrl(
|
|
40
|
+
'https://example.com/event-catalog/prod',
|
|
41
|
+
'https://example.com/event-catalog/uat/services/foo?tab=messages#latest',
|
|
42
|
+
'https://example.com/event-catalog/uat'
|
|
43
|
+
)
|
|
44
|
+
).toBe('https://example.com/event-catalog/prod/services/foo?tab=messages#latest');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('keeps existing origin based environment switching for root catalogs', () => {
|
|
48
|
+
expect(
|
|
49
|
+
buildEnvironmentUrl('https://prod.example.com', 'https://uat.example.com/services/foo', 'https://uat.example.com')
|
|
50
|
+
).toBe('https://prod.example.com/services/foo');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('switches from a root catalog to a subpath catalog', () => {
|
|
54
|
+
expect(buildEnvironmentUrl('https://example.com/prod', 'https://example.com/services/foo', 'https://example.com')).toBe(
|
|
55
|
+
'https://example.com/prod/services/foo'
|
|
56
|
+
);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('preserves the current path when the current environment is unknown', () => {
|
|
60
|
+
expect(buildEnvironmentUrl('https://example.com/prod', 'http://localhost:3000/services/foo')).toBe(
|
|
61
|
+
'https://example.com/prod/services/foo'
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
});
|
|
@@ -11,20 +11,56 @@ interface EnvironmentDropdownProps {
|
|
|
11
11
|
environments: Environment[];
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
const stripTrailingSlash = (pathname: string) => pathname.replace(/\/$/, '') || '/';
|
|
15
|
+
|
|
16
|
+
const startsWithPath = (pathname: string, basePathname: string) =>
|
|
17
|
+
basePathname === '/' || pathname === basePathname || pathname.startsWith(`${basePathname}/`);
|
|
18
|
+
|
|
19
|
+
export const findCurrentEnvironment = (environments: Environment[], currentHref: string) => {
|
|
20
|
+
const currentUrl = new URL(currentHref);
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
environments
|
|
24
|
+
.filter((env) => {
|
|
25
|
+
const envUrl = new URL(env.url, currentUrl.href);
|
|
26
|
+
const envPathname = stripTrailingSlash(envUrl.pathname);
|
|
27
|
+
|
|
28
|
+
return envUrl.origin === currentUrl.origin && startsWithPath(currentUrl.pathname, envPathname);
|
|
29
|
+
})
|
|
30
|
+
.sort(
|
|
31
|
+
(a, b) =>
|
|
32
|
+
stripTrailingSlash(new URL(b.url, currentUrl.href).pathname).length -
|
|
33
|
+
stripTrailingSlash(new URL(a.url, currentUrl.href).pathname).length
|
|
34
|
+
)[0] || null
|
|
35
|
+
);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
export const buildEnvironmentUrl = (environmentUrl: string, currentHref: string, currentEnvironmentUrl?: string) => {
|
|
39
|
+
const currentUrl = new URL(currentHref);
|
|
40
|
+
const targetUrl = new URL(environmentUrl, currentUrl.href);
|
|
41
|
+
const targetBasePathname = stripTrailingSlash(targetUrl.pathname);
|
|
42
|
+
const currentBasePathname = currentEnvironmentUrl
|
|
43
|
+
? stripTrailingSlash(new URL(currentEnvironmentUrl, currentUrl.href).pathname)
|
|
44
|
+
: undefined;
|
|
45
|
+
const pathWithinEnvironment =
|
|
46
|
+
currentBasePathname && currentBasePathname !== '/' && startsWithPath(currentUrl.pathname, currentBasePathname)
|
|
47
|
+
? currentUrl.pathname.slice(currentBasePathname.length)
|
|
48
|
+
: currentUrl.pathname;
|
|
49
|
+
|
|
50
|
+
targetUrl.pathname = `${targetBasePathname}${pathWithinEnvironment}`.replace(/\/+/g, '/');
|
|
51
|
+
targetUrl.search = currentUrl.search;
|
|
52
|
+
targetUrl.hash = currentUrl.hash;
|
|
53
|
+
|
|
54
|
+
return targetUrl.toString();
|
|
55
|
+
};
|
|
56
|
+
|
|
14
57
|
export const EnvironmentDropdown: React.FC<EnvironmentDropdownProps> = ({ environments }) => {
|
|
15
58
|
const [isOpen, setIsOpen] = useState(false);
|
|
16
59
|
const [currentEnvironment, setCurrentEnvironment] = useState<Environment | null>(null);
|
|
17
60
|
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
18
61
|
|
|
19
62
|
useEffect(() => {
|
|
20
|
-
|
|
21
|
-
const currentUrl = window.location.origin;
|
|
22
|
-
const matchedEnv = environments.find((env) => {
|
|
23
|
-
// Normalize URLs for comparison
|
|
24
|
-
const envUrl = new URL(env.url).origin;
|
|
25
|
-
return envUrl === currentUrl;
|
|
26
|
-
});
|
|
27
|
-
setCurrentEnvironment(matchedEnv || null);
|
|
63
|
+
setCurrentEnvironment(findCurrentEnvironment(environments, window.location.href));
|
|
28
64
|
}, [environments]);
|
|
29
65
|
|
|
30
66
|
useEffect(() => {
|
|
@@ -99,11 +135,7 @@ export const EnvironmentDropdown: React.FC<EnvironmentDropdownProps> = ({ enviro
|
|
|
99
135
|
href={env.url}
|
|
100
136
|
onClick={(e) => {
|
|
101
137
|
e.preventDefault();
|
|
102
|
-
|
|
103
|
-
const currentPath = window.location.pathname + window.location.search + window.location.hash;
|
|
104
|
-
const targetUrl = new URL(env.url);
|
|
105
|
-
targetUrl.pathname = currentPath;
|
|
106
|
-
window.location.href = targetUrl.toString();
|
|
138
|
+
window.location.href = buildEnvironmentUrl(env.url, window.location.href, currentEnvironment?.url);
|
|
107
139
|
}}
|
|
108
140
|
className={`block rounded-xl px-3 py-3 transition-colors ${
|
|
109
141
|
isCurrentEnv
|