import { IHttpService, ISDKInfo } from '@kontent-ai/core-sdk'; import { IManagementClientConfig } from '../config/imanagement-client-config.interface'; import { AssetContracts, AssetFolderContracts, AssetRenditionContracts, CollectionContracts, ContentItemContracts, ContentTypeContracts, ContentTypeSnippetContracts, EnvironmentContracts, LanguageContracts, LanguageVariantContracts, ProjectUserContracts, RoleContracts, SubscriptionContracts, SpaceContracts, TaxonomyContracts, WebhookContracts, WorkflowContracts, PreviewContracts, WebSpotlightContracts, CustomAppsContracts } from '../contracts'; import { assetFolderMapper, assetsMapper, contentItemsMapper, contentTypeMapper, contentTypeSnippetMapper, languageMapper, languageVariantMapper, environmentMapper, taxonomyMappper, workflowMapper, genericMapper, collectionsMappers, subscriptionMapper, roleMapper, projectUserMapper, assetRenditionMapper, spacesMapper, previewMapper, webSpotlightMapper, customAppMapper } from '../mappers'; import { webhookMapper } from '../mappers/webhook-mapper'; import { AssetModels, ContentTypeModels, ContentTypeSnippetModels, IContentManagementQueryConfig, LanguageModels, TaxonomyModels, WebhookModels, WorkflowModels, AssetFolderModels, IContentManagementListQueryConfig, CollectionModels, ProjectUserModels, AssetRenditionModels, SpaceModels, PreviewModels, WebSpotlightModels, CustomAppModels, LanguageVariantModels } from '../models'; import { AssetFolderResponses, AssetResponses, BaseResponses, ContentItemResponses, ContentTypeResponses, ContentTypeSnippetResponses, LanguageResponses, LanguageVariantResponses, TaxonomyResponses, WebhookResponses, WorkflowResponses, GenericResponses, CollectionResponses, SubscriptionResponses, RoleResponses, ProjectUsersResponses, AssetRenditionResponses, SpaceResponses, PreviewResponses, WebSpotlightResponses, CustomAppsResponses } from '../responses'; import { BaseManagementQueryService } from './base-management-service.class'; import { EnvironmentResponses } from '../responses/environments/environment-responses'; import { EnvironmentModels } from '../models/environments/environment.models'; export class ManagementQueryService extends BaseManagementQueryService { constructor( protected config: IManagementClientConfig, protected httpService: IHttpService, protected sdkInfo: ISDKInfo ) { super(config, httpService, sdkInfo); } async genericPostResponseAsync( url: string, data: any, config: IContentManagementQueryConfig ): Promise { return genericMapper.mapGenericResponse(await super.postResponseAsync(url, data, {}, config)); } async genericPatchResponseAsync( url: string, data: any, config: IContentManagementQueryConfig ): Promise { return genericMapper.mapGenericResponse(await super.patchResponseAsync(url, data, {}, config)); } async genericDeleteResponseAsync( url: string, config: IContentManagementQueryConfig ): Promise { return genericMapper.mapGenericResponse(await super.deleteResponseAsync(url, {}, config)); } async genericGetResponseAsync( url: string, config: IContentManagementQueryConfig ): Promise { return genericMapper.mapGenericResponse(await super.getResponseAsync(url, {}, config)); } async genericPutResponseAsync( url: string, data: any, config: IContentManagementQueryConfig ): Promise { return genericMapper.mapGenericResponse(await super.putResponseAsync(url, data, {}, config)); } async getListAllResponseAsync< TResponse extends BaseResponses.IContentManagementListResponse, TAllResponse extends BaseResponses.IContentManagementListAllResponse >(data: { getResponse: (xContinuationToken?: string) => Promise; allResponseFactory: (items: any[], responses: TResponse[]) => TAllResponse; listQueryConfig: IContentManagementListQueryConfig | undefined; }): Promise { const responses = await this.getListAllResponseInternalAsync({ resolvedResponses: [], getResponse: data.getResponse, xContinuationToken: undefined, listQueryConfig: data.listQueryConfig }); return data.allResponseFactory( responses.reduce((prev: any[], current) => { prev.push(...current.data.items); return prev; }, []), responses ); } async publishLanguageVariantAsync( url: string, data: WorkflowModels.IPublishLanguageVariantData | undefined, config: IContentManagementQueryConfig ): Promise { return workflowMapper.mapEmptyResponse(await this.putResponseAsync(url, data, {}, config)); } async createNewVersionOfLanguageVariantAsync( url: string, config: IContentManagementQueryConfig ): Promise { return workflowMapper.mapEmptyResponse(await this.putResponseAsync(url, undefined, {}, config)); } async unpublishLanguageVariantAsync( url: string, data: WorkflowModels.IUnpublishLanguageVarianthData | undefined, config: IContentManagementQueryConfig ): Promise { return workflowMapper.mapEmptyResponse(await this.putResponseAsync(url, data, {}, config)); } async cancelScheduledPublishingOfLanguageVariantAsync( url: string, config: IContentManagementQueryConfig ): Promise { return workflowMapper.mapEmptyResponse(await this.putResponseAsync(url, undefined, {}, config)); } async cancelScheduledUnpublishingOfLanguageVariantAsync( url: string, config: IContentManagementQueryConfig ): Promise { return workflowMapper.mapEmptyResponse(await this.putResponseAsync(url, undefined, {}, config)); } async changeWorkflowOfLanguageVariantAsync( url: string, data: WorkflowModels.IChangeWorkflowOfLanguageVariantData, config: IContentManagementQueryConfig ): Promise { return workflowMapper.mapEmptyResponse(await this.putResponseAsync(url, data, {}, config)); } async listWorkflowsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return workflowMapper.mapListWorkflowsResponse( await this.getResponseAsync(url, {}, config) ); } async addWorkflowAsync( url: string, config: IContentManagementQueryConfig, data: WorkflowModels.IAddWorkflowData ): Promise { return workflowMapper.mapAddWorkflowResponse( await this.postResponseAsync(url, data, {}, config) ); } async updateWorkflowAsync( url: string, config: IContentManagementQueryConfig, data: WorkflowModels.IUpdateWorkflowData ): Promise { return workflowMapper.mapUpdateWorkflowResponse( await this.putResponseAsync(url, data, {}, config) ); } async deleteWorkflowAsync( url: string, config: IContentManagementQueryConfig ): Promise { return webhookMapper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async viewContentTypeSnippetAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentTypeSnippetMapper.mapViewContentTypeSnippetResponse( await this.getResponseAsync( url, {}, config ) ); } async deleteContentTypeSnippetAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentTypeSnippetMapper.mapEmptyResponse( await this.deleteResponseAsync( url, {}, config ) ); } async addContentTypeSnippetAsync( url: string, data: ContentTypeSnippetModels.IAddContentTypeSnippetData, config: IContentManagementQueryConfig ): Promise { return contentTypeSnippetMapper.mapAddContentTypeSnippetResponse( await this.postResponseAsync( url, data, {}, config ) ); } async listContentTypeSnippetsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentTypeSnippetMapper.mapListingResponse( await this.getResponseAsync( url, {}, config ) ); } async environmentInformationAsync( url: string, config: IContentManagementQueryConfig ): Promise { return environmentMapper.mapEnvironmentInformationResponse( await this.getResponseAsync(url, {}, config) ); } async listEnvironmentValidationIssuesAsync( url: string, config: IContentManagementQueryConfig ): Promise { return environmentMapper.mapProjectValidationIssuesListResponse( await this.getResponseAsync( url, {}, config ) ); } async startEnvironmentValidationAsync( url: string, config: IContentManagementQueryConfig ): Promise { return environmentMapper.mapStartEnvironmentValidationResponse( await this.postResponseAsync( url, {}, {}, config ) ); } async checkEnvironmentValidationAsync( url: string, config: IContentManagementQueryConfig ): Promise { return environmentMapper.mapCheckEnvironmentValidationResponse( await this.getResponseAsync( url, {}, config ) ); } async addContentTypeAsync( url: string, data: ContentTypeModels.IAddContentTypeData, config: IContentManagementQueryConfig ): Promise { return contentTypeMapper.mapAddContentTypeResponse( await this.postResponseAsync(url, data, {}, config) ); } async deleteContentTypeAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentTypeMapper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async modifyContentTypeAsync( url: string, config: IContentManagementQueryConfig, data: ContentTypeModels.IModifyContentTypeData[] ): Promise { return contentTypeMapper.mapModifyContentTypeResponse( await this.patchResponseAsync( url, data, {}, config ) ); } async modifyTaxonomyAsync( url: string, config: IContentManagementQueryConfig, data: TaxonomyModels.IModifyTaxonomyData[] ): Promise { return taxonomyMappper.mapModifyTaxonomyResponse( await this.patchResponseAsync(url, data, {}, config) ); } async modifyContentTypeSnippetAsync( url: string, config: IContentManagementQueryConfig, data: ContentTypeSnippetModels.IModifyContentTypeSnippetData[] ): Promise { return contentTypeSnippetMapper.mapModifyContentTypeSnippetResponse( await this.patchResponseAsync( url, data, {}, config ) ); } async viewContentTypeAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentTypeMapper.mapViewContentTypeResponse( await this.getResponseAsync(url, {}, config) ); } async listContentTypesAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentTypeMapper.mapListingResponse( await this.getResponseAsync(url, {}, config) ); } async listAssetRenditionsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return assetRenditionMapper.mapListAssetRenditionsResponse( await this.getResponseAsync(url, {}, config) ); } async viewAssetRenditionAsync( url: string, config: IContentManagementQueryConfig ): Promise { return assetRenditionMapper.mapViewAssetRenditionResponse( await this.getResponseAsync(url, {}, config) ); } async addAssetRenditionAsync( url: string, config: IContentManagementQueryConfig, data: AssetRenditionModels.IAddAssetRenditionData ): Promise { return assetRenditionMapper.mapAddAssetRenditionResponse( await this.postResponseAsync( url, data, {}, config ) ); } async modifyAssetRenditionAsync( url: string, config: IContentManagementQueryConfig, data: AssetRenditionModels.IModifyAssetRenditionData ): Promise { return assetRenditionMapper.mapModifyAssetRenditionResponse( await this.putResponseAsync( url, data, {}, config ) ); } async addCustomAppAsync( url: string, data: CustomAppModels.IAddCustomAppData, config: IContentManagementQueryConfig ): Promise { return customAppMapper.mapAddCustomAppResponse( await this.postResponseAsync(url, data, {}, config) ); } async modifyCustomAppAsync( url: string, data: CustomAppModels.ModifyCustomAppOperation[], config: IContentManagementQueryConfig ): Promise { return customAppMapper.mapModifyCustomAppResponse( await this.patchResponseAsync(url, data, {}, config) ); } async deleteCustomAppAsync( url: string, config: IContentManagementQueryConfig ): Promise { return customAppMapper.mapEmptyResponse(await this.deleteResponseAsync<{}>(url, {}, config)); } async getCustomAppAsync( url: string, config: IContentManagementQueryConfig ): Promise { return customAppMapper.mapGetCustomAppResponse( await this.getResponseAsync(url, {}, config) ); } async listCustomAppsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return customAppMapper.mapListCustomAppsResponse( await this.getResponseAsync(url, {}, config) ); } async addTaxonomyAsync( url: string, data: TaxonomyModels.IAddTaxonomyRequestModel, config: IContentManagementQueryConfig ): Promise { return taxonomyMappper.mapAddTaxonomyResponse( await this.postResponseAsync(url, data, {}, config) ); } async deleteTaxonomyAsync( url: string, config: IContentManagementQueryConfig ): Promise { return taxonomyMappper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async getTaxonomyAsync( url: string, config: IContentManagementQueryConfig ): Promise { return taxonomyMappper.mapGetTaxonomyResponse( await this.getResponseAsync(url, {}, config) ); } async listTaxonomiesAsync( url: string, config: IContentManagementQueryConfig ): Promise { return taxonomyMappper.mapListingTaxonomysResponse( await this.getResponseAsync(url, {}, config) ); } async deleteAssetAsync( url: string, config: IContentManagementQueryConfig ): Promise { return assetsMapper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async upsertAssetAsync( url: string, data: AssetModels.IUpsertAssetRequestData, config: IContentManagementQueryConfig ): Promise { return assetsMapper.mapUpsertAssetResponse( await this.putResponseAsync(url, data, {}, config) ); } async addAssetAsync( url: string, data: AssetModels.IAddAssetRequestData, config: IContentManagementQueryConfig ): Promise { return assetsMapper.mapAddAssetResponse( await this.postResponseAsync(url, data, {}, config) ); } async listSubscriptionProjectsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return subscriptionMapper.mapSubscriptionProjectsListResponse( await this.getResponseAsync( url, {}, config ) ); } async litSubscriptionUsersAsync( url: string, config: IContentManagementQueryConfig ): Promise { return subscriptionMapper.mapSubscriptionUsersListResponse( await this.getResponseAsync(url, {}, config) ); } async viewSubscriptionProjectAsync( url: string, config: IContentManagementQueryConfig ): Promise { return subscriptionMapper.mapViewSubscriptionProjectResponse( await this.getResponseAsync(url, {}, config) ); } async viewSubscriptionUserAsync( url: string, config: IContentManagementQueryConfig ): Promise { return subscriptionMapper.mapViewSubscriptionUserResponse( await this.getResponseAsync(url, {}, config) ); } async activateUserInAllProjectsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapEmptyResponse( await this.putResponseAsync(url, {}, {}, config) ); } async deactivateUserInAllProjectsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapEmptyResponse( await this.putResponseAsync(url, {}, {}, config) ); } async uploadAssetFromUrlAsync( uploadBinaryFileUrl: string, addAssetUrl: string, data: AssetModels.IUploadAssetFromUrlRequestData, config: IContentManagementQueryConfig ): Promise { // get binary data from url const binaryData = await super.getBinaryDataFromUrlAsync(data.fileUrl); const mimeType = super.getMimeTypeFromFilename(data.binaryFile.filename); if (!mimeType) { throw Error( `Could not get MIME type for filename '${data.binaryFile.filename}'. Please include extension in your filename (e.g. myfile.png)` ); } // config needs to be cloned as otherwise it would be mutated with invalid // headers in uploadBinaryFile method const configForUploadBinaryFile = JSON.parse(JSON.stringify(config)); // upload binary file const uploadedBinaryFileResponse = await this.uploadBinaryFileAsync( uploadBinaryFileUrl, { binaryData: binaryData, contentType: mimeType, filename: data.binaryFile.filename, contentLength: binaryData.byteLength }, configForUploadBinaryFile ); // creta asset & assign it to binary file const assetResponse = await this.addAssetAsync( addAssetUrl, { file_reference: { id: uploadedBinaryFileResponse.data.id, type: uploadedBinaryFileResponse.data.type }, descriptions: data.asset.descriptions, external_id: data.asset.external_id, folder: data.asset.folder, title: data.asset.title, codename: data.asset.codename, collection: data.asset.collection, elements: data.asset.elements }, config ); return assetResponse; } async uploadBinaryFileAsync( url: string, data: AssetModels.IUploadBinaryFileRequestData, config: IContentManagementQueryConfig ): Promise { config.headers.push({ header: 'Content-type', value: data.contentType }); if (data.contentLength) { config.headers.push({ header: 'Content-length', value: data.contentLength.toString() }); } return assetsMapper.mapUploadBinaryFileResponse( await this.postResponseAsync( url, data.binaryData, {}, config ) ); } async viewAssetAsync( url: string, config: IContentManagementQueryConfig ): Promise { return assetsMapper.mapViewAssetResponse( await this.getResponseAsync(url, {}, config) ); } async listAssetsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return assetsMapper.mapListingAssetsResponse( await this.getResponseAsync(url, {}, config) ); } async listContentItemsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapListingItemsResponse( await this.getResponseAsync(url, {}, config) ); } async viewContentItemAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapViewContentItemResponse( await this.getResponseAsync(url, {}, config) ); } async addContentItemAsync( url: string, data: ContentItemContracts.IAddContentItemPostContract, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapAddContentItemResponse( await this.postResponseAsync(url, data, {}, config) ); } async upsertContentItemAsync( url: string, data: ContentItemContracts.IUpsertContentItemPostContract, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapUpsertContentItemResponse( await this.putResponseAsync(url, data, {}, config) ); } async updateContentItemAsync( url: string, data: ContentItemContracts.IUpdateContentItemPostContract, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapUpdateContentItemResponse( await this.putResponseAsync(url, data, {}, config) ); } async deleteContentItemAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async deleteLanguageVariantAsync( url: string, config: IContentManagementQueryConfig ): Promise { return contentItemsMapper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async upsertLanguageVariantAsync( url: string, data: LanguageVariantContracts.IUpsertLanguageVariantPostContract, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapUpsertLanguageVariantResponse( await this.putResponseAsync( url, data, {}, config ) ); } async viewLanguageVariantAsync( url: string, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapViewLanguageVariantResponse( await this.getResponseAsync(url, {}, config) ); } async listLanguageVariantsOfItemAsync( url: string, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapLanguageVariantsOfItemResponse( await this.getResponseAsync( url, {}, config ) ); } async listLanguageVariantsOfContentTypeWithComponentsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapLanguageVariantsOfContentTypeWithComponentsResponse( await this.getResponseAsync( url, {}, config ) ); } async listLanguageVariantsOfContentTypeAsync( url: string, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapLanguageVariantsOfContentTypeResponse( await this.getResponseAsync( url, {}, config ) ); } async listLanguageVariantsByCollectionAsync( url: string, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapLanguageVariantsByCollectionResponse( await this.getResponseAsync( url, {}, config ) ); } async filterItemsWithVariantsAsync( url: string, data: LanguageVariantModels.IFilterItemsWithVariantsData, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapFilterItemsWithVariantsResponse( await this.postResponseAsync( url, data, {}, config ) ); } async bulkGetItemsWithVariantsAsync( url: string, data: LanguageVariantModels.IBulkGetItemsWithVariantsData, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapBulkGetItemsWithVariantsResponse( await this.postResponseAsync( url, data, {}, config ) ); } async listLanguageVariantsBySpaceAsync( url: string, config: IContentManagementQueryConfig ): Promise { return languageVariantMapper.mapLanguageVariantsBySpaceResponse( await this.getResponseAsync( url, {}, config ) ); } async listLanguagesAsync( url: string, config: IContentManagementQueryConfig ): Promise { return languageMapper.mapListLanguagesResponse( await this.getResponseAsync(url, {}, config) ); } async viewLanguageAsync( url: string, config: IContentManagementQueryConfig ): Promise { return languageMapper.mapViewLanguageResponse( await this.getResponseAsync(url, {}, config) ); } async addLanguageAsync( url: string, config: IContentManagementQueryConfig, data: LanguageModels.IAddLanguageData ): Promise { return languageMapper.mapAddLanguageResponse( await this.postResponseAsync(url, data, {}, config) ); } async modifyLanguageAsync( url: string, config: IContentManagementQueryConfig, data: LanguageModels.IModifyLanguageData[] ): Promise { return languageMapper.mapModifyLanguageResponse( await this.patchResponseAsync(url, data, {}, config) ); } async listWebhooksAsync( url: string, config: IContentManagementQueryConfig ): Promise { return webhookMapper.mapWebhooksListResponse( await this.getResponseAsync(url, {}, config) ); } async getWebhookAsync( url: string, config: IContentManagementQueryConfig ): Promise { return webhookMapper.mapGetWebhookResponse( await this.getResponseAsync(url, {}, config) ); } async addWebhookAsync( url: string, config: IContentManagementQueryConfig, data: WebhookModels.IAddWebhookData ): Promise { return webhookMapper.mapAddWebhookResponse( await this.postResponseAsync(url, data, {}, config) ); } async enableWebhookAsync( url: string, config: IContentManagementQueryConfig ): Promise { return webhookMapper.mapEmptyResponse( await this.putResponseAsync(url, {}, {}, config) ); } async disableWebhookAsync( url: string, config: IContentManagementQueryConfig ): Promise { return webhookMapper.mapEmptyResponse( await this.putResponseAsync(url, {}, {}, config) ); } async deleteWebhookAsync( url: string, config: IContentManagementQueryConfig ): Promise { return webhookMapper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async listAssetFoldersAsync( url: string, config: IContentManagementQueryConfig ): Promise { return assetFolderMapper.mapListAssetFoldersResponse( await this.getResponseAsync(url, {}, config) ); } async addAssetFoldersAsync( url: string, config: IContentManagementQueryConfig, data: AssetFolderModels.IAddAssetFoldersData ): Promise { return assetFolderMapper.mapAddAssetFoldersResponse( await this.postResponseAsync(url, data, {}, config) ); } async modifyAssetFoldersAsync( url: string, config: IContentManagementQueryConfig, data: AssetFolderModels.IModifyAssetFolderData[] ): Promise { return assetFolderMapper.mapModifyAssetFoldersResponse( await this.patchResponseAsync( url, data, {}, config ) ); } async listCollectionsAsync( url: string, config: IContentManagementQueryConfig ): Promise { return collectionsMappers.mapListCollectionsResponse( await this.getResponseAsync(url, {}, config) ); } async listRolesAsync(url: string, config: IContentManagementQueryConfig): Promise { return roleMapper.mapRoleListResponse( await this.getResponseAsync(url, {}, config) ); } async viewRoleAsync(url: string, config: IContentManagementQueryConfig): Promise { return roleMapper.mapViewRoleResponse( await this.getResponseAsync(url, {}, config) ); } async getPreviewConfigurationAsync( url: string, config: IContentManagementQueryConfig ): Promise { return previewMapper.mapPreviewConfigurationResponse( await this.getResponseAsync(url, {}, config) ); } async modifyPreviewConfigurationAsync( url: string, config: IContentManagementQueryConfig, data: PreviewModels.IModifyPreviewConfigurationData ): Promise { return previewMapper.mapModifyConfigurationResponse( await this.putResponseAsync(url, data, {}, config) ); } async getLivePreviewConfigurationAsync( url: string, config: IContentManagementQueryConfig ): Promise { return previewMapper.mapLivePreviewConfigurationResponse( await this.getResponseAsync(url, {}, config) ); } async changeLivePreviewConfigurationAsync( url: string, config: IContentManagementQueryConfig, data: PreviewModels.IChangeLivePreviewConfigurationData ): Promise { return previewMapper.mapChangeLivePreviewConfigurationResponse( await this.putResponseAsync(url, data, {}, config) ); } async setCollectionsAsync( url: string, config: IContentManagementQueryConfig, data: CollectionModels.ISetCollectionData[] ): Promise { return collectionsMappers.mapSetCollectionsResponse( await this.patchResponseAsync(url, data, {}, config) ); } async inviteProjectUserAsync( url: string, config: IContentManagementQueryConfig, data: ProjectUserModels.IInviteUserData ): Promise { return projectUserMapper.mapInviteUserResponse( await this.postResponseAsync(url, data, {}, config) ); } async changeUserRolesAsync( url: string, config: IContentManagementQueryConfig, data: ProjectUserModels.IChangeUserRoleData ): Promise { return projectUserMapper.mapChangeUserRolesResponse( await this.putResponseAsync(url, data, {}, config) ); } async getEnvironmentCloningStateAsync( url: string, config: IContentManagementQueryConfig ): Promise { return environmentMapper.mapGetEnvironmentCloningStateResponse( await this.getResponseAsync(url, {}, config) ); } async deleteEnvironmentAsync( url: string, config: IContentManagementQueryConfig ): Promise { return environmentMapper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async modifyEnvironmentAsync( url: string, config: IContentManagementQueryConfig, data: EnvironmentModels.IModifyEnvironmentData[] ): Promise { return environmentMapper.mapModifyEnvironmentResponse( await this.patchResponseAsync( url, data, {}, config ) ); } async cloneEnvironmentAsync( url: string, config: IContentManagementQueryConfig, data: EnvironmentModels.ICloneEnvironmentData ): Promise { return environmentMapper.mapCloneEnvironmentResponse( await this.postResponseAsync(url, data, {}, config) ); } async markEnvironmentAsProductionAsync( url: string, config: IContentManagementQueryConfig, data: EnvironmentModels.IMarkEnvironmentAsProductionData ): Promise { return environmentMapper.mapEmptyResponse( await this.putResponseAsync( url, data, {}, config ) ); } async addSpaceAsync( url: string, data: SpaceModels.IAddSpaceData, config: IContentManagementQueryConfig ): Promise { return spacesMapper.mapAddSpaceResponse( await this.postResponseAsync(url, data, {}, config) ); } async viewSpaceAsync( url: string, config: IContentManagementQueryConfig ): Promise { return spacesMapper.mapViewSpaceResponse( await this.getResponseAsync(url, {}, config) ); } async listSpacesAsync( url: string, config: IContentManagementQueryConfig ): Promise { return spacesMapper.mapListingSpacesResponse( await this.getResponseAsync(url, {}, config) ); } async deleteSpaceAsync( url: string, config: IContentManagementQueryConfig ): Promise { return spacesMapper.mapEmptyResponse( await this.deleteResponseAsync(url, {}, config) ); } async modifySpaceAsync( url: string, config: IContentManagementQueryConfig, data: SpaceModels.IModifySpaceData[] ): Promise { return spacesMapper.mapModifySpaceResponse( await this.patchResponseAsync(url, data, {}, config) ); } async activateWebSpotlightAsync( url: string, config: IContentManagementQueryConfig, data: WebSpotlightModels.IActivateWebSpotlightData ): Promise { return webSpotlightMapper.mapWebSpotlightStatusResponse( await this.putResponseAsync(url, data, {}, config) ); } async deactivateWebSpotlightAsync( url: string, config: IContentManagementQueryConfig ): Promise { return webSpotlightMapper.mapWebSpotlightStatusResponse( await this.putResponseAsync(url, {}, {}, config) ); } async checkWebSpotlightStatusAsync( url: string, config: IContentManagementQueryConfig ): Promise { return webSpotlightMapper.mapWebSpotlightStatusResponse( await this.getResponseAsync(url, {}, config) ); } private async getListAllResponseInternalAsync< TResponse extends BaseResponses.IContentManagementListResponse >(data: { xContinuationToken: string | undefined; getResponse: (xContinuationToken?: string) => Promise; resolvedResponses: TResponse[]; listQueryConfig: IContentManagementListQueryConfig | undefined; }): Promise { const response = await data.getResponse(data.xContinuationToken); if (data.listQueryConfig?.delayBetweenRequests) { await this.sleepAsync(data.listQueryConfig.delayBetweenRequests); } data.resolvedResponses.push(response); if (data.listQueryConfig?.responseFetched) { data.listQueryConfig.responseFetched(response, data.xContinuationToken); } if (response.data.pagination.continuationToken) { // recursively fetch next page data return await this.getListAllResponseInternalAsync({ xContinuationToken: response.data.pagination.continuationToken, getResponse: data.getResponse, resolvedResponses: data.resolvedResponses, listQueryConfig: data.listQueryConfig }); } return data.resolvedResponses; } private async sleepAsync(ms: number): Promise { return await new Promise((resolve) => setTimeout(resolve, ms)); } }