@certik/skynet 0.22.3 → 0.24.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/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
@@ -11,12 +11,19 @@ async function postMessageToConversation({
11
11
  message,
12
12
  token,
13
13
  verbose,
14
- }: {
15
- conversationId: string;
16
- message: string | Partial<ChatPostMessageArguments>;
17
- token?: string;
18
- verbose?: boolean;
19
- }) {
14
+ }:
15
+ | {
16
+ conversationId: string;
17
+ message: string;
18
+ token?: string;
19
+ verbose?: boolean;
20
+ }
21
+ | {
22
+ conversationId?: undefined;
23
+ message: ChatPostMessageArguments;
24
+ token?: string;
25
+ verbose?: boolean;
26
+ }) {
20
27
  if (!token) {
21
28
  throw new Error("missing slack token");
22
29
  }
@@ -24,16 +31,13 @@ async function postMessageToConversation({
24
31
  try {
25
32
  const client = getClient(token);
26
33
 
27
- const post = typeof message === "string" ? { text: message } : message;
34
+ const post = typeof conversationId === "string" ? { channel: conversationId, text: message } : message;
28
35
 
29
36
  if (verbose) {
30
- console.log(`posting to slack conversation ${conversationId}:`, JSON.stringify(post, null, 2));
37
+ console.log(`posting to slack:`, JSON.stringify(post, null, 2));
31
38
  }
32
39
 
33
- await client.chat.postMessage({
34
- channel: conversationId,
35
- ...post,
36
- });
40
+ await client.chat.postMessage(post);
37
41
  } catch (error) {
38
42
  console.error("failed to post slack message", error);
39
43
 
@@ -42,3 +46,5 @@ async function postMessageToConversation({
42
46
  }
43
47
 
44
48
  export { postMessageToConversation };
49
+
50
+ export type { ChatPostMessageArguments };
@@ -1,99 +0,0 @@
1
- export type OpsgeniePriority = "P1" | "P2" | "P3" | "P4" | "P5";
2
- export interface TeamRefById {
3
- id: string;
4
- type: "team";
5
- }
6
- export interface TeamRefByName {
7
- name: string;
8
- type: "team";
9
- }
10
- export type TeamRef = TeamRefById | TeamRefByName;
11
- export interface UserRefById {
12
- id: string;
13
- type: "user";
14
- }
15
- export interface UserRefByUsername {
16
- username: string;
17
- type: "user";
18
- }
19
- export type UserRef = UserRefById | UserRefByUsername;
20
- export interface EscalationRefById {
21
- id: string;
22
- type: "escalation";
23
- }
24
- export interface EscalationRefByName {
25
- name: string;
26
- type: "escalation";
27
- }
28
- export type EscalationRef = EscalationRefById | EscalationRefByName;
29
- export interface ScheduleRefById {
30
- id: string;
31
- type: "schedule";
32
- }
33
- export interface ScheduleRefByName {
34
- name: string;
35
- type: "schedule";
36
- }
37
- export type ScheduleRef = ScheduleRefById | ScheduleRefByName;
38
- export type ResponderRef = TeamRef | UserRef | EscalationRef | ScheduleRef;
39
- export interface VisibleToTeamById {
40
- id: string;
41
- type: "team";
42
- }
43
- export interface VisibleToTeamByName {
44
- name: string;
45
- type: "team";
46
- }
47
- export type VisibleToTeam = VisibleToTeamById | VisibleToTeamByName;
48
- export interface VisibleToUserById {
49
- id: string;
50
- type: "user";
51
- }
52
- export interface VisibleToUserByUsername {
53
- username: string;
54
- type: "user";
55
- }
56
- export type VisibleToUser = VisibleToUserById | VisibleToUserByUsername;
57
- export type VisibleToRef = VisibleToTeam | VisibleToUser;
58
- export interface CreateAlertRequest {
59
- message: string;
60
- alias?: string;
61
- description?: string;
62
- responders?: ResponderRef[];
63
- visibleTo?: VisibleToRef[];
64
- actions?: string[];
65
- tags?: string[];
66
- details?: Record<string, string>;
67
- entity?: string;
68
- source?: string;
69
- priority?: OpsgeniePriority;
70
- user?: string;
71
- note?: string;
72
- }
73
- export interface OpsgenieAcceptedResponse {
74
- result: string;
75
- took: number;
76
- requestId: string;
77
- }
78
- export interface OpsgenieRequestStatusData {
79
- success: boolean;
80
- action: string;
81
- processedAt: string;
82
- integrationId: string;
83
- isSuccess: boolean;
84
- status: string;
85
- alertId: string;
86
- alias: string;
87
- }
88
- export interface OpsgenieRequestStatusResponse extends OpsgenieAcceptedResponse {
89
- data: OpsgenieRequestStatusData;
90
- }
91
- export type OpsgenieResponse = OpsgenieAcceptedResponse | OpsgenieRequestStatusResponse;
92
- export interface OpsgenieErrorResponse {
93
- message?: string;
94
- took?: number;
95
- requestId?: string;
96
- errors?: unknown;
97
- status?: number | string;
98
- }
99
- export declare function postGenieMessage(body: CreateAlertRequest, apiKey?: string, verbose?: boolean): Promise<OpsgenieResponse>;
package/dist/opsgenie.js DELETED
@@ -1,43 +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 json = await response.json();
28
- if (verbose) {
29
- console.log("Result of API call to Opsgenie...", json);
30
- }
31
- if ("result" in json) {
32
- return json;
33
- }
34
- console.error("Error response from Opsgenie API", json);
35
- throw new Error(json.message || "Unknown error from Opsgenie API");
36
- } catch (error) {
37
- console.error("Failed to make opsgenie API call", error);
38
- throw error;
39
- }
40
- }
41
- export {
42
- postGenieMessage
43
- };
package/src/opsgenie.ts DELETED
@@ -1,176 +0,0 @@
1
- import md5 from "md5";
2
-
3
- // ---- Request Types (Create Alert) ----
4
- // See: https://docs.opsgenie.com/docs/alert-api#create-alert
5
-
6
- export type OpsgeniePriority = "P1" | "P2" | "P3" | "P4" | "P5";
7
-
8
- export interface TeamRefById {
9
- id: string;
10
- type: "team";
11
- }
12
- export interface TeamRefByName {
13
- name: string;
14
- type: "team";
15
- }
16
- export type TeamRef = TeamRefById | TeamRefByName;
17
-
18
- export interface UserRefById {
19
- id: string;
20
- type: "user";
21
- }
22
- export interface UserRefByUsername {
23
- username: string;
24
- type: "user";
25
- }
26
- export type UserRef = UserRefById | UserRefByUsername;
27
-
28
- export interface EscalationRefById {
29
- id: string;
30
- type: "escalation";
31
- }
32
- export interface EscalationRefByName {
33
- name: string;
34
- type: "escalation";
35
- }
36
- export type EscalationRef = EscalationRefById | EscalationRefByName;
37
-
38
- export interface ScheduleRefById {
39
- id: string;
40
- type: "schedule";
41
- }
42
- export interface ScheduleRefByName {
43
- name: string;
44
- type: "schedule";
45
- }
46
- export type ScheduleRef = ScheduleRefById | ScheduleRefByName;
47
-
48
- export type ResponderRef = TeamRef | UserRef | EscalationRef | ScheduleRef;
49
-
50
- export interface VisibleToTeamById {
51
- id: string;
52
- type: "team";
53
- }
54
- export interface VisibleToTeamByName {
55
- name: string;
56
- type: "team";
57
- }
58
- export type VisibleToTeam = VisibleToTeamById | VisibleToTeamByName;
59
- export interface VisibleToUserById {
60
- id: string;
61
- type: "user";
62
- }
63
- export interface VisibleToUserByUsername {
64
- username: string;
65
- type: "user";
66
- }
67
- export type VisibleToUser = VisibleToUserById | VisibleToUserByUsername;
68
- export type VisibleToRef = VisibleToTeam | VisibleToUser;
69
-
70
- export interface CreateAlertRequest {
71
- message: string; // required
72
- alias?: string;
73
- description?: string;
74
- responders?: ResponderRef[];
75
- visibleTo?: VisibleToRef[];
76
- actions?: string[]; // up to 10
77
- tags?: string[]; // up to 20
78
- details?: Record<string, string>;
79
- entity?: string;
80
- source?: string;
81
- priority?: OpsgeniePriority; // default P3
82
- user?: string; // display name of request owner
83
- note?: string; // additional note added while creating
84
- }
85
-
86
- // ---- Generic Async Request Response (202 Accepted) ----
87
- // Many Opsgenie alert mutation endpoints return only: { result, took, requestId }
88
- export interface OpsgenieAcceptedResponse {
89
- result: string; // "Request will be processed"
90
- took: number;
91
- requestId: string;
92
- }
93
-
94
- // ---- Request Status (polling) Response ----
95
- // When querying request status we receive a "data" envelope with success info.
96
- export interface OpsgenieRequestStatusData {
97
- success: boolean;
98
- action: string; // e.g. Create, Acknowledge, etc.
99
- processedAt: string; // ISO timestamp
100
- integrationId: string;
101
- isSuccess: boolean;
102
- status: string; // human readable status e.g. "Created alert"
103
- alertId: string; // may be empty string when failed
104
- alias: string; // may be empty when failed
105
- }
106
-
107
- export interface OpsgenieRequestStatusResponse extends OpsgenieAcceptedResponse {
108
- data: OpsgenieRequestStatusData;
109
- }
110
-
111
- // Some endpoints (create alert) return OpsgenieAcceptedResponse immediately, so our
112
- // function currently returns whatever JSON body shape is present. We model the union.
113
- export type OpsgenieResponse = OpsgenieAcceptedResponse | OpsgenieRequestStatusResponse;
114
-
115
- // ---- Error Shape (from Opsgenie docs/experience) ----
116
- // Keep loose to not block callers; refine if needed later.
117
- export interface OpsgenieErrorResponse {
118
- message?: string;
119
- took?: number;
120
- requestId?: string;
121
- errors?: unknown;
122
- status?: number | string;
123
- }
124
-
125
- function getGenieKey(key?: string) {
126
- return key || process.env["SKYNET_OPSGENIE_API_KEY"];
127
- }
128
-
129
- function getGenieEndPoint() {
130
- return process.env["SKYNET_OPSGENIE_END_POINT"] || "https://api.opsgenie.com/v2/alerts";
131
- }
132
-
133
- export async function postGenieMessage(
134
- body: CreateAlertRequest,
135
- apiKey?: string,
136
- verbose?: boolean,
137
- ): Promise<OpsgenieResponse> {
138
- try {
139
- const genieKey = apiKey || getGenieKey();
140
- const genieEndPoint = getGenieEndPoint();
141
-
142
- // Prevents duplicate alerts (See Opsgenie doc about alias)
143
- if (!body.alias) {
144
- body.alias = md5(body.message);
145
- }
146
-
147
- if (verbose) {
148
- console.log(`Making API call to Opsgenie`, JSON.stringify(body, null, 2));
149
- }
150
-
151
- // Makes the call using fetch and ENV variables
152
- const response = await fetch(genieEndPoint, {
153
- method: "POST",
154
- headers: {
155
- "Content-Type": "application/json",
156
- Authorization: `GenieKey ${genieKey}`,
157
- },
158
- body: JSON.stringify(body),
159
- });
160
-
161
- const json = (await response.json()) as OpsgenieResponse | OpsgenieErrorResponse;
162
- if (verbose) {
163
- console.log("Result of API call to Opsgenie...", json);
164
- }
165
-
166
- if ("result" in json) {
167
- return json;
168
- }
169
-
170
- console.error("Error response from Opsgenie API", json);
171
- throw new Error(json.message || 'Unknown error from Opsgenie API');
172
- } catch (error) {
173
- console.error("Failed to make opsgenie API call", error);
174
- throw error;
175
- }
176
- }