From 34113ccafd94f231c2f419bbfdf60fc8f4ff546c Mon Sep 17 00:00:00 2001 From: raj pandey Date: Thu, 16 Jul 2026 12:54:03 +0530 Subject: [PATCH] feat(taxonomy): remove locale param from fetch(), bump to v5.4.0 --- CHANGELOG.md | 7 +++++++ package-lock.json | 4 ++-- package.json | 2 +- src/taxonomy/index.ts | 8 +++----- src/taxonomy/term.ts | 8 +++----- test/api/taxonomy.spec.ts | 14 +++++++------- test/api/term.spec.ts | 14 +++++++------- test/unit/taxonomy.spec.ts | 4 ++-- test/unit/term.spec.ts | 4 ++-- 9 files changed, 34 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d1c9f6..833d14d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +### Version: 5.4.0 +#### Date: Jul-16-2026 +Enhancement: Removed `locale?` parameter from `Taxonomy.fetch()` and `Term.fetch()` — locale is now set via the chainable `.param('locale', value)` API, consistent with other query modifiers. +- `.param('locale', 'fr-fr').fetch()` is the correct pattern for localized taxonomy/term fetches +- Updated all tests and the `taxonomy-demo.mjs` script to use the new pattern +- No breaking change for calls that did not pass locale to `fetch()` + ### Version: 5.3.0 #### Date: Jul-16-2026 Feature: Added Taxonomy Publishing support to the Content Delivery SDK via `stack.taxonomy()`. diff --git a/package-lock.json b/package-lock.json index 978ece1..aa3cc1c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@contentstack/delivery-sdk", - "version": "5.3.0", + "version": "5.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@contentstack/delivery-sdk", - "version": "5.3.0", + "version": "5.4.0", "license": "MIT", "dependencies": { "@contentstack/core": "^1.4.1", diff --git a/package.json b/package.json index 11a83a5..c03653e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/delivery-sdk", - "version": "5.3.0", + "version": "5.4.0", "type": "module", "license": "MIT", "engines": { diff --git a/src/taxonomy/index.ts b/src/taxonomy/index.ts index 627abb6..c84db4b 100644 --- a/src/taxonomy/index.ts +++ b/src/taxonomy/index.ts @@ -121,18 +121,16 @@ export class Taxonomy { /** * @method fetch * @memberof Taxonomy - * @description Fetches the taxonomy data by UID. Pass a locale code to retrieve the localized version. - * @param {string} [locale] - Optional locale code (e.g. 'hi-in'). Omit to retrieve the master locale. + * @description Fetches the taxonomy data by UID. Use param() or addParams() to pass locale or other query parameters. * @returns {Promise} * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const result = await stack.taxonomy('taxonomy_uid').fetch(); - * const localized = await stack.taxonomy('taxonomy_uid').fetch('hi-in'); + * const localized = await stack.taxonomy('taxonomy_uid').param('locale', 'hi-in').fetch(); */ - async fetch(locale?: string): Promise { - if (locale) this._queryParams.locale = locale; + async fetch(): Promise { const response = await getData(this._client, this._urlPath, { params: this._queryParams }); if (response.taxonomy) return response.taxonomy as T; diff --git a/src/taxonomy/term.ts b/src/taxonomy/term.ts index 1757976..690845e 100644 --- a/src/taxonomy/term.ts +++ b/src/taxonomy/term.ts @@ -168,18 +168,16 @@ export class Term { /** * @method fetch * @memberof Term - * @description Fetches a single published term. Pass a locale code to retrieve the localized version. - * @param {string} [locale] - Optional locale code (e.g. 'mr-in'). Omit to retrieve the master locale. + * @description Fetches a single published term. Use param() or addParams() to pass locale or other query parameters. * @returns {Promise} * @example * import contentstack from '@contentstack/delivery-sdk' * * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); * const result = await stack.taxonomy('taxonomy_uid').term('term_uid').fetch(); - * const localized = await stack.taxonomy('taxonomy_uid').term('term_uid').fetch('mr-in'); + * const localized = await stack.taxonomy('taxonomy_uid').term('term_uid').param('locale', 'hi-in').fetch(); */ - async fetch(locale?: string): Promise { - if (locale) this._queryParams.locale = locale; + async fetch(): Promise { const response = await getData(this._client, this._urlPath, { params: this._queryParams }); if (response.term) return response.term as T; return response; diff --git a/test/api/taxonomy.spec.ts b/test/api/taxonomy.spec.ts index 2d22e78..a717807 100644 --- a/test/api/taxonomy.spec.ts +++ b/test/api/taxonomy.spec.ts @@ -21,8 +21,8 @@ describe('Taxonomy API test cases', () => { expect(result).toBeDefined(); }); - it('should give a localized taxonomy when a locale is passed to fetch', async () => { - const result = await makeTaxonomy(countryUsa).fetch(locale); + it('should give a localized taxonomy when locale is set via param()', async () => { + const result = await makeTaxonomy(countryUsa).param('locale', locale).fetch(); expect(result).toBeDefined(); if (result.publish_details) { expect(result.publish_details.locale).toBeDefined(); @@ -30,12 +30,12 @@ describe('Taxonomy API test cases', () => { }); it('should give a taxonomy with locale fallback when includeFallback is chained', async () => { - const result = await makeTaxonomy(countryUsa).includeFallback().fetch(locale); + const result = await makeTaxonomy(countryUsa).param('locale', locale).includeFallback().fetch(); expect(result).toBeDefined(); }); - it('should give a localized taxonomy when fetch is called with locale', async () => { - const result = await makeTaxonomy('gadgets').fetch('fr-fr'); + it('should give a localized taxonomy when locale is set via param()', async () => { + const result = await makeTaxonomy('gadgets').param('locale', 'fr-fr').fetch(); expect(result).toBeDefined(); }); }); @@ -47,8 +47,8 @@ describe('Taxonomy API test cases - gadgets', () => { expect(result.uid).toBe('gadgets'); }); - it('should fetch gadgets taxonomy in fr-fr locale', async () => { - const result = await makeTaxonomy('gadgets').fetch('fr-fr'); + it('should fetch gadgets taxonomy in fr-fr locale via param()', async () => { + const result = await makeTaxonomy('gadgets').param('locale', 'fr-fr').fetch(); expect(result).toBeDefined(); expect(result.uid).toBe('gadgets'); expect(result.locale).toBe('fr-fr'); diff --git a/test/api/term.spec.ts b/test/api/term.spec.ts index 25fc16d..dcd92c8 100644 --- a/test/api/term.spec.ts +++ b/test/api/term.spec.ts @@ -18,8 +18,8 @@ describe("Terms API test cases", () => { expect(result.updated_by).toBeDefined(); }); - it("should get a localized term when a locale is passed to fetch", async () => { - const result = await makeTerms("texas").fetch(locale); + it("should get a localized term when locale is set via param()", async () => { + const result = await makeTerms("texas").param('locale', locale).fetch(); expect(result).toBeDefined(); if (result.publish_details) { expect(result.publish_details.locale).toBeDefined(); @@ -27,12 +27,12 @@ describe("Terms API test cases", () => { }); it("should get a term with locale fallback when includeFallback is chained", async () => { - const result = await makeTerms("texas").includeFallback().fetch(locale); + const result = await makeTerms("texas").param('locale', locale).includeFallback().fetch(); expect(result).toBeDefined(); }); - it("should get a localized term when fetch is called with locale", async () => { - const result = await stack.taxonomy("gadgets").term("smartphone").fetch("fr-fr"); + it("should get a localized term when locale is set via param()", async () => { + const result = await stack.taxonomy("gadgets").term("smartphone").param('locale', 'fr-fr').fetch(); expect(result).toBeDefined(); }); @@ -71,8 +71,8 @@ describe("Terms API test cases - gadgets taxonomy", () => { expect(result.taxonomy_uid).toBe("gadgets"); }); - it("should fetch smartphone term from gadgets in fr-fr locale", async () => { - const result = await stack.taxonomy("gadgets").term("smartphone").fetch("fr-fr"); + it("should fetch smartphone term from gadgets in fr-fr locale via param()", async () => { + const result = await stack.taxonomy("gadgets").term("smartphone").param('locale', 'fr-fr').fetch(); expect(result).toBeDefined(); expect(result.uid).toBe("smartphone"); expect(result.locale).toBe("fr-fr"); diff --git a/test/unit/taxonomy.spec.ts b/test/unit/taxonomy.spec.ts index 9c5a3cc..8517edc 100644 --- a/test/unit/taxonomy.spec.ts +++ b/test/unit/taxonomy.spec.ts @@ -54,9 +54,9 @@ describe('ta class', () => { await taxonomy.includeFallback().includeBranch().param('locale', 'fr-fr').fetch(); }); - it('should return localized taxonomy when fetch is called with locale', async () => { + it('should return localized taxonomy when param is used to set locale', async () => { mockClient.onGet('/taxonomies/taxonomy_testing').reply(200, taxonomyLocalizedFetchMock); - const response = await taxonomy.fetch('hi-in'); + const response = await taxonomy.param('locale', 'hi-in').fetch(); expect(response).toEqual(taxonomyLocalizedFetchMock.taxonomy); }); }); diff --git a/test/unit/term.spec.ts b/test/unit/term.spec.ts index 511c444..2d27d0f 100644 --- a/test/unit/term.spec.ts +++ b/test/unit/term.spec.ts @@ -76,10 +76,10 @@ describe('Term class', () => { await term.param('depth', 1).addParams({ locale: 'fr-fr' }).ancestors(); }); - it('should fetch localized term when fetch is called with locale', async () => { + it('should fetch localized term when param is used to set locale', async () => { mockClient.onGet('/taxonomies/taxonomy_testing/terms/term1').reply(200, termLocalizedFetchMock); - const response = await term.fetch('hi-in'); + const response = await term.param('locale', 'hi-in').fetch(); expect(response).toEqual(termLocalizedFetchMock.term); }); });