Skip to content

Fix/dx 3133 urlencode for query string #186

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 10 commits into from
Jun 13, 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
32 changes: 20 additions & 12 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,24 @@ fileignoreconfig:
- filename: .github/workflows/secrets-scan.yml
ignore_detectors:
- filecontent
- filename: src/lib/types.ts
checksum: 1eb6d6ec971934d65017dae2f82d6d6ef1cd0e6bfd50f43a9b46f30182307230
- filename: test/unit/image-transform.spec.ts
checksum: 7beabdd07bd35d620668fcd97e1a303b9cbc40170bf3008a376d75ce0895de2a
- filename: test/utils/mocks.ts
checksum: a1cb4b1890a584f1facd30f2a0974c97a66f91417022be79d00516338e244227
- filename: src/lib/query.ts
checksum: c4529069bc974d15c104303c5ae573c9341185a869c612ab07f0ee7f42e8b149
- filename: package-lock.json
checksum: 815fd2251550d87a0f113dd2e14266879be37af3a264041e871436a1cc84ae1c
- filename: .husky/pre-commit
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
- filename: src/lib/types.ts
checksum: 1eb6d6ec971934d65017dae2f82d6d6ef1cd0e6bfd50f43a9b46f30182307230
- filename: test/unit/image-transform.spec.ts
checksum: 7beabdd07bd35d620668fcd97e1a303b9cbc40170bf3008a376d75ce0895de2a
- filename: test/utils/mocks.ts
checksum: a1cb4b1890a584f1facd30f2a0974c97a66f91417022be79d00516338e244227
- filename: src/lib/query.ts
checksum: c4529069bc974d15c104303c5ae573c9341185a869c612ab07f0ee7f42e8b149
- filename: package-lock.json
checksum: f9c5af529a2c4c6576d67bd6c25dc6c3088ddedf2482757d382953f2d4521995
- filename: src/lib/entries.ts
checksum: 1c9a58570f26d3e53526e89b404581a523d3f035234bc099fda96d144dee40f6
- filename: src/lib/entry.ts
checksum: 8826fe3147a2c640b0780dae02345611ed24e562562e7df7b3785cb0fa6f1f14
- filename: .husky/pre-commit
checksum: 5baabd7d2c391648163f9371f0e5e9484f8fb90fa2284cfc378732ec3192c193
version: ""
fileignoreconfig:
- filename: package-lock.json
checksum: be08fac0b5e580b7dd66f5dc2b2f7bdefeef89b98ce60df1fe31ad33adb96172
version: "1.0"
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
### Version: 4.7.1
#### Date: June-13-2025
- Add encode option on find method to encode query params

### Version: 4.7.0
#### Date: Apr-29-2025
- Added return type for entry-querable method
- Added support of top-level export of Stack type in @contentstack/delivery-sdk for compatibility with "moduleResolution": "Bundler".

### Version: 4.6.1
#### Date: March-24-2025
Fix: Update imports and dependencies
Expand Down
2,943 changes: 1,939 additions & 1,004 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@contentstack/delivery-sdk",
"version": "4.7.0",
"version": "4.7.1",
"type": "module",
"license": "MIT",
"main": "./dist/legacy/index.cjs",
Expand Down
11 changes: 9 additions & 2 deletions src/lib/base-query.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AxiosInstance, getData } from '@contentstack/core';
import { Pagination } from './pagination';
import { FindResponse, params } from './types';
import { encodeQueryParams } from './utils';

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

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

if (Object.keys(this._parameters).length > 0) {
requestParams = { ...this._queryParams, query: { ...this._parameters } };
let queryParams = { ...this._parameters };

if (encode) {
queryParams = encodeQueryParams(queryParams);
}

requestParams = { ...this._queryParams, query: queryParams };
}

const getRequestOptions: any = { params: requestParams };
Expand Down
97 changes: 75 additions & 22 deletions src/lib/entries.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AxiosInstance, getData } from '@contentstack/core';
import { EntryQueryable } from './entry-queryable';
import { Query } from './query';
import { BaseQuery } from './base-query';

export class Entries extends EntryQueryable {
export class Entries extends BaseQuery {
private _contentTypeUid: string;

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

/**
* @method includeFallback
* @method except
* @memberof Entries
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
* @description Excludes specific field/fields of an entry
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find()
*
* @param {string} fieldUid - field uid to exclude
* @returns {Entries} - returns Entries object for chaining method calls
*/
except(fieldUid: string|string[]): this {
if (Array.isArray(fieldUid)) {
let i = 0;
for (const uid of fieldUid) {
this._queryParams[`except[BASE][${i}]`] = uid;
i++;
}
} else {
this._queryParams["except[BASE][]"] = fieldUid;
}

return this;
}

/**
* @method includeBranch
* @memberof Entries
* @description Includes the branch in result
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contentType_uid).entry().includeFallback().find();
* const result = await stack.contentType(contentType_uid).entry().includeBranch().find();
*/
includeFallback(): Entries {
this._queryParams.include_fallback = 'true';
includeBranch(): Entries {
this._queryParams.include_branch = 'true';

return this;
}

/**
* @method includeMetadata
* @method includeContentType
* @memberof Entries
* @description Include the metadata for getting metadata content for the entry.
* @description IInclude the details of the content type along with the entries details
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contentType_uid).entry().includeMetadata().find();
* const result = await stack.contentType(contentType_uid).entry().includeContentType().fetch();
*/
includeMetadata(): Entries {
this._queryParams.include_metadata = 'true';
includeContentType(): Entries {
this._queryParams.include_content_type = 'true';

return this;
}
Expand All @@ -65,35 +92,35 @@ export class Entries extends EntryQueryable {
}

/**
* @method includeContentType
* @method includeFallback
* @memberof Entries
* @description IInclude the details of the content type along with the entries details
* @description When an entry is not published in a specific language, content can be fetched from its fallback language
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contentType_uid).entry().includeContentType().fetch();
* const result = await stack.contentType(contentType_uid).entry().includeFallback().find();
*/
includeContentType(): Entries {
this._queryParams.include_content_type = 'true';
includeFallback(): Entries {
this._queryParams.include_fallback = 'true';

return this;
}

/**
* @method includeBranch
* @method includeMetadata
* @memberof Entries
* @description Includes the branch in result
* @description Include the metadata for getting metadata content for the entry.
* @returns {Entries}
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType(contentType_uid).entry().includeBranch().find();
* const result = await stack.contentType(contentType_uid).entry().includeMetadata().find();
*/
includeBranch(): Entries {
this._queryParams.include_branch = 'true';
includeMetadata(): Entries {
this._queryParams.include_metadata = 'true';

return this;
}
Expand Down Expand Up @@ -177,6 +204,32 @@ export class Entries extends EntryQueryable {
return this;
}

/**
* @method only
* @memberof Entries
* @description Selects specific field/fields of an entry
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find()
*
* @param {string} fieldUid - field uid to select
* @returns {Entries} - returns Entries object for chaining method calls
*/
only(fieldUid: string|string[]): this {
if (Array.isArray(fieldUid)) {
let i = 0;
for (const uid of fieldUid) {
this._queryParams[`only[BASE][${i}]`] = uid;
i++;
}
} else {
this._queryParams["only[BASE][]"] = fieldUid;
}
return this;
}

/**
* @method query
* @memberof Entries
Expand Down
53 changes: 1 addition & 52 deletions src/lib/entry-queryable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,56 +2,5 @@ import { BaseQuery } from './base-query';

/* eslint-disable @cspell/spellchecker */
export class EntryQueryable extends BaseQuery {
/**
* @method only
* @memberof EntryQueryable
* @description Selects specific field/fields of an entry
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry().only("fieldUID").find()
*
* @param {string} fieldUid - field uid to select
* @returns {EntryQueryable} - returns EntryQueryable object for chaining method calls
*/
only(fieldUid: string|string[]): this {
if (Array.isArray(fieldUid)) {
let i = 0;
for (const uid of fieldUid) {
this._queryParams[`only[BASE][${i}]`] = uid;
i++;
}
} else {
this._queryParams["only[BASE][]"] = fieldUid;
}
return this;
}

/**
* @method except
* @memberof EntryQueryable
* @description Excludes specific field/fields of an entry
* @example
* import contentstack from '@contentstack/delivery-sdk'
*
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
* const result = await stack.contentType("contentTypeUid").entry().except("fieldUID").find()
*
* @param {string} fieldUid - field uid to exclude
* @returns {EntryQueryable} - returns EntryQueryable object for chaining method calls
*/
except(fieldUid: string|string[]): this {
if (Array.isArray(fieldUid)) {
let i = 0;
for (const uid of fieldUid) {
this._queryParams[`except[BASE][${i}]`] = uid;
i++;
}
} else {
this._queryParams["except[BASE][]"] = fieldUid;
}

return this;
}

}
Loading
Loading