import { Stream } from 'stream' ; import { createRequestConfig } from 'contentful-sdk-core' ; import type { QueryOptions } from './common-types' ; import { BasicQueryOptions , MakeRequest } from './common-types' ; import entities from './entities' ; import type { CreateAppInstallationProps } from './entities/app-installation' ; import type { CreateAppSignedRequestProps } from './entities/app-signed-request' ; import type { AssetFileProp , AssetProps , CreateAssetProps } from './entities/asset' ; import type { CreateAssetKeyProps } from './entities/asset-key' ; import type { BulkAction , BulkActionPayload , BulkActionPublishPayload , BulkActionUnpublishPayload , BulkActionValidatePayload , } from './entities/bulk-action' ; import { ReleaseActionQueryOptions , wrapReleaseAction , wrapReleaseActionCollection , } from './entities/release-action' ; import { wrapRelease , ReleasePayload , wrapReleaseCollection , ReleaseQueryOptions , ReleaseValidatePayload , } from './entities/release' ; import type { ContentTypeProps , CreateContentTypeProps } from './entities/content-type' ; import type { CreateEntryProps , EntryProps , EntryReferenceOptionsProps , EntryReferenceProps , } from './entities/entry' ; import { EnvironmentProps } from './entities/environment' ; import type { CreateExtensionProps } from './entities/extension' ; import type { CreateLocaleProps } from './entities/locale' ; import { TagVisibility , wrapTag , wrapTagCollection } from './entities/tag' ; private export type ContentfulEnvironmentAPI = ReturnType < typeof createEnvironmentApi > ; param { ContentfulEnvironmentAPI } makeRequest return { ContentfulSpaceAPI } private export default function createEnvironmentApi ( makeRequest ) { const { wrapEnvironment } = entities . environment ; const { wrapContentType , wrapContentTypeCollection } = entities . contentType ; const { wrapEntry , wrapEntryCollection } = entities . entry ; const { wrapAsset , wrapAssetCollection } = entities . asset ; const { wrapAssetKey } = entities . assetKey ; const { wrapLocale , wrapLocaleCollection } = entities . locale ; const { wrapSnapshotCollection } = entities . snapshot ; const { wrapEditorInterface , wrapEditorInterfaceCollection } = entities . editorInterface ; const { wrapUpload } = entities . upload ; const { wrapExtension , wrapExtensionCollection } = entities . extension ; const { wrapAppInstallation , wrapAppInstallationCollection } = entities . appInstallation ; const { wrapAppSignedRequest } = entities . appSignedRequest ; const { wrapBulkAction } = entities . bulkAction ; return { return example delete : function deleteEnvironment ( ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Environment' , action : 'delete' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id } , } ) . then ( ( ) => { } ) ; } , return example update : function updateEnvironment ( ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Environment' , action : 'update' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id } , payload : raw , } ) . then ( ( data ) => wrapEnvironment ( makeRequest , data ) ) ; } , param entryData return example getEntryFromData ( entryData ) { return wrapEntry ( makeRequest , entryData ) ; } , param assetData return example getAssetFromData ( assetData ) { return wrapAsset ( makeRequest , assetData ) ; } , description param bulkActionId returns example getBulkAction < T extends BulkActionPayload = any > ( bulkActionId ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'BulkAction' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , bulkActionId , } , } ) . then ( ( data ) => wrapBulkAction < T > ( makeRequest , data ) ) ; } , description param { BulkActionPayload } payload returns example createPublishBulkAction ( payload ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'BulkAction' , action : 'publish' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload , } ) . then ( ( data ) => wrapBulkAction < BulkActionPublishPayload > ( makeRequest , data ) ) ; } , description param { BulkActionPayload } payload returns example createValidateBulkAction ( payload ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'BulkAction' , action : 'validate' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload , } ) . then ( ( data ) => wrapBulkAction < BulkActionValidatePayload > ( makeRequest , data ) ) ; } , description param { BulkActionPayload } payload returns example createUnpublishBulkAction ( payload ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'BulkAction' , action : 'unpublish' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload , } ) . then ( ( data ) => wrapBulkAction < BulkActionUnpublishPayload > ( makeRequest , data ) ) ; } , param contentTypeId return example getContentType ( contentTypeId ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'ContentType' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , contentTypeId , } , } ) . then ( ( data ) => wrapContentType ( makeRequest , data ) ) ; } , param query return example getContentTypes ( query = { } ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'ContentType' , action : 'getMany' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapContentTypeCollection ( makeRequest , data ) ) ; } , param data return example createContentType ( data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'ContentType' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload : data , } ) . then ( ( response ) => wrapContentType ( makeRequest , response ) ) ; } , param contentTypeId param data return example createContentTypeWithId ( contentTypeId , data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'ContentType' , action : 'createWithId' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , contentTypeId , } , payload : data , } ) . then ( ( response ) => wrapContentType ( makeRequest , response ) ) ; } , param contentTypeId return example getEditorInterfaceForContentType ( contentTypeId ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'EditorInterface' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , contentTypeId , } , } ) . then ( ( response ) => wrapEditorInterface ( makeRequest , response ) ) ; } , return example getEditorInterfaces ( ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'EditorInterface' , action : 'getMany' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , } ) . then ( ( response ) => wrapEditorInterfaceCollection ( makeRequest , response ) ) ; } , param id param query return example getEntry ( id , query = { } ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Entry' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , entryId : id , query : createRequestConfig ( { query : query } ) . params , } , } ) . then ( ( data ) => wrapEntry ( makeRequest , data ) ) ; } , param id return example deleteEntry ( id ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Entry' , action : 'delete' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , entryId : id , } , } ) . then ( ( ) => { } ) ; } , param query return example getEntries ( query = { } ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Entry' , action : 'getMany' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , query : createRequestConfig ( { query : query } ) . params , } , } ) . then ( ( data ) => wrapEntryCollection ( makeRequest , data ) ) ; } , param contentTypeId param data return example createEntry ( contentTypeId , data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Entry' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , contentTypeId : contentTypeId , } , payload : data , } ) . then ( ( response ) => wrapEntry ( makeRequest , response ) ) ; } , param contentTypeId param id param data return example createEntryWithId ( contentTypeId , id , data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Entry' , action : 'createWithId' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , entryId : id , contentTypeId : contentTypeId , } , payload : data , } ) . then ( ( response ) => wrapEntry ( makeRequest , response ) ) ; } , param entryId param { Object } options . include param { Object } options . maxDepth returns example getEntryReferences ( entryId , options ? ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Entry' , action : 'references' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , entryId : entryId , deprecated maxDepth : options ?. include || options ?. maxDepth , } , } ) . then ( ( response ) => wrapEntryCollection ( makeRequest , response ) as EntryReferenceProps ) ; } , param id param query return example getAsset ( id , query = { } ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Asset' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , assetId : id , query : createRequestConfig ( { query : query } ) . params , } , } ) . then ( ( data ) => wrapAsset ( makeRequest , data ) ) ; } , param query return example getAssets ( query = { } ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Asset' , action : 'getMany' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , query : createRequestConfig ( { query : query } ) . params , } , } ) . then ( ( data ) => wrapAssetCollection ( makeRequest , data ) ) ; } , param data return example createAsset ( data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Asset' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload : data , } ) . then ( ( response ) => wrapAsset ( makeRequest , response ) ) ; } , param id param data return example createAssetWithId ( id , data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Asset' , action : 'createWithId' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , assetId : id , } , payload : data , } ) . then ( ( response ) => wrapAsset ( makeRequest , response ) ) ; } , param data param data . fields . file . [ return example createAssetFromFiles ( data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Asset' , action : 'createFromFiles' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload : data , } ) . then ( ( response ) => wrapAsset ( makeRequest , response ) ) ; } , param data param data . expiresAt return example createAssetKey ( payload ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'AssetKey' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload , } ) . then ( ( data ) => wrapAssetKey ( makeRequest , data ) ) ; } , param id return example getUpload ( id ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Upload' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , uploadId : id , } , } ) . then ( ( data ) => wrapUpload ( makeRequest , data ) ) ; } , param data param data . file return example createUpload : function createUpload ( data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Upload' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , } , payload : data , } ) . then ( ( data ) => wrapUpload ( makeRequest , data ) ) ; } , param localeId return example getLocale ( localeId ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Locale' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , localeId , } , } ) . then ( ( data ) => wrapLocale ( makeRequest , data ) ) ; } , return example getLocales ( ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Locale' , action : 'getMany' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , } ) . then ( ( data ) => wrapLocaleCollection ( makeRequest , data ) ) ; } , param data return example createLocale ( data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Locale' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload : data , } ) . then ( ( response ) => wrapLocale ( makeRequest , response ) ) ; } , param id return example getUiExtension ( id ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Extension' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , extensionId : id , } , } ) . then ( ( data ) => wrapExtension ( makeRequest , data ) ) ; } , return example getUiExtensions ( ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Extension' , action : 'getMany' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , } ) . then ( ( response ) => wrapExtensionCollection ( makeRequest , response ) ) ; } , param data return example createUiExtension ( data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Extension' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload : data , } ) . then ( ( response ) => wrapExtension ( makeRequest , response ) ) ; } , param id param data return example createUiExtensionWithId ( id , data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Extension' , action : 'createWithId' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , extensionId : id , } , payload : data , } ) . then ( ( response ) => wrapExtension ( makeRequest , response ) ) ; } , param appDefinitionId param data return example createAppInstallation ( appDefinitionId , data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'AppInstallation' , action : 'upsert' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , appDefinitionId , } , payload : data , } ) . then ( ( payload ) => wrapAppInstallation ( makeRequest , payload ) ) ; } , param id return example getAppInstallation ( id ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'AppInstallation' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , appDefinitionId : id , } , } ) . then ( ( data ) => wrapAppInstallation ( makeRequest , data ) ) ; } , return example getAppInstallations ( ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'AppInstallation' , action : 'getMany' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , } ) . then ( ( data ) => wrapAppInstallationCollection ( makeRequest , data ) ) ; } , param appDefinitionId param data return example createAppSignedRequest ( appDefinitionId , data ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'AppSignedRequest' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , appDefinitionId , } , payload : data , } ) . then ( ( payload ) => wrapAppSignedRequest ( makeRequest , payload ) ) ; } , func param entryId param query return example getEntrySnapshots ( entryId , query = { } ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Snapshot' , action : 'getManyForEntry' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , entryId , query , } , } ) . then ( ( data ) => wrapSnapshotCollection < EntryProps > ( makeRequest , data ) ) ; } , func param contentTypeId param query return example getContentTypeSnapshots ( contentTypeId , query = { } ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Snapshot' , action : 'getManyForContentType' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , contentTypeId , query , } , } ) . then ( ( data ) => wrapSnapshotCollection < ContentTypeProps > ( makeRequest , data ) ) ; } , createTag ( id , name , visibility ? ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Tag' , action : 'createWithId' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , tagId : id , } , payload : { name , sys : { visibility : visibility ?? 'private' } , } , } ) . then ( ( data ) => wrapTag ( makeRequest , data ) ) ; } , getTags ( query = { } ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Tag' , action : 'getMany' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , query : createRequestConfig ( { query } ) . params , } , } ) . then ( ( data ) => wrapTagCollection ( makeRequest , data ) ) ; } , getTag ( id ) { const raw = this . toPlainObject ( ) as EnvironmentProps ; return makeRequest ( { entityType : 'Tag' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , tagId : id , } , } ) . then ( ( data ) => wrapTag ( makeRequest , data ) ) ; } , param releaseId returns example getRelease ( releaseId ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'Release' , action : 'get' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , releaseId , } , } ) . then ( ( data ) => wrapRelease ( makeRequest , data ) ) ; } , param { ReleaseQueryOptions } query returns example getReleases ( query ? ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'Release' , action : 'query' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , query , } , } ) . then ( ( data ) => wrapReleaseCollection ( makeRequest , data ) ) ; } , param payload returns example createRelease ( payload ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'Release' , action : 'create' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , } , payload , } ) . then ( ( data ) => wrapRelease ( makeRequest , data ) ) ; } , param options param options . releaseId param options . payload param options . version returns example updateRelease ( { releaseId , payload , version , } ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'Release' , action : 'update' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , releaseId , version , } , payload , } ) . then ( ( data ) => wrapRelease ( makeRequest , data ) ) ; } , param releaseId returns example deleteRelease ( releaseId ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'Release' , action : 'delete' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , releaseId , } , } ) ; } , param options . releaseId param options . version returns example publishRelease ( { releaseId , version } ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'Release' , action : 'publish' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , releaseId , version , } , } ) . then ( ( data ) => wrapReleaseAction ( makeRequest , data ) ) ; } , param options . releaseId param options . version returns example unpublishRelease ( { releaseId , version } ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'Release' , action : 'unpublish' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , releaseId , version , } , } ) . then ( ( data ) => wrapReleaseAction ( makeRequest , data ) ) ; } , param options . releaseId param options . payload returns example validateRelease ( { releaseId , payload , } ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'Release' , action : 'validate' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , releaseId , } , payload , } ) . then ( ( data ) => wrapReleaseAction ( makeRequest , data ) ) ; } , param params . releaseId param params . actionId returns example getReleaseAction ( { actionId , releaseId } ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'ReleaseAction' , action : 'get' , params : { actionId , spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , releaseId , } , } ) . then ( ( data ) => wrapReleaseAction ( makeRequest , data ) ) ; } , param { string } params . releaseId param { ReleaseQueryOptions } params . query returns example getReleaseActions ( { releaseId , query , } ) { const raw = this . toPlainObject ( ) ; return makeRequest ( { entityType : 'ReleaseAction' , action : 'queryForRelease' , params : { spaceId : raw . sys . space . sys . id , environmentId : raw . sys . id , releaseId , query , } , } ) . then ( ( data ) => wrapReleaseActionCollection ( makeRequest , data ) ) ; } , } ; }