@gravitee/gamma-modules-sdk 1.0.0-alpha.2 → 1.0.0-alpha.2-feat-dev-mock-middleware.c567ce0

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/dev.d.ts ADDED
@@ -0,0 +1,36 @@
1
+ import { IncomingMessage, ServerResponse } from 'http';
2
+ export interface DevMockMiddlewareOptions {
3
+ /** Gamma module identifier (e.g. "aim"). */
4
+ moduleId: string;
5
+ /** Absolute path to the directory containing fixture JSON files. */
6
+ fixturesDir: string;
7
+ /**
8
+ * Map of route suffixes to fixture file names.
9
+ * The key is the path after `/catalog` (e.g. "/models"), the value is the fixture filename.
10
+ */
11
+ routes: Record<string, string>;
12
+ /** Organization ID for the mock context. Defaults to "DEFAULT". */
13
+ orgId?: string;
14
+ /** Environment ID for the mock context. Defaults to "DEFAULT". */
15
+ envId?: string;
16
+ }
17
+ /**
18
+ * Creates a Connect-compatible middleware that mocks the Gamma bootstrap endpoint
19
+ * and serves fixture data for catalog-style APIs. Intended for standalone dev mode
20
+ * (`rsbuild dev` / `vite dev`) so modules can run without a backend.
21
+ *
22
+ * Usage in rsbuild.config.ts:
23
+ * ```ts
24
+ * import { createDevMockMiddleware } from '@gravitee/gamma-modules-sdk/dev';
25
+ *
26
+ * setupMiddlewares: [(mw) => mw.unshift(createDevMockMiddleware({
27
+ * moduleId: 'aim',
28
+ * fixturesDir: join(__dirname, 'src/main/resources/catalog-fixtures'),
29
+ * routes: { '/models': 'models.json', '/mcp-servers': 'mcp-servers.json' },
30
+ * }))]
31
+ * ```
32
+ *
33
+ * Requires a `public/constants.json` with `{ "gammaBaseURL": "/gamma" }` in the module root.
34
+ */
35
+ export declare function createDevMockMiddleware(options: DevMockMiddlewareOptions): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
36
+ //# sourceMappingURL=dev.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dev.d.ts","sourceRoot":"","sources":["../src/dev.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAG5D,MAAM,WAAW,wBAAwB;IACvC,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,oEAAoE;IACpE,WAAW,EAAE,MAAM,CAAC;IACpB;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,mEAAmE;IACnE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAeD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,wBAAwB,IAI/D,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,MAAM,IAAI,UAsDpE"}
package/dist/dev.js ADDED
@@ -0,0 +1,53 @@
1
+ import { readFileSync as e } from "fs";
2
+ import { join as t } from "path";
3
+ //#region src/dev.ts
4
+ function n(e, t, n = 200) {
5
+ e.writeHead(n, { "Content-Type": "application/json" }), e.end(JSON.stringify(t));
6
+ }
7
+ function r(n, r) {
8
+ try {
9
+ return JSON.parse(e(t(n, r), "utf-8"));
10
+ } catch {
11
+ return [];
12
+ }
13
+ }
14
+ function i(e) {
15
+ let { moduleId: t, fixturesDir: i, routes: a, orgId: o = "DEFAULT", envId: s = "DEFAULT" } = e, c = `/gamma/organizations/${o}/environments/${s}/modules/${t}/catalog`;
16
+ return (e, t, s) => {
17
+ let { pathname: l, searchParams: u } = new URL(e.url ?? "/", `http://${e.headers.host}`);
18
+ if (l === "/gamma/ui/bootstrap") {
19
+ n(t, {
20
+ gammaBaseURL: "/gamma",
21
+ organizationId: o
22
+ });
23
+ return;
24
+ }
25
+ if (!l.startsWith(c)) {
26
+ s();
27
+ return;
28
+ }
29
+ let d = l.slice(c.length), f = a[d];
30
+ if (f) {
31
+ let e = Number(u.get("page")) || 1, a = Number(u.get("perPage")) || 25, o = (u.get("q") ?? "").trim().toLowerCase(), s = r(i, f);
32
+ o && (s = s.filter((e) => JSON.stringify(e.definition ?? e).toLowerCase().includes(o)));
33
+ let c = (e - 1) * a;
34
+ n(t, {
35
+ data: s.slice(c, c + a),
36
+ pagination: {
37
+ page: e,
38
+ perPage: a,
39
+ totalCount: s.length
40
+ }
41
+ });
42
+ return;
43
+ }
44
+ for (let [e, o] of Object.entries(a)) if (d.startsWith(e + "/")) {
45
+ let a = d.slice(e.length + 1), s = r(i, o).find((e) => e.id === a);
46
+ s ? n(t, s) : n(t, { error: "Not found" }, 404);
47
+ return;
48
+ }
49
+ n(t, { error: "Not found" }, 404);
50
+ };
51
+ }
52
+ //#endregion
53
+ export { i as createDevMockMiddleware };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gravitee/gamma-modules-sdk",
3
- "version": "1.0.0-alpha.2",
3
+ "version": "1.0.0-alpha.2-feat-dev-mock-middleware.c567ce0",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "packageManager": "yarn@4.13.0",
@@ -23,6 +23,10 @@
23
23
  "./routing": {
24
24
  "types": "./dist/routing.d.ts",
25
25
  "import": "./dist/routing.js"
26
+ },
27
+ "./dev": {
28
+ "types": "./dist/dev.d.ts",
29
+ "import": "./dist/dev.js"
26
30
  }
27
31
  },
28
32
  "scripts": {
@@ -50,6 +54,7 @@
50
54
  "@semantic-release/github": "12.0.6",
51
55
  "@semantic-release/npm": "13.1.5",
52
56
  "@semantic-release/release-notes-generator": "14.1.0",
57
+ "@types/node": "25.6.0",
53
58
  "@types/react": "19.2.14",
54
59
  "@types/react-dom": "19.2.3",
55
60
  "@vitejs/plugin-react": "6.0.1",