UNPKG

1.51 kBJavaScriptView Raw
1import entities from './entities';
2
3/**
4 * @private
5 */
6
7/**
8 * @private
9 */
10export default function createUIConfigApi(makeRequest) {
11 const {
12 wrapUIConfig
13 } = entities.uiConfig;
14 const getParams = self => {
15 const uiConfig = self.toPlainObject();
16 return {
17 params: {
18 spaceId: uiConfig.sys.space.sys.id,
19 environmentId: uiConfig.sys.environment.sys.id
20 },
21 raw: uiConfig
22 };
23 };
24 return {
25 /**
26 * Sends an update to the server with any changes made to the object's properties
27 * @return Object returned from the server with updated changes.
28 * @example ```javascript
29 * const contentful = require('contentful-management')
30 *
31 * const client = contentful.createClient({
32 * accessToken: '<content_management_api_key>'
33 * })
34 *
35 * client.getSpace('<space_id>')
36 * .then((space) => space.getEnvironment('<environment_id>'))
37 * .then((environment) => environment.getUIConfig())
38 * .then((uiConfig) => {
39 * uiConfig.entryListViews = [...]
40 * return uiConfig.update()
41 * })
42 * .then((uiConfig) => console.log(`UIConfig updated.`))
43 * .catch(console.error)
44 * ```
45 */
46 update: async function update() {
47 const {
48 raw,
49 params
50 } = getParams(this);
51 const data = await makeRequest({
52 entityType: 'UIConfig',
53 action: 'update',
54 params,
55 payload: raw
56 });
57 return wrapUIConfig(makeRequest, data);
58 }
59 };
60}
\No newline at end of file