@certik/skynet 0.10.49 → 0.10.50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.50
4
+
5
+ - Update slack postMessage to allow passing channelId directly
6
+ - BREAKING: Added key param for postGenieMessage
7
+
3
8
  ## 0.10.49
4
9
 
5
10
  - Updated eth/bsc/polygon protocol to use nodereal
package/opsgenie.js CHANGED
@@ -5,20 +5,14 @@ function getGenieKey() {
5
5
  return process.env.OPSGENIE_API_KEY;
6
6
  }
7
7
 
8
- function getGenieEndPoint() {
9
- const key = getGenieKey();
10
-
11
- if (!key) {
12
- throw new Error("Cannot communicate with opsgenie due to missing API key: process.env.OPSGENIE_API_KEY");
13
- }
14
-
15
- return process.env.OPSGENIE_END_POINT;
8
+ function getGenieEndPoint(key) {
9
+ return process.env.OPSGENIE_END_POINT || "https://api.opsgenie.com/v2/alerts";
16
10
  }
17
11
 
18
- async function postGenieMessage(body, verbose) {
12
+ async function postGenieMessage(body, apiKey, verbose) {
19
13
  try {
20
- const genieKey = getGenieKey();
21
- const genieEndPoint = getGenieEndPoint();
14
+ const genieKey = apiKey || getGenieKey();
15
+ const genieEndPoint = getGenieEndPoint(genieKey);
22
16
 
23
17
  // Prevents duplicate alerts (See Opsgenie doc about alias)
24
18
  if (!body.alias) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.10.49",
3
+ "version": "0.10.50",
4
4
  "description": "Skynet Shared JS library",
5
5
  "main": "index.js",
6
6
  "author": "CertiK Engineering",
package/slack.d.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import { WebClient } from "@slack/web-api";
2
2
 
3
+ type ChannelConfig = {
4
+ name: string;
5
+ id: string;
6
+ };
7
+
3
8
  export function getClient(): WebClient;
4
9
  export function findConversation(client: WebClient, name: string): Promise<string | null>;
5
- export function postMessage(channel: string, message: any, verbose: boolean): Promise<void>;
10
+ export function postMessage(channel: string | ChannelConfig, message: any, verbose: boolean): Promise<void>;
package/slack.js CHANGED
@@ -4,8 +4,8 @@ function getToken() {
4
4
  return process.env.SKYNET_SLACK_TOKEN;
5
5
  }
6
6
 
7
- function getClient() {
8
- const token = getToken();
7
+ function getClient(t) {
8
+ const token = t || getToken();
9
9
 
10
10
  if (!token) {
11
11
  throw new Error("Cannot communicate with slack due to missing slack token: process.env.SKYNET_SLACK_TOKEN");
@@ -49,11 +49,16 @@ async function findConversation(client, name) {
49
49
  return null;
50
50
  }
51
51
 
52
+ function isString(s) {
53
+ return typeof s === "string" || s instanceof String;
54
+ }
55
+
52
56
  async function postMessage(channel, message, verbose) {
53
57
  try {
54
- const client = getClient();
58
+ const token = isString(channel) ? null : channel.token;
59
+ const client = getClient(token);
55
60
 
56
- const conversationId = await findConversation(client, channel);
61
+ let conversationId = isString(channel) ? await findConversation(client, channel) : channel.id;
57
62
 
58
63
  if (!conversationId) {
59
64
  throw new Error(