UNPKG

@netlify/config

Version:
51 lines (50 loc) 1.82 kB
import { EXTENSION_API_BASE_URL } from '../../integrations.js'; export const installExtension = async ({ netlifyToken, accountId, slug, hostSiteUrl, }) => { const extensionOnInstallUrl = new URL('/.netlify/functions/handler/on-install', hostSiteUrl); const installedResponse = await fetch(extensionOnInstallUrl, { method: 'POST', body: JSON.stringify({ teamId: accountId, }), headers: { 'netlify-token': netlifyToken, }, }); if (!installedResponse.ok && installedResponse.status !== 409) { const text = await installedResponse.text(); return { slug, error: { code: installedResponse.status.toString(), message: text, }, }; } return { slug, error: null, }; }; /** * Fetches the list of extensions from Jigsaw that declare associated packages. * Used to determine which extensions should be auto-installed based on the packages * present in the package.json (e.g., if an extension lists '@netlify/neon', * and that package exists in package.json, the extension will be auto-installed). * * @returns Array of extensions with their associated packages */ export async function fetchAutoInstallableExtensionsMeta() { try { const url = new URL(`/meta/auto-installable`, process.env.EXTENSION_API_BASE_URL ?? EXTENSION_API_BASE_URL); const response = await fetch(url.toString()); if (!response.ok) { throw new Error(`Failed to fetch extensions meta`); } const data = await response.json(); return data; } catch (error) { console.error(`Failed to fetch auto-installable extensions meta: ${error.message}`, error); return []; } }