@openapi-typescript-infra/service 4.23.0 → 4.23.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.
Files changed (44) hide show
  1. package/build/bootstrap.d.ts +0 -2
  2. package/build/bootstrap.js +1 -2
  3. package/build/bootstrap.js.map +1 -1
  4. package/build/config/index.js +2 -3
  5. package/build/config/index.js.map +1 -1
  6. package/build/config/shortstops.js +1 -2
  7. package/build/config/shortstops.js.map +1 -1
  8. package/build/config/validation.js +1 -2
  9. package/build/config/validation.js.map +1 -1
  10. package/build/development/port-finder.js +1 -2
  11. package/build/development/port-finder.js.map +1 -1
  12. package/build/development/repl.js +1 -2
  13. package/build/development/repl.js.map +1 -1
  14. package/build/env.js +5 -6
  15. package/build/env.js.map +1 -1
  16. package/build/express-app/app.d.ts +0 -2
  17. package/build/express-app/app.js +3 -4
  18. package/build/express-app/app.js.map +1 -1
  19. package/build/express-app/internal-server.js +1 -2
  20. package/build/express-app/internal-server.js.map +1 -1
  21. package/build/express-app/modules.js +2 -3
  22. package/build/express-app/modules.js.map +1 -1
  23. package/build/express-app/route-loader.js +1 -2
  24. package/build/express-app/route-loader.js.map +1 -1
  25. package/build/hook.js +1 -2
  26. package/build/hook.js.map +1 -1
  27. package/build/openapi.js +65 -62
  28. package/build/openapi.js.map +1 -1
  29. package/build/telemetry/DummyExporter.d.ts +3 -4
  30. package/build/telemetry/DummyExporter.js +5 -6
  31. package/build/telemetry/DummyExporter.js.map +1 -1
  32. package/build/telemetry/index.d.ts +0 -2
  33. package/build/telemetry/index.js +4 -5
  34. package/build/telemetry/index.js.map +1 -1
  35. package/build/telemetry/instrumentations.js +2 -3
  36. package/build/telemetry/instrumentations.js.map +1 -1
  37. package/build/telemetry/requestLogger.d.ts +1 -2
  38. package/build/telemetry/requestLogger.js +3 -4
  39. package/build/telemetry/requestLogger.js.map +1 -1
  40. package/build/tsconfig.build.tsbuildinfo +1 -1
  41. package/build/types.d.ts +0 -4
  42. package/package.json +12 -12
  43. package/src/openapi.ts +60 -58
  44. package/src/telemetry/DummyExporter.ts +9 -11
package/build/types.d.ts CHANGED
@@ -1,7 +1,3 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
- /// <reference types="cookie-parser" />
4
- /// <reference types="node" />
5
1
  import type { Server } from 'http';
6
2
  import type { REPLServer } from 'repl';
7
3
  import type pino from 'pino';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openapi-typescript-infra/service",
3
- "version": "4.23.0",
3
+ "version": "4.23.2",
4
4
  "description": "An opinionated framework for building configuration driven services - web, api, or ob. Uses OpenAPI, pino logging, express, confit, Typescript and vitest.",
5
5
  "main": "build/index.js",
6
6
  "scripts": {
@@ -60,12 +60,12 @@
60
60
  "dependencies": {
61
61
  "@godaddy/terminus": "^4.12.1",
62
62
  "@opentelemetry/api": "^1.9.0",
63
- "@opentelemetry/exporter-prometheus": "^0.52.0",
63
+ "@opentelemetry/exporter-prometheus": "^0.52.1",
64
64
  "@opentelemetry/instrumentation-dns": "^0.37.0",
65
65
  "@opentelemetry/instrumentation-express": "^0.40.1",
66
66
  "@opentelemetry/instrumentation-generic-pool": "^0.37.0",
67
67
  "@opentelemetry/instrumentation-graphql": "^0.41.0",
68
- "@opentelemetry/instrumentation-http": "^0.52.0",
68
+ "@opentelemetry/instrumentation-http": "^0.52.1",
69
69
  "@opentelemetry/instrumentation-ioredis": "^0.41.0",
70
70
  "@opentelemetry/instrumentation-net": "^0.37.0",
71
71
  "@opentelemetry/instrumentation-pg": "^0.42.0",
@@ -73,8 +73,8 @@
73
73
  "@opentelemetry/instrumentation-undici": "^0.3.0",
74
74
  "@opentelemetry/resource-detector-container": "^0.3.11",
75
75
  "@opentelemetry/resource-detector-gcp": "^0.29.10",
76
- "@opentelemetry/sdk-node": "^0.52.0",
77
- "@opentelemetry/semantic-conventions": "^1.25.0",
76
+ "@opentelemetry/sdk-node": "^0.52.1",
77
+ "@opentelemetry/semantic-conventions": "^1.25.1",
78
78
  "@sesamecare-oss/confit": "^2.2.1",
79
79
  "@sesamecare-oss/opentelemetry-node-metrics": "^1.0.1",
80
80
  "ajv": "^8.16.0",
@@ -85,7 +85,7 @@
85
85
  "glob": "^8.1.0",
86
86
  "lodash": "^4.17.21",
87
87
  "minimist": "^1.2.8",
88
- "pino": "^9.1.0",
88
+ "pino": "^9.3.2",
89
89
  "read-pkg-up": "^7.0.1",
90
90
  "request-ip": "^3.3.0"
91
91
  },
@@ -95,14 +95,14 @@
95
95
  "@openapi-typescript-infra/coconfig": "^4.4.0",
96
96
  "@semantic-release/commit-analyzer": "^13.0.0",
97
97
  "@semantic-release/exec": "^6.0.3",
98
- "@semantic-release/github": "^10.0.6",
99
- "@semantic-release/release-notes-generator": "^14.0.0",
98
+ "@semantic-release/github": "^10.1.3",
99
+ "@semantic-release/release-notes-generator": "^14.0.1",
100
100
  "@types/cookie-parser": "^1.4.7",
101
101
  "@types/express": "^4.17.21",
102
102
  "@types/glob": "^8.1.0",
103
- "@types/lodash": "^4.17.5",
103
+ "@types/lodash": "^4.17.7",
104
104
  "@types/minimist": "^1.2.5",
105
- "@types/node": "^20.14.2",
105
+ "@types/node": "^20.14.14",
106
106
  "@types/request-ip": "^0.0.41",
107
107
  "@types/supertest": "^6.0.2",
108
108
  "@typescript-eslint/eslint-plugin": "^6.21.0",
@@ -111,12 +111,12 @@
111
111
  "eslint": "^8.57.0",
112
112
  "eslint-config-prettier": "^9.1.0",
113
113
  "eslint-plugin-import": "^2.29.1",
114
- "pino-pretty": "^11.2.0",
114
+ "pino-pretty": "^11.2.2",
115
115
  "pinst": "^3.0.0",
116
116
  "supertest": "^7.0.0",
117
117
  "ts-node": "^10.9.2",
118
118
  "tsconfig-paths": "^4.2.0",
119
- "typescript": "^5.4.5",
119
+ "typescript": "^5.5.4",
120
120
  "vitest": "^1.6.0"
121
121
  },
122
122
  "resolutions": {
package/src/openapi.ts CHANGED
@@ -74,65 +74,62 @@ export async function openApi<
74
74
  delete (global as { window: unknown }).window;
75
75
  }
76
76
 
77
- app.locals.openApiSpecification = await new OpenAPIFramework({ apiDoc: apiSpec })
78
- .initialize({ visitApi() {} })
79
- .then((docs) => docs.apiDoc)
80
- .catch((error) => {
81
- app.locals.logger.error(error, 'Failed to parse and load OpenAPI spec');
82
- });
83
-
84
- if (_window) {
85
- (global as { window: unknown }).window = _window;
86
- };
77
+ try {
78
+ app.locals.openApiSpecification = await new OpenAPIFramework({ apiDoc: apiSpec })
79
+ .initialize({ visitApi() { } })
80
+ .then((docs) => docs.apiDoc)
81
+ .catch((error) => {
82
+ app.locals.logger.error(error, 'Failed to parse and load OpenAPI spec');
83
+ });
87
84
 
88
- const defaultOptions: OAPIOpts = {
89
- apiSpec: app.locals.openApiSpecification,
90
- ignoreUndocumented: true,
91
- validateRequests: {
92
- allowUnknownQueryParameters: true,
93
- coerceTypes: 'array',
94
- },
95
- operationHandlers: {
96
- basePath,
97
- resolver(
98
- basePath: string,
99
- route: Parameters<typeof OpenApiValidator.resolvers.defaultResolver>[1],
100
- ) {
101
- const pathKey = route.openApiRoute.substring(route.basePath.length);
102
- const modulePath = path.join(basePath, pathKey);
85
+ const defaultOptions: OAPIOpts = {
86
+ apiSpec: app.locals.openApiSpecification,
87
+ ignoreUndocumented: true,
88
+ validateRequests: {
89
+ allowUnknownQueryParameters: true,
90
+ coerceTypes: 'array',
91
+ },
92
+ operationHandlers: {
93
+ basePath,
94
+ resolver(
95
+ basePath: string,
96
+ route: Parameters<typeof OpenApiValidator.resolvers.defaultResolver>[1],
97
+ ) {
98
+ const pathKey = route.openApiRoute.substring(route.basePath.length);
99
+ const modulePath = path.join(basePath, pathKey);
103
100
 
104
- try {
105
- const module = modulesByPath[pathKey];
106
- const method = module
107
- ? Object.keys(module).find((m) => m.toUpperCase() === route.method)
108
- : undefined;
109
- if (!module || !method) {
110
- throw new Error(
111
- `Could not find a [${route.method}] function in ${modulePath} when trying to route [${route.method} ${route.expressRoute}].`,
101
+ try {
102
+ const module = modulesByPath[pathKey];
103
+ const method = module
104
+ ? Object.keys(module).find((m) => m.toUpperCase() === route.method)
105
+ : undefined;
106
+ if (!module || !method) {
107
+ throw new Error(
108
+ `Could not find a [${route.method}] function in ${modulePath} when trying to route [${route.method} ${route.expressRoute}].`,
109
+ );
110
+ }
111
+ return module[method] as RequestHandler;
112
+ } catch (error) {
113
+ app.locals.logger.error(
114
+ {
115
+ error: (error as Error).message,
116
+ pathKey,
117
+ modulePath: path.relative(rootDirectory, modulePath),
118
+ },
119
+ 'Failed to load API method handler',
112
120
  );
121
+ return notImplementedHandler;
113
122
  }
114
- return module[method] as RequestHandler;
115
- } catch (error) {
116
- app.locals.logger.error(
117
- {
118
- error: (error as Error).message,
119
- pathKey,
120
- modulePath: path.relative(rootDirectory, modulePath),
121
- },
122
- 'Failed to load API method handler',
123
- );
124
- return notImplementedHandler;
125
- }
123
+ },
126
124
  },
127
- },
128
- };
125
+ };
129
126
 
130
- const { routing } = app.locals.config;
131
- const combinedOptions = {
132
- // In test mode, validate returned swagger responses. This can easily be disabled
133
- // by setting validateResponses to false in the config.
134
- ...(getNodeEnv() === 'test'
135
- ? {
127
+ const { routing } = app.locals.config;
128
+ const combinedOptions = {
129
+ // In test mode, validate returned swagger responses. This can easily be disabled
130
+ // by setting validateResponses to false in the config.
131
+ ...(getNodeEnv() === 'test'
132
+ ? {
136
133
  validateResponses: {
137
134
  onError(error: Error, body: unknown, req: Request) {
138
135
  console.log('Response body fails validation: ', error);
@@ -142,10 +139,15 @@ export async function openApi<
142
139
  },
143
140
  },
144
141
  }
145
- : {}),
146
- ...(typeof routing.openapi === 'object' ? routing.openapi : {}),
147
- ...openApiOptions,
148
- };
142
+ : {}),
143
+ ...(typeof routing.openapi === 'object' ? routing.openapi : {}),
144
+ ...openApiOptions,
145
+ };
149
146
 
150
- return OpenApiValidator.middleware(_.defaultsDeep(defaultOptions, combinedOptions));
147
+ return OpenApiValidator.middleware(_.defaultsDeep(defaultOptions, combinedOptions));
148
+ } finally {
149
+ if (_window) {
150
+ (global as { window: unknown }).window = _window;
151
+ };
152
+ }
151
153
  }
@@ -1,16 +1,14 @@
1
- import { ExportResultCode } from '@opentelemetry/core';
2
- import type { SpanExporter } from '@opentelemetry/sdk-trace-base';
3
-
4
- const noop: SpanExporter['export'] = (spans, resultCallback) => {
5
- setImmediate(() =>
6
- resultCallback({
7
- code: ExportResultCode.SUCCESS,
8
- }),
9
- );
10
- };
1
+ import { ExportResult, ExportResultCode } from '@opentelemetry/core';
2
+ import type { ReadableSpan, SpanExporter } from '@opentelemetry/sdk-trace-base';
11
3
 
12
4
  export class DummySpanExporter implements SpanExporter {
13
- export: typeof noop = noop;
5
+ export(spans: ReadableSpan[], resultCallback: (r: ExportResult) => void) {
6
+ setImmediate(() =>
7
+ resultCallback({
8
+ code: ExportResultCode.SUCCESS,
9
+ }),
10
+ );
11
+ }
14
12
 
15
13
  async shutdown() {
16
14
  // Nothing to do