Skip to content

allow number, string, object, boolean, and RegExp as valid query para… #320

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## Change log

### Version: 3.25.2
#### Date: April-02-2025
##### Fix:
- allow number, string, object, boolean, and RegExp as valid query parameters in sync method

### Version: 3.25.1
#### Date: April-01-2025
##### Fix:
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",
"version": "3.25.1",
"version": "3.25.2",
"description": "Contentstack Javascript SDK",
"homepage": "https://www.contentstack.com/",
"author": {
Expand Down
11 changes: 9 additions & 2 deletions src/core/stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,16 @@ export default class Stack {

if (params) {
for (const key in params) {
const value = params[key];
if (params.hasOwnProperty(key)) {
if (typeof params[key] !== "string" && typeof params[key] !== "number") {
throw new Error(`Invalid parameter value for key "${key}": must be a string or number.`);
if (
typeof value !== "string" &&
typeof value !== "number" &&
typeof value !== "boolean" &&
!(value instanceof RegExp) &&
(typeof value !== "object" || value === null)
) {
throw new Error(`Invalid parameter value for key "${key}": must be a string, number, object, boolean, or RegExp.`);
}
this._query[key] = params[key];
}
Expand Down
37 changes: 37 additions & 0 deletions test/typescript/sync.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import * as Contentstack from '../..';

const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', fetchOptions: {
logHandler: () => {

}
}});

describe('Sync Test', () => {
test('Sync init test', done => {
const response = makeSync({"init": true})
expect(response).not.toEqual(undefined)
done();
});

test('Sync with startdate test', done => {
const response = makeSync({"init": true, "start_from": "2025-04-02"})
expect(response).not.toEqual(undefined)
done();
});

test('Sync with locale test', done => {
const response = makeSync({"init": true, "locale": "en-us"})
expect(response).not.toEqual(undefined)
done();
});

test('Sync with contentTypeUid test', done => {
const response = makeSync({"init": true, "content_type_uid": "ct_uid"})
expect(response).not.toEqual(undefined)
done();
});
});

function makeSync(params: any) {
return stack.sync(params)
}
Loading