Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
161 lines (110 sloc) 5.2 KB

Developer Chat Apache 2.0 License Typescript Web


Requesting User Data

To request user data, you'll need to have created a session and asked for user's consent. Please see the appropriate sections on how to do these.

getSessionData

Once the user has given consent, we can now call getSessionData to receive user data. This function polls digi.me until we have received all the data the user has that satisfies the contract. getSessionData will return a promise which will resolve when all the files are fetched and a function which you can trigger to stop the data fetch process for whatever reason.

getSessionData = (
    sessionId: string,
    privateKey: NodeRSA.Key,
    onFileData: FileSuccessHandler,
    onFileError: FileErrorHandler
): GetSessionDataResponse;

Returns GetSessionDataResponse

sessionId: string

Session ID received when we first established as session

privateKey: NodeRSA.Key

Private key in PKCS1 format which can be used to decrypt user's data. This is related to the contract, so you would need this when you receive the contract Id from digi.me.

onFileData: FileSuccessHandler

This callback function is triggered whenever we have received data from the server. The content is passed back in files, so this function will be triggered whenever we have received data from one file. The callback will be triggered with an object in the parameter. The object has the following properties:

onFileError: FileErrorHandler

This callback function is triggered whenever we have failed to receive any data for the data file. By default, we try to fetch the data five times with exponential backoff before invoking the error callback. You can configure the retry options when you initiate the SDK.

Exceptions

ParameterValidationError

FileDecryptionError

GetSessionDataResponse

This is what you'll receive when you call getSessionData()

interface GetSessionDataResponse = {
    stopPolling: () => void;
    filePromise: Promise;
}

stopPolling: function

A function which stops the polling when you've called getSessionData(). This is used to prematurely stop the data fetching before all the user data has been received.

filePromise: Promise

A promise that will resolve once all user files have been processed.

FileSuccessHandler

This is the callback that is triggered whenever we've received data from a user. This function will be called once everytime we've fetched a user file. This may be called multiple times per file if the file has been updated since last time we fetched.

type FileSuccessHandler = ({
    fileData: any,
    fileDescriptor: FileDescriptor,
    fileName: string,
    fileList: string[],
}): void;

fileData: string

JSON string of data objects

fileDescriptor: FileDescriptor

Object describing data that is returned

fileName: string

The filename which the objects reside in

fileList: string[]

The list of all files that are to be returned

FileDescriptor

interface FileDescriptor {
    objectCount: number;
    objectType: string;
    serviceGroup: string;
    serviceName: string;
}

objectCount: number

How many data objects are returned in this file.

objectType: string

What data these objects represent. E.g. Media For a full list, please check out our Reference Objects guide on our developer docs.

serviceGroup: string

What service group the data belongs to. E.g. Social. For a full list, please check out our Reference Objects guide on our developer docs.

serviceName: string

What service the data came from. E.g. Facebook. For a full list, please check out our Reference Objects guide on our developer docs.

FileErrorHandler

The error callback will be triggered whenever we encounter a problem with downloading a user file. This callback will contain an object in the parameter. The object has the following properties:

type FileErrorHandler = ({
    error: Error,
    fileName: string,
    fileList: string[],
}): void;

error: Error

Object containing the error

fileName: string

The filename which the objects reside in

fileList: string[]

The list of all files that are to be returned


Back to Index

You can’t perform that action at this time.