-
Notifications
You must be signed in to change notification settings - Fork 4
Feat/taxonomy publishing #304
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
Draft
harshithad0703
wants to merge
25
commits into
development
Choose a base branch
from
feat/taxonomy-publishing
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
240d7f5
feat: Implement Taxonomy class and update TaxonomyQuery for enhanced …
harshithad0703 77caa3b
Merge pull request #240 from contentstack/feat/dx-3628-get-all-taxonomy
harshithad0703 df96f25
get a single taxonomy
harshithad0703 056fc6d
Merge pull request #242 from contentstack/feat/dx-3629-single-taxonomy
harshithad0703 c213dd8
feat: Add Term and TermQuery classes for enhanced taxonomy term manag…
harshithad0703 b7e629a
refactor: Rename TermQueryFindResponseDataMock to termQueryFindRespon…
harshithad0703 6ed4fdb
Merge pull request #243 from contentstack/feat/dx-3630-get-terms
harshithad0703 908f206
feat: Add locales method to Term class and corresponding tests
harshithad0703 92d633d
refactor: Update locales method in Term class to return data directly…
harshithad0703 33bca3b
Merge pull request #247 from contentstack/feat/dx-3632-terms-loacales
harshithad0703 c4695d8
feat: Add ancestors method to Term class and update related tests
harshithad0703 7a8b8a4
Merge pull request #248 from contentstack/feat/dx-3634-ancestors
harshithad0703 4e97212
feat: Add descendants method to Term class and update related tests
harshithad0703 519c7a3
feat: Enhance Taxonomy and TermQuery classes with detailed documentat…
harshithad0703 62e3994
docs: Update descriptions in Taxonomy and Term classes to clarify pub…
harshithad0703 6a8122f
feat: type definitions for taxonomy management
harshithad0703 75c7d9a
Merge pull request #249 from contentstack/feat/dx-3633-descendants
harshithad0703 19aa8d5
Merge branch 'main' into feat/dx-3797-update-taxonomy-api
harshithad0703 13fa7d9
refactor: update API endpoints from /taxonomy-manager to /taxonomies
harshithad0703 251a61c
Merge branch 'main' into feat/taxonomy-publishing
harshithad0703 d88c4fc
Merge branch 'feat/taxonomy-publishing' into feat/dx-3797-update-taxo…
harshithad0703 a85d2a2
Merge pull request #284 from contentstack/feat/dx-3797-update-taxonom…
harshithad0703 63b49fd
Merge branch 'main' into feat/taxonomy-publishing
harshithad0703 38e9def
Merge branch 'main' into feat/taxonomy-publishing
harshithad0703 43bc2aa
test: update locales test case to include assertions
harshithad0703 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,31 @@ | ||
| import { Query } from "./query"; | ||
| import { AxiosInstance } from "@contentstack/core"; | ||
| import { AxiosInstance, getData } from "@contentstack/core"; | ||
| import { FindResponse } from "./types"; | ||
|
|
||
| export class TaxonomyQuery extends Query { | ||
| constructor(client: AxiosInstance) { | ||
| super(client, {}, {}); // will need make changes to Query class so that CT uid is not mandatory | ||
| this._client = client; | ||
| this._urlPath = `/taxonomies/entries`; | ||
| } | ||
| }; | ||
| constructor(client: AxiosInstance) { | ||
| super(client, {}, {}); // will need make changes to Query class so that CT uid is not mandatory | ||
| this._client = client; | ||
| this._urlPath = `/taxonomies/entries`; | ||
| } | ||
| /** | ||
| * @method find | ||
| * @memberof TaxonomyQuery | ||
| * @description Fetches a list of all published taxonomies available in the stack. | ||
| * @returns {Promise<FindResponse<T>>} | ||
| * @example | ||
| * import contentstack from '@contentstack/delivery-sdk' | ||
| * | ||
| * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); | ||
| * const taxonomyQuery = stack.taxonomy(); | ||
| * const result = await taxonomyQuery.find(); | ||
| */ | ||
| override async find<T>(): Promise<FindResponse<T>> { | ||
| this._urlPath = "/taxonomies"; | ||
| const response = await getData(this._client, this._urlPath, { | ||
| params: this._queryParams, | ||
| }); | ||
|
|
||
| return response as FindResponse<T>; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { AxiosInstance, getData } from '@contentstack/core'; | ||
| import { TermQuery } from './term-query'; | ||
| import { Term } from './term'; | ||
|
|
||
| /** | ||
| * @class Taxonomy | ||
| * @description Represents a published taxonomy with methods to fetch taxonomy data and manage terms. Requires taxonomy_publish feature flag to be enabled. | ||
| */ | ||
| export class Taxonomy { | ||
| private _client: AxiosInstance; | ||
| private _taxonomyUid: string; | ||
| private _urlPath: string; | ||
|
|
||
| _queryParams: { [key: string]: string | number } = {}; | ||
|
|
||
| /** | ||
| * @constructor | ||
| * @param {AxiosInstance} client - The HTTP client instance | ||
| * @param {string} taxonomyUid - The taxonomy UID | ||
| */ | ||
| constructor(client: AxiosInstance, taxonomyUid: string) { | ||
| this._client = client; | ||
| this._taxonomyUid = taxonomyUid; | ||
| this._urlPath = `/taxonomies/${this._taxonomyUid}`; | ||
| } | ||
|
|
||
| /** | ||
| * @method term | ||
| * @memberof Taxonomy | ||
| * @description Gets a specific term or creates a term query | ||
| * @param {string} [uid] - Optional term UID. If provided, returns a Term instance. If not provided, returns a TermQuery instance. | ||
| * @returns {Term | TermQuery} | ||
| * @example | ||
| * import contentstack from '@contentstack/delivery-sdk' | ||
| * | ||
| * const stack = contentstack.stack({ apiKey: "apiKey", deliveryToken: "deliveryToken", environment: "environment" }); | ||
| * // Get a specific term | ||
| * const term = stack.taxonomy('taxonomy_uid').term('term_uid'); | ||
| * // Get all terms | ||
| * const termQuery = stack.taxonomy('taxonomy_uid').term(); | ||
| */ | ||
| term(uid: string): Term; | ||
| term(): TermQuery; | ||
| term(uid?: string): Term | TermQuery { | ||
| if (uid) return new Term(this._client, this._taxonomyUid, uid); | ||
|
|
||
| return new TermQuery(this._client, this._taxonomyUid); | ||
| } | ||
|
|
||
| /** | ||
| * @method fetch | ||
| * @memberof Taxonomy | ||
| * @description Fetches the taxonomy data by UID | ||
| * @returns {Promise<T>} | ||
| * @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(); | ||
| */ | ||
| async fetch<T>(): Promise<T> { | ||
| const response = await getData(this._client, this._urlPath); | ||
|
|
||
| if (response.taxonomy) return response.taxonomy as T; | ||
|
|
||
| return response; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { AxiosInstance, getData } from '@contentstack/core'; | ||
| import { FindResponse } from './types'; | ||
|
|
||
| /** | ||
| * @class TermQuery | ||
| * @description Represents a query for fetching multiple published terms from a taxonomy. Requires taxonomy_publish feature flag to be enabled. | ||
| */ | ||
| export class TermQuery { | ||
| private _taxonomyUid: string; | ||
| private _client: AxiosInstance; | ||
| private _urlPath: string; | ||
| _queryParams: { [key: string]: string | number } = {}; | ||
|
|
||
| /** | ||
| * @constructor | ||
| * @param {AxiosInstance} client - The HTTP client instance | ||
| * @param {string} taxonomyUid - The taxonomy UID | ||
| */ | ||
| constructor(client: AxiosInstance, taxonomyUid: string) { | ||
| this._client = client; | ||
| this._taxonomyUid = taxonomyUid; | ||
| this._urlPath = `/taxonomies/${this._taxonomyUid}/terms`; | ||
| } | ||
|
|
||
| /** | ||
| * @method find | ||
| * @memberof TermQuery | ||
| * @description Fetches a list of all published terms within a specific taxonomy. | ||
| * @returns {Promise<FindResponse<T>>} | ||
| * @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().find(); | ||
| */ | ||
| async find<T>(): Promise<FindResponse<T>> { | ||
| const response = await getData(this._client, this._urlPath, { params: this._queryParams }); | ||
| return response as FindResponse<T>; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { AxiosInstance, getData } from "@contentstack/core"; | ||
|
|
||
| /** | ||
| * @class Term | ||
| * @description Represents a published taxonomy term with methods to fetch term data, locales, ancestors, and descendants. Requires taxonomy_publish feature flag to be enabled. | ||
| */ | ||
| export class Term { | ||
| protected _client: AxiosInstance; | ||
| private _taxonomyUid: string; | ||
| private _termUid: string; | ||
| private _urlPath: string; | ||
|
|
||
| /** | ||
| * @constructor | ||
| * @param {AxiosInstance} client - The HTTP client instance | ||
| * @param {string} taxonomyUid - The taxonomy UID | ||
| * @param {string} termUid - The term UID | ||
| */ | ||
| constructor(client: AxiosInstance, taxonomyUid: string, termUid: string) { | ||
| this._client = client; | ||
| this._taxonomyUid = taxonomyUid; | ||
| this._termUid = termUid; | ||
| this._urlPath = `/taxonomies/${this._taxonomyUid}/terms/${this._termUid}`; | ||
| } | ||
|
|
||
| /** | ||
| * @method locales | ||
| * @memberof Term | ||
| * @description Fetches all published, localized versions of a single term. | ||
| * @returns {Promise<T>} | ||
| * @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').locales(); | ||
| */ | ||
| async locales<T>(): Promise<T> { | ||
| const response = await getData(this._client, `${this._urlPath}/locales`); | ||
| if (response.locales) return response.locales as T; | ||
| return response; | ||
| } | ||
|
|
||
| /** | ||
| * @method ancestors | ||
| * @memberof Term | ||
| * @description Fetches all ancestors of a single published term, up to the root. | ||
| * @returns {Promise<T>} | ||
| * @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').ancestors(); | ||
| */ | ||
| async ancestors<T>(): Promise<T> { | ||
| const response = await getData(this._client, `${this._urlPath}/ancestors`); | ||
| if (response.ancestors) return response.ancestors as T; | ||
| return response; | ||
| } | ||
|
|
||
| /** | ||
| * @method descendants | ||
| * @memberof Term | ||
| * @description Fetches all descendants of a single published term. | ||
| * @returns {Promise<T>} | ||
| * @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').descendants(); | ||
| */ | ||
| async descendants<T>(): Promise<T> { | ||
| const response = await getData(this._client, `${this._urlPath}/descendants`); | ||
| if (response.descendants) return response.descendants as T; | ||
| return response; | ||
| } | ||
|
|
||
| /** | ||
| * @method fetch | ||
| * @memberof Term | ||
| * @description Fetches all descendants of a single published term. | ||
| * @returns {Promise<T>} | ||
| * @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(); | ||
| */ | ||
| async fetch<T>(): Promise<T> { | ||
| const response = await getData(this._client, this._urlPath); | ||
| if (response.term) return response.term as T; | ||
| return response; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* eslint-disable no-console */ | ||
| /* eslint-disable promise/always-return */ | ||
| import { stackInstance } from '../utils/stack-instance'; | ||
| import { TTaxonomies, TTaxonomy } from './types'; | ||
| import dotenv from 'dotenv'; | ||
| import { TaxonomyQuery } from '../../src/lib/taxonomy-query'; | ||
| import { Taxonomy } from '../../src/lib/taxonomy'; | ||
|
|
||
| dotenv.config() | ||
|
|
||
| const stack = stackInstance(); | ||
| describe('ContentType API test cases', () => { | ||
| it('should give taxonomies when taxonomies method is called', async () => { | ||
| const result = await makeTaxonomies().find<TTaxonomies>(); | ||
| expect(result).toBeDefined(); | ||
| }); | ||
|
|
||
| it('should give a single taxonomy when taxonomy method is called with taxonomyUid', async () => { | ||
| const result = await makeTaxonomy('taxonomy_testing').fetch<TTaxonomy>(); | ||
| expect(result).toBeDefined(); | ||
| }); | ||
| }); | ||
|
|
||
| function makeTaxonomies(): TaxonomyQuery { | ||
| const taxonomies = stack.taxonomy(); | ||
|
|
||
| return taxonomies; | ||
| } | ||
|
|
||
| function makeTaxonomy(taxonomyUid: string): Taxonomy { | ||
| const taxonomy = stack.taxonomy(taxonomyUid); | ||
| return taxonomy; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harshithad0703 Fix this docstring