Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/plain-pumas-relax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@exactly/server": patch
---

✨ migrate webhook subscription to queue
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"reactnavigation",
"redeployer",
"reentrancy",
"retriable",
"rpid",
"rustup",
"scannability",
Expand Down
6 changes: 5 additions & 1 deletion server/api/auth/authentication.ts
Comment thread
aguxez marked this conversation as resolved.
Comment thread
aguxez marked this conversation as resolved.
Comment thread
devin-ai-integration[bot] marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import database, { credentials } from "../../database";
import androidOrigins from "../../utils/android/origins";
import appOrigin from "../../utils/appOrigin";
import authSecret from "../../utils/authSecret";
import createCredential from "../../utils/createCredential";
import createCredential, { WebhookNotReadyError } from "../../utils/createCredential";
import decodePublicKey from "../../utils/decodePublicKey";
import getIntercomToken from "../../utils/intercom";
import publicClient from "../../utils/publicClient";
Expand Down Expand Up @@ -341,6 +341,10 @@ Submit the signed SIWE message to prove ownership of an Ethereum address. The se
200,
);
} catch (error) {
if (error instanceof WebhookNotReadyError) {
captureException(error, { level: "warning", tags: { retriable: true } });
return c.json({ code: "service unavailable" }, 503);
}
captureException(error, { level: "error", tags: { unhandled: true } });
return c.json({ code: "ouch", legacy: "ouch" }, 500);
}
Expand Down
6 changes: 5 additions & 1 deletion server/api/auth/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { Address, Base64URL, Hex } from "@exactly/common/validation";
import { Authentication } from "./authentication";
import androidOrigins from "../../utils/android/origins";
import appOrigin from "../../utils/appOrigin";
import createCredential from "../../utils/createCredential";
import createCredential, { WebhookNotReadyError } from "../../utils/createCredential";
import getIntercomToken from "../../utils/intercom";
import publicClient from "../../utils/publicClient";
import redis from "../../utils/redis";
Expand Down Expand Up @@ -370,6 +370,10 @@ export default new Hono()
200,
);
} catch (error) {
if (error instanceof WebhookNotReadyError) {
captureException(error, { level: "warning", tags: { retriable: true } });
return c.json({ code: "service unavailable" }, 503);
}
Comment thread
aguxez marked this conversation as resolved.
Comment thread
aguxez marked this conversation as resolved.
captureException(error, { level: "error", tags: { unhandled: true } });
return c.json({ code: "ouch", legacy: "ouch" }, 500);
}
Expand Down
7 changes: 6 additions & 1 deletion server/hooks/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,15 @@ findWebhook(({ webhook_type, webhook_url }) => webhook_type === "ADDRESS_ACTIVIT
.then(async (currentHook) => {
if (currentHook) {
webhookId = currentHook.id;
debug("alchemy webhook initialized with existing hook: %s", webhookId);
return signingKeys.add(currentHook.signing_key);
}
const newHook = await createWebhook({ webhook_type: "ADDRESS_ACTIVITY", webhook_url: url, addresses: [] });
webhookId = newHook.id;
debug("alchemy webhook initialized with new hook: %s", webhookId);
signingKeys.add(newHook.signing_key);
})
.catch((error: unknown) => captureException(error));
.catch((error: unknown) => {
debug("failed to initialize alchemy webhook: %o", error);
captureException(error, { level: "error" });
});
5 changes: 3 additions & 2 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import panda from "./hooks/panda";
import persona from "./hooks/persona";
import androidFingerprints from "./utils/android/fingerprints";
import appOrigin from "./utils/appOrigin";
import { closeQueue as closeAccountQueue } from "./utils/createCredential";
import { close as closeRedis } from "./utils/redis";
import { closeAndFlush as closeSegment } from "./utils/segment";

Expand Down Expand Up @@ -319,10 +320,10 @@ export default app;

const server = serve(app);

export async function close() {
export function close() {
return new Promise((resolve, reject) => {
server.close((error) => {
Promise.allSettled([closeSentry(), closeRedis(), closeSegment(), database.$client.end()])
Promise.allSettled([closeSentry(), closeRedis(), closeSegment(), database.$client.end(), closeAccountQueue()])
Comment thread
aguxez marked this conversation as resolved.
Comment thread
aguxez marked this conversation as resolved.
.then((results) => {
if (error) reject(error);
else if (results.some((result) => result.status === "rejected")) reject(new Error("closing services failed"));
Expand Down
Loading
Loading