From ce61e674561d3b9af46f5f0e9de296d27e119b37 Mon Sep 17 00:00:00 2001 From: Samuel Fraga Mateos Date: Sun, 28 Jun 2026 16:19:47 +0200 Subject: [PATCH] refactor: derive v2 API host from baseUrl in resolveUrl resolveUrl hardcoded https://api.pipedrive.com for /api/v2/ endpoints, duplicating the host from baseUrl. Derive it by stripping the trailing /v1 so v1 and v2 always share the same host, even if baseUrl is ever pointed at a company-specific domain. --- src/pipedrive-client.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/pipedrive-client.ts b/src/pipedrive-client.ts index d652e2f..8916ba0 100644 --- a/src/pipedrive-client.ts +++ b/src/pipedrive-client.ts @@ -303,11 +303,15 @@ export class PipedriveClient { } private resolveUrl(endpoint: string): string { - // v2 endpoints come as "/api/v2/..." — use bare host. - // v1 endpoints come as "/deals", "/persons", etc. — prepend "/v1". - return endpoint.startsWith('/api/v2/') - ? `https://api.pipedrive.com${endpoint}` - : `${this.baseUrl}${endpoint}`; + // v1 endpoints come as "/deals", "/persons", etc. and live under baseUrl (".../v1"). + // v2 endpoints come as "/api/v2/..." and hang off the bare host — derive it from + // baseUrl (strip the trailing "/v1") so both share the same host even if baseUrl + // is ever pointed at a company-specific domain. + if (endpoint.startsWith('/api/v2/')) { + const host = this.baseUrl.replace(/\/v1\/?$/, ''); + return `${host}${endpoint}`; + } + return `${this.baseUrl}${endpoint}`; } private invalidateCachePattern(endpoint: string): void {