@c7-digital/scan 0.0.1
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/lib/scripts/build.d.ts +13 -0
- package/lib/scripts/build.js +160 -0
- package/lib/scripts/download-spec.d.ts +14 -0
- package/lib/scripts/download-spec.js +283 -0
- package/lib/src/client.d.ts +125 -0
- package/lib/src/client.js +160 -0
- package/lib/src/generated/api.d.ts +5205 -0
- package/lib/src/generated/api.js +5 -0
- package/lib/src/generated/sdk-version.d.ts +1 -0
- package/lib/src/generated/sdk-version.js +3 -0
- package/lib/src/index.d.ts +4 -0
- package/lib/src/index.js +3 -0
- package/lib/src/logger.d.ts +41 -0
- package/lib/src/logger.js +56 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/package.json +47 -0
- package/scripts/build.ts +193 -0
- package/scripts/download-spec.ts +344 -0
- package/specs/scan_bundled_0.5.10.yaml +4826 -0
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { logger } from "./logger.js";
|
|
2
|
+
import fetch from "cross-fetch";
|
|
3
|
+
// ─── ScanClient ────────────────────────────────────────────────────────
|
|
4
|
+
export class ScanClient {
|
|
5
|
+
constructor(config) {
|
|
6
|
+
this.baseUrl = config.baseUrl;
|
|
7
|
+
this.token = config.token;
|
|
8
|
+
}
|
|
9
|
+
async request(path, method, options) {
|
|
10
|
+
let url = `${this.baseUrl}${path}`;
|
|
11
|
+
// Append query parameters
|
|
12
|
+
if (options?.query) {
|
|
13
|
+
const params = new URLSearchParams();
|
|
14
|
+
for (const [key, value] of Object.entries(options.query)) {
|
|
15
|
+
if (value === undefined || value === null)
|
|
16
|
+
continue;
|
|
17
|
+
if (Array.isArray(value)) {
|
|
18
|
+
for (const item of value) {
|
|
19
|
+
params.append(key, String(item));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
params.append(key, String(value));
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const qs = params.toString();
|
|
27
|
+
if (qs) {
|
|
28
|
+
url += `?${qs}`;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const headers = {
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
};
|
|
34
|
+
if (this.token) {
|
|
35
|
+
headers["Authorization"] = `Bearer ${this.token}`;
|
|
36
|
+
}
|
|
37
|
+
const requestInit = { method, headers };
|
|
38
|
+
if (options?.body) {
|
|
39
|
+
requestInit.body = JSON.stringify(options.body);
|
|
40
|
+
}
|
|
41
|
+
logger.debug(`${method} ${url}`);
|
|
42
|
+
const response = await fetch(url, requestInit);
|
|
43
|
+
if (!response.ok) {
|
|
44
|
+
const text = await response.text().catch(() => "");
|
|
45
|
+
throw new Error(`HTTP ${response.status}: ${response.statusText}${text ? ` - ${text}` : ""}`);
|
|
46
|
+
}
|
|
47
|
+
// Some health endpoints return empty bodies
|
|
48
|
+
const contentType = response.headers.get("content-type");
|
|
49
|
+
if (!contentType || !contentType.includes("application/json")) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
return (await response.json());
|
|
53
|
+
}
|
|
54
|
+
// ─── ANS / Name Service ────────────────────────────────────────────
|
|
55
|
+
async listAnsEntries(params) {
|
|
56
|
+
return this.request("/v0/ans-entries", "GET", {
|
|
57
|
+
query: params,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
async lookupAnsEntryByParty(party) {
|
|
61
|
+
return this.request(`/v0/ans-entries/by-party/${encodeURIComponent(party)}`, "GET");
|
|
62
|
+
}
|
|
63
|
+
async lookupAnsEntryByName(name) {
|
|
64
|
+
return this.request(`/v0/ans-entries/by-name/${encodeURIComponent(name)}`, "GET");
|
|
65
|
+
}
|
|
66
|
+
// ─── Party Resolution ──────────────────────────────────────────────
|
|
67
|
+
async getPartyToParticipant(domainId, partyId) {
|
|
68
|
+
return this.request(`/v0/domains/${encodeURIComponent(domainId)}/parties/${encodeURIComponent(partyId)}/participant-id`, "GET");
|
|
69
|
+
}
|
|
70
|
+
// ─── Network Info ──────────────────────────────────────────────────
|
|
71
|
+
async getDsoInfo() {
|
|
72
|
+
return this.request("/v0/dso", "GET");
|
|
73
|
+
}
|
|
74
|
+
async getDsoPartyId() {
|
|
75
|
+
return this.request("/v0/dso-party-id", "GET");
|
|
76
|
+
}
|
|
77
|
+
async getDsoSequencers() {
|
|
78
|
+
return this.request("/v0/dso-sequencers", "GET");
|
|
79
|
+
}
|
|
80
|
+
async listScans() {
|
|
81
|
+
return this.request("/v0/scans", "GET");
|
|
82
|
+
}
|
|
83
|
+
// ─── Validator Info ────────────────────────────────────────────────
|
|
84
|
+
async listValidatorLicenses(params) {
|
|
85
|
+
return this.request("/v0/admin/validator/licenses", "GET", { query: params });
|
|
86
|
+
}
|
|
87
|
+
async getValidatorFaucets(params) {
|
|
88
|
+
return this.request("/v0/validators/validator-faucets", "GET", { query: params });
|
|
89
|
+
}
|
|
90
|
+
// ─── Updates (v2) ──────────────────────────────────────────────────
|
|
91
|
+
async getUpdates(body) {
|
|
92
|
+
return this.request("/v2/updates", "POST", { body });
|
|
93
|
+
}
|
|
94
|
+
async getUpdateById(updateId, params) {
|
|
95
|
+
return this.request(`/v2/updates/${encodeURIComponent(updateId)}`, "GET", { query: params });
|
|
96
|
+
}
|
|
97
|
+
// ─── ACS State ─────────────────────────────────────────────────────
|
|
98
|
+
async getAcsSnapshot(body) {
|
|
99
|
+
return this.request("/v0/state/acs", "POST", { body });
|
|
100
|
+
}
|
|
101
|
+
async getAcsSnapshotTimestamp(params) {
|
|
102
|
+
return this.request("/v0/state/acs/snapshot-timestamp", "GET", { query: params });
|
|
103
|
+
}
|
|
104
|
+
async getAcsSnapshotTimestampAfter(params) {
|
|
105
|
+
return this.request("/v0/state/acs/snapshot-timestamp-after", "GET", { query: params });
|
|
106
|
+
}
|
|
107
|
+
async forceAcsSnapshot() {
|
|
108
|
+
return this.request("/v0/state/acs/force", "POST");
|
|
109
|
+
}
|
|
110
|
+
// ─── Holdings ──────────────────────────────────────────────────────
|
|
111
|
+
async getHoldingsState(body) {
|
|
112
|
+
return this.request("/v0/holdings/state", "POST", { body });
|
|
113
|
+
}
|
|
114
|
+
async getHoldingsSummary(body) {
|
|
115
|
+
return this.request("/v0/holdings/summary", "POST", { body });
|
|
116
|
+
}
|
|
117
|
+
// ─── Rounds ────────────────────────────────────────────────────────
|
|
118
|
+
async getClosedRounds() {
|
|
119
|
+
return this.request("/v0/closed-rounds", "GET");
|
|
120
|
+
}
|
|
121
|
+
async getOpenAndIssuingMiningRounds(body) {
|
|
122
|
+
return this.request("/v0/open-and-issuing-mining-rounds", "POST", { body });
|
|
123
|
+
}
|
|
124
|
+
// ─── Events ────────────────────────────────────────────────────────
|
|
125
|
+
async getEvents(body) {
|
|
126
|
+
return this.request("/v0/events", "POST", { body });
|
|
127
|
+
}
|
|
128
|
+
async getEventById(updateId, params) {
|
|
129
|
+
return this.request(`/v0/events/${encodeURIComponent(updateId)}`, "GET", { query: params });
|
|
130
|
+
}
|
|
131
|
+
// ─── Misc ──────────────────────────────────────────────────────────
|
|
132
|
+
async getUnclaimedDevelopmentFundCoupons() {
|
|
133
|
+
return this.request("/v0/unclaimed-development-fund-coupons", "GET");
|
|
134
|
+
}
|
|
135
|
+
// ─── Health ────────────────────────────────────────────────────────
|
|
136
|
+
async isReady() {
|
|
137
|
+
try {
|
|
138
|
+
await this.request("/readyz", "GET");
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async isLive() {
|
|
146
|
+
try {
|
|
147
|
+
await this.request("/livez", "GET");
|
|
148
|
+
return true;
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
async getStatus() {
|
|
155
|
+
return this.request("/status", "GET");
|
|
156
|
+
}
|
|
157
|
+
async getVersion() {
|
|
158
|
+
return this.request("/version", "GET");
|
|
159
|
+
}
|
|
160
|
+
}
|