@scopieflows/apps-common 0.12.3 → 0.12.4

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,13 +1,18 @@
1
1
  {
2
2
  "name": "@scopieflows/apps-common",
3
- "version": "0.12.3",
3
+ "version": "0.12.4",
4
4
  "type": "commonjs",
5
5
  "main": "./src/index.js",
6
6
  "types": "./src/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc -p tsconfig.lib.json && cp package.json dist/",
9
+ "lint": "eslint 'src/**/*.ts'",
10
+ "test": "node --test \"tests/**/*.test.mjs\""
11
+ },
7
12
  "dependencies": {
8
- "@scopieflows/apps-framework": "0.28.1",
9
- "@scopieflows/shared": "0.54.0",
10
- "axios": "1.15.0",
13
+ "@scopieflows/apps-framework": "^0.28.4",
14
+ "@scopieflows/shared": "^0.58.0",
15
+ "axios": "1.19.0",
11
16
  "axios-retry": "4.4.1",
12
17
  "form-data": "4.0.4",
13
18
  "http-proxy-agent": "7.0.2",
@@ -15,5 +20,8 @@
15
20
  "mime-types": "2.1.35",
16
21
  "tslib": "2.6.2",
17
22
  "zod": "4.3.6"
23
+ },
24
+ "devDependencies": {
25
+ "@types/mime-types": "2.1.1"
18
26
  }
19
- }
27
+ }
@@ -1,8 +1,8 @@
1
1
  import { AxiosError } from 'axios';
2
2
  export declare class HttpError extends Error {
3
- private readonly requestBody;
4
3
  private readonly status;
5
4
  private readonly responseBody;
5
+ private readonly safeRequestBody;
6
6
  constructor(requestBody: unknown, err: AxiosError);
7
7
  errorMessage(): {
8
8
  response: {
@@ -17,6 +17,12 @@ export declare class HttpError extends Error {
17
17
  status: number;
18
18
  body: unknown;
19
19
  };
20
+ /**
21
+ * The request body with credentials removed.
22
+ *
23
+ * Deliberately NOT the raw body: this is read by piece error handlers and
24
+ * ends up in user-visible run output.
25
+ */
20
26
  get request(): {
21
27
  body: unknown;
22
28
  };
@@ -1 +1 @@
1
- {"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../../../../src/lib/http/core/http-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,qBAAa,SAAU,SAAQ,KAAK;IAItB,OAAO,CAAC,QAAQ,CAAC,WAAW;IAHxC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;gBAEV,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU;IAoB3D,YAAY;;;;;;;;;IAYnB,IAAI,QAAQ;;;MAKX;IAED,IAAI,OAAO;;MAIV;CACF"}
1
+ {"version":3,"file":"http-error.d.ts","sourceRoot":"","sources":["../../../../../src/lib/http/core/http-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AA6EnC,qBAAa,SAAU,SAAQ,KAAK;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAU;IACvC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAU;gBAK9B,WAAW,EAAE,OAAO,EAAE,GAAG,EAAE,UAAU;IAsB1C,YAAY;;;;;;;;;IAYnB,IAAI,QAAQ;;;MAKX;IAED;;;;;OAKG;IACH,IAAI,OAAO;;MAIV;CACF"}
@@ -1,23 +1,98 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.HttpError = void 0;
4
+ /**
5
+ * Keys whose values are credentials rather than debuggable input.
6
+ *
7
+ * Matched case-insensitively against a normalised key (non-alphanumerics
8
+ * stripped), so `client_secret`, `clientSecret` and `Client-Secret` all hit the
9
+ * same entry.
10
+ */
11
+ const SENSITIVE_KEYS = new Set([
12
+ 'password',
13
+ 'passwd',
14
+ 'passphrase',
15
+ 'secret',
16
+ 'clientsecret',
17
+ 'apikey',
18
+ 'apitoken',
19
+ 'token',
20
+ 'accesstoken',
21
+ 'refreshtoken',
22
+ 'idtoken',
23
+ 'authorization',
24
+ 'auth',
25
+ 'totp',
26
+ 'otp',
27
+ 'mfa',
28
+ 'mfasecret',
29
+ 'pin',
30
+ 'codeverifier',
31
+ 'privatekey',
32
+ 'subscriptionkey',
33
+ 'sessionkey',
34
+ 'credentials',
35
+ ]);
36
+ const REDACTED = '[redacted]';
37
+ const MAX_DEPTH = 6;
38
+ function isSensitive(key) {
39
+ return SENSITIVE_KEYS.has(key.toLowerCase().replace(/[^a-z0-9]/gi, ''));
40
+ }
41
+ /**
42
+ * Strip credentials from a request body before it is recorded on the error.
43
+ *
44
+ * Why this exists: the request body is kept because knowing what you sent is
45
+ * usually the whole point of a failed-request error. But on an auth endpoint the
46
+ * body IS the credential — a login posts a password, a token exchange posts a
47
+ * client secret — and this error's message is JSON.stringify'd into
48
+ * `Error.message`, which reaches the server console, a piece's error handler
49
+ * and the flow run output a user can read.
50
+ *
51
+ * Redaction preserves the shape, so the error still shows which fields were
52
+ * sent and what their names were; only the values go.
53
+ */
54
+ function redact(value, depth = 0) {
55
+ var _a, _b;
56
+ if (depth > MAX_DEPTH || value === null || typeof value !== 'object') {
57
+ return value;
58
+ }
59
+ if (Array.isArray(value)) {
60
+ return value.map((item) => redact(item, depth + 1));
61
+ }
62
+ // Preserve non-plain objects (Buffer, streams, FormData) by description
63
+ // rather than walking them — they are not useful in an error message and may
64
+ // be large.
65
+ const proto = Object.getPrototypeOf(value);
66
+ if (proto !== Object.prototype && proto !== null) {
67
+ return `[${(_b = (_a = value.constructor) === null || _a === void 0 ? void 0 : _a.name) !== null && _b !== void 0 ? _b : 'object'}]`;
68
+ }
69
+ const out = {};
70
+ for (const [key, item] of Object.entries(value)) {
71
+ out[key] = isSensitive(key) ? REDACTED : redact(item, depth + 1);
72
+ }
73
+ return out;
74
+ }
4
75
  class HttpError extends Error {
76
+ // `requestBody` is deliberately a plain parameter, not a property: retaining
77
+ // the raw body would leave credentials on the instance for anything that
78
+ // enumerates it, and TypeScript's `private` is compile-time only.
5
79
  constructor(requestBody, err) {
6
80
  var _a, _b, _c, _d;
7
81
  const status = ((_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.status) || 500;
8
82
  const responseBody = Buffer.isBuffer((_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.data) ? (_c = err === null || err === void 0 ? void 0 : err.response) === null || _c === void 0 ? void 0 : _c.data.toString() : (_d = err === null || err === void 0 ? void 0 : err.response) === null || _d === void 0 ? void 0 : _d.data;
83
+ const safeRequestBody = redact(requestBody);
9
84
  super(JSON.stringify({
10
85
  response: {
11
86
  status: status,
12
87
  body: responseBody,
13
88
  },
14
89
  request: {
15
- body: requestBody,
90
+ body: safeRequestBody,
16
91
  },
17
92
  }));
18
- this.requestBody = requestBody;
19
93
  this.status = status;
20
94
  this.responseBody = responseBody;
95
+ this.safeRequestBody = safeRequestBody;
21
96
  }
22
97
  errorMessage() {
23
98
  return {
@@ -26,7 +101,7 @@ class HttpError extends Error {
26
101
  body: this.responseBody,
27
102
  },
28
103
  request: {
29
- body: this.requestBody,
104
+ body: this.safeRequestBody,
30
105
  },
31
106
  };
32
107
  }
@@ -36,9 +111,15 @@ class HttpError extends Error {
36
111
  body: this.responseBody,
37
112
  };
38
113
  }
114
+ /**
115
+ * The request body with credentials removed.
116
+ *
117
+ * Deliberately NOT the raw body: this is read by piece error handlers and
118
+ * ends up in user-visible run output.
119
+ */
39
120
  get request() {
40
121
  return {
41
- body: this.requestBody,
122
+ body: this.safeRequestBody,
42
123
  };
43
124
  }
44
125
  }
@@ -1 +1 @@
1
- {"version":3,"file":"http-error.js","sourceRoot":"","sources":["../../../../../src/lib/http/core/http-error.ts"],"names":[],"mappings":";;;AAEA,MAAa,SAAU,SAAQ,KAAK;IAIlC,YAA6B,WAAoB,EAAE,GAAe;;QAChE,MAAM,MAAM,GAAG,CAAA,MAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,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