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,2403 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var contentfulSdkCore = require('contentful-sdk-core');
5
+ var index = require('./entities/index.js');
6
+ var releaseAction = require('./entities/release-action.js');
7
+ var release = require('./entities/release.js');
8
+ var tag = require('./entities/tag.js');
9
+ var uiConfig = require('./entities/ui-config.js');
10
+ var userUiConfig = require('./entities/user-ui-config.js');
11
+ var environmentTemplateInstallation = require('./entities/environment-template-installation.js');
12
+ var _function = require('./entities/function.js');
13
+ var functionLog = require('./entities/function-log.js');
14
+ var aiActionInvocation = require('./entities/ai-action-invocation.js');
15
+
16
+ /**
17
+ * Creates API object with methods to access the Environment API
18
+ * @param {ContentfulEnvironmentAPI} makeRequest - function to make requests via an adapter
19
+ * @return {ContentfulSpaceAPI}
20
+ * @private
21
+ */
22
+ function createEnvironmentApi(makeRequest) {
23
+ const { wrapEnvironment } = index.environment;
24
+ const { wrapContentType, wrapContentTypeCollection } = index.contentType;
25
+ const { wrapEntry, wrapEntryCollection } = index.entry;
26
+ const { wrapAsset, wrapAssetCollection } = index.asset;
27
+ const { wrapAssetKey } = index.assetKey;
28
+ const { wrapLocale, wrapLocaleCollection } = index.locale;
29
+ const { wrapSnapshotCollection } = index.snapshot;
30
+ const { wrapEditorInterface, wrapEditorInterfaceCollection } = index.editorInterface;
31
+ const { wrapUpload } = index.upload;
32
+ const { wrapExtension, wrapExtensionCollection } = index.extension;
33
+ const { wrapAppInstallation, wrapAppInstallationCollection } = index.appInstallation;
34
+ const { wrapAppSignedRequest } = index.appSignedRequest;
35
+ const { wrapAppActionCall } = index.appActionCall;
36
+ const { wrapBulkAction } = index.bulkAction;
37
+ const { wrapAppAccessToken } = index.appAccessToken;
38
+ const { wrapResourceTypesForEnvironmentCollection } = index.resourceType;
39
+ const { wrapResourceCollection } = index.resource;
40
+ return {
41
+ /**
42
+ * Deletes the environment
43
+ * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
44
+ * @example ```javascript
45
+ * const contentful = require('contentful-management')
46
+ *
47
+ * const client = contentful.createClient({
48
+ * accessToken: '<content_management_api_key>'
49
+ * })
50
+ *
51
+ * client.getSpace('<space_id>')
52
+ * .then((space) => space.getEnvironment('<environment-id>'))
53
+ * .then((environment) => environment.delete())
54
+ * .then(() => console.log('Environment deleted.'))
55
+ * .catch(console.error)
56
+ * ```
57
+ */
58
+ delete: function deleteEnvironment() {
59
+ const raw = this.toPlainObject();
60
+ return makeRequest({
61
+ entityType: 'Environment',
62
+ action: 'delete',
63
+ params: { spaceId: raw.sys.space.sys.id, environmentId: raw.sys.id },
64
+ }).then(() => {
65
+ // noop
66
+ });
67
+ },
68
+ /**
69
+ * Updates the environment
70
+ * @return Promise for the updated environment.
71
+ * @example ```javascript
72
+ * const contentful = require('contentful-management')
73
+ *
74
+ * const client = contentful.createClient({
75
+ * accessToken: '<content_management_api_key>'
76
+ * })
77
+ *
78
+ * client.getSpace('<space_id>')
79
+ * .then((space) => space.getEnvironment('<environment-id>'))
80
+ * .then((environment) => {
81
+ * environment.name = 'New name'
82
+ * return environment.update()
83
+ * })
84
+ * .then((environment) => console.log(`Environment ${environment.sys.id} renamed.`)
85
+ * .catch(console.error)
86
+ * ```
87
+ */
88
+ update: function updateEnvironment() {
89
+ const raw = this.toPlainObject();
90
+ return makeRequest({
91
+ entityType: 'Environment',
92
+ action: 'update',
93
+ params: { spaceId: raw.sys.space.sys.id, environmentId: raw.sys.id },
94
+ payload: raw,
95
+ }).then((data) => wrapEnvironment(makeRequest, data));
96
+ },
97
+ /**
98
+ * Creates SDK Entry object (locally) from entry data
99
+ * @param entryData - Entry Data
100
+ * @return Entry
101
+ * @example ```javascript
102
+ * environment.getEntry('entryId').then(entry => {
103
+ *
104
+ * // Build a plainObject in order to make it usable for React (saving in state or redux)
105
+ * const plainObject = entry.toPlainObject();
106
+ *
107
+ * // The entry is being updated in some way as plainObject:
108
+ * const updatedPlainObject = {
109
+ * ...plainObject,
110
+ * fields: {
111
+ * ...plainObject.fields,
112
+ * title: {
113
+ * 'en-US': 'updatedTitle'
114
+ * }
115
+ * }
116
+ * };
117
+ *
118
+ * // Rebuild an sdk object out of the updated plainObject:
119
+ * const entryWithMethodsAgain = environment.getEntryFromData(updatedPlainObject);
120
+ *
121
+ * // Update with help of the sdk method:
122
+ * entryWithMethodsAgain.update();
123
+ *
124
+ * });
125
+ * ```
126
+ **/
127
+ getEntryFromData(entryData) {
128
+ return wrapEntry(makeRequest, entryData);
129
+ },
130
+ /**
131
+ * Creates SDK Asset object (locally) from entry data
132
+ * @param assetData - Asset ID
133
+ * @return Asset
134
+ * @example ```javascript
135
+ * environment.getAsset('asset_id').then(asset => {
136
+ *
137
+ * // Build a plainObject in order to make it usable for React (saving in state or redux)
138
+ * const plainObject = asset.toPlainObject();
139
+ *
140
+ * // The asset is being updated in some way as plainObject:
141
+ * const updatedPlainObject = {
142
+ * ...plainObject,
143
+ * fields: {
144
+ * ...plainObject.fields,
145
+ * title: {
146
+ * 'en-US': 'updatedTitle'
147
+ * }
148
+ * }
149
+ * };
150
+ *
151
+ * // Rebuild an sdk object out of the updated plainObject:
152
+ * const assetWithMethodsAgain = environment.getAssetFromData(updatedPlainObject);
153
+ *
154
+ * // Update with help of the sdk method:
155
+ * assetWithMethodsAgain.update();
156
+ *
157
+ * });
158
+ * ```
159
+ */
160
+ getAssetFromData(assetData) {
161
+ return wrapAsset(makeRequest, assetData);
162
+ },
163
+ /**
164
+ *
165
+ * @description Get a BulkAction by ID.
166
+ * See: https://www.contentful.com/developers/docs/references/content-management-api/#/reference/bulk-actions/bulk-action
167
+ * @param bulkActionId - ID of the BulkAction to fetch
168
+ * @returns - Promise with the BulkAction
169
+ *
170
+ * @example ```javascript
171
+ * const contentful = require('contentful-management')
172
+ *
173
+ * const client = contentful.createClient({
174
+ * accessToken: '<content_management_api_key>'
175
+ * })
176
+ *
177
+ * client.getSpace('<space_id>')
178
+ * .then((space) => space.getEnvironment('<environment_id>'))
179
+ * .then((environment) => environment.getBulkAction('<bulk_action_id>'))
180
+ * .then((bulkAction) => console.log(bulkAction))
181
+ * ```
182
+ */
183
+ getBulkAction(bulkActionId) {
184
+ const raw = this.toPlainObject();
185
+ return makeRequest({
186
+ entityType: 'BulkAction',
187
+ action: 'get',
188
+ params: {
189
+ spaceId: raw.sys.space.sys.id,
190
+ environmentId: raw.sys.id,
191
+ bulkActionId,
192
+ },
193
+ }).then((data) => wrapBulkAction(makeRequest, data));
194
+ },
195
+ /**
196
+ * @description Creates a BulkAction that will attempt to publish all items contained in the payload.
197
+ * See: https://www.contentful.com/developers/docs/references/content-management-api/#/reference/bulk-actions/publish-bulk-action
198
+ * @param {BulkActionPayload} payload - Object containing the items to be processed in the bulkAction
199
+ * @returns - Promise with the BulkAction
200
+ *
201
+ * @example
202
+ *
203
+ * ```javascript
204
+ * const contentful = require('contentful-management')
205
+ *
206
+ * const client = contentful.createClient({
207
+ * accessToken: '<content_management_api_key>'
208
+ * })
209
+ *
210
+ * const payload = {
211
+ * entities: {
212
+ * sys: { type: 'Array' }
213
+ * items: [
214
+ * { sys: { type: 'Link', id: '<entry-id>', linkType: 'Entry', version: 2 } }
215
+ * ]
216
+ * }
217
+ * }
218
+ *
219
+ * // Using Thenables
220
+ * client.getSpace('<space_id>')
221
+ * .then((space) => space.getEnvironment('<environment_id>'))
222
+ * .then((environment) => environment.createPublishBulkAction(payload))
223
+ * .then((bulkAction) => console.log(bulkAction.waitProcessing()))
224
+ * .catch(console.error)
225
+ *
226
+ * // Using async/await
227
+ * try {
228
+ * const space = await client.getSpace('<space_id>')
229
+ * const environment = await space.getEnvironment('<environment_id>')
230
+ * const bulkActionInProgress = await environment.createPublishBulkAction(payload)
231
+ *
232
+ * // You can wait for a recently created BulkAction to be processed by using `bulkAction.waitProcessing()`
233
+ * const bulkActionCompleted = await bulkActionInProgress.waitProcessing()
234
+ * console.log(bulkActionCompleted)
235
+ * } catch (error) {
236
+ * console.log(error)
237
+ * }
238
+ * ```
239
+ */
240
+ createPublishBulkAction(payload) {
241
+ const raw = this.toPlainObject();
242
+ return makeRequest({
243
+ entityType: 'BulkAction',
244
+ action: 'publish',
245
+ params: {
246
+ spaceId: raw.sys.space.sys.id,
247
+ environmentId: raw.sys.id,
248
+ },
249
+ payload,
250
+ }).then((data) => wrapBulkAction(makeRequest, data));
251
+ },
252
+ /**
253
+ * @description Creates a BulkAction that will attempt to validate all items contained in the payload.
254
+ * See: https://www.contentful.com/developers/docs/references/content-management-api/#/reference/bulk-actions/validate-bulk-action
255
+ * @param {BulkActionPayload} payload - Object containing the items to be processed in the bulkAction
256
+ * @returns - Promise with the BulkAction
257
+ *
258
+ * @example
259
+ *
260
+ * ```javascript
261
+ * const contentful = require('contentful-management')
262
+ *
263
+ * const client = contentful.createClient({
264
+ * accessToken: '<content_management_api_key>'
265
+ * })
266
+ *
267
+ * const payload = {
268
+ * action: 'publish',
269
+ * entities: {
270
+ * sys: { type: 'Array' }
271
+ * items: [
272
+ * { sys: { type: 'Link', id: '<entry-id>', linkType: 'Entry' } }
273
+ * ]
274
+ * }
275
+ * }
276
+ *
277
+ * // Using Thenables
278
+ * client.getSpace('<space_id>')
279
+ * .then((space) => space.getEnvironment('<environment_id>'))
280
+ * .then((environment) => environment.createValidateBulkAction(payload))
281
+ * .then((bulkAction) => console.log(bulkAction.waitProcessing()))
282
+ * .catch(console.error)
283
+ *
284
+ * // Using async/await
285
+ * try {
286
+ * const space = await client.getSpace('<space_id>')
287
+ * const environment = await space.getEnvironment('<environment_id>')
288
+ * const bulkActionInProgress = await environment.createValidateBulkAction(payload)
289
+ *
290
+ * // You can wait for a recently created BulkAction to be processed by using `bulkAction.waitProcessing()`
291
+ * const bulkActionCompleted = await bulkActionInProgress.waitProcessing()
292
+ * console.log(bulkActionCompleted)
293
+ * } catch (error) {
294
+ * console.log(error)
295
+ * }
296
+ * ```
297
+ */
298
+ createValidateBulkAction(payload) {
299
+ const raw = this.toPlainObject();
300
+ return makeRequest({
301
+ entityType: 'BulkAction',
302
+ action: 'validate',
303
+ params: {
304
+ spaceId: raw.sys.space.sys.id,
305
+ environmentId: raw.sys.id,
306
+ },
307
+ payload,
308
+ }).then((data) => wrapBulkAction(makeRequest, data));
309
+ },
310
+ /**
311
+ * @description Creates a BulkAction that will attempt to unpublish all items contained in the payload.
312
+ * See: https://www.contentful.com/developers/docs/references/content-management-api/#/reference/bulk-actions/unpublish-bulk-action
313
+ * @param {BulkActionPayload} payload - Object containing the items to be processed in the bulkAction
314
+ * @returns - Promise with the BulkAction
315
+ *
316
+ * @example
317
+ *
318
+ * ```javascript
319
+ * const contentful = require('contentful-management')
320
+ *
321
+ * const client = contentful.createClient({
322
+ * accessToken: '<content_management_api_key>'
323
+ * })
324
+ *
325
+ * const payload = {
326
+ * entities: {
327
+ * sys: { type: 'Array' }
328
+ * items: [
329
+ * { sys: { type: 'Link', id: 'entry-id', linkType: 'Entry' } }
330
+ * ]
331
+ * }
332
+ * }
333
+ *
334
+ * // Using Thenables
335
+ * client.getSpace('<space_id>')
336
+ * .then((space) => space.getEnvironment('<environment_id>'))
337
+ * .then((environment) => environment.createUnpublishBulkAction(payload))
338
+ * .then((bulkAction) => console.log(bulkAction.waitProcessing()))
339
+ * .catch(console.error)
340
+ *
341
+ * // Using async/await
342
+ * try {
343
+ * const space = await clientgetSpace('<space_id>')
344
+ * const environment = await space.getEnvironment('<environment_id>')
345
+ * const bulkActionInProgress = await environment.createUnpublishBulkAction(payload)
346
+ *
347
+ * // You can wait for a recently created BulkAction to be processed by using `bulkAction.waitProcessing()`
348
+ * const bulkActionCompleted = await bulkActionInProgress.waitProcessing()
349
+ * console.log(bulkActionCompleted)
350
+ * } catch (error) {
351
+ * console.log(error)
352
+ * }
353
+ * ```
354
+ */
355
+ createUnpublishBulkAction(payload) {
356
+ const raw = this.toPlainObject();
357
+ return makeRequest({
358
+ entityType: 'BulkAction',
359
+ action: 'unpublish',
360
+ params: {
361
+ spaceId: raw.sys.space.sys.id,
362
+ environmentId: raw.sys.id,
363
+ },
364
+ payload,
365
+ }).then((data) => wrapBulkAction(makeRequest, data));
366
+ },
367
+ /**
368
+ * Gets a Content Type
369
+ * @param contentTypeId - Content Type ID
370
+ * @return Promise for a Content Type
371
+ * @example ```javascript
372
+ * const contentful = require('contentful-management')
373
+ *
374
+ * const client = contentful.createClient({
375
+ * accessToken: '<content_management_api_key>'
376
+ * })
377
+ *
378
+ * client.getSpace('<space_id>')
379
+ * .then((space) => space.getEnvironment('<environment-id>'))
380
+ * .then((environment) => environment.getContentType('<content_type_id>'))
381
+ * .then((contentType) => console.log(contentType))
382
+ * .catch(console.error)
383
+ * ```
384
+ */
385
+ getContentType(contentTypeId) {
386
+ const raw = this.toPlainObject();
387
+ return makeRequest({
388
+ entityType: 'ContentType',
389
+ action: 'get',
390
+ params: {
391
+ spaceId: raw.sys.space.sys.id,
392
+ environmentId: raw.sys.id,
393
+ contentTypeId,
394
+ },
395
+ }).then((data) => wrapContentType(makeRequest, data));
396
+ },
397
+ /**
398
+ * Gets a collection of Content Types
399
+ * @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.
400
+ * @return Promise for a collection of Content Types
401
+ * @example ```javascript
402
+ * const contentful = require('contentful-management')
403
+ *
404
+ * const client = contentful.createClient({
405
+ * accessToken: '<content_management_api_key>'
406
+ * })
407
+ *
408
+ * client.getSpace('<space_id>')
409
+ * .then((space) => space.getEnvironment('<environment-id>'))
410
+ * .then((environment) => environment.getContentTypes())
411
+ * .then((response) => console.log(response.items))
412
+ * .catch(console.error)
413
+ * ```
414
+ */
415
+ getContentTypes(query = {}) {
416
+ const raw = this.toPlainObject();
417
+ return makeRequest({
418
+ entityType: 'ContentType',
419
+ action: 'getMany',
420
+ params: {
421
+ spaceId: raw.sys.space.sys.id,
422
+ environmentId: raw.sys.id,
423
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
424
+ },
425
+ }).then((data) => wrapContentTypeCollection(makeRequest, data));
426
+ },
427
+ /**
428
+ * Creates a Content Type
429
+ * @param data - Object representation of the Content Type to be created
430
+ * @return Promise for the newly created Content Type
431
+ * @example ```javascript
432
+ * const contentful = require('contentful-management')
433
+ *
434
+ * const client = contentful.createClient({
435
+ * accessToken: '<content_management_api_key>'
436
+ * })
437
+ *
438
+ * client.getSpace('<space_id>')
439
+ * .then((space) => space.getEnvironment('<environment-id>'))
440
+ * .then((environment) => environment.createContentType({
441
+ * name: 'Blog Post',
442
+ * fields: [
443
+ * {
444
+ * id: 'title',
445
+ * name: 'Title',
446
+ * required: true,
447
+ * localized: false,
448
+ * type: 'Text'
449
+ * }
450
+ * ]
451
+ * }))
452
+ * .then((contentType) => console.log(contentType))
453
+ * .catch(console.error)
454
+ * ```
455
+ */
456
+ createContentType(data) {
457
+ const raw = this.toPlainObject();
458
+ return makeRequest({
459
+ entityType: 'ContentType',
460
+ action: 'create',
461
+ params: {
462
+ spaceId: raw.sys.space.sys.id,
463
+ environmentId: raw.sys.id,
464
+ },
465
+ payload: data,
466
+ }).then((response) => wrapContentType(makeRequest, response));
467
+ },
468
+ /**
469
+ * Creates a Content Type with a custom ID
470
+ * @param contentTypeId - Content Type ID
471
+ * @param data - Object representation of the Content Type to be created
472
+ * @return Promise for the newly created Content Type
473
+ * @example ```javascript
474
+ * const contentful = require('contentful-management')
475
+ *
476
+ * const client = contentful.createClient({
477
+ * accessToken: '<content_management_api_key>'
478
+ * })
479
+ *
480
+ * client.getSpace('<space_id>')
481
+ * .then((space) => space.getEnvironment('<environment-id>'))
482
+ * .then((environment) => environment.createContentTypeWithId('<content-type-id>', {
483
+ * name: 'Blog Post',
484
+ * fields: [
485
+ * {
486
+ * id: 'title',
487
+ * name: 'Title',
488
+ * required: true,
489
+ * localized: false,
490
+ * type: 'Text'
491
+ * }
492
+ * ]
493
+ * }))
494
+ * .then((contentType) => console.log(contentType))
495
+ * .catch(console.error)
496
+ * ```
497
+ */
498
+ createContentTypeWithId(contentTypeId, data) {
499
+ const raw = this.toPlainObject();
500
+ return makeRequest({
501
+ entityType: 'ContentType',
502
+ action: 'createWithId',
503
+ params: {
504
+ spaceId: raw.sys.space.sys.id,
505
+ environmentId: raw.sys.id,
506
+ contentTypeId,
507
+ },
508
+ payload: data,
509
+ }).then((response) => wrapContentType(makeRequest, response));
510
+ },
511
+ /**
512
+ * Gets an EditorInterface for a ContentType
513
+ * @param contentTypeId - Content Type ID
514
+ * @return Promise for an EditorInterface
515
+ * @example ```javascript
516
+ * const contentful = require('contentful-management')
517
+ *
518
+ * const client = contentful.createClient({
519
+ * accessToken: '<content_management_api_key>'
520
+ * })
521
+ *
522
+ * client.getSpace('<space_id>')
523
+ * .then((space) => space.getEnvironment('<environment-id>'))
524
+ * .then((environment) => environment.getEditorInterfaceForContentType('<content_type_id>'))
525
+ * .then((EditorInterface) => console.log(EditorInterface))
526
+ * .catch(console.error)
527
+ * ```
528
+ */
529
+ getEditorInterfaceForContentType(contentTypeId) {
530
+ const raw = this.toPlainObject();
531
+ return makeRequest({
532
+ entityType: 'EditorInterface',
533
+ action: 'get',
534
+ params: {
535
+ spaceId: raw.sys.space.sys.id,
536
+ environmentId: raw.sys.id,
537
+ contentTypeId,
538
+ },
539
+ }).then((response) => wrapEditorInterface(makeRequest, response));
540
+ },
541
+ /**
542
+ * Gets all EditorInterfaces
543
+ * @return Promise for a collection of EditorInterface
544
+ * @example ```javascript
545
+ * const contentful = require('contentful-management')
546
+ *
547
+ * const client = contentful.createClient({
548
+ * accessToken: '<content_management_api_key>'
549
+ * })
550
+ *
551
+ * client.getSpace('<space_id>')
552
+ * .then((space) => space.getEnvironment('<environment-id>'))
553
+ * .then((environment) => environment.getEditorInterfaces())
554
+ * .then((response) => console.log(response.items))
555
+ * .catch(console.error)
556
+ * ```
557
+ */
558
+ getEditorInterfaces() {
559
+ const raw = this.toPlainObject();
560
+ return makeRequest({
561
+ entityType: 'EditorInterface',
562
+ action: 'getMany',
563
+ params: {
564
+ spaceId: raw.sys.space.sys.id,
565
+ environmentId: raw.sys.id,
566
+ },
567
+ }).then((response) => wrapEditorInterfaceCollection(makeRequest, response));
568
+ },
569
+ /**
570
+ * Gets an Entry
571
+ * Warning: if you are using the select operator, when saving, any field that was not selected will be removed
572
+ * from your entry in the backend
573
+ * @param id - Entry ID
574
+ * @param query - Object with search parameters. In this method it's only useful for `locale`.
575
+ * @return Promise for an Entry
576
+ * @example ```javascript
577
+ * const contentful = require('contentful-management')
578
+ *
579
+ * const client = contentful.createClient({
580
+ * accessToken: '<content_management_api_key>'
581
+ * })
582
+ *
583
+ * client.getSpace('<space_id>')
584
+ * .then((space) => space.getEnvironment('<environment-id>'))
585
+ * .then((environment) => environment.getEntry('<entry-id>'))
586
+ * .then((entry) => console.log(entry))
587
+ * .catch(console.error)
588
+ * ```
589
+ */
590
+ getEntry(id, query = {}) {
591
+ const raw = this.toPlainObject();
592
+ return makeRequest({
593
+ entityType: 'Entry',
594
+ action: 'get',
595
+ params: {
596
+ spaceId: raw.sys.space.sys.id,
597
+ environmentId: raw.sys.id,
598
+ entryId: id,
599
+ query: contentfulSdkCore.createRequestConfig({ query: query }).params,
600
+ },
601
+ }).then((data) => wrapEntry(makeRequest, data));
602
+ },
603
+ /**
604
+ * Deletes an Entry of this environment
605
+ * @param id - Entry ID
606
+ * @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
607
+ * @example ```javascript
608
+ * const contentful = require('contentful-management')
609
+ *
610
+ * const client = contentful.createClient({
611
+ * accessToken: '<content_management_api_key>'
612
+ * })
613
+ *
614
+ * client.getSpace('<space_id>')
615
+ * .then((space) => space.getEnvironment('<environment-id>'))
616
+ * .then((environment) => environment.deleteEntry("4bmLXiuviAZH3jkj5DLRWE"))
617
+ * .then(() => console.log('Entry deleted.'))
618
+ * .catch(console.error)
619
+ * ```
620
+ */
621
+ deleteEntry(id) {
622
+ const raw = this.toPlainObject();
623
+ return makeRequest({
624
+ entityType: 'Entry',
625
+ action: 'delete',
626
+ params: {
627
+ spaceId: raw.sys.space.sys.id,
628
+ environmentId: raw.sys.id,
629
+ entryId: id,
630
+ },
631
+ }).then(() => {
632
+ // noop
633
+ });
634
+ },
635
+ /**
636
+ * Gets a collection of Entries
637
+ * Warning: if you are using the select operator, when saving, any field that was not selected will be removed
638
+ * from your entry in the backend
639
+ * @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.
640
+ * @return Promise for a collection of Entries
641
+ * @example ```javascript
642
+ * const contentful = require('contentful-management')
643
+ *
644
+ * const client = contentful.createClient({
645
+ * accessToken: '<content_management_api_key>'
646
+ * })
647
+ *
648
+ * client.getSpace('<space_id>')
649
+ * .then((space) => space.getEnvironment('<environment-id>'))
650
+ * .then((environment) => environment.getEntries({'content_type': 'foo'})) // you can add more queries as 'key': 'value'
651
+ * .then((response) => console.log(response.items))
652
+ * .catch(console.error)
653
+ * ```
654
+ */
655
+ getEntries(query = {}) {
656
+ const raw = this.toPlainObject();
657
+ return makeRequest({
658
+ entityType: 'Entry',
659
+ action: 'getMany',
660
+ params: {
661
+ spaceId: raw.sys.space.sys.id,
662
+ environmentId: raw.sys.id,
663
+ query: contentfulSdkCore.createRequestConfig({ query: query }).params,
664
+ },
665
+ }).then((data) => wrapEntryCollection(makeRequest, data));
666
+ },
667
+ /**
668
+ * Gets a collection of published Entries
669
+ * @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.
670
+ * @return Promise for a collection of published Entries
671
+ * @example ```javascript
672
+ * const contentful = require('contentful-management')
673
+ *
674
+ * const client = contentful.createClient({
675
+ * accessToken: '<content_management_api_key>'
676
+ * })
677
+ *
678
+ * client.getSpace('<space_id>')
679
+ * .then((space) => space.getEnvironment('<environment-id>'))
680
+ * .then((environment) => environment.getPublishedEntries({'content_type': 'foo'})) // you can add more queries as 'key': 'value'
681
+ * .then((response) => console.log(response.items))
682
+ * .catch(console.error)
683
+ * ```
684
+ */
685
+ getPublishedEntries(query = {}) {
686
+ const raw = this.toPlainObject();
687
+ return makeRequest({
688
+ entityType: 'Entry',
689
+ action: 'getPublished',
690
+ params: {
691
+ spaceId: raw.sys.space.sys.id,
692
+ environmentId: raw.sys.id,
693
+ query: contentfulSdkCore.createRequestConfig({ query: query }).params,
694
+ },
695
+ }).then((data) => wrapEntryCollection(makeRequest, data));
696
+ },
697
+ /**
698
+ * Creates a Entry
699
+ * @param contentTypeId - The Content Type ID of the newly created Entry
700
+ * @param data - Object representation of the Entry to be created
701
+ * @return Promise for the newly created Entry
702
+ * @example ```javascript
703
+ * const contentful = require('contentful-management')
704
+ *
705
+ * const client = contentful.createClient({
706
+ * accessToken: '<content_management_api_key>'
707
+ * })
708
+ *
709
+ * client.getSpace('<space_id>')
710
+ * .then((space) => space.getEnvironment('<environment-id>'))
711
+ * .then((environment) => environment.createEntry('<content_type_id>', {
712
+ * fields: {
713
+ * title: {
714
+ * 'en-US': 'Entry title'
715
+ * }
716
+ * }
717
+ * }))
718
+ * .then((entry) => console.log(entry))
719
+ * .catch(console.error)
720
+ * ```
721
+ */
722
+ createEntry(contentTypeId, data) {
723
+ const raw = this.toPlainObject();
724
+ return makeRequest({
725
+ entityType: 'Entry',
726
+ action: 'create',
727
+ params: {
728
+ spaceId: raw.sys.space.sys.id,
729
+ environmentId: raw.sys.id,
730
+ contentTypeId: contentTypeId,
731
+ },
732
+ payload: data,
733
+ }).then((response) => wrapEntry(makeRequest, response));
734
+ },
735
+ /**
736
+ * Creates a Entry with a custom ID
737
+ * @param contentTypeId - The Content Type of the newly created Entry
738
+ * @param id - Entry ID
739
+ * @param data - Object representation of the Entry to be created
740
+ * @return Promise for the newly created Entry
741
+ * @example ```javascript
742
+ * const contentful = require('contentful-management')
743
+ *
744
+ * const client = contentful.createClient({
745
+ * accessToken: '<content_management_api_key>'
746
+ * })
747
+ *
748
+ * // Create entry
749
+ * client.getSpace('<space_id>')
750
+ * .then((space) => space.getEnvironment('<environment-id>'))
751
+ * .then((environment) => environment.createEntryWithId('<content_type_id>', '<entry_id>', {
752
+ * fields: {
753
+ * title: {
754
+ * 'en-US': 'Entry title'
755
+ * }
756
+ * }
757
+ * }))
758
+ * .then((entry) => console.log(entry))
759
+ * .catch(console.error)
760
+ * ```
761
+ */
762
+ createEntryWithId(contentTypeId, id, data) {
763
+ const raw = this.toPlainObject();
764
+ return makeRequest({
765
+ entityType: 'Entry',
766
+ action: 'createWithId',
767
+ params: {
768
+ spaceId: raw.sys.space.sys.id,
769
+ environmentId: raw.sys.id,
770
+ entryId: id,
771
+ contentTypeId: contentTypeId,
772
+ },
773
+ payload: data,
774
+ }).then((response) => wrapEntry(makeRequest, response));
775
+ },
776
+ /**
777
+ * Get entry references
778
+ * @param entryId - Entry ID
779
+ * @param {Object} options.include - Level of the entry descendants from 1 up to 10 maximum
780
+ * @returns Promise of Entry references
781
+ * @example ```javascript
782
+ * const contentful = require('contentful-management');
783
+ *
784
+ * const client = contentful.createClient({
785
+ * accessToken: '<contentful_management_api_key>
786
+ * })
787
+ *
788
+ * // Get entry references
789
+ * client.getSpace('<space_id>')
790
+ * .then((space) => space.getEnvironment('<environment_id>'))
791
+ * .then((environment) => environment.getEntryReferences('<entry_id>', {include: number}))
792
+ * .then((entry) => console.log(entry.includes))
793
+ * // or
794
+ * .then((environment) => environment.getEntry('<entry_id>')).then((entry) => entry.references({include: number}))
795
+ * .catch(console.error)
796
+ * ```
797
+ */
798
+ getEntryReferences(entryId, options) {
799
+ const raw = this.toPlainObject();
800
+ return makeRequest({
801
+ entityType: 'Entry',
802
+ action: 'references',
803
+ params: {
804
+ spaceId: raw.sys.space.sys.id,
805
+ environmentId: raw.sys.id,
806
+ entryId: entryId,
807
+ include: options === null || options === void 0 ? void 0 : options.include,
808
+ },
809
+ }).then((response) => wrapEntryCollection(makeRequest, response));
810
+ },
811
+ /**
812
+ * Gets an Asset
813
+ * Warning: if you are using the select operator, when saving, any field that was not selected will be removed
814
+ * from your entry in the backend
815
+ * @param id - Asset ID
816
+ * @param query - Object with search parameters. In this method it's only useful for `locale`.
817
+ * @return Promise for an Asset
818
+ * @example ```javascript
819
+ * const contentful = require('contentful-management')
820
+ *
821
+ * const client = contentful.createClient({
822
+ * accessToken: '<content_management_api_key>'
823
+ * })
824
+ *
825
+ * client.getSpace('<space_id>')
826
+ * .then((space) => space.getEnvironment('<environment-id>'))
827
+ * .then((environment) => environment.getAsset('<asset_id>'))
828
+ * .then((asset) => console.log(asset))
829
+ * .catch(console.error)
830
+ * ```
831
+ */
832
+ getAsset(id, query = {}) {
833
+ const raw = this.toPlainObject();
834
+ return makeRequest({
835
+ entityType: 'Asset',
836
+ action: 'get',
837
+ params: {
838
+ spaceId: raw.sys.space.sys.id,
839
+ environmentId: raw.sys.id,
840
+ assetId: id,
841
+ query: contentfulSdkCore.createRequestConfig({ query: query }).params,
842
+ },
843
+ }).then((data) => wrapAsset(makeRequest, data));
844
+ },
845
+ /**
846
+ * Gets a collection of Assets
847
+ * Warning: if you are using the select operator, when saving, any field that was not selected will be removed
848
+ * from your entry in the backend
849
+ * @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.
850
+ * @return Promise for a collection of Assets
851
+ * @example ```javascript
852
+ * const contentful = require('contentful-management')
853
+ *
854
+ * const client = contentful.createClient({
855
+ * accessToken: '<content_management_api_key>'
856
+ * })
857
+ *
858
+ * client.getSpace('<space_id>')
859
+ * .then((space) => space.getEnvironment('<environment-id>'))
860
+ * .then((environment) => environment.getAssets())
861
+ * .then((response) => console.log(response.items))
862
+ * .catch(console.error)
863
+ * ```
864
+ */
865
+ getAssets(query = {}) {
866
+ const raw = this.toPlainObject();
867
+ return makeRequest({
868
+ entityType: 'Asset',
869
+ action: 'getMany',
870
+ params: {
871
+ spaceId: raw.sys.space.sys.id,
872
+ environmentId: raw.sys.id,
873
+ query: contentfulSdkCore.createRequestConfig({ query: query }).params,
874
+ },
875
+ }).then((data) => wrapAssetCollection(makeRequest, data));
876
+ },
877
+ /**
878
+ * Gets a collection of published Assets
879
+ * @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.
880
+ * @return Promise for a collection of published Assets
881
+ * @example ```javascript
882
+ * const contentful = require('contentful-management')
883
+ *
884
+ * const client = contentful.createClient({
885
+ * accessToken: '<content_management_api_key>'
886
+ * })
887
+ *
888
+ * client.getSpace('<space_id>')
889
+ * .then((space) => space.getEnvironment('<environment-id>'))
890
+ * .then((environment) => environment.getPublishedAssets())
891
+ * .then((response) => console.log(response.items))
892
+ * .catch(console.error)
893
+ * ```
894
+ */
895
+ getPublishedAssets(query = {}) {
896
+ const raw = this.toPlainObject();
897
+ return makeRequest({
898
+ entityType: 'Asset',
899
+ action: 'getPublished',
900
+ params: {
901
+ spaceId: raw.sys.space.sys.id,
902
+ environmentId: raw.sys.id,
903
+ query: contentfulSdkCore.createRequestConfig({ query: query }).params,
904
+ },
905
+ }).then((data) => wrapAssetCollection(makeRequest, data));
906
+ },
907
+ /**
908
+ * Creates a Asset. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
909
+ * @param data - Object representation of the Asset to be created. Note that the field object should have an upload property on asset creation, which will be removed and replaced with an url property when processing is finished.
910
+ * @return Promise for the newly created Asset
911
+ * @example ```javascript
912
+ * const client = contentful.createClient({
913
+ * accessToken: '<content_management_api_key>'
914
+ * })
915
+ *
916
+ * // Create asset
917
+ * client.getSpace('<space_id>')
918
+ * .then((space) => space.getEnvironment('<environment-id>'))
919
+ * .then((environment) => environment.createAsset({
920
+ * fields: {
921
+ * title: {
922
+ * 'en-US': 'Playsam Streamliner'
923
+ * },
924
+ * file: {
925
+ * 'en-US': {
926
+ * contentType: 'image/jpeg',
927
+ * fileName: 'example.jpeg',
928
+ * upload: 'https://example.com/example.jpg'
929
+ * }
930
+ * }
931
+ * }
932
+ * }))
933
+ * .then((asset) => asset.processForLocale("en-US")) // OR asset.processForAllLocales()
934
+ * .then((asset) => console.log(asset))
935
+ * .catch(console.error)
936
+ * ```
937
+ */
938
+ createAsset(data) {
939
+ const raw = this.toPlainObject();
940
+ return makeRequest({
941
+ entityType: 'Asset',
942
+ action: 'create',
943
+ params: {
944
+ spaceId: raw.sys.space.sys.id,
945
+ environmentId: raw.sys.id,
946
+ },
947
+ payload: data,
948
+ }).then((response) => wrapAsset(makeRequest, response));
949
+ },
950
+ /**
951
+ * Creates a Asset with a custom ID. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
952
+ * @param id - Asset ID
953
+ * @param data - Object representation of the Asset to be created. Note that the field object should have an upload property on asset creation, which will be removed and replaced with an url property when processing is finished.
954
+ * @return Promise for the newly created Asset
955
+ * @example ```javascript
956
+ * const client = contentful.createClient({
957
+ * accessToken: '<content_management_api_key>'
958
+ * })
959
+ *
960
+ * // Create asset
961
+ * client.getSpace('<space_id>')
962
+ * .then((space) => space.getEnvironment('<environment-id>'))
963
+ * .then((environment) => environment.createAssetWithId('<asset_id>', {
964
+ * title: {
965
+ * 'en-US': 'Playsam Streamliner'
966
+ * },
967
+ * file: {
968
+ * 'en-US': {
969
+ * contentType: 'image/jpeg',
970
+ * fileName: 'example.jpeg',
971
+ * upload: 'https://example.com/example.jpg'
972
+ * }
973
+ * }
974
+ * }))
975
+ * .then((asset) => asset.process())
976
+ * .then((asset) => console.log(asset))
977
+ * .catch(console.error)
978
+ * ```
979
+ */
980
+ createAssetWithId(id, data) {
981
+ const raw = this.toPlainObject();
982
+ return makeRequest({
983
+ entityType: 'Asset',
984
+ action: 'createWithId',
985
+ params: {
986
+ spaceId: raw.sys.space.sys.id,
987
+ environmentId: raw.sys.id,
988
+ assetId: id,
989
+ },
990
+ payload: data,
991
+ }).then((response) => wrapAsset(makeRequest, response));
992
+ },
993
+ /**
994
+ * Creates a Asset based on files. After creation, call asset.processForLocale or asset.processForAllLocales to start asset processing.
995
+ * @param data - Object representation of the Asset to be created. Note that the field object should have an uploadFrom property on asset creation, which will be removed and replaced with an url property when processing is finished.
996
+ * @param data.fields.file.[LOCALE].file - Can be a string, an ArrayBuffer or a Stream.
997
+ * @return Promise for the newly created Asset
998
+ * @example ```javascript
999
+ * const client = contentful.createClient({
1000
+ * accessToken: '<content_management_api_key>'
1001
+ * })
1002
+ *
1003
+ * client.getSpace('<space_id>')
1004
+ * .then((space) => space.getEnvironment('<environment-id>'))
1005
+ * .then((environment) => environment.createAssetFromFiles({
1006
+ * fields: {
1007
+ * file: {
1008
+ * 'en-US': {
1009
+ * contentType: 'image/jpeg',
1010
+ * fileName: 'filename_english.jpg',
1011
+ * file: createReadStream('path/to/filename_english.jpg')
1012
+ * },
1013
+ * 'de-DE': {
1014
+ * contentType: 'image/svg+xml',
1015
+ * fileName: 'filename_german.svg',
1016
+ * file: '<svg><path fill="red" d="M50 50h150v50H50z"/></svg>'
1017
+ * }
1018
+ * }
1019
+ * }
1020
+ * }))
1021
+ * .then((asset) => console.log(asset))
1022
+ * .catch(console.error)
1023
+ * ```
1024
+ */
1025
+ createAssetFromFiles(data, options) {
1026
+ const raw = this.toPlainObject();
1027
+ return makeRequest({
1028
+ entityType: 'Asset',
1029
+ action: 'createFromFiles',
1030
+ params: {
1031
+ spaceId: raw.sys.space.sys.id,
1032
+ environmentId: raw.sys.id,
1033
+ uploadTimeout: options === null || options === void 0 ? void 0 : options.uploadTimeout,
1034
+ },
1035
+ payload: data,
1036
+ }).then((response) => wrapAsset(makeRequest, response));
1037
+ },
1038
+ /**
1039
+ * Creates an asset key for signing asset URLs (Embargoed Assets)
1040
+ * @param data Object with request payload
1041
+ * @param data.expiresAt number a UNIX timestamp in the future (but not more than 48 hours from time of calling)
1042
+ * @return Promise for the newly created AssetKey
1043
+ * @example ```javascript
1044
+ * const client = contentful.createClient({
1045
+ * accessToken: '<content_management_api_key>'
1046
+ * })
1047
+ *
1048
+ * // Create assetKey
1049
+ * now = () => Math.floor(Date.now() / 1000)
1050
+ * const withExpiryIn1Hour = () => now() + 1 * 60 * 60
1051
+ * client.getSpace('<space_id>')
1052
+ * .then((space) => space.getEnvironment('<environment-id>'))
1053
+ * .then((environment) => environment.createAssetKey({ expiresAt: withExpiryIn1Hour() }))
1054
+ * .then((policy, secret) => console.log({ policy, secret }))
1055
+ * .catch(console.error)
1056
+ * ```
1057
+ */
1058
+ createAssetKey(payload) {
1059
+ const raw = this.toPlainObject();
1060
+ return makeRequest({
1061
+ entityType: 'AssetKey',
1062
+ action: 'create',
1063
+ params: {
1064
+ spaceId: raw.sys.space.sys.id,
1065
+ environmentId: raw.sys.id,
1066
+ },
1067
+ payload,
1068
+ }).then((data) => wrapAssetKey(makeRequest, data));
1069
+ },
1070
+ /**
1071
+ * Gets an Upload
1072
+ * @param id - Upload ID
1073
+ * @return Promise for an Upload
1074
+ * @example ```javascript
1075
+ * const client = contentful.createClient({
1076
+ * accessToken: '<content_management_api_key>'
1077
+ * })
1078
+ * const uploadStream = createReadStream('path/to/filename_english.jpg')
1079
+ *
1080
+ * client.getSpace('<space_id>')
1081
+ * .then((space) => space.getEnvironment('<environment-id>'))
1082
+ * .then((environment) => environment.getUpload('<upload-id>')
1083
+ * .then((upload) => console.log(upload))
1084
+ * .catch(console.error)
1085
+ */
1086
+ getUpload(id) {
1087
+ const raw = this.toPlainObject();
1088
+ return makeRequest({
1089
+ entityType: 'Upload',
1090
+ action: 'get',
1091
+ params: {
1092
+ spaceId: raw.sys.space.sys.id,
1093
+ environmentId: raw.sys.id,
1094
+ uploadId: id,
1095
+ },
1096
+ }).then((data) => wrapUpload(makeRequest, data));
1097
+ },
1098
+ /**
1099
+ * Creates a Upload.
1100
+ * @param data - Object with file information.
1101
+ * @param data.file - Actual file content. Can be a string, an ArrayBuffer or a Stream.
1102
+ * @return Upload object containing information about the uploaded file.
1103
+ * @example ```javascript
1104
+ * const client = contentful.createClient({
1105
+ * accessToken: '<content_management_api_key>'
1106
+ * })
1107
+ * const uploadStream = createReadStream('path/to/filename_english.jpg')
1108
+ *
1109
+ * client.getSpace('<space_id>')
1110
+ * .then((space) => space.getEnvironment('<environment-id>'))
1111
+ * .then((environment) => environment.createUpload({file: uploadStream})
1112
+ * .then((upload) => console.log(upload))
1113
+ * .catch(console.error)
1114
+ * ```
1115
+ */
1116
+ createUpload: function createUpload(data) {
1117
+ const raw = this.toPlainObject();
1118
+ return makeRequest({
1119
+ entityType: 'Upload',
1120
+ action: 'create',
1121
+ params: {
1122
+ spaceId: raw.sys.space.sys.id,
1123
+ environmentId: raw.sys.id,
1124
+ },
1125
+ payload: data,
1126
+ }).then((data) => wrapUpload(makeRequest, data));
1127
+ },
1128
+ /**
1129
+ * Gets a Locale
1130
+ * @param localeId - Locale ID
1131
+ * @return Promise for an Locale
1132
+ * @example ```javascript
1133
+ * const contentful = require('contentful-management')
1134
+ *
1135
+ * const client = contentful.createClient({
1136
+ * accessToken: '<content_management_api_key>'
1137
+ * })
1138
+ *
1139
+ * client.getSpace('<space_id>')
1140
+ * .then((space) => space.getEnvironment('<environment-id>'))
1141
+ * .then((environment) => environment.getLocale('<locale_id>'))
1142
+ * .then((locale) => console.log(locale))
1143
+ * .catch(console.error)
1144
+ * ```
1145
+ */
1146
+ getLocale(localeId) {
1147
+ const raw = this.toPlainObject();
1148
+ return makeRequest({
1149
+ entityType: 'Locale',
1150
+ action: 'get',
1151
+ params: {
1152
+ spaceId: raw.sys.space.sys.id,
1153
+ environmentId: raw.sys.id,
1154
+ localeId,
1155
+ },
1156
+ }).then((data) => wrapLocale(makeRequest, data));
1157
+ },
1158
+ /**
1159
+ * Gets a collection of Locales
1160
+ * @return Promise for a collection of Locales
1161
+ * @example ```javascript
1162
+ * const contentful = require('contentful-management')
1163
+ *
1164
+ * const client = contentful.createClient({
1165
+ * accessToken: '<content_management_api_key>'
1166
+ * })
1167
+ *
1168
+ * client.getSpace('<space_id>')
1169
+ * .then((space) => space.getEnvironment('<environment-id>'))
1170
+ * .then((environment) => environment.getLocales())
1171
+ * .then((response) => console.log(response.items))
1172
+ * .catch(console.error)
1173
+ * ```
1174
+ */
1175
+ getLocales(query = {}) {
1176
+ const raw = this.toPlainObject();
1177
+ return makeRequest({
1178
+ entityType: 'Locale',
1179
+ action: 'getMany',
1180
+ params: {
1181
+ spaceId: raw.sys.space.sys.id,
1182
+ environmentId: raw.sys.id,
1183
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
1184
+ },
1185
+ }).then((data) => wrapLocaleCollection(makeRequest, data));
1186
+ },
1187
+ /**
1188
+ * Creates a Locale
1189
+ * @param data - Object representation of the Locale to be created
1190
+ * @return Promise for the newly created Locale
1191
+ * @example ```javascript
1192
+ * const contentful = require('contentful-management')
1193
+ *
1194
+ * const client = contentful.createClient({
1195
+ * accessToken: '<content_management_api_key>'
1196
+ * })
1197
+ *
1198
+ * // Create locale
1199
+ * client.getSpace('<space_id>')
1200
+ * .then((space) => space.getEnvironment('<environment-id>'))
1201
+ * .then((environment) => environment.createLocale({
1202
+ * name: 'German (Austria)',
1203
+ * code: 'de-AT',
1204
+ * fallbackCode: 'de-DE',
1205
+ * optional: true
1206
+ * }))
1207
+ * .then((locale) => console.log(locale))
1208
+ * .catch(console.error)
1209
+ * ```
1210
+ */
1211
+ createLocale(data) {
1212
+ const raw = this.toPlainObject();
1213
+ return makeRequest({
1214
+ entityType: 'Locale',
1215
+ action: 'create',
1216
+ params: {
1217
+ spaceId: raw.sys.space.sys.id,
1218
+ environmentId: raw.sys.id,
1219
+ },
1220
+ payload: data,
1221
+ }).then((response) => wrapLocale(makeRequest, response));
1222
+ },
1223
+ /**
1224
+ * Gets an UI Extension
1225
+ * @param id - Extension ID
1226
+ * @return Promise for an UI Extension
1227
+ * @example ```javascript
1228
+ * const contentful = require('contentful-management')
1229
+ *
1230
+ * const client = contentful.createClient({
1231
+ * accessToken: '<content_management_api_key>'
1232
+ * })
1233
+ *
1234
+ * client.getSpace('<space_id>')
1235
+ * .then((space) => space.getEnvironment('<environment-id>'))
1236
+ * .then((environment) => environment.getUiExtension('<extension-id>'))
1237
+ * .then((extension) => console.log(extension))
1238
+ * .catch(console.error)
1239
+ * ```
1240
+ */
1241
+ getUiExtension(id) {
1242
+ const raw = this.toPlainObject();
1243
+ return makeRequest({
1244
+ entityType: 'Extension',
1245
+ action: 'get',
1246
+ params: {
1247
+ spaceId: raw.sys.space.sys.id,
1248
+ environmentId: raw.sys.id,
1249
+ extensionId: id,
1250
+ },
1251
+ }).then((data) => wrapExtension(makeRequest, data));
1252
+ },
1253
+ /**
1254
+ * Gets a collection of UI Extension
1255
+ * @return Promise for a collection of UI Extensions
1256
+ * @example ```javascript
1257
+ * const contentful = require('contentful-management')
1258
+ *
1259
+ * const client = contentful.createClient({
1260
+ * accessToken: '<content_management_api_key>'
1261
+ * })
1262
+ *
1263
+ * client.getSpace('<space_id>')
1264
+ * .then((space) => space.getEnvironment('<environment-id>'))
1265
+ * .then((environment) => environment.getUiExtensions()
1266
+ * .then((response) => console.log(response.items))
1267
+ * .catch(console.error)
1268
+ * ```
1269
+ */
1270
+ getUiExtensions() {
1271
+ const raw = this.toPlainObject();
1272
+ return makeRequest({
1273
+ entityType: 'Extension',
1274
+ action: 'getMany',
1275
+ params: {
1276
+ spaceId: raw.sys.space.sys.id,
1277
+ environmentId: raw.sys.id,
1278
+ },
1279
+ }).then((response) => wrapExtensionCollection(makeRequest, response));
1280
+ },
1281
+ /**
1282
+ * Creates a UI Extension
1283
+ * @param data - Object representation of the UI Extension to be created
1284
+ * @return Promise for the newly created UI Extension
1285
+ * @example ```javascript
1286
+ * const contentful = require('contentful-management')
1287
+ *
1288
+ * const client = contentful.createClient({
1289
+ * accessToken: '<content_management_api_key>'
1290
+ * })
1291
+ *
1292
+ * client.getSpace('<space_id>')
1293
+ * .then((space) => space.getEnvironment('<environment-id>'))
1294
+ * .then((environment) => environment.createUiExtension({
1295
+ * extension: {
1296
+ * name: 'My awesome extension',
1297
+ * src: 'https://example.com/my',
1298
+ * fieldTypes: [
1299
+ * {
1300
+ * type: 'Symbol'
1301
+ * },
1302
+ * {
1303
+ * type: 'Text'
1304
+ * }
1305
+ * ],
1306
+ * sidebar: false
1307
+ * }
1308
+ * }))
1309
+ * .then((extension) => console.log(extension))
1310
+ * .catch(console.error)
1311
+ * ```
1312
+ */
1313
+ createUiExtension(data) {
1314
+ const raw = this.toPlainObject();
1315
+ return makeRequest({
1316
+ entityType: 'Extension',
1317
+ action: 'create',
1318
+ params: {
1319
+ spaceId: raw.sys.space.sys.id,
1320
+ environmentId: raw.sys.id,
1321
+ },
1322
+ payload: data,
1323
+ }).then((response) => wrapExtension(makeRequest, response));
1324
+ },
1325
+ /**
1326
+ * Creates a UI Extension with a custom ID
1327
+ * @param id - Extension ID
1328
+ * @param data - Object representation of the UI Extension to be created
1329
+ * @return Promise for the newly created UI Extension
1330
+ * @example ```javascript
1331
+ * const contentful = require('contentful-management')
1332
+ *
1333
+ * const client = contentful.createClient({
1334
+ * accessToken: '<content_management_api_key>'
1335
+ * })
1336
+ *
1337
+ * client.getSpace('<space_id>')
1338
+ * .then((space) => space.getEnvironment('<environment-id>'))
1339
+ * .then((environment) => environment.createUiExtensionWithId('<extension_id>', {
1340
+ * extension: {
1341
+ * name: 'My awesome extension',
1342
+ * src: 'https://example.com/my',
1343
+ * fieldTypes: [
1344
+ * {
1345
+ * type: 'Symbol'
1346
+ * },
1347
+ * {
1348
+ * type: 'Text'
1349
+ * }
1350
+ * ],
1351
+ * sidebar: false
1352
+ * }
1353
+ * }))
1354
+ * .then((extension) => console.log(extension))
1355
+ * .catch(console.error)
1356
+ * ```
1357
+ */
1358
+ createUiExtensionWithId(id, data) {
1359
+ const raw = this.toPlainObject();
1360
+ return makeRequest({
1361
+ entityType: 'Extension',
1362
+ action: 'createWithId',
1363
+ params: {
1364
+ spaceId: raw.sys.space.sys.id,
1365
+ environmentId: raw.sys.id,
1366
+ extensionId: id,
1367
+ },
1368
+ payload: data,
1369
+ }).then((response) => wrapExtension(makeRequest, response));
1370
+ },
1371
+ /**
1372
+ * Creates an App Installation
1373
+ * @param appDefinitionId - AppDefinition ID
1374
+ * @param data - AppInstallation data
1375
+ * @param options.acceptAllTerms - Flag for accepting Apps' Marketplace EULA, Terms, and Privacy policy (need to pass `{acceptAllTerms: true}` to install a marketplace app)
1376
+ * @return Promise for an App Installation
1377
+ * @example ```javascript
1378
+ * const contentful = require('contentful-management')
1379
+ *
1380
+ * const client = contentful.createClient({
1381
+ * accessToken: '<content_management_api_key>'
1382
+ * })
1383
+ *
1384
+ * client.getSpace('<space_id>')
1385
+ * .then((space) => space.getEnvironment('<environment-id>'))
1386
+ * .then((environment) => environment.createAppInstallation('<app_definition_id>', {
1387
+ * parameters: {
1388
+ * someParameter: someValue
1389
+ * }
1390
+ * })
1391
+ * .then((appInstallation) => console.log(appInstallation))
1392
+ * .catch(console.error)
1393
+ * ```
1394
+ */
1395
+ createAppInstallation(appDefinitionId, data, { acceptAllTerms } = {}) {
1396
+ const raw = this.toPlainObject();
1397
+ return makeRequest({
1398
+ entityType: 'AppInstallation',
1399
+ action: 'upsert',
1400
+ params: {
1401
+ spaceId: raw.sys.space.sys.id,
1402
+ environmentId: raw.sys.id,
1403
+ appDefinitionId,
1404
+ acceptAllTerms,
1405
+ },
1406
+ payload: data,
1407
+ }).then((payload) => wrapAppInstallation(makeRequest, payload));
1408
+ },
1409
+ /**
1410
+ * Gets an App Installation
1411
+ * @param id - AppDefintion ID
1412
+ * @return Promise for an App Installation
1413
+ * @example ```javascript
1414
+ * const contentful = require('contentful-management')
1415
+ *
1416
+ * const client = contentful.createClient({
1417
+ * accessToken: '<content_management_api_key>'
1418
+ * })
1419
+ *
1420
+ * client.getSpace('<space_id>')
1421
+ * .then((space) => space.getEnvironment('<environment-id>'))
1422
+ * .then((environment) => environment.getAppInstallation('<app-definition-id>'))
1423
+ * .then((appInstallation) => console.log(appInstallation))
1424
+ * .catch(console.error)
1425
+ * ```
1426
+ */
1427
+ getAppInstallation(id) {
1428
+ const raw = this.toPlainObject();
1429
+ return makeRequest({
1430
+ entityType: 'AppInstallation',
1431
+ action: 'get',
1432
+ params: {
1433
+ spaceId: raw.sys.space.sys.id,
1434
+ environmentId: raw.sys.id,
1435
+ appDefinitionId: id,
1436
+ },
1437
+ }).then((data) => wrapAppInstallation(makeRequest, data));
1438
+ },
1439
+ /**
1440
+ * Gets a collection of App Installation
1441
+ * @return Promise for a collection of App Installations
1442
+ * @example ```javascript
1443
+ * const contentful = require('contentful-management')
1444
+ *
1445
+ * const client = contentful.createClient({
1446
+ * accessToken: '<content_management_api_key>'
1447
+ * })
1448
+ *
1449
+ * client.getSpace('<space_id>')
1450
+ * .then((space) => space.getEnvironment('<environment-id>'))
1451
+ * .then((environment) => environment.getAppInstallations()
1452
+ * .then((response) => console.log(response.items))
1453
+ * .catch(console.error)
1454
+ * ```
1455
+ */
1456
+ getAppInstallations() {
1457
+ const raw = this.toPlainObject();
1458
+ return makeRequest({
1459
+ entityType: 'AppInstallation',
1460
+ action: 'getMany',
1461
+ params: {
1462
+ spaceId: raw.sys.space.sys.id,
1463
+ environmentId: raw.sys.id,
1464
+ },
1465
+ }).then((data) => wrapAppInstallationCollection(makeRequest, data));
1466
+ },
1467
+ /**
1468
+ * Creates an app action call
1469
+ * @param appDefinitionId - AppDefinition ID
1470
+ * @param appActionId - action ID
1471
+ * @param data - App Action Call data
1472
+ * @return Promise for an App Action Call
1473
+ * @example ```javascript
1474
+ * const contentful = require('contentful-management')
1475
+ *
1476
+ * const client = contentful.createClient({
1477
+ * accessToken: '<content_management_api_key>'
1478
+ * })
1479
+ *
1480
+ * const data = {
1481
+ * headers: {
1482
+ * 'x-my-header': 'some-value'
1483
+ * },
1484
+ * body: {
1485
+ * 'some-body-value': true
1486
+ * }
1487
+ * }
1488
+ *
1489
+ * client.getSpace('<space_id>')
1490
+ * .then((space) => space.getEnvironment('<environment-id>'))
1491
+ * .then((environment) => environment.createAppActionCall('<app_definition_id>', '<action_id>', data)
1492
+ * .then((appActionCall) => console.log(appActionCall))
1493
+ * .catch(console.error)
1494
+ * ```
1495
+ */
1496
+ createAppActionCall(appDefinitionId, appActionId, data) {
1497
+ const raw = this.toPlainObject();
1498
+ return makeRequest({
1499
+ entityType: 'AppActionCall',
1500
+ action: 'create',
1501
+ params: {
1502
+ spaceId: raw.sys.space.sys.id,
1503
+ environmentId: raw.sys.id,
1504
+ appDefinitionId,
1505
+ appActionId,
1506
+ },
1507
+ payload: data,
1508
+ }).then((payload) => wrapAppActionCall(makeRequest, payload));
1509
+ },
1510
+ /**
1511
+ * Creates an app signed request
1512
+ * @param appDefinitionId - AppDefinition ID
1513
+ * @param data - SignedRequest data
1514
+ * @return Promise for a Signed Request
1515
+ * @example ```javascript
1516
+ * const contentful = require('contentful-management')
1517
+ *
1518
+ * const client = contentful.createClient({
1519
+ * accessToken: '<content_management_api_key>'
1520
+ * })
1521
+ *
1522
+ * const data = {
1523
+ * method: 'POST',
1524
+ * path: '/request_path',
1525
+ * body: '{ "key": "data" }',
1526
+ * headers: {
1527
+ * 'x-my-header': 'some-value'
1528
+ * },
1529
+ * }
1530
+ *
1531
+ * client.getSpace('<space_id>')
1532
+ * .then((space) => space.getEnvironment('<environment-id>'))
1533
+ * .then((environment) => environment.createAppSignedRequest('<app_definition_id>', data)
1534
+ * .then((signedRequest) => console.log(signedRequest))
1535
+ * .catch(console.error)
1536
+ * ```
1537
+ */
1538
+ createAppSignedRequest(appDefinitionId, data) {
1539
+ const raw = this.toPlainObject();
1540
+ return makeRequest({
1541
+ entityType: 'AppSignedRequest',
1542
+ action: 'create',
1543
+ params: {
1544
+ spaceId: raw.sys.space.sys.id,
1545
+ environmentId: raw.sys.id,
1546
+ appDefinitionId,
1547
+ },
1548
+ payload: data,
1549
+ }).then((payload) => wrapAppSignedRequest(makeRequest, payload));
1550
+ },
1551
+ /**
1552
+ * Creates an app access token
1553
+ * @param appDefinitionId - AppDefinition ID
1554
+ * @param data - Json Web Token
1555
+ * @return Promise for an app access token
1556
+ * @example ```javascript
1557
+ * const contentful = require('contentful-management')
1558
+ * const { sign } = require('jsonwebtoken')
1559
+ *
1560
+ * const signOptions = { algorithm: 'RS256', issuer: '<app_definition_id>', expiresIn: '10m' }
1561
+ *
1562
+ * const client = contentful.createClient({
1563
+ * accessToken: '<content_management_api_key>'
1564
+ * })
1565
+ *
1566
+ * const data = {
1567
+ * jwt: sign({}, '<private_key>', signOptions)
1568
+ * }
1569
+ *
1570
+ * client.getSpace('<space_id>')
1571
+ * .then((space) => space.getEnvironment('<environment-id>'))
1572
+ * .then((environment) => environment.createAppAccessToken('<app_definition_id>', data)
1573
+ * .then((appAccessToken) => console.log(appAccessToken))
1574
+ * .catch(console.error)
1575
+ * ```
1576
+ */
1577
+ createAppAccessToken(appDefinitionId, data) {
1578
+ const raw = this.toPlainObject();
1579
+ return makeRequest({
1580
+ entityType: 'AppAccessToken',
1581
+ action: 'create',
1582
+ params: {
1583
+ spaceId: raw.sys.space.sys.id,
1584
+ environmentId: raw.sys.id,
1585
+ appDefinitionId,
1586
+ },
1587
+ payload: data,
1588
+ }).then((payload) => wrapAppAccessToken(makeRequest, payload));
1589
+ },
1590
+ /**
1591
+ * Gets a collection of Functions for a given environment
1592
+ * @param appInstallationId
1593
+ * @param {import('../common-types').AcceptsQueryOptions} query - optional query parameter for filtering functions by action
1594
+ * @return Promise containing wrapped collection of Functions in an environment
1595
+ * @example ```javascript
1596
+ * const contentful = require('contentful-management')
1597
+ *
1598
+ * const client = contentful.createClient({
1599
+ * accessToken: '<content_management_api_key>'
1600
+ * })
1601
+ *
1602
+ * client
1603
+ * .getSpace('<space-id>')
1604
+ * .then((space) => space.getEnvironment('<environment-id>'))
1605
+ * .then((environment) => environment.getFunctionsForEnvironment('<app-installation-id>', { 'accepts[all]': '<action>' }))
1606
+ * .then((functions) => console.log(functions.items))
1607
+ * .catch(console.error)
1608
+ * ```
1609
+ */
1610
+ getFunctionsForEnvironment(appInstallationId, query) {
1611
+ const raw = this.toPlainObject();
1612
+ return makeRequest({
1613
+ entityType: 'Function',
1614
+ action: 'getManyForEnvironment',
1615
+ params: {
1616
+ spaceId: raw.sys.space.sys.id,
1617
+ environmentId: raw.sys.id,
1618
+ appInstallationId,
1619
+ query,
1620
+ },
1621
+ }).then((data) => _function.wrapFunctionCollection(makeRequest, data));
1622
+ },
1623
+ /**
1624
+ * Gets a collection of FunctionLogs for a given app installation id and FunctionId
1625
+ * @param appInstallationId
1626
+ * @param functionId
1627
+ * @param {import('../common-types').CursorBasedParams} query - optional query parameter for pagination (limit, nextPage, prevPage)
1628
+ * @return Promise containing wrapped collection of FunctionLogs
1629
+ * * @example ```javascript
1630
+ * const contentful = require('contentful-management')
1631
+ *
1632
+ * const client = contentful.createClient({
1633
+ * accessToken: '<content_management_api_key>'
1634
+ * })
1635
+ *
1636
+ * client
1637
+ * .getSpace('<space-id>')
1638
+ * .then((space) => space.getEnvironment('<environment-id>'))
1639
+ * .then((environment) =>
1640
+ * environment.getFunctionLogs(
1641
+ * '<app-installation-id>',
1642
+ * '<function-id>',
1643
+ * {
1644
+ * query: {
1645
+ * // optional limit
1646
+ * limit: 10,
1647
+ * // optional interval query
1648
+ * 'sys.createdAt[gte]': start,
1649
+ * 'sys.createdAt[lt]': end,
1650
+ * // optional cursor based pagination parameters
1651
+ * pagePrev: '<page_prev>',
1652
+ * },
1653
+ * },
1654
+ * )
1655
+ * )
1656
+ * .then((functionLogs) => console.log(functionLog.items))
1657
+ * .catch(console.error)
1658
+ * ```
1659
+ */
1660
+ getFunctionLogs(appInstallationId, functionId, query) {
1661
+ const raw = this.toPlainObject();
1662
+ return makeRequest({
1663
+ entityType: 'FunctionLog',
1664
+ action: 'getMany',
1665
+ params: {
1666
+ spaceId: raw.sys.space.sys.id,
1667
+ environmentId: raw.sys.id,
1668
+ appInstallationId,
1669
+ functionId,
1670
+ query: query ? contentfulSdkCore.createRequestConfig({ query }).params : undefined,
1671
+ },
1672
+ }).then((data) => functionLog.wrapFunctionLogCollection(makeRequest, data));
1673
+ },
1674
+ /**
1675
+ * Gets a FunctionLog by appInstallationId, functionId and logId
1676
+ * @param appInstallationId
1677
+ * @param functionId
1678
+ * @param logId
1679
+ * @return Promise containing a wrapped FunctionLog
1680
+ * @example ```javascript
1681
+ * const contentful = require('contentful-management')
1682
+ *
1683
+ * const client = contentful.createClient({
1684
+ * accessToken: '<content_management_api_key>'
1685
+ * })
1686
+ *
1687
+ * client
1688
+ * .getSpace(<space-id>)
1689
+ * .then((space) => space.getEnvironment('<environment-id>'))
1690
+ * .then((environment) =>
1691
+ * environment.getFunctionLog(
1692
+ * '<app-installation-id>',
1693
+ * '<function-id>',
1694
+ * '<log-id>'
1695
+ * )
1696
+ * )
1697
+ * .then((functionLog) => console.log(functionLog))
1698
+ * .catch(console.error)
1699
+ * ```
1700
+ */
1701
+ getFunctionLog(appInstallationId, functionId, logId) {
1702
+ const raw = this.toPlainObject();
1703
+ return makeRequest({
1704
+ entityType: 'FunctionLog',
1705
+ action: 'get',
1706
+ params: {
1707
+ spaceId: raw.sys.space.sys.id,
1708
+ environmentId: raw.sys.id,
1709
+ appInstallationId,
1710
+ functionId,
1711
+ logId,
1712
+ },
1713
+ }).then((data) => functionLog.wrapFunctionLog(makeRequest, data));
1714
+ },
1715
+ /**
1716
+ * Gets all snapshots of an entry
1717
+ * @func getEntrySnapshots
1718
+ * @param entryId - Entry ID
1719
+ * @param query - query additional query paramaters
1720
+ * @return Promise for a collection of Entry Snapshots
1721
+ * @example ```javascript
1722
+ * const contentful = require('contentful-management')
1723
+ *
1724
+ * const client = contentful.createClient({
1725
+ * accessToken: '<content_management_api_key>'
1726
+ * })
1727
+ *
1728
+ * client.getSpace('<space_id>')
1729
+ * .then((space) => space.getEnvironment('<environment-id>'))
1730
+ * .then((environment) => environment.getEntrySnapshots('<entry_id>'))
1731
+ * .then((snapshots) => console.log(snapshots.items))
1732
+ * .catch(console.error)
1733
+ * ```
1734
+ */
1735
+ getEntrySnapshots(entryId, query = {}) {
1736
+ const raw = this.toPlainObject();
1737
+ return makeRequest({
1738
+ entityType: 'Snapshot',
1739
+ action: 'getManyForEntry',
1740
+ params: {
1741
+ spaceId: raw.sys.space.sys.id,
1742
+ environmentId: raw.sys.id,
1743
+ entryId,
1744
+ query,
1745
+ },
1746
+ }).then((data) => wrapSnapshotCollection(makeRequest, data));
1747
+ },
1748
+ /**
1749
+ * Gets all snapshots of a contentType
1750
+ * @func getContentTypeSnapshots
1751
+ * @param contentTypeId - Content Type ID
1752
+ * @param query - query additional query paramaters
1753
+ * @return Promise for a collection of Content Type Snapshots
1754
+ * @example ```javascript
1755
+ * const contentful = require('contentful-management')
1756
+ *
1757
+ * const client = contentful.createClient({
1758
+ * accessToken: '<content_management_api_key>'
1759
+ * })
1760
+ *
1761
+ * client.getSpace('<space_id>')
1762
+ * .then((space) => space.getEnvironment('<environment-id>'))
1763
+ * .then((environment) => environment.getContentTypeSnapshots('<contentTypeId>'))
1764
+ * .then((snapshots) => console.log(snapshots.items))
1765
+ * .catch(console.error)
1766
+ * ```
1767
+ */
1768
+ getContentTypeSnapshots(contentTypeId, query = {}) {
1769
+ const raw = this.toPlainObject();
1770
+ return makeRequest({
1771
+ entityType: 'Snapshot',
1772
+ action: 'getManyForContentType',
1773
+ params: {
1774
+ spaceId: raw.sys.space.sys.id,
1775
+ environmentId: raw.sys.id,
1776
+ contentTypeId,
1777
+ query,
1778
+ },
1779
+ }).then((data) => wrapSnapshotCollection(makeRequest, data));
1780
+ },
1781
+ createTag(id, name, visibility) {
1782
+ const raw = this.toPlainObject();
1783
+ return makeRequest({
1784
+ entityType: 'Tag',
1785
+ action: 'createWithId',
1786
+ params: {
1787
+ spaceId: raw.sys.space.sys.id,
1788
+ environmentId: raw.sys.id,
1789
+ tagId: id,
1790
+ },
1791
+ payload: {
1792
+ name,
1793
+ sys: { visibility: visibility !== null && visibility !== void 0 ? visibility : 'private' },
1794
+ },
1795
+ }).then((data) => tag.wrapTag(makeRequest, data));
1796
+ },
1797
+ getTags(query = {}) {
1798
+ const raw = this.toPlainObject();
1799
+ return makeRequest({
1800
+ entityType: 'Tag',
1801
+ action: 'getMany',
1802
+ params: {
1803
+ spaceId: raw.sys.space.sys.id,
1804
+ environmentId: raw.sys.id,
1805
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
1806
+ },
1807
+ }).then((data) => tag.wrapTagCollection(makeRequest, data));
1808
+ },
1809
+ getTag(id) {
1810
+ const raw = this.toPlainObject();
1811
+ return makeRequest({
1812
+ entityType: 'Tag',
1813
+ action: 'get',
1814
+ params: {
1815
+ spaceId: raw.sys.space.sys.id,
1816
+ environmentId: raw.sys.id,
1817
+ tagId: id,
1818
+ },
1819
+ }).then((data) => tag.wrapTag(makeRequest, data));
1820
+ },
1821
+ /**
1822
+ * Retrieves a Release by ID
1823
+ * @param releaseId
1824
+ * @returns Promise containing a wrapped Release
1825
+ * @example ```javascript
1826
+ * const contentful = require('contentful-management')
1827
+ *
1828
+ * const client = contentful.createClient({
1829
+ * accessToken: '<content_management_api_key>'
1830
+ * })
1831
+ *
1832
+ * client.getSpace('<space_id>')
1833
+ * .then((space) => space.getEnvironment('<environment-id>'))
1834
+ * .then((environment) => environment.getRelease('<release_id>'))
1835
+ * .then((release) => console.log(release))
1836
+ * .catch(console.error)
1837
+ * ```
1838
+ */
1839
+ getRelease(releaseId) {
1840
+ const raw = this.toPlainObject();
1841
+ return makeRequest({
1842
+ entityType: 'Release',
1843
+ action: 'get',
1844
+ params: {
1845
+ spaceId: raw.sys.space.sys.id,
1846
+ environmentId: raw.sys.id,
1847
+ releaseId,
1848
+ },
1849
+ }).then((data) => release.wrapRelease(makeRequest, data));
1850
+ },
1851
+ /**
1852
+ * Gets a Collection of Releases,
1853
+ * @param {ReleaseQueryOptions} query filtering options for the collection result
1854
+ * @returns Promise containing a wrapped Release Collection
1855
+ * @example ```javascript
1856
+ * const contentful = require('contentful-management')
1857
+ *
1858
+ * const client = contentful.createClient({
1859
+ * accessToken: '<content_management_api_key>'
1860
+ * })
1861
+ *
1862
+ * client.getSpace('<space_id>')
1863
+ * .then((space) => space.getEnvironment('<environment-id>'))
1864
+ * .then((environment) => environment.getReleases({ 'entities.sys.id[in]': '<asset_id>,<entry_id>' }))
1865
+ * .then((releases) => console.log(releases))
1866
+ * .catch(console.error)
1867
+ * ```
1868
+ */
1869
+ getReleases(query) {
1870
+ const raw = this.toPlainObject();
1871
+ return makeRequest({
1872
+ entityType: 'Release',
1873
+ action: 'query',
1874
+ params: {
1875
+ spaceId: raw.sys.space.sys.id,
1876
+ environmentId: raw.sys.id,
1877
+ query,
1878
+ },
1879
+ }).then((data) => release.wrapReleaseCollection(makeRequest, data));
1880
+ },
1881
+ /**
1882
+ * Creates a new Release with the entities and title in the payload
1883
+ * @param payload Object containing the payload in order to create a Release
1884
+ * @returns Promise containing a wrapped Release, that has other helper methods within.
1885
+ * @example ```javascript
1886
+ * const contentful = require('contentful-management')
1887
+ *
1888
+ * const client = contentful.createClient({
1889
+ * accessToken: '<content_management_api_key>'
1890
+ * })
1891
+ *
1892
+ * const payload = {
1893
+ * title: 'My Release',
1894
+ * entities: {
1895
+ * sys: { type: 'Array' },
1896
+ * items: [
1897
+ * { sys: { linkType: 'Entry', type: 'Link', id: '<entry_id>' } }
1898
+ * ]
1899
+ * }
1900
+ * }
1901
+ *
1902
+ * client.getSpace('<space_id>')
1903
+ * .then((space) => space.getEnvironment('<environment-id>'))
1904
+ * .then((environment) => environment.createRelease(payload))
1905
+ * .then((release) => console.log(release))
1906
+ * .catch(console.error)
1907
+ * ```
1908
+ */
1909
+ createRelease(payload) {
1910
+ const raw = this.toPlainObject();
1911
+ return makeRequest({
1912
+ entityType: 'Release',
1913
+ action: 'create',
1914
+ params: {
1915
+ spaceId: raw.sys.space.sys.id,
1916
+ environmentId: raw.sys.id,
1917
+ },
1918
+ payload,
1919
+ }).then((data) => release.wrapRelease(makeRequest, data));
1920
+ },
1921
+ /**
1922
+ * Updates a Release and replaces all the properties.
1923
+ * @param {object} options,
1924
+ * @param options.releaseId the ID of the release
1925
+ * @param options.payload the payload to be updated in the Release
1926
+ * @param options.version Release sys.version that to be updated
1927
+ * @returns Promise containing a wrapped Release, that has helper methods within.
1928
+ *
1929
+ * @example ```javascript
1930
+ * const contentful = require('contentful-management')
1931
+ *
1932
+ * const client = contentful.createClient({
1933
+ * accessToken: '<content_management_api_key>'
1934
+ * })
1935
+ *
1936
+ *
1937
+ * const payload = {
1938
+ * title: "Updated Release title",
1939
+ * entities: {
1940
+ * sys: { type: 'Array' },
1941
+ * items: [
1942
+ * { sys: { linkType: 'Entry', type: 'Link', id: '<entry_id>' } }
1943
+ * ]
1944
+ * }
1945
+ * }
1946
+ *
1947
+ * client.getSpace('<space_id>')
1948
+ * .then((space) => space.getEnvironment('<environment-id>'))
1949
+ * .then((environment) => environment.updateRelease({ releaseId: '<release_id>', version: 1, payload } ))
1950
+ * .then((release) => console.log(release))
1951
+ * .catch(console.error)
1952
+ * ```
1953
+ */
1954
+ updateRelease({ releaseId, payload, version, }) {
1955
+ const raw = this.toPlainObject();
1956
+ return makeRequest({
1957
+ entityType: 'Release',
1958
+ action: 'update',
1959
+ params: {
1960
+ spaceId: raw.sys.space.sys.id,
1961
+ environmentId: raw.sys.id,
1962
+ releaseId,
1963
+ version,
1964
+ },
1965
+ payload,
1966
+ }).then((data) => release.wrapRelease(makeRequest, data));
1967
+ },
1968
+ /**
1969
+ * Deletes a Release by ID - does not delete any entities.
1970
+ * @param releaseId the ID of the release
1971
+ *
1972
+ * @returns Promise containing a wrapped Release, that has helper methods within.
1973
+ * @example ```javascript
1974
+ * const contentful = require('contentful-management')
1975
+ *
1976
+ * const client = contentful.createClient({
1977
+ * accessToken: '<content_management_api_key>'
1978
+ * })
1979
+ *
1980
+ * client.getSpace('<space_id>')
1981
+ * .then((space) => space.getEnvironment('<environment-id>'))
1982
+ * .then((environment) => environment.deleteRelease('<release_id>')
1983
+ * .catch(console.error)
1984
+ * ```
1985
+ */
1986
+ deleteRelease(releaseId) {
1987
+ const raw = this.toPlainObject();
1988
+ return makeRequest({
1989
+ entityType: 'Release',
1990
+ action: 'delete',
1991
+ params: {
1992
+ spaceId: raw.sys.space.sys.id,
1993
+ environmentId: raw.sys.id,
1994
+ releaseId,
1995
+ },
1996
+ });
1997
+ },
1998
+ /**
1999
+ * Publishes all Entities contained in a Release.
2000
+ * @param options.releaseId the ID of the release
2001
+ * @param options.version the version of the release that is to be published
2002
+ * @returns Promise containing a wrapped Release, that has helper methods within.
2003
+ *
2004
+ * @example ```javascript
2005
+ * const contentful = require('contentful-management')
2006
+ *
2007
+ * const client = contentful.createClient({
2008
+ * accessToken: '<content_management_api_key>'
2009
+ * })
2010
+ *
2011
+ * client.getSpace('<space_id>')
2012
+ * .then((space) => space.getEnvironment('<environment-id>'))
2013
+ * .then((environment) => environment.publishRelease({ releaseId: '<release_id>', version: 1 }))
2014
+ * .catch(console.error)
2015
+ * ```
2016
+ */
2017
+ publishRelease({ releaseId, version }) {
2018
+ const raw = this.toPlainObject();
2019
+ return makeRequest({
2020
+ entityType: 'Release',
2021
+ action: 'publish',
2022
+ params: {
2023
+ spaceId: raw.sys.space.sys.id,
2024
+ environmentId: raw.sys.id,
2025
+ releaseId,
2026
+ version,
2027
+ },
2028
+ }).then((data) => releaseAction.wrapReleaseAction(makeRequest, data));
2029
+ },
2030
+ /**
2031
+ * Unpublishes all Entities contained in a Release.
2032
+ * @param options.releaseId the ID of the release
2033
+ * @param options.version the version of the release that is to be published
2034
+ * @returns Promise containing a wrapped Release, that has helper methods within.
2035
+ *
2036
+ * @example ```javascript
2037
+ * const contentful = require('contentful-management')
2038
+ *
2039
+ * const client = contentful.createClient({
2040
+ * accessToken: '<content_management_api_key>'
2041
+ * })
2042
+ *
2043
+ * client.getSpace('<space_id>')
2044
+ * .then((space) => space.getEnvironment('<environment-id>'))
2045
+ * .then((environment) => environment.unpublishRelease({ releaseId: '<release_id>', version: 1 }))
2046
+ * .catch(console.error)
2047
+ * ```
2048
+ */
2049
+ unpublishRelease({ releaseId, version }) {
2050
+ const raw = this.toPlainObject();
2051
+ return makeRequest({
2052
+ entityType: 'Release',
2053
+ action: 'unpublish',
2054
+ params: {
2055
+ spaceId: raw.sys.space.sys.id,
2056
+ environmentId: raw.sys.id,
2057
+ releaseId,
2058
+ version,
2059
+ },
2060
+ }).then((data) => releaseAction.wrapReleaseAction(makeRequest, data));
2061
+ },
2062
+ /**
2063
+ * Validates all Entities contained in a Release against an action (publish or unpublish)
2064
+ * @param options.releaseId the ID of the release
2065
+ * @param options.payload (optional) the type of action to be validated against
2066
+ *
2067
+ * @returns Promise containing a wrapped Release, that has helper methods within.
2068
+ *
2069
+ * @example ```javascript
2070
+ * const contentful = require('contentful-management')
2071
+ *
2072
+ * const client = contentful.createClient({
2073
+ * accessToken: '<content_management_api_key>'
2074
+ * })
2075
+ *
2076
+ * client.getSpace('<space_id>')
2077
+ * .then((space) => space.getEnvironment('<environment-id>'))
2078
+ * .then((environment) => environment.validateRelease({ releaseId: '<release_id>', payload: { action: 'unpublish' } }))
2079
+ * .catch(console.error)
2080
+ * ```
2081
+ */
2082
+ validateRelease({ releaseId, payload, }) {
2083
+ const raw = this.toPlainObject();
2084
+ return makeRequest({
2085
+ entityType: 'Release',
2086
+ action: 'validate',
2087
+ params: {
2088
+ spaceId: raw.sys.space.sys.id,
2089
+ environmentId: raw.sys.id,
2090
+ releaseId,
2091
+ },
2092
+ payload,
2093
+ }).then((data) => releaseAction.wrapReleaseAction(makeRequest, data));
2094
+ },
2095
+ /**
2096
+ * Archives a Release and prevents new operations (publishing, unpublishing adding new entities etc).
2097
+ * @param options.releaseId the ID of the release
2098
+ * @param options.version the version of the release that is to be archived
2099
+ * @returns Promise containing a wrapped Release, that has helper methods within.
2100
+ *
2101
+ * @example ```javascript
2102
+ * const contentful = require('contentful-management')
2103
+ *
2104
+ * const client = contentful.createClient({
2105
+ * accessToken: '<content_management_api_key>'
2106
+ * })
2107
+ *
2108
+ * client.getSpace('<space_id>')
2109
+ * .then((space) => space.getEnvironment('<environment-id>'))
2110
+ * .then((environment) => environment.archiveRelease({ releaseId: '<release_id>', version: 1 }))
2111
+ * .catch(console.error)
2112
+ * ```
2113
+ */
2114
+ archiveRelease({ releaseId, version }) {
2115
+ const raw = this.toPlainObject();
2116
+ return makeRequest({
2117
+ entityType: 'Release',
2118
+ action: 'archive',
2119
+ params: {
2120
+ spaceId: raw.sys.space.sys.id,
2121
+ environmentId: raw.sys.id,
2122
+ releaseId,
2123
+ version,
2124
+ },
2125
+ }).then((data) => release.wrapRelease(makeRequest, data));
2126
+ },
2127
+ /**
2128
+ * Unarchives a previously archived Release - this enables the release to be published, unpublished etc.
2129
+ * @param options.releaseId the ID of the release
2130
+ * @param options.version the version of the release that is to be unarchived
2131
+ * @returns Promise containing a wrapped Release, that has helper methods within.
2132
+ *
2133
+ * @example ```javascript
2134
+ * const contentful = require('contentful-management')
2135
+ *
2136
+ * const client = contentful.createClient({
2137
+ * accessToken: '<content_management_api_key>'
2138
+ * })
2139
+ *
2140
+ * client.getSpace('<space_id>')
2141
+ * .then((space) => space.getEnvironment('<environment-id>'))
2142
+ * .then((environment) => environment.unarchiveRelease({ releaseId: '<release_id>', version: 1 }))
2143
+ * .catch(console.error)
2144
+ * ```
2145
+ */
2146
+ unarchiveRelease({ releaseId, version }) {
2147
+ const raw = this.toPlainObject();
2148
+ return makeRequest({
2149
+ entityType: 'Release',
2150
+ action: 'unarchive',
2151
+ params: {
2152
+ spaceId: raw.sys.space.sys.id,
2153
+ environmentId: raw.sys.id,
2154
+ releaseId,
2155
+ version,
2156
+ },
2157
+ }).then((data) => release.wrapRelease(makeRequest, data));
2158
+ },
2159
+ /**
2160
+ * Retrieves a ReleaseAction by ID
2161
+ * @param params.releaseId The ID of a Release
2162
+ * @param params.actionId The ID of a Release Action
2163
+ * @returns Promise containing a wrapped ReleaseAction
2164
+ * @example ```javascript
2165
+ * const contentful = require('contentful-management')
2166
+ *
2167
+ * const client = contentful.createClient({
2168
+ * accessToken: '<content_management_api_key>'
2169
+ * })
2170
+ *
2171
+ * client.getSpace('<space_id>')
2172
+ * .then((space) => space.getEnvironment('<environment-id>'))
2173
+ * .then((environment) => environment.getReleaseAction({ releaseId: '<release_id>', actionId: '<action_id>' }))
2174
+ * .then((releaseAction) => console.log(releaseAction))
2175
+ * .catch(console.error)
2176
+ * ```
2177
+ */
2178
+ getReleaseAction({ actionId, releaseId }) {
2179
+ const raw = this.toPlainObject();
2180
+ return makeRequest({
2181
+ entityType: 'ReleaseAction',
2182
+ action: 'get',
2183
+ params: {
2184
+ actionId,
2185
+ spaceId: raw.sys.space.sys.id,
2186
+ environmentId: raw.sys.id,
2187
+ releaseId,
2188
+ },
2189
+ }).then((data) => releaseAction.wrapReleaseAction(makeRequest, data));
2190
+ },
2191
+ /**
2192
+ * Gets a Collection of ReleaseActions
2193
+ * @param {string} params.releaseId ID of the Release to fetch the actions from
2194
+ * @param {ReleaseQueryOptions} params.query filtering options for the collection result
2195
+ * @returns Promise containing a wrapped ReleaseAction Collection
2196
+ *
2197
+ * @example ```javascript
2198
+ * const contentful = require('contentful-management')
2199
+ *
2200
+ * const client = contentful.createClient({
2201
+ * accessToken: '<content_management_api_key>'
2202
+ * })
2203
+ *
2204
+ * client.getSpace('<space_id>')
2205
+ * .then((space) => space.getEnvironment('<environment-id>'))
2206
+ * .then((environment) => environment.getReleaseActions({ query: { 'sys.id[in]': '<id_1>,<id_2>', 'sys.release.sys.id[in]': '<id1>,<id2>' } }))
2207
+ * .then((releaseActions) => console.log(releaseActions))
2208
+ * .catch(console.error)
2209
+ * ```
2210
+ */
2211
+ getReleaseActions({ query }) {
2212
+ const raw = this.toPlainObject();
2213
+ return makeRequest({
2214
+ entityType: 'ReleaseAction',
2215
+ action: 'getMany',
2216
+ params: {
2217
+ spaceId: raw.sys.space.sys.id,
2218
+ environmentId: raw.sys.id,
2219
+ query,
2220
+ },
2221
+ }).then((data) => releaseAction.wrapReleaseActionCollection(makeRequest, data));
2222
+ },
2223
+ async getUIConfig() {
2224
+ const raw = this.toPlainObject();
2225
+ const data = await makeRequest({
2226
+ entityType: 'UIConfig',
2227
+ action: 'get',
2228
+ params: {
2229
+ spaceId: raw.sys.space.sys.id,
2230
+ environmentId: raw.sys.id,
2231
+ },
2232
+ });
2233
+ return uiConfig.wrapUIConfig(makeRequest, data);
2234
+ },
2235
+ async getUserUIConfig() {
2236
+ const raw = this.toPlainObject();
2237
+ const data = await makeRequest({
2238
+ entityType: 'UserUIConfig',
2239
+ action: 'get',
2240
+ params: {
2241
+ spaceId: raw.sys.space.sys.id,
2242
+ environmentId: raw.sys.id,
2243
+ },
2244
+ });
2245
+ return userUiConfig.wrapUserUIConfig(makeRequest, data);
2246
+ },
2247
+ /**
2248
+ * Gets a collection of all environment template installations in the environment for a given template
2249
+ * @param environmentTemplateId - Environment template ID to return installations for
2250
+ * @param [options.installationId] - Installation ID to filter for a specific installation
2251
+ * @return Promise for a collection of EnvironmentTemplateInstallations
2252
+ * ```javascript
2253
+ * const contentful = require('contentful-management')
2254
+ *
2255
+ * const client = contentful.createClient({
2256
+ * accessToken: '<content_management_api_key>'
2257
+ * })
2258
+ *
2259
+ * client.getSpace('<space_id>')
2260
+ * .then((space) => space.getEnvironment('<environment_id>'))
2261
+ * .then((environment) => environment.getEnvironmentTemplateInstallations('<environment_template_id>'))
2262
+ * .then((installations) => console.log(installations.items))
2263
+ * .catch(console.error)
2264
+ * ```
2265
+ */
2266
+ async getEnvironmentTemplateInstallations(environmentTemplateId, _a = {}) {
2267
+ var { installationId } = _a, query = tslib.__rest(_a, ["installationId"]);
2268
+ const raw = this.toPlainObject();
2269
+ return makeRequest({
2270
+ entityType: 'EnvironmentTemplateInstallation',
2271
+ action: 'getForEnvironment',
2272
+ params: Object.assign(Object.assign({ environmentTemplateId }, (installationId && { installationId })), { query: Object.assign({}, contentfulSdkCore.createRequestConfig({ query }).params), spaceId: raw.sys.space.sys.id, environmentId: raw.sys.id }),
2273
+ }).then((data) => environmentTemplateInstallation.wrapEnvironmentTemplateInstallationCollection(makeRequest, data));
2274
+ },
2275
+ /**
2276
+ * Gets a collection of all resource types based on native external references app installations in the environment
2277
+ * @param query - BasicCursorPaginationOptions
2278
+ * @return Promise for a collection of ResourceTypes
2279
+ * ```javascript
2280
+ * const contentful = require('contentful-management')
2281
+ *
2282
+ * const client = contentful.createClient({
2283
+ * accessToken: '<content_management_api_key>'
2284
+ * })
2285
+ *
2286
+ * client.getSpace('<space_id>')
2287
+ * .then((space) => space.getEnvironment('<environment_id>'))
2288
+ * .then((environment) => environment.getResourceTypes({limit: 10}))
2289
+ * .then((installations) => console.log(installations.items))
2290
+ * .catch(console.error)
2291
+ * ```
2292
+ */
2293
+ async getResourceTypes(query) {
2294
+ const raw = this.toPlainObject();
2295
+ return makeRequest({
2296
+ entityType: 'ResourceType',
2297
+ action: 'getForEnvironment',
2298
+ params: {
2299
+ query,
2300
+ spaceId: raw.sys.space.sys.id,
2301
+ environmentId: raw.sys.id,
2302
+ },
2303
+ }).then((data) => wrapResourceTypesForEnvironmentCollection(makeRequest, data));
2304
+ },
2305
+ /**
2306
+ * Gets a collection of all resources for a given resource type based on native external references app installations in the environment
2307
+ * @param resourceTypeId - Id of the resourceType to get its resources
2308
+ * @param query - Either LookupQuery options with 'sys.urn[in]' param or a Search query with 'query' param, in both cases you can add pagination options
2309
+ * @return Promise for a collection of Resources for a given resourceTypeId
2310
+ * ```javascript
2311
+ * const contentful = require('contentful-management')
2312
+ *
2313
+ * const client = contentful.createClient({
2314
+ * accessToken: '<content_management_api_key>'
2315
+ * })
2316
+ *
2317
+ * // Search Query
2318
+ * client.getSpace('<space_id>')
2319
+ * .then((space) => space.getEnvironment('<environment_id>'))
2320
+ * // <search_query> is a string you want to search for in the external resources
2321
+ * .then((environment) => environment.getResourcesForResourceType('<resource_type_id>', {query: '<search_query>', limit: 10}))
2322
+ * .then((installations) => console.log(installations.items))
2323
+ * .catch(console.error)
2324
+ *
2325
+ * // Lookup query
2326
+ *
2327
+ * client.getSpace('<space_id>')
2328
+ * .then((space) => space.getEnvironment('<environment_id>'))
2329
+ * .then((environment) => environment.getResourcesForResourceType('<resource_type_id>', {'sys.urn[in]': '<resource_urn1>,<resource_urn2>', limit: 10}))
2330
+ * .then((installations) => console.log(installations.items))
2331
+ * .catch(console.error)
2332
+ * ```
2333
+ */
2334
+ async getResourcesForResourceType(resourceTypeId, query) {
2335
+ const raw = this.toPlainObject();
2336
+ return makeRequest({
2337
+ entityType: 'Resource',
2338
+ action: 'getMany',
2339
+ params: {
2340
+ query,
2341
+ spaceId: raw.sys.space.sys.id,
2342
+ environmentId: raw.sys.id,
2343
+ resourceTypeId,
2344
+ },
2345
+ }).then((data) => wrapResourceCollection(makeRequest, data));
2346
+ },
2347
+ /**
2348
+ * Invokes an AI Action.
2349
+ * @param aiActionId - The ID of the AI Action to invoke.
2350
+ * @param payload - The invocation payload.
2351
+ * @returns Promise for an AI Action Invocation.
2352
+ * @example ```javascript
2353
+ * client.getSpace('<space_id>')
2354
+ * .then(space => space.getEnvironment('<environment_id>'))
2355
+ * .then(environment => environment.invokeAiAction('<ai_action_id>', {
2356
+ * variables: [ ... ],
2357
+ * outputFormat: 'RichText'
2358
+ * }))
2359
+ * .then(invocation => console.log(invocation))
2360
+ * .catch(console.error)
2361
+ * ```
2362
+ */
2363
+ invokeAiAction(aiActionId, payload) {
2364
+ const raw = this.toPlainObject();
2365
+ return makeRequest({
2366
+ entityType: 'AiAction',
2367
+ action: 'invoke',
2368
+ params: { spaceId: raw.sys.space.sys.id, environmentId: raw.sys.id, aiActionId },
2369
+ payload,
2370
+ }).then((data) => aiActionInvocation.wrapAiActionInvocation(makeRequest, data));
2371
+ },
2372
+ /**
2373
+ * Retrieves an AI Action Invocation.
2374
+ * @param params - Object containing the AI Action ID and the Invocation ID.
2375
+ * @returns Promise for an AI Action Invocation.
2376
+ * @example ```javascript
2377
+ * client.getSpace('<space_id>')
2378
+ * .then(space => space.getEnvironment('<environment_id>'))
2379
+ * .then(environment => environment.getAiActionInvocation({
2380
+ * aiActionId: '<ai_action_id>',
2381
+ * invocationId: '<invocation_id>'
2382
+ * }))
2383
+ * .then(invocation => console.log(invocation))
2384
+ * .catch(console.error)
2385
+ * ```
2386
+ */
2387
+ getAiActionInvocation({ aiActionId, invocationId, }) {
2388
+ const raw = this.toPlainObject();
2389
+ return makeRequest({
2390
+ entityType: 'AiActionInvocation',
2391
+ action: 'get',
2392
+ params: {
2393
+ spaceId: raw.sys.space.sys.id,
2394
+ environmentId: raw.sys.id,
2395
+ aiActionId,
2396
+ invocationId,
2397
+ },
2398
+ }).then((data) => aiActionInvocation.wrapAiActionInvocation(makeRequest, data));
2399
+ },
2400
+ };
2401
+ }
2402
+
2403
+ module.exports = createEnvironmentApi;