Skip to content

Commit f44c5d8

Browse files
authored
Merge pull request #20 from contentstack/feature/nested-publish
Feature/nested publish
2 parents c9e7087 + 527cbff commit f44c5d8

36 files changed

+3795
-3903
lines changed

.jsdoc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,12 @@
1616
"lib/stack/contentType/entry/index.js",
1717
"lib/stack/asset/index.js",
1818
"lib/stack/asset/folders/index.js",
19+
"lib/stack/branch/index.js",
20+
"lib/stack/branchAlias/index.js",
1921
"lib/stack/bulkOperation/index.js",
2022
"lib/stack/extension/index.js",
2123
"lib/stack/release/index.js",
24+
"lib/stack/release/items/index.js",
2225
"lib/stack/label/index.js",
2326
"lib/stack/locale/index.js",
2427
"lib/stack/environment/index.js",

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ docdash-template/
2121
.babelrc
2222
.babel-preset.js
2323
.eslintrc.js
24-
.talismanrc
24+
.talismanrc
25+
lib/

.talismanrc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
fileignoreconfig:
22
- filename: jsdocs/stack_environment_index.js.html
3-
checksum: 1eac06c1c56f00422a548245f1c92fe505174fb349d85584d81508028117f53c
4-
- filename: dist/node/contentstack-management.js
5-
checksum: 0cc6ad62a7f0cef0882d7416e9ec966b34e56ef906592e11aa9a5dc4a6e443b9
6-
- filename: package-lock.json
7-
checksum: 99fcfcea623a71f7b8b8537e19ff32f2e20bc17a21dfe861ce5697c5e928bae7
8-
- filename: dist/nativescript/contentstack-management.js
9-
checksum: fbf96bf31cc89c74e3e239b8c330dd9be336af20973a0ec56dd11c463447ddf1
3+
checksum: 506ccc2492c3ce3218582ba049ee4713b33eb20764227a91f16a10f76ff0a8e7
104
- filename: dist/react-native/contentstack-management.js
11-
checksum: 4eeba7bb1f57f6031334d4394ce2a40890fdc8e96101f8c01441fca2e2708baa
5+
checksum: 279b809bc382f5bc1898525d49d8e49ee3ed82ce8e4728416fef22a8fa0fab81
126
- filename: dist/web/contentstack-management.js
13-
checksum: 394411bc4d75c6ec6fc001cd2aea9747b91a065daa5b770dff0c1e58ef095465
7+
checksum: 62b3396f8d0e8981f299815d3cef4f77f389097e2600e6cf04b6dbc24d4822c7
8+
- filename: dist/nativescript/contentstack-management.js
9+
checksum: 52e66c545bb73f49d75863242e128dc08e3672a5d0291d5e14a360581ad2e71c
10+
- filename: dist/node/contentstack-management.js
11+
checksum: 62d9cc89bdf76f1ef8ccb676e896247bdf689f58716bbceadc174d8ef6fce621
12+
- filename: package-lock.json
13+
checksum: 05fa93e24eaaa69794388ce1d818e3518373919d0d8243f9f921d10086dafbb1

docdash-template/tmpl/layout.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
</head>
3939
<body>
4040
<!-- Google Tag Manager (noscript) -->
41-
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-WGP99J7" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
41+
<noscript><iframe title="Google Tag Manager" src="https://www.googletagmanager.com/ns.html?id=GTM-WGP99J7" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
4242
<!-- End Google Tag Manager (noscript) -->
4343

4444
<input type="checkbox" id="nav-trigger" class="nav-trigger" />

docdash-template/tmpl/params.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,21 @@
5858
});
5959
?>
6060

61-
<table class="params">
61+
<table class="params" aria-describedby="params">
6262
<thead>
6363
<tr>
6464
<?js if (params.hasName) {?>
65-
<th>Name</th>
65+
<th id="name">Name</th>
6666
<?js } ?>
6767

68-
<th>Type</th>
68+
<th id="type">Type</th>
6969

7070
<?js if (params.hasAttributes) {?>
71-
<th>Attributes</th>
71+
<th id="attributes">Attributes</th>
7272
<?js } ?>
7373

7474
<?js if (params.hasDefault) {?>
75-
<th>Default</th>
75+
<th id="default">Default</th>
7676
<?js } ?>
7777

7878
<th class="last">Description</th>

docdash-template/tmpl/properties.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@
3838
});
3939
?>
4040

41-
<table class="props">
41+
<table class="props" aria-describedby="props">
4242
<thead>
4343
<tr>
4444
<?js if (props.hasName) {?>
45-
<th>Name</th>
45+
<th id="name">Name</th>
4646
<?js } ?>
4747

48-
<th>Type</th>
48+
<th id="type">Type</th>
4949

5050
<?js if (props.hasAttributes) {?>
51-
<th>Attributes</th>
51+
<th id="attributes">Attributes</th>
5252
<?js } ?>
5353

5454
<?js if (props.hasDefault) {?>
55-
<th>Default</th>
55+
<th id="default">Default</th>
5656
<?js } ?>
5757

5858
<th class="last">Description</th>

lib/contentstack.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ export function client (params = {}) {
142142
...requiredHeaders
143143
}
144144
const http = httpClient(params)
145-
const api = contentstackClient({
145+
return contentstackClient({
146146
http: http
147147
})
148-
return api
149148
}

lib/contentstackClient.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ export default function contentstackClient ({ http }) {
6161
* @memberof ContentstackClient
6262
* @func stack
6363
* @param {String} api_key - Stack API Key
64-
* @param {String} management_token - Stack API Key
64+
* @param {String} management_token - Management token for Stack.
65+
* @param {String} branch_name - Branch name or alias to access specific branch. Default is master.
6566
* @returns {Stack} Instance of Stack
6667
*
6768
* @example
@@ -85,6 +86,12 @@ export default function contentstackClient ({ http }) {
8586
* client.stack({ api_key: 'api_key', management_token: 'management_token' }).contentType('content_type_uid').fetch()
8687
* .then((stack) => console.log(stack))
8788
*
89+
* @example
90+
* import * as contentstack from '@contentstack/management'
91+
* const client = contentstack.client()
92+
*
93+
* client.stack({ api_key: 'api_key', management_token: 'management_token', branch_uid: 'branch_uid' }).contentType('content_type_uid').fetch()
94+
* .then((stack) => console.log(stack))
8895
*/
8996
function stack (params = {}) {
9097
const stack = { ...cloneDeep(params) }

lib/entity.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ export const update = (http, type) => {
168168
}
169169
}
170170

171-
export const deleteEntity = (http) => {
171+
export const deleteEntity = (http, force = false) => {
172172
return async function (param = {}) {
173173
try {
174174
const headers = {
@@ -177,12 +177,21 @@ export const deleteEntity = (http) => {
177177
...cloneDeep(param)
178178
}
179179
} || {}
180-
180+
if (force === true) {
181+
headers.params.force = true
182+
}
181183
const response = await http.delete(this.urlPath, headers)
182184
if (response.data) {
183185
return response.data
184186
} else {
185-
throw error(response)
187+
if (response.status >= 200 && response.status < 300) {
188+
return {
189+
status: response.status,
190+
statusText: response.statusText
191+
}
192+
} else {
193+
throw error(response)
194+
}
186195
}
187196
} catch (err) {
188197
throw error(err)

lib/stack/branch/index.js

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import cloneDeep from 'lodash/cloneDeep'
2+
import { create, query, fetch, deleteEntity } from '../../entity'
3+
4+
/**
5+
*
6+
* @namespace Branch
7+
*/
8+
export function Branch (http, data = {}) {
9+
this.stackHeaders = data.stackHeaders
10+
this.urlPath = `/stacks/branches`
11+
12+
data.branch = data.branch || data.branch_alias
13+
delete data.branch_alias
14+
15+
if (data.branch) {
16+
Object.assign(this, cloneDeep(data.branch))
17+
this.urlPath = `/stacks/branches/${this.uid}`
18+
19+
/**
20+
* @description The Delete Branch call is used to delete an existing Branch permanently from your Stack.
21+
* @memberof Branch
22+
* @func delete
23+
* @returns {Object} Response Object.
24+
* @example
25+
* import * as contentstack from '@contentstack/management'
26+
* const client = contentstack.client()
27+
*
28+
* client.stack({ api_key: 'api_key'}).branch('branch_uid').delete()
29+
* .then((response) => console.log(response.notice))
30+
*/
31+
this.delete = deleteEntity(http, true)
32+
33+
/**
34+
* @description The fetch Branch call fetches Branch details.
35+
* @memberof Branch
36+
* @func fetch
37+
* @returns {Promise<Branch.Branch>} Promise for Branch instance
38+
* @example
39+
* import * as contentstack from '@contentstack/management'
40+
* const client = contentstack.client()
41+
*
42+
* client.stack({ api_key: 'api_key'}).branch('branch_uid').fetch()
43+
* .then((branch) => console.log(branch))
44+
*
45+
*/
46+
this.fetch = fetch(http, 'branch')
47+
48+
} else {
49+
/**
50+
* @description The Create a Branch call creates a new branch in a particular stack of your Contentstack account.
51+
* @memberof Branch
52+
* @func create
53+
* @returns {Promise<Branch.Branch>} Promise for Branch instance
54+
*
55+
* @example
56+
* import * as contentstack from '@contentstack/management'
57+
* const client = contentstack.client()
58+
* const branch = {
59+
* name: 'branch_name',
60+
* source: 'master'
61+
* }
62+
* client.stack({ api_key: 'api_key'}).branch().create({ branch })
63+
* .then((branch) => { console.log(branch) })
64+
*/
65+
this.create = create({ http: http })
66+
67+
/**
68+
* @description The 'Get all Branch' request returns comprehensive information about branch created in a Stack.
69+
* @memberof Branch
70+
* @func query
71+
* @returns {Promise<ContentstackCollection.ContentstackCollection>} Promise for ContentstackCollection instance
72+
*
73+
* @example
74+
* import * as contentstack from '@contentstack/management'
75+
* const client = contentstack.client()
76+
*
77+
* client.stack({ api_key: 'api_key'}).branch().query().find()
78+
* .then((collection) => { console.log(collection) })
79+
*/
80+
this.query = query({ http, wrapperCollection: BranchCollection })
81+
}
82+
return this
83+
}
84+
85+
export function BranchCollection (http, data) {
86+
const obj = cloneDeep(data.branches) || data.branch_aliases || []
87+
return obj.map((branchData) => {
88+
return new Branch(http, { branch: branchData, stackHeaders: data.stackHeaders })
89+
})
90+
}

0 commit comments

Comments
 (0)