@wetransform/core
v1.1.0
Published
Headless browser SDK to open WeTransform in your app (modal or inline), authenticate, and interact through a typed event API.
Readme
@wetransform/core
Headless browser SDK to open WeTransform in your app (modal or inline), authenticate, and interact through a typed event API.
Installation
npm install @wetransform/coreUsage
import { createWeTransform } from '@wetransform/core'
const sdk = createWeTransform({
organizationHandle: 'acme',
locale: 'en',
displayAsModal: true,
initialLocation: 'transformations',
authentication: {
customerId: 'ext-123',
signature: 'signed-payload',
templateHandle: 'demo-template',
sourceId: 'newsletter',
},
})
// Subscribing to the successSubmit event
sdk.on('successSubmit', (payload) => console.log('File successfully submitted', payload))
// Opening WeTransform
await sdk.open()
// Dynamically switch locale without remounting
await sdk.setLocale('fr')
// Close WeTransform
await sdk.close()
// Destroy WeTransform session
await sdk.destroy()API
createWeTransform(config)
Returns a WeTransformInstance with:
open(): Promise<void>- initializes auth and mounts WeTransformclose(): Promise<void>- closes SDK UI and unmounts WeTransformdestroy(): Promise<void>- closes and tears down SDK resourcessetLocale(locale): Promise<void>- updates locale/auth context and syncs iframe locale when activeon(event, handler): () => void- subscribes to SDK events, returns unsubscribe function
WeTransformConfig
organizationHandle: stringlocale?: 'en' | 'fr'authentication: WeTransformAuthenticationConfiginitialLocation?: 'transformations' | 'uploader' | 'mapper' | 'finalize' | 'sourcePreview' | 'sourceUpdate' | 'scheduler'displayAsModal?: boolean(default:true)mountElement?: string | HTMLElement(default id:weTransform_iframeContainer, used whendisplayAsModalisfalse)
locale defaults to 'en' when not provided.
Runtime locale switching
setLocale('en' | 'fr')is additive and does not require destroy/recreate.- If the locale is unchanged,
setLocaleis a no-op. - If SDK status is
open, locale is sent to iframe immediately via bridge messaging. - If SDK status is
opening, locale is sent after iframe readiness is reached. setLocaleupdates auth API URL context to{VITE_SENDER_API_URL}/{locale}/send/{organizationHandle}for subsequent auth calls.- Calling
setLocaleafterdestroy()throwsCannot set locale after destroy.
Inline mounting behavior (displayAsModal: false)
When displayAsModal is false, wetTransform SDK mounts the iframe into:
- the element with id
weTransform_iframeContainerby default, or - the element resolved from
mountElementwhen you provide one.
If the target element does not exist, the SDK creates the container and appends it to document.body.
Some initialLocation values require additional auth fields:
uploader: requiresauthentication.templateHandlemapper,finalize,sourcePreview,sourceUpdate,scheduler: require bothauthentication.templateHandleandauthentication.sourceId
WeTransformAuthenticationConfig
customerId: stringsignature: stringtemplateHandle?: stringsourceId?: string
Events
Supported sdk.on(...) events:
openclosedestroyonReadysuccessSubmitwith payload
{
customerId: string
templateHandle: string
fileUrl: string
signature: string
// Deprecated
redirectUrl: string
}errorwith payload{ code: string; message: string }
