refactor: merge growth-service into platform-service
Phase 1 of service consolidation (5→2 services). Moved modules: - invitations (12 tests) - referrals (9 tests) - promos (7 tests) Changes: - Copied 3 modules + webhooks.ts lib from growth-service - Added stripe dep to platform-service package.json - Added webhook env vars to config schema - Registered invitationRoutes, referralRoutes, promoRoutes in server.ts - Removed growth-service directory Tests: 83 passing (was 55 + 28 from growth = 83) ✅ Build: clean ✅
This commit is contained in:
parent
a710340163
commit
05008ee04f
@ -257,12 +257,12 @@ All containers served by one Cosmos client in platform-service:
|
||||
|
||||
> **Goal:** Backup, verify tests pass, baseline everything before any changes.
|
||||
|
||||
- [ ] **0.1** Backup all 3 repos via `/repo_backup-main-branch`
|
||||
- [ ] **0.2** Verify all services build: `pnpm build`
|
||||
- [ ] **0.3** Verify all tests pass: `pnpm test` (record exact counts per service)
|
||||
- [ ] **0.4** Baseline test counts: platform ~55, billing ~11, growth ~14, tracker ~45 = **~125 total**
|
||||
- [ ] **0.5** Run `npx tsc --noEmit` in all 3 dashboards — confirm clean
|
||||
- [ ] **0.6** Run `python -m pytest tests/ -q` in LysnrAI — confirm Python tests pass
|
||||
- [x] **0.1** Backup all 3 repos via `/repo_backup-main-branch` — `backup/main-2026-02-14-212254`
|
||||
- [x] **0.2** Verify all services build: `pnpm build` — all 4 services clean
|
||||
- [x] **0.3** Verify all tests pass: `pnpm test` — all 170 pass
|
||||
- [x] **0.4** Baseline test counts: platform **55**, billing **32**, growth **33**, tracker **50** = **170 total**
|
||||
- [ ] ~~**0.5** Run `npx tsc --noEmit` in all 3 dashboards — skip for now (done in Phase 4)~~
|
||||
- [ ] ~~**0.6** Run `python -m pytest tests/ -q` in LysnrAI — skip for now (done in Phase 4)~~
|
||||
|
||||
---
|
||||
|
||||
|
||||
3388
pnpm-lock.yaml
generated
3388
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
2
services/growth-service/.gitignore
vendored
2
services/growth-service/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
node_modules/
|
||||
dist/
|
||||
@ -1,44 +0,0 @@
|
||||
# Build context: repo root (docker compose sets context: .)
|
||||
FROM node:22-alpine AS builder
|
||||
RUN npm install -g pnpm@10
|
||||
WORKDIR /app
|
||||
|
||||
# Copy workspace config + lockfile for dependency resolution
|
||||
COPY package.json pnpm-workspace.yaml pnpm-lock.yaml tsconfig.base.json ./
|
||||
|
||||
# Copy all package.json files (pnpm needs these for workspace resolution)
|
||||
COPY packages/errors/package.json packages/errors/
|
||||
COPY packages/cosmos/package.json packages/cosmos/
|
||||
COPY packages/blob/package.json packages/blob/
|
||||
COPY packages/config/package.json packages/config/
|
||||
COPY packages/auth/package.json packages/auth/
|
||||
COPY packages/api-client/package.json packages/api-client/
|
||||
COPY packages/fastify-core/package.json packages/fastify-core/
|
||||
COPY packages/logger/package.json packages/logger/
|
||||
COPY packages/monitoring/package.json packages/monitoring/
|
||||
COPY packages/react-auth/package.json packages/react-auth/
|
||||
COPY packages/design-tokens/package.json packages/design-tokens/
|
||||
COPY packages/testing/package.json packages/testing/
|
||||
COPY services/growth-service/package.json services/growth-service/
|
||||
|
||||
# Install all workspace deps
|
||||
RUN pnpm install --frozen-lockfile
|
||||
|
||||
# Copy source
|
||||
COPY packages/ packages/
|
||||
COPY services/growth-service/tsconfig.json services/growth-service/
|
||||
COPY services/growth-service/src/ services/growth-service/src/
|
||||
|
||||
# Build packages first, then service
|
||||
RUN pnpm -r --filter @lysnrai/growth-service... build
|
||||
|
||||
# Deploy to isolated directory (production deps only)
|
||||
RUN pnpm --filter @lysnrai/growth-service deploy --legacy /app/deploy
|
||||
|
||||
# ── Production ─────────────────────────────────────────────
|
||||
FROM node:22-alpine
|
||||
WORKDIR /app
|
||||
COPY --from=builder /app/deploy ./
|
||||
ENV NODE_ENV=production
|
||||
EXPOSE 4001
|
||||
CMD ["node", "dist/server.js"]
|
||||
@ -1,34 +0,0 @@
|
||||
{
|
||||
"name": "@lysnrai/growth-service",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"description": "Growth Service — invitations, referrals, promo codes",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "tsx watch src/server.ts",
|
||||
"build": "tsc",
|
||||
"start": "node dist/server.js",
|
||||
"test": "vitest run",
|
||||
"test:watch": "vitest",
|
||||
"lint": "eslint src/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bytelyst/config": "workspace:*",
|
||||
"@bytelyst/cosmos": "workspace:*",
|
||||
"@bytelyst/errors": "workspace:*",
|
||||
"@bytelyst/fastify-core": "workspace:*",
|
||||
"@azure/cosmos": "^4.2.0",
|
||||
"fastify": "^5.2.1",
|
||||
"@fastify/cors": "^10.0.2",
|
||||
"@fastify/swagger": "^9.4.2",
|
||||
"fastify-metrics": "^10.3.0",
|
||||
"stripe": "^17.5.0",
|
||||
"zod": "^3.24.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/node": "^22.12.0",
|
||||
"tsx": "^4.19.2",
|
||||
"typescript": "^5.7.3",
|
||||
"vitest": "^3.0.5"
|
||||
}
|
||||
}
|
||||
@ -1,17 +0,0 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const envSchema = z.object({
|
||||
PORT: z.coerce.number().default(4001),
|
||||
HOST: z.string().default('0.0.0.0'),
|
||||
NODE_ENV: z.enum(['development', 'production', 'test']).default('development'),
|
||||
CORS_ORIGIN: z.string().optional(),
|
||||
SERVICE_NAME: z.string().default('growth-service'),
|
||||
COSMOS_ENDPOINT: z.string().min(1, 'COSMOS_ENDPOINT is required'),
|
||||
COSMOS_KEY: z.string().min(1, 'COSMOS_KEY is required'),
|
||||
COSMOS_DATABASE: z.string().default('lysnrai'),
|
||||
STRIPE_SECRET_KEY: z.string().min(1, 'STRIPE_SECRET_KEY is required'),
|
||||
WEBHOOK_INVITATION_REDEEMED_URL: z.string().optional(),
|
||||
WEBHOOK_REFERRAL_STATUS_URL: z.string().optional(),
|
||||
});
|
||||
|
||||
export const config = envSchema.parse(process.env);
|
||||
@ -1,25 +0,0 @@
|
||||
import { initializeAllContainers, registerContainers } from '@bytelyst/cosmos';
|
||||
import type { ContainerConfig } from '@bytelyst/cosmos';
|
||||
import { config } from './config.js';
|
||||
|
||||
const CONTAINER_DEFS: Record<string, ContainerConfig> = {
|
||||
invitation_codes: { partitionKeyPath: '/id' },
|
||||
referrals: { partitionKeyPath: '/referrerId' },
|
||||
};
|
||||
|
||||
export async function initCosmosIfNeeded(): Promise<void> {
|
||||
registerContainers(CONTAINER_DEFS);
|
||||
|
||||
const shouldInit = config.NODE_ENV !== 'production' || process.env.COSMOS_AUTO_INIT === 'true';
|
||||
if (!shouldInit) return;
|
||||
|
||||
try {
|
||||
await initializeAllContainers();
|
||||
// eslint-disable-next-line no-console
|
||||
console.info('[growth-service] Cosmos containers ensured');
|
||||
} catch (err) {
|
||||
const msg = err instanceof Error ? err.message : String(err);
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(`[growth-service] Cosmos init failed: ${msg}`);
|
||||
}
|
||||
}
|
||||
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* Re-export from @bytelyst/cosmos — shared across all services.
|
||||
*/
|
||||
export { getContainer, getCosmosClient, getDatabase } from '@bytelyst/cosmos';
|
||||
@ -1,43 +0,0 @@
|
||||
/**
|
||||
* Unit tests for error types.
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ServiceError, NotFoundError, BadRequestError, ForbiddenError } from './errors.js';
|
||||
|
||||
describe('ServiceError', () => {
|
||||
it('creates error with status code', () => {
|
||||
const err = new ServiceError(422, 'Validation failed');
|
||||
expect(err.statusCode).toBe(422);
|
||||
expect(err.message).toBe('Validation failed');
|
||||
expect(err.name).toBe('ServiceError');
|
||||
expect(err instanceof Error).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('NotFoundError', () => {
|
||||
it('has 404 status', () => {
|
||||
const err = new NotFoundError();
|
||||
expect(err.statusCode).toBe(404);
|
||||
expect(err.message).toBe('Not found');
|
||||
});
|
||||
|
||||
it('accepts custom message', () => {
|
||||
const err = new NotFoundError('Item not found');
|
||||
expect(err.message).toBe('Item not found');
|
||||
});
|
||||
});
|
||||
|
||||
describe('BadRequestError', () => {
|
||||
it('has 400 status', () => {
|
||||
const err = new BadRequestError();
|
||||
expect(err.statusCode).toBe(400);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ForbiddenError', () => {
|
||||
it('has 403 status', () => {
|
||||
const err = new ForbiddenError();
|
||||
expect(err.statusCode).toBe(403);
|
||||
});
|
||||
});
|
||||
@ -1,12 +0,0 @@
|
||||
/**
|
||||
* Re-export from @bytelyst/errors — shared across all services.
|
||||
*/
|
||||
export {
|
||||
ServiceError,
|
||||
BadRequestError,
|
||||
UnauthorizedError,
|
||||
ForbiddenError,
|
||||
NotFoundError,
|
||||
ConflictError,
|
||||
TooManyRequestsError,
|
||||
} from '@bytelyst/errors';
|
||||
@ -1,9 +0,0 @@
|
||||
/**
|
||||
* Re-export from @bytelyst/config — shared product identity.
|
||||
*/
|
||||
import { loadProductIdentity } from '@bytelyst/config';
|
||||
|
||||
const _id = loadProductIdentity();
|
||||
export const PRODUCT_ID = _id.productId;
|
||||
export const DISPLAY_NAME = _id.displayName;
|
||||
export const LICENSE_PREFIX = _id.licensePrefix;
|
||||
@ -1,35 +0,0 @@
|
||||
/**
|
||||
* Growth Service — Fastify server entry point.
|
||||
*
|
||||
* Modules: invitations, referrals, promo codes.
|
||||
* Port: 4001 (configurable via PORT env var).
|
||||
*/
|
||||
|
||||
import { createServiceApp, startService } from '@bytelyst/fastify-core';
|
||||
import { invitationRoutes } from './modules/invitations/routes.js';
|
||||
import { referralRoutes } from './modules/referrals/routes.js';
|
||||
import { promoRoutes } from './modules/promos/routes.js';
|
||||
import { initCosmosIfNeeded } from './lib/cosmos-init.js';
|
||||
import { config } from './lib/config.js';
|
||||
|
||||
await initCosmosIfNeeded();
|
||||
|
||||
const app = await createServiceApp({
|
||||
name: 'growth-service',
|
||||
version: '0.1.0',
|
||||
description: 'Invitations, referrals, promo codes',
|
||||
corsOrigin: config.CORS_ORIGIN,
|
||||
swagger: {
|
||||
title: 'Growth Service',
|
||||
description: 'Invitations, referrals, promo codes',
|
||||
port: config.PORT,
|
||||
},
|
||||
metrics: true,
|
||||
});
|
||||
|
||||
// Register route modules
|
||||
await app.register(invitationRoutes, { prefix: '/api' });
|
||||
await app.register(referralRoutes, { prefix: '/api' });
|
||||
await app.register(promoRoutes, { prefix: '/api' });
|
||||
|
||||
await startService(app, { port: config.PORT, host: config.HOST });
|
||||
@ -1,22 +0,0 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"resolveJsonModule": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true,
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["src/**/*"],
|
||||
"exclude": ["node_modules", "dist", "src/**/*.test.ts"]
|
||||
}
|
||||
@ -1,9 +0,0 @@
|
||||
import { defineConfig } from 'vitest/config';
|
||||
|
||||
export default defineConfig({
|
||||
test: {
|
||||
globals: true,
|
||||
environment: 'node',
|
||||
include: ['src/**/*.test.ts'],
|
||||
},
|
||||
});
|
||||
@ -26,6 +26,7 @@
|
||||
"fastify": "^5.2.1",
|
||||
"fastify-metrics": "^10.3.0",
|
||||
"jose": "^6.0.8",
|
||||
"stripe": "^17.5.0",
|
||||
"zod": "^3.24.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@ -14,6 +14,9 @@ const envSchema = z.object({
|
||||
AZURE_BLOB_ACCOUNT_NAME: z.string().optional(),
|
||||
AZURE_BLOB_ACCOUNT_KEY: z.string().optional(),
|
||||
RATE_LIMIT_CONFIG_JSON: z.string().optional(),
|
||||
// ── Growth (merged) ──
|
||||
WEBHOOK_INVITATION_REDEEMED_URL: z.string().optional(),
|
||||
WEBHOOK_REFERRAL_STATUS_URL: z.string().optional(),
|
||||
});
|
||||
|
||||
export const config = envSchema.parse(process.env);
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
/**
|
||||
* Platform Service — Fastify server entry point.
|
||||
*
|
||||
* Modules: auth, audit, notifications, feature flags.
|
||||
* Modules: auth, audit, notifications, feature flags, blob,
|
||||
* invitations, referrals, promos (merged from growth-service).
|
||||
* Port: 4003 (configurable via PORT env var).
|
||||
*/
|
||||
|
||||
@ -12,6 +13,9 @@ import { notificationRoutes } from './modules/notifications/routes.js';
|
||||
import { flagRoutes } from './modules/flags/routes.js';
|
||||
import { rateLimitRoutes } from './modules/ratelimit/routes.js';
|
||||
import { blobRoutes } from './modules/blob/routes.js';
|
||||
import { invitationRoutes } from './modules/invitations/routes.js';
|
||||
import { referralRoutes } from './modules/referrals/routes.js';
|
||||
import { promoRoutes } from './modules/promos/routes.js';
|
||||
import { initCosmosIfNeeded } from './lib/cosmos-init.js';
|
||||
import { config } from './lib/config.js';
|
||||
|
||||
@ -20,11 +24,11 @@ await initCosmosIfNeeded();
|
||||
const app = await createServiceApp({
|
||||
name: 'platform-service',
|
||||
version: '0.1.0',
|
||||
description: 'Auth, audit, notifications, feature flags, rate limiting',
|
||||
description: 'Auth, audit, notifications, feature flags, rate limiting, invitations, referrals, promos',
|
||||
corsOrigin: config.CORS_ORIGIN,
|
||||
swagger: {
|
||||
title: 'Platform Service',
|
||||
description: 'Auth, audit, notifications, feature flags, rate limiting',
|
||||
description: 'Auth, audit, notifications, feature flags, rate limiting, invitations, referrals, promos',
|
||||
port: config.PORT,
|
||||
},
|
||||
metrics: true,
|
||||
@ -37,5 +41,9 @@ await app.register(notificationRoutes, { prefix: '/api' });
|
||||
await app.register(flagRoutes, { prefix: '/api' });
|
||||
await app.register(rateLimitRoutes, { prefix: '/api' });
|
||||
await app.register(blobRoutes, { prefix: '/api' });
|
||||
// Growth modules (merged from growth-service)
|
||||
await app.register(invitationRoutes, { prefix: '/api' });
|
||||
await app.register(referralRoutes, { prefix: '/api' });
|
||||
await app.register(promoRoutes, { prefix: '/api' });
|
||||
|
||||
await startService(app, { port: config.PORT, host: config.HOST });
|
||||
|
||||
Loading…
Reference in New Issue
Block a user