/** * Available environments for the SDK */ export type Environment = 'production' | 'staging01' | 'public-qa' | 'certification' | 'eilat' | 'localhost'; /** * Configuration options for SDK initialization */ export interface InitOptions { /** The partner name for the SDK instance */ partnerName: string; /** If true, the session will be kept alive in the background via an invisible iframe */ keepAlive?: boolean; /** The environment to use for API endpoints. Defaults to 'production' */ environment?: Environment; /** The branch to use for the melio platform. Defaults to 'main' */ branchOverride?: string; } /** * Base configuration for all flows */ export interface BaseFlowConfig { /** The ID of the DOM element to inject the flow iframe into */ containerId: string; /** Optional authorization code for the flow */ authCode?: string; } export type BusinessType = 'partnership' | 'limitedLiabilityCompany' | 'corporation' | 'nonProfit'; export interface OrganizationDetails { companyName?: string; businessType?: BusinessType; companyLegalName?: string; taxId?: string; legalDateOfBirth?: string; website?: string; description?: string; contactPhone?: string; } export interface UserDetails { email?: string; firstName?: string; lastName?: string; dateOfBirth?: string; } /** * Which page of your product the user came from. Melio uses it to word the button that * ends the flow: * * | `entryPoint` | return button reads | * | --- | --- | * | `'bills'` | "Back to bills" | * | `'contacts'` | "Back to contacts" | * | `'quickpayment'` | "Back to quick payment" | * | `'managepayments'` | "Back to manage payments" | * | `'home'` | "Back to homepage" | * | `'generic'` | "Finish and return" | * * Use `'generic'` when your page has no single destination; omit `entryPoint` for the * default wording. * * @remarks * Wording only — it does not navigate. The `completed` event carries no destination, so your * application still decides where the click lands. */ export type ExternalEntryPoint = 'bills' | 'contacts' | 'quickpayment' | 'managepayments' | 'home' | 'generic'; /** * Configuration for onboarding flow */ export interface OnboardingConfig extends BaseFlowConfig { userDetails?: UserDetails; organizationDetails?: OrganizationDetails; enforceOnboarding?: boolean; /** Which page of your product the user came from; words the button that ends the flow. See {@link ExternalEntryPoint}. */ entryPoint?: ExternalEntryPoint; } /** * Configuration for pay flow */ export interface PayFlowConfig extends BaseFlowConfig { billIds: Array; /** * Which page of your product the user came from; words the button that ends the flow. * Has no effect when `billIdType` is `'melio'`. See {@link ExternalEntryPoint}. */ entryPoint?: ExternalEntryPoint; /** * How the platform should resolve the provided `billIds`. Defaults to `'accounting'`. * - `'accounting'`: `billIds` are external accounting-software ids. The platform imports * them on demand through the external-entries flow. Use this for accounting-software * partners (e.g. Xero, QuickBooks) whose bills originate in the external system. * - `'melio'`: `billIds` are native Melio bill ids returned by `POST /pay-flow/prepare`. * The bills already exist in Melio, so the payment screen opens directly — no * accounting-platform sync. Use this for the prepare-based pay-flow integration. */ billIdType?: 'accounting' | 'melio'; } /** * Configuration for just pay flow (vendor-based payment) */ export interface JustPayFlowConfig extends BaseFlowConfig { /** External vendor IDs to sync and pay */ externalVendorIds: Array; /** Optional amount to prefill in the payment flow */ amount?: number; /** Which page of your product the user came from; words the button that ends the flow. See {@link ExternalEntryPoint}. */ entryPoint?: ExternalEntryPoint; } /** * Configuration for settings flow */ export interface SettingsConfig extends BaseFlowConfig { } /** * Configuration for payments dashboard flow */ export interface PaymentsDashboardConfig extends BaseFlowConfig { paymentId?: string; } /** * Configuration for init flow */ export interface InitConfig extends BaseFlowConfig { authCode: string; } /** * Event data for navigation events */ export interface NavigationData { /** The target route or page the user navigated to */ target: string; targetAction: 'schedulePayment' | 'scheduleBatchPayments' | 'viewSubscriptionPlans' | 'viewSettingsCollaborators' | 'viewPayment' | 'viewPaidPayment' | 'viewBill' | 'addNewBill' | 'viewVendors' | 'addVendor' | 'viewSettings' | 'viewArInvoices' | 'redirect'; } /** * Which button the user clicked inside the embedded Melio app, delivered by the * `buttonClicked` event. * * `'quickPayment'` is the new payment button on the payments dashboard: take the user to * your own supplier selection page, from which you open a payment flow. * * @remarks * Buttons that end a flow keep their existing events — "Back to bills" still arrives as * `completed`. * * Further button types are added in minor releases, so switch on `type` and treat an * unrecognised value as a no-op rather than an error. */ export interface ButtonClickedData { type: 'quickPayment'; } /** * Flow completion data */ export interface FlowCompletionData { /** Any data returned from the completed flow */ flowName: 'onboarding' | 'payment'; [key: string]: any; } /** * Flow error data. * billsSyncFailed could be returned if the following cases: * 1. Trying to sync a non-USD bill * 2. Trying to sync an already paid bill / draft bill * 3. Trying to sync bills with an unsupported amount (amount 0 or greater than $1M) */ export interface ErrorData { errorCode: 'billsSyncFailed'; } /** * Event types that can be listened to */ export type FlowEventType = 'completed' | 'exit' | 'buttonClicked' | 'navigated' | 'authenticationSucceeded' | 'authenticationFailed' | 'error' | 'loaded' | 'onboardingCompleted' | 'onboardingRequired'; /** * Event callback function types */ export type FlowEventCallback = ((data: FlowCompletionData | NavigationData | ErrorData | ButtonClickedData) => void) | (() => void); /** * Flow instance interface for event handling */ export interface FlowInstance { /** * Register an event listener for this flow * @param event - The event type to listen for * @param callback - The callback function to execute when the event occurs */ on(event: 'completed', callback: (data: FlowCompletionData) => void): void; on(event: 'exit', callback: () => void): void; on(event: 'buttonClicked', callback: (data: ButtonClickedData) => void): void; on(event: 'navigated', callback: (payload: NavigationData) => void): void; on(event: 'authenticationSucceeded', callback: () => void): void; on(event: 'authenticationFailed', callback: () => void): void; on(event: 'error', callback: (data: ErrorData) => void): void; on(event: 'loaded', callback: () => void): void; on(event: 'onboardingCompleted', callback: () => void): void; on(event: 'onboardingRequired', callback: () => void): void; /** * Remove an event listener for this flow * @param event - The event type to remove listener for * @param callback - The callback function to remove */ off(event: FlowEventType, callback: FlowEventCallback): void; /** * Close the flow and clean up resources */ close(): void; } export interface InitFlowInstance { /** * Register an event listener for this flow * @param event - The event type to listen for * @param callback - The callback function to execute when the event occurs */ on(event: 'authenticationSucceeded', callback: () => void): void; on(event: 'authenticationFailed', callback: () => void): void; /** * Remove an event listener for this flow * @param event - The event type to remove listener for * @param callback - The callback function to remove */ off(event: FlowEventType, callback: FlowEventCallback): void; /** * Close the flow and clean up resources */ close(): void; } /** * Main SDK interface */ export interface MelioSDK { /** * Initialize the SDK with the provided authorization code * @param authorizationCode - OAuth code received from the partner * @param options - Initialization options * @returns Flow instance for event handling */ init(authorizationCode: string, options: InitOptions): FlowInstance; /** * Launch the onboarding flow * @param config - Configuration for the onboarding flow * @returns Flow instance for event handling */ openOnboarding(config: OnboardingConfig): FlowInstance; /** * Launch the just pay flow (vendor-based payment) * @param config - Configuration for the just pay flow * @returns Flow instance for event handling */ openJustPayFlow(config: JustPayFlowConfig): FlowInstance; /** * Launch the settings flow * @param config - Configuration for the settings flow * @returns Flow instance for event handling */ openSettings(config: SettingsConfig): FlowInstance; /** * Launch the payments dashboard flow * @param config - Configuration for the payments dashboard flow * @returns Flow instance for event handling */ openPaymentsDashboard(config: PaymentsDashboardConfig): FlowInstance; }