UNPKG

@craftercms/studio-ui

Version:

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

87 lines (85 loc) 3.54 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, postJSON } from '../utils/ajax'; import { map, switchMap } from 'rxjs/operators'; import { of } from 'rxjs'; import { pluckProps, toQueryString } from '../utils/object'; import { fetchItemsByPath } from './content'; export function fetchBlueprints(options) { return fetchMarketplacePlugins({ limit: 1000, showIncompatible: true, ...options, type: 'blueprint' }); } export function fetchMarketplacePlugins(options) { const qs = toQueryString(options); return get(`/studio/api/2/marketplace/search${qs}`).pipe( map((response) => Object.assign(response.response.plugins, pluckProps(response.response, 'limit', 'total', 'offset')) ) ); } export function installMarketplacePlugin(siteId, pluginId, pluginVersion, parameters) { return postJSON('/studio/api/2/marketplace/install', { siteId, pluginId, pluginVersion, parameters }).pipe( map(() => true) ); } export function uninstallMarketplacePlugin(siteId, pluginId, force = false) { return postJSON('/studio/api/2/marketplace/remove', { siteId, pluginId, force }).pipe(map(() => true)); } export function getPluginConfiguration(siteId, pluginId) { const qs = toQueryString({ siteId, pluginId }); return get(`/studio/api/2/plugin/get_configuration${qs}`).pipe(map((response) => response?.response?.content)); } export function setPluginConfiguration(siteId, pluginId, content) { return postJSON('/studio/api/2/plugin/write_configuration', { siteId, pluginId, content }).pipe(map(() => true)); } export function fetchMarketplacePluginUsage(siteId, pluginId) { const qs = toQueryString({ siteId, pluginId }); return get(`/studio/api/2/marketplace/usage${qs}`).pipe( map((response) => response?.response?.items), switchMap((items) => (items.length === 0 ? of(items) : fetchItemsByPath(siteId, items))) ); } export function fetchInstalledMarketplacePlugins(siteId) { return get(`/studio/api/2/marketplace/installed?siteId=${siteId}`).pipe( map((response) => response?.response?.plugins) ); } export function createSite(site) { return postJSON('/studio/api/2/sites/create_site_from_marketplace', site).pipe(map(() => true)); }