createWorthOnboarding
Import
Parameters
createWorthOnboarding accepts a single argument object with the following properties:
createWorthOnboarding validates its options synchronously. An invalid or missing inviteToken or other malformed option throws a WorthOnboardingError immediately rather than surfacing it later through mount() or onError. See Error Handling.Example
dist-sdk/sdk3/worthai-onboarding-sdk.global.js.
When loaded directly in a browser page, use the global namespace configured by the SDK build:
Returned Methods
createWorthOnboarding returns a WorthOnboarding object with two methods:
mount(target)
Mounts the embedded onboarding runtime into a DOM target. SDK styles are injected automatically as part of this call.
Parameters:
target: HTMLElement | string- The element to mount into, or a CSS selector string that resolves to one
Promise<HTMLElement>- Resolves with the mounted host element once the runtime has rendered
unmount() before mounting a new instance on the same page.
unmount()
Tears down the mounted runtime, removes its DOM element, and releases the mount target so that a new instance can be mounted later.
Parameters: None
Returns: void
Example:
unmount() will throw a WorthOnboardingError with the code UNMOUNT_FAILED.
Callbacks
onComplete(event)
Observes the completion of the onboarding flow once the applicant has submitted the final step.
Event shape (WorthOnboardingCompleteEvent):
onComplete fails or rejects, it will throw a WorthOnboardingError with the code CALLBACK_FAILED.
onStepSubmit(event)
Observes submitted step payloads as an applicant progresses through the onboarding flow.
Event shape (WorthOnboardingStepSubmitEvent):
onStepSubmit fails or rejects, it will throw a WorthOnboardingError with the code CALLBACK_FAILED.
onError(error)
Observes every SDK and runtime error, including validation failures, mount failures, and callback failures. See Error Handling for a complete list of codes.
onAuthenticated(result) / onAuthUnsupported(result)
Observes authentication outcomes for the invite token.
onAuthenticatedfires when the invite token authenticates successfully. The result includesauthMode,authResponse, andstatus: 'authenticated'onAuthUnsupportedfires when the invite token’s auth mode isn’t supported by the embedded flow. The result includesauthMode,message, an optionalredirectPath, andstatus: 'unsupported'
Error Handling
Every error that the SDK raises is an instance ofWorthOnboardingError, an Error subclass with a stable code:
WorthOnboardingError has the following shape:
Error Codes
Every error raised from
mount() and unmount() is delivered to onError (if provided) before the returned promise rejects with the same error object.Next Steps
- New to SDK 3? Follow the Quick Start Guide
- Migrating from SDK 2? Read the Migration Guide