Skip to content

Commit 3666f87

Browse files
committed
chore: normalize responses from hyperbeam
1 parent 2d5135e commit 3666f87

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

connect/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@permaweb/aoconnect",
3-
"version": "0.0.92",
3+
"version": "0.0.93",
44
"repository": {
55
"type": "git",
66
"url": "https://github.com/permaweb/ao.git",

connect/src/client/ao-core.js

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
import { debugLog } from '../logger.js'
22

3-
function convertToLegacyOutput(jsonRes) {
4-
let body = {}
3+
function normalizeOutput(jsonRes) {
4+
debugLog('info', 'HyperBEAM Response Body Raw:', jsonRes);
5+
6+
let body = {};
57
try {
6-
body = JSON.parse(jsonRes?.results?.json?.body)
7-
debugLog('info', 'HyperBEAM Response Body:', body)
8-
} catch (_) { }
8+
body = typeof jsonRes === 'string'
9+
? JSON.parse(jsonRes?.results?.json?.body)
10+
: jsonRes?.results?.raw ?? {};
11+
} catch {}
912

10-
debugLog('info', 'Parsed HyperBEAM Response Body:', body)
13+
debugLog('info', 'Parsed HyperBEAM Response Body:', body);
1114

1215
return {
13-
Output: body?.Output || {},
14-
Messages: body?.Messages || [],
15-
Assignments: body?.Assignments || [],
16-
Spawns: body?.Spawns || [],
17-
Error: body?.Error,
18-
...(body ?? {})
19-
}
16+
Output: body.Output ?? {},
17+
Messages: body.Messages ?? [],
18+
Assignments: body.Assignments ?? [],
19+
Spawns: body.Spawns ?? [],
20+
Error: body.Error,
21+
...body,
22+
};
2023
}
2124

2225
const baseParams = {
@@ -122,7 +125,7 @@ export function messageWith(deps) {
122125
if (response.ok) {
123126
const parsedResponse = await response.json()
124127

125-
if (args.opts?.fullResponse) return convertToLegacyOutput(parsedResponse)
128+
if (args.opts?.fullResponse) return normalizeOutput(parsedResponse)
126129
else return parsedResponse.slot
127130
}
128131
else throw new Error('Error sending message')
@@ -145,7 +148,7 @@ export function resultWith(deps) {
145148
const response = await deps.aoCore.request(params)
146149
if (response.ok) {
147150
const parsedResponse = await response.json()
148-
return convertToLegacyOutput(parsedResponse)
151+
return normalizeOutput(parsedResponse)
149152
}
150153
else throw new Error('Error getting result')
151154
} catch (e) {
@@ -182,7 +185,7 @@ export function resultsWith(deps) {
182185
{
183186
cursor: currentSlot,
184187
node: {
185-
...convertToLegacyOutput(parsedResultsResponse)
188+
...normalizeOutput(parsedResultsResponse)
186189
}
187190
}
188191
]
@@ -220,7 +223,7 @@ export function dryrunWith(deps) {
220223
const response = await deps.aoCore.request(params)
221224
if (response.ok) {
222225
const parsedResponse = await response.json()
223-
return convertToLegacyOutput(parsedResponse)
226+
return normalizeOutput(parsedResponse)
224227
}
225228
else throw new Error('Error running dryrun')
226229
} catch (e) {

0 commit comments

Comments
 (0)