Skip to content

Commit c1ecd76

Browse files
committed
docs: 📝 Update Documentation for workflow
1 parent 4406566 commit c1ecd76

File tree

3 files changed

+98
-102
lines changed

3 files changed

+98
-102
lines changed

.jsdoc.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
"lib/stack/environment/index.js",
2525
"lib/stack/deliveryToken/index.js",
2626
"lib/stack/roles/index.js",
27-
"lib/stack/webhook/index.js"
27+
"lib/stack/webhook/index.js",
28+
"lib/stack/workflow/index.js",
29+
"lib/stack/workflow/publishRules/index.js"
30+
2831
],
2932
"excludePattern": "(node_modules/|jsdocs)"
3033
},

lib/stack/workflow/index.js

Lines changed: 92 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ import {
33
create,
44
update,
55
deleteEntity,
6-
fetch,
7-
upload,
8-
parseData
6+
fetch
97
} from '../../entity'
108
import error from '../../core/contentstackError'
11-
import FormData from 'form-data'
12-
import { createReadStream } from 'fs'
139
import ContentstackCollection from '../../contentstackCollection'
1410
import { PublishRules, PublishRulesCollection } from './publishRules'
1511

@@ -60,20 +56,20 @@ export function Workflow (http, data = {}) {
6056
*
6157
*/
6258
this.disable = async function () {
63-
try {
64-
const response = await http.get(`/workflows/${this.uid}/disable`, {
65-
headers: {
66-
...cloneDeep(this.stackHeaders)
67-
},
68-
})
69-
if (response.data) {
70-
return response.data
71-
} else {
72-
throw error(response)
73-
}
74-
} catch (err) {
75-
throw error(err)
59+
try {
60+
const response = await http.get(`/workflows/${this.uid}/disable`, {
61+
headers: {
62+
...cloneDeep(this.stackHeaders)
63+
}
64+
})
65+
if (response.data) {
66+
return response.data
67+
} else {
68+
throw error(response)
7669
}
70+
} catch (err) {
71+
throw error(err)
72+
}
7773
}
7874

7975
/**
@@ -90,23 +86,22 @@ export function Workflow (http, data = {}) {
9086
*
9187
*/
9288
this.enable = async function () {
93-
try {
94-
const response = await http.get(`/workflows/${this.uid}/enable`, {
95-
headers: {
96-
...cloneDeep(this.stackHeaders)
97-
},
98-
})
99-
if (response.data) {
100-
return response.data
101-
} else {
102-
throw error(response)
103-
}
104-
} catch (err) {
105-
throw error(err)
89+
try {
90+
const response = await http.get(`/workflows/${this.uid}/enable`, {
91+
headers: {
92+
...cloneDeep(this.stackHeaders)
93+
}
94+
})
95+
if (response.data) {
96+
return response.data
97+
} else {
98+
throw error(response)
10699
}
100+
} catch (err) {
101+
throw error(err)
102+
}
107103
}
108104

109-
110105
/**
111106
* @description The Delete Workflow call is used to delete an existing Workflow permanently from your Stack.
112107
* @memberof Workflow
@@ -135,11 +130,10 @@ export function Workflow (http, data = {}) {
135130
*
136131
*/
137132
this.fetch = fetch(http, 'workflow')
138-
139133
} else {
140134
this.contentType = (contentTypeUID) => {
141-
if (contentTypeUID) {
142-
/**
135+
if (contentTypeUID) {
136+
/**
143137
* @description The Delete Workflow call is used to delete an existing Workflow permanently from your Stack.
144138
* @memberof Workflow
145139
* @func getPublishRules
@@ -155,34 +149,34 @@ export function Workflow (http, data = {}) {
155149
* client.stack({ api_key: 'api_key'}).workflow('workflow_uid').contentType('contentType_uid').getPublishRules()
156150
* .then((collection) => console.log(collection))
157151
*/
158-
async function getPublishRules(params) {
159-
const headers = {}
160-
if (this.stackHeaders) {
161-
headers.headers = this.stackHeaders
162-
}
163-
if (params) {
164-
headers.params = {
165-
...cloneDeep(params)
166-
}
167-
}
168-
try {
169-
const response = await http.get(`/workflows/content_type/${contentTypeUID}`, headers)
170-
if (response.data) {
171-
return new ContentstackCollection(response, http, this.stackHeaders, PublishRulesCollection)
172-
} else {
173-
throw error(response)
174-
}
175-
} catch (err) {
176-
throw error(err)
177-
}
152+
async function getPublishRules (params) {
153+
const headers = {}
154+
if (this.stackHeaders) {
155+
headers.headers = this.stackHeaders
156+
}
157+
if (params) {
158+
headers.params = {
159+
...cloneDeep(params)
178160
}
179-
return {
180-
getPublishRules,
181-
stackHeaders: {...this.stackHeaders}
161+
}
162+
try {
163+
const response = await http.get(`/workflows/content_type/${contentTypeUID}`, headers)
164+
if (response.data) {
165+
return new ContentstackCollection(response, http, this.stackHeaders, PublishRulesCollection)
166+
} else {
167+
throw error(response)
182168
}
169+
} catch (err) {
170+
throw error(err)
171+
}
183172
}
173+
return {
174+
getPublishRules,
175+
stackHeaders: { ...this.stackHeaders }
176+
}
177+
}
184178
}
185-
/**
179+
/**
186180
* @description The Create a Workflow request allows you to create a Workflow.
187181
* @memberof Workflow
188182
* @func create
@@ -191,7 +185,7 @@ export function Workflow (http, data = {}) {
191185
* @example
192186
* import * as contentstack from '@contentstack/management'
193187
* const client = contentstack.client()
194-
*
188+
*
195189
* const workflow = {
196190
* "workflow_stages": [
197191
* {
@@ -251,11 +245,11 @@ export function Workflow (http, data = {}) {
251245
* ]
252246
* }
253247
* client.stack().workflow().create({ workflow })
254-
* .then((workflow) => console.log(workflow))
248+
* .then((workflow) => console.log(workflow))
255249
*/
256-
this.create = create({ http: http })
250+
this.create = create({ http: http })
257251

258-
/**
252+
/**
259253
* @description The Get all Workflows request retrieves the details of all the Workflows of a stack.
260254
* @memberof Workflow
261255
* @func fetchAll
@@ -271,29 +265,29 @@ export function Workflow (http, data = {}) {
271265
* .then((collection) => console.log(collection))
272266
*
273267
*/
274-
this.fetchAll = async (params) => {
275-
const headers = {}
276-
if (this.stackHeaders) {
277-
headers.headers = this.stackHeaders
278-
}
279-
if (params) {
280-
headers.params = {
281-
...cloneDeep(params)
282-
}
283-
}
284-
try {
285-
const response = await http.get(this.urlPath, headers)
286-
if (response.data) {
287-
return new ContentstackCollection(response, http, null, WorkflowCollection)
288-
} else {
289-
throw error(response)
290-
}
291-
} catch (err) {
292-
throw error(err)
293-
}
268+
this.fetchAll = async (params) => {
269+
const headers = {}
270+
if (this.stackHeaders) {
271+
headers.headers = this.stackHeaders
272+
}
273+
if (params) {
274+
headers.params = {
275+
...cloneDeep(params)
276+
}
277+
}
278+
try {
279+
const response = await http.get(this.urlPath, headers)
280+
if (response.data) {
281+
return new ContentstackCollection(response, http, null, WorkflowCollection)
282+
} else {
283+
throw error(response)
294284
}
285+
} catch (err) {
286+
throw error(err)
287+
}
288+
}
295289

296-
/**
290+
/**
297291
* @description The Publish rule allow you to create, fetch, delete, update the publish rules.
298292
* @memberof Workflow
299293
* @func publishRule
@@ -305,25 +299,25 @@ export function Workflow (http, data = {}) {
305299
*
306300
* client.stack({ api_key: 'api_key'}).workflow().publishRule().fetchAll()
307301
* .then((collection) => console.log(collection))
308-
*
302+
*
309303
* client.stack({ api_key: 'api_key'}).workflow().publishRule('rule_uid').fetch()
310304
* .then((publishrule) => console.log(publishrule))
311305
*
312306
*/
313-
this.publishRule = (ruleUid = null) => {
314-
const publishInfo = { stackHeaders: this.stackHeaders }
315-
if (ruleUid) {
316-
publishInfo.publishing_rule = { uid: ruleUid }
317-
}
318-
return new PublishRules(http, publishInfo)
319-
}
307+
this.publishRule = (ruleUid = null) => {
308+
const publishInfo = { stackHeaders: this.stackHeaders }
309+
if (ruleUid) {
310+
publishInfo.publishing_rule = { uid: ruleUid }
311+
}
312+
return new PublishRules(http, publishInfo)
320313
}
314+
}
321315
}
322316

323317
export function WorkflowCollection (http, data) {
324-
const obj = cloneDeep(data.workflows) || []
325-
const workflowCollection = obj.map((userdata) => {
326-
return new Workflow(http, { workflow: userdata, stackHeaders: data.stackHeaders })
327-
})
328-
return workflowCollection
329-
}
318+
const obj = cloneDeep(data.workflows) || []
319+
const workflowCollection = obj.map((userdata) => {
320+
return new Workflow(http, { workflow: userdata, stackHeaders: data.stackHeaders })
321+
})
322+
return workflowCollection
323+
}

lib/stack/workflow/publishRules/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
} from '../../../entity'
88
import error from '../../../core/contentstackError'
99
import ContentstackCollection from '../../../contentstackCollection'
10-
import loader from 'string-replace-loader'
1110

1211
/**
1312
* PublishRules is a tool that allows you to streamline the process of content creation and publishing, and lets you manage the content lifecycle of your project smoothly. Read more about <a href='https://www.contentstack.com/docs/developers/set-up-publish ruless-and-publish-rules'>PublishRuless and Publish Rules</a>.
@@ -26,7 +25,7 @@ export function PublishRules (http, data = {}) {
2625
* @description The Update Publish Rules request allows you to add a publish rules stage or update the details of the existing stages of a publish rules.
2726
* @memberof Publish Rules
2827
* @func update
29-
* @returns {Promise<Publish Rules.Publish Rules>} Promise for Publish Rules instance
28+
* @returns {Promise<PublishRules.PublishRules>} Promise for Publish Rules instance
3029
* @example
3130
* import * as contentstack from '@contentstack/management'
3231
* const client = contentstack.client()
@@ -60,7 +59,7 @@ export function PublishRules (http, data = {}) {
6059
* @description The fetch publish rules retrieves the comprehensive details of a specific Publish Rules of a stack.
6160
* @memberof Publish Rules
6261
* @func fetch
63-
* @returns {Promise<Publish Rules.Publish Rules>} Promise for Publish Rules instance
62+
* @returns {Promise<PublishRules.PublishRules>} Promise for Publish Rules instance
6463
* @example
6564
* import * as contentstack from '@contentstack/management'
6665
* const client = contentstack.client()

0 commit comments

Comments
 (0)