The class from which all the connectors must inherit. It takes a fetch function in parameter that must return a Promise.
const { BaseKonnector } = require('cozy-konnector-libs')
module.exports = new BaseKonnector(function fetch () {
// use this to access the instance of the konnector to
// store any information that needs to be passed to
// different stages of the konnector
})
Its role is twofold :
- Make the link between account data and konnector
- Handle errors
Use it to log messages in your konnector. Typical types are
debugwarninginfoerrorok
They will be colored in development mode. In production mode, those logs are formatted in JSON to be interpreted by the stack and possibly sent to the client. error will stop the konnector.
logger = log('my-namespace')
logger('debug', '365 bills')
// my-namespace : debug : 365 bills
logger('info', 'Page fetched')
// my-namespace : info : Page fetchedThis is a cozy-client-js instance already initialized and ready to use
This is a function which returns an instance of request-promise initialized with defaults often used in connector development.
// Showing defaults
req = request({
cheerio: false,
jar: true,
json: true
})cheeriowill parse automatically theresponse.bodyin a cheerio instance
req = request({ cheerio: true })
req('http://github.com', $ => {
const repos = $('#repo_listing .repo')
})jaris passed torequestoptions. Remembers cookies for future use.jsonwill parse theresponse.bodyas JSON
A shortcut the the bluebird-retry
const { retry } = require('cozy-konnector-libs')
Used not to duplicate data.
options:keys: List of keys used to check that two items are the same. By default it is set to `['id']'.index: Return value returned bycozy.data.defineIndex, the default will correspond to all documents of the selected doctype.selector: Mango request to get records. Default is built from the keys{selector: {_id: {"$gt": null}}}to get all the records.
The goal of this function is to save the given files in the given folder via the Cozy API.
-
filesis an array of{ fileurl, filename }:- fileurl: The url of the file. This attribute is mandatory or this item will be ignored
- filename : The file name of the item written on disk. This attribute is optional and as default value, the file name will be "smartly" guessed by the function. Use this attribute if the guess is not smart enough for you.
-
folderPath(string) is relative to the main path given by thecozy-collectapplication to the connector. If the connector is run in standalone mode, the main path is the path of the connector. -
options(object) is optional. Possible options :timeout(timestamp) can be used if your connector needs to fetch a lot of files and if the the stack does not give enough time to your connector to fetch it all. It could happen that the connector is stopped right in the middle of the download of the file and the file will be broken. With thetimeoutoption, thesaveFilesfunction will check if the timeout has passed right after downloading each file and then will be sure to be stopped cleanly if the timeout is not too long. And since it is really fast to check that a file has already been downloaded, on the next run of the connector, it will be able to download some more files, and so on. If you want the timeout to be in 10s, doDate.now() + 10*1000. You can try it in the previous code.
Creates the records in the given doctype.
Combines the features of saveFiles, filterData, addData and linkBankOperations. Will create io.cozy.bills objects. The default deduplication keys are ['date', 'amount', 'vendor'].
options is passed directly to saveFiles, filterData, addData and linkBankOperations.
This function will soon move to a dedicated service. You should not use it. The goal of this function is to find links between bills and bank operations.
Please note that some classes require some permissions:
io.cozy.accountsfor theBaseKonnectorclass (GETonly)io.cozy.filesto save filesio.cozy.billsto save billsio.cozy.bank.operationsforlinkBankOperations