Skip to content

Commit

Permalink
Utilize app routes as a plugin. Organize providers
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrgrundas committed Sep 20, 2024
1 parent 1d237d3 commit c5974e3
Show file tree
Hide file tree
Showing 19 changed files with 187 additions and 287 deletions.
26 changes: 0 additions & 26 deletions .env

This file was deleted.

11 changes: 0 additions & 11 deletions .env.test

This file was deleted.

7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ yarn-debug.log*
yarn-error.log*

# local env files
.env
.env.local
.env.development.local
.env.test.local
.env.production.local
.env*
!.env.example*

# turbo
.turbo
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ Apply migrations
1. Add your credentials to [`~/.aws/credentials`](https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html)

2. Build the package:
`$ make package`
`$ ./etc/build.sh

3. Deploy zip to AWS Lambda:
`$ aws lambda update-function-code --profile [YOUR PROFILE] --function-name [YOUR FUNCTION NAME] --zip-file fileb://package.zip`
`$ aws lambda update-function-code --profile [YOUR PROFILE] --function-name [YOUR FUNCTION NAME] --zip-file fileb://artifact.zip`

TODO:

- [ ] Remove graphql yoga & related pacakges
- [ ] Proper readme
- [ ] Commitizen for jira
- [ ] esbuild for both lambdas

````
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
"@graphql-codegen/typescript": "^4.0.9",
"@graphql-codegen/typescript-operations": "^4.2.3",
"@graphql-typed-document-node/core": "^3.2.0",
"@types/aws-lambda": "^8.10.145",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^20.14.9",
"@types/pg": "^8.11.6",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

2 changes: 1 addition & 1 deletion src/api/rest/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import type { FastifyPluginAsync } from "fastify/types/plugin";
import { type ZodTypeProvider } from "fastify-type-provider-zod";

import { verifyJWTSignature } from "@/lib/saleor/auth";
import { getJWKSProvider } from "@/lib/saleor/jwks/provider";
import { saleorBearerHeader } from "@/lib/saleor/schema";
import { getJWKSProvider } from "@/providers/jwks";

import { saleorRoutes } from "./saleor";

Expand Down
51 changes: 49 additions & 2 deletions src/api/rest/saleor/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,60 @@
import type { FastifyPluginAsync } from "fastify/types/plugin";

import { routes } from "./routes";
import { CONFIG } from "@/config";
import { ShippingMethodListForCheckoutSubscriptionDocument } from "@/graphql/operations/subscriptions/generated";
import { saleorAppRouter } from "@/lib/saleor/apps/router";
import { getConfigProvider } from "@/providers/config";
import { getJWKSProvider } from "@/providers/jwks";
import { getSaleorClient } from "@/providers/saleorClient";

import { saleor } from "./saleor";
import { webhooks } from "./webhooks";

export const saleorRoutes: FastifyPluginAsync = async (
fastify
): Promise<void> => {
await Promise.all([
fastify.register(routes),
fastify.register(saleorAppRouter, {
getManifest: async ({ request }) => ({
appUrl: request.urlFor("saleor:app"),
homepageUrl: "https://mirumee.com/",
id: CONFIG.NAME,
name: CONFIG.NAME,
permissions: [
"MANAGE_PRODUCTS",
"MANAGE_CHECKOUTS",
"IMPERSONATE_USER",
"HANDLE_PAYMENTS",
"MANAGE_SHIPPING",
],
tokenTargetUrl: request.urlFor("saleor:register"),
version: CONFIG.VERSION,
webhooks: [
{
asyncEvents: [],
name: "ShippingMethodListForCheckoutSubscription",
query: ShippingMethodListForCheckoutSubscriptionDocument.toString(),
syncEvents: ["SHIPPING_LIST_METHODS_FOR_CHECKOUT"],
targetUrl: request.urlFor(
"saleor:webhooks:shipping-methods-for-checkout"
),
},
],
}),

saleorUrl: CONFIG.SALEOR_URL,

getRegisterProviders: async ({ authToken }) => ({
configProvider: getConfigProvider({ server: fastify }),
jwksProvider: getJWKSProvider(),
saleorClient: getSaleorClient({
authToken,
saleorUrl: CONFIG.SALEOR_URL,
}),
}),
}),

fastify.register(webhooks, { prefix: "/webhooks" }),
fastify.register(saleor),
]);
};
148 changes: 0 additions & 148 deletions src/api/rest/saleor/routes.test.ts

This file was deleted.

Loading

0 comments on commit c5974e3

Please sign in to comment.