-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
116 lines (110 loc) · 4.43 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import cloneDeep from 'lodash/cloneDeep'
import { create, update, deleteEntity, fetch, query } from '../../entity'
/**
* A publishing environment corresponds to one or more deployment servers or a content delivery destination where the entries need to be published. Read more about <a href='https://www.contentstack.com/docs/developers/set-up-environments'>Environment</a>.
* @namespace Environment
* */
export function Environment (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/environments`
if (data.environment) {
Object.assign(this, cloneDeep(data.environment))
this.urlPath = `/environments/${this.name}`
/**
* @description The Update Environment call lets you update the name and description of an existing Environment.
* @memberof Environment
* @func update
* @returns {Promise<Environment.Environment>} Promise for Environment instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).environment('uid').fetch()
* .then((environment) => {
* environment.title = 'My New Content Type'
* environment.description = 'Content Type description'
* return environment.update()
* })
* .then((environment) => console.log(environment))
*
*/
this.update = update(http, 'environment')
/**
* @description The Delete Environment call is used to delete an existing Environment permanently from your Stack.
* @memberof Environment
* @func delete
* @returns {Object} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).environment('uid').delete()
* .then((response) => console.log(response.notice))
*/
this.delete = deleteEntity(http)
/**
* @description The fetch Environment call fetches Environment details.
* @memberof Environment
* @func fetch
* @returns {Promise<Environment.Environment>} Promise for Environment instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).environment('uid').fetch()
* .then((environment) => console.log(environment))
*
*/
this.fetch = fetch(http, 'environment')
} else {
/**
* @description The Create a Environment call creates a new environment in a particular stack of your Contentstack account.
* @memberof Environment
* @func create
* @returns {Promise<Environment.Environment>} Promise for Environment instance
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const environment = {
* name: 'development',
* servers: [
* {
* name: 'default'
* }
* ],
* urls: [
* {
* locale: 'en-us',
* url: 'http://example.com/'
* }
* ],
* deploy_content: true
* }
* client.stack({ api_key: 'api_key'}).environment().create({ environment })
* .then((environment) => console.log(environment))
*/
this.create = create({ http: http })
/**
* @description The Query on GlobalField will allow to fetch details of all or specific GlobalField
* @memberof Environment
* @func query
* @returns {Array<Environment>} Array of GlobalField.
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).environment().query({ query: { name: 'Environment Name' } }).find()
* .then((globalFields) => console.log(globalFields))
*/
this.query = query({ http: http, wrapperCollection: EnvironmentCollection })
}
}
export function EnvironmentCollection (http, data) {
const obj = cloneDeep(data.environments) || []
const environmentCollection = obj.map((userdata) => {
return new Environment(http, { environment: userdata, stackHeaders: data.stackHeaders })
})
return environmentCollection
}