@satrush/api 0.1.0 → 0.1.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/README.md +22 -20
- package/dist/index.cjs +249 -3
- package/dist/index.d.cts +328 -3
- package/dist/index.d.ts +328 -3
- package/dist/index.js +234 -2
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -18,6 +18,91 @@ var extraPrefixesMap = {
|
|
|
18
18
|
$query_: "query"
|
|
19
19
|
};
|
|
20
20
|
var extraPrefixes = Object.entries(extraPrefixesMap);
|
|
21
|
+
var buildKeyMap = (fields, map) => {
|
|
22
|
+
if (!map) {
|
|
23
|
+
map = /* @__PURE__ */ new Map();
|
|
24
|
+
}
|
|
25
|
+
for (const config of fields) {
|
|
26
|
+
if ("in" in config) {
|
|
27
|
+
if (config.key) {
|
|
28
|
+
map.set(config.key, {
|
|
29
|
+
in: config.in,
|
|
30
|
+
map: config.map
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
} else if ("key" in config) {
|
|
34
|
+
map.set(config.key, {
|
|
35
|
+
map: config.map
|
|
36
|
+
});
|
|
37
|
+
} else if (config.args) {
|
|
38
|
+
buildKeyMap(config.args, map);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return map;
|
|
42
|
+
};
|
|
43
|
+
var stripEmptySlots = (params) => {
|
|
44
|
+
for (const [slot, value] of Object.entries(params)) {
|
|
45
|
+
if (value && typeof value === "object" && !Object.keys(value).length) {
|
|
46
|
+
delete params[slot];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var buildClientParams = (args, fields) => {
|
|
51
|
+
const params = {
|
|
52
|
+
body: {},
|
|
53
|
+
headers: {},
|
|
54
|
+
path: {},
|
|
55
|
+
query: {}
|
|
56
|
+
};
|
|
57
|
+
const map = buildKeyMap(fields);
|
|
58
|
+
let config;
|
|
59
|
+
for (const [index, arg] of args.entries()) {
|
|
60
|
+
if (fields[index]) {
|
|
61
|
+
config = fields[index];
|
|
62
|
+
}
|
|
63
|
+
if (!config) {
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
if ("in" in config) {
|
|
67
|
+
if (config.key) {
|
|
68
|
+
const field = map.get(config.key);
|
|
69
|
+
const name = field.map || config.key;
|
|
70
|
+
if (field.in) {
|
|
71
|
+
params[field.in][name] = arg;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
params.body = arg;
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
for (const [key, value] of Object.entries(arg ?? {})) {
|
|
78
|
+
const field = map.get(key);
|
|
79
|
+
if (field) {
|
|
80
|
+
if (field.in) {
|
|
81
|
+
const name = field.map || key;
|
|
82
|
+
params[field.in][name] = value;
|
|
83
|
+
} else {
|
|
84
|
+
params[field.map] = value;
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
|
|
88
|
+
if (extra) {
|
|
89
|
+
const [prefix, slot] = extra;
|
|
90
|
+
params[slot][key.slice(prefix.length)] = value;
|
|
91
|
+
} else if ("allowExtra" in config && config.allowExtra) {
|
|
92
|
+
for (const [slot, allowed] of Object.entries(config.allowExtra)) {
|
|
93
|
+
if (allowed) {
|
|
94
|
+
params[slot][key] = value;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
stripEmptySlots(params);
|
|
104
|
+
return params;
|
|
105
|
+
};
|
|
21
106
|
|
|
22
107
|
// src/generated/core/serverSentEvents.gen.ts
|
|
23
108
|
var createSseClient = ({
|
|
@@ -895,9 +980,39 @@ var getBoardResponseTransformer = async (data) => {
|
|
|
895
980
|
data.data = boardDtoSchemaResponseTransformer(data.data);
|
|
896
981
|
return data;
|
|
897
982
|
};
|
|
983
|
+
var publicDeploymentDtoSchemaResponseTransformer = (data) => {
|
|
984
|
+
data.deployedUsdAmount = u64DtoSchemaResponseTransformer(data.deployedUsdAmount);
|
|
985
|
+
return data;
|
|
986
|
+
};
|
|
987
|
+
var minerDtoSchemaResponseTransformer = (data) => {
|
|
988
|
+
data.hashrateAmount = u64DtoSchemaResponseTransformer(data.hashrateAmount);
|
|
989
|
+
data.unclaimedBtcShares = u64DtoSchemaResponseTransformer(data.unclaimedBtcShares);
|
|
990
|
+
data.unclaimedUsdAmount = u64DtoSchemaResponseTransformer(data.unclaimedUsdAmount);
|
|
991
|
+
return data;
|
|
992
|
+
};
|
|
993
|
+
var profileDtoSchemaResponseTransformer = (data) => {
|
|
994
|
+
data.deployments = data.deployments.map((item) => publicDeploymentDtoSchemaResponseTransformer(item));
|
|
995
|
+
data.miner = minerDtoSchemaResponseTransformer(data.miner);
|
|
996
|
+
return data;
|
|
997
|
+
};
|
|
998
|
+
var getUserProfileResponseTransformer = async (data) => {
|
|
999
|
+
data.data = profileDtoSchemaResponseTransformer(data.data);
|
|
1000
|
+
return data;
|
|
1001
|
+
};
|
|
898
1002
|
|
|
899
1003
|
// src/generated/zod.gen.ts
|
|
900
1004
|
import * as z from "zod";
|
|
1005
|
+
var zBadRequestErrorCodeErrorBody = z.object({
|
|
1006
|
+
code: z.enum([
|
|
1007
|
+
"invalid_path",
|
|
1008
|
+
"invalid_query",
|
|
1009
|
+
"invalid_body"
|
|
1010
|
+
])
|
|
1011
|
+
});
|
|
1012
|
+
var zFieldError = z.object({
|
|
1013
|
+
field: z.string(),
|
|
1014
|
+
message: z.string()
|
|
1015
|
+
});
|
|
901
1016
|
var zI128Dto = z.string();
|
|
902
1017
|
var zI64Dto = z.coerce.bigint().min(BigInt("-9223372036854775808"), { error: "Invalid value: Expected int64 to be >= -9223372036854775808" }).max(BigInt("9223372036854775807"), { error: "Invalid value: Expected int64 to be <= 9223372036854775807" });
|
|
903
1018
|
var zInternalErrorCodeErrorBody = z.object({
|
|
@@ -910,8 +1025,37 @@ var zRoundStateDto = z.enum([
|
|
|
910
1025
|
"settled",
|
|
911
1026
|
"finished"
|
|
912
1027
|
]);
|
|
1028
|
+
var zSatrushConfigDto = z.object({
|
|
1029
|
+
address: zPubkeyDto,
|
|
1030
|
+
btcMint: zPubkeyDto,
|
|
1031
|
+
epochFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1032
|
+
oneBtcFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1033
|
+
protocolFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1034
|
+
satsVaultClaimFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1035
|
+
satsVaultRoundFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1036
|
+
strikeFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1037
|
+
usdMint: zPubkeyDto
|
|
1038
|
+
});
|
|
913
1039
|
var zU128Dto = z.string();
|
|
914
1040
|
var zU64Dto = z.coerce.bigint().min(BigInt("0"), { error: "Invalid value: Expected uint64 to be >= 0" }).max(BigInt("18446744073709551615"), { error: "Invalid value: Expected uint64 to be <= 18446744073709551615" });
|
|
1041
|
+
var zMinerDto = z.object({
|
|
1042
|
+
authority: zPubkeyDto,
|
|
1043
|
+
currentStreakCount: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1044
|
+
hashrateAmount: zU64Dto,
|
|
1045
|
+
lastMinedRoundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1046
|
+
unclaimedBtcShares: zU64Dto,
|
|
1047
|
+
unclaimedUsdAmount: zU64Dto
|
|
1048
|
+
});
|
|
1049
|
+
var zPublicDeploymentDto = z.object({
|
|
1050
|
+
address: zPubkeyDto,
|
|
1051
|
+
deployedUsdAmount: zU64Dto,
|
|
1052
|
+
roundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
1053
|
+
selectionMask: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" })
|
|
1054
|
+
});
|
|
1055
|
+
var zProfileDto = z.object({
|
|
1056
|
+
deployments: z.array(zPublicDeploymentDto),
|
|
1057
|
+
miner: zMinerDto
|
|
1058
|
+
});
|
|
915
1059
|
var zStrikeJackpotDto = z.object({
|
|
916
1060
|
btcAmount: zU64Dto,
|
|
917
1061
|
lastTriggerRoundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
|
|
@@ -959,6 +1103,33 @@ var zBoardDto = z.object({
|
|
|
959
1103
|
startSlot: zU64Dto,
|
|
960
1104
|
strike: zStrikeJackpotDto
|
|
961
1105
|
});
|
|
1106
|
+
var zUserProfileApiError400InvalidAddress = z.object({
|
|
1107
|
+
code: z.enum(["invalid_address"])
|
|
1108
|
+
});
|
|
1109
|
+
var zUserProfileApiError400Error = z.union([
|
|
1110
|
+
z.object({
|
|
1111
|
+
code: z.literal("invalid_address")
|
|
1112
|
+
}).and(zUserProfileApiError400InvalidAddress),
|
|
1113
|
+
z.object({
|
|
1114
|
+
code: z.union([
|
|
1115
|
+
z.literal("invalid_body"),
|
|
1116
|
+
z.literal("invalid_path"),
|
|
1117
|
+
z.literal("invalid_query")
|
|
1118
|
+
])
|
|
1119
|
+
}).and(zBadRequestErrorCodeErrorBody)
|
|
1120
|
+
]);
|
|
1121
|
+
var zValidationErrorCodeErrorBody = z.object({
|
|
1122
|
+
code: z.enum(["validation_failed"]),
|
|
1123
|
+
data: z.optional(z.object({
|
|
1124
|
+
errors: z.array(zFieldError)
|
|
1125
|
+
}))
|
|
1126
|
+
});
|
|
1127
|
+
var zValidationErrorCodeValidationDetailsErrorBody = z.object({
|
|
1128
|
+
code: z.enum(["validation_failed"]),
|
|
1129
|
+
data: z.optional(z.object({
|
|
1130
|
+
errors: z.array(zFieldError)
|
|
1131
|
+
}))
|
|
1132
|
+
});
|
|
962
1133
|
var zGetBoardData = z.object({
|
|
963
1134
|
body: z.optional(z.never()),
|
|
964
1135
|
path: z.optional(z.never()),
|
|
@@ -967,6 +1138,24 @@ var zGetBoardData = z.object({
|
|
|
967
1138
|
var zGetBoardResponse = z.object({
|
|
968
1139
|
data: zBoardDto
|
|
969
1140
|
});
|
|
1141
|
+
var zGetConfigData = z.object({
|
|
1142
|
+
body: z.optional(z.never()),
|
|
1143
|
+
path: z.optional(z.never()),
|
|
1144
|
+
query: z.optional(z.never())
|
|
1145
|
+
});
|
|
1146
|
+
var zGetConfigResponse = z.object({
|
|
1147
|
+
data: zSatrushConfigDto
|
|
1148
|
+
});
|
|
1149
|
+
var zGetUserProfileData = z.object({
|
|
1150
|
+
body: z.optional(z.never()),
|
|
1151
|
+
path: z.object({
|
|
1152
|
+
address: z.string()
|
|
1153
|
+
}),
|
|
1154
|
+
query: z.optional(z.never())
|
|
1155
|
+
});
|
|
1156
|
+
var zGetUserProfileResponse = z.object({
|
|
1157
|
+
data: zProfileDto
|
|
1158
|
+
});
|
|
970
1159
|
|
|
971
1160
|
// src/generated/sdk.gen.ts
|
|
972
1161
|
var HeyApiClient = class {
|
|
@@ -1007,6 +1196,31 @@ var SatrushBackendSdk = class _SatrushBackendSdk extends HeyApiClient {
|
|
|
1007
1196
|
...options
|
|
1008
1197
|
});
|
|
1009
1198
|
}
|
|
1199
|
+
/**
|
|
1200
|
+
* Request config
|
|
1201
|
+
*/
|
|
1202
|
+
getConfig(options) {
|
|
1203
|
+
return (options?.client ?? this.client).get({
|
|
1204
|
+
requestValidator: async (data) => await zGetConfigData.parseAsync(data),
|
|
1205
|
+
responseValidator: async (data) => await zGetConfigResponse.parseAsync(data),
|
|
1206
|
+
url: "/v1/config",
|
|
1207
|
+
...options
|
|
1208
|
+
});
|
|
1209
|
+
}
|
|
1210
|
+
/**
|
|
1211
|
+
* Request user profile
|
|
1212
|
+
*/
|
|
1213
|
+
getUserProfile(parameters, options) {
|
|
1214
|
+
const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "address" }] }]);
|
|
1215
|
+
return (options?.client ?? this.client).get({
|
|
1216
|
+
requestValidator: async (data) => await zGetUserProfileData.parseAsync(data),
|
|
1217
|
+
responseTransformer: getUserProfileResponseTransformer,
|
|
1218
|
+
responseValidator: async (data) => await zGetUserProfileResponse.parseAsync(data),
|
|
1219
|
+
url: "/v1/user/{address}/profile",
|
|
1220
|
+
...options,
|
|
1221
|
+
...params
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1010
1224
|
};
|
|
1011
1225
|
|
|
1012
1226
|
// src/generated/types.gen.ts
|
|
@@ -1049,7 +1263,11 @@ async function unwrap(promise) {
|
|
|
1049
1263
|
if (res && typeof res === "object" && "response" in res) {
|
|
1050
1264
|
const sdkRes = res;
|
|
1051
1265
|
if ("error" in sdkRes && sdkRes.error !== void 0) {
|
|
1052
|
-
throw new SatrushBackendSdkError(
|
|
1266
|
+
throw new SatrushBackendSdkError(
|
|
1267
|
+
String(sdkRes.error),
|
|
1268
|
+
sdkRes.response?.status ?? 0,
|
|
1269
|
+
sdkRes.error
|
|
1270
|
+
);
|
|
1053
1271
|
}
|
|
1054
1272
|
if ("data" in sdkRes) {
|
|
1055
1273
|
return unwrapData(sdkRes.data);
|
|
@@ -1066,17 +1284,31 @@ export {
|
|
|
1066
1284
|
isSatrushSdkError,
|
|
1067
1285
|
satrushSdkErrorInterceptor,
|
|
1068
1286
|
unwrap,
|
|
1287
|
+
zBadRequestErrorCodeErrorBody,
|
|
1069
1288
|
zBoardDto,
|
|
1289
|
+
zFieldError,
|
|
1070
1290
|
zGetBoardData,
|
|
1071
1291
|
zGetBoardResponse,
|
|
1292
|
+
zGetConfigData,
|
|
1293
|
+
zGetConfigResponse,
|
|
1294
|
+
zGetUserProfileData,
|
|
1295
|
+
zGetUserProfileResponse,
|
|
1072
1296
|
zI128Dto,
|
|
1073
1297
|
zI64Dto,
|
|
1074
1298
|
zInternalErrorCodeErrorBody,
|
|
1299
|
+
zMinerDto,
|
|
1300
|
+
zProfileDto,
|
|
1075
1301
|
zPubkeyDto,
|
|
1302
|
+
zPublicDeploymentDto,
|
|
1076
1303
|
zRoundDto,
|
|
1077
1304
|
zRoundStateDto,
|
|
1305
|
+
zSatrushConfigDto,
|
|
1078
1306
|
zStrikeJackpotDto,
|
|
1079
1307
|
zTileStakeDto,
|
|
1080
1308
|
zU128Dto,
|
|
1081
|
-
zU64Dto
|
|
1309
|
+
zU64Dto,
|
|
1310
|
+
zUserProfileApiError400Error,
|
|
1311
|
+
zUserProfileApiError400InvalidAddress,
|
|
1312
|
+
zValidationErrorCodeErrorBody,
|
|
1313
|
+
zValidationErrorCodeValidationDetailsErrorBody
|
|
1082
1314
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@satrush/api",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"decimal.js": "^10.5.0",
|
|
25
25
|
"dotenv": "^17.4.2",
|
|
26
26
|
"eslint": "^10.6.0",
|
|
27
|
+
"globals": "^17.7.0",
|
|
27
28
|
"tsup": "^8.3.5",
|
|
28
29
|
"typescript": "6.0.3",
|
|
29
30
|
"vite-tsconfig-paths": "^6.1.1",
|
|
@@ -44,6 +45,8 @@
|
|
|
44
45
|
"eslint:fix": "eslint \"**/*.ts\" --fix",
|
|
45
46
|
"type-check": "tsc -p .",
|
|
46
47
|
"lint": "pnpm eslint && pnpm type-check",
|
|
48
|
+
"prettier": "prettier . --write",
|
|
49
|
+
"format": "pnpm prettier && pnpm eslint:fix",
|
|
47
50
|
"test": "vitest run --disable-console-intercept",
|
|
48
51
|
"test:start-server": "node scripts/startTestsServer.mjs",
|
|
49
52
|
"test:watch": "vitest watch"
|