UNPKG

sb-mig

Version:

CLI to rule the world. (and handle stuff related to Storyblok CMS)

43 lines (42 loc) 1.27 kB
import { getAllItemsWithPagination } from "../../api/utils/request.js"; export async function getAllPlugins(client) { return getAllItemsWithPagination({ apiFn: ({ per_page, page }) => client.sbApi.get("field_types", { per_page, page }), params: {}, itemsKey: "field_types", }); } export async function getPlugin(client, pluginName) { const plugins = await getAllPlugins(client); const plugin = plugins.find((p) => p.name === pluginName); if (!plugin) return false; return await getPluginDetails(client, plugin); } export async function getPluginDetails(client, plugin) { return client.sbApi .get(`field_types/${plugin.id}`) .then((res) => res.data); } export async function updatePlugin(client, args) { const { plugin, body } = args; return client.sbApi .put(`field_types/${plugin.id}`, { publish: true, field_type: { body, compiled_body: "", }, }) .then((res) => res.data); } export async function createPlugin(client, pluginName) { return client.sbApi .post("field_types", { publish: true, field_type: { name: pluginName, }, }) .then((res) => res.data); }