@congruent-stack/congruent-api-express 0.6.0 → 0.7.0

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/index.cjs CHANGED
@@ -5,22 +5,26 @@ var congruentApi = require('@congruent-stack/congruent-api');
5
5
  function createExpressRegistry(app, diContainer, apiContract) {
6
6
  const registry = congruentApi.createRegistry(diContainer, apiContract, {
7
7
  handlerRegisteredCallback: (entry) => {
8
- console.log("Registering Express route:", entry.methodEndpoint.genericPath);
9
8
  const { genericPath } = entry.methodEndpoint;
10
9
  const method = entry.methodEndpoint.method.toLowerCase();
11
10
  app[method](genericPath, async (req, res) => {
12
11
  req.pathParams = req.params;
13
12
  const result = await entry.trigger(req);
14
- res.status(result.code).json(result.body);
13
+ const resultHeaders = new Map(
14
+ Object.entries(result.headers || {})
15
+ );
16
+ res.status(result.code).setHeaders(resultHeaders).json(result.body);
15
17
  });
16
18
  },
17
19
  middlewareHandlerRegisteredCallback: (entry) => {
18
- console.log("Registering Express middleware:", entry.genericPath);
19
20
  app.use(entry.genericPath, async (req, res, next) => {
20
21
  req.pathParams = req.params;
21
- const haltResponse = await entry.trigger(req, next);
22
- if (haltResponse && congruentApi.isHttpResponseObject(haltResponse)) {
23
- res.status(haltResponse.code).json(haltResponse.body);
22
+ const haltResult = await entry.trigger(req, next);
23
+ if (haltResult && congruentApi.isHttpResponseObject(haltResult)) {
24
+ const haltResultHeaders = new Map(
25
+ Object.entries(haltResult.headers || {})
26
+ );
27
+ res.status(haltResult.code).setHeaders(haltResultHeaders).json(haltResult.body);
24
28
  }
25
29
  });
26
30
  }
package/dist/index.mjs CHANGED
@@ -3,22 +3,26 @@ import { createRegistry, isHttpResponseObject } from '@congruent-stack/congruent
3
3
  function createExpressRegistry(app, diContainer, apiContract) {
4
4
  const registry = createRegistry(diContainer, apiContract, {
5
5
  handlerRegisteredCallback: (entry) => {
6
- console.log("Registering Express route:", entry.methodEndpoint.genericPath);
7
6
  const { genericPath } = entry.methodEndpoint;
8
7
  const method = entry.methodEndpoint.method.toLowerCase();
9
8
  app[method](genericPath, async (req, res) => {
10
9
  req.pathParams = req.params;
11
10
  const result = await entry.trigger(req);
12
- res.status(result.code).json(result.body);
11
+ const resultHeaders = new Map(
12
+ Object.entries(result.headers || {})
13
+ );
14
+ res.status(result.code).setHeaders(resultHeaders).json(result.body);
13
15
  });
14
16
  },
15
17
  middlewareHandlerRegisteredCallback: (entry) => {
16
- console.log("Registering Express middleware:", entry.genericPath);
17
18
  app.use(entry.genericPath, async (req, res, next) => {
18
19
  req.pathParams = req.params;
19
- const haltResponse = await entry.trigger(req, next);
20
- if (haltResponse && isHttpResponseObject(haltResponse)) {
21
- res.status(haltResponse.code).json(haltResponse.body);
20
+ const haltResult = await entry.trigger(req, next);
21
+ if (haltResult && isHttpResponseObject(haltResult)) {
22
+ const haltResultHeaders = new Map(
23
+ Object.entries(haltResult.headers || {})
24
+ );
25
+ res.status(haltResult.code).setHeaders(haltResultHeaders).json(haltResult.body);
22
26
  }
23
27
  });
24
28
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@congruent-stack/congruent-api-express",
3
3
  "type": "module",
4
- "version": "0.6.0",
4
+ "version": "0.7.0",
5
5
  "description": "Typescript schema-first tooling for agnostic REST APIs.",
6
6
  "keywords": [],
7
7
  "author": "congruent-stack",
@@ -22,7 +22,7 @@
22
22
  "peerDependencies": {
23
23
  "@types/express": "5.0.3",
24
24
  "express": "5.1.0",
25
- "@congruent-stack/congruent-api": "0.6.0"
25
+ "@congruent-stack/congruent-api": "0.7.0"
26
26
  },
27
27
  "devDependencies": {
28
28
  "@types/express": "5.0.3",