diff --git a/CHANGELOG.md b/CHANGELOG.md index 23923286..02ac5b48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,13 @@ # Changelog -## [v1.13.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.1) (2023-12-13) - - Fixes - - Fix for issue while updating entries with assets - +## [v1.15.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.15.0) (2024-01-23) + - Feature + - Taxonomy Import/Export feature added ## [v1.14.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.14.0) (2023-12-19) - Feature - Management token feature added +## [v1.13.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.1) (2023-12-13) + - Fixes + - Fix for issue while updating entries with assets ## [v1.13.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.13.0) (2023-11-21) - Feature - Teams API support diff --git a/README.md b/README.md index 1296e588..432838fb 100644 --- a/README.md +++ b/README.md @@ -104,7 +104,7 @@ contentstackClient.stack({ api_key: 'API_KEY' }).asset().create({ asset }) - [Content Management API Docs](https://www.contentstack.com/docs/developers/apis/content-management-api) ### The MIT License (MIT) -Copyright © 2012-2023 [Contentstack](https://www.contentstack.com/). All Rights Reserved +Copyright © 2012-2024 [Contentstack](https://www.contentstack.com/). All Rights Reserved Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/lib/stack/taxonomy/index.js b/lib/stack/taxonomy/index.js index b9d03df5..ccac2296 100644 --- a/lib/stack/taxonomy/index.js +++ b/lib/stack/taxonomy/index.js @@ -5,9 +5,14 @@ import { fetch, query, update, - deleteEntity + deleteEntity, + upload, + parseData } from '../../entity' import { Terms, TermsCollection } from './terms' +import FormData from 'form-data' +import { createReadStream } from 'fs' +import error from '../../core/contentstackError' export function Taxonomy (http, data = {}) { this.stackHeaders = data.stackHeaders @@ -69,6 +74,36 @@ export function Taxonomy (http, data = {}) { */ this.fetch = fetch(http, 'taxonomy') + /** + * @description The Export taxonomy call is used to export an existing taxonomy. + * @memberof Taxonomy + * @func export + * @returns {Promise} Promise for Taxonomy instance + * @example + * import * as contentstack from '@contentstack/management' + * const client = contentstack.client() + * + * client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').export() + * .then((taxonomy) => console.log(taxonomy)) + * + */ + this.export = async () => { + try { + const headers = { + headers: { ...cloneDeep(this.stackHeaders) } + } + const response = await http.get(`${this.urlPath}/export`, headers) + if (response.data) { + return response.data + } else { + throw error(response) + } + } catch (err) { + throw error(err) + } + } + + this.terms = (uid = '') => { const data = { stackHeaders: this.stackHeaders } data.taxonomy_uid = this.uid @@ -113,6 +148,42 @@ export function Taxonomy (http, data = {}) { * .then((taxonomies) => console.log(taxonomies) */ this.query = query({ http: http, wrapperCollection: TaxonomyCollection }) + + /** + * @description The 'Import taxonomy' import a single entry by uploading JSON or CSV files. + * @memberof Taxonomy + * @func import + * @param {String} data.taxonomy path to file + * @example + * import * as contentstack from '@contentstack/management' + * const client = contentstack.client() + * + * const data = { + * taxonomy: 'path/to/file.json', + * } + * // Import a Taxonomy + * client.stack({ api_key: 'api_key'}).taxonomy().import(data) + * .then((taxonomy) => console.log(taxonomy)) + */ + this.import = async function (data, params = {}) { + try { + const response = await upload({ + http: http, + urlPath: `${this.urlPath}/import`, + stackHeaders: this.stackHeaders, + formData: createFormData(data), + params: params + }) + if (response.data) { + return new this.constructor(http, parseData(response, this.stackHeaders)) + } else { + throw error(response) + } + } catch (err) { + throw error(err) + } + } + } } export function TaxonomyCollection (http, data) { @@ -122,3 +193,12 @@ export function TaxonomyCollection (http, data) { }) return taxonomyCollection } + +export function createFormData (data) { + return () => { + const formData = new FormData() + const uploadStream = createReadStream(data.taxonomy) + formData.append('taxonomy', uploadStream) + return formData + } +} \ No newline at end of file diff --git a/package.json b/package.json index 6eede519..aa1833f7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@contentstack/management", - "version": "1.14.1", + "version": "1.15.0", "description": "The Content Management API is used to manage the content of your Contentstack account", "main": "./dist/node/contentstack-management.js", "browser": "./dist/web/contentstack-management.js",