How does it work
How does it work?¶
A connector is a NodeJS script. +The target node version used to run your connector is the version 8.
Like client side apps, connectors communicate with the Cozy Stack using its HTTP API, and get a unique auth token every time they start.
They need to register with a manifest, and ask the user for permissions.
To facilitate connector development, a npm package, cozy-konnector-libs, provides some shared libraries that are adapted to be used for a connector:
- cheerio to easily query a HTML page
- request-promise: request with Promise support
- request-debug that displays all the requests and responses in the standard output. Toggle debug option in requestFactory options
Besides, you’ll probably need some other npm packages to help you run your connector:
When the connector is started, it also receives some data via environment variables:
COZY_CREDENTIALS
: an auth token used by cozy-client-js to communicate with the serverCOZY_URL
: the Cozy Stack API entry pointCOZY_FIELDS
: settings coming from Cozy Home and filled by the user (login, password, directory path).
These variables are used by the connector and the cozy-client to configure the connection to the Cozy Stack with the right permissions as defined in the connector manifest. They are simulated in standalone mode so that you do not need a real Cozy Stack to develop a connector. [More about BaseKonnector]
From the server point of view, each connector is a job
which is executed periodically via a trigger
.
[More about Cozy Stack jobs]