6.0.18 • Published 21 days ago

leo-sdk v6.0.18

Weekly downloads
495
License
MIT
Repository
github
Last release
21 days ago

LeoPlatform/Nodejs

Leo Nodejs SDK

A Nodejs interface to interact with the Leo Platform

Documentation: https://docs.leoplatform.io

How to install the Leo SDK

Pre-Requisites

  1. Install the aws-cli toolkit - Instructions for this are found at http://docs.aws.amazon.com/cli/latest/userguide/installing.html
  2. Configure the aws-cli tools - Instructions are found at http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-getting-started.html
  3. Install node - https://nodejs.org/en/
  4. Create a Leo Bus Stack - https://github.com/LeoPlatform/bus

Install SDK

  1. Install using npm. In your project folder run the following command.
npm install leo-sdk

Configuration

You can now configure a profile that will be used with your sdk similar to the way the AWS SDK works. To do this, you must execute a command line script and enter in your configuration settings.

Issue the following command from your project directory:

node node_modules/leo-sdk/generateProfile.js -r ${region} ${LeoSdkStack}
  • "${region}" is your leo bus AWS region. eg. us-west-2
  • "${LeoSdkStack}" is the name of your leo bus AWS stack. eg. "StagingLeo"

This will create a file in your home directory ~/.leo/config.json that contains your settings. You can setup multiple profiles just like you can do with the AWS SDK by specifying a different Stack.

How to use the Leo SDK

Now you can write to the new Stream

var leo = require("leo-sdk");
var botId = "producerBotId";
var queueName = "queueName";
var stream = leo.load(botId, queueName);

// Write 10 events to the leo bus
for (let i = 0; i < 10; i++) {
  stream.write({
    now: Date.now(),
    index: i,
    number: Math.round(Math.random() * 10000)
  });
}
stream.end(err=>{
	console.log("All done loading events", err);
});

Next in order to read from the stream

var leo = require("leo-sdk");
var botId = "offloadBotId";
var queueName = "queueName";
leo.offload({
	id: botId,
	queue: queueName,
	each: (payload, meta, done) =>{
		console.log(payload);
		console.log(meta);
		done(null, true); // Report this event was handled
	}
}, (err)=>{
	console.log("All done processing events", err);
});

You can also enrich from one queue to another

var leo = require("leo-sdk");

var botId = "enrichBotId";
var inQueueName = "queueName";
var outQueueName = "enrichedQueueName";
leo.enrich({
	id: botId,
	inQueue: inQueueName,
	outQueue:outQueueName,
	each: (payload, meta, done) =>{

		// Add new data to the event payload
		done(null, Object.assign({
			enriched: true,
			numberTimes2: payload.number * 2,
			enrichedNow: Date.now()
		}, payload));
	}
}, (err)=>{
	console.log("All done processing events", err);
});

Manual Configuration Setup

  1. Create a file at ~/.leo/config.json
  2. Add profile to the ~/.leo/config.json Values can be found under Resources in the AWS Stack
{
	"${LeoSdkStack}": {
		"region": "${Region}",
		"kinesis": "${LeoKinesisStream}",
		"s3": "${LeoS3}",
		"firehose": "${LeoFirehoseStream}",
		"resources": {
			"LeoStream": "${LeoStream}",
			"LeoCron": "${LeoCron}",
			"LeoEvent": "${LeoEvent}",
			"LeoSettings": "${LeoSettings}",
			"LeoSystem": "${LeoSystem}",
			"LeoS3": "${LeoS3}",
			"LeoKinesisStream": "${LeoKinesisStream}",
			"LeoFirehoseStream": "${LeoFirehoseStream}",
			"Region": "${Region}"
		}
	}
}
7.1.8

21 days ago

7.0.1

1 month ago

7.1.7

1 month ago

7.1.2-awsv3

3 months ago

7.1.1-awsv3

3 months ago

6.0.26-alpha

3 months ago

7.1.0-awsv3

3 months ago

7.0.2-alphav7

4 months ago

6.0.25-alpha

4 months ago

6.0.24-alpha

4 months ago

7.0.1-alphav7

4 months ago

7.0.0-alphav7

5 months ago

6.0.23-alpha

5 months ago

6.0.22-alpha

6 months ago

6.0.18

5 months ago

5.0.33-latest-v5

5 months ago

5.0.34-latest-v5

5 months ago

6.0.21-alpha

6 months ago

6.0.20-alpha

6 months ago

6.0.18-alpha

7 months ago

6.0.19-alpha

6 months ago

5.0.29-latest-v5

11 months ago

6.0.17-rc.2

9 months ago

5.0.30-latest-v5

10 months ago

6.0.17

9 months ago

5.0.32-latest-v5

9 months ago

5.0.28-latest-v5

11 months ago

5.0.31-latestv5

9 months ago

5.0.27-latest-v5

11 months ago

6.0.17-rc

10 months ago

6.0.16

1 year ago

6.0.15

1 year ago

6.0.14

1 year ago

6.0.13

2 years ago

6.0.9-beta

2 years ago

6.0.12-beta

2 years ago

6.0.10-beta

2 years ago

6.0.11-beta

2 years ago

6.0.8

2 years ago

5.0.20

2 years ago

5.0.21

2 years ago

6.0.5-beta

2 years ago

5.0.19

2 years ago

6.0.6-beta

2 years ago

6.0.7

2 years ago

6.0.4

2 years ago

6.0.0-beta-1

2 years ago

5.0.19-beta.1

2 years ago

5.0.19-beta.0

2 years ago

5.0.19-beta.6

2 years ago

5.0.19-beta.5

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

6.0.3

2 years ago

6.0.2

2 years ago

5.0.15

2 years ago

5.0.16

2 years ago

5.0.17

2 years ago

5.0.18

2 years ago

5.0.14

2 years ago

5.0.13-rc

4 years ago

5.0.12-beta.2

4 years ago

5.0.12-beta.1

4 years ago

5.0.12

4 years ago

5.0.11

4 years ago

5.0.10

4 years ago

5.0.10-beta.6

4 years ago

5.0.10-beta.5

4 years ago

5.0.10-beta.4

4 years ago

5.0.10-beta.3

4 years ago

5.0.10-beta.2

4 years ago

5.0.10-beta

4 years ago

5.0.9

4 years ago

5.0.9-rc

4 years ago

5.0.8

4 years ago

5.0.8-rc

4 years ago

5.0.7

4 years ago

5.0.5

4 years ago

5.0.4

4 years ago

5.0.3

4 years ago

5.0.2

4 years ago

5.0.1

4 years ago

5.0.0

4 years ago

4.1.0

4 years ago

4.0.2

4 years ago

4.0.1

4 years ago

4.0.0

4 years ago

3.2.1

4 years ago

3.2.0

4 years ago

3.1.8

5 years ago

3.1.7

5 years ago

3.1.6

5 years ago

3.1.5

5 years ago

3.1.4

5 years ago

3.1.3

5 years ago

3.1.2

5 years ago

3.1.1

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.3.0-RC2

5 years ago

2.3.0-RC1

5 years ago

2.2.8

5 years ago

2.2.7

5 years ago

2.2.6

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.74

6 years ago

1.0.74-rc.1

6 years ago

1.0.73

6 years ago

1.0.72

6 years ago

1.0.71

6 years ago

1.0.70

6 years ago

1.0.69

6 years ago

1.0.68

6 years ago

1.0.67

6 years ago

1.0.66

6 years ago

1.0.65

6 years ago

1.0.64

6 years ago

1.0.63

6 years ago

1.0.62

6 years ago

1.0.61

6 years ago

1.0.60

6 years ago

1.0.59

6 years ago

1.0.57

6 years ago

1.0.56

6 years ago

1.0.55

6 years ago

1.0.54

6 years ago

1.0.53

6 years ago

1.0.52

6 years ago

1.0.51

6 years ago

1.0.50

6 years ago

1.0.49

6 years ago

1.0.48

6 years ago

1.0.47

6 years ago

1.0.46

6 years ago

1.0.45

6 years ago

1.0.44

6 years ago

1.0.43

6 years ago

1.0.42

6 years ago

1.0.41

6 years ago

1.0.40

6 years ago

1.0.39

6 years ago

1.0.38

6 years ago

1.0.37

6 years ago

1.0.36

6 years ago

1.0.35

6 years ago

1.0.34

6 years ago

1.0.33

6 years ago

1.0.32

7 years ago

1.0.31

7 years ago

1.0.30

7 years ago

1.0.29

7 years ago

1.0.28

7 years ago

1.0.27

7 years ago

1.0.26

7 years ago

1.0.25

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.21

7 years ago

1.0.20

7 years ago

1.0.19

7 years ago

1.0.18

7 years ago

1.0.17

7 years ago

1.0.16

7 years ago

1.0.15

7 years ago

1.0.13

7 years ago

1.0.12

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago