Skip to content

Commit ccf848e

Browse files
committed
Biz PR feedback
1 parent 7c7b4ac commit ccf848e

File tree

2 files changed

+43
-28
lines changed

2 files changed

+43
-28
lines changed

packages/sdk/src/server/__tests__/server.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ beforeEach(() => {
4343
});
4444
});
4545

46+
afterEach(() => {
47+
fetchMock.resetMocks();
48+
jest.clearAllMocks();
49+
});
50+
4651
describe("ServerClient", () => {
4752
beforeEach(() => {
4853
fetchMock.resetMocks();
@@ -700,6 +705,11 @@ describe("ServerClient", () => {
700705
);
701706
});
702707

708+
afterEach(() => {
709+
fetchMock.resetMocks();
710+
jest.clearAllMocks();
711+
});
712+
703713
it("should include externalUserId and environment headers", async () => {
704714
fetchMock.mockResponseOnce(
705715
JSON.stringify({

packages/sdk/src/server/index.ts

Lines changed: 33 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export type CreateServerClientOpts = {
6767
*/
6868
export enum HTTPAuthType {
6969
None = "none",
70-
StaticBearer = "static-bearer",
70+
StaticBearer = "static_bearer_token",
7171
OAuth = "oauth"
7272
}
7373

@@ -775,40 +775,45 @@ export class ServerClient {
775775
}
776776

777777
/**
778-
* Builds a full workflow URL based on the input.
779-
*
780-
* @param input - Either a full URL (with or without protocol) or just an endpoint ID.
781-
*
782-
* @returns The fully constructed URL.
783-
*
784-
* @throws If the input is not a valid URL and not an ID, the function assumes it's an endpoint ID.
785-
*
786-
* @example
787-
* // Full URL input
788-
* this.buildWorkflowUrl("https://en123.m.pipedream.net");
789-
* // Returns: "https://en123.m.pipedream.net"
790-
*
791-
* @example
792-
* // Partial URL (without protocol)
793-
* this.buildWorkflowUrl("en123.m.pipedream.net");
794-
* // Returns: "https://en123.m.pipedream.net"
795-
*
796-
* @example
797-
* // ID only input
798-
* this.buildWorkflowUrl("en123");
799-
* // Returns: "https://en123.yourdomain.com" (where `yourdomain.com` is set in `baseWorkflowDomain`)
800-
*/
778+
* Builds a full workflow URL based on the input.
779+
*
780+
* @param input - Either a full URL (with or without protocol) or just an endpoint ID.
781+
*
782+
* @returns The fully constructed URL.
783+
*
784+
* @throws If the input is a malformed URL, throws an error with a clear message.
785+
*
786+
* @example
787+
* // Full URL input
788+
* this.buildWorkflowUrl("https://en123.m.pipedream.net");
789+
* // Returns: "https://en123.m.pipedream.net"
790+
*
791+
* @example
792+
* // Partial URL (without protocol)
793+
* this.buildWorkflowUrl("en123.m.pipedream.net");
794+
* // Returns: "https://en123.m.pipedream.net"
795+
*
796+
* @example
797+
* // ID only input
798+
* this.buildWorkflowUrl("en123");
799+
* // Returns: "https://en123.yourdomain.com" (where `yourdomain.com` is set in `baseWorkflowDomain`)
800+
*/
801801
private buildWorkflowUrl(input: string): string {
802802
let url: string;
803803

804804
const isUrl = input.includes(".") || input.startsWith("http");
805805

806806
if (isUrl) {
807807
// Try to parse the input as a URL
808-
const parsedUrl = new URL(input.startsWith("http")
809-
? input
810-
: `https://${input}`);
811-
url = parsedUrl.href;
808+
try {
809+
const urlString = input.startsWith("http")
810+
? input
811+
: `https://${input}`;
812+
const parsedUrl = new URL(urlString);
813+
url = parsedUrl.href;
814+
} catch (error) {
815+
throw new Error(`The provided URL is malformed: "${input}". Please provide a valid URL.`);
816+
}
812817
} else {
813818
// If the input is an ID, construct the full URL using the base domain
814819
url = `https://${input}.${this.baseWorkflowDomain}`;

0 commit comments

Comments
 (0)