Skip to content

Commit d9fcf7e

Browse files
committed
changelog and version bump
1 parent abb9f53 commit d9fcf7e

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

packages/sdk/CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
# Changelog
44

5+
## [1.5.1] - 2025-04-15
6+
7+
### Added
8+
9+
- PD_SDK_DEBUG env var. Set it to true to enable debugging of Pipedream Connect
10+
API requests. Simple sanitization is performed to prevent sensitive field leakage
11+
but use caution.
12+
513
## [1.5.0] - 2025-04-08
614

715
### Added

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@pipedream/sdk",
33
"type": "module",
4-
"version": "1.5.0",
4+
"version": "1.5.1",
55
"description": "Pipedream SDK",
66
"main": "./dist/server.js",
77
"module": "./dist/server.js",

packages/sdk/src/shared/index.ts

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -847,13 +847,40 @@ export interface AsyncRequestOptions extends RequestOptions {
847847
body: { async_handle: string; } & Required<RequestOptions["body"]>;
848848
}
849849

850+
const SENSITIVE_KEYS = ["token", "password", "secret", "apiKey", "authorization", "auth", "key", "access_token"];
851+
852+
function sanitize(value: any, seen = new WeakSet()): any {
853+
if (value === null || value === undefined) return value;
854+
855+
if (typeof value === "object") {
856+
if (seen.has(value)) return "[CIRCULAR]";
857+
seen.add(value);
858+
859+
if (Array.isArray(value)) {
860+
return value.map((v) => sanitize(v, seen));
861+
}
862+
863+
const sanitizedObj: Record<string, any> = {};
864+
for (const [k, v] of Object.entries(value)) {
865+
const isSensitiveKey = SENSITIVE_KEYS.some((sensitiveKey) =>
866+
k.toLowerCase().includes(sensitiveKey.toLowerCase())
867+
);
868+
sanitizedObj[k] = isSensitiveKey ? "[REDACTED]" : sanitize(v, seen);
869+
}
870+
return sanitizedObj;
871+
}
872+
873+
return value; // numbers, booleans, functions, etc.
874+
}
875+
850876
export function DEBUG(...args: any[]) {
851877
if (
852878
typeof process !== "undefined" &&
853879
typeof process.env !== "undefined" &&
854-
process.env.DEBUG === "true"
880+
process.env.PD_SDK_DEBUG === "true"
855881
) {
856-
console.log("[DEBUG]", ...args);
882+
const safeArgs = args.map((arg) => sanitize(arg));
883+
console.log("[PD_SDK_DEBUG]", ...safeArgs);
857884
}
858885
}
859886

@@ -971,9 +998,6 @@ export abstract class BaseClient {
971998
) {
972999
requestOptions.body = processedBody;
9731000
}
974-
DEBUG("makeRequest")
975-
DEBUG("url: ", url.toString())
976-
DEBUG("requestOptions: ", requestOptions)
9771001

9781002
const response: Response = await fetch(url.toString(), requestOptions);
9791003

@@ -992,27 +1016,25 @@ export abstract class BaseClient {
9921016
9931017
return (await response.text()) as unknown as T;*/
9941018
const rawBody = await response.text();
995-
DEBUG("Response status:", response.status);
996-
DEBUG("Response body:", rawBody);
9971019

9981020
if (!response.ok) {
9991021
throw new Error(`HTTP error! status: ${response.status}, body: ${rawBody}`);
10001022
}
10011023

1024+
DEBUG(response.status, url.toString(), requestOptions, rawBody)
10021025
const contentType = response.headers.get("Content-Type");
10031026
if (contentType && contentType.includes("application/json")) {
10041027
try {
10051028
const json = JSON.parse(rawBody);
1006-
DEBUG("Parsed JSON:", json);
10071029
return json as T;
10081030
} catch (err) {
1009-
DEBUG("Failed to parse JSON, returning raw body as fallback.");
10101031
}
10111032
}
10121033

10131034
return rawBody as unknown as T;
10141035
}
10151036

1037+
10161038
protected abstract authHeaders(): string | Promise<string>;
10171039

10181040
/**

0 commit comments

Comments
 (0)