Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions __tests__/integration/path-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,18 @@ describe('path param serialization', () => {
'/api/v2/moderation/config/chat%3Amessaging/versions/3',
);
});

it.each(['', '.', '..'])(
'rejects empty or dot-segment path parameter %j',
async (badValue) => {
const fetchSpy = vi.spyOn(globalThis, 'fetch');

await expect(
createApiClient().sendRequest('GET', '/api/v2/chat/messages/{id}', {
id: badValue,
}),
).rejects.toThrow("Invalid path parameter 'id'");
expect(fetchSpy).not.toHaveBeenCalled();
},
);
});
11 changes: 7 additions & 4 deletions src/ApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@
const encodedParams = this.queryParamsStringify(queryParams);
if (pathParams) {
Object.keys(pathParams).forEach((paramName) => {
url = url.replace(
`{${paramName}}`,
encodeURIComponent(pathParams[paramName]),
);
const rawValue = String(pathParams[paramName]);
if (rawValue === '' || rawValue === '.' || rawValue === '..') {
throw new Error(
`Invalid path parameter '${paramName}': must not be empty or a dot-segment`,
);
}
url = url.replace(`{${paramName}}`, encodeURIComponent(rawValue));
});
}

Expand Down Expand Up @@ -87,7 +90,7 @@
response.status,
);
}
throw new StreamError(

Check failure on line 93 in src/ApiClient.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/integration/date-transform.test.ts > dates on responses > channel + members

Error: Stream error code 9: DeleteChannel failed with error: "Too many requests, check response headers for more information." ❯ ApiClient.sendRequest src/ApiClient.ts:93:15 ❯ StreamChatClient.deleteChannel src/gen/chat/ChatApi.ts:588:22 ❯ __tests__/integration/date-transform.test.ts:101:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { metadata: { clientRequestId: '7b6339c1-e112-4728-9e25-ad866801c233', responseHeaders: { constructor: 'Function<Headers>', append: 'Function<append>', delete: 'Function<delete>', get: 'Function<get>', has: 'Function<has>', set: 'Function<set>', getSetCookie: 'Function<getSetCookie>', keys: 'Function<keys>', values: 'Function<values>', entries: 'Function<entries>', forEach: 'Function<forEach>' }, responseCode: 429, rateLimit: { rateLimit: 60, rateLimitRemaining: 0, rateLimitReset: '2026-11-24T20:09:00.000Z' } }, code: 9, apiError: { StatusCode: 429, code: 9, details: [], duration: '0', message: 'DeleteChannel failed with error: "Too many requests, check response headers for more information."', more_info: 'https://getstream.io/chat/docs/api_errors_response' } }

Check failure on line 93 in src/ApiClient.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/integration/date-transform.test.ts > dates on responses > channel + members

Error: Stream error code 9: DeleteChannel failed with error: "Too many requests, check response headers for more information." ❯ ApiClient.sendRequest src/ApiClient.ts:93:15 ❯ StreamChatClient.deleteChannel src/gen/chat/ChatApi.ts:588:22 ❯ __tests__/integration/date-transform.test.ts:101:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { metadata: { clientRequestId: 'b3fd03b8-fce7-45ee-bb07-a1b8973b685b', responseHeaders: { constructor: 'Function<Headers>', append: 'Function<append>', delete: 'Function<delete>', get: 'Function<get>', has: 'Function<has>', set: 'Function<set>', getSetCookie: 'Function<getSetCookie>', keys: 'Function<keys>', values: 'Function<values>', entries: 'Function<entries>', forEach: 'Function<forEach>' }, responseCode: 429, rateLimit: { rateLimit: 60, rateLimitRemaining: 0, rateLimitReset: '2026-11-24T20:09:00.000Z' } }, code: 9, apiError: { StatusCode: 429, code: 9, details: [], duration: '0', message: 'DeleteChannel failed with error: "Too many requests, check response headers for more information."', more_info: 'https://getstream.io/chat/docs/api_errors_response' } }

Check failure on line 93 in src/ApiClient.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/integration/date-transform.test.ts > dates on responses > channel + members

Error: Stream error code 9: DeleteChannel failed with error: "Too many requests, check response headers for more information." ❯ ApiClient.sendRequest src/ApiClient.ts:93:15 ❯ StreamChatClient.deleteChannel src/gen/chat/ChatApi.ts:588:22 ❯ __tests__/integration/date-transform.test.ts:101:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { metadata: { clientRequestId: '8e45a9e8-a6fc-411c-8162-d829dfc8bd64', responseHeaders: { constructor: 'Function<Headers>', append: 'Function<append>', delete: 'Function<delete>', get: 'Function<get>', has: 'Function<has>', set: 'Function<set>', getSetCookie: 'Function<getSetCookie>', keys: 'Function<keys>', values: 'Function<values>', entries: 'Function<entries>', forEach: 'Function<forEach>' }, responseCode: 429, rateLimit: { rateLimit: 60, rateLimitRemaining: 0, rateLimitReset: '2026-11-24T20:09:00.000Z' } }, code: 9, apiError: { StatusCode: 429, code: 9, details: [], duration: '0', message: 'DeleteChannel failed with error: "Too many requests, check response headers for more information."', more_info: 'https://getstream.io/chat/docs/api_errors_response' } }

Check failure on line 93 in src/ApiClient.ts

View workflow job for this annotation

GitHub Actions / test-bun

__tests__/integration/date-transform.test.ts > dates on responses > channel + members

Error: Stream error code 9: DeleteChannel failed with error: "Too many requests, check response headers for more information." ❯ ApiClient.sendRequest src/ApiClient.ts:93:15 ❯ StreamChatClient.deleteChannel src/gen/chat/ChatApi.ts:588:22 ❯ __tests__/integration/date-transform.test.ts:101:5 ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯ Serialized Error: { metadata: { clientRequestId: '5731e4ce-d9be-475c-a5c2-84485341e8cf', responseHeaders: { constructor: 'Function<Headers>', append: 'Function<append>', delete: 'Function<delete>', get: 'Function<get>', has: 'Function<has>', set: 'Function<set>', getSetCookie: 'Function<getSetCookie>', keys: 'Function<keys>', values: 'Function<values>', entries: 'Function<entries>', forEach: 'Function<forEach>' }, responseCode: 429, rateLimit: { rateLimit: 60, rateLimitRemaining: 0, rateLimitReset: '2026-11-24T20:09:00.000Z' } }, code: 9, apiError: { code: 9, message: 'DeleteChannel failed with error: "Too many requests, check response headers for more information."', StatusCode: 429, duration: '0.00ms', more_info: 'https://getstream.io/chat/docs/api_errors_response', details: [] } }
`Stream error code ${error!.code}: ${error!.message}`,
metadata,
error!.code,
Expand Down
Loading