Skip to content

Commit

Permalink
Merge pull request #83 from beabee-communityrm/refactor/split-webhooks
Browse files Browse the repository at this point in the history
refactor: move webhooks to separate app
  • Loading branch information
wpf500 authored Nov 21, 2024
2 parents d9665f5 + 0784ff4 commit a00dca1
Show file tree
Hide file tree
Showing 37 changed files with 468 additions and 276 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ jobs:
- name: Build and push legacy app
uses: docker/build-push-action@v5
with:
file: ./apps/backend/Dockerfile
file: ./packages/docker/base.dockerfile
push: true
build-args: |
REVISION=${{ github.sha }}
Expand All @@ -74,7 +74,7 @@ jobs:
- name: Build and push API app
uses: docker/build-push-action@v5
with:
file: ./apps/backend/Dockerfile
file: ./packages/docker/base.dockerfile
push: true
build-args: |
REVISION=${{ github.sha }}
Expand All @@ -85,7 +85,7 @@ jobs:
- name: Build and push webhook app
uses: docker/build-push-action@v5
with:
file: ./apps/backend/Dockerfile
file: ./packages/docker/base.dockerfile
push: true
build-args: |
REVISION=${{ github.sha }}
Expand All @@ -96,7 +96,7 @@ jobs:
- name: Build and push cron app
uses: docker/build-push-action@v5
with:
file: ./apps/backend/Dockerfile
file: ./packages/docker/base.dockerfile
push: true
build-args: |
REVISION=${{ github.sha }}
Expand Down
4 changes: 4 additions & 0 deletions .vscode/beabee.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"name": "apps/router",
"path": "../apps/router",
},
{
"name": "apps/webhooks",
"path": "../apps/webhooks",
},
{
"name": "packages/common",
"path": "../packages/common",
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/api/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
requestLogger
} from "@beabee/core/logging";
import sessions from "@core/sessions";
import { initApp, startServer } from "@core/server";
import { initApp, startServer } from "@beabee/core/server";

import { Contact } from "@beabee/core/models";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import helmet from "helmet";
import appLoader from "@core/app-loader";
import { log, requestErrorLogger, requestLogger } from "@beabee/core/logging";
import quickflash from "@core/quickflash";
import { initApp, startServer } from "@core/server";
import { initApp, startServer } from "@beabee/core/server";
import sessions from "@core/sessions";
import { isInvalidType } from "@beabee/core/utils/db";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "module-alias/register";
import { checkbox, input } from "@inquirer/prompts";

import { getRepository } from "@beabee/core/database";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";

import OptionsService from "@beabee/core/services/OptionsService";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/database/export-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "module-alias/register";
import { Brackets } from "typeorm";

import { createQueryBuilder } from "@beabee/core/database";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";

import { Contact, Callout, CalloutResponse } from "@beabee/core/models";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/database/export.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "module-alias/register";

import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";

import * as models from "./anonymisers/models";
import { anonymiseModel, clearModels } from "./anonymisers";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@beabee/beabee-common";
import { getRepository, runTransaction } from "@beabee/core/database";
import { Callout, CalloutResponse, Contact } from "@beabee/core/models";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";
import { parse } from "csv-parse";
import { In } from "typeorm";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/database/import-steady.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { parse } from "csv-parse";
import { In } from "typeorm";

import { getRepository } from "@beabee/core/database";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";
import { normalizeEmailAddress } from "@beabee/core/utils/index";

import ContactsService from "@beabee/core/services/ContactsService";
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/database/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import "module-alias/register";
import readline from "readline";

import { dataSource } from "@beabee/core/database";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";

import config from "@beabee/core/config";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/gocardless/migrate-to-stripe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Stripe from "stripe";
import { Equal, In } from "typeorm";

import { createQueryBuilder, getRepository } from "@beabee/core/database";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";
import { stripe, stripeTypeToPaymentMethod } from "@beabee/core/lib/stripe";

import PaymentService from "@beabee/core/services/PaymentService";
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/mailchimp/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Between } from "typeorm";

import { getRepository } from "@beabee/core/database";
import { log as mainLogger } from "@beabee/core/logging";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";

import NewsletterService from "@beabee/core/services/NewsletterService";
import OptionsService from "@beabee/core/services/OptionsService";
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/new-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { input, password, select } from "@inquirer/prompts";
import moment from "moment";

import { getRepository } from "@beabee/core/database";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";
import { passwordRequirements } from "@core/utils/auth";
import { generatePassword } from "@beabee/core/utils/auth";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/process-segments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { In } from "typeorm";

import { getRepository } from "@beabee/core/database";
import { log as mainLogger } from "@beabee/core/logging";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";

import EmailService from "@beabee/core/services/EmailService";
import NewsletterService from "@beabee/core/services/NewsletterService";
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/start-gifts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Between } from "typeorm";

import { getRepository } from "@beabee/core/database";
import { log as mainLogger } from "@beabee/core/logging";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";

import GiftService from "@beabee/core/services/GiftService";

Expand Down
2 changes: 1 addition & 1 deletion apps/backend/src/tools/test-users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import moment from "moment";
import { Brackets } from "typeorm";

import { createQueryBuilder } from "@beabee/core/database";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";
import { getActualAmount } from "@beabee/core/utils/payment";

import config from "@beabee/core/config";
Expand Down
1 change: 1 addition & 0 deletions apps/webhooks/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dist/
2 changes: 2 additions & 0 deletions apps/webhooks/.prettierrc.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { baseConfig } from "@beabee/prettier-config";
export default baseConfig;
62 changes: 62 additions & 0 deletions apps/webhooks/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "@beabee/webhooks",
"version": "0.16.0",
"description": "A community engagement system for community newsrooms",
"private": true,
"main": "dist/app.js",
"type": "commonjs",
"imports": {
"#*": "./dist/*.js"
},
"scripts": {
"build": "rimraf built/ && tsc -p ./tsconfig.build.json",
"dev": "tsc-watch -p tsconfig.build.json --noClear --onSuccess 'docker compose restart webhook_app'",
"watch": "tsc-watch -p tsconfig.build.json --noClear",
"format": "prettier --write .",
"generate:index": "barrelsby -c barrelsby.json",
"test": "jest --setupFiles dotenv/config --passWithNoTests",
"check": "concurrently 'yarn:check:*'",
"check:tsc": "tsc --noEmit",
"check:prettier": "prettier -c .",
"check:dependencies": "dpdm -T --no-warning --no-tree --exit-code circular:1 src/app.ts"
},
"dependencies": {
"@beabee/beabee-common": "workspace:^",
"@beabee/core": "workspace:^",
"body-parser": "^1.20.2",
"date-fns": "^4.1.0",
"express": "^4.19.2",
"gocardless-nodejs": "^3.25.0",
"moment": "^2.30.1",
"stripe": "^15.9.0",
"typeorm": "^0.3.20"
},
"devDependencies": {
"@beabee/prettier-config": "workspace:^",
"@beabee/tsconfig": "workspace:^",
"@tsconfig/node20": "^20.1.4",
"@types/express": "^4.17.21",
"@types/node": "^20.14.1",
"barrelsby": "^2.8.1",
"concurrently": "^9.1.0",
"dotenv": "^16.4.5",
"dpdm": "^3.14.0",
"jest": "^29.7.0",
"prettier": "3.3.3",
"rimraf": "^6.0.1",
"ts-jest": "^29.2.5",
"ts-node": "^10.9.2",
"tsc-watch": "^6.3.0",
"typescript": "^5.6.3"
},
"repository": {
"type": "git",
"url": "git+https://github.com/beabee-communityrm/monorepo.git"
},
"author": "",
"license": "AGPL-3.0",
"bugs": {
"url": "https://github.com/beabee-communityrm/monorepo/issues"
},
"homepage": "https://github.com/beabee-communityrm/monorepo/blob/main/apps/webhooks/README.md"
}
10 changes: 4 additions & 6 deletions apps/backend/src/webhooks/app.ts → apps/webhooks/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import "module-alias/register";

import express, { Handler } from "express";

import { log, requestErrorLogger, requestLogger } from "@beabee/core/logging";
import { initApp, startServer } from "@core/server";
import { initApp, startServer } from "@beabee/core/server";

import OptionsService, {
OptionKey
} from "@beabee/core/services/OptionsService";

import gocardlessApp from "./handlers/gocardless";
import mailchimpApp from "./handlers/mailchimp";
import stripeApp from "./handlers/stripe";
import gocardlessApp from "#handlers/gocardless";
import mailchimpApp from "#handlers/mailchimp";
import stripeApp from "#handlers/stripe";

function checkOpt(key: OptionKey): Handler {
return (req, res, next) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
updatePayment,
cancelSubscription,
cancelMandate
} from "../utils/gocardless";
} from "#utils/gocardless";

const log = mainLogger.child({ app: "webhook-gocardless" });

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import "module-alias/register";

import { PaymentMethod } from "@beabee/beabee-common";
import { In } from "typeorm";

import { getRepository } from "@beabee/core/database";
import { runApp } from "@core/server";
import { runApp } from "@beabee/core/server";
import { stripe } from "@beabee/core/lib/stripe";
import ContactsService from "@beabee/core/services/ContactsService";

import { ContactContribution } from "@beabee/core/models";

import {
handleInvoicePaid,
handleInvoiceUpdated
} from "../../webhooks/handlers/stripe";
import { handleInvoicePaid, handleInvoiceUpdated } from "#handlers/stripe";

const isDangerMode = process.argv.includes("--danger");

Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions apps/webhooks/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@beabee/tsconfig/tsconfig.server.json",
"include": ["./src/**/*", "./src/**/*.json"],
"exclude": ["./**/*.test.ts"],
"compilerOptions": {
"rootDir": "./src",
"outDir": "./dist",
"paths": {},

// Add additional type root for local typings
"typeRoots": ["./src/typings", "./node_modules/@types/"]
}
}
11 changes: 11 additions & 0 deletions apps/webhooks/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": [
"./tsconfig.build.json",
"@beabee/tsconfig/tsconfig.options.json"
],
"exclude": [], // Override tsconfig.build.json exclude
"references": [{ "path": "../../packages/core" }],
"compilerOptions": {
"noEmit": true
}
}
Loading

0 comments on commit a00dca1

Please sign in to comment.