UNPKG

@mondaycom/apps-cli

Version:

A cli tool to manage apps (and monday-code projects) in monday.com

47 lines (46 loc) 2.06 kB
import { exportAppManifestUrl, makeAppManifestExportableUrl } from '../consts/urls.js'; import { execute } from './api-service.js'; import { decompressZipBufferToFiles } from './files-service.js'; import { HttpError } from '../types/errors/index.js'; import { HttpMethodTypes } from '../types/services/api-service.js'; import { appsUrlBuilder } from '../utils/urls-builder.js'; export const downloadManifestTask = async (ctx, task) => { task.output = `downloading manifest for app ${ctx.appId}`; const appManifest = await downloadManifest(ctx.appId, ctx.appVersionId); const outputPath = ctx.manifestPath || `${ctx.appId}`; await decompressZipBufferToFiles(Buffer.from(appManifest, 'base64'), outputPath); const currentWorkingDirectory = process.cwd(); const absolutePath = outputPath.startsWith('/') ? outputPath : `${currentWorkingDirectory}/${outputPath}`; task.title = `your manifest files are downloaded at ${absolutePath}`; }; export const downloadManifest = async (appId, appVersionId) => { const baseUrl = exportAppManifestUrl(appId); const url = appsUrlBuilder(baseUrl); const response = (await execute({ url, method: HttpMethodTypes.GET, query: { ...(appVersionId && { appVersionId }) }, })); return response.data; }; export const validateManifestTask = async (ctx, task) => { task.output = `validating manifest for app ${ctx.appId}`; await validateManifest(ctx.appId, ctx.appVersionId); task.title = 'The app is valid for export'; }; export const validateManifest = async (appId, appVersionId) => { try { const baseUrl = makeAppManifestExportableUrl(appId); const url = appsUrlBuilder(baseUrl); await execute({ url, method: HttpMethodTypes.POST, query: { ...(appVersionId && { appVersionId }) }, }); } catch (error) { if (error instanceof HttpError && error.message.includes('Cannot create slugs for live version')) { throw new Error(error.message); } } };