@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.
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(analytics_exports);
36
36
  var import_os = __toESM(require("os"), 1);
37
37
 
38
38
  // package.json
39
- var version = "3.44.1";
39
+ var version = "3.44.2";
40
40
 
41
41
  // src/constants.ts
42
42
  var VERSION = version;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  raiseEvent
3
- } from "../chunk-MFLSPCEA.js";
4
- import "../chunk-EPDZMVQ3.js";
3
+ } from "../chunk-LIIOK6SZ.js";
4
+ import "../chunk-THDZCUFV.js";
5
5
  export {
6
6
  raiseEvent
7
7
  };
@@ -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.1";
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-DKKPJ3QM.js";
4
- import "../chunk-MFLSPCEA.js";
3
+ } from "../chunk-BLJ5FRR3.js";
4
+ import "../chunk-LIIOK6SZ.js";
5
5
  import "../chunk-DAOXTQVS.js";
6
- import "../chunk-EPDZMVQ3.js";
6
+ import "../chunk-THDZCUFV.js";
7
7
  import "../chunk-6QENHZZP.js";
8
8
  export {
9
9
  log_build_default as default
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  raiseEvent
3
- } from "./chunk-MFLSPCEA.js";
3
+ } from "./chunk-LIIOK6SZ.js";
4
4
  import {
5
5
  countResources,
6
6
  serializeCounts
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  VERSION
3
- } from "./chunk-EPDZMVQ3.js";
3
+ } from "./chunk-THDZCUFV.js";
4
4
 
5
5
  // src/utils/cli-logger.ts
6
6
  import pc from "picocolors";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  VERSION
3
- } from "./chunk-EPDZMVQ3.js";
3
+ } from "./chunk-THDZCUFV.js";
4
4
 
5
5
  // src/analytics/analytics.js
6
6
  import os from "os";
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  logger
3
- } from "./chunk-L26L4Y5J.js";
3
+ } from "./chunk-IU3D7JRW.js";
4
4
  import {
5
5
  cleanup,
6
6
  getEventCatalogConfigFile
@@ -1,5 +1,5 @@
1
1
  // package.json
2
- var version = "3.44.1";
2
+ var version = "3.44.2";
3
3
 
4
4
  // src/constants.ts
5
5
  var VERSION = version;
@@ -25,7 +25,7 @@ __export(constants_exports, {
25
25
  module.exports = __toCommonJS(constants_exports);
26
26
 
27
27
  // package.json
28
- var version = "3.44.1";
28
+ var version = "3.44.2";
29
29
 
30
30
  // src/constants.ts
31
31
  var VERSION = version;
package/dist/constants.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  VERSION
3
- } from "./chunk-EPDZMVQ3.js";
3
+ } from "./chunk-THDZCUFV.js";
4
4
  export {
5
5
  VERSION
6
6
  };
@@ -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.1";
147
+ var version = "3.44.2";
148
148
 
149
149
  // src/constants.ts
150
150
  var VERSION = version;
@@ -13,8 +13,8 @@ import {
13
13
  } from "./chunk-3H2RT3CM.js";
14
14
  import {
15
15
  log_build_default
16
- } from "./chunk-DKKPJ3QM.js";
17
- import "./chunk-MFLSPCEA.js";
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-3UVY6YHH.js";
31
+ } from "./chunk-RUACTEJR.js";
32
32
  import {
33
33
  logger
34
- } from "./chunk-L26L4Y5J.js";
34
+ } from "./chunk-IU3D7JRW.js";
35
35
  import {
36
36
  VERSION
37
- } from "./chunk-EPDZMVQ3.js";
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.1";
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-3UVY6YHH.js";
4
- import "./chunk-L26L4Y5J.js";
5
- import "./chunk-EPDZMVQ3.js";
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
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(cli_logger_exports);
36
36
  var import_picocolors = __toESM(require("picocolors"), 1);
37
37
 
38
38
  // package.json
39
- var version = "3.44.1";
39
+ var version = "3.44.2";
40
40
 
41
41
  // src/constants.ts
42
42
  var VERSION = version;
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  logger
3
- } from "../chunk-L26L4Y5J.js";
4
- import "../chunk-EPDZMVQ3.js";
3
+ } from "../chunk-IU3D7JRW.js";
4
+ import "../chunk-THDZCUFV.js";
5
5
  export {
6
6
  logger
7
7
  };
@@ -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
- // Check if current URL matches any environment
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
- // Construct the full URL with the current path when clicked
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
package/package.json CHANGED
@@ -7,7 +7,7 @@
7
7
  },
8
8
  "license": "SEE LICENSE IN LICENSE",
9
9
  "type": "module",
10
- "version": "3.44.1",
10
+ "version": "3.44.2",
11
11
  "publishConfig": {
12
12
  "access": "public"
13
13
  },