![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
vtex-commons
Advanced tools
Handy VTEX library for NodeJs
This module wrapps the most common used VTEX APIs requests. Currently containing:
Load Orderform by Id
npm i vtex-commons
Here's a example of how to use the Master Data's Search
const VTEX = require('vtex-commons')
mondule.exports = async () => {
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.MasterData().Search({
entity : 'CL',
rule : 'email=imagooddeveloper@maybe.com',
fields : '_all'
})
}
You might be wondering: "Where are the key and token required to perform a private request? I can't see them in the code!"
You're right, they aren't in the code. And if you keep your credentials within your code, you're going to Developers Hell.
When you instanciate the module, it assumes you have at least two enviroment variables already set:
Therefore, there's no need to write them down in your code. If you need to use anothers name for this variables other then the provided, you'll be able to overwrite the default ones. More on that in a minute.
This method requires an object with four parameters:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.MasterData().Search({
entity : 'CL',
rule : 'email=imagooddeveloper@maybe.com',
fields : '_all'
})
This method requires an object with two required parameters:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.MasterData().Post({
entity : 'CL',
data : {name : 'Jane'}
})
This method requires an object with two parameters:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.MasterData().Delete({
entity : 'CL',
id : '54353fsdf-42342rfsfsfs-23rfdsfsdfds'
})
This method requires an object with three parameters:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.MasterData().Patch({
entity : 'CL',
data : {name : 'Jane'}
id : '54353fsdf-42342rfsfsfs-23rfdsfsdfds'
})
This method requires an object with one parameter:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.OMS().LoadOrder({
orderId : '54353fsdf-01'
})
This method requires an object with one parameter:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.OMS().ListOrders({
filter : 'orderBy=creationDate,desc&page=1&q=jemail=imagooddeveloper@maybe.com&f_creationDate=creationDate:%5B2021-11-17T03:00:00.000Z%20TO%202021-11-18T02:59:59.999Z%5D'
})
This method requires an object with one parameter:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.OMS().CancelOrder({
orderId : '54353fsdf-01'
})
This method requires an object with one parameter:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.Catalog().GetSKU({
skuId : 818
})
This method requires an object with one parameter:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.Catalog().GetProduct({
productId : 213
})
This method requires an object with one parameter:
vtex = new VTEX({
store : 'dummystore'
})
const searchResult = await vtex.Catalog().GetProductByRefId({
refId : 213
})
This method requires an object with one parameter:
vtex = new VTEX({
store : 'dummystore'
})
const orderForm = await vtex.Checkout().LoadOrderformById({
orderformId : 'hgcfgtr456yhef'
})
These are the default values when you instanciate the module:
{
appKey : "APP_KEY",
appToken : "APP_TOKEN",
store : null, /*required*/
env : "vtexcommercestable.com.br"
}
You can easily overwrite them:
vtex = new VTEX({
store : 'dummystore',
appKey : 'STORE_KEY',
appToken : 'STORE_TOKEN',
})
REMEMBER: appKey AND appToken SHOULD NOT BE FILLED WITH YOUR CREDENTIALS, BUT WITH THE NAMES OF THE ENVIROMENT VARIABLES THAT CONTAIN THEM.
If you really need to provide the credentials directly to the contructor, say from a query result, you can do this using the following snippet:
vtex = new VTEX({
store : 'dummystore',
appKey : 'vtexappkey-dummiestore-ABCDEF', //the real key
appToken : 'REWREWRW5435435REWREW432RWFSGFDYTR543TGEGFDFDSREWr34TREGFDGDGDWSADWEFDSDFDSAFSADEFGEFD', //the real token
credentials: true
})
Aways wrapp the request inside a try catch. The module will throw an error that will break the execution if something goes wrong with the request.
Fell free to improve this module. Pull requests will be welcome. Just try to keep the existing structure.
FAQs
Handy VTEX library for NodeJs
We found that vtex-commons demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.