@certik/skynet 0.10.6 → 0.10.7
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/.editorconfig +5 -5
- package/.eslintrc.js +13 -13
- package/.prettierrc.js +3 -3
- package/CHANGELOG.md +372 -372
- package/README.md +23 -23
- package/abi.js +353 -353
- package/ably.js +29 -0
- package/address.js +18 -18
- package/api.js +105 -105
- package/app.js +709 -709
- package/availability.js +58 -58
- package/block.js +83 -83
- package/cli.js +53 -53
- package/const.js +92 -92
- package/deploy.js +676 -676
- package/dynamodb.js +444 -444
- package/env.js +90 -90
- package/examples/api +73 -73
- package/examples/consumer +47 -47
- package/examples/indexer +65 -65
- package/examples/mode-indexer +82 -82
- package/examples/producer +80 -80
- package/indexer.js +595 -595
- package/inquiry.js +14 -14
- package/kafka.js +443 -443
- package/labelling.js +90 -90
- package/log.js +29 -29
- package/metric.js +65 -65
- package/monitor.js +191 -191
- package/opsgenie.js +55 -55
- package/package.json +37 -35
- package/price.js +48 -48
- package/primitive.js +77 -77
- package/proxy.js +157 -157
- package/rateLimit.js +21 -21
- package/s3.js +122 -122
- package/scan.js +74 -74
- package/selector.js +53 -53
- package/slack.js +87 -87
- package/snowflake.js +36 -36
- package/sqs.js +12 -12
- package/token.js +46 -46
- package/transaction.js +41 -41
- package/util.js +67 -67
- package/web3.js +117 -117
package/ably.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const Ably = require("ably");
|
|
2
|
+
const Bottleneck = require("bottleneck/es5");
|
|
3
|
+
const { ensureAndGet } = require("./env");
|
|
4
|
+
|
|
5
|
+
const ably = new Ably.Realtime(ensureAndGet("ABLY_ROOT_API_KEY"));
|
|
6
|
+
ably.connection.on("connected", () => {
|
|
7
|
+
console.log("ably connection successful");
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
async function publishMessage(channel, messageName, messageData) {
|
|
11
|
+
const channelObj = ably.channels.get(channel);
|
|
12
|
+
|
|
13
|
+
const messageDataJson = JSON.stringify(messageData);
|
|
14
|
+
|
|
15
|
+
try {
|
|
16
|
+
await channelObj.publish(messageName, messageDataJson);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
console.error("error publishing to ably: ", error);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const rateLimitedPublishMessage = new Bottleneck({
|
|
23
|
+
minTime: 1000 / 50,
|
|
24
|
+
}).wrap(publishMessage);
|
|
25
|
+
|
|
26
|
+
module.exports = {
|
|
27
|
+
publishMessage,
|
|
28
|
+
rateLimitedPublishMessage,
|
|
29
|
+
};
|
package/address.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
function parseAddress(address) {
|
|
2
|
-
const parts = address.split(":");
|
|
3
|
-
|
|
4
|
-
if (parts.length === 2) {
|
|
5
|
-
return [parts[0], parts[1].toLowerCase()];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return ["eth", address.toLowerCase()];
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
function composeAddress(protocol, addr) {
|
|
12
|
-
return `${protocol}:${addr}`;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
module.exports = {
|
|
16
|
-
parseAddress,
|
|
17
|
-
composeAddress
|
|
18
|
-
};
|
|
1
|
+
function parseAddress(address) {
|
|
2
|
+
const parts = address.split(":");
|
|
3
|
+
|
|
4
|
+
if (parts.length === 2) {
|
|
5
|
+
return [parts[0], parts[1].toLowerCase()];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return ["eth", address.toLowerCase()];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function composeAddress(protocol, addr) {
|
|
12
|
+
return `${protocol}:${addr}`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
parseAddress,
|
|
17
|
+
composeAddress
|
|
18
|
+
};
|
package/api.js
CHANGED
|
@@ -1,105 +1,105 @@
|
|
|
1
|
-
const express = require("express");
|
|
2
|
-
const meow = require("meow");
|
|
3
|
-
const { getSelectorFlags, getSelectorDesc } = require("./selector");
|
|
4
|
-
const { isProduction } = require("./env");
|
|
5
|
-
|
|
6
|
-
const apiKeyMiddleware = (key) => {
|
|
7
|
-
async function requireAPIKey(req, res, next) {
|
|
8
|
-
try {
|
|
9
|
-
const apiKey = req.get("x-api-key");
|
|
10
|
-
|
|
11
|
-
if (!apiKey) {
|
|
12
|
-
console.log("request without api key");
|
|
13
|
-
|
|
14
|
-
res.status(400).send("require x-api-key header");
|
|
15
|
-
|
|
16
|
-
return;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
if (apiKey !== key) {
|
|
20
|
-
console.log("request has an invalid api key");
|
|
21
|
-
|
|
22
|
-
res.status(400).send("invalid api key");
|
|
23
|
-
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
next();
|
|
28
|
-
} catch (err) {
|
|
29
|
-
console.log("check api key error", err);
|
|
30
|
-
|
|
31
|
-
res.status(500).send("internal error");
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return requireAPIKey;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
function startApiApp({ binaryName, name, selector = {}, routes, serve }) {
|
|
39
|
-
const app = express();
|
|
40
|
-
app.use(express.json());
|
|
41
|
-
|
|
42
|
-
const cli = meow(
|
|
43
|
-
`
|
|
44
|
-
Usage
|
|
45
|
-
$ ${binaryName} <options>
|
|
46
|
-
|
|
47
|
-
Options
|
|
48
|
-
${getSelectorDesc(selector)}
|
|
49
|
-
--verbose Output debug messages
|
|
50
|
-
`,
|
|
51
|
-
{
|
|
52
|
-
description: false,
|
|
53
|
-
version: false,
|
|
54
|
-
flags: {
|
|
55
|
-
...getSelectorFlags(selector),
|
|
56
|
-
verbose: {
|
|
57
|
-
type: "boolean",
|
|
58
|
-
default: false,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
}
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
const { verbose, ...selectorFlags } = cli.flags;
|
|
65
|
-
|
|
66
|
-
// for health check
|
|
67
|
-
app.get("/", (req, res) => {
|
|
68
|
-
res.send("ok");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
for (const route of routes) {
|
|
72
|
-
const method = route.method ? route.method.toLowerCase() : "get";
|
|
73
|
-
const middlewares = route.middlewares || [];
|
|
74
|
-
|
|
75
|
-
if (route.protected) {
|
|
76
|
-
middlewares.push(apiKeyMiddleware(serve.apiKey));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (app[method]) {
|
|
80
|
-
if (verbose) {
|
|
81
|
-
console.log(`registering ${method} ${route.path}`);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
app[method](route.path, ...middlewares, async (req, res) => {
|
|
85
|
-
try {
|
|
86
|
-
await route.handler({ req, res, ...selectorFlags });
|
|
87
|
-
} catch (routeErr) {
|
|
88
|
-
console.log("caught route err", routeErr);
|
|
89
|
-
|
|
90
|
-
res.status(500).send(`internal server error: ${routeErr.message}`);
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
app.listen(serve.port, () => {
|
|
97
|
-
if (isProduction()) {
|
|
98
|
-
console.log(`${name} listening at https://api.certik-skynet.com/${serve.prefix}`);
|
|
99
|
-
} else {
|
|
100
|
-
console.log(`${name} listening at http://localhost:${serve.port}`);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
module.exports = { startApiApp };
|
|
1
|
+
const express = require("express");
|
|
2
|
+
const meow = require("meow");
|
|
3
|
+
const { getSelectorFlags, getSelectorDesc } = require("./selector");
|
|
4
|
+
const { isProduction } = require("./env");
|
|
5
|
+
|
|
6
|
+
const apiKeyMiddleware = (key) => {
|
|
7
|
+
async function requireAPIKey(req, res, next) {
|
|
8
|
+
try {
|
|
9
|
+
const apiKey = req.get("x-api-key");
|
|
10
|
+
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
console.log("request without api key");
|
|
13
|
+
|
|
14
|
+
res.status(400).send("require x-api-key header");
|
|
15
|
+
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (apiKey !== key) {
|
|
20
|
+
console.log("request has an invalid api key");
|
|
21
|
+
|
|
22
|
+
res.status(400).send("invalid api key");
|
|
23
|
+
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
next();
|
|
28
|
+
} catch (err) {
|
|
29
|
+
console.log("check api key error", err);
|
|
30
|
+
|
|
31
|
+
res.status(500).send("internal error");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return requireAPIKey;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
function startApiApp({ binaryName, name, selector = {}, routes, serve }) {
|
|
39
|
+
const app = express();
|
|
40
|
+
app.use(express.json());
|
|
41
|
+
|
|
42
|
+
const cli = meow(
|
|
43
|
+
`
|
|
44
|
+
Usage
|
|
45
|
+
$ ${binaryName} <options>
|
|
46
|
+
|
|
47
|
+
Options
|
|
48
|
+
${getSelectorDesc(selector)}
|
|
49
|
+
--verbose Output debug messages
|
|
50
|
+
`,
|
|
51
|
+
{
|
|
52
|
+
description: false,
|
|
53
|
+
version: false,
|
|
54
|
+
flags: {
|
|
55
|
+
...getSelectorFlags(selector),
|
|
56
|
+
verbose: {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
default: false,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const { verbose, ...selectorFlags } = cli.flags;
|
|
65
|
+
|
|
66
|
+
// for health check
|
|
67
|
+
app.get("/", (req, res) => {
|
|
68
|
+
res.send("ok");
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
for (const route of routes) {
|
|
72
|
+
const method = route.method ? route.method.toLowerCase() : "get";
|
|
73
|
+
const middlewares = route.middlewares || [];
|
|
74
|
+
|
|
75
|
+
if (route.protected) {
|
|
76
|
+
middlewares.push(apiKeyMiddleware(serve.apiKey));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (app[method]) {
|
|
80
|
+
if (verbose) {
|
|
81
|
+
console.log(`registering ${method} ${route.path}`);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
app[method](route.path, ...middlewares, async (req, res) => {
|
|
85
|
+
try {
|
|
86
|
+
await route.handler({ req, res, ...selectorFlags });
|
|
87
|
+
} catch (routeErr) {
|
|
88
|
+
console.log("caught route err", routeErr);
|
|
89
|
+
|
|
90
|
+
res.status(500).send(`internal server error: ${routeErr.message}`);
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
app.listen(serve.port, () => {
|
|
97
|
+
if (isProduction()) {
|
|
98
|
+
console.log(`${name} listening at https://api.certik-skynet.com/${serve.prefix}`);
|
|
99
|
+
} else {
|
|
100
|
+
console.log(`${name} listening at http://localhost:${serve.port}`);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
module.exports = { startApiApp };
|