diff --git a/README.md b/README.md index dd2be0c..6bae19b 100644 --- a/README.md +++ b/README.md @@ -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, }); @@ -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, @@ -88,10 +89,11 @@ const myOnTick: OnTick = { timestamp: string, rule: IRangeAlertRule, ): Promise => { - 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 []; } @@ -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, }); @@ -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 diff --git a/package.json b/package.json index 5b7a531..ddf1f9c 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/sdk.ts b/src/sdk.ts index 15a9bba..e7f2310 100644 --- a/src/sdk.ts +++ b/src/sdk.ts @@ -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 @@ -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'); @@ -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 {