Skip to content

Commit 6fcb900

Browse files
authored
Merge pull request #379 from contentstack/feat/taxonomy-publishing-v5.4.0
feat(taxonomy): remove locale param from fetch(), bump to v5.4.0
2 parents c50679f + 34113cc commit 6fcb900

9 files changed

Lines changed: 34 additions & 31 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
### Version: 5.4.0
2+
#### Date: Jul-16-2026
3+
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.
4+
- `.param('locale', 'fr-fr').fetch()` is the correct pattern for localized taxonomy/term fetches
5+
- Updated all tests and the `taxonomy-demo.mjs` script to use the new pattern
6+
- No breaking change for calls that did not pass locale to `fetch()`
7+
18
### Version: 5.3.0
29
#### Date: Jul-16-2026
310
Feature: Added Taxonomy Publishing support to the Content Delivery SDK via `stack.taxonomy()`.

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/delivery-sdk",
3-
"version": "5.3.0",
3+
"version": "5.4.0",
44
"type": "module",
55
"license": "MIT",
66
"engines": {

src/taxonomy/index.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,18 +121,16 @@ export class Taxonomy {
121121
/**
122122
* @method fetch
123123
* @memberof Taxonomy
124-
* @description Fetches the taxonomy data by UID. Pass a locale code to retrieve the localized version.
125-
* @param {string} [locale] - Optional locale code (e.g. 'hi-in'). Omit to retrieve the master locale.
124+
* @description Fetches the taxonomy data by UID. Use param() or addParams() to pass locale or other query parameters.
126125
* @returns {Promise<T>}
127126
* @example
128127
* import contentstack from '@contentstack/delivery-sdk'
129128
*
130129
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
131130
* const result = await stack.taxonomy('taxonomy_uid').fetch();
132-
* const localized = await stack.taxonomy('taxonomy_uid').fetch('hi-in');
131+
* const localized = await stack.taxonomy('taxonomy_uid').param('locale', 'hi-in').fetch();
133132
*/
134-
async fetch<T>(locale?: string): Promise<T> {
135-
if (locale) this._queryParams.locale = locale;
133+
async fetch<T>(): Promise<T> {
136134
const response = await getData(this._client, this._urlPath, { params: this._queryParams });
137135

138136
if (response.taxonomy) return response.taxonomy as T;

src/taxonomy/term.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,18 +168,16 @@ export class Term {
168168
/**
169169
* @method fetch
170170
* @memberof Term
171-
* @description Fetches a single published term. Pass a locale code to retrieve the localized version.
172-
* @param {string} [locale] - Optional locale code (e.g. 'mr-in'). Omit to retrieve the master locale.
171+
* @description Fetches a single published term. Use param() or addParams() to pass locale or other query parameters.
173172
* @returns {Promise<T>}
174173
* @example
175174
* import contentstack from '@contentstack/delivery-sdk'
176175
*
177176
* const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
178177
* const result = await stack.taxonomy('taxonomy_uid').term('term_uid').fetch();
179-
* const localized = await stack.taxonomy('taxonomy_uid').term('term_uid').fetch('mr-in');
178+
* const localized = await stack.taxonomy('taxonomy_uid').term('term_uid').param('locale', 'hi-in').fetch();
180179
*/
181-
async fetch<T>(locale?: string): Promise<T> {
182-
if (locale) this._queryParams.locale = locale;
180+
async fetch<T>(): Promise<T> {
183181
const response = await getData(this._client, this._urlPath, { params: this._queryParams });
184182
if (response.term) return response.term as T;
185183
return response;

test/api/taxonomy.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,21 @@ describe('Taxonomy API test cases', () => {
2121
expect(result).toBeDefined();
2222
});
2323

24-
it('should give a localized taxonomy when a locale is passed to fetch', async () => {
25-
const result = await makeTaxonomy(countryUsa).fetch<TTaxonomy>(locale);
24+
it('should give a localized taxonomy when locale is set via param()', async () => {
25+
const result = await makeTaxonomy(countryUsa).param('locale', locale).fetch<TTaxonomy>();
2626
expect(result).toBeDefined();
2727
if (result.publish_details) {
2828
expect(result.publish_details.locale).toBeDefined();
2929
}
3030
});
3131

3232
it('should give a taxonomy with locale fallback when includeFallback is chained', async () => {
33-
const result = await makeTaxonomy(countryUsa).includeFallback().fetch<TTaxonomy>(locale);
33+
const result = await makeTaxonomy(countryUsa).param('locale', locale).includeFallback().fetch<TTaxonomy>();
3434
expect(result).toBeDefined();
3535
});
3636

37-
it('should give a localized taxonomy when fetch is called with locale', async () => {
38-
const result = await makeTaxonomy('gadgets').fetch<TTaxonomy>('fr-fr');
37+
it('should give a localized taxonomy when locale is set via param()', async () => {
38+
const result = await makeTaxonomy('gadgets').param('locale', 'fr-fr').fetch<TTaxonomy>();
3939
expect(result).toBeDefined();
4040
});
4141
});
@@ -47,8 +47,8 @@ describe('Taxonomy API test cases - gadgets', () => {
4747
expect(result.uid).toBe('gadgets');
4848
});
4949

50-
it('should fetch gadgets taxonomy in fr-fr locale', async () => {
51-
const result = await makeTaxonomy('gadgets').fetch<TTaxonomy>('fr-fr');
50+
it('should fetch gadgets taxonomy in fr-fr locale via param()', async () => {
51+
const result = await makeTaxonomy('gadgets').param('locale', 'fr-fr').fetch<TTaxonomy>();
5252
expect(result).toBeDefined();
5353
expect(result.uid).toBe('gadgets');
5454
expect(result.locale).toBe('fr-fr');

test/api/term.spec.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,21 @@ describe("Terms API test cases", () => {
1818
expect(result.updated_by).toBeDefined();
1919
});
2020

21-
it("should get a localized term when a locale is passed to fetch", async () => {
22-
const result = await makeTerms("texas").fetch<TTerm>(locale);
21+
it("should get a localized term when locale is set via param()", async () => {
22+
const result = await makeTerms("texas").param('locale', locale).fetch<TTerm>();
2323
expect(result).toBeDefined();
2424
if (result.publish_details) {
2525
expect(result.publish_details.locale).toBeDefined();
2626
}
2727
});
2828

2929
it("should get a term with locale fallback when includeFallback is chained", async () => {
30-
const result = await makeTerms("texas").includeFallback().fetch<TTerm>(locale);
30+
const result = await makeTerms("texas").param('locale', locale).includeFallback().fetch<TTerm>();
3131
expect(result).toBeDefined();
3232
});
3333

34-
it("should get a localized term when fetch is called with locale", async () => {
35-
const result = await stack.taxonomy("gadgets").term("smartphone").fetch<TTerm>("fr-fr");
34+
it("should get a localized term when locale is set via param()", async () => {
35+
const result = await stack.taxonomy("gadgets").term("smartphone").param('locale', 'fr-fr').fetch<TTerm>();
3636
expect(result).toBeDefined();
3737
});
3838

@@ -71,8 +71,8 @@ describe("Terms API test cases - gadgets taxonomy", () => {
7171
expect(result.taxonomy_uid).toBe("gadgets");
7272
});
7373

74-
it("should fetch smartphone term from gadgets in fr-fr locale", async () => {
75-
const result = await stack.taxonomy("gadgets").term("smartphone").fetch<TTerm>("fr-fr");
74+
it("should fetch smartphone term from gadgets in fr-fr locale via param()", async () => {
75+
const result = await stack.taxonomy("gadgets").term("smartphone").param('locale', 'fr-fr').fetch<TTerm>();
7676
expect(result).toBeDefined();
7777
expect(result.uid).toBe("smartphone");
7878
expect(result.locale).toBe("fr-fr");

test/unit/taxonomy.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ describe('ta class', () => {
5454
await taxonomy.includeFallback().includeBranch().param('locale', 'fr-fr').fetch();
5555
});
5656

57-
it('should return localized taxonomy when fetch is called with locale', async () => {
57+
it('should return localized taxonomy when param is used to set locale', async () => {
5858
mockClient.onGet('/taxonomies/taxonomy_testing').reply(200, taxonomyLocalizedFetchMock);
59-
const response = await taxonomy.fetch('hi-in');
59+
const response = await taxonomy.param('locale', 'hi-in').fetch();
6060
expect(response).toEqual(taxonomyLocalizedFetchMock.taxonomy);
6161
});
6262
});

test/unit/term.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,10 @@ describe('Term class', () => {
7676
await term.param('depth', 1).addParams({ locale: 'fr-fr' }).ancestors();
7777
});
7878

79-
it('should fetch localized term when fetch is called with locale', async () => {
79+
it('should fetch localized term when param is used to set locale', async () => {
8080
mockClient.onGet('/taxonomies/taxonomy_testing/terms/term1').reply(200, termLocalizedFetchMock);
8181

82-
const response = await term.fetch('hi-in');
82+
const response = await term.param('locale', 'hi-in').fetch();
8383
expect(response).toEqual(termLocalizedFetchMock.term);
8484
});
8585
});

0 commit comments

Comments
 (0)