@stackfactor/agent-utils 1.2.2 → 1.2.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AA6JtC;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,OAAO,EAAE,GAAG,KACT,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC,CAAC;AAEzC,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAkDD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAChB,MAAM,SAAS,EACf,UAAS,YAAiB,KACzB,IAAI,CAAC,MAuKP,CAAC"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AA8LtC;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,OAAO,EAAE,GAAG,KACT,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC,CAAC;AAEzC,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAkDD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAChB,MAAM,SAAS,EACf,UAAS,YAAiB,KACzB,IAAI,CAAC,MAuKP,CAAC"}
package/dist/cjs/serve.js CHANGED
@@ -45,9 +45,6 @@ const client_api_1 = require("@stackfactor/client-api");
45
45
  const logger_js_1 = __importDefault(require("./logger.js"));
46
46
  const agentProto_js_1 = require("./agentProto.js");
47
47
  const runtimeContext_js_1 = require("./runtimeContext.js");
48
- // The conventional self-check module run on a deep HealthCheck when the caller
49
- // doesn't specify `check_code`. Resolved relative to the agent's app root.
50
- const DEFAULT_CHECK_PATH = "src/check.js";
51
48
  // Genuine dynamic `import()` that survives TypeScript's CJS downlevelling (which
52
49
  // would otherwise turn `import()` into `require()` and break file:// URLs and
53
50
  // ESM check modules). Built once; see the call site in runSelfCheck.
@@ -60,9 +57,8 @@ const SELF_CHECK_TIMEOUT_MS = 20_000;
60
57
  * path that escapes it or is absolute (the path may originate from the
61
58
  * integration config, so treat it as untrusted). Returns null when unsafe.
62
59
  */
63
- const resolveCheckPath = (checkCode) => {
60
+ const resolveCheckPath = (rel) => {
64
61
  const root = process.cwd();
65
- const rel = (checkCode || "").trim() || DEFAULT_CHECK_PATH;
66
62
  const dest = (0, node_path_1.resolve)(root, rel);
67
63
  const back = (0, node_path_1.relative)(root, dest);
68
64
  if (back === "" || back.startsWith("..") || (0, node_path_1.isAbsolute)(back)) {
@@ -85,19 +81,51 @@ const normalizeChecks = (raw) => {
85
81
  }));
86
82
  };
87
83
  /**
88
- * Loads and runs the agent's self-check module (`check_code` or the default
89
- * `src/check.js`). The check follows the same programming model as `main`: it
90
- * receives the request {@link AbortSignal} and reads `config` / `request`
91
- * (incl. `request.session`) from the per-request globals (bound here via
92
- * {@link runWithContext}); the logger is imported. The agent owns only its own
93
- * checks reachability/version rows are synthesised backend-side. Never throws:
94
- * a missing module yields no rows; a load error, bad export, thrown error, or
95
- * timeout collapses to a single failed `self_check` row.
84
+ * Loads and runs the agent's self-check module named by `check_code`. There is
85
+ * NO default path — if `check_code` is unset, synthetic testing is reported as
86
+ * not enabled (we never guess at `src/check.js`). The check follows the same
87
+ * programming model as `main`: it receives the request {@link AbortSignal} and
88
+ * reads `config` / `request` (incl. `request.session`) from the per-request
89
+ * globals (bound here via {@link runWithContext}); the logger is imported. The
90
+ * agent owns only its own checks reachability/version rows are synthesised
91
+ * backend-side. Never throws: a load error, bad export, thrown error, or timeout
92
+ * collapses to a single failed `synthetic_check` row.
96
93
  */
97
94
  const runSelfCheck = async (checkCode, config, session) => {
98
- const modulePath = resolveCheckPath(checkCode);
99
- if (!modulePath || !(0, node_fs_1.existsSync)(modulePath)) {
100
- return []; // no self-check module shipped baseline checks only
95
+ const rel = (checkCode || "").trim();
96
+ if (!rel) {
97
+ // No self-check configured. Don't assume a default module — surface that
98
+ // synthetic testing simply isn't enabled for this integration.
99
+ logger_js_1.default.log(null, logger_js_1.default.levels.info, "Self-check skipped: no checkCode configured (synthetic testing not enabled).");
100
+ return [
101
+ {
102
+ name: "synthetic_check",
103
+ ok: false,
104
+ detail: "synthetic testing not enabled — no checkCode configured for this integration",
105
+ severity: "warn",
106
+ },
107
+ ];
108
+ }
109
+ const modulePath = resolveCheckPath(rel);
110
+ if (!modulePath) {
111
+ return [
112
+ {
113
+ name: "synthetic_check",
114
+ ok: false,
115
+ detail: `invalid checkCode path "${rel}"`,
116
+ severity: "warn",
117
+ },
118
+ ];
119
+ }
120
+ if (!(0, node_fs_1.existsSync)(modulePath)) {
121
+ return [
122
+ {
123
+ name: "synthetic_check",
124
+ ok: false,
125
+ detail: `checkCode "${rel}" is configured but the module was not found in the agent image`,
126
+ severity: "warn",
127
+ },
128
+ ];
101
129
  }
102
130
  let checkFn;
103
131
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AA6JtC;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,OAAO,EAAE,GAAG,KACT,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC,CAAC;AAEzC,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAkDD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAChB,MAAM,SAAS,EACf,UAAS,YAAiB,KACzB,IAAI,CAAC,MAuKP,CAAC"}
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/serve.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,eAAe,CAAC;AA8LtC;;;;;GAKG;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,CAAC,CAAC;AAE/D;;;;GAIG;AACH,MAAM,MAAM,aAAa,GAAG,CAC1B,OAAO,EAAE,GAAG,KACT,OAAO,CAAC;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,GAAG,CAAA;CAAE,CAAC,CAAC;AAEzC,MAAM,WAAW,YAAY;IAC3B,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,2CAA2C;IAC3C,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,wFAAwF;IACxF,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B;AAkDD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,GAChB,MAAM,SAAS,EACf,UAAS,YAAiB,KACzB,IAAI,CAAC,MAuKP,CAAC"}
package/dist/esm/serve.js CHANGED
@@ -6,9 +6,6 @@ import { session as clientSession } from "@stackfactor/client-api";
6
6
  import logger from "./logger.js";
7
7
  import { loadAgentService } from "./agentProto.js";
8
8
  import { runWithContext, installGlobals } from "./runtimeContext.js";
9
- // The conventional self-check module run on a deep HealthCheck when the caller
10
- // doesn't specify `check_code`. Resolved relative to the agent's app root.
11
- const DEFAULT_CHECK_PATH = "src/check.js";
12
9
  // Genuine dynamic `import()` that survives TypeScript's CJS downlevelling (which
13
10
  // would otherwise turn `import()` into `require()` and break file:// URLs and
14
11
  // ESM check modules). Built once; see the call site in runSelfCheck.
@@ -21,9 +18,8 @@ const SELF_CHECK_TIMEOUT_MS = 20_000;
21
18
  * path that escapes it or is absolute (the path may originate from the
22
19
  * integration config, so treat it as untrusted). Returns null when unsafe.
23
20
  */
24
- const resolveCheckPath = (checkCode) => {
21
+ const resolveCheckPath = (rel) => {
25
22
  const root = process.cwd();
26
- const rel = (checkCode || "").trim() || DEFAULT_CHECK_PATH;
27
23
  const dest = resolve(root, rel);
28
24
  const back = relative(root, dest);
29
25
  if (back === "" || back.startsWith("..") || isAbsolute(back)) {
@@ -46,19 +42,51 @@ const normalizeChecks = (raw) => {
46
42
  }));
47
43
  };
48
44
  /**
49
- * Loads and runs the agent's self-check module (`check_code` or the default
50
- * `src/check.js`). The check follows the same programming model as `main`: it
51
- * receives the request {@link AbortSignal} and reads `config` / `request`
52
- * (incl. `request.session`) from the per-request globals (bound here via
53
- * {@link runWithContext}); the logger is imported. The agent owns only its own
54
- * checks reachability/version rows are synthesised backend-side. Never throws:
55
- * a missing module yields no rows; a load error, bad export, thrown error, or
56
- * timeout collapses to a single failed `self_check` row.
45
+ * Loads and runs the agent's self-check module named by `check_code`. There is
46
+ * NO default path — if `check_code` is unset, synthetic testing is reported as
47
+ * not enabled (we never guess at `src/check.js`). The check follows the same
48
+ * programming model as `main`: it receives the request {@link AbortSignal} and
49
+ * reads `config` / `request` (incl. `request.session`) from the per-request
50
+ * globals (bound here via {@link runWithContext}); the logger is imported. The
51
+ * agent owns only its own checks reachability/version rows are synthesised
52
+ * backend-side. Never throws: a load error, bad export, thrown error, or timeout
53
+ * collapses to a single failed `synthetic_check` row.
57
54
  */
58
55
  const runSelfCheck = async (checkCode, config, session) => {
59
- const modulePath = resolveCheckPath(checkCode);
60
- if (!modulePath || !existsSync(modulePath)) {
61
- return []; // no self-check module shipped baseline checks only
56
+ const rel = (checkCode || "").trim();
57
+ if (!rel) {
58
+ // No self-check configured. Don't assume a default module — surface that
59
+ // synthetic testing simply isn't enabled for this integration.
60
+ logger.log(null, logger.levels.info, "Self-check skipped: no checkCode configured (synthetic testing not enabled).");
61
+ return [
62
+ {
63
+ name: "synthetic_check",
64
+ ok: false,
65
+ detail: "synthetic testing not enabled — no checkCode configured for this integration",
66
+ severity: "warn",
67
+ },
68
+ ];
69
+ }
70
+ const modulePath = resolveCheckPath(rel);
71
+ if (!modulePath) {
72
+ return [
73
+ {
74
+ name: "synthetic_check",
75
+ ok: false,
76
+ detail: `invalid checkCode path "${rel}"`,
77
+ severity: "warn",
78
+ },
79
+ ];
80
+ }
81
+ if (!existsSync(modulePath)) {
82
+ return [
83
+ {
84
+ name: "synthetic_check",
85
+ ok: false,
86
+ detail: `checkCode "${rel}" is configured but the module was not found in the agent image`,
87
+ severity: "warn",
88
+ },
89
+ ];
62
90
  }
63
91
  let checkFn;
64
92
  try {
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "1.2.2",
6
+ "version": "1.2.3",
7
7
  "description": "",
8
8
  "main": "dist/cjs/index.js",
9
9
  "module": "dist/esm/index.js",