feat(api): add drip campaign (#65148)

Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Ahmad Abdolsaheb
2026-01-20 15:44:26 +03:00
committed by GitHub
parent 214c5a3240
commit 67d7fa17ff
8 changed files with 225 additions and 13 deletions

View File

@@ -9,11 +9,16 @@ import {
import Fastify, { FastifyInstance } from 'fastify';
import { checkCanConnectToDb, defaultUserEmail } from '../../vitest.utils.js';
import { HOME_LOCATION } from '../utils/env.js';
import {
HOME_LOCATION,
GROWTHBOOK_FASTIFY_API_HOST,
GROWTHBOOK_FASTIFY_CLIENT_KEY
} from '../utils/env.js';
import { devAuth } from '../plugins/auth-dev.js';
import prismaPlugin from '../db/prisma.js';
import auth from './auth.js';
import cookies from './cookies.js';
import growthBook from './growth-book.js';
import { newUser } from './__fixtures__/user.js';
@@ -28,6 +33,10 @@ describe('dev login', () => {
await fastify.register(devAuth);
await fastify.register(prismaPlugin);
await checkCanConnectToDb(fastify.prisma);
await fastify.register(growthBook, {
apiHost: GROWTHBOOK_FASTIFY_API_HOST,
clientKey: GROWTHBOOK_FASTIFY_CLIENT_KEY
});
});
beforeEach(async () => {

View File

@@ -12,13 +12,19 @@ import {
import Fastify, { FastifyInstance } from 'fastify';
import { createUserInput } from '../utils/create-user.js';
import { AUTH0_DOMAIN, HOME_LOCATION } from '../utils/env.js';
import {
AUTH0_DOMAIN,
HOME_LOCATION,
GROWTHBOOK_FASTIFY_API_HOST,
GROWTHBOOK_FASTIFY_CLIENT_KEY
} from '../utils/env.js';
import prismaPlugin from '../db/prisma.js';
import cookies, { sign, unsign } from './cookies.js';
import { auth0Client } from './auth0.js';
import redirectWithMessage, { formatMessage } from './redirect-with-message.js';
import auth from './auth.js';
import bouncer from './bouncer.js';
import growthBook from './growth-book.js';
import { newUser } from './__fixtures__/user.js';
const COOKIE_DOMAIN = 'test.com';
@@ -40,6 +46,10 @@ describe('auth0 plugin', () => {
await fastify.register(bouncer);
await fastify.register(auth0Client);
await fastify.register(prismaPlugin);
await fastify.register(growthBook, {
apiHost: GROWTHBOOK_FASTIFY_API_HOST,
clientKey: GROWTHBOOK_FASTIFY_CLIENT_KEY
});
});
describe('GET /signin/google', () => {

View File

@@ -12,11 +12,16 @@ declare module 'fastify' {
const growthBook: FastifyPluginAsync<Options> = async (fastify, options) => {
const gb = new GrowthBook(options);
const res = await gb.init({ timeout: 3000 });
if (res.error && FREECODECAMP_NODE_ENV === 'production') {
fastify.log.error(res.error, 'Failed to initialize GrowthBook');
fastify.Sentry.captureException(res.error);
const hasRequiredConfig = Boolean(options.clientKey && options.apiHost);
if (hasRequiredConfig) {
const res = await gb.init({ timeout: 3000 });
if (res.error && FREECODECAMP_NODE_ENV === 'production') {
fastify.log.error(res.error, 'Failed to initialize GrowthBook');
fastify.Sentry.captureException(res.error);
}
}
fastify.decorate('gb', gb);