inbox: add health endpoint & docs (#64)

* inbox: add health endpoint && docs

* inbox: update post endpoint uri

* inbox: update docs & dockerfile

---------

Co-authored-by: Abdullah Atta <abdullahatta@streetwriters.co>
This commit is contained in:
01zulfi
2026-03-27 14:20:42 +05:00
committed by GitHub
parent 3a2a04317f
commit 1c5bcd6eff
3 changed files with 85 additions and 8 deletions

View File

@@ -33,9 +33,15 @@ interface EncryptedInboxItem {
alg: string;
}
/**
* Encrypts raw data using OpenPGP with the recipient's public key
*
* @param {string} rawData - The plaintext data to encrypt
* @param {string} rawPublicKey - The recipient's OpenPGP public key
*/
async function encrypt(
rawData: string,
rawPublicKey: string
rawPublicKey: string,
): Promise<EncryptedInboxItem> {
const publicKey = await openpgp.readKey({ armoredKey: rawPublicKey });
const message = await openpgp.createMessage({ text: rawData });
@@ -57,11 +63,11 @@ async function getInboxPublicEncryptionKey(apiKey: string) {
headers: {
Authorization: apiKey,
},
}
},
);
if (!response.ok) {
throw new Error(
`failed to fetch inbox public encryption key: ${await response.text()}`
`failed to fetch inbox public encryption key: ${await response.text()}`,
);
}
@@ -71,7 +77,7 @@ async function getInboxPublicEncryptionKey(apiKey: string) {
async function postEncryptedInboxItem(
apiKey: string,
item: EncryptedInboxItem
item: EncryptedInboxItem,
) {
const response = await fetch(`${NOTESNOOK_API_SERVER_URL}/inbox/items`, {
method: "POST",
@@ -92,9 +98,12 @@ app.use(
rateLimit({
windowMs: 1 * 60 * 1000, // 1 minute
limit: 60,
})
}),
);
app.post("/inbox", async (req, res) => {
app.get("/health", (_, res) => {
return res.status(200).json({ status: "ok" });
});
app.post("/", async (req, res) => {
try {
const apiKey = req.headers["authorization"];
if (!apiKey) {
@@ -117,7 +126,7 @@ app.post("/inbox", async (req, res) => {
const encryptedItem = await encrypt(
JSON.stringify(validationResult.data),
inboxPublicKey
inboxPublicKey,
);
console.log("[info] encrypted item");