Skip to content

Commit 98c9a1b

Browse files
Merge pull request #320 from contentstack/fix/DX-2389
allow number, string, object, boolean, and RegExp as valid query para…
2 parents 80ce9dc + cbc7c0a commit 98c9a1b

File tree

5 files changed

+54
-5
lines changed

5 files changed

+54
-5
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Change log
22

3+
### Version: 3.25.2
4+
#### Date: April-02-2025
5+
##### Fix:
6+
- allow number, string, object, boolean, and RegExp as valid query parameters in sync method
7+
38
### Version: 3.25.1
49
#### Date: April-01-2025
510
##### Fix:

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "contentstack",
3-
"version": "3.25.1",
3+
"version": "3.25.2",
44
"description": "Contentstack Javascript SDK",
55
"homepage": "https://www.contentstack.com/",
66
"author": {

src/core/stack.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,9 +603,16 @@ export default class Stack {
603603

604604
if (params) {
605605
for (const key in params) {
606+
const value = params[key];
606607
if (params.hasOwnProperty(key)) {
607-
if (typeof params[key] !== "string" && typeof params[key] !== "number") {
608-
throw new Error(`Invalid parameter value for key "${key}": must be a string or number.`);
608+
if (
609+
typeof value !== "string" &&
610+
typeof value !== "number" &&
611+
typeof value !== "boolean" &&
612+
!(value instanceof RegExp) &&
613+
(typeof value !== "object" || value === null)
614+
) {
615+
throw new Error(`Invalid parameter value for key "${key}": must be a string, number, object, boolean, or RegExp.`);
609616
}
610617
this._query[key] = params[key];
611618
}

test/typescript/sync.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as Contentstack from '../..';
2+
3+
const stack = Contentstack.Stack({ api_key: 'api_key', delivery_token: 'delivery_token', environment: 'environment', fetchOptions: {
4+
logHandler: () => {
5+
6+
}
7+
}});
8+
9+
describe('Sync Test', () => {
10+
test('Sync init test', done => {
11+
const response = makeSync({"init": true})
12+
expect(response).not.toEqual(undefined)
13+
done();
14+
});
15+
16+
test('Sync with startdate test', done => {
17+
const response = makeSync({"init": true, "start_from": "2025-04-02"})
18+
expect(response).not.toEqual(undefined)
19+
done();
20+
});
21+
22+
test('Sync with locale test', done => {
23+
const response = makeSync({"init": true, "locale": "en-us"})
24+
expect(response).not.toEqual(undefined)
25+
done();
26+
});
27+
28+
test('Sync with contentTypeUid test', done => {
29+
const response = makeSync({"init": true, "content_type_uid": "ct_uid"})
30+
expect(response).not.toEqual(undefined)
31+
done();
32+
});
33+
});
34+
35+
function makeSync(params: any) {
36+
return stack.sync(params)
37+
}

0 commit comments

Comments
 (0)