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
2 changes: 2 additions & 0 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ fileignoreconfig:
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
- filename: test/request.spec.ts
checksum: 87afd3bb570fd52437404cbe69a39311ad8a8c73bca9d075ecf88652fd3e13f6
- filename: src/lib/request.ts
checksum: 86d761c4f50fcf377e52c98e0c4db6f06be955790fc5a0f2ba8fe32a88c60825
version: ""
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Change log

### Version: 1.4.0
#### Date: Sept-01-2025
- Fix: Replace URLSearchParams.set() with React Native compatible implementation

### Version: 1.3.0
#### Date: Aug-25-2025
- Fix: Remove custom error object and throw axios error
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/core",
"version": "1.3.0",
"version": "1.4.0",
"type": "commonjs",
"main": "./dist/cjs/src/index.js",
"types": "./dist/cjs/src/index.d.ts",
Expand Down
12 changes: 7 additions & 5 deletions src/lib/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@ import { AxiosInstance } from './types';

/**
* Handles array parameters properly with & separators
* React Native compatible implementation without URLSearchParams.set()
*/
function serializeParams(params: any): string {
if (!params) return '';
const urlParams = new URLSearchParams();

const parts: string[] = [];
Object.keys(params).forEach(key => {
const value = params[key];
if (Array.isArray(value)) {
value.forEach(item => {
urlParams.append(key, item);
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(item)}`);
});
} else {
urlParams.set(key, value);
} else if (value !== null && value !== undefined) {
parts.push(`${encodeURIComponent(key)}=${encodeURIComponent(value)}`);
}
});

return urlParams.toString();
return parts.join('&');
}

/**
Expand Down
25 changes: 25 additions & 0 deletions test/request.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,4 +319,29 @@ describe('Request tests', () => {
const result = await getData(client, url, requestData);
expect(result).toEqual(mockResponse);
});

it('should handle React Native compatibility by avoiding URLSearchParams.set()', async () => {
const client = httpClient({});
const mock = new MockAdapter(client as any);
const url = '/your-api-endpoint';
const mockResponse = { data: 'mocked' };
const requestData = {
params: {
limit: 10,
skip: 0,
include: ['field1', 'field2'],
query: { title: 'test' },
nullValue: null,
undefinedValue: undefined,
emptyString: '',
specialChars: 'hello world & more'
}
};

mock.onGet(url).reply(200, mockResponse);

// The test passes if no "URLSearchParams.set is not implemented" error is thrown
const result = await getData(client, url, requestData);
expect(result).toEqual(mockResponse);
});
});
Loading