@trojs/openapi-server 1.16.0 → 1.18.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@trojs/openapi-server",
3
3
  "description": "OpenAPI Server",
4
- "version": "1.16.0",
4
+ "version": "1.18.0",
5
5
  "author": {
6
6
  "name": "Pieter Wigboldus",
7
7
  "url": "https://trojs.org/"
@@ -54,7 +54,7 @@
54
54
  "url": "https://github.com/trojs/openapi-server"
55
55
  },
56
56
  "engines": {
57
- "node": ">= 20 < 21 || >= 22 < 23"
57
+ "node": ">= 20 < 21 || >= 22 < 23 || >= 24 < 25"
58
58
  },
59
59
  "keywords": [
60
60
  "openapi",
@@ -1,3 +1,4 @@
1
+ /* eslint-disable complexity */
1
2
  import { hrtime } from 'node:process'
2
3
  import getStatusByError from './error-status.js'
3
4
  import { parseParams } from './params.js'
@@ -45,6 +46,15 @@ export const makeExpressCallback
45
46
  mock
46
47
  })
47
48
  const url = `${request.protocol}://${request.get('Host')}${request.originalUrl}`
49
+
50
+ const ipHeader = request.headers?.['x-forwarded-for']
51
+ const ipString = Array.isArray(ipHeader) ? ipHeader[0] : ipHeader
52
+ const ip = ipString
53
+ ? ipString.split(',')[0].trim()
54
+ : (request.socket?.remoteAddress || request.ip || '-')
55
+ const { method } = request
56
+ const userAgent = request.headers?.['user-agent'] || request.get('user-agent') || '-'
57
+
48
58
  const feedback = {
49
59
  context,
50
60
  request,
@@ -68,7 +78,13 @@ export const makeExpressCallback
68
78
  url,
69
79
  parameters,
70
80
  post: request.body,
71
- response: responseBody
81
+ response: responseBody,
82
+ method,
83
+ ip,
84
+ userAgent,
85
+ responseTime,
86
+ statusCode: response.statusCode || 200,
87
+ message: 'access'
72
88
  })
73
89
 
74
90
  return responseBody
package/src/server.js CHANGED
@@ -4,6 +4,7 @@ import compression from 'compression'
4
4
  import helmet from 'helmet'
5
5
  import * as Sentry from '@sentry/node'
6
6
  import bodyParser from 'body-parser'
7
+ import { hostname } from 'node:os'
7
8
  import { openAPI } from './openapi.js'
8
9
  import { Api } from './api.js'
9
10
 
@@ -53,6 +54,8 @@ const getOriginResourcePolicy = (origin) => ({
53
54
  * @property {number=} tracesSampleRate
54
55
  * @property {number=} profilesSampleRate
55
56
  * @property {string=} release
57
+ * @property {string=} environment
58
+ * @property {string=} serverName
56
59
  */
57
60
 
58
61
  /**
@@ -88,13 +91,15 @@ export const setupServer = async ({
88
91
  if (sentry) {
89
92
  Sentry.init({
90
93
  dsn: sentry.dsn,
94
+ environment: sentry.environment || process.env.NODE_ENV || 'production',
91
95
  integrations: [
92
96
  new Sentry.Integrations.Http({ tracing: true }),
93
97
  new Sentry.Integrations.Express({ app })
94
98
  ],
95
99
  tracesSampleRate: sentry.tracesSampleRate || 1.0,
96
100
  profilesSampleRate: sentry.profilesSampleRate || 1.0,
97
- release: sentry.release
101
+ release: sentry.release || process.env.SOURCE_VERSION,
102
+ serverName: sentry.serverName || process.env.SERVER_NAME || hostname()
98
103
  })
99
104
 
100
105
  app.use(Sentry.Handlers.requestHandler())
@@ -1 +1 @@
1
- {"version":3,"file":"express-callback.d.ts","sourceRoot":"","sources":["../src/express-callback.js"],"names":[],"mappings":"AAwBO,sHAVJ;IAAyB,UAAU;IACZ,aAAa,EAA5B,MAAM;IACW,YAAY,GAA7B,OAAO,YAAC;IACQ,MAAM,GAAtB,MAAM,YAAC;IACS,IAAI,GAApB,MAAM,YAAC;IACU,IAAI,GAArB,OAAO,YAAC;IACU,MAAM,GAAxB,oBAAS;IACS,OAAO,GAAzB,oBAAS;CACjB,YAqFE;sBAtGQ,OAAO,2BAA2B,EAAE,OAAO;uBAC3C,OAAO,2BAA2B,EAAE,QAAQ;sBAC5C,OAAO,iBAAiB,EAAE,OAAO;qBACjC,OAAO,UAAU,EAAE,MAAM"}
1
+ {"version":3,"file":"express-callback.d.ts","sourceRoot":"","sources":["../src/express-callback.js"],"names":[],"mappings":"AAyBO,sHAVJ;IAAyB,UAAU;IACZ,aAAa,EAA5B,MAAM;IACW,YAAY,GAA7B,OAAO,YAAC;IACQ,MAAM,GAAtB,MAAM,YAAC;IACS,IAAI,GAApB,MAAM,YAAC;IACU,IAAI,GAArB,OAAO,YAAC;IACU,MAAM,GAAxB,oBAAS;IACS,OAAO,GAAzB,oBAAS;CACjB,YAoGE;sBArHQ,OAAO,2BAA2B,EAAE,OAAO;uBAC3C,OAAO,2BAA2B,EAAE,QAAQ;sBAC5C,OAAO,iBAAiB,EAAE,OAAO;qBACjC,OAAO,UAAU,EAAE,MAAM"}
package/types/server.d.ts CHANGED
@@ -32,6 +32,8 @@ export type SentryConfig = {
32
32
  tracesSampleRate?: number | undefined;
33
33
  profilesSampleRate?: number | undefined;
34
34
  release?: string | undefined;
35
+ environment?: string | undefined;
36
+ serverName?: string | undefined;
35
37
  };
36
38
  import { openAPI } from './openapi.js';
37
39
  import { Api } from './api.js';
@@ -1 +1 @@
1
- {"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.js"],"names":[],"mappings":"AAuEO,qHAVJ;IAA4B,IAAI,EAAxB,SAAS,EAAE;IACK,MAAM,GAAtB,MAAM,YAAC;IACS,YAAY,GAA5B,MAAM,YAAC;IACe,MAAM,GAA5B,YAAY,YAAC;IACG,SAAS,GAAzB,MAAM,YAAC;IACS,OAAO,GAAvB,MAAM,YAAC;IACQ,UAAU,GAAzB,GAAG,EAAE,YAAC;IACiB,eAAe,GAAtC,CAAA,MAAM,GAAC,MAAM,aAAC;CACtB,GAAU,OAAO,CAAC;IAAE,GAAG,EAAE,OAAO,CAAA;CAAE,CAAC,CA4DrC;sBAtGY,OAAO,2BAA2B,EAAE,OAAO;uBAC3C,OAAO,2BAA2B,EAAE,QAAQ;sBAC5C,OAAO,iBAAiB,EAAE,OAAO;wBACjC,OAAO,UAAU,EAAE,SAAS;qBAC5B,OAAO,UAAU,EAAE,MAAM;;uBAKxB,CAAC;cAED,OAAO,YAA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