fix(chat): create inbox via apply-batch (POST /api/ea2/flow rejects _key)
This commit is contained in:
+15
-5
@@ -41,10 +41,13 @@ async function ensureInbox(inboxKey: string, email: string, signal?: AbortSignal
|
|||||||
const head = await fetch(`${api.config.baseUrl}/api/ea2/flow/${inboxKey}`, { headers: authHeaders(), signal });
|
const head = await fetch(`${api.config.baseUrl}/api/ea2/flow/${inboxKey}`, { headers: authHeaders(), signal });
|
||||||
if (head.ok) return true;
|
if (head.ok) return true;
|
||||||
} catch { /* fall through */ }
|
} catch { /* fall through */ }
|
||||||
const created = await fetch(`${api.config.baseUrl}/api/ea2/flow`, {
|
const body = {
|
||||||
method: "POST",
|
request_id: newRequestId(),
|
||||||
headers: authHeaders(),
|
ops: [
|
||||||
body: JSON.stringify({
|
{
|
||||||
|
op: "create",
|
||||||
|
coll: "flow",
|
||||||
|
data: {
|
||||||
_key: inboxKey,
|
_key: inboxKey,
|
||||||
kind: "value",
|
kind: "value",
|
||||||
status: "published",
|
status: "published",
|
||||||
@@ -53,7 +56,14 @@ async function ensureInbox(inboxKey: string, email: string, signal?: AbortSignal
|
|||||||
description: `Chat inbox anchor for ${email}`,
|
description: `Chat inbox anchor for ${email}`,
|
||||||
source_context: "CANVAS_CHAT_INBOX",
|
source_context: "CANVAS_CHAT_INBOX",
|
||||||
config: { chat: { owner_email: email } },
|
config: { chat: { owner_email: email } },
|
||||||
}),
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const created = await fetch(`${api.config.baseUrl}/api/ea2/apply-batch`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: authHeaders(),
|
||||||
|
body: JSON.stringify(body),
|
||||||
signal,
|
signal,
|
||||||
});
|
});
|
||||||
return created.ok || created.status === 409;
|
return created.ok || created.status === 409;
|
||||||
|
|||||||
Reference in New Issue
Block a user