@certik/skynet 0.22.2 → 0.23.0

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,16 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.23.0
4
+
5
+ - Added `goalert` module with `sendGoAlertAlert` helper
6
+ - BREAKING: removed `opsgenie` module/export
7
+ - Updated dependencies (including `@databricks/sql`, AWS SDK, Slack, Express)
8
+ - Updated patch for `@databricks/sql@1.12.0` to avoid loading native `lz4`
9
+
10
+ ## 0.22.3
11
+
12
+ - Refine types for opsgenie
13
+
3
14
  ## 0.22.2
4
15
 
5
16
  - Use bun to bundle js files, tsc is used to build types
@@ -38,7 +49,6 @@
38
49
  ## 0.20.0
39
50
 
40
51
  - Fix databricks with bun (extra step needed for projects using the lib):
41
-
42
52
  - Copy the patch file `patches/@databricks%2Fsql@1.9.0.patch`
43
53
  - Add the following configs to your `package.json`:
44
54
 
package/dist/api.js CHANGED
@@ -201,7 +201,6 @@ ${getSelectorDesc(selector)}
201
201
  `, {
202
202
  importMeta: import.meta,
203
203
  description: false,
204
- version: false,
205
204
  flags: {
206
205
  ...getSelectorFlags(selector),
207
206
  verbose: {
package/dist/app.js CHANGED
@@ -201,7 +201,6 @@ ${getSelectorDesc(selector)}
201
201
  `, {
202
202
  importMeta: import.meta,
203
203
  description: false,
204
- version: false,
205
204
  flags: {
206
205
  ...getSelectorFlags(selector),
207
206
  verbose: {
@@ -1141,7 +1140,6 @@ ${selector ? getSelectorDesc(selector) : ""}
1141
1140
  `, {
1142
1141
  importMeta: import.meta,
1143
1142
  description: false,
1144
- version: false,
1145
1143
  flags: {
1146
1144
  ...getSelectorFlags(selector),
1147
1145
  mode: {
@@ -1195,7 +1193,6 @@ ${selector ? getSelectorDesc(selector) : ""}
1195
1193
  `, {
1196
1194
  importMeta: import.meta,
1197
1195
  description: false,
1198
- version: false,
1199
1196
  flags: {
1200
1197
  ...getSelectorFlags(selector),
1201
1198
  verbose: {
@@ -1573,7 +1570,6 @@ ${getSelectorDesc(selector)}
1573
1570
  `, {
1574
1571
  importMeta: import.meta,
1575
1572
  description: false,
1576
- version: false,
1577
1573
  flags: {
1578
1574
  ...getSelectorFlags(selector),
1579
1575
  mode: {
@@ -1696,7 +1692,6 @@ ${getSelectorDesc(selector)}
1696
1692
  `, {
1697
1693
  importMeta: import.meta,
1698
1694
  description: false,
1699
- version: false,
1700
1695
  flags: {
1701
1696
  ...getSelectorFlags(selector),
1702
1697
  schedule: {
package/dist/deploy.js CHANGED
@@ -424,7 +424,6 @@ ${getSelectorDesc(selector)}
424
424
  `, {
425
425
  importMeta: import.meta,
426
426
  description: false,
427
- version: false,
428
427
  flags: {
429
428
  ...getSelectorFlags(selector),
430
429
  mode: {
@@ -547,7 +546,6 @@ ${getSelectorDesc(selector)}
547
546
  `, {
548
547
  importMeta: import.meta,
549
548
  description: false,
550
- version: false,
551
549
  flags: {
552
550
  ...getSelectorFlags(selector),
553
551
  schedule: {
@@ -0,0 +1,19 @@
1
+ export type GoAlertAction = "close";
2
+ export interface GoAlertGenericIncomingRequest {
3
+ /** Short description of the alert sent as SMS and voice. */
4
+ summary: string;
5
+ /** Additional information about the alert, supports markdown. */
6
+ details?: string;
7
+ /** If set to `close`, it will close any matching alerts. */
8
+ action?: GoAlertAction;
9
+ /** All calls for the same service with the same `dedup` string will update the same alert (if open) or create a new one. Defaults to using summary & details together. */
10
+ dedup?: string;
11
+ }
12
+ export interface GoAlertSendOptions {
13
+ url?: string;
14
+ }
15
+ export interface GoAlertSendResult {
16
+ ok: boolean;
17
+ status: number;
18
+ }
19
+ export declare function sendGoAlertAlert(body: GoAlertGenericIncomingRequest, options?: GoAlertSendOptions): Promise<GoAlertSendResult>;
@@ -0,0 +1,43 @@
1
+ // src/goalert.ts
2
+ function getGoAlertUrl(url) {
3
+ return url || process.env["SKYNET_GOALERT_URL"];
4
+ }
5
+ async function sendGoAlertAlert(body, options = {}) {
6
+ if (!body?.summary) {
7
+ throw new Error("missing GoAlert summary");
8
+ }
9
+ const url = getGoAlertUrl(options.url);
10
+ if (!url) {
11
+ throw new Error("missing SKYNET_GOALERT_URL");
12
+ }
13
+ const response = await fetch(url, {
14
+ method: "POST",
15
+ headers: {
16
+ "Content-Type": "application/json"
17
+ },
18
+ body: JSON.stringify(body)
19
+ });
20
+ let parsed = undefined;
21
+ const contentType = response.headers.get("content-type") || "";
22
+ try {
23
+ if (contentType.includes("application/json")) {
24
+ parsed = await response.json();
25
+ } else {
26
+ const text = await response.text();
27
+ parsed = text.length ? text : undefined;
28
+ }
29
+ } catch {
30
+ parsed = undefined;
31
+ }
32
+ if (!response.ok) {
33
+ const extra = typeof parsed === "string" && parsed ? `: ${parsed}` : "";
34
+ throw new Error(`GoAlert API error ${response.status}${extra}`);
35
+ }
36
+ return {
37
+ ok: response.ok,
38
+ status: response.status
39
+ };
40
+ }
41
+ export {
42
+ sendGoAlertAlert
43
+ };
package/dist/indexer.js CHANGED
@@ -996,7 +996,6 @@ ${selector ? getSelectorDesc(selector) : ""}
996
996
  `, {
997
997
  importMeta: import.meta,
998
998
  description: false,
999
- version: false,
1000
999
  flags: {
1001
1000
  ...getSelectorFlags(selector),
1002
1001
  mode: {
@@ -1050,7 +1049,6 @@ ${selector ? getSelectorDesc(selector) : ""}
1050
1049
  `, {
1051
1050
  importMeta: import.meta,
1052
1051
  description: false,
1053
- version: false,
1054
1052
  flags: {
1055
1053
  ...getSelectorFlags(selector),
1056
1054
  verbose: {
package/dist/slack.d.ts CHANGED
@@ -1,8 +1,9 @@
1
1
  import type { ChatPostMessageArguments } from "@slack/web-api";
2
2
  declare function postMessageToConversation({ conversationId, message, token, verbose, }: {
3
3
  conversationId: string;
4
- message: string | Partial<ChatPostMessageArguments>;
4
+ message: string | ChatPostMessageArguments;
5
5
  token?: string;
6
6
  verbose?: boolean;
7
7
  }): Promise<void>;
8
8
  export { postMessageToConversation };
9
+ export type { ChatPostMessageArguments };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.22.2",
3
+ "version": "0.23.0",
4
4
  "description": "Skynet Shared JS library",
5
5
  "type": "module",
6
6
  "exports": {
@@ -52,6 +52,10 @@
52
52
  "import": "./dist/env.js",
53
53
  "types": "./dist/env.d.ts"
54
54
  },
55
+ "./goalert": {
56
+ "import": "./dist/goalert.js",
57
+ "types": "./dist/goalert.d.ts"
58
+ },
55
59
  "./graphql": {
56
60
  "import": "./dist/graphql.js",
57
61
  "types": "./dist/graphql.d.ts"
@@ -68,10 +72,6 @@
68
72
  "import": "./dist/object-hash.js",
69
73
  "types": "./dist/object-hash.d.ts"
70
74
  },
71
- "./opsgenie": {
72
- "import": "./dist/opsgenie.js",
73
- "types": "./dist/opsgenie.d.ts"
74
- },
75
75
  "./por": {
76
76
  "import": "./dist/por.js",
77
77
  "types": "./dist/por.d.ts"
@@ -110,45 +110,46 @@
110
110
  "node": ">= 18"
111
111
  },
112
112
  "dependencies": {
113
- "@aws-sdk/client-dynamodb": "^3.758.0",
114
- "@aws-sdk/client-s3": "^3.758.0",
115
- "@aws-sdk/client-sqs": "^3.758.0",
116
- "@aws-sdk/lib-dynamodb": "^3.758.0",
117
- "@databricks/sql": "^1.9.0",
118
- "@elastic/elasticsearch": "^8.17.1",
113
+ "@aws-sdk/client-dynamodb": "^3.975.0",
114
+ "@aws-sdk/client-s3": "^3.975.0",
115
+ "@aws-sdk/client-sqs": "^3.975.0",
116
+ "@aws-sdk/lib-dynamodb": "^3.975.0",
117
+ "@databricks/sql": "^1.12.0",
118
+ "@elastic/elasticsearch": "^8.19.1",
119
119
  "@node-rs/xxhash": "^1.7.6",
120
- "@slack/web-api": "^6.13.0",
121
- "chalk": "^5.4.1",
122
- "execa": "^9.5.2",
123
- "express": "^4.21.2",
120
+ "@slack/web-api": "^7.13.0",
121
+ "chalk": "^5.6.2",
122
+ "execa": "^9.6.1",
123
+ "express": "^5.2.1",
124
124
  "md5": "^2.3.0",
125
- "meow": "^13.2.0",
126
- "p-memoize": "^7.1.1",
127
- "p-throttle": "^7.0.0",
128
- "quick-lru": "^7.0.0",
129
- "type-fest": "^4.35.0",
130
- "which": "^5.0.0"
125
+ "meow": "^14.0.0",
126
+ "p-memoize": "^8.0.0",
127
+ "p-throttle": "^8.1.0",
128
+ "quick-lru": "^7.3.0",
129
+ "type-fest": "^5.4.1",
130
+ "which": "^6.0.0"
131
131
  },
132
132
  "devDependencies": {
133
- "@eslint/js": "^9.21.0",
134
- "@types/bun": "^1.2.4",
135
- "@types/express": "^5.0.0",
136
- "@types/md5": "^2.3.5",
133
+ "@eslint/js": "^9.39.2",
134
+ "@types/bun": "^1.3.6",
135
+ "@types/express": "^5.0.6",
136
+ "@types/md5": "^2.3.6",
137
137
  "@types/which": "^3.0.4",
138
- "eslint": "^9.21.0",
139
- "eslint-plugin-import": "^2.31.0",
138
+ "eslint": "^9.39.2",
139
+ "eslint-plugin-import": "^2.32.0",
140
140
  "eslint-plugin-md": "^1.0.19",
141
- "eslint-plugin-prettier": "^5.2.3",
142
- "prettier": "^3.5.2",
143
- "rimraf": "^6.0.1",
144
- "typescript": "^5.8.2",
145
- "typescript-eslint": "^8.38.0"
141
+ "eslint-plugin-prettier": "^5.5.5",
142
+ "prettier": "^3.8.1",
143
+ "rimraf": "^6.1.2",
144
+ "typescript": "^5.9.3",
145
+ "typescript-eslint": "^8.53.1"
146
146
  },
147
147
  "license": "MIT",
148
148
  "publishConfig": {
149
149
  "access": "public"
150
150
  },
151
151
  "patchedDependencies": {
152
- "@databricks/sql@1.9.0": "patches/@databricks%2Fsql@1.9.0.patch"
152
+ "@databricks/sql@1.9.0": "patches/@databricks%2Fsql@1.9.0.patch",
153
+ "@databricks/sql@1.12.0": "patches/@databricks%2Fsql@1.12.0.patch"
153
154
  }
154
- }
155
+ }
@@ -0,0 +1,31 @@
1
+ diff --git a/dist/utils/lz4.js b/dist/utils/lz4.js
2
+ index 5f067ab1c3bdf1430deabf488c8259a804dd33f8..fe440516e86f428446afe3c78ab0211a5a5b139c 100644
3
+ --- a/dist/utils/lz4.js
4
+ +++ b/dist/utils/lz4.js
5
+ @@ -1,25 +1,7 @@
6
+ "use strict";
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ function tryLoadLZ4Module() {
9
+ - try {
10
+ - return require('lz4'); // eslint-disable-line global-require
11
+ - }
12
+ - catch (err) {
13
+ - if (!(err instanceof Error) || !('code' in err)) {
14
+ - console.warn('Unexpected error loading LZ4 module: Invalid error object', err);
15
+ - return undefined;
16
+ - }
17
+ - if (err.code === 'MODULE_NOT_FOUND') {
18
+ - return undefined;
19
+ - }
20
+ - if (err.code === 'ERR_DLOPEN_FAILED') {
21
+ - console.warn('LZ4 native module failed to load: Architecture or version mismatch', err);
22
+ - return undefined;
23
+ - }
24
+ - // If it's not a known error, return undefined
25
+ - console.warn('Unknown error loading LZ4 module: Unhandled error code', err);
26
+ - return undefined;
27
+ - }
28
+ + return undefined;
29
+ }
30
+ exports.default = tryLoadLZ4Module();
31
+ //# sourceMappingURL=lz4.js.map
package/src/api.ts CHANGED
@@ -156,7 +156,6 @@ ${getSelectorDesc(selector)}
156
156
  {
157
157
  importMeta: import.meta,
158
158
  description: false,
159
- version: false,
160
159
  flags: {
161
160
  ...getSelectorFlags(selector),
162
161
  verbose: {
package/src/deploy.ts CHANGED
@@ -491,7 +491,6 @@ ${getSelectorDesc(selector)}
491
491
  {
492
492
  importMeta: import.meta,
493
493
  description: false,
494
- version: false,
495
494
  flags: {
496
495
  ...getSelectorFlags(selector),
497
496
  mode: {
@@ -655,7 +654,6 @@ ${getSelectorDesc(selector)}
655
654
  {
656
655
  importMeta: import.meta,
657
656
  description: false,
658
- version: false,
659
657
  flags: {
660
658
  ...getSelectorFlags(selector),
661
659
  schedule: {
package/src/goalert.ts ADDED
@@ -0,0 +1,70 @@
1
+ export type GoAlertAction = "close";
2
+
3
+ export interface GoAlertGenericIncomingRequest {
4
+ /** Short description of the alert sent as SMS and voice. */
5
+ summary: string;
6
+ /** Additional information about the alert, supports markdown. */
7
+ details?: string;
8
+ /** If set to `close`, it will close any matching alerts. */
9
+ action?: GoAlertAction;
10
+ /** All calls for the same service with the same `dedup` string will update the same alert (if open) or create a new one. Defaults to using summary & details together. */
11
+ dedup?: string;
12
+ }
13
+
14
+ export interface GoAlertSendOptions {
15
+ url?: string;
16
+ }
17
+
18
+ export interface GoAlertSendResult {
19
+ ok: boolean;
20
+ status: number;
21
+ }
22
+
23
+ function getGoAlertUrl(url?: string) {
24
+ return url || process.env["SKYNET_GOALERT_URL"];
25
+ }
26
+
27
+ export async function sendGoAlertAlert(
28
+ body: GoAlertGenericIncomingRequest,
29
+ options: GoAlertSendOptions = {},
30
+ ): Promise<GoAlertSendResult> {
31
+ if (!body?.summary) {
32
+ throw new Error("missing GoAlert summary");
33
+ }
34
+
35
+ const url = getGoAlertUrl(options.url);
36
+ if (!url) {
37
+ throw new Error("missing SKYNET_GOALERT_URL");
38
+ }
39
+
40
+ const response = await fetch(url, {
41
+ method: "POST",
42
+ headers: {
43
+ "Content-Type": "application/json",
44
+ },
45
+ body: JSON.stringify(body),
46
+ });
47
+
48
+ let parsed: unknown = undefined;
49
+ const contentType = response.headers.get("content-type") || "";
50
+ try {
51
+ if (contentType.includes("application/json")) {
52
+ parsed = await response.json();
53
+ } else {
54
+ const text = await response.text();
55
+ parsed = text.length ? text : undefined;
56
+ }
57
+ } catch {
58
+ parsed = undefined;
59
+ }
60
+
61
+ if (!response.ok) {
62
+ const extra = typeof parsed === "string" && parsed ? `: ${parsed}` : "";
63
+ throw new Error(`GoAlert API error ${response.status}${extra}`);
64
+ }
65
+
66
+ return {
67
+ ok: response.ok,
68
+ status: response.status,
69
+ };
70
+ }
package/src/indexer.ts CHANGED
@@ -615,7 +615,6 @@ ${selector ? getSelectorDesc(selector) : ""}
615
615
  {
616
616
  importMeta: import.meta,
617
617
  description: false,
618
- version: false,
619
618
  flags: {
620
619
  ...getSelectorFlags(selector),
621
620
  mode: {
@@ -684,7 +683,6 @@ ${selector ? getSelectorDesc(selector) : ""}
684
683
  {
685
684
  importMeta: import.meta,
686
685
  description: false,
687
- version: false,
688
686
  flags: {
689
687
  ...getSelectorFlags(selector),
690
688
  verbose: {
package/src/slack.ts CHANGED
@@ -13,7 +13,7 @@ async function postMessageToConversation({
13
13
  verbose,
14
14
  }: {
15
15
  conversationId: string;
16
- message: string | Partial<ChatPostMessageArguments>;
16
+ message: string | ChatPostMessageArguments;
17
17
  token?: string;
18
18
  verbose?: boolean;
19
19
  }) {
@@ -42,3 +42,5 @@ async function postMessageToConversation({
42
42
  }
43
43
 
44
44
  export { postMessageToConversation };
45
+
46
+ export type { ChatPostMessageArguments };
package/bun.lockb DELETED
Binary file
@@ -1,21 +0,0 @@
1
- type OpsgenieResponse = {
2
- data: {
3
- success: boolean;
4
- action: string;
5
- processedAt: string;
6
- integrationId: string;
7
- isSuccess: boolean;
8
- status: string;
9
- alertId: string;
10
- alias: string;
11
- };
12
- took: number;
13
- requestId: string;
14
- result: string;
15
- };
16
- export declare function postGenieMessage(body: {
17
- alias?: string;
18
- message: string;
19
- description?: string;
20
- }, apiKey?: string, verbose?: boolean): Promise<OpsgenieResponse>;
21
- export {};
package/dist/opsgenie.js DELETED
@@ -1,39 +0,0 @@
1
- // src/opsgenie.ts
2
- import md5 from "md5";
3
- function getGenieKey(key) {
4
- return key || process.env["SKYNET_OPSGENIE_API_KEY"];
5
- }
6
- function getGenieEndPoint() {
7
- return process.env["SKYNET_OPSGENIE_END_POINT"] || "https://api.opsgenie.com/v2/alerts";
8
- }
9
- async function postGenieMessage(body, apiKey, verbose) {
10
- try {
11
- const genieKey = apiKey || getGenieKey();
12
- const genieEndPoint = getGenieEndPoint();
13
- if (!body.alias) {
14
- body.alias = md5(body.message);
15
- }
16
- if (verbose) {
17
- console.log(`Making API call to Opsgenie`, JSON.stringify(body, null, 2));
18
- }
19
- const response = await fetch(genieEndPoint, {
20
- method: "POST",
21
- headers: {
22
- "Content-Type": "application/json",
23
- Authorization: `GenieKey ${genieKey}`
24
- },
25
- body: JSON.stringify(body)
26
- });
27
- const result = await response.json();
28
- if (verbose) {
29
- console.log(`Result of API call to Opsgenie... ${result}`);
30
- }
31
- return result;
32
- } catch (error) {
33
- console.error("Failed to make opsgenie API call", error);
34
- throw error;
35
- }
36
- }
37
- export {
38
- postGenieMessage
39
- };
package/src/opsgenie.ts DELETED
@@ -1,70 +0,0 @@
1
- import md5 from "md5";
2
-
3
- type OpsgenieResponse = {
4
- data: {
5
- success: boolean;
6
- action: string;
7
- processedAt: string;
8
- integrationId: string;
9
- isSuccess: boolean;
10
- status: string;
11
- alertId: string;
12
- alias: string;
13
- };
14
- took: number;
15
- requestId: string;
16
- result: string;
17
- };
18
-
19
- function getGenieKey(key?: string) {
20
- return key || process.env["SKYNET_OPSGENIE_API_KEY"];
21
- }
22
-
23
- function getGenieEndPoint() {
24
- return process.env["SKYNET_OPSGENIE_END_POINT"] || "https://api.opsgenie.com/v2/alerts";
25
- }
26
-
27
- export async function postGenieMessage(
28
- body: {
29
- alias?: string;
30
- message: string;
31
- description?: string;
32
- },
33
- apiKey?: string,
34
- verbose?: boolean,
35
- ) {
36
- try {
37
- const genieKey = apiKey || getGenieKey();
38
- const genieEndPoint = getGenieEndPoint();
39
-
40
- // Prevents duplicate alerts (See Opsgenie doc about alias)
41
- if (!body.alias) {
42
- body.alias = md5(body.message);
43
- }
44
-
45
- if (verbose) {
46
- console.log(`Making API call to Opsgenie`, JSON.stringify(body, null, 2));
47
- }
48
-
49
- // Makes the call using fetch and ENV variables
50
- const response = await fetch(genieEndPoint, {
51
- method: "POST",
52
- headers: {
53
- "Content-Type": "application/json",
54
- Authorization: `GenieKey ${genieKey}`,
55
- },
56
- body: JSON.stringify(body),
57
- });
58
-
59
- const result = (await response.json()) as OpsgenieResponse;
60
- if (verbose) {
61
- console.log(`Result of API call to Opsgenie... ${result}`);
62
- }
63
-
64
- return result;
65
- } catch (error) {
66
- console.error("Failed to make opsgenie API call", error);
67
-
68
- throw error;
69
- }
70
- }