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

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/README.md CHANGED
@@ -27,12 +27,13 @@ In GitHub, set the **default branch** to `alpha` while you are in this phase so
27
27
 
28
28
  ## Architecture
29
29
 
30
- The SDK publishes two entry points:
30
+ The SDK publishes three entry points:
31
31
 
32
32
  | Entry point | Contents | Used by |
33
33
  | ----------------------------------- | ---------------------------- | ------------------------- |
34
34
  | `@gravitee/gamma-modules-sdk` | Types + runtime stubs | Remotes (and host barrel) |
35
35
  | `@gravitee/gamma-modules-sdk/types` | Interfaces only (no runtime) | Host implementation |
36
+ | `@gravitee/gamma-modules-sdk/mock` | OpenAPI mock middleware | Module dev servers |
36
37
 
37
38
  Remote modules compile and bundle against the stubs. At runtime, the host provides its real implementation as a Module Federation singleton (`additionalShared`), replacing the stubs transparently.
38
39
 
@@ -88,6 +89,55 @@ resolve: {
88
89
 
89
90
  ## Exports
90
91
 
92
+ ### Mock middleware (`/mock`)
93
+
94
+ OpenAPI-based mock middleware for standalone dev mode. Reads OpenAPI specs and serves mock responses from fixture files, so modules can run without a backend.
95
+
96
+ ```typescript
97
+ import { createOpenApiMockMiddleware } from '@gravitee/gamma-modules-sdk/mock';
98
+
99
+ // In rsbuild.config.ts setupMiddlewares:
100
+ createOpenApiMockMiddleware({
101
+ moduleId: 'aim',
102
+ specs: [join(__dirname, 'src/main/resources/openapi/openapi-catalog.yaml')],
103
+ fixturesDir: join(__dirname, 'src/main/resources/catalog-fixtures'),
104
+ });
105
+ ```
106
+
107
+ Handles GET list (pagination, `?q=` search), GET by ID, sub-resource filtering, POST, PUT, DELETE, and the `/gamma/ui/bootstrap` endpoint.
108
+
109
+ Fixture files are named after the last path segment in the spec (e.g. `models.json`, `mcp-servers.json`).
110
+
111
+ #### Setting up standalone dev mode for a new module
112
+
113
+ 1. Add `public/constants.json` with `{ "gammaBaseURL": "/gamma" }`
114
+ 2. Write your OpenAPI spec (or copy from an existing module)
115
+ 3. Add fixture JSON files matching your spec paths (e.g. `models.json` for `/catalog/models`)
116
+ 4. In `rsbuild.config.ts`:
117
+
118
+ ```typescript
119
+ import { createOpenApiMockMiddleware } from '@gravitee/gamma-modules-sdk/mock';
120
+
121
+ export default defineConfig(() => ({
122
+ dev: {
123
+ setupMiddlewares: [
124
+ (middlewares) => {
125
+ middlewares.unshift(
126
+ createOpenApiMockMiddleware({
127
+ moduleId: 'your-module',
128
+ specs: [join(__dirname, 'path/to/openapi.yaml')],
129
+ fixturesDir: join(__dirname, 'path/to/fixtures'),
130
+ }),
131
+ );
132
+ return middlewares;
133
+ },
134
+ ],
135
+ },
136
+ }));
137
+ ```
138
+
139
+ 5. Run `yarn serve` and open http://localhost:3002
140
+
91
141
  ### Permissions domain
92
142
 
93
143
  **Types**: `PermissionScope`, `PermissionCheck`, `UserRole`, `PermissionGateProps`, `UseHasPermissionOptions`
package/dist/mock.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import { IncomingMessage, ServerResponse } from 'http';
2
+ export interface OpenApiMockOptions {
3
+ /** Gamma module identifier (e.g. "aim"). */
4
+ moduleId: string;
5
+ /** Paths to OpenAPI spec files (YAML or JSON). */
6
+ specs: string[];
7
+ /** Optional directory with fixture JSON files named after the last path segment (e.g. models.json). */
8
+ fixturesDir?: string;
9
+ orgId?: string;
10
+ envId?: string;
11
+ }
12
+ /**
13
+ * Creates a Connect-compatible middleware that reads OpenAPI specs and serves
14
+ * mock responses for all declared paths. Fixtures override spec examples.
15
+ *
16
+ * Usage in rsbuild.config.ts:
17
+ * ```ts
18
+ * import { createOpenApiMockMiddleware } from '@gravitee/gamma-modules-sdk/mock';
19
+ *
20
+ * setupMiddlewares: [(mw) => mw.unshift(createOpenApiMockMiddleware({
21
+ * moduleId: 'aim',
22
+ * specs: [join(__dirname, 'src/main/resources/openapi/openapi-catalog.yaml')],
23
+ * fixturesDir: join(__dirname, 'src/main/resources/catalog-fixtures'),
24
+ * }))]
25
+ * ```
26
+ */
27
+ export declare function createOpenApiMockMiddleware(options: OpenApiMockOptions): (req: IncomingMessage, res: ServerResponse, next: () => void) => void;
28
+ //# sourceMappingURL=mock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mock.d.ts","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,MAAM,CAAC;AAM5D,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,CAAC;IACjB,kDAAkD;IAClD,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,uGAAuG;IACvG,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,kBAAkB,IAM7D,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,MAAM,IAAI,UAkFpE"}