@certik/skynet 0.22.1 → 0.22.3

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/build.ts +23 -0
  3. package/dist/abi.d.ts +1 -2
  4. package/dist/abi.js +569 -563
  5. package/dist/address.d.ts +0 -1
  6. package/dist/address.js +22 -21
  7. package/dist/api.d.ts +0 -1
  8. package/dist/api.js +235 -120
  9. package/dist/app.d.ts +1 -2
  10. package/dist/app.js +2030 -276
  11. package/dist/availability.d.ts +0 -1
  12. package/dist/availability.js +126 -56
  13. package/dist/cli.d.ts +0 -1
  14. package/dist/cli.js +28 -24
  15. package/dist/const.d.ts +0 -1
  16. package/dist/const.js +153 -132
  17. package/dist/databricks.d.ts +0 -1
  18. package/dist/databricks.js +198 -58
  19. package/dist/date.d.ts +0 -1
  20. package/dist/date.js +48 -21
  21. package/dist/deploy.d.ts +0 -1
  22. package/dist/deploy.js +427 -292
  23. package/dist/dynamodb.d.ts +3 -4
  24. package/dist/dynamodb.js +432 -281
  25. package/dist/env.d.ts +2 -3
  26. package/dist/env.js +16 -9
  27. package/dist/graphql.d.ts +0 -1
  28. package/dist/graphql.js +26 -23
  29. package/dist/indexer.d.ts +0 -1
  30. package/dist/indexer.js +1050 -441
  31. package/dist/log.d.ts +0 -1
  32. package/dist/log.js +53 -52
  33. package/dist/object-hash.d.ts +0 -1
  34. package/dist/object-hash.js +49 -59
  35. package/dist/opsgenie.d.ts +97 -19
  36. package/dist/opsgenie.js +35 -30
  37. package/dist/por.d.ts +0 -1
  38. package/dist/por.js +113 -123
  39. package/dist/s3.d.ts +7 -8
  40. package/dist/s3.js +103 -91
  41. package/dist/search.d.ts +0 -1
  42. package/dist/search.js +100 -25
  43. package/dist/selector.d.ts +0 -1
  44. package/dist/selector.js +34 -38
  45. package/dist/slack.d.ts +0 -1
  46. package/dist/slack.js +27 -21
  47. package/dist/util.d.ts +0 -1
  48. package/dist/util.js +21 -20
  49. package/examples/api.ts +1 -1
  50. package/examples/indexer.ts +1 -1
  51. package/examples/mode-indexer.ts +1 -1
  52. package/package.json +4 -3
  53. package/{graphql.ts → src/graphql.ts} +1 -1
  54. package/src/opsgenie.ts +176 -0
  55. package/tsconfig.build.json +2 -5
  56. package/tsconfig.json +11 -20
  57. package/dist/abi.d.ts.map +0 -1
  58. package/dist/address.d.ts.map +0 -1
  59. package/dist/api.d.ts.map +0 -1
  60. package/dist/app.d.ts.map +0 -1
  61. package/dist/availability.d.ts.map +0 -1
  62. package/dist/cli.d.ts.map +0 -1
  63. package/dist/const.d.ts.map +0 -1
  64. package/dist/databricks.d.ts.map +0 -1
  65. package/dist/date.d.ts.map +0 -1
  66. package/dist/deploy.d.ts.map +0 -1
  67. package/dist/dynamodb.d.ts.map +0 -1
  68. package/dist/env.d.ts.map +0 -1
  69. package/dist/graphql.d.ts.map +0 -1
  70. package/dist/indexer.d.ts.map +0 -1
  71. package/dist/log.d.ts.map +0 -1
  72. package/dist/object-hash.d.ts.map +0 -1
  73. package/dist/opsgenie.d.ts.map +0 -1
  74. package/dist/por.d.ts.map +0 -1
  75. package/dist/s3.d.ts.map +0 -1
  76. package/dist/search.d.ts.map +0 -1
  77. package/dist/selector.d.ts.map +0 -1
  78. package/dist/slack.d.ts.map +0 -1
  79. package/dist/util.d.ts.map +0 -1
  80. package/opsgenie.ts +0 -69
  81. /package/{abi.ts → src/abi.ts} +0 -0
  82. /package/{address.ts → src/address.ts} +0 -0
  83. /package/{api.ts → src/api.ts} +0 -0
  84. /package/{app.ts → src/app.ts} +0 -0
  85. /package/{availability.ts → src/availability.ts} +0 -0
  86. /package/{cli.ts → src/cli.ts} +0 -0
  87. /package/{const.ts → src/const.ts} +0 -0
  88. /package/{databricks.ts → src/databricks.ts} +0 -0
  89. /package/{date.ts → src/date.ts} +0 -0
  90. /package/{deploy.ts → src/deploy.ts} +0 -0
  91. /package/{dynamodb.ts → src/dynamodb.ts} +0 -0
  92. /package/{env.ts → src/env.ts} +0 -0
  93. /package/{indexer.ts → src/indexer.ts} +0 -0
  94. /package/{log.ts → src/log.ts} +0 -0
  95. /package/{object-hash.ts → src/object-hash.ts} +0 -0
  96. /package/{por.ts → src/por.ts} +0 -0
  97. /package/{s3.ts → src/s3.ts} +0 -0
  98. /package/{search.ts → src/search.ts} +0 -0
  99. /package/{selector.ts → src/selector.ts} +0 -0
  100. /package/{slack.ts → src/slack.ts} +0 -0
  101. /package/{util.ts → src/util.ts} +0 -0
package/dist/log.d.ts CHANGED
@@ -11,4 +11,3 @@ declare const logger: {
11
11
  error: (...args: unknown[]) => void;
12
12
  };
13
13
  export { print, getLine, inline, logger };
14
- //# sourceMappingURL=log.d.ts.map
package/dist/log.js CHANGED
@@ -1,62 +1,63 @@
1
+ // src/log.ts
1
2
  function isObject(a) {
2
- return !!a && a.constructor === Object;
3
+ return !!a && a.constructor === Object;
3
4
  }
4
5
  function print(o) {
5
- if (Array.isArray(o)) {
6
- return `[${o.map(print).join(", ")}]`;
7
- }
8
- if (isObject(o)) {
9
- return `{${Object.keys(o)
10
- .map((k) => `${k}: ${o[k]}`)
11
- .join(", ")}}`;
12
- }
13
- return `${o}`;
6
+ if (Array.isArray(o)) {
7
+ return `[${o.map(print).join(", ")}]`;
8
+ }
9
+ if (isObject(o)) {
10
+ return `{${Object.keys(o).map((k) => `${k}: ${o[k]}`).join(", ")}}`;
11
+ }
12
+ return `${o}`;
14
13
  }
15
14
  function getLine(params) {
16
- let line = "";
17
- // Convert to string and filter out newline to tabs (AWS Athena)
18
- for (let i = 0, l = params.length; i < l; i++) {
19
- // Certain objects don't get converted
20
- // Note using JSON.stringfy may be too slow for large objects
21
- line += `${print(params[i])} `.replace(/\n/gm, "\t");
22
- }
23
- return line.trim();
15
+ let line = "";
16
+ for (let i = 0, l = params.length;i < l; i++) {
17
+ line += `${print(params[i])} `.replace(/\n/gm, "\t");
18
+ }
19
+ return line.trim();
24
20
  }
25
21
  function timestamp() {
26
- return new Date().toISOString();
22
+ return new Date().toISOString();
27
23
  }
28
- const inline = {
29
- debug: function (...args) {
30
- if (process.env.NODE_ENV === "development") {
31
- console.log(`${timestamp()} ${getLine(args)}`);
32
- }
33
- },
34
- log: function (...args) {
35
- if (process.env.NODE_ENV !== "test") {
36
- console.log(`${timestamp()} ${getLine(args)}`);
37
- }
38
- },
39
- error: function (...args) {
40
- if (process.env.NODE_ENV !== "test") {
41
- console.error(`${timestamp()} ${getLine(args)}`);
42
- }
43
- },
24
+ var inline = {
25
+ debug: function(...args) {
26
+ if (true) {
27
+ console.log(`${timestamp()} ${getLine(args)}`);
28
+ }
29
+ },
30
+ log: function(...args) {
31
+ if (true) {
32
+ console.log(`${timestamp()} ${getLine(args)}`);
33
+ }
34
+ },
35
+ error: function(...args) {
36
+ if (true) {
37
+ console.error(`${timestamp()} ${getLine(args)}`);
38
+ }
39
+ }
40
+ };
41
+ var logger = {
42
+ debug: function(...args) {
43
+ if (true) {
44
+ console.log(`[${timestamp()}]`, ...args);
45
+ }
46
+ },
47
+ log: function(...args) {
48
+ if (true) {
49
+ console.log(`[${timestamp()}]`, ...args);
50
+ }
51
+ },
52
+ error: function(...args) {
53
+ if (true) {
54
+ console.error(`[${timestamp()}]`, ...args);
55
+ }
56
+ }
44
57
  };
45
- const logger = {
46
- debug: function (...args) {
47
- if (process.env.NODE_ENV === "development") {
48
- console.log(`[${timestamp()}]`, ...args);
49
- }
50
- },
51
- log: function (...args) {
52
- if (process.env.NODE_ENV !== "test") {
53
- console.log(`[${timestamp()}]`, ...args);
54
- }
55
- },
56
- error: function (...args) {
57
- if (process.env.NODE_ENV !== "test") {
58
- console.error(`[${timestamp()}]`, ...args);
59
- }
60
- },
58
+ export {
59
+ print,
60
+ logger,
61
+ inline,
62
+ getLine
61
63
  };
62
- export { print, getLine, inline, logger };
@@ -1,2 +1 @@
1
1
  export declare function getHash(obj: unknown): string;
2
- //# sourceMappingURL=object-hash.d.ts.map
@@ -1,71 +1,61 @@
1
+ // src/object-hash.ts
1
2
  import xh from "@node-rs/xxhash";
2
- export function getHash(obj) {
3
- const xxh3 = xh.xxh3.Xxh3.withSeed();
4
- hash(obj, xxh3);
5
- return xxh3.digest().toString(16);
3
+ function getHash(obj) {
4
+ const xxh3 = xh.xxh3.Xxh3.withSeed();
5
+ hash(obj, xxh3);
6
+ return xxh3.digest().toString(16);
6
7
  }
7
8
  function hash(obj, xxh3) {
8
- if (obj === null) {
9
- xxh3.update("null");
10
- }
11
- else if (obj === undefined) {
12
- xxh3.update("undefined");
13
- }
14
- else if (typeof obj === "string") {
15
- xxh3.update(obj);
16
- }
17
- else if (typeof obj === "number") {
18
- xxh3.update(obj.toString());
19
- }
20
- else if (typeof obj === "boolean") {
21
- xxh3.update(obj.toString());
22
- }
23
- else if (typeof obj === "bigint") {
24
- xxh3.update(obj.toString());
25
- }
26
- else if (obj instanceof Date) {
27
- xxh3.update(obj.toISOString());
28
- }
29
- else if (Array.isArray(obj)) {
30
- arrayHash(obj, xxh3);
31
- }
32
- else if (obj instanceof Set) {
33
- setHash(obj, xxh3);
34
- }
35
- else if (obj instanceof Map) {
36
- mapHash(obj, xxh3);
37
- }
38
- else if (typeof obj === "object") {
39
- objectHash(obj, xxh3);
40
- }
41
- else {
42
- throw new Error(`Unsupported type: ${obj}`);
43
- }
9
+ if (obj === null) {
10
+ xxh3.update("null");
11
+ } else if (obj === undefined) {
12
+ xxh3.update("undefined");
13
+ } else if (typeof obj === "string") {
14
+ xxh3.update(obj);
15
+ } else if (typeof obj === "number") {
16
+ xxh3.update(obj.toString());
17
+ } else if (typeof obj === "boolean") {
18
+ xxh3.update(obj.toString());
19
+ } else if (typeof obj === "bigint") {
20
+ xxh3.update(obj.toString());
21
+ } else if (obj instanceof Date) {
22
+ xxh3.update(obj.toISOString());
23
+ } else if (Array.isArray(obj)) {
24
+ arrayHash(obj, xxh3);
25
+ } else if (obj instanceof Set) {
26
+ setHash(obj, xxh3);
27
+ } else if (obj instanceof Map) {
28
+ mapHash(obj, xxh3);
29
+ } else if (typeof obj === "object") {
30
+ objectHash(obj, xxh3);
31
+ } else {
32
+ throw new Error(`Unsupported type: ${obj}`);
33
+ }
44
34
  }
45
35
  function arrayHash(array, xxh3) {
46
- xxh3.update("[");
47
- for (const obj of array) {
48
- hash(obj, xxh3);
49
- }
50
- xxh3.update("]");
36
+ xxh3.update("[");
37
+ for (const obj of array) {
38
+ hash(obj, xxh3);
39
+ }
40
+ xxh3.update("]");
51
41
  }
52
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
53
42
  function setHash(_set, _xxh3) {
54
- throw new Error("Set hashing not implemented");
43
+ throw new Error("Set hashing not implemented");
55
44
  }
56
45
  function mapHash(map, xxh3) {
57
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
- const array = Array.from(map.entries()).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
59
- for (const [key, value] of array) {
60
- hash(key, xxh3);
61
- hash(value, xxh3);
62
- }
46
+ const array = Array.from(map.entries()).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
47
+ for (const [key, value] of array) {
48
+ hash(key, xxh3);
49
+ hash(value, xxh3);
50
+ }
63
51
  }
64
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
65
52
  function objectHash(obj, xxh3) {
66
- const array = Object.entries(obj).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
67
- for (const [key, value] of array) {
68
- hash(key, xxh3);
69
- hash(value, xxh3);
70
- }
53
+ const array = Object.entries(obj).sort(([aKey], [bKey]) => aKey.localeCompare(bKey));
54
+ for (const [key, value] of array) {
55
+ hash(key, xxh3);
56
+ hash(value, xxh3);
57
+ }
71
58
  }
59
+ export {
60
+ getHash
61
+ };
@@ -1,21 +1,99 @@
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
- };
15
- export declare function postGenieMessage(body: {
16
- alias?: string;
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 {
17
59
  message: string;
60
+ alias?: string;
18
61
  description?: string;
19
- }, apiKey?: string, verbose?: boolean): Promise<OpsgenieResponse>;
20
- export {};
21
- //# sourceMappingURL=opsgenie.d.ts.map
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 CHANGED
@@ -1,38 +1,43 @@
1
+ // src/opsgenie.ts
1
2
  import md5 from "md5";
2
3
  function getGenieKey(key) {
3
- return key || process.env["SKYNET_OPSGENIE_API_KEY"];
4
+ return key || process.env["SKYNET_OPSGENIE_API_KEY"];
4
5
  }
5
6
  function getGenieEndPoint() {
6
- return process.env["SKYNET_OPSGENIE_END_POINT"] || "https://api.opsgenie.com/v2/alerts";
7
+ return process.env["SKYNET_OPSGENIE_END_POINT"] || "https://api.opsgenie.com/v2/alerts";
7
8
  }
8
- export async function postGenieMessage(body, apiKey, verbose) {
9
- try {
10
- const genieKey = apiKey || getGenieKey();
11
- const genieEndPoint = getGenieEndPoint();
12
- // Prevents duplicate alerts (See Opsgenie doc about alias)
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
- // Makes the call using fetch and ENV variables
20
- const response = await fetch(genieEndPoint, {
21
- method: "POST",
22
- headers: {
23
- "Content-Type": "application/json",
24
- Authorization: `GenieKey ${genieKey}`,
25
- },
26
- body: JSON.stringify(body),
27
- });
28
- const result = await response.json();
29
- if (verbose) {
30
- console.log(`Result of API call to Opsgenie... ${result}`);
31
- }
32
- return result;
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);
33
15
  }
34
- catch (error) {
35
- console.error("Failed to make opsgenie API call", error);
36
- throw error;
16
+ if (verbose) {
17
+ console.log(`Making API call to Opsgenie`, JSON.stringify(body, null, 2));
37
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
+ }
38
40
  }
41
+ export {
42
+ postGenieMessage
43
+ };
package/dist/por.d.ts CHANGED
@@ -35,4 +35,3 @@ export declare class MerkleTreePoR {
35
35
  generateProof(userHash: string, token?: string): MerkleProof;
36
36
  static verifyProof(merkleProof: MerkleProof): boolean;
37
37
  }
38
- //# sourceMappingURL=por.d.ts.map