Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,11 @@ const myOnBlock: OnBlock = {
};

(async () => {
// Defining the RangeSDK instance
// token: use your env (e.g. process.env.RANGE_TOKEN in Node)
const range = new RangeSDK({
token: env.RANGE_TOKEN,
token: process.env.RANGE_TOKEN!,
});

// Running the RangeSDK instance
await range.init({
onBlock: myOnBlock,
});
Expand All @@ -75,6 +74,8 @@ const myOnBlock: OnBlock = {

```typescript
// Range Implementation of `rpc-status` alert rule
import axios from 'axios';
import dayjs from 'dayjs';
import {
RangeSDK,
OnTick,
Expand All @@ -88,10 +89,11 @@ const myOnTick: OnTick = {
timestamp: string,
rule: IRangeAlertRule,
): Promise<ISubEvent[]> => {
const parameters = rule.parameters;
const parameters = rule.parameters ?? {};
const tickMinutes = Number(parameters.ticker ?? 10);

// note: if p.ticker is set as 10, the rule will run on each 10 minutes
if (dayjs(timestamp).get('minute') % p.ticker !== 0) {
// note: if ticker is 10, only runs when the clock minute is divisible by 10
if (dayjs(timestamp).minute() % tickMinutes !== 0) {
return [];
}

Expand All @@ -114,12 +116,10 @@ const myOnTick: OnTick = {
};

(async () => {
// Defining the RangeSDK instance
const range = new RangeSDK({
token: env.RANGE_TOKEN,
token: process.env.RANGE_TOKEN!,
});

// Running the RangeSDK instance
await range.init({
onTick: myOnTick,
});
Expand Down Expand Up @@ -161,15 +161,15 @@ npm install
4. Commit your changes and push to your fork.
5. Create a pull request with a detailed explanation of your changes.

Before contributing, please read our [CONTRIBUTING.md](link).
Before contributing, please read our [CONTRIBUTING.md](./CONTRIBUTING.md).

## Reporting bugs

If you encounter any bugs or issues, please [open an issue on GitHub](link). When reporting a bug, please provide as much context as possible, including error messages, logs, and steps to reproduce the bug.
If you encounter any bugs or issues, please [open an issue on GitHub](https://github.com/rangesecurity/range-sdk/issues). When reporting a bug, please provide as much context as possible, including error messages, logs, and steps to reproduce the bug.

## License

This project is licensed under the MIT License. See the [LICENSE](link) file for details.
This project is licensed under the MIT License. See the [LICENSE](./LICENSE) file for details.

## Credits

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dev": "tsc-watch --onSuccess \"node dist/src/index.js\"",
"example": "tsc-watch --onSuccess \"node dist/examples/alertProcessors.js\"",
"pushBlock": "tsc-watch --onSuccess \"node dist/tests/pushBlock.js\"",
"lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
"lint": "eslint \"src/**/*.ts\" \"tests/**/*.ts\" --fix",
"format": "prettier --write \"src/**/*.ts\" \"tests/**/*.ts\"",
"pub": "rm -rf dist && npm run build && npm publish --access public"
},
Expand Down
8 changes: 5 additions & 3 deletions src/sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,8 @@ class RangeSDK implements IRangeSDK {

let err = String(error);
if (error instanceof Error) {
err = error.message + error.stack ? `\n${error.stack}` : '';
err =
error.message + (error.stack ? `\n${error.stack}` : '');
}

// Set metrics so that timed out processes can be jailed
Expand Down Expand Up @@ -867,7 +868,7 @@ class RangeSDK implements IRangeSDK {
): Promise<{ errors: IRangeError[]; alertEventsCount: number }> => {
try {
if (!this.initOpts) {
throw new Error('SDK Init not called, onBlock missing');
throw new Error('SDK Init not called, onTick missing');
}
if (!this.initOpts.onTick) {
throw new Error('Missing handler for tick based alert rules');
Expand Down Expand Up @@ -902,7 +903,8 @@ class RangeSDK implements IRangeSDK {
} catch (error) {
let err = String(error);
if (error instanceof Error) {
err = error.message + error.stack ? `\n${error.stack}` : '';
err =
error.message + (error.stack ? `\n${error.stack}` : '');
}

return {
Expand Down