@gravitee/gamma-modules-sdk 1.0.0-alpha.1 → 1.0.0-alpha.1-feat-routing.a38d2fb

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.
@@ -0,0 +1,4 @@
1
+ export type { Environment } from './types';
2
+ export type { IEnvironmentService, UseEnvironmentFn } from './interfaces';
3
+ export { EnvironmentService, environmentService, useEnvironment } from './stubs';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/environment/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAC3C,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC"}
@@ -0,0 +1,11 @@
1
+ import { Environment } from './types';
2
+ export interface IEnvironmentService {
3
+ setEnvironment(env: Environment): void;
4
+ getEnvironment(): Environment | null;
5
+ getEnvironmentId(): string;
6
+ getEnvHrid(): string;
7
+ subscribe(listener: () => void): () => void;
8
+ getSnapshot(): Environment | null;
9
+ }
10
+ export type UseEnvironmentFn = () => Environment | null;
11
+ //# sourceMappingURL=interfaces.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../../src/environment/interfaces.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,MAAM,WAAW,mBAAmB;IAClC,cAAc,CAAC,GAAG,EAAE,WAAW,GAAG,IAAI,CAAC;IACvC,cAAc,IAAI,WAAW,GAAG,IAAI,CAAC;IACrC,gBAAgB,IAAI,MAAM,CAAC;IAC3B,UAAU,IAAI,MAAM,CAAC;IACrB,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;IAC5C,WAAW,IAAI,WAAW,GAAG,IAAI,CAAC;CACnC;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,WAAW,GAAG,IAAI,CAAC"}
@@ -0,0 +1,18 @@
1
+ import { IEnvironmentService, UseEnvironmentFn } from './interfaces';
2
+ import { Environment } from './types';
3
+ /**
4
+ * Stub implementations replaced at runtime by the host via Module Federation
5
+ * (`additionalShared`, singleton). Remotes bundle these for typing and a
6
+ * minimal runtime shape only.
7
+ */
8
+ export declare class EnvironmentService implements IEnvironmentService {
9
+ setEnvironment(_env: Environment): void;
10
+ getEnvironment(): Environment | null;
11
+ getEnvironmentId(): string;
12
+ getEnvHrid(): string;
13
+ subscribe(_listener: () => void): () => void;
14
+ getSnapshot(): Environment | null;
15
+ }
16
+ export declare const environmentService: IEnvironmentService;
17
+ export declare const useEnvironment: UseEnvironmentFn;
18
+ //# sourceMappingURL=stubs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stubs.d.ts","sourceRoot":"","sources":["../../src/environment/stubs.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;;;GAIG;AAEH,qBAAa,kBAAmB,YAAW,mBAAmB;IAC5D,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IACvC,cAAc,IAAI,WAAW,GAAG,IAAI;IAGpC,gBAAgB,IAAI,MAAM;IAG1B,UAAU,IAAI,MAAM;IAGpB,SAAS,CAAC,SAAS,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAG5C,WAAW,IAAI,WAAW,GAAG,IAAI;CAGlC;AAED,eAAO,MAAM,kBAAkB,EAAE,mBAA8C,CAAC;AAEhF,eAAO,MAAM,cAAc,EAAE,gBAA6B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export interface Environment {
2
+ readonly id: string;
3
+ readonly hrids?: string[];
4
+ readonly name?: string;
5
+ readonly description?: string;
6
+ readonly organizationId: string;
7
+ }
8
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/environment/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;CACjC"}
package/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './permissions';
2
+ export * from './environment';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -18,6 +18,23 @@ var e = class {
18
18
  getSnapshot() {
19
19
  return 0;
20
20
  }
21
- }, t = new e(), n = () => !1, r = () => null, i = () => [], a = () => [];
21
+ }, t = new e(), n = () => !1, r = () => null, i = () => [], a = () => [], o = class {
22
+ setEnvironment(e) {}
23
+ getEnvironment() {
24
+ return null;
25
+ }
26
+ getEnvironmentId() {
27
+ return "";
28
+ }
29
+ getEnvHrid() {
30
+ return "";
31
+ }
32
+ subscribe(e) {
33
+ return () => {};
34
+ }
35
+ getSnapshot() {
36
+ return null;
37
+ }
38
+ }, s = new o(), c = () => null;
22
39
  //#endregion
23
- export { r as PermissionGate, e as PermissionService, i as normalizeCrudMapRecord, a as normalizeOrganizationPermissionsFromRoles, t as permissionService, n as useHasPermission };
40
+ export { o as EnvironmentService, r as PermissionGate, e as PermissionService, s as environmentService, i as normalizeCrudMapRecord, a as normalizeOrganizationPermissionsFromRoles, t as permissionService, c as useEnvironment, n as useHasPermission };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Routing domain — generic helpers for federated modules mounted under the
3
+ * gamma host URL scheme `/environments/:envHrid/:moduleId/<routeKey>`.
4
+ */
5
+ export interface ModuleRouteDefinition {
6
+ readonly path: string;
7
+ readonly label: string;
8
+ }
9
+ export interface ModuleRouteConfig<K extends string = string> {
10
+ readonly routeKeys: readonly K[];
11
+ readonly routes: Record<K, ModuleRouteDefinition>;
12
+ readonly defaultRouteKey: K;
13
+ }
14
+ /** Type-guard: is `segment` one of the declared route keys? */
15
+ export declare function isRouteKey<K extends string>(segment: string, routeKeys: readonly K[]): segment is K;
16
+ /**
17
+ * Resolves the active sidebar key and optional host module prefix from the URL.
18
+ *
19
+ * Handles three mounting modes:
20
+ * 1. **Federated** — `/environments/:envHrid/:moduleId/<routeKey>`
21
+ * 2. **Standalone with prefix** — `/:moduleId/<routeKey>`
22
+ * 3. **Legacy standalone** — `/<routeKey>` (first segment is itself a key)
23
+ */
24
+ export declare function resolveModulePath<K extends string>(pathname: string, config: ModuleRouteConfig<K>): {
25
+ modulePrefix: string;
26
+ activeNavKey: K;
27
+ };
28
+ /**
29
+ * Pure string builder: returns the target pathname for navigating to a route
30
+ * key inside a module.
31
+ *
32
+ * When federated, the environment prefix is extracted from `currentPathname`.
33
+ */
34
+ export declare function buildModuleNavPath(modulePrefix: string, key: string, currentPathname?: string): string;
35
+ /**
36
+ * Returns the "root" pathname for breadcrumbs (e.g. the module's landing page
37
+ * under the current environment).
38
+ */
39
+ export declare function buildModuleRootPath(pathname: string, modulePrefix: string, defaultRouteKey: string): string;
40
+ export interface ModuleRoutingResult<K extends string = string> {
41
+ modulePrefix: string;
42
+ activeNavKey: K;
43
+ navigateToKey: (key: string) => void;
44
+ rootPath: string;
45
+ }
46
+ /**
47
+ * Convenience hook that composes the pure routing helpers for a federated module.
48
+ *
49
+ * Returns raw data — no JSX, no graphene types. Modules use the returned values
50
+ * to wire graphene layout components in their own `ModuleLayout`.
51
+ */
52
+ export declare function useModuleRouting<K extends string>(config: ModuleRouteConfig<K>): ModuleRoutingResult<K>;
53
+ //# sourceMappingURL=routing.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../src/routing.ts"],"names":[],"mappings":"AAkBA;;;GAGG;AAIH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC1D,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC,EAAE,CAAC;IACjC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,qBAAqB,CAAC,CAAC;IAClD,QAAQ,CAAC,eAAe,EAAE,CAAC,CAAC;CAC7B;AAID,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,CAAC,EAAE,GAAG,OAAO,IAAI,CAAC,CAEnG;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAC3B;IAAE,YAAY,EAAE,MAAM,CAAC;IAAC,YAAY,EAAE,CAAC,CAAA;CAAE,CAqB3C;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM,CAUtG;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,MAAM,CAS3G;AAID,MAAM,WAAW,mBAAmB,CAAC,CAAC,SAAS,MAAM,GAAG,MAAM;IAC5D,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,CAAC,CAAC;IAChB,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,iBAAiB,CAAC,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,CAsBvG"}
@@ -0,0 +1,62 @@
1
+ import { useCallback as e, useMemo as t } from "react";
2
+ import { useLocation as n, useNavigate as r } from "react-router-dom";
3
+ //#region src/routing.ts
4
+ function i(e, t) {
5
+ return t.includes(e);
6
+ }
7
+ function a(e, t) {
8
+ let n = e.split("/").filter(Boolean), { routeKeys: r, defaultRouteKey: a } = t;
9
+ if (n.length === 0) return {
10
+ modulePrefix: "",
11
+ activeNavKey: a
12
+ };
13
+ if (n[0] === "environments" && n.length >= 3) {
14
+ let e = n[2], t = n[3] ?? a;
15
+ return {
16
+ modulePrefix: e,
17
+ activeNavKey: i(t, r) ? t : a
18
+ };
19
+ }
20
+ if (i(n[0], r)) return {
21
+ modulePrefix: "",
22
+ activeNavKey: n[0]
23
+ };
24
+ let o = n[0], s = n[1] ?? a;
25
+ return {
26
+ modulePrefix: o,
27
+ activeNavKey: i(s, r) ? s : a
28
+ };
29
+ }
30
+ function o(e, t, n) {
31
+ if (e) {
32
+ let r = n ?? (typeof window < "u" ? window.location.pathname : ""), i = r.indexOf("/", 14);
33
+ return r.startsWith("/environments/") && i > 0 ? `${r.slice(0, i)}/${e}/${t}` : `/${e}/${t}`;
34
+ }
35
+ return `/${t}`;
36
+ }
37
+ function s(e, t, n) {
38
+ if (!t) return "/";
39
+ let r = e.indexOf("/", 14);
40
+ return e.startsWith("/environments/") && r > 0 ? `${e.slice(0, r)}/${t}/${n}` : `/${t}/${n}`;
41
+ }
42
+ function c(i) {
43
+ let c = n(), l = r(), { modulePrefix: u, activeNavKey: d } = t(() => a(c.pathname, i), [c.pathname, i]), f = t(() => s(c.pathname, u, i.defaultRouteKey), [
44
+ c.pathname,
45
+ u,
46
+ i.defaultRouteKey
47
+ ]);
48
+ return {
49
+ modulePrefix: u,
50
+ activeNavKey: d,
51
+ navigateToKey: e((e) => {
52
+ l(o(u, e, c.pathname));
53
+ }, [
54
+ l,
55
+ u,
56
+ c.pathname
57
+ ]),
58
+ rootPath: f
59
+ };
60
+ }
61
+ //#endregion
62
+ export { o as buildModuleNavPath, s as buildModuleRootPath, i as isRouteKey, a as resolveModulePath, c as useModuleRouting };
package/dist/types.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export type { IPermissionService, NormalizeCrudMapRecordFn, NormalizeOrgPermissionsFn, PermissionGateFn, PermissionGateProps, UseHasPermissionFn, UseHasPermissionOptions, } from './permissions/interfaces';
2
2
  export type { PermissionCheck, PermissionScope, UserRole } from './permissions/types';
3
+ export type { Environment } from './environment/types';
4
+ export type { IEnvironmentService, UseEnvironmentFn } from './environment/interfaces';
3
5
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,wBAAwB,EACxB,yBAAyB,EACzB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,GACxB,MAAM,0BAA0B,CAAC;AAClC,YAAY,EAAE,eAAe,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACtF,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,YAAY,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravitee/gamma-modules-sdk",
3
- "version": "1.0.0-alpha.1",
3
+ "version": "1.0.0-alpha.1-feat-routing.a38d2fb",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "packageManager": "yarn@4.13.0",
@@ -19,6 +19,10 @@
19
19
  },
20
20
  "./types": {
21
21
  "types": "./dist/types.d.ts"
22
+ },
23
+ "./routing": {
24
+ "types": "./dist/routing.d.ts",
25
+ "import": "./dist/routing.js"
22
26
  }
23
27
  },
24
28
  "scripts": {
@@ -28,12 +32,14 @@
28
32
  "lint:fix:all": "yarn lint:fix && yarn format",
29
33
  "typecheck": "tsc --noEmit",
30
34
  "format": "prettier --write .",
35
+ "test": "vitest run",
31
36
  "format:check": "prettier --check .",
32
37
  "prepare": "husky"
33
38
  },
34
39
  "peerDependencies": {
35
40
  "react": ">=19",
36
- "react-dom": ">=19"
41
+ "react-dom": ">=19",
42
+ "react-router-dom": ">=6"
37
43
  },
38
44
  "devDependencies": {
39
45
  "@commitlint/cli": "20.5.0",
@@ -60,11 +66,13 @@
60
66
  "prettier": "3.8.3",
61
67
  "react": "19.2.5",
62
68
  "react-dom": "19.2.5",
69
+ "react-router-dom": "7.6.1",
63
70
  "semantic-release": "25.0.3",
64
71
  "typescript": "6.0.3",
65
72
  "typescript-eslint": "8.58.2",
66
73
  "vite": "8.0.8",
67
- "vite-plugin-dts": "4.5.4"
74
+ "vite-plugin-dts": "4.5.4",
75
+ "vitest": "3.2.1"
68
76
  },
69
77
  "lint-staged": {
70
78
  "*.{ts,tsx}": [