@promster/hapi 8.0.5 → 8.0.6

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.
@@ -13,7 +13,7 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
13
13
 
14
14
  var pkg = {
15
15
  name: "@promster/hapi",
16
- version: "8.0.5",
16
+ version: "8.0.6",
17
17
  description: "Hapi server integrations of promster",
18
18
  main: "dist/promster-hapi.cjs.js",
19
19
  typings: "dist/promster-hapi.cjs.d.ts",
@@ -49,69 +49,57 @@ var pkg = {
49
49
  "prometheus"
50
50
  ],
51
51
  dependencies: {
52
- "@promster/metrics": "^9.1.5",
52
+ "@promster/metrics": "^9.1.6",
53
53
  "merge-options": "3.0.4",
54
- semver: "7.3.5",
55
- tslib: "2.3.1"
54
+ semver: "7.3.8",
55
+ tslib: "2.4.1"
56
56
  },
57
57
  devDependencies: {
58
58
  "@hapi/boom": "9.1.4",
59
- "@hapi/hapi": "20.2.1",
60
- "@promster/types": "^3.2.4",
61
- "@types/hapi__hapi": "20.0.10",
59
+ "@hapi/hapi": "20.2.2",
60
+ "@promster/types": "^3.2.5",
61
+ "@types/hapi__hapi": "20.0.13",
62
62
  "parse-prometheus-text-format": "1.1.1"
63
63
  }
64
64
  };
65
65
 
66
- const extractPath = request => request.route.path.replace(/\?/g, '');
66
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
67
67
 
68
+ const extractPath = request => request.route.path.replace(/\?/g, '');
68
69
  const isBoomResponse = response => response.isBoom;
69
-
70
70
  const extractStatusCode = request => {
71
71
  const {
72
72
  response
73
73
  } = request;
74
-
75
74
  if (!response) {
76
75
  return 0;
77
76
  }
78
-
79
77
  if (isBoomResponse(response)) {
80
78
  return response.output.statusCode;
81
79
  }
82
-
83
80
  return response.statusCode;
84
81
  };
85
-
86
82
  let recordRequest;
87
83
  let upMetric;
88
-
89
84
  const getRequestRecorder = () => recordRequest;
90
-
91
85
  const signalIsUp = () => {
92
86
  if (!upMetric) {
93
87
  return;
94
88
  }
95
-
96
89
  upMetric.forEach(upMetricType => {
97
90
  upMetricType.set(1);
98
91
  });
99
92
  };
100
-
101
93
  const signalIsNotUp = () => {
102
94
  if (!upMetric) {
103
95
  return;
104
96
  }
105
-
106
97
  upMetric.forEach(upMetricType => {
107
98
  upMetricType.set(0);
108
99
  });
109
100
  };
110
-
111
101
  const getAreServerEventsSupported = actualVersion => Boolean(actualVersion && semver__default["default"].satisfies(actualVersion, '>= 17.0.0'));
112
-
113
102
  const getDoesResponseNeedInvocation = actualVersion => Boolean(actualVersion && semver__default["default"].satisfies(actualVersion, '< 17.0.0'));
114
-
115
103
  const createPlugin = ({
116
104
  options: pluginOptions
117
105
  } = {
@@ -124,31 +112,25 @@ const createPlugin = ({
124
112
  const observeGc = metrics.createGcObserver(gcMetrics, allDefaultedOptions);
125
113
  recordRequest = metrics.createRequestRecorder(httpMetrics, allDefaultedOptions);
126
114
  upMetric = gcMetrics === null || gcMetrics === void 0 ? void 0 : gcMetrics.up;
127
-
128
115
  if (!shouldSkipMetricsByEnvironment) {
129
116
  observeGc();
130
117
  }
131
-
132
118
  const plugin = {
133
119
  name: pkg.name,
134
120
  version: pkg.version,
135
-
136
121
  // @ts-expect-error
137
122
  register(server, _registrationOptions, onRegistrationFinished = () => null) {
138
123
  const areServerEventsSupported = getAreServerEventsSupported(server.version);
139
124
  const doesResponseNeedInvocation = getDoesResponseNeedInvocation(server.version);
140
-
141
125
  const onRequestHandler = (request, h) => {
142
126
  request.plugins.promster = {
143
127
  timing: metrics.timing.start()
144
- }; // @ts-expect-error
145
-
128
+ };
129
+ // @ts-expect-error
146
130
  return doesResponseNeedInvocation ? h.continue() : h.continue;
147
131
  };
148
-
149
132
  const onResponseHandler = (request, response) => {
150
133
  var _allDefaultedOptions$, _request$headers$cont, _request$headers, _request$response$hea, _request$response, _request$response$hea2, _allDefaultedOptions$2;
151
-
152
134
  const labels = Object.assign({}, {
153
135
  path: allDefaultedOptions.normalizePath(extractPath(request), {
154
136
  req: request,
@@ -167,7 +149,6 @@ const createPlugin = ({
167
149
  const responseContentLength = Number( // @ts-expect-error
168
150
  (_request$response$hea = request === null || request === void 0 ? void 0 : (_request$response = request.response) === null || _request$response === void 0 ? void 0 : (_request$response$hea2 = _request$response.headers) === null || _request$response$hea2 === void 0 ? void 0 : _request$response$hea2['content-length']) !== null && _request$response$hea !== void 0 ? _request$response$hea : 0);
169
151
  const shouldSkipByRequest = (_allDefaultedOptions$2 = allDefaultedOptions.skip) === null || _allDefaultedOptions$2 === void 0 ? void 0 : _allDefaultedOptions$2.call(allDefaultedOptions, request, response, labels);
170
-
171
152
  if (!shouldSkipByRequest && !shouldSkipMetricsByEnvironment) {
172
153
  recordRequest(request.plugins.promster.timing, {
173
154
  labels,
@@ -175,34 +156,32 @@ const createPlugin = ({
175
156
  responseContentLength
176
157
  });
177
158
  }
178
-
179
159
  if (doesResponseNeedInvocation) response.continue();
180
- }; // NOTE: This version detection allows us to gracefully support both new and old Hapi APIs.
181
- // This is very hard to type as we would have to import two aliased versions of types.
182
-
160
+ };
183
161
 
162
+ // NOTE: This version detection allows us to gracefully support both new and old Hapi APIs.
163
+ // This is very hard to type as we would have to import two aliased versions of types.
184
164
  if (areServerEventsSupported) {
185
165
  // @ts-expect-error
186
- server.ext('onRequest', onRequestHandler); // @ts-expect-error
187
-
166
+ server.ext('onRequest', onRequestHandler);
167
+ // @ts-expect-error
188
168
  server.events.on('response', onResponseHandler);
189
169
  } else {
190
170
  // @ts-expect-error
191
- server.ext('onRequest', onRequestHandler); // @ts-expect-error
192
-
171
+ server.ext('onRequest', onRequestHandler);
172
+ // @ts-expect-error
193
173
  server.ext('onPreResponse', onResponseHandler);
194
- } // NOTE: The type of the server.decorate only supports a function signature,
174
+ }
175
+
176
+ // NOTE: The type of the server.decorate only supports a function signature,
195
177
  // even when the docs state that it can also be "other value" in the case of `server`.
196
178
  // @ts-expect-error
197
-
198
-
199
179
  server.decorate('server', 'Prometheus', metrics.Prometheus);
200
180
  server.decorate('server', 'recordRequest', recordRequest);
201
181
  return onRegistrationFinished === null || onRegistrationFinished === void 0 ? void 0 : onRegistrationFinished();
202
182
  }
203
-
204
- }; // @ts-expect-error
205
-
183
+ };
184
+ // @ts-expect-error
206
185
  plugin.register.attributes = {
207
186
  pkg
208
187
  };
@@ -13,7 +13,7 @@ var merge__default = /*#__PURE__*/_interopDefault(merge);
13
13
 
14
14
  var pkg = {
15
15
  name: "@promster/hapi",
16
- version: "8.0.5",
16
+ version: "8.0.6",
17
17
  description: "Hapi server integrations of promster",
18
18
  main: "dist/promster-hapi.cjs.js",
19
19
  typings: "dist/promster-hapi.cjs.d.ts",
@@ -49,69 +49,57 @@ var pkg = {
49
49
  "prometheus"
50
50
  ],
51
51
  dependencies: {
52
- "@promster/metrics": "^9.1.5",
52
+ "@promster/metrics": "^9.1.6",
53
53
  "merge-options": "3.0.4",
54
- semver: "7.3.5",
55
- tslib: "2.3.1"
54
+ semver: "7.3.8",
55
+ tslib: "2.4.1"
56
56
  },
57
57
  devDependencies: {
58
58
  "@hapi/boom": "9.1.4",
59
- "@hapi/hapi": "20.2.1",
60
- "@promster/types": "^3.2.4",
61
- "@types/hapi__hapi": "20.0.10",
59
+ "@hapi/hapi": "20.2.2",
60
+ "@promster/types": "^3.2.5",
61
+ "@types/hapi__hapi": "20.0.13",
62
62
  "parse-prometheus-text-format": "1.1.1"
63
63
  }
64
64
  };
65
65
 
66
- const extractPath = request => request.route.path.replace(/\?/g, '');
66
+ // eslint-disable-next-line @typescript-eslint/consistent-type-definitions
67
67
 
68
+ const extractPath = request => request.route.path.replace(/\?/g, '');
68
69
  const isBoomResponse = response => response.isBoom;
69
-
70
70
  const extractStatusCode = request => {
71
71
  const {
72
72
  response
73
73
  } = request;
74
-
75
74
  if (!response) {
76
75
  return 0;
77
76
  }
78
-
79
77
  if (isBoomResponse(response)) {
80
78
  return response.output.statusCode;
81
79
  }
82
-
83
80
  return response.statusCode;
84
81
  };
85
-
86
82
  let recordRequest;
87
83
  let upMetric;
88
-
89
84
  const getRequestRecorder = () => recordRequest;
90
-
91
85
  const signalIsUp = () => {
92
86
  if (!upMetric) {
93
87
  return;
94
88
  }
95
-
96
89
  upMetric.forEach(upMetricType => {
97
90
  upMetricType.set(1);
98
91
  });
99
92
  };
100
-
101
93
  const signalIsNotUp = () => {
102
94
  if (!upMetric) {
103
95
  return;
104
96
  }
105
-
106
97
  upMetric.forEach(upMetricType => {
107
98
  upMetricType.set(0);
108
99
  });
109
100
  };
110
-
111
101
  const getAreServerEventsSupported = actualVersion => Boolean(actualVersion && semver__default["default"].satisfies(actualVersion, '>= 17.0.0'));
112
-
113
102
  const getDoesResponseNeedInvocation = actualVersion => Boolean(actualVersion && semver__default["default"].satisfies(actualVersion, '< 17.0.0'));
114
-
115
103
  const createPlugin = ({
116
104
  options: pluginOptions
117
105
  } = {
@@ -124,31 +112,25 @@ const createPlugin = ({
124
112
  const observeGc = metrics.createGcObserver(gcMetrics, allDefaultedOptions);
125
113
  recordRequest = metrics.createRequestRecorder(httpMetrics, allDefaultedOptions);
126
114
  upMetric = gcMetrics === null || gcMetrics === void 0 ? void 0 : gcMetrics.up;
127
-
128
115
  if (!shouldSkipMetricsByEnvironment) {
129
116
  observeGc();
130
117
  }
131
-
132
118
  const plugin = {
133
119
  name: pkg.name,
134
120
  version: pkg.version,
135
-
136
121
  // @ts-expect-error
137
122
  register(server, _registrationOptions, onRegistrationFinished = () => null) {
138
123
  const areServerEventsSupported = getAreServerEventsSupported(server.version);
139
124
  const doesResponseNeedInvocation = getDoesResponseNeedInvocation(server.version);
140
-
141
125
  const onRequestHandler = (request, h) => {
142
126
  request.plugins.promster = {
143
127
  timing: metrics.timing.start()
144
- }; // @ts-expect-error
145
-
128
+ };
129
+ // @ts-expect-error
146
130
  return doesResponseNeedInvocation ? h.continue() : h.continue;
147
131
  };
148
-
149
132
  const onResponseHandler = (request, response) => {
150
133
  var _allDefaultedOptions$, _request$headers$cont, _request$headers, _request$response$hea, _request$response, _request$response$hea2, _allDefaultedOptions$2;
151
-
152
134
  const labels = Object.assign({}, {
153
135
  path: allDefaultedOptions.normalizePath(extractPath(request), {
154
136
  req: request,
@@ -167,7 +149,6 @@ const createPlugin = ({
167
149
  const responseContentLength = Number( // @ts-expect-error
168
150
  (_request$response$hea = request === null || request === void 0 ? void 0 : (_request$response = request.response) === null || _request$response === void 0 ? void 0 : (_request$response$hea2 = _request$response.headers) === null || _request$response$hea2 === void 0 ? void 0 : _request$response$hea2['content-length']) !== null && _request$response$hea !== void 0 ? _request$response$hea : 0);
169
151
  const shouldSkipByRequest = (_allDefaultedOptions$2 = allDefaultedOptions.skip) === null || _allDefaultedOptions$2 === void 0 ? void 0 : _allDefaultedOptions$2.call(allDefaultedOptions, request, response, labels);
170
-
171
152
  if (!shouldSkipByRequest && !shouldSkipMetricsByEnvironment) {
172
153
  recordRequest(request.plugins.promster.timing, {
173
154
  labels,
@@ -175,34 +156,32 @@ const createPlugin = ({
175
156
  responseContentLength
176
157
  });
177
158
  }
178
-
179
159
  if (doesResponseNeedInvocation) response.continue();
180
- }; // NOTE: This version detection allows us to gracefully support both new and old Hapi APIs.
181
- // This is very hard to type as we would have to import two aliased versions of types.
182
-
160
+ };
183
161
 
162
+ // NOTE: This version detection allows us to gracefully support both new and old Hapi APIs.
163
+ // This is very hard to type as we would have to import two aliased versions of types.
184
164
  if (areServerEventsSupported) {
185
165
  // @ts-expect-error
186
- server.ext('onRequest', onRequestHandler); // @ts-expect-error
187
-
166
+ server.ext('onRequest', onRequestHandler);
167
+ // @ts-expect-error
188
168
  server.events.on('response', onResponseHandler);
189
169
  } else {
190
170
  // @ts-expect-error
191
- server.ext('onRequest', onRequestHandler); // @ts-expect-error
192
-
171
+ server.ext('onRequest', onRequestHandler);
172
+ // @ts-expect-error
193
173
  server.ext('onPreResponse', onResponseHandler);
194
- } // NOTE: The type of the server.decorate only supports a function signature,
174
+ }
175
+
176
+ // NOTE: The type of the server.decorate only supports a function signature,
195
177
  // even when the docs state that it can also be "other value" in the case of `server`.
196
178
  // @ts-expect-error
197
-
198
-
199
179
  server.decorate('server', 'Prometheus', metrics.Prometheus);
200
180
  server.decorate('server', 'recordRequest', recordRequest);
201
181
  return onRegistrationFinished === null || onRegistrationFinished === void 0 ? void 0 : onRegistrationFinished();
202
182
  }
203
-
204
- }; // @ts-expect-error
205
-
183
+ };
184
+ // @ts-expect-error
206
185
  plugin.register.attributes = {
207
186
  pkg
208
187
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promster/hapi",
3
- "version": "8.0.5",
3
+ "version": "8.0.6",
4
4
  "description": "Hapi server integrations of promster",
5
5
  "main": "dist/promster-hapi.cjs.js",
6
6
  "typings": "dist/promster-hapi.cjs.d.ts",
@@ -36,16 +36,16 @@
36
36
  "prometheus"
37
37
  ],
38
38
  "dependencies": {
39
- "@promster/metrics": "^9.1.5",
39
+ "@promster/metrics": "^9.1.6",
40
40
  "merge-options": "3.0.4",
41
- "semver": "7.3.5",
42
- "tslib": "2.3.1"
41
+ "semver": "7.3.8",
42
+ "tslib": "2.4.1"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@hapi/boom": "9.1.4",
46
- "@hapi/hapi": "20.2.1",
47
- "@promster/types": "^3.2.4",
48
- "@types/hapi__hapi": "20.0.10",
46
+ "@hapi/hapi": "20.2.2",
47
+ "@promster/types": "^3.2.5",
48
+ "@types/hapi__hapi": "20.0.13",
49
49
  "parse-prometheus-text-format": "1.1.1"
50
50
  }
51
51
  }