import type { IRestApiContext, SourceControlAggregatedFile, SourceControlPreferences, SourceControlStatus, } from '@/Interface'; import { makeRestApiRequest } from '@/utils'; import type { IDataObject } from 'n8n-workflow'; const sourceControlApiRoot = '/source-control'; const createPreferencesRequestFn = (method: 'POST' | 'PATCH') => async ( context: IRestApiContext, preferences: Partial, ): Promise => makeRestApiRequest(context, method, `${sourceControlApiRoot}/preferences`, preferences); export const pushWorkfolder = async ( context: IRestApiContext, data: IDataObject, ): Promise => { return makeRestApiRequest(context, 'POST', `${sourceControlApiRoot}/push-workfolder`, data); }; export const pullWorkfolder = async ( context: IRestApiContext, data: IDataObject, ): Promise => { return makeRestApiRequest(context, 'POST', `${sourceControlApiRoot}/pull-workfolder`, data); }; export const getBranches = async ( context: IRestApiContext, ): Promise<{ branches: string[]; currentBranch: string }> => { return makeRestApiRequest(context, 'GET', `${sourceControlApiRoot}/get-branches`); }; export const savePreferences = createPreferencesRequestFn('POST'); export const updatePreferences = createPreferencesRequestFn('PATCH'); export const getPreferences = async ( context: IRestApiContext, ): Promise => { return makeRestApiRequest(context, 'GET', `${sourceControlApiRoot}/preferences`); }; export const getStatus = async (context: IRestApiContext): Promise => { return makeRestApiRequest(context, 'GET', `${sourceControlApiRoot}/status`); }; export const getAggregatedStatus = async ( context: IRestApiContext, ): Promise => { return makeRestApiRequest(context, 'GET', `${sourceControlApiRoot}/get-status`); }; export const disconnect = async ( context: IRestApiContext, keepKeyPair: boolean, ): Promise => { return makeRestApiRequest(context, 'POST', `${sourceControlApiRoot}/disconnect`, { keepKeyPair, }); }; export const generateKeyPair = async (context: IRestApiContext): Promise => { return makeRestApiRequest(context, 'POST', `${sourceControlApiRoot}/generate-key-pair`); };