Skip to content

Commit 1d496f1

Browse files
committed
Fix RestObject response body decoding for browser environments
Don't use envelope for LiveObjects REST requests since they aren't paginated. Use the unpacked flag to decide whether to decode, matching the standard SDK pattern.
1 parent a063708 commit 1d496f1

File tree

1 file changed

+9
-18
lines changed

1 file changed

+9
-18
lines changed

src/plugins/liveobjects/restobject.ts

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,39 +94,34 @@ export class RestObject implements PublicRestObject {
9494
async get(params?: RestObjectGetParams): Promise<RestObjectGetCompactResult | RestObjectGetResult> {
9595
const client = this._channel.client;
9696
const format = client.options.useBinaryProtocol ? client.Utils.Format.msgpack : client.Utils.Format.json;
97-
const envelope = client.http.supportsLinkHeaders ? null : format;
9897
const headers = client.Defaults.defaultGetHeaders(client.options);
9998

10099
client.Utils.mixin(headers, client.options.headers);
101100

102-
const response = await client.rest.Resource.get<RestObjectGetCompactResult | WireRestObjectGetResult>(
101+
const { unpacked, body } = await client.rest.Resource.get<RestObjectGetCompactResult | WireRestObjectGetResult>(
103102
client,
104103
this._basePath(params?.objectId),
105104
headers,
106105
params ?? {},
107-
envelope,
106+
null,
108107
true,
109108
);
110109

111-
const body = format
112-
? client.Utils.decodeBody<RestObjectGetCompactResult | WireRestObjectGetResult>(
113-
response.body,
114-
client._MsgPack,
115-
format,
116-
)
117-
: response.body!;
110+
const decoded = unpacked
111+
? body!
112+
: client.Utils.decodeBody<RestObjectGetCompactResult | WireRestObjectGetResult>(body, client._MsgPack, format);
118113

119114
const compact = params?.compact ?? true;
120115
if (compact) {
121116
// Compact mode: return as-is. Values are JSON-like; bytes appear as base64 strings
122117
// (JSON protocol) or Buffer/ArrayBuffer (binary protocol). We cannot deterministically
123118
// decode values since we can't tell string vs JSON-encoded string.
124-
return body as RestObjectGetCompactResult;
119+
return decoded as RestObjectGetCompactResult;
125120
}
126121

127122
// Non-compact mode: response is a live object (map/counter) or a typed leaf ObjectData.
128123
// Decode wire values using objectmessage decoding.
129-
return this._decodeNonCompactResult(body as WireRestObjectGetResult, format);
124+
return this._decodeNonCompactResult(decoded as WireRestObjectGetResult, format);
130125
}
131126

132127
async publish(op: RestObjectOperation | RestObjectOperation[]): Promise<RestObjectPublishResult> {
@@ -142,7 +137,7 @@ export class RestObject implements PublicRestObject {
142137

143138
const requestBody = client.Utils.encodeBody(wireOps, client._MsgPack, format);
144139

145-
const response = await client.rest.Resource.post<RestObjectPublishResult>(
140+
const { unpacked, body } = await client.rest.Resource.post<RestObjectPublishResult>(
146141
client,
147142
this._basePath(),
148143
requestBody,
@@ -152,11 +147,7 @@ export class RestObject implements PublicRestObject {
152147
true,
153148
);
154149

155-
if (format) {
156-
return client.Utils.decodeBody(response.body, client._MsgPack, format);
157-
}
158-
159-
return response.body!;
150+
return unpacked ? body! : client.Utils.decodeBody(body, client._MsgPack, format);
160151
}
161152

162153
private _basePath(objectId?: string): string {

0 commit comments

Comments
 (0)