Skip to content

Commit

Permalink
[MS-758] feat: Cleanup erors (#24)
Browse files Browse the repository at this point in the history
* [MS-758] feat: Cleanup erors

* [MS-758] build: Align artifact build
  • Loading branch information
piotrgrundas authored Oct 18, 2024
1 parent aad5b01 commit 64bc5bf
Show file tree
Hide file tree
Showing 41 changed files with 450 additions and 278 deletions.
5 changes: 3 additions & 2 deletions etc/commands/build.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#!/bin/bash

# Cleanup
rm -rf build package.zip
rm -rf build artifact.zip
# Install deps
pnpm install --frozen-lockfile --prod
pnpm build:serverless
# Create bundle
pnpm build
# Create zip
cd build; zip -r -D ../artifact.zip .
8 changes: 0 additions & 8 deletions etc/scripts/common.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,6 @@ export const esbuildConfig = {
authToken: process.env.SENTRY_AUTH_TOKEN,
disable: !isSentryEnabled,
}),
copy({
watch: true,
resolveFrom: "cwd",
assets: {
from: ["./src/api/graphql/schema.graphql"],
to: ["./build"],
},
}),
copy({
resolveFrom: "cwd",
assets: {
Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"@fastify/error": "^4.0.0",
"@react-email/components": "^0.0.25",
"@sentry/aws-serverless": "^8.34.0",
"@sentry/esbuild-plugin": "^2.22.5",
"@sentry/node": "^8.34.0",
"@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1",
Expand All @@ -63,6 +64,7 @@
"husky": "^9.1.6",
"jose": "^5.9.4",
"jsonwebtoken": "^9.0.2",
"klona": "^2.0.6",
"nodemailer": "^6.9.15",
"path-to-regexp": "^8.2.0",
"pg": "^8.13.0",
Expand All @@ -73,6 +75,7 @@
"react-email": "^3.0.1",
"tailwind-merge": "^2.5.4",
"tailwindcss": "^3.4.14",
"traverse": "^0.6.10",
"ts-invariant": "^0.10.3",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.6.3",
Expand All @@ -90,13 +93,13 @@
"@graphql-codegen/typescript": "^4.1.0",
"@graphql-codegen/typescript-operations": "^4.3.0",
"@graphql-typed-document-node/core": "^3.2.0",
"@sentry/esbuild-plugin": "^2.22.5",
"@types/aws-lambda": "^8.10.145",
"@types/graphql": "^14.5.0",
"@types/jsonwebtoken": "^9.0.7",
"@types/node": "^20.16.11",
"@types/nodemailer": "^6.4.16",
"@types/pg": "^8.11.10",
"@types/traverse": "^0.6.37",
"@typescript-eslint/parser": "^7.18.0",
"@vitest/coverage-v8": "^2.1.3",
"commitizen": "^4.3.1",
Expand Down
49 changes: 46 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions src/api/rest/routes.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { beforeEach, describe, expect, test, vi } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";

import * as validate from "@/lib/graphql/validate";
import * as auth from "@/lib/saleor/auth";
Expand All @@ -8,7 +8,7 @@ import { EVENT_HANDLERS } from "./saleor/webhooks";

describe("apiRoutes", () => {
describe("/api/healthcheck", () => {
test("200", async () => {
it("200", async () => {
const app = await createServer();
const response = await app.inject({
method: "GET",
Expand All @@ -31,7 +31,7 @@ describe("apiRoutes", () => {
app.sqs.send = sendSpy;
});

test("Should return 401 with invalid JWT.", async () => {
it("Should return 401 with invalid JWT.", async () => {
// given
const expectedStatusCode = 401;
const expectedJson = {
Expand All @@ -56,7 +56,7 @@ describe("apiRoutes", () => {
expect(response.statusCode).toStrictEqual(expectedStatusCode);
});

test("Should return 400 passed when event is not supported.", async () => {
it("Should return 400 passed when event is not supported.", async () => {
// given
const expectedStatusCode = 400;
const expectedJson = {
Expand Down Expand Up @@ -87,7 +87,7 @@ describe("apiRoutes", () => {
expect(response.statusCode).toStrictEqual(expectedStatusCode);
});

test("Should return proper response.", async () => {
it("Should return proper response.", async () => {
const jwtVerifySpy = vi.spyOn(auth, "verifyJWTSignature");
const validateSpy = vi.spyOn(validate, "validateDocumentAgainstData");
const expectedJson = { status: "ok" };
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import { z } from "zod";

import { CONFIG } from "@/config";
import { OrderCreatedSubscriptionDocument } from "@/graphql/operations/subscriptions/generated";
import { serializePayload } from "@/lib/emails/events/helpers";
import { validateDocumentAgainstData } from "@/lib/graphql/validate";
import { serializePayload } from "@/lib/payload";
import { verifyJWTSignature } from "@/lib/saleor/auth";
import { saleorBearerHeader } from "@/lib/saleor/schema";
import { getJWKSProvider } from "@/providers/jwks";
Expand Down
12 changes: 6 additions & 6 deletions src/api/rest/saleor/webhooks.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { JWTInvalid } from "jose/errors";
import { beforeEach, describe, expect, test, vi } from "vitest";
import { beforeEach, describe, expect, it, vi } from "vitest";

import { CONFIG } from "@/config";
import { serializePayload } from "@/lib/emails/events/helpers";
import { serializePayload } from "@/lib/payload";
import * as auth from "@/lib/saleor/auth";
import { createServer } from "@/server";

Expand All @@ -21,7 +21,7 @@ describe("saleorWebhooksRoutes", () => {
});

describe("/api/saleor/webhooks/email/*", () => {
test.each(EVENT_HANDLERS)(
it.each(EVENT_HANDLERS)(
"should register route for $event event",
({ event }) => {
// Given
Expand All @@ -37,7 +37,7 @@ describe("saleorWebhooksRoutes", () => {
}
);

test("require saleor headers", async () => {
it("require saleor headers", async () => {
// Given
const url = `${baseUrl}account-confirmed`;
const expectedStatusCode = 400;
Expand Down Expand Up @@ -82,7 +82,7 @@ describe("saleorWebhooksRoutes", () => {
expect(response.statusCode).toStrictEqual(expectedStatusCode);
});

test("is protected by JWT", async () => {
it("is protected by JWT", async () => {
// Given
const url = `${baseUrl}account-confirmed`;
const expectedStatusCode = 401;
Expand Down Expand Up @@ -116,7 +116,7 @@ describe("saleorWebhooksRoutes", () => {
expect(response.statusCode).toStrictEqual(expectedStatusCode);
});

test("it should send SQS message with proper payload", async () => {
it("it should send SQS message with proper payload", async () => {
// Given
const url = `${baseUrl}account-confirmed`;
const event = "account_confirmed";
Expand Down
2 changes: 1 addition & 1 deletion src/api/rest/saleor/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
OrderRefundedSubscriptionDocument,
} from "@/graphql/operations/subscriptions/generated";
import { type WebhookEventTypeAsyncEnum } from "@/graphql/schema";
import { serializePayload } from "@/lib/emails/events/helpers";
import { serializePayload } from "@/lib/payload";
import { verifyWebhookSignature } from "@/lib/saleor/auth";
import { saleorWebhookHeaders } from "@/lib/saleor/schema";
import { getJWKSProvider } from "@/providers/jwks";
Expand Down
8 changes: 6 additions & 2 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const configSchema = z
// Used for generating paths, selecting localized formatters.
DEFAULT_REGION: z.string().default("GB"),
// Email sender info.
FROM_EMAIL: z.string().email().default("hello@mirumee.com"),
FROM_EMAIL: z.string().email().default("noreply@mirumee.com"),
FROM_NAME: z.string().default("Mirumee"),
// Sentry.
SENTRY_DEBUG: z.boolean().default(false),
Expand All @@ -31,7 +31,11 @@ export const configSchema = z
})
.and(commonConfigSchema)
.and(appConfigSchema)
.and(saleorAppConfigSchema);
.and(saleorAppConfigSchema)
.refine((data) => {
data.STOREFRONT_URL = new URL(data.STOREFRONT_URL).origin;
return data;
});

export type ConfigSchema = z.infer<typeof configSchema>;

Expand Down
7 changes: 1 addition & 6 deletions src/emails-sender-proxy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SQSClient } from "@aws-sdk/client-sqs";
import { type Context, type SQSEvent, type SQSRecord } from "aws-lambda";
import { Consumer } from "sqs-consumer";

Expand All @@ -7,18 +6,14 @@ import { handler, logger } from "@/emails-sender";

const app = Consumer.create({
queueUrl: CONFIG.SQS_QUEUE_URL,
sqs: new SQSClient({
useQueueUrlAsEndpoint: false,
endpoint: CONFIG.SQS_QUEUE_URL,
}),
handleMessageBatch: async (messages) => {
const event: SQSEvent = {
Records: messages as SQSRecord[],
};
const context = {} as Context;
const callback = () => null;

await handler(event, context, () => callback);
return await handler(event, context, () => callback);
},
});

Expand Down
Loading

0 comments on commit 64bc5bf

Please sign in to comment.