1.2.2 • Published 6 years ago
@toxus/adrez-api-mock v1.2.2
adrez-api-mock
Mock for the API of AdreZ
Install
$ npm install @toxus/adrez-api-mock --saveUsage
const Adrez = require('@toxus/adrez-api-mock');
async function changeAdrez() {
  try {
      let connection  = await Adrez.Api.connection({
        customer: 'test',
        password: 'someVerySecretWord'
      })
      let addr = await connection.add({name: 'Test User', email: 'john@adrez.nl'});
      let id = addr.id;
      
      addr.name = 'Other name';
      await connection.update(addr.id, addr); // will update only the name field
      
      let usr = connection.get(id);
      
      await connection.remove(addr.id);
      
      await connection.close();
  } catch (err) {
     console.error(err)
  }
}options:
- mockDef: standard, add, update, remove the delay for the api
 
Address format
To update the AdreZ an object is used. There are a number of fields that can be added. A limited amount of fields are defined as repeating fields.
The basic, none repeating fields are:
- id
 - addressId
 - name
 - fullName
 - firstName
 - insertion
 - title
 - gender
 
The repeating fields are:
- telephone
 - code
 - description
 - contact
 - location (special)
 
Repeating fields are objects. The object has the fields
- type
 - value
 - _index (a special fields that indentifies this unique array element for updating)
 
The location field is different:
- street
 - number
 - zipcode
 - city
 - country
 - countryCode
 
example
let addr = {
  name: 'Toxus',
  firstName: 'Jaap',
  email: [
    { value: 'info@example.com', type: 'work', _index: '0'},
    { value: 'news@example.con', type: 'newsletter', _index: '1'}
  ],
  telephone: '06 01020304',
  location: {
    _index: '0',
    street: 'mainstreet',
    number: '1234',
    city: 'Amsterdam',
    countryCode: 'nl'
  }  
}Maintainers
License
MIT