@certik/skynet 0.22.3 → 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/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 };
@@ -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
- }