UNPKG

8.51 kBTypeScriptView Raw
1import { AxiosRequestConfig } from 'axios';
2import { Collection, MakeRequest, PaginationQueryParams, QueryOptions, QueryParams } from './common-types';
3import { Organization, OrganizationProp } from './entities/organization';
4import { CreatePersonalAccessTokenProps } from './entities/personal-access-token';
5import { Space, SpaceProps } from './entities/space';
6import { UsageQuery } from './entities/usage';
7import { UserProps } from './entities/user';
8export declare type ClientAPI = ReturnType<typeof createClientApi>;
9/**
10 * @private
11 */
12export default function createClientApi(makeRequest: MakeRequest): {
13 /**
14 * Gets all spaces
15 * @return Promise for a collection of Spaces
16 * ```javascript
17 * const contentful = require('contentful-management')
18 *
19 * const client = contentful.createClient({
20 * accessToken: '<content_management_api_key>'
21 * })
22 *
23 * client.getSpaces()
24 * .then((response) => console.log(response.items))
25 * .catch(console.error)
26 * ```
27 */
28 getSpaces: (query?: QueryOptions) => Promise<Collection<Space, SpaceProps>>;
29 /**
30 * Gets a space
31 * @param spaceId - Space ID
32 * @return Promise for a Space
33 * ```javascript
34 * const contentful = require('contentful-management')
35 *
36 * const client = contentful.createClient({
37 * accessToken: '<content_management_api_key>'
38 * })
39 *
40 * client.getSpace('<space_id>')
41 * .then((space) => console.log(space))
42 * .catch(console.error)
43 * ```
44 */
45 getSpace: (spaceId: string) => Promise<Space>;
46 /**
47 * Creates a space
48 * @param spaceData - Object representation of the Space to be created
49 * @param organizationId - Organization ID, if the associated token can manage more than one organization.
50 * @return Promise for the newly created Space
51 * @example ```javascript
52 * const contentful = require('contentful-management')
53 *
54 * const client = contentful.createClient({
55 * accessToken: '<content_management_api_key>'
56 * })
57 *
58 * client.createSpace({
59 * name: 'Name of new space'
60 * })
61 * .then((space) => console.log(space))
62 * .catch(console.error)
63 * ```
64 */
65 createSpace: (spaceData: Omit<SpaceProps, 'sys'>, organizationId: string) => Promise<Space>;
66 /**
67 * Gets an organization
68 * @param id - Organization ID
69 * @return Promise for a Organization
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.getOrganization('<org_id>')
78 * .then((org) => console.log(org))
79 * .catch(console.error)
80 * ```
81 */
82 getOrganization: (id: string) => Promise<Organization>;
83 /**
84 * Gets a collection of Organizations
85 * @return Promise for a collection of Organizations
86 * @example ```javascript
87 * const contentful = require('contentful-management')
88 *
89 * const client = contentful.createClient({
90 * accessToken: '<content_management_api_key>'
91 * })
92 *
93 * client.getOrganizations()
94 * .then(result => console.log(result.items))
95 * .catch(console.error)
96 * ```
97 */
98 getOrganizations: (query?: PaginationQueryParams['query']) => Promise<Collection<Organization, OrganizationProp>>;
99 /**
100 * Gets the authenticated user
101 * @return Promise for a User
102 * @example ```javascript
103 * const contentful = require('contentful-management')
104 *
105 * const client = contentful.createClient({
106 * accessToken: '<content_management_api_key>'
107 * })
108 *
109 * client.getCurrentUser()
110 * .then(user => console.log(user.firstName))
111 * .catch(console.error)
112 * ```
113 */
114 getCurrentUser: <T = UserProps>(params?: QueryParams | undefined) => Promise<T>;
115 /**
116 * Creates a personal access token
117 * @param data - personal access token config
118 * @return Promise for a Token
119 * @example ```javascript
120 * const contentful = require('contentful-management')
121 *
122 * const client = contentful.createClient({
123 * accessToken: '<content_management_api_key>'
124 * })
125 *
126 * client.createPersonalAccessToken(
127 * {
128 * "name": "My Token",
129 * "scope": [
130 * "content_management_manage"
131 * ]
132 * }
133 * )
134 * .then(personalAccessToken => console.log(personalAccessToken.token))
135 * .catch(console.error)
136 * ```
137 */
138 createPersonalAccessToken: (data: CreatePersonalAccessTokenProps) => Promise<import("./entities/personal-access-token").PersonalAccessToken>;
139 /**
140 * Gets a personal access token
141 * @param data - personal access token config
142 * @return Promise for a Token
143 * @example ```javascript
144 * const contentful = require('contentful-management')
145 *
146 * const client = contentful.createClient({
147 * accessToken: '<content_management_api_key>'
148 * })
149 *
150 * client.getPersonalAccessToken(tokenId)
151 * .then(token => console.log(token.token))
152 * .catch(console.error)
153 * ```
154 */
155 getPersonalAccessToken: (tokenId: string) => Promise<import("./entities/personal-access-token").PersonalAccessToken>;
156 /**
157 * Gets all personal access tokens
158 * @return Promise for a Token
159 * @example ```javascript
160 * const contentful = require('contentful-management')
161 *
162 * const client = contentful.createClient({
163 * accessToken: '<content_management_api_key>'
164 * })
165 *
166 * client.getPersonalAccessTokens()
167 * .then(response => console.log(reponse.items))
168 * .catch(console.error)
169 * ```
170 */
171 getPersonalAccessTokens: () => Promise<Collection<import("./entities/personal-access-token").PersonalAccessToken, import("./entities/personal-access-token").PersonalAccessTokenProp>>;
172 /**
173 * Get organization usage grouped by {@link UsageMetricEnum metric}
174 *
175 * @param organizationId - Id of an organization
176 * @param query - Query parameters
177 * @return Promise of a collection of usages
178 * @example ```javascript
179 *
180 * const contentful = require('contentful-management')
181 *
182 * const client = contentful.createClient({
183 * accessToken: '<content_management_api_key>'
184 * })
185 *
186 * client.getOrganizationUsage('<organizationId>', {
187 * 'metric[in]': 'cma,gql',
188 * 'dateRange.startAt': '2019-10-22',
189 * 'dateRange.endAt': '2019-11-10'
190 * }
191 * })
192 * .then(result => console.log(result.items))
193 * .catch(console.error)
194 * ```
195 */
196 getOrganizationUsage: (organizationId: string, query?: QueryOptions) => Promise<Collection<import("./entities/usage").Usage, import("./entities/usage").UsageProps>>;
197 /**
198 * Get organization usage grouped by space and metric
199 *
200 * @param organizationId - Id of an organization
201 * @param query - Query parameters
202 * @return Promise of a collection of usages
203 * ```javascript
204 * const contentful = require('contentful-management')
205 *
206 * const client = contentful.createClient({
207 * accessToken: '<content_management_api_key>'
208 * })
209 *
210 * client.getSpaceUsage('<organizationId>', {
211 * skip: 0,
212 * limit: 10,
213 * 'metric[in]': 'cda,cpa,gql',
214 * 'dateRange.startAt': '2019-10-22',
215 * 'dateRange.endAt': '2020-11-30'
216 * }
217 * })
218 * .then(result => console.log(result.items))
219 * .catch(console.error)
220 * ```
221 */
222 getSpaceUsage: (organizationId: string, query?: UsageQuery) => Promise<Collection<import("./entities/usage").Usage, import("./entities/usage").UsageProps>>;
223 /**
224 * Make a custom request to the Contentful management API's /spaces endpoint
225 * @param opts - axios request options (https://github.com/mzabriskie/axios)
226 * @return Promise for the response data
227 * ```javascript
228 * const contentful = require('contentful-management')
229 *
230 * const client = contentful.createClient({
231 * accessToken: '<content_management_api_key>'
232 * })
233 *
234 * client.rawRequest({
235 * method: 'GET',
236 * url: '/custom/path'
237 * })
238 * .then((responseData) => console.log(responseData))
239 * .catch(console.error)
240 * ```
241 */
242 rawRequest: ({ url, ...config }: AxiosRequestConfig & {
243 url: string;
244 }) => Promise<any>;
245};