Api cleanup
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { Printful, PrintfulClient, PrintfulError, Webflow, WebflowClient, WebflowError } from "@blade-and-brawn/commerce";
|
||||
import { env } from "../util";
|
||||
|
||||
const BASE_URL = "http://dev.api.bladeandbrawn.com";
|
||||
const DOMAIN = "dev.api.bladeandbrawn.com";
|
||||
|
||||
const PRINTFUL_WEBHOOK_URL = `${BASE_URL}/webhook/printful`;
|
||||
const WEBFLOW_WEBHOOK_URL = `${BASE_URL}/webhook/webflow`;
|
||||
const PRINTFUL_WEBHOOK_URL = `http://${DOMAIN}/webhooks/printful`;
|
||||
const WEBFLOW_WEBHOOK_URL = `https://${DOMAIN}/webhooks/webflow`;
|
||||
|
||||
function printError(err: unknown): never {
|
||||
if (err instanceof WebflowError || err instanceof PrintfulError)
|
||||
|
||||
+10
-9
@@ -75,8 +75,10 @@ export const app = new Elysia()
|
||||
})
|
||||
|
||||
.onAfterResponse(({ request, status, path }) => {
|
||||
const skip: Record<string, string[]> = { "/products/sync/": ["GET"] };
|
||||
if (env.NODE_ENV === "development" && skip[path]?.includes(request.method)) return;
|
||||
if (env.NODE_ENV === "development") {
|
||||
const skip: Record<string, string[]> = { "/commerce/products/sync/": ["GET"] };
|
||||
if (skip[path]?.includes(request.method)) return;
|
||||
}
|
||||
|
||||
log.info({
|
||||
method: request.method,
|
||||
@@ -107,8 +109,7 @@ export const app = new Elysia()
|
||||
}, { body: t.Object({ password: t.String() }) })
|
||||
|
||||
// CALCULATOR
|
||||
.group("/calculator",
|
||||
(app) => app
|
||||
.group("/calculator", (app) => app
|
||||
// Non-authenticated
|
||||
.post("/calculate", async ({ body }) => {
|
||||
return { levels: await s.Calculator.calculate(body.player, body.activityPerformances) };
|
||||
@@ -177,6 +178,7 @@ export const app = new Elysia()
|
||||
)
|
||||
|
||||
// COMMERCE
|
||||
.group("/commerce", (app) => app
|
||||
.group("/products",
|
||||
(app) => app
|
||||
.resolve(async ({ jwt, cookie: { auth } }) => {
|
||||
@@ -184,8 +186,7 @@ export const app = new Elysia()
|
||||
if (!token || !token.sessionId) throw status(401, "Unauthorized");
|
||||
return { sessionId: token.sessionId.toString() };
|
||||
})
|
||||
.group("/sync", (app) =>
|
||||
app
|
||||
.group("/sync", (app) => app
|
||||
// Sync status
|
||||
.get("/", async ({ sessionId }) => {
|
||||
const latestSync = await s.Commerce.Sync.getLatest(sessionId);
|
||||
@@ -219,10 +220,10 @@ export const app = new Elysia()
|
||||
}, {
|
||||
params: t.Object({ pProductId: t.Numeric() })
|
||||
})
|
||||
)
|
||||
))
|
||||
|
||||
// WEBHOOKS
|
||||
.post("/webhook/printful", async ({ body }) => {
|
||||
.post("/webhooks/printful", async ({ body }) => {
|
||||
// https://webflow.com/integrations/printful
|
||||
const payload = body as Printful.Webhook.EventPayload;
|
||||
|
||||
@@ -267,7 +268,7 @@ export const app = new Elysia()
|
||||
log.warn({ type: (payload as any).type }, "printful webhook: unhandled event type");
|
||||
}
|
||||
})
|
||||
.post("/webhook/webflow", async ({ request, body }) => {
|
||||
.post("/webhooks/webflow", async ({ request, body }) => {
|
||||
if (!s.Commerce.Webflow.Util.verifyWebflowSignature(request, body))
|
||||
throw status(400, "Invalid signature");
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
return this.status === "active" || this.status === "queued";
|
||||
},
|
||||
poll: async function () {
|
||||
const res = await api.products.sync.get();
|
||||
const res = await api.commerce.products.sync.get();
|
||||
if (res.error) {
|
||||
synchronizer.status = "none";
|
||||
synchronizer.syncingPProductIds = [];
|
||||
@@ -32,11 +32,11 @@
|
||||
},
|
||||
syncAll: async () => {
|
||||
synchronizer.startPolling();
|
||||
await api.products.sync.post();
|
||||
await api.commerce.products.sync.post();
|
||||
},
|
||||
sync: async (pProductId: number) => {
|
||||
synchronizer.startPolling();
|
||||
await api.products.sync({ pProductId }).post();
|
||||
await api.commerce.products.sync({ pProductId }).post();
|
||||
},
|
||||
});
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
<td
|
||||
><button
|
||||
onclick={async () => {
|
||||
const res = await api
|
||||
const res = await api.commerce
|
||||
.products({
|
||||
pProductId:
|
||||
pProduct.id,
|
||||
|
||||
Reference in New Issue
Block a user