fix: encode dynamic URL path segments (#5963)
Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
This commit is contained in:
co-authored by
kartik-mem0
parent
87276ef968
commit
cc52f0e367
@@ -67,6 +67,10 @@ function rejectTopLevelEntityParams(
|
||||
}
|
||||
}
|
||||
|
||||
function encodePathSegment(value: unknown): string {
|
||||
return encodeURIComponent(String(value));
|
||||
}
|
||||
|
||||
class APIError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message);
|
||||
@@ -311,7 +315,7 @@ export default class MemoryClient {
|
||||
this._captureEvent("update", [payloadKeys]);
|
||||
|
||||
const response = await this._fetchWithErrorHandling(
|
||||
`${this.host}/v1/memories/${memoryId}/`,
|
||||
`${this.host}/v1/memories/${encodePathSegment(memoryId)}/`,
|
||||
{
|
||||
method: "PUT",
|
||||
headers: this.headers,
|
||||
@@ -325,7 +329,7 @@ export default class MemoryClient {
|
||||
if (this.telemetryId === "") await this.ping();
|
||||
this._captureEvent("get", []);
|
||||
return this._fetchWithErrorHandling(
|
||||
`${this.host}/v1/memories/${memoryId}/`,
|
||||
`${this.host}/v1/memories/${encodePathSegment(memoryId)}/`,
|
||||
{
|
||||
headers: this.headers,
|
||||
},
|
||||
@@ -397,7 +401,7 @@ export default class MemoryClient {
|
||||
// @ts-ignore
|
||||
const query = new URLSearchParams(snakeOptions).toString();
|
||||
return this._fetchWithErrorHandling(
|
||||
`${this.host}/v1/memories/${memoryId}/${query ? `?${query}` : ""}`,
|
||||
`${this.host}/v1/memories/${encodePathSegment(memoryId)}/${query ? `?${query}` : ""}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: this.headers,
|
||||
@@ -428,7 +432,7 @@ export default class MemoryClient {
|
||||
if (this.telemetryId === "") await this.ping();
|
||||
this._captureEvent("history", []);
|
||||
const response = await this._fetchWithErrorHandling(
|
||||
`${this.host}/v1/memories/${memoryId}/history/`,
|
||||
`${this.host}/v1/memories/${encodePathSegment(memoryId)}/history/`,
|
||||
{
|
||||
headers: this.headers,
|
||||
},
|
||||
@@ -466,7 +470,7 @@ export default class MemoryClient {
|
||||
data.entity_type = "user";
|
||||
}
|
||||
const response = await this._fetchWithErrorHandling(
|
||||
`${this.host}/v1/entities/${data.entity_type}/${data.entity_id}/`,
|
||||
`${this.host}/v1/entities/${encodePathSegment(data.entity_type)}/${encodePathSegment(data.entity_id)}/`,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: this.headers,
|
||||
@@ -510,7 +514,9 @@ export default class MemoryClient {
|
||||
|
||||
for (const entity of to_delete) {
|
||||
try {
|
||||
await this.client.delete(`/v2/entities/${entity.type}/${entity.name}/`);
|
||||
await this.client.delete(
|
||||
`/v2/entities/${encodePathSegment(entity.type)}/${encodePathSegment(entity.name)}/`,
|
||||
);
|
||||
} catch (error: any) {
|
||||
throw new APIError(
|
||||
`Failed to delete ${entity.type} ${entity.name}: ${error.message}`,
|
||||
|
||||
Reference in New Issue
Block a user