UNPKG

@visionfi/server-sdk

Version:

Server-side SDK for VisionFI API access using Google Service Account authentication

120 lines (119 loc) 4.26 kB
import { VisionFiError } from '../../types/index.js'; /** * Class for managing DocuSign configuration. * Provides methods to get, update, and manage DocuSign integration configuration. */ export class DocuSignConfigManager { apiClient; /** * Creates a new DocuSignConfigManager instance. * * @param apiClient - The Axios instance used for API requests */ constructor(apiClient) { this.apiClient = apiClient; } /** * Retrieves the current DocuSign integration configuration. * * @returns A promise that resolves to the DocuSign configuration response * * @example * ```typescript * const configResponse = await docuSignManager.getConfig(); * * if (configResponse.success) { * console.log('DocuSign configuration:', configResponse.data); * } else { * console.error('Failed to get DocuSign config:', configResponse.message); * } * ``` */ async getConfig() { try { const response = await this.apiClient.get('/admin/docusign'); return response.data; } catch (error) { throw this.handleError(error, 'Failed to retrieve DocuSign configuration'); } } /** * Updates or creates the DocuSign integration configuration. * * @param config - The DocuSign configuration to update or create * @returns A promise that resolves to the DocuSign configuration response * * @example * ```typescript * const configResponse = await docuSignManager.updateConfig({ * userId: '12345678-1234-1234-1234-123456789012', * accountId: '98765432-9876-9876-9876-987654321098', * baseUri: 'https://demo.docusign.net/restapi', * name: 'Production DocuSign Integration', * enabled: true * }); * * if (configResponse.success) { * console.log('DocuSign configuration updated:', configResponse.data); * } else { * console.error('Failed to update DocuSign config:', configResponse.message); * } * ``` */ async updateConfig(config) { try { const response = await this.apiClient.put('/admin/docusign', config); return response.data; } catch (error) { throw this.handleError(error, 'Failed to update DocuSign configuration'); } } /** * Updates only the authentication status of a DocuSign integration. * * @param statusUpdate - The authentication status update data * @returns A promise that resolves to the DocuSign authentication status response * * @example * ```typescript * const statusResponse = await docuSignManager.updateAuthStatus({ * authenticationStatus: 'authenticated', * lastAuthenticated: new Date().toISOString() * }); * * if (statusResponse.success) { * console.log('DocuSign auth status updated:', statusResponse.data); * } else { * console.error('Failed to update auth status:', statusResponse.message); * } * ``` */ async updateAuthStatus(statusUpdate) { try { const response = await this.apiClient.patch('/admin/docusign/status', statusUpdate); return response.data; } catch (error) { throw this.handleError(error, 'Failed to update DocuSign authentication status'); } } /** * Handles errors from API calls and formats them for the client. * * @param error - The error object from the failed API call * @param defaultMessage - A default message to use if no specific message is available * @returns A VisionFiError with the appropriate message and status code */ handleError(error, defaultMessage) { if (error instanceof VisionFiError) { return error; } // Use the error message from the response if available, otherwise use default const message = error.response?.data?.message || error.message || defaultMessage; const statusCode = error.response?.status; const code = error.response?.data?.code || 'docusign_config_error'; return new VisionFiError(message, statusCode, code); } }