/** * Core Integration Utilities * DO NOT MODIFY THIS FILE - You may break the integration functionality * * This module provides utilities for making API calls to third-party services * through the platform's multi-provider integration system. * * Supported providers: * - Nango: Self-hosted OAuth for 200+ APIs * - Pipedream: Managed OAuth clients for business apps * - AyrShare: Social media (Instagram, TikTok, Facebook, Twitter, etc.) * * Provider routing is automatic - the code is provider-agnostic. * Use the IntegrationClient class to interact with connected third-party services. */ import { type Env } from './core-utils'; import type { NangoActionResponse, NangoProxyOptions } from './shared/core-types'; export type { NangoActionResponse, NangoProxyOptions, }; /** * Integration requirement definition * Used in integration-requirements.ts to declare which integrations your app needs */ export interface IntegrationRequirement { /** Integration provider ID (e.g., 'github', 'slack', 'hubspot') */ integrationId: string; /** Why this integration is needed */ reason: string; /** Whether the app cannot function without this integration */ required: boolean; } /** * IntegrationClient - Wrapper for making API calls through Nango proxy * * Nango handles OAuth authentication and proxies requests to external APIs. * * For structured data access, prefer IntegrationEntity classes from './core-integration-entities'. * * @example * ```typescript * const client = new IntegrationClient(env); * * // GET request to HubSpot API * const contacts = await client.proxy<{ results: Contact[] }>({ * method: 'GET', * endpoint: '/crm/v3/objects/contacts', * providerConfigKey: 'hubspot' * }); * * // POST request to create a GitHub issue * const issue = await client.proxy({ * method: 'POST', * endpoint: '/repos/owner/repo/issues', * providerConfigKey: 'github', * data: { title: 'New Issue', body: 'Issue description' } * }); * ``` */ export declare class IntegrationClient { private env; private readonly proxyUrl; private readonly proxyToken; constructor(env: Env); /** * Fire-and-forget event emission for integration activity. * Does not require waitUntil context - errors are silently swallowed. */ private fireEvent; /** * Check if integrations are configured */ isConfigured(): boolean; /** * Check if a specific integration has a connection configured. * The proxy resolves connections dynamically, so this returns true * when the proxy is configured even without explicit env vars. */ hasConnection(provider: string): boolean; /** * Normalize integration ID to canonical form for env var lookup. * MUST be identical to platform's normalizeIntegrationId() in provider-config.ts. * * Strips provider prefixes (pd_, nango_, ayrshare_), common suffixes (-demo, _v1), * and removes all separators for consistent cross-provider matching. * * Examples: * - "pd_sendgrid" -> "sendgrid" * - "google-drive" -> "googledrive" * - "pd_google_drive" -> "googledrive" * - "hubspot-demo" -> "hubspot" */ private normalizeIntegrationId; private getWorkspaceIntegrationId; private getLegacyConnectionId; /** * Make a request to external API via platform proxy. * Uses platformFetch which routes through WorkspaceObject DO in production * to avoid 522 timeouts from WfP workers. */ private makeRequest; /** * Make a proxy request to an external API through the integration proxy. * Use this for all API calls to connected third-party services. * Supports multiple providers (Nango, Pipedream, AyrShare) - routing is automatic. * * @example * ```typescript * // GET request * const result = await client.proxy<{ results: Contact[] }>({ * method: 'GET', * endpoint: '/crm/v3/objects/contacts', * providerConfigKey: 'hubspot' * }); * * // POST request with data * const result = await client.proxy({ * method: 'POST', * endpoint: '/repos/owner/repo/issues', * providerConfigKey: 'github', * data: { title: 'Bug Report', body: 'Description' } * }); * ``` */ proxy(options: NangoProxyOptions): Promise>; } /** * Create an integration client instance * * @example * ```typescript * import { createIntegrationClient } from './core-integrations'; * * app.get('/api/hubspot/contacts', async (c) => { * const client = createIntegrationClient(c.env); * const result = await client.proxy<{ results: Contact[] }>({ * method: 'GET', * endpoint: '/crm/v3/objects/contacts', * providerConfigKey: 'hubspot' * }); * return c.json(result); * }); * ``` */ export declare function createIntegrationClient(env: Env): IntegrationClient;