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
debug
warning
info
error
ok
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 fetched
This 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
})
cheerio
will parse automatically theresponse.body
in a cheerio instance
req = request({ cheerio: true })
req('http://github.com', $ => {
const repos = $('#repo_listing .repo')
})
jar
is passed torequest
options. Remembers cookies for future use.json
will parse theresponse.body
as 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.
-
files
is 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-collect
application 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 thetimeout
option, thesaveFiles
function 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.accounts
for theBaseKonnector
class (GET
only)io.cozy.files
to save filesio.cozy.bills
to save billsio.cozy.bank.operations
forlinkBankOperations