@constructive-io/knative-job-fn 0.2.5 → 0.2.7

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/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [0.2.7](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-fn@0.2.6...@constructive-io/knative-job-fn@0.2.7) (2025-12-25)
7
+
8
+ **Note:** Version bump only for package @constructive-io/knative-job-fn
9
+
10
+ ## [0.2.6](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-fn@0.2.5...@constructive-io/knative-job-fn@0.2.6) (2025-12-24)
11
+
12
+ **Note:** Version bump only for package @constructive-io/knative-job-fn
13
+
6
14
  ## [0.2.5](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-fn@0.2.4...@constructive-io/knative-job-fn@0.2.5) (2025-12-19)
7
15
 
8
16
  **Note:** Version bump only for package @constructive-io/knative-job-fn
package/dist/index.js CHANGED
@@ -8,8 +8,46 @@ const body_parser_1 = __importDefault(require("body-parser"));
8
8
  const node_http_1 = __importDefault(require("node:http"));
9
9
  const node_https_1 = __importDefault(require("node:https"));
10
10
  const node_url_1 = require("node:url");
11
+ function getHeaders(req) {
12
+ return {
13
+ 'x-worker-id': req.get('X-Worker-Id'),
14
+ 'x-job-id': req.get('X-Job-Id'),
15
+ 'x-database-id': req.get('X-Database-Id'),
16
+ 'x-callback-url': req.get('X-Callback-Url')
17
+ };
18
+ }
11
19
  const app = (0, express_1.default)();
12
20
  app.use(body_parser_1.default.json());
21
+ // Basic request logging for all incoming job invocations.
22
+ app.use((req, res, next) => {
23
+ try {
24
+ // Log only the headers we care about plus a shallow body snapshot
25
+ const headers = getHeaders(req);
26
+ let body;
27
+ if (req.body && typeof req.body === 'object') {
28
+ // Only log top-level keys to avoid exposing sensitive body contents.
29
+ body = { keys: Object.keys(req.body) };
30
+ }
31
+ else if (typeof req.body === 'string') {
32
+ // For string bodies, log only the length.
33
+ body = { length: req.body.length };
34
+ }
35
+ else {
36
+ body = undefined;
37
+ }
38
+ // eslint-disable-next-line no-console
39
+ console.log('[knative-job-fn] Incoming job request', {
40
+ method: req.method,
41
+ path: req.originalUrl || req.url,
42
+ headers,
43
+ body
44
+ });
45
+ }
46
+ catch {
47
+ // best-effort logging; never block the request
48
+ }
49
+ next();
50
+ });
13
51
  // Echo job headers back on responses for debugging/traceability.
14
52
  app.use((req, res, next) => {
15
53
  res.set({
@@ -122,6 +160,13 @@ app.use((req, res, next) => {
122
160
  if (res.locals.jobCallbackSent)
123
161
  return;
124
162
  res.locals.jobCallbackSent = true;
163
+ // eslint-disable-next-line no-console
164
+ console.log('[knative-job-fn] Function completed', {
165
+ workerId: ctx.workerId,
166
+ jobId: ctx.jobId,
167
+ databaseId: ctx.databaseId,
168
+ statusCode: res.statusCode
169
+ });
125
170
  void sendJobCallback(ctx, 'success');
126
171
  });
127
172
  }
@@ -153,6 +198,33 @@ exports.default = {
153
198
  // eslint-disable-next-line no-console
154
199
  console.error('[knative-job-fn] Failed to send error callback', err);
155
200
  }
201
+ // Log the full error context for debugging.
202
+ try {
203
+ const headers = getHeaders(req);
204
+ // Some error types (e.g. GraphQL ClientError) expose response info.
205
+ const errorDetails = {
206
+ message: error?.message,
207
+ name: error?.name,
208
+ stack: error?.stack
209
+ };
210
+ if (error?.response) {
211
+ errorDetails.response = {
212
+ status: error.response.status,
213
+ statusText: error.response.statusText,
214
+ errors: error.response.errors,
215
+ data: error.response.data
216
+ };
217
+ }
218
+ // eslint-disable-next-line no-console
219
+ console.error('[knative-job-fn] Function error', {
220
+ headers,
221
+ path: req.originalUrl || req.url,
222
+ error: errorDetails
223
+ });
224
+ }
225
+ catch {
226
+ // never throw from the error logger
227
+ }
156
228
  res.status(200).json({ message: error.message });
157
229
  });
158
230
  app.listen(port, cb);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/knative-job-fn",
3
- "version": "0.2.5",
3
+ "version": "0.2.7",
4
4
  "description": "knative job fn",
5
5
  "author": "Constructive <developers@constructive.io>",
6
6
  "homepage": "https://github.com/constructive-io/jobs/tree/master/packages/knative-job-fn#readme",
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "dependencies": {
31
31
  "body-parser": "1.19.0",
32
- "express": "4.17.1"
32
+ "express": "5.2.1"
33
33
  },
34
- "gitHead": "22cfe32e994e26a6490e04e28bab26d1e7e6345c"
34
+ "gitHead": "976cc9e0e09201c7df40518a1797f4178fc21c2c"
35
35
  }
package/src/index.ts CHANGED
@@ -13,10 +13,49 @@ type JobContext = {
13
13
  databaseId: string | undefined;
14
14
  };
15
15
 
16
+ function getHeaders(req: any) {
17
+ return {
18
+ 'x-worker-id': req.get('X-Worker-Id'),
19
+ 'x-job-id': req.get('X-Job-Id'),
20
+ 'x-database-id': req.get('X-Database-Id'),
21
+ 'x-callback-url': req.get('X-Callback-Url')
22
+ };
23
+ }
24
+
16
25
  const app: any = express();
17
26
 
18
27
  app.use(bodyParser.json());
19
28
 
29
+ // Basic request logging for all incoming job invocations.
30
+ app.use((req: any, res: any, next: any) => {
31
+ try {
32
+ // Log only the headers we care about plus a shallow body snapshot
33
+ const headers = getHeaders(req);
34
+
35
+ let body: any;
36
+ if (req.body && typeof req.body === 'object') {
37
+ // Only log top-level keys to avoid exposing sensitive body contents.
38
+ body = { keys: Object.keys(req.body) };
39
+ } else if (typeof req.body === 'string') {
40
+ // For string bodies, log only the length.
41
+ body = { length: req.body.length };
42
+ } else {
43
+ body = undefined;
44
+ }
45
+
46
+ // eslint-disable-next-line no-console
47
+ console.log('[knative-job-fn] Incoming job request', {
48
+ method: req.method,
49
+ path: req.originalUrl || req.url,
50
+ headers,
51
+ body
52
+ });
53
+ } catch {
54
+ // best-effort logging; never block the request
55
+ }
56
+ next();
57
+ });
58
+
20
59
  // Echo job headers back on responses for debugging/traceability.
21
60
  app.use((req: any, res: any, next: any) => {
22
61
  res.set({
@@ -151,6 +190,13 @@ app.use((req: any, res: any, next: any) => {
151
190
  // If an error handler already sent a callback, skip.
152
191
  if (res.locals.jobCallbackSent) return;
153
192
  res.locals.jobCallbackSent = true;
193
+ // eslint-disable-next-line no-console
194
+ console.log('[knative-job-fn] Function completed', {
195
+ workerId: ctx.workerId,
196
+ jobId: ctx.jobId,
197
+ databaseId: ctx.databaseId,
198
+ statusCode: res.statusCode
199
+ });
154
200
  void sendJobCallback(ctx, 'success');
155
201
  });
156
202
  }
@@ -185,6 +231,36 @@ export default {
185
231
  console.error('[knative-job-fn] Failed to send error callback', err);
186
232
  }
187
233
 
234
+ // Log the full error context for debugging.
235
+ try {
236
+ const headers = getHeaders(req);
237
+
238
+ // Some error types (e.g. GraphQL ClientError) expose response info.
239
+ const errorDetails: any = {
240
+ message: error?.message,
241
+ name: error?.name,
242
+ stack: error?.stack
243
+ };
244
+
245
+ if (error?.response) {
246
+ errorDetails.response = {
247
+ status: error.response.status,
248
+ statusText: error.response.statusText,
249
+ errors: error.response.errors,
250
+ data: error.response.data
251
+ };
252
+ }
253
+
254
+ // eslint-disable-next-line no-console
255
+ console.error('[knative-job-fn] Function error', {
256
+ headers,
257
+ path: req.originalUrl || req.url,
258
+ error: errorDetails
259
+ });
260
+ } catch {
261
+ // never throw from the error logger
262
+ }
263
+
188
264
  res.status(200).json({ message: error.message });
189
265
  });
190
266
  app.listen(port, cb);