/** * Contentful Space API. Contains methods to access any operations at a space * level, such as creating and reading entities contained in a space. */ import { MakeRequest, PaginationQueryOptions, QueryOptions } from './common-types'; import { CreateApiKeyProps } from './entities/api-key'; import { CreateEnvironmentProps } from './entities/environment'; import { CreateEnvironmentAliasProps } from './entities/environment-alias'; import { CreateRoleProps, RoleProps } from './entities/role'; import { ScheduledActionProps, ScheduledActionQueryOptions } from './entities/scheduled-action'; import { CreateSpaceMembershipProps } from './entities/space-membership'; import { CreateTeamSpaceMembershipProps } from './entities/team-space-membership'; import { CreateWebhooksProps } from './entities/webhook'; /** * @private */ export declare type ContentfulSpaceAPI = ReturnType; /** * Creates API object with methods to access the Space API * @param {MakeRequest} makeRequest - function to make requests via an adapter * @return {ContentfulSpaceAPI} * @private */ export default function createSpaceApi(makeRequest: MakeRequest): { /** * Deletes the space * @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: '' * }) * * client.getSpace('') * .then((space) => space.delete()) * .then(() => console.log('Space deleted.')) * .catch(console.error) * ``` */ delete: () => Promise; /** * Updates the space * @return Promise for the updated space. * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => { * space.name = 'New name' * return space.update() * }) * .then((space) => console.log(`Space ${space.sys.id} renamed.`) * .catch(console.error) * ``` */ update: () => Promise; /** * Gets an environment * @param id - Environment ID * @return Promise for an Environment * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironment('')) * .then((environment) => console.log(environment)) * .catch(console.error) * ``` */ getEnvironment(environmentId: string): Promise; /** * Gets a collection of Environments * @return Promise for a collection of Environment * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironments()) * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getEnvironments(query?: PaginationQueryOptions): Promise>; /** * Creates an Environement * @param data - Object representation of the Environment to be created * @return Promise for the newly created Environment * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createEnvironment({ name: 'Staging' })) * .then((environment) => console.log(environment)) * .catch(console.error) * ``` */ createEnvironment(data?: CreateEnvironmentProps): Promise; /** * Creates an Environment with a custom ID * @param id - Environment ID * @param data - Object representation of the Environment to be created * @param sourceEnvironmentId - ID of the source environment that will be copied to create the new environment. Default is "master" * @return Promise for the newly created Environment * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createEnvironmentWithId('', { name: 'Staging'}, 'master')) * .then((environment) => console.log(environment)) * .catch(console.error) * ``` */ createEnvironmentWithId(id: string, data: CreateEnvironmentProps, sourceEnvironmentId?: string | undefined): Promise; /** * Gets a Webhook * @param id - Webhook ID * @return Promise for a Webhook * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getWebhook('')) * .then((webhook) => console.log(webhook)) * .catch(console.error) * ``` */ getWebhook(id: string): Promise; /** * Gets a collection of Webhooks * @return Promise for a collection of Webhooks * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getWebhooks()) * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getWebhooks(): Promise>; /** * Creates a Webhook * @param data - Object representation of the Webhook to be created * @return Promise for the newly created Webhook * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.createWebhook({ * 'name': 'My webhook', * 'url': 'https://www.example.com/test', * 'topics': [ * 'Entry.create', * 'ContentType.create', * '*.publish', * 'Asset.*' * ] * })) * .then((webhook) => console.log(webhook)) * .catch(console.error) * ``` */ createWebhook(data: CreateWebhooksProps): Promise; /** * Creates a Webhook with a custom ID * @param id - Webhook ID * @param data - Object representation of the Webhook to be created * @return Promise for the newly created Webhook * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.createWebhookWithId('', { * 'name': 'My webhook', * 'url': 'https://www.example.com/test', * 'topics': [ * 'Entry.create', * 'ContentType.create', * '*.publish', * 'Asset.*' * ] * })) * .then((webhook) => console.log(webhook)) * .catch(console.error) * ``` */ createWebhookWithId(id: string, data: CreateWebhooksProps): Promise; /** * Gets a Role * @param id - Role ID * @return Promise for a Role * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createRole({ * fields: { * title: { * 'en-US': 'Role title' * } * } * })) * .then((role) => console.log(role)) * .catch(console.error) * ``` */ getRole(id: string): Promise; /** * Gets a collection of Roles * @return Promise for a collection of Roles * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getRoles()) * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getRoles(query?: QueryOptions): Promise>; /** * Creates a Role * @param data - Object representation of the Role to be created * @return Promise for the newly created Role * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * client.getSpace('') * .then((space) => space.createRole({ * name: 'My Role', * description: 'foobar role', * permissions: { * ContentDelivery: 'all', * ContentModel: ['read'], * Settings: [] * }, * policies: [ * { * effect: 'allow', * actions: 'all', * constraint: { * and: [ * { * equals: [ * { doc: 'sys.type' }, * 'Entry' * ] * }, * { * equals: [ * { doc: 'sys.type' }, * 'Asset' * ] * } * ] * } * } * ] * })) * .then((role) => console.log(role)) * .catch(console.error) * ``` */ createRole(data: CreateRoleProps): Promise; /** * Creates a Role with a custom ID * @param id - Role ID * @param data - Object representation of the Role to be created * @return Promise for the newly created Role * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * client.getSpace('') * .then((space) => space.createRoleWithId('', { * name: 'My Role', * description: 'foobar role', * permissions: { * ContentDelivery: 'all', * ContentModel: ['read'], * Settings: [] * }, * policies: [ * { * effect: 'allow', * actions: 'all', * constraint: { * and: [ * { * equals: [ * { doc: 'sys.type' }, * 'Entry' * ] * }, * { * equals: [ * { doc: 'sys.type' }, * 'Asset' * ] * } * ] * } * } * ] * })) * .then((role) => console.log(role)) * .catch(console.error) * ``` */ createRoleWithId(id: string, roleData: Omit): Promise; /** * Gets a User * @param userId - User ID * @return Promise for a User * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getSpaceUser('id')) * .then((user) => console.log(user)) * .catch(console.error) * ``` */ getSpaceUser(userId: string): Promise; /** * Gets a collection of Users in a space * @param query - Object with search parameters. Check the JS SDK tutorial and the REST API reference for more details. * @return Promise a collection of Users in a space * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getSpaceUsers(query)) * .then((data) => console.log(data)) * .catch(console.error) * ``` */ getSpaceUsers(query?: QueryOptions): Promise>; /** * Gets a collection of teams for a space * @param query * @return Promise for a collection of teams for a space * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getTeams()) * .then((teamsCollection) => console.log(teamsCollection)) * .catch(console.error) * ``` */ getTeams(query?: QueryOptions): Promise>; /** * Gets a Space Member * @param id Get Space Member by user_id * @return Promise for a Space Member * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getSpaceMember(id)) * .then((spaceMember) => console.log(spaceMember)) * .catch(console.error) * ``` */ getSpaceMember(id: string): Promise; /** * Gets a collection of Space Members * @param query * @return Promise for a collection of Space Members * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getSpaceMembers({'limit': 100})) * .then((spaceMemberCollection) => console.log(spaceMemberCollection)) * .catch(console.error) * ``` */ getSpaceMembers(query?: QueryOptions): Promise>; /** * Gets a Space Membership * Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user). * @param id - Space Membership ID * @return Promise for a Space Membership * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getSpaceMembership('id')) * .then((spaceMembership) => console.log(spaceMembership)) * .catch(console.error) * ``` */ getSpaceMembership(id: string): Promise; /** * Gets a collection of Space Memberships * Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user). * @param query - Object with search parameters. Check the JS SDK tutorial and the REST API reference for more details. * @return Promise for a collection of Space Memberships * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getSpaceMemberships({'limit': 100})) // you can add more queries as 'key': 'value' * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getSpaceMemberships(query?: QueryOptions): Promise>; /** * Creates a Space Membership * Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user). * @param data - Object representation of the Space Membership to be created * @return Promise for the newly created Space Membership * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createSpaceMembership({ * admin: false, * roles: [ * { * type: 'Link', * linkType: 'Role', * id: '' * } * ], * email: 'foo@example.com' * })) * .then((spaceMembership) => console.log(spaceMembership)) * .catch(console.error) * ``` */ createSpaceMembership(data: CreateSpaceMembershipProps): Promise; /** * Creates a Space Membership with a custom ID * Warning: the user attribute in the space membership root is deprecated. The attribute has been moved inside the sys object (i.e. sys.user). * @param id - Space Membership ID * @param data - Object representation of the Space Membership to be created * @return Promise for the newly created Space Membership * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createSpaceMembershipWithId('', { * admin: false, * roles: [ * { * type: 'Link', * linkType: 'Role', * id: '' * } * ], * email: 'foo@example.com' * })) * .then((spaceMembership) => console.log(spaceMembership)) * .catch(console.error) * ``` */ createSpaceMembershipWithId(id: string, data: CreateSpaceMembershipProps): Promise; /** * Gets a Team Space Membership * @param id - Team Space Membership ID * @return Promise for a Team Space Membership * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getTeamSpaceMembership('team_space_membership_id')) * .then((teamSpaceMembership) => console.log(teamSpaceMembership)) * .catch(console.error) * ``` */ getTeamSpaceMembership(teamSpaceMembershipId: string): Promise; /** * Gets a collection of Team Space Memberships * @param query - Object with search parameters. Check the JS SDK tutorial and the REST API reference for more details. * @return Promise for a collection of Team Space Memberships * @example ```javascript * const contentful = require('contentful-management') * * client.getSpace('') * .then((space) => space.getTeamSpaceMemberships()) * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getTeamSpaceMemberships(query?: QueryOptions): Promise>; /** * Creates a Team Space Membership * @param id - Team ID * @param data - Object representation of the Team Space Membership to be created * @return Promise for the newly created Team Space Membership * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createTeamSpaceMembership('team_id', { * admin: false, * roles: [ * { sys: { * type: 'Link', * linkType: 'Role', * id: '' * } * } * ], * })) * .then((teamSpaceMembership) => console.log(teamSpaceMembership)) * .catch(console.error) * ``` */ createTeamSpaceMembership(teamId: string, data: CreateTeamSpaceMembershipProps): Promise; /** * Gets a Api Key * @param id - API Key ID * @return Promise for a Api Key * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getApiKey('')) * .then((apikey) => console.log(apikey)) * .catch(console.error) * ``` */ getApiKey(id: string): Promise; /** * Gets a collection of Api Keys * @return Promise for a collection of Api Keys * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getApiKeys()) * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getApiKeys(): Promise>; /** * Gets a collection of preview Api Keys * @return Promise for a collection of Preview Api Keys * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getPreviewApiKeys()) * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getPreviewApiKeys(): Promise>; /** * Gets a preview Api Key * @param id - Preview API Key ID * @return Promise for a Preview Api Key * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getPreviewApiKey('')) * .then((previewApikey) => console.log(previewApikey)) * .catch(console.error) * ``` */ getPreviewApiKey(id: string): Promise; /** * Creates a Api Key * @param payload - Object representation of the Api Key to be created * @return Promise for the newly created Api Key * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createApiKey({ * name: 'API Key name', * environments:[ * { * sys: { * type: 'Link' * linkType: 'Environment', * id:'' * } * } * ] * } * })) * .then((apiKey) => console.log(apiKey)) * .catch(console.error) * ``` */ createApiKey: (payload: CreateApiKeyProps) => Promise; /** * Creates a Api Key with a custom ID * @param id - Api Key ID * @param payload - Object representation of the Api Key to be created * @return Promise for the newly created Api Key * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createApiKeyWithId('', { * name: 'API Key name' * environments:[ * { * sys: { * type: 'Link' * linkType: 'Environment', * id:'' * } * } * ] * } * })) * .then((apiKey) => console.log(apiKey)) * .catch(console.error) * ``` */ createApiKeyWithId(id: string, payload: CreateApiKeyProps): Promise; /** * Creates an EnvironmentAlias with a custom ID * @param environmentAliasId - EnvironmentAlias ID * @param data - Object representation of the EnvironmentAlias to be created * @return Promise for the newly created EnvironmentAlias * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createEnvironmentAliasWithId('', { * environment: { * sys: { type: 'Link', linkType: 'Environment', id: 'targetEnvironment' } * } * })) * .then((environmentAlias) => console.log(environmentAlias)) * .catch(console.error) * ``` */ createEnvironmentAliasWithId(environmentAliasId: string, data: CreateEnvironmentAliasProps): Promise; /** * Gets an Environment Alias * @param Environment Alias ID * @return Promise for an Environment Alias * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironmentAlias('')) * .then((alias) => console.log(alias)) * .catch(console.error) * ``` */ getEnvironmentAlias(environmentAliasId: string): Promise; /** * Gets a collection of Environment Aliases * @return Promise for a collection of Environment Aliases * @example ```javascript * const contentful = require('contentful-management') * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getEnvironmentAliases() * .then((response) => console.log(response.items)) * .catch(console.error) * ``` */ getEnvironmentAliases(): Promise>; /** * Query for scheduled actions in space. * @param query - Object with search parameters. The enviroment id field is mandatory. Check the REST API reference for more details. * @return Promise for the scheduled actions query * * @example ```javascript * const contentful = require('contentful-management'); * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getScheduledActions({ * 'environment.sys.id': '', * 'sys.status': 'scheduled' * })) * .then((scheduledActionCollection) => console.log(scheduledActionCollection.items)) * .catch(console.error) * ``` */ getScheduledActions(query: ScheduledActionQueryOptions): Promise>; /** * Get a Scheduled Action in the current space by environment and ID. * * @throws if the Scheduled Action cannot be found or the user doesn't have permission to read schedules from the entity of the scheduled action itself. * @returns Promise with the Scheduled Action * @example ```javascript * const contentful = require('contentful-management'); * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.getScheduledAction({ * scheduledActionId: '', * environmentId: '' * })) * .then((scheduledAction) => console.log(scheduledAction)) * .catch(console.error) * ``` */ getScheduledAction({ scheduledActionId, environmentId, }: { scheduledActionId: string; environmentId: string; }): Promise; /** * Creates a scheduled action * @param data - Object representation of the scheduled action to be created * @return Promise for the newly created scheduled actions * @example ```javascript * const contentful = require('contentful-management'); * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => space.createScheduledAction({ * entity: { * sys: { * type: 'Link', * linkType: 'Entry', * id: '' * } * }, * environment: { * sys: { * type: 'Link', * linkType: 'Environment', * id: '' * } * }, * action: 'publish', * scheduledFor: { * datetime: , * timezone: 'Europe/Berlin' * } * })) * .then((scheduledAction) => console.log(scheduledAction)) * .catch(console.error) * ``` */ createScheduledAction(data: Omit): Promise; /** * Update a scheduled action * @param {object} options * @param options.scheduledActionId the id of the scheduled action to update * @param options.version the sys.version of the scheduled action to be updated * @param payload the scheduled actions object with updates, omitting sys object * @returns Promise containing a wrapped scheduled action with helper methods * @example ```javascript * const contentful = require('contentful-management'); * * const client = contentful.createClient({ * accessToken: '' * }) * * client.getSpace('') * .then((space) => { * return space.createScheduledAction({ * entity: { * sys: { * type: 'Link', * linkType: 'Entry', * id: '' * } * }, * environment: { * sys: { * type: 'Link', * linkType: 'Environment', * id: '' * } * }, * action: 'publish', * scheduledFor: { * datetime: , * timezone: 'Europe/Berlin' * } * }) * .then((scheduledAction) => { * const { _sys, ...payload } = scheduledAction; * return space.updateScheduledAction({ * ...payload, * scheduledFor: { * ...payload.scheduledFor, * timezone: 'Europe/Paris' * } * }) * }) * .then((scheduledAction) => console.log(scheduledAction)) * .catch(console.error); * ``` */ updateScheduledAction({ scheduledActionId, payload, version, }: { scheduledActionId: string; payload: Omit; version: number; }): Promise; /** * Cancels a Scheduled Action. * Only cancels actions that have not yet executed. * * @param {object} options * @param options.scheduledActionId the id of the scheduled action to be canceled * @param options.environmentId the environment ID of the scheduled action to be canceled * @throws if the Scheduled Action cannot be found or the user doesn't have permissions in the entity in the action. * @returns Promise containing a wrapped Scheduled Action with helper methods * @example ```javascript * const contentful = require('contentful-management'); * * const client = contentful.createClient({ * accessToken: '' * }) * * // Given that an Scheduled Action is scheduled * client.getSpace('') * .then((space) => space.deleteScheduledAction({ * environmentId: '', * scheduledActionId: '' * })) * // The scheduled Action sys.status is now 'canceled' * .then((scheduledAction) => console.log(scheduledAction)) * .catch(console.error); * ``` */ deleteScheduledAction({ scheduledActionId, environmentId, }: { scheduledActionId: string; environmentId: string; }): Promise; };