Skip to content

Commit

Permalink
[MS-759] feat: Add payload against query validation
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrgrundas committed Oct 7, 2024
1 parent 4cf561c commit de82af4
Show file tree
Hide file tree
Showing 9 changed files with 10,183 additions and 9,333 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = defineConfig({
"import/no-default-export": "off",
"import/no-anonymous-default-export": "off",
},
files: ["**/plugins/**/*.ts", "**/templates/**/*.tsx", "*.config.ts"],
files: ["**/plugins/**/*.ts", "**/templates/**/*.tsx", "*.config.*"],
},
],
});
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
"fastify-raw-body": "^4.3.0",
"fastify-type-provider-zod": "^2.0.0",
"graphql": "^16.9.0",
"graphql-yoga": "^5.6.2",
"graphql-tag": "^2.12.6",
"graphql-yoga": "^5.7.0",
"husky": "^9.1.4",
"jose": "^5.6.3",
"jsonwebtoken": "^9.0.2",
Expand Down Expand Up @@ -85,6 +86,7 @@
"@graphql-codegen/typescript-operations": "^4.2.3",
"@graphql-typed-document-node/core": "^3.2.0",
"@types/aws-lambda": "^8.10.145",
"@types/graphql": "^14.5.0",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^20.14.9",
"@types/pg": "^8.11.6",
Expand Down
50 changes: 32 additions & 18 deletions pnpm-lock.yaml

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

15 changes: 15 additions & 0 deletions src/api/rest/routes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import type { FastifyPluginAsync } from "fastify/types/plugin";
import { type ZodTypeProvider } from "fastify-type-provider-zod";

import { OrderCreatedSubscriptionDocument } from "@/graphql/operations/subscriptions/generated";
import { validateDocumentAgainstData } from "@/lib/graphql/validate";
import { verifyJWTSignature } from "@/lib/saleor/auth";
import { saleorBearerHeader } from "@/lib/saleor/schema";
import { getJWKSProvider } from "@/providers/jwks";
Expand All @@ -25,4 +27,17 @@ export const restRoutes: FastifyPluginAsync = async (fastify) => {
return { status: "ok" };
}
);

fastify.withTypeProvider<ZodTypeProvider>().post(
"/test",

async (request, response) => {
const { isValid, error } = validateDocumentAgainstData({
data: request.body,
document: OrderCreatedSubscriptionDocument,
});

return response.status(isValid ? 200 : 400).send({ isValid, error });
}
);
};
4 changes: 3 additions & 1 deletion src/emails-sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const logger = getLogger("emails-sender");

const parseRecord = (record: SQSRecord) => {
try {
// FIXME: Proxy events has invalid format? Test with real data & localstack.
// FIXME: Proxy events has invalid format? Test with real data.
const data = JSON.parse((record as any).Body);
return data as SerializedPayload;
} catch (error) {
Expand Down Expand Up @@ -68,6 +68,8 @@ export const handler = async (event: SQSEvent, context: Context) => {
props: { data },
template,
});
// TODO: Handle properly
// Will throw TypeError if failed to render / non transient

await sender.send({
html,
Expand Down
Loading

0 comments on commit de82af4

Please sign in to comment.