@satrush/api 0.1.1 → 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.cjs +122 -42
- package/dist/index.d.cts +420 -1
- package/dist/index.d.ts +420 -1
- package/dist/index.js +115 -42
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
29
29
|
// src/index.ts
|
|
30
30
|
var index_exports = {};
|
|
31
31
|
__export(index_exports, {
|
|
32
|
+
NotificationEntity: () => NotificationEntity,
|
|
32
33
|
RoundStateDto: () => RoundStateDto,
|
|
33
34
|
SatrushBackendSdk: () => SatrushBackendSdk,
|
|
34
35
|
SatrushBackendSdkError: () => SatrushBackendSdkError,
|
|
@@ -50,12 +51,18 @@ __export(index_exports, {
|
|
|
50
51
|
zI64Dto: () => zI64Dto,
|
|
51
52
|
zInternalErrorCodeErrorBody: () => zInternalErrorCodeErrorBody,
|
|
52
53
|
zMinerDto: () => zMinerDto,
|
|
54
|
+
zNotificationEntity: () => zNotificationEntity,
|
|
53
55
|
zProfileDto: () => zProfileDto,
|
|
54
56
|
zPubkeyDto: () => zPubkeyDto,
|
|
55
57
|
zPublicDeploymentDto: () => zPublicDeploymentDto,
|
|
56
58
|
zRoundDto: () => zRoundDto,
|
|
57
59
|
zRoundStateDto: () => zRoundStateDto,
|
|
58
60
|
zSatrushConfigDto: () => zSatrushConfigDto,
|
|
61
|
+
zSnapshotDto: () => zSnapshotDto,
|
|
62
|
+
zSseData: () => zSseData,
|
|
63
|
+
zSseResponse: () => zSseResponse,
|
|
64
|
+
zSseResponse2: () => zSseResponse2,
|
|
65
|
+
zSseResponseSnapshot: () => zSseResponseSnapshot,
|
|
59
66
|
zStrikeJackpotDto: () => zStrikeJackpotDto,
|
|
60
67
|
zTileStakeDto: () => zTileStakeDto,
|
|
61
68
|
zU128Dto: () => zU128Dto,
|
|
@@ -173,6 +180,55 @@ var buildClientParams = (args, fields) => {
|
|
|
173
180
|
return params;
|
|
174
181
|
};
|
|
175
182
|
|
|
183
|
+
// src/utils/sse.ts
|
|
184
|
+
var isRecord = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
185
|
+
var applySseResponseTransforms = async (payload) => {
|
|
186
|
+
if (!isRecord(payload)) return payload;
|
|
187
|
+
return payload;
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
// src/utils/transforms.ts
|
|
191
|
+
var snakeToCamel = (value) => value.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
192
|
+
var camelToSnake = (value) => value.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
|
|
193
|
+
var isPlainObject = (value) => !!value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
|
|
194
|
+
var mapKeysDeep = (value, mapKey) => {
|
|
195
|
+
if (Array.isArray(value)) {
|
|
196
|
+
return value.map((item) => mapKeysDeep(item, mapKey));
|
|
197
|
+
}
|
|
198
|
+
if (isPlainObject(value)) {
|
|
199
|
+
const next = {};
|
|
200
|
+
for (const [key, val] of Object.entries(value)) {
|
|
201
|
+
next[mapKey(key)] = mapKeysDeep(val, mapKey);
|
|
202
|
+
}
|
|
203
|
+
return next;
|
|
204
|
+
}
|
|
205
|
+
return value;
|
|
206
|
+
};
|
|
207
|
+
var shouldTransformBody = (value) => isPlainObject(value) || Array.isArray(value);
|
|
208
|
+
var snakecaseQuerySerializerParams = (value) => {
|
|
209
|
+
if (!isPlainObject(value)) return value;
|
|
210
|
+
if (!isPlainObject(value.parameters)) return value;
|
|
211
|
+
const nextParameters = {};
|
|
212
|
+
for (const [key, param] of Object.entries(value.parameters)) {
|
|
213
|
+
nextParameters[camelToSnake(key)] = param;
|
|
214
|
+
}
|
|
215
|
+
return { ...value, parameters: nextParameters };
|
|
216
|
+
};
|
|
217
|
+
var applyRequestCaseTransforms = (options) => {
|
|
218
|
+
const next = { ...options };
|
|
219
|
+
if ("query" in next && isPlainObject(next.query)) {
|
|
220
|
+
next.query = mapKeysDeep(next.query, camelToSnake);
|
|
221
|
+
}
|
|
222
|
+
if ("querySerializer" in next && next.querySerializer) {
|
|
223
|
+
next.querySerializer = snakecaseQuerySerializerParams(next.querySerializer);
|
|
224
|
+
}
|
|
225
|
+
if ("body" in next && shouldTransformBody(next.body)) {
|
|
226
|
+
next.body = mapKeysDeep(next.body, camelToSnake);
|
|
227
|
+
}
|
|
228
|
+
return next;
|
|
229
|
+
};
|
|
230
|
+
var applyResponseCaseTransforms = (value) => mapKeysDeep(value, snakeToCamel);
|
|
231
|
+
|
|
176
232
|
// src/generated/core/serverSentEvents.gen.ts
|
|
177
233
|
var createSseClient = ({
|
|
178
234
|
onRequest,
|
|
@@ -263,9 +319,11 @@ var createSseClient = ({
|
|
|
263
319
|
}
|
|
264
320
|
}
|
|
265
321
|
if (parsedJson) {
|
|
322
|
+
data = applyResponseCaseTransforms(data);
|
|
266
323
|
if (responseValidator) {
|
|
267
324
|
await responseValidator(data);
|
|
268
325
|
}
|
|
326
|
+
data = await applySseResponseTransforms(data);
|
|
269
327
|
if (responseTransformer) {
|
|
270
328
|
data = await responseTransformer(data);
|
|
271
329
|
}
|
|
@@ -521,48 +579,6 @@ function getValidRequestBody(options) {
|
|
|
521
579
|
return void 0;
|
|
522
580
|
}
|
|
523
581
|
|
|
524
|
-
// src/utils/transforms.ts
|
|
525
|
-
var snakeToCamel = (value) => value.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
526
|
-
var camelToSnake = (value) => value.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
|
|
527
|
-
var isPlainObject = (value) => !!value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
|
|
528
|
-
var mapKeysDeep = (value, mapKey) => {
|
|
529
|
-
if (Array.isArray(value)) {
|
|
530
|
-
return value.map((item) => mapKeysDeep(item, mapKey));
|
|
531
|
-
}
|
|
532
|
-
if (isPlainObject(value)) {
|
|
533
|
-
const next = {};
|
|
534
|
-
for (const [key, val] of Object.entries(value)) {
|
|
535
|
-
next[mapKey(key)] = mapKeysDeep(val, mapKey);
|
|
536
|
-
}
|
|
537
|
-
return next;
|
|
538
|
-
}
|
|
539
|
-
return value;
|
|
540
|
-
};
|
|
541
|
-
var shouldTransformBody = (value) => isPlainObject(value) || Array.isArray(value);
|
|
542
|
-
var snakecaseQuerySerializerParams = (value) => {
|
|
543
|
-
if (!isPlainObject(value)) return value;
|
|
544
|
-
if (!isPlainObject(value.parameters)) return value;
|
|
545
|
-
const nextParameters = {};
|
|
546
|
-
for (const [key, param] of Object.entries(value.parameters)) {
|
|
547
|
-
nextParameters[camelToSnake(key)] = param;
|
|
548
|
-
}
|
|
549
|
-
return { ...value, parameters: nextParameters };
|
|
550
|
-
};
|
|
551
|
-
var applyRequestCaseTransforms = (options) => {
|
|
552
|
-
const next = { ...options };
|
|
553
|
-
if ("query" in next && isPlainObject(next.query)) {
|
|
554
|
-
next.query = mapKeysDeep(next.query, camelToSnake);
|
|
555
|
-
}
|
|
556
|
-
if ("querySerializer" in next && next.querySerializer) {
|
|
557
|
-
next.querySerializer = snakecaseQuerySerializerParams(next.querySerializer);
|
|
558
|
-
}
|
|
559
|
-
if ("body" in next && shouldTransformBody(next.body)) {
|
|
560
|
-
next.body = mapKeysDeep(next.body, camelToSnake);
|
|
561
|
-
}
|
|
562
|
-
return next;
|
|
563
|
-
};
|
|
564
|
-
var applyResponseCaseTransforms = (value) => mapKeysDeep(value, snakeToCamel);
|
|
565
|
-
|
|
566
582
|
// src/generated/core/auth.gen.ts
|
|
567
583
|
var getAuthToken = async (auth, callback) => {
|
|
568
584
|
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
@@ -1064,6 +1080,25 @@ var profileDtoSchemaResponseTransformer = (data) => {
|
|
|
1064
1080
|
data.miner = minerDtoSchemaResponseTransformer(data.miner);
|
|
1065
1081
|
return data;
|
|
1066
1082
|
};
|
|
1083
|
+
var snapshotDtoSchemaResponseTransformer = (data) => {
|
|
1084
|
+
data.board = boardDtoSchemaResponseTransformer(data.board);
|
|
1085
|
+
if (data.profile) {
|
|
1086
|
+
data.profile = profileDtoSchemaResponseTransformer(data.profile);
|
|
1087
|
+
}
|
|
1088
|
+
return data;
|
|
1089
|
+
};
|
|
1090
|
+
var sseResponseSnapshotSchemaResponseTransformer = (data) => {
|
|
1091
|
+
data = snapshotDtoSchemaResponseTransformer(data);
|
|
1092
|
+
return data;
|
|
1093
|
+
};
|
|
1094
|
+
var sseResponseSchemaResponseTransformer = (data) => {
|
|
1095
|
+
data = sseResponseSnapshotSchemaResponseTransformer(data);
|
|
1096
|
+
return data;
|
|
1097
|
+
};
|
|
1098
|
+
var sseResponseTransformer = async (data) => {
|
|
1099
|
+
data = sseResponseSchemaResponseTransformer(data);
|
|
1100
|
+
return data;
|
|
1101
|
+
};
|
|
1067
1102
|
var getUserProfileResponseTransformer = async (data) => {
|
|
1068
1103
|
data.data = profileDtoSchemaResponseTransformer(data.data);
|
|
1069
1104
|
return data;
|
|
@@ -1087,6 +1122,7 @@ var zI64Dto = z.coerce.bigint().min(BigInt("-9223372036854775808"), { error: "In
|
|
|
1087
1122
|
var zInternalErrorCodeErrorBody = z.object({
|
|
1088
1123
|
code: z.enum(["internal_error"])
|
|
1089
1124
|
});
|
|
1125
|
+
var zNotificationEntity = z.enum(["state_snapshot"]);
|
|
1090
1126
|
var zPubkeyDto = z.string().regex(/^[1-9A-HJ-NP-Za-km-z]+$/);
|
|
1091
1127
|
var zRoundStateDto = z.enum([
|
|
1092
1128
|
"active",
|
|
@@ -1172,6 +1208,20 @@ var zBoardDto = z.object({
|
|
|
1172
1208
|
startSlot: zU64Dto,
|
|
1173
1209
|
strike: zStrikeJackpotDto
|
|
1174
1210
|
});
|
|
1211
|
+
var zSnapshotDto = z.object({
|
|
1212
|
+
board: zBoardDto,
|
|
1213
|
+
entity: zNotificationEntity,
|
|
1214
|
+
profile: z.optional(z.union([
|
|
1215
|
+
z.null(),
|
|
1216
|
+
zProfileDto
|
|
1217
|
+
]))
|
|
1218
|
+
});
|
|
1219
|
+
var zSseResponseSnapshot = zSnapshotDto.and(z.object({
|
|
1220
|
+
entity: z.enum(["state_snapshot"])
|
|
1221
|
+
}));
|
|
1222
|
+
var zSseResponse = z.object({
|
|
1223
|
+
entity: z.literal("state_snapshot")
|
|
1224
|
+
}).and(zSseResponseSnapshot);
|
|
1175
1225
|
var zUserProfileApiError400InvalidAddress = z.object({
|
|
1176
1226
|
code: z.enum(["invalid_address"])
|
|
1177
1227
|
});
|
|
@@ -1215,6 +1265,14 @@ var zGetConfigData = z.object({
|
|
|
1215
1265
|
var zGetConfigResponse = z.object({
|
|
1216
1266
|
data: zSatrushConfigDto
|
|
1217
1267
|
});
|
|
1268
|
+
var zSseData = z.object({
|
|
1269
|
+
body: z.optional(z.never()),
|
|
1270
|
+
path: z.optional(z.never()),
|
|
1271
|
+
query: z.optional(z.object({
|
|
1272
|
+
wallet: z.optional(z.string())
|
|
1273
|
+
}))
|
|
1274
|
+
});
|
|
1275
|
+
var zSseResponse2 = zSseResponse;
|
|
1218
1276
|
var zGetUserProfileData = z.object({
|
|
1219
1277
|
body: z.optional(z.never()),
|
|
1220
1278
|
path: z.object({
|
|
@@ -1276,6 +1334,20 @@ var SatrushBackendSdk = class _SatrushBackendSdk extends HeyApiClient {
|
|
|
1276
1334
|
...options
|
|
1277
1335
|
});
|
|
1278
1336
|
}
|
|
1337
|
+
/**
|
|
1338
|
+
* Subscribe for SSE stream
|
|
1339
|
+
*/
|
|
1340
|
+
sse(parameters, options) {
|
|
1341
|
+
const params = buildClientParams([parameters], [{ args: [{ in: "query", key: "wallet" }] }]);
|
|
1342
|
+
return (options?.client ?? this.client).sse.get({
|
|
1343
|
+
requestValidator: async (data) => await zSseData.parseAsync(data),
|
|
1344
|
+
responseTransformer: sseResponseTransformer,
|
|
1345
|
+
responseValidator: async (data) => await zSseResponse2.parseAsync(data),
|
|
1346
|
+
url: "/v1/streams/sse",
|
|
1347
|
+
...options,
|
|
1348
|
+
...params
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1279
1351
|
/**
|
|
1280
1352
|
* Request user profile
|
|
1281
1353
|
*/
|
|
@@ -1293,6 +1365,7 @@ var SatrushBackendSdk = class _SatrushBackendSdk extends HeyApiClient {
|
|
|
1293
1365
|
};
|
|
1294
1366
|
|
|
1295
1367
|
// src/generated/types.gen.ts
|
|
1368
|
+
var NotificationEntity = { STATE_SNAPSHOT: "state_snapshot" };
|
|
1296
1369
|
var RoundStateDto = {
|
|
1297
1370
|
ACTIVE: "active",
|
|
1298
1371
|
REVEALED: "revealed",
|
|
@@ -1346,6 +1419,7 @@ async function unwrap(promise) {
|
|
|
1346
1419
|
}
|
|
1347
1420
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1348
1421
|
0 && (module.exports = {
|
|
1422
|
+
NotificationEntity,
|
|
1349
1423
|
RoundStateDto,
|
|
1350
1424
|
SatrushBackendSdk,
|
|
1351
1425
|
SatrushBackendSdkError,
|
|
@@ -1367,12 +1441,18 @@ async function unwrap(promise) {
|
|
|
1367
1441
|
zI64Dto,
|
|
1368
1442
|
zInternalErrorCodeErrorBody,
|
|
1369
1443
|
zMinerDto,
|
|
1444
|
+
zNotificationEntity,
|
|
1370
1445
|
zProfileDto,
|
|
1371
1446
|
zPubkeyDto,
|
|
1372
1447
|
zPublicDeploymentDto,
|
|
1373
1448
|
zRoundDto,
|
|
1374
1449
|
zRoundStateDto,
|
|
1375
1450
|
zSatrushConfigDto,
|
|
1451
|
+
zSnapshotDto,
|
|
1452
|
+
zSseData,
|
|
1453
|
+
zSseResponse,
|
|
1454
|
+
zSseResponse2,
|
|
1455
|
+
zSseResponseSnapshot,
|
|
1376
1456
|
zStrikeJackpotDto,
|
|
1377
1457
|
zTileStakeDto,
|
|
1378
1458
|
zU128Dto,
|