Compare commits

...

No commits in common. 'master' and 'build' have entirely different histories.

10 changed files with 101625 additions and 11398 deletions
Split View
  1. +0
    -31
      .gitignore
  2. +0
    -135
      CONTRIBUTING.md
  3. +126
    -12
      README.md
  4. +0
    -96
      index.js
  5. +101472
    -0
      konnector.js
  6. +21
    -14
      manifest.konnector
  7. +0
    -6586
      package-lock.json
  8. +6
    -6
      package.json
  9. +0
    -19
      webpack.config.js
  10. +0
    -4499
      yarn.lock

+ 0
- 31
.gitignore View File

@@ -1,31 +0,0 @@
# NPM
node_modules/
npm-debug.log
yarn-error.log

# connector data files
.account
.token.json
konnector-dev-config.json

# Build
build/

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
desktop.ini


# Editors / IDEs
.floo
.flooignore

# Default
# /!\ KEEP THIS SECTION THE LAST ONE
!.gitkeep

+ 0
- 135
CONTRIBUTING.md View File

@@ -1,135 +0,0 @@
How to contribute to Cozy <APP_NAME>?
====================================

Thank you for your interest in contributing to Cozy! There are many ways to contribute, and we appreciate all of them.


Security Issues
---------------

If you discover a security issue, please bring it to our attention right away! Please **DO NOT** file a public issue, instead send your report privately to security AT cozycloud DOT cc.

Security reports are greatly appreciated and we will publicly thank you for it. We currently do not offer a paid security bounty program, but are not ruling it out in the future.


Bug Reports
-----------

While bugs are unfortunate, they're a reality in software. We can't fix what we don't know about, so please report liberally. If you're not sure if something is a bug or not, feel free to file a bug anyway.

Opening an issue is as easy as following [this link][issues] and filling out the fields. Here are some things you can write about your bug:

- A short summary
- What did you try, step by step?
- What did you expect?
- What did happen instead?
- What is the version of the Cozy <APP_NAME>?


Pull Requests
-------------

Please keep in mind that:

- Pull-Requests point to the `master` branch
- You need to cover your code and feature by tests
- You may add documentation in the `/docs` directory to explain your choices if needed
- We recommend to use [task lists][checkbox] to explain steps / features in your Pull-Request description
- you do _not_ need to build app to submit a PR
- you should update the Transifex source locale file if you modify it for your feature needs (see [Localization section in README][localization])


### Workflow

Pull requests are the primary mechanism we use to change Cozy. GitHub itself has some [great documentation][pr] on using the Pull Request feature. We use the _fork and pull_ model described there.

#### Step 1: Fork

Fork the project on GitHub and [check out your copy locally][forking].

```
$ git clone github.com/<USERNAME_GH>/<SLUG_GH>.git
$ cd <SLUG_GH>
$ git remote add fork git://github.com/yourusername/<SLUG_GH>.git
```

#### Step 2: Branch

Create a branch and start hacking:

```
$ git checkout -b my-branch origin/master
```

#### Step 3: Code

Well, we think you know how to do that. Just be sure to follow the coding guidelines from the community ([standard JS][stdjs], comment the code, etc).

#### Step 4: Test

Don't forget to add tests and be sure they are green:

```
$ cd <SLUG_GH>
$ npm run test
```

#### Step 5: Commit

Writing [good commit messages][commitmsg] is important. A commit message should describe what changed and why.

#### Step 6: Rebase

Use `git rebase` (_not_ `git merge`) to sync your work from time to time.

```
$ git fetch origin
$ git rebase origin/master my-branch
```

#### Step 7: Push

```
$ git push -u fork my-branch
```

Go to https://github.com/yourusername/<SLUG_GH> and select your branch. Click the 'Pull Request' button and fill out the form.

Alternatively, you can use [hub] to open the pull request from your terminal:

```
$ git pull-request -b master -m "My PR message" -o
```

Pull requests are usually reviewed within a few days. If there are comments to address, apply your changes in a separate commit and push that to your branch. Post a comment in the pull request afterwards; GitHub doesn't send out notifications when you add commits.


Writing documentation
---------------------

Documentation improvements are very welcome. We try to keep a good documentation in the `/docs` folder. But, you know, we are developers, we can forget to document important stuff that look obvious to us. And documentation can always be improved.


Translations
------------

The Cozy <APP_NAME> is translated on a platform called [Transifex][tx]. [This tutorial][tx-start] can help you to learn how to make your first steps here. If you have any question, don't hesitate to ask us!


Community
---------

You can help us by making our community even more vibrant. For example, you can write a blog post, take some videos, answer the questions on [the forum][forum], organize new meetups, and speak about what you like in Cozy!



[issues]: https://github.com/<USERNAME_GH>/<SLUG_GH>/issues/new
[pr]: https://help.github.com/categories/collaborating-with-issues-and-pull-requests/
[forking]: http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html
[stdjs]: http://standardjs.com/
[commitmsg]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html
[localization]: https://github.com/<USERNAME_GH>/<SLUG_GH>/blob/master/README.md#localization
[hub]: https://hub.github.com/
[tx]: https://www.transifex.com/cozy/
[tx-start]: http://docs.transifex.com/getting-started/translators/
[forum]: https://forum.cozy.io/

+ 126
- 12
README.md View File

@@ -1,12 +1,4 @@
Les sources connecteurs COZY ne pouvant être hébergées que sur GITHUB, le dépôt
a été déplacé :

[https://github.com/konnectors/cozy-konnector-enercoop](https://github.com/konnectors/cozy-konnector-enercoop)




[Cozy][cozy] Enercoop Cozy Konnector
[Cozy][cozy] <YOUR SUPER NEW KONNECTOR NAME>
=======================================

What's Cozy?
@@ -18,7 +10,121 @@ What's Cozy?

What's this new konnector?
--------------------------
This konnector collects your Enercoop bills.

<YOUR DESCRIPTION HERE>

### Open a Pull-Request

If you want to work on this konnector and submit code modifications, feel free to open pull-requests! See the [contributing guide][contribute] for more information about how to properly open pull-requests.

### Cozy-konnector-libs

This connector uses [cozy-konnector-libs](https://github.com/cozy/cozy-konnector-libs). You can
find more documentation about it there.

### Test the connector without an accessible cozy-stack

If you just want to test this connector without any cozy available.

You first need an installed [nodejs] (LTS version is fine).

Just run :

```sh
npm install
npm run standalone
```

The requests to the cozy-stack will be stubbed using the [./fixture.json] file as source of data
and when cozy-client is asked to create or update data, the data will be output to the console.
The bills (or any file) will be saved in the . directory.

### Run the connector linked to a cozy-stack

If you do not want to have to install the konnector on a cozy v3 to test it, you can register the
konnector as an OAuth application with the following commands :

```sh
npm install
npm run dev
```

This command will register your konnector as an OAuth application to the cozy-stack. By default,
the cozy-stack is supposed to be located in http://cozy.tools:8080. If this is not your case, just
update the COZY_URL field in [./konnector-dev-config-json].

After that, your konnector is running but should not work since you did not specify any credentials to
the target service. You can do this also in [./konnector-dev-config.json] in the "fields"
attribute.

Now run `yarn dev` one more time, it should be ok.

The files are saved in the root directory of your cozy by default.

### How does the cozy-stack run the connector ?

The cozy-stack runs the connector in a nsjail container to be sure it does not affect the environment.

The connector is run by calling npm start with the following envrionment variables :

- COZY_CREDENTIALS needs to be the result of `cozy-stack instances token-cli <instance name> <scope>`
- COZY_URL is the full http or https url to your cozy
- COZY_FIELDS is something like :
```javascript
{
"data":{
"attributes":{
"arguments":{
"account":"cf31eaef5d899404a7e8c3737c1c2d1f",
"folder_to_save":"folderPathId",
"slug":"mykonnector"
}
}
}
}
```

The "account" field is the id of the record with doctype "io.cozy.accounts" which will be used as
parameters for your konnector.

### Build (without Travis)

To be able to run the connector, the cozy stack needs a connector which is built into only one
file, without needing to npm install it, this will be a lot faster to install.

There is a command in package.json to help you to do that : `npm run build`

This command uses [webpack] to bundle all the code needed by your connector into one file.

This will generate an index.js file in the build directory and add all files the connector will need.

You can deploy this build by using the specific script : `npm run deploy`

This command will commit and push your build in the branch `build` fo your project.

And your konnector can now be installed using the following url :

git://github.com/cozy/cozy-konnector-<yourkonnector>.git#build

### Build using Travis CI

This project contains a `.travis.yml` config file which allows you to build your connector
automatically using [Travis-CI][travis].

You can follow these steps to enable building using Travis:

* On your [travis-ci.org][travis] account, find your project name (should be the same than your Github repository) and enable Travis by using the related checkbox.
* Once enabled, go to this project on Travis by clicking on it and go to the "Settings" menu by using the "More options" menu at the top right.
* Enable these three options:
* "Build only if .travis.yml is present"
* "Build branch updates" (run Travis after each branch update)
* "Build pull request updates" (run Travis after each Pull Request update)
* Then, you have to generate a Github token in [your Github account settings](https://github.com/settings/tokens). Here is the [Github blog post about API token](https://github.com/blog/1509-personal-api-tokens). Don't forget to authorize the access to the repo scope like following: ![repo scope](https://cloud.githubusercontent.com/assets/10224453/26671128/aa735ec2-46b4-11e7-9cd0-25310100e05e.png)
* Then, add an environment variable (still in your Travis project settings) named `GITHUB_TOKEN` and use your previous generated Github token as value (We highly recommand you to __keep the checkbox "Display value in build log" to OFF value__ in order to keep your token value hidden in the Travis logs.)

Now Travis is ready to build your project, it should build it each time your push a commit in your repository or create a pull request.

> __Note:__ Travis will push your build to your `build` branch ONLY for commits made on your master branch (included PR merge commits). You can see the related Travis statement [here](https://github.com/cozy/cozy-konnector-template/blob/master/.travis.yml#L27).

### Add your new connector to [Cozy Collect](https://github.com/cozy/cozy-collect)

@@ -27,9 +133,17 @@ now, if you want to add your new connector to Cozy Collect, you can submit a mes
in the [collect section](https://forum.cozy.io/c/francais/collect-fr), and we will handle this for
you.

### Standard

We use [standard] to format the `index.js` file. You can run it with:

```sh
npm run lint
```

### Maintainer

The lead maintainers for this konnector is Choj
The lead maintainers for this konnector is <YOUR NAME>


### Get in touch
@@ -45,7 +159,7 @@ You can reach the Cozy Community by:
License
-------

Enercoop Cozy Konnector is developed by Choj and distributed under the [AGPL v3 license][agpl-3.0].
<YOUR KONNECTOR NAME> is developed by <your name> and distributed under the [AGPL v3 license][agpl-3.0].

[cozy]: https://cozy.io "Cozy Cloud"
[agpl-3.0]: https://www.gnu.org/licenses/agpl-3.0.html


+ 0
- 96
index.js View File

@@ -1,96 +0,0 @@
const moment = require('moment')
const {log, BaseKonnector, saveBills, requestFactory} = require('cozy-konnector-libs')

const baseUrl = 'https://espace-client.enercoop.fr'
const loginUrl = baseUrl + '/login'
const billUrl = baseUrl + '/mon-espace/factures/'
moment.locale('fr')

let rq = requestFactory({
cheerio: true,
json: false,
debug: false,
jar: true
})

module.exports = new BaseKonnector(function fetch (fields) {
return logIn(fields)
.then(parsePage)
.then(entries => saveBills(entries, fields.folderPath, {
timeout: Date.now() + 60 * 1000,
identifiers: ['Enercoop']
}))
})

// Procedure to login to Enercoop website.
function logIn (fields) {
const form = {
email: fields.login,
password: fields.password,
}

const options = {
url: loginUrl,
method: 'POST',
form: form,
resolveWithFullResponse: true,
followAllRedirects: true,
simple: false
}

return rq(options)
.then(res => {
const isNot200 = res.statusCode !== 200
if (isNot200) {
log('info', 'Authentification error')
throw new Error('LOGIN_FAILED')
}

const url = `${billUrl}`
return rq(url)
.catch(err => {
console.log(err, 'authentication error details')
throw new Error('LOGIN_FAILED')
})
})
}

// Parse the fetched DOM page to extract bill data.
function parsePage ($) {
const bills = []
$('.invoice-line').each(function () {
//one bill per line = a <li> with 'invoice-id' data-attr
let billId = $(this).data('invoice-id')

let amount = $(this).find('.amount').text()
amount = amount.replace('€','')
amount = amount.replace(',', '.').trim()
amount = parseFloat(amount)

//gets pdf download URL
let pdfUrl = $(this).find('a > i').data('url')
pdfUrl = baseUrl + pdfUrl

//<French month>-YYYY format (Décembre - 2017)
let billDate = $(this).find('.invoiceDate').text().trim()
let monthAndYear = billDate.split('-')
let billYear = monthAndYear[0].trim()
let billMonth = monthAndYear[1].trim()

billMonth = moment.months().indexOf(billMonth.toLowerCase()) + 1
billMonth = billMonth < 10 ? '0' + billMonth : billMonth
let date = moment(billYear + billMonth, 'YYYYMM')

let bill = {
amount,
date: date.toDate(),
vendor: 'Enercoop',
filename: `${date.format('YYYYMM')}_enercoop.pdf`,
fileurl: pdfUrl
}

bills.push(bill)
})

return bills
}

+ 101472
- 0
konnector.js
File diff suppressed because it is too large
View File


+ 21
- 14
manifest.konnector View File

@@ -1,25 +1,32 @@
{
"version": "1.0.0",
"name": "Enercoop Cozy konnector",
"name": "konnector name",
"type": "node",
"slug": "enercoop",
"description": "Collects your Enercoop bills",
"source": "https://gitlab.allella.io/dje/cozy-konnector-enercoop",
"slug": "konnectorslug",
"description": "description",
"source": "git://github.com/cozy/cozy-konnector-thename.git",
"locales": {
"fr": {
"permissions": {
"books": {
"description": "Utilisé pour sauvegarder les références de vos livres"
},
"files": {
"description": "Utilisé pour sauvegarder les couvertures de vos livres"
},
"accounts": {
"description": "Utilisé pour récupérer les informations de votre compte"
}
}
}
},
"permissions": {
"bank operations": {
"description": "Required to link bills to bank operations",
"type": "io.cozy.bank.operations"
},
"bills": {
"description": "Required to save bills documents",
"type": "io.cozy.bills"
"books": {
"description": "Required to save books' references",
"type": "io.cozy.books"
},
"files": {
"description": "Required to save the bills files",
"description": "Required to save the covers",
"type": "io.cozy.files"
},
"accounts": {
@@ -29,7 +36,7 @@
}
},
"developer": {
"name": "choj",
"url": "https://gitlab.allella.io/dje/cozy-konnector-enercoop"
"name": "cozy",
"url": "cozy.io"
}
}

+ 0
- 6586
package-lock.json
File diff suppressed because it is too large
View File


+ 6
- 6
package.json View File

@@ -1,13 +1,13 @@
{
"name": "cozy-konnector-enercoop",
"name": "cozy-konnector-template",
"version": "1.0.0",
"description": "Collects your Enercoop bills",
"description": "",
"repository": {
"type": "git",
"url": "git+https://gitlab.allella.io/dje/cozy-konnector-enercoop.git"
"url": "git+https://github.com/cozy/cozy-konnector-template.git"
},
"keywords": ["Enercoop", "bills"],
"author": "Choj",
"keywords": [],
"author": "",
"license": "AGPL-3.0",
"dependencies": {
"cozy-konnector-libs": "^3.0.0"
@@ -19,7 +19,7 @@
"build": "webpack",
"lint": "standard --fix konnector.js",
"deploy:travis": "git-directory-deploy --username <YOUR_GH_USERNAME> --email <YOUR_EMAIL> --directory build/ --repo=https://$GITHUB_TOKEN@github.com/<USERNAME_GH>/<SLUG_GH>.git",
"deploy": "git-directory-deploy --directory build/ --branch build --repo=https://gitlab.allella.io/dje/cozy-konnector-enercoop.git"
"deploy": "git-directory-deploy --directory build/ --branch build --repo=https://github.com/cozy/cozy-konnector-template.git"
},
"devDependencies": {
"copy-webpack-plugin": "^4.0.1",


+ 0
- 19
webpack.config.js View File

@@ -1,19 +0,0 @@
var path = require('path')
const CopyPlugin = require('copy-webpack-plugin')

module.exports = {
entry: './index.js',
target: 'node',
output: {
path: path.join(__dirname, 'build'),
filename: 'konnector.js'
},
plugins: [
new CopyPlugin([
{ from: 'manifest.konnector' },
{ from: 'package.json' },
{ from: 'README.md' },
{ from: 'LICENSE' }
])
]
}

+ 0
- 4499
yarn.lock
File diff suppressed because it is too large
View File


Loading…
Cancel
Save