@heliyos/heliyos-api-core 1.0.66 → 1.0.68

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.
@@ -65,6 +65,17 @@
65
65
  font-weight: bold;
66
66
  color: #111827;
67
67
  margin: 0 0 12px 0;
68
+ word-break: break-word;
69
+ overflow-wrap: anywhere;
70
+ }
71
+
72
+ .event-summary {
73
+ margin: 0 0 12px 0;
74
+ font-size: 14px;
75
+ color: #374151;
76
+ line-height: 1.55;
77
+ word-break: break-word;
78
+ overflow-wrap: anywhere;
68
79
  }
69
80
 
70
81
  .event-details {
@@ -77,6 +88,7 @@
77
88
  .detail-table {
78
89
  width: 100%;
79
90
  border-collapse: collapse;
91
+ table-layout: fixed;
80
92
  }
81
93
 
82
94
  .detail-label {
@@ -90,6 +102,8 @@
90
102
  .detail-value {
91
103
  font-size: 13px;
92
104
  color: #111827;
105
+ word-break: break-word;
106
+ overflow-wrap: anywhere;
93
107
  }
94
108
 
95
109
  .detail-cell {
@@ -157,6 +171,9 @@
157
171
  <div class="event-card">
158
172
  <div class="event-badge">{{event_type_label}}</div>
159
173
  <div class="event-title">{{{object_name}}}</div>
174
+ {{#if summary}}
175
+ <div class="event-summary">{{{summary}}}</div>
176
+ {{/if}}
160
177
  {{#if details}}
161
178
  <div class="event-details">
162
179
  <table class="detail-table">
@@ -19,6 +19,55 @@ const serve_static_1 = __importDefault(require("serve-static"));
19
19
  const authentication_1 = require("./authentication");
20
20
  const allowedOrigin_1 = require("./allowedOrigin");
21
21
  const customError_1 = require("./@types/globals/customError");
22
+ const genericErrorMessage = "Something went wrong";
23
+ const defaultErrorStatusCode = 500;
24
+ const nonProductionEnvironments = new Set(["development", "local", "test"]);
25
+ const sensitiveErrorMessagePatterns = [
26
+ /https?:\/\//i,
27
+ /\bapi\.[a-z0-9.-]+\b/i,
28
+ /\btraceback\b/i,
29
+ /\bstack trace\b/i,
30
+ /\b(httpx|requests|axios)\b/i,
31
+ /\bparallel(?:\.ai)?\b/i,
32
+ ];
33
+ const isProductionEnvironment = () => {
34
+ const nodeEnv = (process.env.NODE_ENV || "").toLowerCase();
35
+ return !nonProductionEnvironments.has(nodeEnv);
36
+ };
37
+ const toStatusCode = (status) => Number.isFinite(Number(status))
38
+ ? Number(status)
39
+ : defaultErrorStatusCode;
40
+ const isSensitiveErrorMessage = (message) => {
41
+ if (!message) {
42
+ return true;
43
+ }
44
+ if (message.length > 220 || message.includes("\n") || message.includes("\r")) {
45
+ return true;
46
+ }
47
+ return sensitiveErrorMessagePatterns.some((pattern) => pattern.test(message));
48
+ };
49
+ const sanitizeErrorMessage = (message, statusCode) => {
50
+ if (!isProductionEnvironment()) {
51
+ return message || genericErrorMessage;
52
+ }
53
+ const normalizedMessage = (message || "").trim();
54
+ if (!normalizedMessage) {
55
+ return genericErrorMessage;
56
+ }
57
+ if (statusCode >= 500 && isSensitiveErrorMessage(normalizedMessage)) {
58
+ return genericErrorMessage;
59
+ }
60
+ if (statusCode < 500 && isSensitiveErrorMessage(normalizedMessage)) {
61
+ return genericErrorMessage;
62
+ }
63
+ return normalizedMessage;
64
+ };
65
+ const sanitizeErrorDescription = (description) => {
66
+ if (isProductionEnvironment()) {
67
+ return {};
68
+ }
69
+ return description;
70
+ };
22
71
  /**
23
72
  * Function to handle invalid routes
24
73
  * @param _
@@ -134,10 +183,10 @@ const apply_cors = (req, res, next) => {
134
183
  */
135
184
  const handle_errors = (error, _, res, __) => {
136
185
  const { message, description, stack, status } = error;
137
- const errorStatus = status || "500";
186
+ const statusCode = toStatusCode(status);
138
187
  const response = {
139
- message,
140
- description,
188
+ message: sanitizeErrorMessage(message, statusCode),
189
+ description: sanitizeErrorDescription(description),
141
190
  };
142
191
  // Log original error
143
192
  console.error("=== Begin Error ===\n---\n" +
@@ -153,14 +202,10 @@ const handle_errors = (error, _, res, __) => {
153
202
  "Stack: " +
154
203
  stack +
155
204
  "\n---\n=== End Error ===");
156
- if (!errorStatus) {
157
- response.message = "Internal server error";
158
- }
159
205
  // Provide stack track in env development and local
160
- if (process.env.NODE_ENV === "development" ||
161
- process.env.NODE_ENV === "local") {
206
+ if (!isProductionEnvironment()) {
162
207
  response.error = Object.assign({ stack }, error);
163
208
  }
164
209
  // Send status and response
165
- return res.status(parseInt(errorStatus, 10)).json(response);
210
+ return res.status(statusCode).json(response);
166
211
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heliyos/heliyos-api-core",
3
- "version": "1.0.66",
3
+ "version": "1.0.68",
4
4
  "description": "Heliyos's core api functions and middlewares. Its a private package hosted on npm.",
5
5
  "main": "./dist/index.js",
6
6
  "scripts": {
@@ -65,6 +65,17 @@
65
65
  font-weight: bold;
66
66
  color: #111827;
67
67
  margin: 0 0 12px 0;
68
+ word-break: break-word;
69
+ overflow-wrap: anywhere;
70
+ }
71
+
72
+ .event-summary {
73
+ margin: 0 0 12px 0;
74
+ font-size: 14px;
75
+ color: #374151;
76
+ line-height: 1.55;
77
+ word-break: break-word;
78
+ overflow-wrap: anywhere;
68
79
  }
69
80
 
70
81
  .event-details {
@@ -77,6 +88,7 @@
77
88
  .detail-table {
78
89
  width: 100%;
79
90
  border-collapse: collapse;
91
+ table-layout: fixed;
80
92
  }
81
93
 
82
94
  .detail-label {
@@ -90,6 +102,8 @@
90
102
  .detail-value {
91
103
  font-size: 13px;
92
104
  color: #111827;
105
+ word-break: break-word;
106
+ overflow-wrap: anywhere;
93
107
  }
94
108
 
95
109
  .detail-cell {
@@ -157,6 +171,9 @@
157
171
  <div class="event-card">
158
172
  <div class="event-badge">{{event_type_label}}</div>
159
173
  <div class="event-title">{{{object_name}}}</div>
174
+ {{#if summary}}
175
+ <div class="event-summary">{{{summary}}}</div>
176
+ {{/if}}
160
177
  {{#if details}}
161
178
  <div class="event-details">
162
179
  <table class="detail-table">