@constructive-io/knative-job-fn 0.2.4 → 0.2.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.
package/CHANGELOG.md CHANGED
@@ -3,10 +3,18 @@
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.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)
7
+
8
+ **Note:** Version bump only for package @constructive-io/knative-job-fn
9
+
10
+ ## [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)
11
+
12
+ **Note:** Version bump only for package @constructive-io/knative-job-fn
13
+
6
14
  ## 0.2.4 (2025-12-18)
7
15
 
8
16
  **Note:** Version bump only for package @constructive-io/knative-job-fn
9
17
 
10
- ## [0.2.3](https://github.com/constructive-io/jobs/compare/@launchql/knative-job-fn@0.2.2...@launchql/knative-job-fn@0.2.3) (2025-12-17)
18
+ ## [0.2.3](https://github.com/constructive-io/jobs/compare/@constructive-io/knative-job-fn@0.2.2...@constructive-io/knative-job-fn@0.2.3) (2025-12-17)
11
19
 
12
- **Note:** Version bump only for package @launchql/knative-job-fn
20
+ **Note:** Version bump only for package @constructive-io/knative-job-fn
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructive-io/knative-job-fn",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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",
@@ -18,7 +18,7 @@
18
18
  "url": "https://github.com/constructive-io/jobs"
19
19
  },
20
20
  "scripts": {
21
- "test": "jest",
21
+ "test": "jest --passWithNoTests",
22
22
  "test:watch": "jest --watch",
23
23
  "test:debug": "node --inspect node_modules/.bin/jest --runInBand",
24
24
  "build": "tsc -p tsconfig.json",
@@ -31,5 +31,5 @@
31
31
  "body-parser": "1.19.0",
32
32
  "express": "4.17.1"
33
33
  },
34
- "gitHead": "86d74dc4fce9051df0d2b5bcc163607aba42f009"
34
+ "gitHead": "fc182ff9e4c4745a3e86eda6d58e3b0061f36564"
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);