@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 CHANGED
@@ -14,16 +14,14 @@ pnpm add @satrush/api
14
14
  ## Usage
15
15
 
16
16
  ```ts
17
- import {SatrushBackendSdk, createClient, unwrap} from "@satrush/api";
17
+ import { SatrushBackendSdk, createClient, unwrap } from '@satrush/api';
18
18
 
19
19
  const client = createClient({
20
- baseUrl: "https://api.satrush.io/api",
20
+ baseUrl: 'https://api.satrush.io/api'
21
21
  });
22
- const sdk = new SatrushBackendSdk({client});
22
+ const sdk = new SatrushBackendSdk({ client });
23
23
 
24
- const board = await unwrap(
25
- sdk.getBoard(),
26
- );
24
+ const board = await unwrap(sdk.getBoard());
27
25
  ```
28
26
 
29
27
  ## How the SDK works
@@ -32,10 +30,10 @@ const board = await unwrap(
32
30
  - Pre-processing: `scripts/camelizeOpenapi.mjs` produces `openapi.camel.yaml` (converts snake_case into cameCase).
33
31
  - Code generation: `@hey-api/openapi-ts` generates `src/generated/**`.
34
32
  - Post-processing: `scripts/postprocessOpenapi.mjs` patches the generated client to:
35
- - snake_case request payloads/params
36
- - camelCase response payloads
37
- - apply response transforms before validators where needed
38
- - apply custom SSE transforms (see below)
33
+ - snake_case request payloads/params
34
+ - camelCase response payloads
35
+ - apply response transforms before validators where needed
36
+ - apply custom SSE transforms (see below)
39
37
 
40
38
  ## Case transforms and scalar transforms
41
39
 
@@ -59,15 +57,19 @@ To throw on non-2xx responses for all SDK calls, set `throwOnError: true` on the
59
57
  and attach the built-in interceptor that wraps errors as `SatRushSdkError`:
60
58
 
61
59
  ```ts
62
- import {SatRushBackendSdk, createClient, satrushSdkErrorInterceptor} from "@satrush/api";
60
+ import {
61
+ SatRushBackendSdk,
62
+ createClient,
63
+ satrushSdkErrorInterceptor
64
+ } from '@satrush/api';
63
65
 
64
66
  const client = createClient({
65
- baseUrl: "https://api.satrush.io/api",
66
- throwOnError: true,
67
+ baseUrl: 'https://api.satrush.io/api',
68
+ throwOnError: true
67
69
  });
68
70
  client.interceptors.error.use(satrushSdkErrorInterceptor);
69
71
 
70
- const sdk = new SatRushBackendSdk({client});
72
+ const sdk = new SatRushBackendSdk({ client });
71
73
  ```
72
74
 
73
75
  `SatRushSdkError` includes the HTTP status and the original error payload in `cause`.
@@ -75,9 +77,9 @@ const sdk = new SatRushBackendSdk({client});
75
77
  If you already have a client, you can also enable it later:
76
78
 
77
79
  ```ts
78
- import {client, satrushSdkErrorInterceptor} from "@satrush/api";
80
+ import { client, satrushSdkErrorInterceptor } from '@satrush/api';
79
81
 
80
- client.setConfig({throwOnError: true});
82
+ client.setConfig({ throwOnError: true });
81
83
  client.interceptors.error.use(satrushSdkErrorInterceptor);
82
84
  ```
83
85
 
@@ -85,13 +87,13 @@ When `responseStyle` is set to `"data"`, SDK calls return only the response payl
85
87
  (no `{ data, error, request, response }` wrapper). This is useful for simpler call sites:
86
88
 
87
89
  ```ts
88
- import {SatRushBackendSdk, createClient} from "@satrush/api";
90
+ import { SatRushBackendSdk, createClient } from '@satrush/api';
89
91
 
90
92
  const client = createClient({
91
- baseUrl: "https://api.satrush.io/api",
92
- responseStyle: "data",
93
+ baseUrl: 'https://api.satrush.io/api',
94
+ responseStyle: 'data'
93
95
  });
94
96
 
95
- const sdk = new SatrushBackendSdk({client});
97
+ const sdk = new SatrushBackendSdk({ client });
96
98
  const board = await sdk.getBoard();
97
99
  ```
package/dist/index.cjs CHANGED
@@ -37,19 +37,33 @@ __export(index_exports, {
37
37
  isSatrushSdkError: () => isSatrushSdkError,
38
38
  satrushSdkErrorInterceptor: () => satrushSdkErrorInterceptor,
39
39
  unwrap: () => unwrap,
40
+ zBadRequestErrorCodeErrorBody: () => zBadRequestErrorCodeErrorBody,
40
41
  zBoardDto: () => zBoardDto,
42
+ zFieldError: () => zFieldError,
41
43
  zGetBoardData: () => zGetBoardData,
42
44
  zGetBoardResponse: () => zGetBoardResponse,
45
+ zGetConfigData: () => zGetConfigData,
46
+ zGetConfigResponse: () => zGetConfigResponse,
47
+ zGetUserProfileData: () => zGetUserProfileData,
48
+ zGetUserProfileResponse: () => zGetUserProfileResponse,
43
49
  zI128Dto: () => zI128Dto,
44
50
  zI64Dto: () => zI64Dto,
45
51
  zInternalErrorCodeErrorBody: () => zInternalErrorCodeErrorBody,
52
+ zMinerDto: () => zMinerDto,
53
+ zProfileDto: () => zProfileDto,
46
54
  zPubkeyDto: () => zPubkeyDto,
55
+ zPublicDeploymentDto: () => zPublicDeploymentDto,
47
56
  zRoundDto: () => zRoundDto,
48
57
  zRoundStateDto: () => zRoundStateDto,
58
+ zSatrushConfigDto: () => zSatrushConfigDto,
49
59
  zStrikeJackpotDto: () => zStrikeJackpotDto,
50
60
  zTileStakeDto: () => zTileStakeDto,
51
61
  zU128Dto: () => zU128Dto,
52
- zU64Dto: () => zU64Dto
62
+ zU64Dto: () => zU64Dto,
63
+ zUserProfileApiError400Error: () => zUserProfileApiError400Error,
64
+ zUserProfileApiError400InvalidAddress: () => zUserProfileApiError400InvalidAddress,
65
+ zValidationErrorCodeErrorBody: () => zValidationErrorCodeErrorBody,
66
+ zValidationErrorCodeValidationDetailsErrorBody: () => zValidationErrorCodeValidationDetailsErrorBody
53
67
  });
54
68
  module.exports = __toCommonJS(index_exports);
55
69
 
@@ -73,6 +87,91 @@ var extraPrefixesMap = {
73
87
  $query_: "query"
74
88
  };
75
89
  var extraPrefixes = Object.entries(extraPrefixesMap);
90
+ var buildKeyMap = (fields, map) => {
91
+ if (!map) {
92
+ map = /* @__PURE__ */ new Map();
93
+ }
94
+ for (const config of fields) {
95
+ if ("in" in config) {
96
+ if (config.key) {
97
+ map.set(config.key, {
98
+ in: config.in,
99
+ map: config.map
100
+ });
101
+ }
102
+ } else if ("key" in config) {
103
+ map.set(config.key, {
104
+ map: config.map
105
+ });
106
+ } else if (config.args) {
107
+ buildKeyMap(config.args, map);
108
+ }
109
+ }
110
+ return map;
111
+ };
112
+ var stripEmptySlots = (params) => {
113
+ for (const [slot, value] of Object.entries(params)) {
114
+ if (value && typeof value === "object" && !Object.keys(value).length) {
115
+ delete params[slot];
116
+ }
117
+ }
118
+ };
119
+ var buildClientParams = (args, fields) => {
120
+ const params = {
121
+ body: {},
122
+ headers: {},
123
+ path: {},
124
+ query: {}
125
+ };
126
+ const map = buildKeyMap(fields);
127
+ let config;
128
+ for (const [index, arg] of args.entries()) {
129
+ if (fields[index]) {
130
+ config = fields[index];
131
+ }
132
+ if (!config) {
133
+ continue;
134
+ }
135
+ if ("in" in config) {
136
+ if (config.key) {
137
+ const field = map.get(config.key);
138
+ const name = field.map || config.key;
139
+ if (field.in) {
140
+ params[field.in][name] = arg;
141
+ }
142
+ } else {
143
+ params.body = arg;
144
+ }
145
+ } else {
146
+ for (const [key, value] of Object.entries(arg ?? {})) {
147
+ const field = map.get(key);
148
+ if (field) {
149
+ if (field.in) {
150
+ const name = field.map || key;
151
+ params[field.in][name] = value;
152
+ } else {
153
+ params[field.map] = value;
154
+ }
155
+ } else {
156
+ const extra = extraPrefixes.find(([prefix]) => key.startsWith(prefix));
157
+ if (extra) {
158
+ const [prefix, slot] = extra;
159
+ params[slot][key.slice(prefix.length)] = value;
160
+ } else if ("allowExtra" in config && config.allowExtra) {
161
+ for (const [slot, allowed] of Object.entries(config.allowExtra)) {
162
+ if (allowed) {
163
+ params[slot][key] = value;
164
+ break;
165
+ }
166
+ }
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+ stripEmptySlots(params);
173
+ return params;
174
+ };
76
175
 
77
176
  // src/generated/core/serverSentEvents.gen.ts
78
177
  var createSseClient = ({
@@ -950,9 +1049,39 @@ var getBoardResponseTransformer = async (data) => {
950
1049
  data.data = boardDtoSchemaResponseTransformer(data.data);
951
1050
  return data;
952
1051
  };
1052
+ var publicDeploymentDtoSchemaResponseTransformer = (data) => {
1053
+ data.deployedUsdAmount = u64DtoSchemaResponseTransformer(data.deployedUsdAmount);
1054
+ return data;
1055
+ };
1056
+ var minerDtoSchemaResponseTransformer = (data) => {
1057
+ data.hashrateAmount = u64DtoSchemaResponseTransformer(data.hashrateAmount);
1058
+ data.unclaimedBtcShares = u64DtoSchemaResponseTransformer(data.unclaimedBtcShares);
1059
+ data.unclaimedUsdAmount = u64DtoSchemaResponseTransformer(data.unclaimedUsdAmount);
1060
+ return data;
1061
+ };
1062
+ var profileDtoSchemaResponseTransformer = (data) => {
1063
+ data.deployments = data.deployments.map((item) => publicDeploymentDtoSchemaResponseTransformer(item));
1064
+ data.miner = minerDtoSchemaResponseTransformer(data.miner);
1065
+ return data;
1066
+ };
1067
+ var getUserProfileResponseTransformer = async (data) => {
1068
+ data.data = profileDtoSchemaResponseTransformer(data.data);
1069
+ return data;
1070
+ };
953
1071
 
954
1072
  // src/generated/zod.gen.ts
955
1073
  var z = __toESM(require("zod"), 1);
1074
+ var zBadRequestErrorCodeErrorBody = z.object({
1075
+ code: z.enum([
1076
+ "invalid_path",
1077
+ "invalid_query",
1078
+ "invalid_body"
1079
+ ])
1080
+ });
1081
+ var zFieldError = z.object({
1082
+ field: z.string(),
1083
+ message: z.string()
1084
+ });
956
1085
  var zI128Dto = z.string();
957
1086
  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" });
958
1087
  var zInternalErrorCodeErrorBody = z.object({
@@ -965,8 +1094,37 @@ var zRoundStateDto = z.enum([
965
1094
  "settled",
966
1095
  "finished"
967
1096
  ]);
1097
+ var zSatrushConfigDto = z.object({
1098
+ address: zPubkeyDto,
1099
+ btcMint: zPubkeyDto,
1100
+ epochFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1101
+ oneBtcFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1102
+ protocolFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1103
+ satsVaultClaimFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1104
+ satsVaultRoundFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1105
+ strikeFeeBps: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1106
+ usdMint: zPubkeyDto
1107
+ });
968
1108
  var zU128Dto = z.string();
969
1109
  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" });
1110
+ var zMinerDto = z.object({
1111
+ authority: zPubkeyDto,
1112
+ currentStreakCount: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1113
+ hashrateAmount: zU64Dto,
1114
+ lastMinedRoundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1115
+ unclaimedBtcShares: zU64Dto,
1116
+ unclaimedUsdAmount: zU64Dto
1117
+ });
1118
+ var zPublicDeploymentDto = z.object({
1119
+ address: zPubkeyDto,
1120
+ deployedUsdAmount: zU64Dto,
1121
+ roundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
1122
+ selectionMask: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" })
1123
+ });
1124
+ var zProfileDto = z.object({
1125
+ deployments: z.array(zPublicDeploymentDto),
1126
+ miner: zMinerDto
1127
+ });
970
1128
  var zStrikeJackpotDto = z.object({
971
1129
  btcAmount: zU64Dto,
972
1130
  lastTriggerRoundId: z.int().gte(0).max(2147483647, { error: "Invalid value: Expected int32 to be <= 2147483647" }),
@@ -1014,6 +1172,33 @@ var zBoardDto = z.object({
1014
1172
  startSlot: zU64Dto,
1015
1173
  strike: zStrikeJackpotDto
1016
1174
  });
1175
+ var zUserProfileApiError400InvalidAddress = z.object({
1176
+ code: z.enum(["invalid_address"])
1177
+ });
1178
+ var zUserProfileApiError400Error = z.union([
1179
+ z.object({
1180
+ code: z.literal("invalid_address")
1181
+ }).and(zUserProfileApiError400InvalidAddress),
1182
+ z.object({
1183
+ code: z.union([
1184
+ z.literal("invalid_body"),
1185
+ z.literal("invalid_path"),
1186
+ z.literal("invalid_query")
1187
+ ])
1188
+ }).and(zBadRequestErrorCodeErrorBody)
1189
+ ]);
1190
+ var zValidationErrorCodeErrorBody = z.object({
1191
+ code: z.enum(["validation_failed"]),
1192
+ data: z.optional(z.object({
1193
+ errors: z.array(zFieldError)
1194
+ }))
1195
+ });
1196
+ var zValidationErrorCodeValidationDetailsErrorBody = z.object({
1197
+ code: z.enum(["validation_failed"]),
1198
+ data: z.optional(z.object({
1199
+ errors: z.array(zFieldError)
1200
+ }))
1201
+ });
1017
1202
  var zGetBoardData = z.object({
1018
1203
  body: z.optional(z.never()),
1019
1204
  path: z.optional(z.never()),
@@ -1022,6 +1207,24 @@ var zGetBoardData = z.object({
1022
1207
  var zGetBoardResponse = z.object({
1023
1208
  data: zBoardDto
1024
1209
  });
1210
+ var zGetConfigData = z.object({
1211
+ body: z.optional(z.never()),
1212
+ path: z.optional(z.never()),
1213
+ query: z.optional(z.never())
1214
+ });
1215
+ var zGetConfigResponse = z.object({
1216
+ data: zSatrushConfigDto
1217
+ });
1218
+ var zGetUserProfileData = z.object({
1219
+ body: z.optional(z.never()),
1220
+ path: z.object({
1221
+ address: z.string()
1222
+ }),
1223
+ query: z.optional(z.never())
1224
+ });
1225
+ var zGetUserProfileResponse = z.object({
1226
+ data: zProfileDto
1227
+ });
1025
1228
 
1026
1229
  // src/generated/sdk.gen.ts
1027
1230
  var HeyApiClient = class {
@@ -1062,6 +1265,31 @@ var SatrushBackendSdk = class _SatrushBackendSdk extends HeyApiClient {
1062
1265
  ...options
1063
1266
  });
1064
1267
  }
1268
+ /**
1269
+ * Request config
1270
+ */
1271
+ getConfig(options) {
1272
+ return (options?.client ?? this.client).get({
1273
+ requestValidator: async (data) => await zGetConfigData.parseAsync(data),
1274
+ responseValidator: async (data) => await zGetConfigResponse.parseAsync(data),
1275
+ url: "/v1/config",
1276
+ ...options
1277
+ });
1278
+ }
1279
+ /**
1280
+ * Request user profile
1281
+ */
1282
+ getUserProfile(parameters, options) {
1283
+ const params = buildClientParams([parameters], [{ args: [{ in: "path", key: "address" }] }]);
1284
+ return (options?.client ?? this.client).get({
1285
+ requestValidator: async (data) => await zGetUserProfileData.parseAsync(data),
1286
+ responseTransformer: getUserProfileResponseTransformer,
1287
+ responseValidator: async (data) => await zGetUserProfileResponse.parseAsync(data),
1288
+ url: "/v1/user/{address}/profile",
1289
+ ...options,
1290
+ ...params
1291
+ });
1292
+ }
1065
1293
  };
1066
1294
 
1067
1295
  // src/generated/types.gen.ts
@@ -1104,7 +1332,11 @@ async function unwrap(promise) {
1104
1332
  if (res && typeof res === "object" && "response" in res) {
1105
1333
  const sdkRes = res;
1106
1334
  if ("error" in sdkRes && sdkRes.error !== void 0) {
1107
- throw new SatrushBackendSdkError(String(sdkRes.error), sdkRes.response?.status ?? 0, sdkRes.error);
1335
+ throw new SatrushBackendSdkError(
1336
+ String(sdkRes.error),
1337
+ sdkRes.response?.status ?? 0,
1338
+ sdkRes.error
1339
+ );
1108
1340
  }
1109
1341
  if ("data" in sdkRes) {
1110
1342
  return unwrapData(sdkRes.data);
@@ -1122,17 +1354,31 @@ async function unwrap(promise) {
1122
1354
  isSatrushSdkError,
1123
1355
  satrushSdkErrorInterceptor,
1124
1356
  unwrap,
1357
+ zBadRequestErrorCodeErrorBody,
1125
1358
  zBoardDto,
1359
+ zFieldError,
1126
1360
  zGetBoardData,
1127
1361
  zGetBoardResponse,
1362
+ zGetConfigData,
1363
+ zGetConfigResponse,
1364
+ zGetUserProfileData,
1365
+ zGetUserProfileResponse,
1128
1366
  zI128Dto,
1129
1367
  zI64Dto,
1130
1368
  zInternalErrorCodeErrorBody,
1369
+ zMinerDto,
1370
+ zProfileDto,
1131
1371
  zPubkeyDto,
1372
+ zPublicDeploymentDto,
1132
1373
  zRoundDto,
1133
1374
  zRoundStateDto,
1375
+ zSatrushConfigDto,
1134
1376
  zStrikeJackpotDto,
1135
1377
  zTileStakeDto,
1136
1378
  zU128Dto,
1137
- zU64Dto
1379
+ zU64Dto,
1380
+ zUserProfileApiError400Error,
1381
+ zUserProfileApiError400InvalidAddress,
1382
+ zValidationErrorCodeErrorBody,
1383
+ zValidationErrorCodeValidationDetailsErrorBody
1138
1384
  });