xmemory 3.8.0 → 3.8.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/cjs/client.js +25 -6
- package/dist/cjs/instance.js +27 -3
- package/dist/esm/client.js +25 -6
- package/dist/esm/instance.js +27 -3
- package/package.json +1 -1
package/dist/cjs/client.js
CHANGED
|
@@ -8,6 +8,24 @@ exports.xmemoryInstance = xmemoryInstance;
|
|
|
8
8
|
const instance_js_1 = require("./instance.js");
|
|
9
9
|
const types_js_1 = require("./types.js");
|
|
10
10
|
const DEFAULT_BASE_URL = "https://api.xmemory.ai";
|
|
11
|
+
/**
|
|
12
|
+
* An *own* property of a decoded response, or `undefined`.
|
|
13
|
+
*
|
|
14
|
+
* A decoded body is a plain object, so a field the server omitted is answered by
|
|
15
|
+
* `Object.prototype`. Reading the envelope that way let a polluted prototype supply
|
|
16
|
+
* an `items` array — and a 200 with an empty body then came back as a genuine
|
|
17
|
+
* result. Every read of a server-controlled envelope goes through here.
|
|
18
|
+
*/
|
|
19
|
+
function own(source, key) {
|
|
20
|
+
return typeof source === "object" && source !== null && Object.hasOwn(source, key)
|
|
21
|
+
? source[key]
|
|
22
|
+
: undefined;
|
|
23
|
+
}
|
|
24
|
+
/** An own array field, or an empty one. Never the prototype's. */
|
|
25
|
+
function ownArray(source, key) {
|
|
26
|
+
const value = own(source, key);
|
|
27
|
+
return Array.isArray(value) ? value : [];
|
|
28
|
+
}
|
|
11
29
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
12
30
|
const ORANGE = "\x1b[38;5;208m";
|
|
13
31
|
const RESET = "\x1b[0m";
|
|
@@ -31,7 +49,7 @@ function extractStructuredError(payload) {
|
|
|
31
49
|
details: (p.details ?? null),
|
|
32
50
|
};
|
|
33
51
|
}
|
|
34
|
-
const errors = p
|
|
52
|
+
const errors = own(p, "errors");
|
|
35
53
|
if (Array.isArray(errors) && errors.length > 0 && typeof errors[0] === "object" && errors[0] !== null) {
|
|
36
54
|
const first = errors[0];
|
|
37
55
|
return {
|
|
@@ -182,15 +200,16 @@ class XmemoryClient {
|
|
|
182
200
|
throw new types_js_1.XmemoryAPIError(`HTTP ${res.status}: ${msg}`, res.status, structured.code, structured.details, parseRetryAfter(res));
|
|
183
201
|
}
|
|
184
202
|
const response = payload;
|
|
185
|
-
|
|
186
|
-
|
|
203
|
+
const responseErrors = ownArray(response, "errors");
|
|
204
|
+
if (responseErrors.length > 0) {
|
|
205
|
+
const first = responseErrors[0];
|
|
187
206
|
throw new types_js_1.XmemoryAPIError(`API error: ${first.message} (${first.code})`, res.status, first.code);
|
|
188
207
|
}
|
|
189
208
|
return response;
|
|
190
209
|
}
|
|
191
210
|
async _requestOne(method, path, options) {
|
|
192
211
|
const response = await this._request(method, path, options);
|
|
193
|
-
const items = response
|
|
212
|
+
const items = ownArray(response, "items");
|
|
194
213
|
if (items.length === 0) {
|
|
195
214
|
throw new types_js_1.XmemoryAPIError(`Expected one item from ${method} ${path}, got none`);
|
|
196
215
|
}
|
|
@@ -201,11 +220,11 @@ class XmemoryClient {
|
|
|
201
220
|
}
|
|
202
221
|
async _requestList(method, path, options) {
|
|
203
222
|
const response = await this._request(method, path, options);
|
|
204
|
-
return (response
|
|
223
|
+
return ownArray(response, "items");
|
|
205
224
|
}
|
|
206
225
|
async _requestIds(method, path, options) {
|
|
207
226
|
const response = await this._request(method, path, options);
|
|
208
|
-
return response
|
|
227
|
+
return ownArray(response, "ids");
|
|
209
228
|
}
|
|
210
229
|
// -----------------------------------------------------------------------
|
|
211
230
|
// Private: build admin namespace
|
package/dist/cjs/instance.js
CHANGED
|
@@ -197,8 +197,21 @@ function buildJsonSchemaProps(params) {
|
|
|
197
197
|
* exactly the deployments that have no link — the case the comparison exists for.
|
|
198
198
|
* Same treatment `read` already gives `reader_results`.
|
|
199
199
|
*/
|
|
200
|
+
/**
|
|
201
|
+
* An *own* property of a decoded response, or `undefined`.
|
|
202
|
+
*
|
|
203
|
+
* A response is JSON, so a field the server omitted is answered by
|
|
204
|
+
* `Object.prototype` — and normalizing with `result.field ?? default` then writes
|
|
205
|
+
* that inherited value back as an own property, where nothing downstream can tell
|
|
206
|
+
* it apart from something the server actually sent. Prototype pollution anywhere in
|
|
207
|
+
* the process could fabricate sub-answers or a trace id this way.
|
|
208
|
+
*/
|
|
209
|
+
function own(result, key) {
|
|
210
|
+
return Object.hasOwn(result, key) ? result[key] : undefined;
|
|
211
|
+
}
|
|
200
212
|
function withConsoleUrl(result) {
|
|
201
|
-
|
|
213
|
+
const url = own(result, "console_url");
|
|
214
|
+
return { ...result, console_url: typeof url === "string" ? url : null };
|
|
202
215
|
}
|
|
203
216
|
class InstanceHandle {
|
|
204
217
|
id;
|
|
@@ -230,7 +243,17 @@ class InstanceHandle {
|
|
|
230
243
|
body,
|
|
231
244
|
timeoutMs: options?.timeoutMs,
|
|
232
245
|
});
|
|
233
|
-
|
|
246
|
+
// Every documented field set explicitly, so each one is an *own* property of
|
|
247
|
+
// what callers get back. Spreading alone leaves an omitted field to be answered
|
|
248
|
+
// by `Object.prototype` when the caller reads it.
|
|
249
|
+
const readerResults = own(result, "reader_results");
|
|
250
|
+
const traceId = own(result, "trace_id");
|
|
251
|
+
return withConsoleUrl({
|
|
252
|
+
...result,
|
|
253
|
+
reader_result: own(result, "reader_result") ?? null,
|
|
254
|
+
reader_results: Array.isArray(readerResults) ? readerResults : [],
|
|
255
|
+
trace_id: typeof traceId === "string" ? traceId : null,
|
|
256
|
+
});
|
|
234
257
|
}
|
|
235
258
|
async write(input, options) {
|
|
236
259
|
return withConsoleUrl(await this._requestOne("POST", `/instances/${this.id}/write`, { body: buildWriteBody(input, options), timeoutMs: options?.timeoutMs }));
|
|
@@ -242,7 +265,8 @@ class InstanceHandle {
|
|
|
242
265
|
});
|
|
243
266
|
// `trace_id` is normalized here as well because this result declares it for the
|
|
244
267
|
// first time, and the wire omits it exactly as it omits the console link.
|
|
245
|
-
|
|
268
|
+
const traceId = own(result, "trace_id");
|
|
269
|
+
return withConsoleUrl({ ...result, trace_id: typeof traceId === "string" ? traceId : null });
|
|
246
270
|
}
|
|
247
271
|
async writeStatus(writeId, options) {
|
|
248
272
|
return withConsoleUrl(await this._requestOne("POST", `/instances/${this.id}/write_status`, { body: { write_id: writeId }, timeoutMs: options?.timeoutMs }));
|
package/dist/esm/client.js
CHANGED
|
@@ -4,6 +4,24 @@
|
|
|
4
4
|
import { InstanceHandle } from "./instance.js";
|
|
5
5
|
import { SetupFormat, XmemoryAPIError, XmemoryHealthCheckError, buildInstanceSchema, } from "./types.js";
|
|
6
6
|
const DEFAULT_BASE_URL = "https://api.xmemory.ai";
|
|
7
|
+
/**
|
|
8
|
+
* An *own* property of a decoded response, or `undefined`.
|
|
9
|
+
*
|
|
10
|
+
* A decoded body is a plain object, so a field the server omitted is answered by
|
|
11
|
+
* `Object.prototype`. Reading the envelope that way let a polluted prototype supply
|
|
12
|
+
* an `items` array — and a 200 with an empty body then came back as a genuine
|
|
13
|
+
* result. Every read of a server-controlled envelope goes through here.
|
|
14
|
+
*/
|
|
15
|
+
function own(source, key) {
|
|
16
|
+
return typeof source === "object" && source !== null && Object.hasOwn(source, key)
|
|
17
|
+
? source[key]
|
|
18
|
+
: undefined;
|
|
19
|
+
}
|
|
20
|
+
/** An own array field, or an empty one. Never the prototype's. */
|
|
21
|
+
function ownArray(source, key) {
|
|
22
|
+
const value = own(source, key);
|
|
23
|
+
return Array.isArray(value) ? value : [];
|
|
24
|
+
}
|
|
7
25
|
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
8
26
|
const ORANGE = "\x1b[38;5;208m";
|
|
9
27
|
const RESET = "\x1b[0m";
|
|
@@ -27,7 +45,7 @@ function extractStructuredError(payload) {
|
|
|
27
45
|
details: (p.details ?? null),
|
|
28
46
|
};
|
|
29
47
|
}
|
|
30
|
-
const errors = p
|
|
48
|
+
const errors = own(p, "errors");
|
|
31
49
|
if (Array.isArray(errors) && errors.length > 0 && typeof errors[0] === "object" && errors[0] !== null) {
|
|
32
50
|
const first = errors[0];
|
|
33
51
|
return {
|
|
@@ -178,15 +196,16 @@ export class XmemoryClient {
|
|
|
178
196
|
throw new XmemoryAPIError(`HTTP ${res.status}: ${msg}`, res.status, structured.code, structured.details, parseRetryAfter(res));
|
|
179
197
|
}
|
|
180
198
|
const response = payload;
|
|
181
|
-
|
|
182
|
-
|
|
199
|
+
const responseErrors = ownArray(response, "errors");
|
|
200
|
+
if (responseErrors.length > 0) {
|
|
201
|
+
const first = responseErrors[0];
|
|
183
202
|
throw new XmemoryAPIError(`API error: ${first.message} (${first.code})`, res.status, first.code);
|
|
184
203
|
}
|
|
185
204
|
return response;
|
|
186
205
|
}
|
|
187
206
|
async _requestOne(method, path, options) {
|
|
188
207
|
const response = await this._request(method, path, options);
|
|
189
|
-
const items = response
|
|
208
|
+
const items = ownArray(response, "items");
|
|
190
209
|
if (items.length === 0) {
|
|
191
210
|
throw new XmemoryAPIError(`Expected one item from ${method} ${path}, got none`);
|
|
192
211
|
}
|
|
@@ -197,11 +216,11 @@ export class XmemoryClient {
|
|
|
197
216
|
}
|
|
198
217
|
async _requestList(method, path, options) {
|
|
199
218
|
const response = await this._request(method, path, options);
|
|
200
|
-
return (response
|
|
219
|
+
return ownArray(response, "items");
|
|
201
220
|
}
|
|
202
221
|
async _requestIds(method, path, options) {
|
|
203
222
|
const response = await this._request(method, path, options);
|
|
204
|
-
return response
|
|
223
|
+
return ownArray(response, "ids");
|
|
205
224
|
}
|
|
206
225
|
// -----------------------------------------------------------------------
|
|
207
226
|
// Private: build admin namespace
|
package/dist/esm/instance.js
CHANGED
|
@@ -193,8 +193,21 @@ function buildJsonSchemaProps(params) {
|
|
|
193
193
|
* exactly the deployments that have no link — the case the comparison exists for.
|
|
194
194
|
* Same treatment `read` already gives `reader_results`.
|
|
195
195
|
*/
|
|
196
|
+
/**
|
|
197
|
+
* An *own* property of a decoded response, or `undefined`.
|
|
198
|
+
*
|
|
199
|
+
* A response is JSON, so a field the server omitted is answered by
|
|
200
|
+
* `Object.prototype` — and normalizing with `result.field ?? default` then writes
|
|
201
|
+
* that inherited value back as an own property, where nothing downstream can tell
|
|
202
|
+
* it apart from something the server actually sent. Prototype pollution anywhere in
|
|
203
|
+
* the process could fabricate sub-answers or a trace id this way.
|
|
204
|
+
*/
|
|
205
|
+
function own(result, key) {
|
|
206
|
+
return Object.hasOwn(result, key) ? result[key] : undefined;
|
|
207
|
+
}
|
|
196
208
|
function withConsoleUrl(result) {
|
|
197
|
-
|
|
209
|
+
const url = own(result, "console_url");
|
|
210
|
+
return { ...result, console_url: typeof url === "string" ? url : null };
|
|
198
211
|
}
|
|
199
212
|
export class InstanceHandle {
|
|
200
213
|
id;
|
|
@@ -226,7 +239,17 @@ export class InstanceHandle {
|
|
|
226
239
|
body,
|
|
227
240
|
timeoutMs: options?.timeoutMs,
|
|
228
241
|
});
|
|
229
|
-
|
|
242
|
+
// Every documented field set explicitly, so each one is an *own* property of
|
|
243
|
+
// what callers get back. Spreading alone leaves an omitted field to be answered
|
|
244
|
+
// by `Object.prototype` when the caller reads it.
|
|
245
|
+
const readerResults = own(result, "reader_results");
|
|
246
|
+
const traceId = own(result, "trace_id");
|
|
247
|
+
return withConsoleUrl({
|
|
248
|
+
...result,
|
|
249
|
+
reader_result: own(result, "reader_result") ?? null,
|
|
250
|
+
reader_results: Array.isArray(readerResults) ? readerResults : [],
|
|
251
|
+
trace_id: typeof traceId === "string" ? traceId : null,
|
|
252
|
+
});
|
|
230
253
|
}
|
|
231
254
|
async write(input, options) {
|
|
232
255
|
return withConsoleUrl(await this._requestOne("POST", `/instances/${this.id}/write`, { body: buildWriteBody(input, options), timeoutMs: options?.timeoutMs }));
|
|
@@ -238,7 +261,8 @@ export class InstanceHandle {
|
|
|
238
261
|
});
|
|
239
262
|
// `trace_id` is normalized here as well because this result declares it for the
|
|
240
263
|
// first time, and the wire omits it exactly as it omits the console link.
|
|
241
|
-
|
|
264
|
+
const traceId = own(result, "trace_id");
|
|
265
|
+
return withConsoleUrl({ ...result, trace_id: typeof traceId === "string" ? traceId : null });
|
|
242
266
|
}
|
|
243
267
|
async writeStatus(writeId, options) {
|
|
244
268
|
return withConsoleUrl(await this._requestOne("POST", `/instances/${this.id}/write_status`, { body: { write_id: writeId }, timeoutMs: options?.timeoutMs }));
|