Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8f19e16
feat: :sparkles: Taxonomy Implementation with docs, unit and api test…
harshithad0703 Sep 13, 2023
aff9588
test: :white_check_mark: changes made in taxonomy function in stack c…
harshithad0703 Sep 13, 2023
c6788f2
test: uncommented 'detele' api test case
harshithad0703 Sep 14, 2023
09e168f
Merge pull request #80 from contentstack/feat/cs-41208-taxonomy-support
harshithad0703 Sep 14, 2023
5cd1ec9
feat: :sparkles: create, fetch, find, update, delete , ancestors and …
harshithad0703 Sep 25, 2023
a0e855e
test: :white_check_mark: added api test cases for terms implementation
harshithad0703 Sep 25, 2023
5ffdd9b
feat: :sparkles: allows content-type for asset upload
nadeem-cs Sep 28, 2023
4219098
Merge pull request #82 from contentstack/fix/CS-41307-contenttype-whi…
nadeem-cs Sep 28, 2023
96ba089
test: :white_check_mark: unit test cases for terms implementation (ex…
harshithad0703 Sep 28, 2023
716afe5
changes done in passing data to create function in api test case
harshithad0703 Sep 29, 2023
56cccff
feat: :sparkles: added move and search functions for terms implementa…
harshithad0703 Sep 29, 2023
3e1a329
test: :white_check_mark: updated and added search and move unit test …
harshithad0703 Sep 29, 2023
8a1d475
test: :white_check_mark: updated and added search and move api test c…
harshithad0703 Sep 29, 2023
6986875
docs: :memo: updated api reference docs for search, ancestors, descen…
harshithad0703 Sep 29, 2023
d643001
Merge pull request #84 from contentstack/feat/cs-41208-taxonomy-support
harshithad0703 Sep 29, 2023
7730b50
Merge pull request #81 from contentstack/feat/cs-41463-terms-support
harshithad0703 Sep 29, 2023
ca51c74
build: :package: updated axios module and version number
nadeem-cs Sep 29, 2023
1843502
Merge branch 'master' into next
nadeem-cs Sep 29, 2023
c6daba3
chore: :loud_sound: update changelog file
nadeem-cs Oct 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .talismanrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
threshold: medium
fileignoreconfig:
- filename: package-lock.json
checksum: 71a070335979f3eed857a887e4bd36d9a1e14b08370c55117c55b45b77889b68
checksum: ef5d374553f431b5a952069f46184ec7e49efd7d72143e1a1642994758db4359
version: ""
23 changes: 21 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
# Changelog

## [v1.10.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.8.0) (2023-07-21)
## [v1.11.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.11.0) (2023-09-03)
- Fixes and Enhancements
- Allows contenttype in asset upload
- Taxonomy feature addition
- Terms feature addition
## [v1.10.2](https://github.com/contentstack/contentstack-management-javascript/tree/v1.10.2) (2023-08-23)
- Fixes and Enhancements
- RefreshToken error handling
- Handling workflow response of object format
- Support for overwrite flag in Contenttype and Global fields import functionality
## [v1.10.1](https://github.com/contentstack/contentstack-management-javascript/tree/v1.10.1) (2023-08-01)
- Fixes:
- Token leak
- Users type
- ContentstackCollection type
- Environment param type
- Enhancements
- Adds Auditlogs functions
- Contenttype references function
## [v1.10.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.10.0) (2023-07-21)
- Fixes
- Fixes Breaking Changes
## [v1.9.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.8.0) (2023-07-19)
## [v1.9.0](https://github.com/contentstack/contentstack-management-javascript/tree/v1.9.0) (2023-07-19)
- Features:
- NRP support added
- Audit logs APIs support
Expand Down
43 changes: 39 additions & 4 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export const create = ({ http, params }) => {
try {
const response = await http.post(this.urlPath, data, headers)
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid))
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
} else {
throw error(response)
}
Expand Down Expand Up @@ -144,7 +144,7 @@ export const update = (http, type, params = {}) => {
}
})
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid))
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
} else {
throw error(response)
}
Expand Down Expand Up @@ -204,7 +204,7 @@ export const fetch = (http, type, params = {}) => {
response.data[type]['content_type'] = response.data['content_type']
response.data[type]['schema'] = response.data['schema']
}
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid))
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
} else {
throw error(response)
}
Expand Down Expand Up @@ -235,14 +235,17 @@ export const fetchAll = (http, wrapperCollection, params = {}) => {
}
}

export function parseData (response, stackHeaders, contentTypeUID) {
export function parseData (response, stackHeaders, contentTypeUID, taxonomy_uid) {
const data = response.data || {}
if (stackHeaders) {
data.stackHeaders = stackHeaders
}
if (contentTypeUID) {
data.content_type_uid = contentTypeUID
}
if (taxonomy_uid) {
data.taxonomy_uid = taxonomy_uid
}
return data
}

Expand All @@ -266,4 +269,36 @@ export async function get (http, url, params, data) {
} catch (err) {
throw error(err)
}
}

export const move = (http, type, force = false, params = {}) => {
return async function (param = {}) {
try {
let updateData = {}
const json = cloneDeep(this)
delete json.parent_uid
if (type) {
updateData[type] = json
} else {
updateData = json
}
const headers = {
headers: { ...cloneDeep(this.stackHeaders), ...cloneDeep(params) },
params: {
...cloneDeep(param)
}
} || {}
if (force === true) {
headers.params.force = true
}
const response = await http.put(`${this.urlPath}/move`, updateData, headers)
if (response.data) {
return new this.constructor(http, parseData(response, this.stackHeaders, this.content_type_uid, this.taxonomy_uid))
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
}
6 changes: 5 additions & 1 deletion lib/stack/asset/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,11 @@ export function createFormData (data) {
formData.append('asset[title]', data.title)
}
const uploadStream = createReadStream(data.upload)
formData.append('asset[upload]', uploadStream)
if (typeof data.content_type === 'string') {
formData.append('asset[upload]', uploadStream, { contentType: data.content_type })
} else {
formData.append('asset[upload]', uploadStream)
}
return formData
}
}
25 changes: 24 additions & 1 deletion lib/stack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import { Label } from './label'
import { Branch } from './branch'
import { BranchAlias } from './branchAlias'
import { AuditLog } from './auditlog'
// import { format } from 'util'
import { Taxonomy } from './taxonomy'

/**
* A stack is a space that stores the content of a project (a web or mobile property). Within a stack, you can create content structures, content entries, users, etc. related to the project. Read more about <a href='https://www.contentstack.com/docs/guide/stack'>Stacks</a>.
* @namespace Stack
Expand Down Expand Up @@ -684,6 +685,28 @@ export function Stack (http, data) {
}
return new Role(http, data)
}

/**
* @description Taxonomies allow you to group a collection of content within a stack. Using taxonomies you can group content types that need to work together
* @param {String} uid The UID of the Taxonomy you want to get details.
* @returns {Taxonomy} Instance of Taxonomy.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).taxonomy().create()
* .then((taxonomy) => console.log(taxonomy))
*
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomy_uid').fetch()
* .then((taxonomy) => console.log(taxonomy))
*/
this.taxonomy = (taxonomyUid = '') => {
const data = { stackHeaders: this.stackHeaders }
if (taxonomyUid) {
data.taxonomy = { uid: taxonomyUid }
}
return new Taxonomy(http, data)
}
} else {
/**
* @description The Create stack call creates a new stack in your Contentstack account.
Expand Down
124 changes: 124 additions & 0 deletions lib/stack/taxonomy/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/* eslint-disable camelcase */
import cloneDeep from 'lodash/cloneDeep'
import {
create,
fetch,
query,
update,
deleteEntity
} from '../../entity'
import { Terms, TermsCollection } from './terms'

export function Taxonomy (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/taxonomies`

if (data.taxonomy) {
Object.assign(this, cloneDeep(data.taxonomy))
if (data.taxonomy.terms) {
this.terms = new TermsCollection(http, { terms: data.taxonomy.terms, stackHeaders: data.stackHeaders }, this.uid)
}
this.urlPath = `/taxonomies/${this.uid}`

/**
* @description The Update taxonomy call is used to update an existing taxonomy.
* @memberof Taxonomy
* @func update
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').fetch()
* .then((taxonomy) => {
* taxonomy.name = 'taxonomy name'
* return taxonomy.update()
* })
* .then((taxonomy) => console.log(taxonomy))
*
*/
this.update = update(http, 'taxonomy')

/**
* @description The Delete taxonomy call is used to delete an existing taxonomy.
* @memberof Taxonomy
* @func delete
* @returns {Promise<Taxonomy.Taxonomy>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').delete()
* .then((response) => console.log(response.notice))
*
*/
this.delete = deleteEntity(http)

/**
* @description The Fetch taxonomy call is used to fetch an existing taxonomy.
* @memberof Taxonomy
* @func fetch
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).taxonomy('taxonomyUid').fetch()
* .then((taxonomy) => console.log(taxonomy))
*
*/
this.fetch = fetch(http, 'taxonomy')

this.terms = (uid = '') => {
const data = { stackHeaders: this.stackHeaders }
data.taxonomy_uid = this.uid
if (uid) {
data.term = { uid: uid }
}
return new Terms(http, data)
}
} else {
/**
* @description The Create taxonomy call is used to create a taxonomy.
* @memberof Taxonomy
* @func create
* @returns {Promise<Taxonomy.Taxonomy>} Promise for Taxonomy instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const taxonomy = {
* uid: 'taxonomy_testing1',
* name: 'taxonomy testing',
* description: 'Description for Taxonomy testing'
* }
* client.stack({ api_key: 'api_key'}).taxonomy().create({taxonomy})
* .then(taxonomy) => console.log(taxonomy)
*
*/
this.create = create({ http })

/**
* @description The Query on Taxonomy will allow to fetch details of all Taxonomies.
* @memberof Taxonomy
* @param {Object} params - URI parameters
* @prop {Object} params.query - Queries that you can use to fetch filtered results.
* @func query
* @returns {Array<Taxonomy>} Array of Taxonomy.
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack().taxonomy().query().find()
* .then((taxonomies) => console.log(taxonomies)
*/
this.query = query({ http: http, wrapperCollection: TaxonomyCollection })
}
}
export function TaxonomyCollection (http, data) {
const obj = cloneDeep(data.taxonomy) || []
const taxonomyCollection = obj.map((userdata) => {
return new Taxonomy(http, { taxonomy: userdata, stackHeaders: data.stackHeaders })
})
return taxonomyCollection
}
Loading