@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.js
CHANGED
|
@@ -104,6 +104,55 @@ var buildClientParams = (args, fields) => {
|
|
|
104
104
|
return params;
|
|
105
105
|
};
|
|
106
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);
|
|
155
|
+
|
|
107
156
|
// src/generated/core/serverSentEvents.gen.ts
|
|
108
157
|
var createSseClient = ({
|
|
109
158
|
onRequest,
|
|
@@ -194,9 +243,11 @@ var createSseClient = ({
|
|
|
194
243
|
}
|
|
195
244
|
}
|
|
196
245
|
if (parsedJson) {
|
|
246
|
+
data = applyResponseCaseTransforms(data);
|
|
197
247
|
if (responseValidator) {
|
|
198
248
|
await responseValidator(data);
|
|
199
249
|
}
|
|
250
|
+
data = await applySseResponseTransforms(data);
|
|
200
251
|
if (responseTransformer) {
|
|
201
252
|
data = await responseTransformer(data);
|
|
202
253
|
}
|
|
@@ -452,48 +503,6 @@ function getValidRequestBody(options) {
|
|
|
452
503
|
return void 0;
|
|
453
504
|
}
|
|
454
505
|
|
|
455
|
-
// src/utils/transforms.ts
|
|
456
|
-
var snakeToCamel = (value) => value.replace(/_([a-z0-9])/g, (_, c) => c.toUpperCase());
|
|
457
|
-
var camelToSnake = (value) => value.replace(/[A-Z]/g, (c) => `_${c.toLowerCase()}`);
|
|
458
|
-
var isPlainObject = (value) => !!value && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
|
|
459
|
-
var mapKeysDeep = (value, mapKey) => {
|
|
460
|
-
if (Array.isArray(value)) {
|
|
461
|
-
return value.map((item) => mapKeysDeep(item, mapKey));
|
|
462
|
-
}
|
|
463
|
-
if (isPlainObject(value)) {
|
|
464
|
-
const next = {};
|
|
465
|
-
for (const [key, val] of Object.entries(value)) {
|
|
466
|
-
next[mapKey(key)] = mapKeysDeep(val, mapKey);
|
|
467
|
-
}
|
|
468
|
-
return next;
|
|
469
|
-
}
|
|
470
|
-
return value;
|
|
471
|
-
};
|
|
472
|
-
var shouldTransformBody = (value) => isPlainObject(value) || Array.isArray(value);
|
|
473
|
-
var snakecaseQuerySerializerParams = (value) => {
|
|
474
|
-
if (!isPlainObject(value)) return value;
|
|
475
|
-
if (!isPlainObject(value.parameters)) return value;
|
|
476
|
-
const nextParameters = {};
|
|
477
|
-
for (const [key, param] of Object.entries(value.parameters)) {
|
|
478
|
-
nextParameters[camelToSnake(key)] = param;
|
|
479
|
-
}
|
|
480
|
-
return { ...value, parameters: nextParameters };
|
|
481
|
-
};
|
|
482
|
-
var applyRequestCaseTransforms = (options) => {
|
|
483
|
-
const next = { ...options };
|
|
484
|
-
if ("query" in next && isPlainObject(next.query)) {
|
|
485
|
-
next.query = mapKeysDeep(next.query, camelToSnake);
|
|
486
|
-
}
|
|
487
|
-
if ("querySerializer" in next && next.querySerializer) {
|
|
488
|
-
next.querySerializer = snakecaseQuerySerializerParams(next.querySerializer);
|
|
489
|
-
}
|
|
490
|
-
if ("body" in next && shouldTransformBody(next.body)) {
|
|
491
|
-
next.body = mapKeysDeep(next.body, camelToSnake);
|
|
492
|
-
}
|
|
493
|
-
return next;
|
|
494
|
-
};
|
|
495
|
-
var applyResponseCaseTransforms = (value) => mapKeysDeep(value, snakeToCamel);
|
|
496
|
-
|
|
497
506
|
// src/generated/core/auth.gen.ts
|
|
498
507
|
var getAuthToken = async (auth, callback) => {
|
|
499
508
|
const token = typeof callback === "function" ? await callback(auth) : callback;
|
|
@@ -995,6 +1004,25 @@ var profileDtoSchemaResponseTransformer = (data) => {
|
|
|
995
1004
|
data.miner = minerDtoSchemaResponseTransformer(data.miner);
|
|
996
1005
|
return data;
|
|
997
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
|
+
};
|
|
998
1026
|
var getUserProfileResponseTransformer = async (data) => {
|
|
999
1027
|
data.data = profileDtoSchemaResponseTransformer(data.data);
|
|
1000
1028
|
return data;
|
|
@@ -1018,6 +1046,7 @@ var zI64Dto = z.coerce.bigint().min(BigInt("-9223372036854775808"), { error: "In
|
|
|
1018
1046
|
var zInternalErrorCodeErrorBody = z.object({
|
|
1019
1047
|
code: z.enum(["internal_error"])
|
|
1020
1048
|
});
|
|
1049
|
+
var zNotificationEntity = z.enum(["state_snapshot"]);
|
|
1021
1050
|
var zPubkeyDto = z.string().regex(/^[1-9A-HJ-NP-Za-km-z]+$/);
|
|
1022
1051
|
var zRoundStateDto = z.enum([
|
|
1023
1052
|
"active",
|
|
@@ -1103,6 +1132,20 @@ var zBoardDto = z.object({
|
|
|
1103
1132
|
startSlot: zU64Dto,
|
|
1104
1133
|
strike: zStrikeJackpotDto
|
|
1105
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);
|
|
1106
1149
|
var zUserProfileApiError400InvalidAddress = z.object({
|
|
1107
1150
|
code: z.enum(["invalid_address"])
|
|
1108
1151
|
});
|
|
@@ -1146,6 +1189,14 @@ var zGetConfigData = z.object({
|
|
|
1146
1189
|
var zGetConfigResponse = z.object({
|
|
1147
1190
|
data: zSatrushConfigDto
|
|
1148
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;
|
|
1149
1200
|
var zGetUserProfileData = z.object({
|
|
1150
1201
|
body: z.optional(z.never()),
|
|
1151
1202
|
path: z.object({
|
|
@@ -1207,6 +1258,20 @@ var SatrushBackendSdk = class _SatrushBackendSdk extends HeyApiClient {
|
|
|
1207
1258
|
...options
|
|
1208
1259
|
});
|
|
1209
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
|
+
}
|
|
1210
1275
|
/**
|
|
1211
1276
|
* Request user profile
|
|
1212
1277
|
*/
|
|
@@ -1224,6 +1289,7 @@ var SatrushBackendSdk = class _SatrushBackendSdk extends HeyApiClient {
|
|
|
1224
1289
|
};
|
|
1225
1290
|
|
|
1226
1291
|
// src/generated/types.gen.ts
|
|
1292
|
+
var NotificationEntity = { STATE_SNAPSHOT: "state_snapshot" };
|
|
1227
1293
|
var RoundStateDto = {
|
|
1228
1294
|
ACTIVE: "active",
|
|
1229
1295
|
REVEALED: "revealed",
|
|
@@ -1276,6 +1342,7 @@ async function unwrap(promise) {
|
|
|
1276
1342
|
return unwrapData(res);
|
|
1277
1343
|
}
|
|
1278
1344
|
export {
|
|
1345
|
+
NotificationEntity,
|
|
1279
1346
|
RoundStateDto,
|
|
1280
1347
|
SatrushBackendSdk,
|
|
1281
1348
|
SatrushBackendSdkError,
|
|
@@ -1297,12 +1364,18 @@ export {
|
|
|
1297
1364
|
zI64Dto,
|
|
1298
1365
|
zInternalErrorCodeErrorBody,
|
|
1299
1366
|
zMinerDto,
|
|
1367
|
+
zNotificationEntity,
|
|
1300
1368
|
zProfileDto,
|
|
1301
1369
|
zPubkeyDto,
|
|
1302
1370
|
zPublicDeploymentDto,
|
|
1303
1371
|
zRoundDto,
|
|
1304
1372
|
zRoundStateDto,
|
|
1305
1373
|
zSatrushConfigDto,
|
|
1374
|
+
zSnapshotDto,
|
|
1375
|
+
zSseData,
|
|
1376
|
+
zSseResponse,
|
|
1377
|
+
zSseResponse2,
|
|
1378
|
+
zSseResponseSnapshot,
|
|
1306
1379
|
zStrikeJackpotDto,
|
|
1307
1380
|
zTileStakeDto,
|
|
1308
1381
|
zU128Dto,
|