Skip to content

Commit 48b66ad

Browse files
Merge pull request #186 from contentstack/fix/DX-3133-urlencode-for-query-string
Fix/dx 3133 urlencode for query string
2 parents a668bc6 + eb76615 commit 48b66ad

17 files changed

+2486
-1210
lines changed

.talismanrc

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,24 @@ fileignoreconfig:
22
- filename: .github/workflows/secrets-scan.yml
33
ignore_detectors:
44
- filecontent
5-
- filename: src/lib/types.ts
6-
checksum: 1eb6d6ec971934d65017dae2f82d6d6ef1cd0e6bfd50f43a9b46f30182307230
7-
- filename: test/unit/image-transform.spec.ts
8-
checksum: 7beabdd07bd35d620668fcd97e1a303b9cbc40170bf3008a376d75ce0895de2a
9-
- filename: test/utils/mocks.ts
10-
checksum: a1cb4b1890a584f1facd30f2a0974c97a66f91417022be79d00516338e244227
11-
- filename: src/lib/query.ts
12-
checksum: c4529069bc974d15c104303c5ae573c9341185a869c612ab07f0ee7f42e8b149
13-
- filename: package-lock.json
14-
checksum: 815fd2251550d87a0f113dd2e14266879be37af3a264041e871436a1cc84ae1c
15-
- filename: .husky/pre-commit
16-
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
5+
- filename: src/lib/types.ts
6+
checksum: 1eb6d6ec971934d65017dae2f82d6d6ef1cd0e6bfd50f43a9b46f30182307230
7+
- filename: test/unit/image-transform.spec.ts
8+
checksum: 7beabdd07bd35d620668fcd97e1a303b9cbc40170bf3008a376d75ce0895de2a
9+
- filename: test/utils/mocks.ts
10+
checksum: a1cb4b1890a584f1facd30f2a0974c97a66f91417022be79d00516338e244227
11+
- filename: src/lib/query.ts
12+
checksum: c4529069bc974d15c104303c5ae573c9341185a869c612ab07f0ee7f42e8b149
13+
- filename: package-lock.json
14+
checksum: f9c5af529a2c4c6576d67bd6c25dc6c3088ddedf2482757d382953f2d4521995
15+
- filename: src/lib/entries.ts
16+
checksum: 1c9a58570f26d3e53526e89b404581a523d3f035234bc099fda96d144dee40f6
17+
- filename: src/lib/entry.ts
18+
checksum: 8826fe3147a2c640b0780dae02345611ed24e562562e7df7b3785cb0fa6f1f14
19+
- filename: .husky/pre-commit
20+
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
1721
version: ""
22+
fileignoreconfig:
23+
- filename: package-lock.json
24+
checksum: be08fac0b5e580b7dd66f5dc2b2f7bdefeef89b98ce60df1fe31ad33adb96172
25+
version: "1.0"

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
### Version: 4.7.1
2+
#### Date: June-13-2025
3+
- Add encode option on find method to encode query params
4+
5+
### Version: 4.7.0
6+
#### Date: Apr-29-2025
7+
- Added return type for entry-querable method
8+
- Added support of top-level export of Stack type in @contentstack/delivery-sdk for compatibility with "moduleResolution": "Bundler".
9+
110
### Version: 4.6.1
211
#### Date: March-24-2025
312
Fix: Update imports and dependencies

package-lock.json

Lines changed: 1939 additions & 1004 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/delivery-sdk",
3-
"version": "4.7.0",
3+
"version": "4.7.1",
44
"type": "module",
55
"license": "MIT",
66
"main": "./dist/legacy/index.cjs",

src/lib/base-query.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { AxiosInstance, getData } from '@contentstack/core';
22
import { Pagination } from './pagination';
33
import { FindResponse, params } from './types';
4+
import { encodeQueryParams } from './utils';
45

56
export class BaseQuery extends Pagination {
67
_parameters: params = {}; // Params of query class ?query={}
@@ -201,11 +202,17 @@ export class BaseQuery extends Pagination {
201202
* const result = await stack.asset(asset_uid).fetch();
202203
*/
203204

204-
async find<T>(): Promise<FindResponse<T>> {
205+
async find<T>(encode: boolean = false): Promise<FindResponse<T>> {
205206
let requestParams: { [key: string]: any } = this._queryParams;
206207

207208
if (Object.keys(this._parameters).length > 0) {
208-
requestParams = { ...this._queryParams, query: { ...this._parameters } };
209+
let queryParams = { ...this._parameters };
210+
211+
if (encode) {
212+
queryParams = encodeQueryParams(queryParams);
213+
}
214+
215+
requestParams = { ...this._queryParams, query: queryParams };
209216
}
210217

211218
const getRequestOptions: any = { params: requestParams };

src/lib/entries.ts

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { AxiosInstance, getData } from '@contentstack/core';
2-
import { EntryQueryable } from './entry-queryable';
32
import { Query } from './query';
3+
import { BaseQuery } from './base-query';
44

5-
export class Entries extends EntryQueryable {
5+
export class Entries extends BaseQuery {
66
private _contentTypeUid: string;
77

88
constructor(client: AxiosInstance, contentTypeUid: string) {
@@ -14,35 +14,62 @@ export class Entries extends EntryQueryable {
1414
}
1515

1616
/**
17-
* @method includeFallback
17+
* @method except
1818
* @memberof Entries
19-
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
19+
* @description Excludes specific field/fields of an entry
20+
* @example
21+
* import contentstack from '@contentstack/delivery-sdk'
22+
*
23+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
24+
* const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find()
25+
*
26+
* @param {string} fieldUid - field uid to exclude
27+
* @returns {Entries} - returns Entries object for chaining method calls
28+
*/
29+
except(fieldUid: string|string[]): this {
30+
if (Array.isArray(fieldUid)) {
31+
let i = 0;
32+
for (const uid of fieldUid) {
33+
this._queryParams[`except[BASE][${i}]`] = uid;
34+
i++;
35+
}
36+
} else {
37+
this._queryParams["except[BASE][]"] = fieldUid;
38+
}
39+
40+
return this;
41+
}
42+
43+
/**
44+
* @method includeBranch
45+
* @memberof Entries
46+
* @description Includes the branch in result
2047
* @returns {Entries}
2148
* @example
2249
* import contentstack from '@contentstack/delivery-sdk'
2350
*
2451
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
25-
* const result = await stack.contentType(contentType_uid).entry().includeFallback().find();
52+
* const result = await stack.contentType(contentType_uid).entry().includeBranch().find();
2653
*/
27-
includeFallback(): Entries {
28-
this._queryParams.include_fallback = 'true';
54+
includeBranch(): Entries {
55+
this._queryParams.include_branch = 'true';
2956

3057
return this;
3158
}
3259

3360
/**
34-
* @method includeMetadata
61+
* @method includeContentType
3562
* @memberof Entries
36-
* @description Include the metadata for getting metadata content for the entry.
63+
* @description IInclude the details of the content type along with the entries details
3764
* @returns {Entries}
3865
* @example
3966
* import contentstack from '@contentstack/delivery-sdk'
4067
*
4168
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
42-
* const result = await stack.contentType(contentType_uid).entry().includeMetadata().find();
69+
* const result = await stack.contentType(contentType_uid).entry().includeContentType().fetch();
4370
*/
44-
includeMetadata(): Entries {
45-
this._queryParams.include_metadata = 'true';
71+
includeContentType(): Entries {
72+
this._queryParams.include_content_type = 'true';
4673

4774
return this;
4875
}
@@ -65,35 +92,35 @@ export class Entries extends EntryQueryable {
6592
}
6693

6794
/**
68-
* @method includeContentType
95+
* @method includeFallback
6996
* @memberof Entries
70-
* @description IInclude the details of the content type along with the entries details
97+
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
7198
* @returns {Entries}
7299
* @example
73100
* import contentstack from '@contentstack/delivery-sdk'
74101
*
75102
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
76-
* const result = await stack.contentType(contentType_uid).entry().includeContentType().fetch();
103+
* const result = await stack.contentType(contentType_uid).entry().includeFallback().find();
77104
*/
78-
includeContentType(): Entries {
79-
this._queryParams.include_content_type = 'true';
105+
includeFallback(): Entries {
106+
this._queryParams.include_fallback = 'true';
80107

81108
return this;
82109
}
83110

84111
/**
85-
* @method includeBranch
112+
* @method includeMetadata
86113
* @memberof Entries
87-
* @description Includes the branch in result
114+
* @description Include the metadata for getting metadata content for the entry.
88115
* @returns {Entries}
89116
* @example
90117
* import contentstack from '@contentstack/delivery-sdk'
91118
*
92119
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
93-
* const result = await stack.contentType(contentType_uid).entry().includeBranch().find();
120+
* const result = await stack.contentType(contentType_uid).entry().includeMetadata().find();
94121
*/
95-
includeBranch(): Entries {
96-
this._queryParams.include_branch = 'true';
122+
includeMetadata(): Entries {
123+
this._queryParams.include_metadata = 'true';
97124

98125
return this;
99126
}
@@ -177,6 +204,32 @@ export class Entries extends EntryQueryable {
177204
return this;
178205
}
179206

207+
/**
208+
* @method only
209+
* @memberof Entries
210+
* @description Selects specific field/fields of an entry
211+
* @example
212+
* import contentstack from '@contentstack/delivery-sdk'
213+
*
214+
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
215+
* const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find()
216+
*
217+
* @param {string} fieldUid - field uid to select
218+
* @returns {Entries} - returns Entries object for chaining method calls
219+
*/
220+
only(fieldUid: string|string[]): this {
221+
if (Array.isArray(fieldUid)) {
222+
let i = 0;
223+
for (const uid of fieldUid) {
224+
this._queryParams[`only[BASE][${i}]`] = uid;
225+
i++;
226+
}
227+
} else {
228+
this._queryParams["only[BASE][]"] = fieldUid;
229+
}
230+
return this;
231+
}
232+
180233
/**
181234
* @method query
182235
* @memberof Entries

src/lib/entry-queryable.ts

Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,56 +2,5 @@ import { BaseQuery } from './base-query';
22

33
/* eslint-disable @cspell/spellchecker */
44
export class EntryQueryable extends BaseQuery {
5-
/**
6-
* @method only
7-
* @memberof EntryQueryable
8-
* @description Selects specific field/fields of an entry
9-
* @example
10-
* import contentstack from '@contentstack/delivery-sdk'
11-
*
12-
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
13-
* const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find()
14-
*
15-
* @param {string} fieldUid - field uid to select
16-
* @returns {EntryQueryable} - returns EntryQueryable object for chaining method calls
17-
*/
18-
only(fieldUid: string|string[]): this {
19-
if (Array.isArray(fieldUid)) {
20-
let i = 0;
21-
for (const uid of fieldUid) {
22-
this._queryParams[`only[BASE][${i}]`] = uid;
23-
i++;
24-
}
25-
} else {
26-
this._queryParams["only[BASE][]"] = fieldUid;
27-
}
28-
return this;
29-
}
30-
31-
/**
32-
* @method except
33-
* @memberof EntryQueryable
34-
* @description Excludes specific field/fields of an entry
35-
* @example
36-
* import contentstack from '@contentstack/delivery-sdk'
37-
*
38-
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
39-
* const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find()
40-
*
41-
* @param {string} fieldUid - field uid to exclude
42-
* @returns {EntryQueryable} - returns EntryQueryable object for chaining method calls
43-
*/
44-
except(fieldUid: string|string[]): this {
45-
if (Array.isArray(fieldUid)) {
46-
let i = 0;
47-
for (const uid of fieldUid) {
48-
this._queryParams[`except[BASE][${i}]`] = uid;
49-
i++;
50-
}
51-
} else {
52-
this._queryParams["except[BASE][]"] = fieldUid;
53-
}
54-
55-
return this;
56-
}
5+
576
}

0 commit comments

Comments
 (0)