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.
Files changed (172) hide show
  1. package/README.md +3 -0
  2. package/dist/cjs/adapters/REST/endpoints/access-token.cjs +136 -0
  3. package/dist/cjs/adapters/REST/endpoints/ai-action-invocation.cjs +9 -0
  4. package/dist/cjs/adapters/REST/endpoints/ai-action.cjs +53 -0
  5. package/dist/cjs/adapters/REST/endpoints/api-key.cjs +48 -0
  6. package/dist/cjs/adapters/REST/endpoints/app-access-token.cjs +9 -0
  7. package/dist/cjs/adapters/REST/endpoints/app-action-call.cjs +65 -0
  8. package/dist/cjs/adapters/REST/endpoints/app-action.cjs +42 -0
  9. package/dist/cjs/adapters/REST/endpoints/app-bundle.cjs +39 -0
  10. package/dist/cjs/adapters/REST/endpoints/app-definition.cjs +47 -0
  11. package/dist/cjs/adapters/REST/endpoints/app-details.cjs +17 -0
  12. package/dist/cjs/adapters/REST/endpoints/app-event-subscription.cjs +17 -0
  13. package/dist/cjs/adapters/REST/endpoints/app-installation.cjs +42 -0
  14. package/dist/cjs/adapters/REST/endpoints/app-key.cjs +21 -0
  15. package/dist/cjs/adapters/REST/endpoints/app-signed-request.cjs +9 -0
  16. package/dist/cjs/adapters/REST/endpoints/app-signing-secret.cjs +17 -0
  17. package/dist/cjs/adapters/REST/endpoints/app-upload.cjs +28 -0
  18. package/dist/cjs/adapters/REST/endpoints/asset-key.cjs +34 -0
  19. package/dist/cjs/adapters/REST/endpoints/asset.cjs +185 -0
  20. package/dist/cjs/adapters/REST/endpoints/bulk-action.cjs +21 -0
  21. package/dist/cjs/adapters/REST/endpoints/comment.cjs +92 -0
  22. package/dist/cjs/adapters/REST/endpoints/concept-scheme.cjs +44 -0
  23. package/dist/cjs/adapters/REST/endpoints/concept.cjs +65 -0
  24. package/dist/cjs/adapters/REST/endpoints/content-type.cjs +56 -0
  25. package/dist/cjs/adapters/REST/endpoints/editor-interface.cjs +24 -0
  26. package/dist/cjs/adapters/REST/endpoints/entry.cjs +104 -0
  27. package/dist/cjs/adapters/REST/endpoints/environment-alias.cjs +44 -0
  28. package/dist/cjs/adapters/REST/endpoints/environment-template-installation.cjs +23 -0
  29. package/dist/cjs/adapters/REST/endpoints/environment-template.cjs +49 -0
  30. package/dist/cjs/adapters/REST/endpoints/environment.cjs +47 -0
  31. package/dist/cjs/adapters/REST/endpoints/extension.cjs +44 -0
  32. package/dist/cjs/adapters/REST/endpoints/function-log.cjs +23 -0
  33. package/dist/cjs/adapters/REST/endpoints/function.cjs +25 -0
  34. package/dist/cjs/adapters/REST/endpoints/http.cjs +29 -0
  35. package/dist/cjs/adapters/REST/endpoints/index.cjs +139 -0
  36. package/dist/cjs/adapters/REST/endpoints/locale.cjs +37 -0
  37. package/dist/cjs/adapters/REST/endpoints/oauth-application.cjs +147 -0
  38. package/dist/cjs/adapters/REST/endpoints/organization-invitation.cjs +23 -0
  39. package/dist/cjs/adapters/REST/endpoints/organization-membership.cjs +32 -0
  40. package/dist/cjs/adapters/REST/endpoints/organization.cjs +28 -0
  41. package/dist/cjs/adapters/REST/endpoints/personal-access-token.cjs +37 -0
  42. package/dist/cjs/adapters/REST/endpoints/preview-api-key.cjs +15 -0
  43. package/dist/cjs/adapters/REST/endpoints/raw.cjs +44 -0
  44. package/dist/cjs/adapters/REST/endpoints/release-action.cjs +21 -0
  45. package/dist/cjs/adapters/REST/endpoints/release.cjs +61 -0
  46. package/dist/cjs/adapters/REST/endpoints/resource-provider.cjs +18 -0
  47. package/dist/cjs/adapters/REST/endpoints/resource-type.cjs +30 -0
  48. package/dist/cjs/adapters/REST/endpoints/resource.cjs +10 -0
  49. package/dist/cjs/adapters/REST/endpoints/role.cjs +48 -0
  50. package/dist/cjs/adapters/REST/endpoints/scheduled-action.cjs +44 -0
  51. package/dist/cjs/adapters/REST/endpoints/snapshot.cjs +30 -0
  52. package/dist/cjs/adapters/REST/endpoints/space-member.cjs +11 -0
  53. package/dist/cjs/adapters/REST/endpoints/space-membership.cjs +60 -0
  54. package/dist/cjs/adapters/REST/endpoints/space.cjs +34 -0
  55. package/dist/cjs/adapters/REST/endpoints/tag.cjs +37 -0
  56. package/dist/cjs/adapters/REST/endpoints/task.cjs +40 -0
  57. package/dist/cjs/adapters/REST/endpoints/team-membership.cjs +35 -0
  58. package/dist/cjs/adapters/REST/endpoints/team-space-membership.cjs +46 -0
  59. package/dist/cjs/adapters/REST/endpoints/team.cjs +36 -0
  60. package/dist/cjs/adapters/REST/endpoints/ui-config.cjs +22 -0
  61. package/dist/cjs/adapters/REST/endpoints/upload-credentials.cjs +16 -0
  62. package/dist/cjs/adapters/REST/endpoints/upload.cjs +42 -0
  63. package/dist/cjs/adapters/REST/endpoints/usage.cjs +17 -0
  64. package/dist/cjs/adapters/REST/endpoints/user-ui-config.cjs +22 -0
  65. package/dist/cjs/adapters/REST/endpoints/user.cjs +27 -0
  66. package/dist/cjs/adapters/REST/endpoints/utils.cjs +20 -0
  67. package/dist/cjs/adapters/REST/endpoints/webhook.cjs +98 -0
  68. package/dist/cjs/adapters/REST/endpoints/workflow-definition.cjs +41 -0
  69. package/dist/cjs/adapters/REST/endpoints/workflow.cjs +49 -0
  70. package/dist/cjs/adapters/REST/endpoints/workflows-changelog.cjs +11 -0
  71. package/dist/cjs/adapters/REST/make-request.cjs +19 -0
  72. package/dist/cjs/adapters/REST/rest-adapter.cjs +32 -0
  73. package/dist/cjs/common-types.cjs +6 -0
  74. package/dist/cjs/common-utils.cjs +38 -0
  75. package/dist/cjs/constants/editor-interface-defaults/controls-defaults.cjs +161 -0
  76. package/dist/cjs/constants/editor-interface-defaults/editors-defaults.cjs +40 -0
  77. package/dist/cjs/constants/editor-interface-defaults/index.cjs +14 -0
  78. package/dist/cjs/constants/editor-interface-defaults/sidebar-defaults.cjs +71 -0
  79. package/dist/cjs/constants/editor-interface-defaults/types.cjs +18 -0
  80. package/dist/cjs/create-adapter.cjs +21 -0
  81. package/dist/cjs/create-app-definition-api.cjs +254 -0
  82. package/dist/cjs/create-contentful-api.cjs +592 -0
  83. package/dist/cjs/create-entry-api.cjs +481 -0
  84. package/dist/cjs/create-environment-api.cjs +2403 -0
  85. package/dist/cjs/create-environment-template-api.cjs +270 -0
  86. package/dist/cjs/create-organization-api.cjs +1136 -0
  87. package/dist/cjs/create-space-api.cjs +1591 -0
  88. package/dist/cjs/create-ui-config-api.cjs +55 -0
  89. package/dist/cjs/create-user-ui-config-api.cjs +55 -0
  90. package/dist/cjs/enhance-with-methods.cjs +26 -0
  91. package/dist/cjs/entities/access-token.cjs +36 -0
  92. package/dist/cjs/entities/ai-action-invocation.cjs +46 -0
  93. package/dist/cjs/entities/ai-action.cjs +94 -0
  94. package/dist/cjs/entities/api-key.cjs +59 -0
  95. package/dist/cjs/entities/app-access-token.cjs +17 -0
  96. package/dist/cjs/entities/app-action-call.cjs +67 -0
  97. package/dist/cjs/entities/app-action.cjs +48 -0
  98. package/dist/cjs/entities/app-bundle.cjs +48 -0
  99. package/dist/cjs/entities/app-definition.cjs +29 -0
  100. package/dist/cjs/entities/app-details.cjs +39 -0
  101. package/dist/cjs/entities/app-event-subscription.cjs +34 -0
  102. package/dist/cjs/entities/app-installation.cjs +55 -0
  103. package/dist/cjs/entities/app-key.cjs +44 -0
  104. package/dist/cjs/entities/app-signed-request.cjs +17 -0
  105. package/dist/cjs/entities/app-signing-secret.cjs +34 -0
  106. package/dist/cjs/entities/app-upload.cjs +47 -0
  107. package/dist/cjs/entities/asset-key.cjs +17 -0
  108. package/dist/cjs/entities/asset.cjs +124 -0
  109. package/dist/cjs/entities/bulk-action.cjs +60 -0
  110. package/dist/cjs/entities/comment.cjs +63 -0
  111. package/dist/cjs/entities/concept-scheme.cjs +2 -0
  112. package/dist/cjs/entities/concept.cjs +2 -0
  113. package/dist/cjs/entities/content-type.cjs +120 -0
  114. package/dist/cjs/entities/editor-interface.cjs +50 -0
  115. package/dist/cjs/entities/entry.cjs +27 -0
  116. package/dist/cjs/entities/environment-alias.cjs +58 -0
  117. package/dist/cjs/entities/environment-template-installation.cjs +23 -0
  118. package/dist/cjs/entities/environment-template.cjs +18 -0
  119. package/dist/cjs/entities/environment.cjs +34 -0
  120. package/dist/cjs/entities/extension.cjs +54 -0
  121. package/dist/cjs/entities/function-log.cjs +26 -0
  122. package/dist/cjs/entities/function.cjs +66 -0
  123. package/dist/cjs/entities/index.cjs +131 -0
  124. package/dist/cjs/entities/locale.cjs +57 -0
  125. package/dist/cjs/entities/oauth-application.cjs +66 -0
  126. package/dist/cjs/entities/organization-invitation.cjs +17 -0
  127. package/dist/cjs/entities/organization-membership.cjs +53 -0
  128. package/dist/cjs/entities/organization.cjs +32 -0
  129. package/dist/cjs/entities/personal-access-token.cjs +36 -0
  130. package/dist/cjs/entities/preview-api-key.cjs +31 -0
  131. package/dist/cjs/entities/release-action.cjs +55 -0
  132. package/dist/cjs/entities/release.cjs +111 -0
  133. package/dist/cjs/entities/resource-provider.cjs +139 -0
  134. package/dist/cjs/entities/resource-type.cjs +98 -0
  135. package/dist/cjs/entities/resource.cjs +13 -0
  136. package/dist/cjs/entities/role.cjs +53 -0
  137. package/dist/cjs/entities/scheduled-action.cjs +154 -0
  138. package/dist/cjs/entities/snapshot.cjs +36 -0
  139. package/dist/cjs/entities/space-member.cjs +23 -0
  140. package/dist/cjs/entities/space-membership.cjs +53 -0
  141. package/dist/cjs/entities/space.cjs +33 -0
  142. package/dist/cjs/entities/tag.cjs +56 -0
  143. package/dist/cjs/entities/task.cjs +57 -0
  144. package/dist/cjs/entities/team-membership.cjs +54 -0
  145. package/dist/cjs/entities/team-space-membership.cjs +53 -0
  146. package/dist/cjs/entities/team.cjs +53 -0
  147. package/dist/cjs/entities/ui-config.cjs +20 -0
  148. package/dist/cjs/entities/upload.cjs +38 -0
  149. package/dist/cjs/entities/usage.cjs +25 -0
  150. package/dist/cjs/entities/user-ui-config.cjs +20 -0
  151. package/dist/cjs/entities/user.cjs +28 -0
  152. package/dist/cjs/entities/webhook.cjs +77 -0
  153. package/dist/cjs/entities/workflow-definition.cjs +79 -0
  154. package/dist/cjs/index.cjs +65 -0
  155. package/dist/cjs/methods/action.cjs +53 -0
  156. package/dist/cjs/methods/content-type.cjs +51 -0
  157. package/dist/cjs/methods/utils.cjs +11 -0
  158. package/dist/cjs/plain/as-iterator.cjs +32 -0
  159. package/dist/cjs/plain/checks.cjs +15 -0
  160. package/dist/cjs/plain/pagination-helper.cjs +56 -0
  161. package/dist/cjs/plain/plain-client.cjs +516 -0
  162. package/dist/cjs/plain/wrappers/wrap.cjs +26 -0
  163. package/dist/cjs/upload-http-client.cjs +17 -0
  164. package/dist/contentful-management.browser.js +50 -34
  165. package/dist/contentful-management.browser.min.js +1 -1
  166. package/dist/contentful-management.cjs +35 -19
  167. package/dist/esm/create-contentful-api.js +1 -1
  168. package/dist/esm/index.js +1 -1
  169. package/dist/esm/plain/plain-client.js +1 -1
  170. package/dist/stats-browser-min.html +1 -1
  171. package/package.json +6 -6
  172. package/types.d.ts +0 -1
@@ -0,0 +1,1136 @@
1
+ 'use strict';
2
+
3
+ var contentfulSdkCore = require('contentful-sdk-core');
4
+ var index = require('./entities/index.js');
5
+
6
+ /**
7
+ * Creates API object with methods to access the Organization API
8
+ * @param {MakeRequest} makeRequest - function to make requests via an adapter
9
+ * @return {ContentfulOrganizationAPI}
10
+ * @private
11
+ */
12
+ function createOrganizationApi(makeRequest) {
13
+ const { wrapAppDefinition, wrapAppDefinitionCollection } = index.appDefinition;
14
+ const { wrapUser, wrapUserCollection } = index.user;
15
+ const { wrapOrganizationMembership, wrapOrganizationMembershipCollection } = index.organizationMembership;
16
+ const { wrapTeamMembership, wrapTeamMembershipCollection } = index.teamMembership;
17
+ const { wrapTeamSpaceMembership, wrapTeamSpaceMembershipCollection } = index.teamSpaceMembership;
18
+ const { wrapTeam, wrapTeamCollection } = index.team;
19
+ const { wrapSpaceMembership, wrapSpaceMembershipCollection } = index.spaceMembership;
20
+ const { wrapOrganizationInvitation } = index.organizationInvitation;
21
+ const { wrapAppUpload } = index.appUpload;
22
+ const { wrapAppSigningSecret } = index.appSigningSecret;
23
+ const { wrapAppEventSubscription } = index.appEventSubscription;
24
+ const { wrapAppKey, wrapAppKeyCollection } = index.appKey;
25
+ const { wrapAppDetails } = index.appDetails;
26
+ const { wrapAppAction, wrapAppActionCollection } = index.appAction;
27
+ const { wrapFunction, wrapFunctionCollection } = index.func;
28
+ const { wrapRoleCollection } = index.role;
29
+ const { wrapSpaceCollection } = index.space;
30
+ return {
31
+ /**
32
+ * Gets a collection of spaces in the organization
33
+ * @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.
34
+ * @return Promise a collection of Spaces in the organization
35
+ * @example ```javascript
36
+ * const contentful = require('contentful-management')
37
+ * const client = contentful.createClient({
38
+ * accessToken: '<content_management_api_key>'
39
+ * })
40
+ *
41
+ * client.getOrganization('<organization_id>')
42
+ * .then((organization) => organization.getSpaces())
43
+ * .then((spaces) => console.log(spaces))
44
+ * .catch(console.error)
45
+ * ```
46
+ */
47
+ getSpaces(query = {}) {
48
+ const raw = this.toPlainObject();
49
+ return makeRequest({
50
+ entityType: 'Space',
51
+ action: 'getManyForOrganization',
52
+ params: {
53
+ organizationId: raw.sys.id,
54
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
55
+ },
56
+ }).then((data) => wrapSpaceCollection(makeRequest, data));
57
+ },
58
+ /**
59
+ * Gets a User
60
+ * @return Promise for a User
61
+ * @example ```javascript
62
+ * const contentful = require('contentful-management')
63
+ * const client = contentful.createClient({
64
+ * accessToken: '<content_management_api_key>'
65
+ * })
66
+ *
67
+ * client.getOrganization('<organization_id>')
68
+ * .then((organization) => organization.getUser('id'))
69
+ * .then((user) => console.log(user))
70
+ * .catch(console.error)
71
+ * ```
72
+ */
73
+ getUser(id) {
74
+ const raw = this.toPlainObject();
75
+ return makeRequest({
76
+ entityType: 'User',
77
+ action: 'getForOrganization',
78
+ params: { organizationId: raw.sys.id, userId: id },
79
+ }).then((data) => wrapUser(makeRequest, data));
80
+ },
81
+ /**
82
+ * Gets a collection of Users in organization
83
+ * @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.
84
+ * @return Promise a collection of Users in organization
85
+ * @example ```javascript
86
+ * const contentful = require('contentful-management')
87
+ * const client = contentful.createClient({
88
+ * accessToken: '<content_management_api_key>'
89
+ * })
90
+ *
91
+ * client.getOrganization('<organization_id>')
92
+ * .then((organization) => organization.getUsers())
93
+ * .then((users) => console.log(users))
94
+ * .catch(console.error)
95
+ * ```
96
+ */
97
+ getUsers(query = {}) {
98
+ const raw = this.toPlainObject();
99
+ return makeRequest({
100
+ entityType: 'User',
101
+ action: 'getManyForOrganization',
102
+ params: {
103
+ organizationId: raw.sys.id,
104
+ query: contentfulSdkCore.createRequestConfig({ query: query }).params,
105
+ },
106
+ }).then((data) => wrapUserCollection(makeRequest, data));
107
+ },
108
+ /**
109
+ * Gets an Organization Membership
110
+ * @param id - Organization Membership ID
111
+ * @return Promise for an Organization Membership
112
+ * @example ```javascript
113
+ * const contentful = require('contentful-management')
114
+ * const client = contentful.createClient({
115
+ * accessToken: '<content_management_api_key>'
116
+ * })
117
+ *
118
+ * client.getOrganization('organization_id')
119
+ * .then((organization) => organization.getOrganizationMembership('organizationMembership_id'))
120
+ * .then((organizationMembership) => console.log(organizationMembership))
121
+ * .catch(console.error)
122
+ * ```
123
+ */
124
+ getOrganizationMembership(id) {
125
+ const raw = this.toPlainObject();
126
+ const organizationId = raw.sys.id;
127
+ return makeRequest({
128
+ entityType: 'OrganizationMembership',
129
+ action: 'get',
130
+ params: {
131
+ organizationId,
132
+ organizationMembershipId: id,
133
+ },
134
+ }).then((data) => wrapOrganizationMembership(makeRequest, data, organizationId));
135
+ },
136
+ /**
137
+ * Gets a collection of Organization Memberships
138
+ * @param params - 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.
139
+ * @return Promise for a collection of Organization Memberships
140
+ * @example ```javascript
141
+ * const contentful = require('contentful-management')
142
+ * const client = contentful.createClient({
143
+ * accessToken: '<content_management_api_key>'
144
+ * })
145
+ *
146
+ * client.getOrganization('organization_id')
147
+ * .then((organization) => organization.getOrganizationMemberships({'limit': 100})) // you can add more queries as 'key': 'value'
148
+ * .then((response) => console.log(response.items))
149
+ * .catch(console.error)
150
+ * ```
151
+ */
152
+ getOrganizationMemberships(params = {}) {
153
+ const raw = this.toPlainObject();
154
+ return makeRequest({
155
+ entityType: 'OrganizationMembership',
156
+ action: 'getMany',
157
+ params: Object.assign({ organizationId: raw.sys.id }, params),
158
+ }).then((data) => wrapOrganizationMembershipCollection(makeRequest, data, raw.sys.id));
159
+ },
160
+ /**
161
+ * Creates a Team
162
+ * @param data representation of the Team to be created
163
+ * @example ```javascript
164
+ * const contentful = require('contentful-management')
165
+ * const client = contentful.createClient({
166
+ * accessToken: '<content_management_api_key>'
167
+ * })
168
+ *
169
+ * client.getOrganization('<org_id>')
170
+ * .then((org) => org.createTeam({
171
+ * name: 'new team',
172
+ * description: 'new team description'
173
+ * }))
174
+ * .then((team) => console.log(team))
175
+ * .catch(console.error)
176
+ * ```
177
+ */
178
+ createTeam(data) {
179
+ const raw = this.toPlainObject();
180
+ return makeRequest({
181
+ entityType: 'Team',
182
+ action: 'create',
183
+ params: { organizationId: raw.sys.id },
184
+ payload: data,
185
+ }).then((data) => wrapTeam(makeRequest, data));
186
+ },
187
+ /**
188
+ * Gets an Team
189
+ * @example ```javascript
190
+ * const contentful = require('contentful-management')
191
+ * const client = contentful.createClient({
192
+ * accessToken: '<content_management_api_key>'
193
+ * })
194
+ *
195
+ * client.getOrganization('orgId')
196
+ * .then((organization) => organization.getTeam('teamId'))
197
+ * .then((team) => console.log(team))
198
+ * .catch(console.error)
199
+ * ```
200
+ */
201
+ getTeam(teamId) {
202
+ const raw = this.toPlainObject();
203
+ return makeRequest({
204
+ entityType: 'Team',
205
+ action: 'get',
206
+ params: { organizationId: raw.sys.id, teamId },
207
+ }).then((data) => wrapTeam(makeRequest, data));
208
+ },
209
+ /**
210
+ * Gets all Teams in an organization
211
+ * @example ```javascript
212
+ * const contentful = require('contentful-management')
213
+ * const client = contentful.createClient({
214
+ * accessToken: '<content_management_api_key>'
215
+ * })
216
+ *
217
+ * client.getOrganization('orgId')
218
+ * .then((organization) => organization.getTeams())
219
+ * .then((teams) => console.log(teams))
220
+ * .catch(console.error)
221
+ * ```
222
+ */
223
+ getTeams(query = {}) {
224
+ const raw = this.toPlainObject();
225
+ return makeRequest({
226
+ entityType: 'Team',
227
+ action: 'getMany',
228
+ params: {
229
+ organizationId: raw.sys.id,
230
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
231
+ },
232
+ }).then((data) => wrapTeamCollection(makeRequest, data));
233
+ },
234
+ /**
235
+ * Creates a Team membership
236
+ * @param teamId - Id of the team the membership will be created in
237
+ * @param data - Object representation of the Team Membership to be created
238
+ * @return Promise for the newly created TeamMembership
239
+ * @example ```javascript
240
+ * const contentful = require('contentful-management')
241
+ * const client = contentful.createClient({
242
+ * accessToken: '<content_management_api_key>'
243
+ * })
244
+ *
245
+ * client.getOrganization('organizationId')
246
+ * .then((org) => org.createTeamMembership('teamId', {
247
+ * admin: true,
248
+ * organizationMembershipId: 'organizationMembershipId'
249
+ * }))
250
+ * .then((teamMembership) => console.log(teamMembership))
251
+ * .catch(console.error)
252
+ * ```
253
+ */
254
+ createTeamMembership(teamId, data) {
255
+ const raw = this.toPlainObject();
256
+ return makeRequest({
257
+ entityType: 'TeamMembership',
258
+ action: 'create',
259
+ params: { organizationId: raw.sys.id, teamId },
260
+ payload: data,
261
+ }).then((data) => wrapTeamMembership(makeRequest, data));
262
+ },
263
+ /**
264
+ * Gets an Team Membership from the team with given teamId
265
+ * @return Promise for an Team Membership
266
+ * @example ```javascript
267
+ * const contentful = require('contentful-management')
268
+ * const client = contentful.createClient({
269
+ * accessToken: '<content_management_api_key>'
270
+ * })
271
+ *
272
+ * client.getOrganization('organizationId')
273
+ * .then((organization) => organization.getTeamMembership('teamId', 'teamMembership_id'))
274
+ * .then((teamMembership) => console.log(teamMembership))
275
+ * .catch(console.error)
276
+ * ```
277
+ */
278
+ getTeamMembership(teamId, teamMembershipId) {
279
+ const raw = this.toPlainObject();
280
+ return makeRequest({
281
+ entityType: 'TeamMembership',
282
+ action: 'get',
283
+ params: { organizationId: raw.sys.id, teamId, teamMembershipId },
284
+ }).then((data) => wrapTeamMembership(makeRequest, data));
285
+ },
286
+ /**
287
+ * 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.
288
+ * @return Promise for a Team Membership Collection
289
+ * @example ```javascript
290
+ * const contentful = require('contentful-management')
291
+ * const client = contentful.createClient({
292
+ * accessToken: '<content_management_api_key>'
293
+ * })
294
+ *
295
+ * client.getOrganization('organizationId')
296
+ * .then((organization) => organization.getTeamMemberships('teamId'))
297
+ * .then((teamMemberships) => console.log(teamMemberships))
298
+ * .catch(console.error)
299
+ * ```
300
+ */
301
+ getTeamMemberships(opts = {}) {
302
+ const { teamId, query = {} } = opts;
303
+ const raw = this.toPlainObject();
304
+ if (teamId) {
305
+ return makeRequest({
306
+ entityType: 'TeamMembership',
307
+ action: 'getManyForTeam',
308
+ params: {
309
+ organizationId: raw.sys.id,
310
+ teamId,
311
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
312
+ },
313
+ }).then((data) => wrapTeamMembershipCollection(makeRequest, data));
314
+ }
315
+ return makeRequest({
316
+ entityType: 'TeamMembership',
317
+ action: 'getManyForOrganization',
318
+ params: {
319
+ organizationId: raw.sys.id,
320
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
321
+ },
322
+ }).then((data) => wrapTeamMembershipCollection(makeRequest, data));
323
+ },
324
+ /**
325
+ * 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.
326
+ * @return Promise for a Team Space Membership Collection
327
+ * @example ```javascript
328
+ * const contentful = require('contentful-management')
329
+ * const client = contentful.createClient({
330
+ * accessToken: '<content_management_api_key>'
331
+ * })
332
+ *
333
+ * client.getOrganization('organizationId')
334
+ * .then((organization) => organization.getTeamSpaceMemberships('teamId'))
335
+ * .then((teamSpaceMemberships) => console.log(teamSpaceMemberships))
336
+ * .catch(console.error)
337
+ * ```
338
+ */
339
+ getTeamSpaceMemberships(opts = {}) {
340
+ const raw = this.toPlainObject();
341
+ return makeRequest({
342
+ entityType: 'TeamSpaceMembership',
343
+ action: 'getManyForOrganization',
344
+ params: {
345
+ organizationId: raw.sys.id,
346
+ query: contentfulSdkCore.createRequestConfig({ query: opts.query || {} }).params,
347
+ teamId: opts.teamId,
348
+ },
349
+ }).then((data) => wrapTeamSpaceMembershipCollection(makeRequest, data));
350
+ },
351
+ /**
352
+ * Get a Team Space Membership with given teamSpaceMembershipId
353
+ * @return Promise for a Team Space Membership
354
+ * @example ```javascript
355
+ * const contentful = require('contentful-management')
356
+ * const client = contentful.createClient({
357
+ * accessToken: '<content_management_api_key>'
358
+ * })
359
+ *
360
+ * client.getOrganization('organizationId')
361
+ * .then((organization) => organization.getTeamSpaceMembership('teamSpaceMembershipId'))
362
+ * .then((teamSpaceMembership) => console.log(teamSpaceMembership))
363
+ * .catch(console.error)]
364
+ * ```
365
+ */
366
+ getTeamSpaceMembership(teamSpaceMembershipId) {
367
+ const raw = this.toPlainObject();
368
+ return makeRequest({
369
+ entityType: 'TeamSpaceMembership',
370
+ action: 'getForOrganization',
371
+ params: {
372
+ organizationId: raw.sys.id,
373
+ teamSpaceMembershipId,
374
+ },
375
+ }).then((data) => wrapTeamSpaceMembership(makeRequest, data));
376
+ },
377
+ /**
378
+ * Gets an Space Membership in Organization
379
+ * @param id - Organiztion Space Membership ID
380
+ * @return Promise for a Space Membership in an organization
381
+ * @example ```javascript
382
+ * const contentful = require('contentful-management')
383
+ * const client = contentful.createClient({
384
+ * accessToken: '<content_management_api_key>'
385
+ * })
386
+ *
387
+ * client.getOrganization('organization_id')
388
+ * .then((organization) => organization.getOrganizationSpaceMembership('organizationSpaceMembership_id'))
389
+ * .then((organizationMembership) => console.log(organizationMembership))
390
+ * .catch(console.error)
391
+ * ```
392
+ */
393
+ getOrganizationSpaceMembership(id) {
394
+ const raw = this.toPlainObject();
395
+ return makeRequest({
396
+ entityType: 'SpaceMembership',
397
+ action: 'getForOrganization',
398
+ params: {
399
+ organizationId: raw.sys.id,
400
+ spaceMembershipId: id,
401
+ },
402
+ }).then((data) => wrapSpaceMembership(makeRequest, data));
403
+ },
404
+ /**
405
+ * Gets a collection Space Memberships in organization
406
+ * @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.
407
+ * @return Promise for a Space Membership collection across all spaces in the organization
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('organization_id')
415
+ * .then((organization) => organization.getOrganizationSpaceMemberships()) // you can add queries like 'limit': 100
416
+ * .then((response) => console.log(response.items))
417
+ * .catch(console.error)
418
+ * ```
419
+ */
420
+ getOrganizationSpaceMemberships(query = {}) {
421
+ const raw = this.toPlainObject();
422
+ return makeRequest({
423
+ entityType: 'SpaceMembership',
424
+ action: 'getManyForOrganization',
425
+ params: {
426
+ organizationId: raw.sys.id,
427
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
428
+ },
429
+ }).then((data) => wrapSpaceMembershipCollection(makeRequest, data));
430
+ },
431
+ /**
432
+ * Gets an Invitation in Organization
433
+ * @return Promise for a OrganizationInvitation in an organization
434
+ * @example ```javascript
435
+ * const contentful = require('contentful-management')
436
+ * const client = contentful.createClient({
437
+ * accessToken: '<content_management_api_key>'
438
+ * })
439
+ *
440
+ * client.getOrganization('<org_id>')
441
+ * .then((organization) => organization.getOrganizationInvitation('invitation_id'))
442
+ * .then((invitation) => console.log(invitation))
443
+ * .catch(console.error)
444
+ * ```
445
+ */
446
+ getOrganizationInvitation(invitationId) {
447
+ const raw = this.toPlainObject();
448
+ return makeRequest({
449
+ entityType: 'OrganizationInvitation',
450
+ action: 'get',
451
+ params: {
452
+ organizationId: raw.sys.id,
453
+ invitationId,
454
+ },
455
+ }).then((data) => wrapOrganizationInvitation(makeRequest, data));
456
+ },
457
+ /**
458
+ * Create an Invitation in Organization
459
+ * @return Promise for a OrganizationInvitation in an organization
460
+ * @example ```javascript
461
+ * const contentful = require('contentful-management')
462
+ * const client = contentful.createClient({
463
+ * accessToken: '<content_management_api_key>'
464
+ * })
465
+ *
466
+ * client.getOrganization('<org_id>')
467
+ * .then((organization) => organization.createOrganizationInvitation({
468
+ * email: 'user.email@example.com'
469
+ * firstName: 'User First Name'
470
+ * lastName: 'User Last Name'
471
+ * role: 'developer'
472
+ * })
473
+ * .catch(console.error)
474
+ * ```
475
+ */
476
+ createOrganizationInvitation(data) {
477
+ const raw = this.toPlainObject();
478
+ return makeRequest({
479
+ entityType: 'OrganizationInvitation',
480
+ action: 'create',
481
+ params: {
482
+ organizationId: raw.sys.id,
483
+ },
484
+ payload: data,
485
+ }).then((data) => wrapOrganizationInvitation(makeRequest, data));
486
+ },
487
+ /**
488
+ * Gets a collection of Roles
489
+ * @return Promise for a collection of Roles
490
+ * @example ```javascript
491
+ * const contentful = require('contentful-management')
492
+ *
493
+ * const client = contentful.createClient({
494
+ * accessToken: '<content_management_api_key>'
495
+ * })
496
+ *
497
+ * client.getOrganization('<org_id>')
498
+ * .then((org) => org.getRoles())
499
+ * .then((response) => console.log(response.items))
500
+ * .catch(console.error)
501
+ * ```
502
+ */
503
+ getRoles(query = {}) {
504
+ const raw = this.toPlainObject();
505
+ return makeRequest({
506
+ entityType: 'Role',
507
+ action: 'getManyForOrganization',
508
+ params: { organizationId: raw.sys.id, query: contentfulSdkCore.createRequestConfig({ query }).params },
509
+ }).then((data) => wrapRoleCollection(makeRequest, data));
510
+ },
511
+ /**
512
+ * Creates an app definition
513
+ * @param Object representation of the App Definition to be created
514
+ * @return Promise for the newly created AppDefinition
515
+ * @example ```javascript
516
+ * const contentful = require('contentful-management')
517
+ * const client = contentful.createClient({
518
+ * accessToken: '<content_management_api_key>'
519
+ * })
520
+ *
521
+ * client.getOrganization('<org_id>')
522
+ * .then((org) => org.createAppDefinition({
523
+ * name: 'Example app',
524
+ * locations: [{ location: 'app-config' }],
525
+ * src: "http://my-app-host.com/my-app"
526
+ * }))
527
+ * .then((appDefinition) => console.log(appDefinition))
528
+ * .catch(console.error)
529
+ * ```
530
+ */
531
+ createAppDefinition(data) {
532
+ const raw = this.toPlainObject();
533
+ return makeRequest({
534
+ entityType: 'AppDefinition',
535
+ action: 'create',
536
+ params: { organizationId: raw.sys.id },
537
+ payload: data,
538
+ }).then((data) => wrapAppDefinition(makeRequest, data));
539
+ },
540
+ /**
541
+ * Gets all app definitions
542
+ * @return Promise for a collection of App Definitions
543
+ * @example ```javascript
544
+ * const contentful = require('contentful-management')
545
+ * const client = contentful.createClient({
546
+ * accessToken: '<content_management_api_key>'
547
+ * })
548
+ *
549
+ * client.getOrganization('<org_id>')
550
+ * .then((org) => org.getAppDefinitions())
551
+ * .then((response) => console.log(response.items))
552
+ * .catch(console.error)
553
+ * ```
554
+ */
555
+ getAppDefinitions(query = {}) {
556
+ const raw = this.toPlainObject();
557
+ return makeRequest({
558
+ entityType: 'AppDefinition',
559
+ action: 'getMany',
560
+ params: { organizationId: raw.sys.id, query: query },
561
+ }).then((data) => wrapAppDefinitionCollection(makeRequest, data));
562
+ },
563
+ /**
564
+ * Gets an app definition
565
+ * @return Promise for an App Definition
566
+ * @example ```javascript
567
+ * const contentful = require('contentful-management')
568
+ * const client = contentful.createClient({
569
+ * accessToken: '<content_management_api_key>'
570
+ * })
571
+ *
572
+ * client.getOrganization('<org_id>')
573
+ * .then((org) => org.getAppDefinition('<app_definition_id>'))
574
+ * .then((appDefinition) => console.log(appDefinition))
575
+ * .catch(console.error)
576
+ * ```
577
+ */
578
+ getAppDefinition(id) {
579
+ const raw = this.toPlainObject();
580
+ return makeRequest({
581
+ entityType: 'AppDefinition',
582
+ action: 'get',
583
+ params: { organizationId: raw.sys.id, appDefinitionId: id },
584
+ }).then((data) => wrapAppDefinition(makeRequest, data));
585
+ },
586
+ /**
587
+ * Gets an app upload
588
+ * @return Promise for an App Upload
589
+ * @example ```javascript
590
+ * const contentful = require('contentful-management')
591
+ * const client = contentful.createClient({
592
+ * accessToken: '<content_management_api_key>'
593
+ * })
594
+ *
595
+ * client.getOrganization('<org_id>')
596
+ * .then((org) => org.getAppUpload('<app_upload_id>'))
597
+ * .then((appUpload) => console.log(appUpload))
598
+ * .catch(console.error)
599
+ * ```
600
+ */
601
+ getAppUpload(appUploadId) {
602
+ const raw = this.toPlainObject();
603
+ return makeRequest({
604
+ entityType: 'AppUpload',
605
+ action: 'get',
606
+ params: { organizationId: raw.sys.id, appUploadId },
607
+ }).then((data) => wrapAppUpload(makeRequest, data));
608
+ },
609
+ /**
610
+ * Creates an app upload
611
+ * @return Promise for an App Upload
612
+ * @example ```javascript
613
+ * const contentful = require('contentful-management')
614
+ * const client = contentful.createClient({
615
+ * accessToken: '<content_management_api_key>'
616
+ * })
617
+ *
618
+ * client.getOrganization('<org_id>')
619
+ * .then((org) => org.createAppUpload('some_zip_file'))
620
+ * .then((appUpload) => console.log(appUpload))
621
+ * .catch(console.error)
622
+ * ```
623
+ */
624
+ createAppUpload(file) {
625
+ const raw = this.toPlainObject();
626
+ return makeRequest({
627
+ entityType: 'AppUpload',
628
+ action: 'create',
629
+ params: { organizationId: raw.sys.id },
630
+ payload: { file },
631
+ }).then((data) => wrapAppUpload(makeRequest, data));
632
+ },
633
+ /**
634
+ * Creates or updates an app signing secret
635
+ * @return Promise for an App SigningSecret
636
+ * @example ```javascript
637
+ * const contentful = require('contentful-management')
638
+ * const client = contentful.createClient({
639
+ * accessToken: '<content_management_api_key>'
640
+ * })
641
+ *
642
+ * client.getOrganization('<org_id>')
643
+ * .then((org) => org.upsertAppSigningSecret('app_definition_id', { value: 'tsren3s1....wn1e' }))
644
+ * .then((appSigningSecret) => console.log(appSigningSecret))
645
+ * .catch(console.error)
646
+ * ```
647
+ */
648
+ upsertAppSigningSecret(appDefinitionId, data) {
649
+ const raw = this.toPlainObject();
650
+ return makeRequest({
651
+ entityType: 'AppSigningSecret',
652
+ action: 'upsert',
653
+ params: { organizationId: raw.sys.id, appDefinitionId },
654
+ payload: data,
655
+ }).then((payload) => wrapAppSigningSecret(makeRequest, payload));
656
+ },
657
+ /**
658
+ * Gets an app signing secret
659
+ * @return Promise for an App SigningSecret
660
+ * @example ```javascript
661
+ * const contentful = require('contentful-management')
662
+ * const client = contentful.createClient({
663
+ * accessToken: '<content_management_api_key>'
664
+ * })
665
+ *
666
+ * client.getOrganization('<org_id>')
667
+ * .then((org) => org.getAppSigningSecret('app_definition_id'))
668
+ * .then((appSigningSecret) => console.log(appSigningSecret))
669
+ * .catch(console.error)
670
+ * ```
671
+ */
672
+ getAppSigningSecret(appDefinitionId) {
673
+ const raw = this.toPlainObject();
674
+ return makeRequest({
675
+ entityType: 'AppSigningSecret',
676
+ action: 'get',
677
+ params: { organizationId: raw.sys.id, appDefinitionId },
678
+ }).then((payload) => wrapAppSigningSecret(makeRequest, payload));
679
+ },
680
+ /**
681
+ * Deletes an app signing secret
682
+ * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
683
+ * @example ```javascript
684
+ * const contentful = require('contentful-management')
685
+ * const client = contentful.createClient({
686
+ * accessToken: '<content_management_api_key>'
687
+ * })
688
+ *
689
+ * client.getOrganization('<org_id>')
690
+ * .then((org) => org.deleteAppSigningSecret('app_definition_id'))
691
+ * .then((result) => console.log(result))
692
+ * .catch(console.error)
693
+ * ```
694
+ */
695
+ deleteAppSigningSecret(appDefinitionId) {
696
+ const raw = this.toPlainObject();
697
+ return makeRequest({
698
+ entityType: 'AppSigningSecret',
699
+ action: 'delete',
700
+ params: { organizationId: raw.sys.id, appDefinitionId },
701
+ }).then(() => {
702
+ /* noop*/
703
+ });
704
+ },
705
+ /**
706
+ * Creates or updates an app event subscription
707
+ * @return Promise for an App Event Subscription
708
+ * @example ```javascript
709
+ * const contentful = require('contentful-management')
710
+ * const client = contentful.createClient({
711
+ * accessToken: '<content_management_api_key>'
712
+ * })
713
+ *
714
+ * client.getOrganization('<org_id>')
715
+ * .then((org) => org.upsertAppEventSubscription('app_definition_id', { targetUrl: '<target_url>', topics: ['<topic>'] }))
716
+ * .then((appEventSubscription) => console.log(appEventSubscription))
717
+ * .catch(console.error)
718
+ * ```
719
+ */
720
+ upsertAppEventSubscription(appDefinitionId, data) {
721
+ const raw = this.toPlainObject();
722
+ return makeRequest({
723
+ entityType: 'AppEventSubscription',
724
+ action: 'upsert',
725
+ params: { organizationId: raw.sys.id, appDefinitionId },
726
+ payload: data,
727
+ }).then((payload) => wrapAppEventSubscription(makeRequest, payload));
728
+ },
729
+ /**
730
+ * Gets an app event subscription
731
+ * @return Promise for an App Event Subscription
732
+ * @example ```javascript
733
+ * const contentful = require('contentful-management')
734
+ * const client = contentful.createClient({
735
+ * accessToken: '<content_management_api_key>'
736
+ * })
737
+ *
738
+ * client.getOrganization('<org_id>')
739
+ * .then((org) => org.getAppEventSubscription('app_definition_id'))
740
+ * .then((appEventSubscription) => console.log(appEventSubscription))
741
+ * .catch(console.error)
742
+ * ```
743
+ */
744
+ getAppEventSubscription(appDefinitionId) {
745
+ const raw = this.toPlainObject();
746
+ return makeRequest({
747
+ entityType: 'AppEventSubscription',
748
+ action: 'get',
749
+ params: { organizationId: raw.sys.id, appDefinitionId },
750
+ }).then((payload) => wrapAppEventSubscription(makeRequest, payload));
751
+ },
752
+ /**
753
+ * Deletes the current App Event Subscription for the given App
754
+ * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
755
+ * @example ```javascript
756
+ * const contentful = require('contentful-management')
757
+ * const client = contentful.createClient({
758
+ * accessToken: '<content_management_api_key>'
759
+ * })
760
+ *
761
+ * client.getOrganization('<org_id>')
762
+ * .then((org) => org.deleteAppEventSubscription('app_definition_id'))
763
+ * .then((result) => console.log(result))
764
+ * .catch(console.error)
765
+ * ```
766
+ */
767
+ deleteAppEventSubscription(appDefinitionId) {
768
+ const raw = this.toPlainObject();
769
+ return makeRequest({
770
+ entityType: 'AppEventSubscription',
771
+ action: 'delete',
772
+ params: { organizationId: raw.sys.id, appDefinitionId },
773
+ }).then(() => {
774
+ /* noop*/
775
+ });
776
+ },
777
+ /**
778
+ * Creates or updates an app event subscription
779
+ * @return Promise for an App Event Subscription
780
+ * @example ```javascript
781
+ * const contentful = require('contentful-management')
782
+ * const client = contentful.createClient({
783
+ * accessToken: '<content_management_api_key>'
784
+ * })
785
+ *
786
+ * // generate a new private key
787
+ * client.getOrganization('<org_id>')
788
+ * .then((org) => org.upsertAppEventSubscription('app_definition_id', { generate: true }))
789
+ * .then((appEventSubscription) => console.log(appEventSubscription))
790
+ * .catch(console.error)
791
+ *
792
+ * // or use an existing JSON Web Key
793
+ * client.getOrganization('<org_id>')
794
+ * .then((org) => org.upsertAppEventSubscription('app_definition_id', { jwk: 'jwk' }))
795
+ * .then((appEventSubscription) => console.log(appEventSubscription))
796
+ * .catch(console.error)
797
+ * ```
798
+ */
799
+ createAppKey(appDefinitionId, data) {
800
+ const raw = this.toPlainObject();
801
+ return makeRequest({
802
+ entityType: 'AppKey',
803
+ action: 'create',
804
+ params: { organizationId: raw.sys.id, appDefinitionId },
805
+ payload: data,
806
+ }).then((payload) => wrapAppKey(makeRequest, payload));
807
+ },
808
+ /**
809
+ * Gets an app key by fingerprint
810
+ * @return Promise for an App Key
811
+ * @example ```javascript
812
+ * const contentful = require('contentful-management')
813
+ * const client = contentful.createClient({
814
+ * accessToken: '<content_management_api_key>'
815
+ * })
816
+ *
817
+ * client.getOrganization('<org_id>')
818
+ * .then((org) => org.getAppKey('app_definition_id', 'fingerprint'))
819
+ * .then((appKey) => console.log(appKey))
820
+ * .catch(console.error)
821
+ * ```
822
+ */
823
+ getAppKey(appDefinitionId, fingerprint) {
824
+ const raw = this.toPlainObject();
825
+ return makeRequest({
826
+ entityType: 'AppKey',
827
+ action: 'get',
828
+ params: { organizationId: raw.sys.id, appDefinitionId, fingerprint },
829
+ }).then((payload) => wrapAppKey(makeRequest, payload));
830
+ },
831
+ /**
832
+ * Gets all keys for the given app
833
+ * @return Promise for an array of App Keys
834
+ * @example ```javascript
835
+ * const contentful = require('contentful-management')
836
+ * const client = contentful.createClient({
837
+ * accessToken: '<content_management_api_key>'
838
+ * })
839
+ *
840
+ * // with default pagination
841
+ * client.getOrganization('<org_id>')
842
+ * .then((org) => org.getAppKeys('app_definition_id'))
843
+ * .then((appKeys) => console.log(appKeys))
844
+ * .catch(console.error)
845
+ *
846
+ * // with explicit pagination
847
+ * client.getOrganization('<org_id>')
848
+ * .then((org) => org.getAppKeys('app_definition_id', { skip: 'skip', limit: 'limit' }))
849
+ * .then((appKeys) => console.log(appKeys))
850
+ * .catch(console.error)
851
+ * ```
852
+ */
853
+ getAppKeys(appDefinitionId, query = {}) {
854
+ const raw = this.toPlainObject();
855
+ return makeRequest({
856
+ entityType: 'AppKey',
857
+ action: 'getMany',
858
+ params: {
859
+ organizationId: raw.sys.id,
860
+ appDefinitionId,
861
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
862
+ },
863
+ }).then((payload) => wrapAppKeyCollection(makeRequest, payload));
864
+ },
865
+ /**
866
+ * Deletes an app key by fingerprint.
867
+ * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
868
+ * @example ```javascript
869
+ * const contentful = require('contentful-management')
870
+ * const client = contentful.createClient({
871
+ * accessToken: '<content_management_api_key>'
872
+ * })
873
+ *
874
+ * client.getOrganization('<org_id>')
875
+ * .then((org) => org.deleteAppKey('app_definition_id', 'fingerprint'))
876
+ * .then((result) => console.log(result))
877
+ * .catch(console.error)
878
+ * ```
879
+ */
880
+ deleteAppKey(appDefinitionId, fingerprint) {
881
+ const raw = this.toPlainObject();
882
+ return makeRequest({
883
+ entityType: 'AppKey',
884
+ action: 'delete',
885
+ params: { organizationId: raw.sys.id, appDefinitionId, fingerprint },
886
+ }).then(() => {
887
+ /* noop*/
888
+ });
889
+ },
890
+ /**
891
+ * Creates or updates an app details entity
892
+ * @return Promise for an App Details
893
+ * @example ```javascript
894
+ * const contentful = require('contentful-management')
895
+ * const client = contentful.createClient({
896
+ * accessToken: '<content_management_api_key>'
897
+ * })
898
+ *
899
+ * client.getOrganization('<org_id>')
900
+ * .then((org) => org.upsertAppDetails('app_definition_id',
901
+ * { icon: { value: 'base_64_image', type: 'base64' }}
902
+ * ))
903
+ * .then((appDetails) => console.log(appDetails))
904
+ * .catch(console.error)
905
+ * ```
906
+ */
907
+ upsertAppDetails(appDefinitionId, data) {
908
+ const raw = this.toPlainObject();
909
+ return makeRequest({
910
+ entityType: 'AppDetails',
911
+ action: 'upsert',
912
+ params: { organizationId: raw.sys.id, appDefinitionId },
913
+ payload: data,
914
+ }).then((payload) => wrapAppDetails(makeRequest, payload));
915
+ },
916
+ /**
917
+ * Gets an app details entity
918
+ * @return Promise for an App Details
919
+ * @example ```javascript
920
+ * const contentful = require('contentful-management')
921
+ * const client = contentful.createClient({
922
+ * accessToken: '<content_management_api_key>'
923
+ * })
924
+ *
925
+ * client.getOrganization('<org_id>')
926
+ * .then((org) => org.getAppDetails('app_definition_id'))
927
+ * .then((appDetails) => console.log(appDetails))
928
+ * .catch(console.error)
929
+ * ```
930
+ */
931
+ getAppDetails(appDefinitionId) {
932
+ const raw = this.toPlainObject();
933
+ return makeRequest({
934
+ entityType: 'AppDetails',
935
+ action: 'get',
936
+ params: { organizationId: raw.sys.id, appDefinitionId },
937
+ }).then((payload) => wrapAppDetails(makeRequest, payload));
938
+ },
939
+ /**
940
+ * Deletes an app details entity.
941
+ * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
942
+ * @example ```javascript
943
+ * const contentful = require('contentful-management')
944
+ * const client = contentful.createClient({
945
+ * accessToken: '<content_management_api_key>'
946
+ * })
947
+ *
948
+ * client.getOrganization('<org_id>')
949
+ * .then((org) => org.deleteAppDetails('app_definition_id'))
950
+ * .then((result) => console.log(result))
951
+ * .catch(console.error)
952
+ * ```
953
+ */
954
+ deleteAppDetails(appDefinitionId) {
955
+ const raw = this.toPlainObject();
956
+ return makeRequest({
957
+ entityType: 'AppDetails',
958
+ action: 'delete',
959
+ params: { organizationId: raw.sys.id, appDefinitionId },
960
+ }).then(() => {
961
+ /* noop*/
962
+ });
963
+ },
964
+ /**
965
+ * Creates an app action entity.
966
+ * @return Promise that resolves an App Action entity
967
+ * @example ```javascript
968
+ * const contentful = require('contentful-management')
969
+ * const client = contentful.createClient({
970
+ * accessToken: '<content_management_api_key>'
971
+ * })
972
+ *
973
+ * client.getOrganization('<org_id>')
974
+ * .then((org) => org.createAppAction('app_definition_id', {
975
+ * type: 'endpoint',
976
+ * name: 'my nice new app action',
977
+ * url: 'https://www.somewhere.com/action'
978
+ * }))
979
+ * .then((appAction) => console.log(appAction))
980
+ * .catch(console.error)
981
+ * ```
982
+ */
983
+ createAppAction(appDefinitionId, data) {
984
+ const raw = this.toPlainObject();
985
+ return makeRequest({
986
+ entityType: 'AppAction',
987
+ action: 'create',
988
+ params: { organizationId: raw.sys.id, appDefinitionId },
989
+ payload: data,
990
+ }).then((payload) => wrapAppAction(makeRequest, payload));
991
+ },
992
+ /**
993
+ * Updates an existing app action entity.
994
+ * @return Promise that resolves an App Action entity
995
+ * @example ```javascript
996
+ * const contentful = require('contentful-management')
997
+ * const client = contentful.createClient({
998
+ * accessToken: '<content_management_api_key>'
999
+ * })
1000
+ *
1001
+ * client.getOrganization('<org_id>')
1002
+ * .then((org) => org.updateAppAction('app_definition_id', 'app_action_id', {
1003
+ * type: 'endpoint',
1004
+ * name: 'my nice updated app action',
1005
+ * url: 'https://www.somewhere-else.com/action'
1006
+ * }))
1007
+ * .then((appAction) => console.log(appAction))
1008
+ * .catch(console.error)
1009
+ * ```
1010
+ */
1011
+ updateAppAction(appDefinitionId, appActionId, data) {
1012
+ const raw = this.toPlainObject();
1013
+ return makeRequest({
1014
+ entityType: 'AppAction',
1015
+ action: 'update',
1016
+ params: { organizationId: raw.sys.id, appDefinitionId, appActionId },
1017
+ payload: data,
1018
+ }).then((payload) => wrapAppAction(makeRequest, payload));
1019
+ },
1020
+ /**
1021
+ * Deletes an app action entity.
1022
+ * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
1023
+ * @example ```javascript
1024
+ * const contentful = require('contentful-management')
1025
+ * const client = contentful.createClient({
1026
+ * accessToken: '<content_management_api_key>'
1027
+ * })
1028
+ *
1029
+ * client.getOrganization('<org_id>')
1030
+ * .then((org) => org.deleteAppAction('app_definition_id', 'app_action_id'))
1031
+ * .then((result) => console.log(result))
1032
+ * .catch(console.error)
1033
+ * ```
1034
+ */
1035
+ deleteAppAction(appDefinitionId, appActionId) {
1036
+ const raw = this.toPlainObject();
1037
+ return makeRequest({
1038
+ entityType: 'AppAction',
1039
+ action: 'delete',
1040
+ params: { organizationId: raw.sys.id, appDefinitionId, appActionId },
1041
+ }).then(() => {
1042
+ /* noop*/
1043
+ });
1044
+ },
1045
+ /**
1046
+ * Gets an existing app action entity.
1047
+ * @return Promise that resolves an App Action entity
1048
+ * @example ```javascript
1049
+ * const contentful = require('contentful-management')
1050
+ * const client = contentful.createClient({
1051
+ * accessToken: '<content_management_api_key>'
1052
+ * })
1053
+ *
1054
+ * client.getOrganization('<org_id>')
1055
+ * .then((org) => org.getAppAction('app_definition_id', 'app_action_id'))
1056
+ * .then((appAction) => console.log(appAction))
1057
+ * .catch(console.error)
1058
+ * ```
1059
+ */
1060
+ getAppAction(appDefinitionId, appActionId) {
1061
+ const raw = this.toPlainObject();
1062
+ return makeRequest({
1063
+ entityType: 'AppAction',
1064
+ action: 'get',
1065
+ params: { organizationId: raw.sys.id, appDefinitionId, appActionId },
1066
+ }).then((payload) => wrapAppAction(makeRequest, payload));
1067
+ },
1068
+ /**
1069
+ * Gets existing app actions for an App Definition.
1070
+ * @return Promise that resolves an App Action entity
1071
+ * @example ```javascript
1072
+ * const contentful = require('contentful-management')
1073
+ * const client = contentful.createClient({
1074
+ * accessToken: '<content_management_api_key>'
1075
+ * })
1076
+ *
1077
+ * client.getOrganization('<org_id>')
1078
+ * .then((org) => org.getAppActions('app_definition_id'))
1079
+ * .then((appActions) => console.log(appActions))
1080
+ * .catch(console.error)
1081
+ * ```
1082
+ */
1083
+ getAppActions(appDefinitionId) {
1084
+ const raw = this.toPlainObject();
1085
+ return makeRequest({
1086
+ entityType: 'AppAction',
1087
+ action: 'getMany',
1088
+ params: { organizationId: raw.sys.id, appDefinitionId },
1089
+ }).then((payload) => wrapAppActionCollection(makeRequest, payload));
1090
+ },
1091
+ /**
1092
+ * Gets an app function
1093
+ * @param appDefinitionId
1094
+ * @param functionId
1095
+ * @returns Promise for a Function
1096
+ * @example ```javascript
1097
+ * const contentful = require('contentful-management')
1098
+ * const client = contentful.createClient({
1099
+ * accessToken: '<content_management_api_key>'
1100
+ * })
1101
+ * const org = await client.getOrganization('<org_id>')
1102
+ * const functions = await org.getFunction('<app_definition_id>', '<function_id>')
1103
+ */
1104
+ getFunction(appDefinitionId, functionId) {
1105
+ const raw = this.toPlainObject();
1106
+ return makeRequest({
1107
+ entityType: 'Function',
1108
+ action: 'get',
1109
+ params: { organizationId: raw.sys.id, appDefinitionId, functionId },
1110
+ }).then((payload) => wrapFunction(makeRequest, payload));
1111
+ },
1112
+ /**
1113
+ * Gets a collection of app functions.
1114
+ * @param appDefinitionId
1115
+ * @param {import('../common-types').AcceptsQueryOptions} query - optional query parameter for filtering functions by action
1116
+ * @returns Promise for a Function
1117
+ * @example ```javascript
1118
+ * const contentful = require('contentful-management')
1119
+ * const client = contentful.createClient({
1120
+ * accessToken: '<content_management_api_key>'
1121
+ * })
1122
+ * const org = await client.getOrganization('<org_id>')
1123
+ * const functions = await org.getFunctions('<app_definition_id>', { 'accepts[all]': '<action>' })
1124
+ */
1125
+ getFunctions(appDefinitionId, query) {
1126
+ const raw = this.toPlainObject();
1127
+ return makeRequest({
1128
+ entityType: 'Function',
1129
+ action: 'getMany',
1130
+ params: { organizationId: raw.sys.id, appDefinitionId, query },
1131
+ }).then((payload) => wrapFunctionCollection(makeRequest, payload));
1132
+ },
1133
+ };
1134
+ }
1135
+
1136
+ module.exports = createOrganizationApi;