All files / sdk/models integrations.ts

80.76% Statements 21/26
76.66% Branches 23/30
100% Functions 6/6
80.76% Lines 21/26

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190  10x   10x                                                                                                                                                                   10x         18x                       1x 1x         1x                               1x 1x     1x             1x 1x           1x                               3x 3x 3x     3x                     3x             1x 1x 1x            
import { DeleteConnectorData, GetConnectorInfoData, GetConnectorInfoResDTO, GetConnectorListResDTO } from "../client";
import apiClient from "../client/client"
import { BackendClient } from "./backendClient";
import { CEG } from "../utils/error";
 
export type ListAllIntegrationsData = {
    /**
     * Page number to fetch
     */
    page?: number;
    /**
     * Page Size to assume
     */
    pageSize?: number;
    /**
     * The name of the app to filter by
     */
    appName?: string;
    /**
     * Whether to show disabled integrations
     */
    showDisabled?: boolean;
};
 
export type GetIntegrationData = {
    /**
     * The unique identifier of the integration.
     */
    integrationId: string;
};
 
export type CreateIntegrationData = {
    requestBody?: {
        /**
         * The name of the connector.
         */
        name?: string;
        /**
         * The authentication scheme used by the connector (e.g., "OAUTH2", "API_KEY").
         */
        authScheme?: string;
        /**
         * The unique identifier of the app associated with the connector.
         */
        appId?: string;
        forceNewIntegration?: boolean;
        /**
         * An object containing the authentication configuration for the connector.
         */
        authConfig?: {
            /**
             * The client ID used for authentication with the app - if authScheme is OAUTH2
             */
            client_id?: string;
            /**
             * The client secret used for authentication with the app - if authScheme is OAUTH2
             */
            client_secret?: string;
            /**
             * The API key used for authentication with the app - if authScheme is API_KEY
             */
            api_key?: string;
            /**
             * The Consumer key used for authentication with the app - if authScheme is OAUTH1
             */
            consumer_key?: string;
            /**
             * The Consumer secret used for authentication with the app - if authScheme is OAUTH1
             */
            consumer_secret?: string;
            /**
             *  The base URL for making API requests to the app.
             */
            base_url?: string;
 
            [key: string]: unknown;
        };
        /**
         * Use default Composio credentials to proceed. The developer app credentials will be of Composio.
         */
        useComposioAuth?: boolean;
    };
};
 
 
export class Integrations {
 
    backendClient: BackendClient;
 
    constructor(backendClient: BackendClient) {
        this.backendClient = backendClient;
    }
 
    /**
     * Retrieves a list of all available integrations in the Composio platform.
     * 
     * This method allows clients to explore and discover the supported integrations. It returns an array of integration objects, each containing essential details such as the integration's key, name, description, logo, categories, and unique identifier.
     * 
     * @returns {Promise<ListAllIntegrationsResponse>} A promise that resolves to the list of all integrations.
     * @throws {ApiError} If the request fails.
     */
    async list(data: ListAllIntegrationsData = {}) {
        try {
            const response = await apiClient.appConnector.listAllConnectors({
                query: data
            });
            
            
            return response.data
        } catch (error) {
            throw CEG.handleError(error);
        }
    }
 
    /**
     * Retrieves details of a specific integration in the Composio platform by providing its integration name.
     * 
     * The response includes the integration's name, display name, description, input parameters, expected response, associated app information, and enabled status.
     * 
     * @param {GetIntegrationData} data The data for the request.
     * @returns {Promise<AppConnectorControllerGetConnectorInfoResponse | undefined>} A promise that resolves to the details of the integration.
     * @throws {ApiError} If the request fails.
     */
    async get(data: GetIntegrationData) {
        try {
            const response = await apiClient.appConnector.getConnectorInfo({
                path: data
            });
            return response.data;
        } catch (error) {
            throw CEG.handleError(error);
        }
    }
 
    async getRequiredParams(integrationId: string) {
        try {
            const response = await apiClient.appConnector.getConnectorInfo({
                path: {
                    integrationId
                },
                throwOnError: true
            });
            return response.data?.expectedInputFields;
        } catch (error) {
            throw CEG.handleError(error);
        }
    }
 
    /**
     * Creates a new integration in the Composio platform.
     * 
     * This method allows clients to create a new integration by providing the necessary details such as app ID, name, authentication mode, and configuration.
     * 
     * @param {CreateIntegrationData["requestBody"]} data The data for the request.
     * @returns {Promise<CreateIntegrationResponse>} A promise that resolves to the created integration model.
     * @throws {ApiError} If the request fails.
     */
    async create(data: CreateIntegrationData["requestBody"]) {
        try {
            if (!data?.authConfig) {
                data!.authConfig = {};
            }
 
            const response = await apiClient.appConnector.createConnector({
                body: {
                    name: data?.name!,
                    appId: data?.appId!,
                    authConfig: data?.authConfig! as any,
                    authScheme: data?.authScheme,
                    useComposioAuth: data?.useComposioAuth!,
                    forceNewIntegration: true
                },
                throwOnError: true
            });
            return response.data;
        } catch (error) {
            throw CEG.handleError(error);
        }
    }
 
    async delete(data: DeleteConnectorData) {
        try {
            const response = await apiClient.appConnector.deleteConnector(data);
            return response.data;
        } catch (error) {
            throw CEG.handleError(error);
        }
    }   
}