Skip to main content
This page covers @cas-parser/connect v2.x. For the underlying APIs the widget calls, see the API Reference.

Authentication

Never expose your raw API key to the browser. Mint a short-lived access token (at_*) on your backend via POST /v1/token and pass that to the widget instead.
The widget accepts either credential — both are sent as the x-api-key header. At least one of accessToken / apiKey is required.
Access tokens:
  • Prefix: at_
  • TTL: 1–60 minutes (default: 60)
  • Drop-in replacement for x-api-key on /v4/* endpoints
  • Cannot mint other tokens

Props


Config

Inbound email config

When enableInboundEmail: true, the widget creates a one-time forwarding address via POST /v4/inbound-email, polls GET /files, and parses the first file it receives. This works without a callback_url. You can also pass an existingId (and optionally email) to inject an inbound email you’ve already created on your backend — useful when you want a stable address per user, or when you’re driving the API yourself and only need the SDK for the polling/UI. The callbackUrl here is the underlying API’s callback_url — set it if you want both webhook delivery to your backend and in-widget reception. Omit for a pure-frontend integration.

Events

onSuccess

Fires once per successful import. The signature is two arguments, not a single payload object.

onError

Error codes the SDK emits: The type is widened to | string, so future codes won’t break exhaustive switches.

onExit

Fires whenever the widget closes — after success, after error, or on user cancel. No argument is passed; combine with state set in onSuccess / onError if you need to distinguish.

onEvent

Fires for every widget event. Useful for analytics integrations. Selected events:
  • Lifecycle: WIDGET_OPENED, WIDGET_CLOSED, MODE_SWITCHED, ASSET_SELECTED, BROKER_SELECTED
  • Upload: FILE_SELECTED, FILE_REMOVED, UPLOAD_STARTED, UPLOAD_PROGRESS, PARSE_STARTED, PARSE_SUCCESS, PARSE_ERROR
  • Generator: GENERATOR_STARTED, GENERATOR_SUCCESS, GENERATOR_ERROR
  • CDSL fetch: CDSL_FETCH_STARTED, CDSL_OTP_SENT, CDSL_OTP_VERIFIED, CDSL_FETCH_SUCCESS, CDSL_FETCH_ERROR
  • Gmail inbox: INBOX_CONNECT_STARTED, INBOX_CONNECTED, INBOX_FILES_LOADED, INBOX_FILE_SELECTED, INBOX_DISCONNECTED, INBOX_ERROR
  • Inbound email: INBOUND_EMAIL_CREATED, INBOUND_EMAIL_COPIED, INBOUND_EMAIL_POLLING, INBOUND_EMAIL_FILE_RECEIVED, INBOUND_EMAIL_TIMEOUT, INBOUND_EMAIL_ERROR
  • Cross-flow handoffs — measure how often the widget’s nudges convert: GENERATOR_TO_INBOUND_HANDOFF, INBOX_TO_GENERATOR_HANDOFF, INBOUND_TO_UPLOAD_HANDOFF, UPLOAD_TO_INBOUND_HANDOFF
The metadata object always includes timestamp and may include event-specific fields.

onSubmit — collect PDFs without parsing

v2.1+. When onSubmit is provided, the SDK routes every intercept-capable flow through it instead of calling the parse API itself. Useful for:
  • Forwarding PDFs to your own backend without burning parse credits
  • Custom retry / queueing logic
  • Storing a copy of the PDF before parsing
The MF generator (KFintech mailback) flow stays out of scope — the CAS is delivered to the investor’s email out of band, so the SDK never sees a PDF. The return value is forwarded to onSuccess. Throw to trigger onError.

Framework integration

React / Next.js

For Next.js App Router, mark the parent component 'use client' and fetch the access token from a server route.

Vanilla JS / Angular / Vue (Imperative API)

The standalone bundle ships its own React copy — no host-page React required.
If your page already has React 18+, use the lighter UMD bundle:
Bundle sizes (gzipped):
  • Standalone: ~71 KB (includes React)
  • UMD: ~27 KB (requires React 18+ on the page)
The imperative open() accepts the same accessToken / apiKey / apiBaseUrl / config / onSubmit / onEvent as the React props, plus an optional onOpen lifecycle hook. The success / error / cancel callbacks are intentionally dropped — the returned OpenResult covers all three outcomes. If you need manual control (open the widget later, dispose without opening), use PortfolioConnect.create(config) which returns a { open, destroy } handle.

React Native / Flutter

Both are supported via WebView. See the @cas-parser/connect examples for working setups.

Theming

The recommended way to brand the widget is the config.theme object — it emits CSS variables on the modal root and derives the full palette (hover, soft, surface, border, text) from your primary colour automatically.

CSS variables

If you need to override individual tokens beyond what theme exposes, set the CSS variables directly. The full list emitted on the modal root:
theme.mode: 'auto' follows the user’s prefers-color-scheme media query.

Next steps

Inbound Email Guide

Forward-email flow used by enableInboundEmail

API Reference

Endpoints the widget calls under the hood