Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@totvs/mingle

Package Overview
Dependencies
Maintainers
26
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@totvs/mingle

Mingle core - client of Mingle

  • 0.0.1-dev.20190517.4
  • npm
  • Socket score

Version published
Weekly downloads
47
increased by62.07%
Maintainers
26
Weekly downloads
 
Created
Source

@TOTVS/MINGLE

What's this?

A typescript library to facilitate the communication of applications written in Javascript with the server Mingle.

How to use?

To start using Mingle, the first thing to do is to install the necessary package for its operation. Run the following command in the folder of your project:

Installation

Using npm: $ npm install --save @totvs/mingle

Mingle with Ionic Application

To use Mingle in an Ionic application you must run the following commands to install the plugins used:

  • Mingle Ionic Device $ npm install --save @totvs/mingle-ionic-device

  • Geolocation $ npm install --save @totvs/geolocation

  • OCR ionic cordova plugin add cordova-plugin-file-transfer $ npm install --save @totvs/ocr

Configuration

In the application's app.component.ts file, import the classes and create a instance:

// using ES6 modules
import { MingleService } from @totvs/mingle;
private mingleService = new MingleService();

// using CommonJS modules
var mingle = require('@totvs/mingle')
var mingleService = new mingle.MingleService();

For a web application:

config.modules.web = true;

For a mobile application:

config.modules.web = false;

Create an instance of the MingleService and configure:

const config = new Configuration();
config.app_identifier = '5c59cb6f29e97849802083fb';
config.environment = 'DEV';
config.server = 'https://dev-mingle.totvs.com.br/api';
config.modules.crashr = true;
config.modules.usage_metrics = true;
config.modules.gateway = true;
config.modules.push_notification = true;
config.modules.ocr = true;
config.modules.web = false;

this.mingleService.setConfiguration(config);

If you want to use aditional plugins:

Geolocation

this.mingleService.use(GeolocationPlugin);

Device Ionic Plugin

this.mingleService.use(DevicePlugin);

OCR

After this, create a instance:

const ocr = new OcrPlugin(this.mingleService);
ocr.readBusinessCard({}, this.mingleService);

Now everything is ready, lets use in application.

The first thing to do is to initialize Mingle, and verify that the user is already authenticated:


this.mingleService.auth.login('admin', 'admin', 'alias sufix').subscribe(() => {
this.mingleService.registerMetric('APP_INIT');
console.log('Sign in ok');

}, (authError) => {

console.log('Authentication Error: User or password invalid!');

});

Gateway

it is the responsibility of the developer to inform the headers required for the gateway service. The mingle provides a method to obtain the parameters registered in SET.

  • Sample tenantid - Protheus value default in set:
const paramsSet = this.mingleService.getParams();

const company = paramsSet.filter(e => e.key === 'EMPRESA').map(e => e.value);
const branch = paramsSet.filter(e => e.key === 'FILIAL').map(e => e.value);
const options = {headers: {tenantid: `${company + ',' + branch}`}};

.get(url, options, params).subscribe(response =>{
...
});

Http Interceptor

Mingle also provides a class called MingleHttpInterceptor that functions as a request interceptor.

The purpose of this interceptor is that any http call made by the app using only the / api / customers feature will automatically be added in the request to the mingle url, and the Authorization (token), Content-Type and tenantId headers.

Angular sample

To use the MingleHttpInterceptor, just set in the app.module.ts:

import { MingleHttpInterceptor } from '@totvs/mingle';
import { HTTP_INTERCEPTORS } from '@angular/common/http';

Add in providers section:

@NgModule({
declarations: [
AppComponent,
DashboardComponent,
HomeComponent
],
imports: [
BrowserModule,
HttpClientModule,
RouterModule.forRoot(routes)
],
providers: [MingleService,
{
provide: HTTP_INTERCEPTORS,
useClass: MingleHttpInterceptor,
multi: true,
}],
bootstrap: [AppComponent]
})
export class AppModule { }

RXJS

We always work with the stable version of rxjs package.

Your application can be in any version of rxjs, because we package it in a way that Mingle uses its own version, ignoring that of the application.

We provide an object to type methods in the version of RXJS that Mingle uses:


import { MingleObservable } from '@totvs/mingle';

myMethod(): MingleObservable<any> {
	return this.mingleService.gateway.get('endpoint');
}

FAQs

Package last updated on 17 May 2019

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc