-
Notifications
You must be signed in to change notification settings - Fork 7
/
index.js
111 lines (106 loc) · 4.29 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
import cloneDeep from 'lodash/cloneDeep'
import { create, update, deleteEntity, fetch, query } from '../../entity'
/**
* Delivery tokens provide read-only access to the associated environments. Read more about <a href='https://www.contentstack.com/docs/developers/create-tokens/about-delivery-tokens'>DeliveryToken</a>.
* @namespace DeliveryToken
*/
export function DeliveryToken (http, data = {}) {
this.stackHeaders = data.stackHeaders
this.urlPath = `/stacks/delivery_tokens`
if (data.token) {
Object.assign(this, cloneDeep(data.token))
this.urlPath = `/stacks/delivery_tokens/${this.uid}`
/**
* @description The Update DeliveryToken call lets you update the name and description of an existing DeliveryToken.
* @memberof DeliveryToken
* @func update
* @returns {Promise<DeliveryToken.DeliveryToken>} Promise for DeliveryToken instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).deliveryToken('delivery_token_uid').fetch()
* .then((deliveryToken) => {
* deliveryToken.title = 'My New Content Type'
* deliveryToken.description = 'Content Type description'
* return deliveryToken.update()
* })
* .then((deliveryToken) => console.log(deliveryToken))
*
*/
this.update = update(http, 'token')
/**
* @description The Delete DeliveryToken call is used to delete an existing DeliveryToken permanently from your Stack.
* @memberof DeliveryToken
* @func delete
* @returns {Object} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).deliveryToken('delivery_token_uid').delete()
* .then((response) => console.log(response.notice))
*/
this.delete = deleteEntity(http)
/**
* @description The fetch DeliveryToken call fetches DeliveryToken details.
* @memberof DeliveryToken
* @func fetch
* @returns {Promise<DeliveryToken.DeliveryToken>} Promise for DeliveryToken instance
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack({ api_key: 'api_key'}).deliveryToken('delivery_token_uid').fetch()
* .then((deliveryToken) => console.log(deliveryToken))
*
*/
this.fetch = fetch(http, 'token')
} else {
/**
* @description The Create a DeliveryToken call creates a new deliveryToken in a particular stack of your Contentstack account.
* @memberof DeliveryToken
* @func create
* @returns {Promise<DeliveryToken.DeliveryToken>} Promise for DeliveryToken instance
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const token = {
* name: 'Test',
* description: 'This is a demo token.',
* scope: [{
* module: 'environment',
* environments: ['development'],
* acl: {
* read: true
* }
* }]
* }
*
* client.stack().deliveryToken().create({ token })
* .then((deliveryToken) => console.log(deliveryToken))
*/
this.create = create({ http: http })
/**
* @description The ‘Get all deliveryToken’ request returns comprehensive information about all deliveryToken created in a stack.
* @memberof DeliveryToken
* @func query
* @returns {ContentstackCollection} Instance of ContentstackCollection.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.stack().deliveryToken().query({ query: { name: 'token_name' } })).find()
* .then((contentstackCollection) => console.log(contentstackCollection))
*/
this.query = query({ http: http, wrapperCollection: DeliveryTokenCollection })
}
}
export function DeliveryTokenCollection (http, data) {
const obj = cloneDeep(data.tokens) || []
const deliveryTokenCollection = obj.map((userdata) => {
return new DeliveryToken(http, { token: userdata, stackHeaders: data.stackHeaders })
})
return deliveryTokenCollection
}