Record Events

React Native ==> Session module

Pending Upload Queue

Records that have been collected but not yet uploaded are held in a persistent queue. You can inspect the queue without affecting the submission pipeline.

Get the number of records pending upload:

const count = await ValidicCore.getQueuedRecordCount();
console.log(`${count} records pending upload`);

Get the full list of records pending upload as an immutable snapshot:

const records = await ValidicCore.getQueuedInformRecords();
records.forEach(record => console.log(record));

Record Upload To Inform

Listeners can be added to listen for the success or failure of records submitted to the Validic API. Registration of listeners is typically done during component initialization to catch events for record uploads, which may occur upon app start.

ValidicCoreEvents.addListener(
  "validic:core:inform:onrecord",
  (informRecord) => {
    // the record was successfully uploaded to validic servers
    console.log("Successfully submitted record: " + JSON.stringify(informRecord));
  }
);
ValidicCoreEvents.addListener(
  "validic:core:inform:onerror",
  (error) => {
    // an error was returned while submitting the record
    console.error("Record submit failed: " + JSON.stringify(error));
  }
);

A listener can also be set to be notified when a Validic session is ended. An event will be emitted with the existing organization identifier, the user identifier, and any InformRecords that were not submitted to the API before the session was ended. A Validic session will end and an event will be emitted in three scenarios:

  1. ValidicCore.endSession is called after ValidicCore.startSession has previously been called to persist a user.
  2. ValidicCore.startSession is called with a different user than the one that was previously persisted.
  3. An existing user session generates a 401 when making a call to the API due to credentials becoming invalid.
ValidicCoreEvents.addListener("validic:core:inform:onsessionend", (endEvent) => {
  // A session was ended
  console.info(
    "Session ended for " + endEvent.userID + " with " + endEvent.informRecords.length + " unsubmitted records"
  );
});

// remove event listeners when the component is going to be unmounted
componentWillUnmount() {
  ValidicCoreEvents.removeAllListeners("validic:core:inform:onrecord");
  ValidicCoreEvents.removeAllListeners("validic:core:inform:onerror");
  ValidicCoreEvents.removeAllListeners("validic:core:inform:onsessionend");
}


Did this page help you?