fix(ts-sdk): preserve user-defined schema keys in createMemoryExport (#5594)

This commit is contained in:
Abhishek Chauhan
2026-06-17 14:40:33 +05:30
committed by GitHub
parent 137b7519f7
commit 0d66d3d127
2 changed files with 52 additions and 1 deletions
+5 -1
View File
@@ -696,7 +696,10 @@ export default class MemoryClient {
throw new Error("Missing filters or schema");
}
const { filters, ...rest } = data;
// filters and schema are user-controlled blobs whose keys must reach the
// API verbatim; only the remaining SDK params (e.g. exportInstructions)
// get camel->snake conversion. See issue #5593.
const { filters, schema, ...rest } = data;
const response = await this._fetchWithErrorHandling(
`${this.host}/v1/exports/`,
{
@@ -705,6 +708,7 @@ export default class MemoryClient {
body: JSON.stringify({
...camelToSnakeKeys(rest),
filters,
schema,
}),
},
);
@@ -0,0 +1,47 @@
/**
* MemoryClient unit tests — createMemoryExport.
* Verifies request construction, not mock response echo.
*/
import { MemoryClient } from "../mem0";
import { TEST_API_KEY } from "./helpers";
import {
setupMockFetch,
findFetchCall,
getFetchBody,
installConsoleSuppression,
} from "./setup";
installConsoleSuppression();
describe("MemoryClient - createMemoryExport()", () => {
test("sends user-defined schema keys verbatim, converts SDK params", async () => {
const extra = new Map<string, { status: number; body: unknown }>();
extra.set("/v1/exports/", {
status: 200,
body: { message: "ok", id: "exp_1" },
});
const mock = setupMockFetch(extra);
const client = new MemoryClient({ apiKey: TEST_API_KEY });
await client.createMemoryExport({
// camelCase keys here are user-defined export field names — they must
// not be snake_cased on the way out.
schema: { messageId: "string", customField: { nestedKey: "number" } },
filters: { user_id: "u1" },
exportInstructions: "export it",
});
const call = findFetchCall(mock, "/v1/exports/", "POST");
expect(call).toBeDefined();
const body = getFetchBody(call!);
// User blobs round-trip verbatim (no camel->snake on their keys).
expect(body.schema).toEqual({
messageId: "string",
customField: { nestedKey: "number" },
});
expect(body.filters).toEqual({ user_id: "u1" });
// SDK param is still snake_cased.
expect(body.export_instructions).toBe("export it");
});
});