Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
fef1e0c
Package dependencies updated test folder restored
uttamukkoji Jun 2, 2022
d30f68d
Type definition added
uttamukkoji Jun 3, 2022
4af8012
Create codeql-analysis.yml
contentstack-admin Jun 3, 2022
2f2bd2a
Create secrets-scan.yml
contentstack-admin Jun 3, 2022
e62f17e
Create sca-monitor.yml
contentstack-admin Jun 3, 2022
d4255c8
Create sca-scan.yml
contentstack-admin Jun 3, 2022
9244217
Create sast-scan.yml
contentstack-admin Jun 3, 2022
dcaa6b1
Package version updated
uttamukkoji Jun 7, 2022
2e9d5a6
Merge pull request #24 from contentstack/feature/typedefination
uttamukkoji Jun 13, 2022
67c6973
Update codeql-analysis.yml
contentstack-admin Jun 14, 2022
c11ef78
Workflow Stage for entry
uttamukkoji Jul 4, 2022
341e11e
Asset download functionality added
uttamukkoji Jul 12, 2022
8311a77
entry doc udpdate
uttamukkoji Jul 12, 2022
5bec03b
ignore github workflow in package publish
uttamukkoji Jul 12, 2022
1805689
Docs update
uttamukkoji Jul 12, 2022
2198718
stack branch config added
uttamukkoji Jul 12, 2022
39459e7
Stack config update for api key mandatory
uttamukkoji Jul 12, 2022
7d86c88
Create entry docs update
uttamukkoji Jul 13, 2022
b79382f
Update types
uttamukkoji Jul 18, 2022
7e6ff6e
Merge pull request #25 from contentstack/bugs/entry-workflow-stage
uttamukkoji Jul 26, 2022
baf2c32
:construction_worker: Apps API implementation
uttamukkoji Jul 26, 2022
4140b49
Merge branch 'master' into feature/marketplace-app
uttamukkoji Jul 26, 2022
8bd1095
feat: :construction: App installation Api implemented
uttamukkoji Jul 27, 2022
221618e
feat: :construction: Installation API test implemented
uttamukkoji Jul 27, 2022
a8f682c
feat: :construction: App installation TS API test added
uttamukkoji Jul 28, 2022
ebc60c3
feat: :sparkles: Marketplace app implementation done
uttamukkoji Jul 28, 2022
1b32485
Update codeql-analysis.yml
aravindbuilt Aug 1, 2022
ba36679
Delete sca-monitor.yml
aravindbuilt Aug 1, 2022
7017a20
Add files via upload
aravindbuilt Aug 1, 2022
8941cbd
refactor: :memo: License, Readme and terser
uttamukkoji Aug 4, 2022
52944a6
Merge pull request #27 from contentstack/feature/marketplace-app
uttamukkoji Aug 10, 2022
793ec57
Docs issue resolved
uttamukkoji Aug 10, 2022
ef185a3
Merge branch 'master' of https://github.com/contentstack/contentstack…
uttamukkoji Aug 10, 2022
c5416f1
sca-scan.yml
aravindbuilt Sep 21, 2022
b6e63dd
Merge branch 'master' of https://github.com/contentstack/contentstack…
uttamukkoji Oct 3, 2022
430161a
Refresh token on Unauthorized request
uttamukkoji Oct 3, 2022
efe7609
jira.yml
aravindbuilt Oct 3, 2022
4f8fcf8
jira.yml
aravindbuilt Oct 4, 2022
ea168dd
Package version Update
uttamukkoji Oct 6, 2022
ab1b3bc
Refresh token promise added
uttamukkoji Oct 17, 2022
ca1eeb6
Merge pull request #31 from contentstack/feature/refresh-token
uttamukkoji Oct 19, 2022
136d182
Stack fetch with org uid issue resolved
uttamukkoji Nov 18, 2022
bd69810
removed white space
uttamukkoji Nov 18, 2022
280c257
Comment added for synk issue
uttamukkoji Nov 18, 2022
ae95b82
Merge pull request #37 from contentstack/bugs/sso-stack-fetch
uttamukkoji Dec 9, 2022
12c9608
sca-scan.yml
aravindbuilt Jan 24, 2023
69b6018
Merge branch 'master' of https://github.com/contentstack/contentstack…
nadeem-cs Apr 10, 2023
b5a4514
feat: :sparkles: added compare and merge functionality for branches w…
nadeem-cs Apr 11, 2023
a84c8a9
test: :white_check_mark: added compare and merge api tests [CS-36688]
nadeem-cs Apr 12, 2023
8ead2bd
test: :white_check_mark: modified api tests for merge api changes [CS…
nadeem-cs Apr 14, 2023
252b14e
test: changes based on PR feedback [CS-36688]
nadeem-cs Apr 14, 2023
bd8eea4
refactor: added ts interface functions [CS-36688]
nadeem-cs Apr 14, 2023
d93625a
refactor: changed URL for compare and merge from api to v3 [CS-36688]
nadeem-cs Apr 18, 2023
3f229c9
refactor: :recycle: modified unit test cases after URL change and mod…
nadeem-cs Apr 19, 2023
1b7a2c1
test: :white_check_mark: added api test for bulk operations publish a…
nadeem-cs Apr 20, 2023
03ca336
fix: :recycle: change url path for compare and merge apis
uttamukkoji Apr 21, 2023
4a65018
Merge branch 'master' into feat/CS-36487-branches-compare-merge
uttamukkoji Apr 21, 2023
821c112
fix: :adhesive_bandage: fixed mergeQueue funciton return type
nadeem-cs Apr 21, 2023
b76a624
Merge branch 'feat/CS-36487-branches-compare-merge' of https://github…
nadeem-cs Apr 21, 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 lib/app/installation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,4 +250,4 @@ export function InstallationCollection (http, data) {
return obj.map((installationData) => {
return new Installation(http, { data: installationData })
})
}
}
22 changes: 22 additions & 0 deletions lib/entity.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,25 @@ export function parseData (response, stackHeaders, contentTypeUID) {
}
return data
}

export async function get (http, url, params, data) {
const headers = {
params: {
...cloneDeep(data.branches),
...cloneDeep(params)
},
headers: {
...cloneDeep(data.stackHeaders)
}
} || {}
try {
const response = await http.get(url, headers)
if (response.data) {
return response.data
} else {
throw error(response)
}
} catch (err) {
throw error(err)
}
}
78 changes: 78 additions & 0 deletions lib/stack/branch/compare.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { get } from '../../entity'

/**
*
* @namespace Branch
*/
export function Compare (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/stacks/branches_compare`

/**
* @description List of content types and global fields that exist in only one branch or are different between the two branches.
* @memberof Compare
* @func all
* @returns {Promise<Response>} Promise for response.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).branch('branch_uid').compare('compare_branch_uid').all({skip: 0, limit: 100})
* .then(response)
* .catch(error)
*
*/
this.all = async (params = {}) => {
return get(http, this.urlPath, params, data)
}

/**
* @description List of all or specific content types that exist in only one branch or are different between the two branches.
* @memberof Compare
* @func contentTypes
* @param {string} params.uid Optional uid for Content Type to compare.
* @returns {Promise<Response>} Promise for response.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).branch('branch_uid').compare().all({skip: 0, limit: 100})
* .then(response)
* .catch(error)
*
*/
this.contentTypes = async (params = {}) => {
let url = `${this.urlPath}/content_types`
if (params.uid) {
url = `${url}/${params.uid}`
delete params.uid
}
return get(http, url, params, data)
}

/**
* @description Compare allows you compare any or specific ContentType or GlobalFields.
* @memberof Compare
* @func globalFields
* @param {string} params.uid Optional uid for Global Field to compare.
* @returns {Promise<Response>} Promise for response.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).branch('branch_uid').compare().all({skip: 0, limit: 100})
* .then(response)
* .catch(error)
*
*/
this.globalFields = async (params = {}) => {
let url = `${this.urlPath}/global_fields`
if (params.uid) {
url = `${url}/${params.uid}`
delete params.uid
}
return get(http, url, params, data)
}

return this
}
90 changes: 89 additions & 1 deletion lib/stack/branch/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import cloneDeep from 'lodash/cloneDeep'
import { create, query, fetch, deleteEntity } from '../../entity'
import { Compare } from './compare'
import { MergeQueue } from './mergeQueue'
import error from '../../core/contentstackError'

/**
*
Expand Down Expand Up @@ -44,6 +47,29 @@ export function Branch (http, data = {}) {
*
*/
this.fetch = fetch(http, 'branch')

/**
* @description Compare allows you compare any or specific ContentType or GlobalFields.
* @memberof Branch
* @func compare
* @returns {Compare} Instance of Compare.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).branch('branch_uid').compare('compare_uid')
*
*/
this.compare = (compareBranchUid) => {
const compareData = { stackHeaders: this.stackHeaders }
if (compareBranchUid) {
compareData.branches = {
base_branch: this.uid,
compare_branch: compareBranchUid
}
}
return new Compare(http, compareData)
}
} else {
/**
* @description The Create a Branch call creates a new branch in a particular stack of your Contentstack account.
Expand All @@ -54,7 +80,7 @@ export function Branch (http, data = {}) {
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const branch = {
* const branch = {
* name: 'branch_name',
* source: 'master'
* }
Expand All @@ -77,6 +103,68 @@ export function Branch (http, data = {}) {
* .then((collection) => { console.log(collection) })
*/
this.query = query({ http, wrapperCollection: BranchCollection })

/**
* @description Merge allows user to merge branches in a Stack.
* @memberof Branch
* @func merge
* @returns {Object} Response Object
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* const params = {
* base_branch: "main",
* compare_branch: "dev",
* default_merge_strategy: "merge_prefer_base",
* merge_comment: "Merging dev into main",
* no_revert: true,
* }
* const mergeObj = {
* item_merge_strategies: [
* {
* uid: "global_field_uid",
* type: "global_field",
* merge_strategy: "merge_prefer_base"
* }
* ],
* }
*
* client.stack({ api_key: 'api_key'}).branch().merge(mergeObj, params)
*/
this.merge = async (mergeObj, params) => {
const url = '/stacks/branches_merge'
const header = {
headers: { ...cloneDeep(this.stackHeaders) },
params: params
}
try {
const response = await http.post(url, mergeObj, header)
if (response.data) return response.data
else throw error(response)
} catch (e) {
throw error(e)
}
}

/**
* @description Merge Queue provides list of all recent merge jobs in a Stack.
* @memberof Branch
* @func mergeQueue
* @returns {MergeQueue} Instance of MergeQueue
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).branch().mergeQueue()
*
*/
this.mergeQueue = (uid) => {
const mergeData = { stackHeaders: this.stackHeaders, uid }
return new MergeQueue(http, mergeData)
}
}
return this
}
Expand Down
47 changes: 47 additions & 0 deletions lib/stack/branch/mergeQueue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { get } from '../../entity'

export function MergeQueue (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/stacks/branches_queue`

if (data.uid) {
/**
* @description Fetch function gets the status of a merge job and it's configuration details.
* @memberof MergeQueue
* @func fetch
* @returns {Promise<Response>} Promise for response.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).branch().mergeQueue('UID').fetch()
* .then(response)
* .catch(error)
*
*/
this.fetch = async () => {
const url = `${this.urlPath}/${data.uid}`
return get(http, url, {}, data)
}
} else {
/**
* @description Find function lists all recent merge jobs.
* @memberof MergeQueue
* @func find
* @returns {Promise<Response>} Promise for response.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).branch().mergeQueue().find()
* .then(response)
* .catch(error)
*
*/
this.find = async (params = {}) => {
return get(http, this.urlPath, params, data)
}
}

return this
}
8 changes: 6 additions & 2 deletions lib/stack/bulkOperation/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function BulkOperation (http, data = {}) {
* .then((response) => { console.log(response.notice) })
*
*/
this.publish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false }) => {
this.publish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = '' }) => {
var httpBody = {}
if (details) {
httpBody = cloneDeep(details)
Expand All @@ -91,6 +91,9 @@ export function BulkOperation (http, data = {}) {
if (approvals) {
headers.headers.approvals = approvals
}

if (api_version) headers.headers.api_version = api_version

return publishUnpublish(http, '/bulk/publish', httpBody, headers)
}

Expand Down Expand Up @@ -153,7 +156,7 @@ export function BulkOperation (http, data = {}) {
* client.stack({ api_key: 'api_key'}).bulkOperation().unpublish({ details: publishDetails, is_nested: true })
* .then((response) => { console.log(response.notice) })
*/
this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false}) => {
this.unpublish = async ({ details, skip_workflow_stage = false, approvals = false, is_nested = false, api_version = ''}) => {
var httpBody = {}
if (details) {
httpBody = cloneDeep(details)
Expand All @@ -175,6 +178,7 @@ export function BulkOperation (http, data = {}) {
if (approvals) {
headers.headers.approvals = approvals
}
if (api_version) headers.headers.api_version = api_version
return publishUnpublish(http, '/bulk/unpublish', httpBody, headers)
}

Expand Down
Loading