1 | /**
|
2 | * Contentful Space API. Contains methods to access any operations at a space
|
3 | * level, such as creating and reading entities contained in a space.
|
4 | */
|
5 | import { createRequestConfig } from 'contentful-sdk-core';
|
6 | import entities from './entities';
|
7 |
|
8 | /**
|
9 | * Creates API object with methods to access the Space API
|
10 | * @param {MakeRequest} makeRequest - function to make requests via an adapter
|
11 | * @return {ContentfulSpaceAPI}
|
12 | * @private
|
13 | */
|
14 | export default function createSpaceApi(makeRequest) {
|
15 | var wrapSpace = entities.space.wrapSpace;
|
16 | var _entities$environment = entities.environment,
|
17 | wrapEnvironment = _entities$environment.wrapEnvironment,
|
18 | wrapEnvironmentCollection = _entities$environment.wrapEnvironmentCollection;
|
19 | var _entities$webhook = entities.webhook,
|
20 | wrapWebhook = _entities$webhook.wrapWebhook,
|
21 | wrapWebhookCollection = _entities$webhook.wrapWebhookCollection;
|
22 | var _entities$role = entities.role,
|
23 | wrapRole = _entities$role.wrapRole,
|
24 | wrapRoleCollection = _entities$role.wrapRoleCollection;
|
25 | var _entities$user = entities.user,
|
26 | wrapUser = _entities$user.wrapUser,
|
27 | wrapUserCollection = _entities$user.wrapUserCollection;
|
28 | var _entities$spaceMember = entities.spaceMember,
|
29 | wrapSpaceMember = _entities$spaceMember.wrapSpaceMember,
|
30 | wrapSpaceMemberCollection = _entities$spaceMember.wrapSpaceMemberCollection;
|
31 | var _entities$spaceMember2 = entities.spaceMembership,
|
32 | wrapSpaceMembership = _entities$spaceMember2.wrapSpaceMembership,
|
33 | wrapSpaceMembershipCollection = _entities$spaceMember2.wrapSpaceMembershipCollection;
|
34 | var _entities$teamSpaceMe = entities.teamSpaceMembership,
|
35 | wrapTeamSpaceMembership = _entities$teamSpaceMe.wrapTeamSpaceMembership,
|
36 | wrapTeamSpaceMembershipCollection = _entities$teamSpaceMe.wrapTeamSpaceMembershipCollection;
|
37 | var wrapTeamCollection = entities.team.wrapTeamCollection;
|
38 | var _entities$apiKey = entities.apiKey,
|
39 | wrapApiKey = _entities$apiKey.wrapApiKey,
|
40 | wrapApiKeyCollection = _entities$apiKey.wrapApiKeyCollection;
|
41 | var _entities$environment2 = entities.environmentAlias,
|
42 | wrapEnvironmentAlias = _entities$environment2.wrapEnvironmentAlias,
|
43 | wrapEnvironmentAliasCollection = _entities$environment2.wrapEnvironmentAliasCollection;
|
44 | var _entities$previewApiK = entities.previewApiKey,
|
45 | wrapPreviewApiKey = _entities$previewApiK.wrapPreviewApiKey,
|
46 | wrapPreviewApiKeyCollection = _entities$previewApiK.wrapPreviewApiKeyCollection;
|
47 | var _entities$scheduledAc = entities.scheduledAction,
|
48 | wrapScheduledAction = _entities$scheduledAc.wrapScheduledAction,
|
49 | wrapScheduledActionCollection = _entities$scheduledAc.wrapScheduledActionCollection;
|
50 | return {
|
51 | /**
|
52 | * Deletes the space
|
53 | * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
|
54 | * @example ```javascript
|
55 | * const contentful = require('contentful-management')
|
56 | *
|
57 | * const client = contentful.createClient({
|
58 | * accessToken: '<content_management_api_key>'
|
59 | * })
|
60 | *
|
61 | * client.getSpace('<space_id>')
|
62 | * .then((space) => space.delete())
|
63 | * .then(() => console.log('Space deleted.'))
|
64 | * .catch(console.error)
|
65 | * ```
|
66 | */
|
67 | "delete": function deleteSpace() {
|
68 | var raw = this.toPlainObject();
|
69 | return makeRequest({
|
70 | entityType: 'Space',
|
71 | action: 'delete',
|
72 | params: {
|
73 | spaceId: raw.sys.id
|
74 | }
|
75 | });
|
76 | },
|
77 |
|
78 | /**
|
79 | * Updates the space
|
80 | * @return Promise for the updated space.
|
81 | * @example ```javascript
|
82 | * const contentful = require('contentful-management')
|
83 | *
|
84 | * const client = contentful.createClient({
|
85 | * accessToken: '<content_management_api_key>'
|
86 | * })
|
87 | *
|
88 | * client.getSpace('<space_id>')
|
89 | * .then((space) => {
|
90 | * space.name = 'New name'
|
91 | * return space.update()
|
92 | * })
|
93 | * .then((space) => console.log(`Space ${space.sys.id} renamed.`)
|
94 | * .catch(console.error)
|
95 | * ```
|
96 | */
|
97 | update: function updateSpace() {
|
98 | var raw = this.toPlainObject();
|
99 | return makeRequest({
|
100 | entityType: 'Space',
|
101 | action: 'update',
|
102 | params: {
|
103 | spaceId: raw.sys.id
|
104 | },
|
105 | payload: raw,
|
106 | headers: {}
|
107 | }).then(function (data) {
|
108 | return wrapSpace(makeRequest, data);
|
109 | });
|
110 | },
|
111 |
|
112 | /**
|
113 | * Gets an environment
|
114 | * @param id - Environment ID
|
115 | * @return Promise for an Environment
|
116 | * @example ```javascript
|
117 | * const contentful = require('contentful-management')
|
118 | *
|
119 | * const client = contentful.createClient({
|
120 | * accessToken: '<content_management_api_key>'
|
121 | * })
|
122 | *
|
123 | * client.getSpace('<space_id>')
|
124 | * .then((space) => space.getEnvironment('<environement_id>'))
|
125 | * .then((environment) => console.log(environment))
|
126 | * .catch(console.error)
|
127 | * ```
|
128 | */
|
129 | getEnvironment: function getEnvironment(environmentId) {
|
130 | var raw = this.toPlainObject();
|
131 | return makeRequest({
|
132 | entityType: 'Environment',
|
133 | action: 'get',
|
134 | params: {
|
135 | spaceId: raw.sys.id,
|
136 | environmentId: environmentId
|
137 | }
|
138 | }).then(function (data) {
|
139 | return wrapEnvironment(makeRequest, data);
|
140 | });
|
141 | },
|
142 |
|
143 | /**
|
144 | * Gets a collection of Environments
|
145 | * @return Promise for a collection of Environment
|
146 | * @example ```javascript
|
147 | * const contentful = require('contentful-management')
|
148 | *
|
149 | * const client = contentful.createClient({
|
150 | * accessToken: '<content_management_api_key>'
|
151 | * })
|
152 | *
|
153 | * client.getSpace('<space_id>')
|
154 | * .then((space) => space.getEnvironments())
|
155 | * .then((response) => console.log(response.items))
|
156 | * .catch(console.error)
|
157 | * ```
|
158 | */
|
159 | getEnvironments: function getEnvironments() {
|
160 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
161 | var raw = this.toPlainObject();
|
162 | return makeRequest({
|
163 | entityType: 'Environment',
|
164 | action: 'getMany',
|
165 | params: {
|
166 | spaceId: raw.sys.id,
|
167 | query: query
|
168 | }
|
169 | }).then(function (data) {
|
170 | return wrapEnvironmentCollection(makeRequest, data);
|
171 | });
|
172 | },
|
173 |
|
174 | /**
|
175 | * Creates an Environement
|
176 | * @param data - Object representation of the Environment to be created
|
177 | * @return Promise for the newly created Environment
|
178 | * @example ```javascript
|
179 | * const contentful = require('contentful-management')
|
180 | *
|
181 | * const client = contentful.createClient({
|
182 | * accessToken: '<content_management_api_key>'
|
183 | * })
|
184 | *
|
185 | * client.getSpace('<space_id>')
|
186 | * .then((space) => space.createEnvironment({ name: 'Staging' }))
|
187 | * .then((environment) => console.log(environment))
|
188 | * .catch(console.error)
|
189 | * ```
|
190 | */
|
191 | createEnvironment: function createEnvironment() {
|
192 | var data = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
193 | var raw = this.toPlainObject();
|
194 | return makeRequest({
|
195 | entityType: 'Environment',
|
196 | action: 'create',
|
197 | params: {
|
198 | spaceId: raw.sys.id
|
199 | },
|
200 | payload: data
|
201 | }).then(function (response) {
|
202 | return wrapEnvironment(makeRequest, response);
|
203 | });
|
204 | },
|
205 |
|
206 | /**
|
207 | * Creates an Environment with a custom ID
|
208 | * @param id - Environment ID
|
209 | * @param data - Object representation of the Environment to be created
|
210 | * @param sourceEnvironmentId - ID of the source environment that will be copied to create the new environment. Default is "master"
|
211 | * @return Promise for the newly created Environment
|
212 | * @example ```javascript
|
213 | * const contentful = require('contentful-management')
|
214 | *
|
215 | * const client = contentful.createClient({
|
216 | * accessToken: '<content_management_api_key>'
|
217 | * })
|
218 | *
|
219 | * client.getSpace('<space_id>')
|
220 | * .then((space) => space.createEnvironmentWithId('<environment-id>', { name: 'Staging'}, 'master'))
|
221 | * .then((environment) => console.log(environment))
|
222 | * .catch(console.error)
|
223 | * ```
|
224 | */
|
225 | createEnvironmentWithId: function createEnvironmentWithId(id, data, sourceEnvironmentId) {
|
226 | var raw = this.toPlainObject();
|
227 | return makeRequest({
|
228 | entityType: 'Environment',
|
229 | action: 'createWithId',
|
230 | params: {
|
231 | spaceId: raw.sys.id,
|
232 | environmentId: id,
|
233 | sourceEnvironmentId: sourceEnvironmentId
|
234 | },
|
235 | payload: data
|
236 | }).then(function (response) {
|
237 | return wrapEnvironment(makeRequest, response);
|
238 | });
|
239 | },
|
240 |
|
241 | /**
|
242 | * Gets a Webhook
|
243 | * @param id - Webhook ID
|
244 | * @return Promise for a Webhook
|
245 | * @example ```javascript
|
246 | * const contentful = require('contentful-management')
|
247 | *
|
248 | * const client = contentful.createClient({
|
249 | * accessToken: '<content_management_api_key>'
|
250 | * })
|
251 | *
|
252 | * client.getSpace('<space_id>')
|
253 | * .then((space) => space.getWebhook('<webhook_id>'))
|
254 | * .then((webhook) => console.log(webhook))
|
255 | * .catch(console.error)
|
256 | * ```
|
257 | */
|
258 | getWebhook: function getWebhook(id) {
|
259 | var raw = this.toPlainObject();
|
260 | return makeRequest({
|
261 | entityType: 'Webhook',
|
262 | action: 'get',
|
263 | params: {
|
264 | spaceId: raw.sys.id,
|
265 | webhookDefinitionId: id
|
266 | }
|
267 | }).then(function (data) {
|
268 | return wrapWebhook(makeRequest, data);
|
269 | });
|
270 | },
|
271 |
|
272 | /**
|
273 | * Gets a collection of Webhooks
|
274 | * @return Promise for a collection of Webhooks
|
275 | * @example ```javascript
|
276 | * const contentful = require('contentful-management')
|
277 | *
|
278 | * const client = contentful.createClient({
|
279 | * accessToken: '<content_management_api_key>'
|
280 | * })
|
281 | *
|
282 | * client.getSpace('<space_id>')
|
283 | * .then((space) => space.getWebhooks())
|
284 | * .then((response) => console.log(response.items))
|
285 | * .catch(console.error)
|
286 | * ```
|
287 | */
|
288 | getWebhooks: function getWebhooks() {
|
289 | var raw = this.toPlainObject();
|
290 | return makeRequest({
|
291 | entityType: 'Webhook',
|
292 | action: 'getMany',
|
293 | params: {
|
294 | spaceId: raw.sys.id
|
295 | }
|
296 | }).then(function (data) {
|
297 | return wrapWebhookCollection(makeRequest, data);
|
298 | });
|
299 | },
|
300 |
|
301 | /**
|
302 | * Creates a Webhook
|
303 | * @param data - Object representation of the Webhook to be created
|
304 | * @return Promise for the newly created Webhook
|
305 | * @example ```javascript
|
306 | * const contentful = require('contentful-management')
|
307 | *
|
308 | * client.getSpace('<space_id>')
|
309 | * .then((space) => space.createWebhook({
|
310 | * 'name': 'My webhook',
|
311 | * 'url': 'https://www.example.com/test',
|
312 | * 'topics': [
|
313 | * 'Entry.create',
|
314 | * 'ContentType.create',
|
315 | * '*.publish',
|
316 | * 'Asset.*'
|
317 | * ]
|
318 | * }))
|
319 | * .then((webhook) => console.log(webhook))
|
320 | * .catch(console.error)
|
321 | * ```
|
322 | */
|
323 | createWebhook: function createWebhook(data) {
|
324 | var raw = this.toPlainObject();
|
325 | return makeRequest({
|
326 | entityType: 'Webhook',
|
327 | action: 'create',
|
328 | params: {
|
329 | spaceId: raw.sys.id
|
330 | },
|
331 | payload: data
|
332 | }).then(function (data) {
|
333 | return wrapWebhook(makeRequest, data);
|
334 | });
|
335 | },
|
336 |
|
337 | /**
|
338 | * Creates a Webhook with a custom ID
|
339 | * @param id - Webhook ID
|
340 | * @param data - Object representation of the Webhook to be created
|
341 | * @return Promise for the newly created Webhook
|
342 | * @example ```javascript
|
343 | * const contentful = require('contentful-management')
|
344 | *
|
345 | * client.getSpace('<space_id>')
|
346 | * .then((space) => space.createWebhookWithId('<webhook_id>', {
|
347 | * 'name': 'My webhook',
|
348 | * 'url': 'https://www.example.com/test',
|
349 | * 'topics': [
|
350 | * 'Entry.create',
|
351 | * 'ContentType.create',
|
352 | * '*.publish',
|
353 | * 'Asset.*'
|
354 | * ]
|
355 | * }))
|
356 | * .then((webhook) => console.log(webhook))
|
357 | * .catch(console.error)
|
358 | * ```
|
359 | */
|
360 | createWebhookWithId: function createWebhookWithId(id, data) {
|
361 | var raw = this.toPlainObject();
|
362 | return makeRequest({
|
363 | entityType: 'Webhook',
|
364 | action: 'createWithId',
|
365 | params: {
|
366 | spaceId: raw.sys.id,
|
367 | webhookDefinitionId: id
|
368 | },
|
369 | payload: data
|
370 | }).then(function (data) {
|
371 | return wrapWebhook(makeRequest, data);
|
372 | });
|
373 | },
|
374 |
|
375 | /**
|
376 | * Gets a Role
|
377 | * @param id - Role ID
|
378 | * @return Promise for a Role
|
379 | * @example ```javascript
|
380 | * const contentful = require('contentful-management')
|
381 | *
|
382 | * const client = contentful.createClient({
|
383 | * accessToken: '<content_management_api_key>'
|
384 | * })
|
385 | *
|
386 | * client.getSpace('<space_id>')
|
387 | * .then((space) => space.createRole({
|
388 | * fields: {
|
389 | * title: {
|
390 | * 'en-US': 'Role title'
|
391 | * }
|
392 | * }
|
393 | * }))
|
394 | * .then((role) => console.log(role))
|
395 | * .catch(console.error)
|
396 | * ```
|
397 | */
|
398 | getRole: function getRole(id) {
|
399 | var raw = this.toPlainObject();
|
400 | return makeRequest({
|
401 | entityType: 'Role',
|
402 | action: 'get',
|
403 | params: {
|
404 | spaceId: raw.sys.id,
|
405 | roleId: id
|
406 | }
|
407 | }).then(function (data) {
|
408 | return wrapRole(makeRequest, data);
|
409 | });
|
410 | },
|
411 |
|
412 | /**
|
413 | * Gets a collection of Roles
|
414 | * @return Promise for a collection of Roles
|
415 | * @example ```javascript
|
416 | * const contentful = require('contentful-management')
|
417 | *
|
418 | * const client = contentful.createClient({
|
419 | * accessToken: '<content_management_api_key>'
|
420 | * })
|
421 | *
|
422 | * client.getSpace('<space_id>')
|
423 | * .then((space) => space.getRoles())
|
424 | * .then((response) => console.log(response.items))
|
425 | * .catch(console.error)
|
426 | * ```
|
427 | */
|
428 | getRoles: function getRoles() {
|
429 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
430 | var raw = this.toPlainObject();
|
431 | return makeRequest({
|
432 | entityType: 'Role',
|
433 | action: 'getMany',
|
434 | params: {
|
435 | spaceId: raw.sys.id,
|
436 | query: createRequestConfig({
|
437 | query: query
|
438 | }).params
|
439 | }
|
440 | }).then(function (data) {
|
441 | return wrapRoleCollection(makeRequest, data);
|
442 | });
|
443 | },
|
444 |
|
445 | /**
|
446 | * Creates a Role
|
447 | * @param data - Object representation of the Role to be created
|
448 | * @return Promise for the newly created Role
|
449 | * @example ```javascript
|
450 | * const contentful = require('contentful-management')
|
451 | *
|
452 | * const client = contentful.createClient({
|
453 | * accessToken: '<content_management_api_key>'
|
454 | * })
|
455 | * client.getSpace('<space_id>')
|
456 | * .then((space) => space.createRole({
|
457 | * name: 'My Role',
|
458 | * description: 'foobar role',
|
459 | * permissions: {
|
460 | * ContentDelivery: 'all',
|
461 | * ContentModel: ['read'],
|
462 | * Settings: []
|
463 | * },
|
464 | * policies: [
|
465 | * {
|
466 | * effect: 'allow',
|
467 | * actions: 'all',
|
468 | * constraint: {
|
469 | * and: [
|
470 | * {
|
471 | * equals: [
|
472 | * { doc: 'sys.type' },
|
473 | * 'Entry'
|
474 | * ]
|
475 | * },
|
476 | * {
|
477 | * equals: [
|
478 | * { doc: 'sys.type' },
|
479 | * 'Asset'
|
480 | * ]
|
481 | * }
|
482 | * ]
|
483 | * }
|
484 | * }
|
485 | * ]
|
486 | * }))
|
487 | * .then((role) => console.log(role))
|
488 | * .catch(console.error)
|
489 | * ```
|
490 | */
|
491 | createRole: function createRole(data) {
|
492 | var raw = this.toPlainObject();
|
493 | return makeRequest({
|
494 | entityType: 'Role',
|
495 | action: 'create',
|
496 | params: {
|
497 | spaceId: raw.sys.id
|
498 | },
|
499 | payload: data
|
500 | }).then(function (data) {
|
501 | return wrapRole(makeRequest, data);
|
502 | });
|
503 | },
|
504 |
|
505 | /**
|
506 | * Creates a Role with a custom ID
|
507 | * @param id - Role ID
|
508 | * @param data - Object representation of the Role to be created
|
509 | * @return Promise for the newly created Role
|
510 | * @example ```javascript
|
511 | * const contentful = require('contentful-management')
|
512 | *
|
513 | * const client = contentful.createClient({
|
514 | * accessToken: '<content_management_api_key>'
|
515 | * })
|
516 | * client.getSpace('<space_id>')
|
517 | * .then((space) => space.createRoleWithId('<role-id>', {
|
518 | * name: 'My Role',
|
519 | * description: 'foobar role',
|
520 | * permissions: {
|
521 | * ContentDelivery: 'all',
|
522 | * ContentModel: ['read'],
|
523 | * Settings: []
|
524 | * },
|
525 | * policies: [
|
526 | * {
|
527 | * effect: 'allow',
|
528 | * actions: 'all',
|
529 | * constraint: {
|
530 | * and: [
|
531 | * {
|
532 | * equals: [
|
533 | * { doc: 'sys.type' },
|
534 | * 'Entry'
|
535 | * ]
|
536 | * },
|
537 | * {
|
538 | * equals: [
|
539 | * { doc: 'sys.type' },
|
540 | * 'Asset'
|
541 | * ]
|
542 | * }
|
543 | * ]
|
544 | * }
|
545 | * }
|
546 | * ]
|
547 | * }))
|
548 | * .then((role) => console.log(role))
|
549 | * .catch(console.error)
|
550 | * ```
|
551 | */
|
552 | createRoleWithId: function createRoleWithId(id, roleData) {
|
553 | var raw = this.toPlainObject();
|
554 | return makeRequest({
|
555 | entityType: 'Role',
|
556 | action: 'createWithId',
|
557 | params: {
|
558 | spaceId: raw.sys.id,
|
559 | roleId: id
|
560 | },
|
561 | payload: roleData
|
562 | }).then(function (data) {
|
563 | return wrapRole(makeRequest, data);
|
564 | });
|
565 | },
|
566 |
|
567 | /**
|
568 | * Gets a User
|
569 | * @param userId - User ID
|
570 | * @return Promise for a User
|
571 | * @example ```javascript
|
572 | * const contentful = require('contentful-management')
|
573 | *
|
574 | * client.getSpace('<space_id>')
|
575 | * .then((space) => space.getSpaceUser('id'))
|
576 | * .then((user) => console.log(user))
|
577 | * .catch(console.error)
|
578 | * ```
|
579 | */
|
580 | getSpaceUser: function getSpaceUser(userId) {
|
581 | var raw = this.toPlainObject();
|
582 | return makeRequest({
|
583 | entityType: 'User',
|
584 | action: 'getForSpace',
|
585 | params: {
|
586 | spaceId: raw.sys.id,
|
587 | userId: userId
|
588 | }
|
589 | }).then(function (data) {
|
590 | return wrapUser(makeRequest, data);
|
591 | });
|
592 | },
|
593 |
|
594 | /**
|
595 | * Gets a collection of Users in a space
|
596 | * @param query - Object with search parameters. Check the <a href="https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/#retrieving-entries-with-search-parameters">JS SDK tutorial</a> and the <a href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters">REST API reference</a> for more details.
|
597 | * @return Promise a collection of Users in a space
|
598 | * @example ```javascript
|
599 | * const contentful = require('contentful-management')
|
600 | *
|
601 | * client.getSpace('<space_id>')
|
602 | * .then((space) => space.getSpaceUsers(query))
|
603 | * .then((data) => console.log(data))
|
604 | * .catch(console.error)
|
605 | * ```
|
606 | */
|
607 | getSpaceUsers: function getSpaceUsers() {
|
608 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
609 | var raw = this.toPlainObject();
|
610 | return makeRequest({
|
611 | entityType: 'User',
|
612 | action: 'getManyForSpace',
|
613 | params: {
|
614 | spaceId: raw.sys.id,
|
615 | query: createRequestConfig({
|
616 | query: query
|
617 | }).params
|
618 | }
|
619 | }).then(function (data) {
|
620 | return wrapUserCollection(makeRequest, data);
|
621 | });
|
622 | },
|
623 |
|
624 | /**
|
625 | * Gets a collection of teams for a space
|
626 | * @param query
|
627 | * @return Promise for a collection of teams for a space
|
628 | * @example ```javascript
|
629 | * const contentful = require('contentful-management')
|
630 | *
|
631 | * client.getSpace('<space_id>')
|
632 | * .then((space) => space.getTeams())
|
633 | * .then((teamsCollection) => console.log(teamsCollection))
|
634 | * .catch(console.error)
|
635 | * ```
|
636 | */
|
637 | getTeams: function getTeams() {
|
638 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
|
639 | limit: 100
|
640 | };
|
641 | var raw = this.toPlainObject();
|
642 | return makeRequest({
|
643 | entityType: 'Team',
|
644 | action: 'getManyForSpace',
|
645 | params: {
|
646 | spaceId: raw.sys.id,
|
647 | query: createRequestConfig({
|
648 | query: query
|
649 | }).params
|
650 | }
|
651 | }).then(function (data) {
|
652 | return wrapTeamCollection(makeRequest, data);
|
653 | });
|
654 | },
|
655 |
|
656 | /**
|
657 | * Gets a Space Member
|
658 | * @param id Get Space Member by user_id
|
659 | * @return Promise for a Space Member
|
660 | * @example ```javascript
|
661 | * const contentful = require('contentful-management')
|
662 | *
|
663 | * client.getSpace('<space_id>')
|
664 | * .then((space) => space.getSpaceMember(id))
|
665 | * .then((spaceMember) => console.log(spaceMember))
|
666 | * .catch(console.error)
|
667 | * ```
|
668 | */
|
669 | getSpaceMember: function getSpaceMember(id) {
|
670 | var raw = this.toPlainObject();
|
671 | return makeRequest({
|
672 | entityType: 'SpaceMember',
|
673 | action: 'get',
|
674 | params: {
|
675 | spaceId: raw.sys.id,
|
676 | spaceMemberId: id
|
677 | }
|
678 | }).then(function (data) {
|
679 | return wrapSpaceMember(makeRequest, data);
|
680 | });
|
681 | },
|
682 |
|
683 | /**
|
684 | * Gets a collection of Space Members
|
685 | * @param query
|
686 | * @return Promise for a collection of Space Members
|
687 | * @example ```javascript
|
688 | * const contentful = require('contentful-management')
|
689 | *
|
690 | * client.getSpace('<space_id>')
|
691 | * .then((space) => space.getSpaceMembers({'limit': 100}))
|
692 | * .then((spaceMemberCollection) => console.log(spaceMemberCollection))
|
693 | * .catch(console.error)
|
694 | * ```
|
695 | */
|
696 | getSpaceMembers: function getSpaceMembers() {
|
697 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
698 | var raw = this.toPlainObject();
|
699 | return makeRequest({
|
700 | entityType: 'SpaceMember',
|
701 | action: 'getMany',
|
702 | params: {
|
703 | spaceId: raw.sys.id,
|
704 | query: createRequestConfig({
|
705 | query: query
|
706 | }).params
|
707 | }
|
708 | }).then(function (data) {
|
709 | return wrapSpaceMemberCollection(makeRequest, data);
|
710 | });
|
711 | },
|
712 |
|
713 | /**
|
714 | * Gets a Space Membership
|
715 | * Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user).
|
716 | * @param id - Space Membership ID
|
717 | * @return Promise for a Space Membership
|
718 | * @example ```javascript
|
719 | * const contentful = require('contentful-management')
|
720 | *
|
721 | * client.getSpace('<space_id>')
|
722 | * .then((space) => space.getSpaceMembership('id'))
|
723 | * .then((spaceMembership) => console.log(spaceMembership))
|
724 | * .catch(console.error)
|
725 | * ```
|
726 | */
|
727 | getSpaceMembership: function getSpaceMembership(id) {
|
728 | var raw = this.toPlainObject();
|
729 | return makeRequest({
|
730 | entityType: 'SpaceMembership',
|
731 | action: 'get',
|
732 | params: {
|
733 | spaceId: raw.sys.id,
|
734 | spaceMembershipId: id
|
735 | }
|
736 | }).then(function (data) {
|
737 | return wrapSpaceMembership(makeRequest, data);
|
738 | });
|
739 | },
|
740 |
|
741 | /**
|
742 | * Gets a collection of Space Memberships
|
743 | * Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user).
|
744 | * @param query - Object with search parameters. Check the <a href="https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/#retrieving-entries-with-search-parameters">JS SDK tutorial</a> and the <a href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters">REST API reference</a> for more details.
|
745 | * @return Promise for a collection of Space Memberships
|
746 | * @example ```javascript
|
747 | * const contentful = require('contentful-management')
|
748 | *
|
749 | * client.getSpace('<space_id>')
|
750 | * .then((space) => space.getSpaceMemberships({'limit': 100})) // you can add more queries as 'key': 'value'
|
751 | * .then((response) => console.log(response.items))
|
752 | * .catch(console.error)
|
753 | * ```
|
754 | */
|
755 | getSpaceMemberships: function getSpaceMemberships() {
|
756 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
757 | var raw = this.toPlainObject();
|
758 | return makeRequest({
|
759 | entityType: 'SpaceMembership',
|
760 | action: 'getMany',
|
761 | params: {
|
762 | spaceId: raw.sys.id,
|
763 | query: createRequestConfig({
|
764 | query: query
|
765 | }).params
|
766 | }
|
767 | }).then(function (data) {
|
768 | return wrapSpaceMembershipCollection(makeRequest, data);
|
769 | });
|
770 | },
|
771 |
|
772 | /**
|
773 | * Creates a Space Membership
|
774 | * Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user).
|
775 | * @param data - Object representation of the Space Membership to be created
|
776 | * @return Promise for the newly created Space Membership
|
777 | * @example ```javascript
|
778 | * const contentful = require('contentful-management')
|
779 | *
|
780 | * const client = contentful.createClient({
|
781 | * accessToken: '<content_management_api_key>'
|
782 | * })
|
783 | *
|
784 | * client.getSpace('<space_id>')
|
785 | * .then((space) => space.createSpaceMembership({
|
786 | * admin: false,
|
787 | * roles: [
|
788 | * {
|
789 | * type: 'Link',
|
790 | * linkType: 'Role',
|
791 | * id: '<role_id>'
|
792 | * }
|
793 | * ],
|
794 | * email: 'foo@example.com'
|
795 | * }))
|
796 | * .then((spaceMembership) => console.log(spaceMembership))
|
797 | * .catch(console.error)
|
798 | * ```
|
799 | */
|
800 | createSpaceMembership: function createSpaceMembership(data) {
|
801 | var raw = this.toPlainObject();
|
802 | return makeRequest({
|
803 | entityType: 'SpaceMembership',
|
804 | action: 'create',
|
805 | params: {
|
806 | spaceId: raw.sys.id
|
807 | },
|
808 | payload: data
|
809 | }).then(function (response) {
|
810 | return wrapSpaceMembership(makeRequest, response);
|
811 | });
|
812 | },
|
813 |
|
814 | /**
|
815 | * Creates a Space Membership with a custom ID
|
816 | * Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user).
|
817 | * @param id - Space Membership ID
|
818 | * @param data - Object representation of the Space Membership to be created
|
819 | * @return Promise for the newly created Space Membership
|
820 | * @example ```javascript
|
821 | * const contentful = require('contentful-management')
|
822 | *
|
823 | * const client = contentful.createClient({
|
824 | * accessToken: '<content_management_api_key>'
|
825 | * })
|
826 | *
|
827 | * client.getSpace('<space_id>')
|
828 | * .then((space) => space.createSpaceMembershipWithId('<space-membership-id>', {
|
829 | * admin: false,
|
830 | * roles: [
|
831 | * {
|
832 | * type: 'Link',
|
833 | * linkType: 'Role',
|
834 | * id: '<role_id>'
|
835 | * }
|
836 | * ],
|
837 | * email: 'foo@example.com'
|
838 | * }))
|
839 | * .then((spaceMembership) => console.log(spaceMembership))
|
840 | * .catch(console.error)
|
841 | * ```
|
842 | */
|
843 | createSpaceMembershipWithId: function createSpaceMembershipWithId(id, data) {
|
844 | var raw = this.toPlainObject();
|
845 | return makeRequest({
|
846 | entityType: 'SpaceMembership',
|
847 | action: 'createWithId',
|
848 | params: {
|
849 | spaceId: raw.sys.id,
|
850 | spaceMembershipId: id
|
851 | },
|
852 | payload: data
|
853 | }).then(function (response) {
|
854 | return wrapSpaceMembership(makeRequest, response);
|
855 | });
|
856 | },
|
857 |
|
858 | /**
|
859 | * Gets a Team Space Membership
|
860 | * @param id - Team Space Membership ID
|
861 | * @return Promise for a Team Space Membership
|
862 | * @example ```javascript
|
863 | * const contentful = require('contentful-management')
|
864 | *
|
865 | * client.getSpace('<space_id>')
|
866 | * .then((space) => space.getTeamSpaceMembership('team_space_membership_id'))
|
867 | * .then((teamSpaceMembership) => console.log(teamSpaceMembership))
|
868 | * .catch(console.error)
|
869 | * ```
|
870 | */
|
871 | getTeamSpaceMembership: function getTeamSpaceMembership(teamSpaceMembershipId) {
|
872 | var raw = this.toPlainObject();
|
873 | return makeRequest({
|
874 | entityType: 'TeamSpaceMembership',
|
875 | action: 'get',
|
876 | params: {
|
877 | spaceId: raw.sys.id,
|
878 | teamSpaceMembershipId: teamSpaceMembershipId
|
879 | }
|
880 | }).then(function (data) {
|
881 | return wrapTeamSpaceMembership(makeRequest, data);
|
882 | });
|
883 | },
|
884 |
|
885 | /**
|
886 | * Gets a collection of Team Space Memberships
|
887 | * @param query - Object with search parameters. Check the <a href="https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/#retrieving-entries-with-search-parameters">JS SDK tutorial</a> and the <a href="https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/search-parameters">REST API reference</a> for more details.
|
888 | * @return Promise for a collection of Team Space Memberships
|
889 | * @example ```javascript
|
890 | * const contentful = require('contentful-management')
|
891 | *
|
892 | * client.getSpace('<space_id>')
|
893 | * .then((space) => space.getTeamSpaceMemberships())
|
894 | * .then((response) => console.log(response.items))
|
895 | * .catch(console.error)
|
896 | * ```
|
897 | */
|
898 | getTeamSpaceMemberships: function getTeamSpaceMemberships() {
|
899 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
900 | var raw = this.toPlainObject();
|
901 | return makeRequest({
|
902 | entityType: 'TeamSpaceMembership',
|
903 | action: 'getMany',
|
904 | params: {
|
905 | spaceId: raw.sys.id,
|
906 | query: createRequestConfig({
|
907 | query: query
|
908 | }).params
|
909 | }
|
910 | }).then(function (data) {
|
911 | return wrapTeamSpaceMembershipCollection(makeRequest, data);
|
912 | });
|
913 | },
|
914 |
|
915 | /**
|
916 | * Creates a Team Space Membership
|
917 | * @param id - Team ID
|
918 | * @param data - Object representation of the Team Space Membership to be created
|
919 | * @return Promise for the newly created Team Space Membership
|
920 | * @example ```javascript
|
921 | * const contentful = require('contentful-management')
|
922 | *
|
923 | * const client = contentful.createClient({
|
924 | * accessToken: '<content_management_api_key>'
|
925 | * })
|
926 | *
|
927 | * client.getSpace('<space_id>')
|
928 | * .then((space) => space.createTeamSpaceMembership('team_id', {
|
929 | * admin: false,
|
930 | * roles: [
|
931 | * {
|
932 | sys: {
|
933 | * type: 'Link',
|
934 | * linkType: 'Role',
|
935 | * id: '<role_id>'
|
936 | * }
|
937 | * }
|
938 | * ],
|
939 | * }))
|
940 | * .then((teamSpaceMembership) => console.log(teamSpaceMembership))
|
941 | * .catch(console.error)
|
942 | * ```
|
943 | */
|
944 | createTeamSpaceMembership: function createTeamSpaceMembership(teamId, data) {
|
945 | var raw = this.toPlainObject();
|
946 | return makeRequest({
|
947 | entityType: 'TeamSpaceMembership',
|
948 | action: 'create',
|
949 | params: {
|
950 | spaceId: raw.sys.id,
|
951 | teamId: teamId
|
952 | },
|
953 | payload: data
|
954 | }).then(function (response) {
|
955 | return wrapTeamSpaceMembership(makeRequest, response);
|
956 | });
|
957 | },
|
958 |
|
959 | /**
|
960 | * Gets a Api Key
|
961 | * @param id - API Key ID
|
962 | * @return Promise for a Api Key
|
963 | * @example ```javascript
|
964 | * const contentful = require('contentful-management')
|
965 | *
|
966 | * const client = contentful.createClient({
|
967 | * accessToken: '<content_management_api_key>'
|
968 | * })
|
969 | *
|
970 | * client.getSpace('<space_id>')
|
971 | * .then((space) => space.getApiKey('<apikey-id>'))
|
972 | * .then((apikey) => console.log(apikey))
|
973 | * .catch(console.error)
|
974 | * ```
|
975 | */
|
976 | getApiKey: function getApiKey(id) {
|
977 | var raw = this.toPlainObject();
|
978 | return makeRequest({
|
979 | entityType: 'ApiKey',
|
980 | action: 'get',
|
981 | params: {
|
982 | spaceId: raw.sys.id,
|
983 | apiKeyId: id
|
984 | }
|
985 | }).then(function (data) {
|
986 | return wrapApiKey(makeRequest, data);
|
987 | });
|
988 | },
|
989 |
|
990 | /**
|
991 | * Gets a collection of Api Keys
|
992 | * @return Promise for a collection of Api Keys
|
993 | * @example ```javascript
|
994 | * const contentful = require('contentful-management')
|
995 | *
|
996 | * const client = contentful.createClient({
|
997 | * accessToken: '<content_management_api_key>'
|
998 | * })
|
999 | *
|
1000 | * client.getSpace('<space_id>')
|
1001 | * .then((space) => space.getApiKeys())
|
1002 | * .then((response) => console.log(response.items))
|
1003 | * .catch(console.error)
|
1004 | * ```
|
1005 | */
|
1006 | getApiKeys: function getApiKeys() {
|
1007 | var raw = this.toPlainObject();
|
1008 | return makeRequest({
|
1009 | entityType: 'ApiKey',
|
1010 | action: 'getMany',
|
1011 | params: {
|
1012 | spaceId: raw.sys.id
|
1013 | }
|
1014 | }).then(function (data) {
|
1015 | return wrapApiKeyCollection(makeRequest, data);
|
1016 | });
|
1017 | },
|
1018 |
|
1019 | /**
|
1020 | * Gets a collection of preview Api Keys
|
1021 | * @return Promise for a collection of Preview Api Keys
|
1022 | * @example ```javascript
|
1023 | * const contentful = require('contentful-management')
|
1024 | *
|
1025 | * const client = contentful.createClient({
|
1026 | * accessToken: '<content_management_api_key>'
|
1027 | * })
|
1028 | *
|
1029 | * client.getSpace('<space_id>')
|
1030 | * .then((space) => space.getPreviewApiKeys())
|
1031 | * .then((response) => console.log(response.items))
|
1032 | * .catch(console.error)
|
1033 | * ```
|
1034 | */
|
1035 | getPreviewApiKeys: function getPreviewApiKeys() {
|
1036 | var raw = this.toPlainObject();
|
1037 | return makeRequest({
|
1038 | entityType: 'PreviewApiKey',
|
1039 | action: 'getMany',
|
1040 | params: {
|
1041 | spaceId: raw.sys.id
|
1042 | }
|
1043 | }).then(function (data) {
|
1044 | return wrapPreviewApiKeyCollection(makeRequest, data);
|
1045 | });
|
1046 | },
|
1047 |
|
1048 | /**
|
1049 | * Gets a preview Api Key
|
1050 | * @param id - Preview API Key ID
|
1051 | * @return Promise for a Preview Api Key
|
1052 | * @example ```javascript
|
1053 | * const contentful = require('contentful-management')
|
1054 | *
|
1055 | * const client = contentful.createClient({
|
1056 | * accessToken: '<content_management_api_key>'
|
1057 | * })
|
1058 | *
|
1059 | * client.getSpace('<space_id>')
|
1060 | * .then((space) => space.getPreviewApiKey('<preview-apikey-id>'))
|
1061 | * .then((previewApikey) => console.log(previewApikey))
|
1062 | * .catch(console.error)
|
1063 | * ```
|
1064 | */
|
1065 | getPreviewApiKey: function getPreviewApiKey(id) {
|
1066 | var raw = this.toPlainObject();
|
1067 | return makeRequest({
|
1068 | entityType: 'PreviewApiKey',
|
1069 | action: 'get',
|
1070 | params: {
|
1071 | spaceId: raw.sys.id,
|
1072 | previewApiKeyId: id
|
1073 | }
|
1074 | }).then(function (data) {
|
1075 | return wrapPreviewApiKey(makeRequest, data);
|
1076 | });
|
1077 | },
|
1078 |
|
1079 | /**
|
1080 | * Creates a Api Key
|
1081 | * @param payload - Object representation of the Api Key to be created
|
1082 | * @return Promise for the newly created Api Key
|
1083 | * @example ```javascript
|
1084 | * const contentful = require('contentful-management')
|
1085 | *
|
1086 | * const client = contentful.createClient({
|
1087 | * accessToken: '<content_management_api_key>'
|
1088 | * })
|
1089 | *
|
1090 | * client.getSpace('<space_id>')
|
1091 | * .then((space) => space.createApiKey({
|
1092 | * name: 'API Key name',
|
1093 | * environments:[
|
1094 | * {
|
1095 | * sys: {
|
1096 | * type: 'Link'
|
1097 | * linkType: 'Environment',
|
1098 | * id:'<environment_id>'
|
1099 | * }
|
1100 | * }
|
1101 | * ]
|
1102 | * }
|
1103 | * }))
|
1104 | * .then((apiKey) => console.log(apiKey))
|
1105 | * .catch(console.error)
|
1106 | * ```
|
1107 | */
|
1108 | createApiKey: function createApiKey(payload) {
|
1109 | var raw = this.toPlainObject();
|
1110 | return makeRequest({
|
1111 | entityType: 'ApiKey',
|
1112 | action: 'create',
|
1113 | params: {
|
1114 | spaceId: raw.sys.id
|
1115 | },
|
1116 | payload: payload
|
1117 | }).then(function (data) {
|
1118 | return wrapApiKey(makeRequest, data);
|
1119 | });
|
1120 | },
|
1121 |
|
1122 | /**
|
1123 | * Creates a Api Key with a custom ID
|
1124 | * @param id - Api Key ID
|
1125 | * @param payload - Object representation of the Api Key to be created
|
1126 | * @return Promise for the newly created Api Key
|
1127 | * @example ```javascript
|
1128 | * const contentful = require('contentful-management')
|
1129 | *
|
1130 | * const client = contentful.createClient({
|
1131 | * accessToken: '<content_management_api_key>'
|
1132 | * })
|
1133 | *
|
1134 | * client.getSpace('<space_id>')
|
1135 | * .then((space) => space.createApiKeyWithId('<api-key-id>', {
|
1136 | * name: 'API Key name'
|
1137 | * environments:[
|
1138 | * {
|
1139 | * sys: {
|
1140 | * type: 'Link'
|
1141 | * linkType: 'Environment',
|
1142 | * id:'<environment_id>'
|
1143 | * }
|
1144 | * }
|
1145 | * ]
|
1146 | * }
|
1147 | * }))
|
1148 | * .then((apiKey) => console.log(apiKey))
|
1149 | * .catch(console.error)
|
1150 | * ```
|
1151 | */
|
1152 | createApiKeyWithId: function createApiKeyWithId(id, payload) {
|
1153 | var raw = this.toPlainObject();
|
1154 | return makeRequest({
|
1155 | entityType: 'ApiKey',
|
1156 | action: 'createWithId',
|
1157 | params: {
|
1158 | spaceId: raw.sys.id,
|
1159 | apiKeyId: id
|
1160 | },
|
1161 | payload: payload
|
1162 | }).then(function (data) {
|
1163 | return wrapApiKey(makeRequest, data);
|
1164 | });
|
1165 | },
|
1166 |
|
1167 | /**
|
1168 | * Creates an EnvironmentAlias with a custom ID
|
1169 | * @param environmentAliasId - EnvironmentAlias ID
|
1170 | * @param data - Object representation of the EnvironmentAlias to be created
|
1171 | * @return Promise for the newly created EnvironmentAlias
|
1172 | * @example ```javascript
|
1173 | * const contentful = require('contentful-management')
|
1174 | *
|
1175 | * const client = contentful.createClient({
|
1176 | * accessToken: '<content_management_api_key>'
|
1177 | * })
|
1178 | *
|
1179 | * client.getSpace('<space_id>')
|
1180 | * .then((space) => space.createEnvironmentAliasWithId('<environment-alias-id>', {
|
1181 | * environment: {
|
1182 | * sys: { type: 'Link', linkType: 'Environment', id: 'targetEnvironment' }
|
1183 | * }
|
1184 | * }))
|
1185 | * .then((environmentAlias) => console.log(environmentAlias))
|
1186 | * .catch(console.error)
|
1187 | * ```
|
1188 | */
|
1189 | createEnvironmentAliasWithId: function createEnvironmentAliasWithId(environmentAliasId, data) {
|
1190 | var raw = this.toPlainObject();
|
1191 | return makeRequest({
|
1192 | entityType: 'EnvironmentAlias',
|
1193 | action: 'createWithId',
|
1194 | params: {
|
1195 | spaceId: raw.sys.id,
|
1196 | environmentAliasId: environmentAliasId
|
1197 | },
|
1198 | payload: data
|
1199 | }).then(function (response) {
|
1200 | return wrapEnvironmentAlias(makeRequest, response);
|
1201 | });
|
1202 | },
|
1203 |
|
1204 | /**
|
1205 | * Gets an Environment Alias
|
1206 | * @param Environment Alias ID
|
1207 | * @return Promise for an Environment Alias
|
1208 | * @example ```javascript
|
1209 | * const contentful = require('contentful-management')
|
1210 | *
|
1211 | * const client = contentful.createClient({
|
1212 | * accessToken: '<content_management_api_key>'
|
1213 | * })
|
1214 | *
|
1215 | * client.getSpace('<space_id>')
|
1216 | * .then((space) => space.getEnvironmentAlias('<alias-id>'))
|
1217 | * .then((alias) => console.log(alias))
|
1218 | * .catch(console.error)
|
1219 | * ```
|
1220 | */
|
1221 | getEnvironmentAlias: function getEnvironmentAlias(environmentAliasId) {
|
1222 | var raw = this.toPlainObject();
|
1223 | return makeRequest({
|
1224 | entityType: 'EnvironmentAlias',
|
1225 | action: 'get',
|
1226 | params: {
|
1227 | spaceId: raw.sys.id,
|
1228 | environmentAliasId: environmentAliasId
|
1229 | }
|
1230 | }).then(function (data) {
|
1231 | return wrapEnvironmentAlias(makeRequest, data);
|
1232 | });
|
1233 | },
|
1234 |
|
1235 | /**
|
1236 | * Gets a collection of Environment Aliases
|
1237 | * @return Promise for a collection of Environment Aliases
|
1238 | * @example ```javascript
|
1239 | * const contentful = require('contentful-management')
|
1240 | *
|
1241 | * const client = contentful.createClient({
|
1242 | * accessToken: '<content_management_api_key>'
|
1243 | * })
|
1244 | *
|
1245 | * client.getSpace('<space_id>')
|
1246 | * .then((space) => space.getEnvironmentAliases()
|
1247 | * .then((response) => console.log(response.items))
|
1248 | * .catch(console.error)
|
1249 | * ```
|
1250 | */
|
1251 | getEnvironmentAliases: function getEnvironmentAliases() {
|
1252 | var raw = this.toPlainObject();
|
1253 | return makeRequest({
|
1254 | entityType: 'EnvironmentAlias',
|
1255 | action: 'getMany',
|
1256 | params: {
|
1257 | spaceId: raw.sys.id
|
1258 | }
|
1259 | }).then(function (data) {
|
1260 | return wrapEnvironmentAliasCollection(makeRequest, data);
|
1261 | });
|
1262 | },
|
1263 |
|
1264 | /**
|
1265 | * Query for scheduled actions in space.
|
1266 | * @param query - Object with search parameters. The enviroment id field is mandatory. Check the <a href="https://www.contentful.com/developers/docs/references/content-management-api/#/reference/scheduled-actions/scheduled-actions-collection">REST API reference</a> for more details.
|
1267 | * @return Promise for the scheduled actions query
|
1268 | *
|
1269 | * @example ```javascript
|
1270 | * const contentful = require('contentful-management');
|
1271 | *
|
1272 | * const client = contentful.createClient({
|
1273 | * accessToken: '<content_management_api_key>'
|
1274 | * })
|
1275 | *
|
1276 | * client.getSpace('<space_id>')
|
1277 | * .then((space) => space.getScheduledActions({
|
1278 | * 'environment.sys.id': '<environment_id>',
|
1279 | * 'sys.status': 'scheduled'
|
1280 | * }))
|
1281 | * .then((scheduledActionCollection) => console.log(scheduledActionCollection.items))
|
1282 | * .catch(console.error)
|
1283 | * ```
|
1284 | */
|
1285 | getScheduledActions: function getScheduledActions(query) {
|
1286 | var raw = this.toPlainObject();
|
1287 | return makeRequest({
|
1288 | entityType: 'ScheduledAction',
|
1289 | action: 'getMany',
|
1290 | params: {
|
1291 | spaceId: raw.sys.id,
|
1292 | query: query
|
1293 | }
|
1294 | }).then(function (response) {
|
1295 | return wrapScheduledActionCollection(makeRequest, response);
|
1296 | });
|
1297 | },
|
1298 |
|
1299 | /**
|
1300 | * Get a Scheduled Action in the current space by environment and ID.
|
1301 | *
|
1302 | * @throws if the Scheduled Action cannot be found or the user doesn't have permission to read schedules from the entity of the scheduled action itself.
|
1303 | * @returns Promise with the Scheduled Action
|
1304 | * @example ```javascript
|
1305 | * const contentful = require('contentful-management');
|
1306 | *
|
1307 | * const client = contentful.createClient({
|
1308 | * accessToken: '<content_management_api_key>'
|
1309 | * })
|
1310 | *
|
1311 | * client.getSpace('<space_id>')
|
1312 | * .then((space) => space.getScheduledAction({
|
1313 | * scheduledActionId: '<scheduled-action-id>',
|
1314 | * environmentId: '<environmentId>'
|
1315 | * }))
|
1316 | * .then((scheduledAction) => console.log(scheduledAction))
|
1317 | * .catch(console.error)
|
1318 | * ```
|
1319 | */
|
1320 | getScheduledAction: function getScheduledAction(_ref) {
|
1321 | var scheduledActionId = _ref.scheduledActionId,
|
1322 | environmentId = _ref.environmentId;
|
1323 | var space = this.toPlainObject();
|
1324 | return makeRequest({
|
1325 | entityType: 'ScheduledAction',
|
1326 | action: 'get',
|
1327 | params: {
|
1328 | spaceId: space.sys.id,
|
1329 | environmentId: environmentId,
|
1330 | scheduledActionId: scheduledActionId
|
1331 | }
|
1332 | }).then(function (scheduledAction) {
|
1333 | return wrapScheduledAction(makeRequest, scheduledAction);
|
1334 | });
|
1335 | },
|
1336 |
|
1337 | /**
|
1338 | * Creates a scheduled action
|
1339 | * @param data - Object representation of the scheduled action to be created
|
1340 | * @return Promise for the newly created scheduled actions
|
1341 | * @example ```javascript
|
1342 | * const contentful = require('contentful-management');
|
1343 | *
|
1344 | * const client = contentful.createClient({
|
1345 | * accessToken: '<content_management_api_key>'
|
1346 | * })
|
1347 | *
|
1348 | * client.getSpace('<space_id>')
|
1349 | * .then((space) => space.createScheduledAction({
|
1350 | * entity: {
|
1351 | * sys: {
|
1352 | * type: 'Link',
|
1353 | * linkType: 'Entry',
|
1354 | * id: '<entry_id>'
|
1355 | * }
|
1356 | * },
|
1357 | * environment: {
|
1358 | * sys: {
|
1359 | * type: 'Link',
|
1360 | * linkType: 'Environment',
|
1361 | * id: '<environment_id>'
|
1362 | * }
|
1363 | * },
|
1364 | * action: 'publish',
|
1365 | * scheduledFor: {
|
1366 | * datetime: <ISO_date_string>,
|
1367 | * timezone: 'Europe/Berlin'
|
1368 | * }
|
1369 | * }))
|
1370 | * .then((scheduledAction) => console.log(scheduledAction))
|
1371 | * .catch(console.error)
|
1372 | * ```
|
1373 | */
|
1374 | createScheduledAction: function createScheduledAction(data) {
|
1375 | var raw = this.toPlainObject();
|
1376 | return makeRequest({
|
1377 | entityType: 'ScheduledAction',
|
1378 | action: 'create',
|
1379 | params: {
|
1380 | spaceId: raw.sys.id
|
1381 | },
|
1382 | payload: data
|
1383 | }).then(function (response) {
|
1384 | return wrapScheduledAction(makeRequest, response);
|
1385 | });
|
1386 | },
|
1387 |
|
1388 | /**
|
1389 | * Update a scheduled action
|
1390 | * @param {object} options
|
1391 | * @param options.scheduledActionId the id of the scheduled action to update
|
1392 | * @param options.version the sys.version of the scheduled action to be updated
|
1393 | * @param payload the scheduled actions object with updates, omitting sys object
|
1394 | * @returns Promise containing a wrapped scheduled action with helper methods
|
1395 | * @example ```javascript
|
1396 | * const contentful = require('contentful-management');
|
1397 | *
|
1398 | * const client = contentful.createClient({
|
1399 | * accessToken: '<content_management_api_key>'
|
1400 | * })
|
1401 | *
|
1402 | * client.getSpace('<space_id>')
|
1403 | * .then((space) => {
|
1404 | * return space.createScheduledAction({
|
1405 | * entity: {
|
1406 | * sys: {
|
1407 | * type: 'Link',
|
1408 | * linkType: 'Entry',
|
1409 | * id: '<entry_id>'
|
1410 | * }
|
1411 | * },
|
1412 | * environment: {
|
1413 | * sys: {
|
1414 | * type: 'Link',
|
1415 | * linkType: 'Environment',
|
1416 | * id: '<environment_id>'
|
1417 | * }
|
1418 | * },
|
1419 | * action: 'publish',
|
1420 | * scheduledFor: {
|
1421 | * datetime: <ISO_date_string>,
|
1422 | * timezone: 'Europe/Berlin'
|
1423 | * }
|
1424 | * })
|
1425 | * .then((scheduledAction) => {
|
1426 | * const { _sys, ...payload } = scheduledAction;
|
1427 | * return space.updateScheduledAction({
|
1428 | * ...payload,
|
1429 | * scheduledFor: {
|
1430 | * ...payload.scheduledFor,
|
1431 | * timezone: 'Europe/Paris'
|
1432 | * }
|
1433 | * })
|
1434 | * })
|
1435 | * .then((scheduledAction) => console.log(scheduledAction))
|
1436 | * .catch(console.error);
|
1437 | * ```
|
1438 | */
|
1439 | updateScheduledAction: function updateScheduledAction(_ref2) {
|
1440 | var scheduledActionId = _ref2.scheduledActionId,
|
1441 | payload = _ref2.payload,
|
1442 | version = _ref2.version;
|
1443 | var spaceProps = this.toPlainObject();
|
1444 | return makeRequest({
|
1445 | entityType: 'ScheduledAction',
|
1446 | action: 'update',
|
1447 | params: {
|
1448 | spaceId: spaceProps.sys.id,
|
1449 | version: version,
|
1450 | scheduledActionId: scheduledActionId
|
1451 | },
|
1452 | payload: payload
|
1453 | }).then(function (response) {
|
1454 | return wrapScheduledAction(makeRequest, response);
|
1455 | });
|
1456 | },
|
1457 |
|
1458 | /**
|
1459 | * Cancels a Scheduled Action.
|
1460 | * Only cancels actions that have not yet executed.
|
1461 | *
|
1462 | * @param {object} options
|
1463 | * @param options.scheduledActionId the id of the scheduled action to be canceled
|
1464 | * @param options.environmentId the environment ID of the scheduled action to be canceled
|
1465 | * @throws if the Scheduled Action cannot be found or the user doesn't have permissions in the entity in the action.
|
1466 | * @returns Promise containing a wrapped Scheduled Action with helper methods
|
1467 | * @example ```javascript
|
1468 | * const contentful = require('contentful-management');
|
1469 | *
|
1470 | * const client = contentful.createClient({
|
1471 | * accessToken: '<content_management_api_key>'
|
1472 | * })
|
1473 | *
|
1474 | * // Given that an Scheduled Action is scheduled
|
1475 | * client.getSpace('<space_id>')
|
1476 | * .then((space) => space.deleteScheduledAction({
|
1477 | * environmentId: '<environment-id>',
|
1478 | * scheduledActionId: '<scheduled-action-id>'
|
1479 | * }))
|
1480 | * // The scheduled Action sys.status is now 'canceled'
|
1481 | * .then((scheduledAction) => console.log(scheduledAction))
|
1482 | * .catch(console.error);
|
1483 | * ```
|
1484 | */
|
1485 | deleteScheduledAction: function deleteScheduledAction(_ref3) {
|
1486 | var scheduledActionId = _ref3.scheduledActionId,
|
1487 | environmentId = _ref3.environmentId;
|
1488 | var spaceProps = this.toPlainObject();
|
1489 | return makeRequest({
|
1490 | entityType: 'ScheduledAction',
|
1491 | action: 'delete',
|
1492 | params: {
|
1493 | spaceId: spaceProps.sys.id,
|
1494 | environmentId: environmentId,
|
1495 | scheduledActionId: scheduledActionId
|
1496 | }
|
1497 | }).then(function (response) {
|
1498 | return wrapScheduledAction(makeRequest, response);
|
1499 | });
|
1500 | }
|
1501 | };
|
1502 | } |
\ | No newline at end of file |