contentful-management 12.0.0-beta.1 → 12.0.0-beta.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/cjs/adapters/REST/endpoints/access-token.cjs +136 -0
- package/dist/cjs/adapters/REST/endpoints/ai-action-invocation.cjs +9 -0
- package/dist/cjs/adapters/REST/endpoints/ai-action.cjs +53 -0
- package/dist/cjs/adapters/REST/endpoints/api-key.cjs +48 -0
- package/dist/cjs/adapters/REST/endpoints/app-access-token.cjs +9 -0
- package/dist/cjs/adapters/REST/endpoints/app-action-call.cjs +65 -0
- package/dist/cjs/adapters/REST/endpoints/app-action.cjs +42 -0
- package/dist/cjs/adapters/REST/endpoints/app-bundle.cjs +39 -0
- package/dist/cjs/adapters/REST/endpoints/app-definition.cjs +47 -0
- package/dist/cjs/adapters/REST/endpoints/app-details.cjs +17 -0
- package/dist/cjs/adapters/REST/endpoints/app-event-subscription.cjs +17 -0
- package/dist/cjs/adapters/REST/endpoints/app-installation.cjs +42 -0
- package/dist/cjs/adapters/REST/endpoints/app-key.cjs +21 -0
- package/dist/cjs/adapters/REST/endpoints/app-signed-request.cjs +9 -0
- package/dist/cjs/adapters/REST/endpoints/app-signing-secret.cjs +17 -0
- package/dist/cjs/adapters/REST/endpoints/app-upload.cjs +28 -0
- package/dist/cjs/adapters/REST/endpoints/asset-key.cjs +34 -0
- package/dist/cjs/adapters/REST/endpoints/asset.cjs +185 -0
- package/dist/cjs/adapters/REST/endpoints/bulk-action.cjs +21 -0
- package/dist/cjs/adapters/REST/endpoints/comment.cjs +92 -0
- package/dist/cjs/adapters/REST/endpoints/concept-scheme.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/concept.cjs +65 -0
- package/dist/cjs/adapters/REST/endpoints/content-type.cjs +56 -0
- package/dist/cjs/adapters/REST/endpoints/editor-interface.cjs +24 -0
- package/dist/cjs/adapters/REST/endpoints/entry.cjs +104 -0
- package/dist/cjs/adapters/REST/endpoints/environment-alias.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/environment-template-installation.cjs +23 -0
- package/dist/cjs/adapters/REST/endpoints/environment-template.cjs +49 -0
- package/dist/cjs/adapters/REST/endpoints/environment.cjs +47 -0
- package/dist/cjs/adapters/REST/endpoints/extension.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/function-log.cjs +23 -0
- package/dist/cjs/adapters/REST/endpoints/function.cjs +25 -0
- package/dist/cjs/adapters/REST/endpoints/http.cjs +29 -0
- package/dist/cjs/adapters/REST/endpoints/index.cjs +139 -0
- package/dist/cjs/adapters/REST/endpoints/locale.cjs +37 -0
- package/dist/cjs/adapters/REST/endpoints/oauth-application.cjs +147 -0
- package/dist/cjs/adapters/REST/endpoints/organization-invitation.cjs +23 -0
- package/dist/cjs/adapters/REST/endpoints/organization-membership.cjs +32 -0
- package/dist/cjs/adapters/REST/endpoints/organization.cjs +28 -0
- package/dist/cjs/adapters/REST/endpoints/personal-access-token.cjs +37 -0
- package/dist/cjs/adapters/REST/endpoints/preview-api-key.cjs +15 -0
- package/dist/cjs/adapters/REST/endpoints/raw.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/release-action.cjs +21 -0
- package/dist/cjs/adapters/REST/endpoints/release.cjs +61 -0
- package/dist/cjs/adapters/REST/endpoints/resource-provider.cjs +18 -0
- package/dist/cjs/adapters/REST/endpoints/resource-type.cjs +30 -0
- package/dist/cjs/adapters/REST/endpoints/resource.cjs +10 -0
- package/dist/cjs/adapters/REST/endpoints/role.cjs +48 -0
- package/dist/cjs/adapters/REST/endpoints/scheduled-action.cjs +44 -0
- package/dist/cjs/adapters/REST/endpoints/snapshot.cjs +30 -0
- package/dist/cjs/adapters/REST/endpoints/space-member.cjs +11 -0
- package/dist/cjs/adapters/REST/endpoints/space-membership.cjs +60 -0
- package/dist/cjs/adapters/REST/endpoints/space.cjs +34 -0
- package/dist/cjs/adapters/REST/endpoints/tag.cjs +37 -0
- package/dist/cjs/adapters/REST/endpoints/task.cjs +40 -0
- package/dist/cjs/adapters/REST/endpoints/team-membership.cjs +35 -0
- package/dist/cjs/adapters/REST/endpoints/team-space-membership.cjs +46 -0
- package/dist/cjs/adapters/REST/endpoints/team.cjs +36 -0
- package/dist/cjs/adapters/REST/endpoints/ui-config.cjs +22 -0
- package/dist/cjs/adapters/REST/endpoints/upload-credentials.cjs +16 -0
- package/dist/cjs/adapters/REST/endpoints/upload.cjs +42 -0
- package/dist/cjs/adapters/REST/endpoints/usage.cjs +17 -0
- package/dist/cjs/adapters/REST/endpoints/user-ui-config.cjs +22 -0
- package/dist/cjs/adapters/REST/endpoints/user.cjs +27 -0
- package/dist/cjs/adapters/REST/endpoints/utils.cjs +20 -0
- package/dist/cjs/adapters/REST/endpoints/webhook.cjs +98 -0
- package/dist/cjs/adapters/REST/endpoints/workflow-definition.cjs +41 -0
- package/dist/cjs/adapters/REST/endpoints/workflow.cjs +49 -0
- package/dist/cjs/adapters/REST/endpoints/workflows-changelog.cjs +11 -0
- package/dist/cjs/adapters/REST/make-request.cjs +19 -0
- package/dist/cjs/adapters/REST/rest-adapter.cjs +32 -0
- package/dist/cjs/common-types.cjs +6 -0
- package/dist/cjs/common-utils.cjs +38 -0
- package/dist/cjs/constants/editor-interface-defaults/controls-defaults.cjs +161 -0
- package/dist/cjs/constants/editor-interface-defaults/editors-defaults.cjs +40 -0
- package/dist/cjs/constants/editor-interface-defaults/index.cjs +14 -0
- package/dist/cjs/constants/editor-interface-defaults/sidebar-defaults.cjs +71 -0
- package/dist/cjs/constants/editor-interface-defaults/types.cjs +18 -0
- package/dist/cjs/create-adapter.cjs +21 -0
- package/dist/cjs/create-app-definition-api.cjs +254 -0
- package/dist/cjs/create-contentful-api.cjs +592 -0
- package/dist/cjs/create-entry-api.cjs +481 -0
- package/dist/cjs/create-environment-api.cjs +2403 -0
- package/dist/cjs/create-environment-template-api.cjs +270 -0
- package/dist/cjs/create-organization-api.cjs +1136 -0
- package/dist/cjs/create-space-api.cjs +1591 -0
- package/dist/cjs/create-ui-config-api.cjs +55 -0
- package/dist/cjs/create-user-ui-config-api.cjs +55 -0
- package/dist/cjs/enhance-with-methods.cjs +26 -0
- package/dist/cjs/entities/access-token.cjs +36 -0
- package/dist/cjs/entities/ai-action-invocation.cjs +46 -0
- package/dist/cjs/entities/ai-action.cjs +94 -0
- package/dist/cjs/entities/api-key.cjs +59 -0
- package/dist/cjs/entities/app-access-token.cjs +17 -0
- package/dist/cjs/entities/app-action-call.cjs +67 -0
- package/dist/cjs/entities/app-action.cjs +48 -0
- package/dist/cjs/entities/app-bundle.cjs +48 -0
- package/dist/cjs/entities/app-definition.cjs +29 -0
- package/dist/cjs/entities/app-details.cjs +39 -0
- package/dist/cjs/entities/app-event-subscription.cjs +34 -0
- package/dist/cjs/entities/app-installation.cjs +55 -0
- package/dist/cjs/entities/app-key.cjs +44 -0
- package/dist/cjs/entities/app-signed-request.cjs +17 -0
- package/dist/cjs/entities/app-signing-secret.cjs +34 -0
- package/dist/cjs/entities/app-upload.cjs +47 -0
- package/dist/cjs/entities/asset-key.cjs +17 -0
- package/dist/cjs/entities/asset.cjs +124 -0
- package/dist/cjs/entities/bulk-action.cjs +60 -0
- package/dist/cjs/entities/comment.cjs +63 -0
- package/dist/cjs/entities/concept-scheme.cjs +2 -0
- package/dist/cjs/entities/concept.cjs +2 -0
- package/dist/cjs/entities/content-type.cjs +120 -0
- package/dist/cjs/entities/editor-interface.cjs +50 -0
- package/dist/cjs/entities/entry.cjs +27 -0
- package/dist/cjs/entities/environment-alias.cjs +58 -0
- package/dist/cjs/entities/environment-template-installation.cjs +23 -0
- package/dist/cjs/entities/environment-template.cjs +18 -0
- package/dist/cjs/entities/environment.cjs +34 -0
- package/dist/cjs/entities/extension.cjs +54 -0
- package/dist/cjs/entities/function-log.cjs +26 -0
- package/dist/cjs/entities/function.cjs +66 -0
- package/dist/cjs/entities/index.cjs +131 -0
- package/dist/cjs/entities/locale.cjs +57 -0
- package/dist/cjs/entities/oauth-application.cjs +66 -0
- package/dist/cjs/entities/organization-invitation.cjs +17 -0
- package/dist/cjs/entities/organization-membership.cjs +53 -0
- package/dist/cjs/entities/organization.cjs +32 -0
- package/dist/cjs/entities/personal-access-token.cjs +36 -0
- package/dist/cjs/entities/preview-api-key.cjs +31 -0
- package/dist/cjs/entities/release-action.cjs +55 -0
- package/dist/cjs/entities/release.cjs +111 -0
- package/dist/cjs/entities/resource-provider.cjs +139 -0
- package/dist/cjs/entities/resource-type.cjs +98 -0
- package/dist/cjs/entities/resource.cjs +13 -0
- package/dist/cjs/entities/role.cjs +53 -0
- package/dist/cjs/entities/scheduled-action.cjs +154 -0
- package/dist/cjs/entities/snapshot.cjs +36 -0
- package/dist/cjs/entities/space-member.cjs +23 -0
- package/dist/cjs/entities/space-membership.cjs +53 -0
- package/dist/cjs/entities/space.cjs +33 -0
- package/dist/cjs/entities/tag.cjs +56 -0
- package/dist/cjs/entities/task.cjs +57 -0
- package/dist/cjs/entities/team-membership.cjs +54 -0
- package/dist/cjs/entities/team-space-membership.cjs +53 -0
- package/dist/cjs/entities/team.cjs +53 -0
- package/dist/cjs/entities/ui-config.cjs +20 -0
- package/dist/cjs/entities/upload.cjs +38 -0
- package/dist/cjs/entities/usage.cjs +25 -0
- package/dist/cjs/entities/user-ui-config.cjs +20 -0
- package/dist/cjs/entities/user.cjs +28 -0
- package/dist/cjs/entities/webhook.cjs +77 -0
- package/dist/cjs/entities/workflow-definition.cjs +79 -0
- package/dist/cjs/index.cjs +65 -0
- package/dist/cjs/methods/action.cjs +53 -0
- package/dist/cjs/methods/content-type.cjs +51 -0
- package/dist/cjs/methods/utils.cjs +11 -0
- package/dist/cjs/plain/as-iterator.cjs +32 -0
- package/dist/cjs/plain/checks.cjs +15 -0
- package/dist/cjs/plain/pagination-helper.cjs +56 -0
- package/dist/cjs/plain/plain-client.cjs +516 -0
- package/dist/cjs/plain/wrappers/wrap.cjs +26 -0
- package/dist/cjs/upload-http-client.cjs +17 -0
- package/dist/contentful-management.browser.js +50 -34
- package/dist/contentful-management.browser.min.js +1 -1
- package/dist/contentful-management.cjs +35 -19
- package/dist/esm/create-contentful-api.js +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/plain/plain-client.js +1 -1
- package/dist/stats-browser-min.html +1 -1
- package/package.json +6 -6
- package/types.d.ts +0 -1
|
@@ -0,0 +1,481 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var checks = require('./plain/checks.js');
|
|
4
|
+
var index = require('./entities/index.js');
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @private
|
|
8
|
+
*/
|
|
9
|
+
function createEntryApi(makeRequest) {
|
|
10
|
+
const { wrapEntry, wrapEntryCollection } = index.entry;
|
|
11
|
+
const { wrapSnapshot, wrapSnapshotCollection } = index.snapshot;
|
|
12
|
+
const { wrapTask, wrapTaskCollection } = index.task;
|
|
13
|
+
const { wrapComment, wrapCommentCollection } = index.comment;
|
|
14
|
+
const getParams = (self) => {
|
|
15
|
+
const entry = self.toPlainObject();
|
|
16
|
+
return {
|
|
17
|
+
params: {
|
|
18
|
+
spaceId: entry.sys.space.sys.id,
|
|
19
|
+
environmentId: entry.sys.environment.sys.id,
|
|
20
|
+
entryId: entry.sys.id,
|
|
21
|
+
},
|
|
22
|
+
raw: entry,
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
return {
|
|
26
|
+
/**
|
|
27
|
+
* Sends an update to the server with any changes made to the object's properties
|
|
28
|
+
* @return Object returned from the server with updated changes.
|
|
29
|
+
* @example ```javascript
|
|
30
|
+
* const contentful = require('contentful-management')
|
|
31
|
+
*
|
|
32
|
+
* const client = contentful.createClient({
|
|
33
|
+
* accessToken: '<content_management_api_key>'
|
|
34
|
+
* })
|
|
35
|
+
*
|
|
36
|
+
* client.getSpace('<space_id>')
|
|
37
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
38
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
39
|
+
* .then((entry) => {
|
|
40
|
+
* entry.fields.title['en-US'] = 'New entry title'
|
|
41
|
+
* return entry.update()
|
|
42
|
+
* })
|
|
43
|
+
* .then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
|
|
44
|
+
* .catch(console.error)
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
update: function update() {
|
|
48
|
+
const { raw, params } = getParams(this);
|
|
49
|
+
return makeRequest({
|
|
50
|
+
entityType: 'Entry',
|
|
51
|
+
action: 'update',
|
|
52
|
+
params,
|
|
53
|
+
payload: raw,
|
|
54
|
+
}).then((data) => wrapEntry(makeRequest, data));
|
|
55
|
+
},
|
|
56
|
+
/**
|
|
57
|
+
* Sends an JSON patch to the server with any changes made to the object's properties
|
|
58
|
+
* @return Object returned from the server with updated changes.
|
|
59
|
+
* @example ```javascript
|
|
60
|
+
* const contentful = require('contentful-management')
|
|
61
|
+
*
|
|
62
|
+
* const client = contentful.createClient({
|
|
63
|
+
* accessToken: '<content_management_api_key>'
|
|
64
|
+
* })
|
|
65
|
+
*
|
|
66
|
+
* client.getSpace('<space_id>')
|
|
67
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
68
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
69
|
+
* .then((entry) => entry.patch([
|
|
70
|
+
* {
|
|
71
|
+
* op: 'replace',
|
|
72
|
+
* path: '/fields/title/en-US',
|
|
73
|
+
* value: 'New entry title'
|
|
74
|
+
* }
|
|
75
|
+
* ]))
|
|
76
|
+
* .then((entry) => console.log(`Entry ${entry.sys.id} updated.`))
|
|
77
|
+
* .catch(console.error)
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
patch: function patch(ops) {
|
|
81
|
+
const { raw, params } = getParams(this);
|
|
82
|
+
return makeRequest({
|
|
83
|
+
entityType: 'Entry',
|
|
84
|
+
action: 'patch',
|
|
85
|
+
params: Object.assign(Object.assign({}, params), { version: raw.sys.version }),
|
|
86
|
+
payload: ops,
|
|
87
|
+
}).then((data) => wrapEntry(makeRequest, data));
|
|
88
|
+
},
|
|
89
|
+
/**
|
|
90
|
+
* Deletes this object on the server.
|
|
91
|
+
* @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
|
|
92
|
+
* @example ```javascript
|
|
93
|
+
* const contentful = require('contentful-management')
|
|
94
|
+
*
|
|
95
|
+
* const client = contentful.createClient({
|
|
96
|
+
* accessToken: '<content_management_api_key>'
|
|
97
|
+
* })
|
|
98
|
+
*
|
|
99
|
+
* client.getSpace('<space_id>')
|
|
100
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
101
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
102
|
+
* .then((entry) => entry.delete())
|
|
103
|
+
* .then(() => console.log(`Entry deleted.`))
|
|
104
|
+
* .catch(console.error)
|
|
105
|
+
* ```
|
|
106
|
+
*/
|
|
107
|
+
delete: function del() {
|
|
108
|
+
const { params } = getParams(this);
|
|
109
|
+
return makeRequest({ entityType: 'Entry', action: 'delete', params });
|
|
110
|
+
},
|
|
111
|
+
/**
|
|
112
|
+
* Publishes the object
|
|
113
|
+
* @return Object returned from the server with updated metadata.
|
|
114
|
+
* @example ```javascript
|
|
115
|
+
* const contentful = require('contentful-management')
|
|
116
|
+
*
|
|
117
|
+
* const client = contentful.createClient({
|
|
118
|
+
* accessToken: '<content_management_api_key>'
|
|
119
|
+
* })
|
|
120
|
+
*
|
|
121
|
+
* client.getSpace('<space_id>')
|
|
122
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
123
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
124
|
+
* .then((entry) => entry.publish())
|
|
125
|
+
* .then((entry) => console.log(`Entry ${entry.sys.id} published.`))
|
|
126
|
+
* .catch(console.error)
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
publish: function publish() {
|
|
130
|
+
const { raw, params } = getParams(this);
|
|
131
|
+
return makeRequest({
|
|
132
|
+
entityType: 'Entry',
|
|
133
|
+
action: 'publish',
|
|
134
|
+
params,
|
|
135
|
+
payload: raw,
|
|
136
|
+
}).then((data) => wrapEntry(makeRequest, data));
|
|
137
|
+
},
|
|
138
|
+
/**
|
|
139
|
+
* Unpublishes the object
|
|
140
|
+
* @return Object returned from the server with updated metadata.
|
|
141
|
+
* @example ```javascript
|
|
142
|
+
* const contentful = require('contentful-management')
|
|
143
|
+
*
|
|
144
|
+
* const client = contentful.createClient({
|
|
145
|
+
* accessToken: '<content_management_api_key>'
|
|
146
|
+
* })
|
|
147
|
+
*
|
|
148
|
+
* client.getSpace('<space_id>')
|
|
149
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
150
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
151
|
+
* .then((entry) => entry.unpublish())
|
|
152
|
+
* .then((entry) => console.log(`Entry ${entry.sys.id} unpublished.`))
|
|
153
|
+
* .catch(console.error)
|
|
154
|
+
* ```
|
|
155
|
+
*/
|
|
156
|
+
unpublish: function unpublish() {
|
|
157
|
+
const { params } = getParams(this);
|
|
158
|
+
return makeRequest({
|
|
159
|
+
entityType: 'Entry',
|
|
160
|
+
action: 'unpublish',
|
|
161
|
+
params,
|
|
162
|
+
}).then((data) => wrapEntry(makeRequest, data));
|
|
163
|
+
},
|
|
164
|
+
/**
|
|
165
|
+
* Archives the object
|
|
166
|
+
* @return Object returned from the server with updated metadata.
|
|
167
|
+
* @example ```javascript
|
|
168
|
+
* const contentful = require('contentful-management')
|
|
169
|
+
*
|
|
170
|
+
* const client = contentful.createClient({
|
|
171
|
+
* accessToken: '<content_management_api_key>'
|
|
172
|
+
* })
|
|
173
|
+
*
|
|
174
|
+
* client.getSpace('<space_id>')
|
|
175
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
176
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
177
|
+
* .then((entry) => entry.archive())
|
|
178
|
+
* .then((entry) => console.log(`Entry ${entry.sys.id} archived.`))
|
|
179
|
+
* .catch(console.error)
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
archive: function archive() {
|
|
183
|
+
const { params } = getParams(this);
|
|
184
|
+
return makeRequest({
|
|
185
|
+
entityType: 'Entry',
|
|
186
|
+
action: 'archive',
|
|
187
|
+
params,
|
|
188
|
+
}).then((data) => wrapEntry(makeRequest, data));
|
|
189
|
+
},
|
|
190
|
+
/**
|
|
191
|
+
* Unarchives the object
|
|
192
|
+
* @return Object returned from the server with updated metadata.
|
|
193
|
+
* @example ```javascript
|
|
194
|
+
* const contentful = require('contentful-management')
|
|
195
|
+
*
|
|
196
|
+
* const client = contentful.createClient({
|
|
197
|
+
* accessToken: '<content_management_api_key>'
|
|
198
|
+
* })
|
|
199
|
+
*
|
|
200
|
+
* client.getSpace('<space_id>')
|
|
201
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
202
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
203
|
+
* .then((entry) => entry.unarchive())
|
|
204
|
+
* .then((entry) => console.log(`Entry ${entry.sys.id} unarchived.`))
|
|
205
|
+
* .catch(console.error)
|
|
206
|
+
* ```
|
|
207
|
+
*/
|
|
208
|
+
unarchive: function unarchive() {
|
|
209
|
+
const { params } = getParams(this);
|
|
210
|
+
return makeRequest({
|
|
211
|
+
entityType: 'Entry',
|
|
212
|
+
action: 'unarchive',
|
|
213
|
+
params,
|
|
214
|
+
}).then((data) => wrapEntry(makeRequest, data));
|
|
215
|
+
},
|
|
216
|
+
/**
|
|
217
|
+
* Gets all snapshots of an entry
|
|
218
|
+
* @example ```javascript
|
|
219
|
+
* const contentful = require('contentful-management')
|
|
220
|
+
*
|
|
221
|
+
* const client = contentful.createClient({
|
|
222
|
+
* accessToken: '<content_management_api_key>'
|
|
223
|
+
* })
|
|
224
|
+
*
|
|
225
|
+
* client.getSpace('<space_id>')
|
|
226
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
227
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
228
|
+
* .then((entry) => entry.getSnapshots())
|
|
229
|
+
* .then((snapshots) => console.log(snapshots.items))
|
|
230
|
+
* .catch(console.error)
|
|
231
|
+
* ```
|
|
232
|
+
*/
|
|
233
|
+
getSnapshots: function (query = {}) {
|
|
234
|
+
const { params } = getParams(this);
|
|
235
|
+
return makeRequest({
|
|
236
|
+
entityType: 'Snapshot',
|
|
237
|
+
action: 'getManyForEntry',
|
|
238
|
+
params: Object.assign(Object.assign({}, params), { query }),
|
|
239
|
+
}).then((data) => wrapSnapshotCollection(makeRequest, data));
|
|
240
|
+
},
|
|
241
|
+
/**
|
|
242
|
+
* Gets a snapshot of an entry
|
|
243
|
+
* @param snapshotId - Id of the snapshot
|
|
244
|
+
* @example ```javascript
|
|
245
|
+
* const contentful = require('contentful-management')
|
|
246
|
+
*
|
|
247
|
+
* const client = contentful.createClient({
|
|
248
|
+
* accessToken: '<content_management_api_key>'
|
|
249
|
+
* })
|
|
250
|
+
*
|
|
251
|
+
* client.getSpace('<space_id>')
|
|
252
|
+
* .then((space) => space.getEnvironment('<environment_id>'))
|
|
253
|
+
* .then((environment) => environment.getEntry('<entry_id>'))
|
|
254
|
+
* .then((entry) => entry.getSnapshot('<snapshot_id>'))
|
|
255
|
+
* .then((snapshot) => console.log(snapshot))
|
|
256
|
+
* .catch(console.error)
|
|
257
|
+
* ```
|
|
258
|
+
*/
|
|
259
|
+
getSnapshot: function (snapshotId) {
|
|
260
|
+
const { params } = getParams(this);
|
|
261
|
+
return makeRequest({
|
|
262
|
+
entityType: 'Snapshot',
|
|
263
|
+
action: 'getForEntry',
|
|
264
|
+
params: Object.assign(Object.assign({}, params), { snapshotId }),
|
|
265
|
+
}).then((data) => wrapSnapshot(makeRequest, data));
|
|
266
|
+
},
|
|
267
|
+
/**
|
|
268
|
+
* Creates a new comment for an entry
|
|
269
|
+
* @param data Object representation of the Comment to be created
|
|
270
|
+
* @returns Promise for the newly created Comment
|
|
271
|
+
* @example ```javascript
|
|
272
|
+
* const contentful = require('contentful-management')
|
|
273
|
+
*
|
|
274
|
+
* const client = contentful.createClient({
|
|
275
|
+
* accessToken: '<content_management_api_key>'
|
|
276
|
+
* })
|
|
277
|
+
*
|
|
278
|
+
* client.getSpace('<space_id>')
|
|
279
|
+
* .then((space) => space.getEnvironment('<environment-id>'))
|
|
280
|
+
* .then((environment) => environment.getEntry('<entry-id>'))
|
|
281
|
+
* .then((entry) => entry.createComment({
|
|
282
|
+
* body: 'Something left to do'
|
|
283
|
+
* }))
|
|
284
|
+
* .then((comment) => console.log(comment))
|
|
285
|
+
* .catch(console.error)
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
createComment: function (data) {
|
|
289
|
+
const { params } = getParams(this);
|
|
290
|
+
return makeRequest({
|
|
291
|
+
entityType: 'Comment',
|
|
292
|
+
action: 'create',
|
|
293
|
+
params: {
|
|
294
|
+
spaceId: params.spaceId,
|
|
295
|
+
environmentId: params.environmentId,
|
|
296
|
+
parentEntityId: params.entryId,
|
|
297
|
+
parentEntityType: 'Entry',
|
|
298
|
+
},
|
|
299
|
+
payload: data,
|
|
300
|
+
}).then((data) => wrapComment(makeRequest, data));
|
|
301
|
+
},
|
|
302
|
+
/**
|
|
303
|
+
* Gets all comments of an entry
|
|
304
|
+
* @returns
|
|
305
|
+
* const contentful = require('contentful-management')
|
|
306
|
+
*
|
|
307
|
+
* const client = contentful.createClient({
|
|
308
|
+
* accessToken: '<content_management_api_key>'
|
|
309
|
+
* })
|
|
310
|
+
*
|
|
311
|
+
* client.getSpace('<space_id>')
|
|
312
|
+
* .then((space) => space.getEnvironment('<environment-id>'))
|
|
313
|
+
* .then((environment) => environment.getEntry('<entry-id>'))
|
|
314
|
+
* .then((entry) => entry.getComments())
|
|
315
|
+
* .then((comments) => console.log(comments))
|
|
316
|
+
* .catch(console.error)
|
|
317
|
+
* ```
|
|
318
|
+
*/
|
|
319
|
+
getComments: function () {
|
|
320
|
+
const { params } = getParams(this);
|
|
321
|
+
return makeRequest({
|
|
322
|
+
entityType: 'Comment',
|
|
323
|
+
action: 'getMany',
|
|
324
|
+
params,
|
|
325
|
+
}).then((data) => wrapCommentCollection(makeRequest, data));
|
|
326
|
+
},
|
|
327
|
+
/**
|
|
328
|
+
* Gets a comment of an entry
|
|
329
|
+
* @returns
|
|
330
|
+
* const contentful = require('contentful-management')
|
|
331
|
+
*
|
|
332
|
+
* const client = contentful.createClient({
|
|
333
|
+
* accessToken: '<content_management_api_key>'
|
|
334
|
+
* })
|
|
335
|
+
*
|
|
336
|
+
* client.getSpace('<space_id>')
|
|
337
|
+
* .then((space) => space.getEnvironment('<environment-id>'))
|
|
338
|
+
* .then((environment) => environment.getEntry('<entry-id>'))
|
|
339
|
+
* .then((entry) => entry.getComment(`<comment-id>`))
|
|
340
|
+
* .then((comment) => console.log(comment))
|
|
341
|
+
* .catch(console.error)
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
getComment: function (id) {
|
|
345
|
+
const { params } = getParams(this);
|
|
346
|
+
return makeRequest({
|
|
347
|
+
entityType: 'Comment',
|
|
348
|
+
action: 'get',
|
|
349
|
+
params: Object.assign(Object.assign({}, params), { commentId: id }),
|
|
350
|
+
}).then((data) => wrapComment(makeRequest, data));
|
|
351
|
+
},
|
|
352
|
+
/**
|
|
353
|
+
* Creates a new task for an entry
|
|
354
|
+
* @param data Object representation of the Task to be created
|
|
355
|
+
* @returns Promise for the newly created Task
|
|
356
|
+
* @example ```javascript
|
|
357
|
+
* const contentful = require('contentful-management')
|
|
358
|
+
*
|
|
359
|
+
* const client = contentful.createClient({
|
|
360
|
+
* accessToken: '<content_management_api_key>'
|
|
361
|
+
* })
|
|
362
|
+
*
|
|
363
|
+
* client.getSpace('<space_id>')
|
|
364
|
+
* .then((space) => space.getEnvironment('<environment-id>'))
|
|
365
|
+
* .then((environment) => environment.getEntry('<entry-id>'))
|
|
366
|
+
* .then((entry) => entry.createTask({
|
|
367
|
+
* body: 'Something left to do',
|
|
368
|
+
* assignedTo: '<user-id>',
|
|
369
|
+
* status: 'active'
|
|
370
|
+
* }))
|
|
371
|
+
* .then((task) => console.log(task))
|
|
372
|
+
* .catch(console.error)
|
|
373
|
+
* ```
|
|
374
|
+
*/
|
|
375
|
+
createTask: function (data) {
|
|
376
|
+
const { params } = getParams(this);
|
|
377
|
+
return makeRequest({
|
|
378
|
+
entityType: 'Task',
|
|
379
|
+
action: 'create',
|
|
380
|
+
params,
|
|
381
|
+
payload: data,
|
|
382
|
+
}).then((data) => wrapTask(makeRequest, data));
|
|
383
|
+
},
|
|
384
|
+
/**
|
|
385
|
+
* Gets all tasks of an entry
|
|
386
|
+
* @returns
|
|
387
|
+
* const contentful = require('contentful-management')
|
|
388
|
+
*
|
|
389
|
+
* const client = contentful.createClient({
|
|
390
|
+
* accessToken: '<content_management_api_key>'
|
|
391
|
+
* })
|
|
392
|
+
*
|
|
393
|
+
* client.getSpace('<space_id>')
|
|
394
|
+
* .then((space) => space.getEnvironment('<environment-id>'))
|
|
395
|
+
* .then((environment) => environment.getEntry('<entry-id>'))
|
|
396
|
+
* .then((entry) => entry.getTasks())
|
|
397
|
+
* .then((tasks) => console.log(tasks))
|
|
398
|
+
* .catch(console.error)
|
|
399
|
+
* ```
|
|
400
|
+
*/
|
|
401
|
+
getTasks: function (query = {}) {
|
|
402
|
+
const { params } = getParams(this);
|
|
403
|
+
return makeRequest({
|
|
404
|
+
entityType: 'Task',
|
|
405
|
+
action: 'getMany',
|
|
406
|
+
params: Object.assign(Object.assign({}, params), { query }),
|
|
407
|
+
}).then((data) => wrapTaskCollection(makeRequest, data));
|
|
408
|
+
},
|
|
409
|
+
/**
|
|
410
|
+
* Gets a task of an entry
|
|
411
|
+
* @returns
|
|
412
|
+
* const contentful = require('contentful-management')
|
|
413
|
+
*
|
|
414
|
+
* const client = contentful.createClient({
|
|
415
|
+
* accessToken: '<content_management_api_key>'
|
|
416
|
+
* })
|
|
417
|
+
*
|
|
418
|
+
* client.getSpace('<space_id>')
|
|
419
|
+
* .then((space) => space.getEnvironment('<environment-id>'))
|
|
420
|
+
* .then((environment) => environment.getEntry('<entry-id>'))
|
|
421
|
+
* .then((entry) => entry.getTask(`<task-id>`))
|
|
422
|
+
* .then((task) => console.log(task))
|
|
423
|
+
* .catch(console.error)
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
getTask: function (id) {
|
|
427
|
+
const { params } = getParams(this);
|
|
428
|
+
return makeRequest({
|
|
429
|
+
entityType: 'Task',
|
|
430
|
+
action: 'get',
|
|
431
|
+
params: Object.assign(Object.assign({}, params), { taskId: id }),
|
|
432
|
+
}).then((data) => wrapTask(makeRequest, data));
|
|
433
|
+
},
|
|
434
|
+
/**
|
|
435
|
+
* Checks if the entry is published. A published entry might have unpublished changes
|
|
436
|
+
*/
|
|
437
|
+
isPublished: function isPublished() {
|
|
438
|
+
const raw = this.toPlainObject();
|
|
439
|
+
return checks.isPublished(raw);
|
|
440
|
+
},
|
|
441
|
+
/**
|
|
442
|
+
* Checks if the entry is updated. This means the entry was previously published but has unpublished changes.
|
|
443
|
+
*/
|
|
444
|
+
isUpdated: function isUpdated() {
|
|
445
|
+
const raw = this.toPlainObject();
|
|
446
|
+
return checks.isUpdated(raw);
|
|
447
|
+
},
|
|
448
|
+
/**
|
|
449
|
+
* Checks if the entry is in draft mode. This means it is not published.
|
|
450
|
+
*/
|
|
451
|
+
isDraft: function isDraft() {
|
|
452
|
+
const raw = this.toPlainObject();
|
|
453
|
+
return checks.isDraft(raw);
|
|
454
|
+
},
|
|
455
|
+
/**
|
|
456
|
+
* Checks if entry is archived. This means it's not exposed to the Delivery/Preview APIs.
|
|
457
|
+
*/
|
|
458
|
+
isArchived: function isArchived() {
|
|
459
|
+
const raw = this.toPlainObject();
|
|
460
|
+
return checks.isArchived(raw);
|
|
461
|
+
},
|
|
462
|
+
/**
|
|
463
|
+
* Recursively collects references of an entry and their descendants
|
|
464
|
+
*/
|
|
465
|
+
references: function references(options) {
|
|
466
|
+
const raw = this.toPlainObject();
|
|
467
|
+
return makeRequest({
|
|
468
|
+
entityType: 'Entry',
|
|
469
|
+
action: 'references',
|
|
470
|
+
params: {
|
|
471
|
+
spaceId: raw.sys.space.sys.id,
|
|
472
|
+
environmentId: raw.sys.environment.sys.id,
|
|
473
|
+
entryId: raw.sys.id,
|
|
474
|
+
include: options === null || options === void 0 ? void 0 : options.include,
|
|
475
|
+
},
|
|
476
|
+
}).then((response) => wrapEntryCollection(makeRequest, response));
|
|
477
|
+
},
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
module.exports = createEntryApi;
|