Skip to content

Getting Started

Installation

Install the CFC SDK using your preferred package manager:

bash
pnpm add @melio-eng/cfc-sdk
bash
npm install @melio-eng/cfc-sdk
bash
yarn add @melio-eng/cfc-sdk

Basic Usage

The SDK provides a CfcClient class that manages the entire iframe lifecycle — creating the iframe, handling authentication, dimension sync, scroll forwarding, URL sync, and all message handling. You just provide a container element and your config.

typescript
import { CfcClient, Environment, IntegrationMode, NavigationTarget } from "@melio-eng/cfc-sdk";

const client = new CfcClient({
	container: document.getElementById("cfc-container")!,
	environment: Environment.STAGING,
	token: "<your-auth-token>",
	tenant: "your-tenant-id",
	mode: IntegrationMode.FULL_PAGE,
	target: NavigationTarget.VIEW_PAYMENTS,

	// Optional callbacks — the SDK handles everything else automatically
	onSessionExpired: () => {
		window.location.href = "/login";
	},
	onExitRequested: (originator) => {
		client.destroy();
		window.location.href = "/dashboard";
	},
});

client.init();

// Navigate programmatically
client.navigateTo(NavigationTarget.viewBill("bill-123"));

// Cleanup when done
client.destroy();

That's it. The SDK automatically handles:

  • Creating the iframe inside your container
  • Constructing the auth URL
  • Dimension synchronization (resize, scroll, content size changes)
  • Navigation callbacks (react to CFC page changes)
  • Forwarding scroll position to CFC
  • All CFC message types

Configuration

The CfcClientConfig interface accepts the following options:

OptionTypeRequiredDescription
containerHTMLElementYesDOM element where the SDK creates the iframe
environmentEnvironmentYesTarget environment (use Environment constants)
tokenstringYesAuthentication token passed to the CFC auth endpoint
tenantstringYesTenant identifier for multi-tenant environments
modeIntegrationModeYesIntegration mode (use IntegrationMode constants)
targetstringNoInitial navigation target (use NavigationTarget helpers)
headerHeightnumberNoHeight of the host app header in pixels (partial mode)
allowedOriginstringNoOverride origin for message validation

Event Callbacks

CallbackTypeDescription
onLoaded() => voidCFC iframe has finished loading and is ready
onNavigated(target, targetAction?) => voidCFC navigated to a new page
onPaymentSuccess() => voidPayment was successfully scheduled
onAuthenticationError(reason, message) => voidAuthentication failed
onSessionExpired() => voidCFC session expired
onExitRequested(originator) => voidUser wants to leave CFC
onUpgradeRequest(featureName, returnUrl) => voidSubscription upgrade needed
onUserActivePing() => voidUser is active in the iframe
onMessage(message) => voidLow-level: all CFC messages
onError(error) => voidSDK-level errors

Integration Modes

The SDK supports two integration modes:

  • Full Page -- CFC owns the full vertical space. The host can still have a sidebar and header — as long as there's no host content above or below the iframe competing for vertical scroll.
  • Partial -- The host has its own content above or below the CFC iframe, creating a shared vertical scroll. The SDK handles scroll coordination and dynamic iframe resizing.

See the Integration Guide for details on both modes. The SDK handles dimension sync, scroll forwarding, and all message handling automatically.

Next Steps