UNPKG

@coveo/platform-client

Version:

The main goal of this package is to provide an easy to configure and straightforward way of querying Coveo Cloud APIs using JavaScript.

114 lines 5.41 kB
import API from '../../APICore.js'; import Resource from '../Resource.js'; import { ResourceSnapshotSupportedFileTypes, } from './ResourceSnapshotsInterfaces.js'; export default class ResourceSnapshots extends Resource { static baseUrl = `/rest/organizations/${API.orgPlaceholder}/snapshots`; list(params) { return this.api.get(this.buildPath(`${ResourceSnapshots.baseUrl}`, params)); } get(snapshotId, options) { return this.api.get(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}`, options)); } /** * Lists the resources that the authenticated user can leverage in snapshots in the target organization. */ listResourceAccess() { return this.api.get(`${ResourceSnapshots.baseUrl}/access/resource`); } /** * Shows whether the authenticated user has the specified access level (i.e., read or write) to the content of the target snapshot. * @param snapshotId * @param options */ validateAccess(snapshotId, options) { return this.api.get(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}/access`, options)); } /** * Retrieves a ZIP file holding the content of the target snapshot, in the target format. * @param snapshotId The unique identifier of the target snapshot. * @param [options] * @returns A newly created Blob object which contains the zipped snapshot */ export(snapshotId, options) { return this.api.get(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}/content`, options), { headers: { accept: 'application/zip' }, responseBodyFormat: 'blob', }); } async getContent(snapshotId, options) { const { url } = await this.generateUrl(snapshotId, options); return fetch(url, { method: 'get' }); } /** * Creates a snapshot from a file containing the configuration. * @param file The file containing the configuration. * @param options */ createFromFile(file, options) { const computedOptions = { developerNotes: options?.developerNotes, snapshotFileType: this.getSnapshotFileType(file), }; const form = new FormData(); form.append('file', file); return this.api.postForm(this.buildPath(`${ResourceSnapshots.baseUrl}/file`, computedOptions), form); } createFromOrganization(exportConfigurationModel, options) { return this.api.post(this.buildPath(`${ResourceSnapshots.baseUrl}/self`, options), exportConfigurationModel); } generateUrl(snapshotId, options) { return this.api.get(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}/url`, options)); } dryRun(snapshotId, options) { return this.api.put(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}/dryrun`, options)); } apply(snapshotId, options) { return this.api.put(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}/apply`, options)); } push(snapshotId, options) { return this.api.put(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}/push`, options)); } delete(snapshotId) { return this.api.delete(`${ResourceSnapshots.baseUrl}/${snapshotId}`); } createSynchronizationPlan(snapshotId) { return this.api.post(`${ResourceSnapshots.baseUrl}/${snapshotId}/synchronization`); } getSynchronizationPlan(snapshotId, synchronizationPlanId) { return this.api.get(`${ResourceSnapshots.baseUrl}/${snapshotId}/synchronization/${synchronizationPlanId}`); } updateSynchronizationPlan(snapshotId, synchronizationPlanId, synchronizationPlanModel) { return this.api.put(`${ResourceSnapshots.baseUrl}/${snapshotId}/synchronization/${synchronizationPlanId}`, synchronizationPlanModel); } applySynchronizationPlan(snapshotId, synchronizationPlanId) { return this.api.put(`${ResourceSnapshots.baseUrl}/${snapshotId}/synchronization/${synchronizationPlanId}/apply`); } updateSynchronizationPlanForChildren(snapshotId, synchronizationPlanId, options) { return this.api.put(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}/synchronization/${synchronizationPlanId}/children`, options)); } getSnapshotFileType(file) { switch (file.type) { case 'application/x-zip-compressed': case 'application/zip': return ResourceSnapshotSupportedFileTypes.ZIP; case 'application/json': return ResourceSnapshotSupportedFileTypes.JSON; default: throw new Error('The uploaded file must be either a ZIP or a JSON file.'); } } /** * @description Shows the diff report for the target snapshot and dry-run report * @experimental * @param snapshotId - The unique identifier of the target snapshot. * @param relativeReportId - The unique identifier of the dry-run operation report associated with the target diff report. * @param [numberOfLinesMax] - Maximum number of lines before the diff is downloaded to a file. */ diff(snapshotId, relativeReportId, numberOfLinesMax) { return this.api.get(this.buildPath(`${ResourceSnapshots.baseUrl}/${snapshotId}/diff`, { relativeReportId, numberOfLinesMax, })); } } //# sourceMappingURL=ResourceSnapshots.js.map