UNPKG

14.3 kBTypeScriptView Raw
1import type { Collection, MakeRequest, PaginationQueryParams, QueryOptions, QueryParams, GetAppDefinitionParams, CursorPaginatedCollection, GetEnvironmentTemplateParams, BasicCursorPaginationOptions } from './common-types';
2import type { Organization, OrganizationProps } from './entities/organization';
3import type { CreatePersonalAccessTokenProps } from './entities/personal-access-token';
4import type { Space, SpaceProps } from './entities/space';
5import type { AppDefinition } from './entities/app-definition';
6import type { UsageQuery } from './entities/usage';
7import type { UserProps } from './entities/user';
8import type { CreateEnvironmentTemplateProps, EnvironmentTemplate, EnvironmentTemplateProps } from './entities/environment-template';
9import type { RawAxiosRequestConfig } from 'axios';
10export type ClientAPI = ReturnType<typeof createClientApi>;
11type CreateSpaceProps = Omit<SpaceProps, 'sys'> & {
12 defaultLocale?: string;
13};
14/**
15 * @private
16 */
17export default function createClientApi(makeRequest: MakeRequest): {
18 /**
19 * Gets all environment templates for a given organization with the lasted version
20 * @param organizationId - Organization ID
21 * @return Promise for a collection of EnvironmentTemplates
22 * ```javascript
23 * const contentful = require('contentful-management')
24 *
25 * const client = contentful.createClient({
26 * accessToken: '<content_management_api_key>'
27 * })
28 *
29 * client.getEnvironmentTemplates('<organization_id>')
30 * .then((response) => console.log(response.items))
31 * .catch(console.error)
32 * ```
33 */
34 getEnvironmentTemplates: (organizationId: string, query?: BasicCursorPaginationOptions & {
35 select?: string;
36 }) => Promise<CursorPaginatedCollection<EnvironmentTemplate, EnvironmentTemplateProps>>;
37 /**
38 * Gets the lasted version environment template if params.version is not specified
39 * @param params.organizationId - Organization ID
40 * @param params.environmentTemplateId - Environment template ID
41 * @param [params.version] - Template version number to return a specific version of the environment template
42 * @return Promise for a EnvironmentTemplate
43 * ```javascript
44 * const contentful = require('contentful-management')
45 *
46 * const client = contentful.createClient({
47 * accessToken: '<content_management_api_key>'
48 * })
49 *
50 * client.getEnvironmentTemplate({
51 * organizationId: '<organization_id>',
52 * environmentTemplateId: '<environment_template_id>',
53 * version: version>
54 * })
55 * .then((space) => console.log(space))
56 * .catch(console.error)
57 * ```
58 */
59 getEnvironmentTemplate: ({ organizationId, environmentTemplateId, version, query, }: GetEnvironmentTemplateParams & {
60 version?: number;
61 query?: {
62 select?: string;
63 };
64 }) => Promise<EnvironmentTemplate>;
65 /**
66 * Creates an environment template
67 * @param organizationId - Organization ID
68 * @param environmentTemplateData - Object representation of the environment template to be created
69 * @return Promise for the newly created EnvironmentTemplate
70 * @example ```javascript
71 * const contentful = require('contentful-management')
72 *
73 * const client = contentful.createClient({
74 * accessToken: '<content_management_api_key>'
75 * })
76 *
77 * client.createEnvironmentTemplate('<organization_id>', {<environment_template_date>})
78 * .then((environmentTemplate) => console.log(environmentTemplate))
79 * .catch(console.error)
80 * ```
81 */
82 createEnvironmentTemplate: (organizationId: string, environmentTemplateData: CreateEnvironmentTemplateProps) => Promise<EnvironmentTemplate>;
83 /**
84 * Gets all spaces
85 * @return Promise for a collection of Spaces
86 * ```javascript
87 * const contentful = require('contentful-management')
88 *
89 * const client = contentful.createClient({
90 * accessToken: '<content_management_api_key>'
91 * })
92 *
93 * client.getSpaces()
94 * .then((response) => console.log(response.items))
95 * .catch(console.error)
96 * ```
97 */
98 getSpaces: (query?: QueryOptions) => Promise<Collection<Space, SpaceProps>>;
99 /**
100 * Gets a space
101 * @param spaceId - Space ID
102 * @return Promise for a Space
103 * ```javascript
104 * const contentful = require('contentful-management')
105 *
106 * const client = contentful.createClient({
107 * accessToken: '<content_management_api_key>'
108 * })
109 *
110 * client.getSpace('<space_id>')
111 * .then((space) => console.log(space))
112 * .catch(console.error)
113 * ```
114 */
115 getSpace: (spaceId: string) => Promise<Space>;
116 /**
117 * Creates a space
118 * @param spaceData - Object representation of the Space to be created
119 * @param organizationId - Organization ID, if the associated token can manage more than one organization.
120 * @return Promise for the newly created Space
121 * @example ```javascript
122 * const contentful = require('contentful-management')
123 *
124 * const client = contentful.createClient({
125 * accessToken: '<content_management_api_key>'
126 * })
127 *
128 * client.createSpace({
129 * name: 'Name of new space'
130 * })
131 * .then((space) => console.log(space))
132 * .catch(console.error)
133 * ```
134 */
135 createSpace: (spaceData: CreateSpaceProps, organizationId: string) => Promise<Space>;
136 /**
137 * Gets an organization
138 * @param id - Organization ID
139 * @return Promise for a Organization
140 * @example ```javascript
141 * const contentful = require('contentful-management')
142 *
143 * const client = contentful.createClient({
144 * accessToken: '<content_management_api_key>'
145 * })
146 *
147 * client.getOrganization('<org_id>')
148 * .then((org) => console.log(org))
149 * .catch(console.error)
150 * ```
151 */
152 getOrganization: (id: string) => Promise<Organization>;
153 /**
154 * Gets a collection of Organizations
155 * @return Promise for a collection of Organizations
156 * @example ```javascript
157 * const contentful = require('contentful-management')
158 *
159 * const client = contentful.createClient({
160 * accessToken: '<content_management_api_key>'
161 * })
162 *
163 * client.getOrganizations()
164 * .then(result => console.log(result.items))
165 * .catch(console.error)
166 * ```
167 */
168 getOrganizations: (query?: PaginationQueryParams["query"]) => Promise<Collection<Organization, OrganizationProps>>;
169 /**
170 * Gets the authenticated user
171 * @return Promise for a User
172 * @example ```javascript
173 * const contentful = require('contentful-management')
174 *
175 * const client = contentful.createClient({
176 * accessToken: '<content_management_api_key>'
177 * })
178 *
179 * client.getCurrentUser()
180 * .then(user => console.log(user.firstName))
181 * .catch(console.error)
182 * ```
183 */
184 getCurrentUser: <T = UserProps>(params?: QueryParams) => Promise<T>;
185 /**
186 * Gets App Definition
187 * @return Promise for App Definition
188 * @param organizationId - Id of the organization where the app is installed
189 * @param appDefinitionId - Id of the app that will be returned
190 * @example ```javascript
191 * const contentful = require('contentful-management')
192 *
193 * const client = contentful.createClient({
194 * accessToken: '<content_management_api_key>'
195 * })
196 *
197 * client.getAppDefinition(<'org_id'>, <'app_id'>)
198 * .then(appDefinition => console.log(appDefinition.name))
199 * .catch(console.error)
200 * ```
201 */
202 getAppDefinition: (params: GetAppDefinitionParams) => Promise<AppDefinition>;
203 /**
204 * Creates a personal access token
205 * @param data - personal access token config
206 * @return Promise for a Token
207 * @example ```javascript
208 * const contentful = require('contentful-management')
209 *
210 * const client = contentful.createClient({
211 * accessToken: '<content_management_api_key>'
212 * })
213 *
214 * client.createPersonalAccessToken(
215 * {
216 * "name": "My Token",
217 * "scope": [
218 * "content_management_manage"
219 * ]
220 * }
221 * )
222 * .then(personalAccessToken => console.log(personalAccessToken.token))
223 * .catch(console.error)
224 * ```
225 */
226 createPersonalAccessToken: (data: CreatePersonalAccessTokenProps) => Promise<import("./entities/personal-access-token").PersonalAccessToken>;
227 /**
228 * @deprecated - use getAccessToken instead
229 *
230 * Gets a personal access token
231 * @param data - personal access token config
232 * @return Promise for a Token
233 * @example ```javascript
234 * const contentful = require('contentful-management')
235 *
236 * const client = contentful.createClient({
237 * accessToken: '<content_management_api_key>'
238 * })
239 *
240 * client.getPersonalAccessToken(tokenId)
241 * .then(token => console.log(token.token))
242 * .catch(console.error)
243 * ```
244 */
245 getPersonalAccessToken: (tokenId: string) => Promise<import("./entities/personal-access-token").PersonalAccessToken>;
246 /**
247 * @deprecated - use getAccessTokens instead
248 *
249 * Gets all personal access tokens
250 * @return Promise for a Token
251 * @example ```javascript
252 * const contentful = require('contentful-management')
253 *
254 * const client = contentful.createClient({
255 * accessToken: '<content_management_api_key>'
256 * })
257 *
258 * client.getPersonalAccessTokens()
259 * .then(response => console.log(reponse.items))
260 * .catch(console.error)
261 * ```
262 */
263 getPersonalAccessTokens: () => Promise<Collection<import("./entities/personal-access-token").PersonalAccessToken, import("./entities/personal-access-token").PersonalAccessTokenProps>>;
264 /**
265 * Gets a users access token
266 * @param data - users access token config
267 * @return Promise for a Token
268 * @example ```javascript
269 * const contentful = require('contentful-management')
270 *
271 * const client = contentful.createClient({
272 * accessToken: '<content_management_api_key>'
273 * })
274 *
275 * client.getAccessToken(tokenId)
276 * .then(token => console.log(token.token))
277 * .catch(console.error)
278 * ```
279 */
280 getAccessToken: (tokenId: string) => Promise<import("./export-types").AccessToken>;
281 /**
282 * Gets all user access tokens
283 * @return Promise for a Token
284 * @example ```javascript
285 * const contentful = require('contentful-management')
286 *
287 * const client = contentful.createClient({
288 * accessToken: '<content_management_api_key>'
289 * })
290 *
291 * client.getAccessTokens()
292 * .then(response => console.log(reponse.items))
293 * .catch(console.error)
294 * ```
295 */
296 getAccessTokens: () => Promise<Collection<import("./export-types").AccessToken, import("./export-types").AccessTokenProp>>;
297 /**
298 * Retrieves a list of redacted versions of access tokens for an organization, accessible to owners or administrators of an organization.
299 *
300 * @return Promise for a Token
301 * @example ```javascript
302 * const contentful = require('contentful-management')
303 *
304 * const client = contentful.createClient({
305 * accessToken: '<content_management_api_key>'
306 * })
307 *
308 * client.getOrganizationAccessTokens(organizationId)
309 * .then(response => console.log(reponse.items))
310 * .catch(console.error)
311 * ```
312 */
313 getOrganizationAccessTokens: (organizationId: string, query?: QueryOptions) => Promise<Collection<import("./export-types").AccessToken, import("./export-types").AccessTokenProp>>;
314 /**
315 * Get organization usage grouped by {@link UsageMetricEnum metric}
316 *
317 * @param organizationId - Id of an organization
318 * @param query - Query parameters
319 * @return Promise of a collection of usages
320 * @example ```javascript
321 *
322 * const contentful = require('contentful-management')
323 *
324 * const client = contentful.createClient({
325 * accessToken: '<content_management_api_key>'
326 * })
327 *
328 * client.getOrganizationUsage('<organizationId>', {
329 * 'metric[in]': 'cma,gql',
330 * 'dateRange.startAt': '2019-10-22',
331 * 'dateRange.endAt': '2019-11-10'
332 * }
333 * })
334 * .then(result => console.log(result.items))
335 * .catch(console.error)
336 * ```
337 */
338 getOrganizationUsage: (organizationId: string, query?: QueryOptions) => Promise<Collection<import("./entities/usage").Usage, import("./entities/usage").UsageProps>>;
339 /**
340 * Get organization usage grouped by space and metric
341 *
342 * @param organizationId - Id of an organization
343 * @param query - Query parameters
344 * @return Promise of a collection of usages
345 * ```javascript
346 * const contentful = require('contentful-management')
347 *
348 * const client = contentful.createClient({
349 * accessToken: '<content_management_api_key>'
350 * })
351 *
352 * client.getSpaceUsage('<organizationId>', {
353 * skip: 0,
354 * limit: 10,
355 * 'metric[in]': 'cda,cpa,gql',
356 * 'dateRange.startAt': '2019-10-22',
357 * 'dateRange.endAt': '2020-11-30'
358 * }
359 * })
360 * .then(result => console.log(result.items))
361 * .catch(console.error)
362 * ```
363 */
364 getSpaceUsage: (organizationId: string, query?: UsageQuery) => Promise<Collection<import("./entities/usage").Usage, import("./entities/usage").UsageProps>>;
365 /**
366 * Make a custom request to the Contentful management API's /spaces endpoint
367 * @param opts - axios request options (https://github.com/mzabriskie/axios)
368 * @return Promise for the response data
369 * ```javascript
370 * const contentful = require('contentful-management')
371 *
372 * const client = contentful.createClient({
373 * accessToken: '<content_management_api_key>'
374 * })
375 *
376 * client.rawRequest({
377 * method: 'GET',
378 * url: '/custom/path'
379 * })
380 * .then((responseData) => console.log(responseData))
381 * .catch(console.error)
382 * ```
383 */
384 rawRequest: ({ url, ...config }: RawAxiosRequestConfig & {
385 url: string;
386 }) => Promise<any>;
387};
388export {};