How to use the cozy-doctypes.Document.registerClient function in cozy-doctypes

To help you get started, we’ve selected a few cozy-doctypes examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cozy / cozy.github.io / en / cozy-banks / src / targets / services / service.js View on Github external
export const runService = service => {
  assertEnvVar('COZY_URL')
  assertEnvVar('COZY_CREDENTIALS')

  const client = new CozyClient({
    uri: process.env.COZY_URL.trim(),
    schema,
    token: process.env.COZY_CREDENTIALS.trim()
  })
  Document.registerClient(client)

  return service({ client }).catch(e => {
    // eslint-disable-next-line no-console
    console.error(e)
    process.exit(1)
  })
}
github cozy / cozy.github.io / en / cozy-banks / scripts / visualizer / src / server / index.js View on Github external
/**
 * Visualizer to see links between transactions and bills.
 *
 * Launch with `cozy-run-dev visualizer/index.js`
 */
const Linker = require('ducks/billsMatching/Linker/Linker').default
const { cozyClient } = require('cozy-konnector-libs')
const { Document } = require('cozy-doctypes')
const { Bill } = require('models')
const path = require('path')

// TODO Find out why our models parent class and Document from cozy-doctypes are different
Document.registerClient(cozyClient)
Bill.registerClient(cozyClient)

class DryLinker extends Linker {
  commitChanges() {
    return Promise.resolve()
  }
}

const generate = async options => {
  const bills = await Bill.fetchAll()

  const linker = new DryLinker(cozyClient)
  const results = await linker.linkBillsToOperations(bills, undefined, options)
  return results
}
github cozy / cozy.github.io / en / cozy-banks / src / targets / services / onOperationOrBillCreate.js View on Github external
const main = async () => {
  attachProcessEventHandlers()
  const client = CozyClient.fromEnv(process.env)
  Document.registerClient(client)
  const options = await getOptions(cozyClient)
  log('info', 'Options:')
  log('info', JSON.stringify(options))
  await onOperationOrBillCreate(client, options)
}