-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (48 loc) · 2.05 KB
/
index.js
File metadata and controls
52 lines (48 loc) · 2.05 KB
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
import cloneDeep from 'lodash/cloneDeep'
import { create, deleteEntity } from '../../../entity'
import { bindModuleHeaders } from '../../../core/moduleHeaderSupport.js'
/**
* Preview tokens provide read-only access to the associated environments. Read more about <a href='https://www.contentstack.com/docs/developers/create-tokens/about-preview-tokens'>PreviewToken</a>.
* @namespace PreviewToken
*/
export function PreviewToken (http, data = {}) {
this.stackHeaders = data.stackHeaders
if (data.token) {
Object.assign(this, cloneDeep(data.token))
this.urlPath = `/stacks/delivery_tokens/${this.uid}/preview_token`
/**
* @description The Delete PreviewToken call is used to delete an existing PreviewToken permanently from your Stack.
* @memberof PreviewToken
* @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').previewToken().delete()
* .then((response) => console.log(response.notice))
*/
this.delete = deleteEntity(http)
/**
* @description The Create a PreviewToken call creates a new previewToken in a particular stack of your Contentstack account.
* @memberof PreviewToken
* @func create
* @returns {Promise<PreviewToken.PreviewToken>} Promise for PreviewToken instance
*
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.stack().deliveryToken('delivery_token_uid').previewToken().create()
* .then((previewToken) => console.log(previewToken))
*/
this.create = create({ http: http })
}
bindModuleHeaders(this)
}
export function PreviewTokenCollection (http, data) {
const obj = cloneDeep(data.tokens) || []
const previewTokenCollection = obj.map((userdata) => {
return new PreviewToken(http, { token: userdata, stackHeaders: data.stackHeaders })
})
return previewTokenCollection
}