web_plsql 0.15.1 → 0.17.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,6 +1,6 @@
1
1
  {
2
2
  "name": "web_plsql",
3
- "version": "0.15.1",
3
+ "version": "0.17.0",
4
4
  "author": "Dieter Oberkofler <dieter.oberkofler@gmail.com>",
5
5
  "license": "MIT",
6
6
  "description": "The Express Middleware for Oracle PL/SQL",
@@ -60,33 +60,29 @@
60
60
  "compression": "1.8.1",
61
61
  "cookie-parser": "1.4.7",
62
62
  "debug": "4.4.3",
63
- "escape-html": "1.0.3",
64
- "express": "5.1.0",
65
- "fs-extra": "11.3.2",
63
+ "express": "5.2.1",
66
64
  "http-parser-js": "0.5.10",
67
65
  "morgan": "1.10.1",
68
66
  "multer": "2.0.2",
69
67
  "rotating-file-stream": "3.2.7",
70
- "zod": "4.1.13"
68
+ "zod": "4.3.6"
71
69
  },
72
70
  "devDependencies": {
73
71
  "@types/basic-auth": "1.1.8",
74
72
  "@types/compression": "1.8.1",
75
73
  "@types/cookie-parser": "1.4.10",
76
74
  "@types/debug": "4.1.12",
77
- "@types/escape-html": "1.0.4",
78
- "@types/fs-extra": "11.0.4",
79
75
  "@types/morgan": "1.9.10",
80
76
  "@types/multer": "2.0.0",
81
- "@types/node": "24.10.1",
82
- "@types/oracledb": "6.10.0",
77
+ "@types/node": "25.0.10",
78
+ "@types/oracledb": "6.10.1",
83
79
  "@types/supertest": "6.0.3",
84
- "eslint": "9.39.1",
85
- "eslint-plugin-jsdoc": "61.4.1",
86
- "prettier": "3.7.1",
80
+ "eslint": "9.39.2",
81
+ "eslint-plugin-jsdoc": "62.4.1",
82
+ "prettier": "3.8.1",
87
83
  "shx": "0.4.0",
88
- "supertest": "7.1.4",
84
+ "supertest": "7.2.2",
89
85
  "typescript": "5.9.3",
90
- "typescript-eslint": "8.48.0"
86
+ "typescript-eslint": "8.53.1"
91
87
  }
92
88
  }
@@ -2,12 +2,11 @@
2
2
  * Error handling
3
3
  */
4
4
 
5
- import util from 'node:util';
6
- import escape from 'escape-html';
7
5
  import {ProcedureError} from './procedureError.js';
8
6
  import {RequestError} from './requestError.js';
9
- import {inspectRequest, logToFile} from '../../util/trace.js';
7
+ import {getFormattedMessage, logToFile} from '../../util/trace.js';
10
8
  import {errorToString} from '../../util/errorToString.js';
9
+ import {getHtmlPage} from '../../util/html.js';
11
10
 
12
11
  /**
13
12
  * @typedef {import('express').Request} Request
@@ -18,86 +17,6 @@ import {errorToString} from '../../util/errorToString.js';
18
17
  * @typedef {{html: string; text: string}} outputType
19
18
  */
20
19
 
21
- /**
22
- * Convert value to string
23
- * @param {unknown} value - The value to convert.
24
- * @returns {string} - The string representation of the value.
25
- */
26
- const inspect = (value) => util.inspect(value, {showHidden: false, depth: null, colors: false});
27
-
28
- /**
29
- * Convert LF and/or CR to <br>
30
- * @param {string} text - The text to convert.
31
- * @returns {string} - The converted text.
32
- */
33
- const convertToHtml = (text) => {
34
- let html = escape(text);
35
-
36
- html = html.replace(/(?:\r\n|\r|\n)/g, '<br />');
37
- html = html.replace(/\t/g, '&nbsp;&nbsp;&nbsp;');
38
-
39
- return html;
40
- };
41
-
42
- /**
43
- * Get html
44
- * @param {string} text - The text to convert.
45
- * @returns {string} - The converted text.
46
- */
47
- const getHtml = (text) => `<p>${convertToHtml(text)}</p>`;
48
-
49
- /**
50
- * Get text header
51
- * @param {string} text - The text to convert.
52
- * @returns {string} - The converted text.
53
- */
54
- const getHeaderText = (text) => `\n${text}\n${'='.repeat(text.length)}\n`;
55
-
56
- /**
57
- * Get html header
58
- * @param {string} text - The text to convert.
59
- * @returns {string} - The converted text.
60
- */
61
- const getHeaderHtml = (text) => `<h1>${text}</h1>`;
62
-
63
- /**
64
- * Get text
65
- * @param {string} text - The text to convert.
66
- * @returns {string} - The converted text.
67
- */
68
- const getText = (text) => `${text}\n`;
69
-
70
- /**
71
- * Get evnironment
72
- * @param {outputType} output - The output.
73
- * @param {environmentType} environment - The environment.
74
- */
75
- const getEnvironment = (output, environment) => {
76
- let html = '<table>';
77
- let text = '';
78
-
79
- try {
80
- for (const key in environment) {
81
- html += `<tr><td>${key}:</td><td>${environment[key]}</td></tr>`;
82
- text += `${key}=${environment[key]}\n`;
83
- }
84
- } catch (err) {
85
- /* istanbul ignore next */
86
- output.html += errorToString(err);
87
-
88
- /* istanbul ignore next */
89
- output.text += errorToString(err);
90
-
91
- /* istanbul ignore next */
92
- return;
93
- }
94
-
95
- html += '</table>';
96
-
97
- output.html += html;
98
- output.text += text;
99
- };
100
-
101
20
  /**
102
21
  * Show an error page
103
22
  * @param {Request} req - The req object represents the HTTP request.
@@ -111,8 +30,8 @@ const getError = (req, error) => {
111
30
  let environment = null;
112
31
  /** @type {string | null} */
113
32
  let sql = null;
114
- /** @type {BindParameterConfig} */
115
- let bind = {};
33
+ /** @type {BindParameterConfig | null} */
34
+ let bind = null;
116
35
 
117
36
  // what type of Error did we receive
118
37
  if (error instanceof ProcedureError) {
@@ -143,113 +62,9 @@ const getError = (req, error) => {
143
62
  }
144
63
  }
145
64
 
146
- /** @type {outputType} */
147
- const output = {
148
- html: '',
149
- text: '',
150
- };
151
-
152
- // timestamp
153
- let header = 'TIMESTAMP';
154
- output.html += getHeaderHtml(header);
155
- output.html += getHtml(timestamp.toUTCString());
156
-
157
- // error
158
- header = 'ERROR';
159
- output.html += getHeaderHtml(header);
160
- output.html += getHtml(message);
161
- output.text += getHeaderText(header);
162
- output.text += getText(message);
163
-
164
- // request
165
- header = 'REQUEST';
166
- output.text += getHeaderText(header);
167
- output.text += getText(inspectRequest(req));
168
-
169
- // parameters
170
- if (typeof sql === 'string' && bind) {
171
- header = 'PROCEDURE';
172
- output.html += getHeaderHtml(header);
173
- output.text += getHeaderText(header);
174
- getProcedure(output, sql, bind);
175
- }
176
-
177
- // environment
178
- if (environment) {
179
- header = 'ENVIRONMENT';
180
- output.html += getHeaderHtml(header);
181
- output.text += getHeaderText(header);
182
- getEnvironment(output, environment);
183
- }
184
-
185
- return output;
65
+ return getFormattedMessage({type: 'error', timestamp, message, req, environment, sql, bind});
186
66
  };
187
67
 
188
- /**
189
- * Get procedure
190
- * @param {outputType} output - The output.
191
- * @param {string} sql - The SQL to execute.
192
- * @param {BindParameterConfig} bind - The bind parameters.
193
- */
194
- const getProcedure = (output, sql, bind) => {
195
- let html = '<table>';
196
- let text = '';
197
-
198
- text += `PROCEDURE: ${sql}\n`;
199
- html += `<tr><td>PROCEDURE:</td><td>${sql}</td></tr>`;
200
-
201
- try {
202
- /* istanbul ignore else */
203
- for (const key in bind) {
204
- const value = inspect(bind[key].val);
205
-
206
- html += `<tr><td>${key}:</td><td>${value}</td></tr>`;
207
- text += `${key}: ${value}\n`;
208
- }
209
- } catch (err) {
210
- /* istanbul ignore next */
211
- output.html += err instanceof Error ? err.toString() : 'ERROR';
212
-
213
- /* istanbul ignore next */
214
- output.text += err instanceof Error ? err.toString() : 'ERROR';
215
- /* istanbul ignore next */
216
- return;
217
- }
218
-
219
- html += '</table>';
220
-
221
- output.html += html;
222
- output.text += text;
223
- };
224
-
225
- /**
226
- * getHtmlPage
227
- * @param {string} body - The body.
228
- * @returns {string} - The html page.
229
- */
230
- const getHtmlPage = (body) => `<!DOCTYPE html>
231
- <html lang="en">
232
- <head>
233
- <meta charset="utf-8">
234
- <title>web_plsql error page</title>
235
- <style type="text/css">
236
- html {
237
- font-family: monospace, sans-serif;
238
- font-size: 12px;
239
- }
240
- h1 {
241
- font-size: 16px;
242
- padding: 2px;
243
- background-color: #cc0000;
244
- }
245
- </style>
246
- </head>
247
- <body>
248
- ${body}
249
- </body>
250
- </html>
251
- `;
252
-
253
68
  /**
254
69
  * Show an error page
255
70
  *
@@ -259,38 +74,19 @@ ${body}
259
74
  * @param {unknown} error - The error.
260
75
  */
261
76
  export const errorPage = (req, res, options, error) => {
262
- let output = {
263
- html: '',
264
- text: '',
265
- };
266
-
267
- // get the error description
268
- try {
269
- output = getError(req, error);
270
- } catch (err) {
271
- /* istanbul ignore next */
272
- const header = 'ERROR';
273
-
274
- /* istanbul ignore next */
275
- const message = errorToString(err);
276
-
277
- /* istanbul ignore next */
278
- output.html += getHeaderHtml(header) + getHtml(message);
279
-
280
- /* istanbul ignore next */
281
- output.text += getHeaderHtml(header) + getHtml(message);
282
- }
77
+ // get error message
78
+ const {html, text} = getError(req, error);
283
79
 
284
80
  // trace to file
285
- logToFile(output.text);
81
+ logToFile(text);
286
82
 
287
83
  // console
288
- console.error(output.text);
84
+ console.error(text);
289
85
 
290
86
  // show page
291
87
  if (options.errorStyle === 'basic') {
292
88
  res.status(404).send('Page not found');
293
89
  } else {
294
- res.status(404).send(getHtmlPage(output.html));
90
+ res.status(404).send(getHtmlPage(html));
295
91
  }
296
92
  };
@@ -37,7 +37,6 @@ const requestHandler = async (req, res, next, connectionPool, options) => {
37
37
  debug(`Redirect to the url "${newUrl}"`);
38
38
  res.redirect(newUrl);
39
39
  } else {
40
- /* istanbul ignore next */
41
40
  errorPage(req, res, options, new RequestError('No procedure name given and no default page has been specified'));
42
41
  }
43
42
  } else {
@@ -45,7 +44,6 @@ const requestHandler = async (req, res, next, connectionPool, options) => {
45
44
  await processRequest(req, res, options, connectionPool);
46
45
  }
47
46
  } catch (err) {
48
- /* istanbul ignore next */
49
47
  errorPage(req, res, options, err);
50
48
  }
51
49
  };