diff --git a/CHANGELOG.md b/CHANGELOG.md index c92f049..4703151 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## Change log +### Version: 4.3.0 +#### Date: Septmber-09-2024 +Feat: Include refernce accepts array of values + ### Version: 4.2.0 #### Date: Septmber-04-2024 Feat: Variants support added diff --git a/package-lock.json b/package-lock.json index 947f608..923ed75 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.2.0", + "version": "4.3.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "4.2.0", + "version": "4.3.0", "dependencies": { "@contentstack/core": "^1.1.0", "@contentstack/utils": "^1.3.8", diff --git a/package.json b/package.json index b212054..c34286a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "4.2.0", + "version": "4.3.0", "type": "commonjs", "main": "./dist/cjs/src/index.js", "types": "./dist/types/src/index.d.ts", diff --git a/src/lib/entries.ts b/src/lib/entries.ts index b886ab9..f5640ae 100644 --- a/src/lib/entries.ts +++ b/src/lib/entries.ts @@ -111,9 +111,17 @@ export class Entries extends EntryQueryable { * @param {string} referenceFieldUid - UID of the reference field to include. * @returns {Entries} - Returns the Entries instance for chaining. */ - includeReference(referenceFieldUid: string): Entries { - this._queryParams['include[]'] = referenceFieldUid; - + includeReference(...referenceFieldUid: (string | string[])[]): Entries { + if (referenceFieldUid.length) { + referenceFieldUid.forEach(value => { + if (!Array.isArray(this._queryParams['include[]'])) { + this._queryParams['include[]'] = []; + } + (this._queryParams['include[]'] as string[]).push(...(Array.isArray(value) ? value : [value])); + }); + } else { + console.error("Argument should be a String or an Array."); + } return this; } diff --git a/src/lib/entry.ts b/src/lib/entry.ts index e764645..b712f29 100644 --- a/src/lib/entry.ts +++ b/src/lib/entry.ts @@ -8,7 +8,7 @@ export class Entry { private _contentTypeUid: string; private _entryUid: string; private _urlPath: string; - _queryParams: { [key: string]: string | number } = {}; + _queryParams: { [key: string]: string | number | string[] } = {}; constructor(client: AxiosInstance, contentTypeUid: string, entryUid: string) { this._client = client; diff --git a/src/lib/internal-types.ts b/src/lib/internal-types.ts index aa5912a..5c998d8 100644 --- a/src/lib/internal-types.ts +++ b/src/lib/internal-types.ts @@ -3,5 +3,5 @@ export type params = { } export type queryParams = { - [key: string]: string | boolean | number + [key: string]: string | boolean | number | string[] } diff --git a/test/unit/entries.spec.ts b/test/unit/entries.spec.ts index 9e7aa4d..793d1d9 100644 --- a/test/unit/entries.spec.ts +++ b/test/unit/entries.spec.ts @@ -35,9 +35,9 @@ describe('Entries class', () => { it('should set the include parameter to the given reference field UID', () => { const referenceFieldUid = 'referenceFieldUid'; entry.includeReference(referenceFieldUid); + expect(entry._queryParams['include[]']).toContain(referenceFieldUid); +}); - expect(entry._queryParams['include[]']).toBe(referenceFieldUid); - }); it('should add "include_fallback" in _queryParams when includeFallback method is called', () => { const returnedValue = entry.includeFallback();