@satrush/api 0.1.0 → 0.1.2

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.js CHANGED
@@ -18,6 +18,140 @@ 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
+ };
106
+
107
+ // src/utils/sse.ts
108
+ var isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
109
+ var applySseResponseTransforms = async (payload) => {
110
+ if (!isRecord(payload)) return payload;
111
+ return payload;
112
+ };
113
+
114
+ // src/utils/transforms.ts
115
+ var snakeToCamel = (value) => value.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
116
+ var camelToSnake = (value) => value.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
117
+ var isPlainObject = (value) => !!value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
118
+ var mapKeysDeep = (value, mapKey) => {
119
+ if (Array.isArray(value)) {
120
+ return value.map((item) => mapKeysDeep(item, mapKey));
121
+ }
122
+ if (isPlainObject(value)) {
123
+ const next = {};
124
+ for (const [key, val] of Object.entries(value)) {
125
+ next[mapKey(key)] = mapKeysDeep(val, mapKey);
126
+ }
127
+ return next;
128
+ }
129
+ return value;
130
+ };
131
+ var shouldTransformBody = (value) => isPlainObject(value) || Array.isArray(value);
132
+ var snakecaseQuerySerializerParams = (value) => {
133
+ if (!isPlainObject(value)) return value;
134
+ if (!isPlainObject(value.parameters)) return value;
135
+ const nextParameters = {};
136
+ for (const [key, param] of Object.entries(value.parameters)) {
137
+ nextParameters[camelToSnake(key)] = param;
138
+ }
139
+ return { ...value, parameters: nextParameters };
140
+ };
141
+ var applyRequestCaseTransforms = (options) => {
142
+ const next = { ...options };
143
+ if ("query" in next && isPlainObject(next.query)) {
144
+ next.query = mapKeysDeep(next.query, camelToSnake);
145
+ }
146
+ if ("querySerializer" in next && next.querySerializer) {
147
+ next.querySerializer = snakecaseQuerySerializerParams(next.querySerializer);
148
+ }
149
+ if ("body" in next && shouldTransformBody(next.body)) {
150
+ next.body = mapKeysDeep(next.body, camelToSnake);
151
+ }
152
+ return next;
153
+ };
154
+ var applyResponseCaseTransforms = (value) => mapKeysDeep(value, snakeToCamel);
21
155
 
22
156
  // src/generated/core/serverSentEvents.gen.ts
23
157
  var createSseClient = ({
@@ -109,9 +243,11 @@ var createSseClient = ({
109
243
  }
110
244
  }
111
245
  if (parsedJson) {
246
+ data = applyResponseCaseTransforms(data);
112
247
  if (responseValidator) {
113
248
  await responseValidator(data);
114
249
  }
250
+ data = await applySseResponseTransforms(data);
115
251
  if (responseTransformer) {
116
252
  data = await responseTransformer(data);
117
253
  }
@@ -367,48 +503,6 @@ function getValidRequestBody(options) {
367
503
  return void 0;
368
504
  }
369
505
 
370
- // src/utils/transforms.ts
371
- var snakeToCamel = (value) => value.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
372
- var camelToSnake = (value) => value.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
373
- var isPlainObject = (value) => !!value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
374
- var mapKeysDeep = (value, mapKey) => {
375
- if (Array.isArray(value)) {
376
- return value.map((item) => mapKeysDeep(item, mapKey));
377
- }
378
- if (isPlainObject(value)) {
379
- const next = {};
380
- for (const [key, val] of Object.entries(value)) {
381
- next[mapKey(key)] = mapKeysDeep(val, mapKey);
382
- }
383
- return next;
384
- }
385
- return value;
386
- };
387
- var shouldTransformBody = (value) => isPlainObject(value) || Array.isArray(value);
388
- var snakecaseQuerySerializerParams = (value) => {
389
- if (!isPlainObject(value)) return value;
390
- if (!isPlainObject(value.parameters)) return value;
391
- const nextParameters = {};
392
- for (const [key, param] of Object.entries(value.parameters)) {
393
- nextParameters[camelToSnake(key)] = param;
394
- }
395
- return { ...value, parameters: nextParameters };
396
- };
397
- var applyRequestCaseTransforms = (options) => {
398
- const next = { ...options };
399
- if ("query" in next && isPlainObject(next.query)) {
400
- next.query = mapKeysDeep(next.query, camelToSnake);
401
- }
402
- if ("querySerializer" in next && next.querySerializer) {
403
- next.querySerializer = snakecaseQuerySerializerParams(next.querySerializer);
404
- }
405
- if ("body" in next && shouldTransformBody(next.body)) {
406
- next.body = mapKeysDeep(next.body, camelToSnake);
407
- }
408
- return next;
409
- };
410
- var applyResponseCaseTransforms = (value) => mapKeysDeep(value, snakeToCamel);
411
-
412
506
  // src/generated/core/auth.gen.ts
413
507
  var getAuthToken = async (auth, callback) => {
414
508
  const token = typeof callback === "function" ? await callback(auth) : callback;
@@ -895,14 +989,64 @@ var getBoardResponseTransformer = async (data) => {
895
989
  data.data = boardDtoSchemaResponseTransformer(data.data);
896
990
  return data;
897
991
  };
992
+ var publicDeploymentDtoSchemaResponseTransformer = (data) => {
993
+ data.deployedUsdAmount = u64DtoSchemaResponseTransformer(data.deployedUsdAmount);
994
+ return data;
995
+ };
996
+ var minerDtoSchemaResponseTransformer = (data) => {
997
+ data.hashrateAmount = u64DtoSchemaResponseTransformer(data.hashrateAmount);
998
+ data.unclaimedBtcShares = u64DtoSchemaResponseTransformer(data.unclaimedBtcShares);
999
+ data.unclaimedUsdAmount = u64DtoSchemaResponseTransformer(data.unclaimedUsdAmount);
1000
+ return data;
1001
+ };
1002
+ var profileDtoSchemaResponseTransformer = (data) => {
1003
+ data.deployments = data.deployments.map((item) => publicDeploymentDtoSchemaResponseTransformer(item));
1004
+ data.miner = minerDtoSchemaResponseTransformer(data.miner);
1005
+ return data;
1006
+ };
1007
+ var snapshotDtoSchemaResponseTransformer = (data) => {
1008
+ data.board = boardDtoSchemaResponseTransformer(data.board);
1009
+ if (data.profile) {
1010
+ data.profile = profileDtoSchemaResponseTransformer(data.profile);
1011
+ }
1012
+ return data;
1013
+ };
1014
+ var sseResponseSnapshotSchemaResponseTransformer = (data) => {
1015
+ data = snapshotDtoSchemaResponseTransformer(data);
1016
+ return data;
1017
+ };
1018
+ var sseResponseSchemaResponseTransformer = (data) => {
1019
+ data = sseResponseSnapshotSchemaResponseTransformer(data);
1020
+ return data;
1021
+ };
1022
+ var sseResponseTransformer = async (data) => {
1023
+ data = sseResponseSchemaResponseTransformer(data);
1024
+ return data;
1025
+ };
1026
+ var getUserProfileResponseTransformer = async (data) => {
1027
+ data.data = profileDtoSchemaResponseTransformer(data.data);
1028
+ return data;
1029
+ };
898
1030
 
899
1031
  // src/generated/zod.gen.ts
900
1032
  import * as z from "zod";
1033
+ var zBadRequestErrorCodeErrorBody = z.object({
1034
+ code: z.enum([
1035
+ "invalid_path",
1036
+ "invalid_query",
1037
+ "invalid_body"
1038
+ ])
1039
+ });
1040
+ var zFieldError = z.object({
1041
+ field: z.string(),
1042
+ message: z.string()
1043
+ });
901
1044
  var zI128Dto = z.string();
902
1045
  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
1046
  var zInternalErrorCodeErrorBody = z.object({
904
1047
  code: z.enum(["internal_error"])
905
1048
  });
1049
+ var zNotificationEntity = z.enum(["state_snapshot"]);
906
1050
  var zPubkeyDto = z.string().regex(/^[1-9A-HJ-NP-Za-km-z]+$/);
907
1051
  var zRoundStateDto = z.enum([
908
1052
  "active",
@@ -910,8 +1054,37 @@ var zRoundStateDto = z.enum([
910
1054
  "settled",
911
1055
  "finished"
912
1056
  ]);
1057
+ var zSatrushConfigDto = z.object({
1058
+ address: zPubkeyDto,
1059
+ btcMint: zPubkeyDto,
1060
+ epochFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1061
+ oneBtcFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1062
+ protocolFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1063
+ satsVaultClaimFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1064
+ satsVaultRoundFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1065
+ strikeFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1066
+ usdMint: zPubkeyDto
1067
+ });
913
1068
  var zU128Dto = z.string();
914
1069
  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" });
1070
+ var zMinerDto = z.object({
1071
+ authority: zPubkeyDto,
1072
+ currentStreakCount: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1073
+ hashrateAmount: zU64Dto,
1074
+ lastMinedRoundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1075
+ unclaimedBtcShares: zU64Dto,
1076
+ unclaimedUsdAmount: zU64Dto
1077
+ });
1078
+ var zPublicDeploymentDto = z.object({
1079
+ address: zPubkeyDto,
1080
+ deployedUsdAmount: zU64Dto,
1081
+ roundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1082
+ selectionMask: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" })
1083
+ });
1084
+ var zProfileDto = z.object({
1085
+ deployments: z.array(zPublicDeploymentDto),
1086
+ miner: zMinerDto
1087
+ });
915
1088
  var zStrikeJackpotDto = z.object({
916
1089
  btcAmount: zU64Dto,
917
1090
  lastTriggerRoundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
@@ -959,6 +1132,47 @@ var zBoardDto = z.object({
959
1132
  startSlot: zU64Dto,
960
1133
  strike: zStrikeJackpotDto
961
1134
  });
1135
+ var zSnapshotDto = z.object({
1136
+ board: zBoardDto,
1137
+ entity: zNotificationEntity,
1138
+ profile: z.optional(z.union([
1139
+ z.null(),
1140
+ zProfileDto
1141
+ ]))
1142
+ });
1143
+ var zSseResponseSnapshot = zSnapshotDto.and(z.object({
1144
+ entity: z.enum(["state_snapshot"])
1145
+ }));
1146
+ var zSseResponse = z.object({
1147
+ entity: z.literal("state_snapshot")
1148
+ }).and(zSseResponseSnapshot);
1149
+ var zUserProfileApiError400InvalidAddress = z.object({
1150
+ code: z.enum(["invalid_address"])
1151
+ });
1152
+ var zUserProfileApiError400Error = z.union([
1153
+ z.object({
1154
+ code: z.literal("invalid_address")
1155
+ }).and(zUserProfileApiError400InvalidAddress),
1156
+ z.object({
1157
+ code: z.union([
1158
+ z.literal("invalid_body"),
1159
+ z.literal("invalid_path"),
1160
+ z.literal("invalid_query")
1161
+ ])
1162
+ }).and(zBadRequestErrorCodeErrorBody)
1163
+ ]);
1164
+ var zValidationErrorCodeErrorBody = z.object({
1165
+ code: z.enum(["validation_failed"]),
1166
+ data: z.optional(z.object({
1167
+ errors: z.array(zFieldError)
1168
+ }))
1169
+ });
1170
+ var zValidationErrorCodeValidationDetailsErrorBody = z.object({
1171
+ code: z.enum(["validation_failed"]),
1172
+ data: z.optional(z.object({
1173
+ errors: z.array(zFieldError)
1174
+ }))
1175
+ });
962
1176
  var zGetBoardData = z.object({
963
1177
  body: z.optional(z.never()),
964
1178
  path: z.optional(z.never()),
@@ -967,6 +1181,32 @@ var zGetBoardData = z.object({
967
1181
  var zGetBoardResponse = z.object({
968
1182
  data: zBoardDto
969
1183
  });
1184
+ var zGetConfigData = z.object({
1185
+ body: z.optional(z.never()),
1186
+ path: z.optional(z.never()),
1187
+ query: z.optional(z.never())
1188
+ });
1189
+ var zGetConfigResponse = z.object({
1190
+ data: zSatrushConfigDto
1191
+ });
1192
+ var zSseData = z.object({
1193
+ body: z.optional(z.never()),
1194
+ path: z.optional(z.never()),
1195
+ query: z.optional(z.object({
1196
+ wallet: z.optional(z.string())
1197
+ }))
1198
+ });
1199
+ var zSseResponse2 = zSseResponse;
1200
+ var zGetUserProfileData = z.object({
1201
+ body: z.optional(z.never()),
1202
+ path: z.object({
1203
+ address: z.string()
1204
+ }),
1205
+ query: z.optional(z.never())
1206
+ });
1207
+ var zGetUserProfileResponse = z.object({
1208
+ data: zProfileDto
1209
+ });
970
1210
 
971
1211
  // src/generated/sdk.gen.ts
972
1212
  var HeyApiClient = class {
@@ -1007,9 +1247,49 @@ var SatrushBackendSdk = class _SatrushBackendSdk extends HeyApiClient {
1007
1247
  ...options
1008
1248
  });
1009
1249
  }
1250
+ /**
1251
+ * Request config
1252
+ */
1253
+ getConfig(options) {
1254
+ return (options?.client ?? this.client).get({
1255
+ requestValidator: async (data) => await zGetConfigData.parseAsync(data),
1256
+ responseValidator: async (data) => await zGetConfigResponse.parseAsync(data),
1257
+ url: "/v1/config",
1258
+ ...options
1259
+ });
1260
+ }
1261
+ /**
1262
+ * Subscribe for SSE stream
1263
+ */
1264
+ sse(parameters, options) {
1265
+ const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "wallet" }] }]);
1266
+ return (options?.client ?? this.client).sse.get({
1267
+ requestValidator: async (data) => await zSseData.parseAsync(data),
1268
+ responseTransformer: sseResponseTransformer,
1269
+ responseValidator: async (data) => await zSseResponse2.parseAsync(data),
1270
+ url: "/v1/streams/sse",
1271
+ ...options,
1272
+ ...params
1273
+ });
1274
+ }
1275
+ /**
1276
+ * Request user profile
1277
+ */
1278
+ getUserProfile(parameters, options) {
1279
+ const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "address" }] }]);
1280
+ return (options?.client ?? this.client).get({
1281
+ requestValidator: async (data) => await zGetUserProfileData.parseAsync(data),
1282
+ responseTransformer: getUserProfileResponseTransformer,
1283
+ responseValidator: async (data) => await zGetUserProfileResponse.parseAsync(data),
1284
+ url: "/v1/user/{address}/profile",
1285
+ ...options,
1286
+ ...params
1287
+ });
1288
+ }
1010
1289
  };
1011
1290
 
1012
1291
  // src/generated/types.gen.ts
1292
+ var NotificationEntity = { STATE_SNAPSHOT: "state_snapshot" };
1013
1293
  var RoundStateDto = {
1014
1294
  ACTIVE: "active",
1015
1295
  REVEALED: "revealed",
@@ -1049,7 +1329,11 @@ async function unwrap(promise) {
1049
1329
  if (res && typeof res === "object" && "response" in res) {
1050
1330
  const sdkRes = res;
1051
1331
  if ("error" in sdkRes && sdkRes.error !== void 0) {
1052
- throw new SatrushBackendSdkError(String(sdkRes.error), sdkRes.response?.status ?? 0, sdkRes.error);
1332
+ throw new SatrushBackendSdkError(
1333
+ String(sdkRes.error),
1334
+ sdkRes.response?.status ?? 0,
1335
+ sdkRes.error
1336
+ );
1053
1337
  }
1054
1338
  if ("data" in sdkRes) {
1055
1339
  return unwrapData(sdkRes.data);
@@ -1058,6 +1342,7 @@ async function unwrap(promise) {
1058
1342
  return unwrapData(res);
1059
1343
  }
1060
1344
  export {
1345
+ NotificationEntity,
1061
1346
  RoundStateDto,
1062
1347
  SatrushBackendSdk,
1063
1348
  SatrushBackendSdkError,
@@ -1066,17 +1351,37 @@ export {
1066
1351
  isSatrushSdkError,
1067
1352
  satrushSdkErrorInterceptor,
1068
1353
  unwrap,
1354
+ zBadRequestErrorCodeErrorBody,
1069
1355
  zBoardDto,
1356
+ zFieldError,
1070
1357
  zGetBoardData,
1071
1358
  zGetBoardResponse,
1359
+ zGetConfigData,
1360
+ zGetConfigResponse,
1361
+ zGetUserProfileData,
1362
+ zGetUserProfileResponse,
1072
1363
  zI128Dto,
1073
1364
  zI64Dto,
1074
1365
  zInternalErrorCodeErrorBody,
1366
+ zMinerDto,
1367
+ zNotificationEntity,
1368
+ zProfileDto,
1075
1369
  zPubkeyDto,
1370
+ zPublicDeploymentDto,
1076
1371
  zRoundDto,
1077
1372
  zRoundStateDto,
1373
+ zSatrushConfigDto,
1374
+ zSnapshotDto,
1375
+ zSseData,
1376
+ zSseResponse,
1377
+ zSseResponse2,
1378
+ zSseResponseSnapshot,
1078
1379
  zStrikeJackpotDto,
1079
1380
  zTileStakeDto,
1080
1381
  zU128Dto,
1081
- zU64Dto
1382
+ zU64Dto,
1383
+ zUserProfileApiError400Error,
1384
+ zUserProfileApiError400InvalidAddress,
1385
+ zValidationErrorCodeErrorBody,
1386
+ zValidationErrorCodeValidationDetailsErrorBody
1082
1387
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@satrush/api",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
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"