/**
 * Contentful Space API. Contains methods to access any operations at a space
 * level, such as creating and reading entities contained in a space.
 */ import { createRequestConfig } from 'contentful-sdk-core' ; import { MakeRequest , PaginationQueryOptions , QueryOptions } from './common-types' ; import entities from './entities' ; 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 { SpaceProps } from './entities/space' ; import { CreateSpaceMembershipProps } from './entities/space-membership' ; import { CreateTeamSpaceMembershipProps } from './entities/team-space-membership' ; import { CreateWebhooksProps } from './entities/webhook' ; private export type ContentfulSpaceAPI = ReturnType < typeof createSpaceApi > ; param { MakeRequest } makeRequest return { ContentfulSpaceAPI } private export default function createSpaceApi ( makeRequest ) { const { wrapSpace } = entities . space ; const { wrapEnvironment , wrapEnvironmentCollection } = entities . environment ; const { wrapWebhook , wrapWebhookCollection } = entities . webhook ; const { wrapRole , wrapRoleCollection } = entities . role ; const { wrapUser , wrapUserCollection } = entities . user ; const { wrapSpaceMember , wrapSpaceMemberCollection } = entities . spaceMember ; const { wrapSpaceMembership , wrapSpaceMembershipCollection } = entities . spaceMembership ; const { wrapTeamSpaceMembership , wrapTeamSpaceMembershipCollection } = entities . teamSpaceMembership ; const { wrapTeamCollection } = entities . team ; const { wrapApiKey , wrapApiKeyCollection } = entities . apiKey ; const { wrapEnvironmentAlias , wrapEnvironmentAliasCollection } = entities . environmentAlias ; const { wrapPreviewApiKey , wrapPreviewApiKeyCollection } = entities . previewApiKey ; const { wrapScheduledAction , wrapScheduledActionCollection } = entities . scheduledAction ; return { return example delete : function deleteSpace ( ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Space' , action : 'delete' , params : { spaceId : raw . sys . id } , } ) ; } , return example update : function updateSpace ( ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Space' , action : 'update' , params : { spaceId : raw . sys . id } , payload : raw , headers : { } , } ) . then ( ( data ) => wrapSpace ( makeRequest , data ) ) ; } , param id return example getEnvironment ( environmentId ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Environment' , action : 'get' , params : { spaceId : raw . sys . id , environmentId } , } ) . then ( ( data ) => wrapEnvironment ( makeRequest , data ) ) ; } , return example getEnvironments ( query = { } ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Environment' , action : 'getMany' , params : { spaceId : raw . sys . id , query } , } ) . then ( ( data ) => wrapEnvironmentCollection ( makeRequest , data ) ) ; } , param data return example createEnvironment ( data = { } ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Environment' , action : 'create' , params : { spaceId : raw . sys . id , } , payload : data , } ) . then ( ( response ) => wrapEnvironment ( makeRequest , response ) ) ; } , param id param data param sourceEnvironmentId return example createEnvironmentWithId ( id , data , sourceEnvironmentId ? ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Environment' , action : 'createWithId' , params : { spaceId : raw . sys . id , environmentId : id , sourceEnvironmentId , } , payload : data , } ) . then ( ( response ) => wrapEnvironment ( makeRequest , response ) ) ; } , param id return example getWebhook ( id ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Webhook' , action : 'get' , params : { spaceId : raw . sys . id , webhookDefinitionId : id } , } ) . then ( ( data ) => wrapWebhook ( makeRequest , data ) ) ; } , return example getWebhooks ( ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Webhook' , action : 'getMany' , params : { spaceId : raw . sys . id } , } ) . then ( ( data ) => wrapWebhookCollection ( makeRequest , data ) ) ; } , param data return example createWebhook ( data ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Webhook' , action : 'create' , params : { spaceId : raw . sys . id } , payload : data , } ) . then ( ( data ) => wrapWebhook ( makeRequest , data ) ) ; } , param id param data return example createWebhookWithId ( id , data ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Webhook' , action : 'createWithId' , params : { spaceId : raw . sys . id , webhookDefinitionId : id } , payload : data , } ) . then ( ( data ) => wrapWebhook ( makeRequest , data ) ) ; } , param id return example getRole ( id ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Role' , action : 'get' , params : { spaceId : raw . sys . id , roleId : id } , } ) . then ( ( data ) => wrapRole ( makeRequest , data ) ) ; } , return example getRoles ( query = { } ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Role' , action : 'getMany' , params : { spaceId : raw . sys . id , query : createRequestConfig ( { query } ) . params } , } ) . then ( ( data ) => wrapRoleCollection ( makeRequest , data ) ) ; } , param data return example createRole ( data ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Role' , action : 'create' , params : { spaceId : raw . sys . id } , payload : data , } ) . then ( ( data ) => wrapRole ( makeRequest , data ) ) ; } , param id param data return example createRoleWithId ( id , roleData ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Role' , action : 'createWithId' , params : { spaceId : raw . sys . id , roleId : id } , payload : roleData , } ) . then ( ( data ) => wrapRole ( makeRequest , data ) ) ; } , param userId return example getSpaceUser ( userId ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'User' , action : 'getForSpace' , params : { spaceId : raw . sys . id , userId , } , } ) . then ( ( data ) => wrapUser ( makeRequest , data ) ) ; } , param query return example getSpaceUsers ( query = { } ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'User' , action : 'getManyForSpace' , params : { spaceId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapUserCollection ( makeRequest , data ) ) ; } , param query return example getTeams ( query = { limit : 100 } ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'Team' , action : 'getManyForSpace' , params : { spaceId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapTeamCollection ( makeRequest , data ) ) ; } , param id return example getSpaceMember ( id ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'SpaceMember' , action : 'get' , params : { spaceId : raw . sys . id , spaceMemberId : id } , } ) . then ( ( data ) => wrapSpaceMember ( makeRequest , data ) ) ; } , param query return example getSpaceMembers ( query = { } ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'SpaceMember' , action : 'getMany' , params : { spaceId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapSpaceMemberCollection ( makeRequest , data ) ) ; } , param id return example getSpaceMembership ( id ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'SpaceMembership' , action : 'get' , params : { spaceId : raw . sys . id , spaceMembershipId : id } , } ) . then ( ( data ) => wrapSpaceMembership ( makeRequest , data ) ) ; } , param query return example getSpaceMemberships ( query = { } ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'SpaceMembership' , action : 'getMany' , params : { spaceId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapSpaceMembershipCollection ( makeRequest , data ) ) ; } , param data return example createSpaceMembership ( data ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'SpaceMembership' , action : 'create' , params : { spaceId : raw . sys . id , } , payload : data , } ) . then ( ( response ) => wrapSpaceMembership ( makeRequest , response ) ) ; } , param id param data return example createSpaceMembershipWithId ( id , data ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'SpaceMembership' , action : 'createWithId' , params : { spaceId : raw . sys . id , spaceMembershipId : id , } , payload : data , } ) . then ( ( response ) => wrapSpaceMembership ( makeRequest , response ) ) ; } , param id return example getTeamSpaceMembership ( teamSpaceMembershipId ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'TeamSpaceMembership' , action : 'get' , params : { spaceId : raw . sys . id , teamSpaceMembershipId , } , } ) . then ( ( data ) => wrapTeamSpaceMembership ( makeRequest , data ) ) ; } , param query return example getTeamSpaceMemberships ( query = { } ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'TeamSpaceMembership' , action : 'getMany' , params : { spaceId : raw . sys . id , query : createRequestConfig ( { query : query } ) . params , } , } ) . then ( ( data ) => wrapTeamSpaceMembershipCollection ( makeRequest , data ) ) ; } , param id param data return example createTeamSpaceMembership ( teamId , data ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'TeamSpaceMembership' , action : 'create' , params : { spaceId : raw . sys . id , teamId , } , payload : data , } ) . then ( ( response ) => wrapTeamSpaceMembership ( makeRequest , response ) ) ; } , param id return example getApiKey ( id ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ApiKey' , action : 'get' , params : { spaceId : raw . sys . id , apiKeyId : id , } , } ) . then ( ( data ) => wrapApiKey ( makeRequest , data ) ) ; } , return example getApiKeys ( ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ApiKey' , action : 'getMany' , params : { spaceId : raw . sys . id , } , } ) . then ( ( data ) => wrapApiKeyCollection ( makeRequest , data ) ) ; } , return example getPreviewApiKeys ( ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'PreviewApiKey' , action : 'getMany' , params : { spaceId : raw . sys . id , } , } ) . then ( ( data ) => wrapPreviewApiKeyCollection ( makeRequest , data ) ) ; } , param id return example getPreviewApiKey ( id ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'PreviewApiKey' , action : 'get' , params : { spaceId : raw . sys . id , previewApiKeyId : id , } , } ) . then ( ( data ) => wrapPreviewApiKey ( makeRequest , data ) ) ; } , param payload return example createApiKey : function createApiKey ( payload ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ApiKey' , action : 'create' , params : { spaceId : raw . sys . id } , payload , } ) . then ( ( data ) => wrapApiKey ( makeRequest , data ) ) ; } , param id param payload return example createApiKeyWithId ( id , payload ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ApiKey' , action : 'createWithId' , params : { spaceId : raw . sys . id , apiKeyId : id } , payload , } ) . then ( ( data ) => wrapApiKey ( makeRequest , data ) ) ; } , param environmentAliasId param data return example createEnvironmentAliasWithId ( environmentAliasId , data ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'EnvironmentAlias' , action : 'createWithId' , params : { spaceId : raw . sys . id , environmentAliasId } , payload : data , } ) . then ( ( response ) => wrapEnvironmentAlias ( makeRequest , response ) ) ; } , param Environment return example getEnvironmentAlias ( environmentAliasId ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'EnvironmentAlias' , action : 'get' , params : { spaceId : raw . sys . id , environmentAliasId } , } ) . then ( ( data ) => wrapEnvironmentAlias ( makeRequest , data ) ) ; } , return example getEnvironmentAliases ( ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'EnvironmentAlias' , action : 'getMany' , params : { spaceId : raw . sys . id , } , } ) . then ( ( data ) => wrapEnvironmentAliasCollection ( makeRequest , data ) ) ; } , param query return example getScheduledActions ( query ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ScheduledAction' , action : 'getMany' , params : { spaceId : raw . sys . id , query } , } ) . then ( ( response ) => wrapScheduledActionCollection ( makeRequest , response ) ) ; } , throws returns example getScheduledAction ( { scheduledActionId , environmentId , } ) { const space = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ScheduledAction' , action : 'get' , params : { spaceId : space . sys . id , environmentId , scheduledActionId , } , } ) . then ( ( scheduledAction ) => wrapScheduledAction ( makeRequest , scheduledAction ) ) ; } , param data return example createScheduledAction ( data ) { const raw = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ScheduledAction' , action : 'create' , params : { spaceId : raw . sys . id } , payload : data , } ) . then ( ( response ) => wrapScheduledAction ( makeRequest , response ) ) ; } , param options param options . scheduledActionId param options . version param payload returns example updateScheduledAction ( { scheduledActionId , payload , version , } ) { const spaceProps = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ScheduledAction' , action : 'update' , params : { spaceId : spaceProps . sys . id , version , scheduledActionId , } , payload , } ) . then ( ( response ) => wrapScheduledAction ( makeRequest , response ) ) ; } , param options param options . scheduledActionId param options . environmentId throws returns example deleteScheduledAction ( { scheduledActionId , environmentId , } ) { const spaceProps = this . toPlainObject ( ) as SpaceProps ; return makeRequest ( { entityType : 'ScheduledAction' , action : 'delete' , params : { spaceId : spaceProps . sys . id , environmentId , scheduledActionId , } , } ) . then ( ( response ) => wrapScheduledAction ( makeRequest , response ) ) ; } , } ; }