Skip to main content

Configuration

Every option is passed to OsiguPreAuth.mount({...}) when you initialise the widget. Options are grouped by concern below.

Required

OptionTypePurpose
containerstring | HTMLElementCSS selector or DOM node the widget will render into.
getToken() => Promise<string>Called whenever the widget needs an access token. Return your cached token from a server-side proxy.
environment'sandbox' | 'production'Which Osigu environment to talk to. Affects both API base URL and OTP delivery.

Common

OptionTypePurpose
sponsorSlugstringLock the widget to a specific sponsor. Omit to let the beneficiary picker filter across all affiliated sponsors.
productType'MEDICATION' | 'LAB' | 'IMAGING' | 'PROCEDURE'Lock the flow to a single product type. Omit for a picker.
locale'en' | 'es' | 'pt-BR'UI language. Defaults to browser locale.
theme'light' | 'dark' | 'auto'Colour scheme. auto follows the user's OS preference.

Prefill

Prefill saves the beneficiary the trouble of re-typing what your app already knows.

OptionTypePurpose
prefill.beneficiaryIdstringSkip beneficiary search — go straight to product selection with this ID.
prefill.beneficiarySearchInputobjectPre-fill the search form values (e.g. { document_type: 'CC', document_number: '...' }). User can still edit.
prefill.diagnosisCodestringPreselect the diagnosis.
prefill.productsArray<{product_code, quantity, posology?}>Preselect one or more products.

Behaviour hooks

OptionTypePurpose
hooks.beforeSubmitasync (payload) => payload | falseCalled with the request payload just before POST /authorization-requests. Return a modified payload to mutate; return false to cancel.
hooks.onStepChange(step) => voidFires whenever the widget moves to a new step. Useful for analytics.
hooks.decorateSearchResult(beneficiary) => beneficiaryPost-process the beneficiary object before the user sees it.

Callback events

OptionSignaturePurpose
onReady() => voidWidget is mounted and ready.
onComplete(outcome) => voidUser finished the flow. See Events for the shape.
onError(err) => voidSomething went wrong. See Events for err shape.
onClose() => voidUser closed the widget without completing.

Telemetry

OptionTypePurpose
telemetry.trackingIdstringOptional identifier attached to internal request logs (e.g. your session ID). Osigu's support team can trace by this.
telemetry.disabledbooleanSet true to opt out of Osigu's usage analytics. Default false.

Advanced

OptionTypePurpose
apiBaseUrlstringOverride the API host. Only use if Osigu's ops team explicitly gave you a private URL.
debugbooleanLog verbose events to the console. Off by default.

Full example

OsiguPreAuth.mount({
container: '#osigu-preauth',
getToken: async () => (await fetch('/api/osigu/token')).json().then(r => r.access_token),
environment: 'sandbox',

sponsorSlug: 'sponsor-sandbox',
productType: 'MEDICATION',
locale: 'es',
theme: 'auto',

prefill: {
beneficiaryId: 'bnf_01HW8...',
diagnosisCode: 'R51',
products: [{ product_code: 'MED-042', quantity: 30, posology: '1c/8h' }],
},

hooks: {
beforeSubmit: async (payload) => {
// stamp our internal case number
payload.additional_data = { ...payload.additional_data, case_id: myCaseId };
return payload;
},
onStepChange: (step) => analytics.track('preauth_step', { step }),
},

telemetry: {
trackingId: `session-${sessionId}`,
},

onReady: () => console.log('widget ready'),
onComplete: (outcome) => {
if (outcome.authorizations[0].status === 'APPROVED') {
redirect(`/authorizations/${outcome.authorizations[0].authorization_code}`);
}
},
onError: (err) => Sentry.captureException(err),
onClose: () => history.back(),
});