Global

Methods

authenticate(user, password) → {boolean}

This function initiates a connection on the CIC website.
Parameters:
Name Type Description
user string
password string
Source:
Throws:
When the website is down or an HTTP error has occurred
Type
Error
Returns:
Returns true if authentication is successful, else false
Type
boolean

(async) downloadExcelWithBankInformation() → {xlsx.WorkBook}

Downloads an Excel file containing all bank accounts and recent transactions on each bank accounts.
Source:
Returns:
Workbook downloaded from CIC website. It contains all bank accounts and recent transactions on each bank account.
Type
xlsx.WorkBook

fetchBalances(accounts) → {array}

Retrieves the balance histories of each bank accounts and adds the balance of the day for each bank account.
Parameters:
Name Type Description
accounts array Collection of io.cozy.bank.accounts already registered in database
Source:
Returns:
Collection of io.cozy.bank.balancehistories registered in database
Type
array
Example
var accounts = [
   {
     _id: '12345...',
     _rev: '14-98765...',
     _type: 'io.cozy.bank.accounts',
     balance: 42,
     cozyMetadata: { updatedAt: '2019-04-17T10:07:30.769Z' },
     institutionLabel: 'CIC',
     label: 'LIVRET',
     number: 'XXXXXXXX',
     rawNumber: 'XXXXXXXX',
     type: 'Savings',
     vendorId: 'XXXXXXXX'
   }
];


fetchBalances(accounts);

// [
//   {
//     _id: '12345...',
//     _rev: '9-98765...',
//     balances: { '2019-04-16': 42, '2019-04-17': 42 },
//     metadata: { version: 1 },
//     relationships: { account: [Object] },
//     year: 2019
//   }
// ]

findMetadataForCreditOperation(words) → {object}

Searches in the classification.json file, the metadata corresponding to words passed in parameters. This function ignores the metadata dedicated to debit operations.
Parameters:
Name Type Description
words array
Source:
Returns:
Type
object

findMetadataForDebitOperation(words) → {object}

Searches in the classification.json file, the metadata corresponding to words passed in parameters. This function ignores the metadata dedicated to credit operations.
Parameters:
Name Type Description
words array
Source:
Returns:
Type
object

(async) getBalanceHistory(year, accountId) → {io.cozy.bank.balancehistories}

Retrieves the balance history for one year and an account. If no balance history is found, this function returns an empty document based on io.cozy.bank.balancehistories doctype.

Note: Can't use BalanceHistory.getByYearAndAccount() directly for the moment, because BalanceHistory invokes Document that doesn't have an cozyClient instance.
Parameters:
Name Type Description
year integer
accountId string
Source:
Returns:
The balance history for one year and an account.
Type
io.cozy.bank.balancehistories

normalizeAmount(amount) → {Number}

Convert an amount to float
Parameters:
Name Type Description
amount string
Source:
Returns:
Type
Number

parseBankAccounts(bankAccountLines) → {array}

Parses and transforms each lines (CSV format) into io.cozy.bank.accounts
Parameters:
Name Type Description
bankAccountLines array Lines containing the bank account information - CSV format expected
Source:
Returns:
Collection of io.cozy.bank.accounts
Type
array
Example
var csv = [
  '...',';;;','Compte;R.I.B.;Solde;Dev', // ignored
  // Bank accounts
  'LIVRET;XXXXXXXX;42;EUR'
];

parseBankAccounts(csv);

// [
//   {
//     institutionLabel: 'CIC',
//     label: 'LIVRET',
//     type: 'Savings',
//     balance: 42,
//     number: 'XXXXXXXX',
//     vendorId: 'XXXXXXXX',
//     rawNumber: 'XXXXXXXX',
//     currency: 'EUR'
//   }
// ]

parseDate(date) → {moment.Moment}

Convert string to moment.Moment
Parameters:
Name Type Description
date string
Source:
Returns:
Type
moment.Moment

parseLabelBankAccount(label) → {string}

Analyzes the label of the bank account to find its type
Parameters:
Name Type Description
label string The label of the bank account
Source:
See:
Returns:
The type of the bank account
Type
string

parseOperations(account, operationLines) → {array}

Parses and transforms each lines (CSV format) into io.cozy.bank.operations
Parameters:
Name Type Description
account io.cozy.bank.accounts Bank account
operationLines array Lines containing operation information for the current bank account - CSV format expected
Source:
Returns:
Collection of io.cozy.bank.operations.
Type
array
Example
var account = {
   institutionLabel: 'CIC',
   label: 'LIVRET',
   type: 'Savings',
   balance: 42,
   number: 'XXXXXXXX',
   vendorId: 'XXXXXXXX',
   rawNumber: 'XXXXXXXX',
   currency: 'EUR'
};

var csv = [
   '...', '...','...','...','Date;Valeur;Libellé;Débit;Crédit;Solde', // ignored
   // Transaction(s)
   '12/31/18;1/1/19;INTERETS 2018;;38.67 €;',
   // End transaction(s)
   '...','...','...','' // ignored
];

parseOperations(account, csv);
// [
//   {
//     label: 'INTERETS 2018',
//     type: 'direct debit',
//     cozyCategoryId: '200130',
//     cozyCategoryProba: 1,
//     date: "2018-12-30T23:00:00+01:00",
//     dateOperation: "2018-12-31T23:00:00+01:00",
//     dateImport: "2019-04-17T10:07:30.553Z",       (UTC)
//     currency: 'EUR',
//     vendorAccountId: 'XXXXXXXX',
//     amount: 38.67,
//     vendorId: 'XXXXXXXX_2018-12-30_0'             {number}_{date}_{index}
//   }

saveBalances(balances) → {Promise}

Saves the balance histories in database.
Parameters:
Name Type Description
balances Collection of io.cozy.bank.balancehistories to save in database
Source:
Returns:
Type
Promise

(async) start(fields)

The start function is run by the BaseKonnector instance only when it got all the account information (fields). When you run this connector yourself in "standalone" mode or "dev" mode, the account information come from ./konnector-dev-config.json file
Parameters:
Name Type Description
fields object
Source: