import { createRequestConfig } from 'contentful-sdk-core' ; import entities from './entities' ; import { Stream } from 'stream' ; import { CreateTeamMembershipProps } from './entities/team-membership' ; import { CreateTeamProps } from './entities/team' ; import { CreateOrganizationInvitationProps } from './entities/organization-invitation' ; import { MakeRequest , QueryOptions } from './common-types' ; import { CreateAppDefinitionProps } from './entities/app-definition' ; import { CreateAppSigningSecretProps } from './entities/app-signing-secret' ; import { CreateAppDetailsProps } from './entities/app-details' ; import { OrganizationProp } from './entities/organization' ; private export type ContentfulOrganizationAPI = ReturnType < typeof createOrganizationApi > ; param { MakeRequest } makeRequest return { ContentfulOrganizationAPI } private export default function createOrganizationApi ( makeRequest ) { const { wrapAppDefinition , wrapAppDefinitionCollection } = entities . appDefinition ; const { wrapUser , wrapUserCollection } = entities . user ; const { wrapOrganizationMembership , wrapOrganizationMembershipCollection } = entities . organizationMembership ; const { wrapTeamMembership , wrapTeamMembershipCollection } = entities . teamMembership ; const { wrapTeamSpaceMembership , wrapTeamSpaceMembershipCollection } = entities . teamSpaceMembership ; const { wrapTeam , wrapTeamCollection } = entities . team ; const { wrapSpaceMembership , wrapSpaceMembershipCollection } = entities . spaceMembership ; const { wrapOrganizationInvitation } = entities . organizationInvitation ; const { wrapAppUpload } = entities . appUpload ; const { wrapAppSigningSecret } = entities . appSigningSecret ; const { wrapAppDetails } = entities . appDetails ; return { return example getUser ( id ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'User' , action : 'getForOrganization' , params : { organizationId : raw . sys . id , userId : id } , } ) . then ( ( data ) => wrapUser ( makeRequest , data ) ) ; } , param query return example getUsers ( query = { } ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'User' , action : 'getManyForOrganization' , params : { organizationId : raw . sys . id , query : createRequestConfig ( { query : query } ) . params , } , } ) . then ( ( data ) => wrapUserCollection ( makeRequest , data ) ) ; } , param id return example getOrganizationMembership ( id ) { const raw = this . toPlainObject ( ) as OrganizationProp ; const organizationId = raw . sys . id ; return makeRequest ( { entityType : 'OrganizationMembership' , action : 'get' , params : { organizationId , organizationMembershipId : id , } , } ) . then ( ( data ) => wrapOrganizationMembership ( makeRequest , data , organizationId ) ) ; } , param query return example getOrganizationMemberships ( query = { } ) { const raw = this . toPlainObject ( ) as OrganizationProp ; const organizationId = raw . sys . id ; return makeRequest ( { entityType : 'OrganizationMembership' , action : 'getMany' , params : { organizationId , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapOrganizationMembershipCollection ( makeRequest , data , organizationId ) ) ; } , param data example createTeam ( data ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'Team' , action : 'create' , params : { organizationId : raw . sys . id } , payload : data , } ) . then ( ( data ) => wrapTeam ( makeRequest , data ) ) ; } , example getTeam ( teamId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'Team' , action : 'get' , params : { organizationId : raw . sys . id , teamId } , } ) . then ( ( data ) => wrapTeam ( makeRequest , data ) ) ; } , example getTeams ( query = { } ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'Team' , action : 'getMany' , params : { organizationId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapTeamCollection ( makeRequest , data ) ) ; } , param teamId param data return example createTeamMembership ( teamId , data ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'TeamMembership' , action : 'create' , params : { organizationId : raw . sys . id , teamId } , payload : data , } ) . then ( ( data ) => wrapTeamMembership ( makeRequest , data ) ) ; } , return example getTeamMembership ( teamId , teamMembershipId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'TeamMembership' , action : 'get' , params : { organizationId : raw . sys . id , teamId , teamMembershipId } , } ) . then ( ( data ) => wrapTeamMembership ( makeRequest , data ) ) ; } , return example getTeamMemberships ( opts = { } ) { const { teamId , query = { } } = opts ; const raw = this . toPlainObject ( ) as OrganizationProp ; if ( teamId ) { return makeRequest ( { entityType : 'TeamMembership' , action : 'getManyForTeam' , params : { organizationId : raw . sys . id , teamId , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapTeamMembershipCollection ( makeRequest , data ) ) ; } return makeRequest ( { entityType : 'TeamMembership' , action : 'getManyForOrganization' , params : { organizationId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapTeamMembershipCollection ( makeRequest , data ) ) ; } , return example getTeamSpaceMemberships ( opts = { } ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'TeamSpaceMembership' , action : 'getManyForOrganization' , params : { organizationId : raw . sys . id , query : createRequestConfig ( { query : opts . query || { } } ) . params , teamId : opts . teamId , } , } ) . then ( ( data ) => wrapTeamSpaceMembershipCollection ( makeRequest , data ) ) ; } , return example getTeamSpaceMembership ( teamSpaceMembershipId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'TeamSpaceMembership' , action : 'getForOrganization' , params : { organizationId : raw . sys . id , teamSpaceMembershipId , } , } ) . then ( ( data ) => wrapTeamSpaceMembership ( makeRequest , data ) ) ; } , param id return example getOrganizationSpaceMembership ( id ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'SpaceMembership' , action : 'getForOrganization' , params : { organizationId : raw . sys . id , spaceMembershipId : id , } , } ) . then ( ( data ) => wrapSpaceMembership ( makeRequest , data ) ) ; } , param query return example getOrganizationSpaceMemberships ( query = { } ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'SpaceMembership' , action : 'getManyForOrganization' , params : { organizationId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapSpaceMembershipCollection ( makeRequest , data ) ) ; } , return example getOrganizationInvitation ( invitationId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'OrganizationInvitation' , action : 'get' , params : { organizationId : raw . sys . id , invitationId , } , } ) . then ( ( data ) => wrapOrganizationInvitation ( makeRequest , data ) ) ; } , return example createOrganizationInvitation ( data ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'OrganizationInvitation' , action : 'create' , params : { organizationId : raw . sys . id , } , payload : data , } ) . then ( ( data ) => wrapOrganizationInvitation ( makeRequest , data ) ) ; } , param Object return example createAppDefinition ( data ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppDefinition' , action : 'create' , params : { organizationId : raw . sys . id } , payload : data , } ) . then ( ( data ) => wrapAppDefinition ( makeRequest , data ) ) ; } , return example getAppDefinitions ( query = { } ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppDefinition' , action : 'getMany' , params : { organizationId : raw . sys . id , query : query } , } ) . then ( ( data ) => wrapAppDefinitionCollection ( makeRequest , data ) ) ; } , return example getAppDefinition ( id ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppDefinition' , action : 'get' , params : { organizationId : raw . sys . id , appDefinitionId : id } , } ) . then ( ( data ) => wrapAppDefinition ( makeRequest , data ) ) ; } , return example getAppUpload ( appUploadId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppUpload' , action : 'get' , params : { organizationId : raw . sys . id , appUploadId } , } ) . then ( ( data ) => wrapAppUpload ( makeRequest , data ) ) ; } , return example createAppUpload ( file ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppUpload' , action : 'create' , params : { organizationId : raw . sys . id } , payload : { file } , } ) . then ( ( data ) => wrapAppUpload ( makeRequest , data ) ) ; } , return example upsertAppSigningSecret ( appDefinitionId , data ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppSigningSecret' , action : 'upsert' , params : { organizationId : raw . sys . id , appDefinitionId } , payload : data , } ) . then ( ( payload ) => wrapAppSigningSecret ( makeRequest , payload ) ) ; } , return example getAppSigningSecret ( appDefinitionId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppSigningSecret' , action : 'get' , params : { organizationId : raw . sys . id , appDefinitionId } , } ) . then ( ( payload ) => wrapAppSigningSecret ( makeRequest , payload ) ) ; } , return example deleteAppSigningSecret ( appDefinitionId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppSigningSecret' , action : 'delete' , params : { organizationId : raw . sys . id , appDefinitionId } , } ) . then ( ( ) => { } ) ; } , return example upsertAppDetails ( appDefinitionId , data ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppDetails' , action : 'upsert' , params : { organizationId : raw . sys . id , appDefinitionId } , payload : data , } ) . then ( ( payload ) => wrapAppDetails ( makeRequest , payload ) ) ; } , return example getAppDetails ( appDefinitionId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppDetails' , action : 'get' , params : { organizationId : raw . sys . id , appDefinitionId } , } ) . then ( ( payload ) => wrapAppDetails ( makeRequest , payload ) ) ; } , return example deleteAppDetails ( appDefinitionId ) { const raw = this . toPlainObject ( ) as OrganizationProp ; return makeRequest ( { entityType : 'AppDetails' , action : 'delete' , params : { organizationId : raw . sys . id , appDefinitionId } , } ) . then ( ( ) => { } ) ; } , } ; }