The launched event will emit a session token which can be used to resume a session. By default, OneSchema will save the session token and resume in case the session was not closed through normal means (usually the browser closing or refreshing). It will not resume if the user cancels the session or if it ends. This behavior is done through the saveSession param.
If you would like to manually resume a session, you can save the session token from the launched event and then later pass it into an importer session at launch. Once a session is complete (through success, error, or cancel), it should no longer be used to init.
The following code snippet shows how you can save the session token to a variable and use later. Consider also saving to something more persistent, like browser storage.
The OneSchemaImporterClass is used to integrate OneSchema into your application. It inherits from the EventEmitter class to emit events that happen in OneSchema.
The launch function will show the OneSchema iframe and begin an importing session. Optionally, pass in params as overrides or that were not given during initialization.
The parameters that can be passed to the launch function
close(clean = false)
The close function will hide the OneSchema iframe from view.
clean
Optional
Type
boolean
Description
If true, will remove and clean up all listeners and remove the iframe from DOM. By default, false
setClassName(className)
className
Required
Type
string
Description
The CSS class that should be set on the iframe. Replaces existing value
setStyles(styles)
styles
Required
Type
Object (CSSStyleDeclaration)
Description
The CSS styles that should be set on the iframe. Replaces existing values
setParent(parent)
parent
Required
Type
HTMLElement
Description
The HTML Element the iframe should be appended to. When called, the iframe will move in the DOM. This will cause the iframe's page to reload.
setIframe(iframe)
iframe
Required
Type
HTMLIFrameElement
Description
The iframe the class should manage. This will set the URL and event listeners for this iframe. This should be used with the OneSchemaParam manageDom set to false.
success Event
The success event will fire when the import is complete. The parameter to the callback will include the data that has been imported for "local" imports. The format of the data is documented here.
For webhook imports, the result will be an object with eventId and responses:
The eventId field will contain a string identifier that was included in the webhook requests. You can use this to associate the user’s session with the requests sent to your webhook. (You could also use the user JWT, which is also sent with the webhook requests, to do this.)
The responses field returns the bodies of the responses sent by your webhook endpoint. It is entirely fine to return nothing at all — you can return whatever data you’d like here. It will be array of objects with a body field containing the response, and a sequenceNumber field that indicates which request returned that response. Once this data is sent to your app you can use it however you want to guide the rest of the user’s import process.
cancel Event
The cancel event will fire when the import is cancelled.
error Event
The error event will fire when an error occurs during the import. The parameter to the callback will be a OneSchemaError.
launched Event
The launched event will fire when the iframe is ready to display. This will happen shortly after launch is called. The event data will include a field named sessionToken which can be used to resume a session manually.
Whether the iframe should automatically hide when completion events are emitted. Defaults to true.
saveSession
Optional
Type
boolean
Description
Whether the SDK should save session information to browser storage so that an import can be resumed (if someone closes the browser and returns). The session is saved based on the JWT and template key. This will not save the session if it is 'cancelled'.
Defaults to true.
manageDOM
Optional
Type
boolean
Description
Whether the class should create and append an iframe to the DOM. If false, you will need to make an iframe and pass the reference to the class via setIframe so that it can be used. Defaults to true.
OneSchemaLaunchParams
These values can be passed into the launch function or with the OneSchemaParams at initialization
Configuration for how data will be imported out of OneSchema when the import is complete. If not specified, will be a full LocalImportConfig
eventWebhookKeys
Optional
Type
string[]
Description
An array of strings for event webhooks to be triggered during the import. For more information, see Using Event Webhooks.
OneSchemaLaunchSessionParams
These values can be passed into the launch function or with the OneSchemaParams at initialization
sessionToken
Required
Type
string
Description
Unique string key which identifies the configuration that the OneSchema importer should initialize as. To be used when initializing the importer via external API.
If success is false, will be included with enum value of error
OneSchemaLaunchError
values
MissingTemplate
templateKey was not passed in at init or launch
MissingJwt
userJwt was not passed in at init or launch
MissingSessionToken
sessionToken was not passed in at init or launch
ImportConfig
Configuration for how data will be imported out of OneSchema when the import is complete.
An import config is one of the following types:
LocalImportConfig
type
Required
Type
"local"
metadataOnly
Optional
Type
boolean
Description
Whether the import should only include metadata. This can then be used inconjuction with the API to get data. If false, all row data will be included in the import
WebhookImportConfig
type
Required
Type
"webhook"
key
Required
Type
string
Description
The webhook key which has been setup inside OneSchema the data should be sent to when the import is complete
FileUploadImportConfig
type
Required
Type
"file-upload"
url
Required
Type
string
Description
The signed url that the file should be sent to
format
Optional
Type
string ("csv" | "json")
Description
The type of file that should be sent. Defaults to "csv"
headers
Optional
Type
Object { [key: string] : string }
Description
Request headers that should be sent on the PUT request. Header names should not contain underscores and should be all lowercase. Header values must be strings.