6.0.18 • Published 3 months ago

leo-sdk v6.0.18

Weekly downloads
495
License
MIT
Repository
github
Last release
3 months 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.9

6 months ago

7.1.11

5 months ago

7.1.12

3 months ago

7.1.10

5 months ago

7.1.8

1 year ago

7.0.1

1 year ago

7.1.7

1 year ago

7.1.2-awsv3

1 year ago

7.1.1-awsv3

1 year ago

6.0.26-alpha

1 year ago

7.1.0-awsv3

1 year ago

7.0.2-alphav7

1 year ago

6.0.25-alpha

1 year ago

6.0.24-alpha

1 year ago

7.0.1-alphav7

1 year ago

7.0.0-alphav7

2 years ago

6.0.23-alpha

2 years ago

6.0.22-alpha

2 years ago

6.0.18

2 years ago

5.0.33-latest-v5

2 years ago

5.0.34-latest-v5

2 years ago

6.0.21-alpha

2 years ago

6.0.20-alpha

2 years ago

6.0.18-alpha

2 years ago

6.0.19-alpha

2 years ago

5.0.29-latest-v5

2 years ago

6.0.17-rc.2

2 years ago

5.0.30-latest-v5

2 years ago

6.0.17

2 years ago

5.0.32-latest-v5

2 years ago

5.0.28-latest-v5

2 years ago

5.0.31-latestv5

2 years ago

5.0.27-latest-v5

2 years ago

6.0.17-rc

2 years ago

6.0.16

2 years ago

6.0.15

2 years ago

6.0.14

3 years ago

6.0.13

3 years ago

5.0.26-latest-v5

3 years ago

6.0.9-beta

3 years ago

6.0.12-beta

3 years ago

6.0.10-beta

3 years ago

6.0.11-beta

3 years ago

6.0.8

3 years ago

5.0.20

3 years ago

5.0.21

3 years ago

6.0.5-beta

3 years ago

5.0.19

3 years ago

6.0.6-beta

3 years ago

6.0.7

3 years ago

6.0.4

3 years ago

6.0.0-beta-1

3 years ago

5.0.19-beta.1

3 years ago

5.0.19-beta.0

3 years ago

5.0.19-beta.6

3 years ago

5.0.19-beta.5

3 years ago

6.0.1

3 years ago

6.0.0

3 years ago

6.0.3

3 years ago

6.0.2

3 years ago

5.0.15

4 years ago

5.0.16

4 years ago

5.0.17

4 years ago

5.0.18

3 years ago

5.0.14

4 years ago

5.0.13-rc

5 years ago

5.0.12-beta.2

5 years ago

5.0.12-beta.1

5 years ago

5.0.12

5 years ago

5.0.11

5 years ago

5.0.10

5 years ago

5.0.10-beta.6

5 years ago

5.0.10-beta.5

5 years ago

5.0.10-beta.4

5 years ago

5.0.10-beta.3

5 years ago

5.0.10-beta.2

5 years ago

5.0.10-beta

5 years ago

5.0.9

5 years ago

5.0.9-rc

5 years ago

5.0.8

5 years ago

5.0.8-rc

5 years ago

5.0.7

5 years ago

5.0.5

5 years ago

5.0.4

5 years ago

5.0.3

5 years ago

5.0.2

5 years ago

5.0.1

5 years ago

5.0.0

5 years ago

4.1.0

5 years ago

4.0.2

5 years ago

4.0.1

5 years ago

4.0.0

6 years ago

3.2.1

6 years ago

3.2.0

6 years ago

3.1.8

6 years ago

3.1.7

6 years ago

3.1.6

6 years ago

3.1.5

6 years ago

3.1.4

6 years ago

3.1.3

6 years ago

3.1.2

6 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.3.1

6 years ago

2.3.0

6 years ago

2.3.0-RC2

6 years ago

2.3.0-RC1

6 years ago

2.2.8

6 years ago

2.2.7

6 years ago

2.2.6

6 years ago

2.2.5

6 years ago

2.2.4

6 years ago

2.2.3

6 years ago

2.2.2

7 years ago

2.2.1

7 years ago

2.2.0

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.74

7 years ago

1.0.74-rc.1

7 years ago

1.0.73

7 years ago

1.0.72

7 years ago

1.0.71

7 years ago

1.0.70

7 years ago

1.0.69

7 years ago

1.0.68

7 years ago

1.0.67

7 years ago

1.0.66

7 years ago

1.0.65

7 years ago

1.0.64

7 years ago

1.0.63

7 years ago

1.0.62

7 years ago

1.0.61

7 years ago

1.0.60

7 years ago

1.0.59

7 years ago

1.0.57

7 years ago

1.0.56

7 years ago

1.0.55

7 years ago

1.0.54

7 years ago

1.0.53

7 years ago

1.0.52

7 years ago

1.0.51

7 years ago

1.0.50

7 years ago

1.0.49

7 years ago

1.0.48

7 years ago

1.0.47

7 years ago

1.0.46

7 years ago

1.0.45

7 years ago

1.0.44

7 years ago

1.0.43

7 years ago

1.0.42

7 years ago

1.0.41

7 years ago

1.0.40

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

8 years ago

1.0.35

8 years ago

1.0.34

8 years ago

1.0.33

8 years ago

1.0.32

8 years ago

1.0.31

8 years ago

1.0.30

8 years ago

1.0.29

8 years ago

1.0.28

8 years ago

1.0.27

8 years ago

1.0.26

8 years ago

1.0.25

8 years ago

1.0.24

8 years ago

1.0.23

8 years ago

1.0.21

8 years ago

1.0.20

8 years ago

1.0.19

8 years ago

1.0.18

8 years ago

1.0.17

8 years ago

1.0.16

8 years ago

1.0.15

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago