UNPKG

@mondaycom/apps-cli

Version:

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

48 lines (47 loc) 1.94 kB
import { getStorageItemsExportUrl, getStorageItemsSearchUrl } from '../consts/urls.js'; import { execute } from './api-service.js'; import { appStorageApiRecordsSearchResponseExportSchema, appStorageApiRecordsSearchResponseSearchSchema, } from './schemas/storage-service-schemas.js'; import { HttpError } from '../types/errors/index.js'; import { HttpMethodTypes } from '../types/services/api-service.js'; import logger from '../utils/logger.js'; import { appsUrlBuilder } from '../utils/urls-builder.js'; export const getStorageItemsSearch = async (appId, clientAccountId, term) => { const DEBUG_TAG = 'get_storage_items_search_url'; try { const baseSignUrl = getStorageItemsSearchUrl(appId, clientAccountId, term); const url = appsUrlBuilder(baseSignUrl); const response = await execute({ url, headers: { Accept: 'application/json' }, method: HttpMethodTypes.GET, }, appStorageApiRecordsSearchResponseSearchSchema); return response; } catch (error) { logger.debug(error, DEBUG_TAG); if (error instanceof HttpError) { throw error; } throw new Error('Failed to fetch storage items.'); } }; export const getStorageItemsExport = async (appId, clientAccountId) => { const DEBUG_TAG = 'get_storage_items_export_url'; try { const baseSignUrl = getStorageItemsExportUrl(appId, clientAccountId); const url = appsUrlBuilder(baseSignUrl); const response = await execute({ url, headers: { Accept: 'application/json' }, method: HttpMethodTypes.GET, }, appStorageApiRecordsSearchResponseExportSchema); return response; } catch (error) { logger.debug(error, DEBUG_TAG); if (error instanceof HttpError) { throw error; } throw new Error('Failed to fetch storage items.'); } };