Coder Social home page Coder Social logo

wutitded88 / ambrosus-node-extended Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ambrosus/ambrosus-node-extended

0.0 0.0 0.0 4.18 MB

Expanded reporting and organizational functionality for the Hermes node.

License: MIT License

JavaScript 0.67% TypeScript 72.73% API Blueprint 26.58% Dockerfile 0.03%

ambrosus-node-extended's Introduction

Build Status

Hermes Extended API

Additional querying capabilities which consists of both REST and GraphQL APIs.

Getting Started

Install dependencies

npm install

Run development

npm start

The extended API should now be running on port 3000

Testing

Run tests

npm run dev:test

Run linting

npm run dev:lint

Production

Build

npm run build

Run compiled server code

npm run start:server

Clean build

npm dev:clean

Usage (REST)

GET endpoints exist for basic fetching of various data collections including assets, events and bundles.

Examples:

Get asset

curl -X GET http://localhost:3000/asset/<assetId>

Get assets

curl -X GET http://localhost:3000/asset 

Get event

curl -X GET http://localhost:3000/event/<eventId>

Get events

curl -X GET http://localhost:3000/event 

For a full list of endpoints see the Postman collection

Pagination

Result sets contain next and previous object pointers which allow navigation through the result set. To navigate to the next page send either pointers and the result set will begin from that position. If both pointers are sent, the next pointer will take precendence. 'hasNext' and 'hasPrevious' indicate whether or not there is additional data in either direction.

Example

{
    "results": [
        ...
    ]
    "previous": "WzE1Mzk5NjM3ODIseyIkdW5kZWZpbmVkIjp0cnVlfV0",
    "hasPrevious": false,
    "next": "WzE1Mzk5NTU0MTkseyIkdW5kZWZpbmVkIjp0cnVlfV0",
    "hasNext": true
}

Filtering data

Querying (filtering) can be achieved by sending a POST request containing a valid query object.

The query object has the following format:

{
    "query": [{
		"field": "",
		"value": "",
		"operator": ""
	},
    ],
    "limit": 0,
    "previous": ""
    "next": ""
    }

Explanation:

The field key corresponds to a field in the database and can be targeted using dot notation. For example 'metadata.bundleId' and 'content.data.unit'.

The value key is used to filter the supplied field and can contain an array, dict or primitive.

The operator key specifies how the field should be queried against the value.

The following operators are supported:

Operator Expected value
equal String or Array
not-equal String or Array
greater-than Integer
greater-than-equal Integer
less-than Integer
less-than-equal Integer
inrange Dictionary containing range - see below

The inrange operator expects a value in the following format:

{
    "field": "content.idData.timestamp",
    "value": {"greater-than-equal": 1538315311, "less-than-equal": 1540216111},
    "operator": "inrange"
}

Query Examples:

Querying an event of type, created gte to a timestamp

curl -X POST http://localhost:3000/event/query \
  -H 'Content-Type: application/json' \
  -d '{
	"query": [{
		"field": "content.data.type",
		"value": "ambrosus.asset.info",
		"operator": "equal"
	},
	{
		"field": "content.idData.timestamp",
		"value": 1535723311,
		"operator": "greater-than-equal"
	}]
}

Querying events not of a type, for a list of assets

curl -X POST http://localhost:3000/event/query \
  -H 'Content-Type: application/json' \
  -d '{
	"query": [{
		"field": "content.data.type",
		"value": [
			"ambrosus.asset.info", "ambrosus.asset.branding"
			],
		"operator": "not-equal"
	},
	{
		"field": "content.idData.assetId",
		"value": [
			"0x7dca2776fad2ee828b2fbc5d51951b1a8d95d8fa83593e692e95dfed084c5691", "0xf0e2333a01d75a71a6e944a602b11d8f2399c2f57070be3131a869cb0b5e1d97"
			],
		"operator": "equal"
	}]
}

Querying events for assets not created by a user

curl -X POST http://localhost:3000/event/query \
  -H 'Content-Type: application/json' \
  -d '{
	"query": [{
		"field": "content.idData.assetId",
		"value": [
			"0x7dca2776fad2ee828b2fbc5d51951b1a8d95d8fa83593e692e95dfed084c5691", "0xf0e2333a01d75a71a6e944a602b11d8f2399c2f57070be3131a869cb0b5e1d97"
			],
		"operator": "equal"
	},
	{
		"field": "content.idData.createdBy",
		"value": "0x38E80315167c5367A56993A6accB58c81B3A81df",
		"operator": "not-equal"
	}]
}

Aggregation

A special endpoint exists to perform limited aggregation of events grouped by assetId. The endpoint exists to fetch the latest asset event of a certain type.

Examples:

curl -X POST http://localhost:3000/event/latest/type \
  -H 'Content-Type: application/json' \
  -d '{
	"assets": ["0x9d8c8bb6101751b583e64002ad8abe681aa61b6f8179ccef668fce91798e3018", "0x2be15879ad66636da6a5cccc70d75cda65809113f50355d97c93296d67486913"],
	"type": "ambrosus.asset.info"
}

Analytics

The following summations are available for all data collections. Time serious data is TBD

Examples:

Count all events

curl -X GET  http://localhost:3000/event/count 

Count of events created month to date

curl -X GET  http://localhost:3000/event/mtd

For a full list of endpoints see the Postman collection

Usage (GraphQL)

In browser IDE:

http://localhost:3000/graphiql

GraphQL Endpoint:

http://localhost:3000/gql

Angular support:

https://www.apollographql.com/docs/angular/

Examples:

Get events

curl -X POST http://localhost:3000/gql \
  -H 'Content-Type: application/json' \
  -d '{
"query": "{
	getEvents {
		results {
			eventId
			content {
				signature
				idData {
					assetId
					createdBy
					accessLevel
					timestamp
				} 
			}
		}
		hasNext
		next
		hasPrevious
		previous
	}
}",
"variables": null,
"operationName": null
}'

Get events, limiting results

curl -X POST http://localhost:3000/gql \
  -H 'Content-Type: application/json' \
  -d '{
"query": "{
	getEvents {
		results {
			eventId
			content {
				idData {
					assetId
				} 
			}
		}
		hasNext
		next
	}
}",
"variables": null,
"operationName": null
}'

ambrosus-node-extended's People

Contributors

conorseabrook avatar seagiv avatar lazar-eric avatar vpowler avatar dependabot[bot] avatar andrewar2 avatar valar999 avatar adinhodovic avatar danihodovic avatar sigismundschlomo avatar amoiseich avatar krzysztof-jelski avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.