contentful-management
Version:
Client for Contentful's Content Management API
170 lines (169 loc) • 6.94 kB
TypeScript
import type { MakeRequest, QueryOptions, SpaceQueryOptions } from './common-types';
import type { CreateAppBundleProps } from './entities/app-bundle';
import type { UpsertResourceProviderProps } from './entities/resource-provider';
/**
* @private
*/
export type ContentfulAppDefinitionAPI = ReturnType<typeof createAppDefinitionApi>;
/**
* @private
*/
export default function createAppDefinitionApi(makeRequest: MakeRequest): {
/**
* Sends an update to the server with any changes made to the object's properties
* @return Object returned from the server with updated changes.
* @example ```javascript
* const contentful = require('contentful-management')
*
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
*
* client.getOrganization('<org_id>')
* .then((org) => org.getAppDefinition('<app_def_id>'))
* .then((appDefinition) => {
* appDefinition.name = 'New App Definition name'
* return appDefinition.update()
* })
* .then((appDefinition) => console.log(`App Definition ${appDefinition.sys.id} updated.`))
* .catch(console.error)
* ```
*/
update: () => Promise<import("./entities/app-definition").AppDefinition>;
/**
* Deletes this object on the server.
* @return Promise for the deletion. It contains no data, but the Promise error case should be handled.
* @example ```javascript
* const contentful = require('contentful-management')
*
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
*
* client.getOrganization('<org_id>')
* .then((org) => org.getAppDefinition('<app_def_id>'))
* .then((appDefinition) => appDefinition.delete())
* .then(() => console.log(`App Definition deleted.`))
* .catch(console.error)
* ```
*/
delete: () => Promise<any>;
/**
* Gets an app bundle
* @param id - AppBundle ID
* @return Promise for an AppBundle
* @example ```javascript
* const contentful = require('contentful-management')
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
*
* client.getOrganization('<org_id>')
* .then((org) => org.getAppDefinition('<app_def_id>'))
* .then((appDefinition) => appDefinition.getAppBundle('<app_upload_id>'))
* .then((appBundle) => console.log(appBundle))
* .catch(console.error)
* ```
*/
getAppBundle(id: string): Promise<import("./entities/app-bundle").AppBundle>;
/**
* Gets a collection of AppBundles
* @return Promise for a collection of AppBundles
* @example ```javascript
* const contentful = require('contentful-management')
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
*
* client.getOrganization('<org_id>')
* .then((org) => org.getAppDefinition('<app_def_id>'))
* .then((appDefinition) => appDefinition.getAppBundles())
* .then((response) => console.log(response.items))
* .catch(console.error)
* ```
*/
getAppBundles(query?: QueryOptions): Promise<import("./common-types").Collection<import("./entities/app-bundle").AppBundle, import("./entities/app-bundle").AppBundleProps>>;
/**
* Creates an app bundle
* @param Object representation of the App Bundle to be created
* @return Promise for the newly created AppBundle
* @example ```javascript
* const contentful = require('contentful-management')
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
* client.getOrganization('<org_id>')
* .then((org) => org.getAppDefinition('<app_def_id>'))
* .then((appDefinition) => appDefinition.createAppBundle('<app_upload_id>'))
* .then((appBundle) => console.log(appBundle))
* .catch(console.error)
* ```
*/
createAppBundle(data: CreateAppBundleProps): Promise<import("./entities/app-bundle").AppBundle>;
/**
* Gets a list of App Installations across an org for given organization and App Definition
* If a spaceId is provided in the query object, it will return the App Installations for that specific space.
* @return Promise for the newly created AppBundle
* @example ```javascript
* const contentful = require('contentful-management')
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
* client.getAppDefinition('<organization_id>', '<app_definition_id>')
* .then((appDefinition) => appDefinition.getInstallationsForOrg(
* { spaceId: '<space_id>' } // optional
* ))
* .then((appInstallationsForOrg) => console.log(appInstallationsForOrg.items))
* .catch(console.error)
* ```
*/
getInstallationsForOrg(query?: SpaceQueryOptions): Promise<import("./entities/app-definition").AppInstallationsForOrganizationProps>;
/**
* Creates or updates a resource provider
* @param data representation of the ResourceProvider
* @return Promise for the newly created or updated ResourceProvider
* @example ```javascript
* const contentful = require('contentful-management')
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
*
* // You need a valid AppDefinition with an activated AppBundle that has a contentful function configured
* client.getOrganization('<org_id>')
* .then((org) => org.getAppDefinition('<app_def_id>'))
* .then((appDefinition) => appDefinition.upsertResourceProvider({
* sys: {
* id: '<resource_provider_id>'
* },
* type: 'function',
* function: {
* sys: {
* id: '<contentful_function_id>',
* type: 'Link'
* linkType: 'Function'
* }
* }
* }))
* .then((resourceProvider) => console.log(resourceProvider))
* .catch(console.error)
* ```
*/
upsertResourceProvider(data: UpsertResourceProviderProps): Promise<import("./entities/resource-provider").ResourceProvider>;
/**
* Gets a Resource Provider
* @return Promise for a Resource Provider
* @example ```javascript
* const contentful = require('contentful-management')
* const client = contentful.createClient({
* accessToken: '<content_management_api_key>'
* })
*
* client.getOrganization('<org_id>')
* .then((org) => org.getAppDefinition('<app_def_id>'))
* .then((appDefinition) => appDefinition.getResourceProvider())
* .then((resourceProvider) => console.log(resourceProvider))
* .catch(console.error)
* ```
*/
getResourceProvider(): Promise<import("./entities/resource-provider").ResourceProvider>;
};