@certik/skynet 0.10.20 → 0.10.23

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,34 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.10.23
4
+
5
+ - Fixed nomad API log elapse time
6
+
7
+ ## 0.10.22
8
+
9
+ - Fixed nomad API log elapse time
10
+ - Fixed missing abort controller for proxy lib
11
+
12
+ ## 0.10.21
13
+
14
+ - Enabled more customizations for indexer selector support, check https://github.com/sindresorhus/meow for available config options, an example
15
+
16
+ ```
17
+ selectors: {
18
+ "onlyProject": {
19
+ type: "string",
20
+ alias: "only-project",
21
+ default: null,
22
+ isRequired: false
23
+ },
24
+
25
+ "protocol": {
26
+ type: "string",
27
+ isRequired: true
28
+ }
29
+ }
30
+ ```
31
+
3
32
  ## 0.10.20
4
33
 
5
34
  - Used shorter lock ttl for api and producer
package/api.js CHANGED
@@ -5,10 +5,18 @@ const { isProduction } = require("./env");
5
5
  const { useLock } = require("./distributed-lock");
6
6
  const { inline } = require("./log");
7
7
 
8
- async function logMiddleware(req, res, next) {
8
+ async function logStartMiddleware(req, res, next) {
9
9
  const start = new Date();
10
+
11
+ res.set("x-requested-at", start.toISOString());
12
+
10
13
  next();
14
+ }
15
+
16
+ async function logEndMiddleware(req, res, next) {
17
+ const start = new Date(res.get("x-requested-at"));
11
18
  const end = new Date();
19
+
12
20
  const logInfo = {
13
21
  start,
14
22
  end,
@@ -21,6 +29,8 @@ async function logMiddleware(req, res, next) {
21
29
  logInfo.errorMessage = res.statusMessage;
22
30
  }
23
31
  inline.log(JSON.stringify(logInfo));
32
+
33
+ next();
24
34
  }
25
35
 
26
36
  const apiKeyMiddleware = (key) => {
@@ -94,10 +104,6 @@ ${getSelectorDesc(selector)}
94
104
  const method = route.method ? route.method.toLowerCase() : "get";
95
105
  const middlewares = route.middlewares || [];
96
106
 
97
- if (route.log !== false) {
98
- middlewares.unshift(logMiddleware);
99
- }
100
-
101
107
  if (route.protected) {
102
108
  middlewares.unshift(apiKeyMiddleware(serve.apiKey));
103
109
  }
@@ -107,21 +113,29 @@ ${getSelectorDesc(selector)}
107
113
  inline.log(`registering ${method} ${route.path}`);
108
114
  }
109
115
 
110
- app[method](route.path, ...middlewares, async (req, res) => {
111
- try {
112
- await route.handler({ req, res, ...selectorFlags });
113
- } catch (routeErr) {
114
- inline.log("caught route err", routeErr);
116
+ app[method](
117
+ route.path,
118
+ logStartMiddleware,
119
+ ...middlewares,
120
+ async (req, res, next) => {
121
+ try {
122
+ await route.handler({ req, res, ...selectorFlags });
123
+ } catch (routeErr) {
124
+ inline.log("caught route err", routeErr);
115
125
 
116
- res.status(500).send(`internal server error: ${routeErr.message}`);
117
- }
118
- });
126
+ res.status(500).send(`internal server error: ${routeErr.message}`);
127
+ }
128
+
129
+ next();
130
+ },
131
+ logEndMiddleware
132
+ );
119
133
  }
120
134
  }
121
135
 
122
136
  app.listen(serve.port, () => {
123
137
  if (isProduction()) {
124
- inline.log(`${name} listening at https://api.certik-skynet.com/${serve.prefix}`);
138
+ inline.log(`${name} listening at https://api.certik-skynet.com${serve.prefix}`);
125
139
  } else {
126
140
  inline.log(`${name} listening at http://localhost:${serve.port}`);
127
141
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@certik/skynet",
3
- "version": "0.10.20",
3
+ "version": "0.10.23",
4
4
  "description": "Skynet Shared JS library",
5
5
  "main": "index.js",
6
6
  "author": "CertiK Engineering",
@@ -14,6 +14,7 @@
14
14
  "dependencies": {
15
15
  "@slack/web-api": "^6.4.0",
16
16
  "ably": "^1.2.22",
17
+ "abort-controller": "^3.0.0",
17
18
  "aws-sdk": "^2.1164.0",
18
19
  "bottleneck": "^2.19.5",
19
20
  "chalk": "^4.1.2",
package/selector.js CHANGED
@@ -17,18 +17,16 @@ function getSelectorDesc(selector) {
17
17
  .join("\n");
18
18
  }
19
19
 
20
+ // check https://github.com/sindresorhus/meow for selector config options
20
21
  function getSelectorFlags(selector) {
21
22
  return Object.keys(selector).reduce((acc, name) => {
22
23
  const flag = {
23
24
  type: selector[name].type || "string",
24
- isRequired: true,
25
+ ...selector[name]
25
26
  };
26
27
 
27
- if (selector[name].default) {
28
- flag.default = selector[name].default;
29
- }
30
-
31
- if (!selector[name].optional) {
28
+ // by default to be required
29
+ if (!selector[name].optional && selector[name].isRequired !== false) {
32
30
  flag.isRequired = true;
33
31
  }
34
32