edge-book 0.9.1 → 0.10.0
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/edge-book.js +28 -0
- package/package.json +1 -1
package/dist/edge-book.js
CHANGED
|
@@ -2732,6 +2732,34 @@ async function handleOwnerApi(req, res, url, adapters) {
|
|
|
2732
2732
|
sendJson(res, 200, response_envelope ? { approval, response_envelope } : { approval });
|
|
2733
2733
|
return true;
|
|
2734
2734
|
}
|
|
2735
|
+
if (req.method === "POST" && url.pathname === "/api/friend/request") {
|
|
2736
|
+
const reqBody = await readJsonBody(req);
|
|
2737
|
+
const invite = (reqBody.invite || "").trim();
|
|
2738
|
+
if (!invite.startsWith("edgebook:invite:")) {
|
|
2739
|
+
throw new EdgeBookError("bad_invite", "Expected an edgebook:invite: link");
|
|
2740
|
+
}
|
|
2741
|
+
const hashIdx = invite.indexOf("#");
|
|
2742
|
+
const cardLink = hashIdx === -1 ? invite : invite.slice(0, hashIdx);
|
|
2743
|
+
const inviteCode = hashIdx === -1 ? "" : new URLSearchParams(invite.slice(hashIdx + 1)).get("code") || "";
|
|
2744
|
+
let card;
|
|
2745
|
+
try {
|
|
2746
|
+
card = await loadCard(cardLink);
|
|
2747
|
+
} catch {
|
|
2748
|
+
throw new EdgeBookError("bad_invite", "Invite did not decode to a valid Agent Card");
|
|
2749
|
+
}
|
|
2750
|
+
const existing = (await store.contacts())[card.agent_id];
|
|
2751
|
+
if (existing && (existing.relationship_state === "friend" || existing.relationship_state === "request_sent")) {
|
|
2752
|
+
sendJson(res, 200, { ok: true, status: existing.relationship_state, contact: existing, response_envelope: null });
|
|
2753
|
+
return true;
|
|
2754
|
+
}
|
|
2755
|
+
if (existing && existing.relationship_state === "blocked") {
|
|
2756
|
+
throw new EdgeBookError("blocked_peer", "Cannot request a blocked peer");
|
|
2757
|
+
}
|
|
2758
|
+
const envelope = await store.createFriendRequest(card, "", inviteCode);
|
|
2759
|
+
const contact = (await store.contacts())[card.agent_id];
|
|
2760
|
+
sendJson(res, 200, { ok: true, status: "request_sent", contact, response_envelope: envelope });
|
|
2761
|
+
return true;
|
|
2762
|
+
}
|
|
2735
2763
|
if (req.method === "GET" && url.pathname === "/api/escalations") {
|
|
2736
2764
|
sendJson(res, 200, { escalations: await store.escalations() });
|
|
2737
2765
|
return true;
|