Socket
Socket
Sign inDemoInstall

ubivar

Package Overview
Dependencies
Maintainers
1
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ubivar - npm Package Compare versions

Comparing version 0.1.3-beta9 to 0.1.4-beta

test/Resources/Accounts/spec.js

26

lib/index.js

@@ -5,14 +5,26 @@ /* Ubivar API client factory

*/
module.exports = function(token, version){
module.exports = function(token, version, resources){
var _ = require("lodash")
, Ubivar = require("./Ubivar")
, Resource = require("./Resource")
, ubivar = new Ubivar(token, version)
_.each(ubivar.get("resources"), function(resourceName){
ubivar[resourceName] = new Resource(ubivar, resourceName)
var Ubivar = require("./Ubivar")
resources = resources || [
"accounts"
, "transactions"
, "routing"
, "orders"
, "login"
, "logout"
, "items"
, "labels"
, "me"
]
var ubivar = new Ubivar(token, version, resources)
_.each(resources, function(resource){
ubivar.extend(resource)
})
ubivar.log.level("warn")
return ubivar
}

@@ -13,3 +13,2 @@ var _ = require("lodash")

this.ubivar = ubivar
this.log = ubivar.log
}

@@ -102,2 +101,18 @@

/*
* Summary a resource
* @parameters [Object] query parameters to retrieve resources
* @next [function] optional callback
*/
Resource.prototype.summary = function(){
var args = arguments
, parameters = !_.isFunction(args[0]) ? args[0] : {}
, next = _.isFunction(args[0]) ? args[0] : _.isFunction(args[1]) ? args[1] : function(){}
this.request.call(this, {"method": "GET"
, "data" : parameters
, "path" : this.path + "/summary"
}, function(err, res){ next(err, res) })
}
/*
* Generic mechanisms to handle:

@@ -104,0 +119,0 @@ * - a request,

var path = require("path")
, fs = require("fs")
, bunyan = require("bunyan")
, _ = require("lodash")
, RESOURCES = [
"accounts"
, "transactions"
, "orders"
, "login"
, "logout"
, "items"
, "labels"
, "fx"
, "me"
]
, Resource = require("../Resource")

@@ -22,3 +11,3 @@ /*

*/
function Ubivar(token, version){
function Ubivar(token, version, resources){
var http = require("http")

@@ -36,3 +25,3 @@ , pathPackage = "../../package.json"

, "timeout" : theTimeout
, "resources" : RESOURCES
, "resources" : resources
, "revokedCerts" : theRevokedCerts

@@ -51,3 +40,2 @@ , "headers" : {

this.set("auth", token)
this.log = bunyan.createLogger({ "name": theName})
}

@@ -74,4 +62,12 @@

/*
* Extend function to add resources to 'this' running instance
* @resource [String] name of the resource to add
*/
Ubivar.prototype.extend = function(resource){
this[resource] = new Resource(this, resource)
}
/*
* Export the wrapper factory of Ubivar
*/
module.exports = Ubivar
{
"name": "ubivar",
"version": "0.1.3-beta9",
"version": "0.1.4-beta",
"description": "API wrapper to Ubivar",

@@ -26,5 +26,4 @@ "main": "lib/index.js",

"dependencies": {
"bunyan": "^1.3.4",
"lodash": "^3.3.1"
}
}
# Ubivar node.js bindings
[![npm version](https://badge.fury.io/js/ubivar.svg)](http://badge.fury.io/js/ubivar) [![Build Status](https://travis-ci.org/ubivar/ubivar-node.png?branch=master)](https://travis-ci.org/ubivar/ubivar-node) [![Inline docs](http://inch-ci.org/github/ubivar/ubivar-node.svg?branch=master)](http://inch-ci.org/github/ubivar/ubivar-node)
[![npm version](https://badge.fury.io/js/ubivar.svg)](http://badge.fury.io/js/ubivar) [![Build Status](https://travis-ci.org/ubivar/ubivar-node.png?branch=master)](https://travis-ci.org/ubivar/ubivar-node) [![Inline docs](http://inch-ci.org/github/ubivar/ubivar-node.svg?branch=master)](http://inch-ci.org/github/ubivar/ubivar-node)
Ubivar is an API that takes over the hassle of automatically screening
e-payment for frauds on e-commerce websites.
Ubivar is an API that takes over the hassle of screening e-payment for
frauds.
Ubivar's purpose is to route e-commerce transactions given their estimated
risk. By default, the three possible routing outcomes are a suggested
rejection, a recommended manual verification, and a proposed acceptance of the
transaction. Ubivar does not need all the business events (aka `resources`),
however the more it has contextual information about the transactions, the
better its accuracy. The two required resources are the `transactions` and the
`labels` that categorize the `transactions` like fraud, not fraud. The API is
simple: you provide Ubivar your request `token` and the bindings provide the
hooks to send and receive resources to the API.
Ubivar routes e-commerce transactions given their risk. By default the three
`routing` outcomes are rejection, manual verification and acceptance. And the two
elementary resources are the `transactions` and the `labels`. `Transactions`
are online sales pushed to your payment gateway and `labels` define the *a
posteriori* truth about each `transaction`, i.e. {`fraud`, `non-fraud`}.
# Install
Using Ubivar simply requires an access `token`. Then the bindings provide the
hooks to send and receive resources to the API. For each `transaction` that
Ubivar receives, it calculates a `routing`. Later, as you review manually some of
the `transactions` or as you receive fraud notifications, you `label`
those `transactions` as `fraud`.
## Quick Start
Install the nodejs binding of `ubivar` from npm.
`npm install ubivar`
# Documentation
Initialize the binding with your API access token:
Documentation is available at [https://ubivar.com/docs/nodejs](https://ubivar.com/docs/nodejs)
```js
var Ubivar = require("ubivar")
, ubivar = new Ubivar("YOUR_API_ACCESS_TOKEN")
```
# API Overview
### A. Send transactions
```js
ubivar.transactions.create({
"user_id" : "test_phahr3Eit3_123" // your client's id
, "user_email" : "test_phahr3Eit3@gmail-123.com" // your client email
, "gender" : "M" // your client's gender
, "first_name" : "John" // your client's first name
, "last_name" : "Doe" // your client's last name
, "type" : "sale" // the transaction type
, "status" : "success" // the transaction status
, "order_id" : "test_iiquoozeiroogi_123" // the shopping cart id
, "tx_id" : "client_tx_id_123" // the transaction id
, "tx_timestamp": "2015-04-13 13:36:41" // the timestamp of this transaction
, "amount" : "43210" // the amount in cents
, "payment_method":{
"bin" : "123456" // the BIN of the card
, "brand" : "Mastercard" // the brand of the card
, "funding" : "credit" // the type of card
, "country" : "US" // the card country code
, "name" : "M John Doe" // the card holder's name
, "cvc_check" : "pass" // the cvc check result
},"billing_address":{
"line1" : "123 Market Street" // the billing address
, "line2" : "4th Floor"
, "city" : "San Francisco"
, "state" : "California"
, "zip" : "94102"
, "country" : "US"
},"ip_address" : "1.2.3.4" // your client ip address
, "user_agent" : "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36" // your client's user agent
}, function(err, res){
Every resource is accessed via your `ubivar` instance and accepts an optional
callback as the last argument. The sample code below retrieves your account
information (as json) and updates the primary phone with a random value.
if(err) return err
// something unexpected occurred
txId = res.data[0].id
// keep track of the transaction id
})
```
### B. Retrieve routing
```js
var Ubivar = require("ubivar")
, ubivar = new Ubivar("YOUR_API_ACCESS_TOKEN", "latest")
, rval = Math.random()
ubivar.routing.retrieve(txId, function(err, res){
ubivar.retrieve.me(function(err, res){
console.log(err, res)
if(err) return err
// something unexpected occurred
ubivar.update.me({"primary_phone":rval}, function(err, res){
console.log(err, res)
})
status = res.data[0].status
// the routing, e.g. {pending, green, orange, red}
})
```
# Available resources and methods
### C. Label as fraud
+ [Me](https://www.ubivar.com/docs/nodejs#me)
+ [retrieve()](https://www.ubivar.com/docs/nodejs#retrieve_your_information)
+ [update(params)](https://www.ubivar.com/docs/nodejs#update_your_information)
+ [Account](https://www.ubivar.com/docs/nodejs#accounts)
+ [create(params)](https://www.ubivar.com/docs/nodejs#create_an_account)
+ [retrieve(id)](https://www.ubivar.com/docs/nodejs#retrieve_an_account)
+ [update(id, params)](https://www.ubivar.com/docs/nodejs#update_an_account)
+ [del(id)](https://www.ubivar.com/docs/nodejs#delete_an_account)
+ [list()](https://www.ubivar.com/docs/nodejs#list_accounts)
+ [Transaction](https://www.ubivar.com/docs/nodejs#transactions)
+ [create(params)](https://www.ubivar.com/docs/nodejs#create_a_transaction)
+ [retrieve(id)](https://www.ubivar.com/docs/nodejs#retrieve_a_transaction)
+ [update(id, params)](https://www.ubivar.com/docs/nodejs#update_a_transaction)
+ [del(id)](https://www.ubivar.com/docs/nodejs#delete_a_transaction)
+ [list()](https://www.ubivar.com/docs/nodejs#list_transactions)
+ [Login](https://www.ubivar.com/docs/nodejs#login)
+ [create(params)](https://www.ubivar.com/docs/nodejs#create_login_event)
+ [retrieve(id)](https://www.ubivar.com/docs/nodejs#retrieve_login_event)
+ [del(id)](https://www.ubivar.com/docs/nodejs#delete_login_event)
+ [list()](https://www.ubivar.com/docs/nodejs#list_login_events)
+ [Logout](https://www.ubivar.com/docs/nodejs#logout)
+ [create(params)](https://www.ubivar.com/docs/nodejs#create_logout_event)
+ [retrieve(id)](https://www.ubivar.com/docs/nodejs#retrieve_logout_event)
+ [del(id)](https://www.ubivar.com/docs/nodejs#delete_logout_event)
+ [list()](https://www.ubivar.com/docs/nodejs#list_logout_events)
+ [Item](https://www.ubivar.com/docs/nodejs#items)
+ [create(params)](https://www.ubivar.com/docs/nodejs#create_item)
+ [retrieve(id)](https://www.ubivar.com/docs/nodejs#retrieve_item)
+ [update(id, params)](https://www.ubivar.com/docs/nodejs#update_item)
+ [del(id)](https://www.ubivar.com/docs/nodejs#delete_item)
+ [list()](https://www.ubivar.com/docs/nodejs#list_items)
+ [Label](https://www.ubivar.com/docs/nodejs#labels)
+ [create(params)](https://www.ubivar.com/docs/nodejs#create_label)
+ [retrieve(id)](https://www.ubivar.com/docs/nodejs#retrieve_label)
+ [update(id, params)](https://www.ubivar.com/docs/nodejs#update_label)
+ [del(id)](https://www.ubivar.com/docs/nodejs#delete_label)
+ [list()](https://www.ubivar.com/docs/nodejs#list_labels)
```js
ubivar.labels.retrieve(txId, {"status": "is_fraud"}, function(err, res){
# Configuration
if(err) return err
// something unexpected occurred
+ `ubivar.set("auth", "your-api-token")`
+ `ubivar.setTimeout(20000) // in ms`, node's default is `120000ms`
status = res.data[0].status
// the label of the transaction
})
```
# More information / wikis
## Resources, actions, and arguments
Every resource is accessed via your `ubivar` instance and accepts an optional
callback as the last argument. In the matrix below we list the resources
(rows), the actions (columns) and the arguments (cells). The full documentation
is available at [https://ubivar.com/docs/nodejs](https://ubivar.com/docs/nodejs).
+ [In-depth documentation](https://www.ubivar.com/docs/nodejs)
| Resource | C | R | U | D | L | Summary | Test Specs |
| ------------- |:-:|:-:|:-:|:-:|:----:|:-------:|:----------:|
| Accounts |<a href="https://ubivar.com/docs/nodejs#create_an_account">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#retrieve_an_account">id</a> |<a href="https://ubivar.com/docs/nodejs#update_an_account">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#delete_an_account">id</a>|<a href="https://ubivar.com/docs/nodejs#list_accounts">`{}`</a>| | [![](https://status.ubivar.com/ubivar-node/resources/accounts.svg)](https://github.com/ubivar/ubivar-node/blob/master/test/Resources/Accounts/spec.js)|
| Items |<a href="https://ubivar.com/docs/nodejs#create_item">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#retrieve_item">id</a> |<a href="https://ubivar.com/docs/nodejs#update_item">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#delete_item">id</a>|<a href="https://ubivar.com/docs/nodejs#list_items">`{}`</a>| | [![](https://status.ubivar.com/ubivar-node/resources/items.svg)](https://github.com/ubivar/ubivar-node/blob/master/test/Resources/Items/spec.js)|
| Labels |<a href="https://ubivar.com/docs/nodejs#create_label">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#retrieve_label">id</a> |<a href="https://ubivar.com/docs/nodejs#update_label">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#delete_label">id</a>|<a href="https://ubivar.com/docs/nodejs#list_labels">`{}`</a>| | [![](https://status.ubivar.com/ubivar-node/resources/labels.svg)](https://github.com/ubivar/ubivar-node/blob/master/test/Resources/Labels/spec.js) |
| Login |<a href="https://ubivar.com/docs/nodejs#create_login_event">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#retrieve_login_event">id</a> | |<a href="https://ubivar.com/docs/nodejs#delete_login_event">id</a>|<a href="https://ubivar.com/docs/nodejs#list_login_events">`{}`</a>| | [![](https://status.ubivar.com/ubivar-node/resources/login.svg)](https://github.com/ubivar/ubivar-node/blob/master/test/Resources/Login/spec.js)|
| Logout |<a href="https://ubivar.com/docs/nodejs#create_logout_event">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#retrieve_logout_event">id</a> | |<a href="https://ubivar.com/docs/nodejs#delete_logout_event">id</a>|<a href="https://ubivar.com/docs/nodejs#list_logout_events">`{}`</a>| | [![](https://status.ubivar.com/ubivar-node/resources/logout.svg)](https://github.com/ubivar/ubivar-node/blob/master/test/Resources/Logout/spec.js)|
| Me | |<a href="https://ubivar.com/docs/nodejs#retrieve_your_information">_</a> |<a href="https://ubivar.com/docs/nodejs#retrieve_your_information">`{}`</a>| | | | [![](https://status.ubivar.com/ubivar-node/resources/me.svg)](https://github.com/ubivar/ubivar-node/blob/master/test/Resources/Me/spec.js) |
| Routing | | <a href="https://ubivar.com/docs/nodejs#retrieve_a_routing">id</a> |<a href="https://ubivar.com/docs/nodejs#update_a_routing">`{}`</a>| |<a href="https://ubivar.com/docs/nodejs#list_routing">`{}`</a>| | [![](https://status.ubivar.com/ubivar-node/resources/routing.svg)](https://github.com/ubivar/ubivar-node/blob/master/test/Resources/Routing/spec.js)|
| Transactions |<a href="https://ubivar.com/docs/nodejs#create_a_transaction">`{}`</a>| <a href="https://ubivar.com/docs/nodejs#retrieve_a_transaction">id</a> |<a href="https://ubivar.com/docs/nodejs#update_a_transaction">`{}`</a>|<a href="https://ubivar.com/docs/nodejs#delete_a_transaction">id</a>|<a href="https://ubivar.com/docs/nodejs#list_transactions">`{}`</a>| | [![](https://status.ubivar.com/ubivar-node/resources/transactions.svg)](https://github.com/ubivar/ubivar-node/blob/master/test/Resources/Transactions/spec.js)|
# Development
+ *C*: Create
+ *R*: Retrieve
+ *U*: Update
+ *D*: Delete
+ *L*: List
+ `{}`: JSON with query parameters
## Filter parameters
| Filter | Default | Example | Description |
| ------------- |:-------:|:--------------------|:------------------------------|
| `start_after` | | `{"start_after":10}`| `id` after the one specified |
| `end_before` | | `{"end_before":10}` | `id` before the one specified |
| `limit` | `10` | `{"limit":10}` | At most `10` returned results |
| `gt` | | `{"id":{"gt":10}}` | `id` greater than 10 |
| `gte` | | `{"id":{"gte":10}}` | `id` greater than or equal |
| `lt` | | `{"id":{"lt":10}}` | `id` less than |
| `lte` | | `{"id":{"lte":10}}` | `id` less than or equal |
## Configuration
Extend `this` `ubivar` instance with a new resource whose accessibility is
controlled by access rights.
```js
var Ubivar = require("ubivar")
, ubivar = new Ubivar("YOUR_API_ACCESS_TOKEN")
ubivar.extend("geoip") // extend with
```
Change API access token dynamically:
```js
ubivar.set("auth", "your-api-token")
```
Define timeout of the binding:
```js
ubivar.set("timeout", 20000) // in ms`, node's default is `120000ms`
```
## Development
To run the tests, you will need a Ubivar test API key (from your [Ubivar dashboard](https://my.ubivar.com))

@@ -105,4 +167,6 @@

# Author
### [Issues and feature requests](https://github.com/ubivar/ubivar-node/issues)
Originally inspired from [stripe-node](https://github.com/stripe/stripe-node). Developed by [Fabrice Colas](https://fabricecolas.me) ([fabrice.colas@gmail.com](mailto:fabrice.colas@gmail.com)). Maintained by Ubivar.
## Author
Originally inspired from [stripe-node](https://github.com/stripe/stripe-node). Developed and maintained by [Fabrice Colas](https://fabricecolas.me) ([fabrice.colas@gmail.com](mailto:fabrice.colas@gmail.com)) for [Ubivar](https://ubivar.com).

@@ -9,5 +9,5 @@ "use strict"

var rootProps = ["log","_api"]
var rootProps = ["_api"]
, subProps = ["auth","protocol","timeout","resources","revokedCerts","headers","request"]
, methods = ["create", "retrieve", "update", "del", "list"]
, methods = ["create", "retrieve", "update", "del", "list", "summary"]
, resources = ubivar.get("resources")

@@ -34,7 +34,4 @@

})
describe("Timeout", function(){
it("Should default to the one of node", function(){
expect(ubivar.get('timeout')).to.equal(require('http').createServer().timeout)
})
it("Should allow to change default value", function(){

@@ -69,3 +66,2 @@ ubivar.set("timeout", 900);

})
})

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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