import type { Collection, MakeRequest, PaginationQueryParams, QueryOptions, QueryParams, GetAppDefinitionParams, CursorPaginatedCollection, GetEnvironmentTemplateParams, BasicCursorPaginationOptions } from './common-types'; import type { Organization, OrganizationProps } from './entities/organization'; import type { CreatePersonalAccessTokenProps } from './entities/personal-access-token'; import type { Space, SpaceProps } from './entities/space'; import type { AppDefinition } from './entities/app-definition'; import type { UsageQuery } from './entities/usage'; import type { UserProps } from './entities/user'; import type { CreateEnvironmentTemplateProps, EnvironmentTemplate, EnvironmentTemplateProps } from './entities/environment-template'; import type { RawAxiosRequestConfig } from 'axios'; export type ClientAPI = ReturnType; type CreateSpaceProps = Omit & { defaultLocale?: string; }; /** * @private */ export default function createClientApi(makeRequest: MakeRequest): { /** * Gets all environment templates for a given organization with the lasted version * @param organizationId - Organization ID * @return Promise for a collection of EnvironmentTemplates * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getEnvironmentTemplates('') * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getEnvironmentTemplates: (organizationId: string, query?: BasicCursorPaginationOptions & { select?: string; }) => Promise>; /** * Gets the lasted version environment template if params.version is not specified * @param params.organizationId - Organization ID * @param params.environmentTemplateId - Environment template ID * @param [params.version] - Template version number to return a specific version of the environment template * @return Promise for a EnvironmentTemplate * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getEnvironmentTemplate({ * organizationId: '', * environmentTemplateId: '', * version: version> * }) * .then((space) => console.log(space)) * .catch(console.error) * ``` */ getEnvironmentTemplate: ({ organizationId, environmentTemplateId, version, query, }: GetEnvironmentTemplateParams & { version?: number; query?: { select?: string; }; }) => Promise; /** * Creates an environment template * @param organizationId - Organization ID * @param environmentTemplateData - Object representation of the environment template to be created * @return Promise for the newly created EnvironmentTemplate * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.createEnvironmentTemplate('', {}) * .then((environmentTemplate) => console.log(environmentTemplate)) * .catch(console.error) * ``` */ createEnvironmentTemplate: (organizationId: string, environmentTemplateData: CreateEnvironmentTemplateProps) => Promise; /** * Gets all spaces * @return Promise for a collection of Spaces * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpaces() * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getSpaces: (query?: QueryOptions) => Promise>; /** * Gets a space * @param spaceId - Space ID * @return Promise for a Space * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => console.log(space)) * .catch(console.error) * ``` */ getSpace: (spaceId: string) => Promise; /** * Creates a space * @param spaceData - Object representation of the Space to be created * @param organizationId - Organization ID, if the associated token can manage more than one organization. * @return Promise for the newly created Space * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.createSpace({ * name: 'Name of new space' * }) * .then((space) => console.log(space)) * .catch(console.error) * ``` */ createSpace: (spaceData: CreateSpaceProps, organizationId: string) => Promise; /** * Gets an organization * @param id - Organization ID * @return Promise for a Organization * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getOrganization('') * .then((org) => console.log(org)) * .catch(console.error) * ``` */ getOrganization: (id: string) => Promise; /** * Gets a collection of Organizations * @return Promise for a collection of Organizations * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getOrganizations() * .then(result => console.log(result.items)) * .catch(console.error) * ``` */ getOrganizations: (query?: PaginationQueryParams["query"]) => Promise>; /** * Gets the authenticated user * @return Promise for a User * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getCurrentUser() * .then(user => console.log(user.firstName)) * .catch(console.error) * ``` */ getCurrentUser: (params?: QueryParams) => Promise; /** * Gets App Definition * @return Promise for App Definition * @param organizationId - Id of the organization where the app is installed * @param appDefinitionId - Id of the app that will be returned * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getAppDefinition(<'org_id'>, <'app_id'>) * .then(appDefinition => console.log(appDefinition.name)) * .catch(console.error) * ``` */ getAppDefinition: (params: GetAppDefinitionParams) => Promise; /** * Creates a personal access token * @param data - personal access token config * @return Promise for a Token * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.createPersonalAccessToken( * { * "name": "My Token", * "scope": [ * "content_management_manage" * ] * } * ) * .then(personalAccessToken => console.log(personalAccessToken.token)) * .catch(console.error) * ``` */ createPersonalAccessToken: (data: CreatePersonalAccessTokenProps) => Promise; /** * @deprecated - use getAccessToken instead * * Gets a personal access token * @param data - personal access token config * @return Promise for a Token * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getPersonalAccessToken(tokenId) * .then(token => console.log(token.token)) * .catch(console.error) * ``` */ getPersonalAccessToken: (tokenId: string) => Promise; /** * @deprecated - use getAccessTokens instead * * Gets all personal access tokens * @return Promise for a Token * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getPersonalAccessTokens() * .then(response => console.log(reponse.items)) * .catch(console.error) * ``` */ getPersonalAccessTokens: () => Promise>; /** * Gets a users access token * @param data - users access token config * @return Promise for a Token * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getAccessToken(tokenId) * .then(token => console.log(token.token)) * .catch(console.error) * ``` */ getAccessToken: (tokenId: string) => Promise; /** * Gets all user access tokens * @return Promise for a Token * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getAccessTokens() * .then(response => console.log(reponse.items)) * .catch(console.error) * ``` */ getAccessTokens: () => Promise>; /** * Retrieves a list of redacted versions of access tokens for an organization, accessible to owners or administrators of an organization. * * @return Promise for a Token * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getOrganizationAccessTokens(organizationId) * .then(response => console.log(reponse.items)) * .catch(console.error) * ``` */ getOrganizationAccessTokens: (organizationId: string, query?: QueryOptions) => Promise>; /** * Get organization usage grouped by {@link UsageMetricEnum metric} * * @param organizationId - Id of an organization * @param query - Query parameters * @return Promise of a collection of usages * @example ```javascript * * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getOrganizationUsage('', { * 'metric[in]': 'cma,gql', * 'dateRange.startAt': '2019-10-22', * 'dateRange.endAt': '2019-11-10' * } * }) * .then(result => console.log(result.items)) * .catch(console.error) * ``` */ getOrganizationUsage: (organizationId: string, query?: QueryOptions) => Promise>; /** * Get organization usage grouped by space and metric * * @param organizationId - Id of an organization * @param query - Query parameters * @return Promise of a collection of usages * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpaceUsage('', { * skip: 0, * limit: 10, * 'metric[in]': 'cda,cpa,gql', * 'dateRange.startAt': '2019-10-22', * 'dateRange.endAt': '2020-11-30' * } * }) * .then(result => console.log(result.items)) * .catch(console.error) * ``` */ getSpaceUsage: (organizationId: string, query?: UsageQuery) => Promise>; /** * Make a custom request to the Contentful management API's /spaces endpoint * @param opts - axios request options (https://github.com/mzabriskie/axios) * @return Promise for the response data * ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.rawRequest({ * method: 'GET', * url: '/custom/path' * }) * .then((responseData) => console.log(responseData)) * .catch(console.error) * ``` */ rawRequest: ({ url, ...config }: RawAxiosRequestConfig & { url: string; }) => Promise; }; export {};