# vtex-masterdata

> Helpers to manipulate data from Vtex Masterdata

Latest version **0.4.1** (published 2019-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install vtex-masterdata
pnpm add vtex-masterdata
yarn add vtex-masterdata
bun add vtex-masterdata
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.1 |
| Published | 2019-11-24 |
| First published | 2017-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 14 |
| Unpacked size | 123.8 KB |
| Known vulnerabilities | 0 (+2 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 13 |
| Author | Zeindelf |
| Maintainers | zeindelf |
| Keywords | vtex, utils, utilities, helpers, data, masterdata, vtex-masterdata, vtex-masterdata.js, vtex-utils, javascript, js-helpers, js-utilities, js-utils, front-end, web, component, development |

## Links

- npm: https://www.npmjs.com/package/vtex-masterdata
- Repository: https://github.com/zeindelf/vtex-masterdata
- Issues: https://github.com/zeindelf/vtex-masterdata/issues
- npm.io page: https://npm.io/package/vtex-masterdata

## Dependencies (14)

- [babel](https://npm.io/package/babel.md) ^6.23.0
- [eslint](https://npm.io/package/eslint.md) ^4.13.1
- [rollup](https://npm.io/package/rollup.md) ^0.53.0
- [del-cli](https://npm.io/package/del-cli.md) ^1.1.0
- [uglify-js](https://npm.io/package/uglify-js.md) ^3.2.2
- [babel-core](https://npm.io/package/babel-core.md) ^6.26.0
- [npm-run-all](https://npm.io/package/npm-run-all.md) ^4.1.2
- [babel-eslint](https://npm.io/package/babel-eslint.md) ^8.1.2
- [rollup-watch](https://npm.io/package/rollup-watch.md) ^4.3.1
- [babel-preset-env](https://npm.io/package/babel-preset-env.md) ^1.6.1
- [rollup-plugin-babel](https://npm.io/package/rollup-plugin-babel.md) ^3.0.3
- [eslint-config-google](https://npm.io/package/eslint-config-google.md) ^0.9.1
- [eslint-plugin-import](https://npm.io/package/eslint-plugin-import.md) ^2.8.0
- [babel-plugin-external-helpers](https://npm.io/package/babel-plugin-external-helpers.md) ^6.22.0

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.4.1 (latest) — 2019-11-24
- 1.0.0-beta.3 (beta) — 2019-11-24
- 1.0.0-beta.2 — 2019-11-24
- 1.0.0-beta.1 — 2019-11-24
- 1.0.0-beta.0 — 2019-11-24
- 0.4.0 — 2019-07-29
- 0.3.4 — 2018-12-17
- 0.3.3 — 2018-08-20
- 0.3.2 — 2018-08-20
- 0.3.1 — 2018-08-19
- 0.3.0 — 2018-01-22
- 0.2.2 — 2018-01-08
- 0.2.1 — 2018-01-07
- 0.2.0 — 2018-01-07
- 0.1.0 — 2018-01-01
- … 3 more at https://npm.io/package/vtex-masterdata/versions

## README

# VtexMasterdata.js

Helpers to manipulate data from Vtex Masterdata

## Table of contents

- [Main](#main)
- [Getting started](#getting-started)
- [Methods](#methods)
- [License](#license)
- [Dependencies](#dependencies)
- [Todo](#todo)

## Main

```text
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](https://github.com/Zeindelf/vtex-masterdata/blob/master/dist/vtex-masterdata.min.js) and include it.

You will need [VtexUtils.js](https://github.com/zeindelf/vtex-utils)

```html
<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](https://www.npmjs.com/package/vtex-masterdata) under the name `vtex-masterdata`.

```shell
npm install vtex-masterdata --save
```

### Module Loaders

VtexMasterdata.js can also be loaded as an CommonJS or ES6 module (recomended).

```js
// 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.

```js
// 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

```js
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)

```js
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)

```js
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**

```js
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)

```js
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

```js
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

```js
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](https://opensource.org/licenses/MIT).

## Dependencies

jQuery 1.8.3+

VtexUtils.js

## Todo

- Docs

---
_Source: https://npm.io/package/vtex-masterdata · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
