Skip to content
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Fixed
- Preserve upload-session HTTP header map keys while decoding API responses (NYL-476).
- Patch vulnerable SDK tooling and example HTTP dependencies while preserving TypeDoc compatibility (NYL-471).
- Redact request bodies, provider errors, and stack traces from AWS Lambda example errors and logs (NYL-473).
- Support validated completed-upload attachment references in JSON and multipart message sends and draft requests (NYL-469).
Expand Down
11 changes: 11 additions & 0 deletions src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,17 @@ export default class APIClient {
},
['metadata']
);
// Upload-session headers are an opaque HTTP header map. Preserve their
// names while keeping the deprecated top-level response headers camelCase.
const dataHeaders = parsed?.data?.headers;
if (
dataHeaders !== null &&
typeof dataHeaders === 'object' &&
!Array.isArray(dataHeaders) &&
Object.values(dataHeaders).every((value) => typeof value === 'string')
) {
payload.data.headers = dataHeaders;
}
// Attach rawHeaders as a non-enumerable property to avoid breaking deep equality
Object.defineProperty(payload, 'rawHeaders', {
value: headers,
Expand Down
61 changes: 61 additions & 0 deletions tests/apiClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,67 @@ describe('APIClient', () => {
});

describe('requestWithResponse', () => {
it('should preserve opaque data header maps without changing response header compatibility', async () => {
const uploadHeaders = {
'Content-Type': 'application/octet-stream',
'x-goog-upload-protocol': 'resumable',
};
const response = mockResponse(
JSON.stringify({
request_id: 'upload-request',
data: {
attachment_id: 'upload-id',
content_type: 'application/octet-stream',
headers: uploadHeaders,
metadata: { Keep_Exact: 'value' },
},
})
);
response.headers.set('content-type', 'application/json');
response.headers.set('x-fixture-response', 'upload-session');

const result: any = await client.requestWithResponse(response);

expect(result.requestId).toBe('upload-request');
expect(result.data.attachmentId).toBe('upload-id');
expect(result.data.contentType).toBe('application/octet-stream');
expect(result.data.headers).toEqual(uploadHeaders);
expect(result.data.metadata).toEqual({ Keep_Exact: 'value' });
expect(result.headers.contentType).toBe('application/json');
expect(result.headers.xFixtureResponse).toBe('upload-session');
expect(result.rawHeaders['content-type']).toBe('application/json');
expect(result.rawHeaders['x-fixture-response']).toBe('upload-session');
expect(Object.keys(result)).not.toContain('rawHeaders');
});

it('should continue converting structured header array fields', async () => {
const response = mockResponse(
JSON.stringify({
data: {
headers: [{ header_name: 'Subject', header_value: 'Example' }],
},
})
);

const result: any = await client.requestWithResponse(response);

expect(result.data.headers).toEqual([
{ headerName: 'Subject', headerValue: 'Example' },
]);
});

it('should continue converting header objects that are not string maps', async () => {
const response = mockResponse(
JSON.stringify({
data: { headers: { custom_field: { inner_value: 1 } } },
})
);

const result: any = await client.requestWithResponse(response);

expect(result.data.headers).toEqual({ customField: { innerValue: 1 } });
});

it('should redact malformed response bodies while retaining request context', async () => {
const response = {
status: 200,
Expand Down
Loading