1.0.5 • Published 10 months ago

@emarketflows/javascript-sdk v1.0.5

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

eMarket Flows - JavaScript SDK

Table of Contents

Why use this SDK?

This package permits use official eMarketFlows API services in easy steps.

Install

  1. Run this command in your project folder:
    npm i @emarketflows/javascript-sdk
  2. To use this SDK you need an account, you can create one here.
  3. 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

ServiceResourceDESCRIPTIONLISTGETPOSTPUTDELETE
notificationspushPush notifications
emailE-mail notifications
oauth2organizationsOrganizations
clientsAccount Auth2.0 clients
membersOrganization members
billingproductsOrgnization products
cataloguesProduct catalogues
ordersOrganization orders
paymentsOrder payments
invoicesInvoices
serialsInvoice serials
paymentMethodsInvoice payment methods
contactscustomersOrganization customers
groupsCustomer groups
providersOrganization providers
addressesContact addresses
activitiesContact activities
ubicationsstoresOrganization stores
warehousesOrganization warehouses
cornersOrganization corners
ecommercestoresOrganization 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.

1.0.5

10 months ago

1.0.4

10 months ago

1.0.3

10 months ago

1.0.2

10 months ago

1.0.1

10 months ago

1.0.0

10 months ago