Skip to main content

Type Alias: NablaConnectClient

NablaConnectClient = object & EventTarget

A client for one Connect iframe, bound to one iframe load. It is an EventTarget: see NablaConnectEventMap.

Type Declaration​

addEventListener​

addEventListener: <K>(type, listener, options?) => void

Listens to an SDK event.

Type Parameters​

K​

K extends keyof NablaConnectEventMap

Parameters​

type​

K

stateChanged, noteExported, patientInstructionsExported or error.

listener​

NablaConnectEventListener<K>

Receives the payload on event.detail.

options?​

boolean | AddEventListenerOptions

As for EventTarget.addEventListener.

Returns​

void

destroy​

destroy: () => void

Ends the client and rejects every pending call with DESTROYED. Idempotent.

Returns​

void

Remarks​

Call it before the iframe changes encounter, after NablaConnectClient.waitUntilClosable when the encounter must not lose anything.

exportNote​

exportNote: () => Promise<void>

Exports the note, like the Export button.

Returns​

Promise<void>

Remarks​

Needs EXPORT_NOTE in NablaConnectState.availableActions. A failed export rejects with COMMAND_REJECTED and the reason EXPORT_FAILED.

Throws​

NablaConnectError with BUSY (another command runs, the state is in transition, or the provider is finishing the Nabla onboarding), INVALID_MESSAGE (the iframe could not read the command), COMMAND_REJECTED (with a reason), TIMEOUT (after 30 seconds), CONTEXT_CHANGED, DESTROYED or UNKNOWN. Before ready, also the error that ends the client: UNSUPPORTED_VERSION, INVALID_ORIGIN or TIMEOUT. After the client ended, the error that ended it.

getCurrentState​

getCurrentState: () => NablaConnectState | null

The latest state.

Returns​

NablaConnectState | null

The same object until the next stateChanged. null until the first state, and once the client has ended.

ready​

readonly ready: Promise<NablaConnectState>

The first state, once the iframe has loaded and the handshake is done.

Remarks​

The wait starts at create and lasts 30 seconds.

Throws​

NablaConnectError with UNSUPPORTED_VERSION, INVALID_ORIGIN, CONTEXT_CHANGED, UNKNOWN or DESTROYED. The client is then ended: create a new one. Or with TIMEOUT when the first state did not come in time: the client is not ended, it keeps listening and reports a late first state on stateChanged. Commands called before it reject with TIMEOUT too.

removeEventListener​

removeEventListener: <K>(type, listener, options?) => void

Stops listening to an SDK event.

Type Parameters​

K​

K extends keyof NablaConnectEventMap

Parameters​

type​

K

stateChanged, noteExported, patientInstructionsExported or error.

listener​

NablaConnectEventListener<K>

The listener given to addEventListener.

options?​

boolean | EventListenerOptions

As for EventTarget.removeEventListener.

Returns​

void

startNoteGeneration​

startNoteGeneration: () => Promise<void>

Stops the recording if needed, then starts the note generation. From NOTE_READY, it generates the note again.

Returns​

Promise<void>

Remarks​

Needs GENERATE_NOTE in NablaConnectState.availableActions. It resolves once the generation has started. The generation ends on stateChanged, with NOTE_READY or with reason set to NOTE_GENERATION_FAILED.

Throws​

NablaConnectError with BUSY (another command runs, the state is in transition, or the provider is finishing the Nabla onboarding), INVALID_MESSAGE (the iframe could not read the command), COMMAND_REJECTED (with a reason), TIMEOUT (after 30 seconds), CONTEXT_CHANGED, DESTROYED or UNKNOWN. Before ready, also the error that ends the client: UNSUPPORTED_VERSION, INVALID_ORIGIN or TIMEOUT. After the client ended, the error that ended it.

startRecording​

startRecording: () => Promise<void>

Starts the recording, or resumes it from PAUSED or NOTE_READY.

Returns​

Promise<void>

Remarks​

Needs START_RECORDING in NablaConnectState.availableActions.

Throws​

NablaConnectError with BUSY (another command runs, the state is in transition, or the provider is finishing the Nabla onboarding), INVALID_MESSAGE (the iframe could not read the command), COMMAND_REJECTED (with a reason), TIMEOUT (after 30 seconds), CONTEXT_CHANGED, DESTROYED or UNKNOWN. Before ready, also the error that ends the client: UNSUPPORTED_VERSION, INVALID_ORIGIN or TIMEOUT. After the client ended, the error that ended it.

stopRecording​

stopRecording: () => Promise<void>

Stops the recording, like Pause in the Nabla UI.

Returns​

Promise<void>

Remarks​

Needs STOP_RECORDING in NablaConnectState.availableActions. Accepted without effect when nothing is recording, so repeating it is safe.

Throws​

NablaConnectError with BUSY (another command runs, the state is in transition, or the provider is finishing the Nabla onboarding), INVALID_MESSAGE (the iframe could not read the command), COMMAND_REJECTED (with a reason), TIMEOUT (after 30 seconds), CONTEXT_CHANGED, DESTROYED or UNKNOWN. Before ready, also the error that ends the client: UNSUPPORTED_VERSION, INVALID_ORIGIN or TIMEOUT. After the client ended, the error that ended it.

waitUntilClosable​

waitUntilClosable: () => Promise<void>

Waits until NablaConnectState.canBeClosed is true, at once if it already is. It has no timeout.

Returns​

Promise<void>

Throws​

NablaConnectError: the error that ended the client, like DESTROYED, CONTEXT_CHANGED or the rejection of ready.

Remarks​

No method throws. Failures arrive as rejected promises or on the error event, and an unexpected failure inside the SDK is an UNKNOWN error that leaves the client running.

A command resolves once the iframe has run it, and its effect arrives on stateChanged. One command runs at a time, and a command called before ready waits for it. Every command rejects with a NablaConnectError:

  • BUSY: another command is running, the iframe is changing state, or the provider is finishing the Nabla onboarding.
  • COMMAND_REJECTED: the iframe refused or failed it. See NablaConnectError.reason.
  • INVALID_MESSAGE or UNKNOWN: the iframe could not read it, the SDK could not send it, or this SDK could not read the answer.
  • TIMEOUT: no answer within 30 seconds.
  • The error that ended the client, like DESTROYED, CONTEXT_CHANGED or the rejection of ready.