1.0.5 • Published 10 months ago
@emarketflows/javascript-sdk v1.0.5
eMarket Flows - JavaScript SDK
- Official website: emarketflows.io
- Developers Space: resources
- GitHub: eMarket Flows - JavaScript SDK
- Node Package: @emarketflows/javascript-sdk
- License: MIT
Table of Contents
Why use this SDK?
This package permits use official eMarketFlows API services in easy steps.
Install
- Run this command in your project folder:
npm i @emarketflows/javascript-sdk
- To use this SDK you need an account, you can create one here.
- Access your account here and create new client credentials.
Authentication
Authenticate client session with your client identifier and Secret:
/* Import eMarketFlows SDK client */
const client = require('@emarketflows/javascript-sdk');
/**
* Initialize the eMarketFlows API client
* Is not necessary export it. This SDK set token in cache
* and get this when is neccesary and refresh.
**/
const emfClient = new client({
AUTH2_CLIENT_ID: YOUR_CLIENT_ID,
AUTH2_CLIENT_SECRET: YOUR_CLIENT_SECRET,
AUTH2_CLIENT_SCOPES: YOUR_CLIENT_SCOPES
});
/**
* Authenticate the client
*
* After install module and autheticate client with your credential,
* this package create cache space where sets your temporal client token
* and refresh it when is necessary.
* */
emfClient.authenticate();
Consume resources
One of principal uses of eMarketFlows SDK is be a developer interface to code fastly integrations.
/* Import eMarketFlows SDK client */
const { v1: EmfClient } = require('@emarketflows/javascript-sdk');
/* Example 1. Access to push notifications service and list last five notifications. */
const notifications = await EmfClient.notifications.push.list({limit: 5});
/* Example 2. Access to customers service and list last ten customers. */
const customers = await EmfClient.contacts.customers.list({limit: 10});
CRUD Methods reference
After install and authenticate your eMarket Flows client:
GET
/* Import eMarketFlows SDK client */
const { v1: EmfClient } = require('@emarketflows/javascript-sdk');
/* Get customer by customer unique identifier */
const customer = await EmfClient.contacts.customers.get(CUSTOMER_ID);
LIST
/* Import eMarketFlows SDK client */
const { v1: EmfClient } = require('@emarketflows/javascript-sdk');
/* List customers with limit */
const customers = await EmfClient.contacts.customers.list({limit: 5});
ADD
/* Import eMarketFlows SDK client */
const { v1: EmfClient } = require('@emarketflows/javascript-sdk');
/* Add customer */
const customer = await EmfClient.contacts.customers.add({
firstName: "John",
lastName: "Doe",
email: "johndoe@email.com"
});
UPDATE
/* Import eMarketFlows SDK client */
const { v1: EmfClient } = require('@emarketflows/javascript-sdk');
/* Update customer */
const customer = await EmfClient.contacts.customers.update({
id: "CUSTOMER_ID",
firstName: "Joana",
lastName: "Doe",
email: "joanadoe@email.com"
});
REMOVE
/* Import eMarketFlows SDK client */
const { v1: EmfClient } = require('@emarketflows/javascript-sdk');
/* Remove customer */
const customer = await EmfClient.contacts.customers.remove(CUSTOMER_ID);
Resources reference
Service | Resource | DESCRIPTION | LIST | GET | POST | PUT | DELETE |
---|---|---|---|---|---|---|---|
notifications | push | Push notifications | ✅ | ✅ | ✅ | ✅ | ✅ |
E-mail notifications | ✅ | ✅ | ✅ | ✅ | ✅ | ||
oauth2 | organizations | Organizations | ✅ | ✅ | ✅ | ✅ | ❌ |
clients | Account Auth2.0 clients | ✅ | ✅ | ✅ | ✅ | ✅ | |
members | Organization members | ✅ | ✅ | ✅ | ✅ | ✅ | |
billing | products | Orgnization products | ✅ | ✅ | ✅ | ✅ | ✅ |
catalogues | Product catalogues | ✅ | ✅ | ✅ | ✅ | ✅ | |
orders | Organization orders | ✅ | ✅ | ✅ | ✅ | ✅ | |
payments | Order payments | ✅ | ✅ | ✅ | ✅ | ✅ | |
invoices | Invoices | ✅ | ✅ | ✅ | ✅ | ✅ | |
serials | Invoice serials | ✅ | ✅ | ✅ | ✅ | ✅ | |
paymentMethods | Invoice payment methods | ✅ | ✅ | ✅ | ✅ | ✅ | |
contacts | customers | Organization customers | ✅ | ✅ | ✅ | ✅ | ✅ |
groups | Customer groups | ✅ | ✅ | ✅ | ✅ | ✅ | |
providers | Organization providers | ✅ | ✅ | ✅ | ✅ | ✅ | |
addresses | Contact addresses | ✅ | ✅ | ✅ | ✅ | ✅ | |
activities | Contact activities | ✅ | ✅ | ✅ | ✅ | ✅ | |
ubications | stores | Organization stores | ✅ | ✅ | ✅ | ✅ | ✅ |
warehouses | Organization warehouses | ✅ | ✅ | ✅ | ✅ | ✅ | |
corners | Organization corners | ✅ | ✅ | ✅ | ✅ | ✅ | |
ecommerce | stores | Organization online stores | ✅ | ✅ | ✅ | ✅ | ✅ |
Authorization Check client scopes
Check client permissions importing validate function:
/* Import validation service */
const { validate } = require('@emarketflows/javascript-sdk');
/* Check client scopes with Auth2.0 authorization service */
const isValid = await validate('super:contacts', 'list:providers');
console.log(`Client has super:contacts and list:providers scopes? ${isValid}`);
/**
* Output if client has scopes:
* Client has super:contacts and list:providers scopes? true
*
* Output if client hasn't scopes:
* Client has super:contacts and list:providers scopes? false
*/
Copyright 2024 @ eMarket Flows. All rights reserved.