UNPKG

@craftercms/studio-ui

Version:

Services, components, models & utils to build CrafterCMS authoring extensions.

105 lines (103 loc) 4 kB
/* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as published by * the Free Software Foundation. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import { get, post, postJSON } from '../utils/ajax'; import { map } from 'rxjs/operators'; import { pluckProps, toQueryString } from '../utils/object'; export function fetchPackages(siteId, filters) { let qs = toQueryString({ siteId, ...filters }); return get(`/studio/api/2/publish/packages${qs}`).pipe( map(({ response }) => Object.assign(response.packages, pluckProps(response, 'limit', 'offset', 'total'))) ); } export function fetchPackage(siteId, packageId) { return get(`/studio/api/2/publish/package?siteId=${siteId}&packageId=${packageId}`).pipe( map((response) => response?.response?.package) ); } export function cancelPackage(siteId, packageIds) { return postJSON('/studio/api/2/publish/cancel', { siteId, packageIds }); } export function fetchPublishingTargets(site) { return get(`/studio/api/2/publish/available_targets?siteId=${site}`).pipe(map((response) => response?.response)); } export function fetchStatus(siteId) { return get(`/studio/api/2/publish/status?siteId=${siteId}`).pipe( map((response) => response?.response?.publishingStatus), map((status) => { if (status.status) { return status; } else { console.error(`[/api/2/publish/status?siteId=${siteId}] Status property value was ${status.status}`); return { ...status, // Address backend sending status as null. status: status.status ?? '' }; } }) ); } export function start(siteId) { return postJSON('/studio/api/1/services/api/1/publish/start.json', { site_id: siteId }).pipe(map(() => true)); } export function stop(siteId) { return postJSON('/studio/api/1/services/api/1/publish/stop.json', { site_id: siteId }).pipe(map(() => true)); } export function bulkGoLive(siteId, path, environment, comment) { const qs = toQueryString({ site_id: siteId, path, environment: encodeURIComponent(environment), comment }); return post(`/studio/api/1/services/api/1/deployment/bulk-golive.json${qs}`).pipe(map(() => true)); } export function publishByCommits(siteId, commitIds, environment, comment) { return postJSON('/studio/api/1/services/api/1/publish/commits.json', { site_id: siteId, commit_ids: commitIds, environment, comment }).pipe(map(() => true)); } export function publishAll(siteId, publishingTarget, submissionComment) { return postJSON('/studio/api/2/publish/all', { siteId, publishingTarget, submissionComment }).pipe(map(() => true)); } export function clearLock(siteId) { return postJSON('/studio/api/2/publish/clear_lock', { siteId }).pipe(map(() => true)); }