1- import cloneDeep from " lodash/cloneDeep" ;
2- import { create , query , fetch , deleteEntity } from " ../../entity" ;
3- import { Compare } from " ./compare" ;
4- import { MergeQueue } from " ./mergeQueue" ;
5- import error from " ../../core/contentstackError" ;
1+ import cloneDeep from ' lodash/cloneDeep'
2+ import { create , query , fetch , deleteEntity } from ' ../../entity'
3+ import { Compare } from ' ./compare'
4+ import { MergeQueue } from ' ./mergeQueue'
5+ import error from ' ../../core/contentstackError'
66
77/**
88 *
99 * @namespace Branch
1010 */
11- export function Branch ( http , data = { } ) {
12- this . stackHeaders = data . stackHeaders ;
13- this . urlPath = `/stacks/branches` ;
11+ export function Branch ( http , data = { } ) {
12+ this . stackHeaders = data . stackHeaders
13+ this . urlPath = `/stacks/branches`
1414
15- data . branch = data . branch || data . branch_alias ;
16- delete data . branch_alias ;
15+ data . branch = data . branch || data . branch_alias
16+ delete data . branch_alias
1717
1818 if ( data . branch ) {
19- Object . assign ( this , cloneDeep ( data . branch ) ) ;
20- this . urlPath = `/stacks/branches/${ this . uid } ` ;
19+ Object . assign ( this , cloneDeep ( data . branch ) )
20+ this . urlPath = `/stacks/branches/${ this . uid } `
2121
2222 /**
2323 * @description The Delete Branch call is used to delete an existing Branch permanently from your Stack.
@@ -31,7 +31,7 @@ export function Branch(http, data = {}) {
3131 * client.stack({ api_key: 'api_key'}).branch('branch_uid').delete()
3232 * .then((response) => console.log(response.notice))
3333 */
34- this . delete = deleteEntity ( http , true ) ;
34+ this . delete = deleteEntity ( http , true )
3535
3636 /**
3737 * @description The fetch Branch call fetches Branch details.
@@ -46,7 +46,7 @@ export function Branch(http, data = {}) {
4646 * .then((branch) => console.log(branch))
4747 *
4848 */
49- this . fetch = fetch ( http , " branch" ) ;
49+ this . fetch = fetch ( http , ' branch' )
5050
5151 /**
5252 * @description Compare allows you to compare any or specific ContentType or GlobalFields.
@@ -61,15 +61,15 @@ export function Branch(http, data = {}) {
6161 *
6262 */
6363 this . compare = ( compareBranchUid ) => {
64- const compareData = { stackHeaders : this . stackHeaders } ;
64+ const compareData = { stackHeaders : this . stackHeaders }
6565 if ( compareBranchUid ) {
6666 compareData . branches = {
6767 base_branch : this . uid ,
68- compare_branch : compareBranchUid ,
69- } ;
68+ compare_branch : compareBranchUid
69+ }
7070 }
71- return new Compare ( http , compareData ) ;
72- } ;
71+ return new Compare ( http , compareData )
72+ }
7373
7474 /**
7575 * @description The Update Branch Settings call updates the settings of an existing Branch.
@@ -80,20 +80,34 @@ export function Branch(http, data = {}) {
8080 * @example
8181 * import * as contentstack from '@contentstack/management'
8282 * const client = contentstack.client()
83+ *
84+ * const payload = {
85+ * branch: {
86+ * settings: {
87+ * am_v2: {
88+ * linked_workspaces: [
89+ * { uid: 'main', space_uid: 'space_uid', is_default: true }
90+ * ]
91+ * }
92+ * }
93+ * }
94+ * }
8395 * client.stack({ api_key: 'api_key' }).branch('branch_uid').updateSettings(payload)
8496 * .then((response) => console.log(response.notice))
8597 */
8698 this . updateSettings = async ( payload ) => {
8799 try {
88- const response = await http . post ( `${ this . urlPath } /settings` , payload , {
89- headers : { ...cloneDeep ( this . stackHeaders ) } ,
90- } ) ;
91- if ( response . data ) return response . data ;
92- else throw error ( response ) ;
100+ const response = await http . post (
101+ `${ this . urlPath } /settings` ,
102+ payload ,
103+ { headers : { ...cloneDeep ( this . stackHeaders ) } }
104+ )
105+ if ( response . data ) return response . data
106+ else throw error ( response )
93107 } catch ( e ) {
94- throw error ( e ) ;
108+ throw error ( e )
95109 }
96- } ;
110+ }
97111 } else {
98112 /**
99113 * @description The Create a Branch call creates a new branch in a particular stack of your Contentstack account.
@@ -111,7 +125,7 @@ export function Branch(http, data = {}) {
111125 * client.stack({ api_key: 'api_key'}).branch().create({ branch })
112126 * .then((branch) => { console.log(branch) })
113127 */
114- this . create = create ( { http : http } ) ;
128+ this . create = create ( { http : http } )
115129
116130 /**
117131 * @description The 'Get all Branch' request returns comprehensive information about branches created in a Stack.
@@ -126,7 +140,7 @@ export function Branch(http, data = {}) {
126140 * client.stack({ api_key: 'api_key'}).branch().query().find()
127141 * .then((collection) => { console.log(collection) })
128142 */
129- this . query = query ( { http, wrapperCollection : BranchCollection } ) ;
143+ this . query = query ( { http, wrapperCollection : BranchCollection } )
130144
131145 /**
132146 * @description Merge allows user to merge branches in a Stack.
@@ -159,19 +173,19 @@ export function Branch(http, data = {}) {
159173 * client.stack({ api_key: 'api_key'}).branch().merge(mergeObj, params)
160174 */
161175 this . merge = async ( mergeObj , params ) => {
162- const url = " /stacks/branches_merge" ;
176+ const url = ' /stacks/branches_merge'
163177 const header = {
164178 headers : { ...cloneDeep ( this . stackHeaders ) } ,
165- params : params ,
166- } ;
179+ params : params
180+ }
167181 try {
168- const response = await http . post ( url , mergeObj , header ) ;
169- if ( response . data ) return response . data ;
170- else throw error ( response ) ;
182+ const response = await http . post ( url , mergeObj , header )
183+ if ( response . data ) return response . data
184+ else throw error ( response )
171185 } catch ( e ) {
172- throw error ( e ) ;
186+ throw error ( e )
173187 }
174- } ;
188+ }
175189
176190 /**
177191 * @description Merge Queue provides list of all recent merge jobs in a Stack.
@@ -187,19 +201,16 @@ export function Branch(http, data = {}) {
187201 *
188202 */
189203 this . mergeQueue = ( uid ) => {
190- const mergeData = { stackHeaders : this . stackHeaders , uid } ;
191- return new MergeQueue ( http , mergeData ) ;
192- } ;
204+ const mergeData = { stackHeaders : this . stackHeaders , uid }
205+ return new MergeQueue ( http , mergeData )
206+ }
193207 }
194- return this ;
208+ return this
195209}
196210
197- export function BranchCollection ( http , data ) {
198- const obj = cloneDeep ( data . branches ) || data . branch_aliases || [ ] ;
211+ export function BranchCollection ( http , data ) {
212+ const obj = cloneDeep ( data . branches ) || data . branch_aliases || [ ]
199213 return obj . map ( ( branchData ) => {
200- return new Branch ( http , {
201- branch : branchData ,
202- stackHeaders : data . stackHeaders ,
203- } ) ;
204- } ) ;
214+ return new Branch ( http , { branch : branchData , stackHeaders : data . stackHeaders } )
215+ } )
205216}
0 commit comments