@@ -2,19 +2,43 @@ import { AxiosInstance, getData } from '@contentstack/core';
22import { TermQuery } from './term-query' ;
33import { Term } from './term' ;
44
5+ /**
6+ * @class Taxonomy
7+ * @description Represents a taxonomy with methods to fetch taxonomy data and manage terms
8+ */
59export class Taxonomy {
610 private _client : AxiosInstance ;
711 private _taxonomyUid : string ;
812 private _urlPath : string ;
913
1014 _queryParams : { [ key : string ] : string | number } = { } ;
1115
16+ /**
17+ * @constructor
18+ * @param {AxiosInstance } client - The HTTP client instance
19+ * @param {string } taxonomyUid - The taxonomy UID
20+ */
1221 constructor ( client : AxiosInstance , taxonomyUid : string ) {
1322 this . _client = client ;
1423 this . _taxonomyUid = taxonomyUid ;
1524 this . _urlPath = `/taxonomy-manager/${ this . _taxonomyUid } ` ; // TODO: change to /taxonomies/${this._taxonomyUid}
1625 }
1726
27+ /**
28+ * @method term
29+ * @memberof Taxonomy
30+ * @description Gets a specific term or creates a term query
31+ * @param {string } [uid] - Optional term UID. If provided, returns a Term instance. If not provided, returns a TermQuery instance.
32+ * @returns {Term | TermQuery }
33+ * @example
34+ * import contentstack from '@contentstack/delivery-sdk'
35+ *
36+ * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
37+ * // Get a specific term
38+ * const term = stack.taxonomy('taxonomy_uid').term('term_uid');
39+ * // Get all terms
40+ * const termQuery = stack.taxonomy('taxonomy_uid').term();
41+ */
1842 term ( uid : string ) : Term ;
1943 term ( ) : TermQuery ;
2044 term ( uid ?: string ) : Term | TermQuery {
@@ -23,6 +47,17 @@ export class Taxonomy {
2347 return new TermQuery ( this . _client , this . _taxonomyUid ) ;
2448 }
2549
50+ /**
51+ * @method fetch
52+ * @memberof Taxonomy
53+ * @description Fetches the taxonomy data by UID
54+ * @returns {Promise<T> }
55+ * @example
56+ * import contentstack from '@contentstack/delivery-sdk'
57+ *
58+ * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" });
59+ * const result = await stack.taxonomy('taxonomy_uid').fetch();
60+ */
2661 async fetch < T > ( ) : Promise < T > {
2762 const response = await getData ( this . _client , this . _urlPath ) ;
2863
0 commit comments