vtex-masterdata
Helpers to manipulate data from Vtex Masterdata
Last updated 3 months ago by zeindelf .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install vtex-masterdata 
SYNC missed versions from official npm registry.

VtexMasterdata.js

Helpers to manipulate data from Vtex Masterdata

Table of contents

Main

dist/
├── vtex-masterdata.js        (UMD)
├── vtex-masterdata.min.js    (UMD, compressed)
├── vtex-masterdata.common.js (CommonJS, default)
└── vtex-masterdata.esm.js    (ES Module)

Getting started

Direct download

Download the script here and include it.

You will need VtexUtils.js

<script type="text/javascript" src="/arquivos/vtex-utils.min.js"></script>
<script type="text/javascript" src="/arquivos/vtex-masterdata.min.js"></script>

Package Managers

VtexMasterdata.js supports npm under the name vtex-masterdata.

npm install vtex-masterdata --save

Module Loaders

VtexMasterdata.js can also be loaded as an CommonJS or ES6 module (recomended).

// CommomJS
var VtexMasterdata = require('vtex-masterdata');

// ES6 module
import VtexMasterdata from 'vtex-masterdata';

Usage

With UMD (Universal Module Definition), the package is available on VTEX namespace.

// First, initialize VtexUtils.js
var vtexUtils = new VTEX.VtexUtils();

// Initialize constructor passing VtexUtils.js as a param
var vtexMasterdata = new VTEX.VtexMasterdata(vtexUtils);

// Set store name (https://store-name.vtexcommercestable.com.br)
vtexMasterdata.setStore('store-name');

Methods

vtexMasterdata.newsletter(email[, newsletter[, entity]])

Newsletter opt-in / opt-out

  • email:

    • Type: String
    • The email of the user to opt-in/out
  • newsletter (optional):

    • Type: Boolean
    • Default: true
    • Whether to opt-in/out
  • entity (optional):

    • Type: String
    • Default: 'CL'
    • The Entity of the user

Example

Remove user from newsletter

vtexMasterdata.newsletter('email@email.com', false)
    .done(function(res) {
        if ( res.result.dataInsert.isNewsletterOptIn ) {
            window.console.log('Subscribed');
        } else {
            window.console.log('Not subscribed');
        }
    })
    .fail(function(err) {
        window.console.log(err);
    });

vtexMasterdata.getUser(email, fields[, entity])

Get User by mail

  • email:

    • Type: String
    • The email of the user
  • fields

    • Type: Array
    • A list of fields to retrieve
  • entity (optional):

    • Type: String
    • Default: 'CL'
    • The Entity of the user

Example

Get email, firstName and lastName by user e-mail (needs read properties set to public on Masterdata)

vtexMasterdata.getUser('email@email.com', ['email', 'firstName', 'lastName'])
    .done(function(res) {
        // Response with an object that contains id, email, firstName and lastName of user
        window.console.log(res.result.dataResponse);
    })
    .fail(function(err) {
        window.console.log(err);
    });

vtexMasterdata.updateUser(email, data[, entity])

Update User by email

  • email:

    • Type: String
    • The email of the user
  • data:

    • Type: Object
    • The data that will be updated.
  • entity (optional):

    • Type: String
    • Default: 'CL'
    • The Entity of the user

Example

Update user newsletter opt in, firstName and lastName (needs update properties set to public on Masterdata)

vtexMasterData.updateUser('email@email.com', {isNewsletterOptIn: true, firstName: 'New firstname', lastName: 'new lastname'})
    .done(function(res) {
        if ( res.isUpdate() ) {
            window.console.log(res.result);
        }
    })
    .fail(function(err) {
        window.console.log(err);
    });

vtexMasterdata.insertUpdateUser(email[, data[, entity]])

Update a user if the email exists, or insert a new one if it doesn't

  • email:

    • Type: String
    • The email of the user
  • data (optional):

    • Type: Object
    • The data that will be updated.
  • entity (optional):

    • Type: String
    • Default: 'CL'
    • The Entity of the user

Example

Create new user by email

vtexMasterdata.insertUpdateUser('new-user@email.com')
    .then(function(res) {
        window.console.log(res);
    })
    .fail(function(err) {
        window.console.log(err);
    });

Update newsletter opt in user by email (needs update properties set to public on Masterdata)

vtexMasterdata.insertUpdateUser('new-user@email.com', {isNewsletterOptIn: true})
    .then(function(res) {
        window.console.log(res);
    })
    .fail(function(err) {
        window.console.log(err);
    });

vtexMasterdata.insert(data[, entity])

Insert a document

  • data:

    • Type: Object
    • The data that will be inserted
  • entity (optional):

    • Type: String
    • Default: 'CL'
    • The entity of the document to insert

vtexMasterdata.insertUpdate(id, data, entity)

vtexMasterdata.search(params, fields[, entity[, limit[, offset]]])

Performs a search

  • params

    • Type: Object
    • The search parameters
  • fields

    • Type: Array
    • A list of fields to retrieve
  • entity (optional):

    • Type: String
    • Default: 'CL'
    • The entity where the search will be performed
  • limit (optional):

    • Type: Integer
    • Default: '49'
    • The search limit
  • offset (optional):

    • Type: Integer
    • Default: '0'
    • The search offset

Example

Search only stores with state = SP

vtexMasterdata.search({state: 'SP'}, ['latitute', 'longitude'], 'SO')
    .done(function(res) {
        // Response with an object that contains only stores from 'SP' and latitude/latitude properties
        window.console.log(res.result.dataResponse);
    })
    .fail(function(err) {
        window.console.log(err)
    });

To search all results from entity, pass params as an empty object

vtexMasterdata.search({}, ['latitute', 'longitude'], 'SO')
    .done(function(res) {
        // Response all data from 'SO' entity
        window.console.log(res.result.dataResponse);
    })
    .fail(function(err) {
        window.console.log(err)
    });

vtexMasterdata.fullSearch(params, fields, [filters[, entity[, limit[, offset]]]])

vtexMasterdata.get(id, fields, entity)

vtexMasterdata.exists(id, entity)

vtexMasterdata.uploadFile(id, entity, field, file)

License

VtexMasterdata.js is open-sourced software licensed under the MIT license.

Dependencies

jQuery 1.8.3+

VtexUtils.js

Todo

  • Docs

Current Tags

  • 0.4.0                                ...           latest (3 months ago)

13 Versions

  • 0.4.0                                ...           3 months ago
  • 0.3.4                                ...           10 months ago
  • 0.3.3                                ...           a year ago
  • 0.3.2                                ...           a year ago
  • 0.3.1                                ...           a year ago
  • 0.3.0                                ...           2 years ago
  • 0.2.2                                ...           2 years ago
  • 0.2.1                                ...           2 years ago
  • 0.2.0                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
  • 0.0.3                                ...           2 years ago
  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 18
Last Day 0
Last Week 1
Last Month 3
Dependencies (14)
Dev Dependencies (0)
None
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |