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,592 @@
1
+ 'use strict';
2
+
3
+ var tslib = require('tslib');
4
+ var contentfulSdkCore = require('contentful-sdk-core');
5
+ var index = require('./entities/index.js');
6
+
7
+ /**
8
+ * @private
9
+ */
10
+ function createClientApi(makeRequest) {
11
+ const { wrapSpace, wrapSpaceCollection } = index.space;
12
+ const { wrapUser } = index.user;
13
+ const { wrapPersonalAccessToken, wrapPersonalAccessTokenCollection } = index.personalAccessToken;
14
+ const { wrapAccessToken, wrapAccessTokenCollection } = index.accessToken;
15
+ const { wrapOrganization, wrapOrganizationCollection } = index.organization;
16
+ const { wrapUsageCollection } = index.usage;
17
+ const { wrapAppDefinition } = index.appDefinition;
18
+ const { wrapEnvironmentTemplate, wrapEnvironmentTemplateCollection } = index.environmentTemplate;
19
+ const { wrapOAuthApplication, wrapOAuthApplicationCollection } = index.oauthApplication;
20
+ return {
21
+ version: "12.0.0-beta.3",
22
+ /**
23
+ * Gets all environment templates for a given organization with the lasted version
24
+ * @param organizationId - Organization ID
25
+ * @return Promise for a collection of EnvironmentTemplates
26
+ * ```javascript
27
+ * const contentful = require('contentful-management')
28
+ *
29
+ * const client = contentful.createClient({
30
+ * accessToken: '<content_management_api_key>'
31
+ * })
32
+ *
33
+ * client.getEnvironmentTemplates('<organization_id>')
34
+ * .then((response) => console.log(response.items))
35
+ * .catch(console.error)
36
+ * ```
37
+ */
38
+ getEnvironmentTemplates: function getEnvironmentTemplates(organizationId, query = {}) {
39
+ return makeRequest({
40
+ entityType: 'EnvironmentTemplate',
41
+ action: 'getMany',
42
+ params: { organizationId, query: contentfulSdkCore.createRequestConfig({ query }).params },
43
+ }).then((data) => wrapEnvironmentTemplateCollection(makeRequest, data, organizationId));
44
+ },
45
+ /**
46
+ * Gets the lasted version environment template if params.version is not specified
47
+ * @param params.organizationId - Organization ID
48
+ * @param params.environmentTemplateId - Environment template ID
49
+ * @param [params.version] - Template version number to return a specific version of the environment template
50
+ * @return Promise for a EnvironmentTemplate
51
+ * ```javascript
52
+ * const contentful = require('contentful-management')
53
+ *
54
+ * const client = contentful.createClient({
55
+ * accessToken: '<content_management_api_key>'
56
+ * })
57
+ *
58
+ * client.getEnvironmentTemplate({
59
+ * organizationId: '<organization_id>',
60
+ * environmentTemplateId: '<environment_template_id>',
61
+ * version: version>
62
+ * })
63
+ * .then((space) => console.log(space))
64
+ * .catch(console.error)
65
+ * ```
66
+ */
67
+ getEnvironmentTemplate: function getEnvironmentTemplate({ organizationId, environmentTemplateId, version, query = {}, }) {
68
+ return makeRequest({
69
+ entityType: 'EnvironmentTemplate',
70
+ action: 'get',
71
+ params: {
72
+ organizationId,
73
+ environmentTemplateId,
74
+ version,
75
+ query: contentfulSdkCore.createRequestConfig({ query }).params,
76
+ },
77
+ }).then((data) => wrapEnvironmentTemplate(makeRequest, data, organizationId));
78
+ },
79
+ /**
80
+ * Creates an environment template
81
+ * @param organizationId - Organization ID
82
+ * @param environmentTemplateData - Object representation of the environment template to be created
83
+ * @return Promise for the newly created EnvironmentTemplate
84
+ * @example ```javascript
85
+ * const contentful = require('contentful-management')
86
+ *
87
+ * const client = contentful.createClient({
88
+ * accessToken: '<content_management_api_key>'
89
+ * })
90
+ *
91
+ * client.createEnvironmentTemplate('<organization_id>', {<environment_template_date>})
92
+ * .then((environmentTemplate) => console.log(environmentTemplate))
93
+ * .catch(console.error)
94
+ * ```
95
+ */
96
+ createEnvironmentTemplate: function createEnvironmentTemplate(organizationId, environmentTemplateData) {
97
+ return makeRequest({
98
+ entityType: 'EnvironmentTemplate',
99
+ action: 'create',
100
+ params: { organizationId },
101
+ payload: environmentTemplateData,
102
+ }).then((data) => wrapEnvironmentTemplate(makeRequest, data, organizationId));
103
+ },
104
+ /**
105
+ * Gets all spaces
106
+ * @return Promise for a collection of Spaces
107
+ * ```javascript
108
+ * const contentful = require('contentful-management')
109
+ *
110
+ * const client = contentful.createClient({
111
+ * accessToken: '<content_management_api_key>'
112
+ * })
113
+ *
114
+ * client.getSpaces()
115
+ * .then((response) => console.log(response.items))
116
+ * .catch(console.error)
117
+ * ```
118
+ */
119
+ getSpaces: function getSpaces(query = {}) {
120
+ return makeRequest({
121
+ entityType: 'Space',
122
+ action: 'getMany',
123
+ params: { query: contentfulSdkCore.createRequestConfig({ query: query }).params },
124
+ }).then((data) => wrapSpaceCollection(makeRequest, data));
125
+ },
126
+ /**
127
+ * Gets a space
128
+ * @param spaceId - Space ID
129
+ * @return Promise for a Space
130
+ * ```javascript
131
+ * const contentful = require('contentful-management')
132
+ *
133
+ * const client = contentful.createClient({
134
+ * accessToken: '<content_management_api_key>'
135
+ * })
136
+ *
137
+ * client.getSpace('<space_id>')
138
+ * .then((space) => console.log(space))
139
+ * .catch(console.error)
140
+ * ```
141
+ */
142
+ getSpace: function getSpace(spaceId) {
143
+ return makeRequest({
144
+ entityType: 'Space',
145
+ action: 'get',
146
+ params: { spaceId },
147
+ }).then((data) => wrapSpace(makeRequest, data));
148
+ },
149
+ /**
150
+ * Creates a space
151
+ * @param spaceData - Object representation of the Space to be created
152
+ * @param organizationId - Organization ID, if the associated token can manage more than one organization.
153
+ * @return Promise for the newly created Space
154
+ * @example ```javascript
155
+ * const contentful = require('contentful-management')
156
+ *
157
+ * const client = contentful.createClient({
158
+ * accessToken: '<content_management_api_key>'
159
+ * })
160
+ *
161
+ * client.createSpace({
162
+ * name: 'Name of new space'
163
+ * })
164
+ * .then((space) => console.log(space))
165
+ * .catch(console.error)
166
+ * ```
167
+ */
168
+ createSpace: function createSpace(spaceData, organizationId) {
169
+ return makeRequest({
170
+ entityType: 'Space',
171
+ action: 'create',
172
+ params: { organizationId },
173
+ payload: spaceData,
174
+ }).then((data) => wrapSpace(makeRequest, data));
175
+ },
176
+ /**
177
+ * Gets an organization
178
+ * @param id - Organization ID
179
+ * @return Promise for a Organization
180
+ * @example ```javascript
181
+ * const contentful = require('contentful-management')
182
+ *
183
+ * const client = contentful.createClient({
184
+ * accessToken: '<content_management_api_key>'
185
+ * })
186
+ *
187
+ * client.getOrganization('<org_id>')
188
+ * .then((org) => console.log(org))
189
+ * .catch(console.error)
190
+ * ```
191
+ */
192
+ getOrganization: function getOrganization(id) {
193
+ return makeRequest({
194
+ entityType: 'Organization',
195
+ action: 'get',
196
+ params: { organizationId: id },
197
+ }).then((data) => wrapOrganization(makeRequest, data));
198
+ },
199
+ /**
200
+ * Gets a collection of Organizations
201
+ * @return Promise for a collection of Organizations
202
+ * @example ```javascript
203
+ * const contentful = require('contentful-management')
204
+ *
205
+ * const client = contentful.createClient({
206
+ * accessToken: '<content_management_api_key>'
207
+ * })
208
+ *
209
+ * client.getOrganizations()
210
+ * .then(result => console.log(result.items))
211
+ * .catch(console.error)
212
+ * ```
213
+ */
214
+ getOrganizations: function getOrganizations(query = {}) {
215
+ return makeRequest({
216
+ entityType: 'Organization',
217
+ action: 'getMany',
218
+ params: { query: contentfulSdkCore.createRequestConfig({ query }).params },
219
+ }).then((data) => wrapOrganizationCollection(makeRequest, data));
220
+ },
221
+ /**
222
+ * Gets the authenticated user
223
+ * @return Promise for a User
224
+ * @example ```javascript
225
+ * const contentful = require('contentful-management')
226
+ *
227
+ * const client = contentful.createClient({
228
+ * accessToken: '<content_management_api_key>'
229
+ * })
230
+ *
231
+ * client.getCurrentUser()
232
+ * .then(user => console.log(user.firstName))
233
+ * .catch(console.error)
234
+ * ```
235
+ */
236
+ getCurrentUser: function getCurrentUser(params) {
237
+ return makeRequest({
238
+ entityType: 'User',
239
+ action: 'getCurrent',
240
+ params,
241
+ }).then((data) => wrapUser(makeRequest, data));
242
+ },
243
+ /**
244
+ *
245
+ * @param params
246
+ * @returns Promise of a OAuthApplication
247
+ * @example ```javascript
248
+ * const contentful = require('contentful-management')
249
+ *
250
+ * const client = contentful.createClient({
251
+ * accessToken: '<content_management_api_key>'
252
+ * })
253
+ *
254
+ * client.getOAuthApplication({
255
+ * userId: '<user_id>'
256
+ * oauthApplicationId: '<oauth_application_id>'
257
+ * }).then(oauthApplication => console.log(oauthApplication))
258
+ * .catch(console.error)
259
+ */
260
+ getOAuthApplication: function getOAuthApplication(params) {
261
+ const { userId } = params;
262
+ return makeRequest({
263
+ entityType: 'OAuthApplication',
264
+ action: 'get',
265
+ params,
266
+ }).then((data) => wrapOAuthApplication(makeRequest, data, userId));
267
+ },
268
+ /**
269
+ *
270
+ * @param params
271
+ * @returns Promise of list of user's OAuthApplications
272
+ * @example ```javascript
273
+ * const contentful = require('contentful-management')
274
+ *
275
+ * const client = contentful.createClient({
276
+ * accessToken: '<content_management_api_key>'
277
+ * })
278
+ *
279
+ * client.getOAuthApplications({
280
+ * userId: '<user_id>'}).then(oauthApplications => console.log(oauthApplications))
281
+ * .catch(console.error)
282
+ */
283
+ getOAuthApplications: function getOAuthApplications(params) {
284
+ const { userId } = params;
285
+ return makeRequest({
286
+ entityType: 'OAuthApplication',
287
+ action: 'getManyForUser',
288
+ params,
289
+ }).then((data) => wrapOAuthApplicationCollection(makeRequest, data, userId));
290
+ },
291
+ /**
292
+ *
293
+ * @param params
294
+ * @returns Promise of a new OAuth application.
295
+ * @example ```javascript
296
+ * const contentful = require('contentful-management')
297
+ *
298
+ * const client = contentful.createClient({
299
+ * accessToken: '<content_management_api_key>'
300
+ * })
301
+ *
302
+ * client.createOAuthApplication({
303
+ * userId: '<user_id>'},
304
+ * { name: '<name>',
305
+ * description: '<description>',
306
+ * scopes: ['scope'],
307
+ * redirectUri: '<redirectUri>',
308
+ * confidential: '<true/false>'}).then(oauthApplications => console.log(oauthApplications))
309
+ * .catch(console.error)
310
+ */
311
+ createOAuthApplication: function createOAuthApplication(params, rawData) {
312
+ const { userId } = params;
313
+ return makeRequest({
314
+ entityType: 'OAuthApplication',
315
+ action: 'create',
316
+ params,
317
+ payload: rawData,
318
+ }).then((data) => wrapOAuthApplication(makeRequest, data, userId));
319
+ },
320
+ /**
321
+ * Gets App Definition
322
+ * @return Promise for App Definition
323
+ * @param organizationId - Id of the organization where the app is installed
324
+ * @param appDefinitionId - Id of the app that will be returned
325
+ * @example ```javascript
326
+ * const contentful = require('contentful-management')
327
+ *
328
+ * const client = contentful.createClient({
329
+ * accessToken: '<content_management_api_key>'
330
+ * })
331
+ *
332
+ * client.getAppDefinition(<'org_id'>, <'app_id'>)
333
+ * .then(appDefinition => console.log(appDefinition.name))
334
+ * .catch(console.error)
335
+ * ```
336
+ */
337
+ getAppDefinition: function getAppDefinition(params) {
338
+ return makeRequest({
339
+ entityType: 'AppDefinition',
340
+ action: 'get',
341
+ params,
342
+ }).then((data) => wrapAppDefinition(makeRequest, data));
343
+ },
344
+ /**
345
+ * Creates a personal access token
346
+ * @param data - personal access token config
347
+ * @return Promise for a Token
348
+ * @example ```javascript
349
+ * const contentful = require('contentful-management')
350
+ *
351
+ * const client = contentful.createClient({
352
+ * accessToken: '<content_management_api_key>'
353
+ * })
354
+ *
355
+ * client.createPersonalAccessToken(
356
+ * {
357
+ * "name": "My Token",
358
+ * "scope": [
359
+ * "content_management_manage"
360
+ * ]
361
+ * }
362
+ * )
363
+ * .then(personalAccessToken => console.log(personalAccessToken.token))
364
+ * .catch(console.error)
365
+ * ```
366
+ */
367
+ createPersonalAccessToken: function createPersonalAccessToken(data) {
368
+ return makeRequest({
369
+ /**
370
+ * When the `PersonalAccessToken` entity is removed, replace the `entityType` with `AccessToken`
371
+ * and update the action to `createPersonalToken` to ultilize the new entity called AccessToken.
372
+ */
373
+ entityType: 'PersonalAccessToken',
374
+ action: 'create',
375
+ params: {},
376
+ payload: data,
377
+ }).then((response) => wrapPersonalAccessToken(makeRequest, response));
378
+ },
379
+ /**
380
+ * @deprecated - use getAccessToken instead
381
+ *
382
+ * Gets a personal access token
383
+ * @param data - personal access token config
384
+ * @return Promise for a Token
385
+ * @example ```javascript
386
+ * const contentful = require('contentful-management')
387
+ *
388
+ * const client = contentful.createClient({
389
+ * accessToken: '<content_management_api_key>'
390
+ * })
391
+ *
392
+ * client.getPersonalAccessToken(tokenId)
393
+ * .then(token => console.log(token.token))
394
+ * .catch(console.error)
395
+ * ```
396
+ */
397
+ getPersonalAccessToken: function getPersonalAccessToken(tokenId) {
398
+ return makeRequest({
399
+ entityType: 'PersonalAccessToken',
400
+ action: 'get',
401
+ params: { tokenId },
402
+ }).then((data) => wrapPersonalAccessToken(makeRequest, data));
403
+ },
404
+ /**
405
+ * @deprecated - use getAccessTokens instead
406
+ *
407
+ * Gets all personal access tokens
408
+ * @return Promise for a Token
409
+ * @example ```javascript
410
+ * const contentful = require('contentful-management')
411
+ *
412
+ * const client = contentful.createClient({
413
+ * accessToken: '<content_management_api_key>'
414
+ * })
415
+ *
416
+ * client.getPersonalAccessTokens()
417
+ * .then(response => console.log(reponse.items))
418
+ * .catch(console.error)
419
+ * ```
420
+ */
421
+ getPersonalAccessTokens: function getPersonalAccessTokens() {
422
+ return makeRequest({
423
+ entityType: 'PersonalAccessToken',
424
+ action: 'getMany',
425
+ params: {},
426
+ }).then((data) => wrapPersonalAccessTokenCollection(makeRequest, data));
427
+ },
428
+ /**
429
+ * Gets a users access token
430
+ * @param data - users access token config
431
+ * @return Promise for a Token
432
+ * @example ```javascript
433
+ * const contentful = require('contentful-management')
434
+ *
435
+ * const client = contentful.createClient({
436
+ * accessToken: '<content_management_api_key>'
437
+ * })
438
+ *
439
+ * client.getAccessToken(tokenId)
440
+ * .then(token => console.log(token.token))
441
+ * .catch(console.error)
442
+ * ```
443
+ */
444
+ getAccessToken: function getAccessToken(tokenId) {
445
+ return makeRequest({
446
+ entityType: 'AccessToken',
447
+ action: 'get',
448
+ params: { tokenId },
449
+ }).then((data) => wrapAccessToken(makeRequest, data));
450
+ },
451
+ /**
452
+ * Gets all user access tokens
453
+ * @return Promise for a Token
454
+ * @example ```javascript
455
+ * const contentful = require('contentful-management')
456
+ *
457
+ * const client = contentful.createClient({
458
+ * accessToken: '<content_management_api_key>'
459
+ * })
460
+ *
461
+ * client.getAccessTokens()
462
+ * .then(response => console.log(reponse.items))
463
+ * .catch(console.error)
464
+ * ```
465
+ */
466
+ getAccessTokens: function getAccessTokens() {
467
+ return makeRequest({
468
+ entityType: 'AccessToken',
469
+ action: 'getMany',
470
+ params: {},
471
+ }).then((data) => wrapAccessTokenCollection(makeRequest, data));
472
+ },
473
+ /**
474
+ * Retrieves a list of redacted versions of access tokens for an organization, accessible to owners or administrators of an organization.
475
+ *
476
+ * @return Promise for a Token
477
+ * @example ```javascript
478
+ * const contentful = require('contentful-management')
479
+ *
480
+ * const client = contentful.createClient({
481
+ * accessToken: '<content_management_api_key>'
482
+ * })
483
+ *
484
+ * client.getOrganizationAccessTokens(organizationId)
485
+ * .then(response => console.log(reponse.items))
486
+ * .catch(console.error)
487
+ * ```
488
+ */
489
+ getOrganizationAccessTokens: function getOrganizationAccessTokens(organizationId, query = {}) {
490
+ return makeRequest({
491
+ entityType: 'AccessToken',
492
+ action: 'getManyForOrganization',
493
+ params: { organizationId, query },
494
+ }).then((data) => wrapAccessTokenCollection(makeRequest, data));
495
+ },
496
+ /**
497
+ * Get organization usage grouped by {@link UsageMetricEnum metric}
498
+ *
499
+ * @param organizationId - Id of an organization
500
+ * @param query - Query parameters
501
+ * @return Promise of a collection of usages
502
+ * @example ```javascript
503
+ *
504
+ * const contentful = require('contentful-management')
505
+ *
506
+ * const client = contentful.createClient({
507
+ * accessToken: '<content_management_api_key>'
508
+ * })
509
+ *
510
+ * client.getOrganizationUsage('<organizationId>', {
511
+ * 'metric[in]': 'cma,gql',
512
+ * 'dateRange.startAt': '2019-10-22',
513
+ * 'dateRange.endAt': '2019-11-10'
514
+ * }
515
+ * })
516
+ * .then(result => console.log(result.items))
517
+ * .catch(console.error)
518
+ * ```
519
+ */
520
+ getOrganizationUsage: function getOrganizationUsage(organizationId, query = {}) {
521
+ return makeRequest({
522
+ entityType: 'Usage',
523
+ action: 'getManyForOrganization',
524
+ params: { organizationId, query },
525
+ }).then((data) => wrapUsageCollection(makeRequest, data));
526
+ },
527
+ /**
528
+ * Get organization usage grouped by space and metric
529
+ *
530
+ * @param organizationId - Id of an organization
531
+ * @param query - Query parameters
532
+ * @return Promise of a collection of usages
533
+ * ```javascript
534
+ * const contentful = require('contentful-management')
535
+ *
536
+ * const client = contentful.createClient({
537
+ * accessToken: '<content_management_api_key>'
538
+ * })
539
+ *
540
+ * client.getSpaceUsage('<organizationId>', {
541
+ * skip: 0,
542
+ * limit: 10,
543
+ * 'metric[in]': 'cda,cpa,gql',
544
+ * 'dateRange.startAt': '2019-10-22',
545
+ * 'dateRange.endAt': '2020-11-30'
546
+ * }
547
+ * })
548
+ * .then(result => console.log(result.items))
549
+ * .catch(console.error)
550
+ * ```
551
+ */
552
+ getSpaceUsage: function getSpaceUsage(organizationId, query = {}) {
553
+ return makeRequest({
554
+ entityType: 'Usage',
555
+ action: 'getManyForSpace',
556
+ params: {
557
+ organizationId,
558
+ query,
559
+ },
560
+ }).then((data) => wrapUsageCollection(makeRequest, data));
561
+ },
562
+ /**
563
+ * Make a custom request to the Contentful management API's /spaces endpoint
564
+ * @param opts - axios request options (https://github.com/mzabriskie/axios)
565
+ * @return Promise for the response data
566
+ * ```javascript
567
+ * const contentful = require('contentful-management')
568
+ *
569
+ * const client = contentful.createClient({
570
+ * accessToken: '<content_management_api_key>'
571
+ * })
572
+ *
573
+ * client.rawRequest({
574
+ * method: 'GET',
575
+ * url: '/custom/path'
576
+ * })
577
+ * .then((responseData) => console.log(responseData))
578
+ * .catch(console.error)
579
+ * ```
580
+ */
581
+ rawRequest: function rawRequest(_a) {
582
+ var { url } = _a, config = tslib.__rest(_a, ["url"]);
583
+ return makeRequest({
584
+ entityType: 'Http',
585
+ action: 'request',
586
+ params: { url, config },
587
+ });
588
+ },
589
+ };
590
+ }
591
+
592
+ module.exports = createClientApi;