1 | import { createRequestConfig } from 'contentful-sdk-core';
|
2 | import entities from './entities';
|
3 |
|
4 | /**
|
5 | * Creates API object with methods to access the Organization API
|
6 | * @param {MakeRequest} makeRequest - function to make requests via an adapter
|
7 | * @return {ContentfulOrganizationAPI}
|
8 | * @private
|
9 | */
|
10 | export default function createOrganizationApi(makeRequest) {
|
11 | var _entities$appDefiniti = entities.appDefinition,
|
12 | wrapAppDefinition = _entities$appDefiniti.wrapAppDefinition,
|
13 | wrapAppDefinitionCollection = _entities$appDefiniti.wrapAppDefinitionCollection;
|
14 | var _entities$user = entities.user,
|
15 | wrapUser = _entities$user.wrapUser,
|
16 | wrapUserCollection = _entities$user.wrapUserCollection;
|
17 | var _entities$organizatio = entities.organizationMembership,
|
18 | wrapOrganizationMembership = _entities$organizatio.wrapOrganizationMembership,
|
19 | wrapOrganizationMembershipCollection = _entities$organizatio.wrapOrganizationMembershipCollection;
|
20 | var _entities$teamMembers = entities.teamMembership,
|
21 | wrapTeamMembership = _entities$teamMembers.wrapTeamMembership,
|
22 | wrapTeamMembershipCollection = _entities$teamMembers.wrapTeamMembershipCollection;
|
23 | var _entities$teamSpaceMe = entities.teamSpaceMembership,
|
24 | wrapTeamSpaceMembership = _entities$teamSpaceMe.wrapTeamSpaceMembership,
|
25 | wrapTeamSpaceMembershipCollection = _entities$teamSpaceMe.wrapTeamSpaceMembershipCollection;
|
26 | var _entities$team = entities.team,
|
27 | wrapTeam = _entities$team.wrapTeam,
|
28 | wrapTeamCollection = _entities$team.wrapTeamCollection;
|
29 | var _entities$spaceMember = entities.spaceMembership,
|
30 | wrapSpaceMembership = _entities$spaceMember.wrapSpaceMembership,
|
31 | wrapSpaceMembershipCollection = _entities$spaceMember.wrapSpaceMembershipCollection;
|
32 | var wrapOrganizationInvitation = entities.organizationInvitation.wrapOrganizationInvitation;
|
33 | var wrapAppUpload = entities.appUpload.wrapAppUpload;
|
34 | var wrapAppSigningSecret = entities.appSigningSecret.wrapAppSigningSecret;
|
35 | var wrapAppDetails = entities.appDetails.wrapAppDetails;
|
36 | return {
|
37 | /**
|
38 | * Gets a User
|
39 | * @return Promise for a User
|
40 | * @example ```javascript
|
41 | * const contentful = require('contentful-management')
|
42 | * const client = contentful.createClient({
|
43 | * accessToken: '<content_management_api_key>'
|
44 | * })
|
45 | *
|
46 | * client.getOrganization('<organization_id>')
|
47 | * .then((organization) => organization.getUser('id'))
|
48 | * .then((user) => console.log(user))
|
49 | * .catch(console.error)
|
50 | * ```
|
51 | */
|
52 | getUser: function getUser(id) {
|
53 | var raw = this.toPlainObject();
|
54 | return makeRequest({
|
55 | entityType: 'User',
|
56 | action: 'getForOrganization',
|
57 | params: {
|
58 | organizationId: raw.sys.id,
|
59 | userId: id
|
60 | }
|
61 | }).then(function (data) {
|
62 | return wrapUser(makeRequest, data);
|
63 | });
|
64 | },
|
65 |
|
66 | /**
|
67 | * Gets a collection of Users in organization
|
68 | * @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.
|
69 | * @return Promise a collection of Users in organization
|
70 | * @example ```javascript
|
71 | * const contentful = require('contentful-management')
|
72 | * const client = contentful.createClient({
|
73 | * accessToken: '<content_management_api_key>'
|
74 | * })
|
75 | *
|
76 | * client.getOrganization('<organization_id>')
|
77 | * .then((organization) => organization.getUsers())
|
78 | * .then((user) => console.log(user))
|
79 | * .catch(console.error)
|
80 | * ```
|
81 | */
|
82 | getUsers: function getUsers() {
|
83 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
84 | var raw = this.toPlainObject();
|
85 | return makeRequest({
|
86 | entityType: 'User',
|
87 | action: 'getManyForOrganization',
|
88 | params: {
|
89 | organizationId: raw.sys.id,
|
90 | query: createRequestConfig({
|
91 | query: query
|
92 | }).params
|
93 | }
|
94 | }).then(function (data) {
|
95 | return wrapUserCollection(makeRequest, data);
|
96 | });
|
97 | },
|
98 |
|
99 | /**
|
100 | * Gets an Organization Membership
|
101 | * @param id - Organization Membership ID
|
102 | * @return Promise for an Organization Membership
|
103 | * @example ```javascript
|
104 | * const contentful = require('contentful-management')
|
105 | * const client = contentful.createClient({
|
106 | * accessToken: '<content_management_api_key>'
|
107 | * })
|
108 | *
|
109 | * client.getOrganization('organization_id')
|
110 | * .then((organization) => organization.getOrganizationMembership('organizationMembership_id'))
|
111 | * .then((organizationMembership) => console.log(organizationMembership))
|
112 | * .catch(console.error)
|
113 | * ```
|
114 | */
|
115 | getOrganizationMembership: function getOrganizationMembership(id) {
|
116 | var raw = this.toPlainObject();
|
117 | var organizationId = raw.sys.id;
|
118 | return makeRequest({
|
119 | entityType: 'OrganizationMembership',
|
120 | action: 'get',
|
121 | params: {
|
122 | organizationId: organizationId,
|
123 | organizationMembershipId: id
|
124 | }
|
125 | }).then(function (data) {
|
126 | return wrapOrganizationMembership(makeRequest, data, organizationId);
|
127 | });
|
128 | },
|
129 |
|
130 | /**
|
131 | * Gets a collection of Organization Memberships
|
132 | * @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.
|
133 | * @return Promise for a collection of Organization Memberships
|
134 | * @example ```javascript
|
135 | * const contentful = require('contentful-management')
|
136 | * const client = contentful.createClient({
|
137 | * accessToken: '<content_management_api_key>'
|
138 | * })
|
139 | *
|
140 | * client.getOrganization('organization_id')
|
141 | * .then((organization) => organization.getOrganizationMemberships({'limit': 100})) // you can add more queries as 'key': 'value'
|
142 | * .then((response) => console.log(response.items))
|
143 | * .catch(console.error)
|
144 | * ```
|
145 | */
|
146 | getOrganizationMemberships: function getOrganizationMemberships() {
|
147 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
148 | var raw = this.toPlainObject();
|
149 | var organizationId = raw.sys.id;
|
150 | return makeRequest({
|
151 | entityType: 'OrganizationMembership',
|
152 | action: 'getMany',
|
153 | params: {
|
154 | organizationId: organizationId,
|
155 | query: createRequestConfig({
|
156 | query: query
|
157 | }).params
|
158 | }
|
159 | }).then(function (data) {
|
160 | return wrapOrganizationMembershipCollection(makeRequest, data, organizationId);
|
161 | });
|
162 | },
|
163 |
|
164 | /**
|
165 | * Creates a Team
|
166 | * @param data representation of the Team to be created
|
167 | * @example ```javascript
|
168 | * const contentful = require('contentful-management')
|
169 | * const client = contentful.createClient({
|
170 | * accessToken: '<content_management_api_key>'
|
171 | * })
|
172 | *
|
173 | * client.getOrganization('<org_id>')
|
174 | * .then((org) => org.createTeam({
|
175 | * name: 'new team',
|
176 | * description: 'new team description'
|
177 | * }))
|
178 | * .then((team) => console.log(team))
|
179 | * .catch(console.error)
|
180 | * ```
|
181 | */
|
182 | createTeam: function createTeam(data) {
|
183 | var raw = this.toPlainObject();
|
184 | return makeRequest({
|
185 | entityType: 'Team',
|
186 | action: 'create',
|
187 | params: {
|
188 | organizationId: raw.sys.id
|
189 | },
|
190 | payload: data
|
191 | }).then(function (data) {
|
192 | return wrapTeam(makeRequest, data);
|
193 | });
|
194 | },
|
195 |
|
196 | /**
|
197 | * Gets an Team
|
198 | * @example ```javascript
|
199 | * const contentful = require('contentful-management')
|
200 | * const client = contentful.createClient({
|
201 | * accessToken: '<content_management_api_key>'
|
202 | * })
|
203 | *
|
204 | * client.getOrganization('orgId')
|
205 | * .then((organization) => organization.getTeam('teamId'))
|
206 | * .then((team) => console.log(team))
|
207 | * .catch(console.error)
|
208 | * ```
|
209 | */
|
210 | getTeam: function getTeam(teamId) {
|
211 | var raw = this.toPlainObject();
|
212 | return makeRequest({
|
213 | entityType: 'Team',
|
214 | action: 'get',
|
215 | params: {
|
216 | organizationId: raw.sys.id,
|
217 | teamId: teamId
|
218 | }
|
219 | }).then(function (data) {
|
220 | return wrapTeam(makeRequest, data);
|
221 | });
|
222 | },
|
223 |
|
224 | /**
|
225 | * Gets all Teams in an organization
|
226 | * @example ```javascript
|
227 | * const contentful = require('contentful-management')
|
228 | * const client = contentful.createClient({
|
229 | * accessToken: '<content_management_api_key>'
|
230 | * })
|
231 | *
|
232 | * client.getOrganization('orgId')
|
233 | * .then((organization) => organization.getTeams())
|
234 | * .then((teams) => console.log(teams))
|
235 | * .catch(console.error)
|
236 | * ```
|
237 | */
|
238 | getTeams: function getTeams() {
|
239 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
240 | var raw = this.toPlainObject();
|
241 | return makeRequest({
|
242 | entityType: 'Team',
|
243 | action: 'getMany',
|
244 | params: {
|
245 | organizationId: raw.sys.id,
|
246 | query: createRequestConfig({
|
247 | query: query
|
248 | }).params
|
249 | }
|
250 | }).then(function (data) {
|
251 | return wrapTeamCollection(makeRequest, data);
|
252 | });
|
253 | },
|
254 |
|
255 | /**
|
256 | * Creates a Team membership
|
257 | * @param teamId - Id of the team the membership will be created in
|
258 | * @param data - Object representation of the Team Membership to be created
|
259 | * @return Promise for the newly created TeamMembership
|
260 | * @example ```javascript
|
261 | * const contentful = require('contentful-management')
|
262 | * const client = contentful.createClient({
|
263 | * accessToken: '<content_management_api_key>'
|
264 | * })
|
265 | *
|
266 | * client.getOrganization('organizationId')
|
267 | * .then((org) => org.createTeamMembership('teamId', {
|
268 | * admin: true,
|
269 | * organizationMembershipId: 'organizationMembershipId'
|
270 | * }))
|
271 | * .then((teamMembership) => console.log(teamMembership))
|
272 | * .catch(console.error)
|
273 | * ```
|
274 | */
|
275 | createTeamMembership: function createTeamMembership(teamId, data) {
|
276 | var raw = this.toPlainObject();
|
277 | return makeRequest({
|
278 | entityType: 'TeamMembership',
|
279 | action: 'create',
|
280 | params: {
|
281 | organizationId: raw.sys.id,
|
282 | teamId: teamId
|
283 | },
|
284 | payload: data
|
285 | }).then(function (data) {
|
286 | return wrapTeamMembership(makeRequest, data);
|
287 | });
|
288 | },
|
289 |
|
290 | /**
|
291 | * Gets an Team Membership from the team with given teamId
|
292 | * @return Promise for an Team Membership
|
293 | * @example ```javascript
|
294 | * const contentful = require('contentful-management')
|
295 | * const client = contentful.createClient({
|
296 | * accessToken: '<content_management_api_key>'
|
297 | * })
|
298 | *
|
299 | * client.getOrganization('organizationId')
|
300 | * .then((organization) => organization.getTeamMembership('teamId', 'teamMembership_id'))
|
301 | * .then((teamMembership) => console.log(teamMembership))
|
302 | * .catch(console.error)
|
303 | * ```
|
304 | */
|
305 | getTeamMembership: function getTeamMembership(teamId, teamMembershipId) {
|
306 | var raw = this.toPlainObject();
|
307 | return makeRequest({
|
308 | entityType: 'TeamMembership',
|
309 | action: 'get',
|
310 | params: {
|
311 | organizationId: raw.sys.id,
|
312 | teamId: teamId,
|
313 | teamMembershipId: teamMembershipId
|
314 | }
|
315 | }).then(function (data) {
|
316 | return wrapTeamMembership(makeRequest, data);
|
317 | });
|
318 | },
|
319 |
|
320 | /**
|
321 | * Get all Team Memberships. If teamID is provided in the optional config object, it will return all Team Memberships in that team. By default, returns all team memberships for the organization.
|
322 | * @return Promise for a Team Membership Collection
|
323 | * @example ```javascript
|
324 | * const contentful = require('contentful-management')
|
325 | * const client = contentful.createClient({
|
326 | * accessToken: '<content_management_api_key>'
|
327 | * })
|
328 | *
|
329 | * client.getOrganization('organizationId')
|
330 | * .then((organization) => organization.getTeamMemberships('teamId'))
|
331 | * .then((teamMemberships) => console.log(teamMemberships))
|
332 | * .catch(console.error)
|
333 | * ```
|
334 | */
|
335 | getTeamMemberships: function getTeamMemberships() {
|
336 | var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
337 | var teamId = opts.teamId,
|
338 | _opts$query = opts.query,
|
339 | query = _opts$query === void 0 ? {} : _opts$query;
|
340 | var raw = this.toPlainObject();
|
341 |
|
342 | if (teamId) {
|
343 | return makeRequest({
|
344 | entityType: 'TeamMembership',
|
345 | action: 'getManyForTeam',
|
346 | params: {
|
347 | organizationId: raw.sys.id,
|
348 | teamId: teamId,
|
349 | query: createRequestConfig({
|
350 | query: query
|
351 | }).params
|
352 | }
|
353 | }).then(function (data) {
|
354 | return wrapTeamMembershipCollection(makeRequest, data);
|
355 | });
|
356 | }
|
357 |
|
358 | return makeRequest({
|
359 | entityType: 'TeamMembership',
|
360 | action: 'getManyForOrganization',
|
361 | params: {
|
362 | organizationId: raw.sys.id,
|
363 | query: createRequestConfig({
|
364 | query: query
|
365 | }).params
|
366 | }
|
367 | }).then(function (data) {
|
368 | return wrapTeamMembershipCollection(makeRequest, data);
|
369 | });
|
370 | },
|
371 |
|
372 | /**
|
373 | * Get all Team Space Memberships. If teamID is provided in the optional config object, it will return all Team Space Memberships in that team. By default, returns all team space memberships across all teams in the organization.
|
374 | * @return Promise for a Team Space Membership Collection
|
375 | * @example ```javascript
|
376 | * const contentful = require('contentful-management')
|
377 | * const client = contentful.createClient({
|
378 | * accessToken: '<content_management_api_key>'
|
379 | * })
|
380 | *
|
381 | * client.getOrganization('organizationId')
|
382 | * .then((organization) => organization.getTeamSpaceMemberships('teamId'))
|
383 | * .then((teamSpaceMemberships) => console.log(teamSpaceMemberships))
|
384 | * .catch(console.error)
|
385 | * ```
|
386 | */
|
387 | getTeamSpaceMemberships: function getTeamSpaceMemberships() {
|
388 | var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
389 | var raw = this.toPlainObject();
|
390 | return makeRequest({
|
391 | entityType: 'TeamSpaceMembership',
|
392 | action: 'getManyForOrganization',
|
393 | params: {
|
394 | organizationId: raw.sys.id,
|
395 | query: createRequestConfig({
|
396 | query: opts.query || {}
|
397 | }).params,
|
398 | teamId: opts.teamId
|
399 | }
|
400 | }).then(function (data) {
|
401 | return wrapTeamSpaceMembershipCollection(makeRequest, data);
|
402 | });
|
403 | },
|
404 |
|
405 | /**
|
406 | * Get a Team Space Membership with given teamSpaceMembershipId
|
407 | * @return Promise for a Team Space Membership
|
408 | * @example ```javascript
|
409 | * const contentful = require('contentful-management')
|
410 | * const client = contentful.createClient({
|
411 | * accessToken: '<content_management_api_key>'
|
412 | * })
|
413 | *
|
414 | * client.getOrganization('organizationId')
|
415 | * .then((organization) => organization.getTeamSpaceMembership('teamSpaceMembershipId'))
|
416 | * .then((teamSpaceMembership) => console.log(teamSpaceMembership))
|
417 | * .catch(console.error)]
|
418 | * ```
|
419 | */
|
420 | getTeamSpaceMembership: function getTeamSpaceMembership(teamSpaceMembershipId) {
|
421 | var raw = this.toPlainObject();
|
422 | return makeRequest({
|
423 | entityType: 'TeamSpaceMembership',
|
424 | action: 'getForOrganization',
|
425 | params: {
|
426 | organizationId: raw.sys.id,
|
427 | teamSpaceMembershipId: teamSpaceMembershipId
|
428 | }
|
429 | }).then(function (data) {
|
430 | return wrapTeamSpaceMembership(makeRequest, data);
|
431 | });
|
432 | },
|
433 |
|
434 | /**
|
435 | * Gets an Space Membership in Organization
|
436 | * @param id - Organiztion Space Membership ID
|
437 | * @return Promise for a Space Membership in an organization
|
438 | * @example ```javascript
|
439 | * const contentful = require('contentful-management')
|
440 | * const client = contentful.createClient({
|
441 | * accessToken: '<content_management_api_key>'
|
442 | * })
|
443 | *
|
444 | * client.getOrganization('organization_id')
|
445 | * .then((organization) => organization.getOrganizationSpaceMembership('organizationSpaceMembership_id'))
|
446 | * .then((organizationMembership) => console.log(organizationMembership))
|
447 | * .catch(console.error)
|
448 | * ```
|
449 | */
|
450 | getOrganizationSpaceMembership: function getOrganizationSpaceMembership(id) {
|
451 | var raw = this.toPlainObject();
|
452 | return makeRequest({
|
453 | entityType: 'SpaceMembership',
|
454 | action: 'getForOrganization',
|
455 | params: {
|
456 | organizationId: raw.sys.id,
|
457 | spaceMembershipId: id
|
458 | }
|
459 | }).then(function (data) {
|
460 | return wrapSpaceMembership(makeRequest, data);
|
461 | });
|
462 | },
|
463 |
|
464 | /**
|
465 | * Gets a collection Space Memberships in organization
|
466 | * @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.
|
467 | * @return Promise for a Space Membership collection across all spaces in the organization
|
468 | * @example ```javascript
|
469 | * const contentful = require('contentful-management')
|
470 | * const client = contentful.createClient({
|
471 | * accessToken: '<content_management_api_key>'
|
472 | * })
|
473 | *
|
474 | * client.getOrganization('organization_id')
|
475 | * .then((organization) => organization.getOrganizationSpaceMemberships()) // you can add queries like 'limit': 100
|
476 | * .then((response) => console.log(response.items))
|
477 | * .catch(console.error)
|
478 | * ```
|
479 | */
|
480 | getOrganizationSpaceMemberships: function getOrganizationSpaceMemberships() {
|
481 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
482 | var raw = this.toPlainObject();
|
483 | return makeRequest({
|
484 | entityType: 'SpaceMembership',
|
485 | action: 'getManyForOrganization',
|
486 | params: {
|
487 | organizationId: raw.sys.id,
|
488 | query: createRequestConfig({
|
489 | query: query
|
490 | }).params
|
491 | }
|
492 | }).then(function (data) {
|
493 | return wrapSpaceMembershipCollection(makeRequest, data);
|
494 | });
|
495 | },
|
496 |
|
497 | /**
|
498 | * Gets an Invitation in Organization
|
499 | * @return Promise for a OrganizationInvitation in an organization
|
500 | * @example ```javascript
|
501 | * const contentful = require('contentful-management')
|
502 | * const client = contentful.createClient({
|
503 | * accessToken: '<content_management_api_key>'
|
504 | * })
|
505 | *
|
506 | * client.getOrganization('<org_id>')
|
507 | * .then((organization) => organization.getOrganizationInvitation('invitation_id'))
|
508 | * .then((invitation) => console.log(invitation))
|
509 | * .catch(console.error)
|
510 | * ```
|
511 | */
|
512 | getOrganizationInvitation: function getOrganizationInvitation(invitationId) {
|
513 | var raw = this.toPlainObject();
|
514 | return makeRequest({
|
515 | entityType: 'OrganizationInvitation',
|
516 | action: 'get',
|
517 | params: {
|
518 | organizationId: raw.sys.id,
|
519 | invitationId: invitationId
|
520 | }
|
521 | }).then(function (data) {
|
522 | return wrapOrganizationInvitation(makeRequest, data);
|
523 | });
|
524 | },
|
525 |
|
526 | /**
|
527 | * Create an Invitation in Organization
|
528 | * @return Promise for a OrganizationInvitation in an organization
|
529 | * @example ```javascript
|
530 | * const contentful = require('contentful-management')
|
531 | * const client = contentful.createClient({
|
532 | * accessToken: '<content_management_api_key>'
|
533 | * })
|
534 | *
|
535 | * client.getOrganization('<org_id>')
|
536 | * .then((organization) => organization.createOrganizationInvitation({
|
537 | * email: 'user.email@example.com'
|
538 | * firstName: 'User First Name'
|
539 | * lastName: 'User Last Name'
|
540 | * role: 'developer'
|
541 | * })
|
542 | * .catch(console.error)
|
543 | * ```
|
544 | */
|
545 | createOrganizationInvitation: function createOrganizationInvitation(data) {
|
546 | var raw = this.toPlainObject();
|
547 | return makeRequest({
|
548 | entityType: 'OrganizationInvitation',
|
549 | action: 'create',
|
550 | params: {
|
551 | organizationId: raw.sys.id
|
552 | },
|
553 | payload: data
|
554 | }).then(function (data) {
|
555 | return wrapOrganizationInvitation(makeRequest, data);
|
556 | });
|
557 | },
|
558 |
|
559 | /**
|
560 | * Creates an app definition
|
561 | * @param Object representation of the App Definition to be created
|
562 | * @return Promise for the newly created AppDefinition
|
563 | * @example ```javascript
|
564 | * const contentful = require('contentful-management')
|
565 | * const client = contentful.createClient({
|
566 | * accessToken: '<content_management_api_key>'
|
567 | * })
|
568 | *
|
569 | * client.getOrganization('<org_id>')
|
570 | * .then((org) => org.createAppDefinition({
|
571 | * name: 'Example app',
|
572 | * locations: [{ location: 'app-config' }],
|
573 | * src: "http://my-app-host.com/my-app"
|
574 | * }))
|
575 | * .then((appDefinition) => console.log(appDefinition))
|
576 | * .catch(console.error)
|
577 | * ```
|
578 | */
|
579 | createAppDefinition: function createAppDefinition(data) {
|
580 | var raw = this.toPlainObject();
|
581 | return makeRequest({
|
582 | entityType: 'AppDefinition',
|
583 | action: 'create',
|
584 | params: {
|
585 | organizationId: raw.sys.id
|
586 | },
|
587 | payload: data
|
588 | }).then(function (data) {
|
589 | return wrapAppDefinition(makeRequest, data);
|
590 | });
|
591 | },
|
592 |
|
593 | /**
|
594 | * Gets all app definitions
|
595 | * @return Promise for a collection of App Definitions
|
596 | * @example ```javascript
|
597 | * const contentful = require('contentful-management')
|
598 | * const client = contentful.createClient({
|
599 | * accessToken: '<content_management_api_key>'
|
600 | * })
|
601 | *
|
602 | * client.getOrganization('<org_id>')
|
603 | * .then((org) => org.getAppDefinitions())
|
604 | * .then((response) => console.log(response.items))
|
605 | * .catch(console.error)
|
606 | * ```
|
607 | */
|
608 | getAppDefinitions: function getAppDefinitions() {
|
609 | var query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
610 | var raw = this.toPlainObject();
|
611 | return makeRequest({
|
612 | entityType: 'AppDefinition',
|
613 | action: 'getMany',
|
614 | params: {
|
615 | organizationId: raw.sys.id,
|
616 | query: query
|
617 | }
|
618 | }).then(function (data) {
|
619 | return wrapAppDefinitionCollection(makeRequest, data);
|
620 | });
|
621 | },
|
622 |
|
623 | /**
|
624 | * Gets an app definition
|
625 | * @return Promise for an App Definition
|
626 | * @example ```javascript
|
627 | * const contentful = require('contentful-management')
|
628 | * const client = contentful.createClient({
|
629 | * accessToken: '<content_management_api_key>'
|
630 | * })
|
631 | *
|
632 | * client.getOrganization('<org_id>')
|
633 | * .then((org) => org.getAppDefinition('<app_definition_id>'))
|
634 | * .then((appDefinition) => console.log(appDefinition))
|
635 | * .catch(console.error)
|
636 | * ```
|
637 | */
|
638 | getAppDefinition: function getAppDefinition(id) {
|
639 | var raw = this.toPlainObject();
|
640 | return makeRequest({
|
641 | entityType: 'AppDefinition',
|
642 | action: 'get',
|
643 | params: {
|
644 | organizationId: raw.sys.id,
|
645 | appDefinitionId: id
|
646 | }
|
647 | }).then(function (data) {
|
648 | return wrapAppDefinition(makeRequest, data);
|
649 | });
|
650 | },
|
651 |
|
652 | /**
|
653 | * Gets an app upload
|
654 | * @return Promise for an App Upload
|
655 | * @example ```javascript
|
656 | * const contentful = require('contentful-management')
|
657 | * const client = contentful.createClient({
|
658 | * accessToken: '<content_management_api_key>'
|
659 | * })
|
660 | *
|
661 | * client.getOrganization('<org_id>')
|
662 | * .then((org) => org.getAppUpload('<app_upload_id>'))
|
663 | * .then((appUpload) => console.log(appUpload))
|
664 | * .catch(console.error)
|
665 | * ```
|
666 | */
|
667 | getAppUpload: function getAppUpload(appUploadId) {
|
668 | var raw = this.toPlainObject();
|
669 | return makeRequest({
|
670 | entityType: 'AppUpload',
|
671 | action: 'get',
|
672 | params: {
|
673 | organizationId: raw.sys.id,
|
674 | appUploadId: appUploadId
|
675 | }
|
676 | }).then(function (data) {
|
677 | return wrapAppUpload(makeRequest, data);
|
678 | });
|
679 | },
|
680 |
|
681 | /**
|
682 | * Creates an app upload
|
683 | * @return Promise for an App Upload
|
684 | * @example ```javascript
|
685 | * const contentful = require('contentful-management')
|
686 | * const client = contentful.createClient({
|
687 | * accessToken: '<content_management_api_key>'
|
688 | * })
|
689 | *
|
690 | * client.getOrganization('<org_id>')
|
691 | * .then((org) => org.createAppUpload('some_zip_file'))
|
692 | * .then((appUpload) => console.log(appUpload))
|
693 | * .catch(console.error)
|
694 | * ```
|
695 | */
|
696 | createAppUpload: function createAppUpload(file) {
|
697 | var raw = this.toPlainObject();
|
698 | return makeRequest({
|
699 | entityType: 'AppUpload',
|
700 | action: 'create',
|
701 | params: {
|
702 | organizationId: raw.sys.id
|
703 | },
|
704 | payload: {
|
705 | file: file
|
706 | }
|
707 | }).then(function (data) {
|
708 | return wrapAppUpload(makeRequest, data);
|
709 | });
|
710 | },
|
711 |
|
712 | /**
|
713 | * Creates or updates an app signing secret
|
714 | * @return Promise for an App SigningSecret
|
715 | * @example ```javascript
|
716 | * const contentful = require('contentful-management')
|
717 | * const client = contentful.createClient({
|
718 | * accessToken: '<content_management_api_key>'
|
719 | * })
|
720 | *
|
721 | * client.getOrganization('<org_id>')
|
722 | * .then((org) => org.upsertAppSigningSecret('app_definition_id', { value: 'tsren3s1....wn1e' }))
|
723 | * .then((appSigningSecret) => console.log(appSigningSecret))
|
724 | * .catch(console.error)
|
725 | * ```
|
726 | */
|
727 | upsertAppSigningSecret: function upsertAppSigningSecret(appDefinitionId, data) {
|
728 | var raw = this.toPlainObject();
|
729 | return makeRequest({
|
730 | entityType: 'AppSigningSecret',
|
731 | action: 'upsert',
|
732 | params: {
|
733 | organizationId: raw.sys.id,
|
734 | appDefinitionId: appDefinitionId
|
735 | },
|
736 | payload: data
|
737 | }).then(function (payload) {
|
738 | return wrapAppSigningSecret(makeRequest, payload);
|
739 | });
|
740 | },
|
741 |
|
742 | /**
|
743 | * Gets an app signing secret
|
744 | * @return Promise for an App SigningSecret
|
745 | * @example ```javascript
|
746 | * const contentful = require('contentful-management')
|
747 | * const client = contentful.createClient({
|
748 | * accessToken: '<content_management_api_key>'
|
749 | * })
|
750 | *
|
751 | * client.getOrganization('<org_id>')
|
752 | * .then((org) => org.getAppSigningSecret('app_definition_id'))
|
753 | * .then((appSigningSecret) => console.log(appSigningSecret))
|
754 | * .catch(console.error)
|
755 | * ```
|
756 | */
|
757 | getAppSigningSecret: function getAppSigningSecret(appDefinitionId) {
|
758 | var raw = this.toPlainObject();
|
759 | return makeRequest({
|
760 | entityType: 'AppSigningSecret',
|
761 | action: 'get',
|
762 | params: {
|
763 | organizationId: raw.sys.id,
|
764 | appDefinitionId: appDefinitionId
|
765 | }
|
766 | }).then(function (payload) {
|
767 | return wrapAppSigningSecret(makeRequest, payload);
|
768 | });
|
769 | },
|
770 |
|
771 | /**
|
772 | * Deletes an app signing secret
|
773 | * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
|
774 | * @example ```javascript
|
775 | * const contentful = require('contentful-management')
|
776 | * const client = contentful.createClient({
|
777 | * accessToken: '<content_management_api_key>'
|
778 | * })
|
779 | *
|
780 | * client.getOrganization('<org_id>')
|
781 | * .then((org) => org.deleteAppSigningSecret('app_definition_id'))
|
782 | * .then((result) => console.log(result))
|
783 | * .catch(console.error)
|
784 | * ```
|
785 | */
|
786 | deleteAppSigningSecret: function deleteAppSigningSecret(appDefinitionId) {
|
787 | var raw = this.toPlainObject();
|
788 | return makeRequest({
|
789 | entityType: 'AppSigningSecret',
|
790 | action: 'delete',
|
791 | params: {
|
792 | organizationId: raw.sys.id,
|
793 | appDefinitionId: appDefinitionId
|
794 | }
|
795 | }).then(function () {
|
796 | /* noop*/
|
797 | });
|
798 | },
|
799 |
|
800 | /**
|
801 | * Creates or updates an app details entity
|
802 | * @return Promise for an App Details
|
803 | * @example ```javascript
|
804 | * const contentful = require('contentful-management')
|
805 | * const client = contentful.createClient({
|
806 | * accessToken: '<content_management_api_key>'
|
807 | * })
|
808 | *
|
809 | * client.getOrganization('<org_id>')
|
810 | * .then((org) => org.upsertAppDetails('app_definition_id',
|
811 | * { icon: { value: 'base_64_image', type: 'base64' }}
|
812 | * ))
|
813 | * .then((appDetails) => console.log(appDetails))
|
814 | * .catch(console.error)
|
815 | * ```
|
816 | */
|
817 | upsertAppDetails: function upsertAppDetails(appDefinitionId, data) {
|
818 | var raw = this.toPlainObject();
|
819 | return makeRequest({
|
820 | entityType: 'AppDetails',
|
821 | action: 'upsert',
|
822 | params: {
|
823 | organizationId: raw.sys.id,
|
824 | appDefinitionId: appDefinitionId
|
825 | },
|
826 | payload: data
|
827 | }).then(function (payload) {
|
828 | return wrapAppDetails(makeRequest, payload);
|
829 | });
|
830 | },
|
831 |
|
832 | /**
|
833 | * Gets an app details entity
|
834 | * @return Promise for an App Details
|
835 | * @example ```javascript
|
836 | * const contentful = require('contentful-management')
|
837 | * const client = contentful.createClient({
|
838 | * accessToken: '<content_management_api_key>'
|
839 | * })
|
840 | *
|
841 | * client.getOrganization('<org_id>')
|
842 | * .then((org) => org.getAppDetails('app_definition_id'))
|
843 | * .then((appDetails) => console.log(appDetails))
|
844 | * .catch(console.error)
|
845 | * ```
|
846 | */
|
847 | getAppDetails: function getAppDetails(appDefinitionId) {
|
848 | var raw = this.toPlainObject();
|
849 | return makeRequest({
|
850 | entityType: 'AppDetails',
|
851 | action: 'get',
|
852 | params: {
|
853 | organizationId: raw.sys.id,
|
854 | appDefinitionId: appDefinitionId
|
855 | }
|
856 | }).then(function (payload) {
|
857 | return wrapAppDetails(makeRequest, payload);
|
858 | });
|
859 | },
|
860 |
|
861 | /**
|
862 | * Deletes an app details entity.
|
863 | * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
|
864 | * @example ```javascript
|
865 | * const contentful = require('contentful-management')
|
866 | * const client = contentful.createClient({
|
867 | * accessToken: '<content_management_api_key>'
|
868 | * })
|
869 | *
|
870 | * client.getOrganization('<org_id>')
|
871 | * .then((org) => org.deleteAppDetails('app_definition_id'))
|
872 | * .then((result) => console.log(result))
|
873 | * .catch(console.error)
|
874 | * ```
|
875 | */
|
876 | deleteAppDetails: function deleteAppDetails(appDefinitionId) {
|
877 | var raw = this.toPlainObject();
|
878 | return makeRequest({
|
879 | entityType: 'AppDetails',
|
880 | action: 'delete',
|
881 | params: {
|
882 | organizationId: raw.sys.id,
|
883 | appDefinitionId: appDefinitionId
|
884 | }
|
885 | }).then(function () {
|
886 | /* noop*/
|
887 | });
|
888 | }
|
889 | };
|
890 | } |
\ | No newline at end of file |