From 82445da4e0bd7941bc35a1f9688e6255898c684e Mon Sep 17 00:00:00 2001 From: domin-mnd Date: Sat, 8 Nov 2025 16:05:10 +0400 Subject: [PATCH 1/5] fix(parseApiRequest): path param parsing --- CHANGELOG.md | 6 ++++++ src/utils/parseApiRequest.ts | 15 ++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cb30d89..647f935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ Формат основан на [Keep a Changelog](https://keepachangelog.com/ru/1.0.0/), и этот проект придерживается [Semantic Versioning](https://semver.org/lang/ru/). +## [3.1.1] - 2025-11-08 + +### Исправлено + +- Исправлен парсинг path-параметров в утилите `parseApiRequest`, чтобы корректно обрабатывать фигурные скобки в URL + ## [3.1.0] - 2025-11-06 ### Добавлено diff --git a/src/utils/parseApiRequest.ts b/src/utils/parseApiRequest.ts index d9d59a4..671605c 100644 --- a/src/utils/parseApiRequest.ts +++ b/src/utils/parseApiRequest.ts @@ -24,7 +24,9 @@ export function parseApiRequest(request: ApiRequest): Request { // Parse path parameters for (const [key, value] of Object.entries(request.pathParams || {})) { - url.pathname = url.pathname.replace(`{${key}}`, encodeURIComponent(String(value))); + // %7B = { + // %7D = } + url.pathname = url.pathname.replace(`%7B${key}%7D`, encodeURIComponent(String(value))); } // Parse headers @@ -39,3 +41,14 @@ export function parseApiRequest(request: ApiRequest): Request { body: request.body ? (request.body instanceof FormData ? request.body : JSON.stringify(request.body)) : undefined, }); } + +console.log( + parseApiRequest({ + baseUrl: 'https://api.example.com', + path: '/users/{id}', + method: 'get', + status: '200', + pathParams: { id: '123' }, + queryParams: { includeDetails: 'true' }, + }) +); From d84e972c352e6584d6afcd9aa633e4d6c42e40d1 Mon Sep 17 00:00:00 2001 From: domin-mnd Date: Sat, 8 Nov 2025 16:06:59 +0400 Subject: [PATCH 2/5] ci: bump version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 78c1cb6..ede9b16 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gratio/api", - "version": "3.1.0", + "version": "3.1.1", "description": "TypeScript common types for Gratio projects API responses and requests", "homepage": "https://github.com/Gratio-tech/Api#readme", "packageManager": "bun@1.2.17", From 50ea2734c67464699b00438a13ebc57a9f399192 Mon Sep 17 00:00:00 2001 From: Domin Date: Sat, 8 Nov 2025 16:15:12 +0400 Subject: [PATCH 3/5] fix(parseApiRequest): remove debug statement smh Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/utils/parseApiRequest.ts | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/utils/parseApiRequest.ts b/src/utils/parseApiRequest.ts index 671605c..3cbf3eb 100644 --- a/src/utils/parseApiRequest.ts +++ b/src/utils/parseApiRequest.ts @@ -42,13 +42,3 @@ export function parseApiRequest(request: ApiRequest): Request { }); } -console.log( - parseApiRequest({ - baseUrl: 'https://api.example.com', - path: '/users/{id}', - method: 'get', - status: '200', - pathParams: { id: '123' }, - queryParams: { includeDetails: 'true' }, - }) -); From 0f922fefec028f99fdbf89adc01f94f5a1115178 Mon Sep 17 00:00:00 2001 From: Domin Date: Sat, 8 Nov 2025 16:16:06 +0400 Subject: [PATCH 4/5] feat(parseApiRequest): add global replace Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/utils/parseApiRequest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/parseApiRequest.ts b/src/utils/parseApiRequest.ts index 3cbf3eb..136dd71 100644 --- a/src/utils/parseApiRequest.ts +++ b/src/utils/parseApiRequest.ts @@ -26,7 +26,7 @@ export function parseApiRequest(request: ApiRequest): Request { for (const [key, value] of Object.entries(request.pathParams || {})) { // %7B = { // %7D = } - url.pathname = url.pathname.replace(`%7B${key}%7D`, encodeURIComponent(String(value))); + url.pathname = url.pathname.replace(new RegExp(`%7B${key}%7D`, 'g'), encodeURIComponent(String(value))); } // Parse headers From 9d689b4a0ec5888a53883cc655d5912851f9c87d Mon Sep 17 00:00:00 2001 From: domin-mnd Date: Sat, 8 Nov 2025 16:17:32 +0400 Subject: [PATCH 5/5] ci: prettier format --- src/utils/parseApiRequest.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/utils/parseApiRequest.ts b/src/utils/parseApiRequest.ts index 136dd71..88e88cf 100644 --- a/src/utils/parseApiRequest.ts +++ b/src/utils/parseApiRequest.ts @@ -41,4 +41,3 @@ export function parseApiRequest(request: ApiRequest): Request { body: request.body ? (request.body instanceof FormData ? request.body : JSON.stringify(request.body)) : undefined, }); } -