@lidofinance/next-pages 0.10.0 → 0.11.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/dist/index.cjs +6 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +6 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.cjs
CHANGED
|
@@ -94,16 +94,16 @@ const $f61917c2527290c5$export$9bfcc39f106ad871 = ({ metrics: { prefix: prefix ,
|
|
|
94
94
|
}, {
|
|
95
95
|
chainId: chainId
|
|
96
96
|
}), serverLogger.error);
|
|
97
|
-
var
|
|
98
|
-
res.setHeader("Content-Type", (
|
|
97
|
+
var _requested_headers_get;
|
|
98
|
+
res.setHeader("Content-Type", (_requested_headers_get = requested.headers.get("Content-Type")) !== null && _requested_headers_get !== void 0 ? _requested_headers_get : "application/json");
|
|
99
99
|
res.status(requested.status).send(requested.body);
|
|
100
100
|
} catch (error) {
|
|
101
101
|
if (error instanceof Error) {
|
|
102
|
-
var
|
|
102
|
+
var _error_message;
|
|
103
103
|
// TODO: check if there are errors duplication with iterateUrls
|
|
104
|
-
serverLogger.error((
|
|
105
|
-
var
|
|
106
|
-
res.status(500).json((
|
|
104
|
+
serverLogger.error((_error_message = error.message) !== null && _error_message !== void 0 ? _error_message : $f61917c2527290c5$export$c982278a0ddc4dbe);
|
|
105
|
+
var _error_message1;
|
|
106
|
+
res.status(500).json((_error_message1 = error.message) !== null && _error_message1 !== void 0 ? _error_message1 : $f61917c2527290c5$export$c982278a0ddc4dbe);
|
|
107
107
|
} else res.status(500).json($f61917c2527290c5$export$56a189db5508cdcb);
|
|
108
108
|
}
|
|
109
109
|
};
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;ACEO,MAAM,
|
|
1
|
+
{"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;ACEO,MAAM,4CAAS,CAA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MAAM,IAAI,MAAM,CAAC,uBAAuB,CAAC,EAAC;gBAE5C,IAAI,CAAC,kBAAkB,QAAQ,CAAC,SAAS;oBACvC,kBAAkB,GAAG;oBACrB,MAAM,IAAI,MAAM,CAAC,WAAW,EAAE,OAAO,cAAc,CAAC,EAAC;gBACvD,CAAC;YACH;YAEA,MAAM,YAAY,MAAM,CAAA,GAAA,iCAAU,EAChC,SAAS,CAAC,QAAQ,EAClB,oFAAoF;YACpF,CAAC,MAAQ,SAAS,KAAK;oBAAE,MAAM,IAAI,IAAI;gBAAqB,GAAG;6BAAE;gBAAQ,IACzE,aAAa,KAAK;gBAGU;YAA9B,IAAI,SAAS,CAAC,gBAAgB,CAAA,yBAAA,UAAU,OAAO,CAAC,GAAG,CAAC,6BAAtB,oCAAA,yBAAyC,kBAAkB;YACzF,IAAI,MAAM,CAAC,UAAU,MAAM,EAAE,IAAI,CAAC,UAAU,IAAI;QAClD,EAAE,OAAO,OAAO;YACd,IAAI,iBAAiB,OAAO;oBAEP;gBADnB,+DAA+D;gBAC/D,aAAa,KAAK,CAAC,CAAA,iBAAA,MAAM,OAAO,cAAb,4BAAA,iBAAiB,yCAAyB;oBACxC;gBAArB,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC,CAAA,kBAAA,MAAM,OAAO,cAAb,6BAAA,kBAAiB,yCAAyB;YACjE,OACE,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC;QAEzB;IACF;AACF;;","sources":["packages/next/pages/src/index.ts","packages/next/pages/src/health.ts","packages/next/pages/src/metricsFactory.ts","packages/next/pages/src/rpcFactory.ts"],"sourcesContent":["export * from './health'\nexport * from './metricsFactory'\nexport * from './rpcFactory'\n","import { NextApiRequest, NextApiResponse } from 'next'\n\nexport const health = (_req: NextApiRequest, res: NextApiResponse): void => {\n res.status(200).send({ status: 'ok' })\n}\n","import { NextApiRequest, NextApiResponse } from 'next'\nimport { Registry } from 'prom-client'\n\nexport type MetricsFactoryParameters = {\n registry: Registry\n}\n\nexport const metricsFactory =\n ({ registry }: MetricsFactoryParameters) =>\n async (_req: NextApiRequest, res: NextApiResponse) => {\n const collectedMetrics = await registry.metrics()\n res.send(collectedMetrics)\n }\n","import type { NextApiRequest, NextApiResponse } from 'next'\nimport { Counter, Registry } from 'prom-client'\nimport { TrackedFetchRPC } from '@lidofinance/api-rpc'\nimport { ServerLogger } from '@lidofinance/api-logger'\nimport { FetchRpcInitBody, iterateUrls } from '@lidofinance/rpc'\n\nexport type RpcProviders = Record<string | number, [string, ...string[]]>\n\nexport const DEFAULT_API_ERROR_MESSAGE = 'Something went wrong. Sorry, try again later :('\n\nexport const HEALTHY_RPC_SERVICES_ARE_OVER = 'Healthy RPC services are over!'\n\nexport class UnsupportedChainIdError extends Error {\n constructor(message?: string) {\n super(message || 'Unsupported chainId')\n }\n}\n\nexport class UnsupportedHTTPMethodError extends Error {\n constructor(message?: string) {\n super(message || 'Unsupported HTTP method')\n }\n}\n\nexport type RPCFactoryParams = {\n metrics: {\n prefix: string\n registry: Registry\n }\n providers: RpcProviders\n fetchRPC: TrackedFetchRPC\n serverLogger: ServerLogger\n defaultChain: string | number\n // If we don't specify allowed RPC methods, then we can't use\n // fetchRPC with prometheus, otherwise it will blow up, if someone will send arbitrary\n // methods\n allowedRPCMethods: string[]\n}\n\nexport const rpcFactory = ({\n metrics: { prefix, registry },\n providers,\n fetchRPC,\n serverLogger,\n defaultChain,\n allowedRPCMethods,\n}: RPCFactoryParams) => {\n const rpcRequestBlocked = new Counter({\n name: prefix + 'rpc_service_request_blocked',\n help: 'RPC service request blocked',\n labelNames: [],\n registers: [],\n })\n registry.registerMetric(rpcRequestBlocked)\n\n return async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {\n try {\n // Accept only POST requests\n if (req.method !== 'POST') {\n // We don't care about tracking blocked requests here\n throw new UnsupportedHTTPMethodError()\n }\n\n const chainId = Number(req.query.chainId || defaultChain)\n\n // Allow only chainId of specified chains\n if (providers[chainId] == null) {\n // We don't care about tracking blocked requests here\n throw new UnsupportedChainIdError()\n }\n\n // TODO: consider returning array of validators instead of throwing error right away\n // Check if provided methods are allowed\n for (const { method } of Array.isArray(req.body) ? req.body : [req.body]) {\n if (typeof method !== 'string') {\n throw new Error(`RPC method isn't string`)\n }\n if (!allowedRPCMethods.includes(method)) {\n rpcRequestBlocked.inc()\n throw new Error(`RPC method ${method} isn't allowed`)\n }\n }\n\n const requested = await iterateUrls(\n providers[chainId],\n // TODO: consider adding verification that body is actually matches FetchRpcInitBody\n (url) => fetchRPC(url, { body: req.body as FetchRpcInitBody }, { chainId }),\n serverLogger.error,\n )\n\n res.setHeader('Content-Type', requested.headers.get('Content-Type') ?? 'application/json')\n res.status(requested.status).send(requested.body)\n } catch (error) {\n if (error instanceof Error) {\n // TODO: check if there are errors duplication with iterateUrls\n serverLogger.error(error.message ?? DEFAULT_API_ERROR_MESSAGE)\n res.status(500).json(error.message ?? DEFAULT_API_ERROR_MESSAGE)\n } else {\n res.status(500).json(HEALTHY_RPC_SERVICES_ARE_OVER)\n }\n }\n }\n}\n"],"names":[],"version":3,"file":"index.cjs.map"}
|
package/dist/index.mjs
CHANGED
|
@@ -78,16 +78,16 @@ const $2f7bb06869d30d12$export$9bfcc39f106ad871 = ({ metrics: { prefix: prefix ,
|
|
|
78
78
|
}, {
|
|
79
79
|
chainId: chainId
|
|
80
80
|
}), serverLogger.error);
|
|
81
|
-
var
|
|
82
|
-
res.setHeader("Content-Type", (
|
|
81
|
+
var _requested_headers_get;
|
|
82
|
+
res.setHeader("Content-Type", (_requested_headers_get = requested.headers.get("Content-Type")) !== null && _requested_headers_get !== void 0 ? _requested_headers_get : "application/json");
|
|
83
83
|
res.status(requested.status).send(requested.body);
|
|
84
84
|
} catch (error) {
|
|
85
85
|
if (error instanceof Error) {
|
|
86
|
-
var
|
|
86
|
+
var _error_message;
|
|
87
87
|
// TODO: check if there are errors duplication with iterateUrls
|
|
88
|
-
serverLogger.error((
|
|
89
|
-
var
|
|
90
|
-
res.status(500).json((
|
|
88
|
+
serverLogger.error((_error_message = error.message) !== null && _error_message !== void 0 ? _error_message : $2f7bb06869d30d12$export$c982278a0ddc4dbe);
|
|
89
|
+
var _error_message1;
|
|
90
|
+
res.status(500).json((_error_message1 = error.message) !== null && _error_message1 !== void 0 ? _error_message1 : $2f7bb06869d30d12$export$c982278a0ddc4dbe);
|
|
91
91
|
} else res.status(500).json($2f7bb06869d30d12$export$56a189db5508cdcb);
|
|
92
92
|
}
|
|
93
93
|
};
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;ACEO,MAAM,
|
|
1
|
+
{"mappings":";;;;;;;;;ACEO,MAAM,4CAAS,CAAC,MAAsB,MAA+B;IAC1E,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC;QAAE,QAAQ;IAAK;AACtC;;ADJA;;;;AEOO,MAAM,4CACX,CAAC,YAAE,SAAQ,EAA4B,GACvC,OAAO,MAAsB,MAAyB;QACpD,MAAM,mBAAmB,MAAM,SAAS,OAAO;QAC/C,IAAI,IAAI,CAAC;IACX;;;;;;;;;;ACZF;;AAQO,MAAM,4CAA4B;AAElC,MAAM,4CAAgC;AAEtC,MAAM,kDAAgC;IAC3C,YAAY,OAAgB,CAAE;QAC5B,KAAK,CAAC,WAAW;IACnB;AACF;AAEO,MAAM,kDAAmC;IAC9C,YAAY,OAAgB,CAAE;QAC5B,KAAK,CAAC,WAAW;IACnB;AACF;AAiBO,MAAM,4CAAa,CAAC,EACzB,SAAS,UAAE,OAAM,YAAE,SAAQ,EAAE,CAAA,aAC7B,UAAS,YACT,SAAQ,gBACR,aAAY,gBACZ,aAAY,qBACZ,kBAAiB,EACA,GAAK;IACtB,MAAM,oBAAoB,IAAI,CAAA,GAAA,cAAM,EAAE;QACpC,MAAM,SAAS;QACf,MAAM;QACN,YAAY,EAAE;QACd,WAAW,EAAE;IACf;IACA,SAAS,cAAc,CAAC;IAExB,OAAO,OAAO,KAAqB,MAAwC;QACzE,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AAO,cAAb,6BAAA,kBAAiB,yCAAyB;YACjE,OACE,IAAI,MAAM,CAAC,KAAK,IAAI,CAAC;QAEzB;IACF;AACF;;","sources":["packages/next/pages/src/index.ts","packages/next/pages/src/health.ts","packages/next/pages/src/metricsFactory.ts","packages/next/pages/src/rpcFactory.ts"],"sourcesContent":["export * from './health'\nexport * from './metricsFactory'\nexport * from './rpcFactory'\n","import { NextApiRequest, NextApiResponse } from 'next'\n\nexport const health = (_req: NextApiRequest, res: NextApiResponse): void => {\n res.status(200).send({ status: 'ok' })\n}\n","import { NextApiRequest, NextApiResponse } from 'next'\nimport { Registry } from 'prom-client'\n\nexport type MetricsFactoryParameters = {\n registry: Registry\n}\n\nexport const metricsFactory =\n ({ registry }: MetricsFactoryParameters) =>\n async (_req: NextApiRequest, res: NextApiResponse) => {\n const collectedMetrics = await registry.metrics()\n res.send(collectedMetrics)\n }\n","import type { NextApiRequest, NextApiResponse } from 'next'\nimport { Counter, Registry } from 'prom-client'\nimport { TrackedFetchRPC } from '@lidofinance/api-rpc'\nimport { ServerLogger } from '@lidofinance/api-logger'\nimport { FetchRpcInitBody, iterateUrls } from '@lidofinance/rpc'\n\nexport type RpcProviders = Record<string | number, [string, ...string[]]>\n\nexport const DEFAULT_API_ERROR_MESSAGE = 'Something went wrong. Sorry, try again later :('\n\nexport const HEALTHY_RPC_SERVICES_ARE_OVER = 'Healthy RPC services are over!'\n\nexport class UnsupportedChainIdError extends Error {\n constructor(message?: string) {\n super(message || 'Unsupported chainId')\n }\n}\n\nexport class UnsupportedHTTPMethodError extends Error {\n constructor(message?: string) {\n super(message || 'Unsupported HTTP method')\n }\n}\n\nexport type RPCFactoryParams = {\n metrics: {\n prefix: string\n registry: Registry\n }\n providers: RpcProviders\n fetchRPC: TrackedFetchRPC\n serverLogger: ServerLogger\n defaultChain: string | number\n // If we don't specify allowed RPC methods, then we can't use\n // fetchRPC with prometheus, otherwise it will blow up, if someone will send arbitrary\n // methods\n allowedRPCMethods: string[]\n}\n\nexport const rpcFactory = ({\n metrics: { prefix, registry },\n providers,\n fetchRPC,\n serverLogger,\n defaultChain,\n allowedRPCMethods,\n}: RPCFactoryParams) => {\n const rpcRequestBlocked = new Counter({\n name: prefix + 'rpc_service_request_blocked',\n help: 'RPC service request blocked',\n labelNames: [],\n registers: [],\n })\n registry.registerMetric(rpcRequestBlocked)\n\n return async (req: NextApiRequest, res: NextApiResponse): Promise<void> => {\n try {\n // Accept only POST requests\n if (req.method !== 'POST') {\n // We don't care about tracking blocked requests here\n throw new UnsupportedHTTPMethodError()\n }\n\n const chainId = Number(req.query.chainId || defaultChain)\n\n // Allow only chainId of specified chains\n if (providers[chainId] == null) {\n // We don't care about tracking blocked requests here\n throw new UnsupportedChainIdError()\n }\n\n // TODO: consider returning array of validators instead of throwing error right away\n // Check if provided methods are allowed\n for (const { method } of Array.isArray(req.body) ? req.body : [req.body]) {\n if (typeof method !== 'string') {\n throw new Error(`RPC method isn't string`)\n }\n if (!allowedRPCMethods.includes(method)) {\n rpcRequestBlocked.inc()\n throw new Error(`RPC method ${method} isn't allowed`)\n }\n }\n\n const requested = await iterateUrls(\n providers[chainId],\n // TODO: consider adding verification that body is actually matches FetchRpcInitBody\n (url) => fetchRPC(url, { body: req.body as FetchRpcInitBody }, { chainId }),\n serverLogger.error,\n )\n\n res.setHeader('Content-Type', requested.headers.get('Content-Type') ?? 'application/json')\n res.status(requested.status).send(requested.body)\n } catch (error) {\n if (error instanceof Error) {\n // TODO: check if there are errors duplication with iterateUrls\n serverLogger.error(error.message ?? DEFAULT_API_ERROR_MESSAGE)\n res.status(500).json(error.message ?? DEFAULT_API_ERROR_MESSAGE)\n } else {\n res.status(500).json(HEALTHY_RPC_SERVICES_ARE_OVER)\n }\n }\n }\n}\n"],"names":[],"version":3,"file":"index.mjs.map"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "Common next pages",
|
|
4
4
|
"repository": "git@github.com:lidofinance/warehouse.git",
|
|
5
5
|
"license": "MIT",
|
|
6
|
-
"version": "0.
|
|
6
|
+
"version": "0.11.0",
|
|
7
7
|
"files": [
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
@@ -17,22 +17,22 @@
|
|
|
17
17
|
"types": "dist/index.d.ts",
|
|
18
18
|
"scripts": {
|
|
19
19
|
"build": "parcel build",
|
|
20
|
-
"
|
|
21
|
-
"
|
|
20
|
+
"lint": "eslint . && prettier --check src",
|
|
21
|
+
"lint:fix": "eslint --fix . && prettier --check src --write",
|
|
22
22
|
"types": "tsc --noEmit"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
|
-
"@lidofinance/api-logger": "~0.
|
|
26
|
-
"@lidofinance/api-rpc": "~0.
|
|
27
|
-
"@lidofinance/rpc": "~0.
|
|
25
|
+
"@lidofinance/api-logger": "~0.11.0",
|
|
26
|
+
"@lidofinance/api-rpc": "~0.11.0",
|
|
27
|
+
"@lidofinance/rpc": "~0.11.0",
|
|
28
28
|
"next": "^12.2.0",
|
|
29
29
|
"prom-client": "^14.0.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@lidofinance/api-logger": "~0.
|
|
33
|
-
"@lidofinance/api-rpc": "~0.
|
|
34
|
-
"@lidofinance/config-prettier": "~0.
|
|
35
|
-
"@lidofinance/rpc": "~0.
|
|
32
|
+
"@lidofinance/api-logger": "~0.11.0",
|
|
33
|
+
"@lidofinance/api-rpc": "~0.11.0",
|
|
34
|
+
"@lidofinance/config-prettier": "~0.11.0",
|
|
35
|
+
"@lidofinance/rpc": "~0.11.0",
|
|
36
36
|
"next": "^12.3.1",
|
|
37
37
|
"prom-client": "^14.1.0"
|
|
38
38
|
}
|