How to use the cozy-client function in cozy-client

To help you get started, we’ve selected a few cozy-client 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 / create-cozy-app / packages / cozy-scripts / template / app / src / targets / browser / index.jsx View on Github external
const appNamePrefix = getDataOrDefault(
    data.cozyAppNamePrefix || require('../../../manifest.webapp').name_prefix,
    ''
  )

  const appName = getDataOrDefault(
    data.cozyAppName,
    require('../../../manifest.webapp').name
  )

  appLocale = getDataOrDefault(data.cozyLocale, 'en')

  const protocol = window.location ? window.location.protocol : 'https:'

  // initialize the client to interact with the cozy stack
  const client = new CozyClient({
    uri: `${protocol}//${data.cozyDomain}`,
    token: data.cozyToken,
    schema
  })

  // initialize the bar, common of all applications, it allows
  // platform features like apps navigation without doing anything
  cozy.bar.init({
    appName: appName,
    appNamePrefix: appNamePrefix,
    iconPath: appIcon,
    lang: appLocale,
    replaceTitleOnMobile: true
  })

  renderApp(client)
github cozy / cozy.github.io / en / cozy-banks / src / ducks / client / mobile / mobile.js View on Github external
'https://downcloud.cozycloud.cc/upload/cozy-banks/email-assets/logo-bank.png',
      notificationPlatform: 'firebase'
    },
    links: getLinks({
      pouchLink: {
        // TODO: the revocation check via cozy-pouch-link should not be
        // done in the app. We should find a way to have this in a shared
        // repository, possibly in cozy-client or cozy-pouch-link
        onSyncError: async () => {
          checkForRevocation(client)
        }
      }
    })
  }

  client = new CozyClient(merge(manifestOptions, banksOptions))
  registerPluginsAndHandlers(client)
  return client
}
github cozy / cozy-bar / examples / index.jsx View on Github external
)
})

const appInfo = {
  name: 'Example bar',
  slug: 'example-bar',
  softwareID: 'io.cozy.example',
  redirectURI: 'http://localhost:1234/auth',
  protocol: 'cozyexample://',
  universalLinkDomain: 'https://links.cozyexample.com'
}

const client = new CozyClient({
  scope: ['io.cozy.apps', 'io.cozy.konnectors'],
  // TODO client: All the oauth information could come from the manifest
  oauth: {
    clientName: appInfo.name,
    softwareID: appInfo.softwareID,
    redirectURI: appInfo.redirectURI
  }
})

// TODO bar: should only need a correctly configured client
client.on('login', () => {
  const oldOptions = {
    token: client.stackClient.token.accessToken,
    cozyURL: client.stackClient.uri
  }
  const newOptions = {
github cozy / cozy-bar / test / lib / stack-client / stack-client.intents.spec.js View on Github external
describe('intents', () => {
    const stackClient = {
      token: { token: 'mytoken' },
      uri: 'https://test.mycozy.cloud'
    }

    const cozyClient = new CozyClient({
      stackClient
    })

    const params = {
      cozyClient,
      onCreateApp: function() {},
      onDeleteApp: function() {}
    }

    beforeAll(async () => {
      await stack.init(params)
    })

    it('should return correctly the Intents instance', () => {
      const intents = stack.get.intents()
      expect(intents).toBeInstanceOf(Intents)
github cozy / cozy.github.io / en / cozy-flags / src / tests.js View on Github external
const setup = () => {
      const client = new CozyClient({})
      client.query = jest.fn(() => flagRemoteResponse)
      return { client }
    }
github cozy / cozy.github.io / en / cozy-banks / src / actions / accounts.spec.js View on Github external
import { removeStats } from './accounts'
import CozyClient from 'cozy-client'

const client = new CozyClient({})

describe('removeStats', () => {
  beforeEach(() => {
    client.query = jest.fn()
    client.destroy = jest.fn()
  })

  afterEach(() => {
    jest.resetAllMocks()
  })

  it('should remove the stats doc corresponding to the account if it exists', async () => {
    const account = { _id: 'account' }
    const stats = { _id: 'stats' }
    client.query.mockResolvedValueOnce({ data: [stats] })
github cozy / cozy-ui / react / ContactsListModal / DemoProvider.jsx View on Github external
import React from 'react'
import PropTypes from 'prop-types'
import contacts from '../ContactsList/data.json'
import CozyClient from 'cozy-client'

const mockClient = new CozyClient({
  uri: 'http://cozy.tools:8080',
  token: 'faketoken'
})

mockClient.__proto__.requestQuery = ({ doctype }) => {
  if (doctype === 'io.cozy.contacts') {
    return Promise.resolve({
      fetchStatus: 'loaded',
      data: contacts
    })
  }

  if (doctype === 'io.cozy.apps') {
    return Promise.resolve({
      fetchStatus: 'loaded',
      data: [
github cozy / cozy.github.io / en / cozy-banks / src / ducks / pin / PinGuard.spec.jsx View on Github external
const setup = ({ pinSetting }) => {
    const client = new CozyClient({})
    client.query = jest.fn()
    const root = mount(
      
        
          
        
      
    )
    return { root }
  }