Skip to content

Commit

Permalink
Merge pull request #367 from RBND-studio/dev
Browse files Browse the repository at this point in the history
Merge dev
  • Loading branch information
VojtechVidra committed May 31, 2024
2 parents cfb7126 + 5b47db7 commit 0dc7aa9
Show file tree
Hide file tree
Showing 72 changed files with 8,861 additions and 7,029 deletions.
28 changes: 16 additions & 12 deletions .github/workflows/code-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,50 +9,54 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm web build
- run: pnpm lint
tsc:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm web build
- run: pnpm tsc
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm test
- run: pnpm be test:e2e
spellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm spellcheck
7 changes: 4 additions & 3 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- uses: pnpm/action-setup@v4
with:
version: 9
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"
- run: pnpm install
- run: pnpm e2e cy:run --env http_auth_username=${{ secrets.http_auth_username }},http_auth_password=${{ secrets.http_auth_password }},app_email=${{ secrets.app_email }},app_password=${{ secrets.app_password }}
2 changes: 1 addition & 1 deletion apps/app/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const dev = process.env.NODE_ENV !== "production";

const cspHeader = `
default-src 'self';
connect-src 'self' https://*.flows.sh https://*.flows-cloud.com https://*.posthog.com${
connect-src 'self' https://flows.sh https://*.flows.sh https://*.flows-cloud.com https://*.posthog.com${
dev ? " http://127.0.0.1:3005 http://localhost:3005" : ""
};
script-src 'self' 'unsafe-eval' 'unsafe-inline' https://flows.sh https://*.lemonsqueezy.com https://challenges.cloudflare.com https://*.posthog.com https://cdn.jsdelivr.net;
Expand Down
28 changes: 14 additions & 14 deletions apps/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,41 @@
"prepare": "panda codegen"
},
"dependencies": {
"@flows/js": "0.0.50",
"@hookform/resolvers": "^3.3.4",
"@marsidev/react-turnstile": "^0.5.3",
"@flows/js": "0.0.51",
"@hookform/resolvers": "^3.4.2",
"@marsidev/react-turnstile": "^0.6.1",
"@monaco-editor/react": "^4.6.0",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-slot": "^1.0.2",
"@rbnd/react-dark-mode": "^2.0.1",
"@supabase/ssr": "^0.3.0",
"@supabase/supabase-js": "^2.43.1",
"@supabase/supabase-js": "^2.43.4",
"@visx/axis": "^3.10.1",
"@visx/event": "^3.3.0",
"@visx/group": "^3.3.0",
"@visx/responsive": "^3.10.2",
"@visx/scale": "^3.5.0",
"@visx/shape": "^3.5.0",
"@visx/tooltip": "^3.3.0",
"dayjs": "^1.11.10",
"dayjs": "^1.11.11",
"icons": "workspace:*",
"monaco-editor": "^0.47.0",
"monaco-editor": "^0.49.0",
"next": "14.2.3",
"posthog-js": "^1.120.4",
"posthog-js": "^1.135.2",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"react-hook-form": "^7.51.1",
"react-hook-form": "^7.51.5",
"shared": "workspace:*",
"sharp": "^0.33.2",
"swr": "^2.2.4",
"sharp": "^0.33.4",
"swr": "^2.2.5",
"ui": "workspace:*",
"zod": "^3.22.4"
"zod": "^3.23.8"
},
"devDependencies": {
"@next/eslint-plugin-next": "14.2.3",
"@pandacss/dev": "0.37.2",
"@types/node": "^20.11.29",
"@types/react": "^18.3.2",
"@pandacss/dev": "0.39.2",
"@types/node": "^20.12.12",
"@types/react": "^18.3.3",
"@types/react-dom": "^18.3.0",
"eslint-config-custom": "workspace:*",
"tsconfig": "workspace:*",
Expand Down
21 changes: 11 additions & 10 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,27 @@
},
"dependencies": {
"@fastify/static": "^7.0.4",
"@lemonsqueezy/lemonsqueezy.js": "^2.2.0",
"@lemonsqueezy/lemonsqueezy.js": "^3.0.0",
"@logtail/node": "^0.4.21",
"@nestjs/common": "^10.3.8",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.3.8",
"@nestjs/platform-fastify": "^10.3.8",
"@nestjs/schedule": "^4.0.2",
"@nestjs/swagger": "^7.3.1",
"@nestjs/throttler": "^5.1.2",
"browserslist": "^4.23.0",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"cors": "^2.8.5",
"dayjs": "^1.11.10",
"dayjs": "^1.11.11",
"db": "workspace:*",
"drizzle-orm": "^0.30.8",
"drizzle-orm": "^0.30.10",
"fastify": "^4.27.0",
"jsonwebtoken": "^9.0.2",
"lightningcss": "^1.24.1",
"loops": "^0.3.0",
"reflect-metadata": "^0.2.1",
"lightningcss": "^1.25.1",
"loops": "^2.0.0",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"shared": "workspace:*",
"slugify": "^1.6.6"
Expand All @@ -49,20 +50,20 @@
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/testing": "^10.3.8",
"@swc/core": "^1.5.6",
"@swc/core": "^1.5.7",
"@types/cors": "^2.8.17",
"@types/jest": "^29.5.12",
"@types/jsonwebtoken": "^9.0.6",
"@types/node": "^20.11.29",
"@types/node": "^20.12.12",
"@types/supertest": "^6.0.2",
"concurrently": "^8.2.2",
"dotenv": "^16.4.5",
"eslint-config-custom": "workspace:*",
"jest": "^29.7.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.4",
"supertest": "^7.0.0",
"swc-loader": "^0.2.6",
"ts-jest": "^29.1.2",
"ts-jest": "^29.1.4",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig": "workspace:*",
Expand Down
4 changes: 4 additions & 0 deletions apps/backend/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { MiddlewareConsumer, NestModule } from "@nestjs/common";
import { Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { APP_GUARD } from "@nestjs/core";
import { ScheduleModule } from "@nestjs/schedule";
import { minutes, ThrottlerGuard, ThrottlerModule } from "@nestjs/throttler";
import cors from "cors";

Expand Down Expand Up @@ -30,6 +31,8 @@ const publicRoutes: string[] = [
"/sdk/flows/:flowId/draft",
];

const isTest = process.env.NODE_ENV === "test";

@Module({
imports: [
ConfigModule.forRoot(),
Expand All @@ -39,6 +42,7 @@ const publicRoutes: string[] = [
limit: 250,
},
]),
...(!isTest ? [ScheduleModule.forRoot()] : []),
DatabaseModule,
DbPermissionModule,
OrganizationUsageModule,
Expand Down
65 changes: 51 additions & 14 deletions apps/backend/src/email/email.service.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { Injectable } from "@nestjs/common";
import type LoopsClient from "loops";
import { LoopsClient } from "loops";

const importLoops = async (): Promise<typeof LoopsClient> => {
// eslint-disable-next-line no-eval -- workaround for the ESM import
const module = (await eval(`import('loops')`)) as { default: typeof LoopsClient };
return module.default;
};
import { type OrganizationUsageAlertType } from "../types/organization";

@Injectable()
export class EmailService {
async loops(): Promise<LoopsClient> {
const LoopsClient = await importLoops();
get loops(): LoopsClient {
return new LoopsClient(process.env.BACKEND_LOOPS_API_KEY);
}

Expand All @@ -21,24 +16,66 @@ export class EmailService {
organizationName: string;
email: string;
}): Promise<ReturnType<LoopsClient["sendTransactionalEmail"]>> {
const loops = await this.loops();
return loops.sendTransactionalEmail("clpxmw7h70012jo0pp0pe0hb5", email, {
return this.loops.sendTransactionalEmail("clpxmw7h70012jo0pp0pe0hb5", email, {
orgName: organizationName,
acceptUrl: process.env.BACKEND_APP_URL,
});
}

async sendUsageAlert({
email,
limit,
isOrganizationSubscribed,
organizationName,
organizationId,
usage,
type,
renewsAt,
}: {
email: string;
type: OrganizationUsageAlertType;
isOrganizationSubscribed: boolean;

organizationName: string;
organizationId: string;
renewsAt: string;
usage: number;
limit: number;
}): Promise<ReturnType<LoopsClient["sendTransactionalEmail"]>> {
const subsribedTemplateByAlertType: Record<OrganizationUsageAlertType, string> = {
// cspell:disable-next-line
approachingUsageLimit: "clwhium2a01nadxap9d3lnvrf",
// cspell:disable-next-line
exceededUsageLimit: "clwhj5ue700v5gn9teb9w7ud2",
};
const freeTemplateByAlertType: Record<OrganizationUsageAlertType, string> = {
// cspell:disable-next-line
approachingUsageLimit: "clwq17f6n0274vmjjp4wmeg60",
// cspell:disable-next-line
exceededUsageLimit: "clwq16zxw01e4lt7jed3sogpz",
};
const template = isOrganizationSubscribed
? subsribedTemplateByAlertType[type]
: freeTemplateByAlertType[type];

return this.loops.sendTransactionalEmail(template, email, {
organizationId,
organizationName,
renewsAt,
usage,
limit,
});
}

async createContact({
email,
}: {
email: string;
}): Promise<ReturnType<LoopsClient["createContact"]>> {
const loops = await this.loops();
return loops.createContact(email);
return this.loops.createContact(email);
}

async signedUp({ email }: { email: string }): Promise<ReturnType<LoopsClient["sendEvent"]>> {
const loops = await this.loops();
return loops.sendEvent({ email }, "signup");
return this.loops.sendEvent({ email, eventName: "signup" });
}
}
2 changes: 1 addition & 1 deletion apps/backend/src/lib/retry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const retry = <T>(fn: () => Promise<T>, retries = 3): Promise<T> =>
fn().catch((error) => {
fn().catch((error: unknown) => {
if (retries > 0) {
return retry(fn, retries - 1);
}
Expand Down
Loading

0 comments on commit 0dc7aa9

Please sign in to comment.