/** * Your actions, trigger and data sources likely connect to third-party * APIs. In this file, you will see an example of how to set up a reusable, * authenticated HTTP client that actions, triggers and data sources can use. * * The createCakemailClient receives a connection that was created when a * customer completed the configuration wizard. The API key and base URL * from that connection are used to create the HTTP client. * * For more information about reusable HTTP clients, see * https://prismatic.io/docs/custom-connectors/get-started/wrap-an-api/#creating-a-shared-http-client */ import { type Connection, util } from "@prismatic-io/spectral"; import { createClient } from "@prismatic-io/spectral/dist/clients/http"; // Helper function to build query parameters from an object function buildQueryParams(params: Record): string { const queryParams = new URLSearchParams(); for (const [key, value] of Object.entries(params)) { if (value !== undefined && value !== null && value !== "") { queryParams.append(key, String(value)); } } const queryString = queryParams.toString(); return queryString ? `?${queryString}` : ""; } export function createCakemailClient( cakemailConnection: Connection, baseUrl?: string ) { const { apiKey } = cakemailConnection.fields; return createClient({ baseUrl: util.types.toString(baseUrl || "https://api.cakemail.dev"), headers: { "Content-Type": "application/json", // Our API returns JSON Authorization: `Bearer ${apiKey}`, }, //debug: true, }); } // Export the helper function for use in actions export { buildQueryParams };