Partner Connect SDK
Promise-based JavaScript SDK for secure cross-origin communication between partner apps and LearnCard
The Partner Connect SDK transforms complex postMessage communication into clean, modern Promise-based functions. It handles the entire cross-origin message lifecycle, including request queuing, origin validation, and timeout management.
On this section
This page covers setup, configuration, and mock mode. For the rest of the SDK, see:
Methods β the full API reference: every method, its parameters, and examples
Errors, Types & Migration β error codes, advanced configuration, the migration guide, and TypeScript types
Features
π Secure: Multi-layered origin validation prevents unauthorized access
π― Type-safe: Full TypeScript support with comprehensive type definitions
β‘ Promise-based: Modern async/await API eliminates callback complexity
π§Ή Clean: Abstracts away all postMessage implementation details
π¦ Lightweight: Zero runtime dependencies, ~8KB minified
π‘οΈ Robust: Built-in timeout handling and structured error management
π§ͺ Standalone-ready: Runs and demos on its own via automatic mock mode β no host required
Installation
Quick Start
Standalone / Mock Mode
The SDK only does real work when it's embedded inside LearnCard β that's what answers its requests. Run your app on its own (local dev, a preview deploy, tests) and there's nothing to answer. Standalone calls that aren't mocked reject immediately with LC_NOT_EMBEDDED (instead of hanging until the request timeout), plus a one-time console hint.
Mock mode fixes this automatically in local development and AI app builders. Whenever no LearnCard host is present and your app runs on a local dev host (localhost, 127.0.0.1, [::1], *.localhost, *.local) or in the editor preview of Lovable, Bolt, v0, or Replit, the SDK stands in for LearnCard so your app stays fully usable:
Every method shows a short notice describing what would happen once embedded β e.g.
sendCredentialβ "In LearnCard, the learner would receive [name].",incrementCounterβ "Counter coins β 10.",launchFeatureβ "In LearnCard, this would open /wallet." Strong, visible feedback for every call. At most three show at once (one on phones).A Practice mode pill in the bottom-left corner expands into a plain-language list of the LearnCard features your app uses, with a Publish app button and a copy-link button.
Captures include a stable appKey saved per app title, or the exact mockOptions.appId you provide, so apps sharing an address remain distinct. Use Start over in the expanded panel (with confirmation) or call learnCard.resetPracticeMode() to clear only this app's captures, practice credentials, and counters. The next capture gets a new generated identity; explicit appId values stay unchanged. The method is safe with the UI disabled and does nothing outside mock mode. Icon capture prefers Apple touch icons, large favicons, and same-origin web app manifest icons before /favicon.ico, and tries to include a small rasterized image. Long publish links omit the embedded image.
requestConsent(...)grants automatically and the notice spells out what the learner would be asked to share; counters (incrementCounter/getCounter/getCounters) save to the browser and survive reloads.Identical or polled calls coalesce into one notice with a ΓN counter, so nothing spams the screen.
requestIdentity, notifications, learner context, and sync status return sensible placeholder data.Everything is also logged to the console with a
[LearnCard SDK Β· MOCK]prefix.
No flags, no separate build in local dev. Your app is demo-able locally and behaves exactly the same against the real host once embedded.
mock
Local dev or app-builder preview
Standalone, other origin
Embedded in LearnCard
'auto' (default)
mock
fail fast (LC_NOT_EMBEDDED)
real host
'standalone'
mock
mock
real host
true
mock
mock
mock
false
fail fast
fail fast
real host
If your app is embedded in something that isn't LearnCard (a cross-origin Storybook canvas, a preview shell), calls don't hang: the SDK mocks in local dev and app-builder previews and otherwise rejects fast with LC_NOT_EMBEDDED. When the parent can't be identified (Firefox, or a same-origin localhost wrapper), a one-time side-effect-free presence probe decides β the SDK only mocks if no host answers within hostProbeTimeout (default 1500 ms).
Every mocked call shows a labeled toast and a [LearnCard SDK Β· MOCK] console log, so it's clear the SDK is simulating rather than talking to a real host. For a production build meant to run only inside LearnCard, set mock: false β standalone calls then reject immediately with LC_NOT_EMBEDDED.
Overrides:
Use learnCard.isMocked() to check whether an instance is currently mocking.
The mock keeps a small session store, so reads reflect writes: after sendCredential(...), calls like checkUserHasCredential, getTemplateRecipients, requestLearnerContext, and askCredentialSearch return that credential β so happy-path UI actually lights up standalone. Use mockOptions.credentials / identity / counters to pre-populate state without performing an action first. Mock credentials are marked _mock: true and are never cryptographically valid.
Security Model
The Partner Connect SDK implements comprehensive security measures:
Origin Validation
Strict Enforcement:
Incoming messages must exactly match the configured host origin
No wildcard (
*) origins are ever usedQuery parameter overrides are validated against whitelist
Configuration Hierarchy:
Default:
https://learncard.app(security anchor)Query Parameter Override:
?lc_host_override=https://staging.learncard.appConfigured Origin: From
hostOriginoption
Example:
Message Security
Protocol Verification: Messages must match expected protocol version
Request ID Tracking: Only tracked requests are processed
Timeout Protection: Requests automatically timeout to prevent hanging
Cleanup on Destroy: Pending requests are properly rejected
Browser Support
Chrome/Edge: 90+
Firefox: 88+
Safari: 14+
Mobile: iOS Safari 14+, Android Chrome 90+
Required APIs:
postMessagePromiseURLSearchParamsaddEventListener
Related Documentation
Build an App Inside LearnCard - Step-by-step guide for App Store credential issuance
LearnCard Core SDK - Backend credential operations
LearnCard Network - Network integration
Connect a User's LearnCard to Your Platform - Integration guide
App Store Development - LearnCard app ecosystem
Last updated
Was this helpful?