@ocap/resolver 1.30.20 → 1.30.22
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/esm/api.d.mts +4 -2
- package/esm/api.mjs +27 -0
- package/lib/api.cjs +27 -0
- package/lib/api.d.cts +4 -2
- package/package.json +14 -14
package/esm/api.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { TIndexedTokenState } from "./types.mjs";
|
|
1
|
+
import { TIndexedTokenState as TIndexedTokenState$1 } from "./types.mjs";
|
|
2
2
|
import { Router } from "express";
|
|
3
|
+
import { ILedger } from "@ocap/types";
|
|
3
4
|
|
|
4
5
|
//#region src/api.d.ts
|
|
5
6
|
|
|
@@ -9,7 +10,8 @@ import { Router } from "express";
|
|
|
9
10
|
interface IAPIResolver {
|
|
10
11
|
getTokenState(params: {
|
|
11
12
|
address: string;
|
|
12
|
-
}): Promise<TIndexedTokenState | null>;
|
|
13
|
+
}): Promise<TIndexedTokenState$1 | null>;
|
|
14
|
+
ledger: ILedger;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Parameters for createAPIHandler
|
package/esm/api.mjs
CHANGED
|
@@ -46,6 +46,33 @@ function createAPIHandler({ resolver }) {
|
|
|
46
46
|
res.setHeader("Content-Type", "image/svg+xml");
|
|
47
47
|
res.send(svg);
|
|
48
48
|
});
|
|
49
|
+
router.get("/health/ledger", async (_req, res) => {
|
|
50
|
+
try {
|
|
51
|
+
const health = await resolver.ledger.getHealth();
|
|
52
|
+
const lagThreshold = Number(process.env.LEDGER_HEALTH_LAG_THRESHOLD) || 1e3;
|
|
53
|
+
const ageThresholdMs = Number(process.env.LEDGER_HEALTH_AGE_THRESHOLD_MS) || 36e5;
|
|
54
|
+
const unfinalizedAgeThresholdMs = Number(process.env.LEDGER_HEALTH_UNFINALIZED_AGE_THRESHOLD_MS) || 3e5;
|
|
55
|
+
const now = Date.now();
|
|
56
|
+
const oldestUnfinalizedAgeMs = health.oldestUnfinalizedTimestamp ? now - health.oldestUnfinalizedTimestamp : null;
|
|
57
|
+
const healthy = health.checkpointLag <= lagThreshold && (health.checkpointAgeMs == null || health.checkpointAgeMs <= ageThresholdMs) && (oldestUnfinalizedAgeMs == null || oldestUnfinalizedAgeMs <= unfinalizedAgeThresholdMs);
|
|
58
|
+
res.json({
|
|
59
|
+
healthy,
|
|
60
|
+
...health,
|
|
61
|
+
oldestUnfinalizedAgeMs,
|
|
62
|
+
thresholds: {
|
|
63
|
+
checkpointLag: lagThreshold,
|
|
64
|
+
checkpointAgeMs: ageThresholdMs,
|
|
65
|
+
unfinalizedAgeMs: unfinalizedAgeThresholdMs
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
} catch (error) {
|
|
69
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
70
|
+
res.status(500).json({
|
|
71
|
+
healthy: false,
|
|
72
|
+
error: message
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
});
|
|
49
76
|
return router;
|
|
50
77
|
}
|
|
51
78
|
|
package/lib/api.cjs
CHANGED
|
@@ -47,6 +47,33 @@ function createAPIHandler({ resolver }) {
|
|
|
47
47
|
res.setHeader("Content-Type", "image/svg+xml");
|
|
48
48
|
res.send(svg);
|
|
49
49
|
});
|
|
50
|
+
router.get("/health/ledger", async (_req, res) => {
|
|
51
|
+
try {
|
|
52
|
+
const health = await resolver.ledger.getHealth();
|
|
53
|
+
const lagThreshold = Number(process.env.LEDGER_HEALTH_LAG_THRESHOLD) || 1e3;
|
|
54
|
+
const ageThresholdMs = Number(process.env.LEDGER_HEALTH_AGE_THRESHOLD_MS) || 36e5;
|
|
55
|
+
const unfinalizedAgeThresholdMs = Number(process.env.LEDGER_HEALTH_UNFINALIZED_AGE_THRESHOLD_MS) || 3e5;
|
|
56
|
+
const now = Date.now();
|
|
57
|
+
const oldestUnfinalizedAgeMs = health.oldestUnfinalizedTimestamp ? now - health.oldestUnfinalizedTimestamp : null;
|
|
58
|
+
const healthy = health.checkpointLag <= lagThreshold && (health.checkpointAgeMs == null || health.checkpointAgeMs <= ageThresholdMs) && (oldestUnfinalizedAgeMs == null || oldestUnfinalizedAgeMs <= unfinalizedAgeThresholdMs);
|
|
59
|
+
res.json({
|
|
60
|
+
healthy,
|
|
61
|
+
...health,
|
|
62
|
+
oldestUnfinalizedAgeMs,
|
|
63
|
+
thresholds: {
|
|
64
|
+
checkpointLag: lagThreshold,
|
|
65
|
+
checkpointAgeMs: ageThresholdMs,
|
|
66
|
+
unfinalizedAgeMs: unfinalizedAgeThresholdMs
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} catch (error) {
|
|
70
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
71
|
+
res.status(500).json({
|
|
72
|
+
healthy: false,
|
|
73
|
+
error: message
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
});
|
|
50
77
|
return router;
|
|
51
78
|
}
|
|
52
79
|
|
package/lib/api.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { TIndexedTokenState } from "./types.cjs";
|
|
1
|
+
import { TIndexedTokenState as TIndexedTokenState$1 } from "./types.cjs";
|
|
2
|
+
import { ILedger } from "@ocap/types";
|
|
2
3
|
import { Router } from "express";
|
|
3
4
|
|
|
4
5
|
//#region src/api.d.ts
|
|
@@ -9,7 +10,8 @@ import { Router } from "express";
|
|
|
9
10
|
interface IAPIResolver {
|
|
10
11
|
getTokenState(params: {
|
|
11
12
|
address: string;
|
|
12
|
-
}): Promise<TIndexedTokenState | null>;
|
|
13
|
+
}): Promise<TIndexedTokenState$1 | null>;
|
|
14
|
+
ledger: ILedger;
|
|
13
15
|
}
|
|
14
16
|
/**
|
|
15
17
|
* Parameters for createAPIHandler
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.30.
|
|
6
|
+
"version": "1.30.22",
|
|
7
7
|
"description": "GraphQL resolver built upon ocap statedb and GQL layer",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"main": "./lib/index.cjs",
|
|
@@ -49,20 +49,20 @@
|
|
|
49
49
|
"tsdown": "^0.18.4"
|
|
50
50
|
},
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@arcblock/did": "1.30.
|
|
53
|
-
"@arcblock/did-ext": "1.30.
|
|
54
|
-
"@arcblock/did-util": "1.30.
|
|
52
|
+
"@arcblock/did": "1.30.22",
|
|
53
|
+
"@arcblock/did-ext": "1.30.22",
|
|
54
|
+
"@arcblock/did-util": "1.30.22",
|
|
55
55
|
"@arcblock/nft-display": "^3.2.3",
|
|
56
|
-
"@arcblock/validator": "1.30.
|
|
57
|
-
"@ocap/config": "1.30.
|
|
58
|
-
"@ocap/indexdb": "1.30.
|
|
59
|
-
"@ocap/mcrypto": "1.30.
|
|
60
|
-
"@ocap/message": "1.30.
|
|
61
|
-
"@ocap/state": "1.30.
|
|
62
|
-
"@ocap/tx-protocols": "1.30.
|
|
63
|
-
"@ocap/types": "1.30.
|
|
64
|
-
"@ocap/util": "1.30.
|
|
65
|
-
"@ocap/wallet": "1.30.
|
|
56
|
+
"@arcblock/validator": "1.30.22",
|
|
57
|
+
"@ocap/config": "1.30.22",
|
|
58
|
+
"@ocap/indexdb": "1.30.22",
|
|
59
|
+
"@ocap/mcrypto": "1.30.22",
|
|
60
|
+
"@ocap/message": "1.30.22",
|
|
61
|
+
"@ocap/state": "1.30.22",
|
|
62
|
+
"@ocap/tx-protocols": "1.30.22",
|
|
63
|
+
"@ocap/types": "1.30.22",
|
|
64
|
+
"@ocap/util": "1.30.22",
|
|
65
|
+
"@ocap/wallet": "1.30.22",
|
|
66
66
|
"debug": "^4.4.3",
|
|
67
67
|
"express": "^4.22.1",
|
|
68
68
|
"lodash": "^4.17.23",
|